]> Shamusworld >> Repos - architektonas/blob - src/base/rs_arc.h
974d97ee119471558434e0104b1bd82f08c091e9
[architektonas] / src / base / rs_arc.h
1 #ifndef RS_ARC_H
2 #define RS_ARC_H
3
4 #include "rs_atomicentity.h"
5
6 class PaintInterface;
7 class GraphicView;
8
9 /**
10  * Holds the data that defines an arc.
11  */
12 class RS_ArcData
13 {
14         public:
15                 RS_ArcData()
16                 {
17                 }
18
19                 RS_ArcData(const Vector & center, double radius, double angle1, double angle2, bool reversed)
20                 {
21                         this->center = center;
22                         this->radius = radius;
23                         this->angle1 = angle1;
24                         this->angle2 = angle2;
25                         this->reversed = reversed;
26                 }
27
28                 void reset()
29                 {
30                         center = Vector(false);
31                         radius = 0.0;
32                         angle1 = 0.0;
33                         angle2 = 0.0;
34                         reversed = false;
35                 }
36
37                 bool isValid()
38                 {
39                         return (center.valid && radius > RS_TOLERANCE
40                                 && fabs(angle1 - angle2) > RS_TOLERANCE_ANGLE);
41                 }
42
43                 friend std::ostream & operator<<(std::ostream & os, const RS_ArcData & ad)
44                 {
45                         os << "(" << ad.center
46                         << "/" << ad.radius
47                         << " " << ad.angle1
48                         << "," << ad.angle2
49                         << ")";
50                         return os;
51                 }
52
53         public:
54                 Vector center;
55                 double radius;
56                 double angle1;
57                 double angle2;
58                 bool reversed;
59 };
60
61 /**
62  * Class for an arc entity. All angles are in Rad.
63  *
64  * @author Andrew Mustun
65  */
66 class RS_Arc: public RS_AtomicEntity
67 {
68         public:
69                 RS_Arc(RS_EntityContainer * parent, const RS_ArcData & d);
70                 virtual ~RS_Arc();
71
72                 virtual RS_Entity * clone();
73                 virtual RS2::EntityType rtti() const;
74                 virtual bool isEdge() const;
75                 RS_ArcData getData() const;
76                 virtual VectorSolutions getRefPoints();
77                 void setData(RS_ArcData d);
78                 Vector getCenter() const;
79                 void setCenter(const Vector & c);
80                 double getRadius() const;
81                 void setRadius(double r);
82                 double getAngle1() const;
83                 void setAngle1(double a1);
84                 double getAngle2() const;
85                 void setAngle2(double a2);
86                 double getDirection1() const;
87                 double getDirection2() const;
88                 bool isReversed() const;
89                 void setReversed(bool r);
90                 virtual Vector getStartpoint() const;
91                 virtual Vector getEndpoint() const;
92                 virtual void moveStartpoint(const Vector & pos);
93                 virtual void moveEndpoint(const Vector & pos);
94                 virtual void trimStartpoint(const Vector & pos);
95                 virtual void trimEndpoint(const Vector & pos);
96                 virtual RS2::Ending getTrimPoint(const Vector & coord, const Vector & trimPoint);
97                 virtual void reverse();
98                 Vector getMiddlepoint() const;
99                 double getAngleLength() const;
100                 virtual double getLength();
101                 double getBulge() const;
102
103                 bool createFrom3P(const Vector & p1, const Vector & p2, const Vector & p3);
104                 bool createFrom2PDirectionRadius(const Vector & startPoint, const Vector & endPoint, double direction1, double radius);
105                 bool createFrom2PBulge(const Vector & startPoint, const Vector & endPoint, double bulge);
106
107                 virtual Vector getNearestEndpoint(const Vector & coord, double * dist = NULL);
108                 virtual Vector getNearestPointOnEntity(const Vector & coord, bool onEntity = true, double * dist = NULL, RS_Entity ** entity = NULL);
109                 virtual Vector getNearestCenter(const Vector & coord, double * dist = NULL);
110                 virtual Vector getNearestMiddle(const Vector & coord, double * dist = NULL);
111                 virtual Vector getNearestDist(double distance, const Vector & coord, double * dist = NULL);
112                 virtual Vector getNearestDist(double distance, bool startp);
113
114                 virtual double getDistanceToPoint(const Vector & coord, RS_Entity * * entity = NULL, RS2::ResolveLevel level = RS2::ResolveNone, double solidDist = RS_MAXDOUBLE);
115                 virtual void move(Vector offset);
116                 virtual void rotate(Vector center, double angle);
117                 virtual void scale(Vector center, Vector factor);
118                 virtual void mirror(Vector axisPoint1, Vector axisPoint2);
119                 virtual void moveRef(const Vector & ref, const Vector & offset);
120                 virtual void stretch(Vector firstCorner, Vector secondCorner, Vector offset);
121
122                 virtual void draw(PaintInterface * painter, GraphicView * view, double patternOffset = 0.0);
123
124                 friend std::ostream & operator<<(std::ostream & os, const RS_Arc & a);
125
126                 virtual void calculateEndpoints();
127                 virtual void calculateBorders();
128
129         protected:
130                 RS_ArcData data;
131
132                 /**
133                  * Startpoint. This is redundant but stored for performance
134                  * reasons.
135                  */
136                 Vector startpoint;
137                 /**
138                  * Endpoint. This is redundant but stored for performance
139                  * reasons.
140                  */
141                 Vector endpoint;
142 };
143
144 #endif