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-2015 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 <pgm_base.h>
23 #include <pcb_calculator.h>
25 #include <UnitSelector.h>
26 #include <bitmaps.h>
28 
29 
30 // extension of pcb_calculator data filename:
31 const wxString DataFileNameExt( wxT("pcbcalc") );
32 
33 PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
34  PCB_CALCULATOR_FRAME_BASE( aParent )
35 {
36  SetKiway( this, aKiway );
40  m_RegulatorListChanged = false;
42  m_TWNested = false;
43 
44  SHAPE_POLY_SET dummy; // A ugly trick to force the linker to include
45  // some methods in code and avoid link errors
46 
47  // Populate transline list ordered like in dialog menu list
48  const static TRANSLINE_TYPE_ID tltype_list[8] =
49  {
53  };
54 
55  for( int ii = 0; ii < 8; ii++ )
56  m_transline_list.push_back( new TRANSLINE_IDENT( tltype_list[ii] ) );
57 
58  // Populate attenuator list ordered like in dialog menu list
59  m_attenuator_list.push_back( new ATTENUATOR_PI() );
60  m_attenuator_list.push_back( new ATTENUATOR_TEE() );
61  m_attenuator_list.push_back( new ATTENUATOR_BRIDGE() );
62  m_attenuator_list.push_back( new ATTENUATOR_SPLITTER() );
64 
65  LoadSettings( config() );
66 
67  ReadDataFile();
68 
71 
72  TW_Init();
73  VS_Init();
74 
75  SetAttenuator( m_AttenuatorsSelection->GetSelection() );
76 
77  ToleranceSelection( m_rbToleranceSelection->GetSelection() );
78 
80 
82 
85 
86  // Give an icon
87  wxIcon icon;
88  icon.CopyFromBitmap( KiBitmap( icon_pcbcalculator_xpm ) );
89  SetIcon( icon );
90 
91  GetSizer()->SetSizeHints( this );
92 
93  // Set previous size and position
94  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
95 
96  if( m_FramePos == wxDefaultPosition )
97  Centre();
98 }
99 
100 
102 {
103  for( unsigned ii = 0; ii < m_transline_list.size(); ii++ )
104  delete m_transline_list[ii];
105 
106  for( unsigned ii = 0; ii < m_attenuator_list.size(); ii++ )
107  delete m_attenuator_list[ii];
108 
109  /* This needed for OSX: avoids furter OnDraw processing after this
110  * destructor and before the native window is destroyed
111  */
112  this->Freeze();
113 }
114 
115 
116 void PCB_CALCULATOR_FRAME::OnClosePcbCalc( wxCloseEvent& event )
117 {
119  {
120  if( GetDataFilename().IsEmpty() )
121  {
122  int opt = wxMessageBox(
123  _("Data modified, and no data filename to save modifications\n"\
124  "Do you want to exit and abandon your change?"),
125  _("Regulator list change"),
126  wxYES_NO | wxICON_QUESTION );
127 
128  if( opt == wxNO )
129  return;
130  }
131  else
132  {
133  if( !WriteDataFile() )
134  {
135  wxString msg;
136  msg.Printf( _("Unable to write file \"%s\"\n"\
137  "Do you want to exit and abandon your change?"),
138  GetDataFilename().c_str() );
139 
140  int opt = wxMessageBox( msg, _("Write Data File Error"),
141  wxYES_NO | wxICON_ERROR );
142  if( opt == wxNO )
143  return;
144  }
145  }
146  }
147 
148  event.Skip();
149 // Destroy();
150 }
151 
153 {
154  if( aCfg == NULL )
155  return;
156 
158 
159  auto cfg = static_cast<PCB_CALCULATOR_SETTINGS*>( aCfg );
160 
161  m_currTransLineType = static_cast<TRANSLINE_TYPE_ID>( cfg->m_TransLine.type );
162  m_Notebook->ChangeSelection( cfg->m_LastPage );
163  m_rbToleranceSelection->SetSelection( cfg->m_ColorCodeTolerance );
164  m_AttenuatorsSelection->SetSelection( cfg->m_Attenuators.type );
165  m_BoardClassesUnitsSelector->SetSelection( cfg->m_BoardClassUnits );
166 
167  // Regul panel config:
168  m_RegulR1Value->SetValue( cfg->m_Regulators.r1 );
169  m_RegulR2Value->SetValue( cfg->m_Regulators.r2 );
170  m_RegulVrefValue->SetValue( cfg->m_Regulators.vref );
171  m_RegulVoutValue->SetValue( cfg->m_Regulators.vout );
172  SetDataFilename( cfg->m_Regulators.data_file );
173  m_lastSelectedRegulatorName = cfg->m_Regulators.selected_regulator;
174  m_choiceRegType->SetSelection( cfg->m_Regulators.type );
175 
176  wxRadioButton* regprms[3] = { m_rbRegulR1, m_rbRegulR2, m_rbRegulVout };
177 
178  if( cfg->m_Regulators.last_param >= 3 )
179  cfg->m_Regulators.last_param = 0;
180 
181  for( int ii = 0; ii < 3; ii++ )
182  regprms[ii]->SetValue( cfg->m_Regulators.last_param == ii );
183 
184  // Electrical panel config
185  m_ElectricalSpacingUnitsSelector->SetSelection( cfg->m_Electrical.spacing_units );
186  m_ElectricalSpacingVoltage->SetValue( cfg->m_Electrical.spacing_voltage );
187 
188  for( auto& transline : m_transline_list )
189  transline->ReadConfig();
190 
191  for( auto& attenuator : m_attenuator_list )
192  attenuator->ReadConfig();
193 }
194 
195 
197 {
198  if( aCfg == NULL )
199  return;
200 
202 
203 #if 0
204  aCfg->Write( KEYWORD_TRANSLINE_SELECTION, (long) m_currTransLineType );
205  aCfg->Write( KEYWORD_PAGE_SELECTION, m_Notebook->GetSelection() );
206  aCfg->Write( KEYWORD_COLORCODE_SELECTION, m_rbToleranceSelection->GetSelection() );
207  aCfg->Write( KEYWORD_ATTENUATORS_SELECTION, m_AttenuatorsSelection->GetSelection() );
208  aCfg->Write( KEYWORD_BRDCLASS_SELECTION, m_BoardClassesUnitsSelector->GetSelection() );
209 
210  aCfg->Write( KEYWORD_REGUL_R1, m_RegulR1Value->GetValue() );
211  aCfg->Write( KEYWORD_REGUL_R2, m_RegulR2Value->GetValue() );
212  aCfg->Write( KEYWORD_REGUL_VREF, m_RegulVrefValue->GetValue() );
213  aCfg->Write( KEYWORD_REGUL_VOUT, m_RegulVoutValue->GetValue() );
214  aCfg->Write( KEYWORD_DATAFILE_FILENAME, GetDataFilename() );
215  aCfg->Write( KEYWORD_REGUL_SELECTED, m_lastSelectedRegulatorName );
216  aCfg->Write( KEYWORD_REGUL_TYPE,
217  m_choiceRegType->GetSelection() );
218  wxRadioButton * regprms[3] =
220  };
221  for( int ii = 0; ii < 3; ii++ )
222  {
223  if( regprms[ii]->GetValue() )
224  {
225  aCfg->Write( KEYWORD_REGUL_LAST_PARAM, ii );
226  break;
227  }
228  }
229 
230 
231  aCfg->Write( KEYWORD_ELECTRICAL_SPACING_SELECTION,
232  m_ElectricalSpacingUnitsSelector->GetSelection() );
233  aCfg->Write( KEYWORD_ELECTRICAL_SPACING_VOLTAGE,
234  m_ElectricalSpacingVoltage->GetValue() );
235 #endif
236  TW_WriteConfig();
237 
238  VS_WriteConfig();
239 
240  for( unsigned ii = 0; ii < m_transline_list.size(); ii++ )
241  m_transline_list[ii]->WriteConfig();
242 
243  for( unsigned ii = 0; ii < m_attenuator_list.size(); ii++ )
244  m_attenuator_list[ii]->WriteConfig();
245 }
246 
247 
253 void PCB_CALCULATOR_FRAME::OnTranslineAnalyse( wxCommandEvent& event )
254 {
255  if( m_currTransLine )
256  {
259  }
260 }
261 
262 
268 void PCB_CALCULATOR_FRAME::OnTranslineSynthetize( wxCommandEvent& event )
269 {
270  if( m_currTransLine )
271  {
274  }
275 }
276 
277 
279 {
280  wxPaintDC dc( m_panelDisplayshape );
281 
283 
284  if( tr_ident )
285  {
286  wxSize size = m_panelDisplayshape->GetSize();
287  size.x -= tr_ident->m_Icon->GetWidth();
288  size.y -= tr_ident->m_Icon->GetHeight();
289  dc.DrawBitmap( *tr_ident->m_Icon, size.x / 2, size.y / 2 );
290  }
291 
292  event.Skip();
293 }
294 
295 /* returns the full filename of the selected pcb_calculator data file
296  * the extension file is forced
297  */
299 {
300  if( m_regulators_fileNameCtrl->GetValue().IsEmpty() )
301  return wxEmptyString;
302 
303  wxFileName fn( m_regulators_fileNameCtrl->GetValue() );
304  fn.SetExt( DataFileNameExt );
305  return fn.GetFullPath();
306 }
307 
308 /* Initialize the full filename of the selected pcb_calculator data file
309  * force the standard extension of the file (.pcbcalc)
310  * aFilename = the full filename, with or without extension
311  */
312 void PCB_CALCULATOR_FRAME::SetDataFilename( const wxString & aFilename)
313 {
314  if( aFilename.IsEmpty() )
315  m_regulators_fileNameCtrl->SetValue( wxEmptyString );
316 
317  else
318  {
319  wxFileName fn( aFilename );
320  fn.SetExt( DataFileNameExt );
321  m_regulators_fileNameCtrl->SetValue( fn.GetFullPath() );
322  }
323 }
void ToleranceSelection(int aSelection)
Definition: colorcode.cpp:32
void VS_WriteConfig()
Function VS_WriteConfig Write Via Size prameters in config.
void SetKiway(wxWindow *aDest, KIWAY *aKiway)
Function SetKiway.
wxBitmap * m_Icon
enum PCB_CALCULATOR_FRAME::@42 m_TWMode
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
TRANSLINE * m_currTransLine
wxString m_lastSelectedRegulatorName
const BITMAP_OPAQUE icon_pcbcalculator_xpm[1]
Class PCB_CALCULATOR_FRAME_BASE.
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:80
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:92
#define NULL
void analyze()
Definition: transline.cpp:200
SHAPE_POLY_SET.
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 prameters in config.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void ElectricalSpacingUpdateData(double aUnitScale)
see class PGM_BASE
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.
ATTENUATOR * m_currAttenuator
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:209
void SelectLastSelectedRegulator()
Function SelectLastSelectedRegulator select in choice box the last selected regulator (name in m_last...
a wxChoiceBox to select units in Pcb_Calculator
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