-
Notifications
You must be signed in to change notification settings - Fork 17
/
importer_NameTable.py
435 lines (381 loc) · 14.2 KB
/
importer_NameTable.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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
# -*- coding: utf-8 -*-
'''
importer_NameTable.py:
'''
import importerSegNode
from importerSegment import SegmentReader
from importerUtils import *
from importerSegNode import _TYP_NODE_REF_, _TYP_NODE_X_REF_, _TYP_UINT32_A_, _TYP_NT_ENTRY_, REF_CHILD, REF_CROSS
from importerClasses import NtEntry, VAL_UINT32, VAL_REF
__author__ = 'Jens M. Plonka'
__copyright__ = 'Copyright 2018, Germany'
__url__ = "https://www.github.com/jmplonka/InventorLoader"
#TODO:
# E9132E94 is a name table entry
class NameTableReader(SegmentReader): # for BRep and DC
def __init__(self, segment):
super(NameTableReader, self).__init__(segment)
def getNtEntry(self, node, offset):
entry = None
nt, i = getUInt32(node.data, offset)
idx, i = getUInt32(node.data, i)
if (nt>0):
entry = NtEntry(nt, idx)
return entry, i
def ReadNtEntry(self, node, offset, name):
entry, i = self.getNtEntry(node, offset)
node.set(name, entry)
return i
def ReadNtEntryList(self, node, offset, name):
lst = []
cnt, i = getSInt32(node.data, offset)
for j in range(cnt):
entry, i = self.getNtEntry(node, i)
lst.append(entry)
node.set(name, lst)
return i
def Read2NtEntryList(self, node, offset, name):
lst = []
cnt, i = getUInt32(node.data, offset)
for j in range(cnt):
e1, i = self.getNtEntry(node, i)
e2, i = self.getNtEntry(node, i)
lst.append((e1, e2))
node.set(name, lst)
return i
def ReadNtEntryU8List(self, node, offset, name):
cnt, i = getUInt32(node.data, offset)
lst = []
for j in range(cnt):
entry, i = self.getNtEntry(node, i)
val, i = getUInt8(node.data, i)
lst.append([entry, val])
node.set(name, lst)
return i
def ReadNtEntryD64List(self, node, offset, name):
cnt, i = getUInt32(node.data, offset)
lst = []
for j in range(cnt):
entry, i = self.getNtEntry(node, i)
val, i = getFloat64(node.data, i)
lst.append([entry, val])
node.set(name, lst)
return i
def ReadList2U32(self, node):
i = self.ReadHeaderNameTableChild1Node(node)
i = node.ReadSInt32A(i, 6, 'a0')
i = node.ReadSInt32(i, 's32_1')
i = self.skipBlockSize(i)
return i
def ReadHeaderNameTableRootNode(self, node, typeName = None):
if (typeName is not None):
node.typeName = typeName
i = self.ReadList2U32(node)
i = self.ReadNtEntry(node, i, 'from') # or is it face 1?
i = self.ReadNtEntry(node, i, 'to') # or is it face 2?
i = node.ReadUInt8(i, 'u8_0') # direction 2 = positive, 1 = negative
i = node.ReadList2(i, importerSegNode._TYP_UINT32_A_, 'lst1', 2)
i = self.ReadNtEntryU8List(node, i, 'lst2')
i = self.skipBlockSize(i)
return i
def ReadRefU32ARefU32List(self, node, offset, name, size):
cnt, i = getUInt32(node.data, offset)
s = Struct('<LLL')
lst = []
for j in range(cnt):
a1, i = getUInt32A(node.data, i, 3)
a2, i = getUInt32A(node.data, i, size)
lst.append([a1, a2])
node.set(name, lst, VAL_UINT32)
return i
def ReadHeaderNameTableOtherNode(self, node, typeName = None):
if (typeName is not None):
node.typeName = typeName
i = self.ReadList2U32(node)
i = self.skipBlockSize(i)
return i
def Read_05C619B6(self, node):
i = self.ReadHeaderNameTableOtherNode(node)
i = node.ReadBoolean(i, 'b1')
i = self.ReadNtEntryList(node, i, 'entries')
i = self.ReadNtEntry(node, i, 'edge')
i = self.ReadNtEntryU8List(node, i, 'lst2')
i = self.ReadNtEntryD64List(node, i, 'a5')
i = self.ReadNtEntryD64List(node, i, 'a6')
if (self.version > 2010): i += 16
return i
def Read_22916CC1(self, node): # Name table root node
i = self.ReadHeaderNameTableOtherNode(node)
i = node.ReadList2(i, importerSegNode._TYP_UINT32_A_, 'lst1', 2)
return i
def Read_2D0AE083(self, node):
i = self.ReadHeaderNameTableOtherNode(node)
i = node.ReadList2(i, importerSegNode._TYP_UINT32_A_, 'lst1', 2)
i = node.ReadUInt32(i, 'u32_1')
i = self.skipBlockSize(i)
i = node.ReadUInt32A(i, 5, 'a1')
return i
def Read_436D821A(self, node):
i = self.ReadHeaderNameTableOtherNode(node)
i = node.ReadList2(i, importerSegNode._TYP_UINT32_A_, 'lst1', 2)
i = self.skipBlockSize(i)
i = node.ReadList2(i, importerSegNode._TYP_UINT32_A_, 'satAtrs', 5) # -> LoftSection.label.u32_4
return i
def Read_47BDD5FD(self, node):
i = self.ReadHeaderNameTableOtherNode(node)
i = node.ReadList2(i, importerSegNode._TYP_UINT32_A_, 'lst1', 2)
i = self.ReadNtEntry(node, i, 'edge')
cnt, i = getUInt32(node.data, i)
i = node.ReadUInt32A(i, cnt, 'a2')
return i
def Read_8E5D4198(self, node):
i = self.ReadHeaderNameTableOtherNode(node)
i = node.ReadList2(i, importerSegNode._TYP_UINT32_A_, 'lst1', 2)
i = self.ReadNtEntryList(node, i, 'entries')
i = self.skipBlockSize(i)
i = node.ReadUInt8(i, 'u8_0')
cnt, i = getUInt32(node.data, i)
i = node.ReadUInt32A(i, cnt, 'a1')
cnt, i = getUInt32(node.data, i)
i = node.ReadUInt32A(i, cnt, 'a2')
i = node.ReadUInt8(i, 'u8_1')
i = node.ReadUInt32A(i, 2, 'a3')
return i
def Read_DE0996B8(self, node): # Name table root node
i = self.ReadHeaderNameTableOtherNode(node)
return i
# The name table itself
def Read_CCE92042(self, node): # NameTable
i = node.Read_Header0('NameTable')
i = node.ReadChildRef(i, 'cld_0')
i = self.skipBlockSize(i)
i = node.ReadUInt32(i, 'lastIdx')
cnt, i = getUInt32(node.data, i) # strange mapping of U32 and REF
lst = {}
for j in range(cnt):
key, i = getUInt32(node.data, i)
val, i = self.ReadNodeRef(node, i, key, REF_CHILD, 'entries')
lst[key] = val
node.set('entries', lst, VAL_REF)
return i
def Read_CCC5085A(self, node): # FaceMergeData
i = node.Read_Header0('FaceMergeData')
i = node.ReadSInt32(i, 's32_0')
i = self.skipBlockSize(i)
i = node.ReadChildRef(i, 'nameTable')
i = self.ReadRefU32AList(node, i, 'lst0', 2, REF_CROSS)
i = self.ReadRefU32ARefU32List(node, i, 'lst1', 2)
i = self.ReadRefU32ARefU32List(node, i, 'lst2', 1)
cnt, i = getUInt32(node.data, i)
sep = ''
lst = []
# remember node content as it will be overwritten by ReadList2!
for j in range(cnt):
u32_0, i = getUInt32(node.data, i)
i = node.ReadList2(i, _TYP_UINT32_A_, 'tmp', 2)
lst0 = node.get('tmp')
u32_1, i = getUInt32(node.data, i)
i = node.ReadList2(i, _TYP_UINT32_A_, 'tmp', 2) # this is ref + uint!
lst1 = node.get('tmp')
lst.append([u32_0, lst0, u32_1, lst1])
sep = ','
node.delete('tmp')
node.set('lst3', lst, VAL_UINT32)
return i
# Root name table entries
def Read_00E41C0E(self, node): # Name table root node
i = self.ReadHeaderNameTableRootNode(node)
i = node.ReadList2(i, importerSegNode._TYP_UINT32_A_, 'lst3', 2)
i = node.ReadCrossRef(i, 'ref_3')
i = node.ReadUInt32(i, 'u32_3')
i = self.skipBlockSize(i)
i = node.ReadUInt32A(i, 3, 'a1')
i = node.ReadUInt8(i, 'u8_2')
i = node.ReadUInt32A(i, 5, 'a2')
i = node.ReadFloat64_3D(i, 'a3')
return i
def Read_139358BF(self, node): # Name table root node
i = self.ReadHeaderNameTableRootNode(node)
i = node.ReadList2(i, importerSegNode._TYP_UINT32_A_, 'lst3', 2)
i = self.ReadNtEntry(node, i, 'edge')
i = node.ReadUInt32(i, 'u32_1')
return i
def Read_14340ADB(self, node): # Name table root node
i = self.ReadHeaderNameTableRootNode(node)
i = node.ReadList2(i, importerSegNode._TYP_UINT32_A_, 'lst3', 2)
i = self.ReadNtEntry(node, i, 'edge')
i = node.ReadList2(i, importerSegNode._TYP_UINT32_A_, 'lst4', 7)
return i
def Read_22178C64(self, node): # Name table root node
i = self.ReadHeaderNameTableRootNode(node)
i = node.ReadList2(i, importerSegNode._TYP_UINT32_A_, 'lst3', 2) # same as lst1 ?!?
i = self.ReadNtEntry(node, i, 'edge')
i = self.skipBlockSize(i)
i = node.ReadList2(i, importerSegNode._TYP_UINT32_A_, 'satAtrs', 5) # [asmKey, atrKey, type, 0, 0]
return i
def Read_40236C89(self, node): # Name table root node
i = self.ReadHeaderNameTableRootNode(node)
i = node.ReadList2(i, importerSegNode._TYP_UINT32_A_, 'lst3', 2)
i = self.ReadNtEntry(node, i, 'edge')
i = self.skipBlockSize(i)
i = node.ReadUInt32A(i, 2, 'a1')
i = node.ReadUInt8(i, 'u8_1')
i = node.ReadUInt32A(i, 3, 'a2')
return i
def Read_488C5309(self, node): # Name table root node
i = self.ReadHeaderNameTableRootNode(node)
i = node.ReadList2(i, importerSegNode._TYP_UINT32_A_, 'lst3', 2)
i = self.ReadNtEntry(node, i, 'edge')
i = self.skipBlockSize(i)
i = node.ReadUInt8(i, 'u8_1')
i = node.ReadUInt32A(i, 4, 'a1')
return i
def Read_606D9AB1(self, node): # Name table root node
i = self.ReadHeaderNameTableRootNode(node)
i = node.ReadList2(i, importerSegNode._TYP_UINT32_A_, 'lst3', 2)
i = self.ReadNtEntry(node, i, 'edge')
i = self.skipBlockSize(i)
return i
def Read_6E2BCB60(self, node): # Name table root node
i = self.ReadHeaderNameTableRootNode(node)
i = node.ReadList2(i, importerSegNode._TYP_UINT32_A_, 'lst3', 2)
i = self.ReadNtEntry(node, i, 'edge')
i = self.skipBlockSize(i)
i = node.ReadUInt32(i, 'u32_4')
i = node.ReadUInt32(i, 'u32_5')
i = node.ReadFloat64(i, 'f64_0')
i = node.ReadUInt32(i, 'u32_2')
return i
def Read_9BB4281C(self, node): # Name table root node for Fillet-Chamfer
i = self.ReadHeaderNameTableRootNode(node)
i = node.ReadList2(i, importerSegNode._TYP_UINT32_A_, 'lst3', 2)
i = self.ReadNtEntry(node, i, 'edge')
i = self.skipBlockSize(i)
i = node.ReadUInt32A(i, 3, 'a1')
cnt, i = getUInt32(node.data, i)
i = node.ReadUInt32A(i, cnt, 'a2')
cnt, i = getUInt32(node.data, i)
i = node.ReadUInt32A(i, cnt, 'a3')
cnt, i = getUInt32(node.data, i)
i = node.ReadUInt32A(i, cnt, 'a4')
i = node.ReadUInt32A(i, 3, 'a5')
if (self.version > 2019): i += 4 # skip 00 00 00 00
return i
def Read_F4360D18(self, node): # Name table root node
i = self.ReadHeaderNameTableRootNode(node)
i = node.ReadList2(i, importerSegNode._TYP_UINT32_A_, 'lst3', 2)
i = self.ReadNtEntry(node, i, 'edge')
i = self.skipBlockSize(i)
i = node.ReadUInt32A(i, 3, 'a1')
node.set('a2', (), VAL_UINT32)
node.set('a3', (), VAL_UINT32)
node.set('a4', (), VAL_UINT32)
node.set('a5', (0,0,0), VAL_UINT32)
return i
def Read_BF32E0A6(self, node): # Name table root node
i = self.ReadHeaderNameTableRootNode(node)
i = self.ReadNtEntryList(node, i, 'entries')
return i
def Read_D4BDEE88(self, node): # Name table root node
i = self.ReadHeaderNameTableRootNode(node)
i = node.ReadList2(i, importerSegNode._TYP_UINT32_A_, 'lst3', 2)
i = self.ReadNtEntry(node, i, 'edge')
i = node.ReadUInt32A(i, 3, 'a2')
return i
def Read_F7693D55(self, node): # Name table root node
i = self.ReadHeaderNameTableRootNode(node)
i = node.ReadList2(i, importerSegNode._TYP_UINT32_A_, 'lst3', 2)
i = self.ReadNtEntry(node, i, 'edge')
i = self.skipBlockSize(i)
i = node.ReadUInt32(i, 'u32_4')
return i
def Read_FF46726C(self, node): # Name table root node
i = self.ReadHeaderNameTableRootNode(node)
i = node.ReadList2(i, importerSegNode._TYP_UINT32_A_, 'lst3', 2)
i = self.ReadNtEntry(node, i, 'edge')
i = self.skipBlockSize(i)
i = node.ReadUInt32(i, 'u32_1')
i = node.ReadUInt16(i, 'u16_0')
return i
####################
# 1x Child name table entries
def ReadHeaderNameTableChild1Node(self, node, typeName = None):
i = node.Read_Header0(typeName)
i = node.ReadUInt32(i, 'u32_0')
i = self.skipBlockSize(i)
i = node.ReadList2(i, _TYP_NODE_REF_, 'lst0')
return i
def Read_B1ED010F(self, node): # Name table child node
i = self.ReadHeaderNameTableChild1Node(node)
i = node.ReadSInt32A(i, 7, 'a0')
i = self.skipBlockSize(i, 2)
i = self.ReadNtEntry(node, i, 'from') # or is it face 1?
i = self.ReadNtEntryList(node, i, 'entries')
return i
def Read_BDE13180(self, node): # Name table child node
i = self.ReadHeaderNameTableChild1Node(node)
return i
####################
# 2x Child name table entries
def ReadHeaderNameTableChild2Node(self, node, typeName = None):
i = self.ReadHeaderNameTableChild1Node(node, typeName)
i = node.ReadSInt32A(i, 6, 'a0')
i = node.ReadSInt32(i, 's32_0')
i = self.skipBlockSize(i, 2)
i = node.ReadList2(i, _TYP_UINT32_A_, 'lst1', 2)
return i
def Read_0811C56E(self, node): # Name table child node
i = self.ReadHeaderNameTableChild2Node(node)
i = node.ReadUInt32(i, 'u32_1')
i = self.skipBlockSize(i)
i = node.ReadUInt32(i, 'u32_2')
i = node.ReadUInt8(i, 'u8_0')
i = node.ReadUInt32A(i, 4, 'a1')
if (self.version > 2011): i += 1
return i
def Read_31D7A200(self, node): # Name table child node
i = self.ReadHeaderNameTableChild2Node(node)
i = self.ReadNtEntryList(node, i, 'entries')
i = self.skipBlockSize(i)
i = node.ReadUInt32(i, 'u32_1')
i = node.ReadFloat64(i, 'f64_0')
i = node.ReadUInt8(i, 'u8_0')
i = node.ReadUInt32(i, 'u32_3')
return i
def Read_36895B07(self, node): # Name table child node
i = self.ReadHeaderNameTableChild2Node(node)
return i
def Read_896A9790(self, node): # Name table child node
i = self.ReadHeaderNameTableChild2Node(node)
i = node.ReadUInt32(i, 'u32_1')
return i
def Read_2E04A208(self, node): # Name table child node for points (last-vertex)
i = self.ReadHeaderNameTableChild2Node(node)
i = self.skipBlockSize(i)
i = node.ReadUInt32A(i, 3, 'a1')
i = node.ReadUInt32A(i, 2, 'a2') # always (0,0)
cnt, i = getUInt32(node.data, i)
i = node.ReadUInt32A(i, cnt, 'a3')
i = node.ReadUInt32A(i, 3, 'a4') # always (0,0,0)
return i
def Read_90F4820A(self, node): # Name table child node for points (first-vertex)
i = self.ReadHeaderNameTableChild2Node(node)
i = self.skipBlockSize(i)
i = node.ReadUInt32A(i, 3, 'a1')
return i
def Read_A170F6B6(self, node): # Name table child node
i = self.ReadHeaderNameTableChild2Node(node)
i = node.ReadSInt32A(i, 7, 'a1')
i = node.ReadUInt32(i, 'u32_1')
cnt, i = getUInt32(node.data, i)
lst = []
for j in range(cnt):
a, i = getUInt32A(node.data, i, 7)
lst.append(a)
node.set('lst2', lst, VAL_UINT32)
return i
def Read_E5289C69(self, node): # Name table child node
i = self.ReadHeaderNameTableChild2Node(node)
i = node.ReadUInt32(i, 'u32_1')
return i
# unknown name table entries