Trim code improvements:

Automatically converts point on object constraints to coincident constraints when these points are trim points.

git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5056 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
mrlukeparry 2011-10-23 20:07:00 +00:00
parent cf3ba212c5
commit 6e6a0ccfb4

View File

@ -527,6 +527,8 @@ int SketchObject::fillet(int GeoId1, int GeoId2,
int SketchObject::trim(int GeoId, const Base::Vector3d& point)
{
const std::vector<Part::Geometry *> &geomlist = this->Geometry.getValues();
const std::vector<Constraint *> &constraints = this->Constraints.getValues();
assert(GeoId < int(geomlist.size()));
int GeoId1=-1, GeoId2=-1;
@ -562,19 +564,52 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
movePoint(GeoId, end, point1);
movePoint(newGeoId, start, point2);
PointPos secondPos1 = Sketcher::none, secondPos2 = Sketcher::none;
ConstraintType constrType1 = Sketcher::PointOnObject, constrType2 = Sketcher::PointOnObject;
for (std::vector<Constraint *>::const_iterator it=constraints.begin(); it != constraints.end(); ++it)
{
Constraint *constr = *(it);
if(secondPos1 == Sketcher::none && (constr->First == GeoId1 && constr->Second == GeoId)) {
constrType1= Sketcher::Coincident;
secondPos1 = constr->FirstPos;
} else if(secondPos2 == Sketcher::none && (constr->First == GeoId2 && constr->Second == GeoId)) {
constrType2 = Sketcher::Coincident;
secondPos2 = constr->FirstPos;
}
}
// constrain the trimming points on the corresponding geometries
Sketcher::Constraint *newConstr = new Sketcher::Constraint();
newConstr->Type = Sketcher::PointOnObject;
newConstr->Type = constrType1;
newConstr->First = GeoId;
newConstr->FirstPos = end;
newConstr->Second = GeoId1;
if(constrType1 == Sketcher::Coincident) {
newConstr->SecondPos = secondPos1;
delConstraintOnPoint(GeoId1, secondPos1, false);
}
addConstraint(newConstr);
// Reset the second pos
newConstr->SecondPos = Sketcher::none;
newConstr->Type = constrType2;
newConstr->First = newGeoId;
newConstr->FirstPos = start;
newConstr->Second = GeoId2;
if(constrType2 == Sketcher::Coincident) {
newConstr->SecondPos = secondPos2;
delConstraintOnPoint(GeoId2, secondPos2, false);
}
addConstraint(newConstr);
// Reset the second pos
newConstr->SecondPos = Sketcher::none;
// new line segments colinear
newConstr->Type = Sketcher::Tangent;
newConstr->First = GeoId;
@ -597,15 +632,36 @@ 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) {
ConstraintType constrType = Sketcher::PointOnObject;
PointPos secondPos = Sketcher::none;
for (std::vector<Constraint *>::const_iterator it=constraints.begin(); it != constraints.end(); ++it)
{
Constraint *constr = *(it);
if((constr->First == GeoId1 && constr->Second == GeoId)) {
constrType = Sketcher::Coincident;
secondPos = constr->FirstPos;
delConstraintOnPoint(GeoId1, constr->FirstPos, false);
break;
}
}
if (x1 > x0) { // trim line start
delConstraintOnPoint(GeoId, start, false);
movePoint(GeoId, start, point1);
// constrain the trimming point on the corresponding geometry
Sketcher::Constraint *newConstr = new Sketcher::Constraint();
newConstr->Type = Sketcher::PointOnObject;
newConstr->Type = constrType;
newConstr->First = GeoId;
newConstr->FirstPos = start;
newConstr->Second = GeoId1;
if(constrType == Sketcher::Coincident)
{
newConstr->SecondPos = secondPos;
}
addConstraint(newConstr);
delete newConstr;
return 0;
@ -614,10 +670,16 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
delConstraintOnPoint(GeoId, end, false);
movePoint(GeoId, end, point1);
Sketcher::Constraint *newConstr = new Sketcher::Constraint();
newConstr->Type = Sketcher::PointOnObject;
newConstr->Type = constrType;
newConstr->First = GeoId;
newConstr->FirstPos = end;
newConstr->Second = GeoId1;
if(constrType == Sketcher::Coincident)
{
newConstr->SecondPos = secondPos;
}
addConstraint(newConstr);
delete newConstr;
return 0;
@ -655,17 +717,48 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
delete geoNew;
rebuildVertexIndex();
PointPos secondPos1 = Sketcher::none, secondPos2 = Sketcher::none;
ConstraintType constrType1 = Sketcher::PointOnObject, constrType2 = Sketcher::PointOnObject;
for (std::vector<Constraint *>::const_iterator it=constraints.begin(); it != constraints.end(); ++it)
{
Constraint *constr = *(it);
if(secondPos1 == Sketcher::none && (constr->First == GeoId1 && constr->Second == GeoId)) {
constrType1= Sketcher::Coincident;
secondPos1 = constr->FirstPos;
} else if(secondPos2 == Sketcher::none && (constr->First == GeoId2 && constr->Second == GeoId)) {
constrType2 = Sketcher::Coincident;
secondPos2 = constr->FirstPos;
}
}
// constrain the trimming points on the corresponding geometries
Sketcher::Constraint *newConstr = new Sketcher::Constraint();
newConstr->Type = Sketcher::PointOnObject;
newConstr->Type = constrType1;
newConstr->First = GeoId;
newConstr->FirstPos = start;
newConstr->Second = GeoId1;
if(constrType1 == Sketcher::Coincident) {
newConstr->SecondPos = secondPos1;
delConstraintOnPoint(GeoId1, secondPos1, false);
}
addConstraint(newConstr);
// Reset secondpos in case it was set previously
newConstr->SecondPos = Sketcher::none;
// Add Second Constraint
newConstr->First = GeoId;
newConstr->FirstPos = end;
newConstr->Second = GeoId2;
if(constrType2 == Sketcher::Coincident) {
newConstr->SecondPos = secondPos2;
delConstraintOnPoint(GeoId2, secondPos2, false);
}
addConstraint(newConstr);
delete newConstr;
@ -710,15 +803,48 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
newConstr->Second = newGeoId;
addConstraint(newConstr);
newConstr->Type = Sketcher::PointOnObject;
PointPos secondPos1 = Sketcher::none, secondPos2 = Sketcher::none;
ConstraintType constrType1 = Sketcher::PointOnObject, constrType2 = Sketcher::PointOnObject;
for (std::vector<Constraint *>::const_iterator it=constraints.begin(); it != constraints.end(); ++it)
{
Constraint *constr = *(it);
if(secondPos1 == Sketcher::none &&
(constr->First == GeoId1 && constr->Second == GeoId)) {
constrType1= Sketcher::Coincident;
secondPos1 = constr->FirstPos;
} else if(secondPos2 == Sketcher::none &&
(constr->First == GeoId2 && constr->Second == GeoId)) {
constrType2 = Sketcher::Coincident;
secondPos2 = constr->FirstPos;
}
}
newConstr->Type = constrType1;
newConstr->First = GeoId;
newConstr->FirstPos = end;
newConstr->Second = GeoId1;
if(constrType1 == Sketcher::Coincident) {
newConstr->SecondPos = secondPos1;
delConstraintOnPoint(GeoId1, secondPos1, false);
}
addConstraint(newConstr);
// Reset secondpos in case it was set previously
newConstr->SecondPos = Sketcher::none;
newConstr->Type = constrType2;
newConstr->First = newGeoId;
newConstr->FirstPos = start;
newConstr->Second = GeoId2;
if(constrType2 == Sketcher::Coincident) {
newConstr->SecondPos = secondPos2;
delConstraintOnPoint(GeoId2, secondPos2, false);
}
addConstraint(newConstr);
newConstr->Type = Sketcher::Coincident;
@ -743,6 +869,20 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
}
if (GeoId1 >= 0) {
ConstraintType constrType = Sketcher::PointOnObject;
PointPos secondPos = Sketcher::none;
for (std::vector<Constraint *>::const_iterator it=constraints.begin(); it != constraints.end(); ++it)
{
Constraint *constr = *(it);
if((constr->First == GeoId1 && constr->Second == GeoId)) {
constrType = Sketcher::Coincident;
secondPos = constr->FirstPos;
delConstraintOnPoint(GeoId1, constr->FirstPos, false);
break;
}
}
double theta1 = Base::fmod(atan2(point1.y - center.y, point1.x - center.x) - startAngle, 2.f*M_PI) * dir; // x1
if (theta1 >= 0.001*arcLength && theta1 <= 0.999*arcLength) {
if (theta1 > theta0) { // trim arc start
@ -751,10 +891,16 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
aoc1->setRange(startAngle + theta1, endAngle);
// constrain the trimming point on the corresponding geometry
Sketcher::Constraint *newConstr = new Sketcher::Constraint();
newConstr->Type = Sketcher::PointOnObject;
newConstr->Type = constrType;
newConstr->First = GeoId;
newConstr->FirstPos = start;
newConstr->Second = GeoId1;
if(constrType == Sketcher::Coincident)
{
newConstr->SecondPos = secondPos;
}
addConstraint(newConstr);
delete newConstr;
return 0;
@ -764,10 +910,16 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
Part::GeomArcOfCircle *aoc1 = dynamic_cast<Part::GeomArcOfCircle*>(geomlist[GeoId]);
aoc1->setRange(startAngle, startAngle + theta1);
Sketcher::Constraint *newConstr = new Sketcher::Constraint();
newConstr->Type = Sketcher::PointOnObject;
newConstr->Type = constrType;
newConstr->First = GeoId;
newConstr->FirstPos = end;
newConstr->Second = GeoId1;
if(constrType == Sketcher::Coincident)
{
newConstr->SecondPos = secondPos;
}
addConstraint(newConstr);
delete newConstr;
return 0;