Sketch.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) Jürgen Riegel          (juergen.riegel@web.de) 2010     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
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     // from base class
00048     virtual unsigned int getMemSize(void) const;
00049     virtual void Save(Base::Writer &/*writer*/) const;
00050     virtual void Restore(Base::XMLReader &/*reader*/);
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, // 1 Point(start), 2 Parameters(x,y)
00180         Line    = 2, // 2 Points(start,end), 4 Parameters(x1,y1,x2,y2)
00181         Arc     = 3, // 3 Points(start,end,mid), (4)+5 Parameters((x1,y1,x2,y2),x,y,r,a1,a2)
00182         Circle  = 4, // 1 Point(mid), 3 Parameters(x,y,r)
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;             // pointer to the geometry
00194         GeoType           type;            // type of the geometry
00195         bool              construction;    // defines if this element is a construction element
00196         int               index;           // index in the corresponding storage vector (Lines, Arcs, Circles, ...)
00197         int               startPointId;    // index in Points of the start point of this geometry
00198         int               midPointId;      // index in Points of the start point of this geometry
00199         int               endPointId;      // index in Points of the end point of this geometry
00200     };
00201 
00202     std::vector<GeoDef> Geoms;
00203     GCS::System GCSsys;
00204     int ConstraintsCounter;
00205     std::vector<int> Conflicting;
00206 
00207     // solving parameters
00208     std::vector<double*> Parameters;    // with memory allocation
00209     std::vector<double*> FixParameters; // with memory allocation
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 } //namespace Part
00224 
00225 
00226 #endif // SKETCHER_SKETCH_H

Generated on Wed Nov 23 19:00:37 2011 for FreeCAD by  doxygen 1.6.1