KiCad PCB EDA Suite
panel_attenuators.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-2011 jean-pierre.charras
5 * Copyright (C) 1992-2021 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
21
22#include <wx/choicdlg.h>
23#include <wx/msgdlg.h>
24
28
29#include <bitmaps.h>
30#include <string_utils.h>
31#include <widgets/ui_common.h>
32
33extern double DoubleFromString( const wxString& TextValue );
34
35
36PANEL_ATTENUATORS::PANEL_ATTENUATORS( wxWindow* parent, wxWindowID id,
37 const wxPoint& pos, const wxSize& size,
38 long style, const wxString& name ) :
39 PANEL_ATTENUATORS_BASE( parent, id, pos, size, style, name )
40{
41 m_CurrAttenuator = nullptr;
43
44 // Populate attenuator list ordered like in dialog menu list
45 m_AttenuatorList.push_back( new ATTENUATOR_PI() );
46 m_AttenuatorList.push_back( new ATTENUATOR_TEE() );
47 m_AttenuatorList.push_back( new ATTENUATOR_BRIDGE() );
48 m_AttenuatorList.push_back( new ATTENUATOR_SPLITTER() );
50 SetAttenuator( 0 ); // Ensure an attenuator and especially its bitmap are set
51
52 m_staticTextAttMsg->SetFont( KIUI::GetInfoFont( this ).Italic() );
53
54 m_attZinUnit->SetLabel( wxT( "Ω" ) );
55 m_attZoutUnit->SetLabel( wxT( "Ω" ) );
56 m_attR1Unit->SetLabel( wxT( "Ω" ) );
57 m_attR2Unit->SetLabel( wxT( "Ω" ) );
58 m_attR3Unit->SetLabel( wxT( "Ω" ) );
59
60 // Needed on wxWidgets 3.0 to ensure sizers are correctly set
61 GetSizer()->SetSizeHints( this );
62}
63
64
66{
67 for( ATTENUATOR* attenuator : m_AttenuatorList )
68 delete attenuator;
69}
70
71
73{
74 // Update the bitmaps
77
78 // Update the font
79 m_staticTextAttMsg->SetFont( KIUI::GetInfoFont( this ).Italic() );
80
81 // Update the HTML windows
84
85 Layout();
86 Refresh();
87}
88
89
91{
93
94 m_attenuatorBitmap->GetParent()->Layout();
95 m_attenuatorBitmap->GetParent()->Refresh();
96}
97
98
100{
101 wxASSERT( aCfg );
102
103 for( ATTENUATOR* attenuator : m_AttenuatorList )
104 attenuator->ReadConfig();
105
106 m_AttenuatorsSelection->SetSelection( aCfg->m_Attenuators.type );
107 SetAttenuator( m_AttenuatorsSelection->GetSelection() );
108}
109
110
112{
113 wxASSERT( aCfg );
114
115 aCfg->m_Attenuators.type = m_AttenuatorsSelection->GetSelection();
116
117 for( ATTENUATOR* attenuator : m_AttenuatorList )
118 attenuator->WriteConfig();
119}
120
121
122// Called on a attenuator selection
123void PANEL_ATTENUATORS::OnAttenuatorSelection( wxCommandEvent& event )
124{
125 SetAttenuator( (unsigned) event.GetSelection() );
126 Refresh();
127}
128
129
131{
132 if( aIdx >=m_AttenuatorList.size() )
133 aIdx = m_AttenuatorList.size() - 1;
134
137 m_Attenuator_Messages->SetPage( wxEmptyString );
138 m_Att_R1_Value->SetValue( wxEmptyString );
139 m_Att_R2_Value->SetValue( wxEmptyString );
140 m_Att_R3_Value->SetValue( wxEmptyString );
141
142 // Disable R3 for bridget T attenuator only
143 bool enable = aIdx != 2;
144 m_attenuatorR3Label->Enable( enable );
145 m_Att_R3_Value->Enable( enable );
146 m_attR3Unit->Enable( enable );
147}
148
149
150void PANEL_ATTENUATORS::OnCalculateAttenuator( wxCommandEvent& event )
151{
155}
156
157
159{
160 wxString msg;
161
162 msg = m_AttValueCtrl->GetValue();
164 msg = m_ZinValueCtrl->GetValue();
166 msg = m_ZoutValueCtrl->GetValue();
168}
169
170
172{
174
175 wxString msg;
176
177 msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_Attenuation );
178 m_AttValueCtrl->SetValue( msg );
180
182
184 msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_Zin );
185 else
186 msg.Clear();
187
188 m_ZinValueCtrl->SetValue( msg );
189
190 msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_Zout );
191 m_ZoutValueCtrl->SetValue( msg );
192
194 {
195 if( m_CurrAttenuator->m_FormulaName->StartsWith( "<!" ) )
196 {
198 }
199 else
200 {
201 wxString html_txt;
202 ConvertMarkdown2Html( wxGetTranslation( *m_CurrAttenuator->m_FormulaName ), html_txt );
203 m_panelAttFormula->SetPage( html_txt );
204 }
205 }
206 else
207 {
208 m_panelAttFormula->SetPage( wxEmptyString );
209 }
210}
211
212
214{
215 wxString msg;
216
217 m_Attenuator_Messages->SetPage( wxEmptyString );
218
220 {
221 msg.Printf( _( "Attenuation more than %f dB" ),
223 m_Attenuator_Messages->AppendToPage( wxT( "<br><b>Error!</b></br><br><em>" ) );
225 m_Attenuator_Messages->AppendToPage( wxT( "</em></br>" ) );
226
227 // Display -- as resistor values:
228 msg = wxT( "--" );
229 m_Att_R1_Value->SetValue( msg );
230 m_Att_R2_Value->SetValue( msg );
231
233 m_Att_R3_Value->SetValue( msg );
234
235 return;
236 }
237
238 msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_R1 );
239 m_Att_R1_Value->SetValue( msg );
240 msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_R2 );
241 m_Att_R2_Value->SetValue( msg );
242
244 {
245 m_Att_R3_Value->SetValue( wxEmptyString );
246 }
247 else
248 {
249 msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_R3 );
250 m_Att_R3_Value->SetValue( msg );
251 }
252}
const char * name
Definition: DXF_plotter.cpp:56
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105
virtual bool Calculate()
Calculates the values of components in attenuator.
BITMAPS m_SchBitmapName
wxString * m_FormulaName
bool m_Attenuation_Enable
double m_Attenuation
bool SetPage(const wxString &aSource) override
Definition: html_window.cpp:38
bool AppendToPage(const wxString &aSource)
Definition: html_window.cpp:57
void ThemeChanged()
Definition: html_window.cpp:63
Class PANEL_ATTENUATORS_BASE.
wxStaticBitmap * m_attenuatorBitmap
wxBitmapButton * m_bpButtonCalcAtt
void SetAttenuator(unsigned aIdx)
void OnCalculateAttenuator(wxCommandEvent &event) override
void LoadSettings(PCB_CALCULATOR_SETTINGS *aCfg) override
Load the settings into the panel.
ATTENUATOR * m_CurrAttenuator
void OnAttenuatorSelection(wxCommandEvent &event) override
PANEL_ATTENUATORS(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 ThemeChanged() override
Update UI elements of the panel when the theme changes to ensure the images and fonts/colors are appr...
std::vector< ATTENUATOR * > m_AttenuatorList
#define _(s)
wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:144
double DoubleFromString(const wxString &TextValue)
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
void ConvertMarkdown2Html(const wxString &aMarkdownInput, wxString &aHtmlOutput)
Functions to provide common constants and other functions to assist in making a consistent UI.