Implement associative center mark workflow

This commit is contained in:
ramox81 committed 2026-08-21 12:05:18 +03:00
1 parent 0ae6355c2c
commit ff09fc7800
18 files changed
+936 -40

No files matched your search

+245 -13
View File
@@ -12,6 +12,62 @@ use crate::scene::model::object::{GripApply, GripDef, PropSection};
use crate::scene::model::wire_model::TangentGeom;
fn to_render(line: &Line) -> RenderEntity {
if let Some(association) =
acadrust::entities::CenterMarkAssociation::read(&line.common.extended_data)
{
let mut segments = crate::scene::centermark::mark_segments(&association);
if !association.associated {
let center = crate::scene::centermark::dvec(association.center);
let directions = crate::scene::centermark::mark_directions(&association);
let size = association.cross_size.max(association.radius * 0.08).max(1.0e-6) * 0.35;
let badge_center = center
+ directions[0] * (association.radius + association.extension_length + size * 2.0)
+ directions[2] * size * 2.0;
let corners = [
badge_center + directions[2] * size,
badge_center + directions[0] * size,
badge_center - directions[2] * size,
badge_center - directions[0] * size,
];
for index in 0..4 {
segments.push([corners[index], corners[(index + 1) % 4]]);
}
segments.push([
badge_center + directions[2] * size * 0.45,
badge_center - directions[2] * size * 0.2,
]);
segments.push([
badge_center - directions[2] * size * 0.55,
badge_center - directions[2] * size * 0.65,
]);
}
let mut points = Vec::with_capacity(segments.len() * 3);
let mut key_vertices = Vec::with_capacity(segments.len() * 2 + 1);
let mut tangent_geoms = Vec::with_capacity(segments.len());
for (index, segment) in segments.iter().enumerate() {
if index > 0 {
points.push([f64::NAN; 3]);
}
for point in segment {
points.push([point.x, point.y, point.z]);
key_vertices.push([point.x, point.y, point.z]);
}
tangent_geoms.push(TangentGeom::Line {
p1: [segment[0].x as f32, segment[0].y as f32, segment[0].z as f32],
p2: [segment[1].x as f32, segment[1].y as f32, segment[1].z as f32],
});
}
let center = crate::scene::centermark::dvec(association.center);
key_vertices.push([center.x, center.y, center.z]);
return RenderEntity {
pick_tris: Vec::new(),
object: RenderObject::Lines(points),
snap_pts: Vec::new(),
tangent_geoms,
key_vertices,
fill_tris: Vec::new(),
};
}
// LINE endpoints are stored in WCS — unlike the planar OCS entities
// (ARC/CIRCLE/LWPOLYLINE/TEXT), the extrusion normal on a LINE only
// orients its thickness sweep. Remapping the endpoints through the
@@ -65,6 +121,29 @@ fn to_render(line: &Line) -> RenderEntity {
}
fn grips(line: &Line) -> Vec<GripDef> {
if let Some(association) =
acadrust::entities::CenterMarkAssociation::read(&line.common.extended_data)
{
let center = crate::scene::centermark::dvec(association.center);
let directions = crate::scene::centermark::mark_directions(&association);
let mut result = vec![center_grip(0, center)];
if !association.show_extensions {
return result;
}
for (index, direction) in directions.iter().enumerate() {
let distance = (association.radius + association.length_adjustments[index]).max(0.0);
result.push(square_grip(index + 1, center + *direction * distance));
}
for (index, direction) in directions.iter().enumerate() {
let distance = (association.radius
+ association.extension_length
+ association.length_adjustments[index]
+ association.overshoots[index])
.max(0.0);
result.push(oriented_triangle_grip(index + 5, center + *direction * distance, *direction));
}
return result;
}
let s = glam::DVec3::new(line.start.x, line.start.y, line.start.z);
let e = glam::DVec3::new(line.end.x, line.end.y, line.end.z);
let m = (s + e) * 0.5;
@@ -88,6 +167,36 @@ fn grips(line: &Line) -> Vec<GripDef> {
}
fn properties(line: &Line) -> Vec<PropSection> {
if let Some(association) =
acadrust::entities::CenterMarkAssociation::read(&line.common.extended_data)
{
use crate::scene::model::object::{PropValue, Property};
return vec![PropSection {
title: t!("Geometry").into_owned(),
props: vec![
Property {
label: "Show extension".to_owned(),
field: "centermark_show_extension",
value: PropValue::Choice {
selected: if association.show_extensions { "Yes" } else { "No" }.to_owned(),
options: vec!["Yes".to_owned(), "No".to_owned()],
},
},
edit("Cross size", "centermark_cross_size", association.cross_size),
edit("Cross gap", "centermark_cross_gap", association.cross_gap),
edit(
"Extension length",
"centermark_extension_length",
association.extension_length,
),
ro(
"Associative",
"centermark_associative",
if association.associated { "Yes" } else { "No" },
),
],
}];
}
if let Some(association) =
acadrust::entities::CenterLineAssociation::read(&line.common.extended_data)
{
@@ -136,6 +245,36 @@ fn properties(line: &Line) -> Vec<PropSection> {
}
fn apply_geom_prop(line: &mut Line, field: &str, value: &str) {
if let Some(mut association) =
acadrust::entities::CenterMarkAssociation::read(&line.common.extended_data)
{
match field {
"centermark_show_extension" => {
association.show_extensions = matches!(
value.trim().to_ascii_lowercase().as_str(),
"yes" | "on" | "true" | "1"
);
}
"centermark_cross_size" | "centermark_cross_gap" | "centermark_extension_length" => {
let Some(number) = parse_f64(value) else { return; };
if !number.is_finite() || number < 0.0 { return; }
match field {
"centermark_cross_size" => association.cross_size = number,
"centermark_cross_gap" => association.cross_gap = number,
"centermark_extension_length" => association.extension_length = number,
_ => unreachable!(),
}
if field == "centermark_cross_size" {
association.cross_size_relative = false;
} else if field == "centermark_cross_gap" {
association.cross_gap_relative = false;
}
}
_ => return,
}
crate::scene::centermark::update_carrier(line, &association);
return;
}
let Some(v) = parse_f64(value) else {
return;
};
@@ -178,6 +317,37 @@ fn apply_geom_prop(line: &mut Line, field: &str, value: &str) {
}
fn apply_grip(line: &mut Line, grip_id: usize, apply: GripApply) {
if let Some(mut association) =
acadrust::entities::CenterMarkAssociation::read(&line.common.extended_data)
{
let center = crate::scene::centermark::dvec(association.center);
let directions = crate::scene::centermark::mark_directions(&association);
match (grip_id, apply) {
(0, GripApply::Translate(delta)) => {
let moved = center + delta;
association.center = acadrust::types::Vector3::new(moved.x, moved.y, moved.z);
let origin = crate::scene::centermark::dvec(association.plane_origin) + delta;
association.plane_origin = acadrust::types::Vector3::new(origin.x, origin.y, origin.z);
association.associated = false;
}
(id @ 1..=4, GripApply::Absolute(point)) => {
let index = id - 1;
let distance = (point - center).dot(directions[index]).max(0.0);
association.length_adjustments[index] = distance - association.radius;
}
(id @ 5..=8, GripApply::Absolute(point)) => {
let index = id - 5;
let distance = (point - center).dot(directions[index]).max(0.0);
association.overshoots[index] = distance
- association.radius
- association.extension_length
- association.length_adjustments[index];
}
_ => return,
}
crate::scene::centermark::update_carrier(line, &association);
return;
}
if let Some(mut association) =
acadrust::entities::CenterLineAssociation::read(&line.common.extended_data)
{
@@ -250,18 +420,10 @@ fn apply_grip(line: &mut Line, grip_id: usize, apply: GripApply) {
}
}
fn apply_transform(line: &mut Line, t: &EntityTransform) {
if let Some(mut association) =
acadrust::entities::CenterLineAssociation::read(&line.common.extended_data)
{
association.associated = false;
association.write(&mut line.common.extended_data);
}
fn apply_plain_transform(line: &mut Line, t: &EntityTransform) {
match t {
EntityTransform::Translate(d) => {
line.translate(acadrust::types::Vector3::new(
d.x as f64, d.y as f64, d.z as f64,
));
line.translate(acadrust::types::Vector3::new(d.x, d.y, d.z));
}
EntityTransform::Rotate { center, axis, angle_rad } => {
crate::scene::view::transform::apply_standard_transform(line, *center, *axis, *angle_rad);
@@ -273,9 +435,7 @@ fn apply_transform(line: &mut Line, t: &EntityTransform) {
acadrust::Entity::apply_transform(
line,
&crate::scene::view::transform::reflection_about_working_line(
*p1,
*p2,
*working_normal,
*p1, *p2, *working_normal,
),
);
}
@@ -285,6 +445,68 @@ fn apply_transform(line: &mut Line, t: &EntityTransform) {
}
}
fn apply_transform(line: &mut Line, t: &EntityTransform) {
if let Some(mut association) =
acadrust::entities::CenterMarkAssociation::read(&line.common.extended_data)
{
if let EntityTransform::Translate(delta) = t {
let center = crate::scene::centermark::dvec(association.center) + *delta;
association.center = acadrust::types::Vector3::new(center.x, center.y, center.z);
let origin = crate::scene::centermark::dvec(association.plane_origin) + *delta;
association.plane_origin = acadrust::types::Vector3::new(origin.x, origin.y, origin.z);
association.associated = false;
crate::scene::centermark::update_carrier(line, &association);
return;
}
let center = crate::scene::centermark::dvec(association.center);
let x = crate::scene::centermark::dvec(association.plane_x).normalize_or(glam::DVec3::X);
let y = crate::scene::centermark::dvec(association.plane_y).normalize_or(glam::DVec3::Y);
let mut x_basis = Line::from_points(
acadrust::types::Vector3::new(center.x, center.y, center.z),
acadrust::types::Vector3::new(center.x + x.x, center.y + x.y, center.z + x.z),
);
let mut y_basis = Line::from_points(
acadrust::types::Vector3::new(center.x, center.y, center.z),
acadrust::types::Vector3::new(center.x + y.x, center.y + y.y, center.z + y.z),
);
apply_plain_transform(&mut x_basis, t);
apply_plain_transform(&mut y_basis, t);
let moved = glam::DVec3::new(x_basis.start.x, x_basis.start.y, x_basis.start.z);
let moved_x = glam::DVec3::new(x_basis.end.x, x_basis.end.y, x_basis.end.z) - moved;
let moved_y = glam::DVec3::new(y_basis.end.x, y_basis.end.y, y_basis.end.z) - moved;
let scale = ((moved_x.length() + moved_y.length()) * 0.5).max(1.0e-12);
association.center = acadrust::types::Vector3::new(moved.x, moved.y, moved.z);
association.plane_origin = association.center;
association.plane_x = acadrust::types::Vector3::new(
moved_x.normalize_or(x).x,
moved_x.normalize_or(x).y,
moved_x.normalize_or(x).z,
);
association.plane_y = acadrust::types::Vector3::new(
moved_y.normalize_or(y).x,
moved_y.normalize_or(y).y,
moved_y.normalize_or(y).z,
);
association.radius *= scale;
association.cross_size *= scale;
association.cross_gap *= scale;
association.extension_length *= scale;
for value in association.length_adjustments.iter_mut().chain(association.overshoots.iter_mut()) {
*value *= scale;
}
association.associated = false;
crate::scene::centermark::update_carrier(line, &association);
return;
}
if let Some(mut association) =
acadrust::entities::CenterLineAssociation::read(&line.common.extended_data)
{
association.associated = false;
association.write(&mut line.common.extended_data);
}
apply_plain_transform(line, t);
}
impl RenderConvertible for Line {
fn to_render(&self, _document: &acadrust::CadDocument) -> Option<RenderEntity> {
Some(to_render(self))
@@ -300,6 +522,16 @@ impl crate::entities::traits::Grippable for Line {
}
fn grip_menu(&self, grip_id: usize) -> Vec<crate::scene::model::object::GripMenuItem> {
use crate::scene::model::object::{GripMenuAction, GripMenuItem};
if acadrust::entities::CenterMarkAssociation::read(&self.common.extended_data).is_some() {
return if grip_id == 0 {
vec![GripMenuItem { label: "Stretch", action: GripMenuAction::Stretch }]
} else {
vec![
GripMenuItem { label: "Stretch", action: GripMenuAction::Stretch },
GripMenuItem { label: "Lengthen", action: GripMenuAction::Lengthen },
]
};
}
if grip_id == 2 {
vec![GripMenuItem {
label: "Stretch",
+2
View File
@@ -13,6 +13,8 @@ use acadrust::EntityType;
pub fn ui_name(e: &EntityType) -> &'static str {
match e {
EntityType::Point(_) => "Point",
EntityType::Line(line)
if acadrust::entities::CenterMarkAssociation::read(&line.common.extended_data).is_some() => "Center Mark",
EntityType::Line(_) => "Line",
EntityType::Circle(_) => "Circle",
EntityType::Arc(_) => "Arc",
+8
View File
@@ -111,6 +111,14 @@ pub trait TextContent {
pub fn entity_type_name(et: &EntityType) -> &str {
match et {
EntityType::Point(_) => "Point",
EntityType::Line(line)
if acadrust::entities::CenterMarkAssociation::read(
&line.common.extended_data,
)
.is_some() =>
{
"CenterMark"
}
EntityType::Line(line)
if acadrust::entities::CenterLineAssociation::read(
&line.common.extended_data,