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-12 08:10:33 +00:00
|
|
|
// Last edit: 12/08/2016
|
2016-08-11 12:41:21 +00:00
|
|
|
// Copyright: (c) David Schalig, Davide Rondini
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
// #pragma implementation "plot.h"
|
|
|
|
#pragma implementation "mathplot.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx.h".
|
|
|
|
#include <wx/window.h>
|
2016-08-12 08:10:33 +00:00
|
|
|
// #include <wx/wxprec.h>
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// 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/settings.h"
|
|
|
|
#include "wx/sizer.h"
|
|
|
|
#include "wx/log.h"
|
|
|
|
#include "wx/intl.h"
|
|
|
|
#include "wx/dcclient.h"
|
|
|
|
#include "wx/cursor.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <widgets/mathplot.h>
|
|
|
|
#include <wx/bmpbuttn.h>
|
|
|
|
#include <wx/module.h>
|
|
|
|
#include <wx/msgdlg.h>
|
|
|
|
#include <wx/image.h>
|
|
|
|
#include <wx/tipwin.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
|
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
|
|
|
|
|
|
|
// Minimum axis label separation
|
2016-08-12 08:10:33 +00:00
|
|
|
#define mpMIN_X_AXIS_LABEL_SEPARATION 64
|
|
|
|
#define mpMIN_Y_AXIS_LABEL_SEPARATION 32
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// Number of pixels to scroll when scrolling by a line
|
2016-08-12 08:10:33 +00:00
|
|
|
#define mpSCROLL_NUM_PIXELS_PER_LINE 10
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// See doxygen comments.
|
|
|
|
double mpWindow::zoomIncrementalFactor = 1.5;
|
|
|
|
|
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
|
|
|
|
2016-08-12 08:10:33 +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 );
|
|
|
|
m_continuous = FALSE; // Default
|
|
|
|
m_showName = TRUE; // Default
|
2016-08-11 12:41:48 +00:00
|
|
|
m_drawOutsideMargins = FALSE;
|
2016-08-11 12:41:21 +00:00
|
|
|
m_visible = true;
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
wxBitmap mpLayer::GetColourSquare( int side )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
wxBitmap square( side, side, -1 );
|
|
|
|
wxColour filler = m_pen.GetColour();
|
|
|
|
wxBrush brush( filler, wxBRUSHSTYLE_SOLID );
|
2016-08-11 12:41:21 +00:00
|
|
|
wxMemoryDC dc;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
dc.SelectObject( square );
|
|
|
|
dc.SetBackground( brush );
|
2016-08-11 12:41:21 +00:00
|
|
|
dc.Clear();
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.SelectObject( wxNullBitmap );
|
2016-08-11 12:41:21 +00:00
|
|
|
return square;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
void mpInfoLayer::UpdateInfo( mpWindow& w, wxEvent& event )
|
|
|
|
{
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
bool mpInfoLayer::Inside( wxPoint& point )
|
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) )
|
|
|
|
{
|
2016-08-11 12:41:21 +00:00
|
|
|
#ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
// wxLogMessage( "mpInfoLayer::Plot() screen size has changed from %d x %d to %d x %d", m_winX, m_winY, scrx, scry);
|
2016-08-11 12:41:21 +00:00
|
|
|
#endif
|
2016-08-11 12:41:26 +00:00
|
|
|
|
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.SetPen( m_pen );
|
|
|
|
// wxImage image0(wxT("pixel.png"), wxBITMAP_TYPE_PNG);
|
|
|
|
// wxBitmap image1(image0);
|
|
|
|
// wxBrush semiWhite(image1);
|
|
|
|
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
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
wxPoint mpInfoLayer::GetPosition()
|
|
|
|
{
|
|
|
|
return m_dim.GetPosition();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
wxSize mpInfoLayer::GetSize()
|
|
|
|
{
|
|
|
|
return m_dim.GetSize();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
mpInfoCoords::mpInfoCoords() : mpInfoLayer()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
mpInfoCoords::mpInfoCoords( wxRect rect, const wxBrush* brush ) : mpInfoLayer( rect, brush )
|
|
|
|
{
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
mpInfoCoords::~mpInfoCoords()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpInfoCoords::UpdateInfo( mpWindow& w, wxEvent& event )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( event.GetEventType() == wxEVT_MOTION )
|
|
|
|
{
|
2016-08-11 12:41:21 +00:00
|
|
|
/* It seems that Windows port of wxWidgets don't support multi-line test to be drawn in a wxDC.
|
2016-08-12 08:10:33 +00:00
|
|
|
* wxGTK instead works perfectly with it.
|
|
|
|
* Info on wxForum: http://wxforum.shadonet.com/viewtopic.php?t=3451&highlight=drawtext+eol */
|
2016-08-11 12:41:21 +00:00
|
|
|
#ifdef _WINDOWS
|
2016-08-11 12:41:48 +00:00
|
|
|
// FIXME m_content.Printf(wxT("x = %f y = %f"), XScale().P2x(w, mouseX), YScale().P2x(w, mouseY));
|
2016-08-11 12:41:21 +00:00
|
|
|
#else
|
2016-08-12 08:10:33 +00:00
|
|
|
// FIXME m_content.Printf(wxT("x = %f\ny = %f"), XScale().P2x(w, mouseX), YScale().P2x(w, mouseY));
|
2016-08-11 12:41:21 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpInfoCoords::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();
|
|
|
|
|
|
|
|
if( (m_winX != scrx) || (m_winY != scry) )
|
|
|
|
{
|
2016-08-11 12:41:21 +00:00
|
|
|
#ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
// wxLogMessage( "mpInfoLayer::Plot() screen size has changed from %d x %d to %d x %d", m_winX, m_winY, scrx, scry);
|
2016-08-11 12:41:21 +00:00
|
|
|
#endif
|
2016-08-11 12:41:26 +00:00
|
|
|
|
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.SetPen( m_pen );
|
|
|
|
// wxImage image0(wxT("pixel.png"), wxBITMAP_TYPE_PNG);
|
|
|
|
// wxBitmap image1(image0);
|
|
|
|
// wxBrush semiWhite(image1);
|
|
|
|
dc.SetBrush( m_brush );
|
|
|
|
dc.SetFont( m_font );
|
2016-08-11 12:41:21 +00:00
|
|
|
int textX, textY;
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.GetTextExtent( m_content, &textX, &textY );
|
|
|
|
|
|
|
|
if( m_dim.width < textX + 10 )
|
|
|
|
m_dim.width = textX + 10;
|
|
|
|
|
|
|
|
if( m_dim.height < textY + 10 )
|
|
|
|
m_dim.height = textY + 10;
|
|
|
|
|
|
|
|
dc.DrawRectangle( m_dim.x, m_dim.y, m_dim.width, m_dim.height );
|
|
|
|
dc.DrawText( m_content, m_dim.x + 5, m_dim.y + 5 );
|
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() : mpInfoLayer()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
mpInfoLegend::mpInfoLegend( wxRect rect, const wxBrush* brush ) : mpInfoLayer( rect, brush )
|
|
|
|
{
|
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::UpdateInfo( mpWindow& w, wxEvent& event )
|
|
|
|
{
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
if( (m_winX != scrx) || (m_winY != scry) )
|
|
|
|
{
|
2016-08-11 12:41:21 +00:00
|
|
|
#ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
// wxLogMessage( "mpInfoLayer::Plot() screen size has changed from %d x %d to %d x %d", m_winX, m_winY, scrx, scry);
|
2016-08-11 12:41:21 +00:00
|
|
|
#endif
|
2016-08-11 12:41:26 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
// wxImage image0(wxT("pixel.png"), wxBITMAP_TYPE_PNG);
|
|
|
|
// wxBitmap image1(image0);
|
|
|
|
// wxBrush semiWhite(image1);
|
|
|
|
dc.SetBrush( m_brush );
|
|
|
|
dc.SetFont( m_font );
|
|
|
|
const int baseWidth = (mpLEGEND_MARGIN * 2 + mpLEGEND_LINEWIDTH);
|
2016-08-11 12:41:21 +00:00
|
|
|
int textX = baseWidth, textY = mpLEGEND_MARGIN;
|
|
|
|
int plotCount = 0;
|
2016-08-12 08:10:33 +00:00
|
|
|
int posY = 0;
|
|
|
|
int tmpX = 0, tmpY = 0;
|
2016-08-11 12:41:21 +00:00
|
|
|
mpLayer* ly = NULL;
|
|
|
|
wxPen lpen;
|
|
|
|
wxString label;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
for( unsigned int p = 0; p < w.CountAllLayers(); p++ )
|
|
|
|
{
|
|
|
|
ly = w.GetLayer( p );
|
|
|
|
|
|
|
|
if( (ly->GetLayerType() == mpLAYER_PLOT) && ( ly->IsVisible() ) )
|
|
|
|
{
|
2016-08-11 12:41:21 +00:00
|
|
|
label = ly->GetName();
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.GetTextExtent( label, &tmpX, &tmpY );
|
|
|
|
textX =
|
|
|
|
( textX > (tmpX + baseWidth) ) ? textX : (tmpX + baseWidth + mpLEGEND_MARGIN);
|
2016-08-11 12:41:21 +00:00
|
|
|
textY += (tmpY);
|
|
|
|
#ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
// wxLogMessage( "mpInfoLegend::Plot() Adding layer %d: %s", p, label.c_str());
|
2016-08-11 12:41:21 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
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++ )
|
|
|
|
{
|
|
|
|
ly = w.GetLayer( p2 );
|
|
|
|
|
|
|
|
if( (ly->GetLayerType() == mpLAYER_PLOT) && ( ly->IsVisible() ) )
|
|
|
|
{
|
|
|
|
label = ly->GetName();
|
|
|
|
lpen = ly->GetPen();
|
|
|
|
dc.GetTextExtent( label, &tmpX, &tmpY );
|
|
|
|
dc.SetPen( lpen );
|
|
|
|
// textX = (textX > (tmpX + baseWidth)) ? textX : (tmpX + baseWidth);
|
|
|
|
// textY += (tmpY + mpLEGEND_MARGIN);
|
|
|
|
posY = m_dim.y + mpLEGEND_MARGIN + plotCount * tmpY + (tmpY >> 1);
|
|
|
|
dc.DrawLine( m_dim.x + mpLEGEND_MARGIN, // X start coord
|
|
|
|
posY, // Y start coord
|
2016-08-11 12:41:21 +00:00
|
|
|
m_dim.x + mpLEGEND_LINEWIDTH + mpLEGEND_MARGIN, // X end coord
|
2016-08-12 08:10:33 +00:00
|
|
|
posY );
|
|
|
|
// dc.DrawRectangle(m_dim.x + 5, m_dim.y + 5 + plotCount*tmpY, 5, 5);
|
|
|
|
dc.DrawText( label,
|
|
|
|
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:48 +00:00
|
|
|
#if 0
|
2016-08-12 08:10:33 +00:00
|
|
|
double mpScaleXLog::X2p( mpWindow& w, double x )
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
|
|
|
return ( x - w.GetPosX() ) * w.GetScaleX();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
double mpScaleXLog::P2x( mpWindow& w, double x )
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
|
|
|
return w.GetPosX() + x / w.GetScaleX();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double mpScaleX::X2p( mpWindow& w, double x )
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
|
|
|
return ( x - w.GetPosX() ) * w.GetScaleX();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
double mpScaleX::P2x( mpWindow& w, double x )
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
|
|
|
return w.GetPosX() + x / w.GetScaleX();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
double mpScaleY::X2p( mpWindow& w, double x )
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
|
|
|
return ( w.GetPosY() - x ) * w.GetScaleY();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
double mpScaleY::P2x( mpWindow& w, double x )
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
return w.GetPosY() - x / w.GetScaleY();
|
2016-08-11 12:41:48 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
#endif
|
|
|
|
|
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 - 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
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
mpFX::mpFX( 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
|
|
|
|
|
|
|
wxCoord startPx = m_drawOutsideMargins ? 0 : w.GetMarginLeft();
|
|
|
|
wxCoord endPx = m_drawOutsideMargins ? w.GetScrX() : w.GetScrX() - w.GetMarginRight();
|
|
|
|
wxCoord minYpx = m_drawOutsideMargins ? 0 : w.GetMarginTop();
|
|
|
|
wxCoord maxYpx = m_drawOutsideMargins ? w.GetScrY() : w.GetScrY() - w.GetMarginBottom();
|
|
|
|
|
|
|
|
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
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_drawOutsideMargins || ( (iy >= minYpx) && (iy <= maxYpx) ) )
|
|
|
|
dc.DrawPoint( i, iy ); // (wxCoord) ((w.GetPosY() - GetY( (double)i / w.GetScaleX() + w.GetPosX()) ) * w.GetScaleY()));
|
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
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_drawOutsideMargins || ( (iy >= minYpx) && (iy <= maxYpx) ) )
|
|
|
|
dc.DrawLine( i, iy, i, iy );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// wxCoord c = YScale().X2p( GetY(XScale().P2x(i)) );
|
|
|
|
//(wxCoord) ((w.GetPosY() - GetY( (double)i / w.GetScaleX() + w.GetPosX()) ) * w.GetScaleY());
|
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
|
|
|
|
|
|
|
/*if ((m_flags & mpALIGNMASK) == mpALIGN_RIGHT)
|
2016-08-12 08:10:33 +00:00
|
|
|
* tx = (w.GetScrX()>>1) - tx - 8;
|
|
|
|
* else if ((m_flags & mpALIGNMASK) == mpALIGN_CENTER)
|
|
|
|
* tx = -tx/2;
|
|
|
|
* else
|
|
|
|
* tx = -(w.GetScrX()>>1) + 8;
|
|
|
|
*/
|
|
|
|
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 )
|
|
|
|
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 )
|
|
|
|
|
|
|
|
mpFY::mpFY( 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;
|
|
|
|
|
|
|
|
wxCoord startPx = m_drawOutsideMargins ? 0 : w.GetMarginLeft();
|
|
|
|
wxCoord endPx = m_drawOutsideMargins ? w.GetScrX() : w.GetScrX() - w.GetMarginRight();
|
|
|
|
wxCoord minYpx = m_drawOutsideMargins ? 0 : w.GetMarginTop();
|
|
|
|
wxCoord maxYpx = m_drawOutsideMargins ? w.GetScrY() : w.GetScrY() - w.GetMarginBottom();
|
|
|
|
|
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 ) ) );
|
|
|
|
|
|
|
|
if( m_drawOutsideMargins || ( (ix >= startPx) && (ix <= endPx) ) )
|
|
|
|
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
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_drawOutsideMargins || ( (ix >= startPx) && (ix <= endPx) ) )
|
|
|
|
dc.DrawLine( ix, i, ix, i );
|
|
|
|
|
|
|
|
// wxCoord c = XScale().X2p(GetX(YScale().P2x(i)));
|
|
|
|
//(wxCoord) ((GetX( (double)i / w.GetScaleY() + w.GetPosY()) - w.GetPosX()) * w.GetScaleX());
|
|
|
|
// dc.DrawLine(c, i, c, 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 )
|
|
|
|
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();
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.DrawText( m_name, w.x2p( GetX( w.p2y( ty ) ) ), ty ); // (wxCoord) ((GetX( (double)i / w.GetScaleY() + w.GetPosY()) - w.GetPosX()) * w.GetScaleX()), -ty);
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
IMPLEMENT_ABSTRACT_CLASS( mpFXY, mpLayer )
|
|
|
|
|
|
|
|
mpFXY::mpFXY( 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;
|
|
|
|
m_scaleX = NULL;
|
|
|
|
m_scaleY = NULL;
|
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
|
|
|
{
|
|
|
|
// Keep track of how many points have been drawn and the bouding 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
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_visible )
|
|
|
|
{
|
|
|
|
dc.SetPen( m_pen );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
double x, y;
|
|
|
|
// Do this to reset the counters to evaluate bounding box for label positioning
|
2016-08-12 08:10:33 +00:00
|
|
|
Rewind(); GetNextXY( x, y );
|
2016-08-11 12:41:21 +00:00
|
|
|
maxDrawX = x; minDrawX = x; maxDrawY = y; minDrawY = y;
|
2016-08-12 08:10:33 +00:00
|
|
|
// drawnPoints = 0;
|
2016-08-11 12:41:21 +00:00
|
|
|
Rewind();
|
|
|
|
|
|
|
|
wxCoord startPx = m_drawOutsideMargins ? 0 : w.GetMarginLeft();
|
|
|
|
wxCoord endPx = m_drawOutsideMargins ? w.GetScrX() : w.GetScrX() - w.GetMarginRight();
|
|
|
|
wxCoord minYpx = m_drawOutsideMargins ? 0 : w.GetMarginTop();
|
|
|
|
wxCoord maxYpx = m_drawOutsideMargins ? w.GetScrY() : w.GetScrY() - w.GetMarginBottom();
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.SetClippingRegion( startPx, minYpx, endPx - startPx + 1, maxYpx - minYpx + 1 );
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
wxCoord ix = 0, iy = 0;
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( !m_continuous )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
// for some reason DrawPoint does not use the current pen,
|
|
|
|
// so we use DrawLine for fat pens
|
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
|
|
|
while( GetNextXY( x, y ) )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
double px = m_scaleX->TransformToPlot( x );
|
|
|
|
double py = m_scaleY->TransformToPlot( y );
|
|
|
|
|
|
|
|
ix = w.x2p( px );
|
|
|
|
iy = w.y2p( py );
|
|
|
|
|
|
|
|
if( m_drawOutsideMargins
|
|
|
|
|| ( (ix >= startPx) && (ix <= endPx) && (iy >= minYpx)
|
|
|
|
&& (iy <= maxYpx) ) )
|
|
|
|
{
|
|
|
|
dc.DrawPoint( ix, iy );
|
|
|
|
UpdateViewBoundary( ix, iy );
|
|
|
|
}
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
while( GetNextXY( x, y ) )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
double px = m_scaleX->TransformToPlot( x );
|
|
|
|
double py = m_scaleY->TransformToPlot( y );
|
|
|
|
|
|
|
|
ix = w.x2p( px );
|
|
|
|
iy = w.y2p( py );
|
|
|
|
|
|
|
|
if( m_drawOutsideMargins
|
|
|
|
|| ( (ix >= startPx) && (ix <= endPx) && (iy >= minYpx)
|
|
|
|
&& (iy <= maxYpx) ) )
|
|
|
|
{
|
|
|
|
dc.DrawLine( ix, iy, ix, iy );
|
|
|
|
UpdateViewBoundary( ix, iy );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
// dc.DrawLine(cx, cy, cx, cy);
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
int n = 0;
|
2016-08-11 12:41:21 +00:00
|
|
|
// Old code
|
2016-08-12 08:10:33 +00:00
|
|
|
wxCoord x0 = 0, c0 = 0;
|
|
|
|
bool first = TRUE;
|
|
|
|
|
|
|
|
while( GetNextXY( x, y ) )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
double px = m_scaleX->TransformToPlot( x );
|
|
|
|
double py = m_scaleY->TransformToPlot( y );
|
|
|
|
|
|
|
|
if( py >= 0.0 && py <= 1.0 )
|
|
|
|
n++;
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// printf("py %.1f\n", py);
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
wxCoord x1 = w.x2p( px );
|
|
|
|
wxCoord c1 = w.y2p( py );
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// printf("px %.10f py %.10f c1 %d\n", px, py, c1);
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// wxCoord x1 = XScale().X2p(w,x); // (wxCoord) ((x - w.GetPosX()) * w.GetScaleX());
|
|
|
|
// wxCoord c1 = YScale().X2p(w,y); // (wxCoord) ((w.GetPosY() - y) * w.GetScaleY());
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( first )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
first = FALSE;
|
|
|
|
x0 = x1; c0 = c1;
|
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 outUp, outDown;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
if( (x1 >= startPx)&&(x0 <= endPx) )
|
|
|
|
{
|
2016-08-11 12:41:21 +00:00
|
|
|
outDown = (c0 > maxYpx) && (c1 > maxYpx);
|
|
|
|
outUp = (c0 < minYpx) && (c1 < minYpx);
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
if( !outUp && !outDown )
|
|
|
|
{
|
|
|
|
dc.DrawLine( x0, c0, x1, c1 );
|
|
|
|
// UpdateViewBoundary(x1, c1);
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
x0 = x1; c0 = c1;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
// printf("n %s %d\n", (const char *) m_name.c_str(), n);
|
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
|
|
|
|
|
|
|
// xxx implement else ... if (!HasBBox())
|
|
|
|
{
|
|
|
|
// const int sx = w.GetScrX();
|
|
|
|
// const int sy = w.GetScrY();
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( (m_flags & mpALIGNMASK) == mpALIGN_NW )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
tx = minDrawX + 8;
|
|
|
|
ty = maxDrawY + 8;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
else if( (m_flags & mpALIGNMASK) == mpALIGN_NE )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
tx = maxDrawX - tx - 8;
|
|
|
|
ty = maxDrawY + 8;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
else if( (m_flags & mpALIGNMASK) == mpALIGN_SE )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
tx = maxDrawX - tx - 8;
|
|
|
|
ty = minDrawY - ty - 8;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
else
|
2016-08-12 08:10:33 +00:00
|
|
|
{
|
|
|
|
// mpALIGN_SW
|
|
|
|
tx = minDrawX + 8;
|
|
|
|
ty = minDrawY - ty - 8;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.DrawText( m_name, tx, ty );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
// mpProfile implementation
|
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( mpProfile, mpLayer )
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
mpProfile::mpProfile( 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 mpProfile::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 startPx = m_drawOutsideMargins ? 0 : w.GetMarginLeft();
|
|
|
|
wxCoord endPx = m_drawOutsideMargins ? w.GetScrX() : w.GetScrX() - w.GetMarginRight();
|
|
|
|
wxCoord minYpx = m_drawOutsideMargins ? 0 : w.GetMarginTop();
|
|
|
|
wxCoord maxYpx = m_drawOutsideMargins ? w.GetScrY() : w.GetScrY() - w.GetMarginBottom();
|
|
|
|
|
|
|
|
// Plot profile linking subsequent point of the profile, instead of mpFY, which plots simple points.
|
2016-08-12 08:10:33 +00:00
|
|
|
for( wxCoord i = startPx; i < endPx; ++i )
|
|
|
|
{
|
|
|
|
wxCoord c0 = w.y2p( GetY( w.p2x( i ) ) ); // (wxCoord) ((w.GetYpos() - GetY( (double)i / w.GetXscl() + w.GetXpos()) ) * w.GetYscl());
|
|
|
|
wxCoord c1 = w.y2p( GetY( w.p2x( i + 1 ) ) ); // (wxCoord) ((w.GetYpos() - GetY( (double)(i+1) / w.GetXscl() + (w.GetXpos() ) ) ) * w.GetYscl());
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// c0 = (c0 <= maxYpx) ? ((c0 >= minYpx) ? c0 : minYpx) : maxYpx;
|
|
|
|
// c1 = (c1 <= maxYpx) ? ((c1 >= minYpx) ? c1 : minYpx) : maxYpx;
|
2016-08-12 08:10:33 +00:00
|
|
|
if( !m_drawOutsideMargins )
|
|
|
|
{
|
|
|
|
c0 = (c0 <= maxYpx) ? ( (c0 >= minYpx) ? c0 : minYpx ) : maxYpx;
|
|
|
|
c1 = (c1 <= maxYpx) ? ( (c1 >= minYpx) ? c1 : minYpx ) : maxYpx;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
dc.DrawLine( i, c0, i + 1, c1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
;
|
|
|
|
|
|
|
|
if( !m_name.IsEmpty() )
|
|
|
|
{
|
|
|
|
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 )
|
|
|
|
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 ) ) ) ); // (wxCoord) ((w.GetPosY() - GetY( (double)tx / w.GetScaleX() + w.GetPosX())) * w.GetScaleY()) );
|
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 ) );
|
|
|
|
|
|
|
|
// printf("minV %.10f maxV %.10f %.10f %.10f\n", minV, maxV, minVvis, maxVvis);
|
2016-08-11 12:41:48 +00:00
|
|
|
|
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;
|
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-12 08:10:33 +00:00
|
|
|
double step = fabs( maxVvis - minVvis ) / (double) i;
|
|
|
|
double base = pow( 10, floor( log10( step ) ) );
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// printf("base %.3f\n", base);
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double stepInt = floor( step / base ) * base;
|
|
|
|
double err = fabs( 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-12 08:10:33 +00:00
|
|
|
|
|
|
|
// printf("step %d %.3f %.3f best %.3f\n",i, step, stepInt, bestStep);
|
2016-08-11 12:42:18 +00:00
|
|
|
}
|
2016-08-11 12:41:49 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
// printf("maxVVis %.3f\n", maxVvis);
|
2016-08-11 12:41:49 +00:00
|
|
|
|
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
|
|
|
// printf("tick %.3f\n", v);
|
|
|
|
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 )
|
2016-08-11 12:42:04 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
m_tickLabels.push_back( TickLabel( t ) );
|
2016-08-11 12:42:04 +00:00
|
|
|
}
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// n0 = floor(minVvis / bestStep) * bestStep;
|
|
|
|
// end = n0 +
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// n0 = floor( (w.GetPosX() ) / step ) * step ;
|
|
|
|
// printf("zeroOffset:%.3f tickjs : %d\n", zeroOffset, m_tickValues.size());
|
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-08-11 12:42:10 +00:00
|
|
|
#if 0
|
2016-08-12 08:10:33 +00:00
|
|
|
int mpScaleBase::getLabelDecimalDigits( int maxDigits )
|
2016-08-11 12:42:04 +00:00
|
|
|
{
|
|
|
|
int m = 0;
|
2016-08-11 12:42:10 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
for( auto l : m_tickLabels )
|
2016-08-11 12:42:04 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
int k = countDecimalDigits( l.pos );
|
|
|
|
m = std::max( k, m );
|
2016-08-11 12:42:04 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
return std::min( m, maxDigits );
|
2016-08-11 12:42:04 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
|
2016-08-11 12:42:10 +00:00
|
|
|
#endif
|
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
|
|
|
// printf("test: %d %d %d\n", countDecimalDigits(1.0), countDecimalDigits(1.1), countDecimalDigits(1.22231));
|
|
|
|
m_maxLabelHeight = 0;
|
|
|
|
m_maxLabelWidth = 0;
|
2016-08-11 12:42:04 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
for( int n = 0; n < labelCount(); n++ )
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
|
|
|
int tx, ty;
|
|
|
|
const wxString s = getLabel( n );
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.GetTextExtent( s, &tx, &ty );
|
|
|
|
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
|
|
|
// int gap = IsHorizontal() ? m_maxLabelWidth + 10 : m_maxLabelHeight + 5;
|
2016-08-11 12:42:04 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// if ( m_tickLabels.size() <= 2)
|
|
|
|
// return;
|
2016-08-11 12:42:04 +00:00
|
|
|
|
2016-08-11 12:42:18 +00:00
|
|
|
/*
|
2016-08-12 08:10:33 +00:00
|
|
|
* fixme!
|
|
|
|
*
|
|
|
|
* for ( auto &l : m_tickLabels )
|
|
|
|
* {
|
|
|
|
* double p = TransformToPlot ( l.pos );
|
|
|
|
*
|
|
|
|
* if ( !IsHorizontal() )
|
|
|
|
* l.pixelPos = (int)(( w.GetPosY() - p ) * w.GetScaleY());
|
|
|
|
* else
|
|
|
|
* l.pixelPos = (int)(( p - w.GetPosX()) * w.GetScaleX());
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* for (int i = 1; i < m_tickLabels.size() - 1; i++)
|
|
|
|
* {
|
|
|
|
* int dist_prev;
|
|
|
|
*
|
|
|
|
* for(int j = i-1; j >= 1; j--)
|
|
|
|
* {
|
|
|
|
* if( m_tickLabels[j].visible)
|
|
|
|
* {
|
|
|
|
* dist_prev = abs( m_tickLabels[j].pixelPos - m_tickLabels[i].pixelPos );
|
|
|
|
* break;
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* if (dist_prev < gap)
|
|
|
|
* m_tickLabels[i].visible = false;
|
|
|
|
* }
|
|
|
|
*/
|
2016-08-11 12:42:04 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:42:04 +00:00
|
|
|
#if 0
|
2016-08-11 12:41:48 +00:00
|
|
|
int mpScaleX::tickCount() const
|
|
|
|
{
|
2016-08-11 12:41:49 +00:00
|
|
|
return m_tickValues.size();
|
2016-08-11 12:41:48 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:48 +00:00
|
|
|
int mpScaleX::labelCount() const
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
return 0; // return m_labeledTicks.size();
|
2016-08-11 12:41:48 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:48 +00:00
|
|
|
const wxString mpScaleX::getLabel( int n )
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
return wxT( "L" );
|
2016-08-11 12:41:48 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:48 +00:00
|
|
|
double mpScaleX::getTickPos( int n )
|
|
|
|
{
|
2016-08-11 12:42:18 +00:00
|
|
|
return m_tickValues[n];
|
2016-08-11 12:41:48 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:48 +00:00
|
|
|
double mpScaleX::getLabelPos( int n )
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
return 0; // return m_labeledTicks[n];
|
2016-08-11 12:41:48 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
|
2016-08-11 12:42:04 +00:00
|
|
|
#endif
|
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
|
|
|
{
|
|
|
|
wxCoord minYpx = m_drawOutsideMargins ? 0 : w.GetMarginTop();
|
|
|
|
wxCoord maxYpx = m_drawOutsideMargins ? w.GetScrY() : w.GetScrY() - w.GetMarginBottom();
|
|
|
|
|
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
|
|
|
// printf("PYmin %.3f PYmax %.3f\n", pymin, pymax);
|
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 )
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_masterScale->m_tickValues.size() == 0 )
|
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
|
|
|
// printf("NTicks %d\n", m_masterScale->m_tickValues.size());
|
|
|
|
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
|
|
|
double m;
|
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
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
for( unsigned int i = 0; i < m_masterScale->m_tickValues.size(); i++ )
|
2016-08-11 12:42:18 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
m = TransformFromPlot( m_masterScale->TransformToPlot( m_masterScale->m_tickValues[i] ) );
|
|
|
|
m_tickValues.push_back( m );
|
|
|
|
m_tickLabels.push_back( TickLabel( m ) );
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
// printf("this %p master %p\n", this, m_masterScale);
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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 );
|
|
|
|
// printf("vdr %.10f %.10f\n", 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
|
|
|
|
2016-08-11 12:42:10 +00:00
|
|
|
|
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;
|
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-12 08:10:33 +00:00
|
|
|
double step = fabs( maxVvis - minVvis ) / (double) i;
|
|
|
|
double base = pow( 10, floor( log10( step ) ) );
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// printf("base %.3f\n", base);
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double stepInt = floor( step / base ) * base;
|
|
|
|
double err = fabs( 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-12 08:10:33 +00:00
|
|
|
|
|
|
|
// printf("step %d %.3f %.3f best %.3f\n",i, step, stepInt, bestStep);
|
2016-08-11 12:42:18 +00:00
|
|
|
}
|
2016-08-11 12:41:48 +00:00
|
|
|
|
|
|
|
|
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;
|
2016-08-12 08:10:33 +00:00
|
|
|
// printf("v %.3f maxVVis %.3f\n", v, maxVvis);
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-11 12:42:02 +00:00
|
|
|
const int iterLimit = 1000;
|
|
|
|
int i = 0;
|
|
|
|
|
2016-08-12 08:10:33 +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
|
|
|
// printf("tick %.3f %d\n", v, m_tickValues.size());
|
|
|
|
v += bestStep;
|
2016-08-11 12:42:04 +00:00
|
|
|
i++;
|
2016-08-11 12:41:48 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 12:42:04 +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 )
|
2016-08-11 12:42:04 +00:00
|
|
|
m_tickLabels.push_back( TickLabel( t ) );
|
|
|
|
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// n0 = floor(minVvis / bestStep) * bestStep;
|
|
|
|
// end = n0 +
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// n0 = floor( (w.GetPosX() ) / step ) * step ;
|
|
|
|
// printf("zeroOffset:%.3f tickjs : %d\n", zeroOffset, m_tickValues.size());
|
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
|
|
|
// labelStep = ceil(((double) m_maxLabelWidth + mpMIN_X_AXIS_LABEL_SEPARATION)/(w.GetScaleX()*step))*step;
|
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
|
|
|
{
|
|
|
|
wxCoord startPx = m_drawOutsideMargins ? 0 : w.GetMarginLeft();
|
2016-08-12 08:10:33 +00:00
|
|
|
wxCoord endPx = m_drawOutsideMargins ? w.GetScrX() : w.GetScrX() - w.GetMarginRight();
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// printf("getVisibleDataRange\n");
|
2016-08-11 12:41:21 +00:00
|
|
|
|
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 ) ) );
|
|
|
|
// printf("test: %d %d %d\n", countDecimalDigits(1.0), countDecimalDigits(1.1), countDecimalDigits(1.22231));
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
double visibleDecades = log( maxVvis / minVvis ) / log( 10 );
|
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;
|
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
for( d = minDecade; d<=maxDecade; d *= 10.0 )
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
// printf("d %.1f\n",d );
|
|
|
|
m_tickLabels.push_back( TickLabel( d ) );
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
for( double dd = d; dd < d * 10; dd += d )
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( visibleDecades < 2 )
|
|
|
|
m_tickLabels.push_back( TickLabel( 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
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
mpScaleXBase::mpScaleXBase( 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;
|
2016-08-12 08:10:33 +00:00
|
|
|
// m_labelType = type;
|
2016-08-11 12:41:21 +00:00
|
|
|
m_type = mpLAYER_AXIS;
|
2016-08-12 08:10:33 +00:00
|
|
|
// m_labelFormat = wxT("");
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
mpScaleX::mpScaleX( wxString name, int flags, bool ticks, unsigned int type ) :
|
|
|
|
mpScaleXBase( name, flags, ticks, type )
|
|
|
|
{
|
|
|
|
};
|
2016-08-11 12:41:48 +00:00
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
mpScaleXLog::mpScaleXLog( wxString name, int flags, bool ticks, unsigned int type ) :
|
|
|
|
mpScaleXBase( name, flags, ticks, type )
|
|
|
|
{
|
|
|
|
};
|
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 )
|
|
|
|
orgy = w.y2p( 0 ); // (int)(w.GetPosY() * w.GetScaleY());
|
|
|
|
|
|
|
|
if( m_flags == mpALIGN_TOP )
|
|
|
|
{
|
|
|
|
if( m_drawOutsideMargins )
|
2016-08-11 12:41:21 +00:00
|
|
|
orgy = X_BORDER_SEPARATION;
|
|
|
|
else
|
|
|
|
orgy = w.GetMarginTop();
|
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
if( m_flags == mpALIGN_BOTTOM )
|
|
|
|
{
|
|
|
|
if( m_drawOutsideMargins )
|
2016-08-11 12:41:21 +00:00
|
|
|
orgy = X_BORDER_SEPARATION;
|
|
|
|
else
|
|
|
|
orgy = w.GetScrY() - w.GetMarginBottom();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_flags == mpALIGN_BORDER_BOTTOM )
|
|
|
|
orgy = w.GetScrY() - 1; // dc.LogicalToDeviceY(0) - 1;
|
|
|
|
|
|
|
|
if( m_flags == mpALIGN_BORDER_TOP )
|
|
|
|
orgy = 1; // -dc.LogicalToDeviceY(0);
|
|
|
|
|
|
|
|
// dc.DrawLine( 0, orgy, w.GetScrX(), orgy);
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
wxCoord startPx = m_drawOutsideMargins ? 0 : w.GetMarginLeft();
|
|
|
|
wxCoord endPx = m_drawOutsideMargins ? w.GetScrX() : w.GetScrX() - w.GetMarginRight();
|
|
|
|
wxCoord minYpx = m_drawOutsideMargins ? 0 : w.GetMarginTop();
|
|
|
|
wxCoord maxYpx = m_drawOutsideMargins ? w.GetScrY() : w.GetScrY() - w.GetMarginBottom();
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// printf("StartPx %d endPx %d ordy %d maxy %d\n", startPx, endPx, orgy, maxYpx);
|
|
|
|
|
|
|
|
// int tmp=-65535;
|
|
|
|
int labelH = m_maxLabelHeight; // Control labels heigth 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();
|
|
|
|
// printf("Ticks : %d\n",labelCount());
|
|
|
|
for( int n = 0; n < tickCount(); n++ )
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
double tp = getTickPos( n );
|
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
|
|
|
double px = TransformToPlot( tp ); // ( log10 ( tp ) - xlogmin) / (xlogmax - xlogmin);
|
2016-08-11 12:41:48 +00:00
|
|
|
|
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-11 12:41:21 +00:00
|
|
|
#ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
wxLogMessage( wxT( "mpScaleX::Plot: n: %f -> p = %d" ), n, p );
|
2016-08-11 12:41:21 +00:00
|
|
|
#endif
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
if( (p >= startPx) && (p <= endPx) )
|
|
|
|
{
|
|
|
|
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 );
|
|
|
|
|
|
|
|
if( (m_flags == mpALIGN_BOTTOM) && !m_drawOutsideMargins )
|
|
|
|
{
|
|
|
|
// printf("d1");
|
|
|
|
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
|
|
|
|
{
|
|
|
|
if( (m_flags == mpALIGN_TOP) && !m_drawOutsideMargins )
|
|
|
|
{
|
|
|
|
// printf("d2");
|
|
|
|
dc.DrawLine( p, orgy - 4, p, maxYpx );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// printf("d3");
|
|
|
|
dc.DrawLine( p, minYpx, p, maxYpx ); // 0/*-w.GetScrY()*/, p, w.GetScrY() );
|
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 );
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// printf("Labels : %d\n",labelCount());
|
2016-08-11 12:41:21 +00:00
|
|
|
// Actually draw labels, taking care of not overlapping them, and distributing them regularly
|
2016-08-12 08:10:33 +00:00
|
|
|
for( int n = 0; n < labelCount(); n++ )
|
2016-08-11 12:41:48 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
double tp = getLabelPos( n );
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( !m_tickLabels[n].visible )
|
2016-08-11 12:42:04 +00:00
|
|
|
continue;
|
|
|
|
|
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
|
|
|
double px = TransformToPlot( tp ); // ( log10 ( tp ) - xlogmin) / (xlogmax - xlogmin);
|
2016-08-11 12:41:48 +00:00
|
|
|
|
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
|
|
|
// printf("p %d %.1f\n", p, px);
|
2016-08-11 12:41:21 +00:00
|
|
|
#ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
wxLogMessage( wxT( "mpScaleX::Plot: n_label = %f -> p_label = %d" ), n, p );
|
2016-08-11 12:41:21 +00:00
|
|
|
#endif
|
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
|
2016-08-11 12:42:04 +00:00
|
|
|
wxString s = m_tickLabels[n].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 );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +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:
|
|
|
|
{
|
|
|
|
if( (!m_drawOutsideMargins) && ( w.GetMarginTop() > (ty + labelH + 8) ) )
|
|
|
|
{
|
|
|
|
dc.DrawText( m_name, (endPx - startPx - tx) >> 1, orgy - 6 - ty - labelH );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dc.DrawText( m_name, extend - tx - 4, orgy + 4 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
mpScaleY::mpScaleY( 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;
|
2016-08-11 12:41:48 +00:00
|
|
|
m_masterScale = NULL;
|
2016-08-11 12:42:04 +00:00
|
|
|
m_nameFlags = mpALIGN_BORDER_LEFT;
|
2016-08-12 08:10:33 +00:00
|
|
|
// m_labelFormat = wxT("");
|
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
|
|
|
// printf("Plot Y-scale\n");
|
|
|
|
recalculateTicks( dc, w );
|
|
|
|
|
|
|
|
if( m_visible )
|
|
|
|
{
|
|
|
|
dc.SetPen( m_pen );
|
|
|
|
dc.SetFont( m_font );
|
|
|
|
|
|
|
|
int orgx = 0;
|
|
|
|
|
|
|
|
// const int extend = w.GetScrY(); // /2;
|
|
|
|
if( m_flags == mpALIGN_CENTER )
|
|
|
|
orgx = w.x2p( 0 ); // (int)(w.GetPosX() * w.GetScaleX());
|
|
|
|
|
|
|
|
if( m_flags == mpALIGN_LEFT )
|
|
|
|
{
|
|
|
|
if( m_drawOutsideMargins )
|
2016-08-11 12:41:21 +00:00
|
|
|
orgx = Y_BORDER_SEPARATION;
|
|
|
|
else
|
|
|
|
orgx = w.GetMarginLeft();
|
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
if( m_flags == mpALIGN_RIGHT )
|
|
|
|
{
|
|
|
|
if( m_drawOutsideMargins )
|
2016-08-11 12:41:21 +00:00
|
|
|
orgx = w.GetScrX() - Y_BORDER_SEPARATION;
|
|
|
|
else
|
|
|
|
orgx = w.GetScrX() - w.GetMarginRight();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_flags == mpALIGN_BORDER_RIGHT )
|
|
|
|
orgx = w.GetScrX() - 1; // dc.LogicalToDeviceX(0) - 1;
|
|
|
|
|
|
|
|
if( m_flags == mpALIGN_BORDER_LEFT )
|
|
|
|
orgx = 1; // -dc.LogicalToDeviceX(0);
|
|
|
|
|
|
|
|
wxCoord endPx = m_drawOutsideMargins ? w.GetScrX() : w.GetScrX() - w.GetMarginRight();
|
2016-08-11 12:42:18 +00:00
|
|
|
wxCoord minYpx = m_drawOutsideMargins ? 0 : w.GetMarginTop();
|
|
|
|
wxCoord maxYpx = m_drawOutsideMargins ? w.GetScrY() : 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
|
|
|
|
|
|
|
|
|
|
|
wxCoord tx, ty;
|
2016-08-12 08:10:33 +00:00
|
|
|
wxString s;
|
|
|
|
wxString fmt;
|
|
|
|
int n = 0;
|
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
|
|
|
|
int labelHeigth = 0;
|
2016-08-12 08:10:33 +00:00
|
|
|
s.Printf( fmt, n );
|
|
|
|
dc.GetTextExtent( s, &tx, &labelHeigth );
|
|
|
|
|
|
|
|
// printf("Y-ticks: %d\n", tickCount());
|
|
|
|
for( n = 0; n < tickCount(); n++ )
|
|
|
|
{
|
|
|
|
// printf("Tick %d\n", n);
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double tp = getTickPos( n );
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double py = TransformToPlot( tp ); // ( log10 ( tp ) - xlogmin) / (xlogmax - xlogmin);
|
|
|
|
const int p = (int) ( ( w.GetPosY() - py ) * w.GetScaleY() );
|
2016-08-11 12:41:48 +00:00
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( (p >= minYpx) && (p <= maxYpx) )
|
|
|
|
{
|
|
|
|
if( m_ticks ) // Draw axis ticks
|
|
|
|
{
|
|
|
|
if( m_flags == mpALIGN_BORDER_LEFT )
|
|
|
|
{
|
|
|
|
dc.DrawLine( orgx, p, orgx + 4, p );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
dc.DrawLine( orgx - 4, p, orgx, p ); // ( orgx, p, orgx+4, 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 );
|
|
|
|
|
|
|
|
if( (m_flags == mpALIGN_LEFT) && !m_drawOutsideMargins )
|
|
|
|
{
|
|
|
|
dc.DrawLine( orgx - 4, p, endPx, p );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( (m_flags == mpALIGN_RIGHT) && !m_drawOutsideMargins )
|
|
|
|
{
|
|
|
|
// dc.DrawLine( orgX-4, p, orgx+4, p);
|
|
|
|
dc.DrawLine( orgx - 4, p, endPx, p );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dc.DrawLine( orgx - 4, p, endPx, p );
|
|
|
|
// dc.DrawLine( orgx-4/*-w.GetScrX()*/, p, w.GetScrX(), 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// printf("Y-ticks: %d\n", tickCount());
|
|
|
|
for( n = 0; n < labelCount(); n++ )
|
|
|
|
{
|
|
|
|
// printf("Tick %d\n", n);
|
2016-08-11 12:42:04 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double tp = getLabelPos( n );
|
2016-08-11 12:42:04 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double py = TransformToPlot( tp ); // ( log10 ( tp ) - xlogmin) / (xlogmax - xlogmin);
|
|
|
|
const int p = (int) ( ( w.GetPosY() - py ) * w.GetScaleY() );
|
2016-08-11 12:42:04 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( !m_tickLabels[n].visible )
|
2016-08-11 12:42:18 +00:00
|
|
|
continue;
|
2016-08-11 12:42:04 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( (p >= minYpx) && (p <= maxYpx) )
|
|
|
|
{
|
|
|
|
s = getLabel( n );
|
|
|
|
dc.GetTextExtent( s, &tx, &ty );
|
2016-08-11 12:42:04 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( (m_flags == mpALIGN_BORDER_LEFT) || (m_flags == mpALIGN_RIGHT) )
|
|
|
|
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:42:18 +00:00
|
|
|
// Draw axis name
|
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:
|
|
|
|
{
|
|
|
|
// if ((!m_drawOutsideMargins) && (w.GetMarginLeft() > (ty + labelW + 8))) {
|
|
|
|
// dc.DrawRotatedText( m_name, orgx - 6 - labelW - ty, (maxYpx + minYpx) / 2 + tx / 2, 90);
|
|
|
|
// } else {
|
|
|
|
dc.DrawText( m_name, orgx + 4, minYpx - ty - 4 );
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case mpALIGN_CENTER:
|
|
|
|
dc.DrawText( m_name, orgx + 4, 4 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case mpALIGN_RIGHT:
|
|
|
|
{
|
|
|
|
// dc.DrawRotatedText( m_name, orgx + 6, (maxYpx + minYpx) / 2 + tx / 2, 90);
|
|
|
|
|
|
|
|
/*if ((!m_drawOutsideMargins) && (w.GetMarginRight() > (ty + labelW + 8))) {
|
|
|
|
* dc.DrawRotatedText( m_name, orgx + 6 + labelW, (maxYpx - minYpx + tx)>>1, 90);
|
|
|
|
* } else {*/
|
|
|
|
dc.DrawText( m_name, orgx - tx - 4, minYpx - ty - 4 );
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
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_SCROLLWIN_THUMBTRACK( mpWindow::OnScrollThumbTrack )
|
|
|
|
EVT_SCROLLWIN_PAGEUP( mpWindow::OnScrollPageUp )
|
|
|
|
EVT_SCROLLWIN_PAGEDOWN( mpWindow::OnScrollPageDown )
|
|
|
|
EVT_SCROLLWIN_LINEUP( mpWindow::OnScrollLineUp )
|
|
|
|
EVT_SCROLLWIN_LINEDOWN( mpWindow::OnScrollLineDown )
|
|
|
|
EVT_SCROLLWIN_TOP( mpWindow::OnScrollTop )
|
|
|
|
EVT_SCROLLWIN_BOTTOM( mpWindow::OnScrollBottom )
|
|
|
|
|
|
|
|
EVT_MIDDLE_DOWN( mpWindow::OnMouseMiddleDown ) // JLB
|
|
|
|
EVT_RIGHT_UP( mpWindow::OnShowPopupMenu )
|
|
|
|
EVT_MOUSEWHEEL( mpWindow::OnMouseWheel ) // JLB
|
|
|
|
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 )
|
|
|
|
EVT_MENU( mpID_LOCKASPECT, mpWindow::OnLockAspect )
|
2016-08-11 12:41:21 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
mpWindow::mpWindow( wxWindow* parent,
|
|
|
|
wxWindowID id,
|
|
|
|
const wxPoint& pos,
|
|
|
|
const wxSize& size,
|
|
|
|
long flag )
|
|
|
|
: wxWindow( parent, id, pos, size, flag, wxT( "mathplot" ) )
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
m_buff_bmp = NULL;
|
|
|
|
m_enableDoubleBuffer = FALSE;
|
|
|
|
m_enableMouseNavigation = TRUE;
|
|
|
|
m_enableLimitedView = FALSE;
|
2016-08-11 12:41:21 +00:00
|
|
|
m_movingInfoLayer = NULL;
|
|
|
|
// Set margins to 0
|
|
|
|
m_marginTop = 0; m_marginRight = 0; m_marginBottom = 0; m_marginLeft = 0;
|
|
|
|
|
|
|
|
|
|
|
|
m_lockaspect = FALSE;
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
m_popmenu.Append( mpID_CENTER, _( "Center" ), _( "Center plot view to this position" ) );
|
|
|
|
m_popmenu.Append( mpID_FIT, _( "Fit" ), _( "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." ) );
|
|
|
|
// m_popmenu.AppendCheckItem( mpID_LOCKASPECT, _("Lock aspect"), _("Lock horizontal and vertical zoom aspect."));
|
|
|
|
// m_popmenu.Append( mpID_HELP_MOUSE, _("Show mouse commands..."), _("Show help about the mouse commands."));
|
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
|
|
|
|
|
|
|
m_enableScrollBars = false;
|
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 );
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_buff_bmp )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
delete m_buff_bmp;
|
|
|
|
m_buff_bmp = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +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;
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:27 +00:00
|
|
|
// Scroll vertically or horizontally (this is SHIFT is hold down).
|
2016-08-12 08:10:33 +00:00
|
|
|
int change = -event.GetWheelRotation(); // Opposite direction (More intuitive)!
|
|
|
|
double changeUnitsX = change / m_scaleX;
|
|
|
|
double changeUnitsY = change / m_scaleY;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( event.m_controlDown )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-11 12:41:27 +00:00
|
|
|
// horizontal scroll
|
2016-08-12 08:10:33 +00:00
|
|
|
SetXView( m_posX + changeUnitsX, m_desiredXmax + changeUnitsX,
|
|
|
|
m_desiredXmin + changeUnitsX );
|
2016-08-11 12:41:27 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
else if( event.m_shiftDown )
|
2016-08-11 12:41:27 +00:00
|
|
|
{
|
|
|
|
// vertical scroll
|
2016-08-12 08:10:33 +00:00
|
|
|
SetYView( m_posY - changeUnitsY, m_desiredYmax - changeUnitsY,
|
|
|
|
m_desiredYmin - changeUnitsY );
|
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 );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-11 12:41:27 +00:00
|
|
|
|
|
|
|
UpdateAll();
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// If the user "drags" with the right buttom pressed, do "pan"
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( event.m_middleDown )
|
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
|
|
|
|
2016-08-11 12:41:37 +00:00
|
|
|
bool updateRequired = false;
|
2016-08-12 08:10:33 +00:00
|
|
|
updateRequired |= SetXView( m_posX + Ax_units,
|
|
|
|
m_desiredXmax + Ax_units,
|
|
|
|
m_desiredXmin + Ax_units );
|
|
|
|
updateRequired |= SetYView( m_posY + Ay_units,
|
|
|
|
m_desiredYmax + Ay_units,
|
|
|
|
m_desiredYmin + Ay_units );
|
|
|
|
|
|
|
|
if( updateRequired )
|
2016-08-11 12:41:37 +00:00
|
|
|
UpdateAll();
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
#ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
wxLogMessage( "[mpWindow::OnMouseMove] Ax:%i Ay:%i m_posX:%f m_posY:%f",
|
|
|
|
Ax,
|
|
|
|
Ay,
|
|
|
|
m_posX,
|
|
|
|
m_posY );
|
2016-08-11 12:41:21 +00:00
|
|
|
#endif
|
2016-08-12 08:10:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( event.m_leftDown )
|
|
|
|
{
|
|
|
|
if( m_movingInfoLayer == NULL )
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
event.GetX() - m_mouseLClick.x, event.GetY() - m_mouseLClick.y );
|
2016-08-11 12:41:48 +00:00
|
|
|
m_zooming = true;
|
2016-08-12 08:10:33 +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;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxPoint moveVector( event.GetX() - m_mouseLClick.x,
|
|
|
|
event.GetY() - m_mouseLClick.y );
|
|
|
|
m_movingInfoLayer->Move( moveVector );
|
2016-08-11 12:41:48 +00:00
|
|
|
m_zooming = false;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
UpdateAll();
|
2016-08-12 08:10:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-11 12:42:18 +00:00
|
|
|
#if 0
|
2016-08-11 12:41:21 +00:00
|
|
|
wxLayerList::iterator li;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
for( li = m_layers.begin(); li != m_layers.end(); li++ )
|
|
|
|
{
|
|
|
|
if( (*li)->IsInfo() && (*li)->IsVisible() )
|
|
|
|
{
|
2016-08-11 12:41:21 +00:00
|
|
|
mpInfoLayer* tmpLyr = (mpInfoLayer*) (*li);
|
2016-08-12 08:10:33 +00:00
|
|
|
tmpLyr->UpdateInfo( *this, event );
|
2016-08-11 12:41:21 +00:00
|
|
|
// UpdateAll();
|
2016-08-12 08:10:33 +00:00
|
|
|
RefreshRect( tmpLyr->GetRectangle() );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:42:18 +00:00
|
|
|
#endif
|
2016-08-11 12:41:21 +00:00
|
|
|
/* if (m_coordTooltip) {
|
2016-08-12 08:10:33 +00:00
|
|
|
* wxString toolTipContent;
|
|
|
|
* toolTipContent.Printf( "X = %f\nY = %f", p2x(event.GetX()), p2y(event.GetY()));
|
|
|
|
* wxTipWindow** ptr = NULL;
|
|
|
|
* wxRect rectBounds(event.GetX(), event.GetY(), 5, 5);
|
|
|
|
* wxTipWindow* tip = new wxTipWindow(this, toolTipContent, 100, ptr, &rectBounds);
|
|
|
|
*
|
|
|
|
* } */
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
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
|
|
|
#ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
wxLogMessage( "mpWindow::OnMouseLeftDown() X = %d , Y = %d", event.GetX(), event.GetY() ); /*m_mouseLClick.x, m_mouseLClick.y);*/
|
2016-08-11 12:41:21 +00:00
|
|
|
#endif
|
|
|
|
wxPoint pointClicked = event.GetPosition();
|
2016-08-12 08:10:33 +00:00
|
|
|
m_movingInfoLayer = IsInsideInfoLayer( pointClicked );
|
|
|
|
|
|
|
|
if( m_movingInfoLayer != NULL )
|
|
|
|
{
|
2016-08-11 12:41:21 +00:00
|
|
|
#ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
wxLogMessage( "mpWindow::OnMouseLeftDown() started moving layer %lx",
|
|
|
|
(long int) m_movingInfoLayer ); /*m_mouseLClick.x, m_mouseLClick.y);*/
|
2016-08-11 12:41:21 +00:00
|
|
|
#endif
|
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
if( m_movingInfoLayer != NULL )
|
|
|
|
{
|
2016-08-11 12:41:21 +00:00
|
|
|
m_movingInfoLayer->UpdateReference();
|
|
|
|
m_movingInfoLayer = NULL;
|
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if( release != press )
|
|
|
|
{
|
|
|
|
ZoomRect( press, release );
|
|
|
|
} /*else {
|
|
|
|
* if (m_coordTooltip) {
|
|
|
|
* wxString toolTipContent;
|
|
|
|
* toolTipContent.Printf( "X = %f\nY = %f", p2x(event.GetX()), p2y(event.GetY()));
|
|
|
|
* SetToolTip(toolTipContent);
|
|
|
|
* }
|
|
|
|
* } */
|
|
|
|
}
|
|
|
|
|
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-08-12 08:10:33 +00:00
|
|
|
void mpWindow::Fit( double xMin,
|
|
|
|
double xMax,
|
|
|
|
double yMin,
|
|
|
|
double yMax,
|
|
|
|
wxCoord* printSizeX,
|
|
|
|
wxCoord* printSizeY )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
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
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// printf(" ******************Fit: %.3f %.3f", xMin, xMax);
|
2016-08-11 12:41:48 +00:00
|
|
|
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// Save desired borders:
|
2016-08-12 08:10:33 +00:00
|
|
|
m_desiredXmin = xMin; m_desiredXmax = xMax;
|
|
|
|
m_desiredYmin = yMin; m_desiredYmax = yMax;
|
|
|
|
// printf("minx %.1f miny %.1f maxx %.1f maxy %.1f\n", xMin, yMin, xMax, yMax);
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( printSizeX!=NULL && printSizeY!=NULL )
|
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
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double Ax, Ay;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
Ax = xMax - xMin;
|
|
|
|
Ay = yMax - yMin;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
m_scaleX = (Ax!=0) ? (m_scrX - m_marginLeft - m_marginRight) / Ax : 1; // m_scaleX = (Ax!=0) ? m_scrX/Ax : 1;
|
|
|
|
m_scaleY = (Ay!=0) ? (m_scrY - m_marginTop - m_marginBottom) / Ay : 1; // m_scaleY = (Ay!=0) ? m_scrY/Ay : 1;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_lockaspect )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
#ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
wxLogMessage( "mpWindow::Fit()(lock) m_scaleX=%f,m_scaleY=%f", m_scaleX, m_scaleY );
|
2016-08-11 12:41:21 +00:00
|
|
|
#endif
|
|
|
|
// Keep the lowest "scale" to fit the whole range required by that axis (to actually "fit"!):
|
|
|
|
double s = m_scaleX < m_scaleY ? m_scaleX : m_scaleY;
|
2016-08-12 08:10:33 +00:00
|
|
|
m_scaleX = s;
|
|
|
|
m_scaleY = s;
|
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 ) /
|
|
|
|
m_scaleX; // m_posX = (xMin+xMax)/2 - (m_scrX/2)/m_scaleX;
|
|
|
|
// m_posY = (yMin+yMax)/2 + ((m_scrY - m_marginTop - m_marginBottom)/2 - m_marginTop)/m_scaleY; // m_posY = (yMin+yMax)/2 + (m_scrY/2)/m_scaleY;
|
|
|
|
m_posY = (yMin + yMax) / 2 + ( (m_scrY - m_marginTop - m_marginBottom) / 2 + m_marginTop ) /
|
|
|
|
m_scaleY; // m_posY = (yMin+yMax)/2 + (m_scrY/2)/m_scaleY;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
#ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
wxLogMessage(
|
|
|
|
"mpWindow::Fit() m_desiredXmin=%f m_desiredXmax=%f m_desiredYmin=%f m_desiredYmax=%f",
|
|
|
|
xMin,
|
|
|
|
xMax,
|
|
|
|
yMin,
|
|
|
|
yMax );
|
|
|
|
wxLogMessage(
|
|
|
|
"mpWindow::Fit() m_scaleX = %f , m_scrX = %d,m_scrY=%d, Ax=%f, Ay=%f, m_posX=%f, m_posY=%f",
|
|
|
|
m_scaleX,
|
|
|
|
m_scrX,
|
|
|
|
m_scrY,
|
|
|
|
Ax,
|
|
|
|
Ay,
|
|
|
|
m_posX,
|
|
|
|
m_posY );
|
2016-08-11 12:41:21 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// 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
|
2016-08-12 08:10:33 +00:00
|
|
|
if( printSizeX==NULL || printSizeY==NULL )
|
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
|
|
|
// Patch ngpaton
|
2016-08-12 08:10:33 +00:00
|
|
|
void mpWindow::DoZoomInXCalc( const int staticXpixel )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
// Preserve the position of the clicked point:
|
|
|
|
double staticX = p2x( staticXpixel );
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// Zoom in:
|
|
|
|
m_scaleX = m_scaleX * zoomIncrementalFactor;
|
|
|
|
// Adjust the new m_posx
|
|
|
|
m_posX = staticX - (staticXpixel / m_scaleX);
|
|
|
|
// Adjust desired
|
2016-08-12 08:10:33 +00:00
|
|
|
m_desiredXmin = m_posX;
|
|
|
|
m_desiredXmax = m_posX + ( m_scrX - (m_marginLeft + m_marginRight) ) / m_scaleX;
|
2016-08-11 12:41:21 +00:00
|
|
|
#ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
wxLogMessage(
|
|
|
|
"mpWindow::DoZoomInXCalc() prior X coord: (%f), new X coord: (%f) SHOULD BE EQUAL!!",
|
|
|
|
staticX, p2x( staticXpixel ) );
|
2016-08-11 12:41:21 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpWindow::DoZoomInYCalc( const int staticYpixel )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
// Preserve the position of the clicked point:
|
|
|
|
double staticY = p2y( staticYpixel );
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// Zoom in:
|
|
|
|
m_scaleY = m_scaleY * zoomIncrementalFactor;
|
|
|
|
// Adjust the new m_posy:
|
|
|
|
m_posY = staticY + (staticYpixel / m_scaleY);
|
|
|
|
// Adjust desired
|
2016-08-12 08:10:33 +00:00
|
|
|
m_desiredYmax = m_posY;
|
|
|
|
m_desiredYmin = m_posY - ( m_scrY - (m_marginTop + m_marginBottom) ) / m_scaleY;
|
2016-08-11 12:41:21 +00:00
|
|
|
#ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
wxLogMessage(
|
|
|
|
"mpWindow::DoZoomInYCalc() prior Y coord: (%f), new Y coord: (%f) SHOULD BE EQUAL!!",
|
|
|
|
staticY, p2y( staticYpixel ) );
|
2016-08-11 12:41:21 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpWindow::DoZoomOutXCalc( const int staticXpixel )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
// Preserve the position of the clicked point:
|
|
|
|
double staticX = p2x( staticXpixel );
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// Zoom out:
|
|
|
|
m_scaleX = m_scaleX / zoomIncrementalFactor;
|
|
|
|
// Adjust the new m_posx/y:
|
|
|
|
m_posX = staticX - (staticXpixel / m_scaleX);
|
|
|
|
// Adjust desired
|
2016-08-12 08:10:33 +00:00
|
|
|
m_desiredXmin = m_posX;
|
|
|
|
m_desiredXmax = m_posX + ( m_scrX - (m_marginLeft + m_marginRight) ) / m_scaleX;
|
2016-08-11 12:41:21 +00:00
|
|
|
#ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
wxLogMessage(
|
|
|
|
"mpWindow::DoZoomOutXCalc() prior X coord: (%f), new X coord: (%f) SHOULD BE EQUAL!!",
|
|
|
|
staticX, p2x( staticXpixel ) );
|
2016-08-11 12:41:21 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpWindow::DoZoomOutYCalc( const int staticYpixel )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
// Preserve the position of the clicked point:
|
|
|
|
double staticY = p2y( staticYpixel );
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// Zoom out:
|
|
|
|
m_scaleY = m_scaleY / zoomIncrementalFactor;
|
|
|
|
// Adjust the new m_posx/y:
|
|
|
|
m_posY = staticY + (staticYpixel / m_scaleY);
|
|
|
|
// Adjust desired
|
2016-08-12 08:10:33 +00:00
|
|
|
m_desiredYmax = m_posY;
|
|
|
|
m_desiredYmin = m_posY - ( m_scrY - (m_marginTop + m_marginBottom) ) / m_scaleY;
|
2016-08-11 12:41:21 +00:00
|
|
|
#ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
wxLogMessage(
|
|
|
|
"mpWindow::DoZoomOutYCalc() prior Y coord: (%f), new Y coord: (%f) SHOULD BE EQUAL!!",
|
|
|
|
staticY, p2y( staticYpixel ) );
|
2016-08-11 12:41:21 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
const double xMin = m_minX - m_marginLeft / m_scaleX;
|
|
|
|
const double xMax = m_maxX - m_marginRight / m_scaleX;
|
|
|
|
const double yMin = m_minY + m_marginTop / m_scaleY;
|
|
|
|
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
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
// if(!CheckXLimits(desiredMax, desiredMin))
|
|
|
|
// return false;
|
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
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
// if(!CheckYLimits(desiredMax, desiredMin))
|
|
|
|
// return false;
|
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 )
|
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;
|
2016-08-12 08:10:33 +00:00
|
|
|
double newScaleX = m_scaleX * zoomIncrementalFactor;
|
|
|
|
double newScaleY = m_scaleY * zoomIncrementalFactor;
|
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
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
m_scaleX = newScaleX;
|
|
|
|
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:
|
2016-08-12 08:10:33 +00:00
|
|
|
m_posX = prior_layer_x - c.x / m_scaleX;
|
|
|
|
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;
|
|
|
|
m_desiredXmax = m_posX + (m_scrX - m_marginLeft - m_marginRight) / m_scaleX; // m_desiredXmax = m_posX + m_scrX / m_scaleX;
|
|
|
|
m_desiredYmax = m_posY;
|
|
|
|
m_desiredYmin = m_posY - (m_scrY - m_marginTop - m_marginBottom) / m_scaleY; // m_desiredYmin = m_posY - m_scrY / m_scaleY;
|
2016-08-11 12:42:08 +00:00
|
|
|
AdjustLimitedView();
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
#ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
wxLogMessage( "mpWindow::ZoomIn() prior coords: (%f,%f), new coords: (%f,%f) SHOULD BE EQUAL!!",
|
|
|
|
prior_layer_x, prior_layer_y, p2x( c.x ), p2y( c.y ) );
|
2016-08-11 12:41:21 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
UpdateAll();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpWindow::ZoomOut( const wxPoint& centerPoint )
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// 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:
|
2016-08-12 08:10:33 +00:00
|
|
|
m_scaleX = m_scaleX / zoomIncrementalFactor;
|
|
|
|
m_scaleY = m_scaleY / zoomIncrementalFactor;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// Adjust the new m_posx/y:
|
2016-08-12 08:10:33 +00:00
|
|
|
m_posX = prior_layer_x - c.x / m_scaleX;
|
|
|
|
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;
|
|
|
|
m_desiredXmax = m_posX + (m_scrX - m_marginLeft - m_marginRight) / m_scaleX; // m_desiredXmax = m_posX + m_scrX / m_scaleX;
|
|
|
|
m_desiredYmax = m_posY;
|
|
|
|
m_desiredYmin = m_posY - (m_scrY - m_marginTop - m_marginBottom) / m_scaleY; // m_desiredYmin = m_posY - m_scrY / m_scaleY;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// printf("desired xmin %.1f ymin %.1f xmax %.1f ymax %.1f l %d\n", m_desiredXmin, m_desiredYmin, m_desiredXmax, m_desiredYmax, !!m_enableLimitedView);
|
|
|
|
// printf("current xmin %.1f ymin %.1f xmax %.1f ymax %.1f\n", m_minX, m_minY, m_maxX, m_maxY);
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( !CheckXLimits( m_desiredXmax,
|
|
|
|
m_desiredXmin ) || !CheckYLimits( m_desiredYmax, m_desiredYmin ) )
|
2016-08-11 12:41:37 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
// printf("call fit()\n");
|
2016-08-11 12:41:37 +00:00
|
|
|
Fit();
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
#ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
wxLogMessage(
|
|
|
|
"mpWindow::ZoomOut() prior coords: (%f,%f), new coords: (%f,%f) SHOULD BE EQUAL!!",
|
|
|
|
prior_layer_x, prior_layer_y, p2x( c.x ), p2y( c.y ) );
|
2016-08-11 12:41:21 +00:00
|
|
|
#endif
|
|
|
|
UpdateAll();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
void mpWindow::ZoomInX()
|
|
|
|
{
|
|
|
|
m_scaleX = m_scaleX * zoomIncrementalFactor;
|
|
|
|
UpdateAll();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
void mpWindow::ZoomOutX()
|
|
|
|
{
|
|
|
|
m_scaleX = m_scaleX / zoomIncrementalFactor;
|
|
|
|
UpdateAll();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
void mpWindow::ZoomInY()
|
|
|
|
{
|
|
|
|
m_scaleY = m_scaleY * zoomIncrementalFactor;
|
|
|
|
UpdateAll();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
void mpWindow::ZoomOutY()
|
|
|
|
{
|
|
|
|
m_scaleY = m_scaleY / zoomIncrementalFactor;
|
|
|
|
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
|
|
|
|
|
|
|
#ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
wxLogMessage( "Zoom: (%f,%f)-(%f,%f)", zoom_x_min, zoom_y_min, zoom_x_max, zoom_y_max );
|
2016-08-11 12:41:21 +00:00
|
|
|
#endif
|
|
|
|
|
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::LockAspect( bool enable )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
m_lockaspect = enable;
|
2016-08-12 08:10:33 +00:00
|
|
|
m_popmenu.Check( mpID_LOCKASPECT, enable );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// Try to fit again with the new config:
|
|
|
|
Fit( m_desiredXmin, m_desiredXmax, m_desiredYmin, m_desiredYmax );
|
|
|
|
}
|
|
|
|
|
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::OnLockAspect( wxCommandEvent& WXUNUSED( event ) )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
LockAspect( !m_lockaspect );
|
|
|
|
}
|
|
|
|
|
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 );
|
|
|
|
int centerX = (m_scrX - m_marginLeft - m_marginRight) / 2; // + m_marginLeft; // c.x = m_scrX/2;
|
|
|
|
int centerY = (m_scrY - m_marginTop - m_marginBottom) / 2; // - m_marginTop; // c.y = m_scrY/2;
|
|
|
|
SetPos( p2x( m_clickedX - centerX ), p2y( m_clickedY - centerY ) );
|
|
|
|
// SetPos( p2x(m_clickedX-m_scrX/2), p2y(m_clickedY-m_scrY/2) ); //SetPos( (double)(m_clickedX-m_scrX/2) / m_scaleX + m_posX, (double)(m_scrY/2-m_clickedY) / m_scaleY + m_posY);
|
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 );
|
|
|
|
#ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
wxLogMessage( "mpWindow::OnSize() m_scrX = %d, m_scrY = %d", m_scrX, m_scrY );
|
|
|
|
#endif // MATHPLOT_DO_LOGGING
|
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::AddLayer( mpLayer* layer, bool refreshDisplay )
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( layer != NULL )
|
|
|
|
{
|
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
|
|
|
|
|
|
|
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
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// void mpWindow::DoPrepareDC(wxDC& dc)
|
|
|
|
// {
|
2016-08-12 08:10:33 +00:00
|
|
|
// dc.SetDeviceOrigin(x2p(m_minX), y2p(m_maxY));
|
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
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
wxPaintDC dc( this );
|
|
|
|
|
|
|
|
dc.GetSize( &m_scrX, &m_scrY ); // This is the size of the visible area only!
|
|
|
|
// DoPrepareDC(dc);
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
#ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
wxLogMessage( "[mpWindow::OnPaint] vis.area: x %i y%i", m_scrX, m_scrY );
|
2016-08-11 12:41:21 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Selects direct or buffered draw:
|
2016-08-12 08:10:33 +00:00
|
|
|
wxDC* trgDc;
|
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
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( 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
|
|
|
if( m_buff_bmp )
|
|
|
|
delete m_buff_bmp;
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
trgDc = &m_buff_dc;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
trgDc = &dc;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw background:
|
2016-08-12 08:10:33 +00:00
|
|
|
// trgDc->SetDeviceOrigin(0,0);
|
2016-08-11 12:41:21 +00:00
|
|
|
trgDc->SetPen( *wxTRANSPARENT_PEN );
|
|
|
|
wxBrush brush( GetBackgroundColour() );
|
|
|
|
trgDc->SetBrush( brush );
|
2016-08-12 08:10:33 +00:00
|
|
|
trgDc->SetTextForeground( m_fgColour );
|
|
|
|
trgDc->DrawRectangle( 0, 0, m_scrX, m_scrY );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// Draw all the layers:
|
2016-08-12 08:10:33 +00:00
|
|
|
// trgDc->SetDeviceOrigin( m_scrX>>1, m_scrY>>1); // Origin at the center
|
2016-08-11 12:41:21 +00:00
|
|
|
wxLayerList::iterator li;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
for( li = m_layers.begin(); li != m_layers.end(); li++ )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
(*li)->Plot( *trgDc, *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 );
|
|
|
|
trgDc->SetPen( pen );
|
|
|
|
trgDc->SetBrush( *wxTRANSPARENT_BRUSH );
|
|
|
|
trgDc->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 )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
// trgDc->SetDeviceOrigin(0,0);
|
|
|
|
// dc.SetDeviceOrigin(0,0); // Origin at the center
|
|
|
|
dc.Blit( 0, 0, m_scrX, m_scrY, trgDc, 0, 0 );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if (m_coordTooltip) {
|
2016-08-12 08:10:33 +00:00
|
|
|
* wxString toolTipContent;
|
|
|
|
* wxPoint mousePoint = wxGetMousePosition();
|
|
|
|
* toolTipContent.Printf( "X = %f\nY = %f", p2x(mousePoint.x), p2y(mousePoint.y));
|
|
|
|
* SetToolTip(toolTipContent);
|
|
|
|
* }*/
|
2016-08-11 12:41:21 +00:00
|
|
|
// If scrollbars are enabled, refresh them
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_enableScrollBars )
|
|
|
|
{
|
2016-08-11 12:41:27 +00:00
|
|
|
/* m_scroll.x = (int) floor((m_posX - m_minX)*m_scaleX);
|
2016-08-12 08:10:33 +00:00
|
|
|
* m_scroll.y = (int) floor((m_maxY - m_posY )*m_scaleY);
|
|
|
|
* Scroll(m_scroll.x, m_scroll.y);*/
|
2016-08-11 12:41:21 +00:00
|
|
|
// Scroll(x2p(m_posX), y2p(m_posY));
|
2016-08-12 08:10:33 +00:00
|
|
|
// SetVirtualSize((int) ((m_maxX - m_minX)*m_scaleX), (int) ((m_maxY - m_minY)*m_scaleY));
|
|
|
|
// int centerX = (m_scrX - m_marginLeft - m_marginRight)/2; // + m_marginLeft; // c.x = m_scrX/2;
|
|
|
|
// int centerY = (m_scrY - m_marginTop - m_marginBottom)/2; // - m_marginTop; // c.y = m_scrY/2;
|
|
|
|
/*SetScrollbars(1, 1, (int) ((m_maxX - m_minX)*m_scaleX), (int) ((m_maxY - m_minY)*m_scaleY));*/ // , x2p(m_posX + centerX/m_scaleX), y2p(m_posY - centerY/m_scaleY), 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::OnScroll2(wxScrollWinEvent &event)
|
|
|
|
// {
|
|
|
|
// #ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
// wxLogMessage( "[mpWindow::OnScroll2] Init: m_posX=%f m_posY=%f, sc_pos = %d",m_posX,m_posY, event.GetPosition());
|
2016-08-11 12:41:21 +00:00
|
|
|
// #endif
|
2016-08-12 08:10:33 +00:00
|
|
|
//// If scrollbars are not enabled, Skip operation
|
|
|
|
// if (!m_enableScrollBars) {
|
|
|
|
// event.Skip();
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
//// m_scroll.x = (int) floor((m_posX - m_minX)*m_scaleX);
|
|
|
|
//// m_scroll.y = (int) floor((m_maxY - m_posY /*- m_minY*/)*m_scaleY);
|
|
|
|
//// Scroll(m_scroll.x, m_scroll.y);
|
2016-08-11 12:41:21 +00:00
|
|
|
//
|
2016-08-12 08:10:33 +00:00
|
|
|
//// GetClientSize( &m_scrX, &m_scrY);
|
|
|
|
////Scroll(x2p(m_desiredXmin), y2p(m_desiredYmin));
|
|
|
|
// int pixelStep = 1;
|
|
|
|
// if (event.GetOrientation() == wxHORIZONTAL) {
|
|
|
|
////m_desiredXmin -= (m_scroll.x - event.GetPosition())/m_scaleX;
|
|
|
|
////m_desiredXmax -= (m_scroll.x - event.GetPosition())/m_scaleX;
|
|
|
|
// m_posX -= (m_scroll.x - event.GetPosition())/m_scaleX;
|
|
|
|
// m_scroll.x = event.GetPosition();
|
|
|
|
// }
|
|
|
|
// Fit(m_desiredXmin, m_desiredXmax, m_desiredYmin, m_desiredYmax);
|
|
|
|
//// /* int pixelStep = 1;
|
|
|
|
//// if (event.GetOrientation() == wxHORIZONTAL) {
|
|
|
|
//// m_posX -= (px - event.GetPosition())/m_scaleX;//(pixelStep/m_scaleX);
|
|
|
|
//// m_desiredXmax -= (px - event.GetPosition())/m_scaleX;//(pixelStep/m_scaleX);
|
|
|
|
//// m_desiredXmin -= (px - event.GetPosition())/m_scaleX;//(pixelStep/m_scaleX);
|
|
|
|
//// //SetPosX( (double)px / GetScaleX() + m_minX + (double)(width>>1)/GetScaleX());
|
|
|
|
//// // m_posX = p2x(px); //m_minX + (double)(px /*+ (m_scrX)*/)/GetScaleX();
|
|
|
|
//// } else {
|
|
|
|
//// m_posY += (py - event.GetPosition())/m_scaleY;//(pixelStep/m_scaleY);
|
|
|
|
//// m_desiredYmax += (py - event.GetPosition())/m_scaleY;//(pixelStep/m_scaleY);
|
|
|
|
//// m_desiredYmax += (py - event.GetPosition())/m_scaleY;//(pixelStep/m_scaleY);
|
|
|
|
//// //SetPosY( m_maxY - (double)py / GetScaleY() - (double)(height>>1)/GetScaleY());
|
|
|
|
//// //m_posY = m_maxY - (double)py / GetScaleY() - (double)(height>>1)/GetScaleY();
|
|
|
|
//// // m_posY = p2y(py);//m_maxY - (double)(py /*+ (m_scrY)*/)/GetScaleY();
|
|
|
|
//// }*/
|
2016-08-11 12:41:21 +00:00
|
|
|
// #ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
// int px, py;
|
|
|
|
// GetViewStart( &px, &py);
|
|
|
|
// wxLogMessage( "[mpWindow::OnScroll2] End: m_posX = %f, m_posY = %f, px = %f, py = %f",m_posX, m_posY, px, py);
|
2016-08-11 12:41:21 +00:00
|
|
|
// #endif
|
|
|
|
//
|
2016-08-12 08:10:33 +00:00
|
|
|
// UpdateAll();
|
|
|
|
//// event.Skip();
|
2016-08-11 12:41:21 +00:00
|
|
|
// }
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
void mpWindow::SetMPScrollbars( bool status )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
// Temporary behaviour: always disable scrollbars
|
2016-08-12 08:10:33 +00:00
|
|
|
m_enableScrollBars = status; // false;
|
|
|
|
|
|
|
|
if( status == false )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
SetScrollbar( wxHORIZONTAL, 0, 0, 0 );
|
|
|
|
SetScrollbar( wxVERTICAL, 0, 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
|
|
|
// else the scroll bars will be updated in UpdateAll();
|
|
|
|
UpdateAll();
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// EnableScrolling(false, false);
|
|
|
|
// m_enableScrollBars = status;
|
|
|
|
// EnableScrolling(status, status);
|
2016-08-11 12:41:27 +00:00
|
|
|
/* m_scroll.x = (int) floor((m_posX - m_minX)*m_scaleX);
|
2016-08-12 08:10:33 +00:00
|
|
|
* m_scroll.y = (int) floor((m_posY - m_minY)*m_scaleY);*/
|
|
|
|
// int scrollWidth = (int) floor((m_maxX - m_minX)*m_scaleX) - m_scrX;
|
|
|
|
// int scrollHeight = (int) floor((m_minY - m_maxY)*m_scaleY) - m_scrY;
|
|
|
|
|
|
|
|
///* m_scroll.x = (int) floor((m_posX - m_minX)*m_scaleX);
|
|
|
|
// m_scroll.y = (int) floor((m_maxY - m_posY /*- m_minY*/)*m_scaleY);
|
|
|
|
// int scrollWidth = (int) floor(((m_maxX - m_minX) - (m_desiredXmax - m_desiredXmin))*m_scaleX);
|
|
|
|
// int scrollHeight = (int) floor(((m_maxY - m_minY) - (m_desiredYmax - m_desiredYmin))*m_scaleY);
|
2016-08-11 12:41:21 +00:00
|
|
|
// #ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
// wxLogMessage( "mpWindow::SetMPScrollbars() scrollWidth = %d, scrollHeight = %d", scrollWidth, scrollHeight);
|
2016-08-11 12:41:21 +00:00
|
|
|
// #endif
|
2016-08-12 08:10:33 +00:00
|
|
|
// if(status) {
|
|
|
|
// SetScrollbars(1,
|
|
|
|
// 1,
|
|
|
|
// scrollWidth,
|
|
|
|
// scrollHeight,
|
|
|
|
// m_scroll.x,
|
|
|
|
// m_scroll.y);
|
|
|
|
//// SetVirtualSize((int) (m_maxX - m_minX), (int) (m_maxY - m_minY));
|
|
|
|
// }
|
|
|
|
// Refresh(false);*/
|
2016-08-11 12:41:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
bool mpWindow::UpdateBBox()
|
|
|
|
{
|
|
|
|
bool first = TRUE;
|
|
|
|
|
2016-08-11 12:41:48 +00:00
|
|
|
|
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:42:18 +00:00
|
|
|
#if 0
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
for( wxLayerList::iterator li = m_layers.begin(); li != m_layers.end(); li++ )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
mpLayer* f = *li;
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( f->HasBBox() )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( first )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
first = FALSE;
|
2016-08-12 08:10:33 +00:00
|
|
|
m_minX = f->GetMinX(); m_maxX = f->GetMaxX();
|
|
|
|
m_minY = f->GetMinY(); m_maxY = f->GetMaxY();
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( f->GetMinX()<m_minX )
|
|
|
|
m_minX = f->GetMinX();
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( f->GetMaxX()>m_maxX )
|
|
|
|
m_maxX = f->GetMaxX();
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( f->GetMinY()<m_minY )
|
|
|
|
m_minY = f->GetMinY();
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( f->GetMaxY()>m_maxY )
|
|
|
|
m_maxY = f->GetMaxY();
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
// node = node->GetNext();
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-11 12:42:18 +00:00
|
|
|
#endif
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
#ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
wxLogDebug( wxT(
|
|
|
|
"[mpWindow::UpdateBBox] Bounding box: Xmin = %f, Xmax = %f, Ymin = %f, YMax = %f" ), m_minX, m_maxX, m_minY,
|
|
|
|
m_maxY );
|
|
|
|
#endif // MATHPLOT_DO_LOGGING
|
2016-08-11 12:41:21 +00:00
|
|
|
return first == FALSE;
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// void mpWindow::UpdateAll()
|
|
|
|
// {
|
|
|
|
// GetClientSize( &m_scrX,&m_scrY);
|
|
|
|
/* if (m_enableScrollBars) {
|
2016-08-12 08:10:33 +00:00
|
|
|
* // The "virtual size" of the scrolled window:
|
|
|
|
* const int sx = (int)((m_maxX - m_minX) * GetScaleX());
|
|
|
|
* const int sy = (int)((m_maxY - m_minY) * GetScaleY());
|
|
|
|
* SetVirtualSize(sx, sy);
|
|
|
|
* SetScrollRate(1, 1);*/
|
|
|
|
// const int px = (int)((GetPosX() - m_minX) * GetScaleX());// - m_scrX); //(cx>>1));
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// J.L.Blanco, Aug 2007: Formula fixed:
|
2016-08-12 08:10:33 +00:00
|
|
|
// const int py = (int)((m_maxY - GetPosY()) * GetScaleY());// - m_scrY); //(cy>>1));
|
|
|
|
// int px, py;
|
|
|
|
// GetViewStart(&px0, &py0);
|
|
|
|
// px = (int)((m_posX - m_minX)*m_scaleX);
|
|
|
|
// py = (int)((m_maxY - m_posY)*m_scaleY);
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// SetScrollbars( 1, 1, sx - m_scrX, sy - m_scrY, px, py, TRUE);
|
|
|
|
// }
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// Working code
|
2016-08-12 08:10:33 +00:00
|
|
|
// UpdateBBox();
|
|
|
|
// Refresh( FALSE );
|
2016-08-11 12:41:21 +00:00
|
|
|
// end working code
|
|
|
|
|
|
|
|
// Old version
|
|
|
|
/* bool box = UpdateBBox();
|
2016-08-12 08:10:33 +00:00
|
|
|
* if (box)
|
|
|
|
* {
|
|
|
|
* int cx, cy;
|
|
|
|
* GetClientSize( &cx, &cy);
|
|
|
|
*
|
|
|
|
* // The "virtual size" of the scrolled window:
|
|
|
|
* const int sx = (int)((m_maxX - m_minX) * GetScaleX());
|
|
|
|
* const int sy = (int)((m_maxY - m_minY) * GetScaleY());
|
|
|
|
*
|
|
|
|
* const int px = (int)((GetPosX() - m_minX) * GetScaleX() - (cx>>1));
|
|
|
|
*
|
|
|
|
* // J.L.Blanco, Aug 2007: Formula fixed:
|
|
|
|
* const int py = (int)((m_maxY - GetPosY()) * GetScaleY() - (cy>>1));
|
|
|
|
*
|
|
|
|
* SetScrollbars( 1, 1, sx, sy, px, py, TRUE);
|
|
|
|
*
|
|
|
|
* #ifdef MATHPLOT_DO_LOGGING
|
|
|
|
* wxLogMessage( "[mpWindow::UpdateAll] Size:%ix%i ScrollBars:%i,%i",sx,sy,px,py);
|
|
|
|
* #endif
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* FitInside();
|
|
|
|
* Refresh( FALSE );
|
|
|
|
*/
|
2016-08-11 12:41:21 +00:00
|
|
|
// }
|
|
|
|
|
|
|
|
void mpWindow::UpdateAll()
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( UpdateBBox() )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_enableScrollBars )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
int cx, cy;
|
2016-08-12 08:10:33 +00:00
|
|
|
GetClientSize( &cx, &cy );
|
2016-08-11 12:41:21 +00:00
|
|
|
// Do x scroll bar
|
|
|
|
{
|
|
|
|
// Convert margin sizes from pixels to coordinates
|
2016-08-12 08:10:33 +00:00
|
|
|
double leftMargin = m_marginLeft / m_scaleX;
|
2016-08-11 12:41:21 +00:00
|
|
|
// Calculate the range in coords that we want to scroll over
|
2016-08-12 08:10:33 +00:00
|
|
|
double maxX = (m_desiredXmax > m_maxX) ? m_desiredXmax : m_maxX;
|
|
|
|
double minX = (m_desiredXmin < m_minX) ? m_desiredXmin : m_minX;
|
|
|
|
|
|
|
|
if( (m_posX + leftMargin) < minX )
|
2016-08-11 12:41:21 +00:00
|
|
|
minX = m_posX + leftMargin;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// Calculate scroll bar size and thumb position
|
2016-08-12 08:10:33 +00:00
|
|
|
int sizeX = (int) ( (maxX - minX) * m_scaleX );
|
|
|
|
int thumbX = (int) ( ( (m_posX + leftMargin) - minX ) * m_scaleX );
|
|
|
|
SetScrollbar( wxHORIZONTAL, thumbX, cx - (m_marginRight + m_marginLeft), sizeX );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
// Do y scroll bar
|
|
|
|
{
|
|
|
|
// Convert margin sizes from pixels to coordinates
|
|
|
|
double topMargin = m_marginTop / m_scaleY;
|
|
|
|
// Calculate the range in coords that we want to scroll over
|
|
|
|
double maxY = (m_desiredYmax > m_maxY) ? m_desiredYmax : m_maxY;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
if( (m_posY - topMargin) > maxY )
|
2016-08-11 12:41:21 +00:00
|
|
|
maxY = m_posY - topMargin;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
double minY = (m_desiredYmin < m_minY) ? m_desiredYmin : m_minY;
|
|
|
|
// Calculate scroll bar size and thumb position
|
2016-08-12 08:10:33 +00:00
|
|
|
int sizeY = (int) ( (maxY - minY) * m_scaleY );
|
|
|
|
int thumbY = (int) ( ( maxY - (m_posY - topMargin) ) * m_scaleY );
|
|
|
|
SetScrollbar( wxVERTICAL, thumbY, cy - (m_marginTop + m_marginBottom), sizeY );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Refresh( FALSE );
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpWindow::DoScrollCalc( const int position, const int orientation )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( orientation == wxVERTICAL )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
// Y axis
|
|
|
|
// Get top margin in coord units
|
|
|
|
double topMargin = m_marginTop / m_scaleY;
|
|
|
|
// Calculate maximum Y coord to be shown in the graph
|
|
|
|
double maxY = m_desiredYmax > m_maxY ? m_desiredYmax : m_maxY;
|
|
|
|
// Set new position
|
2016-08-12 08:10:33 +00:00
|
|
|
SetPosY( ( maxY - (position / m_scaleY) ) + topMargin );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// X Axis
|
|
|
|
// Get left margin in coord units
|
2016-08-12 08:10:33 +00:00
|
|
|
double leftMargin = m_marginLeft / m_scaleX;
|
2016-08-11 12:41:21 +00:00
|
|
|
// Calculate minimum X coord to be shown in the graph
|
|
|
|
double minX = (m_desiredXmin < m_minX) ? m_desiredXmin : m_minX;
|
|
|
|
// Set new position
|
2016-08-12 08:10:33 +00:00
|
|
|
SetPosX( ( minX + (position / m_scaleX) ) - leftMargin );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpWindow::OnScrollThumbTrack( wxScrollWinEvent& event )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
DoScrollCalc( event.GetPosition(), event.GetOrientation() );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpWindow::OnScrollPageUp( wxScrollWinEvent& event )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
int scrollOrientation = event.GetOrientation();
|
|
|
|
// Get position before page up
|
2016-08-12 08:10:33 +00:00
|
|
|
int position = GetScrollPos( scrollOrientation );
|
2016-08-11 12:41:21 +00:00
|
|
|
// Get thumb size
|
2016-08-12 08:10:33 +00:00
|
|
|
int thumbSize = GetScrollThumb( scrollOrientation );
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// Need to adjust position by a page
|
|
|
|
position -= thumbSize;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
if( position < 0 )
|
2016-08-11 12:41:21 +00:00
|
|
|
position = 0;
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
DoScrollCalc( position, scrollOrientation );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
void mpWindow::OnScrollPageDown( wxScrollWinEvent& event )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
int scrollOrientation = event.GetOrientation();
|
|
|
|
// Get position before page up
|
2016-08-12 08:10:33 +00:00
|
|
|
int position = GetScrollPos( scrollOrientation );
|
2016-08-11 12:41:21 +00:00
|
|
|
// Get thumb size
|
2016-08-12 08:10:33 +00:00
|
|
|
int thumbSize = GetScrollThumb( scrollOrientation );
|
2016-08-11 12:41:21 +00:00
|
|
|
// Get scroll range
|
2016-08-12 08:10:33 +00:00
|
|
|
int scrollRange = GetScrollRange( scrollOrientation );
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// Need to adjust position by a page
|
|
|
|
position += thumbSize;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
if( position > (scrollRange - thumbSize) )
|
2016-08-11 12:41:21 +00:00
|
|
|
position = scrollRange - thumbSize;
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
DoScrollCalc( position, scrollOrientation );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpWindow::OnScrollLineUp( wxScrollWinEvent& event )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
int scrollOrientation = event.GetOrientation();
|
|
|
|
// Get position before page up
|
2016-08-12 08:10:33 +00:00
|
|
|
int position = GetScrollPos( scrollOrientation );
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// Need to adjust position by a line
|
|
|
|
position -= mpSCROLL_NUM_PIXELS_PER_LINE;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
if( position < 0 )
|
2016-08-11 12:41:21 +00:00
|
|
|
position = 0;
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
DoScrollCalc( position, scrollOrientation );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpWindow::OnScrollLineDown( wxScrollWinEvent& event )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
int scrollOrientation = event.GetOrientation();
|
|
|
|
// Get position before page up
|
2016-08-12 08:10:33 +00:00
|
|
|
int position = GetScrollPos( scrollOrientation );
|
2016-08-11 12:41:21 +00:00
|
|
|
// Get thumb size
|
2016-08-12 08:10:33 +00:00
|
|
|
int thumbSize = GetScrollThumb( scrollOrientation );
|
2016-08-11 12:41:21 +00:00
|
|
|
// Get scroll range
|
2016-08-12 08:10:33 +00:00
|
|
|
int scrollRange = GetScrollRange( scrollOrientation );
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// Need to adjust position by a page
|
|
|
|
position += mpSCROLL_NUM_PIXELS_PER_LINE;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
if( position > (scrollRange - thumbSize) )
|
2016-08-11 12:41:21 +00:00
|
|
|
position = scrollRange - thumbSize;
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
DoScrollCalc( position, scrollOrientation );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpWindow::OnScrollTop( wxScrollWinEvent& event )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
DoScrollCalc( 0, event.GetOrientation() );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpWindow::OnScrollBottom( wxScrollWinEvent& event )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
int scrollOrientation = event.GetOrientation();
|
|
|
|
// Get thumb size
|
2016-08-12 08:10:33 +00:00
|
|
|
int thumbSize = GetScrollThumb( scrollOrientation );
|
2016-08-11 12:41:21 +00:00
|
|
|
// Get scroll range
|
2016-08-12 08:10:33 +00:00
|
|
|
int scrollRange = GetScrollRange( scrollOrientation );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
DoScrollCalc( scrollRange - thumbSize, scrollOrientation );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// End patch ngpaton
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
void mpWindow::SetScaleX( double scaleX )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( scaleX!=0 )
|
|
|
|
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
|
|
|
|
|
|
|
|
unsigned int mpWindow::CountLayers()
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
// wxNode *node = m_layers.GetFirst();
|
2016-08-11 12:41:21 +00:00
|
|
|
unsigned int layerNo = 0;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
for( wxLayerList::iterator li = m_layers.begin(); li != m_layers.end(); li++ ) // while(node)
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( (*li)->HasBBox() )
|
|
|
|
layerNo++;
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// node = node->GetNext();
|
2016-08-12 08:10:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
;
|
2016-08-11 12:41:21 +00:00
|
|
|
return layerNo;
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
mpLayer* mpWindow::GetLayer( int position )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( ( position >= (int) m_layers.size() ) || position < 0 )
|
|
|
|
return NULL;
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
return m_layers[position];
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
mpLayer* mpWindow::GetLayerByName( const wxString& name )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
for( wxLayerList::iterator it = m_layers.begin(); it!=m_layers.end(); it++ )
|
|
|
|
if( !(*it)->GetName().Cmp( name ) )
|
2016-08-11 12:41:21 +00:00
|
|
|
return *it;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
return NULL; // Not found
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpWindow::GetBoundingBox( double* bbox )
|
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
|
|
|
|
2016-08-11 12:42:15 +00:00
|
|
|
bool mpWindow::SaveScreenshot( const wxString& filename, wxBitmapType type,
|
2016-08-11 12:42:18 +00:00
|
|
|
wxSize imageSize, bool fit )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
int sizeX, sizeY;
|
|
|
|
int bk_scrX, bk_scrY;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
if( imageSize == wxDefaultSize )
|
|
|
|
{
|
|
|
|
sizeX = m_scrX;
|
|
|
|
sizeY = m_scrY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sizeX = imageSize.x;
|
|
|
|
sizeY = imageSize.y;
|
2016-08-11 12:41:21 +00:00
|
|
|
bk_scrX = m_scrX;
|
|
|
|
bk_scrY = m_scrY;
|
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 );
|
2016-08-11 12:41:21 +00:00
|
|
|
screenDC.SetPen( *wxTRANSPARENT_PEN );
|
|
|
|
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
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// Draw all the layers:
|
|
|
|
wxLayerList::iterator li;
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
for( li = m_layers.begin(); li != m_layers.end(); li++ )
|
|
|
|
(*li)->Plot( screenDC, *this );
|
|
|
|
|
|
|
|
if( imageSize != wxDefaultSize )
|
|
|
|
{
|
2016-08-11 12:41:21 +00:00
|
|
|
// Restore dimensions
|
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
|
|
|
{
|
|
|
|
m_marginTop = top;
|
2016-08-12 08:10:33 +00:00
|
|
|
m_marginRight = right;
|
|
|
|
m_marginBottom = bottom;
|
2016-08-11 12:41:21 +00:00
|
|
|
m_marginLeft = left;
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
mpInfoLayer* mpWindow::IsInsideInfoLayer( wxPoint& point )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
wxLayerList::iterator li;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
for( li = m_layers.begin(); li != m_layers.end(); li++ )
|
|
|
|
{
|
2016-08-11 12:41:21 +00:00
|
|
|
#ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
wxLogMessage( "mpWindow::IsInsideInfoLayer() examinining layer = %p", (*li) );
|
|
|
|
#endif // MATHPLOT_DO_LOGGING
|
|
|
|
|
|
|
|
if( (*li)->IsInfo() )
|
|
|
|
{
|
2016-08-11 12:41:21 +00:00
|
|
|
mpInfoLayer* tmpLyr = (mpInfoLayer*) (*li);
|
|
|
|
#ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
wxLogMessage( "mpWindow::IsInsideInfoLayer() layer = %p", (*li) );
|
|
|
|
#endif // MATHPLOT_DO_LOGGING
|
|
|
|
|
|
|
|
if( tmpLyr->Inside( point ) )
|
|
|
|
{
|
2016-08-11 12:41:21 +00:00
|
|
|
return tmpLyr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpWindow::SetLayerVisible( const wxString& name, bool viewable )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
mpLayer* lx = GetLayerByName( name );
|
|
|
|
|
|
|
|
if( lx )
|
|
|
|
{
|
|
|
|
lx->SetVisible( viewable );
|
2016-08-11 12:41:21 +00:00
|
|
|
UpdateAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
bool mpWindow::IsLayerVisible( const wxString& name )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
mpLayer* lx = GetLayerByName( name );
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
return (lx) ? lx->IsVisible() : false;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
mpLayer* lx = GetLayer( position );
|
|
|
|
|
|
|
|
if( lx )
|
|
|
|
{
|
|
|
|
lx->SetVisible( viewable );
|
2016-08-11 12:41:21 +00:00
|
|
|
UpdateAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
bool mpWindow::IsLayerVisible( const unsigned int position )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
mpLayer* lx = GetLayer( position );
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
return (lx) ? lx->IsVisible() : false;
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +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;
|
2016-08-11 12:41:21 +00:00
|
|
|
// cycle between layers to set colours and properties to them
|
|
|
|
wxLayerList::iterator li;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
for( li = m_layers.begin(); li != m_layers.end(); li++ )
|
|
|
|
{
|
|
|
|
if( (*li)->GetLayerType() == mpLAYER_AXIS )
|
|
|
|
{
|
|
|
|
wxPen axisPen = (*li)->GetPen(); // Get the old pen to modify only colour, not style or width
|
|
|
|
axisPen.SetColour( axesColour );
|
|
|
|
(*li)->SetPen( axisPen );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
if( (*li)->GetLayerType() == mpLAYER_INFO )
|
|
|
|
{
|
|
|
|
wxPen infoPen = (*li)->GetPen(); // Get the old pen to modify only colour, not style or width
|
|
|
|
infoPen.SetColour( drawColour );
|
|
|
|
(*li)->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
|
|
|
// void mpWindow::EnableCoordTooltip(bool value)
|
|
|
|
// {
|
2016-08-12 08:10:33 +00:00
|
|
|
// m_coordTooltip = value;
|
|
|
|
//// if (value) GetToolTip()->SetDelay(100);
|
2016-08-11 12:41:21 +00:00
|
|
|
// }
|
|
|
|
|
|
|
|
/*
|
2016-08-12 08:10:33 +00:00
|
|
|
* double mpWindow::p2x(wxCoord pixelCoordX, bool drawOutside )
|
|
|
|
* {
|
|
|
|
* if (drawOutside) {
|
|
|
|
* return m_posX + pixelCoordX/m_scaleX;
|
|
|
|
* }
|
|
|
|
* // Draw inside margins
|
|
|
|
* double marginScaleX = ((double)(m_scrX - m_marginLeft - m_marginRight))/m_scrX;
|
|
|
|
* return m_marginLeft + (m_posX + pixelCoordX/m_scaleX)/marginScaleX;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* double mpWindow::p2y(wxCoord pixelCoordY, bool drawOutside )
|
|
|
|
* {
|
|
|
|
* if (drawOutside) {
|
|
|
|
* return m_posY - pixelCoordY/m_scaleY;
|
|
|
|
* }
|
|
|
|
* // Draw inside margins
|
|
|
|
* double marginScaleY = ((double)(m_scrY - m_marginTop - m_marginBottom))/m_scrY;
|
|
|
|
* return m_marginTop + (m_posY - pixelCoordY/m_scaleY)/marginScaleY;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* wxCoord mpWindow::x2p(double x, bool drawOutside)
|
|
|
|
* {
|
|
|
|
* if (drawOutside) {
|
|
|
|
* return (wxCoord) ((x-m_posX) * m_scaleX);
|
|
|
|
* }
|
|
|
|
* // Draw inside margins
|
|
|
|
* double marginScaleX = ((double)(m_scrX - m_marginLeft - m_marginRight))/m_scrX;
|
|
|
|
* #ifdef MATHPLOT_DO_LOGGING
|
|
|
|
* wxLogMessage(wxT("x2p ScrX = %d, marginRight = %d, marginLeft = %d, marginScaleX = %f"), m_scrX, m_marginRight, m_marginLeft, marginScaleX);
|
|
|
|
* #endif // MATHPLOT_DO_LOGGING
|
|
|
|
* return (wxCoord) (int)(((x-m_posX) * m_scaleX)*marginScaleX) - m_marginLeft;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* wxCoord mpWindow::y2p(double y, bool drawOutside)
|
|
|
|
* {
|
|
|
|
* if (drawOutside) {
|
|
|
|
* return (wxCoord) ( (m_posY-y) * m_scaleY);
|
|
|
|
* }
|
|
|
|
* // Draw inside margins
|
|
|
|
* double marginScaleY = ((double)(m_scrY - m_marginTop - m_marginBottom))/m_scrY;
|
|
|
|
* #ifdef MATHPLOT_DO_LOGGING
|
|
|
|
* wxLogMessage(wxT("y2p ScrY = %d, marginTop = %d, marginBottom = %d, marginScaleY = %f"), m_scrY, m_marginTop, m_marginBottom, marginScaleY);
|
|
|
|
* #endif // MATHPLOT_DO_LOGGING
|
|
|
|
* return (wxCoord) ((int)((m_posY-y) * m_scaleY)*marginScaleY) - m_marginTop;
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
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
|
|
|
|
mpFXYVector::mpFXYVector( wxString name, int flags ) : mpFXY( name, flags )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
m_index = 0;
|
2016-08-12 08:10:33 +00:00
|
|
|
// printf("FXYVector::FXYVector!\n");
|
2016-08-11 12:41:21 +00:00
|
|
|
m_minX = -1;
|
|
|
|
m_maxX = 1;
|
|
|
|
m_minY = -1;
|
|
|
|
m_maxY = 1;
|
2016-08-12 08:10:33 +00:00
|
|
|
m_type = mpLAYER_PLOT;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
double mpScaleX::TransformToPlot( double x )
|
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
|
|
|
|
|
|
|
double mpScaleX::TransformFromPlot( double xplot )
|
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
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double mpScaleY::TransformToPlot( double x )
|
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
|
|
|
|
|
|
|
double mpScaleY::TransformFromPlot( double xplot )
|
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-12 08:10:33 +00:00
|
|
|
double mpScaleXLog::TransformToPlot( double x )
|
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
|
|
|
|
|
|
|
double mpScaleXLog::TransformFromPlot( double xplot )
|
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:49 +00:00
|
|
|
#if 0
|
2016-08-12 08:10:33 +00:00
|
|
|
mpFSemiLogXVector::mpFSemiLogXVector( wxString name, int flags ) :
|
|
|
|
mpFXYVector( name, flags )
|
|
|
|
{
|
|
|
|
}
|
2016-08-11 12:41:48 +00:00
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
IMPLEMENT_DYNAMIC_CLASS( mpFSemiLogXVector, mpFXYVector )
|
2016-08-11 12:41:49 +00:00
|
|
|
#endif
|
2016-08-11 12:41:48 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
void mpFXYVector::Rewind()
|
|
|
|
{
|
|
|
|
m_index = 0;
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
bool mpFXYVector::GetNextXY( double& x, double& y )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_index>=m_xs.size() )
|
2016-08-11 12:41:21 +00:00
|
|
|
return FALSE;
|
|
|
|
else
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
x = m_xs[m_index];
|
|
|
|
y = m_ys[m_index++];
|
2016-08-11 12:41:21 +00:00
|
|
|
return m_index<=m_xs.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
// Check if the data vectora are of the same size
|
2016-08-12 08:10:33 +00:00
|
|
|
if( xs.size() != ys.size() )
|
|
|
|
{
|
|
|
|
wxLogError( "wxMathPlot error: X and Y vector are not of the same length!" );
|
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
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// printf("FXYVector::setData %d %d\n", xs.size(), ys.size());
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// Update internal variables for the bounding box.
|
2016-08-12 08:10:33 +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];
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
std::vector<double>::const_iterator it;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
for( it = xs.begin(); it!=xs.end(); it++ )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( *it<m_minX )
|
|
|
|
m_minX = *it;
|
|
|
|
|
|
|
|
if( *it>m_maxX )
|
|
|
|
m_maxX = *it;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
for( it = ys.begin(); it!=ys.end(); it++ )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( *it<m_minY )
|
|
|
|
m_minY = *it;
|
|
|
|
|
|
|
|
if( *it>m_maxY )
|
|
|
|
m_maxY = *it;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-11 12:41:49 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// printf("minX %.10f maxX %.10f\n ", m_minX, m_maxX );
|
|
|
|
// printf("minY %.10f maxY %.10f\n ", m_minY, m_maxY );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_minX = -1;
|
|
|
|
m_maxX = 1;
|
|
|
|
m_minY = -1;
|
|
|
|
m_maxY = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2016-08-11 12:41:21 +00:00
|
|
|
// mpText - provided by Val Greene
|
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( mpText, mpLayer )
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
/** @param name text to be displayed
|
|
|
|
* @param offsetx x position in percentage (0-100)
|
|
|
|
* @param offsetx y position in percentage (0-100)
|
|
|
|
*/
|
2016-08-11 12:41:21 +00:00
|
|
|
mpText::mpText( wxString name, int offsetx, int offsety )
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
SetName( name );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( offsetx >= 0 && offsetx <= 100 )
|
2016-08-11 12:41:21 +00:00
|
|
|
m_offsetx = offsetx;
|
|
|
|
else
|
|
|
|
m_offsetx = 5;
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( offsety >= 0 && offsety <= 100 )
|
2016-08-11 12:41:21 +00:00
|
|
|
m_offsety = offsety;
|
|
|
|
else
|
|
|
|
m_offsetx = 50;
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
m_type = mpLAYER_INFO;
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
/** mpText Layer plot handler.
|
2016-08-12 08:10:33 +00:00
|
|
|
* This implementation will plot the text adjusted to the visible area.
|
|
|
|
*/
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
void mpText::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 );
|
|
|
|
dc.SetFont( m_font );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
wxCoord tw = 0, th = 0;
|
|
|
|
dc.GetTextExtent( GetName(), &tw, &th );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
// int left = -dc.LogicalToDeviceX(0);
|
|
|
|
// int width = dc.LogicalToDeviceX(0) - left;
|
|
|
|
// int bottom = dc.LogicalToDeviceY(0);
|
|
|
|
// int height = bottom - -dc.LogicalToDeviceY(0);
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
/* dc.DrawText( GetName(),
|
2016-08-12 08:10:33 +00:00
|
|
|
* (int)((((float)width/100.0) * m_offsety) + left - (tw/2)),
|
|
|
|
* (int)((((float)height/100.0) * m_offsetx) - bottom) );*/
|
|
|
|
int px = m_offsetx * ( w.GetScrX() - w.GetMarginLeft() - w.GetMarginRight() ) / 100;
|
|
|
|
int py = m_offsety * ( w.GetScrY() - w.GetMarginTop() - w.GetMarginBottom() ) / 100;
|
|
|
|
dc.DrawText( GetName(), px, py );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2016-08-11 12:41:21 +00:00
|
|
|
// mpPrintout - provided by Davide Rondini
|
2016-08-12 08:10:33 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
mpPrintout::mpPrintout( mpWindow* drawWindow, const wxChar* title ) : wxPrintout( title )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
drawn = false;
|
|
|
|
plotWindow = drawWindow;
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
bool mpPrintout::OnPrintPage( int page )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
wxDC* trgDc = GetDC();
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( (trgDc) && (page == 1) )
|
|
|
|
{
|
2016-08-11 12:41:21 +00:00
|
|
|
wxCoord m_prnX, m_prnY;
|
|
|
|
int marginX = 50;
|
|
|
|
int marginY = 50;
|
2016-08-12 08:10:33 +00:00
|
|
|
trgDc->GetSize( &m_prnX, &m_prnY );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
m_prnX -= (2 * marginX);
|
|
|
|
m_prnY -= (2 * marginY);
|
|
|
|
trgDc->SetDeviceOrigin( marginX, marginY );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
#ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
wxLogMessage( wxT( "Print Size: %d x %d\n" ), m_prnX, m_prnY );
|
|
|
|
wxLogMessage( wxT( "Screen Size: %d x %d\n" ), plotWindow->GetScrX(),
|
|
|
|
plotWindow->GetScrY() );
|
2016-08-11 12:41:21 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Set the scale according to the page:
|
|
|
|
plotWindow->Fit(
|
|
|
|
plotWindow->GetDesiredXmin(),
|
|
|
|
plotWindow->GetDesiredXmax(),
|
|
|
|
plotWindow->GetDesiredYmin(),
|
|
|
|
plotWindow->GetDesiredYmax(),
|
|
|
|
&m_prnX,
|
|
|
|
&m_prnY );
|
|
|
|
|
|
|
|
// Get the colours of the plotWindow to restore them ath the end
|
2016-08-12 08:10:33 +00:00
|
|
|
wxColour oldBgColour = plotWindow->GetBackgroundColour();
|
|
|
|
wxColour oldFgColour = plotWindow->GetForegroundColour();
|
|
|
|
wxColour oldAxColour = plotWindow->GetAxesColour();
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// Draw background, ensuring to use white background for printing.
|
|
|
|
trgDc->SetPen( *wxTRANSPARENT_PEN );
|
|
|
|
// wxBrush brush( plotWindow->GetBackgroundColour() );
|
|
|
|
wxBrush brush = *wxWHITE_BRUSH;
|
|
|
|
trgDc->SetBrush( brush );
|
2016-08-12 08:10:33 +00:00
|
|
|
trgDc->DrawRectangle( 0, 0, m_prnX, m_prnY );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// Draw all the layers:
|
2016-08-12 08:10:33 +00:00
|
|
|
// trgDc->SetDeviceOrigin( m_prnX>>1, m_prnY>>1); // Origin at the center
|
|
|
|
mpLayer* layer;
|
|
|
|
|
|
|
|
for( unsigned int li = 0; li < plotWindow->CountAllLayers(); li++ )
|
|
|
|
{
|
|
|
|
layer = plotWindow->GetLayer( li );
|
|
|
|
layer->Plot( *trgDc, *plotWindow );
|
|
|
|
}
|
|
|
|
|
|
|
|
;
|
2016-08-11 12:41:21 +00:00
|
|
|
// Restore device origin
|
|
|
|
// trgDc->SetDeviceOrigin(0, 0);
|
|
|
|
// Restore colours
|
2016-08-12 08:10:33 +00:00
|
|
|
plotWindow->SetColourTheme( oldBgColour, oldFgColour, oldAxColour );
|
2016-08-11 12:41:21 +00:00
|
|
|
// Restore drawing
|
2016-08-12 08:10:33 +00:00
|
|
|
plotWindow->Fit( plotWindow->GetDesiredXmin(),
|
|
|
|
plotWindow->GetDesiredXmax(), plotWindow->GetDesiredYmin(),
|
|
|
|
plotWindow->GetDesiredYmax(), NULL, NULL );
|
2016-08-11 12:41:21 +00:00
|
|
|
plotWindow->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
|
|
|
|
|
|
|
bool mpPrintout::HasPage( int page )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
return page == 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
|
|
|
// mpMovableObject - provided by Jose Luis Blanco
|
2016-08-12 08:10:33 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void mpMovableObject::TranslatePoint( double x, double y, double& out_x, double& out_y )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
double ccos = cos( m_reference_phi ); // Avoid computing cos/sin twice.
|
|
|
|
double csin = sin( m_reference_phi );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
out_x = m_reference_x + ccos * x - csin * y;
|
|
|
|
out_y = m_reference_y + csin * x + ccos * 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
|
|
|
// This method updates the buffers m_trans_shape_xs/ys, and the precomputed bounding box.
|
|
|
|
void mpMovableObject::ShapeUpdated()
|
|
|
|
{
|
|
|
|
// Just in case...
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_shape_xs.size()!=m_shape_ys.size() )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
wxLogError( wxT(
|
|
|
|
"[mpMovableObject::ShapeUpdated] Error, m_shape_xs and m_shape_ys have different lengths!" ) );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
double ccos = cos( m_reference_phi ); // Avoid computing cos/sin twice.
|
|
|
|
double csin = sin( m_reference_phi );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
m_trans_shape_xs.resize( m_shape_xs.size() );
|
|
|
|
m_trans_shape_ys.resize( m_shape_xs.size() );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
std::vector<double>::iterator itXi, itXo;
|
|
|
|
std::vector<double>::iterator itYi, itYo;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
m_bbox_min_x = 1e300;
|
|
|
|
m_bbox_max_x = -1e300;
|
|
|
|
m_bbox_min_y = 1e300;
|
|
|
|
m_bbox_max_y = -1e300;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
for( itXo = m_trans_shape_xs.begin(),
|
|
|
|
itYo = m_trans_shape_ys.begin(), itXi = m_shape_xs.begin(), itYi = m_shape_ys.begin();
|
|
|
|
itXo!=m_trans_shape_xs.end(); itXo++, itYo++, itXi++, itYi++ )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
*itXo = m_reference_x + ccos * (*itXi) - csin * (*itYi);
|
|
|
|
*itYo = m_reference_y + csin * (*itXi) + ccos * (*itYi);
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// Keep BBox:
|
2016-08-12 08:10:33 +00:00
|
|
|
if( *itXo < m_bbox_min_x )
|
|
|
|
m_bbox_min_x = *itXo;
|
|
|
|
|
|
|
|
if( *itXo > m_bbox_max_x )
|
|
|
|
m_bbox_max_x = *itXo;
|
|
|
|
|
|
|
|
if( *itYo < m_bbox_min_y )
|
|
|
|
m_bbox_min_y = *itYo;
|
|
|
|
|
|
|
|
if( *itYo > m_bbox_max_y )
|
|
|
|
m_bbox_max_y = *itYo;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpMovableObject::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
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
std::vector<double>::iterator itX = m_trans_shape_xs.begin();
|
|
|
|
std::vector<double>::iterator itY = m_trans_shape_ys.begin();
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( !m_continuous )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
// for some reason DrawPoint does not use the current pen,
|
|
|
|
// so we use DrawLine for fat pens
|
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
|
|
|
while( itX!=m_trans_shape_xs.end() )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.DrawPoint( w.x2p( *(itX++) ), w.y2p( *(itY++) ) );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
while( itX!=m_trans_shape_xs.end() )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
wxCoord cx = w.x2p( *(itX++) );
|
|
|
|
wxCoord cy = w.y2p( *(itY++) );
|
|
|
|
dc.DrawLine( cx, cy, cx, cy );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
wxCoord cx0 = 0, cy0 = 0;
|
|
|
|
bool first = TRUE;
|
|
|
|
|
|
|
|
while( itX!=m_trans_shape_xs.end() )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
wxCoord cx = w.x2p( *(itX++) );
|
|
|
|
wxCoord cy = w.y2p( *(itY++) );
|
|
|
|
|
|
|
|
if( first )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
first = FALSE;
|
|
|
|
cx0 = cx; cy0 = cy;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
dc.DrawLine( cx0, cy0, cx, cy );
|
|
|
|
cx0 = cx; cy0 = cy;
|
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( HasBBox() )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
wxCoord sx = (wxCoord) ( ( m_bbox_max_x - w.GetPosX() ) * w.GetScaleX() );
|
|
|
|
wxCoord sy = (wxCoord) ( (w.GetPosY() - m_bbox_max_y ) * w.GetScaleY() );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
tx = sx - tx - 8;
|
|
|
|
ty = sy - 8 - ty;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
const int sx = w.GetScrX() >> 1;
|
|
|
|
const int sy = w.GetScrY() >> 1;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( (m_flags & mpALIGNMASK) == mpALIGN_NE )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
tx = sx - tx - 8;
|
|
|
|
ty = -sy + 8;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
else if( (m_flags & mpALIGNMASK) == mpALIGN_NW )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
tx = -sx + 8;
|
|
|
|
ty = -sy + 8;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
else if( (m_flags & mpALIGNMASK) == mpALIGN_SW )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
tx = -sx + 8;
|
|
|
|
ty = sy - 8 - ty;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
tx = sx - tx - 8;
|
|
|
|
ty = sy - 8 - ty;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.DrawText( m_name, tx, ty );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2016-08-11 12:41:21 +00:00
|
|
|
// mpCovarianceEllipse - provided by Jose Luis Blanco
|
2016-08-12 08:10:33 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// Called to update the m_shape_xs, m_shape_ys vectors, whenever a parameter changes.
|
|
|
|
void mpCovarianceEllipse::RecalculateShape()
|
|
|
|
{
|
|
|
|
m_shape_xs.clear();
|
|
|
|
m_shape_ys.clear();
|
|
|
|
|
|
|
|
// Preliminar checks:
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_quantiles<0 )
|
|
|
|
{
|
|
|
|
wxLogError( wxT( "[mpCovarianceEllipse] Error: quantiles must be non-negative" ) ); return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_cov_00<0 )
|
|
|
|
{
|
|
|
|
wxLogError( wxT( "[mpCovarianceEllipse] Error: cov(0,0) must be non-negative" ) ); return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_cov_11<0 )
|
|
|
|
{
|
|
|
|
wxLogError( wxT( "[mpCovarianceEllipse] Error: cov(1,1) must be non-negative" ) ); return;
|
|
|
|
}
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
m_shape_xs.resize( m_segments, 0 );
|
|
|
|
m_shape_ys.resize( m_segments, 0 );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// Compute the two eigenvalues of the covariance:
|
|
|
|
// -------------------------------------------------
|
2016-08-12 08:10:33 +00:00
|
|
|
double b = -m_cov_00 - m_cov_11;
|
|
|
|
double c = m_cov_00 * m_cov_11 - m_cov_01 * m_cov_01;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double D = b * b - 4 * c;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( D<0 )
|
|
|
|
{
|
|
|
|
wxLogError( wxT( "[mpCovarianceEllipse] Error: cov is not positive definite" ) ); return;
|
|
|
|
}
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double eigenVal0 = 0.5 * ( -b + sqrt( D ) );
|
|
|
|
double eigenVal1 = 0.5 * ( -b - sqrt( D ) );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// Compute the two corresponding eigenvectors:
|
|
|
|
// -------------------------------------------------
|
2016-08-12 08:10:33 +00:00
|
|
|
double eigenVec0_x, eigenVec0_y;
|
|
|
|
double eigenVec1_x, eigenVec1_y;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( fabs( eigenVal0 - m_cov_00 )>1e-6 )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
double k1x = m_cov_01 / ( eigenVal0 - m_cov_00 );
|
|
|
|
eigenVec0_y = 1;
|
|
|
|
eigenVec0_x = eigenVec0_y * k1x;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
double k1y = m_cov_01 / ( eigenVal0 - m_cov_11 );
|
|
|
|
eigenVec0_x = 1;
|
|
|
|
eigenVec0_y = eigenVec0_x * k1y;
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( fabs( eigenVal1 - m_cov_00 )>1e-6 )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
double k2x = m_cov_01 / ( eigenVal1 - m_cov_00 );
|
|
|
|
eigenVec1_y = 1;
|
|
|
|
eigenVec1_x = eigenVec1_y * k2x;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
double k2y = m_cov_01 / ( eigenVal1 - m_cov_11 );
|
|
|
|
eigenVec1_x = 1;
|
|
|
|
eigenVec1_y = eigenVec1_x * k2y;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Normalize the eigenvectors:
|
2016-08-12 08:10:33 +00:00
|
|
|
double len = sqrt( eigenVec0_x * eigenVec0_x + eigenVec0_y * eigenVec0_y );
|
|
|
|
eigenVec0_x /= len; // It *CANNOT* be zero
|
2016-08-11 12:41:21 +00:00
|
|
|
eigenVec0_y /= len;
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
len = sqrt( eigenVec1_x * eigenVec1_x + eigenVec1_y * eigenVec1_y );
|
|
|
|
eigenVec1_x /= len; // It *CANNOT* be zero
|
2016-08-11 12:41:21 +00:00
|
|
|
eigenVec1_y /= len;
|
|
|
|
|
|
|
|
|
|
|
|
// Take the sqrt of the eigenvalues (required for the ellipse scale):
|
2016-08-12 08:10:33 +00:00
|
|
|
eigenVal0 = sqrt( eigenVal0 );
|
|
|
|
eigenVal1 = sqrt( eigenVal1 );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// Compute the 2x2 matrix M = diag(eigVal) * (~eigVec) (each eigen vector is a row):
|
2016-08-12 08:10:33 +00:00
|
|
|
double M_00 = eigenVec0_x * eigenVal0;
|
|
|
|
double M_01 = eigenVec0_y * eigenVal0;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double M_10 = eigenVec1_x * eigenVal1;
|
|
|
|
double M_11 = eigenVec1_y * eigenVal1;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// The points of the 2D ellipse:
|
2016-08-12 08:10:33 +00:00
|
|
|
double ang;
|
|
|
|
double Aang = 6.283185308 / (m_segments - 1);
|
|
|
|
int i;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
for( i = 0, ang = 0; i<m_segments; i++, ang += Aang )
|
|
|
|
{
|
|
|
|
double ccos = cos( ang );
|
|
|
|
double csin = sin( ang );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
m_shape_xs[i] = m_quantiles * (ccos * M_00 + csin * M_10 );
|
|
|
|
m_shape_ys[i] = m_quantiles * (ccos * M_01 + csin * M_11 );
|
|
|
|
} // end for points on ellipse
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
ShapeUpdated();
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2016-08-11 12:41:21 +00:00
|
|
|
// mpPolygon - provided by Jose Luis Blanco
|
2016-08-12 08:10:33 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void mpPolygon::setPoints( const std::vector<double>& points_xs,
|
|
|
|
const std::vector<double>& points_ys,
|
|
|
|
bool closedShape )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( points_xs.size()!=points_ys.size() )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
wxLogError( wxT(
|
|
|
|
"[mpPolygon] Error: points_xs and points_ys must have the same number of elements" ) );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
m_shape_xs = points_xs;
|
|
|
|
m_shape_ys = points_ys;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( closedShape && points_xs.size() )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
m_shape_xs.push_back( points_xs[0] );
|
|
|
|
m_shape_ys.push_back( points_ys[0] );
|
|
|
|
}
|
|
|
|
|
|
|
|
ShapeUpdated();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2016-08-11 12:41:21 +00:00
|
|
|
// mpBitmapLayer - provided by Jose Luis Blanco
|
2016-08-12 08:10:33 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void mpBitmapLayer::GetBitmapCopy( wxImage& outBmp ) const
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_validImg )
|
2016-08-11 12:41:21 +00:00
|
|
|
outBmp = m_bitmap;
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
|
|
|
|
void mpBitmapLayer::SetBitmap( const wxImage& inBmp, double x, double y, double lx, double ly )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( !inBmp.Ok() )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
wxLogError( wxT( "[mpBitmapLayer] Assigned bitmap is not Ok()!" ) );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
m_bitmap = inBmp; // .GetSubBitmap( wxRect(0, 0, inBmp.GetWidth(), inBmp.GetHeight()));
|
2016-08-11 12:41:21 +00:00
|
|
|
m_min_x = x;
|
|
|
|
m_min_y = y;
|
2016-08-12 08:10:33 +00:00
|
|
|
m_max_x = x + lx;
|
|
|
|
m_max_y = y + ly;
|
2016-08-11 12:41:21 +00:00
|
|
|
m_validImg = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
void mpBitmapLayer::Plot( wxDC& dc, mpWindow& w )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_visible && m_validImg )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
/* 1st: We compute (x0,y0)-(x1,y1), the pixel coordinates of the real outer limits
|
2016-08-12 08:10:33 +00:00
|
|
|
* of the image rectangle within the (screen) mpWindow. Note that these coordinates
|
|
|
|
* might fall well far away from the real view limits when the user zoom in.
|
|
|
|
*
|
|
|
|
* 2nd: We compute (dx0,dy0)-(dx1,dy1), the pixel coordinates the rectangle that will
|
|
|
|
* be actually drawn into the mpWindow, i.e. the clipped real rectangle that
|
|
|
|
* avoids the non-visible parts. (offset_x,offset_y) are the pixel coordinates
|
|
|
|
* that correspond to the window point (dx0,dy0) within the image "m_bitmap", and
|
|
|
|
* (b_width,b_height) is the size of the bitmap patch that will be drawn.
|
|
|
|
*
|
|
|
|
* (x0,y0) ................. (x1,y0)
|
|
|
|
* . .
|
|
|
|
* . .
|
|
|
|
* (x0,y1) ................ (x1,y1)
|
|
|
|
* (In pixels!!)
|
|
|
|
*/
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// 1st step -------------------------------
|
2016-08-12 08:10:33 +00:00
|
|
|
wxCoord x0 = w.x2p( m_min_x );
|
|
|
|
wxCoord y0 = w.y2p( m_max_y );
|
|
|
|
wxCoord x1 = w.x2p( m_max_x );
|
|
|
|
wxCoord y1 = w.y2p( m_min_y );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// 2nd step -------------------------------
|
|
|
|
// Precompute the size of the actual bitmap pixel on the screen (e.g. will be >1 if zoomed in)
|
2016-08-12 08:10:33 +00:00
|
|
|
double screenPixelX = ( x1 - x0 ) / (double) m_bitmap.GetWidth();
|
|
|
|
double screenPixelY = ( y1 - y0 ) / (double) m_bitmap.GetHeight();
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// The minimum number of pixels that the streched image will overpass the actual mpWindow borders:
|
2016-08-12 08:10:33 +00:00
|
|
|
wxCoord borderMarginX = (wxCoord) (screenPixelX + 1); // ceil
|
|
|
|
wxCoord borderMarginY = (wxCoord) (screenPixelY + 1); // ceil
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// The actual drawn rectangle (dx0,dy0)-(dx1,dy1) is (x0,y0)-(x1,y1) clipped:
|
2016-08-12 08:10:33 +00:00
|
|
|
wxCoord dx0 = x0, dx1 = x1, dy0 = y0, dy1 = y1;
|
|
|
|
|
|
|
|
if( dx0<0 )
|
|
|
|
dx0 = -borderMarginX;
|
|
|
|
|
|
|
|
if( dy0<0 )
|
|
|
|
dy0 = -borderMarginY;
|
|
|
|
|
|
|
|
if( dx1>w.GetScrX() )
|
|
|
|
dx1 = w.GetScrX() + borderMarginX;
|
|
|
|
|
|
|
|
if( dy1>w.GetScrY() )
|
|
|
|
dy1 = w.GetScrY() + borderMarginY;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// For convenience, compute the width/height of the rectangle to be actually drawn:
|
2016-08-12 08:10:33 +00:00
|
|
|
wxCoord d_width = dx1 - dx0 + 1;
|
|
|
|
wxCoord d_height = dy1 - dy0 + 1;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// Compute the pixel offsets in the internally stored bitmap:
|
2016-08-12 08:10:33 +00:00
|
|
|
wxCoord offset_x = (wxCoord) ( (dx0 - x0) / screenPixelX );
|
|
|
|
wxCoord offset_y = (wxCoord) ( (dy0 - y0) / screenPixelY );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
// and the size in pixel of the area to be actually drawn from the internally stored bitmap:
|
2016-08-12 08:10:33 +00:00
|
|
|
wxCoord b_width = (wxCoord) ( (dx1 - dx0 + 1) / screenPixelX );
|
|
|
|
wxCoord b_height = (wxCoord) ( (dy1 - dy0 + 1) / screenPixelY );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
#ifdef MATHPLOT_DO_LOGGING
|
2016-08-12 08:10:33 +00:00
|
|
|
wxLogMessage( "[mpBitmapLayer::Plot] screenPixel: x=%f y=%f d_width=%ix%i",
|
|
|
|
screenPixelX,
|
|
|
|
screenPixelY,
|
|
|
|
d_width,
|
|
|
|
d_height );
|
|
|
|
wxLogMessage( "[mpBitmapLayer::Plot] offset: x=%i y=%i bmpWidth=%ix%i",
|
|
|
|
offset_x,
|
|
|
|
offset_y,
|
|
|
|
b_width,
|
|
|
|
b_height );
|
2016-08-11 12:41:21 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Is there any visible region?
|
2016-08-12 08:10:33 +00:00
|
|
|
if( d_width>0 && d_height>0 )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
|
|
|
// Build the scaled bitmap from the image, only if it has changed:
|
2016-08-12 08:10:33 +00:00
|
|
|
if( m_scaledBitmap.GetWidth()!=d_width
|
|
|
|
|| m_scaledBitmap.GetHeight()!=d_height
|
|
|
|
|| m_scaledBitmap_offset_x != offset_x
|
|
|
|
|| m_scaledBitmap_offset_y != offset_y )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
wxRect r( wxRect( offset_x, offset_y, b_width, b_height ) );
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// Just for the case....
|
2016-08-12 08:10:33 +00:00
|
|
|
if( r.x<0 )
|
|
|
|
r.x = 0;
|
|
|
|
|
|
|
|
if( r.y<0 )
|
|
|
|
r.y = 0;
|
|
|
|
|
|
|
|
if( r.width>m_bitmap.GetWidth() )
|
|
|
|
r.width = m_bitmap.GetWidth();
|
|
|
|
|
|
|
|
if( r.height>m_bitmap.GetHeight() )
|
|
|
|
r.height = m_bitmap.GetHeight();
|
2016-08-11 12:41:21 +00:00
|
|
|
|
|
|
|
m_scaledBitmap = wxBitmap(
|
2016-08-12 08:10:33 +00:00
|
|
|
wxBitmap( m_bitmap ).GetSubBitmap( r ).ConvertToImage()
|
|
|
|
.Scale( d_width, d_height ) );
|
2016-08-11 12:41:21 +00:00
|
|
|
m_scaledBitmap_offset_x = offset_x;
|
|
|
|
m_scaledBitmap_offset_y = offset_y;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw it:
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.DrawBitmap( m_scaledBitmap, dx0, dy0, true );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the name label
|
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( HasBBox() )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
wxCoord sx = (wxCoord) ( ( m_max_x - w.GetPosX() ) * w.GetScaleX() );
|
|
|
|
wxCoord sy = (wxCoord) ( (w.GetPosY() - m_max_y ) * w.GetScaleY() );
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
tx = sx - tx - 8;
|
|
|
|
ty = sy - 8 - ty;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
const int sx = w.GetScrX() >> 1;
|
|
|
|
const int sy = w.GetScrY() >> 1;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
if( (m_flags & mpALIGNMASK) == mpALIGN_NE )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
tx = sx - tx - 8;
|
|
|
|
ty = -sy + 8;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
else if( (m_flags & mpALIGNMASK) == mpALIGN_NW )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
tx = -sx + 8;
|
|
|
|
ty = -sy + 8;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
2016-08-12 08:10:33 +00:00
|
|
|
else if( (m_flags & mpALIGNMASK) == mpALIGN_SW )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
tx = -sx + 8;
|
|
|
|
ty = sy - 8 - ty;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-12 08:10:33 +00:00
|
|
|
tx = sx - tx - 8;
|
|
|
|
ty = sy - 8 - ty;
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
dc.DrawText( m_name, tx, ty );
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-11 12:41:49 +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-12 08:10:33 +00:00
|
|
|
// printf("SetScales : %p %p\n", scaleX, scaleY);
|
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
|
|
|
{
|
|
|
|
return m_scaleX->TransformFromPlot( plotCoordX );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double mpFXY::s2y( double plotCoordY ) const
|
2016-08-11 12:41:55 +00:00
|
|
|
{
|
|
|
|
return m_scaleY->TransformFromPlot( plotCoordY );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double mpFXY::x2s( double x ) const
|
2016-08-11 12:41:55 +00:00
|
|
|
{
|
|
|
|
return m_scaleX->TransformToPlot( x );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-12 08:10:33 +00:00
|
|
|
double mpFXY::y2s( double y ) const
|
2016-08-11 12:41:55 +00:00
|
|
|
{
|
|
|
|
return m_scaleY->TransformToPlot( y );
|
|
|
|
}
|