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
@@ -471,6 +471,20 @@ void Body::onChanged(const App::Property* prop) {
|
||||
}
|
||||
|
||||
}
|
||||
else if (prop == &ShapeMaterial) {
|
||||
std::vector<App::DocumentObject*> features = Group.getValues();
|
||||
if (!features.empty()) {
|
||||
for (auto it : features) {
|
||||
auto feature = dynamic_cast<Part::Feature*>(it);
|
||||
if (feature) {
|
||||
if (feature->ShapeMaterial.getValue().getUUID()
|
||||
!= ShapeMaterial.getValue().getUUID()) {
|
||||
feature->ShapeMaterial.setValue(ShapeMaterial.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Part::BodyBase::onChanged(prop);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -110,6 +110,11 @@ protected:
|
||||
|
||||
void updateSuppressedShape();
|
||||
|
||||
/**
|
||||
* Set the Material To Body Material object
|
||||
*/
|
||||
void setMaterialToBodyMaterial();
|
||||
|
||||
/// Grab any point from the given face
|
||||
static const gp_Pnt getPointFromFace(const TopoDS_Face& f);
|
||||
/// Make a shape from a base plane (convenience method)
|
||||
|
||||
@@ -247,23 +247,11 @@ void ViewProviderBody::updateData(const App::Property* prop)
|
||||
static_cast<PartDesignGui::ViewProvider*>(vp)->setTipIcon(feature == tip);
|
||||
}
|
||||
}
|
||||
|
||||
if (tip)
|
||||
copyColorsfromTip(tip);
|
||||
}
|
||||
|
||||
PartGui::ViewProviderPart::updateData(prop);
|
||||
}
|
||||
|
||||
void ViewProviderBody::copyColorsfromTip(App::DocumentObject* tip) {
|
||||
// update ShapeAppearance
|
||||
Gui::ViewProvider* vptip = Gui::Application::Instance->getViewProvider(tip);
|
||||
if (vptip && vptip->isDerivedFrom(PartGui::ViewProviderPartExt::getClassTypeId())) {
|
||||
auto materials = static_cast<PartGui::ViewProviderPartExt*>(vptip)->ShapeAppearance.getValues();
|
||||
this->ShapeAppearance.setValues(materials);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewProviderBody::slotChangedObjectApp ( const App::DocumentObject& obj, const App::Property& prop ) {
|
||||
|
||||
if(App::GetApplication().isRestoring())
|
||||
|
||||
@@ -97,9 +97,6 @@ protected:
|
||||
/// Set Feature viewprovider into visual body mode
|
||||
void setVisualBodyMode(bool bodymode);
|
||||
|
||||
private:
|
||||
void copyColorsfromTip(App::DocumentObject* tip);
|
||||
|
||||
private:
|
||||
static const char* BodyModeEnum[];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user