KiCad PCB EDA Suite
attenuators.cpp
Go to the documentation of this file.
1 
5 /*
6  * This program source code file is part of KICAD, a free EDA CAD application.
7  *
8  * Copyright (C) 2015 jean-pierre.charras
9  * Copyright (C) 2015 Kicad Developers, see change_log.txt for contributors.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, you may find one here:
23  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
24  * or you may search the http://www.gnu.org website for the version 2 license,
25  * or you may write to the Free Software Foundation, Inc.,
26  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
27  */
28 #include <wx/wx.h>
29 
30 #include <dialog_helpers.h>
31 
32 #include "pcb_calculator_frame.h"
33 
34 extern double DoubleFromString( const wxString& TextValue );
35 
36 // Called on a attenuator selection
37 void PCB_CALCULATOR_FRAME::OnAttenuatorSelection( wxCommandEvent& event )
38 {
39  SetAttenuator( (unsigned) event.GetSelection() );
40  Refresh();
41 }
42 
43 
45 {
46  if( aIdx >=m_attenuator_list.size() )
47  aIdx = m_attenuator_list.size() - 1;
48 
51  m_Attenuator_Messages->SetPage( wxEmptyString );
52  m_Att_R1_Value->SetValue( wxEmptyString );
53  m_Att_R2_Value->SetValue( wxEmptyString );
54  m_Att_R3_Value->SetValue( wxEmptyString );
55 }
56 
57 
58 void PCB_CALCULATOR_FRAME::OnCalculateAttenuator( wxCommandEvent& event )
59 {
63 }
64 
65 
67 {
68  wxString msg;
69 
70  msg = m_AttValueCtrl->GetValue();
72  msg = m_ZinValueCtrl->GetValue();
74  msg = m_ZoutValueCtrl->GetValue();
76 }
77 
78 
80 {
82 
83  wxString msg;
84 
85  msg.Printf( wxT( "%g" ), m_currAttenuator->m_Attenuation );
86  m_AttValueCtrl->SetValue( msg );
88 
90 
92  msg.Printf( wxT( "%g" ), m_currAttenuator->m_Zin );
93  else
94  msg.Clear();
95 
96  m_ZinValueCtrl->SetValue( msg );
97 
98  msg.Printf( wxT( "%g" ), m_currAttenuator->m_Zout );
99  m_ZoutValueCtrl->SetValue( msg );
100 
102  {
103  if( m_currAttenuator->m_FormulaName->StartsWith( "<!" ) )
104  {
106  }
107  else
108  {
109  wxString html_txt;
110  ConvertMarkdown2Html( wxGetTranslation( *m_currAttenuator->m_FormulaName ), html_txt );
111  m_panelAttFormula->SetPage( html_txt );
112  }
113  }
114  else
115  {
116  m_panelAttFormula->SetPage( wxEmptyString );
117  }
118 }
119 
120 
122 {
123  wxString msg;
124 
125  m_Attenuator_Messages->SetPage( wxEmptyString );
126 
128  {
129  msg.Printf( _( "Attenuation more than %f dB" ),
131  m_Attenuator_Messages->AppendToPage( wxT( "<br><b>Error!</b></br><br><em>" ) );
132  m_Attenuator_Messages->AppendToPage( msg );
133  m_Attenuator_Messages->AppendToPage( wxT( "</em></br>" ) );
134 
135  // Display -- as resistor values:
136  msg = wxT( "--" );
137  m_Att_R1_Value->SetValue( msg );
138  m_Att_R2_Value->SetValue( msg );
139  if( m_currAttenuator->m_ResultCount >= 3 )
140  m_Att_R3_Value->SetValue( msg );
141 
142  return;
143  }
144 
145  msg.Printf( wxT( "%g" ), m_currAttenuator->m_R1 );
146  m_Att_R1_Value->SetValue( msg );
147  msg.Printf( wxT( "%g" ), m_currAttenuator->m_R2 );
148  m_Att_R2_Value->SetValue( msg );
149 
151  {
152  m_Att_R3_Value->SetValue( wxEmptyString );
153  }
154  else
155  {
156  msg.Printf( wxT( "%g" ), m_currAttenuator->m_R3 );
157  m_Att_R3_Value->SetValue( msg );
158  }
159 }
160 
161 
void ConvertMarkdown2Html(const wxString &aMarkdownInput, wxString &aHtmlOutput)
bool m_Attenuation_Enable
wxBitmap * m_SchBitMap
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
virtual bool Calculate()
Function Calculate calculates the values of components in attenuator.
void TransfPanelDataToAttenuator()
Definition: attenuators.cpp:66
Helper dialog and control classes.
double DoubleFromString(const wxString &TextValue)
void OnCalculateAttenuator(wxCommandEvent &event) override
Definition: attenuators.cpp:58
void OnAttenuatorSelection(wxCommandEvent &event) override
Definition: attenuators.cpp:37
#define _(s)
Definition: 3d_actions.cpp:33
void SetAttenuator(unsigned aIdx)
Definition: attenuators.cpp:44
wxString * m_FormulaName
void TransfAttenuatorDataToPanel()
Definition: attenuators.cpp:79
double m_Attenuation
void TransfAttenuatorResultsToPanel()
std::vector< ATTENUATOR * > m_attenuator_list