+ preparation for external geometry constraints in the sketcher

+ change value of H_Axis and V_Axis constants
+ external Geometry transferred in reverse order from SketchObject to Sketch
+ replace construction property with external property in GeoDef
+ support negative geometry indices in the Sketch class
+ whitespace and variables naming improvements, typo fixes


git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5340 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
logari81 2011-12-24 00:25:34 +00:00
parent 95c6daa631
commit 3c9053a599
8 changed files with 212 additions and 189 deletions

View File

@ -51,8 +51,8 @@
using namespace Part;
const int Part2DObject::H_Axis = -2;
const int Part2DObject::V_Axis = -3;
const int Part2DObject::H_Axis = -1;
const int Part2DObject::V_Axis = -2;
PROPERTY_SOURCE(Part::Part2DObject, Part::Feature)

View File

@ -62,17 +62,6 @@ TYPESYSTEM_SOURCE(Sketcher::Sketch, Base::Persistence)
Sketch::Sketch()
: GCSsys(), ConstraintsCounter(0), isInitMove(false)
{
//// add the root point at 0,0
//addPoint(Base::Vector3d());
//// add x,y axis
//Part::GeomLineSegment axis;
//axis.setPoints(Base::Vector3d(0,0,0),Base::Vector3d(100,0,0));
//addLineSegment(axis);
//axis.setPoints(Base::Vector3d(0,0,0),Base::Vector3d(0,100,0));
//addLineSegment(axis);
// set them to construction elements
}
Sketch::~Sketch()
@ -113,13 +102,18 @@ int Sketch::setUpSketch(const std::vector<Part::Geometry *> &GeoList, const std:
return setUpSketch(GeoList, std::vector<Part::Geometry *>(0), ConstraintList);
}
int Sketch::setUpSketch(const std::vector<Part::Geometry *> &GeoList, const std::vector<Part::Geometry *> &FixedGeoList,
int Sketch::setUpSketch(const std::vector<Part::Geometry *> &GeoList, const std::vector<Part::Geometry *> &ExternalGeoList,
const std::vector<Constraint *> &ConstraintList, bool withDiagnose)
{
clear();
addGeometry(GeoList);
addGeometry(FixedGeoList, true);
int extStart=Geoms.size();
std::vector<Part::Geometry *> reversedExternalGeoList(ExternalGeoList.rbegin(),ExternalGeoList.rend());
addGeometry(reversedExternalGeoList, true);
int extEnd=Geoms.size()-1;
for (int i=extStart; i <= extEnd; i++)
Geoms[i].external = true;
// The Geoms list might be empty after an undo/redo
if (!Geoms.empty())
@ -158,15 +152,15 @@ const char* nameByType(Sketch::GeoType type)
int Sketch::addGeometry(const Part::Geometry *geo, bool fixed)
{
if (geo->getTypeId()== GeomLineSegment::getClassTypeId()) { // add a line
if (geo->getTypeId() == GeomLineSegment::getClassTypeId()) { // add a line
const GeomLineSegment *lineSeg = dynamic_cast<const GeomLineSegment*>(geo);
// create the definition struct for that geom
return addLineSegment(*lineSeg, fixed);
} else if (geo->getTypeId()== GeomCircle::getClassTypeId()) { // add a circle
} else if (geo->getTypeId() == GeomCircle::getClassTypeId()) { // add a circle
const GeomCircle *circle = dynamic_cast<const GeomCircle*>(geo);
// create the definition struct for that geom
return addCircle(*circle, fixed);
} else if (geo->getTypeId()== GeomArcOfCircle::getClassTypeId()) { // add an arc
} else if (geo->getTypeId() == GeomArcOfCircle::getClassTypeId()) { // add an arc
const GeomArcOfCircle *aoc = dynamic_cast<const GeomArcOfCircle*>(geo);
// create the definition struct for that geom
return addArc(*aoc, fixed);
@ -178,7 +172,7 @@ int Sketch::addGeometry(const Part::Geometry *geo, bool fixed)
void Sketch::addGeometry(const std::vector<Part::Geometry *> &geo, bool fixed)
{
for (std::vector<Part::Geometry *>::const_iterator it = geo.begin();it!=geo.end();++it)
for (std::vector<Part::Geometry *>::const_iterator it=geo.begin(); it != geo.end(); ++it)
addGeometry(*it, fixed);
}
@ -190,7 +184,6 @@ int Sketch::addPoint(const Base::Vector3d &newPoint, bool fixed)
GeoDef def;
def.geo = 0;
def.type = Point;
def.construction = false;
// set the parameter for the solver
params.push_back(new double(newPoint.x));
@ -227,7 +220,6 @@ int Sketch::addLineSegment(const Part::GeomLineSegment &lineSegment, bool fixed)
GeoDef def;
def.geo = lineSeg;
def.type = Line;
def.construction = lineSeg->Construction;
// get the points from the line
Base::Vector3d start = lineSeg->getStartPoint();
@ -276,7 +268,6 @@ int Sketch::addArc(const Part::GeomArcOfCircle &circleSegment, bool fixed)
GeoDef def;
def.geo = aoc;
def.type = Arc;
def.construction = aoc->Construction;
Base::Vector3d center = aoc->getCenter();
Base::Vector3d startPnt = aoc->getStartPoint();
@ -347,7 +338,6 @@ int Sketch::addCircle(const Part::GeomCircle &cir, bool fixed)
GeoDef def;
def.geo = circ;
def.type = Circle;
def.construction = circ->Construction;
Base::Vector3d center = circ->getCenter();
double radius = circ->getRadius();
@ -387,15 +377,14 @@ int Sketch::addEllipse(const Part::GeomEllipse &ellipse, bool fixed)
return Geoms.size()-1;
}
std::vector<Part::Geometry *> Sketch::getGeometry(bool withConstrucionElements) const
std::vector<Part::Geometry *> Sketch::extractGeometry(bool withConstrucionElements,
bool withExternalElements) const
{
std::vector<Part::Geometry *> temp(Geoms.size());
int i=0;
std::vector<GeoDef>::const_iterator it=Geoms.begin();
for (;it!=Geoms.end();++it,i++)
if (!it->construction || withConstrucionElements)
temp[i] = it->geo->clone();
std::vector<Part::Geometry *> temp;
temp.reserve(Geoms.size());
for (std::vector<GeoDef>::const_iterator it=Geoms.begin(); it != Geoms.end(); ++it)
if ((!it->external || withExternalElements) && (!it->geo->Construction || withConstrucionElements))
temp.push_back(it->geo->clone());
return temp;
}
@ -404,9 +393,7 @@ Py::Tuple Sketch::getPyGeometry(void) const
{
Py::Tuple tuple(Geoms.size());
int i=0;
std::vector<GeoDef>::const_iterator it=Geoms.begin();
for (;it!=Geoms.end();++it,i++) {
for (std::vector<GeoDef>::const_iterator it=Geoms.begin(); it != Geoms.end(); ++it, i++) {
if (it->type == Line) {
GeomLineSegment *lineSeg = dynamic_cast<GeomLineSegment*>(it->geo->clone());
tuple[i] = Py::asObject(new LinePy(lineSeg));
@ -429,18 +416,12 @@ Py::Tuple Sketch::getPyGeometry(void) const
return tuple;
}
void Sketch::setConstruction(int geoId, bool isConstruction)
int Sketch::checkGeoId(int geoId)
{
assert(geoId < int(Geoms.size()));
Geoms[geoId].construction = isConstruction;
}
bool Sketch::getConstruction(int geoId) const
{
assert(geoId < int(Geoms.size()));
return Geoms[geoId].construction;
if (geoId < 0)
geoId += Geoms.size();
assert(geoId >= 0 && geoId < int(Geoms.size()));
return geoId;
}
// constraint adding ==========================================================
@ -561,6 +542,8 @@ int Sketch::addConstraints(const std::vector<Constraint *> &ConstraintList)
int Sketch::addCoordinateXConstraint(int geoId, PointPos pos, double value)
{
geoId = checkGeoId(geoId);
int pointId = getPointId(geoId, pos);
if (pointId >= 0 && pointId < int(Points.size())) {
@ -576,6 +559,8 @@ int Sketch::addCoordinateXConstraint(int geoId, PointPos pos, double value)
int Sketch::addCoordinateYConstraint(int geoId, PointPos pos, double value)
{
geoId = checkGeoId(geoId);
int pointId = getPointId(geoId, pos);
if (pointId >= 0 && pointId < int(Points.size())) {
@ -591,7 +576,8 @@ int Sketch::addCoordinateYConstraint(int geoId, PointPos pos, double value)
int Sketch::addDistanceXConstraint(int geoId, double value)
{
assert(geoId < int(Geoms.size()));
geoId = checkGeoId(geoId);
if (Geoms[geoId].type != Line)
return -1;
@ -607,7 +593,8 @@ int Sketch::addDistanceXConstraint(int geoId, double value)
int Sketch::addDistanceYConstraint(int geoId, double value)
{
assert(geoId < int(Geoms.size()));
geoId = checkGeoId(geoId);
if (Geoms[geoId].type != Line)
return -1;
@ -623,6 +610,9 @@ int Sketch::addDistanceYConstraint(int geoId, double value)
int Sketch::addDistanceXConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double value)
{
geoId1 = checkGeoId(geoId1);
geoId2 = checkGeoId(geoId2);
int pointId1 = getPointId(geoId1, pos1);
int pointId2 = getPointId(geoId2, pos2);
@ -643,6 +633,9 @@ int Sketch::addDistanceXConstraint(int geoId1, PointPos pos1, int geoId2, PointP
int Sketch::addDistanceYConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double value)
{
geoId1 = checkGeoId(geoId1);
geoId2 = checkGeoId(geoId2);
int pointId1 = getPointId(geoId1, pos1);
int pointId2 = getPointId(geoId2, pos2);
@ -664,7 +657,8 @@ int Sketch::addDistanceYConstraint(int geoId1, PointPos pos1, int geoId2, PointP
// horizontal line constraint
int Sketch::addHorizontalConstraint(int geoId)
{
assert(geoId < int(Geoms.size()));
geoId = checkGeoId(geoId);
if (Geoms[geoId].type != Line)
return -1;
@ -677,6 +671,9 @@ int Sketch::addHorizontalConstraint(int geoId)
// two points on a horizontal line constraint
int Sketch::addHorizontalConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2)
{
geoId1 = checkGeoId(geoId1);
geoId2 = checkGeoId(geoId2);
int pointId1 = getPointId(geoId1, pos1);
int pointId2 = getPointId(geoId2, pos2);
@ -694,7 +691,8 @@ int Sketch::addHorizontalConstraint(int geoId1, PointPos pos1, int geoId2, Point
// vertical line constraint
int Sketch::addVerticalConstraint(int geoId)
{
assert(geoId < int(Geoms.size()));
geoId = checkGeoId(geoId);
if (Geoms[geoId].type != Line)
return -1;
@ -707,6 +705,9 @@ int Sketch::addVerticalConstraint(int geoId)
// two points on a vertical line constraint
int Sketch::addVerticalConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2)
{
geoId1 = checkGeoId(geoId1);
geoId2 = checkGeoId(geoId2);
int pointId1 = getPointId(geoId1, pos1);
int pointId2 = getPointId(geoId2, pos2);
@ -723,6 +724,9 @@ int Sketch::addVerticalConstraint(int geoId1, PointPos pos1, int geoId2, PointPo
int Sketch::addPointCoincidentConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2)
{
geoId1 = checkGeoId(geoId1);
geoId2 = checkGeoId(geoId2);
int pointId1 = getPointId(geoId1, pos1);
int pointId2 = getPointId(geoId2, pos2);
@ -742,8 +746,9 @@ int Sketch::addPointCoincidentConstraint(int geoId1, PointPos pos1, int geoId2,
int Sketch::addParallelConstraint(int geoId1, int geoId2)
{
assert(geoId1 < int(Geoms.size()));
assert(geoId2 < int(Geoms.size()));
geoId1 = checkGeoId(geoId1);
geoId2 = checkGeoId(geoId2);
if (Geoms[geoId1].type != Line ||
Geoms[geoId2].type != Line)
return -1;
@ -757,8 +762,8 @@ int Sketch::addParallelConstraint(int geoId1, int geoId2)
int Sketch::addPerpendicularConstraint(int geoId1, int geoId2)
{
assert(geoId1 < int(Geoms.size()));
assert(geoId2 < int(Geoms.size()));
geoId1 = checkGeoId(geoId1);
geoId2 = checkGeoId(geoId2);
if (Geoms[geoId2].type == Line) {
if (Geoms[geoId1].type == Line) {
@ -801,8 +806,8 @@ int Sketch::addTangentConstraint(int geoId1, int geoId2)
// Circle1, Circle2/Arc2 (not implemented yet)
// 3) Arc1, Line2 (converted to case #1)
// Arc1, Circle2/Arc2 (not implemented yet)
assert(geoId1 < int(Geoms.size()));
assert(geoId2 < int(Geoms.size()));
geoId1 = checkGeoId(geoId1);
geoId2 = checkGeoId(geoId2);
if (Geoms[geoId2].type == Line) {
if (Geoms[geoId1].type == Line) {
@ -847,9 +852,10 @@ int Sketch::addTangentConstraint(int geoId1, PointPos pos1, int geoId2)
// 4) Arc1, start/end, Line2
// 5) Arc1, start/end, Circle2 (not implemented yet)
// 6) Arc1, start/end, Arc2 (not implemented yet)
geoId1 = checkGeoId(geoId1);
geoId2 = checkGeoId(geoId2);
int pointId1 = getPointId(geoId1, pos1);
assert(geoId2 < int(Geoms.size()));
if (pointId1 < 0 || pointId1 >= int(Points.size()))
return addTangentConstraint(geoId1, geoId2);
@ -912,6 +918,8 @@ int Sketch::addTangentConstraint(int geoId1, PointPos pos1, int geoId2, PointPos
// 2) Line1, start/end/mid, Arc2, start/end
// 3) Arc1, start/end, Line2, start/end/mid (converted to case #2)
// 4) Arc1, start/end, Arc2, start/end (not implemented yet)
geoId1 = checkGeoId(geoId1);
geoId2 = checkGeoId(geoId2);
int pointId1 = getPointId(geoId1, pos1);
int pointId2 = getPointId(geoId2, pos2);
@ -1006,7 +1014,8 @@ int Sketch::addTangentConstraint(int geoId1, PointPos pos1, int geoId2, PointPos
// line length constraint
int Sketch::addDistanceConstraint(int geoId, double value)
{
assert(geoId < int(Geoms.size()));
geoId = checkGeoId(geoId);
if (Geoms[geoId].type != Line)
return -1;
@ -1024,8 +1033,8 @@ int Sketch::addDistanceConstraint(int geoId, double value)
// line to line distance constraint
int Sketch::addDistanceConstraint(int geoId1, int geoId2, double value)
{
assert(geoId1 < int(Geoms.size()));
assert(geoId2 < int(Geoms.size()));
geoId1 = checkGeoId(geoId1);
geoId2 = checkGeoId(geoId2);
//assert(Geoms[geoId1].type == Line);
//assert(Geoms[geoId2].type == Line);
@ -1038,8 +1047,11 @@ int Sketch::addDistanceConstraint(int geoId1, int geoId2, double value)
// point to line distance constraint
int Sketch::addDistanceConstraint(int geoId1, PointPos pos1, int geoId2, double value)
{
geoId1 = checkGeoId(geoId1);
geoId2 = checkGeoId(geoId2);
int pointId1 = getPointId(geoId1, pos1);
assert(geoId2 < int(Geoms.size()));
if (Geoms[geoId2].type != Line)
return -1;
@ -1061,6 +1073,9 @@ int Sketch::addDistanceConstraint(int geoId1, PointPos pos1, int geoId2, double
// point to point distance constraint
int Sketch::addDistanceConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double value)
{
geoId1 = checkGeoId(geoId1);
geoId2 = checkGeoId(geoId2);
int pointId1 = getPointId(geoId1, pos1);
int pointId2 = getPointId(geoId2, pos2);
@ -1082,7 +1097,7 @@ int Sketch::addDistanceConstraint(int geoId1, PointPos pos1, int geoId2, PointPo
int Sketch::addRadiusConstraint(int geoId, double value)
{
assert(geoId < int(Geoms.size()));
geoId = checkGeoId(geoId);
if (Geoms[geoId].type == Circle) {
GCS::Circle &c = Circles[Geoms[geoId].index];
@ -1108,7 +1123,8 @@ int Sketch::addRadiusConstraint(int geoId, double value)
// line orientation angle constraint
int Sketch::addAngleConstraint(int geoId, double value)
{
assert(geoId < int(Geoms.size()));
geoId = checkGeoId(geoId);
if (Geoms[geoId].type != Line)
return -1;
@ -1126,8 +1142,8 @@ int Sketch::addAngleConstraint(int geoId, double value)
// line to line angle constraint
int Sketch::addAngleConstraint(int geoId1, int geoId2, double value)
{
assert(geoId1 < int(Geoms.size()));
assert(geoId2 < int(Geoms.size()));
geoId1 = checkGeoId(geoId1);
geoId2 = checkGeoId(geoId2);
if (Geoms[geoId1].type != Line ||
Geoms[geoId2].type != Line)
@ -1148,8 +1164,8 @@ int Sketch::addAngleConstraint(int geoId1, int geoId2, double value)
// line to line angle constraint (with explicitly given start points)
int Sketch::addAngleConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double value)
{
assert(geoId1 < int(Geoms.size()));
assert(geoId2 < int(Geoms.size()));
geoId1 = checkGeoId(geoId1);
geoId2 = checkGeoId(geoId2);
if (Geoms[geoId1].type != Line ||
Geoms[geoId2].type != Line)
@ -1187,8 +1203,8 @@ int Sketch::addAngleConstraint(int geoId1, PointPos pos1, int geoId2, PointPos p
int Sketch::addEqualConstraint(int geoId1, int geoId2)
{
assert(geoId1 < int(Geoms.size()));
assert(geoId2 < int(Geoms.size()));
geoId1 = checkGeoId(geoId1);
geoId2 = checkGeoId(geoId2);
if (Geoms[geoId1].type == Line &&
Geoms[geoId2].type == Line) {
@ -1246,8 +1262,10 @@ int Sketch::addEqualConstraint(int geoId1, int geoId2)
// point on object constraint
int Sketch::addPointOnObjectConstraint(int geoId1, PointPos pos1, int geoId2)
{
geoId1 = checkGeoId(geoId1);
geoId2 = checkGeoId(geoId2);
int pointId1 = getPointId(geoId1, pos1);
assert(geoId2 < int(Geoms.size()));
if (pointId1 >= 0 && pointId1 < int(Points.size())) {
GCS::Point &p1 = Points[pointId1];
@ -1277,9 +1295,9 @@ int Sketch::addPointOnObjectConstraint(int geoId1, PointPos pos1, int geoId2)
// symmetric points constraint
int Sketch::addSymmetricConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, int geoId3)
{
assert(geoId1 < int(Geoms.size()));
assert(geoId2 < int(Geoms.size()));
assert(geoId3 < int(Geoms.size()));
geoId1 = checkGeoId(geoId1);
geoId2 = checkGeoId(geoId2);
geoId3 = checkGeoId(geoId3);
if (Geoms[geoId3].type != Line)
return -1;
@ -1302,7 +1320,7 @@ int Sketch::addSymmetricConstraint(int geoId1, PointPos pos1, int geoId2, PointP
bool Sketch::updateGeometry()
{
int i=0;
for (std::vector<GeoDef>::const_iterator it=Geoms.begin();it!=Geoms.end();++it,i++) {
for (std::vector<GeoDef>::const_iterator it=Geoms.begin(); it != Geoms.end(); ++it, i++) {
try {
if (it->type == Line) {
GeomLineSegment *lineSeg = dynamic_cast<GeomLineSegment*>(it->geo);
@ -1432,7 +1450,7 @@ int Sketch::solve()
int Sketch::initMove(int geoId, PointPos pos)
{
assert(geoId >= 0 && geoId < int(Geoms.size()));
geoId = checkGeoId(geoId);
GCSsys.clearByTag(-1);
GCSsys.clearByTag(-2);
@ -1547,8 +1565,7 @@ int Sketch::initMove(int geoId, PointPos pos)
int Sketch::movePoint(int geoId, PointPos pos, Base::Vector3d toPoint, bool relative)
{
// index out of bounds?
assert(geoId < int(Geoms.size()));
geoId = checkGeoId(geoId);
// don't try to move sketches that contain conflicting constraints
if (hasConflicts())
@ -1558,7 +1575,7 @@ int Sketch::movePoint(int geoId, PointPos pos, Base::Vector3d toPoint, bool rela
initMove(geoId, pos);
if (relative) {
for (int i=0; i < MoveParameters.size()-1; i+=2) {
for (int i=0; i < int(MoveParameters.size()-1); i+=2) {
MoveParameters[i] = InitParameters[i] + toPoint.x;
MoveParameters[i+1] = InitParameters[i+1] + toPoint.y;
}
@ -1596,7 +1613,6 @@ int Sketch::setDatum(int constrId, double value)
int Sketch::getPointId(int geoId, PointPos pos) const
{
assert(geoId < int(Geoms.size()));
switch (pos) {
case start:
return Geoms[geoId].startPointId;
@ -1612,6 +1628,7 @@ int Sketch::getPointId(int geoId, PointPos pos) const
Base::Vector3d Sketch::getPoint(int geoId, PointPos pos)
{
geoId = checkGeoId(geoId);
int pointId = getPointId(geoId, pos);
if (pointId != -1)
return Base::Vector3d(*Points[pointId].x, *Points[pointId].y, 0);
@ -1642,7 +1659,7 @@ TopoShape Sketch::toShape(void) const
bool first = true;
for (;it!=Geoms.end();++it) {
if (!it->construction) {
if (!it->geo->Construction) {
TopoDS_Shape sh = it->geo->toShape();
if (first) {
first = false;
@ -1657,9 +1674,9 @@ TopoShape Sketch::toShape(void) const
std::list<TopoDS_Edge> edge_list;
std::list<TopoDS_Wire> wires;
// collecting all (non constructive) edges out of the sketch
// collecting all (non constructive and non external) edges out of the sketch
for (;it!=Geoms.end();++it) {
if (!it->construction) {
if (!it->external && !it->geo->Construction) {
edge_list.push_back(TopoDS::Edge(it->geo->toShape()));
}
}

View File

@ -56,7 +56,7 @@ public:
/// set the sketch up with geoms and constraints
int setUpSketch(const std::vector<Part::Geometry *> &GeoList, const std::vector<Constraint *> &ConstraintList,
bool withDiagnose=true);
int setUpSketch(const std::vector<Part::Geometry *> &GeoList, const std::vector<Part::Geometry *> &FixedGeoList,
int setUpSketch(const std::vector<Part::Geometry *> &GeoList, const std::vector<Part::Geometry *> &ExternalGeoList,
const std::vector<Constraint *> &ConstraintList, bool withDiagnose=true);
/// return the actual geometry of the sketch a TopoShape
Part::TopoShape toShape(void) const;
@ -65,15 +65,11 @@ public:
/// add unspecified geometry
void addGeometry(const std::vector<Part::Geometry *> &geo, bool fixed=false);
/// returns the actual geometry
std::vector<Part::Geometry *> getGeometry(bool withConstrucionElements = true) const;
std::vector<Part::Geometry *> extractGeometry(bool withConstrucionElements=true,
bool withExternalElements=false) const;
/// get the geometry as python objects
Py::Tuple getPyGeometry(void) const;
/// set a geometric element to a construction element
void setConstruction(int geoIndex,bool isConstruction=true);
bool getConstruction(int geoIndex) const;
/// retrieves the index of a point
int getPointId(int geoId, PointPos pos) const;
/// retrieves a point
Base::Vector3d getPoint(int geoId, PointPos pos);
@ -190,11 +186,11 @@ public:
protected:
/// container element to store and work with the geometric elements of this sketch
struct GeoDef {
GeoDef() : geo(0),type(None),construction(false),index(-1),
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 construction; // defines if this element is a construction element
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
@ -218,8 +214,13 @@ protected:
bool isInitMove;
private:
/// retrieves the index of a point
int getPointId(int geoId, PointPos pos) const;
bool updateGeometry(void);
/// checks if the index bounds and converts negative indices to positive
int checkGeoId(int geoId);
};
} //namespace Part

View File

@ -50,9 +50,9 @@ PROPERTY_SOURCE(Sketcher::SketchObject, Part::Part2DObject)
SketchObject::SketchObject()
{
ADD_PROPERTY_TYPE(Geometry, (0) ,"Sketch",(App::PropertyType)(App::Prop_None),"Sketch geometry");
ADD_PROPERTY_TYPE(Constraints, (0) ,"Sketch",(App::PropertyType)(App::Prop_None),"Sketch constraints");
ADD_PROPERTY_TYPE(ExternalConstraints,(0,0),"Sketch",(App::PropertyType)(App::Prop_None),"Sketch external constraints");
ADD_PROPERTY_TYPE(Geometry, (0) ,"Sketch",(App::PropertyType)(App::Prop_None),"Sketch geometry");
ADD_PROPERTY_TYPE(Constraints, (0) ,"Sketch",(App::PropertyType)(App::Prop_None),"Sketch constraints");
ADD_PROPERTY_TYPE(ExternalGeometry,(0,0),"Sketch",(App::PropertyType)(App::Prop_None),"Sketch external geometry");
}
App::DocumentObjectExecReturn *SketchObject::execute(void)
@ -82,9 +82,9 @@ App::DocumentObjectExecReturn *SketchObject::execute(void)
if (sketch.solve() != 0)
return new App::DocumentObjectExecReturn("Solving the sketch failed",this);
std::vector<Part::Geometry *> geomlist = sketch.getGeometry();
std::vector<Part::Geometry *> geomlist = sketch.extractGeometry();
Geometry.setValues(geomlist);
for (std::vector<Part::Geometry *>::iterator it = geomlist.begin(); it != geomlist.end(); ++it)
for (std::vector<Part::Geometry *>::iterator it=geomlist.begin(); it != geomlist.end(); ++it)
if (*it) delete *it;
Shape.setValue(sketch.toShape());
@ -144,7 +144,7 @@ int SketchObject::setDatum(int ConstrId, double Datum)
if (err == 0) {
// set the newly solved geometry
std::vector<Part::Geometry *> geomlist = sketch.getGeometry();
std::vector<Part::Geometry *> geomlist = sketch.extractGeometry();
Geometry.setValues(geomlist);
for (std::vector<Part::Geometry *>::iterator it = geomlist.begin(); it != geomlist.end(); ++it)
if (*it) delete *it;
@ -155,7 +155,7 @@ int SketchObject::setDatum(int ConstrId, double Datum)
return err;
}
int SketchObject::movePoint(int geoIndex, PointPos PosId, const Base::Vector3d& toPoint, bool relative)
int SketchObject::movePoint(int GeoId, PointPos PosId, const Base::Vector3d& toPoint, bool relative)
{
Sketch sketch;
int dofs = sketch.setUpSketch(Geometry.getValues(), Constraints.getValues());
@ -165,11 +165,11 @@ int SketchObject::movePoint(int geoIndex, PointPos PosId, const Base::Vector3d&
return -1;
// move the point and solve
int ret = sketch.movePoint(geoIndex, PosId, toPoint, relative);
int ret = sketch.movePoint(GeoId, PosId, toPoint, relative);
if (ret == 0) {
std::vector<Part::Geometry *> geomlist = sketch.getGeometry();
std::vector<Part::Geometry *> geomlist = sketch.extractGeometry();
Geometry.setValues(geomlist);
for (std::vector<Part::Geometry *>::iterator it = geomlist.begin(); it != geomlist.end(); ++it) {
for (std::vector<Part::Geometry *>::iterator it=geomlist.begin(); it != geomlist.end(); ++it) {
if (*it) delete *it;
}
}
@ -177,11 +177,11 @@ int SketchObject::movePoint(int geoIndex, PointPos PosId, const Base::Vector3d&
return ret;
}
Base::Vector3d SketchObject::getPoint(int geoIndex, PointPos PosId)
Base::Vector3d SketchObject::getPoint(int GeoId, PointPos PosId) const
{
const std::vector< Part::Geometry * > &geomlist = this->Geometry.getValues();
assert(geoIndex < (int)geomlist.size());
Part::Geometry *geo = geomlist[geoIndex];
assert(GeoId < (int)geomlist.size());
Part::Geometry *geo = geomlist[GeoId];
if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
const Part::GeomLineSegment *lineSeg = dynamic_cast<const Part::GeomLineSegment*>(geo);
if (PosId == start)
@ -265,24 +265,24 @@ int SketchObject::addGeometry(const Part::Geometry *geo)
return Geometry.getSize()-1;
}
int SketchObject::delGeometry(int GeoNbr)
int SketchObject::delGeometry(int GeoId)
{
const std::vector< Part::Geometry * > &vals = this->Geometry.getValues();
if (GeoNbr < 0 || GeoNbr >= (int)vals.size())
if (GeoId < 0 || GeoId >= (int)vals.size())
return -1;
std::vector< Part::Geometry * > newVals(vals);
newVals.erase(newVals.begin()+GeoNbr);
newVals.erase(newVals.begin()+GeoId);
const std::vector< Constraint * > &constraints = this->Constraints.getValues();
std::vector< Constraint * > newConstraints(0);
for (std::vector<Constraint *>::const_iterator it = constraints.begin();
it != constraints.end(); ++it) {
if ((*it)->First != GeoNbr && (*it)->Second != GeoNbr) {
if ((*it)->First != GeoId && (*it)->Second != GeoId) {
Constraint *copiedConstr = (*it)->clone();
if (copiedConstr->First > GeoNbr)
if (copiedConstr->First > GeoId)
copiedConstr->First -= 1;
if (copiedConstr->Second > GeoNbr)
if (copiedConstr->Second > GeoId)
copiedConstr->Second -= 1;
newConstraints.push_back(copiedConstr);
}
@ -295,17 +295,17 @@ int SketchObject::delGeometry(int GeoNbr)
return 0;
}
int SketchObject::toggleConstruction(int GeoNbr)
int SketchObject::toggleConstruction(int GeoId)
{
const std::vector< Part::Geometry * > &vals = this->Geometry.getValues();
if (GeoNbr < 0 || GeoNbr >= (int)vals.size())
if (GeoId < 0 || GeoId >= (int)vals.size())
return -1;
std::vector< Part::Geometry * > newVals(vals);
Part::Geometry *geoNew = newVals[GeoNbr]->clone();
Part::Geometry *geoNew = newVals[GeoId]->clone();
geoNew->Construction = !geoNew->Construction;
newVals[GeoNbr]=geoNew;
newVals[GeoId]=geoNew;
this->Geometry.setValues(newVals);
this->Constraints.acceptGeometry(this->Geometry.getValues());
@ -594,11 +594,12 @@ int SketchObject::fillet(int GeoId1, int GeoId2,
int SketchObject::trim(int GeoId, const Base::Vector3d& point)
{
if (GeoId < 0 || GeoId > getHighestCurveIndex())
return -1;
const std::vector<Part::Geometry *> &geomlist = this->Geometry.getValues();
const std::vector<Constraint *> &constraints = this->Constraints.getValues();
assert(GeoId < int(geomlist.size()));
int GeoId1=Constraint::GeoUndef, GeoId2=Constraint::GeoUndef;
Base::Vector3d point1, point2;
Part2DObject::seekTrimPoints(geomlist, GeoId, point, GeoId1, point1, GeoId2, point2);
@ -994,23 +995,27 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
int SketchObject::addExternal(App::DocumentObject *Obj, const char* SubName)
{
// so far only externals to the support of the sketch
assert(Support.getValue() == Obj);
if (Support.getValue() != Obj)
return -1;
// get the actual lists of the externals
std::vector<DocumentObject*> Objects = ExternalConstraints.getValues();
std::vector<std::string> SubElements = ExternalConstraints.getSubValues();
std::vector<DocumentObject*> Objects = ExternalGeometry.getValues();
std::vector<std::string> SubElements = ExternalGeometry.getSubValues();
std::vector<DocumentObject*> originalObjects = Objects;
std::vector<std::string> originalSubElements = SubElements;
// add the new ones
Objects.push_back(Obj);
SubElements.push_back(std::string(SubName));
// set the Link list.
ExternalConstraints.setValues(Objects,SubElements);
ExternalGeometry.setValues(Objects,SubElements);
return ExternalConstraints.getValues().size()-1;
return ExternalGeometry.getValues().size()-1;
}
int SketchObject::delExternal(int ConstrId)
int SketchObject::delExternal(int ExtGeoId)
{
// FIXME: still to implement
return 0;

View File

@ -45,7 +45,7 @@ public:
/// Property
Part ::PropertyGeometryList Geometry;
Sketcher::PropertyConstraintList Constraints;
App ::PropertyLinkSubList ExternalConstraints;
App ::PropertyLinkSubList ExternalGeometry;
/** @name methods overide Feature */
//@{
/// recalculate the Feature
@ -62,7 +62,7 @@ public:
/// add unspecified geometry
int addGeometry(const std::vector<Part::Geometry *> &geoList);
/// delete geometry
int delGeometry(int GeoNbr);
int delGeometry(int GeoId);
/// add all constraints in the list
int addConstraints(const std::vector<Constraint *> &ConstraintList);
/// add constraint
@ -78,7 +78,7 @@ public:
/// returns a list of projected external geoms
std::vector<Part::Geometry *> getExternalGeometry(void);
/// delete external
int delExternal(int ConstrId);
int delExternal(int ExtGeoId);
/// returns non zero if the sketch contains conflicting constraints
int hasConflicts(void) const;
@ -86,12 +86,12 @@ public:
/// set the datum of a Distance or Angle constraint and solve
int setDatum(int ConstrId, double Datum);
/// move this point to a new location and solve
int movePoint(int geoIndex1, PointPos Pos1, const Base::Vector3d& toPoint, bool relative=false);
int movePoint(int GeoId, PointPos PosId, const Base::Vector3d& toPoint, bool relative=false);
/// retrieves the coordinates of a point
Base::Vector3d getPoint(int geoIndex1, PointPos Pos1);
Base::Vector3d getPoint(int GeoId, PointPos PosId) const;
/// toggle geometry to draft line
int toggleConstruction(int GeoNbr);
int toggleConstruction(int GeoId);
/// create a fillet
int fillet(int geoId, PointPos pos, double radius, bool trim=true);
@ -104,8 +104,8 @@ public:
/// retrieves for a Vertex number the corresponding GeoId and PosId
void getGeoVertexIndex(int VertexId, int &GeoId, PointPos &PosId);
int getHighestVertexIndex(void) { return VertexId2GeoId.size() - 1; }
int getHighestCurveIndex(void) { return Geometry.getSize() - 1; }
int getHighestVertexIndex(void) const { return VertexId2GeoId.size() - 1; }
int getHighestCurveIndex(void) const { return Geometry.getSize() - 1; }
void rebuildVertexIndex(void);
/// retrieves for a Vertex number a list with all coincident points

View File

@ -152,7 +152,7 @@ PyObject* SketchObjectPy::addExternal(PyObject *args)
}
// add the external
if (this->getSketchObjectPtr()->addExternal(Obj,SubName)) {
if (this->getSketchObjectPtr()->addExternal(Obj,SubName) < 0) {
std::stringstream str;
str << "Not able to add external shape element";
PyErr_SetString(PyExc_ValueError, str.str().c_str());

View File

@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="PersistencePy"
Name="SketchPy"
Twin="Sketch"
TwinPointer="Sketch"
Include="Mod/Sketcher/App/Sketch.h"
Namespace="Sketcher"
FatherInclude="Base/PersistencePy.h"
<PythonExport
Father="PersistencePy"
Name="SketchPy"
Twin="Sketch"
TwinPointer="Sketch"
Include="Mod/Sketcher/App/Sketch.h"
Namespace="Sketcher"
FatherInclude="Base/PersistencePy.h"
FatherNamespace="Base"
Constructor="true">
@ -17,7 +17,7 @@
</Documentation>
<Methode Name="solve">
<Documentation>
<UserDocu>solve the actuall set of geometry and constraints</UserDocu>
<UserDocu>solve the actual set of geometry and constraints</UserDocu>
</Documentation>
</Methode>
<Methode Name="addGeometry">

View File

@ -358,19 +358,19 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe
float dci = (float) QApplication::doubleClickInterval()/1000.0f;
float length = (point - prvClickPoint).length();
if (edit->PreselectPoint >=0) {
if (edit->PreselectPoint >= 0) {
//Base::Console().Log("start dragging, point:%d\n",this->DragPoint);
Mode = STATUS_SELECT_Point;
done = true;
} else if (edit->PreselectCurve >=0) {
} else if (edit->PreselectCurve >= 0) {
//Base::Console().Log("start dragging, point:%d\n",this->DragPoint);
Mode = STATUS_SELECT_Edge;
done = true;
} else if (edit->PreselectCross >=0) {
} else if (edit->PreselectCross >= 0) {
//Base::Console().Log("start dragging, point:%d\n",this->DragPoint);
Mode = STATUS_SELECT_Cross;
done = true;
} else if (edit->PreselectConstraint >=0) {
} else if (edit->PreselectConstraint >= 0) {
//Base::Console().Log("start dragging, point:%d\n",this->DragPoint);
Mode = STATUS_SELECT_Constraint;
done = true;
@ -462,7 +462,6 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe
case 2: ss << "V_Axis" ; break;
}
// If cross already selected move from selection
if (Gui::Selection().isSelected(getSketchObject()->getDocument()->getName()
,getSketchObject()->getNameInDocument(),ss.str().c_str()) ) {
@ -581,11 +580,11 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe
case STATUS_NONE:
{
// A right click shouldn't change the Edit Mode
if (edit->PreselectPoint >=0) {
if (edit->PreselectPoint >= 0) {
return true;
} else if (edit->PreselectCurve >=0) {
} else if (edit->PreselectCurve >= 0) {
return true;
} else if (edit->PreselectConstraint >=0) {
} else if (edit->PreselectConstraint >= 0) {
return true;
} else {
//Get Viewer
@ -691,18 +690,21 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe
void ViewProviderSketch::editDoubleClicked(void)
{
if (edit->PreselectPoint >=0) {
Base::Console().Log("double click point:%d\n",edit->PreselectPoint);
} else if (edit->PreselectCurve >=0) {
Base::Console().Log("double click edge:%d\n",edit->PreselectCurve);
} else if (edit->PreselectCross >=0) {
Base::Console().Log("double click cross:%d\n",edit->PreselectCross);
} else if (edit->PreselectConstraint >=0) {
if (edit->PreselectPoint >= 0) {
Base::Console().Log("double click point:%d\n",edit->PreselectPoint);
}
else if (edit->PreselectCurve >= 0) {
Base::Console().Log("double click edge:%d\n",edit->PreselectCurve);
}
else if (edit->PreselectCross >= 0) {
Base::Console().Log("double click cross:%d\n",edit->PreselectCross);
}
else if (edit->PreselectConstraint >= 0) {
// Find the constraint
Base::Console().Log("double click constraint:%d\n",edit->PreselectConstraint);
const std::vector<Sketcher::Constraint *> &ConStr = getSketchObject()->Constraints.getValues();
Constraint *Constr = ConStr[edit->PreselectConstraint];
const std::vector<Sketcher::Constraint *> &constrlist = getSketchObject()->Constraints.getValues();
Constraint *Constr = constrlist[edit->PreselectConstraint];
// if its the right constraint
if (Constr->Type == Sketcher::Distance ||
@ -847,13 +849,13 @@ void ViewProviderSketch::moveConstraint(int constNum, const Base::Vector2D &toPo
if (!edit)
return;
const std::vector<Sketcher::Constraint *> &ConStr = getSketchObject()->Constraints.getValues();
Constraint *Constr = ConStr[constNum];
const std::vector<Sketcher::Constraint *> &constrlist = getSketchObject()->Constraints.getValues();
Constraint *Constr = constrlist[constNum];
if (Constr->Type == Distance || Constr->Type == DistanceX || Constr->Type == DistanceY ||
Constr->Type == Radius) {
const std::vector<Part::Geometry *> geomlist = edit->ActSketch.getGeometry();
const std::vector<Part::Geometry *> geomlist = edit->ActSketch.extractGeometry();
assert(Constr->First < int(geomlist.size()));
Base::Vector3d p1(0.,0.,0.), p2(0.,0.,0.);
@ -918,7 +920,7 @@ void ViewProviderSketch::moveConstraint(int constNum, const Base::Vector2D &toPo
}
}
else if (Constr->Type == Angle) {
const std::vector<Part::Geometry *> geomlist = edit->ActSketch.getGeometry();
const std::vector<Part::Geometry *> geomlist = edit->ActSketch.extractGeometry();
assert(Constr->First < int(geomlist.size()));
Base::Vector3d p0(0.,0.,0.);
@ -1146,14 +1148,14 @@ bool ViewProviderSketch::detectPreselection(const SoPickedPoint *Point, int &PtI
PtIndex = static_cast<const SoPointDetail *>(point_detail)->getCoordinateIndex();
}
} else {
// checking for a hit in the Curves
// checking for a hit in the curves
if (tail == edit->CurveSet) {
const SoDetail *curve_detail = Point->getDetail(edit->CurveSet);
if (curve_detail && curve_detail->getTypeId() == SoLineDetail::getClassTypeId()) {
// get the index
CurvIndex = static_cast<const SoLineDetail *>(curve_detail)->getLineIndex();
}
// checking for a hit in the Cross
// checking for a hit in the cross
} else if (tail == edit->RootCrossSetV) {
//const SoDetail *cross_detail = Point->getDetail(edit->RootCrossSet);
//if (cross_detail && cross_detail->getTypeId() == SoLineDetail::getClassTypeId()) {
@ -1549,7 +1551,7 @@ void ViewProviderSketch::draw(bool temp)
const std::vector<Part::Geometry *> *geomlist;
std::vector<Part::Geometry *> tempGeo;
if (temp) {
tempGeo = edit->ActSketch.getGeometry();
tempGeo = edit->ActSketch.extractGeometry();
geomlist = &tempGeo;
} else
geomlist = &getSketchObject()->Geometry.getValues();
@ -1659,6 +1661,22 @@ void ViewProviderSketch::draw(bool temp)
int32_t *index = edit->CurveSet->numVertices.startEditing();
SbVec3f *pverts = edit->PointsCoordinate->point.startEditing();
int i=0; // setting up the line set
for (std::vector<Base::Vector3d>::const_iterator it = Coords.begin(); it != Coords.end(); ++it,i++)
verts[i].setValue(it->x,it->y,zLines);
i=0; // setting up the indexes of the line set
for (std::vector<unsigned int>::const_iterator it = Index.begin(); it != Index.end(); ++it,i++)
index[i] = *it;
i=0; // setting up the point set
for (std::vector<Base::Vector3d>::const_iterator it = Points.begin(); it != Points.end(); ++it,i++)
pverts[i].setValue(it->x,it->y,zPoints);
edit->CurvesCoordinate->point.finishEditing();
edit->CurveSet->numVertices.finishEditing();
edit->PointsCoordinate->point.finishEditing();
// set cross coordinates
edit->RootCrossSetV->numVertices.set1Value(0,2);
edit->RootCrossSetH->numVertices.set1Value(0,2);
@ -1677,42 +1695,24 @@ void ViewProviderSketch::draw(bool temp)
edit->RootCrossCoordinateH->point.set1Value(0,SbVec3f(0.0f, MiY, zCross));
edit->RootCrossCoordinateH->point.set1Value(1,SbVec3f(0.0f, MaY, zCross));
int i=0; // setting up the line set
for (std::vector<Base::Vector3d>::const_iterator it = Coords.begin(); it != Coords.end(); ++it,i++)
verts[i].setValue(it->x,it->y,zLines);
i=0; // setting up the indexes of the line set
for (std::vector<unsigned int>::const_iterator it = Index.begin(); it != Index.end(); ++it,i++)
index[i] = *it;
i=0; // setting up the point set
for (std::vector<Base::Vector3d>::const_iterator it = Points.begin(); it != Points.end(); ++it,i++)
pverts[i].setValue(it->x,it->y,zPoints);
edit->CurvesCoordinate->point.finishEditing();
edit->CurveSet->numVertices.finishEditing();
edit->PointsCoordinate->point.finishEditing();
// Render Constraints ===================================================
const std::vector<Sketcher::Constraint *> &ConStr = getSketchObject()->Constraints.getValues();
const std::vector<Sketcher::Constraint *> &constrlist = getSketchObject()->Constraints.getValues();
// After an undo/redo it can happen that we have an empty geometry list but a non-empty constraint list
// In this case just ignore the constraints. (See bug #0000421)
if (geomlist->empty() && !ConStr.empty()) {
if (geomlist->empty() && !constrlist.empty()) {
rebuildConstraintsVisual();
return;
}
// reset point if the constraint type has changed
Restart:
// check if a new constraint arrived
if (ConStr.size() != edit->vConstrType.size())
if (constrlist.size() != edit->vConstrType.size())
rebuildConstraintsVisual();
assert(int(ConStr.size()) == edit->constrGroup->getNumChildren());
assert(int(constrlist.size()) == edit->constrGroup->getNumChildren());
assert(int(edit->vConstrType.size()) == edit->constrGroup->getNumChildren());
// go through the constraints and update the position
i = 0;
for (std::vector<Sketcher::Constraint *>::const_iterator it = ConStr.begin(); it != ConStr.end(); ++it,i++) {
for (std::vector<Sketcher::Constraint *>::const_iterator it=constrlist.begin(); it != constrlist.end(); ++it,i++) {
// check if the type has changed
if ((*it)->Type != edit->vConstrType[i]) {
// clearing the type vector will force a rebuild of the visual nodes
@ -2379,7 +2379,7 @@ Restart:
this->updateColor();
// delete the cloned objects
for (std::vector<Part::Geometry *>::iterator it = tempGeo.begin(); it != tempGeo.end(); ++it)
for (std::vector<Part::Geometry *>::iterator it=tempGeo.begin(); it != tempGeo.end(); ++it)
if (*it) delete *it;
if (mdi && mdi->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
@ -2389,12 +2389,12 @@ Restart:
void ViewProviderSketch::rebuildConstraintsVisual(void)
{
const std::vector<Sketcher::Constraint *> &ConStr = getSketchObject()->Constraints.getValues();
const std::vector<Sketcher::Constraint *> &constrlist = getSketchObject()->Constraints.getValues();
// clean up
edit->constrGroup->removeAllChildren();
edit->vConstrType.clear();
for (std::vector<Sketcher::Constraint *>::const_iterator it = ConStr.begin(); it != ConStr.end(); ++it) {
for (std::vector<Sketcher::Constraint *>::const_iterator it=constrlist.begin(); it != constrlist.end(); ++it) {
// root separator for one constraint
SoSeparator *sep = new SoSeparator();
// no caching for fluctuand data structures