ezsxf 0.1.0__tar.gz
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.
- ezsxf-0.1.0/Cargo.lock +190 -0
- ezsxf-0.1.0/Cargo.toml +46 -0
- ezsxf-0.1.0/LICENSE +21 -0
- ezsxf-0.1.0/PKG-INFO +151 -0
- ezsxf-0.1.0/README.md +119 -0
- ezsxf-0.1.0/pyproject.toml +47 -0
- ezsxf-0.1.0/src/document.rs +1150 -0
- ezsxf-0.1.0/src/ezsxf/__init__.py +178 -0
- ezsxf-0.1.0/src/ezsxf/__main__.py +5 -0
- ezsxf-0.1.0/src/ezsxf/_core.pyi +6 -0
- ezsxf-0.1.0/src/ezsxf/_drawing.py +162 -0
- ezsxf-0.1.0/src/ezsxf/_drawing_annotations.py +183 -0
- ezsxf-0.1.0/src/ezsxf/_drawing_builder.py +345 -0
- ezsxf-0.1.0/src/ezsxf/_drawing_geometry.py +406 -0
- ezsxf-0.1.0/src/ezsxf/_drawing_hatches.py +251 -0
- ezsxf-0.1.0/src/ezsxf/_drawing_style.py +257 -0
- ezsxf-0.1.0/src/ezsxf/_dxf.py +431 -0
- ezsxf-0.1.0/src/ezsxf/_p21_drawing.py +1235 -0
- ezsxf-0.1.0/src/ezsxf/_plot.py +236 -0
- ezsxf-0.1.0/src/ezsxf/py.typed +1 -0
- ezsxf-0.1.0/src/features.rs +1533 -0
- ezsxf-0.1.0/src/lib.rs +22 -0
- ezsxf-0.1.0/src/model.rs +882 -0
- ezsxf-0.1.0/src/parser.rs +1035 -0
- ezsxf-0.1.0/src/python.rs +834 -0
- ezsxf-0.1.0/src/tests.rs +1415 -0
- ezsxf-0.1.0/tests/test_conversion.py +255 -0
- ezsxf-0.1.0/tests/test_python_api.py +149 -0
ezsxf-0.1.0/Cargo.lock
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
version = 4
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "autocfg"
|
|
7
|
+
version = "1.5.0"
|
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
+
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
|
10
|
+
|
|
11
|
+
[[package]]
|
|
12
|
+
name = "cfg-if"
|
|
13
|
+
version = "1.0.4"
|
|
14
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
15
|
+
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
|
16
|
+
|
|
17
|
+
[[package]]
|
|
18
|
+
name = "encoding_rs"
|
|
19
|
+
version = "0.8.35"
|
|
20
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
21
|
+
checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3"
|
|
22
|
+
dependencies = [
|
|
23
|
+
"cfg-if",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[[package]]
|
|
27
|
+
name = "ezsxf"
|
|
28
|
+
version = "0.1.0"
|
|
29
|
+
dependencies = [
|
|
30
|
+
"encoding_rs",
|
|
31
|
+
"pyo3",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[[package]]
|
|
35
|
+
name = "heck"
|
|
36
|
+
version = "0.5.0"
|
|
37
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
38
|
+
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
|
39
|
+
|
|
40
|
+
[[package]]
|
|
41
|
+
name = "indoc"
|
|
42
|
+
version = "2.0.7"
|
|
43
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
44
|
+
checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706"
|
|
45
|
+
dependencies = [
|
|
46
|
+
"rustversion",
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
[[package]]
|
|
50
|
+
name = "libc"
|
|
51
|
+
version = "0.2.182"
|
|
52
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
53
|
+
checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112"
|
|
54
|
+
|
|
55
|
+
[[package]]
|
|
56
|
+
name = "memoffset"
|
|
57
|
+
version = "0.9.1"
|
|
58
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
59
|
+
checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
|
|
60
|
+
dependencies = [
|
|
61
|
+
"autocfg",
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
[[package]]
|
|
65
|
+
name = "once_cell"
|
|
66
|
+
version = "1.21.3"
|
|
67
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
68
|
+
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
|
69
|
+
|
|
70
|
+
[[package]]
|
|
71
|
+
name = "portable-atomic"
|
|
72
|
+
version = "1.13.1"
|
|
73
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
74
|
+
checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49"
|
|
75
|
+
|
|
76
|
+
[[package]]
|
|
77
|
+
name = "proc-macro2"
|
|
78
|
+
version = "1.0.106"
|
|
79
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
80
|
+
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
|
|
81
|
+
dependencies = [
|
|
82
|
+
"unicode-ident",
|
|
83
|
+
]
|
|
84
|
+
|
|
85
|
+
[[package]]
|
|
86
|
+
name = "pyo3"
|
|
87
|
+
version = "0.22.6"
|
|
88
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
89
|
+
checksum = "f402062616ab18202ae8319da13fa4279883a2b8a9d9f83f20dbade813ce1884"
|
|
90
|
+
dependencies = [
|
|
91
|
+
"cfg-if",
|
|
92
|
+
"indoc",
|
|
93
|
+
"libc",
|
|
94
|
+
"memoffset",
|
|
95
|
+
"once_cell",
|
|
96
|
+
"portable-atomic",
|
|
97
|
+
"pyo3-build-config",
|
|
98
|
+
"pyo3-ffi",
|
|
99
|
+
"pyo3-macros",
|
|
100
|
+
"unindent",
|
|
101
|
+
]
|
|
102
|
+
|
|
103
|
+
[[package]]
|
|
104
|
+
name = "pyo3-build-config"
|
|
105
|
+
version = "0.22.6"
|
|
106
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
107
|
+
checksum = "b14b5775b5ff446dd1056212d778012cbe8a0fbffd368029fd9e25b514479c38"
|
|
108
|
+
dependencies = [
|
|
109
|
+
"once_cell",
|
|
110
|
+
"target-lexicon",
|
|
111
|
+
]
|
|
112
|
+
|
|
113
|
+
[[package]]
|
|
114
|
+
name = "pyo3-ffi"
|
|
115
|
+
version = "0.22.6"
|
|
116
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
117
|
+
checksum = "9ab5bcf04a2cdcbb50c7d6105de943f543f9ed92af55818fd17b660390fc8636"
|
|
118
|
+
dependencies = [
|
|
119
|
+
"libc",
|
|
120
|
+
"pyo3-build-config",
|
|
121
|
+
]
|
|
122
|
+
|
|
123
|
+
[[package]]
|
|
124
|
+
name = "pyo3-macros"
|
|
125
|
+
version = "0.22.6"
|
|
126
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
127
|
+
checksum = "0fd24d897903a9e6d80b968368a34e1525aeb719d568dba8b3d4bfa5dc67d453"
|
|
128
|
+
dependencies = [
|
|
129
|
+
"proc-macro2",
|
|
130
|
+
"pyo3-macros-backend",
|
|
131
|
+
"quote",
|
|
132
|
+
"syn",
|
|
133
|
+
]
|
|
134
|
+
|
|
135
|
+
[[package]]
|
|
136
|
+
name = "pyo3-macros-backend"
|
|
137
|
+
version = "0.22.6"
|
|
138
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
139
|
+
checksum = "36c011a03ba1e50152b4b394b479826cad97e7a21eb52df179cd91ac411cbfbe"
|
|
140
|
+
dependencies = [
|
|
141
|
+
"heck",
|
|
142
|
+
"proc-macro2",
|
|
143
|
+
"pyo3-build-config",
|
|
144
|
+
"quote",
|
|
145
|
+
"syn",
|
|
146
|
+
]
|
|
147
|
+
|
|
148
|
+
[[package]]
|
|
149
|
+
name = "quote"
|
|
150
|
+
version = "1.0.44"
|
|
151
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
152
|
+
checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4"
|
|
153
|
+
dependencies = [
|
|
154
|
+
"proc-macro2",
|
|
155
|
+
]
|
|
156
|
+
|
|
157
|
+
[[package]]
|
|
158
|
+
name = "rustversion"
|
|
159
|
+
version = "1.0.22"
|
|
160
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
161
|
+
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
|
162
|
+
|
|
163
|
+
[[package]]
|
|
164
|
+
name = "syn"
|
|
165
|
+
version = "2.0.115"
|
|
166
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
167
|
+
checksum = "6e614ed320ac28113fa64972c4262d5dbc89deacdfd00c34a3e4cea073243c12"
|
|
168
|
+
dependencies = [
|
|
169
|
+
"proc-macro2",
|
|
170
|
+
"quote",
|
|
171
|
+
"unicode-ident",
|
|
172
|
+
]
|
|
173
|
+
|
|
174
|
+
[[package]]
|
|
175
|
+
name = "target-lexicon"
|
|
176
|
+
version = "0.12.16"
|
|
177
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
178
|
+
checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
|
|
179
|
+
|
|
180
|
+
[[package]]
|
|
181
|
+
name = "unicode-ident"
|
|
182
|
+
version = "1.0.23"
|
|
183
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
184
|
+
checksum = "537dd038a89878be9b64dd4bd1b260315c1bb94f4d784956b81e27a088d9a09e"
|
|
185
|
+
|
|
186
|
+
[[package]]
|
|
187
|
+
name = "unindent"
|
|
188
|
+
version = "0.2.4"
|
|
189
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
190
|
+
checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
|
ezsxf-0.1.0/Cargo.toml
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "ezsxf"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
description = "Fast SXF parser and drawing converter for Python powered by Rust"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
repository = "https://github.com/nekanat/ezsxf"
|
|
9
|
+
homepage = "https://github.com/nekanat/ezsxf"
|
|
10
|
+
keywords = ["sxf", "p21", "sfc", "cad", "parser"]
|
|
11
|
+
categories = ["parser-implementations", "encoding"]
|
|
12
|
+
include = [
|
|
13
|
+
"/Cargo.toml",
|
|
14
|
+
"/Cargo.lock",
|
|
15
|
+
"/pyproject.toml",
|
|
16
|
+
"/README.md",
|
|
17
|
+
"/LICENSE",
|
|
18
|
+
"/CHANGELOG.md",
|
|
19
|
+
"/src/*.rs",
|
|
20
|
+
"/src/ezsxf/__init__.py",
|
|
21
|
+
"/src/ezsxf/__main__.py",
|
|
22
|
+
"/src/ezsxf/_drawing.py",
|
|
23
|
+
"/src/ezsxf/_drawing_annotations.py",
|
|
24
|
+
"/src/ezsxf/_drawing_builder.py",
|
|
25
|
+
"/src/ezsxf/_drawing_geometry.py",
|
|
26
|
+
"/src/ezsxf/_drawing_hatches.py",
|
|
27
|
+
"/src/ezsxf/_drawing_style.py",
|
|
28
|
+
"/src/ezsxf/_dxf.py",
|
|
29
|
+
"/src/ezsxf/_plot.py",
|
|
30
|
+
"/src/ezsxf/_p21_drawing.py",
|
|
31
|
+
"/src/ezsxf/_core.pyi",
|
|
32
|
+
"/src/ezsxf/py.typed",
|
|
33
|
+
"/tests/test_python_api.py",
|
|
34
|
+
"/tests/test_conversion.py",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[lib]
|
|
38
|
+
name = "_core"
|
|
39
|
+
# "cdylib" is necessary to produce a shared library for Python to import from.
|
|
40
|
+
crate-type = ["cdylib"]
|
|
41
|
+
|
|
42
|
+
[dependencies]
|
|
43
|
+
# "extension-module" tells pyo3 we want to build an extension module (skips linking against libpython.so)
|
|
44
|
+
# "abi3-py39" tells pyo3 (and maturin) to build using the stable ABI with minimum Python version 3.9
|
|
45
|
+
encoding_rs = "0.8"
|
|
46
|
+
pyo3 = { version = "0.22.4", features = ["extension-module", "abi3-py39"] }
|
ezsxf-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 nekanat
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
ezsxf-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ezsxf
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Classifier: Development Status :: 3 - Alpha
|
|
5
|
+
Classifier: Intended Audience :: Developers
|
|
6
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
7
|
+
Classifier: Programming Language :: Rust
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
16
|
+
Requires-Dist: maturin>=1.0,<2.0 ; extra == 'dev'
|
|
17
|
+
Requires-Dist: pytest>=8.0 ; extra == 'dev'
|
|
18
|
+
Requires-Dist: matplotlib>=3.8 ; extra == 'plot'
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Provides-Extra: plot
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Summary: Fast SXF parser and drawing converter for Python powered by Rust
|
|
23
|
+
Keywords: sxf,p21,sfc,cad,parser
|
|
24
|
+
Home-Page: https://github.com/nekanat/ezsxf
|
|
25
|
+
Author-email: neka-nat <nekanat.stock@gmail.com>
|
|
26
|
+
Requires-Python: >=3.9
|
|
27
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
28
|
+
Project-URL: Homepage, https://github.com/nekanat/ezsxf
|
|
29
|
+
Project-URL: Issues, https://github.com/nekanat/ezsxf/issues
|
|
30
|
+
Project-URL: Repository, https://github.com/nekanat/ezsxf
|
|
31
|
+
|
|
32
|
+
# ezsxf
|
|
33
|
+
|
|
34
|
+
A fast SXF parser and drawing converter for Python, implemented in Rust with
|
|
35
|
+
PyO3.
|
|
36
|
+
|
|
37
|
+
`ezsxf` supports both SXF formats:
|
|
38
|
+
- `P21` (ISO-10303-21 based)
|
|
39
|
+
- `SFC` (SXF feature blocks)
|
|
40
|
+
|
|
41
|
+
## Status
|
|
42
|
+
|
|
43
|
+
The SFC parser covers all 34 feature types in the SXF Ver.3.1 SFC specification,
|
|
44
|
+
including resolved drawing/compound-figure/composite-curve structure. The P21
|
|
45
|
+
reader currently exposes the generic Part 21 entity representation.
|
|
46
|
+
|
|
47
|
+
## Features
|
|
48
|
+
|
|
49
|
+
- Parse `P21` and `SFC` from file path, text, or bytes
|
|
50
|
+
- Decode SFC files as UTF-8 or Windows Shift-JIS/CP932 without lossy replacement
|
|
51
|
+
- Strict and lenient parsing modes
|
|
52
|
+
- Structured parse output (`header`, `entities`, `typed_features`, `model`, `warnings`)
|
|
53
|
+
- Resolve layer/style code tables, compound-figure placements, and hatch boundaries
|
|
54
|
+
- Decode `ATRF`/`ATRU`/`ATRS` attribute attachments separately from drawing groups
|
|
55
|
+
- Validate compound-figure placement counts, hierarchy, and drawing-group transforms
|
|
56
|
+
- Convert SFC drawings to AutoCAD 2007 ASCII DXF without another runtime dependency
|
|
57
|
+
- Draw SFC drawings with the optional `matplotlib` backend
|
|
58
|
+
- Python API + CLI (`ezsxf` / `python -m ezsxf`)
|
|
59
|
+
|
|
60
|
+
## Installation
|
|
61
|
+
|
|
62
|
+
### From source (recommended currently)
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
python -m venv .venv
|
|
66
|
+
source .venv/bin/activate
|
|
67
|
+
pip install maturin
|
|
68
|
+
maturin develop
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Install the plotting extra when using the matplotlib backend:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
pip install ".[plot]"
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Quick Start
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
import ezsxf
|
|
81
|
+
|
|
82
|
+
result = ezsxf.parse_sfc("./data/D0LS004ZSFC/D0LS004Z.SFC", strict=True)
|
|
83
|
+
print(result["format"]) # "sfc"
|
|
84
|
+
print(len(result["typed_features"]))
|
|
85
|
+
print(result["model"]["sheet"]["component_ids"])
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Convert the original input or an already parsed result to DXF:
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
ezsxf.to_dxf("./data/D0LS004ZSFC/D0LS004Z.SFC", "drawing.dxf")
|
|
92
|
+
|
|
93
|
+
parsed = ezsxf.parse_sfc("./data/D0LS004ZSFC/D0LS004Z.SFC")
|
|
94
|
+
dxf_text = ezsxf.to_dxf(parsed)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Draw with matplotlib and save through the returned `Axes`:
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
ax = ezsxf.plot("./data/D0LS004ZSFC/D0LS004Z.SFC")
|
|
101
|
+
ax.figure.savefig("drawing.png", dpi=200, bbox_inches="tight")
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Both backends share the same hierarchy, placement, layer, color, line type,
|
|
105
|
+
line width, text, dimension, and hatch conversion. Curves are converted to
|
|
106
|
+
polylines; use `curve_segments` to control the approximation resolution.
|
|
107
|
+
|
|
108
|
+
Drawing conversion currently targets SFC input. Externally defined symbols are
|
|
109
|
+
shown as insertion markers, while externally defined and tiled hatch patterns
|
|
110
|
+
retain only boundaries marked visible by the SXF data.
|
|
111
|
+
|
|
112
|
+
## CLI
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
# smoke test
|
|
116
|
+
python -m ezsxf
|
|
117
|
+
|
|
118
|
+
# parse to JSON
|
|
119
|
+
python -m ezsxf parse sfc ./data/D0LS004ZSFC/D0LS004Z.SFC --pretty
|
|
120
|
+
python -m ezsxf parse p21 ./data/D0LS004ZP21/D0LS004Z.P21 --lenient
|
|
121
|
+
|
|
122
|
+
# convert SFC to DXF
|
|
123
|
+
python -m ezsxf to-dxf ./data/D0LS004ZSFC/D0LS004Z.SFC drawing.dxf
|
|
124
|
+
|
|
125
|
+
# save or interactively display a matplotlib drawing
|
|
126
|
+
python -m ezsxf plot ./data/D0LS004ZSFC/D0LS004Z.SFC drawing.png --dpi 200
|
|
127
|
+
python -m ezsxf plot ./data/D0LS004ZSFC/D0LS004Z.SFC
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Development
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
cargo fmt --check
|
|
134
|
+
cargo clippy --all-targets --all-features -- -D warnings
|
|
135
|
+
cargo test
|
|
136
|
+
|
|
137
|
+
# Python-level tests
|
|
138
|
+
python -m unittest discover -s tests -p 'test_*.py' -v
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Repository Layout
|
|
142
|
+
|
|
143
|
+
- `src/*.rs`: Rust parser, resolved model, and PyO3 bindings
|
|
144
|
+
- `src/ezsxf/`: Python API, CLI, DXF writer, matplotlib backend, and stubs
|
|
145
|
+
- `data/`: SXF sample datasets used for validation
|
|
146
|
+
- `resources/`: SXF specification PDFs (reference only)
|
|
147
|
+
|
|
148
|
+
## License
|
|
149
|
+
|
|
150
|
+
MIT License. See [LICENSE](./LICENSE).
|
|
151
|
+
|
ezsxf-0.1.0/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# ezsxf
|
|
2
|
+
|
|
3
|
+
A fast SXF parser and drawing converter for Python, implemented in Rust with
|
|
4
|
+
PyO3.
|
|
5
|
+
|
|
6
|
+
`ezsxf` supports both SXF formats:
|
|
7
|
+
- `P21` (ISO-10303-21 based)
|
|
8
|
+
- `SFC` (SXF feature blocks)
|
|
9
|
+
|
|
10
|
+
## Status
|
|
11
|
+
|
|
12
|
+
The SFC parser covers all 34 feature types in the SXF Ver.3.1 SFC specification,
|
|
13
|
+
including resolved drawing/compound-figure/composite-curve structure. The P21
|
|
14
|
+
reader currently exposes the generic Part 21 entity representation.
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
- Parse `P21` and `SFC` from file path, text, or bytes
|
|
19
|
+
- Decode SFC files as UTF-8 or Windows Shift-JIS/CP932 without lossy replacement
|
|
20
|
+
- Strict and lenient parsing modes
|
|
21
|
+
- Structured parse output (`header`, `entities`, `typed_features`, `model`, `warnings`)
|
|
22
|
+
- Resolve layer/style code tables, compound-figure placements, and hatch boundaries
|
|
23
|
+
- Decode `ATRF`/`ATRU`/`ATRS` attribute attachments separately from drawing groups
|
|
24
|
+
- Validate compound-figure placement counts, hierarchy, and drawing-group transforms
|
|
25
|
+
- Convert SFC drawings to AutoCAD 2007 ASCII DXF without another runtime dependency
|
|
26
|
+
- Draw SFC drawings with the optional `matplotlib` backend
|
|
27
|
+
- Python API + CLI (`ezsxf` / `python -m ezsxf`)
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
### From source (recommended currently)
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
python -m venv .venv
|
|
35
|
+
source .venv/bin/activate
|
|
36
|
+
pip install maturin
|
|
37
|
+
maturin develop
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Install the plotting extra when using the matplotlib backend:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install ".[plot]"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Quick Start
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import ezsxf
|
|
50
|
+
|
|
51
|
+
result = ezsxf.parse_sfc("./data/D0LS004ZSFC/D0LS004Z.SFC", strict=True)
|
|
52
|
+
print(result["format"]) # "sfc"
|
|
53
|
+
print(len(result["typed_features"]))
|
|
54
|
+
print(result["model"]["sheet"]["component_ids"])
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Convert the original input or an already parsed result to DXF:
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
ezsxf.to_dxf("./data/D0LS004ZSFC/D0LS004Z.SFC", "drawing.dxf")
|
|
61
|
+
|
|
62
|
+
parsed = ezsxf.parse_sfc("./data/D0LS004ZSFC/D0LS004Z.SFC")
|
|
63
|
+
dxf_text = ezsxf.to_dxf(parsed)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Draw with matplotlib and save through the returned `Axes`:
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
ax = ezsxf.plot("./data/D0LS004ZSFC/D0LS004Z.SFC")
|
|
70
|
+
ax.figure.savefig("drawing.png", dpi=200, bbox_inches="tight")
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Both backends share the same hierarchy, placement, layer, color, line type,
|
|
74
|
+
line width, text, dimension, and hatch conversion. Curves are converted to
|
|
75
|
+
polylines; use `curve_segments` to control the approximation resolution.
|
|
76
|
+
|
|
77
|
+
Drawing conversion currently targets SFC input. Externally defined symbols are
|
|
78
|
+
shown as insertion markers, while externally defined and tiled hatch patterns
|
|
79
|
+
retain only boundaries marked visible by the SXF data.
|
|
80
|
+
|
|
81
|
+
## CLI
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
# smoke test
|
|
85
|
+
python -m ezsxf
|
|
86
|
+
|
|
87
|
+
# parse to JSON
|
|
88
|
+
python -m ezsxf parse sfc ./data/D0LS004ZSFC/D0LS004Z.SFC --pretty
|
|
89
|
+
python -m ezsxf parse p21 ./data/D0LS004ZP21/D0LS004Z.P21 --lenient
|
|
90
|
+
|
|
91
|
+
# convert SFC to DXF
|
|
92
|
+
python -m ezsxf to-dxf ./data/D0LS004ZSFC/D0LS004Z.SFC drawing.dxf
|
|
93
|
+
|
|
94
|
+
# save or interactively display a matplotlib drawing
|
|
95
|
+
python -m ezsxf plot ./data/D0LS004ZSFC/D0LS004Z.SFC drawing.png --dpi 200
|
|
96
|
+
python -m ezsxf plot ./data/D0LS004ZSFC/D0LS004Z.SFC
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Development
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
cargo fmt --check
|
|
103
|
+
cargo clippy --all-targets --all-features -- -D warnings
|
|
104
|
+
cargo test
|
|
105
|
+
|
|
106
|
+
# Python-level tests
|
|
107
|
+
python -m unittest discover -s tests -p 'test_*.py' -v
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Repository Layout
|
|
111
|
+
|
|
112
|
+
- `src/*.rs`: Rust parser, resolved model, and PyO3 bindings
|
|
113
|
+
- `src/ezsxf/`: Python API, CLI, DXF writer, matplotlib backend, and stubs
|
|
114
|
+
- `data/`: SXF sample datasets used for validation
|
|
115
|
+
- `resources/`: SXF specification PDFs (reference only)
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
MIT License. See [LICENSE](./LICENSE).
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "ezsxf"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Fast SXF parser and drawing converter for Python powered by Rust"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = { file = "LICENSE" }
|
|
7
|
+
authors = [
|
|
8
|
+
{ name = "neka-nat", email = "nekanat.stock@gmail.com" }
|
|
9
|
+
]
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
dependencies = []
|
|
12
|
+
keywords = ["sxf", "p21", "sfc", "cad", "parser"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 3 - Alpha",
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Programming Language :: Rust",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
20
|
+
"Programming Language :: Python :: 3.9",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Topic :: Software Development :: Libraries",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[project.optional-dependencies]
|
|
29
|
+
dev = ["maturin>=1.0,<2.0", "pytest>=8.0"]
|
|
30
|
+
plot = ["matplotlib>=3.8"]
|
|
31
|
+
|
|
32
|
+
[project.urls]
|
|
33
|
+
Homepage = "https://github.com/nekanat/ezsxf"
|
|
34
|
+
Repository = "https://github.com/nekanat/ezsxf"
|
|
35
|
+
Issues = "https://github.com/nekanat/ezsxf/issues"
|
|
36
|
+
|
|
37
|
+
[project.scripts]
|
|
38
|
+
ezsxf = "ezsxf:main"
|
|
39
|
+
|
|
40
|
+
[tool.maturin]
|
|
41
|
+
module-name = "ezsxf._core"
|
|
42
|
+
python-packages = ["ezsxf"]
|
|
43
|
+
python-source = "src"
|
|
44
|
+
|
|
45
|
+
[build-system]
|
|
46
|
+
requires = ["maturin>=1.0,<2.0"]
|
|
47
|
+
build-backend = "maturin"
|