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.

658 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
* 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) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. /**
  25. * @file eeschema/dialogs/dialog_bom.cpp
  26. * @brief Dialog box for creating bom and other documents from generic netlist.
  27. */
  28. #include <fctsys.h>
  29. #include <pgm_base.h>
  30. #include <kiface_i.h>
  31. #include <confirm.h>
  32. #include <gestfich.h>
  33. #include <sch_edit_frame.h>
  34. #include <netlist.h>
  35. #include <netlist_exporter_generic.h>
  36. #include <invoke_sch_dialog.h>
  37. #include <dialog_helpers.h>
  38. #include <dialog_bom_base.h>
  39. #include <html_messagebox.h>
  40. #include <reporter.h>
  41. #include <bom_plugins.h>
  42. #include <i18n_utility.h> // for _HKI definition used in dialog_bom_help_md.h
  43. #include <dialogs/dialog_bom_cfg_lexer.h>
  44. static constexpr wxChar BOM_TRACE[] = wxT( "BOM_GENERATORS" );
  45. static constexpr wxChar BOM_GENERATORS_KEY[] = wxT( "bom_plugins" );
  46. static constexpr wxChar BOM_GENERATOR_SELECTED_KEY[] = wxT( "bom_plugin_selected" );
  47. wxString s_bomHelpInfo =
  48. #include <dialog_bom_help_md.h>
  49. ;
  50. using namespace T_BOMCFG_T; // for the BOM_CFG_PARSER parser and its keywords
  51. // BOM "plugins" are not actually plugins. They are external tools
  52. // (scripts or executables) called by this dialog.
  53. typedef std::vector<BOM_GENERATOR_HANDLER::PTR> BOM_GENERATOR_ARRAY;
  54. /**
  55. * Holds data and functions pertinent to parsing a S-expression file
  56. */
  57. class BOM_CFG_PARSER : public DIALOG_BOM_CFG_LEXER
  58. {
  59. BOM_GENERATOR_ARRAY* m_generatorsList;
  60. public:
  61. BOM_CFG_PARSER( BOM_GENERATOR_ARRAY* aGenerators, const char* aData, const wxString& aSource );
  62. void Parse();
  63. private:
  64. void parseGenerator();
  65. };
  66. BOM_CFG_PARSER::BOM_CFG_PARSER( BOM_GENERATOR_ARRAY* aGenerators, const char* aLine,
  67. const wxString& aSource ) :
  68. DIALOG_BOM_CFG_LEXER( aLine, aSource )
  69. {
  70. m_generatorsList = aGenerators;
  71. }
  72. void BOM_CFG_PARSER::Parse()
  73. {
  74. T token;
  75. while( ( token = NextTok() ) != T_RIGHT )
  76. {
  77. if( token == T_EOF)
  78. break;
  79. if( token == T_LEFT )
  80. token = NextTok();
  81. if( token == T_plugins )
  82. continue;
  83. switch( token )
  84. {
  85. case T_plugin: // Defines a new plugin
  86. parseGenerator();
  87. break;
  88. default:
  89. // Unexpected( CurText() );
  90. break;
  91. }
  92. }
  93. }
  94. void BOM_CFG_PARSER::parseGenerator()
  95. {
  96. NeedSYMBOLorNUMBER();
  97. wxString name = FromUTF8();
  98. auto plugin = std::make_unique<BOM_GENERATOR_HANDLER>( name );
  99. T token;
  100. while( ( token = NextTok() ) != T_RIGHT )
  101. {
  102. if( token == T_EOF)
  103. break;
  104. switch( token )
  105. {
  106. case T_LEFT:
  107. break;
  108. case T_cmd:
  109. NeedSYMBOLorNUMBER();
  110. if( plugin )
  111. plugin->SetCommand( FromUTF8() );
  112. NeedRIGHT();
  113. break;
  114. case T_opts:
  115. NeedSYMBOLorNUMBER();
  116. if( plugin )
  117. {
  118. wxString option = FromUTF8();
  119. if( option.StartsWith( "nickname=", &name ) )
  120. plugin->SetName( name );
  121. else
  122. plugin->Options().Add( option );
  123. }
  124. NeedRIGHT();
  125. break;
  126. default:
  127. Unexpected( CurText() );
  128. break;
  129. }
  130. }
  131. if( plugin )
  132. m_generatorsList->push_back( std::move( plugin ) );
  133. }
  134. // The main dialog frame to run scripts to build bom
  135. class DIALOG_BOM : public DIALOG_BOM_BASE
  136. {
  137. private:
  138. SCH_EDIT_FRAME* m_parent;
  139. BOM_GENERATOR_ARRAY m_generators;
  140. wxConfigBase* m_config; // to store the "plugins"
  141. bool m_initialized;
  142. public:
  143. DIALOG_BOM( SCH_EDIT_FRAME* parent );
  144. ~DIALOG_BOM();
  145. private:
  146. void OnGeneratorSelected( wxCommandEvent& event ) override;
  147. void OnRunGenerator( wxCommandEvent& event ) override;
  148. void OnHelp( wxCommandEvent& event ) override;
  149. void OnAddGenerator( wxCommandEvent& event ) override;
  150. void OnRemoveGenerator( wxCommandEvent& event ) override;
  151. void OnEditGenerator( wxCommandEvent& event ) override;
  152. void OnCommandLineEdited( wxCommandEvent& event ) override;
  153. void OnNameEdited( wxCommandEvent& event ) override;
  154. void OnShowConsoleChanged( wxCommandEvent& event ) override;
  155. void OnIdle( wxIdleEvent& event ) override;
  156. void pluginInit();
  157. void installGeneratorsList();
  158. BOM_GENERATOR_HANDLER* addGenerator( const wxString& aPath, const wxString& aName = wxEmptyString );
  159. bool pluginExists( const wxString& aName );
  160. BOM_GENERATOR_HANDLER* selectedGenerator()
  161. {
  162. int idx = m_lbGenerators->GetSelection();
  163. if( idx < 0 || idx >= (int)m_generators.size() )
  164. return nullptr;
  165. return m_generators[idx].get();
  166. }
  167. wxString chooseGenerator();
  168. };
  169. // Create and show DIALOG_BOM.
  170. int InvokeDialogCreateBOM( SCH_EDIT_FRAME* aCaller )
  171. {
  172. DIALOG_BOM dlg( aCaller );
  173. return dlg.ShowModal();
  174. }
  175. DIALOG_BOM::DIALOG_BOM( SCH_EDIT_FRAME* parent ) :
  176. DIALOG_BOM_BASE( parent )
  177. {
  178. m_parent = parent;
  179. m_config = Kiface().KifaceSettings();
  180. m_initialized = false;
  181. m_buttonAddGenerator->SetBitmap( KiBitmap( small_plus_xpm ) );
  182. m_buttonDelGenerator->SetBitmap( KiBitmap( trash_xpm ) );
  183. m_buttonEdit->SetBitmap( KiBitmap( small_edit_xpm ) );
  184. installGeneratorsList();
  185. #ifndef __WINDOWS__
  186. m_checkBoxShowConsole->Show( false );
  187. #endif
  188. m_sdbSizerOK->SetLabel( _( "Generate" ) );
  189. m_sdbSizerCancel->SetLabel( _( "Close" ) );
  190. m_sdbSizer->Layout();
  191. SetInitialFocus( m_lbGenerators );
  192. m_sdbSizerOK->SetDefault();
  193. // Now all widgets have the size fixed, call FinishDialogSettings
  194. FinishDialogSettings();
  195. }
  196. DIALOG_BOM::~DIALOG_BOM()
  197. {
  198. // Save the plugin descriptions in config.
  199. // The config stores only one string, so we save the plugins inside a S-expr:
  200. // ( plugins
  201. // ( plugin "plugin name 1" (cmd "command line 1") )
  202. // ( plugin "plugin name 2" (cmd "command line 2") (opts "option1") (opts "option2") )
  203. // ....
  204. // )
  205. STRING_FORMATTER writer;
  206. writer.Print( 0, "(plugins" );
  207. for( auto& plugin : m_generators )
  208. {
  209. writer.Print( 1, "(plugin %s (cmd %s)",
  210. writer.Quotew( plugin->GetFile().GetFullPath() ).c_str(),
  211. writer.Quotew( plugin->GetCommand() ).c_str() );
  212. for( unsigned jj = 0; jj < plugin->Options().GetCount(); jj++ )
  213. {
  214. writer.Print( 1, "(opts %s)",
  215. writer.Quotew( plugin->Options().Item( jj ) ).c_str() );
  216. }
  217. if( !plugin->GetName().IsEmpty() )
  218. {
  219. wxString option = wxString::Format( "nickname=%s", plugin->GetName() );
  220. writer.Print( 1, "(opts %s)",
  221. writer.Quotew( option ).c_str() );
  222. }
  223. writer.Print( 0, ")" );
  224. }
  225. writer.Print( 0, ")" );
  226. wxString list( FROM_UTF8( writer.GetString().c_str() ) );
  227. m_config->Write( BOM_GENERATORS_KEY, list );
  228. wxString active_plugin_name = m_lbGenerators->GetStringSelection( );
  229. m_config->Write( BOM_GENERATOR_SELECTED_KEY, active_plugin_name );
  230. }
  231. // Read the initialized plugins in config and fill the list of names
  232. void DIALOG_BOM::installGeneratorsList()
  233. {
  234. wxString list, active_plugin_name;
  235. m_config->Read( BOM_GENERATORS_KEY, &list );
  236. m_config->Read( BOM_GENERATOR_SELECTED_KEY, &active_plugin_name );
  237. if( !list.IsEmpty() )
  238. {
  239. BOM_CFG_PARSER cfg_parser( &m_generators, TO_UTF8( list ), wxT( "plugins" ) );
  240. try
  241. {
  242. cfg_parser.Parse();
  243. }
  244. catch( const IO_ERROR& )
  245. {
  246. // wxLogMessage( ioe.What() );
  247. }
  248. catch( std::runtime_error& e )
  249. {
  250. DisplayError( nullptr, e.what() );
  251. }
  252. // Populate list box
  253. for( unsigned ii = 0; ii < m_generators.size(); ii++ )
  254. {
  255. m_lbGenerators->Append( m_generators[ii]->GetName() );
  256. if( active_plugin_name == m_generators[ii]->GetName() )
  257. m_lbGenerators->SetSelection( ii );
  258. }
  259. }
  260. if( m_generators.empty() ) // No plugins found?
  261. {
  262. // Load plugins from the default locations
  263. std::vector<wxString> pluginPaths = {
  264. #if defined(__WXGTK__)
  265. "/usr/share/kicad/plugins",
  266. "/usr/local/share/kicad/plugins",
  267. #elif defined(__WXMSW__)
  268. wxString::Format( "%s\\scripting\\plugins", Pgm().GetExecutablePath() ),
  269. #elif defined(__WXMAC__)
  270. wxString::Format( "%s/plugins", GetOSXKicadDataDir() ),
  271. #endif
  272. };
  273. wxFileName pluginPath;
  274. for( const auto& path : pluginPaths )
  275. {
  276. wxLogDebug( wxString::Format( "Searching directory %s for BOM generators", path ) );
  277. wxDir dir( path );
  278. if( !dir.IsOpened() )
  279. continue;
  280. pluginPath.AssignDir( dir.GetName() );
  281. wxString fileName;
  282. bool cont = dir.GetFirst( &fileName, wxFileSelectorDefaultWildcardStr, wxDIR_FILES );
  283. while( cont )
  284. {
  285. try
  286. {
  287. wxLogTrace( BOM_TRACE, wxString::Format( "Checking if %s is a BOM generator", fileName ) );
  288. if( BOM_GENERATOR_HANDLER::IsValidGenerator( fileName ) )
  289. {
  290. pluginPath.SetFullName( fileName );
  291. addGenerator( pluginPath.GetFullPath() );
  292. }
  293. }
  294. catch( ... ) { /* well, no big deal */ }
  295. cont = dir.GetNext( &fileName );
  296. }
  297. }
  298. }
  299. pluginInit();
  300. }
  301. BOM_GENERATOR_HANDLER* DIALOG_BOM::addGenerator( const wxString& aPath, const wxString& aName )
  302. {
  303. BOM_GENERATOR_HANDLER* ret = nullptr;
  304. auto plugin = std::make_unique<BOM_GENERATOR_HANDLER>( aPath );
  305. if( !plugin )
  306. return nullptr;
  307. if( !aName.IsEmpty() )
  308. {
  309. plugin->SetName( aName );
  310. m_lbGenerators->Append( aName );
  311. }
  312. else
  313. {
  314. m_lbGenerators->Append( plugin->GetName() );
  315. }
  316. ret = plugin.get();
  317. m_generators.push_back( std::move( plugin ) );
  318. return ret;
  319. }
  320. bool DIALOG_BOM::pluginExists( const wxString& aName )
  321. {
  322. for( unsigned ii = 0; ii < m_generators.size(); ii++ )
  323. {
  324. if( aName == m_generators[ii]->GetName() )
  325. return true;
  326. }
  327. return false;
  328. }
  329. void DIALOG_BOM::OnGeneratorSelected( wxCommandEvent& event )
  330. {
  331. pluginInit();
  332. }
  333. void DIALOG_BOM::pluginInit()
  334. {
  335. auto plugin = selectedGenerator();
  336. if( !plugin )
  337. {
  338. m_textCtrlName->SetValue( wxEmptyString );
  339. m_textCtrlCommand->SetValue( wxEmptyString );
  340. m_Messages->SetValue( wxEmptyString );
  341. return;
  342. }
  343. m_textCtrlName->SetValue( plugin->GetName() );
  344. m_textCtrlCommand->SetValue( plugin->GetCommand() );
  345. m_Messages->SetValue( plugin->GetInfo() );
  346. m_Messages->SetSelection( 0, 0 );
  347. #ifdef __WINDOWS__
  348. if( plugin->Options().Index( wxT( "show_console" ) ) == wxNOT_FOUND )
  349. m_checkBoxShowConsole->SetValue( false );
  350. else
  351. m_checkBoxShowConsole->SetValue( true );
  352. #endif
  353. // A plugin can be not working, so do not left the OK button enabled if
  354. // the plugin is not ready to use
  355. m_sdbSizerOK->Enable( plugin->IsOk() );
  356. }
  357. void DIALOG_BOM::OnRunGenerator( wxCommandEvent& event )
  358. {
  359. // Calculate the xml netlist filename
  360. wxFileName fn = g_RootSheet->GetScreen()->GetFileName();
  361. fn.SetPath( wxPathOnly( Prj().GetProjectFullName() ) );
  362. fn.ClearExt();
  363. wxString fullfilename = fn.GetFullPath();
  364. m_parent->ClearMsgPanel();
  365. wxString reportmsg;
  366. WX_STRING_REPORTER reporter( &reportmsg );
  367. m_parent->SetNetListerCommand( m_textCtrlCommand->GetValue() );
  368. #ifdef __WINDOWS__
  369. if( m_checkBoxShowConsole->IsChecked() )
  370. m_parent->SetExecFlags( wxEXEC_SHOW_CONSOLE );
  371. #endif
  372. auto netlist = m_parent->CreateNetlist( false, false );
  373. m_parent->WriteNetListFile( netlist, -1,
  374. fullfilename, 0, &reporter );
  375. m_Messages->SetValue( reportmsg );
  376. // Force focus back on the dialog
  377. SetFocus();
  378. }
  379. void DIALOG_BOM::OnRemoveGenerator( wxCommandEvent& event )
  380. {
  381. int ii = m_lbGenerators->GetSelection();
  382. if( ii < 0 )
  383. return;
  384. m_lbGenerators->Delete( ii );
  385. m_generators.erase( m_generators.begin() + ii );
  386. // Select the next item, if exists
  387. if( m_lbGenerators->GetCount() )
  388. m_lbGenerators->SetSelection( std::min( ii, (int) m_lbGenerators->GetCount() - 1 ) );
  389. pluginInit();
  390. }
  391. void DIALOG_BOM::OnAddGenerator( wxCommandEvent& event )
  392. {
  393. wxString filename = chooseGenerator();
  394. if( filename.IsEmpty() )
  395. return;
  396. // Creates a new plugin entry
  397. wxFileName fn( filename );
  398. wxString name = wxGetTextFromUser( _( "Generator nickname:" ), _( "Add Generator" ),
  399. fn.GetName(), this );
  400. if( name.IsEmpty() )
  401. return;
  402. // Verify if it does not exists
  403. if( pluginExists( name ) )
  404. {
  405. wxMessageBox( wxString::Format( _( "Nickname \"%s\" already in use." ), name ) );
  406. return;
  407. }
  408. try
  409. {
  410. auto plugin = addGenerator( fn.GetFullPath(), name );
  411. if( plugin )
  412. {
  413. m_lbGenerators->SetSelection( m_lbGenerators->GetCount() - 1 );
  414. m_textCtrlCommand->SetValue( plugin->GetCommand() );
  415. pluginInit();
  416. }
  417. }
  418. catch( const std::runtime_error& e )
  419. {
  420. DisplayError( this, e.what() );
  421. }
  422. }
  423. wxString DIALOG_BOM::chooseGenerator()
  424. {
  425. static wxString lastPath;
  426. if( lastPath.IsEmpty() )
  427. {
  428. #ifndef __WXMAC__
  429. lastPath = Pgm().GetExecutablePath();
  430. #else
  431. lastPath = GetOSXKicadDataDir() + "/plugins";
  432. #endif
  433. }
  434. wxString fullFileName = EDA_FILE_SELECTOR( _( "Generator files:" ), lastPath, wxEmptyString,
  435. wxEmptyString, wxFileSelectorDefaultWildcardStr,
  436. this, wxFD_OPEN, true );
  437. return fullFileName;
  438. }
  439. void DIALOG_BOM::OnEditGenerator( wxCommandEvent& event )
  440. {
  441. auto plugin = selectedGenerator();
  442. if( !plugin )
  443. return;
  444. wxString pluginFile = plugin->GetFile().GetFullPath();
  445. if( pluginFile.Length() <= 2 ) // if name != ""
  446. {
  447. wxMessageBox( _( "Generator file name not found." ) );
  448. return;
  449. }
  450. AddDelimiterString( pluginFile );
  451. wxString editorname = Pgm().GetEditorName();
  452. if( !editorname.IsEmpty() )
  453. ExecuteFile( this, editorname, pluginFile );
  454. else
  455. wxMessageBox( _( "No text editor selected in KiCad. Please choose one." ) );
  456. }
  457. void DIALOG_BOM::OnHelp( wxCommandEvent& event )
  458. {
  459. HTML_MESSAGE_BOX help_Dlg( this, _( "Bill of Material Generation Help" ) );
  460. help_Dlg.SetDialogSizeInDU( 500, 350 );
  461. wxString html_txt;
  462. ConvertMarkdown2Html( wxGetTranslation( s_bomHelpInfo ), html_txt );
  463. help_Dlg.m_htmlWindow->AppendToPage( html_txt );
  464. help_Dlg.ShowModal();
  465. }
  466. void DIALOG_BOM::OnCommandLineEdited( wxCommandEvent& event )
  467. {
  468. auto generator = selectedGenerator();
  469. if( generator )
  470. generator->SetCommand( m_textCtrlCommand->GetValue() );
  471. }
  472. void DIALOG_BOM::OnNameEdited( wxCommandEvent& event )
  473. {
  474. int ii = m_lbGenerators->GetSelection();
  475. if( ii < 0 )
  476. return;
  477. m_generators[ii]->SetName( m_textCtrlName->GetValue() );
  478. m_lbGenerators->SetString( ii, m_generators[ii]->GetName() );
  479. }
  480. void DIALOG_BOM::OnShowConsoleChanged( wxCommandEvent& event )
  481. {
  482. #ifdef __WINDOWS__
  483. static constexpr wxChar OPT_SHOW_CONSOLE[] = wxT( "show_console" );
  484. auto plugin = selectedGenerator();
  485. if( !plugin )
  486. return;
  487. if( m_checkBoxShowConsole->IsChecked() )
  488. {
  489. if( plugin->Options().Index( OPT_SHOW_CONSOLE ) == wxNOT_FOUND )
  490. plugin->Options().Add( OPT_SHOW_CONSOLE );
  491. }
  492. else
  493. {
  494. plugin->Options().Remove( OPT_SHOW_CONSOLE );
  495. }
  496. #endif
  497. }
  498. void DIALOG_BOM::OnIdle( wxIdleEvent& event )
  499. {
  500. // On some platforms we initialize wxTextCtrls to all-selected, but we don't want that
  501. // for the messages text box.
  502. if( !m_initialized )
  503. {
  504. m_Messages->SetSelection( 0, 0 );
  505. m_initialized = true;
  506. }
  507. }