forked from Zolko-123/FreeCAD_Assembly4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInitGui.py
More file actions
250 lines (219 loc) · 10.7 KB
/
Copy pathInitGui.py
File metadata and controls
250 lines (219 loc) · 10.7 KB
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
# -*- 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
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' )
# I don't like this being here
import treeSelectionOverride as selectionOverride
"""
+-----------------------------------------------+
| Initialize the workbench |
+-----------------------------------------------+
"""
class Assembly4Workbench(Workbench):
global main_Assembly4WB_Icon
global selectionOverride
MenuText = "Assembly 4"
ToolTip = "Assembly 4 workbench"
Icon = main_Assembly4WB_Icon
def __init__(self):
"This function is executed when FreeCAD starts"
pass
def Activated(self):
"This function is executed when the workbench is activated"
#selectionOverride.Activate() # Will start with selection override disabled by default
FreeCAD.Console.PrintMessage("Activating Assembly4 WorkBench\n")
return
def Deactivated(self):
"This function is executed when the workbench is deactivated"
FreeCAD.Console.PrintMessage("Leaving Assembly4 WorkBench\n")
selectionOverride.Disable()
return
def GetClassName(self):
# this function is mandatory if this is a full python workbench
return "Gui::PythonWorkbench"
def Initialize(self):
FreeCAD.Console.PrintMessage("Assembly4 WorkBench initializing ... ")
import newModelCmd # creates a new App::Part container called 'Model'
import newDatumCmd # creates a new LCS in 'Model'
import newPartCmd # creates a new App::Part container called 'Model'
import infoPartCmd # edits part information for BoM
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 makeLinkArray # creates a new array of App::Link
import gotoDocumentCmd # opens the documentof the selected App::Link
import Asm4_Measure # Measure tool in the Task panel
import makeBomCmd # creates the parts list
import HelpCmd # shows a basic help window
import showHideLcsCmd # shows/hides all the LCSs
import configurationEngine # save/restore configuration
#import DraftTools
#import treeSelectionOverride as selectionOverride
# 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'
# 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"])
"""
+-----------------------------------------------+
| Assembly |
+-----------------------------------------------+
"""
# commands to appear in the Assembly4 menu 'Assembly'
itemsAssemblyMenu = [ "Asm4_newPart",
"Asm4_newBody",
"Asm4_insertLink",
FastenersCmd,
"Separator",
"Asm4_newSketch",
"Asm4_newLCS",
"Asm4_newPlane",
"Asm4_newAxis",
"Asm4_newPoint",
"Asm4_newHole",
"Asm4_importDatum",
"Separator",
"Asm4_placeLink",
"Asm4_placeFastener",
"Asm4_cloneFastenersToAxes",
"Asm4_placeDatum",
"Asm4_releaseAttachment",
#"Asm4_makeLinkArray",
"Separator",
"Asm4_infoPart",
"Asm4_makeBOM",
"Asm4_Measure",
'Asm4_showLcs',
'Asm4_hideLcs',
"Asm4_addVariable",
"Asm4_delVariable",
"Asm4_Animate",
"Asm4_updateAssembly"]
self.appendMenu("&Assembly",itemsAssemblyMenu)
# commands to appear in the Assembly4 toolbar
itemsAssemblyToolbar = [ "Asm4_newPart",
"Asm4_newBody",
"Asm4_infoPart",
"Asm4_insertLink",
FastenersCmd,
"Separator",
"Asm4_newSketch",
'Asm4_createDatum',
"Asm4_importDatum",
"Separator",
"Asm4_placeLink",
'Asm4_placeFastener',
#'Asm4_cloneFastenersToAxes',
"Asm4_placeDatum",
"Separator",
#"Asm4_makeLinkArray",
#"Draft_PolarArray",
"Asm4_treeSelectionOverrideCmd",
"Asm4_makeBOM",
"Asm4_Measure",
"Asm4_variablesCmd",
"Asm4_Animate",
"Asm4_updateAssembly"]
self.appendToolbar("Assembly",itemsAssemblyToolbar)
# Initialisation finished
FreeCAD.Console.PrintMessage("done.\n")
"""
+-----------------------------------------------+
| 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_placeDatum" ,
'Asm4_FSparameters' ,
'Asm4_placeFastener' ,
'Asm4_cloneFastenersToAxes' ,
'Separator' ,
'Asm4_saveConfiguration',
'Asm4_restoreConfiguration']
# 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",
#"Asm4_makeLinkArray"
]
self.appendContextMenu( "", "Separator")
self.appendContextMenu( "", contextMenu ) # add commands to the context menu
self.appendContextMenu( "Assembly", assemblySubMenu ) # add commands to the context menu
self.appendContextMenu( "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
"""
+-----------------------------------------------+
| actually make the workbench |
+-----------------------------------------------+
"""
wb = Assembly4Workbench()
Gui.addWorkbench(wb)