Browse Source
pcb_calculator rework: move attenuators panel to its own files panel_attenuators_xx
6.0.7
pcb_calculator rework: move attenuators panel to its own files panel_attenuators_xx
6.0.7
12 changed files with 2342 additions and 2148 deletions
-
3pcb_calculator/CMakeLists.txt
-
160pcb_calculator/attenuators.cpp
-
53pcb_calculator/dialogs/panel_attenuators.h
-
195pcb_calculator/dialogs/panel_attenuators_base.cpp
-
1767pcb_calculator/dialogs/panel_attenuators_base.fbp
-
80pcb_calculator/dialogs/panel_attenuators_base.h
-
176pcb_calculator/dialogs/pcb_calculator_frame_base.cpp
-
1719pcb_calculator/dialogs/pcb_calculator_frame_base.fbp
-
42pcb_calculator/dialogs/pcb_calculator_frame_base.h
-
223pcb_calculator/panel_attenuators.cpp
-
48pcb_calculator/pcb_calculator_frame.cpp
-
24pcb_calculator/pcb_calculator_frame.h
@ -1,160 +0,0 @@ |
|||
/**
|
|||
* @file attenuators.cpp |
|||
*/ |
|||
|
|||
/*
|
|||
* This program source code file is part of KICAD, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2015 jean-pierre.charras |
|||
* Copyright (C) 2015 Kicad Developers, see change_log.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 2 |
|||
* 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, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|||
* or you may search the http://www.gnu.org website for the version 2 license,
|
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#include <string_utils.h>
|
|||
|
|||
#include "pcb_calculator_frame.h"
|
|||
|
|||
extern double DoubleFromString( const wxString& TextValue ); |
|||
|
|||
// Called on a attenuator selection
|
|||
void PCB_CALCULATOR_FRAME::OnAttenuatorSelection( wxCommandEvent& event ) |
|||
{ |
|||
SetAttenuator( (unsigned) event.GetSelection() ); |
|||
Refresh(); |
|||
} |
|||
|
|||
|
|||
void PCB_CALCULATOR_FRAME::SetAttenuator( unsigned aIdx ) |
|||
{ |
|||
if( aIdx >=m_attenuator_list.size() ) |
|||
aIdx = m_attenuator_list.size() - 1; |
|||
|
|||
m_currAttenuator = m_attenuator_list[aIdx]; |
|||
TransfAttenuatorDataToPanel(); |
|||
m_Attenuator_Messages->SetPage( wxEmptyString ); |
|||
m_Att_R1_Value->SetValue( wxEmptyString ); |
|||
m_Att_R2_Value->SetValue( wxEmptyString ); |
|||
m_Att_R3_Value->SetValue( wxEmptyString ); |
|||
} |
|||
|
|||
|
|||
void PCB_CALCULATOR_FRAME::OnCalculateAttenuator( wxCommandEvent& event ) |
|||
{ |
|||
TransfPanelDataToAttenuator(); |
|||
m_currAttenuator->Calculate(); |
|||
TransfAttenuatorResultsToPanel(); |
|||
} |
|||
|
|||
|
|||
void PCB_CALCULATOR_FRAME::TransfPanelDataToAttenuator() |
|||
{ |
|||
wxString msg; |
|||
|
|||
msg = m_AttValueCtrl->GetValue(); |
|||
m_currAttenuator->m_Attenuation = DoubleFromString(msg); |
|||
msg = m_ZinValueCtrl->GetValue(); |
|||
m_currAttenuator->m_Zin = DoubleFromString(msg); |
|||
msg = m_ZoutValueCtrl->GetValue(); |
|||
m_currAttenuator->m_Zout = DoubleFromString(msg); |
|||
} |
|||
|
|||
|
|||
void PCB_CALCULATOR_FRAME::TransfAttenuatorDataToPanel() |
|||
{ |
|||
m_attenuatorBitmap->SetBitmap( *m_currAttenuator->m_SchBitMap ); |
|||
|
|||
wxString msg; |
|||
|
|||
msg.Printf( wxT( "%g" ), m_currAttenuator->m_Attenuation ); |
|||
m_AttValueCtrl->SetValue( msg ); |
|||
m_AttValueCtrl->Enable( m_currAttenuator->m_Attenuation_Enable ); |
|||
|
|||
m_ZinValueCtrl->Enable( m_currAttenuator->m_Zin_Enable ); |
|||
|
|||
if( m_currAttenuator->m_Zin_Enable ) |
|||
msg.Printf( wxT( "%g" ), m_currAttenuator->m_Zin ); |
|||
else |
|||
msg.Clear(); |
|||
|
|||
m_ZinValueCtrl->SetValue( msg ); |
|||
|
|||
msg.Printf( wxT( "%g" ), m_currAttenuator->m_Zout ); |
|||
m_ZoutValueCtrl->SetValue( msg ); |
|||
|
|||
if( m_currAttenuator->m_FormulaName ) |
|||
{ |
|||
if( m_currAttenuator->m_FormulaName->StartsWith( "<!" ) ) |
|||
{ |
|||
m_panelAttFormula->SetPage( *m_currAttenuator->m_FormulaName ); |
|||
} |
|||
else |
|||
{ |
|||
wxString html_txt; |
|||
ConvertMarkdown2Html( wxGetTranslation( *m_currAttenuator->m_FormulaName ), html_txt ); |
|||
m_panelAttFormula->SetPage( html_txt ); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
m_panelAttFormula->SetPage( wxEmptyString ); |
|||
} |
|||
} |
|||
|
|||
|
|||
void PCB_CALCULATOR_FRAME::TransfAttenuatorResultsToPanel() |
|||
{ |
|||
wxString msg; |
|||
|
|||
m_Attenuator_Messages->SetPage( wxEmptyString ); |
|||
|
|||
if( m_currAttenuator->m_Error ) |
|||
{ |
|||
msg.Printf( _( "Attenuation more than %f dB" ), |
|||
m_currAttenuator->m_MinimumATT ); |
|||
m_Attenuator_Messages->AppendToPage( wxT( "<br><b>Error!</b></br><br><em>" ) ); |
|||
m_Attenuator_Messages->AppendToPage( msg ); |
|||
m_Attenuator_Messages->AppendToPage( wxT( "</em></br>" ) ); |
|||
|
|||
// Display -- as resistor values:
|
|||
msg = wxT( "--" ); |
|||
m_Att_R1_Value->SetValue( msg ); |
|||
m_Att_R2_Value->SetValue( msg ); |
|||
if( m_currAttenuator->m_ResultCount >= 3 ) |
|||
m_Att_R3_Value->SetValue( msg ); |
|||
|
|||
return; |
|||
} |
|||
|
|||
msg.Printf( wxT( "%g" ), m_currAttenuator->m_R1 ); |
|||
m_Att_R1_Value->SetValue( msg ); |
|||
msg.Printf( wxT( "%g" ), m_currAttenuator->m_R2 ); |
|||
m_Att_R2_Value->SetValue( msg ); |
|||
|
|||
if( m_currAttenuator->m_ResultCount < 3 ) |
|||
{ |
|||
m_Att_R3_Value->SetValue( wxEmptyString ); |
|||
} |
|||
else |
|||
{ |
|||
msg.Printf( wxT( "%g" ), m_currAttenuator->m_R3 ); |
|||
m_Att_R3_Value->SetValue( msg ); |
|||
} |
|||
} |
|||
|
|||
|
@ -0,0 +1,53 @@ |
|||
/* |
|||
* This program source code file is part of KICAD, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 1992-2021 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_ATTENUATORS_H |
|||
#define PANEL_ATTENUATORS_H |
|||
#include "panel_attenuators_base.h" |
|||
|
|||
class ATTENUATOR; |
|||
|
|||
class PANEL_ATTENUATORS : public PANEL_ATTENUATORS_BASE |
|||
{ |
|||
public: |
|||
PANEL_ATTENUATORS( wxWindow* parent, wxWindowID id = wxID_ANY, |
|||
const wxPoint& pos = wxDefaultPosition, |
|||
const wxSize& size = wxDefaultSize, |
|||
long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString ); |
|||
~PANEL_ATTENUATORS(); |
|||
|
|||
wxRadioBox* GetAttenuatorsSelector() { return m_AttenuatorsSelection; } |
|||
void LoadSettings( PCB_CALCULATOR_SETTINGS* aCfg ); |
|||
void SaveSettings( PCB_CALCULATOR_SETTINGS* aCfg ); |
|||
void UpdateUI(); // Update bitmaps |
|||
|
|||
void OnAttenuatorSelection( wxCommandEvent& event ) override; |
|||
void SetAttenuator( unsigned aIdx ); |
|||
void OnCalculateAttenuator( wxCommandEvent& event ) override; |
|||
void TransfPanelDataToAttenuator(); |
|||
void TransfAttenuatorDataToPanel(); |
|||
void TransfAttenuatorResultsToPanel(); |
|||
|
|||
public: |
|||
ATTENUATOR* m_CurrAttenuator; |
|||
std::vector<ATTENUATOR*> m_AttenuatorList; |
|||
|
|||
}; |
|||
|
|||
#endif |
@ -0,0 +1,195 @@ |
|||
///////////////////////////////////////////////////////////////////////////
|
|||
// C++ code generated with wxFormBuilder (version Oct 26 2018)
|
|||
// http://www.wxformbuilder.org/
|
|||
//
|
|||
// PLEASE DO *NOT* EDIT THIS FILE!
|
|||
///////////////////////////////////////////////////////////////////////////
|
|||
|
|||
#include "panel_attenuators_base.h"
|
|||
|
|||
///////////////////////////////////////////////////////////////////////////
|
|||
|
|||
PANEL_ATTENUATORS_BASE::PANEL_ATTENUATORS_BASE( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) : wxPanel( parent, id, pos, size, style, name ) |
|||
{ |
|||
wxBoxSizer* bSizerAtt; |
|||
bSizerAtt = new wxBoxSizer( wxHORIZONTAL ); |
|||
|
|||
wxBoxSizer* bLeftSizerAtt; |
|||
bLeftSizerAtt = new wxBoxSizer( wxVERTICAL ); |
|||
|
|||
bLeftSizerAtt->SetMinSize( wxSize( 260,-1 ) ); |
|||
wxString m_AttenuatorsSelectionChoices[] = { _("PI"), _("Tee"), _("Bridged tee"), _("Resistive splitter") }; |
|||
int m_AttenuatorsSelectionNChoices = sizeof( m_AttenuatorsSelectionChoices ) / sizeof( wxString ); |
|||
m_AttenuatorsSelection = new wxRadioBox( this, wxID_ANY, _("Attenuators"), wxDefaultPosition, wxDefaultSize, m_AttenuatorsSelectionNChoices, m_AttenuatorsSelectionChoices, 1, wxRA_SPECIFY_COLS ); |
|||
m_AttenuatorsSelection->SetSelection( 2 ); |
|||
bLeftSizerAtt->Add( m_AttenuatorsSelection, 0, wxEXPAND|wxALL, 5 ); |
|||
|
|||
|
|||
bLeftSizerAtt->Add( 0, 5, 0, wxEXPAND, 5 ); |
|||
|
|||
m_attenuatorBitmap = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); |
|||
bLeftSizerAtt->Add( m_attenuatorBitmap, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 10 ); |
|||
|
|||
|
|||
bSizerAtt->Add( bLeftSizerAtt, 0, wxEXPAND|wxRIGHT, 5 ); |
|||
|
|||
wxBoxSizer* bMiddleSizerAtt; |
|||
bMiddleSizerAtt = new wxBoxSizer( wxVERTICAL ); |
|||
|
|||
wxStaticBoxSizer* sbSizerAttPrms; |
|||
sbSizerAttPrms = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Parameters") ), wxVERTICAL ); |
|||
|
|||
wxFlexGridSizer* fgSizerAttPrms; |
|||
fgSizerAttPrms = new wxFlexGridSizer( 3, 3, 3, 0 ); |
|||
fgSizerAttPrms->AddGrowableRow( 1 ); |
|||
fgSizerAttPrms->SetFlexibleDirection( wxBOTH ); |
|||
fgSizerAttPrms->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); |
|||
|
|||
m_attenuationLabel = new wxStaticText( sbSizerAttPrms->GetStaticBox(), wxID_ANY, _("Attenuation:"), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_attenuationLabel->Wrap( -1 ); |
|||
fgSizerAttPrms->Add( m_attenuationLabel, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); |
|||
|
|||
m_AttValueCtrl = new wxTextCtrl( sbSizerAttPrms->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); |
|||
fgSizerAttPrms->Add( m_AttValueCtrl, 0, wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 ); |
|||
|
|||
m_attUnit = new wxStaticText( sbSizerAttPrms->GetStaticBox(), wxID_ANY, _("dB"), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_attUnit->Wrap( -1 ); |
|||
fgSizerAttPrms->Add( m_attUnit, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 ); |
|||
|
|||
m_attenuationZinLabel = new wxStaticText( sbSizerAttPrms->GetStaticBox(), wxID_ANY, _("Zin:"), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_attenuationZinLabel->Wrap( -1 ); |
|||
fgSizerAttPrms->Add( m_attenuationZinLabel, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); |
|||
|
|||
m_ZinValueCtrl = new wxTextCtrl( sbSizerAttPrms->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); |
|||
fgSizerAttPrms->Add( m_ZinValueCtrl, 0, wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 ); |
|||
|
|||
m_attZinUnit = new wxStaticText( sbSizerAttPrms->GetStaticBox(), wxID_ANY, _("Ohms"), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_attZinUnit->Wrap( -1 ); |
|||
fgSizerAttPrms->Add( m_attZinUnit, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 ); |
|||
|
|||
m_ZoutLabel = new wxStaticText( sbSizerAttPrms->GetStaticBox(), wxID_ANY, _("Zout:"), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_ZoutLabel->Wrap( -1 ); |
|||
fgSizerAttPrms->Add( m_ZoutLabel, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); |
|||
|
|||
m_ZoutValueCtrl = new wxTextCtrl( sbSizerAttPrms->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); |
|||
fgSizerAttPrms->Add( m_ZoutValueCtrl, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 ); |
|||
|
|||
m_attZoutUnit = new wxStaticText( sbSizerAttPrms->GetStaticBox(), wxID_ANY, _("Ohms"), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_attZoutUnit->Wrap( -1 ); |
|||
fgSizerAttPrms->Add( m_attZoutUnit, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 ); |
|||
|
|||
|
|||
sbSizerAttPrms->Add( fgSizerAttPrms, 0, wxEXPAND|wxBOTTOM, 5 ); |
|||
|
|||
|
|||
bMiddleSizerAtt->Add( sbSizerAttPrms, 0, wxEXPAND|wxTOP|wxBOTTOM|wxRIGHT, 5 ); |
|||
|
|||
wxBoxSizer* bSizerAttButt; |
|||
bSizerAttButt = new wxBoxSizer( wxHORIZONTAL ); |
|||
|
|||
m_buttonAlcAtt = new wxButton( this, wxID_ANY, _("Calculate"), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
bSizerAttButt->Add( m_buttonAlcAtt, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); |
|||
|
|||
m_bpButtonCalcAtt = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 ); |
|||
bSizerAttButt->Add( m_bpButtonCalcAtt, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); |
|||
|
|||
|
|||
bMiddleSizerAtt->Add( bSizerAttButt, 0, wxALIGN_CENTER_HORIZONTAL, 5 ); |
|||
|
|||
wxStaticBoxSizer* sbSizerAttValues; |
|||
sbSizerAttValues = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Values") ), wxVERTICAL ); |
|||
|
|||
wxFlexGridSizer* fgSizerAttResults; |
|||
fgSizerAttResults = new wxFlexGridSizer( 3, 3, 3, 0 ); |
|||
fgSizerAttResults->AddGrowableCol( 1 ); |
|||
fgSizerAttResults->SetFlexibleDirection( wxBOTH ); |
|||
fgSizerAttResults->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); |
|||
|
|||
m_attenuatorR1Label = new wxStaticText( sbSizerAttValues->GetStaticBox(), wxID_ANY, _("R1:"), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_attenuatorR1Label->Wrap( -1 ); |
|||
fgSizerAttResults->Add( m_attenuatorR1Label, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); |
|||
|
|||
m_Att_R1_Value = new wxTextCtrl( sbSizerAttValues->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); |
|||
fgSizerAttResults->Add( m_Att_R1_Value, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT|wxEXPAND, 5 ); |
|||
|
|||
m_attR1Unit = new wxStaticText( sbSizerAttValues->GetStaticBox(), wxID_ANY, _("Ohms"), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_attR1Unit->Wrap( -1 ); |
|||
fgSizerAttResults->Add( m_attR1Unit, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 ); |
|||
|
|||
m_attenuatorR2Label = new wxStaticText( sbSizerAttValues->GetStaticBox(), wxID_ANY, _("R2:"), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_attenuatorR2Label->Wrap( -1 ); |
|||
fgSizerAttResults->Add( m_attenuatorR2Label, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); |
|||
|
|||
m_Att_R2_Value = new wxTextCtrl( sbSizerAttValues->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); |
|||
fgSizerAttResults->Add( m_Att_R2_Value, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT|wxEXPAND, 5 ); |
|||
|
|||
m_attR2Unit = new wxStaticText( sbSizerAttValues->GetStaticBox(), wxID_ANY, _("Ohms"), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_attR2Unit->Wrap( -1 ); |
|||
fgSizerAttResults->Add( m_attR2Unit, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 ); |
|||
|
|||
m_attenuatorR3Label = new wxStaticText( sbSizerAttValues->GetStaticBox(), wxID_ANY, _("R3:"), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_attenuatorR3Label->Wrap( -1 ); |
|||
fgSizerAttResults->Add( m_attenuatorR3Label, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); |
|||
|
|||
m_Att_R3_Value = new wxTextCtrl( sbSizerAttValues->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); |
|||
fgSizerAttResults->Add( m_Att_R3_Value, 0, wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 ); |
|||
|
|||
m_attR3Unit = new wxStaticText( sbSizerAttValues->GetStaticBox(), wxID_ANY, _("Ohms"), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_attR3Unit->Wrap( -1 ); |
|||
fgSizerAttResults->Add( m_attR3Unit, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 ); |
|||
|
|||
|
|||
sbSizerAttValues->Add( fgSizerAttResults, 0, wxEXPAND|wxBOTTOM, 5 ); |
|||
|
|||
|
|||
bMiddleSizerAtt->Add( sbSizerAttValues, 0, wxEXPAND|wxTOP|wxBOTTOM|wxRIGHT, 5 ); |
|||
|
|||
wxBoxSizer* bSizerMessages; |
|||
bSizerMessages = new wxBoxSizer( wxVERTICAL ); |
|||
|
|||
wxBoxSizer* bSizerIndentLabel; |
|||
bSizerIndentLabel = new wxBoxSizer( wxHORIZONTAL ); |
|||
|
|||
m_staticTextAttMsg = new wxStaticText( this, wxID_ANY, _("Messages"), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_staticTextAttMsg->Wrap( -1 ); |
|||
bSizerIndentLabel->Add( m_staticTextAttMsg, 0, wxALL, 2 ); |
|||
|
|||
|
|||
bSizerMessages->Add( bSizerIndentLabel, 0, wxLEFT, 6 ); |
|||
|
|||
m_Attenuator_Messages = new wxHtmlWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_NO_SELECTION|wxHW_SCROLLBAR_AUTO ); |
|||
bSizerMessages->Add( m_Attenuator_Messages, 1, wxEXPAND|wxBOTTOM|wxRIGHT, 8 ); |
|||
|
|||
|
|||
bMiddleSizerAtt->Add( bSizerMessages, 1, wxEXPAND|wxLEFT, 3 ); |
|||
|
|||
|
|||
bSizerAtt->Add( bMiddleSizerAtt, 0, wxEXPAND|wxRIGHT|wxLEFT, 5 ); |
|||
|
|||
wxStaticBoxSizer* sbRightSizerFormula; |
|||
sbRightSizerFormula = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Formula") ), wxVERTICAL ); |
|||
|
|||
m_panelAttFormula = new wxHtmlWindow( sbRightSizerFormula->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO ); |
|||
sbRightSizerFormula->Add( m_panelAttFormula, 1, wxEXPAND|wxBOTTOM, 5 ); |
|||
|
|||
|
|||
bSizerAtt->Add( sbRightSizerFormula, 1, wxEXPAND|wxALL, 5 ); |
|||
|
|||
|
|||
this->SetSizer( bSizerAtt ); |
|||
this->Layout(); |
|||
|
|||
// Connect Events
|
|||
m_AttenuatorsSelection->Connect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( PANEL_ATTENUATORS_BASE::OnAttenuatorSelection ), NULL, this ); |
|||
m_buttonAlcAtt->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_ATTENUATORS_BASE::OnCalculateAttenuator ), NULL, this ); |
|||
m_bpButtonCalcAtt->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_ATTENUATORS_BASE::OnCalculateAttenuator ), NULL, this ); |
|||
} |
|||
|
|||
PANEL_ATTENUATORS_BASE::~PANEL_ATTENUATORS_BASE() |
|||
{ |
|||
// Disconnect Events
|
|||
m_AttenuatorsSelection->Disconnect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( PANEL_ATTENUATORS_BASE::OnAttenuatorSelection ), NULL, this ); |
|||
m_buttonAlcAtt->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_ATTENUATORS_BASE::OnCalculateAttenuator ), NULL, this ); |
|||
m_bpButtonCalcAtt->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_ATTENUATORS_BASE::OnCalculateAttenuator ), NULL, this ); |
|||
|
|||
} |
1767
pcb_calculator/dialogs/panel_attenuators_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,80 @@ |
|||
/////////////////////////////////////////////////////////////////////////// |
|||
// C++ code generated with wxFormBuilder (version Oct 26 2018) |
|||
// 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> |
|||
#include <wx/string.h> |
|||
#include <wx/radiobox.h> |
|||
#include <wx/gdicmn.h> |
|||
#include <wx/font.h> |
|||
#include <wx/colour.h> |
|||
#include <wx/settings.h> |
|||
#include <wx/bitmap.h> |
|||
#include <wx/image.h> |
|||
#include <wx/icon.h> |
|||
#include <wx/statbmp.h> |
|||
#include <wx/sizer.h> |
|||
#include <wx/stattext.h> |
|||
#include <wx/textctrl.h> |
|||
#include <wx/statbox.h> |
|||
#include <wx/button.h> |
|||
#include <wx/bmpbuttn.h> |
|||
#include <wx/html/htmlwin.h> |
|||
#include <wx/panel.h> |
|||
|
|||
/////////////////////////////////////////////////////////////////////////// |
|||
|
|||
|
|||
/////////////////////////////////////////////////////////////////////////////// |
|||
/// Class PANEL_ATTENUATORS_BASE |
|||
/////////////////////////////////////////////////////////////////////////////// |
|||
class PANEL_ATTENUATORS_BASE : public wxPanel |
|||
{ |
|||
private: |
|||
|
|||
protected: |
|||
wxRadioBox* m_AttenuatorsSelection; |
|||
wxStaticBitmap* m_attenuatorBitmap; |
|||
wxStaticText* m_attenuationLabel; |
|||
wxTextCtrl* m_AttValueCtrl; |
|||
wxStaticText* m_attUnit; |
|||
wxStaticText* m_attenuationZinLabel; |
|||
wxTextCtrl* m_ZinValueCtrl; |
|||
wxStaticText* m_attZinUnit; |
|||
wxStaticText* m_ZoutLabel; |
|||
wxTextCtrl* m_ZoutValueCtrl; |
|||
wxStaticText* m_attZoutUnit; |
|||
wxButton* m_buttonAlcAtt; |
|||
wxBitmapButton* m_bpButtonCalcAtt; |
|||
wxStaticText* m_attenuatorR1Label; |
|||
wxTextCtrl* m_Att_R1_Value; |
|||
wxStaticText* m_attR1Unit; |
|||
wxStaticText* m_attenuatorR2Label; |
|||
wxTextCtrl* m_Att_R2_Value; |
|||
wxStaticText* m_attR2Unit; |
|||
wxStaticText* m_attenuatorR3Label; |
|||
wxTextCtrl* m_Att_R3_Value; |
|||
wxStaticText* m_attR3Unit; |
|||
wxStaticText* m_staticTextAttMsg; |
|||
wxHtmlWindow* m_Attenuator_Messages; |
|||
wxHtmlWindow* m_panelAttFormula; |
|||
|
|||
// Virtual event handlers, overide them in your derived class |
|||
virtual void OnAttenuatorSelection( wxCommandEvent& event ) { event.Skip(); } |
|||
virtual void OnCalculateAttenuator( wxCommandEvent& event ) { event.Skip(); } |
|||
|
|||
|
|||
public: |
|||
|
|||
PANEL_ATTENUATORS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,300 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString ); |
|||
~PANEL_ATTENUATORS_BASE(); |
|||
|
|||
}; |
|||
|
1719
pcb_calculator/dialogs/pcb_calculator_frame_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,223 @@ |
|||
/*
|
|||
* This program source code file is part of KICAD, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 1992-2011 jean-pierre.charras |
|||
* Copyright (C) 1992-2021 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/choicdlg.h>
|
|||
#include <wx/msgdlg.h>
|
|||
|
|||
#include "pcb_calculator_settings.h"
|
|||
#include "attenuators/attenuator_classes.h"
|
|||
#include "../dialogs/panel_attenuators.h"
|
|||
|
|||
#include <bitmaps.h>
|
|||
#include <string_utils.h>
|
|||
#include <widgets/ui_common.h>
|
|||
|
|||
extern double DoubleFromString( const wxString& TextValue ); |
|||
|
|||
|
|||
PANEL_ATTENUATORS::PANEL_ATTENUATORS( wxWindow* parent, wxWindowID id, |
|||
const wxPoint& pos, const wxSize& size, |
|||
long style, const wxString& name ) : |
|||
PANEL_ATTENUATORS_BASE( parent, id, pos, size, style, name ) |
|||
{ |
|||
m_CurrAttenuator = nullptr; |
|||
m_bpButtonCalcAtt->SetBitmap( KiBitmap( BITMAPS::small_down ) ); |
|||
|
|||
// Populate attenuator list ordered like in dialog menu list
|
|||
m_AttenuatorList.push_back( new ATTENUATOR_PI() ); |
|||
m_AttenuatorList.push_back( new ATTENUATOR_TEE() ); |
|||
m_AttenuatorList.push_back( new ATTENUATOR_BRIDGE() ); |
|||
m_AttenuatorList.push_back( new ATTENUATOR_SPLITTER() ); |
|||
m_CurrAttenuator = m_AttenuatorList[0]; |
|||
|
|||
m_staticTextAttMsg->SetFont( KIUI::GetInfoFont( this ).Italic() ); |
|||
|
|||
m_attZinUnit->SetLabel( wxT( "Ω" ) ); |
|||
m_attZoutUnit->SetLabel( wxT( "Ω" ) ); |
|||
m_attR1Unit->SetLabel( wxT( "Ω" ) ); |
|||
m_attR2Unit->SetLabel( wxT( "Ω" ) ); |
|||
m_attR3Unit->SetLabel( wxT( "Ω" ) ); |
|||
} |
|||
|
|||
|
|||
PANEL_ATTENUATORS::~PANEL_ATTENUATORS() |
|||
{ |
|||
for( unsigned ii = 0; ii < m_AttenuatorList.size(); ii++ ) |
|||
delete m_AttenuatorList[ii]; |
|||
} |
|||
|
|||
|
|||
void PANEL_ATTENUATORS::UpdateUI() |
|||
{ |
|||
m_attenuatorBitmap->SetBitmap( *m_CurrAttenuator->m_SchBitMap ); |
|||
|
|||
m_attenuatorBitmap->GetParent()->Layout(); |
|||
m_attenuatorBitmap->GetParent()->Refresh(); |
|||
} |
|||
|
|||
|
|||
void PANEL_ATTENUATORS::LoadSettings( PCB_CALCULATOR_SETTINGS* aCfg ) |
|||
{ |
|||
wxASSERT( aCfg ); |
|||
|
|||
for( ATTENUATOR* attenuator : m_AttenuatorList ) |
|||
attenuator->ReadConfig(); |
|||
|
|||
m_AttenuatorsSelection->SetSelection( aCfg->m_Attenuators.type ); |
|||
SetAttenuator( m_AttenuatorsSelection->GetSelection() ); |
|||
} |
|||
|
|||
|
|||
void PANEL_ATTENUATORS::SaveSettings( PCB_CALCULATOR_SETTINGS* aCfg ) |
|||
{ |
|||
wxASSERT( aCfg ); |
|||
|
|||
aCfg->m_Attenuators.type = m_AttenuatorsSelection->GetSelection(); |
|||
|
|||
for( unsigned ii = 0; ii < m_AttenuatorList.size(); ii++ ) |
|||
m_AttenuatorList[ii]->WriteConfig(); |
|||
} |
|||
|
|||
|
|||
// Called on a attenuator selection
|
|||
void PANEL_ATTENUATORS::OnAttenuatorSelection( wxCommandEvent& event ) |
|||
{ |
|||
SetAttenuator( (unsigned) event.GetSelection() ); |
|||
Refresh(); |
|||
} |
|||
|
|||
|
|||
void PANEL_ATTENUATORS::SetAttenuator( unsigned aIdx ) |
|||
{ |
|||
if( aIdx >=m_AttenuatorList.size() ) |
|||
aIdx = m_AttenuatorList.size() - 1; |
|||
|
|||
m_CurrAttenuator = m_AttenuatorList[aIdx]; |
|||
TransfAttenuatorDataToPanel(); |
|||
m_Attenuator_Messages->SetPage( wxEmptyString ); |
|||
m_Att_R1_Value->SetValue( wxEmptyString ); |
|||
m_Att_R2_Value->SetValue( wxEmptyString ); |
|||
m_Att_R3_Value->SetValue( wxEmptyString ); |
|||
} |
|||
|
|||
|
|||
void PANEL_ATTENUATORS::OnCalculateAttenuator( wxCommandEvent& event ) |
|||
{ |
|||
TransfPanelDataToAttenuator(); |
|||
m_CurrAttenuator->Calculate(); |
|||
TransfAttenuatorResultsToPanel(); |
|||
} |
|||
|
|||
|
|||
void PANEL_ATTENUATORS::TransfPanelDataToAttenuator() |
|||
{ |
|||
wxString msg; |
|||
|
|||
msg = m_AttValueCtrl->GetValue(); |
|||
m_CurrAttenuator->m_Attenuation = DoubleFromString(msg); |
|||
msg = m_ZinValueCtrl->GetValue(); |
|||
m_CurrAttenuator->m_Zin = DoubleFromString(msg); |
|||
msg = m_ZoutValueCtrl->GetValue(); |
|||
m_CurrAttenuator->m_Zout = DoubleFromString(msg); |
|||
} |
|||
|
|||
|
|||
void PANEL_ATTENUATORS::TransfAttenuatorDataToPanel() |
|||
{ |
|||
m_attenuatorBitmap->SetBitmap( *m_CurrAttenuator->m_SchBitMap ); |
|||
|
|||
wxString msg; |
|||
|
|||
msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_Attenuation ); |
|||
m_AttValueCtrl->SetValue( msg ); |
|||
m_AttValueCtrl->Enable( m_CurrAttenuator->m_Attenuation_Enable ); |
|||
|
|||
m_ZinValueCtrl->Enable( m_CurrAttenuator->m_Zin_Enable ); |
|||
|
|||
if( m_CurrAttenuator->m_Zin_Enable ) |
|||
msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_Zin ); |
|||
else |
|||
msg.Clear(); |
|||
|
|||
m_ZinValueCtrl->SetValue( msg ); |
|||
|
|||
msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_Zout ); |
|||
m_ZoutValueCtrl->SetValue( msg ); |
|||
|
|||
if( m_CurrAttenuator->m_FormulaName ) |
|||
{ |
|||
if( m_CurrAttenuator->m_FormulaName->StartsWith( "<!" ) ) |
|||
{ |
|||
m_panelAttFormula->SetPage( *m_CurrAttenuator->m_FormulaName ); |
|||
} |
|||
else |
|||
{ |
|||
wxString html_txt; |
|||
ConvertMarkdown2Html( wxGetTranslation( *m_CurrAttenuator->m_FormulaName ), html_txt ); |
|||
m_panelAttFormula->SetPage( html_txt ); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
m_panelAttFormula->SetPage( wxEmptyString ); |
|||
} |
|||
} |
|||
|
|||
|
|||
void PANEL_ATTENUATORS::TransfAttenuatorResultsToPanel() |
|||
{ |
|||
wxString msg; |
|||
|
|||
m_Attenuator_Messages->SetPage( wxEmptyString ); |
|||
|
|||
if( m_CurrAttenuator->m_Error ) |
|||
{ |
|||
msg.Printf( _( "Attenuation more than %f dB" ), |
|||
m_CurrAttenuator->m_MinimumATT ); |
|||
m_Attenuator_Messages->AppendToPage( wxT( "<br><b>Error!</b></br><br><em>" ) ); |
|||
m_Attenuator_Messages->AppendToPage( msg ); |
|||
m_Attenuator_Messages->AppendToPage( wxT( "</em></br>" ) ); |
|||
|
|||
// Display -- as resistor values:
|
|||
msg = wxT( "--" ); |
|||
m_Att_R1_Value->SetValue( msg ); |
|||
m_Att_R2_Value->SetValue( msg ); |
|||
if( m_CurrAttenuator->m_ResultCount >= 3 ) |
|||
m_Att_R3_Value->SetValue( msg ); |
|||
|
|||
return; |
|||
} |
|||
|
|||
msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_R1 ); |
|||
m_Att_R1_Value->SetValue( msg ); |
|||
msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_R2 ); |
|||
m_Att_R2_Value->SetValue( msg ); |
|||
|
|||
if( m_CurrAttenuator->m_ResultCount < 3 ) |
|||
{ |
|||
m_Att_R3_Value->SetValue( wxEmptyString ); |
|||
} |
|||
else |
|||
{ |
|||
msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_R3 ); |
|||
m_Att_R3_Value->SetValue( msg ); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue