00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef __WXPOLYGON_H__
00016 #define __WXPOLYGON_H__
00017
00018 #ifndef WX_PRECOMP
00019 #include "wx/wx.h"
00020 #endif
00021
00022 #include "wx/artbase/afmatrix.h"
00023 #include "wx/geometry.h"
00024 #include "wx/artbase/bbox.h"
00025 #include "wx/artbase/polyver.h"
00026
00027 #include "wx/canvas/canobj.h"
00028 #include "wx/canvas/canprim.h"
00029
00030
00031 class A2DCANVASDLLEXP a2dPolyHandleL;
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 class A2DCANVASDLLEXP a2dPolygonL: public a2dCanvasObject
00048 {
00049 A2D_DECLARE_EVENT_TABLE()
00050
00051 public:
00052
00053 a2dPolygonL();
00054 a2dPolygonL( a2dVertexListPtr points, bool spline = false );
00055 a2dPolygonL( const a2dPolygonL& poly, CloneOptions options );
00056 ~a2dPolygonL();
00057
00058 virtual a2dObject* Clone( CloneOptions options ) const;
00059
00060 a2dCanvasObjectList* GetAsCanvasVpaths( bool transform = true );
00061
00062 virtual a2dCanvasObjectList* GetAsLinesArcs( bool transform = true );
00063
00064 bool RestrictToObject( a2dRestrictionEngine* engine, a2dSnapToWhatMask snapToWhat );
00065
00066 void AddPoint( double x, double y, a2dLineSegmentPtr seg = NULL, bool afterinversion = true );
00067 void AddPoint(const a2dPoint2D& P, int index, bool afterinversion = true );
00068 void AddPoint( double x, double y, int index, bool afterinversion = true );
00069 virtual void InsertSegment( unsigned int index, a2dLineSegmentPtr segin ) { m_lsegments->Insert( index, segin ); }
00070
00071
00072
00073
00074
00075
00076 void RemoveRedundantPoints( a2dCanvasObject *sendCommandsTo = NULL);
00077
00078
00079
00080
00081
00082
00083
00084
00085 virtual void RemoveSegment( double& x, double& y , a2dLineSegmentPtr seg = NULL, bool transformed = true );
00086
00087
00088
00089
00090
00091
00092
00093
00094 void RemoveSegment( double& x, double& y , int index = -1, bool transformed = true );
00095
00096
00097 void Clear();
00098
00099
00100 bool EliminateMatrix();
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 void SetPosXYSegment(int index, double x, double y, bool afterinversion = true );
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 virtual void SetPosXYSegment( a2dLineSegmentPtr seg, double x, double y, bool afterinversion = true );
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 void SetPosXYMidSegment( a2dLineSegmentPtr seg, double x, double y, bool afterinversion = true );
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 void SetPosXYMidSegment( int index, double x, double y, bool afterinversion = true );
00158
00159
00160
00161
00162
00163
00164
00165
00166 void GetPosXYSegment(int index, double& x, double& y, bool transform = true ) const;
00167
00168
00169
00170
00171
00172
00173
00174
00175 virtual void GetPosXYSegment( a2dLineSegmentPtr seg, double& x, double& y, bool transform = true ) const;
00176
00177
00178
00179
00180
00181
00182
00183
00184 void GetPosXYMidSegment(int index, double& x, double& y, bool transform = true ) const;
00185
00186
00187
00188
00189
00190
00191
00192
00193 void GetPosXYMidSegment( a2dLineSegmentPtr seg, double& x, double& y, bool transform = true ) const;
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204 virtual bool AdjustAfterChange( bool final );
00205
00206
00207 a2dVertexListPtr GetSegments() { return m_lsegments; }
00208
00209
00210
00211
00212
00213
00214 void SetSegments( a2dVertexList* points );
00215
00216
00217 size_t GetNumberOfSegments() { return m_lsegments->size(); }
00218
00219
00220 void SetSpline(bool on) { m_spline=on; SetPending(true); }
00221
00222
00223 bool GetSpline() { return m_spline; }
00224
00225 void SetContourWidth(double width) { m_contourwidth = width; SetPending(true); }
00226
00227
00228 double GetContourWidth() const { return m_contourwidth; }
00229
00230
00231 void SetFillRule( wxPolygonFillMode val ) { m_oddeven = val; }
00232
00233
00234 wxPolygonFillMode GetFillRule() { return m_oddeven; }
00235
00236
00237 virtual void SetHandleToIndex( a2dPolyHandleL* handle, unsigned int index );
00238
00239 virtual int GetIndexSegment( a2dLineSegmentPtr seg );
00240
00241 virtual a2dVertexList::iterator GetSegmentAtIndex( unsigned int index );
00242
00243 virtual a2dVertexList* GetSegmentListAtIndex( unsigned int index );
00244
00245 #if wxART2D_USE_CVGIO
00246 void DoSave( wxObject* parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite );
00247
00248 void DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts );
00249 #endif //wxART2D_USE_CVGIO
00250
00251 a2dHit PointInPolygon(const a2dPoint2D& P, double marge);
00252
00253 DECLARE_CLASS(a2dPolygonL)
00254
00255 protected:
00256
00257 void SyncHandlesWithLineSegments();
00258
00259 virtual bool DoStartEdit( wxUint16 editmode, wxEditStyle editstyle );
00260
00261 void OnCanvasObjectMouseEvent( a2dCanvasObjectMouseEvent& event );
00262
00263 void OnChar(wxKeyEvent& event);
00264
00265 void OnHandleEvent(a2dHandleMouseEvent &event);
00266
00267 void DoRender( a2dIterC& ic, OVERLAP clipparent );
00268
00269 bool DoIsHitWorld( a2dIterC& ic, a2dHitEvent& hitEvent );
00270 a2dBoundingBox DoGetUnTransformedBbox( a2dBboxFlags flags = a2dCANOBJ_BBOX_NON ) const;
00271 bool DoUpdate( UpdateMode mode, const a2dBoundingBox& childbox, const a2dBoundingBox& clipbox, const a2dBoundingBox& propbox );
00272
00273 a2dSmrtPtr<a2dVertexList> m_lsegments;
00274
00275 bool m_spline;
00276
00277 wxPolygonFillMode m_oddeven;
00278
00279
00280 double m_contourwidth;
00281
00282 private:
00283
00284 a2dPolygonL( const a2dPolygonL &other );
00285 };
00286
00287 #if defined(WXART2D_USINGDLL)
00288 template class A2DCANVASDLLEXP a2dSmrtPtr<a2dPolygonL>;
00289 #endif
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305 class A2DCANVASDLLEXP a2dPolylineL: public a2dPolygonL
00306 {
00307 public:
00308 a2dPolylineL();
00309 a2dPolylineL( a2dVertexListPtr segments, bool spline = false );
00310 a2dPolylineL( const a2dPolylineL& poly, CloneOptions options );
00311 ~a2dPolylineL();
00312
00313 virtual a2dObject* Clone( CloneOptions options ) const;
00314
00315 a2dPolygonL* GetAsPolygon();
00316
00317 a2dCanvasObjectList* GetAsCanvasVpaths( bool transform = true );
00318
00319 virtual a2dCanvasObjectList* GetAsLinesArcs( bool transform = true );
00320
00321 #if wxART2D_USE_CVGIO
00322 void DoSave( wxObject* parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite );
00323
00324 void DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts );
00325 #endif //wxART2D_USE_CVGIO
00326
00327 virtual void DoWalker( wxObject* parent, a2dWalkerIOHandler& handler );
00328
00329 a2dHit PointOnPolyline(const a2dPoint2D& P, double marge);
00330
00331
00332 void SetBegin(a2dCanvasObject* begin);
00333
00334 a2dCanvasObject* GetBegin() { return m_begin; }
00335
00336
00337 void SetEnd(a2dCanvasObject* end);
00338
00339 a2dCanvasObject* GetEnd() { return m_end; }
00340
00341
00342
00343
00344
00345 void SetEndScaleX(double xs){ m_xscale=xs; SetPending(true); }
00346
00347
00348 double GetEndScaleX(){ return m_xscale; }
00349
00350
00351
00352
00353
00354 void SetEndScaleY(double ys){ m_yscale=ys; SetPending(true); }
00355
00356
00357 double GetEndScaleY(){ return m_yscale; }
00358
00359
00360 void SetPathType( a2dPATH_END_TYPE pathtype ) { m_pathtype = pathtype; SetPending(true); }
00361
00362
00363 a2dPATH_END_TYPE GetPathType() { return m_pathtype; }
00364
00365 DECLARE_DYNAMIC_CLASS(a2dPolylineL)
00366
00367
00368
00369
00370
00371
00372
00373
00374 bool FindNearPoint( const a2dAffineMatrix *cworld, double xIn, double yIn, double *xOut, double *yOut );
00375
00376
00377
00378
00379
00380
00381
00382
00383 bool FindNearPointOrtho( const a2dAffineMatrix *cworld, double xIn, double yIn, double *xOut, double *yOut );
00384
00385
00386
00387 bool MoveDynamicPinCloseTo( a2dPin *pin, const a2dPoint2D &point, bool final );
00388
00389
00390
00391 virtual bool GeneratePins( a2dPinClass* toConnectTo, a2dConnectTask task, double x, double y );
00392
00393
00394 a2dPin *FindBeginPin();
00395
00396 a2dPin *FindEndPin();
00397
00398 a2dPin *FindPin( int *i );
00399
00400 protected:
00401
00402 bool DoCanConnectWith( a2dIterC &ic, a2dPin* pin, double margin, bool autocreate );
00403
00404 void DoRender( a2dIterC& ic, OVERLAP clipparent );
00405
00406 bool DoIsHitWorld( a2dIterC& ic, a2dHitEvent& hitEvent );
00407 a2dBoundingBox DoGetUnTransformedBbox( a2dBboxFlags flags = a2dCANOBJ_BBOX_NON ) const;
00408 bool DoUpdate( UpdateMode mode, const a2dBoundingBox& childbox, const a2dBoundingBox& clipbox, const a2dBoundingBox& propbox );
00409
00410 a2dCanvasObjectPtr m_begin;
00411 a2dCanvasObjectPtr m_end;
00412
00413 double m_xscale;
00414 double m_yscale;
00415
00416
00417 a2dPATH_END_TYPE m_pathtype;
00418
00419 private:
00420
00421 a2dPolylineL( const a2dPolylineL &other );
00422 };
00423
00424 #if defined(WXART2D_USINGDLL)
00425 template class A2DCANVASDLLEXP a2dSmrtPtr<a2dPolylineL>;
00426 #endif
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438 class A2DCANVASDLLEXP a2dSurface: public a2dPolygonL
00439 {
00440 A2D_DECLARE_EVENT_TABLE()
00441
00442 public:
00443
00444 a2dSurface();
00445 a2dSurface( a2dVertexListPtr points, bool spline = false );
00446 a2dSurface( const a2dSurface& poly, CloneOptions options );
00447 ~a2dSurface();
00448
00449 virtual a2dObject* Clone( CloneOptions options ) const;
00450
00451 a2dCanvasObjectList* GetAsCanvasVpaths( bool transform = true );
00452
00453 virtual a2dCanvasObjectList* GetAsLinesArcs( bool transform = true );
00454
00455 void AddHole( a2dVertexListPtr holepoints );
00456
00457
00458
00459
00460
00461
00462 void RemoveRedundantPoints( a2dCanvasObject *sendCommandsTo = NULL);
00463
00464
00465 void Clear();
00466
00467
00468 bool EliminateMatrix();
00469
00470
00471 a2dVertexListPtr GetSegments() { return m_lsegments; }
00472
00473
00474
00475
00476
00477
00478 void SetSegments( a2dVertexList* points );
00479
00480
00481 size_t GetNumberOfSegments() { return m_lsegments->size(); }
00482
00483 #if wxART2D_USE_CVGIO
00484 void DoSave( wxObject* parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite );
00485
00486 void DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts );
00487 #endif //wxART2D_USE_CVGIO
00488
00489 void SetContourWidth(double width) {}
00490
00491
00492 double GetContourWidth() const { return 0; }
00493
00494 a2dListOfa2dVertexList& GetHoles() { return m_holes; }
00495
00496 void SetHandleToIndex( a2dPolyHandleL* handle, unsigned int index );
00497
00498 int GetIndexSegment( a2dLineSegmentPtr seg );
00499
00500 virtual a2dVertexList::iterator GetSegmentAtIndex( unsigned int index );
00501
00502 virtual a2dVertexList* GetSegmentListAtIndex( unsigned int index );
00503
00504 void RemoveSegment( double& x, double& y , a2dLineSegmentPtr seg = NULL, bool transformed = true );
00505
00506 void InsertSegment( unsigned int index, a2dLineSegmentPtr segin );
00507
00508 void GetPosXYSegment( a2dLineSegmentPtr seg, double& x, double& y, bool transform = true ) const;
00509
00510 void SetPosXYSegment( a2dLineSegmentPtr seg, double x, double y, bool afterinversion = true );
00511
00512 DECLARE_CLASS(a2dSurface)
00513
00514 protected:
00515
00516 bool DoStartEdit( wxUint16 editmode, wxEditStyle editstyle );
00517
00518 void OnCanvasObjectMouseEvent( a2dCanvasObjectMouseEvent& event );
00519
00520 void OnHandleEvent(a2dHandleMouseEvent &event);
00521
00522 void DoRender( a2dIterC& ic, OVERLAP clipparent );
00523
00524 bool DoIsHitWorld( a2dIterC& ic, a2dHitEvent& hitEvent );
00525 a2dBoundingBox DoGetUnTransformedBbox( a2dBboxFlags flags = a2dCANOBJ_BBOX_NON ) const;
00526 bool DoUpdate( UpdateMode mode, const a2dBoundingBox& childbox, const a2dBoundingBox& clipbox, const a2dBoundingBox& propbox );
00527
00528 a2dListOfa2dVertexList m_holes;
00529
00530 private:
00531
00532 a2dSurface( const a2dSurface &other );
00533 };
00534
00535
00536
00537
00538
00539
00540
00541 class A2DCANVASDLLEXP a2dPolygonLClipper: public a2dPolygonL
00542 {
00543 public:
00544
00545
00546 a2dPolygonLClipper( a2dBoundingBox& bbox = wxNonValidBbox );
00547
00548
00549 a2dPolygonLClipper( a2dVertexList* points, bool spline = false );
00550
00551
00552 ~a2dPolygonLClipper();
00553
00554
00555 a2dPolygonLClipper( const a2dPolygonLClipper &other, CloneOptions options );
00556
00557
00558 virtual a2dObject* Clone( CloneOptions options ) const;
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568 void SetClippingTransformMatrix(const a2dAffineMatrix& mat = a2dIDENTITY_MATRIX );
00569
00570
00571 void SetClippingFromBox( a2dBoundingBox& bbox = wxNonValidBbox );
00572
00573
00574 void Render( a2dIterC& ic, OVERLAP clipparent );
00575
00576 virtual bool Update( UpdateMode mode );
00577
00578 protected:
00579
00580 void DoRender( a2dIterC& ic, OVERLAP clipparent );
00581
00582
00583 a2dAffineMatrix m_ClipLworld;
00584
00585 DECLARE_DYNAMIC_CLASS(a2dPolygonLClipper)
00586
00587 private:
00588
00589 a2dPolygonLClipper( const a2dPolygonLClipper &other );
00590 };
00591
00592 #if defined(WXART2D_USINGDLL)
00593 template class A2DCANVASDLLEXP a2dSmrtPtr<a2dPolygonLClipper>;
00594 #endif
00595
00596
00597
00598
00599
00600
00601 class A2DCANVASDLLEXP a2dPolygonLClipper2: public a2dPolygonL
00602 {
00603 public:
00604
00605 a2dPolygonLClipper2( a2dBoundingBox& bbox = wxNonValidBbox );
00606
00607 a2dPolygonLClipper2( a2dVertexList* segments, bool spline = false );
00608
00609 ~a2dPolygonLClipper2();
00610
00611 a2dPolygonLClipper2( const a2dPolygonLClipper2 &other, CloneOptions options );
00612
00613 virtual a2dObject* Clone( CloneOptions options ) const;
00614
00615 void Render( a2dIterC& ic, OVERLAP clipparent );
00616
00617 virtual bool Update( UpdateMode mode );
00618
00619 protected:
00620
00621 void DoRender( a2dIterC& ic, OVERLAP clipparent );
00622
00623 DECLARE_DYNAMIC_CLASS(a2dPolygonLClipper2)
00624
00625 private:
00626
00627 a2dPolygonLClipper2( const a2dPolygonLClipper2 &other );
00628 };
00629
00630 #if defined(WXART2D_USINGDLL)
00631 template class A2DCANVASDLLEXP a2dSmrtPtr<a2dPolygonLClipper2>;
00632 #endif
00633
00634
00635
00636
00637
00638 class A2DCANVASDLLEXP a2dPolyHandleL: public a2dHandle
00639 {
00640 public:
00641
00642 DECLARE_DYNAMIC_CLASS(a2dPolyHandleL)
00643
00644 public:
00645
00646 a2dPolyHandleL();
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659 a2dPolyHandleL( a2dPolygonL* parent,
00660 a2dVertexList::iterator segNode,
00661 a2dVertexList::iterator segNodeOrg,
00662 a2dSmrtPtr<a2dVertexList> lsegments,
00663 a2dSmrtPtr<a2dVertexList> lsegmentsOrg,
00664 const wxString& name = wxT("") );
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679 a2dPolyHandleL( a2dPolygonL* parent,
00680 a2dVertexList::iterator segNode,
00681 a2dVertexList::iterator segNodeOrg,
00682 a2dSmrtPtr<a2dVertexList> lsegments,
00683 a2dSmrtPtr<a2dVertexList> lsegmentsOrg,
00684 double xc, double yc, const wxString& name = wxT("") );
00685
00686
00687 a2dPolyHandleL( const a2dPolyHandleL &other, CloneOptions options );
00688
00689
00690 ~a2dPolyHandleL();
00691
00692 a2dVertexList::iterator GetNode() { return m_segNode; }
00693
00694 void SetNode( const a2dVertexList::iterator& iter ) { m_segNode = iter; }
00695
00696 a2dVertexList::iterator GetNodeOrg() { return m_segNodeOrg; }
00697
00698 void SetNodeOrg( const a2dVertexList::iterator& iter ) { m_segNodeOrg = iter; }
00699
00700
00701 void SetArcHandle( bool arcHandle ) { m_arcHandle = arcHandle; }
00702
00703 bool GetArcHandle() { return m_arcHandle; }
00704
00705
00706 a2dVertexList* GetSegments() { return m_lsegments; }
00707
00708
00709 a2dVertexList* GetSegmentsOrg() { return m_lsegmentsOrg; }
00710
00711 public:
00712
00713 static a2dPropertyIdDouble* PROPID_tmpXIH;
00714 static a2dPropertyIdDouble* PROPID_tmpYIH;
00715 static a2dPropertyIdDouble* PROPID_tmpXIV1;
00716 static a2dPropertyIdDouble* PROPID_tmpYIV1;
00717 static a2dPropertyIdDouble* PROPID_tmpXIV2;
00718 static a2dPropertyIdDouble* PROPID_tmpYIV2;
00719
00720 DECLARE_PROPERTIES()
00721
00722 private:
00723
00724
00725 a2dVertexList::iterator m_segNode;
00726
00727
00728 a2dVertexList::iterator m_segNodeOrg;
00729
00730
00731 bool m_arcHandle;
00732
00733
00734 a2dSmrtPtr<a2dVertexList> m_lsegments;
00735
00736
00737 a2dSmrtPtr<a2dVertexList> m_lsegmentsOrg;
00738
00739
00740 a2dPolyHandleL( const a2dPolyHandleL &other );
00741 };
00742 #if defined(WXART2D_USINGDLL)
00743 template class A2DCANVASDLLEXP a2dSmrtPtr<a2dPolyHandleL>;
00744 #endif
00745
00746 #endif
00747