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.

591 lines
17 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
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
11 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 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
15 years ago
14 years ago
14 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
  5. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * @file pcbnew/loadcmp.cpp
  27. * @brief Footprints selection and loading functions.
  28. */
  29. #include <functional>
  30. using namespace std::placeholders;
  31. #include <fctsys.h>
  32. #include <class_drawpanel.h>
  33. #include <pcb_draw_panel_gal.h>
  34. #include <confirm.h>
  35. #include <eda_doc.h>
  36. #include <kicad_string.h>
  37. #include <pgm_base.h>
  38. #include <kiway.h>
  39. #include <wxPcbStruct.h>
  40. #include <dialog_helpers.h>
  41. #include <filter_reader.h>
  42. #include <gr_basic.h>
  43. #include <macros.h>
  44. #include <fp_lib_table.h>
  45. #include <lib_id.h>
  46. #include <class_board.h>
  47. #include <class_module.h>
  48. #include <io_mgr.h>
  49. #include <pcbnew.h>
  50. #include <module_editor_frame.h>
  51. #include <footprint_info.h>
  52. #include <footprint_info_impl.h>
  53. #include <dialog_get_component.h>
  54. #include <modview_frame.h>
  55. #include <wildcards_and_files_ext.h>
  56. #include <class_pcb_layer_widget.h>
  57. static void DisplayCmpDoc( wxString& aName, void* aData );
  58. // Use the _IMPL class directly here because this is static - don't want to yank
  59. // a static through kiface.
  60. static FOOTPRINT_LIST_IMPL MList;
  61. static void clearModuleItemFlags( BOARD_ITEM* aItem )
  62. {
  63. aItem->ClearFlags();
  64. }
  65. bool FOOTPRINT_EDIT_FRAME::Load_Module_From_BOARD( MODULE* aModule )
  66. {
  67. MODULE* newModule;
  68. PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB, false );
  69. if( frame == NULL ) // happens if no board editor opened
  70. return false;
  71. if( aModule == NULL )
  72. {
  73. if( ! frame->GetBoard() || ! frame->GetBoard()->m_Modules )
  74. return false;
  75. aModule = SelectFootprint( frame->GetBoard() );
  76. }
  77. if( aModule == NULL )
  78. return false;
  79. SetCurItem( NULL );
  80. Clear_Pcb( false );
  81. GetBoard()->m_Status_Pcb = 0;
  82. newModule = new MODULE( *aModule );
  83. newModule->SetParent( GetBoard() );
  84. newModule->SetLink( aModule->GetTimeStamp() );
  85. aModule = newModule;
  86. newModule->ClearFlags();
  87. newModule->RunOnChildren( std::bind( &clearModuleItemFlags, _1 ) );
  88. GetBoard()->Add( newModule );
  89. // Clear references to any net info, because the footprint editor
  90. // does know any thing about nets handled by the current edited board.
  91. // Morever we do not want to save any reference to an unknown net when
  92. // saving the footprint in lib cache
  93. // so we force the ORPHANED dummy net info for all pads
  94. newModule->ClearAllNets();
  95. SetCrossHairPosition( wxPoint( 0, 0 ) );
  96. PlaceModule( newModule, NULL );
  97. newModule->SetPosition( wxPoint( 0, 0 ) ); // cursor in GAL may not be initialized at the moment
  98. // Put it on FRONT layer,
  99. // because this is the default in ModEdit, and in libs
  100. if( newModule->GetLayer() != F_Cu )
  101. newModule->Flip( newModule->GetPosition() );
  102. // Put it in orientation 0,
  103. // because this is the default orientation in ModEdit, and in libs
  104. Rotate_Module( NULL, newModule, 0, false );
  105. GetScreen()->ClrModify();
  106. Zoom_Automatique( false );
  107. if( IsGalCanvasActive() )
  108. updateView();
  109. return true;
  110. }
  111. wxString PCB_BASE_FRAME::SelectFootprintFromLibBrowser()
  112. {
  113. // Close the current non-modal Lib browser if opened, and open a new one, in "modal" mode:
  114. FOOTPRINT_VIEWER_FRAME* viewer;
  115. viewer = (FOOTPRINT_VIEWER_FRAME*) Kiway().Player( FRAME_PCB_MODULE_VIEWER, false );
  116. if( viewer )
  117. viewer->Destroy();
  118. SetFocus();
  119. // Creates the modal Lib browser:
  120. viewer = (FOOTPRINT_VIEWER_FRAME*) Kiway().Player( FRAME_PCB_MODULE_VIEWER_MODAL, true, this );
  121. wxString fpid;
  122. int ret = viewer->ShowModal( &fpid, this );
  123. (void) ret; // make static analyser quiet
  124. viewer->Destroy();
  125. return fpid;
  126. }
  127. MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary,
  128. FP_LIB_TABLE* aTable,
  129. bool aUseFootprintViewer,
  130. wxDC* aDC )
  131. {
  132. MODULE* module = NULL;
  133. wxPoint curspos = GetCrossHairPosition();
  134. wxString moduleName, keys;
  135. wxString libName = aLibrary;
  136. bool allowWildSeach = true;
  137. static wxArrayString HistoryList;
  138. static wxString lastComponentName;
  139. // Ask for a component name or key words
  140. DIALOG_GET_COMPONENT dlg( this, HistoryList, _( "Load Footprint" ), aUseFootprintViewer );
  141. dlg.SetComponentName( lastComponentName );
  142. if( dlg.ShowModal() == wxID_CANCEL )
  143. return NULL;
  144. if( dlg.m_GetExtraFunction )
  145. {
  146. // SelectFootprintFromLibBrowser() returns the "full" footprint name, i.e.
  147. // <lib_name>/<footprint name> or LIB_ID format "lib_name:fp_name:rev#"
  148. moduleName = SelectFootprintFromLibBrowser();
  149. }
  150. else
  151. {
  152. moduleName = dlg.GetComponentName();
  153. }
  154. if( moduleName.IsEmpty() ) // Cancel command
  155. {
  156. m_canvas->MoveCursorToCrossHair();
  157. return NULL;
  158. }
  159. if( dlg.IsKeyword() ) // Selection by keywords
  160. {
  161. allowWildSeach = false;
  162. keys = moduleName;
  163. moduleName = SelectFootprint( this, libName, wxEmptyString, keys, aTable );
  164. if( moduleName.IsEmpty() ) // Cancel command
  165. {
  166. m_canvas->MoveCursorToCrossHair();
  167. return NULL;
  168. }
  169. }
  170. else if( moduleName.Contains( wxT( "?" ) )
  171. || moduleName.Contains( wxT( "*" ) ) ) // Selection wild card
  172. {
  173. allowWildSeach = false;
  174. moduleName = SelectFootprint( this, libName, moduleName, wxEmptyString, aTable );
  175. if( moduleName.IsEmpty() )
  176. {
  177. m_canvas->MoveCursorToCrossHair();
  178. return NULL; // Cancel command.
  179. }
  180. }
  181. LIB_ID fpid;
  182. wxCHECK_MSG( fpid.Parse( moduleName ) < 0, NULL,
  183. wxString::Format( wxT( "Could not parse LIB_ID string '%s'." ),
  184. GetChars( moduleName ) ) );
  185. try
  186. {
  187. module = loadFootprint( fpid );
  188. }
  189. catch( const IO_ERROR& ioe )
  190. {
  191. wxLogDebug( wxT( "An error occurred attemping to load footprint '%s'.\n\nError: %s" ),
  192. fpid.Format().c_str(), GetChars( ioe.What() ) );
  193. }
  194. if( !module && allowWildSeach ) // Search with wild card
  195. {
  196. allowWildSeach = false;
  197. wxString wildname = wxChar( '*' ) + moduleName + wxChar( '*' );
  198. moduleName = wildname;
  199. moduleName = SelectFootprint( this, libName, moduleName, wxEmptyString, aTable );
  200. if( moduleName.IsEmpty() )
  201. {
  202. m_canvas->MoveCursorToCrossHair();
  203. return NULL; // Cancel command.
  204. }
  205. else
  206. {
  207. wxCHECK_MSG( fpid.Parse( moduleName ) < 0, NULL,
  208. wxString::Format( wxT( "Could not parse LIB_ID string '%s'." ),
  209. GetChars( moduleName ) ) );
  210. try
  211. {
  212. module = loadFootprint( fpid );
  213. }
  214. catch( const IO_ERROR& ioe )
  215. {
  216. wxLogDebug( wxT( "An error occurred attemping to load footprint '%s'.\n\nError: %s" ),
  217. fpid.Format().c_str(), GetChars( ioe.What() ) );
  218. }
  219. }
  220. }
  221. SetCrossHairPosition( curspos );
  222. m_canvas->MoveCursorToCrossHair();
  223. if( module )
  224. {
  225. GetBoard()->Add( module, ADD_APPEND );
  226. lastComponentName = moduleName;
  227. AddHistoryComponentName( HistoryList, moduleName );
  228. module->SetFlags( IS_NEW );
  229. module->SetLink( 0 );
  230. if( IsGalCanvasActive() )
  231. module->SetPosition( wxPoint( 0, 0 ) ); // cursor in GAL may not be initialized at the moment
  232. else
  233. module->SetPosition( curspos );
  234. module->SetTimeStamp( GetNewTimeStamp() );
  235. GetBoard()->m_Status_Pcb = 0;
  236. // Put it on FRONT layer,
  237. // (Can be stored flipped if the lib is an archive built from a board)
  238. if( module->IsFlipped() )
  239. module->Flip( module->GetPosition() );
  240. // Place it in orientation 0,
  241. // even if it is not saved with orientation 0 in lib
  242. // (Can happen if the lib is an archive built from a board)
  243. Rotate_Module( NULL, module, 0, false );
  244. //RecalculateAllTracksNetcode();
  245. if( aDC )
  246. module->Draw( m_canvas, aDC, GR_OR );
  247. }
  248. return module;
  249. }
  250. MODULE* PCB_BASE_FRAME::LoadFootprint( const LIB_ID& aFootprintId )
  251. {
  252. MODULE* module = NULL;
  253. try
  254. {
  255. module = loadFootprint( aFootprintId );
  256. }
  257. catch( const IO_ERROR& ioe )
  258. {
  259. wxLogDebug( wxT( "An error occurred attemping to load footprint '%s'.\n\nError: %s" ),
  260. aFootprintId.Format().c_str(), GetChars( ioe.What() ) );
  261. }
  262. return module;
  263. }
  264. MODULE* PCB_BASE_FRAME::loadFootprint( const LIB_ID& aFootprintId )
  265. {
  266. FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs();
  267. wxCHECK_MSG( fptbl, NULL, wxT( "Cannot look up LIB_ID in NULL FP_LIB_TABLE." ) );
  268. MODULE *module = nullptr;
  269. try
  270. {
  271. module = fptbl->FootprintLoadWithOptionalNickname( aFootprintId );
  272. }
  273. catch( const IO_ERROR& ioe )
  274. {
  275. wxLogDebug( wxT( "An error occurred attemping to load footprint '%s'.\n\nError: %s" ),
  276. aFootprintId.Format().c_str(), GetChars( ioe.What() ) );
  277. }
  278. // If the module is found, clear all net info,
  279. // to be sure there is no broken links
  280. // to any netinfo list (should be not needed, but it can be edited from
  281. // the footprint editor )
  282. if( module )
  283. module->ClearAllNets();
  284. return module;
  285. }
  286. wxString PCB_BASE_FRAME::SelectFootprint( EDA_DRAW_FRAME* aWindow,
  287. const wxString& aLibraryName,
  288. const wxString& aMask,
  289. const wxString& aKeyWord,
  290. FP_LIB_TABLE* aTable )
  291. {
  292. static wxString oldName; // Save the name of the last module loaded.
  293. wxString fpname;
  294. wxString msg;
  295. wxArrayString libraries;
  296. std::vector< wxArrayString > rows;
  297. wxASSERT( aTable != NULL );
  298. MList.ReadFootprintFiles( aTable, !aLibraryName ? NULL : &aLibraryName );
  299. if( MList.GetErrorCount() )
  300. {
  301. MList.DisplayErrors( this );
  302. return wxEmptyString;
  303. }
  304. if( MList.GetCount() == 0 )
  305. {
  306. wxString tmp;
  307. for( unsigned i = 0; i < libraries.GetCount(); i++ )
  308. {
  309. tmp += libraries[i] + wxT( "\n" );
  310. }
  311. msg.Printf( _( "No footprints could be read from library file(s):\n\n%s\nin any of "
  312. "the library search paths. Verify your system is configured properly "
  313. "so the footprint libraries can be found." ), GetChars( tmp ) );
  314. DisplayError( aWindow, msg );
  315. return wxEmptyString;
  316. }
  317. if( !aKeyWord.IsEmpty() ) // Create a list of modules found by keyword.
  318. {
  319. for( unsigned ii = 0; ii < MList.GetCount(); ii++ )
  320. {
  321. if( KeyWordOk( aKeyWord, MList.GetItem( ii ).GetKeywords() ) )
  322. {
  323. wxArrayString cols;
  324. cols.Add( MList.GetItem( ii ).GetFootprintName() );
  325. cols.Add( MList.GetItem( ii ).GetNickname() );
  326. rows.push_back( cols );
  327. }
  328. }
  329. }
  330. else if( !aMask.IsEmpty() ) // Create a list of modules found by pattern
  331. {
  332. for( unsigned ii = 0; ii < MList.GetCount(); ii++ )
  333. {
  334. const wxString& candidate = MList.GetItem( ii ).GetFootprintName();
  335. if( WildCompareString( aMask, candidate, false ) )
  336. {
  337. wxArrayString cols;
  338. cols.Add( MList.GetItem( ii ).GetFootprintName() );
  339. cols.Add( MList.GetItem( ii ).GetNickname() );
  340. rows.push_back( cols );
  341. }
  342. }
  343. }
  344. else // Create the full list of modules
  345. {
  346. for( unsigned ii = 0; ii < MList.GetCount(); ii++ )
  347. {
  348. wxArrayString cols;
  349. cols.Add( MList.GetItem( ii ).GetFootprintName() );
  350. cols.Add( MList.GetItem( ii ).GetNickname() );
  351. rows.push_back( cols );
  352. }
  353. }
  354. if( !rows.empty() )
  355. {
  356. wxArrayString headers;
  357. headers.Add( _( "Footprint" ) );
  358. headers.Add( _( "Library" ) );
  359. msg.Printf( _( "Footprints [%d items]" ), (int) rows.size() );
  360. EDA_LIST_DIALOG dlg( aWindow, msg, headers, rows, oldName, DisplayCmpDoc );
  361. if( dlg.ShowModal() == wxID_OK )
  362. {
  363. fpname = dlg.GetTextSelection();
  364. fpname = dlg.GetTextSelection( 1 ) + wxT( ":" ) + fpname;
  365. SkipNextLeftButtonReleaseEvent();
  366. }
  367. else
  368. fpname.Empty();
  369. }
  370. else
  371. {
  372. DisplayError( aWindow, _( "No footprint found." ) );
  373. fpname.Empty();
  374. }
  375. if( fpname != wxEmptyString )
  376. oldName = fpname;
  377. wxLogDebug( wxT( "Footprint '%s' was selected." ), GetChars( fpname ) );
  378. return fpname;
  379. }
  380. static void DisplayCmpDoc( wxString& aName, void* aData )
  381. {
  382. FOOTPRINT_INFO* module_info = MList.GetModuleInfo( aName );
  383. if( !module_info )
  384. {
  385. aName.Empty();
  386. return;
  387. }
  388. aName = _( "Description: " ) + module_info->GetDoc();
  389. aName += _( "\nKey words: " ) + module_info->GetKeywords();
  390. }
  391. MODULE* FOOTPRINT_EDIT_FRAME::SelectFootprint( BOARD* aPcb )
  392. {
  393. static wxString oldName; // Save name of last module selected.
  394. wxString fpname;
  395. wxString msg;
  396. wxArrayString listnames;
  397. MODULE* module = aPcb->m_Modules;
  398. for( ; module; module = module->Next() )
  399. listnames.Add( module->GetReference() );
  400. msg.Printf( _( "Footprints [%u items]" ), (unsigned) listnames.GetCount() );
  401. wxArrayString headers;
  402. headers.Add( _( "Footprint" ) );
  403. std::vector<wxArrayString> itemsToDisplay;
  404. // Conversion from wxArrayString to vector of ArrayString
  405. for( unsigned i = 0; i < listnames.GetCount(); i++ )
  406. {
  407. wxArrayString item;
  408. item.Add( listnames[i] );
  409. itemsToDisplay.push_back( item );
  410. }
  411. EDA_LIST_DIALOG dlg( this, msg, headers, itemsToDisplay, wxEmptyString, NULL, NULL, SORT_LIST );
  412. if( dlg.ShowModal() == wxID_OK )
  413. fpname = dlg.GetTextSelection();
  414. else
  415. return NULL;
  416. oldName = fpname;
  417. module = aPcb->m_Modules;
  418. for( ; module; module = module->Next() )
  419. {
  420. if( fpname == module->GetReference() )
  421. break;
  422. }
  423. return module;
  424. }
  425. void FOOTPRINT_EDIT_FRAME::OnSaveLibraryAs( wxCommandEvent& aEvent )
  426. {
  427. wxString curLibPath = getLibPath();
  428. wxString dstLibPath = CreateNewLibrary();
  429. if( !dstLibPath )
  430. return; // user aborted in CreateNewLibrary()
  431. wxBusyCursor dummy;
  432. wxString msg;
  433. IO_MGR::PCB_FILE_T dstType = IO_MGR::GuessPluginTypeFromLibPath( dstLibPath );
  434. IO_MGR::PCB_FILE_T curType = IO_MGR::GuessPluginTypeFromLibPath( curLibPath );
  435. try
  436. {
  437. PLUGIN::RELEASER cur( IO_MGR::PluginFind( curType ) );
  438. PLUGIN::RELEASER dst( IO_MGR::PluginFind( dstType ) );
  439. wxArrayString mods;
  440. cur->FootprintEnumerate( mods, curLibPath );
  441. for( unsigned i = 0; i < mods.size(); ++i )
  442. {
  443. std::unique_ptr<MODULE> m( cur->FootprintLoad( curLibPath, mods[i] ) );
  444. dst->FootprintSave( dstLibPath, m.get() );
  445. msg = wxString::Format( _( "Footprint '%s' saved" ),
  446. GetChars( mods[i] ) );
  447. SetStatusText( msg );
  448. // m is deleted here by unique_ptr.
  449. }
  450. }
  451. catch( const IO_ERROR& ioe )
  452. {
  453. DisplayError( this, ioe.What() );
  454. return;
  455. }
  456. msg = wxString::Format(
  457. _( "Footprint library '%s' saved as '%s'." ),
  458. GetChars( curLibPath ), GetChars( dstLibPath ) );
  459. DisplayInfoMessage( this, msg );
  460. SetStatusText( wxEmptyString );
  461. }