Move homogeneous saved Scenario selections as a group
This commit is contained in:
@@ -246,37 +246,46 @@ fn group_rejects_legacy_singleton_remove_reorder_and_index_arrows() {
|
||||
fn secondary_selection_aba_retires_old_spacing_without_canceling_a_new_gesture() {
|
||||
let (mut app, _, _, lane, message) = setup(true);
|
||||
choose(&mut app, message, multiselect::Choice::Add);
|
||||
let old = spacing::controller::tests::packet(
|
||||
app.project(),
|
||||
&app.behavior.scenario,
|
||||
app.scenario_context().unwrap(),
|
||||
app.camera_epoch,
|
||||
let old = super::super::scenario_spacing::tests::packet_for_app(
|
||||
&app,
|
||||
spacing::Target::Message(message),
|
||||
);
|
||||
choose(&mut app, lane, multiselect::Choice::Add);
|
||||
let group_begin = spacing::controller::tests::packet(
|
||||
app.project(),
|
||||
&app.behavior.scenario,
|
||||
app.scenario_context().unwrap(),
|
||||
app.camera_epoch,
|
||||
let group_begin = super::super::scenario_spacing::tests::packet_for_app(
|
||||
&app,
|
||||
spacing::Target::Message(message),
|
||||
);
|
||||
inert(
|
||||
&mut app,
|
||||
vec![Message::ScenarioCanvas(CanvasEvent::Spacing(group_begin))],
|
||||
true,
|
||||
let original = app.document.snapshot();
|
||||
let selected = app.multiselect_snapshot().unwrap();
|
||||
let epoch = app.canvas_epoch;
|
||||
let _ = app.update(Message::ScenarioCanvas(CanvasEvent::Spacing(group_begin)));
|
||||
assert_eq!(app.project(), &original.decoded.project);
|
||||
assert_eq!(app.document.bundle(), &original.bundle);
|
||||
assert_eq!(
|
||||
app.multiselect_snapshot().unwrap().targets(),
|
||||
selected.targets()
|
||||
);
|
||||
assert_eq!(
|
||||
app.multiselect_snapshot().unwrap().primary(),
|
||||
selected.primary()
|
||||
);
|
||||
assert_eq!(
|
||||
app.canvas_epoch, epoch,
|
||||
"pending click retains its admitted lifetime"
|
||||
);
|
||||
assert_eq!(
|
||||
app.behavior.scenario.spacing_token(),
|
||||
Some(group_begin.token())
|
||||
);
|
||||
choose(&mut app, lane, multiselect::Choice::Remove);
|
||||
assert!(app.behavior.scenario.spacing_token().is_none());
|
||||
inert(
|
||||
&mut app,
|
||||
vec![Message::ScenarioCanvas(CanvasEvent::Spacing(old))],
|
||||
true,
|
||||
);
|
||||
let current = spacing::controller::tests::packet(
|
||||
app.project(),
|
||||
&app.behavior.scenario,
|
||||
app.scenario_context().unwrap(),
|
||||
app.camera_epoch,
|
||||
let current = super::super::scenario_spacing::tests::packet_for_app(
|
||||
&app,
|
||||
spacing::Target::Message(message),
|
||||
);
|
||||
let spacing::Event::Begin { press_screen, .. } = current else {
|
||||
@@ -319,11 +328,8 @@ fn legacy_singleton_selection_aba_retires_old_spacing_begin() {
|
||||
for canvas in [false, true] {
|
||||
let (mut app, _, _, lane, message) = setup(true);
|
||||
choose(&mut app, message, multiselect::Choice::Add);
|
||||
let old = spacing::controller::tests::packet(
|
||||
app.project(),
|
||||
&app.behavior.scenario,
|
||||
app.scenario_context().unwrap(),
|
||||
app.camera_epoch,
|
||||
let old = super::super::scenario_spacing::tests::packet_for_app(
|
||||
&app,
|
||||
spacing::Target::Message(message),
|
||||
);
|
||||
for id in [lane, message] {
|
||||
@@ -345,11 +351,8 @@ fn legacy_singleton_selection_aba_retires_old_spacing_begin() {
|
||||
vec![Message::ScenarioCanvas(CanvasEvent::Spacing(old))],
|
||||
true,
|
||||
);
|
||||
let current = spacing::controller::tests::packet(
|
||||
app.project(),
|
||||
&app.behavior.scenario,
|
||||
app.scenario_context().unwrap(),
|
||||
app.camera_epoch,
|
||||
let current = super::super::scenario_spacing::tests::packet_for_app(
|
||||
&app,
|
||||
spacing::Target::Message(message),
|
||||
);
|
||||
let _ = app.update(Message::ScenarioCanvas(CanvasEvent::Spacing(current)));
|
||||
|
||||
@@ -1,9 +1,33 @@
|
||||
//! Admit spacing packets before ordinary navigation can retire a newer reveal.
|
||||
use super::*;
|
||||
use behavior::scenario::spacing::{Event, controller::Finish};
|
||||
use crate::diagram_usage::Target;
|
||||
use behavior::scenario::{
|
||||
selection,
|
||||
spacing::{Event, Refusal, controller::Finish},
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
mod group_tests;
|
||||
#[cfg(test)]
|
||||
pub(super) mod tests;
|
||||
|
||||
fn refusal_reason(refusal: &Refusal) -> String {
|
||||
match refusal {
|
||||
Refusal::InvalidSelection(reason) => (*reason).into(),
|
||||
Refusal::TargetNotRendered(_) => {
|
||||
"Every selected object must be a rendered local message or lifeline in this saved view."
|
||||
.into()
|
||||
}
|
||||
Refusal::Geometry(_) => {
|
||||
"These positions cannot be displayed together. The saved arrangement is unchanged."
|
||||
.into()
|
||||
}
|
||||
Refusal::Command(reason) => reason.clone(),
|
||||
_ => {
|
||||
"The drag could not be applied in this view. The saved arrangement is unchanged.".into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl App {
|
||||
pub(super) fn spacing_enabled(&self) -> bool {
|
||||
@@ -21,10 +45,12 @@ impl App {
|
||||
{
|
||||
return Task::none();
|
||||
}
|
||||
// Saved group motion has no implicit primary-only spacing operation.
|
||||
// Selection generation changes also advance canvas_epoch, rejecting old
|
||||
// singleton packets after adding then removing a secondary member.
|
||||
if self.scenario_group_selected() {
|
||||
let Some(snapshot) = self.multiselect_snapshot() else {
|
||||
return Task::none();
|
||||
};
|
||||
if snapshot.generation() != stamp.selection_generation
|
||||
|| snapshot.context() != selection::context(stamp.context)
|
||||
{
|
||||
return Task::none();
|
||||
}
|
||||
let state = &self.behavior.scenario;
|
||||
@@ -32,12 +58,33 @@ impl App {
|
||||
state.spacing_token() == Some(event.token()) && state.spacing_stamp() == Some(stamp);
|
||||
if match event {
|
||||
Event::Begin { token, .. } => token.is_nil() || state.spacing_token().is_some(),
|
||||
_ => !matches,
|
||||
_ => {
|
||||
!matches
|
||||
|| !state.spacing_snapshot().is_some_and(|captured| {
|
||||
self.diagram_selection.as_ref().is_some_and(|selected| {
|
||||
selected.matches(captured, selection::context(stamp.context))
|
||||
})
|
||||
})
|
||||
}
|
||||
} {
|
||||
return Task::none();
|
||||
}
|
||||
if matches!(event, Event::Begin { .. }) {
|
||||
let visible = selection::visible(self.project(), stamp.context, self.selected);
|
||||
if !snapshot
|
||||
.targets()
|
||||
.iter()
|
||||
.all(|target| visible.contains(target))
|
||||
{
|
||||
// This otherwise current Begin cannot be replayed after repair.
|
||||
self.canvas_epoch = self.canvas_epoch.wrapping_add(1);
|
||||
self.status =
|
||||
"Every selected object must still be visible before moving the group.".into();
|
||||
return Task::none();
|
||||
}
|
||||
}
|
||||
if matches!(event, Event::Cancel { .. }) || !self.spacing_enabled() {
|
||||
if self.behavior.scenario.cancel_spacing() {
|
||||
if self.behavior.scenario.cancel_spacing() || matches!(event, Event::Begin { .. }) {
|
||||
self.canvas_epoch = self.canvas_epoch.wrapping_add(1);
|
||||
}
|
||||
return Task::none();
|
||||
@@ -45,18 +92,38 @@ impl App {
|
||||
match event {
|
||||
Event::Begin { .. } => {
|
||||
let mut state = std::mem::take(&mut self.behavior.scenario);
|
||||
let result = state.begin_spacing(self.project(), event);
|
||||
let result = state.begin_spacing_with_snapshot(self.project(), event, snapshot);
|
||||
self.behavior.scenario = state;
|
||||
if result.is_err() {
|
||||
self.status = "The drag could not start in this view. Try again.".into();
|
||||
if let Err(error) = result {
|
||||
// Consume admitted failed starts too; a repeated Begin is stale.
|
||||
self.canvas_epoch = self.canvas_epoch.wrapping_add(1);
|
||||
self.status = refusal_reason(&error);
|
||||
}
|
||||
}
|
||||
Event::Move { screen, .. } => self.behavior.scenario.move_spacing(screen),
|
||||
Event::Finish { screen, .. } => {
|
||||
// Full captured selection matched above, before taking the session.
|
||||
let captured = self
|
||||
.behavior
|
||||
.scenario
|
||||
.spacing_snapshot()
|
||||
.cloned()
|
||||
.expect("admitted session snapshot");
|
||||
let group = captured.targets().len() > 1;
|
||||
let finished = self.behavior.scenario.finish_spacing(screen);
|
||||
// Retire queued packets even for zero motion or a refused finish.
|
||||
self.canvas_epoch = self.canvas_epoch.wrapping_add(1);
|
||||
match finished {
|
||||
Ok(Finish::Click(target)) if group => {
|
||||
let target = Target::ScenarioObject(target);
|
||||
// The controller only captures a pressed member of this set.
|
||||
if captured.targets().contains(&target) {
|
||||
self.diagram_selection
|
||||
.as_mut()
|
||||
.expect("admitted selection")
|
||||
.replace(target, |_| true);
|
||||
self.inspect_scenario_multiselect_primary();
|
||||
}
|
||||
}
|
||||
Ok(Finish::Click(target)) => self.select(target),
|
||||
Ok(Finish::Noop) => {}
|
||||
Ok(Finish::Commit {
|
||||
@@ -64,27 +131,35 @@ impl App {
|
||||
selected,
|
||||
scale,
|
||||
pan,
|
||||
}) => {
|
||||
// Document prepares and writes the source candidate before
|
||||
// committing its snapshot. Failure leaves camera/selection
|
||||
// and source/history at their accepted values.
|
||||
match self.document.execute(*command) {
|
||||
Ok(_) => {
|
||||
self.selected = selected;
|
||||
self.selected_node = None;
|
||||
self.diagram_navigation_focus = None;
|
||||
self.behavior.scenario.accept_spacing_camera(scale, pan);
|
||||
self.sync();
|
||||
self.status = "Scenario spacing updated.".into();
|
||||
}) => match self.document.execute(*command) {
|
||||
Ok(_) => {
|
||||
self.selected = if group {
|
||||
match captured.primary() {
|
||||
Some(Target::ScenarioObject(id)) => *id,
|
||||
_ => selected,
|
||||
}
|
||||
} else {
|
||||
selected
|
||||
};
|
||||
self.selected_node = None;
|
||||
self.diagram_navigation_focus = None;
|
||||
self.behavior.scenario.accept_spacing_camera(scale, pan);
|
||||
self.sync();
|
||||
if group {
|
||||
self.inspect_scenario_multiselect_primary();
|
||||
}
|
||||
Err(error) => self.status = format!("Spacing was not applied: {error}"),
|
||||
self.status = if group {
|
||||
format!(
|
||||
"Spacing updated for {} selected objects. Scenario order is unchanged.",
|
||||
captured.targets().len()
|
||||
)
|
||||
} else {
|
||||
"Scenario spacing updated.".into()
|
||||
};
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
self.status =
|
||||
"That position cannot be applied. The saved arrangement is unchanged."
|
||||
.into()
|
||||
}
|
||||
Err(error) => self.status = format!("Spacing was not applied: {error}"),
|
||||
},
|
||||
Err(error) => self.status = refusal_reason(&error),
|
||||
}
|
||||
self.reconcile_multiselect();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,342 @@
|
||||
use super::tests::{begin, finish, move_to, packet_for_app, send, setup};
|
||||
use super::*;
|
||||
use crate::behavior::scenario::{CanvasEvent, selection, spacing::Target};
|
||||
use crate::behavior::scenario_layout::Representation;
|
||||
use crate::diagram_usage::Target as SelectedTarget;
|
||||
use iced::Vector;
|
||||
use oa_core::{
|
||||
DiagramLayout, OccurrenceEndpoint, ScenarioLanePosition, ScenarioLayout,
|
||||
ScenarioMessagePosition,
|
||||
};
|
||||
|
||||
fn id(app: &App, alias: &str) -> Id {
|
||||
app.project()
|
||||
.identities()
|
||||
.into_iter()
|
||||
.find(|(_, a)| *a == alias)
|
||||
.unwrap()
|
||||
.0
|
||||
}
|
||||
fn choose(app: &mut App, id: Id, choice: multiselect::Choice) {
|
||||
let event = selection::Event {
|
||||
context: app.scenario_context().unwrap(),
|
||||
snapshot: app.multiselect_snapshot().unwrap(),
|
||||
intent: selection::Intent::Choose(SelectedTarget::ScenarioObject(id), choice),
|
||||
};
|
||||
let _ = app.update(Message::ScenarioCanvas(CanvasEvent::Selection(Box::new(
|
||||
event,
|
||||
))));
|
||||
}
|
||||
fn group(messages: bool, reverse: bool) -> (App, [Id; 2]) {
|
||||
let (mut app, lane, message) = setup();
|
||||
let ids = if messages {
|
||||
[message, id(&app, "second")]
|
||||
} else {
|
||||
[lane, id(&app, "operator")]
|
||||
};
|
||||
let order = if reverse { [ids[1], ids[0]] } else { ids };
|
||||
for member in order {
|
||||
choose(&mut app, member, multiselect::Choice::Add);
|
||||
}
|
||||
(app, ids)
|
||||
}
|
||||
fn target(messages: bool, id: Id) -> Target {
|
||||
if messages {
|
||||
Target::Message(id)
|
||||
} else {
|
||||
Target::Lane(id)
|
||||
}
|
||||
}
|
||||
fn delta(messages: bool, pixels: f32) -> Vector {
|
||||
if messages {
|
||||
Vector::new(0., pixels)
|
||||
} else {
|
||||
Vector::new(pixels, 0.)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn either_pressed_member_moves_complete_group_and_preserves_primary_source_and_one_history_step() {
|
||||
for messages in [false, true] {
|
||||
for pressed_index in 0..2 {
|
||||
let (mut app, ids) = group(messages, true);
|
||||
let original = app.document.snapshot();
|
||||
let original_selection = app.multiselect_snapshot().unwrap();
|
||||
let primary = app.selected;
|
||||
let c = app.scenario_context().unwrap();
|
||||
let Representation::Saved { diagram } = c.representation else {
|
||||
unreachable!()
|
||||
};
|
||||
let (event, start, scale) = begin(&mut app, target(messages, ids[pressed_index]));
|
||||
let world_delta = 24. / scale;
|
||||
move_to(&mut app, event, start + delta(messages, 24.));
|
||||
assert_eq!(app.project(), &original.decoded.project);
|
||||
assert_eq!(app.document.bundle(), &original.bundle);
|
||||
assert_eq!(app.selected, primary);
|
||||
assert_eq!(
|
||||
app.behavior.scenario.spacing_snapshot(),
|
||||
Some(&original_selection)
|
||||
);
|
||||
let mut expected = original.decoded.project.clone();
|
||||
let mut members = ids.to_vec();
|
||||
members.sort();
|
||||
let mut layout = ScenarioLayout::default();
|
||||
for member in members {
|
||||
if messages {
|
||||
let y = if member == ids[0] { 148. } else { 240. };
|
||||
layout.messages.push(ScenarioMessagePosition {
|
||||
address: OccurrenceEndpoint {
|
||||
references: vec![],
|
||||
occurrence: member,
|
||||
},
|
||||
send_y: (f64::from(y) + f64::from(world_delta)) as f32,
|
||||
});
|
||||
} else {
|
||||
let x = if member == ids[0] { 160. } else { 400. };
|
||||
layout.lanes.push(ScenarioLanePosition {
|
||||
lifeline: member,
|
||||
x: (f64::from(x) + f64::from(world_delta)) as f32,
|
||||
});
|
||||
}
|
||||
}
|
||||
expected.diagrams.get_mut(&diagram).unwrap().layout =
|
||||
Some(DiagramLayout::Scenario(layout));
|
||||
finish(&mut app, event, start + delta(messages, 24.));
|
||||
assert_eq!(app.project(), &expected);
|
||||
assert_eq!(app.selected, primary);
|
||||
assert_eq!(
|
||||
app.multiselect_snapshot().unwrap().targets(),
|
||||
original_selection.targets()
|
||||
);
|
||||
assert_eq!(
|
||||
app.multiselect_snapshot().unwrap().primary(),
|
||||
original_selection.primary()
|
||||
);
|
||||
let saved = app.document.bundle().clone();
|
||||
let _ = app.update(Message::ShortcutUndo(false));
|
||||
assert_eq!(app.project(), &original.decoded.project);
|
||||
assert_eq!(app.document.bundle(), &original.bundle);
|
||||
assert!(!app.document.can_undo() && app.document.can_redo());
|
||||
let _ = app.update(Message::ShortcutUndo(true));
|
||||
assert_eq!(app.project(), &expected);
|
||||
assert_eq!(app.document.bundle(), &saved);
|
||||
let reopened =
|
||||
Document::from_bundle(saved, oa_core::source_project::ProjectLimits::default())
|
||||
.unwrap();
|
||||
assert_eq!(reopened.project(), &expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn group_stationary_click_collapses_but_offaxis_outback_cancel_preserve_group_and_redo() {
|
||||
for messages in [false, true] {
|
||||
for mode in 0..4 {
|
||||
let (mut app, ids) = group(messages, true);
|
||||
let (seed, start, _) = begin(&mut app, target(messages, ids[0]));
|
||||
finish(&mut app, seed, start + delta(messages, 20.));
|
||||
let _ = app.update(Message::ShortcutUndo(false));
|
||||
assert!(app.document.can_redo());
|
||||
let original = app.document.snapshot();
|
||||
let selected = app.multiselect_snapshot().unwrap();
|
||||
let primary = app.selected;
|
||||
let camera = app.behavior.scenario.camera_boundary();
|
||||
let (event, start, _) = begin(&mut app, target(messages, ids[1]));
|
||||
match mode {
|
||||
0 => finish(&mut app, event, start),
|
||||
1 => finish(&mut app, event, start + delta(!messages, 50.)),
|
||||
2 => {
|
||||
move_to(&mut app, event, start + delta(messages, 30.));
|
||||
finish(&mut app, event, start);
|
||||
}
|
||||
_ => {
|
||||
move_to(&mut app, event, start + delta(messages, 30.));
|
||||
send(
|
||||
&mut app,
|
||||
Event::Cancel {
|
||||
stamp: event.stamp(),
|
||||
token: event.token(),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
assert_eq!(app.project(), &original.decoded.project);
|
||||
assert_eq!(app.document.bundle(), &original.bundle);
|
||||
assert!(app.document.can_redo() && !app.document.can_undo());
|
||||
assert!(camera == app.behavior.scenario.camera_boundary());
|
||||
if mode == 0 {
|
||||
assert_eq!(
|
||||
app.multiselect_snapshot().unwrap().targets(),
|
||||
&[SelectedTarget::ScenarioObject(ids[1])]
|
||||
);
|
||||
assert_eq!(app.selected, ids[1]);
|
||||
} else {
|
||||
assert_eq!(
|
||||
app.multiselect_snapshot().unwrap().targets(),
|
||||
selected.targets()
|
||||
);
|
||||
assert_eq!(app.selected, primary);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stale_group_packets_and_generation_forgery_do_not_disturb_a_newer_live_gesture() {
|
||||
let (mut app, ids) = group(true, true);
|
||||
let (old, start, _) = begin(&mut app, Target::Message(ids[0]));
|
||||
send(
|
||||
&mut app,
|
||||
Event::Cancel {
|
||||
stamp: old.stamp(),
|
||||
token: old.token(),
|
||||
},
|
||||
);
|
||||
let (current, current_start, _) = begin(&mut app, Target::Message(ids[1]));
|
||||
let original = app.document.snapshot();
|
||||
let selection = app.multiselect_snapshot();
|
||||
let epoch = app.canvas_epoch;
|
||||
let status = app.status.clone();
|
||||
let mut forged = current;
|
||||
if let Event::Begin { stamp, .. } = &mut forged {
|
||||
stamp.selection_generation = stamp.selection_generation.wrapping_add(1);
|
||||
}
|
||||
for event in [
|
||||
old,
|
||||
forged,
|
||||
Event::Move {
|
||||
stamp: old.stamp(),
|
||||
token: old.token(),
|
||||
screen: start + Vector::new(0., 90.),
|
||||
},
|
||||
Event::Finish {
|
||||
stamp: old.stamp(),
|
||||
token: old.token(),
|
||||
screen: start + Vector::new(0., 90.),
|
||||
},
|
||||
Event::Cancel {
|
||||
stamp: old.stamp(),
|
||||
token: old.token(),
|
||||
},
|
||||
] {
|
||||
send(&mut app, event);
|
||||
assert_eq!(app.canvas_epoch, epoch);
|
||||
assert_eq!(app.status, status);
|
||||
assert_eq!(app.multiselect_snapshot(), selection);
|
||||
assert_eq!(app.document.bundle(), &original.bundle);
|
||||
assert_eq!(app.behavior.scenario.spacing_token(), Some(current.token()));
|
||||
}
|
||||
finish(&mut app, current, current_start + Vector::new(0., 24.));
|
||||
assert!(app.document.can_undo());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mixed_group_drag_refuses_whole_set_without_primary_only_change_or_replay() {
|
||||
let (mut app, lane, message) = setup();
|
||||
choose(&mut app, message, multiselect::Choice::Add);
|
||||
choose(&mut app, lane, multiselect::Choice::Add);
|
||||
let event = packet_for_app(&app, Target::Message(message));
|
||||
let original = app.document.snapshot();
|
||||
let selected = app.multiselect_snapshot().unwrap();
|
||||
let epoch = app.canvas_epoch;
|
||||
send(&mut app, event);
|
||||
assert_eq!(app.canvas_epoch, epoch);
|
||||
let Event::Begin { press_screen, .. } = event else {
|
||||
unreachable!()
|
||||
};
|
||||
move_to(&mut app, event, press_screen + Vector::new(0., 30.));
|
||||
assert_eq!(app.project(), &original.decoded.project);
|
||||
finish(&mut app, event, press_screen + Vector::new(0., 30.));
|
||||
assert_ne!(app.canvas_epoch, epoch);
|
||||
assert!(app.behavior.scenario.spacing_token().is_none());
|
||||
assert_eq!(app.document.bundle(), &original.bundle);
|
||||
assert_eq!(app.project(), &original.decoded.project);
|
||||
assert_eq!(
|
||||
app.multiselect_snapshot().unwrap().targets(),
|
||||
selected.targets()
|
||||
);
|
||||
assert_eq!(
|
||||
app.multiselect_snapshot().unwrap().primary(),
|
||||
selected.primary()
|
||||
);
|
||||
let status = app.status.clone();
|
||||
let epoch = app.canvas_epoch;
|
||||
send(&mut app, event);
|
||||
assert_eq!(app.status, status);
|
||||
assert_eq!(app.canvas_epoch, epoch);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mixed_group_stationary_click_on_either_role_still_selects_only_that_member() {
|
||||
for lane_hit in [false, true] {
|
||||
let (mut app, lane, message) = setup();
|
||||
choose(&mut app, message, multiselect::Choice::Add);
|
||||
choose(&mut app, lane, multiselect::Choice::Add);
|
||||
let original = app.document.snapshot();
|
||||
let member = if lane_hit { lane } else { message };
|
||||
let (event, start, _) = begin(&mut app, target(!lane_hit, member));
|
||||
finish(&mut app, event, start);
|
||||
assert_eq!(
|
||||
app.multiselect_snapshot().unwrap().targets(),
|
||||
&[SelectedTarget::ScenarioObject(member)]
|
||||
);
|
||||
assert_eq!(app.selected, member);
|
||||
assert_eq!(app.document.bundle(), &original.bundle);
|
||||
assert!(!app.document.can_undo());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn malformed_current_begin_consumes_its_lifetime_without_editing_or_replaying() {
|
||||
let (mut app, ids) = group(true, true);
|
||||
let mut event = packet_for_app(&app, Target::Message(ids[0]));
|
||||
if let Event::Begin { canvas_bounds, .. } = &mut event {
|
||||
canvas_bounds.width = 0.;
|
||||
}
|
||||
let original = app.document.snapshot();
|
||||
let selection = app.multiselect_snapshot().unwrap();
|
||||
let epoch = app.canvas_epoch;
|
||||
send(&mut app, event);
|
||||
assert_ne!(app.canvas_epoch, epoch);
|
||||
assert!(app.behavior.scenario.spacing_token().is_none());
|
||||
assert_eq!(app.document.bundle(), &original.bundle);
|
||||
assert_eq!(
|
||||
app.multiselect_snapshot().unwrap().targets(),
|
||||
selection.targets()
|
||||
);
|
||||
let epoch = app.canvas_epoch;
|
||||
let status = app.status.clone();
|
||||
send(&mut app, event);
|
||||
assert_eq!(app.canvas_epoch, epoch);
|
||||
assert_eq!(app.status, status);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn group_source_write_failure_is_atomic_and_preserves_selection_and_camera() {
|
||||
let (mut app, ids) = group(true, true);
|
||||
let bundle = app.document.bundle().clone();
|
||||
let mut limits = oa_core::source_project::ProjectLimits::default();
|
||||
limits.model.max_source_bytes = bundle.files.values().map(String::len).sum();
|
||||
app.document = Document::from_bundle(bundle, limits).unwrap();
|
||||
app.sync();
|
||||
let original = app.document.snapshot();
|
||||
let selection = app.multiselect_snapshot().unwrap();
|
||||
let primary = app.selected;
|
||||
let camera = app.behavior.scenario.camera_boundary();
|
||||
let (event, start, _) = begin(&mut app, Target::Message(ids[1]));
|
||||
finish(&mut app, event, start + Vector::new(0., 24.));
|
||||
assert!(
|
||||
app.status.starts_with("Spacing was not applied:"),
|
||||
"{}",
|
||||
app.status
|
||||
);
|
||||
assert_eq!(app.project(), &original.decoded.project);
|
||||
assert_eq!(app.document.bundle(), &original.bundle);
|
||||
assert_eq!(
|
||||
app.multiselect_snapshot().unwrap().targets(),
|
||||
selection.targets()
|
||||
);
|
||||
assert_eq!(app.selected, primary);
|
||||
assert!(camera == app.behavior.scenario.camera_boundary());
|
||||
assert!(!app.document.can_undo());
|
||||
}
|
||||
@@ -8,7 +8,7 @@ use behavior::scenario::{
|
||||
};
|
||||
use iced::{Point, Size, Vector};
|
||||
|
||||
fn setup() -> (App, Id, Id) {
|
||||
pub(super) fn setup() -> (App, Id, Id) {
|
||||
let (document, owner, diagram, lane, message) = fixture();
|
||||
let mut app = App::with_project(document.project().clone());
|
||||
let _ = app.update(Message::Select(owner));
|
||||
@@ -88,14 +88,21 @@ fn stale_text_and_scenario_messages_do_not_retire_a_new_saved_spacing_gesture()
|
||||
"the current gesture remains usable"
|
||||
);
|
||||
}
|
||||
fn begin(app: &mut App, target: Target) -> (Event, Point, f32) {
|
||||
let event = packet(
|
||||
pub(in crate::app) fn packet_for_app(app: &App, target: Target) -> Event {
|
||||
let mut event = packet(
|
||||
app.project(),
|
||||
&app.behavior.scenario,
|
||||
app.scenario_context().unwrap(),
|
||||
app.camera_epoch,
|
||||
target,
|
||||
);
|
||||
if let Event::Begin { stamp, .. } = &mut event {
|
||||
stamp.selection_generation = app.multiselect_snapshot().unwrap().generation();
|
||||
}
|
||||
event
|
||||
}
|
||||
pub(super) fn begin(app: &mut App, target: Target) -> (Event, Point, f32) {
|
||||
let event = packet_for_app(app, target);
|
||||
let Event::Begin {
|
||||
press_screen,
|
||||
scale,
|
||||
@@ -108,10 +115,10 @@ fn begin(app: &mut App, target: Target) -> (Event, Point, f32) {
|
||||
assert_eq!(app.behavior.scenario.spacing_token(), Some(event.token()));
|
||||
(event, press_screen, scale)
|
||||
}
|
||||
fn send(app: &mut App, event: Event) {
|
||||
pub(super) fn send(app: &mut App, event: Event) {
|
||||
let _ = app.update(Message::ScenarioCanvas(CanvasEvent::Spacing(event)));
|
||||
}
|
||||
fn move_to(app: &mut App, begin: Event, screen: Point) {
|
||||
pub(super) fn move_to(app: &mut App, begin: Event, screen: Point) {
|
||||
send(
|
||||
app,
|
||||
Event::Move {
|
||||
@@ -121,7 +128,7 @@ fn move_to(app: &mut App, begin: Event, screen: Point) {
|
||||
},
|
||||
);
|
||||
}
|
||||
fn finish(app: &mut App, begin: Event, screen: Point) {
|
||||
pub(super) fn finish(app: &mut App, begin: Event, screen: Point) {
|
||||
send(
|
||||
app,
|
||||
Event::Finish {
|
||||
|
||||
@@ -2233,7 +2233,20 @@ impl canvas::Program<Message> for Scene {
|
||||
return self
|
||||
.selection_action(Intent::Choose(target, Choice::Toggle));
|
||||
}
|
||||
if self.is_group() && self.is_selected(hit.id) {
|
||||
let group_spacing_hit = self.coordinate_input
|
||||
&& self.spacing_stamp.is_some()
|
||||
&& matches!(
|
||||
context.representation,
|
||||
scenario_layout::Representation::Saved { .. }
|
||||
)
|
||||
&& matches!(
|
||||
hit.role,
|
||||
SceneHitRole::LifelineHeader
|
||||
| SceneHitRole::MessageBody
|
||||
| SceneHitRole::MessageLabel
|
||||
);
|
||||
if self.is_group() && self.is_selected(hit.id) && !group_spacing_hit
|
||||
{
|
||||
state.group_press = Some(ScenarioGroupPress {
|
||||
context: *selection_context,
|
||||
snapshot: snapshot.clone(),
|
||||
|
||||
@@ -218,6 +218,7 @@ fn complete_fallback_scene_selects_but_cannot_capture_or_finish_coordinate_gestu
|
||||
let stamp = spacing::Stamp {
|
||||
context,
|
||||
camera_epoch: 17,
|
||||
selection_generation: 0,
|
||||
};
|
||||
ready_scene.coordinate_input = true;
|
||||
ready_scene.interaction = Some((context, CanvasTool::Select, true));
|
||||
|
||||
@@ -50,6 +50,70 @@ fn send(
|
||||
fn mouse_event(event: mouse::Event) -> canvas::Event {
|
||||
canvas::Event::Mouse(event)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn saved_group_body_press_emits_one_spacing_lifetime_without_collapsing_selection() {
|
||||
use crate::behavior::scenario::spacing::{self, Event};
|
||||
use crate::behavior::scenario_layout::{Representation, resolve};
|
||||
let (doc, owner, diagram, _, first) = spacing::controller::tests::fixture();
|
||||
let second = doc
|
||||
.project()
|
||||
.identities()
|
||||
.into_iter()
|
||||
.find(|(_, a)| *a == "second")
|
||||
.unwrap()
|
||||
.0;
|
||||
let mut context = scenario::direct_tests::context(owner);
|
||||
context.representation = Representation::Saved { diagram };
|
||||
let mut scene = resolve(doc.project(), context.representation, second)
|
||||
.unwrap()
|
||||
.scene;
|
||||
let mut selection = Selection::new(super::context(context).scope);
|
||||
selection.add(Target::ScenarioObject(first), |_| true);
|
||||
selection.add(Target::ScenarioObject(second), |_| true);
|
||||
let snapshot = selection.snapshot(super::context(context)).unwrap();
|
||||
let stamp = spacing::Stamp {
|
||||
context,
|
||||
camera_epoch: 9,
|
||||
selection_generation: snapshot.generation(),
|
||||
};
|
||||
scene.selection = Some((context, snapshot.clone()));
|
||||
scene.selected = second;
|
||||
scene.interaction = Some((context, CanvasTool::Select, true));
|
||||
scene.coordinate_input = true;
|
||||
scene.spacing_stamp = Some(stamp);
|
||||
let line = scene.lines.iter().find(|line| line.id == first).unwrap();
|
||||
let point = Point::new((line.points[0].x + line.points[1].x) / 2., line.points[0].y);
|
||||
assert_eq!(scene.hit(point), Some(first));
|
||||
let mut input = SequenceInput::default();
|
||||
let Some(CanvasEvent::Spacing(Event::Begin {
|
||||
stamp: got,
|
||||
token,
|
||||
target,
|
||||
..
|
||||
})) = send(
|
||||
&scene,
|
||||
&mut input,
|
||||
mouse_event(mouse::Event::ButtonPressed(mouse::Button::Left)),
|
||||
Some(point),
|
||||
)
|
||||
else {
|
||||
panic!("group spacing begins on first press")
|
||||
};
|
||||
assert_eq!(got, stamp);
|
||||
assert_eq!(target, spacing::Target::Message(first));
|
||||
assert!(input.group_press.is_none());
|
||||
let moved = point + Vector::new(0., 24.);
|
||||
assert!(
|
||||
matches!(send(&scene,&mut input,mouse_event(mouse::Event::CursorMoved{position:moved}),Some(moved)),Some(CanvasEvent::Spacing(Event::Move{stamp:s,token:t,..})) if s==stamp && t==token)
|
||||
);
|
||||
assert!(
|
||||
matches!(send(&scene,&mut input,mouse_event(mouse::Event::ButtonReleased(mouse::Button::Left)),Some(moved)),Some(CanvasEvent::Spacing(Event::Finish{stamp:s,token:t,..})) if s==stamp && t==token)
|
||||
);
|
||||
assert_eq!(scene.selection, Some((context, snapshot)));
|
||||
assert_eq!(scene.selected, second);
|
||||
assert!(input.press.is_none() && input.group_press.is_none());
|
||||
}
|
||||
#[test]
|
||||
fn group_press_retains_snapshot_and_collapses_only_stationary_release_once() {
|
||||
let (f, scene, point) = fixture(true);
|
||||
|
||||
@@ -5,13 +5,17 @@
|
||||
use crate::behavior::scenario_layout::{
|
||||
GeometryIssue, Representation, ResolvedScenarioPlan, presentation::checked_owner, resolve,
|
||||
};
|
||||
use crate::diagram_usage::Target as SelectionTarget;
|
||||
use oa_core::{
|
||||
Command, Id, Kind, OccurrenceBody, OccurrenceEndpoint, Project, ScenarioLanePosition,
|
||||
ScenarioMessagePosition, SharedBody, execute_batch,
|
||||
};
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
pub(crate) mod controller;
|
||||
#[cfg(test)]
|
||||
mod group_tests;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
pub(crate) use controller::{Event, Stamp};
|
||||
|
||||
@@ -30,6 +34,7 @@ impl Target {
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub(crate) enum Refusal {
|
||||
InvalidSelection(&'static str),
|
||||
InvalidSavedView(Id),
|
||||
TargetNotRendered(Target),
|
||||
InvalidDelta,
|
||||
@@ -45,6 +50,7 @@ pub(super) struct Drag {
|
||||
diagram: Id,
|
||||
target: Target,
|
||||
origin: f32,
|
||||
other_origins: Vec<(Target, f32)>,
|
||||
original_geometry: ResolvedScenarioPlan,
|
||||
}
|
||||
|
||||
@@ -58,17 +64,135 @@ pub(super) struct Preview {
|
||||
/// Capture an accepted, actually drawn target. A Saved view displaying automatic
|
||||
/// fallback is not an editable original, even if the target appears in fallback.
|
||||
pub(super) fn capture(project: &Project, diagram: Id, target: Target) -> Result<Drag, Refusal> {
|
||||
let representation = Representation::Saved { diagram };
|
||||
let owner = checked_owner(project, representation).ok_or(Refusal::InvalidSavedView(diagram))?;
|
||||
let geometry = resolve(project, representation, target.id()).map_err(Refusal::Geometry)?;
|
||||
capture_targets(project, diagram, target, &[target])
|
||||
}
|
||||
|
||||
/// The exact selected set is one operation, never an eligible subset. Selection
|
||||
/// order and the pressed member do not determine persistence order.
|
||||
pub(super) fn capture_group(
|
||||
project: &Project,
|
||||
diagram: Id,
|
||||
pressed: Target,
|
||||
targets: &[SelectionTarget],
|
||||
) -> Result<Drag, Refusal> {
|
||||
if targets.is_empty() {
|
||||
return Err(Refusal::InvalidSelection(
|
||||
"Select at least one occurrence to move.",
|
||||
));
|
||||
}
|
||||
let mut seen = BTreeSet::new();
|
||||
let mut members = Vec::with_capacity(targets.len());
|
||||
for selected in targets {
|
||||
let SelectionTarget::ScenarioObject(id) = selected else {
|
||||
return Err(Refusal::InvalidSelection(
|
||||
"Move only local Scenario lifelines or messages.",
|
||||
));
|
||||
};
|
||||
if !seen.insert(*id) {
|
||||
return Err(Refusal::InvalidSelection(
|
||||
"The selection contains a duplicate occurrence.",
|
||||
));
|
||||
}
|
||||
let target = match pressed {
|
||||
Target::Lane(_) => Target::Lane(*id),
|
||||
Target::Message(_) => Target::Message(*id),
|
||||
};
|
||||
let Some(element) = project.elements.get(id) else {
|
||||
return Err(Refusal::TargetNotRendered(target));
|
||||
};
|
||||
let same_role = match target {
|
||||
Target::Lane(_) => element.kind() == Kind::Lifeline,
|
||||
Target::Message(_) => matches!(
|
||||
element.shared(),
|
||||
Some(SharedBody::Occurrence {
|
||||
body: OccurrenceBody::Exchange { .. },
|
||||
..
|
||||
})
|
||||
),
|
||||
};
|
||||
if !same_role {
|
||||
return Err(Refusal::InvalidSelection(
|
||||
"Move a group of lifelines or a group of messages; mixed and other occurrence types are not supported.",
|
||||
));
|
||||
}
|
||||
members.push(target);
|
||||
}
|
||||
if !members.contains(&pressed) {
|
||||
return Err(Refusal::InvalidSelection(
|
||||
"The pressed occurrence is not in the captured selection.",
|
||||
));
|
||||
}
|
||||
members.sort_by_key(|target| target.id());
|
||||
capture_targets(project, diagram, pressed, &members)
|
||||
}
|
||||
|
||||
// Require the actual local sequence/operand path, not just an ancestor pointer.
|
||||
// Cross-operand groups are allowed; no member changes its existing parent.
|
||||
fn local_message(project: &Project, owner: Id, id: Id) -> bool {
|
||||
let mut current = id;
|
||||
let mut visited = BTreeSet::new();
|
||||
while current != owner && visited.insert(current) {
|
||||
let Some(element) = project.elements.get(¤t) else {
|
||||
return false;
|
||||
};
|
||||
let Some(parent) = element.parent.and_then(|id| project.elements.get(&id)) else {
|
||||
return false;
|
||||
};
|
||||
if element.layer() != project.elements[&owner].layer() {
|
||||
return false;
|
||||
}
|
||||
let listed = match parent.shared() {
|
||||
Some(SharedBody::Occurrence {
|
||||
body: OccurrenceBody::Fragment { branches, .. },
|
||||
..
|
||||
}) => {
|
||||
matches!(
|
||||
element.shared(),
|
||||
Some(SharedBody::Occurrence {
|
||||
body: OccurrenceBody::Branch { .. },
|
||||
..
|
||||
})
|
||||
) && branches.iter().filter(|&&id| id == current).count() == 1
|
||||
}
|
||||
_ => parent
|
||||
.steps()
|
||||
.is_some_and(|steps| steps.iter().filter(|&&id| id == current).count() == 1),
|
||||
};
|
||||
if !listed {
|
||||
return false;
|
||||
}
|
||||
current = parent.id;
|
||||
}
|
||||
current == owner
|
||||
}
|
||||
|
||||
fn captured_origin(
|
||||
project: &Project,
|
||||
owner: Id,
|
||||
geometry: &ResolvedScenarioPlan,
|
||||
target: Target,
|
||||
) -> Result<f32, Refusal> {
|
||||
let element = project.elements.get(&target.id());
|
||||
let origin = match target {
|
||||
Target::Lane(id)
|
||||
if element.is_some_and(|e| e.kind() == Kind::Lifeline && e.parent == Some(owner)) =>
|
||||
if element.is_some_and(|e| {
|
||||
e.kind() == Kind::Lifeline
|
||||
&& e.parent == Some(owner)
|
||||
&& e.layer() == project.elements[&owner].layer()
|
||||
}) =>
|
||||
{
|
||||
// Unassigned lifelines still have drawn headers. `scene.lanes`
|
||||
// excludes them only from semantic message-endpoint hit testing.
|
||||
geometry.scene.render_lanes.get(&id).copied()
|
||||
// Unassigned headers are still rendered local targets.
|
||||
let headers = geometry
|
||||
.scene
|
||||
.boxes
|
||||
.iter()
|
||||
.filter(|item| {
|
||||
item.id == id && item.role == crate::behavior::SceneHitRole::LifelineHeader
|
||||
})
|
||||
.count();
|
||||
(headers == 1)
|
||||
.then(|| geometry.scene.render_lanes.get(&id).copied())
|
||||
.flatten()
|
||||
}
|
||||
Target::Message(id)
|
||||
if element.is_some_and(|e| {
|
||||
@@ -79,17 +203,16 @@ pub(super) fn capture(project: &Project, diagram: Id, target: Target) -> Result<
|
||||
..
|
||||
})
|
||||
)
|
||||
}) =>
|
||||
}) && local_message(project, owner, id) =>
|
||||
{
|
||||
// A lifecycle row can denote receive y; the public position means
|
||||
// send y. Read the actual outgoing endpoint, including self calls.
|
||||
geometry
|
||||
.scene
|
||||
.lines
|
||||
.iter()
|
||||
.find(|line| line.id == id)
|
||||
// A lifecycle receive row is not the stored send coordinate. Reject
|
||||
// ambiguous repeated drawing IDs rather than choosing the first.
|
||||
let mut lines = geometry.scene.lines.iter().filter(|line| line.id == id);
|
||||
let first = lines
|
||||
.next()
|
||||
.and_then(|line| line.points.first())
|
||||
.map(|point| point.y)
|
||||
.map(|point| point.y);
|
||||
if lines.next().is_some() { None } else { first }
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
@@ -97,11 +220,38 @@ pub(super) fn capture(project: &Project, diagram: Id, target: Target) -> Result<
|
||||
if !origin.is_finite() {
|
||||
return Err(Refusal::TargetNotRendered(target));
|
||||
}
|
||||
Ok(origin)
|
||||
}
|
||||
|
||||
fn capture_targets(
|
||||
project: &Project,
|
||||
diagram: Id,
|
||||
target: Target,
|
||||
targets: &[Target],
|
||||
) -> Result<Drag, Refusal> {
|
||||
let representation = Representation::Saved { diagram };
|
||||
let owner = checked_owner(project, representation).ok_or(Refusal::InvalidSavedView(diagram))?;
|
||||
let geometry = resolve(project, representation, target.id()).map_err(Refusal::Geometry)?;
|
||||
let origins = targets
|
||||
.iter()
|
||||
.map(|member| {
|
||||
captured_origin(project, owner, &geometry, *member).map(|origin| (*member, origin))
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
let origin = origins
|
||||
.iter()
|
||||
.find(|(member, _)| *member == target)
|
||||
.expect("admitted pressed member")
|
||||
.1;
|
||||
Ok(Drag {
|
||||
original: project.clone(),
|
||||
diagram,
|
||||
target,
|
||||
origin,
|
||||
other_origins: origins
|
||||
.into_iter()
|
||||
.filter(|(member, _)| *member != target)
|
||||
.collect(),
|
||||
original_geometry: geometry,
|
||||
})
|
||||
}
|
||||
@@ -117,28 +267,50 @@ impl Drag {
|
||||
if original_delta == 0. {
|
||||
return Ok(None);
|
||||
}
|
||||
let position = (f64::from(self.origin) + f64::from(original_delta)) as f32;
|
||||
if position == self.origin {
|
||||
let mut commands = Vec::new();
|
||||
for (target, origin) in
|
||||
std::iter::once((self.target, self.origin)).chain(self.other_origins.iter().copied())
|
||||
{
|
||||
let position = (f64::from(origin) + f64::from(original_delta)) as f32;
|
||||
if !position.is_finite() || position.abs() > oa_core::MAX_COORDINATE {
|
||||
return Err(Refusal::Command(
|
||||
"Scenario positions must be finite and within the shared coordinate bounds."
|
||||
.into(),
|
||||
));
|
||||
}
|
||||
if position == origin {
|
||||
continue;
|
||||
}
|
||||
let command = match target {
|
||||
Target::Lane(lifeline) => Command::SetScenarioLanePosition {
|
||||
diagram: self.diagram,
|
||||
position: ScenarioLanePosition {
|
||||
lifeline,
|
||||
x: position,
|
||||
},
|
||||
},
|
||||
Target::Message(occurrence) => Command::SetScenarioMessagePosition {
|
||||
diagram: self.diagram,
|
||||
position: ScenarioMessagePosition {
|
||||
address: OccurrenceEndpoint {
|
||||
references: vec![],
|
||||
occurrence,
|
||||
},
|
||||
send_y: position,
|
||||
},
|
||||
},
|
||||
};
|
||||
commands.push((target.id(), command));
|
||||
}
|
||||
if commands.is_empty() {
|
||||
return Ok(None);
|
||||
}
|
||||
let command = match self.target {
|
||||
Target::Lane(lifeline) => Command::SetScenarioLanePosition {
|
||||
diagram: self.diagram,
|
||||
position: ScenarioLanePosition {
|
||||
lifeline,
|
||||
x: position,
|
||||
},
|
||||
},
|
||||
Target::Message(occurrence) => Command::SetScenarioMessagePosition {
|
||||
diagram: self.diagram,
|
||||
position: ScenarioMessagePosition {
|
||||
address: OccurrenceEndpoint {
|
||||
references: vec![],
|
||||
occurrence,
|
||||
},
|
||||
send_y: position,
|
||||
},
|
||||
},
|
||||
commands.sort_by_key(|(id, _)| *id);
|
||||
let mut commands: Vec<_> = commands.into_iter().map(|(_, command)| command).collect();
|
||||
let command = if self.other_origins.is_empty() {
|
||||
commands.pop().expect("changed singleton")
|
||||
} else {
|
||||
Command::Batch(commands)
|
||||
};
|
||||
let project = execute_batch(&self.original, std::slice::from_ref(&command))
|
||||
.map_err(|error| Refusal::Command(error.to_string()))?;
|
||||
|
||||
@@ -5,6 +5,7 @@ use crate::behavior::{
|
||||
scenario::{CanvasTool, Context, State},
|
||||
scenario_layout::Diagnostic,
|
||||
};
|
||||
use crate::{diagram_selection::Snapshot, diagram_usage::Target as SelectionTarget};
|
||||
use iced::{Point, Rectangle, Vector};
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -16,6 +17,7 @@ mod timing_tests;
|
||||
pub struct Stamp {
|
||||
pub(crate) context: Context,
|
||||
pub(crate) camera_epoch: u64,
|
||||
pub(crate) selection_generation: u64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
@@ -72,11 +74,14 @@ pub(crate) struct Session {
|
||||
drag: Drag,
|
||||
preview: Option<Preview>,
|
||||
refusal: Option<Refusal>,
|
||||
group_refusal: Option<Refusal>,
|
||||
ever_crossed: bool,
|
||||
snapshot: Option<Snapshot>,
|
||||
}
|
||||
|
||||
pub(in crate::behavior) struct Paint<'a> {
|
||||
pub(in crate::behavior) scene: &'a Scene,
|
||||
pub(in crate::behavior) selected_count: usize,
|
||||
#[cfg(test)]
|
||||
pub(in crate::behavior) bounds: Rectangle,
|
||||
pub(in crate::behavior) refusal: Option<&'a Refusal>,
|
||||
@@ -98,7 +103,21 @@ pub(crate) enum Finish {
|
||||
|
||||
impl Session {
|
||||
fn configure(&self, scene: &mut Scene) {
|
||||
scene.selected = self.drag.target.id();
|
||||
scene.selected = self
|
||||
.snapshot
|
||||
.as_ref()
|
||||
.filter(|s| s.targets().len() > 1)
|
||||
.and_then(|s| match s.primary() {
|
||||
Some(SelectionTarget::ScenarioObject(id)) => Some(*id),
|
||||
_ => None,
|
||||
})
|
||||
.unwrap_or(self.drag.target.id());
|
||||
scene.selection = self
|
||||
.snapshot
|
||||
.as_ref()
|
||||
.filter(|s| s.targets().len() > 1)
|
||||
.cloned()
|
||||
.map(|s| (self.stamp.context, s));
|
||||
scene.scale = self.scale;
|
||||
scene.camera_pan = self.pan;
|
||||
scene.interaction = Some((self.stamp.context, CanvasTool::Select, true));
|
||||
@@ -117,8 +136,18 @@ impl Session {
|
||||
Target::Lane(_) => screen.x - self.press_screen.x,
|
||||
Target::Message(_) => screen.y - self.press_screen.y,
|
||||
};
|
||||
self.ever_crossed |= distance.abs() >= 3.;
|
||||
if !self.ever_crossed {
|
||||
self.ever_crossed |= if self
|
||||
.snapshot
|
||||
.as_ref()
|
||||
.is_some_and(|s| s.targets().len() > 1)
|
||||
{
|
||||
screen.distance(self.press_screen) >= 3.
|
||||
} else {
|
||||
distance.abs() >= 3.
|
||||
};
|
||||
if !self.ever_crossed || self.group_refusal.is_some() {
|
||||
// A rejected whole set may retain a pressed singleton only as its
|
||||
// original display witness. It must never prepare a partial move.
|
||||
return;
|
||||
}
|
||||
match self.drag.prepare(distance / self.scale) {
|
||||
@@ -139,6 +168,9 @@ impl State {
|
||||
pub(crate) fn spacing_stamp(&self) -> Option<Stamp> {
|
||||
self.spacing.as_ref().map(|s| s.stamp)
|
||||
}
|
||||
pub(crate) fn spacing_snapshot(&self) -> Option<&Snapshot> {
|
||||
self.spacing.as_ref()?.snapshot.as_ref()
|
||||
}
|
||||
pub(crate) fn cancel_spacing(&mut self) -> bool {
|
||||
self.spacing.take().is_some()
|
||||
}
|
||||
@@ -149,28 +181,55 @@ impl State {
|
||||
camera_epoch: u64,
|
||||
) -> Option<Paint<'_>> {
|
||||
let session = self.spacing.as_ref()?;
|
||||
if session.stamp
|
||||
!= (Stamp {
|
||||
context,
|
||||
camera_epoch,
|
||||
})
|
||||
{
|
||||
if session.stamp.context != context || session.stamp.camera_epoch != camera_epoch {
|
||||
return None;
|
||||
}
|
||||
let original = &session.drag.original_geometry;
|
||||
let shown = session.preview.as_ref().map_or(original, |p| &p.geometry);
|
||||
Some(Paint {
|
||||
scene: &shown.scene,
|
||||
selected_count: session
|
||||
.snapshot
|
||||
.as_ref()
|
||||
.map_or(1, |s| s.targets().len().max(1)),
|
||||
#[cfg(test)]
|
||||
bounds: shown.bounds,
|
||||
refusal: session.refusal.as_ref(),
|
||||
refusal: session.refusal.as_ref().or_else(|| {
|
||||
session
|
||||
.ever_crossed
|
||||
.then_some(session.group_refusal.as_ref())
|
||||
.flatten()
|
||||
}),
|
||||
original_diagnostics: &original.plan.diagnostics,
|
||||
original_latent: &original.latent_messages,
|
||||
diagnostics: &shown.plan.diagnostics,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn begin_spacing(&mut self, project: &Project, event: Event) -> Result<(), Refusal> {
|
||||
self.begin_spacing_capture(project, event, None)
|
||||
}
|
||||
pub(crate) fn begin_spacing_with_snapshot(
|
||||
&mut self,
|
||||
project: &Project,
|
||||
event: Event,
|
||||
snapshot: Snapshot,
|
||||
) -> Result<(), Refusal> {
|
||||
if snapshot.generation() != event.stamp().selection_generation
|
||||
|| snapshot.context()
|
||||
!= crate::behavior::scenario::selection::context(event.stamp().context)
|
||||
{
|
||||
return Err(Refusal::InvalidGesture);
|
||||
}
|
||||
self.begin_spacing_capture(project, event, Some(snapshot))
|
||||
}
|
||||
fn begin_spacing_capture(
|
||||
&mut self,
|
||||
project: &Project,
|
||||
event: Event,
|
||||
snapshot: Option<Snapshot>,
|
||||
) -> Result<(), Refusal> {
|
||||
let Event::Begin {
|
||||
stamp,
|
||||
token,
|
||||
@@ -216,7 +275,34 @@ impl State {
|
||||
let Representation::Saved { diagram } = context.representation else {
|
||||
return Err(Refusal::InvalidGesture);
|
||||
};
|
||||
let mut drag = capture(project, diagram, target)?;
|
||||
let mut group_refusal = None;
|
||||
let mut drag = if let Some(selected) = snapshot.as_ref().filter(|s| s.targets().len() > 1) {
|
||||
if !selected
|
||||
.targets()
|
||||
.contains(&SelectionTarget::ScenarioObject(target.id()))
|
||||
{
|
||||
return Err(Refusal::TargetNotHit(target));
|
||||
}
|
||||
match capture_group(project, diagram, target, selected.targets()) {
|
||||
Ok(drag) => drag,
|
||||
Err(error)
|
||||
if matches!(
|
||||
&error,
|
||||
Refusal::InvalidSelection(_) | Refusal::TargetNotRendered(_)
|
||||
) =>
|
||||
{
|
||||
// Selection clicks do not require movement eligibility.
|
||||
// This capture supplies original paint and the exact hit
|
||||
// only; group_refusal forbids calling its prepare method.
|
||||
let original = capture(project, diagram, target)?;
|
||||
group_refusal = Some(error);
|
||||
original
|
||||
}
|
||||
Err(error) => return Err(error),
|
||||
}
|
||||
} else {
|
||||
capture(project, diagram, target)?
|
||||
};
|
||||
let camera = self.presentation.camera(drag.original_geometry.bounds);
|
||||
if self.presentation.viewport != Some(canvas_bounds.size())
|
||||
|| camera.scale != scale
|
||||
@@ -246,7 +332,19 @@ impl State {
|
||||
}
|
||||
// Configure baseline without changing the persistent camera or selection.
|
||||
let scene = &mut drag.original_geometry.scene;
|
||||
scene.selected = target.id();
|
||||
scene.selected = snapshot
|
||||
.as_ref()
|
||||
.filter(|s| s.targets().len() > 1)
|
||||
.and_then(|s| match s.primary() {
|
||||
Some(SelectionTarget::ScenarioObject(id)) => Some(*id),
|
||||
_ => None,
|
||||
})
|
||||
.unwrap_or(target.id());
|
||||
scene.selection = snapshot
|
||||
.as_ref()
|
||||
.filter(|s| s.targets().len() > 1)
|
||||
.cloned()
|
||||
.map(|s| (context, s));
|
||||
scene.scale = scale;
|
||||
scene.camera_pan = pan;
|
||||
scene.interaction = Some((context, CanvasTool::Select, true));
|
||||
@@ -262,7 +360,9 @@ impl State {
|
||||
drag,
|
||||
preview: None,
|
||||
refusal: None,
|
||||
group_refusal,
|
||||
ever_crossed: false,
|
||||
snapshot,
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
@@ -282,6 +382,9 @@ impl State {
|
||||
if !session.ever_crossed {
|
||||
return Ok(Finish::Click(session.drag.target.id()));
|
||||
}
|
||||
if let Some(error) = session.group_refusal {
|
||||
return Err(error);
|
||||
}
|
||||
Ok(match session.preview {
|
||||
None => Finish::Noop,
|
||||
Some(preview) => Finish::Commit {
|
||||
|
||||
@@ -95,6 +95,7 @@ pub(crate) fn packet(
|
||||
stamp: Stamp {
|
||||
context,
|
||||
camera_epoch,
|
||||
selection_generation: 0,
|
||||
},
|
||||
token: Id::new_v4(),
|
||||
target,
|
||||
@@ -135,6 +136,55 @@ fn press(event: Event) -> Point {
|
||||
press_screen
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn group_preview_keeps_captured_members_and_nonpressed_primary() {
|
||||
use crate::diagram_selection::Selection;
|
||||
use crate::diagram_usage::Target as Selected;
|
||||
let (doc, mut state, mut event) = setup(true);
|
||||
let context = event.stamp().context;
|
||||
let first = match event {
|
||||
Event::Begin { target, .. } => target.id(),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let second = doc
|
||||
.project()
|
||||
.identities()
|
||||
.into_iter()
|
||||
.find(|(_, alias)| *alias == "second")
|
||||
.unwrap()
|
||||
.0;
|
||||
let selection_context = crate::behavior::scenario::selection::context(context);
|
||||
let mut selection = Selection::new(selection_context.scope);
|
||||
selection.add(Selected::ScenarioObject(first), |_| true);
|
||||
selection.add(Selected::ScenarioObject(second), |_| true);
|
||||
let snapshot = selection.snapshot(selection_context).unwrap();
|
||||
if let Event::Begin { stamp, .. } = &mut event {
|
||||
stamp.selection_generation = snapshot.generation();
|
||||
}
|
||||
let start = press(event);
|
||||
state
|
||||
.begin_spacing_with_snapshot(doc.project(), event, snapshot.clone())
|
||||
.unwrap();
|
||||
for delta in [Vector::new(0., 0.), Vector::new(0., 24.)] {
|
||||
state.move_spacing(start + delta);
|
||||
let paint = state
|
||||
.spacing_paint(context, event.stamp().camera_epoch)
|
||||
.unwrap();
|
||||
assert_eq!(paint.scene.selected, second);
|
||||
assert_eq!(
|
||||
paint.scene.selection.as_ref().unwrap(),
|
||||
&(context, snapshot.clone())
|
||||
);
|
||||
assert_eq!(paint.selected_count, 2);
|
||||
}
|
||||
state.move_spacing(start + Vector::new(50., 0.));
|
||||
assert!(matches!(
|
||||
state.finish_spacing(start + Vector::new(50., 0.)).unwrap(),
|
||||
Finish::Noop
|
||||
));
|
||||
assert!(!doc.can_undo());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn real_preview_moves_only_active_axis_from_original_and_never_changes_document() {
|
||||
for message in [false, true] {
|
||||
|
||||
@@ -0,0 +1,675 @@
|
||||
use super::*;
|
||||
use crate::document::Document;
|
||||
use oa_core::{Diagram, DiagramLayout, Layer, ProjectionKind, ScenarioLayout, language};
|
||||
|
||||
fn id(project: &Project, alias: &str) -> Id {
|
||||
project
|
||||
.identities()
|
||||
.into_iter()
|
||||
.find(|(_, name)| *name == alias)
|
||||
.unwrap()
|
||||
.0
|
||||
}
|
||||
|
||||
fn fixture(layout: Option<ScenarioLayout>) -> (Document, Id, Id) {
|
||||
let mut project = language::parse(FIXTURE).unwrap();
|
||||
let owner = id(&project, "conversation");
|
||||
let right = id(&project, "right");
|
||||
let mut views = Vec::new();
|
||||
for (alias, layout) in [
|
||||
("active_view", layout),
|
||||
(
|
||||
"untouched_view",
|
||||
Some(ScenarioLayout {
|
||||
lanes: vec![ScenarioLanePosition {
|
||||
lifeline: right,
|
||||
x: 700.,
|
||||
}],
|
||||
messages: vec![],
|
||||
}),
|
||||
),
|
||||
] {
|
||||
let diagram = Id::new_v4();
|
||||
project.diagrams.insert(
|
||||
diagram,
|
||||
Diagram {
|
||||
id: diagram,
|
||||
alias: alias.into(),
|
||||
name: alias.into(),
|
||||
description: "Preserve authored view metadata".into(),
|
||||
layer: Layer::Oa,
|
||||
projection: ProjectionKind::Scenario { scenario: owner },
|
||||
nodes: Default::default(),
|
||||
routes: vec![],
|
||||
view_options: Default::default(),
|
||||
layout: layout.map(DiagramLayout::Scenario),
|
||||
},
|
||||
);
|
||||
views.push(diagram);
|
||||
}
|
||||
(
|
||||
Document::from_project(project, Default::default()).unwrap(),
|
||||
views[0],
|
||||
views[1],
|
||||
)
|
||||
}
|
||||
|
||||
fn targets(ids: &[Id]) -> Vec<SelectionTarget> {
|
||||
ids.iter()
|
||||
.copied()
|
||||
.map(SelectionTarget::ScenarioObject)
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn message(occurrence: Id, send_y: f32) -> ScenarioMessagePosition {
|
||||
ScenarioMessagePosition {
|
||||
address: OccurrenceEndpoint {
|
||||
references: vec![],
|
||||
occurrence,
|
||||
},
|
||||
send_y,
|
||||
}
|
||||
}
|
||||
|
||||
// Literal expected authored payload, not another execution of planner commands.
|
||||
fn expected(
|
||||
project: &Project,
|
||||
diagram: Id,
|
||||
lanes: Vec<ScenarioLanePosition>,
|
||||
messages: Vec<ScenarioMessagePosition>,
|
||||
) -> Project {
|
||||
let mut result = project.clone();
|
||||
result.diagrams.get_mut(&diagram).unwrap().layout =
|
||||
Some(DiagramLayout::Scenario(ScenarioLayout { lanes, messages }));
|
||||
result
|
||||
}
|
||||
|
||||
fn exact_transaction(mut document: Document, preview: Preview, expected: Project) {
|
||||
let original = document.snapshot();
|
||||
let revision = document.revision();
|
||||
assert_eq!(preview.project, expected);
|
||||
assert!(matches!(&preview.command, Command::Batch(_)));
|
||||
document.execute(preview.command).unwrap();
|
||||
assert_eq!(document.project(), &expected);
|
||||
assert_eq!(document.revision(), revision + 1);
|
||||
let changed = document.bundle().clone();
|
||||
assert_ne!(changed, original.bundle);
|
||||
assert_eq!(
|
||||
language::parse(&language::format(document.project())).unwrap(),
|
||||
expected
|
||||
);
|
||||
assert!(document.undo());
|
||||
assert_eq!(document.project(), &original.decoded.project);
|
||||
assert_eq!(document.bundle(), &original.bundle);
|
||||
assert!(!document.can_undo());
|
||||
assert!(document.redo());
|
||||
assert_eq!(document.project(), &expected);
|
||||
assert_eq!(document.bundle(), &changed);
|
||||
assert!(!document.can_redo());
|
||||
let reopened = Document::from_bundle(changed, Default::default()).unwrap();
|
||||
assert_eq!(reopened.project(), &expected);
|
||||
assert!(!reopened.dirty() && !reopened.can_undo());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn group_messages_move_from_each_original_with_press_and_selection_order_independent() {
|
||||
let (document, diagram, other) = fixture(None);
|
||||
let before = document.project();
|
||||
let first = id(before, "first");
|
||||
let second = id(before, "second");
|
||||
let wanted = expected(
|
||||
before,
|
||||
diagram,
|
||||
vec![],
|
||||
vec![message(first, 188.), message(second, 280.)],
|
||||
);
|
||||
for members in [[first, second], [second, first]] {
|
||||
for pressed in [first, second] {
|
||||
let drag = capture_group(
|
||||
before,
|
||||
diagram,
|
||||
Target::Message(pressed),
|
||||
&targets(&members),
|
||||
)
|
||||
.unwrap();
|
||||
let preview = drag.prepare(40.).unwrap().unwrap();
|
||||
assert_eq!(preview.project, wanted);
|
||||
assert_eq!(preview.project.diagrams[&other], before.diagrams[&other]);
|
||||
assert_eq!(drag.original, *before);
|
||||
}
|
||||
}
|
||||
let preview = capture_group(
|
||||
before,
|
||||
diagram,
|
||||
Target::Message(second),
|
||||
&targets(&[second, first]),
|
||||
)
|
||||
.unwrap()
|
||||
.prepare(40.)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
exact_transaction(document, preview, wanted);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn group_lanes_vacate_each_others_space_in_one_candidate_and_one_history_entry() {
|
||||
let (document, diagram, _) = fixture(None);
|
||||
let before = document.project();
|
||||
let left = id(before, "left");
|
||||
let right = id(before, "right");
|
||||
// Moving only Left into Right's old x cannot render a distinct-endpoint arrow.
|
||||
assert!(matches!(
|
||||
capture(before, diagram, Target::Lane(left))
|
||||
.unwrap()
|
||||
.prepare(240.),
|
||||
Err(Refusal::Geometry(_))
|
||||
));
|
||||
let wanted = expected(
|
||||
before,
|
||||
diagram,
|
||||
vec![
|
||||
ScenarioLanePosition {
|
||||
lifeline: left,
|
||||
x: 400.,
|
||||
},
|
||||
ScenarioLanePosition {
|
||||
lifeline: right,
|
||||
x: 640.,
|
||||
},
|
||||
],
|
||||
vec![],
|
||||
);
|
||||
for pressed in [left, right] {
|
||||
let preview = capture_group(
|
||||
before,
|
||||
diagram,
|
||||
Target::Lane(pressed),
|
||||
&targets(&[right, left]),
|
||||
)
|
||||
.unwrap()
|
||||
.prepare(240.)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(preview.project, wanted);
|
||||
assert_eq!(preview.geometry.scene.render_lanes[&left], 400.);
|
||||
assert_eq!(preview.geometry.scene.render_lanes[&right], 640.);
|
||||
}
|
||||
let preview = capture_group(
|
||||
before,
|
||||
diagram,
|
||||
Target::Lane(right),
|
||||
&targets(&[left, right]),
|
||||
)
|
||||
.unwrap()
|
||||
.prepare(240.)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
exact_transaction(document, preview, wanted);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn self_call_and_reply_are_validated_together_but_partial_candidate_is_refused() {
|
||||
let (document, diagram, _) = fixture(None);
|
||||
let before = document.project();
|
||||
let call = id(before, "call");
|
||||
let reply = id(before, "reply");
|
||||
let first = id(before, "first");
|
||||
assert!(matches!(
|
||||
capture(before, diagram, Target::Message(call))
|
||||
.unwrap()
|
||||
.prepare(118.),
|
||||
Err(Refusal::Geometry(_))
|
||||
));
|
||||
let drag = capture_group(
|
||||
before,
|
||||
diagram,
|
||||
Target::Message(reply),
|
||||
&targets(&[reply, call]),
|
||||
)
|
||||
.unwrap();
|
||||
let preview = drag.prepare(118.).unwrap().unwrap();
|
||||
assert_eq!(
|
||||
preview.project,
|
||||
expected(
|
||||
before,
|
||||
diagram,
|
||||
vec![],
|
||||
vec![message(call, 450.), message(reply, 542.)]
|
||||
)
|
||||
);
|
||||
let line = preview
|
||||
.geometry
|
||||
.scene
|
||||
.lines
|
||||
.iter()
|
||||
.find(|line| line.id == call)
|
||||
.unwrap();
|
||||
assert_eq!(line.points.first().unwrap().y, 450.);
|
||||
assert_eq!(line.points.last().unwrap().y, 474.);
|
||||
let partial = capture_group(
|
||||
before,
|
||||
diagram,
|
||||
Target::Message(first),
|
||||
&targets(&[first, call]),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(matches!(partial.prepare(118.), Err(Refusal::Geometry(_))));
|
||||
assert_eq!(partial.original, *before);
|
||||
assert!(!document.can_undo());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exact_set_admission_rejects_empty_duplicates_mixed_unsupported_missing_and_unpressed() {
|
||||
let (document, diagram, _) = fixture(None);
|
||||
let before = document.project();
|
||||
let first = id(before, "first");
|
||||
let second = id(before, "second");
|
||||
let left = id(before, "left");
|
||||
let source = id(before, "source");
|
||||
let unfinished = id(before, "unfinished");
|
||||
for selection in [
|
||||
vec![],
|
||||
targets(&[first, first]),
|
||||
targets(&[first, left]),
|
||||
targets(&[first, source]),
|
||||
targets(&[first, Id::new_v4()]),
|
||||
targets(&[second]),
|
||||
targets(&[first, unfinished]),
|
||||
vec![
|
||||
SelectionTarget::ScenarioObject(first),
|
||||
SelectionTarget::Whole,
|
||||
],
|
||||
vec![
|
||||
SelectionTarget::ScenarioObject(first),
|
||||
SelectionTarget::Placement(second),
|
||||
],
|
||||
] {
|
||||
assert!(
|
||||
capture_group(before, diagram, Target::Message(first), &selection).is_err(),
|
||||
"{selection:?}"
|
||||
);
|
||||
}
|
||||
assert!(
|
||||
capture_group(
|
||||
before,
|
||||
Id::nil(),
|
||||
Target::Message(first),
|
||||
&targets(&[first, second])
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
assert!(
|
||||
capture_group(
|
||||
before,
|
||||
diagram,
|
||||
Target::Lane(first),
|
||||
&targets(&[first, second])
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
assert!(!document.dirty() && !document.can_undo());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn foreign_unlisted_and_ambiguous_local_messages_cannot_enter_a_group() {
|
||||
let (document, diagram, _) = fixture(None);
|
||||
let before = document.project();
|
||||
let first = id(before, "first");
|
||||
let second = id(before, "second");
|
||||
let owner = id(before, "conversation");
|
||||
for case in 0..3 {
|
||||
let mut project = before.clone();
|
||||
match case {
|
||||
0 => {
|
||||
let foreign = project
|
||||
.add_element(Kind::Scenario, Layer::Oa, "Foreign", None)
|
||||
.unwrap();
|
||||
project.elements.get_mut(&second).unwrap().parent = Some(foreign);
|
||||
}
|
||||
1 => project
|
||||
.elements
|
||||
.get_mut(&owner)
|
||||
.unwrap()
|
||||
.steps_mut()
|
||||
.unwrap()
|
||||
.retain(|id| *id != second),
|
||||
_ => project
|
||||
.elements
|
||||
.get_mut(&owner)
|
||||
.unwrap()
|
||||
.steps_mut()
|
||||
.unwrap()
|
||||
.push(second),
|
||||
}
|
||||
assert!(
|
||||
capture_group(
|
||||
&project,
|
||||
diagram,
|
||||
Target::Message(first),
|
||||
&targets(&[first, second])
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fallback_baseline_is_refused_before_any_zero_motion_can_be_planned() {
|
||||
let (document, diagram, _) = fixture(None);
|
||||
let call = id(document.project(), "call");
|
||||
let reply = id(document.project(), "reply");
|
||||
let invalid = expected(
|
||||
document.project(),
|
||||
diagram,
|
||||
vec![],
|
||||
vec![message(call, 450.)],
|
||||
);
|
||||
let shown = crate::behavior::scenario_layout::presentation::present(
|
||||
&invalid,
|
||||
Representation::Saved { diagram },
|
||||
call,
|
||||
);
|
||||
assert!(shown.capabilities().geometry_navigation);
|
||||
assert!(!shown.capabilities().coordinate_input);
|
||||
assert!(matches!(
|
||||
capture_group(
|
||||
&invalid,
|
||||
diagram,
|
||||
Target::Message(reply),
|
||||
&targets(&[reply, call])
|
||||
),
|
||||
Err(Refusal::Geometry(_))
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn group_noops_preserve_sparse_overrides_complete_source_and_existing_redo() {
|
||||
for sparse in [true, false] {
|
||||
let (mut document, diagram, _) = fixture((!sparse).then(ScenarioLayout::default));
|
||||
let first = id(document.project(), "first");
|
||||
let second = id(document.project(), "second");
|
||||
let owner = id(document.project(), "conversation");
|
||||
document
|
||||
.execute(Command::Rename(owner, "Redo sentinel".into()))
|
||||
.unwrap();
|
||||
let redo = document.snapshot();
|
||||
assert!(document.undo());
|
||||
let original = document.snapshot();
|
||||
let revision = document.revision();
|
||||
let drag = capture_group(
|
||||
document.project(),
|
||||
diagram,
|
||||
Target::Message(second),
|
||||
&targets(&[second, first]),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(drag.prepare(30.).unwrap().is_some());
|
||||
for delta in [0., -0., f32::from_bits(1)] {
|
||||
assert!(drag.prepare(delta).unwrap().is_none());
|
||||
}
|
||||
assert!(std::sync::Arc::ptr_eq(&original, &document.snapshot()));
|
||||
assert_eq!(document.bundle(), &original.bundle);
|
||||
assert_eq!(document.revision(), revision);
|
||||
assert_eq!(drag.original, original.decoded.project);
|
||||
assert!(document.redo());
|
||||
assert_eq!(document.project(), &redo.decoded.project);
|
||||
assert_eq!(document.bundle(), &redo.bundle);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn subprecision_unchanged_member_does_not_materialize_an_absent_override() {
|
||||
let (document, diagram, _) = fixture(None);
|
||||
let first = id(document.project(), "first");
|
||||
let second = id(document.project(), "second");
|
||||
let project = expected(
|
||||
document.project(),
|
||||
diagram,
|
||||
vec![],
|
||||
vec![message(first, 0.)],
|
||||
);
|
||||
let delta = 0.000001_f32;
|
||||
assert_eq!(240_f32 + delta, 240.);
|
||||
let preview = capture_group(
|
||||
&project,
|
||||
diagram,
|
||||
Target::Message(second),
|
||||
&targets(&[second, first]),
|
||||
)
|
||||
.unwrap()
|
||||
.prepare(delta)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
preview.project,
|
||||
expected(&project, diagram, vec![], vec![message(first, delta)])
|
||||
);
|
||||
assert!(matches!(preview.command, Command::Batch(ref commands) if commands.len() == 1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_delta_or_one_out_of_bounds_member_refuses_the_whole_group() {
|
||||
let (document, diagram, _) = fixture(None);
|
||||
let left = id(document.project(), "left");
|
||||
let right = id(document.project(), "right");
|
||||
let project = expected(
|
||||
document.project(),
|
||||
diagram,
|
||||
vec![ScenarioLanePosition {
|
||||
lifeline: right,
|
||||
x: 999_990.,
|
||||
}],
|
||||
vec![],
|
||||
);
|
||||
let drag = capture_group(
|
||||
&project,
|
||||
diagram,
|
||||
Target::Lane(left),
|
||||
&targets(&[left, right]),
|
||||
)
|
||||
.unwrap();
|
||||
for delta in [f32::NAN, f32::INFINITY, f32::NEG_INFINITY] {
|
||||
assert!(matches!(drag.prepare(delta), Err(Refusal::InvalidDelta)));
|
||||
}
|
||||
for delta in [20., f32::MAX, -f32::MAX] {
|
||||
assert!(matches!(drag.prepare(delta), Err(Refusal::Command(_))));
|
||||
}
|
||||
assert_eq!(drag.original, project);
|
||||
assert!(drag.prepare(0.).unwrap().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn singleton_capture_group_retains_existing_singleton_command_and_result() {
|
||||
let (document, diagram, _) = fixture(None);
|
||||
for target in [
|
||||
Target::Lane(id(document.project(), "right")),
|
||||
Target::Message(id(document.project(), "second")),
|
||||
] {
|
||||
let single = capture(document.project(), diagram, target)
|
||||
.unwrap()
|
||||
.prepare(25.)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let group = capture_group(
|
||||
document.project(),
|
||||
diagram,
|
||||
target,
|
||||
&targets(&[target.id()]),
|
||||
)
|
||||
.unwrap()
|
||||
.prepare(25.)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(group.project, single.project);
|
||||
assert!(!matches!(group.command, Command::Batch(_)));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn existing_layout_order_and_unselected_values_are_preserved_exactly() {
|
||||
let (document, diagram, _) = fixture(None);
|
||||
let first = id(document.project(), "first");
|
||||
let second = id(document.project(), "second");
|
||||
let reply = id(document.project(), "reply");
|
||||
let right = id(document.project(), "right");
|
||||
let lanes = vec![ScenarioLanePosition {
|
||||
lifeline: right,
|
||||
x: 400.,
|
||||
}];
|
||||
let project = expected(
|
||||
document.project(),
|
||||
diagram,
|
||||
lanes.clone(),
|
||||
vec![message(reply, 424.), message(first, 148.)],
|
||||
);
|
||||
let preview = capture_group(
|
||||
&project,
|
||||
diagram,
|
||||
Target::Message(second),
|
||||
&targets(&[second, first]),
|
||||
)
|
||||
.unwrap()
|
||||
.prepare(40.)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
preview.project,
|
||||
expected(
|
||||
&project,
|
||||
diagram,
|
||||
lanes,
|
||||
vec![
|
||||
message(reply, 424.),
|
||||
message(first, 188.),
|
||||
message(second, 280.)
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn local_messages_in_different_operands_move_without_reparenting_or_reordering() {
|
||||
use crate::behavior::topology::occurrence;
|
||||
let (document, diagram, _) = fixture(None);
|
||||
let mut project = document.project().clone();
|
||||
let owner = id(&project, "conversation");
|
||||
let first = id(&project, "first");
|
||||
let second = id(&project, "second");
|
||||
let fragment = occurrence(
|
||||
&project,
|
||||
owner,
|
||||
"Alternatives",
|
||||
OccurrenceBody::Fragment {
|
||||
operator: oa_core::FragmentOperator::Alternative,
|
||||
branches: vec![],
|
||||
},
|
||||
);
|
||||
let frame = fragment.id;
|
||||
project.elements.insert(frame, fragment);
|
||||
let mut branches = Vec::new();
|
||||
for member in [first, second] {
|
||||
let branch = occurrence(
|
||||
&project,
|
||||
frame,
|
||||
"Operand",
|
||||
OccurrenceBody::Branch {
|
||||
guard: "ready".into(),
|
||||
occurrences: vec![member],
|
||||
},
|
||||
);
|
||||
let branch_id = branch.id;
|
||||
project.elements.insert(branch_id, branch);
|
||||
project.elements.get_mut(&member).unwrap().parent = Some(branch_id);
|
||||
branches.push(branch_id);
|
||||
}
|
||||
if let Some(SharedBody::Occurrence {
|
||||
body: OccurrenceBody::Fragment {
|
||||
branches: items, ..
|
||||
},
|
||||
..
|
||||
}) = project.elements.get_mut(&frame).unwrap().shared_mut()
|
||||
{
|
||||
*items = branches.clone();
|
||||
} else {
|
||||
unreachable!();
|
||||
}
|
||||
let steps = project
|
||||
.elements
|
||||
.get_mut(&owner)
|
||||
.unwrap()
|
||||
.steps_mut()
|
||||
.unwrap();
|
||||
steps.retain(|id| ![first, second].contains(id));
|
||||
steps.insert(0, frame);
|
||||
let document = Document::from_project(project, Default::default()).unwrap();
|
||||
let project = document.project();
|
||||
let baseline = resolve(project, Representation::Saved { diagram }, first).unwrap();
|
||||
let original_send = |id| {
|
||||
baseline
|
||||
.scene
|
||||
.lines
|
||||
.iter()
|
||||
.find(|line| line.id == id)
|
||||
.unwrap()
|
||||
.points[0]
|
||||
.y
|
||||
};
|
||||
let preview = capture_group(
|
||||
project,
|
||||
diagram,
|
||||
Target::Message(second),
|
||||
&targets(&[second, first]),
|
||||
)
|
||||
.unwrap()
|
||||
.prepare(-5.)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
preview.project,
|
||||
expected(
|
||||
project,
|
||||
diagram,
|
||||
vec![],
|
||||
vec![
|
||||
message(first, original_send(first) - 5.),
|
||||
message(second, original_send(second) - 5.)
|
||||
]
|
||||
)
|
||||
);
|
||||
assert_eq!(preview.project.elements, project.elements);
|
||||
let mut omitted = project.clone();
|
||||
if let Some(SharedBody::Occurrence {
|
||||
body: OccurrenceBody::Fragment {
|
||||
branches: items, ..
|
||||
},
|
||||
..
|
||||
}) = omitted.elements.get_mut(&frame).unwrap().shared_mut()
|
||||
{
|
||||
items.retain(|id| *id != branches[1]);
|
||||
}
|
||||
assert!(
|
||||
capture_group(
|
||||
&omitted,
|
||||
diagram,
|
||||
Target::Message(first),
|
||||
&targets(&[first, second])
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
|
||||
const FIXTURE: &str = r#"arcadia 7;
|
||||
project spacing_group "Saved group spacing" id "71000000-0000-4000-8000-000000000001" {
|
||||
oa_activity source "Source" id "71000000-0000-4000-8000-000000000002" {}
|
||||
oa_activity target "Target" id "71000000-0000-4000-8000-000000000003" {}
|
||||
interaction exchange "Repeated exchange" id "71000000-0000-4000-8000-000000000004" { source @source; target @target; }
|
||||
oa_scenario conversation "Conversation" id "71000000-0000-4000-8000-000000000005" { viewpoint OperationalActivity; steps [@first, @second, @call, @reply, @unfinished]; }
|
||||
oa_lifeline left "Left" id "71000000-0000-4000-8000-000000000006" { parent @conversation; represented @source; }
|
||||
oa_lifeline right "Right" id "71000000-0000-4000-8000-000000000007" { parent @conversation; represented @target; }
|
||||
oa_occurrence first "First" id "71000000-0000-4000-8000-000000000008" { parent @conversation; body { Exchange { exchange @exchange; sender @left; receiver @right; message_kind Asynchronous; }; }; }
|
||||
oa_occurrence second "Second" id "71000000-0000-4000-8000-000000000009" { parent @conversation; body { Exchange { exchange @exchange; sender @left; receiver @right; message_kind Asynchronous; }; }; }
|
||||
oa_occurrence call "Call" id "71000000-0000-4000-8000-00000000000a" { parent @conversation; body { Exchange { exchange none; sender @right; receiver @right; message_kind Call; }; }; }
|
||||
oa_occurrence reply "Reply" id "71000000-0000-4000-8000-00000000000b" { parent @conversation; body { Exchange { exchange none; sender @right; receiver @right; message_kind Reply; reply_to @call; }; }; }
|
||||
oa_occurrence unfinished "Unfinished" id "71000000-0000-4000-8000-00000000000c" { parent @conversation; body { Exchange { exchange @exchange; sender @left; receiver none; message_kind Asynchronous; }; }; }
|
||||
}
|
||||
"#;
|
||||
@@ -144,10 +144,14 @@ pub fn view<'a>(app: &'a App, owner: Id, out: Column<'a, Message>) -> Element<'a
|
||||
&& !app.source_rename.open()
|
||||
&& keyboard
|
||||
&& matches!(context.representation, Representation::Saved { .. }))
|
||||
.then_some(spacing::Stamp {
|
||||
context,
|
||||
camera_epoch: app.camera_epoch,
|
||||
});
|
||||
.then(|| {
|
||||
snapshot.as_ref().map(|snapshot| spacing::Stamp {
|
||||
context,
|
||||
camera_epoch: app.camera_epoch,
|
||||
selection_generation: snapshot.generation(),
|
||||
})
|
||||
})
|
||||
.flatten();
|
||||
scene.coordinate_input = capabilities.coordinate_input;
|
||||
scene.pending_placement = coordinate_input
|
||||
.then(|| state.pending_placement(owner))
|
||||
@@ -162,6 +166,11 @@ pub fn view<'a>(app: &'a App, owner: Id, out: Column<'a, Message>) -> Element<'a
|
||||
let mut layers = iced::widget::stack![raw_canvas];
|
||||
if let Some(paint) = &preview {
|
||||
let feedback = spacing_feedback(p, paint.refusal, paint.diagnostics);
|
||||
let feedback = if paint.selected_count > 1 {
|
||||
format!("{} selected - {feedback}", paint.selected_count)
|
||||
} else {
|
||||
feedback
|
||||
};
|
||||
layers = layers.push(
|
||||
container(
|
||||
container(text(feedback).size(12))
|
||||
|
||||
@@ -184,6 +184,10 @@ impl Selection {
|
||||
}
|
||||
|
||||
impl Snapshot {
|
||||
pub(crate) fn generation(&self) -> u64 {
|
||||
self.generation
|
||||
}
|
||||
|
||||
pub fn context(&self) -> Context {
|
||||
self.context
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
# Saved Scenario group spacing
|
||||
|
||||
Derived from [issue 29](http://217.177.34.108:3000/sorokin.oleg.edu/ARCADIA-Studio/issues/29), the user-owned graphical editing requirements, the [multiple-selection contract](multiselect-contract-20260923.md), and existing Saved singleton spacing. This specifies the next bounded implementation, not completed runtime acceptance.
|
||||
|
||||
## Intent and scope
|
||||
|
||||
Ordinary dragging in a Saved Scenario already adjusts presentation spacing. Extend that operation to the complete homogeneous selected group: messages move their authored send coordinates by one vertical delta; lifelines move their authored horizontal positions by one horizontal delta. Measure each original coordinate from the actual rendered local occurrence, including lifecycle messages whose displayed receive row differs from the send endpoint. Click order and the pressed member do not choose a subset, reorder semantics or change primary.
|
||||
|
||||
Selected local messages may span immediate operands because spacing does not change their containment or step lists. All original targets must be unique, locally owned and actually rendered in the admitted Ready saved representation. Reject mixed lifeline/message sets, unsupported body/typed targets, foreign/referenced subjects, missing/ambiguous targets and fallback/unavailable originals as complete sets. Do not filter to eligible members. These refusals delimit this increment; mixed presentation movement, semantic reorder and aggregate removal remain required follow-ups.
|
||||
|
||||
Prepare all changed positions together in one command batch and validate the complete candidate geometry once. Preserve every semantic declaration, sequence, reference, binding, other view, route and unrelated authored position. The presentation resolver remains authoritative for legal layout; visible dependent geometry may respond to the new positions. Do not promise rigid translation of every line point, since lifecycle and other derived geometry already has its own constraints. Reject an invalid whole candidate without partially applying a member. A point whose requested delta is below its representable precision should not materialize or normalize its unchanged override.
|
||||
|
||||
## Input and lifetime
|
||||
|
||||
Capture full Scenario document/owner/representation/visit/revision/epoch, camera/bounds and exact shared selection Snapshot. Copy event packets carry the captured selection generation; admission matches it and context before capturing the full live Snapshot into the session. Every later packet must match the same session token/stamp and full snapshot before status, selection, reconciliation or mutation. Selection-generation changes, source/model changes, representation visits, camera/bounds changes, focus loss, Escape and outside release retire the applicable input lifetime.
|
||||
|
||||
The original pressed member must belong to a captured group. First-press movement onto a different singleton retains existing behavior. A stationary release on a selected group member performs the existing explicit collapse to that member. For groups, once pointer displacement reaches three screen pixels in any direction, returning to the origin or moving only along the inactive axis is a no-op retaining the group and primary, not a delayed collapse. Singleton threshold semantics remain unchanged. A preview retains the original group/primary and frozen camera; it changes no document/source/history.
|
||||
|
||||
Consume admitted terminal outcomes and admitted failed starts even if the document is unchanged, so an old Begin cannot restart after cancel/no-op/refusal. Reject stale packets before they can consume a newer operation. Commit one Document transaction after revalidating the captured selection; a source-write failure preserves the accepted document/source/history, camera and complete group. Successful Undo/Redo and reopened source must reproduce the complete expected project. Selection membership is transient and is not persisted into source.
|
||||
|
||||
Movement ineligibility must not disable ordinary selection: an otherwise admitted stationary press/release on a mixed group's member still collapses to that member. A pending eligibility refusal may retain that member's original display as a hit/camera witness, but must never prepare or preview its singleton move. Once movement crosses the threshold, report the complete-set refusal and preserve the group.
|
||||
|
||||
## Priority decision and alternatives
|
||||
|
||||
The existing [semantic sibling-block planner](scenario-group-reorder-policy-20260924.md) remains useful but does not fulfill the user's ordinary group-move request. Extending default Saved spacing now is more direct than first building an explicit semantic reorder handle or one-shot arm. It also avoids silently giving the same body drag a different meaning for singleton versus group. This changes implementation priority, not the semantic reorder contract.
|
||||
|
||||
For the later explicitly named Reorder operation, compare a fixed drag handle plus order preview with a compact destination chooser plus the same preview; an arm introduces an extra lifetime and potential next-drag ambiguity. Saved authored positions may differ from semantic order, so exact before-anchor/parent and proposed/resulting order must be observable. Geometric input must use its actual nearest slot without substituting a farther legal target; direct named-slot choice is a distinct input contract that must be specified explicitly. The comparison and unavailable-candidate-display policy remain open; no chooser or handle is accepted here.
|
||||
|
||||
## Discriminating acceptance
|
||||
|
||||
- Shift-select two messages in reverse order and drag either member; both send coordinates change by the same world delta, primary/membership and all semantic steps/other views stay exact. Repeat with two lifeline headers and a horizontal delta.
|
||||
- Verify actual outgoing positions for lifecycle/self/repeated messages, local cross-operand groups, absent and existing overrides, and deterministic whole results independent of pressed/click order.
|
||||
- Preview remains transient and displays the whole selection. One commit, one Undo/Redo, save/reopen and the following singleton spacing operation retain their intended meanings.
|
||||
- Stationary collapse, off-axis drag, out-and-back, cancellation and invalid destination preserve the appropriate group/document and an existing redo branch. Mixed or hidden sets never become primary-only operations.
|
||||
- Reject selection ABA, representation A→B→A, stale Begin/Hover/Finish/Cancel and duplicate packets before newer state is disturbed. Include dirty source/property drafts and atomic source-write failure.
|
||||
- Run a mounted pointer/selection sequence and real packaged/direct desktop workflows, inspecting feedback and preserved group. Automated input and native operator evidence remain distinct; do not claim unexercised held-modifier accessibility or general usability.
|
||||
Reference in New Issue
Block a user