ezmi2d 0.2.2__tar.gz → 0.2.3__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.
Files changed (54) hide show
  1. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/Cargo.lock +2 -2
  2. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/Cargo.toml +1 -1
  3. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/PKG-INFO +3 -2
  4. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/README.md +2 -1
  5. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/crates/ezmi2d-core/src/model.rs +28 -2
  6. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/crates/ezmi2d-core/src/semantic.rs +65 -21
  7. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/crates/ezmi2d-python/src/lib.rs +6 -1
  8. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/docs/api.md +4 -3
  9. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/docs/mi-format-research.md +32 -0
  10. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/pyproject.toml +1 -1
  11. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/scripts/audit_semantics.py +26 -0
  12. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/scripts/verify_release_artifacts.py +12 -7
  13. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/src/ezmi2d/document.py +11 -1
  14. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/src/ezmi2d/entities.py +68 -7
  15. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/tests/data/phase5.mi +33 -5
  16. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/tests/python/test_semantic_audit.py +8 -0
  17. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/LICENSE +0 -0
  18. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/benchmarks/README.md +0 -0
  19. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/benchmarks/benchmark_pipeline.py +0 -0
  20. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/benchmarks/results/phase6-baseline.json +0 -0
  21. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/benchmarks/results/phase6-baseline.md +0 -0
  22. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/crates/ezmi2d-core/Cargo.toml +0 -0
  23. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/crates/ezmi2d-core/src/compression.rs +0 -0
  24. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/crates/ezmi2d-core/src/encoding.rs +0 -0
  25. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/crates/ezmi2d-core/src/error.rs +0 -0
  26. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/crates/ezmi2d-core/src/lib.rs +0 -0
  27. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/crates/ezmi2d-core/src/options.rs +0 -0
  28. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/crates/ezmi2d-core/src/raw.rs +0 -0
  29. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/crates/ezmi2d-core/src/scanner.rs +0 -0
  30. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/crates/ezmi2d-core/tests/hardening.rs +0 -0
  31. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/crates/ezmi2d-core/tests/raw_scan.rs +0 -0
  32. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/crates/ezmi2d-core/tests/semantic_read.rs +0 -0
  33. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/crates/ezmi2d-python/Cargo.toml +0 -0
  34. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/docs/releasing.md +0 -0
  35. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/examples/plot_mi.py +0 -0
  36. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/fuzz/Cargo.lock +0 -0
  37. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/fuzz/Cargo.toml +0 -0
  38. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/fuzz/fuzz_targets/raw_scan.rs +0 -0
  39. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/fuzz/fuzz_targets/semantic_read.rs +0 -0
  40. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/samples/README.md +0 -0
  41. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/samples/manifest.toml +0 -0
  42. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/scripts/check_release_version.py +0 -0
  43. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/scripts/fetch_external_samples.sh +0 -0
  44. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/scripts/smoke_installed_package.py +0 -0
  45. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/src/ezmi2d/__init__.py +0 -0
  46. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/src/ezmi2d/__main__.py +0 -0
  47. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/src/ezmi2d/_core.pyi +0 -0
  48. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/src/ezmi2d/diagnostics.py +0 -0
  49. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/src/ezmi2d/plotting.py +0 -0
  50. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/src/ezmi2d/py.typed +0 -0
  51. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/src/ezmi2d/raw.py +0 -0
  52. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/tests/data/geometry.mi +0 -0
  53. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/tests/data/minimal.mi +0 -0
  54. {ezmi2d-0.2.2 → ezmi2d-0.2.3}/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.2"
37
+ version = "0.2.3"
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.2"
46
+ version = "0.2.3"
47
47
  dependencies = [
48
48
  "ezmi2d-core",
49
49
  "pyo3",
@@ -3,7 +3,7 @@ members = ["crates/ezmi2d-core", "crates/ezmi2d-python"]
3
3
  resolver = "2"
4
4
 
5
5
  [workspace.package]
6
- version = "0.2.2"
6
+ version = "0.2.3"
7
7
  edition = "2021"
8
8
  rust-version = "1.83"
9
9
  authors = ["neka-nat <nekanat.stock@gmail.com>"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ezmi2d
3
- Version: 0.2.2
3
+ Version: 0.2.3
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,8 @@ 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, and linked `DTV` tolerances
164
+ formatted text, placement, DDA/DTF style, the DTA text attribute with the text height
165
+ (`text_height`), the stored text box, and linked `DTV` tolerances
165
166
  - drawable `LED` vertices, `SYML` components, and associative `HAT` patterns/boundaries through
166
167
  typed `COC`, `PFA`, and `HAPP` records
167
168
  - typed `Affine2D`, nested/shared `ASSE` occurrence traversal, composed child-to-parent transforms,
@@ -126,7 +126,8 @@ 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, and linked `DTV` tolerances
129
+ formatted text, placement, DDA/DTF style, the DTA text attribute with the text height
130
+ (`text_height`), the stored text box, and linked `DTV` tolerances
130
131
  - drawable `LED` vertices, `SYML` components, and associative `HAT` patterns/boundaries through
131
132
  typed `COC`, `PFA`, and `HAPP` records
132
133
  - typed `Affine2D`, nested/shared `ASSE` occurrence traversal, composed child-to-parent transforms,
@@ -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,6 +403,18 @@ 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>,
395
419
  /// All fields after the entity ID, retained for version-specific inspection.
396
420
  pub values: Vec<Vec<u8>>,
@@ -408,8 +432,10 @@ pub struct DimensionToleranceEntity {
408
432
  pub upper_text: TextValue,
409
433
  pub lower_text: TextValue,
410
434
  pub text_style_id: EntityId,
411
- /// Text origin adjustment code: 1 (lower-left) through 9 (upper-right).
412
- pub alignment: usize,
435
+ /// Pointer to the DTA text attribute (fonts and size) of the tolerance text: the
436
+ /// last field. It was read as a text alignment code of 1 through 9; in every
437
+ /// tolerance of the corpus it is the ID of a DTA record.
438
+ pub text_attribute_id: EntityId,
413
439
  pub values: Vec<Vec<u8>>,
414
440
  }
415
441
 
@@ -67,6 +67,13 @@ pub fn read_input_with_encoding<'a>(
67
67
  })
68
68
  }
69
69
 
70
+ /// Section `#~31` holds the preview pixmap of the drawing (`PXMAP`), after the global
71
+ /// section. The table of contents lists no entity number for it and the numbering of
72
+ /// the entities starts in `#~41`: the field after `PXMAP` is not an entity ID. Read as
73
+ /// one, its value 1 took the place of the first property, so every pointer to that
74
+ /// property (the text attribute of dimensions, for one) was left unresolved.
75
+ const PIXMAP_SECTION: u32 = 31;
76
+
70
77
  fn read_scanned_with_encoding(
71
78
  data: &[u8],
72
79
  raw: RawDocument,
@@ -83,6 +90,10 @@ fn read_scanned_with_encoding(
83
90
  let Some(mi_type) = record.record_type.as_deref() else {
84
91
  continue;
85
92
  };
93
+ if record.section_number == PIXMAP_SECTION {
94
+ // Not an addressable entity: the record stays in the raw document.
95
+ continue;
96
+ }
86
97
  let part_index = section_parts.get(record.section_index).copied().flatten();
87
98
  if let Some(entity) = parse_entity(
88
99
  data,
@@ -843,6 +854,9 @@ fn parse_property(
843
854
  fields.len().saturating_sub(3)
844
855
  ));
845
856
  }
857
+ let definition_values = (6..fields.len())
858
+ .map(|index| required_f64(fields, index, "DTA numeric definition"))
859
+ .collect::<Result<Vec<_>, _>>()?;
846
860
  Some(DimensionTextAttributeProperty {
847
861
  font_name: decoded_text_field(
848
862
  data,
@@ -874,9 +888,16 @@ fn parse_property(
874
888
  "DTA symbol font",
875
889
  )
876
890
  .expect("DTA field count was checked"),
877
- definition_values: (6..fields.len())
878
- .map(|index| required_f64(fields, index, "DTA numeric definition"))
879
- .collect::<Result<Vec<_>, _>>()?,
891
+ size: definition_values
892
+ .get(2)
893
+ .copied()
894
+ .filter(|size| size.is_finite() && *size > 0.0),
895
+ relative_size: match definition_values.get(1) {
896
+ Some(mode) if *mode == 0.0 => Some(false),
897
+ Some(mode) if *mode == 1.0 => Some(true),
898
+ _ => None,
899
+ },
900
+ definition_values,
880
901
  })
881
902
  } else {
882
903
  None
@@ -967,11 +988,9 @@ fn parse_dimension_tolerance(
967
988
  if fields.len() != 10 {
968
989
  return Err(format!("DTV has {} fields; expected 10", fields.len()));
969
990
  }
970
- let alignment = required_usize(fields, 9, "tolerance text alignment")?;
971
- if !(1..=9).contains(&alignment) {
972
- return Err(format!(
973
- "tolerance text alignment {alignment} is outside 1 through 9"
974
- ));
991
+ let text_attribute_id = required_u64(fields, 9, "tolerance text attribute pointer")?;
992
+ if text_attribute_id == 0 {
993
+ return Err("tolerance text attribute pointer is zero".to_owned());
975
994
  }
976
995
  Ok(SemanticEntity::DimensionTolerance(
977
996
  DimensionToleranceEntity {
@@ -1001,7 +1020,7 @@ fn parse_dimension_tolerance(
1001
1020
  )
1002
1021
  .expect("DTV field count was checked"),
1003
1022
  text_style_id: required_u64(fields, 8, "tolerance text style pointer")?,
1004
- alignment,
1023
+ text_attribute_id,
1005
1024
  values: fields.iter().skip(2).map(|field| field.to_vec()).collect(),
1006
1025
  },
1007
1026
  ))
@@ -1229,6 +1248,22 @@ fn parse_dimension(
1229
1248
  measurement_index - 2,
1230
1249
  "dimension text style pointer",
1231
1250
  )?;
1251
+ let text_attribute_id = required_u64(
1252
+ fields,
1253
+ measurement_index - 1,
1254
+ "dimension text attribute pointer",
1255
+ )?;
1256
+ // The text position is followed by two vectors: the extent of the text box along
1257
+ // the text and across it.
1258
+ let position_index = content_start + position_offset;
1259
+ let text_extent = Point2::new(
1260
+ required_f64(fields, position_index + 2, "dimension text extent x")?,
1261
+ required_f64(fields, position_index + 3, "dimension text extent y")?,
1262
+ );
1263
+ let text_up_extent = Point2::new(
1264
+ required_f64(fields, position_index + 4, "dimension text up extent x")?,
1265
+ required_f64(fields, position_index + 5, "dimension text up extent y")?,
1266
+ );
1232
1267
  Ok(SemanticEntity::Dimension(DimensionEntity {
1233
1268
  entity,
1234
1269
  mi_type: mi_type.to_owned(),
@@ -1268,6 +1303,9 @@ fn parse_dimension(
1268
1303
  .expect("dimension field count was checked"),
1269
1304
  dimension_style_id: (style_id != 0).then_some(style_id),
1270
1305
  text_style_id: (text_style_id != 0).then_some(text_style_id),
1306
+ text_attribute_id: (text_attribute_id != 0).then_some(text_attribute_id),
1307
+ text_extent,
1308
+ text_up_extent,
1271
1309
  tolerance_ids: Vec::new(),
1272
1310
  values: fields.iter().skip(2).map(|field| field.to_vec()).collect(),
1273
1311
  }))
@@ -2261,9 +2299,13 @@ fn resolve_references(
2261
2299
  diagnostics,
2262
2300
  );
2263
2301
  }
2264
- for style_id in [dimension.dimension_style_id, dimension.text_style_id]
2265
- .into_iter()
2266
- .flatten()
2302
+ for style_id in [
2303
+ dimension.dimension_style_id,
2304
+ dimension.text_style_id,
2305
+ dimension.text_attribute_id,
2306
+ ]
2307
+ .into_iter()
2308
+ .flatten()
2267
2309
  {
2268
2310
  validate_property_pointer(
2269
2311
  dimension.entity.id,
@@ -2288,15 +2330,17 @@ fn resolve_references(
2288
2330
  });
2289
2331
  }
2290
2332
  SemanticEntity::DimensionTolerance(tolerance) => {
2291
- validate_property_pointer(
2292
- tolerance.entity.id,
2293
- tolerance.text_style_id,
2294
- tolerance.entity.raw_record_index,
2295
- &property_ids,
2296
- entity_index,
2297
- raw,
2298
- diagnostics,
2299
- );
2333
+ for style_id in [tolerance.text_style_id, tolerance.text_attribute_id] {
2334
+ validate_property_pointer(
2335
+ tolerance.entity.id,
2336
+ style_id,
2337
+ tolerance.entity.raw_record_index,
2338
+ &property_ids,
2339
+ entity_index,
2340
+ raw,
2341
+ diagnostics,
2342
+ );
2343
+ }
2300
2344
  }
2301
2345
  SemanticEntity::Leader(leader) => {
2302
2346
  validate_property(
@@ -384,6 +384,8 @@ fn entity_dict<'py>(py: Python<'py>, entity: &SemanticEntity) -> PyResult<Bound<
384
384
  text_dict(py, &attribute.symbol_font_name)?,
385
385
  )?;
386
386
  value.set_item("definition_values", &attribute.definition_values)?;
387
+ value.set_item("size", attribute.size)?;
388
+ value.set_item("relative_size", attribute.relative_size)?;
387
389
  result.set_item("dimension_text_attribute", value)?;
388
390
  } else {
389
391
  result.set_item("dimension_text_attribute", py.None())?;
@@ -438,6 +440,9 @@ fn set_dimension_fields(
438
440
  result.set_item("formatted_text", text_dict(py, &value.formatted_text)?)?;
439
441
  result.set_item("dimension_style_id", value.dimension_style_id)?;
440
442
  result.set_item("text_style_id", value.text_style_id)?;
443
+ result.set_item("text_attribute_id", value.text_attribute_id)?;
444
+ result.set_item("text_extent", point_dict(py, &value.text_extent)?)?;
445
+ result.set_item("text_up_extent", point_dict(py, &value.text_up_extent)?)?;
441
446
  result.set_item("tolerance_ids", &value.tolerance_ids)?;
442
447
  result.set_item("values", byte_values(py, &value.values)?)?;
443
448
  Ok(())
@@ -455,7 +460,7 @@ fn set_dimension_tolerance_fields(
455
460
  result.set_item("upper_text", text_dict(py, &value.upper_text)?)?;
456
461
  result.set_item("lower_text", text_dict(py, &value.lower_text)?)?;
457
462
  result.set_item("text_style_id", value.text_style_id)?;
458
- result.set_item("alignment", value.alignment)?;
463
+ result.set_item("text_attribute_id", value.text_attribute_id)?;
459
464
  result.set_item("values", byte_values(py, &value.values)?)?;
460
465
  Ok(())
461
466
  }
@@ -137,14 +137,15 @@ Every entity derives from the frozen `MiEntity` data model and retains `id`, `mi
137
137
  | `BSPL` | `BSpline` | order/degree, presence-aware flags/weights, controls, knots, samples, `evaluate()` |
138
138
  | `CIR` | `Circle` | resolved center/circumference and radius |
139
139
  | `TEX` | `Text` | 3x3 transform, origin, rotation, width factor, mirror, alignment, fonts, multiline content |
140
- | `DANG`, `DCHMF`, `DDIA`, `DRAD`, `DSGL` | `Dimension` | resolved geometry/point references, text position, measurement, formatted text, DDA/DTF styles, DTV references |
141
- | `DTV` | `DimensionTolerance` | upper/lower values and text, DTF style, alignment |
140
+ | `DANG`, `DCHMF`, `DDIA`, `DRAD`, `DSGL` | `Dimension` | resolved geometry/point references, text position, measurement, formatted text, DDA/DTF styles, DTA text attribute (`text_attribute`, `text_height`), stored text box (`text_extent`, `text_up_extent`, `text_rotation`), DTV references |
141
+ | `DTV` | `DimensionTolerance` | upper/lower values and text, DTF style, DTA text attribute (`text_attribute`, `text_height(main_text_height)`) |
142
142
  | `LED` | `Leader` | graphic attributes, arrow code/size, ordered 2D vertices and retained elevations |
143
143
  | `COC` | `Contour` | ordered graphic components, closed flag, raw orientation |
144
144
  | `HAT` / `PFA` | `Hatch` / `HatchAssociation` | pattern origin/angle/spacing and resolved outer/inner COC loops |
145
145
  | `SYML` | `Symbol` | three ordered, resolved graphic components |
146
146
  | `PSTAT`, `ASSP` | specialized property types | part status and strictly decoded associated strings |
147
- | `DTA`, `DTF`, `DDA`, `DLA`, `DAF` | dimension property subclasses | fonts or typed numeric tables; unverified enumerations remain ordered values |
147
+ | `DTA` | `DimensionTextAttributeProperty` | fonts, `size` (character height, or a factor of the main text when `relative_size` is true); the other numeric values remain ordered values |
148
+ | `DTF`, `DDA`, `DLA`, `DAF` | dimension property subclasses | typed numeric tables; unverified enumerations remain ordered values |
148
149
  | `HAPP` | `HatchPatternProperty` | ordered offset/distance/angle/color/linetype sub-patterns |
149
150
  | `ASSE` | `Assembly` | property IDs, definition part, child instances, 3x3 transforms |
150
151
  | other addressable records | `UnsupportedEntity` | ID, ownership, and complete raw record |
@@ -215,6 +215,38 @@ Phase 5 では、正式な field 名が得られていない部分を raw bytes
215
215
  - `ASSE` の可変 property prefix、子 assembly ID、member IDs、serialized 3x3 transform、part 対応を復元した。製品サンプルの 25 parts / 24 instances は単一 root に解決され、`DOCU_SHEET` association から sheet part 1 件を同定した。
216
216
  - 自作 fixture は root → 2 sheets → shared leaf という構造を持ち、nested/shared part、異なる instance transform、multiple sheets を regression test にする。
217
217
 
218
+ ### 5.2 寸法の文字の大きさ(DTA)と文字の枠
219
+
220
+ 寸法レコード(`DANG` / `DCHMF` / `DDIA` / `DRAD` / `DSGL`)の、文字の位置から測定値までの 13 欄を、
221
+ 製品サンプル(MI 3.40、寸法 46 個・公差 10 個)で突き合わせた。field 名の一次資料は得られていないので、
222
+ 下は観測された規則である。MI 2.40〜2.80 のファイルでも欄の並びは同じだった。
223
+
224
+ | 位置(文字の位置 x を 0 として) | 内容 | 根拠(製品サンプル) |
225
+ |---|---|---|
226
+ | 0, 1 | 文字の位置 | 既存の解釈。下の 2 つのベクトルの枠の中心にあたる |
227
+ | 2, 3 | 文字の枠の、文字の向きのベクトル(長さ = 枠の幅) | 46 個すべてで次のベクトルと直交 |
228
+ | 4, 5 | 文字の枠の、文字の高さ方向のベクトル(長さ = 枠の高さ) | 公差の無い 36 個中 35 個で、長さが DTA の大きさと一致 |
229
+ | 9 | DDA の pointer | 既存の解釈 |
230
+ | 11 | DTF の pointer | 既存の解釈 |
231
+ | 12 | **DTA の pointer(主の文字の文字属性)** | 46 個すべてで DTA レコードの ID |
232
+ | 13 | 測定値 | 既存の解釈 |
233
+
234
+ `DTA` の数値は、フォント 3 つの後ろが `[0, 相対の印, 大きさ, 比, 色, …]` の順に並ぶ。
235
+
236
+ - 相対の印が 0 のとき、大きさは図面の単位の文字高。寸法の主の文字が指す DTA は 46 個すべてこの形
237
+ - 相対の印が 1 のとき、大きさは 1 や 0.6 といった倍率。公差の文字に使われ、公差 2 行の間隔が
238
+ 「主の文字高 × 倍率 × 1.5」に一致する(主 0.03・倍率 0.6 で間隔 0.027)
239
+ - 枠の高さは、公差を重ねた寸法で文字高の 1.5〜3 倍になる。枠は中身の外接であって文字高ではないので、
240
+ 文字高は DTA から取る
241
+
242
+ `DTV` の最後の欄は、これまで「文字の基準点の位置 1〜9」と読んでいたが、10 個すべてで DTA レコードの ID
243
+ だった(公差の文字の文字属性。倍率 0.6 が 7 個、主の文字と同じ文字高が 3 個)。DTA の ID は property の
244
+ 先頭に並ぶので 9 以下に収まりやすく、範囲の検査を通っていた。1〜9 の検査は外し、`text_attribute_id` として
245
+ 公開する。`alignment` は同じ値を返す旧名として残す。
246
+
247
+ 測定値より後ろ(矢印・寸法線・寸法補助線の座標と DAF / DLA の pointer が、文字の位置を原点にした
248
+ 局所座標で並ぶ)は未解釈のまま `values` に残している。
249
+
218
250
  各 Phase 5 record family には正常 fixture と短縮・破損 fixture があり、破損時も `UnsupportedEntity.raw_record` から payload を取得できる。つまり typed decoder の失敗によって addressable record を黙って捨てない。
219
251
 
220
252
  このサンプルは bundle 内の製品生成圧縮 MI であり、別名保存した standalone `.bi` ではない。したがって現実装が保証する範囲は **gzip magic を持ち、展開後が MI text である入力** である。zlib wrapper、ZIP、UNIX `compress`、UNIX `pack` は signature を検出して unsupported error にし、未検証 decoder へフォールバックしない。同一図面を Drafting から standalone `.mi` / `.bi` へ保存する相互運用試験は引き続き必要である。
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ezmi2d"
3
- version = "0.2.2"
3
+ version = "0.2.3"
4
4
  description = "Lossless reader for PTC Creo Elements/Direct Drafting MI files powered by Rust"
5
5
  readme = "README.md"
6
6
  license = { file = "LICENSE" }
@@ -134,10 +134,36 @@ def audit(inputs: Sequence[Path]) -> dict[str, Any]:
134
134
  ] += 1
135
135
  dimension_stats["tolerance_counts"][len(entity.tolerance_ids)] += 1
136
136
  dimension_stats["decoded_text"][entity.formatted_text is not None] += 1
137
+ # Evidence for the text attribute pointer and the stored text box: the
138
+ # pointer names a DTA with an absolute size, the two extents are at a
139
+ # right angle, and a text without a tolerance is as high as its size.
140
+ dimension_stats["text_attribute_model"][type(entity.text_attribute).__name__] += 1
141
+ dimension_stats["text_height_present"][entity.text_height is not None] += 1
142
+ along, across = entity.text_extent, entity.text_up_extent
143
+ width = (along.x**2 + along.y**2) ** 0.5
144
+ height = (across.x**2 + across.y**2) ** 0.5
145
+ dimension_stats["text_box_right_angle"][
146
+ abs(along.x * across.x + along.y * across.y)
147
+ <= 1e-9 * max(width * height, 1e-300)
148
+ ] += 1
149
+ if entity.text_height is not None and not entity.tolerance_ids:
150
+ dimension_stats["plain_text_box_height_over_size"][
151
+ round(height / entity.text_height, 2)
152
+ ] += 1
137
153
  elif isinstance(entity, ezmi2d.DimensionTolerance):
138
154
  annotation_stats["dtv_decoded_text"][
139
155
  entity.upper_text is not None and entity.lower_text is not None
140
156
  ] += 1
157
+ annotation_stats["dtv_text_attribute_model"][
158
+ type(entity.text_attribute).__name__
159
+ ] += 1
160
+ attribute = entity.text_attribute
161
+ annotation_stats["dtv_text_size"][
162
+ (
163
+ getattr(attribute, "relative_size", None),
164
+ getattr(attribute, "size", None),
165
+ )
166
+ ] += 1
141
167
  elif isinstance(entity, ezmi2d.Leader):
142
168
  annotation_stats["leader_vertex_counts"][len(entity.vertices)] += 1
143
169
  elif isinstance(entity, ezmi2d.Contour):
@@ -78,14 +78,19 @@ def _platform(filename: str, version: str) -> str:
78
78
  prefix = f"ezmi2d-{version}-cp310-abi3-"
79
79
  if not filename.startswith(prefix) or not filename.endswith(".whl"):
80
80
  raise ValueError(f"wheel does not use the required cp310-abi3 tag: {filename}")
81
- tag = filename[len(prefix) : -4]
82
- if "manylinux" in tag and tag.endswith("x86_64"):
83
- return "linux-x86_64"
84
- if "manylinux" in tag and tag.endswith("aarch64"):
85
- return "linux-aarch64"
86
- if tag.startswith("macosx_") and tag.endswith("universal2"):
81
+ # A wheel can name several platform tags joined by "." (a compressed tag set). The build tool
82
+ # does not keep their order stable between releases, so every tag is looked at.
83
+ tags = filename[len(prefix) : -4].split(".")
84
+ if all(tag.startswith("manylinux") for tag in tags):
85
+ if all(tag.endswith("_x86_64") for tag in tags):
86
+ return "linux-x86_64"
87
+ if all(tag.endswith("_aarch64") for tag in tags):
88
+ return "linux-aarch64"
89
+ if all(tag.startswith("macosx_") for tag in tags) and any(
90
+ tag.endswith("_universal2") for tag in tags
91
+ ):
87
92
  return "macos-universal2"
88
- if tag == "win_amd64":
93
+ if tags == ["win_amd64"]:
89
94
  return "windows-x86_64"
90
95
  raise ValueError(f"wheel has an unsupported or non-portable platform tag: {filename}")
91
96
 
@@ -666,6 +666,10 @@ def _property_from_core(row: Mapping[str, Any], raw_records: tuple[Any, ...]) ->
666
666
  alternate_font_name_value=_text_from_core(_mapping(value["alternate_font_name"])),
667
667
  symbol_font_name_value=_text_from_core(_mapping(value["symbol_font_name"])),
668
668
  definition_values=tuple(float(item) for item in value["definition_values"]),
669
+ size=None if value["size"] is None else float(value["size"]),
670
+ relative_size=(
671
+ None if value["relative_size"] is None else bool(value["relative_size"])
672
+ ),
669
673
  )
670
674
  integer_definition = row["integer_definition"]
671
675
  if integer_definition is not None:
@@ -769,7 +773,8 @@ def _dimension_tolerance_from_core(
769
773
  lower_text_value=_text_from_core(_mapping(row["lower_text"])),
770
774
  text_style_id=text_style_id,
771
775
  text_style=propertydb.get(text_style_id),
772
- alignment=int(row["alignment"]),
776
+ text_attribute_id=int(row["text_attribute_id"]),
777
+ text_attribute=propertydb.get(int(row["text_attribute_id"])),
773
778
  )
774
779
 
775
780
 
@@ -808,6 +813,7 @@ def _dimension_from_core(
808
813
  None if row["dimension_style_id"] is None else int(row["dimension_style_id"])
809
814
  )
810
815
  text_style_id = None if row["text_style_id"] is None else int(row["text_style_id"])
816
+ text_attribute_id = None if row["text_attribute_id"] is None else int(row["text_attribute_id"])
811
817
  tolerance_ids = tuple(int(value) for value in row["tolerance_ids"])
812
818
  return Dimension(
813
819
  **_base_fields(row, raw_records),
@@ -833,6 +839,10 @@ def _dimension_from_core(
833
839
  text_style=None if text_style_id is None else propertydb.get(text_style_id),
834
840
  tolerance_ids=tolerance_ids,
835
841
  tolerances=tuple(tolerancedb.get(entity_id) for entity_id in tolerance_ids),
842
+ text_attribute_id=text_attribute_id,
843
+ text_attribute=(None if text_attribute_id is None else propertydb.get(text_attribute_id)),
844
+ text_extent=_vec_from_core(_mapping(row["text_extent"])),
845
+ text_up_extent=_vec_from_core(_mapping(row["text_up_extent"])),
836
846
  )
837
847
 
838
848
 
@@ -187,12 +187,21 @@ class AssociatedStringsProperty(Property):
187
187
 
188
188
  @dataclass(frozen=True, slots=True)
189
189
  class DimensionTextAttributeProperty(Property):
190
- """DTA font fields plus version-specific numeric definition values."""
190
+ """DTA text attribute of a dimension or tolerance text: fonts and text size.
191
+
192
+ ``size`` is the third numeric value: the character height in drawing units, or,
193
+ when ``relative_size`` is true (the second numeric value is 1), a factor of the
194
+ main text of the dimension (0.6 for a tolerance at 60 %). Both are ``None`` when
195
+ the record does not state them. The other numeric values stay in
196
+ ``definition_values``; their meanings vary by MI version.
197
+ """
191
198
 
192
199
  font_name_value: TextValue
193
200
  alternate_font_name_value: TextValue
194
201
  symbol_font_name_value: TextValue
195
202
  definition_values: tuple[float, ...]
203
+ size: float | None = None
204
+ relative_size: bool | None = None
196
205
 
197
206
  @property
198
207
  def font_name(self) -> str | None:
@@ -592,6 +601,14 @@ class Dimension(StructuredEntity):
592
601
  text_style: Property | None
593
602
  tolerance_ids: tuple[int, ...]
594
603
  tolerances: tuple[DimensionTolerance | None, ...]
604
+ #: Pointer to the DTA text attribute (fonts and size) of the main text.
605
+ text_attribute_id: int | None = None
606
+ text_attribute: Property | None = None
607
+ #: Extent of the stored text box along the text (direction of the text, length =
608
+ #: width of the box, tolerances included) and across it (length = height of the
609
+ #: box). The text position is the middle of the box.
610
+ text_extent: Vec2 = Vec2(0.0, 0.0)
611
+ text_up_extent: Vec2 = Vec2(0.0, 0.0)
595
612
 
596
613
  @property
597
614
  def formatted_text(self) -> str | None:
@@ -601,6 +618,31 @@ class Dimension(StructuredEntity):
601
618
  def formatted_text_bytes(self) -> bytes:
602
619
  return self.formatted_text_value.raw_bytes
603
620
 
621
+ @property
622
+ def text_height(self) -> float | None:
623
+ """Character height of the main text in drawing units.
624
+
625
+ The size of the DTA text attribute the dimension points to. ``None`` when the
626
+ dimension names no such attribute or the attribute states a factor instead of
627
+ a length.
628
+ """
629
+ attribute = self.text_attribute
630
+ if not isinstance(attribute, DimensionTextAttributeProperty):
631
+ return None
632
+ if attribute.size is None or attribute.relative_size is not False:
633
+ return None
634
+ return attribute.size
635
+
636
+ @property
637
+ def text_rotation(self) -> float | None:
638
+ """Direction of the text in radians, from the stored text box.
639
+
640
+ ``None`` when the box has no extent along the text.
641
+ """
642
+ if self.text_extent.x == 0.0 and self.text_extent.y == 0.0:
643
+ return None
644
+ return math.atan2(self.text_extent.y, self.text_extent.x)
645
+
604
646
 
605
647
  @dataclass(frozen=True, slots=True)
606
648
  class DimensionTolerance(StructuredEntity):
@@ -612,7 +654,10 @@ class DimensionTolerance(StructuredEntity):
612
654
  lower_text_value: TextValue
613
655
  text_style_id: int
614
656
  text_style: Property | None
615
- alignment: int
657
+ #: Pointer to the DTA text attribute (fonts and size) of the tolerance text: the
658
+ #: last field of the record.
659
+ text_attribute_id: int
660
+ text_attribute: Property | None = None
616
661
 
617
662
  @property
618
663
  def upper_text(self) -> str | None:
@@ -623,12 +668,28 @@ class DimensionTolerance(StructuredEntity):
623
668
  return self.lower_text_value.text
624
669
 
625
670
  @property
626
- def horizontal_alignment(self) -> str:
627
- return ("left", "center", "right")[(self.alignment - 1) % 3]
671
+ def alignment(self) -> int:
672
+ """Deprecated: the last field of the record, which is ``text_attribute_id``.
628
673
 
629
- @property
630
- def vertical_alignment(self) -> str:
631
- return ("lower", "middle", "upper")[(self.alignment - 1) // 3]
674
+ Earlier versions read it as a text alignment code of 1 through 9. In every
675
+ tolerance of the corpus it is the ID of a DTA record.
676
+ """
677
+ return self.text_attribute_id
678
+
679
+ def text_height(self, main_text_height: float | None = None) -> float | None:
680
+ """Character height of the tolerance text in drawing units.
681
+
682
+ A text attribute with a relative size is a factor of the main text of the
683
+ dimension, passed as ``main_text_height``. ``None`` when it cannot be told.
684
+ """
685
+ attribute = self.text_attribute
686
+ if not isinstance(attribute, DimensionTextAttributeProperty) or attribute.size is None:
687
+ return None
688
+ if attribute.relative_size is False:
689
+ return attribute.size
690
+ if attribute.relative_size is True and main_text_height is not None:
691
+ return attribute.size * main_text_height
692
+ return None
632
693
 
633
694
 
634
695
  @dataclass(frozen=True, slots=True)
@@ -103,6 +103,34 @@ DTF
103
103
  4
104
104
  0
105
105
  |~
106
+ DTA
107
+ 9
108
+ 10
109
+ hp_block_v
110
+ hp_block_v
111
+ hp_symbols
112
+ 0
113
+ 0
114
+ 0.2
115
+ 1
116
+ 1
117
+ 0
118
+ 1
119
+ |~
120
+ DTA
121
+ 17
122
+ 10
123
+ hp_block_v
124
+ hp_block_v
125
+ hp_symbols
126
+ 0
127
+ 1
128
+ 0.6
129
+ 1
130
+ 1
131
+ 0
132
+ 1
133
+ |~
106
134
  #~42
107
135
  DTV
108
136
  30
@@ -113,7 +141,7 @@ DTV
113
141
  0.9990
114
142
  0.9985
115
143
  8
116
- 8
144
+ 17
117
145
  |~
118
146
  #~5
119
147
  ASSE
@@ -384,17 +412,17 @@ DANG
384
412
  0
385
413
  0.5
386
414
  0.5
415
+ 0.4
387
416
  0
388
417
  0
418
+ 0.2
389
419
  0
390
420
  0
391
421
  0
392
422
  0
393
423
  0
394
- 0
395
- 0
396
- 0
397
- 0
424
+ 8
425
+ 9
398
426
  1.5707963267948966
399
427
  90
400
428
  0
@@ -39,8 +39,16 @@ def test_semantic_audit_reports_raw_typed_and_evidence_fields() -> None:
39
39
  assert report["annotations"]["hatch_boundary_counts"] == {"1": 1}
40
40
  assert report["annotations"]["hatch_pattern_present"] == {"True": 1}
41
41
  assert report["annotations"]["symbol_component_counts"] == {"3": 1}
42
+ assert report["dimensions"]["text_attribute_model"] == {"DimensionTextAttributeProperty": 1}
43
+ assert report["dimensions"]["text_height_present"] == {"True": 1}
44
+ assert report["dimensions"]["text_box_right_angle"] == {"True": 1}
45
+ assert report["annotations"]["dtv_text_attribute_model"] == {
46
+ "DimensionTextAttributeProperty": 1
47
+ }
48
+ assert report["annotations"]["dtv_text_size"] == {"(True, 0.6)": 1}
42
49
  assert report["property_models"] == {
43
50
  "AssociatedStringsProperty": 1,
51
+ "DimensionTextAttributeProperty": 2,
44
52
  "DimensionTextFormatProperty": 1,
45
53
  "HatchPatternProperty": 1,
46
54
  "PartStatusProperty": 1,
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes