PartDesign: Add method suggesting Revolution Reversed property so that material is always added to the support

This commit is contained in:
logari81 2013-02-14 00:39:10 +01:00
parent 8eef02111d
commit ccf15f968c
2 changed files with 42 additions and 2 deletions

View File

@ -34,6 +34,8 @@
# include <BRepAlgoAPI_Fuse.hxx>
# include <Precision.hxx>
# include <gp_Lin.hxx>
# include <GProp_GProps.hxx>
# include <BRepGProp.hxx>
#endif
#include <Base/Axis.h>
@ -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<double>(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<TopoDS_Wire> 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;
}
}
}

View File

@ -62,6 +62,8 @@ public:
return "PartDesignGui::ViewProviderRevolution";
}
//@}
bool suggestReversed(void) const;
};
} //namespace PartDesign