]> Shamusworld >> Repos - architektonas/blob - src/base/rs_point.cpp
Changed RS_Graphic to Drawing; this is less confusing as a drawing is
[architektonas] / src / base / rs_point.cpp
1 // rs_point.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // (C) 2010 Underground Software
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  06/01/2010  Added this text. :-)
13 //
14
15 #include "rs_point.h"
16
17 #include "rs_graphicview.h"
18 //#include "rs_painter.h"
19 #include "paintintf.h"
20
21 /**
22  * Default constructor.
23  */
24 RS_Point::RS_Point(RS_EntityContainer * parent, const RS_PointData & d):
25         RS_AtomicEntity(parent), data(d)
26 {
27         calculateBorders();
28 }
29
30 /*virtual*/ RS_Entity * RS_Point::clone()
31 {
32         RS_Point * p = new RS_Point(*this);
33         p->initId();
34         return p;
35 }
36
37 /**     @return RS_ENTITY_POINT */
38 /*virtual*/ RS2::EntityType RS_Point::rtti() const
39 {
40         return RS2::EntityPoint;
41 }
42
43 /**
44  * @return Start point of the entity.
45  */
46 /*virtual*/ Vector RS_Point::getStartpoint() const
47 {
48         return data.pos;
49 }
50
51 /**
52  * @return End point of the entity.
53  */
54 /*virtual*/ Vector RS_Point::getEndpoint() const
55 {
56         return data.pos;
57 }
58
59 /** @return Copy of data that defines the point. */
60 RS_PointData RS_Point::getData() const
61 {
62         return data;
63 }
64
65 /** @return Position of the point */
66 Vector RS_Point::getPos()
67 {
68         return data.pos;
69 }
70
71 /** Sets a new position for this point. */
72 void RS_Point::setPos(const Vector & pos)
73 {
74         data.pos = pos;
75 }
76
77 void RS_Point::calculateBorders()
78 {
79         minV = maxV = data.pos;
80 }
81
82 VectorSolutions RS_Point::getRefPoints()
83 {
84         VectorSolutions ret(data.pos);
85         return ret;
86 }
87
88 Vector RS_Point::getNearestEndpoint(const Vector & coord, double * dist)
89 {
90         if (dist != NULL)
91                 *dist = data.pos.distanceTo(coord);
92
93         return data.pos;
94 }
95
96 Vector RS_Point::getNearestPointOnEntity(const Vector & coord,
97         bool /*onEntity*/, double * dist, RS_Entity ** entity)
98 {
99         if (dist != NULL)
100                 *dist = data.pos.distanceTo(coord);
101
102         if (entity != NULL)
103                 *entity = this;
104
105         return data.pos;
106 }
107
108 Vector RS_Point::getNearestCenter(const Vector & coord, double * dist)
109 {
110         if (dist != NULL)
111                 *dist = data.pos.distanceTo(coord);
112
113         return data.pos;
114 }
115
116 Vector RS_Point::getNearestMiddle(const Vector & coord, double * dist)
117 {
118         if (dist != NULL)
119                 *dist = data.pos.distanceTo(coord);
120
121         return data.pos;
122 }
123
124 Vector RS_Point::getNearestDist(double /*distance*/, const Vector & /*coord*/, double * dist)
125 {
126         if (dist != NULL)
127                 *dist = RS_MAXDOUBLE;
128
129         return Vector(false);
130 }
131
132 double RS_Point::getDistanceToPoint(const Vector & coord, RS_Entity ** entity,
133         RS2::ResolveLevel /*level*/, double /*solidDist*/)
134 {
135         if (entity != NULL)
136                 *entity = this;
137
138         return data.pos.distanceTo(coord);
139 }
140
141 void RS_Point::moveStartpoint(const Vector & pos)
142 {
143         data.pos = pos;
144         calculateBorders();
145 }
146
147 void RS_Point::move(Vector offset)
148 {
149         data.pos.move(offset);
150         calculateBorders();
151 }
152
153 void RS_Point::rotate(Vector center, double angle)
154 {
155         data.pos.rotate(center, angle);
156         calculateBorders();
157 }
158
159 void RS_Point::scale(Vector center, Vector factor)
160 {
161         data.pos.scale(center, factor);
162         calculateBorders();
163 }
164
165 void RS_Point::mirror(Vector axisPoint1, Vector axisPoint2)
166 {
167         data.pos.mirror(axisPoint1, axisPoint2);
168         calculateBorders();
169 }
170
171 //void RS_Point::draw(RS_Painter * painter, RS_GraphicView * view, double /*patternOffset*/)
172 void RS_Point::draw(PaintInterface * painter, RS_GraphicView * view, double /*patternOffset*/)
173 {
174         if (painter == NULL || view == NULL)
175                 return;
176
177         painter->drawPoint(view->toGui(getPos()));
178 }
179
180 /**
181  * Dumps the point's data to stdout.
182  */
183 std::ostream & operator<<(std::ostream & os, const RS_Point & p)
184 {
185     os << " Point: " << p.getData() << "\n";
186     return os;
187 }