Draft: Draft_Layer new Material handling (#13949)

Discussion: #13657.

This PR adds  the ShapeAppearance view property to Draft Layers.

The DefaultShapeColor is used for the DiffuseColor of the ShapeAppearance material. Other material properties are not based on the preferences when a layer is created.

The old ShapeColor and Transparency properties remain (ShapeColor as a hidden property) and are kept in synch with the ShapeAppearance. This is consistent with how ShapeAppearance is implemented in Core.

The gui_layers.py and make_layer.py files do not have to be changed. They manipulate the vobj via the mentioned old properties.
This commit is contained in:
Roy-043
2024-05-28 09:45:05 +02:00
committed by GitHub
parent 3eb45b045c
commit 8bcbeae68b
2 changed files with 82 additions and 28 deletions

View File

@@ -30,6 +30,7 @@
# @{
from PySide.QtCore import QT_TRANSLATE_NOOP
import FreeCAD as App
from draftutils.messages import _wrn
from draftutils.translate import translate
@@ -61,24 +62,35 @@ class Layer:
"""Execute code when the document is restored."""
self.set_properties(obj)
if self.Type != "VisGroup":
return
if not hasattr(obj, "ViewObject"):
return
vobj = obj.ViewObject
if not vobj:
return
self.add_missing_properties_0v19(obj, vobj)
self.Type = "Layer"
def add_missing_properties_0v19(self, obj, vobj):
"""Update view properties."""
# It is not possible to change the property group of obj.Group.
for prop in ("DrawStyle", "LineColor", "LineWidth", "ShapeColor", "Transparency"):
vobj.setGroupOfProperty(prop, "Layer")
# ShapeAppearance property was added in v1.0, obj should be OK if it is present:
if hasattr(vobj, "ShapeAppearance"):
return
if self.Type == "VisGroup": # Type prior to v0.19.
self.Type = "Layer"
# It is not possible to change the property group of vobj.Group.
for prop in ("DrawStyle", "LineColor", "LineWidth", "ShapeColor", "Transparency"):
vobj.setGroupOfProperty(prop, "Layer")
vobj.Proxy.set_properties(vobj)
_wrn("v0.19, " + obj.Label + ", "
+ translate("draft", "added missing view properties"))
material = App.Material() # Material with default v0.21 properties.
material.DiffuseColor = vobj.ShapeColor
material.Transparency = vobj.Transparency / 100
vobj.ShapeAppearance = (material, )
vobj.setPropertyStatus("ShapeColor", "Hidden")
if hasattr(vobj, "OverrideShapeColorChildren"): # v0.19 - v0.21
vobj.OverrideShapeAppearanceChildren = vobj.OverrideShapeColorChildren
vobj.removeProperty("OverrideShapeColorChildren")
_wrn("v1.0, " + obj.Label + ", " + translate("draft", "updated view properties"))
def dumps(self):
"""Return a tuple of objects to save or None."""