Fixed Tangent Icon Positioning when lines are colinear

Fixed undo crashes for trim on both line and arcs

Added equality constraint to trimmed arcs and coincident to centers

git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5011 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
mrlukeparry 2011-10-13 17:52:02 +00:00
parent 5ccf289f29
commit 05f05209c1
2 changed files with 76 additions and 38 deletions

View File

@ -459,7 +459,7 @@ int SketchObject::fillet(int GeoId1, int GeoId2,
}
else
return -1;
if (trim) {
PointPos PosId1 = (filletCenter-intersection)*dir1 > 0 ? start : end;
PointPos PosId2 = (filletCenter-intersection)*dir2 > 0 ? start : end;
@ -536,17 +536,28 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
if (x1 < x0 && x2 > x0) {
int newGeoId = addGeometry(geo);
// go through all constraints and replace the point (GeoId,end) with (newGeoId,end)
const std::vector<Constraint *> &constraints = this->Constraints.getValues();
const std::vector<Constraint *> &constraints = 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;
constraints[i]->FirstPos == end) {
Constraint *constNew = newVals[i]->clone();
constNew->First = newGeoId;
newVals[i] = constNew;
} else if (constraints[i]->Second == GeoId &&
constraints[i]->SecondPos == end) {
Constraint *constNew = newVals[i]->clone();
constNew->Second = newGeoId;
newVals[i] = constNew;
}
}
this->Constraints.setValues(newVals);
movePoint(GeoId, end, point1);
movePoint(newGeoId, start, point2);
@ -640,17 +651,21 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
// Trim Point between intersection points
if (theta1 < theta0 && theta2 > theta0) {
Part::GeomArcOfCircle *geo = new Part::GeomArcOfCircle();
geo->setCenter(center);
geo->setRadius(circle->getRadius());
geo->setRange(theta2, theta1);
delGeometry(GeoId);
int newGeoId = addGeometry(dynamic_cast<Part::Geometry *>(geo));
delete(geo);
// Create a new arc to substitute Circle in geometry list and set parameters
Part::GeomArcOfCircle *geoNew = new Part::GeomArcOfCircle();
geoNew->setCenter(center);
geoNew->setRadius(circle->getRadius());
geoNew->setRange(theta2, theta1);
std::vector< Part::Geometry * > newVals(geomlist);
newVals[GeoId] = geoNew;
Geometry.setValues(newVals);
delete geoNew;
// go through all constraints and replace the point (GeoId,end) with (newGeoId,end)
const std::vector<Constraint *> &constraints = this->Constraints.getValues();
/*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 &&
@ -660,16 +675,17 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
constraints[i]->SecondPos == end)
constraints[i]->Second = newGeoId;
}
*/
// constrain the trimming points on the corresponding geometries
Sketcher::Constraint *newConstr = new Sketcher::Constraint();
newConstr->Type = Sketcher::PointOnObject;
newConstr->First = newGeoId;
newConstr->First = GeoId;
newConstr->FirstPos = end;
newConstr->Second = GeoId1;
addConstraint(newConstr);
newConstr->First = newGeoId;
newConstr->First = GeoId;
newConstr->FirstPos = start;
newConstr->Second = GeoId2;
addConstraint(newConstr);
@ -730,19 +746,29 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
Part::GeomArcOfCircle *aoc = dynamic_cast<Part::GeomArcOfCircle*>(geomlist[GeoId]);
Part::GeomArcOfCircle *aoc2 = dynamic_cast<Part::GeomArcOfCircle*>(geomlist[newGeoId]);
// go through all constraints and replace the point (GeoId,end) with (newGeoId,end)
const std::vector<Constraint *> &constraints = this->Constraints.getValues();
const std::vector<Constraint *> &constraints = 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;
constraints[i]->FirstPos == end) {
Constraint *constNew = newVals[i]->clone();
constNew->First = newGeoId;
newVals[i] = constNew;
} else if (constraints[i]->Second == GeoId &&
constraints[i]->SecondPos == end) {
Constraint *constNew = newVals[i]->clone();
constNew->Second = newGeoId;
newVals[i] = constNew;
}
}
// Setting the range manually to improve stability before adding constraints
this->Constraints.setValues(newVals);
// Setting the range manually to improve stability before adding constraints
aoc->getRange(u,v);
u = fmod(u, 2.f*M_PI);
v = fmod(v, 2.f*M_PI);
@ -751,6 +777,12 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
// constrain the trimming points on the corresponding geometries
Sketcher::Constraint *newConstr = new Sketcher::Constraint();
newConstr->Type = Sketcher::Equal;
newConstr->First = GeoId;
newConstr->Second = newGeoId;
addConstraint(newConstr);
newConstr->Type = Sketcher::PointOnObject;
newConstr->First = GeoId;
newConstr->FirstPos = end;
@ -762,6 +794,13 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
newConstr->Second = GeoId2;
addConstraint(newConstr);
newConstr->Type = Sketcher::Coincident;
newConstr->First = GeoId;
newConstr->FirstPos = Sketcher::mid;
newConstr->Second = newGeoId;
newConstr->SecondPos = Sketcher::mid;
addConstraint(newConstr);
delete newConstr;
return 0;

View File

@ -1969,25 +1969,24 @@ Restart:
Base::Vector3d constrPos2 = midpos2 + (norm2 * scale * 2.5);
constrPos2 = seekConstraintPosition(constrPos2, dir2, scale * 2.5, edit->constrGroup->getChild(i));
constrPos2 = constrPos2 - constrPos1;
// Translate the Icon based on calculated position
Base::Vector3d relPos1 = constrPos1 - midpos1 ; // Relative Position of Icons to Midpoint1
Base::Vector3d relPos2 = constrPos2 - midpos2 ; // Relative Position of Icons to Midpoint2
Base::Vector3d relPos1 = midpos1 - constrPos1;
Base::Vector3d relPos2 = midpos2 - constrPos2;
relPos1 = relPos1 / scale;
relPos2 = relPos2 / scale;
relPos1 = relPos1 / scale;
relPos2 = relPos2 / scale;
dynamic_cast<SoZoomTranslation *>(sep->getChild(1))->abPos = SbVec3f(midpos1.x, midpos1.y, zConstr); //Absolute Reference
// Translate the Icon based on calculated position
dynamic_cast<SoZoomTranslation *>(sep->getChild(1))->abPos = SbVec3f(midpos1.x, midpos1.y, zConstr); //Absolute Reference
//Reference Position that is scaled according to zoom
dynamic_cast<SoZoomTranslation *>(sep->getChild(1))->translation = SbVec3f(relPos1.x, relPos1.y, 0);
//Reference Position that is scaled according to zoom
dynamic_cast<SoZoomTranslation *>(sep->getChild(1))->translation = SbVec3f(relPos1.x, relPos1.y, 0);
Base::Vector3d secondPos = midpos2 - midpos1;
dynamic_cast<SoZoomTranslation *>(sep->getChild(3))->abPos = SbVec3f(secondPos.x, secondPos.y, zConstr); //Absolute Reference
// Translate the Icon based on calculated position
dynamic_cast<SoZoomTranslation *>(sep->getChild(3))->abPos = SbVec3f(midpos2.x, midpos2.y, zConstr); //Absolute Reference
//Reference Position that is scaled according to zoom
dynamic_cast<SoZoomTranslation *>(sep->getChild(3))->translation = SbVec3f(relPos2.x -relPos1.x, relPos2.y -relPos1.y, 0);
//Reference Position that is scaled according to zoom
dynamic_cast<SoZoomTranslation *>(sep->getChild(3))->translation = SbVec3f(relPos2.x, relPos2.y, 0);
break;
}
else if (geo2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {