Materials: Child ignoring parent material
Inherit the material from the parent object when creating a new object, such as during a boolean operation, or when extruding a sketch. fixes #15503
This commit is contained in:
committed by
Yorik van Havre
parent
5435b3e4db
commit
0804d80ebf
@@ -32,11 +32,11 @@
|
||||
# include <TopoDS.hxx>
|
||||
#endif
|
||||
|
||||
#include "App/OriginFeature.h"
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/FeaturePythonPyImp.h>
|
||||
#include <App/ElementNamingUtils.h>
|
||||
#include "App/OriginFeature.h"
|
||||
#include <App/FeaturePythonPyImp.h>
|
||||
#include <Base/Console.h>
|
||||
|
||||
#include "Feature.h"
|
||||
@@ -66,6 +66,8 @@ Feature::Feature()
|
||||
|
||||
App::DocumentObjectExecReturn* Feature::recompute()
|
||||
{
|
||||
setMaterialToBodyMaterial();
|
||||
|
||||
SuppressedShape.setValue(TopoShape());
|
||||
|
||||
if (!Suppressed.getValue()) {
|
||||
@@ -97,6 +99,18 @@ App::DocumentObjectExecReturn* Feature::recompute()
|
||||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
|
||||
void Feature::setMaterialToBodyMaterial()
|
||||
{
|
||||
auto body = getFeatureBody();
|
||||
if (body) {
|
||||
// Ensure the part has the same material as the body
|
||||
auto feature = dynamic_cast<Part::Feature*>(body);
|
||||
if (feature) {
|
||||
copyMaterial(feature);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Feature::updateSuppressedShape()
|
||||
{
|
||||
auto baseShape = getBaseTopoShape(true);
|
||||
@@ -166,6 +180,14 @@ void Feature::onChanged(const App::Property *prop)
|
||||
body->insertObject(BaseFeature.getValue(), this);
|
||||
}
|
||||
}
|
||||
} else if (prop == &ShapeMaterial) {
|
||||
auto body = Body::findBodyOf(this);
|
||||
if (body) {
|
||||
if (body->ShapeMaterial.getValue().getUUID()
|
||||
!= ShapeMaterial.getValue().getUUID()) {
|
||||
body->ShapeMaterial.setValue(ShapeMaterial.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Part::Feature::onChanged(prop);
|
||||
@@ -375,7 +397,7 @@ Body* Feature::getFeatureBody() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
App::DocumentObject *Feature::getSubObject(const char *subname,
|
||||
App::DocumentObject *Feature::getSubObject(const char *subname,
|
||||
PyObject **pyObj, Base::Matrix4D *pmat, bool transform, int depth) const
|
||||
{
|
||||
if (subname && subname != Data::findElementName(subname)) {
|
||||
@@ -400,7 +422,7 @@ App::DocumentObject *Feature::getSubObject(const char *subname,
|
||||
// an inverse transform.
|
||||
_mat = Placement.getValue().inverse().toMatrix();
|
||||
if (pmat)
|
||||
*pmat *= _mat;
|
||||
*pmat *= _mat;
|
||||
else
|
||||
pmat = &_mat;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user