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 
173  void WriteCurrentNetlistSetup();
174 
176  {
177  return m_cbUseDefaultNetlistName->IsChecked();
178  }
179 
188  const wxString UserNetlistTypeName( bool first_item );
189 
199  bool FilenamePrms( NETLIST_TYPE_ID aNetTypeId,
200  wxString * aExt, wxString * aWildCard );
201 
202  DECLARE_EVENT_TABLE()
203 };
204 
205 
207 {
208 private:
210 
211 public:
213  const wxString GetPluginTitle()
214  {
215  return m_textCtrlName->GetValue();
216  }
217  const wxString GetPluginTCommandLine()
218  {
219  return m_textCtrlCommand->GetValue();
220  }
221 
222 private:
223 
228  void OnOKClick( wxCommandEvent& event ) override;
229 
230  /*
231  * Browse plugin files, and set m_CommandStringCtrl field
232  */
233  void OnBrowsePlugins( wxCommandEvent& event ) override;
234 };
235 
236 
237 /* Event id for notebook page buttons: */
244 };
245 
246 
247 // keywords for configuration:
248 #define CUSTOM_NETLIST_TITLE wxT( "CustomNetlistTitle" )
249 #define CUSTOM_NETLIST_COMMAND wxT( "CustomNetlistCommand" )
250 #define NETLIST_USE_DEFAULT_NETNAME wxT( "NetlistUseDefaultNetname" )
251 #define NETLIST_PSPICE_USE_NETNAME wxT( "SpiceUseNetNames" )
252 
253 
254 BEGIN_EVENT_TABLE( NETLIST_DIALOG, NETLIST_DIALOG_BASE )
255  EVT_BUTTON( ID_CREATE_NETLIST, NETLIST_DIALOG::GenNetlist )
257  NETLIST_DIALOG::SelectDefaultNetlistType )
258  EVT_BUTTON( ID_RUN_SIMULATOR, NETLIST_DIALOG::RunSimulator )
259 END_EVENT_TABLE()
260 
261 
262 
263 NETLIST_PAGE_DIALOG::NETLIST_PAGE_DIALOG( wxNotebook* parent,
264  const wxString& title,
265  NETLIST_TYPE_ID id_NetType ) :
266  wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL )
267 {
268  m_IdNetType = id_NetType;
269  m_pageNetFmtName = title;
270  m_CommandStringCtrl = NULL;
271  m_TitleStringCtrl = NULL;
272  m_IsCurrentFormat = NULL;
274  m_ButtonCancel = NULL;
275 
276  wxString netfmtName = ((NETLIST_DIALOG*)parent->GetParent())->m_NetFmtName;
277 
278  bool selected = m_pageNetFmtName == netfmtName;
279 
280  parent->AddPage( this, title, selected );
281 
282  wxBoxSizer* MainBoxSizer = new wxBoxSizer( wxVERTICAL );
283  SetSizer( MainBoxSizer );
284  wxBoxSizer* UpperBoxSizer = new wxBoxSizer( wxHORIZONTAL );
285  m_LowBoxSizer = new wxBoxSizer( wxVERTICAL );
286  MainBoxSizer->Add( UpperBoxSizer, 0, wxGROW | wxALL, 5 );
287  MainBoxSizer->Add( m_LowBoxSizer, 0, wxGROW | wxALL, 5 );
288 
289  m_LeftBoxSizer = new wxBoxSizer( wxVERTICAL );
290  m_RightBoxSizer = new wxBoxSizer( wxVERTICAL );
291  m_RightOptionsBoxSizer = new wxBoxSizer( wxVERTICAL );
292  UpperBoxSizer->Add( m_LeftBoxSizer, 0, wxGROW | wxALL, 5 );
293  UpperBoxSizer->Add( m_RightBoxSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
294  UpperBoxSizer->Add( m_RightOptionsBoxSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
295 
296  wxStaticText* text = new wxStaticText( this, -1, _( "Options:" ) );
297  m_LeftBoxSizer->Add( text, 0, wxGROW | wxBOTTOM | wxRIGHT, 5 );
298 
299  m_IsCurrentFormat = new wxCheckBox( this, ID_CURRENT_FORMAT_IS_DEFAULT, _( "Default format" ) );
300  m_LeftBoxSizer->Add( m_IsCurrentFormat, 0, wxGROW | wxBOTTOM | wxRIGHT, 5 );
301  m_IsCurrentFormat->SetValue( selected );
302 
303  if( selected )
304  ((NETLIST_DIALOG*)parent->GetParent())->m_asFormatSelected = true;
305 }
306 
307 
308 
310  NETLIST_DIALOG_BASE( parent )
311 {
312  m_Parent = parent;
314 
315  long tmp;
316  m_config->Read( NETLIST_USE_DEFAULT_NETNAME, &tmp, 0l );
317  m_cbUseDefaultNetlistName->SetValue( tmp );
319 
320  for( int ii = 0; ii < PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX; ii++ )
321  {
322  m_PanelNetType[ii] = NULL;
323  }
324 
325  // Add notebook pages:
326  m_asFormatSelected = false; // Will be set to true, if a format is selected
327 
328  // Add Panel FORMAT PCBNEW
330  new NETLIST_PAGE_DIALOG( m_NoteBook, wxT( "Pcbnew" ),
331  NET_TYPE_PCBNEW );
332 
333  // Add Panel FORMAT ORCADPCB2
335  new NETLIST_PAGE_DIALOG( m_NoteBook, wxT( "OrcadPCB2" ),
337 
338  // Add Panel FORMAT CADSTAR
340  new NETLIST_PAGE_DIALOG( m_NoteBook, wxT( "CadStar" ),
342 
343  // Add Panel spice
345 
346  // Add custom panels:
348 
349  // Ensure a netlist format is selected:
350  if( !m_asFormatSelected )
351  {
352  m_PanelNetType[PANELPCBNEW]->m_IsCurrentFormat->SetValue( true );
353  m_NoteBook->SetSelection( PANELPCBNEW );
354  // call OnNetlistTypeSelection to update some widgets.
355  // SetSelection() do nothing if the current page is already PANELPCBNEW
356  wxNotebookEvent event;
357  OnNetlistTypeSelection( event );
358  }
359 
360  SetDefaultItem( m_buttonNetlist );
361 
362  // Now all widgets have the size fixed, call FinishDialogSettings
364 }
365 
366 
367 const wxString NETLIST_DIALOG::UserNetlistTypeName( bool first_item )
368 {
369  static int index;
370  wxString name, msg;
371 
372  if( first_item )
373  index = 0;
374  else
375  index++;
376 
377  msg = CUSTOM_NETLIST_TITLE;
378  msg << index + 1;
379 
380  name = m_config->Read( msg );
381 
382  return name;
383 }
384 
385 
387 {
388  wxButton* Button;
389  NETLIST_PAGE_DIALOG* page;
390  wxString title = wxT( "Spice" );
391 
392  page = m_PanelNetType[PANELSPICE] =
394 
395  page->m_SpiceAjustPassiveValues = new wxCheckBox( page, ID_USE_NETCODE_AS_NETNAME,
396  _( "Reformat passive symbol values" ) );
397  page->m_SpiceAjustPassiveValues->SetToolTip(
398  _( "Reformat passive symbol values e.g. 1M -> 1Meg" ) );
400  page->m_LeftBoxSizer->Add( page->m_SpiceAjustPassiveValues, 0,
401  wxGROW | wxBOTTOM | wxRIGHT, 5 );
402 
403  page->m_LowBoxSizer->Add( new wxStaticText( page, -1, _( "Simulator command:" ) ), 0,
404  wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
405 
406  page->m_CommandStringCtrl = new wxTextCtrl( page, -1, m_Parent->GetSimulatorCommand(),
407  wxDefaultPosition, wxDefaultSize );
408 
409  page->m_CommandStringCtrl->SetInsertionPoint( 1 );
410  page->m_LowBoxSizer->Add( page->m_CommandStringCtrl,
411  0,
412  wxGROW | wxLEFT | wxRIGHT | wxBOTTOM,
413  5 );
414 
415  // Add buttons
416  Button = new wxButton( page, ID_RUN_SIMULATOR, _( "&Run Simulator" ) );
417  page->m_LowBoxSizer->Add( Button, 0, wxGROW | wxBOTTOM | wxLEFT | wxRIGHT, 5 );
418 }
419 
420 
422 {
423  int ii;
424  wxString title, msg;
425  NETLIST_PAGE_DIALOG* currPage;
426 
427  for( ii = 0; ii < CUSTOMPANEL_COUNTMAX; ii++ )
428  {
429  title = UserNetlistTypeName( ii == 0 ? true : false );
430 
431  if( title.IsEmpty() )
432  break; // No more panel to install
433 
434  // Install a plugin panel
436  msg << ii + 1;
437  wxString command = m_config->Read( msg );
438 
439  currPage = AddOneCustomPage( title, command,
441  m_PanelNetType[PANELCUSTOMBASE + ii] = currPage;
442  }
443 }
444 
445 
447  const wxString & aCommandString,
448  NETLIST_TYPE_ID aNetTypeId )
449 {
450  NETLIST_PAGE_DIALOG* currPage;
451 
452  currPage = new NETLIST_PAGE_DIALOG( m_NoteBook, aTitle, aNetTypeId );
453 
454 
455  currPage->m_LowBoxSizer->Add( new wxStaticText( currPage,
456  -1, _( "Netlist command:" ) ), 0,
457  wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
458 
459  currPage->m_CommandStringCtrl = new wxTextCtrl( currPage, -1, aCommandString,
460  wxDefaultPosition, wxDefaultSize );
461 
462  currPage->m_CommandStringCtrl->SetInsertionPoint( 1 );
463  currPage->m_LowBoxSizer->Add( currPage->m_CommandStringCtrl,
464  0,
465  wxGROW | wxTOP | wxLEFT | wxRIGHT | wxBOTTOM,
466  5 );
467 
468  currPage->m_LowBoxSizer->Add( new wxStaticText( currPage,
469  -1, _( "Title:" ) ), 0,
470  wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
471 
472  currPage->m_TitleStringCtrl = new wxTextCtrl( currPage, -1, aTitle,
473  wxDefaultPosition, wxDefaultSize );
474 
475  currPage->m_TitleStringCtrl->SetInsertionPoint( 1 );
476  currPage->m_LowBoxSizer->Add( currPage->m_TitleStringCtrl,
477  0,
478  wxGROW | wxTOP | wxLEFT | wxRIGHT | wxBOTTOM,
479  5 );
480  return currPage;
481 }
482 
483 
484 void NETLIST_DIALOG::SelectDefaultNetlistType( wxCommandEvent& event )
485 {
486  int ii;
487  NETLIST_PAGE_DIALOG* currPage;
488 
489  for( ii = 0; ii < PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX; ii++ )
490  if( m_PanelNetType[ii] )
491  m_PanelNetType[ii]->m_IsCurrentFormat->SetValue( false );
492 
493  currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage();
494 
495  if( currPage == NULL )
496  return;
497 
499  currPage->m_IsCurrentFormat->SetValue( true );
500 }
501 
502 
503 void NETLIST_DIALOG::OnNetlistTypeSelection( wxNotebookEvent& event )
504 {
505  NETLIST_PAGE_DIALOG* currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage();
506 
507  if( currPage == NULL )
508  return;
509 
510  m_buttonDelPlugin->Enable( currPage->m_IdNetType >= NET_TYPE_CUSTOM1 );
512 
513  wxString fileExt;
514 
515  if( FilenamePrms( currPage->m_IdNetType, &fileExt, NULL ) )
516  {
517  wxFileName fn = g_RootSheet->GetScreen()->GetFileName();
518  fn.SetExt( fileExt );
519  m_textCtrlDefaultFileName->SetValue( fn.GetFullName() );
520  }
521  else
522  m_textCtrlDefaultFileName->Clear();
523 }
524 
525 
527 {
528  int ii;
529 
530  m_Parent->SetSpiceAjustPassiveValues( m_PanelNetType[PANELSPICE]->m_SpiceAjustPassiveValues->IsChecked() );
531  m_Parent->SetSimulatorCommand( m_PanelNetType[PANELSPICE]->m_CommandStringCtrl->GetValue() );
532  m_Parent->SetNetListFormatName( wxEmptyString );
533 
534  for( ii = 0; ii < PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX; ii++ )
535  {
536  if( m_PanelNetType[ii] == NULL )
537  break;
538 
539  if( m_PanelNetType[ii]->m_IsCurrentFormat->GetValue() == true )
541  }
542 }
543 
544 
545 void NETLIST_DIALOG::GenNetlist( wxCommandEvent& event )
546 {
547  wxFileName fn;
548  wxString fileWildcard;
549  wxString fileExt;
550  wxString title = _( "Save Netlist File" );
551 
553 
554  NETLIST_PAGE_DIALOG* currPage;
555  currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage();
556 
557  unsigned netlist_opt = 0;
558 
559  // Calculate the netlist filename
560  fn = g_RootSheet->GetScreen()->GetFileName();
561  FilenamePrms( currPage->m_IdNetType, &fileExt, &fileWildcard );
562 
563  // Set some parameters
564  switch( currPage->m_IdNetType )
565  {
566  case NET_TYPE_SPICE:
567  // Set spice netlist options:
568  if( currPage->m_SpiceAjustPassiveValues->GetValue() )
569  netlist_opt |= NET_ADJUST_PASSIVE_VALS;
570  break;
571 
572  case NET_TYPE_CADSTAR:
573  break;
574 
575  case NET_TYPE_PCBNEW:
576  break;
577 
578  case NET_TYPE_ORCADPCB2:
579  break;
580 
581  default: // custom, NET_TYPE_CUSTOM1 and greater
582  {
583  wxString command = currPage->m_CommandStringCtrl->GetValue();
584  wxRegEx extRE( wxT( ".*\\.([[:alnum:]][[:alnum:]][[:alnum:]][[:alnum:]]?)\\.xslt?\".*" ) );
585 
586  if( extRE.Matches( command ) )
587  fileExt = extRE.GetMatch( command, 1 );
588 
589  title.Printf( _( "%s Export" ), currPage->m_TitleStringCtrl->GetValue().GetData() );
590  }
591  break;
592  }
593 
594  fn.SetExt( fileExt );
595 
596  if( fn.GetPath().IsEmpty() )
597  fn.SetPath( wxPathOnly( Prj().GetProjectFullName() ) );
598 
599  wxString fullpath = fn.GetFullPath();
600 
601  if( !GetUseDefaultNetlistName() || currPage->m_IdNetType >= NET_TYPE_CUSTOM1 )
602  {
603  wxString fullname = fn.GetFullName();
604  wxString path = fn.GetPath();
605 
606  // fullname does not and should not include the path, per wx docs.
607  wxFileDialog dlg( this, title, path, fullname, fileWildcard, wxFD_SAVE );
608 
609  if( dlg.ShowModal() == wxID_CANCEL )
610  return;
611 
612  fullpath = dlg.GetPath(); // directory + filename
613  }
614 
616 
617  if( currPage->m_CommandStringCtrl )
618  m_Parent->SetNetListerCommand( currPage->m_CommandStringCtrl->GetValue() );
619  else
620  m_Parent->SetNetListerCommand( wxEmptyString );
621 
622  m_Parent->CreateNetlist( currPage->m_IdNetType, fullpath, netlist_opt, NULL, false );
623 
625 
626  EndModal( wxID_OK );
627 }
628 
629 
631  wxString * aExt, wxString * aWildCard )
632 {
633  wxString fileExt;
634  wxString fileWildcard;
635 
636  bool ret = true;
637 
638  switch( aNetTypeId )
639  {
640  case NET_TYPE_SPICE:
641  fileExt = wxT( "cir" );
642  fileWildcard = SpiceNetlistFileWildcard();
643  break;
644 
645  case NET_TYPE_CADSTAR:
646  fileExt = wxT( "frp" );
647  fileWildcard = CadstarNetlistFileWildcard();
648  break;
649 
650  case NET_TYPE_PCBNEW:
651  case NET_TYPE_ORCADPCB2:
652  fileExt = NetlistFileExtension;
653  fileWildcard = NetlistFileWildcard();
654  break;
655 
656  default: // custom, NET_TYPE_CUSTOM1 and greater
657  fileWildcard = AllFilesWildcard;
658  ret = false;
659  }
660 
661  if( aExt )
662  *aExt = fileExt;
663 
664  if( aWildCard )
665  *aWildCard = fileWildcard;
666 
667  return ret;
668 }
669 
670 
671 void NETLIST_DIALOG::RunSimulator( wxCommandEvent& event )
672 {
673  wxFileName fn;
674  wxString ExecFile, CommandLine;
675 
677 
678  wxString tmp = m_PanelNetType[PANELSPICE]->m_CommandStringCtrl->GetValue();
679  tmp.Trim( false );
680  tmp.Trim( true );
682  ExecFile = tmp.BeforeFirst( ' ' );
683  CommandLine = tmp.AfterFirst( ' ' );
684 
685  // Calculate the netlist filename
686  fn = g_RootSheet->GetScreen()->GetFileName();
687  fn.SetExt( wxT( "cir" ) );
688  CommandLine += wxT( " \"" ) + fn.GetFullPath() + wxT( "\"" );
689 
690  NETLIST_PAGE_DIALOG* currPage;
691  currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage();
692 
693  // Set spice netlist options:
694  unsigned netlist_opt = 0;
695 
696  if( currPage->m_SpiceAjustPassiveValues && currPage->m_SpiceAjustPassiveValues->GetValue() )
697  netlist_opt |= NET_ADJUST_PASSIVE_VALS;
698 
699  if( ! m_Parent->CreateNetlist( currPage->m_IdNetType, fn.GetFullPath(),
700  netlist_opt, NULL, false ) )
701  return;
702 
703  ExecuteFile( this, ExecFile, CommandLine );
704 }
705 
706 
708 {
709  wxString msg, Command;
710 
712 
714 
715  // Update existing custom pages
716  int jj = 0;
717  for( int ii = 0; ii < CUSTOMPANEL_COUNTMAX; ii++ )
718  {
720 
721  if( currPage == NULL )
722  break;
723 
724  wxString title = currPage->m_TitleStringCtrl->GetValue();
725 
726  if( title.IsEmpty() )
727  continue;
728 
729  msg = CUSTOM_NETLIST_TITLE;
730  msg << jj + 1;
731  m_config->Write( msg, title );
732 
733  Command = currPage->m_CommandStringCtrl->GetValue();
735  msg << jj + 1;
736  m_config->Write( msg, Command );
737  jj++;
738  }
739 
740  // Ensure all other pages are void
741  for(; jj < CUSTOMPANEL_COUNTMAX; jj++ )
742  {
743  msg = CUSTOM_NETLIST_TITLE;
744  msg << jj + 1;
745  m_config->Write( msg, wxEmptyString );
746 
748  msg << jj + 1;
749  m_config->Write( msg, wxEmptyString );
750  }
751 }
752 
753 
754 void NETLIST_DIALOG::OnDelPlugin( wxCommandEvent& event )
755 {
756  NETLIST_PAGE_DIALOG* currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage();
757 
758  currPage->m_CommandStringCtrl->SetValue( wxEmptyString );
759  currPage->m_TitleStringCtrl->SetValue( wxEmptyString );
760 
761  if( currPage->m_IsCurrentFormat->IsChecked() )
762  {
763  currPage->m_IsCurrentFormat->SetValue( false );
764  m_PanelNetType[PANELPCBNEW]->m_IsCurrentFormat->SetValue( true );
765  }
766 
768  EndModal( NET_PLUGIN_CHANGE );
769 }
770 
771 
772 void NETLIST_DIALOG::OnAddPlugin( wxCommandEvent& event )
773 {
774  NETLIST_DIALOG_ADD_PLUGIN dlg( this );
775  if( dlg.ShowModal() != wxID_OK )
776  return;
777 
778  // Creates a new custom plugin page
779  wxString title = dlg.GetPluginTitle();
780 
781  // Verify it does not exists
782  int netTypeId = PANELCUSTOMBASE; // the first not used type id
783  NETLIST_PAGE_DIALOG* currPage;
784  for( int ii = 0; ii < CUSTOMPANEL_COUNTMAX; ii++ )
785  {
786  netTypeId = PANELCUSTOMBASE + ii;
787  currPage = m_PanelNetType[ii + PANELCUSTOMBASE];
788 
789  if( currPage == NULL )
790  break;
791 
792  if( currPage->GetPageNetFmtName() == title )
793  {
794  wxMessageBox( _("This plugin already exists. Abort") );
795  return;
796  }
797  }
798 
799  wxString cmd = dlg.GetPluginTCommandLine();
800  currPage = AddOneCustomPage( title,cmd, (NETLIST_TYPE_ID)netTypeId );
801  m_PanelNetType[netTypeId] = currPage;
803 
804  // Close and reopen dialog to rebuild the dialog after changes
805  EndModal( NET_PLUGIN_CHANGE );
806 }
807 
808 
811 {
812  m_Parent = parent;
813  GetSizer()->SetSizeHints( this );
814 }
815 
816 
817 void NETLIST_DIALOG_ADD_PLUGIN::OnOKClick( wxCommandEvent& event )
818 {
819  if( m_textCtrlCommand->GetValue() == wxEmptyString )
820  {
821  wxMessageBox( _( "Error. You must provide a command String" ) );
822  return;
823  }
824 
825  if( m_textCtrlName->GetValue() == wxEmptyString )
826  {
827  wxMessageBox( _( "Error. You must provide a Title" ) );
828  return;
829  }
830 
831  EndModal( wxID_OK );
832 }
833 
834 
835 void NETLIST_DIALOG_ADD_PLUGIN::OnBrowsePlugins( wxCommandEvent& event )
836 {
837  wxString FullFileName, Mask, Path;
838 
839  Mask = wxT( "*" );
840 #ifndef __WXMAC__
841  Path = Pgm().GetExecutablePath();
842 #else
843  Path = GetOSXKicadDataDir() + wxT( "/plugins" );
844 #endif
845  FullFileName = EDA_FILE_SELECTOR( _( "Plugin files:" ),
846  Path,
847  FullFileName,
848  wxEmptyString,
849  Mask,
850  this,
851  wxFD_OPEN,
852  true
853  );
854  if( FullFileName.IsEmpty() )
855  return;
856 
857  // Creates a default command line, suitable for external tool xslproc or python
858  // try to build a default command line depending on plugin extension
859  // "xsl" or "exe" or "py"
860  wxString cmdLine;
861  wxFileName fn( FullFileName );
862  wxString ext = fn.GetExt();
863 
864  if( ext == wxT("xsl" ) )
865  cmdLine.Printf(wxT("xsltproc -o \"%%O\" \"%s\" \"%%I\""), GetChars(FullFileName) );
866  else if( ext == wxT("exe" ) || ext.IsEmpty() )
867  cmdLine.Printf(wxT("\"%s\" > \"%%O\" < \"%%I\""), GetChars(FullFileName) );
868  else if( ext == wxT("py" ) || ext.IsEmpty() )
869  cmdLine.Printf(wxT("python \"%s\" \"%%I\" \"%%O\""), GetChars(FullFileName) );
870  else
871  cmdLine.Printf(wxT("\"%s\""), GetChars(FullFileName) );
872 
873  m_textCtrlCommand->SetValue( cmdLine );
874 
875  /* Get a title for this page */
876  wxString title = m_textCtrlName->GetValue();
877 
878  if( title.IsEmpty() )
879  wxMessageBox( _( "Do not forget to choose a title for this netlist control page" ) );
880 }
881 
882 
884 {
885  NETLIST_DIALOG dlg( aCaller );
886 
887  return dlg.ShowModal();
888 }
const std::string NetlistFileExtension
Definition of the SCH_SHEET class for Eeschema.
const wxString GetNetListFormatName() const
wxString GetSimulatorCommand() const
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:215
wxString SpiceNetlistFileWildcard()
const wxString & GetFileName() const
Definition: sch_screen.h:131
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:279
#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.
const wxString AllFilesWildcard
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
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()
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:103
#define CUSTOM_NETLIST_TITLE
bool GetSpiceAjustPassiveValues() 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:92
see class PGM_BASE
const char * name
Definition: DXF_plotter.cpp:61
bool CreateNetlist(int aFormat, const wxString &aFullFileName, unsigned aNetlistOptions, REPORTER *aReporter=NULL, bool silent=false)
Create a netlist for the current schematic.
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...
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)
void OnNetlistTypeSelection(wxNotebookEvent &event) override
void ClearMsgPanel(void)
Clear all messages from the message panel.
void SetSpiceAjustPassiveValues(bool aEnable)
const wxString GetPageNetFmtName()
function GetPageNetFmtName
int InvokeDialogNetList(SCH_EDIT_FRAME *aCaller)
void SelectDefaultNetlistType(wxCommandEvent &event)
wxString CadstarNetlistFileWildcard()