Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PartDesign: fix Shapebinder placement #1945

Merged
merged 2 commits into from Feb 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 26 additions & 21 deletions src/Mod/PartDesign/App/ShapeBinder.cpp
Expand Up @@ -25,6 +25,7 @@
#ifndef _PreComp_
#include <cfloat>
#include <boost/bind.hpp>
#include <BRep_Builder.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#endif

Expand Down Expand Up @@ -75,16 +76,20 @@ App::DocumentObjectExecReturn* ShapeBinder::execute(void) {
//if we have a link we rebuild the shape, but we change nothing if we are a simple copy
if (obj) {
Part::TopoShape shape = ShapeBinder::buildShapeFromReferences(obj, subs);
Base::Placement placement(shape.getTransform());
Shape.setValue(shape);
//now, shape is in object's CS, and includes local Placement of obj but nothing else.

if (TraceSupport.getValue()) {
// this is the inverted global placement of the parent group ...
placement = this->globalPlacement() * Placement.getValue().inverse();
// multiplied with the global placement of the support shape
placement = placement.inverse() * obj->globalPlacement();
//compute the transform, and apply it to the shape.
Base::Placement sourceCS = //full placement of container of obj
obj->globalPlacement() * obj->Placement.getValue().inverse();
Base::Placement targetCS = //full placement of container of this shapebinder
this->globalPlacement() * this->Placement.getValue().inverse();
Base::Placement transform = targetCS.inverse() * sourceCS;
shape.setPlacement(transform * shape.getPlacement());
}
Placement.setValue(placement);

this->Placement.setValue(shape.getTransform());
this->Shape.setValue(shape);
}
}

Expand Down Expand Up @@ -145,24 +150,24 @@ Part::TopoShape ShapeBinder::buildShapeFromReferences( Part::Feature* obj, std::
if (subs.empty())
return obj->Shape.getShape();

//if we use multiple subshapes we build a shape from them by fusing them together
Part::TopoShape base;
std::vector<TopoDS_Shape> operators;
std::vector<TopoDS_Shape> shapes;
for (std::string sub : subs) {
if (base.isNull())
base = obj->Shape.getShape().getSubShape(sub.c_str());
else
operators.push_back(obj->Shape.getShape().getSubShape(sub.c_str()));
shapes.push_back(obj->Shape.getShape().getSubShape(sub.c_str()));
}

try {
if (!operators.empty() && !base.isNull())
return base.fuse(operators);
}
catch (...) {
return base;
if (shapes.size() == 1){
//single subshape. Return directly.
return shapes[0];
} else {
//multiple subshapes. Make a compound.
BRep_Builder builder;
TopoDS_Compound cmp;
builder.MakeCompound(cmp);
for(const TopoDS_Shape& sh : shapes){
builder.Add(cmp, sh);
}
return cmp;
}
return base;
}

void ShapeBinder::handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property *prop)
Expand Down