wxArt2D
canext.cpp
Go to the documentation of this file.
1 /*! \file canextobj/src/canext.cpp
2  \author Klaas Holwerda
3 
4  Copyright: 2001-2004 (c) Klaas Holwerda
5 
6  Licence: wxWidgets Licence
7 
8  RCS-ID: $Id: canext.cpp,v 1.65 2009/09/26 20:40:32 titato Exp $
9 */
10 
11 #include "a2dprec.h"
12 
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16 
17 #ifndef WX_PRECOMP
18 #include "wx/wx.h"
19 #endif
20 
21 #include "wx/canextobj/canext.h"
22 #include "wx/canvas/objlist.h"
23 #include "wx/canvas/drawer.h"
24 #include "wx/editor/editmod.h"
25 
26 #include <math.h>
27 
28 //----------------------------------------------------------------------------
29 // globals
30 //----------------------------------------------------------------------------
31 IMPLEMENT_DYNAMIC_CLASS( a2dTextGroup, a2dCanvasObject )
32 IMPLEMENT_DYNAMIC_CLASS( a2dDrawingFrame, a2dPolygonLClipper2 )
33 
34 //----------------------------------------------------------------------------
35 
36 //----------------------------------------------------------------------------
37 // a2dTextGroup
38 //----------------------------------------------------------------------------
39 
41  : a2dCanvasObject()
42 {
43 }
44 
45 a2dTextGroup::a2dTextGroup( double x, double y )
46  : a2dCanvasObject()
47 {
48  m_lworld.Translate( x, y );
49 }
50 
51 a2dTextGroup::~a2dTextGroup()
52 {
53 }
54 
55 a2dObject* a2dTextGroup::DoClone( CloneOptions options, a2dRefMap* refs ) const
56 {
57  return new a2dTextGroup( *this, options, refs );
58 };
59 
60 a2dTextGroup::a2dTextGroup( const a2dTextGroup& other, CloneOptions options, a2dRefMap* refs )
61  : a2dCanvasObject( other, options, refs )
62 {
63 }
64 
65 void a2dTextGroup::RenderChildObjectsOneLayer( a2dIterC& ic, RenderChild& WXUNUSED( whichchilds ), OVERLAP clipparent )
66 {
68  return;
69 
70  //save the current style state of the a2dCanvasView, in order to inherit and restore style of object
71  a2dFill currentdrawer_fill = ic.GetDrawer2D()->GetDrawerFill();
72  a2dStroke currentdrawer_stroke = ic.GetDrawer2D()->GetDrawerStroke();
73 
75  {
76  a2dCanvasObject* obj = *iter;
77 
78  int olayer = obj->GetLayer();
79 
80  if ( olayer == ic.GetLayer() || ic.GetLayer() == wxLAYER_ALL || obj->GetChildObjectList() )
81  {
82 
83  // clipparent is either _IN or _ON ( _OUT would not get us to this point )
84  // testing clipping of children only needed when not totaly _IN.
85 
86  OVERLAP childclip = _IN;
87  if ( clipparent != _IN )
88  childclip = obj->GetClipStatus( ic, clipparent );
89 
90  //line++;
91 
92  if ( childclip != _OUT ) //if a child is _OUT, no need to render it.
93  {
94  obj->Render( ic, childclip );
95  }
96  }
97  }
98 
99  ic.GetDrawer2D()->SetDrawerFill( currentdrawer_fill );
100  ic.GetDrawer2D()->SetDrawerStroke( currentdrawer_stroke );
101 }
102 
103 
104 
105 //----------------------------------------------------------------------------
106 // a2dDrawingFrame
107 //----------------------------------------------------------------------------
108 
109 BEGIN_EVENT_TABLE( a2dDrawingFrame, a2dPolygonLClipper2 )
110  EVT_CANVASOBJECT_MOUSE_EVENT( a2dDrawingFrame::OnCanvasObjectMouseEvent )
111  EVT_CHAR( a2dDrawingFrame::OnChar )
112 END_EVENT_TABLE()
113 
114 void a2dDrawingFrame::DoWalker( wxObject* parent, a2dWalkerIOHandler& handler )
115 {
116  handler.WalkTask( parent, this, a2dWalker_a2dDerivedCanvasObjectStart );
117  a2dPolygonLClipper2::DoWalker( parent, handler );
118  handler.WalkTask( parent, this, a2dWalker_a2dDerivedCanvasObjectEnd );
119 }
120 
121 bool a2dDrawingFrame::DoStartEdit( wxUint16 editmode, wxEditStyle editstyle )
122 {
123  if ( m_flags.m_editable )
124  {
125  PROPID_IncludeChildren->SetPropertyToObject( this, false );
126  PROPID_Allowrotation->SetPropertyToObject( this, false );
127  PROPID_Allowskew->SetPropertyToObject( this, false );
128 
129  return a2dPolygonLClipper2::DoStartEdit( editmode, editstyle );
130  }
131 
132  return false;
133 }
134 
135 
136 /*
137 void a2dDrawingFrame::OnChar(wxKeyEvent& event)
138 {
139  if ( m_flags.m_editingCopy )
140  {
141  switch(event.GetKeyCode())
142  {
143  case 'Z':
144  case 'z':
145  {
146  a2dZoomTool* zoom = new a2dZoomTool(this);
147  PushTool(zoom);
148  }
149  break;
150  case WXK_SPACE:
151  {
152  StopTool();
153  }
154  break;
155  case WXK_ESCAPE:
156  {
157  StopTool();
158  }
159  break;
160  default:
161  event.Skip();
162  }
163  else
164  event.Skip();
165 }
166 */
167 
168 void a2dDrawingFrame::OnCanvasObjectMouseEvent( a2dCanvasObjectMouseEvent& event )
169 {
170  a2dIterC* ic = event.GetIterC();
171 
172  if ( m_flags.m_editingCopy )
173  {
174  //to world group coordinates to do hit test in world group coordinates
175  double xw, yw;
176  xw = event.GetX();
177  yw = event.GetY();
178 
179  a2dAffineMatrix atWorld = ic->GetTransform();
180 
181  if ( event.GetMouseEvent().LeftDown() )
182  {
183  if ( event.GetMouseEvent().m_shiftDown )
184  {
185 
186  a2dDrawingFrame* original = wxStaticCast( PROPID_Original->GetPropertyValue( this ).Get(), a2dDrawingFrame );
187  a2dIterCU cu( *ic, original );
188 
189  a2dStToolContr* controller = wxStaticCast( PROPID_Controller->GetPropertyValue( this ).Get(), a2dStToolContr );
190  ic->SetCorridorPath( true, NULL );
191 
192  /* dependency problem, can not be in editor module, if used here.
193  a2dSubDrawMasterTool* draw = new a2dSubDrawMasterTool( controller );
194  controller->PushTool( draw );
195  */
196  SetPending( true );
197  ic->GetDrawingPart()->SetCursor( a2dCanvasGlobals->GetCursor( a2dCURSOR_CROSS ) );
198  /*
199  a2dDrawRectangleTool* drawrec = new a2dDrawRectangleTool( controller );
200  controller->PushTool( drawrec );
201  drawrec->SetEditAtEnd( true );
202 
203  SetPending( true );
204  ic->GetCanvasView()->SetCursor( a2dCanvasGlobals->GetCursor( a2dCURSOR_CROSS ) );
205  */
206  }
207  else if ( event.GetMouseEvent().m_controlDown )
208  {
209  a2dDrawingFrame* original = wxStaticCast( PROPID_Original->GetPropertyValue( this ).Get(), a2dDrawingFrame );
210  a2dIterCU cu( *ic, original );
211 
212  a2dStToolContr* controller = wxStaticCast( PROPID_Controller->GetPropertyValue( this ).Get(), a2dStToolContr );
213  ic->SetCorridorPath( true, NULL );
214  a2dDrawPolygonLTool* draw = new a2dDrawPolygonLTool( controller );
215  controller->PushTool( draw );
216  draw->SetEditAtEnd( true );
217 
218  SetPending( true );
219  ic->GetDrawingPart()->SetCursor( a2dCanvasGlobals->GetCursor( a2dCURSOR_CROSS ) );
220  }
221  else
222  {
223  a2dHitEvent hitevent = a2dHitEvent( xw, yw, false );
224  if ( IsHitWorld( *ic, hitevent ) )
225  {
226  a2dDrawingFrame* original = wxStaticCast( PROPID_Original->GetPropertyValue( this ).Get(), a2dDrawingFrame );
227  a2dHitEvent hitinfo( xw, yw, false, a2dCANOBJHITOPTION_LAYERS );
228  hitinfo.m_xyRelToChildren = true;
229  a2dCanvasObject* curve = original->ChildIsHitWorld( *ic, hitinfo );
230  if ( curve && curve->GetEditable() )
231  {
232  a2dIterCU cu2( *ic, original );
233  a2dStToolContr* controller = wxStaticCast( PROPID_Controller->GetPropertyValue( this ).Get(), a2dStToolContr );
234 
235  ic->SetCorridorPath( true, NULL );
236  controller->StartEditingObject( curve, *ic );
237 
238  SetPending( true );
239  ic->GetDrawingPart()->SetCursor( a2dCanvasGlobals->GetCursor( a2dCURSOR_CROSS ) );
240  }
241  else
242  event.Skip();
243  }
244  else
245  EndEdit();
246  }
247  }
248  else if ( event.GetMouseEvent().LeftDClick() )
249  {
250  EndEdit();
251  }
252  else if ( event.GetMouseEvent().Moving() )
253  {
254  /*
255  a2dAffineMatrix cworld;
256  a2dHit how;
257  a2dAffineMatrix tworld;
258  tworld *= m_lworld;
259 
260  a2dCanvasObject* curve = m_axesarea->WhichIsHitWorld( &tworld, xw, yw, NULL, how );
261  if ( curve )
262  {
263  event.Skip();
264  }
265  else
266  {
267  event.Skip();
268  }
269  */
270  event.Skip();
271  }
272  else
273  event.Skip();
274  }
275  else
276  event.Skip();
277 }
278 
279 a2dDrawingFrame::a2dDrawingFrame( double x, double y, double width, double height ): a2dPolygonLClipper2()
280 {
281  Clear();
282  AddPoint( 0, 0 );
283  AddPoint( 0 , height );
284  AddPoint( width , height );
285  AddPoint( width , 0 );
286 
287  m_lworld.Translate( x, y );
288 }
289 
291 {
292 }
293 
295  : a2dPolygonLClipper2( other, options, refs )
296 {
297 }
298 
300 {
301  return new a2dDrawingFrame( *this, options, refs );
302 }
303 
305 {
306  a2dPolygonLClipper2::DoRender( ic, clipparent );
307 }
308 
309 bool a2dDrawingFrame::DoIsHitWorld( a2dIterC& WXUNUSED( ic ), a2dHitEvent& hitEvent )
310 {
311  hitEvent.m_how = a2dHit::stock_fill;
312  return true;
313 }
314 
315 #if wxART2D_USE_CVGIO
316 void a2dDrawingFrame::DoSave( wxObject* parent, a2dIOHandlerXmlSerOut& out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite )
317 {
318  a2dPolygonLClipper2::DoSave( parent, out, xmlparts, towrite );
319  if ( xmlparts == a2dXmlSer_attrib )
320  {
321  }
322  else
323  {
324  }
325 }
326 
327 void a2dDrawingFrame::DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts )
328 {
329  a2dPolygonLClipper2::DoLoad( parent, parser, xmlparts );
330  if ( xmlparts == a2dXmlSer_attrib )
331  {
332  }
333  else
334  {
335  }
336 }
337 #endif //wxART2D_USE_CVGIO
338 
a2dHit m_how
return in which way the object was hit (stroke, fill, ...)
Definition: canobj.h:301
virtual void Render(a2dIterC &ic, OVERLAP clipparent)
Render this object to the active a2dDrawingPart.
Definition: canobj.cpp:4712
Base class for all types of strokes, understood by a2dDrawer2D classes.
Definition: stylebase.h:378
virtual a2dObject * DoClone(CloneOptions options, a2dRefMap *refs) const
Clone this object and return a pointer to the new object.
Definition: canext.cpp:299
bool PushTool(a2dBaseTool *tool)
specialize to keep first tool on the stack active
Definition: sttool.cpp:451
bool GetEditable() const
get if the object may be edited
Definition: canobj.h:1584
mouse event sent from a2dCanvasObject to itself
Definition: canglob.h:223
class to map references to objects stored in XML, in order to make the connection later on...
Definition: gen.h:3462
a2dCanvasOFlags m_flags
holds flags for objects
Definition: canobj.h:2528
void DoLoad(wxObject *parent, a2dIOHandlerXmlSerIn &parser, a2dXmlSer_flag xmlparts)
load object specific CVG data
Definition: canext.cpp:327
Ref Counted base object.
Definition: gen.h:1045
clips all children to a polygon
Definition: polygon.h:676
wxUint16 GetLayer()
get the layer that is to be rendered
Definition: canobj.h:3282
virtual ~a2dDrawingFrame()
destructor
Definition: canext.cpp:290
void SetDrawerStroke(const a2dStroke &stroke)
Used to set the current stroke.
Definition: drawer2d.cpp:565
virtual void DoSave(wxObject *parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts, a2dObjectList *towrite)
write object specific CVGL data
Definition: canext.cpp:316
Input and output handler for the XmlSer format.
Definition: genxmlpars.h:819
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
void Clear()
Remove and delete all points in the polygon.
Definition: polygon.cpp:95
OVERLAP GetClipStatus(a2dIterC &ic, OVERLAP clipparent)
used for deciding if the object needs to be rendered against the current clipping area of the active ...
Definition: canobj.cpp:3273
a2dCanvasObject is the base class for Canvas Objects.
Definition: canobj.h:371
To use as a drawing frame within a drawing.
Definition: canext.h:54
A2DGENERALDLLEXP a2dWalkEvent a2dWalker_a2dDerivedCanvasObjectStart
id for a2dWalkEvent issued from within a2dWalkerIOHandler
a2dCanvasObjectList * GetChildObjectList()
get the list where the child objects are stored in.
Definition: canobj.cpp:2551
virtual void EndEdit()
cleanup an editcopy object
Definition: canobj.cpp:1828
virtual bool DoStartEdit(wxUint16 editmode, wxEditStyle editstyle)
only used for editable objects and under control of a editing tool.
Definition: polygon.cpp:869
a2dAffineMatrix m_lworld
used for positioning the object (x,y,ang,scale etc.)
Definition: canobj.h:2559
void SetDrawerFill(const a2dFill &fill)
Used to set the current fill.
Definition: drawer2d.cpp:621
Io handler to iterate through a a2dDocument.
Definition: gen.h:3911
a2dCanvasObjectList * wxNullCanvasObjectList
define a NON a2dCanvasObjectList
Definition: objlist.cpp:53
void SetEditAtEnd(bool editatend)
flag for setting editing tool after drawing a primitive.
Definition: sttool.h:185
a2dCanvasObjectList * m_childobjects
holds child objects
Definition: canobj.h:2562
#define forEachIn(listtype, list)
easy iteration for a2dlist
Definition: a2dlist.h:111
a2dDrawingFrame(double x=0, double y=0, double width=100, double height=100)
construct at given position
Definition: canext.cpp:279
The a2dStToolContr is a Tool Controller specialized for working with a2dCanvasView.
Definition: sttool.h:485
void SetPropertyToObject(a2dObject *obj, const basetype &value, SetFlags setflags=set_none) const
Set the property in obj to value.
Definition: id.inl:238
to render/hold a groups of text objects.
Definition: canext.h:27
Definition: bbox.h:26
a2dDrawer2D * GetDrawer2D() const
get current a2dDrawer2D
Definition: canobj.cpp:636
#define wxStaticCast(obj, className)
The wxWindows 2.4.2 wxStaticCast is buggy. It evaluates its argument twice.
Definition: gen.h:123
bool m_editable
object can be edited
Definition: candefs.h:295
#define EVT_CANVASOBJECT_MOUSE_EVENT(func)
static event table macro for a2dCanvasObject mouse event
Definition: canglob.h:312
void Translate(double x, double y)
relative translate the object to position x,y in world coordinates
Definition: canobj.h:569
wxUint16 GetLayer() const
Returns the layer index where this object is drawn upon.
Definition: canobj.h:2368
Input and output handler for the XmlSer format.
Definition: genxmlpars.h:862
if set, respect layer order, hit testing is done per layer from the top.
Definition: canobj.h:82
void DoRender(a2dIterC &ic, OVERLAP clipparent)
render derived object
Definition: polygon.cpp:3377
bool DoIsHitWorld(a2dIterC &ic, a2dHitEvent &hitEvent)
Does hit test on the object (exclusif child objects)
Definition: canext.cpp:309
a2dCanvasObject * ChildIsHitWorld(a2dIterC &ic, a2dHitEvent &hitEvent, bool filterSelectableLayers=false)
Do hittest on children.
Definition: canobj.cpp:3289
A 2x3 affine matrix class for 2D transformations.
Definition: afmatrix.h:53
wxMouseEvent & GetMouseEvent()
return the original mouse event that was redirected to the a2dCanvasObject
Definition: canglob.h:243
a2dStroke GetDrawerStroke() const
get the current stroke
Definition: drawer2d.h:548
while iterating a a2dCanvasDocument, this holds the context.
Definition: canobj.h:3212
void DoLoad(wxObject *parent, a2dIOHandlerXmlSerIn &parser, a2dXmlSer_flag xmlparts)
load object specific CVG data
Definition: polygon.cpp:1700
a2dLineSegment * AddPoint(double x, double y, a2dLineSegmentPtr seg=NULL, bool afterinversion=true)
add point/segment after a segment.
Definition: polygon.cpp:356
Definition: bbox.h:28
void DoRender(a2dIterC &ic, OVERLAP clipparent)
render derived object
Definition: canext.cpp:304
Interactive drawing of a polygon.
Definition: sttool.h:1715
void DoSave(wxObject *parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts, a2dObjectList *towrite)
write object specific CVGL data
Definition: polygon.cpp:1662
An object of this class will update a a2dIterC with the required information.
Definition: canobj.h:3123
list for a2dCanvasObject
bool Translate(double x, double y)
Translate by dx, dy:
Definition: afmatrix.cpp:420
bool m_editingCopy
true if the object needs to be rendered in edit mode.
Definition: candefs.h:304
a2dFill GetDrawerFill() const
get the current fill
Definition: drawer2d.h:557
a2dCanvasObject * IsHitWorld(a2dIterC &ic, a2dHitEvent &hitEvent)
If the position (x,y) is within the object return this.
Definition: canobj.cpp:3415
static a2dHit stock_fill
Stock object for a fill hit.
Definition: polyver.h:137
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.
basetype GetPropertyValue(const a2dObject *obj) const
Get the property value in obj.
Definition: id.inl:325
A2DGENERALDLLEXP a2dWalkEvent a2dWalker_a2dDerivedCanvasObjectEnd
id for a2dWalkEvent issued from within a2dWalkerIOHandler
a2dCanvasGlobal * a2dCanvasGlobals
global a2dCanvasGlobal to have easy access to global settings
Definition: canglob.cpp:1234
virtual bool StartEditingObject(a2dCanvasObject *objectToEdit)
start editing this object
Definition: sttool.cpp:926
a2dDrawingPart * GetDrawingPart() const
get current a2dDrawingPart
Definition: canobj.cpp:631
all headers in the editor module
const a2dAffineMatrix & GetTransform() const
Get the accumulated transform up to and including m_lworld of the current object. ...
Definition: canobj.cpp:663
list of a2dObject&#39;s
Definition: gen.h:3157
bool DoStartEdit(wxUint16 editmode, wxEditStyle editstyle)
only used for editable objects and under control of a editing tool.
Definition: canext.cpp:121
CloneOptions
options for cloning
Definition: gen.h:1200
void SetCorridorPath(bool OnOff, a2dCanvasObject *captureObject=NULL)
to set corridor path ( also to captured object), its a2dCanvasOFlags::IsOnCorridorPath flag is set on...
Definition: canobj.cpp:739
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
wxEditStyle
Definition: canobj.h:109
canext.cpp Source File -- Sun Oct 12 2014 17:04:13 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation