KiCad PCB EDA Suite
dialog_regulator_form.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KICAD, a free EDA CAD application.
3  *
4  * Copyright (C) 1992-2011 jean-pierre.charras
5  * Copyright (C) 1992-2020 Kicad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include "class_regulator_data.h"
22 #include "pcb_calculator_frame.h"
23 #include "dialog_regulator_form.h"
24 
25 
26 extern double DoubleFromString( const wxString& TextValue );
27 
28 
29 void DIALOG_REGULATOR_FORM::OnOKClick( wxCommandEvent& event )
30 {
31  if( !IsOK() )
32  {
33  wxMessageBox( _( "Bad or missing parameters!" ) );
34  return;
35  }
36 
37  EndModal( wxID_OK );
38 }
39 
40 
42 {
43  bool success = true;
44 
45  if( m_textCtrlName->GetValue().IsEmpty() )
46  success = false;
47  if( m_textCtrlVref->GetValue().IsEmpty() )
48  success = false;
49  else
50  {
51  double vref = DoubleFromString( m_textCtrlVref->GetValue() );
52  if( fabs( vref ) < 0.01 )
53  success = false;
54  }
55  if( m_choiceRegType->GetSelection() == 1 )
56  {
57  if( m_RegulIadjValue->GetValue().IsEmpty() )
58  success = false;
59  }
60 
61  return success;
62 }
63 
64 
66 {
67  bool enbl = m_choiceRegType->GetSelection() == 1;
68  m_RegulIadjValue->Enable( enbl );
69 }
70 
71 
73 {
74  m_textCtrlName->SetValue( aItem->m_Name );
75  wxString value;
76  value.Printf( wxT( "%g" ), aItem->m_Vref );
77  m_textCtrlVref->SetValue( value );
78  value.Printf( wxT( "%g" ), aItem->m_Iadj );
79  m_RegulIadjValue->SetValue( value );
80  m_choiceRegType->SetSelection( aItem->m_Type );
81  UpdateDialog();
82 }
83 
84 
86 {
87  double vref = DoubleFromString( m_textCtrlVref->GetValue() );
88  double iadj = DoubleFromString( m_RegulIadjValue->GetValue() );
89  int type = m_choiceRegType->GetSelection();
90 
91  if( type != 1 )
92  iadj = 0.0;
93 
94  REGULATOR_DATA* item = new REGULATOR_DATA( m_textCtrlName->GetValue(), vref, type, iadj );
95  return item;
96 }
REGULATOR_DATA * BuildRegulatorFromData()
Function BuildRegulatorFromData Creates a new REGULATOR_DATA from dialog.
void UpdateDialog()
Enable/disable Iadj realted widgets, according to the regulator type.
Contains structures for storage of regulator data.
double DoubleFromString(const wxString &TextValue)
#define _(s)
Definition: 3d_actions.cpp:33
void OnOKClick(wxCommandEvent &event) override
void CopyRegulatorDataToDialog(REGULATOR_DATA *aItem)
Function CopyRegulatorDataToDialog Transfert data from dialog to aItem.
bool IsOK()
Function IsOK()
Subclass of DIALOG_REGULATOR_FORM_BASE, which is generated by wxFormBuilder.