forked from 1b-agent/opencadstudio-upstream
feat(command): add MTP/M2P midpoint-between-two-points modifier
Add MTP (Midpoint Between Two Points) as a keyword that can be typed during any point-picking command (e.g. LINE) to suspend the current command, prompt for two points, and return the midpoint to the parent. - New Mid2PointCommand registered under both "MTP" and "M2P" aliases - ReturnPoint CmdResult variant feeds the resolved midpoint back to the suspended parent command - MTP/M2P typed during a point step suspends the active command and starts the midpoint modifier; Escape restores the parent command - Preview wires show a rubber-band line with a triangle marker at the midpoint - Character-by-character typing is routed correctly even with dynamic input active (digits no longer leak into dyn fields) - Three automation tests cover the full workflow, ESC restoration, and dynamic-input character routing
This commit is contained in:
1 parent
f4eeba75df
commit
f77c337af4
4 files changed
+330
-9
No files matched your search
@@ -1513,4 +1513,101 @@ mod tests {
|
||||
// Finish
|
||||
let _ = app.update(Message::CommandOptionPick(String::new()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mtp_in_line_command() {
|
||||
use crate::app::Message;
|
||||
let mut app = OpenCADStudio::new_for_test();
|
||||
app.automation_op(r#"{"op":"new"}"#);
|
||||
{
|
||||
app.tabs[0].scene.selection.borrow_mut().vp_size = (1920.0, 1080.0);
|
||||
app.tabs[0].scene.sync_tiles_from_panes(1920.0, 1080.0);
|
||||
}
|
||||
|
||||
// Start LINE
|
||||
let _ = app.update(Message::CommandInput("LINE".to_string()));
|
||||
let _ = app.update(Message::CommandSubmit);
|
||||
assert_eq!(app.tabs[0].active_cmd.as_ref().map(|c| c.name()), Some("LINE"));
|
||||
|
||||
// Type M2P
|
||||
let _ = app.update(Message::CommandInput("M2P".to_string()));
|
||||
let _ = app.update(Message::CommandSubmit);
|
||||
assert_eq!(app.tabs[0].active_cmd.as_ref().map(|c| c.name()), Some("MTP"));
|
||||
assert!(app.tabs[0].suspended_cmd.is_some());
|
||||
assert_eq!(app.tabs[0].suspended_cmd.as_ref().map(|c| c.name()), Some("LINE"));
|
||||
|
||||
// Point 1: 0,0
|
||||
let _ = app.update(Message::CommandInput("0,0".to_string()));
|
||||
let _ = app.update(Message::CommandSubmit);
|
||||
assert_eq!(app.tabs[0].active_cmd.as_ref().map(|c| c.name()), Some("MTP"));
|
||||
|
||||
// Point 2: 10,20
|
||||
let _ = app.update(Message::CommandInput("10,20".to_string()));
|
||||
let _ = app.update(Message::CommandSubmit);
|
||||
|
||||
// MTP should have finished and restored LINE, with midpoint (5, 10, 0)
|
||||
assert_eq!(app.tabs[0].active_cmd.as_ref().map(|c| c.name()), Some("LINE"));
|
||||
assert!(app.tabs[0].suspended_cmd.is_none());
|
||||
assert_eq!(app.last_point, Some(glam::DVec3::new(5.0, 10.0, 0.0)));
|
||||
|
||||
// Cancel LINE
|
||||
let _ = app.update(Message::CommandEscape);
|
||||
assert!(app.tabs[0].active_cmd.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mtp_escape_restores_parent() {
|
||||
use crate::app::Message;
|
||||
let mut app = OpenCADStudio::new_for_test();
|
||||
app.automation_op(r#"{"op":"new"}"#);
|
||||
|
||||
// Start LINE
|
||||
let _ = app.update(Message::CommandInput("LINE".to_string()));
|
||||
let _ = app.update(Message::CommandSubmit);
|
||||
assert_eq!(app.tabs[0].active_cmd.as_ref().map(|c| c.name()), Some("LINE"));
|
||||
|
||||
// Type MTP
|
||||
let _ = app.update(Message::CommandInput("MTP".to_string()));
|
||||
let _ = app.update(Message::CommandSubmit);
|
||||
assert_eq!(app.tabs[0].active_cmd.as_ref().map(|c| c.name()), Some("MTP"));
|
||||
|
||||
// Escape during MTP
|
||||
let _ = app.update(Message::CommandEscape);
|
||||
// Parent LINE must be restored, not cancelled!
|
||||
assert_eq!(app.tabs[0].active_cmd.as_ref().map(|c| c.name()), Some("LINE"));
|
||||
assert!(app.tabs[0].suspended_cmd.is_none());
|
||||
|
||||
// Escape again cancels LINE
|
||||
let _ = app.update(Message::CommandEscape);
|
||||
assert!(app.tabs[0].active_cmd.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mtp_typing_routing_with_dyn_input() {
|
||||
use crate::app::Message;
|
||||
let mut app = OpenCADStudio::new_for_test();
|
||||
app.automation_op(r#"{"op":"new"}"#);
|
||||
app.dyn_input = true;
|
||||
|
||||
// Start LINE
|
||||
let _ = app.update(Message::CommandInput("LINE".to_string()));
|
||||
let _ = app.update(Message::CommandSubmit);
|
||||
assert_eq!(app.tabs[0].active_cmd.as_ref().map(|c| c.name()), Some("LINE"));
|
||||
|
||||
// Simulate typing 'm', '2', 'p' character by character
|
||||
let _ = app.update(Message::CommandAppendChar("m".to_string()));
|
||||
assert_eq!(app.command_line.input, "M");
|
||||
|
||||
// The digit '2' must stay in command_line.input instead of routing to dyn fields!
|
||||
let _ = app.update(Message::CommandAppendChar("2".to_string()));
|
||||
assert_eq!(app.command_line.input, "M2");
|
||||
|
||||
let _ = app.update(Message::CommandAppendChar("p".to_string()));
|
||||
assert_eq!(app.command_line.input, "M2P");
|
||||
|
||||
// Submit triggers MTP
|
||||
let _ = app.update(Message::CommandSubmit);
|
||||
assert_eq!(app.tabs[0].active_cmd.as_ref().map(|c| c.name()), Some("MTP"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user