1 //**************************************************************************************************
2 // FileTasks.cpp *
3 // --------------- *
4 // Started : 2005-05-28 *
5 // Last Update : 2015-04-09 *
6 // Copyright : (C) 2005 by MSWaters *
7 //**************************************************************************************************
8
9 //**************************************************************************************************
10 // *
11 // This program is free software; you can redistribute it and/or modify it under the *
12 // terms of the GNU General Public License as published by the Free Software Foundation; *
13 // either version 3 of the License, or (at your option) any later version. *
14 // *
15 //**************************************************************************************************
16
17 #include "FileTasks.hpp"
18 #include "FrmMain.hpp"
19
20 //**************************************************************************************************
21 // Constructor.
22 //
23 // Argument List :
24 // poFrmMain - A pointer to the parent frame
25
FileTasks(FrmMain * poFrmMain)26 FileTasks::FileTasks( FrmMain * poFrmMain )
27 {
28 // Set the pointer to the parent frame
29 m_poFrmMain = poFrmMain;
30
31 // Get the global configuration object
32 m_poCfg = (wxConfig *) wxConfig::Get( );
33 }
34
35 //**************************************************************************************************
36 // Destructor.
37
~FileTasks()38 FileTasks::~FileTasks( )
39 {
40 }
41
42 //**************************************************************************************************
43 // Execute the schematic import process.
44 //
45 // Return Values :
46 // true - Success
47 // false - Failure
48
bExecImport(void)49 bool FileTasks::bExecImport( void )
50 {
51 bool bRtn;
52 TextCtrl * poTxtCtl;
53
54 // Display the console page
55 m_poFrmMain->m_oNbkTxtCtls.bSetPage( NbkTxtCtls::ePAGE_CONSOLE );
56
57 // Convert the schematic file/s to a netlist file
58 bRtn = m_oPrcGNetList.bExec( );
59
60 // Print the results
61 poTxtCtl = m_poFrmMain->m_oNbkTxtCtls.poGetPage( );
62 m_oPrcGNetList.Print( *poTxtCtl );
63
64 // Check for errors in the gnetlist output
65 if( poTxtCtl->GetValue( ).Contains( wxT("ERROR") ) ) bRtn = false;
66 if( poTxtCtl->GetValue( ).Contains( wxT("Backtrace") ) ) bRtn = false;
67
68 // Delete the process log file
69 m_oPrcGNetList.bDelLogFile( );
70
71 return( bRtn );
72 }
73
74 //**************************************************************************************************
75 // Initialize the Guile procedure name to be used by gnetlist when importing schematic files.
76
InitGuileProc(void)77 void FileTasks::InitGuileProc( void )
78 {
79 wxString os1;
80
81 // Set the Guile procedure name
82 m_poCfg->SetPath( wxT("/gnetlist") );
83 os1 = m_poCfg->Read( wxT("GuileProc"), wxT("spice-sdb") );
84 bSetGuileProc( os1 );
85 }
86
87 //**************************************************************************************************
88 // Initialize the schematic file name/s.
89
InitSchemFiles(void)90 void FileTasks::InitSchemFiles( void )
91 {
92 wxString os1;
93
94 // Get the schematic file name/s
95 m_poCfg->SetPath( wxT("/Files") );
96 os1 = m_poCfg->Read( wxT("Schematics"), wxT("") );
97 if( os1.IsEmpty( ) ) return;
98
99 // Set the schematic file name/s
100 if( ! bSetSchemFiles( os1 ) ) return;
101
102 // Return if a netlist file has also been specified
103 os1 = m_poCfg->Read( wxT("NetList"), wxT("") );
104 if( ! os1.IsEmpty( ) ) return;
105
106 // Import the schematic file/s
107 bImport( );
108 }
109
110 //**************************************************************************************************
111 // Initialize the netlist file name.
112
InitNetLstFile(void)113 void FileTasks::InitNetLstFile( void )
114 {
115 wxString os1;
116
117 // Return if a netlist file has already been loaded
118 if( ! m_poFrmMain->m_oNetLst.bIsEmpty( ) ) return;
119
120 // Get the netlist file name
121 m_poCfg->SetPath( wxT("/Files") );
122 os1 = m_poCfg->Read( wxT("NetList"), wxT("") );
123 if( os1.IsEmpty( ) ) return;
124
125 // Set the netlist file name
126 if( ! bSetNetLstFile( os1 ) ) return;
127
128 // Open the netlist file
129 bOpen( );
130
131 // Does the netlist file contain simulator specific information?
132 m_poCfg->SetPath( wxT("/Simulator") );
133 if( m_poFrmMain->m_oSimnNgSp.m_oCmdPR.bIsValid( ) )
134 {
135 m_poCfg->Write( wxT("Engine"), CLP_NGSPICE );
136 m_poFrmMain->m_oSimnGCap = m_poFrmMain->m_oSimnNgSp;
137 }
138 else if( m_poFrmMain->m_oSimnGCap.m_oCmdPR.bIsValid( ) )
139 {
140 m_poCfg->Write( wxT("Engine"), CLP_GNUCAP );
141 m_poFrmMain->m_oSimnNgSp = m_poFrmMain->m_oSimnGCap;
142 }
143 }
144
145 //**************************************************************************************************
146 // Display a error message dialog when schematic file/s can't be imported.
147
DlgErrSchems(void)148 void FileTasks::DlgErrSchems( void )
149 {
150 wxString os1, os2, os3;
151 size_t sz1;
152
153 for( sz1=0; sz1<m_oPrcGNetList.roaGetSchemFiles( ).GetCount( ); sz1++ )
154 os2 << wxT(" ") << m_oPrcGNetList.rofnGetSchemFile( sz1 ).GetFullPath( )
155 << wxT("\n");
156
157 if( sz1 > 1 ) os3 = wxT("s were");
158 else os3 = wxT(" was");
159
160 os1 << wxT("The schematic file") << os3 << wxT("n't converted to a netlist correctly :\n")
161 << wxT("\n")
162 << os2
163 << wxT("\n")
164 << wxT("This is usually because gnetlist encountered problem/s\n")
165 << wxT("while attempting to convert the schematic file/s to a netlist. \n")
166 << wxT("Try examining the Console output to determine where the\n")
167 << wxT("problem/s occurred.\n");
168
169 m_poFrmMain->DlgErrMsg( wxT("Import Schematic/s Error"), os1 );
170 }
171
172 //**************************************************************************************************
173 // Display a error message dialog when a netlist file can't be loaded.
174
DlgErrNetLst(void)175 void FileTasks::DlgErrNetLst( void )
176 {
177 wxString os1;
178
179 os1 << wxT("The netlist file wasn't loaded correctly :\n")
180 << wxT("\n ") << m_oPrcGNetList.rofnGetNetLstFile( ).GetFullPath( )
181 << wxT("\n\n")
182 << wxT("This is often because the file is in-complete, empty or \n")
183 << wxT("doesn't exist.\n");
184
185 m_poFrmMain->DlgErrMsg( wxT("Netlist File Error"), os1 );
186 }
187
188 //**************************************************************************************************
189 // Do initialization tasks.
190
Initialize(void)191 void FileTasks::Initialize( void )
192 {
193 InitGuileProc ( );
194 InitSchemFiles( );
195 InitNetLstFile( );
196 }
197
198 //**************************************************************************************************
199 // Check that the gnetlist binary can be found, if not display an error message.
200 //
201 // Return Values :
202 // true - Success
203 // false - Failure
204
bIsOk_gnetlist(void)205 bool FileTasks::bIsOk_gnetlist( void )
206 {
207 wxString os1;
208
209 // Check that gnetlist exists and is accessible
210 if( ! m_oPrcGNetList.bBinExists( ) )
211 {
212 if( m_poFrmMain != NULL )
213 {
214 os1 << wxT("Can't find the binary \"") << m_oPrcGNetList.roGetBinary( ).GetFullName( )
215 << wxT("\" which is required\n")
216 << wxT("to import schematic file/s. The path is unknown \n")
217 << wxT("or gnetlist hasn't been installed.\n");
218
219 m_poFrmMain->DlgErrMsg( wxT("gnetlist Error"), os1 );
220 }
221 return( false );
222 }
223
224 return( true );
225 }
226
227 //**************************************************************************************************
228 // Set the application main frame title.
229 //
230 // Return Values :
231 // true - Success
232 // false - Failure
233
bSetTitle(void)234 bool FileTasks::bSetTitle( void )
235 {
236 wxFileName ofn1;
237 wxString os1;
238
239 if( m_poFrmMain == NULL ) return( false );
240
241 // Create the title line
242 os1 << wxT(" ") << APP_NAME;
243 if( ! rosGetNetLstFile( ).IsEmpty( ) )
244 {
245 ofn1 = rosGetNetLstFile( );
246 if( ! ofn1.IsAbsolute( ) ) ofn1.MakeAbsolute( );
247 if( ofn1.GetFullPath( ).StartsWith( ofn1.GetHomeDir( ) ) )
248 ofn1.MakeRelativeTo( ofn1.GetHomeDir( ) );
249
250 os1 << wxT(" - ");
251 if( ! ofn1.IsAbsolute( ) ) os1 << wxT("~/");
252 os1 << ofn1.GetFullPath( );
253 }
254
255 // Set the main frames title line
256 m_poFrmMain->wxFrame::SetTitle( os1 );
257
258 return( true );
259 }
260
261 //**************************************************************************************************
262 // Set a Guile procedure name to be used for importing schematic files using gNetList.
263 //
264 // Argument List :
265 // rosPName - The Guile procedure name
266 // (Refer to gNetList documentation for list of procedure names)
267
bSetGuileProc(const wxString & rosPName)268 bool FileTasks::bSetGuileProc( const wxString & rosPName )
269 {
270 if( ! m_oPrcGNetList.bSetGuileProc( rosPName ) ) return( false );
271
272 // Record the Guile procedure name currently selected
273 m_poCfg->SetPath( wxT("/gNetList") );
274 m_poCfg->Write( wxT("GuileProc"), rosGetGuileProc( ) );
275
276 // Write any changes to the configuration file
277 m_poCfg->Flush( );
278
279 return( true );
280 }
281
282 //**************************************************************************************************
283 // Set the schematic file name/s.
284 //
285 // Argument List :
286 // rosFNames - A string containing the full path and file name/s
287 //
288 // Return Values :
289 // true - Success
290 // false - Failure
291
bSetSchemFiles(const wxString & rosFNames)292 bool FileTasks::bSetSchemFiles( const wxString & rosFNames )
293 {
294 wxString os1;
295 size_t sz1;
296
297 if( rosFNames.IsEmpty( ) )
298 {
299 // Clear the schematic file name/s in the configuration object
300 m_poCfg->SetPath( wxT("/Files") );
301 m_poCfg->Write( wxT("Schematics"), os1 );
302 m_poCfg->Flush( );
303 }
304
305 // Attempt to set the schematic file name/s in the gnetlist process object
306 if( ! m_oPrcGNetList.bSetSchemFiles( rosFNames ) ) return( false );
307
308 // Set the schematic file name/s
309 if( m_poFrmMain != NULL ) m_poFrmMain->m_oNetLst.bSetSchemFiles( rosFNames );
310
311 // Record the schematic file name/s in the configuration object
312 const wxArrayString & rosa1=rosaGetSchemFiles( );
313 for( sz1=0; sz1<rosa1.GetCount( ); sz1++ )
314 {
315 if( sz1 > 0 ) os1 += wxT(' ');
316 os1 += rosa1[ sz1 ];
317 }
318 m_poCfg->SetPath( wxT("/Files") );
319 m_poCfg->Write( wxT("Schematics"), os1 );
320 m_poCfg->Flush( );
321
322 return( true );
323 }
324
325 //**************************************************************************************************
326 // Set the netlist file name.
327 //
328 // Argument List :
329 // psFileName - A string containing the full path and file name
330 //
331 // Return Values :
332 // true - Success
333 // false - Failure
334
bSetNetLstFile(const wxString & rosFName)335 bool FileTasks::bSetNetLstFile( const wxString & rosFName )
336 {
337 wxString os1;
338
339 if( rosFName.IsEmpty( ) )
340 {
341 // Clear the netlist file name in the configuration object
342 m_poCfg->SetPath( wxT("/Files") );
343 m_poCfg->Write( wxT("NetList"), os1 );
344 m_poCfg->Flush( );
345 }
346
347 // Attempt to set the netlist file name in the gNetList process object
348 if( ! m_oPrcGNetList.bSetNetLstFile( rosFName ) ) return( false );
349
350 // Configure stuff in the main frame
351 if( m_poFrmMain != NULL )
352 {
353 m_poFrmMain->m_oNetLst.bSetLoadFile( rosFName ); // Set load file path
354 m_poFrmMain->m_oNetLst.bSetSaveFile( rosFName ); // Set save file path
355 }
356
357 // Record the netlist file name in the configuration object
358 os1 = rosGetNetLstFile( );
359 m_poCfg->SetPath( wxT("/Files") );
360 m_poCfg->Write( wxT("NetList"), os1 );
361 m_poCfg->Flush( );
362
363 return( true );
364 }
365
366 //**************************************************************************************************
367 // Get the currently selected Guile procedure.
368 //
369 // Return Values :
370 // The currently selected Guile procedure
371
rosGetGuileProc(void)372 const wxString & FileTasks::rosGetGuileProc( void )
373 {
374 return( m_oPrcGNetList.rosGetGuileProc( ) );
375 }
376
377 //**************************************************************************************************
378 // Get an array containing the schematic file name/s.
379 //
380 // Return Values :
381 // An array of schematic file names
382
rosaGetSchemFiles(void)383 const wxArrayString & FileTasks::rosaGetSchemFiles( void )
384 {
385 static wxArrayString osa1;
386 wxString os1;
387 size_t szt1;
388
389 osa1.Clear( );
390
391 for( szt1=0; szt1<m_oPrcGNetList.roaGetSchemFiles( ).GetCount( ); szt1++ )
392 {
393 os1 = m_oPrcGNetList.rofnGetSchemFile( szt1 ).GetFullPath( );
394 if( ! os1.IsEmpty( ) ) osa1.Add( os1 );
395 }
396
397 return( osa1 );
398 }
399
400 //**************************************************************************************************
401 // Get the netlist file name.
402 //
403 // Return Values :
404 // The netlist file name
405
rosGetNetLstFile(void)406 const wxString & FileTasks::rosGetNetLstFile( void )
407 {
408 static wxString osNetLstFile;
409
410 osNetLstFile = m_oPrcGNetList.rofnGetNetLstFile( ).GetFullPath( );
411
412 return( osNetLstFile );
413 }
414
415 //**************************************************************************************************
416 // Display an open file dialog and set the netlist file name.
417 //
418 // Return Values :
419 // true - Success
420 // false - Failure
421
bDlgOpen(void)422 bool FileTasks::bDlgOpen( void )
423 {
424 wxFileDialog * poDlgOpen;
425 wxString os1, os2;
426 long li1;
427
428 // Can't display dialogue unless the application main frame has been created
429 if( m_poFrmMain == NULL ) return( false );
430
431 // Create the different file filters
432 os1 << wxT("All files (*)|*|")
433 << wxT("Circuit files (*.ckt)|*.ckt|")
434 << wxT("Circuit files (*.cir)|*.cir|")
435 << wxT("Netlist files (*.net)|*.net");
436
437 // Get the file path from the global configuration object
438 m_poCfg->SetPath( wxT("/Directories") );
439 os2 = m_poCfg->Read( wxT("LastAccess"), wxGetHomeDir( ) );
440
441 // Set the style bit pattern
442 #if wxCHECK_VERSION( 2,8,0 )
443 li1 = wxFD_OPEN | wxFD_CHANGE_DIR | wxFD_FILE_MUST_EXIST;
444 #else
445 li1 = wxOPEN | wxCHANGE_DIR | wxFILE_MUST_EXIST;
446 #endif
447
448 // Create and configure the file open dialog
449 poDlgOpen = new wxFileDialog( m_poFrmMain, wxT(""), wxT(""), wxT(""),
450 wxT(""), li1 );
451 poDlgOpen->SetMessage( wxT("Open a Circuit Description File") );
452 poDlgOpen->SetWildcard( os1 );
453 poDlgOpen->SetFilterIndex( 1 );
454 poDlgOpen->SetDirectory( os2 );
455
456 // Display file open dialog
457 if( poDlgOpen->ShowModal( ) != wxID_OK ) return( false );
458
459 // Delete temporary files
460 bDelTmpFiles( );
461
462 // Set the netlist file name
463 os1 = poDlgOpen->GetPath( );
464 if( ! bSetNetLstFile( os1 ) ) return( false );
465
466 // Set the path last accessed in the global configuration object
467 m_poCfg->SetPath( wxT("/Directories") );
468 m_poCfg->Write( wxT("LastAccess"), poDlgOpen->GetDirectory( ) );
469 m_poCfg->Flush( );
470
471 return( true );
472 }
473
474 //**************************************************************************************************
475 // Display an import file/s dialog and set the schematic file name/s.
476 //
477 // Return Values :
478 // true - Success
479 // false - Failure
480
bDlgImport(void)481 bool FileTasks::bDlgImport( void )
482 {
483 wxFileDialog * poDlgImport;
484 wxArrayString osa1;
485 wxString os1, os2;
486 long li1;
487 size_t sz1;
488
489 // Can't display dialogue unless the application main frame has been created
490 if( m_poFrmMain == NULL ) return( false );
491
492 // Create the different file filters
493 os1 << wxT("gSchem files (*.sch)|*.sch|")
494 << wxT("Protel II files (*.\?\?\?)|*.\?\?\?");
495
496 // Get the file path from the global configuration object
497 m_poCfg->SetPath( wxT("/Directories") );
498 os2 = m_poCfg->Read( wxT("LastAccess"), wxGetHomeDir( ) );
499
500 // Set the style bit pattern
501 #if wxCHECK_VERSION( 2,8,0 )
502 li1 = wxFD_OPEN | wxFD_CHANGE_DIR | wxFD_MULTIPLE | wxFD_FILE_MUST_EXIST;
503 #else
504 li1 = wxOPEN | wxCHANGE_DIR | wxMULTIPLE | wxFILE_MUST_EXIST;
505 #endif
506
507 // Create and configure the file import dialog
508 poDlgImport = new wxFileDialog( m_poFrmMain, wxT(""), wxT(""), wxT(""), wxT(""), li1 );
509 poDlgImport->SetMessage( wxT("Import a Schematic File/s") );
510 poDlgImport->SetWildcard( os1 );
511 poDlgImport->SetFilterIndex( 0 );
512 poDlgImport->SetDirectory( os2 );
513
514 // Display file import dialog
515 if( poDlgImport->ShowModal( ) != wxID_OK ) return( false );
516
517 // Delete temporary files
518 bDelTmpFiles( );
519
520 // Set the guile procedure name
521 bSetGuileProc( wxT("spice-sdb") );
522
523 // Set the schematic file name/s
524 poDlgImport->GetPaths( osa1 );
525 os1 = osa1.Item( 0 );
526 for( sz1=1; sz1<osa1.GetCount( ); sz1++ )
527 os1 << osa1.Item( sz1 ) << wxT(' ');
528 if( ! bSetSchemFiles( os1 ) ) return( false );
529
530 // Set the netlist file name (derive it from the schematic file name)
531 bSetNetLstFile( );
532
533 // Set the path last accessed in the global configuration object
534 m_poCfg->SetPath( wxT("/Directories") );
535 m_poCfg->Write( wxT("LastAccess"), poDlgImport->GetDirectory( ) );
536 m_poCfg->Flush( );
537
538 return( true );
539 }
540
541 //**************************************************************************************************
542 // Delete temporary files which may have been generated by this application.
543 //
544 // Ie. given the circuit description file "<netlist>.ckt" delete files of the following form :
545 // <netlist>.ngspice.dc, <netlist>.ngspice.ac, ... etc.
546 // <netlist>.gnucap.op, <netlist>.gnucap.dc, .... etc.
547 // gnetlist.log
548
bDelTmpFiles(void)549 bool FileTasks::bDelTmpFiles( void )
550 {
551 wxArrayString osa1;
552 wxFileName ofn1;
553 wxString os1, os2;
554 long liTmpFileMgt;
555 int i1;
556
557 // Determine the current temporary file management strategy
558 m_poCfg->SetPath( wxT("/Main") );
559 m_poCfg->Read( wxT("TmpFileMgt"), &liTmpFileMgt, (long) eTFM_DELETE );
560
561 // Return if nothing needs to be done
562 if( liTmpFileMgt == (long) eTFM_KEEP ) return( true );
563
564 // Get the path to the schematic or circuit description file
565 ofn1 = m_oPrcGNetList.rofnGetNetLstFile( );
566 ofn1.Normalize( );
567 if( !ofn1.IsOk( ) || !ofn1.FileExists( ) ) return( false );
568
569 // Look for the gnetlist log file
570 os1 = ofn1.GetPath( ) + wxT("/gnetlist.log");
571 if( wxFileExists( os1 ) ) osa1.Add( os1 );
572
573 // Look for files containing simulation results
574 os1 = ofn1.GetName( );
575 i1 = os1.Find( wxT(".gspiceui") );
576 if( i1 > 0 ) os1 = os1.Truncate( (size_t) i1 );
577 ofn1.SetFullName( os1 );
578
579 // Look for any GNU-Cap results file
580 os1 = ofn1.GetFullPath( ) + wxT(".gnucap.??");
581 for( os2=wxFindFirstFile( os1 ); !os2.IsEmpty( ); os2=wxFindNextFile( ) )
582 osa1.Add( os2 );
583
584 // Look for any NG-Spice results files
585 os1 = ofn1.GetFullPath( ) + wxT(".ngspice.??");
586 for( os2=wxFindFirstFile( os1 ); !os2.IsEmpty( ); os2=wxFindNextFile( ) )
587 osa1.Add( os2 );
588
589 // If necessary prompt the user for permission to delete temporary files
590 if( osa1.GetCount( ) > 0 )
591 {
592 if( m_poFrmMain!=NULL && m_poFrmMain->IsShown( ) )
593 {
594 // Prompt the user
595 if( liTmpFileMgt == (long) eTFM_PROMPT )
596 {
597 os1 = wxT("Delete Temporary Files");
598 os2 = wxT("\nDelete the following temporary files :\n\n");
599 for( i1=0; i1<(int)osa1.GetCount( ); i1++ )
600 os2 << wxT(" ") << osa1.Item( i1 ) << wxT(" \n");
601 i1 = wxMessageBox( os2, os1, wxYES_NO|wxICON_QUESTION, m_poFrmMain );
602 }
603 else i1 = wxYES;
604
605 // Delete the temporary files
606 if( i1 == wxYES )
607 for( i1=0; i1<(int)osa1.GetCount( ); i1++ )
608 wxRemoveFile( osa1.Item( i1 ) );
609 }
610 }
611
612 return( true );
613 }
614
615 //**************************************************************************************************
616 // Open and load a circuit description (netlist) file into the m_poFrmMain attribute's simulation
617 // objects.
618 //
619 // Return Values :
620 // true - Success
621 // false - Failure
622
bOpen(void)623 bool FileTasks::bOpen( void )
624 {
625 bool bRtn=true;
626 wxString os1;
627
628 // Attempt to load the circuit description file
629 NetList::bLoadFile( );
630
631 // Load circuit description (& simulation) information into the attributes of the class hierarchy
632 if( m_poFrmMain->m_oSimnNgSp.bLoad( ) ) m_poFrmMain->m_oSimnGCap = m_poFrmMain->m_oSimnNgSp;
633 else if( m_poFrmMain->m_oSimnGCap.bLoad( ) ) m_poFrmMain->m_oSimnNgSp = m_poFrmMain->m_oSimnGCap;
634
635 // Check for problems
636 if( ! m_poFrmMain->m_oNetLst.bIsValid( ) )
637 {
638 DlgErrNetLst( );
639 m_poFrmMain->m_oNbkTxtCtls.bSetPage( NbkTxtCtls::ePAGE_NETLIST );
640 bRtn = false;
641 }
642 else
643 m_poFrmMain->SetStatusText( wxT(" Netlist file opened successfully"), FrmMain::ePANE_MESAGE );
644
645 // Set the main frame title and the schematic file name/s if supplied
646 bSetTitle( );
647 os1 = m_poFrmMain->m_oNetLst.rosGetSchemFiles( );
648 if( ! os1.IsEmpty( ) ) bSetSchemFiles( os1 );
649
650 return( bRtn );
651 }
652
653 //**************************************************************************************************
654 // Import a schematic file by converting it to a netlist using gNetList and then loading it into the
655 // FrmMain simulation object.
656 //
657 // Return Values :
658 // true - Success
659 // false - Failure
660
bImport(void)661 bool FileTasks::bImport( void )
662 {
663 bool bRtn=true;
664
665 // Check that gnetList binary exists and is accessible
666 if( ! bIsOk_gnetlist( ) ) return( false );
667
668 // Convert the schematic file/s to a netlist file and load it
669 if( bExecImport( ) )
670 {
671 bSetNetLstFile( m_oPrcGNetList.rofnGetNetLstFile( ).GetFullPath( ) );
672
673 // Attempt to load the circuit description file
674 NetList::bLoadFile( );
675
676 // Load circuit description (& simulation) info. into the attributes of the class hierarchy
677 m_poFrmMain->m_oSimnNgSp.bLoad( );
678 m_poFrmMain->m_oSimnGCap.bLoad( );
679
680 if( m_poFrmMain->m_oNetLst.bIsValid( ) )
681 m_poFrmMain->SetStatusText( wxT(" Schematic file/s imported successfully"),
682 FrmMain::ePANE_MESAGE );
683 else
684 {
685 DlgErrNetLst( );
686 m_poFrmMain->m_oNbkTxtCtls.bSetPage( NbkTxtCtls::ePAGE_NETLIST );
687 bRtn = false;
688 }
689 }
690 else
691 {
692 DlgErrSchems( );
693 m_poFrmMain->m_oNbkTxtCtls.bSetPage( NbkTxtCtls::ePAGE_CONSOLE );
694 m_poFrmMain->m_oNbkTxtCtls.bSetPosn( -1 );
695 bRtn = false;
696 }
697
698 // Set the main frame title
699 bSetTitle( );
700
701 return( bRtn );
702 }
703
704 //**************************************************************************************************
705 // Reload a simulation object whether it be from a schematic or netlist file.
706 //
707 // Return Values :
708 // true - Success
709 // false - Failure
710
bReload(void)711 bool FileTasks::bReload( void )
712 {
713 bool bRtn;
714
715 // Re-initialize the text control notebook
716 m_poFrmMain->m_oNbkTxtCtls.bInitialize( );
717
718 // Attempt to perform the reload operation
719 if( ! m_oPrcGNetList.roaGetSchemFiles( ).IsEmpty( ) )
720 { // Reload schematic file/s
721 bRtn = bImport( );
722 if( bRtn )
723 m_poFrmMain->SetStatusText( wxT(" Schematic file/s re-imported successfully"),
724 FrmMain::ePANE_MESAGE );
725 }
726 else if( m_oPrcGNetList.rofnGetNetLstFile( ).IsOk( ) )
727 { // Reload a netlist file
728 bRtn = bOpen( );
729 if( bRtn )
730 m_poFrmMain->SetStatusText( wxT(" Netlist file reloaded successfully"),
731 FrmMain::ePANE_MESAGE );
732 }
733 else
734 {
735 // There's no open schematic or netlist to reload, display an error message
736 m_poFrmMain->DlgErrMsg( wxT("Reload Operation Error"), wxT("No file is currently open.") );
737 bRtn = false;
738 }
739
740 return( bRtn );
741 }
742
743 //**************************************************************************************************
744 // Close the circuit description file.
745 //
746 // Return Values :
747 // true - Success
748 // false - Failure
749
bClose(void)750 bool FileTasks::bClose( void )
751 {
752 // Is there a file currently open?
753 if( m_oPrcGNetList.roaGetSchemFiles().IsEmpty() && !m_oPrcGNetList.rofnGetNetLstFile().IsOk() )
754 {
755 // There's no open schematic or netlist to close, display an error message
756 m_poFrmMain->DlgErrMsg( wxT("Close Operation Error"), wxT("No file is currently open.") );
757 return( false );
758 }
759
760 // Delete temporary files
761 bDelTmpFiles( );
762
763 // Clear file names
764 m_oPrcGNetList.bClear( );
765 bSetNetLstFile( wxT("") );
766 bSetSchemFiles( wxT("") );
767
768 // Set the status bar message
769 m_poFrmMain->SetStatusText( wxT(" Netlist file closed successfully"), FrmMain::ePANE_MESAGE );
770
771 // Set the text control notebook page
772 m_poFrmMain->m_oNbkTxtCtls.bSetPage( NbkTxtCtls::ePAGE_CONSOLE );
773
774 return( true );
775 }
776
777 //**************************************************************************************************
778 // Do the necessary tasks before the application exits.
779 //
780 // Return Values :
781 // true - Success
782 // false - Failure
783
bExit(void)784 bool FileTasks::bExit( void )
785 {
786 // Delete temporary file/s
787 if( ! bDelTmpFiles( ) ) return( false );
788
789 return( true );
790 }
791
792 //**************************************************************************************************
793