NbkGnuCap.cpp 13.3 KB
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 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
//**************************************************************************************************
//                                          NbkGnuCap.cpp                                          *
//                                         ---------------                                         *
// Started     : 2003-09-05                                                                        *
// Last Update : 2016-11-09                                                                        *
// Copyright   : (C) 2003-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 "NbkGnuCap.hpp"

//**************************************************************************************************
// Implement an event table.

wxBEGIN_EVENT_TABLE( NbkGnuCap, NbkSimEngBase )

  EVT_NOTEBOOK_PAGE_CHANGED( -1,          NbkGnuCap::OnPageChangd )

  EVT_BUTTON( PnlAnaBase::ID_BTN_OPTIONS, NbkGnuCap::OnBtnOptions )

wxEND_EVENT_TABLE( )

//**************************************************************************************************
// Constructor.
//
// Arguments:
//   poParent - The parent window
//   oWinID   - The display object ID
//   roPosn   - The notebook position
//   roSize   - The notebook size

NbkGnuCap::NbkGnuCap( wxWindow * poParent, wxWindowID oWinID )
                    : NbkSimEngBase( poParent, oWinID ), m_oDlgCfgOPT( poParent )
{
  // Set the simulator engine type specifier
  m_eSimEng = eSIMR_GNUCAP;

  // Create the various display objects
  m_poPnlGnuCapOP = new PnlGnuCapOP( this );
  m_poPnlGnuCapDC = new PnlGnuCapDC( this );
  m_poPnlGnuCapAC = new PnlGnuCapAC( this );
  m_poPnlGnuCapTR = new PnlGnuCapTR( this );
//  m_poPnlGnuCapFO = new PnlGnuCapFO( this );

  // Add the display objects to the note book
  AddPage( m_poPnlGnuCapOP, wxT( " Quiescent  "     ) );
  AddPage( m_poPnlGnuCapDC, wxT( "       DC       " ) );
  AddPage( m_poPnlGnuCapAC, wxT( "       AC       " ) );
  AddPage( m_poPnlGnuCapTR, wxT( "  Transient  "    ) );
//  AddPage( m_poPnlGnuCapFO, wxT( "   Fourier    "   ) );

  // Specify the default page to be displayed
  SetSelection( 0 );
}

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

NbkGnuCap::~NbkGnuCap( )
{
}

//**************************************************************************************************
// Clear the object attributes.
//
// Return Values:
//   true  - Success
//   false - Failure

bool  NbkGnuCap::bClear( void )
{
  bool  bRtn=true;

  // Clear the base class
  if( ! NbkSimEngBase  ::bClear( ) ) bRtn = false;

  if( ! m_poPnlGnuCapOP->bClear( ) ) bRtn = false;
  if( ! m_poPnlGnuCapDC->bClear( ) ) bRtn = false;
  if( ! m_poPnlGnuCapAC->bClear( ) ) bRtn = false;
  if( ! m_poPnlGnuCapTR->bClear( ) ) bRtn = false;
//  if( ! m_poPnlGnuCapFO->bClear( ) ) bRtn = false;

  if( ! m_oDlgCfgOPT    .bClear( ) ) bRtn = false;

  return( bRtn );
}

//**************************************************************************************************
// Load information from a simulation object.
//
// Argument List:
//   roSimn - The simulation object
//
// Return Values:
//   true  - Success
//   false - Failure

bool  NbkGnuCap::bLoad( const SimnBase & roSimn )
{
  bool    bRtn=true;
  size_t  sz1;

  if( roSimn.eGetSimEng( ) != eSIMR_GNUCAP )             return( false );

  PnlAnaBase::m_oCpntSwpSrc = roSimn.m_oCpntSwpSrc;

  SimnGnuCap & roSimnGcp = (SimnGnuCap &) roSimn;

  if( ! bSetPage( roSimnGcp.eGetAnaType( ) ) )           bRtn = false;

  sz1 = 0;
  if( m_poPnlGnuCapOP->bLoad( roSimnGcp ) ) sz1++;
  if( m_poPnlGnuCapDC->bLoad( roSimnGcp ) ) sz1++;
  if( m_poPnlGnuCapAC->bLoad( roSimnGcp ) ) sz1++;
  if( m_poPnlGnuCapTR->bLoad( roSimnGcp ) ) sz1++;
//  if( m_poPnlGnuCapFO->bLoad( roSimnGcp ) ) sz1++;
  if( sz1 == 0 )                                         bRtn = false;

  if( ! m_oDlgCfgOPT.bSetValues( roSimnGcp.m_oCmdOPT ) ) bRtn = false;

  return( bRtn );
}

//**************************************************************************************************
// Save information to a simulation object.
//
// Argument List:
//   roSimn - The simulation object
//
// Return Values:
//   true  - Success
//   false - Failure

bool  NbkGnuCap::bSave( SimnBase & roSimn )
{
  wxString  os1;

  // Only proceed if this is an GNU-Cap simulation object
  if( roSimn.eGetSimEng( ) != eSIMR_GNUCAP ) return( false );

  SimnGnuCap & roSimnGcp = (SimnGnuCap &) roSimn;

  // Clear the error string
  NbkSimEngBase::m_osErrMsg.Empty( );

  // Create the analysis command/s
  switch( GetSelection( ) )
  {
    case 0 : // OP analysis
      if( m_poPnlGnuCapOP->bSave( roSimnGcp ) )
           os1.Empty( );
      else SetErrMsg( m_poPnlGnuCapOP->rosGetErrMsg( ) );
      break;

    case 1 : // DC analysis
      if( m_poPnlGnuCapDC->bSave( roSimnGcp ) )
           os1 = roSimnGcp.m_oCmdDC.m_osTempC;
      else SetErrMsg( m_poPnlGnuCapDC->rosGetErrMsg( ) );
      break;

    case 2 : // AC analysis
      if( m_poPnlGnuCapAC->bSave( roSimnGcp ) )
           os1 = roSimnGcp.m_oCmdAC.m_osTempC;
      else SetErrMsg( m_poPnlGnuCapAC->rosGetErrMsg( ) );
      break;

    case 3 : // TR analysis
      if( m_poPnlGnuCapTR->bSave( roSimnGcp ) )
           os1 = roSimnGcp.m_oCmdTR.m_osTempC;
      else SetErrMsg( m_poPnlGnuCapTR->rosGetErrMsg( ) );
      break;

//    case 4 : // FO analysis
//      if( m_poPnlGnuCapFO->bSave( roSimnGcp ) )
//           os1 = roSimnGcp.m_oCmdFO.m_osTempC;
//      else SetErrMsg( m_poPnlGnuCapFO->rosGetErrMsg( ) );
//      break;

    default:                                 return( false );
  }
  if( ! bIsOk( ) )                           return( false );

  // Create the OPTIONS command
  m_oDlgCfgOPT.bGetValues( roSimnGcp.m_oCmdOPT );
  if( ! os1.IsEmpty( ) ) roSimnGcp.m_oCmdOPT.m_osTEMP = os1;
  roSimnGcp.m_oCmdOPT.bFormat( );
  if( ! roSimnGcp.m_oCmdOPT.bIsValid( ) )
  {
    os1 = wxT("OPTIONS command fault :\n\n  ");
    SetErrMsg( os1 + roSimnGcp.m_oCmdOPT.rosGetErrMsg( ) );
    return( false );
  }

  return( true );
}

//**************************************************************************************************
// Set the page to be displayed.
//
// Argument List:
//   eCmdType - The enumerated analysis type specifier
//
// Return Values:
//   true  - Success
//   false - Failure

bool  NbkGnuCap::bSetPage( eTypeCmd eAnalysis )
{
  int  iPage;

  switch( eAnalysis )
  {
    case eCMD_OP   : iPage = 0; break;
    case eCMD_DC   : iPage = 1; break;
    case eCMD_AC   : iPage = 2; break;
    case eCMD_TR   : iPage = 3; break;
//    case eCMD_FO   : iPage = 4; break;
    default        : return( false );
  }

  SetSelection( iPage ); // Specify the page to be displayed

  return( true );
}

//**************************************************************************************************
// Set the page to be displayed.
//
// Argument List:
//   rosAnalysis - The two letter analysis type specifier (case ignored)
//
// Return Values:
//   true  - Success
//   false - Failure

bool  NbkGnuCap::bSetPage( const wxString & rosAnalysis )
{
  eTypeCmd  eAnalysis=eCMD_NONE;
  wxString  os1;

  os1 = rosAnalysis.Upper( );

  if( os1.Length( ) == 2 )
  {
    if(      os1 == wxT("OP") ) eAnalysis = eCMD_OP;
    else if( os1 == wxT("DC") ) eAnalysis = eCMD_DC;
    else if( os1 == wxT("AC") ) eAnalysis = eCMD_AC;
    else if( os1 == wxT("TR") ) eAnalysis = eCMD_TR;
//    else if( os1 == wxT("FO") ) eAnalysis = eCMD_FO;
//    else if( os1 == wxT("DI") ) eAnalysis = eCMD_DI;
//    else if( os1 == wxT("NO") ) eAnalysis = eCMD_NO;
//    else if( os1 == wxT("PZ") ) eAnalysis = eCMD_PZ;
//    else if( os1 == wxT("SE") ) eAnalysis = eCMD_SE;
//    else if( os1 == wxT("TF") ) eAnalysis = eCMD_TF;
  }

  return( bSetPage( eAnalysis ) );
}

//**************************************************************************************************
// Get the two letter page specifier.
//
// Return Values:
//   Success - The two letter analysis type specifier (lower case)
//   Failure - An empty string

const wxString & NbkGnuCap::rosGetPage( void )
{
  static  wxString  osAnalysis;

  switch( eGetPage( ) )
  {
    case eCMD_OP : osAnalysis = wxT("op"); break;
    case eCMD_DC : osAnalysis = wxT("dc"); break;
    case eCMD_AC : osAnalysis = wxT("ac"); break;
    case eCMD_TR : osAnalysis = wxT("tr"); break;
//    case eCMD_FO : osAnalysis = wxT("fo"); break;
    default      : osAnalysis.Empty( );
  }

  return( osAnalysis );
}

//**************************************************************************************************
// Get the enumerated page specifier.
//
// Return Values:
//   Success - The enumerated analysis specifier
//   Failure - eCMD_NONE

eTypeCmd  NbkGnuCap::eGetPage( void )
{
  eTypeCmd  eAnalysis;

  switch( GetSelection( ) )
  {
    case  0 : eAnalysis = eCMD_OP; break;
    case  1 : eAnalysis = eCMD_DC; break;
    case  2 : eAnalysis = eCMD_AC; break;
    case  3 : eAnalysis = eCMD_TR; break;
//    case  4 : eAnalysis = eCMD_FO; break;
    default : eAnalysis = eCMD_NONE;
  }

  return( eAnalysis );
}

//**************************************************************************************************
//                                         Event Handlers                                          *
//**************************************************************************************************
// This event is generated when a notebook page has just changed.
//
// Argument List:
//   roEvtNbk - An object holding information about the event

void  NbkGnuCap::OnPageChangd( wxNotebookEvent & roEvtNbk )
{
  PnlAnaBase * poPnlAna;
  wxString     os1;
  int          i1;

  // Synchronize the ambient temperature values between the different analysis pages
  if( g_oConfig.bGetSyncTemps( ) )
  {
    // Transfer the ambient temperature from the previous page to the OPTIONS dialog
    i1 = roEvtNbk.GetOldSelection( );
    if( i1 != wxNOT_FOUND )
    {
      poPnlAna = (PnlAnaBase *) GetPage( (size_t) i1 );
      if( poPnlAna->m_oPnlTemp.GetParent( ) != NULL )
      {
        os1 = poPnlAna->m_oPnlTemp.rosGetValue( );
        m_oDlgCfgOPT.bSetValue( DlgGcpCfgOPT::ID_PNL_TEMP, os1 );
      }
    }

    // Transfer the ambient temperature from the OPTIONS dialog to current page
    poPnlAna = (PnlAnaBase *) GetCurrentPage( );
    if( poPnlAna->m_oPnlTemp.GetParent( ) != NULL )
    {
      os1 = m_oDlgCfgOPT.rosGetValue( DlgGcpCfgOPT::ID_PNL_TEMP );
      poPnlAna->m_oPnlTemp.bSetValue( os1 );
    }
  }

  // Synchronize the sweep sources between the different analysis pages
  if( g_oConfig.bGetSyncSwpSrcs( ) )
  {
    os1 = poPnlAna->m_oCpntSwpSrc.rosGetName( );

    if( poPnlAna->m_oChoSrcName.SetStringSelection( os1 ) )
    { // Set the sweep source value if it's been defined
      if( poPnlAna->m_oPnlSrcLvl.GetParent( ) != NULL )
      {
        poPnlAna->m_oPnlSrcLvl.bSetUnitsType( poPnlAna->m_oCpntSwpSrc.eGetUnitsType( ) );
        poPnlAna->m_oPnlSrcLvl.bSetValue( poPnlAna->m_oCpntSwpSrc.rosGetValue ( ) );
      }
    }
    else
    { // Couldn't set the sweep source name so clear it
      poPnlAna->m_oChoSrcName.SetSelection( 0 );
      if( poPnlAna->m_oPnlSrcLvl.GetParent( ) != NULL )
      {
        poPnlAna->m_oPnlSrcLvl.bSetUnitsType( eUNITS_NONE );
        poPnlAna->m_oPnlSrcLvl.bSetValue( 0.0 );
      }
    }

    // Update the sweep parameter units
    if( poPnlAna->eGetAnalysType( ) == eCMD_DC )
      m_poPnlGnuCapDC->OnSrcName( (wxCommandEvent &) roEvtNbk );
  }

  // Allow additional event handlers to be called
  roEvtNbk.Skip( );
}

//**************************************************************************************************
// Setup .OPTIONS command button event handler.
//
// Argument List:
//   roEvtCmd - An object holding information about the event

void  NbkGnuCap::OnBtnOptions( wxCommandEvent & roEvtCmd )
{
  PnlAnaBase * poPnlAna;
  wxString     os1;
  int          i1;

  // Get a pointer to the currently displayed analysis page
  poPnlAna = (PnlAnaBase *) GetCurrentPage( );
  if( poPnlAna == NULL ) return;

  // Set the temperature in the OPTIONS dialog
  if( poPnlAna->m_oPnlTemp.GetParent( ) != NULL )
  {
    os1 = poPnlAna->m_oPnlTemp.rosGetValue( );
    m_oDlgCfgOPT.bSetValue( DlgGcpCfgOPT::ID_PNL_TEMP, os1 );
  }

  // Display the OPTIONS dialog
  m_oDlgCfgOPT.CenterOnParent( );
  i1 = m_oDlgCfgOPT.ShowModal( );
  if( i1 != wxID_OK )    return;

  // Set the temperature in the analysis panel
  if( poPnlAna->m_oPnlTemp.GetParent( ) != NULL )
  {
    os1 = m_oDlgCfgOPT.rosGetValue( DlgGcpCfgOPT::ID_PNL_TEMP );
    poPnlAna->m_oPnlTemp.bSetValue( os1 );
  }
}

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