1 //**************************************************************************************************
2 //                                        DlgNgsCfgSrc.hpp                                         *
3 //                                       ------------------                                        *
4 // Started     : 2005-05-13                                                                        *
5 // Last Update : 2015-04-17                                                                        *
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 "DlgNgsCfgSrc.hpp"
18 
19 //**************************************************************************************************
20 // Implement an event table.
21 
wxBEGIN_EVENT_TABLE(DlgNgsCfgSrc,wxDialog)22 wxBEGIN_EVENT_TABLE( DlgNgsCfgSrc, wxDialog )
23 
24   EVT_BUTTON( ID_BTN_OK,     DlgNgsCfgSrc::OnBtnOk     )
25   EVT_BUTTON( ID_BTN_CLEAR,  DlgNgsCfgSrc::OnBtnClear  )
26   EVT_BUTTON( ID_BTN_CANCEL, DlgNgsCfgSrc::OnBtnCancel )
27 
28 wxEND_EVENT_TABLE( )
29 
30 //**************************************************************************************************
31 // Constructor.
32 //
33 // Argument List :
34 //   poWin - A pointer to the dialog parent window
35 
36 DlgNgsCfgSrc::DlgNgsCfgSrc( wxWindow * poWin ) :
37                 wxDialog( poWin, -1, wxT(""), wxDefaultPosition, wxDefaultSize,
38                           wxDEFAULT_DIALOG_STYLE, wxDialogNameStr )
39 {
40   SetTitle( wxT("Signal Source Setup") );
41   Initialize( );
42   bClear( );
43 }
44 
45 //**************************************************************************************************
46 // Destructor.
47 
~DlgNgsCfgSrc()48 DlgNgsCfgSrc::~DlgNgsCfgSrc( )
49 {
50 }
51 
52 //**************************************************************************************************
53 // Initialize object attributes.
54 
Initialize(void)55 void  DlgNgsCfgSrc::Initialize( void )
56 {
57   // Call all the initialization functions
58   Create( );
59   ToolTips( );
60 
61   // Layout the of the display objects
62   DoLayout( );
63 }
64 
65 //**************************************************************************************************
66 // Create the display objects.
67 
Create(void)68 void  DlgNgsCfgSrc::Create( void )
69 {
70   wxPanel * poPnlSine, * poPnlPulse, * poPnlBtns;
71   int       iWdName=115, iWdValue=95, iWdUnits=75;
72 
73   // Create the various underlying panel objects
74   poPnlSine  = new wxPanel( this );
75   poPnlPulse = new wxPanel( this );
76   poPnlBtns  = new wxPanel( this );
77 
78   // Create the Sinusoid panel controls
79   m_oPnlSinAmp   .bCreate( poPnlSine, ID_PNL_SIN_AMP   , iWdName, iWdValue, iWdUnits );
80   m_oPnlSinFreq  .bCreate( poPnlSine, ID_PNL_SIN_FREQ  , iWdName, iWdValue, iWdUnits );
81   m_oPnlSinOffset.bCreate( poPnlSine, ID_PNL_SIN_OFFSET, iWdName, iWdValue, iWdUnits );
82   m_oPnlSinDelay .bCreate( poPnlSine, ID_PNL_SIN_DELAY , iWdName, iWdValue, iWdUnits );
83   m_oPnlSinDamp  .bCreate( poPnlSine, ID_PNL_SIN_DAMP  , iWdName, iWdValue, iWdUnits );
84 
85   m_oPnlSinAmp   .bSetName( wxT("Amplitude")      );
86   m_oPnlSinFreq  .bSetName( wxT("Frequency")      );
87   m_oPnlSinOffset.bSetName( wxT("DC Offset")      );
88   m_oPnlSinDelay .bSetName( wxT("Initial Delay")  );
89   m_oPnlSinDamp  .bSetName( wxT("Damping Factor") );
90 
91   m_oPnlSinAmp   .bSetUnitsType( eUNITS_VOLT );
92   m_oPnlSinFreq  .bSetUnitsType( eUNITS_FREQ );
93   m_oPnlSinOffset.bSetUnitsType( eUNITS_VOLT );
94   m_oPnlSinDelay .bSetUnitsType( eUNITS_TIME );
95   m_oPnlSinDamp  .bShowUnits( PnlValue::eSHOW_LBL );
96 
97   // Create the Pulse panel controls
98   m_oPnlPulInitial.bCreate( poPnlPulse, ID_PNL_PUL_INITV , iWdName, iWdValue, iWdUnits );
99   m_oPnlPulMax    .bCreate( poPnlPulse, ID_PNL_PUL_MAXV  , iWdName, iWdValue, iWdUnits );
100   m_oPnlPulDelay  .bCreate( poPnlPulse, ID_PNL_PUL_DELAY , iWdName, iWdValue, iWdUnits );
101   m_oPnlPulRise   .bCreate( poPnlPulse, ID_PNL_PUL_RISE  , iWdName, iWdValue, iWdUnits );
102   m_oPnlPulWidth  .bCreate( poPnlPulse, ID_PNL_PUL_WIDTH , iWdName, iWdValue, iWdUnits );
103   m_oPnlPulFall   .bCreate( poPnlPulse, ID_PNL_PUL_FALL  , iWdName, iWdValue, iWdUnits );
104   m_oPnlPulPeriod .bCreate( poPnlPulse, ID_PNL_PUL_PERIOD, iWdName, iWdValue, iWdUnits );
105 
106   m_oPnlPulInitial.bSetName( wxT("Initial Value") );
107   m_oPnlPulMax    .bSetName( wxT("Pulsed Value")  );
108   m_oPnlPulDelay  .bSetName( wxT("Initial Delay") );
109   m_oPnlPulRise   .bSetName( wxT("Rise Time")     );
110   m_oPnlPulWidth  .bSetName( wxT("Pulse Width")   );
111   m_oPnlPulFall   .bSetName( wxT("Fall Time")     );
112   m_oPnlPulPeriod .bSetName( wxT("Period")        );
113 
114   m_oPnlPulInitial.bSetUnitsType( eUNITS_VOLT );
115   m_oPnlPulMax    .bSetUnitsType( eUNITS_VOLT );
116   m_oPnlPulDelay  .bSetUnitsType( eUNITS_TIME );
117   m_oPnlPulRise   .bSetUnitsType( eUNITS_TIME );
118   m_oPnlPulWidth  .bSetUnitsType( eUNITS_TIME );
119   m_oPnlPulFall   .bSetUnitsType( eUNITS_TIME );
120   m_oPnlPulPeriod .bSetUnitsType( eUNITS_TIME );
121 
122   // Create buttons panel and the button controls
123   m_oBtnOk    .Create( poPnlBtns, ID_BTN_OK,     wxT("OK")     );
124   m_oBtnClear .Create( poPnlBtns, ID_BTN_CLEAR,  wxT("Clear")  );
125   m_oBtnCancel.Create( poPnlBtns, ID_BTN_CANCEL, wxT("Cancel") );
126 }
127 
128 //**************************************************************************************************
129 // Initialize the tool tips.
130 
ToolTips(void)131 void  DlgNgsCfgSrc::ToolTips( void )
132 {
133   m_oPnlSinAmp    .SetToolTip( wxT("The amplitude of the sinusoidal signal") );
134   m_oPnlSinFreq   .SetToolTip( wxT("The frequency of the sinusoidal signal") );
135   m_oPnlSinOffset .SetToolTip( wxT("The DC offset of the sinusoidal signal") );
136   m_oPnlSinDelay  .SetToolTip( wxT("The initial delay of the sinusoidal signal") );
137   m_oPnlSinDamp   .SetToolTip( wxT("The damping factor of the sinusoidal signal") );
138 
139   m_oPnlPulInitial.SetToolTip( wxT("The initial value of the pulse source") );
140   m_oPnlPulMax    .SetToolTip( wxT("The maximum value of each pulse") );
141   m_oPnlPulDelay  .SetToolTip( wxT("The time until the first pulse") );
142   m_oPnlPulRise   .SetToolTip( wxT("The time taken to go from 0 to the pulsed value") );
143   m_oPnlPulWidth  .SetToolTip( wxT("The width of each pulse") );
144   m_oPnlPulFall   .SetToolTip( wxT("The time taken to go from the pulsed value to 0") );
145   m_oPnlPulPeriod .SetToolTip( wxT("The period of the pulse train") );
146 }
147 
148 //**************************************************************************************************
149 // Layout the dialog display objects.
150 
DoLayout(void)151 void  DlgNgsCfgSrc::DoLayout( void )
152 {
153   wxBoxSizer  * poSzrDlg;
154   wxPanel     * poPnlSine, * poPnlPulse, * poPnlBtns;
155   wxBoxSizer  * poSzrSine, * poSzrPulse, * poSzrBtns;
156   wxSizerFlags  oFlags;
157 
158   // Get pointers to the various panels
159   poPnlSine  = (wxPanel *) m_oPnlSinFreq   .GetParent( );
160   poPnlPulse = (wxPanel *) m_oPnlPulInitial.GetParent( );
161   poPnlBtns  = (wxPanel *) m_oBtnOk        .GetParent( );
162 
163   // Create sizers to associate with the panels
164   poSzrDlg   = new wxBoxSizer      ( wxVERTICAL   );
165   poSzrSine  = new wxStaticBoxSizer( wxVERTICAL, poPnlSine , wxT(" Sinusoid ") );
166   poSzrPulse = new wxStaticBoxSizer( wxVERTICAL, poPnlPulse, wxT(" Pulse ") );
167   poSzrBtns  = new wxBoxSizer      ( wxHORIZONTAL );
168 
169   // Set the sizers to the panels
170               SetSizer( poSzrDlg   );
171   poPnlSine ->SetSizer( poSzrSine  );
172   poPnlPulse->SetSizer( poSzrPulse );
173   poPnlBtns ->SetSizer( poSzrBtns  );
174 
175   // Layout the Sinusoid  panel
176   oFlags.Align( wxALIGN_LEFT );
177   oFlags.Border( wxTOP | wxLEFT | wxRIGHT, 10 );
178   poSzrSine->Add( &m_oPnlSinAmp   , oFlags );
179   oFlags.Border( wxLEFT | wxRIGHT        , 10 );
180   poSzrSine->Add( &m_oPnlSinFreq  , oFlags );
181   poSzrSine->Add( &m_oPnlSinOffset, oFlags );
182   poSzrSine->Add( &m_oPnlSinDelay , oFlags );
183   oFlags.Border( wxLEFT | wxBOTTOM       , 10 );
184   poSzrSine->Add( &m_oPnlSinDamp  , oFlags );
185 
186   // Layout the Pulse panel
187   oFlags.Border( wxTOP | wxLEFT | wxRIGHT, 10 );
188   poSzrPulse->Add( &m_oPnlPulInitial, oFlags );
189   oFlags.Border( wxLEFT | wxRIGHT        , 10 );
190   poSzrPulse->Add( &m_oPnlPulMax    , oFlags );
191   poSzrPulse->Add( &m_oPnlPulDelay  , oFlags );
192   poSzrPulse->Add( &m_oPnlPulRise   , oFlags );
193   poSzrPulse->Add( &m_oPnlPulWidth  , oFlags );
194   poSzrPulse->Add( &m_oPnlPulFall   , oFlags );
195   oFlags.Border( wxLEFT | wxBOTTOM       , 10 );
196   poSzrPulse->Add( &m_oPnlPulPeriod , oFlags );
197 
198   // Layout the button panel
199   oFlags.Align( wxALIGN_RIGHT  );
200   oFlags.Border( wxTOP | wxBOTTOM, 10 );
201   poSzrBtns->Add( &m_oBtnOk    , oFlags );
202   poSzrBtns->AddSpacer( 10 );
203   oFlags.Align( wxALIGN_CENTER );
204   poSzrBtns->Add( &m_oBtnClear , oFlags );
205   poSzrBtns->AddSpacer( 10 );
206   oFlags.Align( wxALIGN_LEFT   );
207   poSzrBtns->Add( &m_oBtnCancel, oFlags );
208 
209   // Layout the underlying dialog
210   oFlags.Align( wxALIGN_CENTER );
211   oFlags.Border( wxTOP | wxLEFT | wxRIGHT, 15 );
212   poSzrDlg->Add( poPnlSine , oFlags );
213   oFlags.Border( wxALL                   , 15 );
214   poSzrDlg->Add( poPnlPulse, oFlags );
215   oFlags.Align( wxALIGN_CENTER );
216   oFlags.Border( wxBOTTOM                , 15 );
217   poSzrDlg->Add( poPnlBtns , oFlags );
218 
219   // Set dialogues minimum size and initial size as calculated by the sizer
220   poSzrSine ->SetSizeHints( poPnlSine  );
221   poSzrPulse->SetSizeHints( poPnlPulse );
222   poSzrBtns ->SetSizeHints( poPnlBtns  );
223   poSzrDlg  ->SetSizeHints( this       );
224 }
225 
226 //**************************************************************************************************
227 // Set the values in the value panel controls.
228 //
229 // Argument List :
230 //   roCpntSrc - A reference to an independent source component object
231 
SetValues(CpntNgsIndSrc & roCpntSrc)232 void  DlgNgsCfgSrc::SetValues( CpntNgsIndSrc & roCpntSrc )
233 {
234   SetEvtHandlerEnabled( false );
235 
236   m_oPnlSinAmp    .bSetValue( roCpntSrc.m_osSinAmp     );
237   m_oPnlSinFreq   .bSetValue( roCpntSrc.m_osSinFreq    );
238   m_oPnlSinOffset .bSetValue( roCpntSrc.m_osSinOffset  );
239   m_oPnlSinDelay  .bSetValue( roCpntSrc.m_osSinDelay   );
240   m_oPnlSinDamp   .bSetValue( roCpntSrc.m_osSinDamp    );
241 
242   m_oPnlPulInitial.bSetValue( roCpntSrc.m_osPulInitial );
243   m_oPnlPulMax    .bSetValue( roCpntSrc.m_osPulMax     );
244   m_oPnlPulDelay  .bSetValue( roCpntSrc.m_osPulDelay   );
245   m_oPnlPulRise   .bSetValue( roCpntSrc.m_osPulRise    );
246   m_oPnlPulWidth  .bSetValue( roCpntSrc.m_osPulWidth   );
247   m_oPnlPulFall   .bSetValue( roCpntSrc.m_osPulFall    );
248   m_oPnlPulPeriod .bSetValue( roCpntSrc.m_osPulPeriod  );
249 
250   SetEvtHandlerEnabled( true );
251 }
252 
253 //**************************************************************************************************
254 // Get the values from the value panel controls.
255 //
256 // Argument List :
257 //   roCpntSrc - A reference to an independent source component object
258 
GetValues(CpntNgsIndSrc & roCpntSrc)259 void  DlgNgsCfgSrc::GetValues( CpntNgsIndSrc & roCpntSrc )
260 {
261   SetEvtHandlerEnabled( false );
262 
263   roCpntSrc.m_osSinAmp     = m_oPnlSinAmp    .rosGetValue( );
264   roCpntSrc.m_osSinFreq    = m_oPnlSinFreq   .rosGetValue( );
265   roCpntSrc.m_osSinOffset  = m_oPnlSinOffset .rosGetValue( );
266   roCpntSrc.m_osSinDelay   = m_oPnlSinDelay  .rosGetValue( );
267   roCpntSrc.m_osSinDamp    = m_oPnlSinDamp   .rosGetValue( );
268 
269   roCpntSrc.m_osPulInitial = m_oPnlPulInitial.rosGetValue( );
270   roCpntSrc.m_osPulMax     = m_oPnlPulMax    .rosGetValue( );
271   roCpntSrc.m_osPulDelay   = m_oPnlPulDelay  .rosGetValue( );
272   roCpntSrc.m_osPulRise    = m_oPnlPulRise   .rosGetValue( );
273   roCpntSrc.m_osPulWidth   = m_oPnlPulWidth  .rosGetValue( );
274   roCpntSrc.m_osPulFall    = m_oPnlPulFall   .rosGetValue( );
275   roCpntSrc.m_osPulPeriod  = m_oPnlPulPeriod .rosGetValue( );
276 
277   SetEvtHandlerEnabled( true );
278 }
279 
280 //**************************************************************************************************
281 // Set the source component name.
282 //
283 // Argument List :
284 //   rosName - The name of the source component
285 //
286 // Return Values :
287 //   true  - Success
288 //   false - Failure
289 
bSetName(wxString & rosName)290 bool  DlgNgsCfgSrc::bSetName( wxString & rosName )
291 {
292   eTypeCpnt  eCpnt;
293 
294   eCpnt = Component::eGetType( rosName );
295   if( eCpnt!=eCPNT_IVS && eCpnt!=eCPNT_ICS ) return( false );
296 
297   m_oCpntIndSrc.bSetName( rosName );
298 
299   return( true );
300 }
301 
302 //**************************************************************************************************
303 // Reset all dialog settings to defaults.
304 //
305 // Return Values :
306 //   true  - Success
307 //   false - Failure
308 
bClear(void)309 bool  DlgNgsCfgSrc::bClear( void )
310 {
311   m_oCpntIndSrc.bClear( );
312 
313   SetValues( m_oCpntIndSrc );
314 
315   return( true );
316 }
317 
318 //**************************************************************************************************
319 // Set the values in the value panel controls.
320 //
321 // Argument List :
322 //   roCpntSrc - A reference to an independent source component object
323 //
324 // Return Values :
325 //   true  - Success
326 //   false - Failure
327 
bSetValues(CpntNgsIndSrc & roCpntSrc)328 bool  DlgNgsCfgSrc::bSetValues( CpntNgsIndSrc & roCpntSrc )
329 {
330   SetValues( roCpntSrc );
331   m_oCpntIndSrc = roCpntSrc;
332 
333   return( true );
334 }
335 
336 //**************************************************************************************************
337 // Get the values from the value panel controls.
338 //
339 // Argument List :
340 //   roCpntSrc - A reference to an independent source component object
341 //
342 // Return Values :
343 //   true  - Success
344 //   false - Failure
345 
bGetValues(CpntNgsIndSrc & roCpntSrc)346 bool  DlgNgsCfgSrc::bGetValues( CpntNgsIndSrc & roCpntSrc )
347 {
348   GetValues( roCpntSrc );
349 
350   return( true );
351 }
352 
353 //**************************************************************************************************
354 //                                         Event Handlers                                          *
355 //**************************************************************************************************
356 // OK button event handler.
357 //
358 // Argument List :
359 //   roEvtCmd - An object holding information about the event (not used)
360 
OnBtnOk(wxCommandEvent & WXUNUSED (roEvtCmd))361 void  DlgNgsCfgSrc::OnBtnOk( wxCommandEvent & WXUNUSED( roEvtCmd ) )
362 {
363   GetValues( m_oCpntIndSrc );
364   EndModal( wxID_OK );
365 }
366 
367 //**************************************************************************************************
368 // Clear button event handler.
369 //
370 // Argument List :
371 //   roEvtCmd - An object holding information about the event (not used)
372 
OnBtnClear(wxCommandEvent & WXUNUSED (roEvtCmd))373 void  DlgNgsCfgSrc::OnBtnClear( wxCommandEvent & WXUNUSED( roEvtCmd ) )
374 {
375   CpntNgsIndSrc  oCpntIndSrc;
376 
377   oCpntIndSrc.bClear( );
378   SetValues( oCpntIndSrc );
379 }
380 
381 //**************************************************************************************************
382 // Cancel button event handler.
383 //
384 // Argument List :
385 //   roEvtCmd - An object holding information about the event (not used)
386 
OnBtnCancel(wxCommandEvent & WXUNUSED (roEvtCmd))387 void  DlgNgsCfgSrc::OnBtnCancel( wxCommandEvent & WXUNUSED( roEvtCmd ) )
388 {
389   SetValues( m_oCpntIndSrc );
390   EndModal( wxID_CANCEL );
391 }
392 
393 //**************************************************************************************************
394