When you cannot sleep, instead drink tea and work on free-cad at 3AM!
Improved trimming behaviour for arcs substantially. Hopefully no problems in the future git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5015 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
@@ -27,6 +27,7 @@
|
|||||||
# include <TopoDS_Face.hxx>
|
# include <TopoDS_Face.hxx>
|
||||||
# include <TopoDS.hxx>
|
# include <TopoDS.hxx>
|
||||||
# include <BRepAdaptor_Surface.hxx>
|
# include <BRepAdaptor_Surface.hxx>
|
||||||
|
# include <Geom_TrimmedCurve.hxx>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <Base/Writer.h>
|
#include <Base/Writer.h>
|
||||||
@@ -557,7 +558,7 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
|||||||
}
|
}
|
||||||
|
|
||||||
this->Constraints.setValues(newVals);
|
this->Constraints.setValues(newVals);
|
||||||
|
|
||||||
movePoint(GeoId, end, point1);
|
movePoint(GeoId, end, point1);
|
||||||
movePoint(newGeoId, start, point2);
|
movePoint(newGeoId, start, point2);
|
||||||
|
|
||||||
@@ -661,22 +662,10 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
|||||||
std::vector< Part::Geometry * > newVals(geomlist);
|
std::vector< Part::Geometry * > newVals(geomlist);
|
||||||
newVals[GeoId] = geoNew;
|
newVals[GeoId] = geoNew;
|
||||||
Geometry.setValues(newVals);
|
Geometry.setValues(newVals);
|
||||||
|
|
||||||
delete geoNew;
|
delete geoNew;
|
||||||
rebuildVertexIndex();
|
rebuildVertexIndex();
|
||||||
|
|
||||||
// go through all constraints and replace the point (GeoId,end) with (newGeoId,end)
|
|
||||||
/*const std::vector<Constraint *> &constraints = this->Constraints.getValues();
|
|
||||||
std::vector<Constraint *> newVals(constraints);
|
|
||||||
for (int i=0; i < int(newVals.size()); i++) {
|
|
||||||
if (constraints[i]->First == GeoId &&
|
|
||||||
constraints[i]->FirstPos == end)
|
|
||||||
constraints[i]->First = newGeoId;
|
|
||||||
else if (constraints[i]->Second == GeoId &&
|
|
||||||
constraints[i]->SecondPos == end)
|
|
||||||
constraints[i]->Second = newGeoId;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// constrain the trimming points on the corresponding geometries
|
// constrain the trimming points on the corresponding geometries
|
||||||
Sketcher::Constraint *newConstr = new Sketcher::Constraint();
|
Sketcher::Constraint *newConstr = new Sketcher::Constraint();
|
||||||
newConstr->Type = Sketcher::PointOnObject;
|
newConstr->Type = Sketcher::PointOnObject;
|
||||||
@@ -691,8 +680,6 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
|||||||
addConstraint(newConstr);
|
addConstraint(newConstr);
|
||||||
|
|
||||||
delete newConstr;
|
delete newConstr;
|
||||||
//movePoint(newGeoId, start, point2);
|
|
||||||
//movePoint(newGeoId, end, point1);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} else
|
} else
|
||||||
@@ -704,6 +691,9 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
|||||||
Base::Vector3d center = aoc->getCenter();
|
Base::Vector3d center = aoc->getCenter();
|
||||||
double theta0 = atan2(point.y - center.y,point.x - center.x);
|
double theta0 = atan2(point.y - center.y,point.x - center.x);
|
||||||
|
|
||||||
|
// Boolean if arc first parameter is greater than last parameter
|
||||||
|
bool swap;
|
||||||
|
|
||||||
if (GeoId1 >= 0 && GeoId2 >= 0) {
|
if (GeoId1 >= 0 && GeoId2 >= 0) {
|
||||||
double theta1 = atan2(point1.y - center.y, point1.x - center.x);
|
double theta1 = atan2(point1.y - center.y, point1.x - center.x);
|
||||||
double theta2 = atan2(point2.y - center.y, point2.x - center.x);
|
double theta2 = atan2(point2.y - center.y, point2.x - center.x);
|
||||||
@@ -723,13 +713,14 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
|||||||
theta1 += 2*M_PI;
|
theta1 += 2*M_PI;
|
||||||
}
|
}
|
||||||
|
|
||||||
double u,v;
|
// Getting Arc Trim Parameters - Note: for some reason aoc->getRange is not reliable
|
||||||
aoc->getRange(u,v);
|
Handle_Geom_TrimmedCurve curve = Handle_Geom_TrimmedCurve::DownCast(aoc->handle());
|
||||||
|
double u = (double) curve->FirstParameter(),v = (double) curve->LastParameter();
|
||||||
|
// aoc->getRange(u,v);
|
||||||
u = fmod(u, 2.f*M_PI);
|
u = fmod(u, 2.f*M_PI);
|
||||||
v = fmod(v, 2.f*M_PI);
|
v = fmod(v, 2.f*M_PI);
|
||||||
|
|
||||||
bool swap = (u > v);
|
swap = (u > v);
|
||||||
|
|
||||||
if (theta1 > theta2) {
|
if (theta1 > theta2) {
|
||||||
std::swap(GeoId1,GeoId2);
|
std::swap(GeoId1,GeoId2);
|
||||||
std::swap(point1,point2);
|
std::swap(point1,point2);
|
||||||
@@ -756,7 +747,6 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
|||||||
Constraint *constNew = newVals[i]->clone();
|
Constraint *constNew = newVals[i]->clone();
|
||||||
constNew->First = newGeoId;
|
constNew->First = newGeoId;
|
||||||
newVals[i] = constNew;
|
newVals[i] = constNew;
|
||||||
|
|
||||||
} else if (constraints[i]->Second == GeoId &&
|
} else if (constraints[i]->Second == GeoId &&
|
||||||
constraints[i]->SecondPos == end) {
|
constraints[i]->SecondPos == end) {
|
||||||
|
|
||||||
@@ -769,15 +759,16 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
|||||||
this->Constraints.setValues(newVals);
|
this->Constraints.setValues(newVals);
|
||||||
|
|
||||||
// Setting the range manually to improve stability before adding constraints
|
// Setting the range manually to improve stability before adding constraints
|
||||||
aoc->getRange(u,v);
|
u = fmod((double) curve->FirstParameter(), 2.f*M_PI);
|
||||||
u = fmod(u, 2.f*M_PI);
|
v = fmod((double) curve->LastParameter(), 2.f*M_PI);
|
||||||
v = fmod(v, 2.f*M_PI);
|
|
||||||
aoc->setRange(u, theta1);
|
aoc->setRange(u, theta1);
|
||||||
aoc2->setRange(theta2, v);
|
aoc2->setRange(theta2, v);
|
||||||
|
|
||||||
// constrain the trimming points on the corresponding geometries
|
// constrain the trimming points on the corresponding geometries
|
||||||
Sketcher::Constraint *newConstr = new Sketcher::Constraint();
|
Sketcher::Constraint *newConstr = new Sketcher::Constraint();
|
||||||
|
|
||||||
|
// Build Constraints associated with new pair of arcs
|
||||||
newConstr->Type = Sketcher::Equal;
|
newConstr->Type = Sketcher::Equal;
|
||||||
newConstr->First = GeoId;
|
newConstr->First = GeoId;
|
||||||
newConstr->Second = newGeoId;
|
newConstr->Second = newGeoId;
|
||||||
@@ -804,17 +795,38 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
|||||||
delete newConstr;
|
delete newConstr;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
} else
|
||||||
} else if ((swap && (u1 < 0.999*u && u1 > 0.999*v)) ||
|
return -1;
|
||||||
(!swap && (u1 > 1.001* u && u1 < 0.999*v)) ) { // drop the first intersection point
|
}
|
||||||
|
|
||||||
|
bool u1Valid = true, v1Valid = true;
|
||||||
|
|
||||||
|
// Check if start and end of arcs have point on object constraints
|
||||||
|
if ((swap && v1 < 1.001*u && v1 > 0.999*v) ||
|
||||||
|
(!swap && !(v1 > 1.001*u && v1 < 0.999*v)) ) { // drop the second intersection point
|
||||||
|
v1Valid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((swap && u1 < 1.001*u && u1 > 0.999*v) ||
|
||||||
|
(!swap && !(u1 > 1.001* u && u1 < 0.999*v)) ) { // drop the first intersection point
|
||||||
std::swap(GeoId1,GeoId2);
|
std::swap(GeoId1,GeoId2);
|
||||||
std::swap(point1,point2);
|
std::swap(point1,point2);
|
||||||
} else if ((swap && (v1 < 0.999*u && v1 > 0.999*v)) ||
|
|
||||||
(!swap && (v1 > 1.001*u && v1 < 0.999*v)) ) { // drop the second intersection point
|
u1Valid = false;
|
||||||
} else
|
}
|
||||||
|
|
||||||
|
// If Both Parameters have invalid ranges. Leave trim operation
|
||||||
|
if(!v1Valid && !u1Valid)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GeoId1 >= 0) {
|
if (GeoId1 >= 0) {
|
||||||
|
Handle_Geom_TrimmedCurve curve = Handle_Geom_TrimmedCurve::DownCast(aoc->handle());
|
||||||
|
double u = (double) curve->FirstParameter(),v = (double) curve->LastParameter();
|
||||||
|
// aoc->getRange(u,v);
|
||||||
|
u = fmod(u, 2.f*M_PI);
|
||||||
|
v = fmod(v, 2.f*M_PI);
|
||||||
|
|
||||||
double theta1 = atan2(point1.y - center.y, point1.x - center.x);
|
double theta1 = atan2(point1.y - center.y, point1.x - center.x);
|
||||||
|
|
||||||
if (theta0 < 0)
|
if (theta0 < 0)
|
||||||
@@ -822,8 +834,9 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
|||||||
|
|
||||||
if (theta1 < 0)
|
if (theta1 < 0)
|
||||||
theta1 += 2*M_PI;
|
theta1 += 2*M_PI;
|
||||||
|
|
||||||
if (theta1 > theta0) { // trim en
|
if ((theta1 > theta0) ||
|
||||||
|
(swap && theta1 < theta0 && theta1 < v)) { // trim en
|
||||||
delConstraintOnPoint(GeoId, start, false);
|
delConstraintOnPoint(GeoId, start, false);
|
||||||
|
|
||||||
movePoint(GeoId, start, point1);
|
movePoint(GeoId, start, point1);
|
||||||
@@ -837,7 +850,8 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
|||||||
delete newConstr;
|
delete newConstr;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if (theta1 < theta0) { // trim line end
|
else if ((theta1 < theta0) ||
|
||||||
|
(swap && theta1 > theta0 && theta1 > v)) { // trim line end
|
||||||
delConstraintOnPoint(GeoId, end, false);
|
delConstraintOnPoint(GeoId, end, false);
|
||||||
movePoint(GeoId, end, point1);
|
movePoint(GeoId, end, point1);
|
||||||
Sketcher::Constraint *newConstr = new Sketcher::Constraint();
|
Sketcher::Constraint *newConstr = new Sketcher::Constraint();
|
||||||
@@ -849,7 +863,6 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
|
|||||||
delete newConstr;
|
delete newConstr;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user