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
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 06/02/2010 Added this text. :-)
17 #include "rs_graphicview.h"
18 #include "paintintf.h"
21 * Default constructor.
23 RS_Solid::RS_Solid(RS_EntityContainer * parent, const RS_SolidData& d):
24 RS_AtomicEntity(parent), data(d)
30 * @return Corner number 'num'.
32 Vector RS_Solid::getCorner(int num)
34 if (num >= 0 && num < 4)
36 return data.corner[num];
40 RS_DEBUG->print("Illegal corner requested from Solid", RS_Debug::D_WARNING);
46 * Shapes this Solid into a standard arrow (used in dimensions).
48 * @param point The point the arrow points to.
49 * @param angle Direction of the arrow.
50 * @param arrowSize Size of arrow (length).
52 void RS_Solid::shapeArrow(const Vector & point, double angle, double arrowSize)
54 double cosv1, sinv1, cosv2, sinv2;
55 double arrowSide = arrowSize/cos(0.165);
57 cosv1 = cos(angle+0.165)*arrowSide;
58 sinv1 = sin(angle+0.165)*arrowSide;
59 cosv2 = cos(angle-0.165)*arrowSide;
60 sinv2 = sin(angle-0.165)*arrowSide;
62 data.corner[0] = point;
63 data.corner[1] = Vector(point.x - cosv1, point.y - sinv1);
64 data.corner[2] = Vector(point.x - cosv2, point.y - sinv2);
65 data.corner[3] = Vector(false);
70 void RS_Solid::calculateBorders()
74 for(int i=0; i<4; ++i)
76 if (data.corner[i].valid)
78 minV = Vector::minimum(minV, data.corner[i]);
79 maxV = Vector::maximum(maxV, data.corner[i]);
84 Vector RS_Solid::getNearestEndpoint(const Vector & coord, double * dist)
86 double minDist = RS_MAXDOUBLE;
90 for (int i=0; i<4; ++i)
92 if (data.corner[i].valid)
94 curDist = data.corner[i].distanceTo(coord);
96 if (curDist < minDist)
111 * @todo Implement this.
113 Vector RS_Solid::getNearestPointOnEntity(const Vector & /*coord*/,
114 bool /*onEntity*/, double * /*dist*/, RS_Entity ** /*entity*/)
120 Vector RS_Solid::getNearestCenter(const Vector & /*coord*/, double * dist)
123 *dist = RS_MAXDOUBLE;
125 return Vector(false);
128 Vector RS_Solid::getNearestMiddle(const Vector & /*coord*/, double * dist)
131 *dist = RS_MAXDOUBLE;
133 return Vector(false);
136 Vector RS_Solid::getNearestDist(double /*distance*/, const Vector & /*coord*/, double * dist)
139 *dist = RS_MAXDOUBLE;
141 return Vector(false);
145 * @return Distance from one of the boundry lines of this solid to given point.
149 double RS_Solid::getDistanceToPoint(const Vector & /*coord*/, RS_Entity ** /*entity*/,
150 RS2::ResolveLevel /*level*/, double /*solidDist*/)
155 void RS_Solid::move(Vector offset)
157 for(int i=0; i<4; ++i)
158 data.corner[i].move(offset);
163 void RS_Solid::rotate(Vector center, double angle)
165 for(int i=0; i<4; ++i)
166 data.corner[i].rotate(center, angle);
171 void RS_Solid::scale(Vector center, Vector factor)
173 for(int i=0; i<4; ++i)
174 data.corner[i].scale(center, factor);
179 void RS_Solid::mirror(Vector axisPoint1, Vector axisPoint2)
181 for(int i=0; i<4; ++i)
182 data.corner[i].mirror(axisPoint1, axisPoint2);
187 //void RS_Solid::draw(RS_Painter* painter, RS_GraphicView* view, double /*patternOffset*/)
188 void RS_Solid::draw(PaintInterface * painter, RS_GraphicView * view, double /*patternOffset*/)
190 if (painter == NULL || view == NULL)
193 RS_SolidData d = getData();
196 painter->fillTriangle(view->toGui(getCorner(0)), view->toGui(getCorner(1)),
197 view->toGui(getCorner(2)));
201 * Dumps the point's data to stdout.
203 std::ostream & operator<<(std::ostream & os, const RS_Solid & p)
205 os << " Solid: " << p.getData() << "\n";