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.

1036 lines
31 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
* 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
* 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-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. /**
  24. * @file librairi.cpp
  25. * @brief Manage module (footprint) libraries.
  26. */
  27. #include <wx/ffile.h>
  28. #include <wx/stdpaths.h>
  29. #include <fctsys.h>
  30. #include <pgm_base.h>
  31. #include <kiface_i.h>
  32. #include <class_drawpanel.h>
  33. #include <confirm.h>
  34. #include <kicad_string.h>
  35. #include <gestfich.h>
  36. #include <pcb_edit_frame.h>
  37. #include <dialog_helpers.h>
  38. #include <filter_reader.h>
  39. #include <macros.h>
  40. #include <fp_lib_table.h>
  41. #include <validators.h>
  42. #include <dialog_text_entry.h>
  43. #include <tool/tool_manager.h>
  44. #include <tools/pcb_actions.h>
  45. #include <class_board.h>
  46. #include <class_module.h>
  47. #include <board_commit.h>
  48. #include <pcbnew.h>
  49. #include <footprint_edit_frame.h>
  50. #include <wildcards_and_files_ext.h>
  51. #include <kicad_plugin.h>
  52. #include <legacy_plugin.h>
  53. // unique, "file local" translations:
  54. #define FMT_OK_DELETE _( "OK to delete footprint \"%s\" in library \"%s\"" )
  55. #define FMT_IMPORT_MODULE _( "Import Footprint" )
  56. #define FMT_FILE_NOT_FOUND _( "File \"%s\" not found" )
  57. #define FMT_NOT_MODULE _( "Not a footprint file" )
  58. #define FMT_MOD_NOT_FOUND _( "Unable to find or load footprint \"%s\" from lib path \"%s\"" )
  59. #define FMT_LIB_READ_ONLY _( "Library \"%s\" is read only, not writable" )
  60. #define FMT_EXPORT_MODULE _( "Export Footprint" )
  61. #define FMT_SAVE_MODULE _( "Save Footprint" )
  62. #define FMT_MOD_REF _( "Enter footprint name:" )
  63. #define FMT_EXPORTED _( "Footprint exported to file \"%s\"" )
  64. #define FMT_MOD_DELETED _( "Footprint \"%s\" deleted from library \"%s\"" )
  65. #define FMT_MOD_CREATE _( "New Footprint" )
  66. #define FMT_NO_REF_ABORTED _( "No footprint name defined." )
  67. #define FMT_SELECT_LIB _( "Select Library" )
  68. static const wxString INFO_LEGACY_LIB_WARN_EDIT(
  69. _( "Writing/modifying legacy libraries (.mod files) is not allowed\n"\
  70. "Please save the current library to the new .pretty format\n"\
  71. "and update your footprint lib table\n"\
  72. "to save your footprint (a .kicad_mod file) in the .pretty library folder" ) );
  73. static const wxString INFO_LEGACY_LIB_WARN_DELETE(
  74. _( "Modifying legacy libraries (.mod files) is not allowed\n"\
  75. "Please save the current library under the new .pretty format\n"\
  76. "and update your footprint lib table\n"\
  77. "before deleting a footprint" ) );
  78. #define EXPORT_IMPORT_LASTPATH_KEY wxT( "import_last_path" )
  79. /**
  80. * Prompt the user for a module file to open.
  81. * @param aParent - parent window for the dialog
  82. * @param aLastPath - last opened path
  83. */
  84. static wxFileName getFootprintFilenameFromUser( wxWindow* aParent, const wxString& aLastPath )
  85. {
  86. static int lastFilterIndex = 0; // To store the last choice during a session.
  87. wxString wildCard;
  88. wildCard << KiCadFootprintLibFileWildcard() << wxChar( '|' )
  89. << ModLegacyExportFileWildcard() << wxChar( '|' )
  90. << GedaPcbFootprintLibFileWildcard();
  91. wxFileDialog dlg( aParent, FMT_IMPORT_MODULE, aLastPath, wxEmptyString, wildCard,
  92. wxFD_OPEN | wxFD_FILE_MUST_EXIST );
  93. dlg.SetFilterIndex( lastFilterIndex );
  94. if( dlg.ShowModal() == wxID_CANCEL )
  95. return wxFileName();
  96. lastFilterIndex = dlg.GetFilterIndex();
  97. return wxFileName( dlg.GetPath() );
  98. }
  99. /**
  100. * Read a file to detect the type.
  101. * @param aFile - open file to be read. File pointer will be closed.
  102. * @param aFileName - file name to be read
  103. * @param aName - wxString to receive the module name iff type is LEGACY
  104. */
  105. static IO_MGR::PCB_FILE_T detect_file_type( FILE* aFile, const wxFileName& aFileName,
  106. wxString* aName )
  107. {
  108. FILE_LINE_READER freader( aFile, aFileName.GetFullPath() );
  109. WHITESPACE_FILTER_READER reader( freader );
  110. IO_MGR::PCB_FILE_T file_type;
  111. wxASSERT( aName );
  112. reader.ReadLine();
  113. char* line = reader.Line();
  114. if( !strncasecmp( line, "(module", strlen( "(module" ) ) )
  115. {
  116. file_type = IO_MGR::KICAD_SEXP;
  117. *aName = aFileName.GetName();
  118. }
  119. else if( !strncasecmp( line, FOOTPRINT_LIBRARY_HEADER, FOOTPRINT_LIBRARY_HEADER_CNT ) )
  120. {
  121. file_type = IO_MGR::LEGACY;
  122. while( reader.ReadLine() )
  123. {
  124. if( !strncasecmp( line, "$MODULE", strlen( "$MODULE" ) ) )
  125. {
  126. *aName = FROM_UTF8( StrPurge( line + strlen( "$MODULE" ) ) );
  127. break;
  128. }
  129. }
  130. }
  131. else if( !strncasecmp( line, "Element", strlen( "Element" ) ) )
  132. {
  133. file_type = IO_MGR::GEDA_PCB;
  134. *aName = aFileName.GetName();
  135. }
  136. else
  137. {
  138. file_type = IO_MGR::FILE_TYPE_NONE;
  139. }
  140. return file_type;
  141. }
  142. /**
  143. * Parse a footprint using a PLUGIN.
  144. * @param aFileName - file name to parse
  145. * @param aFileType - type of the file
  146. * @param aName - name of the footprint
  147. */
  148. static MODULE* parse_module_with_plugin(
  149. const wxFileName& aFileName, IO_MGR::PCB_FILE_T aFileType,
  150. const wxString& aName )
  151. {
  152. wxString path;
  153. switch( aFileType )
  154. {
  155. case IO_MGR::GEDA_PCB:
  156. path = aFileName.GetPath();
  157. break;
  158. case IO_MGR::LEGACY:
  159. path = aFileName.GetFullPath();
  160. break;
  161. default:
  162. wxFAIL_MSG( wxT( "unexpected IO_MGR::PCB_FILE_T" ) );
  163. }
  164. PLUGIN::RELEASER pi( IO_MGR::PluginFind( aFileType ) );
  165. return pi->FootprintLoad( path, aName );
  166. }
  167. /**
  168. * Parse a KICAD footprint.
  169. * @param aFileName - file name to parse
  170. */
  171. static MODULE* parse_module_kicad( const wxFileName& aFileName )
  172. {
  173. wxString fcontents;
  174. PCB_IO pcb_io;
  175. wxFFile f( aFileName.GetFullPath() );
  176. if( !f.IsOpened() )
  177. return NULL;
  178. f.ReadAll( &fcontents );
  179. return dynamic_cast<MODULE*>( pcb_io.Parse( fcontents ) );
  180. }
  181. /**
  182. * Try to load a footprint, returning NULL if the file couldn't be accessed.
  183. * @param aFileName - file name to load
  184. * @param aFileType - type of the file to load
  185. * @param aName - footprint name
  186. */
  187. MODULE* try_load_footprint( const wxFileName& aFileName, IO_MGR::PCB_FILE_T aFileType,
  188. const wxString& aName )
  189. {
  190. MODULE* module;
  191. switch( aFileType )
  192. {
  193. case IO_MGR::GEDA_PCB:
  194. case IO_MGR::LEGACY:
  195. module = parse_module_with_plugin( aFileName, aFileType, aName );
  196. break;
  197. case IO_MGR::KICAD_SEXP:
  198. module = parse_module_kicad( aFileName );
  199. break;
  200. default:
  201. wxFAIL_MSG( wxT( "unexpected IO_MGR::PCB_FILE_T" ) );
  202. module = NULL;
  203. }
  204. return module;
  205. }
  206. MODULE* FOOTPRINT_EDIT_FRAME::Import_Module( const wxString& aName )
  207. {
  208. wxString lastOpenedPathForLoading = m_mruPath;
  209. wxConfigBase* cfg = Kiface().KifaceSettings();
  210. if( cfg )
  211. cfg->Read( EXPORT_IMPORT_LASTPATH_KEY, &lastOpenedPathForLoading );
  212. wxFileName fn;
  213. if( aName != wxT("") )
  214. fn = aName;
  215. else
  216. fn = getFootprintFilenameFromUser( this, lastOpenedPathForLoading );
  217. if( !fn.IsOk() )
  218. return NULL;
  219. FILE* fp = wxFopen( fn.GetFullPath(), wxT( "rt" ) );
  220. if( !fp )
  221. {
  222. wxString msg = wxString::Format( FMT_FILE_NOT_FOUND, GetChars( fn.GetFullPath() ) );
  223. DisplayError( this, msg );
  224. return NULL;
  225. }
  226. if( cfg ) // Save file path
  227. {
  228. lastOpenedPathForLoading = fn.GetPath();
  229. cfg->Write( EXPORT_IMPORT_LASTPATH_KEY, lastOpenedPathForLoading );
  230. }
  231. wxString moduleName;
  232. IO_MGR::PCB_FILE_T fileType = detect_file_type( fp, fn.GetFullPath(), &moduleName );
  233. if( fileType == IO_MGR::FILE_TYPE_NONE )
  234. {
  235. DisplayError( this, FMT_NOT_MODULE );
  236. return NULL;
  237. }
  238. MODULE* module = NULL;
  239. try
  240. {
  241. module = try_load_footprint( fn, fileType, moduleName );
  242. if( !module )
  243. {
  244. wxString msg = wxString::Format(
  245. FMT_MOD_NOT_FOUND, GetChars( moduleName ), GetChars( fn.GetFullPath() ) );
  246. DisplayError( this, msg );
  247. return NULL;
  248. }
  249. }
  250. catch( const IO_ERROR& ioe )
  251. {
  252. DisplayError( this, ioe.What() );
  253. // if the footprint is not loaded, exit.
  254. // However, even if an error happens, it can be loaded, because in KICAD and GPCB format,
  255. // a fp library is a set of separate files, and the error(s) are not necessary when
  256. // reading the selected file
  257. if( !module )
  258. return NULL;
  259. }
  260. LIB_ID fpid;
  261. fpid.SetLibItemName( module->GetFPID().GetLibItemName() );
  262. module->SetFPID( fpid );
  263. // Insert footprint in list
  264. GetBoard()->Add( module );
  265. // Display info :
  266. SetMsgPanel( module );
  267. PlaceModule( module, NULL );
  268. if( IsGalCanvasActive() )
  269. module->SetPosition( wxPoint( 0, 0 ) );
  270. GetBoard()->m_Status_Pcb = 0;
  271. GetBoard()->BuildListOfNets();
  272. updateView();
  273. return module;
  274. }
  275. void FOOTPRINT_EDIT_FRAME::Export_Module( MODULE* aModule )
  276. {
  277. wxFileName fn;
  278. wxConfigBase* cfg = Kiface().KifaceSettings();
  279. if( !aModule )
  280. return;
  281. fn.SetName( aModule->GetFPID().GetLibItemName() );
  282. wxString wildcard = KiCadFootprintLibFileWildcard();
  283. fn.SetExt( KiCadFootprintFileExtension );
  284. if( cfg )
  285. {
  286. wxString path;
  287. cfg->Read( EXPORT_IMPORT_LASTPATH_KEY, &path, m_mruPath );
  288. fn.SetPath( path );
  289. }
  290. wxFileDialog dlg( this, FMT_EXPORT_MODULE, fn.GetPath(), fn.GetFullName(),
  291. wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
  292. if( dlg.ShowModal() == wxID_CANCEL )
  293. return;
  294. fn = dlg.GetPath();
  295. if( cfg ) // Save file path
  296. {
  297. cfg->Write( EXPORT_IMPORT_LASTPATH_KEY, fn.GetPath() );
  298. }
  299. try
  300. {
  301. // Export as *.kicad_pcb format, using a strategy which is specifically chosen
  302. // as an example on how it could also be used to send it to the system clipboard.
  303. PCB_IO pcb_io( CTL_FOR_LIBRARY );
  304. /* This module should *already* be "normalized" in a way such that
  305. orientation is zero, etc., since it came from module editor.
  306. module->SetTimeStamp( 0 );
  307. module->SetParent( 0 );
  308. module->SetOrientation( 0 );
  309. */
  310. pcb_io.Format( aModule );
  311. FILE* fp = wxFopen( dlg.GetPath(), wxT( "wt" ) );
  312. if( fp == NULL )
  313. {
  314. wxMessageBox( wxString::Format(
  315. _( "Unable to create or write file \"%s\"" ),
  316. GetChars( dlg.GetPath() ) ) );
  317. return;
  318. }
  319. fprintf( fp, "%s", pcb_io.GetStringOutput( false ).c_str() );
  320. fclose( fp );
  321. }
  322. catch( const IO_ERROR& ioe )
  323. {
  324. DisplayError( this, ioe.What() );
  325. return;
  326. }
  327. wxString msg = wxString::Format( FMT_EXPORTED, GetChars( dlg.GetPath() ) );
  328. DisplayInfoMessage( this, msg );
  329. }
  330. wxString PCB_BASE_EDIT_FRAME::CreateNewLibrary(const wxString& aLibName )
  331. {
  332. // Kicad cannot write legacy format libraries, only .pretty new format
  333. // because the legacy format cannot handle current features.
  334. // The footprint library is actually a directory
  335. wxString initialPath = wxPathOnly( Prj().GetProjectFullName() );
  336. wxFileName fn;
  337. bool saveInGlobalTable = false, saveInProjectTable = false;
  338. if( aLibName.IsEmpty() )
  339. {
  340. fn = initialPath;
  341. if( !LibraryFileBrowser( false, fn, KiCadFootprintLibPathWildcard(), KiCadFootprintLibPathExtension ) )
  342. return wxEmptyString;
  343. wxArrayString libTableNames;
  344. libTableNames.Add( _( "Global" ) );
  345. libTableNames.Add( _( "Project" ) );
  346. switch( SelectSingleOption( this, _( "Select Library Table" ),
  347. _( "Choose the Library Table to add the library to:" ),
  348. libTableNames ) )
  349. {
  350. case 0: saveInGlobalTable = true; break;
  351. case 1: saveInProjectTable = true; break;
  352. default: return wxEmptyString;
  353. }
  354. }
  355. else
  356. {
  357. fn = aLibName;
  358. if( !fn.IsAbsolute() )
  359. {
  360. fn.SetName( aLibName );
  361. fn.MakeAbsolute( initialPath );
  362. }
  363. // Enforce the .pretty extension:
  364. fn.SetExt( KiCadFootprintLibPathExtension );
  365. }
  366. // We can save fp libs only using IO_MGR::KICAD_SEXP format (.pretty libraries)
  367. IO_MGR::PCB_FILE_T piType = IO_MGR::KICAD_SEXP;
  368. wxString libPath = fn.GetFullPath();
  369. try
  370. {
  371. PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) );
  372. bool writable = false;
  373. bool exists = false;
  374. try
  375. {
  376. writable = pi->IsFootprintLibWritable( libPath );
  377. exists = true; // no exception was thrown, lib must exist.
  378. }
  379. catch( const IO_ERROR& )
  380. { }
  381. if( exists )
  382. {
  383. if( !writable )
  384. {
  385. wxString msg = wxString::Format( FMT_LIB_READ_ONLY, libPath );
  386. DisplayError( this, msg );
  387. return wxEmptyString;
  388. }
  389. else
  390. {
  391. wxString msg = wxString::Format( _( "Library %s already exists." ), libPath );
  392. KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
  393. dlg.SetOKLabel( _( "Overwrite" ) );
  394. dlg.DoNotShowCheckbox();
  395. if( dlg.ShowModal() == wxID_CANCEL )
  396. return wxEmptyString;
  397. pi->FootprintLibDelete( libPath );
  398. }
  399. }
  400. pi->FootprintLibCreate( libPath );
  401. if( saveInGlobalTable )
  402. {
  403. auto row = new FP_LIB_TABLE_ROW( fn.GetName(), libPath, wxT( "KiCad" ), wxEmptyString );
  404. GFootprintTable.InsertRow( row );
  405. GFootprintTable.Save( FP_LIB_TABLE::GetGlobalTableFileName() );
  406. }
  407. else if( saveInProjectTable )
  408. {
  409. auto row = new FP_LIB_TABLE_ROW( fn.GetName(), libPath, wxT( "KiCad" ), wxEmptyString );
  410. Prj().PcbFootprintLibs()->InsertRow( row );
  411. Prj().PcbFootprintLibs()->Save( Prj().FootprintLibTblName() );
  412. }
  413. }
  414. catch( const IO_ERROR& ioe )
  415. {
  416. DisplayError( this, ioe.What() );
  417. return wxEmptyString;
  418. }
  419. return libPath;
  420. }
  421. bool FOOTPRINT_EDIT_FRAME::DeleteModuleFromLibrary( MODULE* aModule )
  422. {
  423. if( !aModule )
  424. return false;
  425. LIB_ID fpid = aModule->GetFPID();
  426. if( !fpid.IsValid() )
  427. return false;
  428. wxString nickname = fpid.GetLibNickname();
  429. wxString fpname = fpid.GetLibItemName();
  430. // Legacy libraries are readable, but modifying legacy format is not allowed
  431. // So prompt the user if he try to delete a footprint from a legacy lib
  432. wxString libfullname = Prj().PcbFootprintLibs()->FindRow( nickname )->GetFullURI();
  433. if( IO_MGR::GuessPluginTypeFromLibPath( libfullname ) == IO_MGR::LEGACY )
  434. {
  435. DisplayInfoMessage( this, INFO_LEGACY_LIB_WARN_DELETE );
  436. return false;
  437. }
  438. if( !Prj().PcbFootprintLibs()->IsFootprintLibWritable( nickname ) )
  439. {
  440. wxString msg = wxString::Format( _( "Library \"%s\" is read only" ), nickname );
  441. DisplayError( this, msg );
  442. return false;
  443. }
  444. // Confirmation
  445. wxString msg = wxString::Format( FMT_OK_DELETE, fpname.GetData(), nickname.GetData() );
  446. if( !IsOK( this, msg ) )
  447. return false;
  448. try
  449. {
  450. Prj().PcbFootprintLibs()->FootprintDelete( nickname, fpname );
  451. }
  452. catch( const IO_ERROR& ioe )
  453. {
  454. DisplayError( this, ioe.What() );
  455. return false;
  456. }
  457. msg.Printf( FMT_MOD_DELETED, fpname.GetData(), nickname.GetData() );
  458. SetStatusText( msg );
  459. return true;
  460. }
  461. void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aStoreInNewLib, const wxString& aLibName,
  462. wxString* aLibPath )
  463. {
  464. if( GetBoard()->m_Modules == NULL )
  465. {
  466. DisplayInfoMessage( this, _( "No footprints to archive!" ) );
  467. return;
  468. }
  469. wxString footprintName;
  470. if( !aStoreInNewLib )
  471. {
  472. // The footprints are saved in an existing .pretty library in the fp lib table
  473. PROJECT& prj = Prj();
  474. wxString last_nickname = prj.GetRString( PROJECT::PCB_LIB_NICKNAME );
  475. wxString nickname = SelectLibrary( last_nickname );
  476. if( !nickname ) // Aborted
  477. return;
  478. prj.SetRString( PROJECT::PCB_LIB_NICKNAME, nickname );
  479. try
  480. {
  481. FP_LIB_TABLE* tbl = prj.PcbFootprintLibs();
  482. for( MODULE* curr_fp = GetBoard()->m_Modules; curr_fp; curr_fp = curr_fp->Next() )
  483. {
  484. if( !curr_fp->GetFPID().GetLibItemName().empty() ) // Can happen with old boards.
  485. tbl->FootprintSave( nickname, curr_fp, false );
  486. }
  487. }
  488. catch( const IO_ERROR& ioe )
  489. {
  490. DisplayError( this, ioe.What() );
  491. }
  492. }
  493. else
  494. {
  495. // The footprints are saved in a new .pretty library.
  496. // If this library already exists, all previous footprints will be deleted
  497. wxString libPath = CreateNewLibrary( aLibName );
  498. if( libPath.IsEmpty() ) // Aborted
  499. return;
  500. if( aLibPath ) *aLibPath = libPath;
  501. IO_MGR::PCB_FILE_T piType = IO_MGR::KICAD_SEXP;
  502. PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) );
  503. for( MODULE* curr_fp = GetBoard()->m_Modules; curr_fp; curr_fp = curr_fp->Next() )
  504. {
  505. try
  506. {
  507. if( !curr_fp->GetFPID().GetLibItemName().empty() ) // Can happen with old boards.
  508. pi->FootprintSave( libPath, curr_fp );
  509. }
  510. catch( const IO_ERROR& ioe )
  511. {
  512. DisplayError( this, ioe.What() );
  513. }
  514. }
  515. }
  516. }
  517. class LIBRARY_NAME_CLEARER
  518. {
  519. MODULE* m_module;
  520. LIB_ID m_savedFPID;
  521. public:
  522. LIBRARY_NAME_CLEARER( MODULE* aModule )
  523. {
  524. m_module = aModule;
  525. m_savedFPID = aModule->GetFPID();
  526. m_module->SetFPID( LIB_ID( wxEmptyString, m_savedFPID.GetLibItemName() ) );
  527. }
  528. ~LIBRARY_NAME_CLEARER()
  529. {
  530. m_module->SetFPID( m_savedFPID );
  531. }
  532. };
  533. bool FOOTPRINT_EDIT_FRAME::SaveFootprint( MODULE* aModule )
  534. {
  535. wxString libraryName = aModule->GetFPID().GetLibNickname();
  536. wxString footprintName = aModule->GetFPID().GetLibItemName();
  537. if( aModule->GetLink() )
  538. {
  539. return SaveFootprintToBoard( false );
  540. }
  541. if( libraryName.IsEmpty() || footprintName.IsEmpty() )
  542. return SaveFootprintAs( aModule );
  543. FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs();
  544. // Legacy libraries are readable, but modifying legacy format is not allowed
  545. // So prompt the user if he try to add/replace a footprint in a legacy lib
  546. wxString libfullname = tbl->FindRow( libraryName )->GetFullURI();
  547. if( IO_MGR::GuessPluginTypeFromLibPath( libfullname ) == IO_MGR::LEGACY )
  548. {
  549. DisplayInfoMessage( this, INFO_LEGACY_LIB_WARN_EDIT );
  550. return false;
  551. }
  552. try
  553. {
  554. MODULE* m = tbl->FootprintLoad( libraryName, footprintName );
  555. delete m;
  556. LIBRARY_NAME_CLEARER temp( aModule );
  557. // this always overwrites any existing footprint, but should yell on its
  558. // own if the library or footprint is not writable.
  559. tbl->FootprintSave( libraryName, aModule );
  560. }
  561. catch( const IO_ERROR& ioe )
  562. {
  563. DisplayError( this, ioe.What() );
  564. return false;
  565. }
  566. return true;
  567. }
  568. bool FOOTPRINT_EDIT_FRAME::SaveFootprintToBoard( bool aAddNew )
  569. {
  570. // update module in the current board,
  571. // not just add it to the board with total disregard for the netlist...
  572. PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB, false );
  573. if( pcbframe == NULL ) // happens when the board editor is not active (or closed)
  574. {
  575. DisplayErrorMessage( this, _("No board currently open." ) );
  576. return false;
  577. }
  578. BOARD* mainpcb = pcbframe->GetBoard();
  579. MODULE* source_module = NULL;
  580. MODULE* module_in_edit = GetBoard()->m_Modules;
  581. // Search the old module (source) if exists
  582. // Because this source could be deleted when editing the main board...
  583. if( module_in_edit->GetLink() ) // this is not a new module ...
  584. {
  585. source_module = mainpcb->m_Modules;
  586. for( ; source_module != NULL; source_module = source_module->Next() )
  587. {
  588. if( module_in_edit->GetLink() == source_module->GetTimeStamp() )
  589. break;
  590. }
  591. }
  592. if( !aAddNew && source_module == NULL ) // source not found
  593. {
  594. DisplayError( this, _( "Unable to find the footprint on the main board.\nCannot save." ) );
  595. return false;
  596. }
  597. if( aAddNew && source_module != NULL )
  598. {
  599. DisplayError( this, _( "Footprint already exists on board." ) );
  600. return false;
  601. }
  602. m_toolManager->RunAction( PCB_ACTIONS::selectionClear, true );
  603. pcbframe->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true );
  604. BOARD_COMMIT commit( pcbframe );
  605. // Create the "new" module
  606. MODULE* newmodule = new MODULE( *module_in_edit );
  607. newmodule->SetParent( mainpcb );
  608. newmodule->SetLink( 0 );
  609. if( source_module ) // this is an update command
  610. {
  611. // In the main board,
  612. // the new module replace the old module (pos, orient, ref, value
  613. // and connexions are kept)
  614. // and the source_module (old module) is deleted
  615. pcbframe->Exchange_Module( source_module, newmodule, commit );
  616. newmodule->SetTimeStamp( module_in_edit->GetLink() );
  617. commit.Push( wxT( "Update module" ) );
  618. }
  619. else // This is an insert command
  620. {
  621. wxPoint cursor_pos = pcbframe->GetCrossHairPosition();
  622. commit.Add( newmodule );
  623. pcbframe->SetCrossHairPosition( wxPoint( 0, 0 ) );
  624. pcbframe->PlaceModule( newmodule, NULL );
  625. newmodule->SetPosition( wxPoint( 0, 0 ) );
  626. pcbframe->SetCrossHairPosition( cursor_pos );
  627. newmodule->SetTimeStamp( GetNewTimeStamp() );
  628. commit.Push( wxT( "Insert module" ) );
  629. }
  630. newmodule->ClearFlags();
  631. pcbframe->SetCurItem( NULL );
  632. // @todo LEGACY should be unnecessary
  633. mainpcb->m_Status_Pcb = 0;
  634. return true;
  635. }
  636. bool FOOTPRINT_EDIT_FRAME::SaveFootprintAs( MODULE* aModule )
  637. {
  638. if( aModule == NULL )
  639. return false;
  640. FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs();
  641. SetMsgPanel( aModule );
  642. wxString libraryName = aModule->GetFPID().GetLibNickname();
  643. wxString footprintName = aModule->GetFPID().GetLibItemName();
  644. bool updateValue = ( aModule->GetValue() == footprintName );
  645. wxArrayString headers;
  646. std::vector<wxArrayString> itemsToDisplay;
  647. std::vector<wxString> nicknames = tbl->GetLogicalLibs();
  648. headers.Add( _( "Nickname" ) );
  649. headers.Add( _( "Description" ) );
  650. for( unsigned i = 0; i < nicknames.size(); i++ )
  651. {
  652. wxArrayString item;
  653. item.Add( nicknames[i] );
  654. item.Add( tbl->GetDescription( nicknames[i] ) );
  655. itemsToDisplay.push_back( item );
  656. }
  657. EDA_LIST_DIALOG dlg( this, FMT_SAVE_MODULE, headers, itemsToDisplay, libraryName,
  658. nullptr, nullptr, /* sort */ false, /* show headers */ false );
  659. dlg.SetListLabel( _( "Save in library:" ) );
  660. dlg.SetOKLabel( _( "Save" ) );
  661. wxBoxSizer* bNameSizer = new wxBoxSizer( wxHORIZONTAL );
  662. wxStaticText* label = new wxStaticText( &dlg, wxID_ANY, _( "Name:" ),
  663. wxDefaultPosition, wxDefaultSize, 0 );
  664. bNameSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 );
  665. wxTextCtrl* nameTextCtrl = new wxTextCtrl( &dlg, wxID_ANY, footprintName,
  666. wxDefaultPosition, wxDefaultSize, 0 );
  667. bNameSizer->Add( nameTextCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
  668. wxTextValidator nameValidator( wxFILTER_EXCLUDE_CHAR_LIST );
  669. nameValidator.SetCharExcludes( MODULE::StringLibNameInvalidChars( false ) );
  670. nameTextCtrl->SetValidator( nameValidator );
  671. wxSizer* mainSizer = dlg.GetSizer();
  672. mainSizer->Prepend( bNameSizer, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5 );
  673. // Move nameTextCtrl to the head of the tab-order
  674. if( dlg.GetChildren().DeleteObject( nameTextCtrl ) )
  675. dlg.GetChildren().Insert( nameTextCtrl );
  676. dlg.SetInitialFocus( nameTextCtrl );
  677. dlg.Layout();
  678. mainSizer->Fit( &dlg );
  679. if( dlg.ShowModal() != wxID_OK )
  680. return false; // canceled by user
  681. libraryName = dlg.GetTextSelection();
  682. if( libraryName.IsEmpty() )
  683. {
  684. DisplayError( NULL, _( "No library specified. Footprint could not be saved." ) );
  685. return false;
  686. }
  687. footprintName = nameTextCtrl->GetValue();
  688. footprintName.Trim( true );
  689. footprintName.Trim( false );
  690. if( footprintName.IsEmpty() )
  691. {
  692. DisplayError( NULL, _( "No footprint name specified. Footprint could not be saved." ) );
  693. return false;
  694. }
  695. aModule->SetFPID( LIB_ID( libraryName, footprintName ) );
  696. if( updateValue )
  697. aModule->SetValue( footprintName );
  698. // Legacy libraries are readable, but modifying legacy format is not allowed
  699. // So prompt the user if he try to add/replace a footprint in a legacy lib
  700. wxString libfullname = Prj().PcbFootprintLibs()->FindRow( libraryName )->GetFullURI();
  701. IO_MGR::PCB_FILE_T piType = IO_MGR::GuessPluginTypeFromLibPath( libfullname );
  702. if( piType == IO_MGR::LEGACY )
  703. {
  704. DisplayInfoMessage( this, INFO_LEGACY_LIB_WARN_EDIT );
  705. return false;
  706. }
  707. bool module_exists = false;
  708. try
  709. {
  710. MODULE* m = tbl->FootprintLoad( libraryName, footprintName );
  711. module_exists = m != nullptr;
  712. delete m;
  713. LIBRARY_NAME_CLEARER temp( aModule );
  714. // this always overwrites any existing footprint, but should yell on its
  715. // own if the library or footprint is not writable.
  716. tbl->FootprintSave( libraryName, aModule );
  717. }
  718. catch( const IO_ERROR& ioe )
  719. {
  720. DisplayError( this, ioe.What() );
  721. return false;
  722. }
  723. wxString fmt = module_exists ? _( "Component \"%s\" replaced in \"%s\"" ) :
  724. _( "Component \"%s\" added in \"%s\"" );
  725. wxString msg = wxString::Format( fmt, footprintName.GetData(), libraryName.GetData() );
  726. SetStatusText( msg );
  727. return true;
  728. }
  729. MODULE* PCB_BASE_FRAME::CreateNewModule( const wxString& aModuleName )
  730. {
  731. // Creates a new footprint at position 0,0 which contains the minimal items:
  732. // the reference and the value.
  733. // Value : initialized to the footprint name.
  734. // put on fab layer (front side)
  735. // Reference : initialized to a default value (REF**).
  736. // put on silkscreen layer (front side)
  737. wxString moduleName = aModuleName;
  738. // Ask for the new module name
  739. if( moduleName.IsEmpty() )
  740. {
  741. WX_TEXT_ENTRY_DIALOG dlg( this, FMT_MOD_REF, FMT_MOD_CREATE, moduleName );
  742. dlg.SetTextValidator( FILE_NAME_CHAR_VALIDATOR( &moduleName ) );
  743. if( dlg.ShowModal() != wxID_OK )
  744. return NULL; //Aborted by user
  745. }
  746. moduleName.Trim( true );
  747. moduleName.Trim( false );
  748. if( moduleName.IsEmpty() )
  749. {
  750. DisplayInfoMessage( this, FMT_NO_REF_ABORTED );
  751. return NULL;
  752. }
  753. // Creates the new module and add it to the head of the linked list of modules
  754. MODULE* module = new MODULE( GetBoard() );
  755. // Update parameters: timestamp ...
  756. module->SetLastEditTime();
  757. // Update its name in lib
  758. module->SetFPID( LIB_ID( wxEmptyString, moduleName ) );
  759. wxPoint default_pos;
  760. BOARD_DESIGN_SETTINGS& settings = GetDesignSettings();
  761. // Update reference:
  762. if( settings.m_RefDefaultText.IsEmpty() )
  763. module->SetReference( moduleName );
  764. else
  765. module->SetReference( settings.m_RefDefaultText );
  766. PCB_LAYER_ID layer = ToLAYER_ID( settings.m_RefDefaultlayer );
  767. module->Reference().SetThickness( settings.GetTextThickness( layer ) );
  768. module->Reference().SetTextSize( settings.GetTextSize( layer ) );
  769. module->Reference().SetItalic( settings.GetTextItalic( layer ) );
  770. module->Reference().SetKeepUpright( settings.GetTextUpright( layer ) );
  771. default_pos.y = GetDesignSettings().GetTextSize( layer ).y / 2;
  772. module->Reference().SetPosition( default_pos );
  773. module->Reference().SetLayer( layer );
  774. module->Reference().SetVisible( settings.m_RefDefaultVisibility );
  775. // Set the value field to a default value
  776. if( settings.m_ValueDefaultText.IsEmpty() )
  777. module->SetValue( moduleName );
  778. else
  779. module->SetValue( settings.m_ValueDefaultText );
  780. layer = ToLAYER_ID( settings.m_ValueDefaultlayer );
  781. module->Value().SetThickness( settings.GetTextThickness( layer ) );
  782. module->Value().SetTextSize( settings.GetTextSize( layer ) );
  783. module->Value().SetItalic( settings.GetTextItalic( layer ) );
  784. module->Value().SetKeepUpright( settings.GetTextUpright( layer ) );
  785. default_pos.y = -default_pos.y;
  786. module->Value().SetPosition( default_pos );
  787. module->Value().SetLayer( layer );
  788. module->Value().SetVisible( settings.m_ValueDefaultVisibility );
  789. SetMsgPanel( module );
  790. return module;
  791. }
  792. wxString PCB_BASE_FRAME::SelectLibrary( const wxString& aNicknameExisting )
  793. {
  794. wxArrayString headers;
  795. headers.Add( _( "Nickname" ) );
  796. headers.Add( _( "Description" ) );
  797. FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs();
  798. std::vector< wxArrayString > itemsToDisplay;
  799. std::vector< wxString > nicknames = fptbl->GetLogicalLibs();
  800. for( unsigned i = 0; i < nicknames.size(); i++ )
  801. {
  802. wxArrayString item;
  803. item.Add( nicknames[i] );
  804. item.Add( fptbl->GetDescription( nicknames[i] ) );
  805. itemsToDisplay.push_back( item );
  806. }
  807. EDA_LIST_DIALOG dlg( this, FMT_SELECT_LIB, headers, itemsToDisplay, aNicknameExisting );
  808. if( dlg.ShowModal() != wxID_OK )
  809. return wxEmptyString;
  810. wxString nickname = dlg.GetTextSelection();
  811. wxLogDebug( wxT( "Chose footprint library \"%s\"." ), GetChars( nickname ) );
  812. return nickname;
  813. }