Skip to content

Commit

Permalink
Merge remote-tracking branch 'abdullahtahiriyo/arc-distance' into arc…
Browse files Browse the repository at this point in the history
…-distance
  • Loading branch information
FlachyJoe committed Dec 12, 2023
2 parents 1e212c3 + 6d7aaa5 commit 720f263
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 132 deletions.
71 changes: 49 additions & 22 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 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,29 +3244,51 @@ 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);
geoId2 = checkGeoId(geoId2);

if (Geoms[geoId1].type == Circle) {
if (Geoms[geoId2].type == Line) {
GCS::Circle* c1;
if (Geoms[geoId1].type == Circle) {
c1 = &Circles[Geoms[geoId1].index];
}
else if (Geoms[geoId1].type == Arc) {
c1 = &Arcs[Geoms[geoId1].index];
}
else {
return -1;
}

GCS::Line* l = &Lines[Geoms[geoId2].index];
int tag = ++ConstraintsCounter;
GCSsys.addConstraintC2LDistance(*c1, *l, value, tag, driving);
return ConstraintsCounter;
}
else {
GCS::Circle *c1, *c2;
if (Geoms[geoId1].type == Circle) {
c1 = &Circles[Geoms[geoId1].index];
}
else if (Geoms[geoId1].type == Arc) {
c1 = &Arcs[Geoms[geoId1].index];
}
if (Geoms[geoId2].type == Circle) {
GCS::Circle& c1 = Circles[Geoms[geoId1].index];
GCS::Circle& c2 = Circles[Geoms[geoId2].index];
int tag = ++ConstraintsCounter;
GCSsys.addConstraintC2CDistance(c1, c2, value, tag, driving);
return ConstraintsCounter;
c2 = &Circles[Geoms[geoId2].index];
}
else if (Geoms[geoId2].type == Line) {
GCS::Circle& c = Circles[Geoms[geoId1].index];
GCS::Line& l = Lines[Geoms[geoId2].index];
int tag = ++ConstraintsCounter;
GCSsys.addConstraintC2LDistance(c, l, value, tag, driving);
return ConstraintsCounter;
else if (Geoms[geoId2].type == Arc) {
c2 = &Arcs[Geoms[geoId2].index];
}
if (c1 == nullptr || c2 == nullptr) {
return -1;
}

int tag = ++ConstraintsCounter;
GCSsys.addConstraintC2CDistance(*c1, *c2, value, tag, driving);
return ConstraintsCounter;
}
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
19 changes: 11 additions & 8 deletions src/Mod/Sketcher/Gui/CommandConstraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4364,16 +4364,12 @@ void CmdSketcherConstrainDistance::activated(int iMsg)
const Part::Geometry* geom1 = Obj->getGeometry(GeoId1);
const Part::Geometry* geom2 = Obj->getGeometry(GeoId2);

if (isCircle(*geom1) && isCircle(*geom2)) {// circle to circle distance
auto circleSeg1 = static_cast<const Part::GeomCircle*>(geom1);
double radius1 = circleSeg1->getRadius();
Base::Vector3d center1 = circleSeg1->getCenter();
if(isCircleOrArc(*geom1) && isCircleOrArc(*geom2)) {

auto circleSeg2 = static_cast<const Part::GeomCircle*>(geom2);
double radius2 = circleSeg2->getRadius();
Base::Vector3d center2 = circleSeg2->getCenter();
auto [radius1, center1] = getRadiusCenterCircleArc(geom1);
auto [radius2, center2] = getRadiusCenterCircleArc(geom2);

double ActDist = 0.;
double ActDist = 0.0;

Base::Vector3d intercenter = center1 - center2;
double intercenterdistance = intercenter.Length();
Expand Down Expand Up @@ -4458,6 +4454,13 @@ void CmdSketcherConstrainDistance::activated(int iMsg)

return;
}
else {
Gui::TranslatedNotification(
Obj,
QObject::tr("Wrong selection"),
QObject::tr("Cannot add a length constraint on this selection!"));
return;
}
}
else if (isEdge(GeoId1, PosId1)) {// line length
if (GeoId1 < 0 && GeoId1 >= Sketcher::GeoEnum::VAxis) {
Expand Down
118 changes: 59 additions & 59 deletions src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ void EditModeConstraintCoinManager::processConstraints(const GeoListFacade& geol
}
else {
double ra = 0, rb = 0;
double angle,
angleplus = 0.; // angle = rotation of object as a whole; angleplus
// = arc angle (t parameter for ellipses).
double angle, // rotation of object as a whole
angleplus = 0.; // arc angle (t parameter for ellipses)

if (geo->is<Part::GeomCircle>()) {
const Part::GeomCircle* circle =
static_cast<const Part::GeomCircle*>(geo);
Expand Down Expand Up @@ -704,8 +704,7 @@ void EditModeConstraintCoinManager::processConstraints(const GeoListFacade& geol
}

if (geo1->is<Part::GeomEllipse>() || geo1->is<Part::GeomArcOfEllipse>()
|| geo1->getTypeId()
== Part::GeomArcOfHyperbola::getClassTypeId()) {
|| geo1->is<Part::GeomArcOfHyperbola>()) {

Base::Vector3d majDir, minDir, rvec;
majDir = Base::Vector3d(cos(angle1),
Expand Down Expand Up @@ -814,62 +813,60 @@ void EditModeConstraintCoinManager::processConstraints(const GeoListFacade& geol
case DistanceX:
case DistanceY: {
assert(Constr->First >= -extGeoCount && Constr->First < intGeoCount);
Base::Vector3d pnt1(0., 0., 0.), pnt2(0., 0., 0.);

// pnt1 will be initialized to (0,0,0) if First is an edge
auto pnt1 = geolistfacade.getPoint(Constr->First, Constr->FirstPos);

Base::Vector3d pnt2(0., 0., 0.);

if (Constr->SecondPos != Sketcher::PointPos::none) { // point to point distance
pnt1 = geolistfacade.getPoint(Constr->First, Constr->FirstPos);
pnt2 = geolistfacade.getPoint(Constr->Second, Constr->SecondPos);
}
else if (Constr->Second != GeoEnum::GeoUndef) {
const Part::Geometry* geo =
geolistfacade.getGeometryFromGeoId(Constr->Second);
if (geo->is<Part::GeomLineSegment>()) {
const Part::GeomLineSegment* lineSeg =
static_cast<const Part::GeomLineSegment*>(geo);
Base::Vector3d l2p1 = lineSeg->getStartPoint();
Base::Vector3d l2p2 = lineSeg->getEndPoint();
if (Constr->FirstPos
!= Sketcher::PointPos::none) { // point to line distance
pnt1 = geolistfacade.getPoint(Constr->First, Constr->FirstPos);
auto geo = geolistfacade.getGeometryFromGeoId(Constr->Second);
auto geo1 = geolistfacade.getGeometryFromGeoId(Constr->First);
if (isLineSegment(*geo)) {
if (Constr->SecondPos != Sketcher::PointPos::none) {
// point to line distance
// NOLINTNEXTLINE
auto lineSeg = static_cast<const Part::GeomLineSegment*>(geo);
Base::Vector3d l2p1 = lineSeg->getStartPoint();
Base::Vector3d l2p2 = lineSeg->getEndPoint();
// calculate the projection of p1 onto line2
pnt2.ProjectToLine(pnt1 - l2p1, l2p2 - l2p1);
pnt2 += pnt1;
}
else {
const Part::Geometry* geo1 =
geolistfacade.getGeometryFromGeoId(Constr->First);
if (geo1->is<Part::GeomCircle>()) { // circle to line
// distance
const Part::GeomCircle* circleSeg =
static_cast<const Part::GeomCircle*>(geo1);
Base::Vector3d ct = circleSeg->getCenter();
double radius = circleSeg->getRadius();
pnt1.ProjectToLine(
ct - l2p1,
l2p2 - l2p1); // project on the line translated to origin
if (isCircleOrArc(*geo1)) {
// circular to line distance
auto lineSeg = static_cast<const Part::GeomLineSegment*>(geo);

auto [radius, ct] = getRadiusCenterCircleArc(geo1);

Base::Vector3d l2p1 = lineSeg->getStartPoint();
Base::Vector3d l2p2 = lineSeg->getEndPoint();
// project on the line translated to origin
pnt1.ProjectToLine(ct - l2p1, l2p2 - l2p1);
Base::Vector3d dir = pnt1;
dir.Normalize();
pnt1 += ct;
pnt2 = ct + dir * radius;
}
}
}
else if (geo->is<Part::GeomCircle>()) {
const Part::Geometry* geo1 =
geolistfacade.getGeometryFromGeoId(Constr->First);
if (geo1->is<Part::GeomCircle>()) { // circle to circle
// distance
const Part::GeomCircle* circleSeg1 =
static_cast<const Part::GeomCircle*>(geo1);
auto circleSeg2 = static_cast<const Part::GeomCircle*>(geo);
GetCirclesMinimalDistance(circleSeg1, circleSeg2, pnt1, pnt2);
}
else if (Constr->FirstPos
!= Sketcher::PointPos::none) { // point to circle distance
auto circleSeg2 = static_cast<const Part::GeomCircle*>(geo);
else if (isCircleOrArc(*geo)) {
if (Constr->FirstPos != Sketcher::PointPos::none) {
// point to circular distance
auto [rad, ct] = getRadiusCenterCircleArc(geo1);

pnt1 = geolistfacade.getPoint(Constr->First, Constr->FirstPos);
Base::Vector3d v = pnt1 - circleSeg2->getCenter();
Base::Vector3d v = pnt1 - ct;
v = v.Normalize();
pnt2 = circleSeg2->getCenter() + circleSeg2->getRadius() * v;
pnt2 = ct + rad * v;
}
else if (isCircleOrArc(*geo1)) {
// circular to circular distance
GetCirclesMinimalDistance(geo1, geo, pnt1, pnt2);
}
}
else {
Expand All @@ -880,11 +877,9 @@ void EditModeConstraintCoinManager::processConstraints(const GeoListFacade& geol
pnt2 = geolistfacade.getPoint(Constr->First, Constr->FirstPos);
}
else if (Constr->First != GeoEnum::GeoUndef) {
const Part::Geometry* geo =
geolistfacade.getGeometryFromGeoId(Constr->First);
if (geo->is<Part::GeomLineSegment>()) { // segment distance
const Part::GeomLineSegment* lineSeg =
static_cast<const Part::GeomLineSegment*>(geo);
auto geo = geolistfacade.getGeometryFromGeoId(Constr->First);
if (isLineSegment(*geo)) { // segment distance
auto lineSeg = static_cast<const Part::GeomLineSegment*>(geo);
pnt1 = lineSeg->getStartPoint();
pnt2 = lineSeg->getEndPoint();
}
Expand All @@ -896,8 +891,10 @@ void EditModeConstraintCoinManager::processConstraints(const GeoListFacade& geol
break;
}

// NOLINTBEGIN
SoDatumLabel* asciiText = static_cast<SoDatumLabel*>(
sep->getChild(static_cast<int>(ConstraintNodePosition::DatumLabelIndex)));
// NOLINTEND

// Get presentation string (w/o units if option is set)
asciiText->string =
Expand Down Expand Up @@ -1038,8 +1035,9 @@ void EditModeConstraintCoinManager::processConstraints(const GeoListFacade& geol
translation = static_cast<SoZoomTranslation*>(sep->getChild(
static_cast<int>(ConstraintNodePosition::SecondTranslationIndex)));

translation->abPos =
SbVec3f(secondPos.x, secondPos.y, zConstrH); // Absolute Reference
translation->abPos = SbVec3f(secondPos.x,
secondPos.y,
zConstrH); // Absolute Reference
translation->translation =
SbVec3f(relpos2.x - relpos1.x, relpos2.y - relpos1.y, 0);

Expand Down Expand Up @@ -1216,7 +1214,8 @@ void EditModeConstraintCoinManager::processConstraints(const GeoListFacade& geol
double det = dir1.x * dir2.y - dir1.y * dir2.x;
if ((det > 0 ? det : -det) < 1e-10) {
// lines are coincident (or parallel) and in this case the
// center of the point pairs with the shortest distance is used
// center of the point pairs with the shortest distance is
// used
Base::Vector3d p1[2], p2[2];
p1[0] = line1->getStartPoint();
p1[1] = line1->getEndPoint();
Expand Down Expand Up @@ -1265,13 +1264,13 @@ void EditModeConstraintCoinManager::processConstraints(const GeoListFacade& geol
p0 = SbVec3f(p.x, p.y, 0);
dir1 = getNormal(geolistfacade, Constr->First, p);
// TODO: Check
// dir1 = getSolvedSketch().calculateNormalAtPoint(Constr->First, p.x,
// p.y);
// dir1 = getSolvedSketch().calculateNormalAtPoint(Constr->First,
// p.x, p.y);
dir1.RotateZ(-M_PI / 2); // convert to vector of tangency by rotating
dir2 = getNormal(geolistfacade, Constr->Second, p);
// TODO: Check
// dir2 = getSolvedSketch().calculateNormalAtPoint(Constr->Second, p.x,
// p.y);
// dir2 = getSolvedSketch().calculateNormalAtPoint(Constr->Second,
// p.x, p.y);
dir2.RotateZ(-M_PI / 2);

startangle = atan2(dir1.y, dir1.x);
Expand Down Expand Up @@ -2158,12 +2157,13 @@ std::set<int> EditModeConstraintCoinManager::detectPreselectionConstr(const SoPi
++b) {

#ifdef FC_DEBUG
// Useful code to debug coordinates and bounding boxes that does not
// need to be compiled in for any debug operations.
// Useful code to debug coordinates and bounding boxes that does
// not need to be compiled in for any debug operations.

/*Base::Console().Log("Abs(%f,%f),Trans(%f,%f),Coords(%d,%d),iCoords(%f,%f),icon(%d,%d),isize(%d,%d),boundingbox([%d,%d],[%d,%d])\n",
* absPos[0],absPos[1],trans[0], trans[1], cursorPos[0], cursorPos[1],
* iconCoords[0], iconCoords[1], iconX, iconY, iconSize[0], iconSize[1],
* absPos[0],absPos[1],trans[0], trans[1], cursorPos[0],
* cursorPos[1], iconCoords[0], iconCoords[1], iconX, iconY,
* iconSize[0], iconSize[1],
* b->first.topLeft().x(),b->first.topLeft().y(),b->first.bottomRight().x(),b->first.bottomRight().y());*/
#endif

Expand Down

0 comments on commit 720f263

Please sign in to comment.