]> Shamusworld >> Repos - architektonas/blob - src/base/rs_solid.h
49120cd00daf19248503640fb4250f28bf0edc64
[architektonas] / src / base / rs_solid.h
1 /****************************************************************************
2 ** $Id: rs_solid.h 2371 2005-04-29 11:44:39Z 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 #ifndef RS_SOLID_H
28 #define RS_SOLID_H
29
30 #include "rs_atomicentity.h"
31 #include "vector.h"
32
33 /**
34  * Holds the data that defines a solid.
35  */
36 class RS_SolidData
37 {
38 public:
39     /**
40      * Default constructor. Leaves the data object uninitialized.
41      */
42     RS_SolidData() {
43         for (int i=0; i<4; ++i) {
44             corner[i] = Vector(false);
45         }
46     }
47
48     /**
49      * Constructor for a solid with 3 corners.
50      */
51     RS_SolidData(const Vector& corner1,
52                  const Vector& corner2,
53                  const Vector& corner3) {
54
55         corner[0] = corner1;
56         corner[1] = corner2;
57         corner[2] = corner3;
58         corner[3] = Vector(false);
59     }
60
61     /**
62      * Constructor for a solid with 4 corners.
63      */
64     RS_SolidData(const Vector& corner1,
65                  const Vector& corner2,
66                  const Vector& corner3,
67                  const Vector& corner4) {
68
69         corner[0] = corner1;
70         corner[1] = corner2;
71         corner[2] = corner3;
72         corner[3] = corner4;
73     }
74
75     friend class RS_Solid;
76
77     friend std::ostream& operator << (std::ostream& os,
78                                       const RS_SolidData& pd) {
79         os << "(";
80         for (int i=0; i<4; i++) {
81             os << pd.corner[i];
82         }
83         os << ")";
84         return os;
85     }
86
87 private:
88     Vector corner[4];
89 };
90
91 /**
92  * Class for a solid entity (e.g. dimension arrows).
93  *
94  * @author Andrew Mustun
95  */
96 class RS_Solid: public RS_AtomicEntity
97 {
98 public:
99     RS_Solid(RS_EntityContainer* parent,
100              const RS_SolidData& d);
101
102     virtual RS_Entity* clone() {
103         RS_Solid* s = new RS_Solid(*this);
104         s->initId();
105         return s;
106     }
107
108     /** @return RS_ENTITY_POINT */
109     virtual RS2::EntityType rtti() const {
110         return RS2::EntitySolid;
111     }
112
113     /**
114          * @return Start point of the entity.
115          */
116     virtual Vector getStartpoint() const {
117         return Vector(false);
118     }
119     /**
120          * @return End point of the entity.
121          */
122     virtual Vector getEndpoint() const {
123         return Vector(false);
124     }
125
126
127     /** @return Copy of data that defines the point. */
128     RS_SolidData getData() const {
129         return data;
130     }
131
132     /** @return true if this is a triangle. */
133     bool isTriangle() {
134         return !data.corner[3].valid;
135     }
136
137     Vector getCorner(int num);
138
139     void shapeArrow(const Vector & point, double angle, double arrowSize);
140
141     virtual Vector getNearestEndpoint(const Vector & coord, double * dist = NULL);
142     virtual Vector getNearestPointOnEntity(const Vector & coord,
143             bool onEntity = true, double * dist = NULL, RS_Entity ** entity = NULL);
144     virtual Vector getNearestCenter(const Vector & coord, double * dist = NULL);
145     virtual Vector getNearestMiddle(const Vector & coord, double * dist = NULL);
146     virtual Vector getNearestDist(double distance, const Vector & coord, double * dist = NULL);
147
148     virtual double getDistanceToPoint(const Vector & coord, RS_Entity ** entity = NULL,
149                 RS2::ResolveLevel level = RS2::ResolveNone, double solidDist = RS_MAXDOUBLE);
150
151     virtual void move(Vector offset);
152     virtual void rotate(Vector center, double angle);
153     virtual void scale(Vector center, Vector factor);
154     virtual void mirror(Vector axisPoint1, Vector axisPoint2);
155
156 //    virtual void draw(RS_Painter* painter, RS_GraphicView* view, double patternOffset=0.0);
157     virtual void draw(PaintInterface * painter, RS_GraphicView * view, double patternOffset = 0.0);
158
159     friend std::ostream & operator<<(std::ostream & os, const RS_Solid & p);
160
161     /** Recalculates the borders of this entity. */
162     virtual void calculateBorders ();
163
164 protected:
165     RS_SolidData data;
166     //Vector point;
167 };
168
169 #endif