Align dimension property editability

This commit is contained in:
ramox81 committed 2026-08-24 14:10:14 +03:00
1 parent f0d00c1d53
commit 9dc4e08f77
4 files changed
+105 -55

No files matched your search

+2 -19
View File
@@ -2409,18 +2409,7 @@ fn set_row_value(
/// The lineweight dropdown options (named defaults + the standard millimetre
/// steps), matching the labels `dim_lineweight_label` produces.
pub(crate) fn lineweight_options() -> Vec<String> {
let mut v = vec![
"ByLayer".to_string(),
"ByBlock".to_string(),
"Default".to_string(),
];
for lw in [
0, 5, 9, 13, 15, 18, 20, 25, 30, 35, 40, 50, 53, 60, 70, 80, 90, 100, 106, 120, 140, 158,
200, 211,
] {
v.push(format!("{:.2} mm", lw as f64 / 100.0));
}
v
crate::entities::common::lineweight_options()
}
/// Inverse of `dim_lineweight_label`: a lineweight label → DIMLWD enum value.
@@ -2546,13 +2535,7 @@ fn leader_arrow_label(
/// DIMLWD lineweight enum → label.
fn dim_lineweight_label(dimlwd: i16) -> String {
match dimlwd {
-1 => "ByLayer".to_string(),
-2 => "ByBlock".to_string(),
-3 => "Default".to_string(),
v if v >= 0 => format!("{:.2} mm", v as f64 / 100.0),
_ => "Default".to_string(),
}
crate::entities::common::lineweight_label(dimlwd)
}
/// Human-readable INSUNITS name (DXF group 70 unit codes).
+27
View File
@@ -573,6 +573,33 @@ pub fn edit_scalar_prop(label: &str, field: &'static str, value: f64) -> Propert
}
}
/// Standard lineweight choices shared by entity-specific Properties rows.
pub fn lineweight_options() -> Vec<String> {
let mut options = vec![
"ByLayer".to_string(),
"ByBlock".to_string(),
"Default".to_string(),
];
for value in [
0, 5, 9, 13, 15, 18, 20, 25, 30, 35, 40, 50, 53, 60, 70, 80, 90, 100, 106, 120,
140, 158, 200, 211,
] {
options.push(format!("{:.2} mm", value as f64 / 100.0));
}
options
}
/// DIMLWD/DIMLWE lineweight value displayed by a Properties dropdown.
pub fn lineweight_label(value: i16) -> String {
match value {
-1 => "ByLayer".to_string(),
-2 => "ByBlock".to_string(),
-3 => "Default".to_string(),
value if value >= 0 => format!("{:.2} mm", value as f64 / 100.0),
_ => "Default".to_string(),
}
}
pub fn ro_prop(label: &str, field: &'static str, value: impl Into<String>) -> Property {
Property {
label: label.into(),
+18 -12
View File
@@ -331,28 +331,34 @@ pub fn set_property(
) -> bool {
let trimmed = value.trim();
let handle_field = match field {
"dim_arrowhead_1" => Some((DIMBLK1, true)),
"dim_arrowhead_2" => Some((DIMBLK2, true)),
"dim_linetype" => Some((DIMLTYPE, false)),
"dim_ext_linetype_1" => Some((DIMLTEX1, false)),
"dim_ext_linetype_2" => Some((DIMLTEX2, false)),
"dim_arrowhead_1" => Some(DIMBLK1),
"dim_arrowhead_2" => Some(DIMBLK2),
"dim_linetype" => Some(DIMLTYPE),
"dim_ext_linetype_1" => Some(DIMLTEX1),
"dim_ext_linetype_2" => Some(DIMLTEX2),
"dim_text_style" => Some(DIMTXSTY),
_ => None,
};
if let Some((code, block)) = handle_field {
let resolved = if block {
(trimmed != "Closed filled")
if let Some(code) = handle_field {
let resolved = match field {
"dim_arrowhead_1" | "dim_arrowhead_2" => (trimmed != "Closed filled")
.then(|| {
doc.block_records
.iter()
.find(|record| record.name == trimmed)
.map(|record| record.handle)
})
.flatten()
} else {
doc.line_types
.flatten(),
"dim_text_style" => doc
.text_styles
.iter()
.find(|style| style.name == trimmed)
.map(|style| style.handle),
_ => doc
.line_types
.iter()
.find(|line_type| line_type.name == trimmed)
.map(|line_type| line_type.handle)
.map(|line_type| line_type.handle),
};
set(doc, handle, code, resolved.map(XDataValue::Handle));
return true;
+58 -24
View File
@@ -8,7 +8,8 @@ use glam::{DVec3, Vec3};
use crate::command::EntityTransform;
use crate::entities::common::{
center_grip, edit_angle_prop as edit_angle, edit_prop as edit, parse_f64, ro_prop as ro, square_grip,
center_grip, edit_angle_prop as edit_angle, edit_prop as edit, lineweight_label,
lineweight_options, parse_f64, ro_prop as ro, square_grip,
};
use crate::entities::traits::{Grippable, PropertyEditable, Transformable};
use crate::scene::model::object::{GripApply, GripDef, PropSection};
@@ -1461,39 +1462,22 @@ pub fn style_sections(
PropSection {
title: t!("Lines & Arrows").into_owned(),
props: vec![
ro(t!("Arrow size").as_ref(), "dim_arrow_size", f(s.dimasz)),
ro(
t!("Arrowhead 1").as_ref(),
t!("Arrow 1").as_ref(),
"dim_arrowhead_1",
block_name(document, s.dimblk1, &s.dimblk1_name),
),
ro(
t!("Arrowhead 2").as_ref(),
t!("Arrow 2").as_ref(),
"dim_arrowhead_2",
block_name(document, s.dimblk2, &s.dimblk2_name),
),
ro(
t!("Dimension linetype").as_ref(),
"dim_linetype",
linetype_name(document, s.dimltex_handle),
),
ro(
t!("Extension linetype 1").as_ref(),
"dim_ext_linetype_1",
linetype_name(document, s.dimltex1_handle),
),
ro(
t!("Extension linetype 2").as_ref(),
"dim_ext_linetype_2",
linetype_name(document, s.dimltex2_handle),
),
ro(t!("Dim line color").as_ref(), "dim_line_color", s.dimclrd.to_string()),
ro(t!("Arrow size").as_ref(), "dim_arrow_size", f(s.dimasz)),
ro(
t!("Dim line lineweight").as_ref(),
"dim_line_lineweight",
s.dimlwd.to_string(),
),
ro(t!("Ext line color").as_ref(), "dim_ext_line_color", s.dimclre.to_string()),
ro(
t!("Ext line lineweight").as_ref(),
"dim_ext_line_lineweight",
@@ -1501,17 +1485,34 @@ pub fn style_sections(
),
ro(t!("Dim line 1").as_ref(), "dim_line_1", onoff(!s.dimsd1)),
ro(t!("Dim line 2").as_ref(), "dim_line_2", onoff(!s.dimsd2)),
ro(t!("Dim line color").as_ref(), "dim_line_color", s.dimclrd.to_string()),
ro(
t!("Dim line linetype").as_ref(),
"dim_linetype",
linetype_name(document, s.dimltex_handle),
),
ro(t!("Dim line ext").as_ref(), "dim_line_ext", f(s.dimdle)),
ro(
t!("Ext line 1 linetype").as_ref(),
"dim_ext_linetype_1",
linetype_name(document, s.dimltex1_handle),
),
ro(
t!("Ext line 2 linetype").as_ref(),
"dim_ext_linetype_2",
linetype_name(document, s.dimltex2_handle),
),
ro(t!("Ext line 1").as_ref(), "dim_ext_line_1", onoff(!s.dimse1)),
ro(t!("Ext line 2").as_ref(), "dim_ext_line_2", onoff(!s.dimse2)),
ro(t!("Dim line ext").as_ref(), "dim_line_ext", f(s.dimdle)),
ro(t!("Ext line ext").as_ref(), "dim_ext_line_ext", f(s.dimexe)),
ro(t!("Ext line offset").as_ref(), "dim_ext_line_offset", f(s.dimexo)),
ro(t!("Ext line fixed").as_ref(), "dim_ext_line_fixed", yn(s.dimfxlon)),
ro(
t!("Ext line fixed length").as_ref(),
"dim_ext_line_fixed_length",
f(s.dimfxl),
),
ro(t!("Ext line color").as_ref(), "dim_ext_line_color", s.dimclre.to_string()),
ro(t!("Ext line ext").as_ref(), "dim_ext_line_ext", f(s.dimexe)),
ro(t!("Ext line offset").as_ref(), "dim_ext_line_offset", f(s.dimexo)),
],
},
PropSection {
@@ -1726,6 +1727,17 @@ pub fn style_sections(
},
&["Bottom", "Middle", "Top"],
),
"dim_line_lineweight" | "dim_ext_line_lineweight" => {
let inherited = if property.field == "dim_line_lineweight" {
s.dimlwd
} else {
s.dimlwe
};
crate::scene::model::object::PropValue::Choice {
selected: lineweight_label(number.unwrap_or(inherited)),
options: lineweight_options(),
}
}
_ => crate::scene::model::object::PropValue::EditText(value),
};
}
@@ -1785,6 +1797,12 @@ pub fn style_sections(
.map(|line_type| line_type.name.clone())
.filter(|name| !name.is_empty())
.collect();
let text_style_options: Vec<String> = document
.text_styles
.iter()
.map(|style| style.name.clone())
.filter(|name| !name.is_empty())
.collect();
for property in sections
.iter_mut()
.flat_map(|section| section.props.iter_mut())
@@ -1822,6 +1840,22 @@ pub fn style_sections(
selected: current,
options: linetype_options.clone(),
};
} else if property.field == "dim_text_style" {
if let Some(handle) = crate::entities::dim_override::handle(
data,
crate::entities::dim_override::DIMTXSTY,
) {
current = document
.text_styles
.iter()
.find(|style| style.handle == handle)
.map(|style| style.name.clone())
.unwrap_or(current);
}
property.value = crate::scene::model::object::PropValue::Choice {
selected: current,
options: text_style_options.clone(),
};
}
}
sections