1 //**************************************************************************************************
2 // PnlGnuCapAC.cpp *
3 // ----------------- *
4 // Started : 2003-08-18 *
5 // Last Update : 2015-03-30 *
6 // Copyright : (C) 2003 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 "PnlGnuCapAC.hpp"
18
19 //**************************************************************************************************
20 // Implement an event table.
21
wxBEGIN_EVENT_TABLE(PnlGnuCapAC,PnlAnaBase)22 wxBEGIN_EVENT_TABLE( PnlGnuCapAC, PnlAnaBase )
23
24 EVT_RADIOBOX( PnlAnaBase::ID_RBX_SCALE , PnlGnuCapAC::OnScale )
25 EVT_CHOICE ( PnlAnaBase::ID_CHO_SRCNAME, PnlGnuCapAC::OnSrcName )
26
27 wxEND_EVENT_TABLE( )
28
29 //**************************************************************************************************
30 // Constructor.
31
32 PnlGnuCapAC::PnlGnuCapAC( wxWindow * poWin ) : PnlAnaBase( poWin )
33 {
34 bSetAnalysType( eCMD_AC );
35
36 Create( ); // Create the analysis panel
37
38 bClear( ); // Clear all object attributes
39 }
40
41 //**************************************************************************************************
42 // Destructor.
43
~PnlGnuCapAC()44 PnlGnuCapAC::~PnlGnuCapAC( )
45 {
46 }
47
48 //**************************************************************************************************
49 // Create the display objects.
50
Create(void)51 void PnlGnuCapAC::Create( void )
52 {
53 PnlAnaBase::CreateBase( ); // Create the base controls
54 PnlAnaBase::CreateScale( ); // Create the scale controls
55 PnlAnaBase::CreateCpxPrt( ); // Create the parameter complex part check boxes
56 PnlAnaBase::CreateSigSrc( ); // Create the input signal source controls
57 PnlAnaBase::CreateTemp( ); // Create the analysis temperature controls
58
59 PnlAnaBase::DoLayout( ); // Layout the panel's GUI objects
60
61 // Set the frequency sweep parameter labels
62 m_oSbxSwpPars.SetLabel( wxT(" AC Sweep ") );
63 m_oPnlStart .bSetName( wxT("Start Frequency") );
64 m_oPnlStop .bSetName( wxT("Stop Frequency") );
65
66 // Set sweep parameter units
67 m_oPnlStart.bSetUnitsType( eUNITS_FREQ );
68 m_oPnlStop .bSetUnitsType( eUNITS_FREQ );
69 m_oPnlStep .bSetUnitsType( eUNITS_FREQ );
70 }
71
72 //**************************************************************************************************
73 // Initialize the step scale.
74
InitScale(void)75 void PnlGnuCapAC::InitScale( void )
76 {
77 switch( m_oRbxSweep.GetSelection( ) )
78 {
79 case eSCALE_LIN :
80 m_oPnlStep.bSetName( wxT("Step Increment") );
81 m_oPnlStep.bSetValueType( eVALUE_FLT );
82 m_oPnlStep.bShowUnits( PnlValue::eSHOW_CHO );
83 m_oPnlStep.bSetUnitsType( eUNITS_FREQ );
84 break;
85
86 case eSCALE_LOG :
87 m_oPnlStep.bSetName( wxT("Step Multiplier") );
88 m_oPnlStep.bSetValueType( eVALUE_FLT );
89 m_oPnlStep.bShowUnits( PnlValue::eSHOW_LBL );
90 m_oPnlStep.bSetUnitsType( eUNITS_EXP );
91 m_oPnlStep.bSetSpnRange( 0.01, 10000.0 );
92 m_oPnlStep.bSetSpnIncSz( 0.1 , 1000.0 );
93 m_oPnlStep.bSetDefValue( 1.1 );
94 break;
95
96 case eSCALE_DEC :
97 m_oPnlStep.bSetName( wxT("Steps / Decade") );
98 m_oPnlStep.bSetValueType( eVALUE_INT );
99 m_oPnlStep.bShowUnits( PnlValue::eSHOW_LBL );
100 m_oPnlStep.bSetUnitsType( eUNITS_EXP );
101 m_oPnlStep.bSetSpnRange( 1, 10000 );
102 m_oPnlStep.bSetSpnIncSz( 1, 1000 );
103 m_oPnlStep.bSetDefValue( 10 );
104 break;
105
106 case eSCALE_OCT :
107 m_oPnlStep.bSetName( wxT("Steps / Octave") );
108 m_oPnlStep.bSetValueType( eVALUE_INT );
109 m_oPnlStep.bShowUnits( PnlValue::eSHOW_LBL );
110 m_oPnlStep.bSetUnitsType( eUNITS_EXP );
111 m_oPnlStep.bSetSpnRange( 1, 10000 );
112 m_oPnlStep.bSetSpnIncSz( 1, 1000 );
113 m_oPnlStep.bSetDefValue( 10 );
114 break;
115
116 default :
117 break;
118 }
119 }
120
121 //**************************************************************************************************
122 // Clear the object attributes.
123 //
124 // Return Values :
125 // true - Success
126 // false - Failure
127
bClear(void)128 bool PnlGnuCapAC::bClear( void )
129 {
130 // Clear the base class
131 PnlAnaBase::bClear( );
132
133 // Set default step scale type and sweep values
134 m_oPnlStart.bSetValue( (float) 1.0 );
135 m_oPnlStop .bSetValue( (float) 100.0 );
136 m_oPnlStep .bSetValue( (float) 10.0 );
137 m_oPnlStart.bSetUnits( wxT("kHz") );
138 m_oPnlStop .bSetUnits( wxT("kHz") );
139 m_oPnlStep .bSetUnits( wxT("kHz") );
140
141 // Set default scale value
142 bSetScale( eSCALE_DEC );
143
144 // Set input source default values
145 m_oChoSrcName.Clear( );
146 m_oChoSrcName.Append( wxT("None") );
147 m_oChoSrcName.SetSelection( 0 );
148 m_oPnlSrcLvl.bSetValue( (float) 0.0 );
149 m_oPnlSrcLvl.bSetUnitsType( eUNITS_NONE );
150
151 // Set parameters check box default values
152 m_oCbxVoltage.SetValue( true );
153 m_oCbxCurrent.SetValue( false );
154 m_oCbxPower .SetValue( false );
155 m_oCbxResist .SetValue( false );
156
157 // Set the complex part check box default values
158 m_oCbxMag .SetValue( true );
159 m_oCbxPhase.SetValue( false );
160 m_oCbxReal .SetValue( false );
161 m_oCbxImag .SetValue( false );
162 m_oCbxMagDb.SetValue( true );
163
164 // Set default temperature value
165 m_oPnlTemp.bSetValue( 27.0 );
166
167 return( true );
168 }
169
170 //**************************************************************************************************
171 // Load information from a simulation object.
172 //
173 // Argument List :
174 // roSimn - A simulation object
175 //
176 // Return Values :
177 // true - Success
178 // false - Failure
179
bLoad(SimnGnuCap & roSimn)180 bool PnlGnuCapAC::bLoad( SimnGnuCap & roSimn )
181 {
182 bool bRtn=true;
183
184 // Load the components into the signal source choice box
185 PnlAnaBase::LoadSrcNames( roSimn.m_oaCpnts, wxT("VI") );
186
187 // Go no further if the AC command isn't valid
188 if( ! roSimn.m_oCmdAC.bIsValid( ) ) return( false );
189
190 // Set the source component
191 if( ! PnlAnaBase::bSetSrcCpnt( roSimn.m_oCpntSwpSrc ) ) bRtn = false;
192
193 // Set the step scale (do this before setting the sweep step)
194 if( roSimn.m_oCmdAC.m_eScale != eSCALE_NONE )
195 {
196 m_oRbxSweep.SetSelection( roSimn.m_oCmdAC.m_eScale );
197 InitScale( );
198 }
199
200 // Set the sweep values
201 if( ! m_oPnlStart.bSetValue( roSimn.m_oCmdAC.m_osStart ) ) bRtn = false;
202 if( ! m_oPnlStop .bSetValue( roSimn.m_oCmdAC.m_osStop ) ) bRtn = false;
203 if( ! m_oPnlStep .bSetValue( roSimn.m_oCmdAC.m_osStep ) ) bRtn = false;
204
205 // Set the parameters to derive
206 m_oCbxVoltage.SetValue( roSimn.m_oCmdPR.m_bParams[ ePARAM_VLT ] );
207 m_oCbxCurrent.SetValue( roSimn.m_oCmdPR.m_bParams[ ePARAM_CUR ] );
208 m_oCbxPower .SetValue( roSimn.m_oCmdPR.m_bParams[ ePARAM_PWR ] );
209 m_oCbxResist .SetValue( roSimn.m_oCmdPR.m_bParams[ ePARAM_RES ] );
210
211 // Set the complex parts to derive
212 m_oCbxMag .SetValue( roSimn.m_oCmdPR.m_bCpxPts[ eCPXPT_MAG ] );
213 m_oCbxPhase.SetValue( roSimn.m_oCmdPR.m_bCpxPts[ eCPXPT_PHASE ] );
214 m_oCbxReal .SetValue( roSimn.m_oCmdPR.m_bCpxPts[ eCPXPT_REAL ] );
215 m_oCbxImag .SetValue( roSimn.m_oCmdPR.m_bCpxPts[ eCPXPT_IMAG ] );
216 m_oCbxMagDb.SetValue( roSimn.m_oCmdPR.m_bCpxPts[ eCPXPT_MAGDB ] );
217
218 // Set the analysis temperature
219 if( ! m_oPnlTemp.bSetValue( roSimn.m_oCmdAC.m_osTempC ) ) bRtn = false;
220
221 return( bRtn );
222 }
223
224 //**************************************************************************************************
225 // Save information to a simulation object.
226 //
227 // Argument List :
228 // roSimn - A simulation object
229 //
230 // Return Values :
231 // true - Success
232 // false - Failure
233
bSave(SimnGnuCap & roSimn)234 bool PnlGnuCapAC::bSave( SimnGnuCap & roSimn )
235 {
236 wxString os1;
237 size_t sz1;
238 bool b1;
239
240 m_osErrMsg.Empty( );
241
242 // Set the analysis type
243 roSimn.m_oCmdPR.bSetAnaType( eCMD_AC );
244
245 // Set the sweep values
246 roSimn.m_oCmdAC.m_osStart = m_oPnlStart.rosGetValue( );
247 roSimn.m_oCmdAC.m_osStop = m_oPnlStop .rosGetValue( );
248 roSimn.m_oCmdAC.m_osStep = m_oPnlStep .rosGetValue( );
249
250 // Set the step scale
251 roSimn.m_oCmdAC.m_eScale = (eTypeScale) m_oRbxSweep.GetSelection( );
252
253 // Set the component to be used as the sweep source
254 if( m_oChoSrcName.GetStringSelection( ) == wxT("None") )
255 SetErrMsg( wxT("No sweep source component has been selected.") );
256 else if ( m_oPnlSrcLvl.dfGetValue( ) == 0.0 )
257 SetErrMsg( wxT("Sweep source component value of zero is not permitted.") );
258 else
259 {
260 os1 = m_oChoSrcName.GetStringSelection( );
261 roSimn.m_oCpntSwpSrc = roSimn.NetList::roGetCpnt( os1 );
262 roSimn.m_oCpntSwpSrc.bSetValue( wxT("GENERATOR(1) AC ") + m_oPnlSrcLvl.rosGetValue( ) );
263 }
264
265 // Store the parameters to derive
266 roSimn.m_oCmdPR.m_bParams[ ePARAM_VLT ] = m_oCbxVoltage.GetValue( );
267 roSimn.m_oCmdPR.m_bParams[ ePARAM_CUR ] = m_oCbxCurrent.GetValue( );
268 roSimn.m_oCmdPR.m_bParams[ ePARAM_PWR ] = m_oCbxPower .GetValue( );
269 roSimn.m_oCmdPR.m_bParams[ ePARAM_RES ] = m_oCbxResist .GetValue( );
270
271 // Store the complex parts of the parameters to derive
272 roSimn.m_oCmdPR.m_bCpxPts[ eCPXPT_MAG ] = m_oCbxMag .GetValue( );
273 roSimn.m_oCmdPR.m_bCpxPts[ eCPXPT_PHASE ] = m_oCbxPhase.GetValue( );
274 roSimn.m_oCmdPR.m_bCpxPts[ eCPXPT_REAL ] = m_oCbxReal .GetValue( );
275 roSimn.m_oCmdPR.m_bCpxPts[ eCPXPT_IMAG ] = m_oCbxImag .GetValue( );
276 roSimn.m_oCmdPR.m_bCpxPts[ eCPXPT_MAGDB ] = m_oCbxMagDb.GetValue( );
277
278 // Set the analysis temperature
279 roSimn.m_oCmdAC.m_osTempC = m_oPnlTemp.rosGetValue( );
280
281 // Create the command strings
282 roSimn.m_oCmdAC.bFormat( );
283 roSimn.m_oCmdPR.bFormat( );
284
285 // Check for errors
286 if( ! roSimn.m_oCmdAC.bIsValid( ) )
287 SetErrMsg( roSimn.m_oCmdAC.rosGetErrMsg( ) );
288 if( ! roSimn.m_oCmdPR.bIsValid( ) )
289 SetErrMsg( roSimn.m_oCmdPR.rosGetErrMsg( ) );
290 for( sz1=eCPXPT_MAG, b1=false; sz1<=eCPXPT_IMAG; sz1++ )
291 if( roSimn.m_oCmdPR.m_bCpxPts[ sz1 ] ) b1 = true;
292 if( ! b1 ) SetErrMsg( wxT("No complex parts have been selected.") );
293
294 return( bIsOk( ) );
295 }
296
297 //**************************************************************************************************
298 // Event Handlers *
299 //**************************************************************************************************
300 // Step scale radio box event handler.
301 //
302 // Argument List :
303 // roEvtCmd - An object holding information about the event
304
OnScale(wxCommandEvent & WXUNUSED (roEvtCmd))305 void PnlGnuCapAC::OnScale( wxCommandEvent & WXUNUSED( roEvtCmd ) )
306 {
307 InitScale( );
308 }
309
310 //**************************************************************************************************
311 // Source component choice box event handler.
312 //
313 // Argument List :
314 // roEvtCmd - An object holding information about the event
315
OnSrcName(wxCommandEvent & roEvtCmd)316 void PnlGnuCapAC::OnSrcName( wxCommandEvent & roEvtCmd )
317 {
318 wxString os1;
319
320 // Execute the base class event handler first
321 PnlAnaBase::OnSrcName( roEvtCmd );
322
323 if( m_oChoSrcName.GetStringSelection( ) != wxT("None") )
324 {
325 // Set the units type
326 os1 = m_oChoSrcName.GetStringSelection( );
327 m_oPnlSrcLvl.bSetUnitsType( Component::eGetUnitsType( os1 ) );
328
329 // Set the source value
330 if( m_oPnlSrcLvl.dfGetValue( ) == 0.0 )
331 m_oPnlSrcLvl.bSetValue( (double) 1.0 );
332 }
333 else
334 {
335 m_oPnlSrcLvl.bSetUnitsType( eUNITS_NONE );
336 m_oPnlSrcLvl.bSetValue( (double) 0.0 );
337 }
338 }
339
340 //**************************************************************************************************
341