1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
/***************************************************************
* Name: PolygonShape.h
* Purpose: Defines polygonial shape class
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFPOLYGONSHAPE_H
#define _WXSFPOLYGONSHAPE_H
#include <wx/wxsf/RectShape.h>
// default values
/*! \brief Default value of wxSFPolygonShape::m_fConnextToVertex data member. */
#define sfdvPOLYGONSHAPE_VERTEXCONNECTIONS true
/*!
* \brief Class extends the wxSFRectShape and encapsulates general polygon shape
* defined by a set of its vertices. The class can be used as it is or as a base class
* for shapes with more complex form and functionality.
* \sa wxSFDiamondShape
*/
class WXDLLIMPEXP_SF wxSFPolygonShape : public wxSFRectShape
{
public:
XS_DECLARE_CLONABLE_CLASS(wxSFPolygonShape);
/*! \brief Default constructor. */
wxSFPolygonShape(void);
/*!
* \brief User constructor.
* \param n Number of the polygon vertices
* \param pts Array of the polygon vertices
* \param pos Relative position of the polygon shape
* \param manager Pointer of parent diagram manager
*/
wxSFPolygonShape(int n, const wxRealPoint pts[], const wxRealPoint& pos, wxSFDiagramManager* manager);
/*!
* \brief Copy constructor.
* \param obj Reference to a source object
*/
wxSFPolygonShape(const wxSFPolygonShape& obj);
/*! \brief Destructor. */
virtual ~wxSFPolygonShape(void);
// public data accessors
/*!
* \brief Set connecting mode.
* \param enable Set this parameter to TRUE if you want to connect
* line shapes to the polygons's vertices, otherwise the lines will be connected
* to the nearest point of the shape's border.
*/
void SetConnectToVertex(bool enable){m_fConnectToVertex = enable;}
/*!
* \brief Get status of connecting mode.
* \return TRUE if the line shapes will be connected to the polygon's vertices
*/
bool IsConnectedToVertex(){return m_fConnectToVertex;}
// public functions
/*!
* \brief Set the poly vertices which define its form.
* \param n Number of the vertices
* \param pts Array of the vertices
*/
void SetVertices(size_t n, const wxRealPoint pts[]);
// public virtual functions
/*!
* \brief Resize the rectangle to bound all child shapes. The function can be overrided if neccessary. */
virtual void FitToChildren();
/*!
* \brief Get intersection point of the shape border and a line leading from
* 'start' point to 'end' point. The function can be overrided if neccessary.
* \param start Starting point of the virtual intersection line
* \param end Ending point of the virtual intersection line
* \return Intersection point
*/
virtual wxRealPoint GetBorderPoint(const wxRealPoint& start, const wxRealPoint& end);
/*!
* \brief Scale the shape size by in both directions. The function can be overrided if necessary
* (new implementation should call default one ore scale shape's children manualy if neccesary).
* \param x Horizontal scale factor
* \param y Vertical scale factor
* \param children TRUE if the shape's children shoould be scaled as well, otherwise the shape will be updated after scaling via Update() function.
*/
virtual void Scale(double x, double y, bool children = sfWITHCHILDREN);
/*!
* \brief Event handler called during dragging of the shape handle.
* The function can be overrided if necessary.
*
* The function is called by the framework (by the shape canvas).
* \param handle Reference to dragged handle
*/
virtual void OnHandle(wxSFShapeHandle &handle);
protected:
// protected data members
bool m_fConnectToVertex;
wxXS::RealPointArray m_arrVertices;
// protected functions
/*!
* \brief Move all vertices so the polygon's relative bounding box position
* will be located in the origin.
*/
void NormalizeVertices();
/*! \brief Scale polygon's vertices to fit into the rectangle bounding the polygon. */
void FitVerticesToBoundingBox();
/*! \brief Scale the bounding rectangle to fit all polygons vertices. */
void FitBoundingBoxToVertices();
/*!
* \brief Get polygon extents.
* \param minx Position of the left side of polygon's bounding box
* \param miny Position of the top side of polygon's bounding box
* \param maxx Position of the right side of polygon's bounding box
* \param maxy Position of the bottom side of polygon's bounding box
*/
void GetExtents(double *minx, double *miny, double *maxx, double *maxy);
/*!
* \brief Get absolute positions of the polygon's vertices.
* \param pts Array of translated polygon's verices
*/
void GetTranslatedVerices(wxRealPoint pts[]);
/*!
* \brief Get absolute positions of the polygon's vertices.
* \param pts Array of translated polygon's verices
*/
void GetTranslatedVerices(wxPoint pts[]);
/*!
* \brief Draw the polygon shape.
* \param dc Refernece to the device context where the shape will be drawn to
*/
void DrawPolygonShape(wxDC& dc);
// protected virtual functions
/*!
* \brief Draw the shape in the normal way. The function can be overrided if neccessary.
* \param dc Reference to device context where the shape will be drawn to
*/
virtual void DrawNormal(wxDC& dc);
/*!
* \brief Draw the shape in the hower mode (the mouse cursor is above the shape).
* The function can be overrided if neccessary.
* \param dc Reference to device context where the shape will be drawn to
*/
virtual void DrawHover(wxDC& dc);
/*!
* \brief Draw the shape in the highlighted mode (another shape is dragged over this
* shape and this shape will accept the dragged one if it will be dropped on it).
* The function can be overrided if neccessary.
* \param dc Reference to device context where the shape will be drawn to
*/
virtual void DrawHighlighted(wxDC& dc);
/*!
* \brief Draw shadow under the shape. The function can be overrided if neccessary.
* \param dc Reference to device context where the shadow will be drawn to
*/
virtual void DrawShadow(wxDC& dc);
/*!
* \brief Serialize shape's properties to the given XML node. The serialization
* routine is automatically called by the framework and should take care about serialization
* of all specific (non-standard) shape's properties.
* \param node Pointer to XML node where the shape's property nodes will be appended to
* \sa xsSerializable::Serialize
*/
virtual wxXmlNode* Serialize(wxXmlNode* node);
/*!
* \brief Deserialize shape's properties from the given XML node. The
* routine is automatically called by the framework and should take care about deserialization
* of all specific (non-standard) shape's properties.
* \param node Pointer to a source XML node containig the shape's property nodes
* \sa xsSerializable::Deserialize
*/
virtual void Deserialize(wxXmlNode* node);
private:
// private functions
/*! \brief Initialize serializable properties. */
void MarkSerializableDataMembers();
};
#endif //_WXSFPOLYGONSHAPE_H
|