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, 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
26/* Functions relative to the dialog creating the netlist for Pcbnew. The dialog is a notebook
27 * with 7 fixed netlist formats:
28 * Pcbnew
29 * ORCADPCB2
30 * Allegro
31 * CADSTAR
32 * Pads
33 * SPICE
34 * SPICE model
35 * and up to CUSTOMPANEL_COUNTMAX user programmable formats. These external converters are
36 * referred to as plugins, but they are really just external binaries.
37 */
38
39#include <pgm_base.h>
40#include <kiface_base.h>
41#include <string_utils.h>
42#include <gestfich.h>
44#include <sch_edit_frame.h>
47#include <invoke_sch_dialog.h>
49#include <paths.h>
51
52#include <eeschema_id.h>
53#include <wx/checkbox.h>
54#include <wx/filedlg.h>
55#include <wx/msgdlg.h>
56#include <wx/process.h>
57#include <wx/regex.h>
58#include <wx/txtstrm.h>
59#include <wx/utils.h>
60
61#include <thread>
62#include <vector>
63
64
65namespace
66{
67std::vector<wxString> SplitCommandLine( const wxString& aCommand )
68{
69 std::vector<wxString> args;
70 wxString current;
71 bool inSingle = false;
72 bool inDouble = false;
73 bool argStarted = false;
74
75 for( wxUniChar c : aCommand )
76 {
77 if( c == '"' && !inSingle )
78 {
79 inDouble = !inDouble;
80 argStarted = true;
81 continue;
82 }
83
84 if( c == '\'' && !inDouble )
85 {
86 inSingle = !inSingle;
87 argStarted = true;
88 continue;
89 }
90
91 if( ( c == ' ' || c == '\t' || c == '\n' || c == '\r' ) && !inSingle && !inDouble )
92 {
93 if( argStarted || !current.IsEmpty() )
94 {
95 args.emplace_back( current );
96 current.clear();
97 argStarted = false;
98 }
99
100 continue;
101 }
102
103 current.Append( c );
104 argStarted = true;
105 }
106
107 if( argStarted || !current.IsEmpty() )
108 args.emplace_back( current );
109
110 return args;
111}
112} // namespace
113
114
115#define CUSTOMPANEL_COUNTMAX 8 // Max number of netlist plugins
116
117/*
118 * PANEL_NETLIST_INDEX values are used as index in m_PanelNetType[]
119 */
121{
122 PANELPCBNEW = 0, /* Handle Netlist format Pcbnew */
123 PANELORCADPCB2, /* Handle Netlist format OracdPcb2 */
124 PANELALLEGRO, /* Handle Netlist format Allegro */
125 PANELCADSTAR, /* Handle Netlist format CadStar */
126 PANELPADS, /* Handle Netlist format PADS */
127 PANELSPICE, /* Handle Netlist format Spice */
128 PANELSPICEMODEL, /* Handle Netlist format Spice Model (subcircuit) */
130
131 /* First auxiliary panel (custom netlists). Subsequent ones use PANELCUSTOMBASE+1,
132 * PANELCUSTOMBASE+2, etc., up to PANELCUSTOMBASE+CUSTOMPANEL_COUNTMAX-1 */
134};
135
136
137/* wxPanels for creating the NoteBook pages for each netlist format: */
138class EXPORT_NETLIST_PAGE : public wxPanel
139{
140public:
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
566 if( dlg.ShowModal() == wxID_CANCEL )
567 return false;
568
569 fullpath = dlg.GetPath(); // directory + filename
570 }
571
572 m_editFrame->ClearMsgPanel();
573 REPORTER& reporter = m_MessagesBox->Reporter();
574
575 if( currPage->m_CommandStringCtrl )
576 m_editFrame->SetNetListerCommand( currPage->m_CommandStringCtrl->GetValue() );
577 else
578 m_editFrame->SetNetListerCommand( wxEmptyString );
579
580 if( !m_editFrame->ReadyToNetlist( _( "Exporting netlist requires a fully annotated schematic." ) ) )
581 return false;
582
583 m_editFrame->WriteNetListFile( currPage->m_IdNetType, fullpath, netlist_opt, &reporter );
584
585 if( runExternalSpiceCommand )
586 {
587 // Build the command line
588 wxString commandLine = m_PanelNetType[ PANELSPICE ]->m_CommandStringCtrl->GetValue();
589 commandLine.Replace( wxS( "%I" ), fullpath, true );
590 commandLine.Trim( true ).Trim( false );
591
592 if( !commandLine.IsEmpty() )
593 {
594 std::vector<wxString> argsStrings = SplitCommandLine( commandLine );
595
596 if( !argsStrings.empty() )
597 {
598 std::vector<const wxChar*> argv;
599 argv.reserve( argsStrings.size() + 1 );
600
601 for( wxString& arg : argsStrings )
602 argv.emplace_back( arg.wc_str() );
603
604 argv.emplace_back( nullptr );
605
606 wxExecuteEnv env;
607 wxGetEnvMap( &env.env );
608
609 const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
610
611 for( const auto& [key, value] : envVars )
612 {
613 if( !value.GetValue().IsEmpty() )
614 env.env[key] = value.GetValue();
615 }
616
617 wxFileName netlistFile( fullpath );
618
619 if( !netlistFile.IsAbsolute() )
620 netlistFile.MakeAbsolute( Prj().GetProjectPath() );
621 else
622 netlistFile.MakeAbsolute();
623
624 wxString cwd = netlistFile.GetPath();
625
626 if( cwd.IsEmpty() )
627 cwd = Prj().GetProjectPath();
628
629 env.cwd = cwd;
630
631 wxProcess* process = new wxProcess( GetEventHandler(), wxID_ANY );
632 process->Redirect();
633
634 long pid = wxExecute( argv.data(), wxEXEC_ASYNC, process, &env );
635
636 reporter.ReportHead( commandLine, RPT_SEVERITY_ACTION );
637
638 if( pid <= 0 )
639 {
640 reporter.Report( _( "external simulator not found" ), RPT_SEVERITY_ERROR );
641 reporter.Report( _( "Note: command line is usually: "
642 "<tt>&lt;path to SPICE binary&gt; \"%I\"</tt>" ),
644 delete process;
645 }
646 else
647 {
648 process->Activate();
649
650 std::this_thread::sleep_for( std::chrono::seconds( 1 ) ); // give the process time to start and output any data or errors
651
652 if( process->IsInputAvailable() )
653 {
654 wxInputStream* in = process->GetInputStream();
655 wxTextInputStream textstream( *in );
656
657 while( in->CanRead() )
658 {
659 wxString line = textstream.ReadLine();
660
661 if( !line.IsEmpty() )
662 reporter.Report( line, RPT_SEVERITY_INFO );
663 }
664 }
665
666 if( process->IsErrorAvailable() )
667 {
668 wxInputStream* err = process->GetErrorStream();
669 wxTextInputStream textstream( *err );
670
671 while( err->CanRead() )
672 {
673 wxString line = textstream.ReadLine();
674
675 if( !line.IsEmpty() )
676 {
677 if( line.EndsWith( wxS( "failed with error 2!" ) ) ) // ENOENT
678 {
679 reporter.Report( _( "external simulator not found" ), RPT_SEVERITY_ERROR );
680 reporter.Report( _( "Note: command line is usually: "
681 "<tt>&lt;path to SPICE binary&gt; \"%I\"</tt>" ),
683 }
684 else if( line.EndsWith( wxS( "failed with error 8!" ) ) ) // ENOEXEC
685 {
686 reporter.Report( _( "external simulator has the wrong format or "
687 "architecture" ), RPT_SEVERITY_ERROR );
688 }
689 else if( line.EndsWith( "failed with error 13!" ) ) // EACCES
690 {
691 reporter.Report( _( "permission denied" ), RPT_SEVERITY_ERROR );
692 }
693 else
694 {
695 reporter.Report( line, RPT_SEVERITY_ERROR );
696 }
697 }
698 }
699 }
700
701 process->CloseOutput();
702 process->Detach();
703
704 // Do not delete process, it will delete itself when it terminates
705 }
706 }
707 }
708 }
709
711
712 return !runExternalSpiceCommand;
713}
714
715
716bool DIALOG_EXPORT_NETLIST::FilenamePrms( NETLIST_TYPE_ID aType, wxString * aExt, wxString * aWildCard )
717{
718 wxString fileExt;
719 wxString fileWildcard;
720 bool ret = true;
721
722 switch( aType )
723 {
724 case NET_TYPE_SPICE:
726 fileWildcard = FILEEXT::SpiceNetlistFileWildcard();
727 break;
728
729 case NET_TYPE_CADSTAR:
732 break;
733
737 break;
738
739 case NET_TYPE_PCBNEW:
741 fileWildcard = FILEEXT::NetlistFileWildcard();
742 break;
743
744 case NET_TYPE_ALLEGRO:
747 break;
748
749 case NET_TYPE_PADS:
751 fileWildcard = FILEEXT::PADSNetlistFileWildcard();
752 break;
753
754
755 default: // custom, NET_TYPE_CUSTOM1 and greater
756 fileWildcard = FILEEXT::AllFilesWildcard();
757 ret = false;
758 }
759
760 if( aExt )
761 *aExt = fileExt;
762
763 if( aWildCard )
764 *aWildCard = fileWildcard;
765
766 return ret;
767}
768
769
771{
772 EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
773 wxCHECK( cfg, /* void */ );
774
775 cfg->m_NetlistPanel.plugins.clear();
776
777 // Update existing custom pages
778 for( int ii = PANELCUSTOMBASE; ii < PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX; ++ii )
779 {
780 if( EXPORT_NETLIST_PAGE* currPage = m_PanelNetType[ii] )
781 {
782 wxString title = currPage->m_TitleStringCtrl->GetValue();
783 wxString command = currPage->m_CommandStringCtrl->GetValue();
784
785 if( title.IsEmpty() || command.IsEmpty() )
786 continue;
787
788 cfg->m_NetlistPanel.plugins.emplace_back( title, wxEmptyString );
789 cfg->m_NetlistPanel.plugins.back().command = command;
790 }
791 }
792}
793
794
795void DIALOG_EXPORT_NETLIST::OnDelGenerator( wxCommandEvent& event )
796{
797 EXPORT_NETLIST_PAGE* currPage = (EXPORT_NETLIST_PAGE*) m_NoteBook->GetCurrentPage();
798
799 if( !currPage->IsCustom() )
800 return;
801
802 currPage->m_CommandStringCtrl->SetValue( wxEmptyString );
803 currPage->m_TitleStringCtrl->SetValue( wxEmptyString );
804
806
807 if( IsQuasiModal() )
809 else
810 EndDialog( NET_PLUGIN_CHANGE );
811}
812
813
814void DIALOG_EXPORT_NETLIST::OnAddGenerator( wxCommandEvent& event )
815{
817
818 if( dlg.ShowModal() != wxID_OK )
819 return;
820
821 wxString title = dlg.GetGeneratorTitle();
822 wxString cmd = dlg.GetGeneratorTCommandLine();
823
824 // Verify it does not exists
825 for( int ii = PANELCUSTOMBASE; ii < PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX; ++ii )
826 {
827 if( m_PanelNetType[ii] && m_PanelNetType[ii]->GetPageNetFmtName() == title )
828 {
829 wxMessageBox( _( "This plugin already exists." ) );
830 return;
831 }
832 }
833
834 // Find the first empty slot
835 int netTypeId = PANELCUSTOMBASE;
836
837 while( m_PanelNetType[netTypeId] )
838 {
839 netTypeId++;
840
841 if( netTypeId == PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX )
842 {
843 wxMessageBox( _( "Maximum number of plugins already added to dialog." ) );
844 return;
845 }
846 }
847
848 m_PanelNetType[netTypeId] = AddOneCustomPage( title, cmd, (NETLIST_TYPE_ID)netTypeId );
849
851
852 if( IsQuasiModal() )
854 else
855 EndDialog( NET_PLUGIN_CHANGE );
856}
857
858
868
869
871{
872 if( !wxDialog::TransferDataFromWindow() )
873 return false;
874
875 if( m_textCtrlName->GetValue() == wxEmptyString )
876 {
877 wxMessageBox( _( "You must provide a netlist generator title" ) );
878 return false;
879 }
880
881 return true;
882}
883
884
886{
887 wxString FullFileName, Path;
888
889#ifndef __WXMAC__
890 Path = Pgm().GetExecutablePath();
891#else
892 Path = PATHS::GetOSXKicadDataDir() + wxT( "/plugins" );
893#endif
894
895 FullFileName = wxFileSelector( _( "Generator File" ), Path, FullFileName, wxEmptyString,
896 wxFileSelectorDefaultWildcardStr, wxFD_OPEN, this );
897
898 if( FullFileName.IsEmpty() )
899 return;
900
901 // Creates a default command line, suitable for external tool xslproc or python, based on
902 // the plugin extension ("xsl" or "exe" or "py")
903 wxString cmdLine;
904 wxFileName fn( FullFileName );
905 wxString ext = fn.GetExt();
906
907 if( ext == wxT( "xsl" ) )
908 cmdLine.Printf( wxT( "xsltproc -o \"%%O\" \"%s\" \"%%I\"" ), FullFileName );
909 else if( ext == wxT( "exe" ) || ext.IsEmpty() )
910 cmdLine.Printf( wxT( "\"%s\" > \"%%O\" < \"%%I\"" ), FullFileName );
911 else if( ext == wxT( "py" ) || ext.IsEmpty() )
912 cmdLine.Printf( wxT( "python \"%s\" \"%%I\" \"%%O\"" ), FullFileName );
913 else
914 cmdLine.Printf( wxT( "\"%s\"" ), FullFileName );
915
916 m_textCtrlCommand->SetValue( cmdLine );
917
918 // We need a title for this panel
919 // Propose a default value if empty ( i.e. the short filename of the script)
920 if( m_textCtrlName->GetValue().IsEmpty() )
921 m_textCtrlName->SetValue( fn.GetName() );
922}
923
924
926{
927 EXPORT_NETLIST_PAGE* currPage = (EXPORT_NETLIST_PAGE*) m_NoteBook->GetCurrentPage();
928
929 if( currPage == nullptr )
930 return;
931
932 m_buttonDelGenerator->Enable( currPage->IsCustom() );
933}
934
935
937{
938 DIALOG_EXPORT_NETLIST dlg( aCaller );
939
940 int ret = dlg.ShowModal();
941 aCaller->SaveProjectLocalSettings();
942
943 return ret;
944}
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
bool IsQuasiModal() const
Definition dialog_shim.h:93
void EndQuasiModal(int retCode)
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:95
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:822
virtual const wxString & GetExecutablePath() const
Definition pgm_base.cpp:890
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition project.cpp:162
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
virtual REPORTER & ReportHead(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Places the report at the beginning of the list for objects that support ordering.
Definition reporter.h:121
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Definition reporter.h:102
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)
@ ID_END_EESCHEMA_ID_LIST
Definition eeschema_id.h:78
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()
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...
NETLIST_TYPE_ID
netlist types
Definition netlist.h:35
@ NET_TYPE_CADSTAR
Definition netlist.h:40
@ NET_TYPE_ORCADPCB2
Definition netlist.h:39
@ NET_TYPE_SPICE
Definition netlist.h:41
@ NET_TYPE_ALLEGRO
Definition netlist.h:43
@ NET_TYPE_SPICE_MODEL
Definition netlist.h:42
@ NET_TYPE_PCBNEW
Definition netlist.h:38
@ NET_TYPE_PADS
Definition netlist.h:44
@ NET_TYPE_CUSTOM1
Definition netlist.h:45
static PGM_BASE * process
Definition pgm_base.cpp:910
PGM_BASE & Pgm()
The global program "get" accessor.
Definition pgm_base.cpp:913
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
Definition of file extensions used in Kicad.