Draft: V0.18 VisGroups were not handled (#8234)
This commit is contained in:
@@ -1,62 +0,0 @@
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2014 Yorik van Havre <yorik@uncreated.net> *
|
||||
# * Copyright (c) 2020 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
|
||||
# * *
|
||||
# * This file is part of the FreeCAD CAx development system. *
|
||||
# * *
|
||||
# * This program is free software; you can redistribute it and/or modify *
|
||||
# * it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
# * as published by the Free Software Foundation; either version 2 of *
|
||||
# * the License, or (at your option) any later version. *
|
||||
# * for detail see the LICENCE text file. *
|
||||
# * *
|
||||
# * This program is distributed in the hope that it will be useful, *
|
||||
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
# * GNU Library General Public License for more details. *
|
||||
# * *
|
||||
# * You should have received a copy of the GNU Library General Public *
|
||||
# * License along with this program; if not, write to the Free Software *
|
||||
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
# * USA *
|
||||
# * *
|
||||
# ***************************************************************************
|
||||
"""Provides the Layer object. This module is deprecated.
|
||||
|
||||
In 6f896d8f22 (April 2014) the `Layer` object was created,
|
||||
but in 4e595bd7bb (June 2014) it was renamed to `VisGroup`.
|
||||
However, it was not used a lot, so in commit 5ee99ca4e (June 2019)
|
||||
it was renamed again to `Layer`, but this time it was improved to behave
|
||||
more like a proper layer system to control the visual properties
|
||||
of the contained objects. All new code was moved to this module.
|
||||
|
||||
With the reorganization of the entire Draft workbench, the Layer object
|
||||
and associated viewprovider, make function, and Gui Command
|
||||
have been moved to the appropriate directories `draftobjects`,
|
||||
`draftviewproviders`, `draftmake`, and `draftguitools`.
|
||||
Therefore, this module is only required to migrate old objects
|
||||
created with v0.18 and earlier, and certain development version of v0.19.
|
||||
|
||||
Since this module is only used to migrate older objects, it is only temporary,
|
||||
and will be removed after one year, that is, in July 2021.
|
||||
|
||||
The explanation of the migration methods is in the wiki page:
|
||||
https://wiki.freecadweb.org/Scripted_objects_migration
|
||||
"""
|
||||
## @package DraftLayer
|
||||
# \ingroup DRAFT
|
||||
# \brief Provides the Layer object. This module is deprecated.
|
||||
#
|
||||
# This module is only required to migrate old objects created
|
||||
# with v0.18 and earlier and with certain development version of v0.19.
|
||||
# It will be removed definitely in January 2021.
|
||||
import FreeCAD as App
|
||||
|
||||
from draftobjects.layer import (Layer,
|
||||
_VisGroup,
|
||||
LayerContainer)
|
||||
|
||||
if App.GuiUp:
|
||||
from draftviewproviders.view_layer import (ViewProviderLayer,
|
||||
_ViewProviderVisGroup,
|
||||
ViewProviderLayerContainer)
|
||||
@@ -30,6 +30,9 @@
|
||||
# @{
|
||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
|
||||
from draftutils.messages import _wrn
|
||||
from draftutils.translate import translate
|
||||
|
||||
|
||||
class Layer:
|
||||
"""The Layer object.
|
||||
@@ -44,13 +47,6 @@ class Layer:
|
||||
|
||||
obj.Proxy = self
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
"""Execute code when the document is restored.
|
||||
|
||||
Add properties that don't exist.
|
||||
"""
|
||||
self.set_properties(obj)
|
||||
|
||||
def set_properties(self, obj):
|
||||
"""Set properties only if they don't exist."""
|
||||
if "Group" not in obj.PropertiesList:
|
||||
@@ -61,6 +57,29 @@ class Layer:
|
||||
"Layer",
|
||||
_tip)
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
"""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")
|
||||
vobj.Proxy.set_properties(vobj)
|
||||
_wrn("v0.19, " + obj.Label + ", "
|
||||
+ translate("draft", "added missing view properties"))
|
||||
|
||||
def __getstate__(self):
|
||||
"""Return a tuple of objects to save or None."""
|
||||
return self.Type
|
||||
|
||||
@@ -51,12 +51,6 @@ class DraftImportTools(unittest.TestCase):
|
||||
imported = aux.import_test(module)
|
||||
self.assertTrue(imported, "Problem importing '{}'".format(module))
|
||||
|
||||
def test_import_gui_draftlayer(self):
|
||||
"""Import Draft Layer."""
|
||||
module = "DraftLayer"
|
||||
imported = aux.import_test(module)
|
||||
self.assertTrue(imported, "Problem importing '{}'".format(module))
|
||||
|
||||
def test_import_gui_draftplane(self):
|
||||
"""Import Draft SelectPlane."""
|
||||
module = "draftguitools.gui_selectplane"
|
||||
|
||||
@@ -254,8 +254,10 @@ class ViewProviderLayer:
|
||||
|
||||
def onChanged(self, vobj, prop):
|
||||
"""Execute when a view property is changed."""
|
||||
if prop in ("LineColor", "ShapeColor", "LineWidth",
|
||||
"DrawStyle", "Transparency", "Visibility"):
|
||||
if (prop in ("LineColor", "ShapeColor", "LineWidth",
|
||||
"DrawStyle", "Transparency", "Visibility")
|
||||
and hasattr(vobj, "OverrideLineColorChildren")
|
||||
and hasattr(vobj, "OverrideShapeColorChildren")):
|
||||
self.change_view_properties(vobj, prop)
|
||||
|
||||
if (prop in ("LineColor", "ShapeColor")
|
||||
|
||||
Reference in New Issue
Block a user