cad-editor/src/entities/traits.rs

513 lines
20 KiB
Rust
Raw Normal View History

2026-03-22 14:56:27 +03:00
use acadrust::{CadDocument, EntityType};
use crate::command::EntityTransform;
refactor: drop truck, and evaluate every curve through the kernel The last four truck crates are gone from the manifest. What they were doing falls into three parts, and each now has one answer instead of two. NURBS evaluation. truck was carrying B-spline curves and surfaces for the SPLINE entity, hatch boundaries, BLEND's endpoint frames, the spline preview and ACIS spline-surface faces. The kernel now has both, over one de Boor written across however many coordinates a control point holds — so a plane curve and a space curve cannot drift apart, and a surface is the same algorithm applied twice. The rational and the polynomial cases stop being separate types: weights absent means polynomial. The entity conversion. Every LINE, ARC, ELLIPSE, SPLINE and polyline was built into truck topology purely so it could be sampled back into points. They are sampled through `entities::curve` now, which is where each one's geometry is already defined once and what EXTRUDE and REVOLVE read — so a circle drawn on screen and a circle handed to the Model tab come from the same definition. That retires four of TruckObject's variants and the module is renamed for what it does. SWEEP and LOFT. Both only ever produced a mesh, so both are built from point lists: a band of quads per span, and a lid where a profile closes. Lofting profiles of different densities resamples them by distance rather than by index, so a circle lofted to a square no longer twists. Two things worth noting for anyone reading the old comments. The tolerance globals that lived in the tessellation module were never about truck at all — they are the per-frame chord height, and they move to `curve_tol`. And the rule that a profile handed over as `Lines` silently broke EXTRUDE and REVOLVE no longer holds: those read the curve directly and never look at this channel. The two `automation` test failures are unchanged from before this and are not caused by it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-10 01:08:50 +03:00
use crate::scene::convert::acad_to_render::RenderEntity;
use crate::scene::model::object::{
feat(grip): multi-functional hover popup menu Phase 2 of the grip overhaul: when the cursor dwells on a selected entity's grip the overlay opens a popup menu with entity-specific options (Stretch / Add Vertex / Remove Vertex / Convert to Arc-Line / …). Picking an item dispatches `apply_grip_menu`; the default `Stretch` entry is a no-op that lets the user click the grip to start the normal drag. - `GripMenuItem` + `GripMenuAction` (full vocabulary covering stretch, add/remove vertex, convert to arc/line, reverse arrows, text-position variants, hatch parameters, tangent direction). - `Grippable` trait gains `grip_menu` + `apply_grip_menu` with trait-default `Stretch`-only impls so every existing entity gets the popup for free. - `EntityTypeOps` dispatches both methods across the same entity list as the existing grip / property machinery. - `OpenCADStudio` carries `grip_hover` (dwell tracker) + `grip_popup` (open menu). `update_grip_hover` runs from `ViewportMove`: hit-tests grips, refreshes the dwell timer, and opens the popup after 600 ms. Cursor drift past 80 px or a grip click dismisses it. - `view.rs` paints the popup as an absolute-positioned column of buttons at the grip's screen anchor; each button publishes `Message::GripMenuPick(idx)`. - `LwPolyline` overrides `Grippable` manually (skips the standard macro) so its vertex grip exposes Add/Remove Vertex and its segment-midpoint grip exposes Add Vertex + Convert to Arc/Line. `apply_grip_menu` performs the edits: vertex insertion at the chord midpoint inheriting the previous bulge, vertex removal, and bulge toggle for the arc/line conversion.
2026-05-29 09:30:54 +03:00
GripApply, GripDef, GripMenuAction, GripMenuItem, PropSection,
};
use crate::scene::convert::tess_util::FallbackGeometry;
2026-03-22 14:56:27 +03:00
refactor: drop truck, and evaluate every curve through the kernel The last four truck crates are gone from the manifest. What they were doing falls into three parts, and each now has one answer instead of two. NURBS evaluation. truck was carrying B-spline curves and surfaces for the SPLINE entity, hatch boundaries, BLEND's endpoint frames, the spline preview and ACIS spline-surface faces. The kernel now has both, over one de Boor written across however many coordinates a control point holds — so a plane curve and a space curve cannot drift apart, and a surface is the same algorithm applied twice. The rational and the polynomial cases stop being separate types: weights absent means polynomial. The entity conversion. Every LINE, ARC, ELLIPSE, SPLINE and polyline was built into truck topology purely so it could be sampled back into points. They are sampled through `entities::curve` now, which is where each one's geometry is already defined once and what EXTRUDE and REVOLVE read — so a circle drawn on screen and a circle handed to the Model tab come from the same definition. That retires four of TruckObject's variants and the module is renamed for what it does. SWEEP and LOFT. Both only ever produced a mesh, so both are built from point lists: a band of quads per span, and a lid where a profile closes. Lofting profiles of different densities resamples them by distance rather than by index, so a circle lofted to a square no longer twists. Two things worth noting for anyone reading the old comments. The tolerance globals that lived in the tessellation module were never about truck at all — they are the per-frame chord height, and they move to `curve_tol`. And the rule that a profile handed over as `Lines` silently broke EXTRUDE and REVOLVE no longer holds: those read the curve directly and never look at this channel. The two `automation` test failures are unchanged from before this and are not caused by it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-10 01:08:50 +03:00
pub trait RenderConvertible {
fn to_render(&self, document: &CadDocument) -> Option<RenderEntity>;
2026-03-22 14:56:27 +03:00
}
refactor: drop truck, and evaluate every curve through the kernel The last four truck crates are gone from the manifest. What they were doing falls into three parts, and each now has one answer instead of two. NURBS evaluation. truck was carrying B-spline curves and surfaces for the SPLINE entity, hatch boundaries, BLEND's endpoint frames, the spline preview and ACIS spline-surface faces. The kernel now has both, over one de Boor written across however many coordinates a control point holds — so a plane curve and a space curve cannot drift apart, and a surface is the same algorithm applied twice. The rational and the polynomial cases stop being separate types: weights absent means polynomial. The entity conversion. Every LINE, ARC, ELLIPSE, SPLINE and polyline was built into truck topology purely so it could be sampled back into points. They are sampled through `entities::curve` now, which is where each one's geometry is already defined once and what EXTRUDE and REVOLVE read — so a circle drawn on screen and a circle handed to the Model tab come from the same definition. That retires four of TruckObject's variants and the module is renamed for what it does. SWEEP and LOFT. Both only ever produced a mesh, so both are built from point lists: a band of quads per span, and a lid where a profile closes. Lofting profiles of different densities resamples them by distance rather than by index, so a circle lofted to a square no longer twists. Two things worth noting for anyone reading the old comments. The tolerance globals that lived in the tessellation module were never about truck at all — they are the per-frame chord height, and they move to `curve_tol`. And the rule that a profile handed over as `Lines` silently broke EXTRUDE and REVOLVE no longer holds: those read the curve directly and never look at this channel. The two `automation` test failures are unchanged from before this and are not caused by it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-10 01:08:50 +03:00
/// Fallback geometry for entities not routed through the render
/// pipeline (Viewport, Insert, Hatch outline, Ole2Frame). Returns absolute
/// WCS `f32` points + snap/key vertices the dispatcher wraps into a
/// `WireModel`.
pub trait FallbackTess {
fn fallback_geometry(&self) -> FallbackGeometry;
}
2026-03-22 14:56:27 +03:00
pub trait Grippable {
fn grips(&self) -> Vec<GripDef>;
fn apply_grip(&mut self, grip_id: usize, apply: GripApply);
feat(grip): multi-functional hover popup menu Phase 2 of the grip overhaul: when the cursor dwells on a selected entity's grip the overlay opens a popup menu with entity-specific options (Stretch / Add Vertex / Remove Vertex / Convert to Arc-Line / …). Picking an item dispatches `apply_grip_menu`; the default `Stretch` entry is a no-op that lets the user click the grip to start the normal drag. - `GripMenuItem` + `GripMenuAction` (full vocabulary covering stretch, add/remove vertex, convert to arc/line, reverse arrows, text-position variants, hatch parameters, tangent direction). - `Grippable` trait gains `grip_menu` + `apply_grip_menu` with trait-default `Stretch`-only impls so every existing entity gets the popup for free. - `EntityTypeOps` dispatches both methods across the same entity list as the existing grip / property machinery. - `OpenCADStudio` carries `grip_hover` (dwell tracker) + `grip_popup` (open menu). `update_grip_hover` runs from `ViewportMove`: hit-tests grips, refreshes the dwell timer, and opens the popup after 600 ms. Cursor drift past 80 px or a grip click dismisses it. - `view.rs` paints the popup as an absolute-positioned column of buttons at the grip's screen anchor; each button publishes `Message::GripMenuPick(idx)`. - `LwPolyline` overrides `Grippable` manually (skips the standard macro) so its vertex grip exposes Add/Remove Vertex and its segment-midpoint grip exposes Add Vertex + Convert to Arc/Line. `apply_grip_menu` performs the edits: vertex insertion at the chord midpoint inheriting the previous bulge, vertex removal, and bulge toggle for the arc/line conversion.
2026-05-29 09:30:54 +03:00
/// Items shown in the hover popup that opens when the cursor
/// dwells on a grip. Default is a single `Stretch` entry — i.e.
/// the popup just confirms the default drag behaviour. Override
/// per entity to add Add Vertex / Convert to Arc / Reverse Arrows /
/// etc.
fn grip_menu(&self, _grip_id: usize) -> Vec<GripMenuItem> {
vec![GripMenuItem { label: "Stretch", action: GripMenuAction::Stretch }]
}
/// React to a popup-menu commit. Default no-op — `Stretch` is the
/// "do nothing extra" path, the normal drag still happens on click.
/// Entities override this to mutate themselves when the user picks
/// Add Vertex / Remove Vertex / Convert / Reverse / …
fn apply_grip_menu(&mut self, _grip_id: usize, _action: GripMenuAction) {}
/// Same as `apply_grip_menu` but for actions that need a numeric
/// follow-up (Lengthen / Radius / Arc Length / Rotate Text / …).
/// The app prompts the user for a value on the command line and
/// calls this with the parsed `f64`.
fn apply_grip_menu_value(
&mut self,
_grip_id: usize,
_action: GripMenuAction,
_value: f64,
) {}
/// If the popup action this entity defines for `grip_id` needs a
/// numeric prompt, return the prompt string and the action so the
/// app can stash a pending-value state and route the next typed
/// number into `apply_grip_menu_value`. `None` for one-shot
/// actions handled by `apply_grip_menu`.
fn grip_menu_value_prompt(
&self,
_grip_id: usize,
_action: GripMenuAction,
) -> Option<&'static str> {
None
}
/// Convert an interactive cursor point into the numeric value consumed by
/// `apply_grip_menu_value`. Actions without a point-driven form return
/// `None`.
fn grip_menu_point_value(
&self,
_grip_id: usize,
_action: GripMenuAction,
_point: glam::DVec3,
) -> Option<f64> {
None
}
2026-03-22 14:56:27 +03:00
}
pub trait PropertyEditable {
/// Type-specific property groups (Geometry, Misc, Text, …) shown after the
/// common General group. May be several groups; empty means none.
fn geometry_properties(&self, text_style_names: &[String]) -> Vec<PropSection>;
2026-03-22 14:56:27 +03:00
fn apply_geom_prop(&mut self, field: &str, value: &str);
}
pub trait Transformable {
fn apply_transform(&mut self, t: &EntityTransform);
}
/// Inquiry-time mass / area / perimeter properties for entities whose
/// 2D footprint has a meaningful area or perimeter (Circle, Arc, Line,
/// LwPolyline, Ellipse). Entities outside this set get `None` via the
/// dispatcher.
#[derive(Clone, Copy, Debug)]
pub struct MassProps {
pub area: f64,
pub perimeter: f64,
pub cx: f64,
pub cy: f64,
}
pub trait MassPropsCalc {
fn mass_props(&self) -> MassProps;
}
/// Read / replace the visible string of text-like entities (Text, MText,
/// AttributeDefinition, AttributeEntity). `replace` rewrites every
/// occurrence of `search` with `rep`.
pub trait TextContent {
fn text_content(&self) -> Option<String>;
fn replace_text(&mut self, search: &str, rep: &str);
}
/// Human-readable variant name used by Quick Select / Select Similar
/// filtering. Stable across releases — the strings here are the canonical
/// type identifiers throughout the UI.
pub fn entity_type_name(et: &EntityType) -> &str {
match et {
EntityType::Point(_) => "Point",
EntityType::Line(_) => "Line",
EntityType::Circle(_) => "Circle",
EntityType::Arc(_) => "Arc",
EntityType::Ellipse(_) => "Ellipse",
EntityType::Polyline(_) => "Polyline",
EntityType::Polyline2D(_) => "Polyline2D",
EntityType::Polyline3D(_) => "Polyline3D",
EntityType::LwPolyline(polyline)
if crate::entities::lwpolyline::is_revision_cloud(polyline) =>
{
"Revcloud"
}
EntityType::LwPolyline(_) => "LwPolyline",
EntityType::Text(_) => "Text",
EntityType::MText(_) => "MText",
EntityType::Spline(_) => "Spline",
EntityType::Helix(_) => "Helix",
EntityType::Dimension(_) => "Dimension",
EntityType::Hatch(_) => "Hatch",
EntityType::Solid(_) => "Solid",
EntityType::Face3D(_) => "3DFace",
EntityType::Insert(_) => "Insert",
EntityType::Block(_) => "Block",
EntityType::BlockEnd(_) => "BlockEnd",
EntityType::Ray(_) => "Ray",
EntityType::XLine(_) => "XLine",
EntityType::Viewport(_) => "Viewport",
EntityType::AttributeDefinition(_) => "AttributeDefinition",
EntityType::AttributeEntity(_) => "Attribute",
EntityType::Leader(_) => "Leader",
EntityType::MultiLeader(_) => "MultiLeader",
EntityType::MLine(_) => "MLine",
EntityType::Mesh(_) => "Mesh",
EntityType::RasterImage(_) => "RasterImage",
EntityType::Solid3D(_) => "Solid3D",
EntityType::Region(_) => "Region",
EntityType::Body(_) => "Body",
EntityType::Surface(_) => "Surface",
EntityType::Table(_) => "Table",
EntityType::Tolerance(_) => "Tolerance",
EntityType::PolyfaceMesh(_) => "PolyfaceMesh",
EntityType::Wipeout(_) => "Wipeout",
EntityType::Shape(_) => "Shape",
EntityType::Underlay(_) => "Underlay",
EntityType::Seqend(_) => "Seqend",
EntityType::Ole2Frame(_) => "Ole2Frame",
EntityType::PolygonMesh(_) => "PolygonMesh",
EntityType::Light(_) => "Light",
EntityType::SectionSymbol(_) => "SectionSymbol",
EntityType::ViewBorder(_) => "ViewBorder",
EntityType::Extended(entity) => entity.class_name(),
EntityType::Unknown(_) => "Unknown",
}
}
2026-03-22 14:56:27 +03:00
pub trait EntityTypeOps {
refactor: drop truck, and evaluate every curve through the kernel The last four truck crates are gone from the manifest. What they were doing falls into three parts, and each now has one answer instead of two. NURBS evaluation. truck was carrying B-spline curves and surfaces for the SPLINE entity, hatch boundaries, BLEND's endpoint frames, the spline preview and ACIS spline-surface faces. The kernel now has both, over one de Boor written across however many coordinates a control point holds — so a plane curve and a space curve cannot drift apart, and a surface is the same algorithm applied twice. The rational and the polynomial cases stop being separate types: weights absent means polynomial. The entity conversion. Every LINE, ARC, ELLIPSE, SPLINE and polyline was built into truck topology purely so it could be sampled back into points. They are sampled through `entities::curve` now, which is where each one's geometry is already defined once and what EXTRUDE and REVOLVE read — so a circle drawn on screen and a circle handed to the Model tab come from the same definition. That retires four of TruckObject's variants and the module is renamed for what it does. SWEEP and LOFT. Both only ever produced a mesh, so both are built from point lists: a band of quads per span, and a lid where a profile closes. Lofting profiles of different densities resamples them by distance rather than by index, so a circle lofted to a square no longer twists. Two things worth noting for anyone reading the old comments. The tolerance globals that lived in the tessellation module were never about truck at all — they are the per-frame chord height, and they move to `curve_tol`. And the rule that a profile handed over as `Lines` silently broke EXTRUDE and REVOLVE no longer holds: those read the curve directly and never look at this channel. The two `automation` test failures are unchanged from before this and are not caused by it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-10 01:08:50 +03:00
fn to_render_entity(&self, document: &CadDocument) -> Option<RenderEntity>;
2026-03-22 14:56:27 +03:00
fn grips(&self) -> Vec<GripDef>;
feat(grip): multi-functional hover popup menu Phase 2 of the grip overhaul: when the cursor dwells on a selected entity's grip the overlay opens a popup menu with entity-specific options (Stretch / Add Vertex / Remove Vertex / Convert to Arc-Line / …). Picking an item dispatches `apply_grip_menu`; the default `Stretch` entry is a no-op that lets the user click the grip to start the normal drag. - `GripMenuItem` + `GripMenuAction` (full vocabulary covering stretch, add/remove vertex, convert to arc/line, reverse arrows, text-position variants, hatch parameters, tangent direction). - `Grippable` trait gains `grip_menu` + `apply_grip_menu` with trait-default `Stretch`-only impls so every existing entity gets the popup for free. - `EntityTypeOps` dispatches both methods across the same entity list as the existing grip / property machinery. - `OpenCADStudio` carries `grip_hover` (dwell tracker) + `grip_popup` (open menu). `update_grip_hover` runs from `ViewportMove`: hit-tests grips, refreshes the dwell timer, and opens the popup after 600 ms. Cursor drift past 80 px or a grip click dismisses it. - `view.rs` paints the popup as an absolute-positioned column of buttons at the grip's screen anchor; each button publishes `Message::GripMenuPick(idx)`. - `LwPolyline` overrides `Grippable` manually (skips the standard macro) so its vertex grip exposes Add/Remove Vertex and its segment-midpoint grip exposes Add Vertex + Convert to Arc/Line. `apply_grip_menu` performs the edits: vertex insertion at the chord midpoint inheriting the previous bulge, vertex removal, and bulge toggle for the arc/line conversion.
2026-05-29 09:30:54 +03:00
fn grip_menu(&self, grip_id: usize) -> Vec<GripMenuItem>;
fn geometry_properties(&self, text_style_names: &[String]) -> Vec<PropSection>;
2026-03-22 14:56:27 +03:00
fn apply_geom_prop(&mut self, field: &str, value: &str);
fn apply_grip(&mut self, grip_id: usize, apply: GripApply);
feat(grip): multi-functional hover popup menu Phase 2 of the grip overhaul: when the cursor dwells on a selected entity's grip the overlay opens a popup menu with entity-specific options (Stretch / Add Vertex / Remove Vertex / Convert to Arc-Line / …). Picking an item dispatches `apply_grip_menu`; the default `Stretch` entry is a no-op that lets the user click the grip to start the normal drag. - `GripMenuItem` + `GripMenuAction` (full vocabulary covering stretch, add/remove vertex, convert to arc/line, reverse arrows, text-position variants, hatch parameters, tangent direction). - `Grippable` trait gains `grip_menu` + `apply_grip_menu` with trait-default `Stretch`-only impls so every existing entity gets the popup for free. - `EntityTypeOps` dispatches both methods across the same entity list as the existing grip / property machinery. - `OpenCADStudio` carries `grip_hover` (dwell tracker) + `grip_popup` (open menu). `update_grip_hover` runs from `ViewportMove`: hit-tests grips, refreshes the dwell timer, and opens the popup after 600 ms. Cursor drift past 80 px or a grip click dismisses it. - `view.rs` paints the popup as an absolute-positioned column of buttons at the grip's screen anchor; each button publishes `Message::GripMenuPick(idx)`. - `LwPolyline` overrides `Grippable` manually (skips the standard macro) so its vertex grip exposes Add/Remove Vertex and its segment-midpoint grip exposes Add Vertex + Convert to Arc/Line. `apply_grip_menu` performs the edits: vertex insertion at the chord midpoint inheriting the previous bulge, vertex removal, and bulge toggle for the arc/line conversion.
2026-05-29 09:30:54 +03:00
fn apply_grip_menu(&mut self, grip_id: usize, action: GripMenuAction);
fn grip_menu_value_prompt(
&self,
grip_id: usize,
action: GripMenuAction,
) -> Option<&'static str>;
fn grip_menu_point_value(
&self,
grip_id: usize,
action: GripMenuAction,
point: glam::DVec3,
) -> Option<f64>;
fn apply_grip_menu_value(
&mut self,
grip_id: usize,
action: GripMenuAction,
value: f64,
);
2026-03-22 14:56:27 +03:00
fn apply_transform(&mut self, t: &EntityTransform);
fn mass_props(&self) -> Option<MassProps>;
fn text_content(&self) -> Option<String>;
fn replace_text(&mut self, search: &str, rep: &str);
2026-03-22 14:56:27 +03:00
}
/// Per-dispatch-function entity-variant lists. Adding a new entity that
/// participates in a dispatch = adding one identifier to one list here
/// (instead of one full match arm to each of five `match self` blocks).
///
/// `dispatch!` expands `EntityType::$Variant(e) => $body` for each name.
macro_rules! dispatch {
($self:expr, |$e:ident| $body:expr, [$($variant:ident),* $(,)?], _ => $default:expr $(,)?) => {
match $self {
$(EntityType::$variant($e) => $body,)*
_ => $default,
}
};
}
/// Generates `Grippable`, `PropertyEditable`, `Transformable` trait impls
/// that delegate to identically-named free functions in the entity's own
/// module (`grips`, `apply_grip`, `properties`, `apply_geom_prop`,
/// `apply_transform`). `properties()` is called with `self` only — for
/// text-like entities that need the document's text-style list use
/// [`impl_entity_basics_with_text_styles!`] instead.
#[macro_export]
macro_rules! impl_entity_basics {
($T:ty) => {
impl $crate::entities::traits::Grippable for $T {
fn grips(&self) -> Vec<$crate::scene::model::object::GripDef> {
grips(self)
}
fn apply_grip(
&mut self,
grip_id: usize,
apply: $crate::scene::model::object::GripApply,
) {
apply_grip(self, grip_id, apply);
}
}
impl $crate::entities::traits::PropertyEditable for $T {
fn geometry_properties(
&self,
_text_style_names: &[String],
) -> Vec<$crate::scene::model::object::PropSection> {
properties(self)
}
fn apply_geom_prop(&mut self, field: &str, value: &str) {
apply_geom_prop(self, field, value);
}
}
impl $crate::entities::traits::Transformable for $T {
fn apply_transform(&mut self, t: &$crate::command::EntityTransform) {
apply_transform(self, t);
}
}
};
}
/// Same as [`impl_entity_basics!`] but the entity's `properties(...)` free
/// function takes the document's text-style name list as a second
/// argument (Text, MText, …).
#[macro_export]
macro_rules! impl_entity_basics_with_text_styles {
($T:ty) => {
impl $crate::entities::traits::Grippable for $T {
fn grips(&self) -> Vec<$crate::scene::model::object::GripDef> {
grips(self)
}
fn apply_grip(
&mut self,
grip_id: usize,
apply: $crate::scene::model::object::GripApply,
) {
apply_grip(self, grip_id, apply);
}
}
impl $crate::entities::traits::PropertyEditable for $T {
fn geometry_properties(
&self,
text_style_names: &[String],
) -> Vec<$crate::scene::model::object::PropSection> {
properties(self, text_style_names)
}
fn apply_geom_prop(&mut self, field: &str, value: &str) {
apply_geom_prop(self, field, value);
}
}
impl $crate::entities::traits::Transformable for $T {
fn apply_transform(&mut self, t: &$crate::command::EntityTransform) {
apply_transform(self, t);
}
}
};
}
2026-03-22 14:56:27 +03:00
impl EntityTypeOps for EntityType {
refactor: drop truck, and evaluate every curve through the kernel The last four truck crates are gone from the manifest. What they were doing falls into three parts, and each now has one answer instead of two. NURBS evaluation. truck was carrying B-spline curves and surfaces for the SPLINE entity, hatch boundaries, BLEND's endpoint frames, the spline preview and ACIS spline-surface faces. The kernel now has both, over one de Boor written across however many coordinates a control point holds — so a plane curve and a space curve cannot drift apart, and a surface is the same algorithm applied twice. The rational and the polynomial cases stop being separate types: weights absent means polynomial. The entity conversion. Every LINE, ARC, ELLIPSE, SPLINE and polyline was built into truck topology purely so it could be sampled back into points. They are sampled through `entities::curve` now, which is where each one's geometry is already defined once and what EXTRUDE and REVOLVE read — so a circle drawn on screen and a circle handed to the Model tab come from the same definition. That retires four of TruckObject's variants and the module is renamed for what it does. SWEEP and LOFT. Both only ever produced a mesh, so both are built from point lists: a band of quads per span, and a lid where a profile closes. Lofting profiles of different densities resamples them by distance rather than by index, so a circle lofted to a square no longer twists. Two things worth noting for anyone reading the old comments. The tolerance globals that lived in the tessellation module were never about truck at all — they are the per-frame chord height, and they move to `curve_tol`. And the rule that a profile handed over as `Lines` silently broke EXTRUDE and REVOLVE no longer holds: those read the curve directly and never look at this channel. The two `automation` test failures are unchanged from before this and are not caused by it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-10 01:08:50 +03:00
fn to_render_entity(&self, document: &CadDocument) -> Option<RenderEntity> {
dispatch!(self,
refactor: drop truck, and evaluate every curve through the kernel The last four truck crates are gone from the manifest. What they were doing falls into three parts, and each now has one answer instead of two. NURBS evaluation. truck was carrying B-spline curves and surfaces for the SPLINE entity, hatch boundaries, BLEND's endpoint frames, the spline preview and ACIS spline-surface faces. The kernel now has both, over one de Boor written across however many coordinates a control point holds — so a plane curve and a space curve cannot drift apart, and a surface is the same algorithm applied twice. The rational and the polynomial cases stop being separate types: weights absent means polynomial. The entity conversion. Every LINE, ARC, ELLIPSE, SPLINE and polyline was built into truck topology purely so it could be sampled back into points. They are sampled through `entities::curve` now, which is where each one's geometry is already defined once and what EXTRUDE and REVOLVE read — so a circle drawn on screen and a circle handed to the Model tab come from the same definition. That retires four of TruckObject's variants and the module is renamed for what it does. SWEEP and LOFT. Both only ever produced a mesh, so both are built from point lists: a band of quads per span, and a lid where a profile closes. Lofting profiles of different densities resamples them by distance rather than by index, so a circle lofted to a square no longer twists. Two things worth noting for anyone reading the old comments. The tolerance globals that lived in the tessellation module were never about truck at all — they are the per-frame chord height, and they move to `curve_tol`. And the rule that a profile handed over as `Lines` silently broke EXTRUDE and REVOLVE no longer holds: those read the curve directly and never look at this channel. The two `automation` test failures are unchanged from before this and are not caused by it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-10 01:08:50 +03:00
|e| RenderConvertible::to_render(e, document),
[
Point, Line, Circle, Arc, Ellipse, Spline, LwPolyline,
Polyline, Polyline2D, Polyline3D, Ray, XLine, RasterImage,
Wipeout, AttributeDefinition, AttributeEntity, MLine,
Tolerance, Solid, Face3D, PolygonMesh, PolyfaceMesh, Mesh,
Table, Text, MText, Leader, MultiLeader, Underlay, Shape,
Ole2Frame, Helix, Light, Extended,
],
2026-03-22 14:56:27 +03:00
_ => None,
)
2026-03-22 14:56:27 +03:00
}
fn grips(&self) -> Vec<GripDef> {
dispatch!(self,
|e| Grippable::grips(e),
[
Line, Circle, Arc, Ellipse, LwPolyline, Polyline, Polyline2D,
Polyline3D, Ray, XLine, RasterImage, Wipeout,
AttributeDefinition, AttributeEntity, MLine, Tolerance,
Solid, Solid3D, Region, Body, Surface, Face3D, PolygonMesh,
PolyfaceMesh, Mesh, Table, Point, Spline, Text, MText,
Viewport, Insert, Leader, MultiLeader, Dimension, Hatch,
Underlay, Shape, Ole2Frame, Helix, Light, SectionSymbol,
ViewBorder, Extended,
],
2026-03-22 14:56:27 +03:00
_ => vec![],
)
2026-03-22 14:56:27 +03:00
}
fn geometry_properties(&self, text_style_names: &[String]) -> Vec<PropSection> {
dispatch!(self,
|e| PropertyEditable::geometry_properties(e, text_style_names),
[
Line, Circle, Arc, Ellipse, LwPolyline, Polyline, Polyline2D,
Polyline3D, Ray, XLine, RasterImage, Wipeout,
AttributeDefinition, AttributeEntity, MLine, Tolerance,
Solid, Solid3D, Region, Body, Surface, Face3D, PolygonMesh,
PolyfaceMesh, Mesh, Table, Hatch, Point, Spline, Text, MText,
Viewport, Insert, Dimension, Leader, MultiLeader, Underlay,
Shape, Ole2Frame, Helix, Light, SectionSymbol, ViewBorder,
Extended,
],
_ => vec![],
)
2026-03-22 14:56:27 +03:00
}
fn apply_geom_prop(&mut self, field: &str, value: &str) {
dispatch!(self,
|e| PropertyEditable::apply_geom_prop(e, field, value),
[
Line, Circle, Arc, Ellipse, LwPolyline, Polyline, Polyline2D,
Polyline3D, Ray, XLine, RasterImage, Wipeout,
AttributeDefinition, AttributeEntity, MLine, Tolerance,
Solid, Solid3D, Region, Body, Surface, Face3D, PolygonMesh,
PolyfaceMesh, Mesh, Table, Hatch, Point, Spline, Text, MText,
Viewport, Insert, Dimension, Leader, MultiLeader, Underlay,
Shape, Ole2Frame, Helix, Light, SectionSymbol, ViewBorder,
Extended,
],
_ => {},
)
2026-03-22 14:56:27 +03:00
}
fn apply_grip(&mut self, grip_id: usize, apply: GripApply) {
dispatch!(self,
|e| Grippable::apply_grip(e, grip_id, apply),
[
Line, Circle, Arc, Ellipse, LwPolyline, Polyline, Polyline2D,
Polyline3D, Ray, XLine, RasterImage, Wipeout,
AttributeDefinition, AttributeEntity, MLine, Tolerance,
Solid, Solid3D, Region, Body, Surface, Face3D, PolygonMesh,
PolyfaceMesh, Mesh, Table, Point, Spline, Text, MText,
Viewport, Insert, Leader, MultiLeader, Dimension, Hatch,
Underlay, Shape, Ole2Frame, Helix, Light, SectionSymbol,
ViewBorder, Extended,
],
_ => {},
)
2026-03-22 14:56:27 +03:00
}
feat(grip): multi-functional hover popup menu Phase 2 of the grip overhaul: when the cursor dwells on a selected entity's grip the overlay opens a popup menu with entity-specific options (Stretch / Add Vertex / Remove Vertex / Convert to Arc-Line / …). Picking an item dispatches `apply_grip_menu`; the default `Stretch` entry is a no-op that lets the user click the grip to start the normal drag. - `GripMenuItem` + `GripMenuAction` (full vocabulary covering stretch, add/remove vertex, convert to arc/line, reverse arrows, text-position variants, hatch parameters, tangent direction). - `Grippable` trait gains `grip_menu` + `apply_grip_menu` with trait-default `Stretch`-only impls so every existing entity gets the popup for free. - `EntityTypeOps` dispatches both methods across the same entity list as the existing grip / property machinery. - `OpenCADStudio` carries `grip_hover` (dwell tracker) + `grip_popup` (open menu). `update_grip_hover` runs from `ViewportMove`: hit-tests grips, refreshes the dwell timer, and opens the popup after 600 ms. Cursor drift past 80 px or a grip click dismisses it. - `view.rs` paints the popup as an absolute-positioned column of buttons at the grip's screen anchor; each button publishes `Message::GripMenuPick(idx)`. - `LwPolyline` overrides `Grippable` manually (skips the standard macro) so its vertex grip exposes Add/Remove Vertex and its segment-midpoint grip exposes Add Vertex + Convert to Arc/Line. `apply_grip_menu` performs the edits: vertex insertion at the chord midpoint inheriting the previous bulge, vertex removal, and bulge toggle for the arc/line conversion.
2026-05-29 09:30:54 +03:00
fn grip_menu(&self, grip_id: usize) -> Vec<GripMenuItem> {
dispatch!(self,
|e| Grippable::grip_menu(e, grip_id),
[
Line, Circle, Arc, Ellipse, LwPolyline, Polyline, Polyline2D,
Polyline3D, Ray, XLine, RasterImage, Wipeout,
AttributeDefinition, AttributeEntity, MLine, Tolerance,
Solid, Solid3D, Region, Body, Surface, Face3D, PolygonMesh,
feat(grip): multi-functional hover popup menu Phase 2 of the grip overhaul: when the cursor dwells on a selected entity's grip the overlay opens a popup menu with entity-specific options (Stretch / Add Vertex / Remove Vertex / Convert to Arc-Line / …). Picking an item dispatches `apply_grip_menu`; the default `Stretch` entry is a no-op that lets the user click the grip to start the normal drag. - `GripMenuItem` + `GripMenuAction` (full vocabulary covering stretch, add/remove vertex, convert to arc/line, reverse arrows, text-position variants, hatch parameters, tangent direction). - `Grippable` trait gains `grip_menu` + `apply_grip_menu` with trait-default `Stretch`-only impls so every existing entity gets the popup for free. - `EntityTypeOps` dispatches both methods across the same entity list as the existing grip / property machinery. - `OpenCADStudio` carries `grip_hover` (dwell tracker) + `grip_popup` (open menu). `update_grip_hover` runs from `ViewportMove`: hit-tests grips, refreshes the dwell timer, and opens the popup after 600 ms. Cursor drift past 80 px or a grip click dismisses it. - `view.rs` paints the popup as an absolute-positioned column of buttons at the grip's screen anchor; each button publishes `Message::GripMenuPick(idx)`. - `LwPolyline` overrides `Grippable` manually (skips the standard macro) so its vertex grip exposes Add/Remove Vertex and its segment-midpoint grip exposes Add Vertex + Convert to Arc/Line. `apply_grip_menu` performs the edits: vertex insertion at the chord midpoint inheriting the previous bulge, vertex removal, and bulge toggle for the arc/line conversion.
2026-05-29 09:30:54 +03:00
PolyfaceMesh, Mesh, Table, Point, Spline, Text, MText,
Viewport, Insert, Leader, MultiLeader, Dimension, Hatch,
Underlay, Shape, Ole2Frame, SectionSymbol, ViewBorder,
Extended,
feat(grip): multi-functional hover popup menu Phase 2 of the grip overhaul: when the cursor dwells on a selected entity's grip the overlay opens a popup menu with entity-specific options (Stretch / Add Vertex / Remove Vertex / Convert to Arc-Line / …). Picking an item dispatches `apply_grip_menu`; the default `Stretch` entry is a no-op that lets the user click the grip to start the normal drag. - `GripMenuItem` + `GripMenuAction` (full vocabulary covering stretch, add/remove vertex, convert to arc/line, reverse arrows, text-position variants, hatch parameters, tangent direction). - `Grippable` trait gains `grip_menu` + `apply_grip_menu` with trait-default `Stretch`-only impls so every existing entity gets the popup for free. - `EntityTypeOps` dispatches both methods across the same entity list as the existing grip / property machinery. - `OpenCADStudio` carries `grip_hover` (dwell tracker) + `grip_popup` (open menu). `update_grip_hover` runs from `ViewportMove`: hit-tests grips, refreshes the dwell timer, and opens the popup after 600 ms. Cursor drift past 80 px or a grip click dismisses it. - `view.rs` paints the popup as an absolute-positioned column of buttons at the grip's screen anchor; each button publishes `Message::GripMenuPick(idx)`. - `LwPolyline` overrides `Grippable` manually (skips the standard macro) so its vertex grip exposes Add/Remove Vertex and its segment-midpoint grip exposes Add Vertex + Convert to Arc/Line. `apply_grip_menu` performs the edits: vertex insertion at the chord midpoint inheriting the previous bulge, vertex removal, and bulge toggle for the arc/line conversion.
2026-05-29 09:30:54 +03:00
],
_ => vec![],
)
}
fn apply_grip_menu(&mut self, grip_id: usize, action: GripMenuAction) {
dispatch!(self,
|e| Grippable::apply_grip_menu(e, grip_id, action),
[
Line, Circle, Arc, Ellipse, LwPolyline, Polyline, Polyline2D,
Polyline3D, Ray, XLine, RasterImage, Wipeout,
AttributeDefinition, AttributeEntity, MLine, Tolerance,
Solid, Solid3D, Region, Body, Surface, Face3D, PolygonMesh,
feat(grip): multi-functional hover popup menu Phase 2 of the grip overhaul: when the cursor dwells on a selected entity's grip the overlay opens a popup menu with entity-specific options (Stretch / Add Vertex / Remove Vertex / Convert to Arc-Line / …). Picking an item dispatches `apply_grip_menu`; the default `Stretch` entry is a no-op that lets the user click the grip to start the normal drag. - `GripMenuItem` + `GripMenuAction` (full vocabulary covering stretch, add/remove vertex, convert to arc/line, reverse arrows, text-position variants, hatch parameters, tangent direction). - `Grippable` trait gains `grip_menu` + `apply_grip_menu` with trait-default `Stretch`-only impls so every existing entity gets the popup for free. - `EntityTypeOps` dispatches both methods across the same entity list as the existing grip / property machinery. - `OpenCADStudio` carries `grip_hover` (dwell tracker) + `grip_popup` (open menu). `update_grip_hover` runs from `ViewportMove`: hit-tests grips, refreshes the dwell timer, and opens the popup after 600 ms. Cursor drift past 80 px or a grip click dismisses it. - `view.rs` paints the popup as an absolute-positioned column of buttons at the grip's screen anchor; each button publishes `Message::GripMenuPick(idx)`. - `LwPolyline` overrides `Grippable` manually (skips the standard macro) so its vertex grip exposes Add/Remove Vertex and its segment-midpoint grip exposes Add Vertex + Convert to Arc/Line. `apply_grip_menu` performs the edits: vertex insertion at the chord midpoint inheriting the previous bulge, vertex removal, and bulge toggle for the arc/line conversion.
2026-05-29 09:30:54 +03:00
PolyfaceMesh, Mesh, Table, Point, Spline, Text, MText,
Viewport, Insert, Leader, MultiLeader, Dimension, Hatch,
Underlay, Shape, Ole2Frame, SectionSymbol, ViewBorder,
Extended,
feat(grip): multi-functional hover popup menu Phase 2 of the grip overhaul: when the cursor dwells on a selected entity's grip the overlay opens a popup menu with entity-specific options (Stretch / Add Vertex / Remove Vertex / Convert to Arc-Line / …). Picking an item dispatches `apply_grip_menu`; the default `Stretch` entry is a no-op that lets the user click the grip to start the normal drag. - `GripMenuItem` + `GripMenuAction` (full vocabulary covering stretch, add/remove vertex, convert to arc/line, reverse arrows, text-position variants, hatch parameters, tangent direction). - `Grippable` trait gains `grip_menu` + `apply_grip_menu` with trait-default `Stretch`-only impls so every existing entity gets the popup for free. - `EntityTypeOps` dispatches both methods across the same entity list as the existing grip / property machinery. - `OpenCADStudio` carries `grip_hover` (dwell tracker) + `grip_popup` (open menu). `update_grip_hover` runs from `ViewportMove`: hit-tests grips, refreshes the dwell timer, and opens the popup after 600 ms. Cursor drift past 80 px or a grip click dismisses it. - `view.rs` paints the popup as an absolute-positioned column of buttons at the grip's screen anchor; each button publishes `Message::GripMenuPick(idx)`. - `LwPolyline` overrides `Grippable` manually (skips the standard macro) so its vertex grip exposes Add/Remove Vertex and its segment-midpoint grip exposes Add Vertex + Convert to Arc/Line. `apply_grip_menu` performs the edits: vertex insertion at the chord midpoint inheriting the previous bulge, vertex removal, and bulge toggle for the arc/line conversion.
2026-05-29 09:30:54 +03:00
],
_ => {},
)
}
fn grip_menu_value_prompt(
&self,
grip_id: usize,
action: GripMenuAction,
) -> Option<&'static str> {
dispatch!(self,
|e| Grippable::grip_menu_value_prompt(e, grip_id, action),
[
Line, Circle, Arc, Ellipse, LwPolyline, Polyline, Polyline2D,
Polyline3D, Ray, XLine, RasterImage, Wipeout,
AttributeDefinition, AttributeEntity, MLine, Tolerance,
Solid, Solid3D, Region, Body, Surface, Face3D, PolygonMesh,
PolyfaceMesh, Mesh, Table, Point, Spline, Text, MText,
Viewport, Insert, Leader, MultiLeader, Dimension, Hatch,
Underlay, Shape, Ole2Frame, SectionSymbol, ViewBorder,
Extended,
],
_ => None,
)
}
fn grip_menu_point_value(
&self,
grip_id: usize,
action: GripMenuAction,
point: glam::DVec3,
) -> Option<f64> {
dispatch!(self,
|e| Grippable::grip_menu_point_value(e, grip_id, action, point),
[
Line, Circle, Arc, Ellipse, LwPolyline, Polyline, Polyline2D,
Polyline3D, Ray, XLine, RasterImage, Wipeout,
AttributeDefinition, AttributeEntity, MLine, Tolerance,
Solid, Solid3D, Region, Body, Surface, Face3D, PolygonMesh,
PolyfaceMesh, Mesh, Table, Point, Spline, Text, MText,
Viewport, Insert, Leader, MultiLeader, Dimension, Hatch,
Underlay, Shape, Ole2Frame, SectionSymbol, ViewBorder,
Extended,
],
_ => None,
)
}
fn apply_grip_menu_value(
&mut self,
grip_id: usize,
action: GripMenuAction,
value: f64,
) {
dispatch!(self,
|e| Grippable::apply_grip_menu_value(e, grip_id, action, value),
[
Line, Circle, Arc, Ellipse, LwPolyline, Polyline, Polyline2D,
Polyline3D, Ray, XLine, RasterImage, Wipeout,
AttributeDefinition, AttributeEntity, MLine, Tolerance,
Solid, Solid3D, Region, Body, Surface, Face3D, PolygonMesh,
PolyfaceMesh, Mesh, Table, Point, Spline, Text, MText,
Viewport, Insert, Leader, MultiLeader, Dimension, Hatch,
Underlay, Shape, Ole2Frame, SectionSymbol, ViewBorder,
],
_ => {},
)
}
2026-03-22 14:56:27 +03:00
fn apply_transform(&mut self, t: &EntityTransform) {
dispatch!(self,
|e| Transformable::apply_transform(e, t),
[
Arc, Circle, Ellipse, Hatch, Insert, Line, LwPolyline,
Polyline, Polyline2D, Polyline3D, Ray, XLine, RasterImage,
Wipeout, AttributeDefinition, AttributeEntity, MLine,
Tolerance, Solid, Face3D, PolygonMesh, PolyfaceMesh, Mesh,
Table, MText, Point, Spline, Text, Viewport, Dimension,
Leader, MultiLeader, Underlay, Shape, Ole2Frame,
Solid3D, Region, Body, Surface, Helix, Light, SectionSymbol,
ViewBorder, Extended,
],
_ => {},
)
2026-03-22 14:56:27 +03:00
}
fn mass_props(&self) -> Option<MassProps> {
dispatch!(self,
|e| Some(MassPropsCalc::mass_props(e)),
[Circle, Arc, Line, LwPolyline, Ellipse],
_ => None,
)
}
fn text_content(&self) -> Option<String> {
dispatch!(self,
|e| TextContent::text_content(e),
[Text, MText, AttributeDefinition, AttributeEntity],
_ => None,
)
}
fn replace_text(&mut self, search: &str, rep: &str) {
dispatch!(self,
|e| TextContent::replace_text(e, search, rep),
[Text, MText, AttributeDefinition, AttributeEntity],
_ => {},
)
}
2026-03-22 14:56:27 +03:00
}