Draft: move mode commands to gui_togglemodes module
`Draft_ToggleConstructionMode` and `Draft_ToggleContinueMode`. They call a base class `BaseMode` which also uses the base `gui_base.GuiCommandSimplest` class. Also add a new icon for continue mode.
This commit is contained in:
@@ -97,6 +97,7 @@ SET(Draft_GUI_tools
|
||||
draftguitools/gui_trackers.py
|
||||
draftguitools/gui_edit.py
|
||||
draftguitools/gui_lineops.py
|
||||
draftguitools/gui_togglemodes.py
|
||||
draftguitools/README.md
|
||||
)
|
||||
|
||||
|
||||
@@ -80,6 +80,8 @@ import draftguitools.gui_planeproxy
|
||||
from draftguitools.gui_lineops import FinishLine
|
||||
from draftguitools.gui_lineops import CloseLine
|
||||
from draftguitools.gui_lineops import UndoLine
|
||||
from draftguitools.gui_togglemodes import ToggleConstructionMode
|
||||
from draftguitools.gui_togglemodes import ToggleContinueMode
|
||||
# import DraftFillet
|
||||
import drafttaskpanels.task_shapestring as task_shapestring
|
||||
import drafttaskpanels.task_scale as task_scale
|
||||
@@ -4124,30 +4126,6 @@ class Scale(Modifier):
|
||||
for ghost in self.ghosts:
|
||||
ghost.finalize()
|
||||
|
||||
class ToggleConstructionMode():
|
||||
"""The Draft_ToggleConstructionMode FreeCAD command definition"""
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap' : 'Draft_Construction',
|
||||
'MenuText': QtCore.QT_TRANSLATE_NOOP("Draft_ToggleConstructionMode", "Toggle Construction Mode"),
|
||||
'Accel' : "C, M",
|
||||
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Draft_ToggleConstructionMode", "Toggles the Construction Mode for next objects.")}
|
||||
|
||||
def Activated(self):
|
||||
FreeCADGui.draftToolBar.constrButton.toggle()
|
||||
|
||||
|
||||
class ToggleContinueMode():
|
||||
"""The Draft_ToggleContinueMode FreeCAD command definition"""
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap' : 'Draft_Rotate',
|
||||
'MenuText': QtCore.QT_TRANSLATE_NOOP("Draft_ToggleContinueMode", "Toggle Continue Mode"),
|
||||
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Draft_ToggleContinueMode", "Toggles the Continue Mode for next commands.")}
|
||||
|
||||
def Activated(self):
|
||||
FreeCADGui.draftToolBar.toggleContinue()
|
||||
|
||||
|
||||
class Drawing(Modifier):
|
||||
"""The Draft Drawing command definition"""
|
||||
@@ -5444,8 +5422,6 @@ FreeCADGui.addCommand('Draft_Slope',Draft_Slope())
|
||||
FreeCADGui.addCommand('Draft_Stretch',Stretch())
|
||||
|
||||
# context commands
|
||||
FreeCADGui.addCommand('Draft_ToggleConstructionMode',ToggleConstructionMode())
|
||||
FreeCADGui.addCommand('Draft_ToggleContinueMode',ToggleContinueMode())
|
||||
FreeCADGui.addCommand('Draft_ApplyStyle',ApplyStyle())
|
||||
FreeCADGui.addCommand('Draft_ToggleDisplayMode',ToggleDisplayMode())
|
||||
FreeCADGui.addCommand('Draft_AddToGroup',AddToGroup())
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
<file>icons/Draft_CircularArray.svg</file>
|
||||
<file>icons/Draft_Clone.svg</file>
|
||||
<file>icons/Draft_Construction.svg</file>
|
||||
<file>icons/Draft_Continue.svg</file>
|
||||
<file>icons/Draft_CubicBezCurve.svg</file>
|
||||
<file>icons/Draft_Cursor.svg</file>
|
||||
<file>icons/Draft_DelPoint.svg</file>
|
||||
|
||||
146
src/Mod/Draft/Resources/icons/Draft_Continue.svg
Normal file
146
src/Mod/Draft/Resources/icons/Draft_Continue.svg
Normal file
@@ -0,0 +1,146 @@
|
||||
<?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"
|
||||
width="64px"
|
||||
height="64px"
|
||||
id="svg3074"
|
||||
version="1.1">
|
||||
<defs
|
||||
id="defs3076">
|
||||
<linearGradient
|
||||
id="linearGradient3841">
|
||||
<stop
|
||||
style="stop-color:#0619c0;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop3843" />
|
||||
<stop
|
||||
style="stop-color:#379cfb;stop-opacity:1;"
|
||||
offset="1"
|
||||
id="stop3845" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
xlink:href="#linearGradient3841"
|
||||
id="linearGradient3863"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1="3709.3296"
|
||||
y1="1286.7291"
|
||||
x2="3935.5251"
|
||||
y2="1076.6174" />
|
||||
<linearGradient
|
||||
xlink:href="#linearGradient3895"
|
||||
id="linearGradient3909"
|
||||
x1="43"
|
||||
y1="22"
|
||||
x2="48"
|
||||
y2="44"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
<linearGradient
|
||||
id="linearGradient3895">
|
||||
<stop
|
||||
style="stop-color:#729fcf;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop3897" />
|
||||
<stop
|
||||
style="stop-color:#204a87;stop-opacity:1;"
|
||||
offset="1"
|
||||
id="stop3899" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
gradientTransform="matrix(0,-1.4500001,1.4705882,0,-15.05882,91.45)"
|
||||
y2="36.079998"
|
||||
x2="21.689653"
|
||||
y1="29.279999"
|
||||
x1="56.172409"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient3036"
|
||||
xlink:href="#linearGradient3895" />
|
||||
<linearGradient
|
||||
y2="36.079998"
|
||||
x2="34.103447"
|
||||
y1="29.279999"
|
||||
x1="56.172409"
|
||||
gradientTransform="matrix(0,-1.4500001,1.4705882,0,-15.05882,91.45)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient869"
|
||||
xlink:href="#linearGradient3895" />
|
||||
<linearGradient
|
||||
y2="36.079998"
|
||||
x2="34.103447"
|
||||
y1="29.279999"
|
||||
x1="56.172409"
|
||||
gradientTransform="matrix(0,-1.4500001,1.4705882,0,-15.05882,78.450001)"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient896"
|
||||
xlink:href="#linearGradient3895" />
|
||||
</defs>
|
||||
<metadata
|
||||
id="metadata5801">
|
||||
<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>[vocx]</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_Continue.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, [wmayer]</dc:title>
|
||||
</cc:Agent>
|
||||
</dc:contributor>
|
||||
<dc:subject>
|
||||
<rdf:Bag>
|
||||
<rdf:li>arrow</rdf:li>
|
||||
<rdf:li>double</rdf:li>
|
||||
<rdf:li>right</rdf:li>
|
||||
</rdf:Bag>
|
||||
</dc:subject>
|
||||
<dc:description>A large blue arrow pointing to the right, and another one following it.</dc:description>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
id="g867"
|
||||
transform="rotate(90,24.500001,24.5)">
|
||||
<path
|
||||
id="path892"
|
||||
d="m 7.0000006,16.100001 14.0000004,-0.1 v 15 h 22 v -15 L 57,16.100001 32,-9.9999989 Z"
|
||||
style="fill:url(#linearGradient896);fill-opacity:1;fill-rule:evenodd;stroke:#0b1521;stroke-width:1.99999988;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<path
|
||||
id="path894"
|
||||
d="m 12.000001,14.000001 h 11 v 15 h 18 v -15 h 11 L 32.172062,-6.9999924 Z"
|
||||
style="fill:none;stroke:#729fcf;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<path
|
||||
style="fill:url(#linearGradient869);fill-opacity:1;fill-rule:evenodd;stroke:#0b1521;stroke-width:1.99999988;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="M 7.0000006,29.1 21.000001,29 v 15 h 22 V 29 L 57,29.1 32,3 Z"
|
||||
id="path863" />
|
||||
<path
|
||||
style="fill:none;stroke:#729fcf;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 12.000001,27 h 11 v 15 h 18 V 27 h 11 L 32.172062,6.000006 Z"
|
||||
id="path865" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.9 KiB |
153
src/Mod/Draft/draftguitools/gui_togglemodes.py
Normal file
153
src/Mod/Draft/draftguitools/gui_togglemodes.py
Normal file
@@ -0,0 +1,153 @@
|
||||
# ***************************************************************************
|
||||
# * (c) 2009, 2010 Yorik van Havre <yorik@uncreated.net> *
|
||||
# * (c) 2009, 2010 Ken Cline <cline@frii.com> *
|
||||
# * (c) 2020 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
|
||||
# * *
|
||||
# * This file is part of the FreeCAD CAx development system. *
|
||||
# * *
|
||||
# * This program is free software; you can redistribute it and/or modify *
|
||||
# * it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
# * as published by the Free Software Foundation; either version 2 of *
|
||||
# * the License, or (at your option) any later version. *
|
||||
# * for detail see the LICENCE text file. *
|
||||
# * *
|
||||
# * FreeCAD is distributed in the hope that it will be useful, *
|
||||
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
# * GNU Library General Public License for more details. *
|
||||
# * *
|
||||
# * You should have received a copy of the GNU Library General Public *
|
||||
# * License along with FreeCAD; if not, write to the Free Software *
|
||||
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
# * USA *
|
||||
# * *
|
||||
# ***************************************************************************
|
||||
"""Provides tools to control the mode of other tools in the Draft Workbench.
|
||||
|
||||
For example, a construction mode, and a continue mode to repeat commands.
|
||||
"""
|
||||
## @package gui_togglemodes
|
||||
# \ingroup DRAFT
|
||||
# \brief Provides certain mode operations of the Draft Workbench.
|
||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
|
||||
import FreeCADGui as Gui
|
||||
import Draft_rc
|
||||
import draftguitools.gui_base as gui_base
|
||||
from draftutils.messages import _msg
|
||||
from draftutils.translate import _tr
|
||||
|
||||
# The module is used to prevent complaints from code checkers (flake8)
|
||||
True if Draft_rc.__name__ else False
|
||||
|
||||
|
||||
class BaseMode(gui_base.GuiCommandSimplest):
|
||||
"""Base class for mode context GuiCommands.
|
||||
|
||||
This is inherited by the other GuiCommand classes to run
|
||||
a set of similar actions when changing modes.
|
||||
|
||||
It inherits `GuiCommandSimplest` to set up the document
|
||||
and other behavior. See this class for more information.
|
||||
"""
|
||||
|
||||
def Activated(self, mode="None"):
|
||||
"""Execute when the command is called.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
action: str
|
||||
Indicates the type of mode to switch to.
|
||||
It can be `'construction'` or `'continue'`.
|
||||
"""
|
||||
super().Activated()
|
||||
|
||||
if hasattr(Gui, "draftToolBar"):
|
||||
_ui = Gui.draftToolBar
|
||||
else:
|
||||
_msg(_tr("No active Draft Toolbar."))
|
||||
return
|
||||
|
||||
if _ui is not None:
|
||||
if mode == "construction" and hasattr(_ui, "constrButton"):
|
||||
_ui.constrButton.toggle()
|
||||
elif mode == "continue":
|
||||
_ui.toggleContinue()
|
||||
|
||||
|
||||
class ToggleConstructionMode(BaseMode):
|
||||
"""GuiCommand for the Draft_ToggleConstructionMode tool.
|
||||
|
||||
When construction mode is active, the following objects created
|
||||
will be included in the construction group, and will be drawn
|
||||
with the specified color and properties.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(name=_tr("Construction mode"))
|
||||
|
||||
def GetResources(self):
|
||||
"""Set icon, menu and tooltip."""
|
||||
_menu = "Toggle construction mode"
|
||||
_tip = ("Toggles the Construction mode.\n"
|
||||
"When this is active, the following objects created "
|
||||
"will be included in the construction group, "
|
||||
"and will be drawn with the specified color "
|
||||
"and properties.")
|
||||
|
||||
d = {'Pixmap': 'Draft_Construction',
|
||||
'MenuText': QT_TRANSLATE_NOOP("Draft_ToggleConstructionMode",
|
||||
_menu),
|
||||
'Accel': "C, M",
|
||||
'ToolTip': QT_TRANSLATE_NOOP("Draft_ToggleConstructionMode",
|
||||
_tip)}
|
||||
return d
|
||||
|
||||
def Activated(self):
|
||||
"""Execute when the command is called.
|
||||
|
||||
It calls the `toggle()` method of the construction button
|
||||
in the `DraftToolbar` class.
|
||||
"""
|
||||
super().Activated(mode="construction")
|
||||
|
||||
|
||||
Gui.addCommand('Draft_ToggleConstructionMode', ToggleConstructionMode())
|
||||
|
||||
|
||||
class ToggleContinueMode(BaseMode):
|
||||
"""GuiCommand for the Draft_ToggleContinueMode tool.
|
||||
|
||||
When continue mode is active, any drawing tool that is terminated
|
||||
will automatically start again. This can be used to draw several
|
||||
objects one after the other in succession.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(name=_tr("Continue mode"))
|
||||
|
||||
def GetResources(self):
|
||||
"""Set icon, menu and tooltip."""
|
||||
_menu = "Toggle continue mode"
|
||||
_tip = ("Toggles the Continue mode.\n"
|
||||
"When this is active, any drawing tool that is terminated "
|
||||
"will automatically start again.\n"
|
||||
"This can be used to draw several objects "
|
||||
"one after the other in succession.")
|
||||
|
||||
d = {'Pixmap': 'Draft_Continue',
|
||||
'MenuText': QT_TRANSLATE_NOOP("Draft_ToggleContinueMode",
|
||||
_menu),
|
||||
'ToolTip': QT_TRANSLATE_NOOP("Draft_ToggleContinueMode",
|
||||
_tip)}
|
||||
return d
|
||||
|
||||
def Activated(self):
|
||||
"""Execute when the command is called.
|
||||
|
||||
It calls the `toggleContinue()` method of the `DraftToolbar` class.
|
||||
"""
|
||||
super().Activated(mode="continue")
|
||||
|
||||
|
||||
Gui.addCommand('Draft_ToggleContinueMode', ToggleContinueMode())
|
||||
Reference in New Issue
Block a user