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
344
345
347{
348 EXPORT_NETLIST_PAGE* pg = new EXPORT_NETLIST_PAGE( m_NoteBook, wxT( "SPICE" ), NET_TYPE_SPICE, false );
349
350 wxStaticText* label = new wxStaticText( pg, wxID_ANY, _( "Export netlist in SPICE format" ) );
351 pg->m_LeftBoxSizer->Add( label, 0, wxBOTTOM, 10 );
352
353 pg->m_CurSheetAsRoot = new wxCheckBox( pg, ID_CUR_SHEET_AS_ROOT, _( "Use current sheet as root" ) );
354 pg->m_CurSheetAsRoot->SetToolTip( _( "Export netlist only for the current sheet" ) );
355 pg->m_LeftBoxSizer->Add( pg->m_CurSheetAsRoot, 0, wxGROW | wxBOTTOM | wxRIGHT, 5 );
356
357 pg->m_SaveAllVoltages = new wxCheckBox( pg, ID_SAVE_ALL_VOLTAGES, _( "Save all voltages" ) );
358 pg->m_SaveAllVoltages->SetToolTip( _( "Write a directive to save all voltages (.save all)" ) );
359 pg->m_LeftBoxSizer->Add( pg->m_SaveAllVoltages, 0, wxBOTTOM | wxRIGHT, 5 );
360
361 pg->m_SaveAllCurrents = new wxCheckBox( pg, ID_SAVE_ALL_CURRENTS, _( "Save all currents" ) );
362 pg->m_SaveAllCurrents->SetToolTip( _( "Write a directive to save all currents (.probe alli)" ) );
363 pg->m_LeftBoxSizer->Add( pg->m_SaveAllCurrents, 0, wxBOTTOM | wxRIGHT, 5 );
364
365 pg->m_SaveAllDissipations = new wxCheckBox( pg, ID_SAVE_ALL_DISSIPATIONS, _( "Save all power dissipations" ) );
366 pg->m_SaveAllDissipations->SetToolTip( _( "Write directives to save power dissipation of all items "
367 "(.probe p(<item>))" ) );
368 pg->m_LeftBoxSizer->Add( pg->m_SaveAllDissipations, 0, wxBOTTOM | wxRIGHT, 5 );
369
370 pg->m_SaveAllEvents = new wxCheckBox( pg, ID_SAVE_ALL_EVENTS, _( "Save all digital event data" ) );
371 pg->m_SaveAllEvents->SetToolTip( _( "If not set, write a directive to prevent the saving of digital event data "
372 "(esave none)" ) );
373 pg->m_LeftBoxSizer->Add( pg->m_SaveAllEvents, 0, wxBOTTOM | wxRIGHT, 5 );
374
375
376 pg->m_RunExternalSpiceCommand = new wxCheckBox( pg, ID_RUN_SIMULATOR, _( "Run external simulator command:" ) );
377 pg->m_RunExternalSpiceCommand->SetToolTip( _( "Enter the command line to run SPICE\n"
378 "Usually '<path to SPICE binary> \"%I\"'\n"
379 "%I will be replaced by the netlist filepath" ) );
380 pg->m_LowBoxSizer->Add( pg->m_RunExternalSpiceCommand, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
381
382 pg->m_CommandStringCtrl = new wxTextCtrl( pg, wxID_ANY, wxT( "spice \"%I\"" ) );
383
384 pg->m_CommandStringCtrl->SetInsertionPoint( 1 );
385 pg->m_LowBoxSizer->Add( pg->m_CommandStringCtrl, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
386
388}
389
390
392{
393 auto* pg = new EXPORT_NETLIST_PAGE( m_NoteBook, wxT( "SPICE Model" ), NET_TYPE_SPICE_MODEL, false );
394
395 wxStaticText* label = new wxStaticText( pg, wxID_ANY, _( "Export netlist as a SPICE .subckt model" ) );
396 pg->m_LeftBoxSizer->Add( label, 0, wxBOTTOM, 10 );
397
398 pg->m_CurSheetAsRoot = new wxCheckBox( pg, ID_CUR_SHEET_AS_ROOT, _( "Use current sheet as root" ) );
399 pg->m_CurSheetAsRoot->SetToolTip( _( "Export netlist only for the current sheet" ) );
400 pg->m_LeftBoxSizer->Add( pg->m_CurSheetAsRoot, 0, wxEXPAND | wxBOTTOM | wxRIGHT, 5 );
401
403}
404
405
407{
408 EXPORT_NETLIST_PAGE* currPage;
409 EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
410 wxCHECK( cfg, /* void */ );
411
412 for( size_t i = 0; i < CUSTOMPANEL_COUNTMAX && i < cfg->m_NetlistPanel.plugins.size(); i++ )
413 {
414 // pairs of (title, command) are stored
415 currPage = AddOneCustomPage( cfg->m_NetlistPanel.plugins[i].name,
416 cfg->m_NetlistPanel.plugins[i].command,
417 static_cast<NETLIST_TYPE_ID>( NET_TYPE_CUSTOM1 + i ) );
418
419 m_PanelNetType[PANELCUSTOMBASE + i] = currPage;
420 }
421}
422
423
425 const wxString& aCommandString,
426 NETLIST_TYPE_ID aNetTypeId )
427{
428 EXPORT_NETLIST_PAGE* pg = new EXPORT_NETLIST_PAGE( m_NoteBook, aTitle, aNetTypeId, true );
429
430 pg->m_LowBoxSizer->Add( new wxStaticText( pg, wxID_ANY, _( "Title:" ) ), 0,
431 wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 5 );
432
433 pg->m_LowBoxSizer->AddSpacer( 2 );
434
435 pg->m_TitleStringCtrl = new wxTextCtrl( pg, wxID_ANY, aTitle );
436
437 pg->m_TitleStringCtrl->SetInsertionPoint( 1 );
438 pg->m_LowBoxSizer->Add( pg->m_TitleStringCtrl, 0, wxEXPAND | wxLEFT | wxRIGHT, 5 );
439
440 pg->m_LowBoxSizer->AddSpacer( 10 );
441
442 pg->m_LowBoxSizer->Add( new wxStaticText( pg, wxID_ANY, _( "Netlist command:" ) ), 0,
443 wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 5 );
444
445 pg->m_LowBoxSizer->AddSpacer( 2 );
446
447 pg->m_CommandStringCtrl = new wxTextCtrl( pg, wxID_ANY, aCommandString );
448
449 pg->m_CommandStringCtrl->SetInsertionPoint( 1 );
450 pg->m_LowBoxSizer->Add( pg->m_CommandStringCtrl, 0, wxEXPAND | wxLEFT | wxRIGHT, 5 );
451
452 return pg;
453}
454
455
457{
459}
460
461
467
468
470{
471 wxFileName fn;
472 wxString fileWildcard;
473 wxString fileExt;
474 wxString title = _( "Save Netlist File" );
475
476 if( m_job )
477 {
478 for( const auto& [format, name] : JOB_EXPORT_SCH_NETLIST::GetFormatNameMap() )
479 {
480 if( name == m_PanelNetType[m_NoteBook->GetSelection()]->GetPageNetFmtName() )
481 {
482 m_job->format = format;
483 break;
484 }
485 }
486
487 m_job->SetConfiguredOutputPath( m_outputPath->GetValue() );
488 m_job->m_spiceSaveAllVoltages = m_PanelNetType[ PANELSPICE ]->m_SaveAllVoltages->IsChecked();
489 m_job->m_spiceSaveAllCurrents = m_PanelNetType[ PANELSPICE ]->m_SaveAllCurrents->IsChecked();
490 m_job->m_spiceSaveAllDissipations = m_PanelNetType[ PANELSPICE ]->m_SaveAllDissipations->IsChecked();
491 m_job->m_spiceSaveAllEvents = m_PanelNetType[ PANELSPICE ]->m_SaveAllEvents->IsChecked();
492
493 return true;
494 }
495
496 EXPORT_NETLIST_PAGE* currPage;
497 currPage = (EXPORT_NETLIST_PAGE*) m_NoteBook->GetCurrentPage();
498
499 bool runExternalSpiceCommand = false;
500 unsigned netlist_opt = 0;
501
502 // Calculate the netlist filename
503 fn = m_editFrame->Schematic().GetFileName();
504 FilenamePrms( currPage->m_IdNetType, &fileExt, &fileWildcard );
505
506 // Set some parameters
507 switch( currPage->m_IdNetType )
508 {
509 case NET_TYPE_SPICE:
510 // Set spice netlist options:
512
513 if( currPage->m_SaveAllVoltages->GetValue() )
515
516 if( currPage->m_SaveAllCurrents->GetValue() )
518
519 if( currPage->m_SaveAllDissipations->GetValue() )
521
522 if( currPage->m_SaveAllEvents->GetValue() )
524
525 if( currPage->m_CurSheetAsRoot->GetValue() )
527
528 runExternalSpiceCommand = currPage->m_RunExternalSpiceCommand->GetValue();
529 break;
530
532 if( currPage->m_CurSheetAsRoot->GetValue() )
534
535 break;
536
537 case NET_TYPE_CADSTAR:
538 break;
539
540 case NET_TYPE_PCBNEW:
541 break;
542
544 break;
545
546 case NET_TYPE_ALLEGRO:
547 break;
548
549 case NET_TYPE_PADS:
550 break;
551
552 default: // custom, NET_TYPE_CUSTOM1 and greater
553 title.Printf( _( "%s Export" ), currPage->m_TitleStringCtrl->GetValue() );
554 break;
555 }
556
557 wxString fullpath;
558
559 if( runExternalSpiceCommand )
560 {
561 fn.SetExt( FILEEXT::SpiceFileExtension );
562 fullpath = fn.GetFullPath();
563 }
564 else
565 {
566 fn.SetExt( fileExt );
567
568 if( fn.GetPath().IsEmpty() )
569 fn.SetPath( wxPathOnly( Prj().GetProjectFullName() ) );
570
571 wxString fullname = fn.GetFullName();
572 wxString path = fn.GetPath();
573
574 // full name does not and should not include the path, per wx docs.
575 wxFileDialog dlg( this, title, path, fullname, fileWildcard, wxFD_SAVE );
576
578
579 if( dlg.ShowModal() == wxID_CANCEL )
580 return false;
581
582 fullpath = dlg.GetPath(); // directory + filename
583 }
584
585 m_editFrame->ClearMsgPanel();
586 REPORTER& reporter = m_MessagesBox->Reporter();
587
588 if( currPage->m_CommandStringCtrl )
589 m_editFrame->SetNetListerCommand( currPage->m_CommandStringCtrl->GetValue() );
590 else
591 m_editFrame->SetNetListerCommand( wxEmptyString );
592
593 if( !m_editFrame->ReadyToNetlist( _( "Exporting netlist requires a fully annotated schematic." ) ) )
594 return false;
595
596 m_editFrame->WriteNetListFile( currPage->m_IdNetType, fullpath, netlist_opt, &reporter );
597
598 if( runExternalSpiceCommand )
599 {
600 // Build the command line
601 wxString commandLine = m_PanelNetType[ PANELSPICE ]->m_CommandStringCtrl->GetValue();
602 commandLine.Replace( wxS( "%I" ), fullpath, true );
603 commandLine.Trim( true ).Trim( false );
604
605 if( !commandLine.IsEmpty() )
606 {
607 std::vector<wxString> argsStrings = SplitCommandLine( commandLine );
608
609 if( !argsStrings.empty() )
610 {
611 std::vector<const wxChar*> argv;
612 argv.reserve( argsStrings.size() + 1 );
613
614 for( wxString& arg : argsStrings )
615 argv.emplace_back( arg.wc_str() );
616
617 argv.emplace_back( nullptr );
618
619 wxExecuteEnv env;
620 wxGetEnvMap( &env.env );
621
622 const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
623
624 for( const auto& [key, value] : envVars )
625 {
626 if( !value.GetValue().IsEmpty() )
627 env.env[key] = value.GetValue();
628 }
629
630 wxFileName netlistFile( fullpath );
631
632 if( !netlistFile.IsAbsolute() )
633 netlistFile.MakeAbsolute( Prj().GetProjectPath() );
634 else
635 netlistFile.MakeAbsolute();
636
637 wxString cwd = netlistFile.GetPath();
638
639 if( cwd.IsEmpty() )
640 cwd = Prj().GetProjectPath();
641
642 env.cwd = cwd;
643
644 wxProcess* process = new wxProcess( GetEventHandler(), wxID_ANY );
645 process->Redirect();
646
647 long pid = wxExecute( argv.data(), wxEXEC_ASYNC, process, &env );
648
649 reporter.ReportHead( commandLine, RPT_SEVERITY_ACTION );
650
651 if( pid <= 0 )
652 {
653 reporter.Report( _( "external simulator not found" ), RPT_SEVERITY_ERROR );
654 reporter.Report( _( "Note: command line is usually: "
655 "<tt>&lt;path to SPICE binary&gt; \"%I\"</tt>" ),
657 delete process;
658 }
659 else
660 {
661 process->Activate();
662
663 std::this_thread::sleep_for( std::chrono::seconds( 1 ) ); // give the process time to start and output any data or errors
664
665 if( process->IsInputAvailable() )
666 {
667 wxInputStream* in = process->GetInputStream();
668 wxTextInputStream textstream( *in );
669
670 while( in->CanRead() )
671 {
672 wxString line = textstream.ReadLine();
673
674 if( !line.IsEmpty() )
675 reporter.Report( line, RPT_SEVERITY_INFO );
676 }
677 }
678
679 if( process->IsErrorAvailable() )
680 {
681 wxInputStream* err = process->GetErrorStream();
682 wxTextInputStream textstream( *err );
683
684 while( err->CanRead() )
685 {
686 wxString line = textstream.ReadLine();
687
688 if( !line.IsEmpty() )
689 {
690 if( line.EndsWith( wxS( "failed with error 2!" ) ) ) // ENOENT
691 {
692 reporter.Report( _( "external simulator not found" ), RPT_SEVERITY_ERROR );
693 reporter.Report( _( "Note: command line is usually: "
694 "<tt>&lt;path to SPICE binary&gt; \"%I\"</tt>" ),
696 }
697 else if( line.EndsWith( wxS( "failed with error 8!" ) ) ) // ENOEXEC
698 {
699 reporter.Report( _( "external simulator has the wrong format or "
700 "architecture" ), RPT_SEVERITY_ERROR );
701 }
702 else if( line.EndsWith( "failed with error 13!" ) ) // EACCES
703 {
704 reporter.Report( _( "permission denied" ), RPT_SEVERITY_ERROR );
705 }
706 else
707 {
708 reporter.Report( line, RPT_SEVERITY_ERROR );
709 }
710 }
711 }
712 }
713
714 process->CloseOutput();
715 process->Detach();
716
717 // Do not delete process, it will delete itself when it terminates
718 }
719 }
720 }
721 }
722
724
725 return !runExternalSpiceCommand;
726}
727
728
729bool DIALOG_EXPORT_NETLIST::FilenamePrms( NETLIST_TYPE_ID aType, wxString* aExt, wxString* aWildCard )
730{
731 wxString fileExt;
732 wxString fileWildcard;
733 bool ret = true;
734
735 switch( aType )
736 {
737 case NET_TYPE_SPICE:
739 fileWildcard = FILEEXT::SpiceNetlistFileWildcard();
740 break;
741
745 break;
746
747 case NET_TYPE_CADSTAR:
750 break;
751
755 break;
756
757 case NET_TYPE_PCBNEW:
759 fileWildcard = FILEEXT::NetlistFileWildcard();
760 break;
761
762 case NET_TYPE_ALLEGRO:
765 break;
766
767 case NET_TYPE_PADS:
769 fileWildcard = FILEEXT::PADSNetlistFileWildcard();
770 break;
771
772 default: // custom, NET_TYPE_CUSTOM1 and greater
773 fileWildcard = FILEEXT::AllFilesWildcard();
774 ret = false;
775 }
776
777 if( aExt )
778 *aExt = fileExt;
779
780 if( aWildCard )
781 *aWildCard = fileWildcard;
782
783 return ret;
784}
785
786
788{
789 EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
790 wxCHECK( cfg, /* void */ );
791
792 cfg->m_NetlistPanel.plugins.clear();
793
794 // Update existing custom pages
795 for( int ii = PANELCUSTOMBASE; ii < PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX; ++ii )
796 {
797 if( EXPORT_NETLIST_PAGE* currPage = m_PanelNetType[ii] )
798 {
799 wxString title = currPage->m_TitleStringCtrl->GetValue();
800 wxString command = currPage->m_CommandStringCtrl->GetValue();
801
802 if( title.IsEmpty() )
803 continue;
804
805 cfg->m_NetlistPanel.plugins.emplace_back( title, wxEmptyString );
806 cfg->m_NetlistPanel.plugins.back().command = command;
807 }
808 }
809}
810
811
812void DIALOG_EXPORT_NETLIST::OnDelGenerator( wxCommandEvent& event )
813{
814 EXPORT_NETLIST_PAGE* currPage = (EXPORT_NETLIST_PAGE*) m_NoteBook->GetCurrentPage();
815
816 if( !currPage->IsCustom() )
817 return;
818
819 currPage->m_CommandStringCtrl->SetValue( wxEmptyString );
820 currPage->m_TitleStringCtrl->SetValue( wxEmptyString );
821
823
825}
826
827
828void DIALOG_EXPORT_NETLIST::OnAddGenerator( wxCommandEvent& event )
829{
831
832 if( dlg.ShowModal() != wxID_OK )
833 return;
834
835 wxString title = dlg.GetGeneratorTitle();
836 wxString cmd = dlg.GetGeneratorTCommandLine();
837
838 // Verify it does not exist
839 for( int ii = PANELCUSTOMBASE; ii < PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX; ++ii )
840 {
841 // Note that we do not check for collisions with m_TitleStringCtrl as that's just
842 // used in the Export File dialog, and is not technically the name of the generator.
843
844 if( m_PanelNetType[ii] && m_PanelNetType[ii]->GetPageNetFmtName() == title )
845 {
846 wxMessageBox( _( "This plugin already exists." ) );
847 return;
848 }
849 }
850
851 // Find the first empty slot
852 int netTypeId = PANELCUSTOMBASE;
853
854 while( m_PanelNetType[netTypeId] )
855 {
856 netTypeId++;
857
858 if( netTypeId == PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX )
859 {
860 wxMessageBox( _( "Maximum number of plugins already added to dialog." ) );
861 return;
862 }
863 }
864
865 m_PanelNetType[netTypeId] = AddOneCustomPage( title, cmd, (NETLIST_TYPE_ID)netTypeId );
866
868
870}
871
872
882
883
885{
886 if( !wxDialog::TransferDataFromWindow() )
887 return false;
888
889 if( m_textCtrlName->GetValue() == wxEmptyString )
890 {
891 wxMessageBox( _( "You must provide a netlist generator title" ) );
892 return false;
893 }
894
895 return true;
896}
897
898
900{
901 wxString FullFileName, Path;
902
903#ifndef __WXMAC__
904 Path = Pgm().GetExecutablePath();
905#else
906 Path = PATHS::GetOSXKicadDataDir() + wxT( "/plugins" );
907#endif
908
909 FullFileName = wxFileSelector( _( "Generator File" ), Path, FullFileName, wxEmptyString,
910 wxFileSelectorDefaultWildcardStr, wxFD_OPEN, this );
911
912 if( FullFileName.IsEmpty() )
913 return;
914
915 // Creates a default command line, suitable for external tool xslproc or python, based on
916 // the plugin extension ("xsl" or "exe" or "py")
917 wxString cmdLine;
918 wxFileName fn( FullFileName );
919 wxString ext = fn.GetExt();
920
921 if( ext == wxT( "xsl" ) )
922 cmdLine.Printf( wxT( "xsltproc -o \"%%O\" \"%s\" \"%%I\"" ), FullFileName );
923 else if( ext == wxT( "exe" ) || ext.IsEmpty() )
924 cmdLine.Printf( wxT( "\"%s\" > \"%%O\" < \"%%I\"" ), FullFileName );
925 else if( ext == wxT( "py" ) || ext.IsEmpty() )
926 cmdLine.Printf( wxT( "python \"%s\" \"%%I\" \"%%O\"" ), FullFileName );
927 else
928 cmdLine.Printf( wxT( "\"%s\"" ), FullFileName );
929
930 m_textCtrlCommand->SetValue( cmdLine );
931
932 // We need a title for this panel
933 // Propose a default value if empty ( i.e. the short filename of the script)
934 if( m_textCtrlName->GetValue().IsEmpty() )
935 m_textCtrlName->SetValue( fn.GetName() );
936}
937
938
940{
941 EXPORT_NETLIST_PAGE* currPage = (EXPORT_NETLIST_PAGE*) m_NoteBook->GetCurrentPage();
942
943 if( currPage == nullptr )
944 return;
945
946 m_buttonDelGenerator->Enable( currPage->IsCustom() );
947}
948
949
951{
952 DIALOG_EXPORT_NETLIST dlg( aCaller );
953
954 int ret = dlg.ShowModal();
955 aCaller->SaveProjectLocalSettings();
956
957 return ret;
958}
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:808
virtual const wxString & GetExecutablePath() const
Definition pgm_base.cpp:888
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition project.cpp:276
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:165
@ 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()
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition idf_helpers.h:37
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:640
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
std::vector< NETLIST_PLUGIN_SETTINGS > plugins
std::string path
IbisParser parser & reporter
Definition of file extensions used in Kicad.