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 (C) 1992-2022 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:
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[] =
120 {
123 };
124
125 wxStaticText* msg_list[] =
126 {
128 };
129
130 unsigned jj = 0;
131
132 for( ; jj < tr_ident->m_Messages.GetCount(); jj++ )
133 {
134 if( left_msg_list[jj] == nullptr )
135 break;
136
137 left_msg_list[jj]->SetLabel( tr_ident->m_Messages[jj] );
138 msg_list[jj]->SetLabel( wxEmptyString );
139 }
140
141 while( left_msg_list[jj] )
142 {
143 left_msg_list[jj]->SetLabel( wxEmptyString );
144 msg_list[jj]->SetLabel( wxEmptyString );
145 jj++;
146 }
147
148
149 // Init parameters dialog items
150 struct DLG_PRM_DATA substrateprms[] =
151 {
153 { m_TanD_label, m_Value_TanD, nullptr },
154 { m_Rho_label, m_Value_Rho, nullptr },
161 };
162
163#define substrateprms_cnt (sizeof(substrateprms)/sizeof(substrateprms[0]))
164
165 struct DLG_PRM_DATA physprms[] =
166 {
170 };
171
172#define physprms_cnt (sizeof(physprms)/sizeof(physprms[0]))
173
174 struct DLG_PRM_DATA elecprms[] =
175 {
179 };
180
181#define elecprms_cnt (sizeof(elecprms)/sizeof(elecprms[0]))
182
183 struct DLG_PRM_DATA frequencyprms[] =
184 {
186 };
187
188#define frequencyprms_cnt (sizeof(frequencyprms)/sizeof(frequencyprms[0]))
189
190 unsigned idxsubs = 0;
191 unsigned idxphys = 0;
192 unsigned idxelec = 0;
193 unsigned idxfreq = 0;
194
195 for( unsigned ii = 0; ii < tr_ident->GetPrmsCount(); ii++ )
196 {
197 TRANSLINE_PRM* prm = tr_ident->GetPrm( ii );
198 struct DLG_PRM_DATA * data = nullptr;
199
200 switch( prm->m_Type )
201 {
202 case PRM_TYPE_SUBS:
203 wxASSERT( idxsubs < substrateprms_cnt );
204 data = &substrateprms[idxsubs];
205 idxsubs++;
206 break;
207
208 case PRM_TYPE_PHYS:
209 wxASSERT( idxphys < physprms_cnt );
210 data = &physprms[idxphys];
211 idxphys++;
212 break;
213
214 case PRM_TYPE_ELEC:
215 wxASSERT( idxelec < elecprms_cnt );
216 data = &elecprms[idxelec];
217 idxelec++;
218 break;
219
221 wxASSERT( idxfreq < frequencyprms_cnt );
222 data = &frequencyprms[idxfreq];
223 idxfreq++;
224 break;
225 }
226
227 wxASSERT ( data );
228 data->name->SetToolTip( prm->m_ToolTip );
229 data->name->SetLabel( prm->m_DlgLabel != wxS( "" ) ? prm->m_DlgLabel + wxS( ':' ) : wxString( wxS( "" ) ) );
230 prm->m_ValueCtrl = data->value;
231
232 if( prm->m_Id != DUMMY_PRM )
233 {
234 data->value->SetValue( wxString::Format( wxS( "%g" ), prm->m_Value ) );
235 data->value->Enable( true );
236 }
237 else
238 {
239 data->value->SetValue( wxEmptyString );
240 data->value->Enable( false );
241 }
242
243 if( prm->m_ConvUnit )
244 prm->m_UnitCtrl = data->unit;
245
246 if( data->unit )
247 {
248 data->unit->Show( prm->m_ConvUnit );
249 data->unit->Enable( prm->m_ConvUnit );
250 data->unit->SetSelection( prm->m_UnitSelection );
251 }
252 }
253
254 // Clear all unused params
255 for( ; idxsubs < substrateprms_cnt; idxsubs++ )
256 {
257 substrateprms[idxsubs].name->SetLabel(wxEmptyString);
258 substrateprms[idxsubs].name->SetToolTip(wxEmptyString);
259 substrateprms[idxsubs].value->SetValue(wxEmptyString);
260 substrateprms[idxsubs].value->Enable( false );
261
262 if( substrateprms[idxsubs].unit)
263 {
264 substrateprms[idxsubs].unit->Show( false );
265 substrateprms[idxsubs].unit->Enable( false );
266 substrateprms[idxsubs].unit->SetSelection( 0 );
267 }
268 }
269
270 for( ; idxphys < physprms_cnt; idxphys++ )
271 {
272 physprms[idxphys].name->SetLabel(wxEmptyString);
273 physprms[idxphys].name->SetToolTip(wxEmptyString);
274 physprms[idxphys].value->SetValue(wxEmptyString);
275 physprms[idxphys].value->Enable( false );
276
277 if( physprms[idxphys].unit)
278 {
279 physprms[idxphys].unit->Show( false );
280 physprms[idxphys].unit->Enable( false );
281 physprms[idxphys].unit->SetSelection( 0 );
282 }
283 }
284
285 for( ; idxelec < elecprms_cnt; idxelec++)
286 {
287 elecprms[idxelec].name->SetLabel(wxEmptyString);
288 elecprms[idxelec].name->SetToolTip(wxEmptyString);
289 elecprms[idxelec].value->SetValue(wxEmptyString);
290 elecprms[idxelec].value->Enable( false );
291
292 if( elecprms[idxelec].unit)
293 {
294 elecprms[idxelec].unit->Show( false );
295 elecprms[idxelec].unit->Enable( false );
296 elecprms[idxelec].unit->SetSelection( 0 );
297 }
298 }
299
300 for( ; idxfreq < frequencyprms_cnt; idxfreq++ )
301 {
302 frequencyprms[idxfreq].name->SetLabel(wxEmptyString);
303 frequencyprms[idxfreq].name->SetToolTip(wxEmptyString);
304 frequencyprms[idxfreq].value->SetValue(wxEmptyString);
305 frequencyprms[idxfreq].value->Enable( false );
306
307 if( frequencyprms[idxfreq].unit )
308 {
309 frequencyprms[idxfreq].unit->Show( false );
310 frequencyprms[idxfreq].unit->Enable( false );
311 frequencyprms[idxfreq].unit->SetSelection( 0 );
312 }
313 }
314}
315
316
318{
320
321 for( unsigned ii = 0; ii < tr_ident->GetPrmsCount(); ii++ )
322 {
323 TRANSLINE_PRM* prm = tr_ident->GetPrm( ii );
324 wxTextCtrl * value_ctrl = (wxTextCtrl * ) prm->m_ValueCtrl;
325 wxString value_txt = value_ctrl->GetValue();
326 double value = DoubleFromString(value_txt);
327 prm->m_Value = value;
328 UNIT_SELECTOR * unit_ctrl = (UNIT_SELECTOR * ) prm->m_UnitCtrl;
329
330 if( unit_ctrl )
331 {
332 prm->m_UnitSelection = unit_ctrl->GetSelection();
333 value *= unit_ctrl->GetUnitScale();
334 }
335
336 prm->m_NormalizedValue = value;
337 }
338}
339
340
341void PANEL_TRANSLINE::OnTranslineSelection( wxCommandEvent& event )
342{
343 // Ensure parameters from current selection are taken in account before switching to a new selection
344 if( m_currTransLine )
346
347 enum TRANSLINE_TYPE_ID id = (enum TRANSLINE_TYPE_ID) event.GetSelection();
348
350
351 // Texts and units choice widgets can have their size modified:
352 // The new size must be taken in account
353 GetSizer()->Layout();
354 Refresh();
355}
356
357
359{
360 // Initialize param values to default value
362
363 for( unsigned ii = 0; ii < tr_ident->GetPrmsCount(); ii++ )
364 {
365 TRANSLINE_PRM* prm = tr_ident->GetPrm( ii );
366 prm->m_Value = prm->m_DefaultValue;
367 }
368
369 // Reinit displayed values
371
372 Refresh();
373}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
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_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
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:61
#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