f3d2solidcraft 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- f3d2solidcraft/__init__.py +3 -0
- f3d2solidcraft/__main__.py +3 -0
- f3d2solidcraft/_vendor/__init__.py +0 -0
- f3d2solidcraft/_vendor/ezf3d/LICENSE +21 -0
- f3d2solidcraft/_vendor/ezf3d/__init__.py +1 -0
- f3d2solidcraft/_vendor/ezf3d/container/__init__.py +1 -0
- f3d2solidcraft/_vendor/ezf3d/container/archive.py +204 -0
- f3d2solidcraft/_vendor/ezf3d/model/__init__.py +1 -0
- f3d2solidcraft/_vendor/ezf3d/model/parameters.py +365 -0
- f3d2solidcraft/_vendor/ezf3d/model/sketch.py +645 -0
- f3d2solidcraft/_vendor/ezf3d/model/timeline.py +493 -0
- f3d2solidcraft/_vendor/ezf3d/streams/__init__.py +1 -0
- f3d2solidcraft/_vendor/ezf3d/streams/manifest.py +262 -0
- f3d2solidcraft/_vendor/ezf3d/streams/primitives.py +191 -0
- f3d2solidcraft/_vendor/ezf3d/streams/segment.py +521 -0
- f3d2solidcraft/cli.py +574 -0
- f3d2solidcraft/engine.py +458 -0
- f3d2solidcraft/fallback.py +250 -0
- f3d2solidcraft/geometry.py +397 -0
- f3d2solidcraft/mappers/__init__.py +141 -0
- f3d2solidcraft/mappers/bodies.py +99 -0
- f3d2solidcraft/mappers/combine.py +73 -0
- f3d2solidcraft/mappers/components.py +542 -0
- f3d2solidcraft/mappers/edges.py +449 -0
- f3d2solidcraft/mappers/extrude.py +1501 -0
- f3d2solidcraft/mappers/faces.py +50 -0
- f3d2solidcraft/mappers/loft.py +149 -0
- f3d2solidcraft/mappers/outputs.py +73 -0
- f3d2solidcraft/mappers/params.py +134 -0
- f3d2solidcraft/mappers/pattern.py +68 -0
- f3d2solidcraft/mappers/planes.py +222 -0
- f3d2solidcraft/mappers/primitives.py +144 -0
- f3d2solidcraft/mappers/records.py +51 -0
- f3d2solidcraft/mappers/revolve.py +134 -0
- f3d2solidcraft/mappers/sheet.py +95 -0
- f3d2solidcraft/mappers/shell.py +180 -0
- f3d2solidcraft/mappers/sketch.py +455 -0
- f3d2solidcraft/mcp.py +218 -0
- f3d2solidcraft/model.py +503 -0
- f3d2solidcraft/oracle.py +905 -0
- f3d2solidcraft/pairing.py +105 -0
- f3d2solidcraft/reader/__init__.py +77 -0
- f3d2solidcraft/reader/cadir.py +832 -0
- f3d2solidcraft/reader/fusion.py +218 -0
- f3d2solidcraft/reader/locale.py +115 -0
- f3d2solidcraft/replay.py +322 -0
- f3d2solidcraft/report.py +107 -0
- f3d2solidcraft/tools.py +219 -0
- f3d2solidcraft/verify.py +186 -0
- f3d2solidcraft/visibility.py +95 -0
- f3d2solidcraft-0.3.0.dist-info/METADATA +189 -0
- f3d2solidcraft-0.3.0.dist-info/RECORD +74 -0
- f3d2solidcraft-0.3.0.dist-info/WHEEL +4 -0
- f3d2solidcraft-0.3.0.dist-info/entry_points.txt +5 -0
- f3d2solidcraft-0.3.0.dist-info/licenses/LICENSE +21 -0
- f3d2solidcraft-0.3.0.dist-info/licenses/src/f3d2solidcraft/_vendor/ezf3d/LICENSE +21 -0
- f3d2solidcraft_app/__init__.py +5 -0
- f3d2solidcraft_app/__main__.py +40 -0
- f3d2solidcraft_app/engines.py +158 -0
- f3d2solidcraft_app/events.py +35 -0
- f3d2solidcraft_app/opener.py +22 -0
- f3d2solidcraft_app/outcome.py +54 -0
- f3d2solidcraft_app/resources/icon-128.png +0 -0
- f3d2solidcraft_app/resources/icon-16.png +0 -0
- f3d2solidcraft_app/resources/icon-256.png +0 -0
- f3d2solidcraft_app/resources/icon-32.png +0 -0
- f3d2solidcraft_app/resources/icon-512.png +0 -0
- f3d2solidcraft_app/resources/icon-64.png +0 -0
- f3d2solidcraft_app/resources/icon.icns +0 -0
- f3d2solidcraft_app/resources/icon.ico +0 -0
- f3d2solidcraft_app/resources/icon.svg +26 -0
- f3d2solidcraft_app/runner.py +91 -0
- f3d2solidcraft_app/texts.py +98 -0
- f3d2solidcraft_app/window.py +677 -0
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
"""The timeline: which features a design has, and in what order.
|
|
2
|
+
|
|
3
|
+
A feature is an ordinary bulk object with a recognisable tail::
|
|
4
|
+
|
|
5
|
+
wstr guid all-zero for most features
|
|
6
|
+
0x00 0x00 0x00
|
|
7
|
+
u32 n, n x reference the inputs -- sketches, faces, bodies it consumes
|
|
8
|
+
u32 token 0xFFFFFFFF where Fusion wrote none
|
|
9
|
+
wstr name "Extrude", "Fillet", "Base Feature"; may be empty
|
|
10
|
+
|
|
11
|
+
The name is the label Fusion shows in the timeline, and a renamed feature
|
|
12
|
+
carries the name the user typed.
|
|
13
|
+
|
|
14
|
+
**Order is not creation order.** Every feature is followed in the object index
|
|
15
|
+
by a small *timeline item*, and one object lists those items in the order the
|
|
16
|
+
timeline runs. In SUCKER that list interleaves ids 1270, 12657, 12825 -- a
|
|
17
|
+
feature created late sitting tenth -- which is what a designer dragging the
|
|
18
|
+
timeline marker back and inserting there produces. Ordering by object id
|
|
19
|
+
would put it last, so the list is read rather than reconstructed.
|
|
20
|
+
|
|
21
|
+
That one is confirmed against Fusion: ``Mirror``, object 12657, is the tenth
|
|
22
|
+
thing SUCKER's history shows. It is the only claim in this module that no
|
|
23
|
+
second reading of the file could settle, so it was settled by opening the
|
|
24
|
+
design.
|
|
25
|
+
|
|
26
|
+
Nothing points from an item back to its feature; the feature is simply the
|
|
27
|
+
object before it in the index. That is what makes the list identifiable:
|
|
28
|
+
:func:`read_timeline` accepts only a list whose every entry resolves that way,
|
|
29
|
+
and takes the longest. It resolves 3 of 3, 58 of 58, 225 of 225 and 400 of
|
|
30
|
+
400 across the four samples, and there is exactly one such list per design.
|
|
31
|
+
|
|
32
|
+
Two independent checks say the reading is right rather than merely
|
|
33
|
+
self-consistent. Every name maps to a kind the registries declare -- see
|
|
34
|
+
:data:`KIND_ALIASES` for the labels Fusion spells differently -- and no kind
|
|
35
|
+
appears in the timeline more often than the registry's own counter says was
|
|
36
|
+
ever issued (:meth:`~ezf3d.streams.segment.BulkStream.feature_counters`).
|
|
37
|
+
Both hold for every sample.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
from __future__ import annotations
|
|
41
|
+
|
|
42
|
+
import re
|
|
43
|
+
import struct
|
|
44
|
+
from bisect import bisect_right
|
|
45
|
+
from collections import Counter
|
|
46
|
+
from collections.abc import Iterable
|
|
47
|
+
from dataclasses import dataclass, field
|
|
48
|
+
|
|
49
|
+
from f3d2solidcraft._vendor.ezf3d.model.parameters import Parameter
|
|
50
|
+
from f3d2solidcraft._vendor.ezf3d.streams.primitives import scan_strings
|
|
51
|
+
from f3d2solidcraft._vendor.ezf3d.streams.segment import BulkObject, Segment
|
|
52
|
+
|
|
53
|
+
#: Bytes between a feature's guid and its input count.
|
|
54
|
+
FEATURE_GAP = 3
|
|
55
|
+
|
|
56
|
+
#: A reference on the wire: ``0x01``, a ``u64`` object id, two spare bytes.
|
|
57
|
+
_STRIDE = 11
|
|
58
|
+
_REFERENCE = 0x01
|
|
59
|
+
|
|
60
|
+
#: Longest reference list treated as real, and longest name.
|
|
61
|
+
_MAX_INPUTS = 4096
|
|
62
|
+
_MAX_NAME = 128
|
|
63
|
+
|
|
64
|
+
GUID_RE = re.compile(r"[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}")
|
|
65
|
+
|
|
66
|
+
#: Bytes into an object searched for a reference count. The lists seen start
|
|
67
|
+
#: it at 10 and 17; the margin covers a revision that moves it.
|
|
68
|
+
_HEADER_SEARCH = 48
|
|
69
|
+
|
|
70
|
+
#: Timeline labels the general rules cannot reach. Most labels are the
|
|
71
|
+
#: registry kind with ``Feature`` dropped -- ``Extrude`` for
|
|
72
|
+
#: ``ExtrudeFeature`` -- or the same name with its spaces removed, and those
|
|
73
|
+
#: need no entry here; ``JointOrigin`` and ``MotionLink`` were listed until a
|
|
74
|
+
#: test showed the plain rule already found them. What is left is where
|
|
75
|
+
#: Fusion's UI and its serializer genuinely disagree, and the counter check is
|
|
76
|
+
#: what says each mapping is right rather than merely plausible.
|
|
77
|
+
KIND_ALIASES = {
|
|
78
|
+
"Assemble": "JointAssembleFeature",
|
|
79
|
+
"Body->Comp": "ComponentFromBodiesFeature",
|
|
80
|
+
"C-Pattern": "CircularPattern",
|
|
81
|
+
"CopyPasteBodies": "PasteBodies",
|
|
82
|
+
"Fillet": "FilletEdgeFeature",
|
|
83
|
+
"Mirror": "MirrorPattern",
|
|
84
|
+
"MoveFace": "MoveFacesFeature",
|
|
85
|
+
"Position": "SnapshotFeature",
|
|
86
|
+
"R-Pattern": "RectangularPattern",
|
|
87
|
+
"RemoveBody": "DeleteBody",
|
|
88
|
+
"Split": "SplitBodyFeature",
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
#: Bytes between a record's revision string and the extrude settings flag:
|
|
93
|
+
#: a ``u64``, a ``u32``, a spare byte, a ``u32`` and three spare.
|
|
94
|
+
SETTINGS_GAP = 20
|
|
95
|
+
|
|
96
|
+
#: What an extrude does with the material it sweeps. ``Join``, ``Cut`` and
|
|
97
|
+
#: ``NewBody`` are pinned by a Fusion readout of SUCKER's eight extrudes; 3 is
|
|
98
|
+
#: never seen in the samples and is left unnamed rather than guessed at.
|
|
99
|
+
EXTRUDE_OPERATIONS = {1: "Join", 2: "Cut", 4: "NewBody"}
|
|
100
|
+
|
|
101
|
+
#: Which way it goes. ``OneSide`` and ``Symmetric`` come from the same
|
|
102
|
+
#: readout. ``TwoSides`` is corroborated instead by the parameters: the one
|
|
103
|
+
#: record in the samples carrying a 2 is also the only extrude whose roles
|
|
104
|
+
#: include ``AgainstDistance`` and ``Side2TaperAngle``, and those two facts are
|
|
105
|
+
#: written into different parts of the file.
|
|
106
|
+
EXTRUDE_DIRECTIONS = {1: "OneSide", 2: "TwoSides", 3: "Symmetric"}
|
|
107
|
+
|
|
108
|
+
#: Codes accepted while looking for the settings block. Anything outside them
|
|
109
|
+
#: means the anchor landed on the wrong revision string, which is what keeps a
|
|
110
|
+
#: loft's and a work plane's records from reading as extrude settings.
|
|
111
|
+
_OPERATION_CODES = frozenset({1, 2, 3, 4})
|
|
112
|
+
_DIRECTION_CODES = frozenset({1, 2, 3})
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
@dataclass(frozen=True, slots=True)
|
|
116
|
+
class Extrude:
|
|
117
|
+
"""What an extrude does, as opposed to by how much."""
|
|
118
|
+
|
|
119
|
+
#: ``Join``, ``Cut``, ``NewBody``, or ``""`` for a code with no name yet.
|
|
120
|
+
operation: str
|
|
121
|
+
#: ``OneSide``, ``TwoSides`` or ``Symmetric``.
|
|
122
|
+
direction: str
|
|
123
|
+
#: The three ``u32`` as read. The third is 2 for all but one record in the
|
|
124
|
+
#: samples and is not understood, so it is carried rather than interpreted.
|
|
125
|
+
codes: tuple[int, int, int]
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
@dataclass(frozen=True, slots=True)
|
|
129
|
+
class Feature:
|
|
130
|
+
"""One entry of the timeline."""
|
|
131
|
+
|
|
132
|
+
#: Object id, which is creation order -- not timeline order.
|
|
133
|
+
oid: int
|
|
134
|
+
#: Position in the timeline, counting from zero.
|
|
135
|
+
index: int
|
|
136
|
+
#: The label Fusion shows, or the name the user gave it. Empty when
|
|
137
|
+
#: Fusion wrote none; 16 of Robotic_Bhujha's 225 are like that.
|
|
138
|
+
name: str
|
|
139
|
+
#: Registry kind this label names, or ``""`` when nothing declares it.
|
|
140
|
+
kind: str
|
|
141
|
+
#: The timeline item that put it here -- the object right after it.
|
|
142
|
+
item: int
|
|
143
|
+
#: Objects it consumes: sketches, faces, bodies, other features.
|
|
144
|
+
inputs: tuple[int, ...] = ()
|
|
145
|
+
#: The numbers that drive it, in object order. Filled in only when
|
|
146
|
+
#: :func:`read_timeline` is given the design's parameters; the feature
|
|
147
|
+
#: record itself does not name them.
|
|
148
|
+
parameters: tuple[Parameter, ...] = ()
|
|
149
|
+
#: Operation and direction, for an extrude. ``None`` for every other kind:
|
|
150
|
+
#: no other kind's record reads as one at this offset.
|
|
151
|
+
extrude: Extrude | None = None
|
|
152
|
+
|
|
153
|
+
@property
|
|
154
|
+
def is_named(self) -> bool:
|
|
155
|
+
return bool(self.name)
|
|
156
|
+
|
|
157
|
+
def role(self, name: str) -> Parameter | None:
|
|
158
|
+
"""The parameter filling one slot, e.g. ``AlongDistance``."""
|
|
159
|
+
return next((p for p in self.parameters if p.role == name), None)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
@dataclass(slots=True)
|
|
163
|
+
class Timeline:
|
|
164
|
+
"""A design's ordered features, and the registry they are checked against."""
|
|
165
|
+
|
|
166
|
+
#: Object id of the list, or 0 when a design has no timeline.
|
|
167
|
+
oid: int = 0
|
|
168
|
+
features: list[Feature] = field(default_factory=list)
|
|
169
|
+
#: Per-kind counters the registries declare — an ever-created upper bound.
|
|
170
|
+
declared: Counter[str] = field(default_factory=Counter)
|
|
171
|
+
#: Named features the design holds that the list does *not*, by kind.
|
|
172
|
+
#: Empty for a single-component design; Robotic_Bhujha's assembly-level
|
|
173
|
+
#: work — joint origins, component creation and placement — sits here,
|
|
174
|
+
#: which says this list is the modelling timeline and not the whole of
|
|
175
|
+
#: what Fusion shows. Counted rather than quietly dropped.
|
|
176
|
+
outside: Counter[str] = field(default_factory=Counter)
|
|
177
|
+
#: Every named feature-shaped object in the design, by id -- the ones the
|
|
178
|
+
#: list holds and the ones :attr:`outside` counts alike. Finding the list
|
|
179
|
+
#: at all means building this, and the wider set is what
|
|
180
|
+
#: :mod:`ezf3d.model.sketch` needs: Focuser Mk1 has 39 sketches of which
|
|
181
|
+
#: the list carries 33.
|
|
182
|
+
named: dict[int, str] = field(default_factory=dict)
|
|
183
|
+
|
|
184
|
+
def __len__(self) -> int:
|
|
185
|
+
return len(self.features)
|
|
186
|
+
|
|
187
|
+
def __iter__(self):
|
|
188
|
+
return iter(self.features)
|
|
189
|
+
|
|
190
|
+
def census(self) -> Counter[str]:
|
|
191
|
+
"""How many live features of each kind, by registry kind."""
|
|
192
|
+
return Counter(feature.kind for feature in self.features if feature.kind)
|
|
193
|
+
|
|
194
|
+
def unnamed(self) -> int:
|
|
195
|
+
return sum(1 for feature in self.features if not feature.name)
|
|
196
|
+
|
|
197
|
+
def check(self) -> tuple[tuple[str, ...], tuple[tuple[str, int, int], ...]]:
|
|
198
|
+
"""``(labels no registry declares, kinds that outrun their counter)``.
|
|
199
|
+
|
|
200
|
+
The second is the sharper of the two: a counter is what Fusion counts
|
|
201
|
+
its own labels up with, so a timeline holding more extrudes than were
|
|
202
|
+
ever issued would mean the list is not the timeline.
|
|
203
|
+
"""
|
|
204
|
+
unknown = sorted(
|
|
205
|
+
{feature.name for feature in self.features if feature.name and not feature.kind}
|
|
206
|
+
)
|
|
207
|
+
census = self.census()
|
|
208
|
+
over = tuple(
|
|
209
|
+
(kind, live, self.declared.get(kind, 0))
|
|
210
|
+
for kind, live in sorted(census.items())
|
|
211
|
+
if live > self.declared.get(kind, 0)
|
|
212
|
+
)
|
|
213
|
+
return tuple(unknown), over
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def kind_of(name: str, declared: Counter[str] | dict[str, int]) -> str:
|
|
217
|
+
"""The registry kind *name* labels, or ``""`` when none matches.
|
|
218
|
+
|
|
219
|
+
Tried in order: the alias table, the name itself, the name with spaces
|
|
220
|
+
removed, and that plus ``Feature`` — which is how Fusion spells most of
|
|
221
|
+
them (``Extrude`` for ``ExtrudeFeature``).
|
|
222
|
+
"""
|
|
223
|
+
if not name:
|
|
224
|
+
return ""
|
|
225
|
+
bare = name.replace(" ", "")
|
|
226
|
+
for candidate in (KIND_ALIASES.get(name, ""), name, bare, f"{bare}Feature"):
|
|
227
|
+
if candidate and candidate in declared:
|
|
228
|
+
return candidate
|
|
229
|
+
return ""
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def read_extrude(body: bytes, item: BulkObject) -> Extrude | None:
|
|
233
|
+
"""An extrude's operation and direction, or ``None``.
|
|
234
|
+
|
|
235
|
+
The settings sit a fixed distance past the record's revision string, and a
|
|
236
|
+
record can carry several of those -- two of Robotic_Bhujha's extrudes nest
|
|
237
|
+
eleven -- so every one is tried and the block is accepted only when its
|
|
238
|
+
codes are ones an extrude uses. That range check is the whole of the
|
|
239
|
+
safety: without it a loft and four work planes read as extrudes.
|
|
240
|
+
|
|
241
|
+
It found the block in **214 of 214** extrudes across the four samples and
|
|
242
|
+
in no record of any other kind.
|
|
243
|
+
"""
|
|
244
|
+
for found in scan_strings(body, start=item.offset, end=item.end, min_len=3):
|
|
245
|
+
if found.kind != "str8" or not found.value.isdigit():
|
|
246
|
+
continue
|
|
247
|
+
at = found.end + SETTINGS_GAP
|
|
248
|
+
if at + 13 > item.end or body[at] != _REFERENCE:
|
|
249
|
+
continue
|
|
250
|
+
codes = struct.unpack_from("<3I", body, at + 1)
|
|
251
|
+
if codes[0] in _OPERATION_CODES and codes[1] in _DIRECTION_CODES:
|
|
252
|
+
return Extrude(
|
|
253
|
+
operation=EXTRUDE_OPERATIONS.get(codes[0], ""),
|
|
254
|
+
direction=EXTRUDE_DIRECTIONS[codes[1]],
|
|
255
|
+
codes=codes,
|
|
256
|
+
)
|
|
257
|
+
return None
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def _wstr_at(body: bytes, pos: int, limit: int) -> tuple[str, int] | None:
|
|
261
|
+
if pos + 4 > limit:
|
|
262
|
+
return None
|
|
263
|
+
count = struct.unpack_from("<I", body, pos)[0]
|
|
264
|
+
if count > _MAX_NAME or pos + 4 + 2 * count > limit:
|
|
265
|
+
return None
|
|
266
|
+
raw = body[pos + 4 : pos + 4 + 2 * count]
|
|
267
|
+
if any(raw[2 * i + 1] for i in range(count)):
|
|
268
|
+
return None
|
|
269
|
+
return raw.decode("utf-16-le"), pos + 4 + 2 * count
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
def _references(body: bytes, pos: int, count: int, limit: int) -> tuple[int, ...] | None:
|
|
273
|
+
"""*count* wire references starting at *pos*, or ``None`` if they are not there."""
|
|
274
|
+
if count > _MAX_INPUTS or pos + _STRIDE * count > limit:
|
|
275
|
+
return None
|
|
276
|
+
if any(body[pos + _STRIDE * i] != _REFERENCE for i in range(count)):
|
|
277
|
+
return None
|
|
278
|
+
return tuple(struct.unpack_from("<Q", body, pos + 1 + _STRIDE * i)[0] for i in range(count))
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def read_feature(body: bytes, item: BulkObject) -> tuple[str, tuple[int, ...]] | None:
|
|
282
|
+
"""``(name, inputs)`` if *item* is shaped like a feature, else ``None``.
|
|
283
|
+
|
|
284
|
+
An empty name is accepted -- Fusion leaves one on features it does not
|
|
285
|
+
label -- so this alone is a loose test. What makes it safe is that
|
|
286
|
+
:func:`read_timeline` only ever asks it about the object *preceding* a
|
|
287
|
+
timeline item.
|
|
288
|
+
|
|
289
|
+
A record can hold more than one guid, and the tail only reads correctly
|
|
290
|
+
after one of them. A **named** parse therefore wins over an unnamed one
|
|
291
|
+
wherever both are available: taking the first guid that merely parses cost
|
|
292
|
+
Robotic_Bhujha all eight of its ``Assemble`` features, which read as
|
|
293
|
+
unlabelled off an earlier guid.
|
|
294
|
+
"""
|
|
295
|
+
fallback: tuple[str, tuple[int, ...]] | None = None
|
|
296
|
+
for found in scan_strings(body, start=item.offset, end=item.end, min_len=1):
|
|
297
|
+
if found.kind != "wstr" or not GUID_RE.fullmatch(found.value):
|
|
298
|
+
continue
|
|
299
|
+
at = found.end + FEATURE_GAP
|
|
300
|
+
if at + 4 > item.end:
|
|
301
|
+
continue
|
|
302
|
+
count = struct.unpack_from("<I", body, at)[0]
|
|
303
|
+
inputs = _references(body, at + 4, count, item.end)
|
|
304
|
+
if inputs is None:
|
|
305
|
+
continue
|
|
306
|
+
named = _wstr_at(body, at + 8 + _STRIDE * count, item.end)
|
|
307
|
+
if named is None:
|
|
308
|
+
continue
|
|
309
|
+
name = named[0]
|
|
310
|
+
if name and (GUID_RE.fullmatch(name) or any(char < " " for char in name)):
|
|
311
|
+
continue
|
|
312
|
+
if name:
|
|
313
|
+
return name, inputs
|
|
314
|
+
if fallback is None:
|
|
315
|
+
fallback = (name, inputs)
|
|
316
|
+
return fallback
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
def read_timeline(segment: Segment, parameters: Iterable[Parameter] | None = None) -> Timeline:
|
|
320
|
+
"""Read a design segment's timeline, in order.
|
|
321
|
+
|
|
322
|
+
The list is found by shape: an object that is nothing but a count and that
|
|
323
|
+
many references, every one of which is preceded in the index by a
|
|
324
|
+
feature-shaped object. Ties go to the lowest object id so two reads of the
|
|
325
|
+
same file give the same answer.
|
|
326
|
+
|
|
327
|
+
Pass *parameters* to fill in :attr:`Feature.parameters`; see
|
|
328
|
+
:func:`attribute` for the rule and what checks it. It is optional because
|
|
329
|
+
it costs a second pass over the stream and most callers only want the
|
|
330
|
+
order.
|
|
331
|
+
"""
|
|
332
|
+
body = segment.bulk.body
|
|
333
|
+
items = segment.objects()
|
|
334
|
+
declared = segment.bulk.feature_counters()
|
|
335
|
+
if not items:
|
|
336
|
+
return Timeline(declared=declared)
|
|
337
|
+
|
|
338
|
+
position = {entry.oid: index for index, entry in enumerate(items)}
|
|
339
|
+
by_id = {entry.oid: entry for entry in items}
|
|
340
|
+
features: dict[int, tuple[str, tuple[int, ...]]] = {}
|
|
341
|
+
for entry in items:
|
|
342
|
+
found = read_feature(body, entry)
|
|
343
|
+
if found is not None:
|
|
344
|
+
features[entry.oid] = found
|
|
345
|
+
|
|
346
|
+
best: tuple[int, list[int], tuple[int, ...]] | None = None
|
|
347
|
+
for entry in items:
|
|
348
|
+
found = _longest_list(body, entry, items, position, features)
|
|
349
|
+
if found is None:
|
|
350
|
+
continue
|
|
351
|
+
if best is None or len(found[0]) > len(best[1]):
|
|
352
|
+
best = (entry.oid, found[0], found[1])
|
|
353
|
+
|
|
354
|
+
named = {oid: name for oid, (name, _) in features.items() if name}
|
|
355
|
+
if best is None:
|
|
356
|
+
return Timeline(
|
|
357
|
+
declared=declared,
|
|
358
|
+
outside=_outside(features, set(), declared),
|
|
359
|
+
named=named,
|
|
360
|
+
)
|
|
361
|
+
oid, owners, list_items = best
|
|
362
|
+
owned = attribute(features, parameters or ())
|
|
363
|
+
return Timeline(
|
|
364
|
+
oid=oid,
|
|
365
|
+
features=[
|
|
366
|
+
Feature(
|
|
367
|
+
oid=owner,
|
|
368
|
+
index=index,
|
|
369
|
+
name=features[owner][0],
|
|
370
|
+
kind=kind_of(features[owner][0], declared),
|
|
371
|
+
item=list_items[index],
|
|
372
|
+
inputs=features[owner][1],
|
|
373
|
+
parameters=owned.get(owner, ()),
|
|
374
|
+
extrude=(
|
|
375
|
+
read_extrude(body, by_id[owner])
|
|
376
|
+
if kind_of(features[owner][0], declared) == "ExtrudeFeature"
|
|
377
|
+
else None
|
|
378
|
+
),
|
|
379
|
+
)
|
|
380
|
+
for index, owner in enumerate(owners)
|
|
381
|
+
],
|
|
382
|
+
declared=declared,
|
|
383
|
+
outside=_outside(features, set(owners), declared),
|
|
384
|
+
named=named,
|
|
385
|
+
)
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
def attribute(
|
|
389
|
+
features: dict[int, tuple[str, tuple[int, ...]]],
|
|
390
|
+
parameters: Iterable[Parameter],
|
|
391
|
+
) -> dict[int, tuple[Parameter, ...]]:
|
|
392
|
+
"""Which feature owns which parameter: the nearest **named** one before it.
|
|
393
|
+
|
|
394
|
+
The feature record does not name its parameters -- its ``inputs`` list
|
|
395
|
+
reaches one 4 times in 1,438 -- so ownership is positional: ids are issued
|
|
396
|
+
in creation order, and Fusion writes a feature's parameters immediately
|
|
397
|
+
after it.
|
|
398
|
+
|
|
399
|
+
What checks a positional rule is that the parameter's ``role`` is the slot
|
|
400
|
+
it fills in the feature that owns it. ``TaperAngle`` must land on an
|
|
401
|
+
extrude and ``Radius`` on a fillet, and over the twenty commonest roles
|
|
402
|
+
they do 97.6% of the time -- the exceptions being roles that genuinely
|
|
403
|
+
belong to several kinds (``countU`` to three pattern kinds) rather than
|
|
404
|
+
misattributions.
|
|
405
|
+
|
|
406
|
+
*features* must be **every** named feature-shaped object, not only the ones
|
|
407
|
+
the timeline lists: restricted to the timeline the agreement falls to 85%,
|
|
408
|
+
because the features 3.4 counts as sitting outside the list fall between.
|
|
409
|
+
"""
|
|
410
|
+
named = sorted(oid for oid, (name, _) in features.items() if name)
|
|
411
|
+
if not named:
|
|
412
|
+
return {}
|
|
413
|
+
owned: dict[int, list[Parameter]] = {}
|
|
414
|
+
for parameter in sorted(parameters, key=lambda p: p.oid):
|
|
415
|
+
position = bisect_right(named, parameter.oid) - 1
|
|
416
|
+
if position >= 0:
|
|
417
|
+
owned.setdefault(named[position], []).append(parameter)
|
|
418
|
+
return {oid: tuple(values) for oid, values in owned.items()}
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
def _outside(
|
|
422
|
+
features: dict[int, tuple[str, tuple[int, ...]]],
|
|
423
|
+
inside: set[int],
|
|
424
|
+
declared: Counter[str],
|
|
425
|
+
) -> Counter[str]:
|
|
426
|
+
"""Named features the timeline list does not hold, by kind."""
|
|
427
|
+
return Counter(
|
|
428
|
+
kind_of(name, declared) or name
|
|
429
|
+
for oid, (name, _) in features.items()
|
|
430
|
+
if name and oid not in inside
|
|
431
|
+
)
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
def _longest_list(
|
|
435
|
+
body: bytes,
|
|
436
|
+
entry: BulkObject,
|
|
437
|
+
items: list[BulkObject],
|
|
438
|
+
position: dict[int, int],
|
|
439
|
+
features: dict[int, tuple[str, tuple[int, ...]]],
|
|
440
|
+
) -> tuple[list[int], tuple[int, ...]] | None:
|
|
441
|
+
"""The longest fully-resolving reference list inside one object.
|
|
442
|
+
|
|
443
|
+
The count sits at a different offset per record revision — 17 in the
|
|
444
|
+
``.f3d`` samples, 10 in one of them — so it is searched for rather than
|
|
445
|
+
assumed, and the resolution requirement is what rejects the wrong guess.
|
|
446
|
+
"""
|
|
447
|
+
best: tuple[list[int], tuple[int, ...]] | None = None
|
|
448
|
+
limit = min(_HEADER_SEARCH, max(0, entry.size - 4))
|
|
449
|
+
for start in range(limit):
|
|
450
|
+
at = entry.offset + start
|
|
451
|
+
# The first reference's marker byte rejects almost every offset, and
|
|
452
|
+
# costs one comparison against the four-byte unpack that follows.
|
|
453
|
+
if at + 5 > entry.end or body[at + 4] != _REFERENCE:
|
|
454
|
+
continue
|
|
455
|
+
count = struct.unpack_from("<I", body, at)[0]
|
|
456
|
+
if not 1 <= count <= _MAX_INPUTS:
|
|
457
|
+
continue
|
|
458
|
+
ids = _references(body, at + 4, count, entry.end)
|
|
459
|
+
if ids is None:
|
|
460
|
+
continue
|
|
461
|
+
owners = _resolve(ids, items, position, features)
|
|
462
|
+
if owners and (best is None or len(owners) > len(best[0])):
|
|
463
|
+
best = (owners, ids)
|
|
464
|
+
return best
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
def _resolve(
|
|
468
|
+
ids: tuple[int, ...],
|
|
469
|
+
items: list[BulkObject],
|
|
470
|
+
position: dict[int, int],
|
|
471
|
+
features: dict[int, tuple[str, tuple[int, ...]]],
|
|
472
|
+
) -> list[int] | None:
|
|
473
|
+
"""The feature behind each timeline item, or ``None`` if any does not resolve.
|
|
474
|
+
|
|
475
|
+
A feature is *always* the object before its item, never the referenced
|
|
476
|
+
object itself. Allowing the second reading as a fallback let a list of
|
|
477
|
+
body-appearance records — a guid, no inputs, no name — pass as a
|
|
478
|
+
seven-entry timeline in two ``.f3z`` members that have no feature registry
|
|
479
|
+
at all. All-or-nothing on purpose: a list that only mostly resolves is not
|
|
480
|
+
the timeline.
|
|
481
|
+
"""
|
|
482
|
+
owners: list[int] = []
|
|
483
|
+
seen: set[int] = set()
|
|
484
|
+
for oid in ids:
|
|
485
|
+
index = position.get(oid)
|
|
486
|
+
if not index:
|
|
487
|
+
return None
|
|
488
|
+
owner = items[index - 1].oid
|
|
489
|
+
if owner not in features or owner in seen:
|
|
490
|
+
return None
|
|
491
|
+
seen.add(owner)
|
|
492
|
+
owners.append(owner)
|
|
493
|
+
return owners
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Vendored from ezf3d 97fe90ab8c39c3978fa6354f4a21c5ebdbc38c6e (MIT). Generated: do not edit."""
|