Align dimension property editability
This commit is contained in:
parent
f0d00c1d53
commit
9dc4e08f77
4 changed files with 105 additions and 55 deletions
|
|
@ -2409,18 +2409,7 @@ fn set_row_value(
|
||||||
/// The lineweight dropdown options (named defaults + the standard millimetre
|
/// The lineweight dropdown options (named defaults + the standard millimetre
|
||||||
/// steps), matching the labels `dim_lineweight_label` produces.
|
/// steps), matching the labels `dim_lineweight_label` produces.
|
||||||
pub(crate) fn lineweight_options() -> Vec<String> {
|
pub(crate) fn lineweight_options() -> Vec<String> {
|
||||||
let mut v = vec![
|
crate::entities::common::lineweight_options()
|
||||||
"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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Inverse of `dim_lineweight_label`: a lineweight label → DIMLWD enum value.
|
/// Inverse of `dim_lineweight_label`: a lineweight label → DIMLWD enum value.
|
||||||
|
|
@ -2546,13 +2535,7 @@ fn leader_arrow_label(
|
||||||
|
|
||||||
/// DIMLWD lineweight enum → label.
|
/// DIMLWD lineweight enum → label.
|
||||||
fn dim_lineweight_label(dimlwd: i16) -> String {
|
fn dim_lineweight_label(dimlwd: i16) -> String {
|
||||||
match dimlwd {
|
crate::entities::common::lineweight_label(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(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Human-readable INSUNITS name (DXF group 70 unit codes).
|
/// Human-readable INSUNITS name (DXF group 70 unit codes).
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
pub fn ro_prop(label: &str, field: &'static str, value: impl Into<String>) -> Property {
|
||||||
Property {
|
Property {
|
||||||
label: label.into(),
|
label: label.into(),
|
||||||
|
|
|
||||||
|
|
@ -331,28 +331,34 @@ pub fn set_property(
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let trimmed = value.trim();
|
let trimmed = value.trim();
|
||||||
let handle_field = match field {
|
let handle_field = match field {
|
||||||
"dim_arrowhead_1" => Some((DIMBLK1, true)),
|
"dim_arrowhead_1" => Some(DIMBLK1),
|
||||||
"dim_arrowhead_2" => Some((DIMBLK2, true)),
|
"dim_arrowhead_2" => Some(DIMBLK2),
|
||||||
"dim_linetype" => Some((DIMLTYPE, false)),
|
"dim_linetype" => Some(DIMLTYPE),
|
||||||
"dim_ext_linetype_1" => Some((DIMLTEX1, false)),
|
"dim_ext_linetype_1" => Some(DIMLTEX1),
|
||||||
"dim_ext_linetype_2" => Some((DIMLTEX2, false)),
|
"dim_ext_linetype_2" => Some(DIMLTEX2),
|
||||||
|
"dim_text_style" => Some(DIMTXSTY),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
if let Some((code, block)) = handle_field {
|
if let Some(code) = handle_field {
|
||||||
let resolved = if block {
|
let resolved = match field {
|
||||||
(trimmed != "Closed filled")
|
"dim_arrowhead_1" | "dim_arrowhead_2" => (trimmed != "Closed filled")
|
||||||
.then(|| {
|
.then(|| {
|
||||||
doc.block_records
|
doc.block_records
|
||||||
.iter()
|
.iter()
|
||||||
.find(|record| record.name == trimmed)
|
.find(|record| record.name == trimmed)
|
||||||
.map(|record| record.handle)
|
.map(|record| record.handle)
|
||||||
})
|
})
|
||||||
.flatten()
|
.flatten(),
|
||||||
} else {
|
"dim_text_style" => doc
|
||||||
doc.line_types
|
.text_styles
|
||||||
|
.iter()
|
||||||
|
.find(|style| style.name == trimmed)
|
||||||
|
.map(|style| style.handle),
|
||||||
|
_ => doc
|
||||||
|
.line_types
|
||||||
.iter()
|
.iter()
|
||||||
.find(|line_type| line_type.name == trimmed)
|
.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));
|
set(doc, handle, code, resolved.map(XDataValue::Handle));
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,8 @@ use glam::{DVec3, Vec3};
|
||||||
|
|
||||||
use crate::command::EntityTransform;
|
use crate::command::EntityTransform;
|
||||||
use crate::entities::common::{
|
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::entities::traits::{Grippable, PropertyEditable, Transformable};
|
||||||
use crate::scene::model::object::{GripApply, GripDef, PropSection};
|
use crate::scene::model::object::{GripApply, GripDef, PropSection};
|
||||||
|
|
@ -1461,39 +1462,22 @@ pub fn style_sections(
|
||||||
PropSection {
|
PropSection {
|
||||||
title: t!("Lines & Arrows").into_owned(),
|
title: t!("Lines & Arrows").into_owned(),
|
||||||
props: vec![
|
props: vec![
|
||||||
ro(t!("Arrow size").as_ref(), "dim_arrow_size", f(s.dimasz)),
|
|
||||||
ro(
|
ro(
|
||||||
t!("Arrowhead 1").as_ref(),
|
t!("Arrow 1").as_ref(),
|
||||||
"dim_arrowhead_1",
|
"dim_arrowhead_1",
|
||||||
block_name(document, s.dimblk1, &s.dimblk1_name),
|
block_name(document, s.dimblk1, &s.dimblk1_name),
|
||||||
),
|
),
|
||||||
ro(
|
ro(
|
||||||
t!("Arrowhead 2").as_ref(),
|
t!("Arrow 2").as_ref(),
|
||||||
"dim_arrowhead_2",
|
"dim_arrowhead_2",
|
||||||
block_name(document, s.dimblk2, &s.dimblk2_name),
|
block_name(document, s.dimblk2, &s.dimblk2_name),
|
||||||
),
|
),
|
||||||
ro(
|
ro(t!("Arrow size").as_ref(), "dim_arrow_size", f(s.dimasz)),
|
||||||
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(
|
ro(
|
||||||
t!("Dim line lineweight").as_ref(),
|
t!("Dim line lineweight").as_ref(),
|
||||||
"dim_line_lineweight",
|
"dim_line_lineweight",
|
||||||
s.dimlwd.to_string(),
|
s.dimlwd.to_string(),
|
||||||
),
|
),
|
||||||
ro(t!("Ext line color").as_ref(), "dim_ext_line_color", s.dimclre.to_string()),
|
|
||||||
ro(
|
ro(
|
||||||
t!("Ext line lineweight").as_ref(),
|
t!("Ext line lineweight").as_ref(),
|
||||||
"dim_ext_line_lineweight",
|
"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 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 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 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!("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").as_ref(), "dim_ext_line_fixed", yn(s.dimfxlon)),
|
||||||
ro(
|
ro(
|
||||||
t!("Ext line fixed length").as_ref(),
|
t!("Ext line fixed length").as_ref(),
|
||||||
"dim_ext_line_fixed_length",
|
"dim_ext_line_fixed_length",
|
||||||
f(s.dimfxl),
|
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 {
|
PropSection {
|
||||||
|
|
@ -1726,6 +1727,17 @@ pub fn style_sections(
|
||||||
},
|
},
|
||||||
&["Bottom", "Middle", "Top"],
|
&["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),
|
_ => crate::scene::model::object::PropValue::EditText(value),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -1785,6 +1797,12 @@ pub fn style_sections(
|
||||||
.map(|line_type| line_type.name.clone())
|
.map(|line_type| line_type.name.clone())
|
||||||
.filter(|name| !name.is_empty())
|
.filter(|name| !name.is_empty())
|
||||||
.collect();
|
.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
|
for property in sections
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.flat_map(|section| section.props.iter_mut())
|
.flat_map(|section| section.props.iter_mut())
|
||||||
|
|
@ -1822,6 +1840,22 @@ pub fn style_sections(
|
||||||
selected: current,
|
selected: current,
|
||||||
options: linetype_options.clone(),
|
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
|
sections
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue