KiCad PCB EDA Suite
pcb_calculator_frame.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-2015 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 #include <wx/wx.h>
21 
22 #include <bitmaps.h>
24 #include <kiface_i.h>
25 
27 #include "class_regulator_data.h"
28 #include "pcb_calculator_frame.h"
30 
31 // extension of pcb_calculator data filename:
32 const wxString DataFileNameExt( wxT("pcbcalc") );
33 
34 PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
35  PCB_CALCULATOR_FRAME_BASE( aParent )
36 {
37  SetKiway( this, aKiway );
41  m_RegulatorListChanged = false;
43  m_TWNested = false;
44 
45  SHAPE_POLY_SET dummy; // A ugly trick to force the linker to include
46  // some methods in code and avoid link errors
47 
48  // Populate transline list ordered like in dialog menu list
49  const static TRANSLINE_TYPE_ID tltype_list[8] =
50  {
54  };
55 
56  for( int ii = 0; ii < 8; ii++ )
57  m_transline_list.push_back( new TRANSLINE_IDENT( tltype_list[ii] ) );
58 
59  // Populate attenuator list ordered like in dialog menu list
60  m_attenuator_list.push_back( new ATTENUATOR_PI() );
61  m_attenuator_list.push_back( new ATTENUATOR_TEE() );
62  m_attenuator_list.push_back( new ATTENUATOR_BRIDGE() );
63  m_attenuator_list.push_back( new ATTENUATOR_SPLITTER() );
65 
66  LoadSettings( config() );
67 
68  ReadDataFile();
69 
72 
73  TW_Init(); // Track Width
74  VS_Init(); // Via Size
75  ES_Init(); // E-Series
76 
77  SetAttenuator( m_AttenuatorsSelection->GetSelection() );
78 
79  ToleranceSelection( m_rbToleranceSelection->GetSelection() );
80 
82 
84 
87 
88  // Give an icon
89  wxIcon icon;
90  icon.CopyFromBitmap( KiBitmap( icon_pcbcalculator_xpm ) );
91  SetIcon( icon );
92 
93  GetSizer()->SetSizeHints( this );
94 
95  // Set previous size and position
96  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
97 
98  if( m_FramePos == wxDefaultPosition )
99  Centre();
100 }
101 
102 
104 {
105  for( unsigned ii = 0; ii < m_transline_list.size(); ii++ )
106  delete m_transline_list[ii];
107 
108  for( unsigned ii = 0; ii < m_attenuator_list.size(); ii++ )
109  delete m_attenuator_list[ii];
110 
111  /* This needed for OSX: avoids furter OnDraw processing after this
112  * destructor and before the native window is destroyed
113  */
114  this->Freeze();
115 }
116 
117 
118 void PCB_CALCULATOR_FRAME::OnClosePcbCalc( wxCloseEvent& event )
119 {
121  {
122  if( GetDataFilename().IsEmpty() )
123  {
124  int opt = wxMessageBox(
125  _("Data modified, and no data filename to save modifications\n"\
126  "Do you want to exit and abandon your change?"),
127  _("Regulator list change"),
128  wxYES_NO | wxICON_QUESTION );
129 
130  if( opt == wxNO )
131  return;
132  }
133  else
134  {
135  if( !WriteDataFile() )
136  {
137  wxString msg;
138  msg.Printf( _("Unable to write file \"%s\"\n"\
139  "Do you want to exit and abandon your change?"),
140  GetDataFilename() );
141 
142  int opt = wxMessageBox( msg, _("Write Data File Error"),
143  wxYES_NO | wxICON_ERROR );
144  if( opt == wxNO )
145  return;
146  }
147  }
148  }
149 
150  event.Skip();
151 // Destroy();
152 }
153 
155 {
156  if( aCfg == NULL )
157  return;
158 
160 
161  PCB_CALCULATOR_SETTINGS* cfg = static_cast<PCB_CALCULATOR_SETTINGS*>( aCfg );
162 
163  m_currTransLineType = static_cast<TRANSLINE_TYPE_ID>( cfg->m_TransLine.type );
164  m_Notebook->ChangeSelection( cfg->m_LastPage );
165  m_rbToleranceSelection->SetSelection( cfg->m_ColorCodeTolerance );
166  m_AttenuatorsSelection->SetSelection( cfg->m_Attenuators.type );
167  m_BoardClassesUnitsSelector->SetSelection( cfg->m_BoardClassUnits );
168 
169  // Regul panel config:
170  m_RegulR1Value->SetValue( cfg->m_Regulators.r1 );
171  m_RegulR2Value->SetValue( cfg->m_Regulators.r2 );
172  m_RegulVrefValue->SetValue( cfg->m_Regulators.vref );
173  m_RegulVoutValue->SetValue( cfg->m_Regulators.vout );
176  m_choiceRegType->SetSelection( cfg->m_Regulators.type );
177 
178  wxRadioButton* regprms[3] = { m_rbRegulR1, m_rbRegulR2, m_rbRegulVout };
179 
180  if( cfg->m_Regulators.last_param >= 3 )
181  cfg->m_Regulators.last_param = 0;
182 
183  for( int ii = 0; ii < 3; ii++ )
184  regprms[ii]->SetValue( cfg->m_Regulators.last_param == ii );
185 
186  // Electrical panel config
189 
190  for( auto& transline : m_transline_list )
191  transline->ReadConfig();
192 
193  for( auto& attenuator : m_attenuator_list )
194  attenuator->ReadConfig();
195 }
196 
197 
199 {
200  if( aCfg == NULL )
201  return;
202 
204 
205  // Save current parameters values in config.
206  auto cfg = dynamic_cast<PCB_CALCULATOR_SETTINGS*>( Kiface().KifaceSettings() );
207 
208  if( cfg )
209  {
210  cfg->m_LastPage = m_Notebook->GetSelection();
211  cfg->m_TransLine.type = m_currTransLineType;
212  cfg->m_Attenuators.type = m_AttenuatorsSelection->GetSelection();
213  cfg->m_ColorCodeTolerance = m_rbToleranceSelection->GetSelection();
214  cfg->m_BoardClassUnits = m_BoardClassesUnitsSelector->GetSelection();
215 
216  cfg->m_Electrical.spacing_units = m_ElectricalSpacingUnitsSelector->GetSelection();
217  cfg->m_Electrical.spacing_voltage = m_ElectricalSpacingVoltage->GetValue();
218 
219  Regulators_WriteConfig( cfg );
220  }
221 
222  TW_WriteConfig();
223 
224  VS_WriteConfig();
225 
226  for( unsigned ii = 0; ii < m_transline_list.size(); ii++ )
227  m_transline_list[ii]->WriteConfig();
228 
229  for( unsigned ii = 0; ii < m_attenuator_list.size(); ii++ )
230  m_attenuator_list[ii]->WriteConfig();
231 }
232 
233 
239 void PCB_CALCULATOR_FRAME::OnTranslineAnalyse( wxCommandEvent& event )
240 {
241  if( m_currTransLine )
242  {
245  }
246 }
247 
248 
254 void PCB_CALCULATOR_FRAME::OnTranslineSynthetize( wxCommandEvent& event )
255 {
256  if( m_currTransLine )
257  {
260  }
261 }
262 
263 
265 {
266  wxPaintDC dc( m_panelDisplayshape );
267 
269 
270  if( tr_ident )
271  {
272  wxSize size = m_panelDisplayshape->GetSize();
273  size.x -= tr_ident->m_Icon->GetWidth();
274  size.y -= tr_ident->m_Icon->GetHeight();
275  dc.DrawBitmap( *tr_ident->m_Icon, size.x / 2, size.y / 2 );
276  }
277 
278  event.Skip();
279 }
280 
281 /* returns the full filename of the selected pcb_calculator data file
282  * the extension file is forced
283  */
285 {
286  if( m_regulators_fileNameCtrl->GetValue().IsEmpty() )
287  return wxEmptyString;
288 
289  wxFileName fn( m_regulators_fileNameCtrl->GetValue() );
290  fn.SetExt( DataFileNameExt );
291  return fn.GetFullPath();
292 }
293 
294 /* Initialize the full filename of the selected pcb_calculator data file
295  * force the standard extension of the file (.pcbcalc)
296  * aFilename = the full filename, with or without extension
297  */
298 void PCB_CALCULATOR_FRAME::SetDataFilename( const wxString & aFilename)
299 {
300  if( aFilename.IsEmpty() )
301  m_regulators_fileNameCtrl->SetValue( wxEmptyString );
302 
303  else
304  {
305  wxFileName fn( aFilename );
306  fn.SetExt( DataFileNameExt );
307  m_regulators_fileNameCtrl->SetValue( fn.GetFullPath() );
308  }
309 }
void ToleranceSelection(int aSelection)
Definition: colorcode.cpp:32
void ES_Init(void)
E-Series Resistor calculator Panel Called on calculator start to display markdown formula explanation...
Definition: eserie.cpp:422
void VS_WriteConfig()
Function VS_WriteConfig Write Via Size parameters in config.
void SetKiway(wxWindow *aDest, KIWAY *aKiway)
Function SetKiway.
wxBitmap * m_Icon
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
virtual void SaveSettings(APP_SETTINGS_BASE *aCfg)
Saves common frame parameters to a configuration data file.
PCB_CALCULATOR_FRAME(KIWAY *aKiway, wxWindow *aParent)
void VS_Init()
Function VS_Init Read config and init dialog widgets values.
void OnPaintTranslinePanel(wxPaintEvent &event) override
const BITMAP_OPAQUE icon_pcbcalculator_xpm[1]
Class PCB_CALCULATOR_FRAME_BASE.
enum PCB_CALCULATOR_FRAME::@40 m_TWMode
void TW_Init()
Function TW_Init Read config and init dialog widgets values.
wxArrayString GetRegList()
void OnTranslineAnalyse(wxCommandEvent &event) override
Function OnTranslineAnalyse Run a new analyse for the current transline with current parameters and d...
const wxString GetDataFilename()
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:82
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:99
#define NULL
void analyze()
Definition: transline.cpp:203
Contains structures for storage of regulator data.
SHAPE_POLY_SET.
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Saves common frame parameters to a configuration data file.
void TransfDlgDataToTranslineParams()
Function TransfDlgDataToTranslineParams Read values entered in dialog frame, and transfert these valu...
KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the s...
Definition: kiway.h:273
void OnTranslineSynthetize(wxCommandEvent &event) override
Function OnTranslineSynthetize Run a new synthezis for the current transline with current parameters ...
void OnClosePcbCalc(wxCloseEvent &event) override
enum TRANSLINE_TYPE_ID m_currTransLineType
TRANSLINE_TYPE_ID
void TranslineTypeSelection(enum TRANSLINE_TYPE_ID aType)
Function TranslineTypeSelection Must be called after selection of a new transline.
void TW_WriteConfig()
Function TW_WriteConfig Write Track width parameters in config.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void ElectricalSpacingUpdateData(double aUnitScale)
void SetDataFilename(const wxString &aFilename)
Initialize the full filename of the selected pcb_calculator data file force the standard extension of...
REGULATOR_LIST m_RegulatorList
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
const wxString DataFileNameExt(wxT("pcbcalc"))
#define _(s)
Definition: 3d_actions.cpp:33
virtual double GetUnitScale() override
Function GetUnitScale.
UNIT_SELECTOR_LEN * m_BoardClassesUnitsSelector
void SetAttenuator(unsigned aIdx)
Definition: attenuators.cpp:44
std::vector< TRANSLINE_IDENT * > m_transline_list
UNIT_SELECTOR_LEN * m_ElectricalSpacingUnitsSelector
virtual void synthesize()
Definition: transline.cpp:212
void Regulators_WriteConfig(PCB_CALCULATOR_SETTINGS *aCfg)
Write regulators parameters in config.
void SelectLastSelectedRegulator()
Function SelectLastSelectedRegulator select in choice box the last selected regulator (name in m_last...
void BoardClassesUpdateData(double aUnitScale)
virtual void LoadSettings(APP_SETTINGS_BASE *aCfg)
Load common frame parameters from a configuration file.
std::vector< ATTENUATOR * > m_attenuator_list