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
|
2016-08-29 09:39:54 +00:00
|
|
|
// Last edit: 25/08/2016
|
2016-08-11 12:41:21 +00:00
|
|
|
// Copyright: (c) David Schalig, Davide Rondini
|
|
|
|
// 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
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
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;
|
|
|
|
pointList.reserve( endPx - startPx + 1 );
|
|
|
|
|
|
|
|
// Note: we can use dc.DrawLines() only for a reasonable number or points (<10000),
|
|
|
|
// because at least on Windows dc.DrawLines() can hang for a lot of points.
|
|
|
|
// (> 10000 points) (can happens when a lot of points is calculated)
|
|
|
|
// To avoid long draw time (and perhaps hanging) one plot only not redundant lines.
|
|
|
|
// To avoid artifacts when skipping points to the same x coordinate, for each group of
|
|
|
|
// points at a give, x coordinate we also draw a vertical line at this coord, from the
|
|
|
|
// ymin to the ymax vertical coordinates of skipped points
|
|
|
|
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 );
|
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-02-26 21:50:43 +00:00
|
|
|
// Store only points on the drawing area, to speed up the drawing time
|
|
|
|
// 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
|
|
|
|
if( x1 >= startPx-1 && x1 <= endPx )
|
|
|
|
{
|
|
|
|
if( !count || line_start.x != x1 )
|
2020-07-27 08:47:52 +00:00
|
|
|
{
|
2023-07-02 20:15:50 +00:00
|
|
|
#ifndef __WXMAC__ // Drawing the vertical lines spoils anti-aliasing on Retina displays
|
2023-02-26 21:50:43 +00:00
|
|
|
if( count && dupx0 > 1 && ymin0 != ymax0 )
|
2020-07-27 08:47:52 +00:00
|
|
|
{
|
2023-02-26 21:50:43 +00:00
|
|
|
// Vertical points are merged, draw the pending vertical line
|
|
|
|
// However, if the line is one pixel length, it is not drawn, because
|
|
|
|
// the main trace show this point
|
|
|
|
dc.DrawLine( x0, ymin0, x0, ymax0 );
|
2020-07-27 08:47:52 +00:00
|
|
|
}
|
2023-07-17 21:28:05 +00:00
|
|
|
#else
|
|
|
|
if( x0 ) { }; // Quiet CLang
|
2023-07-02 20:15:50 +00:00
|
|
|
#endif
|
2020-08-24 16:40:38 +00:00
|
|
|
|
2023-02-26 21:50:43 +00:00
|
|
|
x0 = x1;
|
|
|
|
ymin0 = ymax0 = y1;
|
|
|
|
dupx0 = 0;
|
2020-08-24 16:40:38 +00:00
|
|
|
|
2023-02-26 21:50:43 +00:00
|
|
|
pointList.emplace_back( wxPoint( x1, y1 ) );
|
2020-08-24 16:40:38 +00:00
|
|
|
|
2023-02-26 21:50:43 +00:00
|
|
|
line_start.x = x1;
|
|
|
|
line_start.y = y1;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
else
|
2020-08-24 16:40:38 +00:00
|
|
|
{
|
2023-02-26 21:50:43 +00:00
|
|
|
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-02-26 21:50:43 +00:00
|
|
|
// For a better look (when using dashed lines) and more optimization, try to merge
|
|
|
|
// horizontal segments, in order to plot longer lines
|
|
|
|
// We are merging horizontal segments because this is easy, and horizontal segments
|
|
|
|
// are a frequent cases
|
|
|
|
std::vector<wxPoint> drawPoints;
|
|
|
|
drawPoints.reserve( endPx - startPx + 1 );
|
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] );
|
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() );
|
|
|
|
|
|
|
|
dc.DrawLines( 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.
|
|
|
|
while( visibleDecades - 2 >= m_scrX / 96 )
|
|
|
|
{
|
|
|
|
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 )
|
|
|
|
EVT_MOUSEWHEEL( mpWindow::OnMouseWheel ) // JLB
|
2019-11-19 14:58:32 +00:00
|
|
|
EVT_MAGNIFY( mpWindow::OnMagnify )
|
2016-08-12 08:10:33 +00:00
|
|
|
EVT_MOTION( mpWindow::OnMouseMove ) // JLB
|
|
|
|
EVT_LEFT_DOWN( mpWindow::OnMouseLeftDown )
|
|
|
|
EVT_LEFT_UP( mpWindow::OnMouseLeftRelease )
|
|
|
|
|
|
|
|
EVT_MENU( mpID_CENTER, mpWindow::OnCenter )
|
|
|
|
EVT_MENU( mpID_FIT, mpWindow::OnFit )
|
|
|
|
EVT_MENU( mpID_ZOOM_IN, mpWindow::OnZoomIn )
|
|
|
|
EVT_MENU( mpID_ZOOM_OUT, mpWindow::OnZoomOut )
|
2016-08-11 12:41:21 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2023-03-19 22:01:47 +00:00
|
|
|
mpWindow::mpWindow() :
|
|
|
|
wxWindow(),
|
2020-09-22 11:29:13 +00:00
|
|
|
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 ),
|
2023-07-19 15:25:57 +00:00
|
|
|
m_yLocked( false ),
|
2020-09-22 11:29:13 +00:00
|
|
|
m_desiredXmin( 0.0 ),
|
|
|
|
m_desiredXmax( 1.0 ),
|
|
|
|
m_desiredYmin( 0.0 ),
|
|
|
|
m_desiredYmax( 1.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_enableMouseWheelPan( false ),
|
|
|
|
m_enableLimitedView( false ),
|
|
|
|
m_movingInfoLayer( nullptr ),
|
|
|
|
m_zooming( false )
|
|
|
|
{
|
2022-12-21 20:02:35 +00:00
|
|
|
if( wxGraphicsContext *ctx = m_buff_dc.GetGraphicsContext() )
|
|
|
|
{
|
|
|
|
if( !ctx->SetInterpolationQuality( wxINTERPOLATION_BEST )
|
|
|
|
|| !ctx->SetInterpolationQuality( wxINTERPOLATION_GOOD ) )
|
|
|
|
{
|
|
|
|
ctx->SetInterpolationQuality( wxINTERPOLATION_FAST );
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->SetAntialiasMode( wxANTIALIAS_DEFAULT );
|
|
|
|
}
|
2020-09-22 11:29:13 +00:00
|
|
|
}
|
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
mpWindow::mpWindow( wxWindow* parent, wxWindowID id ) :
|
|
|
|
wxWindow( parent, id, wxDefaultPosition, wxDefaultSize, 0, wxT( "mathplot" ) )
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
|
|
|
m_zooming = false;
|
|
|
|
m_scaleX = m_scaleY = 1.0;
|
|
|
|
m_posX = m_posY = 0;
|
|
|
|
m_desiredXmin = m_desiredYmin = 0;
|
|
|
|
m_desiredXmax = m_desiredYmax = 1;
|
|
|
|
m_scrX = m_scrY = 64; // Fixed from m_scrX = m_scrX = 64;
|
|
|
|
m_minX = m_minY = 0;
|
|
|
|
m_maxX = m_maxY = 0;
|
|
|
|
m_last_lx = m_last_ly = 0;
|
2023-02-19 05:38:42 +00:00
|
|
|
m_buff_bmp = nullptr;
|
2016-11-28 14:37:00 +00:00
|
|
|
m_enableDoubleBuffer = false;
|
|
|
|
m_enableMouseNavigation = true;
|
|
|
|
m_enableLimitedView = false;
|
2023-02-19 05:38:42 +00:00
|
|
|
m_movingInfoLayer = nullptr;
|
2016-08-11 12:41:21 +00:00
|
|
|
// Set margins to 0
|
|
|
|
m_marginTop = 0; m_marginRight = 0; m_marginBottom = 0; m_marginLeft = 0;
|
|
|
|
|
2022-10-03 19:47:45 +00:00
|
|
|
m_popmenu.Append( mpID_CENTER, _( "Center on Cursor" ), _( "Center plot view to this position" ) );
|
2016-08-29 09:39:54 +00:00
|
|
|
m_popmenu.Append( mpID_FIT, _( "Fit on Screen" ), _( "Set plot view to show all items" ) );
|
|
|
|
m_popmenu.Append( mpID_ZOOM_IN, _( "Zoom In" ), _( "Zoom in plot view." ) );
|
|
|
|
m_popmenu.Append( mpID_ZOOM_OUT, _( "Zoom Out" ), _( "Zoom out plot view." ) );
|
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 );
|
|
|
|
|
2022-12-21 20:02:35 +00:00
|
|
|
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-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
|
|
|
|
2019-11-19 14:58:32 +00:00
|
|
|
void mpWindow::OnMagnify( wxMouseEvent& event )
|
|
|
|
{
|
|
|
|
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
|
2016-08-12 08:10:33 +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;
|
|
|
|
}
|
|
|
|
|
2019-11-19 14:58:32 +00:00
|
|
|
int change = event.GetWheelRotation();
|
|
|
|
const int axis = event.GetWheelAxis();
|
|
|
|
double changeUnitsX = change / m_scaleX;
|
|
|
|
double changeUnitsY = change / m_scaleY;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2019-11-19 14:58:32 +00:00
|
|
|
if( ( !m_enableMouseWheelPan && ( event.ControlDown() || event.ShiftDown() ) )
|
|
|
|
|| ( m_enableMouseWheelPan && !event.ControlDown() ) )
|
2016-08-11 12:41:27 +00:00
|
|
|
{
|
2019-11-19 14:58:32 +00:00
|
|
|
// Scrolling
|
|
|
|
if( m_enableMouseWheelPan )
|
|
|
|
{
|
|
|
|
if( axis == wxMOUSE_WHEEL_HORIZONTAL || event.ShiftDown() )
|
2023-07-18 10:56:36 +00:00
|
|
|
{
|
2019-11-19 14:58:32 +00:00
|
|
|
SetXView( m_posX + changeUnitsX, m_desiredXmax + changeUnitsX,
|
2023-07-18 10:56:36 +00:00
|
|
|
m_desiredXmin + changeUnitsX );
|
|
|
|
}
|
2023-07-19 15:25:57 +00:00
|
|
|
else if( !m_yLocked )
|
2023-07-18 10:56:36 +00:00
|
|
|
{
|
2019-11-19 14:58:32 +00:00
|
|
|
SetYView( m_posY + changeUnitsY, m_desiredYmax + changeUnitsY,
|
2023-07-18 10:56:36 +00:00
|
|
|
m_desiredYmin + changeUnitsY );
|
|
|
|
}
|
2019-11-19 14:58:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( event.ControlDown() )
|
2023-07-18 10:56:36 +00:00
|
|
|
{
|
2019-11-19 14:58:32 +00:00
|
|
|
SetXView( m_posX + changeUnitsX, m_desiredXmax + changeUnitsX,
|
2023-07-18 10:56:36 +00:00
|
|
|
m_desiredXmin + changeUnitsX );
|
|
|
|
}
|
2023-07-19 15:25:57 +00:00
|
|
|
else if( !m_yLocked )
|
2023-07-18 10:56:36 +00:00
|
|
|
{
|
2019-11-19 14:58:32 +00:00
|
|
|
SetYView( m_posY + changeUnitsY, m_desiredYmax + changeUnitsY,
|
2023-07-18 10:56:36 +00:00
|
|
|
m_desiredYmin + changeUnitsY );
|
|
|
|
}
|
2019-11-19 14:58:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UpdateAll();
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-11 12:41:27 +00:00
|
|
|
// zoom in/out
|
2016-08-12 08:10:33 +00:00
|
|
|
wxPoint clickPt( event.GetX(), event.GetY() );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( event.GetWheelRotation() > 0 )
|
2016-08-11 12:41:27 +00:00
|
|
|
ZoomIn( clickPt );
|
2016-08-11 12:41:21 +00:00
|
|
|
else
|
2016-08-11 12:41:27 +00:00
|
|
|
ZoomOut( clickPt );
|
|
|
|
|
2019-11-19 14:58:32 +00:00
|
|
|
return;
|
|
|
|
}
|
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
|
2016-08-12 08:10:33 +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
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double Ax_units = Ax / m_scaleX;
|
|
|
|
double Ay_units = -Ay / m_scaleY;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2023-07-18 10:56:36 +00:00
|
|
|
if( SetXView( m_posX + Ax_units, m_desiredXmax + Ax_units, m_desiredXmin + Ax_units )
|
|
|
|
|| SetYView( m_posY + Ay_units, m_desiredYmax + Ay_units, m_desiredYmin + Ay_units ) )
|
|
|
|
{
|
2016-08-11 12:41:37 +00:00
|
|
|
UpdateAll();
|
2023-07-18 10:56:36 +00:00
|
|
|
}
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
2016-11-28 14:37:00 +00:00
|
|
|
void mpWindow::Fit( double xMin, double xMax, double yMin, double yMax,
|
2023-07-18 10:56:36 +00:00
|
|
|
const wxCoord* printSizeX, const wxCoord* printSizeY )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-11-28 14:37:00 +00:00
|
|
|
// Save desired borders:
|
|
|
|
m_desiredXmin = xMin; m_desiredXmax = xMax;
|
|
|
|
m_desiredYmin = yMin; m_desiredYmax = yMax;
|
|
|
|
|
|
|
|
// Give a small margin to plot area
|
2016-08-12 08:10:33 +00:00
|
|
|
double xExtra = fabs( xMax - xMin ) * 0.00;
|
|
|
|
double yExtra = fabs( yMax - yMin ) * 0.03;
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
xMin -= xExtra;
|
|
|
|
xMax += xExtra;
|
|
|
|
yMin -= yExtra;
|
|
|
|
yMax += yExtra;
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2023-02-19 05:38:42 +00:00
|
|
|
if( printSizeX != nullptr && printSizeY != nullptr )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
// Printer:
|
2016-08-12 08:10:33 +00:00
|
|
|
m_scrX = *printSizeX;
|
|
|
|
m_scrY = *printSizeY;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Normal case (screen):
|
2016-08-12 08:10:33 +00:00
|
|
|
GetClientSize( &m_scrX, &m_scrY );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2023-07-18 10:56:36 +00:00
|
|
|
double Ax = xMax - xMin;
|
|
|
|
double Ay = yMax - yMin;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2023-07-18 10:56:36 +00:00
|
|
|
m_scaleX = (Ax != 0) ? (m_scrX - m_marginLeft - m_marginRight) / Ax : 1;
|
|
|
|
m_scaleY = (Ay != 0) ? (m_scrY - m_marginTop - m_marginBottom) / Ay : 1;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// Adjusts corner coordinates: This should be simply:
|
2016-08-12 08:10:33 +00:00
|
|
|
// m_posX = m_minX;
|
|
|
|
// m_posY = m_maxY;
|
2016-08-11 12:41:21 +00:00
|
|
|
// But account for centering if we have lock aspect:
|
2016-08-12 08:10:33 +00:00
|
|
|
m_posX = (xMin + xMax) / 2 - ( (m_scrX - m_marginLeft - m_marginRight) / 2 + m_marginLeft ) /
|
2023-07-18 10:56:36 +00:00
|
|
|
m_scaleX;
|
2016-08-12 08:10:33 +00:00
|
|
|
m_posY = (yMin + yMax) / 2 + ( (m_scrY - m_marginTop - m_marginBottom) / 2 + m_marginTop ) /
|
2023-07-18 10:56:36 +00:00
|
|
|
m_scaleY;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// It is VERY IMPORTANT to DO NOT call Refresh if we are drawing to the printer!!
|
|
|
|
// Otherwise, the DC dimensions will be those of the window instead of the printer device
|
2023-02-19 05:38:42 +00:00
|
|
|
if( printSizeX == nullptr || printSizeY == nullptr )
|
2016-08-11 12:41:21 +00:00
|
|
|
UpdateAll();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:42:08 +00:00
|
|
|
void mpWindow::AdjustLimitedView()
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( !m_enableLimitedView )
|
2016-08-11 12:42:08 +00:00
|
|
|
return;
|
|
|
|
|
2019-09-26 14:29:52 +00:00
|
|
|
// m_min and m_max are plot limits for curves
|
|
|
|
// xMin, xMax, yMin, yMax are the full limits (plot limit + margin)
|
2016-08-12 08:10:33 +00:00
|
|
|
const double xMin = m_minX - m_marginLeft / m_scaleX;
|
2019-09-26 14:29:52 +00:00
|
|
|
const double xMax = m_maxX + m_marginRight / m_scaleX;
|
|
|
|
const double yMin = m_minY - m_marginTop / m_scaleY;
|
2016-08-12 08:10:33 +00:00
|
|
|
const double yMax = m_maxY + m_marginBottom / m_scaleY;
|
2016-08-11 12:42:08 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_desiredXmin < xMin )
|
2016-08-11 12:42:08 +00:00
|
|
|
{
|
|
|
|
double diff = xMin - m_desiredXmin;
|
|
|
|
m_posX += diff;
|
2016-08-12 08:10:33 +00:00
|
|
|
m_desiredXmax += diff;
|
|
|
|
m_desiredXmin = xMin;
|
2016-08-11 12:42:08 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_desiredXmax > xMax )
|
2016-08-11 12:42:08 +00:00
|
|
|
{
|
|
|
|
double diff = m_desiredXmax - xMax;
|
|
|
|
m_posX -= diff;
|
2016-08-12 08:10:33 +00:00
|
|
|
m_desiredXmin -= diff;
|
|
|
|
m_desiredXmax = xMax;
|
2016-08-11 12:42:08 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_desiredYmin < yMin )
|
2016-08-11 12:42:08 +00:00
|
|
|
{
|
|
|
|
double diff = yMin - m_desiredYmin;
|
|
|
|
m_posY += diff;
|
2016-08-12 08:10:33 +00:00
|
|
|
m_desiredYmax += diff;
|
|
|
|
m_desiredYmin = yMin;
|
2016-08-11 12:42:08 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_desiredYmax > yMax )
|
2016-08-11 12:42:08 +00:00
|
|
|
{
|
|
|
|
double diff = m_desiredYmax - yMax;
|
|
|
|
m_posY -= diff;
|
2016-08-12 08:10:33 +00:00
|
|
|
m_desiredYmin -= diff;
|
|
|
|
m_desiredYmax = yMax;
|
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
|
|
|
{
|
|
|
|
m_posX = pos;
|
2016-08-12 08:10:33 +00:00
|
|
|
m_desiredXmax = desiredMax;
|
|
|
|
m_desiredXmin = desiredMin;
|
2016-08-11 12:42:08 +00:00
|
|
|
AdjustLimitedView();
|
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;
|
2016-08-11 12:42:08 +00:00
|
|
|
AdjustLimitedView();
|
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
|
|
|
{
|
|
|
|
ZoomIn( centerPoint, zoomIncrementalFactor );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void mpWindow::ZoomIn( const wxPoint& centerPoint, double zoomFactor )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
wxPoint c( centerPoint );
|
|
|
|
|
|
|
|
if( c == wxDefaultPosition )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
GetClientSize( &m_scrX, &m_scrY );
|
|
|
|
c.x = (m_scrX - m_marginLeft - m_marginRight) / 2 + m_marginLeft; // c.x = m_scrX/2;
|
|
|
|
c.y = (m_scrY - m_marginTop - m_marginBottom) / 2 - m_marginTop; // c.y = m_scrY/2;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-11 12:42:08 +00:00
|
|
|
else
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
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 );
|
2016-08-11 12:42:08 +00:00
|
|
|
}
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// Preserve the position of the clicked point:
|
2016-08-12 08:10:33 +00:00
|
|
|
double prior_layer_x = p2x( c.x );
|
|
|
|
double prior_layer_y = p2y( c.y );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// Zoom in:
|
2016-08-11 12:41:37 +00:00
|
|
|
const double MAX_SCALE = 1e6;
|
2019-11-19 14:58:32 +00:00
|
|
|
double newScaleX = m_scaleX * zoomFactor;
|
|
|
|
double newScaleY = m_scaleY * zoomFactor;
|
2016-08-11 12:41:37 +00:00
|
|
|
|
|
|
|
// Baaaaad things happen when you zoom in too much..
|
2016-08-12 08:10:33 +00:00
|
|
|
if( newScaleX <= MAX_SCALE && newScaleY <= MAX_SCALE )
|
2016-08-11 12:41:37 +00:00
|
|
|
{
|
2023-07-19 15:25:57 +00:00
|
|
|
m_scaleX = newScaleX;
|
|
|
|
|
|
|
|
if( !m_yLocked )
|
|
|
|
m_scaleY = newScaleY;
|
2016-08-11 12:41:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// Adjust the new m_posx/y:
|
2023-07-19 15:25:57 +00:00
|
|
|
m_posX = prior_layer_x - c.x / m_scaleX;
|
|
|
|
|
|
|
|
if( !m_yLocked )
|
|
|
|
m_posY = prior_layer_y + c.y / m_scaleY;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
m_desiredXmin = m_posX;
|
2023-07-18 10:56:36 +00:00
|
|
|
m_desiredXmax = m_posX + (m_scrX - m_marginLeft - m_marginRight) / m_scaleX;
|
2016-08-12 08:10:33 +00:00
|
|
|
m_desiredYmax = m_posY;
|
2023-07-18 10:56:36 +00:00
|
|
|
m_desiredYmin = m_posY - (m_scrY - m_marginTop - m_marginBottom) / m_scaleY;
|
2016-08-11 12:42:08 +00:00
|
|
|
AdjustLimitedView();
|
2016-08-11 12:41:21 +00:00
|
|
|
UpdateAll();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpWindow::ZoomOut( const wxPoint& centerPoint )
|
2019-11-19 14:58:32 +00:00
|
|
|
{
|
|
|
|
ZoomOut( centerPoint, zoomIncrementalFactor );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void mpWindow::ZoomOut( const wxPoint& centerPoint, double zoomFactor )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
wxPoint c( centerPoint );
|
|
|
|
|
|
|
|
if( c == wxDefaultPosition )
|
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
|
|
|
c.x = (m_scrX - m_marginLeft - m_marginRight) / 2 + m_marginLeft;
|
|
|
|
c.y = (m_scrY - m_marginTop - m_marginBottom) / 2 - m_marginTop;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Preserve the position of the clicked point:
|
2016-08-12 08:10:33 +00:00
|
|
|
double prior_layer_x = p2x( c.x );
|
|
|
|
double prior_layer_y = p2y( c.y );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// Zoom out:
|
2019-11-19 14:58:32 +00:00
|
|
|
m_scaleX = m_scaleX / zoomFactor;
|
2023-07-19 15:25:57 +00:00
|
|
|
|
|
|
|
if( !m_yLocked )
|
|
|
|
m_scaleY = m_scaleY / zoomFactor;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// Adjust the new m_posx/y:
|
2023-07-19 15:25:57 +00:00
|
|
|
m_posX = prior_layer_x - c.x / m_scaleX;
|
|
|
|
|
|
|
|
if( !m_yLocked )
|
|
|
|
m_posY = prior_layer_y + c.y / m_scaleY;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
m_desiredXmin = m_posX;
|
2023-07-18 10:56:36 +00:00
|
|
|
m_desiredXmax = m_posX + (m_scrX - m_marginLeft - m_marginRight) / m_scaleX;
|
2016-08-12 08:10:33 +00:00
|
|
|
m_desiredYmax = m_posY;
|
2023-07-18 10:56:36 +00:00
|
|
|
m_desiredYmin = m_posY - (m_scrY - m_marginTop - m_marginBottom) / m_scaleY;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2023-02-12 19:54:28 +00:00
|
|
|
if( !CheckXLimits( m_desiredXmax, m_desiredXmin )
|
|
|
|
|| !CheckYLimits( m_desiredYmax, m_desiredYmin ) )
|
2016-08-11 12:41:37 +00:00
|
|
|
{
|
|
|
|
Fit();
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
UpdateAll();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpWindow::ZoomRect( wxPoint p0, wxPoint p1 )
|
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 );
|
2016-08-11 12:42:08 +00:00
|
|
|
AdjustLimitedView();
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
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
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
void mpWindow::OnZoomOut( wxCommandEvent& WXUNUSED( event ) )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
ZoomOut();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2021-08-03 16:53:30 +00:00
|
|
|
bool mpWindow::SaveScreenshot( const wxString& filename, wxBitmapType type, wxSize imageSize,
|
|
|
|
bool fit )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
int sizeX, sizeY;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
if( imageSize == wxDefaultSize )
|
|
|
|
{
|
2023-04-11 08:53:35 +00:00
|
|
|
sizeX = m_scrX;
|
|
|
|
sizeY = m_scrY;
|
2016-08-12 08:10:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-04-11 08:53:35 +00:00
|
|
|
sizeX = imageSize.x;
|
|
|
|
sizeY = imageSize.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
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( fit )
|
|
|
|
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
|
|
|
|
|
|
|
if( imageSize != wxDefaultSize )
|
|
|
|
{
|
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
|
|
|
|
wxImage screenImage = screenBuffer.ConvertToImage();
|
2016-08-12 08:10:33 +00:00
|
|
|
return screenImage.SaveFile( filename, type );
|
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
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
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;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-08-02 15:26:17 +00:00
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
size_t mpFXYVector::GetCount() const
|
2019-11-19 16:17:37 +00:00
|
|
|
{
|
|
|
|
return m_xs.size();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
bool mpFXYVector::GetNextXY( double& x, double& y )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2018-10-04 20:33:32 +00:00
|
|
|
if( m_index >= m_xs.size() )
|
|
|
|
{
|
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++];
|
|
|
|
return m_index <= m_xs.size();
|
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
|
|
|
}
|