KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_wavelength.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-2022 Kicad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
22#include <string_utils.h>
24#include <wx/choicdlg.h>
26#include "common_data.h"
27#include <wx/dcclient.h>
28
29#define SPEED_LIGHT 299792458
30
31PANEL_WAVELENGTH::PANEL_WAVELENGTH( wxWindow* parent, wxWindowID id, const wxPoint& pos,
32 const wxSize& size, long style, const wxString& name ) :
33 PANEL_WAVELENGTH_BASE( parent, id, pos, size, style, name )
34{
35 // Set the min size of wxTextCtrls showing long values
36 wxSize minSize = m_speedCtrl->GetSize();
37 int minWidth = m_speedCtrl->GetTextExtent( wxT( "1.234567890E+99" ) ).x;
38
39 m_speedCtrl->SetMinSize( wxSize( minWidth, minSize.GetHeight() ) );
40
41 Layout();
42}
43
45{
49
50 aCfg->m_wavelength.frequencyUnit = m_frequencyUnit->GetSelection();
51 aCfg->m_wavelength.periodUnit = m_periodUnit->GetSelection();
54 aCfg->m_wavelength.speedUnit = m_speedUnit->GetSelection();
55}
56
57
59{
60 m_frequencyUnit->SetSelection( aCfg->m_wavelength.frequencyUnit );
61 m_periodUnit->SetSelection( aCfg->m_wavelength.periodUnit );
64 m_speedUnit->SetSelection( aCfg->m_wavelength.speedUnit );
65
69
70 wxString value;
71 value = wxString( "" ) << m_permittivity;
72 m_permittivityCtrl->SetValue( value );
73 value = wxString( "" ) << m_permeability;
74 m_permeabilityCtrl->SetValue( value );
75
77}
78
79void PANEL_WAVELENGTH::updateUnits( wxCommandEvent& aEvent )
80{
82}
83
84
85void PANEL_WAVELENGTH::update( double aFrequency )
86{
87 m_updatingUI = true;
88 wxString value;
89
91 {
92 value = wxString( "" ) << aFrequency / m_frequencyUnit->GetUnitScale();
93 m_frequencyCtrl->SetValue( value );
94 }
95
96 if( !m_updatingPeriod )
97 {
98 value = wxString( "" ) << 1 / aFrequency / m_periodUnit->GetUnitScale();
99 m_periodCtrl->SetValue( value );
100 }
101
103 {
104 value = wxString( "" ) << SPEED_LIGHT / aFrequency / m_wavelengthVacuumUnit->GetUnitScale();
105 m_wavelengthVacuumCtrl->SetValue( value );
106 }
107
109 {
110 value = wxString( "" ) << SPEED_LIGHT / aFrequency / sqrt( m_permittivity * m_permeability )
112 m_wavelengthMediumCtrl->SetValue( value );
113 }
114
115 if( !m_updatingSpeed )
116 {
117 value = wxString( "" ) << SPEED_LIGHT / sqrt( m_permittivity * m_permeability )
119 m_speedCtrl->SetValue( value );
120 }
121
122 m_frequency = aFrequency;
123
124 m_updatingFrequency = false;
125 m_updatingPeriod = false;
128 m_updatingSpeed = false;
129
130 m_updatingUI = false;
131}
132
133void PANEL_WAVELENGTH::OnFrequencyChange( wxCommandEvent& event )
134{
135 double value;
136
137 if( m_updatingUI )
138 {
139 return;
140 }
141
142 wxString input = m_frequencyCtrl->GetValue();
143
144 if( input.ToDouble( &value ) )
145 {
146 if( value > 0 )
147 {
148 m_updatingFrequency = true;
149 update( value * m_frequencyUnit->GetUnitScale() );
150 }
151 }
152}
153
154void PANEL_WAVELENGTH::OnPeriodChange( wxCommandEvent& event )
155{
156 double value;
157
158 if( m_updatingUI )
159 {
160 return;
161 }
162
163 wxString input = m_periodCtrl->GetValue();
164
165 if( input.ToDouble( &value ) )
166 {
167 if( value > 0 )
168 {
169 m_updatingPeriod = true;
170 update( 1 / ( value * m_periodUnit->GetUnitScale() ) );
171 }
172 }
173}
174
176{
177 if( m_updatingUI )
178 {
179 return;
180 }
181
182 double value;
183 wxString input = m_wavelengthVacuumCtrl->GetValue();
184
185 if( input.ToDouble( &value ) )
186 {
187 if( value > 0 )
188 {
191 update( SPEED_LIGHT / value );
192 }
193 }
194};
195
196
198{
199 if( m_updatingUI )
200 {
201 return;
202 }
203
204 double value;
205 wxString input = m_wavelengthMediumCtrl->GetValue();
206
207 if( input.ToDouble( &value ) )
208 {
209 if( value > 0 )
210 {
213 update( SPEED_LIGHT / value / sqrt( m_permittivity * m_permeability ) );
214 }
215 }
216};
217
218void PANEL_WAVELENGTH::OnPermittivityChange( wxCommandEvent& event )
219{
220 double value;
221 wxString input = m_permittivityCtrl->GetValue();
222
223 if( input.ToDouble( &value ) )
224 {
225 if( value >= 1 )
226 {
227 m_permittivity = value;
229 }
230 }
231}
232
233void PANEL_WAVELENGTH::OnPermeabilityChange( wxCommandEvent& event )
234{
235 double value;
236 wxString input = m_permeabilityCtrl->GetValue();
237
238 if( input.ToDouble( &value ) )
239 {
240 if( value >= 1 )
241 {
242 m_permeability = value;
244 }
245 }
246}
247
248void PANEL_WAVELENGTH::OnButtonPermittivity( wxCommandEvent& event )
249{
250 wxArrayString list = StandardRelativeDielectricConstantList();
251 list.Add( "" ); // Add an empty line for no selection
252
253 // Find the previous choice index:
254 wxString prevChoiceStr = m_permittivityCtrl->GetValue();
255 int prevChoice = 0;
256 findMatch( list, prevChoiceStr, prevChoice );
257
258 int index = wxGetSingleChoiceIndex( wxEmptyString, _( "Relative Dielectric Constants" ), list,
259 prevChoice );
260
261 if( index >= 0 && !list.Item( index ).IsEmpty() )
262 {
263 m_permittivityCtrl->SetValue( list.Item( index ).BeforeFirst( ' ' ) );
264 // wx automatically calls onPermittivity()
265 }
266}
const char * name
Definition: DXF_plotter.cpp:57
Class PANEL_WAVELENGTH_BASE.
UNIT_SELECTOR_FREQUENCY * m_frequencyUnit
UNIT_SELECTOR_TIME * m_periodUnit
UNIT_SELECTOR_LEN_CABLE * m_wavelengthVacuumUnit
UNIT_SELECTOR_LEN_CABLE * m_wavelengthMediumUnit
UNIT_SELECTOR_SPEED * m_speedUnit
void LoadSettings(PCB_CALCULATOR_SETTINGS *aCfg) override
Load the settings into the panel.
void OnPermittivityChange(wxCommandEvent &event) override
void updateUnits(wxCommandEvent &aEvent) override
void OnFrequencyChange(wxCommandEvent &event) override
void OnButtonPermittivity(wxCommandEvent &event) override
void OnPeriodChange(wxCommandEvent &event) override
void OnPermeabilityChange(wxCommandEvent &event) override
void OnWavelengthVacuumChange(wxCommandEvent &event) override
void OnWavelengthMediumChange(wxCommandEvent &event) override
PANEL_WAVELENGTH(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
void SaveSettings(PCB_CALCULATOR_SETTINGS *aCfg) override
Save the settings from the panel.
void update(double aFrequency)
double GetUnitScale() override
Function GetUnitScale.
double GetUnitScale() override
Function GetUnitScale.
double GetUnitScale() override
Function GetUnitScale.
double GetUnitScale() override
Function GetUnitScale.
wxArrayString StandardRelativeDielectricConstantList()
Definition: common_data.cpp:28
const int minSize
Push and Shove router track width and via size dialog.
#define _(s)
#define SPEED_LIGHT
bool findMatch(wxArrayString &aList, const wxString &aValue, int &aIdx)