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 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 06/02/2010 Added this text. :-)
19 #include "graphicview.h"
20 #include "paintinterface.h"
23 * Default constructor.
25 RS_Solid::RS_Solid(RS_EntityContainer * parent, const RS_SolidData & d):
26 RS_AtomicEntity(parent), data(d)
31 /*virtual*/ RS_Entity * RS_Solid::clone()
33 RS_Solid * s = new RS_Solid(*this);
38 /** @return RS_ENTITY_POINT */
39 /*virtual*/ RS2::EntityType RS_Solid::rtti() const
41 return RS2::EntitySolid;
45 * @return Start point of the entity.
47 /*virtual*/ Vector RS_Solid::getStartpoint() const
53 * @return End point of the entity.
55 /*virtual*/ Vector RS_Solid::getEndpoint() const
60 /** @return Copy of data that defines the point. */
61 RS_SolidData RS_Solid::getData() const
66 /** @return true if this is a triangle. */
67 bool RS_Solid::isTriangle()
69 return !data.corner[3].valid;
73 * @return Corner number 'num'.
75 Vector RS_Solid::getCorner(int num)
77 if (num >= 0 && num < 4)
78 return data.corner[num];
81 RS_DEBUG->print("Illegal corner requested from Solid", RS_Debug::D_WARNING);
87 * Shapes this Solid into a standard arrow (used in dimensions).
89 * @param point The point the arrow points to.
90 * @param angle Direction of the arrow.
91 * @param arrowSize Size of arrow (length).
93 void RS_Solid::shapeArrow(const Vector & point, double angle, double arrowSize)
95 double cosv1, sinv1, cosv2, sinv2;
96 double arrowSide = arrowSize / cos(0.165);
98 cosv1 = cos(angle + 0.165) * arrowSide;
99 sinv1 = sin(angle + 0.165) * arrowSide;
100 cosv2 = cos(angle - 0.165) * arrowSide;
101 sinv2 = sin(angle - 0.165) * arrowSide;
103 data.corner[0] = point;
104 data.corner[1] = Vector(point.x - cosv1, point.y - sinv1);
105 data.corner[2] = Vector(point.x - cosv2, point.y - sinv2);
106 data.corner[3] = Vector(false);
111 void RS_Solid::calculateBorders()
115 for(int i=0; i<4; ++i)
117 if (data.corner[i].valid)
119 minV = Vector::minimum(minV, data.corner[i]);
120 maxV = Vector::maximum(maxV, data.corner[i]);
125 Vector RS_Solid::getNearestEndpoint(const Vector & coord, double * dist)
127 double minDist = RS_MAXDOUBLE;
131 for(int i=0; i<4; ++i)
133 if (data.corner[i].valid)
135 curDist = data.corner[i].distanceTo(coord);
137 if (curDist < minDist)
139 ret = data.corner[i];
152 * @todo Implement this.
154 Vector RS_Solid::getNearestPointOnEntity(const Vector & /*coord*/, bool /*onEntity*/,
155 double * /*dist*/, RS_Entity ** /*entity*/)
161 Vector RS_Solid::getNearestCenter(const Vector & /*coord*/, double * dist)
164 *dist = RS_MAXDOUBLE;
166 return Vector(false);
169 Vector RS_Solid::getNearestMiddle(const Vector & /*coord*/, double * dist)
172 *dist = RS_MAXDOUBLE;
174 return Vector(false);
177 Vector RS_Solid::getNearestDist(double /*distance*/, const Vector & /*coord*/, double * dist)
180 *dist = RS_MAXDOUBLE;
182 return Vector(false);
186 * @return Distance from one of the boundry lines of this solid to given point.
190 double RS_Solid::getDistanceToPoint(const Vector & /*coord*/, RS_Entity ** /*entity*/,
191 RS2::ResolveLevel /*level*/, double /*solidDist*/)
196 void RS_Solid::move(Vector offset)
198 for(int i=0; i<4; ++i)
199 data.corner[i].move(offset);
204 void RS_Solid::rotate(Vector center, double angle)
206 for(int i=0; i<4; ++i)
207 data.corner[i].rotate(center, angle);
212 void RS_Solid::scale(Vector center, Vector factor)
214 for(int i=0; i<4; ++i)
215 data.corner[i].scale(center, factor);
220 void RS_Solid::mirror(Vector axisPoint1, Vector axisPoint2)
222 for(int i=0; i<4; ++i)
223 data.corner[i].mirror(axisPoint1, axisPoint2);
228 void RS_Solid::draw(PaintInterface * painter, GraphicView * view, double /*patternOffset*/)
230 if (!painter || !view)
233 RS_SolidData d = getData();
236 painter->fillTriangle(view->toGui(getCorner(0)), view->toGui(getCorner(1)),
237 view->toGui(getCorner(2)));
241 * Dumps the point's data to stdout.
243 std::ostream & operator<<(std::ostream & os, const RS_Solid & p)
245 os << " Solid: " << p.getData() << "\n";