00001 /*! \file wx/canvas/vpath.h 00002 \brief vector path a2dVectorPath derived from a2dCanvasObject 00003 00004 a2dVectorPath holds internal a plain a2dVpath, which no can be styled and placed 00005 inside a document. 00006 00007 \author Klaas Holwerda 00008 00009 Copyright: 2000-2004 (c) Klaas Holwerda 00010 00011 Licence: wxWidgets Licence 00012 00013 RCS-ID: $Id: vpath.h,v 1.17 2009/04/04 15:04:56 titato Exp $ 00014 */ 00015 00016 /*! 00017 \defgroup vpath vector path a2dCanvasObject plus segment classes 00018 00019 \ingroup canvasobject 00020 */ 00021 00022 #ifndef __WXVPATH_H__ 00023 #define __WXVPATH_H__ 00024 00025 #ifndef WX_PRECOMP 00026 #include "wx/wx.h" 00027 #endif 00028 00029 #include "wx/artbase/drawer2d.h" 00030 #include "wx/canvas/canobj.h" 00031 00032 //---------------------------------------------------------------------------- 00033 // a2dVectorPath 00034 //---------------------------------------------------------------------------- 00035 00036 00037 //!a2dCanvasObject for a Vector Path 00038 /*! 00039 This class is mainly a wrapper around a2dVpath, 00040 a2dVpath is a wxArray like structure. 00041 So see wxArray for more documentation. 00042 00043 00044 \sa a2dVpath 00045 \sa a2dVpathqBCurveSegment 00046 \sa a2dVpathCBCurveSegment 00047 \sa a2dVpathArcSegment 00048 00049 \sa wxArray 00050 00051 \remark do use Shrink() after filling a a2dVectorPath, to reduce memory usage 00052 00053 \ingroup canvasobject vpath 00054 */ 00055 class A2DCANVASDLLEXP a2dVectorPath: public a2dCanvasObject 00056 { 00057 public: 00058 00059 //! construct with empty array of segments 00060 a2dVectorPath(); 00061 00062 //! initialize using a vector path array 00063 a2dVectorPath( a2dVpath* path ); 00064 00065 //! construct with a pointer to another a2dVectorPath 00066 a2dVectorPath( const a2dVectorPath &other, CloneOptions options ); 00067 00068 ~a2dVectorPath(); 00069 00070 virtual a2dObject* Clone( CloneOptions options ) const; 00071 00072 //! calculate Length 00073 double Length() { return m_segments->Length(); } 00074 00075 //! reduce matrix to identity without replacing object 00076 bool EliminateMatrix(); 00077 00078 //! Convert complex segments to line segments. 00079 void ConvertToLines(); 00080 00081 //! convert to a list of a2dPolygonL and a2dPolylineL 00082 /*! 00083 For vectorpaths can be split into closed sections ( polygon filled areas), 00084 non closed sections ( polyline ). Those two type can be stroked or not. 00085 If m_contourwidth is set the two type above are contoured and a distance of 00086 m_contourwidth/2.0 and those parts are stroked. 00087 Effectively this brings only pure polygons as output. 00088 */ 00089 a2dCanvasObjectList* GetAsPolygons(); 00090 00091 a2dCanvasObjectList* GetAsCanvasVpaths( bool transform = true ); 00092 00093 bool RestrictToObject( a2dRestrictionEngine* engine, a2dSnapToWhatMask snapToWhat ); 00094 00095 //!modify point at index to x,y 00096 /*! 00097 Set the coordinates of the point at index to x,y. 00098 \param index the index of the point to change 00099 \param x new x for the point 00100 \param y new y for the point 00101 \param afterinversion if true the input x,y or first inverted with the local matrix of the object. 00102 The inverted values are used to set the point. 00103 00104 \remark afterinversion = true should be used if you have x,y relative to the polygon object, 00105 while afterinversion = false should be used when x,y are relative to the point in the polygon. 00106 */ 00107 //void SetPosXYSegment(int index, double x, double y, bool afterinversion = true ); 00108 00109 //! get point x and y at index 00110 /*! 00111 \param index the index of the point to change 00112 \param x new x for the point 00113 \param y new y for the point 00114 \param transform if true return x y transformed with local matrix 00115 */ 00116 //void GetPosXYSegment(int index, double& x, double& y, bool transform = true ); 00117 00118 //! use this to get to other function in underlying wxArray 00119 a2dVpath* GetSegments() { return m_segments; } 00120 00121 //!Return the number of segments. 00122 size_t GetCount() { return m_segments->GetCount(); } 00123 00124 //!Append a new segment, which is owned by this class now 00125 void Add( a2dVpathSegment *item ) { m_segments->Add( item ); } 00126 00127 //!Preallocates memory for a given number of array elements. 00128 /*! 00129 It is worth calling when the number of items which are going to be added to the array 00130 is known in advance because it will save unneeded memory reallocation. 00131 If the array already has enough memory for the given number of items, nothing happens. 00132 */ 00133 void Alloc(size_t count) { m_segments->Alloc( count ); } 00134 00135 //!This function does the same as Empty() and additionally frees the memory allocated to the array. 00136 void Clear() { m_segments->Clear(); } 00137 00138 //! Removes the element from the array, but, unlike, Remove() doesn't delete it. 00139 //! The function returns the pointer to the removed element. 00140 a2dVpathSegment* Detach(size_t index) { return m_segments->Detach( index ); } 00141 00142 //!Empties the array. For wxObjArray classes, this destroys all of the array elements. 00143 //!this function does not free the allocated memory, use Clear() for this. 00144 void Empty() { m_segments->Empty(); } 00145 00146 //!Insert a new segment into the array before the segment n - thus, Insert(something, 0u) 00147 //!will insert a segment in such way that it will become the first array element. 00148 // void Insert( a2dVpathSegment *item, size_t n ); 00149 00150 //!Returns true if the array is empty, false otherwise. 00151 bool IsEmpty() const { return m_segments->IsEmpty(); } 00152 00153 //! get i'th segment 00154 a2dVpathSegment& operator[](size_t index) const { return m_segments->Item( index ); } 00155 00156 //!Returns a reference to the segment at the given position in the array. 00157 //!If index is out of bounds, an assert failure is raised in 00158 //!the debug builds but nothing special is done in the release build. 00159 a2dVpathSegment& Item(size_t index) const { return m_segments->Item( index ); } 00160 00161 //!Returns a reference to the last segment in de array, i.e. is the same as 00162 //!Item(GetCount() - 1). An assert failure is raised in the debug mode if the array is empty. 00163 a2dVpathSegment& Last() const { return m_segments->Last(); } 00164 00165 //!Removes a segment from the array by index. When a segment is removed 00166 //!it is deleted - use Detach() if you don't want this to happen. 00167 void RemoveAt(size_t index) { m_segments->RemoveAt( index ); } 00168 00169 //!Frees all memory unused by the array. 00170 /*!If the program knows that no new items will be added to the 00171 array it may call Shrink() to reduce its memory usage. However, if a 00172 new item is added to the array, some extra memory will be allocated again. 00173 */ 00174 void Shrink() { m_segments->Shrink(); } 00175 00176 void SetContourWidth(double width) { m_contourwidth = width; SetPending(true); } 00177 00178 //!get the Contour width of the shape 00179 double GetContourWidth() const { return m_contourwidth; } 00180 00181 //! GDSII compatible to sub identify this object. 00182 /*! you can use it as a special tagged object */ 00183 void SetDataType( int type ) { m_datatype = type; } 00184 00185 //! GDSII compatible to sub identify this object. 00186 /*! you can use it as a special tagged object */ 00187 int GetDataType() { return m_datatype; } 00188 00189 //! Set when m_contourwidth != 0 what is the end of the lines should be. 00190 void SetPathType( a2dPATH_END_TYPE pathtype ) { m_pathtype = pathtype; } 00191 00192 //! get when m_contourwidth != 0 what is the end of the lines looks like. 00193 a2dPATH_END_TYPE GetPathType() { return m_pathtype; } 00194 00195 void DoRender( a2dIterC& ic, OVERLAP clipparent ); 00196 00197 DECLARE_DYNAMIC_CLASS(a2dVectorPath) 00198 00199 protected: 00200 00201 bool DoIsHitWorld( a2dIterC& ic, a2dHitEvent& hitEvent ); 00202 00203 a2dBoundingBox DoGetUnTransformedBbox( a2dBboxFlags flags = a2dCANOBJ_BBOX_NON ) const; 00204 00205 bool DoUpdate( UpdateMode mode, const a2dBoundingBox& childbox, const a2dBoundingBox& clipbox, const a2dBoundingBox& propbox ); 00206 00207 #if wxART2D_USE_CVGIO 00208 void DoSave( wxObject* parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite ); 00209 void DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts ); 00210 #endif //wxART2D_USE_CVGIO 00211 00212 a2dVpath* m_segments; 00213 00214 //! if != 0 the continues path parts are contoured at distance m_contourwidth/2 00215 double m_contourwidth; 00216 00217 //! GDSII compatible to sub identify this object 00218 int m_datatype; 00219 00220 //! when m_contourwidth != 0 what is the end of the line looking like. 00221 a2dPATH_END_TYPE m_pathtype; 00222 00223 private: 00224 //!this is a not implemented copy constructor that avoids automatic creation of one 00225 a2dVectorPath( const a2dVectorPath &other ); 00226 }; 00227 00228 #endif 00229