From c3da141020f478b393954c94edc0de650f504c42 Mon Sep 17 00:00:00 2001 From: DeepSOIC Date: Mon, 20 Jul 2015 00:01:19 +0300 Subject: [PATCH] Revolution: fix failure on sketch edges used as an axis PartDesign Revolution used to fail, when an edge of a sketch was selected as an axis of revolution. This is fixed by this commit. Also, made it support selecting an edge from the sketch the revolution itself is made from. --- src/Mod/PartDesign/App/FeatureSketchBased.cpp | 58 +++++++++++-------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/src/Mod/PartDesign/App/FeatureSketchBased.cpp b/src/Mod/PartDesign/App/FeatureSketchBased.cpp index 23977fcd8..4b0aa05f8 100644 --- a/src/Mod/PartDesign/App/FeatureSketchBased.cpp +++ b/src/Mod/PartDesign/App/FeatureSketchBased.cpp @@ -1020,8 +1020,10 @@ void SketchBased::getAxis(const App::DocumentObject *pcReferenceAxis, const std: // Check that axis is perpendicular with sketch plane! if (sketchplane.Axis().Direction().Angle(gp_Dir(dir.x, dir.y, dir.z))< Precision::Angular()) throw Base::Exception("Rotation axis must not be perpendicular with the sketch plane"); + return; } - else if (pcReferenceAxis->getTypeId().isDerivedFrom(App::Line::getClassTypeId())) { + + if (pcReferenceAxis->getTypeId().isDerivedFrom(App::Line::getClassTypeId())) { const App::Line* line = static_cast(pcReferenceAxis); base = Base::Vector3d(0,0,0); if( strcmp(line->LineType.getValue(), App::Part::BaselineTypes[0]) == 0) @@ -1034,8 +1036,34 @@ void SketchBased::getAxis(const App::DocumentObject *pcReferenceAxis, const std: // Check that axis is perpendicular with sketch plane! if (sketchplane.Axis().Direction().Angle(gp_Dir(dir.x, dir.y, dir.z)) < Precision::Angular()) throw Base::Exception("Rotation axis must not be perpendicular with the sketch plane"); + return; } - else if (pcReferenceAxis->getTypeId().isDerivedFrom(PartDesign::Feature::getClassTypeId())) { + + if (pcReferenceAxis == sketch){ + bool hasValidAxis=false; + Base::Axis axis; + if (subReferenceAxis[0] == "V_Axis") { + hasValidAxis = true; + axis = sketch->getAxis(Part::Part2DObject::V_Axis); + } else if (subReferenceAxis[0] == "H_Axis") { + hasValidAxis = true; + axis = sketch->getAxis(Part::Part2DObject::H_Axis); + } else if (subReferenceAxis[0].size() > 4 && subReferenceAxis[0].substr(0,4) == "Axis") { + int AxId = std::atoi(subReferenceAxis[0].substr(4,4000).c_str()); + if (AxId >= 0 && AxId < sketch->getAxisCount()) { + hasValidAxis = true; + axis = sketch->getAxis(AxId); + } + } + if (hasValidAxis) { + axis *= SketchPlm; + base=axis.getBase(); + dir=axis.getDirection(); + return; + } //else - an edge of the sketch was selected as an axis + } + + if (pcReferenceAxis->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { if (subReferenceAxis.empty()) throw Base::Exception("No rotation axis reference specified"); const Part::Feature* refFeature = static_cast(pcReferenceAxis); @@ -1058,33 +1086,13 @@ void SketchBased::getAxis(const App::DocumentObject *pcReferenceAxis, const std: // Check that axis is perpendicular with sketch plane! if (sketchplane.Axis().Direction().Angle(d) < Precision::Angular()) throw Base::Exception("Rotation axis must not be perpendicular with the sketch plane"); + return; } else { throw Base::Exception("Rotation reference must be an edge"); } - } else if (pcReferenceAxis && pcReferenceAxis == sketch) { - bool hasValidAxis=false; - Base::Axis axis; - if (subReferenceAxis[0] == "V_Axis") { - hasValidAxis = true; - axis = sketch->getAxis(Part::Part2DObject::V_Axis); - } - else if (subReferenceAxis[0] == "H_Axis") { - hasValidAxis = true; - axis = sketch->getAxis(Part::Part2DObject::H_Axis); - } - else if (subReferenceAxis[0].size() > 4 && subReferenceAxis[0].substr(0,4) == "Axis") { - int AxId = std::atoi(subReferenceAxis[0].substr(4,4000).c_str()); - if (AxId >= 0 && AxId < sketch->getAxisCount()) { - hasValidAxis = true; - axis = sketch->getAxis(AxId); - } - } - if (hasValidAxis) { - axis *= SketchPlm; - base=axis.getBase(); - dir=axis.getDirection(); - } } + + throw Base::Exception("Rotation axis reference is invalid"); } TopoDS_Shape SketchBased::refineShapeIfActive(const TopoDS_Shape& oldShape) const