From 6a3437e28e304ef95066be29e8aa6c35b8f043c8 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 10 Jan 2015 15:15:18 +0100 Subject: [PATCH] + fixes #0000692: Sketcher: Add angle constraint for arcs --- src/Mod/Sketcher/App/Sketch.cpp | 29 +++++++++----- src/Mod/Sketcher/Gui/CommandConstraints.cpp | 22 +++++++++-- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 43 ++++++++++++++------- 3 files changed, 69 insertions(+), 25 deletions(-) diff --git a/src/Mod/Sketcher/App/Sketch.cpp b/src/Mod/Sketcher/App/Sketch.cpp index c19994abd..6a3e0c475 100644 --- a/src/Mod/Sketcher/App/Sketch.cpp +++ b/src/Mod/Sketcher/App/Sketch.cpp @@ -1376,18 +1376,29 @@ 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]; - GCS::Line &l = Lines[Geoms[geoId].index]; + // add the parameter for the angle + FixParameters.push_back(new double(value)); + double *angle = FixParameters[FixParameters.size()-1]; - // add the parameter for the angle - FixParameters.push_back(new double(value)); - double *angle = FixParameters[FixParameters.size()-1]; + 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]; - int tag = ++ConstraintsCounter; - GCSsys.addConstraintP2PAngle(l.p1, l.p2, angle, tag); - return ConstraintsCounter; + // 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 diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.cpp b/src/Mod/Sketcher/Gui/CommandConstraints.cpp index 851ce1824..da7319a73 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.cpp +++ b/src/Mod/Sketcher/Gui/CommandConstraints.cpp @@ -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(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; } diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 2eb00338c..9358db36e 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -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()) + if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { + const Part::GeomLineSegment *lineSeg = dynamic_cast(geo); + p0 = (lineSeg->getEndPoint()+lineSeg->getStartPoint())/2; + } + else if (geo->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { + const Part::GeomArcOfCircle *arc = dynamic_cast(geo); + p0 = arc->getCenter(); + } + else { return; - const Part::GeomLineSegment *lineSeg = dynamic_cast(geo); - p0 = (lineSeg->getEndPoint()+lineSeg->getStartPoint())/2; + } } 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()) + if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { + const Part::GeomLineSegment *lineSeg = dynamic_cast(geo); + p0 = Base::convertTo((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(geo); + p0 = Base::convertTo(arc->getCenter()); + + Base::Vector3d dir = arc->getEndPoint()-arc->getStartPoint(); + arc->getRange(startangle, endangle); + range = endangle - startangle; + } + else { break; - const Part::GeomLineSegment *lineSeg = dynamic_cast(geo); - - p0 = Base::convertTo((lineSeg->getEndPoint()+lineSeg->getStartPoint())/2); - - Base::Vector3d dir = lineSeg->getEndPoint()-lineSeg->getStartPoint(); - startangle = 0.; - range = atan2(dir.y,dir.x); - endangle = startangle + range; + } } else break;