+ avoid code repetition in positioning of Sketch

git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5254 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
logari81
2011-12-10 15:14:56 +00:00
parent 6ed7ad3a15
commit fad7696ad4
4 changed files with 45 additions and 55 deletions

View File

@@ -20,7 +20,7 @@
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
# include <TopoDS_Shape.hxx>
@@ -63,25 +63,36 @@ Part2DObject::Part2DObject()
App::DocumentObjectExecReturn *Part2DObject::execute(void)
{
return App::DocumentObject::StdReturn;
}
Base::Placement Part2DObject::positionBySupport(const TopoDS_Face &face, const Base::Placement &Place)
void Part2DObject::positionBySupport(void)
{
if (face.IsNull())
throw Base::Exception("Null Face in Part2DObject::positionBySupport()!");
// recalculate support:
Part::Feature *part = static_cast<Part::Feature*>(Support.getValue());
if (!part || !part->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
return;
bool Reverse = false;
if (face.Orientation() == TopAbs_REVERSED)
Reverse = true;
Base::Placement Place = part->Placement.getValue();
const std::vector<std::string> &sub = Support.getSubValues();
assert(sub.size()==1);
// get the selected sub shape (a Face)
const Part::TopoShape &shape = part->Shape.getShape();
if (shape._Shape.IsNull())
throw Base::Exception("Support shape is empty!");
TopoDS_Shape sh = shape.getSubShape(sub[0].c_str());
const TopoDS_Face &face = TopoDS::Face(sh);
if (face.IsNull())
throw Base::Exception("Null face in Part2DObject::positionBySupport()!");
BRepAdaptor_Surface adapt(face);
if (adapt.GetType() != GeomAbs_Plane)
throw Base::Exception("No planar Face in Part2DObject::positionBySupport()!");
throw Base::Exception("No planar face in Part2DObject::positionBySupport()!");
bool Reverse = false;
if (face.Orientation() == TopAbs_REVERSED)
Reverse = true;
gp_Pnt ObjOrg(Place.getPosition().x,Place.getPosition().y,Place.getPosition().z);
gp_Pln plane = adapt.Plane();
Standard_Boolean ok = plane.Direct();
if (!ok) {
@@ -94,6 +105,8 @@ Base::Placement Part2DObject::positionBySupport(const TopoDS_Face &face, const B
if (Reverse)
Normal.Reverse();
gp_Pnt ObjOrg(Place.getPosition().x,Place.getPosition().y,Place.getPosition().z);
Handle (Geom_Plane) gPlane = new Geom_Plane(plane);
GeomAPI_ProjectPointOnSurf projector(ObjOrg,gPlane);
gp_Pnt SketchBasePoint = projector.NearestPoint();
@@ -168,7 +181,7 @@ Base::Placement Part2DObject::positionBySupport(const TopoDS_Face &face, const B
// check the angle against the Z Axis
//Standard_Real a = Normal.Angle(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1)));
return Base::Placement(mtrx);
Placement.setValue(Base::Placement(mtrx));
}
bool Part2DObject::seekTrimPoints(const std::vector<Geometry *> &geomlist,