Changed tree ordering of booleans and bodies

This commit is contained in:
jrheinlaender
2013-05-24 08:23:04 +04:30
committed by Stefan Tröger
parent 106efeec02
commit 026242231e
8 changed files with 104 additions and 45 deletions

View File

@@ -90,7 +90,7 @@ const gp_Pnt Feature::getPointFromFace(const TopoDS_Face& f)
throw Base::Exception("getPointFromFace(): Not implemented yet for this case");
}
const TopoDS_Shape& Feature::getBaseShape() const {
const Part::Feature* Feature::getBaseObject() const {
App::DocumentObject* BaseLink = BaseFeature.getValue();
if (BaseLink == NULL) throw Base::Exception("Base property not set");
Part::Feature* BaseObject = NULL;
@@ -100,6 +100,12 @@ const TopoDS_Shape& Feature::getBaseShape() const {
if (BaseObject == NULL)
throw Base::Exception("No base feature linked");
return BaseObject;
}
const TopoDS_Shape& Feature::getBaseShape() const {
const Part::Feature* BaseObject = getBaseObject();
const TopoDS_Shape& result = BaseObject->Shape.getValue();
if (result.IsNull())
throw Base::Exception("Base feature's shape is invalid");
@@ -110,6 +116,16 @@ const TopoDS_Shape& Feature::getBaseShape() const {
return result;
}
const Part::TopoShape Feature::getBaseTopoShape() const {
const Part::Feature* BaseObject = getBaseObject();
const Part::TopoShape& result = BaseObject->Shape.getShape();
if (result._Shape.IsNull())
throw Base::Exception("Base feature's TopoShape is invalid");
return result;
}
bool Feature::isDatum(const App::DocumentObject* feature)
{
return feature->getTypeId().isDerivedFrom(App::Plane::getClassTypeId()) ||

View File

@@ -57,8 +57,12 @@ public:
static bool isDatum(const App::DocumentObject* feature);
protected:
/// Returns the BaseFeature property's object (if any)
const Part::Feature* getBaseObject() const;
/// Returns the BaseFeature property's shape (if any)
const TopoDS_Shape& getBaseShape() const;
/// Returns the BaseFeature property's TopoShape (if any)
const Part::TopoShape getBaseTopoShape() const;
/**
* Get a solid of the given shape. If no solid is found an exception is raised.

View File

@@ -60,33 +60,36 @@ short Boolean::mustExecute() const
App::DocumentObjectExecReturn *Boolean::execute(void)
{
// Get the base shape to operate on
Part::TopoShape baseTopShape;
try {
baseTopShape = getBaseTopoShape();
} catch (const Base::Exception&) {
return new App::DocumentObjectExecReturn("Cannot do boolean operation with invalid base shape");
}
std::vector<App::DocumentObject*> bodies = Bodies.getValues();
if (bodies.empty())
return App::DocumentObject::StdReturn;
// Get the first body
if (bodies.front() == NULL)
return new App::DocumentObjectExecReturn("No body for boolean");
PartDesign::Body* body = static_cast<PartDesign::Body*>(bodies.front());
const Part::TopoShape& bodyTopShape = body->Shape.getShape();
if (bodyTopShape._Shape.IsNull())
return new App::DocumentObjectExecReturn("Cannot do boolean operation on invalid body shape");
// create an untransformed copy of the body shape
Part::TopoShape bodyShape(bodyTopShape);
bodyShape.setTransform(Base::Matrix4D());
TopoDS_Shape result = bodyShape._Shape;
// create an untransformed copy of the base shape
Part::TopoShape baseShape(baseTopShape);
baseShape.setTransform(Base::Matrix4D());
TopoDS_Shape result = baseShape._Shape;
// Position this feature by the first body
this->Placement.setValue(body->Placement.getValue());
const Part::Feature* baseFeature;
try {
baseFeature = getBaseObject();
} catch (const Base::Exception&) {
return new App::DocumentObjectExecReturn("Cannot do boolean operation with invalid BaseFeature");
}
this->Placement.setValue(baseFeature->Placement.getValue());
// Get the operation type
std::string type = Type.getValueAsString();
std::vector<App::DocumentObject*>::const_iterator b = bodies.begin();
b++;
for (; b != bodies.end(); b++)
for (std::vector<App::DocumentObject*>::const_iterator b = bodies.begin(); b != bodies.end(); b++)
{
// Extract the body shape
PartDesign::Body* body = static_cast<PartDesign::Body*>(*b);