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. :-)
20 #include "graphicview.h"
21 #include "paintinterface.h"
24 * Default constructor.
26 Solid::Solid(EntityContainer * parent, const SolidData & d):
27 AtomicEntity(parent), data(d)
32 /*virtual*/ Entity * Solid::clone()
34 Solid * s = new Solid(*this);
39 /** @return RS_ENTITY_POINT */
40 /*virtual*/ RS2::EntityType Solid::rtti() const
42 return RS2::EntitySolid;
46 * @return Start point of the entity.
48 /*virtual*/ Vector Solid::getStartpoint() const
54 * @return End point of the entity.
56 /*virtual*/ Vector Solid::getEndpoint() const
61 /** @return Copy of data that defines the point. */
62 SolidData Solid::getData() const
67 /** @return true if this is a triangle. */
68 bool Solid::isTriangle()
70 return !data.corner[3].valid;
74 * @return Corner number 'num'.
76 Vector Solid::getCorner(int num)
78 if (num >= 0 && num < 4)
79 return data.corner[num];
82 DEBUG->print("Illegal corner requested from Solid", Debug::D_WARNING);
88 * Shapes this Solid into a standard arrow (used in dimensions).
90 * @param point The point the arrow points to.
91 * @param angle Direction of the arrow.
92 * @param arrowSize Size of arrow (length).
94 void Solid::shapeArrow(const Vector & point, double angle, double arrowSize)
96 double cosv1, sinv1, cosv2, sinv2;
97 double arrowSide = arrowSize / cos(0.165);
99 cosv1 = cos(angle + 0.165) * arrowSide;
100 sinv1 = sin(angle + 0.165) * arrowSide;
101 cosv2 = cos(angle - 0.165) * arrowSide;
102 sinv2 = sin(angle - 0.165) * arrowSide;
104 data.corner[0] = point;
105 data.corner[1] = Vector(point.x - cosv1, point.y - sinv1);
106 data.corner[2] = Vector(point.x - cosv2, point.y - sinv2);
107 data.corner[3] = Vector(false);
112 void Solid::calculateBorders()
116 for(int i=0; i<4; ++i)
118 if (data.corner[i].valid)
120 minV = Vector::minimum(minV, data.corner[i]);
121 maxV = Vector::maximum(maxV, data.corner[i]);
126 Vector Solid::getNearestEndpoint(const Vector & coord, double * dist)
128 double minDist = RS_MAXDOUBLE;
132 for(int i=0; i<4; ++i)
134 if (data.corner[i].valid)
136 curDist = data.corner[i].distanceTo(coord);
138 if (curDist < minDist)
140 ret = data.corner[i];
153 * @todo Implement this.
155 Vector Solid::getNearestPointOnEntity(const Vector & /*coord*/, bool /*onEntity*/,
156 double * /*dist*/, Entity ** /*entity*/)
162 Vector Solid::getNearestCenter(const Vector & /*coord*/, double * dist)
165 *dist = RS_MAXDOUBLE;
167 return Vector(false);
170 Vector Solid::getNearestMiddle(const Vector & /*coord*/, double * dist)
173 *dist = RS_MAXDOUBLE;
175 return Vector(false);
178 Vector Solid::getNearestDist(double /*distance*/, const Vector & /*coord*/, double * dist)
181 *dist = RS_MAXDOUBLE;
183 return Vector(false);
187 * @return Distance from one of the boundry lines of this solid to given point.
191 double Solid::getDistanceToPoint(const Vector & /*coord*/, Entity ** /*entity*/,
192 RS2::ResolveLevel /*level*/, double /*solidDist*/)
197 void Solid::move(Vector offset)
199 for(int i=0; i<4; ++i)
200 data.corner[i].move(offset);
205 void Solid::rotate(Vector center, double angle)
207 for(int i=0; i<4; ++i)
208 data.corner[i].rotate(center, angle);
213 void Solid::scale(Vector center, Vector factor)
215 for(int i=0; i<4; ++i)
216 data.corner[i].scale(center, factor);
221 void Solid::mirror(Vector axisPoint1, Vector axisPoint2)
223 for(int i=0; i<4; ++i)
224 data.corner[i].mirror(axisPoint1, axisPoint2);
229 void Solid::draw(PaintInterface * painter, GraphicView * view, double /*patternOffset*/)
231 if (!painter || !view)
234 SolidData d = getData();
237 painter->fillTriangle(view->toGui(getCorner(0)), view->toGui(getCorner(1)),
238 view->toGui(getCorner(2)));
242 * Dumps the point's data to stdout.
244 std::ostream & operator<<(std::ostream & os, const Solid & p)
246 os << " Solid: " << p.getData() << "\n";