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-2017 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
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,
267  wxTAB_TRAVERSAL | wxBORDER_SUNKEN )
268 {
269  m_IdNetType = id_NetType;
270  m_pageNetFmtName = title;
271  m_CommandStringCtrl = NULL;
272  m_TitleStringCtrl = NULL;
273  m_IsCurrentFormat = NULL;
275  m_ButtonCancel = NULL;
276 
277  wxString netfmtName = ((NETLIST_DIALOG*)parent->GetParent())->m_NetFmtName;
278 
279  bool selected = m_pageNetFmtName == netfmtName;
280 
281  parent->AddPage( this, title, selected );
282 
283  wxBoxSizer* MainBoxSizer = new wxBoxSizer( wxVERTICAL );
284  SetSizer( MainBoxSizer );
285  wxBoxSizer* UpperBoxSizer = new wxBoxSizer( wxHORIZONTAL );
286  m_LowBoxSizer = new wxBoxSizer( wxVERTICAL );
287  MainBoxSizer->Add( UpperBoxSizer, 0, wxGROW | wxALL, 5 );
288  MainBoxSizer->Add( m_LowBoxSizer, 0, wxGROW | wxALL, 5 );
289 
290  m_LeftBoxSizer = new wxBoxSizer( wxVERTICAL );
291  m_RightBoxSizer = new wxBoxSizer( wxVERTICAL );
292  m_RightOptionsBoxSizer = new wxBoxSizer( wxVERTICAL );
293  UpperBoxSizer->Add( m_LeftBoxSizer, 0, wxGROW | wxALL, 5 );
294  UpperBoxSizer->Add( m_RightBoxSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
295  UpperBoxSizer->Add( m_RightOptionsBoxSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
296 
297  wxStaticText* text = new wxStaticText( this, -1, _( "Options:" ) );
298  m_LeftBoxSizer->Add( text, 0, wxGROW | wxBOTTOM | wxRIGHT, 5 );
299 
300  m_IsCurrentFormat = new wxCheckBox( this, ID_CURRENT_FORMAT_IS_DEFAULT, _( "Default format" ) );
301  m_LeftBoxSizer->Add( m_IsCurrentFormat, 0, wxGROW | wxBOTTOM | wxRIGHT, 5 );
302  m_IsCurrentFormat->SetValue( selected );
303 
304  if( selected )
305  ((NETLIST_DIALOG*)parent->GetParent())->m_asFormatSelected = true;
306 }
307 
308 
309 
311  NETLIST_DIALOG_BASE( parent )
312 {
313  m_Parent = parent;
315 
316  long tmp;
317  m_config->Read( NETLIST_USE_DEFAULT_NETNAME, &tmp, 0l );
318  m_cbUseDefaultNetlistName->SetValue( tmp );
320 
321  for( int ii = 0; ii < PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX; ii++ )
322  {
323  m_PanelNetType[ii] = NULL;
324  }
325 
326  // Add notebook pages:
327  m_asFormatSelected = false; // Will be set to true, if a format is selected
328 
329  // Add Panel FORMAT PCBNEW
331  new NETLIST_PAGE_DIALOG( m_NoteBook, wxT( "Pcbnew" ),
332  NET_TYPE_PCBNEW );
333 
334  // Add Panel FORMAT ORCADPCB2
336  new NETLIST_PAGE_DIALOG( m_NoteBook, wxT( "OrcadPCB2" ),
338 
339  // Add Panel FORMAT CADSTAR
341  new NETLIST_PAGE_DIALOG( m_NoteBook, wxT( "CadStar" ),
343 
344  // Add Panel spice
346 
347  // Add custom panels:
349 
350  // Ensure a netlist format is selected:
351  if( !m_asFormatSelected )
352  {
353  m_PanelNetType[PANELPCBNEW]->m_IsCurrentFormat->SetValue( true );
354  m_NoteBook->SetSelection( PANELPCBNEW );
355  // call OnNetlistTypeSelection to update some widgets.
356  // SetSelection() do nothing if the current page is already PANELPCBNEW
357  wxNotebookEvent event;
358  OnNetlistTypeSelection( event );
359  }
360 
361  SetDefaultItem( m_buttonNetlist );
362 
363  // Now all widgets have the size fixed, call FinishDialogSettings
365 }
366 
367 
368 const wxString NETLIST_DIALOG::UserNetlistTypeName( bool first_item )
369 {
370  static int index;
371  wxString name, msg;
372 
373  if( first_item )
374  index = 0;
375  else
376  index++;
377 
378  msg = CUSTOM_NETLIST_TITLE;
379  msg << index + 1;
380 
381  name = m_config->Read( msg );
382 
383  return name;
384 }
385 
386 
388 {
389  wxButton* Button;
390  NETLIST_PAGE_DIALOG* page;
391  wxString title = wxT( "Spice" );
392 
393  page = m_PanelNetType[PANELSPICE] =
395 
396  page->m_SpiceAjustPassiveValues = new wxCheckBox( page, ID_USE_NETCODE_AS_NETNAME,
397  _( "Reformat passive symbol values" ) );
398  page->m_SpiceAjustPassiveValues->SetToolTip(
399  _( "Reformat passive symbol values e.g. 1M -> 1Meg" ) );
401  page->m_LeftBoxSizer->Add( page->m_SpiceAjustPassiveValues, 0,
402  wxGROW | wxBOTTOM | wxRIGHT, 5 );
403 
404  page->m_LowBoxSizer->Add( new wxStaticText( page, -1, _( "Simulator command:" ) ), 0,
405  wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
406 
407  page->m_CommandStringCtrl = new wxTextCtrl( page, -1, m_Parent->GetSimulatorCommand(),
408  wxDefaultPosition, wxDefaultSize );
409 
410  page->m_CommandStringCtrl->SetInsertionPoint( 1 );
411  page->m_LowBoxSizer->Add( page->m_CommandStringCtrl,
412  0,
413  wxGROW | wxLEFT | wxRIGHT | wxBOTTOM,
414  5 );
415 
416  // Add buttons
417  Button = new wxButton( page, ID_RUN_SIMULATOR, _( "&Run Simulator" ) );
418  page->m_LowBoxSizer->Add( Button, 0, wxGROW | wxBOTTOM | wxLEFT | wxRIGHT, 5 );
419 }
420 
421 
423 {
424  int ii;
425  wxString title, msg;
426  NETLIST_PAGE_DIALOG* currPage;
427 
428  for( ii = 0; ii < CUSTOMPANEL_COUNTMAX; ii++ )
429  {
430  title = UserNetlistTypeName( ii == 0 ? true : false );
431 
432  if( title.IsEmpty() )
433  break; // No more panel to install
434 
435  // Install a plugin panel
437  msg << ii + 1;
438  wxString command = m_config->Read( msg );
439 
440  currPage = AddOneCustomPage( title, command,
442  m_PanelNetType[PANELCUSTOMBASE + ii] = currPage;
443  }
444 }
445 
446 
448  const wxString & aCommandString,
449  NETLIST_TYPE_ID aNetTypeId )
450 {
451  NETLIST_PAGE_DIALOG* currPage;
452 
453  currPage = new NETLIST_PAGE_DIALOG( m_NoteBook, aTitle, aNetTypeId );
454 
455 
456  currPage->m_LowBoxSizer->Add( new wxStaticText( currPage,
457  -1, _( "Netlist command:" ) ), 0,
458  wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
459 
460  currPage->m_CommandStringCtrl = new wxTextCtrl( currPage, -1, aCommandString,
461  wxDefaultPosition, wxDefaultSize );
462 
463  currPage->m_CommandStringCtrl->SetInsertionPoint( 1 );
464  currPage->m_LowBoxSizer->Add( currPage->m_CommandStringCtrl,
465  0,
466  wxGROW | wxTOP | wxLEFT | wxRIGHT | wxBOTTOM,
467  5 );
468 
469  currPage->m_LowBoxSizer->Add( new wxStaticText( currPage,
470  -1, _( "Title:" ) ), 0,
471  wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
472 
473  currPage->m_TitleStringCtrl = new wxTextCtrl( currPage, -1, aTitle,
474  wxDefaultPosition, wxDefaultSize );
475 
476  currPage->m_TitleStringCtrl->SetInsertionPoint( 1 );
477  currPage->m_LowBoxSizer->Add( currPage->m_TitleStringCtrl,
478  0,
479  wxGROW | wxTOP | wxLEFT | wxRIGHT | wxBOTTOM,
480  5 );
481  return currPage;
482 }
483 
484 
485 void NETLIST_DIALOG::SelectDefaultNetlistType( wxCommandEvent& event )
486 {
487  int ii;
488  NETLIST_PAGE_DIALOG* currPage;
489 
490  for( ii = 0; ii < PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX; ii++ )
491  if( m_PanelNetType[ii] )
492  m_PanelNetType[ii]->m_IsCurrentFormat->SetValue( false );
493 
494  currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage();
495 
496  if( currPage == NULL )
497  return;
498 
500  currPage->m_IsCurrentFormat->SetValue( true );
501 }
502 
503 
504 void NETLIST_DIALOG::OnNetlistTypeSelection( wxNotebookEvent& event )
505 {
506  NETLIST_PAGE_DIALOG* currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage();
507 
508  if( currPage == NULL )
509  return;
510 
511  m_buttonDelPlugin->Enable( currPage->m_IdNetType >= NET_TYPE_CUSTOM1 );
513 
514  wxString fileExt;
515 
516  if( FilenamePrms( currPage->m_IdNetType, &fileExt, NULL ) )
517  {
518  wxFileName fn = g_RootSheet->GetScreen()->GetFileName();
519  fn.SetExt( fileExt );
520  m_textCtrlDefaultFileName->SetValue( fn.GetFullName() );
521  }
522  else
523  m_textCtrlDefaultFileName->Clear();
524 }
525 
526 
528 {
529  int ii;
530 
531  m_Parent->SetSpiceAjustPassiveValues( m_PanelNetType[PANELSPICE]->m_SpiceAjustPassiveValues->IsChecked() );
532  m_Parent->SetSimulatorCommand( m_PanelNetType[PANELSPICE]->m_CommandStringCtrl->GetValue() );
533  m_Parent->SetNetListFormatName( wxEmptyString );
534 
535  for( ii = 0; ii < PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX; ii++ )
536  {
537  if( m_PanelNetType[ii] == NULL )
538  break;
539 
540  if( m_PanelNetType[ii]->m_IsCurrentFormat->GetValue() == true )
542  }
543 }
544 
545 
546 void NETLIST_DIALOG::GenNetlist( wxCommandEvent& event )
547 {
548  wxFileName fn;
549  wxString fileWildcard;
550  wxString fileExt;
551  wxString title = _( "Save Netlist File" );
552 
554 
555  NETLIST_PAGE_DIALOG* currPage;
556  currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage();
557 
558  unsigned netlist_opt = 0;
559 
560  // Calculate the netlist filename
561  fn = g_RootSheet->GetScreen()->GetFileName();
562  FilenamePrms( currPage->m_IdNetType, &fileExt, &fileWildcard );
563 
564  // Set some parameters
565  switch( currPage->m_IdNetType )
566  {
567  case NET_TYPE_SPICE:
568  // Set spice netlist options:
569  if( currPage->m_SpiceAjustPassiveValues->GetValue() )
570  netlist_opt |= NET_ADJUST_PASSIVE_VALS;
571  break;
572 
573  case NET_TYPE_CADSTAR:
574  break;
575 
576  case NET_TYPE_PCBNEW:
577  break;
578 
579  case NET_TYPE_ORCADPCB2:
580  break;
581 
582  default: // custom, NET_TYPE_CUSTOM1 and greater
583  {
584  wxString command = currPage->m_CommandStringCtrl->GetValue();
585  wxRegEx extRE( wxT( ".*\\.([[:alnum:]][[:alnum:]][[:alnum:]][[:alnum:]]?)\\.xslt?\".*" ) );
586 
587  if( extRE.Matches( command ) )
588  fileExt = extRE.GetMatch( command, 1 );
589 
590  title.Printf( _( "%s Export" ), currPage->m_TitleStringCtrl->GetValue().GetData() );
591  }
592  break;
593  }
594 
595  fn.SetExt( fileExt );
596 
597  if( fn.GetPath().IsEmpty() )
598  fn.SetPath( wxPathOnly( Prj().GetProjectFullName() ) );
599 
600  wxString fullpath = fn.GetFullPath();
601 
602  if( !GetUseDefaultNetlistName() || currPage->m_IdNetType >= NET_TYPE_CUSTOM1 )
603  {
604  wxString fullname = fn.GetFullName();
605  wxString path = fn.GetPath();
606 
607  // fullname does not and should not include the path, per wx docs.
608  wxFileDialog dlg( this, title, path, fullname, fileWildcard, wxFD_SAVE );
609 
610  if( dlg.ShowModal() == wxID_CANCEL )
611  return;
612 
613  fullpath = dlg.GetPath(); // directory + filename
614  }
615 
617 
618  if( currPage->m_CommandStringCtrl )
619  m_Parent->SetNetListerCommand( currPage->m_CommandStringCtrl->GetValue() );
620  else
621  m_Parent->SetNetListerCommand( wxEmptyString );
622 
623  m_Parent->CreateNetlist( currPage->m_IdNetType, fullpath, netlist_opt, NULL, false );
624 
626 
627  EndModal( wxID_OK );
628 }
629 
630 
632  wxString * aExt, wxString * aWildCard )
633 {
634  wxString fileExt;
635  wxString fileWildcard;
636 
637  bool ret = true;
638 
639  switch( aNetTypeId )
640  {
641  case NET_TYPE_SPICE:
642  fileExt = wxT( "cir" );
643  fileWildcard = SpiceNetlistFileWildcard();
644  break;
645 
646  case NET_TYPE_CADSTAR:
647  fileExt = wxT( "frp" );
648  fileWildcard = CadstarNetlistFileWildcard();
649  break;
650 
651  case NET_TYPE_PCBNEW:
652  case NET_TYPE_ORCADPCB2:
653  fileExt = NetlistFileExtension;
654  fileWildcard = NetlistFileWildcard();
655  break;
656 
657  default: // custom, NET_TYPE_CUSTOM1 and greater
658  fileWildcard = AllFilesWildcard;
659  ret = false;
660  }
661 
662  if( aExt )
663  *aExt = fileExt;
664 
665  if( aWildCard )
666  *aWildCard = fileWildcard;
667 
668  return ret;
669 }
670 
671 
672 void NETLIST_DIALOG::RunSimulator( wxCommandEvent& event )
673 {
674  wxFileName fn;
675  wxString ExecFile, CommandLine;
676 
678 
679  wxString tmp = m_PanelNetType[PANELSPICE]->m_CommandStringCtrl->GetValue();
680  tmp.Trim( false );
681  tmp.Trim( true );
683  ExecFile = tmp.BeforeFirst( ' ' );
684  CommandLine = tmp.AfterFirst( ' ' );
685 
686  // Calculate the netlist filename
687  fn = g_RootSheet->GetScreen()->GetFileName();
688  fn.SetExt( wxT( "cir" ) );
689  CommandLine += wxT( " \"" ) + fn.GetFullPath() + wxT( "\"" );
690 
691  NETLIST_PAGE_DIALOG* currPage;
692  currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage();
693 
694  // Set spice netlist options:
695  unsigned netlist_opt = 0;
696 
697  if( currPage->m_SpiceAjustPassiveValues && currPage->m_SpiceAjustPassiveValues->GetValue() )
698  netlist_opt |= NET_ADJUST_PASSIVE_VALS;
699 
700  if( ! m_Parent->CreateNetlist( currPage->m_IdNetType, fn.GetFullPath(),
701  netlist_opt, NULL, false ) )
702  return;
703 
704  ExecuteFile( this, ExecFile, CommandLine );
705 }
706 
707 
709 {
710  wxString msg, Command;
711 
713 
715 
716  // Update existing custom pages
717  int jj = 0;
718  for( int ii = 0; ii < CUSTOMPANEL_COUNTMAX; ii++ )
719  {
721 
722  if( currPage == NULL )
723  break;
724 
725  wxString title = currPage->m_TitleStringCtrl->GetValue();
726 
727  if( title.IsEmpty() )
728  continue;
729 
730  msg = CUSTOM_NETLIST_TITLE;
731  msg << jj + 1;
732  m_config->Write( msg, title );
733 
734  Command = currPage->m_CommandStringCtrl->GetValue();
736  msg << jj + 1;
737  m_config->Write( msg, Command );
738  jj++;
739  }
740 
741  // Ensure all other pages are void
742  for(; jj < CUSTOMPANEL_COUNTMAX; jj++ )
743  {
744  msg = CUSTOM_NETLIST_TITLE;
745  msg << jj + 1;
746  m_config->Write( msg, wxEmptyString );
747 
749  msg << jj + 1;
750  m_config->Write( msg, wxEmptyString );
751  }
752 }
753 
754 
755 void NETLIST_DIALOG::OnDelPlugin( wxCommandEvent& event )
756 {
757  NETLIST_PAGE_DIALOG* currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage();
758 
759  currPage->m_CommandStringCtrl->SetValue( wxEmptyString );
760  currPage->m_TitleStringCtrl->SetValue( wxEmptyString );
761 
762  if( currPage->m_IsCurrentFormat->IsChecked() )
763  {
764  currPage->m_IsCurrentFormat->SetValue( false );
765  m_PanelNetType[PANELPCBNEW]->m_IsCurrentFormat->SetValue( true );
766  }
767 
769  EndModal( NET_PLUGIN_CHANGE );
770 }
771 
772 
773 void NETLIST_DIALOG::OnAddPlugin( wxCommandEvent& event )
774 {
775  NETLIST_DIALOG_ADD_PLUGIN dlg( this );
776  if( dlg.ShowModal() != wxID_OK )
777  return;
778 
779  // Creates a new custom plugin page
780  wxString title = dlg.GetPluginTitle();
781 
782  // Verify it does not exists
783  int netTypeId = PANELCUSTOMBASE; // the first not used type id
784  NETLIST_PAGE_DIALOG* currPage;
785  for( int ii = 0; ii < CUSTOMPANEL_COUNTMAX; ii++ )
786  {
787  netTypeId = PANELCUSTOMBASE + ii;
788  currPage = m_PanelNetType[ii + PANELCUSTOMBASE];
789 
790  if( currPage == NULL )
791  break;
792 
793  if( currPage->GetPageNetFmtName() == title )
794  {
795  wxMessageBox( _("This plugin already exists. Abort") );
796  return;
797  }
798  }
799 
800  wxString cmd = dlg.GetPluginTCommandLine();
801  currPage = AddOneCustomPage( title,cmd, (NETLIST_TYPE_ID)netTypeId );
802  m_PanelNetType[netTypeId] = currPage;
804 
805  // Close and reopen dialog to rebuild the dialog after changes
806  EndModal( NET_PLUGIN_CHANGE );
807 }
808 
809 
812 {
813  m_Parent = parent;
814  GetSizer()->SetSizeHints( this );
815 }
816 
817 
818 void NETLIST_DIALOG_ADD_PLUGIN::OnOKClick( wxCommandEvent& event )
819 {
820  if( m_textCtrlCommand->GetValue() == wxEmptyString )
821  {
822  wxMessageBox( _( "Error. You must provide a command String" ) );
823  return;
824  }
825 
826  if( m_textCtrlName->GetValue() == wxEmptyString )
827  {
828  wxMessageBox( _( "Error. You must provide a Title" ) );
829  return;
830  }
831 
832  EndModal( wxID_OK );
833 }
834 
835 
836 void NETLIST_DIALOG_ADD_PLUGIN::OnBrowsePlugins( wxCommandEvent& event )
837 {
838  wxString FullFileName, Mask, Path;
839 
840  Mask = wxT( "*" );
841 #ifndef __WXMAC__
842  Path = Pgm().GetExecutablePath();
843 #else
844  Path = GetOSXKicadDataDir() + wxT( "/plugins" );
845 #endif
846  FullFileName = EDA_FILE_SELECTOR( _( "Plugin files:" ),
847  Path,
848  FullFileName,
849  wxEmptyString,
850  Mask,
851  this,
852  wxFD_OPEN,
853  true
854  );
855  if( FullFileName.IsEmpty() )
856  return;
857 
858  // Creates a default command line, suitable for external tool xslproc or python
859  // try to build a default command line depending on plugin extension
860  // "xsl" or "exe" or "py"
861  wxString cmdLine;
862  wxFileName fn( FullFileName );
863  wxString ext = fn.GetExt();
864 
865  if( ext == wxT("xsl" ) )
866  cmdLine.Printf(wxT("xsltproc -o \"%%O\" \"%s\" \"%%I\""), GetChars(FullFileName) );
867  else if( ext == wxT("exe" ) || ext.IsEmpty() )
868  cmdLine.Printf(wxT("\"%s\" > \"%%O\" < \"%%I\""), GetChars(FullFileName) );
869  else if( ext == wxT("py" ) || ext.IsEmpty() )
870  cmdLine.Printf(wxT("python \"%s\" \"%%I\" \"%%O\""), GetChars(FullFileName) );
871  else
872  cmdLine.Printf(wxT("\"%s\""), GetChars(FullFileName) );
873 
874  m_textCtrlCommand->SetValue( cmdLine );
875 
876  /* Get a title for this page */
877  wxString title = m_textCtrlName->GetValue();
878 
879  if( title.IsEmpty() )
880  wxMessageBox( _( "Do not forget to choose a title for this netlist control page" ) );
881 }
882 
883 
885 {
886  NETLIST_DIALOG dlg( aCaller );
887 
888  return dlg.ShowModal();
889 }
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:173
wxString SpiceNetlistFileWildcard()
const wxString & GetFileName() const
Definition: sch_screen.h:120
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:65
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.
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
const wxString NetlistFileExtension
void WriteCurrentNetlistSetup()
Function WriteCurrentNetlistSetup Write the current netlist options setup in the configuration.
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:55
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
const wxString AllFilesWildcard
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.
Definition: draw_frame.cpp:823
void SetSpiceAjustPassiveValues(bool aEnable)
const wxString GetPageNetFmtName()
function GetPageNetFmtName
int InvokeDialogNetList(SCH_EDIT_FRAME *aCaller)
void SelectDefaultNetlistType(wxCommandEvent &event)
wxString CadstarNetlistFileWildcard()