2016-08-11 12:41:07 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2023-01-01 23:37:24 +00:00
|
|
|
* Copyright (C) 2016-2023 CERN
|
|
|
|
* Copyright (C) 2021-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2021-07-09 20:20:23 +00:00
|
|
|
*
|
2016-08-11 12:41:07 +00:00
|
|
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
2016-08-11 12:41:21 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
2016-08-11 12:41:07 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
2016-08-11 12:41:43 +00:00
|
|
|
* as published by the Free Software Foundation; either version 3
|
2016-08-11 12:41:07 +00:00
|
|
|
* 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:
|
2016-08-11 12:41:43 +00:00
|
|
|
* https://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 3 license,
|
2016-08-11 12:41:07 +00:00
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2021-01-21 21:17:13 +00:00
|
|
|
#include "sim_plot_colors.h"
|
2023-07-09 22:00:25 +00:00
|
|
|
#include "sim_plot_tab.h"
|
2023-03-03 22:36:07 +00:00
|
|
|
#include "simulator_frame.h"
|
2023-02-27 21:08:05 +00:00
|
|
|
#include "core/kicad_algo.h"
|
2016-08-11 12:41:01 +00:00
|
|
|
|
2016-08-11 12:41:16 +00:00
|
|
|
#include <algorithm>
|
2016-08-11 12:41:14 +00:00
|
|
|
#include <limits>
|
|
|
|
|
2021-07-09 20:20:23 +00:00
|
|
|
|
2016-08-11 12:42:17 +00:00
|
|
|
static wxString formatFloat( double x, int nDigits )
|
2016-08-11 12:41:49 +00:00
|
|
|
{
|
|
|
|
wxString rv, fmt;
|
|
|
|
|
2016-08-11 12:42:17 +00:00
|
|
|
if( nDigits )
|
2021-02-17 23:52:56 +00:00
|
|
|
fmt.Printf( "%%.0%df", nDigits );
|
2016-08-11 12:42:17 +00:00
|
|
|
else
|
|
|
|
fmt = wxT( "%.0f" );
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2016-08-11 12:42:17 +00:00
|
|
|
rv.Printf( fmt, x );
|
2016-08-11 12:41:49 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:42:17 +00:00
|
|
|
|
|
|
|
static void getSISuffix( double x, const wxString& unit, int& power, wxString& suffix )
|
2016-08-11 12:41:49 +00:00
|
|
|
{
|
|
|
|
const int n_powers = 11;
|
2016-08-11 12:42:17 +00:00
|
|
|
|
|
|
|
const struct
|
|
|
|
{
|
2022-12-11 20:10:09 +00:00
|
|
|
int exponent;
|
2016-08-11 12:42:10 +00:00
|
|
|
char suffix;
|
2016-08-11 12:42:17 +00:00
|
|
|
} powers[] =
|
|
|
|
{
|
|
|
|
{ -18, 'a' },
|
|
|
|
{ -15, 'f' },
|
|
|
|
{ -12, 'p' },
|
|
|
|
{ -9, 'n' },
|
|
|
|
{ -6, 'u' },
|
|
|
|
{ -3, 'm' },
|
|
|
|
{ 0, 0 },
|
|
|
|
{ 3, 'k' },
|
|
|
|
{ 6, 'M' },
|
|
|
|
{ 9, 'G' },
|
|
|
|
{ 12, 'T' },
|
|
|
|
{ 14, 'P' }
|
2016-08-11 12:41:49 +00:00
|
|
|
};
|
|
|
|
|
2016-08-11 12:42:10 +00:00
|
|
|
power = 0;
|
|
|
|
suffix = unit;
|
|
|
|
|
2016-08-11 12:42:17 +00:00
|
|
|
if( x == 0.0 )
|
2016-08-11 12:42:10 +00:00
|
|
|
return;
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2016-08-11 12:42:17 +00:00
|
|
|
for( int i = 0; i < n_powers - 1; i++ )
|
2016-08-11 12:41:49 +00:00
|
|
|
{
|
2016-08-11 12:42:17 +00:00
|
|
|
double r_cur = pow( 10, powers[i].exponent );
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2016-08-11 12:42:17 +00:00
|
|
|
if( fabs( x ) >= r_cur && fabs( x ) < r_cur * 1000.0 )
|
2016-08-11 12:41:49 +00:00
|
|
|
{
|
2016-08-11 12:42:10 +00:00
|
|
|
power = powers[i].exponent;
|
2016-08-11 12:42:17 +00:00
|
|
|
|
|
|
|
if( powers[i].suffix )
|
|
|
|
suffix = wxString( powers[i].suffix ) + unit;
|
2016-08-11 12:42:10 +00:00
|
|
|
else
|
|
|
|
suffix = unit;
|
2016-08-11 12:42:17 +00:00
|
|
|
|
2016-08-11 12:42:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2016-08-11 12:42:17 +00:00
|
|
|
|
|
|
|
static int countDecimalDigits( double x, int maxDigits )
|
2016-08-11 12:42:10 +00:00
|
|
|
{
|
2021-02-17 23:52:56 +00:00
|
|
|
if( std::isnan( x ) )
|
|
|
|
return 0;
|
|
|
|
|
2023-08-02 12:24:46 +00:00
|
|
|
auto countSignificantDigits =
|
|
|
|
[&]( int64_t k )
|
|
|
|
{
|
|
|
|
while( k && ( k % 10LL ) == 0LL )
|
|
|
|
k /= 10LL;
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2023-08-02 12:24:46 +00:00
|
|
|
int n = 0;
|
2016-08-11 12:42:10 +00:00
|
|
|
|
2023-08-02 12:24:46 +00:00
|
|
|
while( k != 0LL )
|
|
|
|
{
|
|
|
|
n++;
|
|
|
|
k /= 10LL;
|
|
|
|
}
|
2016-08-11 12:42:10 +00:00
|
|
|
|
2023-08-02 12:24:46 +00:00
|
|
|
return n;
|
|
|
|
};
|
|
|
|
|
|
|
|
int64_t k = (int)( ( x - floor( x ) ) * pow( 10.0, (double) maxDigits ) );
|
|
|
|
int n = countSignificantDigits( k );
|
|
|
|
|
|
|
|
// check for trailing 9's
|
|
|
|
n = std::min( n, countSignificantDigits( k + 1 ) );
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2016-08-11 12:42:10 +00:00
|
|
|
return n;
|
2016-08-11 12:41:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-02 12:49:50 +00:00
|
|
|
template <typename T_PARENT>
|
|
|
|
class LIN_SCALE : public T_PARENT
|
2016-08-11 12:41:49 +00:00
|
|
|
{
|
2021-01-25 21:29:13 +00:00
|
|
|
public:
|
2022-12-11 20:10:09 +00:00
|
|
|
LIN_SCALE( const wxString& name, const wxString& unit, int flags ) :
|
2023-08-02 12:49:50 +00:00
|
|
|
T_PARENT( name, flags, false ),
|
2022-12-11 20:10:09 +00:00
|
|
|
m_unit( unit )
|
|
|
|
{};
|
2016-08-11 12:41:52 +00:00
|
|
|
|
2023-01-29 16:01:03 +00:00
|
|
|
wxString GetUnits() const { return m_unit; }
|
|
|
|
|
|
|
|
private:
|
2021-01-25 21:29:13 +00:00
|
|
|
void formatLabels() override
|
2016-08-11 12:41:52 +00:00
|
|
|
{
|
2023-08-02 12:49:50 +00:00
|
|
|
double maxVis = T_PARENT::AbsVisibleMaxValue();
|
2016-08-11 12:42:10 +00:00
|
|
|
|
2022-12-11 20:10:09 +00:00
|
|
|
wxString suffix;
|
|
|
|
int power = 0;
|
|
|
|
int digits = 0;
|
2023-08-02 12:24:46 +00:00
|
|
|
int constexpr MAX_DIGITS = 3;
|
2023-08-02 12:49:50 +00:00
|
|
|
int constexpr MAX_DISAMBIGUATION_DIGITS = 6;
|
2023-08-02 12:43:08 +00:00
|
|
|
bool duplicateLabels = false;
|
2016-08-11 12:41:52 +00:00
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
getSISuffix( maxVis, m_unit, power, suffix );
|
2016-08-11 12:41:52 +00:00
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
double sf = pow( 10.0, power );
|
2016-08-11 12:42:17 +00:00
|
|
|
|
2023-08-02 15:26:17 +00:00
|
|
|
for( mpScaleBase::TICK_LABEL& l : T_PARENT::m_tickLabels )
|
2023-08-02 12:43:08 +00:00
|
|
|
digits = std::max( digits, countDecimalDigits( l.pos / sf, MAX_DIGITS ) );
|
|
|
|
|
|
|
|
do
|
2021-01-25 21:29:13 +00:00
|
|
|
{
|
2023-08-02 14:43:53 +00:00
|
|
|
for( size_t ii = 0; ii < T_PARENT::m_tickLabels.size(); ++ii )
|
2023-08-02 12:43:08 +00:00
|
|
|
{
|
2023-08-02 15:26:17 +00:00
|
|
|
mpScaleBase::TICK_LABEL& l = T_PARENT::m_tickLabels[ii];
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2023-08-04 22:41:50 +00:00
|
|
|
l.label = formatFloat( l.pos / sf, digits );
|
2023-08-02 12:43:08 +00:00
|
|
|
l.visible = true;
|
2016-08-11 12:42:10 +00:00
|
|
|
|
2023-08-02 14:43:53 +00:00
|
|
|
if( ii > 0 && l.label == T_PARENT::m_tickLabels[ii-1].label )
|
2023-08-02 12:43:08 +00:00
|
|
|
duplicateLabels = true;
|
|
|
|
}
|
2016-08-11 12:42:10 +00:00
|
|
|
}
|
2023-08-02 12:49:50 +00:00
|
|
|
while( duplicateLabels && ++digits <= MAX_DISAMBIGUATION_DIGITS );
|
2023-08-04 22:41:50 +00:00
|
|
|
|
|
|
|
if( m_base_axis_label.IsEmpty() )
|
|
|
|
m_base_axis_label = T_PARENT::GetName();
|
|
|
|
|
|
|
|
T_PARENT::SetName( wxString::Format( "%s (%s)", m_base_axis_label, suffix ) );
|
2016-08-11 12:42:10 +00:00
|
|
|
}
|
2021-07-09 20:20:23 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
const wxString m_unit;
|
2023-08-04 22:41:50 +00:00
|
|
|
wxString m_base_axis_label;
|
2016-08-11 12:42:10 +00:00
|
|
|
};
|
|
|
|
|
2016-08-11 12:42:17 +00:00
|
|
|
|
2023-06-18 15:23:38 +00:00
|
|
|
class TIME_SCALE : public LIN_SCALE<mpScaleX>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TIME_SCALE( const wxString& name, const wxString& unit, int flags ) :
|
2023-09-20 16:23:08 +00:00
|
|
|
LIN_SCALE( name, unit, flags ),
|
|
|
|
m_startTime( 0.0 ),
|
|
|
|
m_endTime( 1.0 )
|
2023-06-18 15:23:38 +00:00
|
|
|
{};
|
|
|
|
|
|
|
|
void ExtendDataRange( double minV, double maxV ) override
|
|
|
|
{
|
2023-09-20 16:23:08 +00:00
|
|
|
LIN_SCALE::ExtendDataRange( minV, maxV );
|
2023-06-18 15:23:38 +00:00
|
|
|
|
2023-09-20 16:23:08 +00:00
|
|
|
// Time is never longer than the simulation itself
|
|
|
|
if( m_minV < m_startTime )
|
|
|
|
m_minV = m_startTime;
|
|
|
|
|
|
|
|
if( m_maxV > m_endTime )
|
|
|
|
m_maxV = m_endTime;
|
|
|
|
};
|
|
|
|
|
|
|
|
void SetStartAndEnd( double aStartTime, double aEndTime )
|
|
|
|
{
|
|
|
|
m_startTime = aStartTime;
|
|
|
|
m_endTime = aEndTime;
|
|
|
|
ResetDataRange();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResetDataRange() override
|
|
|
|
{
|
|
|
|
m_minV = m_startTime;
|
|
|
|
m_maxV = m_endTime;
|
|
|
|
m_rangeSet = true;
|
2023-06-18 15:23:38 +00:00
|
|
|
}
|
2023-09-20 16:23:08 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
double m_startTime;
|
|
|
|
double m_endTime;
|
2023-06-18 15:23:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-08-02 12:49:50 +00:00
|
|
|
template <typename T_PARENT>
|
|
|
|
class LOG_SCALE : public T_PARENT
|
2016-08-11 12:41:49 +00:00
|
|
|
{
|
|
|
|
public:
|
2022-12-11 20:10:09 +00:00
|
|
|
LOG_SCALE( const wxString& name, const wxString& unit, int flags ) :
|
2023-08-02 12:49:50 +00:00
|
|
|
T_PARENT( name, flags, false ),
|
2022-12-11 20:10:09 +00:00
|
|
|
m_unit( unit )
|
|
|
|
{};
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2023-01-29 16:01:03 +00:00
|
|
|
wxString GetUnits() const { return m_unit; }
|
|
|
|
|
|
|
|
private:
|
2016-09-27 08:58:05 +00:00
|
|
|
void formatLabels() override
|
2016-08-11 12:41:49 +00:00
|
|
|
{
|
2023-08-02 12:24:46 +00:00
|
|
|
wxString suffix;
|
|
|
|
int power;
|
|
|
|
int constexpr MAX_DIGITS = 3;
|
2016-08-11 12:42:17 +00:00
|
|
|
|
2023-08-02 15:26:17 +00:00
|
|
|
for( mpScaleBase::TICK_LABEL& l : T_PARENT::m_tickLabels )
|
2021-01-25 21:29:13 +00:00
|
|
|
{
|
|
|
|
getSISuffix( l.pos, m_unit, power, suffix );
|
|
|
|
double sf = pow( 10.0, power );
|
2023-08-02 12:24:46 +00:00
|
|
|
int k = countDecimalDigits( l.pos / sf, MAX_DIGITS );
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
l.label = formatFloat( l.pos / sf, k ) + suffix;
|
|
|
|
l.visible = true;
|
|
|
|
}
|
2016-08-11 12:41:49 +00:00
|
|
|
}
|
2021-07-09 20:20:23 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
const wxString m_unit;
|
2016-08-11 12:41:49 +00:00
|
|
|
};
|
2016-08-11 12:42:04 +00:00
|
|
|
|
2016-08-11 12:42:07 +00:00
|
|
|
|
2023-01-29 16:01:03 +00:00
|
|
|
void CURSOR::SetCoordX( double aValue )
|
2016-08-11 12:41:22 +00:00
|
|
|
{
|
2023-01-29 16:01:03 +00:00
|
|
|
wxRealPoint oldCoords = m_coords;
|
2016-08-11 12:41:24 +00:00
|
|
|
|
2023-01-29 16:01:03 +00:00
|
|
|
doSetCoordX( aValue );
|
|
|
|
m_updateRequired = false;
|
|
|
|
m_updateRef = true;
|
|
|
|
|
|
|
|
if( m_window )
|
|
|
|
{
|
|
|
|
wxRealPoint delta = m_coords - oldCoords;
|
|
|
|
mpInfoLayer::Move( wxPoint( m_window->x2p( m_trace->x2s( delta.x ) ),
|
|
|
|
m_window->y2p( m_trace->y2s( delta.y ) ) ) );
|
|
|
|
|
|
|
|
m_window->Refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CURSOR::doSetCoordX( double aValue )
|
|
|
|
{
|
|
|
|
m_coords.x = aValue;
|
2016-08-11 12:41:22 +00:00
|
|
|
|
2023-01-29 16:01:03 +00:00
|
|
|
const std::vector<double>& dataX = m_trace->GetDataX();
|
|
|
|
const std::vector<double>& dataY = m_trace->GetDataY();
|
2016-08-11 12:41:22 +00:00
|
|
|
|
|
|
|
if( dataX.size() <= 1 )
|
|
|
|
return;
|
|
|
|
|
2023-01-29 16:01:03 +00:00
|
|
|
// Find the closest point coordinates
|
|
|
|
auto maxXIt = std::upper_bound( dataX.begin(), dataX.end(), m_coords.x );
|
|
|
|
int maxIdx = maxXIt - dataX.begin();
|
|
|
|
int minIdx = maxIdx - 1;
|
|
|
|
|
|
|
|
// Out of bounds checks
|
2023-09-17 18:23:20 +00:00
|
|
|
if( minIdx < 0 || maxIdx >= (int) dataX.size() )
|
2016-08-11 12:41:22 +00:00
|
|
|
{
|
2023-09-17 18:23:20 +00:00
|
|
|
// Simulation may not be complete yet, or we may have a cursor off the beginning or end
|
|
|
|
// of the data. Either way, that's where the user put it. Don't second guess them; just
|
|
|
|
// leave its y value undefined.
|
|
|
|
m_coords.y = NAN;
|
|
|
|
return;
|
2023-01-29 16:01:03 +00:00
|
|
|
}
|
2016-08-11 12:41:22 +00:00
|
|
|
|
2023-01-29 16:01:03 +00:00
|
|
|
const double leftX = dataX[minIdx];
|
|
|
|
const double rightX = dataX[maxIdx];
|
|
|
|
const double leftY = dataY[minIdx];
|
|
|
|
const double rightY = dataY[maxIdx];
|
2016-08-11 12:41:22 +00:00
|
|
|
|
2023-01-29 16:01:03 +00:00
|
|
|
// Linear interpolation
|
|
|
|
m_coords.y = leftY + ( rightY - leftY ) / ( rightX - leftX ) * ( m_coords.x - leftX );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-29 17:35:19 +00:00
|
|
|
wxString CURSOR::getID()
|
|
|
|
{
|
|
|
|
for( const auto& [ id, cursor ] : m_trace->GetCursors() )
|
|
|
|
{
|
|
|
|
if( cursor == this )
|
|
|
|
return wxString::Format( _( "%d" ), id );
|
|
|
|
}
|
|
|
|
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-29 16:01:03 +00:00
|
|
|
void CURSOR::Plot( wxDC& aDC, mpWindow& aWindow )
|
|
|
|
{
|
|
|
|
if( !m_window )
|
|
|
|
m_window = &aWindow;
|
2016-08-11 12:41:22 +00:00
|
|
|
|
2023-01-29 16:01:03 +00:00
|
|
|
if( !m_visible || m_trace->GetDataX().size() <= 1 )
|
|
|
|
return;
|
2016-08-11 12:41:22 +00:00
|
|
|
|
2023-01-29 16:01:03 +00:00
|
|
|
if( m_updateRequired )
|
|
|
|
{
|
|
|
|
doSetCoordX( m_trace->s2x( aWindow.p2x( m_dim.x ) ) );
|
2016-08-11 12:41:25 +00:00
|
|
|
m_updateRequired = false;
|
2016-08-11 12:41:27 +00:00
|
|
|
|
|
|
|
// Notify the parent window about the changes
|
|
|
|
wxQueueEvent( aWindow.GetParent(), new wxCommandEvent( EVT_SIM_CURSOR_UPDATE ) );
|
2016-08-11 12:41:22 +00:00
|
|
|
}
|
|
|
|
else
|
2016-08-11 12:42:14 +00:00
|
|
|
{
|
|
|
|
m_updateRef = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_updateRef )
|
2016-08-11 12:41:22 +00:00
|
|
|
{
|
|
|
|
UpdateReference();
|
2016-08-11 12:42:14 +00:00
|
|
|
m_updateRef = false;
|
2016-08-11 12:41:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Line length in horizontal and vertical dimensions
|
2016-08-11 12:41:55 +00:00
|
|
|
const wxPoint cursorPos( aWindow.x2p( m_trace->x2s( m_coords.x ) ),
|
|
|
|
aWindow.y2p( m_trace->y2s( m_coords.y ) ) );
|
2016-08-11 12:41:55 +00:00
|
|
|
|
2023-07-18 10:56:36 +00:00
|
|
|
wxCoord leftPx = aWindow.GetMarginLeft();
|
|
|
|
wxCoord rightPx = aWindow.GetScrX() - aWindow.GetMarginRight();
|
|
|
|
wxCoord topPx = aWindow.GetMarginTop();
|
|
|
|
wxCoord bottomPx = aWindow.GetScrY() - aWindow.GetMarginBottom();
|
2016-08-11 12:41:55 +00:00
|
|
|
|
2023-01-29 17:35:19 +00:00
|
|
|
wxPen pen = GetPen();
|
|
|
|
wxColour fg = GetPen().GetColour();
|
|
|
|
|
|
|
|
pen.SetColour( COLOR4D( m_trace->GetTraceColour() ).Mix( fg, 0.6 ).ToColour() );
|
2021-01-21 21:17:13 +00:00
|
|
|
pen.SetStyle( m_continuous ? wxPENSTYLE_SOLID : wxPENSTYLE_LONG_DASH );
|
|
|
|
aDC.SetPen( pen );
|
2016-08-11 12:41:55 +00:00
|
|
|
|
|
|
|
if( topPx < cursorPos.y && cursorPos.y < bottomPx )
|
|
|
|
aDC.DrawLine( leftPx, cursorPos.y, rightPx, cursorPos.y );
|
|
|
|
|
|
|
|
if( leftPx < cursorPos.x && cursorPos.x < rightPx )
|
2023-01-29 17:35:19 +00:00
|
|
|
{
|
2016-08-11 12:41:55 +00:00
|
|
|
aDC.DrawLine( cursorPos.x, topPx, cursorPos.x, bottomPx );
|
2023-01-29 17:35:19 +00:00
|
|
|
|
|
|
|
wxString id = getID();
|
|
|
|
wxSize size = aDC.GetTextExtent( wxS( "M" ) );
|
|
|
|
wxRect textRect( wxPoint( cursorPos.x + 1 - size.x / 2, topPx - 4 - size.y ), size );
|
|
|
|
wxBrush brush;
|
|
|
|
wxPoint poly[3];
|
|
|
|
|
|
|
|
// Because a "1" looks off-center if it's actually centred.
|
|
|
|
if( id == "1" )
|
|
|
|
textRect.x -= 1;
|
|
|
|
|
|
|
|
// We want an equalateral triangle, so use size.y for both axes.
|
|
|
|
size.y += 3;
|
|
|
|
// Make sure it's an even number so the slopes of the sides will be identical.
|
|
|
|
size.y = ( size.y / 2 ) * 2;
|
|
|
|
poly[0] = { cursorPos.x - 1 - size.y / 2, topPx - size.y };
|
|
|
|
poly[1] = { cursorPos.x + 1 + size.y / 2, topPx - size.y };
|
|
|
|
poly[2] = { cursorPos.x, topPx };
|
|
|
|
|
|
|
|
brush.SetStyle( wxBRUSHSTYLE_SOLID );
|
|
|
|
brush.SetColour( m_trace->GetTraceColour() );
|
|
|
|
aDC.SetBrush( brush );
|
|
|
|
aDC.DrawPolygon( 3, poly );
|
|
|
|
|
|
|
|
aDC.SetTextForeground( fg );
|
|
|
|
aDC.DrawLabel( id, textRect, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL );
|
|
|
|
}
|
2016-08-11 12:41:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-31 17:29:46 +00:00
|
|
|
bool CURSOR::Inside( const wxPoint& aPoint ) const
|
2016-08-11 12:41:55 +00:00
|
|
|
{
|
2023-02-21 09:06:02 +00:00
|
|
|
if( !m_window || !m_trace )
|
2016-08-11 12:41:55 +00:00
|
|
|
return false;
|
|
|
|
|
2021-07-09 20:20:23 +00:00
|
|
|
return ( std::abs( (double) aPoint.x -
|
|
|
|
m_window->x2p( m_trace->x2s( m_coords.x ) ) ) <= DRAG_MARGIN )
|
|
|
|
|| ( std::abs( (double) aPoint.y -
|
|
|
|
m_window->y2p( m_trace->y2s( m_coords.y ) ) ) <= DRAG_MARGIN );
|
2016-08-11 12:41:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CURSOR::UpdateReference()
|
|
|
|
{
|
|
|
|
if( !m_window )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_reference.x = m_window->x2p( m_trace->x2s( m_coords.x ) );
|
|
|
|
m_reference.y = m_window->y2p( m_trace->y2s( m_coords.y ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-19 15:25:57 +00:00
|
|
|
SIM_PLOT_TAB::SIM_PLOT_TAB( const wxString& aSimCommand, wxWindow* parent ) :
|
|
|
|
SIM_TAB( aSimCommand, parent ),
|
2023-02-10 20:52:52 +00:00
|
|
|
m_axis_x( nullptr ),
|
|
|
|
m_axis_y1( nullptr ),
|
|
|
|
m_axis_y2( nullptr ),
|
|
|
|
m_axis_y3( nullptr ),
|
|
|
|
m_dotted_cp( false )
|
2016-08-11 12:41:01 +00:00
|
|
|
{
|
2020-04-15 01:51:58 +00:00
|
|
|
m_sizer = new wxBoxSizer( wxVERTICAL );
|
2023-07-05 17:25:52 +00:00
|
|
|
m_plotWin = new mpWindow( this, wxID_ANY );
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2020-04-15 01:51:58 +00:00
|
|
|
m_plotWin->LimitView( true );
|
2023-08-06 19:33:56 +00:00
|
|
|
m_plotWin->SetMargins( 30, 70, 45, 70 );
|
2021-01-21 21:17:13 +00:00
|
|
|
UpdatePlotColors();
|
2020-04-15 01:51:58 +00:00
|
|
|
|
2021-10-18 17:01:08 +00:00
|
|
|
updateAxes();
|
|
|
|
|
|
|
|
// a mpInfoLegend displays le name of traces on the left top panel corner:
|
2023-07-20 21:43:49 +00:00
|
|
|
m_legend = new mpInfoLegend( wxRect( 0, 0, 200, 40 ), wxTRANSPARENT_BRUSH );
|
2021-10-18 17:01:08 +00:00
|
|
|
m_legend->SetVisible( false );
|
|
|
|
m_plotWin->AddLayer( m_legend );
|
2023-08-09 11:09:00 +00:00
|
|
|
m_LastLegendPosition = m_legend->GetPosition();
|
2021-10-18 17:01:08 +00:00
|
|
|
|
|
|
|
m_plotWin->EnableDoubleBuffer( true );
|
|
|
|
m_plotWin->UpdateAll();
|
|
|
|
|
|
|
|
m_sizer->Add( m_plotWin, 1, wxALL | wxEXPAND, 1 );
|
|
|
|
SetSizer( m_sizer );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
SIM_PLOT_TAB::~SIM_PLOT_TAB()
|
2021-10-18 17:01:08 +00:00
|
|
|
{
|
|
|
|
// ~mpWindow destroys all the added layers, so there is no need to destroy m_traces contents
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-19 15:25:57 +00:00
|
|
|
void SIM_PLOT_TAB::SetY1Scale( bool aLock, double aMin, double aMax )
|
|
|
|
{
|
2024-02-08 22:48:12 +00:00
|
|
|
wxCHECK( m_axis_y1, /* void */ );
|
2023-07-19 15:25:57 +00:00
|
|
|
m_axis_y1->SetAxisMinMax( aLock, aMin, aMax );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_TAB::SetY2Scale( bool aLock, double aMin, double aMax )
|
|
|
|
{
|
2024-02-08 22:48:12 +00:00
|
|
|
wxCHECK( m_axis_y2, /* void */ );
|
2023-07-19 15:25:57 +00:00
|
|
|
m_axis_y2->SetAxisMinMax( aLock, aMin, aMax );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_TAB::SetY3Scale( bool aLock, double aMin, double aMax )
|
|
|
|
{
|
2024-02-08 22:48:12 +00:00
|
|
|
wxCHECK( m_axis_y3, /* void */ );
|
2023-07-19 15:25:57 +00:00
|
|
|
m_axis_y3->SetAxisMinMax( aLock, aMin, aMax );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
wxString SIM_PLOT_TAB::GetUnitsX() const
|
2023-01-29 16:01:03 +00:00
|
|
|
{
|
|
|
|
LOG_SCALE<mpScaleXLog>* logScale = dynamic_cast<LOG_SCALE<mpScaleXLog>*>( m_axis_x );
|
|
|
|
LIN_SCALE<mpScaleX>* linScale = dynamic_cast<LIN_SCALE<mpScaleX>*>( m_axis_x );
|
|
|
|
|
|
|
|
if( logScale )
|
|
|
|
return logScale->GetUnits();
|
|
|
|
else if( linScale )
|
|
|
|
return linScale->GetUnits();
|
|
|
|
else
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
wxString SIM_PLOT_TAB::GetUnitsY1() const
|
2023-02-05 20:47:27 +00:00
|
|
|
{
|
|
|
|
LIN_SCALE<mpScaleY>* linScale = dynamic_cast<LIN_SCALE<mpScaleY>*>( m_axis_y1 );
|
|
|
|
|
|
|
|
if( linScale )
|
|
|
|
return linScale->GetUnits();
|
|
|
|
else
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
wxString SIM_PLOT_TAB::GetUnitsY2() const
|
2023-02-05 20:47:27 +00:00
|
|
|
{
|
|
|
|
LIN_SCALE<mpScaleY>* linScale = dynamic_cast<LIN_SCALE<mpScaleY>*>( m_axis_y2 );
|
|
|
|
|
|
|
|
if( linScale )
|
|
|
|
return linScale->GetUnits();
|
|
|
|
else
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
wxString SIM_PLOT_TAB::GetUnitsY3() const
|
2021-10-18 17:01:08 +00:00
|
|
|
{
|
2023-02-10 20:52:52 +00:00
|
|
|
LIN_SCALE<mpScaleY>* linScale = dynamic_cast<LIN_SCALE<mpScaleY>*>( m_axis_y3 );
|
|
|
|
|
|
|
|
if( linScale )
|
|
|
|
return linScale->GetUnits();
|
|
|
|
else
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
2023-01-04 18:06:04 +00:00
|
|
|
|
2021-10-18 17:01:08 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
void SIM_PLOT_TAB::updateAxes( int aNewTraceType )
|
2023-02-10 20:52:52 +00:00
|
|
|
{
|
2023-07-04 15:53:44 +00:00
|
|
|
switch( GetSimType() )
|
2016-08-11 12:41:35 +00:00
|
|
|
{
|
|
|
|
case ST_AC:
|
2023-01-04 18:06:04 +00:00
|
|
|
if( !m_axis_x )
|
|
|
|
{
|
|
|
|
m_axis_x = new LOG_SCALE<mpScaleXLog>( wxEmptyString, wxT( "Hz" ), mpALIGN_BOTTOM );
|
2023-02-10 20:52:52 +00:00
|
|
|
m_axis_x->SetNameAlign( mpALIGN_BOTTOM );
|
|
|
|
m_plotWin->AddLayer( m_axis_x );
|
|
|
|
|
2023-01-04 18:06:04 +00:00
|
|
|
m_axis_y1 = new LIN_SCALE<mpScaleY>( wxEmptyString, wxT( "dBV" ), mpALIGN_LEFT );
|
2023-02-10 20:52:52 +00:00
|
|
|
m_axis_y1->SetNameAlign( mpALIGN_LEFT );
|
|
|
|
m_plotWin->AddLayer( m_axis_y1 );
|
|
|
|
|
2023-01-04 18:06:04 +00:00
|
|
|
m_axis_y2 = new LIN_SCALE<mpScaleY>( wxEmptyString, wxT( "°" ), mpALIGN_RIGHT );
|
2023-02-10 20:52:52 +00:00
|
|
|
m_axis_y2->SetNameAlign( mpALIGN_RIGHT );
|
2023-01-04 18:06:04 +00:00
|
|
|
m_axis_y2->SetMasterScale( m_axis_y1 );
|
2023-02-10 20:52:52 +00:00
|
|
|
m_plotWin->AddLayer( m_axis_y2 );
|
2023-01-04 18:06:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_axis_x->SetName( _( "Frequency" ) );
|
|
|
|
m_axis_y1->SetName( _( "Gain" ) );
|
|
|
|
m_axis_y2->SetName( _( "Phase" ) );
|
2016-08-11 12:41:35 +00:00
|
|
|
break;
|
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
case ST_SP:
|
2023-07-04 16:01:12 +00:00
|
|
|
if( !m_axis_x )
|
|
|
|
{
|
|
|
|
m_axis_x = new LOG_SCALE<mpScaleXLog>( wxEmptyString, wxT( "Hz" ), mpALIGN_BOTTOM );
|
|
|
|
m_axis_x->SetNameAlign( mpALIGN_BOTTOM );
|
|
|
|
m_plotWin->AddLayer( m_axis_x );
|
|
|
|
|
|
|
|
m_axis_y1 = new LIN_SCALE<mpScaleY>( wxEmptyString, wxT( "" ), mpALIGN_LEFT );
|
|
|
|
m_axis_y1->SetNameAlign( mpALIGN_LEFT );
|
|
|
|
m_plotWin->AddLayer( m_axis_y1 );
|
|
|
|
|
|
|
|
m_axis_y2 = new LIN_SCALE<mpScaleY>( wxEmptyString, wxT( "°" ), mpALIGN_RIGHT );
|
|
|
|
m_axis_y2->SetNameAlign( mpALIGN_RIGHT );
|
|
|
|
m_axis_y2->SetMasterScale( m_axis_y1 );
|
|
|
|
m_plotWin->AddLayer( m_axis_y2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_axis_x->SetName( _( "Frequency" ) );
|
2024-01-10 16:17:07 +00:00
|
|
|
m_axis_y1->SetName( _( "Amplitude" ) );
|
2023-07-04 16:01:12 +00:00
|
|
|
m_axis_y2->SetName( _( "Phase" ) );
|
|
|
|
break;
|
|
|
|
|
2016-08-11 12:41:35 +00:00
|
|
|
case ST_DC:
|
2023-02-25 23:10:19 +00:00
|
|
|
prepareDCAxes( aNewTraceType );
|
2016-08-11 12:41:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ST_NOISE:
|
2023-01-04 18:06:04 +00:00
|
|
|
if( !m_axis_x )
|
|
|
|
{
|
|
|
|
m_axis_x = new LOG_SCALE<mpScaleXLog>( wxEmptyString, wxT( "Hz" ), mpALIGN_BOTTOM );
|
2023-02-10 20:52:52 +00:00
|
|
|
m_axis_x->SetNameAlign( mpALIGN_BOTTOM );
|
|
|
|
m_plotWin->AddLayer( m_axis_x );
|
|
|
|
|
2023-07-03 22:11:43 +00:00
|
|
|
if( ( aNewTraceType & SPT_CURRENT ) == 0 )
|
|
|
|
{
|
|
|
|
m_axis_y1 = new LIN_SCALE<mpScaleY>( wxEmptyString, wxT( "" ), mpALIGN_LEFT );
|
|
|
|
m_axis_y1->SetNameAlign( mpALIGN_LEFT );
|
|
|
|
m_plotWin->AddLayer( m_axis_y1 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_axis_y2 = new LIN_SCALE<mpScaleY>( wxEmptyString, wxT( "" ), mpALIGN_RIGHT );
|
|
|
|
m_axis_y2->SetNameAlign( mpALIGN_RIGHT );
|
|
|
|
m_plotWin->AddLayer( m_axis_y2 );
|
|
|
|
}
|
2023-01-04 18:06:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_axis_x->SetName( _( "Frequency" ) );
|
2023-07-03 22:11:43 +00:00
|
|
|
|
|
|
|
if( m_axis_y1 )
|
|
|
|
m_axis_y1->SetName( _( "Noise (V/√Hz)" ) );
|
|
|
|
|
|
|
|
if( m_axis_y2 )
|
|
|
|
m_axis_y2->SetName( _( "Noise (A/√Hz)" ) );
|
|
|
|
|
2016-08-11 12:41:35 +00:00
|
|
|
break;
|
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
case ST_FFT:
|
|
|
|
if( !m_axis_x )
|
|
|
|
{
|
|
|
|
m_axis_x = new LOG_SCALE<mpScaleXLog>( wxEmptyString, wxT( "Hz" ), mpALIGN_BOTTOM );
|
|
|
|
m_axis_x->SetNameAlign( mpALIGN_BOTTOM );
|
|
|
|
m_plotWin->AddLayer( m_axis_x );
|
|
|
|
|
|
|
|
m_axis_y1 = new LIN_SCALE<mpScaleY>( wxEmptyString, wxT( "dB" ), mpALIGN_LEFT );
|
|
|
|
m_axis_y1->SetNameAlign( mpALIGN_LEFT );
|
|
|
|
m_plotWin->AddLayer( m_axis_y1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_axis_x->SetName( _( "Frequency" ) );
|
|
|
|
m_axis_y1->SetName( _( "Intensity" ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ST_TRAN:
|
2023-01-04 18:06:04 +00:00
|
|
|
if( !m_axis_x )
|
|
|
|
{
|
2023-06-18 15:23:38 +00:00
|
|
|
m_axis_x = new TIME_SCALE( wxEmptyString, wxT( "s" ), mpALIGN_BOTTOM );
|
2023-02-10 20:52:52 +00:00
|
|
|
m_axis_x->SetNameAlign( mpALIGN_BOTTOM );
|
|
|
|
m_plotWin->AddLayer( m_axis_x );
|
|
|
|
|
2023-01-04 18:06:04 +00:00
|
|
|
m_axis_y1 = new LIN_SCALE<mpScaleY>(wxEmptyString, wxT( "V" ), mpALIGN_LEFT );
|
2023-02-10 20:52:52 +00:00
|
|
|
m_axis_y1->SetNameAlign( mpALIGN_LEFT );
|
|
|
|
m_plotWin->AddLayer( m_axis_y1 );
|
|
|
|
|
2023-01-04 18:06:04 +00:00
|
|
|
m_axis_y2 = new LIN_SCALE<mpScaleY>( wxEmptyString, wxT( "A" ), mpALIGN_RIGHT );
|
2023-02-10 20:52:52 +00:00
|
|
|
m_axis_y2->SetNameAlign( mpALIGN_RIGHT );
|
2023-01-04 18:06:04 +00:00
|
|
|
m_axis_y2->SetMasterScale( m_axis_y1 );
|
2023-02-10 20:52:52 +00:00
|
|
|
m_plotWin->AddLayer( m_axis_y2 );
|
2023-01-04 18:06:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_axis_x->SetName( _( "Time" ) );
|
|
|
|
m_axis_y1->SetName( _( "Voltage" ) );
|
|
|
|
m_axis_y2->SetName( _( "Current" ) );
|
2016-08-11 12:41:35 +00:00
|
|
|
|
2023-02-22 12:17:46 +00:00
|
|
|
if( ( aNewTraceType & SPT_POWER ) && !m_axis_y3 )
|
2023-02-10 20:52:52 +00:00
|
|
|
{
|
2023-08-06 19:33:56 +00:00
|
|
|
m_plotWin->SetMargins( 30, 140, 45, 70 );
|
2023-01-04 18:06:04 +00:00
|
|
|
|
2023-02-10 20:52:52 +00:00
|
|
|
m_axis_y3 = new LIN_SCALE<mpScaleY>( wxEmptyString, wxT( "W" ), mpALIGN_FAR_RIGHT );
|
|
|
|
m_axis_y3->SetNameAlign( mpALIGN_FAR_RIGHT );
|
|
|
|
m_axis_y3->SetMasterScale( m_axis_y1 );
|
|
|
|
m_plotWin->AddLayer( m_axis_y3 );
|
|
|
|
}
|
2016-08-11 12:42:04 +00:00
|
|
|
|
2023-02-10 20:52:52 +00:00
|
|
|
if( m_axis_y3 )
|
|
|
|
m_axis_y3->SetName( _( "Power" ) );
|
2016-08-11 12:41:35 +00:00
|
|
|
|
2023-02-10 20:52:52 +00:00
|
|
|
break;
|
2016-08-11 12:41:35 +00:00
|
|
|
|
2023-02-10 20:52:52 +00:00
|
|
|
default:
|
|
|
|
// suppress warnings
|
|
|
|
break;
|
2016-08-11 12:41:35 +00:00
|
|
|
}
|
2023-06-19 21:52:13 +00:00
|
|
|
|
|
|
|
if( m_axis_x )
|
|
|
|
m_axis_x->SetFont( KIUI::GetStatusFont( m_plotWin ) );
|
|
|
|
|
|
|
|
if( m_axis_y1 )
|
|
|
|
m_axis_y1->SetFont( KIUI::GetStatusFont( m_plotWin ) );
|
|
|
|
|
|
|
|
if( m_axis_y2 )
|
|
|
|
m_axis_y2->SetFont( KIUI::GetStatusFont( m_plotWin ) );
|
|
|
|
|
|
|
|
if( m_axis_y3 )
|
|
|
|
m_axis_y3->SetFont( KIUI::GetStatusFont( m_plotWin ) );
|
2016-08-11 12:41:14 +00:00
|
|
|
}
|
|
|
|
|
2023-06-19 21:52:13 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
void SIM_PLOT_TAB::prepareDCAxes( int aNewTraceType )
|
2021-01-25 21:29:13 +00:00
|
|
|
{
|
2023-02-12 14:55:00 +00:00
|
|
|
wxString sim_cmd = GetSimCommand().Lower();
|
2021-10-18 17:01:08 +00:00
|
|
|
wxString rem;
|
2021-01-25 21:29:13 +00:00
|
|
|
|
2021-10-18 17:09:36 +00:00
|
|
|
if( sim_cmd.StartsWith( ".dc", &rem ) )
|
2021-01-25 21:29:13 +00:00
|
|
|
{
|
2023-04-11 08:53:35 +00:00
|
|
|
wxChar ch = 0;
|
2021-10-18 17:01:08 +00:00
|
|
|
|
2021-10-18 17:09:36 +00:00
|
|
|
rem.Trim( false );
|
|
|
|
|
2021-10-18 17:01:08 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
ch = rem.GetChar( 0 );
|
|
|
|
}
|
|
|
|
catch( ... )
|
2023-01-04 18:06:04 +00:00
|
|
|
{
|
|
|
|
// Best efforts
|
|
|
|
}
|
2021-10-18 17:01:08 +00:00
|
|
|
|
|
|
|
switch( ch )
|
2021-01-25 21:29:13 +00:00
|
|
|
{
|
2021-10-18 17:01:08 +00:00
|
|
|
// Make sure that we have a reliable default (even if incorrectly labeled)
|
|
|
|
default:
|
2021-01-25 21:29:13 +00:00
|
|
|
case 'v':
|
2023-01-04 18:06:04 +00:00
|
|
|
if( !m_axis_x )
|
2023-02-10 20:52:52 +00:00
|
|
|
{
|
2023-01-04 18:06:04 +00:00
|
|
|
m_axis_x = new LIN_SCALE<mpScaleX>( wxEmptyString, wxT( "V" ), mpALIGN_BOTTOM );
|
2023-02-10 20:52:52 +00:00
|
|
|
m_axis_x->SetNameAlign( mpALIGN_BOTTOM );
|
|
|
|
m_plotWin->AddLayer( m_axis_x );
|
|
|
|
}
|
2023-01-04 18:06:04 +00:00
|
|
|
|
|
|
|
m_axis_x->SetName( _( "Voltage (swept)" ) );
|
2021-01-25 21:29:13 +00:00
|
|
|
break;
|
2023-01-04 18:06:04 +00:00
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
case 'i':
|
2023-01-04 18:06:04 +00:00
|
|
|
if( !m_axis_x )
|
2023-02-10 20:52:52 +00:00
|
|
|
{
|
2023-01-04 18:06:04 +00:00
|
|
|
m_axis_x = new LIN_SCALE<mpScaleX>( wxEmptyString, wxT( "A" ), mpALIGN_BOTTOM );
|
2023-02-10 20:52:52 +00:00
|
|
|
m_axis_x->SetNameAlign( mpALIGN_BOTTOM );
|
|
|
|
m_plotWin->AddLayer( m_axis_x );
|
|
|
|
}
|
2023-01-04 18:06:04 +00:00
|
|
|
|
|
|
|
m_axis_x->SetName( _( "Current (swept)" ) );
|
2021-01-25 21:29:13 +00:00
|
|
|
break;
|
2023-01-04 18:06:04 +00:00
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
case 'r':
|
2023-01-04 18:06:04 +00:00
|
|
|
if( !m_axis_x )
|
2023-02-10 20:52:52 +00:00
|
|
|
{
|
2023-01-04 18:06:04 +00:00
|
|
|
m_axis_x = new LIN_SCALE<mpScaleX>( wxEmptyString, wxT( "Ω" ), mpALIGN_BOTTOM );
|
2023-02-10 20:52:52 +00:00
|
|
|
m_axis_x->SetNameAlign( mpALIGN_BOTTOM );
|
|
|
|
m_plotWin->AddLayer( m_axis_x );
|
|
|
|
}
|
2023-01-04 18:06:04 +00:00
|
|
|
|
|
|
|
m_axis_x->SetName( _( "Resistance (swept)" ) );
|
2021-01-25 21:29:13 +00:00
|
|
|
break;
|
2023-01-04 18:06:04 +00:00
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
case 't':
|
2023-01-04 18:06:04 +00:00
|
|
|
if( !m_axis_x )
|
2023-02-10 20:52:52 +00:00
|
|
|
{
|
2023-01-04 18:06:04 +00:00
|
|
|
m_axis_x = new LIN_SCALE<mpScaleX>( wxEmptyString, wxT( "°C" ), mpALIGN_BOTTOM );
|
2023-02-10 20:52:52 +00:00
|
|
|
m_axis_x->SetNameAlign( mpALIGN_BOTTOM );
|
|
|
|
m_plotWin->AddLayer( m_axis_x );
|
|
|
|
}
|
2023-01-04 18:06:04 +00:00
|
|
|
|
|
|
|
m_axis_x->SetName( _( "Temperature (swept)" ) );
|
2021-01-25 21:29:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-01-04 18:06:04 +00:00
|
|
|
if( !m_axis_y1 )
|
2023-02-10 20:52:52 +00:00
|
|
|
{
|
2023-01-04 18:06:04 +00:00
|
|
|
m_axis_y1 = new LIN_SCALE<mpScaleY>( wxEmptyString, wxT( "V" ), mpALIGN_LEFT );
|
2023-02-10 20:52:52 +00:00
|
|
|
m_axis_y1->SetNameAlign( mpALIGN_LEFT );
|
|
|
|
m_plotWin->AddLayer( m_axis_y1 );
|
|
|
|
}
|
2023-01-04 18:06:04 +00:00
|
|
|
|
|
|
|
if( !m_axis_y2 )
|
2023-02-10 20:52:52 +00:00
|
|
|
{
|
2023-01-04 18:06:04 +00:00
|
|
|
m_axis_y2 = new LIN_SCALE<mpScaleY>( wxEmptyString, wxT( "A" ), mpALIGN_RIGHT );
|
2023-02-10 20:52:52 +00:00
|
|
|
m_axis_y2->SetNameAlign( mpALIGN_RIGHT );
|
|
|
|
m_plotWin->AddLayer( m_axis_y2 );
|
|
|
|
}
|
2023-01-04 18:06:04 +00:00
|
|
|
|
|
|
|
m_axis_y1->SetName( _( "Voltage (measured)" ) );
|
|
|
|
m_axis_y2->SetName( _( "Current" ) );
|
2023-02-25 23:10:19 +00:00
|
|
|
|
2024-02-08 22:48:12 +00:00
|
|
|
if( ( aNewTraceType & SPT_POWER ) )
|
|
|
|
EnsureThirdYAxisExists();
|
2023-02-25 23:10:19 +00:00
|
|
|
|
|
|
|
if( m_axis_y3 )
|
|
|
|
m_axis_y3->SetName( _( "Power" ) );
|
2021-01-25 21:29:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-02-08 22:48:12 +00:00
|
|
|
void SIM_PLOT_TAB::EnsureThirdYAxisExists()
|
|
|
|
{
|
|
|
|
if( !m_axis_y3 )
|
|
|
|
{
|
|
|
|
m_plotWin->SetMargins( 30, 140, 45, 70 );
|
|
|
|
m_axis_y3 = new LIN_SCALE<mpScaleY>( wxEmptyString, wxT( "W" ), mpALIGN_FAR_RIGHT );
|
|
|
|
m_axis_y3->SetNameAlign( mpALIGN_FAR_RIGHT );
|
|
|
|
m_axis_y3->SetMasterScale( m_axis_y1 );
|
|
|
|
m_plotWin->AddLayer( m_axis_y3 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
void SIM_PLOT_TAB::UpdatePlotColors()
|
2020-02-01 12:05:44 +00:00
|
|
|
{
|
|
|
|
// Update bg and fg colors:
|
2021-01-21 21:17:13 +00:00
|
|
|
m_plotWin->SetColourTheme( m_colors.GetPlotColor( SIM_PLOT_COLORS::COLOR_SET::BACKGROUND ),
|
|
|
|
m_colors.GetPlotColor( SIM_PLOT_COLORS::COLOR_SET::FOREGROUND ),
|
|
|
|
m_colors.GetPlotColor( SIM_PLOT_COLORS::COLOR_SET::AXIS ) );
|
2020-02-01 12:05:44 +00:00
|
|
|
|
2021-01-21 21:17:13 +00:00
|
|
|
m_plotWin->UpdateAll();
|
2020-02-01 12:05:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
void SIM_PLOT_TAB::OnLanguageChanged()
|
2023-01-04 18:06:04 +00:00
|
|
|
{
|
|
|
|
updateAxes();
|
|
|
|
m_plotWin->UpdateAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
void SIM_PLOT_TAB::UpdateTraceStyle( TRACE* trace )
|
2019-11-19 16:17:37 +00:00
|
|
|
{
|
2021-05-24 20:17:29 +00:00
|
|
|
int type = trace->GetType();
|
2021-10-18 17:01:08 +00:00
|
|
|
wxPenStyle penStyle = ( ( ( type & SPT_AC_PHASE ) || ( type & SPT_CURRENT ) ) && m_dotted_cp )
|
2021-05-24 20:17:29 +00:00
|
|
|
? wxPENSTYLE_DOT
|
|
|
|
: wxPENSTYLE_SOLID;
|
2019-11-19 16:17:37 +00:00
|
|
|
trace->SetPen( wxPen( trace->GetTraceColour(), 2, penStyle ) );
|
2023-10-04 15:50:49 +00:00
|
|
|
|
|
|
|
m_sessionTraceColors[ trace->GetName() ] = trace->GetTraceColour();
|
2019-11-19 16:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-03 11:55:19 +00:00
|
|
|
TRACE* SIM_PLOT_TAB::GetOrAddTrace( const wxString& aVectorName, int aType )
|
2016-08-11 12:41:01 +00:00
|
|
|
{
|
2023-03-02 00:37:12 +00:00
|
|
|
TRACE* trace = GetTrace( aVectorName, aType );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2023-02-27 21:08:05 +00:00
|
|
|
if( !trace )
|
2016-08-11 12:41:16 +00:00
|
|
|
{
|
2023-02-27 21:08:05 +00:00
|
|
|
updateAxes( aType );
|
2016-08-11 12:42:14 +00:00
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
if( GetSimType() == ST_TRAN || GetSimType() == ST_DC )
|
2023-02-12 14:55:00 +00:00
|
|
|
{
|
2023-02-27 21:08:05 +00:00
|
|
|
bool hasVoltageTraces = false;
|
|
|
|
|
|
|
|
for( const auto& [ id, candidate ] : m_traces )
|
2016-08-11 12:42:14 +00:00
|
|
|
{
|
2023-02-27 21:08:05 +00:00
|
|
|
if( candidate->GetType() & SPT_VOLTAGE )
|
|
|
|
{
|
|
|
|
hasVoltageTraces = true;
|
|
|
|
break;
|
|
|
|
}
|
2016-08-11 12:42:14 +00:00
|
|
|
}
|
|
|
|
|
2023-02-27 21:08:05 +00:00
|
|
|
if( !hasVoltageTraces )
|
|
|
|
{
|
|
|
|
if( m_axis_y2 )
|
|
|
|
m_axis_y2->SetMasterScale( nullptr );
|
2023-02-10 20:52:52 +00:00
|
|
|
|
2023-02-27 21:08:05 +00:00
|
|
|
if( m_axis_y3 )
|
|
|
|
m_axis_y3->SetMasterScale( nullptr );
|
|
|
|
}
|
2016-08-11 12:42:14 +00:00
|
|
|
}
|
|
|
|
|
2023-03-02 00:37:12 +00:00
|
|
|
trace = new TRACE( aVectorName, (SIM_TRACE_TYPE) aType );
|
2023-10-04 15:50:49 +00:00
|
|
|
|
|
|
|
if( m_sessionTraceColors.count( aVectorName ) )
|
|
|
|
trace->SetTraceColour( m_sessionTraceColors[ aVectorName ] );
|
|
|
|
else
|
|
|
|
trace->SetTraceColour( m_colors.GenerateColor( m_sessionTraceColors ) );
|
|
|
|
|
2023-02-27 21:08:05 +00:00
|
|
|
UpdateTraceStyle( trace );
|
2023-03-02 00:37:12 +00:00
|
|
|
m_traces[ getTraceId( aVectorName, aType ) ] = trace;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2023-02-27 21:08:05 +00:00
|
|
|
m_plotWin->AddLayer( (mpLayer*) trace );
|
|
|
|
}
|
2016-08-11 12:41:14 +00:00
|
|
|
|
2023-02-12 14:55:00 +00:00
|
|
|
return trace;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-13 15:03:40 +00:00
|
|
|
void SIM_PLOT_TAB::SetTraceData( TRACE* trace, std::vector<double>& aX, std::vector<double>& aY )
|
2023-02-12 14:55:00 +00:00
|
|
|
{
|
2023-07-12 09:40:02 +00:00
|
|
|
if( dynamic_cast<LOG_SCALE<mpScaleXLog>*>( m_axis_x ) )
|
2023-07-05 17:25:52 +00:00
|
|
|
{
|
|
|
|
// log( 0 ) is not valid.
|
2023-07-13 15:03:40 +00:00
|
|
|
if( aX.size() > 0 && aX[0] == 0 )
|
2023-07-05 17:25:52 +00:00
|
|
|
{
|
2023-07-13 15:03:40 +00:00
|
|
|
aX.erase( aX.begin() );
|
|
|
|
aY.erase( aY.begin() );
|
2023-07-05 17:25:52 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-11 12:41:50 +00:00
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
if( GetSimType() == ST_AC || GetSimType() == ST_FFT )
|
2016-08-11 12:41:50 +00:00
|
|
|
{
|
2023-02-12 14:55:00 +00:00
|
|
|
if( trace->GetType() & SPT_AC_PHASE )
|
2016-08-11 12:41:50 +00:00
|
|
|
{
|
2023-07-13 15:03:40 +00:00
|
|
|
for( double& pt : aY )
|
|
|
|
pt = pt * 180.0 / M_PI; // convert to degrees
|
2016-08-11 12:41:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-07-13 15:03:40 +00:00
|
|
|
for( double& pt : aY )
|
2021-07-09 20:20:23 +00:00
|
|
|
{
|
|
|
|
// log( 0 ) is not valid.
|
2023-07-13 15:03:40 +00:00
|
|
|
if( pt != 0 )
|
|
|
|
pt = 20 * log( pt ) / log( 10.0 ); // convert to dB
|
2021-07-09 20:20:23 +00:00
|
|
|
}
|
2016-08-11 12:41:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-13 15:03:40 +00:00
|
|
|
trace->SetData( aX, aY );
|
2016-08-11 12:41:50 +00:00
|
|
|
|
2023-02-12 14:55:00 +00:00
|
|
|
if( ( trace->GetType() & SPT_AC_PHASE ) || ( trace->GetType() & SPT_CURRENT ) )
|
2016-08-12 09:00:58 +00:00
|
|
|
trace->SetScale( m_axis_x, m_axis_y2 );
|
2023-02-12 14:55:00 +00:00
|
|
|
else if( trace->GetType() & SPT_POWER )
|
2023-02-10 20:52:52 +00:00
|
|
|
trace->SetScale( m_axis_x, m_axis_y3 );
|
2016-08-11 12:41:50 +00:00
|
|
|
else
|
2016-08-12 09:00:58 +00:00
|
|
|
trace->SetScale( m_axis_x, m_axis_y1 );
|
2016-08-11 12:41:50 +00:00
|
|
|
|
2023-02-12 19:54:28 +00:00
|
|
|
for( auto& [ cursorId, cursor ] : trace->GetCursors() )
|
|
|
|
{
|
|
|
|
if( cursor )
|
|
|
|
cursor->SetCoordX( cursor->GetCoords().x );
|
|
|
|
}
|
2016-08-11 12:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
void SIM_PLOT_TAB::DeleteTrace( TRACE* aTrace )
|
2016-08-11 12:41:24 +00:00
|
|
|
{
|
2023-02-27 21:08:05 +00:00
|
|
|
for( const auto& [ name, trace ] : m_traces )
|
2016-08-11 12:41:24 +00:00
|
|
|
{
|
2023-02-27 21:08:05 +00:00
|
|
|
if( trace == aTrace )
|
2023-01-29 16:01:03 +00:00
|
|
|
{
|
2023-02-27 21:08:05 +00:00
|
|
|
m_traces.erase( name );
|
|
|
|
break;
|
2023-01-29 16:01:03 +00:00
|
|
|
}
|
2023-02-27 21:08:05 +00:00
|
|
|
}
|
2016-08-11 12:41:25 +00:00
|
|
|
|
2023-02-27 21:08:05 +00:00
|
|
|
for( const auto& [ id, cursor ] : aTrace->GetCursors() )
|
|
|
|
{
|
|
|
|
if( cursor )
|
|
|
|
m_plotWin->DelLayer( cursor, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_plotWin->DelLayer( aTrace, true, true );
|
2023-06-18 15:23:38 +00:00
|
|
|
ResetScales( false );
|
2023-02-27 21:08:05 +00:00
|
|
|
}
|
2016-08-11 12:42:03 +00:00
|
|
|
|
2023-02-27 21:08:05 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
bool SIM_PLOT_TAB::DeleteTrace( const wxString& aVectorName, int aTraceType )
|
2023-02-27 21:08:05 +00:00
|
|
|
{
|
|
|
|
if( TRACE* trace = GetTrace( aVectorName, aTraceType ) )
|
|
|
|
{
|
|
|
|
DeleteTrace( trace );
|
2016-08-11 12:41:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2016-08-11 12:41:01 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:07 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
void SIM_PLOT_TAB::EnableCursor( const wxString& aVectorName, int aType, int aCursorId,
|
|
|
|
bool aEnable, const wxString& aSignalName )
|
2016-08-11 12:41:25 +00:00
|
|
|
{
|
2023-02-27 21:08:05 +00:00
|
|
|
TRACE* t = GetTrace( aVectorName, aType );
|
2016-08-11 12:41:25 +00:00
|
|
|
|
2023-01-29 16:01:03 +00:00
|
|
|
if( t == nullptr || t->HasCursor( aCursorId ) == aEnable )
|
2016-08-11 12:41:25 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if( aEnable )
|
|
|
|
{
|
2023-01-29 16:01:03 +00:00
|
|
|
CURSOR* cursor = new CURSOR( t, this );
|
|
|
|
mpWindow* win = GetPlotWin();
|
|
|
|
int width = win->GetXScreen() - win->GetMarginLeft() - win->GetMarginRight();
|
|
|
|
int center = win->GetMarginLeft() + KiROUND( width * ( aCursorId == 1 ? 0.4 : 0.6 ) );
|
|
|
|
|
2023-02-26 17:09:56 +00:00
|
|
|
cursor->SetName( aSignalName );
|
2023-01-29 16:01:03 +00:00
|
|
|
cursor->SetX( center );
|
|
|
|
|
|
|
|
t->SetCursor( aCursorId, cursor );
|
|
|
|
m_plotWin->AddLayer( cursor );
|
2016-08-11 12:41:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-01-29 16:01:03 +00:00
|
|
|
CURSOR* cursor = t->GetCursor( aCursorId );
|
|
|
|
t->SetCursor( aCursorId, nullptr );
|
|
|
|
m_plotWin->DelLayer( cursor, true );
|
2016-08-11 12:41:25 +00:00
|
|
|
}
|
2016-08-11 12:41:27 +00:00
|
|
|
|
|
|
|
// Notify the parent window about the changes
|
|
|
|
wxQueueEvent( GetParent(), new wxCommandEvent( EVT_SIM_CURSOR_UPDATE ) );
|
2016-08-11 12:41:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
void SIM_PLOT_TAB::ResetScales( bool aIncludeX )
|
2016-08-11 12:42:04 +00:00
|
|
|
{
|
2023-06-18 15:23:38 +00:00
|
|
|
if( m_axis_x && aIncludeX )
|
2023-09-20 16:23:08 +00:00
|
|
|
{
|
2016-08-11 12:42:04 +00:00
|
|
|
m_axis_x->ResetDataRange();
|
|
|
|
|
2023-09-20 16:23:08 +00:00
|
|
|
if( GetSimType() == ST_TRAN )
|
|
|
|
{
|
|
|
|
wxStringTokenizer tokenizer( GetSimCommand(), wxS( " \t\n\r" ), wxTOKEN_STRTOK );
|
|
|
|
wxString cmd = tokenizer.GetNextToken().Lower();
|
|
|
|
|
|
|
|
wxASSERT( cmd == wxS( ".tran" ) );
|
|
|
|
|
|
|
|
SPICE_VALUE step;
|
|
|
|
SPICE_VALUE end( 1.0 );
|
|
|
|
SPICE_VALUE start( 0.0 );
|
|
|
|
|
|
|
|
if( tokenizer.HasMoreTokens() )
|
|
|
|
step = SPICE_VALUE( tokenizer.GetNextToken() );
|
|
|
|
|
|
|
|
if( tokenizer.HasMoreTokens() )
|
|
|
|
end = SPICE_VALUE( tokenizer.GetNextToken() );
|
|
|
|
|
|
|
|
if( tokenizer.HasMoreTokens() )
|
|
|
|
start = SPICE_VALUE( tokenizer.GetNextToken() );
|
|
|
|
|
|
|
|
static_cast<TIME_SCALE*>( m_axis_x )->SetStartAndEnd( start.ToDouble(), end.ToDouble() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:42:04 +00:00
|
|
|
if( m_axis_y1 )
|
|
|
|
m_axis_y1->ResetDataRange();
|
|
|
|
|
|
|
|
if( m_axis_y2 )
|
|
|
|
m_axis_y2->ResetDataRange();
|
|
|
|
|
2023-02-10 20:52:52 +00:00
|
|
|
if( m_axis_y3 )
|
|
|
|
m_axis_y3->ResetDataRange();
|
|
|
|
|
2022-12-11 20:10:09 +00:00
|
|
|
for( auto& [ name, trace ] : m_traces )
|
|
|
|
trace->UpdateScales();
|
2016-08-11 12:42:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:41:27 +00:00
|
|
|
wxDEFINE_EVENT( EVT_SIM_CURSOR_UPDATE, wxCommandEvent );
|