forked from Zolko-123/FreeCAD_Assembly4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InitGui.py
359 lines (316 loc) · 13.6 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
350
351
352
353
354
355
356
# -*- coding: utf-8 -*-
###################################################################################
#
# InitGui.py
#
# 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 os
from Asm4_Translate import _atr, QT_TRANSLATE_NOOP
import Asm4_locator
global Asm4_icon, Asm4_path
Asm4_path = os.path.dirname( Asm4_locator.__file__ )
Asm4_icon = os.path.join( Asm4_path , 'Resources/icons/Assembly4.svg' )
# I don't like this being here
import selectionFilter
"""
+-----------------------------------------------+
| Initialize the workbench |
+-----------------------------------------------+
"""
class Assembly4Workbench(Workbench):
global Asm4_icon
global selectionFilter
global _atr, QT_TRANSLATE_NOOP
MenuText = "Assembly 4"
ToolTip = "Assembly 4 workbench"
Icon = Asm4_icon
def __init__(self):
"This function is executed when FreeCAD starts"
pass
def Activated(self):
"This function is executed when the workbench is activated"
# FreeCAD.Console.PrintMessage(_atr("Asm4", "Activating Assembly4 WorkBench") + '\n')
# make buttons of the selection toolbar checkable
from PySide import QtGui
mainwin = Gui.getMainWindow()
sf_tb = None
for tb in mainwin.findChildren(QtGui.QToolBar):
if tb.objectName()=='Selection Filter':
sf_tb = tb
# make all buttons except last one (clear selection filter) checkable
if sf_tb is not None:
for button in sf_tb.actions()[0:-1]:
button.setCheckable(True)
return
def Deactivated(self):
"This function is executed when the workbench is deactivated"
selectionFilter.observerDisable()
# FreeCAD.Console.PrintMessage(_atr("Asm4", "Leaving Assembly4 WorkBench") + "\n")
return
def GetClassName(self):
# this function is mandatory if this is a full python workbench
return "Gui::PythonWorkbench"
"""
+-----------------------------------------------+
| This is where all is defined |
+-----------------------------------------------+
"""
def Initialize(self):
# Assembly4 version info
# with file VERSION
versionPath = os.path.join( Asm4_path, 'VERSION' )
versionFile = open(versionPath,"r")
version = versionFile.readlines()[1]
Asm4_version = version[:-1]
versionFile.close()
'''
# with file package.xml
packageFile = os.path.join( Asm4_path, 'package.xml' )
metadata = FreeCAD.Metadata(packageFile)
Asm4_date = metadata.Date
Asm4_version = metadata.Version
'''
FreeCAD.Console.PrintMessage(_atr("Asm4", "Initializing Assembly4 workbench")+ ' ('+Asm4_version+') .')
FreeCADGui.updateGui()
# import all stuff
# import newAssemblyCmd # created an App::Part container called 'Assembly'
import newModelCmd # creates a new App::Part container called 'Model'
self.dot()
import newDatumCmd # creates a new LCS in 'Model'
self.dot()
import newPartCmd # creates a new App::Part container called 'Model'
self.dot()
import mirrorPartCmd # creates a new App::Part container with the mirrored part of the selection
self.dot()
import infoPartCmd # edits part information for BoM
self.dot()
import insertLinkCmd # inserts an App::Link to a 'Model' in another file
self.dot()
import placeLinkCmd # places a linked part by snapping LCS (in the Part and in the Assembly)
self.dot()
#import placeDatumCmd # places an LCS relative to an external file (creates a local attached copy)
#self.dot()
import importDatumCmd # creates an LCS in assembly and attaches it to an LCS relative to an external file
self.dot()
import releaseAttachmentCmd# creates an LCS in assembly and attaches it to an LCS relative to an external file
self.dot()
import makeBinderCmd # creates an LCS in assembly and attaches it to an LCS relative to an external file
self.dot()
import VariablesLib # creates an LCS in assembly and attaches it to an LCS relative to an external file
self.dot()
import AnimationLib # creates an LCS in assembly and attaches it to an LCS relative to an external file
self.dot()
import updateAssemblyCmd # updates all parts and constraints in the assembly
self.dot()
import makeArrayCmd # creates a new array of App::Link
self.dot()
import variantLinkCmd # creates a variant link
self.dot()
import gotoDocumentCmd # opens the documentof the selected App::Link
self.dot()
import Asm4_Measure # Measure tool in the Task panel
self.dot()
import makeBomCmd # creates the parts list
self.dot()
import HelpCmd # shows a basic help window
self.dot()
import showHideLcsCmd # shows/hides all the LCSs
self.dot()
import configurationEngine # save/restore configuration
self.dot()
# Fasteners
if self.checkWorkbench('FastenersWorkbench'):
# a library to handle fasteners from the FastenersWorkbench
import FastenersLib
self.FastenersCmd = 'Asm4_Fasteners'
else:
# a dummy library if the FastenersWorkbench is not installed
import FastenersDummy
self.FastenersCmd = 'Asm4_insertScrew'
self.dot()
# Define Menus
# commands to appear in the Assembly4 menu 'Assembly'
self.appendMenu(QT_TRANSLATE_NOOP("Workbench", "&Assembly"), self.assemblyMenuItems())
self.dot()
# put all constraints related commands in a separate menu
self.appendMenu("&Constraints", self.constraintsMenuItems())
self.dot()
# self.appendMenu("&Geometry",["Asm4_newPart"])
# additional entry in the Help menu
self.appendMenu(QT_TRANSLATE_NOOP("Workbench", "&Help"), ["Asm4_Help"])
self.dot()
# Define Toolbars
# commands to appear in the Assembly4 toolbar
self.appendToolbar(_atr("Asm4", "Assembly"), self.assemblyToolbarItems())
self.dot()
# build the selection toolbar
self.appendToolbar(_atr("Asm4", "Selection Filter"), self.selectionToolbarItems())
self.dot()
# self.appendToolbar("Geometry",["Asm4_newPart"])
FreeCAD.Console.PrintMessage(" " + _atr("Asm4", "done") + ".\n")
"""
+-----------------------------------------------+
| Initialisation finished |
+-----------------------------------------------+
"""
"""
+-----------------------------------------------+
| Assembly Menu & Toolbar |
+-----------------------------------------------+
"""
def assemblyMenuItems(self):
commandList = [ "Asm4_newModel",
"Asm4_newPart",
"Asm4_newBody",
"Asm4_newGroup",
"Asm4_newSketch",
'Asm4_createDatum',
self.FastenersCmd,
"Separator",
"Asm4_insertLink",
"Asm4_mirrorPart",
"Asm4_circularArray",
"Asm4_variantLink",
"Separator",
"Asm4_cloneFastenersToAxes",
"Asm4_importDatum",
"Asm4_shapeBinder",
"Separator",
"Asm4_infoPart",
"Asm4_makeBOM",
"Asm4_Measure",
'Asm4_showLcs',
'Asm4_hideLcs',
"Asm4_addVariable",
"Asm4_delVariable",
"Asm4_openConfigurations",
"Asm4_Animate",
]
return commandList
def constraintsMenuItems(self):
commandList = [ "Asm4_placeLink",
"Asm4_releaseAttachment",
"Separator",
"Asm4_updateAssembly",
"Separator",
]
return commandList
def assemblyToolbarItems(self):
commandList = [ "Asm4_newModel",
"Asm4_newPart",
"Asm4_newBody",
"Asm4_newGroup",
"Asm4_infoPart",
"Asm4_insertLink",
self.FastenersCmd,
"Separator",
"Asm4_newSketch",
'Asm4_createDatum',
"Asm4_importDatum",
"Asm4_shapeBinder",
"Separator",
"Asm4_placeLink",
"Asm4_releaseAttachment",
"Asm4_updateAssembly",
"Separator",
"Asm4_mirrorPart",
"Asm4_circularArray",
"Asm4_variantLink",
"Separator",
'Asm4_showLcs',
'Asm4_hideLcs',
"Asm4_makeBOM",
"Asm4_Measure",
"Asm4_variablesCmd",
"Asm4_openConfigurations",
"Asm4_Animate",
]
return commandList
"""
+-----------------------------------------------+
| Selection Toolbar |
+-----------------------------------------------+
"""
def selectionToolbarItems(self):
# commands to appear in the Selection toolbar
commandList = ["Asm4_SelectionFilterVertexCmd",
"Asm4_SelectionFilterEdgeCmd",
"Asm4_SelectionFilterFaceCmd",
"Asm4_selObserver3DViewCmd" ,
"Asm4_SelectionFilterClearCmd"]
return commandList
"""
+-----------------------------------------------+
| Contextual Menus |
+-----------------------------------------------+
"""
def ContextMenu(self, recipient):
# This is executed whenever the user right-clicks on screen"
# "recipient" will be either "view" or "tree"
contextMenu = ['Asm4_gotoDocument' ,
'Asm4_showLcs' ,
'Asm4_hideLcs' ]
# commands to appear in the 'Assembly' sub-menu in the contextual menu (right-click)
assemblySubMenu =[ "Asm4_insertLink" ,
"Asm4_placeLink" ,
"Asm4_importDatum" ,
'Asm4_FSparameters' ,
'Separator' ,
'Asm4_applyConfiguration']
# commands to appear in the 'Create' sub-menu in the contextual menu (right-click)
createSubMenu =["Asm4_newSketch",
"Asm4_newBody",
"Asm4_newLCS",
"Asm4_newAxis",
"Asm4_newPlane",
"Asm4_newPoint",
"Asm4_newHole",
"Asm4_insertScrew",
"Asm4_insertNut",
"Asm4_insertWasher",
'Separator',
'Asm4_newConfiguration']
self.appendContextMenu("", "Separator")
self.appendContextMenu("", contextMenu) # add commands to the context menu
self.appendContextMenu(_atr("Asm4", "Assembly"), assemblySubMenu) # add commands to the context menu
self.appendContextMenu(_atr("Asm4", "Create"), createSubMenu) # add commands to the context menu
self.appendContextMenu("", "Separator")
"""
+-----------------------------------------------+
| helper functions |
+-----------------------------------------------+
"""
def checkWorkbench( self, workbench ):
# checks whether the specified workbench (a 'string') is installed
listWB = Gui.listWorkbenches()
hasWB = False
for wb in listWB.keys():
if wb == workbench:
hasWB = True
return hasWB
def dot(self):
FreeCAD.Console.PrintMessage(".")
FreeCADGui.updateGui()
"""
+-----------------------------------------------+
| actually make the workbench |
+-----------------------------------------------+
"""
wb = Assembly4Workbench()
Gui.addWorkbench(wb)