Blame view

GUI/SW2/SRC/src/process/PrcGSchem.cpp 5.61 KB
886c558b   Steve Greedy   SACAMOS Public Re...
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
//**************************************************************************************************
//                                          PrcGSchem.cpp                                          *
//                                         ---------------                                         *
// Started     : 2008-02-18                                                                        *
// Last Update : 2016-10-29                                                                        *
// Copyright   : (C) 2004-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 "PrcGSchem.hpp"

//**************************************************************************************************
// Constructor.

PrcGSchem::PrcGSchem( void ) : PrcBase( wxPROCESS_REDIRECT )
{
  // Initialize the object attributes
  m_oaNameSchems.Clear( );
  m_oNameLog    .Clear( );

  // Attempt to set and find the appropriate binary
  bSetBinFile( BIN_GSCHEM );
}

//**************************************************************************************************
// Destructor.

PrcGSchem::~PrcGSchem( )
{
}

//**************************************************************************************************
// Set the schematic file name/s.
//
// Argument List:
//   rosFileNames - A string containing the full path and file name/s
//
// Return Values:
//   true  - Success
//   false - Failure

bool  PrcGSchem::bSetSchemFiles( const wxString & rosFileNames )
{
  wxStringTokenizer  ostk1;
  wxArrayString      oas1;

  ostk1.SetString( rosFileNames );
  while( ostk1.HasMoreTokens( ) )
    oas1.Add( ostk1.GetNextToken( ) );

  return( bSetSchemFiles( oas1 ) );
}

//**************************************************************************************************
// 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  PrcGSchem::bSetSchemFiles( const wxArrayString & roasFileNames )
{
  wxFileName  ofn1;
  size_t      szt1;

  // Clear the current list of schematic files
  m_oaNameSchems.Clear( );

  // Check the argument is empty
  if( roasFileNames.IsEmpty( ) )                              return( true );

  // Add the new schematic file name/s to the list
  for( szt1=0; szt1<roasFileNames.GetCount( ); szt1++ )
  {
    ofn1 = roasFileNames.Item( szt1 );
    if( ofn1.GetPath( ).IsEmpty( ) ) ofn1.SetPath( wxT(".") );

    if( ! ofn1.IsOk( )       ) continue;
    if( ! ofn1.FileExists( ) ) continue;

    m_oaNameSchems.Add( ofn1 );
  }

  // Check that at least one schematic file name was accepted
  if( m_oaNameSchems.IsEmpty( ) )                               return( false );

  // Set the log file path
  ofn1 = roGetLogFile( );
  ofn1.SetPath( m_oaNameSchems.Item( 0 ).GetPath( ) );
  bSetLogFile( ofn1.GetFullPath( ) );

  // Check if any of the schematic files were invalid
  if( m_oaNameSchems.GetCount( ) != roasFileNames.GetCount( ) ) return( false );

  return( true );
}

//**************************************************************************************************
// Get a schematic file from the list of schematic files.
//
// Return Values:
//   Success - The procedure name
//   Failure - An empty file name

const wxString & PrcGSchem::rosGetSchemFiles( void )
{
  static  wxString  osSchems;
  size_t  sz1;

  osSchems.Empty( );

  for( sz1=0; sz1<m_oaNameSchems.GetCount( ); sz1++ )
  {
    if( ! osSchems.IsEmpty( ) ) osSchems << wxT(' ');
    osSchems << m_oaNameSchems.Item( sz1 ).GetFullPath( );
  }

  return( osSchems );
}

//**************************************************************************************************
// Edit the schematic file/s.
//
// (Eg. using the following : gschem ../sch/test-amp1.sch)
//
// Return Values :
//   true  - Success
//   false - Failure

bool  PrcGSchem::bExec( void )
{
  wxString  osArgLst;

  // Test file names needed by this function
  if( ! bBinExists( ) )          return( false );
  if( rosGetSchemFiles( ).IsEmpty( ) )
  {
    m_osErrMsg << wxT("The schematic file/s have not been set.");
    return( false );
  }

  // Disable backup files in gschem eg. circuit.sch~
  osArgLst << wxT("-c \"(auto-save-interval 0)\" ");

  // Don't display the status windows at startup
  osArgLst << wxT("-c \"(view-status)\" ");

  // Don't display the side bar at startup
  osArgLst << wxT("-c \"(view-sidebar)\" ");

  // Use the light colour scheme
  osArgLst << wxT("-c \"(view-light-colors)\" ");

  // Append input file name to argument list
  osArgLst << rosGetSchemFiles( );

  // Set the command line arguments
  if( ! bSetArgLst( osArgLst ) ) return( false );

  // Execute the process
  if( ! PrcBase::bExecAsync( ) ) return( false );

  return( true );
}

//**************************************************************************************************