diff --git a/src/Mod/Draft/DraftLayer.py b/src/Mod/Draft/DraftLayer.py deleted file mode 100644 index c106619b64..0000000000 --- a/src/Mod/Draft/DraftLayer.py +++ /dev/null @@ -1,62 +0,0 @@ -# *************************************************************************** -# * Copyright (c) 2014 Yorik van Havre * -# * Copyright (c) 2020 Eliud Cabrera Castillo * -# * * -# * 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) diff --git a/src/Mod/Draft/draftobjects/layer.py b/src/Mod/Draft/draftobjects/layer.py index a6a75d8649..53cbedeb27 100644 --- a/src/Mod/Draft/draftobjects/layer.py +++ b/src/Mod/Draft/draftobjects/layer.py @@ -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 diff --git a/src/Mod/Draft/drafttests/test_import_tools.py b/src/Mod/Draft/drafttests/test_import_tools.py index 0c8be82ff9..9e970c7c33 100644 --- a/src/Mod/Draft/drafttests/test_import_tools.py +++ b/src/Mod/Draft/drafttests/test_import_tools.py @@ -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" diff --git a/src/Mod/Draft/draftviewproviders/view_layer.py b/src/Mod/Draft/draftviewproviders/view_layer.py index e58da388db..56dd1dfe35 100644 --- a/src/Mod/Draft/draftviewproviders/view_layer.py +++ b/src/Mod/Draft/draftviewproviders/view_layer.py @@ -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")