From ae6814ef5abe06fb3bed372fec77126d902f5fad Mon Sep 17 00:00:00 2001 From: logari81 Date: Wed, 31 Oct 2012 23:04:29 +0100 Subject: [PATCH] PartDesign: variable naming improvements and code simplifications --- src/Mod/PartDesign/App/FeatureGroove.cpp | 18 +++++++----- src/Mod/PartDesign/App/FeatureRevolution.cpp | 30 +++++++++++--------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/Mod/PartDesign/App/FeatureGroove.cpp b/src/Mod/PartDesign/App/FeatureGroove.cpp index 017f93a14..72400c9c3 100644 --- a/src/Mod/PartDesign/App/FeatureGroove.cpp +++ b/src/Mod/PartDesign/App/FeatureGroove.cpp @@ -135,8 +135,8 @@ App::DocumentObjectExecReturn *Groove::execute(void) try { // TopoDS::Face is not strictly necessary, but it will through an exception for // invalid wires e.g. intersections or multiple separate wires - TopoDS_Shape aFace = TopoDS::Face(makeFace(wires)); - if (aFace.IsNull()) + TopoDS_Shape sketchshape = TopoDS::Face(makeFace(wires)); + if (sketchshape.IsNull()) return new App::DocumentObjectExecReturn("Creating a face from sketch failed"); // Rotate the face by half the angle to get Groove symmetric to sketch plane @@ -144,25 +144,26 @@ App::DocumentObjectExecReturn *Groove::execute(void) gp_Trsf mov; mov.SetRotation(gp_Ax1(pnt, dir), Base::toRadians(Angle.getValue()) * (-1.0) / 2.0); TopLoc_Location loc(mov); - aFace.Move(loc); + sketchshape.Move(loc); } this->positionBySketch(); TopLoc_Location invObjLoc = this->getLocation().Inverted(); pnt.Transform(invObjLoc.Transformation()); dir.Transform(invObjLoc.Transformation()); + support.Move(invObjLoc); + sketchshape.Move(invObjLoc); // revolve the face to a solid - BRepPrimAPI_MakeRevol RevolMaker(aFace.Moved(invObjLoc), gp_Ax1(pnt, dir), angle); + BRepPrimAPI_MakeRevol RevolMaker(sketchshape, gp_Ax1(pnt, dir), angle); if (RevolMaker.IsDone()) { TopoDS_Shape result = RevolMaker.Shape(); - - // Set the subtractive shape property for later usage in e.g. pattern + // set the subtractive shape property for later usage in e.g. pattern this->SubShape.setValue(result); // cut out groove to get one result object - BRepAlgoAPI_Cut mkCut(support.Moved(invObjLoc), result); + BRepAlgoAPI_Cut mkCut(support, result); // Let's check if the fusion has been successful if (!mkCut.IsDone()) throw Base::Exception("Cut out of support failed"); @@ -187,6 +188,9 @@ App::DocumentObjectExecReturn *Groove::execute(void) else return new App::DocumentObjectExecReturn(e->GetMessageString()); } + catch (Base::Exception& e) { + return new App::DocumentObjectExecReturn(e.what()); + } } } diff --git a/src/Mod/PartDesign/App/FeatureRevolution.cpp b/src/Mod/PartDesign/App/FeatureRevolution.cpp index 2460b1186..edb3c3b0f 100644 --- a/src/Mod/PartDesign/App/FeatureRevolution.cpp +++ b/src/Mod/PartDesign/App/FeatureRevolution.cpp @@ -71,12 +71,17 @@ short Revolution::mustExecute() const App::DocumentObjectExecReturn *Revolution::execute(void) { // Validate parameters - double a = Angle.getValue(); - if (a < Precision::Confusion()) + double angle = Angle.getValue(); + if (angle < Precision::Confusion()) return new App::DocumentObjectExecReturn("Angle of groove too small"); - if (a > 360.0) + if (angle > 360.0) return new App::DocumentObjectExecReturn("Angle of groove too large"); + angle = Base::toRadians(angle); + // Reverse angle if selected + if (Reversed.getValue() && !Midplane.getValue()) + angle *= (-1.0); + Part::Part2DObject* sketch = 0; std::vector wires; try { @@ -136,30 +141,27 @@ App::DocumentObjectExecReturn *Revolution::execute(void) try { // TopoDS::Face is not strictly necessary, but it will through an exception for // invalid wires e.g. intersections or multiple separate wires - TopoDS_Shape aFace = TopoDS::Face(makeFace(wires)); - if (aFace.IsNull()) + TopoDS_Shape sketchshape = TopoDS::Face(makeFace(wires)); + if (sketchshape.IsNull()) return new App::DocumentObjectExecReturn("Creating a face from sketch failed"); - // Rotate the face by half the angle to get revolution symmetric to sketch plane + // Rotate the face by half the angle to get Revolution symmetric to sketch plane if (Midplane.getValue()) { gp_Trsf mov; mov.SetRotation(gp_Ax1(pnt, dir), Base::toRadians(Angle.getValue()) * (-1.0) / 2.0); TopLoc_Location loc(mov); - aFace.Move(loc); + sketchshape.Move(loc); } this->positionBySketch(); TopLoc_Location invObjLoc = this->getLocation().Inverted(); pnt.Transform(invObjLoc.Transformation()); dir.Transform(invObjLoc.Transformation()); - - // Reverse angle if selected - double angle = Base::toRadians(Angle.getValue()); - if (Reversed.getValue() && !Midplane.getValue()) - angle *= (-1.0); + support.Move(invObjLoc); + sketchshape.Move(invObjLoc); // revolve the face to a solid - BRepPrimAPI_MakeRevol RevolMaker(aFace.Moved(invObjLoc), gp_Ax1(pnt, dir), angle); + BRepPrimAPI_MakeRevol RevolMaker(sketchshape, gp_Ax1(pnt, dir), angle); if (RevolMaker.IsDone()) { TopoDS_Shape result = RevolMaker.Shape(); @@ -169,7 +171,7 @@ App::DocumentObjectExecReturn *Revolution::execute(void) // if the sketch has a support fuse them to get one result object (PAD!) if (!support.IsNull()) { // Let's call algorithm computing a fuse operation: - BRepAlgoAPI_Fuse mkFuse(support.Moved(invObjLoc), result); + BRepAlgoAPI_Fuse mkFuse(support, result); // Let's check if the fusion has been successful if (!mkFuse.IsDone()) throw Base::Exception("Fusion with support failed");