forked from 1b-agent/opencadstudio-upstream
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
bdde862597
commit
468633c1fe
18 files changed
+264
-275
No files matched your search
@@ -1,4 +1,4 @@
|
||||
// Match Properties tool — ribbon definition.
|
||||
// Match Properties tool — ribbon definition + CadCommand implementation.
|
||||
|
||||
use crate::modules::{IconKind, ModuleEvent, ToolDef};
|
||||
|
||||
@@ -10,3 +10,82 @@ pub fn tool() -> ToolDef {
|
||||
event: ModuleEvent::Command("MATCHPROP".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
// ── CadCommand implementation ─────────────────────────────────────────────
|
||||
|
||||
use acadrust::Handle;
|
||||
use glam::Vec3;
|
||||
|
||||
use crate::command::{CadCommand, CmdResult};
|
||||
use crate::scene::wire_model::WireModel;
|
||||
|
||||
pub struct MatchPropCommand {
|
||||
/// Source handle; NULL until phase 1 is complete.
|
||||
src: Handle,
|
||||
}
|
||||
|
||||
impl MatchPropCommand {
|
||||
pub fn new() -> Self {
|
||||
Self { src: Handle::NULL }
|
||||
}
|
||||
|
||||
fn phase1_done(&self) -> bool {
|
||||
!self.src.is_null()
|
||||
}
|
||||
}
|
||||
|
||||
impl CadCommand for MatchPropCommand {
|
||||
fn name(&self) -> &'static str {
|
||||
"MATCHPROP"
|
||||
}
|
||||
|
||||
fn prompt(&self) -> String {
|
||||
if !self.phase1_done() {
|
||||
"MATCHPROP Select source object:".into()
|
||||
} else {
|
||||
"MATCHPROP Select destination objects (Enter to apply):".into()
|
||||
}
|
||||
}
|
||||
|
||||
// ── Phase 1: single entity pick ───────────────────────────────────────
|
||||
|
||||
fn needs_entity_pick(&self) -> bool {
|
||||
!self.phase1_done()
|
||||
}
|
||||
|
||||
fn on_entity_pick(&mut self, handle: Handle, _pt: Vec3) -> CmdResult {
|
||||
if handle.is_null() {
|
||||
return CmdResult::NeedPoint; // nothing hit, keep waiting
|
||||
}
|
||||
self.src = handle;
|
||||
CmdResult::NeedPoint // move to phase 2 (selection gathering)
|
||||
}
|
||||
|
||||
// ── Phase 2: destination selection gathering ──────────────────────────
|
||||
|
||||
fn is_selection_gathering(&self) -> bool {
|
||||
self.phase1_done()
|
||||
}
|
||||
|
||||
fn on_selection_complete(&mut self, handles: Vec<Handle>) -> CmdResult {
|
||||
if handles.is_empty() {
|
||||
return CmdResult::NeedPoint;
|
||||
}
|
||||
CmdResult::MatchProperties {
|
||||
dest: handles,
|
||||
src: self.src,
|
||||
}
|
||||
}
|
||||
|
||||
fn on_enter(&mut self) -> CmdResult {
|
||||
CmdResult::Cancel
|
||||
}
|
||||
|
||||
fn on_point(&mut self, _pt: Vec3) -> CmdResult {
|
||||
CmdResult::NeedPoint
|
||||
}
|
||||
|
||||
fn on_hover_entity(&mut self, _handle: Handle, _pt: Vec3) -> Vec<WireModel> {
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
pub(super) mod match_prop;
|
||||
pub mod match_prop;
|
||||
Reference in new issue
Block a user