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 
33 extern double DoubleFromString( const wxString& TextValue );
34 
35 
36 PANEL_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
123 void PANEL_ATTENUATORS::OnAttenuatorSelection( wxCommandEvent& event )
124 {
125  SetAttenuator( (unsigned) event.GetSelection() );
126  Refresh();
127 }
128 
129 
130 void PANEL_ATTENUATORS::SetAttenuator( unsigned aIdx )
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 
143 
144 void PANEL_ATTENUATORS::OnCalculateAttenuator( wxCommandEvent& event )
145 {
149 }
150 
151 
153 {
154  wxString msg;
155 
156  msg = m_AttValueCtrl->GetValue();
158  msg = m_ZinValueCtrl->GetValue();
160  msg = m_ZoutValueCtrl->GetValue();
162 }
163 
164 
166 {
168 
169  wxString msg;
170 
171  msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_Attenuation );
172  m_AttValueCtrl->SetValue( msg );
174 
176 
178  msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_Zin );
179  else
180  msg.Clear();
181 
182  m_ZinValueCtrl->SetValue( msg );
183 
184  msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_Zout );
185  m_ZoutValueCtrl->SetValue( msg );
186 
188  {
189  if( m_CurrAttenuator->m_FormulaName->StartsWith( "<!" ) )
190  {
192  }
193  else
194  {
195  wxString html_txt;
196  ConvertMarkdown2Html( wxGetTranslation( *m_CurrAttenuator->m_FormulaName ), html_txt );
197  m_panelAttFormula->SetPage( html_txt );
198  }
199  }
200  else
201  {
202  m_panelAttFormula->SetPage( wxEmptyString );
203  }
204 }
205 
206 
208 {
209  wxString msg;
210 
211  m_Attenuator_Messages->SetPage( wxEmptyString );
212 
214  {
215  msg.Printf( _( "Attenuation more than %f dB" ),
217  m_Attenuator_Messages->AppendToPage( wxT( "<br><b>Error!</b></br><br><em>" ) );
219  m_Attenuator_Messages->AppendToPage( wxT( "</em></br>" ) );
220 
221  // Display -- as resistor values:
222  msg = wxT( "--" );
223  m_Att_R1_Value->SetValue( msg );
224  m_Att_R2_Value->SetValue( msg );
225 
226  if( m_CurrAttenuator->m_ResultCount >= 3 )
227  m_Att_R3_Value->SetValue( msg );
228 
229  return;
230  }
231 
232  msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_R1 );
233  m_Att_R1_Value->SetValue( msg );
234  msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_R2 );
235  m_Att_R2_Value->SetValue( msg );
236 
238  {
239  m_Att_R3_Value->SetValue( wxEmptyString );
240  }
241  else
242  {
243  msg.Printf( wxT( "%g" ), m_CurrAttenuator->m_R3 );
244  m_Att_R3_Value->SetValue( msg );
245  }
246 }
void SetAttenuator(unsigned aIdx)
PANEL_ATTENUATORS(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
wxStaticBitmap * m_attenuatorBitmap
wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:144
bool m_Attenuation_Enable
BITMAPS m_SchBitmapName
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
void OnCalculateAttenuator(wxCommandEvent &event) override
void OnAttenuatorSelection(wxCommandEvent &event) override
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
virtual bool Calculate()
Calculates the values of components in attenuator.
bool AppendToPage(const wxString &aSource)
Definition: html_window.cpp:57
void ConvertMarkdown2Html(const wxString &aMarkdownInput, wxString &aHtmlOutput)
Functions to provide common constants and other functions to assist in making a consistent UI.
bool SetPage(const wxString &aSource) override
Definition: html_window.cpp:38
#define _(s)
double DoubleFromString(const wxString &TextValue)
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
Class PANEL_ATTENUATORS_BASE.
void LoadSettings(PCB_CALCULATOR_SETTINGS *aCfg) override
Load the settings into the panel.
wxBitmapButton * m_bpButtonCalcAtt
void ThemeChanged()
Definition: html_window.cpp:63
void SaveSettings(PCB_CALCULATOR_SETTINGS *aCfg) override
Save the settings from the panel.
const char * name
Definition: DXF_plotter.cpp:56
wxString * m_FormulaName
ATTENUATOR * m_CurrAttenuator
double m_Attenuation