+ fixes #0000692: Sketcher: Add angle constraint for arcs

This commit is contained in:
wmayer 2015-01-10 15:15:18 +01:00
parent 2bff32d704
commit 6a3437e28e
3 changed files with 69 additions and 25 deletions

View File

@ -1376,9 +1376,7 @@ int Sketch::addAngleConstraint(int geoId, double value)
{
geoId = checkGeoId(geoId);
if (Geoms[geoId].type != Line)
return -1;
if (Geoms[geoId].type == Line) {
GCS::Line &l = Lines[Geoms[geoId].index];
// add the parameter for the angle
@ -1388,6 +1386,19 @@ int Sketch::addAngleConstraint(int geoId, double value)
int tag = ++ConstraintsCounter;
GCSsys.addConstraintP2PAngle(l.p1, l.p2, angle, tag);
return ConstraintsCounter;
}
else if (Geoms[geoId].type == Arc) {
GCS::Arc &a = Arcs[Geoms[geoId].index];
// add the parameter for the angle
FixParameters.push_back(new double(value));
double *angle = FixParameters[FixParameters.size()-1];
int tag = ++ConstraintsCounter;
GCSsys.addConstraintL2LAngle(a.center, a.start, a.center, a.end, angle, tag);
return ConstraintsCounter;
}
return -1;
}
// line to line angle constraint

View File

@ -2070,7 +2070,7 @@ void CmdSketcherConstrainAngle::activated(int iMsg)
if (isEdge(GeoId1, PosId1) && isEdge(GeoId2, PosId2) && isVertex(GeoId3, PosId3)) {
double ActAngle = 0.0;
openCommand("add angle constraint");
openCommand("Add angle constraint");
//add missing point-on-object constraints
if(! IsPointAlreadyOnCurve(GeoId1, GeoId3, PosId3, Obj)){
@ -2163,7 +2163,7 @@ void CmdSketcherConstrainAngle::activated(int iMsg)
std::swap(PosId1,PosId2);
}
openCommand("add angle constraint");
openCommand("Add angle constraint");
Gui::Command::doCommand(
Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Angle',%d,%d,%d,%d,%f)) ",
selection[0].getFeatName(),GeoId1,PosId1,GeoId2,PosId2,ActAngle);
@ -2187,12 +2187,28 @@ void CmdSketcherConstrainAngle::activated(int iMsg)
Base::Vector3d dir = lineSeg->getEndPoint()-lineSeg->getStartPoint();
double ActAngle = atan2(dir.y,dir.x);
openCommand("add angle constraint");
openCommand("Add angle constraint");
Gui::Command::doCommand(
Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Angle',%d,%f)) ",
selection[0].getFeatName(),GeoId1,ActAngle);
commitCommand();
finishDistanceConstraint(this, Obj);
return;
}
else if (geom->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) {
const Part::GeomArcOfCircle *arc;
arc = dynamic_cast<const Part::GeomArcOfCircle*>(geom);
double startangle, endangle;
arc->getRange(startangle, endangle);
double angle = endangle - startangle;
openCommand("Add angle constraint");
Gui::Command::doCommand(
Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Angle',%d,%f)) ",
selection[0].getFeatName(),GeoId1,angle);
commitCommand();
finishDistanceConstraint(this, Obj);
return;
}

View File

@ -1265,12 +1265,19 @@ void ViewProviderSketch::moveConstraint(int constNum, const Base::Vector2D &toPo
dir2.RotateZ(-M_PI/2);
}
} else if (Constr->First != Constraint::GeoUndef) { // line angle
} else if (Constr->First != Constraint::GeoUndef) { // line/arc angle
const Part::Geometry *geo = GeoById(geomlist, Constr->First);
if (geo->getTypeId() != Part::GeomLineSegment::getClassTypeId())
return;
if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
const Part::GeomLineSegment *lineSeg = dynamic_cast<const Part::GeomLineSegment *>(geo);
p0 = (lineSeg->getEndPoint()+lineSeg->getStartPoint())/2;
}
else if (geo->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) {
const Part::GeomArcOfCircle *arc = dynamic_cast<const Part::GeomArcOfCircle *>(geo);
p0 = arc->getCenter();
}
else {
return;
}
} else
return;
@ -3721,16 +3728,26 @@ Restart:
} else if (Constr->First != Constraint::GeoUndef) {
const Part::Geometry *geo = GeoById(*geomlist, Constr->First);
if (geo->getTypeId() != Part::GeomLineSegment::getClassTypeId())
break;
if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
const Part::GeomLineSegment *lineSeg = dynamic_cast<const Part::GeomLineSegment *>(geo);
p0 = Base::convertTo<SbVec3f>((lineSeg->getEndPoint()+lineSeg->getStartPoint())/2);
Base::Vector3d dir = lineSeg->getEndPoint()-lineSeg->getStartPoint();
startangle = 0.;
range = atan2(dir.y,dir.x);
endangle = startangle + range;
}
else if (geo->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) {
const Part::GeomArcOfCircle *arc = dynamic_cast<const Part::GeomArcOfCircle *>(geo);
p0 = Base::convertTo<SbVec3f>(arc->getCenter());
Base::Vector3d dir = arc->getEndPoint()-arc->getStartPoint();
arc->getRange(startangle, endangle);
range = endangle - startangle;
}
else {
break;
}
} else
break;