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.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 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"]