You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1123 lines
33 KiB

* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
18 years ago
18 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
  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. #include <wx/ffile.h>
  24. #include <fctsys.h>
  25. #include <pgm_base.h>
  26. #include <kiface_i.h>
  27. #include <confirm.h>
  28. #include <kicad_string.h>
  29. #include <pcb_edit_frame.h>
  30. #include <dialog_helpers.h>
  31. #include <filter_reader.h>
  32. #include <macros.h>
  33. #include <fp_lib_table.h>
  34. #include <validators.h>
  35. #include <dialog_text_entry.h>
  36. #include <tool/tool_manager.h>
  37. #include <tools/pcb_actions.h>
  38. #include <class_board.h>
  39. #include <class_module.h>
  40. #include <board_commit.h>
  41. #include <footprint_edit_frame.h>
  42. #include <wildcards_and_files_ext.h>
  43. #include <kicad_plugin.h>
  44. #include <legacy_plugin.h>
  45. #include <env_paths.h>
  46. #include <settings/settings_manager.h>
  47. #include <footprint_editor_settings.h>
  48. #include "footprint_viewer_frame.h"
  49. // unique, "file local" translations:
  50. static const wxString INFO_LEGACY_LIB_WARN_EDIT(
  51. _( "Writing/modifying legacy libraries (.mod files) is not allowed\n"\
  52. "Please save the current library to the new .pretty format\n"\
  53. "and update your footprint lib table\n"\
  54. "to save your footprint (a .kicad_mod file) in the .pretty library folder" ) );
  55. static const wxString INFO_LEGACY_LIB_WARN_DELETE(
  56. _( "Modifying legacy libraries (.mod files) is not allowed\n"\
  57. "Please save the current library under the new .pretty format\n"\
  58. "and update your footprint lib table\n"\
  59. "before deleting a footprint" ) );
  60. /**
  61. * Prompt the user for a module file to open.
  62. * @param aParent - parent window for the dialog
  63. * @param aLastPath - last opened path
  64. */
  65. static wxFileName getFootprintFilenameFromUser( wxWindow* aParent, const wxString& aLastPath )
  66. {
  67. static int lastFilterIndex = 0; // To store the last choice during a session.
  68. wxString wildCard;
  69. wildCard << KiCadFootprintLibFileWildcard() << wxChar( '|' )
  70. << ModLegacyExportFileWildcard() << wxChar( '|' )
  71. << GedaPcbFootprintLibFileWildcard() << wxChar( '|' )
  72. << AllFilesWildcard();
  73. wxFileDialog dlg( aParent, _( "Import Footprint" ), aLastPath, wxEmptyString, wildCard,
  74. wxFD_OPEN | wxFD_FILE_MUST_EXIST );
  75. dlg.SetFilterIndex( lastFilterIndex );
  76. if( dlg.ShowModal() == wxID_CANCEL )
  77. return wxFileName();
  78. lastFilterIndex = dlg.GetFilterIndex();
  79. return wxFileName( dlg.GetPath() );
  80. }
  81. /**
  82. * Read a file to detect the type.
  83. * @param aFile - open file to be read. File pointer will be closed.
  84. * @param aFileName - file name to be read
  85. * @param aName - wxString to receive the module name iff type is LEGACY
  86. */
  87. static IO_MGR::PCB_FILE_T detect_file_type( FILE* aFile, const wxFileName& aFileName,
  88. wxString* aName )
  89. {
  90. FILE_LINE_READER freader( aFile, aFileName.GetFullPath() );
  91. WHITESPACE_FILTER_READER reader( freader );
  92. IO_MGR::PCB_FILE_T file_type;
  93. wxASSERT( aName );
  94. reader.ReadLine();
  95. char* line = reader.Line();
  96. if( !strncasecmp( line, "(module", strlen( "(module" ) ) )
  97. {
  98. file_type = IO_MGR::KICAD_SEXP;
  99. *aName = aFileName.GetName();
  100. }
  101. else if( !strncasecmp( line, FOOTPRINT_LIBRARY_HEADER, FOOTPRINT_LIBRARY_HEADER_CNT ) )
  102. {
  103. file_type = IO_MGR::LEGACY;
  104. while( reader.ReadLine() )
  105. {
  106. if( !strncasecmp( line, "$MODULE", strlen( "$MODULE" ) ) )
  107. {
  108. *aName = FROM_UTF8( StrPurge( line + strlen( "$MODULE" ) ) );
  109. break;
  110. }
  111. }
  112. }
  113. else if( !strncasecmp( line, "Element", strlen( "Element" ) ) )
  114. {
  115. file_type = IO_MGR::GEDA_PCB;
  116. *aName = aFileName.GetName();
  117. }
  118. else
  119. {
  120. file_type = IO_MGR::FILE_TYPE_NONE;
  121. }
  122. return file_type;
  123. }
  124. /**
  125. * Parse a footprint using a PLUGIN.
  126. * @param aFileName - file name to parse
  127. * @param aFileType - type of the file
  128. * @param aName - name of the footprint
  129. */
  130. static MODULE* parse_module_with_plugin(
  131. const wxFileName& aFileName, IO_MGR::PCB_FILE_T aFileType,
  132. const wxString& aName )
  133. {
  134. wxString path;
  135. switch( aFileType )
  136. {
  137. case IO_MGR::GEDA_PCB:
  138. path = aFileName.GetPath();
  139. break;
  140. case IO_MGR::LEGACY:
  141. path = aFileName.GetFullPath();
  142. break;
  143. default:
  144. wxFAIL_MSG( wxT( "unexpected IO_MGR::PCB_FILE_T" ) );
  145. }
  146. PLUGIN::RELEASER pi( IO_MGR::PluginFind( aFileType ) );
  147. return pi->FootprintLoad( path, aName );
  148. }
  149. /**
  150. * Parse a KICAD footprint.
  151. * @param aFileName - file name to parse
  152. */
  153. static MODULE* parse_module_kicad( const wxFileName& aFileName )
  154. {
  155. wxString fcontents;
  156. PCB_IO pcb_io;
  157. wxFFile f( aFileName.GetFullPath() );
  158. if( !f.IsOpened() )
  159. return NULL;
  160. f.ReadAll( &fcontents );
  161. return dynamic_cast<MODULE*>( pcb_io.Parse( fcontents ) );
  162. }
  163. /**
  164. * Try to load a footprint, returning NULL if the file couldn't be accessed.
  165. * @param aFileName - file name to load
  166. * @param aFileType - type of the file to load
  167. * @param aName - footprint name
  168. */
  169. MODULE* try_load_footprint( const wxFileName& aFileName, IO_MGR::PCB_FILE_T aFileType,
  170. const wxString& aName )
  171. {
  172. MODULE* module;
  173. switch( aFileType )
  174. {
  175. case IO_MGR::GEDA_PCB:
  176. case IO_MGR::LEGACY:
  177. module = parse_module_with_plugin( aFileName, aFileType, aName );
  178. break;
  179. case IO_MGR::KICAD_SEXP:
  180. module = parse_module_kicad( aFileName );
  181. break;
  182. default:
  183. wxFAIL_MSG( wxT( "unexpected IO_MGR::PCB_FILE_T" ) );
  184. module = NULL;
  185. }
  186. return module;
  187. }
  188. MODULE* FOOTPRINT_EDIT_FRAME::Import_Module( const wxString& aName )
  189. {
  190. wxString lastOpenedPathForLoading = m_mruPath;
  191. FOOTPRINT_EDITOR_SETTINGS* cfg = GetSettings();
  192. if( !cfg->m_LastImportExportPath.empty() )
  193. lastOpenedPathForLoading = cfg->m_LastImportExportPath;
  194. wxFileName fn;
  195. if( aName != wxT("") )
  196. fn = aName;
  197. else
  198. fn = getFootprintFilenameFromUser( this, lastOpenedPathForLoading );
  199. if( !fn.IsOk() )
  200. return NULL;
  201. FILE* fp = wxFopen( fn.GetFullPath(), wxT( "rt" ) );
  202. if( !fp )
  203. {
  204. wxString msg = wxString::Format( _( "File \"%s\" not found" ), fn.GetFullPath() );
  205. DisplayError( this, msg );
  206. return NULL;
  207. }
  208. cfg->m_LastImportExportPath = lastOpenedPathForLoading;
  209. wxString moduleName;
  210. IO_MGR::PCB_FILE_T fileType = detect_file_type( fp, fn.GetFullPath(), &moduleName );
  211. if( fileType == IO_MGR::FILE_TYPE_NONE )
  212. {
  213. DisplayError( this, _( "Not a footprint file" ) );
  214. return NULL;
  215. }
  216. MODULE* module = NULL;
  217. try
  218. {
  219. module = try_load_footprint( fn, fileType, moduleName );
  220. if( !module )
  221. {
  222. wxString msg = wxString::Format( _( "Unable to load footprint '%s' from '%s'" ),
  223. moduleName,
  224. fn.GetFullPath() );
  225. DisplayError( this, msg );
  226. return NULL;
  227. }
  228. }
  229. catch( const IO_ERROR& ioe )
  230. {
  231. DisplayError( this, ioe.What() );
  232. // if the footprint is not loaded, exit.
  233. // However, even if an error happens, it can be loaded, because in KICAD and GPCB format,
  234. // a fp library is a set of separate files, and the error(s) are not necessary when
  235. // reading the selected file
  236. if( !module )
  237. return NULL;
  238. }
  239. module->SetFPID( LIB_ID( wxEmptyString, moduleName ) );
  240. // Insert footprint in list
  241. AddModuleToBoard( module );
  242. // Display info :
  243. SetMsgPanel( module );
  244. PlaceModule( module );
  245. module->SetPosition( wxPoint( 0, 0 ) );
  246. GetBoard()->BuildListOfNets();
  247. updateView();
  248. return module;
  249. }
  250. void FOOTPRINT_EDIT_FRAME::Export_Module( MODULE* aModule )
  251. {
  252. wxFileName fn;
  253. FOOTPRINT_EDITOR_SETTINGS* cfg = GetSettings();
  254. if( !aModule )
  255. return;
  256. fn.SetName( aModule->GetFPID().GetLibItemName() );
  257. wxString wildcard = KiCadFootprintLibFileWildcard();
  258. fn.SetExt( KiCadFootprintFileExtension );
  259. if( !cfg->m_LastImportExportPath.empty() )
  260. fn.SetPath( cfg->m_LastImportExportPath );
  261. else
  262. fn.SetPath( m_mruPath );
  263. wxFileDialog dlg( this, _( "Export Footprint" ), fn.GetPath(), fn.GetFullName(),
  264. wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
  265. if( dlg.ShowModal() == wxID_CANCEL )
  266. return;
  267. fn = dlg.GetPath();
  268. cfg->m_LastImportExportPath = fn.GetPath();
  269. try
  270. {
  271. // Export as *.kicad_pcb format, using a strategy which is specifically chosen
  272. // as an example on how it could also be used to send it to the system clipboard.
  273. PCB_IO pcb_io( CTL_FOR_LIBRARY );
  274. /* This module should *already* be "normalized" in a way such that
  275. orientation is zero, etc., since it came from module editor.
  276. module->SetParent( 0 );
  277. module->SetOrientation( 0 );
  278. */
  279. pcb_io.Format( aModule );
  280. FILE* fp = wxFopen( dlg.GetPath(), wxT( "wt" ) );
  281. if( fp == NULL )
  282. {
  283. wxMessageBox( wxString::Format( _( "Unable to create or write file \"%s\"" ),
  284. dlg.GetPath() ) );
  285. return;
  286. }
  287. fprintf( fp, "%s", pcb_io.GetStringOutput( false ).c_str() );
  288. fclose( fp );
  289. }
  290. catch( const IO_ERROR& ioe )
  291. {
  292. DisplayError( this, ioe.What() );
  293. return;
  294. }
  295. wxString msg = wxString::Format( _( "Footprint exported to file \"%s\"" ), dlg.GetPath() );
  296. DisplayInfoMessage( this, msg );
  297. }
  298. wxString PCB_BASE_EDIT_FRAME::CreateNewLibrary( const wxString& aLibName,
  299. const wxString& aProposedName )
  300. {
  301. // Kicad cannot write legacy format libraries, only .pretty new format
  302. // because the legacy format cannot handle current features.
  303. // The footprint library is actually a directory
  304. wxString initialPath = aProposedName.IsEmpty() ? Prj().GetProjectPath() : aProposedName;
  305. wxFileName fn;
  306. bool doAdd = false;
  307. if( aLibName.IsEmpty() )
  308. {
  309. fn = initialPath;
  310. if( !LibraryFileBrowser( false, fn,
  311. KiCadFootprintLibPathWildcard(), KiCadFootprintLibPathExtension ) )
  312. {
  313. return wxEmptyString;
  314. }
  315. doAdd = true;
  316. }
  317. else
  318. {
  319. fn = aLibName;
  320. if( !fn.IsAbsolute() )
  321. {
  322. fn.SetName( aLibName );
  323. fn.MakeAbsolute( initialPath );
  324. }
  325. // Enforce the .pretty extension:
  326. fn.SetExt( KiCadFootprintLibPathExtension );
  327. }
  328. // We can save fp libs only using IO_MGR::KICAD_SEXP format (.pretty libraries)
  329. IO_MGR::PCB_FILE_T piType = IO_MGR::KICAD_SEXP;
  330. wxString libPath = fn.GetFullPath();
  331. try
  332. {
  333. PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) );
  334. bool writable = false;
  335. bool exists = false;
  336. try
  337. {
  338. writable = pi->IsFootprintLibWritable( libPath );
  339. exists = true; // no exception was thrown, lib must exist.
  340. }
  341. catch( const IO_ERROR& )
  342. { }
  343. if( exists )
  344. {
  345. if( !writable )
  346. {
  347. wxString msg = wxString::Format( _( "Library \"%s\" is read only." ), libPath );
  348. ShowInfoBarError( msg );
  349. return wxEmptyString;
  350. }
  351. else
  352. {
  353. wxString msg = wxString::Format( _( "Library %s already exists." ), libPath );
  354. KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
  355. dlg.SetOKLabel( _( "Overwrite" ) );
  356. dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
  357. if( dlg.ShowModal() == wxID_CANCEL )
  358. return wxEmptyString;
  359. pi->FootprintLibDelete( libPath );
  360. }
  361. }
  362. pi->FootprintLibCreate( libPath );
  363. }
  364. catch( const IO_ERROR& ioe )
  365. {
  366. DisplayError( this, ioe.What() );
  367. return wxEmptyString;
  368. }
  369. if( doAdd )
  370. AddLibrary( libPath );
  371. return libPath;
  372. }
  373. bool PCB_BASE_EDIT_FRAME::AddLibrary( const wxString& aFilename )
  374. {
  375. wxFileName fn( aFilename );
  376. if( aFilename.IsEmpty() )
  377. {
  378. if( !LibraryFileBrowser( true, fn,
  379. KiCadFootprintLibPathWildcard(), KiCadFootprintLibPathExtension,
  380. true ) )
  381. {
  382. return false;
  383. }
  384. }
  385. wxString libPath = fn.GetFullPath();
  386. wxString libName = fn.GetName();
  387. if( libName.IsEmpty() )
  388. return false;
  389. bool saveInGlobalTable = false;
  390. bool saveInProjectTable = false;
  391. if( Prj().IsNullProject() )
  392. {
  393. saveInGlobalTable = true;
  394. }
  395. else
  396. {
  397. wxArrayString libTableNames;
  398. libTableNames.Add( _( "Global" ) );
  399. libTableNames.Add( _( "Project" ) );
  400. switch( SelectSingleOption( this, _( "Select Library Table" ),
  401. _( "Choose the Library Table to add the library to:" ), libTableNames ) )
  402. {
  403. case 0: saveInGlobalTable = true; break;
  404. case 1: saveInProjectTable = true; break;
  405. default: return false;
  406. }
  407. }
  408. wxString type = IO_MGR::ShowType( IO_MGR::GuessPluginTypeFromLibPath( libPath ) );
  409. // try to use path normalized to an environmental variable or project path
  410. wxString normalizedPath = NormalizePath( libPath, &Pgm().GetLocalEnvVariables(), &Prj() );
  411. if( normalizedPath.IsEmpty() )
  412. normalizedPath = libPath;
  413. try
  414. {
  415. if( saveInGlobalTable )
  416. {
  417. auto row = new FP_LIB_TABLE_ROW( libName, normalizedPath, type, wxEmptyString );
  418. GFootprintTable.InsertRow( row );
  419. GFootprintTable.Save( FP_LIB_TABLE::GetGlobalTableFileName() );
  420. }
  421. else if( saveInProjectTable )
  422. {
  423. auto row = new FP_LIB_TABLE_ROW( libName, normalizedPath, type, wxEmptyString );
  424. Prj().PcbFootprintLibs()->InsertRow( row );
  425. Prj().PcbFootprintLibs()->Save( Prj().FootprintLibTblName() );
  426. }
  427. }
  428. catch( const IO_ERROR& ioe )
  429. {
  430. DisplayError( this, ioe.What() );
  431. return false;
  432. }
  433. auto editor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_FOOTPRINT_EDITOR, false );
  434. if( editor )
  435. {
  436. LIB_ID libID( libName, wxEmptyString );
  437. editor->SyncLibraryTree( true );
  438. editor->FocusOnLibID( libID );
  439. }
  440. auto viewer = (FOOTPRINT_VIEWER_FRAME*) Kiway().Player( FRAME_FOOTPRINT_VIEWER, false );
  441. if( viewer )
  442. viewer->ReCreateLibraryList();
  443. return true;
  444. }
  445. bool FOOTPRINT_EDIT_FRAME::DeleteModuleFromLibrary( const LIB_ID& aFPID, bool aConfirm )
  446. {
  447. if( !aFPID.IsValid() )
  448. return false;
  449. wxString nickname = aFPID.GetLibNickname();
  450. wxString fpname = aFPID.GetLibItemName();
  451. // Legacy libraries are readable, but modifying legacy format is not allowed
  452. // So prompt the user if he try to delete a footprint from a legacy lib
  453. wxString libfullname = Prj().PcbFootprintLibs()->FindRow( nickname )->GetFullURI();
  454. if( IO_MGR::GuessPluginTypeFromLibPath( libfullname ) == IO_MGR::LEGACY )
  455. {
  456. DisplayInfoMessage( this, INFO_LEGACY_LIB_WARN_DELETE );
  457. return false;
  458. }
  459. if( !Prj().PcbFootprintLibs()->IsFootprintLibWritable( nickname ) )
  460. {
  461. wxString msg = wxString::Format( _( "Library '%s' is read only." ), nickname );
  462. ShowInfoBarError( msg );
  463. return false;
  464. }
  465. // Confirmation
  466. wxString msg = wxString::Format( _( "Delete footprint '%s' from library '%s'?" ),
  467. fpname.GetData(),
  468. nickname.GetData() );
  469. if( aConfirm && !IsOK( this, msg ) )
  470. return false;
  471. try
  472. {
  473. Prj().PcbFootprintLibs()->FootprintDelete( nickname, fpname );
  474. }
  475. catch( const IO_ERROR& ioe )
  476. {
  477. DisplayError( this, ioe.What() );
  478. return false;
  479. }
  480. msg.Printf( _( "Footprint '%s' deleted from library '%s'" ),
  481. fpname.GetData(),
  482. nickname.GetData() );
  483. SetStatusText( msg );
  484. return true;
  485. }
  486. void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aStoreInNewLib, const wxString& aLibName,
  487. wxString* aLibPath )
  488. {
  489. if( GetBoard()->GetFirstModule() == NULL )
  490. {
  491. DisplayInfoMessage( this, _( "No footprints to archive!" ) );
  492. return;
  493. }
  494. wxString footprintName;
  495. if( !aStoreInNewLib )
  496. {
  497. // The footprints are saved in an existing .pretty library in the fp lib table
  498. PROJECT& prj = Prj();
  499. wxString last_nickname = prj.GetRString( PROJECT::PCB_LIB_NICKNAME );
  500. wxString nickname = SelectLibrary( last_nickname );
  501. if( !nickname ) // Aborted
  502. return;
  503. prj.SetRString( PROJECT::PCB_LIB_NICKNAME, nickname );
  504. try
  505. {
  506. FP_LIB_TABLE* tbl = prj.PcbFootprintLibs();
  507. for( auto curr_fp : GetBoard()->Modules() )
  508. {
  509. if( !curr_fp->GetFPID().GetLibItemName().empty() ) // Can happen with old boards.
  510. tbl->FootprintSave( nickname, curr_fp, false );
  511. }
  512. }
  513. catch( const IO_ERROR& ioe )
  514. {
  515. DisplayError( this, ioe.What() );
  516. }
  517. }
  518. else
  519. {
  520. // The footprints are saved in a new .pretty library.
  521. // If this library already exists, all previous footprints will be deleted
  522. wxString libPath = CreateNewLibrary( aLibName );
  523. if( libPath.IsEmpty() ) // Aborted
  524. return;
  525. if( aLibPath ) *aLibPath = libPath;
  526. IO_MGR::PCB_FILE_T piType = IO_MGR::KICAD_SEXP;
  527. PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) );
  528. for( auto curr_fp : GetBoard()->Modules() )
  529. {
  530. try
  531. {
  532. if( !curr_fp->GetFPID().GetLibItemName().empty() ) // Can happen with old boards.
  533. pi->FootprintSave( libPath, curr_fp );
  534. }
  535. catch( const IO_ERROR& ioe )
  536. {
  537. DisplayError( this, ioe.What() );
  538. }
  539. }
  540. }
  541. }
  542. bool FOOTPRINT_EDIT_FRAME::SaveFootprint( MODULE* aModule )
  543. {
  544. if( !aModule ) // Happen if no footprint loaded
  545. return false;
  546. wxString libraryName = aModule->GetFPID().GetLibNickname();
  547. wxString footprintName = aModule->GetFPID().GetLibItemName();
  548. bool nameChanged = m_footprintNameWhenLoaded != footprintName;
  549. if( aModule->GetLink() != niluuid )
  550. {
  551. if( SaveFootprintToBoard( false ) )
  552. {
  553. m_footprintNameWhenLoaded = footprintName;
  554. return true;
  555. }
  556. else
  557. return false;
  558. }
  559. else if( libraryName.IsEmpty() || footprintName.IsEmpty() )
  560. {
  561. if( SaveFootprintAs( aModule ) )
  562. {
  563. m_footprintNameWhenLoaded = footprintName;
  564. SyncLibraryTree( true );
  565. return true;
  566. }
  567. else
  568. return false;
  569. }
  570. FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs();
  571. // Legacy libraries are readable, but modifying legacy format is not allowed
  572. // So prompt the user if he try to add/replace a footprint in a legacy lib
  573. wxString libfullname = tbl->FindRow( libraryName )->GetFullURI();
  574. if( IO_MGR::GuessPluginTypeFromLibPath( libfullname ) == IO_MGR::LEGACY )
  575. {
  576. DisplayInfoMessage( this, INFO_LEGACY_LIB_WARN_EDIT );
  577. return false;
  578. }
  579. if( nameChanged )
  580. {
  581. LIB_ID oldFPID( libraryName, m_footprintNameWhenLoaded );
  582. DeleteModuleFromLibrary( oldFPID, false );
  583. }
  584. if( !SaveFootprintInLibrary( aModule, libraryName ) )
  585. return false;
  586. if( nameChanged )
  587. {
  588. m_footprintNameWhenLoaded = footprintName;
  589. SyncLibraryTree( true );
  590. }
  591. return true;
  592. }
  593. bool FOOTPRINT_EDIT_FRAME::SaveFootprintInLibrary( MODULE* aModule, const wxString& aLibraryName )
  594. {
  595. try
  596. {
  597. aModule->SetFPID( LIB_ID( wxEmptyString, aModule->GetFPID().GetLibItemName() ) );
  598. Prj().PcbFootprintLibs()->FootprintSave( aLibraryName, aModule );
  599. aModule->SetFPID( LIB_ID( aLibraryName, aModule->GetFPID().GetLibItemName() ) );
  600. return true;
  601. }
  602. catch( const IO_ERROR& ioe )
  603. {
  604. DisplayError( this, ioe.What() );
  605. aModule->SetFPID( LIB_ID( aLibraryName, aModule->GetFPID().GetLibItemName() ) );
  606. return false;
  607. }
  608. }
  609. bool FOOTPRINT_EDIT_FRAME::SaveFootprintToBoard( bool aAddNew )
  610. {
  611. // update module in the current board,
  612. // not just add it to the board with total disregard for the netlist...
  613. PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB_EDITOR, false );
  614. if( pcbframe == NULL ) // happens when the board editor is not active (or closed)
  615. {
  616. ShowInfoBarError( _( "No board currently open." ) );
  617. return false;
  618. }
  619. BOARD* mainpcb = pcbframe->GetBoard();
  620. MODULE* source_module = NULL;
  621. MODULE* module_in_edit = GetBoard()->GetFirstModule();
  622. // Search the old module (source) if exists
  623. // Because this source could be deleted when editing the main board...
  624. if( module_in_edit->GetLink() != niluuid ) // this is not a new module ...
  625. {
  626. source_module = nullptr;
  627. for( MODULE* mod : mainpcb->Modules() )
  628. {
  629. if( module_in_edit->GetLink() == mod->m_Uuid )
  630. {
  631. source_module = mod;
  632. break;
  633. }
  634. }
  635. }
  636. if( !aAddNew && source_module == NULL ) // source not found
  637. {
  638. DisplayError( this, _( "Unable to find the footprint on the main board.\nCannot save." ) );
  639. return false;
  640. }
  641. m_toolManager->RunAction( PCB_ACTIONS::selectionClear, true );
  642. pcbframe->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true );
  643. BOARD_COMMIT commit( pcbframe );
  644. // Create the "new" module
  645. MODULE* newmodule = new MODULE( *module_in_edit );
  646. const_cast<KIID&>( newmodule->m_Uuid ) = KIID();
  647. newmodule->SetParent( mainpcb );
  648. newmodule->SetLink( niluuid );
  649. if( source_module ) // this is an update command
  650. {
  651. // In the main board the new module replaces the old module (pos, orient, ref, value,
  652. // connections and properties are kept) and the source_module (old module) is deleted
  653. pcbframe->Exchange_Module( source_module, newmodule, commit );
  654. const_cast<KIID&>( newmodule->m_Uuid ) = module_in_edit->GetLink();
  655. commit.Push( wxT( "Update module" ) );
  656. }
  657. else // This is an insert command
  658. {
  659. KIGFX::VIEW_CONTROLS* viewControls = pcbframe->GetCanvas()->GetViewControls();
  660. VECTOR2D cursorPos = viewControls->GetCursorPosition();
  661. commit.Add( newmodule );
  662. viewControls->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false );
  663. pcbframe->PlaceModule( newmodule );
  664. newmodule->SetPosition( wxPoint( 0, 0 ) );
  665. viewControls->SetCrossHairCursorPosition( cursorPos, false );
  666. const_cast<KIID&>( newmodule->m_Uuid ) = KIID();
  667. commit.Push( wxT( "Insert module" ) );
  668. pcbframe->Raise();
  669. pcbframe->GetToolManager()->RunAction( PCB_ACTIONS::placeModule, true, newmodule );
  670. }
  671. newmodule->ClearFlags();
  672. return true;
  673. }
  674. bool FOOTPRINT_EDIT_FRAME::SaveFootprintAs( MODULE* aModule )
  675. {
  676. if( aModule == NULL )
  677. return false;
  678. FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs();
  679. SetMsgPanel( aModule );
  680. wxString libraryName = aModule->GetFPID().GetLibNickname();
  681. wxString footprintName = aModule->GetFPID().GetLibItemName();
  682. bool updateValue = ( aModule->GetValue() == footprintName );
  683. wxArrayString headers;
  684. std::vector<wxArrayString> itemsToDisplay;
  685. std::vector<wxString> nicknames = tbl->GetLogicalLibs();
  686. headers.Add( _( "Nickname" ) );
  687. headers.Add( _( "Description" ) );
  688. for( const wxString& nickname : nicknames )
  689. {
  690. wxArrayString item;
  691. item.Add( nickname );
  692. item.Add( tbl->GetDescription( nickname ) );
  693. itemsToDisplay.push_back( item );
  694. }
  695. EDA_LIST_DIALOG dlg( this, _( "Save Footprint" ), headers, itemsToDisplay, libraryName );
  696. dlg.SetListLabel( _( "Save in library:" ) );
  697. dlg.SetOKLabel( _( "Save" ) );
  698. wxBoxSizer* bNameSizer = new wxBoxSizer( wxHORIZONTAL );
  699. wxStaticText* label = new wxStaticText( &dlg, wxID_ANY, _( "Name:" ),
  700. wxDefaultPosition, wxDefaultSize, 0 );
  701. bNameSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 );
  702. wxTextCtrl* nameTextCtrl = new wxTextCtrl( &dlg, wxID_ANY, footprintName,
  703. wxDefaultPosition, wxDefaultSize, 0 );
  704. bNameSizer->Add( nameTextCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
  705. wxTextValidator nameValidator( wxFILTER_EXCLUDE_CHAR_LIST );
  706. nameValidator.SetCharExcludes( MODULE::StringLibNameInvalidChars( false ) );
  707. nameTextCtrl->SetValidator( nameValidator );
  708. wxSizer* mainSizer = dlg.GetSizer();
  709. mainSizer->Prepend( bNameSizer, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5 );
  710. // Move nameTextCtrl to the head of the tab-order
  711. if( dlg.GetChildren().DeleteObject( nameTextCtrl ) )
  712. dlg.GetChildren().Insert( nameTextCtrl );
  713. dlg.SetInitialFocus( nameTextCtrl );
  714. dlg.Layout();
  715. mainSizer->Fit( &dlg );
  716. if( dlg.ShowModal() != wxID_OK )
  717. return false; // canceled by user
  718. libraryName = dlg.GetTextSelection();
  719. if( libraryName.IsEmpty() )
  720. {
  721. DisplayError( NULL, _( "No library specified. Footprint could not be saved." ) );
  722. return false;
  723. }
  724. footprintName = nameTextCtrl->GetValue();
  725. footprintName.Trim( true );
  726. footprintName.Trim( false );
  727. if( footprintName.IsEmpty() )
  728. {
  729. DisplayError( NULL, _( "No footprint name specified. Footprint could not be saved." ) );
  730. return false;
  731. }
  732. aModule->SetFPID( LIB_ID( libraryName, footprintName ) );
  733. if( updateValue )
  734. aModule->SetValue( footprintName );
  735. // Legacy libraries are readable, but modifying legacy format is not allowed
  736. // So prompt the user if he try to add/replace a footprint in a legacy lib
  737. wxString libfullname = Prj().PcbFootprintLibs()->FindRow( libraryName )->GetFullURI();
  738. IO_MGR::PCB_FILE_T piType = IO_MGR::GuessPluginTypeFromLibPath( libfullname );
  739. if( piType == IO_MGR::LEGACY )
  740. {
  741. DisplayInfoMessage( this, INFO_LEGACY_LIB_WARN_EDIT );
  742. return false;
  743. }
  744. bool module_exists = tbl->FootprintExists( libraryName, footprintName );
  745. if( module_exists )
  746. {
  747. wxString msg = wxString::Format( _( "Footprint %s already exists in %s." ),
  748. footprintName,
  749. libraryName );
  750. KIDIALOG chkdlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
  751. chkdlg.SetOKLabel( _( "Overwrite" ) );
  752. if( chkdlg.ShowModal() == wxID_CANCEL )
  753. return false;
  754. }
  755. if( !SaveFootprintInLibrary( aModule, libraryName ) )
  756. return false;
  757. // Once saved-as a board footprint is no longer a board footprint
  758. aModule->SetLink( niluuid );
  759. wxString fmt = module_exists ? _( "Component \"%s\" replaced in \"%s\"" ) :
  760. _( "Component \"%s\" added in \"%s\"" );
  761. wxString msg = wxString::Format( fmt, footprintName.GetData(), libraryName.GetData() );
  762. SetStatusText( msg );
  763. updateTitle();
  764. ReCreateHToolbar();
  765. return true;
  766. }
  767. bool FOOTPRINT_EDIT_FRAME::RevertFootprint()
  768. {
  769. if( GetScreen()->IsModify() && m_revertModule )
  770. {
  771. wxString msg = wxString::Format( _( "Revert \"%s\" to last version saved?" ),
  772. GetChars( GetLoadedFPID().GetLibItemName() ) );
  773. if( ConfirmRevertDialog( this, msg ) )
  774. {
  775. Clear_Pcb( false );
  776. AddModuleToBoard( (MODULE*) m_revertModule->Clone() );
  777. Zoom_Automatique( false );
  778. Update3DView( true );
  779. ClearUndoRedoList();
  780. GetScreen()->ClrModify();
  781. updateView();
  782. GetCanvas()->Refresh();
  783. return true;
  784. }
  785. }
  786. return false;
  787. }
  788. MODULE* PCB_BASE_FRAME::CreateNewModule( const wxString& aModuleName )
  789. {
  790. wxString moduleName = aModuleName;
  791. // Ask for the new module name
  792. if( moduleName.IsEmpty() )
  793. {
  794. WX_TEXT_ENTRY_DIALOG dlg( this, _( "Enter footprint name:" ), _( "New Footprint" ),
  795. moduleName );
  796. dlg.SetTextValidator( MODULE_NAME_CHAR_VALIDATOR( &moduleName ) );
  797. if( dlg.ShowModal() != wxID_OK )
  798. return NULL; //Aborted by user
  799. }
  800. moduleName.Trim( true );
  801. moduleName.Trim( false );
  802. if( moduleName.IsEmpty() )
  803. {
  804. DisplayInfoMessage( this, _( "No footprint name defined." ) );
  805. return NULL;
  806. }
  807. // Creates the new module and add it to the head of the linked list of modules
  808. MODULE* module = new MODULE( GetBoard() );
  809. // Update parameters: timestamp ...
  810. module->SetLastEditTime();
  811. // Update its name in lib
  812. module->SetFPID( LIB_ID( wxEmptyString, moduleName ) );
  813. PCB_LAYER_ID txt_layer;
  814. wxPoint default_pos;
  815. BOARD_DESIGN_SETTINGS& settings = GetDesignSettings();
  816. module->Reference().SetText( settings.m_DefaultFPTextItems[0].m_Text );
  817. module->Reference().SetVisible( settings.m_DefaultFPTextItems[0].m_Visible );
  818. txt_layer = (PCB_LAYER_ID) settings.m_DefaultFPTextItems[0].m_Layer;
  819. module->Reference().SetLayer( txt_layer );
  820. default_pos.y -= settings.GetTextSize( txt_layer ).y / 2;
  821. module->Reference().SetPosition( default_pos );
  822. default_pos.y += settings.GetTextSize( txt_layer ).y;
  823. module->Value().SetText( settings.m_DefaultFPTextItems[1].m_Text );
  824. module->Value().SetVisible( settings.m_DefaultFPTextItems[1].m_Visible );
  825. txt_layer = (PCB_LAYER_ID) settings.m_DefaultFPTextItems[1].m_Layer;
  826. module->Value().SetLayer( txt_layer );
  827. default_pos.y += settings.GetTextSize( txt_layer ).y / 2;
  828. module->Value().SetPosition( default_pos );
  829. default_pos.y += settings.GetTextSize( txt_layer ).y;
  830. for( size_t i = 2; i < settings.m_DefaultFPTextItems.size(); ++i )
  831. {
  832. TEXTE_MODULE* textItem = new TEXTE_MODULE( module );
  833. textItem->SetText( settings.m_DefaultFPTextItems[i].m_Text );
  834. textItem->SetVisible( settings.m_DefaultFPTextItems[i].m_Visible );
  835. txt_layer = (PCB_LAYER_ID) settings.m_DefaultFPTextItems[i].m_Layer;
  836. textItem->SetLayer( txt_layer );
  837. default_pos.y += settings.GetTextSize( txt_layer ).y / 2;
  838. textItem->SetPosition( default_pos );
  839. default_pos.y += settings.GetTextSize( txt_layer ).y;
  840. module->GraphicalItems().push_back( textItem );
  841. }
  842. if( module->GetReference().IsEmpty() )
  843. module->SetReference( moduleName );
  844. if( module->GetValue().IsEmpty() )
  845. module->SetValue( moduleName );
  846. module->RunOnChildren(
  847. [&] ( BOARD_ITEM* aChild )
  848. {
  849. if( aChild->Type() == PCB_MODULE_TEXT_T )
  850. {
  851. TEXTE_MODULE* textItem = static_cast<TEXTE_MODULE*>( aChild );
  852. PCB_LAYER_ID layer = textItem->GetLayer();
  853. textItem->SetTextThickness( settings.GetTextThickness( layer ) );
  854. textItem->SetTextSize( settings.GetTextSize( layer ) );
  855. textItem->SetItalic( settings.GetTextItalic( layer ) );
  856. textItem->SetKeepUpright( settings.GetTextUpright( layer ) );
  857. }
  858. } );
  859. SetMsgPanel( module );
  860. return module;
  861. }
  862. wxString PCB_BASE_FRAME::SelectLibrary( const wxString& aNicknameExisting )
  863. {
  864. wxArrayString headers;
  865. headers.Add( _( "Nickname" ) );
  866. headers.Add( _( "Description" ) );
  867. FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs();
  868. std::vector< wxArrayString > itemsToDisplay;
  869. std::vector< wxString > nicknames = fptbl->GetLogicalLibs();
  870. for( const wxString& nickname : nicknames )
  871. {
  872. wxArrayString item;
  873. item.Add( nickname );
  874. item.Add( fptbl->GetDescription( nickname ) );
  875. itemsToDisplay.push_back( item );
  876. }
  877. EDA_LIST_DIALOG dlg( this, _( "Select Library" ), headers, itemsToDisplay, aNicknameExisting );
  878. if( dlg.ShowModal() != wxID_OK )
  879. return wxEmptyString;
  880. return dlg.GetTextSelection();
  881. }