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 <pgm_base.h>
26 #include <kiface_i.h>
27 #include <confirm.h>
28 #include <kicad_string.h>
29 #include <pcb_edit_frame.h>
30 #include <dialog_helpers.h>
31 #include <filter_reader.h>
32 #include <fp_lib_table.h>
33 #include <validators.h>
34 #include <dialog_text_entry.h>
35 #include <tool/tool_manager.h>
36 #include <tools/pcb_actions.h>
37 #include <board.h>
38 #include <footprint.h>
39 #include <board_commit.h>
40 #include <footprint_edit_frame.h>
44 #include <env_paths.h>
47 #include "footprint_viewer_frame.h"
48 
49 
50 // unique, "file local" translations:
51 
52 
53 static const wxString INFO_LEGACY_LIB_WARN_EDIT(
54  _( "Writing/modifying legacy libraries (.mod files) is not allowed\n"\
55  "Please save the current library to the new .pretty format\n"\
56  "and update your footprint lib table\n"\
57  "to save your footprint (a .kicad_mod file) in the .pretty library folder" ) );
58 
59 static const wxString INFO_LEGACY_LIB_WARN_DELETE(
60  _( "Modifying legacy libraries (.mod files) is not allowed\n"\
61  "Please save the current library under the new .pretty format\n"\
62  "and update your footprint lib table\n"\
63  "before deleting a footprint" ) );
64 
65 
71 static wxFileName getFootprintFilenameFromUser( wxWindow* aParent, const wxString& aLastPath )
72 {
73  static int lastFilterIndex = 0; // To store the last choice during a session.
74  wxString wildCard;
75 
76  wildCard << KiCadFootprintLibFileWildcard() << wxChar( '|' )
77  << ModLegacyExportFileWildcard() << wxChar( '|' )
78  << GedaPcbFootprintLibFileWildcard() << wxChar( '|' )
79  << AllFilesWildcard();
80 
81  wxFileDialog dlg( aParent, _( "Import Footprint" ), aLastPath, wxEmptyString, wildCard,
82  wxFD_OPEN | wxFD_FILE_MUST_EXIST );
83 
84  dlg.SetFilterIndex( lastFilterIndex );
85 
86  if( dlg.ShowModal() == wxID_CANCEL )
87  return wxFileName();
88 
89  lastFilterIndex = dlg.GetFilterIndex();
90 
91  return wxFileName( dlg.GetPath() );
92 }
93 
94 
101 static IO_MGR::PCB_FILE_T detect_file_type( FILE* aFile, const wxFileName& aFileName,
102  wxString* aName )
103 {
104  FILE_LINE_READER freader( aFile, aFileName.GetFullPath() );
105  WHITESPACE_FILTER_READER reader( freader );
106  IO_MGR::PCB_FILE_T file_type;
107 
108  wxASSERT( aName );
109 
110  reader.ReadLine();
111  char* line = reader.Line();
112 
113  if( !strncasecmp( line, "(module", strlen( "(module" ) ) )
114  {
115  file_type = IO_MGR::KICAD_SEXP;
116  *aName = aFileName.GetName();
117  }
118  else if( !strncasecmp( line, FOOTPRINT_LIBRARY_HEADER, FOOTPRINT_LIBRARY_HEADER_CNT ) )
119  {
120  file_type = IO_MGR::LEGACY;
121 
122  while( reader.ReadLine() )
123  {
124  if( !strncasecmp( line, "$MODULE", strlen( "$MODULE" ) ) )
125  {
126  *aName = FROM_UTF8( StrPurge( line + strlen( "$MODULE" ) ) );
127  break;
128  }
129  }
130  }
131  else if( !strncasecmp( line, "Element", strlen( "Element" ) ) )
132  {
133  file_type = IO_MGR::GEDA_PCB;
134  *aName = aFileName.GetName();
135  }
136  else
137  {
138  file_type = IO_MGR::FILE_TYPE_NONE;
139  }
140 
141  return file_type;
142 }
143 
144 
151 static FOOTPRINT* parse_footprint_with_plugin( const wxFileName& aFileName,
152  IO_MGR::PCB_FILE_T aFileType,
153  const wxString& aName )
154 {
155  wxString path;
156 
157  switch( aFileType )
158  {
159  case IO_MGR::GEDA_PCB: path = aFileName.GetPath(); break;
160  case IO_MGR::LEGACY: path = aFileName.GetFullPath(); break;
161  default: wxFAIL_MSG( wxT( "unexpected IO_MGR::PCB_FILE_T" ) ); break;
162  }
163 
164  PLUGIN::RELEASER pi( IO_MGR::PluginFind( aFileType ) );
165 
166  return pi->FootprintLoad( path, aName );
167 }
168 
169 
174 static FOOTPRINT* parse_footprint_kicad( const wxFileName& aFileName )
175 {
176  wxString fcontents;
177  PCB_IO pcb_io;
178  wxFFile f( aFileName.GetFullPath() );
179 
180  if( !f.IsOpened() )
181  return NULL;
182 
183  f.ReadAll( &fcontents );
184 
185  return dynamic_cast<FOOTPRINT*>( pcb_io.Parse( fcontents ) );
186 }
187 
188 
195 FOOTPRINT* try_load_footprint( const wxFileName& aFileName, IO_MGR::PCB_FILE_T aFileType,
196  const wxString& aName )
197 {
198  FOOTPRINT* footprint;
199 
200  switch( aFileType )
201  {
202  case IO_MGR::GEDA_PCB:
203  case IO_MGR::LEGACY:
204  footprint = parse_footprint_with_plugin( aFileName, aFileType, aName );
205  break;
206 
207  case IO_MGR::KICAD_SEXP:
208  footprint = parse_footprint_kicad( aFileName );
209  break;
210 
211  default:
212  wxFAIL_MSG( wxT( "unexpected IO_MGR::PCB_FILE_T" ) );
213  footprint = NULL;
214  }
215 
216  return footprint;
217 }
218 
219 
221 {
222  wxString lastOpenedPathForLoading = m_mruPath;
224 
225  if( !cfg->m_LastImportExportPath.empty() )
226  lastOpenedPathForLoading = cfg->m_LastImportExportPath;
227 
228  wxFileName fn;
229 
230  if( aName != wxT("") )
231  fn = aName;
232  else
233  fn = getFootprintFilenameFromUser( this, lastOpenedPathForLoading );
234 
235  if( !fn.IsOk() )
236  return NULL;
237 
238  FILE* fp = wxFopen( fn.GetFullPath(), wxT( "rt" ) );
239 
240  if( !fp )
241  {
242  wxString msg = wxString::Format( _( "File \"%s\" not found" ), fn.GetFullPath() );
243  DisplayError( this, msg );
244  return NULL;
245  }
246 
247  cfg->m_LastImportExportPath = lastOpenedPathForLoading;
248 
249  wxString footprintName;
250  IO_MGR::PCB_FILE_T fileType = detect_file_type( fp, fn.GetFullPath(), &footprintName );
251 
253  {
254  DisplayError( this, _( "Not a footprint file" ) );
255  return NULL;
256  }
257 
258  FOOTPRINT* footprint = NULL;
259 
260  try
261  {
262  footprint = try_load_footprint( fn, fileType, footprintName );
263 
264  if( !footprint )
265  {
266  wxString msg = wxString::Format( _( "Unable to load footprint '%s' from '%s'" ),
267  footprintName,
268  fn.GetFullPath() );
269  DisplayError( this, msg );
270  return NULL;
271  }
272  }
273  catch( const IO_ERROR& ioe )
274  {
275  DisplayError( this, ioe.What() );
276 
277  // if the footprint is not loaded, exit.
278  // However, even if an error happens, it can be loaded, because in KICAD and GPCB format,
279  // a fp library is a set of separate files, and the error(s) are not necessary when
280  // reading the selected file
281 
282  if( !footprint )
283  return NULL;
284  }
285 
286  footprint->SetFPID( LIB_ID( wxEmptyString, footprintName ) );
287 
288  // Insert footprint in list
289  AddFootprintToBoard( footprint );
290 
291  // Display info :
292  SetMsgPanel( footprint );
293  PlaceFootprint( footprint );
294 
295  footprint->SetPosition( wxPoint( 0, 0 ) );
296 
298  UpdateView();
299 
300  return footprint;
301 }
302 
303 
305 {
306  wxFileName fn;
308 
309  if( !aFootprint )
310  return;
311 
312  fn.SetName( aFootprint->GetFPID().GetLibItemName() );
313 
314  wxString wildcard = KiCadFootprintLibFileWildcard();
315 
316  fn.SetExt( KiCadFootprintFileExtension );
317 
318  if( !cfg->m_LastImportExportPath.empty() )
319  fn.SetPath( cfg->m_LastImportExportPath );
320  else
321  fn.SetPath( m_mruPath );
322 
323  wxFileDialog dlg( this, _( "Export Footprint" ), fn.GetPath(), fn.GetFullName(),
324  wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
325 
326  if( dlg.ShowModal() == wxID_CANCEL )
327  return;
328 
329  fn = dlg.GetPath();
330  cfg->m_LastImportExportPath = fn.GetPath();
331 
332  try
333  {
334  // Export as *.kicad_pcb format, using a strategy which is specifically chosen
335  // as an example on how it could also be used to send it to the system clipboard.
336 
337  PCB_IO pcb_io( CTL_FOR_LIBRARY );
338 
339  /* This footprint should *already* be "normalized" in a way such that
340  orientation is zero, etc., since it came from the Footprint Editor.
341 
342  aFootprint->SetParent( 0 );
343  aFootprint->SetOrientation( 0 );
344  */
345 
346  pcb_io.Format( aFootprint );
347 
348  FILE* fp = wxFopen( dlg.GetPath(), wxT( "wt" ) );
349 
350  if( fp == NULL )
351  {
352  wxMessageBox( wxString::Format( _( "Unable to create or write file \"%s\"" ),
353  dlg.GetPath() ) );
354  return;
355  }
356 
357  fprintf( fp, "%s", pcb_io.GetStringOutput( false ).c_str() );
358  fclose( fp );
359  }
360  catch( const IO_ERROR& ioe )
361  {
362  DisplayError( this, ioe.What() );
363  return;
364  }
365 
366  wxString msg = wxString::Format( _( "Footprint exported to file \"%s\"" ), dlg.GetPath() );
367  DisplayInfoMessage( this, msg );
368 }
369 
370 
371 wxString PCB_BASE_EDIT_FRAME::CreateNewLibrary( const wxString& aLibName,
372  const wxString& aProposedName )
373 {
374  // Kicad cannot write legacy format libraries, only .pretty new format
375  // because the legacy format cannot handle current features.
376  // The footprint library is actually a directory
377 
378  wxString initialPath = aProposedName.IsEmpty() ? Prj().GetProjectPath() : aProposedName;
379  wxFileName fn;
380  bool doAdd = false;
381 
382  if( aLibName.IsEmpty() )
383  {
384  fn = initialPath;
385 
386  if( !LibraryFileBrowser( false, fn,
388  {
389  return wxEmptyString;
390  }
391 
392  doAdd = true;
393  }
394  else
395  {
396  fn = aLibName;
397 
398  if( !fn.IsAbsolute() )
399  {
400  fn.SetName( aLibName );
401  fn.MakeAbsolute( initialPath );
402  }
403 
404  // Enforce the .pretty extension:
405  fn.SetExt( KiCadFootprintLibPathExtension );
406  }
407 
408  // We can save fp libs only using IO_MGR::KICAD_SEXP format (.pretty libraries)
410  wxString libPath = fn.GetFullPath();
411 
412  try
413  {
414  PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) );
415 
416  bool writable = false;
417  bool exists = false;
418 
419  try
420  {
421  writable = pi->IsFootprintLibWritable( libPath );
422  exists = true; // no exception was thrown, lib must exist.
423  }
424  catch( const IO_ERROR& )
425  { }
426 
427  if( exists )
428  {
429  if( !writable )
430  {
431  wxString msg = wxString::Format( _( "Library \"%s\" is read only." ), libPath );
432  ShowInfoBarError( msg );
433  return wxEmptyString;
434  }
435  else
436  {
437  wxString msg = wxString::Format( _( "Library %s already exists." ), libPath );
438  KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
439  dlg.SetOKLabel( _( "Overwrite" ) );
440  dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
441 
442  if( dlg.ShowModal() == wxID_CANCEL )
443  return wxEmptyString;
444 
445  pi->FootprintLibDelete( libPath );
446  }
447  }
448 
449  pi->FootprintLibCreate( libPath );
450  }
451  catch( const IO_ERROR& ioe )
452  {
453  DisplayError( this, ioe.What() );
454  return wxEmptyString;
455  }
456 
457  if( doAdd )
458  AddLibrary( libPath );
459 
460  return libPath;
461 }
462 
463 
464 bool PCB_BASE_EDIT_FRAME::AddLibrary( const wxString& aFilename )
465 {
466  wxFileName fn( aFilename );
467 
468  if( aFilename.IsEmpty() )
469  {
470  if( !LibraryFileBrowser( true, fn,
472  true ) )
473  {
474  return false;
475  }
476  }
477 
478  wxString libPath = fn.GetFullPath();
479  wxString libName = fn.GetName();
480 
481  if( libName.IsEmpty() )
482  return false;
483 
484  bool saveInGlobalTable = false;
485  bool saveInProjectTable = false;
486 
487  if( Prj().IsNullProject() )
488  {
489  saveInGlobalTable = true;
490  }
491  else
492  {
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:" ), libTableNames ) )
500  {
501  case 0: saveInGlobalTable = true; break;
502  case 1: saveInProjectTable = true; break;
503  default: return false;
504  }
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::DeleteFootprintFromLibrary( 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  ShowInfoBarError( 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::ExportFootprintsToLibrary( bool aStoreInNewLib, const wxString& aLibName,
608  wxString* aLibPath )
609 {
610  if( GetBoard()->GetFirstFootprint() == NULL )
611  {
612  DisplayInfoMessage( this, _( "No footprints to export!" ) );
613  return;
614  }
615 
616  wxString footprintName;
617 
618  auto resetReference =
619  []( FOOTPRINT* aFootprint )
620  {
621  aFootprint->SetReference( "REF**" );
622  };
623 
624  if( !aStoreInNewLib )
625  {
626  // The footprints are saved in an existing .pretty library in the fp lib table
627  PROJECT& prj = Prj();
628  wxString last_nickname = prj.GetRString( PROJECT::PCB_LIB_NICKNAME );
629  wxString nickname = SelectLibrary( last_nickname );
630 
631  if( !nickname ) // Aborted
632  return;
633 
634  prj.SetRString( PROJECT::PCB_LIB_NICKNAME, nickname );
635 
636  for( FOOTPRINT* footprint : GetBoard()->Footprints() )
637  {
638  try
639  {
640  FP_LIB_TABLE* tbl = prj.PcbFootprintLibs();
641 
642  if( !footprint->GetFPID().GetLibItemName().empty() ) // Handle old boards.
643  {
644  FOOTPRINT* fpCopy = static_cast<FOOTPRINT*>( footprint->Duplicate() );
645 
646  resetReference( fpCopy );
647  tbl->FootprintSave( nickname, fpCopy, true );
648 
649  delete fpCopy;
650  }
651  }
652  catch( const IO_ERROR& ioe )
653  {
654  DisplayError( this, ioe.What() );
655  }
656  }
657  }
658  else
659  {
660  // The footprints are saved in a new .pretty library.
661  // If this library already exists, all previous footprints will be deleted
662  wxString libPath = CreateNewLibrary( aLibName );
663 
664  if( libPath.IsEmpty() ) // Aborted
665  return;
666 
667  if( aLibPath )
668  *aLibPath = libPath;
669 
671  PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) );
672 
673  for( FOOTPRINT* footprint : GetBoard()->Footprints() )
674  {
675  try
676  {
677  if( !footprint->GetFPID().GetLibItemName().empty() ) // Handle old boards.
678  {
679  FOOTPRINT* fpCopy = static_cast<FOOTPRINT*>( footprint->Duplicate() );
680 
681  resetReference( fpCopy );
682  pi->FootprintSave( libPath, fpCopy );
683 
684  delete fpCopy;
685  }
686  }
687  catch( const IO_ERROR& ioe )
688  {
689  DisplayError( this, ioe.What() );
690  }
691  }
692  }
693 }
694 
695 
697 {
698  if( !aFootprint ) // Happen if no footprint loaded
699  return false;
700 
701  wxString libraryName = aFootprint->GetFPID().GetLibNickname();
702  wxString footprintName = aFootprint->GetFPID().GetLibItemName();
703  bool nameChanged = m_footprintNameWhenLoaded != footprintName;
704 
705  if( aFootprint->GetLink() != niluuid )
706  {
707  if( SaveFootprintToBoard( false ) )
708  {
709  m_footprintNameWhenLoaded = footprintName;
710  return true;
711  }
712  else
713  return false;
714  }
715  else if( libraryName.IsEmpty() || footprintName.IsEmpty() )
716  {
717  if( SaveFootprintAs( aFootprint ) )
718  {
719  m_footprintNameWhenLoaded = footprintName;
720  SyncLibraryTree( true );
721  return true;
722  }
723  else
724  return false;
725  }
726 
727  FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs();
728 
729  // Legacy libraries are readable, but modifying legacy format is not allowed
730  // So prompt the user if he try to add/replace a footprint in a legacy lib
731  wxString libfullname = tbl->FindRow( libraryName )->GetFullURI();
732 
733  if( IO_MGR::GuessPluginTypeFromLibPath( libfullname ) == IO_MGR::LEGACY )
734  {
736  return false;
737  }
738 
739  if( nameChanged )
740  {
741  LIB_ID oldFPID( libraryName, m_footprintNameWhenLoaded );
742  DeleteFootprintFromLibrary( oldFPID, false );
743  }
744 
745  if( !SaveFootprintInLibrary( aFootprint, libraryName ) )
746  return false;
747 
748  if( nameChanged )
749  {
750  m_footprintNameWhenLoaded = footprintName;
751  SyncLibraryTree( true );
752  }
753 
754  return true;
755 }
756 
757 
759  const wxString& aLibraryName )
760 {
761  try
762  {
763  aFootprint->SetFPID( LIB_ID( wxEmptyString, aFootprint->GetFPID().GetLibItemName() ) );
764 
765  Prj().PcbFootprintLibs()->FootprintSave( aLibraryName, aFootprint );
766 
767  aFootprint->SetFPID( LIB_ID( aLibraryName, aFootprint->GetFPID().GetLibItemName() ) );
768  return true;
769  }
770  catch( const IO_ERROR& ioe )
771  {
772  DisplayError( this, ioe.What() );
773 
774  aFootprint->SetFPID( LIB_ID( aLibraryName, aFootprint->GetFPID().GetLibItemName() ) );
775  return false;
776  }
777 }
778 
779 
781 {
782  // update footprint in the current board,
783  // not just add it to the board with total disregard for the netlist...
784  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB_EDITOR, false );
785 
786  if( pcbframe == NULL ) // happens when the board editor is not active (or closed)
787  {
788  ShowInfoBarError( _( "No board currently open." ) );
789  return false;
790  }
791 
792  BOARD* mainpcb = pcbframe->GetBoard();
793  FOOTPRINT* sourceFootprint = NULL;
794  FOOTPRINT* editorFootprint = GetBoard()->GetFirstFootprint();
795 
796  // Search the old footprint (source) if exists
797  // Because this source could be deleted when editing the main board...
798  if( editorFootprint->GetLink() != niluuid ) // this is not a new footprint ...
799  {
800  sourceFootprint = nullptr;
801 
802  for( FOOTPRINT* candidate : mainpcb->Footprints() )
803  {
804  if( editorFootprint->GetLink() == candidate->m_Uuid )
805  {
806  sourceFootprint = candidate;
807  break;
808  }
809  }
810  }
811 
812  if( !aAddNew && sourceFootprint == NULL ) // source not found
813  {
814  DisplayError( this, _( "Unable to find the footprint on the main board.\nCannot save." ) );
815  return false;
816  }
817 
820  BOARD_COMMIT commit( pcbframe );
821 
822  // Create the "new" footprint
823  FOOTPRINT* newFootprint = new FOOTPRINT( *editorFootprint );
824  const_cast<KIID&>( newFootprint->m_Uuid ) = KIID();
825 
826  newFootprint->SetParent( mainpcb );
827  newFootprint->SetLink( niluuid );
828 
829  if( sourceFootprint ) // this is an update command
830  {
831  // In the main board the new footprint replaces the old one (pos, orient, ref, value,
832  // connections and properties are kept) and the sourceFootprint (old footprint) is
833  // deleted
834  pcbframe->ExchangeFootprint( sourceFootprint, newFootprint, commit );
835  const_cast<KIID&>( newFootprint->m_Uuid ) = editorFootprint->GetLink();
836  commit.Push( wxT( "Update footprint" ) );
837  }
838  else // This is an insert command
839  {
840  KIGFX::VIEW_CONTROLS* viewControls = pcbframe->GetCanvas()->GetViewControls();
841  VECTOR2D cursorPos = viewControls->GetCursorPosition();
842 
843  commit.Add( newFootprint );
844  viewControls->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false );
845  pcbframe->PlaceFootprint( newFootprint );
846  newFootprint->SetPosition( wxPoint( 0, 0 ) );
847  viewControls->SetCrossHairCursorPosition( cursorPos, false );
848  const_cast<KIID&>( newFootprint->m_Uuid ) = KIID();
849  commit.Push( wxT( "Insert footprint" ) );
850 
851  pcbframe->Raise();
852  pcbframe->GetToolManager()->RunAction( PCB_ACTIONS::placeModule, true, newFootprint );
853  }
854 
855  newFootprint->ClearFlags();
856 
857  return true;
858 }
859 
860 
862 {
863  if( aFootprint == NULL )
864  return false;
865 
866  FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs();
867 
868  SetMsgPanel( aFootprint );
869 
870  wxString libraryName = aFootprint->GetFPID().GetLibNickname();
871  wxString footprintName = aFootprint->GetFPID().GetLibItemName();
872  bool updateValue = aFootprint->GetValue() == footprintName;
873 
874  wxArrayString headers;
875  std::vector<wxArrayString> itemsToDisplay;
876  std::vector<wxString> nicknames = tbl->GetLogicalLibs();
877 
878  headers.Add( _( "Nickname" ) );
879  headers.Add( _( "Description" ) );
880 
881  for( const wxString& nickname : nicknames )
882  {
883  wxArrayString item;
884  item.Add( nickname );
885  item.Add( tbl->GetDescription( nickname ) );
886  itemsToDisplay.push_back( item );
887  }
888 
889  EDA_LIST_DIALOG dlg( this, _( "Save Footprint" ), headers, itemsToDisplay, libraryName );
890  dlg.SetListLabel( _( "Save in library:" ) );
891  dlg.SetOKLabel( _( "Save" ) );
892 
893  wxBoxSizer* bNameSizer = new wxBoxSizer( wxHORIZONTAL );
894 
895  wxStaticText* label = new wxStaticText( &dlg, wxID_ANY, _( "Name:" ),
896  wxDefaultPosition, wxDefaultSize, 0 );
897  bNameSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 );
898 
899  wxTextCtrl* nameTextCtrl = new wxTextCtrl( &dlg, wxID_ANY, footprintName,
900  wxDefaultPosition, wxDefaultSize, 0 );
901  bNameSizer->Add( nameTextCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
902 
903  wxTextValidator nameValidator( wxFILTER_EXCLUDE_CHAR_LIST );
904  nameValidator.SetCharExcludes( FOOTPRINT::StringLibNameInvalidChars( false ) );
905  nameTextCtrl->SetValidator( nameValidator );
906 
907  wxSizer* mainSizer = dlg.GetSizer();
908  mainSizer->Prepend( bNameSizer, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5 );
909 
910  // Move nameTextCtrl to the head of the tab-order
911  if( dlg.GetChildren().DeleteObject( nameTextCtrl ) )
912  dlg.GetChildren().Insert( nameTextCtrl );
913 
914  dlg.SetInitialFocus( nameTextCtrl );
915 
916  dlg.Layout();
917  mainSizer->Fit( &dlg );
918 
919  if( dlg.ShowModal() != wxID_OK )
920  return false; // canceled by user
921 
922  libraryName = dlg.GetTextSelection();
923 
924  if( libraryName.IsEmpty() )
925  {
926  DisplayError( NULL, _( "No library specified. Footprint could not be saved." ) );
927  return false;
928  }
929 
930  footprintName = nameTextCtrl->GetValue();
931  footprintName.Trim( true );
932  footprintName.Trim( false );
933 
934  if( footprintName.IsEmpty() )
935  {
936  DisplayError( NULL, _( "No footprint name specified. Footprint could not be saved." ) );
937  return false;
938  }
939 
940  aFootprint->SetFPID( LIB_ID( libraryName, footprintName ) );
941 
942  if( updateValue )
943  aFootprint->SetValue( footprintName );
944 
945  // Legacy libraries are readable, but modifying legacy format is not allowed
946  // So prompt the user if he try to add/replace a footprint in a legacy lib
947  wxString libfullname = Prj().PcbFootprintLibs()->FindRow( libraryName )->GetFullURI();
949 
950  if( piType == IO_MGR::LEGACY )
951  {
953  return false;
954  }
955 
956  bool footprintExists = tbl->FootprintExists( libraryName, footprintName );
957 
958  if( footprintExists )
959  {
960  wxString msg = wxString::Format( _( "Footprint %s already exists in %s." ),
961  footprintName,
962  libraryName );
963  KIDIALOG chkdlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
964  chkdlg.SetOKLabel( _( "Overwrite" ) );
965 
966  if( chkdlg.ShowModal() == wxID_CANCEL )
967  return false;
968  }
969 
970  if( !SaveFootprintInLibrary( aFootprint, libraryName ) )
971  return false;
972 
973  // Once saved-as a board footprint is no longer a board footprint
974  aFootprint->SetLink( niluuid );
975 
976  wxString fmt = footprintExists ? _( "Component \"%s\" replaced in \"%s\"" )
977  : _( "Component \"%s\" added in \"%s\"" );
978 
979  wxString msg = wxString::Format( fmt, footprintName.GetData(), libraryName.GetData() );
980  SetStatusText( msg );
981  updateTitle();
983 
984  return true;
985 }
986 
987 
989 {
990  if( GetScreen()->IsModify() && m_revertModule )
991  {
992  wxString msg = wxString::Format( _( "Revert \"%s\" to last version saved?" ),
993  GetLoadedFPID().GetLibItemName().wx_str() );
994 
995  if( ConfirmRevertDialog( this, msg ) )
996  {
997  Clear_Pcb( false );
998  AddFootprintToBoard( static_cast<FOOTPRINT*>( m_revertModule->Clone() ) );
999 
1000  Zoom_Automatique( false );
1001 
1002  Update3DView( true );
1003 
1005  GetScreen()->ClrModify();
1006 
1007  UpdateView();
1008  GetCanvas()->Refresh();
1009 
1010  return true;
1011  }
1012  }
1013 
1014  return false;
1015 }
1016 
1017 
1018 FOOTPRINT* PCB_BASE_FRAME::CreateNewFootprint( const wxString& aFootprintName )
1019 {
1020  wxString footprintName = aFootprintName;
1021 
1022  // Ask for the new footprint name
1023  if( footprintName.IsEmpty() )
1024  {
1025  WX_TEXT_ENTRY_DIALOG dlg( this, _( "Enter footprint name:" ), _( "New Footprint" ),
1026  footprintName );
1027  dlg.SetTextValidator( FOOTPRINT_NAME_VALIDATOR( &footprintName ) );
1028 
1029  if( dlg.ShowModal() != wxID_OK )
1030  return NULL; //Aborted by user
1031  }
1032 
1033  footprintName.Trim( true );
1034  footprintName.Trim( false );
1035 
1036  if( footprintName.IsEmpty() )
1037  {
1038  DisplayInfoMessage( this, _( "No footprint name defined." ) );
1039  return NULL;
1040  }
1041 
1042  // Creates the new footprint and add it to the head of the linked list of footprints
1043  FOOTPRINT* footprint = new FOOTPRINT( GetBoard() );
1044 
1045  // Update parameters: timestamp ...
1046  footprint->SetLastEditTime();
1047 
1048  // Update its name in lib
1049  footprint->SetFPID( LIB_ID( wxEmptyString, footprintName ) );
1050 
1051  PCB_LAYER_ID txt_layer;
1052  wxPoint default_pos;
1054 
1055  footprint->Reference().SetText( settings.m_DefaultFPTextItems[0].m_Text );
1056  footprint->Reference().SetVisible( settings.m_DefaultFPTextItems[0].m_Visible );
1057  txt_layer = (PCB_LAYER_ID) settings.m_DefaultFPTextItems[0].m_Layer;
1058  footprint->Reference().SetLayer( txt_layer );
1059  default_pos.y -= settings.GetTextSize( txt_layer ).y / 2;
1060  footprint->Reference().SetPosition( default_pos );
1061  default_pos.y += settings.GetTextSize( txt_layer ).y;
1062 
1063  footprint->Value().SetText( settings.m_DefaultFPTextItems[1].m_Text );
1064  footprint->Value().SetVisible( settings.m_DefaultFPTextItems[1].m_Visible );
1065  txt_layer = (PCB_LAYER_ID) settings.m_DefaultFPTextItems[1].m_Layer;
1066  footprint->Value().SetLayer( txt_layer );
1067  default_pos.y += settings.GetTextSize( txt_layer ).y / 2;
1068  footprint->Value().SetPosition( default_pos );
1069  default_pos.y += settings.GetTextSize( txt_layer ).y;
1070 
1071  for( size_t i = 2; i < settings.m_DefaultFPTextItems.size(); ++i )
1072  {
1073  FP_TEXT* textItem = new FP_TEXT( footprint );
1074  textItem->SetText( settings.m_DefaultFPTextItems[i].m_Text );
1075  textItem->SetVisible( settings.m_DefaultFPTextItems[i].m_Visible );
1076  txt_layer = (PCB_LAYER_ID) settings.m_DefaultFPTextItems[i].m_Layer;
1077  textItem->SetLayer( txt_layer );
1078  default_pos.y += settings.GetTextSize( txt_layer ).y / 2;
1079  textItem->SetPosition( default_pos );
1080  default_pos.y += settings.GetTextSize( txt_layer ).y;
1081  footprint->GraphicalItems().push_back( textItem );
1082  }
1083 
1084  if( footprint->GetReference().IsEmpty() )
1085  footprint->SetReference( footprintName );
1086 
1087  if( footprint->GetValue().IsEmpty() )
1088  footprint->SetValue( footprintName );
1089 
1090  footprint->RunOnChildren(
1091  [&] ( BOARD_ITEM* aChild )
1092  {
1093  if( aChild->Type() == PCB_FP_TEXT_T )
1094  {
1095  FP_TEXT* textItem = static_cast<FP_TEXT*>( aChild );
1096  PCB_LAYER_ID layer = textItem->GetLayer();
1097 
1098  textItem->SetTextThickness( settings.GetTextThickness( layer ) );
1099  textItem->SetTextSize( settings.GetTextSize( layer ) );
1100  textItem->SetItalic( settings.GetTextItalic( layer ) );
1101  textItem->SetKeepUpright( settings.GetTextUpright( layer ) );
1102  }
1103  } );
1104 
1105  SetMsgPanel( footprint );
1106  return footprint;
1107 }
1108 
1109 
1110 wxString PCB_BASE_FRAME::SelectLibrary( const wxString& aNicknameExisting )
1111 {
1112  wxArrayString headers;
1113 
1114  headers.Add( _( "Nickname" ) );
1115  headers.Add( _( "Description" ) );
1116 
1117  FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs();
1118 
1119  std::vector< wxArrayString > itemsToDisplay;
1120  std::vector< wxString > nicknames = fptbl->GetLogicalLibs();
1121 
1122  for( const wxString& nickname : nicknames )
1123  {
1124  wxArrayString item;
1125 
1126  item.Add( nickname );
1127  item.Add( fptbl->GetDescription( nickname ) );
1128 
1129  itemsToDisplay.push_back( item );
1130  }
1131 
1132  EDA_LIST_DIALOG dlg( this, _( "Select Library" ), headers, itemsToDisplay, aNicknameExisting );
1133 
1134  if( dlg.ShowModal() != wxID_OK )
1135  return wxEmptyString;
1136 
1137  return dlg.GetTextSelection();
1138 }
void SetReference(const wxString &aReference)
Function SetReference.
Definition: footprint.h:450
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:240
void BuildListOfNets()
Definition: board.h:700
static TOOL_ACTION placeModule
Definition: pcb_actions.h:161
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
void DoNotShowCheckbox(wxString file, int line)
Shows the 'do not show again' checkbox
Definition: confirm.cpp:54
bool ConfirmRevertDialog(wxWindow *parent, const wxString &aMessage)
Display a confirmation dialog for a revert action.
Definition: confirm.cpp:191
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.
BOARD_ITEM * Parse(const wxString &aClipboardSourceInput)
std::vector< TEXT_ITEM_INFO > m_DefaultFPTextItems
KIID niluuid(0)
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.
class FP_TEXT, text in a footprint
Definition: typeinfo.h:93
wxString m_mruPath
virtual void SetPosition(const wxPoint &aPos) override
Definition: fp_text.h:91
PROJECT holds project specific data.
Definition: project.h:63
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:109
char * StrPurge(char *text)
Remove leading and training spaces, tabs and end of line chars in text.
Definition: string.cpp:371
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.
Definition: board_item.h:206
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,...
Definition: board_item.h:86
const std::string KiCadFootprintFileExtension
const wxString GetValue() const
Function GetValue.
Definition: footprint.h:465
static wxFileName getFootprintFilenameFromUser(wxWindow *aParent, const wxString &aLastPath)
Prompt the user for a footprint file to open.
void SetOKLabel(const wxString &aLabel)
COMMIT & Add(EDA_ITEM *aItem)
Adds a new item to the model
Definition: commit.h:78
static FOOTPRINT * parse_footprint_kicad(const wxFileName &aFileName)
Parse a KICAD footprint.
FP_LIB_TABLE GFootprintTable
!!!!!!!!!!!!!! This code is obsolete because of the merge into pcbnew, don't bother with it.
virtual void Update3DView(bool aReloadRequest, const wxString *aTitle=nullptr)
Update the 3D view, if the viewer is opened by this frame.
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:185
A KICAD version of wxTextEntryDialog which supports the various improvments/work-arounds from DIALOG_...
Component library viewer main window.
void SetTextValidator(wxTextValidatorStyle style)
void SetVisible(bool aVisible)
Definition: eda_text.h:191
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:141
void UpdateView()
Reloads displayed items and sets view.
EDA_LIST_DIALOG.
void SaveFootprintToBoard(wxCommandEvent &event)
bool DeleteFootprintFromLibrary(const LIB_ID &aFPID, bool aConfirm)
Delete the given footprint from its library.
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:244
static const wxString ShowType(PCB_FILE_T aFileType)
Function ShowType returns a brief name for a plugin, given aFileType enum.
Definition: io_mgr.cpp:76
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
#define CTL_FOR_LIBRARY
Format output for a footprint library instead of clipboard or BOARD.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:102
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:122
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
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:123
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:184
void PlaceFootprint(FOOTPRINT *aFootprint, bool aRecreateRatsnest=true)
Function PlaceFootprint places aFootprint at the current cursor position and updates footprint coordi...
void ExportFootprintsToLibrary(bool aStoreInNewLib, const wxString &aLibName=wxEmptyString, wxString *aLibPath=NULL)
Function ExportFootprintsToLibrary Save footprints in a library:
FP_TEXT & Value()
read/write accessors:
Definition: footprint.h:480
bool GetTextUpright(PCB_LAYER_ID aLayer) const
This class provides a custom wxValidator object for limiting the allowable characters when defining f...
Definition: validators.h:63
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...
FP_TEXT & Reference()
Definition: footprint.h:481
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:575
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 ExportFootprint(FOOTPRINT *aFootprint)
Create a file containing only one footprint.
void SyncLibraryTree(bool aProgress)
Synchronize the footprint library tree to the current state of the footprint library table.
Definition: kiid.h:44
void ExchangeFootprint(FOOTPRINT *aExisting, FOOTPRINT *aNew, 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,...
static FOOTPRINT * parse_footprint_with_plugin(const wxFileName &aFileName, IO_MGR::PCB_FILE_T aFileType, const wxString &aName)
Parse a footprint using a PLUGIN.
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:181
FOOTPRINT * GetFirstFootprint() const
Gets the first footprint on the board or nullptr.
Definition: board.h:348
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:345
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:29
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)
const wxString GetDescription(const wxString &aNickname)
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
bool SaveFootprintInLibrary(FOOTPRINT *aFootprint, const wxString &aLibraryName)
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...
FOOTPRINTS & Footprints()
Definition: board.h:283
bool AddLibrary(const wxString &aLibName=wxEmptyString)
Function AddLibrary Add an existing library to either the global or project library table.
wxString ModLegacyExportFileWildcard()
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
DRAWINGS & GraphicalItems()
Definition: footprint.h:185
const LIB_ID & GetFPID() const
Definition: footprint.h:208
static IO_MGR::PCB_FILE_T detect_file_type(FILE *aFile, const wxFileName &aFileName, wxString *aName)
Read a file to detect the type.
const wxString GetReference() const
Function GetReference.
Definition: footprint.h:440
virtual void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true)=0
Moves the graphic crosshair cursor to the requested position expressed in world coordinates.
void SetValue(const wxString &aValue)
Function SetValue.
Definition: footprint.h:474
FormatType fileType(const char *aFileName)
Definition: loadmodel.cpp:271
std::unique_ptr< FOOTPRINT > m_revertModule
VTBL_ENTRY bool IsNullProject() const
Checks if this project is a null project (i.e.
Definition: project.cpp:134
#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...
KIID GetLink() const
Definition: footprint.h:556
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:212
const KIID m_Uuid
Definition: eda_item.h:151
VTBL_ENTRY FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
Definition: project.cpp:284
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
FOOTPRINT * CreateNewFootprint(const wxString &aFootprintName)
Function CreateNewFootprint Creates a new footprint, at position 0,0 The new footprint contains only ...
void updateTitle()
Updates window title according to getLibNickName().
void SetFPID(const LIB_ID &aFPID)
Definition: footprint.h:209
void SetKeepUpright(bool aKeepUpright)
Definition: fp_text.h:113
void SetLink(const KIID &aLink)
Definition: footprint.h:557
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:227
wxString KiCadFootprintLibPathWildcard()
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:48
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:56
see class PGM_BASE
LIB_ID GetLoadedFPID() const
Return the LIB_ID of the part being edited.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:186
FOOTPRINT * 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.
#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:57
void SetLastEditTime(timestamp_t aTime)
Definition: footprint.h:344
SAVE_T FootprintSave(const wxString &aNickname, const FOOTPRINT *aFootprint, bool aOverwrite=true)
Function FootprintSave.
PCB_EDIT_FRAME is the main frame for Pcbnew.
void ClrModify()
Definition: base_screen.h:121
bool SaveFootprintAs(FOOTPRINT *aFootprint)
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.
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false)
Show the WX_INFOBAR displayed on the top of the canvas with a message and a Error icon on the left of...
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:96
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:221
FOOTPRINT_EDITOR_SETTINGS * GetSettings()
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction) const
Function RunOnChildren.
Definition: footprint.cpp:1087
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:164
wxString SelectLibrary(const wxString &aNicknameExisting)
Function SelectLibrary puts up a dialog and allows the user to pick a library, for unspecified use.
void AddFootprintToBoard(FOOTPRINT *aFootprint) override
Override from PCB_BASE_EDIT_FRAME which adds a footprint to the editor's dummy board,...
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:76
BOARD * GetBoard() const
void SetPosition(const wxPoint &aPos) override
Definition: footprint.cpp:1344
void Format(BOARD_ITEM *aItem, int aNestLevel=0) const
Output aItem to aFormatter in s-expression format.
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:294
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:268
bool SaveFootprint(FOOTPRINT *aFootprint)
Save in an existing library a given footprint.
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
Definition: board_item.h:185
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:284
const std::string KiCadFootprintLibPathExtension
virtual void ClearUndoRedoList()
Function ClearUndoRedoList clear undo and redo list, using ClearUndoORRedoList() picked items are del...
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.
static const wxChar * StringLibNameInvalidChars(bool aUserReadable)
static function StringLibNameInvalidChars Test for validity of the name in a library of the footprint...
Definition: footprint.cpp:1235
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: eda_item.h:181
FOOTPRINT * ImportFootprint(const wxString &aName=wxT(""))
Read a file containing only one footprint.
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)