forked from 1b-agent/opencadstudio-upstream
fix(dimension): grip menu Above Dim Line places text by the style, not a 1-unit nudge
It moved the text a fixed drawing unit off the line and then another unit up, wrong at any real scale. It now sets DIMTAD = Above on the dimension and lets the automatic layout place the text. Fixes #543 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bc13f71882
commit
c45f22652d
2 files changed
+14
-31
No files matched your search
@@ -1934,6 +1934,14 @@ pub(super) fn on_tab_close(&mut self, idx: usize) -> Task<Message> {
|
|||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
if matches!(item.action, GripMenuAction::AboveDimLine) {
|
||||||
|
crate::entities::dim_override::set_property(
|
||||||
|
&mut self.tabs[i].scene.document,
|
||||||
|
popup.handle,
|
||||||
|
"dim_text_pos_vert",
|
||||||
|
"Above",
|
||||||
|
);
|
||||||
|
}
|
||||||
if let Some(entity) = self.tabs[i].scene.document.get_entity_mut(popup.handle) {
|
if let Some(entity) = self.tabs[i].scene.document.get_entity_mut(popup.handle) {
|
||||||
entity.apply_grip_menu(popup.grip_id, item.action);
|
entity.apply_grip_menu(popup.grip_id, item.action);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1111,32 +1111,6 @@ fn dimension_line_grip_position(dim: &Dimension) -> Option<DVec3> {
|
|||||||
Some((p1 + p2) * 0.5)
|
Some((p1 + p2) * 0.5)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn above_dimension_text_position(dim: &Dimension) -> Option<DVec3> {
|
|
||||||
if let Some((vertex, start, end, radius)) = angular_dimension_frame(dim) {
|
|
||||||
let angle = (start + end) * 0.5;
|
|
||||||
let direction = DVec3::new(angle.cos() as f64, angle.sin() as f64, 0.0);
|
|
||||||
return Some(
|
|
||||||
DVec3::new(vertex.x as f64, vertex.y as f64, vertex.z as f64)
|
|
||||||
+ direction * (radius as f64 + 1.0),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
let center = dimension_line_grip_position(dim)?;
|
|
||||||
let (ax, ay) = match dim {
|
|
||||||
Dimension::Linear(d) => (d.rotation.cos(), d.rotation.sin()),
|
|
||||||
Dimension::Aligned(d) => {
|
|
||||||
let dx = d.second_point.x - d.first_point.x;
|
|
||||||
let dy = d.second_point.y - d.first_point.y;
|
|
||||||
let length = (dx * dx + dy * dy).sqrt();
|
|
||||||
if length <= 1e-12 {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
(dx / length, dy / length)
|
|
||||||
}
|
|
||||||
_ => return Some(center + DVec3::Y),
|
|
||||||
};
|
|
||||||
Some(center + DVec3::new(-ay, ax, 0.0))
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Grippable for Dimension {
|
impl Grippable for Dimension {
|
||||||
fn grips(&self) -> Vec<GripDef> {
|
fn grips(&self) -> Vec<GripDef> {
|
||||||
// Auto-placed dimensions carry a zero text_middle_point sentinel; put
|
// Auto-placed dimensions carry a zero text_middle_point sentinel; put
|
||||||
@@ -1489,12 +1463,13 @@ impl Grippable for Dimension {
|
|||||||
base.flip_arrow1 = !base.flip_arrow1;
|
base.flip_arrow1 = !base.flip_arrow1;
|
||||||
base.flip_arrow2 = !base.flip_arrow2;
|
base.flip_arrow2 = !base.flip_arrow2;
|
||||||
}
|
}
|
||||||
|
// The caller sets DIMTAD = Above as an override; the text goes
|
||||||
|
// back to automatic placement so DIMGAP and the text height set
|
||||||
|
// how far above the line it sits, at any drawing scale. (#543)
|
||||||
A::AboveDimLine if grip_id == text_grip => {
|
A::AboveDimLine if grip_id == text_grip => {
|
||||||
if let Some(point) = above_dimension_text_position(self) {
|
let b = self.base_mut();
|
||||||
let base = self.base_mut();
|
b.text_middle_point = Vector3::new(0.0, 0.0, 0.0);
|
||||||
base.text_middle_point = Vector3::new(point.x, point.y + 1.0, point.z);
|
b.text_user_positioned = false;
|
||||||
base.text_user_positioned = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user