wxArt2D
zoomcur.cpp
Go to the documentation of this file.
1 /*! \file curves/src/zoomcur.cpp
2  \author Klaas Holwerda
3 
4  Copyright: 2000-2004 (c) Klaas Holwerda
5 
6  Licence: wxWidgets Licence
7 
8  RCS-ID: $Id: zoomcur.cpp,v 1.20 2008/08/19 23:17:11 titato Exp $
9 */
10 
11 #pragma warning(disable:4786)
12 
13 #include "a2dprec.h"
14 
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18 
19 #ifndef WX_PRECOMP
20 #include "wx/wx.h"
21 #endif
22 
23 #include <wx/wfstream.h>
24 #include <math.h>
25 
26 #include "wx/canvas/eval.h"
27 #include "wx/curves/meta.h"
28 
29 #include "wx/canvas/canobj.h"
30 #include "wx/canvas/drawing.h"
31 #include "wx/canvas/drawer.h"
32 #include "wx/canvas/canvas.h"
33 
34 #if wxART2D_USE_EDITOR
35 #include "wx/canvas/edit.h"
36 #endif //wxART2D_USE_EDITOR
37 
38 //----------------------------------------------------------------------------
39 // globals
40 //----------------------------------------------------------------------------
41 
42 IMPLEMENT_CLASS( a2dCurveZoomTool, a2dStTool )
43 
44 
45 //! used to set internal boundaries of canvas plot objects
46 /*!
47 */
49 {
50 
51 public:
52 
53  static const a2dCommandId COMID_SetInternalBoundaries;
54 
56 // double x1, double y1, double x2, double y2 );
58 
59  bool Do( void );
60  bool Undo( void );
61 
62  inline a2dCanvasCommandProcessor* GetCanvasCmp() { return wxStaticCast( m_cmp, a2dCanvasCommandProcessor ); }
63 
64 protected:
65 
66  a2dSmrtPtr<a2dBboxHash> m_irectHash;
67 // double m_x1;
68 // double m_y1;
69 // double m_x2;
70 // double m_y2;
71 
73 
74 
75 };
76 
77 const a2dCommandId a2dCommand_SetInternalBoundaries::COMID_SetInternalBoundaries( wxT( "SetInternalBoundaries" ) );
78 
79 /*
80 * a2dCommand_SetInternalBoundaries
81 */
82 
83 a2dCommand_SetInternalBoundaries::a2dCommand_SetInternalBoundaries(
84  a2dCanvasXYDisplayGroupAreas* object, a2dBboxHash* irectHash ) :
85 // double x1, double y1, double x2, double y2):
86  a2dCommand( true, COMID_SetInternalBoundaries ), m_irectHash( irectHash )
87 {
88  m_canvasobject = object;
89 // m_x1 = x1;
90 // m_y1 = y1;
91 // m_x2 = x2;
92 // m_y2 = y2;
93 }
94 
95 a2dCommand_SetInternalBoundaries::~a2dCommand_SetInternalBoundaries( void )
96 {
97 }
98 
100 {
101  a2dBboxHash* oldIRectHash = new a2dBboxHash;
102  const a2dCurvesAreaList& areaList = m_canvasobject->GetCurvesAreaList();
103  size_t i;
104  for( i = 0; i < areaList.GetCount(); i++ )
105  {
106  a2dCurvesArea* area = areaList.Item( i );
107  const a2dBoundingBox& aRect = area->GetInternalBoundaries();
108  ( *oldIRectHash )[area->GetName()] = aRect;
109  }
110 
111  for( i = 0; i < areaList.GetCount(); i++ )
112  {
113  a2dCurvesArea* area = areaList.Item( i );
114  const a2dBoundingBox& aRect = ( *m_irectHash )[area->GetName()];
115  area->SetInternalBoundaries( m_canvasobject->GetPlotAreaRect(), aRect );
116  }
117  m_canvasobject->SetPending( true );
118  m_canvasobject->GetAxisX()->SetPending( true );
119  if( m_canvasobject->GetCursor() )
120  m_canvasobject->GetCursor()->SetPending( true );
121 
122  m_irectHash = oldIRectHash;
123 
124  m_canvasobject->Update( a2dCanvasObject::updatemask_normal );
125 
126  m_canvasobject->GetRoot()->Modify( true );
128 
129  return true;
130 }
131 
133 {
134  a2dBboxHash* oldIRectHash = new a2dBboxHash;
135  const a2dCurvesAreaList& areaList = m_canvasobject->GetCurvesAreaList();
136  size_t i;
137  for( i = 0; i < areaList.GetCount(); i++ )
138  {
139  a2dCurvesArea* area = areaList.Item( i );
140  const a2dBoundingBox& aRect = area->GetInternalBoundaries();
141  ( *oldIRectHash )[area->GetName()] = aRect;
142  }
143 
144  for( i = 0; i < areaList.GetCount(); i++ )
145  {
146  a2dCurvesArea* area = areaList.Item( i );
147  const a2dBoundingBox& aRect = ( *m_irectHash )[area->GetName()];
148  area->SetInternalBoundaries( m_canvasobject->GetPlotAreaRect(), aRect );
149  }
150  m_canvasobject->SetPending( true );
151  m_canvasobject->GetAxisX()->SetPending( true );
152  if( m_canvasobject->GetCursor() )
153  m_canvasobject->GetCursor()->SetPending( true );
154 
155  m_irectHash = oldIRectHash;
156 
157  m_canvasobject->Update( a2dCanvasObject::updatemask_normal );
158 
159  m_canvasobject->GetRoot()->Modify( true );
161 
162  return true;
163 }
164 
165 
166 //----------------------------------------------------------------------------
167 // a2dCurveZoomTool
168 //----------------------------------------------------------------------------
169 
170 #if wxART2D_USE_EDITOR
171 
172 #define CONTRDRAWER m_controller->GetDrawingPart()
173 #define CONTRDRAWER2D m_controller->GetDrawingPart()->GetDrawer2D()
174 
175 BEGIN_EVENT_TABLE( a2dCurveZoomTool, a2dStTool )
176  EVT_CHAR( a2dCurveZoomTool::OnChar )
177  EVT_MOUSE_EVENTS( a2dCurveZoomTool::OnMouseEvent )
178 END_EVENT_TABLE()
179 
180 a2dCurveZoomTool::a2dCurveZoomTool( a2dStToolContr* controller ): a2dStTool( controller )
181 {
182  m_anotate = true;//false;
183  m_toolcursor = a2dCanvasGlobals->GetCursor( a2dCURSOR_MAGNIFIER );
184  m_toolBusyCursor = a2dCanvasGlobals->GetCursor( a2dCURSOR_CROSS );
185 
186  //stroke and fill should not change as in base class for m_canvasobject
187 
188  //i like transparent fill and specific stroke
189  SetFill( *a2dTRANSPARENT_FILL );
190  SetStroke( a2dStroke( *wxBLACK, 1, a2dSTROKE_LONG_DASH ) );
191 }
192 
193 a2dCurveZoomTool::~a2dCurveZoomTool()
194 {
195 }
196 
198 {
199  // Add old (and later new) annotation area to pending region
201 
202  a2dRect* rec = wxStaticCast( m_canvasobject.Get(), a2dRect );
203  m_anotation.Printf( wxT( "w %6.3f h %6.3f" ) , rec->GetWidth(), rec->GetHeight() );
204  m_xanotation = m_x;
205  m_yanotation = m_y;
206 
207  wxDC* dc = GetDrawer2D()->GetRenderDC();
208  if ( dc )
209  {
210  wxCoord w, h;
211  dc->SetFont( m_annotateFont );
212  dc->GetTextExtent( m_anotation, &w, &h );
213  m_xanotation = m_x + ( int ) h;
214  m_yanotation = m_y + ( int ) h;
216  }
217 }
218 
219 void a2dCurveZoomTool::OnChar( wxKeyEvent& event )
220 {
221  if ( !GetBusy() )
222  {
223  switch( event.GetKeyCode() )
224  {
225  case WXK_RETURN:
226  {
228  }
229  break;
230  case WXK_SUBTRACT:
231  {
233  }
234  break;
235  default:
236  event.Skip();
237  }
238  }
239  else
240  event.Skip();
241 }
242 
243 void a2dCurveZoomTool::OnMouseEvent( wxMouseEvent& event )
244 {
245  if ( !m_active )
246  {
247  event.Skip();
248  return;
249  }
250 
251  if ( GetBusy() )
252  GetDrawingPart()->SetCursor( m_toolBusyCursor );
253  else
254  GetDrawingPart()->SetCursor( m_toolcursor );
255 
256  m_x = event.GetX();
257  m_y = event.GetY();
259 
260  if ( event.LeftDClick() && !GetBusy() )
261  {
262 
263  a2dCanvasObject* object;
264  object = GetDrawingPart()->IsHitWorld( m_xwprev, m_ywprev );
265 
266  if ( !object )
267  return;
268  if ( 0 == wxDynamicCast( object , a2dCanvasXYDisplayGroupAreas ) )
269  {
270  m_curves = 0;
271  return;
272  }
273  m_curves = ( a2dCanvasXYDisplayGroupAreas* )object;
274 
275  a2dBboxHash* aHash = new a2dBboxHash;
276 // m_curves->AppendInternalBoundaries(aHash);
277  m_curves->AppendCurvesBoundaries( aHash );
278 
280  new a2dCommand_SetInternalBoundaries( m_curves, aHash ) );
281 
282  m_curves->SetPending( true );
283  }
284  else if ( event.LeftDown() && !GetBusy() )
285  {
286  a2dCanvasObject* object;
287  object = GetDrawingPart()->IsHitWorld( m_xwprev, m_ywprev );
288 
289  if ( !object )
290  return;
291  if ( 0 == wxDynamicCast( object , a2dCanvasXYDisplayGroupAreas ) )
292  {
293  m_curves = 0;
294  return;
295  }
296  m_curves = ( a2dCanvasXYDisplayGroupAreas* )object;
297 
298  a2dRect* rec = new a2dRect( m_xwprev, m_ywprev, 0, 0, 0 );
300  m_canvasobject = rec;
301  AddDecorationObject( rec );
302 
303  rec->SetRoot( m_parentobject->GetRoot() );
304  rec->SetFill( m_fill );
305  rec->SetStroke( m_stroke );
307  m_pending = true;
308  EnterBusyMode();
309 
310  //special case to have the canvas itself recieve at least this one also.
311  //because often the zoomtool is active as only tool, but
312  //some object on the canvas are meant to react to MD (Href's etc.)
313  event.Skip();
314  }
315  else if ( event.LeftUp() /*event.LeftDown()*/ && GetBusy() )
316  {
317  a2dRect* rec = wxStaticCast( m_canvasobject.Get(), a2dRect );
318 
319  double w = GetDrawer2D()->WorldToDeviceXRel( rec->GetWidth() );
320  double h = GetDrawer2D()->WorldToDeviceYRel( rec->GetHeight() );
321 
322  a2dAffineMatrix tworld = m_curves->GetTransformMatrix();
323 
324  a2dAffineMatrix inverse = tworld;
325  inverse.Invert();
326 
327  //to be able to intercept doubleclick
328  //ignore the LeftDown and LeftUp if mouse position is the same
329  if ( fabs( w ) < 3 && fabs( h ) < 3 )
330  {
331  FinishBusyMode();
332  SetPending( true );
333  a2dCursor* aCursor = m_curves->GetCursor();
334  if( aCursor )
335  {
336 // m_curves->SetCursorPosition(rec->GetPosX(),rec->GetPosY());
337  double xwi;
338  double ywi;
339  inverse.TransformPoint( rec->GetPosX(), rec->GetPosY(), xwi, ywi );
341  double xcurve, ycurve;
342  area->World2Curve( xwi, ywi, xcurve, ycurve );
343  aCursor->SetPosition( xcurve, ycurve, area->GetCurveAreaTransform() );
344  }
345  event.Skip();
346  }
347  else
348  {
349  double xwi;
350  double ywi;
351  double x2wi;
352  double y2wi;
353  inverse.TransformPoint( rec->GetBbox().GetMinX(), rec->GetBbox().GetMinY(), xwi, ywi );
354  inverse.TransformPoint( rec->GetBbox().GetMaxX(), rec->GetBbox().GetMaxY(), x2wi, y2wi );
355 
356  a2dBboxHash* aHash = new a2dBboxHash;
357 
358  const a2dCurvesAreaList& areaList = m_curves->GetCurvesAreaList();
359  for( size_t i = 0; i < areaList.GetCount(); i++ )
360  {
361  a2dCurvesArea* area = areaList.Item( i );
362 
363  double xcurve, ycurve;
364  double xcurve2, ycurve2;
365  area->World2Curve( xwi, ywi, xcurve, ycurve );
366  area->World2Curve( x2wi, y2wi, xcurve2, ycurve2 );
367 
368  a2dBoundingBox aRect( xcurve, ycurve, xcurve2, ycurve2 );
369  ( *aHash )[area->GetName()] = aRect;
370  }
371 
373  new a2dCommand_SetInternalBoundaries( m_curves, aHash ) );
374 
375  m_curves->SetPending( true );
376 
377  FinishBusyMode();
378  event.Skip();
379  }
380  }
381  else if ( ( event.Dragging() && GetBusy() ) /*|| (event.Moving() && GetBusy())*/ )
382  {
383  a2dRect* rec = wxStaticCast( m_canvasobject.Get(), a2dRect );
384  rec->SetWidth( m_xwprev - rec->GetPosX() );
385  rec->SetHeight( m_ywprev - rec->GetPosY() );
386 
387  m_pending = true;
388  }
389  else
390  event.Skip();
391 }
392 
393 #endif //wxART2D_USE_EDITOR
394 
395 
396 
cursor on curve plot as a vertical line with markers
Definition: marker.h:512
int WorldToDeviceXRel(double x) const
convert x relative from world to device coordinates
Definition: drawer2d.h:460
a2dCanvasObjectPtr m_canvasobject
This is the object currently edited.
Definition: sttool.h:381
#define wxDynamicCast(obj, className)
Define wxDynamicCast so that it will give a compiler error for unrelated types.
Definition: gen.h:75
Base class for all types of strokes, understood by a2dDrawer2D classes.
Definition: stylebase.h:378
void SetRoot(a2dDrawing *root, bool recurse=true)
Sets this object to a a2dCanvasDocument.
Definition: canobj.cpp:5933
a2dCanvasObjectPtr m_parentobject
( if needed ) parent a2dCanvasObject relative to which the tool actions take place.
Definition: tools.h:854
classes for plotting curve and pie data, and editing them.
bool m_pending
set when tool needs an redraw (after a a2dCanvas Repaint etc.)
Definition: tools.h:814
virtual wxString GetName() const
Returns the name of this object, if no name is given the internal id will be returned.
Definition: gen.cpp:1310
const a2dAffineMatrix & GetTransformMatrix() const
get the matrix used to position the object
Definition: canobj.h:500
wxCursor m_toolcursor
cursor to use
Definition: tools.h:768
int m_x
x of mouse in device
Definition: sttool.h:352
void AddDecorationObject(a2dCanvasObject *object)
Add a decoration object to be rendered by the tool.
Definition: tools.cpp:932
a2dDrawing * GetRoot() const
get a2dCanvasDocument of the object.
Definition: canobj.h:952
The a2dStTool is used to derive tools from.
Definition: sttool.h:115
a2dSmrtPtr< a2dCurvesArea > GetBaseCurvesArea() const
the a2dCurveArea which has bin set to be the m_leftAxisY
Definition: curvegroup.h:317
a2dDrawingPart * GetDrawingPart()
Access to the tool controllers drawer.
Definition: tools.h:632
virtual bool Update(UpdateMode mode)
Update the state of the object according to its current position etc.
Definition: canobj.cpp:5149
a2dStToolContr * m_stcontroller
controller for canvas
Definition: sttool.h:391
wxString m_anotation
anotation string, which is in general modified by the tools to display position etc.
Definition: sttool.h:340
void World2Curve(double xw, double yw, double &xcurve, double &ycurve)
used by a2dCurve to transform its own curve coordinates to the curve plotting area ...
Definition: curvegroup.cpp:164
a command processor specially designed to work with a a2dCanvasDocument
Definition: drawing.h:1046
virtual void SetPending(bool pending)
set this object pending for update
Definition: canobj.cpp:2585
bool m_active
tool is operational
Definition: tools.h:777
double m_ywprev
y world coordinates old or new value of mouse
Definition: sttool.h:366
The base class for all drawable objects in a a2dCanvasDocument.
virtual void FinishBusyMode(bool closeCommandGroup=true)
Called when the user finishes editing a distinct object */.
Definition: sttool.cpp:1161
double GetWidth() const
return width
Definition: canprim.h:337
void SetPending(bool pending=true)
a tool is set pending when it needs to be redrawn.
Definition: tools.h:615
a2dCanvasObject is the base class for Canvas Objects.
Definition: canobj.h:371
a2dCurveAxis * GetAxisX() const
get X axis object
Definition: curvegroup.h:545
bool Undo(void)
Override this to undo a command.
Definition: zoomcur.cpp:132
void Zoomout()
show all on canvas
Definition: sttool.cpp:378
used to set internal boundaries of canvas plot objects
Definition: zoomcur.cpp:48
void SetWidth(double w)
set width of rectangle
Definition: canprim.h:328
a2dCanvas uses a2dCanvasView for displaying a view on a a2dCanvasDocument.
void TransformPoint(double x, double y, double &tx, double &ty) const
Transform a point.
Definition: afmatrix.cpp:559
a2dStroke m_stroke
stroke for new object
Definition: tools.h:826
Interactive Zooming into a a2dCanvasXYDisplayGroup.
Definition: zoomcur.h:35
void ZoomUndo()
go to previous zoom area (used while another tool is active)
Definition: sttool.cpp:362
int WorldToDeviceYRel(double y) const
convert y relative from world to device coordinates
Definition: drawer2d.h:465
void SetHeight(double h)
set height of rectangle
Definition: canprim.h:334
list for a2dCurvesArea objects
Definition: curvegroup.h:264
a2dDrawer2D * GetDrawer2D()
Access to the tool controllers drawers drawer2d.
Definition: tools.cpp:959
double GetMinX() const
get minimum X of the boundingbox
Definition: bbox.cpp:304
a2dFill m_fill
fill for new object
Definition: tools.h:823
void AddAnotationToPendingUpdateArea()
after calculating anotation position and string, extend the boundingbox of the tools with it...
Definition: sttool.cpp:1358
const a2dBoundingBox & GetPlotAreaRect() const
get the boundingbox in relative world coordinates of the plot area
Definition: curvegroup.h:533
The a2dStToolContr is a Tool Controller specialized for working with a2dCanvasView.
Definition: sttool.h:485
double GetPosX() const
get x position from affine matrix
Definition: canobj.h:527
const a2dAffineMatrix & GetCurveAreaTransform()
Definition: curvegroup.h:111
wxCursor m_toolBusyCursor
cursor to use when the tool is busy doing something.
Definition: tools.h:771
#define wxStaticCast(obj, className)
The wxWindows 2.4.2 wxStaticCast is buggy. It evaluates its argument twice.
Definition: gen.h:123
a2dCanvasObject * GetShowObject() const
return pointer of then currently shown object on the drawer.
Definition: drawer.h:680
int m_yanotation
y position of anotation text
Definition: sttool.h:346
virtual void SetPending(bool pending)
set this object pending for update
Definition: marker.cpp:1850
Special object group to plot a2dCurve Objects but also any other a2dCanvasObject. ...
Definition: curvegroup.h:394
int AppendCurvesBoundaries(a2dBboxHash *irectHash)
fills a2dBboxHash with rectangles representing the plotting area of a curve
Contains a2dDrawing Class to hold a drawing.
virtual void GenerateAnotation()
to display a string along with a tool drawing.
Definition: zoomcur.cpp:197
Each a2dCommand is given a command id at construction.
Definition: comevt.h:99
virtual bool Submit(a2dCommand *command, bool storeIt=true)
next to the base class submit, it sets a2DocumentCommandProcessor for a2dCommand
Definition: comevt.cpp:842
A 2x3 affine matrix class for 2D transformations.
Definition: afmatrix.h:53
double m_xwprev
x world coordinates old or new value of mouse
Definition: sttool.h:363
double GetMaxX() const
get maximum X of the boundingbox
Definition: bbox.cpp:316
double GetPosY() const
get y position from affine matrix
Definition: canobj.h:530
const a2dCurvesAreaList & GetCurvesAreaList() const
return reference to list of all a2dCurveArea objects used
Definition: curvegroup.h:409
All updates of these modes force an update (e.g. update non-pending valid bounding boxes) ...
Definition: canobj.h:1107
a2dCommandProcessor * GetCommandProcessor() const
Returns a pointer to the command processor associated with this document.
Definition: drawing.h:549
void SetStroke(const wxColour &strokecolor, double width=0, a2dStrokeStyle style=a2dSTROKE_SOLID)
Set a stroke for the object which will be used instead of the layer stroke.
Definition: canobj.cpp:2924
int m_y
y of mouse in device
Definition: sttool.h:354
editing tool for a2dCanvasObject&#39;s
double GetMaxY() const
get maximum Y of the boundingbox
Definition: bbox.cpp:322
bool Do(void)
Override this to perform a command.
Definition: zoomcur.cpp:99
a2dCanvasObject * IsHitWorld(double x, double y, int layer=wxLAYER_ALL, a2dHitOption option=a2dCANOBJHITOPTION_NONE, bool filterSelectableLayers=false)
do a hittest on the view at coordinates x,y
Definition: drawer.cpp:1565
virtual wxDC * GetRenderDC() const
get the DC that is used for rendering
Definition: drawer2d.h:226
const a2dBoundingBox & GetInternalBoundaries() const
get the plotting rectangle in curve coordinates
Definition: curvegroup.h:107
a2dRect
Definition: canprim.h:440
The a2dBoundingBox class stores one a2dBoundingBox of a a2dCanvasObject.
Definition: bbox.h:39
bool Invert(void)
Invert matrix.
Definition: afmatrix.cpp:197
wxFont m_annotateFont
font to use for anotation
Definition: tools.h:842
void Modify(bool increment)
set the drawing as modified or not
Definition: drawing.cpp:146
double GetMinY() const
get minimum Y of the boundingbox
Definition: bbox.cpp:310
a2dDrawing * GetDrawing() const
get drawing via top object
Definition: drawer.cpp:726
the a2dDrawingPart is a a2dView specially designed for displaying parts of a a2dDrawing. It uses a a2dDrawer2D to actually redraw things from the document, by giving that a2dDrawer2D as drawing context to the document, and telling the document to redraw a certain rectangular area. At that last is what this class is for. It optimizes the areas to be redrawn after object in the document were changed. To do that it combines redraw areas to a minimal set of redrawing areas. All the administration for this and the way things will be redrawn is from this view.
virtual bool EnterBusyMode()
starts a new action (e.g drawing something ) in a tool that is already pushed.
Definition: sttool.cpp:1147
a2dCanvasGlobal * a2dCanvasGlobals
global a2dCanvasGlobal to have easy access to global settings
Definition: canglob.cpp:1234
void OnChar(wxKeyEvent &event)
character handling
Definition: zoomcur.cpp:219
void MouseToToolWorld(int x, int y, double &xWorldLocal, double &yWorldLocal)
calculate world coordinates from devide coordinates
Definition: sttool.cpp:1622
bool GetBusy()
Check if the tool is busy editing a distinct object */.
Definition: tools.h:513
double GetHeight() const
return height
Definition: canprim.h:339
void SetInternalBoundaries(const a2dBoundingBox &extbox, const a2dBoundingBox &intbox)
set the internal curve boundaries, and update conversion to world matrix
Definition: curvegroup.h:94
int m_xanotation
x position of anotation text
Definition: sttool.h:343
a2dBoundingBox & GetBbox()
get boundingbox in world coordinates exclusive stroke width relative to its parent ...
Definition: canobj.cpp:3175
void SetFill(const a2dFill &fill)
Set a fill for the object which will be used instead of the layer fill.
Definition: canobj.cpp:2874
const a2dFill * a2dTRANSPARENT_FILL
global a2dFill stock object for TRANSPARENT filling
base class for curve area in a a2dCurvesAreaList, like used in a2dCanvasXYDisplayGroups ...
Definition: curvegroup.h:56
a base command for the a2dCommandProcessor
Definition: comevt.h:140
zoomcur.cpp Source File -- Sun Oct 12 2014 17:04:26 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation