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