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 The 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
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21
22#include <wx/choicdlg.h>
23
28
29#include <bitmaps.h>
30#include <string_utils.h>
31#include <widgets/ui_common.h>
33
34
35PANEL_RF_ATTENUATORS::PANEL_RF_ATTENUATORS( wxWindow* parent, wxWindowID id, const wxPoint& pos,
36 const wxSize& size, long style, const wxString& name ) :
37 PANEL_RF_ATTENUATORS_BASE( parent, id, pos, size, style, name )
38{
39 m_CurrAttenuator = nullptr;
41
42 // Populate attenuator list ordered like in dialog menu list
43 m_AttenuatorList.push_back( new ATTENUATOR_PI() );
44 m_AttenuatorList.push_back( new ATTENUATOR_TEE() );
45 m_AttenuatorList.push_back( new ATTENUATOR_BRIDGE() );
46 m_AttenuatorList.push_back( new ATTENUATOR_SPLITTER() );
48 SetAttenuator( 0 ); // Ensure an attenuator and especially its bitmap are set
49
50 m_staticTextAttMsg->SetFont( KIUI::GetInfoFont( this ).Italic() );
51
52 m_attZinUnit->SetLabel( wxT( "Ω" ) );
53 m_attZoutUnit->SetLabel( wxT( "Ω" ) );
54 m_attR1Unit->SetLabel( wxT( "Ω" ) );
55 m_attR2Unit->SetLabel( wxT( "Ω" ) );
56 m_attR3Unit->SetLabel( wxT( "Ω" ) );
57
58 // Needed on wxWidgets 3.0 to ensure sizers are correctly set
59 GetSizer()->SetSizeHints( this );
60}
61
62
64{
65 for( ATTENUATOR* attenuator : m_AttenuatorList )
66 delete attenuator;
67}
68
69
71{
72 // Update the bitmaps
74 m_attenuatorBitmap->SetBitmap( KiBitmapBundle( m_CurrAttenuator->m_SchBitmapName ) );
75
76 // Update the font
77 m_staticTextAttMsg->SetFont( KIUI::GetInfoFont( this ).Italic() );
78
79 // Update the HTML windows
80 m_Attenuator_Messages->ThemeChanged();
81 m_panelAttFormula->ThemeChanged();
82
83 Layout();
84 Refresh();
85}
86
87
89{
90 m_attenuatorBitmap->SetBitmap( KiBitmapBundle( m_CurrAttenuator->m_SchBitmapName ) );
91
92 m_attenuatorBitmap->GetParent()->Layout();
93 m_attenuatorBitmap->GetParent()->Refresh();
94}
95
96
98{
99 wxASSERT( aCfg );
100
101 for( ATTENUATOR* attenuator : m_AttenuatorList )
102 attenuator->ReadConfig();
103
104 m_AttenuatorsSelection->SetSelection( aCfg->m_Attenuators.type );
105 SetAttenuator( m_AttenuatorsSelection->GetSelection() );
106}
107
108
110{
111 wxASSERT( aCfg );
112
113 aCfg->m_Attenuators.type = m_AttenuatorsSelection->GetSelection();
114
115 for( ATTENUATOR* attenuator : m_AttenuatorList )
116 attenuator->WriteConfig();
117}
118
119
120// Called on a attenuator selection
122{
123 SetAttenuator( (unsigned) event.GetSelection() );
124 Refresh();
125}
126
127
129{
130 if( aIdx >=m_AttenuatorList.size() )
131 aIdx = m_AttenuatorList.size() - 1;
132
135 m_Attenuator_Messages->SetPage( wxEmptyString );
136 m_Att_R1_Value->SetValue( wxEmptyString );
137 m_Att_R2_Value->SetValue( wxEmptyString );
138 m_Att_R3_Value->SetValue( wxEmptyString );
139
140 // Disable R3 for bridget T attenuator only
141 bool enable = aIdx != 2;
142 m_attenuatorR3Label->Enable( enable );
143 m_Att_R3_Value->Enable( enable );
144 m_attR3Unit->Enable( enable );
145}
146
147
154
155
157{
158 wxString msg;
159
160 msg = m_AttValueCtrl->GetValue();
161 m_CurrAttenuator->m_Attenuation = DoubleFromString(msg);
162 msg = m_ZinValueCtrl->GetValue();
164 msg = m_ZoutValueCtrl->GetValue();
165 m_CurrAttenuator->m_Zout = DoubleFromString(msg);
166}
167
168
170{
171 m_attenuatorBitmap->SetBitmap( KiBitmapBundle( m_CurrAttenuator->m_SchBitmapName ) );
172
173 wxString msg;
174
175 msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_Attenuation );
176 m_AttValueCtrl->SetValue( msg );
177 m_AttValueCtrl->Enable( m_CurrAttenuator->m_Attenuation_Enable );
178
179 m_ZinValueCtrl->Enable( m_CurrAttenuator->m_Zin_Enable );
180
181 if( m_CurrAttenuator->m_Zin_Enable )
182 msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_Zin );
183 else
184 msg.Clear();
185
186 m_ZinValueCtrl->SetValue( msg );
187
188 msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_Zout );
189 m_ZoutValueCtrl->SetValue( msg );
190
191 if( m_CurrAttenuator->m_FormulaName )
192 {
193 if( m_CurrAttenuator->m_FormulaName->StartsWith( "<!" ) )
194 {
195 m_panelAttFormula->SetPage( *m_CurrAttenuator->m_FormulaName );
196 }
197 else
198 {
199 wxString html_txt;
200 ConvertMarkdown2Html( wxGetTranslation( *m_CurrAttenuator->m_FormulaName ), html_txt );
201 m_panelAttFormula->SetPage( html_txt );
202 }
203 }
204 else
205 {
206 m_panelAttFormula->SetPage( wxEmptyString );
207 }
208}
209
210
212{
213 wxString msg;
214
215 m_Attenuator_Messages->SetPage( wxEmptyString );
216
217 if( m_CurrAttenuator->m_Error )
218 {
219 msg.Printf( _( "Attenuation more than %f dB" ),
220 m_CurrAttenuator->m_MinimumATT );
221 m_Attenuator_Messages->AppendToPage( wxT( "<br><b>Error!</b></br><br><em>" ) );
222 m_Attenuator_Messages->AppendToPage( msg );
223 m_Attenuator_Messages->AppendToPage( wxT( "</em></br>" ) );
224
225 // Display -- as resistor values:
226 msg = wxT( "--" );
227 m_Att_R1_Value->SetValue( msg );
228 m_Att_R2_Value->SetValue( msg );
229
230 if( m_CurrAttenuator->m_ResultCount >= 3 )
231 m_Att_R3_Value->SetValue( msg );
232
233 return;
234 }
235
236 msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_R1 );
237 m_Att_R1_Value->SetValue( msg );
238 msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_R2 );
239 m_Att_R2_Value->SetValue( msg );
240
241 if( m_CurrAttenuator->m_ResultCount < 3 )
242 {
243 m_Att_R3_Value->SetValue( wxEmptyString );
244 }
245 else
246 {
247 msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_R3 );
248 m_Att_R3_Value->SetValue( msg );
249 }
250}
const char * name
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
PANEL_RF_ATTENUATORS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
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
#define _(s)
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
double DoubleFromString(const wxString &TextValue)
void ConvertMarkdown2Html(const wxString &aMarkdownInput, wxString &aHtmlOutput)
Functions to provide common constants and other functions to assist in making a consistent UI.