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 (C) 2023 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, you may find one here:
18 * https://www.gnu.org/licenses/gpl-3.0.html
19 * or you may search the http://www.gnu.org website for the version 3 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
25#include <sim/spice_value.h>
26#include <core/kicad_algo.h>
27
28
31 m_format( aFormat )
32{
33 if( aFormat->Range.EndsWith( wxS( "V" ) ) )
34 {
35 m_units = aFormat->Range.Right( 1 );
36 SetTitle( wxString::Format( GetTitle(), _( "Voltage" ) ) );
37 }
38 else if( aFormat->Range.EndsWith( wxS( "A" ) ) )
39 {
40 m_units = aFormat->Range.Right( 1 );
41 SetTitle( wxString::Format( GetTitle(), _( "Current" ) ) );
42 }
43 else if( aFormat->Range.EndsWith( wxS( "s" ) ) )
44 {
45 m_units = aFormat->Range.Right( 1 );
46 SetTitle( wxString::Format( GetTitle(), _( "Time" ) ) );
47 }
48 else if( aFormat->Range.EndsWith( wxS( "Hz" ) ) )
49 {
50 m_units = aFormat->Range.Right( 2 );
51 SetTitle( wxString::Format( GetTitle(), _( "Frequency" ) ) );
52 }
53 else if( aFormat->Range.EndsWith( wxS( "dB" ) ) )
54 {
55 m_units = aFormat->Range.Right( 3 );
56 SetTitle( wxString::Format( GetTitle(), _( "Gain" ) ) );
57 }
58 else if( aFormat->Range.EndsWith( wxS( "°" ) ) )
59 {
60 m_units = aFormat->Range.Right( 1 );
61 SetTitle( wxString::Format( GetTitle(), _( "Phase" ) ) );
62 }
63 else if( aFormat->Range.StartsWith( wxS( "~" ), &m_units ) )
64 {
65 // m_units set as remainder in StartsWith() call....
66 SetTitle( wxString::Format( GetTitle(), _( "Value" ) ) );
67 }
68 else
69 {
70 if( SPICE_VALUE::ParseSIPrefix( aFormat->Range.GetChar( 0 ) ) != SPICE_VALUE::PFX_NONE )
71 m_units = aFormat->Range.Right( aFormat->Range.Length() - 1 );
72 else
73 m_units = aFormat->Range;
74
75 SetTitle( wxString::Format( GetTitle(), _( "Value" ) ) );
76 }
77
78 m_precisionCtrl->SetValue( aFormat->Precision );
79
80 for( int ii = 1; ii < (int) m_rangeCtrl->GetCount(); ++ii )
81 m_rangeCtrl->SetString( ii, m_rangeCtrl->GetString( ii ) + m_units );
82
83 if( aFormat->Range.GetChar( 0 ) == '~' )
84 m_rangeCtrl->SetSelection( 0 );
85 else
86 m_rangeCtrl->SetStringSelection( aFormat->Range );
87}
88
89
91{
92 m_format->Precision = std::clamp( m_precisionCtrl->GetValue(), 1, 9 );
93
94 if( m_rangeCtrl->GetSelection() == 0 )
95 m_format->Range = wxS( "~" ) + m_units;
96 else
97 m_format->Range = m_rangeCtrl->GetStringSelection();
98
99 return true;
100}
101
Class DIALOG_SIM_FORMAT_VALUE_BASE.
DIALOG_SIM_FORMAT_VALUE(wxWindow *aParent, SPICE_VALUE_FORMAT *aFormat)
SPICE_VALUE_FORMAT * m_format
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:43