From ccf15f968c905852fb1c2f938a82a2db800ca2de Mon Sep 17 00:00:00 2001 From: logari81 Date: Thu, 14 Feb 2013 00:39:10 +0100 Subject: [PATCH] PartDesign: Add method suggesting Revolution Reversed property so that material is always added to the support --- src/Mod/PartDesign/App/FeatureRevolution.cpp | 42 +++++++++++++++++++- src/Mod/PartDesign/App/FeatureRevolution.h | 2 + 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/Mod/PartDesign/App/FeatureRevolution.cpp b/src/Mod/PartDesign/App/FeatureRevolution.cpp index 84d0eba8e..6745da5f4 100644 --- a/src/Mod/PartDesign/App/FeatureRevolution.cpp +++ b/src/Mod/PartDesign/App/FeatureRevolution.cpp @@ -34,6 +34,8 @@ # include # include # include +# include +# include #endif #include @@ -75,9 +77,9 @@ App::DocumentObjectExecReturn *Revolution::execute(void) // Validate parameters double angle = Angle.getValue(); if (angle < Precision::Confusion()) - return new App::DocumentObjectExecReturn("Angle of groove too small"); + return new App::DocumentObjectExecReturn("Angle of revolution too small"); if (angle > 360.0) - return new App::DocumentObjectExecReturn("Angle of groove too large"); + return new App::DocumentObjectExecReturn("Angle of revolution too large"); angle = Base::toRadians(angle); // Reverse angle if selected @@ -204,5 +206,41 @@ App::DocumentObjectExecReturn *Revolution::execute(void) return new App::DocumentObjectExecReturn(e.what()); } } + +bool Revolution::suggestReversed(void) const +{ + // suggest a value for Reversed flag so that material is added to the support + try { + Part::Part2DObject* sketch = getVerifiedSketch(); + std::vector wires = getSketchWires(); + TopoDS_Shape sketchshape = makeFace(wires); + + Base::Vector3f b = Base.getValue(); + Base::Vector3f v = Axis.getValue(); + + // get centre of gravity of the sketch face + GProp_GProps props; + BRepGProp::SurfaceProperties(sketchshape, props); + gp_Pnt cog = props.CentreOfMass(); + Base::Vector3f p_cog(cog.X(), cog.Y(), cog.Z()); + // get direction to cog from its projection on the revolve axis + Base::Vector3f perp_dir = p_cog - p_cog.Perpendicular(b, v); + // get cross product of projection direction with revolve axis direction + Base::Vector3f cross = v % perp_dir; + // get sketch vector pointing away from support material + Base::Placement SketchPos = sketch->Placement.getValue(); + Base::Rotation SketchOrientation = SketchPos.getRotation(); + Base::Vector3d SketchNormal(0,0,1); + SketchOrientation.multVec(SketchNormal,SketchNormal); + // simply convert double to float + Base::Vector3f norm(SketchNormal.x, SketchNormal.y, SketchNormal.z); + + // return true if the angle between norm and cross is acute + return norm * cross < 0.f; + } + catch (...) { + return false; + } +} } diff --git a/src/Mod/PartDesign/App/FeatureRevolution.h b/src/Mod/PartDesign/App/FeatureRevolution.h index 485c851f6..89a79b5a3 100644 --- a/src/Mod/PartDesign/App/FeatureRevolution.h +++ b/src/Mod/PartDesign/App/FeatureRevolution.h @@ -62,6 +62,8 @@ public: return "PartDesignGui::ViewProviderRevolution"; } //@} + + bool suggestReversed(void) const; }; } //namespace PartDesign