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