13 #include <wx/window.h> 24 #include "wx/object.h" 26 #include "wx/colour.h" 29 #include "wx/dcclient.h" 30 #include "wx/cursor.h" 34 #include <wx/module.h> 48 #define mpLEGEND_MARGIN 5 49 #define mpLEGEND_LINEWIDTH 10 52 #define mpSCROLL_NUM_PIXELS_PER_LINE 10 61 IMPLEMENT_ABSTRACT_CLASS(
mpLayer, wxObject )
65 SetPen( (wxPen&) *wxBLACK_PEN );
66 SetFont( (wxFont&) *wxNORMAL_FONT );
69 m_drawOutsideMargins =
false;
76 wxBitmap
square( side, side, -1 );
77 wxColour filler =
m_pen.GetColour();
78 wxBrush brush( filler, wxBRUSHSTYLE_SOLID );
82 dc.SetBackground( brush );
84 dc.SelectObject( wxNullBitmap );
96 m_dim = wxRect( 0, 0, 1, 1 );
97 m_brush = *wxTRANSPARENT_BRUSH;
98 m_reference.x = 0; m_reference.y = 0;
128 return m_dim.Contains( point );
189 return m_dim.GetPosition();
195 return m_dim.GetSize();
216 if( event.GetEventType() == wxEVT_MOTION )
261 dc.GetTextExtent(
m_content, &textX, &textY );
263 if(
m_dim.width < textX + 10 )
264 m_dim.width = textX + 10;
266 if(
m_dim.height < textY + 10 )
267 m_dim.height = textY + 10;
328 int tmpX = 0, tmpY = 0;
340 dc.GetTextExtent( label, &tmpX, &tmpY );
342 ( textX > (tmpX + baseWidth) ) ? textX : (tmpX + baseWidth +
mpLEGEND_MARGIN);
354 m_dim.height = textY;
365 dc.GetTextExtent( label, &tmpX, &tmpY );
413 if(
m_pen.GetWidth() <= 1 )
415 for( wxCoord i = startPx; i < endPx; ++i )
421 dc.DrawPoint( i, iy );
426 for( wxCoord i = startPx; i < endPx; ++i )
432 dc.DrawLine( i, iy, i, iy );
444 dc.GetTextExtent(
m_name, &tx, &ty );
490 if(
m_pen.GetWidth() <= 1 )
492 for( i = minYpx; i < maxYpx; ++i )
497 dc.DrawPoint( ix, i );
502 for( i = 0; i< w.
GetScrY(); ++i )
507 dc.DrawLine( ix, i, ix, i );
520 dc.GetTextExtent(
m_name, &tx, &ty );
547 maxDrawX = minDrawX = maxDrawY = minDrawY = 0;
580 dc.SetClippingRegion( startPx, minYpx, endPx - startPx + 1, maxYpx - minYpx + 1 );
586 std::set<wxCoord> ys;
592 wxCoord newX = w.
x2p( px );
603 ys.insert( w.
y2p( py ) );
610 || ( (ix >= startPx) && (ix <= endPx) && (iy >= minYpx)
611 && (iy <= maxYpx) ) )
615 if(
m_pen.GetWidth() <= 1 )
617 dc.DrawPoint( ix, iy );
621 dc.DrawLine( ix, iy, ix, iy );
630 ys.insert( w.
y2p( py ) );
643 std::vector<wxPoint>pointList;
644 pointList.reserve( endPx - startPx + 1 );
658 wxCoord x1 = w.
x2p( px );
659 wxCoord y1 = w.
y2p( py );
664 if( x1 >= startPx-1 && x1 <= endPx )
666 if( !count || line_start.x != x1 )
668 if( count && dupx0 > 1 && ymin0 != ymax0 )
673 dc.DrawLine( x0, ymin0, x0, ymax0 );
680 pointList.emplace_back( wxPoint( x1, y1 ) );
688 ymin0 = std::min( ymin0, y1 );
689 ymax0 = std::max( ymax0, y1 );
696 if( pointList.size() > 1 )
702 std::vector<wxPoint> drawPoints;
703 drawPoints.reserve( endPx - startPx + 1 );
705 drawPoints.push_back( pointList[0] );
707 for(
size_t ii = 1; ii < pointList.size()-1; ii++ )
711 if( drawPoints.back().y == pointList[ii].y &&
712 drawPoints.back().y == pointList[ii+1].y )
715 drawPoints.push_back( pointList[ii] );
719 if( drawPoints.back() != pointList.back() )
720 drawPoints.push_back( pointList.back() );
722 dc.DrawLines( drawPoints.size(), &drawPoints[0] );
731 dc.GetTextExtent(
m_name, &tx, &ty );
761 dc.DrawText(
m_name, tx, ty );
765 dc.DestroyClippingRegion();
795 for( wxCoord i = startPx; i < endPx; ++i )
804 c0 = (c0 <= maxYpx) ? ( (c0 >= minYpx) ? c0 : minYpx ) : maxYpx;
805 c1 = (c1 <= maxYpx) ? ( (c1 >= minYpx) ? c1 : minYpx ) : maxYpx;
808 dc.DrawLine( i, c0, i + 1, c1 );
818 dc.GetTextExtent(
m_name, &tx, &ty );
838 #define mpLN10 2.3025850929940456840179914546844 842 double minV, maxV, minVvis, maxVvis;
852 double minErr = 1000000000000.0;
853 double bestStep = 1.0;
855 for(
int i = 10; i <= 20; i += 2 )
857 double curr_step = fabs( maxVvis - minVvis ) / (double) i;
858 double base = pow( 10, floor( log10( curr_step ) ) );
859 double stepInt = floor( curr_step / base ) * base;
860 double err = fabs( curr_step - stepInt );
870 double v = floor( minVvis / bestStep ) * bestStep;
872 double zeroOffset = 100000000.0;
878 if( fabs( v ) < zeroOffset )
879 zeroOffset = fabs( v );
884 if( zeroOffset <= bestStep )
927 dc.GetTextExtent( s, &tx, &ty );
983 double pymin = w.
p2y( minYpx );
984 double pymax = w.
p2y( maxYpx );
1005 double y_slave0 = p0 /
m_scale;
1006 double y_slave1 = p1 /
m_scale;
1008 double dy_slave = (y_slave1 - y_slave0);
1009 double exponent = floor( log10( dy_slave ) );
1010 double base = dy_slave / pow( 10.0, exponent );
1012 double dy_scaled = ceil( 2.0 * base ) / 2.0 * pow( 10.0, exponent );
1014 double minvv, maxvv;
1018 minvv = floor( minvv / dy_scaled ) * dy_scaled;
1021 m_scale *= dy_slave / dy_scaled;
1051 double minV, maxV, minVvis, maxVvis;
1059 double minErr = 1000000000000.0;
1060 double bestStep = 1.0;
1062 for(
int i = 10; i <= 20; i += 2 )
1064 double curr_step = fabs( maxVvis - minVvis ) / (double) i;
1065 double base = pow( 10, floor( log10( curr_step ) ) );
1066 double stepInt = floor( curr_step / base ) * base;
1067 double err = fabs( curr_step - stepInt );
1077 double v = floor( minVvis / bestStep ) * bestStep;
1079 double zeroOffset = 100000000.0;
1081 const int iterLimit = 1000;
1084 while( v < maxVvis && i < iterLimit )
1088 if( fabs( v ) < zeroOffset )
1089 zeroOffset = fabs( v );
1097 if( i == iterLimit )
1102 if( zeroOffset <= bestStep )
1126 double pxmin = w.
p2x( startPx );
1127 double pxmax = w.
p2x( endPx );
1136 double minV, maxV, minVvis, maxVvis;
1142 double minDecade = pow( 10, floor( log10( minV ) ) );
1143 double maxDecade = pow( 10, ceil( log10( maxV ) ) );
1144 double visibleDecades = log( maxVvis / minVvis ) / log( 10 );
1151 if( minDecade == 0.0 )
1155 for( d = minDecade; d<=maxDecade; d *= 10.0 )
1159 for(
double dd = d; dd < d * 10; dd += d )
1161 if( visibleDecades < 2 )
1179 SetFont( (wxFont&) *wxSMALL_FONT );
1180 SetPen( (wxPen&) *wxGREY_PEN );
1215 const int extend = w.
GetScrX();
1264 if( (p >= startPx) && (p <= endPx) )
1269 dc.DrawLine( p, orgy, p, orgy - 4 );
1271 dc.DrawLine( p, orgy, p, orgy + 4 );
1275 m_pen.SetStyle( wxPENSTYLE_DOT );
1280 m_pen.SetStyle( wxPENSTYLE_DOT );
1282 dc.DrawLine( p, orgy + 4, p, minYpx );
1283 m_pen.SetStyle( wxPENSTYLE_SOLID );
1285 dc.DrawLine( p, orgy + 4, p, orgy - 4 );
1291 dc.DrawLine( p, orgy - 4, p, maxYpx );
1295 dc.DrawLine( p, minYpx, p, maxYpx );
1299 m_pen.SetStyle( wxPENSTYLE_SOLID );
1305 m_pen.SetStyle( wxPENSTYLE_SOLID );
1307 dc.DrawLine( startPx, minYpx, endPx, minYpx );
1308 dc.DrawLine( startPx, maxYpx, endPx, maxYpx );
1326 if( (p >= startPx) && (p <= endPx) )
1331 dc.GetTextExtent( s, &tx, &ty );
1335 dc.DrawText( s, p - tx / 2, orgy - 4 - ty );
1339 dc.DrawText( s, p - tx / 2, orgy + 4 );
1345 dc.GetTextExtent(
m_name, &tx, &ty );
1350 dc.DrawText(
m_name, extend - tx - 4, orgy - 8 - ty - labelH );
1355 dc.DrawText(
m_name, (endPx + startPx) / 2 - tx / 2, orgy + 6 + labelH );
1360 dc.DrawText(
m_name, extend - tx - 4, orgy - 4 - ty );
1367 dc.DrawText(
m_name, (endPx - startPx - tx) >> 1, orgy - 6 - ty - labelH );
1371 dc.DrawText(
m_name, extend - tx - 4, orgy + 4 );
1377 dc.DrawText(
m_name, extend - tx - 4, orgy + 6 + labelH );
1392 SetFont( (wxFont&) *wxSMALL_FONT );
1393 SetPen( (wxPen&) *wxGREY_PEN );
1397 m_masterScale = NULL;
1446 dc.DrawLine( orgx, minYpx, orgx, maxYpx );
1457 int labelHeight = 0;
1459 dc.GetTextExtent( s, &tx, &labelHeight );
1469 if( (p >= minYpx) && (p <= maxYpx) )
1475 dc.DrawLine( orgx, p, orgx + 4, p );
1479 dc.DrawLine( orgx - 4, p, orgx, p );
1484 dc.DrawLine( orgx - 4, p, orgx + 4, p );
1486 m_pen.SetStyle( wxPENSTYLE_DOT );
1489 dc.DrawLine( orgx - 4, p, endPx, p );
1491 m_pen.SetStyle( wxPENSTYLE_SOLID );
1509 if( (p >= minYpx) && (p <= maxYpx) )
1512 dc.GetTextExtent( s, &tx, &ty );
1515 dc.DrawText( s, orgx + 4, p - ty / 2 );
1517 dc.DrawText( s, orgx - 4 - tx, p - ty / 2 );
1524 dc.GetTextExtent(
m_name, &tx, &ty );
1529 dc.DrawText(
m_name, labelW + 8, 4 );
1537 dc.DrawText(
m_name, orgx + 4, minYpx - ty - 4 );
1543 dc.DrawText(
m_name, orgx + 4, 4 );
1553 dc.DrawText(
m_name, orgx - tx - 4, minYpx - ty - 4 );
1559 dc.DrawText(
m_name, orgx - 6 - tx - labelW, 4 );
1573 IMPLEMENT_DYNAMIC_CLASS(
mpWindow, wxWindow )
1575 BEGIN_EVENT_TABLE(
mpWindow, wxWindow )
1587 EVT_RIGHT_UP(
mpWindow::OnShowPopupMenu )
1588 EVT_MOUSEWHEEL(
mpWindow::OnMouseWheel )
1589 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT ) 1604 m_lockaspect( false ),
1617 m_desiredXmin( 0.0 ),
1618 m_desiredXmax( 1.0 ),
1619 m_desiredYmin( 0.0 ),
1620 m_desiredYmax( 1.0 ),
1623 m_marginBottom( 0 ),
1627 m_buff_bmp(
nullptr ),
1628 m_enableDoubleBuffer( false ),
1629 m_enableMouseNavigation( true ),
1630 m_enableMouseWheelPan( false ),
1631 m_enableLimitedView( false ),
1632 m_enableScrollBars( false ),
1633 m_movingInfoLayer(
nullptr ),
1643 : wxWindow( parent, id, pos, size,
flag, wxT(
"mathplot" ) )
1666 m_popmenu.Append(
mpID_FIT,
_(
"Fit on Screen" ),
_(
"Set plot view to show all items" ) );
1673 SetBackgroundColour( *wxWHITE );
1678 SetSizeHints( 128, 128 );
1681 SetBackgroundStyle( wxBG_STYLE_CUSTOM );
1709 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT ) 1718 float zoom =
event.GetMagnification() + 1.0f;
1719 wxPoint pos( event.GetX(),
event.GetY() );
1722 else if(
zoom < 1.0f )
1738 int change =
event.GetWheelRotation();
1739 const int axis =
event.GetWheelAxis();
1740 double changeUnitsX = change /
m_scaleX;
1741 double changeUnitsY = change /
m_scaleY;
1749 if( axis == wxMOUSE_WHEEL_HORIZONTAL || event.ShiftDown() )
1758 if( event.ControlDown() )
1771 wxPoint clickPt( event.GetX(),
event.GetY() );
1773 if( event.GetWheelRotation() > 0 )
1793 if( event.m_middleDown )
1806 bool updateRequired =
false;
1814 if( updateRequired )
1819 if( event.m_leftDown )
1823 wxClientDC dc(
this );
1826 dc.SetBrush( *wxTRANSPARENT_BRUSH );
1847 wxLayerList::iterator li;
1851 if( (*li)->IsInfo() && (*li)->IsVisible() )
1881 wxPoint pointClicked =
event.GetPosition();
1890 wxPoint release( event.GetX(),
event.GetY() );
1902 if( release != press )
1919 wxCoord* printSizeX, wxCoord* printSizeY )
1926 double xExtra = fabs( xMax - xMin ) * 0.00;
1927 double yExtra = fabs( yMax - yMin ) * 0.03;
1934 if( printSizeX != NULL && printSizeY != NULL )
1975 if( printSizeX == NULL || printSizeY == NULL )
1984 double staticX =
p2x( staticXpixel );
2078 wxPoint c( centerPoint );
2080 if( c == wxDefaultPosition )
2095 double prior_layer_x =
p2x( c.x );
2096 double prior_layer_y =
p2y( c.y );
2100 double newScaleX =
m_scaleX * zoomFactor;
2101 double newScaleY =
m_scaleY * zoomFactor;
2135 wxPoint c( centerPoint );
2137 if( c == wxDefaultPosition )
2145 double prior_layer_x =
p2x( c.x );
2146 double prior_layer_y =
p2y( c.y );
2181 double p0x =
p2x( p0.x );
2182 double p0y =
p2y( p0.y );
2183 double p1x =
p2x( p1.x );
2184 double p1y =
p2y( p1.y );
2187 double zoom_x_min = p0x<p1x ? p0x : p1x;
2188 double zoom_x_max = p0x>p1x ? p0x : p1x;
2189 double zoom_y_min = p0y<p1y ? p0y : p1y;
2190 double zoom_y_max = p0y>p1y ? p0y : p1y;
2192 Fit( zoom_x_min, zoom_x_max, zoom_y_min, zoom_y_max );
2211 PopupMenu( &
m_popmenu, event.GetX(),
event.GetY() );
2262 if( refreshDisplay )
2274 bool alsoDeleteObject,
2275 bool refreshDisplay )
2277 wxLayerList::iterator layIt;
2281 if( *layIt == layer )
2284 if( alsoDeleteObject )
2289 if( refreshDisplay )
2305 if( alsoDeleteObject )
2311 if( refreshDisplay )
2318 wxPaintDC dc(
this );
2348 trgDc->SetPen( *wxTRANSPARENT_PEN );
2349 wxBrush brush( GetBackgroundColour() );
2350 trgDc->SetBrush( brush );
2356 wxLayerList::iterator li;
2359 (*li)->Plot( *trgDc, *
this );
2364 trgDc->SetPen( pen );
2365 trgDc->SetBrush( *wxTRANSPARENT_BRUSH );
2410 GetClientSize( &cx, &cy );
2419 if( (
m_posX + leftMargin) < minX )
2420 minX =
m_posX + leftMargin;
2423 int sizeX = (int) ( (maxX - minX) *
m_scaleX );
2424 int thumbX = (int) ( ( (
m_posX + leftMargin) - minX ) *
m_scaleX );
2434 if( (
m_posY - topMargin) > maxY )
2435 maxY =
m_posY - topMargin;
2439 int sizeY = (int) ( (maxY - minY) *
m_scaleY );
2440 int thumbY = (int) ( ( maxY - (
m_posY - topMargin) ) *
m_scaleY );
2452 if( orientation == wxVERTICAL )
2477 DoScrollCalc( event.GetPosition(),
event.GetOrientation() );
2483 int scrollOrientation =
event.GetOrientation();
2485 int position = GetScrollPos( scrollOrientation );
2487 int thumbSize = GetScrollThumb( scrollOrientation );
2490 position -= thumbSize;
2501 int scrollOrientation =
event.GetOrientation();
2503 int position = GetScrollPos( scrollOrientation );
2505 int thumbSize = GetScrollThumb( scrollOrientation );
2507 int scrollRange = GetScrollRange( scrollOrientation );
2510 position += thumbSize;
2512 if( position > (scrollRange - thumbSize) )
2513 position = scrollRange - thumbSize;
2521 int scrollOrientation =
event.GetOrientation();
2523 int position = GetScrollPos( scrollOrientation );
2537 int scrollOrientation =
event.GetOrientation();
2539 int position = GetScrollPos( scrollOrientation );
2541 int thumbSize = GetScrollThumb( scrollOrientation );
2543 int scrollRange = GetScrollRange( scrollOrientation );
2548 if( position > (scrollRange - thumbSize) )
2549 position = scrollRange - thumbSize;
2563 int scrollOrientation =
event.GetOrientation();
2565 int thumbSize = GetScrollThumb( scrollOrientation );
2567 int scrollRange = GetScrollRange( scrollOrientation );
2569 DoScrollCalc( scrollRange - thumbSize, scrollOrientation );
2588 unsigned int layerNo = 0;
2592 if( layer->HasBBox() )
2602 if( ( position >= (
int)
m_layers.size() ) || position < 0 )
2613 if( !layer->GetName().Cmp(
name ) )
2634 int bk_scrX, bk_scrY;
2636 if( imageSize == wxDefaultSize )
2643 sizeX = imageSize.x;
2644 sizeY = imageSize.y;
2650 wxBitmap screenBuffer( sizeX, sizeY );
2651 wxMemoryDC screenDC;
2652 screenDC.SelectObject( screenBuffer );
2653 screenDC.SetPen( *wxWHITE_PEN );
2655 wxBrush brush( GetBackgroundColour() );
2656 screenDC.SetBrush( brush );
2657 screenDC.DrawRectangle( 0, 0, sizeX, sizeY );
2666 layer->Plot( screenDC, *
this );
2668 if( imageSize != wxDefaultSize )
2671 SetScr( bk_scrX, bk_scrY );
2677 wxImage screenImage = screenBuffer.ConvertToImage();
2678 return screenImage.SaveFile( filename, type );
2695 if( layer->IsInfo() )
2697 mpInfoLayer* tmpLyr = static_cast<mpInfoLayer*>( layer );
2699 if( tmpLyr->
Inside( point ) )
2749 const wxColour& axesColour )
2751 SetBackgroundColour( bgColour );
2752 SetForegroundColour( drawColour );
2762 wxPen axisPen = layer->GetPen();
2763 axisPen.SetColour( axesColour );
2764 layer->SetPen( axisPen );
2769 wxPen infoPen = layer->GetPen();
2770 infoPen.SetColour( drawColour );
2771 layer->SetPen( infoPen );
2821 double xlogmin = log10(
m_minV );
2822 double xlogmax = log10(
m_maxV );
2824 return ( log10( x ) - xlogmin) / (xlogmax - xlogmin);
2830 double xlogmin = log10(
m_minV );
2831 double xlogmax = log10(
m_maxV );
2833 return pow( 10.0, xplot * (xlogmax - xlogmin) + xlogmin );
2838 mpFSemiLogXVector::mpFSemiLogXVector( wxString
name,
int flags ) :
2844 IMPLEMENT_DYNAMIC_CLASS( mpFSemiLogXVector,
mpFXYVector )
2883 if( xs.size() != ys.size() )
2898 for(
const double x : xs )
2907 for(
const double y : ys )
2941 if( offsetx >= 0 && offsetx <= 100 )
2942 m_offsetx = offsetx;
2946 if( offsety >= 0 && offsety <= 100 )
2947 m_offsety = offsety;
2966 wxCoord tw = 0, th = 0;
2967 dc.GetTextExtent(
GetName(), &tw, &th );
2979 dc.DrawText(
GetName(), px, py );
2997 wxDC* trgDc = GetDC();
2999 if( (trgDc) && (page == 1) )
3001 wxCoord m_prnX, m_prnY;
3004 trgDc->GetSize( &m_prnX, &m_prnY );
3006 m_prnX -= (2 * marginX);
3007 m_prnY -= (2 * marginY);
3008 trgDc->SetDeviceOrigin( marginX, marginY );
3020 wxColour oldBgColour =
plotWindow->GetBackgroundColour();
3021 wxColour oldFgColour =
plotWindow->GetForegroundColour();
3025 trgDc->SetPen( *wxTRANSPARENT_PEN );
3027 wxBrush brush = *wxWHITE_BRUSH;
3028 trgDc->SetBrush( brush );
3029 trgDc->DrawRectangle( 0, 0, m_prnX, m_prnY );
3091 std::vector<double>::iterator itXi, itXo;
3092 std::vector<double>::iterator itYi, itYo;
3137 if(
m_pen.GetWidth() <= 1 )
3141 dc.DrawPoint( w.
x2p( *(itX++) ), w.
y2p( *(itY++) ) );
3148 wxCoord cx = w.
x2p( *(itX++) );
3149 wxCoord cy = w.
y2p( *(itY++) );
3150 dc.DrawLine( cx, cy, cx, cy );
3156 wxCoord cx0 = 0, cy0 = 0;
3161 wxCoord cx = w.
x2p( *(itX++) );
3162 wxCoord cy = w.
y2p( *(itY++) );
3170 dc.DrawLine( cx0, cy0, cx, cy );
3180 dc.GetTextExtent(
m_name, &tx, &ty );
3192 const int sx = w.
GetScrX() >> 1;
3193 const int sy = w.
GetScrY() >> 1;
3217 dc.DrawText(
m_name, tx, ty );
3251 double D = b * b - 4 * c;
3256 double eigenVal0 = 0.5 * ( -b + sqrt(
D ) );
3257 double eigenVal1 = 0.5 * ( -b - sqrt(
D ) );
3261 double eigenVec0_x, eigenVec0_y;
3262 double eigenVec1_x, eigenVec1_y;
3264 if( fabs( eigenVal0 -
m_cov_00 ) > 1e-6 )
3268 eigenVec0_x = eigenVec0_y * k1x;
3274 eigenVec0_y = eigenVec0_x * k1y;
3277 if( fabs( eigenVal1 -
m_cov_00 ) > 1e-6 )
3281 eigenVec1_x = eigenVec1_y * k2x;
3287 eigenVec1_y = eigenVec1_x * k2y;
3291 double len = sqrt( eigenVec0_x * eigenVec0_x + eigenVec0_y * eigenVec0_y );
3295 len = sqrt( eigenVec1_x * eigenVec1_x + eigenVec1_y * eigenVec1_y );
3301 eigenVal0 = sqrt( eigenVal0 );
3302 eigenVal1 = sqrt( eigenVal1 );
3305 double M_00 = eigenVec0_x * eigenVal0;
3306 double M_01 = eigenVec0_y * eigenVal0;
3308 double M_10 = eigenVec1_x * eigenVal1;
3309 double M_11 = eigenVec1_y * eigenVal1;
3313 double Aang = 6.283185308 / (
m_segments - 1);
3316 for( i = 0, ang = 0; i <
m_segments; i++, ang += Aang )
3318 double ccos = cos( ang );
3319 double csin = sin( ang );
3333 const std::vector<double>& points_ys,
3336 if( points_xs.size() == points_ys.size() )
3341 if( closedShape && !points_xs.empty() )
3405 double screenPixelX = ( x1 - x0 ) / (
double)
m_bitmap.GetWidth();
3406 double screenPixelY = ( y1 - y0 ) / (
double)
m_bitmap.GetHeight();
3409 wxCoord borderMarginX = (wxCoord) (screenPixelX + 1);
3410 wxCoord borderMarginY = (wxCoord) (screenPixelY + 1);
3413 wxCoord dx0 = x0, dx1 = x1, dy0 = y0, dy1 = y1;
3416 dx0 = -borderMarginX;
3419 dy0 = -borderMarginY;
3422 dx1 = w.
GetScrX() + borderMarginX;
3425 dy1 = w.
GetScrY() + borderMarginY;
3428 wxCoord d_width = dx1 - dx0 + 1;
3429 wxCoord d_height = dy1 - dy0 + 1;
3432 wxCoord offset_x = (wxCoord) ( (dx0 - x0) / screenPixelX );
3433 wxCoord offset_y = (wxCoord) ( (dy0 - y0) / screenPixelY );
3436 wxCoord b_width = (wxCoord) ( (dx1 - dx0 + 1) / screenPixelX );
3437 wxCoord b_height = (wxCoord) ( (dy1 - dy0 + 1) / screenPixelY );
3440 if( d_width>0 && d_height>0 )
3448 wxRect
r( wxRect( offset_x, offset_y, b_width, b_height ) );
3464 wxBitmap(
m_bitmap ).GetSubBitmap(
r ).ConvertToImage()
3465 .Scale( d_width, d_height ) );
3481 dc.GetTextExtent(
m_name, &tx, &ty );
3493 const int sx = w.
GetScrX() >> 1;
3494 const int sy = w.
GetScrY() >> 1;
3518 dc.DrawText(
m_name, tx, ty );
mpInfoLegend()
Default constructor.
void ZoomOut(const wxPoint ¢erPoint=wxDefaultPosition)
Zoom out current view and refresh display.
double s2x(double plotCoordX) const
virtual void UpdateInfo(mpWindow &w, wxEvent &event) override
Updates the content of the info box.
void OnScrollThumbTrack(wxScrollWinEvent &event)
#define mpALIGN_LEFT
Aligns label to the left.
virtual void recalculateTicks(wxDC &dc, mpWindow &w)
virtual void getVisibleDataRange(mpWindow &w, double &minV, double &maxV) override
int GetMarginBottom() const
void OnMagnify(wxMouseEvent &event)
virtual void Plot(wxDC &dc, mpWindow &w) override
Plot method.
virtual bool Inside(wxPoint &point)
Checks whether a point is inside the info box rectangle.
#define mpALIGN_NW
Aligns label to north-west.
void OnLockAspect(wxCommandEvent &event)
const wxString & GetName() const
Get layer name.
double GetPosY(void) const
const wxRect & GetRectangle() const
Returns the current rectangle coordinates.
mpInfoCoords()
Default constructor.
bool IsLayerVisible(const wxString &name) const
Check whether a layer with given name is visible.
void RecalculateShape()
Called to update the m_shape_xs, m_shape_ys vectors, whenever a parameter changes.
virtual double getLabelPos(int n) const
void GetDataRange(double &minV, double &maxV) const
virtual bool SetYView(double pos, double desiredMax, double desiredMin)
Applies new Y view coordinates depending on the settings.
void Rewind() override
Rewind value enumeration with mpFXY::GetNextXY.
double GetScaleX(void) const
double p2x(wxCoord pixelCoordX)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates,...
void updateTickLabels(wxDC &dc, mpWindow &w)
unsigned int CountLayers() const
Counts the number of plot layers, excluding axes or text: this is to count only the layers which have...
virtual void Plot(wxDC &dc, mpWindow &w) override
Layer plot handler.
std::vector< double > m_trans_shape_ys
void OnScrollLineDown(wxScrollWinEvent &event)
void computeSlaveTicks(mpWindow &w)
virtual double GetMaxY() const
Get inclusive top border of bounding box.
bool DelLayer(mpLayer *layer, bool alsoDeleteObject=false, bool refreshDisplay=true)
Remove a plot layer from the canvas.
virtual void SetScale(mpScaleBase *scaleX, mpScaleBase *scaleY)
bool OnPrintPage(int page) override
virtual double TransformFromPlot(double xplot) const
Abstract base class providing plot and labeling functionality for functions F:X->Y.
void OnZoomOut(wxCommandEvent &event)
#define Y_BORDER_SEPARATION
bool m_enableMouseNavigation
double GetScaleY(void) const
virtual double TransformFromPlot(double xplot) const override
int m_segments
The number of line segments that build up the ellipse.
void OnMouseMiddleDown(wxMouseEvent &event)
void GetBitmapCopy(wxImage &outBmp) const
Returns a copy of the current bitmap assigned to the layer.
std::vector< TickLabel > m_tickLabels
virtual void Plot(wxDC &dc, mpWindow &w) override
Layer plot handler.
Abstract base class providing plot and labeling functionality for functions F:Y->X.
wxSize GetSize() const
Returns the size of the box (in pixels)
const wxColour & GetAxesColour()
Get axes draw colour.
virtual double TransformToPlot(double x) const override
unsigned int CountAllLayers() const
Counts the number of plot layers, whether or not they have a bounding box.
bool m_enableMouseWheelPan
double y2s(double y) const
double m_reference_x
The coordinates of the object (orientation "phi" is in radians).
#define mpALIGN_RIGHT
Aligns label to the right.
void SetLayerVisible(const wxString &name, bool viewable)
Sets the visibility of a layer by its name.
double p2y(wxCoord pixelCoordY)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates,...
void OnScrollLineUp(wxScrollWinEvent &event)
virtual double TransformFromPlot(double xplot) const override
A class providing graphs functionality for a 2D plot (either continuous or a set of points),...
virtual void Plot(wxDC &dc, mpWindow &w) override
Plot method.
std::vector< double > m_xs
The internal copy of the set of data to draw.
mpInfoLayer * IsInsideInfoLayer(wxPoint &point)
Check if a given point is inside the area of a mpInfoLayer and eventually returns its pointer.
void DoZoomInXCalc(const int staticXpixel)
bool AddLayer(mpLayer *layer, bool refreshDisplay=true)
Add a plot layer to the canvas.
const mpLayer * GetLayerByName(const wxString &name) const
void OnSize(wxSizeEvent &event)
bool GetNextXY(double &x, double &y) override
Get locus value for next N.
std::vector< double > m_ys
size_t m_index
The internal counter for the "GetNextXY" interface.
void ZoomInX()
Zoom in current view along X and refresh display.
double GetPosX(void) const
void OnZoomIn(wxCommandEvent &event)
~mpInfoCoords()
Default destructor.
void LockAspect(bool enable=true)
Enable or disable X/Y scale aspect locking for the view.
virtual void Plot(wxDC &dc, mpWindow &w) override
Layer plot handler.
Abstract base class providing plot and labeling functionality for a locus plot F:N->X,...
virtual double TransformToPlot(double x) const override
virtual double GetMaxX() const
Get inclusive right border of bounding box.
void ExtendDataRange(double minV, double maxV)
virtual bool HasBBox() const override
Check whether this layer has a bounding box.
#define X_BORDER_SEPARATION
void UpdateAll()
Refresh display.
virtual double TransformToPlot(double x) const
void OnPaint(wxPaintEvent &event)
wxCoord m_scaledBitmap_offset_x
int GetMarginRight() const
#define mpALIGN_BORDER_TOP
Aligns X axis to top border.
virtual void Move(wxPoint delta)
Moves the layer rectangle of given pixel deltas.
wxCoord y2p(double y)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates,...
void SetPosX(double posX)
Set current view's X position and refresh display.
#define mpALIGN_BORDER_LEFT
Aligns Y axis to left border.
void computeLabelExtents(wxDC &dc, mpWindow &w)
void SetPosY(double posY)
Set current view's Y position and refresh display.
Plot layer implementing a x-scale ruler.
virtual void recalculateTicks(wxDC &dc, mpWindow &w) override
double m_bbox_min_x
The precomputed bounding box:
void SetVisible(bool show)
Sets layer visibility.
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
void OnScrollPageUp(wxScrollWinEvent &event)
virtual void Plot(wxDC &dc, mpWindow &w) override
Plot given view of layer to the given device context.
void ZoomIn(const wxPoint ¢erPoint=wxDefaultPosition)
Zoom into current view and refresh display.
void OnScrollBottom(wxScrollWinEvent &event)
virtual void UpdateInfo(mpWindow &w, wxEvent &event)
Updates the content of the info box.
double GetDesiredXmax() const
Returns the right-border layer coordinate that the user wants the mpWindow to show (it may be not exa...
void SetScaleX(double scaleX)
Set current view's X scale and refresh display.
virtual double TransformFromPlot(double xplot) const override
Base class to create small rectangular info boxes mpInfoLayer is the base class to create a small rec...
void ZoomRect(wxPoint p0, wxPoint p1)
Zoom view fitting given coordinates to the window (p0 and p1 do not need to be in any specific order)
virtual double GetMinX() const
Get inclusive left border of bounding box.
int GetScrX(void) const
Get current view's X dimension in device context units.
void OnMouseLeftRelease(wxMouseEvent &event)
void OnMouseMove(wxMouseEvent &event)
Plot layer implementing a y-scale ruler.
bool IsVisible() const
Checks whether the layer is visible or not.
virtual double GetMinY() const
Get inclusive bottom border of bounding box.
void ShapeUpdated()
Must be called by the descendent class after updating the shape (m_shape_xs/ys), or when the transfor...
void SetMargins(int top, int right, int bottom, int left)
Set window margins, creating a blank area where some kinds of layers cannot draw.
virtual void recalculateTicks(wxDC &dc, mpWindow &w) override
double m_desiredXmin
These are updated in Fit() only, and may be different from the real borders (layer coordinates) only ...
#define mpALIGN_TOP
Aligns label to the top.
virtual ~mpInfoLayer()
Destructor.
void SetColourTheme(const wxColour &bgColour, const wxColour &drawColour, const wxColour &axesColour)
Set Color theme.
EVT_MIDDLE_DOWN(mpWindow::OnMouseMiddleDown) EVT_MOUSEWHEEL(mpWindow
bool CheckYLimits(double &desiredMax, double &desiredMin) const
void DelAllLayers(bool alsoDeleteObject, bool refreshDisplay=true)
Remove all layers from the plot.
wxBitmap GetColourSquare(int side=16) const
Get a small square bitmap filled with the colour of the pen used in the layer.
mpInfoLayer * m_movingInfoLayer
mpInfoLayer()
Default constructor.
virtual void Plot(wxDC &dc, mpWindow &w) override
Layer plot handler.
#define mpALIGN_NE
Aligns label to north-east.
virtual void Plot(wxDC &dc, mpWindow &w) override
Layer plot handler.
virtual void UpdateInfo(mpWindow &w, wxEvent &event) override
Updates the content of the info box.
mpLayer * GetLayer(int position) const
void OnCenter(wxCommandEvent &event)
bool HasPage(int page) override
virtual double getTickPos(int n) const
void recalculateTicks(wxDC &dc, mpWindow &w) override
Layer plot handler.
wxPoint GetPosition() const
Returns the position of the upper left corner of the box (in pixels)
bool m_drawOutsideMargins
void TranslatePoint(double x, double y, double &out_x, double &out_y)
A method for 2D translation and rotation, using the current transformation stored in m_reference_x,...
double GetDesiredXmin() const
Returns the left-border layer coordinate that the user wants the mpWindow to show (it may be not exac...
#define mpALIGN_BORDER_BOTTOM
Aligns X axis to bottom border.
void Fit() override
Set view to fit global bounding box of all plot layers and refresh display.
double x2s(double x) const
void UpdateViewBoundary(wxCoord xnew, wxCoord ynew)
Update label positioning data.
virtual bool GetNextXY(double &x, double &y)=0
Get locus value for next N.
virtual double TransformToPlot(double x) const override
Layer plot handler.
wxImage m_bitmap
The internal copy of the Bitmap:
virtual wxString getLabel(int n) const
void OnFit(wxCommandEvent &event)
virtual void UpdateReference()
Updates the rectangle reference point.
mpScaleXLog(const wxString &name=wxT("log(X)"), int flags=mpALIGN_CENTER, bool ticks=true, unsigned int type=mpX_NORMAL)
Full constructor.
void OnShowPopupMenu(wxMouseEvent &event)
virtual double GetY(double x) const =0
Get function value for argument.
wxCoord x2p(double x)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates,...
virtual void formatLabels()
void Clear()
Clears all the data, leaving the layer empty.
virtual void getVisibleDataRange(mpWindow &w, double &minV, double &maxV) override
virtual void Plot(wxDC &dc, mpWindow &w) override
Plot given view of layer to the given device context.
wxCoord m_scaledBitmap_offset_y
void SetScr(int scrX, int scrY)
Set current view's dimensions in device context units.
double GetDesiredYmin() const
Returns the bottom-border layer coordinate that the user wants the mpWindow to show (it may be not ex...
void SetBitmap(const wxImage &inBmp, double x, double y, double lx, double ly)
Change the bitmap associated with the layer (to update the screen, refresh the mpWindow).
#define mpSCROLL_NUM_PIXELS_PER_LINE
void SetPos(double posX, double posY)
Set current view's X and Y position and refresh display.
void DoScrollCalc(const int position, const int orientation)
virtual void Plot(wxDC &dc, mpWindow &w) override
Plot method.
mpPrintout(mpWindow *drawWindow, const wxChar *title=_T("wxMathPlot print output"))
~mpInfoLegend()
Default destructor.
virtual void Plot(wxDC &dc, mpWindow &w)=0
Plot given view of layer to the given device context.
std::vector< double > m_shape_ys
std::vector< double > m_trans_shape_xs
The buffer for the translated & rotated points (to avoid recomputing them with each mpWindow refresh)...
virtual void SetData(const std::vector< double > &xs, const std::vector< double > &ys)
Changes the internal data: the set of points to draw.
Plot layer implementing a text string.
virtual bool SetXView(double pos, double desiredMax, double desiredMin)
Applies new X view coordinates depending on the settings.
void OnMouseLeftDown(wxMouseEvent &event)
Canvas for plotting mpLayer implementations.
virtual void Rewind()=0
Rewind value enumeration with mpFXY::GetNextXY.
double m_minX
Loaded at SetData.
virtual double GetX(double y) const =0
Get function value for argument.
#define mpALIGN_BOTTOM
Aligns label to the bottom.
mpScaleX(const wxString &name=wxT("X"), int flags=mpALIGN_CENTER, bool ticks=true, unsigned int type=mpX_NORMAL)
Full constructor.
virtual bool UpdateBBox()
Recalculate global layer bounding box, and save it in m_minX,...
virtual double GetY(double x) const =0
Get function value for argument.
int GetMarginLeft() const
#define mpALIGN_CENTER
Aligns label to the center.
void setPoints(const std::vector< double > &points_xs, const std::vector< double > &points_ys, bool closedShape=true)
Set the points in the polygon.
void OnScrollPageDown(wxScrollWinEvent &event)
void OnScrollTop(wxScrollWinEvent &event)
bool CheckXLimits(double &desiredMax, double &desiredMin) const
bool SaveScreenshot(const wxString &filename, wxBitmapType type=wxBITMAP_TYPE_BMP, wxSize imageSize=wxDefaultSize, bool fit=false)
Draw the window on a wxBitmap, then save it to a file.
double GetDesiredYmax() const
Returns the top layer-border coordinate that the user wants the mpWindow to show (it may be not exact...
double s2y(double plotCoordY) const
virtual int labelCount() const
bool m_enableDoubleBuffer
void GetBoundingBox(double *bbox) const
Returns the bounding box coordinates.
double m_cov_00
The elements of the matrix (only 3 since cov(0,1)=cov(1,0) in any positive definite matrix).
static double zoomIncrementalFactor
This value sets the zoom steps whenever the user clicks "Zoom in/out" or performs zoom with the mouse...
std::vector< double > m_tickValues
const wxPen & GetPen() const
Get pen set for this layer.
virtual void Plot(wxDC &dc, mpWindow &w) override
Layer plot handler.
#define mpALIGN_SE
Aligns label to south-east.
Abstract base class providing plot and labeling functionality for functions F:Y->X.
std::vector< double > m_shape_xs
This contains the object points, in local coordinates (to be transformed by the current transformatio...
#define mpLEGEND_LINEWIDTH
void OnMouseWheel(wxMouseEvent &event)
mpLayerType GetLayerType() const
Get layer type: a Layer can be of different types: plot lines, axis, info boxes, etc,...
#define mpALIGN_BORDER_RIGHT
Aligns Y axis to right border.
virtual bool HasBBox() const override
Check whether this layer has a bounding box.
int GetScrY(void) const
Get current view's Y dimension in device context units.
double m_min_x
The shape of the bitmap:
virtual void Plot(wxDC &dc, mpWindow &w) override
Text Layer plot handler.
#define mpALIGN_SW
Aligns label to south-west.
size_t GetCount() const override