wxArt2D
polygon.h
Go to the documentation of this file.
1 /*! \file wx/canvas/polygon.h
2  \brief all polygon and polyline a2dCanvasObject are here.
3 
4  Next to that the handle classes that are specialized for editing polygonn types.
5 
6  \author Klaas Holwerda
7 
8  Copyright: 2000-2004 (c) Klaas Holwerda
9 
10  Licence: wxWidgets Licence
11 
12  RCS-ID: $Id: polygon.h,v 1.35 2009/10/01 19:22:35 titato Exp $
13 */
14 
15 #ifndef __WXPOLYGON_H__
16 #define __WXPOLYGON_H__
17 
18 #ifndef WX_PRECOMP
19 #include "wx/wx.h"
20 #endif
21 
22 #include "wx/artbase/afmatrix.h"
23 #include "wx/geometry.h"
24 #include "wx/artbase/bbox.h"
25 #include "wx/artbase/polyver.h"
26 
27 #include "wx/canvas/canobj.h"
28 
29 class A2DCANVASDLLEXP a2dPolyHandleL;
30 
31 //----------------------------------------------------------------------------
32 // a2dPolygonL
33 //----------------------------------------------------------------------------
34 
35 //!polygon defined with list of points.
36 /*!
37  The point in the polygon are relative to 0,0, without the local matrix aplied.
38  So all points will be transformed with the local matrix before drawing them.
39  The position of the polygon is defined by the local matrix its translation.
40  A polygon point (0,0) would be exactly at the translation set in the local matrix.
41 
42  \ingroup canvasobject
43 
44 */
45 class A2DCANVASDLLEXP a2dPolygonL: public a2dCanvasObject
46 {
47  DECLARE_EVENT_TABLE()
48 
49 public:
50 
51  a2dPolygonL();
52  a2dPolygonL( a2dVertexListPtr points, bool spline = false );
53  a2dPolygonL( const a2dPolygonL& poly, CloneOptions options, a2dRefMap* refs );
54  ~a2dPolygonL();
55 
56  a2dCanvasObjectList* GetAsCanvasVpaths( bool transform = true ) const;
57 
58  virtual a2dVertexList* GetAsVertexList( bool& returnIsPolygon ) const;
59 
60  virtual a2dCanvasObjectList* GetAsLinesArcs( bool transform = true );
61 
62  virtual a2dCanvasObjectList* GetSnapVpath( a2dSnapToWhatMask snapToWhat );
63 
64  virtual bool RestrictToObject( a2dIterC& ic, const a2dPoint2D& pointToSnapTo, a2dPoint2D& bestPointSofar, a2dSnapToWhatMask snapToWhat, double thresHoldWorld );
65 
66  //! add point/segment after a segment.
67  /*!
68  \param x x of segment to add.
69  \param y y of segment to add.
70  \param seg insert new segment starting at x, y here. If NULL, add at end.
71  \param afterinversion if true, x,y is first transformed to the polygon its segments, using its matrix.
72 
73  \return pointer to new inserted segment
74  */
75  a2dLineSegment* AddPoint( double x, double y, a2dLineSegmentPtr seg = NULL, bool afterinversion = true );
76  //! add point/segment after index given
77  a2dLineSegment* AddPoint( const a2dPoint2D& P, int index, bool afterinversion = true );
78  //! add point/segment after index given
79  a2dLineSegment* AddPoint( double x, double y, int index, bool afterinversion = true );
80  //! insert segment after index given
81  virtual void InsertSegment( unsigned int index, a2dLineSegmentPtr segin ) { m_lsegments->Insert( index, segin ); }
82 
83  //! remove all points that are redundant
84  /*! currently this only removes successive points at the same coordinate,
85  but it could also remove points with an angle of 180 deg
86  \param sendCommandsTo if not NULL, send a2dCommand_RemovePoint commands to this object
87  */
88  void RemoveRedundantPoints( a2dCanvasObject* sendCommandsTo = NULL );
89 
90  //!removes point at index
91  /*!
92  \param x x value of removed point
93  \param y y value of removed point
94  \param seg which segment
95  \param transformed if true returned values x,y are transformed with local matrix
96  */
97  virtual void RemoveSegment( double& x, double& y , a2dLineSegmentPtr seg = NULL, bool transformed = true );
98 
99  //!removes point at index
100  /*!
101  \param x x value of removed point
102  \param y y value of removed point
103  \param index index of point to remove (-1 means last point)
104  \param transformed if true returned values x,y are transformed with local matrix
105  */
106  void RemoveSegment( double& x, double& y , int index = -1, bool transformed = true );
107 
108  //! Remove and delete all points in the polygon
109  void Clear();
110 
111  //! reduce matrix to identity without replacing object
112  bool EliminateMatrix();
113 
114  //!modify point at index to x,y
115  /*!
116  Set the coordinates of the point at index to x,y.
117  \param index the index of the point to change
118  \param x new x for the point
119  \param y new y for the point
120  \param afterinversion if true the input x,y or first inverted with the local matrix of the object.
121  The inverted values are used to set the point.
122 
123  \remark afterinversion = true should be used if you have x,y relative to the polygon object,
124  while afterinversion = false should be used when x,y are relative to the point in the polygon.
125  */
126  void SetPosXYSegment( int index, double x, double y, bool afterinversion = true );
127 
128  //!modify point at index to x,y
129  /*!
130  Set the coordinates of the point at index to x,y.
131  \param seg the segment to change
132  \param x new x for the point
133  \param y new y for the point
134  \param afterinversion if true the input x,y or first inverted with the local matrix of the object.
135  The inverted values are used to set the point.
136 
137  \remark afterinversion = true should be used if you have x,y relative to the polygon object,
138  while afterinversion = false should be used when x,y are relative to the point in the polygon.
139  */
140  virtual void SetPosXYSegment( a2dLineSegmentPtr seg, double x, double y, bool afterinversion = true );
141 
142 
143  //!modify middle point of arcsegment at index to x,y
144  /*!
145  Set the coordinates of the point at index to x,y.
146  \param seg the segment to change
147  \param x new x for the middle point
148  \param y new y for the middle point
149  \param afterinversion if true the input x,y or first inverted with the local matrix of the object.
150  The inverted values are used to set the point.
151 
152  \remark afterinversion = true should be used if you have x,y relative to the polygon object,
153  while afterinversion = false should be used when x,y are relative to the point in the polygon.
154  */
155  void SetPosXYMidSegment( a2dLineSegmentPtr seg, double x, double y, bool afterinversion = true );
156 
157  //!modify middle point of arcsegment at index to x,y
158  /*!
159  Set the coordinates of the point at index to x,y.
160  \param index the index of the point to change
161  \param x new x for the middle point
162  \param y new y for the middle point
163  \param afterinversion if true the input x,y or first inverted with the local matrix of the object.
164  The inverted values are used to set the point.
165 
166  \remark afterinversion = true should be used if you have x,y relative to the polygon object,
167  while afterinversion = false should be used when x,y are relative to the point in the polygon.
168  */
169  void SetPosXYMidSegment( int index, double x, double y, bool afterinversion = true );
170 
171  //! get point x and y at index
172  /*!
173  \param index the index of the point to get (-1 for last segment)
174  \param x new x for the point
175  \param y new y for the point
176  \param transform if true return x y transformed with local matrix
177  */
178  void GetPosXYSegment( int index, double& x, double& y, bool transform = true ) const;
179 
180  //! get point x and y at index
181  /*!
182  \param seg the segment to change
183  \param x new x for the point
184  \param y new y for the point
185  \param transform if true return x y transformed with local matrix
186  */
187  virtual void GetPosXYSegment( a2dLineSegmentPtr seg, double& x, double& y, bool transform = true ) const;
188 
189  //! get middle point of arcsegment at index to x,y
190  /*!
191  \param index the index of the point to get
192  \param x new x for the point
193  \param y new y for the point
194  \param transform if true return x y transformed with local matrix
195  */
196  void GetPosXYMidSegment( int index, double& x, double& y, bool transform = true ) const;
197 
198  //! get middle point of arcsegment at index to x,y
199  /*!
200  \param seg the segment to change
201  \param x new x for the point
202  \param y new y for the point
203  \param transform if true return x y transformed with local matrix
204  */
205  void GetPosXYMidSegment( a2dLineSegmentPtr seg, double& x, double& y, bool transform = true ) const;
206 
207  //! adjust the polygon after a point change
208  /*! This version does nothing, but derived classes, notably wires, might want to update
209  something when the point coordinates change. This is not part of SetPosXYPoint,
210  because these updates should only be done by interactive editing functions on copies
211  by e.g. handle events, and not by commands.
212  As an example a2dWirePolylineL uses this function to adjust a2dPin location with its segments.
213  \param final if true make changes by issuing stored commands
214  \return true if a change was made
215  */
216  virtual bool AdjustAfterChange( bool final );
217 
218  //! Get the list of points ( this is not a copy! )
219  a2dVertexListPtr GetSegments() { return m_lsegments; }
220 
221  //! Set the list of points ( the old list is NOT DELETED !!! )
222  /*!
223  \param points list of points
224  \param delold if true, the old points list is deleted. Be carefull, if the points list is still needed for undo redo.
225  */
226  void SetSegments( a2dVertexList* points );
227 
228  //! get the number of points in the pointlist
229  size_t GetNumberOfSegments() { return m_lsegments->size(); }
230 
231  //! set to true, the polygon will be drawn as a spline
232  void SetSpline( bool on ) { m_spline = on; SetPending( true ); }
233 
234  //! Get the polygon spline setting
235  bool GetSpline() { return m_spline; }
236 
237  void SetContourWidth( double width ) { m_contourwidth = width; SetPending( true ); }
238 
239  //!get the Contour width of the shape
240  double GetContourWidth() const { return m_contourwidth; }
241 
242  //!Set Polygon filling mode wxODDEVEN_RULE or wxWINDING_RULE
243  void SetFillRule( wxPolygonFillMode val ) { m_oddeven = val; }
244 
245  //!Get Polygon filling mode wxODDEVEN_RULE or wxWINDING_RULE
246  wxPolygonFillMode GetFillRule() { return m_oddeven; }
247 
248  //! a handle in editing is updated to a segment at index given
249  virtual void SetHandleToIndex( a2dPolyHandleL* handle, unsigned int index );
250 
251  virtual int GetIndexSegment( a2dLineSegmentPtr seg );
252 
253  virtual a2dVertexList::iterator GetSegmentAtIndex( unsigned int index );
254 
255  virtual a2dVertexList* GetSegmentListAtIndex( unsigned int index );
256 
257 #if wxART2D_USE_CVGIO
258  void DoSave( wxObject* parent, a2dIOHandlerXmlSerOut& out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite );
259 
260  void DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts );
261 #endif //wxART2D_USE_CVGIO
262 
263  a2dHit PointInPolygon( const a2dPoint2D& P, double marge );
264 
265  static void SetAllowCrossAtVertex( bool allowCrossAtVertex ) { m_allowCrossAtVertex = allowCrossAtVertex; }
266 
267  DECLARE_DYNAMIC_CLASS( a2dPolygonL )
268 
269 protected:
270 
271  virtual a2dObject* DoClone( CloneOptions options, a2dRefMap* refs ) const;
272 
273  void SyncHandlesWithLineSegments();
274 
275  virtual bool DoStartEdit( wxUint16 editmode, wxEditStyle editstyle );
276 
277  void OnCanvasObjectMouseEvent( a2dCanvasObjectMouseEvent& event );
278 
279  void OnChar( wxKeyEvent& event );
280 
281  void OnEnterObject( a2dCanvasObjectMouseEvent& event );
282 
283  void OnLeaveObject( a2dCanvasObjectMouseEvent& event );
284 
285  void OnHandleEvent( a2dHandleMouseEvent& event );
286 
287  void OnHandleEventEnter( a2dHandleMouseEvent& event );
288 
289  void OnHandleEventLeave( a2dHandleMouseEvent& event );
290 
291  void DoRender( a2dIterC& ic, OVERLAP clipparent );
292  //return this object if one of the objects it references is hit
293  bool DoIsHitWorld( a2dIterC& ic, a2dHitEvent& hitEvent );
294  a2dBoundingBox DoGetUnTransformedBbox( a2dBboxFlags flags = a2dCANOBJ_BBOX_NON ) const;
295  bool DoUpdate( UpdateMode mode, const a2dBoundingBox& childbox, const a2dBoundingBox& clipbox, const a2dBoundingBox& propbox );
296 
297  a2dSmrtPtr<a2dVertexList> m_lsegments;
298 
299  static bool m_allowCrossAtVertex;
300 
301  bool m_spline: 1;
302  bool m_crossAtVertex: 1;
303 
304  wxPolygonFillMode m_oddeven; //: 2; make this a bitfield if new members are added
305 
306  //! if != 0 the polygon is contoured at distance m_contourwidth/2
307  double m_contourwidth;
308 
309 private:
310  //!this is a not implemented copy constructor that avoids automatic creation of one
311  a2dPolygonL( const a2dPolygonL& other );
312 };
313 
314 #if defined(WXART2D_USINGDLL)
315 template class A2DCANVASDLLEXP a2dSmrtPtr<a2dPolygonL>;
316 #endif
317 
318 //----------------------------------------------------------------------------
319 // a2dPolylineL
320 //----------------------------------------------------------------------------
321 
322 //!polyline defined with list of points.
323 /*!
324  The point in the polyline are relative to 0,0, without the local matrix aplied.
325  So all points will be transformed with the local matrix before drawing them.
326  The position of the polyline is defined by the local matrix its translation.
327  A polyline point (0,0) would be exactly at the translation set in the local matrix.
328 
329  \ingroup canvasobject
330 
331 */
332 class A2DCANVASDLLEXP a2dPolylineL: public a2dPolygonL
333 {
334  DECLARE_EVENT_TABLE()
335 
336 public:
337  a2dPolylineL();
338  a2dPolylineL( a2dVertexListPtr segments, bool spline = false );
339  a2dPolylineL( const a2dPolylineL& poly, CloneOptions options, a2dRefMap* refs );
340  ~a2dPolylineL();
341 
342  virtual a2dVertexList* GetAsVertexList( bool& returnIsPolygon ) const;
343 
344  a2dCanvasObjectList* GetAsCanvasVpaths( bool transform = true ) const;
345 
346  virtual a2dCanvasObjectList* GetAsLinesArcs( bool transform = true );
347 
348  //! remove all points that are redundant
349  /*! removes successive points at the same coordinate,
350  or if 3 successive points are one the same vertical or horizontal line, remove the middle point
351  \param sendCommandsTo if not NULL, send a2dCommand_RemovePoint commands to this object
352  */
353  void RemoveRedundantPoints( a2dCanvasObject* sendCommandsTo = NULL );
354 
355  //! remove segments which are opposite direction overlapping.
356  /*!
357  \param sendCommandsTo if not NULL, send a2dCommand_RemovePoint commands to this object
358  \param removeZeroFirst if true first zero lenght segments are removed.
359  */
360  void Remove180DegPoints( a2dCanvasObject* sendCommandsTo = NULL, bool removeZeroFirst = true );
361 
362 #if wxART2D_USE_CVGIO
363  void DoSave( wxObject* parent, a2dIOHandlerXmlSerOut& out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite );
364 
365  void DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts );
366 #endif //wxART2D_USE_CVGIO
367 
368  virtual void DoWalker( wxObject* parent, a2dWalkerIOHandler& handler );
369 
370  a2dHit PointOnPolyline( const a2dPoint2D& P, double marge );
371 
372  //! set object to draw as begin point
373  void SetBegin( a2dCanvasObject* begin );
374 
375  a2dCanvasObject* GetBegin() { return m_begin; }
376 
377  //! set object to draw as end point
378  void SetEnd( a2dCanvasObject* end );
379 
380  a2dCanvasObject* GetEnd() { return m_end; }
381 
382  //!scale begin and end object with this factor in X
383  /*!
384  \remark set object pending for redraw
385  */
386  void SetEndScaleX( double xs ) { m_xscale = xs; SetPending( true ); }
387 
388  //!scale begin and end object with this factor in X
389  double GetEndScaleX() { return m_xscale; }
390 
391  //!scale begin and end object with this factor in Y
392  /*!
393  \remark set object pending for redraw
394  */
395  void SetEndScaleY( double ys ) { m_yscale = ys; SetPending( true ); }
396 
397  //!scale begin and end object with this factor in X
398  double GetEndScaleY() { return m_yscale; }
399 
400  //! Set when m_contourwidth != 0 what is the end of the line should be.
401  void SetPathType( a2dPATH_END_TYPE pathtype ) { m_pathtype = pathtype; SetPending( true ); }
402 
403  //! get when m_contourwidth != 0 what is the end of the line looks like.
404  a2dPATH_END_TYPE GetPathType() { return m_pathtype; }
405 
406  DECLARE_DYNAMIC_CLASS( a2dPolylineL )
407 
408  //! Find the point on the polyline closest to the given world point
409  /*! \param cworld is the accumulated affine transformation WITHOUT the local transform. If NULL, all coordinates are local
410  \param xIn x-world coordinate of point to which nearest point on line is searched
411  \param yIn y-world coordinate of point to which nearest point on line is searched
412  \param xOut x-world coordinate of nearest point on line
413  \param yOut y-world coordinate of nearest point on line
414  */
415  bool FindNearPoint( const a2dAffineMatrix* cworld, double xIn, double yIn, double* xOut, double* yOut );
416 
417  //! Find the point on the polyline that is the closest orthogonal projection to the given world point
418  /*! \param cworld is the accumulated affine transformation WITHOUT the local transform. If NULL, all coordinates are local
419  \param xIn x-world coordinate of point to which nearest point on line is searched
420  \param yIn y-world coordinate of point to which nearest point on line is searched
421  \param xOut x-world coordinate of nearest point on line
422  \param yOut y-world coordinate of nearest point on line
423  */
424  bool FindNearPointOrtho( const a2dAffineMatrix* cworld, double xIn, double yIn, double* xOut, double* yOut );
425 
426  //! Move the given dynamic pin close to the given absolute point
427  /*! \return true if the pin was really moved */
428  bool MoveDynamicPinCloseTo( a2dPin* pin, const a2dPoint2D& point, bool final );
429 
430  //! pins on the begin and end of the wire are created, and after that
431  //! point along the line if possible at position x,y
432  virtual bool GeneratePins( a2dPinClass* toConnectTo, a2dConnectTask task, double x, double y, double margin = 0 );
433 
434  //! Get the begin pin from the childs
435  a2dPin* FindBeginPin();
436  //! Get the end pin from the childs
437  a2dPin* FindEndPin();
438  //! Get all pins one by one. i is updated by this function.
439  a2dPin* FindPin( int* i );
440 
441  a2dLineSegment* GetFirstPoint() const;
442  a2dLineSegment* GetLastPoint() const;
443 
444  int FindSegmentIndex( const a2dPoint2D& point, double margin = a2dACCUR );
445 
446  //! find the index of the segment where the pin is on.
447  int FindPinSegmentIndex( a2dPin* pinToFind, double margin = a2dACCUR );
448 
449  //! find the segment where the pin is on.
450  a2dLineSegment* FindPinSegment( a2dPin* pinToFind, double margin = a2dACCUR );
451 
452  //! new object willl generate pins or not based on this value
453  static bool SetDefaultGeneratePins( bool value ) { m_generatePins = value; }
454 
455  //! new object willl generate pins or not based on this value
456  static bool GetDefaultGeneratePins() { return m_generatePins; }
457 
458 protected:
459 
460  virtual a2dObject* DoClone( CloneOptions options, a2dRefMap* refs ) const;
461 
462  bool DoCanConnectWith( a2dIterC& ic, a2dPin* pin, double margin, bool autocreate );
463 
464  void DoRender( a2dIterC& ic, OVERLAP clipparent );
465  //!return this object if one of the objects it references is hit
466  bool DoIsHitWorld( a2dIterC& ic, a2dHitEvent& hitEvent );
467  a2dBoundingBox DoGetUnTransformedBbox( a2dBboxFlags flags = a2dCANOBJ_BBOX_NON ) const;
468  bool DoUpdate( UpdateMode mode, const a2dBoundingBox& childbox, const a2dBoundingBox& clipbox, const a2dBoundingBox& propbox );
469 
470  void OnChar( wxKeyEvent& event );
471 
472  a2dCanvasObjectPtr m_begin;
473  a2dCanvasObjectPtr m_end;
474 
475  double m_xscale;
476  double m_yscale;
477 
478  static bool m_generatePins;
479 
480  //! when m_contourwidth != 0 what is the end of the line looking like.
482 
483 private:
484  //!this is a not implemented copy constructor that avoids automatic creation of one
485  a2dPolylineL( const a2dPolylineL& other );
486 };
487 
488 #if defined(WXART2D_USINGDLL)
489 template class A2DCANVASDLLEXP a2dSmrtPtr<a2dPolylineL>;
490 #endif
491 
492 //----------------------------------------------------------------------------
493 // a2dSurface
494 //----------------------------------------------------------------------------
495 
496 //!polygon defined with list of points for outer contour plus a list of hole polygons
497 /*!
498  As a a2dPolygonL but, and extra list of polygons is used to define holes within the outer contour.
499 
500  \ingroup canvasobject
501 */
502 class A2DCANVASDLLEXP a2dSurface: public a2dPolygonL
503 {
504  DECLARE_EVENT_TABLE()
505 
506 public:
507 
508  a2dSurface();
509  a2dSurface( a2dVertexListPtr points, bool spline = false );
510  a2dSurface( const a2dSurface& poly, CloneOptions options, a2dRefMap* refs );
511  ~a2dSurface();
512 
513  a2dVertexList* GetAsVertexList( bool& returnIsPolygon ) const;
514 
515  //! convert contour to a polygons and holes to seperate polygons.
516  /*!
517  Holes will be lost in this case.
518  */
519  virtual a2dCanvasObjectList* GetAsPolygons( bool transform = true ) const;
520 
521  //! convert contour to a polyline and holes to seperate polylines.
522  /*!
523  */
524  virtual a2dCanvasObjectList* GetAsPolylines( bool transform = true ) const;
525 
526  virtual a2dCanvasObjectList* GetAsCanvasVpaths( bool transform = true ) const;
527 
528  virtual a2dCanvasObjectList* GetAsLinesArcs( bool transform = true );
529 
530  void AddHole( a2dVertexListPtr holepoints );
531 
532  //! remove all points that are redundant
533  /*! removes successive points at the same coordinate,
534  or if 3 successive points are one the same vertical or horizontal line, remove the middle point
535  \param sendCommandsTo if not NULL, send a2dCommand_RemovePoint commands to this object
536  */
537  void RemoveRedundantPoints( a2dCanvasObject* sendCommandsTo = NULL );
538 
539  //! Remove and delete all points in the polygon
540  void Clear();
541 
542  //! reduce matrix to identity without replacing object
543  bool EliminateMatrix();
544 
545  //! Get the list of points ( this is not a copy! )
546  a2dVertexListPtr GetSegments() { return m_lsegments; }
547 
548  //! Set the list of points ( the old list is NOT DELETED !!! )
549  /*!
550  \param points list of points
551  \param delold if true, the old points list is deleted. Be carefull, if the points list is still needed for undo redo.
552  */
553  void SetSegments( a2dVertexList* points );
554 
555  //! get the number of points in the pointlist
556  size_t GetNumberOfSegments() { return m_lsegments->size(); }
557 
558 #if wxART2D_USE_CVGIO
559  void DoSave( wxObject* parent, a2dIOHandlerXmlSerOut& out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite );
560 
561  void DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts );
562 #endif //wxART2D_USE_CVGIO
563 
564  void SetContourWidth( double width ) {}
565 
566  //!get the Contour width of the shape
567  double GetContourWidth() const { return 0; }
568 
569  a2dListOfa2dVertexList& GetHoles() { return m_holes; }
570 
571  void SetHandleToIndex( a2dPolyHandleL* handle, unsigned int index );
572 
573  int GetIndexSegment( a2dLineSegmentPtr seg );
574 
575  virtual a2dVertexList::iterator GetSegmentAtIndex( unsigned int index );
576 
577  virtual a2dVertexList* GetSegmentListAtIndex( unsigned int index );
578 
579  void RemoveSegment( double& x, double& y , a2dLineSegmentPtr seg = NULL, bool transformed = true );
580 
581  void InsertSegment( unsigned int index, a2dLineSegmentPtr segin );
582 
583  void GetPosXYSegment( a2dLineSegmentPtr seg, double& x, double& y, bool transform = true ) const;
584 
585  void SetPosXYSegment( a2dLineSegmentPtr seg, double x, double y, bool afterinversion = true );
586 
587  DECLARE_DYNAMIC_CLASS( a2dSurface )
588 
589 protected:
590 
591  virtual a2dObject* DoClone( CloneOptions options, a2dRefMap* refs ) const;
592  bool DoStartEdit( wxUint16 editmode, wxEditStyle editstyle );
593 
594  void OnCanvasObjectMouseEvent( a2dCanvasObjectMouseEvent& event );
595 
596  void OnHandleEvent( a2dHandleMouseEvent& event );
597 
598  void DoRender( a2dIterC& ic, OVERLAP clipparent );
599  //return this object if one of the objects it references is hit
600  bool DoIsHitWorld( a2dIterC& ic, a2dHitEvent& hitEvent );
601  a2dBoundingBox DoGetUnTransformedBbox( a2dBboxFlags flags = a2dCANOBJ_BBOX_NON ) const;
602  bool DoUpdate( UpdateMode mode, const a2dBoundingBox& childbox, const a2dBoundingBox& clipbox, const a2dBoundingBox& propbox );
603 
604  a2dListOfa2dVertexList m_holes;
605 
606 private:
607  //!this is a not implemented copy constructor that avoids automatic creation of one
608  a2dSurface( const a2dSurface& other );
609 };
610 
611 
612 //! clips all children to a polygon
613 /*!
614 
615  \ingroup canvasobject
616 */
617 class A2DCANVASDLLEXP a2dPolygonLClipper: public a2dPolygonL
618 {
619 public:
620 
621  //! construct the clipping polygon according to the given box
623 
624  //! construct the clipping polygon according to the given polygon
625  a2dPolygonLClipper( a2dVertexList* points, bool spline = false );
626 
627  //! destructor
629 
630  //! copy with clone options
631  a2dPolygonLClipper( const a2dPolygonLClipper& other, CloneOptions options, a2dRefMap* refs );
632 
633  //!Set the matrix used for the clipping polygon
634  /*!
635  Children object are clipped to a polygon.
636  The child object are transformed with the m_lworld transform.
637  But the clipping polygon is using m_ClipLworld to place/draw itself.
638 
639  \param mat matrix to be used for the clipping polygon
640  */
641  void SetClippingTransformMatrix( const a2dAffineMatrix& mat = a2dIDENTITY_MATRIX );
642 
643  //! set the clipping polygon according to the given box
644  void SetClippingFromBox( a2dBoundingBox& bbox = wxNonValidBbox );
645 
646  //! render by first setting clipping box and next start rendering children and itself.
647  void Render( a2dIterC& ic, OVERLAP clipparent );
648 
649  virtual bool Update( UpdateMode mode );
650 
651 protected:
652 
653  //! clone it
654  virtual a2dObject* DoClone( CloneOptions options, a2dRefMap* refs ) const;
655  void DoRender( a2dIterC& ic, OVERLAP clipparent );
656 
657  //! clipping matrix.
659 
660  DECLARE_DYNAMIC_CLASS( a2dPolygonLClipper )
661 
662 private:
663  //!this is a not implemented copy constructor that avoids automatic creation of one
664  a2dPolygonLClipper( const a2dPolygonLClipper& other );
665 };
666 
667 #if defined(WXART2D_USINGDLL)
668 template class A2DCANVASDLLEXP a2dSmrtPtr<a2dPolygonLClipper>;
669 #endif
670 
671 //! clips all children to a polygon
672 /*!
673 
674  \ingroup canvasobject
675 */
676 class A2DCANVASDLLEXP a2dPolygonLClipper2: public a2dPolygonL
677 {
678 public:
679 
681 
682  a2dPolygonLClipper2( a2dVertexList* segments, bool spline = false );
683 
685 
686  a2dPolygonLClipper2( const a2dPolygonLClipper2& other, CloneOptions options, a2dRefMap* refs );
687 
688  void Render( a2dIterC& ic, OVERLAP clipparent );
689 
690  virtual bool Update( UpdateMode mode );
691 
692 protected:
693 
694  virtual a2dObject* DoClone( CloneOptions options, a2dRefMap* refs ) const;
695 
696  void DoRender( a2dIterC& ic, OVERLAP clipparent );
697 
698  DECLARE_DYNAMIC_CLASS( a2dPolygonLClipper2 )
699 
700 private:
701  //!this is a not implemented copy constructor that avoids automatic creation of one
703 };
704 
705 #if defined(WXART2D_USINGDLL)
706 template class A2DCANVASDLLEXP a2dSmrtPtr<a2dPolygonLClipper2>;
707 #endif
708 
709 
710 //! handle holds a pointer to a polygon/polyline segment
711 /*! this class is used for editing, to quickly update handles from vertexes.
712 */
713 class A2DCANVASDLLEXP a2dPolyHandleL: public a2dHandle
714 {
715 public:
716 
717  DECLARE_DYNAMIC_CLASS( a2dPolyHandleL )
718 
719 public:
720  //! constructor
721  a2dPolyHandleL();
722 
723  //! construct for use in a2dVertexList
724  /*!
725  node based
726 
727  \param parent polygon that contains this handle
728  \param segNode pointer to the node of the segment for which this handle is generated.
729  \param segNodeOrg pointer to the node in original of the segment for which this handle is generated.
730  \param lsegments list of segments where segNode points to
731  \param lsegments list of segments where segNodeOrg points to
732  \param name name of handle
733  */
734  a2dPolyHandleL( a2dPolygonL* parent,
735  a2dVertexList::iterator segNode,
736  a2dVertexList::iterator segNodeOrg,
737  a2dSmrtPtr<a2dVertexList> lsegments,
738  a2dSmrtPtr<a2dVertexList> lsegmentsOrg,
739  const wxString& name = wxT( "" ) );
740 
741  //! construct for use in a2dVertexList
742  /*!
743  node based
744 
745  \param parent polygon that contains this handle
746  \param segNode pointer to the node of the segment for which this handle is generated.
747  \param segNodeOrg pointer to the node in original of the segment for which this handle is generated.
748  \param lsegments list of segments where segNode points to
749  \param lsegments list of segments where segNodeOrg points to
750  \param xc center x
751  \param yc center y
752  \param name name of handle
753  */
754  a2dPolyHandleL( a2dPolygonL* parent,
755  a2dVertexList::iterator segNode,
756  a2dVertexList::iterator segNodeOrg,
757  a2dSmrtPtr<a2dVertexList> lsegments,
758  a2dSmrtPtr<a2dVertexList> lsegmentsOrg,
759  double xc, double yc, const wxString& name = wxT( "" ) );
760 
761  //! copy constructor
762  a2dPolyHandleL( const a2dPolyHandleL& other, CloneOptions options, a2dRefMap* refs );
763 
764  //! destructor
765  ~a2dPolyHandleL();
766 
767  a2dVertexList::iterator GetNode() { return m_segNode; }
768 
769  void SetNode( const a2dVertexList::iterator& iter ) { m_segNode = iter; }
770 
771  a2dVertexList::iterator GetNodeOrg() { return m_segNodeOrg; }
772 
773  void SetNodeOrg( const a2dVertexList::iterator& iter ) { m_segNodeOrg = iter; }
774 
775  //! set handle on segment as arc modifier
776  void SetArcHandle( bool arcHandle ) { m_arcHandle = arcHandle; }
777  //! is the handle on segment an arc modifier?
778  bool GetArcHandle() { return m_arcHandle; }
779 
780  //! get to segments chain to which this handle belongs in the original ( not edit copy )
781  a2dVertexList* GetSegments() { return m_lsegments; }
782 
783  //! get to segments chain to which this handle belongs in the original ( not edit copy )
784  a2dVertexList* GetSegmentsOrg() { return m_lsegmentsOrg; }
785 
786  //! if handle is at the position of a pin, it can be set here, to make it easy moving it in sync with the handle.
787  void SetPin( a2dPin* pin ) { m_pin = pin; }
788  //! see SetPin()
789  a2dPin* GetPin() { return m_pin; }
790 
791 public:
792 
793  //! indicates dragging was/is going on
795 
796  static a2dPropertyIdDouble* PROPID_tmpXIH;
797  static a2dPropertyIdDouble* PROPID_tmpYIH;
798  static a2dPropertyIdDouble* PROPID_tmpXIV1;
799  static a2dPropertyIdDouble* PROPID_tmpYIV1;
800  static a2dPropertyIdDouble* PROPID_tmpXIV2;
801  static a2dPropertyIdDouble* PROPID_tmpYIV2;
802 
804 
805 protected:
806  a2dObject* DoClone( CloneOptions options, a2dRefMap* refs ) const;
807 
808 private:
809 
810  //! to the node of the segment for which this handle is used
811  a2dVertexList::iterator m_segNode;
812 
813  //! to the node of the segment for which this handle is used
814  a2dVertexList::iterator m_segNodeOrg;
815 
816  //! handle is for arc segments
817  bool m_arcHandle;
818 
819  //! segments of handle
820  a2dSmrtPtr<a2dVertexList> m_lsegments;
821 
822  //! segments of original of handle
823  a2dSmrtPtr<a2dVertexList> m_lsegmentsOrg;
824 
825  a2dPinPtr m_pin;
826 
827  //!this is a not implemented copy constructor that avoids automatic creation of one
828  a2dPolyHandleL( const a2dPolyHandleL& other );
829 
830 };
831 #if defined(WXART2D_USINGDLL)
832 template class A2DCANVASDLLEXP a2dSmrtPtr<a2dPolyHandleL>;
833 #endif
834 
835 #endif
836 
wxPoint2DDouble a2dPoint2D
this to define if coordinate numbers are integer or doubles
Definition: artglob.h:47
a2dPATH_END_TYPE
defines the way a polyline with a contour width is ended.
Definition: polyver.h:31
virtual void Render(a2dIterC &ic, OVERLAP clipparent)
Render this object to the active a2dDrawingPart.
Definition: canobj.cpp:4712
double GetEndScaleY()
scale begin and end object with this factor in X
Definition: polygon.h:398
virtual bool DoIsHitWorld(a2dIterC &ic, a2dHitEvent &hitEvent)
Does hit test on the object (exclusif child objects)
Definition: canobj.cpp:3713
a2dVertexList * GetSegmentsOrg()
get to segments chain to which this handle belongs in the original ( not edit copy ) ...
Definition: polygon.h:784
a2dHandle is used inside editing versions of a certain objects.
Definition: canpin.h:30
mouse event sent from a2dCanvasObject to itself
Definition: canglob.h:223
a2dConnectTask
flags for searching a connecting a2dpinClass, for the connecting task at hand.
Definition: connectgen.h:40
#define a2dACCUR
accuracy used to have some limit to calculation like hittesting
Definition: artglob.h:41
void SetEndScaleX(double xs)
scale begin and end object with this factor in X
Definition: polygon.h:386
virtual a2dObject * DoClone(CloneOptions options, a2dRefMap *refs) const
Clone this object and return a pointer to the new object.
Definition: canobj.cpp:1426
virtual void InsertSegment(unsigned int index, a2dLineSegmentPtr segin)
insert segment after index given
Definition: polygon.h:81
class to map references to objects stored in XML, in order to make the connection later on...
Definition: gen.h:3462
a2dVertexList * GetSegments()
get to segments chain to which this handle belongs in the original ( not edit copy ) ...
Definition: polygon.h:781
a2dPin is used in a2dCanvasObject to add pins to it.
Definition: canpin.h:233
This is a class/type description for a2dPin&#39;s.
Definition: canpin.h:628
polygon defined with list of points.
Definition: polygon.h:45
Ref Counted base object.
Definition: gen.h:1045
void OnChar(wxKeyEvent &event)
default handler for character events
Definition: canobj.cpp:1900
a2dPATH_END_TYPE m_pathtype
when m_contourwidth != 0 what is the end of the line looking like.
Definition: polygon.h:481
clips all children to a polygon
Definition: polygon.h:676
void SetContourWidth(double width)
set the Contour width of the shape
Definition: polygon.h:564
virtual bool Update(UpdateMode mode)
Update the state of the object according to its current position etc.
Definition: canobj.cpp:5149
void SetSpline(bool on)
set to true, the polygon will be drawn as a spline
Definition: polygon.h:232
Input and output handler for the XmlSer format.
Definition: genxmlpars.h:819
UpdateMode
Various mode flags for Update.
Definition: canobj.h:1091
virtual void SetPending(bool pending)
set this object pending for update
Definition: canobj.cpp:2585
OVERLAP
Result of a a2dBoundingBox intersection or hittest.
Definition: bbox.h:24
The base class for all drawable objects in a a2dCanvasDocument.
bool m_dragging
indicates dragging was/is going on
Definition: polygon.h:794
#define DECLARE_PROPERTIES()
check if class has the given id as a valid id for this object
Definition: gen.h:835
virtual void DoLoad(wxObject *parent, a2dIOHandlerXmlSerIn &parser, a2dXmlSer_flag xmlparts)
load object specific CVG data
Definition: canobj.cpp:5728
a2dCanvasObject is the base class for Canvas Objects.
Definition: canobj.h:371
void SetFillRule(wxPolygonFillMode val)
Set Polygon filling mode wxODDEVEN_RULE or wxWINDING_RULE.
Definition: polygon.h:243
a2dAffineMatrix a2dIDENTITY_MATRIX
global a2dAffineMatrix to set/pass the identity matrix.
Definition: afmatrix.cpp:51
a2dBoundingBox wxNonValidBbox
global non valid boundingbox to use as default argument etc.
Definition: bbox.cpp:23
vertex list of line and arc segments.
Definition: polyver.h:600
handle holds a pointer to a polygon/polyline segment
Definition: polygon.h:713
virtual void DoRender(a2dIterC &ic, OVERLAP clipparent)
render derived object
Definition: canobj.cpp:4695
virtual bool RestrictToObject(a2dIterC &ic, const a2dPoint2D &pointToSnapTo, a2dPoint2D &bestPointSofar, a2dSnapToWhatMask snapToWhat, double thresHoldWorld)
called from an a2dRestrictionEngine, to restrict vertexes, lines, object to this object.
Definition: canobj.cpp:4209
a2dPATH_END_TYPE GetPathType()
get when m_contourwidth != 0 what is the end of the line looks like.
Definition: polygon.h:404
general vertexlist and array and vector path functions and classes.
void SetContourWidth(double width)
set the Contour width of the shape
Definition: polygon.h:237
Io handler to iterate through a a2dDocument.
Definition: gen.h:3911
void SetPathType(a2dPATH_END_TYPE pathtype)
Set when m_contourwidth != 0 what is the end of the line should be.
Definition: polygon.h:401
bool GetArcHandle()
is the handle on segment an arc modifier?
Definition: polygon.h:778
clips all children to a polygon
Definition: polygon.h:617
polyline defined with list of points.
Definition: polygon.h:332
double GetContourWidth() const
get the Contour width of the shape
Definition: polygon.h:567
virtual a2dCanvasObjectList * GetAsCanvasVpaths(bool transform=true) const
when implemented the object without its children, is converted to
Definition: canobj.cpp:1505
bounding class for optimizing drawing speed.
a2dVertexListPtr GetSegments()
Get the list of points ( this is not a copy! )
Definition: polygon.h:219
Normal straight line segment in a2dVertexList and a2dVertexArray.
Definition: polyver.h:163
void SetEndScaleY(double ys)
scale begin and end object with this factor in Y
Definition: polygon.h:395
virtual void DoSave(wxObject *parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts, a2dObjectList *towrite)
write object specific CVGL data
Definition: canobj.cpp:5569
general event sent from a2dHandle to its parent a2dCanvasObject
Definition: canglob.h:273
Input and output handler for the XmlSer format.
Definition: genxmlpars.h:862
bool GetSpline()
Get the polygon spline setting.
Definition: polygon.h:235
wxUint32 a2dSnapToWhatMask
mask for a2dSnapToWhat flags
Definition: restrict.h:26
virtual a2dCanvasObjectList * GetSnapVpath(a2dSnapToWhatMask snapToWhat)
return a vectorpath indicating on which point/segments the object likes to be snapped.
Definition: canobj.cpp:4308
double GetContourWidth() const
get the Contour width of the shape
Definition: polygon.h:240
A 2x3 affine matrix class for 2D transformations.
Definition: afmatrix.h:53
while iterating a a2dCanvasDocument, this holds the context.
Definition: canobj.h:3212
static bool GetDefaultGeneratePins()
new object willl generate pins or not based on this value
Definition: polygon.h:456
struct for how a single object on one layer was hit
Definition: polyver.h:38
polygon defined with list of points for outer contour plus a list of hole polygons ...
Definition: polygon.h:502
a2dVertexListPtr GetSegments()
Get the list of points ( this is not a copy! )
Definition: polygon.h:546
virtual a2dVertexList * GetAsVertexList(bool &returnIsPolygon) const
convert to a polygon.
Definition: canobj.h:2491
virtual bool DoCanConnectWith(a2dIterC &ic, a2dPin *pin, double margin, bool autocreate)
prepare an object for being connected to a given pin
Definition: canobj.cpp:6817
wxPolygonFillMode GetFillRule()
Get Polygon filling mode wxODDEVEN_RULE or wxWINDING_RULE.
Definition: polygon.h:246
a2dAffineMatrix m_ClipLworld
clipping matrix.
Definition: polygon.h:658
void SetPin(a2dPin *pin)
if handle is at the position of a pin, it can be set here, to make it easy moving it in sync with the...
Definition: polygon.h:787
size_t GetNumberOfSegments()
get the number of points in the pointlist
Definition: polygon.h:556
virtual bool EliminateMatrix()
reduce matrix to identity
Definition: canobj.cpp:6191
a2dPin * GetPin()
see SetPin()
Definition: polygon.h:789
double GetEndScaleX()
scale begin and end object with this factor in X
Definition: polygon.h:389
The a2dBoundingBox class stores one a2dBoundingBox of a a2dCanvasObject.
Definition: bbox.h:39
virtual a2dBoundingBox DoGetUnTransformedBbox(a2dBboxFlags flags=a2dCANOBJ_BBOX_NON) const
In derived object this should be overriden to calculate the boundingbox of the object without its chi...
Definition: canobj.cpp:5031
affine matrix class
virtual bool DoUpdate(UpdateMode mode, const a2dBoundingBox &childbox, const a2dBoundingBox &clipbox, const a2dBoundingBox &propbox)
Update derived Object specific things ( mainly boundingbox)
Definition: canobj.cpp:5098
size_t GetNumberOfSegments()
get the number of points in the pointlist
Definition: polygon.h:229
virtual a2dCanvasObjectList * GetAsPolygons(bool transform=true) const
convert to a list of polygons.
Definition: canobj.cpp:1510
This template class is for property ids with a known data type.
Definition: id.h:477
virtual a2dCanvasObjectList * GetAsPolylines(bool transform=true) const
convert to a list of polylines.
Definition: canobj.cpp:1545
list of a2dObject&#39;s
Definition: gen.h:3157
CloneOptions
options for cloning
Definition: gen.h:1200
structure to give as parameter to member functions of a2dCanvasObject
Definition: canobj.h:252
virtual void DoWalker(wxObject *parent, a2dWalkerIOHandler &handler)
iterate over this object and its children
Definition: canobj.cpp:5504
void SetArcHandle(bool arcHandle)
set handle on segment as arc modifier
Definition: polygon.h:776
wxEditStyle
Definition: canobj.h:109
polygon.h Source File -- Sun Oct 12 2014 17:04:23 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation