wxArt2D
objlist.h
Go to the documentation of this file.
1 /*! \file wx/canvas/objlist.h
2  \brief list for a2dCanvasObject
3 
4  Action that can be performed on a list of a2dCanvasObject's go into a2dCanvasObjectList.
5 
6  \author Klaas Holwerda
7 
8  Copyright: 2000-2004 (c) Klaas Holwerda
9 
10  Licence: wxWidgets Licence
11 
12  RCS-ID: $Id: objlist.h,v 1.30 2009/09/26 19:01:02 titato Exp $
13 */
14 
15 #ifndef __WXOBJLIST_H__
16 #define __WXOBJLIST_H__
17 
18 #ifndef WX_PRECOMP
19 #include "wx/wx.h"
20 #endif
21 
22 #include "wx/geometry.h"
23 #include "wx/artbase/afmatrix.h"
24 #include "wx/canvas/candefs.h"
25 #include "wx/canvas/canobj.h"
26 #include "wx/canvas/canprop.h"
27 
28 //----------------------------------------------------------------------------
29 // decls
30 //----------------------------------------------------------------------------
31 
32 //! define a NON a2dCanvasObjectList
33 /*!
34  Even if a a2dCanvasObject has no children, still its Length can be asked for.
35 */
36 A2DCANVASDLLEXP_DATA( extern a2dCanvasObjectList* ) wxNullCanvasObjectList;
37 
38 //initalization
39 #if defined(WXART2D_USINGDLL)
40 template class A2DCANVASDLLEXP std::allocator<class a2dSmrtPtr<class a2dCanvasObject> >;
41 template class A2DCANVASDLLEXP std::allocator< std::_List_nod<class a2dSmrtPtr<class a2dCanvasObject>, std::allocator<class a2dSmrtPtr<class a2dCanvasObject> > >::_Node >;
42 template class A2DCANVASDLLEXP std::allocator< std::_List_ptr<class a2dSmrtPtr<class a2dCanvasObject>, std::allocator<class a2dSmrtPtr<class a2dCanvasObject> > >::_Nodeptr >;
43 template class A2DCANVASDLLEXP std::list<class a2dSmrtPtr<class a2dCanvasObject> >::iterator;
44 template class A2DCANVASDLLEXP std::list<class a2dSmrtPtr<class a2dCanvasObject> >;
45 template class A2DCANVASDLLEXP a2dlist<a2dSmrtPtr<a2dCanvasObject> >;
46 template class A2DCANVASDLLEXP a2dSmrtPtrList<a2dCanvasObject>;
47 #endif
48 
49 #include <wx/listimpl.cpp>
50 
51 //! list of a2dCanvasObject's
52 /*!
53  Action that can be performed on a list of a2dCanvasObject's go into a2dCanvasObjectList.
54 
55  \ingroup canvasobject
56 */
57 
59 
60 class A2DCANVASDLLEXP a2dCanvasObjectList: public a2dSmrtPtrList<a2dCanvasObject>
61 {
62 
63 public:
65 
67 
68  //!this only copies pointer stored in the list.
69  /*!
70  if you want the object itself copied also, use Clone
71  */
72  a2dCanvasObjectList& operator=( const a2dCanvasObjectList& other );
73 
74  //!Clone everything ( Clones objects also) in a new created list
75  a2dCanvasObjectList* Clone( a2dObject::CloneOptions options ) const;
76 
77  //! clone to new list only objects with certain mask
78  /*!
79  \param mask object must have this mask.
80  \param options way to clone
81  \param objectsIndex list with indexes of cloned objects
82  \param bbox only find objects within this box.
83 
84  \return cloned objects list
85  */
86  a2dCanvasObjectList* Clone( a2dCanvasObjectFlagsMask mask = a2dCanvasOFlags::ALL, a2dObject::CloneOptions options = a2dObject::clone_deep, a2dlist< long >* objectsIndex = NULL, const a2dBoundingBox& bbox = wxNonValidBbox ) const;
87 
88  //! clone to new list only objects with check flag set
89  /*!
90  \param options way to clone
91  \param objectsIndex list with indexes of cloned objects
92 
93  \return cloned objects list
94  */
95  a2dCanvasObjectList* CloneChecked( a2dObject::CloneOptions options = a2dObject::clone_deep, a2dlist< long >* objectsIndex = NULL ) const;
96 
97  //! sort in X and is same also Y
98  void SortXY();
99 
100  //! sort in X and is same also in reverse Y
101  void SortXRevY();
102 
103  //! sort in Y and is same also X
104  void SortYX();
105 
106  //! sort in Y and is same also in reverse X
107  void SortYRevX();
108 
109  //! all with reference count > 1 are cloned.
110  void MakeUnique();
111 
112  //!set all given bit flags at once recursive for all objects in given boundingbox
113  bool SetSpecificFlags( bool setOrClear, a2dCanvasObjectFlagsMask which, const wxString& classname = wxT( "" ),
115  const a2dAffineMatrix& tworld = a2dIDENTITY_MATRIX );
116 
117  //!move only in this group objects with the given mask to the layer given
118  bool ChangeLayer( wxUint16 layer, a2dCanvasObjectFlagsMask mask = a2dCanvasOFlags::ALL );
119 
121 
122  //!move only in this group objects with the given mask to the back of the list drawn last
123  /*!
124  \param mask object must have this mask.
125  \param check if true, moved objects will have check flag set
126 
127  \return number of moved objects
128  */
129  int BringToTop( a2dCanvasObjectFlagsMask mask = a2dCanvasOFlags::ALL, bool check = false );
130 
131  //!move only in this group objects with the given mask to the front of the list drawn first
132  /*!
133  \param mask object must have this mask.
134  \param check if true, moved objects will have check flag set
135 
136  \return number of moved objects
137  */
138  int BringToBack( a2dCanvasObjectFlagsMask mask = a2dCanvasOFlags::ALL, bool check = false );
139 
140  //! release only objects with the given mask and classname and has property named propertyname and object name
141  /*!
142  \param mask object must have this mask.
143  \param classname if set, this classname is required
144  \param id is object contains this property, it will be released. If NULL, this parameter is ignored.
145  \param name if set, this name is required for the objects
146  \param now if true remove all references to object right now, else only set its delete flag for delete in update cycle.
147  empty string means ignore.
148  */
149  int Release( a2dCanvasObjectFlagsMask mask = a2dCanvasOFlags::ALL, const wxString& classname = wxT( "" ), const a2dPropertyId* id = NULL, const wxString& name = wxT( "" ), bool now = true );
150 
151  //! release a specific object
152  /*!
153  \param object object to release
154  \param backwards start at the end
155  \param all if true remove all references to object
156  \param now if true remove all references to object right now, else only set its delete flag for delete in update cycle.
157  \param id is object contains this property, it will be released. If NULL, this parameter is ignored.
158 
159  \return number of released objects
160  */
161  int Release( a2dCanvasObject* object, bool backwards = false, bool all = true, bool now = true, const a2dPropertyId* id = NULL );
162 
163  //!copy only in this group object with the same mask
164  /*!
165  \param x copy object at distance x
166  \param y copy object at distance y
167  \param mask object must have this mask.
168  \param target if not -1, objects will be copied to this layer
169  \param check if true, copied objects will have check flag set
170 
171  \return number of copied objects
172  */
173  int Copy( double x, double y, a2dCanvasObjectFlagsMask mask = a2dCanvasOFlags::ALL, long target = -1, bool check = false );
174 
175  //!move only in this group object with the same mask
176  /*!
177  \param x move object distance x
178  \param y move object distance y
179  \param mask object must have this mask.
180  \param target if not -1, objects will be copied to this layer
181  \param check if true, moved objects will have check flag set
182 
183  \return number of moved objects
184  */
185  int Move( double x, double y, a2dCanvasObjectFlagsMask mask = a2dCanvasOFlags::ALL, long target = -1, bool check = false );
186 
187  //!return the object if it is part of the list
188  /*!
189  \param obj object to search for
190  */
191  a2dCanvasObject* Find( a2dCanvasObject* obj ) const;
192 
193  //!return the object which fits the filter.
194  /*!
195  \param objectname object with this name to search for
196  \param classname If classname is empty it collects all objects else only object with this class name.
197  \param mask object must have this mask.
198  \param propid if a property id is given, the object must have a property with this id
199  \param valueAsString StringValueRepresentation of the property that is required (if not empty).
200  \param id GetUniqueSerializationId() should be this unless 0
201  */
202  a2dCanvasObject* Find( const wxString& objectname, const wxString& classname = wxT( "" ),
203  a2dCanvasObjectFlagsMask mask = a2dCanvasOFlags::ALL , const a2dPropertyId* propid = NULL, const wxString& valueAsString = wxT( "" ),
204  wxUint32 id = 0 ) const;
205 
206  //! If object with the given name is found, it is switched to newobject
207  /*!
208  The old object will be released.
209  The new object will be owned.
210 
211  \return true is object was found.
212  */
213  bool SwitchObjectNamed( const wxString& objectname, a2dCanvasObject* newobject );
214 
215  //!Transform objects fitting the given filter.
216  /*!
217  \param tworld transform matrix to transform the objects
218  \param type If type is empty it collects all objects else only object with this class name.
219  \param mask object must have this mask.
220  \param id if a property id is given, the object must have a property with this id
221  */
222  void Transform( const a2dAffineMatrix& tworld , const wxString& type = wxT( "" ),
224  const a2dPropertyId* id = NULL );
225 
226  //!Transform objects fitting the given filter.
227  /*!
228  \param tworld transform matrix to be set as the new transform for the objects
229  \param type If type is empty it collects all objects else only object with this class name.
230  \param mask object must have this mask.
231  \param id if a property id is given, the object must have a property with this id
232  */
233  void SetTransform( const a2dAffineMatrix& tworld , const wxString& type = wxT( "" ),
235  const a2dPropertyId* id = NULL );
236 
237  //!Move objects fitting the given filter to the total list.
238  /*!
239  \param total list of object found (may already contain elements found in earlier call)
240  \param type If type is empty it collects all objects else only object with this class name.
241  \param mask object must have this mask.
242  \param id the object needs to have this property set if not NULL
243 
244  \return number of objects found
245  */
246  int TakeOverTo( a2dCanvasObjectList* total, const wxString& type = wxT( "" ),
248  const a2dPropertyId* id = NULL );
249 
250  //!Move objects fitting the given filter from the total list to this list
251  /*!
252  \param total list of object found (may already contain elements found in earlier call)
253  \param type If type is empty it collects all objects else only object with this class name.
254  \param mask object must have this mask.
255  \param id the object needs to have this property set if not NULL
256 
257  \return number of objects found
258  */
259  int TakeOverFrom( a2dCanvasObjectList* total, const wxString& type = wxT( "" ),
261  const a2dPropertyId* id = NULL );
262 
263 
264  //!Copy objects fitting the given filter to the total list.
265  /*!
266  \param total list of object found (may already contain elements found in earlier call)
267  \param type If type is empty it collects all objects else only object with this class name.
268  \param mask object must have this mask.
269  \param id if a property id is given, the object must have a property with this id
270  \param bbox only find objects within this box.
271 
272  \return number of objects found
273  */
274  int CollectObjects( a2dCanvasObjectList* total, const wxString& type = wxT( "" ),
276  const a2dPropertyId* id = NULL,
277  const a2dBoundingBox& bbox = wxNonValidBbox
278  );
279 
280  //!set only in this list fill and stroke of objects with the given mask
281  bool SetDrawerStyle( const a2dFill& brush, const a2dStroke& stroke, a2dCanvasObjectFlagsMask mask = a2dCanvasOFlags::ALL );
282 
283  //DECLARE_CLASS(a2dCanvasObjectList)
284 
285  //! Check if all objects are only once in the list
286  void AssertUnique();
287 
288  //! insert at index, taking into account released objects if needed.
289  void Insert( size_t before, a2dCanvasObject* obj, bool ignoreReleased );
290 
291 };
292 
293 typedef a2dCanvasObjectList::iterator a2dCanvasObjectListIter;
294 
295 #if defined(__WXDEBUG__) && wxUSE_GLOBAL_MEMORY_OPERATORS && wxUSE_DEBUG_NEW_ALWAYS
296 #define new new(__TFILE__,__LINE__)
297 #endif
298 
299 //! corridor as a direct event path to a a2dCanvasObject
300 /*!
301  This class is used to store the state of a corridor path set inside a a2dCanvasDocument.
302  All a2dCanvasObject's on the path do have the a2dCanvasOFlags::IsOnCorridorPath flag set.
303  A corridor path is normally initiated from inside a a2dCanvasDocument, somewhere in one of its nested a2dCanvasObject's.
304  This is done via a2dIterC::SetCorridorPath(), this function also stores the matrixes that the iterative context did
305  calculate sofar. This object can therefore be initiated with a a2dIterC.
306 
307  The a2dCorridor is used in drawings and editing tools to restore a corridor to a specific object in a document,
308  e.g when pushing and popping a tool from the toolstack. See a2dBaseTool::GetCorridor()
309 
310  When one tries to construct a corridor based on a2dCanvasView, the matrixes are calculated based on the matrix
311  of the objects in the list.
312 */
313 class A2DCANVASDLLEXP a2dCorridor: public a2dCanvasObjectList
314 {
315 public:
316 
317  a2dCorridor();
318 
319  a2dCorridor( const a2dIterC& context );
320 
321  //! initiate corridor from the current corridor path in a document.
322  /*!
323  The a2dCanvasObject in the document with the m_flags.m_isOnCorridorPath set, are searched
324  starting from the view its ShowObject(), and pushed into the corridor list.
325 
326  The matrix (and its inverse) at the end of the corridor is calculated from the multiplied
327  a2dCanvasObject matrixes in the corridor.
328  */
329  a2dCorridor( const a2dDrawingPart& drawingPart );
330 
331  ~a2dCorridor();
332 
333  //! push object onto existing corridor
334  void Push( a2dCanvasObject* object );
335 
336  //! Get the accumulated transform up to and including m_lworld of the current object
337  /*! This converts from relative local coordinates of the current object to world coordinates.
338  This matrix transforms all drawing primitives used to draw a a2dCanvasObject from relative
339  world coordinates to absolute world coordinates.
340  */
341  const a2dAffineMatrix& GetTransform() const { return m_relativetransform; }
342 
343  //! Inverse of GetTransform()
344  const a2dAffineMatrix& GetInverseTransform() const { return m_inverseRelativetransform; }
345 
346  //!are events redirected to a captured corridor? if so return the captured object in it, else NULL
347  inline a2dCanvasObject* GetCaptured() const { return m_capture; }
348 
349 private:
350 
351  //! the accumulated transforms up to and including m_lworld of last object
352  a2dAffineMatrix m_relativetransform;
353 
354  //! inverse of m_relativetransform
355  a2dAffineMatrix m_inverseRelativetransform;
356 
357  //!set to capctured object at the end of the corridor.
358  a2dCanvasObjectPtr m_capture;
359 };
360 
361 class A2DCANVASDLLEXP a2dCanvasObjectIter: public a2dCanvasObjectList::iterator
362 {
363 public:
364 
366 
367  a2dCanvasObjectIter& operator=( const a2dCanvasObjectIter& other )
368  {
369  *this = other;
370  return *this;
371  }
372 
373  void operator++()
374  {
375  a2dCanvasObjectList::iterator::operator++();
376  }
377 
378  a2dCanvasObject* Item()
379  {
380  a2dCanvasObject* cur = ( *this )->Get();
381  return cur;
382  }
383 
384 };
385 
386 #endif /* __WXOBJLIST_H__ */
Display Part of a a2dDrawing, in which a2dCanvasObjects are shown.
Definition: drawer.h:470
Base class for all types of strokes, understood by a2dDrawer2D classes.
Definition: stylebase.h:378
The base class for all drawable objects in a a2dCanvasDocument.
a2dCanvasObject is the base class for Canvas Objects.
Definition: canobj.h:371
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
defenitions an no more
wxUint64 a2dCanvasObjectFlagsMask
mask flags for a2dCanvasObject
Definition: candefs.h:152
const a2dAffineMatrix & GetInverseTransform() const
Inverse of GetTransform()
Definition: objlist.h:344
a2dCanvasObjectList * wxNullCanvasObjectList
define a NON a2dCanvasObjectList
Definition: objlist.cpp:53
std list compatible list
Definition: a2dlist.h:42
properties specific for a2dCanvasOject
corridor as a direct event path to a a2dCanvasObject
Definition: objlist.h:313
A 2x3 affine matrix class for 2D transformations.
Definition: afmatrix.h:53
while iterating a a2dCanvasDocument, this holds the context.
Definition: canobj.h:3212
a2dCanvasObject * GetCaptured() const
are events redirected to a captured corridor? if so return the captured object in it...
Definition: objlist.h:347
const a2dAffineMatrix & GetTransform() const
Get the accumulated transform up to and including m_lworld of the current object. ...
Definition: objlist.h:341
This is the base class for all kinds of property id&#39;s for a2dObject.
Definition: id.h:154
The a2dBoundingBox class stores one a2dBoundingBox of a a2dCanvasObject.
Definition: bbox.h:39
affine matrix class
static const a2dCanvasObjectFlagsMask ALL
Definition: candefs.h:220
CloneOptions
options for cloning
Definition: gen.h:1200
objlist.h Source File -- Sun Oct 12 2014 17:04:22 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation