forked from Zolko-123/FreeCAD_Assembly4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInitGui.py
352 lines (305 loc) · 14.9 KB
/
InitGui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# -*- coding: utf-8 -*-
###################################################################################
#
# InitGui.py
#
# Copyright 2018 Mark Ganson <TheMarkster> mwganson at gmail
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
###################################################################################
import asm4wb_locator
asm4wbPath = os.path.dirname( asm4wb_locator.__file__ )
asm4wb_icons_path = os.path.join( asm4wbPath, 'Resources/icons')
global main_Assembly4WB_Icon
main_Assembly4WB_Icon = os.path.join( asm4wb_icons_path , 'Assembly4.svg' )
"""
+-----------------------------------------------+
| Drop-down menu to switch Configurations |
+-----------------------------------------------+
"""
# from https://github.com/HakanSeven12/FreeCAD-Geomatics-Workbench/commit/d82d27b47fcf794bf6f9825405eacc284de18996
class dropDownCmdGroup:
def __init__(self, cmdlist, menu, tooltip = None):
self.cmdlist = cmdlist
self.menu = menu
if tooltip is None:
self.tooltip = menu
else:
self.tooltip = tooltip
def GetCommands(self):
return tuple(self.cmdlist)
def GetResources(self):
return { 'MenuText': self.menu, 'ToolTip': self.tooltip }
"""
+-----------------------------------------------+
| Initialize the workbench |
+-----------------------------------------------+
"""
class Assembly4Workbench(Workbench):
global main_Assembly4WB_Icon
MenuText = "Assembly 4"
ToolTip = "Assembly 4 workbench"
Icon = main_Assembly4WB_Icon
def __init__(self):
"This function is executed when FreeCAD starts"
pass
def Initialize(self):
global dropDownCmdGroup
import newModelCmd # creates a new App::Part container called 'Model'
#import newSketchCmd # creates a new Sketch in 'Model'
import newDatumCmd # creates a new LCS in 'Model'
import newPartCmd # creates a new App::Part container called 'Model'
#import newBodyCmd # creates a new Body in 'Model
import insertLinkCmd # inserts an App::Link to a 'Model' in another file
import placeLinkCmd # places a linked part by snapping LCS (in the Part and in the Assembly)
import placeDatumCmd # places an LCS relative to an external file (creates a local attached copy)
import importDatumCmd # creates an LCS in assembly and attaches it to an LCS relative to an external file
import releaseAttachmentCmd# creates an LCS in assembly and attaches it to an LCS relative to an external file
import VariablesLib # creates an LCS in assembly and attaches it to an LCS relative to an external file
import AnimationLib # creates an LCS in assembly and attaches it to an LCS relative to an external file
import updateAssemblyCmd # updates all parts and constraints in the assembly
import newLinkArray # creates a new array of App::Link
import gotoDocumentCmd # opens the documentof the selected App::Link
import HelpCmd # shows a basic help window
# create the toolbars and menus, nearly empty, to decide about their position
self.appendToolbar("Assembly",["Asm4_newModel"])
# self.appendToolbar("Design",["Asm4_newPart"])
# self.appendMenu("&Design",["Asm4_newPart"])
self.appendMenu("&Assembly",["Asm4_newModel"])
self.appendMenu("&Help", ["Asm4_Help"])
"""
+-----------------------------------------------+
| DropDowns |
+-----------------------------------------------+
"""
# defines the drop-down button for Fasteners:
insertFastenerList = [ 'Asm4_insertScrew',
'Asm4_insertNut',
'Asm4_insertWasher',
'Asm4_placeFastener' ]
Gui.addCommand( 'Asm4_Fasteners', dropDownCmdGroup( insertFastenerList, 'Insert Fastener'))
# check whether the Fasteners workbench is installed
if self.checkWorkbench('FastenersWorkbench'):
# a library to handle fasteners from the FastenersWorkbench
import FastenersLib
fastenersCmd = 'Asm4_Fasteners'
else:
# a dummy library if the FastenersWorkbench is not installed
import FastenersDummy
fastenersCmd = 'Asm4_insertScrew'
# defines the drop-down button for Datum objects
createDatumList = [ 'Asm4_newLCS',
'Asm4_newPlane',
'Asm4_newAxis',
'Asm4_newPoint',
'Asm4_newHole' ]
Gui.addCommand( 'Asm4_createDatum', dropDownCmdGroup( createDatumList, 'Create Datum Object'))
# defines the drop-down button for boolean operations
compBooleanList = [ "Part_Fuse",
"Part_Common",
"Part_Cut",
"Part_XOR",
"Part_Common",
"Part_Slice",
"Part_SliceApart",
"Part_BooleanFragments",
"Part_Boolean" ]
Gui.addCommand( 'Asm4_compBoolean', dropDownCmdGroup( compBooleanList, 'Boolean Operations'))
"""
+-----------------------------------------------+
| Design |
+-----------------------------------------------+
"""
# commands to appear in the menu 'Design'
self.itemsDesignMenu = ["Part_Import",
"Part_Primitives",
"Part_SimpleCopy",
"Part_TransformedCopy",
"Separator",
"Asm4_createDatum",
"Asm4_newSketch",
"Part_EditAttachment",
"Separator",
"Part_Extrude",
"Part_Revolve",
"Part_Loft",
"Part_Sweep",
"Part_RuledSurface",
"Asm4_compBoolean",
"Separator",
"Part_Fillet",
"Part_Chamfer",
"Part_Mirror",
"Part_Offset",
"Part_Offset2D",
"Part_Section",
"Part_CrossSections",
"Part_Thickness",
"Part_CompJoinFeatures",
"Separator",
"Part_ShapeInfo",
"Part_Defeaturing",
"Part_CheckGeometry",
"Part_RefineShape" ]
# self.appendMenu("&Design",self.itemsDesignMenu)
# commands to appear in the Design toolbar
self.itemsDesignToolbar = [ "Asm4_createDatum",
"Asm4_newSketch",
"Part_EditAttachment",
"Separator",
"Part_Extrude",
"Part_Revolve",
"Part_Loft",
"Part_Sweep",
"Part_RuledSurface",
"Part_Fillet",
"Part_Chamfer",
"Separator",
"Part_Section",
"Part_CrossSections",
"Part_Mirror",
"Part_CompOffset",
"Asm4_compBoolean"]
# self.appendToolbar("Design",self.itemsDesignToolbar) # leave settings off toolbar
"""
+-----------------------------------------------+
| Assembly |
+-----------------------------------------------+
"""
# commands to appear in the Assembly4 menu 'Assembly'
self.itemsAssemblyMenu = [ "Asm4_newPart",
"Asm4_newBody",
"Part_Import",
"Asm4_insertLink",
"Asm4_placeLink",
"Asm4_releaseAttachment",
"Asm4_insertScrew",
"Asm4_insertNut",
"Asm4_insertWasher",
"Asm4_placeFastener",
"Asm4_newSketch",
"Asm4_newLCS",
"Asm4_newPlane",
"Asm4_newAxis",
"Asm4_newPoint",
"Asm4_newHole",
"Asm4_placeDatum",
"Asm4_importDatum",
"Asm4_newLinkArray",
"Asm4_addVariable",
"Asm4_Animate",
"Asm4_updateAssembly"]
self.appendMenu("&Assembly",self.itemsAssemblyMenu)
# commands to appear in the Assembly4 toolbar
self.itemsAssemblyToolbar = [ "Asm4_newPart",
"Asm4_newBody",
"Asm4_insertLink",
"Asm4_placeLink",
fastenersCmd,
"Separator",
"Asm4_newSketch",
'Asm4_newLCS',
'Asm4_newPlane',
'Asm4_newAxis',
'Asm4_newPoint',
"Asm4_newHole",
"Asm4_importDatum",
"Asm4_placeDatum",
"Separator",
"Asm4_newLinkArray",
"Asm4_addVariable",
"Asm4_Animate",
"Asm4_updateAssembly"]
self.appendToolbar("Assembly",self.itemsAssemblyToolbar) # leave settings off toolbar
"""
+-----------------------------------------------+
| Contextual Menus |
+-----------------------------------------------+
"""
# commands to appear in the 'Assembly' sub-menu in the contextual menu (right-click)
self.itemsContextMenu =["Asm4_insertLink",
"Asm4_placeLink",
"Asm4_placeFastener",
"Asm4_importDatum",
"Asm4_placeDatum"]
# commands to appear in the 'Create' sub-menu in the contextual menu (right-click)
self.itemsCreateMenu = ["Asm4_newSketch",
"Asm4_newBody",
"Asm4_newLCS",
"Asm4_newAxis",
"Asm4_newPlane",
"Asm4_newPoint",
"Asm4_newHole",
"Asm4_insertScrew",
"Asm4_insertNut",
"Asm4_insertWasher"]
"""
+-----------------------------------------------+
| helper functions |
+-----------------------------------------------+
"""
def checkWorkbench( self, workbench ):
# checks whether the specified workbench is installed
listWB = Gui.listWorkbenches()
hasWB = False
for wb in listWB.keys():
if wb == workbench:
hasWB = True
return hasWB
"""
+-----------------------------------------------+
| Standard necessary functions |
+-----------------------------------------------+
"""
def Activated(self):
"""
from PySide import QtGui, QtCore
"This function is executed when the workbench is activated"
# Set the drop-down button for the Configurations in text mode
# QtCore.Qt.ToolButtonTextOnly
# QtCore.Qt.ToolButtonTextBesideIcon
# QtCore.Qt.ToolButtonTextUnderIcon
# QtCore.Qt.ToolButtonIconOnly
for toolbar in Gui.getMainWindow().findChildren(QtGui.QToolBar):
if toolbar.objectName()=='Assembly 4':
for button in toolbar.children():
if button.isWidgetType() and button.text()=='Configurations':
button.setToolButtonStyle( QtCore.Qt.ToolButtonTextOnly )
"""
return
def Deactivated(self):
"This function is executed when the workbench is deactivated"
return
def ContextMenu(self, recipient):
# This is executed whenever the user right-clicks on screen"
# "recipient" will be either "view" or "tree"
self.appendContextMenu( "", "Separator")
self.appendContextMenu( "", ["Asm4_gotoDocument"] ) # add commands to the context menu
self.appendContextMenu( "Assembly", self.itemsContextMenu ) # add commands to the context menu
self.appendContextMenu( "Create", self.itemsCreateMenu ) # add commands to the context menu
self.appendContextMenu( "", "Separator")
def GetClassName(self):
# this function is mandatory if this is a full python workbench
return "Gui::PythonWorkbench"
"""
+-----------------------------------------------+
| actually make the workbench |
+-----------------------------------------------+
"""
wb = Assembly4Workbench()
Gui.addWorkbench(wb)