Co-locate CadCommand impls with their ribbon toolbar modules

Each command implementation is now in the same file as its ribbon
tool definition. Groups moved to a dedicated groups/ toolbar folder.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
Hakan SevenandClaude Sonnet 4.6 committed 2026-03-22 23:21:29 +03:00
1 parent bdde862597
commit 468633c1fe
18 files changed
+264 -275

No files matched your search

+74
View File
@@ -0,0 +1,74 @@
// Group tool — ribbon definition + CadCommand implementation.
use crate::modules::{IconKind, ModuleEvent, ToolDef};
pub fn tool() -> ToolDef {
ToolDef {
id: "GROUP",
label: "Group",
icon: IconKind::Svg(include_bytes!("../../../../assets/icons/group.svg")),
event: ModuleEvent::Command("GROUP".to_string()),
}
}
// ── CadCommand implementation ─────────────────────────────────────────────
use acadrust::Handle;
use glam::Vec3;
use crate::command::{CadCommand, CmdResult};
use crate::scene::wire_model::WireModel;
pub struct GroupCommand {
handles: Vec<Handle>,
/// Auto-generated fallback name shown in the prompt.
auto_name: String,
}
impl GroupCommand {
pub fn new(handles: Vec<Handle>, auto_name: String) -> Self {
Self { handles, auto_name }
}
}
impl CadCommand for GroupCommand {
fn name(&self) -> &'static str {
"GROUP"
}
fn prompt(&self) -> String {
format!("GROUP Enter group name [{}]:", self.auto_name)
}
fn wants_text_input(&self) -> bool {
true
}
fn on_text_input(&mut self, text: &str) -> Option<CmdResult> {
let name = if text.trim().is_empty() {
std::mem::take(&mut self.auto_name)
} else {
text.trim().to_string()
};
Some(CmdResult::CreateGroup {
handles: std::mem::take(&mut self.handles),
name,
})
}
fn on_enter(&mut self) -> CmdResult {
// Enter with no typed name uses the auto-generated name.
CmdResult::CreateGroup {
handles: std::mem::take(&mut self.handles),
name: std::mem::take(&mut self.auto_name),
}
}
fn on_point(&mut self, _pt: Vec3) -> CmdResult {
CmdResult::NeedPoint
}
fn on_hover_entity(&mut self, _handle: Handle, _pt: Vec3) -> Vec<WireModel> {
vec![]
}
}
+2
View File
@@ -0,0 +1,2 @@
pub mod group;
pub mod ungroup;
+61
View File
@@ -0,0 +1,61 @@
// Ungroup tool — ribbon definition + CadCommand implementation.
use crate::modules::{IconKind, ModuleEvent, ToolDef};
pub fn tool() -> ToolDef {
ToolDef {
id: "UNGROUP",
label: "Ungroup",
icon: IconKind::Svg(include_bytes!("../../../../assets/icons/ungroup.svg")),
event: ModuleEvent::Command("UNGROUP".to_string()),
}
}
// ── CadCommand implementation ─────────────────────────────────────────────
use acadrust::Handle;
use glam::Vec3;
use crate::command::{CadCommand, CmdResult};
use crate::scene::wire_model::WireModel;
pub struct UngroupCommand;
impl UngroupCommand {
pub fn new() -> Self {
Self
}
}
impl CadCommand for UngroupCommand {
fn name(&self) -> &'static str {
"UNGROUP"
}
fn prompt(&self) -> String {
"UNGROUP Select grouped objects:".into()
}
fn is_selection_gathering(&self) -> bool {
true
}
fn on_selection_complete(&mut self, handles: Vec<Handle>) -> CmdResult {
if handles.is_empty() {
return CmdResult::NeedPoint;
}
CmdResult::DeleteGroups { handles }
}
fn on_point(&mut self, _pt: Vec3) -> CmdResult {
CmdResult::NeedPoint
}
fn on_enter(&mut self) -> CmdResult {
CmdResult::Cancel
}
fn on_hover_entity(&mut self, _handle: Handle, _pt: Vec3) -> Vec<WireModel> {
vec![]
}
}