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-2018 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 
29 #include <wx/ffile.h>
30 #include <wx/stdpaths.h>
31 
32 #include <fctsys.h>
33 #include <pgm_base.h>
34 #include <kiface_i.h>
35 #include <class_drawpanel.h>
36 #include <confirm.h>
37 #include <kicad_string.h>
38 #include <gestfich.h>
39 #include <pcb_edit_frame.h>
40 #include <dialog_helpers.h>
41 #include <filter_reader.h>
42 #include <macros.h>
43 #include <fp_lib_table.h>
44 #include <validators.h>
45 #include <dialog_text_entry.h>
46 #include <tool/tool_manager.h>
47 #include <tools/pcb_actions.h>
48 #include <class_board.h>
49 #include <class_module.h>
50 #include <board_commit.h>
51 #include <pcbnew.h>
52 #include <footprint_edit_frame.h>
54 #include <kicad_plugin.h>
55 #include <legacy_plugin.h>
56 #include <env_paths.h>
57 #include "footprint_viewer_frame.h"
58 
59 
60 // unique, "file local" translations:
61 
62 #define FMT_OK_DELETE _( "OK to delete footprint \"%s\" in library \"%s\"" )
63 #define FMT_IMPORT_MODULE _( "Import Footprint" )
64 #define FMT_FILE_NOT_FOUND _( "File \"%s\" not found" )
65 #define FMT_NOT_MODULE _( "Not a footprint file" )
66 #define FMT_MOD_NOT_FOUND _( "Unable to find or load footprint \"%s\" from lib path \"%s\"" )
67 #define FMT_LIB_READ_ONLY _( "Library \"%s\" is read only, not writable" )
68 
69 #define FMT_EXPORT_MODULE _( "Export Footprint" )
70 #define FMT_SAVE_MODULE _( "Save Footprint" )
71 #define FMT_MOD_REF _( "Enter footprint name:" )
72 #define FMT_EXPORTED _( "Footprint exported to file \"%s\"" )
73 #define FMT_MOD_DELETED _( "Footprint \"%s\" deleted from library \"%s\"" )
74 #define FMT_MOD_CREATE _( "New Footprint" )
75 
76 #define FMT_NO_REF_ABORTED _( "No footprint name defined." )
77 #define FMT_SELECT_LIB _( "Select Library" )
78 
79 static const wxString INFO_LEGACY_LIB_WARN_EDIT(
80  _( "Writing/modifying legacy libraries (.mod files) is not allowed\n"\
81  "Please save the current library to the new .pretty format\n"\
82  "and update your footprint lib table\n"\
83  "to save your footprint (a .kicad_mod file) in the .pretty library folder" ) );
84 
85 static const wxString INFO_LEGACY_LIB_WARN_DELETE(
86  _( "Modifying legacy libraries (.mod files) is not allowed\n"\
87  "Please save the current library under the new .pretty format\n"\
88  "and update your footprint lib table\n"\
89  "before deleting a footprint" ) );
90 
91 
92 #define EXPORT_IMPORT_LASTPATH_KEY wxT( "import_last_path" )
93 
94 
100 static wxFileName getFootprintFilenameFromUser( wxWindow* aParent, const wxString& aLastPath )
101 {
102  static int lastFilterIndex = 0; // To store the last choice during a session.
103  wxString wildCard;
104 
105  wildCard << KiCadFootprintLibFileWildcard() << wxChar( '|' )
106  << ModLegacyExportFileWildcard() << wxChar( '|' )
108 
109  wxFileDialog dlg( aParent, FMT_IMPORT_MODULE, aLastPath, wxEmptyString, wildCard,
110  wxFD_OPEN | wxFD_FILE_MUST_EXIST );
111 
112  dlg.SetFilterIndex( lastFilterIndex );
113 
114  if( dlg.ShowModal() == wxID_CANCEL )
115  return wxFileName();
116 
117  lastFilterIndex = dlg.GetFilterIndex();
118 
119  return wxFileName( dlg.GetPath() );
120 }
121 
122 
129 static IO_MGR::PCB_FILE_T detect_file_type( FILE* aFile, const wxFileName& aFileName,
130  wxString* aName )
131 {
132  FILE_LINE_READER freader( aFile, aFileName.GetFullPath() );
133  WHITESPACE_FILTER_READER reader( freader );
134  IO_MGR::PCB_FILE_T file_type;
135 
136  wxASSERT( aName );
137 
138  reader.ReadLine();
139  char* line = reader.Line();
140 
141  if( !strncasecmp( line, "(module", strlen( "(module" ) ) )
142  {
143  file_type = IO_MGR::KICAD_SEXP;
144  *aName = aFileName.GetName();
145  }
146  else if( !strncasecmp( line, FOOTPRINT_LIBRARY_HEADER, FOOTPRINT_LIBRARY_HEADER_CNT ) )
147  {
148  file_type = IO_MGR::LEGACY;
149 
150  while( reader.ReadLine() )
151  {
152  if( !strncasecmp( line, "$MODULE", strlen( "$MODULE" ) ) )
153  {
154  *aName = FROM_UTF8( StrPurge( line + strlen( "$MODULE" ) ) );
155  break;
156  }
157  }
158  }
159  else if( !strncasecmp( line, "Element", strlen( "Element" ) ) )
160  {
161  file_type = IO_MGR::GEDA_PCB;
162  *aName = aFileName.GetName();
163  }
164  else
165  {
166  file_type = IO_MGR::FILE_TYPE_NONE;
167  }
168 
169  return file_type;
170 }
171 
172 
180  const wxFileName& aFileName, IO_MGR::PCB_FILE_T aFileType,
181  const wxString& aName )
182 {
183  wxString path;
184 
185  switch( aFileType )
186  {
187  case IO_MGR::GEDA_PCB:
188  path = aFileName.GetPath();
189  break;
190  case IO_MGR::LEGACY:
191  path = aFileName.GetFullPath();
192  break;
193  default:
194  wxFAIL_MSG( wxT( "unexpected IO_MGR::PCB_FILE_T" ) );
195  }
196 
197  PLUGIN::RELEASER pi( IO_MGR::PluginFind( aFileType ) );
198 
199  return pi->FootprintLoad( path, aName );
200 }
201 
202 
207 static MODULE* parse_module_kicad( const wxFileName& aFileName )
208 {
209  wxString fcontents;
210  PCB_IO pcb_io;
211  wxFFile f( aFileName.GetFullPath() );
212 
213  if( !f.IsOpened() )
214  return NULL;
215 
216  f.ReadAll( &fcontents );
217 
218  return dynamic_cast<MODULE*>( pcb_io.Parse( fcontents ) );
219 }
220 
221 
228 MODULE* try_load_footprint( const wxFileName& aFileName, IO_MGR::PCB_FILE_T aFileType,
229  const wxString& aName )
230 {
231  MODULE* module;
232 
233  switch( aFileType )
234  {
235  case IO_MGR::GEDA_PCB:
236  case IO_MGR::LEGACY:
237  module = parse_module_with_plugin( aFileName, aFileType, aName );
238  break;
239 
240  case IO_MGR::KICAD_SEXP:
241  module = parse_module_kicad( aFileName );
242  break;
243 
244  default:
245  wxFAIL_MSG( wxT( "unexpected IO_MGR::PCB_FILE_T" ) );
246  module = NULL;
247  }
248 
249  return module;
250 }
251 
252 
254 {
255  wxString lastOpenedPathForLoading = m_mruPath;
256  wxConfigBase* cfg = Kiface().KifaceSettings();
257 
258  if( cfg )
259  cfg->Read( EXPORT_IMPORT_LASTPATH_KEY, &lastOpenedPathForLoading );
260 
261  wxFileName fn;
262 
263  if( aName != wxT("") )
264  fn = aName;
265  else
266  fn = getFootprintFilenameFromUser( this, lastOpenedPathForLoading );
267 
268  if( !fn.IsOk() )
269  return NULL;
270 
271  FILE* fp = wxFopen( fn.GetFullPath(), wxT( "rt" ) );
272 
273  if( !fp )
274  {
275  wxString msg = wxString::Format( FMT_FILE_NOT_FOUND, GetChars( fn.GetFullPath() ) );
276  DisplayError( this, msg );
277  return NULL;
278  }
279 
280  if( cfg ) // Save file path
281  {
282  lastOpenedPathForLoading = fn.GetPath();
283  cfg->Write( EXPORT_IMPORT_LASTPATH_KEY, lastOpenedPathForLoading );
284  }
285 
286  wxString moduleName;
287  IO_MGR::PCB_FILE_T fileType = detect_file_type( fp, fn.GetFullPath(), &moduleName );
288 
289  if( fileType == IO_MGR::FILE_TYPE_NONE )
290  {
291  DisplayError( this, FMT_NOT_MODULE );
292  return NULL;
293  }
294 
295  MODULE* module = NULL;
296 
297  try
298  {
299  module = try_load_footprint( fn, fileType, moduleName );
300 
301  if( !module )
302  {
303  wxString msg = wxString::Format(
304  FMT_MOD_NOT_FOUND, GetChars( moduleName ), GetChars( fn.GetFullPath() ) );
305  DisplayError( this, msg );
306  return NULL;
307  }
308  }
309  catch( const IO_ERROR& ioe )
310  {
311  DisplayError( this, ioe.What() );
312 
313  // if the footprint is not loaded, exit.
314  // However, even if an error happens, it can be loaded, because in KICAD and GPCB format,
315  // a fp library is a set of separate files, and the error(s) are not necessary when
316  // reading the selected file
317 
318  if( !module )
319  return NULL;
320  }
321 
322  module->SetFPID( LIB_ID( wxEmptyString, moduleName ) );
323 
324  // Insert footprint in list
325  AddModuleToBoard( module );
326 
327  // Display info :
328  SetMsgPanel( module );
329  PlaceModule( module, NULL );
330 
331  if( IsGalCanvasActive() )
332  module->SetPosition( wxPoint( 0, 0 ) );
333 
334  GetBoard()->m_Status_Pcb = 0;
336  updateView();
337 
338  return module;
339 }
340 
341 
343 {
344  wxFileName fn;
345  wxConfigBase* cfg = Kiface().KifaceSettings();
346 
347  if( !aModule )
348  return;
349 
350  fn.SetName( aModule->GetFPID().GetLibItemName() );
351 
352  wxString wildcard = KiCadFootprintLibFileWildcard();
353 
354  fn.SetExt( KiCadFootprintFileExtension );
355 
356  if( cfg )
357  {
358  wxString path;
359  cfg->Read( EXPORT_IMPORT_LASTPATH_KEY, &path, m_mruPath );
360  fn.SetPath( path );
361  }
362 
363  wxFileDialog dlg( this, FMT_EXPORT_MODULE, fn.GetPath(), fn.GetFullName(),
364  wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
365 
366  if( dlg.ShowModal() == wxID_CANCEL )
367  return;
368 
369  fn = dlg.GetPath();
370 
371  if( cfg ) // Save file path
372  {
373  cfg->Write( EXPORT_IMPORT_LASTPATH_KEY, fn.GetPath() );
374  }
375 
376  try
377  {
378  // Export as *.kicad_pcb format, using a strategy which is specifically chosen
379  // as an example on how it could also be used to send it to the system clipboard.
380 
381  PCB_IO pcb_io( CTL_FOR_LIBRARY );
382 
383  /* This module should *already* be "normalized" in a way such that
384  orientation is zero, etc., since it came from module editor.
385 
386  module->SetTimeStamp( 0 );
387  module->SetParent( 0 );
388  module->SetOrientation( 0 );
389  */
390 
391  pcb_io.Format( aModule );
392 
393  FILE* fp = wxFopen( dlg.GetPath(), wxT( "wt" ) );
394 
395  if( fp == NULL )
396  {
397  wxMessageBox( wxString::Format(
398  _( "Unable to create or write file \"%s\"" ),
399  GetChars( dlg.GetPath() ) ) );
400  return;
401  }
402 
403  fprintf( fp, "%s", pcb_io.GetStringOutput( false ).c_str() );
404  fclose( fp );
405  }
406  catch( const IO_ERROR& ioe )
407  {
408  DisplayError( this, ioe.What() );
409  return;
410  }
411 
412  wxString msg = wxString::Format( FMT_EXPORTED, GetChars( dlg.GetPath() ) );
413  DisplayInfoMessage( this, msg );
414 }
415 
416 
417 wxString PCB_BASE_EDIT_FRAME::CreateNewLibrary(const wxString& aLibName )
418 {
419  // Kicad cannot write legacy format libraries, only .pretty new format
420  // because the legacy format cannot handle current features.
421  // The footprint library is actually a directory
422 
423  wxString initialPath = wxPathOnly( Prj().GetProjectFullName() );
424  wxFileName fn;
425  bool doAdd = false;
426 
427  if( aLibName.IsEmpty() )
428  {
429  fn = initialPath;
430 
431  if( !LibraryFileBrowser( false, fn,
433  true ) )
434  {
435  return wxEmptyString;
436  }
437 
438  doAdd = true;
439  }
440  else
441  {
442  fn = aLibName;
443 
444  if( !fn.IsAbsolute() )
445  {
446  fn.SetName( aLibName );
447  fn.MakeAbsolute( initialPath );
448  }
449 
450  // Enforce the .pretty extension:
451  fn.SetExt( KiCadFootprintLibPathExtension );
452  }
453 
454  // We can save fp libs only using IO_MGR::KICAD_SEXP format (.pretty libraries)
456  wxString libPath = fn.GetFullPath();
457 
458  try
459  {
460  PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) );
461 
462  bool writable = false;
463  bool exists = false;
464 
465  try
466  {
467  writable = pi->IsFootprintLibWritable( libPath );
468  exists = true; // no exception was thrown, lib must exist.
469  }
470  catch( const IO_ERROR& )
471  { }
472 
473  if( exists )
474  {
475  if( !writable )
476  {
477  wxString msg = wxString::Format( FMT_LIB_READ_ONLY, libPath );
478  DisplayError( this, msg );
479  return wxEmptyString;
480  }
481  else
482  {
483  wxString msg = wxString::Format( _( "Library %s already exists." ), libPath );
484  KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
485  dlg.SetOKLabel( _( "Overwrite" ) );
486  dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
487 
488  if( dlg.ShowModal() == wxID_CANCEL )
489  return wxEmptyString;
490 
491  pi->FootprintLibDelete( libPath );
492  }
493  }
494 
495  pi->FootprintLibCreate( libPath );
496  }
497  catch( const IO_ERROR& ioe )
498  {
499  DisplayError( this, ioe.What() );
500  return wxEmptyString;
501  }
502 
503  if( doAdd )
504  AddLibrary( libPath );
505 
506  return libPath;
507 }
508 
509 
510 bool PCB_BASE_EDIT_FRAME::AddLibrary( const wxString& aFilename )
511 {
512  wxFileName fn( aFilename );
513 
514  if( aFilename.IsEmpty() )
515  {
516  if( !LibraryFileBrowser( true, fn,
518  true ) )
519  {
520  return false;
521  }
522  }
523 
524  wxString libPath = fn.GetFullPath();
525  wxString libName = fn.GetName();
526 
527  if( libName.IsEmpty() )
528  return false;
529 
530  bool saveInGlobalTable = false;
531  bool saveInProjectTable = false;
532  wxArrayString libTableNames;
533 
534  libTableNames.Add( _( "Global" ) );
535  libTableNames.Add( _( "Project" ) );
536 
537  switch( SelectSingleOption( this, _( "Select Library Table" ),
538  _( "Choose the Library Table to add the library to:" ),
539  libTableNames ) )
540  {
541  case 0: saveInGlobalTable = true; break;
542  case 1: saveInProjectTable = true; break;
543  default: return false;
544  }
545 
546  wxString type = IO_MGR::ShowType( IO_MGR::GuessPluginTypeFromLibPath( libPath ) );
547 
548  // try to use path normalized to an environmental variable or project path
549  wxString normalizedPath = NormalizePath( libPath, &Pgm().GetLocalEnvVariables(), &Prj() );
550 
551  if( normalizedPath.IsEmpty() )
552  normalizedPath = libPath;
553 
554  try
555  {
556  if( saveInGlobalTable )
557  {
558  auto row = new FP_LIB_TABLE_ROW( libName, normalizedPath, type, wxEmptyString );
559  GFootprintTable.InsertRow( row );
561  }
562  else if( saveInProjectTable )
563  {
564  auto row = new FP_LIB_TABLE_ROW( libName, normalizedPath, type, wxEmptyString );
565  Prj().PcbFootprintLibs()->InsertRow( row );
566  Prj().PcbFootprintLibs()->Save( Prj().FootprintLibTblName() );
567  }
568  }
569  catch( const IO_ERROR& ioe )
570  {
571  DisplayError( this, ioe.What() );
572  return false;
573  }
574 
575  auto editor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_PCB_MODULE_EDITOR, false );
576 
577  if( editor )
578  editor->SyncLibraryTree( true );
579 
580  auto viewer = (FOOTPRINT_VIEWER_FRAME*) Kiway().Player( FRAME_PCB_MODULE_VIEWER, false );
581 
582  if( viewer )
583  viewer->ReCreateLibraryList();
584 
585  return true;
586 }
587 
588 
589 bool FOOTPRINT_EDIT_FRAME::DeleteModuleFromLibrary( const LIB_ID& aFPID, bool aConfirm )
590 {
591  if( !aFPID.IsValid() )
592  return false;
593 
594  wxString nickname = aFPID.GetLibNickname();
595  wxString fpname = aFPID.GetLibItemName();
596 
597  // Legacy libraries are readable, but modifying legacy format is not allowed
598  // So prompt the user if he try to delete a footprint from a legacy lib
599  wxString libfullname = Prj().PcbFootprintLibs()->FindRow( nickname )->GetFullURI();
600 
601  if( IO_MGR::GuessPluginTypeFromLibPath( libfullname ) == IO_MGR::LEGACY )
602  {
604  return false;
605  }
606 
607  if( !Prj().PcbFootprintLibs()->IsFootprintLibWritable( nickname ) )
608  {
609  wxString msg = wxString::Format( _( "Library \"%s\" is read only" ), nickname );
610  DisplayError( this, msg );
611  return false;
612  }
613 
614  // Confirmation
615  wxString msg = wxString::Format( FMT_OK_DELETE, fpname.GetData(), nickname.GetData() );
616 
617  if( aConfirm && !IsOK( this, msg ) )
618  return false;
619 
620  try
621  {
622  Prj().PcbFootprintLibs()->FootprintDelete( nickname, fpname );
623  }
624  catch( const IO_ERROR& ioe )
625  {
626  DisplayError( this, ioe.What() );
627  return false;
628  }
629 
630  msg.Printf( FMT_MOD_DELETED, fpname.GetData(), nickname.GetData() );
631 
632  SetStatusText( msg );
633 
634  return true;
635 }
636 
637 
638 void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aStoreInNewLib, const wxString& aLibName,
639  wxString* aLibPath )
640 {
641  if( GetBoard()->m_Modules == NULL )
642  {
643  DisplayInfoMessage( this, _( "No footprints to archive!" ) );
644  return;
645  }
646 
647  wxString footprintName;
648 
649  if( !aStoreInNewLib )
650  {
651  // The footprints are saved in an existing .pretty library in the fp lib table
652  PROJECT& prj = Prj();
653  wxString last_nickname = prj.GetRString( PROJECT::PCB_LIB_NICKNAME );
654  wxString nickname = SelectLibrary( last_nickname );
655 
656  if( !nickname ) // Aborted
657  return;
658 
659  prj.SetRString( PROJECT::PCB_LIB_NICKNAME, nickname );
660 
661  try
662  {
663  FP_LIB_TABLE* tbl = prj.PcbFootprintLibs();
664 
665  for( MODULE* curr_fp = GetBoard()->m_Modules; curr_fp; curr_fp = curr_fp->Next() )
666  {
667  if( !curr_fp->GetFPID().GetLibItemName().empty() ) // Can happen with old boards.
668  tbl->FootprintSave( nickname, curr_fp, false );
669  }
670  }
671  catch( const IO_ERROR& ioe )
672  {
673  DisplayError( this, ioe.What() );
674  }
675  }
676  else
677  {
678  // The footprints are saved in a new .pretty library.
679  // If this library already exists, all previous footprints will be deleted
680  wxString libPath = CreateNewLibrary( aLibName );
681 
682  if( libPath.IsEmpty() ) // Aborted
683  return;
684 
685 
686  if( aLibPath ) *aLibPath = libPath;
687 
689  PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) );
690 
691  for( MODULE* curr_fp = GetBoard()->m_Modules; curr_fp; curr_fp = curr_fp->Next() )
692  {
693  try
694  {
695  if( !curr_fp->GetFPID().GetLibItemName().empty() ) // Can happen with old boards.
696  pi->FootprintSave( libPath, curr_fp );
697  }
698  catch( const IO_ERROR& ioe )
699  {
700  DisplayError( this, ioe.What() );
701  }
702  }
703  }
704 }
705 
706 
708 {
709  wxString libraryName = aModule->GetFPID().GetLibNickname();
710  wxString footprintName = aModule->GetFPID().GetLibItemName();
711  bool nameChanged = m_footprintNameWhenLoaded != footprintName;
712 
713  if( aModule->GetLink() )
714  {
715  if( SaveFootprintToBoard( false ) )
716  {
717  m_footprintNameWhenLoaded = footprintName;
718  return true;
719  }
720  else
721  return false;
722  }
723  else if( libraryName.IsEmpty() || footprintName.IsEmpty() )
724  {
725  if( SaveFootprintAs( aModule ) )
726  {
727  m_footprintNameWhenLoaded = footprintName;
728  SyncLibraryTree( true );
729  return true;
730  }
731  else
732  return false;
733  }
734 
735  FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs();
736 
737  // Legacy libraries are readable, but modifying legacy format is not allowed
738  // So prompt the user if he try to add/replace a footprint in a legacy lib
739  wxString libfullname = tbl->FindRow( libraryName )->GetFullURI();
740 
741  if( IO_MGR::GuessPluginTypeFromLibPath( libfullname ) == IO_MGR::LEGACY )
742  {
744  return false;
745  }
746 
747  if( nameChanged )
748  {
749  LIB_ID oldFPID( libraryName, m_footprintNameWhenLoaded );
750  DeleteModuleFromLibrary( oldFPID, false );
751  }
752 
753  if( !saveFootprintInLibrary( aModule, libraryName ) )
754  return false;
755 
756  if( nameChanged )
757  {
758  m_footprintNameWhenLoaded = footprintName;
759  SyncLibraryTree( true );
760  }
761 
762  return true;
763 }
764 
765 
766 bool FOOTPRINT_EDIT_FRAME::saveFootprintInLibrary( MODULE* aModule, const wxString& aLibraryName )
767 {
768  try
769  {
770  aModule->SetFPID( LIB_ID( wxEmptyString, aModule->GetFPID().GetLibItemName() ) );
771 
772  Prj().PcbFootprintLibs()->FootprintSave( aLibraryName, aModule );
773 
774  aModule->SetFPID( LIB_ID( aLibraryName, aModule->GetFPID().GetLibItemName() ) );
775  return true;
776  }
777  catch( const IO_ERROR& ioe )
778  {
779  DisplayError( this, ioe.What() );
780 
781  aModule->SetFPID( LIB_ID( aLibraryName, aModule->GetFPID().GetLibItemName() ) );
782  return false;
783  }
784 }
785 
786 
788 {
789  // update module in the current board,
790  // not just add it to the board with total disregard for the netlist...
791  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB, false );
792 
793  if( pcbframe == NULL ) // happens when the board editor is not active (or closed)
794  {
795  DisplayErrorMessage( this, _("No board currently open." ) );
796  return false;
797  }
798 
799  BOARD* mainpcb = pcbframe->GetBoard();
800  MODULE* source_module = NULL;
801  MODULE* module_in_edit = GetBoard()->m_Modules;
802 
803  // Search the old module (source) if exists
804  // Because this source could be deleted when editing the main board...
805  if( module_in_edit->GetLink() ) // this is not a new module ...
806  {
807  source_module = mainpcb->m_Modules;
808 
809  for( ; source_module != NULL; source_module = source_module->Next() )
810  {
811  if( module_in_edit->GetLink() == source_module->GetTimeStamp() )
812  break;
813  }
814  }
815 
816  if( !aAddNew && source_module == NULL ) // source not found
817  {
818  DisplayError( this, _( "Unable to find the footprint on the main board.\nCannot save." ) );
819  return false;
820  }
821 
822  if( aAddNew && source_module != NULL )
823  {
824  DisplayError( this, _( "Footprint already exists on board." ) );
825  return false;
826  }
827 
830  BOARD_COMMIT commit( pcbframe );
831 
832  // Create the "new" module
833  MODULE* newmodule = new MODULE( *module_in_edit );
834  newmodule->SetParent( mainpcb );
835  newmodule->SetLink( 0 );
836 
837  if( source_module ) // this is an update command
838  {
839  // In the main board,
840  // the new module replace the old module (pos, orient, ref, value
841  // and connexions are kept)
842  // and the source_module (old module) is deleted
843  pcbframe->Exchange_Module( source_module, newmodule, commit );
844  newmodule->SetTimeStamp( module_in_edit->GetLink() );
845  commit.Push( wxT( "Update module" ) );
846  }
847  else // This is an insert command
848  {
849  wxPoint cursor_pos = pcbframe->GetCrossHairPosition();
850 
851  commit.Add( newmodule );
852  pcbframe->SetCrossHairPosition( wxPoint( 0, 0 ) );
853  pcbframe->PlaceModule( newmodule, NULL );
854  newmodule->SetPosition( wxPoint( 0, 0 ) );
855  pcbframe->SetCrossHairPosition( cursor_pos );
856  newmodule->SetTimeStamp( GetNewTimeStamp() );
857  commit.Push( wxT( "Insert module" ) );
858  }
859 
860  newmodule->ClearFlags();
861  pcbframe->SetCurItem( NULL );
862  // @todo LEGACY should be unnecessary
863  mainpcb->m_Status_Pcb = 0;
864 
865  return true;
866 }
867 
868 
870 {
871  if( aModule == NULL )
872  return false;
873 
874  FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs();
875 
876  SetMsgPanel( aModule );
877 
878  wxString libraryName = aModule->GetFPID().GetLibNickname();
879  wxString footprintName = aModule->GetFPID().GetLibItemName();
880  bool updateValue = ( aModule->GetValue() == footprintName );
881 
882  wxArrayString headers;
883  std::vector<wxArrayString> itemsToDisplay;
884  std::vector<wxString> nicknames = tbl->GetLogicalLibs();
885 
886  headers.Add( _( "Nickname" ) );
887  headers.Add( _( "Description" ) );
888 
889  for( unsigned i = 0; i < nicknames.size(); i++ )
890  {
891  wxArrayString item;
892  item.Add( nicknames[i] );
893  item.Add( tbl->GetDescription( nicknames[i] ) );
894  itemsToDisplay.push_back( item );
895  }
896 
897  EDA_LIST_DIALOG dlg( this, FMT_SAVE_MODULE, headers, itemsToDisplay, libraryName,
898  nullptr, nullptr, /* sort */ false, /* show headers */ false );
899  dlg.SetListLabel( _( "Save in library:" ) );
900  dlg.SetOKLabel( _( "Save" ) );
901 
902  wxBoxSizer* bNameSizer = new wxBoxSizer( wxHORIZONTAL );
903 
904  wxStaticText* label = new wxStaticText( &dlg, wxID_ANY, _( "Name:" ),
905  wxDefaultPosition, wxDefaultSize, 0 );
906  bNameSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 );
907 
908  wxTextCtrl* nameTextCtrl = new wxTextCtrl( &dlg, wxID_ANY, footprintName,
909  wxDefaultPosition, wxDefaultSize, 0 );
910  bNameSizer->Add( nameTextCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
911 
912  wxTextValidator nameValidator( wxFILTER_EXCLUDE_CHAR_LIST );
913  nameValidator.SetCharExcludes( MODULE::StringLibNameInvalidChars( false ) );
914  nameTextCtrl->SetValidator( nameValidator );
915 
916  wxSizer* mainSizer = dlg.GetSizer();
917  mainSizer->Prepend( bNameSizer, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5 );
918 
919  // Move nameTextCtrl to the head of the tab-order
920  if( dlg.GetChildren().DeleteObject( nameTextCtrl ) )
921  dlg.GetChildren().Insert( nameTextCtrl );
922 
923  dlg.SetInitialFocus( nameTextCtrl );
924 
925  dlg.Layout();
926  mainSizer->Fit( &dlg );
927 
928  if( dlg.ShowModal() != wxID_OK )
929  return false; // canceled by user
930 
931  libraryName = dlg.GetTextSelection();
932 
933  if( libraryName.IsEmpty() )
934  {
935  DisplayError( NULL, _( "No library specified. Footprint could not be saved." ) );
936  return false;
937  }
938 
939  footprintName = nameTextCtrl->GetValue();
940  footprintName.Trim( true );
941  footprintName.Trim( false );
942 
943  if( footprintName.IsEmpty() )
944  {
945  DisplayError( NULL, _( "No footprint name specified. Footprint could not be saved." ) );
946  return false;
947  }
948 
949  aModule->SetFPID( LIB_ID( libraryName, footprintName ) );
950 
951  if( updateValue )
952  aModule->SetValue( footprintName );
953 
954  // Legacy libraries are readable, but modifying legacy format is not allowed
955  // So prompt the user if he try to add/replace a footprint in a legacy lib
956  wxString libfullname = Prj().PcbFootprintLibs()->FindRow( libraryName )->GetFullURI();
958 
959  if( piType == IO_MGR::LEGACY )
960  {
962  return false;
963  }
964 
965  bool module_exists = tbl->FootprintExists( libraryName, footprintName );
966 
967  if( module_exists )
968  {
969  wxString msg = wxString::Format( _( "Footprint %s already exists in %s." ),
970  footprintName,
971  libraryName );
972  KIDIALOG chkdlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
973  chkdlg.SetOKLabel( _( "Overwrite" ) );
974 
975  if( chkdlg.ShowModal() == wxID_CANCEL )
976  return false;
977  }
978 
979  if( !saveFootprintInLibrary( aModule, libraryName ) )
980  return false;
981 
982  // Once saved-as a board footprint is no longer a board footprint
983  aModule->SetLink( 0 );
984 
985  wxString fmt = module_exists ? _( "Component \"%s\" replaced in \"%s\"" ) :
986  _( "Component \"%s\" added in \"%s\"" );
987 
988  wxString msg = wxString::Format( fmt, footprintName.GetData(), libraryName.GetData() );
989  SetStatusText( msg );
990  updateTitle();
991 
992  return true;
993 }
994 
995 
997 {
998  if( GetScreen()->IsModify() && m_revertModule )
999  {
1000  wxString msg = wxString::Format( _( "Revert \"%s\" to last version saved?" ),
1001  GetChars( GetLoadedFPID().GetLibItemName() ) );
1002 
1003  if( ConfirmRevertDialog( this, msg ) )
1004  {
1005  Clear_Pcb( false );
1006  AddModuleToBoard( (MODULE*) m_revertModule->Clone() );
1007 
1008  Zoom_Automatique( false );
1009 
1010  Update3DView();
1011 
1013  GetScreen()->ClrModify();
1014 
1015  updateView();
1016  m_canvas->Refresh();
1017 
1018  return true;
1019  }
1020  }
1021 
1022  return false;
1023 }
1024 
1025 
1026 MODULE* PCB_BASE_FRAME::CreateNewModule( const wxString& aModuleName )
1027 {
1028  // Creates a new footprint at position 0,0 which contains the minimal items:
1029  // the reference and the value.
1030  // Value : initialized to the footprint name.
1031  // put on fab layer (front side)
1032  // Reference : initialized to a default value (REF**).
1033  // put on silkscreen layer (front side)
1034 
1035  wxString moduleName = aModuleName;
1036 
1037  // Ask for the new module name
1038  if( moduleName.IsEmpty() )
1039  {
1040  WX_TEXT_ENTRY_DIALOG dlg( this, FMT_MOD_REF, FMT_MOD_CREATE, moduleName );
1041  dlg.SetTextValidator( FILE_NAME_CHAR_VALIDATOR( &moduleName ) );
1042 
1043  if( dlg.ShowModal() != wxID_OK )
1044  return NULL; //Aborted by user
1045  }
1046 
1047  moduleName.Trim( true );
1048  moduleName.Trim( false );
1049 
1050  if( moduleName.IsEmpty() )
1051  {
1053  return NULL;
1054  }
1055 
1056  // Creates the new module and add it to the head of the linked list of modules
1057  MODULE* module = new MODULE( GetBoard() );
1058 
1059  // Update parameters: timestamp ...
1060  module->SetLastEditTime();
1061 
1062  // Update its name in lib
1063  module->SetFPID( LIB_ID( wxEmptyString, moduleName ) );
1064 
1065  wxPoint default_pos;
1067 
1068  // Update reference:
1069  if( settings.m_RefDefaultText.IsEmpty() )
1070  module->SetReference( moduleName );
1071  else
1072  module->SetReference( settings.m_RefDefaultText );
1073 
1074  PCB_LAYER_ID layer = ToLAYER_ID( settings.m_RefDefaultlayer );
1075  module->Reference().SetThickness( settings.GetTextThickness( layer ) );
1076  module->Reference().SetTextSize( settings.GetTextSize( layer ) );
1077  module->Reference().SetItalic( settings.GetTextItalic( layer ) );
1078  module->Reference().SetKeepUpright( settings.GetTextUpright( layer ) );
1079  default_pos.y = GetDesignSettings().GetTextSize( layer ).y / 2;
1080  module->Reference().SetPosition( default_pos );
1081  module->Reference().SetLayer( layer );
1082  module->Reference().SetVisible( settings.m_RefDefaultVisibility );
1083 
1084  // Set the value field to a default value
1085  if( settings.m_ValueDefaultText.IsEmpty() )
1086  module->SetValue( moduleName );
1087  else
1088  module->SetValue( settings.m_ValueDefaultText );
1089 
1090  layer = ToLAYER_ID( settings.m_ValueDefaultlayer );
1091  module->Value().SetThickness( settings.GetTextThickness( layer ) );
1092  module->Value().SetTextSize( settings.GetTextSize( layer ) );
1093  module->Value().SetItalic( settings.GetTextItalic( layer ) );
1094  module->Value().SetKeepUpright( settings.GetTextUpright( layer ) );
1095  default_pos.y = -default_pos.y;
1096  module->Value().SetPosition( default_pos );
1097  module->Value().SetLayer( layer );
1098  module->Value().SetVisible( settings.m_ValueDefaultVisibility );
1099 
1100  SetMsgPanel( module );
1101  return module;
1102 }
1103 
1104 
1105 wxString PCB_BASE_FRAME::SelectLibrary( const wxString& aNicknameExisting )
1106 {
1107  wxArrayString headers;
1108 
1109  headers.Add( _( "Nickname" ) );
1110  headers.Add( _( "Description" ) );
1111 
1112  FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs();
1113 
1114  std::vector< wxArrayString > itemsToDisplay;
1115  std::vector< wxString > nicknames = fptbl->GetLogicalLibs();
1116 
1117  for( unsigned i = 0; i < nicknames.size(); i++ )
1118  {
1119  wxArrayString item;
1120 
1121  item.Add( nicknames[i] );
1122  item.Add( fptbl->GetDescription( nicknames[i] ) );
1123 
1124  itemsToDisplay.push_back( item );
1125  }
1126 
1127  EDA_LIST_DIALOG dlg( this, FMT_SELECT_LIB, headers, itemsToDisplay, aNicknameExisting );
1128 
1129  if( dlg.ShowModal() != wxID_OK )
1130  return wxEmptyString;
1131 
1132  wxString nickname = dlg.GetTextSelection();
1133 
1134  wxLogDebug( wxT( "Chose footprint library \"%s\"." ), GetChars( nickname ) );
1135 
1136  return nickname;
1137 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
timestamp_t GetLink() const
Definition: class_module.h:577
TOOL_MANAGER * m_toolManager
Definition: draw_frame.h:125
bool IsValid() const
Definition: lib_id.h:171
wxString m_RefDefaultText
Default ref text on fp creation.
void BuildListOfNets()
Definition: class_board.h:729
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&#39;t be accessed.
bool m_ValueDefaultVisibility
Default value text visibility on fp creation.
void SetKeepUpright(bool aKeepUpright)
TEXTE_MODULE & Reference()
Definition: class_module.h:513
void DoNotShowCheckbox(wxString file, int line)
Shows the &#39;do not show again&#39; checkbox
Definition: confirm.cpp:60
bool ConfirmRevertDialog(wxWindow *parent, const wxString &aMessage)
Function ConfirmRevertDialog displays a confirmation for a revert action.
Definition: confirm.cpp:200
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_player.h:60
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:156
Class PCB_IO is a PLUGIN derivation for saving and loading Pcbnew s-expression formatted files...
wxString m_mruPath
Most recently used path.
Class PROJECT holds project specific data.
Definition: project.h:57
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:53
bool GetTextItalic(PCB_LAYER_ID aLayer) const
char * StrPurge(char *text)
Function StrPurge removes leading and training spaces, tabs and end of line chars in text return a po...
Definition: string.cpp:271
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Function DisplayErrorMessage displays an error message with aMessage.
Definition: confirm.cpp:259
BOARD_DESIGN_SETTINGS & GetDesignSettings() const override
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame...
This file is part of the common library TODO brief description.
Helper class to create more flexible dialogs, including &#39;do not show again&#39; checkbox handling...
Definition: confirm.h:44
Class 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:126
COMMIT & Add(EDA_ITEM *aItem)
Adds a new item to the model
Definition: commit.h:78
Class BOARD to handle a board.
void SetItalic(bool isItalic)
Definition: eda_text.h:182
#define EXPORT_IMPORT_LASTPATH_KEY
virtual void FootprintSave(const wxString &aLibraryPath, const MODULE *aFootprint, const PROPERTIES *aProperties=NULL)
Function FootprintSave will write aModule to an existing library located at aLibraryPath.
Definition: plugin.cpp:93
Component library viewer main window.
void SetTextValidator(wxTextValidatorStyle style)
MODULE * Next() const
Definition: class_module.h:123
void SetVisible(bool aVisible)
Definition: eda_text.h:188
void SetCurItem(BOARD_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
BOARD * GetBoard() const
const wxString & GetValue() const
Function GetValue.
Definition: class_module.h:497
class EDA_LIST_DIALOG
bool saveFootprintInLibrary(MODULE *aModule, const wxString &aLibraryName)
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
#define FMT_SELECT_LIB
int m_ValueDefaultlayer
Default value text layer on fp creation.
int GetTextThickness(PCB_LAYER_ID aLayer) const
Function GetTextThickness Returns the default text thickness from the layer class for the given layer...
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:227
static const wxChar * StringLibNameInvalidChars(bool aUserReadable)
static function StringLibNameInvalidChars Test for validity of the name in a library of the footprint...
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
MODULE * CreateNewModule(const wxString &aModuleName)
Function CreateNewModule Creates a new module or footprint, at position 0,0 The new module contains o...
Definition of class FOOTPRINT_EDIT_FRAME.
wxSize GetTextSize(PCB_LAYER_ID aLayer) const
Function GetTextSize Returns the default text size from the layer class for the given layer...
#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.
Class WHITESPACE_FILTER_READER reads lines of text from another LINE_READER, but only returns non-com...
Definition: filter_reader.h:71
Geda PCB file formats.
Definition: io_mgr.h:58
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"))
static PCB_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath)
Function GuessPluginTypeFromLibPath returns a plugin type given a footprint library&#39;s libPath...
Definition: io_mgr.cpp:124
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...
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
FP_LIB_TABLE GFootprintTable
The global footprint library table.
Definition: pcbnew.cpp:333
This file contains miscellaneous commonly used macros and functions.
Class FILE_NAME_CHAR_VALIDATOR.
Definition: validators.h:63
virtual bool IsFootprintLibWritable(const wxString &aLibraryPath)
Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable.
Definition: plugin.cpp:124
BOARD_ITEM * Next() const
Class RELEASER releases a PLUGIN in the context of a potential thrown exception, through its destruct...
Definition: io_mgr.h:563
const LIB_ID & GetFPID() const
Definition: class_module.h:193
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
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...
std::unique_ptr< MODULE > m_revertModule
timestamp_t GetNewTimeStamp()
Definition: common.cpp:212
#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:94
Class FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
#define FMT_MOD_NOT_FOUND
virtual MODULE * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL)
Function FootprintLoad loads a footprint having aFootprintName from the aLibraryPath containing a lib...
Definition: plugin.cpp:84
#define FMT_OK_DELETE
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:300
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
void SetLink(timestamp_t aLink)
Definition: class_module.h:578
std::string GetStringOutput(bool doClear)
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:216
void PlaceModule(MODULE *aModule, wxDC *aDC, bool aRecreateRatsnest=true)
Function PlaceModule places aModule at the current cursor position and updates module coordinates wit...
virtual bool FootprintLibDelete(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Function FootprintLibDelete deletes an existing footprint library and returns true, or if library does not exist returns false, or throws an exception if library exists but is read only or cannot be deleted for some other reason.
Definition: plugin.cpp:116
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:512
const wxString GetDescription(const wxString &aNickname)
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
void SetLastEditTime(timestamp_t aTime)
Definition: class_module.h:314
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
LIB_ID GetLoadedFPID() const
Return the LIB_ID of the part being edited.
wxString ModLegacyExportFileWildcard()
The common library.
Helper dialog and control classes.
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use...
Definition: draw_frame.h:911
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
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 SetReference(const wxString &aReference)
Function SetReference.
Definition: class_module.h:473
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
#define FMT_FILE_NOT_FOUND
void SetPosition(const wxPoint &aPos) override
wxString m_ValueDefaultText
Default value text on fp creation.
#define FMT_EXPORT_MODULE
void Format(BOARD_ITEM *aItem, int aNestLevel=0) const
Function Format outputs aItem to aFormatter in s-expression format.
bool LibraryFileBrowser(bool doOpen, wxFileName &aFilename, const wxString &wildcard, const wxString &ext, bool isDirectory)
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
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:171
VTBL_ENTRY FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
bool GetTextUpright(PCB_LAYER_ID aLayer) const
bool SaveFootprintAs(MODULE *aModule)
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:123
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 ...
TOOL_MANAGER * GetToolManager() const
Return the tool manager instance, if any.
Definition: draw_frame.h:924
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:186
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
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:92
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:54
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:
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
#define FMT_IMPORT_MODULE
DLIST< MODULE > m_Modules
Definition: class_board.h:248
static PLUGIN * PluginFind(PCB_FILE_T aFileType)
Function PluginFind returns a PLUGIN which the caller can use to import, export, save, or load design documents.
Definition: io_mgr.cpp:58
size_t i
Definition: json11.cpp:597
void updateView()
Reloads displayed items and sets view.
bool SaveFootprint(MODULE *aModule)
Save in an existing library a given footprint.
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
void ClrModify()
Definition: base_screen.h:325
void SetValue(const wxString &aValue)
Function SetValue.
Definition: class_module.h:506
#define FMT_EXPORTED
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.
virtual void FootprintLibCreate(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Function FootprintLibCreate creates a new empty footprint library at aLibraryPath empty...
Definition: plugin.cpp:109
int ShowModal() override
Definition: confirm.cpp:102
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:257
wxString SelectLibrary(const wxString &aNicknameExisting)
Function SelectLibrary puts up a dialog and allows the user to pick a library, for unspecified use...
void AddModuleToBoard(MODULE *module) override
Override from PCB_BASE_EDIT_FRAME which adds a module to the editor&#39;s dummy board, NOT to the user&#39;s PCB.
Module description (excepted pads)
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
void SetCrossHairPosition(const wxPoint &aPosition, bool aSnapToGrid=true)
Set the screen cross hair position to aPosition in logical (drawing) units.
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:304
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:52
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Function DisplayInfoMessage displays an informational message box with aMessage.
Definition: confirm.cpp:277
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:245
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Return the current cross hair position in logical (drawing) coordinates.
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)
Function IsOK displays a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:295
const std::string KiCadFootprintLibPathExtension
bool m_RefDefaultVisibility
Default ref text visibility on fp creation.
void SetFPID(const LIB_ID &aFPID)
Definition: class_module.h:194
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:810
wxString KiCadFootprintLibFileWildcard()
Custom text control validator definitions.
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:67
bool FootprintExists(const wxString &aNickname, const wxString &aFootprintName)
Function FootprintExists.
static wxString GetGlobalTableFileName()
Function GetGlobalTableFileName.
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:161
timestamp_t GetTimeStamp() const
Definition: base_struct.h:207
bool Update3DView(const wxString *aTitle=nullptr)
Update the 3D view, if the viewer is opened by this frame.
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...
void Exchange_Module(MODULE *aSrc, MODULE *aDest, BOARD_COMMIT &aCommit, bool deleteExtraTexts=true, bool resetTextLayers=true, bool resetTextEffects=true)
Function Exchange_Module Replaces OldModule by NewModule, using OldModule settings: position...
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:206
S-expression Pcbnew file format.
Definition: io_mgr.h:55
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
int m_Status_Pcb
Flags used in ratsnest calculation and update.
Definition: class_board.h:240
void SetListLabel(const wxString &aLabel)
Definition: displlst.cpp:120