KiCad PCB EDA Suite
librairi.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-2017 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 <wxPcbStruct.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 
46 #include <class_board.h>
47 #include <class_module.h>
48 
49 #include <pcbnew.h>
50 #include <module_editor_frame.h>
52 #include <kicad_plugin.h>
53 #include <legacy_plugin.h>
54 
56 
57 
58 // unique, "file local" translations:
59 
60 #define FMT_OK_OVERWRITE _( "Library '%s' exists, OK to replace ?" )
61 #define FMT_CREATE_LIB _( "Create New Library Folder (the .pretty folder is the library)" )
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_BAD_PATH _( "Unable to find or load footprint from path '%s'" )
68 #define FMT_BAD_PATHS _( "The footprint library '%s' could not be found in any of the search paths." )
69 #define FMT_LIB_READ_ONLY _( "Library '%s' is read only, not writable" )
70 
71 #define FMT_EXPORT_MODULE _( "Export Footprint" )
72 #define FMT_SAVE_MODULE _( "Save Footprint" )
73 #define FMT_MOD_REF _( "Enter footprint name:" )
74 #define FMT_EXPORTED _( "Footprint exported to file '%s'" )
75 #define FMT_MOD_DELETED _( "Footprint %s deleted from library '%s'" )
76 #define FMT_MOD_CREATE _( "New Footprint" )
77 
78 #define FMT_MOD_EXISTS _( "Footprint %s already exists in library '%s'" )
79 #define FMT_NO_REF_ABORTED _( "No footprint name defined." )
80 #define FMT_SELECT_LIB _( "Select Library" )
81 
82 static const wxString INFO_LEGACY_LIB_WARN_EDIT(
83  _( "Writing/modifying legacy libraries (.mod files) is not allowed\n"\
84  "Please save the current library to the new .pretty format\n"\
85  "and update your footprint lib table\n"\
86  "to save your footprint (a .kicad_mod file) in the .pretty library folder" ) );
87 
88 static const wxString INFO_LEGACY_LIB_WARN_DELETE(
89  _( "Modifying legacy libraries (.mod files) is not allowed\n"\
90  "Please save the current library under the new .pretty format\n"\
91  "and update your footprint lib table\n"\
92  "before deleting a footprint" ) );
93 
94 static const wxString ModLegacyExportFileWildcard( _( "Legacy foot print export files (*.emp)|*.emp" ) );
95 static const wxString ModImportFileWildcard( _( "GPcb foot print files (*)|*" ) );
96 
97 
98 #define EXPORT_IMPORT_LASTPATH_KEY wxT( "import_last_path" )
99 
100 
106 static wxFileName prompt_for_module( wxWindow* aParent, const wxString& aLastPath )
107 {
108  static int lastFilterIndex = 0;
109  wxString wildCard;
110 
111  wildCard << wxGetTranslation( KiCadFootprintLibFileWildcard ) << wxChar( '|' )
112  << wxGetTranslation( ModLegacyExportFileWildcard ) << wxChar( '|' )
113  << wxGetTranslation( ModImportFileWildcard ) << wxChar( '|' )
114  << wxGetTranslation( GedaPcbFootprintLibFileWildcard );
115 
116  wxFileDialog dlg( aParent, FMT_IMPORT_MODULE, aLastPath, wxEmptyString, wildCard,
117  wxFD_OPEN | wxFD_FILE_MUST_EXIST );
118 
119  dlg.SetFilterIndex( lastFilterIndex );
120 
121  if( dlg.ShowModal() == wxID_CANCEL )
122  return wxFileName();
123 
124  lastFilterIndex = dlg.GetFilterIndex();
125 
126  return wxFileName( dlg.GetPath() );
127 }
128 
129 
136 static IO_MGR::PCB_FILE_T detect_file_type( FILE* aFile, const wxFileName& aFileName, wxString* aName )
137 {
138  FILE_LINE_READER freader( aFile, aFileName.GetFullPath() );
139  WHITESPACE_FILTER_READER reader( freader );
140  IO_MGR::PCB_FILE_T file_type;
141 
142  wxASSERT( aName );
143 
144  reader.ReadLine();
145  char* line = reader.Line();
146 
147  if( !strncasecmp( line, "(module", strlen( "(module" ) ) )
148  {
149  file_type = IO_MGR::KICAD;
150  *aName = aFileName.GetName();
151  }
152  else if( !strncasecmp( line, FOOTPRINT_LIBRARY_HEADER, FOOTPRINT_LIBRARY_HEADER_CNT ) )
153  {
154  file_type = IO_MGR::LEGACY;
155  while( reader.ReadLine() )
156  {
157  if( !strncasecmp( line, "$MODULE", strlen( "$MODULE" ) ) )
158  {
159  *aName = FROM_UTF8( StrPurge( line + strlen( "$MODULE" ) ) );
160  break;
161  }
162  }
163  }
164  else if( !strncasecmp( line, "Element", strlen( "Element" ) ) )
165  {
166  file_type = IO_MGR::GEDA_PCB;
167  *aName = aFileName.GetName();
168  }
169  else
170  {
171  file_type = IO_MGR::FILE_TYPE_NONE;
172  }
173 
174  return file_type;
175 }
176 
177 
185  const wxFileName& aFileName, IO_MGR::PCB_FILE_T aFileType,
186  const wxString& aName )
187 {
188  wxString path;
189 
190  switch( aFileType )
191  {
192  case IO_MGR::GEDA_PCB:
193  path = aFileName.GetPath();
194  break;
195  case IO_MGR::LEGACY:
196  path = aFileName.GetFullPath();
197  break;
198  default:
199  wxFAIL_MSG( wxT( "unexpected IO_MGR::PCB_FILE_T" ) );
200  }
201 
202  PLUGIN::RELEASER pi( IO_MGR::PluginFind( aFileType ) );
203 
204  return pi->FootprintLoad( path, aName );
205 }
206 
207 
212 static MODULE* parse_module_kicad( const wxFileName& aFileName )
213 {
214  wxString fcontents;
215  PCB_IO pcb_io;
216  wxFFile f( aFileName.GetFullPath() );
217 
218  if( !f.IsOpened() )
219  return NULL;
220 
221  f.ReadAll( &fcontents );
222 
223  return dynamic_cast<MODULE*>( pcb_io.Parse( fcontents ) );
224 }
225 
226 
233 MODULE* try_load_footprint( const wxFileName& aFileName, IO_MGR::PCB_FILE_T aFileType,
234  const wxString& aName )
235 {
236  MODULE* module;
237 
238  switch( aFileType )
239  {
240  case IO_MGR::GEDA_PCB:
241  case IO_MGR::LEGACY:
242  module = parse_module_with_plugin( aFileName, aFileType, aName );
243  break;
244 
245  case IO_MGR::KICAD:
246  module = parse_module_kicad( aFileName );
247  break;
248 
249  default:
250  wxFAIL_MSG( wxT( "unexpected IO_MGR::PCB_FILE_T" ) );
251  module = NULL;
252  }
253 
254  return module;
255 }
256 
257 
259 {
260  wxString lastOpenedPathForLoading = m_mruPath;
261  wxConfigBase* config = Kiface().KifaceSettings();
262 
263  if( config )
264  config->Read( EXPORT_IMPORT_LASTPATH_KEY, &lastOpenedPathForLoading );
265 
266  wxFileName fn = prompt_for_module( 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( config ) // Save file path
281  {
282  lastOpenedPathForLoading = fn.GetPath();
283  config->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;
296  wxString errMessage;
297 
298  try
299  {
300  module = try_load_footprint( fn, fileType, moduleName );
301 
302  if( !module )
303  {
304  wxString msg = wxString::Format(
305  FMT_MOD_NOT_FOUND, GetChars( moduleName ), GetChars( fn.GetFullPath() ) );
306  DisplayError( this, msg );
307  return NULL;
308  }
309  }
310  catch( const IO_ERROR& ioe )
311  {
312  DisplayError( this, ioe.What() );
313  return NULL;
314  }
315 
316  // Insert footprint in list
317  GetBoard()->Add( module );
318 
319  // Display info :
320  SetMsgPanel( module );
321  PlaceModule( module, NULL );
322 
323  if( IsGalCanvasActive() )
324  module->SetPosition( wxPoint( 0, 0 ) );
325 
326  GetBoard()->m_Status_Pcb = 0;
328  updateView();
329 
330  return module;
331 }
332 
333 
335 {
336  wxFileName fn;
337  wxConfigBase* config = Kiface().KifaceSettings();
338 
339  if( !aModule )
340  return;
341 
342  fn.SetName( FROM_UTF8( aModule->GetFPID().GetLibItemName() ) );
343 
344  wxString wildcard = wxGetTranslation( KiCadFootprintLibFileWildcard );
345 
346  fn.SetExt( KiCadFootprintFileExtension );
347 
348  if( config )
349  {
350  wxString path;
351  config->Read( EXPORT_IMPORT_LASTPATH_KEY, &path, m_mruPath );
352  fn.SetPath( path );
353  }
354 
355  wxFileDialog dlg( this, FMT_EXPORT_MODULE, fn.GetPath(), fn.GetFullName(),
356  wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
357 
358  if( dlg.ShowModal() == wxID_CANCEL )
359  return;
360 
361  fn = dlg.GetPath();
362 
363  if( config ) // Save file path
364  {
365  config->Write( EXPORT_IMPORT_LASTPATH_KEY, fn.GetPath() );
366  }
367 
368  try
369  {
370  // Export as *.kicad_pcb format, using a strategy which is specifically chosen
371  // as an example on how it could also be used to send it to the system clipboard.
372 
373  PCB_IO pcb_io( CTL_FOR_LIBRARY );
374 
375  /* This module should *already* be "normalized" in a way such that
376  orientation is zero, etc., since it came from module editor.
377 
378  module->SetTimeStamp( 0 );
379  module->SetParent( 0 );
380  module->SetOrientation( 0 );
381  */
382 
383  pcb_io.Format( aModule );
384 
385  FILE* fp = wxFopen( dlg.GetPath(), wxT( "wt" ) );
386 
387  if( fp == NULL )
388  {
389  wxMessageBox( wxString::Format(
390  _( "Unable to create or write file '%s'" ),
391  GetChars( dlg.GetPath() ) ) );
392  return;
393  }
394 
395  fprintf( fp, "%s", pcb_io.GetStringOutput( false ).c_str() );
396  fclose( fp );
397  }
398  catch( const IO_ERROR& ioe )
399  {
400  DisplayError( this, ioe.What() );
401  return;
402  }
403 
404  wxString msg = wxString::Format( FMT_EXPORTED, GetChars( dlg.GetPath() ) );
405  DisplayInfoMessage( this, msg );
406 }
407 
408 bool FOOTPRINT_EDIT_FRAME::SaveCurrentModule( const wxString* aLibPath )
409 {
410  wxString libPath = aLibPath ? *aLibPath : getLibPath();
411 
413 
414  // Legacy libraries are readable, but writing legacy format is not allowed
415  if( piType == IO_MGR::LEGACY )
416  {
418  return false;
419  }
420 
421  try
422  {
423  PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) );
424 
425  pi->FootprintSave( libPath, GetBoard()->m_Modules );
426  }
427  catch( const IO_ERROR& ioe )
428  {
429  DisplayError( this, ioe.What() );
430  return false;
431  }
432  return true;
433 }
434 
436 {
437  // Kicad cannot write legacy format libraries, only .pretty new format
438  // because the legacy format cannot handle current features.
439  // The footprint library is actually a directory
440 
441  // prompt user for footprint library name, ending by ".pretty"
442  // Because there are constraints for the directory name to create,
443  // (the name should have the extension ".pretty", and the folder cannot be inside
444  // a footprint library), we do not use the standard wxDirDialog.
445 
446  wxString initialPath = wxPathOnly( Prj().GetProjectFullName() );
447  DIALOG_SELECT_PRETTY_LIB dlg( this, initialPath );
448 
449  if( dlg.ShowModal() != wxID_OK )
450  return wxEmptyString;
451 
452  wxString libPath = dlg.GetFullPrettyLibName();
453 
454  // We can save fp libs only using IO_MGR::KICAD format (.pretty libraries)
456 
457  try
458  {
459  PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) );
460 
461  bool writable = false;
462  bool exists = false;
463 
464  try
465  {
466  writable = pi->IsFootprintLibWritable( libPath );
467  exists = true; // no exception was thrown, lib must exist.
468  }
469  catch( const IO_ERROR& )
470  {
471  // ignore, original values of 'writable' and 'exists' are accurate.
472  }
473 
474  if( exists )
475  {
476  if( !writable )
477  {
478  wxString msg = wxString::Format( FMT_LIB_READ_ONLY, GetChars( libPath ) );
479  DisplayError( this, msg );
480  return wxEmptyString;
481  }
482  else
483  {
484  wxString msg = wxString::Format( FMT_OK_OVERWRITE, GetChars( libPath ) );
485 
486  if( !IsOK( this, msg ) )
487  return wxEmptyString;
488 
489  pi->FootprintLibDelete( libPath );
490  }
491  }
492 
493  pi->FootprintLibCreate( libPath );
494  }
495  catch( const IO_ERROR& ioe )
496  {
497  DisplayError( this, ioe.What() );
498  return wxEmptyString;
499  }
500 
501  return libPath;
502 }
503 
504 
506 {
507  wxString nickname = GetCurrentLib();
508 
509  // Legacy libraries are readable, but modifying legacy format is not allowed
510  // So prompt the user if he try to delete a footprint from a legacy lib
511  wxString libfullname = Prj().PcbFootprintLibs()->FindRow(nickname)->GetFullURI();
513 
514  if( piType == IO_MGR::LEGACY )
515  {
517  return false;
518  }
519 
520  if( !Prj().PcbFootprintLibs()->IsFootprintLibWritable( nickname ) )
521  {
522  wxString msg = wxString::Format(
523  _( "Library '%s' is read only" ),
524  GetChars( nickname )
525  );
526 
527  DisplayError( this, msg );
528  return false;
529  }
530 
531  wxString fpid_txt = PCB_BASE_FRAME::SelectFootprint( this, nickname,
532  wxEmptyString, wxEmptyString, Prj().PcbFootprintLibs() );
533 
534  if( !fpid_txt )
535  return false;
536 
537  LIB_ID fpid( fpid_txt );
538  wxString fpname = FROM_UTF8( fpid.GetLibItemName() );
539 
540  // Confirmation
541  wxString msg = wxString::Format( FMT_OK_DELETE, fpname.GetData(), nickname.GetData() );
542 
543  if( !IsOK( this, msg ) )
544  return false;
545 
546  try
547  {
548  Prj().PcbFootprintLibs()->FootprintDelete( nickname, fpname );
549  }
550  catch( const IO_ERROR& ioe )
551  {
552  DisplayError( this, ioe.What() );
553  return false;
554  }
555 
556  msg.Printf( FMT_MOD_DELETED, fpname.GetData(), nickname.GetData() );
557 
558  SetStatusText( msg );
559 
560  return true;
561 }
562 
563 
564 void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aStoreInNewLib )
565 {
566  if( GetBoard()->m_Modules == NULL )
567  {
568  DisplayInfoMessage( this, _( "No footprints to archive!" ) );
569  return;
570  }
571 
572  wxString footprintName;
573 
574  if( !aStoreInNewLib )
575  {
576  // The footprints are saved in an existing .pretty library in the fp lib table
577  PROJECT& prj = Prj();
578  wxString last_nickname = prj.GetRString( PROJECT::PCB_LIB_NICKNAME );
579  wxString nickname = SelectLibrary( last_nickname );
580 
581  if( !nickname ) // Aborted
582  return;
583 
584  prj.SetRString( PROJECT::PCB_LIB_NICKNAME, nickname );
585 
586  try
587  {
588  FP_LIB_TABLE* tbl = prj.PcbFootprintLibs();
589 
590  for( MODULE* curr_fp = GetBoard()->m_Modules; curr_fp; curr_fp = curr_fp->Next() )
591  {
592  if( !curr_fp->GetFPID().GetLibItemName().empty() ) // Can happen with old boards.
593  tbl->FootprintSave( nickname, curr_fp, false );
594  }
595  }
596  catch( const IO_ERROR& ioe )
597  {
598  DisplayError( this, ioe.What() );
599  }
600  }
601  else
602  {
603  // The footprints are saved in a new .pretty library.
604  // If this library already exists, all previous footprints will be deleted
605  wxString libPath = CreateNewLibrary();
606 
607  if( libPath.IsEmpty() ) // Aborted
608  return;
609 
611  PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) );
612 
613  for( MODULE* curr_fp = GetBoard()->m_Modules; curr_fp; curr_fp = curr_fp->Next() )
614  {
615  try
616  {
617  if( !curr_fp->GetFPID().GetLibItemName().empty() ) // Can happen with old boards.
618  pi->FootprintSave( libPath, curr_fp );
619  }
620  catch( const IO_ERROR& ioe )
621  {
622  DisplayError( this, ioe.What() );
623  }
624  }
625  }
626 }
627 
628 
629 bool FOOTPRINT_EDIT_FRAME::SaveFootprintInLibrary( const wxString& aLibrary,
630  MODULE* aModule,
631  bool aOverwrite,
632  bool aDisplayDialog )
633 {
634  if( aModule == NULL )
635  return false;
636 
637  SetMsgPanel( aModule );
638 
639 
640  // Legacy libraries are readable, but modifying legacy format is not allowed
641  // So prompt the user if he try to add/replace a footprint in a legacy lib
642  wxString libfullname = Prj().PcbFootprintLibs()->FindRow( aLibrary )->GetFullURI();
644 
645  if( piType == IO_MGR::LEGACY )
646  {
648  return false;
649  }
650 
651  // Ask what to use as the footprint name in the library
652  wxString footprintName = FROM_UTF8( aModule->GetFPID().GetLibItemName() );
653 
654  if( aDisplayDialog )
655  {
656  wxTextEntryDialog dlg( this, _( "Name:" ), FMT_SAVE_MODULE, footprintName );
657 
658  if( dlg.ShowModal() != wxID_OK )
659  return false; // canceled by user
660 
661  footprintName = dlg.GetValue();
662  footprintName.Trim( true );
663  footprintName.Trim( false );
664 
665  if( footprintName.IsEmpty() )
666  return false;
667 
668  if( ! MODULE::IsLibNameValid( footprintName ) )
669  {
670  wxString msg = wxString::Format(
671  _("Error:\none of invalid chars '%s' found\nin '%s'" ),
673  GetChars( footprintName ) );
674 
675  DisplayError( NULL, msg );
676  return false;
677  }
678 
679  aModule->SetFPID( LIB_ID( footprintName ) );
680  }
681 
682  // Ensure this footprint has a libname
683  if( footprintName.IsEmpty() )
684  {
685  footprintName = wxT("noname");
686  aModule->SetFPID( LIB_ID( footprintName ) );
687  }
688 
689  bool module_exists = false;
690 
691  try
692  {
693  FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs();
694 
695  MODULE* m = tbl->FootprintLoad( aLibrary, footprintName );
696 
697  if( m )
698  {
699  delete m;
700 
701  module_exists = true;
702 
703  // an existing footprint is found in current lib
704  if( aDisplayDialog )
705  {
706  wxString msg = wxString::Format( FMT_MOD_EXISTS,
707  footprintName.GetData(), aLibrary.GetData() );
708 
709  SetStatusText( msg );
710  }
711 
712  if( !aOverwrite )
713  {
714  // Do not save the given footprint: an old one exists
715  return true;
716  }
717  }
718 
719  // this always overwrites any existing footprint, but should yell on its
720  // own if the library or footprint is not writable.
721  tbl->FootprintSave( aLibrary, aModule );
722  }
723  catch( const IO_ERROR& ioe )
724  {
725  DisplayError( this, ioe.What() );
726  return false;
727  }
728 
729  if( aDisplayDialog )
730  {
731  wxString fmt = module_exists ?
732  _( "Component [%s] replaced in '%s'" ) :
733  _( "Component [%s] added in '%s'" );
734 
735  wxString msg = wxString::Format( fmt, footprintName.GetData(), aLibrary.GetData() );
736  SetStatusText( msg );
737  }
738 
739  return true;
740 }
741 
742 
743 MODULE* PCB_BASE_FRAME::CreateNewModule( const wxString& aModuleName )
744 {
745  // Creates a new footprint at position 0,0 which contains the minimal items:
746  // the reference and the value.
747  // Value : initialized to the footprint name.
748  // put on fab layer (front side)
749  // Reference : initialized to a default value (REF**).
750  // put on silkscreen layer (front side)
751 
752  wxString moduleName = aModuleName;
753 
754  // Ask for the new module name
755  if( moduleName.IsEmpty() )
756  {
757  wxTextEntryDialog dlg( this, FMT_MOD_REF, FMT_MOD_CREATE, moduleName );
758  dlg.SetTextValidator( FILE_NAME_CHAR_VALIDATOR( &moduleName ) );
759 
760  if( dlg.ShowModal() != wxID_OK )
761  return NULL; //Aborted by user
762  }
763 
764  moduleName.Trim( true );
765  moduleName.Trim( false );
766 
767  if( moduleName.IsEmpty() )
768  {
770  return NULL;
771  }
772 
773  // Creates the new module and add it to the head of the linked list of modules
774  MODULE* module = new MODULE( GetBoard() );
775 
776  GetBoard()->Add( module );
777 
778  // Update parameters: timestamp ...
779  module->SetLastEditTime();
780 
781  // Update its name in lib
782  module->SetFPID( LIB_ID( moduleName ) );
783 
784  wxPoint default_pos;
786 
787  // Update reference:
788  if( settings.m_RefDefaultText.IsEmpty() )
789  module->SetReference( moduleName );
790  else
791  module->SetReference( settings.m_RefDefaultText );
792 
793  module->Reference().SetThickness( settings.m_ModuleTextWidth );
794  module->Reference().SetTextSize( settings.m_ModuleTextSize );
795  default_pos.y = GetDesignSettings().m_ModuleTextSize.y / 2;
796  module->Reference().SetPosition( default_pos );
797  module->Reference().SetLayer( ToLAYER_ID( settings.m_RefDefaultlayer ) );
798  module->Reference().SetVisible( settings.m_RefDefaultVisibility );
799 
800  // Set the value field to a default value
801  if( settings.m_ValueDefaultText.IsEmpty() )
802  module->SetValue( moduleName );
803  else
804  module->SetValue( settings.m_ValueDefaultText );
805 
806  module->Value().SetThickness( GetDesignSettings().m_ModuleTextWidth );
807  module->Value().SetTextSize( GetDesignSettings().m_ModuleTextSize );
808  default_pos.y = -default_pos.y;
809  module->Value().SetPosition( default_pos );
810  module->Value().SetLayer( ToLAYER_ID( settings.m_ValueDefaultlayer ) );
811  module->Value().SetVisible( settings.m_ValueDefaultVisibility );
812 
813  SetMsgPanel( module );
814  return module;
815 }
816 
817 
818 wxString PCB_BASE_FRAME::SelectLibrary( const wxString& aNicknameExisting )
819 {
820  wxArrayString headers;
821 
822  headers.Add( _( "Nickname" ) );
823  headers.Add( _( "Description" ) );
824 
825  FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs();
826 
827  std::vector< wxArrayString > itemsToDisplay;
828  std::vector< wxString > nicknames = fptbl->GetLogicalLibs();
829 
830  for( unsigned i = 0; i < nicknames.size(); i++ )
831  {
832  wxArrayString item;
833 
834  item.Add( nicknames[i] );
835  item.Add( fptbl->GetDescription( nicknames[i] ) );
836 
837  itemsToDisplay.push_back( item );
838  }
839 
840  EDA_LIST_DIALOG dlg( this, FMT_SELECT_LIB, headers, itemsToDisplay, aNicknameExisting );
841 
842  if( dlg.ShowModal() != wxID_OK )
843  return wxEmptyString;
844 
845  wxString nickname = dlg.GetTextSelection();
846 
847  wxLogDebug( wxT( "Chose footprint library '%s'." ), GetChars( nickname ) );
848 
849  return nickname;
850 }
A dialog to select/create a .pretty folder which is a footprint library.
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"))
wxString m_RefDefaultText
Default ref text on fp creation.
void BuildListOfNets()
Definition: class_board.h:764
const wxString KiCadFootprintFileExtension
Definition of class FOOTPRINT_EDIT_FRAME.
bool m_ValueDefaultVisibility
Default value text visibility on fp creation.
#define FMT_MOD_NOT_FOUND
Definition: librairi.cpp:66
TEXTE_MODULE & Reference()
Definition: class_module.h:456
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"))
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:137
Class PCB_IO is a PLUGIN derivation for saving and loading Pcbnew s-expression formatted files...
wxString m_mruPath
Most recently used path.
Definition: wxstruct.h:155
Class PROJECT holds project specific data.
Definition: project.h:52
#define FMT_FILE_NOT_FOUND
Definition: librairi.cpp:64
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
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:194
This file is part of the common library TODO brief description.
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.
Definition: librairi.cpp:233
#define FMT_MOD_REF
Definition: librairi.cpp:73
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
This file is part of the common library.
int m_ModuleTextWidth
Default footprint texts thickness.
Class BOARD to handle a board.
MODULE * FootprintLoad(const wxString &aNickname, const wxString &aFootprintName)
Function FootprintLoad.
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:85
#define FMT_MOD_CREATE
Definition: librairi.cpp:76
void SetVisible(bool aVisible)
Definition: eda_text.h:175
const wxString KiCadFootprintLibFileWildcard
BOARD * GetBoard() const
virtual wxConfigBase * config()
Function config returns the wxConfigBase used in SaveSettings(), and is overloaded in KICAD_MANAGER_F...
Definition: basicframe.cpp:361
class EDA_LIST_DIALOG
static const wxString ModImportFileWildcard(_("GPcb foot print files (*)|*"))
int m_ValueDefaultlayer
Default value text layer on fp creation.
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:214
static const wxChar * StringLibNameInvalidChars(bool aUserReadable)
static function StringLibNameInvalidChars Test for validity of the name in a library of the footprint...
Class LIB_ID.
Definition: lib_id.h:56
wxSize m_ModuleTextSize
Default footprint texts size.
void SetLastEditTime(time_t aTime)
Definition: class_module.h:270
#define FMT_SELECT_LIB
Definition: librairi.cpp:80
MODULE * CreateNewModule(const wxString &aModuleName)
Function CreateNewModule Creates a new module or footprint, at position 0,0 The new module contains o...
Definition: librairi.cpp:743
static wxFileName prompt_for_module(wxWindow *aParent, const wxString &aLastPath)
Prompt the user for a module file to open.
Definition: librairi.cpp:106
#define FMT_OK_DELETE
Definition: librairi.cpp:62
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:57
static PCB_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath)
Function GuessPluginTypeFromLibPath returns a plugin type given a footprint library's libPath...
Definition: io_mgr.cpp:182
const wxString GetFullURI(bool aSubstituted=false) const
Function GetFullURI.
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
wxString CreateNewLibrary()
Function CreateNewLibrary prompts user for a library path, then creates a new footprint library at th...
Definition: librairi.cpp:435
const wxString GetCurrentLib() const
Return the current library nickname.
This file contains miscellaneous commonly used macros and functions.
Class FILE_NAME_CHAR_VALIDATOR.
Definition: validators.h:43
static IO_MGR::PCB_FILE_T detect_file_type(FILE *aFile, const wxFileName &aFileName, wxString *aName)
Read a file to detect the type.
Definition: librairi.cpp:136
void PlaceModule(MODULE *aModule, wxDC *aDC, bool aDoNotRecreateRatsnest=false)
Function PlaceModule places aModule at the current cursor position and updates module coordinates wit...
Definition: modules.cpp:351
static const wxString ModLegacyExportFileWildcard(_("Legacy foot print export files (*.emp)|*.emp"))
virtual bool IsFootprintLibWritable(const wxString &aLibraryPath)
Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable.
Definition: plugin.cpp:114
BOARD_ITEM * Next() const
Class RELEASER releases a PLUGIN in the context of a potential thrown exception, through its destruct...
Definition: io_mgr.h:476
const LIB_ID & GetFPID() const
Definition: class_module.h:152
#define FMT_EXPORT_MODULE
Definition: librairi.cpp:71
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
#define FOOTPRINT_LIBRARY_HEADER
Definition: legacy_plugin.h:38
Class FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
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:76
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Function SetMsgPanel clears the message panel and populates it with the contents of aList...
Definition: draw_frame.cpp:754
#define FMT_NOT_MODULE
Definition: librairi.cpp:65
std::string GetStringOutput(bool doClear)
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:106
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:455
#define FMT_NO_REF_ABORTED
Definition: librairi.cpp:79
const wxString GetDescription(const wxString &aNickname)
Function GetDescription.
const UTF8 & GetLibItemName() const
Function GetLibItemName.
Definition: lib_id.h:129
S-expression Pcbnew file format.
Definition: io_mgr.h:54
static MODULE * parse_module_with_plugin(const wxFileName &aFileName, IO_MGR::PCB_FILE_T aFileType, const wxString &aName)
Parse a footprint using a PLUGIN.
Definition: librairi.cpp:184
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
>
#define EXPORT_IMPORT_LASTPATH_KEY
Definition: librairi.cpp:98
The common library.
Helper dialog and control classes.
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:101
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use...
Definition: draw_frame.h:795
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame...
void SetReference(const wxString &aReference)
Function SetReference.
Definition: class_module.h:422
virtual void SetPosition(const wxPoint &aPos) override
void SetPosition(const wxPoint &aPos) override
wxString m_ValueDefaultText
Default value text on fp creation.
void Format(BOARD_ITEM *aItem, int aNestLevel=0) const
Function Format outputs aItem to aFormatter in s-expression format.
#define FOOTPRINT_LIBRARY_HEADER_CNT
Definition: legacy_plugin.h:39
#define FMT_IMPORT_MODULE
Definition: librairi.cpp:63
#define FMT_MOD_EXISTS
Definition: librairi.cpp:78
void Export_Module(MODULE *aModule)
Function Export_Module Create a file containing only one footprint.
Definition: librairi.cpp:334
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:162
VTBL_ENTRY FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
bool DeleteModuleFromCurrentLibrary()
Function DeleteModuleFromCurrentLibrary prompts user for footprint name, then deletes it from current...
Definition: librairi.cpp:505
bool SaveCurrentModule(const wxString *aLibPath=NULL)
Function SaveCurrentModule saves the module which is currently being edited into aLibPath or into the...
Definition: librairi.cpp:408
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
static bool IsLibNameValid(const wxString &aName)
static function IsLibNameValid Test for validity of a name of a footprint to be used in a footprint l...
void DisplayInfoMessage(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayInfoMessage displays an informational message box with aMessage.
Definition: confirm.cpp:89
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:177
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
MODULE * Import_Module()
Function Import_Module Read a file containing only one footprint.
Definition: librairi.cpp:258
#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:53
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)
Function ArchiveModulesOnBoard Save modules in a library:
Definition: librairi.cpp:564
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
#define FMT_MOD_DELETED
Definition: librairi.cpp:75
const wxString getLibPath()
The libPath is not publicly visible, grab it from the FP_LIB_TABLE if we must.
void updateView()
Reloads displayed items and sets view.
void SetValue(const wxString &aValue)
Function SetValue.
Definition: class_module.h:449
static MODULE * parse_module_kicad(const wxFileName &aFileName)
Parse a KICAD footprint.
Definition: librairi.cpp:212
#define FMT_LIB_READ_ONLY
Definition: librairi.cpp:69
int m_RefDefaultlayer
Default ref text layer on fp creation.
#define FMT_EXPORTED
Definition: librairi.cpp:74
virtual void FootprintLibCreate(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Function FootprintLibCreate creates a new empty footprint library at aLibraryPath empty...
Definition: plugin.cpp:99
#define FMT_SAVE_MODULE
Definition: librairi.cpp:72
wxString SelectLibrary(const wxString &aNicknameExisting)
Function SelectLibrary puts up a dialog and allows the user to pick a library, for unspecified use...
Definition: librairi.cpp:818
const wxString GedaPcbFootprintLibFileWildcard
Module description (excepted pads)
bool SaveFootprintInLibrary(const wxString &aLibName, MODULE *aModule, bool aOverwrite, bool aDisplayDialog)
Function SaveFootprintInLibrary Save in an existing library a given footprint.
Definition: librairi.cpp:629
SAVE_T FootprintSave(const wxString &aNickname, const MODULE *aFootprint, bool aOverwrite=true)
Function FootprintSave.
void FootprintDelete(const wxString &aNickname, const wxString &aFootprintName)
Function FootprintDelete.
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:51
#define FMT_OK_OVERWRITE
Definition: librairi.cpp:60
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:69
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Function IsOK displays a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:111
bool m_RefDefaultVisibility
Default ref text visibility on fp creation.
void SetFPID(const LIB_ID &aFPID)
Definition: class_module.h:153
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:767
Custom text control validator definitions.
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:148
std::vector< wxString > GetLogicalLibs()
Function GetLogicalLibs.
wxString SelectFootprint(EDA_DRAW_FRAME *aWindow, const wxString &aLibraryName, const wxString &aMask, const wxString &aKeyWord, FP_LIB_TABLE *aTable)
Function SelectFootprint displays a list of modules found in all libraries or a given library...
Definition: loadcmp.cpp:354
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