forked from Zolko-123/FreeCAD_Assembly4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInitGui.py
256 lines (215 loc) · 10.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
# -*- 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 Assembly4_WorkBench(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 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
if self.checkWorkbench('FastenersWorkbench'):
import FastenersLib # a library to handle fasteners from the FastenersWorkbench
fastenersCmd = 'Asm4_Fasteners'
else:
import FastenersDummy # a dummy library if the FastenersWorkbench is not installed
fastenersCmd = 'Asm4_insertScrew'
insertFastenerList = [ 'Asm4_insertScrew',
'Asm4_insertNut',
'Asm4_insertWasher',
'Asm4_placeFastener' ]
Gui.addCommand( 'Asm4_Fasteners', dropDownCmdGroup( insertFastenerList, 'Insert Fastener'))
# 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'))
# list of all commands (use ?)
self.listCmd = [ "Asm4_newModel",
"Asm4_newBody",
"Asm4_newPart",
"Asm4_newSketch",
"Asm4_newLCS",
"Asm4_newPlane",
"Asm4_newPoint",
"Asm4_insertLink",
"Asm4_placeLink",
"Asm4_importDatum",
"Asm4_placeDatum",
"Asm4_updateAssembly",
"Asm4_newLinkArray"]
# commands to appear in the Assembly4 menu 'Assembly'
self.itemsMenu = [ "Asm4_newModel",
"Asm4_newBody",
"Asm4_newPart",
"Asm4_insertLink",
"Asm4_placeLink",
"Asm4_insertScrew",
"Asm4_insertNut",
"Asm4_insertWasher",
"Asm4_placeFastener",
"Asm4_newLinkArray",
"Asm4_newSketch",
"Asm4_newLCS",
"Asm4_newPlane",
"Asm4_newAxis",
"Asm4_newPoint",
"Asm4_newHole",
"Asm4_placeDatum",
"Asm4_importDatum",
"Asm4_addVariable",
"Asm4_Animate",
"Asm4_updateAssembly"]
self.appendMenu("&Assembly",self.itemsMenu)
# commands to appear in the Assembly4 toolbar
self.itemsToolbar = [ "Asm4_newModel",
"Asm4_newBody",
"Asm4_newPart",
"Asm4_insertLink",
"Asm4_placeLink",
fastenersCmd,
"Asm4_newLinkArray",
"Asm4_newSketch",
"Asm4_createDatum",
"Asm4_placeDatum",
"Asm4_importDatum",
"Asm4_addVariable",
"Asm4_Animate",
"Asm4_updateAssembly"]
self.appendToolbar("Assembly 4",self.itemsToolbar) # leave settings off toolbar
# 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_addVariable",
"Asm4_newLCS",
"Asm4_newAxis",
"Asm4_newPlane",
"Asm4_newPoint",
"Asm4_newHole",
"Asm4_insertScrew",
"Asm4_insertNut",
"Asm4_insertWasher"]
#self.appendMenu(["&Edit","DynamicData"],self.list) # appends a submenu to an existing menu
"""
+-----------------------------------------------+
| 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( "Assembly", self.itemsContextMenu ) # add commands to the context menu
self.appendContextMenu( "Create", self.itemsCreateMenu ) # add commands to the context menu
def GetClassName(self):
# this function is mandatory if this is a full python workbench
return "Gui::PythonWorkbench"
"""
+-----------------------------------------------+
| actually make the workbench |
+-----------------------------------------------+
"""
wb = Assembly4_WorkBench()
Gui.addWorkbench(wb)