Merge pull request #3358 from JeromeL63/Draft_addgroup

[0.20] [Draft] Groups, Added "AddNamedGroup" function
This commit is contained in:
Yorik van Havre
2021-09-06 12:02:45 +02:00
committed by GitHub
4 changed files with 531 additions and 18 deletions

View File

@@ -4,6 +4,7 @@
<file>icons/Draft_AddConstruction.svg</file>
<file>icons/Draft_AddPoint.svg</file>
<file>icons/Draft_AddToGroup.svg</file>
<file>icons/Draft_AddNamedGroup.svg</file>
<file>icons/Draft_Annotation_Style.svg</file>
<file>icons/Draft_Apply.svg</file>
<file>icons/Draft_Arc.svg</file>

View File

@@ -0,0 +1,432 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
id="svg3612"
height="64px"
width="64px"
sodipodi:docname="Draft_AddNamedGroup.svg"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)">
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1003"
id="namedview70"
showgrid="false"
inkscape:zoom="3.6875"
inkscape:cx="-22.705694"
inkscape:cy="21.403241"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="g4670" />
<defs
id="defs3614">
<linearGradient
id="linearGradient3144-6">
<stop
offset="0"
style="stop-color:#ffffff;stop-opacity:1"
id="stop3146-9" />
<stop
offset="1"
style="stop-color:#ffffff;stop-opacity:0"
id="stop3148-2" />
</linearGradient>
<linearGradient
id="linearGradient3701">
<stop
offset="0"
style="stop-color:#ffffff;stop-opacity:1"
id="stop3703" />
<stop
offset="1"
style="stop-color:#ffffff;stop-opacity:0"
id="stop3705" />
</linearGradient>
<radialGradient
r="34.345188"
fy="672.79736"
fx="225.26402"
cy="672.79736"
cx="225.26402"
gradientTransform="matrix(1,0,0,0.6985294,0,202.82863)"
gradientUnits="userSpaceOnUse"
id="radialGradient3688"
xlink:href="#linearGradient3144-6" />
<linearGradient
id="linearGradient3708">
<stop
offset="0"
style="stop-color:#ffffff;stop-opacity:1"
id="stop3710" />
<stop
offset="1"
style="stop-color:#ffffff;stop-opacity:0"
id="stop3712" />
</linearGradient>
<linearGradient
id="linearGradient3864-0-0">
<stop
style="stop-color:#0619c0;stop-opacity:1;"
offset="0"
id="stop3866-5-7" />
<stop
style="stop-color:#379cfb;stop-opacity:1;"
offset="1"
id="stop3868-7-6" />
</linearGradient>
<linearGradient
id="linearGradient3377">
<stop
style="stop-color:#ffaa00;stop-opacity:1;"
offset="0"
id="stop3379" />
<stop
style="stop-color:#faff2b;stop-opacity:1;"
offset="1"
id="stop3381" />
</linearGradient>
<linearGradient
id="linearGradient3864-0">
<stop
style="stop-color:#0619c0;stop-opacity:1;"
offset="0"
id="stop3866-5" />
<stop
style="stop-color:#379cfb;stop-opacity:1;"
offset="1"
id="stop3868-7" />
</linearGradient>
<linearGradient
id="linearGradient5048">
<stop
id="stop5050"
offset="0"
style="stop-color:black;stop-opacity:0;" />
<stop
style="stop-color:black;stop-opacity:1;"
offset="0.5"
id="stop5056" />
<stop
id="stop5052"
offset="1"
style="stop-color:black;stop-opacity:0;" />
</linearGradient>
<linearGradient
id="linearGradient3841-0-3">
<stop
style="stop-color:#0619c0;stop-opacity:1;"
offset="0"
id="stop3843-1-3" />
<stop
style="stop-color:#379cfb;stop-opacity:1;"
offset="1"
id="stop3845-0-8" />
</linearGradient>
<radialGradient
id="aigrd2"
cx="20.892099"
cy="114.5684"
r="5.256"
fx="20.892099"
fy="114.5684"
gradientUnits="userSpaceOnUse">
<stop
offset="0"
style="stop-color:#F0F0F0"
id="stop15566" />
<stop
offset="1.0000000"
style="stop-color:#9a9a9a;stop-opacity:1.0000000;"
id="stop15568" />
</radialGradient>
<radialGradient
id="aigrd3"
cx="20.892099"
cy="64.567902"
r="5.257"
fx="20.892099"
fy="64.567902"
gradientUnits="userSpaceOnUse">
<stop
offset="0"
style="stop-color:#F0F0F0"
id="stop15573" />
<stop
offset="1.0000000"
style="stop-color:#9a9a9a;stop-opacity:1.0000000;"
id="stop15575" />
</radialGradient>
<linearGradient
id="linearGradient15662">
<stop
id="stop15664"
offset="0.0000000"
style="stop-color:#ffffff;stop-opacity:1.0000000;" />
<stop
id="stop15666"
offset="1.0000000"
style="stop-color:#f8f8f8;stop-opacity:1.0000000;" />
</linearGradient>
<radialGradient
xlink:href="#linearGradient259"
id="radialGradient4452"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.96049297,0,0,1.041132,-52.144249,-702.33158)"
cx="33.966679"
cy="35.736916"
fx="33.966679"
fy="35.736916"
r="86.70845" />
<linearGradient
id="linearGradient259">
<stop
id="stop260"
offset="0.0000000"
style="stop-color:#fafafa;stop-opacity:1.0000000;" />
<stop
id="stop261"
offset="1.0000000"
style="stop-color:#bbbbbb;stop-opacity:1.0000000;" />
</linearGradient>
<radialGradient
xlink:href="#linearGradient269"
id="radialGradient4454"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.96827297,0,0,1.032767,-48.790699,-701.68513)"
cx="8.824419"
cy="3.7561285"
fx="8.824419"
fy="3.7561285"
r="37.751713" />
<linearGradient
id="linearGradient269">
<stop
id="stop270"
offset="0.0000000"
style="stop-color:#a3a3a3;stop-opacity:1.0000000;" />
<stop
id="stop271"
offset="1.0000000"
style="stop-color:#4c4c4c;stop-opacity:1.0000000;" />
</linearGradient>
<linearGradient
id="linearGradient4095">
<stop
id="stop4097"
offset="0"
style="stop-color:#005bff;stop-opacity:1;" />
<stop
id="stop4099"
offset="1"
style="stop-color:#c1e3f7;stop-opacity:1;" />
</linearGradient>
<linearGradient
gradientTransform="matrix(0.94231826,0,0,0.94231826,23.727549,8.8262536)"
gradientUnits="userSpaceOnUse"
y2="140.22731"
x2="434.73947"
y1="185.1304"
x1="394.15784"
id="linearGradient4253"
xlink:href="#linearGradient4247" />
<linearGradient
id="linearGradient4247">
<stop
id="stop4249"
offset="0"
style="stop-color:#2e8207;stop-opacity:1;" />
<stop
id="stop4251"
offset="1"
style="stop-color:#52ff00;stop-opacity:1;" />
</linearGradient>
<linearGradient
xlink:href="#linearGradient4247"
id="linearGradient5087"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.94231826,0,0,0.94231826,23.727549,8.8262536)"
x1="394.15784"
y1="185.1304"
x2="434.73947"
y2="140.22731" />
</defs>
<g
id="layer1">
<g
style="fill:none;stroke:#2e3436"
id="g4670"
transform="translate(-259.85207,-132.78349)">
<path
style="fill:none;stroke:#2e3436;stroke-width:6;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="m 270.85207,145.78349 0,42 12,0"
id="path5098-3" />
<path
style="fill:none;stroke:#2e3436;stroke-width:6;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="m 282.85207,155.78349 -12,0"
id="path5100-6" />
<path
style="fill:none;stroke:#d3d7cf;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="m 270.85207,205.78349 0,42 12,0"
id="path5098"
transform="translate(0,-60)" />
<path
style="fill:none;stroke:#d3d7cf;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="m 282.85207,155.78349 -12,0"
id="path5100" />
<rect
style="color:#000000;fill:#eeeeec;stroke:#2e3436;stroke-width:1.99999988000000006;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
id="rect4258-1-7-4"
width="37.999989"
height="10"
x="262.85208"
y="135.78349"
rx="0"
ry="0" />
<rect
style="color:#000000;fill:#eeeeec;stroke:#2e3436;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
id="rect4258-1-7-4-3"
width="37.999989"
height="9.9999943"
x="282.85208"
y="183.78349"
rx="0"
ry="0" />
<rect
style="color:#000000;fill:#eeeeec;stroke:#2e3436;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
id="rect4258-1-7-4-6"
width="37.999989"
height="10.000002"
x="282.85208"
y="151.78349"
rx="0"
ry="0" />
<rect
y="153.78349"
x="284.85208"
height="6"
width="34"
id="rect3852-5"
style="fill:#d3d7cf;fill-opacity:1;stroke:#ffffff;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
<rect
y="137.78349"
x="264.85208"
height="6"
width="34"
id="rect3852-5-3"
style="fill:#d3d7cf;fill-opacity:1;stroke:#ffffff;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
<rect
y="185.78349"
x="284.85208"
height="6"
width="34"
id="rect3852-5-5"
style="fill:#d3d7cf;fill-opacity:1;stroke:#ffffff;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
<path
inkscape:connector-curvature="0"
style="fill:none;stroke:#2e3436;stroke-width:5.74898672;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 283.06394,171.03772 H 272.04699"
id="path5100-6-7"
sodipodi:nodetypes="cc" />
<path
inkscape:connector-curvature="0"
style="fill:none;stroke:#d3d7cf;stroke-width:2.14987254;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 283.06394,171.03772 H 270.21649"
id="path5100-5"
sodipodi:nodetypes="cc" />
<rect
style="color:#000000;display:inline;overflow:visible;visibility:visible;fill:#eeeeec;stroke:#2e3436;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate"
id="rect4258-1-7-4-6-3"
width="37.999989"
height="10.000002"
x="283.06396"
y="167.03772"
rx="0"
ry="0" />
<rect
y="169.03772"
x="285.06396"
height="6"
width="34"
id="rect3852-5-56"
style="fill:#d3d7cf;fill-opacity:1;stroke:#ffffff;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<rect
style="fill:#2e3436;fill-opacity:1;stroke-width:0.9605186"
id="rect941"
width="1.5310026"
height="11.090331"
x="311.76453"
y="135.4756" />
<rect
style="fill:#2e3436;fill-opacity:1;stroke:#2e3436"
id="rect941-2"
width="1.4915212"
height="12.338985"
x="-141.80043"
y="306.5639"
ry="0"
transform="rotate(-90)" />
</g>
</g>
<metadata
id="metadata3200">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
<cc:license
rdf:resource="" />
<dc:date>Mon Oct 10 13:44:52 2011 +0000</dc:date>
<dc:creator>
<cc:Agent>
<dc:title>[wmayer]</dc:title>
</cc:Agent>
</dc:creator>
<dc:rights>
<cc:Agent>
<dc:title>FreeCAD LGPL2+</dc:title>
</cc:Agent>
</dc:rights>
<dc:publisher>
<cc:Agent>
<dc:title>FreeCAD</dc:title>
</cc:Agent>
</dc:publisher>
<dc:identifier>FreeCAD/src/Mod/Draft/Resources/icons/Draft_AddToGroup.svg</dc:identifier>
<dc:relation>http://www.freecadweb.org/wiki/index.php?title=Artwork</dc:relation>
<dc:contributor>
<cc:Agent>
<dc:title>[agryson] Alexander Gryson</dc:title>
</cc:Agent>
</dc:contributor>
<dc:subject>
<rdf:Bag>
<rdf:li>tree</rdf:li>
<rdf:li>hierarchy</rdf:li>
<rdf:li>list</rdf:li>
<rdf:li>rectangle</rdf:li>
</rdf:Bag>
</dc:subject>
<dc:description>A parent rectangle with two hierarchically subordinate rectangles with a single detached rectangle between the two children</dc:description>
</cc:Work>
</rdf:RDF>
</metadata>
</svg>

After

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -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()
## @}

View File

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