KiCad PCB EDA Suite
Loading...
Searching...
No Matches
transline_dlg_funct.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) 2011 jean-pierre.charras
5 * Copyright The 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/choicdlg.h>
21#include <wx/filename.h>
22#include <wx/settings.h>
23
24#include <bitmaps.h>
26#include <common_data.h>
29
30
31extern double DoubleFromString( const wxString& TextValue );
32
34{
35 wxArrayString list = StandardRelativeDielectricConstantList();
36 list.Add( "" ); // Add an empty line for no selection
37
38 // Find the previous choice index:
39 wxString prevChoiceStr = m_Value_EpsilonR->GetValue();
40 int prevChoice = 0;
41 findMatch( list, prevChoiceStr, prevChoice );
42
43 int index = wxGetSingleChoiceIndex( wxEmptyString, _( "Relative Dielectric Constants" ),
44 list, prevChoice );
45
46 if( index >= 0 && !list.Item( index ).IsEmpty() ) // i.e. non canceled.
47 m_Value_EpsilonR->SetValue( list.Item( index ).BeforeFirst( ' ' ) );
48}
49
50
51void PANEL_TRANSLINE::OnTranslineTanD_Button( wxCommandEvent& event )
52{
53 wxArrayString list = StandardLossTangentList();
54 list.Add( "" ); // Add an empty line for no selection
55
56 // Find the previous choice index:
57 wxString prevChoiceStr = m_Value_TanD->GetValue();
58 int prevChoice = 0;
59 findMatch( list, prevChoiceStr, prevChoice );
60
61 int index = wxGetSingleChoiceIndex( wxEmptyString, _( "Dielectric Loss Factor" ), list,
62 prevChoice, nullptr );
63
64 if( index >= 0 && !list.Item( index ).IsEmpty() ) // i.e. non canceled.
65 m_Value_TanD->SetValue( list.Item( index ).BeforeFirst( ' ' ) );
66}
67
68
69void PANEL_TRANSLINE::OnTranslineRho_Button( wxCommandEvent& event )
70{
71 wxArrayString list = StandardResistivityList();
72 list.Add( "" ); // Add an empty line for no selection
73
74 // Find the previous choice index:
75 wxString prevChoiceStr = m_Value_Rho->GetValue();
76 int prevChoice = 0;
77 findMatch( list, prevChoiceStr, prevChoice );
78
79 int index = wxGetSingleChoiceIndex( wxEmptyString, _( "Specific Resistance" ), list,
80 prevChoice, nullptr );
81
82 if( index >= 0 && !list.Item( index ).IsEmpty() ) // i.e. non canceled.
83 m_Value_Rho->SetValue( list.Item( index ).BeforeFirst( ' ' ) );
84}
85
86
87// Minor helper struct to handle dialog items for a given parameter
89{
90 wxStaticText* name;
91 wxTextCtrl* value;
93};
94
95
97{
98 m_currTransLineType = aType;
99
102 {
104 }
105
107
108 // This helper bitmap is shown for coupled microstrip only:
109 m_bmCMicrostripZoddZeven->Show( aType == C_MICROSTRIP_TYPE || aType == C_STRIPLINE_TYPE );
110 m_bmCMicrostripZoddZeven->SetBitmap( KiBitmapBundle( BITMAPS::microstrip_zodd_zeven ) );
111
113 m_currTransLine = tr_ident->m_TLine;
114
115 m_radioBtnPrm1->Show( tr_ident->m_HasPrmSelection );
116 m_radioBtnPrm2->Show( tr_ident->m_HasPrmSelection );
117
118 // Setup messages
119 wxStaticText* left_msg_list[] = { m_left_message1, m_left_message2, m_left_message3, m_left_message4,
122
123 wxStaticText* msg_list[] = { m_Message1, m_Message2, m_Message3, m_Message4, m_Message5, m_Message6,
125
126 unsigned jj = 0;
127
128 for( ; jj < tr_ident->m_Messages.GetCount(); jj++ )
129 {
130 if( left_msg_list[jj] == nullptr )
131 break;
132
133 left_msg_list[jj]->SetLabel( tr_ident->m_Messages[jj] );
134 msg_list[jj]->SetLabel( wxEmptyString );
135 }
136
137 while( left_msg_list[jj] )
138 {
139 left_msg_list[jj]->SetLabel( wxEmptyString );
140 msg_list[jj]->SetLabel( wxEmptyString );
141 jj++;
142 }
143
144
145 // Init parameters dialog items
146 struct DLG_PRM_DATA substrateprms[] =
147 {
149 { m_TanD_label, m_Value_TanD, nullptr },
150 { m_Rho_label, m_Value_Rho, nullptr },
157 };
158
159#define substrateprms_cnt (sizeof(substrateprms)/sizeof(substrateprms[0]))
160
161 struct DLG_PRM_DATA physprms[] =
162 {
166 };
167
168#define physprms_cnt (sizeof(physprms)/sizeof(physprms[0]))
169
170 struct DLG_PRM_DATA elecprms[] =
171 {
175 };
176
177#define elecprms_cnt (sizeof(elecprms)/sizeof(elecprms[0]))
178
179 struct DLG_PRM_DATA frequencyprms[] =
180 {
182 };
183
184#define frequencyprms_cnt (sizeof(frequencyprms)/sizeof(frequencyprms[0]))
185
186 unsigned idxsubs = 0;
187 unsigned idxphys = 0;
188 unsigned idxelec = 0;
189 unsigned idxfreq = 0;
190
191 for( unsigned ii = 0; ii < tr_ident->GetPrmsCount(); ii++ )
192 {
193 TRANSLINE_PRM* prm = tr_ident->GetPrm( ii );
194 struct DLG_PRM_DATA * data = nullptr;
195
196 switch( prm->m_Type )
197 {
198 case PRM_TYPE_SUBS:
199 wxASSERT( idxsubs < substrateprms_cnt );
200 data = &substrateprms[idxsubs];
201 idxsubs++;
202 break;
203
204 case PRM_TYPE_PHYS:
205 wxASSERT( idxphys < physprms_cnt );
206 data = &physprms[idxphys];
207 idxphys++;
208 break;
209
210 case PRM_TYPE_ELEC:
211 wxASSERT( idxelec < elecprms_cnt );
212 data = &elecprms[idxelec];
213 idxelec++;
214 break;
215
217 wxASSERT( idxfreq < frequencyprms_cnt );
218 data = &frequencyprms[idxfreq];
219 idxfreq++;
220 break;
221 }
222
223 wxASSERT ( data );
224 data->name->SetToolTip( prm->m_ToolTip );
225 data->name->SetLabel( prm->m_DlgLabel != wxS( "" ) ? prm->m_DlgLabel + wxS( ':' ) : wxString( wxS( "" ) ) );
226 prm->m_ValueCtrl = data->value;
227
228 if( prm->m_Id != DUMMY_PRM )
229 {
230 data->value->SetValue( wxString::Format( wxS( "%g" ), prm->m_Value ) );
231 data->value->Enable( true );
232 }
233 else
234 {
235 data->value->SetValue( wxEmptyString );
236 data->value->Enable( false );
237 }
238
239 if( prm->m_ConvUnit )
240 prm->m_UnitCtrl = data->unit;
241
242 if( data->unit )
243 {
244 data->unit->Show( prm->m_ConvUnit );
245 data->unit->Enable( prm->m_ConvUnit );
246 data->unit->SetSelection( prm->m_UnitSelection );
247 }
248 }
249
250 // Clear all unused params
251 for( ; idxsubs < substrateprms_cnt; idxsubs++ )
252 {
253 substrateprms[idxsubs].name->SetLabel(wxEmptyString);
254 substrateprms[idxsubs].name->SetToolTip(wxEmptyString);
255 substrateprms[idxsubs].value->SetValue(wxEmptyString);
256 substrateprms[idxsubs].value->Enable( false );
257
258 if( substrateprms[idxsubs].unit)
259 {
260 substrateprms[idxsubs].unit->Show( false );
261 substrateprms[idxsubs].unit->Enable( false );
262 substrateprms[idxsubs].unit->SetSelection( 0 );
263 }
264 }
265
266 for( ; idxphys < physprms_cnt; idxphys++ )
267 {
268 physprms[idxphys].name->SetLabel(wxEmptyString);
269 physprms[idxphys].name->SetToolTip(wxEmptyString);
270 physprms[idxphys].value->SetValue(wxEmptyString);
271 physprms[idxphys].value->Enable( false );
272
273 if( physprms[idxphys].unit)
274 {
275 physprms[idxphys].unit->Show( false );
276 physprms[idxphys].unit->Enable( false );
277 physprms[idxphys].unit->SetSelection( 0 );
278 }
279 }
280
281 for( ; idxelec < elecprms_cnt; idxelec++)
282 {
283 elecprms[idxelec].name->SetLabel(wxEmptyString);
284 elecprms[idxelec].name->SetToolTip(wxEmptyString);
285 elecprms[idxelec].value->SetValue(wxEmptyString);
286 elecprms[idxelec].value->Enable( false );
287
288 if( elecprms[idxelec].unit)
289 {
290 elecprms[idxelec].unit->Show( false );
291 elecprms[idxelec].unit->Enable( false );
292 elecprms[idxelec].unit->SetSelection( 0 );
293 }
294 }
295
296 for( ; idxfreq < frequencyprms_cnt; idxfreq++ )
297 {
298 frequencyprms[idxfreq].name->SetLabel(wxEmptyString);
299 frequencyprms[idxfreq].name->SetToolTip(wxEmptyString);
300 frequencyprms[idxfreq].value->SetValue(wxEmptyString);
301 frequencyprms[idxfreq].value->Enable( false );
302
303 if( frequencyprms[idxfreq].unit )
304 {
305 frequencyprms[idxfreq].unit->Show( false );
306 frequencyprms[idxfreq].unit->Enable( false );
307 frequencyprms[idxfreq].unit->SetSelection( 0 );
308 }
309 }
310}
311
312
314{
316
317 for( unsigned ii = 0; ii < tr_ident->GetPrmsCount(); ii++ )
318 {
319 TRANSLINE_PRM* prm = tr_ident->GetPrm( ii );
320 wxTextCtrl * value_ctrl = (wxTextCtrl * ) prm->m_ValueCtrl;
321 wxString value_txt = value_ctrl->GetValue();
322 double value = DoubleFromString(value_txt);
323 prm->m_Value = value;
324 UNIT_SELECTOR * unit_ctrl = (UNIT_SELECTOR * ) prm->m_UnitCtrl;
325
326 if( unit_ctrl )
327 {
328 prm->m_UnitSelection = unit_ctrl->GetSelection();
329 value *= unit_ctrl->GetUnitScale();
330 }
331
332 prm->m_NormalizedValue = value;
333 }
334}
335
336
337void PANEL_TRANSLINE::OnTranslineSelection( wxCommandEvent& event )
338{
339 // Ensure parameters from current selection are taken in account before switching to a new selection
340 if( m_currTransLine )
342
343 enum TRANSLINE_TYPE_ID id = (enum TRANSLINE_TYPE_ID) event.GetSelection();
344
346
347 // Texts and units choice widgets can have their size modified:
348 // The new size must be taken in account
349 GetSizer()->Layout();
350 Refresh();
351}
352
353
355{
356 // Initialize param values to default value
358
359 for( unsigned ii = 0; ii < tr_ident->GetPrmsCount(); ii++ )
360 {
361 TRANSLINE_PRM* prm = tr_ident->GetPrm( ii );
362 prm->m_Value = prm->m_DefaultValue;
363 UNIT_SELECTOR* unit_ctrl = (UNIT_SELECTOR*) prm->m_UnitCtrl;
364
365 if( unit_ctrl )
366 prm->m_UnitSelection = prm->m_DefaultUnit;
367 }
368
369 // Reinit displayed values
371
372 Refresh();
373}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition: bitmap.cpp:110
wxTextCtrl * m_Substrate_prm5_Value
UNIT_SELECTOR_RESISTOR * m_choiceUnit_ElecPrm2
wxStaticText * m_left_message5
UNIT_SELECTOR_LEN * m_SubsPrm9_choiceUnit
wxStaticText * m_substrate_prm9_label
wxStaticText * m_left_message3
wxTextCtrl * m_Substrate_prm9_Value
wxStaticText * m_left_message8
UNIT_SELECTOR_LEN * m_SubsPrm4_choiceUnit
wxStaticText * m_left_message9
wxStaticText * m_phys_prm2_label
wxStaticText * m_EpsilonR_label
wxStaticText * m_substrate_prm7_label
wxStaticText * m_left_message10
wxStaticText * m_Frequency_label
wxTextCtrl * m_Substrate_prm7_Value
wxStaticBitmap * m_bmCMicrostripZoddZeven
wxStaticText * m_substrate_prm6_label
UNIT_SELECTOR_LEN * m_SubsPrm7_choiceUnit
wxStaticText * m_phys_prm1_label
wxStaticText * m_elec_prm2_label
UNIT_SELECTOR_LEN * m_choiceUnit_Param3
wxTextCtrl * m_Substrate_prm4_Value
wxRadioButton * m_radioBtnPrm2
wxStaticText * m_left_message2
UNIT_SELECTOR_LEN * m_SubsPrm5_choiceUnit
wxStaticText * m_left_message6
wxTextCtrl * m_Substrate_prm6_Value
wxRadioButton * m_radioBtnPrm1
wxStaticText * m_substrate_prm8_label
wxStaticText * m_elec_prm1_label
UNIT_SELECTOR_ANGLE * m_choiceUnit_ElecPrm3
wxStaticText * m_phys_prm3_label
wxStaticText * m_left_message7
UNIT_SELECTOR_LEN * m_SubsPrm6_choiceUnit
wxStaticText * m_elec_prm3_label
wxStaticBitmap * m_translineBitmap
UNIT_SELECTOR_LEN * m_choiceUnit_Param2
UNIT_SELECTOR_FREQUENCY * m_choiceUnit_Frequency
UNIT_SELECTOR_LEN * m_SubsPrm8_choiceUnit
wxTextCtrl * m_Substrate_prm8_Value
wxStaticText * m_left_message4
UNIT_SELECTOR_RESISTOR * m_choiceUnit_ElecPrm1
wxStaticText * m_left_message1
wxStaticText * m_substrate_prm4_label
UNIT_SELECTOR_LEN * m_choiceUnit_Param1
wxStaticText * m_substrate_prm5_label
wxTextCtrl * m_Value_Frequency_Ctrl
TRANSLINE * m_currTransLine
void OnTranslineTanD_Button(wxCommandEvent &event) override
Show a list of current dielectric loss factor (tangent delta) and set the selected value in main dial...
void TranslineTypeSelection(enum TRANSLINE_TYPE_ID aType)
Must be called after selection of a new transline.
void OnTranslineEpsilonR_Button(wxCommandEvent &event) override
Shows a list of current relative dielectric constant(Er) and set the selected value in main dialog fr...
void TransfDlgDataToTranslineParams()
Read values entered in dialog frame, and transfer these values in current transline parameters,...
void OnTranslineSelection(wxCommandEvent &event) override
Called on new transmission line selection.
std::vector< TRANSLINE_IDENT * > m_transline_list
void OnTransLineResetButtonClick(wxCommandEvent &event) override
Called when the user clicks the reset button; sets the parameters to their default values.
void OnTranslineRho_Button(wxCommandEvent &event) override
Show a list of current Specific resistance list (rho) and set the selected value in main dialog frame...
enum TRANSLINE_TYPE_ID m_currTransLineType
A class to handle a list of parameters of a given transline.
TRANSLINE * m_TLine
unsigned GetPrmsCount() const
TRANSLINE_PRM * GetPrm(unsigned aIdx) const
wxArrayString m_Messages
A class to handle one parameter of transline.
double m_DefaultValue
double m_NormalizedValue
wxString m_ToolTip
wxString m_DlgLabel
virtual double GetUnitScale()=0
Function GetUnitScale.
wxArrayString StandardResistivityList()
Definition: common_data.cpp:84
wxArrayString StandardRelativeDielectricConstantList()
Definition: common_data.cpp:28
wxArrayString StandardLossTangentList()
Definition: common_data.cpp:55
#define _(s)
double DoubleFromString(const wxString &TextValue)
bool findMatch(wxArrayString &aList, const wxString &aValue, int &aIdx)
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
wxTextCtrl * value
wxStaticText * name
UNIT_SELECTOR * unit
@ DUMMY_PRM
Definition: transline.h:63
#define elecprms_cnt
#define substrateprms_cnt
double DoubleFromString(const wxString &TextValue)
#define frequencyprms_cnt
#define physprms_cnt
@ PRM_TYPE_FREQUENCY
@ PRM_TYPE_SUBS
@ PRM_TYPE_ELEC
@ PRM_TYPE_PHYS
TRANSLINE_TYPE_ID
@ C_MICROSTRIP_TYPE
@ END_OF_LIST_TYPE
@ DEFAULT_TYPE
@ START_OF_LIST_TYPE
@ C_STRIPLINE_TYPE