KiCad PCB EDA Suite
footprint_libraries_utils.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #include <wx/ffile.h>
25 #include <fctsys.h>
26 #include <pgm_base.h>
27 #include <kiface_i.h>
28 #include <confirm.h>
29 #include <kicad_string.h>
30 #include <pcb_edit_frame.h>
31 #include <dialog_helpers.h>
32 #include <filter_reader.h>
33 #include <macros.h>
34 #include <fp_lib_table.h>
35 #include <validators.h>
36 #include <dialog_text_entry.h>
37 #include <tool/tool_manager.h>
38 #include <tools/pcb_actions.h>
39 #include <class_board.h>
40 #include <class_module.h>
41 #include <board_commit.h>
42 #include <footprint_edit_frame.h>
44 #include <kicad_plugin.h>
45 #include <legacy_plugin.h>
46 #include <env_paths.h>
49 #include "footprint_viewer_frame.h"
50 
51 
52 // unique, "file local" translations:
53 
54 
55 static const wxString INFO_LEGACY_LIB_WARN_EDIT(
56  _( "Writing/modifying legacy libraries (.mod files) is not allowed\n"\
57  "Please save the current library to the new .pretty format\n"\
58  "and update your footprint lib table\n"\
59  "to save your footprint (a .kicad_mod file) in the .pretty library folder" ) );
60 
61 static const wxString INFO_LEGACY_LIB_WARN_DELETE(
62  _( "Modifying legacy libraries (.mod files) is not allowed\n"\
63  "Please save the current library under the new .pretty format\n"\
64  "and update your footprint lib table\n"\
65  "before deleting a footprint" ) );
66 
67 
73 static wxFileName getFootprintFilenameFromUser( wxWindow* aParent, const wxString& aLastPath )
74 {
75  static int lastFilterIndex = 0; // To store the last choice during a session.
76  wxString wildCard;
77 
78  wildCard << KiCadFootprintLibFileWildcard() << wxChar( '|' )
79  << ModLegacyExportFileWildcard() << wxChar( '|' )
80  << GedaPcbFootprintLibFileWildcard() << wxChar( '|' )
81  << AllFilesWildcard();
82 
83  wxFileDialog dlg( aParent, _( "Import Footprint" ), aLastPath, wxEmptyString, wildCard,
84  wxFD_OPEN | wxFD_FILE_MUST_EXIST );
85 
86  dlg.SetFilterIndex( lastFilterIndex );
87 
88  if( dlg.ShowModal() == wxID_CANCEL )
89  return wxFileName();
90 
91  lastFilterIndex = dlg.GetFilterIndex();
92 
93  return wxFileName( dlg.GetPath() );
94 }
95 
96 
103 static IO_MGR::PCB_FILE_T detect_file_type( FILE* aFile, const wxFileName& aFileName,
104  wxString* aName )
105 {
106  FILE_LINE_READER freader( aFile, aFileName.GetFullPath() );
107  WHITESPACE_FILTER_READER reader( freader );
108  IO_MGR::PCB_FILE_T file_type;
109 
110  wxASSERT( aName );
111 
112  reader.ReadLine();
113  char* line = reader.Line();
114 
115  if( !strncasecmp( line, "(module", strlen( "(module" ) ) )
116  {
117  file_type = IO_MGR::KICAD_SEXP;
118  *aName = aFileName.GetName();
119  }
120  else if( !strncasecmp( line, FOOTPRINT_LIBRARY_HEADER, FOOTPRINT_LIBRARY_HEADER_CNT ) )
121  {
122  file_type = IO_MGR::LEGACY;
123 
124  while( reader.ReadLine() )
125  {
126  if( !strncasecmp( line, "$MODULE", strlen( "$MODULE" ) ) )
127  {
128  *aName = FROM_UTF8( StrPurge( line + strlen( "$MODULE" ) ) );
129  break;
130  }
131  }
132  }
133  else if( !strncasecmp( line, "Element", strlen( "Element" ) ) )
134  {
135  file_type = IO_MGR::GEDA_PCB;
136  *aName = aFileName.GetName();
137  }
138  else
139  {
140  file_type = IO_MGR::FILE_TYPE_NONE;
141  }
142 
143  return file_type;
144 }
145 
146 
154  const wxFileName& aFileName, IO_MGR::PCB_FILE_T aFileType,
155  const wxString& aName )
156 {
157  wxString path;
158 
159  switch( aFileType )
160  {
161  case IO_MGR::GEDA_PCB:
162  path = aFileName.GetPath();
163  break;
164  case IO_MGR::LEGACY:
165  path = aFileName.GetFullPath();
166  break;
167  default:
168  wxFAIL_MSG( wxT( "unexpected IO_MGR::PCB_FILE_T" ) );
169  }
170 
171  PLUGIN::RELEASER pi( IO_MGR::PluginFind( aFileType ) );
172 
173  return pi->FootprintLoad( path, aName );
174 }
175 
176 
181 static MODULE* parse_module_kicad( const wxFileName& aFileName )
182 {
183  wxString fcontents;
184  PCB_IO pcb_io;
185  wxFFile f( aFileName.GetFullPath() );
186 
187  if( !f.IsOpened() )
188  return NULL;
189 
190  f.ReadAll( &fcontents );
191 
192  return dynamic_cast<MODULE*>( pcb_io.Parse( fcontents ) );
193 }
194 
195 
202 MODULE* try_load_footprint( const wxFileName& aFileName, IO_MGR::PCB_FILE_T aFileType,
203  const wxString& aName )
204 {
205  MODULE* module;
206 
207  switch( aFileType )
208  {
209  case IO_MGR::GEDA_PCB:
210  case IO_MGR::LEGACY:
211  module = parse_module_with_plugin( aFileName, aFileType, aName );
212  break;
213 
214  case IO_MGR::KICAD_SEXP:
215  module = parse_module_kicad( aFileName );
216  break;
217 
218  default:
219  wxFAIL_MSG( wxT( "unexpected IO_MGR::PCB_FILE_T" ) );
220  module = NULL;
221  }
222 
223  return module;
224 }
225 
226 
228 {
229  wxString lastOpenedPathForLoading = m_mruPath;
231 
232  if( !cfg->m_LastImportExportPath.empty() )
233  lastOpenedPathForLoading = cfg->m_LastImportExportPath;
234 
235  wxFileName fn;
236 
237  if( aName != wxT("") )
238  fn = aName;
239  else
240  fn = getFootprintFilenameFromUser( this, lastOpenedPathForLoading );
241 
242  if( !fn.IsOk() )
243  return NULL;
244 
245  FILE* fp = wxFopen( fn.GetFullPath(), wxT( "rt" ) );
246 
247  if( !fp )
248  {
249  wxString msg = wxString::Format( _( "File \"%s\" not found" ), fn.GetFullPath() );
250  DisplayError( this, msg );
251  return NULL;
252  }
253 
254  cfg->m_LastImportExportPath = lastOpenedPathForLoading;
255 
256  wxString moduleName;
257  IO_MGR::PCB_FILE_T fileType = detect_file_type( fp, fn.GetFullPath(), &moduleName );
258 
260  {
261  DisplayError( this, _( "Not a footprint file" ) );
262  return NULL;
263  }
264 
265  MODULE* module = NULL;
266 
267  try
268  {
269  module = try_load_footprint( fn, fileType, moduleName );
270 
271  if( !module )
272  {
273  wxString msg = wxString::Format( _( "Unable to load footprint '%s' from '%s'" ),
274  moduleName,
275  fn.GetFullPath() );
276  DisplayError( this, msg );
277  return NULL;
278  }
279  }
280  catch( const IO_ERROR& ioe )
281  {
282  DisplayError( this, ioe.What() );
283 
284  // if the footprint is not loaded, exit.
285  // However, even if an error happens, it can be loaded, because in KICAD and GPCB format,
286  // a fp library is a set of separate files, and the error(s) are not necessary when
287  // reading the selected file
288 
289  if( !module )
290  return NULL;
291  }
292 
293  module->SetFPID( LIB_ID( wxEmptyString, moduleName ) );
294 
295  // Insert footprint in list
296  AddModuleToBoard( module );
297 
298  // Display info :
299  SetMsgPanel( module );
300  PlaceModule( module );
301 
302  module->SetPosition( wxPoint( 0, 0 ) );
303 
305  updateView();
306 
307  return module;
308 }
309 
310 
312 {
313  wxFileName fn;
315 
316  if( !aModule )
317  return;
318 
319  fn.SetName( aModule->GetFPID().GetLibItemName() );
320 
321  wxString wildcard = KiCadFootprintLibFileWildcard();
322 
323  fn.SetExt( KiCadFootprintFileExtension );
324 
325  if( !cfg->m_LastImportExportPath.empty() )
326  fn.SetPath( cfg->m_LastImportExportPath );
327  else
328  fn.SetPath( m_mruPath );
329 
330  wxFileDialog dlg( this, _( "Export Footprint" ), fn.GetPath(), fn.GetFullName(),
331  wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
332 
333  if( dlg.ShowModal() == wxID_CANCEL )
334  return;
335 
336  fn = dlg.GetPath();
337  cfg->m_LastImportExportPath = fn.GetPath();
338 
339  try
340  {
341  // Export as *.kicad_pcb format, using a strategy which is specifically chosen
342  // as an example on how it could also be used to send it to the system clipboard.
343 
344  PCB_IO pcb_io( CTL_FOR_LIBRARY );
345 
346  /* This module should *already* be "normalized" in a way such that
347  orientation is zero, etc., since it came from module editor.
348 
349  module->SetParent( 0 );
350  module->SetOrientation( 0 );
351  */
352 
353  pcb_io.Format( aModule );
354 
355  FILE* fp = wxFopen( dlg.GetPath(), wxT( "wt" ) );
356 
357  if( fp == NULL )
358  {
359  wxMessageBox( wxString::Format( _( "Unable to create or write file \"%s\"" ),
360  dlg.GetPath() ) );
361  return;
362  }
363 
364  fprintf( fp, "%s", pcb_io.GetStringOutput( false ).c_str() );
365  fclose( fp );
366  }
367  catch( const IO_ERROR& ioe )
368  {
369  DisplayError( this, ioe.What() );
370  return;
371  }
372 
373  wxString msg = wxString::Format( _( "Footprint exported to file \"%s\"" ), dlg.GetPath() );
374  DisplayInfoMessage( this, msg );
375 }
376 
377 
378 wxString PCB_BASE_EDIT_FRAME::CreateNewLibrary( const wxString& aLibName,
379  const wxString& aProposedName )
380 {
381  // Kicad cannot write legacy format libraries, only .pretty new format
382  // because the legacy format cannot handle current features.
383  // The footprint library is actually a directory
384 
385  wxString initialPath = aProposedName.IsEmpty() ? Prj().GetProjectPath() : aProposedName;
386  wxFileName fn;
387  bool doAdd = false;
388 
389  if( aLibName.IsEmpty() )
390  {
391  fn = initialPath;
392 
393  if( !LibraryFileBrowser( false, fn,
395  {
396  return wxEmptyString;
397  }
398 
399  doAdd = true;
400  }
401  else
402  {
403  fn = aLibName;
404 
405  if( !fn.IsAbsolute() )
406  {
407  fn.SetName( aLibName );
408  fn.MakeAbsolute( initialPath );
409  }
410 
411  // Enforce the .pretty extension:
412  fn.SetExt( KiCadFootprintLibPathExtension );
413  }
414 
415  // We can save fp libs only using IO_MGR::KICAD_SEXP format (.pretty libraries)
417  wxString libPath = fn.GetFullPath();
418 
419  try
420  {
421  PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) );
422 
423  bool writable = false;
424  bool exists = false;
425 
426  try
427  {
428  writable = pi->IsFootprintLibWritable( libPath );
429  exists = true; // no exception was thrown, lib must exist.
430  }
431  catch( const IO_ERROR& )
432  { }
433 
434  if( exists )
435  {
436  if( !writable )
437  {
438  wxString msg = wxString::Format( _( "Library \"%s\" is read only." ), libPath );
439  ShowInfoBarError( msg );
440  return wxEmptyString;
441  }
442  else
443  {
444  wxString msg = wxString::Format( _( "Library %s already exists." ), libPath );
445  KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
446  dlg.SetOKLabel( _( "Overwrite" ) );
447  dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
448 
449  if( dlg.ShowModal() == wxID_CANCEL )
450  return wxEmptyString;
451 
452  pi->FootprintLibDelete( libPath );
453  }
454  }
455 
456  pi->FootprintLibCreate( libPath );
457  }
458  catch( const IO_ERROR& ioe )
459  {
460  DisplayError( this, ioe.What() );
461  return wxEmptyString;
462  }
463 
464  if( doAdd )
465  AddLibrary( libPath );
466 
467  return libPath;
468 }
469 
470 
471 bool PCB_BASE_EDIT_FRAME::AddLibrary( const wxString& aFilename )
472 {
473  wxFileName fn( aFilename );
474 
475  if( aFilename.IsEmpty() )
476  {
477  if( !LibraryFileBrowser( true, fn,
479  true ) )
480  {
481  return false;
482  }
483  }
484 
485  wxString libPath = fn.GetFullPath();
486  wxString libName = fn.GetName();
487 
488  if( libName.IsEmpty() )
489  return false;
490 
491  bool saveInGlobalTable = false;
492  bool saveInProjectTable = false;
493 
494  if( Prj().IsNullProject() )
495  {
496  saveInGlobalTable = true;
497  }
498  else
499  {
500  wxArrayString libTableNames;
501 
502  libTableNames.Add( _( "Global" ) );
503  libTableNames.Add( _( "Project" ) );
504 
505  switch( SelectSingleOption( this, _( "Select Library Table" ),
506  _( "Choose the Library Table to add the library to:" ), libTableNames ) )
507  {
508  case 0: saveInGlobalTable = true; break;
509  case 1: saveInProjectTable = true; break;
510  default: return false;
511  }
512  }
513 
514  wxString type = IO_MGR::ShowType( IO_MGR::GuessPluginTypeFromLibPath( libPath ) );
515 
516  // try to use path normalized to an environmental variable or project path
517  wxString normalizedPath = NormalizePath( libPath, &Pgm().GetLocalEnvVariables(), &Prj() );
518 
519  if( normalizedPath.IsEmpty() )
520  normalizedPath = libPath;
521 
522  try
523  {
524  if( saveInGlobalTable )
525  {
526  auto row = new FP_LIB_TABLE_ROW( libName, normalizedPath, type, wxEmptyString );
527  GFootprintTable.InsertRow( row );
529  }
530  else if( saveInProjectTable )
531  {
532  auto row = new FP_LIB_TABLE_ROW( libName, normalizedPath, type, wxEmptyString );
533  Prj().PcbFootprintLibs()->InsertRow( row );
534  Prj().PcbFootprintLibs()->Save( Prj().FootprintLibTblName() );
535  }
536  }
537  catch( const IO_ERROR& ioe )
538  {
539  DisplayError( this, ioe.What() );
540  return false;
541  }
542 
543  auto editor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_FOOTPRINT_EDITOR, false );
544 
545  if( editor )
546  {
547  LIB_ID libID( libName, wxEmptyString );
548  editor->SyncLibraryTree( true );
549  editor->FocusOnLibID( libID );
550  }
551 
552  auto viewer = (FOOTPRINT_VIEWER_FRAME*) Kiway().Player( FRAME_FOOTPRINT_VIEWER, false );
553 
554  if( viewer )
555  viewer->ReCreateLibraryList();
556 
557  return true;
558 }
559 
560 
561 bool FOOTPRINT_EDIT_FRAME::DeleteModuleFromLibrary( const LIB_ID& aFPID, bool aConfirm )
562 {
563  if( !aFPID.IsValid() )
564  return false;
565 
566  wxString nickname = aFPID.GetLibNickname();
567  wxString fpname = aFPID.GetLibItemName();
568 
569  // Legacy libraries are readable, but modifying legacy format is not allowed
570  // So prompt the user if he try to delete a footprint from a legacy lib
571  wxString libfullname = Prj().PcbFootprintLibs()->FindRow( nickname )->GetFullURI();
572 
573  if( IO_MGR::GuessPluginTypeFromLibPath( libfullname ) == IO_MGR::LEGACY )
574  {
576  return false;
577  }
578 
579  if( !Prj().PcbFootprintLibs()->IsFootprintLibWritable( nickname ) )
580  {
581  wxString msg = wxString::Format( _( "Library '%s' is read only." ), nickname );
582  ShowInfoBarError( msg );
583  return false;
584  }
585 
586  // Confirmation
587  wxString msg = wxString::Format( _( "Delete footprint '%s' from library '%s'?" ),
588  fpname.GetData(),
589  nickname.GetData() );
590 
591  if( aConfirm && !IsOK( this, msg ) )
592  return false;
593 
594  try
595  {
596  Prj().PcbFootprintLibs()->FootprintDelete( nickname, fpname );
597  }
598  catch( const IO_ERROR& ioe )
599  {
600  DisplayError( this, ioe.What() );
601  return false;
602  }
603 
604  msg.Printf( _( "Footprint '%s' deleted from library '%s'" ),
605  fpname.GetData(),
606  nickname.GetData() );
607 
608  SetStatusText( msg );
609 
610  return true;
611 }
612 
613 
614 void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aStoreInNewLib, const wxString& aLibName,
615  wxString* aLibPath )
616 {
617  if( GetBoard()->GetFirstModule() == NULL )
618  {
619  DisplayInfoMessage( this, _( "No footprints to archive!" ) );
620  return;
621  }
622 
623  wxString footprintName;
624 
625  if( !aStoreInNewLib )
626  {
627  // The footprints are saved in an existing .pretty library in the fp lib table
628  PROJECT& prj = Prj();
629  wxString last_nickname = prj.GetRString( PROJECT::PCB_LIB_NICKNAME );
630  wxString nickname = SelectLibrary( last_nickname );
631 
632  if( !nickname ) // Aborted
633  return;
634 
635  prj.SetRString( PROJECT::PCB_LIB_NICKNAME, nickname );
636 
637  try
638  {
639  FP_LIB_TABLE* tbl = prj.PcbFootprintLibs();
640 
641  for( auto curr_fp : GetBoard()->Modules() )
642  {
643  if( !curr_fp->GetFPID().GetLibItemName().empty() ) // Can happen with old boards.
644  tbl->FootprintSave( nickname, curr_fp, false );
645  }
646  }
647  catch( const IO_ERROR& ioe )
648  {
649  DisplayError( this, ioe.What() );
650  }
651  }
652  else
653  {
654  // The footprints are saved in a new .pretty library.
655  // If this library already exists, all previous footprints will be deleted
656  wxString libPath = CreateNewLibrary( aLibName );
657 
658  if( libPath.IsEmpty() ) // Aborted
659  return;
660 
661 
662  if( aLibPath ) *aLibPath = libPath;
663 
665  PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) );
666 
667  for( auto curr_fp : GetBoard()->Modules() )
668  {
669  try
670  {
671  if( !curr_fp->GetFPID().GetLibItemName().empty() ) // Can happen with old boards.
672  pi->FootprintSave( libPath, curr_fp );
673  }
674  catch( const IO_ERROR& ioe )
675  {
676  DisplayError( this, ioe.What() );
677  }
678  }
679  }
680 }
681 
682 
684 {
685  if( !aModule ) // Happen if no footprint loaded
686  return false;
687 
688  wxString libraryName = aModule->GetFPID().GetLibNickname();
689  wxString footprintName = aModule->GetFPID().GetLibItemName();
690  bool nameChanged = m_footprintNameWhenLoaded != footprintName;
691 
692  if( aModule->GetLink() != niluuid )
693  {
694  if( SaveFootprintToBoard( false ) )
695  {
696  m_footprintNameWhenLoaded = footprintName;
697  return true;
698  }
699  else
700  return false;
701  }
702  else if( libraryName.IsEmpty() || footprintName.IsEmpty() )
703  {
704  if( SaveFootprintAs( aModule ) )
705  {
706  m_footprintNameWhenLoaded = footprintName;
707  SyncLibraryTree( true );
708  return true;
709  }
710  else
711  return false;
712  }
713 
714  FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs();
715 
716  // Legacy libraries are readable, but modifying legacy format is not allowed
717  // So prompt the user if he try to add/replace a footprint in a legacy lib
718  wxString libfullname = tbl->FindRow( libraryName )->GetFullURI();
719 
720  if( IO_MGR::GuessPluginTypeFromLibPath( libfullname ) == IO_MGR::LEGACY )
721  {
723  return false;
724  }
725 
726  if( nameChanged )
727  {
728  LIB_ID oldFPID( libraryName, m_footprintNameWhenLoaded );
729  DeleteModuleFromLibrary( oldFPID, false );
730  }
731 
732  if( !SaveFootprintInLibrary( aModule, libraryName ) )
733  return false;
734 
735  if( nameChanged )
736  {
737  m_footprintNameWhenLoaded = footprintName;
738  SyncLibraryTree( true );
739  }
740 
741  return true;
742 }
743 
744 
745 bool FOOTPRINT_EDIT_FRAME::SaveFootprintInLibrary( MODULE* aModule, const wxString& aLibraryName )
746 {
747  try
748  {
749  aModule->SetFPID( LIB_ID( wxEmptyString, aModule->GetFPID().GetLibItemName() ) );
750 
751  Prj().PcbFootprintLibs()->FootprintSave( aLibraryName, aModule );
752 
753  aModule->SetFPID( LIB_ID( aLibraryName, aModule->GetFPID().GetLibItemName() ) );
754  return true;
755  }
756  catch( const IO_ERROR& ioe )
757  {
758  DisplayError( this, ioe.What() );
759 
760  aModule->SetFPID( LIB_ID( aLibraryName, aModule->GetFPID().GetLibItemName() ) );
761  return false;
762  }
763 }
764 
765 
767 {
768  // update module in the current board,
769  // not just add it to the board with total disregard for the netlist...
770  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB_EDITOR, false );
771 
772  if( pcbframe == NULL ) // happens when the board editor is not active (or closed)
773  {
774  ShowInfoBarError( _( "No board currently open." ) );
775  return false;
776  }
777 
778  BOARD* mainpcb = pcbframe->GetBoard();
779  MODULE* source_module = NULL;
780  MODULE* module_in_edit = GetBoard()->GetFirstModule();
781 
782  // Search the old module (source) if exists
783  // Because this source could be deleted when editing the main board...
784  if( module_in_edit->GetLink() != niluuid ) // this is not a new module ...
785  {
786  source_module = nullptr;
787 
788  for( MODULE* mod : mainpcb->Modules() )
789  {
790  if( module_in_edit->GetLink() == mod->m_Uuid )
791  {
792  source_module = mod;
793  break;
794  }
795  }
796  }
797 
798  if( !aAddNew && source_module == NULL ) // source not found
799  {
800  DisplayError( this, _( "Unable to find the footprint on the main board.\nCannot save." ) );
801  return false;
802  }
803 
806  BOARD_COMMIT commit( pcbframe );
807 
808  // Create the "new" module
809  MODULE* newmodule = new MODULE( *module_in_edit );
810  const_cast<KIID&>( newmodule->m_Uuid ) = KIID();
811 
812  newmodule->SetParent( mainpcb );
813  newmodule->SetLink( niluuid );
814 
815  if( source_module ) // this is an update command
816  {
817  // In the main board the new module replaces the old module (pos, orient, ref, value,
818  // connections and properties are kept) and the source_module (old module) is deleted
819  pcbframe->Exchange_Module( source_module, newmodule, commit );
820  const_cast<KIID&>( newmodule->m_Uuid ) = module_in_edit->GetLink();
821  commit.Push( wxT( "Update module" ) );
822  }
823  else // This is an insert command
824  {
825  KIGFX::VIEW_CONTROLS* viewControls = pcbframe->GetCanvas()->GetViewControls();
826  VECTOR2D cursorPos = viewControls->GetCursorPosition();
827 
828  commit.Add( newmodule );
829  viewControls->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false );
830  pcbframe->PlaceModule( newmodule );
831  newmodule->SetPosition( wxPoint( 0, 0 ) );
832  viewControls->SetCrossHairCursorPosition( cursorPos, false );
833  const_cast<KIID&>( newmodule->m_Uuid ) = KIID();
834  commit.Push( wxT( "Insert module" ) );
835 
836  pcbframe->Raise();
837  pcbframe->GetToolManager()->RunAction( PCB_ACTIONS::placeModule, true, newmodule );
838  }
839 
840  newmodule->ClearFlags();
841 
842  return true;
843 }
844 
845 
847 {
848  if( aModule == NULL )
849  return false;
850 
851  FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs();
852 
853  SetMsgPanel( aModule );
854 
855  wxString libraryName = aModule->GetFPID().GetLibNickname();
856  wxString footprintName = aModule->GetFPID().GetLibItemName();
857  bool updateValue = ( aModule->GetValue() == footprintName );
858 
859  wxArrayString headers;
860  std::vector<wxArrayString> itemsToDisplay;
861  std::vector<wxString> nicknames = tbl->GetLogicalLibs();
862 
863  headers.Add( _( "Nickname" ) );
864  headers.Add( _( "Description" ) );
865 
866  for( const wxString& nickname : nicknames )
867  {
868  wxArrayString item;
869  item.Add( nickname );
870  item.Add( tbl->GetDescription( nickname ) );
871  itemsToDisplay.push_back( item );
872  }
873 
874  EDA_LIST_DIALOG dlg( this, _( "Save Footprint" ), headers, itemsToDisplay, libraryName );
875  dlg.SetListLabel( _( "Save in library:" ) );
876  dlg.SetOKLabel( _( "Save" ) );
877 
878  wxBoxSizer* bNameSizer = new wxBoxSizer( wxHORIZONTAL );
879 
880  wxStaticText* label = new wxStaticText( &dlg, wxID_ANY, _( "Name:" ),
881  wxDefaultPosition, wxDefaultSize, 0 );
882  bNameSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 );
883 
884  wxTextCtrl* nameTextCtrl = new wxTextCtrl( &dlg, wxID_ANY, footprintName,
885  wxDefaultPosition, wxDefaultSize, 0 );
886  bNameSizer->Add( nameTextCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
887 
888  wxTextValidator nameValidator( wxFILTER_EXCLUDE_CHAR_LIST );
889  nameValidator.SetCharExcludes( MODULE::StringLibNameInvalidChars( false ) );
890  nameTextCtrl->SetValidator( nameValidator );
891 
892  wxSizer* mainSizer = dlg.GetSizer();
893  mainSizer->Prepend( bNameSizer, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5 );
894 
895  // Move nameTextCtrl to the head of the tab-order
896  if( dlg.GetChildren().DeleteObject( nameTextCtrl ) )
897  dlg.GetChildren().Insert( nameTextCtrl );
898 
899  dlg.SetInitialFocus( nameTextCtrl );
900 
901  dlg.Layout();
902  mainSizer->Fit( &dlg );
903 
904  if( dlg.ShowModal() != wxID_OK )
905  return false; // canceled by user
906 
907  libraryName = dlg.GetTextSelection();
908 
909  if( libraryName.IsEmpty() )
910  {
911  DisplayError( NULL, _( "No library specified. Footprint could not be saved." ) );
912  return false;
913  }
914 
915  footprintName = nameTextCtrl->GetValue();
916  footprintName.Trim( true );
917  footprintName.Trim( false );
918 
919  if( footprintName.IsEmpty() )
920  {
921  DisplayError( NULL, _( "No footprint name specified. Footprint could not be saved." ) );
922  return false;
923  }
924 
925  aModule->SetFPID( LIB_ID( libraryName, footprintName ) );
926 
927  if( updateValue )
928  aModule->SetValue( footprintName );
929 
930  // Legacy libraries are readable, but modifying legacy format is not allowed
931  // So prompt the user if he try to add/replace a footprint in a legacy lib
932  wxString libfullname = Prj().PcbFootprintLibs()->FindRow( libraryName )->GetFullURI();
934 
935  if( piType == IO_MGR::LEGACY )
936  {
938  return false;
939  }
940 
941  bool module_exists = tbl->FootprintExists( libraryName, footprintName );
942 
943  if( module_exists )
944  {
945  wxString msg = wxString::Format( _( "Footprint %s already exists in %s." ),
946  footprintName,
947  libraryName );
948  KIDIALOG chkdlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
949  chkdlg.SetOKLabel( _( "Overwrite" ) );
950 
951  if( chkdlg.ShowModal() == wxID_CANCEL )
952  return false;
953  }
954 
955  if( !SaveFootprintInLibrary( aModule, libraryName ) )
956  return false;
957 
958  // Once saved-as a board footprint is no longer a board footprint
959  aModule->SetLink( niluuid );
960 
961  wxString fmt = module_exists ? _( "Component \"%s\" replaced in \"%s\"" ) :
962  _( "Component \"%s\" added in \"%s\"" );
963 
964  wxString msg = wxString::Format( fmt, footprintName.GetData(), libraryName.GetData() );
965  SetStatusText( msg );
966  updateTitle();
968 
969  return true;
970 }
971 
972 
974 {
975  if( GetScreen()->IsModify() && m_revertModule )
976  {
977  wxString msg = wxString::Format( _( "Revert \"%s\" to last version saved?" ),
978  GetChars( GetLoadedFPID().GetLibItemName() ) );
979 
980  if( ConfirmRevertDialog( this, msg ) )
981  {
982  Clear_Pcb( false );
983  AddModuleToBoard( (MODULE*) m_revertModule->Clone() );
984 
985  Zoom_Automatique( false );
986 
987  Update3DView( true );
988 
990  GetScreen()->ClrModify();
991 
992  updateView();
993  GetCanvas()->Refresh();
994 
995  return true;
996  }
997  }
998 
999  return false;
1000 }
1001 
1002 
1003 MODULE* PCB_BASE_FRAME::CreateNewModule( const wxString& aModuleName )
1004 {
1005  wxString moduleName = aModuleName;
1006 
1007  // Ask for the new module name
1008  if( moduleName.IsEmpty() )
1009  {
1010  WX_TEXT_ENTRY_DIALOG dlg( this, _( "Enter footprint name:" ), _( "New Footprint" ),
1011  moduleName );
1012  dlg.SetTextValidator( MODULE_NAME_CHAR_VALIDATOR( &moduleName ) );
1013 
1014  if( dlg.ShowModal() != wxID_OK )
1015  return NULL; //Aborted by user
1016  }
1017 
1018  moduleName.Trim( true );
1019  moduleName.Trim( false );
1020 
1021  if( moduleName.IsEmpty() )
1022  {
1023  DisplayInfoMessage( this, _( "No footprint name defined." ) );
1024  return NULL;
1025  }
1026 
1027  // Creates the new module and add it to the head of the linked list of modules
1028  MODULE* module = new MODULE( GetBoard() );
1029 
1030  // Update parameters: timestamp ...
1031  module->SetLastEditTime();
1032 
1033  // Update its name in lib
1034  module->SetFPID( LIB_ID( wxEmptyString, moduleName ) );
1035 
1036  PCB_LAYER_ID txt_layer;
1037  wxPoint default_pos;
1039 
1040  module->Reference().SetText( settings.m_DefaultFPTextItems[0].m_Text );
1041  module->Reference().SetVisible( settings.m_DefaultFPTextItems[0].m_Visible );
1042  txt_layer = (PCB_LAYER_ID) settings.m_DefaultFPTextItems[0].m_Layer;
1043  module->Reference().SetLayer( txt_layer );
1044  default_pos.y -= settings.GetTextSize( txt_layer ).y / 2;
1045  module->Reference().SetPosition( default_pos );
1046  default_pos.y += settings.GetTextSize( txt_layer ).y;
1047 
1048  module->Value().SetText( settings.m_DefaultFPTextItems[1].m_Text );
1049  module->Value().SetVisible( settings.m_DefaultFPTextItems[1].m_Visible );
1050  txt_layer = (PCB_LAYER_ID) settings.m_DefaultFPTextItems[1].m_Layer;
1051  module->Value().SetLayer( txt_layer );
1052  default_pos.y += settings.GetTextSize( txt_layer ).y / 2;
1053  module->Value().SetPosition( default_pos );
1054  default_pos.y += settings.GetTextSize( txt_layer ).y;
1055 
1056  for( size_t i = 2; i < settings.m_DefaultFPTextItems.size(); ++i )
1057  {
1058  TEXTE_MODULE* textItem = new TEXTE_MODULE( module );
1059  textItem->SetText( settings.m_DefaultFPTextItems[i].m_Text );
1060  textItem->SetVisible( settings.m_DefaultFPTextItems[i].m_Visible );
1061  txt_layer = (PCB_LAYER_ID) settings.m_DefaultFPTextItems[i].m_Layer;
1062  textItem->SetLayer( txt_layer );
1063  default_pos.y += settings.GetTextSize( txt_layer ).y / 2;
1064  textItem->SetPosition( default_pos );
1065  default_pos.y += settings.GetTextSize( txt_layer ).y;
1066  module->GraphicalItems().push_back( textItem );
1067  }
1068 
1069  if( module->GetReference().IsEmpty() )
1070  module->SetReference( moduleName );
1071 
1072  if( module->GetValue().IsEmpty() )
1073  module->SetValue( moduleName );
1074 
1075  module->RunOnChildren(
1076  [&] ( BOARD_ITEM* aChild )
1077  {
1078  if( aChild->Type() == PCB_MODULE_TEXT_T )
1079  {
1080  TEXTE_MODULE* textItem = static_cast<TEXTE_MODULE*>( aChild );
1081  PCB_LAYER_ID layer = textItem->GetLayer();
1082 
1083  textItem->SetTextThickness( settings.GetTextThickness( layer ) );
1084  textItem->SetTextSize( settings.GetTextSize( layer ) );
1085  textItem->SetItalic( settings.GetTextItalic( layer ) );
1086  textItem->SetKeepUpright( settings.GetTextUpright( layer ) );
1087  }
1088  } );
1089 
1090  SetMsgPanel( module );
1091  return module;
1092 }
1093 
1094 
1095 wxString PCB_BASE_FRAME::SelectLibrary( const wxString& aNicknameExisting )
1096 {
1097  wxArrayString headers;
1098 
1099  headers.Add( _( "Nickname" ) );
1100  headers.Add( _( "Description" ) );
1101 
1102  FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs();
1103 
1104  std::vector< wxArrayString > itemsToDisplay;
1105  std::vector< wxString > nicknames = fptbl->GetLogicalLibs();
1106 
1107  for( const wxString& nickname : nicknames )
1108  {
1109  wxArrayString item;
1110 
1111  item.Add( nickname );
1112  item.Add( fptbl->GetDescription( nickname ) );
1113 
1114  itemsToDisplay.push_back( item );
1115  }
1116 
1117  EDA_LIST_DIALOG dlg( this, _( "Select Library" ), headers, itemsToDisplay, aNicknameExisting );
1118 
1119  if( dlg.ShowModal() != wxID_OK )
1120  return wxEmptyString;
1121 
1122  return dlg.GetTextSelection();
1123 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:62
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:239
void SetLink(const KIID &aLink)
Definition: class_module.h:568
void BuildListOfNets()
Definition: class_board.h:662
static TOOL_ACTION placeModule
Definition: pcb_actions.h:155
MODULE * try_load_footprint(const wxFileName &aFileName, IO_MGR::PCB_FILE_T aFileType, const wxString &aName)
Try to load a footprint, returning NULL if the file couldn't be accessed.
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
void SetKeepUpright(bool aKeepUpright)
TEXTE_MODULE & Reference()
Definition: class_module.h:492
void DoNotShowCheckbox(wxString file, int line)
Shows the 'do not show again' checkbox
Definition: confirm.cpp:53
bool ConfirmRevertDialog(wxWindow *parent, const wxString &aMessage)
Display a confirmation dialog for a revert action.
Definition: confirm.cpp:190
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_holder.h:56
static const wxString INFO_LEGACY_LIB_WARN_EDIT(_("Writing/modifying legacy libraries (.mod files) is not allowed\n" "Please save the current library to the new .pretty format\n" "and update your footprint lib table\n" "to save your footprint (a .kicad_mod file) in the .pretty library folder"))
void ReCreateHToolbar() override
Create the main horizontal toolbar for the footprint editor.
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Returns the BOARD_DESIGN_SETTINGS for the open project Overloaded in FOOTPRINT_EDIT_FRAME.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
BOARD_ITEM * Parse(const wxString &aClipboardSourceInput)
std::vector< TEXT_ITEM_INFO > m_DefaultFPTextItems
wxString GetTextSelection(int aColumn=0)
Function GetTextSelection return the selected text from aColumn in the wxListCtrl in the dialog.
PCB_IO is a PLUGIN derivation for saving and loading Pcbnew s-expression formatted files.
KIGFX::VIEW_CONTROLS * GetViewControls() const
Function GetViewControls() Returns a pointer to the VIEW_CONTROLS instance used in the panel.
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction)
Function RunOnChildren.
wxString m_mruPath
PROJECT holds project specific data.
Definition: project.h:61
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:114
char * StrPurge(char *text)
Remove leading and training spaces, tabs and end of line chars in text.
Definition: string.cpp:365
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition: confirm.h:44
FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Adds aRow if it does not already exist or if doReplace is true.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
bool SaveFootprintToBoard(bool aAddNew)
This file is part of the common library.
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
const std::string KiCadFootprintFileExtension
static wxFileName getFootprintFilenameFromUser(wxWindow *aParent, const wxString &aLastPath)
Prompt the user for a module file to open.
void SetOKLabel(const wxString &aLabel)
COMMIT & Add(EDA_ITEM *aItem)
Adds a new item to the model
Definition: commit.h:78
FP_LIB_TABLE GFootprintTable
!!!!!!!!!!!!!! This code is obsolete because of the merge into pcbnew, don't bother with it.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void SetItalic(bool isItalic)
Definition: eda_text.h:179
Component library viewer main window.
void SetTextValidator(wxTextValidatorStyle style)
void SetVisible(bool aVisible)
Definition: eda_text.h:185
const wxString GetValue() const
Function GetValue.
Definition: class_module.h:476
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:140
EDA_LIST_DIALOG.
const LIB_ID & GetFPID() const
Definition: class_module.h:228
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:238
static const wxChar * StringLibNameInvalidChars(bool aUserReadable)
static function StringLibNameInvalidChars Test for validity of the name in a library of the footprint...
DRAWINGS & GraphicalItems()
Definition: class_module.h:191
static const wxString ShowType(PCB_FILE_T aFileType)
Function ShowType returns a brief name for a plugin, given aFileType enum.
Definition: io_mgr.cpp:81
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
int GetTextThickness(PCB_LAYER_ID aLayer) const
Function GetTextThickness Returns the default text thickness from the layer class for the given layer...
bool IsValid() const
Definition: lib_id.h:171
MODULE * CreateNewModule(const wxString &aModuleName)
Function CreateNewModule Creates a new module or footprint, at position 0,0 The new module contains o...
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:124
wxString AllFilesWildcard()
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:114
bool DeleteModuleFromLibrary(const LIB_ID &aFPID, bool aConfirm)
Delete the given module from its library.
WHITESPACE_FILTER_READER reads lines of text from another LINE_READER, but only returns non-comment l...
Definition: filter_reader.h:71
Geda PCB file formats.
Definition: io_mgr.h:64
static PCB_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath)
Function GuessPluginTypeFromLibPath returns a plugin type given a footprint library's libPath.
Definition: io_mgr.cpp:128
virtual void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:196
This file contains miscellaneous commonly used macros and functions.
const wxString GetReference() const
Function GetReference.
Definition: class_module.h:451
bool GetTextUpright(PCB_LAYER_ID aLayer) const
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
bool GetTextItalic(PCB_LAYER_ID aLayer) const
RELEASER releases a PLUGIN in the context of a potential thrown exception, through its destructor.
Definition: io_mgr.h:580
virtual void Zoom_Automatique(bool aWarpPointer)
Redraw the screen with best zoom level and the best centering that shows all the page or the board.
void SyncLibraryTree(bool aProgress)
Synchronize the footprint library tree to the current state of the footprint library table.
Definition: common.h:68
std::unique_ptr< MODULE > m_revertModule
PCB_LAYER_ID
A quick note on layer IDs:
#define FOOTPRINT_LIBRARY_HEADER
Definition: legacy_plugin.h:38
bool Clear_Pcb(bool aQuery)
Delete all and reinitialize the current board.
Definition: initpcb.cpp:95
FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:121
#define NULL
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
VTBL_ENTRY KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=NULL)
Function Player returns the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:343
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:29
MODULES & Modules()
Definition: class_board.h:247
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
std::string GetStringOutput(bool doClear)
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:491
const wxString GetDescription(const wxString &aNickname)
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
wxString CreateNewLibrary(const wxString &aLibName=wxEmptyString, const wxString &aProposedName=wxEmptyString)
If a library name is given, creates a new footprint library in the project folder with the given name...
KIID niluuid(0)
void SetLastEditTime(timestamp_t aTime)
Definition: class_module.h:357
bool AddLibrary(const wxString &aLibName=wxEmptyString)
Function AddLibrary Add an existing library to either the global or project library table.
This class provides a custom wxValidator object for limiting the allowable characters when defining f...
Definition: validators.h:63
wxString ModLegacyExportFileWildcard()
MODULE * GetFirstModule() const
Gets the first module in the list (used in footprint viewer/editor) or NULL if none.
Definition: class_board.h:308
Definition of file extensions used in Kicad.
Helper dialog and control classes.
bool LibraryFileBrowser(bool doOpen, wxFileName &aFilename, const wxString &wildcard, const wxString &ext, bool isDirectory=false)
VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (such a...
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
void SetReference(const wxString &aReference)
Function SetReference.
Definition: class_module.h:461
static IO_MGR::PCB_FILE_T detect_file_type(FILE *aFile, const wxFileName &aFileName, wxString *aName)
Read a file to detect the type.
virtual void SetPosition(const wxPoint &aPos) override
virtual void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true)=0
Moves the graphic crosshair cursor to the requested position expressed in world coordinates.
void SetPosition(const wxPoint &aPos) override
FormatType fileType(const char *aFileName)
Definition: loadmodel.cpp:271
void ShowInfoBarError(const wxString &aErrorMsg)
VTBL_ENTRY bool IsNullProject() const
Checks if this project is a null project (i.e.
Definition: project.cpp:136
static MODULE * parse_module_kicad(const wxFileName &aFileName)
Parse a KICAD footprint.
static MODULE * parse_module_with_plugin(const wxFileName &aFileName, IO_MGR::PCB_FILE_T aFileType, const wxString &aName)
Parse a footprint using a PLUGIN.
#define FOOTPRINT_LIBRARY_HEADER_CNT
Definition: legacy_plugin.h:39
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
void Export_Module(MODULE *aModule)
Create a file containing only one footprint.
VTBL_ENTRY void SetRString(RSTRING_T aStringId, const wxString &aString)
Function SetRString stores a "retained string", which is any session and project specific string iden...
Definition: project.cpp:214
const KIID m_Uuid
Definition: base_struct.h:162
VTBL_ENTRY FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
Definition: project.cpp:286
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
bool SaveFootprintInLibrary(MODULE *aModule, const wxString &aLibraryName)
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
bool SaveFootprintAs(MODULE *aModule)
void updateTitle()
Updates window title according to getLibNickName().
VTBL_ENTRY const wxString & GetRString(RSTRING_T aStringId)
Function GetRString returns a "retained string", which is any session and project specific string ide...
Definition: project.cpp:229
wxString KiCadFootprintLibPathWildcard()
void Exchange_Module(MODULE *aSrc, MODULE *aDest, BOARD_COMMIT &aCommit, bool deleteExtraTexts=true, bool resetTextLayers=true, bool resetTextEffects=true, bool resetFabricationAttrs=true, bool reset3DModels=true)
Function Exchange_Module Replaces OldModule by NewModule, using OldModule settings: position,...
#define CTL_FOR_LIBRARY
Format output for a footprint library instead of clipboard or BOARD.
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:50
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:153
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:56
see class PGM_BASE
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201
void ArchiveModulesOnBoard(bool aStoreInNewLib, const wxString &aLibName=wxEmptyString, wxString *aLibPath=NULL)
Function ArchiveModulesOnBoard Save modules in a library:
LIB_ID GetLoadedFPID() const
Return the LIB_ID of the part being edited.
Information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:176
#define _(s)
Definition: 3d_actions.cpp:33
static PLUGIN * PluginFind(PCB_FILE_T aFileType)
Function PluginFind returns a PLUGIN which the caller can use to import, export, save,...
Definition: io_mgr.cpp:62
void updateView()
Reloads displayed items and sets view.
bool SaveFootprint(MODULE *aModule)
Save in an existing library a given footprint.
PCB_EDIT_FRAME is the main frame for Pcbnew.
void ClrModify()
Definition: base_screen.h:101
void SetValue(const wxString &aValue)
Function SetValue.
Definition: class_module.h:485
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Executes the changes.
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
KIID GetLink() const
Definition: class_module.h:567
static const wxString INFO_LEGACY_LIB_WARN_DELETE(_("Modifying legacy libraries (.mod files) is not allowed\n" "Please save the current library under the new .pretty format\n" "and update your footprint lib table\n" "before deleting a footprint"))
int ShowModal() override
Definition: confirm.cpp:95
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:233
FOOTPRINT_EDITOR_SETTINGS * GetSettings()
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:158
wxString SelectLibrary(const wxString &aNicknameExisting)
Function SelectLibrary puts up a dialog and allows the user to pick a library, for unspecified use.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:78
void AddModuleToBoard(MODULE *module) override
Override from PCB_BASE_EDIT_FRAME which adds a module to the editor's dummy board,...
BOARD * GetBoard() const
void PlaceModule(MODULE *aModule, bool aRecreateRatsnest=true)
Function PlaceModule places aModule at the current cursor position and updates module coordinates wit...
void Format(BOARD_ITEM *aItem, int aNestLevel=0) const
Output aItem to aFormatter in s-expression format.
virtual void Update3DView(bool aForceReload, const wxString *aTitle=nullptr)
Update the 3D view, if the viewer is opened by this frame.
SAVE_T FootprintSave(const wxString &aNickname, const MODULE *aFootprint, bool aOverwrite=true)
Function FootprintSave.
void FootprintDelete(const wxString &aNickname, const wxString &aFootprintName)
Function FootprintDelete.
int SelectSingleOption(wxWindow *aParent, const wxString &aTitle, const wxString &aMessage, const wxArrayString &aOptions)
Displays a dialog with radioboxes asking the user to select an option.
Definition: confirm.cpp:293
MODULE * Import_Module(const wxString &aName=wxT(""))
Read a file containing only one footprint.
PCB_FILE_T
Enum PCB_FILE_T is a set of file types that the IO_MGR knows about, and for which there has been a pl...
Definition: io_mgr.h:54
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:267
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:283
const std::string KiCadFootprintLibPathExtension
virtual void ClearUndoRedoList()
Function ClearUndoRedoList clear undo and redo list, using ClearUndoORRedoList() picked items are del...
void SetFPID(const LIB_ID &aFPID)
Definition: class_module.h:229
wxString KiCadFootprintLibFileWildcard()
Custom text control validator definitions.
wxSize GetTextSize(PCB_LAYER_ID aLayer) const
Function GetTextSize Returns the default text size from the layer class for the given layer.
wxString NormalizePath(const wxFileName &aFilePath, const ENV_VAR_MAP *aEnvVars, const wxString &aProjectPath)
Normalizes a file path to an environmental variable, if possible.
Definition: env_paths.cpp:68
bool FootprintExists(const wxString &aNickname, const wxString &aFootprintName)
Function FootprintExists.
static wxString GetGlobalTableFileName()
Function GetGlobalTableFileName.
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
wxString GedaPcbFootprintLibFileWildcard()
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193
S-expression Pcbnew file format.
Definition: io_mgr.h:57
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
void SetListLabel(const wxString &aLabel)