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#include <kiplatform/ui.h>
52
53#include <eeschema_id.h>
54#include <wx/checkbox.h>
55#include <wx/filedlg.h>
56#include <wx/msgdlg.h>
57#include <wx/process.h>
58#include <wx/regex.h>
59#include <wx/txtstrm.h>
60#include <wx/utils.h>
61
62#include <thread>
63#include <vector>
64
65
66namespace
67{
68std::vector<wxString> SplitCommandLine( const wxString& aCommand )
69{
70 std::vector<wxString> args;
71 wxString current;
72 bool inSingle = false;
73 bool inDouble = false;
74 bool argStarted = false;
75
76 for( wxUniChar c : aCommand )
77 {
78 if( c == '"' && !inSingle )
79 {
80 inDouble = !inDouble;
81 argStarted = true;
82 continue;
83 }
84
85 if( c == '\'' && !inDouble )
86 {
87 inSingle = !inSingle;
88 argStarted = true;
89 continue;
90 }
91
92 if( ( c == ' ' || c == '\t' || c == '\n' || c == '\r' ) && !inSingle && !inDouble )
93 {
94 if( argStarted || !current.IsEmpty() )
95 {
96 args.emplace_back( current );
97 current.clear();
98 argStarted = false;
99 }
100
101 continue;
102 }
103
104 current.Append( c );
105 argStarted = true;
106 }
107
108 if( argStarted || !current.IsEmpty() )
109 args.emplace_back( current );
110
111 return args;
112}
113} // namespace
114
115
116#define CUSTOMPANEL_COUNTMAX 8 // Max number of netlist plugins
117
118/*
119 * PANEL_NETLIST_INDEX values are used as index in m_PanelNetType[]
120 */
122{
123 PANELPCBNEW = 0, /* Handle Netlist format Pcbnew */
124 PANELORCADPCB2, /* Handle Netlist format OracdPcb2 */
125 PANELALLEGRO, /* Handle Netlist format Allegro */
126 PANELCADSTAR, /* Handle Netlist format CadStar */
127 PANELPADS, /* Handle Netlist format PADS */
128 PANELSPICE, /* Handle Netlist format Spice */
129 PANELSPICEMODEL, /* Handle Netlist format Spice Model (subcircuit) */
131
132 /* First auxiliary panel (custom netlists). Subsequent ones use PANELCUSTOMBASE+1,
133 * PANELCUSTOMBASE+2, etc., up to PANELCUSTOMBASE+CUSTOMPANEL_COUNTMAX-1 */
135};
136
137
138/* wxPanels for creating the NoteBook pages for each netlist format: */
139class EXPORT_NETLIST_PAGE : public wxPanel
140{
141public:
151 EXPORT_NETLIST_PAGE( wxNotebook* aParent, const wxString& aTitle, NETLIST_TYPE_ID aIdNetType, bool aCustom );
153
157 const wxString GetPageNetFmtName() { return m_pageNetFmtName; }
158
159 bool IsCustom() const { return m_custom; }
160
161public:
163
164 // opt to reformat passive component values (e.g. 1M -> 1Meg):
165 wxCheckBox* m_CurSheetAsRoot;
166 wxCheckBox* m_SaveAllVoltages;
167 wxCheckBox* m_SaveAllCurrents;
169 wxCheckBox* m_SaveAllEvents;
172 wxTextCtrl* m_TitleStringCtrl;
173 wxBoxSizer* m_LeftBoxSizer;
174 wxBoxSizer* m_RightBoxSizer;
176 wxBoxSizer* m_LowBoxSizer;
177
178private:
181};
182
183
185{
186public:
188
189 const wxString GetGeneratorTitle() { return m_textCtrlName->GetValue(); }
190 const wxString GetGeneratorTCommandLine() { return m_textCtrlCommand->GetValue(); }
191
192 bool TransferDataFromWindow() override;
193
194private:
198 void OnBrowseGenerators( wxCommandEvent& event ) override;
199
201};
202
203
204/* Event id for notebook page buttons: */
214
215
216EXPORT_NETLIST_PAGE::EXPORT_NETLIST_PAGE( wxNotebook* aParent, const wxString& aTitle,
217 NETLIST_TYPE_ID aIdNetType, bool aCustom ) :
218 wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ),
219 m_IdNetType( aIdNetType ),
220 m_CurSheetAsRoot( nullptr ),
221 m_SaveAllVoltages( nullptr ),
222 m_SaveAllCurrents( nullptr ),
223 m_SaveAllDissipations( nullptr ),
224 m_SaveAllEvents( nullptr ),
225 m_RunExternalSpiceCommand( nullptr ),
226 m_CommandStringCtrl( nullptr ),
227 m_TitleStringCtrl( nullptr ),
228 m_pageNetFmtName( aTitle ),
229 m_custom( aCustom )
230{
231 aParent->AddPage( this, aTitle, false );
232
233 wxBoxSizer* MainBoxSizer = new wxBoxSizer( wxVERTICAL );
234 SetSizer( MainBoxSizer );
235 wxBoxSizer* UpperBoxSizer = new wxBoxSizer( wxHORIZONTAL );
236 m_LowBoxSizer = new wxBoxSizer( wxVERTICAL );
237 MainBoxSizer->Add( UpperBoxSizer, 0, wxEXPAND | wxALL, 5 );
238 MainBoxSizer->Add( m_LowBoxSizer, 0, wxEXPAND | wxALL, 5 );
239
240 m_LeftBoxSizer = new wxBoxSizer( wxVERTICAL );
241 m_RightBoxSizer = new wxBoxSizer( wxVERTICAL );
242 m_RightOptionsBoxSizer = new wxBoxSizer( wxVERTICAL );
243 UpperBoxSizer->Add( m_LeftBoxSizer, 0, wxEXPAND | wxALL, 5 );
244 UpperBoxSizer->Add( m_RightBoxSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
245 UpperBoxSizer->Add( m_RightOptionsBoxSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
246}
247
248
250 DIALOG_EXPORT_NETLIST( aEditFrame, aEditFrame )
251{
252}
253
254
256 JOB_EXPORT_SCH_NETLIST* aJob ) :
258 m_job( aJob )
259{
260 m_editFrame = aEditFrame;
261
262 // Initialize the array of netlist pages
264
265 // Add notebook pages:
266 EXPORT_NETLIST_PAGE* page = nullptr;
267 wxStaticText* label = nullptr;
268
269 page = new EXPORT_NETLIST_PAGE( m_NoteBook, wxT( "KiCad" ), NET_TYPE_PCBNEW, false );
270 label = new wxStaticText( page, wxID_ANY, _( "Export netlist in KiCad format" ) );
271 page->m_LeftBoxSizer->Add( label, 0, wxBOTTOM, 10 );
273
274 page = new EXPORT_NETLIST_PAGE( m_NoteBook, wxT( "OrcadPCB2" ), NET_TYPE_ORCADPCB2, false );
275 label = new wxStaticText( page, wxID_ANY, _( "Export netlist in OrcadPCB2 format" ) );
276 page->m_LeftBoxSizer->Add( label, 0, wxBOTTOM, 10 );
278
279 page = new EXPORT_NETLIST_PAGE( m_NoteBook, wxT( "Allegro" ), NET_TYPE_ALLEGRO, false );
280 label = new wxStaticText( page, wxID_ANY, _( "Export netlist in Allegro format" ) );
281 page->m_LeftBoxSizer->Add( label, 0, wxBOTTOM, 10 );
283
284 page = new EXPORT_NETLIST_PAGE( m_NoteBook, wxT( "CadStar" ), NET_TYPE_CADSTAR, false );
285 label = new wxStaticText( page, wxID_ANY, _( "Export netlist in CadStar format" ) );
286 page->m_LeftBoxSizer->Add( label, 0, wxBOTTOM, 10 );
288
289 page = new EXPORT_NETLIST_PAGE( m_NoteBook, wxT( "PADS" ), NET_TYPE_PADS, false );
290 label = new wxStaticText( page, wxID_ANY, _( "Export netlist in PADS format" ) );
291 page->m_LeftBoxSizer->Add( label, 0, wxBOTTOM, 10 );
293
296
297 if( !m_job )
298 {
299 m_outputPath->Hide();
302
303 SetupStandardButtons( { { wxID_OK, _( "Export Netlist" ) },
304 { wxID_CANCEL, _( "Close" ) } } );
305 }
306 else
307 {
308 SetTitle( m_job->GetSettingsDialogTitle() );
309
310 m_MessagesBox->Hide();
311 m_outputPath->SetValue( m_job->GetConfiguredOutputPath() );
312
314
315 // custom netlist (external invokes, not supported)
316 for( int ii = 0; ii < DEFINED_NETLISTS_COUNT + CUSTOMPANEL_COUNTMAX; ++ii )
317 {
318 if( EXPORT_NETLIST_PAGE* candidate = m_PanelNetType[ii] )
319 {
320 if( candidate->GetPageNetFmtName() == JOB_EXPORT_SCH_NETLIST::GetFormatNameMap()[m_job->format] )
321 {
322 m_NoteBook->ChangeSelection( ii );
323 break;
324 }
325 }
326 }
327
328 m_buttonAddGenerator->Hide();
329 m_buttonDelGenerator->Hide();
330 }
331
332 // DIALOG_SHIM needs a unique hash_key because classname will be the same for both job and
333 // non-job versions.
334 m_hash_key = TO_UTF8( GetTitle() );
335
336 // Now all widgets have the size fixed, call FinishDialogSettings
338
340}
341
342
344{
345 EXPORT_NETLIST_PAGE* pg = new EXPORT_NETLIST_PAGE( m_NoteBook, wxT( "SPICE" ), NET_TYPE_SPICE, false );
346
347 wxStaticText* label = new wxStaticText( pg, wxID_ANY, _( "Export netlist in SPICE format" ) );
348 pg->m_LeftBoxSizer->Add( label, 0, wxBOTTOM, 10 );
349
350 pg->m_CurSheetAsRoot = new wxCheckBox( pg, ID_CUR_SHEET_AS_ROOT, _( "Use current sheet as root" ) );
351 pg->m_CurSheetAsRoot->SetToolTip( _( "Export netlist only for the current sheet" ) );
352 pg->m_LeftBoxSizer->Add( pg->m_CurSheetAsRoot, 0, wxGROW | wxBOTTOM | wxRIGHT, 5 );
353
354 pg->m_SaveAllVoltages = new wxCheckBox( pg, ID_SAVE_ALL_VOLTAGES, _( "Save all voltages" ) );
355 pg->m_SaveAllVoltages->SetToolTip( _( "Write a directive to save all voltages (.save all)" ) );
356 pg->m_LeftBoxSizer->Add( pg->m_SaveAllVoltages, 0, wxBOTTOM | wxRIGHT, 5 );
357
358 pg->m_SaveAllCurrents = new wxCheckBox( pg, ID_SAVE_ALL_CURRENTS, _( "Save all currents" ) );
359 pg->m_SaveAllCurrents->SetToolTip( _( "Write a directive to save all currents (.probe alli)" ) );
360 pg->m_LeftBoxSizer->Add( pg->m_SaveAllCurrents, 0, wxBOTTOM | wxRIGHT, 5 );
361
362 pg->m_SaveAllDissipations = new wxCheckBox( pg, ID_SAVE_ALL_DISSIPATIONS, _( "Save all power dissipations" ) );
363 pg->m_SaveAllDissipations->SetToolTip( _( "Write directives to save power dissipation of all items "
364 "(.probe p(<item>))" ) );
365 pg->m_LeftBoxSizer->Add( pg->m_SaveAllDissipations, 0, wxBOTTOM | wxRIGHT, 5 );
366
367 pg->m_SaveAllEvents = new wxCheckBox( pg, ID_SAVE_ALL_EVENTS, _( "Save all digital event data" ) );
368 pg->m_SaveAllEvents->SetToolTip( _( "If not set, write a directive to prevent the saving of digital event data "
369 "(esave none)" ) );
370 pg->m_LeftBoxSizer->Add( pg->m_SaveAllEvents, 0, wxBOTTOM | wxRIGHT, 5 );
371
372
373 pg->m_RunExternalSpiceCommand = new wxCheckBox( pg, ID_RUN_SIMULATOR, _( "Run external simulator command:" ) );
374 pg->m_RunExternalSpiceCommand->SetToolTip( _( "Enter the command line to run SPICE\n"
375 "Usually '<path to SPICE binary> \"%I\"'\n"
376 "%I will be replaced by the netlist filepath" ) );
377 pg->m_LowBoxSizer->Add( pg->m_RunExternalSpiceCommand, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
378
379 pg->m_CommandStringCtrl = new wxTextCtrl( pg, wxID_ANY, wxT( "spice \"%I\"" ) );
380
381 pg->m_CommandStringCtrl->SetInsertionPoint( 1 );
382 pg->m_LowBoxSizer->Add( pg->m_CommandStringCtrl, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
383
385}
386
387
389{
390 auto* pg = new EXPORT_NETLIST_PAGE( m_NoteBook, wxT( "SPICE Model" ), NET_TYPE_SPICE_MODEL, false );
391
392 wxStaticText* label = new wxStaticText( pg, wxID_ANY, _( "Export netlist as a SPICE .subckt model" ) );
393 pg->m_LeftBoxSizer->Add( label, 0, wxBOTTOM, 10 );
394
395 pg->m_CurSheetAsRoot = new wxCheckBox( pg, ID_CUR_SHEET_AS_ROOT, _( "Use current sheet as root" ) );
396 pg->m_CurSheetAsRoot->SetToolTip( _( "Export netlist only for the current sheet" ) );
397 pg->m_LeftBoxSizer->Add( pg->m_CurSheetAsRoot, 0, wxEXPAND | wxBOTTOM | wxRIGHT, 5 );
398
400}
401
402
404{
405 EXPORT_NETLIST_PAGE* currPage;
406 EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
407 wxCHECK( cfg, /* void */ );
408
409 for( size_t i = 0; i < CUSTOMPANEL_COUNTMAX && i < cfg->m_NetlistPanel.plugins.size(); i++ )
410 {
411 // pairs of (title, command) are stored
412 currPage = AddOneCustomPage( cfg->m_NetlistPanel.plugins[i].name,
413 cfg->m_NetlistPanel.plugins[i].command,
414 static_cast<NETLIST_TYPE_ID>( NET_TYPE_CUSTOM1 + i ) );
415
416 m_PanelNetType[PANELCUSTOMBASE + i] = currPage;
417 }
418}
419
420
422 const wxString& aCommandString,
423 NETLIST_TYPE_ID aNetTypeId )
424{
425 EXPORT_NETLIST_PAGE* pg = new EXPORT_NETLIST_PAGE( m_NoteBook, aTitle, aNetTypeId, true );
426
427 pg->m_LowBoxSizer->Add( new wxStaticText( pg, wxID_ANY, _( "Title:" ) ), 0,
428 wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 5 );
429
430 pg->m_LowBoxSizer->AddSpacer( 2 );
431
432 pg->m_TitleStringCtrl = new wxTextCtrl( pg, wxID_ANY, aTitle );
433
434 pg->m_TitleStringCtrl->SetInsertionPoint( 1 );
435 pg->m_LowBoxSizer->Add( pg->m_TitleStringCtrl, 0, wxEXPAND | wxLEFT | wxRIGHT, 5 );
436
437 pg->m_LowBoxSizer->AddSpacer( 10 );
438
439 pg->m_LowBoxSizer->Add( new wxStaticText( pg, wxID_ANY, _( "Netlist command:" ) ), 0,
440 wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 5 );
441
442 pg->m_LowBoxSizer->AddSpacer( 2 );
443
444 pg->m_CommandStringCtrl = new wxTextCtrl( pg, wxID_ANY, aCommandString );
445
446 pg->m_CommandStringCtrl->SetInsertionPoint( 1 );
447 pg->m_LowBoxSizer->Add( pg->m_CommandStringCtrl, 0, wxEXPAND | wxLEFT | wxRIGHT, 5 );
448
449 return pg;
450}
451
452
454{
456}
457
458
460{
461 wxFileName fn;
462 wxString fileWildcard;
463 wxString fileExt;
464 wxString title = _( "Save Netlist File" );
465
466 if( m_job )
467 {
468 for( const auto& [format, name] : JOB_EXPORT_SCH_NETLIST::GetFormatNameMap() )
469 {
470 if( name == m_PanelNetType[m_NoteBook->GetSelection()]->GetPageNetFmtName() )
471 {
472 m_job->format = format;
473 break;
474 }
475 }
476
477 m_job->SetConfiguredOutputPath( m_outputPath->GetValue() );
478 m_job->m_spiceSaveAllVoltages = m_PanelNetType[ PANELSPICE ]->m_SaveAllVoltages->IsChecked();
479 m_job->m_spiceSaveAllCurrents = m_PanelNetType[ PANELSPICE ]->m_SaveAllCurrents->IsChecked();
480 m_job->m_spiceSaveAllDissipations = m_PanelNetType[ PANELSPICE ]->m_SaveAllDissipations->IsChecked();
481 m_job->m_spiceSaveAllEvents = m_PanelNetType[ PANELSPICE ]->m_SaveAllEvents->IsChecked();
482
483 return true;
484 }
485
486 EXPORT_NETLIST_PAGE* currPage;
487 currPage = (EXPORT_NETLIST_PAGE*) m_NoteBook->GetCurrentPage();
488
489 bool runExternalSpiceCommand = false;
490 unsigned netlist_opt = 0;
491
492 // Calculate the netlist filename
493 fn = m_editFrame->Schematic().GetFileName();
494 FilenamePrms( currPage->m_IdNetType, &fileExt, &fileWildcard );
495
496 // Set some parameters
497 switch( currPage->m_IdNetType )
498 {
499 case NET_TYPE_SPICE:
500 // Set spice netlist options:
502
503 if( currPage->m_SaveAllVoltages->GetValue() )
505
506 if( currPage->m_SaveAllCurrents->GetValue() )
508
509 if( currPage->m_SaveAllDissipations->GetValue() )
511
512 if( currPage->m_SaveAllEvents->GetValue() )
514
515 if( currPage->m_CurSheetAsRoot->GetValue() )
517
518 runExternalSpiceCommand = currPage->m_RunExternalSpiceCommand->GetValue();
519 break;
520
522 if( currPage->m_CurSheetAsRoot->GetValue() )
524
525 break;
526
527 case NET_TYPE_CADSTAR:
528 break;
529
530 case NET_TYPE_PCBNEW:
531 break;
532
534 break;
535
536 case NET_TYPE_ALLEGRO:
537 break;
538
539 case NET_TYPE_PADS:
540 break;
541
542 default: // custom, NET_TYPE_CUSTOM1 and greater
543 title.Printf( _( "%s Export" ), currPage->m_TitleStringCtrl->GetValue() );
544 break;
545 }
546
547 wxString fullpath;
548
549 if( runExternalSpiceCommand )
550 {
551 fn.SetExt( FILEEXT::SpiceFileExtension );
552 fullpath = fn.GetFullPath();
553 }
554 else
555 {
556 fn.SetExt( fileExt );
557
558 if( fn.GetPath().IsEmpty() )
559 fn.SetPath( wxPathOnly( Prj().GetProjectFullName() ) );
560
561 wxString fullname = fn.GetFullName();
562 wxString path = fn.GetPath();
563
564 // full name does not and should not include the path, per wx docs.
565 wxFileDialog dlg( this, title, path, fullname, fileWildcard, wxFD_SAVE );
566
568
569 if( dlg.ShowModal() == wxID_CANCEL )
570 return false;
571
572 fullpath = dlg.GetPath(); // directory + filename
573 }
574
575 m_editFrame->ClearMsgPanel();
576 REPORTER& reporter = m_MessagesBox->Reporter();
577
578 if( currPage->m_CommandStringCtrl )
579 m_editFrame->SetNetListerCommand( currPage->m_CommandStringCtrl->GetValue() );
580 else
581 m_editFrame->SetNetListerCommand( wxEmptyString );
582
583 if( !m_editFrame->ReadyToNetlist( _( "Exporting netlist requires a fully annotated schematic." ) ) )
584 return false;
585
586 m_editFrame->WriteNetListFile( currPage->m_IdNetType, fullpath, netlist_opt, &reporter );
587
588 if( runExternalSpiceCommand )
589 {
590 // Build the command line
591 wxString commandLine = m_PanelNetType[ PANELSPICE ]->m_CommandStringCtrl->GetValue();
592 commandLine.Replace( wxS( "%I" ), fullpath, true );
593 commandLine.Trim( true ).Trim( false );
594
595 if( !commandLine.IsEmpty() )
596 {
597 std::vector<wxString> argsStrings = SplitCommandLine( commandLine );
598
599 if( !argsStrings.empty() )
600 {
601 std::vector<const wxChar*> argv;
602 argv.reserve( argsStrings.size() + 1 );
603
604 for( wxString& arg : argsStrings )
605 argv.emplace_back( arg.wc_str() );
606
607 argv.emplace_back( nullptr );
608
609 wxExecuteEnv env;
610 wxGetEnvMap( &env.env );
611
612 const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
613
614 for( const auto& [key, value] : envVars )
615 {
616 if( !value.GetValue().IsEmpty() )
617 env.env[key] = value.GetValue();
618 }
619
620 wxFileName netlistFile( fullpath );
621
622 if( !netlistFile.IsAbsolute() )
623 netlistFile.MakeAbsolute( Prj().GetProjectPath() );
624 else
625 netlistFile.MakeAbsolute();
626
627 wxString cwd = netlistFile.GetPath();
628
629 if( cwd.IsEmpty() )
630 cwd = Prj().GetProjectPath();
631
632 env.cwd = cwd;
633
634 wxProcess* process = new wxProcess( GetEventHandler(), wxID_ANY );
635 process->Redirect();
636
637 long pid = wxExecute( argv.data(), wxEXEC_ASYNC, process, &env );
638
639 reporter.ReportHead( commandLine, RPT_SEVERITY_ACTION );
640
641 if( pid <= 0 )
642 {
643 reporter.Report( _( "external simulator not found" ), RPT_SEVERITY_ERROR );
644 reporter.Report( _( "Note: command line is usually: "
645 "<tt>&lt;path to SPICE binary&gt; \"%I\"</tt>" ),
647 delete process;
648 }
649 else
650 {
651 process->Activate();
652
653 std::this_thread::sleep_for( std::chrono::seconds( 1 ) ); // give the process time to start and output any data or errors
654
655 if( process->IsInputAvailable() )
656 {
657 wxInputStream* in = process->GetInputStream();
658 wxTextInputStream textstream( *in );
659
660 while( in->CanRead() )
661 {
662 wxString line = textstream.ReadLine();
663
664 if( !line.IsEmpty() )
665 reporter.Report( line, RPT_SEVERITY_INFO );
666 }
667 }
668
669 if( process->IsErrorAvailable() )
670 {
671 wxInputStream* err = process->GetErrorStream();
672 wxTextInputStream textstream( *err );
673
674 while( err->CanRead() )
675 {
676 wxString line = textstream.ReadLine();
677
678 if( !line.IsEmpty() )
679 {
680 if( line.EndsWith( wxS( "failed with error 2!" ) ) ) // ENOENT
681 {
682 reporter.Report( _( "external simulator not found" ), RPT_SEVERITY_ERROR );
683 reporter.Report( _( "Note: command line is usually: "
684 "<tt>&lt;path to SPICE binary&gt; \"%I\"</tt>" ),
686 }
687 else if( line.EndsWith( wxS( "failed with error 8!" ) ) ) // ENOEXEC
688 {
689 reporter.Report( _( "external simulator has the wrong format or "
690 "architecture" ), RPT_SEVERITY_ERROR );
691 }
692 else if( line.EndsWith( "failed with error 13!" ) ) // EACCES
693 {
694 reporter.Report( _( "permission denied" ), RPT_SEVERITY_ERROR );
695 }
696 else
697 {
698 reporter.Report( line, RPT_SEVERITY_ERROR );
699 }
700 }
701 }
702 }
703
704 process->CloseOutput();
705 process->Detach();
706
707 // Do not delete process, it will delete itself when it terminates
708 }
709 }
710 }
711 }
712
714
715 return !runExternalSpiceCommand;
716}
717
718
719bool DIALOG_EXPORT_NETLIST::FilenamePrms( NETLIST_TYPE_ID aType, wxString * aExt, wxString * aWildCard )
720{
721 wxString fileExt;
722 wxString fileWildcard;
723 bool ret = true;
724
725 switch( aType )
726 {
727 case NET_TYPE_SPICE:
729 fileWildcard = FILEEXT::SpiceNetlistFileWildcard();
730 break;
731
732 case NET_TYPE_CADSTAR:
735 break;
736
740 break;
741
742 case NET_TYPE_PCBNEW:
744 fileWildcard = FILEEXT::NetlistFileWildcard();
745 break;
746
747 case NET_TYPE_ALLEGRO:
750 break;
751
752 case NET_TYPE_PADS:
754 fileWildcard = FILEEXT::PADSNetlistFileWildcard();
755 break;
756
757
758 default: // custom, NET_TYPE_CUSTOM1 and greater
759 fileWildcard = FILEEXT::AllFilesWildcard();
760 ret = false;
761 }
762
763 if( aExt )
764 *aExt = fileExt;
765
766 if( aWildCard )
767 *aWildCard = fileWildcard;
768
769 return ret;
770}
771
772
774{
775 EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
776 wxCHECK( cfg, /* void */ );
777
778 cfg->m_NetlistPanel.plugins.clear();
779
780 // Update existing custom pages
781 for( int ii = PANELCUSTOMBASE; ii < PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX; ++ii )
782 {
783 if( EXPORT_NETLIST_PAGE* currPage = m_PanelNetType[ii] )
784 {
785 wxString title = currPage->m_TitleStringCtrl->GetValue();
786 wxString command = currPage->m_CommandStringCtrl->GetValue();
787
788 if( title.IsEmpty() || command.IsEmpty() )
789 continue;
790
791 cfg->m_NetlistPanel.plugins.emplace_back( title, wxEmptyString );
792 cfg->m_NetlistPanel.plugins.back().command = command;
793 }
794 }
795}
796
797
798void DIALOG_EXPORT_NETLIST::OnDelGenerator( wxCommandEvent& event )
799{
800 EXPORT_NETLIST_PAGE* currPage = (EXPORT_NETLIST_PAGE*) m_NoteBook->GetCurrentPage();
801
802 if( !currPage->IsCustom() )
803 return;
804
805 currPage->m_CommandStringCtrl->SetValue( wxEmptyString );
806 currPage->m_TitleStringCtrl->SetValue( wxEmptyString );
807
809
810 if( IsQuasiModal() )
812 else
813 EndDialog( NET_PLUGIN_CHANGE );
814}
815
816
817void DIALOG_EXPORT_NETLIST::OnAddGenerator( wxCommandEvent& event )
818{
820
821 if( dlg.ShowModal() != wxID_OK )
822 return;
823
824 wxString title = dlg.GetGeneratorTitle();
825 wxString cmd = dlg.GetGeneratorTCommandLine();
826
827 // Verify it does not exists
828 for( int ii = PANELCUSTOMBASE; ii < PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX; ++ii )
829 {
830 if( m_PanelNetType[ii] && m_PanelNetType[ii]->GetPageNetFmtName() == title )
831 {
832 wxMessageBox( _( "This plugin already exists." ) );
833 return;
834 }
835 }
836
837 // Find the first empty slot
838 int netTypeId = PANELCUSTOMBASE;
839
840 while( m_PanelNetType[netTypeId] )
841 {
842 netTypeId++;
843
844 if( netTypeId == PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX )
845 {
846 wxMessageBox( _( "Maximum number of plugins already added to dialog." ) );
847 return;
848 }
849 }
850
851 m_PanelNetType[netTypeId] = AddOneCustomPage( title, cmd, (NETLIST_TYPE_ID)netTypeId );
852
854
855 if( IsQuasiModal() )
857 else
858 EndDialog( NET_PLUGIN_CHANGE );
859}
860
861
871
872
874{
875 if( !wxDialog::TransferDataFromWindow() )
876 return false;
877
878 if( m_textCtrlName->GetValue() == wxEmptyString )
879 {
880 wxMessageBox( _( "You must provide a netlist generator title" ) );
881 return false;
882 }
883
884 return true;
885}
886
887
889{
890 wxString FullFileName, Path;
891
892#ifndef __WXMAC__
893 Path = Pgm().GetExecutablePath();
894#else
895 Path = PATHS::GetOSXKicadDataDir() + wxT( "/plugins" );
896#endif
897
898 FullFileName = wxFileSelector( _( "Generator File" ), Path, FullFileName, wxEmptyString,
899 wxFileSelectorDefaultWildcardStr, wxFD_OPEN, this );
900
901 if( FullFileName.IsEmpty() )
902 return;
903
904 // Creates a default command line, suitable for external tool xslproc or python, based on
905 // the plugin extension ("xsl" or "exe" or "py")
906 wxString cmdLine;
907 wxFileName fn( FullFileName );
908 wxString ext = fn.GetExt();
909
910 if( ext == wxT( "xsl" ) )
911 cmdLine.Printf( wxT( "xsltproc -o \"%%O\" \"%s\" \"%%I\"" ), FullFileName );
912 else if( ext == wxT( "exe" ) || ext.IsEmpty() )
913 cmdLine.Printf( wxT( "\"%s\" > \"%%O\" < \"%%I\"" ), FullFileName );
914 else if( ext == wxT( "py" ) || ext.IsEmpty() )
915 cmdLine.Printf( wxT( "python \"%s\" \"%%I\" \"%%O\"" ), FullFileName );
916 else
917 cmdLine.Printf( wxT( "\"%s\"" ), FullFileName );
918
919 m_textCtrlCommand->SetValue( cmdLine );
920
921 // We need a title for this panel
922 // Propose a default value if empty ( i.e. the short filename of the script)
923 if( m_textCtrlName->GetValue().IsEmpty() )
924 m_textCtrlName->SetValue( fn.GetName() );
925}
926
927
929{
930 EXPORT_NETLIST_PAGE* currPage = (EXPORT_NETLIST_PAGE*) m_NoteBook->GetCurrentPage();
931
932 if( currPage == nullptr )
933 return;
934
935 m_buttonDelGenerator->Enable( currPage->IsCustom() );
936}
937
938
940{
941 DIALOG_EXPORT_NETLIST dlg( aCaller );
942
943 int ret = dlg.ShowModal();
944 aCaller->SaveProjectLocalSettings();
945
946 return ret;
947}
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:781
virtual const wxString & GetExecutablePath() const
Definition pgm_base.cpp:861
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition project.cpp:168
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)
NETLIST_TYPE_ID
netlist types
@ 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...
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:717
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
Definition of file extensions used in Kicad.