Complete CHAMFEREDGE workflow and history

This commit is contained in:
ramox81 committed 2026-09-08 15:45:10 +03:00
1 parent ed8cddc556
commit 8822371e18
10 files changed
+678 -157

No files matched your search

+124 -2
View File
@@ -1,7 +1,8 @@
use acadrust::entities::{EmbeddedEntity, Solid3D};
use acadrust::objects::{
DynamicBlockData, ObjectType, SolidHistoryBox, SolidHistoryBrep, SolidHistoryCone,
SolidHistoryCylinder, SolidHistoryFillet, SolidHistoryLoft, SolidHistoryLoftParameters, SolidHistoryNodeBase, SolidHistoryOperation,
DynamicBlockData, ObjectType, SolidHistoryBox, SolidHistoryBrep, SolidHistoryChamfer,
SolidHistoryCone, SolidHistoryCylinder, SolidHistoryFillet, SolidHistoryLoft,
SolidHistoryLoftParameters, SolidHistoryNodeBase, SolidHistoryOperation,
SolidHistoryPyramid, SolidHistoryRevolve, SolidHistorySphere, SolidHistorySweep,
SolidHistoryTorus,
};
@@ -33,6 +34,8 @@ pub const GRIP_LOFT_SECTION_FIRST: usize = 40_000;
pub const GRIP_REVOLVE_PROFILE_FIRST: usize = 50_000;
pub const GRIP_REVOLVE_AXIS: usize = 10_013;
pub const GRIP_FILLET_RADIUS: usize = 10_014;
pub const GRIP_CHAMFER_DISTANCE1: usize = 10_015;
pub const GRIP_CHAMFER_DISTANCE2: usize = 10_016;
pub const GRIP_BOX_CORNER_FIRST: usize = 10_100;
pub const GRIP_BOX_FACE_X_MIN: usize = 10_110;
pub const GRIP_BOX_FACE_X_MAX: usize = 10_111;
@@ -3132,6 +3135,104 @@ pub fn fillet_radius_grip(body: &Body, radius: f64) -> Option<GripDef> {
None
}
pub fn chamfer_distance_grips(
document: &acadrust::CadDocument,
handle: acadrust::Handle,
value: &SolidHistoryChamfer,
) -> Vec<GripDef> {
let Some(operations) = document.solid_history_operations(handle) else {
return Vec::new();
};
let Some(chamfer_index) = operations
.iter()
.rposition(|operation| matches!(operation, SolidHistoryOperation::Chamfer(_)))
else {
return Vec::new();
};
let Ok(source) = cadkernel::acis::rebuild_history(&operations[..chamfer_index]) else {
return Vec::new();
};
let edges = source.edge_keys().collect::<Vec<_>>();
let faces = source.face_keys().collect::<Vec<_>>();
let Some(edge) = value
.edges
.first()
.and_then(|ordinal| usize::try_from(*ordinal).ok())
.and_then(|ordinal| edges.get(ordinal).copied())
.and_then(|edge| source.edges.get(edge))
else {
return Vec::new();
};
let Some(base_face) = usize::try_from(value.base_face)
.ok()
.and_then(|ordinal| faces.get(ordinal).copied())
else {
return Vec::new();
};
let adjacent = edge
.coedges
.iter()
.filter_map(|coedge| source.coedges.get(*coedge))
.filter_map(|coedge| source.loops.get(coedge.owner))
.map(|edge_loop| edge_loop.owner)
.collect::<Vec<_>>();
let Some(other_face) = adjacent.iter().copied().find(|face| *face != base_face) else {
return Vec::new();
};
let outward = |face_key| {
let face = source.faces.get(face_key)?;
let Surface::Plane(plane) = source.surfaces.get(face.surface)? else {
return None;
};
let normal = glam::DVec3::from_array(plane.normal()?).try_normalize()?;
Some(if face.forward { normal } else { -normal })
};
let Some(base_normal) = outward(base_face) else {
return Vec::new();
};
let Some(other_normal) = outward(other_face) else {
return Vec::new();
};
let dot = base_normal.dot(other_normal);
let Some(base_inward) = (-(other_normal - base_normal * dot)).try_normalize() else {
return Vec::new();
};
let Some(other_inward) = (-(base_normal - other_normal * dot)).try_normalize() else {
return Vec::new();
};
let Some(start) = source.vertices.get(edge.start) else {
return Vec::new();
};
let Some(end) = source.vertices.get(edge.end) else {
return Vec::new();
};
let midpoint =
(glam::DVec3::from_array(start.point) + glam::DVec3::from_array(end.point)) * 0.5;
[
(
GRIP_CHAMFER_DISTANCE1,
value.base_distance,
base_inward,
),
(
GRIP_CHAMFER_DISTANCE2,
value.other_distance,
other_inward,
),
]
.into_iter()
.filter(|(_, distance, _)| distance.is_finite() && *distance > 0.0)
.map(|(id, distance, axis)| {
grip(
id,
midpoint + axis * distance,
GripShape::Square,
Some(axis),
)
})
.collect()
}
pub fn primitive_grips(
document: &acadrust::CadDocument,
handle: acadrust::Handle,
@@ -3151,6 +3252,9 @@ pub fn primitive_grips(
.into_iter()
.collect();
}
if let SolidHistoryOperation::Chamfer(value) = operation {
return chamfer_distance_grips(document, handle, value);
}
let mut grips = Vec::new();
let mut add = |id, transform, point, shape, axis: Option<[f64; 3]>| {
if let Some(world) = world_point(transform, point) {
@@ -3782,3 +3886,21 @@ pub fn fillet_op(edges: Vec<i32>, radius: f64) -> SolidHistoryOperation {
..SolidHistoryFillet::default()
})
}
pub fn chamfer_op(
edges: Vec<i32>,
base_face: i32,
base_distance: f64,
other_distance: f64,
) -> SolidHistoryOperation {
SolidHistoryOperation::Chamfer(SolidHistoryChamfer {
base: base(glam::DMat4::IDENTITY.to_cols_array()),
operation_major: 1,
method: 0,
base_distance,
other_distance,
edges,
base_face,
..SolidHistoryChamfer::default()
})
}
+41
View File
@@ -1183,6 +1183,47 @@ impl Scene {
value.radii.push(radius);
return self.preview_solid_history(handle, operation);
}
if matches!(
grip_id,
crate::scene::model::solid_history::GRIP_CHAMFER_DISTANCE1
| crate::scene::model::solid_history::GRIP_CHAMFER_DISTANCE2
) {
let definitions = {
let acadrust::objects::SolidHistoryOperation::Chamfer(value) = &operation else {
return false;
};
crate::scene::model::solid_history::chamfer_distance_grips(
&self.document,
handle,
value,
)
};
let Some(definition) = definitions.into_iter().find(|grip| grip.id == grip_id) else {
return false;
};
let Some(axis) = definition.axis else {
return false;
};
let change = match apply {
GripApply::Absolute(world) => (world - definition.world).dot(axis),
GripApply::Translate(delta) => delta.dot(axis),
};
let acadrust::objects::SolidHistoryOperation::Chamfer(value) = &mut operation else {
return false;
};
let distance = if grip_id
== crate::scene::model::solid_history::GRIP_CHAMFER_DISTANCE1
{
&mut value.base_distance
} else {
&mut value.other_distance
};
*distance += change;
if !distance.is_finite() || *distance <= 1.0e-6 {
return false;
}
return self.preview_solid_history(handle, operation);
}
if !crate::scene::model::solid_history::apply_primitive_grip(
&mut operation,
grip_id,