KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_sim_format_value.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21#include <sim/spice_value.h>
22#include <core/kicad_algo.h>
23
24
27 m_format( aFormat )
28{
29 OptOut( this );
30
31 if( aFormat->Range.EndsWith( wxS( "V" ) ) )
32 {
33 m_units = aFormat->Range.Right( 1 );
34 SetTitle( wxString::Format( GetTitle(), _( "Voltage" ) ) );
35 }
36 else if( aFormat->Range.EndsWith( wxS( "A" ) ) )
37 {
38 m_units = aFormat->Range.Right( 1 );
39 SetTitle( wxString::Format( GetTitle(), _( "Current" ) ) );
40 }
41 else if( aFormat->Range.EndsWith( wxS( "s" ) ) )
42 {
43 m_units = aFormat->Range.Right( 1 );
44 SetTitle( wxString::Format( GetTitle(), _( "Time" ) ) );
45 }
46 else if( aFormat->Range.EndsWith( wxS( "Hz" ) ) )
47 {
48 m_units = aFormat->Range.Right( 2 );
49 SetTitle( wxString::Format( GetTitle(), _( "Frequency" ) ) );
50 }
51 else if( aFormat->Range.EndsWith( wxS( "dB" ) ) )
52 {
53 m_units = aFormat->Range.Right( 3 );
54 SetTitle( wxString::Format( GetTitle(), _( "Gain" ) ) );
55 }
56 else if( aFormat->Range.EndsWith( wxS( "°" ) ) )
57 {
58 m_units = aFormat->Range.Right( 1 );
59 SetTitle( wxString::Format( GetTitle(), _( "Phase" ) ) );
60 }
61 else if( aFormat->Range.StartsWith( wxS( "~" ), &m_units ) )
62 {
63 // m_units set as remainder in StartsWith() call....
64 SetTitle( wxString::Format( GetTitle(), _( "Value" ) ) );
65 }
66 else
67 {
68 if( SPICE_VALUE::ParseSIPrefix( aFormat->Range.GetChar( 0 ) ) != SPICE_VALUE::PFX_NONE )
69 m_units = aFormat->Range.Right( aFormat->Range.Length() - 1 );
70 else
71 m_units = aFormat->Range;
72
73 SetTitle( wxString::Format( GetTitle(), _( "Value" ) ) );
74 }
75
76 m_precisionCtrl->SetValue( aFormat->Precision );
77
78 for( int ii = 1; ii < (int) m_rangeCtrl->GetCount(); ++ii )
79 m_rangeCtrl->SetString( ii, m_rangeCtrl->GetString( ii ) + m_units );
80
81 if( aFormat->Range.GetChar( 0 ) == '~' )
82 m_rangeCtrl->SetSelection( 0 );
83 else
84 m_rangeCtrl->SetStringSelection( aFormat->Range );
85}
86
87
89{
90 m_format->Precision = std::clamp( m_precisionCtrl->GetValue(), 1, 9 );
91
92 if( m_rangeCtrl->GetSelection() == 0 )
93 m_format->Range = wxS( "~" ) + m_units;
94 else
95 m_format->Range = m_rangeCtrl->GetStringSelection();
96
97 return true;
98}
99
void OptOut(wxWindow *aWindow)
Opt out of control state saving.
DIALOG_SIM_FORMAT_VALUE_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Format %s"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
DIALOG_SIM_FORMAT_VALUE(wxWindow *aParent, SPICE_VALUE_FORMAT *aFormat)
static UNIT_PREFIX ParseSIPrefix(wxChar c)
#define _(s)
A SPICE_VALUE_FORMAT holds precision and range info for formatting values.Helper class to handle Spic...
Definition spice_value.h:39