]> Shamusworld >> Repos - architektonas/blob - src/base/rs_solid.h
Refactoring: Moved RS_GraphicView to GraphicView.
[architektonas] / src / base / rs_solid.h
1 #ifndef RS_SOLID_H
2 #define RS_SOLID_H
3
4 #include "rs_atomicentity.h"
5 #include "vector.h"
6
7 /**
8  * Holds the data that defines a solid.
9  */
10 class RS_SolidData
11 {
12         public:
13                 /**
14                  * Default constructor. Leaves the data object uninitialized.
15                  */
16                 RS_SolidData()
17                 {
18                         for(int i=0; i<4; ++i)
19                                 corner[i] = Vector(false);
20                 }
21
22                 /**
23                  * Constructor for a solid with 3 corners.
24                  */
25                 RS_SolidData(const Vector & corner1, const Vector & corner2, const Vector & corner3)
26                 {
27                         corner[0] = corner1;
28                         corner[1] = corner2;
29                         corner[2] = corner3;
30                         corner[3] = Vector(false);
31                 }
32
33                 /**
34                  * Constructor for a solid with 4 corners.
35                  */
36                 RS_SolidData(const Vector & corner1, const Vector & corner2, const Vector & corner3, const Vector & corner4)
37                 {
38                         corner[0] = corner1;
39                         corner[1] = corner2;
40                         corner[2] = corner3;
41                         corner[3] = corner4;
42                 }
43
44                 friend class RS_Solid;
45
46                 friend std::ostream & operator<<(std::ostream & os, const RS_SolidData & pd)
47                 {
48                         os << "(";
49
50                         for(int i=0; i<4; i++)
51                                 os << pd.corner[i];
52
53                         os << ")";
54                         return os;
55                 }
56
57         private:
58                 Vector corner[4];
59 };
60
61 /**
62  * Class for a solid entity (e.g. dimension arrows).
63  *
64  * @author Andrew Mustun
65  */
66 class RS_Solid: public RS_AtomicEntity
67 {
68         public:
69                 RS_Solid(RS_EntityContainer * parent, const RS_SolidData & d);
70
71                 virtual RS_Entity * clone();
72                 virtual RS2::EntityType rtti() const;
73                 virtual Vector getStartpoint() const;
74                 virtual Vector getEndpoint() const;
75                 RS_SolidData getData() const;
76                 bool isTriangle();
77                 Vector getCorner(int num);
78                 void shapeArrow(const Vector & point, double angle, double arrowSize);
79
80                 virtual Vector getNearestEndpoint(const Vector & coord, double * dist = NULL);
81                 virtual Vector getNearestPointOnEntity(const Vector & coord, bool onEntity = true,
82                         double * dist = NULL, RS_Entity ** entity = NULL);
83                 virtual Vector getNearestCenter(const Vector & coord, double * dist = NULL);
84                 virtual Vector getNearestMiddle(const Vector & coord, double * dist = NULL);
85                 virtual Vector getNearestDist(double distance, const Vector & coord, double * dist = NULL);
86                 virtual double getDistanceToPoint(const Vector & coord, RS_Entity ** entity = NULL,
87                         RS2::ResolveLevel level = RS2::ResolveNone, double solidDist = RS_MAXDOUBLE);
88                 virtual void move(Vector offset);
89                 virtual void rotate(Vector center, double angle);
90                 virtual void scale(Vector center, Vector factor);
91                 virtual void mirror(Vector axisPoint1, Vector axisPoint2);
92                 virtual void draw(PaintInterface * painter, GraphicView * view, double patternOffset = 0.0);
93
94                 friend std::ostream & operator<<(std::ostream & os, const RS_Solid & p);
95
96                 /** Recalculates the borders of this entity. */
97                 virtual void calculateBorders ();
98
99         protected:
100                 RS_SolidData data;
101 };
102
103 #endif