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 #define FMT_OK_DELETE _( "OK to delete footprint \"%s\" in library \"%s\"" )
55 #define FMT_IMPORT_MODULE _( "Import Footprint" )
56 #define FMT_FILE_NOT_FOUND _( "File \"%s\" not found" )
57 #define FMT_NOT_MODULE _( "Not a footprint file" )
58 #define FMT_MOD_NOT_FOUND _( "Unable to find or load footprint \"%s\" from lib path \"%s\"" )
59 #define FMT_LIB_READ_ONLY _( "Library \"%s\" is read only, not writable" )
60 
61 #define FMT_EXPORT_MODULE _( "Export Footprint" )
62 #define FMT_SAVE_MODULE _( "Save Footprint" )
63 #define FMT_MOD_REF _( "Enter footprint name:" )
64 #define FMT_EXPORTED _( "Footprint exported to file \"%s\"" )
65 #define FMT_MOD_DELETED _( "Footprint \"%s\" deleted from library \"%s\"" )
66 #define FMT_MOD_CREATE _( "New Footprint" )
67 
68 #define FMT_NO_REF_ABORTED _( "No footprint name defined." )
69 #define FMT_SELECT_LIB _( "Select Library" )
70 
71 static const wxString INFO_LEGACY_LIB_WARN_EDIT(
72  _( "Writing/modifying legacy libraries (.mod files) is not allowed\n"\
73  "Please save the current library to the new .pretty format\n"\
74  "and update your footprint lib table\n"\
75  "to save your footprint (a .kicad_mod file) in the .pretty library folder" ) );
76 
77 static const wxString INFO_LEGACY_LIB_WARN_DELETE(
78  _( "Modifying legacy libraries (.mod files) is not allowed\n"\
79  "Please save the current library under the new .pretty format\n"\
80  "and update your footprint lib table\n"\
81  "before deleting a footprint" ) );
82 
83 
89 static wxFileName getFootprintFilenameFromUser( wxWindow* aParent, const wxString& aLastPath )
90 {
91  static int lastFilterIndex = 0; // To store the last choice during a session.
92  wxString wildCard;
93 
94  wildCard << KiCadFootprintLibFileWildcard() << wxChar( '|' )
95  << ModLegacyExportFileWildcard() << wxChar( '|' )
96  << GedaPcbFootprintLibFileWildcard() << wxChar( '|' )
97  << AllFilesWildcard();
98 
99  wxFileDialog dlg( aParent, FMT_IMPORT_MODULE, aLastPath, wxEmptyString, wildCard,
100  wxFD_OPEN | wxFD_FILE_MUST_EXIST );
101 
102  dlg.SetFilterIndex( lastFilterIndex );
103 
104  if( dlg.ShowModal() == wxID_CANCEL )
105  return wxFileName();
106 
107  lastFilterIndex = dlg.GetFilterIndex();
108 
109  return wxFileName( dlg.GetPath() );
110 }
111 
112 
119 static IO_MGR::PCB_FILE_T detect_file_type( FILE* aFile, const wxFileName& aFileName,
120  wxString* aName )
121 {
122  FILE_LINE_READER freader( aFile, aFileName.GetFullPath() );
123  WHITESPACE_FILTER_READER reader( freader );
124  IO_MGR::PCB_FILE_T file_type;
125 
126  wxASSERT( aName );
127 
128  reader.ReadLine();
129  char* line = reader.Line();
130 
131  if( !strncasecmp( line, "(module", strlen( "(module" ) ) )
132  {
133  file_type = IO_MGR::KICAD_SEXP;
134  *aName = aFileName.GetName();
135  }
136  else if( !strncasecmp( line, FOOTPRINT_LIBRARY_HEADER, FOOTPRINT_LIBRARY_HEADER_CNT ) )
137  {
138  file_type = IO_MGR::LEGACY;
139 
140  while( reader.ReadLine() )
141  {
142  if( !strncasecmp( line, "$MODULE", strlen( "$MODULE" ) ) )
143  {
144  *aName = FROM_UTF8( StrPurge( line + strlen( "$MODULE" ) ) );
145  break;
146  }
147  }
148  }
149  else if( !strncasecmp( line, "Element", strlen( "Element" ) ) )
150  {
151  file_type = IO_MGR::GEDA_PCB;
152  *aName = aFileName.GetName();
153  }
154  else
155  {
156  file_type = IO_MGR::FILE_TYPE_NONE;
157  }
158 
159  return file_type;
160 }
161 
162 
170  const wxFileName& aFileName, IO_MGR::PCB_FILE_T aFileType,
171  const wxString& aName )
172 {
173  wxString path;
174 
175  switch( aFileType )
176  {
177  case IO_MGR::GEDA_PCB:
178  path = aFileName.GetPath();
179  break;
180  case IO_MGR::LEGACY:
181  path = aFileName.GetFullPath();
182  break;
183  default:
184  wxFAIL_MSG( wxT( "unexpected IO_MGR::PCB_FILE_T" ) );
185  }
186 
187  PLUGIN::RELEASER pi( IO_MGR::PluginFind( aFileType ) );
188 
189  return pi->FootprintLoad( path, aName );
190 }
191 
192 
197 static MODULE* parse_module_kicad( const wxFileName& aFileName )
198 {
199  wxString fcontents;
200  PCB_IO pcb_io;
201  wxFFile f( aFileName.GetFullPath() );
202 
203  if( !f.IsOpened() )
204  return NULL;
205 
206  f.ReadAll( &fcontents );
207 
208  return dynamic_cast<MODULE*>( pcb_io.Parse( fcontents ) );
209 }
210 
211 
218 MODULE* try_load_footprint( const wxFileName& aFileName, IO_MGR::PCB_FILE_T aFileType,
219  const wxString& aName )
220 {
221  MODULE* module;
222 
223  switch( aFileType )
224  {
225  case IO_MGR::GEDA_PCB:
226  case IO_MGR::LEGACY:
227  module = parse_module_with_plugin( aFileName, aFileType, aName );
228  break;
229 
230  case IO_MGR::KICAD_SEXP:
231  module = parse_module_kicad( aFileName );
232  break;
233 
234  default:
235  wxFAIL_MSG( wxT( "unexpected IO_MGR::PCB_FILE_T" ) );
236  module = NULL;
237  }
238 
239  return module;
240 }
241 
242 
244 {
245  wxString lastOpenedPathForLoading = m_mruPath;
247 
248  if( !cfg->m_LastImportExportPath.empty() )
249  lastOpenedPathForLoading = cfg->m_LastImportExportPath;
250 
251  wxFileName fn;
252 
253  if( aName != wxT("") )
254  fn = aName;
255  else
256  fn = getFootprintFilenameFromUser( this, lastOpenedPathForLoading );
257 
258  if( !fn.IsOk() )
259  return NULL;
260 
261  FILE* fp = wxFopen( fn.GetFullPath(), wxT( "rt" ) );
262 
263  if( !fp )
264  {
265  wxString msg = wxString::Format( FMT_FILE_NOT_FOUND, GetChars( fn.GetFullPath() ) );
266  DisplayError( this, msg );
267  return NULL;
268  }
269 
270  cfg->m_LastImportExportPath = lastOpenedPathForLoading;
271 
272  wxString moduleName;
273  IO_MGR::PCB_FILE_T fileType = detect_file_type( fp, fn.GetFullPath(), &moduleName );
274 
276  {
277  DisplayError( this, FMT_NOT_MODULE );
278  return NULL;
279  }
280 
281  MODULE* module = NULL;
282 
283  try
284  {
285  module = try_load_footprint( fn, fileType, moduleName );
286 
287  if( !module )
288  {
289  wxString msg = wxString::Format(
290  FMT_MOD_NOT_FOUND, GetChars( moduleName ), GetChars( fn.GetFullPath() ) );
291  DisplayError( this, msg );
292  return NULL;
293  }
294  }
295  catch( const IO_ERROR& ioe )
296  {
297  DisplayError( this, ioe.What() );
298 
299  // if the footprint is not loaded, exit.
300  // However, even if an error happens, it can be loaded, because in KICAD and GPCB format,
301  // a fp library is a set of separate files, and the error(s) are not necessary when
302  // reading the selected file
303 
304  if( !module )
305  return NULL;
306  }
307 
308  module->SetFPID( LIB_ID( wxEmptyString, moduleName ) );
309 
310  // Insert footprint in list
311  AddModuleToBoard( module );
312 
313  // Display info :
314  SetMsgPanel( module );
315  PlaceModule( module );
316 
317  module->SetPosition( wxPoint( 0, 0 ) );
318 
320  updateView();
321 
322  return module;
323 }
324 
325 
327 {
328  wxFileName fn;
330 
331  if( !aModule )
332  return;
333 
334  fn.SetName( aModule->GetFPID().GetLibItemName() );
335 
336  wxString wildcard = KiCadFootprintLibFileWildcard();
337 
338  fn.SetExt( KiCadFootprintFileExtension );
339 
340  if( !cfg->m_LastImportExportPath.empty() )
341  fn.SetPath( cfg->m_LastImportExportPath );
342  else
343  fn.SetPath( m_mruPath );
344 
345  wxFileDialog dlg( this, FMT_EXPORT_MODULE, fn.GetPath(), fn.GetFullName(),
346  wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
347 
348  if( dlg.ShowModal() == wxID_CANCEL )
349  return;
350 
351  fn = dlg.GetPath();
352  cfg->m_LastImportExportPath = fn.GetPath();
353 
354  try
355  {
356  // Export as *.kicad_pcb format, using a strategy which is specifically chosen
357  // as an example on how it could also be used to send it to the system clipboard.
358 
359  PCB_IO pcb_io( CTL_FOR_LIBRARY );
360 
361  /* This module should *already* be "normalized" in a way such that
362  orientation is zero, etc., since it came from module editor.
363 
364  module->SetParent( 0 );
365  module->SetOrientation( 0 );
366  */
367 
368  pcb_io.Format( aModule );
369 
370  FILE* fp = wxFopen( dlg.GetPath(), wxT( "wt" ) );
371 
372  if( fp == NULL )
373  {
374  wxMessageBox( wxString::Format( _( "Unable to create or write file \"%s\"" ),
375  dlg.GetPath() ) );
376  return;
377  }
378 
379  fprintf( fp, "%s", pcb_io.GetStringOutput( false ).c_str() );
380  fclose( fp );
381  }
382  catch( const IO_ERROR& ioe )
383  {
384  DisplayError( this, ioe.What() );
385  return;
386  }
387 
388  wxString msg = wxString::Format( FMT_EXPORTED, GetChars( dlg.GetPath() ) );
389  DisplayInfoMessage( this, msg );
390 }
391 
392 
393 wxString PCB_BASE_EDIT_FRAME::CreateNewLibrary(const wxString& aLibName )
394 {
395  // Kicad cannot write legacy format libraries, only .pretty new format
396  // because the legacy format cannot handle current features.
397  // The footprint library is actually a directory
398 
399  wxString initialPath = wxPathOnly( Prj().GetProjectFullName() );
400  wxFileName fn;
401  bool doAdd = false;
402 
403  if( aLibName.IsEmpty() )
404  {
405  fn = initialPath;
406 
407  if( !LibraryFileBrowser( false, fn,
409  {
410  return wxEmptyString;
411  }
412 
413  doAdd = true;
414  }
415  else
416  {
417  fn = aLibName;
418 
419  if( !fn.IsAbsolute() )
420  {
421  fn.SetName( aLibName );
422  fn.MakeAbsolute( initialPath );
423  }
424 
425  // Enforce the .pretty extension:
426  fn.SetExt( KiCadFootprintLibPathExtension );
427  }
428 
429  // We can save fp libs only using IO_MGR::KICAD_SEXP format (.pretty libraries)
431  wxString libPath = fn.GetFullPath();
432 
433  try
434  {
435  PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) );
436 
437  bool writable = false;
438  bool exists = false;
439 
440  try
441  {
442  writable = pi->IsFootprintLibWritable( libPath );
443  exists = true; // no exception was thrown, lib must exist.
444  }
445  catch( const IO_ERROR& )
446  { }
447 
448  if( exists )
449  {
450  if( !writable )
451  {
452  wxString msg = wxString::Format( FMT_LIB_READ_ONLY, libPath );
453  DisplayError( this, msg );
454  return wxEmptyString;
455  }
456  else
457  {
458  wxString msg = wxString::Format( _( "Library %s already exists." ), libPath );
459  KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
460  dlg.SetOKLabel( _( "Overwrite" ) );
461  dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
462 
463  if( dlg.ShowModal() == wxID_CANCEL )
464  return wxEmptyString;
465 
466  pi->FootprintLibDelete( libPath );
467  }
468  }
469 
470  pi->FootprintLibCreate( libPath );
471  }
472  catch( const IO_ERROR& ioe )
473  {
474  DisplayError( this, ioe.What() );
475  return wxEmptyString;
476  }
477 
478  if( doAdd )
479  AddLibrary( libPath );
480 
481  return libPath;
482 }
483 
484 
485 bool PCB_BASE_EDIT_FRAME::AddLibrary( const wxString& aFilename )
486 {
487  wxFileName fn( aFilename );
488 
489  if( aFilename.IsEmpty() )
490  {
491  if( !LibraryFileBrowser( true, fn,
493  true ) )
494  {
495  return false;
496  }
497  }
498 
499  wxString libPath = fn.GetFullPath();
500  wxString libName = fn.GetName();
501 
502  if( libName.IsEmpty() )
503  return false;
504 
505  bool saveInGlobalTable = false;
506  bool saveInProjectTable = false;
507  wxArrayString libTableNames;
508 
509  libTableNames.Add( _( "Global" ) );
510  libTableNames.Add( _( "Project" ) );
511 
512  switch( SelectSingleOption( this, _( "Select Library Table" ),
513  _( "Choose the Library Table to add the library to:" ),
514  libTableNames ) )
515  {
516  case 0: saveInGlobalTable = true; break;
517  case 1: saveInProjectTable = true; break;
518  default: return false;
519  }
520 
521  wxString type = IO_MGR::ShowType( IO_MGR::GuessPluginTypeFromLibPath( libPath ) );
522 
523  // try to use path normalized to an environmental variable or project path
524  wxString normalizedPath = NormalizePath( libPath, &Pgm().GetLocalEnvVariables(), &Prj() );
525 
526  if( normalizedPath.IsEmpty() )
527  normalizedPath = libPath;
528 
529  try
530  {
531  if( saveInGlobalTable )
532  {
533  auto row = new FP_LIB_TABLE_ROW( libName, normalizedPath, type, wxEmptyString );
534  GFootprintTable.InsertRow( row );
536  }
537  else if( saveInProjectTable )
538  {
539  auto row = new FP_LIB_TABLE_ROW( libName, normalizedPath, type, wxEmptyString );
540  Prj().PcbFootprintLibs()->InsertRow( row );
541  Prj().PcbFootprintLibs()->Save( Prj().FootprintLibTblName() );
542  }
543  }
544  catch( const IO_ERROR& ioe )
545  {
546  DisplayError( this, ioe.What() );
547  return false;
548  }
549 
550  auto editor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_FOOTPRINT_EDITOR, false );
551 
552  if( editor )
553  {
554  LIB_ID libID( libName, wxEmptyString );
555  editor->SyncLibraryTree( true );
556  editor->FocusOnLibID( libID );
557  }
558 
559  auto viewer = (FOOTPRINT_VIEWER_FRAME*) Kiway().Player( FRAME_FOOTPRINT_VIEWER, false );
560 
561  if( viewer )
562  viewer->ReCreateLibraryList();
563 
564  return true;
565 }
566 
567 
568 bool FOOTPRINT_EDIT_FRAME::DeleteModuleFromLibrary( const LIB_ID& aFPID, bool aConfirm )
569 {
570  if( !aFPID.IsValid() )
571  return false;
572 
573  wxString nickname = aFPID.GetLibNickname();
574  wxString fpname = aFPID.GetLibItemName();
575 
576  // Legacy libraries are readable, but modifying legacy format is not allowed
577  // So prompt the user if he try to delete a footprint from a legacy lib
578  wxString libfullname = Prj().PcbFootprintLibs()->FindRow( nickname )->GetFullURI();
579 
580  if( IO_MGR::GuessPluginTypeFromLibPath( libfullname ) == IO_MGR::LEGACY )
581  {
583  return false;
584  }
585 
586  if( !Prj().PcbFootprintLibs()->IsFootprintLibWritable( nickname ) )
587  {
588  wxString msg = wxString::Format( _( "Library \"%s\" is read only" ), nickname );
589  DisplayError( this, msg );
590  return false;
591  }
592 
593  // Confirmation
594  wxString msg = wxString::Format( FMT_OK_DELETE, fpname.GetData(), nickname.GetData() );
595 
596  if( aConfirm && !IsOK( this, msg ) )
597  return false;
598 
599  try
600  {
601  Prj().PcbFootprintLibs()->FootprintDelete( nickname, fpname );
602  }
603  catch( const IO_ERROR& ioe )
604  {
605  DisplayError( this, ioe.What() );
606  return false;
607  }
608 
609  msg.Printf( FMT_MOD_DELETED, fpname.GetData(), nickname.GetData() );
610 
611  SetStatusText( msg );
612 
613  return true;
614 }
615 
616 
617 void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aStoreInNewLib, const wxString& aLibName,
618  wxString* aLibPath )
619 {
620  if( GetBoard()->GetFirstModule() == NULL )
621  {
622  DisplayInfoMessage( this, _( "No footprints to archive!" ) );
623  return;
624  }
625 
626  wxString footprintName;
627 
628  if( !aStoreInNewLib )
629  {
630  // The footprints are saved in an existing .pretty library in the fp lib table
631  PROJECT& prj = Prj();
632  wxString last_nickname = prj.GetRString( PROJECT::PCB_LIB_NICKNAME );
633  wxString nickname = SelectLibrary( last_nickname );
634 
635  if( !nickname ) // Aborted
636  return;
637 
638  prj.SetRString( PROJECT::PCB_LIB_NICKNAME, nickname );
639 
640  try
641  {
642  FP_LIB_TABLE* tbl = prj.PcbFootprintLibs();
643 
644  for( auto curr_fp : GetBoard()->Modules() )
645  {
646  if( !curr_fp->GetFPID().GetLibItemName().empty() ) // Can happen with old boards.
647  tbl->FootprintSave( nickname, curr_fp, false );
648  }
649  }
650  catch( const IO_ERROR& ioe )
651  {
652  DisplayError( this, ioe.What() );
653  }
654  }
655  else
656  {
657  // The footprints are saved in a new .pretty library.
658  // If this library already exists, all previous footprints will be deleted
659  wxString libPath = CreateNewLibrary( aLibName );
660 
661  if( libPath.IsEmpty() ) // Aborted
662  return;
663 
664 
665  if( aLibPath ) *aLibPath = libPath;
666 
668  PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) );
669 
670  for( auto curr_fp : GetBoard()->Modules() )
671  {
672  try
673  {
674  if( !curr_fp->GetFPID().GetLibItemName().empty() ) // Can happen with old boards.
675  pi->FootprintSave( libPath, curr_fp );
676  }
677  catch( const IO_ERROR& ioe )
678  {
679  DisplayError( this, ioe.What() );
680  }
681  }
682  }
683 }
684 
685 
687 {
688  if( !aModule ) // Happen if no footprint loaded
689  return false;
690 
691  wxString libraryName = aModule->GetFPID().GetLibNickname();
692  wxString footprintName = aModule->GetFPID().GetLibItemName();
693  bool nameChanged = m_footprintNameWhenLoaded != footprintName;
694 
695  if( aModule->GetLink() != niluuid )
696  {
697  if( SaveFootprintToBoard( false ) )
698  {
699  m_footprintNameWhenLoaded = footprintName;
700  return true;
701  }
702  else
703  return false;
704  }
705  else if( libraryName.IsEmpty() || footprintName.IsEmpty() )
706  {
707  if( SaveFootprintAs( aModule ) )
708  {
709  m_footprintNameWhenLoaded = footprintName;
710  SyncLibraryTree( true );
711  return true;
712  }
713  else
714  return false;
715  }
716 
717  FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs();
718 
719  // Legacy libraries are readable, but modifying legacy format is not allowed
720  // So prompt the user if he try to add/replace a footprint in a legacy lib
721  wxString libfullname = tbl->FindRow( libraryName )->GetFullURI();
722 
723  if( IO_MGR::GuessPluginTypeFromLibPath( libfullname ) == IO_MGR::LEGACY )
724  {
726  return false;
727  }
728 
729  if( nameChanged )
730  {
731  LIB_ID oldFPID( libraryName, m_footprintNameWhenLoaded );
732  DeleteModuleFromLibrary( oldFPID, false );
733  }
734 
735  if( !SaveFootprintInLibrary( aModule, libraryName ) )
736  return false;
737 
738  if( nameChanged )
739  {
740  m_footprintNameWhenLoaded = footprintName;
741  SyncLibraryTree( true );
742  }
743 
744  return true;
745 }
746 
747 
748 bool FOOTPRINT_EDIT_FRAME::SaveFootprintInLibrary( MODULE* aModule, const wxString& aLibraryName )
749 {
750  try
751  {
752  aModule->SetFPID( LIB_ID( wxEmptyString, aModule->GetFPID().GetLibItemName() ) );
753 
754  Prj().PcbFootprintLibs()->FootprintSave( aLibraryName, aModule );
755 
756  aModule->SetFPID( LIB_ID( aLibraryName, aModule->GetFPID().GetLibItemName() ) );
757  return true;
758  }
759  catch( const IO_ERROR& ioe )
760  {
761  DisplayError( this, ioe.What() );
762 
763  aModule->SetFPID( LIB_ID( aLibraryName, aModule->GetFPID().GetLibItemName() ) );
764  return false;
765  }
766 }
767 
768 
770 {
771  // update module in the current board,
772  // not just add it to the board with total disregard for the netlist...
773  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB_EDITOR, false );
774 
775  if( pcbframe == NULL ) // happens when the board editor is not active (or closed)
776  {
777  DisplayErrorMessage( this, _("No board currently open." ) );
778  return false;
779  }
780 
781  BOARD* mainpcb = pcbframe->GetBoard();
782  MODULE* source_module = NULL;
783  MODULE* module_in_edit = GetBoard()->GetFirstModule();
784 
785  // Search the old module (source) if exists
786  // Because this source could be deleted when editing the main board...
787  if( module_in_edit->GetLink() != niluuid ) // this is not a new module ...
788  {
789  source_module = nullptr;
790 
791  for( auto mod : mainpcb->Modules() )
792  {
793  if( module_in_edit->GetLink() == mod->m_Uuid )
794  {
795  source_module = mod;
796  break;
797  }
798  }
799  }
800 
801  if( !aAddNew && source_module == NULL ) // source not found
802  {
803  DisplayError( this, _( "Unable to find the footprint on the main board.\nCannot save." ) );
804  return false;
805  }
806 
807  if( aAddNew && source_module != NULL )
808  {
809  DisplayError( this, _( "Footprint already exists on board." ) );
810  return false;
811  }
812 
815  BOARD_COMMIT commit( pcbframe );
816 
817  // Create the "new" module
818  MODULE* newmodule = new MODULE( *module_in_edit );
819  newmodule->SetParent( mainpcb );
820  newmodule->SetLink( niluuid );
821 
822  if( source_module ) // this is an update command
823  {
824  // In the main board,
825  // the new module replace the old module (pos, orient, ref, value
826  // and connexions are kept)
827  // and the source_module (old module) is deleted
828  pcbframe->Exchange_Module( source_module, newmodule, commit );
829  const_cast<KIID&>( newmodule->m_Uuid ) = module_in_edit->GetLink();
830  commit.Push( wxT( "Update module" ) );
831  }
832  else // This is an insert command
833  {
834  KIGFX::VIEW_CONTROLS* viewControls = pcbframe->GetCanvas()->GetViewControls();
835  VECTOR2D cursorPos = viewControls->GetCursorPosition();
836 
837  commit.Add( newmodule );
838  viewControls->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false );
839  pcbframe->PlaceModule( newmodule );
840  newmodule->SetPosition( wxPoint( 0, 0 ) );
841  viewControls->SetCrossHairCursorPosition( cursorPos, false );
842  const_cast<KIID&>( newmodule->m_Uuid ) = KIID();
843  commit.Push( wxT( "Insert module" ) );
844 
845  pcbframe->Raise();
846  pcbframe->GetToolManager()->RunAction( PCB_ACTIONS::placeModule, true, newmodule );
847  }
848 
849  newmodule->ClearFlags();
850 
851  return true;
852 }
853 
854 
856 {
857  if( aModule == NULL )
858  return false;
859 
860  FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs();
861 
862  SetMsgPanel( aModule );
863 
864  wxString libraryName = aModule->GetFPID().GetLibNickname();
865  wxString footprintName = aModule->GetFPID().GetLibItemName();
866  bool updateValue = ( aModule->GetValue() == footprintName );
867 
868  wxArrayString headers;
869  std::vector<wxArrayString> itemsToDisplay;
870  std::vector<wxString> nicknames = tbl->GetLogicalLibs();
871 
872  headers.Add( _( "Nickname" ) );
873  headers.Add( _( "Description" ) );
874 
875  for( const wxString& nickname : nicknames )
876  {
877  wxArrayString item;
878  item.Add( nickname );
879  item.Add( tbl->GetDescription( nickname ) );
880  itemsToDisplay.push_back( item );
881  }
882 
883  EDA_LIST_DIALOG dlg( this, FMT_SAVE_MODULE, headers, itemsToDisplay, libraryName );
884  dlg.SetListLabel( _( "Save in library:" ) );
885  dlg.SetOKLabel( _( "Save" ) );
886 
887  wxBoxSizer* bNameSizer = new wxBoxSizer( wxHORIZONTAL );
888 
889  wxStaticText* label = new wxStaticText( &dlg, wxID_ANY, _( "Name:" ),
890  wxDefaultPosition, wxDefaultSize, 0 );
891  bNameSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 );
892 
893  wxTextCtrl* nameTextCtrl = new wxTextCtrl( &dlg, wxID_ANY, footprintName,
894  wxDefaultPosition, wxDefaultSize, 0 );
895  bNameSizer->Add( nameTextCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
896 
897  wxTextValidator nameValidator( wxFILTER_EXCLUDE_CHAR_LIST );
898  nameValidator.SetCharExcludes( MODULE::StringLibNameInvalidChars( false ) );
899  nameTextCtrl->SetValidator( nameValidator );
900 
901  wxSizer* mainSizer = dlg.GetSizer();
902  mainSizer->Prepend( bNameSizer, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5 );
903 
904  // Move nameTextCtrl to the head of the tab-order
905  if( dlg.GetChildren().DeleteObject( nameTextCtrl ) )
906  dlg.GetChildren().Insert( nameTextCtrl );
907 
908  dlg.SetInitialFocus( nameTextCtrl );
909 
910  dlg.Layout();
911  mainSizer->Fit( &dlg );
912 
913  if( dlg.ShowModal() != wxID_OK )
914  return false; // canceled by user
915 
916  libraryName = dlg.GetTextSelection();
917 
918  if( libraryName.IsEmpty() )
919  {
920  DisplayError( NULL, _( "No library specified. Footprint could not be saved." ) );
921  return false;
922  }
923 
924  footprintName = nameTextCtrl->GetValue();
925  footprintName.Trim( true );
926  footprintName.Trim( false );
927 
928  if( footprintName.IsEmpty() )
929  {
930  DisplayError( NULL, _( "No footprint name specified. Footprint could not be saved." ) );
931  return false;
932  }
933 
934  aModule->SetFPID( LIB_ID( libraryName, footprintName ) );
935 
936  if( updateValue )
937  aModule->SetValue( footprintName );
938 
939  // Legacy libraries are readable, but modifying legacy format is not allowed
940  // So prompt the user if he try to add/replace a footprint in a legacy lib
941  wxString libfullname = Prj().PcbFootprintLibs()->FindRow( libraryName )->GetFullURI();
943 
944  if( piType == IO_MGR::LEGACY )
945  {
947  return false;
948  }
949 
950  bool module_exists = tbl->FootprintExists( libraryName, footprintName );
951 
952  if( module_exists )
953  {
954  wxString msg = wxString::Format( _( "Footprint %s already exists in %s." ),
955  footprintName,
956  libraryName );
957  KIDIALOG chkdlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
958  chkdlg.SetOKLabel( _( "Overwrite" ) );
959 
960  if( chkdlg.ShowModal() == wxID_CANCEL )
961  return false;
962  }
963 
964  if( !SaveFootprintInLibrary( aModule, libraryName ) )
965  return false;
966 
967  // Once saved-as a board footprint is no longer a board footprint
968  aModule->SetLink( niluuid );
969 
970  wxString fmt = module_exists ? _( "Component \"%s\" replaced in \"%s\"" ) :
971  _( "Component \"%s\" added in \"%s\"" );
972 
973  wxString msg = wxString::Format( fmt, footprintName.GetData(), libraryName.GetData() );
974  SetStatusText( msg );
975  updateTitle();
977 
978  return true;
979 }
980 
981 
983 {
984  if( GetScreen()->IsModify() && m_revertModule )
985  {
986  wxString msg = wxString::Format( _( "Revert \"%s\" to last version saved?" ),
987  GetChars( GetLoadedFPID().GetLibItemName() ) );
988 
989  if( ConfirmRevertDialog( this, msg ) )
990  {
991  Clear_Pcb( false );
992  AddModuleToBoard( (MODULE*) m_revertModule->Clone() );
993 
994  Zoom_Automatique( false );
995 
996  Update3DView( true );
997 
999  GetScreen()->ClrModify();
1000 
1001  updateView();
1002  GetCanvas()->Refresh();
1003 
1004  return true;
1005  }
1006  }
1007 
1008  return false;
1009 }
1010 
1011 
1012 MODULE* PCB_BASE_FRAME::CreateNewModule( const wxString& aModuleName )
1013 {
1014  // Creates a new footprint at position 0,0 which contains the minimal items:
1015  // the reference and the value.
1016  // Value : initialized to the footprint name.
1017  // put on fab layer (front side)
1018  // Reference : initialized to a default value (REF**).
1019  // put on silkscreen layer (front side)
1020 
1021  wxString moduleName = aModuleName;
1022 
1023  // Ask for the new module name
1024  if( moduleName.IsEmpty() )
1025  {
1026  WX_TEXT_ENTRY_DIALOG dlg( this, FMT_MOD_REF, FMT_MOD_CREATE, moduleName );
1027  dlg.SetTextValidator( MODULE_NAME_CHAR_VALIDATOR( &moduleName ) );
1028 
1029  if( dlg.ShowModal() != wxID_OK )
1030  return NULL; //Aborted by user
1031  }
1032 
1033  moduleName.Trim( true );
1034  moduleName.Trim( false );
1035 
1036  if( moduleName.IsEmpty() )
1037  {
1039  return NULL;
1040  }
1041 
1042  // Creates the new module and add it to the head of the linked list of modules
1043  MODULE* module = new MODULE( GetBoard() );
1044 
1045  // Update parameters: timestamp ...
1046  module->SetLastEditTime();
1047 
1048  // Update its name in lib
1049  module->SetFPID( LIB_ID( wxEmptyString, moduleName ) );
1050 
1051  wxPoint default_pos;
1053 
1054  // Update reference:
1055  if( settings.m_RefDefaultText.empty() )
1056  module->SetReference( moduleName );
1057  else
1058  module->SetReference( settings.m_RefDefaultText );
1059 
1060  PCB_LAYER_ID layer = ToLAYER_ID( settings.m_RefDefaultlayer );
1061  module->Reference().SetThickness( settings.GetTextThickness( layer ) );
1062  module->Reference().SetTextSize( settings.GetTextSize( layer ) );
1063  module->Reference().SetItalic( settings.GetTextItalic( layer ) );
1064  module->Reference().SetKeepUpright( settings.GetTextUpright( layer ) );
1065  default_pos.y = GetDesignSettings().GetTextSize( layer ).y / 2;
1066  module->Reference().SetPosition( default_pos );
1067  module->Reference().SetLayer( layer );
1068  module->Reference().SetVisible( settings.m_RefDefaultVisibility );
1069 
1070  // Set the value field to a default value
1071  if( settings.m_ValueDefaultText.empty() )
1072  module->SetValue( moduleName );
1073  else
1074  module->SetValue( settings.m_ValueDefaultText );
1075 
1076  layer = ToLAYER_ID( settings.m_ValueDefaultlayer );
1077  module->Value().SetThickness( settings.GetTextThickness( layer ) );
1078  module->Value().SetTextSize( settings.GetTextSize( layer ) );
1079  module->Value().SetItalic( settings.GetTextItalic( layer ) );
1080  module->Value().SetKeepUpright( settings.GetTextUpright( layer ) );
1081  default_pos.y = -default_pos.y;
1082  module->Value().SetPosition( default_pos );
1083  module->Value().SetLayer( layer );
1084  module->Value().SetVisible( settings.m_ValueDefaultVisibility );
1085 
1086  SetMsgPanel( module );
1087  return module;
1088 }
1089 
1090 
1091 wxString PCB_BASE_FRAME::SelectLibrary( const wxString& aNicknameExisting )
1092 {
1093  wxArrayString headers;
1094 
1095  headers.Add( _( "Nickname" ) );
1096  headers.Add( _( "Description" ) );
1097 
1098  FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs();
1099 
1100  std::vector< wxArrayString > itemsToDisplay;
1101  std::vector< wxString > nicknames = fptbl->GetLogicalLibs();
1102 
1103  for( unsigned i = 0; i < nicknames.size(); i++ )
1104  {
1105  wxArrayString item;
1106 
1107  item.Add( nicknames[i] );
1108  item.Add( fptbl->GetDescription( nicknames[i] ) );
1109 
1110  itemsToDisplay.push_back( item );
1111  }
1112 
1113  EDA_LIST_DIALOG dlg( this, FMT_SELECT_LIB, headers, itemsToDisplay, aNicknameExisting );
1114 
1115  if( dlg.ShowModal() != wxID_OK )
1116  return wxEmptyString;
1117 
1118  wxString nickname = dlg.GetTextSelection();
1119 
1120  wxLogDebug( wxT( "Chose footprint library \"%s\"." ), GetChars( nickname ) );
1121 
1122  return nickname;
1123 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:73
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:550
wxString m_RefDefaultText
Default ref text on fp creation.
void BuildListOfNets()
Definition: class_board.h:692
static TOOL_ACTION placeModule
Definition: pcb_actions.h:160
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.
bool m_ValueDefaultVisibility
Default value text visibility on fp creation.
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
void SetKeepUpright(bool aKeepUpright)
TEXTE_MODULE & Reference()
Definition: class_module.h:477
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
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
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
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:103
BOARD_ITEM * Parse(const wxString &aClipboardSourceInput)
wxString GetTextSelection(int aColumn=0)
Function GetTextSelection return the selected text from aColumn in the wxListCtrl in the dialog.
Definition: displlst.cpp:141
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.
wxString m_mruPath
PROJECT holds project specific data.
Definition: project.h:59
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:62
char * StrPurge(char *text)
Remove leading and training spaces, tabs and end of line chars in text.
Definition: string.cpp:310
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.
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)
Definition: displlst.cpp:112
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:163
Component library viewer main window.
void SetTextValidator(wxTextValidatorStyle style)
void SetVisible(bool aVisible)
Definition: eda_text.h:169
const wxString GetValue() const
Function GetValue.
Definition: class_module.h:461
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:139
EDA_LIST_DIALOG.
#define FMT_SELECT_LIB
int m_ValueDefaultlayer
Default value text layer on fp creation.
const LIB_ID & GetFPID() const
Definition: class_module.h:219
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:222
static const wxChar * StringLibNameInvalidChars(bool aUserReadable)
static function StringLibNameInvalidChars Test for validity of the name in a library of the footprint...
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:77
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()
#define FMT_NOT_MODULE
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:115
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:60
static PCB_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath)
Function GuessPluginTypeFromLibPath returns a plugin type given a footprint library's libPath.
Definition: io_mgr.cpp:124
This file contains miscellaneous commonly used macros and functions.
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:577
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:65
std::unique_ptr< MODULE > m_revertModule
#define FMT_NO_REF_ABORTED
#define FMT_MOD_DELETED
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:98
FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
#define FMT_MOD_NOT_FOUND
#define NULL
#define FMT_OK_DELETE
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:341
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
MODULES & Modules()
Definition: class_board.h:229
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)
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:218
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:476
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:347
virtual void ClearUndoRedoList()
Function ClearUndoRedoList clear undo and redo list, using ClearUndoORRedoList() picked items are del...
bool AddLibrary(const wxString &aLibName=wxEmptyString)
Function AddLibrary Add an existing library to either the global or project library table.
#define FMT_SAVE_MODULE
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:283
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:446
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.
#define FMT_FILE_NOT_FOUND
void SetPosition(const wxPoint &aPos) override
wxString m_ValueDefaultText
Default value text on fp creation.
#define FMT_EXPORT_MODULE
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
#define FMT_LIB_READ_ONLY
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:198
const KIID m_Uuid
Definition: base_struct.h:169
VTBL_ENTRY FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
Definition: project.cpp:427
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:213
wxString KiCadFootprintLibPathWildcard()
#define CTL_FOR_LIBRARY
Format output for a footprint library instead of clipboard or BOARD.
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:101
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:163
#define FMT_IMPORT_MODULE
#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:58
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:225
void SetValue(const wxString &aValue)
Function SetValue.
Definition: class_module.h:470
#define FMT_EXPORTED
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
int m_RefDefaultlayer
Default ref text layer on fp creation.
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:549
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:258
FOOTPRINT_EDITOR_SETTINGS * GetSettings()
wxString SelectLibrary(const wxString &aNicknameExisting)
Function SelectLibrary puts up a dialog and allows the user to pick a library, for unspecified use.
TOOL_MANAGER * m_toolManager
void AddModuleToBoard(MODULE *module) override
Override from PCB_BASE_EDIT_FRAME which adds a module to the editor's dummy board,...
Module description (excepted pads)
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.
#define FMT_MOD_CREATE
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
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
bool m_RefDefaultVisibility
Default ref text visibility on fp creation.
void SetFPID(const LIB_ID &aFPID)
Definition: class_module.h:220
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:823
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.
void SetThickness(int aNewThickness)
Set the pen width.
Definition: eda_text.h:143
wxString GedaPcbFootprintLibFileWildcard()
#define FMT_MOD_REF
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.
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)
Definition: displlst.cpp:105