committed by
Seth Hillbrand
15 changed files with 2191 additions and 83 deletions
-
3pcb_calculator/CMakeLists.txt
-
258pcb_calculator/calculator_panels/panel_wavelength.cpp
-
65pcb_calculator/calculator_panels/panel_wavelength.h
-
151pcb_calculator/calculator_panels/panel_wavelength_base.cpp
-
1372pcb_calculator/calculator_panels/panel_wavelength_base.fbp
-
84pcb_calculator/calculator_panels/panel_wavelength_base.h
-
5pcb_calculator/pcb_calculator_frame.cpp
-
24pcb_calculator/pcb_calculator_settings.cpp
-
14pcb_calculator/pcb_calculator_settings.h
-
92pcb_calculator/pcb_calculator_utils.cpp
-
32pcb_calculator/pcb_calculator_utils.h
-
83pcb_calculator/transline_dlg_funct.cpp
-
11pcb_calculator/units_scales.h
-
52pcb_calculator/widgets/unit_selector.cpp
-
28pcb_calculator/widgets/unit_selector.h
@ -0,0 +1,258 @@ |
|||
/*
|
|||
* This program source code file is part of KICAD, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 1992-2022 Kicad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 3 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along |
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
#include <calculator_panels/panel_wavelength.h>
|
|||
#include <pcb_calculator_settings.h>
|
|||
#include <string_utils.h>
|
|||
#include <widgets/unit_selector.h>
|
|||
#include <wx/choicdlg.h>
|
|||
#include "pcb_calculator_utils.h"
|
|||
#include "common_data.h"
|
|||
|
|||
#define SPEED_LIGHT 299792458
|
|||
|
|||
PANEL_WAVELENGTH::PANEL_WAVELENGTH( wxWindow* parent, wxWindowID id, const wxPoint& pos, |
|||
const wxSize& size, long style, const wxString& name ) : |
|||
PANEL_WAVELENGTH_BASE( parent, id, pos, size, style, name ) |
|||
{ |
|||
} |
|||
|
|||
void PANEL_WAVELENGTH::SaveSettings( PCB_CALCULATOR_SETTINGS* aCfg ) |
|||
{ |
|||
aCfg->m_wavelength.frequency = m_frequency; |
|||
aCfg->m_wavelength.permittivity = m_permittivity; |
|||
aCfg->m_wavelength.permeability = m_permeability; |
|||
|
|||
aCfg->m_wavelength.frequencyUnit = m_frequencyUnit->GetSelection(); |
|||
aCfg->m_wavelength.periodUnit = m_periodUnit->GetSelection(); |
|||
aCfg->m_wavelength.wavelengthVacuumUnit = m_wavelengthVacuumUnit->GetSelection(); |
|||
aCfg->m_wavelength.wavelengthMediumUnit = m_wavelengthMediumUnit->GetSelection(); |
|||
aCfg->m_wavelength.speedUnit = m_speedUnit->GetSelection(); |
|||
} |
|||
|
|||
|
|||
void PANEL_WAVELENGTH::LoadSettings( PCB_CALCULATOR_SETTINGS* aCfg ) |
|||
{ |
|||
m_frequencyUnit->SetSelection( aCfg->m_wavelength.frequencyUnit ); |
|||
m_periodUnit->SetSelection( aCfg->m_wavelength.periodUnit ); |
|||
m_wavelengthVacuumUnit->SetSelection( aCfg->m_wavelength.wavelengthVacuumUnit ); |
|||
m_wavelengthMediumUnit->SetSelection( aCfg->m_wavelength.wavelengthMediumUnit ); |
|||
m_speedUnit->SetSelection( aCfg->m_wavelength.speedUnit ); |
|||
|
|||
m_permittivity = aCfg->m_wavelength.permittivity; |
|||
m_permeability = aCfg->m_wavelength.permeability; |
|||
m_frequency = aCfg->m_wavelength.frequency; |
|||
|
|||
wxString value; |
|||
value = wxString( "" ) << m_permittivity; |
|||
m_permittivityCtrl->SetValue( value ); |
|||
value = wxString( "" ) << m_permeability; |
|||
m_permeabilityCtrl->SetValue( value ); |
|||
|
|||
update( m_frequency ); |
|||
} |
|||
|
|||
void PANEL_WAVELENGTH::updateUnits( wxCommandEvent& aEvent ) |
|||
{ |
|||
update( m_frequency ); |
|||
} |
|||
|
|||
|
|||
void PANEL_WAVELENGTH::update( double aFrequency ) |
|||
{ |
|||
m_updatingUI = true; |
|||
wxString value; |
|||
|
|||
if( !m_updatingFrequency ) |
|||
{ |
|||
value = wxString( "" ) << aFrequency / m_frequencyUnit->GetUnitScale(); |
|||
m_frequencyCtrl->SetValue( value ); |
|||
} |
|||
|
|||
if( !m_updatingPeriod ) |
|||
{ |
|||
value = wxString( "" ) << 1 / aFrequency / m_periodUnit->GetUnitScale(); |
|||
m_periodCtrl->SetValue( value ); |
|||
} |
|||
|
|||
if( !m_updatingWavelengthVacuum ) |
|||
{ |
|||
value = wxString( "" ) << SPEED_LIGHT / aFrequency / m_wavelengthVacuumUnit->GetUnitScale(); |
|||
m_wavelengthVacuumCtrl->SetValue( value ); |
|||
} |
|||
|
|||
if( !m_updatingWavelengthMedium ) |
|||
{ |
|||
value = wxString( "" ) << SPEED_LIGHT / aFrequency / sqrt( m_permittivity * m_permeability ) |
|||
/ m_wavelengthMediumUnit->GetUnitScale(); |
|||
m_wavelengthMediumCtrl->SetValue( value ); |
|||
} |
|||
|
|||
if( !m_updatingSpeed ) |
|||
{ |
|||
value = wxString( "" ) << SPEED_LIGHT / sqrt( m_permittivity * m_permeability ) |
|||
/ m_speedUnit->GetUnitScale(); |
|||
m_speedCtrl->SetValue( value ); |
|||
} |
|||
|
|||
m_frequency = aFrequency; |
|||
|
|||
m_updatingFrequency = false; |
|||
m_updatingPeriod = false; |
|||
m_updatingWavelengthVacuum = false; |
|||
m_updatingWavelengthMedium = false; |
|||
m_updatingSpeed = false; |
|||
|
|||
m_updatingUI = false; |
|||
} |
|||
|
|||
void PANEL_WAVELENGTH::OnFrequencyChange( wxCommandEvent& event ) |
|||
{ |
|||
double value; |
|||
|
|||
if( m_updatingUI ) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
wxString input = m_frequencyCtrl->GetValue(); |
|||
|
|||
if( input.ToDouble( &value ) ) |
|||
{ |
|||
if( value > 0 ) |
|||
{ |
|||
m_updatingFrequency = true; |
|||
update( value * m_frequencyUnit->GetUnitScale() ); |
|||
} |
|||
} |
|||
} |
|||
|
|||
void PANEL_WAVELENGTH::OnPeriodChange( wxCommandEvent& event ) |
|||
{ |
|||
double value; |
|||
|
|||
if( m_updatingUI ) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
wxString input = m_periodCtrl->GetValue(); |
|||
|
|||
if( input.ToDouble( &value ) ) |
|||
{ |
|||
if( value > 0 ) |
|||
{ |
|||
m_updatingPeriod = true; |
|||
update( 1 / ( value * m_periodUnit->GetUnitScale() ) ); |
|||
} |
|||
} |
|||
} |
|||
|
|||
void PANEL_WAVELENGTH::OnWavelengthVacuumChange( wxCommandEvent& event ) |
|||
{ |
|||
if( m_updatingUI ) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
double value; |
|||
wxString input = m_wavelengthVacuumCtrl->GetValue(); |
|||
|
|||
if( input.ToDouble( &value ) ) |
|||
{ |
|||
if( value > 0 ) |
|||
{ |
|||
value *= m_wavelengthVacuumUnit->GetUnitScale(); |
|||
m_updatingWavelengthVacuum = true; |
|||
update( SPEED_LIGHT / value ); |
|||
} |
|||
} |
|||
}; |
|||
|
|||
|
|||
void PANEL_WAVELENGTH::OnWavelengthMediumChange( wxCommandEvent& event ) |
|||
{ |
|||
if( m_updatingUI ) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
double value; |
|||
wxString input = m_wavelengthMediumCtrl->GetValue(); |
|||
|
|||
if( input.ToDouble( &value ) ) |
|||
{ |
|||
if( value > 0 ) |
|||
{ |
|||
value *= m_wavelengthMediumUnit->GetUnitScale(); |
|||
m_updatingWavelengthMedium = true; |
|||
update( SPEED_LIGHT / value / sqrt( m_permittivity * m_permeability ) ); |
|||
} |
|||
} |
|||
}; |
|||
|
|||
void PANEL_WAVELENGTH::OnPermittivityChange( wxCommandEvent& event ) |
|||
{ |
|||
double value; |
|||
wxString input = m_permittivityCtrl->GetValue(); |
|||
|
|||
if( input.ToDouble( &value ) ) |
|||
{ |
|||
if( value >= 1 ) |
|||
{ |
|||
m_permittivity = value; |
|||
update( m_frequency ); |
|||
} |
|||
} |
|||
} |
|||
|
|||
void PANEL_WAVELENGTH::OnPermeabilityChange( wxCommandEvent& event ) |
|||
{ |
|||
double value; |
|||
wxString input = m_permeabilityCtrl->GetValue(); |
|||
|
|||
if( input.ToDouble( &value ) ) |
|||
{ |
|||
if( value >= 1 ) |
|||
{ |
|||
m_permeability = value; |
|||
update( m_frequency ); |
|||
} |
|||
} |
|||
} |
|||
|
|||
void PANEL_WAVELENGTH::OnButtonPermittivity( wxCommandEvent& event ) |
|||
{ |
|||
wxArrayString list = StandardRelativeDielectricConstantList(); |
|||
list.Add( "" ); // Add an empty line for no selection
|
|||
|
|||
// Find the previous choice index:
|
|||
wxString prevChoiceStr = m_permittivityCtrl->GetValue(); |
|||
int prevChoice = 0; |
|||
findMatch( list, prevChoiceStr, prevChoice ); |
|||
|
|||
int index = wxGetSingleChoiceIndex( wxEmptyString, _( "Relative Dielectric Constants" ), list, |
|||
prevChoice ); |
|||
|
|||
if( index >= 0 && !list.Item( index ).IsEmpty() ) |
|||
{ |
|||
m_permittivityCtrl->SetValue( list.Item( index ).BeforeFirst( ' ' ) ); |
|||
// wx automatically calls onPermittivity()
|
|||
} |
|||
} |
@ -0,0 +1,65 @@ |
|||
/* |
|||
* This program source code file is part of KICAD, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 1992-2022 Kicad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 3 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along |
|||
* with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#ifndef PANEL_WAVELENGTH_H |
|||
#define PANEL_WAVELENGTH_H |
|||
|
|||
#include "panel_wavelength_base.h" |
|||
|
|||
class PCB_CALCULATOR_SETTINGS; |
|||
|
|||
class PANEL_WAVELENGTH : public PANEL_WAVELENGTH_BASE |
|||
{ |
|||
public: |
|||
PANEL_WAVELENGTH( wxWindow* parent, wxWindowID id = wxID_ANY, |
|||
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, |
|||
long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString ); |
|||
~PANEL_WAVELENGTH(){}; |
|||
|
|||
// Methods from CALCULATOR_PANEL that must be overriden |
|||
void LoadSettings( PCB_CALCULATOR_SETTINGS* aCfg ) override; |
|||
void SaveSettings( PCB_CALCULATOR_SETTINGS* aCfg ) override; |
|||
void ThemeChanged() override{}; |
|||
|
|||
void OnFrequencyChange( wxCommandEvent& event ); |
|||
void OnPeriodChange( wxCommandEvent& event ); |
|||
void OnWavelengthVacuumChange( wxCommandEvent& event ); |
|||
void OnWavelengthMediumChange( wxCommandEvent& event ); |
|||
void OnPermittivityChange( wxCommandEvent& event ); |
|||
void OnPermeabilityChange( wxCommandEvent& event ); |
|||
void OnButtonPermittivity( wxCommandEvent& event ); |
|||
|
|||
private: |
|||
void update( double aFrequency ); |
|||
void updateUnits( wxCommandEvent& aEvent ); |
|||
|
|||
double m_permittivity = 1; |
|||
double m_permeability = 1; |
|||
double m_frequency = 1; |
|||
|
|||
bool m_updatingFrequency = false; |
|||
bool m_updatingPeriod = false; |
|||
bool m_updatingWavelengthVacuum = false; |
|||
bool m_updatingWavelengthMedium = false; |
|||
bool m_updatingSpeed = false; |
|||
|
|||
bool m_updatingUI = false; |
|||
}; |
|||
|
|||
#endif |
@ -0,0 +1,151 @@ |
|||
///////////////////////////////////////////////////////////////////////////
|
|||
// C++ code generated with wxFormBuilder (version 3.10.1)
|
|||
// http://www.wxformbuilder.org/
|
|||
//
|
|||
// PLEASE DO *NOT* EDIT THIS FILE!
|
|||
///////////////////////////////////////////////////////////////////////////
|
|||
|
|||
#include "widgets/unit_selector.h"
|
|||
|
|||
#include "panel_wavelength_base.h"
|
|||
|
|||
///////////////////////////////////////////////////////////////////////////
|
|||
|
|||
PANEL_WAVELENGTH_BASE::PANEL_WAVELENGTH_BASE( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) : CALCULATOR_PANEL( parent, id, pos, size, style, name ) |
|||
{ |
|||
wxBoxSizer* bSizer6; |
|||
bSizer6 = new wxBoxSizer( wxVERTICAL ); |
|||
|
|||
wxBoxSizer* bSizer4; |
|||
bSizer4 = new wxBoxSizer( wxVERTICAL ); |
|||
|
|||
wxFlexGridSizer* fgSizer3; |
|||
fgSizer3 = new wxFlexGridSizer( 0, 3, 0, 0 ); |
|||
fgSizer3->SetFlexibleDirection( wxBOTH ); |
|||
fgSizer3->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); |
|||
|
|||
m_staticText18 = new wxStaticText( this, wxID_ANY, _("Frequency:"), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_staticText18->Wrap( -1 ); |
|||
fgSizer3->Add( m_staticText18, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 ); |
|||
|
|||
m_frequencyCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); |
|||
fgSizer3->Add( m_frequencyCtrl, 0, wxALL|wxEXPAND, 5 ); |
|||
|
|||
wxArrayString m_frequencyUnitChoices; |
|||
m_frequencyUnit = new UNIT_SELECTOR_FREQUENCY( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_frequencyUnitChoices, 0 ); |
|||
m_frequencyUnit->SetSelection( 0 ); |
|||
fgSizer3->Add( m_frequencyUnit, 0, wxALL, 5 ); |
|||
|
|||
m_staticText181 = new wxStaticText( this, wxID_ANY, _("Period:"), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_staticText181->Wrap( -1 ); |
|||
fgSizer3->Add( m_staticText181, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 ); |
|||
|
|||
m_periodCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); |
|||
fgSizer3->Add( m_periodCtrl, 0, wxALL, 5 ); |
|||
|
|||
wxArrayString m_periodUnitChoices; |
|||
m_periodUnit = new UNIT_SELECTOR_TIME( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_periodUnitChoices, 0 ); |
|||
m_periodUnit->SetSelection( 0 ); |
|||
fgSizer3->Add( m_periodUnit, 0, wxALL, 5 ); |
|||
|
|||
m_staticText1811 = new wxStaticText( this, wxID_ANY, _("Wavelength in vacuum:"), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_staticText1811->Wrap( -1 ); |
|||
fgSizer3->Add( m_staticText1811, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 ); |
|||
|
|||
m_wavelengthVacuumCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); |
|||
fgSizer3->Add( m_wavelengthVacuumCtrl, 0, wxALL, 5 ); |
|||
|
|||
wxArrayString m_wavelengthVacuumUnitChoices; |
|||
m_wavelengthVacuumUnit = new UNIT_SELECTOR_LEN_CABLE( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_wavelengthVacuumUnitChoices, 0 ); |
|||
m_wavelengthVacuumUnit->SetSelection( 0 ); |
|||
fgSizer3->Add( m_wavelengthVacuumUnit, 0, wxALL, 5 ); |
|||
|
|||
m_staticText18111 = new wxStaticText( this, wxID_ANY, _("Wavelength in medium:"), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_staticText18111->Wrap( -1 ); |
|||
fgSizer3->Add( m_staticText18111, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 ); |
|||
|
|||
m_wavelengthMediumCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); |
|||
fgSizer3->Add( m_wavelengthMediumCtrl, 0, wxALL, 5 ); |
|||
|
|||
wxArrayString m_wavelengthMediumUnitChoices; |
|||
m_wavelengthMediumUnit = new UNIT_SELECTOR_LEN_CABLE( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_wavelengthMediumUnitChoices, 0 ); |
|||
m_wavelengthMediumUnit->SetSelection( 0 ); |
|||
fgSizer3->Add( m_wavelengthMediumUnit, 0, wxALL, 5 ); |
|||
|
|||
m_staticText181112 = new wxStaticText( this, wxID_ANY, _("Speed in medium:"), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_staticText181112->Wrap( -1 ); |
|||
fgSizer3->Add( m_staticText181112, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 ); |
|||
|
|||
m_speedCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_speedCtrl->Enable( false ); |
|||
|
|||
fgSizer3->Add( m_speedCtrl, 0, wxALL, 5 ); |
|||
|
|||
wxArrayString m_speedUnitChoices; |
|||
m_speedUnit = new UNIT_SELECTOR_SPEED( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_speedUnitChoices, 0 ); |
|||
m_speedUnit->SetSelection( 0 ); |
|||
fgSizer3->Add( m_speedUnit, 0, wxALL, 5 ); |
|||
|
|||
m_staticText181111 = new wxStaticText( this, wxID_ANY, _("er:"), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_staticText181111->Wrap( -1 ); |
|||
m_staticText181111->SetToolTip( _("relative permittivity (dielectric constant)") ); |
|||
|
|||
fgSizer3->Add( m_staticText181111, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 ); |
|||
|
|||
m_permittivityCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); |
|||
fgSizer3->Add( m_permittivityCtrl, 0, wxALL, 5 ); |
|||
|
|||
m_button1 = new wxButton( this, wxID_ANY, _("..."), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
fgSizer3->Add( m_button1, 0, wxALL, 5 ); |
|||
|
|||
m_staticText42 = new wxStaticText( this, wxID_ANY, _("mur:"), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_staticText42->Wrap( -1 ); |
|||
m_staticText42->SetToolTip( _("relative permeability") ); |
|||
|
|||
fgSizer3->Add( m_staticText42, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 ); |
|||
|
|||
m_permeabilityCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); |
|||
fgSizer3->Add( m_permeabilityCtrl, 0, wxALL, 5 ); |
|||
|
|||
|
|||
bSizer4->Add( fgSizer3, 1, wxEXPAND, 5 ); |
|||
|
|||
|
|||
bSizer6->Add( bSizer4, 1, wxEXPAND, 5 ); |
|||
|
|||
|
|||
this->SetSizer( bSizer6 ); |
|||
this->Layout(); |
|||
|
|||
// Connect Events
|
|||
m_frequencyCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_WAVELENGTH_BASE::OnFrequencyChange ), NULL, this ); |
|||
m_frequencyUnit->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PANEL_WAVELENGTH_BASE::updateUnits ), NULL, this ); |
|||
m_periodCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_WAVELENGTH_BASE::OnPeriodChange ), NULL, this ); |
|||
m_periodUnit->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PANEL_WAVELENGTH_BASE::updateUnits ), NULL, this ); |
|||
m_wavelengthVacuumCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_WAVELENGTH_BASE::OnWavelengthVacuumChange ), NULL, this ); |
|||
m_wavelengthVacuumUnit->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PANEL_WAVELENGTH_BASE::updateUnits ), NULL, this ); |
|||
m_wavelengthMediumCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_WAVELENGTH_BASE::OnWavelengthMediumChange ), NULL, this ); |
|||
m_wavelengthMediumUnit->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PANEL_WAVELENGTH_BASE::updateUnits ), NULL, this ); |
|||
m_speedUnit->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PANEL_WAVELENGTH_BASE::updateUnits ), NULL, this ); |
|||
m_permittivityCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_WAVELENGTH_BASE::OnPermittivityChange ), NULL, this ); |
|||
m_button1->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_WAVELENGTH_BASE::OnButtonPermittivity ), NULL, this ); |
|||
m_permeabilityCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_WAVELENGTH_BASE::OnPermeabilityChange ), NULL, this ); |
|||
} |
|||
|
|||
PANEL_WAVELENGTH_BASE::~PANEL_WAVELENGTH_BASE() |
|||
{ |
|||
// Disconnect Events
|
|||
m_frequencyCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_WAVELENGTH_BASE::OnFrequencyChange ), NULL, this ); |
|||
m_frequencyUnit->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PANEL_WAVELENGTH_BASE::updateUnits ), NULL, this ); |
|||
m_periodCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_WAVELENGTH_BASE::OnPeriodChange ), NULL, this ); |
|||
m_periodUnit->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PANEL_WAVELENGTH_BASE::updateUnits ), NULL, this ); |
|||
m_wavelengthVacuumCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_WAVELENGTH_BASE::OnWavelengthVacuumChange ), NULL, this ); |
|||
m_wavelengthVacuumUnit->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PANEL_WAVELENGTH_BASE::updateUnits ), NULL, this ); |
|||
m_wavelengthMediumCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_WAVELENGTH_BASE::OnWavelengthMediumChange ), NULL, this ); |
|||
m_wavelengthMediumUnit->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PANEL_WAVELENGTH_BASE::updateUnits ), NULL, this ); |
|||
m_speedUnit->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PANEL_WAVELENGTH_BASE::updateUnits ), NULL, this ); |
|||
m_permittivityCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_WAVELENGTH_BASE::OnPermittivityChange ), NULL, this ); |
|||
m_button1->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_WAVELENGTH_BASE::OnButtonPermittivity ), NULL, this ); |
|||
m_permeabilityCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_WAVELENGTH_BASE::OnPermeabilityChange ), NULL, this ); |
|||
|
|||
} |
1372
pcb_calculator/calculator_panels/panel_wavelength_base.fbp
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,84 @@ |
|||
/////////////////////////////////////////////////////////////////////////// |
|||
// C++ code generated with wxFormBuilder (version 3.10.1) |
|||
// http://www.wxformbuilder.org/ |
|||
// |
|||
// PLEASE DO *NOT* EDIT THIS FILE! |
|||
/////////////////////////////////////////////////////////////////////////// |
|||
|
|||
#pragma once |
|||
|
|||
#include <wx/artprov.h> |
|||
#include <wx/xrc/xmlres.h> |
|||
#include <wx/intl.h> |
|||
class UNIT_SELECTOR_FREQUENCY; |
|||
class UNIT_SELECTOR_LEN_CABLE; |
|||
class UNIT_SELECTOR_SPEED; |
|||
class UNIT_SELECTOR_TIME; |
|||
|
|||
#include "calculator_panels/calculator_panel.h" |
|||
#include <wx/string.h> |
|||
#include <wx/stattext.h> |
|||
#include <wx/gdicmn.h> |
|||
#include <wx/font.h> |
|||
#include <wx/colour.h> |
|||
#include <wx/settings.h> |
|||
#include <wx/textctrl.h> |
|||
#include <wx/choice.h> |
|||
#include <wx/button.h> |
|||
#include <wx/bitmap.h> |
|||
#include <wx/image.h> |
|||
#include <wx/icon.h> |
|||
#include <wx/sizer.h> |
|||
#include <wx/panel.h> |
|||
|
|||
/////////////////////////////////////////////////////////////////////////// |
|||
|
|||
|
|||
/////////////////////////////////////////////////////////////////////////////// |
|||
/// Class PANEL_WAVELENGTH_BASE |
|||
/////////////////////////////////////////////////////////////////////////////// |
|||
class PANEL_WAVELENGTH_BASE : public CALCULATOR_PANEL |
|||
{ |
|||
private: |
|||
|
|||
protected: |
|||
wxStaticText* m_staticText18; |
|||
wxTextCtrl* m_frequencyCtrl; |
|||
UNIT_SELECTOR_FREQUENCY* m_frequencyUnit; |
|||
wxStaticText* m_staticText181; |
|||
wxTextCtrl* m_periodCtrl; |
|||
UNIT_SELECTOR_TIME* m_periodUnit; |
|||
wxStaticText* m_staticText1811; |
|||
wxTextCtrl* m_wavelengthVacuumCtrl; |
|||
UNIT_SELECTOR_LEN_CABLE* m_wavelengthVacuumUnit; |
|||
wxStaticText* m_staticText18111; |
|||
wxTextCtrl* m_wavelengthMediumCtrl; |
|||
UNIT_SELECTOR_LEN_CABLE* m_wavelengthMediumUnit; |
|||
wxStaticText* m_staticText181112; |
|||
wxTextCtrl* m_speedCtrl; |
|||
UNIT_SELECTOR_SPEED* m_speedUnit; |
|||
wxStaticText* m_staticText181111; |
|||
wxTextCtrl* m_permittivityCtrl; |
|||
wxButton* m_button1; |
|||
wxStaticText* m_staticText42; |
|||
wxTextCtrl* m_permeabilityCtrl; |
|||
|
|||
// Virtual event handlers, override them in your derived class |
|||
virtual void OnFrequencyChange( wxCommandEvent& event ) { event.Skip(); } |
|||
virtual void updateUnits( wxCommandEvent& event ) { event.Skip(); } |
|||
virtual void OnPeriodChange( wxCommandEvent& event ) { event.Skip(); } |
|||
virtual void OnWavelengthVacuumChange( wxCommandEvent& event ) { event.Skip(); } |
|||
virtual void OnWavelengthMediumChange( wxCommandEvent& event ) { event.Skip(); } |
|||
virtual void OnPermittivityChange( wxCommandEvent& event ) { event.Skip(); } |
|||
virtual void OnButtonPermittivity( wxCommandEvent& event ) { event.Skip(); } |
|||
virtual void OnPermeabilityChange( wxCommandEvent& event ) { event.Skip(); } |
|||
|
|||
|
|||
public: |
|||
|
|||
PANEL_WAVELENGTH_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 736,453 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString ); |
|||
|
|||
~PANEL_WAVELENGTH_BASE(); |
|||
|
|||
}; |
|||
|
@ -0,0 +1,92 @@ |
|||
/*
|
|||
* This program source code file is part of KICAD, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 1992-2022 Kicad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 3 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along |
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
#include <pcb_calculator_utils.h>
|
|||
|
|||
bool findMatch( wxArrayString& aList, const wxString& aValue, int& aIdx ) |
|||
{ |
|||
bool success = false; |
|||
// Find the previous choice index:
|
|||
aIdx = 0; |
|||
|
|||
// Some countries use comma instead of point as separator.
|
|||
// The value can be enter with pint or comma
|
|||
// use point for string comparisons:
|
|||
wxString cvalue = aValue; |
|||
cvalue.Replace( ',', '.' ); |
|||
|
|||
// First compare strings:
|
|||
for( wxString& text : aList ) |
|||
{ |
|||
if( text.IsEmpty() ) // No match found: select the empty line choice
|
|||
break; |
|||
|
|||
wxString val_str = text.BeforeFirst( ' ' ); |
|||
val_str.Replace( ',', '.' ); |
|||
|
|||
// compare string values
|
|||
if( val_str == cvalue ) |
|||
{ |
|||
success = true; |
|||
break; |
|||
} |
|||
|
|||
aIdx++; |
|||
} |
|||
|
|||
// Due to multiple ways to write a double, if string values
|
|||
// do not match, compare double values
|
|||
if( !success ) |
|||
{ |
|||
struct lconv* lc = localeconv(); |
|||
char localeDecimalSeparator = *lc->decimal_point; |
|||
|
|||
if( localeDecimalSeparator == ',' ) |
|||
cvalue.Replace( '.', ',' ); |
|||
|
|||
double curr_value; |
|||
cvalue.ToDouble( &curr_value ); |
|||
|
|||
aIdx = 0; |
|||
|
|||
for( wxString& text : aList ) |
|||
{ |
|||
if( text.IsEmpty() ) // No match found: select the empty line choice
|
|||
break; |
|||
|
|||
double val; |
|||
wxString val_str = text.BeforeFirst( ' ' ); |
|||
|
|||
if( localeDecimalSeparator == ',' ) |
|||
val_str.Replace( '.', ',' ); |
|||
|
|||
val_str.ToDouble( &val );; |
|||
|
|||
if( curr_value == val ) |
|||
{ |
|||
success = true; |
|||
break; |
|||
} |
|||
|
|||
aIdx++; |
|||
} |
|||
} |
|||
|
|||
return success; |
|||
} |
@ -0,0 +1,32 @@ |
|||
/* |
|||
* This program source code file is part of KICAD, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 1992-2022 Kicad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 3 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along |
|||
* with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include <wx/string.h> |
|||
#include <wx/arrstr.h> |
|||
|
|||
#ifndef PCB_CALCULATOR_UTILS_H |
|||
#define PCB_CALCULATOR_UTILS_H |
|||
// Display a selection of usual Er, TanD, Rho values |
|||
// List format is <value><space><comment> |
|||
|
|||
// A helper function to find the choice in a list of values |
|||
// return true if a index in aList that matches aValue is found. |
|||
bool findMatch( wxArrayString& aList, const wxString& aValue, int& aIdx ); |
|||
|
|||
#endif |
Write
Preview
Loading…
Cancel
Save
Reference in new issue