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:
David Carter
2024-10-21 10:04:55 -04:00
committed by Yorik van Havre
parent 5435b3e4db
commit 0804d80ebf
14 changed files with 96 additions and 22 deletions

View File

@@ -86,7 +86,7 @@ App::DocumentObjectExecReturn *Chamfer::execute()
TopoShape res(0);
this->Shape.setValue(res.makeElementShape(mkChamfer,baseTopoShape,Part::OpCodes::Chamfer));
return Part::Feature::execute();
return Part::FilletBase::execute();
}
catch (Standard_Failure& e) {
return new App::DocumentObjectExecReturn(e.GetMessageString());

View File

@@ -69,6 +69,10 @@ App::DocumentObjectExecReturn *Compound::execute()
}
}
this->Shape.setValue(TopoShape().makeElementCompound(shapes));
if (Links.getSize() > 0) {
App::DocumentObject* link = Links.getValues()[0];
copyMaterial(link);
}
return Part::Feature::execute();
}
catch (Standard_Failure& e) {

View File

@@ -90,7 +90,7 @@ App::DocumentObjectExecReturn *Fillet::execute()
TopoShape res(0);
this->Shape.setValue(res.makeElementShape(mkFillet,baseTopoShape,Part::OpCodes::Fillet));
return Part::Feature::execute();
return Part::FilletBase::execute();
}
catch (Standard_Failure& e) {
return new App::DocumentObjectExecReturn(e.GetMessageString());

View File

@@ -257,6 +257,8 @@ App::DocumentObjectExecReturn *Mirroring::execute()
if (shape.isNull())
Standard_Failure::Raise("Cannot mirror empty shape");
this->Shape.setValue(TopoShape(0).makeElementMirror(shape,ax2));
copyMaterial(link);
return Part::Feature::execute();
}
catch (Standard_Failure& e) {

View File

@@ -136,6 +136,7 @@ App::DocumentObjectExecReturn* Boolean::execute()
res = res.makeElementRefine();
}
this->Shape.setValue(res);
copyMaterial(base);
return Part::Feature::execute();
}
catch (...) {

View File

@@ -117,6 +117,10 @@ App::DocumentObjectExecReturn *MultiCommon::execute()
res = res.makeElementRefine();
}
this->Shape.setValue(res);
if (Shapes.getSize() > 0) {
App::DocumentObject* link = Shapes.getValues()[0];
copyMaterial(link);
}
return Part::Feature::execute();
}

View File

@@ -208,6 +208,9 @@ App::DocumentObjectExecReturn *MultiFuse::execute()
}
this->Shape.setValue(res);
this->History.setValues(history);
App::DocumentObject* link = Shapes.getValues()[0];
copyMaterial(link);
return Part::Feature::execute();
}
catch (Standard_Failure& e) {

View File

@@ -128,6 +128,26 @@ PyObject *Feature::getPyObject()
return Py::new_reference_to(PythonObject);
}
void Feature::copyMaterial(Feature* feature)
{
auto mat = Materials::MaterialManager::defaultMaterial();
if (feature) {
if (ShapeMaterial.getValue().getUUID() != feature->ShapeMaterial.getValue().getUUID()) {
if (ShapeMaterial.getValue().getUUID() == mat->getUUID()) {
ShapeMaterial.setValue(feature->ShapeMaterial.getValue());
}
}
}
}
void Feature::copyMaterial(App::DocumentObject* link)
{
auto feature = dynamic_cast<Part::Feature*>(link);
if (feature) {
copyMaterial(feature);
}
}
/**
* Override getElementName to support the Export type. Other calls are passed to the original
* method
@@ -1709,6 +1729,16 @@ short FilletBase::mustExecute() const
return 0;
}
App::DocumentObjectExecReturn* FilletBase::execute()
{
App::DocumentObject* link = this->Base.getValue();
if (!link) {
return new App::DocumentObjectExecReturn("No object linked");
}
copyMaterial(link);
return Part::Feature::execute();
}
void FilletBase::onChanged(const App::Property *prop) {
if(getDocument() && !getDocument()->testStatus(App::Document::Restoring)) {
if(prop == &Edges || prop == &Base) {

View File

@@ -169,6 +169,9 @@ protected:
void onBeforeChange(const App::Property* prop) override;
void onChanged(const App::Property* prop) override;
void copyMaterial(Feature* feature);
void copyMaterial(App::DocumentObject* link);
void registerElementCache(const std::string &prefix, PropertyPartShape *prop);
/** Helper function to obtain mapped and indexed element name from a shape
@@ -210,7 +213,8 @@ public:
App::PropertyLinkSub EdgeLinks;
short mustExecute() const override;
void onUpdateElementReference(const App::Property *prop) override;
App::DocumentObjectExecReturn* execute() override;
void onUpdateElementReference(const App::Property* prop) override;
protected:
void onDocumentRestored() override;