forked from 1b-agent/opencadstudio-upstream
Complete Dimension host model coverage for all nine subtypes
Adds a hand-written flat Dimension model to the adapter (manifest manual_kinds hook) and a synthetic-property section to the host coverage policy. The host derives actual_measurement and the base definition point on scripted create/edit. staged_python_dimension_lifecycle_over_real_ipc passes the full gate for every subtype including DWG and DXF reopen. Python ints are now accepted for coordinates and angles. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a86d5bc727
commit
6b4c86fd7a
13 files changed
+1281
-49
No files matched your search
@@ -21,6 +21,13 @@ use entity_coverage_schema::{
|
||||
EntityCoverageCatalog, EntityKindCoverage, EntityScope, ModelAccess, PropertyCoverage,
|
||||
};
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
struct SyntheticProperty {
|
||||
name: String,
|
||||
type_id: String,
|
||||
access: String,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
struct EntityCoveragePolicy {
|
||||
internal_kinds: Vec<String>,
|
||||
@@ -28,6 +35,10 @@ struct EntityCoveragePolicy {
|
||||
editable: BTreeMap<String, Vec<String>>,
|
||||
readable: BTreeMap<String, Vec<String>>,
|
||||
aliases: BTreeMap<String, BTreeMap<String, String>>,
|
||||
/// Properties for kinds whose payload is a nested enum (Dimension), where
|
||||
/// the traced variant has no single field list to map.
|
||||
#[serde(default)]
|
||||
synthetic: BTreeMap<String, Vec<SyntheticProperty>>,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -802,6 +813,19 @@ fn generate_entity_coverage(out_dir: &Path, registry: &TypeRegistry) {
|
||||
model_access: access,
|
||||
});
|
||||
}
|
||||
for synthetic in policy.synthetic.get(kind).into_iter().flatten() {
|
||||
let writable = synthetic.access == "read_write";
|
||||
properties.push(PropertyCoverage {
|
||||
name: synthetic.name.clone(),
|
||||
source_path: format!("<subtype>.{}", synthetic.name),
|
||||
type_id: synthetic.type_id.clone(),
|
||||
optional: false,
|
||||
is_sequence: false,
|
||||
snapshot_readable: true,
|
||||
validation: if writable { "transaction_geometry" } else { "none" }.into(),
|
||||
model_access: if writable { ModelAccess::ReadWrite } else { ModelAccess::ReadOnly },
|
||||
});
|
||||
}
|
||||
assert!(
|
||||
unresolved.is_empty(),
|
||||
"{kind} has coverage keys absent from registry: {unresolved:?}"
|
||||
|
||||
@@ -1,44 +1,526 @@
|
||||
{
|
||||
"internal_kinds": ["Block", "BlockEnd", "Seqend"],
|
||||
"opaque_kinds": ["Extended", "Unknown"],
|
||||
"internal_kinds": [
|
||||
"Block",
|
||||
"BlockEnd",
|
||||
"Seqend"
|
||||
],
|
||||
"opaque_kinds": [
|
||||
"Extended",
|
||||
"Unknown"
|
||||
],
|
||||
"editable": {
|
||||
"Point": ["layer", "location", "thickness", "normal", "x_axis_angle"],
|
||||
"Line": ["layer", "start", "end", "thickness", "normal"],
|
||||
"Circle": ["layer", "center", "radius", "thickness", "normal"],
|
||||
"Arc": ["layer", "center", "radius", "start_angle", "end_angle", "thickness", "normal"],
|
||||
"Ellipse": ["layer", "center", "major_axis", "minor_axis_ratio", "start_parameter", "end_parameter", "normal"],
|
||||
"Polyline": ["layer", "closed", "vertices"],
|
||||
"Polyline2D": ["layer", "closed", "smooth_surface", "start_width", "end_width", "thickness", "elevation", "normal", "vertices"],
|
||||
"Polyline3D": ["layer", "flags", "default_start_width", "default_end_width", "mesh_m_count", "mesh_n_count", "smooth_m_density", "smooth_n_density", "elevation", "normal", "vertices"],
|
||||
"LwPolyline": ["layer", "vertices", "is_closed", "plinegen", "constant_width", "elevation", "thickness", "normal"],
|
||||
"Spline": ["layer", "degree", "flags", "knots", "control_points", "weights", "fit_points", "normal", "knot_tolerance", "control_tolerance", "fit_tolerance", "begin_tangent", "end_tangent", "knot_parameterization", "cv_frame_visible", "dwg_flags1", "dxf_flags"],
|
||||
"Text": ["layer", "text", "insertion", "alignment_point", "height", "rotation", "width_factor", "oblique_angle", "style", "horizontal_alignment", "vertical_alignment", "normal", "thickness", "generation_flags"],
|
||||
"MText": ["layer", "text", "insertion", "height", "rectangle_width", "rectangle_height", "rotation", "dwg_x_direction", "style", "attachment_point", "drawing_direction", "line_spacing_factor", "line_spacing_style", "normal", "background_fill_flags", "background_scale", "background_transparency", "is_annotative", "column_data", "extents_width", "extents_height"],
|
||||
"Ray": ["layer", "base_point", "direction"],
|
||||
"XLine": ["layer", "base_point", "direction"],
|
||||
"Solid": ["layer", "first_corner", "second_corner", "third_corner", "fourth_corner", "normal", "thickness", "is_trace"],
|
||||
"Face3D": ["layer", "first_corner", "second_corner", "third_corner", "fourth_corner", "invisible_edges"],
|
||||
"Insert": ["layer", "insert_point", "x_scale", "y_scale", "z_scale", "rotation", "normal", "column_count", "row_count", "column_spacing", "row_spacing"],
|
||||
"Tolerance": ["layer", "insertion_point", "direction", "normal", "text", "dimension_style_name", "text_height", "dimension_gap"],
|
||||
"Shape": ["layer", "insertion_point", "size", "shape_name", "shape_number", "rotation", "relative_x_scale", "oblique_angle", "normal", "thickness", "style_name"],
|
||||
"AttributeDefinition": ["layer", "tag", "prompt", "default_value", "insertion_point", "alignment_point", "height", "rotation", "width_factor", "oblique_angle", "text_style", "text_generation_flags", "horizontal_alignment", "vertical_alignment", "flags", "field_length", "normal", "mtext_flag", "is_multiline", "line_count", "lock_position"],
|
||||
"AttributeEntity": ["layer", "tag", "value", "insertion_point", "alignment_point", "height", "rotation", "width_factor", "oblique_angle", "text_style", "text_generation_flags", "horizontal_alignment", "vertical_alignment", "flags", "field_length", "normal", "mtext_flag", "is_multiline", "line_count", "lock_position"],
|
||||
"Hatch": ["layer", "elevation", "normal", "is_solid", "pattern", "pattern_angle", "pattern_scale", "pattern_type", "is_double", "style", "is_associative", "pixel_size", "paths", "seed_points"],
|
||||
"Leader": ["layer", "dimension_style", "arrow_enabled", "path_type", "creation_type", "hookline_direction", "hookline_enabled", "text_height", "text_width", "vertices", "annotation_handle", "normal", "horizontal_direction", "block_offset", "annotation_offset"],
|
||||
"MLine": ["layer", "flags", "justification", "normal", "scale_factor", "style_name", "vertices"]
|
||||
"Point": [
|
||||
"layer",
|
||||
"location",
|
||||
"thickness",
|
||||
"normal",
|
||||
"x_axis_angle"
|
||||
],
|
||||
"Line": [
|
||||
"layer",
|
||||
"start",
|
||||
"end",
|
||||
"thickness",
|
||||
"normal"
|
||||
],
|
||||
"Circle": [
|
||||
"layer",
|
||||
"center",
|
||||
"radius",
|
||||
"thickness",
|
||||
"normal"
|
||||
],
|
||||
"Arc": [
|
||||
"layer",
|
||||
"center",
|
||||
"radius",
|
||||
"start_angle",
|
||||
"end_angle",
|
||||
"thickness",
|
||||
"normal"
|
||||
],
|
||||
"Ellipse": [
|
||||
"layer",
|
||||
"center",
|
||||
"major_axis",
|
||||
"minor_axis_ratio",
|
||||
"start_parameter",
|
||||
"end_parameter",
|
||||
"normal"
|
||||
],
|
||||
"Polyline": [
|
||||
"layer",
|
||||
"closed",
|
||||
"vertices"
|
||||
],
|
||||
"Polyline2D": [
|
||||
"layer",
|
||||
"closed",
|
||||
"smooth_surface",
|
||||
"start_width",
|
||||
"end_width",
|
||||
"thickness",
|
||||
"elevation",
|
||||
"normal",
|
||||
"vertices"
|
||||
],
|
||||
"Polyline3D": [
|
||||
"layer",
|
||||
"flags",
|
||||
"default_start_width",
|
||||
"default_end_width",
|
||||
"mesh_m_count",
|
||||
"mesh_n_count",
|
||||
"smooth_m_density",
|
||||
"smooth_n_density",
|
||||
"elevation",
|
||||
"normal",
|
||||
"vertices"
|
||||
],
|
||||
"LwPolyline": [
|
||||
"layer",
|
||||
"vertices",
|
||||
"is_closed",
|
||||
"plinegen",
|
||||
"constant_width",
|
||||
"elevation",
|
||||
"thickness",
|
||||
"normal"
|
||||
],
|
||||
"Spline": [
|
||||
"layer",
|
||||
"degree",
|
||||
"flags",
|
||||
"knots",
|
||||
"control_points",
|
||||
"weights",
|
||||
"fit_points",
|
||||
"normal",
|
||||
"knot_tolerance",
|
||||
"control_tolerance",
|
||||
"fit_tolerance",
|
||||
"begin_tangent",
|
||||
"end_tangent",
|
||||
"knot_parameterization",
|
||||
"cv_frame_visible",
|
||||
"dwg_flags1",
|
||||
"dxf_flags"
|
||||
],
|
||||
"Text": [
|
||||
"layer",
|
||||
"text",
|
||||
"insertion",
|
||||
"alignment_point",
|
||||
"height",
|
||||
"rotation",
|
||||
"width_factor",
|
||||
"oblique_angle",
|
||||
"style",
|
||||
"horizontal_alignment",
|
||||
"vertical_alignment",
|
||||
"normal",
|
||||
"thickness",
|
||||
"generation_flags"
|
||||
],
|
||||
"MText": [
|
||||
"layer",
|
||||
"text",
|
||||
"insertion",
|
||||
"height",
|
||||
"rectangle_width",
|
||||
"rectangle_height",
|
||||
"rotation",
|
||||
"dwg_x_direction",
|
||||
"style",
|
||||
"attachment_point",
|
||||
"drawing_direction",
|
||||
"line_spacing_factor",
|
||||
"line_spacing_style",
|
||||
"normal",
|
||||
"background_fill_flags",
|
||||
"background_scale",
|
||||
"background_transparency",
|
||||
"is_annotative",
|
||||
"column_data",
|
||||
"extents_width",
|
||||
"extents_height"
|
||||
],
|
||||
"Ray": [
|
||||
"layer",
|
||||
"base_point",
|
||||
"direction"
|
||||
],
|
||||
"XLine": [
|
||||
"layer",
|
||||
"base_point",
|
||||
"direction"
|
||||
],
|
||||
"Solid": [
|
||||
"layer",
|
||||
"first_corner",
|
||||
"second_corner",
|
||||
"third_corner",
|
||||
"fourth_corner",
|
||||
"normal",
|
||||
"thickness",
|
||||
"is_trace"
|
||||
],
|
||||
"Face3D": [
|
||||
"layer",
|
||||
"first_corner",
|
||||
"second_corner",
|
||||
"third_corner",
|
||||
"fourth_corner",
|
||||
"invisible_edges"
|
||||
],
|
||||
"Insert": [
|
||||
"layer",
|
||||
"insert_point",
|
||||
"x_scale",
|
||||
"y_scale",
|
||||
"z_scale",
|
||||
"rotation",
|
||||
"normal",
|
||||
"column_count",
|
||||
"row_count",
|
||||
"column_spacing",
|
||||
"row_spacing"
|
||||
],
|
||||
"Tolerance": [
|
||||
"layer",
|
||||
"insertion_point",
|
||||
"direction",
|
||||
"normal",
|
||||
"text",
|
||||
"dimension_style_name",
|
||||
"text_height",
|
||||
"dimension_gap"
|
||||
],
|
||||
"Shape": [
|
||||
"layer",
|
||||
"insertion_point",
|
||||
"size",
|
||||
"shape_name",
|
||||
"shape_number",
|
||||
"rotation",
|
||||
"relative_x_scale",
|
||||
"oblique_angle",
|
||||
"normal",
|
||||
"thickness",
|
||||
"style_name"
|
||||
],
|
||||
"AttributeDefinition": [
|
||||
"layer",
|
||||
"tag",
|
||||
"prompt",
|
||||
"default_value",
|
||||
"insertion_point",
|
||||
"alignment_point",
|
||||
"height",
|
||||
"rotation",
|
||||
"width_factor",
|
||||
"oblique_angle",
|
||||
"text_style",
|
||||
"text_generation_flags",
|
||||
"horizontal_alignment",
|
||||
"vertical_alignment",
|
||||
"flags",
|
||||
"field_length",
|
||||
"normal",
|
||||
"mtext_flag",
|
||||
"is_multiline",
|
||||
"line_count",
|
||||
"lock_position"
|
||||
],
|
||||
"AttributeEntity": [
|
||||
"layer",
|
||||
"tag",
|
||||
"value",
|
||||
"insertion_point",
|
||||
"alignment_point",
|
||||
"height",
|
||||
"rotation",
|
||||
"width_factor",
|
||||
"oblique_angle",
|
||||
"text_style",
|
||||
"text_generation_flags",
|
||||
"horizontal_alignment",
|
||||
"vertical_alignment",
|
||||
"flags",
|
||||
"field_length",
|
||||
"normal",
|
||||
"mtext_flag",
|
||||
"is_multiline",
|
||||
"line_count",
|
||||
"lock_position"
|
||||
],
|
||||
"Hatch": [
|
||||
"layer",
|
||||
"elevation",
|
||||
"normal",
|
||||
"is_solid",
|
||||
"pattern",
|
||||
"pattern_angle",
|
||||
"pattern_scale",
|
||||
"pattern_type",
|
||||
"is_double",
|
||||
"style",
|
||||
"is_associative",
|
||||
"pixel_size",
|
||||
"paths",
|
||||
"seed_points"
|
||||
],
|
||||
"Leader": [
|
||||
"layer",
|
||||
"dimension_style",
|
||||
"arrow_enabled",
|
||||
"path_type",
|
||||
"creation_type",
|
||||
"hookline_direction",
|
||||
"hookline_enabled",
|
||||
"text_height",
|
||||
"text_width",
|
||||
"vertices",
|
||||
"annotation_handle",
|
||||
"normal",
|
||||
"horizontal_direction",
|
||||
"block_offset",
|
||||
"annotation_offset"
|
||||
],
|
||||
"MLine": [
|
||||
"layer",
|
||||
"flags",
|
||||
"justification",
|
||||
"normal",
|
||||
"scale_factor",
|
||||
"style_name",
|
||||
"vertices"
|
||||
]
|
||||
},
|
||||
"readable": {
|
||||
"Insert": ["block_name"],
|
||||
"Tolerance": ["dimension_style_handle"],
|
||||
"Shape": ["style_handle"],
|
||||
"MLine": ["start_point", "style_handle", "style_element_count"],
|
||||
"Leader": ["origin", "dimension_gap", "arrowhead_type", "arrow_size", "byblock_color"],
|
||||
"AttributeEntity": ["attdef_handle"]
|
||||
"Insert": [
|
||||
"block_name"
|
||||
],
|
||||
"Tolerance": [
|
||||
"dimension_style_handle"
|
||||
],
|
||||
"Shape": [
|
||||
"style_handle"
|
||||
],
|
||||
"MLine": [
|
||||
"start_point",
|
||||
"style_handle",
|
||||
"style_element_count"
|
||||
],
|
||||
"Leader": [
|
||||
"origin",
|
||||
"dimension_gap",
|
||||
"arrowhead_type",
|
||||
"arrow_size",
|
||||
"byblock_color"
|
||||
],
|
||||
"AttributeEntity": [
|
||||
"attdef_handle"
|
||||
]
|
||||
},
|
||||
"aliases": {
|
||||
"Polyline": {"closed": "flags"},
|
||||
"Polyline2D": {"closed": "flags"},
|
||||
"Text": {"text": "value", "insertion": "insertion_point"},
|
||||
"MText": {"text": "value", "insertion": "insertion_point"}
|
||||
"Polyline": {
|
||||
"closed": "flags"
|
||||
},
|
||||
"Polyline2D": {
|
||||
"closed": "flags"
|
||||
},
|
||||
"Text": {
|
||||
"text": "value",
|
||||
"insertion": "insertion_point"
|
||||
},
|
||||
"MText": {
|
||||
"text": "value",
|
||||
"insertion": "insertion_point"
|
||||
}
|
||||
},
|
||||
"synthetic": {
|
||||
"Dimension": [
|
||||
{
|
||||
"name": "subtype",
|
||||
"type_id": "String",
|
||||
"access": "read_only"
|
||||
},
|
||||
{
|
||||
"name": "actual_measurement",
|
||||
"type_id": "f64",
|
||||
"access": "read_only"
|
||||
},
|
||||
{
|
||||
"name": "text",
|
||||
"type_id": "String",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "style_name",
|
||||
"type_id": "String",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "normal",
|
||||
"type_id": "Vector3",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "text_middle_point",
|
||||
"type_id": "Vector3",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "attachment_point",
|
||||
"type_id": "AttachmentPointType",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "text_rotation",
|
||||
"type_id": "f64",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "horizontal_direction",
|
||||
"type_id": "f64",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "flip_arrow1",
|
||||
"type_id": "bool",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "flip_arrow2",
|
||||
"type_id": "bool",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "text_user_positioned",
|
||||
"type_id": "bool",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "definition_point",
|
||||
"type_id": "Vector3",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "first_point",
|
||||
"type_id": "Vector3",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "second_point",
|
||||
"type_id": "Vector3",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "angle_vertex",
|
||||
"type_id": "Vector3",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "dimension_arc",
|
||||
"type_id": "Vector3",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "feature_location",
|
||||
"type_id": "Vector3",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "leader_endpoint",
|
||||
"type_id": "Vector3",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "first_extension_point",
|
||||
"type_id": "Vector3",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "second_extension_point",
|
||||
"type_id": "Vector3",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "center_point",
|
||||
"type_id": "Vector3",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "first_leader_point",
|
||||
"type_id": "Vector3",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "second_leader_point",
|
||||
"type_id": "Vector3",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "chord_point",
|
||||
"type_id": "Vector3",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "override_center",
|
||||
"type_id": "Vector3",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "jog_point",
|
||||
"type_id": "Vector3",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "rotation",
|
||||
"type_id": "f64",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "ext_line_rotation",
|
||||
"type_id": "f64",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "leader_length",
|
||||
"type_id": "f64",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "arc_start_parameter",
|
||||
"type_id": "f64",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "arc_end_parameter",
|
||||
"type_id": "f64",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "jog_angle",
|
||||
"type_id": "f64",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "is_ordinate_type_x",
|
||||
"type_id": "bool",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "is_partial",
|
||||
"type_id": "bool",
|
||||
"access": "read_write"
|
||||
},
|
||||
{
|
||||
"name": "has_leader",
|
||||
"type_id": "bool",
|
||||
"access": "read_write"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -377,6 +377,94 @@ fn validate_mline(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Field checks for every Dimension subtype. Derived fields (base definition
|
||||
/// point, `actual_measurement`) are recomputed by the host, so they are not
|
||||
/// validated as inputs; the measurement the geometry implies must be finite.
|
||||
#[cfg(feature = "host")]
|
||||
fn validate_dimension(
|
||||
old: Option<&crate::host::acadrust::entities::Dimension>,
|
||||
new: &crate::host::acadrust::entities::Dimension,
|
||||
) -> Result<(), String> {
|
||||
use crate::host::acadrust::entities::Dimension as D;
|
||||
if old == Some(new) {
|
||||
return Ok(());
|
||||
}
|
||||
let base = new.base();
|
||||
solid_normal("Dimension.normal", &base.normal)?;
|
||||
finite_vector("Dimension.text_middle_point", &base.text_middle_point)?;
|
||||
if !base.text_rotation.is_finite() || !base.horizontal_direction.is_finite() {
|
||||
return Err("Dimension.text_rotation and horizontal_direction must be finite".into());
|
||||
}
|
||||
if base.style_name.trim().is_empty() {
|
||||
return Err("Dimension.style_name is empty".into());
|
||||
}
|
||||
let (points, scalars, distinct): (Vec<(&str, &crate::host::acadrust::types::Vector3)>, Vec<(&str, f64)>, Vec<(&str, &str)>) = match new {
|
||||
D::Aligned(d) => (
|
||||
vec![("definition_point", &d.definition_point), ("first_point", &d.first_point), ("second_point", &d.second_point)],
|
||||
vec![("ext_line_rotation", d.ext_line_rotation)],
|
||||
vec![("first_point", "second_point")],
|
||||
),
|
||||
D::Linear(d) => (
|
||||
vec![("definition_point", &d.definition_point), ("first_point", &d.first_point), ("second_point", &d.second_point)],
|
||||
vec![("rotation", d.rotation), ("ext_line_rotation", d.ext_line_rotation)],
|
||||
vec![("first_point", "second_point")],
|
||||
),
|
||||
D::Radius(d) => (
|
||||
vec![("definition_point", &d.definition_point), ("angle_vertex", &d.angle_vertex)],
|
||||
vec![("leader_length", d.leader_length)],
|
||||
vec![("definition_point", "angle_vertex")],
|
||||
),
|
||||
D::Diameter(d) => (
|
||||
vec![("definition_point", &d.definition_point), ("angle_vertex", &d.angle_vertex)],
|
||||
vec![("leader_length", d.leader_length)],
|
||||
vec![("definition_point", "angle_vertex")],
|
||||
),
|
||||
D::Angular2Ln(d) => (
|
||||
vec![("definition_point", &d.definition_point), ("dimension_arc", &d.dimension_arc), ("first_point", &d.first_point), ("second_point", &d.second_point), ("angle_vertex", &d.angle_vertex)],
|
||||
vec![],
|
||||
vec![],
|
||||
),
|
||||
D::Angular3Pt(d) => (
|
||||
vec![("definition_point", &d.definition_point), ("first_point", &d.first_point), ("second_point", &d.second_point), ("angle_vertex", &d.angle_vertex)],
|
||||
vec![],
|
||||
vec![("first_point", "angle_vertex"), ("second_point", "angle_vertex")],
|
||||
),
|
||||
D::Ordinate(d) => (
|
||||
vec![("definition_point", &d.definition_point), ("feature_location", &d.feature_location), ("leader_endpoint", &d.leader_endpoint)],
|
||||
vec![],
|
||||
vec![],
|
||||
),
|
||||
D::Arc(d) => (
|
||||
vec![("definition_point", &d.definition_point), ("first_extension_point", &d.first_extension_point), ("second_extension_point", &d.second_extension_point), ("center_point", &d.center_point), ("first_leader_point", &d.first_leader_point), ("second_leader_point", &d.second_leader_point)],
|
||||
vec![("arc_start_parameter", d.arc_start_parameter), ("arc_end_parameter", d.arc_end_parameter)],
|
||||
vec![("first_extension_point", "second_extension_point")],
|
||||
),
|
||||
D::LargeRadial(d) => (
|
||||
vec![("definition_point", &d.definition_point), ("chord_point", &d.chord_point), ("override_center", &d.override_center), ("jog_point", &d.jog_point)],
|
||||
vec![("jog_angle", d.jog_angle)],
|
||||
vec![("definition_point", "chord_point")],
|
||||
),
|
||||
};
|
||||
for (name, point) in &points {
|
||||
finite_vector(&format!("Dimension.{name}"), point)?;
|
||||
}
|
||||
for (name, value) in &scalars {
|
||||
if !value.is_finite() {
|
||||
return Err(format!("Dimension.{name} must be finite"));
|
||||
}
|
||||
}
|
||||
let find = |name: &str| points.iter().find(|(n, _)| *n == name).map(|(_, p)| **p);
|
||||
for (a, b) in distinct {
|
||||
if find(a) == find(b) {
|
||||
return Err(format!("Dimension.{a} and {b} must not coincide"));
|
||||
}
|
||||
}
|
||||
if !new.measurement().is_finite() {
|
||||
return Err("Dimension geometry does not define a finite measurement".into());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Validate newly created geometry for the kinds whose mapped fields have
|
||||
/// host checks. Called by the Python add path before an entity enters the document.
|
||||
#[cfg(feature = "host")]
|
||||
@@ -470,6 +558,7 @@ pub fn validate_new_canvas_entity(entity: &crate::host::EntityType) -> Result<()
|
||||
}
|
||||
EntityType::Leader(value) => validate_leader(None, value)?,
|
||||
EntityType::MLine(value) => validate_mline(None, value)?,
|
||||
EntityType::Dimension(value) => validate_dimension(None, value)?,
|
||||
EntityType::AttributeDefinition(value) => {
|
||||
finite_vector(
|
||||
"AttributeDefinition.insertion_point",
|
||||
@@ -824,6 +913,7 @@ pub fn validate_entity_mutation(
|
||||
return Err("Shape.style_handle is read-only".into());
|
||||
}
|
||||
}
|
||||
(EntityType::Dimension(old), EntityType::Dimension(new)) => validate_dimension(Some(old), new)?,
|
||||
(EntityType::MLine(old), EntityType::MLine(new)) => validate_mline(Some(old), new)?,
|
||||
(EntityType::Leader(old), EntityType::Leader(new)) => validate_leader(Some(old), new)?,
|
||||
(EntityType::AttributeDefinition(old), EntityType::AttributeDefinition(new)) => {
|
||||
@@ -1087,6 +1177,12 @@ pub fn validate_canvas_entity_references(
|
||||
return Err(format!("Shape text style {:?} has no SHX file", style.name));
|
||||
}
|
||||
}
|
||||
if let EntityType::Dimension(value) = entity {
|
||||
let name = value.base().style_name.trim();
|
||||
if !document.dim_styles.iter().any(|style| style.name.eq_ignore_ascii_case(name)) {
|
||||
return Err(format!("Dimension style {:?} does not exist", value.base().style_name));
|
||||
}
|
||||
}
|
||||
if let EntityType::MLine(value) = entity {
|
||||
let style = resolve_mline_style(document, value).ok_or_else(|| {
|
||||
format!("MLine style {:?} does not exist", value.style_name)
|
||||
@@ -1443,6 +1539,7 @@ mod tests {
|
||||
| "Hatch"
|
||||
| "Leader"
|
||||
| "MLine"
|
||||
| "Dimension"
|
||||
)
|
||||
{
|
||||
assert!(
|
||||
@@ -1597,6 +1694,40 @@ mod tests {
|
||||
"MLine.scale_factor".to_owned(),
|
||||
"MLine.style_name".to_owned(),
|
||||
"MLine.vertices".to_owned(),
|
||||
"Dimension.text".to_owned(),
|
||||
"Dimension.style_name".to_owned(),
|
||||
"Dimension.normal".to_owned(),
|
||||
"Dimension.text_middle_point".to_owned(),
|
||||
"Dimension.attachment_point".to_owned(),
|
||||
"Dimension.text_rotation".to_owned(),
|
||||
"Dimension.horizontal_direction".to_owned(),
|
||||
"Dimension.flip_arrow1".to_owned(),
|
||||
"Dimension.flip_arrow2".to_owned(),
|
||||
"Dimension.text_user_positioned".to_owned(),
|
||||
"Dimension.definition_point".to_owned(),
|
||||
"Dimension.first_point".to_owned(),
|
||||
"Dimension.second_point".to_owned(),
|
||||
"Dimension.angle_vertex".to_owned(),
|
||||
"Dimension.dimension_arc".to_owned(),
|
||||
"Dimension.feature_location".to_owned(),
|
||||
"Dimension.leader_endpoint".to_owned(),
|
||||
"Dimension.first_extension_point".to_owned(),
|
||||
"Dimension.second_extension_point".to_owned(),
|
||||
"Dimension.center_point".to_owned(),
|
||||
"Dimension.first_leader_point".to_owned(),
|
||||
"Dimension.second_leader_point".to_owned(),
|
||||
"Dimension.chord_point".to_owned(),
|
||||
"Dimension.override_center".to_owned(),
|
||||
"Dimension.jog_point".to_owned(),
|
||||
"Dimension.rotation".to_owned(),
|
||||
"Dimension.ext_line_rotation".to_owned(),
|
||||
"Dimension.leader_length".to_owned(),
|
||||
"Dimension.arc_start_parameter".to_owned(),
|
||||
"Dimension.arc_end_parameter".to_owned(),
|
||||
"Dimension.jog_angle".to_owned(),
|
||||
"Dimension.is_ordinate_type_x".to_owned(),
|
||||
"Dimension.is_partial".to_owned(),
|
||||
"Dimension.has_leader".to_owned(),
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user