1 //**************************************************************************************************
2 //                                        PnlNgSpiceTR.cpp                                         *
3 //                                       ------------------                                        *
4 // Started     : 2004-08-05                                                                        *
5 // Last Update : 2015-03-29                                                                        *
6 // Copyright   : (C) 2004 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 "PnlNgSpiceTR.hpp"
18 
19 //**************************************************************************************************
20 // Implement an event table.
21 
wxBEGIN_EVENT_TABLE(PnlNgSpiceTR,PnlAnaBase)22 wxBEGIN_EVENT_TABLE( PnlNgSpiceTR, PnlAnaBase )
23 
24   EVT_CHOICE( PnlAnaBase  ::ID_CHO_SRCNAME, PnlNgSpiceTR::OnSrcName  )
25   EVT_BUTTON( PnlNgSpiceTR::ID_BTN_SETUP  , PnlNgSpiceTR::OnBtnSetup )
26 
27 wxEND_EVENT_TABLE( )
28 
29 //**************************************************************************************************
30 // Constructor.
31 
32 PnlNgSpiceTR::PnlNgSpiceTR( wxWindow * poWin ) : PnlAnaBase( poWin ), m_oDlgCfgSrc( poWin )
33 {
34   bSetAnalysType( eCMD_TR );
35 
36   Create( );  // Create the analysis panel
37   bClear( );  // Clear all object attributes
38 }
39 
40 //**************************************************************************************************
41 // Destructor.
42 
~PnlNgSpiceTR()43 PnlNgSpiceTR::~PnlNgSpiceTR( )
44 {
45 }
46 
47 //**************************************************************************************************
48 // Create the display objects.
49 
Create(void)50 void  PnlNgSpiceTR::Create( void )
51 {
52   PnlAnaBase::CreateBase( );    // Create the base controls
53   PnlAnaBase::CreateInitC( );   // Create and add the initial condtns controls
54   PnlAnaBase::CreateTemp( );    // Create the analysis temperature controls
55               CreateSigSrc( );  // Create and add signal source controls
56 
57   PnlAnaBase::DoLayout( );      // Layout the panel's GUI objects
58 
59   // Set the time sweep parameter labels
60   m_oSbxSwpPars.SetLabel( wxT(" Time Sweep ") );
61   m_oPnlStart  .bSetName( wxT("Start Time") );
62   m_oPnlStop   .bSetName( wxT("Stop Time") );
63   m_oPnlStep   .bSetName( wxT("Step Increment") );
64 
65   // Set sweep parameter units
66   m_oPnlStart.bSetUnitsType( eUNITS_TIME );
67   m_oPnlStop .bSetUnitsType( eUNITS_TIME );
68   m_oPnlStep .bSetUnitsType( eUNITS_TIME );
69 
70   // Disable the checkboxes for the parameters NG-Spice cannot calculate
71   m_oCbxCurrent.Disable( );
72   m_oCbxPower  .Disable( );
73   m_oCbxResist .Disable( );
74 }
75 
76 //**************************************************************************************************
77 // Create the source component display objects.
78 
CreateSigSrc(void)79 void  PnlNgSpiceTR::CreateSigSrc( void )
80 {
81   // Create and add signal source controls
82   m_oSbxSigSrc .Create( this, ID_UNUSED   , wxT(" Signal Source "), wxPoint(   6, 178 ),
83                         wxSize( 255, 60 ) );
84   m_oChoSrcName.Create( this, ID_CHO_SRCNAME,                       wxPoint(  18, 200 ),
85                         wxSize( 121, GUI_CTRL_HT ) );
86   m_oBtnSetup  .Create( this, ID_BTN_SETUP, wxT("Setup ..."),       wxPoint( 143, 200 ),
87                         wxSize( 105, GUI_CTRL_HT ) );
88 
89   // Set static box font
90   m_oSbxSigSrc.SetOwnFont( FONT_SLANT );
91 }
92 
93 //**************************************************************************************************
94 // Clear the object attributes.
95 //
96 // Return Values:
97 //   true  - Success
98 //   false - Failure
99 
bClear(void)100 bool  PnlNgSpiceTR::bClear( void )
101 {
102   // Clear the base class
103   PnlAnaBase::bClear( );
104 
105   // Set the sweep parameters to their defaults
106   m_oPnlStart.bSetValue( (float)   0.0 );
107   m_oPnlStop .bSetValue( (float) 100.0 );
108   m_oPnlStep .bSetValue( (float)  10.0 );
109   m_oPnlStart.bSetUnits( wxT("msec") );
110   m_oPnlStop .bSetUnits( wxT("msec") );
111   m_oPnlStep .bSetUnits( wxT("msec") );
112 
113   // Set default initial condition values
114   bSetInitC( eINITC_WARM );
115 
116   // Set input source default values
117   m_oChoSrcName.Clear( );
118   m_oChoSrcName.Append( wxT("None") );
119   m_oChoSrcName.SetSelection( 0 );
120 
121   // Clear the generator dialog
122   m_oDlgCfgSrc.bClear( );
123 
124   // Set parameters check box default values
125   m_oCbxVoltage.SetValue( true );
126   m_oCbxCurrent.SetValue( false );
127   m_oCbxPower  .SetValue( false );
128   m_oCbxResist .SetValue( false );
129 
130   // Set default temperature value
131   m_oPnlTemp.bSetValue( 27.0 );
132 
133   return( true );
134 }
135 
136 //**************************************************************************************************
137 // Load information from a simulation object.
138 //
139 // Argument List :
140 //   roSimn - A simulation object
141 //
142 // Return Values :
143 //   true  - Success
144 //   false - Failure
145 
bLoad(SimnNgSpice & roSimn)146 bool  PnlNgSpiceTR::bLoad( SimnNgSpice & roSimn )
147 {
148   bool  bRtn=true;
149 
150   // Load the components into the signal source choice box
151   PnlAnaBase::LoadSrcNames( roSimn.m_oaCpnts, wxT("VI") );
152 
153   // Go no further if the TR command isn't valid
154   if( ! roSimn.m_oCmdTR.bIsValid( ) )                        return( false );
155 
156   // Set the source component name (a sweep source is not mandatory for a TR analysis)
157   PnlAnaBase::bSetSrcCpnt( roSimn.m_oCpntSwpSrc );
158 
159   // Set the initial state of the source setup dialog
160   m_oDlgCfgSrc.bSetValues( roSimn.m_oCpntIndSrc );
161 
162   // Set the initial conditions
163   if( ! bSetInitC( (eTypeInitC) roSimn.m_oCmdTR.m_eInitC ) ) bRtn = false;
164 
165   // Set the sweep values
166   if( ! m_oPnlStart.bSetValue( roSimn.m_oCmdTR.m_osStart ) ) bRtn = false;
167   if( ! m_oPnlStop .bSetValue( roSimn.m_oCmdTR.m_osStop  ) ) bRtn = false;
168   if( ! m_oPnlStep .bSetValue( roSimn.m_oCmdTR.m_osStep  ) ) bRtn = false;
169 
170   // Set the analysis temperature
171   if( ! m_oPnlTemp.bSetValue( roSimn.m_oCmdOPT.m_osTEMP ) )  bRtn = false;
172 
173   return( bRtn );
174 }
175 
176 //**************************************************************************************************
177 // Save information to a simulation object.
178 // (Prior to it being passed to a simulator object.)
179 //
180 // Argument List :
181 //   roSimn - A simulation object
182 //
183 // Return Values :
184 //   true  - Success
185 //   false - Failure
186 
bSave(SimnNgSpice & roSimn)187 bool  PnlNgSpiceTR::bSave( SimnNgSpice & roSimn )
188 {
189   wxString  os1;
190 
191   m_osErrMsg.Empty( );
192 
193   // Set the analysis type
194   roSimn.m_oCmdPR.bSetAnaType( eCMD_TR );
195 
196   // Set the sweep values
197   roSimn.m_oCmdTR.m_osStart = m_oPnlStart.rosGetValue( );
198   roSimn.m_oCmdTR.m_osStop  = m_oPnlStop .rosGetValue( );
199   roSimn.m_oCmdTR.m_osStep  = m_oPnlStep .rosGetValue( );
200 
201   // Set the initial conditions
202   roSimn.m_oCmdTR.m_eInitC = (eTypeInitC) m_oRbxSweep.GetSelection( );
203 
204   // Set the component to be used as a signal source
205   if( m_oChoSrcName.GetStringSelection( ) != wxT("None") )
206   {
207     // Get the unmodified signal source component
208     os1 = m_oChoSrcName.GetStringSelection( );
209     (Component &) roSimn.m_oCpntIndSrc = roSimn.roGetCpnt( os1 );
210     // Add the modifications from the independent source configuration dialog
211     m_oDlgCfgSrc.bGetValues( roSimn.m_oCpntIndSrc );
212     if( roSimn.m_oCpntIndSrc.bFormat( ) )
213       roSimn.m_oCpntSwpSrc = roSimn.m_oCpntIndSrc;
214     else
215     {
216       os1 = wxT("The signal source ")
217           + roSimn.m_oCpntIndSrc.rosGetErrMsg( ) + wxT(".   ");
218       SetErrMsg( os1 );
219     }
220   }
221   else
222   {
223     roSimn.m_oCpntSwpSrc.bClear( );
224     roSimn.m_oCpntIndSrc.bClear( );
225   }
226 
227   // Store the parameters to derive
228   roSimn.m_oCmdPR.m_bParams[ ePARAM_VLT ] = m_oCbxVoltage.GetValue( );
229   roSimn.m_oCmdPR.m_bParams[ ePARAM_CUR ] = m_oCbxCurrent.GetValue( );
230   roSimn.m_oCmdPR.m_bParams[ ePARAM_PWR ] = m_oCbxPower  .GetValue( );
231   roSimn.m_oCmdPR.m_bParams[ ePARAM_RES ] = m_oCbxResist .GetValue( );
232 
233   // Create the command strings
234   roSimn.m_oCmdTR.bFormat( );
235   roSimn.m_oCmdPR.bFormat( );
236 
237   // Check for errors
238   if( ! roSimn.m_oCmdTR.bIsValid( ) )
239     SetErrMsg( roSimn.m_oCmdTR.rosGetErrMsg( ) );
240   if( ! roSimn.m_oCmdPR.bIsValid( ) )
241     SetErrMsg( roSimn.m_oCmdPR.rosGetErrMsg( ) );
242 
243   return( bIsOk( ) );
244 }
245 
246 //**************************************************************************************************
247 //                                         Event Handlers                                          *
248 //**************************************************************************************************
249 // Generator component choice control event handler.
250 //
251 // Argument List:
252 //   roEvtCmd - An object holding information about the event
253 
OnSrcName(wxCommandEvent & roEvtCmd)254 void  PnlNgSpiceTR::OnSrcName( wxCommandEvent & roEvtCmd )
255 {
256   wxString  os1;
257 
258   // Execute the base class event handler first
259   PnlAnaBase::OnSrcName( roEvtCmd );
260 
261   // Set the signal source name in the configuration dialogue
262   os1 = m_oChoSrcName.GetStringSelection( );
263   if( os1 != wxT("None") ) m_oDlgCfgSrc.bSetName( os1 );
264   else                     m_oDlgCfgSrc.bClear( );
265 }
266 
267 //**************************************************************************************************
268 // Generator component setup button control event handler.
269 //
270 // Argument List:
271 //   roEvtCmd - An object holding information about the event
272 
OnBtnSetup(wxCommandEvent & WXUNUSED (roEvtCmd))273 void  PnlNgSpiceTR::OnBtnSetup( wxCommandEvent & WXUNUSED( roEvtCmd ) )
274 {
275   m_oDlgCfgSrc.CenterOnParent( );
276   m_oDlgCfgSrc.ShowModal( );
277 }
278 
279 //**************************************************************************************************
280