KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_rf_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-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
21
22#include <wx/choicdlg.h>
23
27
28#include <bitmaps.h>
29#include <string_utils.h>
30#include <widgets/ui_common.h>
32
33extern double DoubleFromString( const wxString& TextValue );
34
35
36PANEL_RF_ATTENUATORS::PANEL_RF_ATTENUATORS( wxWindow* parent, wxWindowID id, const wxPoint& pos,
37 const wxSize& size, long style, const wxString& name ) :
38 PANEL_RF_ATTENUATORS_BASE( parent, id, pos, size, style, name )
39{
40 m_CurrAttenuator = nullptr;
41 m_bpButtonCalcAtt->SetBitmap( KiBitmapBundle( BITMAPS::small_down ) );
42
43 // Populate attenuator list ordered like in dialog menu list
44 m_AttenuatorList.push_back( new ATTENUATOR_PI() );
45 m_AttenuatorList.push_back( new ATTENUATOR_TEE() );
46 m_AttenuatorList.push_back( new ATTENUATOR_BRIDGE() );
47 m_AttenuatorList.push_back( new ATTENUATOR_SPLITTER() );
49 SetAttenuator( 0 ); // Ensure an attenuator and especially its bitmap are set
50
51 m_staticTextAttMsg->SetFont( KIUI::GetInfoFont( this ).Italic() );
52
53 m_attZinUnit->SetLabel( wxT( "Ω" ) );
54 m_attZoutUnit->SetLabel( wxT( "Ω" ) );
55 m_attR1Unit->SetLabel( wxT( "Ω" ) );
56 m_attR2Unit->SetLabel( wxT( "Ω" ) );
57 m_attR3Unit->SetLabel( wxT( "Ω" ) );
58
59 // Needed on wxWidgets 3.0 to ensure sizers are correctly set
60 GetSizer()->SetSizeHints( this );
61}
62
63
65{
66 for( ATTENUATOR* attenuator : m_AttenuatorList )
67 delete attenuator;
68}
69
70
72{
73 // Update the bitmaps
74 m_bpButtonCalcAtt->SetBitmap( KiBitmapBundle( BITMAPS::small_down ) );
76
77 // Update the font
78 m_staticTextAttMsg->SetFont( KIUI::GetInfoFont( this ).Italic() );
79
80 // Update the HTML windows
83
84 Layout();
85 Refresh();
86}
87
88
90{
92
93 m_attenuatorBitmap->GetParent()->Layout();
94 m_attenuatorBitmap->GetParent()->Refresh();
95}
96
97
99{
100 wxASSERT( aCfg );
101
102 for( ATTENUATOR* attenuator : m_AttenuatorList )
103 attenuator->ReadConfig();
104
105 m_AttenuatorsSelection->SetSelection( aCfg->m_Attenuators.type );
106 SetAttenuator( m_AttenuatorsSelection->GetSelection() );
107}
108
109
111{
112 wxASSERT( aCfg );
113
114 aCfg->m_Attenuators.type = m_AttenuatorsSelection->GetSelection();
115
116 for( ATTENUATOR* attenuator : m_AttenuatorList )
117 attenuator->WriteConfig();
118}
119
120
121// Called on a attenuator selection
123{
124 SetAttenuator( (unsigned) event.GetSelection() );
125 Refresh();
126}
127
128
130{
131 if( aIdx >=m_AttenuatorList.size() )
132 aIdx = m_AttenuatorList.size() - 1;
133
136 m_Attenuator_Messages->SetPage( wxEmptyString );
137 m_Att_R1_Value->SetValue( wxEmptyString );
138 m_Att_R2_Value->SetValue( wxEmptyString );
139 m_Att_R3_Value->SetValue( wxEmptyString );
140
141 // Disable R3 for bridget T attenuator only
142 bool enable = aIdx != 2;
143 m_attenuatorR3Label->Enable( enable );
144 m_Att_R3_Value->Enable( enable );
145 m_attR3Unit->Enable( enable );
146}
147
148
150{
154}
155
156
158{
159 wxString msg;
160
161 msg = m_AttValueCtrl->GetValue();
163 msg = m_ZinValueCtrl->GetValue();
165 msg = m_ZoutValueCtrl->GetValue();
167}
168
169
171{
173
174 wxString msg;
175
176 msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_Attenuation );
177 m_AttValueCtrl->SetValue( msg );
179
181
183 msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_Zin );
184 else
185 msg.Clear();
186
187 m_ZinValueCtrl->SetValue( msg );
188
189 msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_Zout );
190 m_ZoutValueCtrl->SetValue( msg );
191
193 {
194 if( m_CurrAttenuator->m_FormulaName->StartsWith( "<!" ) )
195 {
197 }
198 else
199 {
200 wxString html_txt;
201 ConvertMarkdown2Html( wxGetTranslation( *m_CurrAttenuator->m_FormulaName ), html_txt );
202 m_panelAttFormula->SetPage( html_txt );
203 }
204 }
205 else
206 {
207 m_panelAttFormula->SetPage( wxEmptyString );
208 }
209}
210
211
213{
214 wxString msg;
215
216 m_Attenuator_Messages->SetPage( wxEmptyString );
217
219 {
220 msg.Printf( _( "Attenuation more than %f dB" ),
222 m_Attenuator_Messages->AppendToPage( wxT( "<br><b>Error!</b></br><br><em>" ) );
224 m_Attenuator_Messages->AppendToPage( wxT( "</em></br>" ) );
225
226 // Display -- as resistor values:
227 msg = wxT( "--" );
228 m_Att_R1_Value->SetValue( msg );
229 m_Att_R2_Value->SetValue( msg );
230
232 m_Att_R3_Value->SetValue( msg );
233
234 return;
235 }
236
237 msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_R1 );
238 m_Att_R1_Value->SetValue( msg );
239 msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_R2 );
240 m_Att_R2_Value->SetValue( msg );
241
243 {
244 m_Att_R3_Value->SetValue( wxEmptyString );
245 }
246 else
247 {
248 msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_R3 );
249 m_Att_R3_Value->SetValue( msg );
250 }
251}
const char * name
Definition: DXF_plotter.cpp:57
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
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_RF_ATTENUATORS_BASE.
void SaveSettings(PCB_CALCULATOR_SETTINGS *aCfg) override
Save the settings from the panel.
void OnAttenuatorSelection(wxCommandEvent &event) override
void SetAttenuator(unsigned aIdx)
void LoadSettings(PCB_CALCULATOR_SETTINGS *aCfg) override
Load the settings into 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
PANEL_RF_ATTENUATORS(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
void OnCalculateAttenuator(wxCommandEvent &event) override
void SetBitmap(const wxBitmapBundle &aBmp)
#define _(s)
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:151
double DoubleFromString(const wxString &TextValue)
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.