Skip to content

Commit 01df7c0

Browse files
vocx-fcyorikvanhavre
authored andcommitted
Draft: added init_tools to create the toolbars
1 parent 0cb62a9 commit 01df7c0

File tree

3 files changed

+189
-64
lines changed

3 files changed

+189
-64
lines changed

src/Mod/Draft/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ SET(Draft_tests
4949

5050
SET(Draft_utilities
5151
draftutils/__init__.py
52+
draftutils/init_tools.py
5253
draftutils/utils.py
5354
draftutils/gui_utils.py
5455
draftutils/todo.py

src/Mod/Draft/InitGui.py

Lines changed: 32 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -91,68 +91,35 @@ def QT_TRANSLATE_NOOP(context, text):
9191
"Draft will not work as expected.\n")
9292

9393
# Set up command lists
94-
self.cmdList = ["Draft_Line", "Draft_Wire", "Draft_Fillet", "Draft_ArcTools",
95-
"Draft_Circle", "Draft_Ellipse", "Draft_Rectangle", "Draft_Polygon",
96-
"Draft_BSpline", "Draft_BezierTools", "Draft_Point",
97-
"Draft_Facebinder"]
98-
99-
self.annotation_tools = ["Draft_Text", "Draft_ShapeString", "Draft_Dimension",
100-
"Draft_Label"]
101-
102-
self.modList = ["Draft_Move", "Draft_Rotate", "Draft_Offset",
103-
"Draft_Trimex", "Draft_Join", "Draft_Split",
104-
"Draft_Upgrade", "Draft_Downgrade", "Draft_Scale",
105-
"Draft_Edit", "Draft_SubelementHighlight",
106-
"Draft_WireToBSpline", "Draft_AddPoint",
107-
"Draft_DelPoint", "Draft_Shape2DView",
108-
"Draft_Draft2Sketch", "Draft_Array", "Draft_LinkArray",
109-
"Draft_PolarArray", "Draft_CircularArray",
110-
"Draft_PathArray", "Draft_PathLinkArray", "Draft_PointArray", "Draft_Clone",
111-
"Draft_Drawing", "Draft_Mirror", "Draft_Stretch"]
112-
113-
self.treecmdList = ["Draft_ApplyStyle", "Draft_ToggleDisplayMode",
114-
"Draft_AddToGroup", "Draft_SelectGroup",
115-
"Draft_SelectPlane", "Draft_ShowSnapBar",
116-
"Draft_ToggleGrid", "Draft_AutoGroup"]
117-
118-
self.lineList = ["Draft_UndoLine", "Draft_FinishLine",
119-
"Draft_CloseLine"]
120-
121-
self.utils = ["Draft_Layer", "Draft_Heal", "Draft_FlipDimension",
122-
"Draft_ToggleConstructionMode",
123-
"Draft_ToggleContinueMode", "Draft_Edit",
124-
"Draft_Slope", "Draft_SetWorkingPlaneProxy",
125-
"Draft_AddConstruction"]
126-
127-
self.snapList = ['Draft_Snap_Lock', 'Draft_Snap_Midpoint',
128-
'Draft_Snap_Perpendicular',
129-
'Draft_Snap_Grid', 'Draft_Snap_Intersection',
130-
'Draft_Snap_Parallel',
131-
'Draft_Snap_Endpoint', 'Draft_Snap_Angle',
132-
'Draft_Snap_Center',
133-
'Draft_Snap_Extension', 'Draft_Snap_Near',
134-
'Draft_Snap_Ortho', 'Draft_Snap_Special',
135-
'Draft_Snap_Dimensions', 'Draft_Snap_WorkingPlane']
94+
import draftutils.init_tools as it
95+
self.drawing_commands = it.get_draft_drawing_commands()
96+
self.annotation_commands = it.get_draft_annotation_commands()
97+
self.modification_commands = it.get_draft_modification_commands()
98+
self.context_commands = it.get_draft_context_commands()
99+
self.line_commands = it.get_draft_line_commands()
100+
self.utility_commands = it.get_draft_utility_commands()
136101

137102
# Set up toolbars
138-
self.appendToolbar("Draft creation tools", self.cmdList)
139-
self.appendToolbar("Draft annotation tools", self.annotation_tools)
140-
self.appendToolbar("Draft modification tools", self.modList)
103+
self.appendToolbar(QT_TRANSLATE_NOOP("Draft", "Draft creation tools"), self.drawing_commands)
104+
self.appendToolbar(QT_TRANSLATE_NOOP("Draft", "Draft annotation tools"), self.annotation_commands)
105+
self.appendToolbar(QT_TRANSLATE_NOOP("Draft", "Draft modification tools"), self.modification_commands)
141106

142-
# Set up menu
143-
self.appendMenu(QT_TRANSLATE_NOOP("draft","&2D Drafting"),self.cmdList)
144-
self.appendMenu(QT_TRANSLATE_NOOP("draft","&Modify"),self.modList)
145-
self.appendMenu(QT_TRANSLATE_NOOP("draft","&Annotation"),self.annotation_tools)
146-
self.appendMenu(QT_TRANSLATE_NOOP("draft", "&Utilities"), self.utils + self.treecmdList)
107+
# Set up menus
108+
self.appendMenu(QT_TRANSLATE_NOOP("Draft", "&Drafting"), self.drawing_commands)
109+
self.appendMenu(QT_TRANSLATE_NOOP("Draft", "&Annotation"), self.annotation_commands)
110+
self.appendMenu(QT_TRANSLATE_NOOP("Draft", "&Modification"), self.modification_commands)
111+
self.appendMenu(QT_TRANSLATE_NOOP("Draft", "&Utilities"), self.utility_commands + self.context_commands)
147112

113+
# Set up preferences pages
148114
if hasattr(FreeCADGui, "draftToolBar"):
149115
if not hasattr(FreeCADGui.draftToolBar, "loadedPreferences"):
150-
FreeCADGui.addPreferencePage(":/ui/preferences-draft.ui", QT_TRANSLATE_NOOP("draft", "Draft"))
151-
FreeCADGui.addPreferencePage(":/ui/preferences-draftsnap.ui", QT_TRANSLATE_NOOP("draft", "Draft"))
152-
FreeCADGui.addPreferencePage(":/ui/preferences-draftvisual.ui", QT_TRANSLATE_NOOP("draft", "Draft"))
153-
FreeCADGui.addPreferencePage(":/ui/preferences-drafttexts.ui", QT_TRANSLATE_NOOP("draft", "Draft"))
116+
FreeCADGui.addPreferencePage(":/ui/preferences-draft.ui", QT_TRANSLATE_NOOP("Draft", "Draft"))
117+
FreeCADGui.addPreferencePage(":/ui/preferences-draftsnap.ui", QT_TRANSLATE_NOOP("Draft", "Draft"))
118+
FreeCADGui.addPreferencePage(":/ui/preferences-draftvisual.ui", QT_TRANSLATE_NOOP("Draft", "Draft"))
119+
FreeCADGui.addPreferencePage(":/ui/preferences-drafttexts.ui", QT_TRANSLATE_NOOP("Draft", "Draft"))
154120
FreeCADGui.draftToolBar.loadedPreferences = True
155-
FreeCAD.Console.PrintLog('Loading Draft module, done.\n')
121+
122+
FreeCAD.Console.PrintLog('Loading Draft workbench, done.\n')
156123

157124
def Activated(self):
158125
"""When entering the workbench."""
@@ -176,17 +143,17 @@ def ContextMenu(self, recipient):
176143
if recipient == "View":
177144
if FreeCAD.activeDraftCommand is None:
178145
if FreeCADGui.Selection.getSelection():
179-
self.appendContextMenu("Draft", self.cmdList + self.modList)
180-
self.appendContextMenu("Utilities", self.treecmdList)
146+
self.appendContextMenu("Draft", self.drawing_commands + self.modification_commands)
147+
self.appendContextMenu("Utilities", self.context_commands)
181148
else:
182-
self.appendContextMenu("Draft", self.cmdList)
149+
self.appendContextMenu("Draft", self.drawing_commands)
183150
else:
184151
if FreeCAD.activeDraftCommand.featureName == translate("draft","Line"):
185152
# BUG: line subcommands are not usable while another command is active
186-
self.appendContextMenu("", self.lineList)
153+
self.appendContextMenu("", self.line_commands)
187154
else:
188155
if FreeCADGui.Selection.getSelection():
189-
self.appendContextMenu("Utilities", self.treecmdList)
156+
self.appendContextMenu("Utilities", self.context_commands)
190157

191158
def GetClassName(self):
192159
"""Type of workbench."""
@@ -198,9 +165,10 @@ def GetClassName(self):
198165
# Preference pages for importing and exporting various file formats
199166
# are independent of the loading of the workbench and can be loaded at startup
200167
import Draft_rc
201-
FreeCADGui.addPreferencePage(":/ui/preferences-dxf.ui", "Import-Export")
202-
FreeCADGui.addPreferencePage(":/ui/preferences-dwg.ui", "Import-Export")
203-
FreeCADGui.addPreferencePage(":/ui/preferences-svg.ui", "Import-Export")
204-
FreeCADGui.addPreferencePage(":/ui/preferences-oca.ui", "Import-Export")
168+
from PySide.QtCore import QT_TRANSLATE_NOOP
169+
FreeCADGui.addPreferencePage(":/ui/preferences-dxf.ui", QT_TRANSLATE_NOOP("Draft", "Import-Export"))
170+
FreeCADGui.addPreferencePage(":/ui/preferences-dwg.ui", QT_TRANSLATE_NOOP("Draft", "Import-Export"))
171+
FreeCADGui.addPreferencePage(":/ui/preferences-svg.ui", QT_TRANSLATE_NOOP("Draft", "Import-Export"))
172+
FreeCADGui.addPreferencePage(":/ui/preferences-oca.ui", QT_TRANSLATE_NOOP("Draft", "Import-Export"))
205173

206174
FreeCAD.__unit_test__ += ["TestDraft"]
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
"""Provides lists of commands for the Draft Workbench.
2+
3+
This module returns lists of commands, so that the toolbars
4+
can be initilized by Draft, and by other workbenches.
5+
These commands should be defined in `DraftTools`, and in the individual
6+
modules in `draftguitools`.
7+
"""
8+
## @package init_tools
9+
# \ingroup DRAFT
10+
# \brief This module provides lists of commands for the Draft Workbench.
11+
12+
# ***************************************************************************
13+
# * (c) 2020 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
14+
# * *
15+
# * This file is part of the FreeCAD CAx development system. *
16+
# * *
17+
# * This program is free software; you can redistribute it and/or modify *
18+
# * it under the terms of the GNU Lesser General Public License (LGPL) *
19+
# * as published by the Free Software Foundation; either version 2 of *
20+
# * the License, or (at your option) any later version. *
21+
# * for detail see the LICENCE text file. *
22+
# * *
23+
# * FreeCAD is distributed in the hope that it will be useful, *
24+
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25+
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26+
# * GNU Library General Public License for more details. *
27+
# * *
28+
# * You should have received a copy of the GNU Library General Public *
29+
# * License along with FreeCAD; if not, write to the Free Software *
30+
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
31+
# * USA *
32+
# * *
33+
# ***************************************************************************
34+
35+
from PySide.QtCore import QT_TRANSLATE_NOOP
36+
37+
# Comment out commands that aren't ready to be used
38+
39+
40+
def get_draft_drawing_commands():
41+
"""Return the drawing commands list."""
42+
return ["Draft_Line", "Draft_Wire", # "Draft_Fillet",
43+
"Draft_ArcTools",
44+
"Draft_Circle", "Draft_Ellipse", "Draft_Rectangle",
45+
"Draft_Polygon", "Draft_BSpline", "Draft_BezierTools",
46+
"Draft_Point", "Draft_Facebinder"]
47+
48+
49+
def get_draft_annotation_commands():
50+
"""Return the annotation commands list."""
51+
return ["Draft_Text", "Draft_ShapeString", "Draft_Dimension",
52+
"Draft_Label"]
53+
54+
55+
def get_draft_array_commands():
56+
"""Return the array commands list."""
57+
# After the array commands are grouped, return this
58+
# return ["Draft_ArrayTools"]
59+
return ["Draft_Array", "Draft_LinkArray",
60+
"Draft_PolarArray", "Draft_CircularArray",
61+
"Draft_PathArray", "Draft_PathLinkArray", "Draft_PointArray"]
62+
63+
64+
def get_draft_modification_commands():
65+
"""Return the modification commands list."""
66+
lst = ["Draft_Move", "Draft_Rotate", "Draft_Offset",
67+
"Draft_Trimex", "Draft_Join", "Draft_Split",
68+
"Draft_Upgrade", "Draft_Downgrade", "Draft_Scale",
69+
"Draft_Edit", "Draft_SubelementHighlight",
70+
"Draft_WireToBSpline", "Draft_AddPoint",
71+
"Draft_DelPoint", "Draft_Shape2DView",
72+
"Draft_Draft2Sketch"]
73+
lst += get_draft_array_commands()
74+
lst += ["Draft_Clone",
75+
"Draft_Drawing", "Draft_Mirror", "Draft_Stretch"]
76+
return lst
77+
78+
79+
def get_draft_context_commands():
80+
"""Return the context menu commands list."""
81+
return ["Draft_ApplyStyle", "Draft_ToggleDisplayMode",
82+
"Draft_AddToGroup", "Draft_SelectGroup",
83+
"Draft_SelectPlane", "Draft_ShowSnapBar",
84+
"Draft_ToggleGrid", "Draft_AutoGroup"]
85+
86+
87+
def get_draft_line_commands():
88+
"""Return the line commands list."""
89+
return ["Draft_UndoLine", "Draft_FinishLine",
90+
"Draft_CloseLine"]
91+
92+
93+
def get_draft_utility_commands():
94+
"""Return the utility commands list."""
95+
return ["Draft_Layer", "Draft_Heal", "Draft_FlipDimension",
96+
"Draft_ToggleConstructionMode",
97+
"Draft_ToggleContinueMode", "Draft_Edit",
98+
"Draft_Slope", "Draft_SetWorkingPlaneProxy",
99+
"Draft_AddConstruction"]
100+
101+
102+
def get_draft_snap_commands():
103+
"""Return the snapping commands list."""
104+
return ['Draft_Snap_Lock', 'Draft_Snap_Midpoint',
105+
'Draft_Snap_Perpendicular',
106+
'Draft_Snap_Grid', 'Draft_Snap_Intersection',
107+
'Draft_Snap_Parallel',
108+
'Draft_Snap_Endpoint', 'Draft_Snap_Angle',
109+
'Draft_Snap_Center',
110+
'Draft_Snap_Extension', 'Draft_Snap_Near',
111+
'Draft_Snap_Ortho', 'Draft_Snap_Special',
112+
'Draft_Snap_Dimensions', 'Draft_Snap_WorkingPlane']
113+
114+
115+
def init_draft_toolbars(workbench):
116+
"""Initialize the Draft toolbars.
117+
118+
Parameters
119+
----------
120+
workbench : Gui.Workbench
121+
The workbench class on which the commands have to be available.
122+
If called from within the `Initialize` method
123+
of a workbench class defined inside `InitGui.py`,
124+
it can be used as `setup_draft_toolbars(self)`.
125+
"""
126+
workbench.appendToolbar(QT_TRANSLATE_NOOP("Draft",
127+
"Draft creation tools"),
128+
get_draft_drawing_commands())
129+
workbench.appendToolbar(QT_TRANSLATE_NOOP("Draft",
130+
"Draft annotation tools"),
131+
get_draft_annotation_commands())
132+
workbench.appendToolbar(QT_TRANSLATE_NOOP("Draft",
133+
"Draft modification tools"),
134+
get_draft_modification_commands())
135+
136+
137+
def init_draft_menus(workbench):
138+
"""Initialize the Draft menus.
139+
140+
Parameters
141+
----------
142+
workbench : Gui.Workbench
143+
The workbench class on which the commands have to be available.
144+
If called from within the `Initialize` method
145+
of a workbench class defined inside `InitGui.py`,
146+
it can be used as `setup_draft_menus(self)`.
147+
"""
148+
workbench.appendMenu(QT_TRANSLATE_NOOP("Draft", "&Drafting"),
149+
get_draft_drawing_commands())
150+
workbench.appendMenu(QT_TRANSLATE_NOOP("Draft", "&Annotation"),
151+
get_draft_annotation_commands())
152+
workbench.appendMenu(QT_TRANSLATE_NOOP("Draft", "&Modification"),
153+
get_draft_modification_commands())
154+
workbench.appendMenu(QT_TRANSLATE_NOOP("Draft", "&Utilities"),
155+
get_draft_utility_commands()
156+
+ get_draft_context_commands())

0 commit comments

Comments
 (0)