]> Shamusworld >> Repos - architektonas/blob - src/base/rs_point.cpp
b9725fff149c9ccf43d630dfdd86d638c483ebae
[architektonas] / src / base / rs_point.cpp
1 /****************************************************************************
2 ** $Id: rs_point.cpp 1907 2004-09-04 19:56:42Z andrew $
3 **
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
5 **
6 ** This file is part of the qcadlib Library project.
7 **
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
12 **
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
16 **
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 **
20 ** See http://www.ribbonsoft.com for further details.
21 **
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
23 ** not clear to you.
24 **
25 **********************************************************************/
26
27 #include "rs_point.h"
28
29 #include "rs_graphicview.h"
30 //#include "rs_painter.h"
31 #include "paintintf.h"
32
33 /**
34  * Default constructor.
35  */
36 RS_Point::RS_Point(RS_EntityContainer * parent, const RS_PointData & d):
37         RS_AtomicEntity(parent), data(d)
38 {
39         calculateBorders();
40 }
41
42 /*virtual*/ RS_Entity * RS_Point::clone()
43 {
44         RS_Point * p = new RS_Point(*this);
45         p->initId();
46         return p;
47 }
48
49 /**     @return RS_ENTITY_POINT */
50 /*virtual*/ RS2::EntityType RS_Point::rtti() const
51 {
52         return RS2::EntityPoint;
53 }
54
55 /**
56  * @return Start point of the entity.
57  */
58 /*virtual*/ Vector RS_Point::getStartpoint() const
59 {
60         return data.pos;
61 }
62
63 /**
64  * @return End point of the entity.
65  */
66 /*virtual*/ Vector RS_Point::getEndpoint() const
67 {
68         return data.pos;
69 }
70
71 /** @return Copy of data that defines the point. */
72 RS_PointData RS_Point::getData() const
73 {
74         return data;
75 }
76
77 /** @return Position of the point */
78 Vector RS_Point::getPos()
79 {
80         return data.pos;
81 }
82
83 /** Sets a new position for this point. */
84 void RS_Point::setPos(const Vector & pos)
85 {
86         data.pos = pos;
87 }
88
89 void RS_Point::calculateBorders()
90 {
91         minV = maxV = data.pos;
92 }
93
94 VectorSolutions RS_Point::getRefPoints()
95 {
96         VectorSolutions ret(data.pos);
97         return ret;
98 }
99
100 Vector RS_Point::getNearestEndpoint(const Vector & coord, double * dist)
101 {
102         if (dist != NULL)
103                 *dist = data.pos.distanceTo(coord);
104
105         return data.pos;
106 }
107
108 Vector RS_Point::getNearestPointOnEntity(const Vector & coord,
109         bool /*onEntity*/, double * dist, RS_Entity ** entity)
110 {
111         if (dist != NULL)
112                 *dist = data.pos.distanceTo(coord);
113
114         if (entity != NULL)
115                 *entity = this;
116
117         return data.pos;
118 }
119
120 Vector RS_Point::getNearestCenter(const Vector & coord, double * dist)
121 {
122         if (dist != NULL)
123                 *dist = data.pos.distanceTo(coord);
124
125         return data.pos;
126 }
127
128 Vector RS_Point::getNearestMiddle(const Vector & coord, double * dist)
129 {
130         if (dist != NULL)
131                 *dist = data.pos.distanceTo(coord);
132
133         return data.pos;
134 }
135
136 Vector RS_Point::getNearestDist(double /*distance*/, const Vector & /*coord*/, double * dist)
137 {
138         if (dist != NULL)
139                 *dist = RS_MAXDOUBLE;
140
141         return Vector(false);
142 }
143
144 double RS_Point::getDistanceToPoint(const Vector & coord, RS_Entity ** entity,
145         RS2::ResolveLevel /*level*/, double /*solidDist*/)
146 {
147         if (entity != NULL)
148                 *entity = this;
149
150         return data.pos.distanceTo(coord);
151 }
152
153 void RS_Point::moveStartpoint(const Vector & pos)
154 {
155         data.pos = pos;
156         calculateBorders();
157 }
158
159 void RS_Point::move(Vector offset)
160 {
161         data.pos.move(offset);
162         calculateBorders();
163 }
164
165 void RS_Point::rotate(Vector center, double angle)
166 {
167         data.pos.rotate(center, angle);
168         calculateBorders();
169 }
170
171 void RS_Point::scale(Vector center, Vector factor)
172 {
173         data.pos.scale(center, factor);
174         calculateBorders();
175 }
176
177 void RS_Point::mirror(Vector axisPoint1, Vector axisPoint2)
178 {
179         data.pos.mirror(axisPoint1, axisPoint2);
180         calculateBorders();
181 }
182
183 //void RS_Point::draw(RS_Painter * painter, RS_GraphicView * view, double /*patternOffset*/)
184 void RS_Point::draw(PaintInterface * painter, RS_GraphicView * view, double /*patternOffset*/)
185 {
186         if (painter == NULL || view == NULL)
187                 return;
188
189         painter->drawPoint(view->toGui(getPos()));
190 }
191
192 /**
193  * Dumps the point's data to stdout.
194  */
195 std::ostream & operator<<(std::ostream & os, const RS_Point & p)
196 {
197     os << " Point: " << p.getData() << "\n";
198     return os;
199 }