KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_export_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, [email protected]
5 * Copyright (C) 2013 Wayne Stambaugh <[email protected]>
6 * Copyright The 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, see <https://www.gnu.org/licenses/>.
20 */
21
22/* Functions relative to the dialog creating the netlist for Pcbnew. The dialog is a notebook
23 * with 7 fixed netlist formats:
24 * Pcbnew
25 * ORCADPCB2
26 * Allegro
27 * CADSTAR
28 * Pads
29 * SPICE
30 * SPICE model
31 * and up to CUSTOMPANEL_COUNTMAX user programmable formats. These external converters are
32 * referred to as plugins, but they are really just external binaries.
33 */
34
35#include <properties/property.h>
36#include <pgm_base.h>
37#include <kiface_base.h>
38#include <string_utils.h>
39#include <gestfich.h>
41#include <sch_edit_frame.h>
44#include <invoke_sch_dialog.h>
46#include <paths.h>
48#include <kiplatform/ui.h>
49
50#include <eeschema_id.h>
51#include <wx/checkbox.h>
52#include <wx/filedlg.h>
53#include <wx/msgdlg.h>
54#include <wx/process.h>
55#include <wx/regex.h>
56#include <wx/txtstrm.h>
57#include <wx/utils.h>
58
59#include <thread>
60#include <vector>
62
63
64namespace
65{
66std::vector<wxString> SplitCommandLine( const wxString& aCommand )
67{
68 std::vector<wxString> args;
69 wxString current;
70 bool inSingle = false;
71 bool inDouble = false;
72 bool argStarted = false;
73
74 for( wxUniChar c : aCommand )
75 {
76 if( c == '"' && !inSingle )
77 {
78 inDouble = !inDouble;
79 argStarted = true;
80 continue;
81 }
82
83 if( c == '\'' && !inDouble )
84 {
85 inSingle = !inSingle;
86 argStarted = true;
87 continue;
88 }
89
90 if( ( c == ' ' || c == '\t' || c == '\n' || c == '\r' ) && !inSingle && !inDouble )
91 {
92 if( argStarted || !current.IsEmpty() )
93 {
94 args.emplace_back( current );
95 current.clear();
96 argStarted = false;
97 }
98
99 continue;
100 }
101
102 current.Append( c );
103 argStarted = true;
104 }
105
106 if( argStarted || !current.IsEmpty() )
107 args.emplace_back( current );
108
109 return args;
110}
111} // namespace
112
113
114#define CUSTOMPANEL_COUNTMAX 8 // Max number of netlist plugins
115
116/*
117 * PANEL_NETLIST_INDEX values are used as index in m_PanelNetType[]
118 */
120{
121 PANELPCBNEW = 0, /* Handle Netlist format Pcbnew */
122 PANELORCADPCB2, /* Handle Netlist format OracdPcb2 */
123 PANELALLEGRO, /* Handle Netlist format Allegro */
124 PANELCADSTAR, /* Handle Netlist format CadStar */
125 PANELPADS, /* Handle Netlist format PADS */
126 PANELSPICE, /* Handle Netlist format Spice */
127 PANELSPICEMODEL, /* Handle Netlist format Spice Model (subcircuit) */
129
130 /* First auxiliary panel (custom netlists). Subsequent ones use PANELCUSTOMBASE+1,
131 * PANELCUSTOMBASE+2, etc., up to PANELCUSTOMBASE+CUSTOMPANEL_COUNTMAX-1 */
133};
134
135
136/* wxPanels for creating the NoteBook pages for each netlist format: */
137class EXPORT_NETLIST_PAGE : public wxPanel
138{
139public:
150 EXPORT_NETLIST_PAGE( wxNotebook* aParent, const wxString& aTitle, NETLIST_TYPE_ID aIdNetType, bool aCustom );
152
156 const wxString GetPageNetFmtName() { return m_pageNetFmtName; }
157
158 bool IsCustom() const { return m_custom; }
159
160public:
162
163 // opt to reformat passive component values (e.g. 1M -> 1Meg):
164 wxCheckBox* m_CurSheetAsRoot;
165 wxCheckBox* m_SaveAllVoltages;
166 wxCheckBox* m_SaveAllCurrents;
168 wxCheckBox* m_SaveAllEvents;
171 wxTextCtrl* m_TitleStringCtrl;
172 wxBoxSizer* m_LeftBoxSizer;
173 wxBoxSizer* m_RightBoxSizer;
175 wxBoxSizer* m_LowBoxSizer;
176
177private:
180};
181
182
184{
185public:
187
188 const wxString GetGeneratorTitle() { return m_textCtrlName->GetValue(); }
189 const wxString GetGeneratorTCommandLine() { return m_textCtrlCommand->GetValue(); }
190
191 bool TransferDataFromWindow() override;
192
193private:
197 void OnBrowseGenerators( wxCommandEvent& event ) override;
198
200};
201
202
203/* Event id for notebook page buttons: */
213
214
215EXPORT_NETLIST_PAGE::EXPORT_NETLIST_PAGE( wxNotebook* aParent, const wxString& aTitle,
216 NETLIST_TYPE_ID aIdNetType, bool aCustom ) :
217 wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ),
218 m_IdNetType( aIdNetType ),
219 m_CurSheetAsRoot( nullptr ),
220 m_SaveAllVoltages( nullptr ),
221 m_SaveAllCurrents( nullptr ),
222 m_SaveAllDissipations( nullptr ),
223 m_SaveAllEvents( nullptr ),
224 m_RunExternalSpiceCommand( nullptr ),
225 m_CommandStringCtrl( nullptr ),
226 m_TitleStringCtrl( nullptr ),
227 m_pageNetFmtName( aTitle ),
228 m_custom( aCustom )
229{
230 aParent->AddPage( this, aTitle, false );
231
232 wxBoxSizer* MainBoxSizer = new wxBoxSizer( wxVERTICAL );
233 SetSizer( MainBoxSizer );
234 wxBoxSizer* UpperBoxSizer = new wxBoxSizer( wxHORIZONTAL );
235 m_LowBoxSizer = new wxBoxSizer( wxVERTICAL );
236 MainBoxSizer->Add( UpperBoxSizer, 0, wxEXPAND | wxALL, 5 );
237 MainBoxSizer->Add( m_LowBoxSizer, 0, wxEXPAND | wxALL, 5 );
238
239 m_LeftBoxSizer = new wxBoxSizer( wxVERTICAL );
240 m_RightBoxSizer = new wxBoxSizer( wxVERTICAL );
241 m_RightOptionsBoxSizer = new wxBoxSizer( wxVERTICAL );
242 UpperBoxSizer->Add( m_LeftBoxSizer, 0, wxEXPAND | wxALL, 5 );
243 UpperBoxSizer->Add( m_RightBoxSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
244 UpperBoxSizer->Add( m_RightOptionsBoxSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
245}
246
247
249 DIALOG_EXPORT_NETLIST( aEditFrame, aEditFrame )
250{
251}
252
253
255 JOB_EXPORT_SCH_NETLIST* aJob ) :
257 m_job( aJob )
258{
259 m_editFrame = aEditFrame;
260
261 // Initialize the array of netlist pages
263
264 // Add notebook pages:
265 EXPORT_NETLIST_PAGE* page = nullptr;
266 wxStaticText* label = nullptr;
267
268 page = new EXPORT_NETLIST_PAGE( m_NoteBook, wxT( "KiCad" ), NET_TYPE_PCBNEW, false );
269 label = new wxStaticText( page, wxID_ANY, _( "Export netlist in KiCad format" ) );
270 page->m_LeftBoxSizer->Add( label, 0, wxBOTTOM, 10 );
272
273 page = new EXPORT_NETLIST_PAGE( m_NoteBook, wxT( "OrcadPCB2" ), NET_TYPE_ORCADPCB2, false );
274 label = new wxStaticText( page, wxID_ANY, _( "Export netlist in OrcadPCB2 format" ) );
275 page->m_LeftBoxSizer->Add( label, 0, wxBOTTOM, 10 );
277
278 page = new EXPORT_NETLIST_PAGE( m_NoteBook, wxT( "Allegro" ), NET_TYPE_ALLEGRO, false );
279 label = new wxStaticText( page, wxID_ANY, _( "Export netlist in Allegro format" ) );
280 page->m_LeftBoxSizer->Add( label, 0, wxBOTTOM, 10 );
282
283 page = new EXPORT_NETLIST_PAGE( m_NoteBook, wxT( "CadStar" ), NET_TYPE_CADSTAR, false );
284 label = new wxStaticText( page, wxID_ANY, _( "Export netlist in CadStar format" ) );
285 page->m_LeftBoxSizer->Add( label, 0, wxBOTTOM, 10 );
287
288 page = new EXPORT_NETLIST_PAGE( m_NoteBook, wxT( "PADS" ), NET_TYPE_PADS, false );
289 label = new wxStaticText( page, wxID_ANY, _( "Export netlist in PADS format" ) );
290 page->m_LeftBoxSizer->Add( label, 0, wxBOTTOM, 10 );
292
295
296 if( !m_job )
297 {
298 m_outputPath->Hide();
301
302 SetupStandardButtons( { { wxID_OK, _( "Export Netlist" ) },
303 { wxID_CANCEL, _( "Close" ) } } );
304 }
305 else
306 {
307 SetTitle( m_job->GetSettingsDialogTitle() );
308
309 m_MessagesBox->Hide();
310 m_outputPath->SetValue( m_job->GetConfiguredOutputPath() );
311
313
314 // custom netlist (external invokes, not supported)
315 for( int ii = 0; ii < DEFINED_NETLISTS_COUNT + CUSTOMPANEL_COUNTMAX; ++ii )
316 {
317 if( EXPORT_NETLIST_PAGE* candidate = m_PanelNetType[ii] )
318 {
319 if( candidate->GetPageNetFmtName() == JOB_EXPORT_SCH_NETLIST::GetFormatNameMap()[m_job->format] )
320 {
321 m_NoteBook->ChangeSelection( ii );
322 break;
323 }
324 }
325 }
326
327 m_buttonAddGenerator->Hide();
328 m_buttonDelGenerator->Hide();
329 }
330
331 // DIALOG_SHIM needs a unique hash_key because classname will be the same for both job and
332 // non-job versions.
333 m_hash_key = TO_UTF8( GetTitle() );
334
335 // Now all widgets have the size fixed, call FinishDialogSettings
337}
338
339
345
346
348{
349 EXPORT_NETLIST_PAGE* pg = new EXPORT_NETLIST_PAGE( m_NoteBook, wxT( "SPICE" ), NET_TYPE_SPICE, false );
350
351 wxStaticText* label = new wxStaticText( pg, wxID_ANY, _( "Export netlist in SPICE format" ) );
352 pg->m_LeftBoxSizer->Add( label, 0, wxBOTTOM, 10 );
353
354 pg->m_CurSheetAsRoot = new wxCheckBox( pg, ID_CUR_SHEET_AS_ROOT, _( "Use current sheet as root" ) );
355 pg->m_CurSheetAsRoot->SetToolTip( _( "Export netlist only for the current sheet" ) );
356 pg->m_LeftBoxSizer->Add( pg->m_CurSheetAsRoot, 0, wxGROW | wxBOTTOM | wxRIGHT, 5 );
357
358 pg->m_SaveAllVoltages = new wxCheckBox( pg, ID_SAVE_ALL_VOLTAGES, _( "Save all voltages" ) );
359 pg->m_SaveAllVoltages->SetToolTip( _( "Write a directive to save all voltages (.save all)" ) );
360 pg->m_LeftBoxSizer->Add( pg->m_SaveAllVoltages, 0, wxBOTTOM | wxRIGHT, 5 );
361
362 pg->m_SaveAllCurrents = new wxCheckBox( pg, ID_SAVE_ALL_CURRENTS, _( "Save all currents" ) );
363 pg->m_SaveAllCurrents->SetToolTip( _( "Write a directive to save all currents (.probe alli)" ) );
364 pg->m_LeftBoxSizer->Add( pg->m_SaveAllCurrents, 0, wxBOTTOM | wxRIGHT, 5 );
365
366 pg->m_SaveAllDissipations = new wxCheckBox( pg, ID_SAVE_ALL_DISSIPATIONS, _( "Save all power dissipations" ) );
367 pg->m_SaveAllDissipations->SetToolTip( _( "Write directives to save power dissipation of all items "
368 "(.probe p(<item>))" ) );
369 pg->m_LeftBoxSizer->Add( pg->m_SaveAllDissipations, 0, wxBOTTOM | wxRIGHT, 5 );
370
371 pg->m_SaveAllEvents = new wxCheckBox( pg, ID_SAVE_ALL_EVENTS, _( "Save all digital event data" ) );
372 pg->m_SaveAllEvents->SetToolTip( _( "If not set, write a directive to prevent the saving of digital event data "
373 "(esave none)" ) );
374 pg->m_LeftBoxSizer->Add( pg->m_SaveAllEvents, 0, wxBOTTOM | wxRIGHT, 5 );
375
376
377 pg->m_RunExternalSpiceCommand = new wxCheckBox( pg, ID_RUN_SIMULATOR, _( "Run external simulator command:" ) );
378 pg->m_RunExternalSpiceCommand->SetToolTip( _( "Enter the command line to run SPICE\n"
379 "Usually '<path to SPICE binary> \"%I\"'\n"
380 "%I will be replaced by the netlist filepath" ) );
381 pg->m_LowBoxSizer->Add( pg->m_RunExternalSpiceCommand, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
382
383 pg->m_CommandStringCtrl = new wxTextCtrl( pg, wxID_ANY, wxT( "spice \"%I\"" ) );
384
385 pg->m_CommandStringCtrl->SetInsertionPoint( 1 );
386 pg->m_LowBoxSizer->Add( pg->m_CommandStringCtrl, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
387
389}
390
391
393{
394 auto* pg = new EXPORT_NETLIST_PAGE( m_NoteBook, wxT( "SPICE Model" ), NET_TYPE_SPICE_MODEL, false );
395
396 wxStaticText* label = new wxStaticText( pg, wxID_ANY, _( "Export netlist as a SPICE .subckt model" ) );
397 pg->m_LeftBoxSizer->Add( label, 0, wxBOTTOM, 10 );
398
399 pg->m_CurSheetAsRoot = new wxCheckBox( pg, ID_CUR_SHEET_AS_ROOT, _( "Use current sheet as root" ) );
400 pg->m_CurSheetAsRoot->SetToolTip( _( "Export netlist only for the current sheet" ) );
401 pg->m_LeftBoxSizer->Add( pg->m_CurSheetAsRoot, 0, wxEXPAND | wxBOTTOM | wxRIGHT, 5 );
402
404}
405
406
408{
409 EXPORT_NETLIST_PAGE* currPage;
410 EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
411 wxCHECK( cfg, /* void */ );
412
413 for( size_t i = 0; i < CUSTOMPANEL_COUNTMAX && i < cfg->m_NetlistPanel.plugins.size(); i++ )
414 {
415 // pairs of (title, command) are stored
416 currPage = AddOneCustomPage( cfg->m_NetlistPanel.plugins[i].name,
417 cfg->m_NetlistPanel.plugins[i].command,
418 static_cast<NETLIST_TYPE_ID>( NET_TYPE_CUSTOM1 + i ) );
419
420 m_PanelNetType[PANELCUSTOMBASE + i] = currPage;
421 }
422}
423
424
426 const wxString& aCommandString,
427 NETLIST_TYPE_ID aNetTypeId )
428{
429 EXPORT_NETLIST_PAGE* pg = new EXPORT_NETLIST_PAGE( m_NoteBook, aTitle, aNetTypeId, true );
430
431 pg->m_LowBoxSizer->Add( new wxStaticText( pg, wxID_ANY, _( "Title:" ) ), 0,
432 wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 5 );
433
434 pg->m_LowBoxSizer->AddSpacer( 2 );
435
436 pg->m_TitleStringCtrl = new wxTextCtrl( pg, wxID_ANY, aTitle );
437
438 pg->m_TitleStringCtrl->SetInsertionPoint( 1 );
439 pg->m_LowBoxSizer->Add( pg->m_TitleStringCtrl, 0, wxEXPAND | wxLEFT | wxRIGHT, 5 );
440
441 pg->m_LowBoxSizer->AddSpacer( 10 );
442
443 pg->m_LowBoxSizer->Add( new wxStaticText( pg, wxID_ANY, _( "Netlist command:" ) ), 0,
444 wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 5 );
445
446 pg->m_LowBoxSizer->AddSpacer( 2 );
447
448 pg->m_CommandStringCtrl = new wxTextCtrl( pg, wxID_ANY, aCommandString );
449
450 pg->m_CommandStringCtrl->SetInsertionPoint( 1 );
451 pg->m_LowBoxSizer->Add( pg->m_CommandStringCtrl, 0, wxEXPAND | wxLEFT | wxRIGHT, 5 );
452
453 return pg;
454}
455
456
458{
460}
461
462
468
469
471{
472 wxFileName fn;
473 wxString fileWildcard;
474 wxString fileExt;
475 wxString title = _( "Save Netlist File" );
476
477 if( m_job )
478 {
479 for( const auto& [format, name] : JOB_EXPORT_SCH_NETLIST::GetFormatNameMap() )
480 {
481 if( name == m_PanelNetType[m_NoteBook->GetSelection()]->GetPageNetFmtName() )
482 {
483 m_job->format = format;
484 break;
485 }
486 }
487
488 m_job->SetConfiguredOutputPath( m_outputPath->GetValue() );
489 m_job->m_spiceSaveAllVoltages = m_PanelNetType[ PANELSPICE ]->m_SaveAllVoltages->IsChecked();
490 m_job->m_spiceSaveAllCurrents = m_PanelNetType[ PANELSPICE ]->m_SaveAllCurrents->IsChecked();
491 m_job->m_spiceSaveAllDissipations = m_PanelNetType[ PANELSPICE ]->m_SaveAllDissipations->IsChecked();
492 m_job->m_spiceSaveAllEvents = m_PanelNetType[ PANELSPICE ]->m_SaveAllEvents->IsChecked();
493
494 return true;
495 }
496
497 EXPORT_NETLIST_PAGE* currPage;
498 currPage = (EXPORT_NETLIST_PAGE*) m_NoteBook->GetCurrentPage();
499
500 bool runExternalSpiceCommand = false;
501 unsigned netlist_opt = 0;
502
503 // Calculate the netlist filename
504 fn = m_editFrame->Schematic().GetFileName();
505 FilenamePrms( currPage->m_IdNetType, &fileExt, &fileWildcard );
506
507 // Set some parameters
508 switch( currPage->m_IdNetType )
509 {
510 case NET_TYPE_SPICE:
511 // Set spice netlist options:
513
514 if( currPage->m_SaveAllVoltages->GetValue() )
516
517 if( currPage->m_SaveAllCurrents->GetValue() )
519
520 if( currPage->m_SaveAllDissipations->GetValue() )
522
523 if( currPage->m_SaveAllEvents->GetValue() )
525
526 if( currPage->m_CurSheetAsRoot->GetValue() )
528
529 runExternalSpiceCommand = currPage->m_RunExternalSpiceCommand->GetValue();
530 break;
531
533 if( currPage->m_CurSheetAsRoot->GetValue() )
535
536 break;
537
538 case NET_TYPE_CADSTAR:
539 break;
540
541 case NET_TYPE_PCBNEW:
542 break;
543
545 break;
546
547 case NET_TYPE_ALLEGRO:
548 break;
549
550 case NET_TYPE_PADS:
551 break;
552
553 default: // custom, NET_TYPE_CUSTOM1 and greater
554 title.Printf( _( "%s Export" ), currPage->m_TitleStringCtrl->GetValue() );
555 break;
556 }
557
558 wxString fullpath;
559
560 if( runExternalSpiceCommand )
561 {
562 fn.SetExt( FILEEXT::SpiceFileExtension );
563 fullpath = fn.GetFullPath();
564 }
565 else
566 {
567 fn.SetExt( fileExt );
568
569 if( fn.GetPath().IsEmpty() )
570 fn.SetPath( wxPathOnly( Prj().GetProjectFullName() ) );
571
572 wxString fullname = fn.GetFullName();
573 wxString path = fn.GetPath();
574
575 // full name does not and should not include the path, per wx docs.
576 wxFileDialog dlg( this, title, path, fullname, fileWildcard, wxFD_SAVE );
577
579
580 if( dlg.ShowModal() == wxID_CANCEL )
581 return false;
582
583 fullpath = dlg.GetPath(); // directory + filename
584 }
585
586 m_editFrame->ClearMsgPanel();
587 REPORTER& reporter = m_MessagesBox->Reporter();
588
589 if( currPage->m_CommandStringCtrl )
590 m_editFrame->SetNetListerCommand( currPage->m_CommandStringCtrl->GetValue() );
591 else
592 m_editFrame->SetNetListerCommand( wxEmptyString );
593
594 if( !m_editFrame->ReadyToNetlist( _( "Exporting netlist requires a fully annotated schematic." ) ) )
595 return false;
596
597 m_editFrame->WriteNetListFile( currPage->m_IdNetType, fullpath, netlist_opt, &reporter );
598
599 if( runExternalSpiceCommand )
600 {
601 // Build the command line
602 wxString commandLine = m_PanelNetType[ PANELSPICE ]->m_CommandStringCtrl->GetValue();
603 commandLine.Replace( wxS( "%I" ), fullpath, true );
604 commandLine.Trim( true ).Trim( false );
605
606 if( !commandLine.IsEmpty() )
607 {
608 std::vector<wxString> argsStrings = SplitCommandLine( commandLine );
609
610 if( !argsStrings.empty() )
611 {
612 std::vector<const wxChar*> argv;
613 argv.reserve( argsStrings.size() + 1 );
614
615 for( wxString& arg : argsStrings )
616 argv.emplace_back( arg.wc_str() );
617
618 argv.emplace_back( nullptr );
619
620 wxExecuteEnv env;
621 wxGetEnvMap( &env.env );
622
623 const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
624
625 for( const auto& [key, value] : envVars )
626 {
627 if( !value.GetValue().IsEmpty() )
628 env.env[key] = value.GetValue();
629 }
630
631 wxFileName netlistFile( fullpath );
632
633 if( !netlistFile.IsAbsolute() )
634 netlistFile.MakeAbsolute( Prj().GetProjectPath() );
635 else
636 netlistFile.MakeAbsolute();
637
638 wxString cwd = netlistFile.GetPath();
639
640 if( cwd.IsEmpty() )
641 cwd = Prj().GetProjectPath();
642
643 env.cwd = cwd;
644
645 wxProcess* process = new wxProcess( GetEventHandler(), wxID_ANY );
646 process->Redirect();
647
648 long pid = wxExecute( argv.data(), wxEXEC_ASYNC, process, &env );
649
650 reporter.ReportHead( commandLine, RPT_SEVERITY_ACTION );
651
652 if( pid <= 0 )
653 {
654 reporter.Report( _( "external simulator not found" ), RPT_SEVERITY_ERROR );
655 reporter.Report( _( "Note: command line is usually: "
656 "<tt>&lt;path to SPICE binary&gt; \"%I\"</tt>" ),
658 delete process;
659 }
660 else
661 {
662 process->Activate();
663
664 std::this_thread::sleep_for( std::chrono::seconds( 1 ) ); // give the process time to start and output any data or errors
665
666 if( process->IsInputAvailable() )
667 {
668 wxInputStream* in = process->GetInputStream();
669 wxTextInputStream textstream( *in );
670
671 while( in->CanRead() )
672 {
673 wxString line = textstream.ReadLine();
674
675 if( !line.IsEmpty() )
676 reporter.Report( line, RPT_SEVERITY_INFO );
677 }
678 }
679
680 if( process->IsErrorAvailable() )
681 {
682 wxInputStream* err = process->GetErrorStream();
683 wxTextInputStream textstream( *err );
684
685 while( err->CanRead() )
686 {
687 wxString line = textstream.ReadLine();
688
689 if( !line.IsEmpty() )
690 {
691 if( line.EndsWith( wxS( "failed with error 2!" ) ) ) // ENOENT
692 {
693 reporter.Report( _( "external simulator not found" ), RPT_SEVERITY_ERROR );
694 reporter.Report( _( "Note: command line is usually: "
695 "<tt>&lt;path to SPICE binary&gt; \"%I\"</tt>" ),
697 }
698 else if( line.EndsWith( wxS( "failed with error 8!" ) ) ) // ENOEXEC
699 {
700 reporter.Report( _( "external simulator has the wrong format or "
701 "architecture" ), RPT_SEVERITY_ERROR );
702 }
703 else if( line.EndsWith( "failed with error 13!" ) ) // EACCES
704 {
705 reporter.Report( _( "permission denied" ), RPT_SEVERITY_ERROR );
706 }
707 else
708 {
709 reporter.Report( line, RPT_SEVERITY_ERROR );
710 }
711 }
712 }
713 }
714
715 process->CloseOutput();
716 process->Detach();
717
718 // Do not delete process, it will delete itself when it terminates
719 }
720 }
721 }
722 }
723
725
726 return !runExternalSpiceCommand;
727}
728
729
730bool DIALOG_EXPORT_NETLIST::FilenamePrms( NETLIST_TYPE_ID aType, wxString* aExt, wxString* aWildCard )
731{
732 wxString fileExt;
733 wxString fileWildcard;
734 bool ret = true;
735
736 switch( aType )
737 {
738 case NET_TYPE_SPICE:
740 fileWildcard = FILEEXT::SpiceNetlistFileWildcard();
741 break;
742
746 break;
747
748 case NET_TYPE_CADSTAR:
751 break;
752
756 break;
757
758 case NET_TYPE_PCBNEW:
760 fileWildcard = FILEEXT::NetlistFileWildcard();
761 break;
762
763 case NET_TYPE_ALLEGRO:
766 break;
767
768 case NET_TYPE_PADS:
770 fileWildcard = FILEEXT::PADSNetlistFileWildcard();
771 break;
772
773 default: // custom, NET_TYPE_CUSTOM1 and greater
774 fileWildcard = FILEEXT::AllFilesWildcard();
775 ret = false;
776 }
777
778 if( aExt )
779 *aExt = fileExt;
780
781 if( aWildCard )
782 *aWildCard = fileWildcard;
783
784 return ret;
785}
786
787
789{
790 EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
791 wxCHECK( cfg, /* void */ );
792
793 cfg->m_NetlistPanel.plugins.clear();
794
795 // Update existing custom pages
796 for( int ii = PANELCUSTOMBASE; ii < PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX; ++ii )
797 {
798 if( EXPORT_NETLIST_PAGE* currPage = m_PanelNetType[ii] )
799 {
800 wxString title = currPage->m_TitleStringCtrl->GetValue();
801 wxString command = currPage->m_CommandStringCtrl->GetValue();
802
803 if( title.IsEmpty() )
804 continue;
805
806 cfg->m_NetlistPanel.plugins.emplace_back( title, wxEmptyString );
807 cfg->m_NetlistPanel.plugins.back().command = command;
808 }
809 }
810}
811
812
813void DIALOG_EXPORT_NETLIST::OnDelGenerator( wxCommandEvent& event )
814{
815 EXPORT_NETLIST_PAGE* currPage = (EXPORT_NETLIST_PAGE*) m_NoteBook->GetCurrentPage();
816
817 if( !currPage->IsCustom() )
818 return;
819
820 currPage->m_CommandStringCtrl->SetValue( wxEmptyString );
821 currPage->m_TitleStringCtrl->SetValue( wxEmptyString );
822
824
826}
827
828
829void DIALOG_EXPORT_NETLIST::OnAddGenerator( wxCommandEvent& event )
830{
832
833 if( dlg.ShowModal() != wxID_OK )
834 return;
835
836 wxString title = dlg.GetGeneratorTitle();
837 wxString cmd = dlg.GetGeneratorTCommandLine();
838
839 // Verify it does not exist
840 for( int ii = PANELCUSTOMBASE; ii < PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX; ++ii )
841 {
842 // Note that we do not check for collisions with m_TitleStringCtrl as that's just
843 // used in the Export File dialog, and is not technically the name of the generator.
844
845 if( m_PanelNetType[ii] && m_PanelNetType[ii]->GetPageNetFmtName() == title )
846 {
847 wxMessageBox( _( "This plugin already exists." ) );
848 return;
849 }
850 }
851
852 // Find the first empty slot
853 int netTypeId = PANELCUSTOMBASE;
854
855 while( m_PanelNetType[netTypeId] )
856 {
857 netTypeId++;
858
859 if( netTypeId == PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX )
860 {
861 wxMessageBox( _( "Maximum number of plugins already added to dialog." ) );
862 return;
863 }
864 }
865
866 m_PanelNetType[netTypeId] = AddOneCustomPage( title, cmd, (NETLIST_TYPE_ID)netTypeId );
867
869
871}
872
873
883
884
886{
887 if( !wxDialog::TransferDataFromWindow() )
888 return false;
889
890 if( m_textCtrlName->GetValue() == wxEmptyString )
891 {
892 wxMessageBox( _( "You must provide a netlist generator title" ) );
893 return false;
894 }
895
896 return true;
897}
898
899
901{
902 wxString FullFileName, Path;
903
904#ifndef __WXMAC__
905 Path = Pgm().GetExecutablePath();
906#else
907 Path = PATHS::GetOSXKicadDataDir() + wxT( "/plugins" );
908#endif
909
910 FullFileName = wxFileSelector( _( "Generator File" ), Path, FullFileName, wxEmptyString,
911 wxFileSelectorDefaultWildcardStr, wxFD_OPEN, this );
912
913 if( FullFileName.IsEmpty() )
914 return;
915
916 // Creates a default command line, suitable for external tool xslproc or python, based on
917 // the plugin extension ("xsl" or "exe" or "py")
918 wxString cmdLine;
919 wxFileName fn( FullFileName );
920 wxString ext = fn.GetExt();
921
922 if( ext == wxT( "xsl" ) )
923 cmdLine.Printf( wxT( "xsltproc -o \"%%O\" \"%s\" \"%%I\"" ), FullFileName );
924 else if( ext == wxT( "exe" ) || ext.IsEmpty() )
925 cmdLine.Printf( wxT( "\"%s\" > \"%%O\" < \"%%I\"" ), FullFileName );
926 else if( ext == wxT( "py" ) || ext.IsEmpty() )
927 cmdLine.Printf( wxT( "python \"%s\" \"%%I\" \"%%O\"" ), FullFileName );
928 else
929 cmdLine.Printf( wxT( "\"%s\"" ), FullFileName );
930
931 m_textCtrlCommand->SetValue( cmdLine );
932
933 // We need a title for this panel
934 // Propose a default value if empty ( i.e. the short filename of the script)
935 if( m_textCtrlName->GetValue().IsEmpty() )
936 m_textCtrlName->SetValue( fn.GetName() );
937}
938
939
941{
942 EXPORT_NETLIST_PAGE* currPage = (EXPORT_NETLIST_PAGE*) m_NoteBook->GetCurrentPage();
943
944 if( currPage == nullptr )
945 return;
946
947 m_buttonDelGenerator->Enable( currPage->IsCustom() );
948}
949
950
952{
953 DIALOG_EXPORT_NETLIST dlg( aCaller );
954
955 int ret = dlg.ShowModal();
956 aCaller->SaveProjectLocalSettings();
957
958 return ret;
959}
const char * name
DIALOG_EXPORT_NETLIST_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Export Netlist"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
void OnDelGenerator(wxCommandEvent &event) override
Remove a panel relative to a netlist plugin.
void WriteCurrentNetlistSetup()
Write the current netlist options setup in the configuration.
EXPORT_NETLIST_PAGE * AddOneCustomPage(const wxString &aTitle, const wxString &aCommandString, NETLIST_TYPE_ID aNetTypeId)
std::vector< EXPORT_NETLIST_PAGE * > m_PanelNetType
JOB_EXPORT_SCH_NETLIST * m_job
void OnAddGenerator(wxCommandEvent &event) override
Add a new panel for a new netlist plugin.
void OnNetlistTypeSelection(wxNotebookEvent &event) override
bool FilenamePrms(NETLIST_TYPE_ID aType, wxString *aExt, wxString *aWildCard)
Return the filename extension and the wildcard string for this page or a void name if there is no def...
DIALOG_EXPORT_NETLIST(SCH_EDIT_FRAME *aEditFrame)
void SetupStandardButtons(std::map< int, wxString > aLabels={})
std::string m_hash_key
void EndDialogShim(int aReturnCode)
A mode agnostic way to close a dialog.
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
wxWindow * m_initialFocusTarget
int ShowModal() override
PANEL_NETLIST m_NetlistPanel
const wxString GetPageNetFmtName()
~EXPORT_NETLIST_PAGE()=default
EXPORT_NETLIST_PAGE(wxNotebook *aParent, const wxString &aTitle, NETLIST_TYPE_ID aIdNetType, bool aCustom)
Create a setup page for one netlist format.
static std::map< JOB_EXPORT_SCH_NETLIST::FORMAT, wxString > & GetFormatNameMap()
APP_SETTINGS_BASE * KifaceSettings() const
Definition kiface_base.h:92
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
NETLIST_DIALOG_ADD_GENERATOR_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Add Script-based Netlist Exporter"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
NETLIST_DIALOG_ADD_GENERATOR(DIALOG_EXPORT_NETLIST *parent)
void OnBrowseGenerators(wxCommandEvent &event) override
Browse plugin files, and set m_CommandStringCtrl field.
virtual ENV_VAR_MAP & GetLocalEnvVariables() const
Definition pgm_base.cpp:846
virtual const wxString & GetExecutablePath() const
Definition pgm_base.cpp:926
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition project.cpp:277
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
Schematic editor (Eeschema) main window.
void SaveProjectLocalSettings() override
Save changes to the project settings to the project (.pro) file.
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
Definition cvpcb.cpp:178
@ DEFINED_NETLISTS_COUNT
@ ID_SAVE_ALL_VOLTAGES
@ ID_SAVE_ALL_CURRENTS
@ ID_CUR_SHEET_AS_ROOT
@ ID_SAVE_ALL_DISSIPATIONS
#define CUSTOMPANEL_COUNTMAX
int InvokeDialogNetList(SCH_EDIT_FRAME *aCaller)
#define _(s)
NETLIST_TYPE_ID
netlist types
@ ID_END_EESCHEMA_ID_LIST
Definition eeschema_id.h:70
static const std::string CadstarNetlistFileExtension
static const std::string NetlistFileExtension
static const std::string OrCadPcb2NetlistFileExtension
static const std::string SpiceFileExtension
static const std::string PADSNetlistFileExtension
static const std::string SpiceSubcircuitFileExtension
static const std::string AllegroNetlistFileExtension
static wxString SpiceNetlistFileWildcard()
static wxString OrCadPcb2NetlistFileWildcard()
static wxString AllFilesWildcard()
static wxString AllegroNetlistFileWildcard()
static wxString CadstarNetlistFileWildcard()
static wxString PADSNetlistFileWildcard()
static wxString NetlistFileWildcard()
static wxString SpiceSubcircuitFileWildcard()
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
#define NET_PLUGIN_CHANGE
Create and shows DIALOG_EXPORT_NETLIST and returns whatever DIALOG_EXPORT_NETLIST::ShowModal() return...
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:741
static PGM_BASE * process
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_INFO
@ RPT_SEVERITY_ACTION
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
std::vector< NETLIST_PLUGIN_SETTINGS > plugins
std::string path
IbisParser parser & reporter
Definition of file extensions used in Kicad.