1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxPlotWindow
4 // Author: Robert Roebling
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "plot.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/object.h"
28 #include "wx/colour.h"
29 #include "wx/settings.h"
33 #include "wx/dcclient.h"
36 #include "wx/generic/plot.h"
37 #include "wx/bmpbuttn.h"
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 #if !defined(__WXMSW__) && !defined(__WXPM__)
46 #include "wx/generic/plot_enl.xpm"
47 #include "wx/generic/plot_shr.xpm"
48 #include "wx/generic/plot_zin.xpm"
49 #include "wx/generic/plot_zot.xpm"
50 #include "wx/generic/plot_up.xpm"
51 #include "wx/generic/plot_dwn.xpm"
54 // ----------------------------------------------------------------------------
55 // accessor functions for the bitmaps (may return NULL, check for it!)
56 // ----------------------------------------------------------------------------
58 static wxBitmap
*GetEnlargeBitmap();
59 static wxBitmap
*GetShrinkBitmap();
60 static wxBitmap
*GetZoomInBitmap();
61 static wxBitmap
*GetZoomOutBitmap();
62 static wxBitmap
*GetUpBitmap();
63 static wxBitmap
*GetDownBitmap();
65 //-----------------------------------------------------------------------------
67 //-----------------------------------------------------------------------------
69 #define wxPLOT_SCROLL_STEP 30
71 //-----------------------------------------------------------------------------
73 //-----------------------------------------------------------------------------
75 wxPlotEvent::wxPlotEvent( wxEventType commandType
, int id
)
76 : wxNotifyEvent( commandType
, id
)
78 m_curve
= (wxPlotCurve
*) NULL
;
83 //-----------------------------------------------------------------------------
85 //-----------------------------------------------------------------------------
87 IMPLEMENT_ABSTRACT_CLASS(wxPlotCurve
, wxObject
)
89 wxPlotCurve::wxPlotCurve( int offsetY
, double startY
, double endY
)
96 //-----------------------------------------------------------------------------
98 //-----------------------------------------------------------------------------
100 IMPLEMENT_CLASS(wxPlotOnOffCurve
, wxObject
)
102 #include "wx/arrimpl.cpp"
103 WX_DEFINE_OBJARRAY(wxArrayPlotOnOff
);
105 wxPlotOnOffCurve::wxPlotOnOffCurve( int offsetY
)
112 void wxPlotOnOffCurve::Add( wxInt32 on
, wxInt32 off
, void *clientData
)
114 wxASSERT_MSG( on
> 0, wxT("plot index < 0") );
115 wxASSERT( on
<= off
);
122 wxPlotOnOff
*v
= new wxPlotOnOff
;
125 v
->m_clientData
= clientData
;
129 size_t wxPlotOnOffCurve::GetCount()
131 return m_marks
.GetCount();
134 wxInt32
wxPlotOnOffCurve::GetOn( size_t index
)
136 wxPlotOnOff
*v
= &m_marks
.Item( index
);
140 wxInt32
wxPlotOnOffCurve::GetOff( size_t index
)
142 wxPlotOnOff
*v
= &m_marks
.Item( index
);
146 void* wxPlotOnOffCurve::GetClientData( size_t index
)
148 wxPlotOnOff
*v
= &m_marks
.Item( index
);
149 return v
->m_clientData
;
152 wxPlotOnOff
*wxPlotOnOffCurve::GetAt( size_t index
)
154 return &m_marks
.Item( index
);
157 void wxPlotOnOffCurve::DrawOnLine( wxDC
&dc
, wxCoord y
, wxCoord start
, wxCoord end
, void *WXUNUSED(clientData
) )
159 dc
.DrawLine( start
, y
, start
, y
-30 );
160 dc
.DrawLine( start
, y
-30, end
, y
-30 );
161 dc
.DrawLine( end
, y
-30, end
, y
);
164 void wxPlotOnOffCurve::DrawOffLine( wxDC
&dc
, wxCoord y
, wxCoord start
, wxCoord end
)
166 dc
.DrawLine( start
, y
, end
, y
);
169 //-----------------------------------------------------------------------------
171 //-----------------------------------------------------------------------------
173 IMPLEMENT_DYNAMIC_CLASS(wxPlotArea
, wxWindow
)
175 BEGIN_EVENT_TABLE(wxPlotArea
, wxWindow
)
176 EVT_PAINT( wxPlotArea::OnPaint
)
177 EVT_LEFT_DOWN( wxPlotArea::OnMouse
)
178 EVT_LEFT_DCLICK( wxPlotArea::OnMouse
)
181 wxPlotArea::wxPlotArea( wxPlotWindow
*parent
)
182 : wxWindow( parent
, -1, wxDefaultPosition
, wxDefaultSize
, wxSIMPLE_BORDER
, "plotarea" )
188 SetBackgroundColour( *wxWHITE
);
191 void wxPlotArea::OnMouse( wxMouseEvent
&event
)
195 GetClientSize( &client_width
, &client_height
);
198 m_owner
->GetViewStart( &view_x
, &view_y
);
199 view_x
*= wxPLOT_SCROLL_STEP
;
200 view_y
*= wxPLOT_SCROLL_STEP
;
202 wxCoord x
= event
.GetX();
203 wxCoord y
= event
.GetY();
207 wxNode
*node
= m_owner
->m_curves
.First();
210 wxPlotCurve
*curve
= (wxPlotCurve
*)node
->Data();
212 double double_client_height
= (double)client_height
;
213 double range
= curve
->GetEndY() - curve
->GetStartY();
214 double end
= curve
->GetEndY();
215 wxCoord offset_y
= curve
->GetOffsetY();
217 double dy
= (end
- curve
->GetY( (wxInt32
)(x
/m_owner
->GetZoom()) )) / range
;
218 wxCoord curve_y
= (wxCoord
)(dy
* double_client_height
) - offset_y
- 1;
220 if ((y
-curve_y
< 4) && (y
-curve_y
> -4))
222 wxPlotEvent
event1( event
.ButtonDClick() ? wxEVT_PLOT_DOUBLECLICKED
: wxEVT_PLOT_CLICKED
, m_owner
->GetId() );
223 event1
.SetEventObject( m_owner
);
224 event1
.SetZoom( m_owner
->GetZoom() );
225 event1
.SetCurve( curve
);
226 event1
.SetPosition( (int)floor(x
/m_owner
->GetZoom()) );
227 m_owner
->GetEventHandler()->ProcessEvent( event1
);
229 if (curve
!= m_owner
->GetCurrent());
231 wxPlotEvent
event2( wxEVT_PLOT_SEL_CHANGING
, m_owner
->GetId() );
232 event2
.SetEventObject( m_owner
);
233 event2
.SetZoom( m_owner
->GetZoom() );
234 event2
.SetCurve( curve
);
235 if (!m_owner
->GetEventHandler()->ProcessEvent( event2
) || event2
.IsAllowed())
237 m_owner
->SetCurrent( curve
);
247 void wxPlotArea::DeleteCurve( wxPlotCurve
*curve
, int from
, int to
)
250 m_owner
->PrepareDC( dc
);
251 dc
.SetPen( *wxWHITE_PEN
);
252 DrawCurve( &dc
, curve
, from
, to
);
255 void wxPlotArea::DrawCurve( wxDC
*dc
, wxPlotCurve
*curve
, int from
, int to
)
259 m_owner
->GetViewStart( &view_x
, &view_y
);
260 view_x
*= wxPLOT_SCROLL_STEP
;
267 GetClientSize( &client_width
, &client_height
);
270 to
= view_x
+ client_width
;
272 double zoom
= m_owner
->GetZoom();
274 int start_x
= wxMax( from
, (int)floor(curve
->GetStartX()*zoom
) );
275 int end_x
= wxMin( to
, (int)floor(curve
->GetEndX()*zoom
) );
277 start_x
= wxMax( view_x
, start_x
);
278 end_x
= wxMin( view_x
+ client_width
, end_x
);
282 double double_client_height
= (double)client_height
;
283 double range
= curve
->GetEndY() - curve
->GetStartY();
284 double end
= curve
->GetEndY();
285 wxCoord offset_y
= curve
->GetOffsetY();
287 wxCoord y
=0,last_y
=0;
288 for (int x
= start_x
; x
< end_x
; x
++)
290 double dy
= (end
- curve
->GetY( (wxInt32
)(x
/zoom
) )) / range
;
291 y
= (wxCoord
)(dy
* double_client_height
) - offset_y
- 1;
294 dc
->DrawLine( x
-1, last_y
, x
, y
);
300 void wxPlotArea::DrawOnOffCurve( wxDC
*dc
, wxPlotOnOffCurve
*curve
, int from
, int to
)
304 m_owner
->GetViewStart( &view_x
, &view_y
);
305 view_x
*= wxPLOT_SCROLL_STEP
;
312 GetClientSize( &client_width
, &client_height
);
315 to
= view_x
+ client_width
;
317 double zoom
= m_owner
->GetZoom();
319 int start_x
= wxMax( from
, (int)floor(curve
->GetStartX()*zoom
) );
320 int end_x
= wxMin( to
, (int)floor(curve
->GetEndX()*zoom
) );
322 start_x
= wxMax( view_x
, start_x
);
323 end_x
= wxMin( view_x
+ client_width
, end_x
);
327 wxCoord offset_y
= curve
->GetOffsetY();
328 wxCoord last_off
= -5;
330 if (curve
->GetCount() == 0)
333 for (size_t index
= 0; index
< curve
->GetCount(); index
++)
335 wxPlotOnOff
*p
= curve
->GetAt( index
);
337 wxCoord on
= (wxCoord
)(p
->m_on
*zoom
);
338 wxCoord off
= (wxCoord
)(p
->m_off
*zoom
);
342 curve
->DrawOffLine( *dc
, client_height
-offset_y
, last_off
, on
);
348 curve
->DrawOffLine( *dc
, client_height
-offset_y
, last_off
, on
);
349 curve
->DrawOnLine( *dc
, client_height
-offset_y
, on
, off
, p
->m_clientData
);
354 wxPlotOnOff
*p
= curve
->GetAt( curve
->GetCount()-1 );
355 wxCoord off
= (wxCoord
)(p
->m_off
*zoom
);
357 curve
->DrawOffLine( *dc
, client_height
-offset_y
, off
, to
);
360 void wxPlotArea::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
364 m_owner
->GetViewStart( &view_x
, &view_y
);
365 view_x
*= wxPLOT_SCROLL_STEP
;
366 view_y
*= wxPLOT_SCROLL_STEP
;
368 wxPaintDC
dc( this );
369 m_owner
->PrepareDC( dc
);
371 wxRegionIterator
upd( GetUpdateRegion() );
375 int update_x
= upd
.GetX();
376 int update_y
= upd
.GetY();
377 int update_width
= upd
.GetWidth();
383 if (m_owner->m_current)
385 dc.SetPen( *wxLIGHT_GREY_PEN );
386 int base_line = client_height - m_owner->m_current->GetOffsetY();
387 dc.DrawLine( update_x-1, base_line-1, update_x+update_width+2, base_line-1 );
391 wxNode
*node
= m_owner
->m_curves
.First();
394 wxPlotCurve
*curve
= (wxPlotCurve
*) node
->Data();
396 if (curve
== m_owner
->GetCurrent())
397 dc
.SetPen( *wxBLACK_PEN
);
399 dc
.SetPen( *wxGREY_PEN
);
401 DrawCurve( &dc
, curve
, update_x
-1, update_x
+update_width
+2 );
406 dc
.SetPen( *wxRED_PEN
);
408 node
= m_owner
->m_onOffCurves
.First();
411 wxPlotOnOffCurve
*curve
= (wxPlotOnOffCurve
*) node
->Data();
413 DrawOnOffCurve( &dc
, curve
, update_x
-1, update_x
+update_width
+2 );
422 void wxPlotArea::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
424 wxWindow::ScrollWindow( dx
, dy
, rect
);
425 // m_owner->m_xaxis->ScrollWindow( dx, 0 );
428 //-----------------------------------------------------------------------------
430 //-----------------------------------------------------------------------------
432 IMPLEMENT_DYNAMIC_CLASS(wxPlotXAxisArea
, wxWindow
)
434 BEGIN_EVENT_TABLE(wxPlotXAxisArea
, wxWindow
)
435 EVT_PAINT( wxPlotXAxisArea::OnPaint
)
436 EVT_LEFT_DOWN( wxPlotXAxisArea::OnMouse
)
439 wxPlotXAxisArea::wxPlotXAxisArea( wxPlotWindow
*parent
)
440 : wxWindow( parent
, -1, wxDefaultPosition
, wxSize(-1,40), 0, "plotxaxisarea" )
444 SetBackgroundColour( *wxWHITE
);
445 SetFont( *wxSMALL_FONT
);
448 void wxPlotXAxisArea::OnMouse( wxMouseEvent
&event
)
452 GetClientSize( &client_width
, &client_height
);
455 m_owner
->GetViewStart( &view_x
, &view_y
);
456 view_x
*= wxPLOT_SCROLL_STEP
;
457 view_y
*= wxPLOT_SCROLL_STEP
;
459 wxCoord x
= event
.GetX();
460 wxCoord y
= event
.GetY();
464 /* do something here */
467 void wxPlotXAxisArea::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
471 m_owner
->GetViewStart( &view_x
, &view_y
);
472 view_x
*= wxPLOT_SCROLL_STEP
;
473 view_y
*= wxPLOT_SCROLL_STEP
;
475 wxPaintDC
dc( this );
479 GetClientSize( &client_width
, &client_height
);
481 double zoom
= m_owner
->GetZoom();
483 double ups
= m_owner
->GetUnitsPerValue() / zoom
;
485 double start
= view_x
* ups
;
486 double end
= (view_x
+ client_width
) * ups
;
487 double range
= end
- start
;
489 int int_log_range
= (int)floor( log10( range
) );
491 if (int_log_range
> 0)
493 for (int i
= 0; i
< int_log_range
; i
++)
496 if (int_log_range
< 0)
498 for (int i
= 0; i
< -int_log_range
; i
++)
501 double lower
= ceil(start
/ step
) * step
;
502 double upper
= floor(end
/ step
) * step
;
504 // if too few values, shrink size
505 if ((range
/step
) < 4)
508 if (lower
-step
> start
) lower
-= step
;
509 if (upper
+step
< end
) upper
+= step
;
512 // if still too few, again
513 if ((range
/step
) < 4)
516 if (lower
-step
> start
) lower
-= step
;
517 if (upper
+step
< end
) upper
+= step
;
520 dc
.SetBrush( *wxWHITE_BRUSH
);
521 dc
.SetPen( *wxTRANSPARENT_PEN
);
522 dc
.DrawRectangle( 4, 5, client_width
-14, 10 );
523 dc
.DrawRectangle( 0, 20, client_width
, 20 );
524 dc
.SetPen( *wxBLACK_PEN
);
526 double current
= lower
;
527 while (current
< upper
+(step
/2))
529 int x
= (int)ceil((current
-start
) / range
* (double)client_width
) - 1;
530 if ((x
> 4) && (x
< client_width
-25))
532 dc
.DrawLine( x
, 5, x
, 15 );
536 label
.Printf( wxT("%f"), current
);
537 while (label
.Last() == wxT('0'))
539 if ((label
.Last() == wxT('.')) || (label
.Last() == wxT(',')))
540 label
.Append( wxT('0') );
543 label
.Printf( wxT("%d"), (int)floor(current
) );
544 dc
.DrawText( label
, x
-4, 20 );
550 dc
.DrawLine( 0, 15, client_width
-8, 15 );
551 dc
.DrawLine( client_width
-4, 15, client_width
-10, 10 );
552 dc
.DrawLine( client_width
-4, 15, client_width
-10, 20 );
555 //-----------------------------------------------------------------------------
557 //-----------------------------------------------------------------------------
559 IMPLEMENT_DYNAMIC_CLASS(wxPlotYAxisArea
, wxWindow
)
561 BEGIN_EVENT_TABLE(wxPlotYAxisArea
, wxWindow
)
562 EVT_PAINT( wxPlotYAxisArea::OnPaint
)
563 EVT_LEFT_DOWN( wxPlotYAxisArea::OnMouse
)
566 wxPlotYAxisArea::wxPlotYAxisArea( wxPlotWindow
*parent
)
567 : wxWindow( parent
, -1, wxDefaultPosition
, wxSize(60,-1), 0, "plotyaxisarea" )
571 SetBackgroundColour( *wxWHITE
);
572 SetFont( *wxSMALL_FONT
);
575 void wxPlotYAxisArea::OnMouse( wxMouseEvent
&WXUNUSED(event
) )
577 /* do something here */
580 void wxPlotYAxisArea::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
582 wxPaintDC
dc( this );
584 wxPlotCurve
*curve
= m_owner
->GetCurrent();
590 GetClientSize( &client_width
, &client_height
);
593 double range
= curve
->GetEndY() - curve
->GetStartY();
594 double offset
= ((double) curve
->GetOffsetY() / (double)client_height
) * range
;
595 double start
= curve
->GetStartY() - offset
;
596 double end
= curve
->GetEndY() - offset
;
598 int int_log_range
= (int)floor( log10( range
) );
600 if (int_log_range
> 0)
602 for (int i
= 0; i
< int_log_range
; i
++)
605 if (int_log_range
< 0)
607 for (int i
= 0; i
< -int_log_range
; i
++)
610 double lower
= ceil(start
/ step
) * step
;
611 double upper
= floor(end
/ step
) * step
;
613 // if too few values, shrink size
614 if ((range
/step
) < 4)
617 if (lower
-step
> start
) lower
-= step
;
618 if (upper
+step
< end
) upper
+= step
;
621 // if still too few, again
622 if ((range
/step
) < 4)
625 if (lower
-step
> start
) lower
-= step
;
626 if (upper
+step
< end
) upper
+= step
;
629 dc
.SetPen( *wxBLACK_PEN
);
631 double current
= lower
;
632 while (current
< upper
+(step
/2))
634 int y
= (int)((curve
->GetEndY()-current
) / range
* (double)client_height
) - 1;
635 y
-= curve
->GetOffsetY();
636 if ((y
> 10) && (y
< client_height
-7))
638 dc
.DrawLine( client_width
-15, y
, client_width
-7, y
);
642 label
.Printf( wxT("%f"), current
);
643 while (label
.Last() == wxT('0'))
645 if ((label
.Last() == wxT('.')) || (label
.Last() == wxT(',')))
646 label
.Append( wxT('0') );
649 label
.Printf( wxT("%d"), (int)floor(current
) );
650 dc
.DrawText( label
, 5, y
-7 );
656 dc
.DrawLine( client_width
-15, 6, client_width
-15, client_height
);
657 dc
.DrawLine( client_width
-15, 2, client_width
-20, 8 );
658 dc
.DrawLine( client_width
-15, 2, client_width
-10, 8 );
661 //-----------------------------------------------------------------------------
663 //-----------------------------------------------------------------------------
665 #define ID_ENLARGE 1000
666 #define ID_SHRINK 1002
668 #define ID_MOVE_UP 1006
669 #define ID_MOVE_DOWN 1007
671 #define ID_ZOOM_IN 1010
672 #define ID_ZOOM_OUT 1011
675 IMPLEMENT_DYNAMIC_CLASS(wxPlotWindow
, wxScrolledWindow
)
677 BEGIN_EVENT_TABLE(wxPlotWindow
, wxScrolledWindow
)
678 EVT_BUTTON( ID_MOVE_UP
, wxPlotWindow::OnMoveUp
)
679 EVT_BUTTON( ID_MOVE_DOWN
, wxPlotWindow::OnMoveDown
)
681 EVT_BUTTON( ID_ENLARGE
, wxPlotWindow::OnEnlarge
)
682 EVT_BUTTON( ID_SHRINK
, wxPlotWindow::OnShrink
)
684 EVT_BUTTON( ID_ZOOM_IN
, wxPlotWindow::OnZoomIn
)
685 EVT_BUTTON( ID_ZOOM_OUT
, wxPlotWindow::OnZoomOut
)
687 EVT_SCROLLWIN( wxPlotWindow::OnScroll2
)
690 wxPlotWindow::wxPlotWindow( wxWindow
*parent
, wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
, int flag
)
691 : wxScrolledWindow( parent
, id
, pos
, size
, flag
, "plotcanvas" )
693 m_xUnitsPerValue
= 1.0;
696 m_enlargeAroundWindowCentre
= FALSE
;
697 m_scrollOnThumbRelease
= FALSE
;
699 m_area
= new wxPlotArea( this );
700 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxHORIZONTAL
);
702 if ((GetWindowStyleFlag() & wxPLOT_BUTTON_ALL
) != 0)
704 wxBoxSizer
*buttonlist
= new wxBoxSizer( wxVERTICAL
);
705 if ((GetWindowStyleFlag() & wxPLOT_BUTTON_ENLARGE
) != 0)
707 buttonlist
->Add( new wxBitmapButton( this, ID_ENLARGE
, *GetEnlargeBitmap() ), 0, wxEXPAND
|wxALL
, 2 );
708 buttonlist
->Add( new wxBitmapButton( this, ID_SHRINK
, *GetShrinkBitmap() ), 0, wxEXPAND
|wxALL
, 2 );
709 buttonlist
->Add( 20,10, 0 );
711 if ((GetWindowStyleFlag() & wxPLOT_BUTTON_MOVE
) != 0)
713 buttonlist
->Add( new wxBitmapButton( this, ID_MOVE_UP
, *GetUpBitmap() ), 0, wxEXPAND
|wxALL
, 2 );
714 buttonlist
->Add( new wxBitmapButton( this, ID_MOVE_DOWN
, *GetDownBitmap() ), 0, wxEXPAND
|wxALL
, 2 );
715 buttonlist
->Add( 20,10, 0 );
717 if ((GetWindowStyleFlag() & wxPLOT_BUTTON_ZOOM
) != 0)
719 buttonlist
->Add( new wxBitmapButton( this, ID_ZOOM_IN
, *GetZoomInBitmap() ), 0, wxEXPAND
|wxALL
, 2 );
720 buttonlist
->Add( new wxBitmapButton( this, ID_ZOOM_OUT
, *GetZoomOutBitmap() ), 0, wxEXPAND
|wxALL
, 2 );
722 mainsizer
->Add( buttonlist
, 0, wxEXPAND
|wxALL
, 4 );
725 wxBoxSizer
*plotsizer
= new wxBoxSizer( wxHORIZONTAL
);
727 if ((GetWindowStyleFlag() & wxPLOT_Y_AXIS
) != 0)
729 m_yaxis
= new wxPlotYAxisArea( this );
731 wxBoxSizer
*vert1
= new wxBoxSizer( wxVERTICAL
);
732 plotsizer
->Add( vert1
, 0, wxEXPAND
);
733 vert1
->Add( m_yaxis
, 1 );
734 if ((GetWindowStyleFlag() & wxPLOT_X_AXIS
) != 0)
735 vert1
->Add( 60, 40 );
739 m_yaxis
= (wxPlotYAxisArea
*) NULL
;
742 if ((GetWindowStyleFlag() & wxPLOT_X_AXIS
) != 0)
744 m_xaxis
= new wxPlotXAxisArea( this );
746 wxBoxSizer
*vert2
= new wxBoxSizer( wxVERTICAL
);
747 plotsizer
->Add( vert2
, 1, wxEXPAND
);
748 vert2
->Add( m_area
, 1, wxEXPAND
);
749 vert2
->Add( m_xaxis
, 0, wxEXPAND
);
753 plotsizer
->Add( m_area
, 1, wxEXPAND
);
754 m_xaxis
= (wxPlotXAxisArea
*) NULL
;
757 mainsizer
->Add( plotsizer
, 1, wxEXPAND
);
759 SetAutoLayout( TRUE
);
760 SetSizer( mainsizer
);
762 SetTargetWindow( m_area
);
764 SetBackgroundColour( *wxWHITE
);
766 m_current
= (wxPlotCurve
*) NULL
;
769 wxPlotWindow::~wxPlotWindow()
773 void wxPlotWindow::Add( wxPlotCurve
*curve
)
775 m_curves
.Append( curve
);
776 if (!m_current
) m_current
= curve
;
781 size_t wxPlotWindow::GetCount()
783 return m_curves
.GetCount();
786 wxPlotCurve
*wxPlotWindow::GetAt( size_t n
)
788 wxNode
*node
= m_curves
.Nth( n
);
790 return (wxPlotCurve
*) NULL
;
792 return (wxPlotCurve
*) node
->Data();
795 void wxPlotWindow::SetCurrent( wxPlotCurve
* current
)
798 m_area
->Refresh( FALSE
);
802 wxPlotEvent
event( wxEVT_PLOT_SEL_CHANGED
, GetId() );
803 event
.SetEventObject( this );
804 event
.SetZoom( GetZoom() );
805 event
.SetCurve( m_current
);
806 GetEventHandler()->ProcessEvent( event
);
809 void wxPlotWindow::Delete( wxPlotCurve
* curve
)
811 wxNode
*node
= m_curves
.Find( curve
);
814 m_curves
.DeleteObject( curve
);
816 m_area
->DeleteCurve( curve
);
817 m_area
->Refresh( FALSE
);
820 wxPlotCurve
*wxPlotWindow::GetCurrent()
825 void wxPlotWindow::Add( wxPlotOnOffCurve
*curve
)
827 m_onOffCurves
.Append( curve
);
830 void wxPlotWindow::Delete( wxPlotOnOffCurve
* curve
)
832 wxNode
*node
= m_onOffCurves
.Find( curve
);
835 m_onOffCurves
.DeleteObject( curve
);
838 size_t wxPlotWindow::GetOnOffCurveCount()
840 return m_onOffCurves
.GetCount();
843 wxPlotOnOffCurve
*wxPlotWindow::GetOnOffCurveAt( size_t n
)
845 wxNode
*node
= m_onOffCurves
.Nth( n
);
847 return (wxPlotOnOffCurve
*) NULL
;
849 return (wxPlotOnOffCurve
*) node
->Data();
852 void wxPlotWindow::Move( wxPlotCurve
* curve
, int pixels_up
)
854 m_area
->DeleteCurve( curve
);
856 curve
->SetOffsetY( curve
->GetOffsetY() + pixels_up
);
858 m_area
->Refresh( FALSE
);
863 void wxPlotWindow::OnMoveUp( wxCommandEvent
& WXUNUSED(event
) )
865 if (!m_current
) return;
867 Move( m_current
, 25 );
870 void wxPlotWindow::OnMoveDown( wxCommandEvent
& WXUNUSED(event
) )
872 if (!m_current
) return;
874 Move( m_current
, -25 );
877 void wxPlotWindow::Enlarge( wxPlotCurve
*curve
, double factor
)
879 m_area
->DeleteCurve( curve
);
883 m_area
->GetClientSize( &client_width
, &client_height
);
884 double offset
= (double)curve
->GetOffsetY() / (double)client_height
;
886 double range
= curve
->GetEndY() - curve
->GetStartY();
889 double new_range
= range
/ factor
;
890 double new_offset
= offset
/ factor
;
892 if (m_enlargeAroundWindowCentre
)
894 double middle
= curve
->GetStartY() - offset
+ range
/2;
896 curve
->SetStartY( middle
- new_range
/ 2 + new_offset
);
897 curve
->SetEndY( middle
+ new_range
/ 2 + new_offset
);
901 curve
->SetStartY( (curve
->GetStartY() - offset
)/factor
+ new_offset
);
902 curve
->SetEndY( (curve
->GetEndY() - offset
)/factor
+ new_offset
);
905 m_area
->Refresh( FALSE
);
909 void wxPlotWindow::SetUnitsPerValue( double upv
)
911 m_xUnitsPerValue
= upv
;
916 void wxPlotWindow::SetZoom( double zoom
)
918 double old_zoom
= m_xZoom
;
923 GetViewStart( &view_x
, &view_y
);
926 wxNode
*node
= m_curves
.First();
929 wxPlotCurve
*curve
= (wxPlotCurve
*) node
->Data();
930 if (curve
->GetEndX() > max
)
931 max
= curve
->GetEndX();
934 SetScrollbars( wxPLOT_SCROLL_STEP
, wxPLOT_SCROLL_STEP
,
935 (int)((max
*m_xZoom
)/wxPLOT_SCROLL_STEP
)+1, 0,
936 (int)(view_x
*zoom
/old_zoom
), 0,
940 m_area
->Refresh( TRUE
);
943 void wxPlotWindow::ResetScrollbar()
946 wxNode
*node
= m_curves
.First();
949 wxPlotCurve
*curve
= (wxPlotCurve
*) node
->Data();
950 if (curve
->GetEndX() > max
)
951 max
= curve
->GetEndX();
955 SetScrollbars( wxPLOT_SCROLL_STEP
, wxPLOT_SCROLL_STEP
,
956 (int)(((max
*m_xZoom
)/wxPLOT_SCROLL_STEP
)+1), 0 );
959 void wxPlotWindow::RedrawXAxis()
962 m_xaxis
->Refresh( FALSE
);
965 void wxPlotWindow::RedrawYAxis()
968 m_yaxis
->Refresh( TRUE
);
971 void wxPlotWindow::RedrawEverything()
974 m_xaxis
->Refresh( TRUE
);
976 m_yaxis
->Refresh( TRUE
);
977 m_area
->Refresh( TRUE
);
980 void wxPlotWindow::OnZoomIn( wxCommandEvent
& WXUNUSED(event
) )
982 SetZoom( m_xZoom
* 1.5 );
985 void wxPlotWindow::OnZoomOut( wxCommandEvent
& WXUNUSED(event
) )
987 SetZoom( m_xZoom
* 0.6666 );
990 void wxPlotWindow::OnEnlarge( wxCommandEvent
& WXUNUSED(event
) )
992 if (!m_current
) return;
994 Enlarge( m_current
, 1.5 );
997 void wxPlotWindow::OnShrink( wxCommandEvent
& WXUNUSED(event
) )
999 if (!m_current
) return;
1001 Enlarge( m_current
, 0.6666666 );
1004 void wxPlotWindow::OnScroll2( wxScrollWinEvent
& event
)
1006 if ((!m_scrollOnThumbRelease
) || (event
.GetEventType() != wxEVT_SCROLLWIN_THUMBTRACK
))
1008 wxScrolledWindow::OnScroll( event
);
1013 // ----------------------------------------------------------------------------
1015 // ----------------------------------------------------------------------------
1018 static wxBitmap
*GetEnlargeBitmap()
1020 static wxBitmap
* s_bitmap
= (wxBitmap
*) NULL
;
1021 static bool s_loaded
= FALSE
;
1025 s_loaded
= TRUE
; // set it to TRUE anyhow, we won't try again
1027 #if defined(__WXMSW__) || defined(__WXPM__)
1028 s_bitmap
= new wxBitmap("plot_enl_bmp", wxBITMAP_TYPE_RESOURCE
);
1030 s_bitmap
= new wxBitmap( plot_enl_xpm
);
1037 static wxBitmap
*GetShrinkBitmap()
1039 static wxBitmap
* s_bitmap
= (wxBitmap
*) NULL
;
1040 static bool s_loaded
= FALSE
;
1044 s_loaded
= TRUE
; // set it to TRUE anyhow, we won't try again
1046 #if defined(__WXMSW__) || defined(__WXPM__)
1047 s_bitmap
= new wxBitmap("plot_shr_bmp", wxBITMAP_TYPE_RESOURCE
);
1049 s_bitmap
= new wxBitmap( plot_shr_xpm
);
1056 static wxBitmap
*GetZoomInBitmap()
1058 static wxBitmap
* s_bitmap
= (wxBitmap
*) NULL
;
1059 static bool s_loaded
= FALSE
;
1063 s_loaded
= TRUE
; // set it to TRUE anyhow, we won't try again
1065 #if defined(__WXMSW__) || defined(__WXPM__)
1066 s_bitmap
= new wxBitmap("plot_zin_bmp", wxBITMAP_TYPE_RESOURCE
);
1068 s_bitmap
= new wxBitmap( plot_zin_xpm
);
1075 static wxBitmap
*GetZoomOutBitmap()
1077 static wxBitmap
* s_bitmap
= (wxBitmap
*) NULL
;
1078 static bool s_loaded
= FALSE
;
1082 s_loaded
= TRUE
; // set it to TRUE anyhow, we won't try again
1084 #if defined(__WXMSW__) || defined(__WXPM__)
1085 s_bitmap
= new wxBitmap("plot_zot_bmp", wxBITMAP_TYPE_RESOURCE
);
1087 s_bitmap
= new wxBitmap( plot_zot_xpm
);
1094 static wxBitmap
*GetUpBitmap()
1096 static wxBitmap
* s_bitmap
= (wxBitmap
*) NULL
;
1097 static bool s_loaded
= FALSE
;
1101 s_loaded
= TRUE
; // set it to TRUE anyhow, we won't try again
1103 #if defined(__WXMSW__) || defined(__WXPM__)
1104 s_bitmap
= new wxBitmap("plot_up_bmp", wxBITMAP_TYPE_RESOURCE
);
1106 s_bitmap
= new wxBitmap( plot_up_xpm
);
1113 static wxBitmap
*GetDownBitmap()
1115 static wxBitmap
* s_bitmap
= (wxBitmap
*) NULL
;
1116 static bool s_loaded
= FALSE
;
1120 s_loaded
= TRUE
; // set it to TRUE anyhow, we won't try again
1122 #if defined(__WXMSW__) || defined(__WXPM__)
1123 s_bitmap
= new wxBitmap("plot_dwn_bmp", wxBITMAP_TYPE_RESOURCE
);
1125 s_bitmap
= new wxBitmap( plot_dwn_xpm
);
1132 #endif // wxUSE_PLOT