2023-02-05 20:47:27 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 3
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* https://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 3 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <dialog_sim_format_value.h>
|
2023-02-21 11:36:14 +00:00
|
|
|
#include <sim/spice_value.h>
|
2023-06-03 15:59:00 +00:00
|
|
|
#include <core/kicad_algo.h>
|
2023-02-05 20:47:27 +00:00
|
|
|
|
|
|
|
|
2023-02-21 11:36:14 +00:00
|
|
|
DIALOG_SIM_FORMAT_VALUE::DIALOG_SIM_FORMAT_VALUE( wxWindow* aParent, SPICE_VALUE_FORMAT* aFormat ) :
|
2023-02-05 20:47:27 +00:00
|
|
|
DIALOG_SIM_FORMAT_VALUE_BASE( aParent ),
|
2023-02-21 11:36:14 +00:00
|
|
|
m_format( aFormat )
|
2023-02-05 20:47:27 +00:00
|
|
|
{
|
2023-02-21 11:36:14 +00:00
|
|
|
if( aFormat->Range.EndsWith( wxS( "V" ) ) )
|
2023-02-05 20:47:27 +00:00
|
|
|
{
|
2023-02-21 11:36:14 +00:00
|
|
|
m_units = aFormat->Range.Right( 1 );
|
2023-02-05 20:47:27 +00:00
|
|
|
SetTitle( wxString::Format( GetTitle(), _( "Voltage" ) ) );
|
|
|
|
}
|
2023-02-21 11:36:14 +00:00
|
|
|
else if( aFormat->Range.EndsWith( wxS( "A" ) ) )
|
2023-02-05 20:47:27 +00:00
|
|
|
{
|
2023-02-21 11:36:14 +00:00
|
|
|
m_units = aFormat->Range.Right( 1 );
|
2023-02-05 20:47:27 +00:00
|
|
|
SetTitle( wxString::Format( GetTitle(), _( "Current" ) ) );
|
|
|
|
}
|
2023-02-21 11:36:14 +00:00
|
|
|
else if( aFormat->Range.EndsWith( wxS( "s" ) ) )
|
2023-02-05 20:47:27 +00:00
|
|
|
{
|
2023-02-21 11:36:14 +00:00
|
|
|
m_units = aFormat->Range.Right( 1 );
|
2023-02-05 20:47:27 +00:00
|
|
|
SetTitle( wxString::Format( GetTitle(), _( "Time" ) ) );
|
|
|
|
}
|
2023-02-21 11:36:14 +00:00
|
|
|
else if( aFormat->Range.EndsWith( wxS( "Hz" ) ) )
|
2023-02-05 20:47:27 +00:00
|
|
|
{
|
2023-02-21 11:36:14 +00:00
|
|
|
m_units = aFormat->Range.Right( 2 );
|
2023-02-05 20:47:27 +00:00
|
|
|
SetTitle( wxString::Format( GetTitle(), _( "Frequency" ) ) );
|
|
|
|
}
|
2023-02-21 11:36:14 +00:00
|
|
|
else if( aFormat->Range.EndsWith( wxS( "dBV" ) ) )
|
2023-02-05 20:47:27 +00:00
|
|
|
{
|
2023-02-21 11:36:14 +00:00
|
|
|
m_units = aFormat->Range.Right( 3 );
|
2023-02-05 20:47:27 +00:00
|
|
|
SetTitle( wxString::Format( GetTitle(), _( "Gain" ) ) );
|
|
|
|
}
|
2023-02-21 11:36:14 +00:00
|
|
|
else if( aFormat->Range.EndsWith( wxS( "°" ) ) )
|
2023-02-05 20:47:27 +00:00
|
|
|
{
|
2023-02-21 11:36:14 +00:00
|
|
|
m_units = aFormat->Range.Right( 1 );
|
2023-02-05 20:47:27 +00:00
|
|
|
SetTitle( wxString::Format( GetTitle(), _( "Phase" ) ) );
|
|
|
|
}
|
2023-02-21 11:36:14 +00:00
|
|
|
else if( aFormat->Range.StartsWith( wxS( "~" ), &m_units ) )
|
|
|
|
{
|
|
|
|
// m_units set as remainder in StartsWith() call....
|
|
|
|
SetTitle( wxString::Format( GetTitle(), _( "Value" ) ) );
|
|
|
|
}
|
2023-02-05 20:47:27 +00:00
|
|
|
else
|
|
|
|
{
|
2023-02-21 11:36:14 +00:00
|
|
|
if( SPICE_VALUE::ParseSIPrefix( aFormat->Range.GetChar( 0 ) ) != SPICE_VALUE::PFX_NONE )
|
|
|
|
m_units = aFormat->Range.Right( aFormat->Range.Length() - 1 );
|
2023-02-05 20:47:27 +00:00
|
|
|
else
|
2023-02-21 11:36:14 +00:00
|
|
|
m_units = aFormat->Range;
|
2023-02-05 20:47:27 +00:00
|
|
|
|
|
|
|
SetTitle( wxString::Format( GetTitle(), _( "Value" ) ) );
|
|
|
|
}
|
|
|
|
|
2023-02-21 11:36:14 +00:00
|
|
|
m_precisionCtrl->SetValue( aFormat->Precision );
|
2023-02-05 20:47:27 +00:00
|
|
|
|
|
|
|
for( int ii = 1; ii < (int) m_rangeCtrl->GetCount(); ++ii )
|
|
|
|
m_rangeCtrl->SetString( ii, m_rangeCtrl->GetString( ii ) + m_units );
|
|
|
|
|
2023-02-21 11:36:14 +00:00
|
|
|
if( aFormat->Range.GetChar( 0 ) == '~' )
|
2023-02-05 20:47:27 +00:00
|
|
|
m_rangeCtrl->SetSelection( 0 );
|
|
|
|
else
|
2023-02-21 11:36:14 +00:00
|
|
|
m_rangeCtrl->SetStringSelection( aFormat->Range );
|
2023-02-05 20:47:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_SIM_FORMAT_VALUE::TransferDataFromWindow()
|
|
|
|
{
|
2023-06-03 15:59:00 +00:00
|
|
|
m_format->Precision = alg::clamp( 1, m_precisionCtrl->GetValue(), 9 );
|
2023-02-05 20:47:27 +00:00
|
|
|
|
|
|
|
if( m_rangeCtrl->GetSelection() == 0 )
|
2023-02-21 11:36:14 +00:00
|
|
|
m_format->Range = wxS( "~" ) + m_units;
|
2023-02-05 20:47:27 +00:00
|
|
|
else
|
2023-02-21 11:36:14 +00:00
|
|
|
m_format->Range = m_rangeCtrl->GetStringSelection();
|
2023-02-05 20:47:27 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|