From 28e2e20a00d509d81a2532ee9aeedc3b64a3127d Mon Sep 17 00:00:00 2001 From: vocx-fc Date: Mon, 16 Mar 2020 19:56:14 -0600 Subject: [PATCH] Draft: move Draft_Heal to gui_heal module --- src/Mod/Draft/CMakeLists.txt | 1 + src/Mod/Draft/DraftTools.py | 20 +------ src/Mod/Draft/draftguitools/gui_heal.py | 76 +++++++++++++++++++++++++ src/Mod/Draft/draftutils/init_tools.py | 3 +- 4 files changed, 80 insertions(+), 20 deletions(-) create mode 100644 src/Mod/Draft/draftguitools/gui_heal.py diff --git a/src/Mod/Draft/CMakeLists.txt b/src/Mod/Draft/CMakeLists.txt index cf2844e8d9..a663a4674c 100644 --- a/src/Mod/Draft/CMakeLists.txt +++ b/src/Mod/Draft/CMakeLists.txt @@ -100,6 +100,7 @@ SET(Draft_GUI_tools draftguitools/gui_togglemodes.py draftguitools/gui_groups.py draftguitools/gui_grid.py + draftguitools/gui_heal.py draftguitools/README.md ) diff --git a/src/Mod/Draft/DraftTools.py b/src/Mod/Draft/DraftTools.py index ee758a6977..13ddf33a38 100644 --- a/src/Mod/Draft/DraftTools.py +++ b/src/Mod/Draft/DraftTools.py @@ -86,6 +86,7 @@ from draftguitools.gui_togglemodes import ToggleDisplayMode from draftguitools.gui_groups import AddToGroup from draftguitools.gui_groups import SelectGroup from draftguitools.gui_grid import ToggleGrid +from draftguitools.gui_heal import Heal # import DraftFillet import drafttaskpanels.task_shapestring as task_shapestring import drafttaskpanels.task_scale as task_scale @@ -4705,24 +4706,6 @@ class Draft_Clone(Modifier): ToDo.delay(FreeCADGui.runCommand, "Draft_Move") -class Heal(): - """The Draft Heal command definition""" - - def GetResources(self): - return {'Pixmap' : 'Draft_Heal', - 'MenuText': QtCore.QT_TRANSLATE_NOOP("Draft_Heal", "Heal"), - 'ToolTip' : QtCore.QT_TRANSLATE_NOOP("Draft_Heal", "Heal faulty Draft objects saved from an earlier FreeCAD version")} - - def Activated(self): - s = FreeCADGui.Selection.getSelection() - FreeCAD.ActiveDocument.openTransaction("Heal") - if s: - Draft.heal(s) - else: - Draft.heal() - FreeCAD.ActiveDocument.commitTransaction() - - class Draft_Facebinder(Creator): """The Draft Facebinder command definition""" @@ -5312,7 +5295,6 @@ FreeCADGui.addCommand('Draft_Clone',Draft_Clone()) FreeCADGui.addCommand('Draft_PathArray',PathArray()) FreeCADGui.addCommand('Draft_PathLinkArray',PathLinkArray()) FreeCADGui.addCommand('Draft_PointArray',PointArray()) -FreeCADGui.addCommand('Draft_Heal',Heal()) FreeCADGui.addCommand('Draft_Mirror',Mirror()) FreeCADGui.addCommand('Draft_Slope',Draft_Slope()) FreeCADGui.addCommand('Draft_Stretch',Stretch()) diff --git a/src/Mod/Draft/draftguitools/gui_heal.py b/src/Mod/Draft/draftguitools/gui_heal.py new file mode 100644 index 0000000000..0c6a3ac300 --- /dev/null +++ b/src/Mod/Draft/draftguitools/gui_heal.py @@ -0,0 +1,76 @@ +# *************************************************************************** +# * (c) 2009, 2010 Yorik van Havre * +# * (c) 2009, 2010 Ken Cline * +# * (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. * +# * * +# * FreeCAD 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 FreeCAD; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** +"""Provides the Draft_Heal command to heal older Draft files.""" +## @package gui_health +# \ingroup DRAFT +# \brief Provides the Draft_Heal command to heal older Draft files. + +from PySide.QtCore import QT_TRANSLATE_NOOP + +import FreeCADGui as Gui +import Draft +import draftguitools.gui_base as gui_base +from draftutils.translate import _tr + + +class Heal(gui_base.GuiCommandSimplest): + """The Draft Heal command definition. + + Heal faulty Draft objects saved with an earlier version of the program. + + It inherits `GuiCommandSimplest` to set up the document + and other behavior. See this class for more information. + """ + + def __init__(self): + super().__init__(name=_tr("Heal")) + + def GetResources(self): + """Set icon, menu and tooltip.""" + _tip = ("Heal faulty Draft objects saved with an earlier version " + "of the program.\n" + "If an object is selected it will try to heal that object " + "in particular,\n" + "otherwise it will try to heal all objects " + "in the active document.") + + return {'Pixmap': 'Draft_Heal', + 'MenuText': QT_TRANSLATE_NOOP("Draft_Heal", "Heal"), + 'ToolTip': QT_TRANSLATE_NOOP("Draft_Heal", _tip)} + + def Activated(self): + """Execute when the command is called.""" + super().Activated() + + s = Gui.Selection.getSelection() + self.doc.openTransaction("Heal") + if s: + Draft.heal(s) + else: + Draft.heal() + self.doc.commitTransaction() + + +Gui.addCommand('Draft_Heal', Heal()) diff --git a/src/Mod/Draft/draftutils/init_tools.py b/src/Mod/Draft/draftutils/init_tools.py index d926fae601..258b62025f 100644 --- a/src/Mod/Draft/draftutils/init_tools.py +++ b/src/Mod/Draft/draftutils/init_tools.py @@ -63,7 +63,8 @@ def get_draft_small_commands(): "Draft_WorkingPlaneProxy", "Draft_ToggleDisplayMode", "Draft_AddToGroup", - "Draft_SelectGroup"] + "Draft_SelectGroup", + "Draft_Heal"] def get_draft_modification_commands():