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>
30#include <properties/property.h>
31
32
33extern double DoubleFromString( const wxString& TextValue );
34
36{
37 wxArrayString list = StandardRelativeDielectricConstantList();
38 list.Add( "" ); // Add an empty line for no selection
39
40 // Find the previous choice index:
41 wxString prevChoiceStr = m_Value_EpsilonR->GetValue();
42 int prevChoice = 0;
43 findMatch( list, prevChoiceStr, prevChoice );
44
45 int index = wxGetSingleChoiceIndex( wxEmptyString, _( "Relative Dielectric Constants" ),
46 list, prevChoice );
47
48 if( index >= 0 && !list.Item( index ).IsEmpty() ) // i.e. non canceled.
49 m_Value_EpsilonR->SetValue( list.Item( index ).BeforeFirst( ' ' ) );
50}
51
52
53void PANEL_TRANSLINE::OnTranslineTanD_Button( wxCommandEvent& event )
54{
55 wxArrayString list = StandardLossTangentList();
56 list.Add( "" ); // Add an empty line for no selection
57
58 // Find the previous choice index:
59 wxString prevChoiceStr = m_Value_TanD->GetValue();
60 int prevChoice = 0;
61 findMatch( list, prevChoiceStr, prevChoice );
62
63 int index = wxGetSingleChoiceIndex( wxEmptyString, _( "Dielectric Loss Factor" ), list,
64 prevChoice, nullptr );
65
66 if( index >= 0 && !list.Item( index ).IsEmpty() ) // i.e. non canceled.
67 m_Value_TanD->SetValue( list.Item( index ).BeforeFirst( ' ' ) );
68}
69
70
71void PANEL_TRANSLINE::OnTranslineRho_Button( wxCommandEvent& event )
72{
73 wxArrayString list = StandardResistivityList();
74 list.Add( "" ); // Add an empty line for no selection
75
76 // Find the previous choice index:
77 wxString prevChoiceStr = m_Value_Rho->GetValue();
78 int prevChoice = 0;
79 findMatch( list, prevChoiceStr, prevChoice );
80
81 int index = wxGetSingleChoiceIndex( wxEmptyString, _( "Specific Resistance" ), list,
82 prevChoice, nullptr );
83
84 if( index >= 0 && !list.Item( index ).IsEmpty() ) // i.e. non canceled.
85 m_Value_Rho->SetValue( list.Item( index ).BeforeFirst( ' ' ) );
86}
87
88
89// Minor helper struct to handle dialog items for a given parameter
91{
92 wxStaticText* name;
93 wxTextCtrl* value;
95};
96
97
99{
100 m_currTransLineType = aType;
101
104 {
106 }
107
109
110 // This helper bitmap is shown for coupled microstrip only:
111 m_bmCMicrostripZoddZeven->Show( aType == C_MICROSTRIP_TYPE || aType == C_STRIPLINE_TYPE );
113
115 m_currTransLine = tr_ident->m_TLine;
116
117 m_radioBtnPrm1->Show( tr_ident->m_HasPrmSelection );
118 m_radioBtnPrm2->Show( tr_ident->m_HasPrmSelection );
119
120 // Setup messages
121 wxStaticText* left_msg_list[] = { m_left_message1, m_left_message2, m_left_message3, m_left_message4,
124
125 wxStaticText* msg_list[] = { m_Message1, m_Message2, m_Message3, m_Message4, m_Message5, m_Message6,
127
128 unsigned jj = 0;
129
130 for( ; jj < tr_ident->m_Messages.GetCount(); jj++ )
131 {
132 if( left_msg_list[jj] == nullptr )
133 break;
134
135 left_msg_list[jj]->SetLabel( tr_ident->m_Messages[jj] );
136 msg_list[jj]->SetLabel( wxEmptyString );
137 }
138
139 while( left_msg_list[jj] )
140 {
141 left_msg_list[jj]->SetLabel( wxEmptyString );
142 msg_list[jj]->SetLabel( wxEmptyString );
143 jj++;
144 }
145
146
147 // Init parameters dialog items
148 struct DLG_PRM_DATA substrateprms[] =
149 {
151 { m_TanD_label, m_Value_TanD, nullptr },
152 { m_Rho_label, m_Value_Rho, nullptr },
159 };
160
161#define substrateprms_cnt (sizeof(substrateprms)/sizeof(substrateprms[0]))
162
163 struct DLG_PRM_DATA physprms[] =
164 {
168 };
169
170#define physprms_cnt (sizeof(physprms)/sizeof(physprms[0]))
171
172 struct DLG_PRM_DATA elecprms[] =
173 {
177 };
178
179#define elecprms_cnt (sizeof(elecprms)/sizeof(elecprms[0]))
180
181 struct DLG_PRM_DATA frequencyprms[] =
182 {
184 };
185
186#define frequencyprms_cnt (sizeof(frequencyprms)/sizeof(frequencyprms[0]))
187
188 unsigned idxsubs = 0;
189 unsigned idxphys = 0;
190 unsigned idxelec = 0;
191 unsigned idxfreq = 0;
192
193 for( unsigned ii = 0; ii < tr_ident->GetPrmsCount(); ii++ )
194 {
195 TRANSLINE_PRM* prm = tr_ident->GetPrm( ii );
196 struct DLG_PRM_DATA * data = nullptr;
197
198 switch( prm->m_Type )
199 {
200 case PRM_TYPE_SUBS:
201 wxASSERT( idxsubs < substrateprms_cnt );
202 data = &substrateprms[idxsubs];
203 idxsubs++;
204 break;
205
206 case PRM_TYPE_PHYS:
207 wxASSERT( idxphys < physprms_cnt );
208 data = &physprms[idxphys];
209 idxphys++;
210 break;
211
212 case PRM_TYPE_ELEC:
213 wxASSERT( idxelec < elecprms_cnt );
214 data = &elecprms[idxelec];
215 idxelec++;
216 break;
217
219 wxASSERT( idxfreq < frequencyprms_cnt );
220 data = &frequencyprms[idxfreq];
221 idxfreq++;
222 break;
223 }
224
225 wxASSERT ( data );
226 data->name->SetToolTip( prm->m_ToolTip );
227 data->name->SetLabel( prm->m_DlgLabel != wxS( "" ) ? prm->m_DlgLabel + wxS( ':' ) : wxString( wxS( "" ) ) );
228 prm->m_ValueCtrl = data->value;
229
230 if( prm->m_Id != DUMMY_PRM )
231 {
232 data->value->SetValue( wxString::Format( wxS( "%g" ), prm->m_Value ) );
233 data->value->Enable( true );
234 }
235 else
236 {
237 data->value->SetValue( wxEmptyString );
238 data->value->Enable( false );
239 }
240
241 if( prm->m_ConvUnit )
242 prm->m_UnitCtrl = data->unit;
243
244 if( data->unit )
245 {
246 data->unit->Show( prm->m_ConvUnit );
247 data->unit->Enable( prm->m_ConvUnit );
248 data->unit->SetSelection( prm->m_UnitSelection );
249 }
250 }
251
252 // Clear all unused params
253 for( ; idxsubs < substrateprms_cnt; idxsubs++ )
254 {
255 substrateprms[idxsubs].name->SetLabel(wxEmptyString);
256 substrateprms[idxsubs].name->SetToolTip(wxEmptyString);
257 substrateprms[idxsubs].value->SetValue(wxEmptyString);
258 substrateprms[idxsubs].value->Enable( false );
259
260 if( substrateprms[idxsubs].unit)
261 {
262 substrateprms[idxsubs].unit->Show( false );
263 substrateprms[idxsubs].unit->Enable( false );
264 substrateprms[idxsubs].unit->SetSelection( 0 );
265 }
266 }
267
268 for( ; idxphys < physprms_cnt; idxphys++ )
269 {
270 physprms[idxphys].name->SetLabel(wxEmptyString);
271 physprms[idxphys].name->SetToolTip(wxEmptyString);
272 physprms[idxphys].value->SetValue(wxEmptyString);
273 physprms[idxphys].value->Enable( false );
274
275 if( physprms[idxphys].unit)
276 {
277 physprms[idxphys].unit->Show( false );
278 physprms[idxphys].unit->Enable( false );
279 physprms[idxphys].unit->SetSelection( 0 );
280 }
281 }
282
283 for( ; idxelec < elecprms_cnt; idxelec++)
284 {
285 elecprms[idxelec].name->SetLabel(wxEmptyString);
286 elecprms[idxelec].name->SetToolTip(wxEmptyString);
287 elecprms[idxelec].value->SetValue(wxEmptyString);
288 elecprms[idxelec].value->Enable( false );
289
290 if( elecprms[idxelec].unit)
291 {
292 elecprms[idxelec].unit->Show( false );
293 elecprms[idxelec].unit->Enable( false );
294 elecprms[idxelec].unit->SetSelection( 0 );
295 }
296 }
297
298 for( ; idxfreq < frequencyprms_cnt; idxfreq++ )
299 {
300 frequencyprms[idxfreq].name->SetLabel(wxEmptyString);
301 frequencyprms[idxfreq].name->SetToolTip(wxEmptyString);
302 frequencyprms[idxfreq].value->SetValue(wxEmptyString);
303 frequencyprms[idxfreq].value->Enable( false );
304
305 if( frequencyprms[idxfreq].unit )
306 {
307 frequencyprms[idxfreq].unit->Show( false );
308 frequencyprms[idxfreq].unit->Enable( false );
309 frequencyprms[idxfreq].unit->SetSelection( 0 );
310 }
311 }
312}
313
314
316{
318
319 for( unsigned ii = 0; ii < tr_ident->GetPrmsCount(); ii++ )
320 {
321 TRANSLINE_PRM* prm = tr_ident->GetPrm( ii );
322 wxTextCtrl * value_ctrl = (wxTextCtrl * ) prm->m_ValueCtrl;
323 wxString value_txt = value_ctrl->GetValue();
324 double value = DoubleFromString(value_txt);
325 prm->m_Value = value;
326 UNIT_SELECTOR * unit_ctrl = (UNIT_SELECTOR * ) prm->m_UnitCtrl;
327
328 if( unit_ctrl )
329 {
330 prm->m_UnitSelection = unit_ctrl->GetSelection();
331 value *= unit_ctrl->GetUnitScale();
332 }
333
334 prm->m_NormalizedValue = value;
335 }
336}
337
338
339void PANEL_TRANSLINE::OnTranslineSelection( wxCommandEvent& event )
340{
341 // Ensure parameters from current selection are taken in account before switching to a new selection
342 if( m_currTransLine )
344
345 enum TRANSLINE_TYPE_ID id = (enum TRANSLINE_TYPE_ID) event.GetSelection();
346
348
349 // Texts and units choice widgets can have their size modified:
350 // The new size must be taken in account
351 GetSizer()->Layout();
352 Refresh();
353}
354
355
357{
358 // Initialize param values to default value
360
361 for( unsigned ii = 0; ii < tr_ident->GetPrmsCount(); ii++ )
362 {
363 TRANSLINE_PRM* prm = tr_ident->GetPrm( ii );
364 prm->m_Value = prm->m_DefaultValue;
365 UNIT_SELECTOR* unit_ctrl = (UNIT_SELECTOR*) prm->m_UnitCtrl;
366
367 if( unit_ctrl )
368 prm->m_UnitSelection = prm->m_DefaultUnit;
369 }
370
371 // Reinit displayed values
373
374 Refresh();
375}
int index
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:110
@ microstrip_zodd_zeven
wxTextCtrl * m_Substrate_prm5_Value
UNIT_SELECTOR_RESISTOR * m_choiceUnit_ElecPrm2
UNIT_SELECTOR_LEN * m_SubsPrm9_choiceUnit
wxStaticText * m_substrate_prm9_label
wxTextCtrl * m_Substrate_prm9_Value
UNIT_SELECTOR_LEN * m_SubsPrm4_choiceUnit
wxStaticText * m_phys_prm2_label
wxStaticText * m_EpsilonR_label
wxStaticText * m_substrate_prm7_label
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
UNIT_SELECTOR_LEN * m_choiceUnit_Param3
wxTextCtrl * m_Substrate_prm4_Value
wxRadioButton * m_radioBtnPrm2
UNIT_SELECTOR_LEN * m_SubsPrm5_choiceUnit
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
UNIT_SELECTOR_LEN * m_SubsPrm6_choiceUnit
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
UNIT_SELECTOR_RESISTOR * m_choiceUnit_ElecPrm1
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_NormalizedValue
wxString m_DlgLabel
virtual double GetUnitScale()=0
Function GetUnitScale.
wxArrayString StandardResistivityList()
wxArrayString StandardRelativeDielectricConstantList()
wxArrayString StandardLossTangentList()
#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...
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