Restore ViewObject implementation for all Draft objects

In my tests the code works fine. Using @AIRCAP's instructions,  I have created a 'broken' file from draft_test_objects.FCStd.
This commit is contained in:
Roy-043
2024-10-24 15:24:13 +02:00
parent 8c4d696180
commit 0fac810797
24 changed files with 226 additions and 94 deletions

View File

@@ -31,6 +31,7 @@
from PySide.QtCore import QT_TRANSLATE_NOOP
import FreeCAD as App
from draftutils import gui_utils
from draftutils.messages import _wrn
from draftutils.translate import translate
@@ -63,26 +64,26 @@ class Layer:
def onDocumentRestored(self, obj):
"""Execute code when the document is restored."""
# Group property type was changed last in the v1.0 dev cycle:
if obj.getTypeIdOfProperty("Group") == "App::PropertyLinkListHidden":
return
# Group property type changed in v1.0:
if obj.getTypeIdOfProperty("Group") != "App::PropertyLinkListHidden":
grp = obj.Group # Type: "App::PropertyLinkList".
group_removed = obj.removeProperty("Group") # Not possible for VisGroups (< v0.19)
self.set_properties(obj)
if group_removed:
obj.Group = grp
_wrn("v1.0, " + obj.Label + ", " + translate("draft", "changed 'Group' property type"))
grp = obj.Group # Type: "App::PropertyLinkList".
group_removed = obj.removeProperty("Group") # Not possible for VisGroups (< v0.19)
self.set_properties(obj)
if group_removed:
obj.Group = grp
_wrn("v1.0, " + obj.Label + ", " + translate("draft", "changed 'Group' property type"))
gui_utils.restore_view_object(
obj, vp_module="view_layer", vp_class="ViewProviderLayer", format=False
)
if not hasattr(obj, "ViewObject"):
if not getattr(obj, "ViewObject", None):
return
vobj = obj.ViewObject
if not vobj:
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.
# It is not possible to change the property group of obj.Group.
for prop in ("DrawStyle", "LineColor", "LineWidth", "ShapeColor", "Transparency"):
vobj.setGroupOfProperty(prop, "Layer")
@@ -134,6 +135,11 @@ class LayerContainer:
self.Type = "LayerContainer"
obj.Proxy = self
def onDocumentRestored(self, obj):
gui_utils.restore_view_object(
obj, vp_module="view_layer", vp_class="ViewProviderLayerContainer", format=False
)
def execute(self, obj):
"""Execute when the object is created or recomputed.