wxArt2D
styleprop.cpp
Go to the documentation of this file.
1 /*! \file canvas/src/styleprop.cpp
2  \author Klaas Holwerda
3 
4  Copyright: 2000-2004 (c) Klaas Holwerda
5 
6  Licence: wxWidgets Licence
7 
8  RCS-ID: $Id: styleprop.cpp,v 1.33 2009/07/24 16:35:01 titato Exp $
9 */
10 
11 #include "a2dprec.h"
12 
13 #ifndef WX_PRECOMP
14 #include "wx/wx.h"
15 #endif
16 
17 
18 #include "wx/canvas/canglob.h"
19 #include "wx/canvas/styleprop.h"
20 #include "wx/canvas/canobj.h"
21 
22 #define newline wxString("\n")
23 
24 IMPLEMENT_DYNAMIC_CLASS( a2dFillProperty, a2dNamedProperty )
25 IMPLEMENT_DYNAMIC_CLASS( a2dStrokeProperty, a2dNamedProperty )
26 IMPLEMENT_DYNAMIC_CLASS( a2dFontProperty, a2dNamedProperty )
27 
28 //----------------------------------------------------------------------------
29 // a2dFillProperty
30 //----------------------------------------------------------------------------
31 
33 {
34 }
35 
36 a2dFillProperty::a2dFillProperty( const a2dPropertyIdFill* id, const a2dFill& value )
37  : a2dNamedProperty( id )
38 {
39  m_value = value;
40 }
41 
42 a2dFillProperty::~a2dFillProperty()
43 {
44 }
45 
46 a2dFillProperty::a2dFillProperty( const a2dFillProperty* ori )
47  : a2dNamedProperty( *ori )
48 {
49  m_value = ori->m_value;
50 }
51 
52 a2dFillProperty::a2dFillProperty( const a2dFillProperty& other )
53  : a2dNamedProperty( other )
54 {
55  m_value = other.m_value;
56 }
57 
58 a2dNamedProperty* a2dFillProperty::Clone( a2dObject::CloneOptions WXUNUSED( options ) ) const
59 {
60  return new a2dFillProperty( *this );
61 };
62 
64 {
65  a2dFillProperty* propcast = wxStaticCast( &other, a2dFillProperty );
66  m_value = propcast->m_value;
67 }
68 
69 a2dFillProperty* a2dFillProperty::CreatePropertyFromString( const a2dPropertyIdFill* id, const wxString& WXUNUSED( value ) )
70 {
71  return 0;
72 }
73 
74 #if wxART2D_USE_CVGIO
75 void a2dFillProperty::DoSave( wxObject* parent, a2dIOHandlerXmlSerOut& out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite )
76 {
77  a2dNamedProperty::DoSave( parent, out, xmlparts, towrite );
78  if ( xmlparts == a2dXmlSer_attrib )
79  {
80  }
81  else
82  {
83  m_value.Save( parent, out, towrite );
84  }
85 }
86 
87 void a2dFillProperty::DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts )
88 {
89  a2dNamedProperty::DoLoad( parent, parser, xmlparts );
90  if ( xmlparts == a2dXmlSer_attrib )
91  {
92  }
93  else
94  {
95  m_value.Load( parent, parser );
96  }
97 }
98 #endif //wxART2D_USE_CVGIO
99 
100 void a2dFillProperty::SetValue( const a2dFill& value )
101 {
102  m_value = value;
103 }
104 
106 {
107  return wxT( "VOID" );
108 }
109 
111 {
112  return wxT( "VOID" );
113 }
114 
115 //----------------------------------------------------------------------------
116 // a2dStrokeProperty
117 //----------------------------------------------------------------------------
118 
119 a2dStrokeProperty::a2dStrokeProperty(): a2dNamedProperty()
120 {
121 }
122 
123 a2dStrokeProperty::a2dStrokeProperty( const a2dPropertyIdStroke* id, const a2dStroke& value )
124  : a2dNamedProperty( id )
125 {
126  m_value = value;
127 }
128 
129 a2dStrokeProperty::~a2dStrokeProperty()
130 {
131 }
132 
133 a2dStrokeProperty::a2dStrokeProperty( const a2dStrokeProperty* ori )
134  : a2dNamedProperty( *ori )
135 {
136  m_value = ori->m_value;
137 }
138 
139 a2dStrokeProperty::a2dStrokeProperty( const a2dStrokeProperty& other )
140  : a2dNamedProperty( other )
141 {
142  m_value = other.m_value;
143 }
144 
145 a2dNamedProperty* a2dStrokeProperty::Clone( a2dObject::CloneOptions WXUNUSED( options ) ) const
146 {
147  return new a2dStrokeProperty( *this );
148 };
149 
151 {
152  a2dStrokeProperty* propcast = wxStaticCast( &other, a2dStrokeProperty );
153  m_value = propcast->m_value;
154 }
155 
157 {
158  return 0;
159 }
160 
161 #if wxART2D_USE_CVGIO
162 void a2dStrokeProperty::DoSave( wxObject* parent, a2dIOHandlerXmlSerOut& out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite )
163 {
164  a2dNamedProperty::DoSave( parent, out, xmlparts, towrite );
165  if ( xmlparts == a2dXmlSer_attrib )
166  {
167  }
168  else
169  {
170  m_value.Save( parent, out, towrite );
171  }
172 }
173 
174 void a2dStrokeProperty::DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts )
175 {
176  a2dNamedProperty::DoLoad( parent, parser, xmlparts );
177  if ( xmlparts == a2dXmlSer_attrib )
178  {
179  }
180  else
181  {
182  m_value.Load( parent, parser );
183  }
184 }
185 #endif //wxART2D_USE_CVGIO
186 
187 void a2dStrokeProperty::SetValue( const a2dStroke& value )
188 {
189  m_value = value;
190 }
191 
193 {
194  return wxT( "VOID" );
195 }
196 
198 {
199  return wxT( "VOID" );
200 }
201 
202 //----------------------------------------------------------------------------
203 // a2dFontProperty
204 //----------------------------------------------------------------------------
205 
206 a2dFontProperty::a2dFontProperty(): a2dNamedProperty()
207 {
208 }
209 
210 a2dFontProperty::a2dFontProperty( const a2dPropertyIdFont* id, const a2dFont& value )
211  : a2dNamedProperty( id )
212 {
213  m_value = value;
214 }
215 
216 a2dFontProperty::a2dFontProperty( const a2dFontProperty* ori )
217  : a2dNamedProperty( *ori )
218 {
219  m_value = ori->m_value;
220 }
221 
222 a2dFontProperty::~a2dFontProperty()
223 {
224 }
225 
226 a2dFontProperty::a2dFontProperty( const a2dFontProperty& other )
227  : a2dNamedProperty( other )
228 {
229  m_value = other.m_value;
230 }
231 
232 a2dNamedProperty* a2dFontProperty::Clone( a2dObject::CloneOptions WXUNUSED( options ) ) const
233 {
234  return new a2dFontProperty( *this );
235 };
236 
238 {
239  a2dFontProperty* propcast = wxStaticCast( &other, a2dFontProperty );
240  m_value = propcast->m_value;
241 }
242 
243 a2dFontProperty* a2dFontProperty::CreatePropertyFromString( const a2dPropertyIdFont* id, const wxString& WXUNUSED( value ) )
244 {
245  return 0;
246 }
247 
248 #if wxART2D_USE_CVGIO
249 void a2dFontProperty::DoSave( wxObject* parent, a2dIOHandlerXmlSerOut& out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite )
250 {
251  a2dNamedProperty::DoSave( parent, out, xmlparts, towrite );
252  if ( xmlparts == a2dXmlSer_attrib )
253  {
254  }
255  else
256  {
257  //m_value.Save( parent, out, towrite );
258  }
259 }
260 
261 void a2dFontProperty::DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts )
262 {
263  a2dNamedProperty::DoLoad( parent, parser, xmlparts );
264  if ( xmlparts == a2dXmlSer_attrib )
265  {
266  }
267  else
268  {
269  //m_value.Load( parent, parser );
270  }
271 }
272 #endif //wxART2D_USE_CVGIO
273 
274 void a2dFontProperty::SetValue( const a2dFont& value )
275 {
276  m_value = value;
277 }
278 
280 {
281  return wxT( "VOID" );
282 }
283 
285 {
286  return wxT( "VOID" );
287 }
288 
289 
290 
291 //IMPLEMENT_DYNAMIC_CLASS(a2dCanvasObjectStroke, a2dOneColourStroke)
292 
293 
294 /**************************************************
295 a2dCanvasObjectStroke
296 **************************************************/
297 /*
298 a2dCanvasObjectStroke::a2dCanvasObjectStroke(): a2dOneColourStroke()
299 {
300  m_distance = 0;
301  m_style = a2dSTROKE_OBJECTS;
302  SetStyle( m_style );
303  m_obj = 0;
304 }
305 
306 a2dCanvasObjectStroke::a2dCanvasObjectStroke( a2dCanvasObject* object ): a2dOneColourStroke()
307 {
308  m_distance = 0;
309  m_style = a2dSTROKE_OBJECTS;
310  SetStyle( m_style );
311  wxASSERT_MSG( object != 0 , wxT("a2dCanvasObject for a2dCanvasObjectStroke may not be Null") );
312  m_obj = object;
313 }
314 
315 a2dCanvasObjectStroke::a2dCanvasObjectStroke( a2dCanvasObject* object, const wxColour& col, float width, a2dStrokeStyle style )
316  :a2dOneColourStroke( col, width, style )
317 {
318  m_distance = 0;
319  m_style = a2dSTROKE_OBJECTS;
320  SetStyle( m_style );
321  wxASSERT_MSG( object != 0 , wxT("a2dCanvasObject for a2dCanvasObjectStroke may not be Null") );
322  m_obj = object;
323 }
324 
325 a2dCanvasObjectStroke::a2dCanvasObjectStroke( a2dCanvasObject* object, const wxColour& col, int width, a2dStrokeStyle style)
326  :a2dOneColourStroke( col, width, style )
327 {
328  m_distance = 0;
329  m_style = a2dSTROKE_OBJECTS;
330  SetStyle( m_style );
331  wxASSERT_MSG( object != 0 , wxT("a2dCanvasObject for a2dCanvasObjectStroke may not be Null") );
332  m_obj = object;
333 }
334 
335 a2dCanvasObjectStroke::a2dCanvasObjectStroke( a2dCanvasObject* object, const wxPen& stroke )
336  :a2dOneColourStroke( stroke )
337 {
338  m_distance = 0;
339  m_style = a2dSTROKE_OBJECTS;
340  SetStyle( m_style );
341  wxASSERT_MSG( object != 0 , wxT("a2dCanvasObject for a2dCanvasObjectStroke may not be Null") );
342  m_obj = object;
343 }
344 
345 
346 a2dCanvasObjectStroke::~a2dCanvasObjectStroke()
347 {
348 }
349 
350 a2dObject* a2dCanvasObjectStroke::Clone( CloneOptions WXUNUSED(options) ) const
351 {
352  return new a2dCanvasObjectStroke( *this );
353 }
354 
355 a2dCanvasObjectStroke::a2dCanvasObjectStroke( const a2dCanvasObjectStroke& stroke ): a2dOneColourStroke( stroke )
356 {
357  m_distance = stroke.m_distance;
358  m_obj = stroke.m_obj;
359  m_style = a2dSTROKE_OBJECTS;
360  SetStyle( m_style );
361 }
362 
363 #if wxART2D_USE_CVGIO
364 void a2dCanvasObjectStroke::DoSave( wxObject* parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite )
365 {
366  a2dStroke::DoSave( parent, out, xmlparts, towrite );
367  if ( xmlparts == a2dXmlSer_attrib )
368  {
369  if ( this == a2dINHERIT_STROKE )
370  {
371  out.WriteAttribute( wxT("style"), wxT("inherit") );
372  }
373  else
374  {
375  }
376  }
377  else
378  {
379  }
380 }
381 
382 void a2dCanvasObjectStroke::DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts )
383 {
384  a2dStroke::DoLoad( parent, parser, xmlparts );
385  if ( xmlparts == a2dXmlSer_attrib )
386  {
387  }
388  else
389  {
390  }
391 }
392 #endif //wxART2D_USE_CVGIO
393 
394 void a2dCanvasObjectStroke::Render( a2dIterC& ic, a2dDrawer2D* drawer, const a2dBoundingBox& WXUNUSED(clipbox), int n, wxPoint points[] )
395 {
396  if ( m_distance == 0 )
397  {
398  int i;
399  double x,y;
400  for (i = 0; i < n; i++)
401  {
402  x = drawer->DeviceToWorldX( points[i].x );
403  y = drawer->DeviceToWorldY( points[i].y );
404  a2dAffineMatrix relative;
405  relative.Translate( x, y );
406 
407  a2dIterCU cu( ic, relative );
408 
409  m_obj->Render( ic, _ON );
410  }
411  }
412  else
413  { //at every distance further around the contour place the object
414  int i;
415  double x,y;
416  double prevx,prevy;
417  double done = 0;
418 
419  prevx = drawer->DeviceToWorldX( points[0].x );
420  prevy = drawer->DeviceToWorldY( points[0].y );
421 
422  for (i = 0; i < n-1; i++)
423  {
424 
425  x = drawer->DeviceToWorldX( points[i+1].x );
426  y = drawer->DeviceToWorldY( points[i+1].y );
427 
428  double dx =(x-prevx);
429  double dy =(y-prevy);
430 
431  double lseg = sqrt( dx*dx + dy*dy );
432 
433  while ( done <= lseg && lseg)
434  {
435  x = prevx + done/lseg * dx ;
436  y = prevy + done/lseg * dy ;
437  a2dAffineMatrix relative;
438  relative.Translate( x, y );
439  a2dIterC ic( ic.GetCanvasView() );
440  a2dIterCU cu( ic, relative );
441 
442  m_obj->Render( ic, _ON );
443  done += m_distance;
444  }
445 
446  done = done - lseg;
447  prevx = drawer->DeviceToWorldX( points[i+1].x );
448  prevy = drawer->DeviceToWorldY( points[i+1].y );
449  }
450  }
451 //
452  drawer->DeviceDrawLines(n, points, spline );
453  int i;
454  double x,y;
455  for (i = 0; i < n; i++)
456  {
457  x = drawer->DeviceToWorldX( points[i].x );
458  y = drawer->DeviceToWorldY( points[i].y );
459  drawer->SetDrawerStroke( a2dTRANSPARENT_STROKE );
460  drawer->SetDrawerContour( wxLAYER_CONTOUR );
461  a2dFill* localfill = a2dFill( wxColour(1,233,5 ));
462  drawer->SetDrawerFill( localfill );
463  drawer->DrawCircle( points[i].x, points[i].y, drawer->WorldToDeviceXRel(22) );
464  delete localfill;
465  }
466 //
467 }
468 */
469 /*
470 float a2dCanvasObjectStroke::GetExtend() const
471 {
472  a2dBoundingBox box;
473  box = m_obj->GetBbox();
474 
475  double xdisttozero = wxMax( fabs(box.GetMinX()),fabs(box.GetMaxX()) );
476  double ydisttozero = wxMax( fabs(box.GetMinY()),fabs(box.GetMaxY()) );
477  double max = sqrt ( xdisttozero*xdisttozero + ydisttozero*ydisttozero);
478  return max;
479 }
480 
481 */
482 
483 
484 
485 
virtual wxString StringValueRepresentation() const
Definition: styleprop.cpp:197
(In) Visible property that can be added to Docview Objects.
Definition: gen.h:1785
Base class for all types of strokes, understood by a2dDrawer2D classes.
Definition: stylebase.h:378
virtual wxString StringValueRepresentation() const
Definition: styleprop.cpp:284
virtual wxString StringValueRepresentation() const
Definition: styleprop.cpp:110
Defines a font to be set to a2dDrawer2D or stored in a2dCanvsObject etc.
Definition: stylebase.h:779
Input and output handler for the XmlSer format.
Definition: genxmlpars.h:819
The base class for all drawable objects in a a2dCanvasDocument.
property to hold a a2dFont type variable to be associated with a a2dObject
Definition: styleprop.h:151
static a2dFontProperty * CreatePropertyFromString(const a2dPropertyIdFont *id, const wxString &value)
Definition: styleprop.cpp:243
static a2dStrokeProperty * CreatePropertyFromString(const a2dPropertyIdStroke *id, const wxString &value)
Definition: styleprop.cpp:156
#define wxStaticCast(obj, className)
The wxWindows 2.4.2 wxStaticCast is buggy. It evaluates its argument twice.
Definition: gen.h:123
virtual wxString StringRepresentation() const
Definition: styleprop.cpp:279
virtual wxString StringRepresentation() const
Definition: styleprop.cpp:105
Input and output handler for the XmlSer format.
Definition: genxmlpars.h:862
virtual void Assign(const a2dNamedProperty &other)
Virtual assignment operator.
Definition: styleprop.cpp:63
virtual void Assign(const a2dNamedProperty &other)
Virtual assignment operator.
Definition: styleprop.cpp:150
virtual void Assign(const a2dNamedProperty &other)
Virtual assignment operator.
Definition: styleprop.cpp:237
property to hold a a2dStroke type variable to be associated with a a2dObject
Definition: styleprop.h:98
style properties that are specific to the canvas modules.
This template class is for property ids with a known data type.
Definition: id.h:477
virtual wxString StringRepresentation() const
Definition: styleprop.cpp:192
property to hold a a2dFill type variable to be associated with a a2dObject
Definition: styleprop.h:44
list of a2dObject&#39;s
Definition: gen.h:3157
static a2dFillProperty * CreatePropertyFromString(const a2dPropertyIdFill *id, const wxString &value)
Definition: styleprop.cpp:69
CloneOptions
options for cloning
Definition: gen.h:1200
general canvas module declarations and classes
styleprop.cpp Source File -- Sun Oct 12 2014 17:04:26 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation