2016-08-11 12:41:21 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: mathplot.cpp
|
|
|
|
// Purpose: Framework for plotting in wxWindows
|
|
|
|
// Original Author: David Schalig
|
|
|
|
// Maintainer: Davide Rondini
|
2016-08-11 12:42:18 +00:00
|
|
|
// Contributors: Jose Luis Blanco, Val Greene, Maciej Suminski, Tomasz Wlostowski
|
2016-08-11 12:41:21 +00:00
|
|
|
// Created: 21/07/2003
|
2024-01-23 01:02:50 +00:00
|
|
|
// Last edit: 2024
|
2016-08-11 12:41:21 +00:00
|
|
|
// Copyright: (c) David Schalig, Davide Rondini
|
2024-01-23 01:02:50 +00:00
|
|
|
// Copyright (c) 2021-2024 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-08-11 12:41:21 +00:00
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include <wx/window.h>
|
|
|
|
|
|
|
|
// Comment out for release operation:
|
|
|
|
// (Added by J.L.Blanco, Aug 2007)
|
2016-08-12 08:10:33 +00:00
|
|
|
//#define MATHPLOT_DO_LOGGING
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/object.h"
|
|
|
|
#include "wx/font.h"
|
|
|
|
#include "wx/colour.h"
|
|
|
|
#include "wx/sizer.h"
|
|
|
|
#include "wx/intl.h"
|
|
|
|
#include "wx/dcclient.h"
|
|
|
|
#include "wx/cursor.h"
|
2023-01-31 17:29:46 +00:00
|
|
|
#include "gal/cursors.h"
|
2016-08-11 12:41:21 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <widgets/mathplot.h>
|
2022-12-21 20:02:35 +00:00
|
|
|
#include <wx/graphics.h>
|
2016-08-11 12:41:21 +00:00
|
|
|
#include <wx/image.h>
|
|
|
|
|
|
|
|
#include <cmath>
|
2016-08-12 08:10:33 +00:00
|
|
|
#include <cstdio> // used only for debug
|
|
|
|
#include <ctime> // used for representation of x axes involving date
|
2018-10-04 20:45:22 +00:00
|
|
|
#include <set>
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// Memory leak debugging
|
|
|
|
#ifdef _DEBUG
|
|
|
|
#define new DEBUG_NEW
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Legend margins
|
2016-08-12 08:10:33 +00:00
|
|
|
#define mpLEGEND_MARGIN 5
|
|
|
|
#define mpLEGEND_LINEWIDTH 10
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// See doxygen comments.
|
2019-11-19 14:58:32 +00:00
|
|
|
double mpWindow::zoomIncrementalFactor = 1.1;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2016-08-11 12:41:21 +00:00
|
|
|
// mpLayer
|
2016-08-12 08:10:33 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
IMPLEMENT_ABSTRACT_CLASS( mpLayer, wxObject )
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2023-03-19 22:01:47 +00:00
|
|
|
mpLayer::mpLayer() :
|
|
|
|
m_type( mpLAYER_UNDEF )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
SetPen( (wxPen&) *wxBLACK_PEN );
|
|
|
|
SetFont( (wxFont&) *wxNORMAL_FONT );
|
2016-11-28 14:37:00 +00:00
|
|
|
m_continuous = false; // Default
|
|
|
|
m_showName = true; // Default
|
2016-08-11 12:41:21 +00:00
|
|
|
m_visible = true;
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2016-08-11 12:41:21 +00:00
|
|
|
// mpInfoLayer
|
2016-08-12 08:10:33 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS( mpInfoLayer, mpLayer )
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
mpInfoLayer::mpInfoLayer()
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
m_dim = wxRect( 0, 0, 1, 1 );
|
2016-08-11 12:41:21 +00:00
|
|
|
m_brush = *wxTRANSPARENT_BRUSH;
|
|
|
|
m_reference.x = 0; m_reference.y = 0;
|
2016-08-12 08:10:33 +00:00
|
|
|
m_winX = 1; // parent->GetScrX();
|
|
|
|
m_winY = 1; // parent->GetScrY();
|
|
|
|
m_type = mpLAYER_INFO;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2023-01-31 17:29:46 +00:00
|
|
|
mpInfoLayer::mpInfoLayer( wxRect rect, const wxBrush* brush ) :
|
|
|
|
m_dim( rect )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
m_brush = *brush;
|
2016-08-12 08:10:33 +00:00
|
|
|
m_reference.x = rect.x;
|
|
|
|
m_reference.y = rect.y;
|
|
|
|
m_winX = 1; // parent->GetScrX();
|
|
|
|
m_winY = 1; // parent->GetScrY();
|
|
|
|
m_type = mpLAYER_INFO;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
mpInfoLayer::~mpInfoLayer()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-31 17:29:46 +00:00
|
|
|
bool mpInfoLayer::Inside( const wxPoint& point ) const
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
return m_dim.Contains( point );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpInfoLayer::Move( wxPoint delta )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
m_dim.SetX( m_reference.x + delta.x );
|
|
|
|
m_dim.SetY( m_reference.y + delta.y );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
void mpInfoLayer::UpdateReference()
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
m_reference.x = m_dim.x;
|
|
|
|
m_reference.y = m_dim.y;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
void mpInfoLayer::Plot( wxDC& dc, mpWindow& w )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_visible )
|
|
|
|
{
|
2016-08-11 12:41:21 +00:00
|
|
|
// Adjust relative position inside the window
|
2016-08-12 08:10:33 +00:00
|
|
|
int scrx = w.GetScrX();
|
|
|
|
int scry = w.GetScrY();
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// Avoid dividing by 0
|
2016-08-12 08:10:33 +00:00
|
|
|
if( scrx == 0 )
|
|
|
|
scrx = 1;
|
|
|
|
|
|
|
|
if( scry == 0 )
|
|
|
|
scry = 1;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( (m_winX != scrx) || (m_winY != scry) )
|
|
|
|
{
|
|
|
|
if( m_winX > 1 )
|
|
|
|
m_dim.x = (int) floor( (double) (m_dim.x * scrx / m_winX) );
|
|
|
|
|
|
|
|
if( m_winY > 1 )
|
|
|
|
{
|
|
|
|
m_dim.y = (int) floor( (double) (m_dim.y * scry / m_winY) );
|
2016-08-11 12:41:21 +00:00
|
|
|
UpdateReference();
|
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// Finally update window size
|
2016-08-12 08:10:33 +00:00
|
|
|
m_winX = scrx;
|
|
|
|
m_winY = scry;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
dc.SetPen( m_pen );
|
|
|
|
dc.SetBrush( m_brush );
|
|
|
|
dc.DrawRectangle( m_dim.x, m_dim.y, m_dim.width, m_dim.height );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
wxPoint mpInfoLayer::GetPosition() const
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
return m_dim.GetPosition();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
wxSize mpInfoLayer::GetSize() const
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
return m_dim.GetSize();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2023-03-19 22:01:47 +00:00
|
|
|
mpInfoLegend::mpInfoLegend() :
|
|
|
|
mpInfoLayer()
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-19 22:01:47 +00:00
|
|
|
mpInfoLegend::mpInfoLegend( wxRect rect, const wxBrush* brush ) :
|
|
|
|
mpInfoLayer( rect, brush )
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
mpInfoLegend::~mpInfoLegend()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
void mpInfoLegend::Plot( wxDC& dc, mpWindow& w )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_visible )
|
|
|
|
{
|
2016-08-11 12:41:21 +00:00
|
|
|
// Adjust relative position inside the window
|
2016-08-12 08:10:33 +00:00
|
|
|
int scrx = w.GetScrX();
|
|
|
|
int scry = w.GetScrY();
|
|
|
|
|
2023-03-19 22:01:47 +00:00
|
|
|
if( m_winX != scrx || m_winY != scry )
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
|
|
|
if( m_winX > 1 )
|
|
|
|
m_dim.x = (int) floor( (double) (m_dim.x * scrx / m_winX) );
|
|
|
|
|
|
|
|
if( m_winY > 1 )
|
|
|
|
{
|
|
|
|
m_dim.y = (int) floor( (double) (m_dim.y * scry / m_winY) );
|
2016-08-11 12:41:21 +00:00
|
|
|
UpdateReference();
|
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// Finally update window size
|
2016-08-12 08:10:33 +00:00
|
|
|
m_winX = scrx;
|
|
|
|
m_winY = scry;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
dc.SetBrush( m_brush );
|
|
|
|
dc.SetFont( m_font );
|
2023-03-19 22:01:47 +00:00
|
|
|
|
|
|
|
const int baseWidth = mpLEGEND_MARGIN * 2 + mpLEGEND_LINEWIDTH;
|
|
|
|
int textX = baseWidth, textY = mpLEGEND_MARGIN;
|
|
|
|
int plotCount = 0;
|
|
|
|
int posY = 0;
|
|
|
|
int tmpX = 0;
|
|
|
|
int tmpY = 0;
|
|
|
|
mpLayer* layer = nullptr;
|
|
|
|
wxPen lpen;
|
|
|
|
wxString label;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
for( unsigned int p = 0; p < w.CountAllLayers(); p++ )
|
|
|
|
{
|
2023-03-19 22:01:47 +00:00
|
|
|
layer = w.GetLayer( p );
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2023-03-19 22:01:47 +00:00
|
|
|
if( layer->GetLayerType() == mpLAYER_PLOT && layer->IsVisible() )
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
2023-03-19 23:02:23 +00:00
|
|
|
label = layer->GetDisplayName();
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.GetTextExtent( label, &tmpX, &tmpY );
|
2023-03-19 22:01:47 +00:00
|
|
|
textX = ( textX > tmpX + baseWidth ) ? textX : tmpX + baseWidth + mpLEGEND_MARGIN;
|
|
|
|
textY += tmpY;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
dc.SetPen( m_pen );
|
|
|
|
dc.SetBrush( m_brush );
|
2016-08-11 12:41:21 +00:00
|
|
|
m_dim.width = textX;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
if( textY != mpLEGEND_MARGIN ) // Don't draw any thing if there are no visible layers
|
|
|
|
{
|
2016-08-11 12:41:21 +00:00
|
|
|
textY += mpLEGEND_MARGIN;
|
|
|
|
m_dim.height = textY;
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.DrawRectangle( m_dim.x, m_dim.y, m_dim.width, m_dim.height );
|
|
|
|
|
|
|
|
for( unsigned int p2 = 0; p2 < w.CountAllLayers(); p2++ )
|
|
|
|
{
|
2023-03-19 22:01:47 +00:00
|
|
|
layer = w.GetLayer( p2 );
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2023-03-19 22:01:47 +00:00
|
|
|
if( layer->GetLayerType() == mpLAYER_PLOT && layer->IsVisible() )
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
2023-03-19 23:02:23 +00:00
|
|
|
label = layer->GetDisplayName();
|
2023-03-19 22:01:47 +00:00
|
|
|
lpen = layer->GetPen();
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.GetTextExtent( label, &tmpX, &tmpY );
|
|
|
|
dc.SetPen( lpen );
|
|
|
|
posY = m_dim.y + mpLEGEND_MARGIN + plotCount * tmpY + (tmpY >> 1);
|
2023-03-19 22:01:47 +00:00
|
|
|
dc.DrawLine( m_dim.x + mpLEGEND_MARGIN, // X start coord
|
|
|
|
posY, // Y start coord
|
|
|
|
m_dim.x + mpLEGEND_LINEWIDTH + mpLEGEND_MARGIN, // X end coord
|
|
|
|
posY );
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.DrawText( label,
|
2023-03-19 22:01:47 +00:00
|
|
|
m_dim.x + baseWidth,
|
|
|
|
m_dim.y + mpLEGEND_MARGIN + plotCount * tmpY );
|
2016-08-11 12:41:21 +00:00
|
|
|
plotCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2016-08-11 12:41:21 +00:00
|
|
|
// mpLayer implementations - functions
|
2016-08-12 08:10:33 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
IMPLEMENT_ABSTRACT_CLASS( mpFX, mpLayer )
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2017-09-23 09:20:10 +00:00
|
|
|
mpFX::mpFX( const wxString& name, int flags )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
SetName( name );
|
2016-08-11 12:41:21 +00:00
|
|
|
m_flags = flags;
|
2016-08-12 08:10:33 +00:00
|
|
|
m_type = mpLAYER_PLOT;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpFX::Plot( wxDC& dc, mpWindow& w )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_visible )
|
|
|
|
{
|
|
|
|
dc.SetPen( m_pen );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2023-07-18 10:56:36 +00:00
|
|
|
wxCoord startPx = w.GetMarginLeft();
|
|
|
|
wxCoord endPx = w.GetScrX() - w.GetMarginRight();
|
|
|
|
wxCoord minYpx = w.GetMarginTop();
|
|
|
|
wxCoord maxYpx = w.GetScrY() - w.GetMarginBottom();
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
wxCoord iy = 0;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
if( m_pen.GetWidth() <= 1 )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
for( wxCoord i = startPx; i < endPx; ++i )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
iy = w.y2p( GetY( w.p2x( i ) ) );
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// Draw the point only if you can draw outside margins or if the point is inside margins
|
2023-07-18 10:56:36 +00:00
|
|
|
if( (iy >= minYpx) && (iy <= maxYpx) )
|
|
|
|
dc.DrawPoint( i, iy );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
for( wxCoord i = startPx; i < endPx; ++i )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
iy = w.y2p( GetY( w.p2x( i ) ) );
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// Draw the point only if you can draw outside margins or if the point is inside margins
|
2023-08-02 15:26:17 +00:00
|
|
|
if( iy >= minYpx && iy <= maxYpx )
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.DrawLine( i, iy, i, iy );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( !m_name.IsEmpty() && m_showName )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.SetFont( m_font );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
wxCoord tx, ty;
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.GetTextExtent( m_name, &tx, &ty );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( (m_flags & mpALIGNMASK) == mpALIGN_RIGHT )
|
2016-08-11 12:41:21 +00:00
|
|
|
tx = (w.GetScrX() - tx) - w.GetMarginRight() - 8;
|
2016-08-12 08:10:33 +00:00
|
|
|
else if( (m_flags & mpALIGNMASK) == mpALIGN_CENTER )
|
2023-08-02 15:26:17 +00:00
|
|
|
tx = ( (w.GetScrX() - w.GetMarginRight() - w.GetMarginLeft() - tx) / 2 ) + w.GetMarginLeft();
|
2016-08-11 12:41:21 +00:00
|
|
|
else
|
|
|
|
tx = w.GetMarginLeft() + 8;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
dc.DrawText( m_name, tx, w.y2p( GetY( w.p2x( tx ) ) ) );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
IMPLEMENT_ABSTRACT_CLASS( mpFY, mpLayer )
|
|
|
|
|
2017-09-23 09:20:10 +00:00
|
|
|
mpFY::mpFY( const wxString& name, int flags )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
SetName( name );
|
2016-08-11 12:41:21 +00:00
|
|
|
m_flags = flags;
|
2016-08-12 08:10:33 +00:00
|
|
|
m_type = mpLAYER_PLOT;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpFY::Plot( wxDC& dc, mpWindow& w )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_visible )
|
|
|
|
{
|
|
|
|
dc.SetPen( m_pen );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
wxCoord i, ix;
|
|
|
|
|
2023-07-18 10:56:36 +00:00
|
|
|
wxCoord startPx = w.GetMarginLeft();
|
|
|
|
wxCoord endPx = w.GetScrX() - w.GetMarginRight();
|
|
|
|
wxCoord minYpx = w.GetMarginTop();
|
|
|
|
wxCoord maxYpx = w.GetScrY() - w.GetMarginBottom();
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_pen.GetWidth() <= 1 )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
for( i = minYpx; i < maxYpx; ++i )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
ix = w.x2p( GetX( w.p2y( i ) ) );
|
|
|
|
|
2023-07-18 10:56:36 +00:00
|
|
|
if( (ix >= startPx) && (ix <= endPx) )
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.DrawPoint( ix, i );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
for( i = 0; i< w.GetScrY(); ++i )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
ix = w.x2p( GetX( w.p2y( i ) ) );
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2023-07-18 10:56:36 +00:00
|
|
|
if( (ix >= startPx) && (ix <= endPx) )
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.DrawLine( ix, i, ix, i );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( !m_name.IsEmpty() && m_showName )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.SetFont( m_font );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
wxCoord tx, ty;
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.GetTextExtent( m_name, &tx, &ty );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( (m_flags & mpALIGNMASK) == mpALIGN_TOP )
|
2016-08-11 12:41:21 +00:00
|
|
|
ty = w.GetMarginTop() + 8;
|
2016-08-12 08:10:33 +00:00
|
|
|
else if( (m_flags & mpALIGNMASK) == mpALIGN_CENTER )
|
2023-08-02 15:26:17 +00:00
|
|
|
ty = ( ( w.GetScrY() - w.GetMarginTop() - w.GetMarginBottom() - ty) / 2 ) + w.GetMarginTop();
|
2016-08-11 12:41:21 +00:00
|
|
|
else
|
|
|
|
ty = w.GetScrY() - 8 - ty - w.GetMarginBottom();
|
|
|
|
|
2023-07-18 10:56:36 +00:00
|
|
|
dc.DrawText( m_name, w.x2p( GetX( w.p2y( ty ) ) ), ty );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
IMPLEMENT_ABSTRACT_CLASS( mpFXY, mpLayer )
|
|
|
|
|
2017-09-23 09:20:10 +00:00
|
|
|
mpFXY::mpFXY( const wxString& name, int flags )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
SetName( name );
|
|
|
|
m_flags = flags;
|
|
|
|
m_type = mpLAYER_PLOT;
|
2023-02-19 05:38:42 +00:00
|
|
|
m_scaleX = nullptr;
|
|
|
|
m_scaleY = nullptr;
|
2016-12-30 13:36:23 +00:00
|
|
|
|
|
|
|
// Avoid not initialized members:
|
|
|
|
maxDrawX = minDrawX = maxDrawY = minDrawY = 0;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpFXY::UpdateViewBoundary( wxCoord xnew, wxCoord ynew )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2019-08-20 17:22:30 +00:00
|
|
|
// Keep track of how many points have been drawn and the bounding box
|
2016-08-12 08:10:33 +00:00
|
|
|
maxDrawX = (xnew > maxDrawX) ? xnew : maxDrawX;
|
|
|
|
minDrawX = (xnew < minDrawX) ? xnew : minDrawX;
|
|
|
|
maxDrawY = (maxDrawY > ynew) ? maxDrawY : ynew;
|
|
|
|
minDrawY = (minDrawY < ynew) ? minDrawY : ynew;
|
|
|
|
// drawnPoints++;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpFXY::Plot( wxDC& dc, mpWindow& w )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2023-02-25 11:38:27 +00:00
|
|
|
// If trace doesn't have any data yet then it won't have any scale set. In any case, there's
|
|
|
|
// nothing to plot.
|
|
|
|
if( !GetCount() )
|
|
|
|
return;
|
|
|
|
|
2023-02-19 05:38:42 +00:00
|
|
|
wxCHECK_RET( m_scaleX, wxS( "X scale was not set" ) );
|
|
|
|
wxCHECK_RET( m_scaleY, wxS( "Y scale was not set" ) );
|
|
|
|
|
2023-02-26 21:50:43 +00:00
|
|
|
if( !m_visible )
|
|
|
|
return;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2023-07-18 10:56:36 +00:00
|
|
|
wxCoord startPx = w.GetMarginLeft();
|
|
|
|
wxCoord endPx = w.GetScrX() - w.GetMarginRight();
|
|
|
|
wxCoord minYpx = w.GetMarginTop();
|
|
|
|
wxCoord maxYpx = w.GetScrY() - w.GetMarginBottom();
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2023-02-26 21:50:43 +00:00
|
|
|
// Check for a collapsed window before we try to allocate a negative number of points
|
|
|
|
if( endPx <= startPx || minYpx >= maxYpx )
|
|
|
|
return;
|
|
|
|
|
|
|
|
dc.SetPen( m_pen );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2023-02-26 21:50:43 +00:00
|
|
|
double x, y;
|
|
|
|
// Do this to reset the counters to evaluate bounding box for label positioning
|
|
|
|
Rewind();
|
|
|
|
GetNextXY( x, y );
|
|
|
|
maxDrawX = x;
|
|
|
|
minDrawX = x;
|
|
|
|
maxDrawY = y;
|
|
|
|
minDrawY = y;
|
|
|
|
// drawnPoints = 0;
|
|
|
|
Rewind();
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2023-02-26 21:50:43 +00:00
|
|
|
dc.SetClippingRegion( startPx, minYpx, endPx - startPx + 1, maxYpx - minYpx + 1 );
|
|
|
|
|
|
|
|
if( !m_continuous )
|
|
|
|
{
|
|
|
|
bool first = true;
|
|
|
|
wxCoord ix = 0;
|
|
|
|
std::set<wxCoord> ys;
|
|
|
|
|
|
|
|
while( GetNextXY( x, y ) )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2023-02-26 21:50:43 +00:00
|
|
|
double px = m_scaleX->TransformToPlot( x );
|
|
|
|
double py = m_scaleY->TransformToPlot( y );
|
|
|
|
wxCoord newX = w.x2p( px );
|
2018-10-04 20:33:32 +00:00
|
|
|
|
2023-02-26 21:50:43 +00:00
|
|
|
if( first )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2023-02-26 21:50:43 +00:00
|
|
|
ix = newX;
|
|
|
|
first = false;
|
|
|
|
}
|
2018-10-04 20:33:32 +00:00
|
|
|
|
2023-02-26 21:50:43 +00:00
|
|
|
if( newX == ix ) // continue until a new X coordinate is reached
|
|
|
|
{
|
|
|
|
// collect all unique points
|
|
|
|
ys.insert( w.y2p( py ) );
|
|
|
|
continue;
|
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2023-02-26 21:50:43 +00:00
|
|
|
for( auto& iy: ys )
|
|
|
|
{
|
2023-07-18 10:56:36 +00:00
|
|
|
if( (ix >= startPx) && (ix <= endPx) && (iy >= minYpx) && (iy <= maxYpx) )
|
2018-10-04 20:45:22 +00:00
|
|
|
{
|
2023-02-26 21:50:43 +00:00
|
|
|
// for some reason DrawPoint does not use the current pen, so we use
|
|
|
|
// DrawLine for fat pens
|
|
|
|
if( m_pen.GetWidth() <= 1 )
|
|
|
|
dc.DrawPoint( ix, iy );
|
|
|
|
else
|
|
|
|
dc.DrawLine( ix, iy, ix, iy );
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2023-02-26 21:50:43 +00:00
|
|
|
UpdateViewBoundary( ix, iy );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
2023-02-26 21:50:43 +00:00
|
|
|
|
|
|
|
ys.clear();
|
|
|
|
ix = newX;
|
|
|
|
ys.insert( w.y2p( py ) );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2023-02-26 21:50:43 +00:00
|
|
|
}
|
2024-05-23 11:24:13 +00:00
|
|
|
else for( int sweep = 0; sweep < GetSweepCount(); ++sweep )
|
2023-02-26 21:50:43 +00:00
|
|
|
{
|
2024-05-23 11:24:13 +00:00
|
|
|
SetSweepWindow( sweep );
|
|
|
|
|
2023-07-17 21:28:05 +00:00
|
|
|
int count = 0;
|
|
|
|
int x0 = 0; // X position of merged current vertical line
|
|
|
|
int ymin0 = 0; // y min coord of merged current vertical line
|
|
|
|
int ymax0 = 0; // y max coord of merged current vertical line
|
|
|
|
int dupx0 = 0; // count of currently merged vertical lines
|
2023-02-26 21:50:43 +00:00
|
|
|
wxPoint line_start; // starting point of the current line to draw
|
|
|
|
|
|
|
|
// A buffer to store coordinates of lines to draw
|
|
|
|
std::vector<wxPoint>pointList;
|
2023-10-21 15:33:28 +00:00
|
|
|
pointList.reserve( ( endPx - startPx ) * 2 );
|
|
|
|
|
|
|
|
double nextX;
|
|
|
|
double nextY;
|
|
|
|
bool hasNext = GetNextXY( nextX, nextY );
|
|
|
|
bool offRight = false;
|
2023-02-26 21:50:43 +00:00
|
|
|
|
2023-10-23 11:57:46 +00:00
|
|
|
// Note: we can use dc.DrawLines() only for a reasonable number or points (<10,000),
|
|
|
|
// because at least on Windows dc.DrawLines() can hang for a lot of points. Note that
|
|
|
|
// this includes the intermediate points when drawing dotted lines.
|
|
|
|
|
|
|
|
// Our first-pass optimization is to exclude points outside the view, and aggregate all
|
|
|
|
// contiguous y values found at a single x value into a vertical line.
|
2023-10-21 15:33:28 +00:00
|
|
|
while( hasNext )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2023-10-21 15:33:28 +00:00
|
|
|
x = nextX;
|
|
|
|
y = nextY;
|
|
|
|
hasNext = GetNextXY( nextX, nextY );
|
|
|
|
|
2023-02-26 21:50:43 +00:00
|
|
|
double px = m_scaleX->TransformToPlot( x );
|
|
|
|
double py = m_scaleY->TransformToPlot( y );
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2023-02-26 21:50:43 +00:00
|
|
|
wxCoord x1 = w.x2p( px );
|
|
|
|
wxCoord y1 = w.y2p( py );
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2023-10-23 11:57:46 +00:00
|
|
|
// Note that we can't start *right* at the edge of the view because we need to
|
|
|
|
// interpolate between two points, one of which might be outside the view.
|
2023-02-26 21:50:43 +00:00
|
|
|
// Note: x1 is a value truncated from px by w.x2p(). So to be sure the first point
|
|
|
|
// is drawn, the x1 low limit is startPx-1 in plot coordinates
|
2023-10-21 15:33:28 +00:00
|
|
|
if( x1 < startPx-1 )
|
|
|
|
{
|
|
|
|
wxCoord nextX1 = w.x2p( m_scaleX->TransformToPlot( nextX ) );
|
|
|
|
|
|
|
|
if( nextX1 < startPx-1 )
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if( x1 > endPx )
|
|
|
|
{
|
|
|
|
if( offRight )
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
offRight = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !count || line_start.x != x1 )
|
2023-02-26 21:50:43 +00:00
|
|
|
{
|
2023-10-23 11:57:46 +00:00
|
|
|
// We've aggregated a bunch of y values with a shared x value, so we need to draw
|
|
|
|
// a vertical line. However, short vertical segments spoil anti-aliasing on
|
|
|
|
// Retina displays, so only draw them if they're "significant" (the user should
|
|
|
|
// zoom in if they need a more accurate picture).
|
|
|
|
if( count && dupx0 > 1 && abs( ymax0 - ymin0 ) > 2 )
|
2023-10-21 15:33:28 +00:00
|
|
|
dc.DrawLine( x0, ymin0, x0, ymax0 );
|
2020-08-24 16:40:38 +00:00
|
|
|
|
2023-10-21 15:33:28 +00:00
|
|
|
x0 = x1;
|
|
|
|
ymin0 = ymax0 = y1;
|
|
|
|
dupx0 = 0;
|
2020-08-24 16:40:38 +00:00
|
|
|
|
2023-10-21 15:33:28 +00:00
|
|
|
pointList.emplace_back( wxPoint( x1, y1 ) );
|
2020-08-24 16:40:38 +00:00
|
|
|
|
2023-10-21 15:33:28 +00:00
|
|
|
line_start.x = x1;
|
|
|
|
line_start.y = y1;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ymin0 = std::min( ymin0, y1 );
|
|
|
|
ymax0 = std::max( ymax0, y1 );
|
|
|
|
x0 = x1;
|
|
|
|
dupx0++;
|
2020-08-24 16:40:38 +00:00
|
|
|
}
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2023-02-26 21:50:43 +00:00
|
|
|
if( pointList.size() > 1 )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2023-10-23 11:57:46 +00:00
|
|
|
// Second pass optimization is to merge horizontal segments. This improves the look
|
|
|
|
// of dotted lines, keeps the point count down, and it's easy.
|
|
|
|
//
|
|
|
|
// This pass also includes a final protection to keep MSW from hanging by chunking to
|
|
|
|
// a size it can handle.
|
2023-02-26 21:50:43 +00:00
|
|
|
std::vector<wxPoint> drawPoints;
|
2023-10-23 11:57:46 +00:00
|
|
|
drawPoints.reserve( ( endPx - startPx ) * 2 );
|
|
|
|
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
int chunkSize = 10000;
|
|
|
|
#else
|
|
|
|
int chunkSize = 100000;
|
|
|
|
#endif
|
|
|
|
if( dc.GetPen().GetStyle() == wxPENSTYLE_DOT )
|
|
|
|
chunkSize /= 500;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2023-02-26 21:50:43 +00:00
|
|
|
drawPoints.push_back( pointList[0] ); // push the first point in list
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2023-02-26 21:50:43 +00:00
|
|
|
for( size_t ii = 1; ii < pointList.size()-1; ii++ )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2023-02-26 21:50:43 +00:00
|
|
|
// Skip intermediate points between the first point and the last point of the
|
|
|
|
// segment candidate
|
|
|
|
if( drawPoints.back().y == pointList[ii].y &&
|
|
|
|
drawPoints.back().y == pointList[ii+1].y )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2023-02-26 21:50:43 +00:00
|
|
|
continue;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
else
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
2023-02-26 21:50:43 +00:00
|
|
|
drawPoints.push_back( pointList[ii] );
|
2023-10-23 11:57:46 +00:00
|
|
|
|
|
|
|
if( (int) drawPoints.size() > chunkSize )
|
|
|
|
{
|
|
|
|
dc.DrawLines( (int) drawPoints.size(), &drawPoints[0] );
|
|
|
|
drawPoints.clear();
|
|
|
|
|
|
|
|
// Restart the line with the current point
|
|
|
|
drawPoints.push_back( pointList[ii] );
|
|
|
|
}
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-26 21:50:43 +00:00
|
|
|
// push the last point to draw in list
|
|
|
|
if( drawPoints.back() != pointList.back() )
|
|
|
|
drawPoints.push_back( pointList.back() );
|
|
|
|
|
2023-10-23 11:57:46 +00:00
|
|
|
dc.DrawLines( (int) drawPoints.size(), &drawPoints[0] );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2023-02-26 21:50:43 +00:00
|
|
|
if( !m_name.IsEmpty() && m_showName )
|
|
|
|
{
|
|
|
|
dc.SetFont( m_font );
|
|
|
|
|
|
|
|
wxCoord tx, ty;
|
|
|
|
dc.GetTextExtent( m_name, &tx, &ty );
|
|
|
|
|
2023-07-18 10:56:36 +00:00
|
|
|
if( (m_flags & mpALIGNMASK) == mpALIGN_NW )
|
2023-02-26 21:50:43 +00:00
|
|
|
{
|
2023-07-18 10:56:36 +00:00
|
|
|
tx = minDrawX + 8;
|
|
|
|
ty = maxDrawY + 8;
|
|
|
|
}
|
|
|
|
else if( (m_flags & mpALIGNMASK) == mpALIGN_NE )
|
|
|
|
{
|
|
|
|
tx = maxDrawX - tx - 8;
|
|
|
|
ty = maxDrawY + 8;
|
|
|
|
}
|
|
|
|
else if( (m_flags & mpALIGNMASK) == mpALIGN_SE )
|
|
|
|
{
|
|
|
|
tx = maxDrawX - tx - 8;
|
|
|
|
ty = minDrawY - ty - 8;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// mpALIGN_SW
|
|
|
|
tx = minDrawX + 8;
|
|
|
|
ty = minDrawY - ty - 8;
|
2023-02-26 21:50:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dc.DrawText( m_name, tx, ty );
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:49 +00:00
|
|
|
dc.DestroyClippingRegion();
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2016-08-11 12:41:21 +00:00
|
|
|
// mpLayer implementations - furniture (scales, ...)
|
2016-08-12 08:10:33 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
#define mpLN10 2.3025850929940456840179914546844
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
void mpScaleX::recalculateTicks( wxDC& dc, mpWindow& w )
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
2016-08-11 12:41:49 +00:00
|
|
|
double minV, maxV, minVvis, maxVvis;
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
GetDataRange( minV, maxV );
|
|
|
|
getVisibleDataRange( w, minVvis, maxVvis );
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
m_absVisibleMaxV = std::max( std::abs( minVvis ), std::abs( maxVvis ) );
|
|
|
|
|
2016-08-11 12:41:49 +00:00
|
|
|
m_tickValues.clear();
|
2016-08-11 12:42:04 +00:00
|
|
|
m_tickLabels.clear();
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double minErr = 1000000000000.0;
|
2016-08-15 08:53:36 +00:00
|
|
|
double bestStep = 1.0;
|
2023-08-31 22:50:14 +00:00
|
|
|
int m_scrX = w.GetXScreen();
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
for( int i = 10; i <= 20; i += 2 )
|
2016-08-11 12:42:18 +00:00
|
|
|
{
|
2016-08-29 09:39:54 +00:00
|
|
|
double curr_step = fabs( maxVvis - minVvis ) / (double) i;
|
|
|
|
double base = pow( 10, floor( log10( curr_step ) ) );
|
|
|
|
double stepInt = floor( curr_step / base ) * base;
|
|
|
|
double err = fabs( curr_step - stepInt );
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2016-08-15 08:53:36 +00:00
|
|
|
if( err < minErr )
|
2016-08-11 12:42:18 +00:00
|
|
|
{
|
|
|
|
minErr = err;
|
|
|
|
bestStep = stepInt;
|
2016-08-11 12:41:49 +00:00
|
|
|
}
|
2016-08-11 12:42:18 +00:00
|
|
|
}
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2023-08-31 22:50:14 +00:00
|
|
|
double numberSteps = floor( ( maxVvis - minVvis ) / bestStep );
|
2023-09-05 18:17:53 +00:00
|
|
|
|
2023-08-31 22:50:14 +00:00
|
|
|
// Half the number of ticks according to window size.
|
|
|
|
// The value 96 is used to have only 4 ticks when m_scrX is 268.
|
|
|
|
// For each 96 device context units, is possible to add a new tick.
|
2023-09-05 18:17:53 +00:00
|
|
|
while( numberSteps - 2.0 >= m_scrX/96.0 )
|
2023-08-31 22:50:14 +00:00
|
|
|
{
|
|
|
|
bestStep *= 2;
|
|
|
|
numberSteps = floor( ( maxVvis - minVvis ) / bestStep );
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double v = floor( minVvis / bestStep ) * bestStep;
|
2016-08-11 12:41:49 +00:00
|
|
|
double zeroOffset = 100000000.0;
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
while( v < maxVvis )
|
2016-08-11 12:41:49 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
m_tickValues.push_back( v );
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( fabs( v ) < zeroOffset )
|
|
|
|
zeroOffset = fabs( v );
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
v += bestStep;
|
2016-08-11 12:41:49 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( zeroOffset <= bestStep )
|
2016-08-11 12:41:49 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
for( double& t : m_tickValues )
|
2016-08-11 12:41:49 +00:00
|
|
|
t -= zeroOffset;
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
for( double t : m_tickValues )
|
2019-12-05 15:41:21 +00:00
|
|
|
m_tickLabels.emplace_back( t );
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2016-08-11 12:42:04 +00:00
|
|
|
updateTickLabels( dc, w );
|
2016-08-11 12:41:48 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 12:42:04 +00:00
|
|
|
|
2016-12-30 11:39:41 +00:00
|
|
|
mpScaleBase::mpScaleBase()
|
|
|
|
{
|
|
|
|
m_rangeSet = false;
|
2023-07-19 15:25:57 +00:00
|
|
|
m_axisLocked = false;
|
|
|
|
m_axisMin = 0;
|
|
|
|
m_axisMax = 0;
|
2016-12-30 11:39:41 +00:00
|
|
|
m_nameFlags = mpALIGN_BORDER_BOTTOM;
|
|
|
|
|
|
|
|
// initialize these members mainly to avoid not initialized values
|
|
|
|
m_offset = 0.0;
|
|
|
|
m_scale = 1.0;
|
|
|
|
m_absVisibleMaxV = 0.0;
|
|
|
|
m_flags = 0; // Flag for axis alignment
|
|
|
|
m_ticks = true; // Flag to toggle between ticks or grid
|
|
|
|
m_minV = 0.0;
|
|
|
|
m_maxV = 0.0;
|
|
|
|
m_maxLabelHeight = 1;
|
|
|
|
m_maxLabelWidth = 1;
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:42:04 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
void mpScaleBase::computeLabelExtents( wxDC& dc, mpWindow& w )
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
m_maxLabelHeight = 0;
|
|
|
|
m_maxLabelWidth = 0;
|
2016-08-11 12:42:04 +00:00
|
|
|
|
2023-08-02 15:26:17 +00:00
|
|
|
for( const TICK_LABEL& tickLabel : m_tickLabels )
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
2023-08-02 14:43:53 +00:00
|
|
|
int tx, ty;
|
|
|
|
const wxString s = tickLabel.label;
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.GetTextExtent( s, &tx, &ty );
|
2023-08-02 14:43:53 +00:00
|
|
|
m_maxLabelHeight = std::max( ty, m_maxLabelHeight );
|
|
|
|
m_maxLabelWidth = std::max( tx, m_maxLabelWidth );
|
2016-08-11 12:41:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:42:04 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
void mpScaleBase::updateTickLabels( wxDC& dc, mpWindow& w )
|
|
|
|
{
|
2016-08-11 12:42:10 +00:00
|
|
|
formatLabels();
|
2016-08-12 08:10:33 +00:00
|
|
|
computeLabelExtents( dc, w );
|
2016-08-11 12:42:04 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpScaleY::getVisibleDataRange( mpWindow& w, double& minV, double& maxV )
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
2023-07-18 10:56:36 +00:00
|
|
|
wxCoord minYpx = w.GetMarginTop();
|
|
|
|
wxCoord maxYpx = w.GetScrY() - w.GetMarginBottom();
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double pymin = w.p2y( minYpx );
|
|
|
|
double pymax = w.p2y( maxYpx );
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
minV = TransformFromPlot( pymax );
|
|
|
|
maxV = TransformFromPlot( pymin );
|
2016-08-11 12:41:48 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:48 +00:00
|
|
|
|
|
|
|
void mpScaleY::computeSlaveTicks( mpWindow& w )
|
|
|
|
{
|
2023-08-03 21:23:39 +00:00
|
|
|
// No need for slave ticks when there aren't 2 main ticks for them to go between
|
|
|
|
if( m_masterScale->m_tickValues.size() < 2 )
|
2016-08-11 12:42:18 +00:00
|
|
|
return;
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2016-08-11 12:42:18 +00:00
|
|
|
m_tickValues.clear();
|
|
|
|
m_tickLabels.clear();
|
2016-08-11 12:42:04 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double p0 = m_masterScale->TransformToPlot( m_masterScale->m_tickValues[0] );
|
|
|
|
double p1 = m_masterScale->TransformToPlot( m_masterScale->m_tickValues[1] );
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
m_scale = 1.0 / ( m_maxV - m_minV );
|
|
|
|
m_offset = -m_minV;
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double y_slave0 = p0 / m_scale;
|
|
|
|
double y_slave1 = p1 / m_scale;
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double dy_slave = (y_slave1 - y_slave0);
|
|
|
|
double exponent = floor( log10( dy_slave ) );
|
|
|
|
double base = dy_slave / pow( 10.0, exponent );
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double dy_scaled = ceil( 2.0 * base ) / 2.0 * pow( 10.0, exponent );
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-11 12:42:18 +00:00
|
|
|
double minvv, maxvv;
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
getVisibleDataRange( w, minvv, maxvv );
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
minvv = floor( minvv / dy_scaled ) * dy_scaled;
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-11 12:42:18 +00:00
|
|
|
m_scale = 1.0 / ( m_maxV - m_minV );
|
|
|
|
m_scale *= dy_slave / dy_scaled;
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-11 12:42:18 +00:00
|
|
|
m_offset = p0 / m_scale - minvv;
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-11 12:42:18 +00:00
|
|
|
m_tickValues.clear();
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-11 12:42:18 +00:00
|
|
|
m_absVisibleMaxV = 0;
|
2016-08-11 12:42:10 +00:00
|
|
|
|
2023-07-19 15:25:57 +00:00
|
|
|
for( double tickValue : m_masterScale->m_tickValues )
|
2016-08-11 12:42:18 +00:00
|
|
|
{
|
2023-07-19 15:25:57 +00:00
|
|
|
double m = TransformFromPlot( m_masterScale->TransformToPlot( tickValue ) );
|
2016-08-12 08:10:33 +00:00
|
|
|
m_tickValues.push_back( m );
|
2019-12-05 15:41:21 +00:00
|
|
|
m_tickLabels.emplace_back( m );
|
2016-08-12 08:10:33 +00:00
|
|
|
m_absVisibleMaxV = std::max( m_absVisibleMaxV, fabs( m ) );
|
2016-08-11 12:42:18 +00:00
|
|
|
}
|
2016-08-11 12:41:48 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
void mpScaleY::recalculateTicks( wxDC& dc, mpWindow& w )
|
|
|
|
{
|
2023-07-20 16:20:57 +00:00
|
|
|
double minVvis, maxVvis;
|
|
|
|
|
|
|
|
if( m_axisLocked )
|
|
|
|
{
|
|
|
|
minVvis = m_axisMin;
|
|
|
|
maxVvis = m_axisMax;
|
|
|
|
m_offset = -m_axisMin;
|
|
|
|
m_scale = 1.0 / ( m_axisMax - m_axisMin );
|
|
|
|
}
|
|
|
|
else if( m_masterScale )
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
|
|
|
computeSlaveTicks( w );
|
2016-08-12 08:10:33 +00:00
|
|
|
updateTickLabels( dc, w );
|
2016-08-11 12:42:04 +00:00
|
|
|
|
2016-08-11 12:41:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-07-20 16:20:57 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
getVisibleDataRange( w, minVvis, maxVvis );
|
|
|
|
}
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
m_absVisibleMaxV = std::max( std::abs( minVvis ), std::abs( maxVvis ) );
|
2016-08-11 12:41:48 +00:00
|
|
|
m_tickValues.clear();
|
2016-08-11 12:42:04 +00:00
|
|
|
m_tickLabels.clear();
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double minErr = 1000000000000.0;
|
2016-08-15 08:53:36 +00:00
|
|
|
double bestStep = 1.0;
|
2023-08-31 22:50:14 +00:00
|
|
|
int m_scrY = w.GetYScreen();
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
for( int i = 10; i <= 20; i += 2 )
|
2016-08-11 12:42:18 +00:00
|
|
|
{
|
2023-07-20 16:20:57 +00:00
|
|
|
double curr_step = fabs( maxVvis - minVvis ) / (double) i;
|
|
|
|
double base = pow( 10, floor( log10( curr_step ) ) );
|
2016-08-29 09:39:54 +00:00
|
|
|
double stepInt = floor( curr_step / base ) * base;
|
|
|
|
double err = fabs( curr_step - stepInt );
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( err< minErr )
|
2016-08-11 12:42:18 +00:00
|
|
|
{
|
|
|
|
minErr = err;
|
|
|
|
bestStep = stepInt;
|
2016-08-11 12:41:48 +00:00
|
|
|
}
|
2016-08-11 12:42:18 +00:00
|
|
|
}
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2023-08-31 22:50:14 +00:00
|
|
|
double numberSteps = floor( ( maxVvis - minVvis ) / bestStep );
|
|
|
|
|
|
|
|
// Half the number of ticks according to window size.
|
|
|
|
// For each 32 device context units, is possible to add a new tick.
|
2023-09-05 18:17:53 +00:00
|
|
|
while( numberSteps >= m_scrY/32.0 )
|
2023-08-31 22:50:14 +00:00
|
|
|
{
|
|
|
|
bestStep *= 2;
|
|
|
|
numberSteps = floor( ( maxVvis - minVvis ) / bestStep );
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double v = floor( minVvis / bestStep ) * bestStep;
|
2016-08-11 12:41:48 +00:00
|
|
|
double zeroOffset = 100000000.0;
|
2023-07-20 16:20:57 +00:00
|
|
|
const int iterLimit = 1000;
|
|
|
|
int i = 0;
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2023-07-20 16:20:57 +00:00
|
|
|
while( v <= maxVvis && i < iterLimit )
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
m_tickValues.push_back( v );
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( fabs( v ) < zeroOffset )
|
|
|
|
zeroOffset = fabs( v );
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
v += bestStep;
|
2016-08-11 12:42:04 +00:00
|
|
|
i++;
|
2016-08-11 12:41:48 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 12:42:02 +00:00
|
|
|
// something weird happened...
|
2016-08-12 08:10:33 +00:00
|
|
|
if( i == iterLimit )
|
2016-08-11 12:42:02 +00:00
|
|
|
m_tickValues.clear();
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( zeroOffset <= bestStep )
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
for( double& t : m_tickValues )
|
2016-08-11 12:41:48 +00:00
|
|
|
t -= zeroOffset;
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
for( double t : m_tickValues )
|
2019-12-05 15:41:21 +00:00
|
|
|
m_tickLabels.emplace_back( t );
|
2016-08-11 12:42:04 +00:00
|
|
|
|
|
|
|
updateTickLabels( dc, w );
|
2016-08-11 12:41:48 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
void mpScaleXBase::getVisibleDataRange( mpWindow& w, double& minV, double& maxV )
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
2023-07-18 10:56:36 +00:00
|
|
|
wxCoord startPx = w.GetMarginLeft();
|
|
|
|
wxCoord endPx = w.GetScrX() - w.GetMarginRight();
|
2016-08-12 08:10:33 +00:00
|
|
|
double pxmin = w.p2x( startPx );
|
|
|
|
double pxmax = w.p2x( endPx );
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
minV = TransformFromPlot( pxmin );
|
|
|
|
maxV = TransformFromPlot( pxmax );
|
2016-08-11 12:41:48 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpScaleXLog::recalculateTicks( wxDC& dc, mpWindow& w )
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
|
|
|
double minV, maxV, minVvis, maxVvis;
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
GetDataRange( minV, maxV );
|
|
|
|
getVisibleDataRange( w, minVvis, maxVvis );
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// double decades = log( maxV / minV ) / log(10);
|
|
|
|
double minDecade = pow( 10, floor( log10( minV ) ) );
|
|
|
|
double maxDecade = pow( 10, ceil( log10( maxV ) ) );
|
|
|
|
double visibleDecades = log( maxVvis / minVvis ) / log( 10 );
|
2023-08-31 22:50:14 +00:00
|
|
|
double step = 10.0;
|
|
|
|
int m_scrX = w.GetXScreen();
|
2016-08-11 12:41:48 +00:00
|
|
|
|
|
|
|
double d;
|
|
|
|
|
2016-08-11 12:41:49 +00:00
|
|
|
m_tickValues.clear();
|
2016-08-11 12:42:04 +00:00
|
|
|
m_tickLabels.clear();
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( minDecade == 0.0 )
|
2016-08-11 12:41:49 +00:00
|
|
|
return;
|
|
|
|
|
2023-08-31 22:50:14 +00:00
|
|
|
// Half the number of ticks according to window size.
|
|
|
|
// The value 96 is used to have only 4 ticks when m_scrX is 268.
|
|
|
|
// For each 96 device context units, is possible to add a new tick.
|
2023-09-20 15:59:39 +00:00
|
|
|
while( visibleDecades - 2 >= m_scrX / 96.0 )
|
2023-08-31 22:50:14 +00:00
|
|
|
{
|
|
|
|
step *= 10.0;
|
|
|
|
visibleDecades = log( maxVvis / minVvis ) / log( step );
|
|
|
|
}
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2023-08-31 22:50:14 +00:00
|
|
|
for( d = minDecade; d<=maxDecade; d *= step )
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
2019-12-05 15:41:21 +00:00
|
|
|
m_tickLabels.emplace_back( d );
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2023-08-31 22:50:14 +00:00
|
|
|
for( double dd = d; dd < d * step; dd += d )
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( visibleDecades < 2 )
|
2019-12-05 15:41:21 +00:00
|
|
|
m_tickLabels.emplace_back( dd );
|
2016-08-11 12:42:04 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
m_tickValues.push_back( dd );
|
2016-08-11 12:41:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:42:04 +00:00
|
|
|
updateTickLabels( dc, w );
|
2016-08-11 12:41:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
IMPLEMENT_ABSTRACT_CLASS( mpScaleXBase, mpLayer )
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS( mpScaleX, mpScaleXBase )
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS( mpScaleXLog, mpScaleXBase )
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2017-09-23 09:20:10 +00:00
|
|
|
mpScaleXBase::mpScaleXBase( const wxString& name, int flags, bool ticks, unsigned int type )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
SetName( name );
|
|
|
|
SetFont( (wxFont&) *wxSMALL_FONT );
|
|
|
|
SetPen( (wxPen&) *wxGREY_PEN );
|
2016-08-11 12:41:21 +00:00
|
|
|
m_flags = flags;
|
|
|
|
m_ticks = ticks;
|
|
|
|
m_type = mpLAYER_AXIS;
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2017-09-23 09:20:10 +00:00
|
|
|
mpScaleX::mpScaleX( const wxString& name, int flags, bool ticks, unsigned int type ) :
|
2016-08-12 08:10:33 +00:00
|
|
|
mpScaleXBase( name, flags, ticks, type )
|
|
|
|
{
|
2017-11-02 20:41:29 +00:00
|
|
|
}
|
2016-08-11 12:41:48 +00:00
|
|
|
|
|
|
|
|
2017-09-23 09:20:10 +00:00
|
|
|
mpScaleXLog::mpScaleXLog( const wxString& name, int flags, bool ticks, unsigned int type ) :
|
2016-08-12 08:10:33 +00:00
|
|
|
mpScaleXBase( name, flags, ticks, type )
|
|
|
|
{
|
2017-11-02 20:41:29 +00:00
|
|
|
}
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpScaleXBase::Plot( wxDC& dc, mpWindow& w )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-11 12:41:48 +00:00
|
|
|
int tx, ty;
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
m_offset = -m_minV;
|
|
|
|
m_scale = 1.0 / ( m_maxV - m_minV );
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2016-08-11 12:41:48 +00:00
|
|
|
recalculateTicks( dc, w );
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_visible )
|
|
|
|
{
|
|
|
|
dc.SetPen( m_pen );
|
|
|
|
dc.SetFont( m_font );
|
|
|
|
int orgy = 0;
|
|
|
|
|
|
|
|
const int extend = w.GetScrX(); ///2;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_flags == mpALIGN_CENTER )
|
2023-07-18 10:56:36 +00:00
|
|
|
orgy = w.y2p( 0 );
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
if( m_flags == mpALIGN_TOP )
|
2023-07-18 10:56:36 +00:00
|
|
|
orgy = w.GetMarginTop();
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
if( m_flags == mpALIGN_BOTTOM )
|
2023-07-18 10:56:36 +00:00
|
|
|
orgy = w.GetScrY() - w.GetMarginBottom();
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_flags == mpALIGN_BORDER_BOTTOM )
|
2023-07-18 10:56:36 +00:00
|
|
|
orgy = w.GetScrY() - 1;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
if( m_flags == mpALIGN_BORDER_TOP )
|
2023-07-18 10:56:36 +00:00
|
|
|
orgy = 1;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2023-07-18 10:56:36 +00:00
|
|
|
wxCoord startPx = w.GetMarginLeft();
|
|
|
|
wxCoord endPx = w.GetScrX() - w.GetMarginRight();
|
|
|
|
wxCoord minYpx = w.GetMarginTop();
|
|
|
|
wxCoord maxYpx = w.GetScrY() - w.GetMarginBottom();
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// int tmp=-65535;
|
2021-06-09 19:32:58 +00:00
|
|
|
int labelH = m_maxLabelHeight; // Control labels height to decide where to put axis name (below labels or on top of axis)
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// int maxExtent = tc.MaxLabelWidth();
|
2023-08-02 14:43:53 +00:00
|
|
|
for( double tp : m_tickValues )
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
2023-08-02 14:43:53 +00:00
|
|
|
double px = TransformToPlot( tp );
|
2016-08-12 08:10:33 +00:00
|
|
|
const int p = (int) ( ( px - w.GetPosX() ) * w.GetScaleX() );
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2023-08-02 14:43:53 +00:00
|
|
|
if( p >= startPx && p <= endPx )
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
|
|
|
if( m_ticks ) // draw axis ticks
|
|
|
|
{
|
|
|
|
if( m_flags == mpALIGN_BORDER_BOTTOM )
|
|
|
|
dc.DrawLine( p, orgy, p, orgy - 4 );
|
2016-08-11 12:41:21 +00:00
|
|
|
else
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.DrawLine( p, orgy, p, orgy + 4 );
|
|
|
|
}
|
|
|
|
else // draw grid dotted lines
|
|
|
|
{
|
|
|
|
m_pen.SetStyle( wxPENSTYLE_DOT );
|
|
|
|
dc.SetPen( m_pen );
|
|
|
|
|
2023-07-18 10:56:36 +00:00
|
|
|
if( m_flags == mpALIGN_BOTTOM )
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
|
|
|
m_pen.SetStyle( wxPENSTYLE_DOT );
|
|
|
|
dc.SetPen( m_pen );
|
|
|
|
dc.DrawLine( p, orgy + 4, p, minYpx );
|
|
|
|
m_pen.SetStyle( wxPENSTYLE_SOLID );
|
|
|
|
dc.SetPen( m_pen );
|
|
|
|
dc.DrawLine( p, orgy + 4, p, orgy - 4 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-07-18 10:56:36 +00:00
|
|
|
if( m_flags == mpALIGN_TOP )
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.DrawLine( p, orgy - 4, p, maxYpx );
|
|
|
|
else
|
2023-07-18 10:56:36 +00:00
|
|
|
dc.DrawLine( p, minYpx, p, maxYpx );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
m_pen.SetStyle( wxPENSTYLE_SOLID );
|
|
|
|
dc.SetPen( m_pen );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
m_pen.SetStyle( wxPENSTYLE_SOLID );
|
|
|
|
dc.SetPen( m_pen );
|
2016-08-11 12:41:48 +00:00
|
|
|
dc.DrawLine( startPx, minYpx, endPx, minYpx );
|
|
|
|
dc.DrawLine( startPx, maxYpx, endPx, maxYpx );
|
|
|
|
|
2020-08-18 14:17:16 +00:00
|
|
|
// Actually draw labels, taking care of not overlapping them, and distributing them
|
|
|
|
// regularly
|
2023-08-02 15:26:17 +00:00
|
|
|
for( const TICK_LABEL& tickLabel : m_tickLabels )
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
2023-08-02 14:43:53 +00:00
|
|
|
if( !tickLabel.visible )
|
2016-08-11 12:42:04 +00:00
|
|
|
continue;
|
|
|
|
|
2023-08-02 14:43:53 +00:00
|
|
|
double px = TransformToPlot( tickLabel.pos );
|
2016-08-12 08:10:33 +00:00
|
|
|
const int p = (int) ( ( px - w.GetPosX() ) * w.GetScaleX() );
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( (p >= startPx) && (p <= endPx) )
|
|
|
|
{
|
2016-08-11 12:41:21 +00:00
|
|
|
// Write ticks labels in s string
|
2023-08-02 14:43:53 +00:00
|
|
|
wxString s = tickLabel.label;
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.GetTextExtent( s, &tx, &ty );
|
|
|
|
|
|
|
|
if( (m_flags == mpALIGN_BORDER_BOTTOM) || (m_flags == mpALIGN_TOP) )
|
|
|
|
dc.DrawText( s, p - tx / 2, orgy - 4 - ty );
|
|
|
|
else
|
|
|
|
dc.DrawText( s, p - tx / 2, orgy + 4 );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw axis name
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.GetTextExtent( m_name, &tx, &ty );
|
|
|
|
|
|
|
|
switch( m_nameFlags )
|
|
|
|
{
|
|
|
|
case mpALIGN_BORDER_BOTTOM:
|
|
|
|
dc.DrawText( m_name, extend - tx - 4, orgy - 8 - ty - labelH );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case mpALIGN_BOTTOM:
|
|
|
|
dc.DrawText( m_name, (endPx + startPx) / 2 - tx / 2, orgy + 6 + labelH );
|
2023-07-18 10:56:36 +00:00
|
|
|
break;
|
2016-08-11 12:42:04 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
case mpALIGN_CENTER:
|
|
|
|
dc.DrawText( m_name, extend - tx - 4, orgy - 4 - ty );
|
|
|
|
break;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
case mpALIGN_TOP:
|
2023-07-18 10:56:36 +00:00
|
|
|
if( w.GetMarginTop() > (ty + labelH + 8) )
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.DrawText( m_name, (endPx - startPx - tx) >> 1, orgy - 6 - ty - labelH );
|
|
|
|
else
|
|
|
|
dc.DrawText( m_name, extend - tx - 4, orgy + 4 );
|
2023-07-18 10:56:36 +00:00
|
|
|
|
|
|
|
break;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
case mpALIGN_BORDER_TOP:
|
|
|
|
dc.DrawText( m_name, extend - tx - 4, orgy + 6 + labelH );
|
|
|
|
break;
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-11 12:41:48 +00:00
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
IMPLEMENT_DYNAMIC_CLASS( mpScaleY, mpLayer )
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2017-09-23 09:20:10 +00:00
|
|
|
mpScaleY::mpScaleY( const wxString& name, int flags, bool ticks )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
SetName( name );
|
|
|
|
SetFont( (wxFont&) *wxSMALL_FONT );
|
|
|
|
SetPen( (wxPen&) *wxGREY_PEN );
|
2016-08-11 12:41:21 +00:00
|
|
|
m_flags = flags;
|
|
|
|
m_ticks = ticks;
|
2016-08-12 08:10:33 +00:00
|
|
|
m_type = mpLAYER_AXIS;
|
2023-02-19 05:38:42 +00:00
|
|
|
m_masterScale = nullptr;
|
2016-08-11 12:42:04 +00:00
|
|
|
m_nameFlags = mpALIGN_BORDER_LEFT;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpScaleY::Plot( wxDC& dc, mpWindow& w )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
m_offset = -m_minV;
|
|
|
|
m_scale = 1.0 / ( m_maxV - m_minV );
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
recalculateTicks( dc, w );
|
|
|
|
|
|
|
|
if( m_visible )
|
|
|
|
{
|
|
|
|
dc.SetPen( m_pen );
|
|
|
|
dc.SetFont( m_font );
|
|
|
|
|
|
|
|
int orgx = 0;
|
|
|
|
|
|
|
|
if( m_flags == mpALIGN_CENTER )
|
2023-07-18 10:56:36 +00:00
|
|
|
orgx = w.x2p( 0 );
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
if( m_flags == mpALIGN_LEFT )
|
2023-07-18 10:56:36 +00:00
|
|
|
orgx = w.GetMarginLeft();
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
if( m_flags == mpALIGN_RIGHT )
|
2023-07-18 10:56:36 +00:00
|
|
|
orgx = w.GetScrX() - w.GetMarginRight();
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2023-02-10 20:52:52 +00:00
|
|
|
if( m_flags == mpALIGN_FAR_RIGHT )
|
|
|
|
orgx = w.GetScrX() - ( w.GetMarginRight() / 2 );
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_flags == mpALIGN_BORDER_RIGHT )
|
2023-07-18 10:56:36 +00:00
|
|
|
orgx = w.GetScrX() - 1;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
if( m_flags == mpALIGN_BORDER_LEFT )
|
2023-07-18 10:56:36 +00:00
|
|
|
orgx = 1;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2023-07-18 10:56:36 +00:00
|
|
|
wxCoord endPx = w.GetScrX() - w.GetMarginRight();
|
|
|
|
wxCoord minYpx = w.GetMarginTop();
|
|
|
|
wxCoord maxYpx = w.GetScrY() - w.GetMarginBottom();
|
2016-08-11 12:41:21 +00:00
|
|
|
// Draw line
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.DrawLine( orgx, minYpx, orgx, maxYpx );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2023-08-02 14:43:53 +00:00
|
|
|
wxCoord tx, ty;
|
|
|
|
wxString s;
|
|
|
|
wxString fmt;
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
int labelW = 0;
|
|
|
|
// Before staring cycle, calculate label height
|
2021-06-10 01:24:15 +00:00
|
|
|
int labelHeight = 0;
|
2023-08-02 14:43:53 +00:00
|
|
|
s.Printf( fmt, 0 );
|
2021-06-10 01:24:15 +00:00
|
|
|
dc.GetTextExtent( s, &tx, &labelHeight );
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2023-08-02 14:43:53 +00:00
|
|
|
for( double tp : m_tickValues )
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
2023-08-02 14:43:53 +00:00
|
|
|
double py = TransformToPlot( tp );
|
2016-08-12 08:10:33 +00:00
|
|
|
const int p = (int) ( ( w.GetPosY() - py ) * w.GetScaleY() );
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2023-08-02 14:43:53 +00:00
|
|
|
if( p >= minYpx && p <= maxYpx )
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
|
|
|
if( m_ticks ) // Draw axis ticks
|
|
|
|
{
|
|
|
|
if( m_flags == mpALIGN_BORDER_LEFT )
|
|
|
|
dc.DrawLine( orgx, p, orgx + 4, p );
|
|
|
|
else
|
2023-07-18 10:56:36 +00:00
|
|
|
dc.DrawLine( orgx - 4, p, orgx, p );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
dc.DrawLine( orgx - 4, p, orgx + 4, p );
|
|
|
|
|
|
|
|
m_pen.SetStyle( wxPENSTYLE_DOT );
|
|
|
|
dc.SetPen( m_pen );
|
|
|
|
|
2020-04-07 10:24:39 +00:00
|
|
|
dc.DrawLine( orgx - 4, p, endPx, p );
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
m_pen.SetStyle( wxPENSTYLE_SOLID );
|
|
|
|
dc.SetPen( m_pen );
|
|
|
|
}
|
2016-08-11 12:42:04 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// Print ticks labels
|
2016-08-11 12:42:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-02 15:26:17 +00:00
|
|
|
for( const TICK_LABEL& tickLabel : m_tickLabels )
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
2023-08-02 14:43:53 +00:00
|
|
|
double py = TransformToPlot( tickLabel.pos );
|
2016-08-12 08:10:33 +00:00
|
|
|
const int p = (int) ( ( w.GetPosY() - py ) * w.GetScaleY() );
|
2016-08-11 12:42:04 +00:00
|
|
|
|
2023-08-02 14:43:53 +00:00
|
|
|
if( !tickLabel.visible )
|
2016-08-11 12:42:18 +00:00
|
|
|
continue;
|
2016-08-11 12:42:04 +00:00
|
|
|
|
2023-08-02 14:43:53 +00:00
|
|
|
if( p >= minYpx && p <= maxYpx )
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
2023-08-02 14:43:53 +00:00
|
|
|
s = tickLabel.label;
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.GetTextExtent( s, &tx, &ty );
|
2016-08-11 12:42:04 +00:00
|
|
|
|
2023-02-10 20:52:52 +00:00
|
|
|
if( m_flags == mpALIGN_BORDER_LEFT || m_flags == mpALIGN_RIGHT || m_flags == mpALIGN_FAR_RIGHT )
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.DrawText( s, orgx + 4, p - ty / 2 );
|
2016-08-11 12:42:18 +00:00
|
|
|
else
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.DrawText( s, orgx - 4 - tx, p - ty / 2 ); // ( s, orgx+4, p-ty/2);
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-11 12:42:18 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// Draw axis name
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.GetTextExtent( m_name, &tx, &ty );
|
|
|
|
|
|
|
|
switch( m_nameFlags )
|
|
|
|
{
|
|
|
|
case mpALIGN_BORDER_LEFT:
|
|
|
|
dc.DrawText( m_name, labelW + 8, 4 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case mpALIGN_LEFT:
|
2023-02-10 20:52:52 +00:00
|
|
|
dc.DrawText( m_name, orgx - ( tx / 2 ), minYpx - ty - 4 );
|
2023-07-18 10:56:36 +00:00
|
|
|
break;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
case mpALIGN_CENTER:
|
|
|
|
dc.DrawText( m_name, orgx + 4, 4 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case mpALIGN_RIGHT:
|
2023-02-10 20:52:52 +00:00
|
|
|
case mpALIGN_FAR_RIGHT:
|
|
|
|
dc.DrawText( m_name, orgx - ( tx / 2 ), minYpx - ty - 4 );
|
2023-07-18 10:56:36 +00:00
|
|
|
break;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
case mpALIGN_BORDER_RIGHT:
|
|
|
|
dc.DrawText( m_name, orgx - 6 - tx - labelW, 4 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:42:04 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2016-08-11 12:41:21 +00:00
|
|
|
// mpWindow
|
2016-08-12 08:10:33 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS( mpWindow, wxWindow )
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE( mpWindow, wxWindow )
|
|
|
|
EVT_PAINT( mpWindow::OnPaint )
|
|
|
|
EVT_SIZE( mpWindow::OnSize )
|
|
|
|
|
|
|
|
EVT_MIDDLE_DOWN( mpWindow::OnMouseMiddleDown ) // JLB
|
|
|
|
EVT_RIGHT_UP( mpWindow::OnShowPopupMenu )
|
2023-09-26 12:18:28 +00:00
|
|
|
EVT_MOUSEWHEEL( mpWindow::onMouseWheel ) // JLB
|
|
|
|
EVT_MAGNIFY( mpWindow::onMagnify )
|
|
|
|
EVT_MOTION( mpWindow::onMouseMove ) // JLB
|
|
|
|
EVT_LEFT_DOWN( mpWindow::onMouseLeftDown )
|
|
|
|
EVT_LEFT_UP( mpWindow::onMouseLeftRelease )
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
EVT_MENU( mpID_CENTER, mpWindow::OnCenter )
|
|
|
|
EVT_MENU( mpID_FIT, mpWindow::OnFit )
|
2023-09-26 12:18:28 +00:00
|
|
|
EVT_MENU( mpID_ZOOM_IN, mpWindow::onZoomIn )
|
|
|
|
EVT_MENU( mpID_ZOOM_OUT, mpWindow::onZoomOut )
|
|
|
|
EVT_MENU( mpID_ZOOM_UNDO, mpWindow::onZoomUndo )
|
|
|
|
EVT_MENU( mpID_ZOOM_REDO, mpWindow::onZoomRedo )
|
2016-08-11 12:41:21 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2024-01-30 03:59:12 +00:00
|
|
|
mpWindow::mpWindow() : mpWindow( DelegatingContructorTag() )
|
2020-09-22 11:29:13 +00:00
|
|
|
{
|
2024-01-23 01:02:50 +00:00
|
|
|
initializeGraphicsContext();
|
2020-09-22 11:29:13 +00:00
|
|
|
}
|
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
mpWindow::mpWindow( wxWindow* parent, wxWindowID id ) :
|
2024-01-30 03:59:12 +00:00
|
|
|
mpWindow( DelegatingContructorTag(), parent, id, wxDefaultPosition, wxDefaultSize, 0,
|
|
|
|
wxT( "mathplot" ) )
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
2023-09-26 12:18:28 +00:00
|
|
|
m_popmenu.Append( mpID_ZOOM_UNDO, _( "Undo Last Zoom" ), _( "Return zoom to level prior to last zoom action" ) );
|
|
|
|
m_popmenu.Append( mpID_ZOOM_REDO, _( "Redo Last Zoom" ), _( "Return zoom to level prior to last zoom undo" ) );
|
|
|
|
m_popmenu.AppendSeparator();
|
2016-08-29 09:39:54 +00:00
|
|
|
m_popmenu.Append( mpID_ZOOM_IN, _( "Zoom In" ), _( "Zoom in plot view." ) );
|
|
|
|
m_popmenu.Append( mpID_ZOOM_OUT, _( "Zoom Out" ), _( "Zoom out plot view." ) );
|
2023-09-26 12:18:28 +00:00
|
|
|
m_popmenu.Append( mpID_CENTER, _( "Center on Cursor" ), _( "Center plot view to this position" ) );
|
|
|
|
m_popmenu.Append( mpID_FIT, _( "Fit on Screen" ), _( "Set plot view to show all items" ) );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
m_layers.clear();
|
|
|
|
SetBackgroundColour( *wxWHITE );
|
2016-08-12 08:10:33 +00:00
|
|
|
m_bgColour = *wxWHITE;
|
|
|
|
m_fgColour = *wxBLACK;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
SetSizeHints( 128, 128 );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// J.L.Blanco: Eliminates the "flick" with the double buffer.
|
|
|
|
SetBackgroundStyle( wxBG_STYLE_CUSTOM );
|
|
|
|
|
2024-01-23 01:02:50 +00:00
|
|
|
initializeGraphicsContext();
|
2016-08-11 12:41:21 +00:00
|
|
|
UpdateAll();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
mpWindow::~mpWindow()
|
|
|
|
{
|
|
|
|
// Free all the layers:
|
|
|
|
DelAllLayers( true, false );
|
|
|
|
|
2023-02-12 19:54:28 +00:00
|
|
|
delete m_buff_bmp;
|
|
|
|
m_buff_bmp = nullptr;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// Mouse handler, for detecting when the user drag with the right button or just "clicks" for the menu
|
|
|
|
// JLB
|
2016-08-12 08:10:33 +00:00
|
|
|
void mpWindow::OnMouseMiddleDown( wxMouseEvent& event )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-11 12:41:27 +00:00
|
|
|
m_mouseMClick.x = event.GetX();
|
|
|
|
m_mouseMClick.y = event.GetY();
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-03 16:53:30 +00:00
|
|
|
|
2023-09-26 12:18:28 +00:00
|
|
|
void mpWindow::onMagnify( wxMouseEvent& event )
|
2019-11-19 14:58:32 +00:00
|
|
|
{
|
|
|
|
if( !m_enableMouseNavigation )
|
|
|
|
{
|
|
|
|
event.Skip();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
float zoom = event.GetMagnification() + 1.0f;
|
|
|
|
wxPoint pos( event.GetX(), event.GetY() );
|
2023-07-18 10:56:36 +00:00
|
|
|
|
2019-11-19 14:58:32 +00:00
|
|
|
if( zoom > 1.0f )
|
|
|
|
ZoomIn( pos, zoom );
|
|
|
|
else if( zoom < 1.0f )
|
|
|
|
ZoomOut( pos, 1.0f / zoom );
|
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2021-08-03 16:53:30 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// Process mouse wheel events
|
|
|
|
// JLB
|
2023-09-26 12:18:28 +00:00
|
|
|
void mpWindow::onMouseWheel( wxMouseEvent& event )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( !m_enableMouseNavigation )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
event.Skip();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-23 01:02:50 +00:00
|
|
|
const wxMouseWheelAxis axis = event.GetWheelAxis();
|
2024-01-30 03:59:12 +00:00
|
|
|
const int modifiers = event.GetModifiers();
|
|
|
|
MouseWheelAction action = MouseWheelAction::NONE;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2024-01-23 01:02:50 +00:00
|
|
|
if( axis == wxMOUSE_WHEEL_HORIZONTAL )
|
2016-08-11 12:41:27 +00:00
|
|
|
{
|
2024-01-23 01:02:50 +00:00
|
|
|
action = m_mouseWheelActions.horizontal;
|
|
|
|
}
|
|
|
|
else if( modifiers == wxMOD_NONE )
|
|
|
|
{
|
|
|
|
action = m_mouseWheelActions.verticalUnmodified;
|
|
|
|
}
|
|
|
|
else if( modifiers == wxMOD_CONTROL )
|
|
|
|
{
|
|
|
|
action = m_mouseWheelActions.verticalWithCtrl;
|
|
|
|
}
|
|
|
|
else if( modifiers == wxMOD_SHIFT )
|
|
|
|
{
|
|
|
|
action = m_mouseWheelActions.verticalWithShift;
|
|
|
|
}
|
|
|
|
else if( modifiers == wxMOD_ALT )
|
|
|
|
{
|
|
|
|
action = m_mouseWheelActions.verticalWithAlt;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-01-23 01:02:50 +00:00
|
|
|
event.Skip();
|
2019-11-19 14:58:32 +00:00
|
|
|
return;
|
|
|
|
}
|
2024-01-23 01:02:50 +00:00
|
|
|
|
|
|
|
PerformMouseWheelAction( event, action );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
// If the user "drags" with the right button pressed, do "pan"
|
2016-08-11 12:41:21 +00:00
|
|
|
// JLB
|
2023-09-26 12:18:28 +00:00
|
|
|
void mpWindow::onMouseMove( wxMouseEvent& event )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( !m_enableMouseNavigation )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
event.Skip();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-31 17:29:46 +00:00
|
|
|
wxCursor cursor = wxCURSOR_MAGNIFIER;
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( event.m_middleDown )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2023-01-31 17:29:46 +00:00
|
|
|
cursor = wxCURSOR_ARROW;
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// The change:
|
2016-08-12 08:10:33 +00:00
|
|
|
int Ax = m_mouseMClick.x - event.GetX();
|
|
|
|
int Ay = m_mouseMClick.y - event.GetY();
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// For the next event, use relative to this coordinates.
|
2016-08-11 12:41:27 +00:00
|
|
|
m_mouseMClick.x = event.GetX();
|
|
|
|
m_mouseMClick.y = event.GetY();
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2023-10-27 06:13:44 +00:00
|
|
|
if( Ax )
|
|
|
|
{
|
|
|
|
double Ax_units = Ax / m_scaleX;
|
|
|
|
SetXView( m_posX + Ax_units, m_desiredXmax + Ax_units, m_desiredXmin + Ax_units );
|
|
|
|
}
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2023-10-27 06:13:44 +00:00
|
|
|
if( Ay )
|
2023-07-18 10:56:36 +00:00
|
|
|
{
|
2023-10-27 06:13:44 +00:00
|
|
|
double Ay_units = -Ay / m_scaleY;
|
|
|
|
SetYView( m_posY + Ay_units, m_desiredYmax + Ay_units, m_desiredYmin + Ay_units );
|
2023-07-18 10:56:36 +00:00
|
|
|
}
|
2023-10-27 06:13:44 +00:00
|
|
|
|
|
|
|
if( Ax || Ay )
|
|
|
|
UpdateAll();
|
2016-08-12 08:10:33 +00:00
|
|
|
}
|
2023-01-31 17:29:46 +00:00
|
|
|
else if( event.m_leftDown )
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
2023-01-31 17:29:46 +00:00
|
|
|
if( m_movingInfoLayer )
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
2023-03-20 09:43:16 +00:00
|
|
|
if( dynamic_cast<mpInfoLegend*>( m_movingInfoLayer ) )
|
|
|
|
cursor = wxCURSOR_SIZING;
|
|
|
|
else
|
|
|
|
cursor = wxCURSOR_SIZEWE;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2023-01-31 17:29:46 +00:00
|
|
|
wxPoint moveVector( event.GetX() - m_mouseLClick.x, event.GetY() - m_mouseLClick.y );
|
|
|
|
m_movingInfoLayer->Move( moveVector );
|
|
|
|
m_zooming = false;
|
2016-08-12 08:10:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-01-31 17:29:46 +00:00
|
|
|
cursor = wxCURSOR_MAGNIFIER;
|
|
|
|
|
|
|
|
wxClientDC dc( this );
|
|
|
|
wxPen pen( m_fgColour, 1, wxPENSTYLE_DOT );
|
|
|
|
dc.SetPen( pen );
|
|
|
|
dc.SetBrush( *wxTRANSPARENT_BRUSH );
|
|
|
|
dc.DrawRectangle( m_mouseLClick.x, m_mouseLClick.y,
|
2023-07-17 21:28:05 +00:00
|
|
|
event.GetX() - m_mouseLClick.x, event.GetY() - m_mouseLClick.y );
|
2023-01-31 17:29:46 +00:00
|
|
|
m_zooming = true;
|
2023-07-17 21:28:05 +00:00
|
|
|
m_zoomRect.x = m_mouseLClick.x;
|
|
|
|
m_zoomRect.y = m_mouseLClick.y;
|
|
|
|
m_zoomRect.width = event.GetX() - m_mouseLClick.x;
|
|
|
|
m_zoomRect.height = event.GetY() - m_mouseLClick.y;
|
2023-01-31 17:29:46 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2023-01-31 17:29:46 +00:00
|
|
|
UpdateAll();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( mpLayer* layer : m_layers)
|
|
|
|
{
|
|
|
|
if( layer->IsInfo() && layer->IsVisible() )
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
2023-01-31 17:29:46 +00:00
|
|
|
mpInfoLayer* infoLayer = (mpInfoLayer*) layer;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2023-01-31 17:29:46 +00:00
|
|
|
if( infoLayer->Inside( event.GetPosition() ) )
|
2023-03-20 09:43:16 +00:00
|
|
|
{
|
|
|
|
if( dynamic_cast<mpInfoLegend*>( infoLayer ) )
|
|
|
|
cursor = wxCURSOR_SIZING;
|
|
|
|
else
|
|
|
|
cursor = wxCURSOR_SIZEWE;
|
|
|
|
}
|
2023-01-31 17:29:46 +00:00
|
|
|
}
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2023-01-31 17:29:46 +00:00
|
|
|
SetCursor( cursor );
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2023-09-26 12:18:28 +00:00
|
|
|
void mpWindow::onMouseLeftDown( wxMouseEvent& event )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-11 12:41:27 +00:00
|
|
|
m_mouseLClick.x = event.GetX();
|
|
|
|
m_mouseLClick.y = event.GetY();
|
2016-08-11 12:41:48 +00:00
|
|
|
m_zooming = true;
|
2016-08-11 12:41:21 +00:00
|
|
|
wxPoint pointClicked = event.GetPosition();
|
2016-08-12 08:10:33 +00:00
|
|
|
m_movingInfoLayer = IsInsideInfoLayer( pointClicked );
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2023-09-26 12:18:28 +00:00
|
|
|
void mpWindow::onMouseLeftRelease( wxMouseEvent& event )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
wxPoint release( event.GetX(), event.GetY() );
|
|
|
|
wxPoint press( m_mouseLClick.x, m_mouseLClick.y );
|
2016-08-11 12:41:48 +00:00
|
|
|
|
|
|
|
m_zooming = false;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2023-02-19 05:38:42 +00:00
|
|
|
if( m_movingInfoLayer != nullptr )
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
2016-08-11 12:41:21 +00:00
|
|
|
m_movingInfoLayer->UpdateReference();
|
2023-02-19 05:38:42 +00:00
|
|
|
m_movingInfoLayer = nullptr;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if( release != press )
|
|
|
|
ZoomRect( press, release );
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
void mpWindow::Fit()
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( UpdateBBox() )
|
|
|
|
Fit( m_minX, m_maxX, m_minY, m_maxY );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// JL
|
2024-01-30 03:59:12 +00:00
|
|
|
void mpWindow::Fit( double xMin, double xMax, double yMin, double yMax, const wxCoord* printSizeX,
|
|
|
|
const wxCoord* printSizeY, wxOrientation directions )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2024-01-23 01:02:50 +00:00
|
|
|
const bool isPrinting = printSizeX != nullptr && printSizeY != nullptr;
|
|
|
|
|
2016-11-28 14:37:00 +00:00
|
|
|
// Save desired borders:
|
2024-01-23 01:02:50 +00:00
|
|
|
double newDesiredXmin = xMin;
|
|
|
|
double newDesiredXmax = xMax;
|
|
|
|
double newDesiredYmin = yMin;
|
|
|
|
double newDesiredYmax = yMax;
|
2016-11-28 14:37:00 +00:00
|
|
|
|
2024-01-23 01:02:50 +00:00
|
|
|
// Provide a gap between the extrema of the curve and the top/bottom edges of the
|
|
|
|
// plot area. Not to be confused with the left/right/top/bottom margins outside the plot area.
|
|
|
|
const double xGap = fabs( xMax - xMin ) * m_leftRightPlotGapFactor;
|
|
|
|
const double yGap = fabs( yMax - yMin ) * m_topBottomPlotGapFactor;
|
|
|
|
xMin -= xGap;
|
|
|
|
xMax += xGap;
|
|
|
|
yMin -= yGap;
|
|
|
|
yMax += yGap;
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2024-01-23 01:02:50 +00:00
|
|
|
int newScrX = m_scrX;
|
|
|
|
int newScrY = m_scrY;
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2024-01-23 01:02:50 +00:00
|
|
|
if( isPrinting )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
// Printer:
|
2024-01-23 01:02:50 +00:00
|
|
|
newScrX = *printSizeX;
|
|
|
|
newScrY = *printSizeY;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Normal case (screen):
|
2024-01-23 01:02:50 +00:00
|
|
|
GetClientSize( &newScrX, &newScrY );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2024-01-23 01:02:50 +00:00
|
|
|
// Compute the width/height in pixels for the plot area.
|
|
|
|
const int plotScreenWidth = newScrX - m_marginLeft - m_marginRight;
|
|
|
|
const int plotScreenHeight = newScrY - m_marginTop - m_marginBottom;
|
|
|
|
|
|
|
|
// Adjust scale so that desired X/Y span plus extra gap fits in the plot area
|
|
|
|
double desiredSpanX = xMax - xMin;
|
|
|
|
double desiredSpanY = yMax - yMin;
|
2024-01-30 03:59:12 +00:00
|
|
|
double newScaleX = ( desiredSpanX != 0 ) ? double( plotScreenWidth ) / desiredSpanX : 1;
|
|
|
|
double newScaleY = ( desiredSpanY != 0 ) ? double( plotScreenHeight ) / desiredSpanY : 1;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2024-01-23 01:02:50 +00:00
|
|
|
// Adjust corner coordinates:
|
|
|
|
// Upstream's aspect lock code has been removed, so no need to account for centering.
|
2024-01-30 03:59:12 +00:00
|
|
|
double newPosX = xMin - ( m_marginLeft / newScaleX );
|
|
|
|
double newPosY = yMax + ( m_marginTop / newScaleY );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2024-01-23 01:02:50 +00:00
|
|
|
// Commit above changes to member variables only if enabled for their respective dimension.
|
2024-01-30 03:59:12 +00:00
|
|
|
if( ( ( directions & wxHORIZONTAL ) != 0 ) || isPrinting )
|
2024-01-23 01:02:50 +00:00
|
|
|
{
|
|
|
|
// Don't commit the passed desired bounds when printing
|
2024-01-30 03:59:12 +00:00
|
|
|
if( !isPrinting )
|
2024-01-23 01:02:50 +00:00
|
|
|
{
|
|
|
|
m_desiredXmin = newDesiredXmin;
|
|
|
|
m_desiredXmax = newDesiredXmax;
|
|
|
|
}
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2024-01-30 03:59:12 +00:00
|
|
|
m_scrX = newScrX;
|
2024-01-23 01:02:50 +00:00
|
|
|
m_scaleX = newScaleX;
|
2024-01-30 03:59:12 +00:00
|
|
|
m_posX = newPosX;
|
2024-01-23 01:02:50 +00:00
|
|
|
}
|
|
|
|
|
2024-01-30 03:59:12 +00:00
|
|
|
if( ( ( directions & wxVERTICAL ) != 0 ) || isPrinting )
|
2024-01-23 01:02:50 +00:00
|
|
|
{
|
|
|
|
// Don't commit the passed desired bounds when printing
|
2024-01-30 03:59:12 +00:00
|
|
|
if( !isPrinting )
|
2024-01-23 01:02:50 +00:00
|
|
|
{
|
|
|
|
m_desiredYmin = newDesiredYmin;
|
|
|
|
m_desiredYmax = newDesiredYmax;
|
|
|
|
}
|
|
|
|
|
2024-01-30 03:59:12 +00:00
|
|
|
m_scrY = newScrY;
|
2024-01-23 01:02:50 +00:00
|
|
|
m_scaleY = newScaleY;
|
2024-01-30 03:59:12 +00:00
|
|
|
m_posY = newPosY;
|
2024-01-23 01:02:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// It is VERY IMPORTANT to NOT call Refresh if we are drawing to the printer!!
|
2016-08-11 12:41:21 +00:00
|
|
|
// Otherwise, the DC dimensions will be those of the window instead of the printer device
|
2024-01-23 01:02:50 +00:00
|
|
|
// The caller wanting to print should perform another Fit() afterwards to restore this
|
|
|
|
// object's state.
|
|
|
|
if( !isPrinting )
|
2016-08-11 12:41:21 +00:00
|
|
|
UpdateAll();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2024-01-23 01:02:50 +00:00
|
|
|
void mpWindow::AdjustLimitedView( wxOrientation directions )
|
2016-08-11 12:42:08 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( !m_enableLimitedView )
|
2016-08-11 12:42:08 +00:00
|
|
|
return;
|
|
|
|
|
2024-01-23 01:02:50 +00:00
|
|
|
// The m_desired* members are expressed in plot coordinates.
|
|
|
|
// They should be clamped against their respective m_minX, m_maxX, m_minY, m_maxY limits.
|
2016-08-11 12:42:08 +00:00
|
|
|
|
2024-01-30 03:59:12 +00:00
|
|
|
if( ( directions & wxHORIZONTAL ) != 0 )
|
2016-08-11 12:42:08 +00:00
|
|
|
{
|
2024-01-23 01:02:50 +00:00
|
|
|
if( m_desiredXmin < m_minX )
|
|
|
|
{
|
|
|
|
double diff = m_minX - m_desiredXmin;
|
|
|
|
m_posX += diff;
|
2024-01-30 03:59:12 +00:00
|
|
|
m_desiredXmax += diff;
|
|
|
|
m_desiredXmin = m_minX;
|
2024-01-23 01:02:50 +00:00
|
|
|
}
|
2016-08-11 12:42:08 +00:00
|
|
|
|
2024-01-23 01:02:50 +00:00
|
|
|
if( m_desiredXmax > m_maxX )
|
|
|
|
{
|
|
|
|
double diff = m_desiredXmax - m_maxX;
|
|
|
|
m_posX -= diff;
|
2024-01-30 03:59:12 +00:00
|
|
|
m_desiredXmin -= diff;
|
|
|
|
m_desiredXmax = m_maxX;
|
2024-01-23 01:02:50 +00:00
|
|
|
}
|
2016-08-11 12:42:08 +00:00
|
|
|
}
|
|
|
|
|
2024-01-30 03:59:12 +00:00
|
|
|
if( ( directions & wxVERTICAL ) != 0 )
|
2016-08-11 12:42:08 +00:00
|
|
|
{
|
2024-01-23 01:02:50 +00:00
|
|
|
if( m_desiredYmin < m_minY )
|
|
|
|
{
|
|
|
|
double diff = m_minY - m_desiredYmin;
|
|
|
|
m_posY += diff;
|
2024-01-30 03:59:12 +00:00
|
|
|
m_desiredYmax += diff;
|
|
|
|
m_desiredYmin = m_minY;
|
2024-01-23 01:02:50 +00:00
|
|
|
}
|
2016-08-11 12:42:08 +00:00
|
|
|
|
2024-01-23 01:02:50 +00:00
|
|
|
if( m_desiredYmax > m_maxY )
|
|
|
|
{
|
|
|
|
double diff = m_desiredYmax - m_maxY;
|
|
|
|
m_posY -= diff;
|
2024-01-30 03:59:12 +00:00
|
|
|
m_desiredYmin -= diff;
|
|
|
|
m_desiredYmax = m_maxY;
|
2024-01-23 01:02:50 +00:00
|
|
|
}
|
2016-08-11 12:42:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
bool mpWindow::SetXView( double pos, double desiredMax, double desiredMin )
|
2016-08-11 12:41:37 +00:00
|
|
|
{
|
2024-01-23 01:02:50 +00:00
|
|
|
// TODO (ecorm): Investigate X scale flickering when panning at minimum zoom level
|
|
|
|
// Possible cause: When AdjustLimitedView subtracts the out-of-bound delta, it does not
|
|
|
|
// revert back to the exact same original coordinates due to floating point rounding errors.
|
2016-08-11 12:41:37 +00:00
|
|
|
m_posX = pos;
|
2016-08-12 08:10:33 +00:00
|
|
|
m_desiredXmax = desiredMax;
|
|
|
|
m_desiredXmin = desiredMin;
|
2024-01-23 01:02:50 +00:00
|
|
|
AdjustLimitedView( wxHORIZONTAL );
|
2016-08-11 12:41:37 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
bool mpWindow::SetYView( double pos, double desiredMax, double desiredMin )
|
2016-08-11 12:41:37 +00:00
|
|
|
{
|
|
|
|
m_posY = pos;
|
2016-08-12 08:10:33 +00:00
|
|
|
m_desiredYmax = desiredMax;
|
|
|
|
m_desiredYmin = desiredMin;
|
2024-01-23 01:02:50 +00:00
|
|
|
AdjustLimitedView( wxVERTICAL );
|
2016-08-11 12:41:37 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
void mpWindow::ZoomIn( const wxPoint& centerPoint )
|
2019-11-19 14:58:32 +00:00
|
|
|
{
|
2024-01-23 01:02:50 +00:00
|
|
|
ZoomIn( centerPoint, zoomIncrementalFactor, wxBOTH );
|
2019-11-19 14:58:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-23 01:02:50 +00:00
|
|
|
void mpWindow::ZoomIn( const wxPoint& centerPoint, double zoomFactor, wxOrientation directions )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2024-01-23 01:02:50 +00:00
|
|
|
DoZoom( centerPoint, zoomFactor, directions );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpWindow::ZoomOut( const wxPoint& centerPoint )
|
2019-11-19 14:58:32 +00:00
|
|
|
{
|
2024-01-23 01:02:50 +00:00
|
|
|
ZoomOut( centerPoint, zoomIncrementalFactor, wxBOTH );
|
2019-11-19 14:58:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-30 03:59:12 +00:00
|
|
|
void mpWindow::ZoomOut( const wxPoint& centerPoint, double zoomFactor, wxOrientation directions )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2024-01-30 03:59:12 +00:00
|
|
|
if( zoomFactor == 0 )
|
2024-01-23 01:02:50 +00:00
|
|
|
zoomFactor = 1.0;
|
|
|
|
DoZoom( centerPoint, 1.0 / zoomFactor, directions );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpWindow::ZoomRect( wxPoint p0, wxPoint p1 )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2023-09-26 12:18:28 +00:00
|
|
|
pushZoomUndo( { m_desiredXmin, m_desiredXmax, m_desiredYmin, m_desiredYmax } );
|
|
|
|
|
2024-01-23 01:02:50 +00:00
|
|
|
// Constrain given rectangle to plot area
|
|
|
|
const int pMinX = m_marginLeft;
|
|
|
|
const int pMaxX = m_scrX - m_marginRight;
|
|
|
|
const int pMinY = m_marginTop;
|
|
|
|
const int pMaxY = m_scrY - m_marginBottom;
|
|
|
|
p0.x = std::max( p0.x, pMinX );
|
|
|
|
p0.x = std::min( p0.x, pMaxX );
|
|
|
|
p0.y = std::max( p0.y, pMinY );
|
|
|
|
p0.y = std::min( p0.y, pMaxY );
|
|
|
|
p1.x = std::max( p1.x, pMinX );
|
|
|
|
p1.x = std::min( p1.x, pMaxX );
|
|
|
|
p1.y = std::max( p1.y, pMinY );
|
|
|
|
p1.y = std::min( p1.y, pMaxY );
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// Compute the 2 corners in graph coordinates:
|
2016-08-12 08:10:33 +00:00
|
|
|
double p0x = p2x( p0.x );
|
|
|
|
double p0y = p2y( p0.y );
|
|
|
|
double p1x = p2x( p1.x );
|
|
|
|
double p1y = p2y( p1.y );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// Order them:
|
2016-08-12 08:10:33 +00:00
|
|
|
double zoom_x_min = p0x<p1x ? p0x : p1x;
|
|
|
|
double zoom_x_max = p0x>p1x ? p0x : p1x;
|
|
|
|
double zoom_y_min = p0y<p1y ? p0y : p1y;
|
|
|
|
double zoom_y_max = p0y>p1y ? p0y : p1y;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2023-07-19 15:25:57 +00:00
|
|
|
if( m_yLocked )
|
|
|
|
{
|
|
|
|
zoom_y_min = m_desiredYmin;
|
|
|
|
zoom_y_max = m_desiredYmax;
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
Fit( zoom_x_min, zoom_x_max, zoom_y_min, zoom_y_max );
|
2024-01-23 01:02:50 +00:00
|
|
|
|
|
|
|
// Even with the input rectangle contrained to the plot area, it's still possible for the
|
|
|
|
// resulting view to exceed limits when a portion of the gap is grabbed.
|
2016-08-11 12:42:08 +00:00
|
|
|
AdjustLimitedView();
|
2024-01-23 01:02:50 +00:00
|
|
|
|
|
|
|
// These additional checks are needed because AdjustLimitedView only adjusts the position
|
|
|
|
// and not the scale.
|
|
|
|
wxOrientation directionsNeedingRefitting = ViewNeedsRefitting( wxBOTH );
|
|
|
|
if( directionsNeedingRefitting != 0 )
|
|
|
|
Fit( m_minX, m_maxX, m_minY, m_maxY, nullptr, nullptr, directionsNeedingRefitting );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2023-09-26 12:18:28 +00:00
|
|
|
void mpWindow::pushZoomUndo( const std::array<double, 4>& aZoom )
|
|
|
|
{
|
|
|
|
m_undoZoomStack.push( aZoom );
|
|
|
|
|
|
|
|
while( !m_redoZoomStack.empty() )
|
|
|
|
m_redoZoomStack.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void mpWindow::ZoomUndo()
|
|
|
|
{
|
|
|
|
if( m_undoZoomStack.size() )
|
|
|
|
{
|
|
|
|
m_redoZoomStack.push( { m_desiredXmin, m_desiredXmax, m_desiredYmin, m_desiredYmax } );
|
|
|
|
|
|
|
|
std::array<double, 4> zoom = m_undoZoomStack.top();
|
|
|
|
m_undoZoomStack.pop();
|
|
|
|
|
|
|
|
Fit( zoom[0], zoom[1], zoom[2], zoom[3] );
|
|
|
|
AdjustLimitedView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void mpWindow::ZoomRedo()
|
|
|
|
{
|
|
|
|
if( m_redoZoomStack.size() )
|
|
|
|
{
|
|
|
|
m_undoZoomStack.push( { m_desiredXmin, m_desiredXmax, m_desiredYmin, m_desiredYmax } );
|
|
|
|
|
|
|
|
std::array<double, 4> zoom = m_redoZoomStack.top();
|
|
|
|
m_redoZoomStack.pop();
|
|
|
|
|
|
|
|
Fit( zoom[0], zoom[1], zoom[2], zoom[3] );
|
|
|
|
AdjustLimitedView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
void mpWindow::OnShowPopupMenu( wxMouseEvent& event )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
m_clickedX = event.GetX();
|
|
|
|
m_clickedY = event.GetY();
|
2023-09-26 12:18:28 +00:00
|
|
|
|
|
|
|
m_popmenu.Enable( mpID_ZOOM_UNDO, !m_undoZoomStack.empty() );
|
|
|
|
m_popmenu.Enable( mpID_ZOOM_REDO, !m_redoZoomStack.empty() );
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
PopupMenu( &m_popmenu, event.GetX(), event.GetY() );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpWindow::OnFit( wxCommandEvent& WXUNUSED( event ) )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2023-09-26 12:18:28 +00:00
|
|
|
pushZoomUndo( { m_desiredXmin, m_desiredXmax, m_desiredYmin, m_desiredYmax } );
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
Fit();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpWindow::OnCenter( wxCommandEvent& WXUNUSED( event ) )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
GetClientSize( &m_scrX, &m_scrY );
|
2023-07-18 10:56:36 +00:00
|
|
|
int centerX = (m_scrX - m_marginLeft - m_marginRight) / 2;
|
|
|
|
int centerY = (m_scrY - m_marginTop - m_marginBottom) / 2;
|
2016-08-12 08:10:33 +00:00
|
|
|
SetPos( p2x( m_clickedX - centerX ), p2y( m_clickedY - centerY ) );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2024-01-23 01:02:50 +00:00
|
|
|
mpWindow::MouseWheelActionSet mpWindow::defaultMouseWheelActions()
|
|
|
|
{
|
|
|
|
MouseWheelActionSet actions;
|
|
|
|
actions.verticalUnmodified = MouseWheelAction::ZOOM;
|
|
|
|
actions.verticalWithCtrl = MouseWheelAction::PAN_LEFT_RIGHT;
|
|
|
|
actions.verticalWithShift = MouseWheelAction::PAN_UP_DOWN;
|
|
|
|
actions.verticalWithAlt = MouseWheelAction::NONE;
|
|
|
|
actions.horizontal = MouseWheelAction::NONE;
|
|
|
|
return actions;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-26 12:18:28 +00:00
|
|
|
void mpWindow::onZoomIn( wxCommandEvent& WXUNUSED( event ) )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
ZoomIn( wxPoint( m_mouseMClick.x, m_mouseMClick.y ) );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2023-09-26 12:18:28 +00:00
|
|
|
void mpWindow::onZoomOut( wxCommandEvent& WXUNUSED( event ) )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
ZoomOut();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2023-09-26 12:18:28 +00:00
|
|
|
void mpWindow::onZoomUndo( wxCommandEvent& WXUNUSED( event ) )
|
|
|
|
{
|
|
|
|
ZoomUndo();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void mpWindow::onZoomRedo( wxCommandEvent& WXUNUSED( event ) )
|
|
|
|
{
|
|
|
|
ZoomRedo();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
void mpWindow::OnSize( wxSizeEvent& WXUNUSED( event ) )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
// Try to fit again with the new window size:
|
|
|
|
Fit( m_desiredXmin, m_desiredXmax, m_desiredYmin, m_desiredYmax );
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
bool mpWindow::AddLayer( mpLayer* layer, bool refreshDisplay )
|
|
|
|
{
|
2023-02-12 19:54:28 +00:00
|
|
|
if( layer )
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
2016-08-11 12:41:21 +00:00
|
|
|
m_layers.push_back( layer );
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
if( refreshDisplay )
|
|
|
|
UpdateAll();
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
return true;
|
2016-08-12 08:10:33 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2023-02-12 19:54:28 +00:00
|
|
|
bool mpWindow::DelLayer( mpLayer* layer, bool alsoDeleteObject, bool refreshDisplay )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
wxLayerList::iterator layIt;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
for( layIt = m_layers.begin(); layIt != m_layers.end(); layIt++ )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( *layIt == layer )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
// Also delete the object?
|
2016-08-12 08:10:33 +00:00
|
|
|
if( alsoDeleteObject )
|
2016-08-11 12:41:21 +00:00
|
|
|
delete *layIt;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
m_layers.erase( layIt ); // this deleted the reference only
|
|
|
|
|
|
|
|
if( refreshDisplay )
|
2016-08-11 12:41:21 +00:00
|
|
|
UpdateAll();
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpWindow::DelAllLayers( bool alsoDeleteObject, bool refreshDisplay )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
while( m_layers.size()>0 )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
// Also delete the object?
|
2016-08-12 08:10:33 +00:00
|
|
|
if( alsoDeleteObject )
|
|
|
|
delete m_layers[0];
|
|
|
|
|
|
|
|
m_layers.erase( m_layers.begin() ); // this deleted the reference only
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
if( refreshDisplay )
|
|
|
|
UpdateAll();
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpWindow::OnPaint( wxPaintEvent& WXUNUSED( event ) )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2023-07-02 20:15:50 +00:00
|
|
|
wxPaintDC paintDC( this );
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2023-07-02 20:15:50 +00:00
|
|
|
paintDC.GetSize( &m_scrX, &m_scrY ); // This is the size of the visible area only!
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// Selects direct or buffered draw:
|
2023-07-02 20:15:50 +00:00
|
|
|
wxDC* targetDC = &paintDC;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// J.L.Blanco @ Aug 2007: Added double buffer support
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_enableDoubleBuffer )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2021-03-06 09:27:41 +00:00
|
|
|
if( m_last_lx != m_scrX || m_last_ly != m_scrY )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2023-02-12 19:54:28 +00:00
|
|
|
delete m_buff_bmp;
|
2016-08-12 08:10:33 +00:00
|
|
|
m_buff_bmp = new wxBitmap( m_scrX, m_scrY );
|
|
|
|
m_buff_dc.SelectObject( *m_buff_bmp );
|
|
|
|
m_last_lx = m_scrX;
|
|
|
|
m_last_ly = m_scrY;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2023-07-02 20:15:50 +00:00
|
|
|
targetDC = &m_buff_dc;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2023-07-02 20:15:50 +00:00
|
|
|
if( wxGraphicsContext* ctx = targetDC->GetGraphicsContext() )
|
2022-12-21 20:02:35 +00:00
|
|
|
{
|
2023-07-02 20:15:50 +00:00
|
|
|
if( !ctx->SetInterpolationQuality( wxINTERPOLATION_BEST ) )
|
|
|
|
if( !ctx->SetInterpolationQuality( wxINTERPOLATION_GOOD ) )
|
|
|
|
ctx->SetInterpolationQuality( wxINTERPOLATION_FAST );
|
2022-12-21 20:02:35 +00:00
|
|
|
|
|
|
|
ctx->SetAntialiasMode( wxANTIALIAS_DEFAULT );
|
|
|
|
}
|
|
|
|
|
2023-07-02 20:15:50 +00:00
|
|
|
// Draw background:
|
|
|
|
targetDC->SetPen( *wxTRANSPARENT_PEN );
|
2016-08-11 12:41:21 +00:00
|
|
|
wxBrush brush( GetBackgroundColour() );
|
2023-07-02 20:15:50 +00:00
|
|
|
targetDC->SetBrush( brush );
|
|
|
|
targetDC->SetTextForeground( m_fgColour );
|
|
|
|
targetDC->DrawRectangle( 0, 0, m_scrX, m_scrY );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// Draw all the layers:
|
2023-07-02 20:15:50 +00:00
|
|
|
for( mpLayer* layer : m_layers )
|
|
|
|
layer->Plot( *targetDC, *this );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_zooming )
|
2016-08-11 12:41:49 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
wxPen pen( m_fgColour, 1, wxPENSTYLE_DOT );
|
2023-07-02 20:15:50 +00:00
|
|
|
targetDC->SetPen( pen );
|
|
|
|
targetDC->SetBrush( *wxTRANSPARENT_BRUSH );
|
|
|
|
targetDC->DrawRectangle( m_zoomRect );
|
2016-08-11 12:41:49 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// If doublebuffer, draw now to the window:
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_enableDoubleBuffer )
|
2023-07-02 20:15:50 +00:00
|
|
|
paintDC.Blit( 0, 0, m_scrX, m_scrY, targetDC, 0, 0 );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2024-01-30 03:59:12 +00:00
|
|
|
void mpWindow::DoZoom( const wxPoint& centerPoint, double zoomFactor, wxOrientation directions )
|
2024-01-23 01:02:50 +00:00
|
|
|
{
|
|
|
|
if( m_yLocked )
|
|
|
|
{
|
|
|
|
if( directions == wxVERTICAL )
|
|
|
|
return;
|
|
|
|
directions = wxHORIZONTAL;
|
|
|
|
}
|
|
|
|
|
2024-01-30 03:59:12 +00:00
|
|
|
const bool horizontally = ( directions & wxHORIZONTAL ) != 0;
|
|
|
|
const bool vertically = ( directions & wxVERTICAL ) != 0;
|
2024-01-23 01:02:50 +00:00
|
|
|
|
|
|
|
pushZoomUndo( { m_desiredXmin, m_desiredXmax, m_desiredYmin, m_desiredYmax } );
|
|
|
|
|
|
|
|
// Preserve the position of the clicked point:
|
|
|
|
wxPoint c( centerPoint );
|
|
|
|
if( c == wxDefaultPosition )
|
|
|
|
{
|
|
|
|
GetClientSize( &m_scrX, &m_scrY );
|
2024-01-30 03:59:12 +00:00
|
|
|
c.x = ( m_scrX - m_marginLeft - m_marginRight ) / 2 + m_marginLeft;
|
|
|
|
c.y = ( m_scrY - m_marginTop - m_marginBottom ) / 2 + m_marginTop;
|
2024-01-23 01:02:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
c.x = std::max( c.x, m_marginLeft );
|
|
|
|
c.x = std::min( c.x, m_scrX - m_marginRight );
|
|
|
|
c.y = std::max( c.y, m_marginTop );
|
|
|
|
c.y = std::min( c.y, m_scrY - m_marginBottom );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Zoom in/out:
|
|
|
|
const double MAX_SCALE = 1e6;
|
2024-01-30 03:59:12 +00:00
|
|
|
const double newScaleX = horizontally ? ( m_scaleX * zoomFactor ) : m_scaleX;
|
|
|
|
const double newScaleY = vertically ? ( m_scaleY * zoomFactor ) : m_scaleY;
|
2024-01-23 01:02:50 +00:00
|
|
|
|
|
|
|
// Baaaaad things happen when you zoom in too much..
|
|
|
|
if( newScaleX > MAX_SCALE || newScaleY > MAX_SCALE )
|
|
|
|
return;
|
|
|
|
|
2024-01-30 03:59:12 +00:00
|
|
|
if( horizontally )
|
2024-01-23 01:02:50 +00:00
|
|
|
{
|
|
|
|
// Transform the clicked X point to layer coordinates:
|
|
|
|
const double prior_layer_x = p2x( c.x );
|
|
|
|
|
|
|
|
// Adjust the new X scale and plot X origin:
|
|
|
|
m_scaleX = newScaleX;
|
2024-01-30 03:59:12 +00:00
|
|
|
m_posX = prior_layer_x - c.x / newScaleX;
|
2024-01-23 01:02:50 +00:00
|
|
|
|
|
|
|
// Recompute the desired X view extents:
|
|
|
|
RecomputeDesiredX( m_desiredXmin, m_desiredXmax );
|
|
|
|
}
|
|
|
|
|
2024-01-30 03:59:12 +00:00
|
|
|
if( vertically )
|
2024-01-23 01:02:50 +00:00
|
|
|
{
|
|
|
|
// Transform the clicked Y point to layer coordinates:
|
|
|
|
const double prior_layer_y = p2y( c.y );
|
|
|
|
|
|
|
|
// Adjust the new Y scale and plot Y origin:
|
|
|
|
m_scaleY = newScaleY;
|
2024-01-30 03:59:12 +00:00
|
|
|
m_posY = prior_layer_y + c.y / newScaleY;
|
2024-01-23 01:02:50 +00:00
|
|
|
|
|
|
|
// Recompute the desired Y view extents:
|
|
|
|
RecomputeDesiredY( m_desiredYmin, m_desiredYmax );
|
|
|
|
}
|
|
|
|
|
|
|
|
AdjustLimitedView( directions );
|
|
|
|
|
2024-01-30 03:59:12 +00:00
|
|
|
if( zoomFactor < 1.0 )
|
2024-01-23 01:02:50 +00:00
|
|
|
{
|
|
|
|
// These additional checks are needed because AdjustLimitedView only adjusts the position
|
|
|
|
// and not the scale.
|
|
|
|
wxOrientation directionsNeedingRefitting = ViewNeedsRefitting( directions );
|
|
|
|
|
|
|
|
// If the view is still out-of-limits after AdjustLimitedView is called, perform a Fit
|
|
|
|
// along the offending dimension(s).
|
|
|
|
if( directionsNeedingRefitting != 0 )
|
|
|
|
Fit( m_minX, m_maxX, m_minY, m_maxY, nullptr, nullptr, directionsNeedingRefitting );
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void mpWindow::RecomputeDesiredX( double& min, double& max )
|
|
|
|
{
|
2024-01-30 03:59:12 +00:00
|
|
|
const int plotScreenWidth = m_scrX - m_marginLeft - m_marginRight;
|
|
|
|
const double plotSpanX = plotScreenWidth / m_scaleX;
|
|
|
|
const double desiredSpanX = plotSpanX / ( 2 * m_leftRightPlotGapFactor + 1 );
|
|
|
|
const double xGap = desiredSpanX * m_leftRightPlotGapFactor;
|
2024-01-23 01:02:50 +00:00
|
|
|
min = m_posX + ( m_marginLeft / m_scaleX ) + xGap;
|
|
|
|
max = m_desiredXmin + desiredSpanX;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void mpWindow::RecomputeDesiredY( double& min, double& max )
|
|
|
|
{
|
2024-01-30 03:59:12 +00:00
|
|
|
const int plotScreenHeight = m_scrY - m_marginTop - m_marginBottom;
|
|
|
|
const double plotSpanY = plotScreenHeight / m_scaleY;
|
|
|
|
const double desiredSpanY = plotSpanY / ( 2 * m_topBottomPlotGapFactor + 1 );
|
|
|
|
const double yGap = desiredSpanY * m_topBottomPlotGapFactor;
|
|
|
|
max = m_posY - ( m_marginTop / m_scaleY ) - yGap;
|
2024-01-23 01:02:50 +00:00
|
|
|
min = m_desiredYmax - desiredSpanY;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxOrientation mpWindow::ViewNeedsRefitting( wxOrientation directions ) const
|
|
|
|
{
|
|
|
|
if( !m_enableLimitedView )
|
|
|
|
return static_cast<wxOrientation>( 0 );
|
|
|
|
|
|
|
|
// Allow a gap between the extrema of the curve and the edges of the plot area. Not to be
|
|
|
|
// confused with the left/right/top/bottom margins outside the plot area.
|
|
|
|
const double xGap = fabs( m_maxX - m_minX ) * m_leftRightPlotGapFactor;
|
|
|
|
const double yGap = fabs( m_maxY - m_minY ) * m_topBottomPlotGapFactor;
|
|
|
|
|
|
|
|
wxOrientation result = {};
|
|
|
|
|
2024-01-30 03:59:12 +00:00
|
|
|
if( ( directions & wxHORIZONTAL ) != 0 )
|
2024-01-23 01:02:50 +00:00
|
|
|
{
|
2024-01-30 03:59:12 +00:00
|
|
|
if( ( m_desiredXmax > m_maxX + xGap ) || ( m_desiredXmin < m_minX - xGap ) )
|
2024-01-23 01:02:50 +00:00
|
|
|
result = static_cast<wxOrientation>( result | wxHORIZONTAL );
|
|
|
|
}
|
|
|
|
|
2024-01-30 03:59:12 +00:00
|
|
|
if( ( directions & wxVERTICAL ) != 0 )
|
2024-01-23 01:02:50 +00:00
|
|
|
{
|
2024-01-30 03:59:12 +00:00
|
|
|
if( ( m_desiredYmax > m_maxY + yGap ) || ( m_desiredYmin < m_minY - yGap ) )
|
2024-01-23 01:02:50 +00:00
|
|
|
result = static_cast<wxOrientation>( result | wxVERTICAL );
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void mpWindow::PerformMouseWheelAction( wxMouseEvent& event, MouseWheelAction action )
|
|
|
|
{
|
2024-01-30 03:59:12 +00:00
|
|
|
const int change = event.GetWheelRotation();
|
|
|
|
const double changeUnitsX = change / m_scaleX;
|
|
|
|
const double changeUnitsY = change / m_scaleY;
|
2024-01-23 01:02:50 +00:00
|
|
|
const wxPoint clickPt( event.GetX(), event.GetY() );
|
|
|
|
|
2024-01-30 03:59:12 +00:00
|
|
|
switch( action )
|
2024-01-23 01:02:50 +00:00
|
|
|
{
|
2024-01-30 03:59:12 +00:00
|
|
|
case MouseWheelAction::NONE: break;
|
2024-01-23 01:02:50 +00:00
|
|
|
|
|
|
|
case MouseWheelAction::PAN_LEFT_RIGHT:
|
|
|
|
SetXView( m_posX + changeUnitsX, m_desiredXmax + changeUnitsX,
|
|
|
|
m_desiredXmin + changeUnitsX );
|
|
|
|
UpdateAll();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MouseWheelAction::PAN_RIGHT_LEFT:
|
|
|
|
SetXView( m_posX - changeUnitsX, m_desiredXmax - changeUnitsX,
|
|
|
|
m_desiredXmin - changeUnitsX );
|
|
|
|
UpdateAll();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MouseWheelAction::PAN_UP_DOWN:
|
|
|
|
if( !m_yLocked )
|
|
|
|
{
|
|
|
|
SetYView( m_posY + changeUnitsY, m_desiredYmax + changeUnitsY,
|
|
|
|
m_desiredYmin + changeUnitsY );
|
|
|
|
UpdateAll();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MouseWheelAction::ZOOM:
|
|
|
|
if( event.GetWheelRotation() > 0 )
|
|
|
|
ZoomIn( clickPt );
|
|
|
|
else
|
|
|
|
ZoomOut( clickPt );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MouseWheelAction::ZOOM_HORIZONTALLY:
|
|
|
|
if( event.GetWheelRotation() > 0 )
|
|
|
|
ZoomIn( clickPt, zoomIncrementalFactor, wxHORIZONTAL );
|
|
|
|
else
|
|
|
|
ZoomOut( clickPt, zoomIncrementalFactor, wxHORIZONTAL );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MouseWheelAction::ZOOM_VERTICALLY:
|
|
|
|
if( event.GetWheelRotation() > 0 )
|
|
|
|
ZoomIn( clickPt, zoomIncrementalFactor, wxVERTICAL );
|
|
|
|
else
|
|
|
|
ZoomOut( clickPt, zoomIncrementalFactor, wxVERTICAL );
|
|
|
|
break;
|
|
|
|
|
2024-01-30 03:59:12 +00:00
|
|
|
default: break;
|
2024-01-23 01:02:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
bool mpWindow::UpdateBBox()
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
m_minX = 0.0;
|
|
|
|
m_maxX = 1.0;
|
|
|
|
m_minY = 0.0;
|
|
|
|
m_maxY = 1.0;
|
2016-08-11 12:41:48 +00:00
|
|
|
|
|
|
|
return true;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
void mpWindow::UpdateAll()
|
|
|
|
{
|
2023-07-18 10:56:36 +00:00
|
|
|
UpdateBBox();
|
2016-11-28 14:37:00 +00:00
|
|
|
Refresh( false );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpWindow::SetScaleX( double scaleX )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2021-03-06 09:27:41 +00:00
|
|
|
if( scaleX != 0 )
|
2016-08-12 08:10:33 +00:00
|
|
|
m_scaleX = scaleX;
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
UpdateAll();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// New methods implemented by Davide Rondini
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
mpLayer* mpWindow::GetLayer( int position ) const
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( ( position >= (int) m_layers.size() ) || position < 0 )
|
2023-02-19 05:38:42 +00:00
|
|
|
return nullptr;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
return m_layers[position];
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
const mpLayer* mpWindow::GetLayerByName( const wxString& name ) const
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2021-03-06 09:27:41 +00:00
|
|
|
for( const mpLayer* layer : m_layers )
|
2021-08-03 16:53:30 +00:00
|
|
|
{
|
2021-03-06 09:27:41 +00:00
|
|
|
if( !layer->GetName().Cmp( name ) )
|
|
|
|
return layer;
|
2021-08-03 16:53:30 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2023-02-19 05:38:42 +00:00
|
|
|
return nullptr; // Not found
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
void mpWindow::GetBoundingBox( double* bbox ) const
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
bbox[0] = m_minX;
|
|
|
|
bbox[1] = m_maxX;
|
|
|
|
bbox[2] = m_minY;
|
|
|
|
bbox[3] = m_maxY;
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2024-03-19 16:04:42 +00:00
|
|
|
bool mpWindow::SaveScreenshot( wxImage& aImage, wxSize aImageSize, bool aFit )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
int sizeX, sizeY;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2024-03-19 16:04:42 +00:00
|
|
|
if( aImageSize == wxDefaultSize )
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
2023-04-11 08:53:35 +00:00
|
|
|
sizeX = m_scrX;
|
|
|
|
sizeY = m_scrY;
|
2016-08-12 08:10:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-03-19 16:04:42 +00:00
|
|
|
sizeX = aImageSize.x;
|
|
|
|
sizeY = aImageSize.y;
|
2016-08-12 08:10:33 +00:00
|
|
|
SetScr( sizeX, sizeY );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
wxBitmap screenBuffer( sizeX, sizeY );
|
2016-08-11 12:41:21 +00:00
|
|
|
wxMemoryDC screenDC;
|
2016-08-12 08:10:33 +00:00
|
|
|
screenDC.SelectObject( screenBuffer );
|
2019-06-06 02:43:41 +00:00
|
|
|
screenDC.SetPen( *wxWHITE_PEN );
|
|
|
|
screenDC.SetTextForeground( m_fgColour );
|
2016-08-11 12:41:21 +00:00
|
|
|
wxBrush brush( GetBackgroundColour() );
|
|
|
|
screenDC.SetBrush( brush );
|
2016-08-12 08:10:33 +00:00
|
|
|
screenDC.DrawRectangle( 0, 0, sizeX, sizeY );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2024-03-19 16:04:42 +00:00
|
|
|
if( aFit )
|
2016-08-12 08:10:33 +00:00
|
|
|
Fit( m_minX, m_maxX, m_minY, m_maxY, &sizeX, &sizeY );
|
|
|
|
else
|
|
|
|
Fit( m_desiredXmin, m_desiredXmax, m_desiredYmin, m_desiredYmax, &sizeX, &sizeY );
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// Draw all the layers:
|
2021-03-06 09:27:41 +00:00
|
|
|
for( mpLayer* layer : m_layers )
|
|
|
|
layer->Plot( screenDC, *this );
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2024-03-19 16:04:42 +00:00
|
|
|
if( aImageSize != wxDefaultSize )
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
2016-08-11 12:41:21 +00:00
|
|
|
// Restore dimensions
|
2023-04-11 08:53:35 +00:00
|
|
|
int bk_scrX = m_scrX;
|
|
|
|
int bk_scrY = m_scrY;
|
2016-08-12 08:10:33 +00:00
|
|
|
SetScr( bk_scrX, bk_scrY );
|
|
|
|
Fit( m_desiredXmin, m_desiredXmax, m_desiredYmin, m_desiredYmax, &bk_scrX, &bk_scrY );
|
2016-08-11 12:41:21 +00:00
|
|
|
UpdateAll();
|
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// Once drawing is complete, actually save screen shot
|
2024-03-19 16:04:42 +00:00
|
|
|
aImage = screenBuffer.ConvertToImage();
|
|
|
|
|
|
|
|
return true;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpWindow::SetMargins( int top, int right, int bottom, int left )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2021-03-06 09:27:41 +00:00
|
|
|
m_marginTop = top;
|
|
|
|
m_marginRight = right;
|
|
|
|
m_marginBottom = bottom;
|
|
|
|
m_marginLeft = left;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
mpInfoLayer* mpWindow::IsInsideInfoLayer( wxPoint& point )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2021-03-06 09:27:41 +00:00
|
|
|
for( mpLayer* layer : m_layers )
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
2021-03-06 09:27:41 +00:00
|
|
|
if( layer->IsInfo() )
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
2021-03-06 09:27:41 +00:00
|
|
|
mpInfoLayer* tmpLyr = static_cast<mpInfoLayer*>( layer );
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
if( tmpLyr->Inside( point ) )
|
2016-08-11 12:41:21 +00:00
|
|
|
return tmpLyr;
|
|
|
|
}
|
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2023-02-19 05:38:42 +00:00
|
|
|
return nullptr;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpWindow::SetLayerVisible( const wxString& name, bool viewable )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2023-08-02 15:26:17 +00:00
|
|
|
if( mpLayer* lx = GetLayerByName( name ) )
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
|
|
|
lx->SetVisible( viewable );
|
2016-08-11 12:41:21 +00:00
|
|
|
UpdateAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
bool mpWindow::IsLayerVisible( const wxString& name ) const
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2023-08-02 15:26:17 +00:00
|
|
|
if( const mpLayer* lx = GetLayerByName( name ) )
|
|
|
|
return lx->IsVisible();
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2023-08-02 15:26:17 +00:00
|
|
|
return false;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpWindow::SetLayerVisible( const unsigned int position, bool viewable )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2023-08-02 15:26:17 +00:00
|
|
|
if( mpLayer* lx = GetLayer( position ) )
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
|
|
|
lx->SetVisible( viewable );
|
2016-08-11 12:41:21 +00:00
|
|
|
UpdateAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
bool mpWindow::IsLayerVisible( unsigned int position ) const
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2023-08-02 15:26:17 +00:00
|
|
|
if( const mpLayer* lx = GetLayer( position ) )
|
|
|
|
return lx->IsVisible();
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2023-08-02 15:26:17 +00:00
|
|
|
return false;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2021-08-03 16:53:30 +00:00
|
|
|
void mpWindow::SetColourTheme( const wxColour& bgColour, const wxColour& drawColour,
|
|
|
|
const wxColour& axesColour )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
SetBackgroundColour( bgColour );
|
|
|
|
SetForegroundColour( drawColour );
|
|
|
|
m_bgColour = bgColour;
|
|
|
|
m_fgColour = drawColour;
|
|
|
|
m_axColour = axesColour;
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
// Cycle between layers to set colours and properties to them
|
|
|
|
for( mpLayer* layer : m_layers )
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
2021-03-06 09:27:41 +00:00
|
|
|
if( layer->GetLayerType() == mpLAYER_AXIS )
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
2021-03-06 09:27:41 +00:00
|
|
|
wxPen axisPen = layer->GetPen(); // Get the old pen to modify only colour, not style or width
|
2016-08-12 08:10:33 +00:00
|
|
|
axisPen.SetColour( axesColour );
|
2021-03-06 09:27:41 +00:00
|
|
|
layer->SetPen( axisPen );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
if( layer->GetLayerType() == mpLAYER_INFO )
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
2021-03-06 09:27:41 +00:00
|
|
|
wxPen infoPen = layer->GetPen(); // Get the old pen to modify only colour, not style or width
|
2016-08-12 08:10:33 +00:00
|
|
|
infoPen.SetColour( drawColour );
|
2021-03-06 09:27:41 +00:00
|
|
|
layer->SetPen( infoPen );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2024-01-23 01:02:50 +00:00
|
|
|
template <typename... Ts>
|
|
|
|
mpWindow::mpWindow( DelegatingContructorTag, Ts&&... windowArgs ) :
|
|
|
|
wxWindow( std::forward<Ts>( windowArgs )... ),
|
|
|
|
m_minX( 0.0 ),
|
|
|
|
m_maxX( 0.0 ),
|
|
|
|
m_minY( 0.0 ),
|
|
|
|
m_maxY( 0.0 ),
|
|
|
|
m_scaleX( 1.0 ),
|
|
|
|
m_scaleY( 1.0 ),
|
|
|
|
m_posX( 0.0 ),
|
|
|
|
m_posY( 0.0 ),
|
|
|
|
m_scrX( 64 ),
|
|
|
|
m_scrY( 64 ),
|
|
|
|
m_clickedX( 0 ),
|
|
|
|
m_clickedY( 0 ),
|
|
|
|
m_yLocked( false ),
|
|
|
|
m_desiredXmin( 0.0 ),
|
|
|
|
m_desiredXmax( 1.0 ),
|
|
|
|
m_desiredYmin( 0.0 ),
|
|
|
|
m_desiredYmax( 1.0 ),
|
|
|
|
m_topBottomPlotGapFactor( 0.03 ),
|
|
|
|
m_leftRightPlotGapFactor( 0.0 ),
|
|
|
|
m_marginTop( 0 ),
|
|
|
|
m_marginRight( 0 ),
|
|
|
|
m_marginBottom( 0 ),
|
|
|
|
m_marginLeft( 0 ),
|
|
|
|
m_last_lx( 0 ),
|
|
|
|
m_last_ly( 0 ),
|
|
|
|
m_buff_bmp( nullptr ),
|
|
|
|
m_enableDoubleBuffer( false ),
|
|
|
|
m_enableMouseNavigation( true ),
|
|
|
|
m_enableLimitedView( false ),
|
|
|
|
m_mouseWheelActions( defaultMouseWheelActions() ),
|
|
|
|
m_movingInfoLayer( nullptr ),
|
|
|
|
m_zooming( false )
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
void mpWindow::initializeGraphicsContext()
|
|
|
|
{
|
|
|
|
if( wxGraphicsContext* ctx = m_buff_dc.GetGraphicsContext() )
|
|
|
|
{
|
|
|
|
if( !ctx->SetInterpolationQuality( wxINTERPOLATION_BEST )
|
|
|
|
|| !ctx->SetInterpolationQuality( wxINTERPOLATION_GOOD ) )
|
|
|
|
{
|
|
|
|
ctx->SetInterpolationQuality( wxINTERPOLATION_FAST );
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->SetAntialiasMode( wxANTIALIAS_DEFAULT );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2016-08-11 12:41:21 +00:00
|
|
|
// mpFXYVector implementation - by Jose Luis Blanco (AGO-2007)
|
2016-08-12 08:10:33 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
IMPLEMENT_DYNAMIC_CLASS( mpFXYVector, mpFXY )
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// Constructor
|
2023-03-19 22:01:47 +00:00
|
|
|
mpFXYVector::mpFXYVector( const wxString& name, int flags ) :
|
|
|
|
mpFXY( name, flags )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
m_index = 0;
|
2024-06-15 09:20:21 +00:00
|
|
|
m_sweepWindow = 0;
|
2016-08-11 12:41:21 +00:00
|
|
|
m_minX = -1;
|
|
|
|
m_maxX = 1;
|
|
|
|
m_minY = -1;
|
|
|
|
m_maxY = 1;
|
2016-08-12 08:10:33 +00:00
|
|
|
m_type = mpLAYER_PLOT;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
double mpScaleX::TransformToPlot( double x ) const
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
2016-08-11 12:41:49 +00:00
|
|
|
return (x + m_offset) * m_scale;
|
2016-08-11 12:41:48 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
double mpScaleX::TransformFromPlot( double xplot ) const
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
return xplot / m_scale - m_offset;
|
2016-08-11 12:41:48 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
double mpScaleY::TransformToPlot( double x ) const
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
2016-08-11 12:41:48 +00:00
|
|
|
return (x + m_offset) * m_scale;
|
2016-08-11 12:41:48 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
double mpScaleY::TransformFromPlot( double xplot ) const
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
return xplot / m_scale - m_offset;
|
2016-08-11 12:41:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
double mpScaleXLog::TransformToPlot( double x ) const
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
double xlogmin = log10( m_minV );
|
|
|
|
double xlogmax = log10( m_maxV );
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
return ( log10( x ) - xlogmin) / (xlogmax - xlogmin);
|
2016-08-11 12:41:48 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
double mpScaleXLog::TransformFromPlot( double xplot ) const
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
double xlogmin = log10( m_minV );
|
|
|
|
double xlogmax = log10( m_maxV );
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
return pow( 10.0, xplot * (xlogmax - xlogmin) + xlogmin );
|
2016-08-11 12:41:48 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
void mpFXYVector::Rewind()
|
|
|
|
{
|
|
|
|
m_index = 0;
|
2024-05-23 11:24:13 +00:00
|
|
|
m_sweepWindow = std::numeric_limits<size_t>::max();
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2023-08-02 15:26:17 +00:00
|
|
|
|
2024-05-23 11:24:13 +00:00
|
|
|
void mpFXYVector::SetSweepWindow( int aSweepIdx )
|
2019-11-19 16:17:37 +00:00
|
|
|
{
|
2024-05-23 11:24:13 +00:00
|
|
|
m_index = aSweepIdx * m_sweepSize;
|
|
|
|
m_sweepWindow = ( aSweepIdx + 1 ) * m_sweepSize;
|
2019-11-19 16:17:37 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
bool mpFXYVector::GetNextXY( double& x, double& y )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2024-05-23 11:24:13 +00:00
|
|
|
if( m_index >= m_xs.size() || m_index >= m_sweepWindow )
|
2018-10-04 20:33:32 +00:00
|
|
|
{
|
2016-11-28 14:37:00 +00:00
|
|
|
return false;
|
2018-10-04 20:33:32 +00:00
|
|
|
}
|
2016-08-11 12:41:21 +00:00
|
|
|
else
|
|
|
|
{
|
2018-10-04 20:33:32 +00:00
|
|
|
x = m_xs[m_index];
|
|
|
|
y = m_ys[m_index++];
|
2024-05-23 11:24:13 +00:00
|
|
|
return m_index <= m_xs.size() && m_index <= m_sweepWindow;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
void mpFXYVector::Clear()
|
|
|
|
{
|
|
|
|
m_xs.clear();
|
|
|
|
m_ys.clear();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpFXYVector::SetData( const std::vector<double>& xs, const std::vector<double>& ys )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2021-04-05 13:24:57 +00:00
|
|
|
// Check if the data vectors are of the same size
|
2016-08-12 08:10:33 +00:00
|
|
|
if( xs.size() != ys.size() )
|
2016-08-11 12:41:21 +00:00
|
|
|
return;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// Copy the data:
|
2016-08-12 08:10:33 +00:00
|
|
|
m_xs = xs;
|
|
|
|
m_ys = ys;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// Update internal variables for the bounding box.
|
2021-03-06 09:27:41 +00:00
|
|
|
if( xs.size() > 0 )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
m_minX = xs[0];
|
|
|
|
m_maxX = xs[0];
|
|
|
|
m_minY = ys[0];
|
|
|
|
m_maxY = ys[0];
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
for( const double x : xs )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2021-03-06 09:27:41 +00:00
|
|
|
if( x < m_minX )
|
|
|
|
m_minX = x;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
if( x > m_maxX )
|
|
|
|
m_maxX = x;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
for( const double y : ys )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2021-03-06 09:27:41 +00:00
|
|
|
if( y < m_minY )
|
|
|
|
m_minY = y;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
if( y > m_maxY )
|
|
|
|
m_maxY = y;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-18 15:23:38 +00:00
|
|
|
m_minX = 0;
|
|
|
|
m_maxX = 0;
|
|
|
|
m_minY = 0;
|
|
|
|
m_maxY = 0;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpFXY::SetScale( mpScaleBase* scaleX, mpScaleBase* scaleY )
|
2016-08-11 12:41:49 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
m_scaleX = scaleX;
|
|
|
|
m_scaleY = scaleY;
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2016-08-11 12:42:03 +00:00
|
|
|
UpdateScales();
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2016-08-11 12:42:03 +00:00
|
|
|
void mpFXY::UpdateScales()
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_scaleX )
|
|
|
|
m_scaleX->ExtendDataRange( GetMinX(), GetMaxX() );
|
2016-08-11 12:42:03 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_scaleY )
|
|
|
|
m_scaleY->ExtendDataRange( GetMinY(), GetMaxY() );
|
2016-08-11 12:41:49 +00:00
|
|
|
}
|
2016-08-11 12:41:55 +00:00
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double mpFXY::s2x( double plotCoordX ) const
|
2016-08-11 12:41:55 +00:00
|
|
|
{
|
2023-02-20 14:02:08 +00:00
|
|
|
return m_scaleX ? m_scaleX->TransformFromPlot( plotCoordX ) : plotCoordX;
|
2016-08-11 12:41:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double mpFXY::s2y( double plotCoordY ) const
|
2016-08-11 12:41:55 +00:00
|
|
|
{
|
2023-02-20 14:02:08 +00:00
|
|
|
return m_scaleY ? m_scaleY->TransformFromPlot( plotCoordY ) : plotCoordY;
|
2016-08-11 12:41:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double mpFXY::x2s( double x ) const
|
2016-08-11 12:41:55 +00:00
|
|
|
{
|
2023-02-20 14:02:08 +00:00
|
|
|
return m_scaleX ? m_scaleX->TransformToPlot( x ) : x;
|
2016-08-11 12:41:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double mpFXY::y2s( double y ) const
|
2016-08-11 12:41:55 +00:00
|
|
|
{
|
2023-02-20 14:02:08 +00:00
|
|
|
return m_scaleY ? m_scaleY->TransformToPlot( y ) : y;
|
2016-08-11 12:41:55 +00:00
|
|
|
}
|