forked from 1b-agent/opencadstudio-upstream
Merge pull request #850 from ramox81/codex/associative-center-mark
This commit is contained in:
commit
b648000e78
21 files changed
+1672
-241
No files matched your search
+334
-8
@@ -3,7 +3,8 @@ use crate::t;
|
||||
|
||||
use crate::command::EntityTransform;
|
||||
use crate::entities::common::{
|
||||
center_grip, edit_prop as edit, parse_f64, ro_prop as ro, square_grip,
|
||||
center_grip, edit_prop as edit, oriented_triangle_grip, parse_f64, ro_prop as ro,
|
||||
square_grip,
|
||||
};
|
||||
use crate::entities::traits::RenderConvertible;
|
||||
use crate::scene::convert::acad_to_render::{extrusion_wall_tris, RenderEntity, RenderObject};
|
||||
@@ -11,6 +12,37 @@ 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 segments = crate::scene::centermark::render_segments(&association);
|
||||
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
|
||||
@@ -64,13 +96,106 @@ 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)];
|
||||
let extension_start = association.cross_size * 0.5 + association.cross_gap;
|
||||
if !association.show_extensions || association.radius <= extension_start {
|
||||
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(extension_start);
|
||||
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;
|
||||
if let Some(association) =
|
||||
acadrust::entities::CenterLineAssociation::read(&line.common.extended_data)
|
||||
{
|
||||
let direction = (e - s).normalize_or(glam::DVec3::X);
|
||||
let base_start = s + direction * association.start_extension;
|
||||
let base_end = e - direction * association.end_extension;
|
||||
return vec![
|
||||
square_grip(0, base_start),
|
||||
square_grip(1, base_end),
|
||||
center_grip(2, m),
|
||||
oriented_triangle_grip(3, s, -direction),
|
||||
oriented_triangle_grip(4, e, direction),
|
||||
];
|
||||
}
|
||||
vec![square_grip(0, s), square_grip(1, e), center_grip(2, m)]
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return vec![PropSection {
|
||||
title: t!("Geometry").into_owned(),
|
||||
props: vec![
|
||||
edit(
|
||||
"Start extension",
|
||||
"centerline_start_extension",
|
||||
association.start_extension,
|
||||
),
|
||||
edit(
|
||||
"End extension",
|
||||
"centerline_end_extension",
|
||||
association.end_extension,
|
||||
),
|
||||
ro(t!("Length").as_ref(), "length", format!("{:.4}", line.length())),
|
||||
ro(
|
||||
"Associative",
|
||||
"centerline_associative",
|
||||
if association.associated { "Yes" } else { "No" },
|
||||
),
|
||||
],
|
||||
}];
|
||||
}
|
||||
let dx = line.end.x - line.start.x;
|
||||
let dy = line.end.y - line.start.y;
|
||||
let dz = line.end.z - line.start.z;
|
||||
@@ -94,9 +219,66 @@ 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;
|
||||
};
|
||||
if let Some(mut association) =
|
||||
acadrust::entities::CenterLineAssociation::read(&line.common.extended_data)
|
||||
{
|
||||
if !v.is_finite() || v < 0.0 {
|
||||
return;
|
||||
}
|
||||
let start = glam::DVec3::new(line.start.x, line.start.y, line.start.z);
|
||||
let end = glam::DVec3::new(line.end.x, line.end.y, line.end.z);
|
||||
let direction = (end - start).normalize_or(glam::DVec3::X);
|
||||
match field {
|
||||
"centerline_start_extension" => {
|
||||
let delta = v - association.start_extension;
|
||||
let moved = start - direction * delta;
|
||||
line.start = acadrust::types::Vector3::new(moved.x, moved.y, moved.z);
|
||||
association.start_extension = v;
|
||||
}
|
||||
"centerline_end_extension" => {
|
||||
let delta = v - association.end_extension;
|
||||
let moved = end + direction * delta;
|
||||
line.end = acadrust::types::Vector3::new(moved.x, moved.y, moved.z);
|
||||
association.end_extension = v;
|
||||
}
|
||||
_ => return,
|
||||
}
|
||||
association.write(&mut line.common.extended_data);
|
||||
return;
|
||||
}
|
||||
match field {
|
||||
"start_x" => line.start.x = v,
|
||||
"start_y" => line.start.y = v,
|
||||
@@ -109,6 +291,84 @@ 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)
|
||||
{
|
||||
let start = glam::DVec3::new(line.start.x, line.start.y, line.start.z);
|
||||
let end = glam::DVec3::new(line.end.x, line.end.y, line.end.z);
|
||||
let direction = (end - start).normalize_or(glam::DVec3::X);
|
||||
let base_start = start + direction * association.start_extension;
|
||||
let base_end = end - direction * association.end_extension;
|
||||
match (grip_id, apply) {
|
||||
(0, GripApply::Absolute(point)) => {
|
||||
let delta = (point - base_start).dot(direction);
|
||||
association.start_length_adjustment -= delta;
|
||||
let moved = start + direction * delta;
|
||||
line.start = acadrust::types::Vector3::new(moved.x, moved.y, moved.z);
|
||||
}
|
||||
(1, GripApply::Absolute(point)) => {
|
||||
let delta = (point - base_end).dot(direction);
|
||||
association.end_length_adjustment += delta;
|
||||
let moved = end + direction * delta;
|
||||
line.end = acadrust::types::Vector3::new(moved.x, moved.y, moved.z);
|
||||
}
|
||||
(2, GripApply::Translate(delta)) => {
|
||||
line.start.x += delta.x;
|
||||
line.start.y += delta.y;
|
||||
line.start.z += delta.z;
|
||||
line.end.x += delta.x;
|
||||
line.end.y += delta.y;
|
||||
line.end.z += delta.z;
|
||||
association.associated = false;
|
||||
}
|
||||
(3, GripApply::Absolute(point)) => {
|
||||
let total = (base_start - point).dot(direction).max(0.0);
|
||||
association.start_extension = total;
|
||||
let moved = base_start - direction * association.start_extension;
|
||||
line.start = acadrust::types::Vector3::new(moved.x, moved.y, moved.z);
|
||||
}
|
||||
(4, GripApply::Absolute(point)) => {
|
||||
let total = (point - base_end).dot(direction).max(0.0);
|
||||
association.end_extension = total;
|
||||
let moved = base_end + direction * association.end_extension;
|
||||
line.end = acadrust::types::Vector3::new(moved.x, moved.y, moved.z);
|
||||
}
|
||||
_ => return,
|
||||
}
|
||||
association.write(&mut line.common.extended_data);
|
||||
return;
|
||||
}
|
||||
match (grip_id, apply) {
|
||||
(0, GripApply::Absolute(p)) => {
|
||||
line.start.x = p.x as f64;
|
||||
@@ -132,12 +392,10 @@ fn apply_grip(line: &mut Line, grip_id: usize, apply: GripApply) {
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_transform(line: &mut Line, t: &EntityTransform) {
|
||||
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);
|
||||
@@ -149,9 +407,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,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -161,6 +417,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))
|
||||
@@ -176,6 +494,14 @@ 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()
|
||||
|| acadrust::entities::CenterLineAssociation::read(&self.common.extended_data).is_some()
|
||||
{
|
||||
return vec![GripMenuItem {
|
||||
label: "Stretch",
|
||||
action: GripMenuAction::Stretch,
|
||||
}];
|
||||
}
|
||||
if grip_id == 2 {
|
||||
vec![GripMenuItem {
|
||||
label: "Stretch",
|
||||
|
||||
@@ -13,6 +13,10 @@ 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)
|
||||
if acadrust::entities::CenterLineAssociation::read(&line.common.extended_data).is_some() => "Center Line",
|
||||
EntityType::Line(_) => "Line",
|
||||
EntityType::Circle(_) => "Circle",
|
||||
EntityType::Arc(_) => "Arc",
|
||||
|
||||
@@ -111,6 +111,22 @@ 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,
|
||||
)
|
||||
.is_some() =>
|
||||
{
|
||||
"CenterLine"
|
||||
}
|
||||
EntityType::Line(_) => "Line",
|
||||
EntityType::Circle(_) => "Circle",
|
||||
EntityType::Arc(_) => "Arc",
|
||||
|
||||
Reference in new issue
Block a user