1 /****************************************************************************
2 ** $Id: rs_solid.cpp 1938 2004-12-09 23:09:53Z andrew $
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
6 ** This file is part of the qcadlib Library project.
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.
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.
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.
20 ** See http://www.ribbonsoft.com for further details.
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
25 **********************************************************************/
29 #include "rs_graphicview.h"
30 //#include "rs_painter.h"
31 #include "paintintf.h"
34 * Default constructor.
36 RS_Solid::RS_Solid(RS_EntityContainer* parent,
37 const RS_SolidData& d)
38 :RS_AtomicEntity(parent), data(d) {
45 * @return Corner number 'num'.
47 Vector RS_Solid::getCorner(int num) {
48 if (num>=0 && num<4) {
49 return data.corner[num];
51 RS_DEBUG->print("Illegal corner requested from Solid",
60 * Shapes this Solid into a standard arrow (used in dimensions).
62 * @param point The point the arrow points to.
63 * @param angle Direction of the arrow.
64 * @param arrowSize Size of arrow (length).
66 void RS_Solid::shapeArrow(const Vector& point,
70 double cosv1, sinv1, cosv2, sinv2;
71 double arrowSide = arrowSize/cos(0.165);
73 cosv1 = cos(angle+0.165)*arrowSide;
74 sinv1 = sin(angle+0.165)*arrowSide;
75 cosv2 = cos(angle-0.165)*arrowSide;
76 sinv2 = sin(angle-0.165)*arrowSide;
78 data.corner[0] = point;
79 data.corner[1] = Vector(point.x - cosv1, point.y - sinv1);
80 data.corner[2] = Vector(point.x - cosv2, point.y - sinv2);
81 data.corner[3] = Vector(false);
88 void RS_Solid::calculateBorders() {
91 for (int i=0; i<4; ++i) {
92 if (data.corner[i].valid) {
93 minV = Vector::minimum(minV, data.corner[i]);
94 maxV = Vector::maximum(maxV, data.corner[i]);
101 Vector RS_Solid::getNearestEndpoint(const Vector& coord, double* dist) {
103 double minDist = RS_MAXDOUBLE;
107 for (int i=0; i<4; ++i) {
108 if (data.corner[i].valid) {
109 curDist = data.corner[i].distanceTo(coord);
110 if (curDist<minDist) {
111 ret = data.corner[i];
127 * @todo Implement this.
129 Vector RS_Solid::getNearestPointOnEntity(const Vector& /*coord*/,
130 bool /*onEntity*/, double* /*dist*/, RS_Entity** /*entity*/) {
138 Vector RS_Solid::getNearestCenter(const Vector& /*coord*/,
142 *dist = RS_MAXDOUBLE;
145 return Vector(false);
150 Vector RS_Solid::getNearestMiddle(const Vector& /*coord*/,
153 *dist = RS_MAXDOUBLE;
155 return Vector(false);
160 Vector RS_Solid::getNearestDist(double /*distance*/,
161 const Vector& /*coord*/,
164 *dist = RS_MAXDOUBLE;
166 return Vector(false);
172 * @return Distance from one of the boundry lines of this solid to given point.
176 double RS_Solid::getDistanceToPoint(const Vector& /*coord*/,
177 RS_Entity** /*entity*/,
178 RS2::ResolveLevel /*level*/,
179 double /*solidDist*/) {
185 void RS_Solid::move(Vector offset) {
186 for (int i=0; i<4; ++i) {
187 data.corner[i].move(offset);
194 void RS_Solid::rotate(Vector center, double angle) {
195 for (int i=0; i<4; ++i) {
196 data.corner[i].rotate(center, angle);
203 void RS_Solid::scale(Vector center, Vector factor) {
204 for (int i=0; i<4; ++i) {
205 data.corner[i].scale(center, factor);
212 void RS_Solid::mirror(Vector axisPoint1, Vector axisPoint2) {
213 for (int i=0; i<4; ++i) {
214 data.corner[i].mirror(axisPoint1, axisPoint2);
219 //void RS_Solid::draw(RS_Painter* painter, RS_GraphicView* view, double /*patternOffset*/)
220 void RS_Solid::draw(PaintInterface * painter, RS_GraphicView * view, double /*patternOffset*/)
222 if (painter == NULL || view == NULL)
225 RS_SolidData d = getData();
228 painter->fillTriangle(view->toGui(getCorner(0)), view->toGui(getCorner(1)),
229 view->toGui(getCorner(2)));
233 * Dumps the point's data to stdout.
235 std::ostream & operator<<(std::ostream & os, const RS_Solid & p)
237 os << " Solid: " << p.getData() << "\n";