Skip to content

Commit

Permalink
Draft: use onDocumentRestored to migrate the Fillet
Browse files Browse the repository at this point in the history
Identify the previous object as `DraftFillet.Fillet`
and then use the new proxy class `draftobjects.fillet.Fillet`
and new viewprovider `view_fillet.ViewProviderFillet` on it.
  • Loading branch information
vocx-fc authored and yorikvanhavre committed May 13, 2020
1 parent d438aec commit 16d8986
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions src/Mod/Draft/DraftFillet.py
Expand Up @@ -56,7 +56,13 @@
# from August 2019 to February 2020. It will be removed definitely
# in August 2020, as the new Fillet object should be available.

import FreeCAD as App
import draftobjects.fillet
import draftobjects.base as base
from draftutils.messages import _wrn

if App.GuiUp:
import draftviewproviders.view_fillet as view_fillet

# -----------------------------------------------------------------------------
# Removed definitions
Expand All @@ -69,8 +75,34 @@
# class CommandFillet(DraftTools.Creator):
# -----------------------------------------------------------------------------

# When an old object is opened it will reconstruct the object
# by searching for the class `DraftFillet.Fillet`.
# So we redirect this class to the new class in the new module.
# This migrates the old object to the new object.
Fillet = draftobjects.fillet.Fillet

class Fillet(base.DraftObject):
"""The old Fillet object. DEPRECATED.
This class is solely defined to migrate older objects.
When an old object is opened it will reconstruct the object
by searching for this class. So we implement `onDocumentRestored`
to test that it is the old class and we migrate it,
by assigning the new proxy class, and the new viewprovider.
"""

def onDocumentRestored(self, obj):
"""Run when the document that is using this class is restored."""
if hasattr(obj, "Proxy") and obj.Proxy.Type == "Fillet":
_module = str(obj.Proxy.__class__)
_module = _module.lstrip("<class '").rstrip("'>")

if _module == "DraftFillet.Fillet":
self._migrate(obj, _module)

def _migrate(self, obj, _module):
"""Migrate the object to the new object."""
_wrn("v0.19, {0}, '{1}' object ".format(obj.Label, _module)
+ "will be migrated to 'draftobjects.fillet.Fillet'")

draftobjects.fillet.Fillet(obj)

if App.GuiUp:
vobj = obj.ViewObject
view_fillet.ViewProviderFillet(vobj)

0 comments on commit 16d8986

Please sign in to comment.