From e3aba1ca5972afba099c4c1283e434e229bfd4e2 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 18 Apr 2024 13:35:36 +0200 Subject: [PATCH 1/3] App: Imrove exception handling in MaterialPy --- src/App/MaterialPyImp.cpp | 75 +++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 23 deletions(-) diff --git a/src/App/MaterialPyImp.cpp b/src/App/MaterialPyImp.cpp index bf7979106d..867ac18280 100644 --- a/src/App/MaterialPyImp.cpp +++ b/src/App/MaterialPyImp.cpp @@ -143,31 +143,36 @@ int MaterialPy::PyInit(PyObject* args, PyObject* kwds) return -1; } - if (diffuse) { - setDiffuseColor(Py::Object(diffuse)); - } + try { + if (diffuse) { + setDiffuseColor(Py::Object(diffuse)); + } - if (ambient) { - setAmbientColor(Py::Object(ambient)); - } + if (ambient) { + setAmbientColor(Py::Object(ambient)); + } - if (specular) { - setSpecularColor(Py::Object(specular)); - } + if (specular) { + setSpecularColor(Py::Object(specular)); + } - if (emissive) { - setEmissiveColor(Py::Object(emissive)); - } + if (emissive) { + setEmissiveColor(Py::Object(emissive)); + } - if (shininess) { - setShininess(Py::Float(shininess)); - } + if (shininess) { + setShininess(Py::Float(shininess)); + } - if (transparency) { - setTransparency(Py::Float(transparency)); - } + if (transparency) { + setTransparency(Py::Float(transparency)); + } - return 0; + return 0; + } + catch (const Py::Exception&) { + return -1; + } } // returns a string which represents the object e.g. when printed in python @@ -200,7 +205,13 @@ Py::Object MaterialPy::getAmbientColor() const void MaterialPy::setAmbientColor(Py::Object arg) { - getMaterialPtr()->ambientColor = toColor(*arg); + try { + getMaterialPtr()->ambientColor = toColor(*arg); + } + catch (const Base::Exception& e) { + e.setPyException(); + throw Py::Exception(); + } } Py::Object MaterialPy::getDiffuseColor() const @@ -215,7 +226,13 @@ Py::Object MaterialPy::getDiffuseColor() const void MaterialPy::setDiffuseColor(Py::Object arg) { - getMaterialPtr()->diffuseColor = toColor(*arg); + try { + getMaterialPtr()->diffuseColor = toColor(*arg); + } + catch (const Base::Exception& e) { + e.setPyException(); + throw Py::Exception(); + } } Py::Object MaterialPy::getEmissiveColor() const @@ -230,7 +247,13 @@ Py::Object MaterialPy::getEmissiveColor() const void MaterialPy::setEmissiveColor(Py::Object arg) { - getMaterialPtr()->emissiveColor = toColor(*arg); + try { + getMaterialPtr()->emissiveColor = toColor(*arg); + } + catch (const Base::Exception& e) { + e.setPyException(); + throw Py::Exception(); + } } Py::Object MaterialPy::getSpecularColor() const @@ -245,7 +268,13 @@ Py::Object MaterialPy::getSpecularColor() const void MaterialPy::setSpecularColor(Py::Object arg) { - getMaterialPtr()->specularColor = toColor(*arg); + try { + getMaterialPtr()->specularColor = toColor(*arg); + } + catch (const Base::Exception& e) { + e.setPyException(); + throw Py::Exception(); + } } Py::Float MaterialPy::getShininess() const From 378f72029187c346485cb6b6e1b709500c5a2946 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 18 Apr 2024 13:46:59 +0200 Subject: [PATCH 2/3] Arch: fix regressions with material handling --- src/Mod/Arch/ArchFence.py | 2 +- src/Mod/Arch/ArchSpace.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mod/Arch/ArchFence.py b/src/Mod/Arch/ArchFence.py index e7930fc251..89a436954b 100644 --- a/src/Mod/Arch/ArchFence.py +++ b/src/Mod/Arch/ArchFence.py @@ -302,7 +302,7 @@ class _ViewProviderFence(ArchComponent.ViewProviderComponent): def applyColors(self, obj): if not hasattr(obj.ViewObject, "UseOriginalColors") or not obj.ViewObject.UseOriginalColors: - obj.ViewObject.DiffuseColor = [obj.ViewObject.ShapeAppeaarance.DiffuseColor] + obj.ViewObject.DiffuseColor = [obj.ViewObject.ShapeAppeaarance[0].DiffuseColor] else: post = obj.Post section = obj.Section diff --git a/src/Mod/Arch/ArchSpace.py b/src/Mod/Arch/ArchSpace.py index 7e2e998c76..82224e0da9 100644 --- a/src/Mod/Arch/ArchSpace.py +++ b/src/Mod/Arch/ArchSpace.py @@ -727,7 +727,7 @@ class _ViewProviderSpace(ArchComponent.ViewProviderComponent): elif prop == "ShapeColor": if hasattr(vobj,"ShapeColor"): - self.fmat = vobj.ShapeColor.getValue() + self.fmat.diffuseColor.setValue((vobj.ShapeColor[0],vobj.ShapeColor[1],vobj.ShapeColor[2])) elif prop == "Transparency": if hasattr(vobj,"Transparency"): From 550fd359c0bc266cad6870b08bcc191a41110001 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 18 Apr 2024 13:57:48 +0200 Subject: [PATCH 3/3] CAM: fix regressions with material handling The ShapeAppearance is a list of materials and thus assigning a color with 'obj.ViewObject.ShapeAppearance.DiffuseColor = color' is incorrect. But doing it with 'obj.ViewObject.ShapeAppearance[0].DiffuseColor = color' doesn't work as expected because the internal notification doesn't work with a list. So, the only viable way is to revert the changes and do it by assigning the color to the 'ShapeColor' attribute. --- src/Mod/CAM/Path/Dressup/Gui/Dogbone.py | 4 ++-- src/Mod/CAM/Path/Dressup/Gui/ZCorrect.py | 2 +- src/Mod/CAM/Path/Dressup/Tags.py | 6 +++--- src/Mod/CAM/Path/Main/Gui/Simulator.py | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Mod/CAM/Path/Dressup/Gui/Dogbone.py b/src/Mod/CAM/Path/Dressup/Gui/Dogbone.py index 3fb153a2be..f3b4a8d619 100644 --- a/src/Mod/CAM/Path/Dressup/Gui/Dogbone.py +++ b/src/Mod/CAM/Path/Dressup/Gui/Dogbone.py @@ -59,7 +59,7 @@ def debugMarker(vector, label, color=None, radius=0.5): vector, FreeCAD.Rotation(FreeCAD.Vector(0, 0, 1), 0) ) if color: - obj.ViewObject.ShapeAppearance.DiffuseColor = color + obj.ViewObject.ShapeColor = color def debugCircle(vector, r, label, color=None): @@ -73,7 +73,7 @@ def debugCircle(vector, r, label, color=None): ) obj.ViewObject.Transparency = 90 if color: - obj.ViewObject.ShapeAppearance.DiffuseColor = color + obj.ViewObject.ShapeColor = color def addAngle(a1, a2): diff --git a/src/Mod/CAM/Path/Dressup/Gui/ZCorrect.py b/src/Mod/CAM/Path/Dressup/Gui/ZCorrect.py index 8de1c58ab2..d4c038c5b4 100644 --- a/src/Mod/CAM/Path/Dressup/Gui/ZCorrect.py +++ b/src/Mod/CAM/Path/Dressup/Gui/ZCorrect.py @@ -231,7 +231,7 @@ class TaskPanel: ) self.interpshape.Shape = obj.interpSurface self.interpshape.ViewObject.Transparency = 60 - self.interpshape.ViewObject.ShapeAppearance.DiffuseColor = (1.00000, 1.00000, 0.01961) + self.interpshape.ViewObject.ShapeColor = (1.00000, 1.00000, 0.01961) self.interpshape.ViewObject.Selectable = False stock = PathUtils.findParentJob(obj).Stock self.interpshape.Placement.Base.z = stock.Shape.BoundBox.ZMax diff --git a/src/Mod/CAM/Path/Dressup/Tags.py b/src/Mod/CAM/Path/Dressup/Tags.py index 52919dc04a..f9b24ec2d2 100644 --- a/src/Mod/CAM/Path/Dressup/Tags.py +++ b/src/Mod/CAM/Path/Dressup/Tags.py @@ -83,7 +83,7 @@ def debugMarker(vector, label, color=None, radius=0.5): vector, FreeCAD.Rotation(FreeCAD.Vector(0, 0, 1), 0) ) if color: - obj.ViewObject.ShapeAppearance.DiffuseColor = color + obj.ViewObject.ShapeColor = color def debugCylinder(vector, r, height, label, color=None): @@ -97,7 +97,7 @@ def debugCylinder(vector, r, height, label, color=None): ) obj.ViewObject.Transparency = 90 if color: - obj.ViewObject.ShapeAppearance.DiffuseColor = color + obj.ViewObject.ShapeColor = color def debugCone(vector, r1, r2, height, label, color=None): @@ -112,7 +112,7 @@ def debugCone(vector, r1, r2, height, label, color=None): ) obj.ViewObject.Transparency = 90 if color: - obj.ViewObject.ShapeAppearance.DiffuseColor = color + obj.ViewObject.ShapeColor = color class Tag: diff --git a/src/Mod/CAM/Path/Main/Gui/Simulator.py b/src/Mod/CAM/Path/Main/Gui/Simulator.py index 98b21d6c5e..0e4b53cf43 100644 --- a/src/Mod/CAM/Path/Main/Gui/Simulator.py +++ b/src/Mod/CAM/Path/Main/Gui/Simulator.py @@ -228,7 +228,7 @@ class PathSimulation: ) self.cutMaterialIn.ViewObject.Proxy = 0 self.cutMaterialIn.ViewObject.show() - self.cutMaterialIn.ViewObject.ShapeAppearance.DiffuseColor = (1.0, 0.85, 0.45, 0.0) + self.cutMaterialIn.ViewObject.ShapeColor = (1.0, 0.85, 0.45, 0.0) else: self.cutMaterial = FreeCAD.ActiveDocument.addObject( "Part::FeaturePython", "CutMaterial" @@ -236,7 +236,7 @@ class PathSimulation: self.cutMaterial.Shape = self.job.Stock.Shape self.cutMaterial.ViewObject.Proxy = 0 self.cutMaterial.ViewObject.show() - self.cutMaterial.ViewObject.ShapeAppearance.DiffuseColor = (0.5, 0.25, 0.25, 0.0) + self.cutMaterial.ViewObject.ShapeColor = (0.5, 0.25, 0.25, 0.0) # Add cut path solid for debug if self.debug: