-
Notifications
You must be signed in to change notification settings - Fork 69
/
a2p_importedPart_class.py
197 lines (170 loc) · 7.92 KB
/
a2p_importedPart_class.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
#***************************************************************************
#* *
#* Copyright (c) 2019 kbwbe *
#* *
#* Portions of code based on hamish's assembly 2 *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* 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 Library General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with this program; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************
import FreeCAD
import FreeCADGui
import Part
import os
import copy
import numpy
from FreeCAD import Base
from PySide import QtGui
from a2p_translateUtils import *
import a2plib
#==============================================================================
class Proxy_importPart:
"""The a2p importPart object."""
def __init__(self,obj):
obj.Proxy = self
Proxy_importPart.setProperties(self,obj)
self.type = "a2p_importPart"
def setProperties(self,obj):
propList = obj.PropertiesList
if not "objectType" in propList:
obj.addProperty("App::PropertyString", "objectType", "importPart")
obj.objectType = 'a2pPart'
if not "a2p_Version" in propList:
obj.addProperty("App::PropertyString", "a2p_Version", "importPart")
obj.a2p_Version = a2plib.getA2pVersion()
if not "sourceFile" in propList:
obj.addProperty("App::PropertyFile", "sourceFile", "importPart")
if not "sourcePart" in propList:
obj.addProperty("App::PropertyString", "sourcePart", "importPart")
if not "localSourceObject" in propList:
obj.addProperty("App::PropertyString", "localSourceObject", "importPart")
if not "muxInfo" in propList:
obj.addProperty("App::PropertyStringList","muxInfo","importPart")
if not "timeLastImport" in propList:
obj.addProperty("App::PropertyFloat", "timeLastImport","importPart")
if not "fixedPosition" in propList:
obj.addProperty("App::PropertyBool","fixedPosition","importPart")
if not "subassemblyImport" in propList:
obj.addProperty("App::PropertyBool","subassemblyImport","importPart")
obj.subassemblyImport = False
if not "updateColors" in propList:
obj.addProperty("App::PropertyBool","updateColors","importPart")
obj.updateColors = True
if a2plib.GRAPHICALDEBUG == True and not "debugmode" in propList:
obj.addProperty("App::PropertyBool","debugmode","importPart")
obj.debugmode = False
if a2plib.GRAPHICALDEBUG == False and "debugmode" in propList:
obj.removeProperty("debugmode")
self.type = "a2p_importPart"
def onDocumentRestored(self,obj):
Proxy_importPart.setProperties(self,obj)
def __getstate__(self):
return None
def __setstate__(self, state):
return None
def dumps(self):
return None
def loads(self, state):
return None
def execute(self, obj):
# if a group containing LCS's exists, then move it
# according to the imported part
if hasattr(obj,"lcsLink"):
if len(obj.lcsLink) > 0:
lcsGroup = obj.lcsLink[0]
lcsGroup.Placement = obj.Placement
lcsGroup.purgeTouched() #untouch the lcsGroup, otherwise it stays touched.
#==============================================================================
class ImportedPartViewProviderProxy:
"""A ViewProvider for the a2p importPart object."""
def __init__(self,vobj):
vobj.Proxy = self
def claimChildren(self):
if hasattr(self,'Object'):
try:
children = list()
for obj in self.Object.InList:
if a2plib.isA2pObject(obj):
children.append(obj)
if hasattr(self.Object,'lcsLink'):
for obj in self.Object.lcsLink:
children.append(obj)
return children
except:
# FreeCAD has already deleted self.Object !!
return[]
else:
return []
def onDelete(self, viewObject, subelements): # subelements is a tuple of strings
if FreeCAD.activeDocument() != viewObject.Object.Document:
return False # only delete objects in the active Document anytime !!
obj = viewObject.Object
doc = obj.Document
deleteList = []
for c in doc.Objects:
if 'ConstraintInfo' in c.Content: # a related Constraint
if obj.Name in [ c.Object1, c.Object2 ]:
deleteList.append(c)
if len(deleteList) > 0:
for c in deleteList:
a2plib.removeConstraint(c) # also deletes the mirrors...
if hasattr(obj,"lcsLink"):
if len(obj.lcsLink)>0:
lscGroup = doc.getObject(obj.lcsLink[0].Name)
lscGroup.deleteContent(doc)
doc.removeObject(lscGroup.Name)
return True # If False is returned the object won't be deleted
def getIcon(self):
if hasattr(self,"Object"):
if a2plib.isA2pSketch(self.Object):
return a2plib.get_module_path()+'/icons/a2p_SketchReference.svg'
if hasattr(self.Object,"sourceFile") and hasattr(self.Object,"sourcePart"):
if self.Object.sourcePart is not None and self.Object.sourcePart !='':
return a2plib.get_module_path()+'/icons/a2p_ObjReference.svg'
if hasattr(self.Object,"subassemblyImport"):
if self.Object.subassemblyImport:
return ":/icons/a2p_Asm.svg"
if hasattr(self.Object,"sourceFile"):
if self.Object.sourceFile == 'converted':
return ":/icons/a2p_ConvertPart.svg"
return ":/icons/a2p_Obj.svg"
def __getstate__(self):
return None
def __setstate__(self, state):
return None
def dumps(self):
return None
def loads(self, state):
return None
def attach(self, vobj):
self.object_Name = vobj.Object.Name
self.Object = vobj.Object
def setupContextMenu(self, ViewObject, popup_menu):
pass
#==============================================================================
class Proxy_muxAssemblyObj(Proxy_importPart):
"""
A wrapper for compatibility reasons...
"""
pass
#==============================================================================
class Proxy_convertPart(Proxy_importPart):
"""
A wrapper for compatibility reasons...
"""
pass
#==============================================================================