diff --git a/src/Mod/Draft/Resources/Draft.qrc b/src/Mod/Draft/Resources/Draft.qrc
index e403999a49..4bfa75d77a 100644
--- a/src/Mod/Draft/Resources/Draft.qrc
+++ b/src/Mod/Draft/Resources/Draft.qrc
@@ -4,6 +4,7 @@
icons/Draft_AddConstruction.svgicons/Draft_AddPoint.svgicons/Draft_AddToGroup.svg
+ icons/Draft_AddNamedGroup.svgicons/Draft_Annotation_Style.svgicons/Draft_Apply.svgicons/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 @@
+
+
diff --git a/src/Mod/Draft/draftguitools/gui_groups.py b/src/Mod/Draft/draftguitools/gui_groups.py
index 465bad01d5..666d816861 100644
--- a/src/Mod/Draft/draftguitools/gui_groups.py
+++ b/src/Mod/Draft/draftguitools/gui_groups.py
@@ -36,6 +36,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
@@ -43,8 +44,8 @@ import Draft_rc
import draftutils.utils as utils
import draftutils.groups as groups
import draftguitools.gui_base as gui_base
+from draftutils.translate import _tr, translate
-from draftutils.translate import translate
# The module is used to prevent complaints from code checkers (flake8)
True if Draft_rc.__name__ else False
@@ -63,14 +64,16 @@ class AddToGroup(gui_base.GuiCommandNeedsSelection):
def __init__(self):
super(AddToGroup, self).__init__(name=translate("draft","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."""
_tooltip = ()
d = {'Pixmap': 'Draft_AddToGroup',
'MenuText': QT_TRANSLATE_NOOP("Draft_AddToGroup","Move to group")+"...",
- 'ToolTip': QT_TRANSLATE_NOOP("Draft_AddToGroup","Moves the selected objects to an existing group, or removes them from any group.\nCreate a group first to use this tool.")}
+ 'ToolTip': QT_TRANSLATE_NOOP("Draft_AddToGroup","Moves the selected objects to an existing group, or removes them from any group.\nCreate a group first to use this tool.")}
return d
def Activated(self):
@@ -85,6 +88,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,
@@ -96,19 +101,15 @@ class AddToGroup(gui_base.GuiCommandNeedsSelection):
self.ui.sourceCmd = self
self.ui.popupMenu(self.labels)
+
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:
@@ -118,19 +119,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.
@@ -378,4 +402,59 @@ 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",translate("Gui::Dialog::DlgAddProperty","Group"))
+ group.Label=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 2cbee4bb02..e90cbe5ba4 100644
--- a/src/Mod/Draft/draftutils/init_tools.py
+++ b/src/Mod/Draft/draftutils/init_tools.py
@@ -64,6 +64,7 @@ def get_draft_small_commands():
return ["Draft_Layer",
"Draft_WorkingPlaneProxy",
"Draft_ToggleDisplayMode",
+ "Draft_AddNamedGroup",
"Draft_AddToGroup",
"Draft_SelectGroup",
"Draft_AddConstruction"]
@@ -94,7 +95,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_SetStyle"]