2026-03-22 14:56:27 +03:00
|
|
|
use acadrust::entities::Insert;
|
|
|
|
|
use acadrust::types::{Transform, Vector3};
|
2026-05-23 23:26:14 +03:00
|
|
|
use acadrust::{EntityType, Handle};
|
2026-03-22 14:56:27 +03:00
|
|
|
use glam::Vec3;
|
|
|
|
|
|
|
|
|
|
use crate::command::EntityTransform;
|
|
|
|
|
use crate::entities::common::{edit_prop as edit, parse_f64, ro_prop as ro, square_grip};
|
refactor(entities): collapse trait wrapper boilerplate via macro
Every entity file ended with the same three-trait wrapper block:
impl Grippable for T {
fn grips(&self) -> Vec<GripDef> { grips(self) }
fn apply_grip(&mut self, ...) { apply_grip(self, ...) }
}
impl PropertyEditable for T { ... }
impl Transformable for T { ... }
— 23 lines of pure delegation around five same-named free functions.
Replace with `crate::impl_entity_basics!(T);` (a macro in
entities/traits.rs that expands to the three trait impls).
Applied where the file already follows the free-fn delegation
convention (Arc, Circle, Ellipse, Insert, Leader, Line, LwPolyline,
MultiLeader, Ole2Frame, Point, Spline, Viewport). Files that inlined
the trait method bodies directly (Ray, XLine, Shape, Solid, Tolerance,
MLine, Mesh, Solid3D/Region/Body, Table, RasterImage, Wipeout,
Underlay, Hatch, Polyline, Polyline2D, Polyline3D, Dimension) left
alone — they already skip the indirection. Text/MText/Attribute use
the with-text-style flavour and will move once that variant is needed
beyond the existing two manual impls.
A second macro `impl_entity_basics_with_text_styles!` is included for
the text-like flavour but no entity uses it yet.
Net: -204 lines.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-26 17:16:06 +03:00
|
|
|
|
2026-03-22 14:56:27 +03:00
|
|
|
use crate::scene::object::{GripApply, GripDef, PropSection};
|
2026-05-23 23:26:14 +03:00
|
|
|
use crate::scene::{block_cache, render, tessellate};
|
|
|
|
|
use crate::scene::wire_model::WireModel;
|
2026-03-22 14:56:27 +03:00
|
|
|
|
|
|
|
|
fn grips(ins: &Insert) -> Vec<GripDef> {
|
|
|
|
|
let p = Vec3::new(
|
|
|
|
|
ins.insert_point.x as f32,
|
|
|
|
|
ins.insert_point.y as f32,
|
|
|
|
|
ins.insert_point.z as f32,
|
|
|
|
|
);
|
|
|
|
|
vec![square_grip(0, p)]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn properties(ins: &Insert) -> PropSection {
|
|
|
|
|
PropSection {
|
|
|
|
|
title: "Geometry".into(),
|
|
|
|
|
props: vec![
|
|
|
|
|
edit("Insert X", "ins_x", ins.insert_point.x),
|
|
|
|
|
edit("Insert Y", "ins_y", ins.insert_point.y),
|
|
|
|
|
edit("Insert Z", "ins_z", ins.insert_point.z),
|
|
|
|
|
edit("Scale X", "x_scale", ins.x_scale()),
|
|
|
|
|
edit("Scale Y", "y_scale", ins.y_scale()),
|
|
|
|
|
edit("Scale Z", "z_scale", ins.z_scale()),
|
|
|
|
|
edit("Rotation", "rotation", ins.rotation.to_degrees()),
|
|
|
|
|
ro("Block", "block", ins.block_name.clone()),
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn apply_geom_prop(ins: &mut Insert, field: &str, value: &str) {
|
|
|
|
|
let Some(v) = parse_f64(value) else {
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
match field {
|
|
|
|
|
"ins_x" => ins.insert_point.x = v,
|
|
|
|
|
"ins_y" => ins.insert_point.y = v,
|
|
|
|
|
"ins_z" => ins.insert_point.z = v,
|
|
|
|
|
"x_scale" => ins.set_x_scale(v),
|
|
|
|
|
"y_scale" => ins.set_y_scale(v),
|
|
|
|
|
"z_scale" => ins.set_z_scale(v),
|
|
|
|
|
"rotation" => ins.rotation = v.to_radians(),
|
|
|
|
|
_ => {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn apply_grip(ins: &mut Insert, _grip_id: usize, apply: GripApply) {
|
|
|
|
|
match apply {
|
|
|
|
|
GripApply::Absolute(p) => {
|
|
|
|
|
ins.insert_point.x = p.x as f64;
|
|
|
|
|
ins.insert_point.y = p.y as f64;
|
|
|
|
|
ins.insert_point.z = p.z as f64;
|
|
|
|
|
}
|
|
|
|
|
GripApply::Translate(d) => {
|
|
|
|
|
ins.insert_point.x += d.x as f64;
|
|
|
|
|
ins.insert_point.y += d.y as f64;
|
|
|
|
|
ins.insert_point.z += d.z as f64;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn apply_transform(ins: &mut Insert, t: &EntityTransform) {
|
|
|
|
|
crate::scene::transform::apply_standard_entity_transform(ins, t, |entity, p1, p2| {
|
|
|
|
|
let dx = (p2.x - p1.x) as f64;
|
|
|
|
|
let dy = (p2.y - p1.y) as f64;
|
|
|
|
|
let len = (dx * dx + dy * dy).sqrt();
|
|
|
|
|
if len < 1e-12 {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let ux = dx / len;
|
|
|
|
|
let uy = dy / len;
|
|
|
|
|
let mirror = acadrust::types::Matrix4 {
|
|
|
|
|
m: [
|
|
|
|
|
[2.0 * ux * ux - 1.0, 2.0 * ux * uy, 0.0, 0.0],
|
|
|
|
|
[2.0 * ux * uy, 2.0 * uy * uy - 1.0, 0.0, 0.0],
|
|
|
|
|
[0.0, 0.0, 1.0, 0.0],
|
|
|
|
|
[0.0, 0.0, 0.0, 1.0],
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
let t = Transform::from_translation(Vector3::new(-(p1.x as f64), -(p1.y as f64), 0.0))
|
|
|
|
|
.then(&Transform::from_matrix(mirror))
|
2026-05-12 10:36:15 +03:00
|
|
|
.then(&Transform::from_translation(Vector3::new(
|
|
|
|
|
p1.x as f64,
|
|
|
|
|
p1.y as f64,
|
|
|
|
|
0.0,
|
|
|
|
|
)));
|
2026-03-22 14:56:27 +03:00
|
|
|
acadrust::Entity::apply_transform(entity, &t);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
refactor(entities): collapse trait wrapper boilerplate via macro
Every entity file ended with the same three-trait wrapper block:
impl Grippable for T {
fn grips(&self) -> Vec<GripDef> { grips(self) }
fn apply_grip(&mut self, ...) { apply_grip(self, ...) }
}
impl PropertyEditable for T { ... }
impl Transformable for T { ... }
— 23 lines of pure delegation around five same-named free functions.
Replace with `crate::impl_entity_basics!(T);` (a macro in
entities/traits.rs that expands to the three trait impls).
Applied where the file already follows the free-fn delegation
convention (Arc, Circle, Ellipse, Insert, Leader, Line, LwPolyline,
MultiLeader, Ole2Frame, Point, Spline, Viewport). Files that inlined
the trait method bodies directly (Ray, XLine, Shape, Solid, Tolerance,
MLine, Mesh, Solid3D/Region/Body, Table, RasterImage, Wipeout,
Underlay, Hatch, Polyline, Polyline2D, Polyline3D, Dimension) left
alone — they already skip the indirection. Text/MText/Attribute use
the with-text-style flavour and will move once that variant is needed
beyond the existing two manual impls.
A second macro `impl_entity_basics_with_text_styles!` is included for
the text-like flavour but no entity uses it yet.
Net: -204 lines.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-26 17:16:06 +03:00
|
|
|
crate::impl_entity_basics!(Insert);
|
refactor(tess): move per-entity tessellation into entities/
Each entity's tessellation now lives alongside its definition in
entities/*.rs, attached to the entity type via a local trait:
LegacyTess — Viewport / Insert / Hatch / Ole2Frame
(fallback path for entities not on the truck pipeline)
LeaderTess — Leader
MultiLeaderTess — MultiLeader
DimensionTess — Dimension (carries its dim-only helpers too:
~1700 lines of dim_geometry, dim_text_*, format_*,
tolerance, suppression, etc.)
scene/tessellate.rs keeps only the cross-entity dispatcher plus the
shared dim machinery reused by leader/multileader/dimension
(ArrowKind, DimGeom, append_arrow, arrow_from_block, add_segment,
add_polyline, normalized_or, push_tri, color_or_inherit, entity_z,
offset_snap_pts). Cross-entity arc helpers + aci_to_rgba moved to
scene/tess_util.rs.
scene/tessellate.rs shrinks from ~3300 to 809 lines. Compile clean,
all 9 tests pass.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-23 23:12:27 +03:00
|
|
|
|
2026-05-23 23:16:57 +03:00
|
|
|
impl crate::entities::traits::FallbackTess for Insert {
|
|
|
|
|
fn fallback_geometry(&self, world_offset: [f64; 3]) -> crate::scene::tess_util::FallbackGeometry {
|
refactor(tess): move per-entity tessellation into entities/
Each entity's tessellation now lives alongside its definition in
entities/*.rs, attached to the entity type via a local trait:
LegacyTess — Viewport / Insert / Hatch / Ole2Frame
(fallback path for entities not on the truck pipeline)
LeaderTess — Leader
MultiLeaderTess — MultiLeader
DimensionTess — Dimension (carries its dim-only helpers too:
~1700 lines of dim_geometry, dim_text_*, format_*,
tolerance, suppression, etc.)
scene/tessellate.rs keeps only the cross-entity dispatcher plus the
shared dim machinery reused by leader/multileader/dimension
(ArrowKind, DimGeom, append_arrow, arrow_from_block, add_segment,
add_polyline, normalized_or, push_tri, color_or_inherit, entity_z,
offset_snap_pts). Cross-entity arc helpers + aci_to_rgba moved to
scene/tess_util.rs.
scene/tessellate.rs shrinks from ~3300 to 809 lines. Compile clean,
all 9 tests pass.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-23 23:12:27 +03:00
|
|
|
let [ox, oy, oz] = world_offset;
|
|
|
|
|
let ip = Vec3::new(
|
|
|
|
|
(self.insert_point.x - ox) as f32,
|
|
|
|
|
(self.insert_point.y - oy) as f32,
|
|
|
|
|
(self.insert_point.z - oz) as f32,
|
|
|
|
|
);
|
|
|
|
|
let s = 0.1_f32;
|
|
|
|
|
let pts = vec![
|
|
|
|
|
[ip.x - s, ip.y, ip.z],
|
|
|
|
|
[ip.x + s, ip.y, ip.z],
|
|
|
|
|
[ip.x, ip.y - s, ip.z],
|
|
|
|
|
[ip.x, ip.y + s, ip.z],
|
|
|
|
|
];
|
|
|
|
|
(
|
|
|
|
|
pts,
|
|
|
|
|
vec![(ip, crate::scene::wire_model::SnapHint::Insertion)],
|
|
|
|
|
vec![],
|
|
|
|
|
vec![],
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-05-23 23:26:14 +03:00
|
|
|
pub(crate) fn append_insert_attribute_wires(
|
|
|
|
|
wires: &mut Vec<WireModel>,
|
|
|
|
|
document: &acadrust::CadDocument,
|
|
|
|
|
ins: &acadrust::entities::Insert,
|
|
|
|
|
insert_handle: Handle,
|
|
|
|
|
sel: bool,
|
|
|
|
|
ins_color: [f32; 4],
|
|
|
|
|
ins_pat_len: f32,
|
|
|
|
|
ins_pat: [f32; 8],
|
|
|
|
|
ins_lw_px: f32,
|
|
|
|
|
bg_color: [f32; 4],
|
|
|
|
|
is_xref: bool,
|
|
|
|
|
pslt_factor: f32,
|
|
|
|
|
anno_scale: f32,
|
|
|
|
|
world_offset: [f64; 3],
|
|
|
|
|
) {
|
|
|
|
|
if ins.attributes.is_empty() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// ATTMODE (header.attribute_visibility):
|
|
|
|
|
// 0 = Off — every attribute hidden
|
|
|
|
|
// 1 = Normal — honour per-attribute `invisible` flag (default)
|
|
|
|
|
// 2 = On — every attribute forced visible, ignoring its flag
|
|
|
|
|
let attmode = document.header.attribute_visibility;
|
|
|
|
|
if attmode == 0 {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for attr in &ins.attributes {
|
|
|
|
|
let per_attr_hidden = attr.common.invisible || attr.flags.invisible;
|
|
|
|
|
if attmode == 1 && per_attr_hidden {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
let attr_entity = EntityType::AttributeEntity(attr.clone());
|
|
|
|
|
let (sub_color, sub_plen, sub_pat, sub_lw_px, sub_aci) =
|
|
|
|
|
render::render_style_for_block_sub(
|
|
|
|
|
document,
|
|
|
|
|
&attr_entity,
|
|
|
|
|
ins_color,
|
|
|
|
|
ins_pat_len,
|
|
|
|
|
ins_pat,
|
|
|
|
|
ins_lw_px,
|
|
|
|
|
);
|
|
|
|
|
let sub_color = render::adapt_to_bg(sub_color, bg_color);
|
|
|
|
|
let sub_color = if is_xref && !sel {
|
|
|
|
|
block_cache::fade_toward_bg(sub_color, bg_color)
|
|
|
|
|
} else {
|
|
|
|
|
sub_color
|
|
|
|
|
};
|
|
|
|
|
let sub_aabb = crate::scene::entity_aabb(&attr_entity, world_offset);
|
|
|
|
|
let mut attr_wires = tessellate::tessellate(
|
|
|
|
|
document,
|
|
|
|
|
insert_handle,
|
|
|
|
|
&attr_entity,
|
|
|
|
|
sel,
|
|
|
|
|
sub_color,
|
|
|
|
|
sub_plen * pslt_factor,
|
|
|
|
|
sub_pat.map(|v| v * pslt_factor),
|
|
|
|
|
sub_lw_px,
|
|
|
|
|
world_offset,
|
|
|
|
|
anno_scale,
|
|
|
|
|
);
|
|
|
|
|
// Use the INSERT's handle so selection / picking groups attribute
|
|
|
|
|
// text with the parent insert instead of treating it as a stray text.
|
|
|
|
|
for w in &mut attr_wires {
|
|
|
|
|
w.name = insert_handle.value().to_string();
|
|
|
|
|
w.aci = sub_aci;
|
|
|
|
|
w.aabb = sub_aabb;
|
|
|
|
|
}
|
|
|
|
|
wires.extend(attr_wires);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|