KiCad PCB EDA Suite
eeschema/dialogs/dialog_netlist.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2013-2015 Jean-Pierre Charras, jp.charras@wanadoo.fr
5  * Copyright (C) 2013-2015 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 1992-2016 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 
31 /* Functions relative to the dialog creating the netlist for Pcbnew.
32  * The dialog is a notebook with 4 fixed netlist format:
33  * Pcbnew ORCADPCB2 CADSTAR and SPICE
34  * and up to CUSTOMPANEL_COUNTMAX (see netlist.h) user programmable format
35  * calling an external converter with convert an intermediate format to the
36  * user specific format.
37  * these external converters are referred there as plugins,
38  * but there are not really plugins, there are only external binaries
39  */
40 
41 #include <fctsys.h>
42 #include <pgm_base.h>
43 #include <kiface_i.h>
44 #include <gestfich.h>
45 #include <schframe.h>
46 
47 #include <general.h>
48 #include <netlist.h>
49 #include <sch_sheet.h>
50 #include <dialog_helpers.h>
54 #include <invoke_sch_dialog.h>
56 
57 #include <eeschema_id.h>
58 
59 
60 
61 #define CUSTOMPANEL_COUNTMAX 8 // Max number of netlist plugins
62 
63 
64 /* panel (notebook page) identifiers */
66  PANELPCBNEW = 0, /* Handle Netlist format Pcbnew */
67  PANELORCADPCB2, /* Handle Netlist format OracdPcb2 */
68  PANELCADSTAR, /* Handle Netlist format CadStar */
69  PANELSPICE, /* Handle Netlist format Pspice */
70  PANELCUSTOMBASE /* First auxiliary panel (custom netlists).
71  * others use PANELCUSTOMBASE+1, PANELCUSTOMBASE+2.. */
72 };
73 
74 
75 /* wxPanels for creating the NoteBook pages for each netlist format: */
76 class NETLIST_PAGE_DIALOG : public wxPanel
77 {
78 public:
80  wxCheckBox* m_IsCurrentFormat;
81  // opt to reformat passive component values (e.g. 1M -> 1Meg):
83  wxTextCtrl* m_CommandStringCtrl;
84  wxTextCtrl* m_TitleStringCtrl;
85  wxButton* m_ButtonCancel;
86  wxBoxSizer* m_LeftBoxSizer;
87  wxBoxSizer* m_RightBoxSizer;
89  wxBoxSizer* m_LowBoxSizer;
90 
91 private:
92  wxString m_pageNetFmtName;
93 
94 public:
101  NETLIST_PAGE_DIALOG( wxNotebook* parent, const wxString& title,
102  NETLIST_TYPE_ID id_NetType );
104 
110  const wxString GetPageNetFmtName()
111  {
112  return m_pageNetFmtName;
113  }
114 };
115 
116 
117 /* Dialog frame for creating netlists */
119 {
120  friend class NETLIST_PAGE_DIALOG;
121 
122 public:
124  wxString m_NetFmtName;
126 
127 protected:
129 
130 private:
131  wxConfigBase* m_config;
132 
133 public:
134 
135  // Constructor and destructor
136  NETLIST_DIALOG( SCH_EDIT_FRAME* parent );
138 
139 private:
140  void InstallCustomPages();
141  NETLIST_PAGE_DIALOG* AddOneCustomPage( const wxString & aTitle,
142  const wxString & aCommandString,
143  NETLIST_TYPE_ID aNetTypeId );
144  void InstallPageSpice();
145  void GenNetlist( wxCommandEvent& event ) override;
146  void RunSimulator( wxCommandEvent& event );
147  void NetlistUpdateOpt();
148  void OnNetlistTypeSelection( wxNotebookEvent& event ) override;
149  void SelectDefaultNetlistType( wxCommandEvent& event );
150 
155  void OnAddPlugin( wxCommandEvent& event ) override;
156 
161  void OnDelPlugin( wxCommandEvent& event ) override;
162 
168 
170  {
171  return m_cbUseDefaultNetlistName->IsChecked();
172  }
173 
182  const wxString UserNetlistTypeName( bool first_item );
183 
193  bool FilenamePrms( NETLIST_TYPE_ID aNetTypeId,
194  wxString * aExt, wxString * aWildCard );
195 
196  DECLARE_EVENT_TABLE()
197 };
198 
199 
201 {
202 private:
204 
205 public:
207  const wxString GetPluginTitle()
208  {
209  return m_textCtrlName->GetValue();
210  }
211  const wxString GetPluginTCommandLine()
212  {
213  return m_textCtrlCommand->GetValue();
214  }
215 
216 private:
217 
222  void OnOKClick( wxCommandEvent& event ) override;
223 
224  /*
225  * Browse plugin files, and set m_CommandStringCtrl field
226  */
227  void OnBrowsePlugins( wxCommandEvent& event ) override;
228 };
229 
230 
231 /* Event id for notebook page buttons: */
238 };
239 
240 
241 // ID for configuration:
242 #define CUSTOM_NETLIST_TITLE wxT( "CustomNetlistTitle" )
243 #define CUSTOM_NETLIST_COMMAND wxT( "CustomNetlistCommand" )
244 #define NETLIST_USE_DEFAULT_NETNAME wxT( "NetlistUseDefaultNetname" )
245 #define NETLIST_PSPICE_USE_NETNAME wxT( "SpiceUseNetNames" )
246 
247 
248 BEGIN_EVENT_TABLE( NETLIST_DIALOG, NETLIST_DIALOG_BASE )
249  EVT_BUTTON( ID_CREATE_NETLIST, NETLIST_DIALOG::GenNetlist )
251  NETLIST_DIALOG::SelectDefaultNetlistType )
252  EVT_BUTTON( ID_RUN_SIMULATOR, NETLIST_DIALOG::RunSimulator )
253 END_EVENT_TABLE()
254 
255 
256 
257 NETLIST_PAGE_DIALOG::NETLIST_PAGE_DIALOG( wxNotebook* parent,
258  const wxString& title,
259  NETLIST_TYPE_ID id_NetType ) :
260  wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize,
261  wxTAB_TRAVERSAL | wxBORDER_SUNKEN )
262 {
263  m_IdNetType = id_NetType;
264  m_pageNetFmtName = title;
265  m_CommandStringCtrl = NULL;
266  m_TitleStringCtrl = NULL;
267  m_IsCurrentFormat = NULL;
268  m_SpiceAjustPassiveValues = NULL;
269  m_ButtonCancel = NULL;
270 
271  wxString netfmtName = ((NETLIST_DIALOG*)parent->GetParent())->m_NetFmtName;
272 
273  bool selected = m_pageNetFmtName == netfmtName;
274 
275  parent->AddPage( this, title, selected );
276 
277  wxBoxSizer* MainBoxSizer = new wxBoxSizer( wxVERTICAL );
278  SetSizer( MainBoxSizer );
279  wxBoxSizer* UpperBoxSizer = new wxBoxSizer( wxHORIZONTAL );
280  m_LowBoxSizer = new wxBoxSizer( wxVERTICAL );
281  MainBoxSizer->Add( UpperBoxSizer, 0, wxGROW | wxALL, 5 );
282  MainBoxSizer->Add( m_LowBoxSizer, 0, wxGROW | wxALL, 5 );
283 
284  m_LeftBoxSizer = new wxBoxSizer( wxVERTICAL );
285  m_RightBoxSizer = new wxBoxSizer( wxVERTICAL );
286  m_RightOptionsBoxSizer = new wxBoxSizer( wxVERTICAL );
287  UpperBoxSizer->Add( m_LeftBoxSizer, 0, wxGROW | wxALL, 5 );
288  UpperBoxSizer->Add( m_RightBoxSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
289  UpperBoxSizer->Add( m_RightOptionsBoxSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
290 
291  wxStaticText* text = new wxStaticText( this, -1, _( "Options:" ) );
292  m_LeftBoxSizer->Add( text, 0, wxGROW | wxALL, 5 );
293 
294  m_IsCurrentFormat = new wxCheckBox( this, ID_CURRENT_FORMAT_IS_DEFAULT,
295  _( "Default format" ) );
296  m_LeftBoxSizer->Add( m_IsCurrentFormat, 0, wxGROW | wxALL, 5 );
297  m_IsCurrentFormat->SetValue( selected );
298 
299  if( selected )
300  ((NETLIST_DIALOG*)parent->GetParent())->m_asFormatSelected = true;
301 }
302 
303 
304 
306  NETLIST_DIALOG_BASE( parent )
307 {
308  m_Parent = parent;
310 
311  long tmp;
312  m_config->Read( NETLIST_USE_DEFAULT_NETNAME, &tmp, 0l );
313  m_cbUseDefaultNetlistName->SetValue( tmp );
315 
316  for( int ii = 0; ii < PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX; ii++ )
317  {
318  m_PanelNetType[ii] = NULL;
319  }
320 
321  // Add notebook pages:
322  m_asFormatSelected = false; // Will be set to true, if a format is selected
323 
324  // Add Panel FORMAT PCBNEW
326  new NETLIST_PAGE_DIALOG( m_NoteBook, wxT( "Pcbnew" ),
327  NET_TYPE_PCBNEW );
328 
329  // Add Panel FORMAT ORCADPCB2
331  new NETLIST_PAGE_DIALOG( m_NoteBook, wxT( "OrcadPCB2" ),
333 
334  // Add Panel FORMAT CADSTAR
336  new NETLIST_PAGE_DIALOG( m_NoteBook, wxT( "CadStar" ),
338 
339  // Add Panel spice
341 
342  // Add custom panels:
344 
345  if( !m_asFormatSelected )
346  m_PanelNetType[PANELPCBNEW]->m_IsCurrentFormat->SetValue( true );
347 
348  SetDefaultItem( m_buttonNetlist );
349 
350  // Now all widgets have the size fixed, call FinishDialogSettings
352 }
353 
354 
355 const wxString NETLIST_DIALOG::UserNetlistTypeName( bool first_item )
356 {
357  static int index;
358  wxString name, msg;
359 
360  if( first_item )
361  index = 0;
362  else
363  index++;
364 
365  msg = CUSTOM_NETLIST_TITLE;
366  msg << index + 1;
367 
368  name = m_config->Read( msg );
369 
370  return name;
371 }
372 
373 
375 {
376  wxButton* Button;
377  NETLIST_PAGE_DIALOG* page;
378  wxString title = wxT( "Spice" );
379 
380  page = m_PanelNetType[PANELSPICE] =
382 
383  page->m_SpiceAjustPassiveValues = new wxCheckBox( page, ID_USE_NETCODE_AS_NETNAME,
384  _( "Reformat passive component values" ) );
385  page->m_SpiceAjustPassiveValues->SetToolTip(
386  _( "Reformat passive component values e.g. 1M -> 1Meg" ) );
388  page->m_LeftBoxSizer->Add( page->m_SpiceAjustPassiveValues, 0, wxGROW | wxALL, 5 );
389 
390  page->m_LowBoxSizer->Add( new wxStaticText( page, -1, _( "Simulator command:" ) ), 0,
391  wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
392 
393  page->m_CommandStringCtrl = new wxTextCtrl( page, -1, m_Parent->GetSimulatorCommand(),
394  wxDefaultPosition, wxDefaultSize );
395 
396  page->m_CommandStringCtrl->SetInsertionPoint( 1 );
397  page->m_LowBoxSizer->Add( page->m_CommandStringCtrl,
398  0,
399  wxGROW | wxLEFT | wxRIGHT | wxBOTTOM,
400  5 );
401 
402  // Add buttons
403  Button = new wxButton( page, ID_RUN_SIMULATOR, _( "&Run Simulator" ) );
404  page->m_RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
405 }
406 
407 
409 {
410  int ii;
411  wxString title, msg;
412  NETLIST_PAGE_DIALOG* currPage;
413 
414  for( ii = 0; ii < CUSTOMPANEL_COUNTMAX; ii++ )
415  {
416  title = UserNetlistTypeName( ii == 0 ? true : false );
417 
418  if( title.IsEmpty() )
419  break; // No more panel to install
420 
421  // Install a plugin panel
423  msg << ii + 1;
424  wxString command = m_config->Read( msg );
425 
426  currPage = AddOneCustomPage( title, command,
428  m_PanelNetType[PANELCUSTOMBASE + ii] = currPage;
429  }
430 }
431 
432 
434  const wxString & aCommandString,
435  NETLIST_TYPE_ID aNetTypeId )
436 {
437  NETLIST_PAGE_DIALOG* currPage;
438 
439  currPage = new NETLIST_PAGE_DIALOG( m_NoteBook, aTitle, aNetTypeId );
440 
441 
442  currPage->m_LowBoxSizer->Add( new wxStaticText( currPage,
443  -1, _( "Netlist command:" ) ), 0,
444  wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
445 
446  currPage->m_CommandStringCtrl = new wxTextCtrl( currPage, -1, aCommandString,
447  wxDefaultPosition, wxDefaultSize );
448 
449  currPage->m_CommandStringCtrl->SetInsertionPoint( 1 );
450  currPage->m_LowBoxSizer->Add( currPage->m_CommandStringCtrl,
451  0,
452  wxGROW | wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT | wxBOTTOM,
453  5 );
454 
455  currPage->m_LowBoxSizer->Add( new wxStaticText( currPage,
456  -1, _( "Title:" ) ), 0,
457  wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
458 
459  currPage->m_TitleStringCtrl = new wxTextCtrl( currPage, -1, aTitle,
460  wxDefaultPosition, wxDefaultSize );
461 
462  currPage->m_TitleStringCtrl->SetInsertionPoint( 1 );
463  currPage->m_LowBoxSizer->Add( currPage->m_TitleStringCtrl,
464  0,
465  wxGROW | wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT | wxBOTTOM,
466  5 );
467  return currPage;
468 }
469 
470 
471 void NETLIST_DIALOG::SelectDefaultNetlistType( wxCommandEvent& event )
472 {
473  int ii;
474  NETLIST_PAGE_DIALOG* currPage;
475 
476  for( ii = 0; ii < PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX; ii++ )
477  if( m_PanelNetType[ii] )
478  m_PanelNetType[ii]->m_IsCurrentFormat->SetValue( false );
479 
480  currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage();
481 
482  if( currPage == NULL )
483  return;
484 
486  currPage->m_IsCurrentFormat->SetValue( true );
487 }
488 
489 
490 void NETLIST_DIALOG::OnNetlistTypeSelection( wxNotebookEvent& event )
491 {
492  NETLIST_PAGE_DIALOG* currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage();
493  if( currPage == NULL )
494  return;
495 
496  m_buttonDelPlugin->Enable( currPage->m_IdNetType >= NET_TYPE_CUSTOM1 );
498 
499  wxString fileExt;
500  if( FilenamePrms( currPage->m_IdNetType, &fileExt, NULL ) )
501  {
502  wxFileName fn = g_RootSheet->GetScreen()->GetFileName();
503  fn.SetExt( fileExt );
504  m_textCtrlDefaultFileName->SetValue( fn.GetFullName() );
505  }
506  else
507  m_textCtrlDefaultFileName->Clear();
508 }
509 
510 
512 {
513  int ii;
514 
515  m_Parent->SetSpiceAjustPassiveValues( m_PanelNetType[PANELSPICE]->m_SpiceAjustPassiveValues->IsChecked() );
516  m_Parent->SetSimulatorCommand( m_PanelNetType[PANELSPICE]->m_CommandStringCtrl->GetValue() );
517  m_Parent->SetNetListFormatName( wxEmptyString );
518 
519  for( ii = 0; ii < PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX; ii++ )
520  {
521  if( m_PanelNetType[ii] == NULL )
522  break;
523 
524  if( m_PanelNetType[ii]->m_IsCurrentFormat->GetValue() == true )
526  }
527 }
528 
529 
530 void NETLIST_DIALOG::GenNetlist( wxCommandEvent& event )
531 {
532  wxFileName fn;
533  wxString fileWildcard;
534  wxString fileExt;
535  wxString title = _( "Save Netlist File" );
536 
538 
539  NETLIST_PAGE_DIALOG* currPage;
540  currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage();
541 
542  unsigned netlist_opt = 0;
543 
544  // Calculate the netlist filename
545  fn = g_RootSheet->GetScreen()->GetFileName();
546  FilenamePrms( currPage->m_IdNetType, &fileExt, &fileWildcard );
547 
548  // Set some parameters
549  switch( currPage->m_IdNetType )
550  {
551  case NET_TYPE_SPICE:
552  // Set spice netlist options:
553  if( currPage->m_SpiceAjustPassiveValues->GetValue() )
554  netlist_opt |= NET_ADJUST_PASSIVE_VALS;
555  break;
556 
557  case NET_TYPE_CADSTAR:
558  break;
559 
560  case NET_TYPE_PCBNEW:
561  break;
562 
563  case NET_TYPE_ORCADPCB2:
564  break;
565 
566  default: // custom, NET_TYPE_CUSTOM1 and greater
567  title.Printf( _( "%s Export" ), currPage->m_TitleStringCtrl->GetValue().GetData() );
568  }
569 
570  fn.SetExt( fileExt );
571 
572  if( fn.GetPath().IsEmpty() )
573  fn.SetPath( wxPathOnly( Prj().GetProjectFullName() ) );
574 
575  wxString fullpath = fn.GetFullPath();
576 
577  if( !GetUseDefaultNetlistName() || currPage->m_IdNetType >= NET_TYPE_CUSTOM1 )
578  {
579  wxString fullname = fn.GetFullName();
580  wxString path = fn.GetPath();
581 
582  // fullname does not and should not include the path, per wx docs.
583  wxFileDialog dlg( this, title, path, fullname, fileWildcard, wxFD_SAVE );
584 
585  if( dlg.ShowModal() == wxID_CANCEL )
586  return;
587 
588  fullpath = dlg.GetPath(); // directory + filename
589  }
590 
592 
593  if( currPage->m_CommandStringCtrl )
594  m_Parent->SetNetListerCommand( currPage->m_CommandStringCtrl->GetValue() );
595  else
596  m_Parent->SetNetListerCommand( wxEmptyString );
597 
598  m_Parent->CreateNetlist( currPage->m_IdNetType, fullpath, netlist_opt );
599 
601 
602  EndModal( wxID_OK );
603 }
604 
605 
607  wxString * aExt, wxString * aWildCard )
608 {
609  wxString fileExt;
610  wxString fileWildcard;
611 
612  bool ret = true;
613 
614  switch( aNetTypeId )
615  {
616  case NET_TYPE_SPICE:
617  fileExt = wxT( "cir" );
618  fileWildcard = _( "SPICE netlist file (.cir)|*.cir" );
619  break;
620 
621  case NET_TYPE_CADSTAR:
622  fileExt = wxT( "frp" );
623  fileWildcard = _( "CadStar netlist file (.frp)|*.frp" );
624  break;
625 
626  case NET_TYPE_PCBNEW:
627  case NET_TYPE_ORCADPCB2:
628  fileExt = NetlistFileExtension;
629  fileWildcard = NetlistFileWildcard;
630  break;
631 
632  default: // custom, NET_TYPE_CUSTOM1 and greater
633  fileWildcard = AllFilesWildcard;
634  ret = false;
635  }
636 
637  if( aExt )
638  *aExt = fileExt;
639 
640  if( aWildCard )
641  *aWildCard = fileWildcard;
642 
643  return ret;
644 }
645 
646 
647 void NETLIST_DIALOG::RunSimulator( wxCommandEvent& event )
648 {
649  wxFileName fn;
650  wxString ExecFile, CommandLine;
651 
653 
654  wxString tmp = m_PanelNetType[PANELSPICE]->m_CommandStringCtrl->GetValue();
655  tmp.Trim( false );
656  tmp.Trim( true );
658  ExecFile = tmp.BeforeFirst( ' ' );
659  CommandLine = tmp.AfterFirst( ' ' );
660 
661  // Calculate the netlist filename
662  fn = g_RootSheet->GetScreen()->GetFileName();
663  fn.SetExt( wxT( "cir" ) );
664  CommandLine += wxT( " \"" ) + fn.GetFullPath() + wxT( "\"" );
665 
666  NETLIST_PAGE_DIALOG* currPage;
667  currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage();
668 
669  // Set spice netlist options:
670  unsigned netlist_opt = 0;
671 
672  if( currPage->m_SpiceAjustPassiveValues && currPage->m_SpiceAjustPassiveValues->GetValue() )
673  netlist_opt |= NET_ADJUST_PASSIVE_VALS;
674 
675  if( ! m_Parent->CreateNetlist( currPage->m_IdNetType, fn.GetFullPath(),
676  netlist_opt ) )
677  return;
678 
679  ExecuteFile( this, ExecFile, CommandLine );
680 }
681 
682 
684 {
685  wxString msg, Command;
686 
688 
690 
691  // Update existing custom pages
692  int jj = 0;
693  for( int ii = 0; ii < CUSTOMPANEL_COUNTMAX; ii++ )
694  {
696 
697  if( currPage == NULL )
698  break;
699 
700  wxString title = currPage->m_TitleStringCtrl->GetValue();
701 
702  if( title.IsEmpty() )
703  continue;
704 
705  msg = CUSTOM_NETLIST_TITLE;
706  msg << jj + 1;
707  m_config->Write( msg, title );
708 
709  Command = currPage->m_CommandStringCtrl->GetValue();
711  msg << jj + 1;
712  m_config->Write( msg, Command );
713  jj++;
714  }
715 
716  // Ensure all other pages are void
717  for(; jj < CUSTOMPANEL_COUNTMAX; jj++ )
718  {
719  msg = CUSTOM_NETLIST_TITLE;
720  msg << jj + 1;
721  m_config->Write( msg, wxEmptyString );
722 
724  msg << jj + 1;
725  m_config->Write( msg, wxEmptyString );
726  }
727 }
728 
729 
730 void NETLIST_DIALOG::OnDelPlugin( wxCommandEvent& event )
731 {
732  NETLIST_PAGE_DIALOG* currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage();
733 
734  currPage->m_CommandStringCtrl->SetValue( wxEmptyString );
735  currPage->m_TitleStringCtrl->SetValue( wxEmptyString );
736 
737  if( currPage->m_IsCurrentFormat->IsChecked() )
738  {
739  currPage->m_IsCurrentFormat->SetValue( false );
740  m_PanelNetType[PANELPCBNEW]->m_IsCurrentFormat->SetValue( true );
741  }
742 
744  EndModal( NET_PLUGIN_CHANGE );
745 }
746 
747 
748 void NETLIST_DIALOG::OnAddPlugin( wxCommandEvent& event )
749 {
750  NETLIST_DIALOG_ADD_PLUGIN dlg( this );
751  if( dlg.ShowModal() != wxID_OK )
752  return;
753 
754  // Creates a new custom plugin page
755  wxString title = dlg.GetPluginTitle();
756 
757  // Verify it does not exists
758  int netTypeId = PANELCUSTOMBASE; // the first not used type id
759  NETLIST_PAGE_DIALOG* currPage;
760  for( int ii = 0; ii < CUSTOMPANEL_COUNTMAX; ii++ )
761  {
762  netTypeId = PANELCUSTOMBASE + ii;
763  currPage = m_PanelNetType[ii + PANELCUSTOMBASE];
764 
765  if( currPage == NULL )
766  break;
767 
768  if( currPage->GetPageNetFmtName() == title )
769  {
770  wxMessageBox( _("This plugin already exists. Abort") );
771  return;
772  }
773  }
774 
775  wxString cmd = dlg.GetPluginTCommandLine();
776  currPage = AddOneCustomPage( title,cmd, (NETLIST_TYPE_ID)netTypeId );
777  m_PanelNetType[netTypeId] = currPage;
779 
780  // Close and reopen dialog to rebuild the dialog after changes
781  EndModal( NET_PLUGIN_CHANGE );
782 }
783 
784 
787 {
788  m_Parent = parent;
789  GetSizer()->SetSizeHints( this );
790 }
791 
792 
793 void NETLIST_DIALOG_ADD_PLUGIN::OnOKClick( wxCommandEvent& event )
794 {
795  if( m_textCtrlCommand->GetValue() == wxEmptyString )
796  {
797  wxMessageBox( _( "Error. You must provide a command String" ) );
798  return;
799  }
800 
801  if( m_textCtrlName->GetValue() == wxEmptyString )
802  {
803  wxMessageBox( _( "Error. You must provide a Title" ) );
804  return;
805  }
806 
807  EndModal( wxID_OK );
808 }
809 
810 
811 void NETLIST_DIALOG_ADD_PLUGIN::OnBrowsePlugins( wxCommandEvent& event )
812 {
813  wxString FullFileName, Mask, Path;
814 
815  Mask = wxT( "*" );
816 #ifndef __WXMAC__
817  Path = Pgm().GetExecutablePath();
818 #else
819  Path = GetOSXKicadDataDir() + wxT( "/plugins" );
820 #endif
821  FullFileName = EDA_FILE_SELECTOR( _( "Plugin files:" ),
822  Path,
823  FullFileName,
824  wxEmptyString,
825  Mask,
826  this,
827  wxFD_OPEN,
828  true
829  );
830  if( FullFileName.IsEmpty() )
831  return;
832 
833  // Creates a default command line, suitable for external tool xslproc or python
834  // try to build a default command line depending on plugin extension
835  // "xsl" or "exe" or "py"
836  wxString cmdLine;
837  wxFileName fn( FullFileName );
838  wxString ext = fn.GetExt();
839 
840  if( ext == wxT("xsl" ) )
841  cmdLine.Printf(wxT("xsltproc -o \"%%O\" \"%s\" \"%%I\""), GetChars(FullFileName) );
842  else if( ext == wxT("exe" ) || ext.IsEmpty() )
843  cmdLine.Printf(wxT("\"%s\" > \"%%O\" < \"%%I\""), GetChars(FullFileName) );
844  else if( ext == wxT("py" ) || ext.IsEmpty() )
845  cmdLine.Printf(wxT("python \"%s\" \"%%I\" \"%%O\""), GetChars(FullFileName) );
846  else
847  cmdLine.Printf(wxT("\"%s\""), GetChars(FullFileName) );
848 
849  m_textCtrlCommand->SetValue( cmdLine );
850 
851  /* Get a title for this page */
852  wxString title = m_textCtrlName->GetValue();
853 
854  if( title.IsEmpty() )
855  wxMessageBox( _( "Do not forget to choose a title for this netlist control page" ) );
856 }
857 
858 
860 {
861  NETLIST_DIALOG dlg( aCaller );
862 
863  return dlg.ShowModal();
864 }
865 
Definition of the SCH_SHEET class for Eeschema.
const wxString GetNetListFormatName() const
Definition: schframe.h:247
wxTextCtrl * m_textCtrlDefaultFileName
wxString GetSimulatorCommand() const
Definition: schframe.h:1371
This file is part of the common library TODO brief description.
NETLIST_PAGE_DIALOG(wxNotebook *parent, const wxString &title, NETLIST_TYPE_ID id_NetType)
Constructor to create a setup page for one netlist format.
void RunSimulator(wxCommandEvent &event)
VTBL_ENTRY const wxString & GetExecutablePath() const
Definition: pgm_base.h:173
const wxString AllFilesWildcard
const wxString & GetFileName() const
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
const wxString NetlistFileExtension
EVT_CHECKBOX(ID_CURRENT_FORMAT_IS_DEFAULT, NETLIST_DIALOG::SelectDefaultNetlistType) NETLIST_PAGE_DIALOG
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
void SetSimulatorCommand(const wxString &aCommand)
Definition: schframe.h:1369
Schematic editor (Eeschema) main window.
Definition: schframe.h:117
SCH_SCREEN * GetScreen()
Definition: sch_sheet.h:286
#define CUSTOM_NETLIST_COMMAND
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
wxCheckBox * m_cbUseDefaultNetlistName
NETLIST_TYPE_ID
netlist types
Definition: netlist.h:35
void OnAddPlugin(wxCommandEvent &event) override
Function OnAddPlugin Add a new panel for a new netlist plugin.
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
bool FilenamePrms(NETLIST_TYPE_ID aNetTypeId, wxString *aExt, wxString *aWildCard)
Function FilenamePrms returns the filename extension and the wildcard string for this curr or a void ...
#define NETLIST_USE_DEFAULT_NETNAME
Class NETLIST_DIALOG_BASE.
void WriteCurrentNetlistSetup()
Function WriteCurrentNetlistSetup Write the current netlist options setup in the configuration.
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:54
NETLIST_DIALOG(SCH_EDIT_FRAME *parent)
#define CUSTOMPANEL_COUNTMAX
bool CreateNetlist(int aFormat, const wxString &aFullFileName, unsigned aNetlistOptions, REPORTER *aReporter=NULL)
Function CreateNetlist.
const wxString NetlistFileWildcard
wxString EDA_FILE_SELECTOR(const wxString &aTitle, const wxString &aPath, const wxString &aFileName, const wxString &aExtension, const wxString &aWildcard, wxWindow *aParent, int aStyle, const bool aKeepWorkingDirectory, const wxPoint &aPosition, wxString *aMruPath)
Function EDA_FILE_SELECTOR.
Definition: gestfich.cpp:82
void OnDelPlugin(wxCommandEvent &event) override
Function OnDelPlugin Remove a panel relative to a netlist plugin.
The common library.
Helper dialog and control classes.
const wxString UserNetlistTypeName(bool first_item)
Function UserNetlistTypeName to retrieve user netlist type names.
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:101
#define CUSTOM_NETLIST_TITLE
bool GetSpiceAjustPassiveValues() const
Definition: schframe.h:251
NETLIST_DIALOG_ADD_PLUGIN(NETLIST_DIALOG *parent)
NETLIST_PAGE_DIALOG * m_PanelNetType[4+CUSTOMPANEL_COUNTMAX]
NETLIST_PAGE_DIALOG * AddOneCustomPage(const wxString &aTitle, const wxString &aCommandString, NETLIST_TYPE_ID aNetTypeId)
void SetNetListFormatName(const wxString &aFormat)
Definition: schframe.h:249
Class NETLIST_DIALOG_ADD_PLUGIN_BASE.
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
see class PGM_BASE
void OnOKClick(wxCommandEvent &event) override
Function OnOKClick Validate info relative to a new netlist plugin.
#define NET_PLUGIN_CHANGE
Function InvokeDialogNetList creates and shows NETLIST_DIALOG and returns whatever NETLIST_DIALOG::Sh...
const char * name
void OnBrowsePlugins(wxCommandEvent &event) override
void GenNetlist(wxCommandEvent &event) override
int ExecuteFile(wxWindow *frame, const wxString &ExecFile, const wxString &param, wxProcess *callback)
Function ExecuteFile calls the executable file ExecFile with the command line parameters param...
Definition: gestfich.cpp:208
void SetNetListerCommand(const wxString &aCommand)
Definition: schframe.h:1373
void OnNetlistTypeSelection(wxNotebookEvent &event) override
void ClearMsgPanel(void)
Clear all messages from the message panel.
Definition: draw_frame.cpp:745
void SetSpiceAjustPassiveValues(bool aEnable)
Definition: schframe.h:253
const wxString GetPageNetFmtName()
function GetPageNetFmtName
int InvokeDialogNetList(SCH_EDIT_FRAME *aCaller)
void SelectDefaultNetlistType(wxCommandEvent &event)