Make PartDesign::Boolean work with new Link structure

This is the first feature that used GeoFeatureGroupExtension and required links to the groups inside as well as to things on the same level. Hence a few modifications to link scopes have been nesseccary.
This commit is contained in:
Stefan Tröger
2017-08-04 20:08:52 +02:00
committed by wmayer
parent 4fa3005343
commit 8841fb0805
15 changed files with 124 additions and 83 deletions

View File

@@ -46,7 +46,7 @@ using namespace PartDesign;
namespace PartDesign {
PROPERTY_SOURCE(PartDesign::Boolean, PartDesign::Feature)
PROPERTY_SOURCE_WITH_EXTENSIONS(PartDesign::Boolean, PartDesign::Feature)
const char* Boolean::TypeEnums[]= {"Fuse","Cut","Common","Section",NULL};
@@ -54,13 +54,13 @@ Boolean::Boolean()
{
ADD_PROPERTY(Type,((long)0));
Type.setEnums(TypeEnums);
ADD_PROPERTY(Bodies,(0));
Bodies.setSize(0);
initExtension(this);
}
short Boolean::mustExecute() const
{
if (Bodies.isTouched())
if (Group.isTouched())
return 1;
return PartDesign::Feature::mustExecute();
}
@@ -74,8 +74,8 @@ App::DocumentObjectExecReturn *Boolean::execute(void)
return new App::DocumentObjectExecReturn("Cannot do boolean operation with invalid BaseFeature");
}
std::vector<App::DocumentObject*> bodies = Bodies.getValues();
if (bodies.empty())
std::vector<App::DocumentObject*> tools = Group.getValues();
if (tools.empty())
return App::DocumentObject::StdReturn;
// Get the base shape to operate on
@@ -89,84 +89,66 @@ App::DocumentObjectExecReturn *Boolean::execute(void)
if(!baseBody)
return new App::DocumentObjectExecReturn("Cannot do boolean on feature which is not in a body");
// TODO: Why is Feature::getLocation() protected?
Base::Placement place = baseBody->Placement.getValue();
Base::Rotation rot(place.getRotation());
Base::Vector3d axis;
double angle;
rot.getValue(axis, angle);
gp_Trsf trf;
trf.SetRotation(gp_Ax1(gp_Pnt(), gp_Dir(axis.x, axis.y, axis.z)), angle);
trf.SetTranslationPart(gp_Vec(place.getPosition().x,place.getPosition().y,place.getPosition().z));
TopLoc_Location objLoc(trf);
TopoDS_Shape result = baseTopShape.getShape();
result.Move(objLoc);
// Get the operation type
std::string type = Type.getValueAsString();
for (std::vector<App::DocumentObject*>::const_iterator b = bodies.begin(); b != bodies.end(); b++)
for (auto tool : tools)
{
// Extract the body shape. Its important to get the actual feature that provides the last solid in the body
// so that the placement will be right
PartDesign::Body* body = static_cast<PartDesign::Body*>(*b);
if(!tool->isDerivedFrom(Part::Feature::getClassTypeId()))
return new App::DocumentObjectExecReturn("Cannot do boolean with anything but Part::Feature and its derivatives");
TopoDS_Shape shape = body->Shape.getValue();
// Move the shape to the location of the base shape in the other body
Base::Placement pl = body->Placement.getValue();
// TODO: Why is Feature::getLocation() protected?
Base::Rotation rot(pl.getRotation());
Base::Vector3d axis;
double angle;
rot.getValue(axis, angle);
gp_Trsf trf;
trf.SetRotation(gp_Ax1(gp_Pnt(), gp_Dir(axis.x, axis.y, axis.z)), angle);
trf.SetTranslationPart(gp_Vec(pl.getPosition().x,pl.getPosition().y,pl.getPosition().z));
TopLoc_Location bLoc(trf);
shape.Move(bLoc);
TopoDS_Shape shape = static_cast<Part::Feature*>(tool)->Shape.getValue();
TopoDS_Shape boolOp;
if (type == "Fuse") {
BRepAlgoAPI_Fuse mkFuse(result, shape);
if (!mkFuse.IsDone())
return new App::DocumentObjectExecReturn("Fusion of bodies failed", *b);
return new App::DocumentObjectExecReturn("Fusion of tools failed");
// we have to get the solids (fuse sometimes creates compounds)
boolOp = this->getSolid(mkFuse.Shape());
// lets check if the result is a solid
if (boolOp.IsNull())
return new App::DocumentObjectExecReturn("Resulting shape is not a solid", *b);
return new App::DocumentObjectExecReturn("Resulting shape is not a solid");
} else if (type == "Cut") {
BRepAlgoAPI_Cut mkCut(result, shape);
if (!mkCut.IsDone())
return new App::DocumentObjectExecReturn("Cut out of first body failed", *b);
return new App::DocumentObjectExecReturn("Cut out failed");
boolOp = mkCut.Shape();
} else if (type == "Common") {
BRepAlgoAPI_Common mkCommon(result, shape);
if (!mkCommon.IsDone())
return new App::DocumentObjectExecReturn("Common operation with first body failed", *b);
return new App::DocumentObjectExecReturn("Common operation failed");
boolOp = mkCommon.Shape();
} else if (type == "Section") {
BRepAlgoAPI_Section mkSection(result, shape);
if (!mkSection.IsDone())
return new App::DocumentObjectExecReturn("Section out of first body failed", *b);
return new App::DocumentObjectExecReturn("Section failed");
// we have to get the solids
boolOp = this->getSolid(mkSection.Shape());
// lets check if the result is a solid
if (boolOp.IsNull())
return new App::DocumentObjectExecReturn("Resulting shape is not a solid", *b);
return new App::DocumentObjectExecReturn("Resulting shape is not a solid");
}
result = boolOp; // Use result of this operation for fuse/cut of next body
//bring the result geometry into the correct coordinance of the body the boolean belongs to
BRepBuilderAPI_GTransform mkTrf(result, objLoc.Inverted().Transformation());
result = mkTrf.Shape();
}
this->Shape.setValue(getSolid(result));
return App::DocumentObject::StdReturn;
}
void Boolean::onChanged(const App::Property* prop) {
if(strcmp(prop->getName(), "Group") == 0)
touch();
PartDesign::Feature::onChanged(prop);
}
}