wxArt2D
booloper.h
Go to the documentation of this file.
1 /*! \file wx/canvas/booloper.h
2  \brief boolean operation on primitives in a a2dDocument.
3 
4 
5  \author Klaas Holwerda
6 
7  Copyright: 2000-2004 (c) Klaas Holwerda
8 
9  Licence: wxWidgets Licence
10 
11  RCS-ID: $Id: booloper.h,v 1.19 2009/04/30 14:21:44 titato Exp $
12 */
13 
14 #ifndef __WXBOOLOPER_H__
15 #define __WXBOOLOPER_H__
16 
17 #ifndef WX_PRECOMP
18 #include "wx/wx.h"
19 #endif
20 
21 #include "a2dprivate.h"
22 
23 #if wxART2D_USE_KBOOL
24 
25 #include "kbool/booleng.h"
26 #include "wx/artbase/artmod.h"
27 #include "wx/canvas/algos.h"
28 
29 //! walk a document tree and perform boolean opration on primitives.
30 /*!
31  For each object fitting the group and mask, and is at the same child level,
32  can be merged with other objects at that same level.
33  Only if the object can be converted to polygons, this will be the case.
34  For new polygons created this way, the BIN2 flags is set, so one is able to find them.
35  The reuslting polygons are added to the target layer.
36 
37  \ingroup canvasobject
38 */
39 class A2DCANVASDLLEXP a2dBooleanWalkerHandler
41 {
42 public:
43 
44  static const long Boolean_NON; /*!< No operation */
45  static const long Boolean_OR; /*!< boolean OR operation */
46  static const long Boolean_AND; /*!< boolean AND operation */
47  static const long Boolean_EXOR; /*!< boolean EX_OR operation */
48  static const long Boolean_A_SUB_B; /*!< boolean Group A - Group B operation */
49  static const long Boolean_B_SUB_A; /*!< boolean Group B - Group A operation */
50  static const long Boolean_CORRECTION; /*!< polygon correction/offset operation */
51  static const long Boolean_SMOOTHEN; /*!< smooth operation */
52  static const long Boolean_MAKERING; /*!< create a ring on all polygons */
53  static const long Boolean_Polygon2Surface; /*!< convert selected polygon shapes to surfaces */
54  static const long Boolean_Surface2Polygon; /*!< convert selected surfaces shapes to polygons */
55 
57 
59 
60  Bool_Engine* GetBooleanEngine() { return m_booleng; }
61 
62  //!log file will be created when set True
63  void SetLog( bool OnOff ) { m_booleng->SetLog( OnOff ); }
64 
65  //!when set debug information and output will be generated.
66  void SetDebug( bool OnOff ) { m_booleng->SetDebug( OnOff ); }
67 
68  void Initialize();
69 
70  //! clear the target layer before adding result.
71  void SetClearTarget( bool clearTarget ) { m_clearTarget = clearTarget; }
72 
73  void SetMarge( double marge ) { m_booleng->SetMarge( marge ); }
74  void SetGrid( long grid ) { m_booleng->SetGrid( grid ); }
75  void SetDGrid( double dgrid ) { m_booleng->SetDGrid( dgrid ); }
76  void SetCorrectionAber( double aber ) { m_booleng->SetCorrectionAber( aber ); }
77  void SetCorrectionFactor( double aber ) { m_booleng->SetCorrectionFactor( aber ); }
78  void SetMaxlinemerge( double maxline ) { m_booleng->SetMaxlinemerge( maxline ); }
79  void SetWindingRule( bool rule ) { m_booleng->SetWindingRule( rule ); }
80  void SetRoundfactor( double roundfac ) { m_booleng->SetRoundfactor( roundfac ); }
81  void SetSmoothAber( double aber ) { m_booleng->SetSmoothAber( aber ); }
82  //! If set false a2dSurfaces will be produced, meaning holes stored seperately
83  //! If true, the result will be a2dPolygonL objects, with holes linked in to outer contour.
84  //! Only if operation is Boolean_Polygon2Surface, linked holes is ignored, and holes are not linked.
85  void SetLinkHoles( bool doLinkHoles ) { m_booleng->SetLinkHoles( doLinkHoles ); }
86  void SetOrientationEntryMode( bool orientationEntryMode ) { m_booleng->SetOrientationEntryMode( orientationEntryMode ); }
87 
88  //! when an object takes part in operation, and this flag is true, the original is removed.
89  void SetReleaseOrignals( bool releaseOrignals ) { m_releaseOrignals = releaseOrignals; }
90 
91  //! if set, the result will be placed on same layer as the first object in the operation
92  void SetResultOnSameLayer( bool resultOnSameLayer ) { m_resultOnSameLayer = resultOnSameLayer; }
93 
94  //! Set the Result stroke style
95  /*!
96  When set ( non wxNullStroke ), the style will be used for polygons
97  resulting from a boolean operation.
98  */
99  void SetResultStroke( const a2dStroke& resultStroke ) { m_resultStroke = resultStroke; }
100 
101  //! Set the Result fill style
102  /*!
103  When set ( non wxNullFill ), the style will be used for polygons
104  resulting from a boolean operation.
105  */
106  void SetResultFill( const a2dFill& resultFill ) { m_resultFill = resultFill; }
107 
108  //! when set the style of the resulting polygons
109  /*!
110  will be the same as the first child (being part of the operation) found in a parent object.
111  Unless m_resultStroke or m_resultFill or set.
112  */
113  void SetStyleOfFirstChild( bool useStyle ) { m_useFirstChildStyle = useStyle; }
114 
115  //! called for boolean operation
116  /*!
117  All child objects of this parent and below, will be converted to polygons,
118  and next a boolean operation will be applied.
119  */
120  virtual bool Start( a2dCanvasObject* object );
121 
122  //! called from within a2dCanvasDocument
123  bool WalkTask( wxObject* parent, wxObject* object, a2dWalkEvent event );
124 
125 protected:
126 
127  bool CallEngine( a2dCanvasObject* canobjToAddChildren );
128 
129  //! search objects that are convertable to Surface and add them to m_foundA
130  bool GetObjectsForSurface( a2dCanvasObject* booleanobject, GroupType A_or_B );
131 
132  //! search objects that are Surface and add them to m_foundA
133  bool GetObjectsSurface( a2dCanvasObject* booleanobject, GroupType A_or_B );
134 
135  //! vector path split ino polygons, and added to engine
136  bool VectorPathPolygonsToEngine( a2dCanvasObjectList* vpath, GroupType A_or_B );
137 
138  //! convert obj to polygons and add to m_foundA and m_foundB
139  bool ConvertToPolygons( a2dCanvasObject* booleanobject, GroupType A_or_B );
140 
141  //! the boolean engine
142  Bool_Engine* m_booleng;
143 
144  //! \see resultStroke
146 
147  //! \see resultFill
149 
150  //! use first child style or not.
152 
153  //! clear the target layer before adding result.
155 
156  //! when an object takes part in operation, and this flag is true, the original is removed.
158 
159  //! objects found for groupA
161 
162  //! objects found for groupB
164 
165  //! to keep track of levels to do boolean operations
166  wxUint16 m_lastdepth;
167 
168  a2dStroke m_useFirstChildStyleStroke;
169 
170  a2dFill m_useFirstChildStyleFill;
171 
172  wxUint16 m_useFirstChildLayer;
173 
174  bool m_firstLevelChild;
175 
176  bool m_resultOnSameLayer;
177 
178  //DECLARE_CLASS(a2dBooleanWalkerHandler)
179 };
180 
181 #endif //wxART2D_USE_KBOOL
182 
183 #endif
184 
Base class for all types of strokes, understood by a2dDrawer2D classes.
Definition: stylebase.h:378
static const long Boolean_Surface2Polygon
Definition: booloper.h:54
Bool_Engine * m_booleng
the boolean engine
Definition: booloper.h:142
bool m_releaseOrignals
when an object takes part in operation, and this flag is true, the original is removed.
Definition: booloper.h:157
a2dCanvasObjectList m_foundB
objects found for groupB
Definition: booloper.h:163
static const long Boolean_MAKERING
Definition: booloper.h:52
const long a2dWalkEvent
Definition: gen.h:3842
a2dCanvasObjectList m_foundA
objects found for groupA
Definition: booloper.h:160
wxUint16 m_lastdepth
to keep track of levels to do boolean operations
Definition: booloper.h:166
a2dStroke m_resultStroke
Definition: booloper.h:145
a2dCanvasObject is the base class for Canvas Objects.
Definition: canobj.h:371
void SetReleaseOrignals(bool releaseOrignals)
when an object takes part in operation, and this flag is true, the original is removed.
Definition: booloper.h:89
static const long Boolean_NON
Definition: booloper.h:44
wxUint64 a2dCanvasObjectFlagsMask
mask flags for a2dCanvasObject
Definition: candefs.h:152
void SetClearTarget(bool clearTarget)
clear the target layer before adding result.
Definition: booloper.h:71
static const long Boolean_AND
Definition: booloper.h:46
void SetResultStroke(const a2dStroke &resultStroke)
Set the Result stroke style.
Definition: booloper.h:99
a2dWalker based algorithms
void SetLog(bool OnOff)
log file will be created when set True
Definition: booloper.h:63
static const long Boolean_B_SUB_A
Definition: booloper.h:49
static const long Boolean_A_SUB_B
Definition: booloper.h:48
static const long Boolean_CORRECTION
Definition: booloper.h:50
void SetDebug(bool OnOff)
when set debug information and output will be generated.
Definition: booloper.h:66
void SetResultOnSameLayer(bool resultOnSameLayer)
if set, the result will be placed on same layer as the first object in the operation ...
Definition: booloper.h:92
bool Start(a2dCanvasObject *object)
start at this object
Definition: algos.cpp:1249
void SetStyleOfFirstChild(bool useStyle)
when set the style of the resulting polygons
Definition: booloper.h:113
bool m_useFirstChildStyle
use first child style or not.
Definition: booloper.h:151
virtual bool WalkTask(wxObject *parent, wxObject *object, a2dWalkEvent event)
called from within a2dCanvasDocument
Definition: algos.cpp:1311
static const long Boolean_OR
Definition: booloper.h:45
void SetResultFill(const a2dFill &resultFill)
Set the Result fill style.
Definition: booloper.h:106
all headers of the artbase module in one.
void SetLinkHoles(bool doLinkHoles)
Definition: booloper.h:85
walk a document tree and perform boolean opration on primitives.
Definition: booloper.h:39
algorithm to delete a2dCanvasObjects on layers or to move, copy to other layers
Definition: algos.h:911
a2dCanvasObjectList * ConvertToPolygons(a2dCanvasObject *canvasobject, bool transform)
Definition: algos.cpp:484
static const a2dCanvasObjectFlagsMask ALL
Definition: candefs.h:220
void Initialize()
used from constructor
Definition: algos.cpp:1300
bool m_clearTarget
clear the target layer before adding result.
Definition: booloper.h:154
static const long Boolean_Polygon2Surface
Definition: booloper.h:53
static const long Boolean_EXOR
Definition: booloper.h:47
static const long Boolean_SMOOTHEN
Definition: booloper.h:51
booloper.h Source File -- Sun Oct 12 2014 17:04:12 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation