Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ce7324a80 | ||
|
|
aaf5fec28b | ||
|
|
37be41092b |
+28
-272
@@ -10,17 +10,13 @@ mod hosted;
|
||||
mod reference_authoring;
|
||||
#[cfg(test)]
|
||||
mod review_navigation_tests;
|
||||
#[cfg(test)]
|
||||
mod scenario_details_tests;
|
||||
mod scenario_diagram;
|
||||
mod scenario_spacing;
|
||||
pub(crate) mod source_rename;
|
||||
mod source_symbols;
|
||||
#[cfg(test)]
|
||||
mod transition_context_tests;
|
||||
#[cfg(test)]
|
||||
mod view_copy_tests;
|
||||
pub(crate) const SAVED_SCENARIO_UNAVAILABLE: &str = "This action uses architecture diagram tools and is unavailable for a saved Scenario. Open the view in Behavior; saved positions are preserved.";
|
||||
pub(crate) const SAVED_SCENARIO_UNAVAILABLE: &str = "Saved Scenario layout rendering and canvas editing are not available yet. Select the Scenario in Behavior to use its existing semantic preview.";
|
||||
use crate::forms::Draft;
|
||||
use crate::{
|
||||
behavior,
|
||||
@@ -534,7 +530,6 @@ pub struct App {
|
||||
pub(crate) diagram_navigation_focus: Option<crate::diagram_usage::Focus>,
|
||||
source_diagram_job: Option<Id>,
|
||||
diagram_lookup_in_flight: Option<Id>,
|
||||
pending_scenario_reveal_visit: Option<Id>,
|
||||
pending_diagram_reveal: Option<(
|
||||
crate::diagram_usage::Context,
|
||||
crate::diagram_usage::Usage,
|
||||
@@ -656,7 +651,6 @@ impl App {
|
||||
source_diagram_job: None,
|
||||
diagram_lookup_in_flight: None,
|
||||
pending_diagram_reveal: None,
|
||||
pending_scenario_reveal_visit: None,
|
||||
model_issues,
|
||||
migration: None,
|
||||
source_version: 0,
|
||||
@@ -671,7 +665,6 @@ impl App {
|
||||
workflow: None,
|
||||
};
|
||||
app.route_state_diagram_workspace();
|
||||
app.reconcile_scenario_workspace();
|
||||
app.last_workspace_page = app.page;
|
||||
app
|
||||
}
|
||||
@@ -782,17 +775,6 @@ impl App {
|
||||
self.sync_with_alias_editor(None);
|
||||
}
|
||||
fn sync_with_alias_editor(&mut self, hint: Option<source_rename::EditorRefresh<'_>>) {
|
||||
// A saved view may be retargeted across layers by one source transaction.
|
||||
// Follow that explicit identity before generic active-view normalization.
|
||||
if let Some(rep @ behavior::scenario_layout::Representation::Saved { diagram }) =
|
||||
self.behavior.scenario.representation()
|
||||
&& self.active_diagram == Some(diagram)
|
||||
&& let Some(owner) =
|
||||
behavior::scenario_layout::presentation::checked_owner(self.project(), rep)
|
||||
{
|
||||
self.layer = self.project().elements[&owner].layer();
|
||||
self.behavior.active_owner = Some(owner);
|
||||
}
|
||||
self.explorer_index = crate::explorer::Index::new(self.project(), self.layer);
|
||||
self.model_issues = validate(self.project());
|
||||
self.normalize_creation();
|
||||
@@ -897,26 +879,6 @@ impl App {
|
||||
.map_err(|e| e.to_string())
|
||||
}) {
|
||||
Ok(id) => {
|
||||
if self.behavior.scenario.representation()
|
||||
== Some(behavior::scenario_layout::Representation::Saved { diagram: original })
|
||||
&& id != original
|
||||
{
|
||||
let representation =
|
||||
behavior::scenario_layout::Representation::Saved { diagram: id };
|
||||
if let Some(owner) = behavior::scenario_layout::presentation::checked_owner(
|
||||
self.project(),
|
||||
representation,
|
||||
) {
|
||||
self.behavior.scenario.enter_representation(
|
||||
self.canvas_document,
|
||||
owner,
|
||||
representation,
|
||||
);
|
||||
if self.page != Page::Behavior {
|
||||
self.behavior.scenario.leave();
|
||||
}
|
||||
}
|
||||
}
|
||||
if self.active_diagram == Some(original) {
|
||||
self.active_diagram = Some(id);
|
||||
}
|
||||
@@ -1121,17 +1083,6 @@ impl App {
|
||||
&& let Some(owner) = crate::behavior::selected_behavior(self.project(), id)
|
||||
{
|
||||
self.behavior.active_owner = Some(owner);
|
||||
if self.behavior.scenario.representation().is_some_and(|rep| {
|
||||
behavior::scenario_layout::presentation::checked_owner(self.project(), rep)
|
||||
!= Some(owner)
|
||||
}) && self.project().elements[&owner].kind() == Kind::Scenario
|
||||
{
|
||||
self.enter_scenario_representation(
|
||||
behavior::scenario_layout::Representation::Derived { owner },
|
||||
);
|
||||
} else if self.project().elements[&owner].kind() != Kind::Scenario {
|
||||
self.behavior.scenario.forget_view();
|
||||
}
|
||||
}
|
||||
if self.reset_state_view_after_navigation(previous_state_view)
|
||||
&& self.page == Page::Behavior
|
||||
@@ -1274,9 +1225,6 @@ impl App {
|
||||
])
|
||||
}
|
||||
pub fn update(&mut self, message: Message) -> Task<Message> {
|
||||
if let Message::ScenarioCanvas(behavior::scenario::CanvasEvent::Spacing(event)) = &message {
|
||||
return self.scenario_spacing(*event);
|
||||
}
|
||||
// Reject stale rename intents before camera/reveal reconciliation or
|
||||
// source interaction can disturb a newer navigation destination.
|
||||
if let Message::SourceRename(event) = &message
|
||||
@@ -1284,53 +1232,6 @@ impl App {
|
||||
{
|
||||
return Task::none();
|
||||
}
|
||||
// Prior view visits are inert before they can retire a newer reveal,
|
||||
// camera lifetime or focus operation. Passive events may relax epoch,
|
||||
// but never the destination identity.
|
||||
if let Message::ScenarioCanvas(event) = &message {
|
||||
let captured = event.context();
|
||||
if self.scenario_context().is_none_or(|current| {
|
||||
current.document != captured.document
|
||||
|| current.scenario != captured.scenario
|
||||
|| current.representation != captured.representation
|
||||
|| current.visit != captured.visit
|
||||
|| (!matches!(event, behavior::scenario::CanvasEvent::Restored(..))
|
||||
&& current.revision != captured.revision)
|
||||
}) {
|
||||
return Task::none();
|
||||
}
|
||||
if let behavior::scenario::CanvasEvent::Camera(_, lifetime, _) = event
|
||||
&& *lifetime != self.camera_epoch
|
||||
{
|
||||
return Task::none();
|
||||
}
|
||||
// A retained Details button may belong to an earlier selection or
|
||||
// canvas epoch. Refuse it before retiring any newer reveal or draft.
|
||||
if let behavior::scenario::CanvasEvent::Properties(_, id) = event
|
||||
&& (self.scenario_context() != Some(captured)
|
||||
|| self.selected != *id
|
||||
|| !self.project().contains(*id)
|
||||
|| !behavior::scenario::properties_target(self.project(), captured, *id)
|
||||
|| self.behavior.has_pending()
|
||||
|| self.draft_dirty()
|
||||
|| self.source_dirty()
|
||||
|| self.source_rename.open()
|
||||
|| !behavior::canvas_workspace::keyboard_enabled(self))
|
||||
{
|
||||
return Task::none();
|
||||
}
|
||||
}
|
||||
if let Message::BehaviorControl(intent) = &message
|
||||
&& behavior::canvas_workspace::Scope::current(self).is_none_or(|scope| {
|
||||
scope.document != intent.scope.document
|
||||
|| scope.owner != intent.scope.owner
|
||||
|| scope.scenario_view != intent.scope.scenario_view
|
||||
|| scope.revision != intent.scope.revision
|
||||
|| scope.epoch != intent.scope.epoch
|
||||
})
|
||||
{
|
||||
return Task::none();
|
||||
}
|
||||
let usage_viewport = self.diagram_reveal_viewport(&message);
|
||||
let window_resized = matches!(&message, Message::WindowResized(_));
|
||||
// Reject stale measurements before legacy viewport handlers can change
|
||||
@@ -1351,7 +1252,6 @@ impl App {
|
||||
| Message::TopologyCanvas(crate::behavior::topology::CanvasEvent::Camera(..))
|
||||
);
|
||||
let before = self.camera_boundary();
|
||||
let spacing_selected = self.selected;
|
||||
let task = self.update_inner(message);
|
||||
if window_resized && let Some((_, _, epoch)) = &mut self.pending_diagram_reveal {
|
||||
*epoch = self.canvas_epoch;
|
||||
@@ -1366,13 +1266,6 @@ impl App {
|
||||
{
|
||||
self.diagram_navigation_focus = None;
|
||||
}
|
||||
if (self.camera_boundary() != before
|
||||
|| self.selected != spacing_selected
|
||||
|| !self.spacing_enabled())
|
||||
&& self.behavior.scenario.cancel_spacing()
|
||||
{
|
||||
self.canvas_epoch = self.canvas_epoch.wrapping_add(1);
|
||||
}
|
||||
if !camera && self.camera_boundary() != before {
|
||||
self.camera_epoch = self.camera_epoch.wrapping_add(1);
|
||||
self.camera_boundary_epoch = self.canvas_epoch;
|
||||
@@ -1391,7 +1284,6 @@ impl App {
|
||||
let valid_scenario = |c: behavior::scenario::Context| {
|
||||
c.document == scope.document
|
||||
&& c.scenario == scope.owner
|
||||
&& scope.scenario_view == Some((c.representation, c.visit))
|
||||
&& c.revision == scope.revision
|
||||
&& self.camera_toolbar_epoch(c.epoch)
|
||||
};
|
||||
@@ -1407,9 +1299,6 @@ impl App {
|
||||
Message::ScenarioCanvas(Scenario::Camera(c, lifetime, Camera::Focus))
|
||||
if valid_scenario(*c) && *lifetime == scope.epoch =>
|
||||
{
|
||||
if self.behavior.scenario.cancel_spacing() {
|
||||
self.canvas_epoch = self.canvas_epoch.wrapping_add(1);
|
||||
}
|
||||
return canvas_workspace::focus_task(scope, Camera::Focus);
|
||||
}
|
||||
Message::TopologyCanvas(Process::Camera(c, lifetime, Camera::Focus))
|
||||
@@ -1435,9 +1324,6 @@ impl App {
|
||||
_ => return Task::none(),
|
||||
}
|
||||
let task = self.update(message);
|
||||
if self.behavior.scenario.cancel_spacing() {
|
||||
self.canvas_epoch = self.canvas_epoch.wrapping_add(1);
|
||||
}
|
||||
// Reapplying Fit or a tool also ends a held gesture. Focus is stamped
|
||||
// after the action, for Iced's final-view ordering.
|
||||
if self.camera_epoch == scope.epoch {
|
||||
@@ -1781,7 +1667,6 @@ impl App {
|
||||
self.refresh_source_rename_context();
|
||||
self.reconcile_reference_chooser();
|
||||
self.route_state_diagram_workspace();
|
||||
self.reconcile_scenario_workspace();
|
||||
if self.page != Page::Home {
|
||||
self.last_workspace_page = self.page;
|
||||
}
|
||||
@@ -1790,6 +1675,11 @@ impl App {
|
||||
.topology
|
||||
.enter(context.document, context.owner);
|
||||
}
|
||||
if let Some(context) = self.scenario_context() {
|
||||
self.behavior
|
||||
.scenario
|
||||
.enter(context.document, context.scenario);
|
||||
}
|
||||
if self.connection.as_ref().is_some_and(|session| {
|
||||
Some(session.context) != self.route_context()
|
||||
|| self.page != Page::Diagram
|
||||
@@ -1833,23 +1723,15 @@ impl App {
|
||||
}
|
||||
}
|
||||
pub(crate) fn scenario_context(&self) -> Option<crate::behavior::scenario::Context> {
|
||||
if self.page != Page::Behavior {
|
||||
return None;
|
||||
}
|
||||
let scenario = if matches!(
|
||||
self.behavior.scenario.representation(),
|
||||
Some(behavior::scenario_layout::Representation::Saved { .. })
|
||||
) {
|
||||
self.behavior.scenario.owner()?
|
||||
} else {
|
||||
crate::behavior::selected_owner(self)?
|
||||
};
|
||||
self.behavior.scenario.context(
|
||||
self.canvas_document,
|
||||
scenario,
|
||||
self.document.revision(),
|
||||
self.canvas_epoch,
|
||||
)
|
||||
let scenario = crate::behavior::selected_owner(self)?;
|
||||
(self.page == Page::Behavior
|
||||
&& self.project().elements.get(&scenario)?.kind() == Kind::Scenario)
|
||||
.then_some(crate::behavior::scenario::Context {
|
||||
document: self.canvas_document,
|
||||
scenario,
|
||||
revision: self.document.revision(),
|
||||
epoch: self.canvas_epoch,
|
||||
})
|
||||
}
|
||||
pub(crate) fn scenario_focus_owner(&self) -> Option<crate::behavior::scenario::focus::Stamp> {
|
||||
if self.busy
|
||||
@@ -1877,7 +1759,10 @@ impl App {
|
||||
.active_diagram
|
||||
.is_some_and(|id| self.saved_scenario_diagram(id));
|
||||
match message {
|
||||
Message::Command(Command::Layout(diagram)) => self.saved_scenario_diagram(*diagram),
|
||||
Message::Diagram(choice) => self.saved_scenario_diagram(choice.id),
|
||||
Message::RevealInDiagram(diagram, _) | Message::Command(Command::Layout(diagram)) => {
|
||||
self.saved_scenario_diagram(*diagram)
|
||||
}
|
||||
Message::Projection(projection) => active || projection.scenario().is_some(),
|
||||
Message::SelectNode(_)
|
||||
| Message::PlaceSelected
|
||||
@@ -1926,8 +1811,6 @@ impl App {
|
||||
if self.scenario_context().is_some_and(|current| {
|
||||
current.document == context.document
|
||||
&& current.scenario == context.scenario
|
||||
&& current.representation == context.representation
|
||||
&& current.visit == context.visit
|
||||
&& current.revision == context.revision
|
||||
}) && self.scenario_focus_owner().is_some()
|
||||
&& self.behavior.scenario.take_form_focus(mount)
|
||||
@@ -1940,8 +1823,6 @@ impl App {
|
||||
if self.scenario_context().is_some_and(|current| {
|
||||
current.document == context.document
|
||||
&& current.scenario == context.scenario
|
||||
&& current.representation == context.representation
|
||||
&& current.visit == context.visit
|
||||
&& current.revision == context.revision
|
||||
}) && self.behavior.scenario.viewport(size)
|
||||
{
|
||||
@@ -1951,10 +1832,7 @@ impl App {
|
||||
}
|
||||
if let CanvasEvent::Restored(_, token, area, offset) = event {
|
||||
if self.scenario_context().is_some_and(|current| {
|
||||
current.document == context.document
|
||||
&& current.scenario == context.scenario
|
||||
&& current.representation == context.representation
|
||||
&& current.visit == context.visit
|
||||
current.document == context.document && current.scenario == context.scenario
|
||||
}) && self
|
||||
.behavior
|
||||
.scenario
|
||||
@@ -1971,8 +1849,6 @@ impl App {
|
||||
if self.scenario_context().is_some_and(|current| {
|
||||
current.document == context.document
|
||||
&& current.scenario == context.scenario
|
||||
&& current.representation == context.representation
|
||||
&& current.visit == context.visit
|
||||
&& current.revision == context.revision
|
||||
}) && self.behavior.scenario.scrolled(area, offset)
|
||||
{
|
||||
@@ -1986,8 +1862,6 @@ impl App {
|
||||
|| !self.scenario_context().is_some_and(|c| {
|
||||
c.document == context.document
|
||||
&& c.scenario == context.scenario
|
||||
&& c.representation == context.representation
|
||||
&& c.visit == context.visit
|
||||
&& c.revision == context.revision
|
||||
})
|
||||
{
|
||||
@@ -1996,7 +1870,6 @@ impl App {
|
||||
let scope = canvas_workspace::Scope {
|
||||
document: context.document,
|
||||
owner: context.scenario,
|
||||
scenario_view: Some((context.representation, context.visit)),
|
||||
revision: context.revision,
|
||||
epoch: lifetime,
|
||||
};
|
||||
@@ -2007,9 +1880,6 @@ impl App {
|
||||
{
|
||||
return Task::none();
|
||||
}
|
||||
if self.behavior.scenario.cancel_spacing() {
|
||||
self.canvas_epoch = self.canvas_epoch.wrapping_add(1);
|
||||
}
|
||||
match input {
|
||||
Event::Focus
|
||||
| Event::Traverse(_)
|
||||
@@ -2022,10 +1892,7 @@ impl App {
|
||||
self.canvas_epoch = self.canvas_epoch.wrapping_add(1)
|
||||
}
|
||||
input => {
|
||||
let mut state = std::mem::take(&mut self.behavior.scenario);
|
||||
let changed = state.camera(self.project(), context.scenario, input);
|
||||
self.behavior.scenario = state;
|
||||
if changed {
|
||||
if self.behavior.scenario.camera(input) {
|
||||
self.canvas_epoch = self.canvas_epoch.wrapping_add(1);
|
||||
}
|
||||
}
|
||||
@@ -2036,45 +1903,6 @@ impl App {
|
||||
return Task::none();
|
||||
}
|
||||
match event {
|
||||
CanvasEvent::Representation(_, requested) => {
|
||||
use behavior::scenario_layout::{
|
||||
Representation, presentation::checked_owner,
|
||||
};
|
||||
if checked_owner(self.project(), requested) != Some(context.scenario) {
|
||||
return Task::none();
|
||||
}
|
||||
// An explicitly selected current view record follows
|
||||
// the arrangement picker, as with the Diagram picker.
|
||||
// Independent occurrence/lifeline selection stays put.
|
||||
let follow_view = matches!(context.representation,
|
||||
Representation::Saved { diagram } if self.selected == diagram);
|
||||
if !self.apply() {
|
||||
return Task::none();
|
||||
}
|
||||
let requested = match requested {
|
||||
Representation::Saved { diagram }
|
||||
if context.representation
|
||||
== (Representation::Saved { diagram }) =>
|
||||
{
|
||||
Representation::Saved {
|
||||
diagram: self.active_diagram.unwrap_or(diagram),
|
||||
}
|
||||
}
|
||||
Representation::Derived { owner } => Representation::Derived {
|
||||
owner: self.behavior.active_owner.unwrap_or(owner),
|
||||
},
|
||||
other => other,
|
||||
};
|
||||
if self.enter_scenario_representation(requested) && follow_view {
|
||||
self.selected = match requested {
|
||||
Representation::Saved { diagram } => diagram,
|
||||
// Automatic has no Diagram record; its Scenario
|
||||
// owner is the corresponding inspectable target.
|
||||
Representation::Derived { owner } => owner,
|
||||
};
|
||||
self.refresh_draft();
|
||||
}
|
||||
}
|
||||
CanvasEvent::Focus(_) => {
|
||||
self.behavior.scenario.toggle_focus();
|
||||
self.canvas_epoch = self.canvas_epoch.wrapping_add(1);
|
||||
@@ -2083,13 +1911,6 @@ impl App {
|
||||
self.behavior.scenario.toggle_shelf(shelf);
|
||||
self.canvas_epoch = self.canvas_epoch.wrapping_add(1);
|
||||
}
|
||||
CanvasEvent::Properties(_, _) => {
|
||||
// The checked action opens the current record only: no
|
||||
// select()/Apply side effect or representation change.
|
||||
self.behavior.scenario.show_properties();
|
||||
self.inspector_tab = crate::navigation::InspectorTab::Properties;
|
||||
self.canvas_epoch = self.canvas_epoch.wrapping_add(1);
|
||||
}
|
||||
CanvasEvent::Zoom(_, scale) => {
|
||||
let mut state = std::mem::take(&mut self.behavior.scenario);
|
||||
if state.camera_zoom(self.project(), context.scenario, scale) {
|
||||
@@ -2110,11 +1931,7 @@ impl App {
|
||||
Ok(target) => {
|
||||
// A command can preselect this target while the
|
||||
// caller remains visible, bypassing select below.
|
||||
self.enter_scenario_representation(
|
||||
behavior::scenario_layout::Representation::Derived {
|
||||
owner: target,
|
||||
},
|
||||
);
|
||||
self.behavior.active_owner = Some(target);
|
||||
self.select(target);
|
||||
self.canvas_epoch = self.canvas_epoch.wrapping_add(1);
|
||||
}
|
||||
@@ -2136,7 +1953,7 @@ impl App {
|
||||
// A command may already have selected this UUID while
|
||||
// leaving the referenced definition open. select's
|
||||
// same-UUID fast path must not keep that old owner.
|
||||
self.enter_scenario_representation(caller.representation);
|
||||
self.behavior.active_owner = Some(caller.owner);
|
||||
self.select(caller.occurrence);
|
||||
self.canvas_epoch = self.canvas_epoch.wrapping_add(1);
|
||||
if let Some(context) = self.scenario_context() {
|
||||
@@ -2164,15 +1981,6 @@ impl App {
|
||||
}
|
||||
}
|
||||
CanvasEvent::Choose(_, tool) => {
|
||||
if tool != scenario::CanvasTool::Select
|
||||
&& !self
|
||||
.behavior
|
||||
.scenario
|
||||
.coordinate_input(self.project(), context)
|
||||
{
|
||||
self.status = "Canvas insertion and reordering are unavailable for this presentation.".into();
|
||||
return Task::none();
|
||||
}
|
||||
if self.behavior.has_pending() || self.draft_dirty() || self.source_dirty()
|
||||
{
|
||||
self.status =
|
||||
@@ -2184,17 +1992,6 @@ impl App {
|
||||
self.canvas_epoch = self.canvas_epoch.wrapping_add(1);
|
||||
}
|
||||
mutation => {
|
||||
if !behavior::scenario_layout::presentation::present(
|
||||
self.project(),
|
||||
context.representation,
|
||||
self.selected,
|
||||
)
|
||||
.capabilities()
|
||||
.coordinate_input
|
||||
{
|
||||
self.status = "Layout editing is unavailable for this presentation. Saved positions are preserved.".into();
|
||||
return Task::none();
|
||||
}
|
||||
if self.behavior.has_pending() || self.draft_dirty() || self.source_dirty()
|
||||
{
|
||||
self.status =
|
||||
@@ -2295,13 +2092,6 @@ impl App {
|
||||
})
|
||||
{
|
||||
self.behavior.active_owner = Some(choice.id);
|
||||
if self.project().elements[&choice.id].kind() == Kind::Scenario {
|
||||
self.enter_scenario_representation(
|
||||
behavior::scenario_layout::Representation::Derived { owner: choice.id },
|
||||
);
|
||||
} else {
|
||||
self.behavior.scenario.forget_view();
|
||||
}
|
||||
self.behavior.diagram = Default::default();
|
||||
self.canvas_epoch = self.canvas_epoch.wrapping_add(1);
|
||||
self.select(choice.id);
|
||||
@@ -2667,15 +2457,6 @@ impl App {
|
||||
crate::behavior::selected_behavior(self.project(), self.selected)
|
||||
{
|
||||
self.behavior.active_owner = Some(owner);
|
||||
if self.project().elements[&owner].kind() == Kind::Scenario
|
||||
&& self.behavior.scenario.owner() != Some(owner)
|
||||
{
|
||||
self.enter_scenario_representation(
|
||||
behavior::scenario_layout::Representation::Derived { owner },
|
||||
);
|
||||
} else if self.project().elements[&owner].kind() != Kind::Scenario {
|
||||
self.behavior.scenario.forget_view();
|
||||
}
|
||||
}
|
||||
self.behavior.active_owner = crate::behavior::selected_owner(self);
|
||||
self.reset_state_view_after_navigation(previous_state_view);
|
||||
@@ -2912,7 +2693,6 @@ impl App {
|
||||
}
|
||||
Message::Layer(layer) => {
|
||||
if self.apply() {
|
||||
self.behavior.scenario.forget_view();
|
||||
let previous_state_view = self.state_view_identity();
|
||||
self.layer = layer;
|
||||
self.create_kind = if layer == Layer::Oa {
|
||||
@@ -3085,9 +2865,6 @@ impl App {
|
||||
}
|
||||
}
|
||||
Message::RevealInDiagram(diagram, selected) => {
|
||||
if self.saved_scenario_diagram(diagram) {
|
||||
return self.reveal_saved_scenario(diagram, selected);
|
||||
}
|
||||
let original = self.selected;
|
||||
if !self.apply() {
|
||||
return Task::none();
|
||||
@@ -3319,16 +3096,6 @@ impl App {
|
||||
self.status = "Diagram no longer exists.".into();
|
||||
return Task::none();
|
||||
}
|
||||
if self.saved_scenario_diagram(choice.id)
|
||||
&& behavior::scenario_layout::presentation::checked_owner(
|
||||
self.project(),
|
||||
behavior::scenario_layout::Representation::Saved { diagram: choice.id },
|
||||
)
|
||||
.is_none()
|
||||
{
|
||||
self.status = "This Scenario view has an incompatible or missing owner.".into();
|
||||
return Task::none();
|
||||
}
|
||||
let previous_diagram = self.active_diagram;
|
||||
let follow_view = previous_diagram == Some(self.selected);
|
||||
if self.apply() {
|
||||
@@ -3348,14 +3115,7 @@ impl App {
|
||||
}
|
||||
self.selected_node = None;
|
||||
self.refresh_draft();
|
||||
if self.saved_scenario_diagram(diagram) {
|
||||
self.enter_scenario_representation(
|
||||
behavior::scenario_layout::Representation::Saved { diagram },
|
||||
);
|
||||
} else {
|
||||
self.page = Page::Diagram;
|
||||
self.fit();
|
||||
}
|
||||
self.fit();
|
||||
}
|
||||
}
|
||||
Message::Projection(projection) => {
|
||||
@@ -5988,17 +5748,12 @@ mod saved_scenario_dispatch_tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn saved_picker_with_invalid_properties_and_reveal_with_pending_properties_do_not_apply() {
|
||||
fn unsupported_saved_picker_and_reveal_do_not_apply_pending_properties() {
|
||||
for reveal in [false, true] {
|
||||
let (mut app, architecture, saved, owner) = fixture();
|
||||
let _ = app.update(Message::Field(
|
||||
if reveal { "/name" } else { "/id" }.into(),
|
||||
if reveal {
|
||||
"Unapplied scenario name"
|
||||
} else {
|
||||
"-"
|
||||
}
|
||||
.into(),
|
||||
"/name".into(),
|
||||
"Unapplied scenario name".into(),
|
||||
));
|
||||
assert!(app.draft_dirty());
|
||||
let before = app.document.bundle().clone();
|
||||
@@ -6018,6 +5773,7 @@ mod saved_scenario_dispatch_tests {
|
||||
assert_eq!(app.active_diagram, Some(architecture));
|
||||
assert_eq!(app.selected, selected);
|
||||
assert!(app.draft_dirty());
|
||||
assert_eq!(app.status, SAVED_SCENARIO_UNAVAILABLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
//! Complete a navigation camera after the destination reports its real viewport.
|
||||
use super::*;
|
||||
use crate::behavior::scenario_layout::Representation;
|
||||
use crate::diagram_usage::{Context, Surface};
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
@@ -48,23 +47,11 @@ impl App {
|
||||
&& c.epoch == *epoch,
|
||||
),
|
||||
Message::ScenarioCanvas(behavior::scenario::CanvasEvent::Viewport(c, size)) => (
|
||||
match c.representation {
|
||||
Representation::Derived { owner } => Surface::Scenario(owner),
|
||||
Representation::Saved { diagram } => Surface::Saved(diagram),
|
||||
},
|
||||
Surface::Scenario(c.scenario),
|
||||
*size,
|
||||
c.document == context.document
|
||||
&& c.revision == context.revision
|
||||
&& c.epoch == *epoch
|
||||
&& self.pending_scenario_reveal_visit == Some(c.visit)
|
||||
&& self.page == Page::Behavior
|
||||
&& self.behavior.active_owner == Some(c.scenario)
|
||||
&& self.behavior.scenario.context(
|
||||
self.canvas_document,
|
||||
c.scenario,
|
||||
self.document.revision(),
|
||||
self.canvas_epoch,
|
||||
) == Some(*c),
|
||||
&& c.epoch == *epoch,
|
||||
),
|
||||
Message::StateDiagram(behavior::state_edit::Event::Viewport(c, size)) => (
|
||||
Surface::Saved(c.diagram),
|
||||
@@ -104,7 +91,6 @@ impl App {
|
||||
| Message::StateDiagram(behavior::state_edit::Event::Viewport(..))
|
||||
) {
|
||||
self.pending_diagram_reveal = None;
|
||||
self.pending_scenario_reveal_visit = None;
|
||||
if !Self::is_navigation_camera(message) {
|
||||
self.diagram_navigation_focus = None;
|
||||
}
|
||||
@@ -156,6 +142,5 @@ impl App {
|
||||
self.reveal_diagram_usage(&usage);
|
||||
}
|
||||
self.pending_diagram_reveal = None;
|
||||
self.pending_scenario_reveal_visit = None;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +144,6 @@ fn measurement(
|
||||
epoch: u64,
|
||||
surface: Surface,
|
||||
size: Size,
|
||||
visit: Id,
|
||||
) -> Message {
|
||||
match canvas {
|
||||
Canvas::Architecture => Message::DiagramRevealViewport(context, epoch, size),
|
||||
@@ -161,10 +160,6 @@ fn measurement(
|
||||
behavior::scenario::Context {
|
||||
document: context.document,
|
||||
scenario: surface.id(),
|
||||
representation: Representation::Derived {
|
||||
owner: surface.id(),
|
||||
},
|
||||
visit,
|
||||
revision: context.revision,
|
||||
epoch,
|
||||
},
|
||||
@@ -182,16 +177,12 @@ fn measurement(
|
||||
}
|
||||
}
|
||||
|
||||
fn stamp(app: &App) -> (Context, u64, Id) {
|
||||
fn stamp(app: &App) -> (Context, u64) {
|
||||
let (context, _, epoch) = app
|
||||
.pending_diagram_reveal
|
||||
.as_ref()
|
||||
.expect("reveal awaits measured destination");
|
||||
(
|
||||
*context,
|
||||
*epoch,
|
||||
app.pending_scenario_reveal_visit.unwrap_or(Id::nil()),
|
||||
)
|
||||
(*context, *epoch)
|
||||
}
|
||||
|
||||
fn assert_centered(app: &App, canvas: Canvas, target: &Usage) {
|
||||
@@ -229,11 +220,7 @@ fn assert_centered(app: &App, canvas: Canvas, target: &Usage) {
|
||||
expected.choose_tool(target.surface.id(), behavior::scenario::CanvasTool::Select);
|
||||
expected.viewport(ACTUAL);
|
||||
expected.zoom(Some(zoom));
|
||||
expected.camera(
|
||||
app.project(),
|
||||
target.surface.id(),
|
||||
behavior::canvas_workspace::Event::Pan(pan),
|
||||
);
|
||||
expected.camera(behavior::canvas_workspace::Event::Pan(pan));
|
||||
assert!(app.behavior.scenario.camera_boundary() == expected.camera_boundary());
|
||||
}
|
||||
}
|
||||
@@ -252,10 +239,10 @@ fn all_reveal_surfaces_recenter_once_after_the_real_viewport_and_preserve_author
|
||||
app.document.dirty(),
|
||||
);
|
||||
assert!(app.reveal_diagram_usage(&target));
|
||||
let (context, epoch, visit) = stamp(&app);
|
||||
let (context, epoch) = stamp(&app);
|
||||
send(
|
||||
&mut app,
|
||||
measurement(canvas, context, epoch, target.surface, ACTUAL, visit),
|
||||
measurement(canvas, context, epoch, target.surface, ACTUAL),
|
||||
);
|
||||
assert!(app.pending_diagram_reveal.is_none());
|
||||
assert_centered(&app, canvas, &target);
|
||||
@@ -274,7 +261,7 @@ fn all_reveal_surfaces_recenter_once_after_the_real_viewport_and_preserve_author
|
||||
let camera = app.camera_boundary();
|
||||
send(
|
||||
&mut app,
|
||||
measurement(canvas, context, epoch, target.surface, ACTUAL, visit),
|
||||
measurement(canvas, context, epoch, target.surface, ACTUAL),
|
||||
);
|
||||
assert!(app.pending_diagram_reveal.is_none());
|
||||
assert!(app.camera_boundary() == camera);
|
||||
@@ -288,7 +275,7 @@ fn malformed_or_wrong_stamp_measurements_cannot_poison_a_pending_reveal() {
|
||||
for invalid in 0..6 {
|
||||
let (mut app, target) = fixture(canvas);
|
||||
assert!(app.reveal_diagram_usage(&target));
|
||||
let (context, epoch, visit) = stamp(&app);
|
||||
let (context, epoch) = stamp(&app);
|
||||
let camera = app.camera_boundary();
|
||||
let mut stale = context;
|
||||
let mut wrong_epoch = epoch;
|
||||
@@ -303,13 +290,13 @@ fn malformed_or_wrong_stamp_measurements_cannot_poison_a_pending_reveal() {
|
||||
}
|
||||
send(
|
||||
&mut app,
|
||||
measurement(canvas, stale, wrong_epoch, target.surface, size, visit),
|
||||
measurement(canvas, stale, wrong_epoch, target.surface, size),
|
||||
);
|
||||
assert!(
|
||||
app.pending_diagram_reveal.is_some(),
|
||||
"{canvas:?} invalid case {invalid}"
|
||||
);
|
||||
assert_eq!(stamp(&app), (context, epoch, visit));
|
||||
assert_eq!(stamp(&app), (context, epoch));
|
||||
assert_eq!(app.canvas_epoch, epoch);
|
||||
assert!(
|
||||
app.camera_boundary() == camera,
|
||||
@@ -317,7 +304,7 @@ fn malformed_or_wrong_stamp_measurements_cannot_poison_a_pending_reveal() {
|
||||
);
|
||||
send(
|
||||
&mut app,
|
||||
measurement(canvas, context, epoch, target.surface, ACTUAL, visit),
|
||||
measurement(canvas, context, epoch, target.surface, ACTUAL),
|
||||
);
|
||||
assert!(app.pending_diagram_reveal.is_none());
|
||||
assert_centered(&app, canvas, &target);
|
||||
@@ -331,10 +318,9 @@ fn actual_window_resize_before_first_measurement_retains_focus_for_the_new_conte
|
||||
let (mut app, target) = fixture(canvas);
|
||||
let accepted = app.document.snapshot();
|
||||
assert!(app.reveal_diagram_usage(&target));
|
||||
let (context, old_epoch, visit) = stamp(&app);
|
||||
let (context, old_epoch) = stamp(&app);
|
||||
send(&mut app, Message::WindowResized(Size::new(1100., 700.)));
|
||||
let (current, epoch, current_visit) = stamp(&app);
|
||||
assert_eq!(current_visit, visit);
|
||||
let (current, epoch) = stamp(&app);
|
||||
assert_eq!(current, context);
|
||||
assert_eq!(epoch, app.canvas_epoch);
|
||||
if matches!(canvas, Canvas::Process | Canvas::Scenario) {
|
||||
@@ -342,14 +328,14 @@ fn actual_window_resize_before_first_measurement_retains_focus_for_the_new_conte
|
||||
let camera = app.camera_boundary();
|
||||
send(
|
||||
&mut app,
|
||||
measurement(canvas, context, old_epoch, target.surface, ACTUAL, visit),
|
||||
measurement(canvas, context, old_epoch, target.surface, ACTUAL),
|
||||
);
|
||||
assert_eq!(stamp(&app), (current, epoch, visit));
|
||||
assert_eq!(stamp(&app), (current, epoch));
|
||||
assert!(app.camera_boundary() == camera);
|
||||
}
|
||||
send(
|
||||
&mut app,
|
||||
measurement(canvas, current, epoch, target.surface, ACTUAL, visit),
|
||||
measurement(canvas, current, epoch, target.surface, ACTUAL),
|
||||
);
|
||||
assert!(app.pending_diagram_reveal.is_none());
|
||||
assert_centered(&app, canvas, &target);
|
||||
@@ -364,7 +350,7 @@ fn user_camera_edit_and_navigation_cancel_deferred_focus_without_late_snapping()
|
||||
let (mut app, target) = fixture(canvas);
|
||||
let accepted = app.document.snapshot();
|
||||
assert!(app.reveal_diagram_usage(&target));
|
||||
let (context, epoch, visit) = stamp(&app);
|
||||
let (context, epoch) = stamp(&app);
|
||||
let event = match action {
|
||||
0 => match canvas {
|
||||
Canvas::Architecture => Message::Pan(Vector::new(31., -17.)),
|
||||
@@ -401,7 +387,7 @@ fn user_camera_edit_and_navigation_cancel_deferred_focus_without_late_snapping()
|
||||
// restore the old navigation camera after deliberate user input.
|
||||
send(
|
||||
&mut app,
|
||||
measurement(canvas, context, epoch, target.surface, WIDE, visit),
|
||||
measurement(canvas, context, epoch, target.surface, WIDE),
|
||||
);
|
||||
assert!(app.pending_diagram_reveal.is_none());
|
||||
assert!(
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
//! Navigation-only adapter: validates destinations before changing presentation.
|
||||
use super::*;
|
||||
use crate::behavior::scenario_layout::{Representation, presentation};
|
||||
use crate::diagram_usage::{self as usage, Context, Event, Panel, Surface, Target, Usage};
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
@@ -59,6 +58,10 @@ impl App {
|
||||
let process = presentation.into_query_state();
|
||||
let scenario = behavior::scenario::State::default();
|
||||
usage::collect(&project, context.subject, &process, &scenario)
|
||||
.into_iter()
|
||||
.filter(|row| !matches!(row.surface, Surface::Saved(id)
|
||||
if project.diagrams.get(&id).is_some_and(|d| d.projection.scenario().is_some())))
|
||||
.collect()
|
||||
})
|
||||
.await
|
||||
.map_err(|error| format!("Diagram lookup failed: {error}. Close and try again."));
|
||||
@@ -165,7 +168,6 @@ impl App {
|
||||
// Only an accepted new chooser supersedes the previous reveal.
|
||||
// Rejected/stale panel envelopes leave its first measurement intact.
|
||||
self.pending_diagram_reveal = None;
|
||||
self.pending_scenario_reveal_visit = None;
|
||||
self.diagram_navigation_focus = None;
|
||||
self.canvas_epoch = self.canvas_epoch.wrapping_add(1);
|
||||
return Task::batch([
|
||||
@@ -288,78 +290,14 @@ impl App {
|
||||
Task::none()
|
||||
}
|
||||
|
||||
/// Explicit saved-Scenario reveal runs before generic Apply. An absent target
|
||||
/// never selects the owner or another saved arrangement as a fallback.
|
||||
pub(super) fn reveal_saved_scenario(&mut self, diagram: Id, selected: Id) -> Task<Message> {
|
||||
if self.diagram_usages.is_some() || !self.usage_navigation_available() {
|
||||
self.status = "Apply or revert pending edits before revealing a saved Scenario. Your inputs are retained.".into();
|
||||
return Task::none();
|
||||
}
|
||||
if presentation::checked_owner(self.project(), Representation::Saved { diagram }).is_none()
|
||||
{
|
||||
return Task::none();
|
||||
}
|
||||
let Some(found) = self
|
||||
.current_surface_usages(selected, Surface::Saved(diagram))
|
||||
.into_iter()
|
||||
.find(|row| matches!(row.target, Target::Whole | Target::ScenarioObject(_)))
|
||||
else {
|
||||
self.status = "This object has no visible target in that saved Scenario.".into();
|
||||
return Task::none();
|
||||
};
|
||||
self.reveal_diagram_usage(&found);
|
||||
Task::none()
|
||||
}
|
||||
|
||||
pub(super) fn reveal_diagram_usage(&mut self, usage: &Usage) -> bool {
|
||||
if !self.usage_navigation_available() {
|
||||
return false;
|
||||
}
|
||||
let previous_layer = self.layer;
|
||||
let scenario_representation = match usage.surface {
|
||||
Surface::Saved(diagram) if self.saved_scenario_diagram(diagram) => {
|
||||
Some(Representation::Saved { diagram })
|
||||
}
|
||||
Surface::Scenario(owner) => Some(Representation::Derived { owner }),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(representation) = scenario_representation {
|
||||
let Some(owner) = presentation::checked_owner(self.project(), representation) else {
|
||||
return false;
|
||||
};
|
||||
if !self
|
||||
.behavior
|
||||
.scenario
|
||||
.representation_usages(self.project(), representation, usage.subject)
|
||||
.iter()
|
||||
.any(|row| row == usage)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// Finish target/camera admission before changing the App route. The
|
||||
// checked immutable owner also makes the following entry infallible.
|
||||
let revealed = match representation {
|
||||
Representation::Derived { .. } => self.behavior.scenario.reveal_usage(
|
||||
self.document.project(),
|
||||
self.canvas_document,
|
||||
owner,
|
||||
&usage.target,
|
||||
),
|
||||
Representation::Saved { .. } => self.behavior.scenario.reveal_representation_usage(
|
||||
self.document.project(),
|
||||
self.canvas_document,
|
||||
owner,
|
||||
representation,
|
||||
&usage.target,
|
||||
),
|
||||
};
|
||||
if !revealed {
|
||||
return false;
|
||||
}
|
||||
if !self.enter_scenario_representation(representation) {
|
||||
return false;
|
||||
}
|
||||
if matches!(usage.surface, Surface::Saved(id) if self.saved_scenario_diagram(id)) {
|
||||
return false;
|
||||
}
|
||||
let previous_layer = self.layer;
|
||||
let p = self.document.project();
|
||||
let (selected, placement) = match &usage.target {
|
||||
Target::Whole => (usage.surface.id(), None),
|
||||
@@ -399,10 +337,7 @@ impl App {
|
||||
};
|
||||
self.layer = diagram.layer;
|
||||
self.active_diagram = Some(id);
|
||||
if let Some(owner) = diagram.projection.scenario() {
|
||||
self.behavior.active_owner = Some(owner);
|
||||
self.page = Page::Behavior;
|
||||
} else if let Some(machine) = diagram.projection.state_machine() {
|
||||
if let Some(machine) = diagram.projection.state_machine() {
|
||||
let viewport = self.behavior.diagram.viewport.unwrap_or(iced::Size::new(
|
||||
(self.window_size.width - 610.).max(280.),
|
||||
(self.window_size.height - 320.).max(240.),
|
||||
@@ -444,14 +379,19 @@ impl App {
|
||||
self.page = Page::Behavior;
|
||||
}
|
||||
Surface::Scenario(owner) => {
|
||||
if !self.behavior.scenario.reveal_usage(
|
||||
p,
|
||||
self.canvas_document,
|
||||
owner,
|
||||
&usage.target,
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
self.layer = p.elements[&owner].layer();
|
||||
self.behavior.active_owner = Some(owner);
|
||||
self.page = Page::Behavior;
|
||||
}
|
||||
}
|
||||
if scenario_representation.is_none() {
|
||||
self.behavior.scenario.forget_view();
|
||||
}
|
||||
self.selected = selected;
|
||||
self.selected_node = placement;
|
||||
self.model_menu = None;
|
||||
@@ -478,18 +418,6 @@ impl App {
|
||||
usage: usage.clone(),
|
||||
selected,
|
||||
});
|
||||
self.pending_scenario_reveal_visit = scenario_representation.and_then(|representation| {
|
||||
let owner = presentation::checked_owner(self.project(), representation)?;
|
||||
self.behavior
|
||||
.scenario
|
||||
.context(
|
||||
self.canvas_document,
|
||||
owner,
|
||||
self.document.revision(),
|
||||
self.canvas_epoch,
|
||||
)
|
||||
.map(|context| context.visit)
|
||||
});
|
||||
self.pending_diagram_reveal = Some((
|
||||
Context {
|
||||
document: self.canvas_document,
|
||||
@@ -509,21 +437,12 @@ impl App {
|
||||
let current_surface = match surface {
|
||||
Surface::Saved(id) => {
|
||||
self.active_diagram == Some(id)
|
||||
&& !self.saved_scenario_diagram(id)
|
||||
&& matches!(self.page, Page::Diagram | Page::Behavior)
|
||||
&& (!self.saved_scenario_diagram(id)
|
||||
|| (self.page == Page::Behavior
|
||||
&& self.behavior.scenario.representation()
|
||||
== Some(Representation::Saved { diagram: id })))
|
||||
}
|
||||
Surface::Process(owner) => {
|
||||
Surface::Process(owner) | Surface::Scenario(owner) => {
|
||||
self.page == Page::Behavior && self.behavior.active_owner == Some(owner)
|
||||
}
|
||||
Surface::Scenario(owner) => {
|
||||
self.page == Page::Behavior
|
||||
&& self.behavior.active_owner == Some(owner)
|
||||
&& self.behavior.scenario.representation()
|
||||
== Some(Representation::Derived { owner })
|
||||
}
|
||||
};
|
||||
(current_surface
|
||||
&& focus.usage.surface == surface
|
||||
|
||||
@@ -1029,9 +1029,10 @@ fn repeated_preview_arrows_select_the_relation_and_highlight_the_exact_caller_li
|
||||
let camera = app.behavior.topology.camera_boundary();
|
||||
if call == calls[1]
|
||||
&& let Some((previous_call, previous)) = &previous_camera
|
||||
&& *previous_call != call
|
||||
{
|
||||
assert!(&camera != previous);
|
||||
if *previous_call != call {
|
||||
assert!(&camera != previous);
|
||||
}
|
||||
}
|
||||
if let Some(epoch) = previous_epoch {
|
||||
assert_ne!(app.canvas_epoch, epoch);
|
||||
@@ -1374,7 +1375,7 @@ fn whole_surface_camera_fits_huge_extent_while_target_camera_remains_readable()
|
||||
};
|
||||
let viewport = iced::Size::new(800., 500.);
|
||||
let (zoom, pan) = usage::camera_for(&Target::Whole, bounds, viewport);
|
||||
assert!((0.0001..0.05).contains(&zoom));
|
||||
assert!(zoom < 0.05 && zoom >= 0.0001);
|
||||
assert!(bounds.width * zoom <= viewport.width - 64. + 0.01);
|
||||
assert!(bounds.height * zoom <= viewport.height - 64. + 0.01);
|
||||
assert!((bounds.center_x() * zoom + pan.x - viewport.width / 2.).abs() < 0.01);
|
||||
@@ -1400,5 +1401,3 @@ fn completion_releases_worker_behind_busy_modal_without_navigation() {
|
||||
assert_eq!(location(&app), prior);
|
||||
assert_eq!(authored(&app), before);
|
||||
}
|
||||
|
||||
mod saved_scenario;
|
||||
|
||||
@@ -1,108 +0,0 @@
|
||||
arcadia 7;
|
||||
project incident_workspace "Incident report review" id "70200000-0000-4000-8000-000000000001" {
|
||||
// Two operational activities, with one lifeline appearance per Scenario.
|
||||
oa_activity report_incident "Report incident" id "70200000-0000-4000-8000-000000000002" {}
|
||||
oa_activity assess_incident "Assess incident" id "70200000-0000-4000-8000-000000000003" {}
|
||||
interaction incident_report "Incident report" id "70200000-0000-4000-8000-000000000004" {
|
||||
source @report_incident;
|
||||
target @assess_incident;
|
||||
}
|
||||
|
||||
oa_scenario incident_response "Review a reported incident" id "70200000-0000-4000-8000-000000000010" {
|
||||
viewpoint OperationalActivity;
|
||||
steps [@initial_report, @updated_report, @assess_call, @assess_reply, @unfinished_notice, @use_review];
|
||||
}
|
||||
oa_lifeline reporter "Reporting activity" id "70200000-0000-4000-8000-000000000011" {
|
||||
parent @incident_response; represented @report_incident;
|
||||
}
|
||||
oa_lifeline assessor "Assessment activity" id "70200000-0000-4000-8000-000000000012" {
|
||||
parent @incident_response; represented @assess_incident;
|
||||
}
|
||||
// Both appearances reuse one definition. Navigation must retain the occurrence.
|
||||
oa_occurrence initial_report "Initial incident report" id "70200000-0000-4000-8000-000000000020" {
|
||||
parent @incident_response;
|
||||
body { Exchange { exchange @incident_report; sender @reporter; receiver @assessor; message_kind Asynchronous; }; };
|
||||
}
|
||||
oa_occurrence updated_report "Updated incident report" id "70200000-0000-4000-8000-000000000021" {
|
||||
parent @incident_response;
|
||||
body { Exchange { exchange @incident_report; sender @reporter; receiver @assessor; message_kind Asynchronous; }; };
|
||||
}
|
||||
// A correlated self call/reply with deliberately unassigned exchange definitions.
|
||||
oa_occurrence assess_call "Assess report details" id "70200000-0000-4000-8000-000000000022" {
|
||||
parent @incident_response;
|
||||
body { Exchange { exchange none; sender @assessor; receiver @assessor; message_kind Call; }; };
|
||||
}
|
||||
oa_occurrence assess_reply "Assessment ready" id "70200000-0000-4000-8000-000000000023" {
|
||||
parent @incident_response;
|
||||
body { Exchange { exchange none; sender @assessor; receiver @assessor; message_kind Reply; reply_to @assess_call; }; };
|
||||
}
|
||||
// Intentional unfinished work: no receiver and therefore no fabricated arrow.
|
||||
oa_occurrence unfinished_notice "Follow-up recipient undecided" id "70200000-0000-4000-8000-000000000024" {
|
||||
parent @incident_response;
|
||||
body { Exchange { exchange @incident_report; sender @reporter; receiver none; message_kind Asynchronous; }; };
|
||||
}
|
||||
oa_occurrence use_review "Use the reviewed reporting procedure" id "70200000-0000-4000-8000-000000000025" {
|
||||
parent @incident_response;
|
||||
body { ScenarioUse {
|
||||
bindings [{ local @reporter; referenced @review_reporter; }, { local @assessor; referenced @review_assessor; }];
|
||||
scenario @reporting_review;
|
||||
}; };
|
||||
}
|
||||
|
||||
// This definition stays opaque in the caller. Open it, then Back to the saved view.
|
||||
oa_scenario reporting_review "Reporting procedure detail" id "70200000-0000-4000-8000-000000000030" {
|
||||
viewpoint OperationalActivity;
|
||||
steps [@review_delivery];
|
||||
}
|
||||
oa_lifeline review_reporter "Reporting activity in detail" id "70200000-0000-4000-8000-000000000031" {
|
||||
parent @reporting_review; represented @report_incident;
|
||||
}
|
||||
oa_lifeline review_assessor "Assessment activity in detail" id "70200000-0000-4000-8000-000000000032" {
|
||||
parent @reporting_review; represented @assess_incident;
|
||||
}
|
||||
oa_occurrence review_delivery "Check the incident report" id "70200000-0000-4000-8000-000000000033" {
|
||||
parent @reporting_review;
|
||||
body { Exchange { exchange @incident_report; sender @review_reporter; receiver @review_assessor; message_kind Asynchronous; }; };
|
||||
}
|
||||
|
||||
diagram incident_readable "A - Incident review readable" id "70200000-0000-4000-8000-000000000040" {
|
||||
layer Oa;
|
||||
projection { Scenario { scenario @incident_response; }; };
|
||||
layout { Scenario {
|
||||
lanes [{ lifeline @reporter; x 160; }, { lifeline @assessor; x 640; }];
|
||||
messages [
|
||||
{ address { references []; occurrence @initial_report; }; send_y 160; },
|
||||
{ address { references []; occurrence @updated_report; }; send_y 252; },
|
||||
{ address { references []; occurrence @assess_call; }; send_y 344; },
|
||||
{ address { references []; occurrence @assess_reply; }; send_y 436; }
|
||||
];
|
||||
}; };
|
||||
}
|
||||
diagram incident_wide "B - Incident review negative and far" id "70200000-0000-4000-8000-000000000041" {
|
||||
layer Oa;
|
||||
projection { Scenario { scenario @incident_response; }; };
|
||||
layout { Scenario {
|
||||
lanes [{ lifeline @reporter; x -500; }, { lifeline @assessor; x 50000; }];
|
||||
messages [
|
||||
{ address { references []; occurrence @initial_report; }; send_y 160; },
|
||||
{ address { references []; occurrence @updated_report; }; send_y 252; },
|
||||
{ address { references []; occurrence @assess_call; }; send_y 344; },
|
||||
{ address { references []; occurrence @assess_reply; }; send_y 436; }
|
||||
];
|
||||
}; };
|
||||
}
|
||||
diagram incident_repair "C - Incident review needs layout repair" id "70200000-0000-4000-8000-000000000042" {
|
||||
layer Oa;
|
||||
projection { Scenario { scenario @incident_response; }; };
|
||||
layout { Scenario {
|
||||
// These valid authored lanes must remain saved during complete fallback.
|
||||
lanes [{ lifeline @reporter; x 900; }, { lifeline @assessor; x -500; }];
|
||||
messages [
|
||||
// REPAIR: change only this 300 to 424, then Undo and Redo the edit.
|
||||
{ address { references []; occurrence @assess_reply; }; send_y 300; },
|
||||
// This authored value stays latent while the receiver is missing.
|
||||
{ address { references []; occurrence @unfinished_notice; }; send_y 2000; }
|
||||
];
|
||||
}; };
|
||||
}
|
||||
}
|
||||
@@ -1,356 +0,0 @@
|
||||
//! Actual App chooser/explicit-reveal checks for saved Scenario identity and source history.
|
||||
use super::*;
|
||||
use crate::behavior::scenario::{CanvasEvent, State};
|
||||
use crate::behavior::scenario_layout::{
|
||||
Representation,
|
||||
presentation::{self, PresentationStatus},
|
||||
};
|
||||
use iced::{Size, Vector};
|
||||
|
||||
fn fixture() -> App {
|
||||
let p = language::parse(include_str!("saved_scenario.arcadia")).unwrap();
|
||||
let errors: Vec<_> = oa_core::validation::validate(&p)
|
||||
.into_iter()
|
||||
.filter(|d| d.severity == oa_core::validation::Severity::Error)
|
||||
.collect();
|
||||
assert!(errors.is_empty(), "{errors:?}");
|
||||
App::with_project(p)
|
||||
}
|
||||
fn id(app: &App, alias: &str) -> Id {
|
||||
app.project()
|
||||
.identities()
|
||||
.into_iter()
|
||||
.find(|(_, a)| *a == alias)
|
||||
.unwrap()
|
||||
.0
|
||||
}
|
||||
fn representation(view: Id) -> Representation {
|
||||
Representation::Saved { diagram: view }
|
||||
}
|
||||
fn find(app: &App, subject: Id, view: Id) -> Usage {
|
||||
usage::saved_usages_for(app.project(), subject, Some(view))
|
||||
.into_iter()
|
||||
.find(|row| row.target == Target::ScenarioObject(subject))
|
||||
.expect("exact saved occurrence")
|
||||
}
|
||||
fn context(app: &App) -> behavior::scenario::Context {
|
||||
let owner = app.behavior.active_owner.unwrap();
|
||||
app.behavior
|
||||
.scenario
|
||||
.context(
|
||||
app.canvas_document,
|
||||
owner,
|
||||
app.document.revision(),
|
||||
app.canvas_epoch,
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
fn navigate(app: &mut App, subject: Id, view: Id) -> Id {
|
||||
let (token, rows) = open(app, subject);
|
||||
let found = rows
|
||||
.into_iter()
|
||||
.find(|u| u.surface == Surface::Saved(view) && u.target == Target::ScenarioObject(subject))
|
||||
.expect("saved chooser destination");
|
||||
choose(app, token, found);
|
||||
assert!(app.diagram_usages.is_none());
|
||||
assert_eq!(app.page, Page::Behavior);
|
||||
assert_eq!(app.active_diagram, Some(view));
|
||||
assert_eq!(
|
||||
app.behavior.scenario.representation(),
|
||||
Some(representation(view))
|
||||
);
|
||||
assert_eq!(app.selected, subject);
|
||||
token
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn saved_queries_use_each_actual_presentation_and_keep_repeated_appearances_and_references_opaque()
|
||||
{
|
||||
let app = fixture();
|
||||
let owner = id(&app, "incident_response");
|
||||
let first = id(&app, "initial_report");
|
||||
let second = id(&app, "updated_report");
|
||||
let exchange = id(&app, "incident_report");
|
||||
let latent = id(&app, "unfinished_notice");
|
||||
let callee_message = id(&app, "review_delivery");
|
||||
let views = ["incident_readable", "incident_wide", "incident_repair"].map(|a| id(&app, a));
|
||||
let derived = app
|
||||
.behavior
|
||||
.scenario
|
||||
.diagram_usages(app.project(), owner, first)
|
||||
.pop()
|
||||
.unwrap();
|
||||
let rows = views.map(|view| find(&app, first, view));
|
||||
assert_eq!(rows[0].bounds.y - derived.bounds.y, 12.);
|
||||
assert_ne!(rows[0].bounds, rows[1].bounds);
|
||||
assert_eq!(
|
||||
rows[2].bounds, derived.bounds,
|
||||
"complete fallback cannot retain the authored lane override"
|
||||
);
|
||||
for view in views {
|
||||
let represented = usage::saved_usages_for(app.project(), exchange, Some(view));
|
||||
assert_eq!(represented.len(), 2);
|
||||
assert!(
|
||||
represented
|
||||
.iter()
|
||||
.any(|u| u.target == Target::ScenarioObject(first))
|
||||
);
|
||||
assert!(
|
||||
represented
|
||||
.iter()
|
||||
.any(|u| u.target == Target::ScenarioObject(second))
|
||||
);
|
||||
assert!(
|
||||
represented
|
||||
.iter()
|
||||
.all(|u| u.surface == Surface::Saved(view))
|
||||
);
|
||||
assert!(usage::saved_usages_for(app.project(), callee_message, Some(view)).is_empty());
|
||||
assert_eq!(
|
||||
find(&app, latent, view).target,
|
||||
Target::ScenarioObject(latent)
|
||||
);
|
||||
let shown = presentation::present(app.project(), representation(view), owner);
|
||||
let whole = usage::saved_usages_for(app.project(), view, Some(view));
|
||||
assert_eq!(whole.len(), 1);
|
||||
assert_eq!(whole[0].target, Target::Whole);
|
||||
assert_eq!(Some(whole[0].bounds), shown.bounds());
|
||||
}
|
||||
let wide = presentation::present(app.project(), representation(views[1]), owner)
|
||||
.bounds()
|
||||
.unwrap();
|
||||
assert!(wide.x < -500. && wide.x + wide.width > 50000.);
|
||||
let fallback = presentation::present(app.project(), representation(views[2]), owner);
|
||||
assert!(matches!(
|
||||
fallback.status(),
|
||||
PresentationStatus::Fallback { .. }
|
||||
));
|
||||
assert_eq!(fallback.latent_messages(), &[latent]);
|
||||
assert!(!fallback.capabilities().coordinate_input);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn saved_chooser_and_explicit_reveal_preserve_complete_source_and_actual_undo_redo() {
|
||||
for alias in ["incident_readable", "incident_wide", "incident_repair"] {
|
||||
let mut app = fixture();
|
||||
let view = id(&app, alias);
|
||||
let first = id(&app, "initial_report");
|
||||
let owner = id(&app, "incident_response");
|
||||
let original = app.document.snapshot();
|
||||
app.document
|
||||
.execute(Command::Rename(first, "Reviewed incident report".into()))
|
||||
.unwrap();
|
||||
let edited = app.document.snapshot();
|
||||
app.sync_source();
|
||||
app.refresh_draft();
|
||||
let before = authored(&app);
|
||||
navigate(&mut app, first, view);
|
||||
assert_eq!(app.behavior.active_owner, Some(owner));
|
||||
assert_eq!(authored(&app), before);
|
||||
send(&mut app, Message::RevealInDiagram(view, first));
|
||||
assert_eq!(app.active_diagram, Some(view));
|
||||
assert_eq!(authored(&app), before);
|
||||
assert!(app.document.undo());
|
||||
assert_eq!(app.project(), &original.decoded.project);
|
||||
assert_eq!(app.document.bundle(), &original.bundle);
|
||||
assert!(app.document.redo());
|
||||
assert_eq!(app.project(), &edited.decoded.project);
|
||||
assert_eq!(app.document.bundle(), &edited.bundle);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn saved_reveal_and_chooser_refuse_source_property_and_behavior_drafts() {
|
||||
for chooser in [false, true] {
|
||||
for block in 0..3 {
|
||||
let mut app = fixture();
|
||||
let view = id(&app, "incident_repair");
|
||||
let first = id(&app, "initial_report");
|
||||
let choice = chooser.then(|| {
|
||||
let (token, rows) = open(&mut app, first);
|
||||
(
|
||||
token,
|
||||
rows.into_iter()
|
||||
.find(|u| u.surface == Surface::Saved(view))
|
||||
.unwrap(),
|
||||
)
|
||||
});
|
||||
match block {
|
||||
0 => {
|
||||
let cursor = app.source_editor.cursor();
|
||||
app.source_workspace
|
||||
.edit("? preserve unfinished source".into(), cursor);
|
||||
}
|
||||
1 => {
|
||||
app.draft
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.input("/name", "Unapplied inspector value".into());
|
||||
assert!(app.draft_dirty());
|
||||
}
|
||||
_ => {
|
||||
let p = app.project().clone();
|
||||
app.behavior
|
||||
.creation
|
||||
.update(&p, behavior::creation::Event::Open(Layer::Oa))
|
||||
.unwrap();
|
||||
assert!(app.behavior.has_pending());
|
||||
}
|
||||
}
|
||||
let before = authored(&app);
|
||||
let prior = location(&app);
|
||||
let draft = app
|
||||
.draft
|
||||
.as_ref()
|
||||
.map(|d| serde_json::to_value(d.recovery_snapshot()).unwrap());
|
||||
if let Some((token, row)) = choice {
|
||||
choose(&mut app, token, row);
|
||||
} else {
|
||||
send(&mut app, Message::RevealInDiagram(view, first));
|
||||
}
|
||||
assert_eq!(authored(&app), before);
|
||||
assert_eq!(location(&app), prior);
|
||||
assert_eq!(
|
||||
app.draft
|
||||
.as_ref()
|
||||
.map(|d| serde_json::to_value(d.recovery_snapshot()).unwrap()),
|
||||
draft
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn saved_a_b_a_rejects_old_visit_and_panel_callbacks_before_deferred_measurement() {
|
||||
let mut app = fixture();
|
||||
let a = id(&app, "incident_readable");
|
||||
let b = id(&app, "incident_wide");
|
||||
let first = id(&app, "initial_report");
|
||||
let before = authored(&app);
|
||||
let old_token = navigate(&mut app, first, a);
|
||||
let old = context(&app);
|
||||
navigate(&mut app, first, b);
|
||||
navigate(&mut app, first, a);
|
||||
let current = context(&app);
|
||||
assert_ne!(old.visit, current.visit);
|
||||
let held = behavior::scenario::Context {
|
||||
epoch: current.epoch,
|
||||
..old
|
||||
};
|
||||
let camera = app.behavior.scenario.camera_boundary();
|
||||
send(
|
||||
&mut app,
|
||||
Message::ScenarioCanvas(CanvasEvent::Viewport(held, Size::new(900., 900.))),
|
||||
);
|
||||
send(&mut app, Message::ScenarioCanvas(CanvasEvent::Focus(held)));
|
||||
send(
|
||||
&mut app,
|
||||
Message::DiagramUsage(Event::Search(old_token, "obsolete filter".into())),
|
||||
);
|
||||
send(&mut app, Message::DiagramUsage(Event::Close(old_token)));
|
||||
assert_eq!(app.pending_scenario_reveal_visit, Some(current.visit));
|
||||
assert!(app.pending_diagram_reveal.is_some());
|
||||
assert!(app.behavior.scenario.camera_boundary() == camera);
|
||||
let bounds = find(&app, first, a).bounds;
|
||||
send(
|
||||
&mut app,
|
||||
Message::ScenarioCanvas(CanvasEvent::Viewport(current, Size::new(500., 300.))),
|
||||
);
|
||||
assert!(app.pending_diagram_reveal.is_none());
|
||||
assert_eq!(context(&app).visit, current.visit);
|
||||
let mut expected = State::default();
|
||||
expected.enter_representation(app.canvas_document, current.scenario, representation(a));
|
||||
expected.viewport(Size::new(500., 300.));
|
||||
expected.zoom(Some(1.25));
|
||||
expected.camera(
|
||||
app.project(),
|
||||
current.scenario,
|
||||
behavior::canvas_workspace::Event::Pan(Vector::new(
|
||||
250. - bounds.center_x() * 1.25,
|
||||
150. - bounds.center_y() * 1.25,
|
||||
)),
|
||||
);
|
||||
assert!(app.behavior.scenario.camera_boundary() == expected.camera_boundary());
|
||||
assert_eq!(authored(&app), before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn retargeted_saved_view_cannot_reveal_a_former_owner_occurrence() {
|
||||
let mut app = fixture();
|
||||
let first = id(&app, "initial_report");
|
||||
let view = id(&app, "incident_readable");
|
||||
let other = id(&app, "reporting_review");
|
||||
let (token, rows) = open(&mut app, first);
|
||||
let old = rows
|
||||
.into_iter()
|
||||
.find(|u| u.surface == Surface::Saved(view))
|
||||
.unwrap();
|
||||
let mut replacement = app.project().diagrams[&view].clone();
|
||||
replacement.projection = ProjectionKind::Scenario { scenario: other };
|
||||
replacement.layout = None;
|
||||
app.document
|
||||
.execute(Command::EditDiagram(view, replacement))
|
||||
.unwrap();
|
||||
app.sync_source();
|
||||
app.refresh_draft();
|
||||
let before = authored(&app);
|
||||
let prior = location(&app);
|
||||
choose(&mut app, token, old);
|
||||
assert_eq!(location(&app), prior);
|
||||
assert_eq!(authored(&app), before);
|
||||
finish_lookup(&mut app);
|
||||
let token = app.diagram_usages.as_ref().unwrap().token;
|
||||
assert!(
|
||||
app.diagram_usages
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.usages
|
||||
.iter()
|
||||
.all(|u| u.surface != Surface::Saved(view))
|
||||
);
|
||||
send(&mut app, Message::DiagramUsage(Event::Close(token)));
|
||||
send(&mut app, Message::RevealInDiagram(view, first));
|
||||
assert_eq!(location(&app), prior);
|
||||
assert_eq!(authored(&app), before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicit_saved_layout_repair_undo_redo_requeries_authored_and_fallback_geometry_without_extra_history()
|
||||
{
|
||||
let mut app = fixture();
|
||||
let view = id(&app, "incident_repair");
|
||||
let first = id(&app, "initial_report");
|
||||
let reply = id(&app, "assess_reply");
|
||||
let before = app.document.snapshot();
|
||||
let fallback = find(&app, first, view);
|
||||
app.document
|
||||
.execute(Command::SetScenarioMessagePosition {
|
||||
diagram: view,
|
||||
position: oa_core::ScenarioMessagePosition {
|
||||
address: oa_core::OccurrenceEndpoint {
|
||||
references: vec![],
|
||||
occurrence: reply,
|
||||
},
|
||||
send_y: 424.,
|
||||
},
|
||||
})
|
||||
.unwrap();
|
||||
app.sync_source();
|
||||
app.refresh_draft();
|
||||
let repaired = app.document.snapshot();
|
||||
let authored_row = find(&app, first, view);
|
||||
assert_ne!(authored_row.bounds, fallback.bounds);
|
||||
navigate(&mut app, first, view);
|
||||
assert!(app.document.undo());
|
||||
app.sync_source();
|
||||
app.refresh_draft();
|
||||
assert_eq!(app.project(), &before.decoded.project);
|
||||
assert_eq!(app.document.bundle(), &before.bundle);
|
||||
assert_eq!(find(&app, first, view).bounds, fallback.bounds);
|
||||
assert!(app.document.redo());
|
||||
app.sync_source();
|
||||
app.refresh_draft();
|
||||
assert_eq!(app.project(), &repaired.decoded.project);
|
||||
assert_eq!(app.document.bundle(), &repaired.bundle);
|
||||
assert_eq!(find(&app, first, view).bounds, authored_row.bounds);
|
||||
}
|
||||
@@ -65,7 +65,6 @@ impl App {
|
||||
owner: context.owner,
|
||||
revision: context.revision,
|
||||
epoch: lifetime,
|
||||
scenario_view: None,
|
||||
};
|
||||
if self.behavior.has_pending()
|
||||
|| self.draft_dirty()
|
||||
|
||||
@@ -1,281 +0,0 @@
|
||||
//! Actual arrangement selection and current-record Details admission.
|
||||
use super::*;
|
||||
use crate::behavior::canvas_workspace::tests::Mounted;
|
||||
use crate::behavior::scenario::{CanvasEvent, Context, Shelf};
|
||||
use crate::behavior::scenario_layout::Representation;
|
||||
use iced::{Point, Size, advanced::widget};
|
||||
|
||||
const FIXTURE: &str = include_str!("diagram_usages/tests/saved_scenario.arcadia");
|
||||
|
||||
fn id(app: &App, alias: &str) -> Id {
|
||||
app.project()
|
||||
.identities()
|
||||
.into_iter()
|
||||
.find(|(_, name)| *name == alias)
|
||||
.unwrap()
|
||||
.0
|
||||
}
|
||||
fn setup() -> (App, Id, Id, Id) {
|
||||
let mut app = App::with_project(oa_core::language::parse(FIXTURE).unwrap());
|
||||
let a = id(&app, "incident_readable");
|
||||
let b = id(&app, "incident_wide");
|
||||
let owner = id(&app, "incident_response");
|
||||
let _ = app.update(Message::Select(owner));
|
||||
let _ = app.update(Message::Page(Page::Behavior));
|
||||
choose(&mut app, Representation::Saved { diagram: a });
|
||||
let _ = app.update(Message::Select(a));
|
||||
app.window_size = Size::new(1440., 1000.);
|
||||
(app, a, b, owner)
|
||||
}
|
||||
fn send(app: &mut App, event: impl FnOnce(Context) -> CanvasEvent) {
|
||||
let context = app.scenario_context().unwrap();
|
||||
let _ = app.update(Message::ScenarioCanvas(event(context)));
|
||||
}
|
||||
fn choose(app: &mut App, representation: Representation) {
|
||||
send(app, |context| {
|
||||
CanvasEvent::Representation(context, representation)
|
||||
});
|
||||
}
|
||||
fn model_state(app: &App) -> (u64, bool, bool, bool) {
|
||||
(
|
||||
app.document.revision(),
|
||||
app.document.dirty(),
|
||||
app.document.can_undo(),
|
||||
app.document.can_redo(),
|
||||
)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn actual_arrangement_picker_follows_selected_saved_record_and_opens_b_properties() {
|
||||
let (mut app, a, b, _) = setup();
|
||||
let mut mounted = Mounted::new(&mut app).await;
|
||||
let snapshot = app.document.snapshot();
|
||||
let before = model_state(&app);
|
||||
let captured = app.scenario_context().unwrap();
|
||||
let picker = mounted.geometry(&app).bounds("scenario-arrangement-picker");
|
||||
assert!(
|
||||
app.window_size.height - (picker.y + picker.height) > picker.y,
|
||||
"fixture has room for Iced's menu below the actual picker"
|
||||
);
|
||||
assert_eq!(app.selected, a);
|
||||
mounted.click(&mut app, picker.center()).await;
|
||||
// iced_widget 0.14.2 overlay/menu.rs uses default line height plus
|
||||
// vertical padding for each row. The real workspace orders Automatic,
|
||||
// then the fixture's A/B/C Diagram IDs. Select B from the actual overlay.
|
||||
let row_height =
|
||||
f32::from(iced::advanced::text::LineHeight::default().to_absolute(12.into())) + 10.;
|
||||
let b_row = Point::new(
|
||||
picker.center_x(),
|
||||
picker.y + picker.height + row_height * 2.5,
|
||||
);
|
||||
assert!(b_row.y < app.window_size.height);
|
||||
let events = mounted.click(&mut app, b_row).await;
|
||||
assert!(events.iter().any(|event| matches!(event,
|
||||
Message::ScenarioCanvas(CanvasEvent::Representation(context, Representation::Saved { diagram }))
|
||||
if *context == captured && *diagram == b)), "must exercise the actual arrangement callback");
|
||||
assert_eq!(app.selected, b);
|
||||
assert_eq!(app.draft.as_ref().unwrap().original, b);
|
||||
assert_eq!(
|
||||
app.draft.as_ref().unwrap().value["name"],
|
||||
"B - Incident review negative and far"
|
||||
);
|
||||
assert_eq!(app.active_diagram, Some(b));
|
||||
assert_eq!(
|
||||
app.scenario_context().unwrap().representation,
|
||||
Representation::Saved { diagram: b }
|
||||
);
|
||||
assert_ne!(app.scenario_context().unwrap().visit, captured.visit);
|
||||
|
||||
send(&mut app, CanvasEvent::Focus);
|
||||
send(&mut app, |context| {
|
||||
CanvasEvent::Shelf(context, Shelf::Selection)
|
||||
});
|
||||
mounted.settle(&mut app).await;
|
||||
let geometry = mounted.geometry(&app);
|
||||
let (details, offset) = geometry.scrolls[&widget::Id::new("scenario-details")];
|
||||
let point = geometry.bounds("scenario-properties").center() - offset;
|
||||
assert!(details.contains(point));
|
||||
let events = mounted.click(&mut app, point).await;
|
||||
assert!(events.iter().any(|event| matches!(event,
|
||||
Message::ScenarioCanvas(CanvasEvent::Properties(_, selected)) if *selected == b)));
|
||||
mounted.settle(&mut app).await;
|
||||
let geometry = mounted.geometry(&app);
|
||||
let (inspector, offset) = geometry.scrolls[&widget::Id::new("inspector")];
|
||||
assert!(
|
||||
geometry
|
||||
.text_inputs
|
||||
.iter()
|
||||
.any(|bounds| inspector.contains(bounds.center() - offset)),
|
||||
"current B Properties must expose an actual editable field"
|
||||
);
|
||||
assert!(!app.behavior.scenario.focused());
|
||||
assert!(
|
||||
!geometry
|
||||
.scrolls
|
||||
.contains_key(&widget::Id::new("scenario-details"))
|
||||
);
|
||||
assert_eq!(
|
||||
app.inspector_tab,
|
||||
crate::navigation::InspectorTab::Properties
|
||||
);
|
||||
assert_eq!(app.selected, b);
|
||||
assert_eq!(app.draft.as_ref().unwrap().original, b);
|
||||
assert!(Arc::ptr_eq(&snapshot, &app.document.snapshot()));
|
||||
assert_eq!(app.project(), &snapshot.decoded.project);
|
||||
assert_eq!(app.document.bundle(), &snapshot.bundle);
|
||||
assert_eq!(model_state(&app), before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arrangement_change_preserves_independent_semantic_and_foreign_view_selection() {
|
||||
for alias in [
|
||||
"initial_report",
|
||||
"reporter",
|
||||
"incident_response",
|
||||
"incident_repair",
|
||||
] {
|
||||
let (mut app, _, b, _) = setup();
|
||||
let selected = id(&app, alias);
|
||||
let _ = app.update(Message::Select(selected));
|
||||
let snapshot = app.document.snapshot();
|
||||
let before = model_state(&app);
|
||||
choose(&mut app, Representation::Saved { diagram: b });
|
||||
assert_eq!(app.selected, selected, "independent selection {alias}");
|
||||
assert_eq!(app.draft.as_ref().unwrap().original, selected);
|
||||
assert_eq!(app.active_diagram, Some(b));
|
||||
assert!(Arc::ptr_eq(&snapshot, &app.document.snapshot()));
|
||||
assert_eq!(app.document.bundle(), &snapshot.bundle);
|
||||
assert_eq!(model_state(&app), before);
|
||||
if alias == "incident_repair" {
|
||||
assert!(!behavior::scenario::properties_target(
|
||||
app.project(),
|
||||
app.scenario_context().unwrap(),
|
||||
selected
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arrangement_follows_view_record_to_automatic_owner_but_not_owner_back_to_saved() {
|
||||
let (mut app, _, b, owner) = setup();
|
||||
let snapshot = app.document.snapshot();
|
||||
let before = model_state(&app);
|
||||
choose(&mut app, Representation::Derived { owner });
|
||||
assert_eq!(app.selected, owner);
|
||||
assert_eq!(app.draft.as_ref().unwrap().original, owner);
|
||||
assert_eq!(app.active_diagram, None);
|
||||
assert!(behavior::scenario::properties_target(
|
||||
app.project(),
|
||||
app.scenario_context().unwrap(),
|
||||
owner
|
||||
));
|
||||
choose(&mut app, Representation::Saved { diagram: b });
|
||||
assert_eq!(
|
||||
app.selected, owner,
|
||||
"Scenario owner is now independent semantic selection"
|
||||
);
|
||||
assert_eq!(app.draft.as_ref().unwrap().original, owner);
|
||||
assert_eq!(app.active_diagram, Some(b));
|
||||
assert!(Arc::ptr_eq(&snapshot, &app.document.snapshot()));
|
||||
assert_eq!(app.document.bundle(), &snapshot.bundle);
|
||||
assert_eq!(model_state(&app), before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arrangement_applies_only_the_old_view_draft_then_follows_b_with_one_undo() {
|
||||
let (mut app, a, b, _) = setup();
|
||||
let snapshot = app.document.snapshot();
|
||||
let mut expected = app.project().clone();
|
||||
expected.diagrams.get_mut(&a).unwrap().name = "Reviewed A".into();
|
||||
let revision = app.document.revision();
|
||||
let _ = app.update(Message::Field("/name".into(), "Reviewed A".into()));
|
||||
choose(&mut app, Representation::Saved { diagram: b });
|
||||
assert_eq!(app.project(), &expected);
|
||||
assert_eq!(app.selected, b);
|
||||
assert_eq!(app.draft.as_ref().unwrap().original, b);
|
||||
assert!(!app.draft_dirty());
|
||||
assert_eq!(app.document.revision(), revision + 1);
|
||||
let accepted = app.document.snapshot();
|
||||
let _ = app.update(Message::Undo);
|
||||
assert_eq!(app.project(), &snapshot.decoded.project);
|
||||
assert_eq!(app.document.bundle(), &snapshot.bundle);
|
||||
assert!(!app.document.can_undo() && app.document.can_redo());
|
||||
let _ = app.update(Message::Redo);
|
||||
assert_eq!(app.project(), &expected);
|
||||
assert_eq!(app.document.bundle(), &accepted.bundle);
|
||||
assert!(app.document.can_undo() && !app.document.can_redo());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn same_arrangement_uuid_edit_follows_the_reidentified_record_and_round_trips_source() {
|
||||
let (mut app, a, _, _) = setup();
|
||||
let snapshot = app.document.snapshot();
|
||||
let replacement = Id::parse_str("70200000-0000-4000-8000-000000000099").unwrap();
|
||||
let mut expected = app.project().clone();
|
||||
let mut diagram = expected.diagrams.remove(&a).unwrap();
|
||||
diagram.id = replacement;
|
||||
expected.diagrams.insert(replacement, diagram);
|
||||
let _ = app.update(Message::Field("/id".into(), replacement.to_string()));
|
||||
choose(&mut app, Representation::Saved { diagram: a });
|
||||
assert_eq!(app.project(), &expected);
|
||||
assert_eq!(app.selected, replacement);
|
||||
assert_eq!(app.draft.as_ref().unwrap().original, replacement);
|
||||
assert_eq!(app.active_diagram, Some(replacement));
|
||||
assert_eq!(
|
||||
app.scenario_context().unwrap().representation,
|
||||
Representation::Saved {
|
||||
diagram: replacement
|
||||
}
|
||||
);
|
||||
let accepted = app.document.snapshot();
|
||||
let _ = app.update(Message::Undo);
|
||||
assert_eq!(app.project(), &snapshot.decoded.project);
|
||||
assert_eq!(app.document.bundle(), &snapshot.bundle);
|
||||
assert!(!app.document.can_undo() && app.document.can_redo());
|
||||
let _ = app.update(Message::Redo);
|
||||
assert_eq!(app.project(), &expected);
|
||||
assert_eq!(app.document.bundle(), &accepted.bundle);
|
||||
assert!(!app.document.can_redo());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_draft_and_stale_arrangement_preserve_selection_inputs_and_accepted_state() {
|
||||
let (mut app, a, b, _) = setup();
|
||||
let old = app.scenario_context().unwrap();
|
||||
let snapshot = app.document.snapshot();
|
||||
let before = model_state(&app);
|
||||
let _ = app.update(Message::Field("/id".into(), "not-a-uuid".into()));
|
||||
let draft_value = app.draft.as_ref().unwrap().value.clone();
|
||||
choose(&mut app, Representation::Saved { diagram: b });
|
||||
assert_eq!(app.selected, a);
|
||||
assert_eq!(app.active_diagram, Some(a));
|
||||
assert_eq!(
|
||||
app.scenario_context().unwrap().representation,
|
||||
old.representation
|
||||
);
|
||||
assert_eq!(app.draft.as_ref().unwrap().value, draft_value);
|
||||
assert_eq!(app.draft.as_ref().unwrap().inputs["/id"].raw, "not-a-uuid");
|
||||
assert!(app.draft_dirty());
|
||||
assert!(Arc::ptr_eq(&snapshot, &app.document.snapshot()));
|
||||
assert_eq!(model_state(&app), before);
|
||||
let _ = app.update(Message::RevertProperties);
|
||||
choose(&mut app, Representation::Saved { diagram: b });
|
||||
let current = app.scenario_context().unwrap();
|
||||
let _ = app.update(Message::Field("/name".into(), "Retained B input".into()));
|
||||
let selected = app.selected;
|
||||
let _ = app.update(Message::ScenarioCanvas(CanvasEvent::Representation(
|
||||
old,
|
||||
Representation::Saved { diagram: a },
|
||||
)));
|
||||
assert_eq!(app.selected, selected);
|
||||
assert_eq!(app.active_diagram, Some(b));
|
||||
assert_eq!(app.scenario_context().unwrap().visit, current.visit);
|
||||
assert_eq!(
|
||||
app.draft.as_ref().unwrap().inputs["/name"].raw,
|
||||
"Retained B input"
|
||||
);
|
||||
assert!(Arc::ptr_eq(&snapshot, &app.document.snapshot()));
|
||||
assert_eq!(app.document.bundle(), &snapshot.bundle);
|
||||
assert_eq!(model_state(&app), before);
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
//! Saved Scenario navigation is presentation state, never a document edit.
|
||||
use super::*;
|
||||
use crate::behavior::scenario_layout::{Representation, presentation::checked_owner};
|
||||
|
||||
impl App {
|
||||
pub(super) fn enter_scenario_representation(&mut self, representation: Representation) -> bool {
|
||||
let Some(owner) = checked_owner(self.project(), representation) else {
|
||||
self.status =
|
||||
"This Scenario view is no longer available or has an incompatible owner.".into();
|
||||
return false;
|
||||
};
|
||||
self.layer = self.project().elements[&owner].layer();
|
||||
self.page = Page::Behavior;
|
||||
self.behavior.active_owner = Some(owner);
|
||||
match representation {
|
||||
Representation::Saved { diagram } => self.active_diagram = Some(diagram),
|
||||
Representation::Derived { .. } => {
|
||||
if self
|
||||
.active_diagram
|
||||
.is_some_and(|id| self.saved_scenario_diagram(id))
|
||||
{
|
||||
self.active_diagram = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
self.selected_node = None;
|
||||
if self
|
||||
.behavior
|
||||
.scenario
|
||||
.enter_representation(self.canvas_document, owner, representation)
|
||||
{
|
||||
self.canvas_epoch = self.canvas_epoch.wrapping_add(1);
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
/// Reconcile after navigation/adoption without selecting or applying a draft.
|
||||
/// A retained invalid Saved identity remains unavailable; it must not silently
|
||||
/// turn into a different automatic Scenario or another saved arrangement.
|
||||
pub(super) fn reconcile_scenario_workspace(&mut self) {
|
||||
if self.page == Page::Diagram
|
||||
&& !self.behavior.has_pending()
|
||||
&& let Some(diagram) = self
|
||||
.active_diagram
|
||||
.filter(|id| self.saved_scenario_diagram(*id))
|
||||
{
|
||||
self.enter_scenario_representation(Representation::Saved { diagram });
|
||||
}
|
||||
if self.page != Page::Behavior {
|
||||
self.behavior.scenario.leave();
|
||||
return;
|
||||
}
|
||||
if let Some(rep @ Representation::Saved { diagram }) =
|
||||
self.behavior.scenario.representation()
|
||||
{
|
||||
// The requested view is authoritative until explicit navigation
|
||||
// retires it. This also recovers the same view when Undo restores it.
|
||||
if let Some(owner) = checked_owner(self.project(), rep) {
|
||||
self.active_diagram = Some(diagram);
|
||||
self.layer = self.project().elements[&owner].layer();
|
||||
self.behavior.active_owner = Some(owner);
|
||||
self.behavior
|
||||
.scenario
|
||||
.enter_representation(self.canvas_document, owner, rep);
|
||||
} else if let Some(owner) = self.behavior.scenario.owner() {
|
||||
self.behavior
|
||||
.scenario
|
||||
.enter_representation(self.canvas_document, owner, rep);
|
||||
}
|
||||
return;
|
||||
}
|
||||
let Some(owner) = behavior::selected_owner(self) else {
|
||||
self.behavior.scenario.leave();
|
||||
return;
|
||||
};
|
||||
if self
|
||||
.project()
|
||||
.elements
|
||||
.get(&owner)
|
||||
.is_some_and(|e| e.kind() == Kind::Scenario)
|
||||
{
|
||||
self.behavior.scenario.enter(self.canvas_document, owner);
|
||||
} else {
|
||||
self.behavior.scenario.leave();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod adoption_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod owner_navigation_tests;
|
||||
@@ -1,264 +0,0 @@
|
||||
//! Independent adoption oracles: expected Projects are edited directly in the
|
||||
//! fixture, then admitted through the actual source editor/Document transaction.
|
||||
//! Navigation is checked separately from the expected authored mutation.
|
||||
use super::*;
|
||||
use crate::behavior::canvas_workspace::tests::Mounted;
|
||||
use iced::advanced::widget;
|
||||
use iced::widget::text_editor;
|
||||
use oa_core::language;
|
||||
use std::sync::Arc;
|
||||
|
||||
struct Fixture {
|
||||
app: App,
|
||||
owner: Id,
|
||||
same_layer: Id,
|
||||
other_layer: Id,
|
||||
view: Id,
|
||||
spare_view: Id,
|
||||
}
|
||||
|
||||
fn fixture() -> Fixture {
|
||||
let mut project = Project::empty();
|
||||
let owner = project
|
||||
.add_element(Kind::Scenario, Layer::Oa, "Original owner", None)
|
||||
.unwrap();
|
||||
let same_layer = project
|
||||
.add_element(Kind::Scenario, Layer::Oa, "Other OA owner", None)
|
||||
.unwrap();
|
||||
let other_layer = project
|
||||
.add_element(Kind::Scenario, Layer::Sa, "SA owner", None)
|
||||
.unwrap();
|
||||
// A remaining topology makes silent fallback observably different from the
|
||||
// required unavailable Saved view after its owner is deleted.
|
||||
project
|
||||
.add_element(Kind::Process, Layer::Oa, "Remaining process", None)
|
||||
.unwrap();
|
||||
let mut make_view = |alias: &str, name: &str, owner| {
|
||||
let id = Id::new_v4();
|
||||
project.diagrams.insert(
|
||||
id,
|
||||
Diagram {
|
||||
id,
|
||||
alias: alias.into(),
|
||||
name: name.into(),
|
||||
description: String::new(),
|
||||
layer: Layer::Oa,
|
||||
projection: ProjectionKind::Scenario { scenario: owner },
|
||||
layout: None,
|
||||
nodes: Default::default(),
|
||||
routes: vec![],
|
||||
view_options: Default::default(),
|
||||
},
|
||||
);
|
||||
id
|
||||
};
|
||||
let view = make_view("retained_view", "Retained arrangement", owner);
|
||||
let spare_view = make_view("spare_view", "Spare arrangement", same_layer);
|
||||
let mut app = App::with_project(project);
|
||||
let _ = app.update(Message::Select(owner));
|
||||
choose(&mut app, view);
|
||||
assert_saved(&app, view, owner, Layer::Oa);
|
||||
assert!(!app.document.can_undo());
|
||||
Fixture {
|
||||
app,
|
||||
owner,
|
||||
same_layer,
|
||||
other_layer,
|
||||
view,
|
||||
spare_view,
|
||||
}
|
||||
}
|
||||
|
||||
fn choose(app: &mut App, id: Id) {
|
||||
let _ = app.update(Message::Diagram(Choice {
|
||||
id,
|
||||
label: "Previously captured picker item".into(),
|
||||
}));
|
||||
}
|
||||
|
||||
fn assert_saved(app: &App, view: Id, owner: Id, layer: Layer) {
|
||||
assert_eq!(app.page, Page::Behavior);
|
||||
assert_eq!(app.layer, layer);
|
||||
assert_eq!(app.active_diagram, Some(view));
|
||||
let context = app
|
||||
.scenario_context()
|
||||
.expect("saved owner remains the visible context");
|
||||
assert_eq!(context.scenario, owner);
|
||||
assert_eq!(
|
||||
context.representation,
|
||||
Representation::Saved { diagram: view }
|
||||
);
|
||||
assert!(!context.visit.is_nil());
|
||||
}
|
||||
|
||||
fn adopt_from_source(app: &mut App, expected: &Project) {
|
||||
let text = language::format(expected);
|
||||
// Parser equality is a fixture precondition, not the navigation oracle.
|
||||
assert_eq!(language::parse(&text).unwrap(), *expected);
|
||||
let _ = app.update(Message::Page(Page::Text));
|
||||
let _ = app.update(Message::SourceEdit(text_editor::Action::SelectAll));
|
||||
let _ = app.update(Message::SourceEdit(text_editor::Action::Edit(
|
||||
text_editor::Edit::Paste(Arc::new(text)),
|
||||
)));
|
||||
assert!(app.source_dirty());
|
||||
let _ = app.update(Message::ApplySource);
|
||||
assert!(!app.source_dirty(), "{}", app.status);
|
||||
assert_eq!(
|
||||
app.project(),
|
||||
expected,
|
||||
"actual source transaction must adopt exactly the fixture change"
|
||||
);
|
||||
let _ = app.update(Message::Page(Page::Behavior));
|
||||
}
|
||||
|
||||
fn retarget(cross_layer: bool) {
|
||||
let mut f = fixture();
|
||||
let before = f.app.document.snapshot();
|
||||
let old_context = f.app.scenario_context().unwrap();
|
||||
let revision = f.app.document.revision();
|
||||
let target = if cross_layer {
|
||||
f.other_layer
|
||||
} else {
|
||||
f.same_layer
|
||||
};
|
||||
let layer = if cross_layer { Layer::Sa } else { Layer::Oa };
|
||||
let mut expected = before.decoded.project.clone();
|
||||
let view = expected.diagrams.get_mut(&f.view).unwrap();
|
||||
view.projection = ProjectionKind::Scenario { scenario: target };
|
||||
view.layer = layer;
|
||||
|
||||
adopt_from_source(&mut f.app, &expected);
|
||||
assert_saved(&f.app, f.view, target, layer);
|
||||
assert_ne!(f.app.scenario_context().unwrap().visit, old_context.visit);
|
||||
assert_eq!(
|
||||
f.app.document.revision(),
|
||||
revision + 1,
|
||||
"routing must not create a second transaction"
|
||||
);
|
||||
assert_eq!(
|
||||
f.app.project().diagrams[&f.spare_view],
|
||||
before.decoded.project.diagrams[&f.spare_view]
|
||||
);
|
||||
let adopted_bundle = f.app.document.bundle().clone();
|
||||
|
||||
let _ = f.app.update(Message::Undo);
|
||||
assert_saved(&f.app, f.view, f.owner, Layer::Oa);
|
||||
assert_eq!(f.app.project(), &before.decoded.project);
|
||||
assert_eq!(f.app.document.bundle(), &before.bundle);
|
||||
assert!(
|
||||
!f.app.document.can_undo(),
|
||||
"exactly one authored adoption must be undone"
|
||||
);
|
||||
let _ = f.app.update(Message::Redo);
|
||||
assert_saved(&f.app, f.view, target, layer);
|
||||
assert_eq!(f.app.project(), &expected);
|
||||
assert_eq!(f.app.document.bundle(), &adopted_bundle);
|
||||
assert!(!f.app.document.can_redo());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn source_same_layer_owner_retarget_undo_redo_keeps_requested_saved_uuid() {
|
||||
retarget(false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn source_cross_layer_owner_retarget_undo_redo_keeps_requested_saved_uuid() {
|
||||
retarget(true);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn source_deleted_owner_and_saved_view_mount_unavailable_instead_of_another_behavior() {
|
||||
let mut f = fixture();
|
||||
let before = f.app.document.snapshot();
|
||||
let mut expected = before.decoded.project.clone();
|
||||
assert!(expected.elements.remove(&f.owner).is_some());
|
||||
assert!(expected.diagrams.remove(&f.view).is_some());
|
||||
assert!(expected.elements.contains_key(&f.same_layer));
|
||||
assert!(
|
||||
expected
|
||||
.elements
|
||||
.values()
|
||||
.any(|e| e.kind() == Kind::Process)
|
||||
);
|
||||
adopt_from_source(&mut f.app, &expected);
|
||||
assert_eq!(
|
||||
f.app.behavior.scenario.representation(),
|
||||
Some(Representation::Saved { diagram: f.view })
|
||||
);
|
||||
let adopted = f.app.document.snapshot();
|
||||
let revision = f.app.document.revision();
|
||||
let mut mounted = Mounted::new(&mut f.app).await;
|
||||
let geometry = mounted.geometry(&f.app);
|
||||
assert!(
|
||||
geometry
|
||||
.containers
|
||||
.contains_key(&widget::Id::from("scenario-viewport-unavailable"))
|
||||
);
|
||||
assert!(
|
||||
!geometry
|
||||
.containers
|
||||
.contains_key(&widget::Id::from("scenario-viewport"))
|
||||
);
|
||||
assert_eq!(f.app.project(), &expected);
|
||||
assert_eq!(f.app.document.bundle(), &adopted.bundle);
|
||||
assert_eq!(
|
||||
f.app.document.revision(),
|
||||
revision,
|
||||
"mounting unavailable must remain passive"
|
||||
);
|
||||
|
||||
let _ = f.app.update(Message::Undo);
|
||||
assert_saved(&f.app, f.view, f.owner, Layer::Oa);
|
||||
assert_eq!(f.app.document.bundle(), &before.bundle);
|
||||
let _ = f.app.update(Message::Redo);
|
||||
assert_eq!(
|
||||
f.app.behavior.scenario.representation(),
|
||||
Some(Representation::Saved { diagram: f.view })
|
||||
);
|
||||
mounted.settle(&mut f.app).await;
|
||||
assert!(
|
||||
mounted
|
||||
.geometry(&f.app)
|
||||
.containers
|
||||
.contains_key(&widget::Id::from("scenario-viewport-unavailable"))
|
||||
);
|
||||
assert_eq!(f.app.project(), &expected);
|
||||
assert_eq!(f.app.document.bundle(), &adopted.bundle);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_and_deleted_picker_ids_cannot_apply_an_unrelated_valid_property_draft() {
|
||||
let mut f = fixture();
|
||||
let mut expected = f.app.project().clone();
|
||||
expected.diagrams.remove(&f.spare_view).unwrap();
|
||||
adopt_from_source(&mut f.app, &expected);
|
||||
let _ = f.app.update(Message::Select(f.owner));
|
||||
let _ = f.app.update(Message::Field(
|
||||
"/name".into(),
|
||||
"Pending valid owner rename".into(),
|
||||
));
|
||||
assert!(f.app.draft_dirty());
|
||||
let before = f.app.document.snapshot();
|
||||
let revision = f.app.document.revision();
|
||||
let selected = f.app.selected;
|
||||
for invalid in [Id::nil(), f.spare_view] {
|
||||
choose(&mut f.app, invalid);
|
||||
assert_saved(&f.app, f.view, f.owner, Layer::Oa);
|
||||
assert_eq!(f.app.selected, selected);
|
||||
assert!(f.app.draft_dirty());
|
||||
assert_eq!(f.app.project(), &before.decoded.project);
|
||||
assert_eq!(f.app.document.bundle(), &before.bundle);
|
||||
assert_eq!(f.app.document.revision(), revision);
|
||||
}
|
||||
// Establish that the retained draft really was valid, not merely refused by
|
||||
// the property validator: explicit Apply commits it in exactly one step.
|
||||
assert!(f.app.apply(), "{}", f.app.status);
|
||||
assert_eq!(
|
||||
f.app.project().elements[&f.owner].name,
|
||||
"Pending valid owner rename"
|
||||
);
|
||||
assert_eq!(f.app.document.revision(), revision + 1);
|
||||
let _ = f.app.update(Message::Undo);
|
||||
assert_eq!(f.app.project(), &before.decoded.project);
|
||||
assert_eq!(f.app.document.bundle(), &before.bundle);
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
//! Explicit owner navigation must retire a retained Saved Scenario, including
|
||||
//! when selection was made on a different page. These are real App events.
|
||||
use super::*;
|
||||
use crate::behavior::scenario::CanvasEvent;
|
||||
|
||||
fn setup(kind: Kind) -> (App, Id, Id) {
|
||||
let mut project = Project::empty();
|
||||
let scenario = project
|
||||
.add_element(Kind::Scenario, Layer::Oa, "Incident review", None)
|
||||
.unwrap();
|
||||
let target = project
|
||||
.add_element(kind, Layer::Oa, "Explicit destination", None)
|
||||
.unwrap();
|
||||
let view = Id::new_v4();
|
||||
project.diagrams.insert(
|
||||
view,
|
||||
Diagram {
|
||||
id: view,
|
||||
alias: "incident_saved".into(),
|
||||
name: "Incident saved arrangement".into(),
|
||||
description: String::new(),
|
||||
layer: Layer::Oa,
|
||||
projection: ProjectionKind::Scenario { scenario },
|
||||
layout: None,
|
||||
nodes: Default::default(),
|
||||
routes: vec![],
|
||||
view_options: Default::default(),
|
||||
},
|
||||
);
|
||||
let errors: Vec<_> = oa_core::validation::validate(&project)
|
||||
.into_iter()
|
||||
.filter(|issue| issue.severity == oa_core::validation::Severity::Error)
|
||||
.collect();
|
||||
assert!(errors.is_empty(), "{errors:?}");
|
||||
let mut app = App::with_project(project);
|
||||
let _ = app.update(Message::Select(scenario));
|
||||
let _ = app.update(Message::Diagram(Choice {
|
||||
id: view,
|
||||
label: "Incident saved arrangement".into(),
|
||||
}));
|
||||
assert_eq!(app.page, Page::Behavior);
|
||||
assert_eq!(
|
||||
app.scenario_context().unwrap().representation,
|
||||
Representation::Saved { diagram: view }
|
||||
);
|
||||
assert_eq!(app.selected, scenario);
|
||||
(app, scenario, target)
|
||||
}
|
||||
|
||||
fn assert_destination(app: &App, target: Id) {
|
||||
assert_eq!(app.page, Page::Behavior);
|
||||
assert_eq!(app.selected, target);
|
||||
assert_eq!(app.behavior.active_owner, Some(target));
|
||||
assert_eq!(behavior::selected_owner(app), Some(target));
|
||||
assert_eq!(
|
||||
app.behavior.scenario.representation(),
|
||||
None,
|
||||
"explicit non-Scenario destination must not retain an overriding Saved request"
|
||||
);
|
||||
assert!(app.scenario_context().is_none());
|
||||
}
|
||||
|
||||
fn exercise(via_guide: bool) {
|
||||
for kind in [Kind::Process, Kind::StateMachine] {
|
||||
let (mut app, scenario, target) = setup(kind);
|
||||
assert_ne!(scenario, target);
|
||||
let held = app.scenario_context().unwrap();
|
||||
let accepted = app.document.snapshot();
|
||||
let drafts = app.source_workspace.bundle();
|
||||
let revision = app.document.revision();
|
||||
let dirty = (app.document.dirty(), app.dirty(), app.source_dirty());
|
||||
assert!(!app.document.can_undo() && !app.document.can_redo());
|
||||
if via_guide {
|
||||
let _ = app.update(Message::Page(Page::Guide));
|
||||
assert_eq!(app.page, Page::Guide);
|
||||
assert!(app.scenario_context().is_none());
|
||||
}
|
||||
let _ = app.update(Message::Select(target));
|
||||
if via_guide {
|
||||
assert_eq!(
|
||||
app.page,
|
||||
Page::Guide,
|
||||
"explorer selection must not itself switch the page"
|
||||
);
|
||||
let _ = app.update(Message::Page(Page::Behavior));
|
||||
}
|
||||
assert_destination(&app, target);
|
||||
let camera = app.camera_boundary();
|
||||
// The prior saved canvas cannot regain focus after either owner route.
|
||||
let _ = app.update(Message::ScenarioCanvas(CanvasEvent::Focus(held)));
|
||||
assert_destination(&app, target);
|
||||
assert!(app.camera_boundary() == camera);
|
||||
assert_eq!(app.project(), &accepted.decoded.project);
|
||||
assert_eq!(app.document.bundle(), &accepted.bundle);
|
||||
assert_eq!(app.source_workspace.bundle(), drafts);
|
||||
assert_eq!(app.document.revision(), revision);
|
||||
assert_eq!(
|
||||
(app.document.dirty(), app.dirty(), app.source_dirty()),
|
||||
dirty
|
||||
);
|
||||
assert!(!app.document.can_undo() && !app.document.can_redo());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn saved_scenario_guide_selection_returns_to_explicit_process_or_state_owner() {
|
||||
exercise(true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn saved_scenario_direct_behavior_selection_enters_explicit_process_or_state_owner() {
|
||||
exercise(false);
|
||||
}
|
||||
@@ -1,205 +0,0 @@
|
||||
use super::*;
|
||||
use crate::behavior::scenario::{CanvasEvent, ScrollArea};
|
||||
|
||||
fn saved(p: &mut Project, owner: Id, name: &str) -> Id {
|
||||
let id = Id::new_v4();
|
||||
p.diagrams.insert(
|
||||
id,
|
||||
Diagram {
|
||||
id,
|
||||
alias: format!("view_{}", p.diagrams.len()),
|
||||
name: name.into(),
|
||||
description: String::new(),
|
||||
layer: Layer::Oa,
|
||||
projection: ProjectionKind::Scenario { scenario: owner },
|
||||
layout: None,
|
||||
routes: vec![],
|
||||
nodes: Default::default(),
|
||||
view_options: Default::default(),
|
||||
},
|
||||
);
|
||||
id
|
||||
}
|
||||
fn setup() -> (App, Id, Id, Id, Id) {
|
||||
let (mut p, [owner, callee, _], [reference, _, _]) =
|
||||
behavior::scenario::direct_tests::navigation_fixture();
|
||||
let a = saved(&mut p, owner, "Review A");
|
||||
let b = saved(&mut p, owner, "Review B");
|
||||
let mut app = App::with_project(p);
|
||||
app.select(owner);
|
||||
(app, a, b, reference, callee)
|
||||
}
|
||||
fn choose(app: &mut App, diagram: Id) {
|
||||
let _ = app.update(Message::Diagram(Choice {
|
||||
id: diagram,
|
||||
label: "Captured view".into(),
|
||||
}));
|
||||
}
|
||||
fn event(app: &mut App, f: impl FnOnce(behavior::scenario::Context) -> CanvasEvent) {
|
||||
let context = app.scenario_context().unwrap();
|
||||
let _ = app.update(Message::ScenarioCanvas(f(context)));
|
||||
}
|
||||
#[test]
|
||||
fn saved_view_switches_are_distinct_passive_visits_and_preserve_actual_history() {
|
||||
let (mut app, a, b, _, _) = setup();
|
||||
let original = app.document.snapshot();
|
||||
let owner = app.selected;
|
||||
assert!(app.execute(Command::Rename(owner, "Previously edited caller".into())));
|
||||
let edited = app.document.snapshot();
|
||||
let edited_revision = app.document.revision();
|
||||
choose(&mut app, a);
|
||||
let first = app.scenario_context().unwrap();
|
||||
choose(&mut app, b);
|
||||
let second = app.scenario_context().unwrap();
|
||||
choose(&mut app, a);
|
||||
let third = app.scenario_context().unwrap();
|
||||
assert_eq!(first.scenario, owner);
|
||||
assert_eq!(first.representation, Representation::Saved { diagram: a });
|
||||
assert_eq!(second.representation, Representation::Saved { diagram: b });
|
||||
assert_ne!(first.visit, second.visit);
|
||||
assert_ne!(first.visit, third.visit);
|
||||
assert_eq!(app.page, Page::Behavior);
|
||||
assert_eq!(app.selected, owner);
|
||||
assert_eq!(app.document.bundle(), &edited.bundle);
|
||||
assert_eq!(app.project(), &edited.decoded.project);
|
||||
assert_eq!(app.document.revision(), edited_revision);
|
||||
let _ = app.update(Message::Undo);
|
||||
assert_eq!(app.document.bundle(), &original.bundle);
|
||||
assert_eq!(app.project(), &original.decoded.project);
|
||||
let _ = app.update(Message::Redo);
|
||||
assert_eq!(app.document.bundle(), &edited.bundle);
|
||||
assert_eq!(app.project(), &edited.decoded.project);
|
||||
}
|
||||
#[test]
|
||||
fn saved_view_return_rejects_old_passive_events_without_an_intermediate_frame() {
|
||||
let (mut app, a, b, _, _) = setup();
|
||||
choose(&mut app, a);
|
||||
let old = app.scenario_context().unwrap();
|
||||
choose(&mut app, b);
|
||||
choose(&mut app, a);
|
||||
let current = app.scenario_context().unwrap();
|
||||
let camera = app.behavior.scenario.camera_boundary();
|
||||
let before = app.document.snapshot();
|
||||
for stale in [
|
||||
CanvasEvent::Viewport(old, iced::Size::new(432., 321.)),
|
||||
CanvasEvent::Scrolled(old, ScrollArea::Page, iced::Vector::new(0., 800.)),
|
||||
CanvasEvent::FormShown(old, Id::new_v4()),
|
||||
CanvasEvent::Restored(
|
||||
old,
|
||||
Id::new_v4(),
|
||||
ScrollArea::Page,
|
||||
iced::Vector::new(0., 800.),
|
||||
),
|
||||
CanvasEvent::Camera(
|
||||
old,
|
||||
app.camera_epoch,
|
||||
behavior::canvas_workspace::Event::Pan(iced::Vector::new(90., 80.)),
|
||||
),
|
||||
] {
|
||||
let _ = app.update(Message::ScenarioCanvas(stale));
|
||||
assert_eq!(app.scenario_context(), Some(current));
|
||||
assert!(app.behavior.scenario.camera_boundary() == camera);
|
||||
assert_eq!(app.document.bundle(), &before.bundle);
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn saved_reference_back_restores_exact_view_with_a_fresh_visit() {
|
||||
let (mut app, a, _, reference, callee) = setup();
|
||||
choose(&mut app, a);
|
||||
let caller = app.scenario_context().unwrap();
|
||||
let before = app.document.snapshot();
|
||||
event(&mut app, |ctx| CanvasEvent::OpenUse(ctx, reference));
|
||||
let target = app.scenario_context().unwrap();
|
||||
assert_eq!(target.scenario, callee);
|
||||
assert_eq!(
|
||||
target.representation,
|
||||
Representation::Derived { owner: callee }
|
||||
);
|
||||
assert_eq!(app.active_diagram, None);
|
||||
event(&mut app, CanvasEvent::Back);
|
||||
let returned = app.scenario_context().unwrap();
|
||||
assert_eq!(returned.representation, caller.representation);
|
||||
assert_eq!(app.active_diagram, Some(a));
|
||||
assert_eq!(app.selected, reference);
|
||||
assert_ne!(returned.visit, caller.visit);
|
||||
assert_eq!(app.document.bundle(), &before.bundle);
|
||||
assert_eq!(app.project(), &before.decoded.project);
|
||||
assert!(!app.document.can_undo());
|
||||
}
|
||||
#[test]
|
||||
fn saved_picker_applies_valid_old_draft_and_uuid_edit_follows_that_same_view() {
|
||||
let (mut app, a, b, _, _) = setup();
|
||||
choose(&mut app, a);
|
||||
let _ = app.update(Message::Select(a));
|
||||
let before = app.document.snapshot();
|
||||
let _ = app.update(Message::Field("/name".into(), "Renamed A".into()));
|
||||
choose(&mut app, b);
|
||||
assert_eq!(app.project().diagrams[&a].name, "Renamed A");
|
||||
assert_eq!(app.selected, b);
|
||||
assert_eq!(
|
||||
app.scenario_context().unwrap().representation,
|
||||
Representation::Saved { diagram: b }
|
||||
);
|
||||
let _ = app.update(Message::Undo);
|
||||
assert_eq!(app.document.bundle(), &before.bundle);
|
||||
choose(&mut app, a);
|
||||
let replacement = Id::new_v4();
|
||||
let _ = app.update(Message::Field("/id".into(), replacement.to_string()));
|
||||
choose(&mut app, a);
|
||||
assert!(!app.project().diagrams.contains_key(&a));
|
||||
assert_eq!(app.active_diagram, Some(replacement));
|
||||
assert_eq!(app.selected, replacement);
|
||||
assert_eq!(
|
||||
app.scenario_context().unwrap().representation,
|
||||
Representation::Saved {
|
||||
diagram: replacement
|
||||
}
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn leaving_and_reentering_saved_view_preserves_source_and_retires_passive_visit() {
|
||||
let (mut app, a, _, _, _) = setup();
|
||||
choose(&mut app, a);
|
||||
let old = app.scenario_context().unwrap();
|
||||
let before = app.document.snapshot();
|
||||
let _ = app.update(Message::Page(Page::Guide));
|
||||
assert!(app.scenario_context().is_none());
|
||||
let _ = app.update(Message::Page(Page::Behavior));
|
||||
let fresh = app.scenario_context().unwrap();
|
||||
assert_eq!(fresh.representation, old.representation);
|
||||
assert_ne!(fresh.visit, old.visit);
|
||||
assert_eq!(app.document.bundle(), &before.bundle);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arrangement_picker_rejects_previous_visit_and_switches_automatic_without_model_changes() {
|
||||
let (mut app, a, b, _, _) = setup();
|
||||
choose(&mut app, a);
|
||||
let stale = app.scenario_context().unwrap();
|
||||
choose(&mut app, b);
|
||||
let current = app.scenario_context().unwrap();
|
||||
let before = app.document.snapshot();
|
||||
let _ = app.update(Message::ScenarioCanvas(CanvasEvent::Representation(
|
||||
stale,
|
||||
Representation::Saved { diagram: a },
|
||||
)));
|
||||
assert_eq!(app.scenario_context(), Some(current));
|
||||
event(&mut app, |context| {
|
||||
CanvasEvent::Representation(
|
||||
context,
|
||||
Representation::Derived {
|
||||
owner: context.scenario,
|
||||
},
|
||||
)
|
||||
});
|
||||
assert_eq!(
|
||||
app.scenario_context().unwrap().representation,
|
||||
Representation::Derived {
|
||||
owner: current.scenario
|
||||
}
|
||||
);
|
||||
assert_eq!(app.active_diagram, None);
|
||||
assert_eq!(app.document.bundle(), &before.bundle);
|
||||
assert_eq!(app.project(), &before.decoded.project);
|
||||
assert!(!app.document.can_undo());
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
//! Admit spacing packets before ordinary navigation can retire a newer reveal.
|
||||
use super::*;
|
||||
use behavior::scenario::spacing::{Event, controller::Finish};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
impl App {
|
||||
pub(super) fn spacing_enabled(&self) -> bool {
|
||||
self.pending_diagram_reveal.is_none()
|
||||
&& !self.behavior.has_pending()
|
||||
&& !self.draft_dirty()
|
||||
&& !self.source_dirty()
|
||||
&& !self.source_rename.open()
|
||||
&& behavior::canvas_workspace::keyboard_enabled(self)
|
||||
}
|
||||
|
||||
pub(super) fn scenario_spacing(&mut self, event: Event) -> Task<Message> {
|
||||
let stamp = event.stamp();
|
||||
if self.scenario_context() != Some(stamp.context) || self.camera_epoch != stamp.camera_epoch
|
||||
{
|
||||
return Task::none();
|
||||
}
|
||||
let state = &self.behavior.scenario;
|
||||
let matches =
|
||||
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,
|
||||
} {
|
||||
return Task::none();
|
||||
}
|
||||
if matches!(event, Event::Cancel { .. }) || !self.spacing_enabled() {
|
||||
if self.behavior.scenario.cancel_spacing() {
|
||||
self.canvas_epoch = self.canvas_epoch.wrapping_add(1);
|
||||
}
|
||||
return Task::none();
|
||||
}
|
||||
match event {
|
||||
Event::Begin { .. } => {
|
||||
let mut state = std::mem::take(&mut self.behavior.scenario);
|
||||
let result = state.begin_spacing(self.project(), event);
|
||||
self.behavior.scenario = state;
|
||||
if result.is_err() {
|
||||
self.status = "The drag could not start in this view. Try again.".into();
|
||||
}
|
||||
}
|
||||
Event::Move { screen, .. } => self.behavior.scenario.move_spacing(screen),
|
||||
Event::Finish { screen, .. } => {
|
||||
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)) => self.select(target),
|
||||
Ok(Finish::Noop) => {}
|
||||
Ok(Finish::Commit {
|
||||
command,
|
||||
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();
|
||||
}
|
||||
Err(error) => self.status = format!("Spacing was not applied: {error}"),
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
self.status =
|
||||
"That position cannot be applied. The saved arrangement is unchanged."
|
||||
.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
Event::Cancel { .. } => unreachable!(),
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
}
|
||||
@@ -1,272 +0,0 @@
|
||||
use super::*;
|
||||
use behavior::scenario::{
|
||||
CanvasEvent,
|
||||
spacing::{
|
||||
Target,
|
||||
controller::tests::{fixture, packet},
|
||||
},
|
||||
};
|
||||
use iced::{Point, Size, Vector};
|
||||
|
||||
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));
|
||||
let _ = app.update(Message::Diagram(Choice {
|
||||
id: diagram,
|
||||
label: "Saved".into(),
|
||||
}));
|
||||
let c = app.scenario_context().unwrap();
|
||||
let _ = app.update(Message::ScenarioCanvas(CanvasEvent::Viewport(
|
||||
c,
|
||||
Size::new(900., 600.),
|
||||
)));
|
||||
assert!(app.spacing_enabled());
|
||||
(app, lane, message)
|
||||
}
|
||||
fn begin(app: &mut App, target: Target) -> (Event, Point, f32) {
|
||||
let event = packet(
|
||||
app.project(),
|
||||
&app.behavior.scenario,
|
||||
app.scenario_context().unwrap(),
|
||||
app.camera_epoch,
|
||||
target,
|
||||
);
|
||||
let Event::Begin {
|
||||
press_screen,
|
||||
scale,
|
||||
..
|
||||
} = event
|
||||
else {
|
||||
unreachable!()
|
||||
};
|
||||
let _ = app.update(Message::ScenarioCanvas(CanvasEvent::Spacing(event)));
|
||||
assert_eq!(app.behavior.scenario.spacing_token(), Some(event.token()));
|
||||
(event, press_screen, scale)
|
||||
}
|
||||
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) {
|
||||
send(
|
||||
app,
|
||||
Event::Move {
|
||||
stamp: begin.stamp(),
|
||||
token: begin.token(),
|
||||
screen,
|
||||
},
|
||||
);
|
||||
}
|
||||
fn finish(app: &mut App, begin: Event, screen: Point) {
|
||||
send(
|
||||
app,
|
||||
Event::Finish {
|
||||
stamp: begin.stamp(),
|
||||
token: begin.token(),
|
||||
screen,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn same_batch_preview_is_immutable_and_one_commit_undo_redo_has_exact_source_parity() {
|
||||
let (mut app, lane, _) = setup();
|
||||
let original = app.document.snapshot();
|
||||
let source = app.source_workspace.bundle();
|
||||
let selected = app.selected;
|
||||
let epoch = app.canvas_epoch;
|
||||
let (event, start, scale) = begin(&mut app, Target::Lane(lane));
|
||||
move_to(&mut app, event, start + Vector::new(40., 300.));
|
||||
assert_eq!(app.selected, selected);
|
||||
assert_eq!(app.canvas_epoch, epoch);
|
||||
assert_eq!(app.project(), &original.decoded.project);
|
||||
assert_eq!(app.source_workspace.bundle(), source);
|
||||
assert!(!app.document.can_undo() && !app.document.can_redo());
|
||||
finish(&mut app, event, start + Vector::new(40., 300.));
|
||||
assert_eq!(app.selected, lane);
|
||||
assert!(app.document.can_undo() && !app.document.can_redo());
|
||||
let accepted = app.document.snapshot();
|
||||
assert_ne!(accepted.bundle, original.bundle);
|
||||
let expected = behavior::scenario::spacing::controller::tests::expected(
|
||||
&original.decoded.project,
|
||||
match event.stamp().context.representation {
|
||||
behavior::scenario_layout::Representation::Saved { diagram } => diagram,
|
||||
_ => unreachable!(),
|
||||
},
|
||||
Target::Lane(lane),
|
||||
40. / scale,
|
||||
);
|
||||
assert_eq!(app.project(), &expected);
|
||||
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(), &accepted.decoded.project);
|
||||
assert_eq!(app.document.bundle(), &accepted.bundle);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn click_selects_but_crossed_return_and_cancel_preserve_selection_camera_and_history() {
|
||||
let (mut app, lane, message) = setup();
|
||||
let original = app.document.snapshot();
|
||||
let camera = app.behavior.scenario.camera_boundary();
|
||||
let (event, start, _) = begin(&mut app, Target::Message(message));
|
||||
finish(&mut app, event, start + Vector::new(30., 2.));
|
||||
assert_eq!(app.selected, message);
|
||||
assert!(camera == app.behavior.scenario.camera_boundary());
|
||||
for cancel in [false, true] {
|
||||
let (event, start, _) = begin(&mut app, Target::Lane(lane));
|
||||
move_to(&mut app, event, start + Vector::new(30., 0.));
|
||||
if cancel {
|
||||
send(
|
||||
&mut app,
|
||||
Event::Cancel {
|
||||
stamp: event.stamp(),
|
||||
token: event.token(),
|
||||
},
|
||||
);
|
||||
} else {
|
||||
finish(&mut app, event, start);
|
||||
}
|
||||
assert_eq!(app.selected, message);
|
||||
assert!(camera == app.behavior.scenario.camera_boundary());
|
||||
assert_eq!(app.document.bundle(), &original.bundle);
|
||||
assert_eq!(app.project(), &original.decoded.project);
|
||||
assert!(!app.document.can_undo() && !app.document.can_redo());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stale_finish_after_new_view_and_forged_token_are_inert_before_reveal_reconciliation() {
|
||||
let (mut app, lane, _) = setup();
|
||||
let (event, start, _) = begin(&mut app, Target::Lane(lane));
|
||||
let held_epoch = app.canvas_epoch;
|
||||
send(
|
||||
&mut app,
|
||||
Event::Finish {
|
||||
stamp: event.stamp(),
|
||||
token: Id::new_v4(),
|
||||
screen: start + Vector::new(30., 0.),
|
||||
},
|
||||
);
|
||||
assert_eq!(app.canvas_epoch, held_epoch);
|
||||
assert_eq!(app.behavior.scenario.spacing_token(), Some(event.token()));
|
||||
let owner = event.stamp().context.scenario;
|
||||
let _ = app.update(Message::ScenarioCanvas(CanvasEvent::Representation(
|
||||
event.stamp().context,
|
||||
behavior::scenario_layout::Representation::Derived { owner },
|
||||
)));
|
||||
let current = app.scenario_context();
|
||||
let epoch = app.canvas_epoch;
|
||||
let original = app.document.snapshot();
|
||||
finish(&mut app, event, start + Vector::new(50., 0.));
|
||||
assert_eq!(app.scenario_context(), current);
|
||||
assert_eq!(app.canvas_epoch, epoch);
|
||||
assert!(app.behavior.scenario.spacing_token().is_none());
|
||||
assert_eq!(app.document.bundle(), &original.bundle);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn source_write_failure_cannot_commit_candidate_or_materialize_camera() {
|
||||
let (mut app, lane, _) = setup();
|
||||
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 selected = app.selected;
|
||||
let camera = app.behavior.scenario.camera_boundary();
|
||||
let (event, start, _) = begin(&mut app, Target::Lane(lane));
|
||||
move_to(&mut app, event, start + Vector::new(40., 0.));
|
||||
finish(&mut app, event, start + Vector::new(40., 0.));
|
||||
assert!(
|
||||
app.status.starts_with("Spacing was not applied:"),
|
||||
"{}",
|
||||
app.status
|
||||
);
|
||||
assert_eq!(app.selected, selected);
|
||||
assert!(camera == app.behavior.scenario.camera_boundary());
|
||||
assert_eq!(app.project(), &original.decoded.project);
|
||||
assert_eq!(app.document.bundle(), &original.bundle);
|
||||
assert!(!app.document.can_undo() && !app.document.can_redo());
|
||||
assert!(app.behavior.scenario.spacing_token().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pending_semantic_draft_and_source_edit_cancel_and_reject_held_finish() {
|
||||
for source in [false, true] {
|
||||
let (mut app, lane, _) = setup();
|
||||
let original = app.document.snapshot();
|
||||
let selected = app.selected;
|
||||
let (event, start, _) = begin(&mut app, Target::Lane(lane));
|
||||
move_to(&mut app, event, start + Vector::new(30., 0.));
|
||||
if source {
|
||||
let _ = app.update(Message::SourceEdit(text_editor::Action::Edit(
|
||||
text_editor::Edit::Insert(' '),
|
||||
)));
|
||||
assert!(app.source_dirty());
|
||||
} else {
|
||||
let _ = app.update(Message::Behavior(behavior::Event::Scenario(
|
||||
behavior::scenario::Event::Start(
|
||||
event.stamp().context.scenario,
|
||||
behavior::scenario::Tool::Lifeline,
|
||||
),
|
||||
)));
|
||||
assert!(app.behavior.has_pending());
|
||||
}
|
||||
let draft = app.source_workspace.bundle();
|
||||
assert!(app.behavior.scenario.spacing_token().is_none());
|
||||
finish(&mut app, event, start + Vector::new(30., 0.));
|
||||
assert_eq!(app.project(), &original.decoded.project);
|
||||
assert_eq!(app.document.bundle(), &original.bundle);
|
||||
assert_eq!(app.source_workspace.bundle(), draft);
|
||||
assert_eq!(app.selected, selected);
|
||||
assert!(!app.document.can_undo());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stale_finish_cannot_remove_new_same_view_deferred_reveal() {
|
||||
let (mut app, lane, message) = setup();
|
||||
let (event, start, _) = begin(&mut app, Target::Lane(lane));
|
||||
let behavior::scenario_layout::Representation::Saved { diagram } =
|
||||
event.stamp().context.representation
|
||||
else {
|
||||
unreachable!()
|
||||
};
|
||||
let _ = app.update(Message::RevealInDiagram(diagram, message));
|
||||
assert!(app.pending_diagram_reveal.is_some());
|
||||
let epoch = app.canvas_epoch;
|
||||
let selected = app.selected;
|
||||
let visit = app.pending_scenario_reveal_visit;
|
||||
let original = app.document.snapshot();
|
||||
finish(&mut app, event, start + Vector::new(50., 0.));
|
||||
assert_eq!(app.canvas_epoch, epoch);
|
||||
assert_eq!(app.pending_scenario_reveal_visit, visit);
|
||||
assert!(app.pending_diagram_reveal.is_some());
|
||||
assert_eq!(app.selected, selected);
|
||||
assert_eq!(app.document.bundle(), &original.bundle);
|
||||
assert!(!app.document.can_undo());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn modal_open_cancels_preview_and_captured_begin_stays_retired_after_close() {
|
||||
let (mut app, lane, _) = setup();
|
||||
let original = app.document.snapshot();
|
||||
let camera = app.behavior.scenario.camera_boundary();
|
||||
let (event, start, _) = begin(&mut app, Target::Lane(lane));
|
||||
move_to(&mut app, event, start + Vector::new(30., 0.));
|
||||
let _ = app.update(Message::Delete);
|
||||
assert!(app.delete_pending);
|
||||
assert!(app.behavior.scenario.spacing_token().is_none());
|
||||
finish(&mut app, event, start + Vector::new(30., 0.));
|
||||
let _ = app.update(Message::CancelDelete);
|
||||
send(&mut app, event);
|
||||
assert!(app.behavior.scenario.spacing_token().is_none());
|
||||
assert_eq!(app.project(), &original.decoded.project);
|
||||
assert_eq!(app.document.bundle(), &original.bundle);
|
||||
assert!(camera == app.behavior.scenario.camera_boundary());
|
||||
assert!(!app.document.can_undo());
|
||||
}
|
||||
@@ -24,7 +24,6 @@ impl App {
|
||||
if self.behavior.has_pending() {
|
||||
return;
|
||||
}
|
||||
self.behavior.scenario.forget_view();
|
||||
self.layer = layer;
|
||||
self.page = Page::Behavior;
|
||||
self.behavior.active_owner = Some(machine);
|
||||
|
||||
@@ -49,28 +49,11 @@ fn fixture(layer: Layer, kind: Kind) -> (App, Id, Id, Id) {
|
||||
p.diagrams.get_mut(&view).unwrap().name = "Unrelated architecture".into();
|
||||
p.place(view, reused, Position { x: 873., y: 421. });
|
||||
let mut app = App::with_project(p);
|
||||
let accepted = app.document.snapshot();
|
||||
// Enter through the actual navigation path: assigning Page/owner alone does
|
||||
// not create the representation and live visit required by canvas events.
|
||||
send(&mut app, Message::Select(root));
|
||||
send(&mut app, Message::Page(Page::Behavior));
|
||||
assert_eq!(app.layer, layer);
|
||||
assert_eq!(app.page, Page::Behavior);
|
||||
assert_eq!(app.selected, root);
|
||||
assert_eq!(app.behavior.active_owner, Some(root));
|
||||
if kind == Kind::Scenario {
|
||||
let context = app.scenario_context().unwrap();
|
||||
assert_eq!(context.document, app.canvas_document);
|
||||
assert_eq!(context.scenario, root);
|
||||
assert_eq!(
|
||||
context.representation,
|
||||
crate::behavior::scenario_layout::Representation::Derived { owner: root }
|
||||
);
|
||||
assert!(!context.visit.is_nil());
|
||||
}
|
||||
assert!(Arc::ptr_eq(&accepted, &app.document.snapshot()));
|
||||
assert_eq!(app.source_workspace.bundle(), accepted.bundle);
|
||||
assert!(!app.document.can_undo() && !app.document.can_redo());
|
||||
app.layer = layer;
|
||||
app.page = Page::Behavior;
|
||||
app.selected = root;
|
||||
app.behavior.active_owner = Some(root);
|
||||
app.refresh_draft();
|
||||
(app, root, work, reused)
|
||||
}
|
||||
|
||||
|
||||
@@ -21,11 +21,9 @@ pub(crate) mod creation;
|
||||
mod form_session;
|
||||
pub(crate) mod scenario;
|
||||
mod scenario_activation;
|
||||
#[cfg(test)]
|
||||
mod scenario_hit_tests;
|
||||
// Pure saved-geometry bridge; workspace integration is a separate checkpoint.
|
||||
#[allow(dead_code)]
|
||||
pub(crate) mod scenario_layout;
|
||||
mod scenario_layout;
|
||||
mod scenario_lifecycle;
|
||||
pub(crate) mod source_draft;
|
||||
pub(crate) mod state_canvas;
|
||||
@@ -64,18 +62,9 @@ mod scenario_scroll {
|
||||
process: bool,
|
||||
restore: Option<scenario::ScrollRestore>,
|
||||
}
|
||||
type Identity = (Id, Id, scenario_layout::Representation, Id);
|
||||
fn identity(context: scenario::Context) -> Identity {
|
||||
(
|
||||
context.document,
|
||||
context.scenario,
|
||||
context.representation,
|
||||
context.visit,
|
||||
)
|
||||
}
|
||||
type Report = Option<(bool, Identity, Vector)>;
|
||||
type Report = Option<(bool, Id, Id, Vector)>;
|
||||
struct ObservedScroll {
|
||||
identity: Identity,
|
||||
identity: (Id, Id),
|
||||
report: Report,
|
||||
restored: Option<Id>,
|
||||
}
|
||||
@@ -126,12 +115,8 @@ mod scenario_scroll {
|
||||
) {
|
||||
let restore = self.restore.filter(|request| {
|
||||
!self.process
|
||||
&& (
|
||||
request.document,
|
||||
request.owner,
|
||||
request.representation,
|
||||
request.visit,
|
||||
) == identity(self.context)
|
||||
&& (request.document, request.owner)
|
||||
== (self.context.document, self.context.scenario)
|
||||
&& tree.state.downcast_ref::<ObservedScroll>().restored != Some(request.token)
|
||||
});
|
||||
let receipt = restore.and_then(|request| {
|
||||
@@ -155,7 +140,12 @@ mod scenario_scroll {
|
||||
&mut offset,
|
||||
);
|
||||
if let Some(offset) = offset.0 {
|
||||
let next = Some((self.process, identity(self.context), offset));
|
||||
let next = Some((
|
||||
self.process,
|
||||
self.context.document,
|
||||
self.context.scenario,
|
||||
offset,
|
||||
));
|
||||
let state = tree.state.downcast_mut::<ObservedScroll>();
|
||||
if let Some(token) = receipt {
|
||||
state.restored = Some(token);
|
||||
@@ -199,7 +189,7 @@ mod scenario_scroll {
|
||||
}
|
||||
fn state(&self) -> widget::tree::State {
|
||||
widget::tree::State::new(ObservedScroll {
|
||||
identity: identity(self.context),
|
||||
identity: (self.context.document, self.context.scenario),
|
||||
report: None,
|
||||
restored: None,
|
||||
})
|
||||
@@ -208,7 +198,9 @@ mod scenario_scroll {
|
||||
vec![widget::Tree::new(self.content.as_widget())]
|
||||
}
|
||||
fn diff(&self, tree: &mut widget::Tree) {
|
||||
if tree.state.downcast_ref::<ObservedScroll>().identity != identity(self.context) {
|
||||
if tree.state.downcast_ref::<ObservedScroll>().identity
|
||||
!= (self.context.document, self.context.scenario)
|
||||
{
|
||||
// A new owner/document needs fresh real scroll state, not merely
|
||||
// cleared mirrored offsets. Edits and tool/form changes retain it.
|
||||
tree.state = self.state();
|
||||
@@ -497,25 +489,17 @@ mod scenario_scroll {
|
||||
}
|
||||
#[test]
|
||||
fn direct_scenario_restore_cannot_scroll_another_document_owner_or_process_view() {
|
||||
for mismatch in 0..5 {
|
||||
for mismatch in 0..3 {
|
||||
let context = scenario::direct_tests::context(Id::new_v4());
|
||||
let mut request = scenario::ScrollRestore {
|
||||
document: context.document,
|
||||
owner: context.scenario,
|
||||
representation: context.representation,
|
||||
visit: context.visit,
|
||||
token: Id::new_v4(),
|
||||
offset: Vector::new(0., 180.),
|
||||
};
|
||||
match mismatch {
|
||||
0 => request.document = Id::new_v4(),
|
||||
1 => request.owner = Id::new_v4(),
|
||||
3 => {
|
||||
request.representation = scenario_layout::Representation::Saved {
|
||||
diagram: Id::new_v4(),
|
||||
}
|
||||
}
|
||||
4 => request.visit = Id::new_v4(),
|
||||
_ => {}
|
||||
}
|
||||
let mut view = observer(600., context);
|
||||
@@ -602,7 +586,7 @@ mod scenario_scroll {
|
||||
use widget::operation::scrollable::{AbsoluteOffset, scroll_to};
|
||||
for process in [false, true] {
|
||||
let area = scenario::ScrollArea::Page;
|
||||
for change in 0..6 {
|
||||
for change in 0..4 {
|
||||
let context = scenario::direct_tests::context(Id::new_v4());
|
||||
let mut view = observer(600., context);
|
||||
view.process = process;
|
||||
@@ -631,12 +615,6 @@ mod scenario_scroll {
|
||||
next.revision += 1;
|
||||
next.epoch += 5;
|
||||
}
|
||||
4 => {
|
||||
next.representation = scenario_layout::Representation::Saved {
|
||||
diagram: Id::new_v4(),
|
||||
}
|
||||
}
|
||||
5 => next.visit = Id::new_v4(),
|
||||
_ => {}
|
||||
}
|
||||
view = observer(if change == 3 { 800. } else { 600. }, next);
|
||||
@@ -684,7 +662,7 @@ mod scenario_scroll {
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(
|
||||
actual,
|
||||
vec![if !(2..4).contains(&change) {
|
||||
vec![if change < 2 {
|
||||
Vector::ZERO
|
||||
} else {
|
||||
Vector::new(0., 180.)
|
||||
@@ -998,19 +976,6 @@ pub fn view(app: &App) -> Element<'_, Message> {
|
||||
return container(out).padding(16).width(Fill).height(Fill).into();
|
||||
}
|
||||
}
|
||||
// A requested saved view remains the destination even after its model is removed.
|
||||
// The shared display adapter reports unavailable instead of choosing another behavior.
|
||||
if matches!(
|
||||
app.behavior.scenario.representation(),
|
||||
Some(scenario_layout::Representation::Saved { .. })
|
||||
) && let Some(owner) = app.behavior.scenario.owner()
|
||||
&& !p
|
||||
.elements
|
||||
.get(&owner)
|
||||
.is_some_and(|element| element.kind() == Kind::Scenario && element.layer() == app.layer)
|
||||
{
|
||||
return scenario::view(app, owner, column![].spacing(6));
|
||||
}
|
||||
let choices = p
|
||||
.elements
|
||||
.values()
|
||||
@@ -1022,14 +987,7 @@ pub fn view(app: &App) -> Element<'_, Message> {
|
||||
label: format!("{} · {}", e.kind(), e.name),
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let owner = if matches!(
|
||||
app.behavior.scenario.representation(),
|
||||
Some(scenario_layout::Representation::Saved { .. })
|
||||
) {
|
||||
app.behavior.scenario.owner()
|
||||
} else {
|
||||
selected_owner(app)
|
||||
};
|
||||
let owner = selected_owner(app);
|
||||
let selected = owner
|
||||
.and_then(|id| choices.iter().find(|c| c.id == id))
|
||||
.or(choices.first())
|
||||
@@ -1163,27 +1121,8 @@ fn in_machine(p: &Project, id: Id, machine: Id) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
/// Identifies the drawn primitive that won selection, not an authoring permission.
|
||||
/// In particular an activation and its message can share an occurrence UUID.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum SceneHitRole {
|
||||
LifelineHeader,
|
||||
MessageBody,
|
||||
MessageLabel,
|
||||
Activation,
|
||||
LifecycleMarker,
|
||||
LifelineGuide,
|
||||
Box,
|
||||
OtherLine,
|
||||
}
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
struct SceneHit {
|
||||
id: Id,
|
||||
role: SceneHitRole,
|
||||
}
|
||||
struct BoxItem {
|
||||
id: Id,
|
||||
role: SceneHitRole,
|
||||
rect: Rectangle,
|
||||
title: String,
|
||||
detail: String,
|
||||
@@ -1216,7 +1155,6 @@ fn box_text_clip(
|
||||
|
||||
struct Line {
|
||||
id: Id,
|
||||
role: SceneHitRole,
|
||||
points: Vec<Point>,
|
||||
label: String,
|
||||
label_at: Point,
|
||||
@@ -1242,8 +1180,6 @@ struct Scene {
|
||||
scale: f32,
|
||||
camera_pan: iced::Vector,
|
||||
interaction: Option<(scenario::Context, scenario::CanvasTool, bool)>,
|
||||
spacing_stamp: Option<scenario::spacing::Stamp>,
|
||||
coordinate_input: bool,
|
||||
pending_placement: Option<(scenario::Slot, Option<Id>)>,
|
||||
lanes: BTreeMap<Id, f32>,
|
||||
// Exact render coordinates include unassigned lanes; do not derive from cards.
|
||||
@@ -1271,10 +1207,6 @@ struct SequenceInput {
|
||||
}
|
||||
#[derive(Clone, Copy)]
|
||||
enum SequencePress {
|
||||
Spacing {
|
||||
stamp: scenario::spacing::Stamp,
|
||||
token: Id,
|
||||
},
|
||||
Occurrence {
|
||||
tool: scenario::Tool,
|
||||
slot: scenario::Slot,
|
||||
@@ -1295,26 +1227,12 @@ enum SequencePress {
|
||||
},
|
||||
}
|
||||
impl SequenceInput {
|
||||
fn cancel_spacing(&mut self) -> Option<Action<Message>> {
|
||||
let cancel = match self.press {
|
||||
Some(SequencePress::Spacing { stamp, token }) => Some(
|
||||
Action::publish(Message::ScenarioCanvas(scenario::CanvasEvent::Spacing(
|
||||
scenario::spacing::Event::Cancel { stamp, token },
|
||||
)))
|
||||
.and_capture(),
|
||||
),
|
||||
_ => None,
|
||||
};
|
||||
self.cancel();
|
||||
cancel
|
||||
}
|
||||
fn cancel(&mut self) {
|
||||
self.source = None;
|
||||
self.press = None;
|
||||
}
|
||||
}
|
||||
impl Scene {
|
||||
#[cfg(test)]
|
||||
fn sequence(p: &Project, owner: Id, selected: Id) -> Self {
|
||||
Self::sequence_geometry(p, owner, selected, None, None)
|
||||
}
|
||||
@@ -1334,8 +1252,6 @@ impl Scene {
|
||||
layout_origin: Point::ORIGIN,
|
||||
selected,
|
||||
interaction: None,
|
||||
spacing_stamp: None,
|
||||
coordinate_input: true,
|
||||
pending_placement: None,
|
||||
lanes: BTreeMap::new(),
|
||||
render_lanes: BTreeMap::new(),
|
||||
@@ -1492,7 +1408,6 @@ impl Scene {
|
||||
0,
|
||||
Line {
|
||||
id,
|
||||
role: SceneHitRole::LifelineGuide,
|
||||
points: vec![Point::new(x, 85.), Point::new(x, scene.size.height - 20.)],
|
||||
label: String::new(),
|
||||
label_at: Point::ORIGIN,
|
||||
@@ -1502,11 +1417,6 @@ impl Scene {
|
||||
}
|
||||
scene.boxes.push(BoxItem {
|
||||
id,
|
||||
role: if scenario {
|
||||
SceneHitRole::LifelineHeader
|
||||
} else {
|
||||
SceneHitRole::Box
|
||||
},
|
||||
rect: Rectangle::new(Point::new(x - 102., 15.), Size::new(204., 70.)),
|
||||
title: if scenario {
|
||||
format!("Lane · {name}")
|
||||
@@ -1600,7 +1510,6 @@ impl Scene {
|
||||
0,
|
||||
BoxItem {
|
||||
id: *id,
|
||||
role: SceneHitRole::Box,
|
||||
rect,
|
||||
title: format!("{operator:?} · {}", e.name),
|
||||
detail: String::new(),
|
||||
@@ -1612,7 +1521,6 @@ impl Scene {
|
||||
OccurrenceBody::Branch { guard, .. } => {
|
||||
self.boxes.push(BoxItem {
|
||||
id: *id,
|
||||
role: SceneHitRole::Box,
|
||||
rect: Rectangle::new(
|
||||
Point::new(36. + depth as f32 * 10., *y),
|
||||
Size::new(self.size.width - 85. - depth as f32 * 20., 43.),
|
||||
@@ -1696,7 +1604,6 @@ impl Scene {
|
||||
}
|
||||
self.lines.push(Line {
|
||||
id: *id,
|
||||
role: SceneHitRole::MessageBody,
|
||||
points,
|
||||
label: format!("{}. {kind}{}", index + 1, message_label),
|
||||
label_at: Point::new(a.min(*b) + 12., *y - 26.),
|
||||
@@ -1705,7 +1612,6 @@ impl Scene {
|
||||
} else {
|
||||
self.boxes.push(BoxItem {
|
||||
id: *id,
|
||||
role: SceneHitRole::Box,
|
||||
rect: Rectangle::new(
|
||||
Point::new(65., *y - 20.),
|
||||
Size::new(self.size.width - 130., 65.),
|
||||
@@ -1728,7 +1634,6 @@ impl Scene {
|
||||
.unwrap_or(180.);
|
||||
self.boxes.push(BoxItem {
|
||||
id: *id,
|
||||
role: SceneHitRole::Box,
|
||||
rect: Rectangle::new(Point::new(x - 110., *y - 20.), Size::new(220., 70.)),
|
||||
title: e.name.clone(),
|
||||
detail: action
|
||||
@@ -1741,7 +1646,6 @@ impl Scene {
|
||||
OccurrenceBody::Control { kind } => {
|
||||
self.boxes.push(BoxItem {
|
||||
id: *id,
|
||||
role: SceneHitRole::Box,
|
||||
rect: Rectangle::new(Point::new(65., *y - 20.), Size::new(240., 70.)),
|
||||
title: format!("{kind:?} · {}", e.name),
|
||||
detail: "Contextual process control".into(),
|
||||
@@ -1752,7 +1656,6 @@ impl Scene {
|
||||
OccurrenceBody::SequenceReference { sequence } => {
|
||||
self.boxes.push(BoxItem {
|
||||
id: *id,
|
||||
role: SceneHitRole::Box,
|
||||
rect: Rectangle::new(Point::new(65., *y - 20.), Size::new(280., 70.)),
|
||||
title: e.name.clone(),
|
||||
detail: sequence
|
||||
@@ -1765,7 +1668,6 @@ impl Scene {
|
||||
OccurrenceBody::ScenarioUse { scenario, bindings } => {
|
||||
self.boxes.push(BoxItem {
|
||||
id: *id,
|
||||
role: SceneHitRole::Box,
|
||||
rect: Rectangle::new(
|
||||
Point::new(65., *y - 20.),
|
||||
Size::new(self.size.width - 130., 70.),
|
||||
@@ -1831,21 +1733,11 @@ impl Scene {
|
||||
))
|
||||
}
|
||||
fn hit(&self, point: Point) -> Option<Id> {
|
||||
self.hit_item(point).map(|hit| hit.id)
|
||||
}
|
||||
|
||||
/// Preserve the semantic selection order and tolerance while retaining the
|
||||
/// primitive's identity. Future spacing admission must also validate the
|
||||
/// saved view, owner and core occurrence kind; a hit alone grants no edit.
|
||||
fn hit_item(&self, point: Point) -> Option<SceneHit> {
|
||||
if !point.x.is_finite() || !point.y.is_finite() {
|
||||
return None;
|
||||
}
|
||||
if let Some(id) = self.lifecycle.marker_at(point) {
|
||||
return Some(SceneHit {
|
||||
id,
|
||||
role: SceneHitRole::LifecycleMarker,
|
||||
});
|
||||
return Some(id);
|
||||
}
|
||||
self.boxes
|
||||
.iter()
|
||||
@@ -1855,10 +1747,7 @@ impl Scene {
|
||||
&& b.rect.contains(point)
|
||||
&& (b.marker != Some(Kind::Occurrence) || point.y < b.rect.y + 38.)
|
||||
})
|
||||
.map(|b| SceneHit {
|
||||
id: b.id,
|
||||
role: b.role,
|
||||
})
|
||||
.map(|b| b.id)
|
||||
.or_else(|| {
|
||||
self.lines
|
||||
.iter()
|
||||
@@ -1868,51 +1757,36 @@ impl Scene {
|
||||
crate::diagram::distance_to_segment(point, p[0], p[1]) < 1.5
|
||||
})
|
||||
})
|
||||
.map(|line| SceneHit {
|
||||
id: line.id,
|
||||
role: line.role,
|
||||
})
|
||||
.map(|line| line.id)
|
||||
})
|
||||
.or_else(|| {
|
||||
self.activations
|
||||
.iter()
|
||||
.rev()
|
||||
.find(|b| b.rect.contains(point))
|
||||
.map(|b| SceneHit {
|
||||
id: b.call,
|
||||
role: SceneHitRole::Activation,
|
||||
})
|
||||
.map(|b| b.call)
|
||||
})
|
||||
.or_else(|| {
|
||||
self.lines
|
||||
.iter()
|
||||
.find(|line| !line.label.is_empty() && line.label_bounds().contains(point))
|
||||
.map(|line| SceneHit {
|
||||
id: line.id,
|
||||
role: if line.role == SceneHitRole::MessageBody {
|
||||
SceneHitRole::MessageLabel
|
||||
} else {
|
||||
SceneHitRole::OtherLine
|
||||
},
|
||||
.find(|line| {
|
||||
!line.label.is_empty()
|
||||
&& Rectangle::new(
|
||||
line.label_at,
|
||||
Size::new(
|
||||
(line.label.chars().count() as f32 * 6.8 + 8.).min(225.),
|
||||
25.,
|
||||
),
|
||||
)
|
||||
.contains(point)
|
||||
})
|
||||
.map(|line| line.id)
|
||||
})
|
||||
// The generous message tolerance must not steal the exposed
|
||||
// shoulder of another call's execution when the view is zoomed out.
|
||||
.or_else(|| self.near_sequence_item(point))
|
||||
.or_else(|| {
|
||||
self.lifecycle
|
||||
.lane_at(point, self.scale)
|
||||
.map(|id| SceneHit {
|
||||
id,
|
||||
role: SceneHitRole::LifelineGuide,
|
||||
})
|
||||
})
|
||||
.or_else(|| {
|
||||
self.lane_at(point).map(|id| SceneHit {
|
||||
id,
|
||||
role: SceneHitRole::LifelineGuide,
|
||||
})
|
||||
})
|
||||
.or_else(|| self.lifecycle.lane_at(point, self.scale))
|
||||
.or_else(|| self.lane_at(point))
|
||||
.or_else(|| {
|
||||
self.lines
|
||||
.iter()
|
||||
@@ -1923,14 +1797,11 @@ impl Scene {
|
||||
< 8. / self.scale
|
||||
})
|
||||
})
|
||||
.map(|line| SceneHit {
|
||||
id: line.id,
|
||||
role: line.role,
|
||||
})
|
||||
.map(|line| line.id)
|
||||
})
|
||||
}
|
||||
|
||||
fn near_sequence_item(&self, point: Point) -> Option<SceneHit> {
|
||||
fn near_sequence_item(&self, point: Point) -> Option<Id> {
|
||||
if !self.scale.is_finite() || self.scale <= 0. {
|
||||
return None;
|
||||
}
|
||||
@@ -1944,32 +1815,17 @@ impl Scene {
|
||||
.windows(2)
|
||||
.map(|p| crate::diagram::distance_to_segment(point, p[0], p[1]))
|
||||
.fold(f32::INFINITY, f32::min);
|
||||
(
|
||||
SceneHit {
|
||||
id: line.id,
|
||||
role: line.role,
|
||||
},
|
||||
distance,
|
||||
)
|
||||
(line.id, distance)
|
||||
});
|
||||
// Compare broad message and lifecycle-marker tolerance together after
|
||||
// exact shapes, so dense minimum-Fit rows choose the nearer item.
|
||||
self.lifecycle
|
||||
.nearest_marker(point)
|
||||
.map(|(id, distance)| {
|
||||
(
|
||||
SceneHit {
|
||||
id,
|
||||
role: SceneHitRole::LifecycleMarker,
|
||||
},
|
||||
distance,
|
||||
)
|
||||
})
|
||||
.into_iter()
|
||||
.chain(messages)
|
||||
.filter(|(_, distance)| *distance <= 8. / self.scale)
|
||||
.min_by(|a, b| a.1.total_cmp(&b.1).then_with(|| a.0.id.cmp(&b.0.id)))
|
||||
.map(|(hit, _)| hit)
|
||||
.min_by(|a, b| a.1.total_cmp(&b.1).then_with(|| a.0.cmp(&b.0)))
|
||||
.map(|(id, _)| id)
|
||||
}
|
||||
}
|
||||
impl canvas::Program<Message> for Scene {
|
||||
@@ -1997,33 +1853,15 @@ impl canvas::Program<Message> for Scene {
|
||||
// captured insertion slot belongs to the previous view, even if the
|
||||
// pointer itself did not move and the semantic context is unchanged.
|
||||
if state.bounds.is_some_and(|previous| previous != bounds) {
|
||||
let cancelled = state.cancel_spacing();
|
||||
state.cancel();
|
||||
state.pointer = None;
|
||||
state.bounds = Some(bounds);
|
||||
if cancelled.is_some() {
|
||||
return cancelled;
|
||||
}
|
||||
}
|
||||
state.bounds = Some(bounds);
|
||||
if (!editable || !self.coordinate_input)
|
||||
&& let Some(cancelled) = state.cancel_spacing()
|
||||
{
|
||||
return Some(cancelled);
|
||||
if !editable {
|
||||
state.cancel();
|
||||
}
|
||||
// The viewport masks input outside its visible canvas bounds.
|
||||
let visible = cursor.position().is_some();
|
||||
if !visible
|
||||
&& matches!(state.press, Some(SequencePress::Spacing { .. }))
|
||||
&& matches!(
|
||||
event,
|
||||
canvas::Event::Mouse(
|
||||
mouse::Event::CursorMoved { .. }
|
||||
| mouse::Event::ButtonReleased(mouse::Button::Left)
|
||||
)
|
||||
)
|
||||
{
|
||||
return state.cancel_spacing();
|
||||
}
|
||||
if !visible
|
||||
&& matches!(
|
||||
event,
|
||||
@@ -2042,7 +1880,7 @@ impl canvas::Program<Message> for Scene {
|
||||
| SequencePress::Reorder { start, moved, .. } => {
|
||||
*moved |= position.distance(*start) >= 3.
|
||||
}
|
||||
SequencePress::Occurrence { .. } | SequencePress::Spacing { .. } => {}
|
||||
SequencePress::Occurrence { .. } => {}
|
||||
}
|
||||
}
|
||||
mouse::Cursor::Available(*position)
|
||||
@@ -2051,9 +1889,9 @@ impl canvas::Program<Message> for Scene {
|
||||
| canvas::Event::Window(iced::window::Event::Resized(_))
|
||||
| canvas::Event::Mouse(mouse::Event::CursorLeft)
|
||||
| canvas::Event::Window(iced::window::Event::Unfocused) => {
|
||||
let cancelled = state.cancel_spacing();
|
||||
state.cancel();
|
||||
state.pointer = None;
|
||||
return cancelled.or_else(|| Some(Action::request_redraw()));
|
||||
return Some(Action::request_redraw());
|
||||
}
|
||||
canvas::Event::Mouse(
|
||||
mouse::Event::ButtonPressed(_) | mouse::Event::ButtonReleased(_),
|
||||
@@ -2066,9 +1904,8 @@ impl canvas::Program<Message> for Scene {
|
||||
key: iced::keyboard::Key::Named(iced::keyboard::key::Named::Escape),
|
||||
..
|
||||
}) if state.source.is_some() || state.press.is_some() => {
|
||||
return state
|
||||
.cancel_spacing()
|
||||
.or_else(|| Some(Action::request_redraw().and_capture()));
|
||||
state.cancel();
|
||||
return Some(Action::request_redraw().and_capture());
|
||||
}
|
||||
_ => cursor,
|
||||
};
|
||||
@@ -2088,14 +1925,6 @@ impl canvas::Program<Message> for Scene {
|
||||
if !editable {
|
||||
return None;
|
||||
}
|
||||
if !self.coordinate_input {
|
||||
return self.hit(point).map(|id| {
|
||||
Action::publish(Message::ScenarioCanvas(CanvasEvent::Select(
|
||||
context, id,
|
||||
)))
|
||||
.and_capture()
|
||||
});
|
||||
}
|
||||
if let CanvasTool::Message(_) = tool {
|
||||
let first = state.source.is_none();
|
||||
let (source, slot) = state.source.or_else(|| {
|
||||
@@ -2122,48 +1951,6 @@ impl canvas::Program<Message> for Scene {
|
||||
});
|
||||
return Some(Action::request_redraw().and_capture());
|
||||
}
|
||||
if matches!(
|
||||
context.representation,
|
||||
scenario_layout::Representation::Saved { .. }
|
||||
) {
|
||||
let hit = self.hit_item(point)?;
|
||||
let target = match hit.role {
|
||||
SceneHitRole::LifelineHeader => {
|
||||
Some(scenario::spacing::Target::Lane(hit.id))
|
||||
}
|
||||
SceneHitRole::MessageBody | SceneHitRole::MessageLabel => {
|
||||
Some(scenario::spacing::Target::Message(hit.id))
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
if let Some((target, stamp)) = target.zip(self.spacing_stamp)
|
||||
&& stamp.context == context
|
||||
{
|
||||
let token = Id::new_v4();
|
||||
state.press = Some(SequencePress::Spacing { stamp, token });
|
||||
return Some(
|
||||
Action::publish(Message::ScenarioCanvas(CanvasEvent::Spacing(
|
||||
scenario::spacing::Event::Begin {
|
||||
stamp,
|
||||
token,
|
||||
target,
|
||||
press_screen: cursor.position()?,
|
||||
canvas_bounds: bounds,
|
||||
scale: self.scale,
|
||||
pan: self.camera_pan,
|
||||
},
|
||||
)))
|
||||
.and_capture(),
|
||||
);
|
||||
}
|
||||
// Saved spacing never silently changes the shared Scenario order.
|
||||
return Some(
|
||||
Action::publish(Message::ScenarioCanvas(CanvasEvent::Select(
|
||||
context, hit.id,
|
||||
)))
|
||||
.and_capture(),
|
||||
);
|
||||
}
|
||||
if let Some(occurrence) = self
|
||||
.hit(point)
|
||||
.filter(|id| self.rows.contains_key(id))
|
||||
@@ -2193,22 +1980,6 @@ impl canvas::Program<Message> for Scene {
|
||||
let press = state.press.take()?;
|
||||
let context = context?;
|
||||
match press {
|
||||
SequencePress::Spacing { stamp, token } => {
|
||||
state.source = None;
|
||||
let event = if world.is_some() {
|
||||
scenario::spacing::Event::Finish {
|
||||
stamp,
|
||||
token,
|
||||
screen: cursor.position()?,
|
||||
}
|
||||
} else {
|
||||
scenario::spacing::Event::Cancel { stamp, token }
|
||||
};
|
||||
return Some(
|
||||
Action::publish(Message::ScenarioCanvas(CanvasEvent::Spacing(event)))
|
||||
.and_capture(),
|
||||
);
|
||||
}
|
||||
SequencePress::Occurrence {
|
||||
tool: captured,
|
||||
slot,
|
||||
@@ -2300,18 +2071,6 @@ impl canvas::Program<Message> for Scene {
|
||||
Some(Action::request_redraw().and_capture())
|
||||
}
|
||||
canvas::Event::Mouse(mouse::Event::CursorMoved { .. }) if context.is_some() => {
|
||||
if let Some(SequencePress::Spacing { stamp, token }) = state.press {
|
||||
return Some(
|
||||
Action::publish(Message::ScenarioCanvas(CanvasEvent::Spacing(
|
||||
scenario::spacing::Event::Move {
|
||||
stamp,
|
||||
token,
|
||||
screen: cursor.position()?,
|
||||
},
|
||||
)))
|
||||
.and_capture(),
|
||||
);
|
||||
}
|
||||
Some(Action::request_redraw())
|
||||
}
|
||||
_ => None,
|
||||
@@ -2493,10 +2252,7 @@ impl canvas::Program<Message> for Scene {
|
||||
self.lifecycle
|
||||
.draw_markers(&mut f, self.selected, self.scale, self.camera_pan);
|
||||
if let Some((context, tool, editable)) = self.interaction {
|
||||
let active = editable
|
||||
&& self.coordinate_input
|
||||
&& state.context == Some(context)
|
||||
&& state.tool == tool;
|
||||
let active = editable && state.context == Some(context) && state.tool == tool;
|
||||
let point = cursor.position_in(bounds).map(|p| {
|
||||
Point::new(
|
||||
(p.x - self.camera_pan.x) / self.scale,
|
||||
@@ -2512,12 +2268,7 @@ impl canvas::Program<Message> for Scene {
|
||||
}
|
||||
});
|
||||
if editable
|
||||
&& self.coordinate_input
|
||||
&& tool == scenario::CanvasTool::Select
|
||||
&& matches!(
|
||||
context.representation,
|
||||
scenario_layout::Representation::Derived { .. }
|
||||
)
|
||||
&& let Some(handle) = self.reorder_handle()
|
||||
{
|
||||
f.fill_rectangle(handle.position(), handle.size(), style::TEAL);
|
||||
|
||||
@@ -50,7 +50,7 @@ pub fn controls<'a>(
|
||||
tooltip::Position::Bottom),
|
||||
control("Fit", "Fit", Some(zoom(None))),
|
||||
control("ZoomOut", "−", Some(zoom(Some(scale / 1.25)))),
|
||||
text(zoom_label(scale)).size(12),
|
||||
text(format!("{:.0}%", scale * 100.)).size(12),
|
||||
control("ZoomIn", "+", Some(zoom(Some(scale * 1.25)))),
|
||||
control("ActualSize", "100%", Some(zoom(Some(1.)))),
|
||||
].spacing(4).align_y(iced::Center).into()
|
||||
@@ -58,7 +58,6 @@ pub fn controls<'a>(
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct Scope {
|
||||
pub(crate) scenario_view: Option<(super::scenario_layout::Representation, Id)>,
|
||||
pub document: Id,
|
||||
pub owner: Id,
|
||||
pub revision: u64,
|
||||
@@ -70,7 +69,6 @@ impl Scope {
|
||||
Some(Self {
|
||||
document: context.document,
|
||||
owner: context.scenario,
|
||||
scenario_view: Some((context.representation, context.visit)),
|
||||
revision: context.revision,
|
||||
epoch: app.camera_epoch,
|
||||
})
|
||||
@@ -79,7 +77,6 @@ impl Scope {
|
||||
Some(Self {
|
||||
document: context.document,
|
||||
owner: context.owner,
|
||||
scenario_view: None,
|
||||
revision: context.revision,
|
||||
epoch: app.camera_epoch,
|
||||
})
|
||||
@@ -99,8 +96,8 @@ impl Scope {
|
||||
|
||||
pub fn control_id(self, name: &str) -> iced::advanced::widget::Id {
|
||||
iced::advanced::widget::Id::from(format!(
|
||||
"behavior-control:{}:{}:{}:{:?}:{name}",
|
||||
self.document, self.owner, self.revision, self.scenario_view
|
||||
"behavior-control:{}:{}:{}:{name}",
|
||||
self.document, self.owner, self.revision
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -134,20 +131,6 @@ pub enum Event {
|
||||
pub use focus::{focus_task, root as focus_root};
|
||||
/// Fold relative input in event order. The base scale is used only on leaving Fit.
|
||||
pub fn change(pan: &mut Vector, zoom: &mut Option<f32>, fit: &mut bool, event: Event) -> bool {
|
||||
change_with_minimum(pan, zoom, fit, event, 0.05)
|
||||
}
|
||||
|
||||
/// Scenario extents can require scales below the topology canvas's 5% floor.
|
||||
pub(super) fn change_with_minimum(
|
||||
pan: &mut Vector,
|
||||
zoom: &mut Option<f32>,
|
||||
fit: &mut bool,
|
||||
event: Event,
|
||||
minimum: f32,
|
||||
) -> bool {
|
||||
if !minimum.is_finite() || minimum <= 0. || minimum > 3. {
|
||||
return false;
|
||||
}
|
||||
match event {
|
||||
Event::Pan(delta) if delta.x.is_finite() && delta.y.is_finite() => {
|
||||
let next = *pan + delta;
|
||||
@@ -167,10 +150,7 @@ pub(super) fn change_with_minimum(
|
||||
&& at.y.is_finite() =>
|
||||
{
|
||||
let old = if *fit { base } else { zoom.unwrap_or(base) };
|
||||
if !old.is_finite() || old <= 0. {
|
||||
return false;
|
||||
}
|
||||
let next = (old * factor).clamp(minimum, 3.);
|
||||
let next = (old * factor).clamp(0.05, 3.);
|
||||
if old == next {
|
||||
return false;
|
||||
}
|
||||
@@ -188,51 +168,6 @@ pub(super) fn change_with_minimum(
|
||||
}
|
||||
}
|
||||
|
||||
fn zoom_label(scale: f32) -> String {
|
||||
let percent = f64::from(scale) * 100.;
|
||||
if !percent.is_finite() || percent <= 0. {
|
||||
return "—".into();
|
||||
}
|
||||
if percent >= 1. {
|
||||
format!("{percent:.0}%")
|
||||
} else if percent >= 0.01 {
|
||||
format!("{percent:.3}%")
|
||||
} else {
|
||||
format!("{percent:.2e}%")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod camera_policy_tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn topology_retains_five_percent_floor() {
|
||||
let (mut pan, mut zoom, mut fit) = (Vector::ZERO, Some(0.06), false);
|
||||
assert!(change(
|
||||
&mut pan,
|
||||
&mut zoom,
|
||||
&mut fit,
|
||||
Event::Zoom {
|
||||
factor: 0.1,
|
||||
at: Point::ORIGIN,
|
||||
base: 0.06,
|
||||
}
|
||||
));
|
||||
assert_eq!(zoom, Some(0.05));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tiny_zoom_label_is_nonzero_and_changes_with_zoom() {
|
||||
assert_eq!(zoom_label(1.), "100%");
|
||||
assert_eq!(zoom_label(0.05), "5%");
|
||||
assert_eq!(zoom_label(0.00034193), "0.034%");
|
||||
assert_eq!(zoom_label(0.00034193 * 1.25), "0.043%");
|
||||
assert_eq!(zoom_label(1e-7), "1.00e-5%");
|
||||
assert_ne!(zoom_label(f32::from_bits(1)), "0%");
|
||||
}
|
||||
}
|
||||
|
||||
/// Constant-width labelled palette. Arming a tool never reallocates the canvas.
|
||||
pub fn palette<'a>(
|
||||
scope: Scope,
|
||||
|
||||
@@ -368,7 +368,6 @@ fn relative_camera_zoom_keeps_the_cursor_world_point_and_rejects_nonfinite_input
|
||||
fn viewport_ordered_batch_uses_each_event_position_and_cancels_before_camera_motion() {
|
||||
use iced::widget::Space;
|
||||
let scope = Scope {
|
||||
scenario_view: None,
|
||||
document: Id::new_v4(),
|
||||
owner: Id::new_v4(),
|
||||
revision: 2,
|
||||
@@ -428,7 +427,6 @@ pub(crate) fn scope(app: &App) -> Scope {
|
||||
Scope {
|
||||
document: context.document,
|
||||
owner: context.scenario,
|
||||
scenario_view: Some((context.representation, context.visit)),
|
||||
revision: context.revision,
|
||||
epoch: app.camera_epoch,
|
||||
}
|
||||
@@ -437,7 +435,6 @@ pub(crate) fn scope(app: &App) -> Scope {
|
||||
Scope {
|
||||
document: context.document,
|
||||
owner: context.owner,
|
||||
scenario_view: None,
|
||||
revision: context.revision,
|
||||
epoch: app.camera_epoch,
|
||||
}
|
||||
|
||||
@@ -893,14 +893,11 @@ fn contextual_source_empty_palette_lifeline_cannot_open_a_previous_owner_or_laye
|
||||
.add_element(Kind::Scenario, Layer::Oa, "Second scenario", None)
|
||||
.unwrap();
|
||||
let mut app = App::with_project(p.clone());
|
||||
// Capture the context created by actual navigation, including its visit.
|
||||
// Merely assigning active_owner/selected does not mount a Scenario anymore.
|
||||
let _ = app.update(Message::Select(a));
|
||||
let _ = app.update(Message::Page(Page::Behavior));
|
||||
app.page = Page::Behavior;
|
||||
app.layer = Layer::Oa;
|
||||
app.behavior.active_owner = Some(a);
|
||||
app.selected = a;
|
||||
let context = app.scenario_context().unwrap();
|
||||
assert_eq!(context.scenario, a);
|
||||
assert!(!context.visit.is_nil());
|
||||
let snapshot = app.document.snapshot();
|
||||
let source = app.document.bundle().clone();
|
||||
let begin = |context| scenario::CanvasEvent::BeginOccurrence {
|
||||
context,
|
||||
@@ -911,40 +908,23 @@ fn contextual_source_empty_palette_lifeline_cannot_open_a_previous_owner_or_laye
|
||||
},
|
||||
lifeline: None,
|
||||
};
|
||||
let _ = app.update(Message::Select(b));
|
||||
let second = app.scenario_context().unwrap();
|
||||
assert_eq!(second.scenario, b);
|
||||
assert_ne!(second.visit, context.visit);
|
||||
app.behavior.active_owner = Some(b);
|
||||
app.selected = b;
|
||||
let _ = app.update(Message::ScenarioCanvas(begin(context)));
|
||||
assert!(!app.behavior.has_pending());
|
||||
assert_eq!(app.project(), &p);
|
||||
|
||||
let _ = app.update(Message::Select(a));
|
||||
let before_layer_change = app.scenario_context().unwrap();
|
||||
assert_eq!(before_layer_change.scenario, a);
|
||||
assert_ne!(before_layer_change.visit, context.visit);
|
||||
let _ = app.update(Message::Layer(Layer::Sa));
|
||||
assert_eq!(app.layer, Layer::Sa);
|
||||
assert!(app.scenario_context().is_none());
|
||||
let _ = app.update(Message::ScenarioCanvas(begin(before_layer_change)));
|
||||
app.behavior.active_owner = Some(a);
|
||||
app.selected = a;
|
||||
app.layer = Layer::Sa;
|
||||
let _ = app.update(Message::ScenarioCanvas(begin(context)));
|
||||
assert!(!app.behavior.has_pending());
|
||||
|
||||
let _ = app.update(Message::Layer(Layer::Oa));
|
||||
let _ = app.update(Message::Select(a));
|
||||
app.layer = Layer::Oa;
|
||||
let current = app.scenario_context().unwrap();
|
||||
assert_eq!(current.scenario, a);
|
||||
assert_ne!(current.visit, before_layer_change.visit);
|
||||
// Returning to the same owner/layer must not revive either retired packet.
|
||||
for retired in [context, before_layer_change] {
|
||||
let _ = app.update(Message::ScenarioCanvas(begin(retired)));
|
||||
assert!(!app.behavior.has_pending());
|
||||
}
|
||||
assert!(std::sync::Arc::ptr_eq(&snapshot, &app.document.snapshot()));
|
||||
let _ = app.update(Message::ScenarioCanvas(begin(current)));
|
||||
assert_eq!(app.behavior.pending_owner(), Some(a));
|
||||
assert_eq!(app.project(), &p);
|
||||
assert_eq!(app.document.bundle(), &source);
|
||||
assert!(!app.document.can_undo() && !app.document.can_redo());
|
||||
assert!(!app.document.can_undo());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -4,28 +4,12 @@ use super::topology::{occurrence, unique_batch};
|
||||
use super::*;
|
||||
use iced::widget::{Column, column, text_input};
|
||||
use std::{cell::RefCell, collections::BTreeSet};
|
||||
mod camera;
|
||||
pub(crate) mod focus;
|
||||
pub(crate) mod spacing;
|
||||
use super::scenario_layout::{
|
||||
Representation,
|
||||
presentation::{self, ScenarioPresentation},
|
||||
};
|
||||
#[cfg(test)]
|
||||
mod presentation_tests;
|
||||
mod usage;
|
||||
mod workspace;
|
||||
pub(crate) use workspace::NAME_INPUT;
|
||||
pub use workspace::{Shelf, view};
|
||||
|
||||
// A picker may select the Saved diagram record itself. Another view of the
|
||||
// same Scenario is not the property target of this displayed representation.
|
||||
pub(crate) fn properties_target(p: &Project, context: Context, id: Id) -> bool {
|
||||
super::selected_behavior(p, id) == Some(context.scenario)
|
||||
|| matches!(context.representation, Representation::Saved { diagram } if diagram == id)
|
||||
&& presentation::checked_owner(p, context.representation) == Some(context.scenario)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "scenario_operation_tests.rs"]
|
||||
mod operation_tests;
|
||||
@@ -87,8 +71,6 @@ impl std::fmt::Display for MessageStyle {
|
||||
pub struct Context {
|
||||
pub document: Id,
|
||||
pub scenario: Id,
|
||||
pub representation: Representation,
|
||||
pub visit: Id,
|
||||
pub revision: u64,
|
||||
pub epoch: u64,
|
||||
}
|
||||
@@ -115,7 +97,6 @@ impl std::fmt::Display for CanvasTool {
|
||||
}
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum CanvasEvent {
|
||||
Spacing(spacing::Event),
|
||||
Scrolled(Context, ScrollArea, iced::Vector),
|
||||
Restored(Context, Id, ScrollArea, iced::Vector),
|
||||
Viewport(Context, Size),
|
||||
@@ -124,11 +105,9 @@ pub enum CanvasEvent {
|
||||
Camera(Context, u64, super::canvas_workspace::Event),
|
||||
Focus(Context),
|
||||
Shelf(Context, Shelf),
|
||||
Properties(Context, Id),
|
||||
OpenUse(Context, Id),
|
||||
Back(Context),
|
||||
Choose(Context, CanvasTool),
|
||||
Representation(Context, Representation),
|
||||
Select(Context, Id),
|
||||
Begin {
|
||||
context: Context,
|
||||
@@ -157,7 +136,6 @@ pub enum ScrollArea {
|
||||
impl CanvasEvent {
|
||||
pub fn context(&self) -> Context {
|
||||
match self {
|
||||
Self::Spacing(event) => event.stamp().context,
|
||||
Self::Scrolled(context, _, _)
|
||||
| Self::Restored(context, ..)
|
||||
| Self::Viewport(context, _)
|
||||
@@ -166,11 +144,9 @@ impl CanvasEvent {
|
||||
| Self::Camera(context, ..)
|
||||
| Self::Focus(context)
|
||||
| Self::Shelf(context, _)
|
||||
| Self::Properties(context, _)
|
||||
| Self::OpenUse(context, _)
|
||||
| Self::Back(context)
|
||||
| Self::Choose(context, _)
|
||||
| Self::Representation(context, _)
|
||||
| Self::Select(context, _)
|
||||
| Self::Begin { context, .. }
|
||||
| Self::BeginOccurrence { context, .. }
|
||||
@@ -227,7 +203,6 @@ pub enum ValueSection {
|
||||
const VALUE_PAGE_SIZE: usize = 24;
|
||||
#[derive(Default)]
|
||||
pub struct State {
|
||||
spacing: Option<spacing::controller::Session>,
|
||||
draft: Option<Draft>,
|
||||
form_session: Id,
|
||||
form_mount: Id,
|
||||
@@ -243,7 +218,6 @@ const CALLER_LIMIT: usize = 32;
|
||||
pub(crate) struct Caller {
|
||||
document: Id,
|
||||
pub owner: Id,
|
||||
pub representation: Representation,
|
||||
pub occurrence: Id,
|
||||
target: Id,
|
||||
tool: CanvasTool,
|
||||
@@ -253,8 +227,6 @@ pub(crate) struct Caller {
|
||||
struct DetailsRestore {
|
||||
document: Id,
|
||||
owner: Id,
|
||||
representation: Representation,
|
||||
visit: Id,
|
||||
token: Id,
|
||||
offset: iced::Vector,
|
||||
}
|
||||
@@ -262,8 +234,6 @@ struct DetailsRestore {
|
||||
pub(super) struct ScrollRestore {
|
||||
pub document: Id,
|
||||
pub owner: Id,
|
||||
pub representation: Representation,
|
||||
pub visit: Id,
|
||||
pub token: Id,
|
||||
pub offset: iced::Vector,
|
||||
}
|
||||
@@ -357,149 +327,42 @@ impl State {
|
||||
}
|
||||
|
||||
pub(crate) fn enter(&mut self, document: Id, owner: Id) {
|
||||
self.enter_representation(document, owner, Representation::Derived { owner });
|
||||
}
|
||||
/// App validates requested identity with checked_owner before entering.
|
||||
pub(crate) fn enter_representation(
|
||||
&mut self,
|
||||
document: Id,
|
||||
owner: Id,
|
||||
representation: Representation,
|
||||
) -> bool {
|
||||
if matches!(representation, Representation::Derived { owner: requested } if requested != owner)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
let changed = self.presentation.identity != Some((document, owner))
|
||||
|| self.presentation.representation != Some(representation);
|
||||
if changed {
|
||||
if self.presentation.identity != Some((document, owner)) {
|
||||
self.presentation = workspace::Presentation {
|
||||
identity: Some((document, owner)),
|
||||
representation: Some(representation),
|
||||
focused: self.presentation.focused,
|
||||
fit: matches!(representation, Representation::Saved { .. }),
|
||||
..Default::default()
|
||||
};
|
||||
self.details_offset = iced::Vector::ZERO;
|
||||
self.canvas_tool = Some((owner, CanvasTool::Select));
|
||||
}
|
||||
if changed || self.presentation.visit.is_nil() {
|
||||
self.spacing = None;
|
||||
self.presentation.visit = Id::new_v4();
|
||||
self.restore = None;
|
||||
return true;
|
||||
}
|
||||
false
|
||||
}
|
||||
/// Suspend captured events while preserving this destination's camera state.
|
||||
pub(crate) fn leave(&mut self) {
|
||||
self.spacing = None;
|
||||
self.presentation.visit = Id::nil();
|
||||
self.restore = None;
|
||||
}
|
||||
pub(crate) fn forget_view(&mut self) {
|
||||
self.spacing = None;
|
||||
self.presentation.identity = None;
|
||||
self.presentation.representation = None;
|
||||
self.presentation.visit = Id::nil();
|
||||
self.restore = None;
|
||||
}
|
||||
pub(crate) fn representation(&self) -> Option<Representation> {
|
||||
self.presentation.representation
|
||||
}
|
||||
pub(crate) fn owner(&self) -> Option<Id> {
|
||||
self.presentation.identity.map(|(_, owner)| owner)
|
||||
}
|
||||
pub(crate) fn context(
|
||||
&self,
|
||||
document: Id,
|
||||
owner: Id,
|
||||
revision: u64,
|
||||
epoch: u64,
|
||||
) -> Option<Context> {
|
||||
if self.presentation.identity != Some((document, owner)) || self.presentation.visit.is_nil()
|
||||
{
|
||||
return None;
|
||||
}
|
||||
Some(Context {
|
||||
document,
|
||||
scenario: owner,
|
||||
representation: self.representation()?,
|
||||
visit: self.presentation.visit,
|
||||
revision,
|
||||
epoch,
|
||||
})
|
||||
}
|
||||
pub(crate) fn display(
|
||||
&self,
|
||||
p: &Project,
|
||||
owner: Id,
|
||||
selected: Id,
|
||||
) -> Option<ScenarioPresentation> {
|
||||
let (_, current_owner) = self.presentation.identity?;
|
||||
let representation = self.representation()?;
|
||||
(current_owner == owner).then(|| presentation::present(p, representation, selected))
|
||||
}
|
||||
pub(crate) fn coordinate_input(&self, p: &Project, context: Context) -> bool {
|
||||
self.context(
|
||||
context.document,
|
||||
context.scenario,
|
||||
context.revision,
|
||||
context.epoch,
|
||||
) == Some(context)
|
||||
&& self
|
||||
.display(p, context.scenario, context.scenario)
|
||||
.is_some_and(|shown| shown.capabilities().coordinate_input)
|
||||
}
|
||||
pub(crate) fn viewport(&mut self, size: Size) -> bool {
|
||||
self.presentation.viewport(size)
|
||||
}
|
||||
pub(crate) fn camera(
|
||||
&mut self,
|
||||
project: &Project,
|
||||
owner: Id,
|
||||
event: super::canvas_workspace::Event,
|
||||
) -> bool {
|
||||
let Some(bounds) = self
|
||||
.display(project, owner, owner)
|
||||
.and_then(|shown| shown.bounds())
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
pub(crate) fn camera(&mut self, event: super::canvas_workspace::Event) -> bool {
|
||||
let p = &mut self.presentation;
|
||||
camera::change(
|
||||
&mut p.pan,
|
||||
&mut p.zoom,
|
||||
&mut p.fit,
|
||||
p.viewport,
|
||||
bounds,
|
||||
event,
|
||||
)
|
||||
super::canvas_workspace::change(&mut p.pan, &mut p.zoom, &mut p.fit, event)
|
||||
}
|
||||
pub(crate) fn zoom(&mut self, scale: Option<f32>) -> bool {
|
||||
self.presentation.zoom(scale)
|
||||
}
|
||||
pub(crate) fn camera_zoom(&mut self, p: &Project, owner: Id, zoom: Option<f32>) -> bool {
|
||||
let Some(bounds) = self
|
||||
.display(p, owner, owner)
|
||||
.and_then(|shown| shown.bounds())
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
let size = Scene::sequence(p, owner, owner).size;
|
||||
let old = self.presentation.scale(size);
|
||||
if let Some(next) = zoom {
|
||||
let current = self.presentation.camera(bounds);
|
||||
let viewport = self.presentation.viewport.unwrap_or(Size::new(500., 300.));
|
||||
self.camera(
|
||||
p,
|
||||
owner,
|
||||
super::canvas_workspace::Event::Zoom {
|
||||
factor: next / current.scale,
|
||||
at: Point::new(viewport.width / 2., viewport.height / 2.),
|
||||
base: current.scale,
|
||||
},
|
||||
)
|
||||
self.camera(super::canvas_workspace::Event::Zoom {
|
||||
factor: next / old,
|
||||
at: Point::new(viewport.width / 2., viewport.height / 2.),
|
||||
base: old,
|
||||
})
|
||||
} else {
|
||||
self.zoom(None)
|
||||
self.zoom(None);
|
||||
let fitted = self.presentation.scale(size);
|
||||
self.zoom(Some(fitted));
|
||||
self.presentation.pan = iced::Vector::ZERO;
|
||||
true
|
||||
}
|
||||
}
|
||||
pub(crate) fn focused(&self) -> bool {
|
||||
@@ -511,12 +374,6 @@ impl State {
|
||||
pub(crate) fn toggle_shelf(&mut self, shelf: Shelf) {
|
||||
self.presentation.shelf = (self.presentation.shelf != Some(shelf)).then_some(shelf);
|
||||
}
|
||||
pub(crate) fn show_properties(&mut self) {
|
||||
// Properties belong to the inspector. Restore that panel and dismiss
|
||||
// the competing outline without replacing this view or its camera.
|
||||
self.presentation.focused = false;
|
||||
self.presentation.shelf = None;
|
||||
}
|
||||
pub(crate) fn open_use(
|
||||
&mut self,
|
||||
p: &Project,
|
||||
@@ -533,7 +390,6 @@ impl State {
|
||||
self.return_to.push(Caller {
|
||||
document: context.document,
|
||||
owner: context.scenario,
|
||||
representation: context.representation,
|
||||
occurrence,
|
||||
target,
|
||||
tool: self.canvas_tool(context.scenario),
|
||||
@@ -548,7 +404,6 @@ impl State {
|
||||
fn valid_caller(p: &Project, context: Context, frame: &Caller) -> bool {
|
||||
frame.document == context.document
|
||||
&& frame.target == context.scenario
|
||||
&& presentation::checked_owner(p, frame.representation) == Some(frame.owner)
|
||||
&& referenced_scenario(p, frame.owner, frame.occurrence) == Some(frame.target)
|
||||
}
|
||||
pub(super) fn can_back(&self, p: &Project, context: Context) -> bool {
|
||||
@@ -565,23 +420,16 @@ impl State {
|
||||
None
|
||||
}
|
||||
pub(crate) fn restore_caller(&mut self, context: Context, frame: Caller) {
|
||||
if context.document != frame.document
|
||||
|| context.scenario != frame.owner
|
||||
|| context.representation != frame.representation
|
||||
{
|
||||
if context.document != frame.document || context.scenario != frame.owner {
|
||||
return;
|
||||
}
|
||||
self.canvas_tool = Some((frame.owner, frame.tool));
|
||||
self.details_offset = frame.details_offset;
|
||||
self.presentation = frame.presentation;
|
||||
self.presentation.identity = Some((context.document, context.scenario));
|
||||
self.presentation.representation = Some(frame.representation);
|
||||
self.presentation.visit = context.visit;
|
||||
self.restore = Some(DetailsRestore {
|
||||
document: context.document,
|
||||
owner: frame.owner,
|
||||
representation: frame.representation,
|
||||
visit: context.visit,
|
||||
token: Id::new_v4(),
|
||||
offset: frame.details_offset,
|
||||
});
|
||||
@@ -591,17 +439,13 @@ impl State {
|
||||
context: Context,
|
||||
ScrollArea::Page: ScrollArea,
|
||||
) -> Option<ScrollRestore> {
|
||||
let restore = self.restore.as_ref().filter(|r| {
|
||||
r.document == context.document
|
||||
&& r.owner == context.scenario
|
||||
&& r.representation == context.representation
|
||||
&& r.visit == context.visit
|
||||
})?;
|
||||
let restore = self
|
||||
.restore
|
||||
.as_ref()
|
||||
.filter(|r| r.document == context.document && r.owner == context.scenario)?;
|
||||
Some(ScrollRestore {
|
||||
document: restore.document,
|
||||
owner: restore.owner,
|
||||
representation: restore.representation,
|
||||
visit: restore.visit,
|
||||
token: restore.token,
|
||||
offset: restore.offset,
|
||||
})
|
||||
@@ -614,11 +458,7 @@ impl State {
|
||||
offset: iced::Vector,
|
||||
) -> bool {
|
||||
if !self.restore.as_ref().is_some_and(|r| {
|
||||
r.document == context.document
|
||||
&& r.owner == context.scenario
|
||||
&& r.representation == context.representation
|
||||
&& r.visit == context.visit
|
||||
&& r.token == token
|
||||
r.document == context.document && r.owner == context.scenario && r.token == token
|
||||
}) {
|
||||
return false;
|
||||
}
|
||||
@@ -2091,8 +1931,6 @@ pub(crate) mod direct_tests {
|
||||
Context {
|
||||
document: Id::new_v4(),
|
||||
scenario: owner,
|
||||
representation: Representation::Derived { owner },
|
||||
visit: Id::new_v4(),
|
||||
revision: 0,
|
||||
epoch: 0,
|
||||
}
|
||||
|
||||
@@ -1,284 +0,0 @@
|
||||
//! Scenario camera policy. Bounds are from the exact displayed presentation,
|
||||
//! including its origin and automatic fallback; no model geometry is authored.
|
||||
use crate::behavior::canvas_workspace::{self, Event};
|
||||
use iced::{Rectangle, Size, Vector};
|
||||
|
||||
pub(super) const MIN_SCALE: f32 = f32::from_bits(1);
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub(super) struct Camera {
|
||||
pub(super) scale: f32,
|
||||
pub(super) pan: Vector,
|
||||
}
|
||||
|
||||
/// Fit never enlarges above 100%. Use f64 intermediates so a valid f32 origin
|
||||
/// and size cannot overflow while finding the center. Unrepresentable cameras
|
||||
/// are refused rather than silently clamped to an unrelated minimum scale.
|
||||
pub(super) fn fit(bounds: Rectangle, viewport: Size) -> Option<Camera> {
|
||||
if [
|
||||
bounds.x,
|
||||
bounds.y,
|
||||
bounds.width,
|
||||
bounds.height,
|
||||
viewport.width,
|
||||
viewport.height,
|
||||
]
|
||||
.iter()
|
||||
.any(|n| !n.is_finite())
|
||||
|| bounds.width < 0.
|
||||
|| bounds.height < 0.
|
||||
|| viewport.width <= 0.
|
||||
|| viewport.height <= 0.
|
||||
{
|
||||
return None;
|
||||
}
|
||||
let width = f64::from(viewport.width);
|
||||
let height = f64::from(viewport.height);
|
||||
let scale = ((width - 2. * (width / 4.).min(8.)) / f64::from(bounds.width).max(1.))
|
||||
.min((height - 2. * (height / 4.).min(8.)) / f64::from(bounds.height).max(1.))
|
||||
.min(1.) as f32;
|
||||
if !scale.is_finite() || scale <= 0. {
|
||||
return None;
|
||||
}
|
||||
let x = width / 2. - (f64::from(bounds.x) + f64::from(bounds.width) / 2.) * f64::from(scale);
|
||||
let y = height / 2. - (f64::from(bounds.y) + f64::from(bounds.height) / 2.) * f64::from(scale);
|
||||
let pan = Vector::new(x as f32, y as f32);
|
||||
(pan.x.is_finite() && pan.y.is_finite()).then_some(Camera { scale, pan })
|
||||
}
|
||||
|
||||
pub(super) fn effective_camera(
|
||||
pan: Vector,
|
||||
zoom: Option<f32>,
|
||||
fitting: bool,
|
||||
viewport: Option<Size>,
|
||||
bounds: Rectangle,
|
||||
) -> Camera {
|
||||
if fitting && let Some(camera) = viewport.and_then(|size| fit(bounds, size)) {
|
||||
return camera;
|
||||
}
|
||||
Camera {
|
||||
scale: zoom.unwrap_or(1.),
|
||||
pan,
|
||||
}
|
||||
}
|
||||
|
||||
/// None preserves Fit as a mode, including before the first viewport arrives.
|
||||
pub(super) fn set_zoom(
|
||||
pan: &mut Vector,
|
||||
zoom: &mut Option<f32>,
|
||||
fitting: &mut bool,
|
||||
scale: Option<f32>,
|
||||
) -> bool {
|
||||
if scale.is_some_and(|value| !value.is_finite() || value <= 0.) {
|
||||
return false;
|
||||
}
|
||||
let next = scale.map(|value| value.min(3.));
|
||||
let next_pan = if scale.is_none() { Vector::ZERO } else { *pan };
|
||||
let changed = *zoom != next || *fitting != scale.is_none() || *pan != next_pan;
|
||||
*zoom = next;
|
||||
*fitting = scale.is_none();
|
||||
*pan = next_pan;
|
||||
changed
|
||||
}
|
||||
|
||||
/// Materialize the visible fitted camera only when a camera gesture succeeds.
|
||||
/// A zero-motion or rejected event preserves the original mode and fields.
|
||||
pub(super) fn change(
|
||||
pan: &mut Vector,
|
||||
zoom: &mut Option<f32>,
|
||||
fitting: &mut bool,
|
||||
viewport: Option<Size>,
|
||||
bounds: Rectangle,
|
||||
event: Event,
|
||||
) -> bool {
|
||||
let camera = effective_camera(*pan, *zoom, *fitting, viewport, bounds);
|
||||
let (mut next_pan, mut next_zoom, mut next_fit) = (camera.pan, Some(camera.scale), false);
|
||||
let event = match event {
|
||||
Event::Zoom { base, .. } if !base.is_finite() || base <= 0. => return false,
|
||||
Event::Zoom { factor, at, .. } => Event::Zoom {
|
||||
factor,
|
||||
at,
|
||||
base: camera.scale,
|
||||
},
|
||||
event => event,
|
||||
};
|
||||
if !canvas_workspace::change_with_minimum(
|
||||
&mut next_pan,
|
||||
&mut next_zoom,
|
||||
&mut next_fit,
|
||||
event,
|
||||
MIN_SCALE,
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
*pan = next_pan;
|
||||
*zoom = next_zoom;
|
||||
*fitting = next_fit;
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use iced::Point;
|
||||
|
||||
fn bounds() -> Rectangle {
|
||||
Rectangle {
|
||||
x: -1_000_160.,
|
||||
y: -200.,
|
||||
width: 2_000_400.,
|
||||
height: 1_000.,
|
||||
}
|
||||
}
|
||||
fn near(actual: f32, expected: f32, tolerance: f32) {
|
||||
assert!(
|
||||
(actual - expected).abs() <= tolerance,
|
||||
"{actual} != {expected}"
|
||||
);
|
||||
}
|
||||
fn projected(camera: Camera, point: Point) -> Point {
|
||||
Point::new(
|
||||
point.x * camera.scale + camera.pan.x,
|
||||
point.y * camera.scale + camera.pan.y,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn negative_origin_fit_contains_independently_known_extremes() {
|
||||
let camera = fit(bounds(), Size::new(700., 500.)).unwrap();
|
||||
near(camera.scale, 0.0003419316, 1e-10);
|
||||
near(camera.pan.x, 349.98633, 0.0001);
|
||||
near(
|
||||
projected(camera, Point::new(-1_000_160., -200.)).x,
|
||||
8.,
|
||||
0.0001,
|
||||
);
|
||||
near(
|
||||
projected(camera, Point::new(1_000_240., 800.)).x,
|
||||
692.,
|
||||
0.0001,
|
||||
);
|
||||
near(projected(camera, Point::new(40., 300.)).y, 250., 0.0001);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fit_remains_active_across_first_and_changed_viewport() {
|
||||
let (mut pan, mut zoom, mut fitting) = (Vector::new(50., 80.), Some(0.8), false);
|
||||
assert!(set_zoom(&mut pan, &mut zoom, &mut fitting, None));
|
||||
let retained = effective_camera(pan, zoom, fitting, Some(Size::new(1200., 500.)), bounds());
|
||||
let actual = effective_camera(pan, zoom, fitting, Some(Size::new(500., 500.)), bounds());
|
||||
assert!(actual.scale < retained.scale);
|
||||
near(
|
||||
projected(actual, Point::new(-1_000_160., -200.)).x,
|
||||
8.,
|
||||
0.0001,
|
||||
);
|
||||
near(
|
||||
projected(actual, Point::new(1_000_240., 800.)).x,
|
||||
492.,
|
||||
0.0001,
|
||||
);
|
||||
assert_eq!((pan, zoom, fitting), (Vector::ZERO, None, true));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tiny_fit_zoom_in_out_preserves_pointer_world_anchor_without_floor_jump() {
|
||||
let size = Size::new(700., 500.);
|
||||
let viewport = Some(size);
|
||||
let start = fit(bounds(), size).unwrap();
|
||||
let (mut pan, mut zoom, mut fitting) = (Vector::ZERO, None, true);
|
||||
let at = Point::new(210., 180.);
|
||||
let world = Point::new(
|
||||
(at.x - start.pan.x) / start.scale,
|
||||
(at.y - start.pan.y) / start.scale,
|
||||
);
|
||||
for factor in [1.25, 0.8] {
|
||||
let prior_scale = zoom.unwrap_or(start.scale);
|
||||
assert!(change(
|
||||
&mut pan,
|
||||
&mut zoom,
|
||||
&mut fitting,
|
||||
viewport,
|
||||
bounds(),
|
||||
Event::Zoom {
|
||||
factor,
|
||||
at,
|
||||
base: start.scale,
|
||||
}
|
||||
));
|
||||
let camera = effective_camera(pan, zoom, fitting, viewport, bounds());
|
||||
near(camera.scale, prior_scale * factor, 1e-10);
|
||||
assert!(camera.scale < 0.001);
|
||||
near(projected(camera, world).x, at.x, 0.0001);
|
||||
near(projected(camera, world).y, at.y, 0.0001);
|
||||
}
|
||||
near(zoom.unwrap(), start.scale, 1e-10);
|
||||
near(pan.x, start.pan.x, 0.0001);
|
||||
assert!(!fitting);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pan_leaves_fit_from_displayed_position_and_zero_motion_preserves_fit() {
|
||||
let size = Size::new(700., 500.);
|
||||
let viewport = Some(size);
|
||||
let (mut pan, mut zoom, mut fitting) = (Vector::ZERO, None, true);
|
||||
for event in [
|
||||
Event::Pan(Vector::ZERO),
|
||||
Event::Zoom {
|
||||
factor: 1.,
|
||||
at: Point::ORIGIN,
|
||||
base: 1.,
|
||||
},
|
||||
] {
|
||||
assert!(!change(
|
||||
&mut pan,
|
||||
&mut zoom,
|
||||
&mut fitting,
|
||||
viewport,
|
||||
bounds(),
|
||||
event
|
||||
));
|
||||
assert_eq!((pan, zoom, fitting), (Vector::ZERO, None, true));
|
||||
}
|
||||
let start = fit(bounds(), size).unwrap();
|
||||
assert!(change(
|
||||
&mut pan,
|
||||
&mut zoom,
|
||||
&mut fitting,
|
||||
viewport,
|
||||
bounds(),
|
||||
Event::Pan(Vector::new(20., -30.))
|
||||
));
|
||||
assert_eq!(pan, start.pan + Vector::new(20., -30.));
|
||||
assert_eq!(zoom, Some(start.scale));
|
||||
assert!(!fitting);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_inputs_are_passive_and_large_finite_bounds_do_not_overflow_center() {
|
||||
assert!(fit(bounds(), Size::new(f32::NAN, 500.)).is_none());
|
||||
let extreme = Rectangle {
|
||||
x: f32::MAX,
|
||||
y: 0.,
|
||||
width: f32::MAX,
|
||||
height: 100.,
|
||||
};
|
||||
let camera = fit(extreme, Size::new(700., 500.)).unwrap();
|
||||
assert!(camera.scale > 0. && camera.scale < 1e-30 && camera.pan.x.is_finite());
|
||||
let (mut pan, mut zoom, mut fitting) = (Vector::ZERO, None, true);
|
||||
assert!(!set_zoom(&mut pan, &mut zoom, &mut fitting, Some(f32::NAN)));
|
||||
assert!(!change(
|
||||
&mut pan,
|
||||
&mut zoom,
|
||||
&mut fitting,
|
||||
Some(Size::new(700., 500.)),
|
||||
bounds(),
|
||||
Event::Zoom {
|
||||
factor: 1.25,
|
||||
at: Point::ORIGIN,
|
||||
base: f32::NAN
|
||||
}
|
||||
));
|
||||
assert_eq!((pan, zoom, fitting), (Vector::ZERO, None, true));
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,6 @@ use std::collections::BTreeMap;
|
||||
pub(crate) struct Stamp {
|
||||
document: ModelId,
|
||||
owner: ModelId,
|
||||
representation: super::Representation,
|
||||
visit: ModelId,
|
||||
revision: u64,
|
||||
session: ModelId,
|
||||
mount: ModelId,
|
||||
@@ -22,8 +20,6 @@ impl Stamp {
|
||||
Self {
|
||||
document: context.document,
|
||||
owner: context.scenario,
|
||||
representation: context.representation,
|
||||
visit: context.visit,
|
||||
revision: context.revision,
|
||||
session,
|
||||
mount,
|
||||
@@ -32,12 +28,10 @@ impl Stamp {
|
||||
}
|
||||
pub(crate) fn name_id(stamp: Stamp) -> Id {
|
||||
Id::from(format!(
|
||||
"{}:{}:{}:{:?}:{}:{}:{}:{}",
|
||||
"{}:{}:{}:{}:{}:{}",
|
||||
super::NAME_INPUT,
|
||||
stamp.document,
|
||||
stamp.owner,
|
||||
stamp.representation,
|
||||
stamp.visit,
|
||||
stamp.revision,
|
||||
stamp.session,
|
||||
stamp.mount
|
||||
|
||||
@@ -1,348 +0,0 @@
|
||||
//! Controller identity and actual presentation input, independent of App routing.
|
||||
use super::*;
|
||||
use oa_core::{Diagram, DiagramLayout, ProjectionKind, ScenarioLanePosition, ScenarioLayout};
|
||||
|
||||
fn saved(p: &mut Project, owner: Id, lanes: &[(Id, f32)]) -> Representation {
|
||||
let id = Id::new_v4();
|
||||
p.diagrams.insert(
|
||||
id,
|
||||
Diagram {
|
||||
id,
|
||||
alias: format!("saved_{}", p.diagrams.len()),
|
||||
name: "Saved scenario".into(),
|
||||
description: String::new(),
|
||||
layer: p.elements[&owner].layer(),
|
||||
projection: ProjectionKind::Scenario { scenario: owner },
|
||||
view_options: Default::default(),
|
||||
nodes: Default::default(),
|
||||
routes: vec![],
|
||||
layout: Some(DiagramLayout::Scenario(ScenarioLayout {
|
||||
lanes: lanes
|
||||
.iter()
|
||||
.map(|&(lifeline, x)| ScenarioLanePosition { lifeline, x })
|
||||
.collect(),
|
||||
messages: vec![],
|
||||
})),
|
||||
},
|
||||
);
|
||||
let errors: Vec<_> = oa_core::validation::validate(p)
|
||||
.into_iter()
|
||||
.filter(|issue| issue.severity == oa_core::validation::Severity::Error)
|
||||
.collect();
|
||||
assert!(errors.is_empty(), "{errors:?}");
|
||||
Representation::Saved { diagram: id }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn saved_visits_distinguish_same_owner_roundtrips_and_suspended_return_without_editing() {
|
||||
let mut f = direct_tests::fixture();
|
||||
let a = saved(&mut f.project, f.owner, &[(f.sender, -500.)]);
|
||||
let b = saved(&mut f.project, f.owner, &[(f.sender, 900.)]);
|
||||
let original = f.project.clone();
|
||||
let document = Id::new_v4();
|
||||
let mut state = State::default();
|
||||
assert!(state.enter_representation(document, f.owner, a));
|
||||
let first = state.context(document, f.owner, 7, 9).unwrap();
|
||||
assert!(!state.enter_representation(document, f.owner, a));
|
||||
assert_eq!(state.context(document, f.owner, 7, 9), Some(first));
|
||||
state.presentation.pan = iced::Vector::new(23., -17.);
|
||||
state.leave();
|
||||
assert_eq!(state.representation(), Some(a));
|
||||
assert_eq!(state.owner(), Some(f.owner));
|
||||
assert!(state.context(document, f.owner, 7, 9).is_none());
|
||||
assert!(state.enter_representation(document, f.owner, a));
|
||||
let returned = state.context(document, f.owner, 7, 9).unwrap();
|
||||
assert_ne!(returned.visit, first.visit);
|
||||
assert_eq!(state.presentation.pan, iced::Vector::new(23., -17.));
|
||||
assert!(state.enter_representation(document, f.owner, b));
|
||||
let middle = state.context(document, f.owner, 7, 9).unwrap();
|
||||
assert!(state.enter_representation(document, f.owner, a));
|
||||
let last = state.context(document, f.owner, 7, 9).unwrap();
|
||||
assert_ne!(last.visit, returned.visit);
|
||||
assert_ne!(last.visit, middle.visit);
|
||||
assert!(!state.coordinate_input(&f.project, first));
|
||||
assert!(state.coordinate_input(&f.project, last));
|
||||
let session = Id::new_v4();
|
||||
let mount = Id::new_v4();
|
||||
assert_ne!(
|
||||
focus::Stamp::new(first, session, mount),
|
||||
focus::Stamp::new(last, session, mount)
|
||||
);
|
||||
assert_eq!(f.project, original);
|
||||
state.forget_view();
|
||||
assert_eq!(state.representation(), None);
|
||||
assert_eq!(state.owner(), None);
|
||||
assert!(state.context(document, f.owner, 7, 9).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn saved_caller_restores_exact_representation_with_fresh_visit_and_rejects_deleted_view() {
|
||||
let (mut project, [a, b, _], [reference, _, _]) = direct_tests::navigation_fixture();
|
||||
let view = saved(&mut project, a, &[]);
|
||||
let original = project.clone();
|
||||
let document = Id::new_v4();
|
||||
let mut state = State::default();
|
||||
state.enter_representation(document, a, view);
|
||||
let initial = state.context(document, a, 0, 0).unwrap();
|
||||
state.presentation.pan = iced::Vector::new(11., 29.);
|
||||
state.details_offset = iced::Vector::new(0., 71.);
|
||||
assert_eq!(state.open_use(&project, initial, reference).unwrap(), b);
|
||||
state.enter(document, b);
|
||||
let callee = state.context(document, b, 0, 0).unwrap();
|
||||
let frame = state.back(&project, callee).unwrap();
|
||||
assert_eq!(frame.representation, view);
|
||||
state.enter_representation(document, a, frame.representation);
|
||||
let returned = state.context(document, a, 0, 0).unwrap();
|
||||
state.restore_caller(returned, frame);
|
||||
assert_ne!(returned.visit, initial.visit);
|
||||
assert_eq!(state.representation(), Some(view));
|
||||
assert_eq!(state.presentation.pan, iced::Vector::new(11., 29.));
|
||||
assert!(state.scroll_restore(initial, ScrollArea::Page).is_none());
|
||||
assert_eq!(
|
||||
state
|
||||
.scroll_restore(returned, ScrollArea::Page)
|
||||
.unwrap()
|
||||
.offset,
|
||||
iced::Vector::new(0., 71.)
|
||||
);
|
||||
assert_eq!(project, original);
|
||||
state.open_use(&project, returned, reference).unwrap();
|
||||
state.enter(document, b);
|
||||
let Representation::Saved { diagram } = view else {
|
||||
unreachable!()
|
||||
};
|
||||
project.diagrams.remove(&diagram);
|
||||
let callee = state.context(document, b, 0, 0).unwrap();
|
||||
assert!(state.back(&project, callee).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn complete_fallback_scene_selects_but_cannot_capture_or_finish_coordinate_gestures() {
|
||||
let mut f = direct_tests::fixture();
|
||||
// Equal authored lane centers are structurally valid, but cannot render a distinct-endpoint call.
|
||||
let rep = saved(
|
||||
&mut f.project,
|
||||
f.owner,
|
||||
&[(f.sender, 900.), (f.receiver, 900.)],
|
||||
);
|
||||
let original = f.project.clone();
|
||||
let mut state = State::default();
|
||||
state.enter_representation(Id::new_v4(), f.owner, rep);
|
||||
let document = state.presentation.identity.unwrap().0;
|
||||
let context = state.context(document, f.owner, 0, 0).unwrap();
|
||||
let shown = state.display(&f.project, f.owner, f.call).unwrap();
|
||||
assert!(matches!(
|
||||
shown.status(),
|
||||
presentation::PresentationStatus::Fallback { .. }
|
||||
));
|
||||
assert!(!state.coordinate_input(&f.project, context));
|
||||
let automatic = presentation::present(
|
||||
&f.project,
|
||||
Representation::Derived { owner: f.owner },
|
||||
f.call,
|
||||
);
|
||||
let automatic = automatic.scene().unwrap();
|
||||
assert_eq!(shown.scene().unwrap().render_lanes, automatic.render_lanes);
|
||||
assert_eq!(shown.scene().unwrap().activations, automatic.activations);
|
||||
assert!(!automatic.activations.is_empty());
|
||||
let mut scene = shown.into_scene().unwrap();
|
||||
scene.coordinate_input = false;
|
||||
let line = scene.lines.iter().find(|line| line.id == f.call).unwrap();
|
||||
let point = Point::new(
|
||||
(line.points[0].x + line.points.last().unwrap().x) / 2.,
|
||||
line.points[0].y,
|
||||
);
|
||||
assert_eq!(scene.hit(point), Some(f.call));
|
||||
let bounds = Rectangle::with_size(Size::new(1600., 1000.));
|
||||
for tool in [
|
||||
CanvasTool::Select,
|
||||
CanvasTool::Message(MessageStyle::CallReply),
|
||||
CanvasTool::Add(Tool::Reuse),
|
||||
] {
|
||||
scene.interaction = Some((context, tool, true));
|
||||
let mut input = SequenceInput::default();
|
||||
let mut messages = vec![];
|
||||
for event in [
|
||||
mouse::Event::CursorMoved { position: point },
|
||||
mouse::Event::ButtonPressed(mouse::Button::Left),
|
||||
mouse::Event::CursorMoved {
|
||||
position: Point::new(point.x, point.y + 100.),
|
||||
},
|
||||
mouse::Event::ButtonReleased(mouse::Button::Left),
|
||||
] {
|
||||
if let Some(message) = canvas::Program::update(
|
||||
&scene,
|
||||
&mut input,
|
||||
&canvas::Event::Mouse(event),
|
||||
bounds,
|
||||
mouse::Cursor::Available(point),
|
||||
)
|
||||
.and_then(|action| action.into_inner().0)
|
||||
{
|
||||
messages.push(message);
|
||||
}
|
||||
}
|
||||
assert_eq!(messages.len(), 1);
|
||||
assert!(
|
||||
matches!(messages[0], Message::ScenarioCanvas(CanvasEvent::Select(c, id)) if c == context && id == f.call)
|
||||
);
|
||||
assert!(input.press.is_none() && input.source.is_none());
|
||||
}
|
||||
// Capture from an actual Ready presentation, then revoke coordinate input
|
||||
// with the complete fallback frame of the same Saved representation.
|
||||
let Representation::Saved { diagram } = rep else {
|
||||
unreachable!()
|
||||
};
|
||||
let mut ready_project = f.project.clone();
|
||||
ready_project.diagrams.get_mut(&diagram).unwrap().layout =
|
||||
Some(DiagramLayout::Scenario(ScenarioLayout::default()));
|
||||
let ready_original = ready_project.clone();
|
||||
let ready = state.display(&ready_project, f.owner, f.call).unwrap();
|
||||
assert!(matches!(
|
||||
ready.status(),
|
||||
presentation::PresentationStatus::Ready
|
||||
));
|
||||
let mut ready_scene = ready.into_scene().unwrap();
|
||||
let line = ready_scene
|
||||
.lines
|
||||
.iter()
|
||||
.find(|line| line.id == f.call)
|
||||
.unwrap();
|
||||
let ready_point = Point::new(
|
||||
(line.points[0].x + line.points.last().unwrap().x) / 2.,
|
||||
line.points[0].y,
|
||||
);
|
||||
let hit = ready_scene.hit_item(ready_point).unwrap();
|
||||
assert_eq!(hit.id, f.call);
|
||||
assert_eq!(hit.role, SceneHitRole::MessageBody);
|
||||
let stamp = spacing::Stamp {
|
||||
context,
|
||||
camera_epoch: 17,
|
||||
};
|
||||
ready_scene.coordinate_input = true;
|
||||
ready_scene.interaction = Some((context, CanvasTool::Select, true));
|
||||
ready_scene.spacing_stamp = Some(stamp);
|
||||
let mut input = SequenceInput::default();
|
||||
let begin = canvas::Program::update(
|
||||
&ready_scene,
|
||||
&mut input,
|
||||
&canvas::Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)),
|
||||
bounds,
|
||||
mouse::Cursor::Available(ready_point),
|
||||
)
|
||||
.and_then(|action| action.into_inner().0)
|
||||
.unwrap();
|
||||
let Message::ScenarioCanvas(CanvasEvent::Spacing(spacing::Event::Begin {
|
||||
stamp: captured_stamp,
|
||||
token,
|
||||
target: spacing::Target::Message(target),
|
||||
..
|
||||
})) = begin
|
||||
else {
|
||||
panic!("Ready Saved message must begin a stamped spacing gesture");
|
||||
};
|
||||
assert_eq!(captured_stamp, stamp);
|
||||
assert_eq!(target, f.call);
|
||||
assert!(matches!(input.press, Some(SequencePress::Spacing {
|
||||
stamp: held_stamp, token: held_token
|
||||
}) if held_stamp == stamp && held_token == token));
|
||||
scene.interaction = Some((context, CanvasTool::Select, true));
|
||||
assert!(!scene.coordinate_input && scene.spacing_stamp.is_none());
|
||||
let release = canvas::Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left));
|
||||
let result = canvas::Program::update(
|
||||
&scene,
|
||||
&mut input,
|
||||
&release,
|
||||
bounds,
|
||||
mouse::Cursor::Available(ready_point),
|
||||
)
|
||||
.and_then(|action| action.into_inner().0);
|
||||
assert!(
|
||||
matches!(result, Some(Message::ScenarioCanvas(CanvasEvent::Spacing(
|
||||
spacing::Event::Cancel { stamp: cancelled_stamp, token: cancelled_token }
|
||||
))) if cancelled_stamp == stamp && cancelled_token == token)
|
||||
);
|
||||
assert!(input.press.is_none() && input.source.is_none());
|
||||
assert!(
|
||||
canvas::Program::update(
|
||||
&scene,
|
||||
&mut input,
|
||||
&release,
|
||||
bounds,
|
||||
mouse::Cursor::Available(ready_point),
|
||||
)
|
||||
.and_then(|action| action.into_inner().0)
|
||||
.is_none()
|
||||
);
|
||||
assert_eq!(ready_project, ready_original);
|
||||
assert_eq!(f.project, original);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn saved_camera_fits_actual_negative_origin_and_tiny_scale_without_authored_mutation() {
|
||||
let mut f = direct_tests::fixture();
|
||||
let rep = saved(
|
||||
&mut f.project,
|
||||
f.owner,
|
||||
&[(f.sender, -1_000_000.), (f.receiver, 1_000_000.)],
|
||||
);
|
||||
let original = f.project.clone();
|
||||
let mut state = State::default();
|
||||
state.enter_representation(Id::new_v4(), f.owner, rep);
|
||||
state.viewport(Size::new(700., 500.));
|
||||
assert!(
|
||||
state.presentation.fit,
|
||||
"new saved views await their real viewport in Fit mode"
|
||||
);
|
||||
assert!(
|
||||
!state.camera_zoom(&f.project, f.owner, None),
|
||||
"already-active Fit is idempotent"
|
||||
);
|
||||
let shown = state.display(&f.project, f.owner, f.owner).unwrap();
|
||||
assert!(matches!(
|
||||
shown.status(),
|
||||
presentation::PresentationStatus::Ready
|
||||
));
|
||||
let bounds = shown.bounds().unwrap();
|
||||
assert!(bounds.x < -1_000_000. && bounds.x + bounds.width > 1_000_000.);
|
||||
let fitted = state.presentation.camera(bounds);
|
||||
assert!(fitted.scale > 0. && fitted.scale < 0.001);
|
||||
let left = bounds.x * fitted.scale + fitted.pan.x;
|
||||
let right = (bounds.x + bounds.width) * fitted.scale + fitted.pan.x;
|
||||
assert!((left - 8.).abs() < 0.001 && (right - 692.).abs() < 0.001);
|
||||
assert!(state.camera(
|
||||
&f.project,
|
||||
f.owner,
|
||||
super::super::canvas_workspace::Event::Pan(iced::Vector::new(13., -7.))
|
||||
));
|
||||
let moved = state.presentation.camera(bounds);
|
||||
assert_eq!(moved.scale, fitted.scale);
|
||||
assert_eq!(moved.pan, fitted.pan + iced::Vector::new(13., -7.));
|
||||
assert!(!state.presentation.fit);
|
||||
assert_eq!(f.project, original);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deleted_saved_identity_remains_unavailable_and_never_falls_into_derived_geometry() {
|
||||
let mut f = direct_tests::fixture();
|
||||
let rep = saved(&mut f.project, f.owner, &[]);
|
||||
let mut state = State::default();
|
||||
let document = Id::new_v4();
|
||||
state.enter_representation(document, f.owner, rep);
|
||||
let Representation::Saved { diagram } = rep else {
|
||||
unreachable!()
|
||||
};
|
||||
f.project.diagrams.remove(&diagram);
|
||||
let original = f.project.clone();
|
||||
let shown = state.display(&f.project, f.owner, f.owner).unwrap();
|
||||
assert_eq!(shown.requested(), rep);
|
||||
assert!(matches!(
|
||||
shown.status(),
|
||||
presentation::PresentationStatus::Unavailable { .. }
|
||||
));
|
||||
assert!(shown.scene().is_none() && shown.bounds().is_none());
|
||||
assert_eq!(state.owner(), Some(f.owner));
|
||||
assert!(state.context(document, f.owner, 0, 0).is_some());
|
||||
assert!(!state.camera_zoom(&f.project, f.owner, None));
|
||||
assert_eq!(f.project, original);
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
//! Pure Saved-only spacing preparation. Delta is measured from the original
|
||||
//! pointer in the captured camera's world coordinates, never from the last
|
||||
//! preview. The controller must own document/revision/visit, camera and hit-role
|
||||
//! admission; this module neither dispatches commands nor changes selection.
|
||||
use crate::behavior::scenario_layout::{
|
||||
GeometryIssue, Representation, ResolvedScenarioPlan, presentation::checked_owner, resolve,
|
||||
};
|
||||
use oa_core::{
|
||||
Command, Id, Kind, OccurrenceBody, OccurrenceEndpoint, Project, ScenarioLanePosition,
|
||||
ScenarioMessagePosition, SharedBody, execute_batch,
|
||||
};
|
||||
|
||||
pub(crate) mod controller;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
pub(crate) use controller::{Event, Stamp};
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum Target {
|
||||
Lane(Id),
|
||||
Message(Id),
|
||||
}
|
||||
impl Target {
|
||||
pub(crate) fn id(self) -> Id {
|
||||
match self {
|
||||
Self::Lane(id) | Self::Message(id) => id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub(crate) enum Refusal {
|
||||
InvalidSavedView(Id),
|
||||
TargetNotRendered(Target),
|
||||
InvalidDelta,
|
||||
InvalidGesture,
|
||||
CameraChanged,
|
||||
TargetNotHit(Target),
|
||||
Command(String),
|
||||
Geometry(Vec<GeometryIssue>),
|
||||
}
|
||||
|
||||
pub(super) struct Drag {
|
||||
original: Project,
|
||||
diagram: Id,
|
||||
target: Target,
|
||||
origin: f32,
|
||||
original_geometry: ResolvedScenarioPlan,
|
||||
}
|
||||
|
||||
pub(super) struct Preview {
|
||||
pub(super) command: Command,
|
||||
#[cfg(test)]
|
||||
pub(super) project: Project,
|
||||
pub(super) geometry: ResolvedScenarioPlan,
|
||||
}
|
||||
|
||||
/// 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)?;
|
||||
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)) =>
|
||||
{
|
||||
// Unassigned lifelines still have drawn headers. `scene.lanes`
|
||||
// excludes them only from semantic message-endpoint hit testing.
|
||||
geometry.scene.render_lanes.get(&id).copied()
|
||||
}
|
||||
Target::Message(id)
|
||||
if element.is_some_and(|e| {
|
||||
matches!(
|
||||
e.shared(),
|
||||
Some(SharedBody::Occurrence {
|
||||
body: OccurrenceBody::Exchange { .. },
|
||||
..
|
||||
})
|
||||
)
|
||||
}) =>
|
||||
{
|
||||
// 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)
|
||||
.and_then(|line| line.points.first())
|
||||
.map(|point| point.y)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
.ok_or(Refusal::TargetNotRendered(target))?;
|
||||
if !origin.is_finite() {
|
||||
return Err(Refusal::TargetNotRendered(target));
|
||||
}
|
||||
Ok(Drag {
|
||||
original: project.clone(),
|
||||
diagram,
|
||||
target,
|
||||
origin,
|
||||
original_geometry: geometry,
|
||||
})
|
||||
}
|
||||
|
||||
impl Drag {
|
||||
/// None means there is no command to commit. In particular +0/-0, return to
|
||||
/// start, and sub-precision motion never materialize a missing override or
|
||||
/// normalize an existing explicit value. Document/redo are never touched.
|
||||
pub(super) fn prepare(&self, original_delta: f32) -> Result<Option<Preview>, Refusal> {
|
||||
if !original_delta.is_finite() {
|
||||
return Err(Refusal::InvalidDelta);
|
||||
}
|
||||
if original_delta == 0. {
|
||||
return Ok(None);
|
||||
}
|
||||
let position = (f64::from(self.origin) + f64::from(original_delta)) as f32;
|
||||
if position == self.origin {
|
||||
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,
|
||||
},
|
||||
},
|
||||
};
|
||||
let project = execute_batch(&self.original, std::slice::from_ref(&command))
|
||||
.map_err(|error| Refusal::Command(error.to_string()))?;
|
||||
let geometry = resolve(
|
||||
&project,
|
||||
Representation::Saved {
|
||||
diagram: self.diagram,
|
||||
},
|
||||
self.target.id(),
|
||||
)
|
||||
.map_err(Refusal::Geometry)?;
|
||||
Ok(Some(Preview {
|
||||
command,
|
||||
#[cfg(test)]
|
||||
project,
|
||||
geometry,
|
||||
}))
|
||||
}
|
||||
}
|
||||
@@ -1,300 +0,0 @@
|
||||
//! One press owns one immutable accepted Project and one frozen display camera.
|
||||
use super::*;
|
||||
use crate::behavior::{
|
||||
Scene, SceneHitRole,
|
||||
scenario::{CanvasTool, Context, State},
|
||||
scenario_layout::Diagnostic,
|
||||
};
|
||||
use iced::{Point, Rectangle, Vector};
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) mod tests;
|
||||
#[cfg(test)]
|
||||
mod timing_tests;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct Stamp {
|
||||
pub(crate) context: Context,
|
||||
pub(crate) camera_epoch: u64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum Event {
|
||||
Begin {
|
||||
stamp: Stamp,
|
||||
token: Id,
|
||||
target: Target,
|
||||
press_screen: Point,
|
||||
canvas_bounds: Rectangle,
|
||||
scale: f32,
|
||||
pan: Vector,
|
||||
},
|
||||
Move {
|
||||
stamp: Stamp,
|
||||
token: Id,
|
||||
screen: Point,
|
||||
},
|
||||
Finish {
|
||||
stamp: Stamp,
|
||||
token: Id,
|
||||
screen: Point,
|
||||
},
|
||||
Cancel {
|
||||
stamp: Stamp,
|
||||
token: Id,
|
||||
},
|
||||
}
|
||||
impl Event {
|
||||
pub(crate) fn stamp(self) -> Stamp {
|
||||
match self {
|
||||
Self::Begin { stamp, .. }
|
||||
| Self::Move { stamp, .. }
|
||||
| Self::Finish { stamp, .. }
|
||||
| Self::Cancel { stamp, .. } => stamp,
|
||||
}
|
||||
}
|
||||
pub(crate) fn token(self) -> Id {
|
||||
match self {
|
||||
Self::Begin { token, .. }
|
||||
| Self::Move { token, .. }
|
||||
| Self::Finish { token, .. }
|
||||
| Self::Cancel { token, .. } => token,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct Session {
|
||||
stamp: Stamp,
|
||||
token: Id,
|
||||
press_screen: Point,
|
||||
scale: f32,
|
||||
pan: Vector,
|
||||
drag: Drag,
|
||||
preview: Option<Preview>,
|
||||
refusal: Option<Refusal>,
|
||||
ever_crossed: bool,
|
||||
}
|
||||
|
||||
pub(in crate::behavior) struct Paint<'a> {
|
||||
pub(in crate::behavior) scene: &'a Scene,
|
||||
#[cfg(test)]
|
||||
pub(in crate::behavior) bounds: Rectangle,
|
||||
pub(in crate::behavior) refusal: Option<&'a Refusal>,
|
||||
pub(in crate::behavior) original_diagnostics: &'a [Diagnostic],
|
||||
pub(in crate::behavior) original_latent: &'a [Id],
|
||||
pub(in crate::behavior) diagnostics: &'a [Diagnostic],
|
||||
}
|
||||
|
||||
pub(crate) enum Finish {
|
||||
Click(Id),
|
||||
Noop,
|
||||
Commit {
|
||||
command: Box<Command>,
|
||||
selected: Id,
|
||||
scale: f32,
|
||||
pan: Vector,
|
||||
},
|
||||
}
|
||||
|
||||
impl Session {
|
||||
fn configure(&self, scene: &mut Scene) {
|
||||
scene.selected = self.drag.target.id();
|
||||
scene.scale = self.scale;
|
||||
scene.camera_pan = self.pan;
|
||||
scene.interaction = Some((self.stamp.context, CanvasTool::Select, true));
|
||||
scene.spacing_stamp = Some(self.stamp);
|
||||
scene.coordinate_input = true;
|
||||
scene.pending_placement = None;
|
||||
}
|
||||
fn update(&mut self, screen: Point) {
|
||||
self.preview = None;
|
||||
self.refusal = None;
|
||||
if !screen.x.is_finite() || !screen.y.is_finite() {
|
||||
self.refusal = Some(Refusal::InvalidDelta);
|
||||
return;
|
||||
}
|
||||
let distance = match self.drag.target {
|
||||
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 {
|
||||
return;
|
||||
}
|
||||
match self.drag.prepare(distance / self.scale) {
|
||||
Ok(Some(mut preview)) => {
|
||||
self.configure(&mut preview.geometry.scene);
|
||||
self.preview = Some(preview);
|
||||
}
|
||||
Ok(None) => {}
|
||||
Err(error) => self.refusal = Some(error),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl State {
|
||||
pub(crate) fn spacing_token(&self) -> Option<Id> {
|
||||
self.spacing.as_ref().map(|s| s.token)
|
||||
}
|
||||
pub(crate) fn spacing_stamp(&self) -> Option<Stamp> {
|
||||
self.spacing.as_ref().map(|s| s.stamp)
|
||||
}
|
||||
pub(crate) fn cancel_spacing(&mut self) -> bool {
|
||||
self.spacing.take().is_some()
|
||||
}
|
||||
|
||||
pub(in crate::behavior) fn spacing_paint(
|
||||
&self,
|
||||
context: Context,
|
||||
camera_epoch: u64,
|
||||
) -> Option<Paint<'_>> {
|
||||
let session = self.spacing.as_ref()?;
|
||||
if session.stamp
|
||||
!= (Stamp {
|
||||
context,
|
||||
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,
|
||||
#[cfg(test)]
|
||||
bounds: shown.bounds,
|
||||
refusal: session.refusal.as_ref(),
|
||||
original_diagnostics: &original.plan.diagnostics,
|
||||
original_latent: &original.latent_messages,
|
||||
diagnostics: &shown.plan.diagnostics,
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn begin_spacing(&mut self, project: &Project, event: Event) -> Result<(), Refusal> {
|
||||
let Event::Begin {
|
||||
stamp,
|
||||
token,
|
||||
target,
|
||||
press_screen,
|
||||
canvas_bounds,
|
||||
scale,
|
||||
pan,
|
||||
} = event
|
||||
else {
|
||||
return Err(Refusal::InvalidGesture);
|
||||
};
|
||||
let context = stamp.context;
|
||||
if self.spacing.is_some()
|
||||
|| token.is_nil()
|
||||
|| self.context(
|
||||
context.document,
|
||||
context.scenario,
|
||||
context.revision,
|
||||
context.epoch,
|
||||
) != Some(context)
|
||||
|| self.canvas_tool(context.scenario) != CanvasTool::Select
|
||||
|| ![
|
||||
press_screen.x,
|
||||
press_screen.y,
|
||||
canvas_bounds.x,
|
||||
canvas_bounds.y,
|
||||
canvas_bounds.width,
|
||||
canvas_bounds.height,
|
||||
scale,
|
||||
pan.x,
|
||||
pan.y,
|
||||
]
|
||||
.into_iter()
|
||||
.all(f32::is_finite)
|
||||
|| scale <= 0.
|
||||
|| canvas_bounds.width <= 0.
|
||||
|| canvas_bounds.height <= 0.
|
||||
|| !canvas_bounds.contains(press_screen)
|
||||
{
|
||||
return Err(Refusal::InvalidGesture);
|
||||
}
|
||||
let Representation::Saved { diagram } = context.representation else {
|
||||
return Err(Refusal::InvalidGesture);
|
||||
};
|
||||
let mut drag = capture(project, diagram, target)?;
|
||||
let camera = self.presentation.camera(drag.original_geometry.bounds);
|
||||
if self.presentation.viewport != Some(canvas_bounds.size())
|
||||
|| camera.scale != scale
|
||||
|| camera.pan != pan
|
||||
{
|
||||
return Err(Refusal::CameraChanged);
|
||||
}
|
||||
let world = Point::new(
|
||||
(press_screen.x - canvas_bounds.x - pan.x) / scale,
|
||||
(press_screen.y - canvas_bounds.y - pan.y) / scale,
|
||||
);
|
||||
// Hit tolerance is measured in displayed pixels, just like the widget.
|
||||
drag.original_geometry.scene.scale = scale;
|
||||
drag.original_geometry.scene.camera_pan = pan;
|
||||
let hit = drag.original_geometry.scene.hit_item(world);
|
||||
if !hit.is_some_and(|hit| {
|
||||
hit.id == target.id()
|
||||
&& match target {
|
||||
Target::Lane(_) => hit.role == SceneHitRole::LifelineHeader,
|
||||
Target::Message(_) => matches!(
|
||||
hit.role,
|
||||
SceneHitRole::MessageBody | SceneHitRole::MessageLabel
|
||||
),
|
||||
}
|
||||
}) {
|
||||
return Err(Refusal::TargetNotHit(target));
|
||||
}
|
||||
// Configure baseline without changing the persistent camera or selection.
|
||||
let scene = &mut drag.original_geometry.scene;
|
||||
scene.selected = target.id();
|
||||
scene.scale = scale;
|
||||
scene.camera_pan = pan;
|
||||
scene.interaction = Some((context, CanvasTool::Select, true));
|
||||
scene.spacing_stamp = Some(stamp);
|
||||
scene.coordinate_input = true;
|
||||
scene.pending_placement = None;
|
||||
self.spacing = Some(Session {
|
||||
stamp,
|
||||
token,
|
||||
press_screen,
|
||||
scale,
|
||||
pan,
|
||||
drag,
|
||||
preview: None,
|
||||
refusal: None,
|
||||
ever_crossed: false,
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
pub(crate) fn move_spacing(&mut self, screen: Point) {
|
||||
if let Some(session) = &mut self.spacing {
|
||||
session.update(screen);
|
||||
}
|
||||
}
|
||||
pub(crate) fn finish_spacing(&mut self, screen: Point) -> Result<Finish, Refusal> {
|
||||
let Some(mut session) = self.spacing.take() else {
|
||||
return Err(Refusal::InvalidGesture);
|
||||
};
|
||||
session.update(screen);
|
||||
if let Some(error) = session.refusal {
|
||||
return Err(error);
|
||||
}
|
||||
if !session.ever_crossed {
|
||||
return Ok(Finish::Click(session.drag.target.id()));
|
||||
}
|
||||
Ok(match session.preview {
|
||||
None => Finish::Noop,
|
||||
Some(preview) => Finish::Commit {
|
||||
command: Box::new(preview.command),
|
||||
selected: session.drag.target.id(),
|
||||
scale: session.scale,
|
||||
pan: session.pan,
|
||||
},
|
||||
})
|
||||
}
|
||||
pub(crate) fn accept_spacing_camera(&mut self, scale: f32, pan: Vector) {
|
||||
self.presentation.zoom = Some(scale);
|
||||
self.presentation.pan = pan;
|
||||
self.presentation.fit = false;
|
||||
}
|
||||
}
|
||||
@@ -1,421 +0,0 @@
|
||||
use super::*;
|
||||
use crate::document::Document;
|
||||
use iced::Size;
|
||||
use oa_core::{Diagram, Layer, ProjectionKind, language, source_project::ProjectLimits};
|
||||
|
||||
pub(crate) fn fixture() -> (Document, Id, Id, Id, Id) {
|
||||
let mut p = language::parse(r#"arcadia 7;
|
||||
project spacing "Spacing" {
|
||||
oa_activity work "Work" {}
|
||||
oa_activity response "Response" {}
|
||||
oa_scenario incident "Incident" { viewpoint OperationalActivity; steps [@first, @second]; }
|
||||
oa_lifeline reporter "Reporter" { parent @incident; represented @work; }
|
||||
oa_lifeline operator "Operator" { parent @incident; represented @response; }
|
||||
oa_occurrence first "First" { parent @incident; body { Exchange { exchange none; sender @reporter; receiver @operator; message_kind Asynchronous; }; }; }
|
||||
oa_occurrence second "Second" { parent @incident; body { Exchange { exchange none; sender @operator; receiver @reporter; message_kind Asynchronous; }; }; }
|
||||
}"#).unwrap();
|
||||
let id = |name: &str| {
|
||||
p.identities()
|
||||
.into_iter()
|
||||
.find(|(_, alias)| *alias == name)
|
||||
.unwrap()
|
||||
.0
|
||||
};
|
||||
let (owner, lane, message) = (id("incident"), id("reporter"), id("first"));
|
||||
let diagram = Id::new_v4();
|
||||
p.diagrams.insert(
|
||||
diagram,
|
||||
Diagram {
|
||||
id: diagram,
|
||||
alias: "saved".into(),
|
||||
name: "Saved".into(),
|
||||
description: String::new(),
|
||||
layer: Layer::Oa,
|
||||
projection: ProjectionKind::Scenario { scenario: owner },
|
||||
nodes: Default::default(),
|
||||
routes: vec![],
|
||||
view_options: Default::default(),
|
||||
layout: None,
|
||||
},
|
||||
);
|
||||
(
|
||||
Document::from_project(p, ProjectLimits::default()).unwrap(),
|
||||
owner,
|
||||
diagram,
|
||||
lane,
|
||||
message,
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn expected(p: &Project, diagram: Id, target: Target, delta: f32) -> Project {
|
||||
capture(p, diagram, target)
|
||||
.unwrap()
|
||||
.prepare(delta)
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.project
|
||||
}
|
||||
|
||||
pub(crate) fn packet(
|
||||
p: &Project,
|
||||
state: &State,
|
||||
context: Context,
|
||||
camera_epoch: u64,
|
||||
target: Target,
|
||||
) -> Event {
|
||||
let geometry = resolve(p, context.representation, target.id()).unwrap();
|
||||
let world = match target {
|
||||
Target::Lane(id) => geometry
|
||||
.scene
|
||||
.boxes
|
||||
.iter()
|
||||
.find(|item| item.id == id && item.role == SceneHitRole::LifelineHeader)
|
||||
.unwrap()
|
||||
.rect
|
||||
.center(),
|
||||
Target::Message(id) => {
|
||||
let line = geometry
|
||||
.scene
|
||||
.lines
|
||||
.iter()
|
||||
.find(|line| line.id == id)
|
||||
.unwrap();
|
||||
Point::new((line.points[0].x + line.points[1].x) / 2., line.points[0].y)
|
||||
}
|
||||
};
|
||||
assert!(
|
||||
geometry
|
||||
.scene
|
||||
.hit_item(world)
|
||||
.is_some_and(|hit| hit.id == target.id())
|
||||
);
|
||||
let camera = state.presentation.camera(geometry.bounds);
|
||||
let canvas_bounds = Rectangle::new(Point::new(17., 23.), state.presentation.viewport.unwrap());
|
||||
Event::Begin {
|
||||
stamp: Stamp {
|
||||
context,
|
||||
camera_epoch,
|
||||
},
|
||||
token: Id::new_v4(),
|
||||
target,
|
||||
press_screen: Point::new(
|
||||
canvas_bounds.x + world.x * camera.scale + camera.pan.x,
|
||||
canvas_bounds.y + world.y * camera.scale + camera.pan.y,
|
||||
),
|
||||
canvas_bounds,
|
||||
scale: camera.scale,
|
||||
pan: camera.pan,
|
||||
}
|
||||
}
|
||||
fn setup(target_message: bool) -> (Document, State, Event) {
|
||||
let (doc, owner, diagram, lane, message) = fixture();
|
||||
let mut state = State::default();
|
||||
state.enter_representation(Id::new_v4(), owner, Representation::Saved { diagram });
|
||||
state.presentation.viewport = Some(Size::new(900., 600.));
|
||||
let context = state
|
||||
.context(
|
||||
state.presentation.identity.unwrap().0,
|
||||
owner,
|
||||
doc.revision(),
|
||||
4,
|
||||
)
|
||||
.unwrap();
|
||||
let target = if target_message {
|
||||
Target::Message(message)
|
||||
} else {
|
||||
Target::Lane(lane)
|
||||
};
|
||||
let event = packet(doc.project(), &state, context, 9, target);
|
||||
(doc, state, event)
|
||||
}
|
||||
fn press(event: Event) -> Point {
|
||||
let Event::Begin { press_screen, .. } = event else {
|
||||
unreachable!()
|
||||
};
|
||||
press_screen
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn real_preview_moves_only_active_axis_from_original_and_never_changes_document() {
|
||||
for message in [false, true] {
|
||||
let (doc, mut state, begin) = setup(message);
|
||||
let original = doc.snapshot();
|
||||
let camera = state.camera_boundary();
|
||||
let start = press(begin);
|
||||
state.begin_spacing(doc.project(), begin).unwrap();
|
||||
let first = if message {
|
||||
Vector::new(500., 30.)
|
||||
} else {
|
||||
Vector::new(30., 500.)
|
||||
};
|
||||
state.move_spacing(start + first);
|
||||
let session = state.spacing.as_ref().unwrap();
|
||||
let candidate = session.preview.as_ref().unwrap();
|
||||
let delta = 30. / session.scale;
|
||||
let actual_anchor = match session.drag.target {
|
||||
Target::Lane(id) => candidate.geometry.scene.render_lanes[&id],
|
||||
Target::Message(id) => {
|
||||
candidate
|
||||
.geometry
|
||||
.scene
|
||||
.lines
|
||||
.iter()
|
||||
.find(|line| line.id == id)
|
||||
.unwrap()
|
||||
.points[0]
|
||||
.y
|
||||
}
|
||||
};
|
||||
let wanted = (f64::from(session.drag.origin) + f64::from(delta)) as f32;
|
||||
assert_eq!(actual_anchor.to_bits(), wanted.to_bits());
|
||||
let expected = session.drag.prepare(delta).unwrap().unwrap();
|
||||
assert_eq!(candidate.project, expected.project);
|
||||
assert_eq!(candidate.geometry.scene.rows, expected.geometry.scene.rows);
|
||||
assert_eq!(
|
||||
candidate.geometry.scene.render_lanes,
|
||||
expected.geometry.scene.render_lanes
|
||||
);
|
||||
state.move_spacing(start + first * 2.);
|
||||
let session = state.spacing.as_ref().unwrap();
|
||||
assert_eq!(
|
||||
session.preview.as_ref().unwrap().project,
|
||||
session.drag.prepare(delta * 2.).unwrap().unwrap().project
|
||||
);
|
||||
assert_eq!(doc.project(), &original.decoded.project);
|
||||
assert_eq!(doc.compiled().bundle, original.bundle);
|
||||
assert!(!doc.dirty() && !doc.can_undo() && !doc.can_redo());
|
||||
assert!(camera == state.camera_boundary());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn click_threshold_is_active_axis_and_return_to_zero_is_not_a_click() {
|
||||
let (doc, mut state, begin) = setup(false);
|
||||
let start = press(begin);
|
||||
state.begin_spacing(doc.project(), begin).unwrap();
|
||||
state.move_spacing(start + Vector::new(2., 100.));
|
||||
assert!(matches!(
|
||||
state.finish_spacing(start).unwrap(),
|
||||
Finish::Click(_)
|
||||
));
|
||||
state.begin_spacing(doc.project(), begin).unwrap();
|
||||
state.move_spacing(start + Vector::new(4., 0.));
|
||||
assert!(matches!(state.finish_spacing(start).unwrap(), Finish::Noop));
|
||||
assert!(!doc.can_undo());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_move_discards_prior_candidate_and_finish_rechecks_final_pointer() {
|
||||
let (doc, mut state, begin) = setup(false);
|
||||
let start = press(begin);
|
||||
state.begin_spacing(doc.project(), begin).unwrap();
|
||||
state.move_spacing(start + Vector::new(20., 0.));
|
||||
state.move_spacing(Point::new(f32::NAN, start.y));
|
||||
let paint = state.spacing_paint(begin.stamp().context, 9).unwrap();
|
||||
assert!(matches!(paint.refusal, Some(Refusal::InvalidDelta)));
|
||||
assert_eq!(
|
||||
paint.scene.render_lanes,
|
||||
state
|
||||
.spacing
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.drag
|
||||
.original_geometry
|
||||
.scene
|
||||
.render_lanes
|
||||
);
|
||||
assert!(matches!(
|
||||
state.finish_spacing(Point::new(f32::NAN, start.y)),
|
||||
Err(Refusal::InvalidDelta)
|
||||
));
|
||||
assert!(state.spacing_token().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn forged_camera_hit_role_and_retired_visit_cannot_capture() {
|
||||
let (doc, mut state, begin) = setup(false);
|
||||
let Event::Begin {
|
||||
stamp,
|
||||
token,
|
||||
target,
|
||||
press_screen,
|
||||
canvas_bounds,
|
||||
scale,
|
||||
pan,
|
||||
} = begin
|
||||
else {
|
||||
unreachable!()
|
||||
};
|
||||
assert!(matches!(
|
||||
state.begin_spacing(
|
||||
doc.project(),
|
||||
Event::Begin {
|
||||
stamp,
|
||||
token,
|
||||
target,
|
||||
press_screen,
|
||||
canvas_bounds,
|
||||
scale: scale * 2.,
|
||||
pan
|
||||
}
|
||||
),
|
||||
Err(Refusal::CameraChanged)
|
||||
));
|
||||
assert!(matches!(
|
||||
state.begin_spacing(
|
||||
doc.project(),
|
||||
Event::Begin {
|
||||
stamp,
|
||||
token,
|
||||
target,
|
||||
press_screen: canvas_bounds.center(),
|
||||
canvas_bounds,
|
||||
scale,
|
||||
pan
|
||||
}
|
||||
),
|
||||
Err(Refusal::TargetNotHit(_))
|
||||
));
|
||||
state.leave();
|
||||
assert!(matches!(
|
||||
state.begin_spacing(doc.project(), begin),
|
||||
Err(Refusal::InvalidGesture)
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zoomed_out_message_tolerance_matches_actual_canvas_hit() {
|
||||
let (doc, mut state, _) = setup(true);
|
||||
state.presentation.fit = false;
|
||||
state.presentation.zoom = Some(0.25);
|
||||
state.presentation.pan = Vector::ZERO;
|
||||
let context = state
|
||||
.context(
|
||||
state.presentation.identity.unwrap().0,
|
||||
state.owner().unwrap(),
|
||||
doc.revision(),
|
||||
4,
|
||||
)
|
||||
.unwrap();
|
||||
let message = doc
|
||||
.project()
|
||||
.identities()
|
||||
.into_iter()
|
||||
.find(|(_, alias)| *alias == "first")
|
||||
.map(|(id, _)| id)
|
||||
.unwrap();
|
||||
let Event::Begin {
|
||||
stamp,
|
||||
token,
|
||||
target,
|
||||
press_screen,
|
||||
canvas_bounds,
|
||||
scale,
|
||||
pan,
|
||||
} = packet(doc.project(), &state, context, 9, Target::Message(message))
|
||||
else {
|
||||
unreachable!()
|
||||
};
|
||||
let event = Event::Begin {
|
||||
stamp,
|
||||
token,
|
||||
target,
|
||||
press_screen: press_screen + Vector::new(0., 3.),
|
||||
canvas_bounds,
|
||||
scale,
|
||||
pan,
|
||||
};
|
||||
state.begin_spacing(doc.project(), event).unwrap();
|
||||
assert_eq!(state.spacing_token(), Some(token));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fractional_screen_packet_preserves_subpixel_motion_in_preview_and_finish() {
|
||||
let (doc, owner, diagram, _, message) = fixture();
|
||||
let original = doc.snapshot();
|
||||
assert!(doc.project().diagrams[&diagram].layout.is_none());
|
||||
let mut state = State::default();
|
||||
let document = Id::new_v4();
|
||||
state.enter_representation(document, owner, Representation::Saved { diagram });
|
||||
state.presentation.viewport = Some(Size::new(900., 600.));
|
||||
state.presentation.fit = false;
|
||||
state.presentation.zoom = Some(0.5);
|
||||
// 406 + 2^-15 puts the press just below the 512 screen-coordinate boundary.
|
||||
state.presentation.pan = Vector::new(0., f32::from_bits(0x43cb_0001));
|
||||
let camera = state.camera_boundary();
|
||||
let context = state.context(document, owner, doc.revision(), 4).unwrap();
|
||||
let baseline = resolve(doc.project(), context.representation, message).unwrap();
|
||||
let line = baseline
|
||||
.scene
|
||||
.lines
|
||||
.iter()
|
||||
.find(|line| line.id == message)
|
||||
.unwrap();
|
||||
assert_eq!(line.points[0].y, 148.);
|
||||
let begin = packet(doc.project(), &state, context, 9, Target::Message(message));
|
||||
let Event::Begin {
|
||||
press_screen,
|
||||
canvas_bounds,
|
||||
scale,
|
||||
pan,
|
||||
..
|
||||
} = begin
|
||||
else {
|
||||
unreachable!()
|
||||
};
|
||||
assert_eq!(canvas_bounds.y, 23.);
|
||||
assert_eq!(scale, 0.5);
|
||||
assert_eq!(pan.y.to_bits(), 0x43cb_0001);
|
||||
assert_eq!(press_screen.y.to_bits(), 0x43fb_8001); // 503 + 2^-15.
|
||||
let end = press_screen + Vector::new(0., 10.);
|
||||
assert_eq!(end.y, 513.);
|
||||
assert!(canvas_bounds.contains(press_screen) && canvas_bounds.contains(end));
|
||||
// The submitted f32 displacement is 10 - 2^-15, not exactly 10.
|
||||
assert_eq!((end.y - press_screen.y).to_bits(), 0x411f_ffe0);
|
||||
assert_eq!(((end.y - press_screen.y) / scale).to_bits(), 0x419f_ffe0);
|
||||
// Independent oracle: 148 + (10 - 2^-15) / .5 = 168 - 2^-14.
|
||||
let expected_y = f32::from_bits(0x4327_fffc);
|
||||
let mut expected = original.decoded.project.clone();
|
||||
expected.diagrams.get_mut(&diagram).unwrap().layout =
|
||||
Some(oa_core::DiagramLayout::Scenario(oa_core::ScenarioLayout {
|
||||
lanes: vec![],
|
||||
messages: vec![oa_core::ScenarioMessagePosition {
|
||||
address: oa_core::OccurrenceEndpoint {
|
||||
references: vec![],
|
||||
occurrence: message,
|
||||
},
|
||||
send_y: expected_y,
|
||||
}],
|
||||
}));
|
||||
state.begin_spacing(doc.project(), begin).unwrap();
|
||||
state.move_spacing(end);
|
||||
let preview = state.spacing.as_ref().unwrap().preview.as_ref().unwrap();
|
||||
assert_eq!(preview.project, expected);
|
||||
let line = preview
|
||||
.geometry
|
||||
.scene
|
||||
.lines
|
||||
.iter()
|
||||
.find(|line| line.id == message)
|
||||
.unwrap();
|
||||
assert_eq!(line.points[0].y.to_bits(), expected_y.to_bits());
|
||||
let Finish::Commit {
|
||||
command,
|
||||
selected,
|
||||
scale,
|
||||
pan,
|
||||
} = state.finish_spacing(end).unwrap()
|
||||
else {
|
||||
panic!("fractional motion must remain a commit")
|
||||
};
|
||||
assert_eq!(selected, message);
|
||||
assert_eq!(scale, 0.5);
|
||||
assert_eq!(pan.y.to_bits(), 0x43cb_0001);
|
||||
let committed = oa_core::execute_batch(doc.project(), &[*command]).unwrap();
|
||||
assert_eq!(committed, expected);
|
||||
assert!(state.spacing_token().is_none());
|
||||
assert_eq!(doc.project(), &original.decoded.project);
|
||||
assert_eq!(doc.compiled().bundle, original.bundle);
|
||||
assert!(!doc.dirty() && !doc.can_undo() && !doc.can_redo());
|
||||
assert!(camera == state.camera_boundary());
|
||||
}
|
||||
@@ -1,304 +0,0 @@
|
||||
//! Diagnostic only: production capture/prepare, excluding fixture construction,
|
||||
//! oracle work, App source writes, widget rebuilds, text shaping and GPU paint.
|
||||
use super::*;
|
||||
use crate::document::Document;
|
||||
use oa_core::{
|
||||
DiagramLayout, Layer, MessageKind, RelationKind, ScenarioLayout, source_project::ProjectLimits,
|
||||
};
|
||||
use serde_json::{Value, json};
|
||||
use std::{collections::BTreeSet, sync::Arc, time::Instant};
|
||||
|
||||
const MESSAGE_COUNT: usize = 1000;
|
||||
const TARGET_INDEX: usize = 500;
|
||||
|
||||
fn large_fixture() -> (Document, Id, [Id; 3], Vec<Id>, Vec<Id>) {
|
||||
let (seed, owner, a, reporter, first) = super::tests::fixture();
|
||||
let mut p = seed.project().clone();
|
||||
let old_steps = p.elements[&owner].steps().unwrap().clone();
|
||||
let template = p.elements[&first].clone();
|
||||
let work = |alias: &str| {
|
||||
p.identities()
|
||||
.into_iter()
|
||||
.find(|(_, name)| *name == alias)
|
||||
.unwrap()
|
||||
.0
|
||||
};
|
||||
let (source, target) = (work("work"), work("response"));
|
||||
let operator = work("operator");
|
||||
let relation = p.relate(
|
||||
RelationKind::Interaction,
|
||||
"Repeated incident report",
|
||||
source,
|
||||
target,
|
||||
);
|
||||
let mut lanes = vec![];
|
||||
for index in 0..20 {
|
||||
let original = if index < 10 { reporter } else { operator };
|
||||
let mut lane = p.elements[&original].clone();
|
||||
lane.id = Id::new_v4();
|
||||
lane.alias = format!("timing_lane_{index:02}");
|
||||
lane.name = format!("Review participant {index:02}");
|
||||
lanes.push(lane.id);
|
||||
p.elements.insert(lane.id, lane);
|
||||
}
|
||||
p.elements.remove(&reporter);
|
||||
p.elements.remove(&operator);
|
||||
for id in old_steps {
|
||||
p.elements.remove(&id);
|
||||
}
|
||||
let mut messages = vec![];
|
||||
for index in 0..MESSAGE_COUNT {
|
||||
let mut occurrence = template.clone();
|
||||
occurrence.id = Id::new_v4();
|
||||
occurrence.alias = format!("timing_message_{index:04}");
|
||||
occurrence.name = format!("Validate incident report {index:04}");
|
||||
*occurrence.shared_mut().unwrap() = SharedBody::Occurrence {
|
||||
body: OccurrenceBody::Exchange {
|
||||
exchange: Some(relation),
|
||||
sender: Some(lanes[index % 10]),
|
||||
receiver: Some(lanes[10 + index % 10]),
|
||||
message_kind: MessageKind::Asynchronous,
|
||||
operation: None,
|
||||
reply_to: None,
|
||||
values: vec![],
|
||||
},
|
||||
precondition: String::new(),
|
||||
postcondition: String::new(),
|
||||
};
|
||||
messages.push(occurrence.id);
|
||||
p.elements.insert(occurrence.id, occurrence);
|
||||
}
|
||||
*p.elements.get_mut(&owner).unwrap().steps_mut().unwrap() = messages.clone();
|
||||
p.diagrams.get_mut(&a).unwrap().layout = Some(DiagramLayout::Scenario(ScenarioLayout {
|
||||
lanes: lanes
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, &lifeline)| ScenarioLanePosition {
|
||||
lifeline,
|
||||
x: 160. + i as f32 * 240.,
|
||||
})
|
||||
.collect(),
|
||||
messages: vec![],
|
||||
}));
|
||||
let mut views = [a, Id::nil(), Id::nil()];
|
||||
for (index, x, offset) in [(1, -500., 12.), (2, 6500., -12.)] {
|
||||
let mut view = p.diagrams[&a].clone();
|
||||
view.id = Id::new_v4();
|
||||
view.alias = format!("timing_saved_{index}");
|
||||
view.name = format!("Review arrangement {index}");
|
||||
view.layout = Some(DiagramLayout::Scenario(ScenarioLayout {
|
||||
lanes: vec![ScenarioLanePosition {
|
||||
lifeline: lanes[0],
|
||||
x,
|
||||
}],
|
||||
messages: vec![ScenarioMessagePosition {
|
||||
address: OccurrenceEndpoint {
|
||||
references: vec![],
|
||||
occurrence: messages[TARGET_INDEX],
|
||||
},
|
||||
send_y: 148. + TARGET_INDEX as f32 * 92. + offset,
|
||||
}],
|
||||
}));
|
||||
views[index] = view.id;
|
||||
p.diagrams.insert(view.id, view);
|
||||
}
|
||||
let document = Document::from_project(p, ProjectLimits::default()).unwrap();
|
||||
assert_eq!(
|
||||
document
|
||||
.project()
|
||||
.children(owner)
|
||||
.filter(|e| e.kind() == Kind::Lifeline)
|
||||
.count(),
|
||||
20
|
||||
);
|
||||
assert_eq!(document.project().elements[&owner].layer(), Layer::Oa);
|
||||
assert_eq!(document.project().diagrams.len(), 3);
|
||||
(document, owner, views, lanes, messages)
|
||||
}
|
||||
|
||||
fn assert_scene(
|
||||
scene: &Scene,
|
||||
lanes: &[Id],
|
||||
messages: &[Id],
|
||||
moved_message: Option<(Id, f32)>,
|
||||
moved_lane: Option<(Id, f32)>,
|
||||
) {
|
||||
assert_eq!(scene.render_lanes.len(), 20);
|
||||
assert_eq!(
|
||||
scene
|
||||
.boxes
|
||||
.iter()
|
||||
.filter(|b| b.role == SceneHitRole::LifelineHeader)
|
||||
.count(),
|
||||
20
|
||||
);
|
||||
assert_eq!(scene.lines.len(), MESSAGE_COUNT);
|
||||
assert_eq!(
|
||||
scene
|
||||
.lines
|
||||
.iter()
|
||||
.map(|line| line.id)
|
||||
.collect::<BTreeSet<_>>(),
|
||||
messages.iter().copied().collect::<BTreeSet<_>>()
|
||||
);
|
||||
assert!(scene.activations.is_empty() && scene.open_calls.is_empty());
|
||||
let x = |index: usize| {
|
||||
160. + index as f32 * 240.
|
||||
+ moved_lane
|
||||
.filter(|(id, _)| *id == lanes[index])
|
||||
.map_or(0., |(_, delta)| delta)
|
||||
};
|
||||
for (index, &lane) in lanes.iter().enumerate() {
|
||||
assert_eq!(scene.render_lanes[&lane], x(index));
|
||||
}
|
||||
for (index, (line, &id)) in scene.lines.iter().zip(messages).enumerate() {
|
||||
let y = 148.
|
||||
+ index as f32 * 92.
|
||||
+ moved_message
|
||||
.filter(|(target, _)| *target == id)
|
||||
.map_or(0., |(_, delta)| delta);
|
||||
assert_eq!(line.id, id);
|
||||
assert_eq!(
|
||||
line.points,
|
||||
vec![
|
||||
Point::new(x(index % 10), y),
|
||||
Point::new(x(10 + index % 10), y)
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn summary(samples: &[Value], phase: &str) -> Value {
|
||||
let mut times: Vec<u64> = samples
|
||||
.iter()
|
||||
.filter(|sample| sample["phase"] == phase)
|
||||
.map(|sample| sample["elapsed_ns"].as_u64().unwrap())
|
||||
.collect();
|
||||
times.sort_unstable();
|
||||
let n = times.len();
|
||||
let median = if n.is_multiple_of(2) {
|
||||
((u128::from(times[n / 2 - 1]) + u128::from(times[n / 2])) / 2) as u64
|
||||
} else {
|
||||
times[n / 2]
|
||||
};
|
||||
json!({"samples": n, "min_ns": times[0], "median_ns": median, "max_ns": times[n-1]})
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "Diagnostic timing only; run alone with --exact --ignored --nocapture after correctness gates; no latency acceptance threshold"]
|
||||
fn saved_spacing_capture_prepare_20_lanes_1000_messages_3_views() {
|
||||
let (document, owner, views, lanes, messages) = large_fixture();
|
||||
let original = document.snapshot();
|
||||
let target = messages[TARGET_INDEX];
|
||||
let mut samples = vec![];
|
||||
let mut retained = None;
|
||||
for iteration in 0..4 {
|
||||
let start = Instant::now();
|
||||
let result = capture(document.project(), views[0], Target::Message(target));
|
||||
let elapsed_ns = u64::try_from(start.elapsed().as_nanos()).unwrap();
|
||||
let drag = result.expect("complete asynchronous fixture must resolve");
|
||||
samples.push(json!({"phase":"capture_message", "iteration":iteration,
|
||||
"first_in_probe":iteration==0, "elapsed_ns":elapsed_ns, "outcome":"captured"}));
|
||||
assert_scene(&drag.original_geometry.scene, &lanes, &messages, None, None);
|
||||
if iteration == 0 {
|
||||
retained = Some(drag);
|
||||
}
|
||||
}
|
||||
let drag = retained.unwrap();
|
||||
// Every sample is relative to the original press, including duplicate,
|
||||
// reverse and return-to-start samples. Oracle work is outside each timer.
|
||||
let deltas = [
|
||||
4., 8., 12., 16., 20., 24., 28., 32., 32., 28., 24., 20., 16., 12., 8., 4., -4., -8., -4.,
|
||||
0.,
|
||||
];
|
||||
for (iteration, delta) in deltas.into_iter().enumerate() {
|
||||
let start = Instant::now();
|
||||
let result = drag.prepare(delta);
|
||||
let elapsed_ns = u64::try_from(start.elapsed().as_nanos()).unwrap();
|
||||
let candidate = result.expect("these isolated asynchronous offsets are feasible");
|
||||
samples.push(json!({"phase":"prepare_message", "iteration":iteration,
|
||||
"delta_world":delta, "elapsed_ns":elapsed_ns, "outcome":if candidate.is_some(){"preview"}else{"noop"}}));
|
||||
if delta == 0. {
|
||||
assert!(candidate.is_none());
|
||||
} else {
|
||||
let candidate = candidate.unwrap();
|
||||
let mut expected = original.decoded.project.clone();
|
||||
let Some(DiagramLayout::Scenario(layout)) =
|
||||
&mut expected.diagrams.get_mut(&views[0]).unwrap().layout
|
||||
else {
|
||||
panic!()
|
||||
};
|
||||
layout.messages.push(ScenarioMessagePosition {
|
||||
address: OccurrenceEndpoint {
|
||||
references: vec![],
|
||||
occurrence: target,
|
||||
},
|
||||
send_y: 148. + TARGET_INDEX as f32 * 92. + delta,
|
||||
});
|
||||
assert_eq!(candidate.project, expected);
|
||||
assert_scene(
|
||||
&candidate.geometry.scene,
|
||||
&lanes,
|
||||
&messages,
|
||||
Some((target, delta)),
|
||||
None,
|
||||
);
|
||||
}
|
||||
assert_eq!(
|
||||
document.project().elements[&owner].steps().unwrap(),
|
||||
&messages
|
||||
);
|
||||
assert_eq!(document.project(), &original.decoded.project);
|
||||
assert!(Arc::ptr_eq(&original, &document.snapshot()));
|
||||
}
|
||||
let lane = lanes[10];
|
||||
let start = Instant::now();
|
||||
let result = capture(document.project(), views[0], Target::Lane(lane));
|
||||
let elapsed_ns = u64::try_from(start.elapsed().as_nanos()).unwrap();
|
||||
let drag = result.unwrap();
|
||||
samples.push(json!({"phase":"capture_lane", "iteration":0, "elapsed_ns":elapsed_ns, "outcome":"captured"}));
|
||||
for (iteration, delta) in [20., 40., -20.].into_iter().enumerate() {
|
||||
let start = Instant::now();
|
||||
let result = drag.prepare(delta);
|
||||
let elapsed_ns = u64::try_from(start.elapsed().as_nanos()).unwrap();
|
||||
let candidate = result.unwrap().unwrap();
|
||||
samples.push(json!({"phase":"prepare_lane", "iteration":iteration,
|
||||
"delta_world":delta, "elapsed_ns":elapsed_ns, "outcome":"preview"}));
|
||||
let mut expected = original.decoded.project.clone();
|
||||
let Some(DiagramLayout::Scenario(layout)) =
|
||||
&mut expected.diagrams.get_mut(&views[0]).unwrap().layout
|
||||
else {
|
||||
panic!()
|
||||
};
|
||||
layout.lanes[10].x = 2560. + delta;
|
||||
assert_eq!(candidate.project, expected);
|
||||
assert_scene(
|
||||
&candidate.geometry.scene,
|
||||
&lanes,
|
||||
&messages,
|
||||
None,
|
||||
Some((lane, delta)),
|
||||
);
|
||||
}
|
||||
assert_eq!(document.project(), &original.decoded.project);
|
||||
assert_eq!(document.bundle(), &original.bundle);
|
||||
for view in views {
|
||||
assert_eq!(
|
||||
document.project().diagrams[&view],
|
||||
original.decoded.project.diagrams[&view]
|
||||
);
|
||||
}
|
||||
assert_eq!(document.revision(), 0);
|
||||
assert!(!document.dirty() && !document.can_undo() && !document.can_redo());
|
||||
let report = json!({
|
||||
"schema":"scenario_spacing_timing_v1",
|
||||
"fixture":{"lanes":20,"messages":MESSAGE_COUNT,"saved_views":3,"target_index":TARGET_INDEX,"distinct_message_ids":messages.iter().copied().collect::<BTreeSet<_>>().len()},
|
||||
"profile_context":{"debug_assertions":cfg!(debug_assertions),"os":std::env::consts::OS,"arch":std::env::consts::ARCH,
|
||||
"source_pin_from_runner":std::env::var("SCENARIO_SPACING_SOURCE_PIN").ok(),"source_binary_toolchain_binding":"external gate receipt required"},
|
||||
"summaries":{"capture_message":summary(&samples,"capture_message"),"prepare_message":summary(&samples,"prepare_message"),"capture_lane":summary(&samples,"capture_lane"),"prepare_lane":summary(&samples,"prepare_lane")},
|
||||
"samples":samples,
|
||||
"invariant_status":"passed",
|
||||
"limits":"First capture is first in this probe, not cold OS caches. Timers exclude construction/oracles, prior-preview disposal, source write/history, widget rebuild, label shaping, GPU paint and queued input; no responsiveness acceptance or latency threshold. All messages asynchronous; no nested frame/lifecycle stress."
|
||||
});
|
||||
println!("SPACING_TIMING_JSON={report}");
|
||||
}
|
||||
@@ -1,522 +0,0 @@
|
||||
use super::*;
|
||||
use crate::behavior::scenario_layout::Diagnostic;
|
||||
use crate::document::Document;
|
||||
use oa_core::{
|
||||
Diagram, DiagramLayout, ProjectionKind, ScenarioLayout, language, source_project::ProjectLimits,
|
||||
};
|
||||
|
||||
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 mut add = |alias: &str, layout: Option<ScenarioLayout>| {
|
||||
let diagram = Id::new_v4();
|
||||
project.diagrams.insert(
|
||||
diagram,
|
||||
Diagram {
|
||||
id: diagram,
|
||||
alias: alias.into(),
|
||||
name: alias.into(),
|
||||
description: String::new(),
|
||||
layer: oa_core::Layer::Oa,
|
||||
projection: ProjectionKind::Scenario { scenario: owner },
|
||||
nodes: Default::default(),
|
||||
routes: vec![],
|
||||
view_options: Default::default(),
|
||||
layout: layout.map(DiagramLayout::Scenario),
|
||||
},
|
||||
);
|
||||
diagram
|
||||
};
|
||||
let a = add("saved_a", layout);
|
||||
let b = add("saved_b", Some(ScenarioLayout::default()));
|
||||
let document = Document::from_project(project, ProjectLimits::default()).unwrap();
|
||||
(document, a, b)
|
||||
}
|
||||
|
||||
fn resolved(project: &Project, diagram: Id, selected: Id) -> ResolvedScenarioPlan {
|
||||
resolve(project, Representation::Saved { diagram }, selected).unwrap()
|
||||
}
|
||||
|
||||
fn same_geometry(a: &ResolvedScenarioPlan, b: &ResolvedScenarioPlan) {
|
||||
assert_eq!(a.bounds, b.bounds);
|
||||
assert_eq!(a.lanes, b.lanes);
|
||||
assert_eq!(a.plan.frames, b.plan.frames);
|
||||
assert_eq!(a.plan.scopes, b.plan.scopes);
|
||||
let (a, b) = (&a.scene, &b.scene);
|
||||
assert_eq!(a.rows, b.rows);
|
||||
assert_eq!(a.sequence_bounds, b.sequence_bounds);
|
||||
assert_eq!(a.size, b.size);
|
||||
assert_eq!(a.layout_origin, b.layout_origin);
|
||||
assert_eq!(a.lanes, b.lanes);
|
||||
assert_eq!(a.render_lanes, b.render_lanes);
|
||||
assert_eq!(a.activations, b.activations);
|
||||
assert_eq!(a.lifecycle, b.lifecycle);
|
||||
assert_eq!(a.open_calls, b.open_calls);
|
||||
let slots = |scene: &crate::behavior::Scene| {
|
||||
scene
|
||||
.slots
|
||||
.iter()
|
||||
.map(|item| {
|
||||
(
|
||||
item.slot.parent,
|
||||
item.slot.before,
|
||||
item.y,
|
||||
item.label.clone(),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
assert_eq!(slots(a), slots(b));
|
||||
let lines = |scene: &crate::behavior::Scene| {
|
||||
scene
|
||||
.lines
|
||||
.iter()
|
||||
.map(|line| {
|
||||
(
|
||||
line.id,
|
||||
line.points.clone(),
|
||||
line.label_at,
|
||||
line.label.clone(),
|
||||
line.dashed,
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
let boxes = |scene: &crate::behavior::Scene| {
|
||||
scene
|
||||
.boxes
|
||||
.iter()
|
||||
.map(|item| {
|
||||
(
|
||||
item.id,
|
||||
item.rect,
|
||||
item.title.clone(),
|
||||
item.detail.clone(),
|
||||
item.marker,
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
assert_eq!(lines(a), lines(b));
|
||||
assert_eq!(boxes(a), boxes(b));
|
||||
}
|
||||
|
||||
fn expected_message(project: &Project, diagram: Id, occurrence: Id, y: f32) -> Project {
|
||||
// Independent expected mutation: tests begin with no message overrides.
|
||||
let mut expected = project.clone();
|
||||
expected.diagrams.get_mut(&diagram).unwrap().layout =
|
||||
Some(DiagramLayout::Scenario(ScenarioLayout {
|
||||
lanes: vec![],
|
||||
messages: vec![ScenarioMessagePosition {
|
||||
address: OccurrenceEndpoint {
|
||||
references: vec![],
|
||||
occurrence,
|
||||
},
|
||||
send_y: y,
|
||||
}],
|
||||
}));
|
||||
expected
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn one_repeated_message_moves_in_one_view_with_exact_document_undo_redo_and_reopen() {
|
||||
let (mut document, a, b) = fixture(None);
|
||||
let original = document.snapshot();
|
||||
let before = document.project().clone();
|
||||
let first = id(&before, "first");
|
||||
let second = id(&before, "second");
|
||||
let baseline = resolved(&before, a, second);
|
||||
assert_eq!(baseline.scene.rows[&first].1, 148.);
|
||||
assert_eq!(baseline.scene.rows[&second].1, 240.);
|
||||
let untouched = resolved(&before, b, second);
|
||||
let drag = capture(&before, a, Target::Message(second)).unwrap();
|
||||
let preview = drag.prepare(-40.).unwrap().unwrap();
|
||||
let expected = expected_message(&before, a, second, 200.);
|
||||
assert_eq!(preview.project, expected);
|
||||
assert_eq!(preview.geometry.scene.rows[&first].1, 148.);
|
||||
assert_eq!(preview.geometry.scene.rows[&second].1, 200.);
|
||||
let line = preview
|
||||
.geometry
|
||||
.scene
|
||||
.lines
|
||||
.iter()
|
||||
.find(|line| line.id == second)
|
||||
.unwrap();
|
||||
assert_eq!(line.points.first().unwrap().y, 200.);
|
||||
assert_eq!(line.points.last().unwrap().y, 200.);
|
||||
assert_eq!(
|
||||
preview.geometry.scene.activations,
|
||||
baseline.scene.activations
|
||||
);
|
||||
assert_eq!(preview.geometry.scene.lifecycle, baseline.scene.lifecycle);
|
||||
same_geometry(&resolved(&preview.project, b, second), &untouched);
|
||||
assert_eq!(drag.original, before);
|
||||
assert!(std::sync::Arc::ptr_eq(&original, &document.snapshot()));
|
||||
assert!(!document.can_undo());
|
||||
|
||||
let returned_selection = document.execute(preview.command).unwrap();
|
||||
assert_eq!(
|
||||
returned_selection,
|
||||
Some(a),
|
||||
"controller must preserve the dragged semantic selection separately"
|
||||
);
|
||||
assert_eq!(document.project(), &expected);
|
||||
assert_eq!(document.revision(), 1);
|
||||
let accepted = document.bundle().clone();
|
||||
same_geometry(&resolved(document.project(), a, second), &preview.geometry);
|
||||
assert!(document.undo());
|
||||
assert_eq!(document.project(), &before);
|
||||
assert_eq!(document.bundle(), &original.bundle);
|
||||
assert!(!document.can_undo());
|
||||
assert!(document.redo());
|
||||
assert_eq!(document.project(), &expected);
|
||||
assert_eq!(document.bundle(), &accepted);
|
||||
let reopened = Document::from_bundle(accepted, ProjectLimits::default()).unwrap();
|
||||
assert_eq!(reopened.project(), &expected);
|
||||
same_geometry(&resolved(reopened.project(), a, second), &preview.geometry);
|
||||
assert!(!reopened.dirty() && !reopened.can_undo());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn horizontal_lane_move_changes_actual_header_and_attached_endpoints_only_in_selected_view() {
|
||||
let (document, a, b) = fixture(None);
|
||||
let before = document.project();
|
||||
let right = id(before, "right");
|
||||
let first = id(before, "first");
|
||||
let other = resolved(before, b, right);
|
||||
let preview = capture(before, a, Target::Lane(right))
|
||||
.unwrap()
|
||||
.prepare(100.)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let mut expected = before.clone();
|
||||
expected.diagrams.get_mut(&a).unwrap().layout = Some(DiagramLayout::Scenario(ScenarioLayout {
|
||||
lanes: vec![ScenarioLanePosition {
|
||||
lifeline: right,
|
||||
x: 500.,
|
||||
}],
|
||||
messages: vec![],
|
||||
}));
|
||||
assert_eq!(preview.project, expected);
|
||||
assert_eq!(preview.geometry.scene.lanes[&right], 500.);
|
||||
let header = preview
|
||||
.geometry
|
||||
.scene
|
||||
.boxes
|
||||
.iter()
|
||||
.find(|item| item.id == right)
|
||||
.unwrap();
|
||||
assert_eq!(header.rect.center_x(), 500.);
|
||||
let line = preview
|
||||
.geometry
|
||||
.scene
|
||||
.lines
|
||||
.iter()
|
||||
.find(|line| line.id == first)
|
||||
.unwrap();
|
||||
assert_eq!(line.points.first().unwrap().x, 160.);
|
||||
assert_eq!(line.points.last().unwrap().x, 500.);
|
||||
assert!(line.points.iter().all(|point| point.y == 148.));
|
||||
same_geometry(&resolved(&preview.project, b, right), &other);
|
||||
assert_eq!(document.project(), before);
|
||||
assert!(!document.dirty() && !document.can_undo());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drawn_unassigned_lifeline_can_move_without_assigning_a_semantic_participant() {
|
||||
let (document, a, _) = fixture(None);
|
||||
let mut project = document.project().clone();
|
||||
let owner = id(&project, "conversation");
|
||||
let lane = project
|
||||
.add_element(
|
||||
Kind::Lifeline,
|
||||
oa_core::Layer::Oa,
|
||||
"Unassigned header",
|
||||
Some(owner),
|
||||
)
|
||||
.unwrap();
|
||||
let document = Document::from_project(project, ProjectLimits::default()).unwrap();
|
||||
let baseline = resolved(document.project(), a, lane);
|
||||
assert!(!baseline.scene.lanes.contains_key(&lane));
|
||||
let before_header = baseline
|
||||
.scene
|
||||
.boxes
|
||||
.iter()
|
||||
.find(|item| item.id == lane)
|
||||
.unwrap()
|
||||
.rect;
|
||||
let preview = capture(document.project(), a, Target::Lane(lane))
|
||||
.unwrap()
|
||||
.prepare(70.)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let after_header = preview
|
||||
.geometry
|
||||
.scene
|
||||
.boxes
|
||||
.iter()
|
||||
.find(|item| item.id == lane)
|
||||
.unwrap()
|
||||
.rect;
|
||||
assert_eq!(after_header.x, before_header.x + 70.);
|
||||
assert_eq!(after_header.y, before_header.y);
|
||||
assert_eq!(after_header.size(), before_header.size());
|
||||
assert_eq!(preview.project.elements, document.project().elements);
|
||||
assert_eq!(preview.project.relations, document.project().relations);
|
||||
assert!(!document.can_undo());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn self_call_spacing_uses_send_y_and_preserves_reply_and_actual_activation_finish() {
|
||||
let (document, a, _) = fixture(None);
|
||||
let before = document.project();
|
||||
let call = id(before, "call");
|
||||
let reply = id(before, "reply");
|
||||
let baseline = resolved(before, a, call);
|
||||
let preview = capture(before, a, Target::Message(call))
|
||||
.unwrap()
|
||||
.prepare(-22.)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(preview.project, expected_message(before, a, call, 310.));
|
||||
let line = preview
|
||||
.geometry
|
||||
.scene
|
||||
.lines
|
||||
.iter()
|
||||
.find(|line| line.id == call)
|
||||
.unwrap();
|
||||
assert_eq!(line.points.first().unwrap().y, 310.);
|
||||
assert_eq!(line.points.last().unwrap().y, 334.);
|
||||
assert_eq!(preview.geometry.scene.rows[&reply].1, 424.);
|
||||
assert_eq!(preview.geometry.scene.activations.len(), 1);
|
||||
let mut expected_activation = baseline.scene.activations.clone();
|
||||
expected_activation[0].rect.y = 334.;
|
||||
expected_activation[0].rect.height = 90.;
|
||||
assert_eq!(preview.geometry.scene.activations, expected_activation);
|
||||
assert_eq!(preview.geometry.scene.lifecycle, baseline.scene.lifecycle);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn feasible_spacing_crossing_remains_authored_with_diagnostic_and_unchanged_steps() {
|
||||
let (document, a, _) = fixture(None);
|
||||
let before = document.project();
|
||||
let first = id(before, "first");
|
||||
let second = id(before, "second");
|
||||
let owner = id(before, "conversation");
|
||||
let preview = capture(before, a, Target::Message(second))
|
||||
.unwrap()
|
||||
.prepare(-120.)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(preview.project, expected_message(before, a, second, 120.));
|
||||
assert_eq!(preview.geometry.scene.rows[&second].1, 120.);
|
||||
assert_eq!(preview.geometry.scene.rows[&first].1, 148.);
|
||||
assert_eq!(
|
||||
preview.project.elements[&owner].steps(),
|
||||
before.elements[&owner].steps()
|
||||
);
|
||||
let shown = crate::behavior::scenario_layout::presentation::present(
|
||||
&preview.project,
|
||||
Representation::Saved { diagram: a },
|
||||
second,
|
||||
);
|
||||
assert!(shown.capabilities().coordinate_input);
|
||||
assert!(
|
||||
shown
|
||||
.diagnostics()
|
||||
.contains(&Diagnostic::SourceOrderCrossing {
|
||||
scope: owner,
|
||||
before: first,
|
||||
after: second
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unsupported_self_call_move_is_refused_and_automatic_fallback_is_not_editable_capture() {
|
||||
let (document, a, _) = fixture(None);
|
||||
let before = document.project();
|
||||
let call = id(before, "call");
|
||||
let drag = capture(before, a, Target::Message(call)).unwrap();
|
||||
let Err(Refusal::Geometry(issues)) = drag.prepare(118.) else {
|
||||
panic!("send450 / receive474 after reply424 must be refused")
|
||||
};
|
||||
assert!(issues.iter().any(|issue| matches!(issue, GeometryIssue::TypedActivationCrossingNotSupported { call: id, .. } if *id == call)));
|
||||
assert_eq!(&drag.original, before);
|
||||
let invalid_geometry = expected_message(before, a, call, 450.);
|
||||
let shown = crate::behavior::scenario_layout::presentation::present(
|
||||
&invalid_geometry,
|
||||
Representation::Saved { diagram: a },
|
||||
call,
|
||||
);
|
||||
assert!(shown.capabilities().geometry_navigation && !shown.capabilities().coordinate_input);
|
||||
assert!(matches!(
|
||||
capture(&invalid_geometry, a, Target::Message(call)),
|
||||
Err(Refusal::Geometry(_))
|
||||
));
|
||||
assert!(!document.dirty() && !document.can_undo());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_view_foreign_identity_and_latent_message_are_not_spacing_targets() {
|
||||
let (document, a, b) = fixture(None);
|
||||
let p = document.project();
|
||||
let unfinished = id(p, "unfinished");
|
||||
let source = id(p, "source");
|
||||
assert!(matches!(
|
||||
capture(p, Id::nil(), Target::Lane(source)),
|
||||
Err(Refusal::InvalidSavedView(_))
|
||||
));
|
||||
for target in [
|
||||
Target::Lane(source),
|
||||
Target::Lane(b),
|
||||
Target::Message(source),
|
||||
Target::Message(unfinished),
|
||||
] {
|
||||
assert!(
|
||||
matches!(capture(p, a, target), Err(Refusal::TargetNotRendered(found)) if found == target)
|
||||
);
|
||||
}
|
||||
// A stored latent coordinate is not permission to fabricate a painted arrow.
|
||||
let mut latent = expected_message(p, a, unfinished, 2000.);
|
||||
let foreign_owner = latent
|
||||
.add_element(Kind::Scenario, oa_core::Layer::Oa, "Foreign", None)
|
||||
.unwrap();
|
||||
let foreign_lane = latent
|
||||
.add_element(
|
||||
Kind::Lifeline,
|
||||
oa_core::Layer::Oa,
|
||||
"Foreign lane",
|
||||
Some(foreign_owner),
|
||||
)
|
||||
.unwrap();
|
||||
*latent
|
||||
.elements
|
||||
.get_mut(&foreign_lane)
|
||||
.unwrap()
|
||||
.shared_mut()
|
||||
.unwrap() = SharedBody::Lifeline {
|
||||
represented: Some(source),
|
||||
};
|
||||
let latent_document = Document::from_project(latent, ProjectLimits::default()).unwrap();
|
||||
assert!(matches!(
|
||||
capture(latent_document.project(), a, Target::Message(unfinished)),
|
||||
Err(Refusal::TargetNotRendered(_))
|
||||
));
|
||||
assert!(matches!(
|
||||
capture(latent_document.project(), a, Target::Lane(foreign_lane)),
|
||||
Err(Refusal::TargetNotRendered(_))
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zero_motion_return_to_start_and_subprecision_preserve_sparse_intent_and_real_redo() {
|
||||
let parsed = language::parse(FIXTURE).unwrap();
|
||||
let left = id(&parsed, "left");
|
||||
let second = id(&parsed, "second");
|
||||
let layouts = [
|
||||
None,
|
||||
Some(ScenarioLayout::default()),
|
||||
Some(ScenarioLayout {
|
||||
lanes: vec![],
|
||||
messages: vec![ScenarioMessagePosition {
|
||||
address: OccurrenceEndpoint {
|
||||
references: vec![],
|
||||
occurrence: second,
|
||||
},
|
||||
send_y: 240.,
|
||||
}],
|
||||
}),
|
||||
Some(ScenarioLayout {
|
||||
lanes: vec![ScenarioLanePosition {
|
||||
lifeline: left,
|
||||
x: -0.,
|
||||
}],
|
||||
messages: vec![],
|
||||
}),
|
||||
];
|
||||
for (index, layout) in layouts.into_iter().enumerate() {
|
||||
let (mut document, a, _) = fixture(layout);
|
||||
let owner = id(document.project(), "conversation");
|
||||
document
|
||||
.execute(Command::Rename(owner, "A real redo entry".into()))
|
||||
.unwrap();
|
||||
let redo = document.snapshot();
|
||||
assert!(document.undo());
|
||||
let before = document.snapshot();
|
||||
let revision = document.revision();
|
||||
let target = if index == 3 {
|
||||
Target::Lane(left)
|
||||
} else {
|
||||
Target::Message(second)
|
||||
};
|
||||
let drag = capture(document.project(), a, target).unwrap();
|
||||
if index == 3 {
|
||||
let Some(DiagramLayout::Scenario(layout)) = &drag.original.diagrams[&a].layout else {
|
||||
panic!()
|
||||
};
|
||||
assert_eq!(layout.lanes[0].x.to_bits(), (-0_f32).to_bits());
|
||||
}
|
||||
assert!(drag.prepare(10.).unwrap().is_some());
|
||||
for delta in [0., -0.] {
|
||||
assert!(drag.prepare(delta).unwrap().is_none());
|
||||
}
|
||||
if index != 3 {
|
||||
assert!(drag.prepare(f32::from_bits(1)).unwrap().is_none());
|
||||
}
|
||||
assert_eq!(
|
||||
serde_json::to_vec(&drag.original).unwrap(),
|
||||
serde_json::to_vec(document.project()).unwrap()
|
||||
);
|
||||
assert!(std::sync::Arc::ptr_eq(&before, &document.snapshot()));
|
||||
assert_eq!(document.bundle(), &before.bundle);
|
||||
assert_eq!(document.revision(), revision);
|
||||
assert!(document.can_redo());
|
||||
assert!(document.redo());
|
||||
assert_eq!(document.project(), &redo.decoded.project);
|
||||
assert_eq!(document.bundle(), &redo.bundle);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn malformed_or_out_of_range_motion_cannot_mutate_original() {
|
||||
let (document, a, _) = fixture(None);
|
||||
let drag = capture(
|
||||
document.project(),
|
||||
a,
|
||||
Target::Message(id(document.project(), "second")),
|
||||
)
|
||||
.unwrap();
|
||||
for delta in [f32::NAN, f32::INFINITY, f32::NEG_INFINITY] {
|
||||
assert!(matches!(drag.prepare(delta), Err(Refusal::InvalidDelta)));
|
||||
}
|
||||
assert!(matches!(drag.prepare(f32::MAX), Err(Refusal::Command(_))));
|
||||
assert_eq!(&drag.original, document.project());
|
||||
assert!(!document.dirty() && !document.can_undo());
|
||||
}
|
||||
|
||||
const FIXTURE: &str = r#"arcadia 7;
|
||||
project spacing_probe "Saved spacing probe" 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; }; }; }
|
||||
}
|
||||
"#;
|
||||
@@ -1,6 +1,5 @@
|
||||
//! Navigation is derived from the same opaque-reference scene that is painted.
|
||||
use super::*;
|
||||
use crate::behavior::scenario_layout::{Representation, presentation};
|
||||
use crate::diagram_usage::{Surface, Target, Usage};
|
||||
|
||||
/// The renderer collapses whitespace before shortening. Require at least one
|
||||
@@ -23,14 +22,7 @@ fn label_field_visible(full: &str, prefix: &str, value: &str) -> bool {
|
||||
start < retained
|
||||
}
|
||||
|
||||
fn usages(
|
||||
p: &Project,
|
||||
owner: Id,
|
||||
subject: Id,
|
||||
surface: Surface,
|
||||
bounds: Rectangle,
|
||||
scene: &Scene,
|
||||
) -> Vec<Usage> {
|
||||
fn usages(p: &Project, owner: Id, subject: Id, scene: &Scene) -> Vec<Usage> {
|
||||
let mut result = Vec::new();
|
||||
let mut add = |id, bounds, role: &str| {
|
||||
// Activation bars share the occurrence identity with a labelled message;
|
||||
@@ -41,7 +33,7 @@ fn usages(
|
||||
{
|
||||
result.push(Usage {
|
||||
subject,
|
||||
surface,
|
||||
surface: Surface::Scenario(owner),
|
||||
target: Target::ScenarioObject(id),
|
||||
role: role.into(),
|
||||
bounds,
|
||||
@@ -145,15 +137,15 @@ fn usages(
|
||||
}
|
||||
}
|
||||
}
|
||||
if subject == owner || subject == surface.id() {
|
||||
if subject == owner {
|
||||
result.insert(
|
||||
0,
|
||||
Usage {
|
||||
subject,
|
||||
surface,
|
||||
surface: Surface::Scenario(owner),
|
||||
target: Target::Whole,
|
||||
role: "scenario".into(),
|
||||
bounds,
|
||||
bounds: Rectangle::new(Point::ORIGIN, scene.size),
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -161,29 +153,15 @@ fn usages(
|
||||
}
|
||||
|
||||
impl State {
|
||||
/// Membership comes from the complete presentation chosen for this exact view,
|
||||
/// including automatic fallback geometry while retaining its Saved identity.
|
||||
pub(crate) fn representation_usages(
|
||||
&self,
|
||||
p: &Project,
|
||||
representation: Representation,
|
||||
subject: Id,
|
||||
) -> Vec<Usage> {
|
||||
let shown = presentation::present(p, representation, subject);
|
||||
let (Some(owner), Some(bounds), Some(scene)) =
|
||||
(shown.owner(), shown.bounds(), shown.scene())
|
||||
else {
|
||||
return vec![];
|
||||
};
|
||||
let surface = match representation {
|
||||
Representation::Derived { owner } => Surface::Scenario(owner),
|
||||
Representation::Saved { diagram } => Surface::Saved(diagram),
|
||||
};
|
||||
usages(p, owner, subject, surface, bounds, scene)
|
||||
}
|
||||
|
||||
pub(crate) fn diagram_usages(&self, p: &Project, owner: Id, subject: Id) -> Vec<Usage> {
|
||||
self.representation_usages(p, Representation::Derived { owner }, subject)
|
||||
if !p
|
||||
.elements
|
||||
.get(&owner)
|
||||
.is_some_and(|e| e.kind() == Kind::Scenario)
|
||||
{
|
||||
return vec![];
|
||||
}
|
||||
usages(p, owner, subject, &Scene::sequence(p, owner, subject))
|
||||
}
|
||||
|
||||
pub(crate) fn reveal_usage(
|
||||
@@ -193,24 +171,12 @@ impl State {
|
||||
owner: Id,
|
||||
target: &Target,
|
||||
) -> bool {
|
||||
self.reveal_representation_usage(
|
||||
p,
|
||||
document,
|
||||
owner,
|
||||
Representation::Derived { owner },
|
||||
target,
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn reveal_representation_usage(
|
||||
&mut self,
|
||||
p: &Project,
|
||||
document: Id,
|
||||
owner: Id,
|
||||
representation: Representation,
|
||||
target: &Target,
|
||||
) -> bool {
|
||||
if self.draft.is_some() || presentation::checked_owner(p, representation) != Some(owner) {
|
||||
if self.draft.is_some()
|
||||
|| !p
|
||||
.elements
|
||||
.get(&owner)
|
||||
.is_some_and(|e| e.kind() == Kind::Scenario)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
let id = match target {
|
||||
@@ -219,7 +185,7 @@ impl State {
|
||||
_ => return false,
|
||||
};
|
||||
let Some(usage) = self
|
||||
.representation_usages(p, representation, id)
|
||||
.diagram_usages(p, owner, id)
|
||||
.into_iter()
|
||||
.find(|u| &u.target == target)
|
||||
else {
|
||||
@@ -227,29 +193,11 @@ impl State {
|
||||
};
|
||||
// Preserve an existing mounted viewport across enter's owner reset.
|
||||
let viewport = self.presentation.viewport.unwrap_or(Size::new(500., 300.));
|
||||
if !viewport.width.is_finite()
|
||||
|| !viewport.height.is_finite()
|
||||
|| viewport.width <= 0.
|
||||
|| viewport.height <= 0.
|
||||
{
|
||||
return false;
|
||||
}
|
||||
let (zoom, pan) = if matches!(target, Target::Whole) {
|
||||
let Some(camera) = super::camera::fit(usage.bounds, viewport) else {
|
||||
return false;
|
||||
};
|
||||
(None, camera.pan)
|
||||
} else {
|
||||
let (zoom, pan) = crate::diagram_usage::camera_for(target, usage.bounds, viewport);
|
||||
if !zoom.is_finite() || !pan.x.is_finite() || !pan.y.is_finite() {
|
||||
return false;
|
||||
}
|
||||
(Some(zoom), pan)
|
||||
};
|
||||
self.enter_representation(document, owner, representation);
|
||||
self.enter(document, owner);
|
||||
self.presentation.viewport = Some(viewport);
|
||||
self.canvas_tool = Some((owner, CanvasTool::Select));
|
||||
self.presentation.zoom(zoom);
|
||||
let (zoom, pan) = crate::diagram_usage::camera_for(target, usage.bounds, viewport);
|
||||
self.presentation.zoom(Some(zoom));
|
||||
self.presentation.pan = pan;
|
||||
true
|
||||
}
|
||||
|
||||
@@ -10,10 +10,10 @@ fn add_occurrence(p: &mut Project, owner: Id, name: &str, body: OccurrenceBody)
|
||||
precondition: String::new(),
|
||||
postcondition: String::new(),
|
||||
};
|
||||
if let Some(steps) = p.elements.get_mut(&owner).unwrap().steps_mut()
|
||||
&& !steps.contains(&id)
|
||||
{
|
||||
steps.push(id);
|
||||
if let Some(steps) = p.elements.get_mut(&owner).unwrap().steps_mut() {
|
||||
if !steps.contains(&id) {
|
||||
steps.push(id);
|
||||
}
|
||||
}
|
||||
id
|
||||
}
|
||||
|
||||
@@ -13,8 +13,6 @@ pub enum Shelf {
|
||||
#[derive(Clone, Default)]
|
||||
pub(super) struct Presentation {
|
||||
pub(super) identity: Option<(Id, Id)>,
|
||||
pub(super) representation: Option<Representation>,
|
||||
pub(super) visit: Id,
|
||||
pub(super) viewport: Option<Size>,
|
||||
pub(super) focused: bool,
|
||||
pub(super) shelf: Option<Shelf>,
|
||||
@@ -22,6 +20,7 @@ pub(super) struct Presentation {
|
||||
pub(super) zoom: Option<f32>,
|
||||
pub(super) fit: bool,
|
||||
}
|
||||
const MIN_SCALE: f32 = 0.05;
|
||||
impl Presentation {
|
||||
pub(super) fn viewport(&mut self, size: Size) -> bool {
|
||||
if !size.width.is_finite()
|
||||
@@ -36,26 +35,29 @@ impl Presentation {
|
||||
true
|
||||
}
|
||||
pub(super) fn zoom(&mut self, scale: Option<f32>) -> bool {
|
||||
camera::set_zoom(&mut self.pan, &mut self.zoom, &mut self.fit, scale)
|
||||
if scale.is_some_and(|value| !value.is_finite() || value <= 0.) {
|
||||
return false;
|
||||
}
|
||||
let next = scale.map(|value| value.clamp(MIN_SCALE, 3.));
|
||||
let changed = self.zoom != next || self.fit != scale.is_none();
|
||||
self.zoom = next;
|
||||
self.fit = scale.is_none();
|
||||
changed
|
||||
}
|
||||
pub(super) fn camera(&self, bounds: Rectangle) -> camera::Camera {
|
||||
camera::effective_camera(self.pan, self.zoom, self.fit, self.viewport, bounds)
|
||||
fn fit_scale(&self, scene: Size) -> Option<f32> {
|
||||
let viewport = self.viewport?;
|
||||
// Fit uses the actual mounted viewport with a small visual gutter.
|
||||
Some(
|
||||
((viewport.width - 16.).max(1.) / scene.width.max(1.))
|
||||
.min((viewport.height - 16.).max(1.) / scene.height.max(1.)),
|
||||
)
|
||||
}
|
||||
// Legacy tests call size-only scale; actual display always passes full bounds.
|
||||
#[cfg(test)]
|
||||
pub(super) fn scale(&self, size: Size) -> f32 {
|
||||
self.camera(Rectangle::new(Point::ORIGIN, size)).scale
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
struct ArrangementChoice {
|
||||
representation: Representation,
|
||||
label: String,
|
||||
}
|
||||
impl std::fmt::Display for ArrangementChoice {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str(&self.label)
|
||||
pub(super) fn scale(&self, scene: Size) -> f32 {
|
||||
if self.fit {
|
||||
self.fit_scale(scene).unwrap_or(1.).clamp(MIN_SCALE, 1.)
|
||||
} else {
|
||||
self.zoom.unwrap_or(1.)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,136 +69,43 @@ pub fn view<'a>(app: &'a App, owner: Id, out: Column<'a, Message>) -> Element<'a
|
||||
.draft
|
||||
.as_ref()
|
||||
.is_some_and(|draft| draft.owner == owner);
|
||||
let Some(context) = app.scenario_context() else {
|
||||
return column![
|
||||
out,
|
||||
text("Scenario view is unavailable."),
|
||||
button("Open selected source").on_press(Message::SourceForSelection)
|
||||
]
|
||||
.spacing(8)
|
||||
.into();
|
||||
};
|
||||
let context = app.scenario_context().expect("visible scenario context");
|
||||
let tool = state.canvas_tool(owner);
|
||||
let clean = !app.behavior.has_pending() && !app.draft_dirty() && !app.source_dirty();
|
||||
// Resolve once per accepted view. An active spacing session owns its exact
|
||||
// prepared geometry; borrowing it also retains the canvas input state.
|
||||
let preview = state.spacing_paint(context, app.camera_epoch);
|
||||
let shown = preview
|
||||
.is_none()
|
||||
.then(|| presentation::present(p, context.representation, app.selected));
|
||||
let capabilities = shown.as_ref().map_or(
|
||||
presentation::PresentationCapabilities {
|
||||
geometry_navigation: true,
|
||||
coordinate_input: true,
|
||||
},
|
||||
ScenarioPresentation::capabilities,
|
||||
);
|
||||
let coordinate_input = clean && capabilities.coordinate_input;
|
||||
let notice = if let Some(paint) = &preview {
|
||||
display_notice_parts(
|
||||
p,
|
||||
context.representation,
|
||||
&presentation::PresentationStatus::Ready,
|
||||
paint.original_diagnostics,
|
||||
paint.original_latent,
|
||||
)
|
||||
} else {
|
||||
display_notice(p, shown.as_ref().expect("normal presentation"))
|
||||
};
|
||||
let camera_state = preview
|
||||
.as_ref()
|
||||
.map(|paint| camera::Camera {
|
||||
scale: paint.scene.scale,
|
||||
pan: paint.scene.camera_pan,
|
||||
})
|
||||
.or_else(|| {
|
||||
shown
|
||||
.as_ref()
|
||||
.and_then(ScenarioPresentation::bounds)
|
||||
.map(|bounds| presentation.camera(bounds))
|
||||
});
|
||||
let scale = camera_state.map_or(1., |camera| camera.scale);
|
||||
let mut scene = Scene::sequence(p, owner, app.selected);
|
||||
let scale = presentation.scale(scene.size);
|
||||
scene.scale = scale;
|
||||
scene.camera_pan = presentation.pan;
|
||||
scene.interaction = Some((context, tool, clean));
|
||||
scene.pending_placement = state.pending_placement(owner);
|
||||
let scope = super::super::canvas_workspace::Scope {
|
||||
document: context.document,
|
||||
owner,
|
||||
revision: context.revision,
|
||||
epoch: app.camera_epoch,
|
||||
scenario_view: Some((context.representation, context.visit)),
|
||||
};
|
||||
let keyboard = clean
|
||||
&& capabilities.geometry_navigation
|
||||
&& super::super::canvas_workspace::keyboard_enabled(app);
|
||||
let keyboard = clean && super::super::canvas_workspace::keyboard_enabled(app);
|
||||
let camera = move |e| Message::ScenarioCanvas(CanvasEvent::Camera(context, scope.epoch, e));
|
||||
let raw_canvas: Option<Element<'a, Message>> = if let Some(paint) = &preview {
|
||||
Some(
|
||||
canvas::Canvas::new(paint.scene)
|
||||
.width(Fill)
|
||||
.height(Fill)
|
||||
.into(),
|
||||
)
|
||||
} else if let Some(mut scene) = shown.and_then(ScenarioPresentation::into_scene) {
|
||||
let camera_state = camera_state.expect("displayed Scene has complete bounds");
|
||||
scene.scale = camera_state.scale;
|
||||
scene.camera_pan = camera_state.pan;
|
||||
scene.interaction = Some((context, tool, clean));
|
||||
scene.spacing_stamp = (coordinate_input
|
||||
&& !app.source_rename.open()
|
||||
&& keyboard
|
||||
&& matches!(context.representation, Representation::Saved { .. }))
|
||||
.then_some(spacing::Stamp {
|
||||
context,
|
||||
camera_epoch: app.camera_epoch,
|
||||
});
|
||||
scene.coordinate_input = capabilities.coordinate_input;
|
||||
scene.pending_placement = coordinate_input
|
||||
.then(|| state.pending_placement(owner))
|
||||
.flatten();
|
||||
Some(canvas::Canvas::new(scene).width(Fill).height(Fill).into())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let canvas: Element<'a, Message> = if let Some(raw_canvas) = raw_canvas {
|
||||
// Keep this Stack in both branches: replacing the Canvas with a wrapper
|
||||
// on Begin would discard its pointer capture before Move/Finish.
|
||||
let mut layers = iced::widget::stack![raw_canvas];
|
||||
if let Some(paint) = &preview {
|
||||
let feedback = spacing_feedback(p, paint.refusal, paint.diagnostics);
|
||||
layers = layers.push(
|
||||
container(
|
||||
container(text(feedback).size(12))
|
||||
.padding(6)
|
||||
.width(Fill)
|
||||
.style(style::card),
|
||||
)
|
||||
.width(Fill)
|
||||
.align_bottom(Fill)
|
||||
.padding(8),
|
||||
);
|
||||
}
|
||||
container(
|
||||
sensor(
|
||||
super::super::canvas_workspace::Viewport::new(
|
||||
layers, scope, scale, keyboard, camera,
|
||||
)
|
||||
.pan_background(tool == CanvasTool::Select || !capabilities.coordinate_input),
|
||||
let canvas = container(
|
||||
sensor(
|
||||
super::super::canvas_workspace::Viewport::new(
|
||||
canvas::Canvas::new(scene).width(Fill).height(Fill),
|
||||
scope,
|
||||
scale,
|
||||
keyboard,
|
||||
camera,
|
||||
)
|
||||
.key((
|
||||
context.document,
|
||||
format!("{:?}", context.representation),
|
||||
context.visit,
|
||||
))
|
||||
.on_show(move |size| Message::ScenarioCanvas(CanvasEvent::Viewport(context, size)))
|
||||
.on_resize(move |size| Message::ScenarioCanvas(CanvasEvent::Viewport(context, size))),
|
||||
.pan_background(tool == CanvasTool::Select),
|
||||
)
|
||||
.id("scenario-viewport")
|
||||
.width(Fill)
|
||||
.height(Fill)
|
||||
.style(style::card)
|
||||
.into()
|
||||
} else {
|
||||
container(text("No supported canvas geometry is available. Inspect the model or open its source to repair this view."))
|
||||
.id("scenario-viewport-unavailable").padding(16).width(Fill).height(Fill).style(style::card).into()
|
||||
};
|
||||
.key((context.document, owner))
|
||||
.on_show(move |size| Message::ScenarioCanvas(CanvasEvent::Viewport(context, size)))
|
||||
.on_resize(move |size| Message::ScenarioCanvas(CanvasEvent::Viewport(context, size))),
|
||||
)
|
||||
.id("scenario-viewport")
|
||||
.width(Fill)
|
||||
.height(Fill)
|
||||
.style(style::card)
|
||||
.into();
|
||||
let mut navigation = row![
|
||||
out.width(Fill),
|
||||
super::super::canvas_workspace::Control::new(
|
||||
@@ -232,54 +141,9 @@ pub fn view<'a>(app: &'a App, owner: Id, out: Column<'a, Message>) -> Element<'a
|
||||
clean.then_some(Message::ScenarioCanvas(CanvasEvent::Back(context))),
|
||||
));
|
||||
}
|
||||
let mut header = column![navigation, notice].spacing(4);
|
||||
let saved_views = p
|
||||
.diagrams
|
||||
.values()
|
||||
.filter(|diagram| {
|
||||
presentation::checked_owner(
|
||||
p,
|
||||
Representation::Saved {
|
||||
diagram: diagram.id,
|
||||
},
|
||||
) == Some(owner)
|
||||
})
|
||||
.map(|diagram| ArrangementChoice {
|
||||
representation: Representation::Saved {
|
||||
diagram: diagram.id,
|
||||
},
|
||||
label: short(&diagram.name, 64),
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
if !saved_views.is_empty() {
|
||||
let mut choices = vec![ArrangementChoice {
|
||||
representation: Representation::Derived { owner },
|
||||
label: "Automatic arrangement".into(),
|
||||
}];
|
||||
choices.extend(saved_views);
|
||||
let selected = choices
|
||||
.iter()
|
||||
.find(|choice| choice.representation == context.representation)
|
||||
.cloned();
|
||||
header = header.push(
|
||||
container(
|
||||
pick_list(choices, selected, move |choice: ArrangementChoice| {
|
||||
Message::ScenarioCanvas(CanvasEvent::Representation(
|
||||
context,
|
||||
choice.representation,
|
||||
))
|
||||
})
|
||||
.placeholder("Choose arrangement")
|
||||
.text_size(12)
|
||||
.padding(5)
|
||||
.width(Fill),
|
||||
)
|
||||
.width(Fill)
|
||||
.id("scenario-arrangement-picker"),
|
||||
);
|
||||
}
|
||||
if capabilities.geometry_navigation {
|
||||
header = header.push(super::super::canvas_workspace::controls(
|
||||
let header = column![
|
||||
navigation,
|
||||
super::super::canvas_workspace::controls(
|
||||
scope,
|
||||
keyboard,
|
||||
scale,
|
||||
@@ -287,22 +151,15 @@ pub fn view<'a>(app: &'a App, owner: Id, out: Column<'a, Message>) -> Element<'a
|
||||
clean.then_some(Message::ScenarioCanvas(CanvasEvent::Camera(
|
||||
context,
|
||||
scope.epoch,
|
||||
super::super::canvas_workspace::Event::Focus,
|
||||
super::super::canvas_workspace::Event::Focus
|
||||
))),
|
||||
move |zoom| Message::ScenarioCanvas(CanvasEvent::Zoom(context, zoom)),
|
||||
camera,
|
||||
));
|
||||
}
|
||||
camera
|
||||
)
|
||||
]
|
||||
.spacing(4);
|
||||
let entries = [
|
||||
(
|
||||
"S",
|
||||
if matches!(context.representation, Representation::Saved { .. }) {
|
||||
"Select / move messages and lifelines"
|
||||
} else {
|
||||
"Select / reorder occurrences"
|
||||
},
|
||||
CanvasTool::Select,
|
||||
),
|
||||
("S", "Select / reorder occurrences", CanvasTool::Select),
|
||||
(
|
||||
"L",
|
||||
"Lifeline: click to choose represented work or participant",
|
||||
@@ -369,21 +226,16 @@ pub fn view<'a>(app: &'a App, owner: Id, out: Column<'a, Message>) -> Element<'a
|
||||
glyph,
|
||||
label,
|
||||
choice == tool,
|
||||
(clean && (choice == CanvasTool::Select || capabilities.coordinate_input))
|
||||
.then_some(Message::ScenarioCanvas(CanvasEvent::Choose(
|
||||
context, choice,
|
||||
))),
|
||||
clean.then_some(Message::ScenarioCanvas(CanvasEvent::Choose(
|
||||
context, choice,
|
||||
))),
|
||||
)
|
||||
}),
|
||||
);
|
||||
let mut details = column![
|
||||
text(format!("Selected: {}", p.named(app.selected))).size(12),
|
||||
container(button(text("Properties").size(12)).on_press_maybe(
|
||||
(clean && properties_target(p, context, app.selected)).then_some(
|
||||
Message::ScenarioCanvas(CanvasEvent::Properties(context, app.selected)),
|
||||
),
|
||||
))
|
||||
.id("scenario-properties")
|
||||
button(text("Properties").size(12))
|
||||
.on_press_maybe(clean.then_some(Message::EditProperties(app.selected)))
|
||||
]
|
||||
.spacing(6);
|
||||
if referenced_scenario(p, owner, app.selected).is_some() {
|
||||
@@ -394,10 +246,6 @@ pub fn view<'a>(app: &'a App, owner: Id, out: Column<'a, Message>) -> Element<'a
|
||||
))),
|
||||
));
|
||||
}
|
||||
details = details.push(text("Scenario order").size(13));
|
||||
if matches!(context.representation, Representation::Saved { .. }) {
|
||||
details = details.push(text("↑ and ↓ change the shared Scenario order. Saved message positions are retained; automatically placed items may move.").size(11));
|
||||
}
|
||||
let details = details_pane(
|
||||
context,
|
||||
state.scroll_restore(context, ScrollArea::Page),
|
||||
@@ -727,153 +575,6 @@ pub fn view<'a>(app: &'a App, owner: Id, out: Column<'a, Message>) -> Element<'a
|
||||
super::super::canvas_workspace::host(header.into(), palette, canvas, editor)
|
||||
}
|
||||
|
||||
fn display_notice<'a>(p: &Project, shown: &ScenarioPresentation) -> Element<'a, Message> {
|
||||
display_notice_parts(
|
||||
p,
|
||||
shown.requested(),
|
||||
shown.status(),
|
||||
shown.diagnostics(),
|
||||
shown.latent_messages(),
|
||||
)
|
||||
}
|
||||
|
||||
fn display_notice_parts<'a>(
|
||||
p: &Project,
|
||||
requested: Representation,
|
||||
status: &presentation::PresentationStatus,
|
||||
diagnostics: &[super::super::scenario_layout::Diagnostic],
|
||||
latent_messages: &[Id],
|
||||
) -> Element<'a, Message> {
|
||||
use super::super::scenario_layout::{Diagnostic, presentation::PresentationStatus};
|
||||
let title = match requested {
|
||||
Representation::Saved { diagram } => p.diagrams.get(&diagram).map_or_else(
|
||||
|| "Unavailable saved Scenario view".into(),
|
||||
|view| format!("Saved view · {}", view.name),
|
||||
),
|
||||
Representation::Derived { owner } => format!("Automatic view · {}", p.named(owner)),
|
||||
};
|
||||
let mut notice = column![text(title).size(14)].spacing(4);
|
||||
match status {
|
||||
PresentationStatus::Ready => {
|
||||
for diagnostic in diagnostics.iter().take(3) {
|
||||
let explanation = match diagnostic {
|
||||
Diagnostic::SourceOrderCrossing { before, after, .. } => format!(
|
||||
"Saved spacing places '{}' below '{}'. The Scenario order is unchanged.",
|
||||
p.named(*before),
|
||||
p.named(*after)
|
||||
),
|
||||
Diagnostic::FrameExtendsPastFollowingAnchor { frame, following } => format!(
|
||||
"Saved spacing makes '{}' overlap '{}'. Both keep their saved positions.",
|
||||
p.named(*frame),
|
||||
p.named(*following)
|
||||
),
|
||||
};
|
||||
notice = notice.push(text(explanation).size(12));
|
||||
}
|
||||
if diagnostics.len() > 3 {
|
||||
notice = notice.push(
|
||||
text(format!(
|
||||
"{} additional spacing notices are retained.",
|
||||
diagnostics.len() - 3
|
||||
))
|
||||
.size(12),
|
||||
);
|
||||
}
|
||||
}
|
||||
PresentationStatus::Fallback { requested_issues } => {
|
||||
notice = notice.push(text("Showing the complete automatic arrangement because the saved positions cannot currently be displayed. Saved positions are preserved.").size(12));
|
||||
if let Some(issue) = requested_issues.first() {
|
||||
notice = notice.push(text(geometry_problem(p, issue)).size(12));
|
||||
}
|
||||
notice = notice.push(text("Selection, navigation and Fit remain available. Canvas insertion and reordering are unavailable until the saved positions are repaired.").size(12));
|
||||
}
|
||||
PresentationStatus::Unavailable { .. } => {
|
||||
notice = notice.push(text("This view is unavailable. Its identity or automatic geometry cannot be resolved; the model and source remain available for inspection and repair.").size(12));
|
||||
}
|
||||
}
|
||||
if !latent_messages.is_empty() {
|
||||
notice = notice.push(text(format!("{} unfinished message position(s) are retained until their endpoints are complete.", latent_messages.len())).size(12));
|
||||
}
|
||||
notice = notice.push(button("Open selected source").on_press(Message::SourceForSelection));
|
||||
container(notice)
|
||||
.id("scenario-display-notice")
|
||||
.padding(6)
|
||||
.width(Fill)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn spacing_feedback(
|
||||
p: &Project,
|
||||
refusal: Option<&spacing::Refusal>,
|
||||
diagnostics: &[super::super::scenario_layout::Diagnostic],
|
||||
) -> String {
|
||||
if let Some(refusal) = refusal {
|
||||
let reason = match refusal {
|
||||
spacing::Refusal::Geometry(issues) => issues
|
||||
.first()
|
||||
.map(|issue| geometry_problem(p, issue))
|
||||
.unwrap_or_else(|| "This position cannot be displayed.".into()),
|
||||
spacing::Refusal::Command(error) => error.clone(),
|
||||
_ => "This position is unavailable in the current view.".into(),
|
||||
};
|
||||
return format!(
|
||||
"Position unavailable · {reason} Move back to a supported position, or release to cancel."
|
||||
);
|
||||
}
|
||||
let explanation = match diagnostics.first() {
|
||||
Some(super::super::scenario_layout::Diagnostic::SourceOrderCrossing {
|
||||
before,
|
||||
after,
|
||||
..
|
||||
}) => format!(
|
||||
" '{}' is below '{}'; Scenario order stays unchanged.",
|
||||
p.named(*before),
|
||||
p.named(*after)
|
||||
),
|
||||
Some(super::super::scenario_layout::Diagnostic::FrameExtendsPastFollowingAnchor {
|
||||
frame,
|
||||
following,
|
||||
}) => format!(" '{}' overlaps '{}'.", p.named(*frame), p.named(*following)),
|
||||
None => " Scenario order stays unchanged.".into(),
|
||||
};
|
||||
format!("Spacing preview · Release to finish; Escape cancels.{explanation}")
|
||||
}
|
||||
|
||||
fn geometry_problem(p: &Project, issue: &super::super::scenario_layout::GeometryIssue) -> String {
|
||||
use super::super::scenario_layout::GeometryIssue;
|
||||
match issue {
|
||||
GeometryIssue::TypedActivationCrossingNotSupported { call, event } => format!(
|
||||
"The position of '{}' conflicts with the execution of '{}'.",
|
||||
p.named(*event),
|
||||
p.named(*call)
|
||||
),
|
||||
GeometryIssue::CoincidentDistinctEndpoints(message) => format!(
|
||||
"The distinct endpoints of '{}' have the same horizontal position.",
|
||||
p.named(*message)
|
||||
),
|
||||
GeometryIssue::TypedActivationOutsideLifetime { call, .. }
|
||||
| GeometryIssue::TypedActivationOutsideScope { call, .. } => format!(
|
||||
"The position of '{}' falls outside its supported execution interval.",
|
||||
p.named(*call)
|
||||
),
|
||||
GeometryIssue::FixedFrameHeaderWouldMove { frame } => format!(
|
||||
"The saved spacing would move the fixed header of '{}'.",
|
||||
p.named(*frame)
|
||||
),
|
||||
GeometryIssue::OperandScopeOutsideEnclosingInterval { operand, .. } => format!(
|
||||
"The spacing of '{}' extends outside its enclosing frame.",
|
||||
p.named(*operand)
|
||||
),
|
||||
GeometryIssue::LifecycleGeometryNotSupported { .. }
|
||||
| GeometryIssue::LifecycleAnchorOutsideRenderScope { .. }
|
||||
| GeometryIssue::LifetimeInversionNotSupported { .. } => {
|
||||
"The saved spacing cannot preserve the participant lifetime geometry.".into()
|
||||
}
|
||||
_ => "These saved positions are outside the geometry currently supported by the canvas."
|
||||
.into(),
|
||||
}
|
||||
}
|
||||
|
||||
fn sequence_action<'a>(
|
||||
title: &str,
|
||||
message: Message,
|
||||
@@ -930,12 +631,6 @@ fn editor_panel<'a, R: iced::advanced::text::Renderer + 'a>(
|
||||
#[cfg(all(test, debug_assertions))]
|
||||
mod tests;
|
||||
|
||||
#[cfg(all(test, debug_assertions))]
|
||||
mod spacing_tests;
|
||||
|
||||
#[cfg(all(test, debug_assertions))]
|
||||
mod details_tests;
|
||||
|
||||
fn sequence_rows<'a>(
|
||||
p: &'a Project,
|
||||
context: Context,
|
||||
|
||||
@@ -1,443 +0,0 @@
|
||||
//! Mounted Scenario Details → inspector regression and retained-intent guards.
|
||||
use super::*;
|
||||
use crate::behavior::canvas_workspace::tests::Mounted;
|
||||
use crate::behavior::scenario_layout::resolve;
|
||||
use iced::advanced::widget;
|
||||
use iced::{Vector, keyboard};
|
||||
use std::sync::Arc;
|
||||
|
||||
const FIXTURE: &str = include_str!("../../../app/diagram_usages/tests/saved_scenario.arcadia");
|
||||
|
||||
fn id(app: &App, alias: &str) -> Id {
|
||||
app.project()
|
||||
.identities()
|
||||
.into_iter()
|
||||
.find(|(_, name)| *name == alias)
|
||||
.unwrap()
|
||||
.0
|
||||
}
|
||||
fn send(app: &mut App, event: impl FnOnce(Context) -> CanvasEvent) {
|
||||
let context = app.scenario_context().unwrap();
|
||||
let _ = app.update(Message::ScenarioCanvas(event(context)));
|
||||
}
|
||||
fn setup() -> (App, Id, Id) {
|
||||
let mut app = App::with_project(oa_core::language::parse(FIXTURE).unwrap());
|
||||
let owner = id(&app, "incident_response");
|
||||
let diagram = id(&app, "incident_readable");
|
||||
let message = id(&app, "initial_report");
|
||||
let _ = app.update(Message::Select(owner));
|
||||
let _ = app.update(Message::Diagram(crate::app::Choice {
|
||||
id: diagram,
|
||||
label: "A".into(),
|
||||
}));
|
||||
send(&mut app, |c| CanvasEvent::Select(c, message));
|
||||
app.window_size = Size::new(1440., 1000.);
|
||||
(app, diagram, message)
|
||||
}
|
||||
fn open_focused_details(app: &mut App) {
|
||||
if !app.behavior.scenario.focused() {
|
||||
send(app, CanvasEvent::Focus);
|
||||
}
|
||||
if app.behavior.scenario.presentation.shelf.is_none() {
|
||||
send(app, |c| CanvasEvent::Shelf(c, Shelf::Selection));
|
||||
}
|
||||
}
|
||||
fn stored_camera(app: &App) -> (Vector, Option<f32>, bool) {
|
||||
let p = &app.behavior.scenario.presentation;
|
||||
(p.pan, p.zoom, p.fit)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn focused_saved_details_opens_real_editable_inspector_and_returns_to_same_view() {
|
||||
let (mut app, diagram, message) = setup();
|
||||
let _ = app.update(Message::InspectorTab(
|
||||
crate::navigation::InspectorTab::Connections,
|
||||
));
|
||||
let mut mounted = Mounted::new(&mut app).await;
|
||||
open_focused_details(&mut app);
|
||||
mounted.settle(&mut app).await;
|
||||
let before = mounted.geometry(&app);
|
||||
assert!(!before.scrolls.contains_key(&widget::Id::new("inspector")));
|
||||
let (details, offset) = before.scrolls[&widget::Id::new("scenario-details")];
|
||||
let button = before.bounds("scenario-properties").center() - offset;
|
||||
assert!(
|
||||
details.contains(button),
|
||||
"Properties must be actually visible"
|
||||
);
|
||||
let context = app.scenario_context().unwrap();
|
||||
let camera = stored_camera(&app);
|
||||
let original = app.document.snapshot();
|
||||
let bundle = app.document.bundle().clone();
|
||||
let messages = mounted.click(&mut app, button).await;
|
||||
assert!(messages.iter().any(|event| matches!(event,
|
||||
Message::ScenarioCanvas(CanvasEvent::Properties(c, selected))
|
||||
if *c == context && *selected == message)));
|
||||
mounted.settle(&mut app).await;
|
||||
assert!(!app.behavior.scenario.focused());
|
||||
assert!(app.behavior.scenario.presentation.shelf.is_none());
|
||||
assert_eq!(
|
||||
app.inspector_tab,
|
||||
crate::navigation::InspectorTab::Properties
|
||||
);
|
||||
assert_eq!(app.selected, message);
|
||||
assert_eq!(app.active_diagram, Some(diagram));
|
||||
assert_eq!(app.page, crate::app::Page::Behavior);
|
||||
let current = app.scenario_context().unwrap();
|
||||
assert_eq!(current.representation, context.representation);
|
||||
assert_eq!(current.visit, context.visit);
|
||||
assert_eq!(
|
||||
stored_camera(&app),
|
||||
camera,
|
||||
"restoring panels retains camera intent"
|
||||
);
|
||||
assert!(Arc::ptr_eq(&original, &app.document.snapshot()));
|
||||
assert_eq!(app.document.bundle(), &bundle);
|
||||
assert!(!app.document.can_undo() && !app.document.can_redo());
|
||||
|
||||
let shown = mounted.geometry(&app);
|
||||
assert!(
|
||||
!shown
|
||||
.scrolls
|
||||
.contains_key(&widget::Id::new("scenario-details"))
|
||||
);
|
||||
let (inspector, offset) = shown.scrolls[&widget::Id::new("inspector")];
|
||||
assert!(inspector.width > 250. && inspector.height > 500.);
|
||||
// Production Properties places Name before the other scalar text inputs.
|
||||
// Account for the retained inspector scroll, rather than clicking content coordinates.
|
||||
let input = shown
|
||||
.text_inputs
|
||||
.iter()
|
||||
.map(|bounds| bounds.center() - offset)
|
||||
.filter(|point| inspector.contains(*point))
|
||||
.min_by(|a, b| a.y.total_cmp(&b.y))
|
||||
.expect("visible editable property");
|
||||
mounted.click(&mut app, input).await;
|
||||
let typed = mounted
|
||||
.batch(
|
||||
&mut app,
|
||||
&[iced::Event::Keyboard(keyboard::Event::KeyPressed {
|
||||
key: keyboard::Key::Character("x".into()),
|
||||
modified_key: keyboard::Key::Character("x".into()),
|
||||
physical_key: keyboard::key::Physical::Unidentified(
|
||||
keyboard::key::NativeCode::Unidentified,
|
||||
),
|
||||
location: keyboard::Location::Standard,
|
||||
modifiers: keyboard::Modifiers::empty(),
|
||||
text: Some("x".into()),
|
||||
repeat: false,
|
||||
})],
|
||||
mouse::Cursor::Available(input),
|
||||
)
|
||||
.await;
|
||||
assert!(
|
||||
typed
|
||||
.iter()
|
||||
.any(|message| matches!(message, Message::Field(path, _) if path == "/name")),
|
||||
"real Name editor must publish its edit: {typed:?}"
|
||||
);
|
||||
assert!(app.draft_dirty());
|
||||
assert!(
|
||||
Arc::ptr_eq(&original, &app.document.snapshot()),
|
||||
"typing is only a draft"
|
||||
);
|
||||
let _ = app.update(Message::RevertProperties);
|
||||
assert!(!app.draft_dirty());
|
||||
send(&mut app, CanvasEvent::Focus);
|
||||
mounted.settle(&mut app).await;
|
||||
let returned = mounted.geometry(&app);
|
||||
assert!(!returned.scrolls.contains_key(&widget::Id::new("inspector")));
|
||||
let viewport = returned.bounds("scenario-viewport");
|
||||
assert_eq!(app.selected, message);
|
||||
assert_eq!(app.scenario_context().unwrap().visit, context.visit);
|
||||
assert_eq!(
|
||||
app.scenario_context().unwrap().representation,
|
||||
context.representation
|
||||
);
|
||||
assert_eq!(stored_camera(&app), camera);
|
||||
let geometry = resolve(app.project(), context.representation, message).unwrap();
|
||||
let line = geometry
|
||||
.scene
|
||||
.lines
|
||||
.iter()
|
||||
.find(|line| line.id == message)
|
||||
.unwrap();
|
||||
let effective = app.behavior.scenario.presentation.camera(geometry.bounds);
|
||||
let point = viewport.position()
|
||||
+ effective.pan
|
||||
+ Vector::new(line.points[0].x, line.points[0].y) * effective.scale;
|
||||
assert!(
|
||||
viewport.contains(point),
|
||||
"the same selected message remains in fitted view"
|
||||
);
|
||||
assert!(Arc::ptr_eq(&original, &app.document.snapshot()));
|
||||
assert_eq!(app.document.bundle(), &bundle);
|
||||
assert!(!app.document.can_undo() && !app.document.can_redo());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn details_properties_refuses_pending_property_source_and_behavior_drafts_without_apply() {
|
||||
for kind in 0..3 {
|
||||
let (mut app, _, message) = setup();
|
||||
open_focused_details(&mut app);
|
||||
match kind {
|
||||
0 => {
|
||||
let _ = app.update(Message::Field(
|
||||
"/name".into(),
|
||||
"Retained property draft".into(),
|
||||
));
|
||||
assert!(app.draft_dirty());
|
||||
}
|
||||
1 => {
|
||||
let _ = app.update(Message::SourceEdit(
|
||||
iced::widget::text_editor::Action::Edit(
|
||||
iced::widget::text_editor::Edit::Insert('x'),
|
||||
),
|
||||
));
|
||||
assert!(app.source_dirty());
|
||||
}
|
||||
_ => {
|
||||
let owner = app.scenario_context().unwrap().scenario;
|
||||
let _ = app.update(Message::Behavior(super::super::super::Event::Scenario(
|
||||
Event::Start(owner, Tool::Lifeline),
|
||||
)));
|
||||
assert!(app.behavior.has_pending());
|
||||
}
|
||||
}
|
||||
let snapshot = app.document.snapshot();
|
||||
let bundle = app.document.bundle().clone();
|
||||
let property = app.draft.as_ref().unwrap().materialize();
|
||||
let source = app.source_editor.text();
|
||||
let behavior = app.behavior.recovery_snapshot();
|
||||
let camera = app.behavior.scenario.camera_boundary();
|
||||
let context = app.scenario_context().unwrap();
|
||||
let epochs = (app.canvas_epoch, app.camera_epoch);
|
||||
let _ = app.update(Message::ScenarioCanvas(CanvasEvent::Properties(
|
||||
context, message,
|
||||
)));
|
||||
assert!(app.behavior.scenario.camera_boundary() == camera);
|
||||
assert_eq!(app.scenario_context(), Some(context));
|
||||
assert_eq!((app.canvas_epoch, app.camera_epoch), epochs);
|
||||
assert_eq!(app.draft.as_ref().unwrap().materialize(), property);
|
||||
assert_eq!(app.source_editor.text(), source);
|
||||
assert_eq!(app.behavior.recovery_snapshot(), behavior);
|
||||
assert_eq!(app.selected, message);
|
||||
assert!(Arc::ptr_eq(&snapshot, &app.document.snapshot()));
|
||||
assert_eq!(app.document.bundle(), &bundle);
|
||||
assert!(!app.document.can_undo() && !app.document.can_redo());
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn focused_details_opens_current_saved_view_properties_after_following_diagram_picker() {
|
||||
let (mut app, a, _) = setup();
|
||||
let b = id(&app, "incident_wide");
|
||||
// Selecting the current view record makes the real picker follow that
|
||||
// record selection to B. Do not seed selected=B or its property draft.
|
||||
let _ = app.update(Message::Select(a));
|
||||
assert_eq!(app.selected, a);
|
||||
let _ = app.update(Message::Diagram(crate::app::Choice {
|
||||
id: b,
|
||||
label: "B".into(),
|
||||
}));
|
||||
assert_eq!(app.selected, b);
|
||||
assert_eq!(app.draft.as_ref().unwrap().original, b);
|
||||
assert_eq!(
|
||||
app.scenario_context().unwrap().representation,
|
||||
Representation::Saved { diagram: b }
|
||||
);
|
||||
let _ = app.update(Message::InspectorTab(
|
||||
crate::navigation::InspectorTab::Connections,
|
||||
));
|
||||
let mut mounted = Mounted::new(&mut app).await;
|
||||
open_focused_details(&mut app);
|
||||
mounted.settle(&mut app).await;
|
||||
let context = app.scenario_context().unwrap();
|
||||
let camera = stored_camera(&app);
|
||||
let snapshot = app.document.snapshot();
|
||||
let bundle = app.document.bundle().clone();
|
||||
let before = mounted.geometry(&app);
|
||||
assert!(!before.scrolls.contains_key(&widget::Id::new("inspector")));
|
||||
let (details, offset) = before.scrolls[&widget::Id::new("scenario-details")];
|
||||
let point = before.bounds("scenario-properties").center() - offset;
|
||||
assert!(details.contains(point));
|
||||
let events = mounted.click(&mut app, point).await;
|
||||
assert!(events.iter().any(|event| matches!(event,
|
||||
Message::ScenarioCanvas(CanvasEvent::Properties(c, selected))
|
||||
if *c == context && *selected == b)));
|
||||
mounted.settle(&mut app).await;
|
||||
let shown = mounted.geometry(&app);
|
||||
assert!(
|
||||
!shown
|
||||
.scrolls
|
||||
.contains_key(&widget::Id::new("scenario-details"))
|
||||
);
|
||||
let (inspector, offset) = shown.scrolls[&widget::Id::new("inspector")];
|
||||
assert!(
|
||||
shown
|
||||
.text_inputs
|
||||
.iter()
|
||||
.any(|bounds| inspector.contains(bounds.center() - offset)),
|
||||
"current Saved diagram has a visible editable inspector"
|
||||
);
|
||||
assert!(!app.behavior.scenario.focused());
|
||||
assert_eq!(
|
||||
app.inspector_tab,
|
||||
crate::navigation::InspectorTab::Properties
|
||||
);
|
||||
assert_eq!(app.selected, b);
|
||||
assert_eq!(app.draft.as_ref().unwrap().original, b);
|
||||
assert_eq!(app.active_diagram, Some(b));
|
||||
assert_eq!(app.page, crate::app::Page::Behavior);
|
||||
assert_eq!(
|
||||
app.scenario_context().unwrap().representation,
|
||||
context.representation
|
||||
);
|
||||
assert_eq!(app.scenario_context().unwrap().visit, context.visit);
|
||||
assert_eq!(stored_camera(&app), camera);
|
||||
assert!(Arc::ptr_eq(&snapshot, &app.document.snapshot()));
|
||||
assert_eq!(app.document.bundle(), &bundle);
|
||||
assert!(!app.document.can_undo() && !app.document.can_redo());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn details_properties_refuses_another_saved_view_even_with_the_same_scenario_owner() {
|
||||
let (mut app, a, _) = setup();
|
||||
let b = id(&app, "incident_wide");
|
||||
let _ = app.update(Message::Diagram(crate::app::Choice {
|
||||
id: b,
|
||||
label: "B".into(),
|
||||
}));
|
||||
let _ = app.update(Message::Select(a));
|
||||
assert_eq!(app.selected, a);
|
||||
open_focused_details(&mut app);
|
||||
let context = app.scenario_context().unwrap();
|
||||
assert_eq!(context.representation, Representation::Saved { diagram: b });
|
||||
assert_eq!(
|
||||
presentation::checked_owner(app.project(), Representation::Saved { diagram: a }),
|
||||
Some(context.scenario)
|
||||
);
|
||||
assert!(!properties_target(app.project(), context, a));
|
||||
let camera = app.behavior.scenario.camera_boundary();
|
||||
let epochs = (app.canvas_epoch, app.camera_epoch);
|
||||
let snapshot = app.document.snapshot();
|
||||
let bundle = app.document.bundle().clone();
|
||||
let _ = app.update(Message::ScenarioCanvas(CanvasEvent::Properties(context, a)));
|
||||
assert!(app.behavior.scenario.camera_boundary() == camera);
|
||||
assert_eq!((app.canvas_epoch, app.camera_epoch), epochs);
|
||||
assert_eq!(app.scenario_context(), Some(context));
|
||||
assert_eq!(app.selected, a);
|
||||
assert_eq!(app.draft.as_ref().unwrap().original, a);
|
||||
assert!(Arc::ptr_eq(&snapshot, &app.document.snapshot()));
|
||||
assert_eq!(app.document.bundle(), &bundle);
|
||||
assert!(!app.document.can_undo() && !app.document.can_redo());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn details_properties_rejects_retired_view_selection_and_epoch_without_changing_panels() {
|
||||
for kind in 0..3 {
|
||||
let (mut app, diagram, message) = setup();
|
||||
open_focused_details(&mut app);
|
||||
let captured = app.scenario_context().unwrap();
|
||||
match kind {
|
||||
0 => {
|
||||
let other = id(&app, "incident_wide");
|
||||
for view in [other, diagram] {
|
||||
let _ = app.update(Message::Diagram(crate::app::Choice {
|
||||
id: view,
|
||||
label: "view".into(),
|
||||
}));
|
||||
}
|
||||
open_focused_details(&mut app);
|
||||
assert_ne!(app.scenario_context().unwrap().visit, captured.visit);
|
||||
}
|
||||
1 => {
|
||||
let other = id(&app, "updated_report");
|
||||
send(&mut app, |c| CanvasEvent::Select(c, other));
|
||||
}
|
||||
_ => {
|
||||
send(&mut app, |c| CanvasEvent::Zoom(c, Some(0.5)));
|
||||
}
|
||||
}
|
||||
let camera = app.behavior.scenario.camera_boundary();
|
||||
let context = app.scenario_context();
|
||||
let selected = app.selected;
|
||||
let tab = app.inspector_tab;
|
||||
let epochs = (app.canvas_epoch, app.camera_epoch);
|
||||
let snapshot = app.document.snapshot();
|
||||
let bundle = app.document.bundle().clone();
|
||||
let _ = app.update(Message::ScenarioCanvas(CanvasEvent::Properties(
|
||||
captured, message,
|
||||
)));
|
||||
assert!(app.behavior.scenario.camera_boundary() == camera);
|
||||
assert_eq!(app.scenario_context(), context);
|
||||
assert_eq!(app.selected, selected);
|
||||
assert_eq!(app.inspector_tab, tab);
|
||||
assert_eq!((app.canvas_epoch, app.camera_epoch), epochs);
|
||||
assert!(Arc::ptr_eq(&snapshot, &app.document.snapshot()));
|
||||
assert_eq!(app.document.bundle(), &bundle);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opening_scenario_properties_cancels_held_spacing_and_rejects_its_late_finish() {
|
||||
use super::super::spacing::{Event as Spacing, Target, controller::tests::packet};
|
||||
let (mut app, _, message) = setup();
|
||||
send(&mut app, |c| {
|
||||
CanvasEvent::Viewport(c, Size::new(900., 600.))
|
||||
});
|
||||
open_focused_details(&mut app);
|
||||
let begin = packet(
|
||||
app.project(),
|
||||
&app.behavior.scenario,
|
||||
app.scenario_context().unwrap(),
|
||||
app.camera_epoch,
|
||||
Target::Message(message),
|
||||
);
|
||||
let Spacing::Begin { press_screen, .. } = begin else {
|
||||
panic!()
|
||||
};
|
||||
let _ = app.update(Message::ScenarioCanvas(CanvasEvent::Spacing(begin)));
|
||||
assert_eq!(app.behavior.scenario.spacing_token(), Some(begin.token()));
|
||||
let snapshot = app.document.snapshot();
|
||||
let end = press_screen + Vector::new(0., 12.);
|
||||
let _ = app.update(Message::ScenarioCanvas(CanvasEvent::Spacing(
|
||||
Spacing::Move {
|
||||
stamp: begin.stamp(),
|
||||
token: begin.token(),
|
||||
screen: end,
|
||||
},
|
||||
)));
|
||||
let paint = app
|
||||
.behavior
|
||||
.scenario
|
||||
.spacing_paint(begin.stamp().context, begin.stamp().camera_epoch)
|
||||
.unwrap();
|
||||
assert!(paint.refusal.is_none());
|
||||
let line = paint
|
||||
.scene
|
||||
.lines
|
||||
.iter()
|
||||
.find(|line| line.id == message)
|
||||
.unwrap();
|
||||
assert!(
|
||||
line.points[0].y > 160.,
|
||||
"a real proposed scene moved the first message"
|
||||
);
|
||||
assert!(
|
||||
Arc::ptr_eq(&snapshot, &app.document.snapshot()),
|
||||
"preview is not authored"
|
||||
);
|
||||
let camera = stored_camera(&app);
|
||||
send(&mut app, |c| CanvasEvent::Properties(c, message));
|
||||
assert!(app.behavior.scenario.spacing_token().is_none());
|
||||
assert_eq!(stored_camera(&app), camera);
|
||||
let _ = app.update(Message::ScenarioCanvas(CanvasEvent::Spacing(
|
||||
Spacing::Finish {
|
||||
stamp: begin.stamp(),
|
||||
token: begin.token(),
|
||||
screen: end,
|
||||
},
|
||||
)));
|
||||
assert!(Arc::ptr_eq(&snapshot, &app.document.snapshot()));
|
||||
assert!(!app.document.can_undo() && !app.document.can_redo());
|
||||
}
|
||||
@@ -1,438 +0,0 @@
|
||||
//! Real mounted widgets dispatch the gesture; expectations name authored fields
|
||||
//! and actual displayed anchors independently of controller command results.
|
||||
use super::*;
|
||||
use crate::behavior::canvas_workspace::tests::{Mounted, key};
|
||||
use crate::behavior::scenario_layout::{ResolvedScenarioPlan, resolve};
|
||||
use crate::document::Document;
|
||||
use iced::Vector;
|
||||
use std::sync::Arc;
|
||||
|
||||
const FIXTURE: &str = include_str!("../../../app/diagram_usages/tests/saved_scenario.arcadia");
|
||||
|
||||
fn id(app: &App, alias: &str) -> Id {
|
||||
app.project()
|
||||
.identities()
|
||||
.into_iter()
|
||||
.find(|(_, name)| *name == alias)
|
||||
.unwrap()
|
||||
.0
|
||||
}
|
||||
|
||||
async fn setup(fit: bool) -> (App, Mounted, Id) {
|
||||
let mut app = App::with_project(oa_core::language::parse(FIXTURE).unwrap());
|
||||
let owner = id(&app, "incident_response");
|
||||
let diagram = id(&app, "incident_readable");
|
||||
let _ = app.update(Message::Select(owner));
|
||||
let _ = app.update(Message::Diagram(crate::app::Choice {
|
||||
id: diagram,
|
||||
label: "A - Incident review readable".into(),
|
||||
}));
|
||||
app.window_size = Size::new(1440., 900.);
|
||||
let mut mounted = Mounted::new(&mut app).await;
|
||||
if !fit {
|
||||
let context = app.scenario_context().unwrap();
|
||||
let task = app.update(Message::ScenarioCanvas(CanvasEvent::Zoom(
|
||||
context,
|
||||
Some(0.5),
|
||||
)));
|
||||
mounted.perform(&mut app, task).await;
|
||||
mounted.settle(&mut app).await;
|
||||
}
|
||||
assert_eq!(
|
||||
app.scenario_context().unwrap().representation,
|
||||
Representation::Saved { diagram }
|
||||
);
|
||||
assert!(!app.document.can_undo() && !app.document.can_redo());
|
||||
(app, mounted, diagram)
|
||||
}
|
||||
|
||||
fn resolved(app: &App) -> ResolvedScenarioPlan {
|
||||
resolve(
|
||||
app.project(),
|
||||
app.scenario_context().unwrap().representation,
|
||||
app.selected,
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn stored_camera(app: &App) -> (Vector, Option<f32>, bool) {
|
||||
let p = &app.behavior.scenario.presentation;
|
||||
(p.pan, p.zoom, p.fit)
|
||||
}
|
||||
|
||||
fn screen(mounted: &mut Mounted, app: &App, world: Point) -> Point {
|
||||
let bounds = mounted.geometry(app).bounds("scenario-viewport");
|
||||
let geometry = resolved(app);
|
||||
let camera = app.behavior.scenario.presentation.camera(geometry.bounds);
|
||||
let point = bounds.position() + camera.pan + Vector::new(world.x, world.y) * camera.scale;
|
||||
assert!(
|
||||
bounds.contains(point),
|
||||
"actual visible world {world:?}: {point:?} in {bounds:?}"
|
||||
);
|
||||
point
|
||||
}
|
||||
|
||||
fn mouse_event(event: mouse::Event) -> iced::Event {
|
||||
iced::Event::Mouse(event)
|
||||
}
|
||||
|
||||
async fn press(mounted: &mut Mounted, app: &mut App, point: Point) -> Vec<Message> {
|
||||
mounted
|
||||
.batch(
|
||||
app,
|
||||
&[
|
||||
mouse_event(mouse::Event::CursorMoved { position: point }),
|
||||
mouse_event(mouse::Event::ButtonPressed(mouse::Button::Left)),
|
||||
],
|
||||
mouse::Cursor::Available(point),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn move_to(mounted: &mut Mounted, app: &mut App, point: Point) -> Vec<Message> {
|
||||
mounted
|
||||
.batch(
|
||||
app,
|
||||
&[mouse_event(mouse::Event::CursorMoved { position: point })],
|
||||
mouse::Cursor::Available(point),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn release(mounted: &mut Mounted, app: &mut App, point: Point) -> Vec<Message> {
|
||||
mounted
|
||||
.batch(
|
||||
app,
|
||||
&[mouse_event(mouse::Event::ButtonReleased(
|
||||
mouse::Button::Left,
|
||||
))],
|
||||
mouse::Cursor::Available(point),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
fn set_expected_message(project: &mut oa_core::Project, diagram: Id, occurrence: Id, y: f32) {
|
||||
let Some(oa_core::DiagramLayout::Scenario(layout)) =
|
||||
&mut project.diagrams.get_mut(&diagram).unwrap().layout
|
||||
else {
|
||||
panic!()
|
||||
};
|
||||
layout
|
||||
.messages
|
||||
.iter_mut()
|
||||
.find(|m| m.address.occurrence == occurrence)
|
||||
.unwrap()
|
||||
.send_y = y;
|
||||
}
|
||||
|
||||
fn set_expected_lane(project: &mut oa_core::Project, diagram: Id, lifeline: Id, x: f32) {
|
||||
let Some(oa_core::DiagramLayout::Scenario(layout)) =
|
||||
&mut project.diagrams.get_mut(&diagram).unwrap().layout
|
||||
else {
|
||||
panic!()
|
||||
};
|
||||
layout
|
||||
.lanes
|
||||
.iter_mut()
|
||||
.find(|lane| lane.lifeline == lifeline)
|
||||
.unwrap()
|
||||
.x = x;
|
||||
}
|
||||
|
||||
fn assert_reopens_exactly(app: &App) {
|
||||
let reopened = Document::from_bundle(
|
||||
app.document.bundle().clone(),
|
||||
oa_core::source_project::ProjectLimits::default(),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(reopened.project(), app.project());
|
||||
assert_eq!(reopened.bundle(), app.document.bundle());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn saved_message_same_batch_pointer_events_commit_once_and_one_undo_redo_restores_exact_source()
|
||||
{
|
||||
let (mut app, mut mounted, diagram) = setup(false).await;
|
||||
let target = id(&app, "updated_report");
|
||||
let before = app.document.snapshot();
|
||||
let revision = app.document.revision();
|
||||
let projected = screen(&mut mounted, &app, Point::new(400., 252.));
|
||||
// This fixture asks for exactly +20 world units. A fractional start near a
|
||||
// screen-coordinate exponent boundary need not retain an exact +10 delta.
|
||||
let start = Point::new(projected.x.round(), projected.y.round());
|
||||
let mut geometry = resolved(&app);
|
||||
let camera = app.behavior.scenario.presentation.camera(geometry.bounds);
|
||||
assert_eq!(camera.scale, 0.5);
|
||||
let bounds = mounted.geometry(&app).bounds("scenario-viewport");
|
||||
let world = Point::new(
|
||||
(start.x - bounds.x - camera.pan.x) / camera.scale,
|
||||
(start.y - bounds.y - camera.pan.y) / camera.scale,
|
||||
);
|
||||
geometry.scene.scale = camera.scale;
|
||||
geometry.scene.camera_pan = camera.pan;
|
||||
let hit = geometry.scene.hit_item(world).unwrap();
|
||||
assert_eq!(hit.id, target);
|
||||
assert_eq!(hit.role, crate::behavior::SceneHitRole::MessageBody);
|
||||
let end = start + Vector::new(0., 10.); // .5 display scale: +20 authored y.
|
||||
assert_eq!(end.y - start.y, 10.);
|
||||
assert!(bounds.contains(start) && bounds.contains(end));
|
||||
let messages = mounted
|
||||
.batch(
|
||||
&mut app,
|
||||
&[
|
||||
mouse_event(mouse::Event::CursorMoved { position: start }),
|
||||
mouse_event(mouse::Event::ButtonPressed(mouse::Button::Left)),
|
||||
mouse_event(mouse::Event::CursorMoved { position: end }),
|
||||
mouse_event(mouse::Event::ButtonReleased(mouse::Button::Left)),
|
||||
],
|
||||
mouse::Cursor::Available(end),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(
|
||||
messages
|
||||
.iter()
|
||||
.filter(|m| matches!(
|
||||
m,
|
||||
Message::ScenarioCanvas(CanvasEvent::Spacing(spacing::Event::Begin { .. }))
|
||||
))
|
||||
.count(),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
messages
|
||||
.iter()
|
||||
.filter(|m| matches!(
|
||||
m,
|
||||
Message::ScenarioCanvas(CanvasEvent::Spacing(spacing::Event::Finish { .. }))
|
||||
))
|
||||
.count(),
|
||||
1
|
||||
);
|
||||
let mut expected = before.decoded.project.clone();
|
||||
set_expected_message(&mut expected, diagram, target, 272.);
|
||||
assert_eq!(
|
||||
app.project(),
|
||||
&expected,
|
||||
"Only Saved A's addressed y changes; steps, other occurrences and B/C are exact"
|
||||
);
|
||||
assert_eq!(app.document.revision(), revision + 1);
|
||||
assert_eq!(app.selected, target);
|
||||
assert!(app.behavior.scenario.spacing_token().is_none());
|
||||
assert_reopens_exactly(&app);
|
||||
let after = app.document.snapshot();
|
||||
let task = app.update(Message::Undo);
|
||||
mounted.perform(&mut app, task).await;
|
||||
assert_eq!(app.project(), &before.decoded.project);
|
||||
assert_eq!(app.document.bundle(), &before.bundle);
|
||||
assert!(!app.document.can_undo() && app.document.can_redo());
|
||||
let task = app.update(Message::Redo);
|
||||
mounted.perform(&mut app, task).await;
|
||||
assert_eq!(app.project(), &after.decoded.project);
|
||||
assert_eq!(app.document.bundle(), &after.bundle);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn saved_header_preview_survives_frames_and_freezes_fit_while_actual_bounds_expand() {
|
||||
let (mut app, mut mounted, diagram) = setup(true).await;
|
||||
let assessor = id(&app, "assessor");
|
||||
let before = app.document.snapshot();
|
||||
let original = resolved(&app);
|
||||
let original_camera = app.behavior.scenario.presentation.camera(original.bounds);
|
||||
let stored = stored_camera(&app);
|
||||
assert!(stored.2, "test must exercise original Fit");
|
||||
let start = screen(&mut mounted, &app, Point::new(640., 45.));
|
||||
press(&mut mounted, &mut app, start).await;
|
||||
let token = app
|
||||
.behavior
|
||||
.scenario
|
||||
.spacing_token()
|
||||
.expect("actual header press begins");
|
||||
for x in [670., 700.] {
|
||||
let end = start + Vector::new((x - 640.) * original_camera.scale, 0.);
|
||||
move_to(&mut mounted, &mut app, end).await;
|
||||
mounted.settle(&mut app).await; // Actual borrowed Scene/Stack tree is rebuilt.
|
||||
assert_eq!(app.behavior.scenario.spacing_token(), Some(token));
|
||||
assert!(Arc::ptr_eq(&before, &app.document.snapshot()));
|
||||
assert_eq!(stored_camera(&app), stored);
|
||||
let paint = app
|
||||
.behavior
|
||||
.scenario
|
||||
.spacing_paint(app.scenario_context().unwrap(), app.camera_epoch)
|
||||
.unwrap();
|
||||
assert!(paint.refusal.is_none());
|
||||
assert!((paint.scene.render_lanes[&assessor] - x).abs() < 0.001);
|
||||
assert!(paint.bounds.width > original.bounds.width);
|
||||
assert_eq!(paint.scene.scale, original_camera.scale);
|
||||
assert_eq!(paint.scene.camera_pan, original_camera.pan);
|
||||
let header = paint.scene.boxes.iter().find(|b| b.id == assessor).unwrap();
|
||||
let displayed = Vector::new(header.rect.center().x, header.rect.center().y)
|
||||
* paint.scene.scale
|
||||
+ paint.scene.camera_pan;
|
||||
let baseline = Vector::new(640., 50.) * original_camera.scale + original_camera.pan;
|
||||
assert!((displayed.x - baseline.x - (x - 640.) * original_camera.scale).abs() < 0.001);
|
||||
assert_eq!(displayed.y, baseline.y);
|
||||
}
|
||||
let end = start + Vector::new(60. * original_camera.scale, 0.);
|
||||
release(&mut mounted, &mut app, end).await;
|
||||
let final_geometry = resolved(&app);
|
||||
let actual_x = final_geometry.scene.render_lanes[&assessor];
|
||||
assert!((actual_x - 700.).abs() < 0.001);
|
||||
let mut expected = before.decoded.project.clone();
|
||||
set_expected_lane(&mut expected, diagram, assessor, actual_x);
|
||||
assert_eq!(app.project(), &expected);
|
||||
let final_camera = app
|
||||
.behavior
|
||||
.scenario
|
||||
.presentation
|
||||
.camera(final_geometry.bounds);
|
||||
assert_eq!(
|
||||
final_camera, original_camera,
|
||||
"commit must not refit underneath pointer"
|
||||
);
|
||||
assert!(!app.behavior.scenario.presentation.fit);
|
||||
assert_eq!(app.selected, assessor);
|
||||
assert_reopens_exactly(&app);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn saved_body_and_header_clicks_select_without_materializing_spacing() {
|
||||
let (mut app, mut mounted, _) = setup(false).await;
|
||||
let before = app.document.snapshot();
|
||||
let original_camera = stored_camera(&app);
|
||||
for (alias, world) in [
|
||||
("updated_report", Point::new(400., 252.)),
|
||||
("assessor", Point::new(640., 45.)),
|
||||
] {
|
||||
let target = id(&app, alias);
|
||||
let point = screen(&mut mounted, &app, world);
|
||||
mounted.click(&mut app, point).await;
|
||||
assert_eq!(app.selected, target);
|
||||
assert!(app.behavior.scenario.spacing_token().is_none());
|
||||
assert!(Arc::ptr_eq(&before, &app.document.snapshot()));
|
||||
assert_eq!(stored_camera(&app), original_camera);
|
||||
}
|
||||
assert!(!app.document.can_undo() && !app.document.can_redo());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn saved_valid_preview_then_refused_self_call_never_commits_last_valid_candidate() {
|
||||
let (mut app, mut mounted, _) = setup(false).await;
|
||||
let target = id(&app, "assess_call");
|
||||
let before = app.document.snapshot();
|
||||
let camera = stored_camera(&app);
|
||||
let start = screen(&mut mounted, &app, Point::new(680., 344.));
|
||||
press(&mut mounted, &mut app, start).await;
|
||||
let valid = start + Vector::new(0., -10.); // send324, receive348, reply436 unchanged.
|
||||
move_to(&mut mounted, &mut app, valid).await;
|
||||
mounted.settle(&mut app).await;
|
||||
let paint = app
|
||||
.behavior
|
||||
.scenario
|
||||
.spacing_paint(app.scenario_context().unwrap(), app.camera_epoch)
|
||||
.unwrap();
|
||||
assert!(paint.refusal.is_none());
|
||||
let line = paint.scene.lines.iter().find(|l| l.id == target).unwrap();
|
||||
assert_eq!(line.points[0].y, 324.);
|
||||
assert_eq!(line.points.last().unwrap().y, 348.);
|
||||
let refused = start + Vector::new(0., 53.); // send450, receive474 would follow reply436.
|
||||
move_to(&mut mounted, &mut app, refused).await;
|
||||
mounted.settle(&mut app).await;
|
||||
let paint = app
|
||||
.behavior
|
||||
.scenario
|
||||
.spacing_paint(app.scenario_context().unwrap(), app.camera_epoch)
|
||||
.unwrap();
|
||||
assert!(paint.refusal.is_some());
|
||||
assert_eq!(
|
||||
paint
|
||||
.scene
|
||||
.lines
|
||||
.iter()
|
||||
.find(|l| l.id == target)
|
||||
.unwrap()
|
||||
.points[0]
|
||||
.y,
|
||||
344.
|
||||
);
|
||||
assert!(Arc::ptr_eq(&before, &app.document.snapshot()));
|
||||
release(&mut mounted, &mut app, refused).await;
|
||||
assert!(app.behavior.scenario.spacing_token().is_none());
|
||||
assert!(Arc::ptr_eq(&before, &app.document.snapshot()));
|
||||
assert_eq!(stored_camera(&app), camera);
|
||||
assert!(!app.document.can_undo() && !app.document.can_redo());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn saved_escape_and_outside_pointer_cancel_actual_held_preview() {
|
||||
for escape in [true, false] {
|
||||
let (mut app, mut mounted, _) = setup(false).await;
|
||||
let before = app.document.snapshot();
|
||||
let camera = stored_camera(&app);
|
||||
let start = screen(&mut mounted, &app, Point::new(400., 252.));
|
||||
let end = start + Vector::new(0., 10.);
|
||||
press(&mut mounted, &mut app, start).await;
|
||||
move_to(&mut mounted, &mut app, end).await;
|
||||
mounted.settle(&mut app).await;
|
||||
assert!(app.behavior.scenario.spacing_token().is_some());
|
||||
let release_at = if escape {
|
||||
mounted
|
||||
.batch(
|
||||
&mut app,
|
||||
&[key(iced::keyboard::key::Named::Escape)],
|
||||
mouse::Cursor::Available(end),
|
||||
)
|
||||
.await;
|
||||
end
|
||||
} else {
|
||||
let bounds = mounted.geometry(&app).bounds("scenario-viewport");
|
||||
let outside = Point::new(bounds.x - 5., bounds.y + 100.);
|
||||
move_to(&mut mounted, &mut app, outside).await;
|
||||
outside
|
||||
};
|
||||
assert!(app.behavior.scenario.spacing_token().is_none());
|
||||
release(&mut mounted, &mut app, release_at).await;
|
||||
assert!(Arc::ptr_eq(&before, &app.document.snapshot()));
|
||||
assert_eq!(stored_camera(&app), camera);
|
||||
assert!(!app.document.can_undo() && !app.document.can_redo());
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn saved_drag_return_to_origin_preserves_redo_selection_and_original_fit_camera() {
|
||||
let (mut app, mut mounted, _) = setup(true).await;
|
||||
let owner = id(&app, "incident_response");
|
||||
app.document
|
||||
.execute(oa_core::Command::Rename(
|
||||
owner,
|
||||
"Previously edited owner".into(),
|
||||
))
|
||||
.unwrap();
|
||||
let redo = app.document.snapshot();
|
||||
let task = app.update(Message::Undo);
|
||||
mounted.perform(&mut app, task).await;
|
||||
mounted.settle(&mut app).await;
|
||||
assert!(app.document.can_redo());
|
||||
let before = app.document.snapshot();
|
||||
let camera = stored_camera(&app);
|
||||
let selected = app.selected;
|
||||
let revision = app.document.revision();
|
||||
let start = screen(&mut mounted, &app, Point::new(400., 252.));
|
||||
press(&mut mounted, &mut app, start).await;
|
||||
move_to(&mut mounted, &mut app, start + Vector::new(0., 12.)).await;
|
||||
mounted.settle(&mut app).await;
|
||||
assert!(app.behavior.scenario.spacing_token().is_some());
|
||||
move_to(&mut mounted, &mut app, start).await;
|
||||
mounted.settle(&mut app).await;
|
||||
release(&mut mounted, &mut app, start).await;
|
||||
assert!(app.behavior.scenario.spacing_token().is_none());
|
||||
assert!(Arc::ptr_eq(&before, &app.document.snapshot()));
|
||||
assert_eq!(app.document.bundle(), &before.bundle);
|
||||
assert_eq!(app.document.revision(), revision);
|
||||
assert_eq!(stored_camera(&app), camera);
|
||||
assert_eq!(app.selected, selected);
|
||||
assert!(app.document.can_redo());
|
||||
let task = app.update(Message::Redo);
|
||||
mounted.perform(&mut app, task).await;
|
||||
assert_eq!(app.project(), &redo.decoded.project);
|
||||
assert_eq!(app.document.bundle(), &redo.bundle);
|
||||
}
|
||||
@@ -48,28 +48,8 @@ async fn production_scenario_canvas_keeps_bounds_draft_identity_and_camera_throu
|
||||
mounted.pan(&mut app, start, start + delta).await;
|
||||
let diff = app.behavior.scenario.presentation.pan - next_pan;
|
||||
assert!(diff.x.hypot(diff.y) < 0.01);
|
||||
// Iced operations report palette children in content coordinates.
|
||||
// The preceding Action focus may have scrolled this retained palette.
|
||||
let geometry = mounted.geometry(&app);
|
||||
let scope = canvas_workspace::Scope::current(&app).unwrap();
|
||||
let (palette, offset) = geometry.scrolls[&scope.control_id("palette-scroll")];
|
||||
let tool = geometry.bounds("behavior-tool:A").center() - offset;
|
||||
assert!(
|
||||
palette.contains(tool),
|
||||
"visible Action at {tool:?}: {palette:?}"
|
||||
);
|
||||
let chosen = mounted.click(&mut app, tool).await;
|
||||
assert!(
|
||||
chosen.iter().any(|message| matches!(
|
||||
canvas_workspace::tests::intent_action(message),
|
||||
Message::ScenarioCanvas(CanvasEvent::Choose(_, CanvasTool::Add(Tool::Action)))
|
||||
)),
|
||||
"Action palette click at scale {scale}, offset {offset:?}: {chosen:?}"
|
||||
);
|
||||
assert_eq!(
|
||||
app.behavior.scenario.canvas_tool(f.owner),
|
||||
CanvasTool::Add(Tool::Action)
|
||||
);
|
||||
let tool = mounted.geometry(&app).bounds("behavior-tool:A").center();
|
||||
mounted.click(&mut app, tool).await;
|
||||
let messages = mounted.click(&mut app, bounds.position() + desired).await;
|
||||
assert!(
|
||||
messages.iter().any(
|
||||
@@ -77,7 +57,7 @@ async fn production_scenario_canvas_keeps_bounds_draft_identity_and_camera_throu
|
||||
tool: Tool::Action, slot, lifeline: Some(line), ..
|
||||
}) if *slot == expected && *line == f.sender)
|
||||
),
|
||||
"scale {scale}, expected slot {expected:?}: {messages:?}"
|
||||
"scale {scale}: {messages:?}"
|
||||
);
|
||||
let session = app.behavior.scenario.form_session().unwrap();
|
||||
let invocation = app.behavior.scenario.draft.as_ref().unwrap().invocation;
|
||||
@@ -1357,18 +1337,7 @@ async fn production_scenario_camera_external_controls_bounds_and_retained_deltas
|
||||
let bounds = mounted.geometry(&app).bounds("scenario-viewport");
|
||||
let point = bounds.position() + iced::Vector::new(95., 90.);
|
||||
let lifetime = app.camera_epoch;
|
||||
// Fit stores no pan offset. A real drag starts from the displayed fitted
|
||||
// camera, then materializes it before applying its ordered screen deltas.
|
||||
let shown = app
|
||||
.behavior
|
||||
.scenario
|
||||
.display(app.project(), f.owner, app.selected)
|
||||
.unwrap();
|
||||
let before_camera = app
|
||||
.behavior
|
||||
.scenario
|
||||
.presentation
|
||||
.camera(shown.bounds().unwrap());
|
||||
let pan = app.behavior.scenario.presentation.pan;
|
||||
let first = point + iced::Vector::new(13., 9.);
|
||||
let last = first + iced::Vector::new(17., -3.);
|
||||
let emitted = mounted
|
||||
@@ -1383,21 +1352,7 @@ async fn production_scenario_camera_external_controls_bounds_and_retained_deltas
|
||||
mouse::Cursor::Available(last),
|
||||
)
|
||||
.await;
|
||||
let expected_pan = before_camera.pan + (last - point);
|
||||
let actual_pan = app.behavior.scenario.presentation.pan;
|
||||
let difference = actual_pan - expected_pan;
|
||||
assert!(
|
||||
difference.x.hypot(difference.y) < 0.001,
|
||||
"{boundary}: displayed pan {actual_pan:?} must follow {expected_pan:?}"
|
||||
);
|
||||
assert_eq!(
|
||||
app.behavior.scenario.presentation.zoom,
|
||||
Some(before_camera.scale)
|
||||
);
|
||||
assert!(
|
||||
!app.behavior.scenario.presentation.fit,
|
||||
"drag materializes the visible Fit camera"
|
||||
);
|
||||
assert_eq!(app.behavior.scenario.presentation.pan, pan + (last - point));
|
||||
assert_eq!(
|
||||
app.camera_epoch, lifetime,
|
||||
"own ordered deltas retain their lifetime"
|
||||
@@ -1805,19 +1760,14 @@ fn scenario_workspace_fit_uses_measured_inner_viewport_and_rejects_nonfinite_inp
|
||||
assert!(!presentation.viewport(Size::new(484., 204.)));
|
||||
let scale = presentation.scale(graph);
|
||||
assert!(graph.width * scale <= 468. && graph.height * scale <= 188.);
|
||||
assert!(scale > camera::MIN_SCALE);
|
||||
assert!(scale > MIN_SCALE);
|
||||
for bad in [f32::NAN, f32::INFINITY, 0., -1.] {
|
||||
assert!(!presentation.zoom(Some(bad)));
|
||||
assert!(!presentation.viewport(Size::new(bad, 100.)));
|
||||
assert!(!presentation.viewport(Size::new(100., bad)));
|
||||
assert_eq!(presentation.scale(graph), scale);
|
||||
}
|
||||
let tall = Rectangle::with_size(Size::new(900., 10000.));
|
||||
let camera = presentation.camera(tall);
|
||||
assert!(camera.scale < 0.05 && camera.scale > 0.);
|
||||
assert!((camera.scale - 188. / 10000.).abs() < 1e-8);
|
||||
assert!((tall.height * camera.scale + camera.pan.y - 196.).abs() < 1e-4);
|
||||
assert!((camera.pan.y - 8.).abs() < 1e-4);
|
||||
assert_eq!(presentation.scale(Size::new(900., 10000.)), MIN_SCALE);
|
||||
assert!(presentation.zoom(Some(1.25)));
|
||||
presentation.viewport(Size::new(200., 100.));
|
||||
assert_eq!(
|
||||
|
||||
@@ -1,386 +0,0 @@
|
||||
//! Actual Scene primitives, with independently chosen points and semantic IDs.
|
||||
//! These preserve the existing label hit band; they do not establish ink bounds
|
||||
//! or authoring eligibility, and do not dispatch a spacing gesture.
|
||||
use super::*;
|
||||
use crate::document::Document;
|
||||
|
||||
struct Fixture {
|
||||
project: Project,
|
||||
owner: Id,
|
||||
sender: Id,
|
||||
receiver: Id,
|
||||
call: Id,
|
||||
reply: Id,
|
||||
exchange: Id,
|
||||
}
|
||||
|
||||
fn fixture() -> Fixture {
|
||||
let project = language::parse(r#"arcadia 7;
|
||||
project hits "Hit roles" {
|
||||
oa_activity source "Source" {}
|
||||
oa_activity target "Target" {}
|
||||
interaction exchange "Contract" { source @source; target @target; }
|
||||
oa_scenario conversation "Conversation" { viewpoint OperationalActivity; steps [@call, @reply]; }
|
||||
oa_lifeline left "Left" { parent @conversation; represented @source; }
|
||||
oa_lifeline right "Right" { parent @conversation; represented @target; }
|
||||
oa_occurrence call "Call" { parent @conversation; body { Exchange { exchange @exchange; sender @left; receiver @right; message_kind Call; }; }; }
|
||||
oa_occurrence reply "Reply" { parent @conversation; body { Exchange { exchange @exchange; sender @right; receiver @left; message_kind Reply; reply_to @call; }; }; }
|
||||
}
|
||||
"#).unwrap();
|
||||
let id = |alias: &str| {
|
||||
project
|
||||
.identities()
|
||||
.into_iter()
|
||||
.find(|(_, name)| *name == alias)
|
||||
.unwrap()
|
||||
.0
|
||||
};
|
||||
Fixture {
|
||||
owner: id("conversation"),
|
||||
sender: id("left"),
|
||||
receiver: id("right"),
|
||||
call: id("call"),
|
||||
reply: id("reply"),
|
||||
exchange: id("exchange"),
|
||||
project,
|
||||
}
|
||||
}
|
||||
|
||||
fn scene(f: &Fixture) -> Scene {
|
||||
let document =
|
||||
Document::from_project(f.project.clone(), source_project::ProjectLimits::default())
|
||||
.unwrap();
|
||||
let before = document.snapshot();
|
||||
let result = Scene::sequence_geometry(
|
||||
document.project(),
|
||||
f.owner,
|
||||
f.call,
|
||||
Some(&BTreeMap::from([(f.sender, 160.), (f.receiver, 400.)])),
|
||||
None,
|
||||
);
|
||||
assert_eq!(document.project(), &before.decoded.project);
|
||||
assert_eq!(document.bundle(), &before.bundle);
|
||||
assert_eq!(document.revision(), 0);
|
||||
assert!(!document.can_undo() && !document.can_redo() && !document.dirty());
|
||||
result
|
||||
}
|
||||
|
||||
fn hit(scene: &Scene, point: Point, id: Id, role: SceneHitRole) {
|
||||
assert_eq!(scene.hit_item(point), Some(SceneHit { id, role }));
|
||||
assert_eq!(scene.hit(point), Some(id));
|
||||
}
|
||||
|
||||
fn occurrence(p: &mut Project, parent: Id, body: OccurrenceBody) -> Id {
|
||||
let mut element = p
|
||||
.make_element(Kind::Occurrence, Layer::Oa, "Hit target", Some(parent))
|
||||
.unwrap();
|
||||
let id = element.id;
|
||||
*element.shared_mut().unwrap() = SharedBody::Occurrence {
|
||||
body,
|
||||
precondition: String::new(),
|
||||
postcondition: String::new(),
|
||||
};
|
||||
p.elements.insert(id, element);
|
||||
p.elements
|
||||
.get_mut(&parent)
|
||||
.unwrap()
|
||||
.steps_mut()
|
||||
.unwrap()
|
||||
.push(id);
|
||||
id
|
||||
}
|
||||
|
||||
fn exchange_mut(p: &mut Project, id: Id) -> &mut OccurrenceBody {
|
||||
let SharedBody::Occurrence { body, .. } =
|
||||
p.elements.get_mut(&id).unwrap().shared_mut().unwrap()
|
||||
else {
|
||||
panic!("expected occurrence")
|
||||
};
|
||||
body
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exact_headers_include_unassigned_lifelines_but_guides_are_not_headers() {
|
||||
let mut f = fixture();
|
||||
*f.project
|
||||
.elements
|
||||
.get_mut(&f.receiver)
|
||||
.unwrap()
|
||||
.shared_mut()
|
||||
.unwrap() = SharedBody::Lifeline { represented: None };
|
||||
let s = scene(&f);
|
||||
assert!(!s.lanes.contains_key(&f.receiver));
|
||||
assert_eq!(s.render_lanes[&f.receiver], 400.);
|
||||
for (id, x) in [(f.sender, 160.), (f.receiver, 400.)] {
|
||||
// The actual header is x-102..x+102, y15..85, including its padding.
|
||||
for point in [Point::new(x - 101., 16.), Point::new(x + 101., 84.)] {
|
||||
hit(&s, point, id, SceneHitRole::LifelineHeader);
|
||||
}
|
||||
hit(&s, Point::new(x, 95.), id, SceneHitRole::LifelineGuide);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn repeated_exchange_occurrences_keep_distinct_message_body_and_label_hits() {
|
||||
let f = fixture();
|
||||
let s = scene(&f);
|
||||
assert_eq!(s.rows[&f.call].1, 148.);
|
||||
assert_eq!(s.rows[&f.reply].1, 240.);
|
||||
for (id, y) in [(f.call, 148.), (f.reply, 240.)] {
|
||||
hit(&s, Point::new(280., y), id, SceneHitRole::MessageBody);
|
||||
hit(
|
||||
&s,
|
||||
Point::new(180., y - 16.),
|
||||
id,
|
||||
SceneHitRole::MessageLabel,
|
||||
);
|
||||
assert_ne!(id, f.exchange);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn self_call_elbow_and_receive_endpoint_are_messages_not_execution_hits() {
|
||||
let mut f = fixture();
|
||||
for id in [f.call, f.reply] {
|
||||
let OccurrenceBody::Exchange {
|
||||
sender,
|
||||
receiver,
|
||||
exchange,
|
||||
..
|
||||
} = exchange_mut(&mut f.project, id)
|
||||
else {
|
||||
unreachable!()
|
||||
};
|
||||
*sender = Some(f.sender);
|
||||
*receiver = Some(f.sender);
|
||||
*exchange = None;
|
||||
}
|
||||
let s = scene(&f);
|
||||
let call = s.lines.iter().find(|l| l.id == f.call).unwrap();
|
||||
assert_eq!(call.points.len(), 4);
|
||||
assert_eq!(call.points[0].y, 148.);
|
||||
assert_eq!(call.points[3].y, 172.);
|
||||
hit(
|
||||
&s,
|
||||
Point::new(call.points[1].x, 160.),
|
||||
f.call,
|
||||
SceneHitRole::MessageBody,
|
||||
);
|
||||
hit(&s, call.points[3], f.call, SceneHitRole::MessageBody);
|
||||
hit(
|
||||
&s,
|
||||
Point::new(180., 132.),
|
||||
f.call,
|
||||
SceneHitRole::MessageLabel,
|
||||
);
|
||||
let bar = s.activations.iter().find(|a| a.call == f.call).unwrap();
|
||||
hit(
|
||||
&s,
|
||||
Point::new(bar.rect.x + 2., 190.),
|
||||
f.call,
|
||||
SceneHitRole::Activation,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn activation_shoulder_beats_another_calls_label_and_broad_message_tolerance() {
|
||||
let mut f = fixture();
|
||||
let mut inner = f.project.elements[&f.call].clone();
|
||||
inner.id = Id::new_v4();
|
||||
inner.alias = "inner_call_hit".into();
|
||||
inner.name = "Pressure verification with a descriptive operation label".into();
|
||||
let inner_id = inner.id;
|
||||
f.project.elements.insert(inner_id, inner);
|
||||
let mut inner_reply = f.project.elements[&f.reply].clone();
|
||||
inner_reply.id = Id::new_v4();
|
||||
inner_reply.alias = "inner_reply_hit".into();
|
||||
let reply_id = inner_reply.id;
|
||||
f.project.elements.insert(reply_id, inner_reply);
|
||||
let OccurrenceBody::Exchange { reply_to, .. } = exchange_mut(&mut f.project, reply_id) else {
|
||||
unreachable!()
|
||||
};
|
||||
*reply_to = Some(inner_id);
|
||||
*f.project
|
||||
.elements
|
||||
.get_mut(&f.owner)
|
||||
.unwrap()
|
||||
.steps_mut()
|
||||
.unwrap() = vec![f.call, inner_id, reply_id, f.reply];
|
||||
let mut s = scene(&f);
|
||||
let inner = s.lines.iter().find(|l| l.id == inner_id).unwrap();
|
||||
let outer = s.activations.iter().find(|a| a.call == f.call).unwrap();
|
||||
let shoulder = Point::new(outer.rect.x + 1., 225.);
|
||||
assert!(outer.rect.contains(shoulder));
|
||||
assert!(inner.label_bounds().contains(shoulder));
|
||||
let endpoint = *inner.points.last().unwrap();
|
||||
for scale in [1., 0.05, 0.0003] {
|
||||
s.scale = scale;
|
||||
hit(&s, shoulder, f.call, SceneHitRole::Activation);
|
||||
hit(&s, endpoint, inner_id, SceneHitRole::MessageBody);
|
||||
hit(
|
||||
&s,
|
||||
Point::new(180., 225.),
|
||||
inner_id,
|
||||
SceneHitRole::MessageLabel,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_delete_markers_are_distinct_from_their_own_message_body_and_label() {
|
||||
let mut f = fixture();
|
||||
for (id, kind) in [
|
||||
(f.call, MessageKind::Create),
|
||||
(f.reply, MessageKind::Delete),
|
||||
] {
|
||||
let OccurrenceBody::Exchange {
|
||||
sender,
|
||||
receiver,
|
||||
message_kind,
|
||||
reply_to,
|
||||
..
|
||||
} = exchange_mut(&mut f.project, id)
|
||||
else {
|
||||
unreachable!()
|
||||
};
|
||||
*sender = Some(f.sender);
|
||||
*receiver = Some(f.receiver);
|
||||
*message_kind = kind;
|
||||
*reply_to = None;
|
||||
}
|
||||
let s = scene(&f);
|
||||
for (id, y, label_y) in [(f.call, 148., 118.), (f.reply, 240., 224.)] {
|
||||
hit(&s, Point::new(400., y), id, SceneHitRole::LifecycleMarker);
|
||||
hit(&s, Point::new(280., y), id, SceneHitRole::MessageBody);
|
||||
hit(
|
||||
&s,
|
||||
Point::new(180., label_y),
|
||||
id,
|
||||
SceneHitRole::MessageLabel,
|
||||
);
|
||||
}
|
||||
// Capsule boundary owns its contact with the incoming Create arrow.
|
||||
hit(
|
||||
&s,
|
||||
Point::new(330., 148.),
|
||||
f.call,
|
||||
SceneHitRole::LifecycleMarker,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tiny_scale_nearest_hit_retains_the_winning_marker_or_message_role() {
|
||||
let mut f = fixture();
|
||||
let OccurrenceBody::Exchange {
|
||||
sender,
|
||||
receiver,
|
||||
message_kind,
|
||||
reply_to,
|
||||
..
|
||||
} = exchange_mut(&mut f.project, f.reply)
|
||||
else {
|
||||
unreachable!()
|
||||
};
|
||||
*sender = Some(f.sender);
|
||||
*receiver = Some(f.receiver);
|
||||
*message_kind = MessageKind::Delete;
|
||||
*reply_to = None;
|
||||
let mut s = scene(&f);
|
||||
s.scale = 0.0003;
|
||||
// Both are outside exact strokes/labels. Comparing all broad candidates
|
||||
// chooses the actual nearer shape, even when their UUID is identical.
|
||||
hit(
|
||||
&s,
|
||||
Point::new(280., 246.),
|
||||
f.reply,
|
||||
SceneHitRole::MessageBody,
|
||||
);
|
||||
hit(
|
||||
&s,
|
||||
Point::new(400., 265.),
|
||||
f.reply,
|
||||
SceneHitRole::LifecycleMarker,
|
||||
);
|
||||
hit(
|
||||
&s,
|
||||
Point::new(280., 154.),
|
||||
f.call,
|
||||
SceneHitRole::MessageBody,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn action_frame_and_use_boxes_do_not_advertise_message_or_header_roles() {
|
||||
for body in [
|
||||
OccurrenceBody::Action {
|
||||
action: None,
|
||||
lifeline: None,
|
||||
},
|
||||
OccurrenceBody::Fragment {
|
||||
operator: FragmentOperator::Alternative,
|
||||
branches: vec![],
|
||||
},
|
||||
OccurrenceBody::ScenarioUse {
|
||||
scenario: None,
|
||||
bindings: vec![],
|
||||
},
|
||||
OccurrenceBody::Exchange {
|
||||
exchange: None,
|
||||
sender: None,
|
||||
receiver: None,
|
||||
message_kind: MessageKind::Asynchronous,
|
||||
operation: None,
|
||||
reply_to: None,
|
||||
values: vec![],
|
||||
},
|
||||
] {
|
||||
let mut f = fixture();
|
||||
let id = occurrence(&mut f.project, f.owner, body);
|
||||
let s = scene(&f);
|
||||
let item = s.boxes.iter().find(|b| b.id == id).unwrap();
|
||||
hit(
|
||||
&s,
|
||||
item.rect.position() + iced::Vector::new(15., 15.),
|
||||
id,
|
||||
SceneHitRole::Box,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn winning_primitive_role_does_not_come_from_its_shared_uuid() {
|
||||
let f = fixture();
|
||||
let mut s = scene(&f);
|
||||
// A controlled overlapping primitive verifies reverse box order without
|
||||
// inventing a core alias. Its ID intentionally equals a real header's ID.
|
||||
s.boxes.push(BoxItem {
|
||||
id: f.sender,
|
||||
role: SceneHitRole::Box,
|
||||
rect: Rectangle::new(Point::new(150., 20.), Size::new(20., 20.)),
|
||||
title: "Overlay control".into(),
|
||||
detail: String::new(),
|
||||
marker: None,
|
||||
});
|
||||
hit(&s, Point::new(160., 30.), f.sender, SceneHitRole::Box);
|
||||
hit(
|
||||
&s,
|
||||
Point::new(180., 30.),
|
||||
f.sender,
|
||||
SceneHitRole::LifelineHeader,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_points_never_produce_a_semantic_or_spacing_hit() {
|
||||
let f = fixture();
|
||||
let s = scene(&f);
|
||||
for point in [
|
||||
Point::new(f32::NAN, 148.),
|
||||
Point::new(280., f32::NAN),
|
||||
Point::new(f32::INFINITY, 148.),
|
||||
Point::new(280., f32::NEG_INFINITY),
|
||||
] {
|
||||
assert_eq!(s.hit_item(point), None);
|
||||
assert_eq!(s.hit(point), None);
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,6 @@ use oa_core::{DiagramLayout, ScenarioLayout};
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
pub(crate) mod presentation;
|
||||
|
||||
type Candidate = BTreeMap<Id, f32>;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
@@ -32,13 +30,13 @@ struct MessageAnchors {
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum Diagnostic {
|
||||
enum Diagnostic {
|
||||
SourceOrderCrossing { scope: Id, before: Id, after: Id },
|
||||
FrameExtendsPastFollowingAnchor { frame: Id, following: Id },
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum GeometryIssue {
|
||||
pub(super) enum GeometryIssue {
|
||||
UnknownAnchor(Id),
|
||||
LifecycleGeometryNotSupported { lifeline: Id, scope: Id },
|
||||
InvalidRepresentation(Id),
|
||||
@@ -64,7 +62,7 @@ pub(super) struct Plan {
|
||||
pub(super) frames: BTreeMap<Id, Rectangle>,
|
||||
pub(super) scopes: BTreeMap<Id, (f32, f32)>,
|
||||
pub(super) height: f32,
|
||||
pub(super) diagnostics: Vec<Diagnostic>,
|
||||
diagnostics: Vec<Diagnostic>,
|
||||
}
|
||||
|
||||
pub(super) fn occurrence(p: &Project, id: Id) -> Option<&OccurrenceBody> {
|
||||
@@ -475,7 +473,7 @@ impl Plan {
|
||||
|
||||
/// An appearance identity, never inferred from selection or from the owner alone.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum Representation {
|
||||
pub(super) enum Representation {
|
||||
Derived { owner: Id },
|
||||
Saved { diagram: Id },
|
||||
}
|
||||
|
||||
@@ -1,234 +0,0 @@
|
||||
//! Display policy for one requested Scenario representation, without authoring.
|
||||
//! The resolver remains the sole renderer. Freshness and editor admission belong
|
||||
//! to the caller; a capability here never bypasses those guards.
|
||||
use super::{Diagnostic, GeometryIssue, Representation, ResolvedScenarioPlan, resolve};
|
||||
use crate::behavior::Scene;
|
||||
use iced::Rectangle;
|
||||
use oa_core::{DiagramLayout, Id, Kind, OccurrenceBody, Project, SharedBody};
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum PresentationStatus {
|
||||
Ready,
|
||||
Fallback {
|
||||
requested_issues: Vec<GeometryIssue>,
|
||||
},
|
||||
Unavailable {
|
||||
requested_issues: Vec<GeometryIssue>,
|
||||
automatic_issues: Vec<GeometryIssue>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) struct PresentationCapabilities {
|
||||
/// Actual geometry exists for inspection, Fit and geometry-based navigation.
|
||||
pub(crate) geometry_navigation: bool,
|
||||
/// Still subject to document, gesture, editor and view-visit admission.
|
||||
pub(crate) coordinate_input: bool,
|
||||
}
|
||||
|
||||
pub(crate) struct ScenarioPresentation {
|
||||
requested: Representation,
|
||||
owner: Option<Id>,
|
||||
status: PresentationStatus,
|
||||
geometry: Option<ResolvedScenarioPlan>,
|
||||
// Saved metadata must survive a complete automatic fallback.
|
||||
latent_messages: Vec<Id>,
|
||||
}
|
||||
|
||||
impl ScenarioPresentation {
|
||||
pub(crate) fn requested(&self) -> Representation {
|
||||
self.requested
|
||||
}
|
||||
pub(crate) fn owner(&self) -> Option<Id> {
|
||||
self.owner
|
||||
}
|
||||
pub(crate) fn status(&self) -> &PresentationStatus {
|
||||
&self.status
|
||||
}
|
||||
pub(crate) fn geometry_representation(&self) -> Option<Representation> {
|
||||
self.geometry
|
||||
.as_ref()
|
||||
.map(|geometry| geometry.representation)
|
||||
}
|
||||
pub(crate) fn bounds(&self) -> Option<Rectangle> {
|
||||
self.geometry.as_ref().map(|geometry| geometry.bounds)
|
||||
}
|
||||
/// Diagnostics describe the actual displayed geometry. Requested hard failures
|
||||
/// are retained separately in status(), never presented as automatic warnings.
|
||||
pub(crate) fn diagnostics(&self) -> &[Diagnostic] {
|
||||
self.geometry
|
||||
.as_ref()
|
||||
.map_or(&[], |geometry| &geometry.plan.diagnostics)
|
||||
}
|
||||
pub(crate) fn latent_messages(&self) -> &[Id] {
|
||||
&self.latent_messages
|
||||
}
|
||||
pub(crate) fn capabilities(&self) -> PresentationCapabilities {
|
||||
PresentationCapabilities {
|
||||
geometry_navigation: self.geometry.is_some(),
|
||||
coordinate_input: matches!(self.status, PresentationStatus::Ready),
|
||||
}
|
||||
}
|
||||
pub(in crate::behavior) fn scene(&self) -> Option<&Scene> {
|
||||
self.geometry.as_ref().map(|geometry| &geometry.scene)
|
||||
}
|
||||
pub(in crate::behavior) fn into_scene(self) -> Option<Scene> {
|
||||
self.geometry.map(|geometry| geometry.scene)
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolve a structurally accepted Project for passive display. This is not a
|
||||
/// second model validator: identity and resolver-reported structural failures
|
||||
/// cannot be converted into a more permissive automatic representation.
|
||||
pub(crate) fn present(
|
||||
project: &Project,
|
||||
requested: Representation,
|
||||
selected: Id,
|
||||
) -> ScenarioPresentation {
|
||||
let owner = checked_owner(project, requested);
|
||||
let Some(owner_id) = owner else {
|
||||
let id = match requested {
|
||||
Representation::Derived { owner } => owner,
|
||||
Representation::Saved { diagram } => diagram,
|
||||
};
|
||||
return ScenarioPresentation {
|
||||
requested,
|
||||
owner: None,
|
||||
geometry: None,
|
||||
latent_messages: vec![],
|
||||
status: PresentationStatus::Unavailable {
|
||||
requested_issues: vec![GeometryIssue::InvalidRepresentation(id)],
|
||||
automatic_issues: vec![],
|
||||
},
|
||||
};
|
||||
};
|
||||
match resolve(project, requested, selected) {
|
||||
Ok(geometry) => ScenarioPresentation {
|
||||
requested,
|
||||
owner,
|
||||
status: PresentationStatus::Ready,
|
||||
latent_messages: geometry.latent_messages.clone(),
|
||||
geometry: Some(geometry),
|
||||
},
|
||||
Err(requested_issues) => {
|
||||
if matches!(requested, Representation::Derived { .. })
|
||||
|| requested_issues.iter().any(structural_failure)
|
||||
{
|
||||
return ScenarioPresentation {
|
||||
requested,
|
||||
owner,
|
||||
geometry: None,
|
||||
latent_messages: vec![],
|
||||
status: PresentationStatus::Unavailable {
|
||||
requested_issues,
|
||||
automatic_issues: vec![],
|
||||
},
|
||||
};
|
||||
}
|
||||
match resolve(
|
||||
project,
|
||||
Representation::Derived { owner: owner_id },
|
||||
selected,
|
||||
) {
|
||||
Ok(geometry) => {
|
||||
let latent_messages =
|
||||
saved_latent_messages(project, requested, &geometry.scene);
|
||||
ScenarioPresentation {
|
||||
requested,
|
||||
owner,
|
||||
status: PresentationStatus::Fallback { requested_issues },
|
||||
geometry: Some(geometry),
|
||||
latent_messages,
|
||||
}
|
||||
}
|
||||
Err(automatic_issues) => ScenarioPresentation {
|
||||
requested,
|
||||
owner,
|
||||
geometry: None,
|
||||
latent_messages: vec![],
|
||||
status: PresentationStatus::Unavailable {
|
||||
requested_issues,
|
||||
automatic_issues,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn checked_owner(project: &Project, requested: Representation) -> Option<Id> {
|
||||
let owner = match requested {
|
||||
Representation::Derived { owner } => owner,
|
||||
Representation::Saved { diagram } => {
|
||||
let view = project.diagrams.get(&diagram)?;
|
||||
let owner = view.projection.scenario()?;
|
||||
if view.id != diagram || project.elements.get(&owner)?.layer() != view.layer {
|
||||
return None;
|
||||
}
|
||||
owner
|
||||
}
|
||||
};
|
||||
project
|
||||
.elements
|
||||
.get(&owner)
|
||||
.is_some_and(|element| element.kind() == Kind::Scenario)
|
||||
.then_some(owner)
|
||||
}
|
||||
|
||||
fn structural_failure(issue: &GeometryIssue) -> bool {
|
||||
// These violate the existing identity/address/finite-coordinate admission
|
||||
// contract. Geometry support failures below do not invalidate stored intent.
|
||||
match issue {
|
||||
GeometryIssue::InvalidRepresentation(_)
|
||||
| GeometryIssue::UnknownAnchor(_)
|
||||
| GeometryIssue::InvalidCoordinate(_)
|
||||
| GeometryIssue::DuplicateCoordinate(_)
|
||||
| GeometryIssue::ExpandedAddressNotSupported(_)
|
||||
| GeometryIssue::NonFinite(_) => true,
|
||||
GeometryIssue::LifecycleGeometryNotSupported { .. }
|
||||
| GeometryIssue::CoincidentDistinctEndpoints(_)
|
||||
| GeometryIssue::TypedActivationOutsideScope { .. }
|
||||
| GeometryIssue::TypedActivationOutsideLifetime { .. }
|
||||
| GeometryIssue::TypedActivationCrossingNotSupported { .. }
|
||||
| GeometryIssue::CompoundMoveNotImplemented(_)
|
||||
| GeometryIssue::FixedFrameHeaderWouldMove { .. }
|
||||
| GeometryIssue::OperandScopeOutsideEnclosingInterval { .. }
|
||||
| GeometryIssue::LifecycleAnchorOutsideRenderScope { .. }
|
||||
| GeometryIssue::LifetimeInversionNotSupported { .. } => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn saved_latent_messages(project: &Project, requested: Representation, scene: &Scene) -> Vec<Id> {
|
||||
let Representation::Saved { diagram } = requested else {
|
||||
return vec![];
|
||||
};
|
||||
let Some(DiagramLayout::Scenario(layout)) = project.diagrams[&diagram].layout.as_ref() else {
|
||||
return vec![];
|
||||
};
|
||||
let lines: BTreeSet<_> = scene.lines.iter().map(|line| line.id).collect();
|
||||
layout
|
||||
.messages
|
||||
.iter()
|
||||
.filter_map(|message| {
|
||||
let id = message.address.occurrence;
|
||||
(message.address.references.is_empty()
|
||||
&& scene.rows.contains_key(&id)
|
||||
&& !lines.contains(&id)
|
||||
&& matches!(
|
||||
project
|
||||
.elements
|
||||
.get(&id)
|
||||
.and_then(|element| element.shared()),
|
||||
Some(SharedBody::Occurrence {
|
||||
body: OccurrenceBody::Exchange { .. },
|
||||
..
|
||||
})
|
||||
))
|
||||
.then_some(id)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
@@ -1,351 +0,0 @@
|
||||
use super::*;
|
||||
use crate::document::Document;
|
||||
use oa_core::{
|
||||
Command, Diagram, OccurrenceEndpoint, ProjectionKind, ScenarioLanePosition, ScenarioLayout,
|
||||
ScenarioMessagePosition, language, validation,
|
||||
};
|
||||
|
||||
fn fixture() -> (Project, Id) {
|
||||
let project = language::parse(FIXTURE).unwrap();
|
||||
assert_admitted(&project);
|
||||
let owner = named(&project, "conversation");
|
||||
(project, owner)
|
||||
}
|
||||
fn named(project: &Project, alias: &str) -> Id {
|
||||
project
|
||||
.identities()
|
||||
.into_iter()
|
||||
.find(|(_, name)| *name == alias)
|
||||
.unwrap()
|
||||
.0
|
||||
}
|
||||
fn assert_admitted(project: &Project) {
|
||||
let errors: Vec<_> = validation::validate(project)
|
||||
.into_iter()
|
||||
.filter(|issue| issue.severity == validation::Severity::Error)
|
||||
.collect();
|
||||
assert!(errors.is_empty(), "{errors:?}");
|
||||
}
|
||||
fn save(project: &mut Project, owner: Id, layout: Option<ScenarioLayout>) -> Id {
|
||||
let id = Id::new_v4();
|
||||
project.diagrams.insert(
|
||||
id,
|
||||
Diagram {
|
||||
id,
|
||||
alias: format!("view_{}", project.diagrams.len()),
|
||||
name: "Saved conversation".into(),
|
||||
description: String::new(),
|
||||
layer: project.elements[&owner].layer(),
|
||||
projection: ProjectionKind::Scenario { scenario: owner },
|
||||
view_options: Default::default(),
|
||||
nodes: Default::default(),
|
||||
routes: vec![],
|
||||
layout: layout.map(DiagramLayout::Scenario),
|
||||
},
|
||||
);
|
||||
id
|
||||
}
|
||||
fn layout(messages: &[(Id, f32)], lanes: &[(Id, f32)]) -> ScenarioLayout {
|
||||
ScenarioLayout {
|
||||
lanes: lanes
|
||||
.iter()
|
||||
.map(|&(lifeline, x)| ScenarioLanePosition { lifeline, x })
|
||||
.collect(),
|
||||
messages: messages
|
||||
.iter()
|
||||
.map(|&(occurrence, send_y)| ScenarioMessagePosition {
|
||||
address: OccurrenceEndpoint {
|
||||
occurrence,
|
||||
references: vec![],
|
||||
},
|
||||
send_y,
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
fn same_geometry(a: &Scene, b: &Scene) {
|
||||
assert!(
|
||||
!a.activations.is_empty(),
|
||||
"fallback must include real typed executions"
|
||||
);
|
||||
assert_eq!(a.activations, b.activations);
|
||||
assert_eq!(a.lifecycle, b.lifecycle);
|
||||
assert_eq!(a.rows, b.rows);
|
||||
assert_eq!(a.sequence_bounds, b.sequence_bounds);
|
||||
assert_eq!(a.render_lanes, b.render_lanes);
|
||||
assert_eq!(a.lanes, b.lanes);
|
||||
assert_eq!(a.open_calls, b.open_calls);
|
||||
assert_eq!((a.size, a.layout_origin), (b.size, b.layout_origin));
|
||||
let boxes = |scene: &Scene| {
|
||||
scene
|
||||
.boxes
|
||||
.iter()
|
||||
.map(|item| {
|
||||
(
|
||||
item.id,
|
||||
item.rect,
|
||||
item.title.clone(),
|
||||
item.detail.clone(),
|
||||
item.marker,
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
let lines = |scene: &Scene| {
|
||||
scene
|
||||
.lines
|
||||
.iter()
|
||||
.map(|line| {
|
||||
(
|
||||
line.id,
|
||||
line.points.clone(),
|
||||
line.label.clone(),
|
||||
line.label_at,
|
||||
line.dashed,
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
let slots = |scene: &Scene| {
|
||||
scene
|
||||
.slots
|
||||
.iter()
|
||||
.map(|slot| {
|
||||
(
|
||||
slot.slot.parent,
|
||||
slot.slot.before,
|
||||
slot.y,
|
||||
slot.label.clone(),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
assert_eq!(boxes(a), boxes(b));
|
||||
assert_eq!(lines(a), lines(b));
|
||||
assert_eq!(slots(a), slots(b));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn absent_and_empty_saved_layouts_remain_saved_ready_representations() {
|
||||
let (mut project, owner) = fixture();
|
||||
let absent = save(&mut project, owner, None);
|
||||
let empty = save(&mut project, owner, Some(ScenarioLayout::default()));
|
||||
assert_admitted(&project);
|
||||
let automatic = present(&project, Representation::Derived { owner }, owner);
|
||||
assert_eq!(automatic.status(), &PresentationStatus::Ready);
|
||||
for diagram in [absent, empty] {
|
||||
let requested = Representation::Saved { diagram };
|
||||
let displayed = present(&project, requested, owner);
|
||||
assert_eq!(displayed.requested(), requested);
|
||||
assert_eq!(displayed.geometry_representation(), Some(requested));
|
||||
assert_eq!(displayed.owner(), Some(owner));
|
||||
assert_eq!(displayed.status(), &PresentationStatus::Ready);
|
||||
assert!(displayed.capabilities().coordinate_input);
|
||||
assert_eq!(displayed.bounds(), automatic.bounds());
|
||||
same_geometry(displayed.scene().unwrap(), automatic.scene().unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn successful_crossing_diagnostic_keeps_authored_geometry_and_latent_identity() {
|
||||
let (mut project, owner) = fixture();
|
||||
let first = named(&project, "first");
|
||||
let second = named(&project, "second");
|
||||
let left = named(&project, "left");
|
||||
let unfinished = named(&project, "unfinished");
|
||||
let diagram = save(
|
||||
&mut project,
|
||||
owner,
|
||||
Some(layout(
|
||||
&[(first, 1000.), (unfinished, 2000.)],
|
||||
&[(left, 900.)],
|
||||
)),
|
||||
);
|
||||
assert_admitted(&project);
|
||||
let shown = present(&project, Representation::Saved { diagram }, first);
|
||||
assert_eq!(shown.status(), &PresentationStatus::Ready);
|
||||
assert_eq!(shown.scene().unwrap().rows[&first].1, 1000.);
|
||||
assert_eq!(shown.scene().unwrap().rows[&second].1, 240.);
|
||||
assert_eq!(shown.scene().unwrap().render_lanes[&left], 900.);
|
||||
assert!(
|
||||
shown
|
||||
.diagnostics()
|
||||
.contains(&Diagnostic::SourceOrderCrossing {
|
||||
scope: owner,
|
||||
before: first,
|
||||
after: second
|
||||
})
|
||||
);
|
||||
assert_eq!(shown.latent_messages(), &[unfinished]);
|
||||
assert_eq!(shown.scene().unwrap().rows[&unfinished].1, 516.);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hard_failure_uses_complete_automatic_geometry_but_retains_each_saved_request_and_latent_notice()
|
||||
{
|
||||
let (mut project, owner) = fixture();
|
||||
let call = named(&project, "call");
|
||||
let reply = named(&project, "reply");
|
||||
let unfinished = named(&project, "unfinished");
|
||||
let left = named(&project, "left");
|
||||
let right = named(&project, "right");
|
||||
let authored = layout(
|
||||
&[(reply, 300.), (unfinished, 2000.)],
|
||||
&[(left, 900.), (right, -500.)],
|
||||
);
|
||||
let a = save(&mut project, owner, Some(authored.clone()));
|
||||
let b = save(&mut project, owner, Some(authored));
|
||||
assert_admitted(&project);
|
||||
let before = project.clone();
|
||||
let automatic = present(&project, Representation::Derived { owner }, call);
|
||||
let control = automatic.scene().unwrap();
|
||||
assert_eq!(control.render_lanes[&left], 160.);
|
||||
assert_eq!(control.render_lanes[&right], 400.);
|
||||
assert_eq!(control.rows[&reply].1, 424.);
|
||||
assert_eq!(control.activations.len(), 1);
|
||||
assert_eq!(
|
||||
(
|
||||
control.activations[0].rect.y,
|
||||
control.activations[0].rect.height
|
||||
),
|
||||
(356., 68.)
|
||||
);
|
||||
for diagram in [a, b] {
|
||||
let request = Representation::Saved { diagram };
|
||||
let shown = present(&project, request, call);
|
||||
assert_eq!(shown.requested(), request);
|
||||
assert_eq!(
|
||||
shown.geometry_representation(),
|
||||
Some(Representation::Derived { owner })
|
||||
);
|
||||
assert_eq!(
|
||||
shown.status(),
|
||||
&PresentationStatus::Fallback {
|
||||
requested_issues: vec![GeometryIssue::TypedActivationCrossingNotSupported {
|
||||
call,
|
||||
event: reply
|
||||
}],
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
shown.capabilities(),
|
||||
PresentationCapabilities {
|
||||
geometry_navigation: true,
|
||||
coordinate_input: false
|
||||
}
|
||||
);
|
||||
assert_eq!(shown.latent_messages(), &[unfinished]);
|
||||
assert!(shown.diagnostics().is_empty());
|
||||
assert_eq!(shown.bounds(), automatic.bounds());
|
||||
same_geometry(shown.scene().unwrap(), control);
|
||||
}
|
||||
assert_eq!(project, before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_or_incompatible_identity_and_structural_coordinate_errors_are_unavailable() {
|
||||
let (mut project, owner) = fixture();
|
||||
let left = named(&project, "left");
|
||||
let diagram = save(&mut project, owner, None);
|
||||
let missing = Id::new_v4();
|
||||
for request in [
|
||||
Representation::Saved { diagram: missing },
|
||||
Representation::Derived { owner: left },
|
||||
] {
|
||||
let shown = present(&project, request, owner);
|
||||
assert_eq!(shown.requested(), request);
|
||||
assert_eq!(shown.owner(), None);
|
||||
assert!(
|
||||
matches!(shown.status(), PresentationStatus::Unavailable { automatic_issues, .. } if automatic_issues.is_empty())
|
||||
);
|
||||
assert!(shown.scene().is_none() && shown.bounds().is_none());
|
||||
assert_eq!(
|
||||
shown.capabilities(),
|
||||
PresentationCapabilities {
|
||||
geometry_navigation: false,
|
||||
coordinate_input: false
|
||||
}
|
||||
);
|
||||
}
|
||||
project.diagrams.get_mut(&diagram).unwrap().projection =
|
||||
ProjectionKind::Scenario { scenario: missing };
|
||||
assert!(matches!(
|
||||
present(&project, Representation::Saved { diagram }, owner).status(),
|
||||
PresentationStatus::Unavailable { .. }
|
||||
));
|
||||
// Deliberately invalid-model control, not a warning-admitted geometry failure.
|
||||
project.diagrams.get_mut(&diagram).unwrap().projection =
|
||||
ProjectionKind::Scenario { scenario: owner };
|
||||
project.diagrams.get_mut(&diagram).unwrap().layout = Some(DiagramLayout::Scenario(layout(
|
||||
&[],
|
||||
&[(left, oa_core::MAX_COORDINATE + 1.)],
|
||||
)));
|
||||
assert!(
|
||||
validation::validate(&project)
|
||||
.iter()
|
||||
.any(|issue| issue.severity == validation::Severity::Error)
|
||||
);
|
||||
let before = project.clone();
|
||||
let shown = present(&project, Representation::Saved { diagram }, owner);
|
||||
assert!(
|
||||
matches!(shown.status(), PresentationStatus::Unavailable { requested_issues, automatic_issues }
|
||||
if requested_issues == &[GeometryIssue::InvalidCoordinate(left)] && automatic_issues.is_empty())
|
||||
);
|
||||
assert!(shown.scene().is_none());
|
||||
assert_eq!(project, before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn passive_fallback_preserves_exact_document_source_and_one_step_undo_redo() {
|
||||
let (mut project, owner) = fixture();
|
||||
let first = named(&project, "first");
|
||||
let reply = named(&project, "reply");
|
||||
let view = save(&mut project, owner, Some(layout(&[(reply, 300.)], &[])));
|
||||
assert_admitted(&project);
|
||||
let mut document = Document::from_project(project, Default::default()).unwrap();
|
||||
let initial_project = document.project().clone();
|
||||
let initial_source = document.bundle().clone();
|
||||
document
|
||||
.execute(Command::Rename(first, "An intentional prior edit".into()))
|
||||
.unwrap();
|
||||
let accepted_project = document.project().clone();
|
||||
let accepted_source = document.bundle().clone();
|
||||
let revision = document.revision();
|
||||
{
|
||||
let shown = present(
|
||||
document.project(),
|
||||
Representation::Saved { diagram: view },
|
||||
first,
|
||||
);
|
||||
assert!(matches!(
|
||||
shown.status(),
|
||||
PresentationStatus::Fallback { .. }
|
||||
));
|
||||
assert!(shown.scene().is_some());
|
||||
}
|
||||
assert_eq!(document.project(), &accepted_project);
|
||||
assert_eq!(document.bundle(), &accepted_source);
|
||||
assert_eq!(document.revision(), revision);
|
||||
assert!(document.undo());
|
||||
assert_eq!(document.project(), &initial_project);
|
||||
assert_eq!(document.bundle(), &initial_source);
|
||||
assert!(document.redo());
|
||||
assert_eq!(document.project(), &accepted_project);
|
||||
assert_eq!(document.bundle(), &accepted_source);
|
||||
}
|
||||
|
||||
const FIXTURE: &str = r#"arcadia 7;
|
||||
project display_probe "Scenario display probe" id "70000000-0000-4000-8000-000000000001" {
|
||||
oa_activity source "Source" id "70000000-0000-4000-8000-000000000002" {}
|
||||
oa_activity target "Target" id "70000000-0000-4000-8000-000000000003" {}
|
||||
interaction exchange "Repeated exchange" id "70000000-0000-4000-8000-000000000004" { source @source; target @target; }
|
||||
oa_scenario conversation "Conversation" id "70000000-0000-4000-8000-000000000005" { viewpoint OperationalActivity; steps [@first, @second, @call, @reply, @unfinished]; }
|
||||
oa_lifeline left "Left" id "70000000-0000-4000-8000-000000000006" { parent @conversation; represented @source; }
|
||||
oa_lifeline right "Right" id "70000000-0000-4000-8000-000000000007" { parent @conversation; represented @target; }
|
||||
oa_occurrence first "First" id "70000000-0000-4000-8000-000000000008" { parent @conversation; body { Exchange { exchange @exchange; sender @left; receiver @right; message_kind Asynchronous; }; }; }
|
||||
oa_occurrence second "Second" id "70000000-0000-4000-8000-000000000009" { parent @conversation; body { Exchange { exchange @exchange; sender @left; receiver @right; message_kind Asynchronous; }; }; }
|
||||
oa_occurrence call "Call" id "70000000-0000-4000-8000-00000000000a" { parent @conversation; body { Exchange { exchange none; sender @right; receiver @right; message_kind Call; }; }; }
|
||||
oa_occurrence reply "Reply" id "70000000-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 "70000000-0000-4000-8000-00000000000c" { parent @conversation; body { Exchange { exchange @exchange; sender @left; receiver none; message_kind Asynchronous; }; }; }
|
||||
}
|
||||
"#;
|
||||
@@ -458,7 +458,8 @@ fn test_only_upstream_row_offsets_update_lifetime_segments_and_endpoints_without
|
||||
assert_eq!(scene.activations.len(), 2);
|
||||
for (call, reply) in [(c1, r1), (c2, r2)] {
|
||||
assert!(scene.activations.iter().any(|segment| {
|
||||
segment.call == call && segment.finish == Finish::Reply(reply)
|
||||
segment.call == call
|
||||
&& segment.finish == Finish::Reply(reply)
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,7 +219,6 @@ pub(super) fn view<'a>(app: &'a App, owner: Id, out: Column<'a, Message>) -> Ele
|
||||
graph.interaction = Some((context, state.tool, clean));
|
||||
let scale = graph.scale;
|
||||
let scope = super::super::canvas_workspace::Scope {
|
||||
scenario_view: None,
|
||||
document: context.document,
|
||||
owner,
|
||||
revision: context.revision,
|
||||
|
||||
@@ -170,13 +170,6 @@ impl Surface {
|
||||
{
|
||||
"State views"
|
||||
}
|
||||
Self::Saved(id)
|
||||
if p.diagrams
|
||||
.get(&id)
|
||||
.is_some_and(|d| d.projection.scenario().is_some()) =>
|
||||
{
|
||||
"Scenarios"
|
||||
}
|
||||
Self::Saved(_) => "Architecture",
|
||||
Self::Process(_) => "Processes and chains",
|
||||
Self::Scenario(_) => "Scenarios",
|
||||
@@ -283,18 +276,6 @@ pub(crate) fn saved_usages_for(p: &Project, subject: Id, only_diagram: Option<Id
|
||||
if only_diagram.is_some_and(|id| !p.diagrams.contains_key(&id)) {
|
||||
return Vec::new();
|
||||
}
|
||||
if let Some(diagram) = only_diagram
|
||||
.and_then(|id| p.diagrams.get(&id))
|
||||
.filter(|d| d.projection.scenario().is_some())
|
||||
{
|
||||
return crate::behavior::scenario::State::default().representation_usages(
|
||||
p,
|
||||
crate::behavior::scenario_layout::Representation::Saved {
|
||||
diagram: diagram.id,
|
||||
},
|
||||
subject,
|
||||
);
|
||||
}
|
||||
let index = ViewIndex::new(p);
|
||||
let mut usages = Vec::new();
|
||||
for diagram in p
|
||||
@@ -302,18 +283,6 @@ pub(crate) fn saved_usages_for(p: &Project, subject: Id, only_diagram: Option<Id
|
||||
.values()
|
||||
.filter(|diagram| only_diagram.is_none_or(|id| diagram.id == id))
|
||||
{
|
||||
if diagram.projection.scenario().is_some() {
|
||||
usages.extend(
|
||||
crate::behavior::scenario::State::default().representation_usages(
|
||||
p,
|
||||
crate::behavior::scenario_layout::Representation::Saved {
|
||||
diagram: diagram.id,
|
||||
},
|
||||
subject,
|
||||
),
|
||||
);
|
||||
continue;
|
||||
}
|
||||
let view = projection::project_diagram_with_index(p, diagram, &index);
|
||||
let surface = Surface::Saved(diagram.id);
|
||||
if subject == diagram.id || diagram.projection.state_machine() == Some(subject) {
|
||||
|
||||
@@ -804,27 +804,22 @@ fn inspector(app: &App) -> View<'_, Message> {
|
||||
);
|
||||
}
|
||||
}
|
||||
let actions = row![
|
||||
button(text("Apply changes").size(12))
|
||||
.padding([9, 12])
|
||||
.on_press(Message::Apply)
|
||||
.width(Fill),
|
||||
action("Revert", Message::RevertProperties)
|
||||
]
|
||||
.spacing(5);
|
||||
body = body.push(
|
||||
row![
|
||||
button(text("Apply changes").size(12))
|
||||
.padding([9, 12])
|
||||
.on_press(Message::Apply)
|
||||
.width(Fill),
|
||||
action("Revert", Message::RevertProperties)
|
||||
]
|
||||
.spacing(5),
|
||||
);
|
||||
if let Some(d) = &app.draft {
|
||||
body = body.push(forms::view(d, p));
|
||||
}
|
||||
container(
|
||||
column![
|
||||
column![
|
||||
tabs,
|
||||
container(actions).padding(iced::Padding {
|
||||
right: 14.,
|
||||
..Default::default()
|
||||
})
|
||||
]
|
||||
.spacing(12),
|
||||
tabs,
|
||||
scrollable(body.padding(iced::Padding {
|
||||
right: 14.,
|
||||
..Default::default()
|
||||
|
||||
@@ -14,14 +14,14 @@ mod communication_limits;
|
||||
mod data_contracts;
|
||||
#[path = "http/port_anchors.rs"]
|
||||
mod port_anchors;
|
||||
#[path = "http/scenario_layout.rs"]
|
||||
mod scenario_layout;
|
||||
#[path = "http/semantic_transitions.rs"]
|
||||
mod semantic_transitions;
|
||||
#[path = "http/source6_views.rs"]
|
||||
mod source6_views;
|
||||
#[path = "http/source7_contracts.rs"]
|
||||
mod source7_contracts;
|
||||
#[path = "http/scenario_layout.rs"]
|
||||
mod scenario_layout;
|
||||
#[path = "http/source_projects.rs"]
|
||||
mod source_projects;
|
||||
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
# Scenario arrangement selection
|
||||
|
||||
An explicit arrangement change follows an inspector that is showing the current Saved Diagram record. Switching from Saved A to Saved B selects B and refreshes its Properties draft. Switching that view inspection to Automatic selects the Scenario owner, since Automatic has no Diagram record. An occurrence, lifeline, Scenario owner or independently selected foreign view keeps its selection. Returning from Automatic to a Saved view therefore preserves an already selected Scenario owner.
|
||||
|
||||
The follow intention is captured before the existing property Apply. The destination must pass the existing owner/context checks; a rejected draft or stale event cannot change selection. A same-view UUID edit follows the resulting Diagram identity. Successful entry refreshes the selected view's draft without a second Apply or a new document transaction. Passive page navigation and Back retain their existing behavior.
|
||||
|
||||
This corrects the actual Scenario picker (`CanvasEvent::Representation`). Previously, selecting A's whole-view usage and then choosing B left A selected, so the exact-current-view Details guard disabled Properties. Preserving that foreign view selection would make the inspector disagree with an explicit view change. Broadly selecting B after every arrangement change was rejected because it would discard an engineer's independent model-element inspection. The separate `Message::Diagram` handler already follows the current view, but its global UI picker excludes Scenario diagrams and cannot substitute for this workflow.
|
||||
|
||||
The regression module `app::scenario_details_tests` exercises the real picker overlay and Properties button, independent selections, Automatic, valid draft application and exact Undo/Redo, same-view UUID edits, and invalid/stale refusals. A container ID exposes the unchanged picker's bounds to the mounted evaluator. Native acceptance must retain the original A-record → Scenario arrangement B → Details → Properties workflow. Compilation and actual execution status belong to the linked review and [Gitea issue #24](http://217.177.34.108:3000/sorokin.oleg.edu/ARCADIA-Studio/issues/24).
|
||||
Reference in New Issue
Block a user