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 <[email protected]>
This commit is contained in:
1 parent
bdde862597
commit
468633c1fe
18 files changed
+264
-275
No files matched your search
@@ -1,3 +1,5 @@
|
||||
// Paste tool — ribbon definition + CadCommand implementation.
|
||||
|
||||
use crate::modules::{IconKind, ModuleEvent, ToolDef};
|
||||
|
||||
pub fn tool() -> ToolDef {
|
||||
@@ -8,3 +10,51 @@ pub fn tool() -> ToolDef {
|
||||
event: ModuleEvent::Command("PASTECLIP".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
// ── CadCommand implementation ─────────────────────────────────────────────
|
||||
|
||||
use acadrust::Handle;
|
||||
use glam::Vec3;
|
||||
|
||||
use crate::command::{CadCommand, CmdResult};
|
||||
use crate::scene::wire_model::WireModel;
|
||||
|
||||
pub struct PasteCommand {
|
||||
/// Wire models of the clipboard entities (used for preview).
|
||||
wires: Vec<WireModel>,
|
||||
/// Centroid of the clipboard entities (offset origin for translation).
|
||||
centroid: Vec3,
|
||||
}
|
||||
|
||||
impl PasteCommand {
|
||||
pub fn new(wires: Vec<WireModel>, centroid: Vec3) -> Self {
|
||||
Self { wires, centroid }
|
||||
}
|
||||
}
|
||||
|
||||
impl CadCommand for PasteCommand {
|
||||
fn name(&self) -> &'static str {
|
||||
"PASTECLIP"
|
||||
}
|
||||
|
||||
fn prompt(&self) -> String {
|
||||
"PASTECLIP Pick insertion point:".into()
|
||||
}
|
||||
|
||||
fn on_point(&mut self, pt: Vec3) -> CmdResult {
|
||||
CmdResult::PasteClipboard { base_pt: pt }
|
||||
}
|
||||
|
||||
fn on_enter(&mut self) -> CmdResult {
|
||||
CmdResult::Cancel
|
||||
}
|
||||
|
||||
fn on_hover_entity(&mut self, _handle: Handle, _pt: Vec3) -> Vec<WireModel> {
|
||||
vec![]
|
||||
}
|
||||
|
||||
fn on_preview_wires(&mut self, pt: Vec3) -> Vec<WireModel> {
|
||||
let delta = pt - self.centroid;
|
||||
self.wires.iter().map(|w| w.translated(delta)).collect()
|
||||
}
|
||||
}
|
||||
@@ -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![]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
pub mod group;
|
||||
pub mod ungroup;
|
||||
@@ -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![]
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
// Match Layer tool — ribbon definition + CadCommand implementation.
|
||||
|
||||
use crate::modules::{IconKind, ModuleEvent, ToolDef};
|
||||
|
||||
pub fn tool() -> ToolDef {
|
||||
@@ -8,3 +10,70 @@ pub fn tool() -> ToolDef {
|
||||
event: ModuleEvent::Command("LAYMATCH".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
// ── CadCommand implementation ─────────────────────────────────────────────
|
||||
|
||||
use acadrust::Handle;
|
||||
use glam::Vec3;
|
||||
|
||||
use crate::command::{CadCommand, CmdResult};
|
||||
use crate::scene::wire_model::WireModel;
|
||||
|
||||
pub struct LayMatchCommand {
|
||||
dest_handles: Vec<Handle>,
|
||||
}
|
||||
|
||||
impl LayMatchCommand {
|
||||
pub fn new(dest: Vec<Handle>) -> Self {
|
||||
Self { dest_handles: dest }
|
||||
}
|
||||
}
|
||||
|
||||
impl CadCommand for LayMatchCommand {
|
||||
fn name(&self) -> &'static str {
|
||||
"LAYMATCH"
|
||||
}
|
||||
|
||||
fn prompt(&self) -> String {
|
||||
if self.dest_handles.is_empty() {
|
||||
"LAYMATCH Select objects to change layer:".into()
|
||||
} else {
|
||||
"LAYMATCH Select source object to match layer from:".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;
|
||||
}
|
||||
if self.dest_handles.is_empty() {
|
||||
// Phase 1 complete — store destinations, move to phase 2.
|
||||
self.dest_handles = handles;
|
||||
CmdResult::NeedPoint
|
||||
} else {
|
||||
// Phase 2 complete — first handle is the source object.
|
||||
let src = handles[0];
|
||||
CmdResult::MatchEntityLayer {
|
||||
dest: std::mem::take(&mut self.dest_handles),
|
||||
src,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn on_point(&mut self, _pt: Vec3) -> CmdResult {
|
||||
CmdResult::NeedPoint
|
||||
}
|
||||
fn on_enter(&mut self) -> CmdResult {
|
||||
CmdResult::Cancel
|
||||
}
|
||||
fn on_escape(&mut self) -> CmdResult {
|
||||
CmdResult::Cancel
|
||||
}
|
||||
fn on_hover_entity(&mut self, _handle: Handle, _pt: Vec3) -> Vec<WireModel> {
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
@@ -6,5 +6,5 @@ pub(super) mod layon;
|
||||
pub(super) mod laythw;
|
||||
pub(super) mod layulk;
|
||||
pub(super) mod make_current;
|
||||
pub(super) mod match_layer;
|
||||
pub mod match_layer;
|
||||
pub(super) mod panel;
|
||||
@@ -1,12 +1,14 @@
|
||||
// Home module — Draw, Modify, Annotation and Layer tools.
|
||||
|
||||
mod clipboard;
|
||||
pub mod clipboard;
|
||||
pub mod defaults;
|
||||
mod donate;
|
||||
pub mod draw;
|
||||
mod layers;
|
||||
pub mod groups;
|
||||
pub mod layers;
|
||||
pub mod modify;
|
||||
mod properties;
|
||||
pub mod properties;
|
||||
pub mod select;
|
||||
|
||||
use crate::modules::{CadModule, RibbonGroup, RibbonItem};
|
||||
|
||||
@@ -27,9 +29,10 @@ impl CadModule for HomeModule {
|
||||
use donate;
|
||||
use draw::{arc, circle, ellipse, hatch, line, polyline, shapes};
|
||||
use layers::{layfrz, laylck, layoff, layon, laythw, layulk, make_current, match_layer, panel};
|
||||
use groups::{group, ungroup};
|
||||
use modify::{
|
||||
array, copy, delete, explode, fillet, group, mirror, offset, rotate, scale, stretch,
|
||||
translate, trim, ungroup,
|
||||
array, copy, delete, explode, fillet, mirror, offset, rotate, scale, stretch,
|
||||
translate, trim,
|
||||
};
|
||||
use properties::match_prop;
|
||||
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
// Group tool — ribbon definition.
|
||||
|
||||
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()),
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ pub mod delete;
|
||||
pub mod explode;
|
||||
mod extend;
|
||||
pub mod fillet;
|
||||
pub mod group;
|
||||
pub mod mirror;
|
||||
pub mod offset;
|
||||
pub mod rotate;
|
||||
@@ -12,4 +11,3 @@ pub mod scale;
|
||||
pub mod stretch;
|
||||
pub mod translate;
|
||||
pub mod trim;
|
||||
pub mod ungroup;
|
||||
@@ -1,12 +0,0 @@
|
||||
// Ungroup tool — ribbon definition.
|
||||
|
||||
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()),
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
@@ -0,0 +1,62 @@
|
||||
// SelectObjectsCommand — generic "select objects then run command" gather phase.
|
||||
//
|
||||
// Used when a modify command is invoked with nothing pre-selected.
|
||||
// The user may single-click, box-select, or polygon-select any number of objects.
|
||||
// After the FIRST completed selection action (regardless of method) the command fires
|
||||
// immediately — no Enter required.
|
||||
|
||||
use acadrust::Handle;
|
||||
use glam::Vec3;
|
||||
|
||||
use crate::command::{CadCommand, CmdResult};
|
||||
use crate::scene::wire_model::WireModel;
|
||||
|
||||
pub struct SelectObjectsCommand {
|
||||
pending_cmd: String,
|
||||
}
|
||||
|
||||
impl SelectObjectsCommand {
|
||||
pub fn new(pending_cmd: &str) -> Self {
|
||||
Self {
|
||||
pending_cmd: pending_cmd.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CadCommand for SelectObjectsCommand {
|
||||
fn name(&self) -> &'static str {
|
||||
"SELECT"
|
||||
}
|
||||
|
||||
fn prompt(&self) -> String {
|
||||
format!("{} Select objects:", self.pending_cmd)
|
||||
}
|
||||
|
||||
// Opt into the selection-gathering path; host routes clicks through
|
||||
// the normal selection system and calls on_selection_complete after each action.
|
||||
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::Relaunch(std::mem::take(&mut self.pending_cmd), handles)
|
||||
}
|
||||
|
||||
// These are never called while is_selection_gathering is true, but the
|
||||
// trait requires implementations.
|
||||
fn on_point(&mut self, _pt: Vec3) -> CmdResult {
|
||||
CmdResult::NeedPoint
|
||||
}
|
||||
fn on_enter(&mut self) -> CmdResult {
|
||||
CmdResult::Cancel
|
||||
}
|
||||
fn on_escape(&mut self) -> CmdResult {
|
||||
CmdResult::Cancel
|
||||
}
|
||||
fn on_hover_entity(&mut self, _handle: Handle, _pt: Vec3) -> Vec<WireModel> {
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user