Blame view

GUI/SW2/SRC/src/tests/AppPnlValue.cpp 9.49 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
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
//**************************************************************************************************
//                                        AppPnlValue.cpp                                          *
//                                       -----------------                                         *
// Started     : 2014-11-17                                                                        *
// Last Update : 2015-01-24                                                                        *
// Copyright   : (C) 2014-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 "AppPnlValue.hpp"

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

wxIMPLEMENT_APP( AppPnlValue );

wxBEGIN_EVENT_TABLE( FrmMain, wxFrame )

  EVT_MENU  ( FrmMain::ID_BTN_NEXT, FrmMain::OnNext  )
  EVT_MENU  (        wxID_EXIT    , FrmMain::OnExit  )
  EVT_MENU  (        wxID_ABOUT   , FrmMain::OnAbout )

  EVT_BUTTON( FrmMain::ID_BTN_NEXT, FrmMain::OnNext  )
  EVT_BUTTON( FrmMain::ID_BTN_READ, FrmMain::OnRead  )
  EVT_BUTTON( FrmMain::ID_BTN_QUIT, FrmMain::OnExit  )

wxEND_EVENT_TABLE( )

//**************************************************************************************************
//                                    Class AppPnlValue
//**************************************************************************************************

bool  AppPnlValue::OnInit( )
{
  FrmMain * poFrmMain = new FrmMain( wxT("test_AppPnlValue"), wxPoint( 83, 83 ), wxDefaultSize );

  poFrmMain->Show( true );

  return( true );
}

//**************************************************************************************************
//                                    Class FrmMain
//**************************************************************************************************

FrmMain::FrmMain( const wxString & osTitle, const wxPoint & oPosn, const wxSize & oSize )
                : wxFrame( NULL, wxID_ANY, osTitle, oPosn, oSize )
{
  wxCommandEvent  oNonEvent;

  // Create the GUI
  Create( );
  DoLayout( );

  // Load test values
  oVecTests.push_back( wxT("10.0E-12F") ); // Working 2015-01-24
  oVecTests.push_back( wxT("1.0V")      ); // Working 2015-01-24
  oVecTests.push_back( wxT("1000.0mV")  ); // Working 2015-01-24
  oVecTests.push_back( wxT("1.0fV")     ); // Working 2015-01-24
  oVecTests.push_back( wxT("0.0mV")     ); // Working 2015-01-24
  oVecTests.push_back( wxT("140mV")     ); // Working 2015-01-24
  oVecTests.push_back( wxT("1.0pA")     ); // Working 2015-01-24
  oVecTests.push_back( wxT("1.0E-12A")  ); // Working 2015-01-24
  oVecTests.push_back( wxT("1000GOhm")  ); // Working 2015-01-24
  oVecTests.push_back( wxT("1000Ohm")   ); // Working 2015-01-24
  oVecTests.push_back( wxT("10.0fC")    ); // Working 2015-01-24
  oVecTests.push_back( wxT("1234")      ); // Working 2015-01-24
  oVecTests.push_back( wxT("1.235")     ); // Working 2015-01-24
  oVecTests.push_back( wxT("1.0E-12")   ); // Working 2015-01-24

  // Load the first test value
  OnNext( oNonEvent );
}

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

void  FrmMain::Create( void )
{
  wxMenuBar * poMenuBar  = new wxMenuBar;
  wxMenu    * poMenuFile = new wxMenu;
  wxMenu    * poMenuHelp = new wxMenu;
  wxPanel   * poPnlMain  = new wxPanel( this );
  wxPanel   * poPnlCtls  = new wxPanel( poPnlMain );
  wxPanel   * poPnlBtns  = new wxPanel( poPnlMain );

  // Create the menu items
  poMenuFile->Append( ID_BTN_NEXT, wxT("&Next...\tCtrl-N") );
  poMenuFile->AppendSeparator( );
  poMenuFile->Append( wxID_EXIT );
  poMenuHelp->Append( wxID_ABOUT );

  // Create the menu bar
  poMenuBar->Append( poMenuFile, wxT("&File") );
  poMenuBar->Append( poMenuHelp, wxT("&Help") );
  SetMenuBar( poMenuBar );

  // Create the text control to contain the value written to the PnlValue test control
  m_oTxtInput.bCreate( poPnlCtls, ID_TXT_INPUT  , 150, 163 );
  m_oTxtInput.bSetName( wxT("PnlValue input value") );

  // Create the PnlValue test control
  m_oPnlValue.bCreate( poPnlCtls, ID_VAL_TEST   , 150, 90, 70 );
  m_oPnlValue.bSetName( wxT("PnlValue test control") );

  // Create the text control to contain the value read from the PnlValue test control
  m_oTxtOutput.bCreate( poPnlCtls, ID_TXT_OUTPUT, 150, 163 );
  m_oTxtOutput.bSetName( wxT("PnlValue output value") );

  // Create the button control
  m_oBtnNext.Create( poPnlBtns, ID_BTN_NEXT, wxT("Next") );
  m_oBtnRead.Create( poPnlBtns, ID_BTN_READ, wxT("Read") );
  m_oBtnQuit.Create( poPnlBtns, ID_BTN_QUIT, wxT("Quit") );
}

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

void  FrmMain::DoLayout( void )
{
  wxPanel     * poPnlCtls = (wxPanel *) m_oPnlValue.GetParent( );
  wxPanel     * poPnlBtns = (wxPanel *) m_oBtnNext .GetParent( );
  wxPanel     * poPnlMain = (wxPanel *) poPnlCtls ->GetParent( );
  wxBoxSizer  * poSzrMain = new wxBoxSizer      ( wxVERTICAL );
  wxBoxSizer  * poSzrCtls = new wxStaticBoxSizer( wxVERTICAL, poPnlCtls );
  wxBoxSizer  * poSzrBtns = new wxBoxSizer      ( wxHORIZONTAL );
  wxSizerFlags  oFlags;

  // Set the sizer
  poPnlMain->SetSizer( poSzrMain );
  poPnlCtls->SetSizer( poSzrCtls );
  poPnlBtns->SetSizer( poSzrBtns );

  // Layout the controls
  oFlags.Align( wxALIGN_LEFT );
  oFlags.Border( wxLEFT | wxRIGHT | wxTOP   , 10 );
  poSzrCtls->Add( &m_oTxtInput , oFlags );
  oFlags.Border( wxLEFT | wxRIGHT           , 10 );
  poSzrCtls->Add( &m_oPnlValue , oFlags );
  oFlags.Border( wxLEFT | wxRIGHT | wxBOTTOM, 10 );
  poSzrCtls->Add( &m_oTxtOutput, oFlags );

  // Layout the buttons
  oFlags.Border( wxTOP, 15 );
  oFlags.Align( wxALIGN_RIGHT );
  poSzrBtns->Add( &m_oBtnNext, oFlags );
  poSzrBtns->AddSpacer( 15 );
  oFlags.Align( wxALIGN_CENTER );
  poSzrBtns->Add( &m_oBtnRead, oFlags );
  poSzrBtns->AddSpacer( 15 );
  oFlags.Align( wxALIGN_LEFT );
  poSzrBtns->Add( &m_oBtnQuit, oFlags );

  // Layout the main frame
  oFlags.Border( wxLEFT | wxRIGHT | wxTOP, 15 );
  poSzrMain->Add( poPnlCtls, oFlags );
  oFlags.Border( wxBOTTOM                , 15 );
  oFlags.Align( wxALIGN_CENTER );
  poSzrMain->Add( poPnlBtns, oFlags );

  // Set minimum size and initial size as calculated by the sizer
  poSzrMain->SetSizeHints( this );
}

//**************************************************************************************************
//                                         Event Handlers                                          *
//**************************************************************************************************

void  FrmMain::OnNext( wxCommandEvent & roEvent )
{
  static  size_t      sz1=oVecTests.size( );
          eTypeUnits  eUType;
          wxString    os1;
          double      df1;

  // Increment the index to the next PnlValue value
  if( ++sz1 >= oVecTests.size( ) ) sz1 = 0;

  // Get the PnlValue value
  os1 = oVecTests[ sz1 ];

  // Set the new PnlValue contents
  m_oTxtInput.bSetText( os1 );

  // Decide how the PnlValue should configured to display this value
  m_oPnlValue.bClear( );
  if( UnitsBase::bGetUnitsType( os1, &eUType ) )
  { // Display a units choice box
    m_oPnlValue.bShowUnits( PnlValue::eSHOW_CHO );
    m_oPnlValue.bSetUnitsType( eUType );
  }
  else
  { // Display a units label
    m_oPnlValue.bShowUnits( PnlValue::eSHOW_LBL );
    if(      CnvtType::bIsInteger( os1 ) )
    { // Display the value as an integer
      m_oPnlValue.bSetValueType( eVALUE_INT );
      m_oPnlValue.bSetSpnRange( 0, 10000 );
      m_oPnlValue.bSetSpnIncSz( 1,  1000 );
    }
    else if( CnvtType::bIsFloat( os1 ) )
    { // Display the value as a float
      CnvtType::bStrToFlt( os1, &df1 );
      if( (df1>0.1 && df1<1000.0) || df1==0.0 )
           m_oPnlValue.bSetValueType( eVALUE_FLT );
      else m_oPnlValue.bSetValueType( eVALUE_SCI );
    }
  }

  // Display the value
  m_oPnlValue.bSetValue( os1 );
}

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

void  FrmMain::OnRead( wxCommandEvent & roEvent )
{
  m_oTxtOutput.bSetText( m_oPnlValue.rosGetValue( ) + m_oPnlValue.rosGetUnits( ) );
}

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

void  FrmMain::OnAbout( wxCommandEvent & roEvent )
{
  wxString os1;

  os1 << wxT("Test Application for : \n\n")
      << wxT("C++ class PnlValue and all  \n")
      << wxT("classes it makes use of.\n\n")
      << wxT("Version 1.07 (2015-01-19)");

  wxMessageBox( os1, wxT("About"), wxOK | wxICON_INFORMATION );
}

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

void  FrmMain::OnExit( wxCommandEvent & roEvent )
{
  Close( true );
}

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