/
Sketch.h
235 lines (206 loc) · 11 KB
/
Sketch.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
/***************************************************************************
* Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2010 *
* *
* 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 SKETCHER_SKETCH_H
#define SKETCHER_SKETCH_H
#include <App/PropertyStandard.h>
#include <App/PropertyFile.h>
#include <Mod/Part/App/Geometry.h>
#include <Mod/Part/App/TopoShape.h>
#include "Constraint.h"
#include "freegcs/GCS.h"
#include <Base/Persistence.h>
namespace Sketcher
{
class SketcherExport Sketch :public Base::Persistence
{
TYPESYSTEM_HEADER();
public:
Sketch();
~Sketch();
// from base class
virtual unsigned int getMemSize(void) const;
virtual void Save(Base::Writer &/*writer*/) const;
virtual void Restore(Base::XMLReader &/*reader*/);
/// solve the actual set up sketch
int solve(void);
/// delete all geometry and constraints, leave an empty sketch
void clear(void);
/** set the sketch up with geoms and constraints
*
* returns the degree of freedom of a sketch and calculates a list of
* conflicting constraints
*
* 0 degrees of freedom correspond to a fully constrained sketch
* -1 degrees of freedom correspond to an over-constrained sketch
* positive degrees of freedom correspond to an under-constrained sketch
*
* an over-constrained sketch will always contain conflicting constraints
* a fully constrained or under-constrained sketch may contain conflicting
* constraints or may not
*/
int setUpSketch(const std::vector<Part::Geometry *> &GeoList, const std::vector<Constraint *> &ConstraintList,
int extGeoCount=0);
/// return the actual geometry of the sketch a TopoShape
Part::TopoShape toShape(void) const;
/// add unspecified geometry
int addGeometry(const Part::Geometry *geo, bool fixed=false);
/// add unspecified geometry
int addGeometry(const std::vector<Part::Geometry *> &geo, bool fixed=false);
/// returns the actual geometry
std::vector<Part::Geometry *> extractGeometry(bool withConstrucionElements=true,
bool withExternalElements=false) const;
/// get the geometry as python objects
Py::Tuple getPyGeometry(void) const;
/// retrieves the index of a point
int getPointId(int geoId, PointPos pos) const;
/// retrieves a point
Base::Vector3d getPoint(int geoId, PointPos pos);
bool hasConflicts(void) const { return (Conflicting.size() > 0); }
const std::vector<int> &getConflicting(void) const { return Conflicting; }
bool hasRedundancies(void) const { return (Redundant.size() > 0); }
const std::vector<int> &getRedundant(void) const { return Redundant; }
/** set the datum of a distance or angle constraint to a certain value and solve
* This can cause the solving to fail!
*/
int setDatum(int constrId, double value);
/** initializes a point (or curve) drag by setting the current
* sketch status as a reference
*/
int initMove(int geoId, PointPos pos, bool fine=true);
/** move this point (or curve) to a new location and solve.
* This will introduce some additional weak constraints expressing
* a condition for satisfying the new point location!
* The relative flag permits moving relatively to the current position
*/
int movePoint(int geoId, PointPos pos, Base::Vector3d toPoint, bool relative=false);
/// add dedicated geometry
//@{
/// add a point
int addPoint(const Part::GeomPoint &point, bool fixed=false);
/// add an infinite line
int addLine(const Part::GeomLineSegment &line, bool fixed=false);
/// add a line segment
int addLineSegment(const Part::GeomLineSegment &lineSegment, bool fixed=false);
/// add a arc (circle segment)
int addArc(const Part::GeomArcOfCircle &circleSegment, bool fixed=false);
/// add a circle
int addCircle(const Part::GeomCircle &circle, bool fixed=false);
/// add a ellipse
int addEllipse(const Part::GeomEllipse &ellipse, bool fixed=false);
//@}
/// constraints
//@{
/// add all constraints in the list
int addConstraints(const std::vector<Constraint *> &ConstraintList);
/// add one constraint to the sketch
int addConstraint(const Constraint *constraint);
/// add a fixed coordinate constraint to a point
int addCoordinateXConstraint(int geoId, PointPos pos, double value);
int addCoordinateYConstraint(int geoId, PointPos pos, double value);
/// add a horizontal distance constraint to two points or line ends
int addDistanceXConstraint(int geoId, double value);
int addDistanceXConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double value);
/// add a vertical distance constraint to two points or line ends
int addDistanceYConstraint(int geoId, double value);
int addDistanceYConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double value);
/// add a horizontal constraint to a geometry
int addHorizontalConstraint(int geoId);
int addHorizontalConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2);
/// add a vertical constraint to a geometry
int addVerticalConstraint(int geoId);
int addVerticalConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2);
/// add a coincident constraint to two points of two geometries
int addPointCoincidentConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2);
/// add a length or distance constraint
int addDistanceConstraint(int geoId1, double value);
int addDistanceConstraint(int geoId1, int geoId2, double value);
int addDistanceConstraint(int geoId1, PointPos pos1, int geoId2, double value);
int addDistanceConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double value);
/// add a parallel constraint between two lines
int addParallelConstraint(int geoId1, int geoId2);
/// add a perpendicular constraint between two lines
int addPerpendicularConstraint(int geoId1, int geoId2);
int addPerpendicularConstraint(int geoId1, PointPos pos1, int geoId2);
int addPerpendicularConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2);
/// add a tangency constraint between two geometries
int addTangentConstraint(int geoId1, int geoId2);
int addTangentConstraint(int geoId1, PointPos pos1, int geoId2);
int addTangentConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2);
/// add a radius constraint on a circle or an arc
int addRadiusConstraint(int geoId, double value);
/// add an angle constraint on a line or between two lines
int addAngleConstraint(int geoId, double value);
int addAngleConstraint(int geoId1, int geoId2, double value);
int addAngleConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double value);
/// add an equal length or radius constraints between two lines or between circles and arcs
int addEqualConstraint(int geoId1, int geoId2);
/// add a point on line constraint
int addPointOnObjectConstraint(int geoId1, PointPos pos1, int geoId2);
/// add a symmetric constraint between two points with respect to a line
int addSymmetricConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, int geoId3);
/// add a symmetric constraint between three points, the last point is in the middle of the first two
int addSymmetricConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, int geoId3, PointPos pos3);
//@}
enum GeoType {
None = 0,
Point = 1, // 1 Point(start), 2 Parameters(x,y)
Line = 2, // 2 Points(start,end), 4 Parameters(x1,y1,x2,y2)
Arc = 3, // 3 Points(start,end,mid), (4)+5 Parameters((x1,y1,x2,y2),x,y,r,a1,a2)
Circle = 4, // 1 Point(mid), 3 Parameters(x,y,r)
Ellipse = 5
};
float SolveTime;
protected:
/// container element to store and work with the geometric elements of this sketch
struct GeoDef {
GeoDef() : geo(0),type(None),external(false),index(-1),
startPointId(-1),midPointId(-1),endPointId(-1) {}
Part::Geometry * geo; // pointer to the geometry
GeoType type; // type of the geometry
bool external; // flag for external geometries
int index; // index in the corresponding storage vector (Lines, Arcs, Circles, ...)
int startPointId; // index in Points of the start point of this geometry
int midPointId; // index in Points of the start point of this geometry
int endPointId; // index in Points of the end point of this geometry
};
std::vector<GeoDef> Geoms;
GCS::System GCSsys;
int ConstraintsCounter;
std::vector<int> Conflicting;
std::vector<int> Redundant;
// solving parameters
std::vector<double*> Parameters; // with memory allocation
std::vector<double*> FixParameters; // with memory allocation
std::vector<double> MoveParameters, InitParameters;
std::vector<GCS::Point> Points;
std::vector<GCS::Line> Lines;
std::vector<GCS::Arc> Arcs;
std::vector<GCS::Circle> Circles;
bool isInitMove;
bool isFine;
private:
bool updateGeometry(void);
/// checks if the index bounds and converts negative indices to positive
int checkGeoId(int geoId);
};
} //namespace Part
#endif // SKETCHER_SKETCH_H