Skip to content

Commit

Permalink
Sketcher: Enable undo when trimming
Browse files Browse the repository at this point in the history
===================================

Reported here:
https://forum.freecadweb.org/viewtopic.php?p=311853#p312647
  • Loading branch information
abdullahtahiriyo committed May 26, 2020
1 parent 078432a commit 6f3160d
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/Mod/Sketcher/App/SketchObject.cpp
Expand Up @@ -1951,6 +1951,10 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)

};

auto creategeometryundopoint = [this, geomlist]() {
Geometry.setValues(geomlist);
};

Part::Geometry *geo = geomlist[GeoId];
if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
const Part::GeomLineSegment *lineSeg = static_cast<const Part::GeomLineSegment*>(geo);
Expand Down Expand Up @@ -2047,7 +2051,7 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
if (GeoId1 >= 0) {
double x1 = (point1 - startPnt)*dir;
if (x1 >= 0.001*length && x1 <= 0.999*length) {

creategeometryundopoint(); // for when geometry will change, but no new geometry will be committed.
ConstraintType constrType = Sketcher::PointOnObject;
PointPos secondPos = Sketcher::none;
for (std::vector<Constraint *>::const_iterator it=constraints.begin();
Expand Down Expand Up @@ -2444,7 +2448,7 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
}

if (GeoId1 >= 0) {

creategeometryundopoint(); // for when geometry will change, but no new geometry will be committed.
ConstraintType constrType = Sketcher::PointOnObject;
PointPos secondPos = Sketcher::none;
for (std::vector<Constraint *>::const_iterator it=constraints.begin();
Expand Down Expand Up @@ -2620,7 +2624,12 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
}

if (GeoId1 >= 0) {
double theta1 = Base::fmod(
atan2(-aoe->getMajorRadius()*((point1.x-center.x)*aoe->getMajorAxisDir().y-(point1.y-center.y)*aoe->getMajorAxisDir().x),
aoe->getMinorRadius()*((point1.x-center.x)*aoe->getMajorAxisDir().x+(point1.y-center.y)*aoe->getMajorAxisDir().y)
)- startAngle, 2.f*M_PI) * dir; // x1

creategeometryundopoint(); // for when geometry will change, but no new geometry will be committed.
ConstraintType constrType = Sketcher::PointOnObject;
PointPos secondPos = Sketcher::none;
for (std::vector<Constraint *>::const_iterator it=constraints.begin();
Expand All @@ -2634,11 +2643,6 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
}
}

double theta1 = Base::fmod(
atan2(-aoe->getMajorRadius()*((point1.x-center.x)*aoe->getMajorAxisDir().y-(point1.y-center.y)*aoe->getMajorAxisDir().x),
aoe->getMinorRadius()*((point1.x-center.x)*aoe->getMajorAxisDir().x+(point1.y-center.y)*aoe->getMajorAxisDir().y)
)- startAngle, 2.f*M_PI) * dir; // x1

if (theta1 >= 0.001*arcLength && theta1 <= 0.999*arcLength) {
if (theta1 > theta0) { // trim arc start
delConstraintOnPoint(GeoId, start, false);
Expand Down Expand Up @@ -2799,6 +2803,12 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)

if (GeoId1 >= 0) {

double theta1 = Base::fmod(
atan2(-aoh->getMajorRadius()*((point1.x-center.x)*sin(aoh->getAngleXU())-(point1.y-center.y)*cos(aoh->getAngleXU())),
aoh->getMinorRadius()*((point1.x-center.x)*cos(aoh->getAngleXU())+(point1.y-center.y)*sin(aoh->getAngleXU()))
)- startAngle, 2.f*M_PI) * dir; // x1

creategeometryundopoint(); // for when geometry will change, but no new geometry will be committed.
ConstraintType constrType = Sketcher::PointOnObject;
PointPos secondPos = Sketcher::none;
for (std::vector<Constraint *>::const_iterator it=constraints.begin();
Expand All @@ -2812,11 +2822,6 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
}
}

double theta1 = Base::fmod(
atan2(-aoh->getMajorRadius()*((point1.x-center.x)*sin(aoh->getAngleXU())-(point1.y-center.y)*cos(aoh->getAngleXU())),
aoh->getMinorRadius()*((point1.x-center.x)*cos(aoh->getAngleXU())+(point1.y-center.y)*sin(aoh->getAngleXU()))
)- startAngle, 2.f*M_PI) * dir; // x1

if (theta1 >= 0.001*arcLength && theta1 <= 0.999*arcLength) {
if (theta1 > theta0) { // trim arc start
delConstraintOnPoint(GeoId, start, false);
Expand Down

0 comments on commit 6f3160d

Please sign in to comment.