/
Geometry.h
269 lines (224 loc) · 7.52 KB
/
Geometry.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/***************************************************************************
* Copyright (c) 2012 Luke Parry <l.parry@warwick.ac.uk> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef TECHDRAW_GEOMETRY_H
#define TECHDRAW_GEOMETRY_H
#include <Base/Tools2D.h>
#include <Base/Vector3D.h>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Wire.hxx>
namespace TechDrawGeometry {
enum ExtractionType { //obs sb vis/hid + hard/smooth/seam/out(edgeClass?)
Plain,
WithHidden,
WithSmooth
};
enum edgeClass {
ecNONE, // Not used, OCC index starts at 1
ecUVISO,
ecOUTLINE,
ecSMOOTH,
ecSEAM,
ecHARD
};
enum GeomType {
NOTDEF,
CIRCLE,
ARCOFCIRCLE,
ELLIPSE,
ARCOFELLIPSE,
BSPLINE,
GENERIC
};
class TechDrawExport BaseGeom
{
public:
BaseGeom();
virtual ~BaseGeom() = default;
public:
GeomType geomType;
ExtractionType extractType; //obs
edgeClass classOfEdge;
bool visible;
bool reversed;
int ref3D;
TopoDS_Edge occEdge; //projected Edge
std::vector<Base::Vector2D> findEndPoints();
Base::Vector2D getStartPoint();
Base::Vector2D getEndPoint();
static BaseGeom* baseFactory(TopoDS_Edge edge);
};
typedef std::vector<BaseGeom *> BaseGeomPtrVector;
class TechDrawExport Circle: public BaseGeom
{
public:
Circle(const TopoDS_Edge &e);
~Circle() = default;
public:
Base::Vector2D center;
double radius;
};
class TechDrawExport Ellipse: public BaseGeom
{
public:
Ellipse(const TopoDS_Edge &e);
~Ellipse() = default;
public:
Base::Vector2D center;
double minor;
double major;
/// Angle between the major axis of the ellipse and the X axis, in radian
double angle;
};
class TechDrawExport AOE: public Ellipse
{
public:
AOE(const TopoDS_Edge &e);
~AOE() = default;
public:
Base::Vector2D startPnt; //TODO: The points are used for drawing, the angles for bounding box calcs - seems redundant
Base::Vector2D endPnt;
Base::Vector2D midPnt;
/// Angle in radian
double startAngle;
/// Angle in radian
double endAngle;
/// Arc is drawn clockwise from startAngle to endAngle if true, counterclockwise if false
bool cw;
bool largeArc;
};
class TechDrawExport AOC: public Circle
{
public:
AOC(const TopoDS_Edge &e);
~AOC() = default;
public:
Base::Vector2D startPnt;
Base::Vector2D endPnt;
Base::Vector2D midPnt;
/// Angle in radian ??angle with horizontal?
double startAngle;
/// Angle in radian
double endAngle;
/// Arc is drawn clockwise from startAngle to endAngle if true, counterclockwise if false
bool cw; // TODO: Instead of this (and similar one in AOE), why not reorder startAngle and endAngle?
bool largeArc;
bool isOnArc(Base::Vector3d v);
bool intersectsArc(Base::Vector3d p1,Base::Vector3d p2);
double distToArc(Base::Vector3d p);
};
/// Handles degree 1 to 3 Bezier segments
/*!
* \todo extend this to higher orders if necessary
*/
struct BezierSegment
{
/// Number of entries in pnts that are valid
int poles;
/// Control points for this segment
/*!
* Note that first and last used points define the endpoints for this
* segment, so when we know that a sequence of BezierSegment objects are
* going to be strung together, then we only need to know the start of
* the first element (or the end of the last element).
*/
Base::Vector2D pnts[4];
};
class TechDrawExport BSpline: public BaseGeom
{
public:
BSpline(const TopoDS_Edge &e);
~BSpline() = default;
public:
bool isLine(void);
std::vector<BezierSegment> segments;
};
class TechDrawExport Generic: public BaseGeom
{
public:
Generic(const TopoDS_Edge &e);
Generic();
~Generic() = default;
std::vector<Base::Vector2D> points;
};
/// Simple Collection of geometric features based on BaseGeom inherited classes in order
class TechDrawExport Wire
{
public:
Wire();
Wire(const TopoDS_Wire &w);
~Wire();
std::vector<BaseGeom *> geoms;
};
/// Simple Collection of geometric features based on BaseGeom inherited classes in order
class TechDrawExport Face
{
public:
Face() = default;
~Face();
std::vector<Wire *> wires;
};
//! 2D Vertex
class TechDrawExport Vertex
{
public:
Vertex(double x, double y);
Vertex(Base::Vector2D v) : Vertex(v.fX,v.fY) {}
~Vertex() = default;
Base::Vector2D pnt;
ExtractionType extractType; //obs?
bool visible;
int ref3D; //obs. never used.
bool isCenter;
TopoDS_Vertex occVertex;
bool isEqual(Vertex* v, double tol);
Base::Vector3d getAs3D(void) {return Base::Vector3d(pnt.fX,pnt.fY,0.0);}
double x() {return pnt.fX;}
double y() {return pnt.fY;}
};
/// Encapsulates some useful static methods
class TechDrawExport GeometryUtils
{
public:
/// Used by nextGeom()
struct TechDrawExport ReturnType {
unsigned int index;
bool reversed;
explicit ReturnType(int i = 0, bool r = false) :
index(i),
reversed(r)
{}
};
/// Find an unused geom starts or ends at atPoint.
/*!
* returns index[1:geoms.size()),reversed [true,false]
*/
static ReturnType nextGeom( Base::Vector2D atPoint,
std::vector<TechDrawGeometry::BaseGeom*> geoms,
std::vector<bool> used,
double tolerance );
//! return a vector of BaseGeom*'s in tail to nose order
static std::vector<BaseGeom*> chainGeoms(std::vector<BaseGeom*> geoms);
};
} //end namespace TechDrawGeometry
#endif //TECHDRAW_GEOMETRY_H