Skip to content

Commit

Permalink
Sketcher: Extend distance constraint to arcs
Browse files Browse the repository at this point in the history
  • Loading branch information
FlachyJoe committed Nov 29, 2023
1 parent 786f642 commit 8b4831a
Show file tree
Hide file tree
Showing 5 changed files with 459 additions and 423 deletions.
39 changes: 20 additions & 19 deletions src/Mod/Sketcher/App/Sketch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3178,7 +3178,7 @@ int Sketch::addDistanceConstraint(int geoId, double* value, bool driving)
return ConstraintsCounter;
}

// point to line or circle distance constraint
// point to line or circular distance constraint
int Sketch::addDistanceConstraint(int geoId1,
PointPos pos1,
int geoId2,
Expand All @@ -3201,16 +3201,21 @@ int Sketch::addDistanceConstraint(int geoId1,
GCSsys.addConstraintP2LDistance(p1, l2, value, tag, driving);
return ConstraintsCounter;
}
else if (Geoms[geoId2].type == Circle) {
GCS::Circle& c2 = Circles[Geoms[geoId2].index];

else {
GCS::Circle* c2;
if (Geoms[geoId2].type == Circle) {
c2 = &Circles[Geoms[geoId2].index];
}
else if (Geoms[geoId2].type == Arc) {
c2 = &Arcs[Geoms[geoId2].index];
}
else {
return -1;
}
int tag = ++ConstraintsCounter;
GCSsys.addConstraintP2CDistance(p1, c2, value, tag, driving);
GCSsys.addConstraintP2CDistance(p1, *c2, value, tag, driving);
return ConstraintsCounter;
}
else {
return -1;
}
}

// point to point distance constraint
Expand Down Expand Up @@ -3239,7 +3244,7 @@ int Sketch::addDistanceConstraint(int geoId1,
return -1;
}

// circle-(circle or line) distance constraint
// circular-(circular or line) distance constraint
int Sketch::addDistanceConstraint(int geoId1, int geoId2, double* value, bool driving)
{
geoId1 = checkGeoId(geoId1);
Expand All @@ -3259,23 +3264,19 @@ int Sketch::addDistanceConstraint(int geoId1, int geoId2, double* value, bool dr
return ConstraintsCounter;
}
else {
if ((Geoms[geoId1].type == Circle) && (Geoms[geoId2].type == Circle)) {
if (Geoms[geoId1].type == Circle) {
c1 = &Circles[Geoms[geoId1].index];
c2 = &Circles[Geoms[geoId2].index];
}
else if ((Geoms[geoId1].type == Arc) && (Geoms[geoId2].type == Circle)) {
else if (Geoms[geoId1].type == Arc) {
c1 = &Arcs[Geoms[geoId1].index];
c2 = &Circles[Geoms[geoId2].index];
}
else if ((Geoms[geoId1].type == Circle) && (Geoms[geoId2].type == Arc)) {
c1 = &Circles[Geoms[geoId1].index];
c2 = &Arcs[Geoms[geoId2].index];
if (Geoms[geoId2].type == Circle) {
c2 = &Circles[Geoms[geoId2].index];
}
else if ((Geoms[geoId1].type == Arc) && (Geoms[geoId2].type == Arc)) {
c1 = &Arcs[Geoms[geoId1].index];
else if (Geoms[geoId2].type == Arc) {
c2 = &Arcs[Geoms[geoId2].index];
}
else {
if (c1 == nullptr || c2 == nullptr) {
return -1;
}

Expand Down
5 changes: 4 additions & 1 deletion src/Mod/Sketcher/App/SketchObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,12 @@ int SketchObject::setDatum(int ConstrId, double Datum)
if (!vals[ConstrId]->isDimensional() && type != Tangent && type != Perpendicular)
return -1;

if ((type == Distance || type == Radius || type == Diameter || type == Weight) && Datum <= 0)
if ((type == Radius || type == Diameter || type == Weight) && Datum <= 0)
return (Datum == 0) ? -5 : -4;

if (type == Distance && Datum == 0)
return -5;

// copy the list
std::vector<Constraint*> newVals(vals);
double oldDatum = newVals[ConstrId]->getValue();
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Sketcher/Gui/CommandConstraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4186,7 +4186,7 @@ void CmdSketcherConstrainDistance::activated(int iMsg)
radius1 = arcSeg1->getRadius();
center1 = arcSeg1->getCenter();
}
if (isArcOfCircle(*geom2))) {
if (isArcOfCircle(*geom2)) {
auto arcSeg2 = static_cast<const Part::GeomArcOfCircle*>(geom2);
radius2 = arcSeg2->getRadius();
center2 = arcSeg2->getCenter();
Expand Down

0 comments on commit 8b4831a

Please sign in to comment.