ezmi2d 0.2.2__tar.gz → 0.2.4__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.
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/Cargo.lock +2 -2
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/Cargo.toml +1 -1
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/PKG-INFO +8 -4
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/README.md +7 -3
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/crates/ezmi2d-core/src/lib.rs +3 -2
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/crates/ezmi2d-core/src/model.rs +110 -2
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/crates/ezmi2d-core/src/semantic.rs +303 -56
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/crates/ezmi2d-core/tests/semantic_read.rs +39 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/crates/ezmi2d-python/src/lib.rs +78 -5
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/docs/api.md +43 -3
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/docs/mi-format-research.md +89 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/pyproject.toml +1 -1
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/scripts/audit_semantics.py +98 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/scripts/verify_release_artifacts.py +12 -7
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/src/ezmi2d/__init__.py +14 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/src/ezmi2d/document.py +85 -1
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/src/ezmi2d/entities.py +304 -8
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/tests/data/phase5.mi +112 -44
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/tests/python/test_semantic_audit.py +24 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/LICENSE +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/benchmarks/README.md +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/benchmarks/benchmark_pipeline.py +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/benchmarks/results/phase6-baseline.json +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/benchmarks/results/phase6-baseline.md +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/crates/ezmi2d-core/Cargo.toml +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/crates/ezmi2d-core/src/compression.rs +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/crates/ezmi2d-core/src/encoding.rs +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/crates/ezmi2d-core/src/error.rs +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/crates/ezmi2d-core/src/options.rs +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/crates/ezmi2d-core/src/raw.rs +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/crates/ezmi2d-core/src/scanner.rs +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/crates/ezmi2d-core/tests/hardening.rs +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/crates/ezmi2d-core/tests/raw_scan.rs +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/crates/ezmi2d-python/Cargo.toml +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/docs/releasing.md +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/examples/plot_mi.py +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/fuzz/Cargo.lock +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/fuzz/Cargo.toml +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/fuzz/fuzz_targets/raw_scan.rs +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/fuzz/fuzz_targets/semantic_read.rs +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/samples/README.md +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/samples/manifest.toml +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/scripts/check_release_version.py +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/scripts/fetch_external_samples.sh +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/scripts/smoke_installed_package.py +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/src/ezmi2d/__main__.py +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/src/ezmi2d/_core.pyi +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/src/ezmi2d/diagnostics.py +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/src/ezmi2d/plotting.py +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/src/ezmi2d/py.typed +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/src/ezmi2d/raw.py +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/tests/data/geometry.mi +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/tests/data/minimal.mi +0 -0
- {ezmi2d-0.2.2 → ezmi2d-0.2.4}/tests/data/text-utf8.mi +0 -0
|
@@ -34,7 +34,7 @@ dependencies = [
|
|
|
34
34
|
|
|
35
35
|
[[package]]
|
|
36
36
|
name = "ezmi2d-core"
|
|
37
|
-
version = "0.2.
|
|
37
|
+
version = "0.2.4"
|
|
38
38
|
dependencies = [
|
|
39
39
|
"encoding_rs",
|
|
40
40
|
"flate2",
|
|
@@ -43,7 +43,7 @@ dependencies = [
|
|
|
43
43
|
|
|
44
44
|
[[package]]
|
|
45
45
|
name = "ezmi2d-python"
|
|
46
|
-
version = "0.2.
|
|
46
|
+
version = "0.2.4"
|
|
47
47
|
dependencies = [
|
|
48
48
|
"ezmi2d-core",
|
|
49
49
|
"pyo3",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ezmi2d
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Classifier: Development Status :: 2 - Pre-Alpha
|
|
5
5
|
Classifier: Intended Audience :: Developers
|
|
6
6
|
Classifier: License :: OSI Approved :: MIT License
|
|
@@ -161,7 +161,10 @@ ezmi2d inspect drawing.mi --json --records
|
|
|
161
161
|
- typed `P`, `LIN`, `ARC`, `FIL`, `BSPL`, `CIR`, and `TEX` entities; point references are resolved
|
|
162
162
|
- De Boor evaluation for `BSPL`, including rational weights when a verified layout records them
|
|
163
163
|
- typed dimension (`DANG`, `DCHMF`, `DDIA`, `DRAD`, `DSGL`) references, measurement,
|
|
164
|
-
formatted text, placement, DDA/DTF style,
|
|
164
|
+
formatted text, placement, DDA/DTF style, the DTA text attribute with the text height
|
|
165
|
+
(`text_height`), the stored text box, linked `DTV` tolerances, and the drawn form the
|
|
166
|
+
file stores with the dimension (`graphics`: terminators, dimension and extension line
|
|
167
|
+
pieces, arcs, and where the main, tolerance, prefix and postfix texts start)
|
|
165
168
|
- drawable `LED` vertices, `SYML` components, and associative `HAT` patterns/boundaries through
|
|
166
169
|
typed `COC`, `PFA`, and `HAPP` records
|
|
167
170
|
- typed `Affine2D`, nested/shared `ASSE` occurrence traversal, composed child-to-parent transforms,
|
|
@@ -219,8 +222,9 @@ public Creo bundle: 87,506 compressed bytes expand to 393,805 logical bytes.
|
|
|
219
222
|
Its 853 lines, 187 arcs, 88 B-splines, 76 circles, 57 texts, 88 typed annotations,
|
|
220
223
|
11 hatch contours, 9 hatch associations, 25-part hierarchy, and sheet association produce
|
|
221
224
|
identical semantic models and diagnostics from compressed and expanded input. All 46 dimensions
|
|
222
|
-
resolve their source geometry and point references
|
|
223
|
-
components. One COC member is a retained unsupported `PLN`
|
|
225
|
+
resolve their source geometry and point references and carry a typed drawn form; all 16
|
|
226
|
+
symbols resolve three graphic components. One COC member is a retained unsupported `PLN`
|
|
227
|
+
record.
|
|
224
228
|
|
|
225
229
|
## Distribution
|
|
226
230
|
|
|
@@ -126,7 +126,10 @@ ezmi2d inspect drawing.mi --json --records
|
|
|
126
126
|
- typed `P`, `LIN`, `ARC`, `FIL`, `BSPL`, `CIR`, and `TEX` entities; point references are resolved
|
|
127
127
|
- De Boor evaluation for `BSPL`, including rational weights when a verified layout records them
|
|
128
128
|
- typed dimension (`DANG`, `DCHMF`, `DDIA`, `DRAD`, `DSGL`) references, measurement,
|
|
129
|
-
formatted text, placement, DDA/DTF style,
|
|
129
|
+
formatted text, placement, DDA/DTF style, the DTA text attribute with the text height
|
|
130
|
+
(`text_height`), the stored text box, linked `DTV` tolerances, and the drawn form the
|
|
131
|
+
file stores with the dimension (`graphics`: terminators, dimension and extension line
|
|
132
|
+
pieces, arcs, and where the main, tolerance, prefix and postfix texts start)
|
|
130
133
|
- drawable `LED` vertices, `SYML` components, and associative `HAT` patterns/boundaries through
|
|
131
134
|
typed `COC`, `PFA`, and `HAPP` records
|
|
132
135
|
- typed `Affine2D`, nested/shared `ASSE` occurrence traversal, composed child-to-parent transforms,
|
|
@@ -184,8 +187,9 @@ public Creo bundle: 87,506 compressed bytes expand to 393,805 logical bytes.
|
|
|
184
187
|
Its 853 lines, 187 arcs, 88 B-splines, 76 circles, 57 texts, 88 typed annotations,
|
|
185
188
|
11 hatch contours, 9 hatch associations, 25-part hierarchy, and sheet association produce
|
|
186
189
|
identical semantic models and diagnostics from compressed and expanded input. All 46 dimensions
|
|
187
|
-
resolve their source geometry and point references
|
|
188
|
-
components. One COC member is a retained unsupported `PLN`
|
|
190
|
+
resolve their source geometry and point references and carry a typed drawn form; all 16
|
|
191
|
+
symbols resolve three graphic components. One COC member is a retained unsupported `PLN`
|
|
192
|
+
record.
|
|
189
193
|
|
|
190
194
|
## Distribution
|
|
191
195
|
|
|
@@ -14,8 +14,9 @@ pub use encoding::{EncodingSource, TextDecodeError, TextEncoding};
|
|
|
14
14
|
pub use error::MiError;
|
|
15
15
|
pub use model::{
|
|
16
16
|
ArcEntity, AssemblyEntity, AssemblyInstance, BSplineEntity, BSplineSample, Bounds2,
|
|
17
|
-
CircleEntity, ContourEntity, DimensionEntity,
|
|
18
|
-
|
|
17
|
+
CircleEntity, ContourEntity, DimensionArc, DimensionArrow, DimensionEntity, DimensionGraphics,
|
|
18
|
+
DimensionSegment, DimensionTextAttributeProperty, DimensionTextPart, DimensionToleranceEntity,
|
|
19
|
+
DimensionTolerancePlacement, EncodingInfo, EntityHeader, EntityId, GlobalInfo, GraphicHeader,
|
|
19
20
|
HatchAssociationEntity, HatchEntity, HatchPatternLine, HatchPatternProperty, LeaderEntity,
|
|
20
21
|
LeaderPoint, LineEntity, Part, PartStatusProperty, Point2, PointEntity, PropertyEntity,
|
|
21
22
|
SemanticDocument, SemanticEntity, StructuredEntity, SymbolEntity, TextEntity, TextValue,
|
|
@@ -363,6 +363,18 @@ pub struct DimensionTextAttributeProperty {
|
|
|
363
363
|
pub symbol_font_name: TextValue,
|
|
364
364
|
/// Remaining serialized numeric values. Their individual meanings vary by MI version.
|
|
365
365
|
pub definition_values: Vec<f64>,
|
|
366
|
+
/// Size of the text, the third numeric value: the character height in drawing
|
|
367
|
+
/// units, or a factor of the main text of the dimension when `relative_size` is
|
|
368
|
+
/// true. `None` when the value is missing or not positive.
|
|
369
|
+
///
|
|
370
|
+
/// In MI 2.40 through 3.40 the text attribute a dimension points to for its main
|
|
371
|
+
/// text states the height of the stored text box of a dimension without a
|
|
372
|
+
/// tolerance, and the attribute of a tolerance states either that same height or a
|
|
373
|
+
/// factor such as 0.6 that the stored line spacing of the tolerance agrees with.
|
|
374
|
+
pub size: Option<f64>,
|
|
375
|
+
/// Whether `size` is a factor rather than a length: the second numeric value is 1
|
|
376
|
+
/// (true) or 0 (false). `None` when it is missing or another value.
|
|
377
|
+
pub relative_size: Option<bool>,
|
|
366
378
|
}
|
|
367
379
|
|
|
368
380
|
#[derive(Debug, Clone, PartialEq)]
|
|
@@ -391,11 +403,105 @@ pub struct DimensionEntity {
|
|
|
391
403
|
pub formatted_text: TextValue,
|
|
392
404
|
pub dimension_style_id: Option<EntityId>,
|
|
393
405
|
pub text_style_id: Option<EntityId>,
|
|
406
|
+
/// Pointer to the DTA text attribute (fonts and size) of the main text: the field
|
|
407
|
+
/// between the DTF pointer and the measurement.
|
|
408
|
+
pub text_attribute_id: Option<EntityId>,
|
|
409
|
+
/// Extent of the stored text box along the text: the first vector after the text
|
|
410
|
+
/// position. Its direction is the direction of the text and its length the width
|
|
411
|
+
/// of the box, tolerances included.
|
|
412
|
+
pub text_extent: Point2,
|
|
413
|
+
/// Extent of the stored text box across the text: the second vector after the
|
|
414
|
+
/// text position, at a right angle to `text_extent`. Its length is the height of
|
|
415
|
+
/// the box: the text size for a plain text, more with stacked tolerances or a
|
|
416
|
+
/// glyph that reaches below the baseline.
|
|
417
|
+
pub text_up_extent: Point2,
|
|
394
418
|
pub tolerance_ids: Vec<EntityId>,
|
|
419
|
+
/// The drawn form of the dimension stored after the formatted text: where each
|
|
420
|
+
/// text starts, the terminators, and the dimension, extension and arc pieces.
|
|
421
|
+
/// `None` when the fields after the formatted text do not follow the layout
|
|
422
|
+
/// read from MI 2.40 through 3.40.
|
|
423
|
+
pub graphics: Option<DimensionGraphics>,
|
|
395
424
|
/// All fields after the entity ID, retained for version-specific inspection.
|
|
396
425
|
pub values: Vec<Vec<u8>>,
|
|
397
426
|
}
|
|
398
427
|
|
|
428
|
+
/// A terminator (arrowhead) stored with a dimension.
|
|
429
|
+
#[derive(Debug, Clone, PartialEq)]
|
|
430
|
+
pub struct DimensionArrow {
|
|
431
|
+
/// Serialized display code: 1 for a terminator that is drawn, 0 for one that is
|
|
432
|
+
/// stored without being drawn (the far end of a diameter with one arrowhead).
|
|
433
|
+
pub display_value: i64,
|
|
434
|
+
/// Pointer to the DAF record with the shape and size of the terminator.
|
|
435
|
+
pub style_id: EntityId,
|
|
436
|
+
pub tip: Point2,
|
|
437
|
+
/// Direction from the tip along the body of the terminator, in radians.
|
|
438
|
+
pub angle: f64,
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/// A straight piece of a dimension line or of an extension line.
|
|
442
|
+
#[derive(Debug, Clone, PartialEq)]
|
|
443
|
+
pub struct DimensionSegment {
|
|
444
|
+
pub start: Point2,
|
|
445
|
+
pub end: Point2,
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/// A piece of a dimension arc, counterclockwise from `start` to `end`.
|
|
449
|
+
#[derive(Debug, Clone, PartialEq)]
|
|
450
|
+
pub struct DimensionArc {
|
|
451
|
+
pub start: Point2,
|
|
452
|
+
pub end: Point2,
|
|
453
|
+
pub center: Point2,
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/// A text beside the main text of a dimension, such as a prefix or a postfix.
|
|
457
|
+
#[derive(Debug, Clone, PartialEq)]
|
|
458
|
+
pub struct DimensionTextPart {
|
|
459
|
+
/// Which of the five text lists after the arcs the text is stored in, from 0.
|
|
460
|
+
/// List 1 holds texts placed before the main text, list 2 texts after it and
|
|
461
|
+
/// list 4 texts in a row below it; lists 0 and 3 are empty in the corpus.
|
|
462
|
+
pub slot: usize,
|
|
463
|
+
pub text: TextValue,
|
|
464
|
+
/// Start of the text: the lower left corner of its first character.
|
|
465
|
+
pub origin: Point2,
|
|
466
|
+
/// Pointer to the DTA text attribute of the text.
|
|
467
|
+
pub text_attribute_id: EntityId,
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/// Where the texts of a tolerance are drawn.
|
|
471
|
+
#[derive(Debug, Clone, PartialEq)]
|
|
472
|
+
pub struct DimensionTolerancePlacement {
|
|
473
|
+
/// Serialized layout code: 1 for one text after the main text, 2 for an upper
|
|
474
|
+
/// and a lower text after the main text, 3 for two limits drawn in place of the
|
|
475
|
+
/// main text.
|
|
476
|
+
pub layout_value: i64,
|
|
477
|
+
/// Pointer to the DTV record with the texts.
|
|
478
|
+
pub tolerance_id: EntityId,
|
|
479
|
+
/// Start of the upper text (the only text of layout 1).
|
|
480
|
+
pub upper_origin: Point2,
|
|
481
|
+
/// Start of the lower text. Layout 1 stores the text position here.
|
|
482
|
+
pub lower_origin: Point2,
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/// The drawn form of a dimension. The file stores these coordinates relative to
|
|
486
|
+
/// the text position, without rotation; here the text position is added, so they
|
|
487
|
+
/// are in the coordinate system of the part like every other entity.
|
|
488
|
+
#[derive(Debug, Clone, PartialEq)]
|
|
489
|
+
pub struct DimensionGraphics {
|
|
490
|
+
/// Start of the main text: the lower left corner of its first character.
|
|
491
|
+
pub text_origin: Point2,
|
|
492
|
+
/// Serialized value after the start of the main text. 0 or 1 in the corpus;
|
|
493
|
+
/// its meaning is not established.
|
|
494
|
+
pub text_flag_value: i64,
|
|
495
|
+
pub tolerance: Option<DimensionTolerancePlacement>,
|
|
496
|
+
pub arrows: Vec<DimensionArrow>,
|
|
497
|
+
/// Pointer to the DLA record of the dimension and extension lines.
|
|
498
|
+
pub line_style_id: EntityId,
|
|
499
|
+
pub lines: Vec<DimensionSegment>,
|
|
500
|
+
pub extension_lines: Vec<DimensionSegment>,
|
|
501
|
+
pub arcs: Vec<DimensionArc>,
|
|
502
|
+
pub text_parts: Vec<DimensionTextPart>,
|
|
503
|
+
}
|
|
504
|
+
|
|
399
505
|
#[derive(Debug, Clone, PartialEq)]
|
|
400
506
|
pub struct DimensionToleranceEntity {
|
|
401
507
|
pub entity: EntityHeader,
|
|
@@ -408,8 +514,10 @@ pub struct DimensionToleranceEntity {
|
|
|
408
514
|
pub upper_text: TextValue,
|
|
409
515
|
pub lower_text: TextValue,
|
|
410
516
|
pub text_style_id: EntityId,
|
|
411
|
-
///
|
|
412
|
-
|
|
517
|
+
/// Pointer to the DTA text attribute (fonts and size) of the tolerance text: the
|
|
518
|
+
/// last field. It was read as a text alignment code of 1 through 9; in every
|
|
519
|
+
/// tolerance of the corpus it is the ID of a DTA record.
|
|
520
|
+
pub text_attribute_id: EntityId,
|
|
413
521
|
pub values: Vec<Vec<u8>>,
|
|
414
522
|
}
|
|
415
523
|
|
|
@@ -3,8 +3,9 @@ use std::collections::{BTreeMap, BTreeSet};
|
|
|
3
3
|
|
|
4
4
|
use crate::model::{
|
|
5
5
|
ArcEntity, AssemblyEntity, AssemblyInstance, BSplineEntity, BSplineSample, Bounds2,
|
|
6
|
-
CircleEntity, ContourEntity, DimensionEntity,
|
|
7
|
-
|
|
6
|
+
CircleEntity, ContourEntity, DimensionArc, DimensionArrow, DimensionEntity, DimensionGraphics,
|
|
7
|
+
DimensionSegment, DimensionTextAttributeProperty, DimensionTextPart, DimensionToleranceEntity,
|
|
8
|
+
DimensionTolerancePlacement, EncodingInfo, EntityHeader, EntityId, GlobalInfo, GraphicHeader,
|
|
8
9
|
HatchAssociationEntity, HatchEntity, HatchPatternLine, HatchPatternProperty, LeaderEntity,
|
|
9
10
|
LeaderPoint, LineEntity, Part, PartStatusProperty, Point2, PointEntity, PropertyEntity,
|
|
10
11
|
SemanticDocument, SemanticEntity, SymbolEntity, TextEntity, TextValue, UnsupportedEntity,
|
|
@@ -67,6 +68,13 @@ pub fn read_input_with_encoding<'a>(
|
|
|
67
68
|
})
|
|
68
69
|
}
|
|
69
70
|
|
|
71
|
+
/// Section `#~31` holds the preview pixmap of the drawing (`PXMAP`), after the global
|
|
72
|
+
/// section. The table of contents lists no entity number for it and the numbering of
|
|
73
|
+
/// the entities starts in `#~41`: the field after `PXMAP` is not an entity ID. Read as
|
|
74
|
+
/// one, its value 1 took the place of the first property, so every pointer to that
|
|
75
|
+
/// property (the text attribute of dimensions, for one) was left unresolved.
|
|
76
|
+
const PIXMAP_SECTION: u32 = 31;
|
|
77
|
+
|
|
70
78
|
fn read_scanned_with_encoding(
|
|
71
79
|
data: &[u8],
|
|
72
80
|
raw: RawDocument,
|
|
@@ -83,6 +91,10 @@ fn read_scanned_with_encoding(
|
|
|
83
91
|
let Some(mi_type) = record.record_type.as_deref() else {
|
|
84
92
|
continue;
|
|
85
93
|
};
|
|
94
|
+
if record.section_number == PIXMAP_SECTION {
|
|
95
|
+
// Not an addressable entity: the record stays in the raw document.
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
86
98
|
let part_index = section_parts.get(record.section_index).copied().flatten();
|
|
87
99
|
if let Some(entity) = parse_entity(
|
|
88
100
|
data,
|
|
@@ -843,6 +855,9 @@ fn parse_property(
|
|
|
843
855
|
fields.len().saturating_sub(3)
|
|
844
856
|
));
|
|
845
857
|
}
|
|
858
|
+
let definition_values = (6..fields.len())
|
|
859
|
+
.map(|index| required_f64(fields, index, "DTA numeric definition"))
|
|
860
|
+
.collect::<Result<Vec<_>, _>>()?;
|
|
846
861
|
Some(DimensionTextAttributeProperty {
|
|
847
862
|
font_name: decoded_text_field(
|
|
848
863
|
data,
|
|
@@ -874,9 +889,16 @@ fn parse_property(
|
|
|
874
889
|
"DTA symbol font",
|
|
875
890
|
)
|
|
876
891
|
.expect("DTA field count was checked"),
|
|
877
|
-
|
|
878
|
-
.
|
|
879
|
-
.
|
|
892
|
+
size: definition_values
|
|
893
|
+
.get(2)
|
|
894
|
+
.copied()
|
|
895
|
+
.filter(|size| size.is_finite() && *size > 0.0),
|
|
896
|
+
relative_size: match definition_values.get(1) {
|
|
897
|
+
Some(mode) if *mode == 0.0 => Some(false),
|
|
898
|
+
Some(mode) if *mode == 1.0 => Some(true),
|
|
899
|
+
_ => None,
|
|
900
|
+
},
|
|
901
|
+
definition_values,
|
|
880
902
|
})
|
|
881
903
|
} else {
|
|
882
904
|
None
|
|
@@ -967,11 +989,9 @@ fn parse_dimension_tolerance(
|
|
|
967
989
|
if fields.len() != 10 {
|
|
968
990
|
return Err(format!("DTV has {} fields; expected 10", fields.len()));
|
|
969
991
|
}
|
|
970
|
-
let
|
|
971
|
-
if
|
|
972
|
-
return Err(
|
|
973
|
-
"tolerance text alignment {alignment} is outside 1 through 9"
|
|
974
|
-
));
|
|
992
|
+
let text_attribute_id = required_u64(fields, 9, "tolerance text attribute pointer")?;
|
|
993
|
+
if text_attribute_id == 0 {
|
|
994
|
+
return Err("tolerance text attribute pointer is zero".to_owned());
|
|
975
995
|
}
|
|
976
996
|
Ok(SemanticEntity::DimensionTolerance(
|
|
977
997
|
DimensionToleranceEntity {
|
|
@@ -1001,7 +1021,7 @@ fn parse_dimension_tolerance(
|
|
|
1001
1021
|
)
|
|
1002
1022
|
.expect("DTV field count was checked"),
|
|
1003
1023
|
text_style_id: required_u64(fields, 8, "tolerance text style pointer")?,
|
|
1004
|
-
|
|
1024
|
+
text_attribute_id,
|
|
1005
1025
|
values: fields.iter().skip(2).map(|field| field.to_vec()).collect(),
|
|
1006
1026
|
},
|
|
1007
1027
|
))
|
|
@@ -1229,50 +1249,271 @@ fn parse_dimension(
|
|
|
1229
1249
|
measurement_index - 2,
|
|
1230
1250
|
"dimension text style pointer",
|
|
1231
1251
|
)?;
|
|
1252
|
+
let text_attribute_id = required_u64(
|
|
1253
|
+
fields,
|
|
1254
|
+
measurement_index - 1,
|
|
1255
|
+
"dimension text attribute pointer",
|
|
1256
|
+
)?;
|
|
1257
|
+
// The text position is followed by two vectors: the extent of the text box along
|
|
1258
|
+
// the text and across it.
|
|
1259
|
+
let position_index = content_start + position_offset;
|
|
1260
|
+
let text_extent = Point2::new(
|
|
1261
|
+
required_f64(fields, position_index + 2, "dimension text extent x")?,
|
|
1262
|
+
required_f64(fields, position_index + 3, "dimension text extent y")?,
|
|
1263
|
+
);
|
|
1264
|
+
let text_up_extent = Point2::new(
|
|
1265
|
+
required_f64(fields, position_index + 4, "dimension text up extent x")?,
|
|
1266
|
+
required_f64(fields, position_index + 5, "dimension text up extent y")?,
|
|
1267
|
+
);
|
|
1268
|
+
let reference_geometry_ids = geometry_offsets
|
|
1269
|
+
.iter()
|
|
1270
|
+
.map(|offset| required_u64(fields, content_start + offset, "dimension geometry pointer"))
|
|
1271
|
+
.collect::<Result<Vec<_>, _>>()?;
|
|
1272
|
+
let reference_point_ids = point_offsets
|
|
1273
|
+
.iter()
|
|
1274
|
+
.map(|offset| required_u64(fields, content_start + offset, "dimension point pointer"))
|
|
1275
|
+
.collect::<Result<Vec<_>, _>>()?;
|
|
1276
|
+
let text_position = Point2::new(
|
|
1277
|
+
required_f64(fields, position_index, "dimension text position x")?,
|
|
1278
|
+
required_f64(fields, position_index + 1, "dimension text position y")?,
|
|
1279
|
+
);
|
|
1280
|
+
let measurement = required_f64(fields, measurement_index, "dimension measurement")?;
|
|
1281
|
+
let formatted_text = decoded_text_field(
|
|
1282
|
+
data,
|
|
1283
|
+
fields,
|
|
1284
|
+
measurement_index + 1,
|
|
1285
|
+
start_line,
|
|
1286
|
+
encoding,
|
|
1287
|
+
diagnostics,
|
|
1288
|
+
&format!("{mi_type} formatted measurement"),
|
|
1289
|
+
)
|
|
1290
|
+
.expect("dimension field count was checked");
|
|
1291
|
+
let graphics = parse_dimension_graphics(
|
|
1292
|
+
data,
|
|
1293
|
+
fields,
|
|
1294
|
+
measurement_index + 2,
|
|
1295
|
+
&text_position,
|
|
1296
|
+
start_line,
|
|
1297
|
+
encoding,
|
|
1298
|
+
diagnostics,
|
|
1299
|
+
mi_type,
|
|
1300
|
+
);
|
|
1232
1301
|
Ok(SemanticEntity::Dimension(DimensionEntity {
|
|
1233
1302
|
entity,
|
|
1234
1303
|
mi_type: mi_type.to_owned(),
|
|
1235
1304
|
property_ids,
|
|
1236
|
-
reference_geometry_ids
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
.collect::<Result<Vec<_>, _>>()?,
|
|
1242
|
-
reference_point_ids: point_offsets
|
|
1243
|
-
.iter()
|
|
1244
|
-
.map(|offset| required_u64(fields, content_start + offset, "dimension point pointer"))
|
|
1245
|
-
.collect::<Result<Vec<_>, _>>()?,
|
|
1246
|
-
text_position: Point2::new(
|
|
1247
|
-
required_f64(
|
|
1248
|
-
fields,
|
|
1249
|
-
content_start + position_offset,
|
|
1250
|
-
"dimension text position x",
|
|
1251
|
-
)?,
|
|
1252
|
-
required_f64(
|
|
1253
|
-
fields,
|
|
1254
|
-
content_start + position_offset + 1,
|
|
1255
|
-
"dimension text position y",
|
|
1256
|
-
)?,
|
|
1257
|
-
),
|
|
1258
|
-
measurement: required_f64(fields, measurement_index, "dimension measurement")?,
|
|
1259
|
-
formatted_text: decoded_text_field(
|
|
1260
|
-
data,
|
|
1261
|
-
fields,
|
|
1262
|
-
measurement_index + 1,
|
|
1263
|
-
start_line,
|
|
1264
|
-
encoding,
|
|
1265
|
-
diagnostics,
|
|
1266
|
-
&format!("{mi_type} formatted measurement"),
|
|
1267
|
-
)
|
|
1268
|
-
.expect("dimension field count was checked"),
|
|
1305
|
+
reference_geometry_ids,
|
|
1306
|
+
reference_point_ids,
|
|
1307
|
+
text_position,
|
|
1308
|
+
measurement,
|
|
1309
|
+
formatted_text,
|
|
1269
1310
|
dimension_style_id: (style_id != 0).then_some(style_id),
|
|
1270
1311
|
text_style_id: (text_style_id != 0).then_some(text_style_id),
|
|
1312
|
+
text_attribute_id: (text_attribute_id != 0).then_some(text_attribute_id),
|
|
1313
|
+
text_extent,
|
|
1314
|
+
text_up_extent,
|
|
1271
1315
|
tolerance_ids: Vec::new(),
|
|
1316
|
+
graphics,
|
|
1272
1317
|
values: fields.iter().skip(2).map(|field| field.to_vec()).collect(),
|
|
1273
1318
|
}))
|
|
1274
1319
|
}
|
|
1275
1320
|
|
|
1321
|
+
/// Reads fields in order and remembers the first one that does not fit.
|
|
1322
|
+
struct FieldCursor<'a, 'b> {
|
|
1323
|
+
fields: &'a [&'b [u8]],
|
|
1324
|
+
index: usize,
|
|
1325
|
+
failed: bool,
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
impl FieldCursor<'_, '_> {
|
|
1329
|
+
fn integer(&mut self) -> i64 {
|
|
1330
|
+
let value = self
|
|
1331
|
+
.fields
|
|
1332
|
+
.get(self.index)
|
|
1333
|
+
.and_then(|field| parse_i64(field));
|
|
1334
|
+
self.index += 1;
|
|
1335
|
+
value.unwrap_or_else(|| {
|
|
1336
|
+
self.failed = true;
|
|
1337
|
+
0
|
|
1338
|
+
})
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
fn count(&mut self) -> usize {
|
|
1342
|
+
// a count larger than the record cannot be honest; it also bounds the loops
|
|
1343
|
+
match usize::try_from(self.integer()) {
|
|
1344
|
+
Ok(count) if count <= self.fields.len() => count,
|
|
1345
|
+
_ => {
|
|
1346
|
+
self.failed = true;
|
|
1347
|
+
0
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
fn pointer(&mut self) -> EntityId {
|
|
1353
|
+
u64::try_from(self.integer()).unwrap_or_else(|_| {
|
|
1354
|
+
self.failed = true;
|
|
1355
|
+
0
|
|
1356
|
+
})
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
fn number(&mut self) -> f64 {
|
|
1360
|
+
let value = self
|
|
1361
|
+
.fields
|
|
1362
|
+
.get(self.index)
|
|
1363
|
+
.and_then(|field| parse_f64(field))
|
|
1364
|
+
.filter(|value| value.is_finite());
|
|
1365
|
+
self.index += 1;
|
|
1366
|
+
value.unwrap_or_else(|| {
|
|
1367
|
+
self.failed = true;
|
|
1368
|
+
0.0
|
|
1369
|
+
})
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
/// A point stored relative to `origin`.
|
|
1373
|
+
fn point(&mut self, origin: &Point2) -> Point2 {
|
|
1374
|
+
let x = self.number();
|
|
1375
|
+
let y = self.number();
|
|
1376
|
+
Point2::new(origin.x + x, origin.y + y)
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
fn skip_field(&mut self) -> usize {
|
|
1380
|
+
if self.index >= self.fields.len() {
|
|
1381
|
+
self.failed = true;
|
|
1382
|
+
}
|
|
1383
|
+
self.index += 1;
|
|
1384
|
+
self.index - 1
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
/// The fields after the formatted text of a dimension: the drawn form.
|
|
1389
|
+
///
|
|
1390
|
+
/// ```text
|
|
1391
|
+
/// x y start of the main text
|
|
1392
|
+
/// flag
|
|
1393
|
+
/// layout [DTV x y x y] tolerance; the bracket only when layout is not 0
|
|
1394
|
+
/// 0
|
|
1395
|
+
/// n [0 n*(display DAF x y angle)] terminators
|
|
1396
|
+
/// DLA
|
|
1397
|
+
/// n n*(x y x y) dimension lines
|
|
1398
|
+
/// n [0 n*(x y x y)] extension lines
|
|
1399
|
+
/// 0
|
|
1400
|
+
/// n n*(x y x y x y) dimension arcs: start, end, center
|
|
1401
|
+
/// 5 * (n n*(text x y DTA)) texts beside the main text
|
|
1402
|
+
/// ```
|
|
1403
|
+
///
|
|
1404
|
+
/// Every coordinate is relative to the text position. The layout is read from
|
|
1405
|
+
/// MI 2.40 through 3.40. A record that does not follow it to its last field, or
|
|
1406
|
+
/// whose fixed zeros are not zero, has no typed graphics.
|
|
1407
|
+
#[allow(clippy::too_many_arguments)]
|
|
1408
|
+
fn parse_dimension_graphics(
|
|
1409
|
+
data: &[u8],
|
|
1410
|
+
fields: &[&[u8]],
|
|
1411
|
+
start: usize,
|
|
1412
|
+
text_position: &Point2,
|
|
1413
|
+
start_line: usize,
|
|
1414
|
+
encoding: &EncodingInfo,
|
|
1415
|
+
diagnostics: &mut Vec<Diagnostic>,
|
|
1416
|
+
mi_type: &str,
|
|
1417
|
+
) -> Option<DimensionGraphics> {
|
|
1418
|
+
const TEXT_SLOTS: usize = 5;
|
|
1419
|
+
let mut cursor = FieldCursor {
|
|
1420
|
+
fields,
|
|
1421
|
+
index: start,
|
|
1422
|
+
failed: false,
|
|
1423
|
+
};
|
|
1424
|
+
let text_origin = cursor.point(text_position);
|
|
1425
|
+
let text_flag_value = cursor.integer();
|
|
1426
|
+
let layout_value = cursor.integer();
|
|
1427
|
+
let tolerance = (layout_value != 0).then(|| DimensionTolerancePlacement {
|
|
1428
|
+
layout_value,
|
|
1429
|
+
tolerance_id: cursor.pointer(),
|
|
1430
|
+
upper_origin: cursor.point(text_position),
|
|
1431
|
+
lower_origin: cursor.point(text_position),
|
|
1432
|
+
});
|
|
1433
|
+
let mut zeros = vec![cursor.integer()];
|
|
1434
|
+
let arrow_count = cursor.count();
|
|
1435
|
+
if arrow_count > 0 {
|
|
1436
|
+
zeros.push(cursor.integer());
|
|
1437
|
+
}
|
|
1438
|
+
let arrows = (0..arrow_count)
|
|
1439
|
+
.map(|_| DimensionArrow {
|
|
1440
|
+
display_value: cursor.integer(),
|
|
1441
|
+
style_id: cursor.pointer(),
|
|
1442
|
+
tip: cursor.point(text_position),
|
|
1443
|
+
angle: cursor.number(),
|
|
1444
|
+
})
|
|
1445
|
+
.collect::<Vec<_>>();
|
|
1446
|
+
let line_style_id = cursor.pointer();
|
|
1447
|
+
let line_count = cursor.count();
|
|
1448
|
+
let lines = (0..line_count)
|
|
1449
|
+
.map(|_| DimensionSegment {
|
|
1450
|
+
start: cursor.point(text_position),
|
|
1451
|
+
end: cursor.point(text_position),
|
|
1452
|
+
})
|
|
1453
|
+
.collect::<Vec<_>>();
|
|
1454
|
+
let extension_count = cursor.count();
|
|
1455
|
+
if extension_count > 0 {
|
|
1456
|
+
zeros.push(cursor.integer());
|
|
1457
|
+
}
|
|
1458
|
+
let extension_lines = (0..extension_count)
|
|
1459
|
+
.map(|_| DimensionSegment {
|
|
1460
|
+
start: cursor.point(text_position),
|
|
1461
|
+
end: cursor.point(text_position),
|
|
1462
|
+
})
|
|
1463
|
+
.collect::<Vec<_>>();
|
|
1464
|
+
zeros.push(cursor.integer());
|
|
1465
|
+
let arc_count = cursor.count();
|
|
1466
|
+
let arcs = (0..arc_count)
|
|
1467
|
+
.map(|_| DimensionArc {
|
|
1468
|
+
start: cursor.point(text_position),
|
|
1469
|
+
end: cursor.point(text_position),
|
|
1470
|
+
center: cursor.point(text_position),
|
|
1471
|
+
})
|
|
1472
|
+
.collect::<Vec<_>>();
|
|
1473
|
+
// (slot, field index of the text, start, DTA pointer): decoded once the whole
|
|
1474
|
+
// record is known to fit, so a record that does not fit reports nothing
|
|
1475
|
+
let mut parts = Vec::new();
|
|
1476
|
+
for slot in 0..TEXT_SLOTS {
|
|
1477
|
+
for _ in 0..cursor.count() {
|
|
1478
|
+
let field_index = cursor.skip_field();
|
|
1479
|
+
let origin = cursor.point(text_position);
|
|
1480
|
+
parts.push((slot, field_index, origin, cursor.pointer()));
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
if cursor.failed || cursor.index != fields.len() || zeros.iter().any(|value| *value != 0) {
|
|
1484
|
+
return None;
|
|
1485
|
+
}
|
|
1486
|
+
let text_parts = parts
|
|
1487
|
+
.into_iter()
|
|
1488
|
+
.map(
|
|
1489
|
+
|(slot, field_index, origin, text_attribute_id)| DimensionTextPart {
|
|
1490
|
+
slot,
|
|
1491
|
+
text: decode_text_value(
|
|
1492
|
+
data,
|
|
1493
|
+
fields[field_index],
|
|
1494
|
+
start_line + field_index,
|
|
1495
|
+
encoding,
|
|
1496
|
+
diagnostics,
|
|
1497
|
+
&format!("{mi_type} text part"),
|
|
1498
|
+
),
|
|
1499
|
+
origin,
|
|
1500
|
+
text_attribute_id,
|
|
1501
|
+
},
|
|
1502
|
+
)
|
|
1503
|
+
.collect();
|
|
1504
|
+
Some(DimensionGraphics {
|
|
1505
|
+
text_origin,
|
|
1506
|
+
text_flag_value,
|
|
1507
|
+
tolerance,
|
|
1508
|
+
arrows,
|
|
1509
|
+
line_style_id,
|
|
1510
|
+
lines,
|
|
1511
|
+
extension_lines,
|
|
1512
|
+
arcs,
|
|
1513
|
+
text_parts,
|
|
1514
|
+
})
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1276
1517
|
fn parse_assembly(
|
|
1277
1518
|
data: &[u8],
|
|
1278
1519
|
fields: &[&[u8]],
|
|
@@ -2261,9 +2502,13 @@ fn resolve_references(
|
|
|
2261
2502
|
diagnostics,
|
|
2262
2503
|
);
|
|
2263
2504
|
}
|
|
2264
|
-
for style_id in [
|
|
2265
|
-
.
|
|
2266
|
-
.
|
|
2505
|
+
for style_id in [
|
|
2506
|
+
dimension.dimension_style_id,
|
|
2507
|
+
dimension.text_style_id,
|
|
2508
|
+
dimension.text_attribute_id,
|
|
2509
|
+
]
|
|
2510
|
+
.into_iter()
|
|
2511
|
+
.flatten()
|
|
2267
2512
|
{
|
|
2268
2513
|
validate_property_pointer(
|
|
2269
2514
|
dimension.entity.id,
|
|
@@ -2288,15 +2533,17 @@ fn resolve_references(
|
|
|
2288
2533
|
});
|
|
2289
2534
|
}
|
|
2290
2535
|
SemanticEntity::DimensionTolerance(tolerance) => {
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2536
|
+
for style_id in [tolerance.text_style_id, tolerance.text_attribute_id] {
|
|
2537
|
+
validate_property_pointer(
|
|
2538
|
+
tolerance.entity.id,
|
|
2539
|
+
style_id,
|
|
2540
|
+
tolerance.entity.raw_record_index,
|
|
2541
|
+
&property_ids,
|
|
2542
|
+
entity_index,
|
|
2543
|
+
raw,
|
|
2544
|
+
diagnostics,
|
|
2545
|
+
);
|
|
2546
|
+
}
|
|
2300
2547
|
}
|
|
2301
2548
|
SemanticEntity::Leader(leader) => {
|
|
2302
2549
|
validate_property(
|