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-2015 Wayne Stambaugh <stambaughw@verizon.net>
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 <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 
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 
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;
274  m_SpiceAjustPassiveValues = 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 | wxALL, 5 );
299 
300  m_IsCurrentFormat = new wxCheckBox( this, ID_CURRENT_FORMAT_IS_DEFAULT,
301  _( "Default format" ) );
302  m_LeftBoxSizer->Add( m_IsCurrentFormat, 0, wxGROW | wxALL, 5 );
303  m_IsCurrentFormat->SetValue( selected );
304 
305  if( selected )
306  ((NETLIST_DIALOG*)parent->GetParent())->m_asFormatSelected = true;
307 }
308 
309 
310 
312  NETLIST_DIALOG_BASE( parent )
313 {
314  m_Parent = parent;
316 
317  long tmp;
318  m_config->Read( NETLIST_USE_DEFAULT_NETNAME, &tmp, 0l );
319  m_cbUseDefaultNetlistName->SetValue( tmp );
321 
322  for( int ii = 0; ii < PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX; ii++ )
323  {
324  m_PanelNetType[ii] = NULL;
325  }
326 
327  // Add notebook pages:
328  m_asFormatSelected = false; // Will be set to true, if a format is selected
329 
330  // Add Panel FORMAT PCBNEW
332  new NETLIST_PAGE_DIALOG( m_NoteBook, wxT( "Pcbnew" ),
333  NET_TYPE_PCBNEW );
334 
335  // Add Panel FORMAT ORCADPCB2
337  new NETLIST_PAGE_DIALOG( m_NoteBook, wxT( "OrcadPCB2" ),
339 
340  // Add Panel FORMAT CADSTAR
342  new NETLIST_PAGE_DIALOG( m_NoteBook, wxT( "CadStar" ),
344 
345  // Add Panel spice
347 
348  // Add custom panels:
350 
351  // Ensure a netlist format is selected:
352  if( !m_asFormatSelected )
353  {
354  m_PanelNetType[PANELPCBNEW]->m_IsCurrentFormat->SetValue( true );
355  m_NoteBook->SetSelection( PANELPCBNEW );
356  // call OnNetlistTypeSelection to update some widgets.
357  // SetSelection() do nothing if the current page is already PANELPCBNEW
358  wxNotebookEvent event;
359  OnNetlistTypeSelection( event );
360  }
361 
362  SetDefaultItem( m_buttonNetlist );
363 
364  // Now all widgets have the size fixed, call FinishDialogSettings
366 }
367 
368 
369 const wxString NETLIST_DIALOG::UserNetlistTypeName( bool first_item )
370 {
371  static int index;
372  wxString name, msg;
373 
374  if( first_item )
375  index = 0;
376  else
377  index++;
378 
379  msg = CUSTOM_NETLIST_TITLE;
380  msg << index + 1;
381 
382  name = m_config->Read( msg );
383 
384  return name;
385 }
386 
387 
389 {
390  wxButton* Button;
391  NETLIST_PAGE_DIALOG* page;
392  wxString title = wxT( "Spice" );
393 
394  page = m_PanelNetType[PANELSPICE] =
396 
397  page->m_SpiceAjustPassiveValues = new wxCheckBox( page, ID_USE_NETCODE_AS_NETNAME,
398  _( "Reformat passive component values" ) );
399  page->m_SpiceAjustPassiveValues->SetToolTip(
400  _( "Reformat passive component values e.g. 1M -> 1Meg" ) );
402  page->m_LeftBoxSizer->Add( page->m_SpiceAjustPassiveValues, 0, wxGROW | wxALL, 5 );
403 
404  page->m_LowBoxSizer->Add( new wxStaticText( page, -1, _( "Simulator command:" ) ), 0,
405  wxGROW | wxLEFT | wxRIGHT | wxTOP, 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_RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 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  title.Printf( _( "%s Export" ), currPage->m_TitleStringCtrl->GetValue().GetData() );
584  }
585 
586  fn.SetExt( fileExt );
587 
588  if( fn.GetPath().IsEmpty() )
589  fn.SetPath( wxPathOnly( Prj().GetProjectFullName() ) );
590 
591  wxString fullpath = fn.GetFullPath();
592 
593  if( !GetUseDefaultNetlistName() || currPage->m_IdNetType >= NET_TYPE_CUSTOM1 )
594  {
595  wxString fullname = fn.GetFullName();
596  wxString path = fn.GetPath();
597 
598  // fullname does not and should not include the path, per wx docs.
599  wxFileDialog dlg( this, title, path, fullname, fileWildcard, wxFD_SAVE );
600 
601  if( dlg.ShowModal() == wxID_CANCEL )
602  return;
603 
604  fullpath = dlg.GetPath(); // directory + filename
605  }
606 
608 
609  if( currPage->m_CommandStringCtrl )
610  m_Parent->SetNetListerCommand( currPage->m_CommandStringCtrl->GetValue() );
611  else
612  m_Parent->SetNetListerCommand( wxEmptyString );
613 
614  m_Parent->CreateNetlist( currPage->m_IdNetType, fullpath, netlist_opt );
615 
617 
618  EndModal( wxID_OK );
619 }
620 
621 
623  wxString * aExt, wxString * aWildCard )
624 {
625  wxString fileExt;
626  wxString fileWildcard;
627 
628  bool ret = true;
629 
630  switch( aNetTypeId )
631  {
632  case NET_TYPE_SPICE:
633  fileExt = wxT( "cir" );
634  fileWildcard = _( "SPICE netlist file (.cir)|*.cir" );
635  break;
636 
637  case NET_TYPE_CADSTAR:
638  fileExt = wxT( "frp" );
639  fileWildcard = _( "CadStar netlist file (.frp)|*.frp" );
640  break;
641 
642  case NET_TYPE_PCBNEW:
643  case NET_TYPE_ORCADPCB2:
644  fileExt = NetlistFileExtension;
645  fileWildcard = NetlistFileWildcard;
646  break;
647 
648  default: // custom, NET_TYPE_CUSTOM1 and greater
649  fileWildcard = AllFilesWildcard;
650  ret = false;
651  }
652 
653  if( aExt )
654  *aExt = fileExt;
655 
656  if( aWildCard )
657  *aWildCard = fileWildcard;
658 
659  return ret;
660 }
661 
662 
663 void NETLIST_DIALOG::RunSimulator( wxCommandEvent& event )
664 {
665  wxFileName fn;
666  wxString ExecFile, CommandLine;
667 
669 
670  wxString tmp = m_PanelNetType[PANELSPICE]->m_CommandStringCtrl->GetValue();
671  tmp.Trim( false );
672  tmp.Trim( true );
674  ExecFile = tmp.BeforeFirst( ' ' );
675  CommandLine = tmp.AfterFirst( ' ' );
676 
677  // Calculate the netlist filename
678  fn = g_RootSheet->GetScreen()->GetFileName();
679  fn.SetExt( wxT( "cir" ) );
680  CommandLine += wxT( " \"" ) + fn.GetFullPath() + wxT( "\"" );
681 
682  NETLIST_PAGE_DIALOG* currPage;
683  currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage();
684 
685  // Set spice netlist options:
686  unsigned netlist_opt = 0;
687 
688  if( currPage->m_SpiceAjustPassiveValues && currPage->m_SpiceAjustPassiveValues->GetValue() )
689  netlist_opt |= NET_ADJUST_PASSIVE_VALS;
690 
691  if( ! m_Parent->CreateNetlist( currPage->m_IdNetType, fn.GetFullPath(),
692  netlist_opt ) )
693  return;
694 
695  ExecuteFile( this, ExecFile, CommandLine );
696 }
697 
698 
700 {
701  wxString msg, Command;
702 
704 
706 
707  // Update existing custom pages
708  int jj = 0;
709  for( int ii = 0; ii < CUSTOMPANEL_COUNTMAX; ii++ )
710  {
712 
713  if( currPage == NULL )
714  break;
715 
716  wxString title = currPage->m_TitleStringCtrl->GetValue();
717 
718  if( title.IsEmpty() )
719  continue;
720 
721  msg = CUSTOM_NETLIST_TITLE;
722  msg << jj + 1;
723  m_config->Write( msg, title );
724 
725  Command = currPage->m_CommandStringCtrl->GetValue();
727  msg << jj + 1;
728  m_config->Write( msg, Command );
729  jj++;
730  }
731 
732  // Ensure all other pages are void
733  for(; jj < CUSTOMPANEL_COUNTMAX; jj++ )
734  {
735  msg = CUSTOM_NETLIST_TITLE;
736  msg << jj + 1;
737  m_config->Write( msg, wxEmptyString );
738 
740  msg << jj + 1;
741  m_config->Write( msg, wxEmptyString );
742  }
743 }
744 
745 
746 void NETLIST_DIALOG::OnDelPlugin( wxCommandEvent& event )
747 {
748  NETLIST_PAGE_DIALOG* currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage();
749 
750  currPage->m_CommandStringCtrl->SetValue( wxEmptyString );
751  currPage->m_TitleStringCtrl->SetValue( wxEmptyString );
752 
753  if( currPage->m_IsCurrentFormat->IsChecked() )
754  {
755  currPage->m_IsCurrentFormat->SetValue( false );
756  m_PanelNetType[PANELPCBNEW]->m_IsCurrentFormat->SetValue( true );
757  }
758 
760  EndModal( NET_PLUGIN_CHANGE );
761 }
762 
763 
764 void NETLIST_DIALOG::OnAddPlugin( wxCommandEvent& event )
765 {
766  NETLIST_DIALOG_ADD_PLUGIN dlg( this );
767  if( dlg.ShowModal() != wxID_OK )
768  return;
769 
770  // Creates a new custom plugin page
771  wxString title = dlg.GetPluginTitle();
772 
773  // Verify it does not exists
774  int netTypeId = PANELCUSTOMBASE; // the first not used type id
775  NETLIST_PAGE_DIALOG* currPage;
776  for( int ii = 0; ii < CUSTOMPANEL_COUNTMAX; ii++ )
777  {
778  netTypeId = PANELCUSTOMBASE + ii;
779  currPage = m_PanelNetType[ii + PANELCUSTOMBASE];
780 
781  if( currPage == NULL )
782  break;
783 
784  if( currPage->GetPageNetFmtName() == title )
785  {
786  wxMessageBox( _("This plugin already exists. Abort") );
787  return;
788  }
789  }
790 
791  wxString cmd = dlg.GetPluginTCommandLine();
792  currPage = AddOneCustomPage( title,cmd, (NETLIST_TYPE_ID)netTypeId );
793  m_PanelNetType[netTypeId] = currPage;
795 
796  // Close and reopen dialog to rebuild the dialog after changes
797  EndModal( NET_PLUGIN_CHANGE );
798 }
799 
800 
803 {
804  m_Parent = parent;
805  GetSizer()->SetSizeHints( this );
806 }
807 
808 
809 void NETLIST_DIALOG_ADD_PLUGIN::OnOKClick( wxCommandEvent& event )
810 {
811  if( m_textCtrlCommand->GetValue() == wxEmptyString )
812  {
813  wxMessageBox( _( "Error. You must provide a command String" ) );
814  return;
815  }
816 
817  if( m_textCtrlName->GetValue() == wxEmptyString )
818  {
819  wxMessageBox( _( "Error. You must provide a Title" ) );
820  return;
821  }
822 
823  EndModal( wxID_OK );
824 }
825 
826 
827 void NETLIST_DIALOG_ADD_PLUGIN::OnBrowsePlugins( wxCommandEvent& event )
828 {
829  wxString FullFileName, Mask, Path;
830 
831  Mask = wxT( "*" );
832 #ifndef __WXMAC__
833  Path = Pgm().GetExecutablePath();
834 #else
835  Path = GetOSXKicadDataDir() + wxT( "/plugins" );
836 #endif
837  FullFileName = EDA_FILE_SELECTOR( _( "Plugin files:" ),
838  Path,
839  FullFileName,
840  wxEmptyString,
841  Mask,
842  this,
843  wxFD_OPEN,
844  true
845  );
846  if( FullFileName.IsEmpty() )
847  return;
848 
849  // Creates a default command line, suitable for external tool xslproc or python
850  // try to build a default command line depending on plugin extension
851  // "xsl" or "exe" or "py"
852  wxString cmdLine;
853  wxFileName fn( FullFileName );
854  wxString ext = fn.GetExt();
855 
856  if( ext == wxT("xsl" ) )
857  cmdLine.Printf(wxT("xsltproc -o \"%%O\" \"%s\" \"%%I\""), GetChars(FullFileName) );
858  else if( ext == wxT("exe" ) || ext.IsEmpty() )
859  cmdLine.Printf(wxT("\"%s\" > \"%%O\" < \"%%I\""), GetChars(FullFileName) );
860  else if( ext == wxT("py" ) || ext.IsEmpty() )
861  cmdLine.Printf(wxT("python \"%s\" \"%%I\" \"%%O\""), GetChars(FullFileName) );
862  else
863  cmdLine.Printf(wxT("\"%s\""), GetChars(FullFileName) );
864 
865  m_textCtrlCommand->SetValue( cmdLine );
866 
867  /* Get a title for this page */
868  wxString title = m_textCtrlName->GetValue();
869 
870  if( title.IsEmpty() )
871  wxMessageBox( _( "Do not forget to choose a title for this netlist control page" ) );
872 }
873 
874 
876 {
877  NETLIST_DIALOG dlg( aCaller );
878 
879  return dlg.ShowModal();
880 }
881 
Definition of the SCH_SHEET class for Eeschema.
const wxString GetNetListFormatName() const
Definition: schframe.h:246
wxTextCtrl * m_textCtrlDefaultFileName
wxString GetSimulatorCommand() const
Definition: schframe.h:1378
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:1376
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:55
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:103
#define CUSTOM_NETLIST_TITLE
bool GetSpiceAjustPassiveValues() const
Definition: schframe.h:250
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:248
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:1380
void OnNetlistTypeSelection(wxNotebookEvent &event) override
void ClearMsgPanel(void)
Clear all messages from the message panel.
Definition: draw_frame.cpp:764
void SetSpiceAjustPassiveValues(bool aEnable)
Definition: schframe.h:252
const wxString GetPageNetFmtName()
function GetPageNetFmtName
int InvokeDialogNetList(SCH_EDIT_FRAME *aCaller)
void SelectDefaultNetlistType(wxCommandEvent &event)