PartDesign: Apply pattern transform in Feature not VP
This is followup for https://github.com/FreeCAD/FreeCAD/pull/26563 which fixed previews for a given file but broke it for others. This approach should be more robust as it is applied in the Feature itself and not on view provider level which should give us more precise control and per feature transform ability.
This commit is contained in:
committed by
Chris Hennes
parent
800990bacd
commit
4fae2b83f8
@@ -235,19 +235,34 @@ App::DocumentObjectExecReturn* Transformed::recomputePreview()
|
||||
{
|
||||
const auto mode = static_cast<Mode>(TransformMode.getValue());
|
||||
|
||||
const auto makeCompoundOfToolShapes = [this]() {
|
||||
const Part::Feature* supportFeature = getBaseObject();
|
||||
const Part::TopoShape supportShape = supportFeature->Shape.getShape();
|
||||
|
||||
if (supportShape.isNull()) {
|
||||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
|
||||
gp_Trsf supportTransform = supportShape.getShape().Location().Transformation();
|
||||
|
||||
const auto makeCompoundOfToolShapes = [this, &supportTransform]() {
|
||||
BRep_Builder builder;
|
||||
TopoDS_Compound compound;
|
||||
|
||||
builder.MakeCompound(compound);
|
||||
for (const auto& original : getOriginals()) {
|
||||
if (auto* feature = freecad_cast<FeatureAddSub*>(original)) {
|
||||
const auto& shape = feature->AddSubShape.getShape();
|
||||
auto shape = feature->AddSubShape.getShape();
|
||||
|
||||
gp_Trsf trsf = feature->getLocation().Transformation().Multiplied(
|
||||
supportTransform.Inverted()
|
||||
);
|
||||
|
||||
if (shape.isNull()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
shape = shape.makeElementTransform(trsf);
|
||||
|
||||
builder.Add(compound, shape.getShape());
|
||||
}
|
||||
}
|
||||
@@ -260,9 +275,14 @@ App::DocumentObjectExecReturn* Transformed::recomputePreview()
|
||||
PreviewShape.setValue(makeCompoundOfToolShapes());
|
||||
return StdReturn;
|
||||
|
||||
case Mode::WholeShape:
|
||||
PreviewShape.setValue(getBaseShape());
|
||||
case Mode::WholeShape: {
|
||||
auto shape = getBaseTopoShape();
|
||||
shape = shape.makeElementTransform(supportTransform.Inverted());
|
||||
|
||||
PreviewShape.setValue(shape.getShape());
|
||||
|
||||
return StdReturn;
|
||||
}
|
||||
|
||||
default:
|
||||
return FeatureRefine::recomputePreview();
|
||||
|
||||
@@ -104,19 +104,6 @@ void ViewProviderTransformed::updatePreview()
|
||||
|
||||
try {
|
||||
if (auto feature = getObject<PartDesign::Transformed>()) {
|
||||
const Part::Feature* supportFeature = feature->getBaseObject();
|
||||
const Part::TopoShape& supportShape = supportFeature->Shape.getShape();
|
||||
|
||||
if (supportShape.isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Base::Matrix4D invertedSupportMatrix;
|
||||
Part::TopoShape::convertToMatrix(
|
||||
supportShape.getShape().Location().Transformation().Inverted(),
|
||||
invertedSupportMatrix
|
||||
);
|
||||
|
||||
auto originals = feature->getOriginals();
|
||||
auto transforms = feature->getTransformations(originals);
|
||||
|
||||
@@ -133,7 +120,7 @@ void ViewProviderTransformed::updatePreview()
|
||||
auto sep = new SoSeparator;
|
||||
|
||||
auto transformNode = new SoTransform;
|
||||
transformNode->setMatrix(convert(transformMatrix * invertedSupportMatrix));
|
||||
transformNode->setMatrix(convert(transformMatrix));
|
||||
|
||||
sep->addChild(transformNode);
|
||||
sep->addChild(pcPreviewShape);
|
||||
|
||||
Reference in New Issue
Block a user