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.
Files changed (74) hide show
  1. f3d2solidcraft/__init__.py +3 -0
  2. f3d2solidcraft/__main__.py +3 -0
  3. f3d2solidcraft/_vendor/__init__.py +0 -0
  4. f3d2solidcraft/_vendor/ezf3d/LICENSE +21 -0
  5. f3d2solidcraft/_vendor/ezf3d/__init__.py +1 -0
  6. f3d2solidcraft/_vendor/ezf3d/container/__init__.py +1 -0
  7. f3d2solidcraft/_vendor/ezf3d/container/archive.py +204 -0
  8. f3d2solidcraft/_vendor/ezf3d/model/__init__.py +1 -0
  9. f3d2solidcraft/_vendor/ezf3d/model/parameters.py +365 -0
  10. f3d2solidcraft/_vendor/ezf3d/model/sketch.py +645 -0
  11. f3d2solidcraft/_vendor/ezf3d/model/timeline.py +493 -0
  12. f3d2solidcraft/_vendor/ezf3d/streams/__init__.py +1 -0
  13. f3d2solidcraft/_vendor/ezf3d/streams/manifest.py +262 -0
  14. f3d2solidcraft/_vendor/ezf3d/streams/primitives.py +191 -0
  15. f3d2solidcraft/_vendor/ezf3d/streams/segment.py +521 -0
  16. f3d2solidcraft/cli.py +574 -0
  17. f3d2solidcraft/engine.py +458 -0
  18. f3d2solidcraft/fallback.py +250 -0
  19. f3d2solidcraft/geometry.py +397 -0
  20. f3d2solidcraft/mappers/__init__.py +141 -0
  21. f3d2solidcraft/mappers/bodies.py +99 -0
  22. f3d2solidcraft/mappers/combine.py +73 -0
  23. f3d2solidcraft/mappers/components.py +542 -0
  24. f3d2solidcraft/mappers/edges.py +449 -0
  25. f3d2solidcraft/mappers/extrude.py +1501 -0
  26. f3d2solidcraft/mappers/faces.py +50 -0
  27. f3d2solidcraft/mappers/loft.py +149 -0
  28. f3d2solidcraft/mappers/outputs.py +73 -0
  29. f3d2solidcraft/mappers/params.py +134 -0
  30. f3d2solidcraft/mappers/pattern.py +68 -0
  31. f3d2solidcraft/mappers/planes.py +222 -0
  32. f3d2solidcraft/mappers/primitives.py +144 -0
  33. f3d2solidcraft/mappers/records.py +51 -0
  34. f3d2solidcraft/mappers/revolve.py +134 -0
  35. f3d2solidcraft/mappers/sheet.py +95 -0
  36. f3d2solidcraft/mappers/shell.py +180 -0
  37. f3d2solidcraft/mappers/sketch.py +455 -0
  38. f3d2solidcraft/mcp.py +218 -0
  39. f3d2solidcraft/model.py +503 -0
  40. f3d2solidcraft/oracle.py +905 -0
  41. f3d2solidcraft/pairing.py +105 -0
  42. f3d2solidcraft/reader/__init__.py +77 -0
  43. f3d2solidcraft/reader/cadir.py +832 -0
  44. f3d2solidcraft/reader/fusion.py +218 -0
  45. f3d2solidcraft/reader/locale.py +115 -0
  46. f3d2solidcraft/replay.py +322 -0
  47. f3d2solidcraft/report.py +107 -0
  48. f3d2solidcraft/tools.py +219 -0
  49. f3d2solidcraft/verify.py +186 -0
  50. f3d2solidcraft/visibility.py +95 -0
  51. f3d2solidcraft-0.3.0.dist-info/METADATA +189 -0
  52. f3d2solidcraft-0.3.0.dist-info/RECORD +74 -0
  53. f3d2solidcraft-0.3.0.dist-info/WHEEL +4 -0
  54. f3d2solidcraft-0.3.0.dist-info/entry_points.txt +5 -0
  55. f3d2solidcraft-0.3.0.dist-info/licenses/LICENSE +21 -0
  56. f3d2solidcraft-0.3.0.dist-info/licenses/src/f3d2solidcraft/_vendor/ezf3d/LICENSE +21 -0
  57. f3d2solidcraft_app/__init__.py +5 -0
  58. f3d2solidcraft_app/__main__.py +40 -0
  59. f3d2solidcraft_app/engines.py +158 -0
  60. f3d2solidcraft_app/events.py +35 -0
  61. f3d2solidcraft_app/opener.py +22 -0
  62. f3d2solidcraft_app/outcome.py +54 -0
  63. f3d2solidcraft_app/resources/icon-128.png +0 -0
  64. f3d2solidcraft_app/resources/icon-16.png +0 -0
  65. f3d2solidcraft_app/resources/icon-256.png +0 -0
  66. f3d2solidcraft_app/resources/icon-32.png +0 -0
  67. f3d2solidcraft_app/resources/icon-512.png +0 -0
  68. f3d2solidcraft_app/resources/icon-64.png +0 -0
  69. f3d2solidcraft_app/resources/icon.icns +0 -0
  70. f3d2solidcraft_app/resources/icon.ico +0 -0
  71. f3d2solidcraft_app/resources/icon.svg +26 -0
  72. f3d2solidcraft_app/runner.py +91 -0
  73. f3d2solidcraft_app/texts.py +98 -0
  74. f3d2solidcraft_app/window.py +677 -0
@@ -0,0 +1,262 @@
1
+ """Readers for the two ``Manifest.dat`` flavours.
2
+
3
+ A Fusion document carries a manifest at two levels:
4
+
5
+ **Document manifest** (``/Manifest.dat``) — document type, identity GUIDs, the
6
+ ``{module: schema_version}`` table that tells a reader which schema revision
7
+ every subsystem was written with, and the list of asset folders.
8
+
9
+ **Asset manifest** (``<Asset>[State]/Manifest.dat``) — the asset's identity and
10
+ its *segment table*: ``(slot, folder_prefix, segment_type)`` triples. The
11
+ folder on disk is ``prefix`` plus an instance number, which is why
12
+ ``FusionDesignSegmentType`` in one document and ``Design`` in another both
13
+ describe the design segment. Never key off the folder name; key off the type.
14
+
15
+ Fields whose meaning is not yet established are preserved verbatim in
16
+ ``reserved`` rather than dropped, so later phases can mine them.
17
+ """
18
+
19
+ from __future__ import annotations
20
+
21
+ from dataclasses import dataclass, field
22
+
23
+ from f3d2solidcraft._vendor.ezf3d.streams.primitives import Reader, StreamError, scan_strings
24
+
25
+ #: Sentinel that opens the version block of a recent document manifest. Older
26
+ #: documents (and ``.f3z`` members written by the cloud translator) open with a
27
+ #: build stamp instead, and carry two fewer words, so the block is located by
28
+ #: validating what follows rather than by trusting a fixed layout.
29
+ MANIFEST_COOKIE = 1234
30
+
31
+ #: Candidate sizes, in words, of the version block between the identity GUIDs
32
+ #: and the schema table.
33
+ _VERSION_BLOCK_WORDS = (4, 2, 6)
34
+
35
+ #: Sanity bounds used to reject a misparsed count.
36
+ _MAX_SEGMENTS = 64
37
+ _MAX_SCHEMA_ENTRIES = 64
38
+
39
+
40
+ @dataclass(slots=True)
41
+ class ManifestItem:
42
+ """An entry of the document manifest's optional item list."""
43
+
44
+ fields: tuple[str, str, str, str]
45
+ numbers: tuple[int, int, int, int]
46
+ properties: dict[str, str] = field(default_factory=dict)
47
+
48
+
49
+ @dataclass(slots=True)
50
+ class DocumentManifest:
51
+ """Parsed ``/Manifest.dat``."""
52
+
53
+ format_version: str
54
+ doc_type_key: str
55
+ extension: str
56
+ doc_type: str
57
+ doc_description: str
58
+ document_guid: str
59
+ lineage_guid: str
60
+ schema: dict[str, int]
61
+ related_guids: list[str]
62
+ content_guid: str
63
+ asset_names: list[str]
64
+ #: Provenance marker. ``NA_OFFLINESAVE`` / ``NA_EXPORT`` for a document
65
+ #: saved from the desktop app; the design's name for one produced by the
66
+ #: cloud translator.
67
+ origin: str
68
+ items: list[ManifestItem] = field(default_factory=list)
69
+ reserved: tuple[int, ...] = ()
70
+
71
+
72
+ @dataclass(frozen=True, slots=True)
73
+ class SegmentDeclaration:
74
+ """One row of an asset manifest's segment table."""
75
+
76
+ slot: int
77
+ prefix: str
78
+ segment_type: str
79
+
80
+ def matches(self, folder: str) -> bool:
81
+ """True if *folder* is an instance of this declaration (``prefix`` + N)."""
82
+ return folder == self.prefix or (
83
+ folder.startswith(self.prefix) and folder[len(self.prefix) :].isdigit()
84
+ )
85
+
86
+
87
+ @dataclass(slots=True)
88
+ class AssetManifest:
89
+ """Parsed ``<Asset>[State]/Manifest.dat``."""
90
+
91
+ asset_name: str
92
+ asset_guid: str
93
+ revision_guid: str
94
+ asset_type_key: str
95
+ schema: dict[str, int]
96
+ asset_type: str
97
+ properties: dict[str, str] = field(default_factory=dict)
98
+ #: GUIDs of assets this one derives from (``Animation`` -> its design).
99
+ parent_guids: list[str] = field(default_factory=list)
100
+ segments: list[SegmentDeclaration] = field(default_factory=list)
101
+ change_counter: int = 0
102
+ #: Bytes left unconsumed — non-empty means an undecoded schema revision.
103
+ trailing: bytes = b""
104
+
105
+
106
+ def _read_version_block(r: Reader) -> tuple[tuple[int, ...], dict[str, int]]:
107
+ """Read the version words plus the schema table that follows them.
108
+
109
+ The block's width varies by document revision, so each candidate width is
110
+ tried and accepted only if a plausible schema table decodes right after it.
111
+ """
112
+ anchor = r.pos
113
+ for words in _VERSION_BLOCK_WORDS:
114
+ r.seek(anchor)
115
+ try:
116
+ reserved = tuple(r.u32() for _ in range(words))
117
+ table = r.str8_u32_table()
118
+ except StreamError:
119
+ continue
120
+ if _plausible_schema(table):
121
+ return reserved, table
122
+ raise StreamError(f"no readable schema table after the identity GUIDs at {anchor}")
123
+
124
+
125
+ def _plausible_schema(table: dict[str, int]) -> bool:
126
+ if not 0 < len(table) <= _MAX_SCHEMA_ENTRIES:
127
+ return False
128
+ return all(
129
+ name.isascii() and name.isidentifier() and 0 <= version < 1 << 24
130
+ for name, version in table.items()
131
+ )
132
+
133
+
134
+ def read_document_manifest(data: bytes) -> DocumentManifest:
135
+ """Parse the top-level ``Manifest.dat``."""
136
+ r = Reader(data)
137
+ format_version = r.str8()
138
+ doc_type_key = r.str8()
139
+ extension = r.wstr()
140
+ doc_type = r.wstr()
141
+ doc_description = r.wstr()
142
+ document_guid = r.wstr()
143
+ lineage_guid = r.wstr()
144
+
145
+ reserved, schema = _read_version_block(r)
146
+ related_guids = [r.wstr() for _ in range(r.u32())]
147
+
148
+ items: list[ManifestItem] = []
149
+ if r.u8():
150
+ for _ in range(r.u32()):
151
+ texts = (r.wstr(), r.wstr(), r.wstr(), r.wstr())
152
+ numbers = (r.u32(), r.u32(), r.u32(), r.u32())
153
+ props = {r.wstr(): r.wstr() for _ in range(r.u32())}
154
+ items.append(ManifestItem(texts, numbers, props))
155
+
156
+ content_guid = r.wstr()
157
+ asset_names = [r.wstr() for _ in range(r.u32())]
158
+ r.u32() # always 0 in observed files
159
+ r.u8() # always 1 in observed files
160
+ origin = r.wstr()
161
+
162
+ return DocumentManifest(
163
+ format_version=format_version,
164
+ doc_type_key=doc_type_key,
165
+ extension=extension,
166
+ doc_type=doc_type,
167
+ doc_description=doc_description,
168
+ document_guid=document_guid,
169
+ lineage_guid=lineage_guid,
170
+ schema=schema,
171
+ related_guids=related_guids,
172
+ content_guid=content_guid,
173
+ asset_names=asset_names,
174
+ origin=origin,
175
+ items=items,
176
+ reserved=reserved,
177
+ )
178
+
179
+
180
+ def read_asset_manifest(data: bytes) -> AssetManifest:
181
+ """Parse an asset folder's ``Manifest.dat``."""
182
+ r = Reader(data)
183
+ manifest = AssetManifest(
184
+ asset_name=r.wstr(),
185
+ asset_guid=r.wstr(),
186
+ revision_guid=r.wstr(),
187
+ asset_type_key=r.str8(),
188
+ schema={},
189
+ asset_type="",
190
+ )
191
+ r.u32() # schema-table tag, 20 in every observed file
192
+ manifest.schema = r.str8_u32_table()
193
+ manifest.asset_type = r.str8()
194
+ r.u32()
195
+ r.u8()
196
+ manifest.properties = {r.str8(): r.wstr() for _ in range(r.u32())}
197
+
198
+ anchor = r.pos
199
+ try:
200
+ _read_asset_tail(r, manifest)
201
+ if r.remaining:
202
+ raise StreamError(f"{r.remaining} bytes left after the segment table")
203
+ except StreamError:
204
+ # Unrecognised revision of the reference block. The segment table is
205
+ # self-describing enough to find on its own, so recover rather than
206
+ # give up: everything before it is metadata we can afford to skip.
207
+ manifest.parent_guids.clear()
208
+ manifest.segments.clear()
209
+ r.seek(anchor)
210
+ if not _recover_segment_table(data, r, manifest):
211
+ manifest.trailing = data[anchor:]
212
+ return manifest
213
+ manifest.trailing = data[r.pos :]
214
+ return manifest
215
+
216
+
217
+ def _read_asset_tail(r: Reader, manifest: AssetManifest) -> None:
218
+ """Reference block, change counter and segment table, strict reading."""
219
+ for _ in range(r.u32()):
220
+ r.u32() # reference kind; 0 in every observed file
221
+ manifest.parent_guids.append(r.guid())
222
+ manifest.parent_guids.append(r.guid())
223
+ r.u32()
224
+ r.u32()
225
+ manifest.parent_guids.append(r.guid())
226
+ manifest.change_counter = r.u32()
227
+ count = r.u32()
228
+ if count > _MAX_SEGMENTS:
229
+ raise StreamError(f"implausible segment count {count}")
230
+ for _ in range(count):
231
+ manifest.segments.append(SegmentDeclaration(r.u32(), r.str8(), r.str8()))
232
+
233
+
234
+ def _recover_segment_table(data: bytes, r: Reader, manifest: AssetManifest) -> bool:
235
+ """Locate the segment table by shape when the preamble is unrecognised.
236
+
237
+ The table is a run of ``(uint32, str8, str8)`` triples that ends exactly at
238
+ end-of-buffer and is preceded by its own ``uint32`` count, so a candidate
239
+ offset can be checked rather than guessed.
240
+ """
241
+ for found in scan_strings(data, start=r.pos, min_len=3):
242
+ start = found.offset - 4
243
+ if start < r.pos:
244
+ continue
245
+ probe = Reader(data, start)
246
+ try:
247
+ rows = []
248
+ while not probe.eof:
249
+ rows.append(SegmentDeclaration(probe.u32(), probe.str8(), probe.str8()))
250
+ except StreamError:
251
+ continue
252
+ if not rows or probe.pos != len(data):
253
+ continue
254
+ if not all(row.prefix and row.segment_type for row in rows):
255
+ continue
256
+ count_at = start - 4
257
+ if count_at >= r.pos and Reader(data, count_at).u32() != len(rows):
258
+ continue
259
+ manifest.segments.extend(rows)
260
+ r.seek(len(data))
261
+ return True
262
+ return False
@@ -0,0 +1,191 @@
1
+ """Primitive readers for Fusion's "Neutron" binary serialization.
2
+
3
+ Every ``.dat`` stream in a Fusion document uses the same handful of encodings:
4
+
5
+ =============== ==========================================================
6
+ ``str8`` ``uint32`` byte count, then that many bytes of ASCII/UTF-8
7
+ ``wstr`` ``uint32`` *character* count, then 2x that many bytes UTF-16LE
8
+ scalars little-endian ``u8/u16/u32/u64/i32/i64/f32/f64``
9
+ guid a ``wstr`` of exactly 36 characters
10
+ =============== ==========================================================
11
+
12
+ There are no type tags on the wire: a reader has to know the schema of the
13
+ record it is standing on. That is why :class:`Reader` is deliberately thin and
14
+ why :func:`scan_strings` exists — when a schema is not yet known, scanning for
15
+ self-consistent strings is how it gets discovered.
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+ import struct
21
+ from collections.abc import Iterator
22
+ from dataclasses import dataclass
23
+
24
+ _U8 = struct.Struct("<B")
25
+ _U16 = struct.Struct("<H")
26
+ _U32 = struct.Struct("<I")
27
+ _U64 = struct.Struct("<Q")
28
+ _I32 = struct.Struct("<i")
29
+ _I64 = struct.Struct("<q")
30
+ _F32 = struct.Struct("<f")
31
+ _F64 = struct.Struct("<d")
32
+
33
+ GUID_LEN = 36
34
+
35
+
36
+ class StreamError(ValueError):
37
+ """Raised when a stream does not match the expected shape."""
38
+
39
+
40
+ class Reader:
41
+ """A cursor over a ``bytes`` buffer with Neutron's primitive readers."""
42
+
43
+ __slots__ = ("data", "pos")
44
+
45
+ def __init__(self, data: bytes, pos: int = 0) -> None:
46
+ self.data = data
47
+ self.pos = pos
48
+
49
+ # -- cursor ------------------------------------------------------------
50
+
51
+ def __len__(self) -> int:
52
+ return len(self.data)
53
+
54
+ @property
55
+ def remaining(self) -> int:
56
+ return len(self.data) - self.pos
57
+
58
+ @property
59
+ def eof(self) -> bool:
60
+ return self.pos >= len(self.data)
61
+
62
+ def seek(self, pos: int) -> None:
63
+ self.pos = pos
64
+
65
+ def skip(self, n: int) -> None:
66
+ self.pos += n
67
+
68
+ def _take(self, size: int) -> int:
69
+ start = self.pos
70
+ end = start + size
71
+ if end > len(self.data):
72
+ raise StreamError(f"read of {size} bytes at {start} runs past end ({len(self.data)})")
73
+ self.pos = end
74
+ return start
75
+
76
+ # -- scalars -----------------------------------------------------------
77
+
78
+ def u8(self) -> int:
79
+ return _U8.unpack_from(self.data, self._take(1))[0]
80
+
81
+ def u16(self) -> int:
82
+ return _U16.unpack_from(self.data, self._take(2))[0]
83
+
84
+ def u32(self) -> int:
85
+ return _U32.unpack_from(self.data, self._take(4))[0]
86
+
87
+ def u64(self) -> int:
88
+ return _U64.unpack_from(self.data, self._take(8))[0]
89
+
90
+ def i32(self) -> int:
91
+ return _I32.unpack_from(self.data, self._take(4))[0]
92
+
93
+ def i64(self) -> int:
94
+ return _I64.unpack_from(self.data, self._take(8))[0]
95
+
96
+ def f32(self) -> float:
97
+ return _F32.unpack_from(self.data, self._take(4))[0]
98
+
99
+ def f64(self) -> float:
100
+ return _F64.unpack_from(self.data, self._take(8))[0]
101
+
102
+ def raw(self, n: int) -> bytes:
103
+ start = self._take(n)
104
+ return self.data[start : start + n]
105
+
106
+ # -- strings -----------------------------------------------------------
107
+
108
+ def str8(self) -> str:
109
+ n = self.u32()
110
+ return self.raw(n).decode("utf-8", "replace")
111
+
112
+ def wstr(self) -> str:
113
+ n = self.u32()
114
+ return self.raw(2 * n).decode("utf-16-le", "replace")
115
+
116
+ def guid(self) -> str:
117
+ value = self.wstr()
118
+ if len(value) != GUID_LEN:
119
+ raise StreamError(f"expected a 36-char GUID at {self.pos}, got {value!r}")
120
+ return value
121
+
122
+ # -- composites --------------------------------------------------------
123
+
124
+ def counted(self, read_one, count: int | None = None) -> list:
125
+ """Read a ``uint32`` count (unless given) followed by that many items."""
126
+ n = self.u32() if count is None else count
127
+ return [read_one() for _ in range(n)]
128
+
129
+ def str8_u32_table(self) -> dict[str, int]:
130
+ """Read ``count x (str8, uint32)`` — Fusion's schema-version tables."""
131
+ return dict(self.counted(lambda: (self.str8(), self.u32())))
132
+
133
+
134
+ # -- discovery helpers -----------------------------------------------------
135
+
136
+
137
+ @dataclass(frozen=True, slots=True)
138
+ class FoundString:
139
+ """A string located by :func:`scan_strings`."""
140
+
141
+ offset: int
142
+ kind: str # 'str8' | 'wstr'
143
+ value: str
144
+
145
+ @property
146
+ def end(self) -> int:
147
+ n = len(self.value)
148
+ return self.offset + 4 + (2 * n if self.kind == "wstr" else n)
149
+
150
+
151
+ def _plausible(value: str, min_len: int) -> bool:
152
+ if len(value) < min_len:
153
+ return False
154
+ return all(c == "\t" or 32 <= ord(c) < 127 for c in value)
155
+
156
+
157
+ def scan_strings(
158
+ data: bytes,
159
+ *,
160
+ start: int = 0,
161
+ end: int | None = None,
162
+ min_len: int = 3,
163
+ max_len: int = 512,
164
+ ) -> Iterator[FoundString]:
165
+ """Walk *data* yielding every self-consistent ``str8``/``wstr``.
166
+
167
+ Used by the forensic ``ezf3d raw`` command and by schema archaeology on
168
+ streams we have not fully decoded yet. Greedy and non-overlapping: once a
169
+ string is accepted, scanning resumes after it.
170
+ """
171
+ view = memoryview(data)
172
+ limit = len(data) if end is None else min(end, len(data))
173
+ pos = start
174
+ while pos + 4 <= limit:
175
+ n = _U32.unpack_from(view, pos)[0]
176
+ if min_len <= n <= max_len:
177
+ if pos + 4 + 2 * n <= limit:
178
+ raw = bytes(view[pos + 4 : pos + 4 + 2 * n])
179
+ if all(raw[i * 2 + 1] == 0 for i in range(n)):
180
+ text = raw.decode("utf-16-le", "replace")
181
+ if _plausible(text, min_len):
182
+ yield FoundString(pos, "wstr", text)
183
+ pos += 4 + 2 * n
184
+ continue
185
+ if pos + 4 + n <= limit:
186
+ text = bytes(view[pos + 4 : pos + 4 + n]).decode("latin-1")
187
+ if _plausible(text, min_len):
188
+ yield FoundString(pos, "str8", text)
189
+ pos += 4 + n
190
+ continue
191
+ pos += 1