forked from Zolko-123/FreeCAD_Assembly4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibAsm4.py
218 lines (187 loc) · 8.47 KB
/
libAsm4.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
#!/usr/bin/env python
# coding: utf-8
#
# libraries for FreeCAD's Assembly Without Solver
"""
+-----------------------------------------------+
| shouldn't these be DEFINE's ? |
+-----------------------------------------------+
"""
import os
#__dir__ = os.path.dirname(__file__)
wbPath = os.path.dirname(__file__)
iconPath = os.path.join( wbPath, 'Resources/icons' )
libPath = os.path.join( wbPath, 'Resources/library' )
from PySide import QtGui, QtCore
import FreeCADGui as Gui
import FreeCAD as App
"""
+-----------------------------------------------+
| check whether a workbench exists |
+-----------------------------------------------+
"""
def checkWorkbench( 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
"""
+-----------------------------------------------+
| Shows a Warning message box |
+-----------------------------------------------+
"""
def warningBox( text ):
msgBox = QtGui.QMessageBox()
msgBox.setWindowTitle('Warning')
msgBox.setIcon(QtGui.QMessageBox.Critical)
msgBox.setText("There is already an Assembly4 Model in this document.")
msgBox.exec_()
return
"""
+-----------------------------------------------+
| populate the ExpressionEngine |
| for a linked App::Part |
+-----------------------------------------------+
"""
def makeExpressionPart( attLink, attPart, attLCS, linkedDoc, linkLCS ):
# if everything is defined
if attLink and attLCS and linkedDoc and linkLCS:
# this is where all the magic is, see:
#
# https://forum.freecadweb.org/viewtopic.php?p=278124#p278124
#
# as of FreeCAD v0.19 the syntax is different:
# https://forum.freecadweb.org/viewtopic.php?f=17&t=38974&p=337784#p337784
# expr = ParentLink.Placement * ParentPart#LCS.Placement * constr_LinkName.AttachmentOffset * LinkedPart#LCS.Placement ^ -1
# expr = LCS_in_the_assembly.Placement * constr_LinkName.AttachmentOffset * LinkedPart#LCS.Placement ^ -1
# the AttachmentOffset is now a property of the App::Link
# expr = LCS_in_the_assembly.Placement * AttachmentOffset * LinkedPart#LCS.Placement ^ -1
expr = attLCS+'.Placement * AttachmentOffset * '+linkedDoc+'#'+linkLCS+'.Placement ^ -1'
# if we're attached to another sister part (and not the Parent Assembly)
# we need to take into account the Placement of that Part.
if attPart:
expr = attLink+'.Placement * '+attPart+'#'+expr
else:
expr = False
return expr
"""
+-----------------------------------------------+
| split the ExpressionEngine of a linked part |
| to find the old attachment LCS |
| (in the parent assembly or a sister part) |
| and the old target LCS in the linked Part |
+-----------------------------------------------+
"""
# this is the case for a link to a part coming from another document
def splitExpressionLink( expr, parent ):
# expr = ParentLink.Placement * ParentPart#LCS.Placement * constr_LinkName.AttachmentOffset * LinkedPart#LCS.Placement ^ -1'
bad_EE = ( '', 'None', 'None' )
if not expr:
return bad_EE
if parent == 'Parent Assembly':
# we're attached to an LCS in the parent assembly
# expr = LCS_in_the_assembly.Placement * AttachmentOffset * LinkedPart#LCS.Placement ^ -1'
( attLCS, separator, rest1 ) = expr.partition('.Placement * AttachmentOffset * ')
( linkedDoc, separator, rest2 ) = rest1.partition('#')
( linkLCS, separator, rest3 ) = rest2.partition('.Placement ^ ')
restFinal = rest3[0:2]
attLink = parent
attPart = 'None'
#return ( restFinal, 'None', 'None', 'None', 'None', 'None')
else:
# we're attached to an LCS in a sister part
# expr = ParentLink.Placement * ParentPart#LCS.Placement * AttachmentOffset * LinkedPart#LCS.Placement ^ -1'
( attLink, separator, rest1 ) = expr.partition('.Placement * ')
( attPart, separator, rest2 ) = rest1.partition('#')
( attLCS, separator, rest3 ) = rest2.partition('.Placement * AttachmentOffset * ')
( linkedDoc, separator, rest4 ) = rest3.partition('#')
( linkLCS, separator, rest5 ) = rest4.partition('.Placement ^ ')
restFinal = rest5[0:2]
#return ( restFinal, 'None', 'None', 'None', 'None', 'None')
if restFinal=='-1' and attLink==parent :
# wow, everything went according to plan
# retval = ( expr, attPart, attLCS, constrLink, partLCS )
retval = ( attLink, attLCS, linkLCS )
else:
# rats ! Didn't succeed in decoding the ExpressionEngine.
# But still, if the decode is unsuccessful, put some text
retval = bad_EE
return retval
# this is the case for a link to a part coming from the same document as the assembly
def splitExpressionDoc( expr, parent ):
# expr = ParentLink.Placement * LCS_parent.Placement * constr_linkName.AttachmentOffset * LCS_linkedPart.Placement ^ -1
# expr = LCS_model.Placement * constr_linkName.AttachmentOffset * LCS_linkedPart.Placement ^ -1
bad_EE = ( '', 'None', 'None' )
if not expr:
return bad_EE
if parent == 'Parent Assembly':
# we're attached to an LCS in the parent assembly
# expr = LCS_in_the_assembly.Placement * constr_linkName.AttachmentOffset * LCS_linkedPart.Placement ^ -1
( attLCS, separator, rest1 ) = expr.partition('.Placement * AttachmentOffset * ')
( linkLCS, separator, rest2 ) = rest1.partition('.Placement ^ ')
restFinal = rest2[0:2]
attLink = parent
attPart = 'None'
#return ( restFinal, 'None', 'None', 'None', 'None', 'None')
else:
# we're attached to an LCS in a sister part
# expr = ParentLink.Placement * LCS_parent.Placement * constr_linkName.AttachmentOffset * LCS_linkedPart.Placement ^ -1
( attLink, separator, rest1 ) = expr.partition('.Placement * ')
( attLCS, separator, rest2 ) = rest1.partition('.Placement * AttachmentOffset * ')
( linkLCS, separator, rest3 ) = rest2.partition('.Placement ^ ')
restFinal = rest3[0:2]
#return ( restFinal, 'None', 'None', 'None', 'None', 'None')
if restFinal=='-1' and attLink==parent :
# wow, everything went according to plan
# retval = ( expr, attPart, attLCS, constrLink, partLCS )
retval = ( attLink, attLCS, linkLCS )
else:
# rats ! Didn't succeed in decoding the ExpressionEngine.
# But still, if the decode is unsuccessful, put some text
retval = bad_EE
return retval
"""
+-----------------------------------------------+
| populate the ExpressionEngine |
| for a Datum object |
| linked to an LCS in a sister part |
+-----------------------------------------------+
"""
def makeExpressionDatum( attLink, attPart, attLCS ):
# check that everything is defined
if attLink and attPart and attLCS:
# expr = Link.Placement * LinkedPart#LCS.Placement
expr = attLink +'.Placement * '+ attPart +'#'+ attLCS +'.Placement'
else:
expr = False
return expr
"""
+-----------------------------------------------+
| split the ExpressionEngine |
| of a linked Datum object to find |
| the old attachment Part and LCS |
+-----------------------------------------------+
"""
def splitExpressionDatum( expr ):
# expr = Link.Placement * LinkedPart#LCS.Placement
( attLink, separator, rest1 ) = expr.partition('.Placement * ')
( attPart, separator, rest2 ) = rest1.partition('#')
( attLCS, separator, rest3 ) = rest2.partition('.')
restFinal = rest3[0:9]
if restFinal=='Placement':
# wow, everything went according to plan
retval = ( attLink, attPart, attLCS )
#self.expression.setText( attPart +'***'+ attLCS )
else:
# rats ! But still, if the decode is unsuccessful, put some text
retval = ( restFinal, 'None', 'None' )
return retval
"""
+-----------------------------------------------+
| ExpressionEngine for Fasteners |
+-----------------------------------------------+
"""
# is in the FastenersLib.py file