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:
@@ -108,6 +108,7 @@ from draftutils.gui_utils import (get3DView,
|
||||
remove_hidden,
|
||||
get_diffuse_color,
|
||||
apply_current_style,
|
||||
restore_view_object,
|
||||
formatObject,
|
||||
format_object,
|
||||
getSelection,
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
|
||||
import FreeCAD as App
|
||||
from draftutils import gui_utils
|
||||
from draftutils import params
|
||||
from draftobjects.base import DraftObject
|
||||
|
||||
@@ -38,7 +39,7 @@ class BezCurve(DraftObject):
|
||||
"""The BezCurve object"""
|
||||
|
||||
def __init__(self, obj):
|
||||
super(BezCurve, self).__init__(obj, "BezCurve")
|
||||
super().__init__(obj, "BezCurve")
|
||||
|
||||
_tip = QT_TRANSLATE_NOOP("App::Property",
|
||||
"The points of the Bezier curve")
|
||||
@@ -75,6 +76,12 @@ class BezCurve(DraftObject):
|
||||
#obj.setEditorMode("Degree", 2)
|
||||
obj.setEditorMode("Continuity", 1)
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
super().onDocumentRestored(obj)
|
||||
gui_utils.restore_view_object(
|
||||
obj, vp_module="view_bezcurve", vp_class="ViewProviderBezCurve"
|
||||
)
|
||||
|
||||
def execute(self, fp):
|
||||
if self.props_changed_placement_only():
|
||||
fp.positionBySupport()
|
||||
|
||||
@@ -30,18 +30,25 @@
|
||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
|
||||
from draftobjects.base import DraftObject
|
||||
from draftutils import gui_utils
|
||||
|
||||
|
||||
class Block(DraftObject):
|
||||
"""The Block object"""
|
||||
|
||||
def __init__(self, obj):
|
||||
super(Block, self).__init__(obj, "Block")
|
||||
super().__init__(obj, "Block")
|
||||
|
||||
_tip = QT_TRANSLATE_NOOP("App::Property",
|
||||
"The components of this block")
|
||||
obj.addProperty("App::PropertyLinkList","Components", "Draft", _tip)
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
super().onDocumentRestored(obj)
|
||||
gui_utils.restore_view_object(
|
||||
obj, vp_module="view_base", vp_class="ViewProviderDraftPart", format=False
|
||||
)
|
||||
|
||||
def execute(self, obj):
|
||||
if self.props_changed_placement_only(obj):
|
||||
obj.positionBySupport()
|
||||
|
||||
@@ -31,6 +31,7 @@ from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
|
||||
import FreeCAD as App
|
||||
from draftobjects.base import DraftObject
|
||||
from draftutils import gui_utils
|
||||
from draftutils import params
|
||||
|
||||
|
||||
@@ -38,7 +39,7 @@ class BSpline(DraftObject):
|
||||
"""The BSpline object"""
|
||||
|
||||
def __init__(self, obj):
|
||||
super(BSpline, self).__init__(obj, "BSpline")
|
||||
super().__init__(obj, "BSpline")
|
||||
|
||||
_tip = QT_TRANSLATE_NOOP("App::Property",
|
||||
"The points of the B-spline")
|
||||
@@ -60,6 +61,12 @@ class BSpline(DraftObject):
|
||||
obj.Points = []
|
||||
self.assureProperties(obj)
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
super().onDocumentRestored(obj)
|
||||
gui_utils.restore_view_object(
|
||||
obj, vp_module="view_bspline", vp_class="ViewProviderBSpline"
|
||||
)
|
||||
|
||||
def assureProperties(self, obj): # for Compatibility with older versions
|
||||
if not hasattr(obj, "Parameterization"):
|
||||
_tip = QT_TRANSLATE_NOOP("App::Property","Parameterization factor")
|
||||
|
||||
@@ -31,6 +31,7 @@ from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
|
||||
import FreeCAD as App
|
||||
from draftobjects.base import DraftObject
|
||||
from draftutils import gui_utils
|
||||
from draftutils import params
|
||||
|
||||
|
||||
@@ -38,7 +39,7 @@ class Circle(DraftObject):
|
||||
"""The Circle object"""
|
||||
|
||||
def __init__(self, obj):
|
||||
super(Circle, self).__init__(obj, "Circle")
|
||||
super().__init__(obj, "Circle")
|
||||
|
||||
_tip = QT_TRANSLATE_NOOP("App::Property", "Start angle of the arc")
|
||||
obj.addProperty("App::PropertyAngle", "FirstAngle",
|
||||
@@ -63,6 +64,10 @@ class Circle(DraftObject):
|
||||
|
||||
obj.MakeFace = params.get_param("fillmode")
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
super().onDocumentRestored(obj)
|
||||
gui_utils.restore_view_object(obj, vp_module="view_base", vp_class="ViewProviderDraft")
|
||||
|
||||
def execute(self, obj):
|
||||
"""This method is run when the object is created or recomputed."""
|
||||
if self.props_changed_placement_only():
|
||||
|
||||
@@ -31,15 +31,15 @@ from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
|
||||
import FreeCAD as App
|
||||
import DraftVecUtils
|
||||
|
||||
from draftobjects.base import DraftObject
|
||||
from draftutils import gui_utils
|
||||
|
||||
|
||||
class Clone(DraftObject):
|
||||
"""The Clone object"""
|
||||
|
||||
def __init__(self,obj):
|
||||
super(Clone, self).__init__(obj, "Clone")
|
||||
super().__init__(obj, "Clone")
|
||||
|
||||
_tip = QT_TRANSLATE_NOOP("App::Property",
|
||||
"The objects included in this clone")
|
||||
@@ -59,6 +59,12 @@ class Clone(DraftObject):
|
||||
|
||||
obj.Scale = App.Vector(1,1,1)
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
super().onDocumentRestored(obj)
|
||||
gui_utils.restore_view_object(
|
||||
obj, vp_module="view_clone", vp_class="ViewProviderClone", format_ref=obj.Objects[0]
|
||||
)
|
||||
|
||||
def join(self,obj,shapes):
|
||||
fuse = getattr(obj, 'Fuse', False)
|
||||
if fuse:
|
||||
|
||||
@@ -107,13 +107,12 @@ import FreeCAD as App
|
||||
import DraftVecUtils
|
||||
import DraftGeomUtils
|
||||
import WorkingPlane
|
||||
|
||||
from draftobjects.draft_annotation import DraftAnnotation
|
||||
from draftutils import gui_utils
|
||||
from draftutils import utils
|
||||
from draftutils.messages import _wrn
|
||||
from draftutils.translate import translate
|
||||
|
||||
from draftobjects.draft_annotation import DraftAnnotation
|
||||
|
||||
|
||||
class DimensionBase(DraftAnnotation):
|
||||
"""The base objects for dimension objects.
|
||||
@@ -192,19 +191,6 @@ class DimensionBase(DraftAnnotation):
|
||||
_tip)
|
||||
obj.Dimline = App.Vector(0, 1, 0)
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
"""Execute code when the document is restored."""
|
||||
super().onDocumentRestored(obj)
|
||||
|
||||
if not hasattr(obj, "ViewObject"):
|
||||
return
|
||||
vobj = obj.ViewObject
|
||||
if not vobj:
|
||||
return
|
||||
if hasattr(vobj, "TextColor"):
|
||||
return
|
||||
self.update_properties_0v21(obj, vobj)
|
||||
|
||||
def update_properties_0v21(self, obj, vobj):
|
||||
"""Update view properties."""
|
||||
vobj.Proxy.set_text_properties(vobj, vobj.PropertiesList)
|
||||
@@ -308,8 +294,18 @@ class LinearDimension(DimensionBase):
|
||||
def onDocumentRestored(self, obj):
|
||||
"""Execute code when the document is restored."""
|
||||
super().onDocumentRestored(obj)
|
||||
gui_utils.restore_view_object(
|
||||
obj, vp_module="view_dimension", vp_class="ViewProviderLinearDimension"
|
||||
)
|
||||
self.Type = "LinearDimension"
|
||||
|
||||
if not getattr(obj, "ViewObject", None):
|
||||
return
|
||||
vobj = obj.ViewObject
|
||||
if hasattr(vobj, "TextColor"):
|
||||
return
|
||||
super().update_properties_0v21(obj, vobj)
|
||||
|
||||
def onChanged(self, obj, prop):
|
||||
"""Execute when a property is changed.
|
||||
|
||||
@@ -563,8 +559,18 @@ class AngularDimension(DimensionBase):
|
||||
def onDocumentRestored(self, obj):
|
||||
"""Execute code when the document is restored."""
|
||||
super().onDocumentRestored(obj)
|
||||
gui_utils.restore_view_object(
|
||||
obj, vp_module="view_dimension", vp_class="ViewProviderAngularDimension"
|
||||
)
|
||||
self.Type = "AngularDimension"
|
||||
|
||||
if not getattr(obj, "ViewObject", None):
|
||||
return
|
||||
vobj = obj.ViewObject
|
||||
if hasattr(vobj, "TextColor"):
|
||||
return
|
||||
super().update_properties_0v21(obj, vobj)
|
||||
|
||||
def execute(self, obj):
|
||||
"""Execute when the object is created or recomputed.
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ class DraftAnnotation(object):
|
||||
return
|
||||
vobj = obj.ViewObject
|
||||
if not getattr(vobj, "Proxy", None):
|
||||
# Object was save without GUI.
|
||||
# Object was saved without GUI.
|
||||
# onDocumentRestored in the object class should restore the ViewObject.
|
||||
return
|
||||
if hasattr(vobj, "ScaleMultiplier") and hasattr(vobj, "AnnotationStyle"):
|
||||
|
||||
@@ -38,8 +38,9 @@ import lazy_loader.lazy_loader as lz
|
||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
|
||||
import FreeCAD as App
|
||||
|
||||
from draftutils import gui_utils
|
||||
from draftutils.messages import _wrn
|
||||
|
||||
from draftobjects.base import DraftObject
|
||||
|
||||
# Delay import of module until first use because it is heavy
|
||||
@@ -60,7 +61,7 @@ class DraftLink(DraftObject):
|
||||
|
||||
def __init__(self, obj, tp):
|
||||
self.use_link = False if obj else True
|
||||
super(DraftLink, self).__init__(obj, tp)
|
||||
super().__init__(obj, tp)
|
||||
if obj:
|
||||
self.attach(obj)
|
||||
|
||||
@@ -74,7 +75,7 @@ class DraftLink(DraftObject):
|
||||
self.__dict__ = state
|
||||
else:
|
||||
self.use_link = False
|
||||
super(DraftLink, self).loads(state)
|
||||
super().loads(state)
|
||||
|
||||
def attach(self, obj):
|
||||
"""Set up the properties when the object is attached."""
|
||||
@@ -181,8 +182,15 @@ class DraftLink(DraftObject):
|
||||
else:
|
||||
self.execute(obj)
|
||||
|
||||
# Object properties are updated when the document is opened.
|
||||
self.props_changed_clear()
|
||||
super().onDocumentRestored(obj)
|
||||
if hasattr(obj, "LinkTransform"):
|
||||
gui_utils.restore_view_object(
|
||||
obj, vp_module="view_draftlink", vp_class="ViewProviderDraftLink", format=False
|
||||
)
|
||||
else:
|
||||
gui_utils.restore_view_object(
|
||||
obj, vp_module="view_array", vp_class="ViewProviderDraftArray"
|
||||
)
|
||||
|
||||
def buildShape(self, obj, pl, pls):
|
||||
"""Build the shape of the link object."""
|
||||
|
||||
@@ -31,6 +31,7 @@ from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
|
||||
import FreeCAD as App
|
||||
from draftobjects.base import DraftObject
|
||||
from draftutils import gui_utils
|
||||
from draftutils import params
|
||||
|
||||
|
||||
@@ -38,7 +39,7 @@ class Ellipse(DraftObject):
|
||||
"""The Circle object"""
|
||||
|
||||
def __init__(self, obj):
|
||||
super(Ellipse, self).__init__(obj, "Ellipse")
|
||||
super().__init__(obj, "Ellipse")
|
||||
|
||||
_tip = QT_TRANSLATE_NOOP("App::Property","Start angle of the elliptical arc")
|
||||
obj.addProperty("App::PropertyAngle", "FirstAngle", "Draft", _tip)
|
||||
@@ -61,6 +62,10 @@ class Ellipse(DraftObject):
|
||||
|
||||
obj.MakeFace = params.get_param("fillmode")
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
super().onDocumentRestored(obj)
|
||||
gui_utils.restore_view_object(obj, vp_module="view_base", vp_class="ViewProviderDraft")
|
||||
|
||||
def execute(self, obj):
|
||||
if self.props_changed_placement_only():
|
||||
obj.positionBySupport()
|
||||
|
||||
@@ -31,14 +31,14 @@
|
||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
|
||||
import FreeCAD as App
|
||||
|
||||
from draftobjects.base import DraftObject
|
||||
from draftutils import gui_utils
|
||||
|
||||
|
||||
class Facebinder(DraftObject):
|
||||
"""The Draft Facebinder object"""
|
||||
def __init__(self,obj):
|
||||
super(Facebinder, self).__init__(obj, "Facebinder")
|
||||
super().__init__(obj, "Facebinder")
|
||||
|
||||
_tip = QT_TRANSLATE_NOOP("App::Property","Linked faces")
|
||||
obj.addProperty("App::PropertyLinkSubList", "Faces", "Draft", _tip)
|
||||
@@ -59,6 +59,12 @@ class Facebinder(DraftObject):
|
||||
obj.addProperty("App::PropertyArea","Area", "Draft", _tip)
|
||||
obj.setEditorMode("Area", 1)
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
super().onDocumentRestored(obj)
|
||||
gui_utils.restore_view_object(
|
||||
obj, vp_module="view_facebinder", vp_class="ViewProviderFacebinder", format=False
|
||||
)
|
||||
|
||||
def execute(self, obj):
|
||||
if self.props_changed_placement_only(obj):
|
||||
self.props_changed_clear()
|
||||
|
||||
@@ -28,16 +28,21 @@
|
||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
|
||||
import FreeCAD as App
|
||||
import draftobjects.base as base
|
||||
from draftobjects.base import DraftObject
|
||||
from draftutils import gui_utils
|
||||
|
||||
|
||||
class Fillet(base.DraftObject):
|
||||
class Fillet(DraftObject):
|
||||
"""Proxy class for the Fillet object."""
|
||||
|
||||
def __init__(self, obj):
|
||||
super(Fillet, self).__init__(obj, "Fillet")
|
||||
super().__init__(obj, "Fillet")
|
||||
self._set_properties(obj)
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
super().onDocumentRestored(obj)
|
||||
gui_utils.restore_view_object(obj, vp_module="view_fillet", vp_class="ViewProviderFillet")
|
||||
|
||||
def _set_properties(self, obj):
|
||||
"""Set the properties of objects if they don't exist."""
|
||||
if not hasattr(obj, "Start"):
|
||||
|
||||
@@ -24,11 +24,13 @@
|
||||
"""This module contains FreeCAD commands for the Draft workbench"""
|
||||
|
||||
import os
|
||||
import FreeCAD as App
|
||||
from draftutils.translate import translate, QT_TRANSLATE_NOOP
|
||||
from draftgeoutils.general import geomType
|
||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
|
||||
import FreeCAD as App
|
||||
from draftgeoutils.general import geomType
|
||||
from draftobjects.base import DraftObject
|
||||
from draftutils import gui_utils
|
||||
from draftutils.translate import translate
|
||||
|
||||
|
||||
class Hatch(DraftObject):
|
||||
@@ -64,8 +66,11 @@ class Hatch(DraftObject):
|
||||
self.Type = "Hatch"
|
||||
|
||||
def onDocumentRestored(self,obj):
|
||||
|
||||
self.setProperties(obj)
|
||||
super().onDocumentRestored(obj)
|
||||
gui_utils.restore_view_object(
|
||||
obj, vp_module="view_hatch", vp_class="ViewProviderDraftHatch"
|
||||
)
|
||||
|
||||
def dumps(self):
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -31,15 +31,15 @@ import math
|
||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
|
||||
import FreeCAD as App
|
||||
|
||||
from draftobjects.base import DraftObject
|
||||
from draftutils import gui_utils
|
||||
|
||||
|
||||
class Point(DraftObject):
|
||||
"""The Draft Point object."""
|
||||
|
||||
def __init__(self, obj, x=0, y=0, z=0):
|
||||
super(Point, self).__init__(obj, "Point")
|
||||
super().__init__(obj, "Point")
|
||||
|
||||
_tip = QT_TRANSLATE_NOOP("App::Property", "X Location")
|
||||
obj.addProperty("App::PropertyDistance", "X", "Draft", _tip)
|
||||
@@ -56,6 +56,10 @@ class Point(DraftObject):
|
||||
|
||||
obj.setPropertyStatus('Placement', 'Hidden')
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
super().onDocumentRestored(obj)
|
||||
gui_utils.restore_view_object(obj, vp_module="view_point", vp_class="ViewProviderPoint")
|
||||
|
||||
def execute(self, obj):
|
||||
base = obj.Placement.Base
|
||||
xyz_vec = App.Vector(obj.X.Value, obj.Y.Value, obj.Z.Value)
|
||||
|
||||
@@ -33,6 +33,7 @@ from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
import FreeCAD as App
|
||||
import DraftGeomUtils
|
||||
from draftobjects.base import DraftObject
|
||||
from draftutils import gui_utils
|
||||
from draftutils import params
|
||||
|
||||
|
||||
@@ -40,7 +41,7 @@ class Polygon(DraftObject):
|
||||
"""The Polygon object"""
|
||||
|
||||
def __init__(self, obj):
|
||||
super(Polygon, self).__init__(obj, "Polygon")
|
||||
super().__init__(obj, "Polygon")
|
||||
|
||||
_tip = QT_TRANSLATE_NOOP("App::Property",
|
||||
"Number of faces")
|
||||
@@ -75,6 +76,10 @@ class Polygon(DraftObject):
|
||||
obj.FacesNumber = 0
|
||||
obj.Radius = 1
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
super().onDocumentRestored(obj)
|
||||
gui_utils.restore_view_object(obj, vp_module="view_base", vp_class="ViewProviderDraft")
|
||||
|
||||
def execute(self, obj):
|
||||
if self.props_changed_placement_only():
|
||||
obj.positionBySupport()
|
||||
|
||||
@@ -32,6 +32,7 @@ from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
import FreeCAD as App
|
||||
import DraftGeomUtils
|
||||
from draftobjects.base import DraftObject
|
||||
from draftutils import gui_utils
|
||||
from draftutils import params
|
||||
|
||||
|
||||
@@ -39,7 +40,7 @@ class Rectangle(DraftObject):
|
||||
"""The Rectangle object"""
|
||||
|
||||
def __init__(self, obj):
|
||||
super(Rectangle, self).__init__(obj, "Rectangle")
|
||||
super().__init__(obj, "Rectangle")
|
||||
|
||||
_tip = QT_TRANSLATE_NOOP("App::Property", "Length of the rectangle")
|
||||
obj.addProperty("App::PropertyDistance", "Length", "Draft", _tip)
|
||||
@@ -71,6 +72,12 @@ class Rectangle(DraftObject):
|
||||
obj.Rows=1
|
||||
obj.Columns=1
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
super().onDocumentRestored(obj)
|
||||
gui_utils.restore_view_object(
|
||||
obj, vp_module="view_rectangle", vp_class="ViewProviderRectangle"
|
||||
)
|
||||
|
||||
def execute(self, obj):
|
||||
"""This method is run when the object is created or recomputed."""
|
||||
if self.props_changed_placement_only():
|
||||
|
||||
@@ -31,12 +31,11 @@ from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
|
||||
import FreeCAD as App
|
||||
import DraftVecUtils
|
||||
import draftutils.utils as utils
|
||||
import draftutils.gui_utils as gui_utils
|
||||
import draftutils.groups as groups
|
||||
|
||||
from draftutils.translate import translate
|
||||
from draftobjects.base import DraftObject
|
||||
from draftutils import groups
|
||||
from draftutils import gui_utils
|
||||
from draftutils import utils
|
||||
from draftutils.translate import translate
|
||||
|
||||
|
||||
class Shape2DView(DraftObject):
|
||||
@@ -45,7 +44,14 @@ class Shape2DView(DraftObject):
|
||||
def __init__(self,obj):
|
||||
|
||||
self.setProperties(obj)
|
||||
super(Shape2DView, self).__init__(obj, "Shape2DView")
|
||||
super().__init__(obj, "Shape2DView")
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
self.setProperties(obj)
|
||||
super().onDocumentRestored(obj)
|
||||
gui_utils.restore_view_object(
|
||||
obj, vp_module="view_base", vp_class="ViewProviderDraftAlt", format=False
|
||||
)
|
||||
|
||||
def setProperties(self,obj):
|
||||
|
||||
@@ -136,10 +142,6 @@ class Shape2DView(DraftObject):
|
||||
"Draft", _tip)
|
||||
obj.AutoUpdate = True
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
|
||||
self.setProperties(obj)
|
||||
|
||||
def getProjected(self,obj,shape,direction):
|
||||
|
||||
"returns projected edges from a shape and a direction"
|
||||
|
||||
@@ -32,13 +32,12 @@ from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
|
||||
import FreeCAD as App
|
||||
import Part
|
||||
|
||||
from draftgeoutils import faces
|
||||
from draftobjects.base import DraftObject
|
||||
from draftutils import gui_utils
|
||||
from draftutils.messages import _wrn
|
||||
from draftutils.translate import translate
|
||||
|
||||
from draftobjects.base import DraftObject
|
||||
|
||||
|
||||
class ShapeString(DraftObject):
|
||||
"""The ShapeString object"""
|
||||
@@ -103,9 +102,11 @@ class ShapeString(DraftObject):
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
super().onDocumentRestored(obj)
|
||||
if hasattr(obj, "ObliqueAngle"): # several more properties were added
|
||||
return
|
||||
self.update_properties_1v0(obj)
|
||||
gui_utils.restore_view_object(
|
||||
obj, vp_module="view_shapestring", vp_class="ViewProviderShapeString"
|
||||
)
|
||||
if not hasattr(obj, "ObliqueAngle"): # several more properties were added
|
||||
self.update_properties_1v0(obj)
|
||||
|
||||
def update_properties_1v0(self, obj):
|
||||
"""Update view properties."""
|
||||
|
||||
@@ -31,12 +31,11 @@
|
||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
|
||||
import FreeCAD as App
|
||||
|
||||
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 Text(DraftAnnotation):
|
||||
"""The Draft Text object."""
|
||||
@@ -75,15 +74,17 @@ class Text(DraftAnnotation):
|
||||
def onDocumentRestored(self,obj):
|
||||
"""Execute code when the document is restored."""
|
||||
super().onDocumentRestored(obj)
|
||||
|
||||
# See loads: self.Type is None for new objects.
|
||||
if self.Type is not None \
|
||||
and hasattr(obj, "ViewObject") \
|
||||
and obj.ViewObject:
|
||||
self.update_properties_0v21(obj, obj.ViewObject)
|
||||
|
||||
gui_utils.restore_view_object(obj, vp_module="view_text", vp_class="ViewProviderText")
|
||||
# See loads: old_type is None for new objects.
|
||||
old_type = self.Type
|
||||
self.Type = "Text"
|
||||
|
||||
if old_type is None:
|
||||
return
|
||||
if not getattr(obj, "ViewObject", None):
|
||||
return
|
||||
self.update_properties_0v21(obj, obj.ViewObject)
|
||||
|
||||
def update_properties_0v21(self, obj, vobj):
|
||||
"""Update view properties."""
|
||||
# The DisplayMode is updated automatically but the new values are
|
||||
|
||||
@@ -34,6 +34,7 @@ import FreeCAD as App
|
||||
import DraftGeomUtils
|
||||
import DraftVecUtils
|
||||
from draftobjects.base import DraftObject
|
||||
from draftutils import gui_utils
|
||||
from draftutils import params
|
||||
|
||||
|
||||
@@ -41,7 +42,7 @@ class Wire(DraftObject):
|
||||
"""The Wire object"""
|
||||
|
||||
def __init__(self, obj):
|
||||
super(Wire, self).__init__(obj, "Wire")
|
||||
super().__init__(obj, "Wire")
|
||||
|
||||
_tip = QT_TRANSLATE_NOOP("App::Property",
|
||||
"The vertices of the wire")
|
||||
@@ -94,6 +95,10 @@ class Wire(DraftObject):
|
||||
obj.MakeFace = params.get_param("fillmode")
|
||||
obj.Closed = False
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
super().onDocumentRestored(obj)
|
||||
gui_utils.restore_view_object(obj, vp_module="view_wire", vp_class="ViewProviderWire")
|
||||
|
||||
def execute(self, obj):
|
||||
if self.props_changed_placement_only(obj): # Supplying obj is required because of `Base` and `Tool`.
|
||||
obj.positionBySupport()
|
||||
|
||||
@@ -27,10 +27,11 @@
|
||||
|
||||
## \addtogroup draftobjects
|
||||
# @{
|
||||
import FreeCAD as App
|
||||
|
||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
|
||||
import FreeCAD as App
|
||||
from draftutils import gui_utils
|
||||
|
||||
|
||||
class WorkingPlaneProxy:
|
||||
"""The Draft working plane proxy object"""
|
||||
@@ -48,6 +49,11 @@ class WorkingPlaneProxy:
|
||||
|
||||
self.Type = "WorkingPlaneProxy"
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
gui_utils.restore_view_object(
|
||||
obj, vp_module="view_wpproxy", vp_class="ViewProviderWorkingPlaneProxy", format=False
|
||||
)
|
||||
|
||||
def execute(self,obj):
|
||||
import Part
|
||||
l = 1
|
||||
|
||||
@@ -36,6 +36,7 @@ of the objects or the 3D view.
|
||||
|
||||
## \addtogroup draftutils
|
||||
# @{
|
||||
import importlib
|
||||
import math
|
||||
import os
|
||||
|
||||
@@ -467,6 +468,39 @@ def apply_current_style(objs):
|
||||
setattr(vobj, prop, style[prop][1])
|
||||
|
||||
|
||||
def restore_view_object(obj, vp_module, vp_class, format=True, format_ref=None):
|
||||
"""Restore the ViewObject if the object was saved without the GUI.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
obj: App::DocumentObject
|
||||
Object whose ViewObject needs to be restored.
|
||||
|
||||
vp_module: string
|
||||
View provider module. Must be in the draftviewproviders directory.
|
||||
|
||||
vp_class: string
|
||||
View provider class.
|
||||
|
||||
format: bool, optional
|
||||
Defaults to `True`.
|
||||
If `True` the `format_object` function is called to update the
|
||||
properties of the ViewObject.
|
||||
|
||||
format_ref: App::DocumentObject, optional
|
||||
Defaults to `None`.
|
||||
Reference object to copy ViewObject properties from.
|
||||
"""
|
||||
if not getattr(obj, "ViewObject", None):
|
||||
return
|
||||
vobj = obj.ViewObject
|
||||
if not getattr(vobj, "Proxy", None):
|
||||
vp_module = importlib.import_module("draftviewproviders." + vp_module)
|
||||
getattr(vp_module, vp_class)(vobj)
|
||||
if format:
|
||||
format_object(obj, format_ref)
|
||||
|
||||
|
||||
def format_object(target, origin=None):
|
||||
"""Apply visual properties to an object.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user