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 #include <wx/config.h>
22 
23 #include <pgm_base.h>
24 #include <pcb_calculator.h>
25 #include <UnitSelector.h>
26 #include <bitmaps.h>
28 
29 
30 #define KEYWORD_FRAME_POSX wxT( "Pcb_calculator_Pos_x" )
31 #define KEYWORD_FRAME_POSY wxT( "Pcb_calculator_Pos_y" )
32 #define KEYWORD_FRAME_SIZEX wxT( "Pcb_calculator_Size_x" )
33 #define KEYWORD_FRAME_SIZEY wxT( "Pcb_calculator_Size_y" )
34 #define KEYWORD_TRANSLINE_SELECTION wxT( "Transline_selection" )
35 #define KEYWORD_PAGE_SELECTION wxT( "Page_selection" )
36 #define KEYWORD_COLORCODE_SELECTION wxT( "CC_selection" )
37 #define KEYWORD_ATTENUATORS_SELECTION wxT( "Att_selection" )
38 #define KEYWORD_BRDCLASS_SELECTION wxT( "BrdClass_selection" )
39 #define KEYWORD_ELECTRICAL_SPACING_SELECTION wxT( "ElectSpacing_selection" )
40 #define KEYWORD_ELECTRICAL_SPACING_VOLTAGE wxT( "ElectSpacing_voltage" )
41 #define KEYWORD_REGUL_R1 wxT( "RegulR1" )
42 #define KEYWORD_REGUL_R2 wxT( "RegulR2" )
43 #define KEYWORD_REGUL_VREF wxT( "RegulVREF" )
44 #define KEYWORD_REGUL_VOUT wxT( "RegulVOUT" )
45 #define KEYWORD_REGUL_SELECTED wxT( "RegulName" )
46 #define KEYWORD_REGUL_TYPE wxT( "RegulType" )
47 #define KEYWORD_REGUL_LAST_PARAM wxT( "RegulLastParam" )
48 #define KEYWORD_DATAFILE_FILENAME wxT( "DataFilename" )
49 
50 // extension of pcb_calculator data filename:
51 const wxString DataFileNameExt( wxT("pcbcalc") );
52 
53 PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
54  PCB_CALCULATOR_FRAME_BASE( aParent )
55 {
56  SetKiway( this, aKiway );
60  m_RegulatorListChanged = false;
62  m_TWNested = false;
63 
64  SHAPE_POLY_SET dummy; // A ugly trick to force the linker to include
65  // some methods in code and avoid link errors
66 
67  // Populate transline list ordered like in dialog menu list
68  const static TRANSLINE_TYPE_ID tltype_list[8] =
69  {
73  };
74 
75  for( int ii = 0; ii < 8; ii++ )
76  m_transline_list.push_back( new TRANSLINE_IDENT( tltype_list[ii] ) );
77 
78  // Populate attenuator list ordered like in dialog menu list
79  m_attenuator_list.push_back( new ATTENUATOR_PI() );
80  m_attenuator_list.push_back( new ATTENUATOR_TEE() );
81  m_attenuator_list.push_back( new ATTENUATOR_BRIDGE() );
82  m_attenuator_list.push_back( new ATTENUATOR_SPLITTER() );
84 
85  auto config = GetNewConfig( Pgm().App().GetAppName() );
86  LoadSettings( config.get() );
87 
88  ReadDataFile();
89 
92 
93  TW_Init( config.get() );
94 
95  VS_Init( config.get() );
96 
97  SetAttenuator( m_AttenuatorsSelection->GetSelection() );
98 
99  ToleranceSelection( m_rbToleranceSelection->GetSelection() );
100 
102 
104 
107 
108  // Give an icon
109  wxIcon icon;
110  icon.CopyFromBitmap( KiBitmap( icon_pcbcalculator_xpm ) );
111  SetIcon( icon );
112 
113  GetSizer()->SetSizeHints( this );
114 
115  // Set previous size and position
116  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
117 
118  if( m_FramePos == wxDefaultPosition )
119  Centre();
120 }
121 
122 
124 {
125  for( unsigned ii = 0; ii < m_transline_list.size(); ii++ )
126  delete m_transline_list[ii];
127 
128  for( unsigned ii = 0; ii < m_attenuator_list.size(); ii++ )
129  delete m_attenuator_list[ii];
130 
131  /* This needed for OSX: avoids furter OnDraw processing after this
132  * destructor and before the native window is destroyed
133  */
134  this->Freeze();
135 }
136 
137 
138 void PCB_CALCULATOR_FRAME::OnClosePcbCalc( wxCloseEvent& event )
139 {
141  {
142  if( GetDataFilename().IsEmpty() )
143  {
144  int opt = wxMessageBox(
145  _("Data modified, and no data filename to save modifications\n"\
146  "Do you want to exit and abandon your change?"),
147  _("Regulator list change"),
148  wxYES_NO | wxICON_QUESTION );
149 
150  if( opt == wxNO )
151  return;
152  }
153  else
154  {
155  if( !WriteDataFile() )
156  {
157  wxString msg;
158  msg.Printf( _("Unable to write file \"%s\"\n"\
159  "Do you want to exit and abandon your change?"),
160  GetDataFilename().c_str() );
161 
162  int opt = wxMessageBox( msg, _("Write Data File Error"),
163  wxYES_NO | wxICON_ERROR );
164  if( opt == wxNO )
165  return;
166  }
167  }
168  }
169 
170  event.Skip();
171 // Destroy();
172 }
173 
174 void PCB_CALCULATOR_FRAME::LoadSettings( wxConfigBase* aCfg )
175 {
176  if( aCfg == NULL )
177  return;
178 
180 
181  long ltmp;
182  wxString msg;
183  aCfg->Read( KEYWORD_TRANSLINE_SELECTION, &ltmp, (long) DEFAULT_TYPE );
185  aCfg->Read( KEYWORD_PAGE_SELECTION, &ltmp, 0 );
186  m_Notebook->ChangeSelection( ltmp );
187  aCfg->Read( KEYWORD_COLORCODE_SELECTION, &ltmp, 1 );
188  m_rbToleranceSelection->SetSelection( ltmp );
189  aCfg->Read( KEYWORD_ATTENUATORS_SELECTION, &ltmp, 0 );
190  m_AttenuatorsSelection->SetSelection( ltmp );
191  aCfg->Read( KEYWORD_BRDCLASS_SELECTION, &ltmp, 0 );
192  m_BoardClassesUnitsSelector->SetSelection( ltmp );
193 
194  // Regul panel config:
195  aCfg->Read( KEYWORD_REGUL_R1, &msg, wxT( "10" ) );
196  m_RegulR1Value->SetValue( msg );
197  aCfg->Read( KEYWORD_REGUL_R2, &msg, wxT( "10" ) );
198  m_RegulR2Value->SetValue( msg );
199  aCfg->Read( KEYWORD_REGUL_VREF, &msg, wxT( "3" ) );
200  m_RegulVrefValue->SetValue( msg );
201  aCfg->Read( KEYWORD_REGUL_VOUT, &msg, wxT( "12" ) );
202  m_RegulVoutValue->SetValue( msg );
203  aCfg->Read( KEYWORD_DATAFILE_FILENAME, &msg, wxT( "" ) );
204  SetDataFilename( msg );
205  aCfg->Read( KEYWORD_REGUL_SELECTED, &msg, wxT( "" ) );
207  aCfg->Read( KEYWORD_REGUL_TYPE, &ltmp, 0 );
208  m_choiceRegType->SetSelection( ltmp );
209  aCfg->Read( KEYWORD_REGUL_LAST_PARAM, &ltmp, 0 );
210  wxRadioButton * regprms[3] =
212  };
213  if( (unsigned)ltmp >= 3 )
214  ltmp = 0;
215  for( int ii = 0; ii < 3; ii++ )
216  regprms[ii]->SetValue( ltmp == ii );
217 
218  // Electrical panel config
219  aCfg->Read( KEYWORD_ELECTRICAL_SPACING_SELECTION, &ltmp, 0 );
220  m_ElectricalSpacingUnitsSelector->SetSelection( ltmp );
221  aCfg->Read( KEYWORD_ELECTRICAL_SPACING_VOLTAGE, &msg, wxT( "500" ) );
222  m_ElectricalSpacingVoltage->SetValue( msg );
223 
224  for( unsigned ii = 0; ii < m_transline_list.size(); ii++ )
225  m_transline_list[ii]->ReadConfig( aCfg );
226 
227  for( unsigned ii = 0; ii < m_attenuator_list.size(); ii++ )
228  m_attenuator_list[ii]->ReadConfig( aCfg );
229 }
230 
231 
232 void PCB_CALCULATOR_FRAME::SaveSettings( wxConfigBase* aCfg )
233 {
234  if( aCfg == NULL )
235  return;
236 
238 
239  aCfg->Write( KEYWORD_TRANSLINE_SELECTION, (long) m_currTransLineType );
240  aCfg->Write( KEYWORD_PAGE_SELECTION, m_Notebook->GetSelection() );
241  aCfg->Write( KEYWORD_COLORCODE_SELECTION, m_rbToleranceSelection->GetSelection() );
242  aCfg->Write( KEYWORD_ATTENUATORS_SELECTION, m_AttenuatorsSelection->GetSelection() );
243  aCfg->Write( KEYWORD_BRDCLASS_SELECTION, m_BoardClassesUnitsSelector->GetSelection() );
244 
245  aCfg->Write( KEYWORD_REGUL_R1, m_RegulR1Value->GetValue() );
246  aCfg->Write( KEYWORD_REGUL_R2, m_RegulR2Value->GetValue() );
247  aCfg->Write( KEYWORD_REGUL_VREF, m_RegulVrefValue->GetValue() );
248  aCfg->Write( KEYWORD_REGUL_VOUT, m_RegulVoutValue->GetValue() );
249  aCfg->Write( KEYWORD_DATAFILE_FILENAME, GetDataFilename() );
251  aCfg->Write( KEYWORD_REGUL_TYPE,
252  m_choiceRegType->GetSelection() );
253  wxRadioButton * regprms[3] =
255  };
256  for( int ii = 0; ii < 3; ii++ )
257  {
258  if( regprms[ii]->GetValue() )
259  {
260  aCfg->Write( KEYWORD_REGUL_LAST_PARAM, ii );
261  break;
262  }
263  }
264 
265 
267  m_ElectricalSpacingUnitsSelector->GetSelection() );
269  m_ElectricalSpacingVoltage->GetValue() );
270 
271  TW_WriteConfig( aCfg );
272 
273  VS_WriteConfig( aCfg );
274 
275  for( unsigned ii = 0; ii < m_transline_list.size(); ii++ )
276  m_transline_list[ii]->WriteConfig( aCfg );
277 
278  for( unsigned ii = 0; ii < m_attenuator_list.size(); ii++ )
279  m_attenuator_list[ii]->WriteConfig( aCfg );
280 }
281 
282 
288 void PCB_CALCULATOR_FRAME::OnTranslineAnalyse( wxCommandEvent& event )
289 {
290  if( m_currTransLine )
291  {
294  }
295 }
296 
297 
303 void PCB_CALCULATOR_FRAME::OnTranslineSynthetize( wxCommandEvent& event )
304 {
305  if( m_currTransLine )
306  {
309  }
310 }
311 
312 
314 {
315  wxPaintDC dc( m_panelDisplayshape );
316 
318 
319  if( tr_ident )
320  {
321  wxSize size = m_panelDisplayshape->GetSize();
322  size.x -= tr_ident->m_Icon->GetWidth();
323  size.y -= tr_ident->m_Icon->GetHeight();
324  dc.DrawBitmap( *tr_ident->m_Icon, size.x / 2, size.y / 2 );
325  }
326 
327  event.Skip();
328 }
329 
330 /* returns the full filename of the selected pcb_calculator data file
331  * the extension file is forced
332  */
334 {
335  if( m_regulators_fileNameCtrl->GetValue().IsEmpty() )
336  return wxEmptyString;
337 
338  wxFileName fn( m_regulators_fileNameCtrl->GetValue() );
339  fn.SetExt( DataFileNameExt );
340  return fn.GetFullPath();
341 }
342 
343 /* Initialize the full filename of the selected pcb_calculator data file
344  * force the standard extension of the file (.pcbcalc)
345  * aFilename = the full filename, with or without extension
346  */
347 void PCB_CALCULATOR_FRAME::SetDataFilename( const wxString & aFilename)
348 {
349  if( aFilename.IsEmpty() )
350  m_regulators_fileNameCtrl->SetValue( wxEmptyString );
351 
352  else
353  {
354  wxFileName fn( aFilename );
355  fn.SetExt( DataFileNameExt );
356  m_regulators_fileNameCtrl->SetValue( fn.GetFullPath() );
357  }
358 }
void ToleranceSelection(int aSelection)
Definition: colorcode.cpp:33
#define KEYWORD_DATAFILE_FILENAME
void SetKiway(wxWindow *aDest, KIWAY *aKiway)
Function SetKiway.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:98
wxBitmap * m_Icon
enum PCB_CALCULATOR_FRAME::@42 m_TWMode
#define KEYWORD_ELECTRICAL_SPACING_SELECTION
std::unique_ptr< wxConfigBase > GetNewConfig(const wxString &aProgName)
Create a new wxConfig so we can put configuration files in a more proper place for each platform.
Definition: common.cpp:231
PCB_CALCULATOR_FRAME(KIWAY *aKiway, wxWindow *aParent)
void VS_Init(wxConfigBase *aCfg)
Function VS_Init Read config and init dialog widgets values.
void OnPaintTranslinePanel(wxPaintEvent &event) override
TRANSLINE * m_currTransLine
#define KEYWORD_REGUL_VOUT
wxString m_lastSelectedRegulatorName
virtual void SaveSettings(wxConfigBase *aCfg)
Saves common frame parameters to a configuration data file.
#define KEYWORD_PAGE_SELECTION
const BITMAP_OPAQUE icon_pcbcalculator_xpm[1]
virtual wxConfigBase * config()
Returns the wxConfigBase used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
Class PCB_CALCULATOR_FRAME_BASE.
void TW_Init(wxConfigBase *aCfg)
Function TW_Init Read config and init dialog widgets values.
void VS_WriteConfig(wxConfigBase *aCfg)
Function VS_WriteConfig Write Via Size prameters in config.
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:79
#define KEYWORD_TRANSLINE_SELECTION
#define KEYWORD_REGUL_SELECTED
#define NULL
SHAPE_POLY_SET.
virtual void LoadSettings(wxConfigBase *aCfg)
Load common frame parameters from a configuration file.
void TransfDlgDataToTranslineParams()
Function TransfDlgDataToTranslineParams Read values entered in dialog frame, and transfert these valu...
virtual void analyze()
Definition: transline.h:72
KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the s...
Definition: kiway.h:274
#define KEYWORD_ATTENUATORS_SELECTION
virtual void synthesize()
Definition: transline.h:71
#define KEYWORD_REGUL_LAST_PARAM
void OnTranslineSynthetize(wxCommandEvent &event) override
Function OnTranslineSynthetize Run a new synthezis for the current transline with current parameters ...
void OnClosePcbCalc(wxCloseEvent &event) override
#define KEYWORD_REGUL_TYPE
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.
#define KEYWORD_COLORCODE_SELECTION
#define KEYWORD_REGUL_R1
#define KEYWORD_ELECTRICAL_SPACING_VOLTAGE
void ElectricalSpacingUpdateData(double aUnitScale)
#define KEYWORD_BRDCLASS_SELECTION
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:31
std::vector< TRANSLINE_IDENT * > m_transline_list
virtual double GetUnitScale() override
Function GetUnitScale.
UNIT_SELECTOR_LEN * m_BoardClassesUnitsSelector
void SetAttenuator(unsigned aIdx)
Definition: attenuators.cpp:44
UNIT_SELECTOR_LEN * m_ElectricalSpacingUnitsSelector
#define KEYWORD_REGUL_R2
void TW_WriteConfig(wxConfigBase *aCfg)
Function TW_WriteConfig Write Track width prameters in config.
std::vector< ATTENUATOR * > m_attenuator_list
void SaveSettings(wxConfigBase *aCfg) override
Saves common frame parameters to a configuration data file.
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)
#define KEYWORD_REGUL_VREF
void LoadSettings(wxConfigBase *aCfg) override
Load common frame parameters from a configuration file.