From 8eaf6dd997a717da4ede4f7f04e54b353a6932f1 Mon Sep 17 00:00:00 2001 From: jerome Laverroux Date: Fri, 17 Apr 2020 22:45:52 +0200 Subject: [PATCH 1/4] Added "AddNamedGroup" function Added addToGroup->"+ new named group" in list Added shortcut "M"->addtoGroup like Blender Ui Added "AddNamedGroup" icon --- src/Mod/Draft/Resources/Draft.qrc | 1 + .../Resources/icons/Draft_AddNamedGroup.svg | 432 ++++++++++++++++++ src/Mod/Draft/draftguitools/gui_groups.py | 117 ++++- src/Mod/Draft/draftutils/init_tools.py | 3 +- 4 files changed, 531 insertions(+), 22 deletions(-) create mode 100644 src/Mod/Draft/Resources/icons/Draft_AddNamedGroup.svg diff --git a/src/Mod/Draft/Resources/Draft.qrc b/src/Mod/Draft/Resources/Draft.qrc index 9b9d29ed6a..c525de0d58 100644 --- a/src/Mod/Draft/Resources/Draft.qrc +++ b/src/Mod/Draft/Resources/Draft.qrc @@ -4,6 +4,7 @@ icons/Draft_AddConstruction.svg icons/Draft_AddPoint.svg icons/Draft_AddToGroup.svg + icons/Draft_AddNamedGroup.svg icons/Draft_Annotation_Style.svg icons/Draft_Apply.svg icons/Draft_Arc.svg diff --git a/src/Mod/Draft/Resources/icons/Draft_AddNamedGroup.svg b/src/Mod/Draft/Resources/icons/Draft_AddNamedGroup.svg new file mode 100644 index 0000000000..ba0377be23 --- /dev/null +++ b/src/Mod/Draft/Resources/icons/Draft_AddNamedGroup.svg @@ -0,0 +1,432 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + Mon Oct 10 13:44:52 2011 +0000 + + + [wmayer] + + + + + FreeCAD LGPL2+ + + + + + FreeCAD + + + FreeCAD/src/Mod/Draft/Resources/icons/Draft_AddToGroup.svg + http://www.freecadweb.org/wiki/index.php?title=Artwork + + + [agryson] Alexander Gryson + + + + + tree + hierarchy + list + rectangle + + + A parent rectangle with two hierarchically subordinate rectangles with a single detached rectangle between the two children + + + + diff --git a/src/Mod/Draft/draftguitools/gui_groups.py b/src/Mod/Draft/draftguitools/gui_groups.py index bc790bbf0c..20bf93525d 100644 --- a/src/Mod/Draft/draftguitools/gui_groups.py +++ b/src/Mod/Draft/draftguitools/gui_groups.py @@ -34,6 +34,7 @@ to the construction group. import PySide.QtCore as QtCore from PySide.QtCore import QT_TRANSLATE_NOOP +from PySide import QtGui import FreeCAD as App import FreeCADGui as Gui @@ -60,6 +61,8 @@ class AddToGroup(gui_base.GuiCommandNeedsSelection): super().__init__(name=_tr("Add to group")) self.ungroup = QT_TRANSLATE_NOOP("Draft_AddToGroup", "Ungroup") + #add new group string option + self.addNewGroupStr=_tr("+ Add new group") def GetResources(self): """Set icon, menu and tooltip.""" @@ -68,6 +71,7 @@ class AddToGroup(gui_base.GuiCommandNeedsSelection): "Create a group first to use this tool.") d = {'Pixmap': 'Draft_AddToGroup', + 'Accel':"M", 'MenuText': QT_TRANSLATE_NOOP("Draft_AddToGroup", "Move to group"), 'ToolTip': QT_TRANSLATE_NOOP("Draft_AddToGroup", @@ -86,6 +90,8 @@ class AddToGroup(gui_base.GuiCommandNeedsSelection): obj = self.doc.getObject(group) if obj: self.labels.append(obj.Label) + #add new group option + self.labels.append(self.addNewGroupStr) # It uses the `DraftToolBar` class defined in the `DraftGui` module # and globally initialized in the `Gui` namespace, @@ -97,19 +103,12 @@ class AddToGroup(gui_base.GuiCommandNeedsSelection): self.ui.sourceCmd = self self.ui.popupMenu(self.labels) + # def actions(self,labelname): + + + + def proceed(self, labelname): - """Place the selected objects in the chosen group or ungroup them. - - Parameters - ---------- - labelname: str - The passed string with the name of the group. - It puts the selected objects inside this group. - """ - # Deactivate the source command of the `DraftToolBar` class - # so that it doesn't do more with this command. - self.ui.sourceCmd = None - # If the selected group matches the ungroup label, # remove the selection from all groups. if labelname == self.ungroup: @@ -119,19 +118,42 @@ class AddToGroup(gui_base.GuiCommandNeedsSelection): except Exception: pass else: - # Otherwise try to add all selected objects to the chosen group - if labelname in self.labels: - i = self.labels.index(labelname) - g = self.doc.getObject(self.groups[i]) - for obj in Gui.Selection.getSelection(): - try: - g.addObject(obj) - except Exception: - pass + # Deactivate the source command of the `DraftToolBar` class + # so that it doesn't do more with this command. + self.ui.sourceCmd = None + + #if new group is selected then launch AddNamedGroup + if labelname == self.addNewGroupStr: + add=AddNamedGroup() + add.Activated() + else: + #else add selection to the selected group + if labelname in self.labels : + i = self.labels.index(labelname) + g = self.doc.getObject(self.groups[i]) + moveToGroup(g) Gui.addCommand('Draft_AddToGroup', AddToGroup()) +def moveToGroup(group): + """ + Place the selected objects in the chosen group. + """ + + for obj in Gui.Selection.getSelection(): + try: + #retreive group's visibility + obj.ViewObject.Visibility = group.ViewObject.Visibility + group.addObject(obj) + + except Exception: + pass + + App.activeDocument().recompute(None, True, True) + + + class SelectGroup(gui_base.GuiCommandNeedsSelection): """GuiCommand for the Draft_SelectGroup tool. @@ -394,3 +416,56 @@ class AddToConstruction(gui_base.GuiCommandSimplest): Draft_AddConstruction = AddToConstruction Gui.addCommand('Draft_AddConstruction', AddToConstruction()) + +class AddNamedGroup(gui_base.GuiCommandSimplest): + + """Gui Command for the addGroup tool. + It adds a new named group + """ + def __init__(self): + super().__init__(name=_tr("Add a new group with a given name")) + + + def GetResources(self): + """Set icon, menu and tooltip.""" + _menu = "Add a new named group" + _tip = ("Add a new group with a given name.") + + d = {'Pixmap': 'Draft_AddNamedGroup', + 'MenuText': QT_TRANSLATE_NOOP("Draft_AddNamedGroup", _menu), + 'ToolTip': QT_TRANSLATE_NOOP("Draft_AddNamedGroup", _tip)} + return d + + def Activated(self): + super().Activated() + panel = Ui_AddNamedGroup() + Gui.Control.showDialog(panel) + panel.name.setFocus() + + +Draft_AddNamedGroup = AddNamedGroup +Gui.addCommand('Draft_AddNamedGroup', AddNamedGroup()) + + +class Ui_AddNamedGroup(): + """ + User interface for addgroup tool + simple label and line edit in dialogbox + """ + def __init__(self): + self.form = QtGui.QWidget() + self.form.setWindowTitle(_tr("Add group")) + row = QtGui.QHBoxLayout(self.form) + lbl = QtGui.QLabel(_tr("Group name:")) + self.name = QtGui.QLineEdit() + row.addWidget(lbl) + row.addWidget(self.name) + + + def accept(self): + group = App.activeDocument().addObject("App::DocumentObjectGroup",self.name.text()) + moveToGroup(group) + Gui.Control.closeDialog() + + + diff --git a/src/Mod/Draft/draftutils/init_tools.py b/src/Mod/Draft/draftutils/init_tools.py index 49b85cbcf6..9c69e154f0 100644 --- a/src/Mod/Draft/draftutils/init_tools.py +++ b/src/Mod/Draft/draftutils/init_tools.py @@ -62,6 +62,7 @@ def get_draft_small_commands(): return ["Draft_Layer", "Draft_WorkingPlaneProxy", "Draft_ToggleDisplayMode", + "Draft_AddNamedGroup", "Draft_AddToGroup", "Draft_SelectGroup", "Draft_AddConstruction", @@ -93,7 +94,7 @@ def get_draft_modification_commands(): def get_draft_context_commands(): """Return the context menu commands list.""" return ["Draft_ApplyStyle", "Draft_ToggleDisplayMode", - "Draft_AddToGroup", "Draft_SelectGroup", + "Draft_AddToGroup","Draft_AddNamedGroup", "Draft_SelectGroup", "Draft_SelectPlane", "Draft_ShowSnapBar", "Draft_ToggleGrid", "Draft_AutoGroup"] From c5f84631bb85efa06a5eb2fb22667b851958064b Mon Sep 17 00:00:00 2001 From: jerome Laverroux Date: Tue, 21 Apr 2020 14:49:30 +0200 Subject: [PATCH 2/4] Modified : - naming Label and not Name/ID --- src/Mod/Draft/draftguitools/gui_groups.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Mod/Draft/draftguitools/gui_groups.py b/src/Mod/Draft/draftguitools/gui_groups.py index 20bf93525d..a8bbca3db3 100644 --- a/src/Mod/Draft/draftguitools/gui_groups.py +++ b/src/Mod/Draft/draftguitools/gui_groups.py @@ -41,7 +41,8 @@ import FreeCADGui as Gui import Draft_rc import draftutils.utils as utils import draftguitools.gui_base as gui_base -from draftutils.translate import _tr, translate +from draftutils.translate import _tr +from DraftTools import translate # The module is used to prevent complaints from code checkers (flake8) True if Draft_rc.__name__ else False @@ -67,8 +68,7 @@ class AddToGroup(gui_base.GuiCommandNeedsSelection): def GetResources(self): """Set icon, menu and tooltip.""" _tooltip = ("Moves the selected objects to an existing group, " - "or removes them from any group.\n" - "Create a group first to use this tool.") + "or removes them from any group.") d = {'Pixmap': 'Draft_AddToGroup', 'Accel':"M", @@ -103,10 +103,6 @@ class AddToGroup(gui_base.GuiCommandNeedsSelection): self.ui.sourceCmd = self self.ui.popupMenu(self.labels) - # def actions(self,labelname): - - - def proceed(self, labelname): # If the selected group matches the ungroup label, @@ -456,14 +452,15 @@ class Ui_AddNamedGroup(): self.form = QtGui.QWidget() self.form.setWindowTitle(_tr("Add group")) row = QtGui.QHBoxLayout(self.form) - lbl = QtGui.QLabel(_tr("Group name:")) + lbl = QtGui.QLabel(_tr("Group name")+":") self.name = QtGui.QLineEdit() row.addWidget(lbl) row.addWidget(self.name) def accept(self): - group = App.activeDocument().addObject("App::DocumentObjectGroup",self.name.text()) + group = App.activeDocument().addObject("App::DocumentObjectGroup",translate("Gui::Dialog::DlgAddProperty","Group")) + group.Label=self.name.text() moveToGroup(group) Gui.Control.closeDialog() From 1d043b8cd36bae608b86e944190b2ce720138b23 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Mon, 6 Sep 2021 11:53:28 +0200 Subject: [PATCH 3/4] Changed M shortcut to M,G --- src/Mod/Draft/draftguitools/gui_groups.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mod/Draft/draftguitools/gui_groups.py b/src/Mod/Draft/draftguitools/gui_groups.py index 55f9f53e4b..9baa3dc000 100644 --- a/src/Mod/Draft/draftguitools/gui_groups.py +++ b/src/Mod/Draft/draftguitools/gui_groups.py @@ -71,7 +71,7 @@ class AddToGroup(gui_base.GuiCommandNeedsSelection): "or removes them from any group.") d = {'Pixmap': 'Draft_AddToGroup', - 'Accel':"M", + 'Accel':"M,G", 'MenuText': QT_TRANSLATE_NOOP("Draft_AddToGroup", "Move to group"), 'ToolTip': QT_TRANSLATE_NOOP("Draft_AddToGroup", From d0a3a3466599283e8bf84b24355190af56aafd50 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Mon, 6 Sep 2021 11:55:42 +0200 Subject: [PATCH 4/4] Restored docstring --- src/Mod/Draft/draftguitools/gui_groups.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Mod/Draft/draftguitools/gui_groups.py b/src/Mod/Draft/draftguitools/gui_groups.py index 9baa3dc000..343e68257c 100644 --- a/src/Mod/Draft/draftguitools/gui_groups.py +++ b/src/Mod/Draft/draftguitools/gui_groups.py @@ -105,6 +105,13 @@ class AddToGroup(gui_base.GuiCommandNeedsSelection): def proceed(self, labelname): + """Place the selected objects in the chosen group or ungroup them. + Parameters + ---------- + labelname: str + The passed string with the name of the group. + It puts the selected objects inside this group. + """ # If the selected group matches the ungroup label, # remove the selection from all groups. if labelname == self.ungroup: