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 {
380  // Kicad cannot write legacy format libraries, only .pretty new format
381  // because the legacy format cannot handle current features.
382  // The footprint library is actually a directory
383 
384  wxString initialPath = wxPathOnly( Prj().GetProjectFullName() );
385  wxFileName fn;
386  bool doAdd = false;
387 
388  if( aLibName.IsEmpty() )
389  {
390  fn = initialPath;
391 
392  if( !LibraryFileBrowser( false, fn,
394  {
395  return wxEmptyString;
396  }
397 
398  doAdd = true;
399  }
400  else
401  {
402  fn = aLibName;
403 
404  if( !fn.IsAbsolute() )
405  {
406  fn.SetName( aLibName );
407  fn.MakeAbsolute( initialPath );
408  }
409 
410  // Enforce the .pretty extension:
411  fn.SetExt( KiCadFootprintLibPathExtension );
412  }
413 
414  // We can save fp libs only using IO_MGR::KICAD_SEXP format (.pretty libraries)
416  wxString libPath = fn.GetFullPath();
417 
418  try
419  {
420  PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) );
421 
422  bool writable = false;
423  bool exists = false;
424 
425  try
426  {
427  writable = pi->IsFootprintLibWritable( libPath );
428  exists = true; // no exception was thrown, lib must exist.
429  }
430  catch( const IO_ERROR& )
431  { }
432 
433  if( exists )
434  {
435  if( !writable )
436  {
437  wxString msg = wxString::Format( _( "Library \"%s\" is read only, not writable" ),
438  libPath );
439  DisplayError( this, 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  wxArrayString libTableNames;
494 
495  libTableNames.Add( _( "Global" ) );
496  libTableNames.Add( _( "Project" ) );
497 
498  switch( SelectSingleOption( this, _( "Select Library Table" ),
499  _( "Choose the Library Table to add the library to:" ),
500  libTableNames ) )
501  {
502  case 0: saveInGlobalTable = true; break;
503  case 1: saveInProjectTable = true; break;
504  default: return false;
505  }
506 
507  wxString type = IO_MGR::ShowType( IO_MGR::GuessPluginTypeFromLibPath( libPath ) );
508 
509  // try to use path normalized to an environmental variable or project path
510  wxString normalizedPath = NormalizePath( libPath, &Pgm().GetLocalEnvVariables(), &Prj() );
511 
512  if( normalizedPath.IsEmpty() )
513  normalizedPath = libPath;
514 
515  try
516  {
517  if( saveInGlobalTable )
518  {
519  auto row = new FP_LIB_TABLE_ROW( libName, normalizedPath, type, wxEmptyString );
520  GFootprintTable.InsertRow( row );
522  }
523  else if( saveInProjectTable )
524  {
525  auto row = new FP_LIB_TABLE_ROW( libName, normalizedPath, type, wxEmptyString );
526  Prj().PcbFootprintLibs()->InsertRow( row );
527  Prj().PcbFootprintLibs()->Save( Prj().FootprintLibTblName() );
528  }
529  }
530  catch( const IO_ERROR& ioe )
531  {
532  DisplayError( this, ioe.What() );
533  return false;
534  }
535 
536  auto editor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_FOOTPRINT_EDITOR, false );
537 
538  if( editor )
539  {
540  LIB_ID libID( libName, wxEmptyString );
541  editor->SyncLibraryTree( true );
542  editor->FocusOnLibID( libID );
543  }
544 
545  auto viewer = (FOOTPRINT_VIEWER_FRAME*) Kiway().Player( FRAME_FOOTPRINT_VIEWER, false );
546 
547  if( viewer )
548  viewer->ReCreateLibraryList();
549 
550  return true;
551 }
552 
553 
554 bool FOOTPRINT_EDIT_FRAME::DeleteModuleFromLibrary( const LIB_ID& aFPID, bool aConfirm )
555 {
556  if( !aFPID.IsValid() )
557  return false;
558 
559  wxString nickname = aFPID.GetLibNickname();
560  wxString fpname = aFPID.GetLibItemName();
561 
562  // Legacy libraries are readable, but modifying legacy format is not allowed
563  // So prompt the user if he try to delete a footprint from a legacy lib
564  wxString libfullname = Prj().PcbFootprintLibs()->FindRow( nickname )->GetFullURI();
565 
566  if( IO_MGR::GuessPluginTypeFromLibPath( libfullname ) == IO_MGR::LEGACY )
567  {
569  return false;
570  }
571 
572  if( !Prj().PcbFootprintLibs()->IsFootprintLibWritable( nickname ) )
573  {
574  wxString msg = wxString::Format( _( "Library '%s' is read only" ), nickname );
575  DisplayError( this, msg );
576  return false;
577  }
578 
579  // Confirmation
580  wxString msg = wxString::Format( _( "Delete footprint '%s' from library '%s'?" ),
581  fpname.GetData(),
582  nickname.GetData() );
583 
584  if( aConfirm && !IsOK( this, msg ) )
585  return false;
586 
587  try
588  {
589  Prj().PcbFootprintLibs()->FootprintDelete( nickname, fpname );
590  }
591  catch( const IO_ERROR& ioe )
592  {
593  DisplayError( this, ioe.What() );
594  return false;
595  }
596 
597  msg.Printf( _( "Footprint '%s' deleted from library '%s'" ),
598  fpname.GetData(),
599  nickname.GetData() );
600 
601  SetStatusText( msg );
602 
603  return true;
604 }
605 
606 
607 void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aStoreInNewLib, const wxString& aLibName,
608  wxString* aLibPath )
609 {
610  if( GetBoard()->GetFirstModule() == NULL )
611  {
612  DisplayInfoMessage( this, _( "No footprints to archive!" ) );
613  return;
614  }
615 
616  wxString footprintName;
617 
618  if( !aStoreInNewLib )
619  {
620  // The footprints are saved in an existing .pretty library in the fp lib table
621  PROJECT& prj = Prj();
622  wxString last_nickname = prj.GetRString( PROJECT::PCB_LIB_NICKNAME );
623  wxString nickname = SelectLibrary( last_nickname );
624 
625  if( !nickname ) // Aborted
626  return;
627 
628  prj.SetRString( PROJECT::PCB_LIB_NICKNAME, nickname );
629 
630  try
631  {
632  FP_LIB_TABLE* tbl = prj.PcbFootprintLibs();
633 
634  for( auto curr_fp : GetBoard()->Modules() )
635  {
636  if( !curr_fp->GetFPID().GetLibItemName().empty() ) // Can happen with old boards.
637  tbl->FootprintSave( nickname, curr_fp, false );
638  }
639  }
640  catch( const IO_ERROR& ioe )
641  {
642  DisplayError( this, ioe.What() );
643  }
644  }
645  else
646  {
647  // The footprints are saved in a new .pretty library.
648  // If this library already exists, all previous footprints will be deleted
649  wxString libPath = CreateNewLibrary( aLibName );
650 
651  if( libPath.IsEmpty() ) // Aborted
652  return;
653 
654 
655  if( aLibPath ) *aLibPath = libPath;
656 
658  PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) );
659 
660  for( auto curr_fp : GetBoard()->Modules() )
661  {
662  try
663  {
664  if( !curr_fp->GetFPID().GetLibItemName().empty() ) // Can happen with old boards.
665  pi->FootprintSave( libPath, curr_fp );
666  }
667  catch( const IO_ERROR& ioe )
668  {
669  DisplayError( this, ioe.What() );
670  }
671  }
672  }
673 }
674 
675 
677 {
678  if( !aModule ) // Happen if no footprint loaded
679  return false;
680 
681  wxString libraryName = aModule->GetFPID().GetLibNickname();
682  wxString footprintName = aModule->GetFPID().GetLibItemName();
683  bool nameChanged = m_footprintNameWhenLoaded != footprintName;
684 
685  if( aModule->GetLink() != niluuid )
686  {
687  if( SaveFootprintToBoard( false ) )
688  {
689  m_footprintNameWhenLoaded = footprintName;
690  return true;
691  }
692  else
693  return false;
694  }
695  else if( libraryName.IsEmpty() || footprintName.IsEmpty() )
696  {
697  if( SaveFootprintAs( aModule ) )
698  {
699  m_footprintNameWhenLoaded = footprintName;
700  SyncLibraryTree( true );
701  return true;
702  }
703  else
704  return false;
705  }
706 
707  FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs();
708 
709  // Legacy libraries are readable, but modifying legacy format is not allowed
710  // So prompt the user if he try to add/replace a footprint in a legacy lib
711  wxString libfullname = tbl->FindRow( libraryName )->GetFullURI();
712 
713  if( IO_MGR::GuessPluginTypeFromLibPath( libfullname ) == IO_MGR::LEGACY )
714  {
716  return false;
717  }
718 
719  if( nameChanged )
720  {
721  LIB_ID oldFPID( libraryName, m_footprintNameWhenLoaded );
722  DeleteModuleFromLibrary( oldFPID, false );
723  }
724 
725  if( !SaveFootprintInLibrary( aModule, libraryName ) )
726  return false;
727 
728  if( nameChanged )
729  {
730  m_footprintNameWhenLoaded = footprintName;
731  SyncLibraryTree( true );
732  }
733 
734  return true;
735 }
736 
737 
738 bool FOOTPRINT_EDIT_FRAME::SaveFootprintInLibrary( MODULE* aModule, const wxString& aLibraryName )
739 {
740  try
741  {
742  aModule->SetFPID( LIB_ID( wxEmptyString, aModule->GetFPID().GetLibItemName() ) );
743 
744  Prj().PcbFootprintLibs()->FootprintSave( aLibraryName, aModule );
745 
746  aModule->SetFPID( LIB_ID( aLibraryName, aModule->GetFPID().GetLibItemName() ) );
747  return true;
748  }
749  catch( const IO_ERROR& ioe )
750  {
751  DisplayError( this, ioe.What() );
752 
753  aModule->SetFPID( LIB_ID( aLibraryName, aModule->GetFPID().GetLibItemName() ) );
754  return false;
755  }
756 }
757 
758 
760 {
761  // update module in the current board,
762  // not just add it to the board with total disregard for the netlist...
763  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB_EDITOR, false );
764 
765  if( pcbframe == NULL ) // happens when the board editor is not active (or closed)
766  {
767  DisplayErrorMessage( this, _( "No board currently open." ) );
768  return false;
769  }
770 
771  BOARD* mainpcb = pcbframe->GetBoard();
772  MODULE* source_module = NULL;
773  MODULE* module_in_edit = GetBoard()->GetFirstModule();
774 
775  // Search the old module (source) if exists
776  // Because this source could be deleted when editing the main board...
777  if( module_in_edit->GetLink() != niluuid ) // this is not a new module ...
778  {
779  source_module = nullptr;
780 
781  for( auto mod : mainpcb->Modules() )
782  {
783  if( module_in_edit->GetLink() == mod->m_Uuid )
784  {
785  source_module = mod;
786  break;
787  }
788  }
789  }
790 
791  if( !aAddNew && source_module == NULL ) // source not found
792  {
793  DisplayError( this, _( "Unable to find the footprint on the main board.\nCannot save." ) );
794  return false;
795  }
796 
797  if( aAddNew && source_module != NULL )
798  {
799  DisplayError( this, _( "Footprint already exists on board." ) );
800  return false;
801  }
802 
805  BOARD_COMMIT commit( pcbframe );
806 
807  // Create the "new" module
808  MODULE* newmodule = new MODULE( *module_in_edit );
809  newmodule->SetParent( mainpcb );
810  newmodule->SetLink( niluuid );
811 
812  if( source_module ) // this is an update command
813  {
814  // In the main board,
815  // the new module replace the old module (pos, orient, ref, value
816  // and connexions are kept)
817  // and the source_module (old module) is deleted
818  pcbframe->Exchange_Module( source_module, newmodule, commit );
819  const_cast<KIID&>( newmodule->m_Uuid ) = module_in_edit->GetLink();
820  commit.Push( wxT( "Update module" ) );
821  }
822  else // This is an insert command
823  {
824  KIGFX::VIEW_CONTROLS* viewControls = pcbframe->GetCanvas()->GetViewControls();
825  VECTOR2D cursorPos = viewControls->GetCursorPosition();
826 
827  commit.Add( newmodule );
828  viewControls->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false );
829  pcbframe->PlaceModule( newmodule );
830  newmodule->SetPosition( wxPoint( 0, 0 ) );
831  viewControls->SetCrossHairCursorPosition( cursorPos, false );
832  const_cast<KIID&>( newmodule->m_Uuid ) = KIID();
833  commit.Push( wxT( "Insert module" ) );
834 
835  pcbframe->Raise();
836  pcbframe->GetToolManager()->RunAction( PCB_ACTIONS::placeModule, true, newmodule );
837  }
838 
839  newmodule->ClearFlags();
840 
841  return true;
842 }
843 
844 
846 {
847  if( aModule == NULL )
848  return false;
849 
850  FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs();
851 
852  SetMsgPanel( aModule );
853 
854  wxString libraryName = aModule->GetFPID().GetLibNickname();
855  wxString footprintName = aModule->GetFPID().GetLibItemName();
856  bool updateValue = ( aModule->GetValue() == footprintName );
857 
858  wxArrayString headers;
859  std::vector<wxArrayString> itemsToDisplay;
860  std::vector<wxString> nicknames = tbl->GetLogicalLibs();
861 
862  headers.Add( _( "Nickname" ) );
863  headers.Add( _( "Description" ) );
864 
865  for( const wxString& nickname : nicknames )
866  {
867  wxArrayString item;
868  item.Add( nickname );
869  item.Add( tbl->GetDescription( nickname ) );
870  itemsToDisplay.push_back( item );
871  }
872 
873  EDA_LIST_DIALOG dlg( this, _( "Save Footprint" ), headers, itemsToDisplay, libraryName );
874  dlg.SetListLabel( _( "Save in library:" ) );
875  dlg.SetOKLabel( _( "Save" ) );
876 
877  wxBoxSizer* bNameSizer = new wxBoxSizer( wxHORIZONTAL );
878 
879  wxStaticText* label = new wxStaticText( &dlg, wxID_ANY, _( "Name:" ),
880  wxDefaultPosition, wxDefaultSize, 0 );
881  bNameSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 );
882 
883  wxTextCtrl* nameTextCtrl = new wxTextCtrl( &dlg, wxID_ANY, footprintName,
884  wxDefaultPosition, wxDefaultSize, 0 );
885  bNameSizer->Add( nameTextCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
886 
887  wxTextValidator nameValidator( wxFILTER_EXCLUDE_CHAR_LIST );
888  nameValidator.SetCharExcludes( MODULE::StringLibNameInvalidChars( false ) );
889  nameTextCtrl->SetValidator( nameValidator );
890 
891  wxSizer* mainSizer = dlg.GetSizer();
892  mainSizer->Prepend( bNameSizer, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5 );
893 
894  // Move nameTextCtrl to the head of the tab-order
895  if( dlg.GetChildren().DeleteObject( nameTextCtrl ) )
896  dlg.GetChildren().Insert( nameTextCtrl );
897 
898  dlg.SetInitialFocus( nameTextCtrl );
899 
900  dlg.Layout();
901  mainSizer->Fit( &dlg );
902 
903  if( dlg.ShowModal() != wxID_OK )
904  return false; // canceled by user
905 
906  libraryName = dlg.GetTextSelection();
907 
908  if( libraryName.IsEmpty() )
909  {
910  DisplayError( NULL, _( "No library specified. Footprint could not be saved." ) );
911  return false;
912  }
913 
914  footprintName = nameTextCtrl->GetValue();
915  footprintName.Trim( true );
916  footprintName.Trim( false );
917 
918  if( footprintName.IsEmpty() )
919  {
920  DisplayError( NULL, _( "No footprint name specified. Footprint could not be saved." ) );
921  return false;
922  }
923 
924  aModule->SetFPID( LIB_ID( libraryName, footprintName ) );
925 
926  if( updateValue )
927  aModule->SetValue( footprintName );
928 
929  // Legacy libraries are readable, but modifying legacy format is not allowed
930  // So prompt the user if he try to add/replace a footprint in a legacy lib
931  wxString libfullname = Prj().PcbFootprintLibs()->FindRow( libraryName )->GetFullURI();
933 
934  if( piType == IO_MGR::LEGACY )
935  {
937  return false;
938  }
939 
940  bool module_exists = tbl->FootprintExists( libraryName, footprintName );
941 
942  if( module_exists )
943  {
944  wxString msg = wxString::Format( _( "Footprint %s already exists in %s." ),
945  footprintName,
946  libraryName );
947  KIDIALOG chkdlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
948  chkdlg.SetOKLabel( _( "Overwrite" ) );
949 
950  if( chkdlg.ShowModal() == wxID_CANCEL )
951  return false;
952  }
953 
954  if( !SaveFootprintInLibrary( aModule, libraryName ) )
955  return false;
956 
957  // Once saved-as a board footprint is no longer a board footprint
958  aModule->SetLink( niluuid );
959 
960  wxString fmt = module_exists ? _( "Component \"%s\" replaced in \"%s\"" ) :
961  _( "Component \"%s\" added in \"%s\"" );
962 
963  wxString msg = wxString::Format( fmt, footprintName.GetData(), libraryName.GetData() );
964  SetStatusText( msg );
965  updateTitle();
967 
968  return true;
969 }
970 
971 
973 {
974  if( GetScreen()->IsModify() && m_revertModule )
975  {
976  wxString msg = wxString::Format( _( "Revert \"%s\" to last version saved?" ),
977  GetChars( GetLoadedFPID().GetLibItemName() ) );
978 
979  if( ConfirmRevertDialog( this, msg ) )
980  {
981  Clear_Pcb( false );
982  AddModuleToBoard( (MODULE*) m_revertModule->Clone() );
983 
984  Zoom_Automatique( false );
985 
986  Update3DView( true );
987 
989  GetScreen()->ClrModify();
990 
991  updateView();
992  GetCanvas()->Refresh();
993 
994  return true;
995  }
996  }
997 
998  return false;
999 }
1000 
1001 
1002 MODULE* PCB_BASE_FRAME::CreateNewModule( const wxString& aModuleName )
1003 {
1004  wxString moduleName = aModuleName;
1005 
1006  // Ask for the new module name
1007  if( moduleName.IsEmpty() )
1008  {
1009  WX_TEXT_ENTRY_DIALOG dlg( this, _( "Enter footprint name:" ), _( "New Footprint" ),
1010  moduleName );
1011  dlg.SetTextValidator( MODULE_NAME_CHAR_VALIDATOR( &moduleName ) );
1012 
1013  if( dlg.ShowModal() != wxID_OK )
1014  return NULL; //Aborted by user
1015  }
1016 
1017  moduleName.Trim( true );
1018  moduleName.Trim( false );
1019 
1020  if( moduleName.IsEmpty() )
1021  {
1022  DisplayInfoMessage( this, _( "No footprint name defined." ) );
1023  return NULL;
1024  }
1025 
1026  // Creates the new module and add it to the head of the linked list of modules
1027  MODULE* module = new MODULE( GetBoard() );
1028 
1029  // Update parameters: timestamp ...
1030  module->SetLastEditTime();
1031 
1032  // Update its name in lib
1033  module->SetFPID( LIB_ID( wxEmptyString, moduleName ) );
1034 
1035  PCB_LAYER_ID txt_layer;
1036  wxPoint default_pos;
1038 
1039  module->Reference().SetText( settings.m_DefaultFPTextItems[0].m_Text );
1040  module->Reference().SetVisible( settings.m_DefaultFPTextItems[0].m_Visible );
1041  txt_layer = (PCB_LAYER_ID) settings.m_DefaultFPTextItems[0].m_Layer;
1042  module->Reference().SetLayer( txt_layer );
1043  default_pos.y -= settings.GetTextSize( txt_layer ).y / 2;
1044  module->Reference().SetPosition( default_pos );
1045  default_pos.y += settings.GetTextSize( txt_layer ).y;
1046 
1047  module->Value().SetText( settings.m_DefaultFPTextItems[1].m_Text );
1048  module->Value().SetVisible( settings.m_DefaultFPTextItems[1].m_Visible );
1049  txt_layer = (PCB_LAYER_ID) settings.m_DefaultFPTextItems[1].m_Layer;
1050  module->Value().SetLayer( txt_layer );
1051  default_pos.y += settings.GetTextSize( txt_layer ).y / 2;
1052  module->Value().SetPosition( default_pos );
1053  default_pos.y += settings.GetTextSize( txt_layer ).y;
1054 
1055  for( size_t i = 2; i < settings.m_DefaultFPTextItems.size(); ++i )
1056  {
1057  TEXTE_MODULE* textItem = new TEXTE_MODULE( module );
1058  textItem->SetText( settings.m_DefaultFPTextItems[i].m_Text );
1059  textItem->SetVisible( settings.m_DefaultFPTextItems[i].m_Visible );
1060  txt_layer = (PCB_LAYER_ID) settings.m_DefaultFPTextItems[i].m_Layer;
1061  textItem->SetLayer( txt_layer );
1062  default_pos.y += settings.GetTextSize( txt_layer ).y / 2;
1063  textItem->SetPosition( default_pos );
1064  default_pos.y += settings.GetTextSize( txt_layer ).y;
1065  module->GraphicalItems().push_back( textItem );
1066  }
1067 
1068  if( module->GetReference().IsEmpty() )
1069  module->SetReference( moduleName );
1070 
1071  if( module->GetValue().IsEmpty() )
1072  module->SetValue( moduleName );
1073 
1074  module->RunOnChildren(
1075  [&] ( BOARD_ITEM* aChild )
1076  {
1077  if( aChild->Type() == PCB_MODULE_TEXT_T )
1078  {
1079  TEXTE_MODULE* textItem = static_cast<TEXTE_MODULE*>( aChild );
1080  PCB_LAYER_ID layer = textItem->GetLayer();
1081 
1082  textItem->SetTextThickness( settings.GetTextThickness( layer ) );
1083  textItem->SetTextSize( settings.GetTextSize( layer ) );
1084  textItem->SetItalic( settings.GetTextItalic( layer ) );
1085  textItem->SetKeepUpright( settings.GetTextUpright( layer ) );
1086  }
1087  } );
1088 
1089  SetMsgPanel( module );
1090  return module;
1091 }
1092 
1093 
1094 wxString PCB_BASE_FRAME::SelectLibrary( const wxString& aNicknameExisting )
1095 {
1096  wxArrayString headers;
1097 
1098  headers.Add( _( "Nickname" ) );
1099  headers.Add( _( "Description" ) );
1100 
1101  FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs();
1102 
1103  std::vector< wxArrayString > itemsToDisplay;
1104  std::vector< wxString > nicknames = fptbl->GetLogicalLibs();
1105 
1106  for( const wxString& nickname : nicknames )
1107  {
1108  wxArrayString item;
1109 
1110  item.Add( nickname );
1111  item.Add( fptbl->GetDescription( nickname ) );
1112 
1113  itemsToDisplay.push_back( item );
1114  }
1115 
1116  EDA_LIST_DIALOG dlg( this, _( "Select Library" ), headers, itemsToDisplay, aNicknameExisting );
1117 
1118  if( dlg.ShowModal() != wxID_OK )
1119  return wxEmptyString;
1120 
1121  return dlg.GetTextSelection();
1122 }
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:547
void BuildListOfNets()
Definition: class_board.h:718
static TOOL_ACTION placeModule
Definition: pcb_actions.h:153
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:474
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:344
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:252
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:178
Component library viewer main window.
void SetTextValidator(wxTextValidatorStyle style)
void SetVisible(bool aVisible)
Definition: eda_text.h:184
const wxString GetValue() const
Function GetValue.
Definition: class_module.h:458
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:215
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:237
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:179
void Exchange_Module(MODULE *aSrc, MODULE *aDest, BOARD_COMMIT &aCommit, bool deleteExtraTexts=true, bool resetTextLayers=true, bool resetTextEffects=true, bool reset3DModels=true)
Function Exchange_Module Replaces OldModule by NewModule, using OldModule settings: position,...
static const wxString ShowType(PCB_FILE_T aFileType)
Function ShowType returns a brief name for a plugin, given aFileType enum.
Definition: io_mgr.cpp:80
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...
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:63
static PCB_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath)
Function GuessPluginTypeFromLibPath returns a plugin type given a footprint library's libPath.
Definition: io_mgr.cpp:127
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:433
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:579
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:94
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:116
#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:342
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
MODULES & Modules()
Definition: class_board.h:266
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:473
const wxString GetDescription(const wxString &aNickname)
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
KIID niluuid(0)
void SetLastEditTime(timestamp_t aTime)
Definition: class_module.h:343
virtual void ClearUndoRedoList()
Function ClearUndoRedoList clear undo and redo list, using ClearUndoORRedoList() picked items are del...
Definition: base_screen.cpp:73
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:330
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:443
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:269
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:206
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:284
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().
wxString CreateNewLibrary(const wxString &aLibName=wxEmptyString)
Function CreateNewLibrary If a library name is given, creates a new footprint library in the project ...
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:221
wxString KiCadFootprintLibPathWildcard()
#define CTL_FOR_LIBRARY
Format output for a footprint library instead of clipboard or BOARD.
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:48
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:205
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.
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
#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:61
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:184
void SetValue(const wxString &aValue)
Function SetValue.
Definition: class_module.h:467
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:546
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:157
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:74
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
Function Format outputs 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
void SetFPID(const LIB_ID &aFPID)
Definition: class_module.h:216
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)