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 6c9ea36225
commit d218d35527
24 changed files with 226 additions and 94 deletions

View File

@@ -34,12 +34,11 @@ from PySide.QtCore import QT_TRANSLATE_NOOP
import FreeCAD as App
from FreeCAD import Units as U
from draftobjects.draft_annotation import DraftAnnotation
from draftutils import gui_utils
from draftutils.messages import _wrn
from draftutils.translate import translate
from draftobjects.draft_annotation import DraftAnnotation
class Label(DraftAnnotation):
"""The Draft Label object."""
@@ -225,18 +224,12 @@ class Label(DraftAnnotation):
def onDocumentRestored(self, obj):
"""Execute code when the document is restored."""
super().onDocumentRestored(obj)
gui_utils.restore_view_object(obj, vp_module="view_label", vp_class="ViewProviderLabel")
self.Type = "Label"
if not getattr(obj, "ViewObject", None):
return
vobj = obj.ViewObject
if not getattr(vobj, "Proxy", None):
# Object was save without GUI. We need to restore the ViewObject.
from draftviewproviders.view_label import ViewProviderLabel
from draftutils import gui_utils
ViewProviderLabel(obj.ViewObject)
gui_utils.format_object(obj)
return
if hasattr(vobj, "FontName") and hasattr(vobj, "FontSize"):
return
self.update_properties_0v21(obj, vobj)