00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef SKETCHER_SKETCH_H
00024 #define SKETCHER_SKETCH_H
00025
00026 #include <App/PropertyStandard.h>
00027 #include <App/PropertyFile.h>
00028 #include <Mod/Part/App/Geometry.h>
00029 #include <Mod/Part/App/TopoShape.h>
00030 #include "Constraint.h"
00031
00032 #include "freegcs/GCS.h"
00033
00034 #include <Base/Persistence.h>
00035
00036 namespace Sketcher
00037 {
00038
00039 class SketcherExport Sketch :public Base::Persistence
00040 {
00041 TYPESYSTEM_HEADER();
00042
00043 public:
00044 Sketch();
00045 ~Sketch();
00046
00047
00048 virtual unsigned int getMemSize(void) const;
00049 virtual void Save(Base::Writer &) const;
00050 virtual void Restore(Base::XMLReader &);
00051
00053 int solve(void);
00055 void clear(void);
00057 int setUpSketch(const std::vector<Part::Geometry *> &GeoList,const std::vector<Constraint *> &ConstraintList,
00058 bool withDiagnose=true);
00060 Part::TopoShape toShape(void) const;
00062 int addGeometry(const Part::Geometry *geo);
00064 void addGeometry(const std::vector<Part::Geometry *> &geo);
00066 std::vector<Part::Geometry *> getGeometry(bool withConstrucionElements = true) const;
00068 Py::Tuple getPyGeometry(void) const;
00070 void setConstruction(int geoIndex,bool isConstruction=true);
00071 bool getConstruction(int geoIndex) const;
00072
00074 int getPointId(int geoId, PointPos pos) const;
00076 Base::Vector3d getPoint(int geoId, PointPos pos);
00077
00089 int diagnose(void);
00090 bool hasConflicts(void) const { return (Conflicting.size() > 0); };
00091 const std::vector<int> &getConflicting(void) const { return Conflicting; };
00092
00096 int setDatum(int constrId, double value);
00097
00101 int initMove(int geoIndex, PointPos pos);
00102
00108 int movePoint(int geoIndex, PointPos pos, Base::Vector3d toPoint, bool relative=false);
00109
00111
00112
00113 int addPoint(const Base::Vector3d &point);
00115 int addLine(const Part::GeomLineSegment &line);
00117 int addLineSegment(const Part::GeomLineSegment &lineSegment);
00119 int addArc(const Part::GeomArcOfCircle &circleSegment);
00121 int addCircle(const Part::GeomCircle &circle);
00123 int addEllipse(const Part::GeomEllipse &ellipse);
00125
00126
00128
00129
00130 int addConstraints(const std::vector<Constraint *> &ConstraintList);
00132 int addConstraint(const Constraint *constraint);
00134 int addCoordinateXConstraint(int geoIndex, PointPos pos, double value);
00135 int addCoordinateYConstraint(int geoIndex, PointPos pos, double value);
00137 int addDistanceXConstraint(int geoId, double value);
00138 int addDistanceXConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double value);
00140 int addDistanceYConstraint(int geoId, double value);
00141 int addDistanceYConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double value);
00143 int addHorizontalConstraint(int geoIndex);
00144 int addHorizontalConstraint(int geoIndex1, PointPos pos1, int geoIndex2, PointPos pos2);
00146 int addVerticalConstraint(int geoIndex);
00147 int addVerticalConstraint(int geoIndex1, PointPos pos1, int geoIndex2, PointPos pos2);
00149 int addPointCoincidentConstraint(int geoIndex1, PointPos pos1, int geoIndex2, PointPos pos2);
00151 int addDistanceConstraint(int geoIndex1, double value);
00152 int addDistanceConstraint(int geoIndex1, int geoIndex2, double value);
00153 int addDistanceConstraint(int geoIndex1, PointPos pos1, int geoIndex2, double value);
00154 int addDistanceConstraint(int geoIndex1, PointPos pos1, int geoIndex2, PointPos pos2, double value);
00156 int addParallelConstraint(int geoIndex1, int geoIndex2);
00158 int addPerpendicularConstraint(int geoIndex1, int geoIndex2);
00160 int addTangentConstraint(int geoIndex1, int geoIndex2);
00161 int addTangentConstraint(int geoIndex1, PointPos pos1, int geoIndex2);
00162 int addTangentConstraint(int geoIndex1, PointPos pos1, int geoIndex2, PointPos pos2);
00164 int addRadiusConstraint(int geoIndex, double value);
00166 int addAngleConstraint(int geoIndex, double value);
00167 int addAngleConstraint(int geoIndex1, int geoIndex2, double value);
00168 int addAngleConstraint(int geoIndex1, PointPos pos1, int geoIndex2, PointPos pos2, double value);
00170 int addEqualConstraint(int geoIndex1, int geoIndex2);
00172 int addPointOnObjectConstraint(int geoId1, PointPos pos1, int geoId2);
00174 int addSymmetricConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, int geoId3);
00176
00177 enum GeoType {
00178 None = 0,
00179 Point = 1,
00180 Line = 2,
00181 Arc = 3,
00182 Circle = 4,
00183 Ellipse = 5
00184 };
00185
00186 float SolveTime;
00187
00188 protected:
00190 struct GeoDef {
00191 GeoDef() : geo(0),type(None),construction(false),index(-1),
00192 startPointId(-1),midPointId(-1),endPointId(-1) {}
00193 Part::Geometry * geo;
00194 GeoType type;
00195 bool construction;
00196 int index;
00197 int startPointId;
00198 int midPointId;
00199 int endPointId;
00200 };
00201
00202 std::vector<GeoDef> Geoms;
00203 GCS::System GCSsys;
00204 int ConstraintsCounter;
00205 std::vector<int> Conflicting;
00206
00207
00208 std::vector<double*> Parameters;
00209 std::vector<double*> FixParameters;
00210 std::vector<double> MoveParameters, InitParameters;
00211 std::vector<GCS::Point> Points;
00212 std::vector<GCS::Line> Lines;
00213 std::vector<GCS::Arc> Arcs;
00214 std::vector<GCS::Circle> Circles;
00215
00216 bool isInitMove;
00217
00218 private:
00219 bool updateGeometry(void);
00220
00221 };
00222
00223 }
00224
00225
00226 #endif // SKETCHER_SKETCH_H