diff --git a/src/Mod/Draft/DraftTools.py b/src/Mod/Draft/DraftTools.py index c1183b9ef6..8e9c5400f6 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_groups import SetAutoGroup +from draftguitools.gui_groups import Draft_AddConstruction from draftguitools.gui_grid import ToggleGrid from draftguitools.gui_heal import Heal from draftguitools.gui_dimension_ops import Draft_FlipDimension @@ -5002,37 +5003,6 @@ class Draft_Label(Creator): self.create() -class Draft_AddConstruction(): - - def GetResources(self): - return {'Pixmap' : 'Draft_Construction', - 'MenuText': QtCore.QT_TRANSLATE_NOOP("Draft_AddConstruction", "Add to Construction group"), - 'ToolTip' : QtCore.QT_TRANSLATE_NOOP("Draft_AddConstruction", "Adds the selected objects to the Construction group")} - - def Activated(self): - import FreeCADGui - if hasattr(FreeCADGui,"draftToolBar"): - col = FreeCADGui.draftToolBar.getDefaultColor("constr") - col = (float(col[0]),float(col[1]),float(col[2]),0.0) - gname = Draft.getParam("constructiongroupname","Construction") - grp = FreeCAD.ActiveDocument.getObject(gname) - if not grp: - grp = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup",gname) - for obj in FreeCADGui.Selection.getSelection(): - grp.addObject(obj) - obrep = obj.ViewObject - if "TextColor" in obrep.PropertiesList: - obrep.TextColor = col - if "PointColor" in obrep.PropertiesList: - obrep.PointColor = col - if "LineColor" in obrep.PropertiesList: - obrep.LineColor = col - if "ShapeColor" in obrep.PropertiesList: - obrep.ShapeColor = col - if hasattr(obrep,"Transparency"): - obrep.Transparency = 80 - - class Draft_Arc_3Points: @@ -5179,7 +5149,6 @@ FreeCADGui.addCommand('Draft_Stretch',Stretch()) # context commands FreeCADGui.addCommand('Draft_ApplyStyle',ApplyStyle()) FreeCADGui.addCommand('Draft_Shape2DView',Shape2DView()) -FreeCADGui.addCommand('Draft_AddConstruction',Draft_AddConstruction()) # a global place to look for active draft Command FreeCAD.activeDraftCommand = None diff --git a/src/Mod/Draft/Resources/Draft.qrc b/src/Mod/Draft/Resources/Draft.qrc index 45efb36c65..9b9d29ed6a 100644 --- a/src/Mod/Draft/Resources/Draft.qrc +++ b/src/Mod/Draft/Resources/Draft.qrc @@ -1,6 +1,7 @@ icons/Draft_2DShapeView.svg + icons/Draft_AddConstruction.svg icons/Draft_AddPoint.svg icons/Draft_AddToGroup.svg icons/Draft_Annotation_Style.svg diff --git a/src/Mod/Draft/Resources/icons/Draft_AddConstruction.svg b/src/Mod/Draft/Resources/icons/Draft_AddConstruction.svg new file mode 100644 index 0000000000..f1a2be3a75 --- /dev/null +++ b/src/Mod/Draft/Resources/icons/Draft_AddConstruction.svg @@ -0,0 +1,227 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + Mon Oct 10 13:44:52 2011 +0000 + + + [vocx] + + + + + FreeCAD LGPL2+ + + + + + FreeCAD + + + FreeCAD/src/Mod/Draft/Resources/icons/Draft_AddConstruction.svg + http://www.freecadweb.org/wiki/index.php?title=Artwork + + + [agryson] Alexander Gryson, [wmayer] + + + + + trowel + tool + plus sign + + + A trowel, and a plus sign + + + + + + + + + + diff --git a/src/Mod/Draft/draftguitools/gui_groups.py b/src/Mod/Draft/draftguitools/gui_groups.py index afd0403598..bc790bbf0c 100644 --- a/src/Mod/Draft/draftguitools/gui_groups.py +++ b/src/Mod/Draft/draftguitools/gui_groups.py @@ -25,7 +25,8 @@ """Provides tools to do various operations with groups. For example, add objects to groups, select objects inside groups, -and set the automatic group in which to create objects. +set the automatic group in which to create objects, and add objects +to the construction group. """ ## @package gui_groups # \ingroup DRAFT @@ -328,3 +329,68 @@ class SetAutoGroup(gui_base.GuiCommandSimplest): Gui.addCommand('Draft_AutoGroup', SetAutoGroup()) + + +class AddToConstruction(gui_base.GuiCommandSimplest): + """Gui Command for the AddToConstruction tool. + + It adds the selected objects to the construction group + defined in the `DraftToolBar` class which is initialized + in the `Gui` namespace when the workbench loads. + + It adds a construction group if it doesn't exist. + + Added objects are also given the visual properties of the construction + group. + """ + + def __init__(self): + super().__init__(name=_tr("Add to construction group")) + + def GetResources(self): + """Set icon, menu and tooltip.""" + _menu = "Add to Construction group" + _tip = ("Adds the selected objects to the construction group,\n" + "and changes their appearance to the construction style.\n" + "It creates a construction group if it doesn't exist.") + + d = {'Pixmap': 'Draft_AddConstruction', + 'MenuText': QT_TRANSLATE_NOOP("Draft_AddConstruction", _menu), + 'ToolTip': QT_TRANSLATE_NOOP("Draft_AddConstruction", _tip)} + return d + + def Activated(self): + """Execute when the command is called.""" + super().Activated() + + if not hasattr(Gui, "draftToolBar"): + return + + col = Gui.draftToolBar.getDefaultColor("constr") + col = (float(col[0]), float(col[1]), float(col[2]), 0.0) + + # Get the construction group or create it if it doesn't exist + gname = utils.get_param("constructiongroupname", "Construction") + grp = self.doc.getObject(gname) + if not grp: + grp = self.doc.addObject("App::DocumentObjectGroup", gname) + + for obj in Gui.Selection.getSelection(): + grp.addObject(obj) + + # Change the appearance to the construction colors + vobj = obj.ViewObject + if "TextColor" in vobj.PropertiesList: + vobj.TextColor = col + if "PointColor" in vobj.PropertiesList: + vobj.PointColor = col + if "LineColor" in vobj.PropertiesList: + vobj.LineColor = col + if "ShapeColor" in vobj.PropertiesList: + vobj.ShapeColor = col + if hasattr(vobj, "Transparency"): + vobj.Transparency = 80 + + +Draft_AddConstruction = AddToConstruction +Gui.addCommand('Draft_AddConstruction', AddToConstruction()) diff --git a/src/Mod/Draft/draftutils/init_tools.py b/src/Mod/Draft/draftutils/init_tools.py index eb6e881daf..49b85cbcf6 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(): "Draft_ToggleDisplayMode", "Draft_AddToGroup", "Draft_SelectGroup", + "Draft_AddConstruction", "Draft_Heal"]