forked from 1b-agent/opencadstudio-upstream
feat(model): align polysolid workflow
This commit is contained in:
1 parent
6d6defa0ad
commit
1dd6b115cf
12 files changed
+857
-250
No files matched your search
+1
-98
@@ -1127,104 +1127,6 @@ impl CadCommand for TCountCommand {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Generic front-end for a two-value command that operates on the current
|
||||
/// selection (POLYSOLID width + height on a selected polyline). Gathers a
|
||||
/// selection first when none is set, prompts for two values, and dispatches
|
||||
/// `<name> <first> <second>` to the inline handler.
|
||||
pub struct SelectThenTwoValueCommand {
|
||||
name: &'static str,
|
||||
prompt1: &'static str,
|
||||
prompt2: &'static str,
|
||||
gathering: bool,
|
||||
selected: Vec<Handle>,
|
||||
first: Option<String>,
|
||||
}
|
||||
|
||||
impl SelectThenTwoValueCommand {
|
||||
pub fn new(
|
||||
name: &'static str,
|
||||
prompt1: &'static str,
|
||||
prompt2: &'static str,
|
||||
has_selection: bool,
|
||||
) -> Self {
|
||||
Self {
|
||||
name,
|
||||
prompt1,
|
||||
prompt2,
|
||||
gathering: !has_selection,
|
||||
selected: Vec::new(),
|
||||
first: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CadCommand for SelectThenTwoValueCommand {
|
||||
fn name(&self) -> &'static str {
|
||||
self.name
|
||||
}
|
||||
|
||||
fn prompt(&self) -> String {
|
||||
if self.gathering {
|
||||
crate::t!(
|
||||
"%{name} select objects, then press Enter:",
|
||||
name = self.name
|
||||
)
|
||||
.into_owned()
|
||||
} else if self.first.is_none() {
|
||||
crate::t!(self.prompt1).into_owned()
|
||||
} else {
|
||||
crate::t!(self.prompt2).into_owned()
|
||||
}
|
||||
}
|
||||
|
||||
fn wants_text_input(&self) -> bool {
|
||||
!self.gathering
|
||||
}
|
||||
|
||||
fn is_selection_gathering(&self) -> bool {
|
||||
self.gathering
|
||||
}
|
||||
|
||||
fn on_selection_complete(&mut self, handles: Vec<Handle>) -> CmdResult {
|
||||
self.selected = handles;
|
||||
CmdResult::NeedPoint
|
||||
}
|
||||
|
||||
fn on_text_input(&mut self, text: &str) -> Option<CmdResult> {
|
||||
if self.gathering {
|
||||
return None;
|
||||
}
|
||||
let t = text.trim();
|
||||
if t.is_empty() {
|
||||
return None;
|
||||
}
|
||||
match &self.first {
|
||||
None => {
|
||||
self.first = Some(t.to_string());
|
||||
// Consumed; `None` would feed the same text back as the second
|
||||
// value and dispatch `<name> <x> <x>` in one step.
|
||||
Some(CmdResult::NeedPoint)
|
||||
}
|
||||
Some(first) => Some(CmdResult::Dispatch(format!("{} {first} {t}", self.name))),
|
||||
}
|
||||
}
|
||||
|
||||
fn on_point(&mut self, _pt: DVec3) -> CmdResult {
|
||||
CmdResult::NeedPoint
|
||||
}
|
||||
|
||||
fn on_enter(&mut self) -> CmdResult {
|
||||
if self.gathering {
|
||||
if self.selected.is_empty() {
|
||||
return CmdResult::Cancel;
|
||||
}
|
||||
self.gathering = false;
|
||||
return CmdResult::NeedPoint;
|
||||
}
|
||||
CmdResult::Cancel
|
||||
}
|
||||
}
|
||||
|
||||
// ── Result token ──────────────────────────────────────────────────────────
|
||||
|
||||
/// Returned by every `CadCommand` method to tell main.rs what to do.
|
||||
@@ -1278,6 +1180,7 @@ pub enum CmdResult {
|
||||
entity: EntityType,
|
||||
solid: Box<cadkernel::brep::Body>,
|
||||
history: acadrust::objects::SolidHistoryOperation,
|
||||
erase_source: Option<Handle>,
|
||||
},
|
||||
/// Commit an acadrust entity, end the command, and open the in-place text
|
||||
/// editor on it (used by MLEADER to type the annotation after placement).
|
||||
|
||||
Reference in new issue
Block a user