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-2017 Jean-Pierre Charras, jp.charras@wanadoo.fr
5  * Copyright (C) 2013 Wayne Stambaugh <stambaughw@gmail.com>
6  * Copyright (C) 1992-2018 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 <sch_edit_frame.h>
46 
47 #include <general.h>
48 #include <netlist.h>
49 #include <sch_sheet.h>
50 #include <dialog_helpers.h>
51 #include <dialogs/dialog_netlist_base.h>
54 #include <invoke_sch_dialog.h>
56 
57 #include <eeschema_id.h>
58 #include <wx/regex.h>
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 
149  // Called when changing the notebook page, therefore the current
150  // netlist format
151  void OnNetlistTypeSelection( wxNotebookEvent& event ) override;
152 
153  // called when checking the "Default format" wxCheckBox
154  // in the current page of the notbook
155  void SelectDefaultNetlistType( wxCommandEvent& event );
156 
161  void OnAddPlugin( wxCommandEvent& event ) override;
162 
167  void OnDelPlugin( wxCommandEvent& event ) override;
168 
174 
183  const wxString UserNetlistTypeName( bool first_item );
184 
194  bool FilenamePrms( NETLIST_TYPE_ID aNetTypeId,
195  wxString * aExt, wxString * aWildCard );
196 
197  DECLARE_EVENT_TABLE()
198 };
199 
200 
202 {
203 private:
205 
206 public:
208  const wxString GetPluginTitle()
209  {
210  return m_textCtrlName->GetValue();
211  }
212  const wxString GetPluginTCommandLine()
213  {
214  return m_textCtrlCommand->GetValue();
215  }
216 
217 private:
218 
223  void OnOKClick( wxCommandEvent& event ) override;
224 
225  /*
226  * Browse plugin files, and set m_CommandStringCtrl field
227  */
228  void OnBrowsePlugins( wxCommandEvent& event ) override;
229 };
230 
231 
232 /* Event id for notebook page buttons: */
239 };
240 
241 
242 // keywords for configuration:
243 #define CUSTOM_NETLIST_TITLE wxT( "CustomNetlistTitle" )
244 #define CUSTOM_NETLIST_COMMAND wxT( "CustomNetlistCommand" )
245 #define NETLIST_USE_DEFAULT_NETNAME wxT( "NetlistUseDefaultNetname" )
246 #define NETLIST_PSPICE_USE_NETNAME wxT( "SpiceUseNetNames" )
247 
248 
249 BEGIN_EVENT_TABLE( NETLIST_DIALOG, NETLIST_DIALOG_BASE )
252  NETLIST_DIALOG::SelectDefaultNetlistType )
253  EVT_BUTTON( ID_RUN_SIMULATOR, NETLIST_DIALOG::RunSimulator )
254 END_EVENT_TABLE()
255 
256 
257 
258 NETLIST_PAGE_DIALOG::NETLIST_PAGE_DIALOG( wxNotebook* parent,
259  const wxString& title,
260  NETLIST_TYPE_ID id_NetType ) :
261  wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL )
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 | wxBOTTOM | wxRIGHT, 5 );
293 
294  m_IsCurrentFormat = new wxCheckBox( this, ID_CURRENT_FORMAT_IS_DEFAULT, _( "Default format" ) );
295  m_LeftBoxSizer->Add( m_IsCurrentFormat, 0, wxGROW | wxBOTTOM | wxRIGHT, 5 );
296  m_IsCurrentFormat->SetValue( selected );
297 
298  if( selected )
299  ((NETLIST_DIALOG*)parent->GetParent())->m_asFormatSelected = true;
300 }
301 
302 
303 
305  NETLIST_DIALOG_BASE( parent )
306 {
307  m_Parent = parent;
309 
310  long tmp;
311  m_config->Read( NETLIST_USE_DEFAULT_NETNAME, &tmp, 0l );
313 
314  for( int ii = 0; ii < PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX; ii++ )
315  {
316  m_PanelNetType[ii] = NULL;
317  }
318 
319  // Add notebook pages:
320  m_asFormatSelected = false; // Will be set to true, if a format is selected
321 
322  // Add Panel FORMAT PCBNEW
324  new NETLIST_PAGE_DIALOG( m_NoteBook, wxT( "Pcbnew" ),
325  NET_TYPE_PCBNEW );
326 
327  // Add Panel FORMAT ORCADPCB2
329  new NETLIST_PAGE_DIALOG( m_NoteBook, wxT( "OrcadPCB2" ),
331 
332  // Add Panel FORMAT CADSTAR
334  new NETLIST_PAGE_DIALOG( m_NoteBook, wxT( "CadStar" ),
336 
337  // Add Panel spice
339 
340  // Add custom panels:
342 
343  // Ensure a netlist format is selected:
344  if( !m_asFormatSelected )
345  {
346  m_PanelNetType[PANELPCBNEW]->m_IsCurrentFormat->SetValue( true );
347  m_NoteBook->SetSelection( PANELPCBNEW );
348  // call OnNetlistTypeSelection to update some widgets.
349  // SetSelection() do nothing if the current page is already PANELPCBNEW
350  wxNotebookEvent event;
351  OnNetlistTypeSelection( event );
352  }
353 
354  SetDefaultItem( m_buttonNetlist );
355 
356  // Now all widgets have the size fixed, call FinishDialogSettings
358 }
359 
360 
361 const wxString NETLIST_DIALOG::UserNetlistTypeName( bool first_item )
362 {
363  static int index;
364  wxString name, msg;
365 
366  if( first_item )
367  index = 0;
368  else
369  index++;
370 
371  msg = CUSTOM_NETLIST_TITLE;
372  msg << index + 1;
373 
374  name = m_config->Read( msg );
375 
376  return name;
377 }
378 
379 
381 {
382  wxButton* Button;
383  NETLIST_PAGE_DIALOG* page;
384  wxString title = wxT( "Spice" );
385 
386  page = m_PanelNetType[PANELSPICE] =
388 
389  page->m_SpiceAjustPassiveValues = new wxCheckBox( page, ID_USE_NETCODE_AS_NETNAME,
390  _( "Reformat passive symbol values" ) );
391  page->m_SpiceAjustPassiveValues->SetToolTip(
392  _( "Reformat passive symbol values e.g. 1M -> 1Meg" ) );
394  page->m_LeftBoxSizer->Add( page->m_SpiceAjustPassiveValues, 0,
395  wxGROW | wxBOTTOM | wxRIGHT, 5 );
396 
397  page->m_LowBoxSizer->Add( new wxStaticText( page, -1, _( "Simulator command:" ) ), 0,
398  wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
399 
400  page->m_CommandStringCtrl = new wxTextCtrl( page, -1, m_Parent->GetSimulatorCommand(),
401  wxDefaultPosition, wxDefaultSize );
402 
403  page->m_CommandStringCtrl->SetInsertionPoint( 1 );
404  page->m_LowBoxSizer->Add( page->m_CommandStringCtrl,
405  0,
406  wxGROW | wxLEFT | wxRIGHT | wxBOTTOM,
407  5 );
408 
409  // Add buttons
410  Button = new wxButton( page, ID_RUN_SIMULATOR, _( "&Run Simulator" ) );
411  page->m_LowBoxSizer->Add( Button, 0, wxGROW | wxBOTTOM | wxLEFT | wxRIGHT, 5 );
412 }
413 
414 
416 {
417  int ii;
418  wxString title, msg;
419  NETLIST_PAGE_DIALOG* currPage;
420 
421  for( ii = 0; ii < CUSTOMPANEL_COUNTMAX; ii++ )
422  {
423  title = UserNetlistTypeName( ii == 0 ? true : false );
424 
425  if( title.IsEmpty() )
426  break; // No more panel to install
427 
428  // Install a plugin panel
430  msg << ii + 1;
431  wxString command = m_config->Read( msg );
432 
433  currPage = AddOneCustomPage( title, command,
435  m_PanelNetType[PANELCUSTOMBASE + ii] = currPage;
436  }
437 }
438 
439 
441  const wxString & aCommandString,
442  NETLIST_TYPE_ID aNetTypeId )
443 {
444  NETLIST_PAGE_DIALOG* currPage;
445 
446  currPage = new NETLIST_PAGE_DIALOG( m_NoteBook, aTitle, aNetTypeId );
447 
448 
449  currPage->m_LowBoxSizer->Add( new wxStaticText( currPage,
450  -1, _( "Netlist command:" ) ), 0,
451  wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
452 
453  currPage->m_CommandStringCtrl = new wxTextCtrl( currPage, -1, aCommandString,
454  wxDefaultPosition, wxDefaultSize );
455 
456  currPage->m_CommandStringCtrl->SetInsertionPoint( 1 );
457  currPage->m_LowBoxSizer->Add( currPage->m_CommandStringCtrl,
458  0,
459  wxGROW | wxTOP | wxLEFT | wxRIGHT | wxBOTTOM,
460  5 );
461 
462  currPage->m_LowBoxSizer->Add( new wxStaticText( currPage,
463  -1, _( "Title:" ) ), 0,
464  wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
465 
466  currPage->m_TitleStringCtrl = new wxTextCtrl( currPage, -1, aTitle,
467  wxDefaultPosition, wxDefaultSize );
468 
469  currPage->m_TitleStringCtrl->SetInsertionPoint( 1 );
470  currPage->m_LowBoxSizer->Add( currPage->m_TitleStringCtrl,
471  0,
472  wxGROW | wxTOP | wxLEFT | wxRIGHT | wxBOTTOM,
473  5 );
474  return currPage;
475 }
476 
477 
478 void NETLIST_DIALOG::SelectDefaultNetlistType( wxCommandEvent& event )
479 {
480  int ii;
481  NETLIST_PAGE_DIALOG* currPage;
482 
483  for( ii = 0; ii < PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX; ii++ )
484  if( m_PanelNetType[ii] )
485  m_PanelNetType[ii]->m_IsCurrentFormat->SetValue( false );
486 
487  currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage();
488 
489  if( currPage == NULL )
490  return;
491 
493  currPage->m_IsCurrentFormat->SetValue( true );
494 }
495 
496 
497 void NETLIST_DIALOG::OnNetlistTypeSelection( wxNotebookEvent& event )
498 {
499  NETLIST_PAGE_DIALOG* currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage();
500 
501  if( currPage == NULL )
502  return;
503 
504  m_buttonDelPlugin->Enable( currPage->m_IdNetType >= NET_TYPE_CUSTOM1 );
505 }
506 
507 
509 {
510  int ii;
511 
512  m_Parent->SetSpiceAjustPassiveValues( m_PanelNetType[PANELSPICE]->m_SpiceAjustPassiveValues->IsChecked() );
513  m_Parent->SetSimulatorCommand( m_PanelNetType[PANELSPICE]->m_CommandStringCtrl->GetValue() );
514  m_Parent->SetNetListFormatName( wxEmptyString );
515 
516  for( ii = 0; ii < PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX; ii++ )
517  {
518  if( m_PanelNetType[ii] == NULL )
519  break;
520 
521  if( m_PanelNetType[ii]->m_IsCurrentFormat->GetValue() == true )
523  }
524 }
525 
526 
527 void NETLIST_DIALOG::GenNetlist( wxCommandEvent& event )
528 {
529  wxFileName fn;
530  wxString fileWildcard;
531  wxString fileExt;
532  wxString title = _( "Save Netlist File" );
533 
535 
536  NETLIST_PAGE_DIALOG* currPage;
537  currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage();
538 
539  unsigned netlist_opt = 0;
540 
541  // Calculate the netlist filename
542  fn = g_RootSheet->GetScreen()->GetFileName();
543  FilenamePrms( currPage->m_IdNetType, &fileExt, &fileWildcard );
544 
545  // Set some parameters
546  switch( currPage->m_IdNetType )
547  {
548  case NET_TYPE_SPICE:
549  // Set spice netlist options:
550  if( currPage->m_SpiceAjustPassiveValues->GetValue() )
551  netlist_opt |= NET_ADJUST_PASSIVE_VALS;
552  break;
553 
554  case NET_TYPE_CADSTAR:
555  break;
556 
557  case NET_TYPE_PCBNEW:
558  break;
559 
560  case NET_TYPE_ORCADPCB2:
561  break;
562 
563  default: // custom, NET_TYPE_CUSTOM1 and greater
564  {
565  wxString command = currPage->m_CommandStringCtrl->GetValue();
566  wxRegEx extRE( wxT( ".*\\.([[:alnum:]][[:alnum:]][[:alnum:]][[:alnum:]]?)\\.xslt?\".*" ) );
567 
568  if( extRE.Matches( command ) )
569  fileExt = extRE.GetMatch( command, 1 );
570 
571  title.Printf( _( "%s Export" ), currPage->m_TitleStringCtrl->GetValue().GetData() );
572  }
573  break;
574  }
575 
576  fn.SetExt( fileExt );
577 
578  if( fn.GetPath().IsEmpty() )
579  fn.SetPath( wxPathOnly( Prj().GetProjectFullName() ) );
580 
581  wxString fullpath = fn.GetFullPath();
582  wxString fullname = fn.GetFullName();
583  wxString path = fn.GetPath();
584 
585  // fullname does not and should not include the path, per wx docs.
586  wxFileDialog dlg( this, title, path, fullname, fileWildcard, wxFD_SAVE );
587 
588  if( dlg.ShowModal() == wxID_CANCEL )
589  return;
590 
591  fullpath = dlg.GetPath(); // directory + filename
592 
594 
595  if( currPage->m_CommandStringCtrl )
596  m_Parent->SetNetListerCommand( currPage->m_CommandStringCtrl->GetValue() );
597  else
598  m_Parent->SetNetListerCommand( wxEmptyString );
599 
600  auto netlist = m_Parent->CreateNetlist( false, false );
601 
602  if( netlist == nullptr )
603  wxMessageBox( _( "Schematic netlist not available" ) );
604  else
605  m_Parent->WriteNetListFile( netlist, currPage->m_IdNetType,
606  fullpath, netlist_opt, NULL );
607 
609 
610  EndModal( wxID_OK );
611 }
612 
613 
615  wxString * aExt, wxString * aWildCard )
616 {
617  wxString fileExt;
618  wxString fileWildcard;
619 
620  bool ret = true;
621 
622  switch( aNetTypeId )
623  {
624  case NET_TYPE_SPICE:
625  fileExt = wxT( "cir" );
626  fileWildcard = SpiceNetlistFileWildcard();
627  break;
628 
629  case NET_TYPE_CADSTAR:
630  fileExt = wxT( "frp" );
631  fileWildcard = CadstarNetlistFileWildcard();
632  break;
633 
634  case NET_TYPE_PCBNEW:
635  case NET_TYPE_ORCADPCB2:
636  fileExt = NetlistFileExtension;
637  fileWildcard = NetlistFileWildcard();
638  break;
639 
640  default: // custom, NET_TYPE_CUSTOM1 and greater
641  fileWildcard = AllFilesWildcard();
642  ret = false;
643  }
644 
645  if( aExt )
646  *aExt = fileExt;
647 
648  if( aWildCard )
649  *aWildCard = fileWildcard;
650 
651  return ret;
652 }
653 
654 
655 void NETLIST_DIALOG::RunSimulator( wxCommandEvent& event )
656 {
657  wxFileName fn;
658  wxString ExecFile, CommandLine;
659 
661 
662  wxString tmp = m_PanelNetType[PANELSPICE]->m_CommandStringCtrl->GetValue();
663  tmp.Trim( false );
664  tmp.Trim( true );
666  ExecFile = tmp.BeforeFirst( ' ' );
667  CommandLine = tmp.AfterFirst( ' ' );
668 
669  // Calculate the netlist filename
670  fn = g_RootSheet->GetScreen()->GetFileName();
671  fn.SetExt( wxT( "cir" ) );
672  CommandLine += wxT( " \"" ) + fn.GetFullPath() + wxT( "\"" );
673 
674  NETLIST_PAGE_DIALOG* currPage;
675  currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage();
676 
677  // Set spice netlist options:
678  unsigned netlist_opt = 0;
679 
680  if( currPage->m_SpiceAjustPassiveValues && currPage->m_SpiceAjustPassiveValues->GetValue() )
681  netlist_opt |= NET_ADJUST_PASSIVE_VALS;
682 
683  auto netlist = m_Parent->CreateNetlist( false, false );
684 
685  if( ! m_Parent->WriteNetListFile( netlist, currPage->m_IdNetType,
686  fn.GetFullPath(), netlist_opt, NULL ) )
687  return;
688 
689  ExecuteFile( this, ExecFile, CommandLine );
690 }
691 
692 
694 {
695  wxString msg, Command;
696 
698 
699  // Update existing custom pages
700  int jj = 0;
701  for( int ii = 0; ii < CUSTOMPANEL_COUNTMAX; ii++ )
702  {
704 
705  if( currPage == NULL )
706  break;
707 
708  wxString title = currPage->m_TitleStringCtrl->GetValue();
709 
710  if( title.IsEmpty() )
711  continue;
712 
713  msg = CUSTOM_NETLIST_TITLE;
714  msg << jj + 1;
715  m_config->Write( msg, title );
716 
717  Command = currPage->m_CommandStringCtrl->GetValue();
719  msg << jj + 1;
720  m_config->Write( msg, Command );
721  jj++;
722  }
723 
724  // Ensure all other pages are void
725  for(; jj < CUSTOMPANEL_COUNTMAX; jj++ )
726  {
727  msg = CUSTOM_NETLIST_TITLE;
728  msg << jj + 1;
729  m_config->Write( msg, wxEmptyString );
730 
732  msg << jj + 1;
733  m_config->Write( msg, wxEmptyString );
734  }
735 }
736 
737 
738 void NETLIST_DIALOG::OnDelPlugin( wxCommandEvent& event )
739 {
740  NETLIST_PAGE_DIALOG* currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage();
741 
742  currPage->m_CommandStringCtrl->SetValue( wxEmptyString );
743  currPage->m_TitleStringCtrl->SetValue( wxEmptyString );
744 
745  if( currPage->m_IsCurrentFormat->IsChecked() )
746  {
747  currPage->m_IsCurrentFormat->SetValue( false );
748  m_PanelNetType[PANELPCBNEW]->m_IsCurrentFormat->SetValue( true );
749  }
750 
752  EndModal( NET_PLUGIN_CHANGE );
753 }
754 
755 
756 void NETLIST_DIALOG::OnAddPlugin( wxCommandEvent& event )
757 {
758  NETLIST_DIALOG_ADD_PLUGIN dlg( this );
759  if( dlg.ShowModal() != wxID_OK )
760  return;
761 
762  // Creates a new custom plugin page
763  wxString title = dlg.GetPluginTitle();
764 
765  // Verify it does not exists
766  int netTypeId = PANELCUSTOMBASE; // the first not used type id
767  NETLIST_PAGE_DIALOG* currPage;
768  for( int ii = 0; ii < CUSTOMPANEL_COUNTMAX; ii++ )
769  {
770  netTypeId = PANELCUSTOMBASE + ii;
771  currPage = m_PanelNetType[ii + PANELCUSTOMBASE];
772 
773  if( currPage == NULL )
774  break;
775 
776  if( currPage->GetPageNetFmtName() == title )
777  {
778  wxMessageBox( _("This plugin already exists. Abort") );
779  return;
780  }
781  }
782 
783  wxString cmd = dlg.GetPluginTCommandLine();
784  currPage = AddOneCustomPage( title,cmd, (NETLIST_TYPE_ID)netTypeId );
785  m_PanelNetType[netTypeId] = currPage;
787 
788  // Close and reopen dialog to rebuild the dialog after changes
789  EndModal( NET_PLUGIN_CHANGE );
790 }
791 
792 
795 {
796  m_Parent = parent;
797  GetSizer()->SetSizeHints( this );
798 }
799 
800 
801 void NETLIST_DIALOG_ADD_PLUGIN::OnOKClick( wxCommandEvent& event )
802 {
803  if( m_textCtrlCommand->GetValue() == wxEmptyString )
804  {
805  wxMessageBox( _( "Error. You must provide a command String" ) );
806  return;
807  }
808 
809  if( m_textCtrlName->GetValue() == wxEmptyString )
810  {
811  wxMessageBox( _( "Error. You must provide a Title" ) );
812  return;
813  }
814 
815  EndModal( wxID_OK );
816 }
817 
818 
819 void NETLIST_DIALOG_ADD_PLUGIN::OnBrowsePlugins( wxCommandEvent& event )
820 {
821  wxString FullFileName, Path;
822 
823 #ifndef __WXMAC__
824  Path = Pgm().GetExecutablePath();
825 #else
826  Path = GetOSXKicadDataDir() + wxT( "/plugins" );
827 #endif
828  FullFileName = EDA_FILE_SELECTOR( _( "Plugin files:" ),
829  Path,
830  FullFileName,
831  wxEmptyString,
832  wxFileSelectorDefaultWildcardStr,
833  this,
834  wxFD_OPEN,
835  true
836  );
837  if( FullFileName.IsEmpty() )
838  return;
839 
840  // Creates a default command line, suitable for external tool xslproc or python
841  // try to build a default command line depending on plugin extension
842  // "xsl" or "exe" or "py"
843  wxString cmdLine;
844  wxFileName fn( FullFileName );
845  wxString ext = fn.GetExt();
846 
847  if( ext == wxT("xsl" ) )
848  cmdLine.Printf(wxT("xsltproc -o \"%%O\" \"%s\" \"%%I\""), GetChars(FullFileName) );
849  else if( ext == wxT("exe" ) || ext.IsEmpty() )
850  cmdLine.Printf(wxT("\"%s\" > \"%%O\" < \"%%I\""), GetChars(FullFileName) );
851  else if( ext == wxT("py" ) || ext.IsEmpty() )
852  cmdLine.Printf(wxT("python \"%s\" \"%%I\" \"%%O\""), GetChars(FullFileName) );
853  else
854  cmdLine.Printf(wxT("\"%s\""), GetChars(FullFileName) );
855 
856  m_textCtrlCommand->SetValue( cmdLine );
857 
858  /* Get a title for this page */
859  wxString title = m_textCtrlName->GetValue();
860 
861  if( title.IsEmpty() )
862  wxMessageBox( _( "Do not forget to choose a title for this netlist control page" ) );
863 }
864 
865 
867 {
868  NETLIST_DIALOG dlg( aCaller );
869 
870  return dlg.ShowModal();
871 }
const std::string NetlistFileExtension
const wxString GetNetListFormatName() const
const wxString & GetFileName() const
Definition: sch_screen.h:124
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)
wxString SpiceNetlistFileWildcard()
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
EVT_CHECKBOX(ID_CURRENT_FORMAT_IS_DEFAULT, NETLIST_DIALOG::SelectDefaultNetlistType) NETLIST_PAGE_DIALOG
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
void SetSimulatorCommand(const wxString &aCommand)
Schematic editor (Eeschema) main window.
SCH_SCREEN * GetScreen()
Definition: sch_sheet.h:268
wxString AllFilesWildcard()
#define CUSTOM_NETLIST_COMMAND
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
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.
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
void WriteCurrentNetlistSetup()
Function WriteCurrentNetlistSetup Write the current netlist options setup in the configuration.
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:56
NETLIST_DIALOG(SCH_EDIT_FRAME *parent)
#define CUSTOMPANEL_COUNTMAX
wxString NetlistFileWildcard()
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
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.
Definition of file extensions used in Kicad.
Helper dialog and control classes.
const wxString UserNetlistTypeName(bool first_item)
Function UserNetlistTypeName to retrieve user netlist type names.
#define CUSTOM_NETLIST_TITLE
virtual void ClearMsgPanel()
Clear all messages from the message panel.
wxString GetSimulatorCommand() const
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)
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:100
see class PGM_BASE
const char * name
Definition: DXF_plotter.cpp:61
NETLIST_OBJECT_LIST * CreateNetlist(bool aSilent=false, bool aSilentAnnotate=false)
Create a netlist for the current schematic.
void OnOKClick(wxCommandEvent &event) override
Function OnOKClick Validate info relative to a new netlist plugin.
VTBL_ENTRY const wxString & GetExecutablePath() const
Definition: pgm_base.h:218
#define NET_PLUGIN_CHANGE
Create and shows NETLIST_DIALOG and returns whatever NETLIST_DIALOG::ShowModal() returns.
void OnBrowsePlugins(wxCommandEvent &event) override
bool GetSpiceAjustPassiveValues() const
void GenNetlist(wxCommandEvent &event) override
bool WriteNetListFile(NETLIST_OBJECT_LIST *aConnectedItemsList, int aFormat, const wxString &aFullFileName, unsigned aNetlistOptions, REPORTER *aReporter=NULL)
Create a netlist file.
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)
void OnNetlistTypeSelection(wxNotebookEvent &event) override
void SetSpiceAjustPassiveValues(bool aEnable)
const wxString GetPageNetFmtName()
function GetPageNetFmtName
int InvokeDialogNetList(SCH_EDIT_FRAME *aCaller)
void SelectDefaultNetlistType(wxCommandEvent &event)
wxString CadstarNetlistFileWildcard()