Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b8685416f5 | ||
|
|
26979c1093 | ||
|
|
53d01a3d44 | ||
|
|
3aa80de89c | ||
|
|
79cc9d5551 | ||
|
|
3f9e6a18af | ||
|
|
7836a93edb | ||
|
|
f714a25bbc | ||
|
|
cb941367d7 | ||
|
|
96b756bece | ||
|
|
e624d5b9c4 | ||
|
|
d7c065991d |
@@ -0,0 +1,27 @@
|
||||
//! Read and validate a saved acceptance fixture without rewriting its source.
|
||||
//! cargo run --locked -p oa-core --example attachment_snapshot -- input.arcadia output.json
|
||||
use oa_core::{persistence, validate_candidate};
|
||||
use std::{fs::OpenOptions, io::Write, path::Path};
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let args: Vec<_> = std::env::args_os().skip(1).collect();
|
||||
if args.len() != 2 {
|
||||
return Err("Expected input source/JSON and a new output JSON path".into());
|
||||
}
|
||||
let project = persistence::load(Path::new(&args[0]))?;
|
||||
validate_candidate(&project)?;
|
||||
let bytes = serde_json::to_vec_pretty(&project)?;
|
||||
let mut output = OpenOptions::new()
|
||||
.write(true)
|
||||
.create_new(true)
|
||||
.open(&args[1])?;
|
||||
output.write_all(&bytes)?;
|
||||
output.write_all(b"\n")?;
|
||||
output.sync_all()?;
|
||||
println!(
|
||||
"Validated {} objects and {} views; saved a complete Project snapshot",
|
||||
project.identities().len(),
|
||||
project.diagrams.len()
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
//! Read-only saved-State geometry evidence for a predeclared native bend trial.
|
||||
//!
|
||||
//! Usage:
|
||||
//! state_bend_routing_snapshot INPUT.arcadia NEW_OUTPUT.json
|
||||
//!
|
||||
//! Loads and validates the complete Project, then independently projects/routes
|
||||
//! every saved State view through core APIs. The complete Project permits exact
|
||||
//! semantic and presentation comparison; derived geometry permits declaring a
|
||||
//! segment and insertion position before native actions. No desktop command,
|
||||
//! planner, gesture, or pin insertion helper is called. Input is never written;
|
||||
//! output uses create_new and fails rather than overwriting an existing file.
|
||||
//!
|
||||
//! Limits: this shares production core routing, so it is not an independent
|
||||
//! mathematical test of that router, nor evidence of UI picking/gesture success.
|
||||
//! It does not generate expected mutations or adapt an oracle to observed edits.
|
||||
//! The acceptance recipe must declare the intended segment/index/point and exact
|
||||
//! Project mutation before UI execution, and bind this executable/source/input
|
||||
//! and output hashes externally. Warning strings are diagnostic Debug output,
|
||||
//! not a stable interchange schema. Missing/hidden/internal transitions have no
|
||||
//! routed edge; their semantic records remain in the complete Project snapshot.
|
||||
|
||||
use oa_core::{persistence, projection, routing, validate_candidate};
|
||||
use serde_json::json;
|
||||
use std::{fs::OpenOptions, io::Write, path::Path};
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let args: Vec<_> = std::env::args_os().skip(1).collect();
|
||||
if args.len() != 2 {
|
||||
return Err("Expected input source/JSON and a new output JSON path".into());
|
||||
}
|
||||
let project = persistence::load(Path::new(&args[0]))?;
|
||||
validate_candidate(&project)?;
|
||||
let mut views = Vec::new();
|
||||
for (diagram_id, diagram) in &project.diagrams {
|
||||
let Some(machine) = diagram.projection.state_machine() else {
|
||||
continue;
|
||||
};
|
||||
let projected = projection::project_diagram(&project, diagram);
|
||||
let routed = routing::route_diagram(&project, diagram, &projected);
|
||||
let edges: Vec<_> = routed
|
||||
.edges
|
||||
.iter()
|
||||
.map(|(edge_id, edge)| {
|
||||
json!({
|
||||
"edge": edge_id,
|
||||
"id": edge.id,
|
||||
"points": edge.points,
|
||||
"pins": edge.pins,
|
||||
"pin_fractions": edge.pin_fractions,
|
||||
"custom_suspended": edge.custom_suspended,
|
||||
"warnings": edge.warnings.iter().map(|warning| format!("{warning:?}")).collect::<Vec<_>>(),
|
||||
"label": {
|
||||
"text": edge.label.text,
|
||||
"fraction": edge.label.fraction,
|
||||
"anchor": edge.label.anchor,
|
||||
"center": edge.label.center,
|
||||
"bounds": {
|
||||
"position": edge.label.bounds.position,
|
||||
"size": edge.label.bounds.size
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
views.push(json!({
|
||||
"diagram": diagram_id,
|
||||
"machine": machine,
|
||||
"projected": projected,
|
||||
"routed_bounds": {
|
||||
"position": routed.bounds.position,
|
||||
"size": routed.bounds.size
|
||||
},
|
||||
"routed_edges": edges
|
||||
}));
|
||||
}
|
||||
// Preserve the canonical typed Project serialization (including f32
|
||||
// formatting). Serializing it through Value directly promotes f32 to f64.
|
||||
let project_json: serde_json::Value = serde_json::from_slice(&serde_json::to_vec(&project)?)?;
|
||||
let snapshot = json!({
|
||||
"schema": "state-bend-routing-snapshot/v1",
|
||||
"project": project_json,
|
||||
"state_views": views
|
||||
});
|
||||
// Finish all reading, validation, routing and serialization before creating
|
||||
// the new evidence file. A failed load cannot leave an apparent snapshot.
|
||||
let mut bytes = serde_json::to_vec_pretty(&snapshot)?;
|
||||
bytes.push(b'\n');
|
||||
let mut output = OpenOptions::new()
|
||||
.write(true)
|
||||
.create_new(true)
|
||||
.open(&args[1])?;
|
||||
output.write_all(&bytes)?;
|
||||
output.sync_all()?;
|
||||
println!(
|
||||
"Validated {} objects and {} saved views; snapshotted {} State views and the complete Project",
|
||||
project.identities().len(),
|
||||
project.diagrams.len(),
|
||||
views.len()
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
@@ -3,6 +3,8 @@
|
||||
mod semantic_source;
|
||||
#[path = "migration_v2/source.rs"]
|
||||
mod v2_source;
|
||||
pub(crate) use crate::source_defaults::Mode as DeclarationFormat;
|
||||
use crate::source_defaults::{self, Context as DefaultContext};
|
||||
use crate::*;
|
||||
use serde_json::{Map, Value};
|
||||
use std::{collections::BTreeMap, fmt};
|
||||
@@ -645,25 +647,34 @@ fn offset_for(source: &str, line: usize, column: usize) -> usize {
|
||||
source.len()
|
||||
}
|
||||
|
||||
/// Canonical output uses persistent aliases and explicit identities. Typed
|
||||
/// nested records are ordinary language fields; JSON documents are not embedded.
|
||||
/// Canonical output uses persistent aliases and explicit identities, omitting
|
||||
/// only values supplied by source defaults. Typed nested records are ordinary
|
||||
/// language fields; JSON documents are not embedded.
|
||||
pub fn format(project: &Project) -> String {
|
||||
let mut out = std::format!(
|
||||
"arcadia {SCHEMA_VERSION};\nproject {} {} id \"{}\" {{\n description {};\n\n",
|
||||
"arcadia {SCHEMA_VERSION};\nproject {} {} id \"{}\" {{\n",
|
||||
project.alias,
|
||||
quote(&project.name),
|
||||
project.id,
|
||||
quote(&project.description)
|
||||
);
|
||||
for (_, declaration) in format_declarations(project) {
|
||||
if !project.description.is_empty() {
|
||||
out.push_str(&std::format!(
|
||||
" description {};\n",
|
||||
quote(&project.description)
|
||||
));
|
||||
}
|
||||
out.push('\n');
|
||||
for (_, declaration) in format_declarations(project, DeclarationFormat::Compact) {
|
||||
out.push_str(&declaration);
|
||||
}
|
||||
out.push_str("}\n");
|
||||
out
|
||||
}
|
||||
|
||||
/// The same typed declaration writer is used by flat and modular source output.
|
||||
pub(crate) fn format_declarations(project: &Project) -> Vec<(Id, String)> {
|
||||
/// Shared typed writer for canonical output and lossless editing. Complete edit
|
||||
/// comparisons retain defaults; emitted declarations and value fragments apply
|
||||
/// only the omission rules valid in their selected source context.
|
||||
pub(crate) fn format_declarations(project: &Project, mode: DeclarationFormat) -> Vec<(Id, String)> {
|
||||
let aliases = project
|
||||
.identities()
|
||||
.into_iter()
|
||||
@@ -675,6 +686,7 @@ pub(crate) fn format_declarations(project: &Project) -> Vec<(Id, String)> {
|
||||
let mut fields = payload(&serde_json::to_value(&e.body).unwrap());
|
||||
fields.insert("description".into(), Value::String(e.description.clone()));
|
||||
fields.insert("parent".into(), serde_json::to_value(e.parent).unwrap());
|
||||
let fields = source_defaults::fields(DefaultContext::Element(e.kind()), &fields, mode);
|
||||
write_declaration(
|
||||
&mut out,
|
||||
&element_word(e.kind(), e.layer()),
|
||||
@@ -690,6 +702,7 @@ pub(crate) fn format_declarations(project: &Project) -> Vec<(Id, String)> {
|
||||
let mut out = String::new();
|
||||
let mut fields = payload(&serde_json::to_value(&r.body).unwrap());
|
||||
fields.insert("description".into(), Value::String(r.description.clone()));
|
||||
let fields = source_defaults::fields(DefaultContext::Relation(r.kind()), &fields, mode);
|
||||
write_declaration(
|
||||
&mut out,
|
||||
&relation_word(r.kind()),
|
||||
@@ -705,6 +718,7 @@ pub(crate) fn format_declarations(project: &Project) -> Vec<(Id, String)> {
|
||||
let mut out = String::new();
|
||||
let mut fields = record_fields(d);
|
||||
fields.remove("nodes");
|
||||
let fields = source_defaults::fields(DefaultContext::Diagram, &fields, mode);
|
||||
write_declaration(
|
||||
&mut out,
|
||||
"diagram",
|
||||
@@ -719,6 +733,7 @@ pub(crate) fn format_declarations(project: &Project) -> Vec<(Id, String)> {
|
||||
let mut out = String::new();
|
||||
let mut fields = record_fields(n);
|
||||
fields.insert("diagram".into(), Value::String(d.id.to_string()));
|
||||
let fields = source_defaults::fields(DefaultContext::Node, &fields, mode);
|
||||
write_declaration(&mut out, "node", &n.alias, None, n.id, &fields, &aliases);
|
||||
declarations.push((n.id, out));
|
||||
}
|
||||
@@ -731,7 +746,7 @@ pub(crate) fn format_declarations(project: &Project) -> Vec<(Id, String)> {
|
||||
&a.alias,
|
||||
Some(&a.name),
|
||||
a.id,
|
||||
&record_fields(a),
|
||||
&source_defaults::fields(DefaultContext::Artifact, &record_fields(a), mode),
|
||||
&aliases,
|
||||
);
|
||||
declarations.push((a.id, out));
|
||||
@@ -744,7 +759,7 @@ pub(crate) fn format_declarations(project: &Project) -> Vec<(Id, String)> {
|
||||
&t.alias,
|
||||
Some(&t.name),
|
||||
t.id,
|
||||
&record_fields(t),
|
||||
&source_defaults::fields(DefaultContext::Trace, &record_fields(t), mode),
|
||||
&aliases,
|
||||
);
|
||||
declarations.push((t.id, out));
|
||||
@@ -1742,7 +1757,9 @@ pub(crate) fn resolve_declarations(
|
||||
*viewpoint = ScenarioViewpoint::MixedLegacy;
|
||||
}
|
||||
let mut body = serde_json::to_value(initial).unwrap();
|
||||
let defaults = if legacy {
|
||||
let defaults = if project.schema_version >= 7 {
|
||||
source_defaults::parser_fields(DefaultContext::Element(kind))
|
||||
} else if legacy {
|
||||
crate::persistence::v3::legacy_defaults(kind)
|
||||
.and_then(|value| value.as_object().cloned())
|
||||
.unwrap_or_else(|| payload(&body))
|
||||
@@ -1799,7 +1816,12 @@ pub(crate) fn resolve_declarations(
|
||||
let mut body =
|
||||
serde_json::to_value(RelationBody::new(kind, Id::nil(), Id::nil()))
|
||||
.unwrap();
|
||||
let merged = merge_fields(payload(&body), fields).map_err(&conversion_error)?;
|
||||
let defaults = if project.schema_version >= 7 {
|
||||
source_defaults::parser_fields(DefaultContext::Relation(kind))
|
||||
} else {
|
||||
payload(&body)
|
||||
};
|
||||
let merged = merge_fields(defaults, fields).map_err(&conversion_error)?;
|
||||
replace_payload(&mut body, merged);
|
||||
let body = serde_json::from_value(body)
|
||||
.map_err(|e| conversion_error(e.to_string()))?;
|
||||
@@ -1824,7 +1846,10 @@ pub(crate) fn resolve_declarations(
|
||||
}
|
||||
let defaults =
|
||||
serde_json::json!({"description":"","layer":"Oa","projection":"Overview","routes":[],"view_options":crate::view_options::ViewOptions::default()});
|
||||
let mut record = merge_fields(defaults.as_object().unwrap().clone(), fields)
|
||||
let defaults = if project.schema_version >= 7 {
|
||||
source_defaults::parser_fields(DefaultContext::Diagram)
|
||||
} else { defaults.as_object().unwrap().clone() };
|
||||
let mut record = merge_fields(defaults, fields)
|
||||
.map_err(&conversion_error)?;
|
||||
header(&mut record, d, true);
|
||||
record.insert("nodes".into(), serde_json::json!({}));
|
||||
@@ -1839,7 +1864,10 @@ pub(crate) fn resolve_declarations(
|
||||
return Err(conversion_error("Missing required field 'element'.".into()));
|
||||
}
|
||||
let defaults = serde_json::json!({"element":null,"position":{"x":0.0,"y":0.0},"size":{"width":224.0,"height":94.0},"collapsed":false,"port_anchors":[]});
|
||||
let mut record = merge_fields(defaults.as_object().unwrap().clone(), fields)
|
||||
let defaults = if project.schema_version >= 7 {
|
||||
source_defaults::parser_fields(DefaultContext::Node)
|
||||
} else { defaults.as_object().unwrap().clone() };
|
||||
let mut record = merge_fields(defaults, fields)
|
||||
.map_err(&conversion_error)?;
|
||||
header(&mut record, d, false);
|
||||
let node: NodePlacement = serde_json::from_value(Value::Object(record))
|
||||
@@ -1851,7 +1879,10 @@ pub(crate) fn resolve_declarations(
|
||||
return Err(conversion_error("Missing required field 'owner'.".into()));
|
||||
}
|
||||
let defaults = serde_json::json!({"description":"","owner":null,"relation":"References","uri":"","revision":null,"fragment":null});
|
||||
let mut record = merge_fields(defaults.as_object().unwrap().clone(), fields)
|
||||
let defaults = if project.schema_version >= 7 {
|
||||
source_defaults::parser_fields(DefaultContext::Artifact)
|
||||
} else { defaults.as_object().unwrap().clone() };
|
||||
let mut record = merge_fields(defaults, fields)
|
||||
.map_err(&conversion_error)?;
|
||||
header(&mut record, d, true);
|
||||
let artifact = serde_json::from_value(Value::Object(record))
|
||||
@@ -1867,7 +1898,10 @@ pub(crate) fn resolve_declarations(
|
||||
}
|
||||
}
|
||||
let defaults = serde_json::json!({"description":"","oa":null,"sa":null,"kind":"Refinement","baseline":null});
|
||||
let mut record = merge_fields(defaults.as_object().unwrap().clone(), fields)
|
||||
let defaults = if project.schema_version >= 7 {
|
||||
source_defaults::parser_fields(DefaultContext::Trace)
|
||||
} else { defaults.as_object().unwrap().clone() };
|
||||
let mut record = merge_fields(defaults, fields)
|
||||
.map_err(&conversion_error)?;
|
||||
header(&mut record, d, true);
|
||||
let trace = if project.schema_version < 5 {
|
||||
|
||||
@@ -11,6 +11,7 @@ pub mod references;
|
||||
pub mod routing;
|
||||
pub mod semantic;
|
||||
pub mod session;
|
||||
mod source_defaults;
|
||||
pub mod source_files;
|
||||
pub mod source_project;
|
||||
pub mod topology_context;
|
||||
|
||||
@@ -1502,11 +1502,45 @@ pub struct Diagram {
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct EdgeRoute {
|
||||
pub edge: Id,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub source_attachment: Option<EdgeAttachment>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub target_attachment: Option<EdgeAttachment>,
|
||||
#[serde(default)]
|
||||
pub waypoints: Vec<Position>,
|
||||
#[serde(default)]
|
||||
pub label: Option<EdgeLabel>,
|
||||
}
|
||||
|
||||
/// Presentation preference on one end of a connection. Real ports take precedence.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct EdgeAttachment {
|
||||
pub side: PortAnchorSide,
|
||||
pub offset: f32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum EdgeEnd {
|
||||
Source,
|
||||
Target,
|
||||
}
|
||||
|
||||
impl EdgeRoute {
|
||||
pub fn attachment(&self, end: EdgeEnd) -> Option<EdgeAttachment> {
|
||||
match end {
|
||||
EdgeEnd::Source => self.source_attachment,
|
||||
EdgeEnd::Target => self.target_attachment,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_attachment(&mut self, end: EdgeEnd, attachment: Option<EdgeAttachment>) {
|
||||
match end {
|
||||
EdgeEnd::Source => self.source_attachment = attachment,
|
||||
EdgeEnd::Target => self.target_attachment = attachment,
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct EdgeLabel {
|
||||
|
||||
+132
-38
@@ -1,7 +1,12 @@
|
||||
//! Deterministic, bounded diagram geometry. Only authored pins belong in the model;
|
||||
//! callers share this derived geometry for drawing, picking, fitting and export.
|
||||
use crate::projection::{self, ProjectedEdge, ProjectedNode, ProjectedView};
|
||||
use crate::{Diagram, Id, Position, Project, Relation, RelationBody, RelationKind, Size};
|
||||
use crate::{
|
||||
Diagram, EdgeAttachment, EdgeEnd, Id, PortAnchorSide, Position, Project, Relation,
|
||||
RelationBody, RelationKind, Size,
|
||||
};
|
||||
mod attachments;
|
||||
pub use attachments::{attachment_from_point, attachment_point, semantic_port_endpoint};
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::{BTreeMap, BTreeSet, BinaryHeap};
|
||||
use std::fmt;
|
||||
@@ -41,6 +46,7 @@ pub struct RoutedEdge {
|
||||
// Derived solver state, never persisted. A preview must inherit the same
|
||||
// remaining work budget as this edge had in stable-ID settled traversal.
|
||||
search_budget_before: usize,
|
||||
attachments: [Option<EdgeAttachment>; 2],
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
@@ -173,6 +179,7 @@ pub fn association_end_geometry(
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum RouteWarning {
|
||||
CoincidentAttachments,
|
||||
PinInsideObstacle { pin: usize, obstacle: Id },
|
||||
NoClearPath,
|
||||
SearchBudgetExhausted,
|
||||
@@ -181,6 +188,9 @@ pub enum RouteWarning {
|
||||
impl fmt::Display for RouteWarning {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::CoincidentAttachments => f.write_str(
|
||||
"The two attachments coincide; move either end to separate the loop tips.",
|
||||
),
|
||||
Self::PinInsideObstacle { pin, .. } => {
|
||||
write!(f, "Bend {} is inside a card or its clearance", pin + 1)
|
||||
}
|
||||
@@ -374,7 +384,14 @@ struct Endpoint {
|
||||
point: Position,
|
||||
stub: Position,
|
||||
}
|
||||
fn endpoints(node: &ProjectedNode, port: Option<Id>, view: &ProjectedView) -> Vec<Endpoint> {
|
||||
fn endpoints(
|
||||
project: &Project,
|
||||
diagram: &Diagram,
|
||||
node: &ProjectedNode,
|
||||
port: Option<Id>,
|
||||
view: &ProjectedView,
|
||||
attachment: Option<EdgeAttachment>,
|
||||
) -> Vec<Endpoint> {
|
||||
if let Some(port) = port.and_then(|id| {
|
||||
view.ports
|
||||
.iter()
|
||||
@@ -389,26 +406,18 @@ fn endpoints(node: &ProjectedNode, port: Option<Id>, view: &ProjectedView) -> Ve
|
||||
),
|
||||
}];
|
||||
}
|
||||
let r = Rect::node(node);
|
||||
let mid = pos((r.left + r.right) / 2.0, (r.top + r.bottom) / 2.0);
|
||||
vec![
|
||||
Endpoint {
|
||||
point: pos(r.left, mid.y),
|
||||
stub: pos(r.left - PORT_STUB, mid.y),
|
||||
},
|
||||
Endpoint {
|
||||
point: pos(r.right, mid.y),
|
||||
stub: pos(r.right + PORT_STUB, mid.y),
|
||||
},
|
||||
Endpoint {
|
||||
point: pos(mid.x, r.top),
|
||||
stub: pos(mid.x, r.top - PORT_STUB),
|
||||
},
|
||||
Endpoint {
|
||||
point: pos(mid.x, r.bottom),
|
||||
stub: pos(mid.x, r.bottom + PORT_STUB),
|
||||
},
|
||||
if let Some(attachment) = attachment {
|
||||
return vec![attachments::endpoint(project, diagram, node, attachment)];
|
||||
}
|
||||
[
|
||||
PortAnchorSide::Left,
|
||||
PortAnchorSide::Right,
|
||||
PortAnchorSide::Top,
|
||||
PortAnchorSide::Bottom,
|
||||
]
|
||||
.into_iter()
|
||||
.map(|side| attachments::endpoint(project, diagram, node, EdgeAttachment { side, offset: 0.5 }))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn ancestors(id: Id, nodes: &BTreeMap<Id, &ProjectedNode>, out: &mut BTreeSet<Id>) {
|
||||
@@ -507,6 +516,12 @@ fn route_diagram_impl(
|
||||
.is_some_and(|(source, target)| source != edge.source || target != edge.target);
|
||||
let custom_suspended = promoted;
|
||||
let route = if promoted { None } else { stored };
|
||||
let attachments = [EdgeEnd::Source, EdgeEnd::Target].map(|end| {
|
||||
semantic_port_endpoint(project, edge.id, end)
|
||||
.is_none()
|
||||
.then(|| route.and_then(|r| r.attachment(end)))
|
||||
.flatten()
|
||||
});
|
||||
let pins = route.map_or_else(Vec::new, |r| r.waypoints.clone());
|
||||
let obstacles = edge_obstacles(edge, &nodes, &rectangles, &headers);
|
||||
|
||||
@@ -517,7 +532,10 @@ fn route_diagram_impl(
|
||||
});
|
||||
if let Some(cached) = cached {
|
||||
budget = cached.search_budget_before;
|
||||
if cached.pins == pins && cached.custom_suspended == custom_suspended {
|
||||
if cached.pins == pins
|
||||
&& cached.attachments == attachments
|
||||
&& cached.custom_suspended == custom_suspended
|
||||
{
|
||||
// Label-only editing cannot change the connection beneath the
|
||||
// pointer, including a settled fallback with routing warnings.
|
||||
for &point in &cached.points {
|
||||
@@ -543,9 +561,22 @@ fn route_diagram_impl(
|
||||
}
|
||||
let (points, pin_lengths, failure) = route_edge(
|
||||
edge,
|
||||
source,
|
||||
target,
|
||||
view,
|
||||
&endpoints(
|
||||
project,
|
||||
diagram,
|
||||
source,
|
||||
semantic_port_endpoint(project, edge.id, EdgeEnd::Source).or(edge.source_port),
|
||||
view,
|
||||
attachments[0],
|
||||
),
|
||||
&endpoints(
|
||||
project,
|
||||
diagram,
|
||||
target,
|
||||
semantic_port_endpoint(project, edge.id, EdgeEnd::Target).or(edge.target_port),
|
||||
view,
|
||||
attachments[1],
|
||||
),
|
||||
&pins,
|
||||
&obstacles,
|
||||
&previous,
|
||||
@@ -574,6 +605,7 @@ fn route_diagram_impl(
|
||||
warnings,
|
||||
custom_suspended,
|
||||
search_budget_before,
|
||||
attachments,
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -679,6 +711,46 @@ struct RoutingSpace<'a> {
|
||||
xs: Vec<f32>,
|
||||
ys: Vec<f32>,
|
||||
}
|
||||
|
||||
fn coincident_detour(a: Endpoint, obstacles: &[Rect]) -> [Position; 3] {
|
||||
let direction = |delta: f32| if delta == 0. { 0. } else { delta.signum() };
|
||||
let normal = pos(
|
||||
direction(a.stub.x - a.point.x),
|
||||
direction(a.stub.y - a.point.y),
|
||||
);
|
||||
let tangent = pos(-normal.y, normal.x);
|
||||
let candidates: Vec<_> = [36., 72., 144., 288.]
|
||||
.into_iter()
|
||||
.flat_map(|extent| {
|
||||
[-1., 1.].into_iter().map(move |side| {
|
||||
[
|
||||
pos(a.stub.x + normal.x * extent, a.stub.y + normal.y * extent),
|
||||
pos(
|
||||
a.stub.x + (normal.x + tangent.x * side) * extent,
|
||||
a.stub.y + (normal.y + tangent.y * side) * extent,
|
||||
),
|
||||
pos(
|
||||
a.stub.x + tangent.x * side * extent,
|
||||
a.stub.y + tangent.y * side * extent,
|
||||
),
|
||||
]
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
// These are computed loop guards, not authored hard pins. Prefer a clear
|
||||
// orientation/size before asking the bounded router to connect them.
|
||||
candidates
|
||||
.iter()
|
||||
.find(|p| clear_path(&[a.stub, p[0], p[1], p[2], a.stub], obstacles))
|
||||
.or_else(|| {
|
||||
candidates.iter().find(|p| {
|
||||
p.iter()
|
||||
.all(|point| !obstacles.iter().any(|r| r.contains(*point)))
|
||||
})
|
||||
})
|
||||
.copied()
|
||||
.unwrap_or(candidates[0])
|
||||
}
|
||||
impl<'a> RoutingSpace<'a> {
|
||||
fn new(obstacles: &'a [Rect]) -> Self {
|
||||
Self {
|
||||
@@ -692,24 +764,41 @@ impl<'a> RoutingSpace<'a> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn route_edge(
|
||||
edge: &ProjectedEdge,
|
||||
source: &ProjectedNode,
|
||||
target: &ProjectedNode,
|
||||
view: &ProjectedView,
|
||||
source_ends: &[Endpoint],
|
||||
target_ends: &[Endpoint],
|
||||
pins: &[Position],
|
||||
obstacles: &[Rect],
|
||||
previous: &[Segment],
|
||||
budget: &mut usize,
|
||||
) -> EdgePath {
|
||||
// Coincident authored tips are valid presentation, including on self loops.
|
||||
// Preserve them and add an external detour; never index an empty candidate
|
||||
// list or turn the connection into an out-and-back degenerate stub.
|
||||
let coincident = edge.source == edge.target
|
||||
&& source_ends.len() == 1
|
||||
&& target_ends.len() == 1
|
||||
&& source_ends[0].point == target_ends[0].point
|
||||
&& source_ends[0].stub == target_ends[0].stub;
|
||||
let authored_pin_count = pins.len();
|
||||
let mut loop_pins = Vec::new();
|
||||
if coincident {
|
||||
let a = source_ends[0];
|
||||
loop_pins.extend_from_slice(pins);
|
||||
loop_pins.extend(coincident_detour(a, obstacles));
|
||||
}
|
||||
let pins = if coincident { &loop_pins[..] } else { pins };
|
||||
let space = RoutingSpace::new(obstacles);
|
||||
let mut candidates = Vec::new();
|
||||
for a in endpoints(source, edge.source_port, view) {
|
||||
for b in endpoints(target, edge.target_port, view) {
|
||||
for &a in source_ends {
|
||||
for &b in target_ends {
|
||||
// A real self-relation must leave and return at distinct anchors.
|
||||
// Reusing one anchor makes the cheapest path a degenerate stub.
|
||||
if edge.source == edge.target
|
||||
&& edge.source_port.is_none()
|
||||
&& edge.target_port.is_none()
|
||||
&& a.point == b.point
|
||||
&& a.stub == b.stub
|
||||
&& !coincident
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -729,10 +818,9 @@ fn route_edge(
|
||||
// Try all side combinations cheaply before spending the bounded grid budget.
|
||||
for search in [false, true] {
|
||||
for &(estimate, a, b) in &candidates {
|
||||
if best
|
||||
.as_ref()
|
||||
.is_some_and(|(cost, _, _)| estimate + 2.0 * PORT_STUB > *cost)
|
||||
{
|
||||
if best.as_ref().is_some_and(|(cost, _, _)| {
|
||||
estimate + manhattan(a.point, a.stub) + manhattan(b.point, b.stub) > *cost
|
||||
}) {
|
||||
continue;
|
||||
}
|
||||
if obstacles
|
||||
@@ -748,7 +836,7 @@ fn route_edge(
|
||||
let mut occupied = previous.to_vec();
|
||||
record_segments(&mut occupied, &points);
|
||||
let mut pin_lengths = Vec::new();
|
||||
let mut distance = PORT_STUB;
|
||||
let mut distance = manhattan(a.point, a.stub);
|
||||
let mut start = a.stub;
|
||||
let mut failed = false;
|
||||
for (index, end) in pins
|
||||
@@ -792,15 +880,20 @@ fn route_edge(
|
||||
break;
|
||||
}
|
||||
}
|
||||
if let Some((_, points, pin_lengths)) = best {
|
||||
return (points, pin_lengths, None);
|
||||
if let Some((_, points, mut pin_lengths)) = best {
|
||||
pin_lengths.truncate(authored_pin_count);
|
||||
return (
|
||||
points,
|
||||
pin_lengths,
|
||||
coincident.then_some(RouteWarning::CoincidentAttachments),
|
||||
);
|
||||
}
|
||||
// Recoverable fallback retains every hard pin, in order, and the actual port
|
||||
// leads. Its warning is deliberately visible to consumers.
|
||||
let (_, a, b) = candidates[0];
|
||||
let mut points = vec![a.point, a.stub];
|
||||
let mut pin_lengths = Vec::new();
|
||||
let mut distance = PORT_STUB;
|
||||
let mut distance = manhattan(a.point, a.stub);
|
||||
let mut start = a.stub;
|
||||
for (index, end) in pins
|
||||
.iter()
|
||||
@@ -833,6 +926,7 @@ fn route_edge(
|
||||
start = end;
|
||||
}
|
||||
points.push(b.point);
|
||||
pin_lengths.truncate(authored_pin_count);
|
||||
(
|
||||
points,
|
||||
pin_lengths,
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
//! One boundary definition shared by persisted routing and attachment gestures.
|
||||
use super::*;
|
||||
use crate::{EdgeAttachment, EdgeEnd, Kind, PortAnchorSide};
|
||||
|
||||
/// Semantic authority, independent of whether projection currently exposes a port.
|
||||
pub fn semantic_port_endpoint(project: &Project, edge: Id, end: EdgeEnd) -> Option<Id> {
|
||||
let endpoint = if let Some(relation) = project.relations.get(&edge) {
|
||||
match (&relation.body, end) {
|
||||
(RelationBody::FunctionalExchange { source_port, .. }, EdgeEnd::Source) => *source_port,
|
||||
(RelationBody::FunctionalExchange { target_port, .. }, EdgeEnd::Target) => *target_port,
|
||||
(_, EdgeEnd::Source) => relation.source(),
|
||||
(_, EdgeEnd::Target) => relation.target(),
|
||||
}
|
||||
} else {
|
||||
let trace = project.traces.get(&edge)?;
|
||||
match end {
|
||||
EdgeEnd::Source => trace.oa,
|
||||
EdgeEnd::Target => trace.sa,
|
||||
}
|
||||
};
|
||||
project
|
||||
.elements
|
||||
.get(&endpoint)
|
||||
.filter(|e| e.kind() == Kind::Port)
|
||||
.map(|_| endpoint)
|
||||
}
|
||||
|
||||
/// Intersect the chosen cardinal scan line with the painted shape. Offset is
|
||||
/// measured over the complete projected bounding side, including its corners.
|
||||
/// Terminate's X uses its outermost stroke intersection rather than a contour.
|
||||
pub fn attachment_point(
|
||||
project: &Project,
|
||||
diagram: &Diagram,
|
||||
node: &ProjectedNode,
|
||||
attachment: &EdgeAttachment,
|
||||
) -> Position {
|
||||
let vertical = matches!(
|
||||
attachment.side,
|
||||
PortAnchorSide::Left | PortAnchorSide::Right
|
||||
);
|
||||
let (extent, depth) = if vertical {
|
||||
(node.size.height, node.size.width)
|
||||
} else {
|
||||
(node.size.width, node.size.height)
|
||||
};
|
||||
let along = attachment.offset.clamp(0., 1.) * extent;
|
||||
let t = 2. * attachment.offset.clamp(0., 1.) - 1.;
|
||||
let kind = diagram
|
||||
.projection
|
||||
.state_machine()
|
||||
.and_then(|_| project.elements.get(&node.element))
|
||||
.map(|e| e.kind());
|
||||
let inset = match kind {
|
||||
Some(Kind::Choice) => depth * 0.5 * t.abs(),
|
||||
Some(Kind::Terminate) => {
|
||||
depth
|
||||
* attachment
|
||||
.offset
|
||||
.clamp(0., 1.)
|
||||
.min(1. - attachment.offset.clamp(0., 1.))
|
||||
}
|
||||
Some(
|
||||
Kind::Initial
|
||||
| Kind::Junction
|
||||
| Kind::Final
|
||||
| Kind::ShallowHistory
|
||||
| Kind::DeepHistory
|
||||
| Kind::EntryPoint
|
||||
| Kind::ExitPoint,
|
||||
) => depth * 0.5 * (1. - (1. - t * t).max(0.).sqrt()),
|
||||
Some(Kind::Region | Kind::Fork | Kind::Join) => 0.,
|
||||
_ => {
|
||||
let radius = 10_f32.min(extent / 2.).min(depth / 2.);
|
||||
let corner = (radius - along.min(extent - along)).max(0.);
|
||||
radius - (radius * radius - corner * corner).max(0.).sqrt()
|
||||
}
|
||||
};
|
||||
match attachment.side {
|
||||
PortAnchorSide::Left => pos(node.position.x + inset, node.position.y + along),
|
||||
PortAnchorSide::Right => pos(
|
||||
node.position.x + node.size.width - inset,
|
||||
node.position.y + along,
|
||||
),
|
||||
PortAnchorSide::Top => pos(node.position.x + along, node.position.y + inset),
|
||||
PortAnchorSide::Bottom => pos(
|
||||
node.position.x + along,
|
||||
node.position.y + node.size.height - inset,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/// Choose a cardinal bounding side, then map its fraction onto the painted
|
||||
/// contour. Contour distances cannot distinguish the sides of a circle at its
|
||||
/// extrema: Right/0 and Top/0.5 denote the same point but different lead directions.
|
||||
/// Hysteresis is in diagram units, capped for small symbols. Only UI snapping
|
||||
/// rounds to hundredths: source/API values retain their complete precision.
|
||||
pub fn attachment_from_point(
|
||||
node: &ProjectedNode,
|
||||
cursor: Position,
|
||||
previous: Option<PortAnchorSide>,
|
||||
hysteresis: f32,
|
||||
) -> EdgeAttachment {
|
||||
let candidate = |side| EdgeAttachment {
|
||||
side,
|
||||
offset: projection::port_anchor_offset(node, side, cursor),
|
||||
};
|
||||
// Measure side intent at the box, not from a distant overshoot: Euclidean
|
||||
// distance differences converge outside a small symbol and would otherwise
|
||||
// let hysteresis retain a perpendicular side indefinitely.
|
||||
let boundary_cursor = pos(
|
||||
cursor
|
||||
.x
|
||||
.clamp(node.position.x, node.position.x + node.size.width),
|
||||
cursor
|
||||
.y
|
||||
.clamp(node.position.y, node.position.y + node.size.height),
|
||||
);
|
||||
let distance = |side| {
|
||||
length(
|
||||
projection::port_anchor_position(node, side, candidate(side).offset),
|
||||
boundary_cursor,
|
||||
)
|
||||
};
|
||||
let mut side = [
|
||||
PortAnchorSide::Left,
|
||||
PortAnchorSide::Right,
|
||||
PortAnchorSide::Top,
|
||||
PortAnchorSide::Bottom,
|
||||
]
|
||||
.into_iter()
|
||||
.min_by(|a, b| distance(*a).total_cmp(&distance(*b)))
|
||||
.unwrap();
|
||||
let hysteresis = hysteresis
|
||||
.max(0.)
|
||||
.min(node.size.width.min(node.size.height) * 0.2);
|
||||
if let Some(old) = previous
|
||||
&& distance(old) <= distance(side) + hysteresis
|
||||
{
|
||||
side = old;
|
||||
}
|
||||
let mut attachment = candidate(side);
|
||||
attachment.offset = (attachment.offset * 100.).round() / 100.;
|
||||
attachment
|
||||
}
|
||||
|
||||
pub(super) fn endpoint(
|
||||
project: &Project,
|
||||
diagram: &Diagram,
|
||||
node: &ProjectedNode,
|
||||
attachment: EdgeAttachment,
|
||||
) -> Endpoint {
|
||||
let point = attachment_point(project, diagram, node, &attachment);
|
||||
let stub = match attachment.side {
|
||||
PortAnchorSide::Left => pos(node.position.x - PORT_STUB, point.y),
|
||||
PortAnchorSide::Right => pos(node.position.x + node.size.width + PORT_STUB, point.y),
|
||||
PortAnchorSide::Top => pos(point.x, node.position.y - PORT_STUB),
|
||||
PortAnchorSide::Bottom => pos(point.x, node.position.y + node.size.height + PORT_STUB),
|
||||
};
|
||||
Endpoint { point, stub }
|
||||
}
|
||||
@@ -0,0 +1,399 @@
|
||||
//! Ordinary source defaults shared by current parsing and declaration rendering.
|
||||
//!
|
||||
//! These are source omission defaults, not graphical creation defaults. The
|
||||
//! policy operates on complete typed declaration maps. Required named fields
|
||||
//! and selected constructor payloads remain distinct from omission defaults.
|
||||
//! Historical versions use their existing frozen parser paths. Semantic baseline
|
||||
//! history is never traversed or normalized here.
|
||||
use crate::{Kind, RelationKind};
|
||||
use serde_json::{Map, Value, json};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub(crate) enum Context {
|
||||
Element(Kind),
|
||||
Relation(RelationKind),
|
||||
Diagram,
|
||||
Node,
|
||||
Artifact,
|
||||
Trace,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub(crate) enum Mode {
|
||||
CompleteForEdit,
|
||||
Compact,
|
||||
/// Internal lossless-edit fragments: retain every top-level value while
|
||||
/// compacting its selected constructor's optional nested fields.
|
||||
CompactValues,
|
||||
}
|
||||
|
||||
/// Top-level field inventory for the current ordinary reader. Callers must
|
||||
/// check required fields before merging; null entries only admit their names.
|
||||
/// This never supplies defaults inside a selected constructor.
|
||||
pub(crate) fn parser_fields(context: Context) -> Map<String, Value> {
|
||||
let mut fields = declaration_defaults(context);
|
||||
let required: &[&str] = match context {
|
||||
Context::Element(kind) => {
|
||||
fields.remove("description");
|
||||
fields.remove("parent");
|
||||
if kind == Kind::Port {
|
||||
&["contract"]
|
||||
} else {
|
||||
&[]
|
||||
}
|
||||
}
|
||||
Context::Relation(kind) => {
|
||||
fields.remove("description");
|
||||
match kind {
|
||||
RelationKind::ContextualLink => &["owner", "source", "target", "purpose"],
|
||||
RelationKind::FunctionalExchange => {
|
||||
&["source", "target", "source_port", "target_port"]
|
||||
}
|
||||
_ => &["source", "target"],
|
||||
}
|
||||
}
|
||||
Context::Diagram => &[],
|
||||
Context::Node => &["element"],
|
||||
Context::Artifact => &["owner"],
|
||||
Context::Trace => &["oa", "sa"],
|
||||
};
|
||||
for name in required {
|
||||
fields.insert((*name).into(), Value::Null);
|
||||
}
|
||||
fields
|
||||
}
|
||||
|
||||
pub(crate) fn fields(
|
||||
context: Context,
|
||||
input: &Map<String, Value>,
|
||||
mode: Mode,
|
||||
) -> Map<String, Value> {
|
||||
let mut result = input.clone();
|
||||
restore_serialization_skips(context, &mut result);
|
||||
if mode != Mode::CompleteForEdit {
|
||||
compact_nested(context, &mut result);
|
||||
}
|
||||
if mode == Mode::Compact {
|
||||
// Compact a composite and its declared default by the same nested rules
|
||||
// before whole-field comparison. This also makes compact input stable:
|
||||
// e.g. String{minimum_length:0} still denotes the default definition.
|
||||
let mut defaults = declaration_defaults(context);
|
||||
compact_nested(context, &mut defaults);
|
||||
omit_defaults(&mut result, &defaults);
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
fn restore_serialization_skips(context: Context, fields: &mut Map<String, Value>) {
|
||||
match context {
|
||||
Context::Element(Kind::Occurrence) => {
|
||||
if let Some(exchange) = constructor_payload(fields, "body", "Exchange") {
|
||||
exchange
|
||||
.entry("operation".to_owned())
|
||||
.or_insert(Value::Null);
|
||||
}
|
||||
}
|
||||
Context::Diagram => {
|
||||
if let Some(routes) = fields.get_mut("routes").and_then(Value::as_array_mut) {
|
||||
for route in routes.iter_mut().filter_map(Value::as_object_mut) {
|
||||
route
|
||||
.entry("source_attachment".to_owned())
|
||||
.or_insert(Value::Null);
|
||||
route
|
||||
.entry("target_attachment".to_owned())
|
||||
.or_insert(Value::Null);
|
||||
}
|
||||
}
|
||||
}
|
||||
Context::Node => {
|
||||
fields.entry("port_anchors".to_owned()).or_insert(json!([]));
|
||||
}
|
||||
Context::Trace => {
|
||||
if let Some(baseline) = fields.get_mut("baseline").and_then(Value::as_object_mut) {
|
||||
baseline.entry("semantic".to_owned()).or_insert(Value::Null);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn declaration_defaults(context: Context) -> Map<String, Value> {
|
||||
let mut defaults = match context {
|
||||
Context::Element(kind) => element_defaults(kind),
|
||||
Context::Relation(kind) => relation_defaults(kind),
|
||||
Context::Diagram => object(json!({
|
||||
"description": "", "layer": "Oa", "projection": "Overview",
|
||||
"routes": [], "view_options": {
|
||||
"hidden_edges": [], "relation_kinds": "All",
|
||||
"work_categories": "All", "participant_categories": "All",
|
||||
"coverage": "All", "work_contexts": "All", "exchange_labels": "Name"
|
||||
}
|
||||
})),
|
||||
Context::Node => object(json!({
|
||||
"position": {"x": 0.0, "y": 0.0},
|
||||
"size": {"width": 224.0, "height": 94.0},
|
||||
"collapsed": false, "port_anchors": []
|
||||
})),
|
||||
Context::Artifact => object(json!({
|
||||
"description": "", "relation": "References", "uri": "",
|
||||
"revision": null, "fragment": null
|
||||
})),
|
||||
Context::Trace => object(json!({
|
||||
"description": "", "kind": "Refinement", "baseline": null
|
||||
})),
|
||||
};
|
||||
match context {
|
||||
Context::Element(_) => {
|
||||
defaults.insert("description".into(), json!(""));
|
||||
defaults.insert("parent".into(), Value::Null);
|
||||
}
|
||||
Context::Relation(_) => {
|
||||
defaults.insert("description".into(), json!(""));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
defaults
|
||||
}
|
||||
|
||||
fn element_defaults(kind: Kind) -> Map<String, Value> {
|
||||
if let Some(state_kind) = kind.state_kind() {
|
||||
// The declaration selects this discriminator; no GUI factory is used.
|
||||
return object(json!({
|
||||
"kind": state_kind, "entry": "", "exit": "", "do_activity": ""
|
||||
}));
|
||||
}
|
||||
match kind {
|
||||
Kind::Process | Kind::FunctionalChain => object(json!({"steps": []})),
|
||||
Kind::ExchangeItem => object(json!({
|
||||
"kind": "Information", "mechanism": "Unspecified", "supertype": null
|
||||
})),
|
||||
Kind::ExchangeCategory => object(json!({"family": "Work", "exchanges": []})),
|
||||
Kind::DataType => object(json!({
|
||||
"definition": {"String": {"minimum_length": 0, "maximum_length": null}},
|
||||
"default": null, "unit": ""
|
||||
})),
|
||||
Kind::DataField => object(json!({
|
||||
"type_ref": "String", "minimum": 1, "maximum": 1, "unit": "",
|
||||
"direction": "Unspecified", "storage": "Value", "default": null
|
||||
})),
|
||||
Kind::Interface => object(json!({"supertype": null})),
|
||||
// Port.contract is required, even when its explicit value is Legacy.
|
||||
Kind::Port => object(json!({"legacy": null})),
|
||||
Kind::Scenario => object(json!({
|
||||
"viewpoint": "MixedLegacy", "context": null,
|
||||
"precondition": "", "postcondition": "", "steps": []
|
||||
})),
|
||||
Kind::Lifeline => object(json!({"represented": null})),
|
||||
Kind::Occurrence => object(json!({
|
||||
"body": {"Exchange": {
|
||||
"exchange": null, "sender": null, "receiver": null,
|
||||
"message_kind": "Asynchronous", "reply_to": null,
|
||||
"values": [], "operation": null
|
||||
}},
|
||||
"precondition": "", "postcondition": ""
|
||||
})),
|
||||
Kind::Event => object(json!({"body": {"Signal": {"items": []}}})),
|
||||
Kind::Constraint => object(json!({"expression": "", "constrained": []})),
|
||||
// Unit-body declarations have no additional omission defaults. A future
|
||||
// Kind reaches this branch without gaining speculative payload rules.
|
||||
_ => Map::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn relation_defaults(kind: RelationKind) -> Map<String, Value> {
|
||||
match kind {
|
||||
RelationKind::InterfaceItemAllocation => object(json!({
|
||||
"order": 0, "transmission": "Unspecified", "acquisition": "Unspecified"
|
||||
})),
|
||||
RelationKind::DataAssociation => object(json!({
|
||||
"source_role": "", "target_role": "",
|
||||
"source_minimum": 0, "target_minimum": 0,
|
||||
"source_maximum": null, "target_maximum": null,
|
||||
"source_navigable": false, "target_navigable": false
|
||||
})),
|
||||
RelationKind::Interaction | RelationKind::FunctionalExchange => {
|
||||
object(json!({"items": []}))
|
||||
}
|
||||
RelationKind::BoundaryExchange => object(json!({"items": [], "oriented": true})),
|
||||
RelationKind::CommunicationMean => object(json!({"items": [], "oriented": false})),
|
||||
RelationKind::CapabilityExtend => object(json!({"condition": ""})),
|
||||
RelationKind::SequenceLink => object(json!({"guard": ""})),
|
||||
RelationKind::StateTransition => object(json!({
|
||||
"transition_kind": "External", "trigger": "", "guard": "", "effect": "",
|
||||
"triggers": [], "effects": []
|
||||
})),
|
||||
RelationKind::StateAction => object(json!({"phase": "Do"})),
|
||||
// source/target, FunctionalExchange ports and ContextualLink's owner,
|
||||
// endpoints and purpose are required, despite factory placeholder values.
|
||||
_ => Map::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn compact_nested(context: Context, fields: &mut Map<String, Value>) {
|
||||
match context {
|
||||
Context::Element(Kind::DataType) => compact_data_definition(fields),
|
||||
Context::Element(Kind::Port) => {
|
||||
if let Some(legacy) = fields.get_mut("legacy").and_then(Value::as_object_mut) {
|
||||
omit_nulls(legacy, &["interface"]);
|
||||
}
|
||||
// Every selected PortContract payload field remains required.
|
||||
}
|
||||
Context::Element(Kind::Occurrence) => compact_occurrence(fields),
|
||||
Context::Diagram => {
|
||||
if let Some(options) = fields
|
||||
.get_mut("view_options")
|
||||
.and_then(Value::as_object_mut)
|
||||
{
|
||||
omit_defaults(
|
||||
options,
|
||||
&object(json!({
|
||||
"hidden_edges": [], "relation_kinds": "All",
|
||||
"work_categories": "All", "participant_categories": "All",
|
||||
"coverage": "All", "work_contexts": "All", "exchange_labels": "Name"
|
||||
})),
|
||||
);
|
||||
}
|
||||
if let Some(routes) = fields.get_mut("routes").and_then(Value::as_array_mut) {
|
||||
for route in routes {
|
||||
if let Some(route) = route.as_object_mut() {
|
||||
omit_defaults(
|
||||
route,
|
||||
&object(
|
||||
json!({"waypoints": [], "label": null, "source_attachment": null, "target_attachment": null}),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Route entries, EdgeLabel coordinates, projection machine IDs, and
|
||||
// Only([])/Any([]) selectors remain even when their values are empty.
|
||||
}
|
||||
Context::Trace => {
|
||||
if let Some(baseline) = fields.get_mut("baseline").and_then(Value::as_object_mut) {
|
||||
omit_nulls(baseline, &["semantic"]);
|
||||
}
|
||||
// No recursion through snapshots or semantic historical facets.
|
||||
}
|
||||
// DataValue/TypeRef payloads, EventBody fields, Node geometry/anchors,
|
||||
// contextual endpoints/purposes, and other required records stay intact.
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn compact_data_definition(fields: &mut Map<String, Value>) {
|
||||
for tag in ["Integer", "Real"] {
|
||||
if let Some(payload) = constructor_payload(fields, "definition", tag) {
|
||||
omit_nulls(payload, &["minimum", "maximum"]);
|
||||
}
|
||||
}
|
||||
if let Some(payload) = constructor_payload(fields, "definition", "String") {
|
||||
omit_nulls(payload, &["maximum_length"]);
|
||||
// minimum_length is required inside a selected String constructor.
|
||||
}
|
||||
if let Some(payload) = constructor_payload(fields, "definition", "Record") {
|
||||
omit_nulls(payload, &["supertype"]);
|
||||
}
|
||||
// Boolean has no payload; Enumeration.literals remains required even [].
|
||||
}
|
||||
|
||||
fn compact_occurrence(fields: &mut Map<String, Value>) {
|
||||
if let Some(exchange) = constructor_payload(fields, "body", "Exchange") {
|
||||
omit_defaults(
|
||||
exchange,
|
||||
&object(json!({
|
||||
"exchange": null, "sender": null, "receiver": null,
|
||||
"message_kind": "Asynchronous", "reply_to": null,
|
||||
"values": [], "operation": null
|
||||
})),
|
||||
);
|
||||
if let Some(operation) = exchange.get_mut("operation").and_then(Value::as_object_mut) {
|
||||
omit_nulls(operation, &["allocation"]);
|
||||
// Keep the containing operation field even if its record becomes {}:
|
||||
// explicit unresolved operation intent is not an absent operation.
|
||||
}
|
||||
if let Some(values) = exchange.get_mut("values").and_then(Value::as_array_mut) {
|
||||
for value in values {
|
||||
if let Some(message_value) = value.as_object_mut() {
|
||||
omit_defaults(message_value, &object(json!({"path": []})));
|
||||
}
|
||||
}
|
||||
}
|
||||
// MessageKind::Timer.expression, MessageValue.field/expression remain.
|
||||
}
|
||||
for (tag, optional) in [
|
||||
("Action", &["action", "lifeline"][..]),
|
||||
("State", &["state", "lifeline"][..]),
|
||||
("SequenceReference", &["sequence"][..]),
|
||||
("ScenarioUse", &["scenario"][..]),
|
||||
] {
|
||||
if let Some(payload) = constructor_payload(fields, "body", tag) {
|
||||
omit_nulls(payload, optional);
|
||||
}
|
||||
}
|
||||
// ScenarioUse.bindings, Control.kind, Fragment.operator/branches and
|
||||
// Branch.guard/occurrences are required, including empty strings/lists.
|
||||
}
|
||||
|
||||
fn constructor_payload<'a>(
|
||||
fields: &'a mut Map<String, Value>,
|
||||
key: &str,
|
||||
tag: &str,
|
||||
) -> Option<&'a mut Map<String, Value>> {
|
||||
let wrapper = fields.get_mut(key)?.as_object_mut()?;
|
||||
if wrapper.len() != 1 {
|
||||
return None;
|
||||
}
|
||||
wrapper.get_mut(tag)?.as_object_mut()
|
||||
}
|
||||
|
||||
fn omit_nulls(fields: &mut Map<String, Value>, names: &[&str]) {
|
||||
for name in names {
|
||||
if fields.get(*name).is_some_and(Value::is_null) {
|
||||
fields.remove(*name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn omit_defaults(fields: &mut Map<String, Value>, defaults: &Map<String, Value>) {
|
||||
for (name, default) in defaults {
|
||||
if fields.get(name).is_some_and(|value| same(value, default)) {
|
||||
fields.remove(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Comparison recurses only to compare a known field with its exact declared
|
||||
// default. It never traverses arbitrary data looking for values to remove.
|
||||
fn same(value: &Value, default: &Value) -> bool {
|
||||
match (value, default) {
|
||||
(Value::Object(a), Value::Object(b)) => {
|
||||
a.len() == b.len()
|
||||
&& a.iter()
|
||||
.all(|(key, value)| b.get(key).is_some_and(|d| same(value, d)))
|
||||
}
|
||||
(Value::Array(a), Value::Array(b)) => {
|
||||
a.len() == b.len() && a.iter().zip(b).all(|(value, d)| same(value, d))
|
||||
}
|
||||
(Value::Number(a), Value::Number(b)) => {
|
||||
// serde_json numeric equality alone can equate -0.0 with +0.0.
|
||||
// Extracted f32 coordinates are represented exactly as f64 here.
|
||||
a == b
|
||||
&& match (a.as_f64(), b.as_f64()) {
|
||||
(Some(x), Some(y)) if x == 0.0 && y == 0.0 => x.to_bits() == y.to_bits(),
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
_ => value == default,
|
||||
}
|
||||
}
|
||||
|
||||
fn object(value: Value) -> Map<String, Value> {
|
||||
match value {
|
||||
Value::Object(fields) => fields,
|
||||
_ => unreachable!("literal source default is an object"),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "source_defaults_tests.rs"]
|
||||
mod tests;
|
||||
@@ -0,0 +1,718 @@
|
||||
//! Independent literal oracles for the production source-default policy.
|
||||
use super::{self as policy, Context, Mode};
|
||||
use crate::{Kind, RelationKind};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
#[test]
|
||||
fn complete_comparison_keeps_populated_serializer_skip_values() {
|
||||
for (context, input) in [
|
||||
(
|
||||
Context::Element(Kind::Occurrence),
|
||||
json!({"body":{"Exchange":{"operation":{"allocation":"allocation-id"},"values":[]}}}),
|
||||
),
|
||||
(
|
||||
Context::Node,
|
||||
json!({"port_anchors":[{"port":"port-id","side":"Left","offset":0.0}]}),
|
||||
),
|
||||
(
|
||||
Context::Trace,
|
||||
json!({"baseline":{"semantic":{"historical":"payload"}}}),
|
||||
),
|
||||
] {
|
||||
assert_eq!(rendered(context, &input, Mode::CompleteForEdit), input);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compact_value_fragments_keep_selected_constructor_requirements() {
|
||||
for (context, input, expected) in [
|
||||
(
|
||||
Context::Element(Kind::DataType),
|
||||
json!({"definition":{"String":{"minimum_length":0,"maximum_length":null}},"default":null,"unit":""}),
|
||||
json!({"definition":{"String":{"minimum_length":0}},"default":null,"unit":""}),
|
||||
),
|
||||
(
|
||||
Context::Element(Kind::Event),
|
||||
json!({"body":{"Signal":{"items":[]}}}),
|
||||
json!({"body":{"Signal":{"items":[]}}}),
|
||||
),
|
||||
(
|
||||
Context::Element(Kind::Occurrence),
|
||||
json!({"body":{"Exchange":{"operation":{"allocation":null},"values":[]}},"precondition":""}),
|
||||
json!({"body":{"Exchange":{"operation":{}}},"precondition":""}),
|
||||
),
|
||||
(
|
||||
Context::Element(Kind::Occurrence),
|
||||
json!({"body":{"ScenarioUse":{"scenario":null,"bindings":[]}}}),
|
||||
json!({"body":{"ScenarioUse":{"bindings":[]}}}),
|
||||
),
|
||||
] {
|
||||
assert_eq!(rendered(context, &input, Mode::CompactValues), expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn source_scenario_default_is_independent_of_graphical_creation() {
|
||||
use crate::{ElementBody, Layer, ScenarioViewpoint, SharedBody, language};
|
||||
let project = language::parse(
|
||||
"arcadia 7; project p \"P\" { oa_scenario o \"O\" {} sa_scenario s \"S\" {} }",
|
||||
)
|
||||
.unwrap();
|
||||
for element in project.elements.values() {
|
||||
assert!(matches!(
|
||||
element.body.shared(),
|
||||
Some(SharedBody::Scenario {
|
||||
viewpoint: ScenarioViewpoint::MixedLegacy,
|
||||
..
|
||||
})
|
||||
));
|
||||
assert!(!matches!(
|
||||
ElementBody::new(Kind::Scenario, element.layer())
|
||||
.unwrap()
|
||||
.shared(),
|
||||
Some(SharedBody::Scenario {
|
||||
viewpoint: ScenarioViewpoint::MixedLegacy,
|
||||
..
|
||||
})
|
||||
));
|
||||
}
|
||||
let source = language::format(&project);
|
||||
assert!(!source.contains("description"));
|
||||
assert!(!source.contains("parent"));
|
||||
assert!(!source.contains("viewpoint"));
|
||||
assert_eq!(language::parse(&source).unwrap(), project);
|
||||
|
||||
let mut typed = project;
|
||||
for element in typed.elements.values_mut() {
|
||||
let viewpoint = if element.layer() == Layer::Oa {
|
||||
ScenarioViewpoint::OperationalActivity
|
||||
} else {
|
||||
ScenarioViewpoint::Functional
|
||||
};
|
||||
*element.body.shared_mut().unwrap() = SharedBody::Scenario {
|
||||
viewpoint,
|
||||
context: None,
|
||||
precondition: String::new(),
|
||||
postcondition: String::new(),
|
||||
steps: vec![],
|
||||
};
|
||||
}
|
||||
let source = language::format(&typed);
|
||||
assert!(source.contains("viewpoint OperationalActivity;"));
|
||||
assert!(source.contains("viewpoint Functional;"));
|
||||
assert_eq!(language::parse(&source).unwrap(), typed);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shared_parser_defaults_preserve_required_fields_and_kind_checks() {
|
||||
for (declaration, message) in [
|
||||
(
|
||||
"oa_port p0 \"Port\" {}",
|
||||
"Missing required field 'contract'",
|
||||
),
|
||||
(
|
||||
"allocation r \"R\" { source @owner; }",
|
||||
"Missing required field 'target'",
|
||||
),
|
||||
(
|
||||
"functional_exchange r \"R\" { source @owner; target @work; }",
|
||||
"Missing required field 'source_port'",
|
||||
),
|
||||
(
|
||||
"contextual_link r \"R\" {}",
|
||||
"Missing required field 'owner'",
|
||||
),
|
||||
("node n { diagram @d; }", "Missing required field 'element'"),
|
||||
("artifact a \"A\" {}", "Missing required field 'owner'"),
|
||||
("trace t \"T\" {}", "Missing required field 'oa'"),
|
||||
(
|
||||
"oa_state s \"S\" { kind Initial; }",
|
||||
"Declaration kind disagrees",
|
||||
),
|
||||
(
|
||||
"oa_activity a \"A\" { unknown true; }",
|
||||
"Unknown field 'unknown'",
|
||||
),
|
||||
(
|
||||
"oa_data_type t \"T\" { definition { String {}; }; }",
|
||||
"minimum_length",
|
||||
),
|
||||
(
|
||||
"oa_occurrence o \"O\" { body { ScenarioUse {}; }; }",
|
||||
"bindings",
|
||||
),
|
||||
] {
|
||||
let source = format!(
|
||||
"arcadia 7; project p \"P\" {{ oa_entity owner \"Owner\" {{}} oa_activity work \"Work\" {{}} diagram d \"D\" {{}} {declaration} }}"
|
||||
);
|
||||
let errors = crate::language::parse(&source).unwrap_err();
|
||||
assert!(
|
||||
errors.iter().any(|error| error.message.contains(message)),
|
||||
"{declaration}: {errors:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn rendered(context: Context, input: &Value, mode: Mode) -> Value {
|
||||
Value::Object(policy::fields(context, input.as_object().unwrap(), mode))
|
||||
}
|
||||
|
||||
fn compact(context: Context, input: Value, expected: Value) {
|
||||
let original = input.clone();
|
||||
let result = rendered(context, &input, Mode::Compact);
|
||||
assert_eq!(result, expected, "context {context:?}");
|
||||
assert_eq!(input, original, "the input remains immutable");
|
||||
assert_eq!(
|
||||
rendered(context, &result, Mode::Compact),
|
||||
result,
|
||||
"compact policy is idempotent"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn complete_comparison_restores_only_the_three_known_skips() {
|
||||
let exchange = json!({"body":{"Exchange":{"exchange":null,"sender":null,"receiver":null,"message_kind":"Asynchronous","reply_to":null,"values":[]}}});
|
||||
let mut complete = exchange.clone();
|
||||
complete["body"]["Exchange"]["operation"] = Value::Null;
|
||||
assert_eq!(
|
||||
rendered(
|
||||
Context::Element(Kind::Occurrence),
|
||||
&exchange,
|
||||
Mode::CompleteForEdit
|
||||
),
|
||||
complete
|
||||
);
|
||||
assert_eq!(
|
||||
rendered(
|
||||
Context::Node,
|
||||
&json!({"element":"e","diagram":"d"}),
|
||||
Mode::CompleteForEdit
|
||||
),
|
||||
json!({"element":"e","diagram":"d","port_anchors":[]})
|
||||
);
|
||||
assert_eq!(
|
||||
rendered(
|
||||
Context::Trace,
|
||||
&json!({"baseline":{"oa":{"name":"","description":""},"sa":{"name":"","description":""}}}),
|
||||
Mode::CompleteForEdit
|
||||
),
|
||||
json!({"baseline":{"oa":{"name":"","description":""},"sa":{"name":"","description":""},"semantic":null}})
|
||||
);
|
||||
for input in [
|
||||
json!({"body":{"Action":{"action":null,"lifeline":null}}}),
|
||||
json!({"body":{"State":{"state":null,"lifeline":null}}}),
|
||||
] {
|
||||
assert_eq!(
|
||||
rendered(
|
||||
Context::Element(Kind::Occurrence),
|
||||
&input,
|
||||
Mode::CompleteForEdit
|
||||
),
|
||||
input
|
||||
);
|
||||
}
|
||||
for input in [
|
||||
json!({"baseline":null}),
|
||||
json!({"baseline":{"semantic":{"historical":[null,[],false,0,""]},"oa":{"name":"n","description":""},"sa":{"name":"s","description":""}}}),
|
||||
] {
|
||||
assert_eq!(
|
||||
rendered(Context::Trace, &input, Mode::CompleteForEdit),
|
||||
input
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_element_omits_only_empty_common_defaults() {
|
||||
for kind in Kind::ALL {
|
||||
// Future/unknown payloads are preservation sentinels, not admitted source.
|
||||
compact(
|
||||
Context::Element(kind),
|
||||
json!({"description":"","parent":null,"future":{"empty":[],"absent":null,"zero":0,"flag":false}}),
|
||||
json!({"future":{"empty":[],"absent":null,"zero":0,"flag":false}}),
|
||||
);
|
||||
compact(
|
||||
Context::Element(kind),
|
||||
json!({"description":" \n","parent":"owner"}),
|
||||
json!({"description":" \n","parent":"owner"}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ordinary_element_defaults_are_context_specific() {
|
||||
for kind in [Kind::Process, Kind::FunctionalChain] {
|
||||
compact(Context::Element(kind), json!({"steps":[]}), json!({}));
|
||||
compact(
|
||||
Context::Element(kind),
|
||||
json!({"steps":["second","first"]}),
|
||||
json!({"steps":["second","first"]}),
|
||||
);
|
||||
}
|
||||
compact(
|
||||
Context::Element(Kind::ExchangeItem),
|
||||
json!({"kind":"Information","mechanism":"Unspecified","supertype":null}),
|
||||
json!({}),
|
||||
);
|
||||
compact(
|
||||
Context::Element(Kind::ExchangeItem),
|
||||
json!({"kind":"Energy","mechanism":"Flow","supertype":"base"}),
|
||||
json!({"kind":"Energy","mechanism":"Flow","supertype":"base"}),
|
||||
);
|
||||
compact(
|
||||
Context::Element(Kind::ExchangeCategory),
|
||||
json!({"family":"Work","exchanges":[]}),
|
||||
json!({}),
|
||||
);
|
||||
compact(
|
||||
Context::Element(Kind::ExchangeCategory),
|
||||
json!({"family":"Participant","exchanges":["x"]}),
|
||||
json!({"family":"Participant","exchanges":["x"]}),
|
||||
);
|
||||
compact(
|
||||
Context::Element(Kind::Interface),
|
||||
json!({"supertype":null}),
|
||||
json!({}),
|
||||
);
|
||||
compact(
|
||||
Context::Element(Kind::Lifeline),
|
||||
json!({"represented":null}),
|
||||
json!({}),
|
||||
);
|
||||
compact(
|
||||
Context::Element(Kind::Constraint),
|
||||
json!({"expression":"","constrained":[]}),
|
||||
json!({}),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scenario_source_default_never_uses_the_graphical_viewpoint_default() {
|
||||
compact(
|
||||
Context::Element(Kind::Scenario),
|
||||
json!({"viewpoint":"MixedLegacy","context":null,"precondition":"","postcondition":"","steps":[]}),
|
||||
json!({}),
|
||||
);
|
||||
for viewpoint in [
|
||||
"OperationalActivity",
|
||||
"Functional",
|
||||
"ParticipantInteraction",
|
||||
"BoundaryInterface",
|
||||
] {
|
||||
compact(
|
||||
Context::Element(Kind::Scenario),
|
||||
json!({"viewpoint":viewpoint,"context":"scope","precondition":"ready","postcondition":"","steps":["two","one"]}),
|
||||
json!({"viewpoint":viewpoint,"context":"scope","precondition":"ready","steps":["two","one"]}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn each_state_header_supplies_its_own_kind() {
|
||||
for (kind, name) in [
|
||||
(Kind::State, "State"),
|
||||
(Kind::Mode, "Mode"),
|
||||
(Kind::Initial, "Initial"),
|
||||
(Kind::Final, "Final"),
|
||||
(Kind::Choice, "Choice"),
|
||||
(Kind::Junction, "Junction"),
|
||||
(Kind::Fork, "Fork"),
|
||||
(Kind::Join, "Join"),
|
||||
(Kind::ShallowHistory, "ShallowHistory"),
|
||||
(Kind::DeepHistory, "DeepHistory"),
|
||||
(Kind::EntryPoint, "EntryPoint"),
|
||||
(Kind::ExitPoint, "ExitPoint"),
|
||||
(Kind::Terminate, "Terminate"),
|
||||
] {
|
||||
compact(
|
||||
Context::Element(kind),
|
||||
json!({"kind":name,"entry":"","exit":"","do_activity":""}),
|
||||
json!({}),
|
||||
);
|
||||
}
|
||||
// Invalid mismatches must not be silently normalized by the writer policy.
|
||||
compact(
|
||||
Context::Element(Kind::Mode),
|
||||
json!({"kind":"State","entry":"work"}),
|
||||
json!({"kind":"State","entry":"work"}),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn data_field_unbounded_and_present_empty_values_are_not_defaults() {
|
||||
compact(
|
||||
Context::Element(Kind::DataField),
|
||||
json!({"type_ref":"String","minimum":1,"maximum":1,"unit":"","direction":"Unspecified","storage":"Value","default":null}),
|
||||
json!({}),
|
||||
);
|
||||
compact(
|
||||
Context::Element(Kind::DataField),
|
||||
json!({"type_ref":{"Named":"record"},"minimum":0,"maximum":null,"unit":"m","direction":"Out","storage":"Reference","default":[]}),
|
||||
json!({"type_ref":{"Named":"record"},"minimum":0,"maximum":null,"unit":"m","direction":"Out","storage":"Reference","default":[]}),
|
||||
);
|
||||
for value in [
|
||||
json!({"Boolean":false}),
|
||||
json!({"Integer":0}),
|
||||
json!({"Real":0.0}),
|
||||
json!({"String":""}),
|
||||
] {
|
||||
compact(
|
||||
Context::Element(Kind::DataField),
|
||||
json!({"default":[value.clone()]}),
|
||||
json!({"default":[value]}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn data_definition_whole_default_and_selected_required_fields_differ() {
|
||||
compact(
|
||||
Context::Element(Kind::DataType),
|
||||
json!({"definition":{"String":{"minimum_length":0,"maximum_length":null}},"default":null,"unit":""}),
|
||||
json!({}),
|
||||
);
|
||||
for (input, expected) in [
|
||||
(
|
||||
json!({"Integer":{"minimum":null,"maximum":null}}),
|
||||
json!({"Integer":{}}),
|
||||
),
|
||||
(
|
||||
json!({"Real":{"minimum":null,"maximum":2.5}}),
|
||||
json!({"Real":{"maximum":2.5}}),
|
||||
),
|
||||
(
|
||||
json!({"String":{"minimum_length":4,"maximum_length":null}}),
|
||||
json!({"String":{"minimum_length":4}}),
|
||||
),
|
||||
(json!({"Record":{"supertype":null}}), json!({"Record":{}})),
|
||||
(
|
||||
json!({"Enumeration":{"literals":[]}}),
|
||||
json!({"Enumeration":{"literals":[]}}),
|
||||
),
|
||||
] {
|
||||
compact(
|
||||
Context::Element(Kind::DataType),
|
||||
json!({"definition":input}),
|
||||
json!({"definition":expected}),
|
||||
);
|
||||
}
|
||||
compact(
|
||||
Context::Element(Kind::DataType),
|
||||
json!({"definition":"Boolean","default":{"Boolean":false}}),
|
||||
json!({"definition":"Boolean","default":{"Boolean":false}}),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn port_contract_and_its_required_payload_stay_explicit() {
|
||||
compact(
|
||||
Context::Element(Kind::Port),
|
||||
json!({"contract":"Legacy","legacy":{"direction":"Out","interface":null}}),
|
||||
json!({"contract":"Legacy","legacy":{"direction":"Out"}}),
|
||||
);
|
||||
for contract in [
|
||||
json!({"FunctionInput":{"incoming_items":[]}}),
|
||||
json!({"FunctionOutput":{"outgoing_items":[]}}),
|
||||
json!({"Component":{"kind":"Standard","orientation":"Unset"}}),
|
||||
] {
|
||||
compact(
|
||||
Context::Element(Kind::Port),
|
||||
json!({"contract":contract.clone(),"legacy":null}),
|
||||
json!({"contract":contract}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn occurrence_whole_default_is_distinct_from_selected_constructor_payload() {
|
||||
compact(
|
||||
Context::Element(Kind::Occurrence),
|
||||
json!({"body":{"Exchange":{"exchange":null,"sender":null,"receiver":null,"message_kind":"Asynchronous","reply_to":null,"values":[]}},"precondition":"","postcondition":""}),
|
||||
json!({}),
|
||||
);
|
||||
for (input, expected) in [
|
||||
(
|
||||
json!({"Action":{"action":null,"lifeline":null}}),
|
||||
json!({"Action":{}}),
|
||||
),
|
||||
(
|
||||
json!({"State":{"state":null,"lifeline":null}}),
|
||||
json!({"State":{}}),
|
||||
),
|
||||
(
|
||||
json!({"SequenceReference":{"sequence":null}}),
|
||||
json!({"SequenceReference":{}}),
|
||||
),
|
||||
(
|
||||
json!({"ScenarioUse":{"scenario":null,"bindings":[]}}),
|
||||
json!({"ScenarioUse":{"bindings":[]}}),
|
||||
),
|
||||
(
|
||||
json!({"Branch":{"guard":"","occurrences":[]}}),
|
||||
json!({"Branch":{"guard":"","occurrences":[]}}),
|
||||
),
|
||||
(
|
||||
json!({"Fragment":{"operator":"Parallel","branches":[]}}),
|
||||
json!({"Fragment":{"operator":"Parallel","branches":[]}}),
|
||||
),
|
||||
(
|
||||
json!({"Control":{"kind":"Choice"}}),
|
||||
json!({"Control":{"kind":"Choice"}}),
|
||||
),
|
||||
] {
|
||||
compact(
|
||||
Context::Element(Kind::Occurrence),
|
||||
json!({"body":input}),
|
||||
json!({"body":expected}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unresolved_operation_and_required_message_value_are_preserved() {
|
||||
compact(
|
||||
Context::Element(Kind::Occurrence),
|
||||
json!({"body":{"Exchange":{"exchange":null,"sender":null,"receiver":null,"message_kind":"Asynchronous","reply_to":null,"values":[{"field":"f","path":[],"expression":""}],"operation":{"allocation":null}}}}),
|
||||
json!({"body":{"Exchange":{"values":[{"field":"f","expression":""}],"operation":{}}}}),
|
||||
);
|
||||
compact(
|
||||
Context::Element(Kind::Occurrence),
|
||||
json!({"body":{"Exchange":{"exchange":"flow","sender":"a","receiver":"b","message_kind":{"Timer":{"expression":""}},"reply_to":"request","values":[],"operation":null}}}),
|
||||
json!({"body":{"Exchange":{"exchange":"flow","sender":"a","receiver":"b","message_kind":{"Timer":{"expression":""}},"reply_to":"request"}}}),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn event_body_whole_default_does_not_prune_selected_required_fields() {
|
||||
compact(
|
||||
Context::Element(Kind::Event),
|
||||
json!({"body":{"Signal":{"items":[]}}}),
|
||||
json!({}),
|
||||
);
|
||||
for body in [
|
||||
json!({"Signal":{"items":["i"]}}),
|
||||
json!({"Time":{"kind":"After","expression":""}}),
|
||||
json!({"Change":{"expression":""}}),
|
||||
] {
|
||||
compact(
|
||||
Context::Element(Kind::Event),
|
||||
json!({"body":body.clone()}),
|
||||
json!({"body":body}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn relation_required_endpoints_and_contextual_payloads_remain() {
|
||||
for kind in RelationKind::ALL {
|
||||
compact(
|
||||
Context::Relation(kind),
|
||||
json!({"description":"","source":"s","target":"t","future":[]}),
|
||||
json!({"source":"s","target":"t","future":[]}),
|
||||
);
|
||||
}
|
||||
compact(
|
||||
Context::Relation(RelationKind::FunctionalExchange),
|
||||
json!({"source":"s","target":"t","source_port":"sp","target_port":"tp","items":[]}),
|
||||
json!({"source":"s","target":"t","source_port":"sp","target_port":"tp"}),
|
||||
);
|
||||
let contextual = json!({"owner":"o","source":{"references":[],"occurrence":"s"},"target":{"references":[],"occurrence":"t"},"purpose":{"Precedence":{"guard":""}}});
|
||||
compact(
|
||||
Context::Relation(RelationKind::ContextualLink),
|
||||
contextual.clone(),
|
||||
contextual,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn relation_defaults_preserve_contextual_orientation_and_multiplicity() {
|
||||
for (kind, orientation) in [
|
||||
(RelationKind::BoundaryExchange, true),
|
||||
(RelationKind::CommunicationMean, false),
|
||||
] {
|
||||
compact(
|
||||
Context::Relation(kind),
|
||||
json!({"oriented":orientation,"items":[]}),
|
||||
json!({}),
|
||||
);
|
||||
compact(
|
||||
Context::Relation(kind),
|
||||
json!({"oriented":!orientation}),
|
||||
json!({"oriented":!orientation}),
|
||||
);
|
||||
}
|
||||
compact(
|
||||
Context::Relation(RelationKind::DataAssociation),
|
||||
json!({"source_role":"","target_role":"","source_minimum":0,"target_minimum":0,"source_maximum":null,"target_maximum":null,"source_navigable":false,"target_navigable":false}),
|
||||
json!({}),
|
||||
);
|
||||
compact(
|
||||
Context::Relation(RelationKind::DataAssociation),
|
||||
json!({"source_maximum":0,"target_maximum":1,"source_navigable":true}),
|
||||
json!({"source_maximum":0,"target_maximum":1,"source_navigable":true}),
|
||||
);
|
||||
compact(
|
||||
Context::Relation(RelationKind::InterfaceItemAllocation),
|
||||
json!({"order":0,"transmission":"Unspecified","acquisition":"Unspecified"}),
|
||||
json!({}),
|
||||
);
|
||||
compact(
|
||||
Context::Relation(RelationKind::CapabilityExtend),
|
||||
json!({"condition":""}),
|
||||
json!({}),
|
||||
);
|
||||
compact(
|
||||
Context::Relation(RelationKind::SequenceLink),
|
||||
json!({"guard":""}),
|
||||
json!({}),
|
||||
);
|
||||
compact(
|
||||
Context::Relation(RelationKind::StateAction),
|
||||
json!({"phase":"Do"}),
|
||||
json!({}),
|
||||
);
|
||||
compact(
|
||||
Context::Relation(RelationKind::StateTransition),
|
||||
json!({"transition_kind":"External","trigger":"","guard":"","effect":"","triggers":[],"effects":[]}),
|
||||
json!({}),
|
||||
);
|
||||
compact(
|
||||
Context::Relation(RelationKind::StateTransition),
|
||||
json!({"transition_kind":"Internal","triggers":["t"],"effects":["e"]}),
|
||||
json!({"transition_kind":"Internal","triggers":["t"],"effects":["e"]}),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn diagram_options_remove_only_unrestricted_defaults() {
|
||||
let defaults = json!({"hidden_edges":[],"relation_kinds":"All","work_categories":"All","participant_categories":"All","coverage":"All","work_contexts":"All","exchange_labels":"Name"});
|
||||
compact(
|
||||
Context::Diagram,
|
||||
json!({"description":"","layer":"Oa","projection":"Overview","routes":[],"view_options":defaults}),
|
||||
json!({}),
|
||||
);
|
||||
compact(
|
||||
Context::Diagram,
|
||||
json!({"layer":"Sa","projection":{"StateMachine":{"machine":"m"}},"view_options":{"hidden_edges":[],"relation_kinds":{"Only":[]},"work_categories":{"Any":[]},"participant_categories":"All","coverage":"All","work_contexts":{"Any":[]},"exchange_labels":"Name"}}),
|
||||
json!({"layer":"Sa","projection":{"StateMachine":{"machine":"m"}},"view_options":{"relation_kinds":{"Only":[]},"work_categories":{"Any":[]},"work_contexts":{"Any":[]}}}),
|
||||
);
|
||||
compact(
|
||||
Context::Diagram,
|
||||
json!({"routes":[{"edge":"e","waypoints":[],"label":null}]}),
|
||||
json!({"routes":[{"edge":"e"}]}),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn node_whole_defaults_preserve_negative_zero_and_required_coordinates() {
|
||||
compact(
|
||||
Context::Node,
|
||||
json!({"diagram":"d","element":"e","position":{"x":0.0,"y":0.0},"size":{"width":224.0,"height":94.0},"collapsed":false}),
|
||||
json!({"diagram":"d","element":"e"}),
|
||||
);
|
||||
for position in [
|
||||
json!({"x":-0.0,"y":0.0}),
|
||||
json!({"x":0.0,"y":-0.0}),
|
||||
json!({"x":1.0,"y":0.0}),
|
||||
] {
|
||||
let result = rendered(
|
||||
Context::Node,
|
||||
&json!({"position":position.clone()}),
|
||||
Mode::Compact,
|
||||
);
|
||||
assert_eq!(result, json!({"position":position.clone()}));
|
||||
for coordinate in ["x", "y"] {
|
||||
assert_eq!(
|
||||
result["position"][coordinate].as_f64().unwrap().to_bits(),
|
||||
position[coordinate].as_f64().unwrap().to_bits(),
|
||||
"coordinate sign is part of fidelity"
|
||||
);
|
||||
}
|
||||
}
|
||||
compact(
|
||||
Context::Node,
|
||||
json!({"size":{"width":300.0,"height":94.0},"port_anchors":[{"port":"p","side":"Left","offset":0.0}]}),
|
||||
json!({"size":{"width":300.0,"height":94.0},"port_anchors":[{"port":"p","side":"Left","offset":0.0}]}),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn artifact_present_empty_strings_and_trace_history_stay_distinct() {
|
||||
compact(
|
||||
Context::Artifact,
|
||||
json!({"owner":"o","description":"","relation":"References","uri":"","revision":null,"fragment":null}),
|
||||
json!({"owner":"o"}),
|
||||
);
|
||||
compact(
|
||||
Context::Artifact,
|
||||
json!({"owner":"o","relation":"Implements","revision":"","fragment":""}),
|
||||
json!({"owner":"o","relation":"Implements","revision":"","fragment":""}),
|
||||
);
|
||||
compact(
|
||||
Context::Trace,
|
||||
json!({"oa":"o","sa":"s","description":"","kind":"Refinement","baseline":null}),
|
||||
json!({"oa":"o","sa":"s"}),
|
||||
);
|
||||
compact(
|
||||
Context::Trace,
|
||||
json!({"baseline":{"oa":{"name":"","description":""},"sa":{"name":"s","description":""}}}),
|
||||
json!({"baseline":{"oa":{"name":"","description":""},"sa":{"name":"s","description":""}}}),
|
||||
);
|
||||
let baseline = json!({"oa":{"name":"o","description":""},"sa":{"name":"s","description":""},"semantic":{"facets":[{"Value":null},{"Value":[]},{"Value":false},{"Value":0},{"Value":""}]}});
|
||||
compact(
|
||||
Context::Trace,
|
||||
json!({"kind":"Manual","baseline":baseline.clone()}),
|
||||
json!({"kind":"Manual","baseline":baseline}),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nested_future_fields_prevent_whole_default_removal() {
|
||||
// These sentinels exercise preservation, not current parser admission of
|
||||
// unknown fields. Only known slots may lose their redundant defaults.
|
||||
compact(
|
||||
Context::Element(Kind::DataType),
|
||||
json!({"definition":{"String":{"minimum_length":0,"maximum_length":null,"future":[]}}}),
|
||||
json!({"definition":{"String":{"minimum_length":0,"future":[]}}}),
|
||||
);
|
||||
compact(
|
||||
Context::Element(Kind::Occurrence),
|
||||
json!({"body":{"Exchange":{"exchange":null,"sender":null,"receiver":null,"message_kind":"Asynchronous","reply_to":null,"values":[],"operation":null,"future":false}}}),
|
||||
json!({"body":{"Exchange":{"future":false}}}),
|
||||
);
|
||||
compact(
|
||||
Context::Diagram,
|
||||
json!({"view_options":{"hidden_edges":[],"relation_kinds":"All","work_categories":"All","participant_categories":"All","coverage":"All","work_contexts":"All","exchange_labels":"Name","future":null}}),
|
||||
json!({"view_options":{"future":null}}),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_and_multikey_constructor_wrappers_are_not_reinterpreted() {
|
||||
for definition in [
|
||||
json!({"Future":{"minimum":null,"maximum":null}}),
|
||||
json!({"String":{"minimum_length":0,"maximum_length":null},"Future":{}}),
|
||||
] {
|
||||
compact(
|
||||
Context::Element(Kind::DataType),
|
||||
json!({"definition":definition.clone()}),
|
||||
json!({"definition":definition}),
|
||||
);
|
||||
}
|
||||
for body in [
|
||||
json!({"Future":{"operation":null,"values":[]}}),
|
||||
json!({"Exchange":{"exchange":null,"values":[]},"Future":{}}),
|
||||
] {
|
||||
let fields = json!({"body":body});
|
||||
assert_eq!(
|
||||
rendered(
|
||||
Context::Element(Kind::Occurrence),
|
||||
&fields,
|
||||
Mode::CompleteForEdit
|
||||
),
|
||||
fields,
|
||||
"do not invent a selected Exchange constructor in an unknown wrapper",
|
||||
);
|
||||
compact(Context::Element(Kind::Occurrence), fields.clone(), fields);
|
||||
}
|
||||
}
|
||||
@@ -726,7 +726,8 @@ fn apply_edits(bundle: &mut SourceBundle, edits: Edits) -> Result<(), Vec<Source
|
||||
pub fn format_bundle(project: &Project) -> SourceBundle {
|
||||
let ownership = default_ownership(project);
|
||||
let aliases: BTreeMap<_, _> = project.identities().into_iter().collect();
|
||||
let mut declarations = language::format_declarations(project);
|
||||
let mut declarations =
|
||||
language::format_declarations(project, language::DeclarationFormat::Compact);
|
||||
declarations.sort_by_key(|(id, _)| declaration_order(project, *id, &aliases));
|
||||
let mut files: BTreeMap<LogicalPath, String> = BTreeMap::new();
|
||||
for (id, declaration) in declarations {
|
||||
@@ -735,11 +736,13 @@ pub fn format_bundle(project: &Project) -> SourceBundle {
|
||||
.or_default()
|
||||
.push_str(&unindent(&declaration));
|
||||
}
|
||||
let mut entry = format!(
|
||||
"arcadia {SCHEMA_VERSION};\n{}{{\n description {};\n",
|
||||
project_header(project),
|
||||
quote(&project.description)
|
||||
);
|
||||
let mut entry = format!("arcadia {SCHEMA_VERSION};\n{}{{\n", project_header(project));
|
||||
if !project.description.is_empty() {
|
||||
entry.push_str(&format!(
|
||||
" description {};\n",
|
||||
quote(&project.description)
|
||||
));
|
||||
}
|
||||
for path in files.keys() {
|
||||
entry.push_str(&format!(" include {};\n", quote(path)));
|
||||
}
|
||||
@@ -850,8 +853,25 @@ pub fn update_bundle_with_identity_map(
|
||||
)]);
|
||||
}
|
||||
let origins: BTreeMap<_, _> = identities.iter().map(|(old, new)| (*new, *old)).collect();
|
||||
let before: BTreeMap<_, _> = language::format_declarations(old).into_iter().collect();
|
||||
let after: BTreeMap<_, _> = language::format_declarations(project).into_iter().collect();
|
||||
// Comparison must include defaults even when persistence serialization or
|
||||
// compact output omits them. Otherwise an unrelated payload edit erases
|
||||
// unchanged explicit fields from the authored document.
|
||||
let before: BTreeMap<_, _> =
|
||||
language::format_declarations(old, language::DeclarationFormat::CompleteForEdit)
|
||||
.into_iter()
|
||||
.collect();
|
||||
let after: BTreeMap<_, _> =
|
||||
language::format_declarations(project, language::DeclarationFormat::CompleteForEdit)
|
||||
.into_iter()
|
||||
.collect();
|
||||
let compact: BTreeMap<_, _> =
|
||||
language::format_declarations(project, language::DeclarationFormat::Compact)
|
||||
.into_iter()
|
||||
.collect();
|
||||
let compact_values: BTreeMap<_, _> =
|
||||
language::format_declarations(project, language::DeclarationFormat::CompactValues)
|
||||
.into_iter()
|
||||
.collect();
|
||||
let old_aliases: BTreeMap<_, _> = old
|
||||
.identities()
|
||||
.into_iter()
|
||||
@@ -907,6 +927,27 @@ pub fn update_bundle_with_identity_map(
|
||||
};
|
||||
let mut previous = parse(old_text)?;
|
||||
let mut next = parse(new_text)?;
|
||||
let next_id = identities[&id];
|
||||
let value_text = &compact_values[&next_id];
|
||||
let insertion = InsertionSyntax::new(
|
||||
&next.fields,
|
||||
&parse(value_text)?.fields,
|
||||
value_text,
|
||||
&parse(&compact[&next_id])?.fields,
|
||||
);
|
||||
let old_kind = previous.header["kind"];
|
||||
let new_kind = next.header["kind"];
|
||||
if old_text[old_kind.start..old_kind.end] != new_text[new_kind.start..new_kind.end]
|
||||
&& let language::EditKind::Record(actual_fields) = &actual.fields.kind
|
||||
&& let language::EditKind::Record(previous_fields) = &mut previous.fields.kind
|
||||
{
|
||||
// An implicit value is supplied by its declaration context.
|
||||
// After a kind change, an unchanged value may need explicit
|
||||
// syntax (e.g. BoundaryExchange true -> CommunicationMean true).
|
||||
// Reconsider only absent fields; authored explicit values still
|
||||
// compare against their complete old values and keep trivia.
|
||||
previous_fields.retain(|key, _| actual_fields.contains_key(key));
|
||||
}
|
||||
if actual.lexical_owner.is_some()
|
||||
&& let language::EditKind::Record(fields) = &actual.fields.kind
|
||||
&& !fields.contains_key("parent")
|
||||
@@ -923,6 +964,7 @@ pub fn update_bundle_with_identity_map(
|
||||
source,
|
||||
before: old_text,
|
||||
after: new_text,
|
||||
insertion: Some(&insertion),
|
||||
old_aliases: &old_aliases,
|
||||
new_aliases: &new_aliases,
|
||||
legacy_value_paths: false,
|
||||
@@ -953,6 +995,7 @@ pub fn update_bundle_with_identity_map(
|
||||
source,
|
||||
before: &before,
|
||||
after: &after,
|
||||
insertion: None,
|
||||
old_aliases: &old_aliases,
|
||||
new_aliases: &new_aliases,
|
||||
legacy_value_paths: false,
|
||||
@@ -1011,7 +1054,7 @@ pub fn update_bundle_with_identity_map(
|
||||
project,
|
||||
identities,
|
||||
&original_order,
|
||||
&after,
|
||||
&compact,
|
||||
limits,
|
||||
)?;
|
||||
let result = compile_bundle(&bundle, limits)?;
|
||||
@@ -1119,10 +1162,73 @@ fn inserted_value(text: &str, indent: &str, source: &str) -> String {
|
||||
output
|
||||
}
|
||||
|
||||
// Value fragments retain required payload fields even when the enclosing
|
||||
// declaration field is itself omittable. For example, a selected String type
|
||||
// needs minimum_length; an Event Signal needs items. The complete tree remains
|
||||
// the comparison authority; this parallel tree is only an insertion template.
|
||||
struct InsertionSyntax<'a> {
|
||||
source: &'a str,
|
||||
values: BTreeMap<usize, Span>,
|
||||
omitted_fields: BTreeSet<usize>,
|
||||
}
|
||||
impl<'a> InsertionSyntax<'a> {
|
||||
fn new(
|
||||
complete: &language::EditValue,
|
||||
compact_values: &language::EditValue,
|
||||
source: &'a str,
|
||||
compact: &language::EditValue,
|
||||
) -> Self {
|
||||
let mut result = Self {
|
||||
source,
|
||||
values: BTreeMap::new(),
|
||||
omitted_fields: BTreeSet::new(),
|
||||
};
|
||||
result.collect(complete, compact_values);
|
||||
if let (language::EditKind::Record(all), language::EditKind::Record(kept)) =
|
||||
(&complete.kind, &compact.kind)
|
||||
{
|
||||
for (key, field) in all {
|
||||
if !kept.contains_key(key) {
|
||||
result.omitted_fields.insert(field.value.span.start);
|
||||
}
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
fn collect(&mut self, complete: &language::EditValue, compact: &language::EditValue) {
|
||||
// Borrow the existing compact text once. Copying each containing record
|
||||
// here would duplicate a large nested payload at every depth.
|
||||
self.values.insert(complete.span.start, compact.span);
|
||||
match (&complete.kind, &compact.kind) {
|
||||
(language::EditKind::Record(all), language::EditKind::Record(kept)) => {
|
||||
for (key, field) in all {
|
||||
if let Some(next) = kept.get(key) {
|
||||
self.collect(&field.value, &next.value);
|
||||
} else {
|
||||
self.omitted_fields.insert(field.value.span.start);
|
||||
}
|
||||
}
|
||||
}
|
||||
(language::EditKind::List(all), language::EditKind::List(kept)) => {
|
||||
assert_eq!(
|
||||
all.len(),
|
||||
kept.len(),
|
||||
"compaction preserves array membership"
|
||||
);
|
||||
for (field, next) in all.iter().zip(kept) {
|
||||
self.collect(field, next);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct SyntaxUpdate<'a> {
|
||||
source: &'a str,
|
||||
before: &'a str,
|
||||
after: &'a str,
|
||||
insertion: Option<&'a InsertionSyntax<'a>>,
|
||||
old_aliases: &'a BTreeMap<String, String>,
|
||||
new_aliases: &'a BTreeMap<String, String>,
|
||||
// Source3 migration only adds path qualification; the existing field identity
|
||||
@@ -1131,6 +1237,16 @@ struct SyntaxUpdate<'a> {
|
||||
identity_origins: Option<&'a BTreeMap<Id, Id>>,
|
||||
}
|
||||
impl SyntaxUpdate<'_> {
|
||||
fn inserted(&self, value: &language::EditValue) -> &str {
|
||||
self.insertion
|
||||
.and_then(|syntax| {
|
||||
syntax
|
||||
.values
|
||||
.get(&value.span.start)
|
||||
.map(|span| &syntax.source[span.start..span.end])
|
||||
})
|
||||
.unwrap_or(&self.after[value.span.start..value.span.end])
|
||||
}
|
||||
fn header(
|
||||
&self,
|
||||
actual: &BTreeMap<&str, Span>,
|
||||
@@ -1243,7 +1359,7 @@ impl SyntaxUpdate<'_> {
|
||||
_ => {
|
||||
erase_syntax(self.source, actual.span, edits);
|
||||
let text = inserted_value(
|
||||
&self.after[after.span.start..after.span.end],
|
||||
self.inserted(after),
|
||||
indent_at(self.source, actual.span.start),
|
||||
self.source,
|
||||
);
|
||||
@@ -1308,6 +1424,9 @@ impl SyntaxUpdate<'_> {
|
||||
.iter()
|
||||
.filter(|(key, field)| {
|
||||
!actual.contains_key(*key)
|
||||
&& self.insertion.is_none_or(|syntax| {
|
||||
!syntax.omitted_fields.contains(&field.value.span.start)
|
||||
})
|
||||
&& before
|
||||
.and_then(|fields| fields.get(*key))
|
||||
.is_none_or(|old| !self.same(&old.value, &field.value))
|
||||
@@ -1326,11 +1445,7 @@ impl SyntaxUpdate<'_> {
|
||||
.unwrap_or_else(|| format!("{} ", indent_at(self.source, span.start)));
|
||||
let mut text = String::new();
|
||||
for (key, field) in added {
|
||||
let value = inserted_value(
|
||||
&self.after[field.value.span.start..field.value.span.end],
|
||||
&indent,
|
||||
self.source,
|
||||
);
|
||||
let value = inserted_value(self.inserted(&field.value), &indent, self.source);
|
||||
if multiline {
|
||||
text.push_str(&indent);
|
||||
text.push_str(&format!("{key} {value};{}", newline(self.source)));
|
||||
@@ -1450,11 +1565,7 @@ impl SyntaxUpdate<'_> {
|
||||
} else {
|
||||
text.push(' ');
|
||||
}
|
||||
text.push_str(&inserted_value(
|
||||
&self.after[next.span.start..next.span.end],
|
||||
&indent,
|
||||
self.source,
|
||||
));
|
||||
text.push_str(&inserted_value(self.inserted(next), &indent, self.source));
|
||||
suffix = "";
|
||||
}
|
||||
if i + 1 < after.len() {
|
||||
|
||||
@@ -11,7 +11,10 @@ pub(super) fn upgrade(
|
||||
.as_ref()
|
||||
.expect("an explicit source migration report");
|
||||
let project = ¤t.decoded.project;
|
||||
let canonical: BTreeMap<_, _> = language::format_declarations(project).into_iter().collect();
|
||||
let canonical: BTreeMap<_, _> =
|
||||
language::format_declarations(project, language::DeclarationFormat::CompleteForEdit)
|
||||
.into_iter()
|
||||
.collect();
|
||||
let changed: BTreeSet<_> = report
|
||||
.semantic_defaults
|
||||
.iter()
|
||||
@@ -59,6 +62,7 @@ pub(super) fn upgrade(
|
||||
source,
|
||||
before: source,
|
||||
after,
|
||||
insertion: None,
|
||||
old_aliases: &aliases,
|
||||
new_aliases: &aliases,
|
||||
legacy_value_paths: true,
|
||||
|
||||
@@ -643,6 +643,20 @@ pub fn validate(p: &Project) -> Vec<Issue> {
|
||||
}
|
||||
let mut routed_edges = BTreeSet::new();
|
||||
for (index, route) in d.routes.iter().enumerate() {
|
||||
for attachment in [route.source_attachment, route.target_attachment]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
{
|
||||
if !attachment.offset.is_finite() || !(0.0..=1.0).contains(&attachment.offset) {
|
||||
error(
|
||||
&mut out,
|
||||
d.id,
|
||||
"invalid_attachment_offset",
|
||||
"routes",
|
||||
"Connection attachment offset must be finite and between zero and one.",
|
||||
);
|
||||
}
|
||||
}
|
||||
if !routed_edges.insert(route.edge) {
|
||||
error(
|
||||
&mut out,
|
||||
|
||||
@@ -0,0 +1,385 @@
|
||||
use oa_core::{projection::*, routing::*, *};
|
||||
|
||||
fn pos(x: f32, y: f32) -> Position {
|
||||
Position { x, y }
|
||||
}
|
||||
fn anchor(side: PortAnchorSide, offset: f32) -> EdgeAttachment {
|
||||
EdgeAttachment { side, offset }
|
||||
}
|
||||
fn fixture() -> (Project, Id, Id, Id, Id) {
|
||||
let mut p = Project::empty();
|
||||
let a = p
|
||||
.add_element(Kind::Activity, Layer::Oa, "Report", None)
|
||||
.unwrap();
|
||||
let b = p
|
||||
.add_element(Kind::Activity, Layer::Oa, "Receive", None)
|
||||
.unwrap();
|
||||
let edge = p.relate(RelationKind::Interaction, "Report status", a, b);
|
||||
let d = p.ensure_diagram(Layer::Oa);
|
||||
p.place(d, a, pos(50., 50.));
|
||||
p.place(d, b, pos(750., 200.));
|
||||
(p, d, a, b, edge)
|
||||
}
|
||||
fn stored(edge: Id) -> EdgeRoute {
|
||||
EdgeRoute {
|
||||
edge,
|
||||
source_attachment: None,
|
||||
target_attachment: None,
|
||||
waypoints: vec![],
|
||||
label: None,
|
||||
}
|
||||
}
|
||||
fn routed(p: &Project, d: Id) -> RoutedView {
|
||||
let diagram = &p.diagrams[&d];
|
||||
route_diagram(p, diagram, &project_diagram(p, diagram))
|
||||
}
|
||||
fn near(a: f32, b: f32) {
|
||||
assert!((a - b).abs() < 0.002, "{a} != {b}");
|
||||
}
|
||||
fn orthogonal(points: &[Position]) {
|
||||
assert!(points.len() >= 2);
|
||||
for span in points.windows(2) {
|
||||
assert!(span[0].x == span[1].x || span[0].y == span[1].y, "{span:?}");
|
||||
}
|
||||
}
|
||||
fn length(points: &[Position]) -> f32 {
|
||||
points
|
||||
.windows(2)
|
||||
.map(|p| (p[0].x - p[1].x).abs() + (p[0].y - p[1].y).abs())
|
||||
.sum()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn authored_boundary_follows_projected_owner_and_preview_matches_committed_geometry() {
|
||||
let (mut p, d, a, _, edge) = fixture();
|
||||
let initial = routed(&p, d);
|
||||
let mut route = stored(edge);
|
||||
route.source_attachment = Some(anchor(PortAnchorSide::Bottom, 0.25));
|
||||
route.target_attachment = Some(anchor(PortAnchorSide::Top, 0.75));
|
||||
route.waypoints = vec![pos(460., 350.)];
|
||||
p.diagrams.get_mut(&d).unwrap().routes.push(route.clone());
|
||||
let view = project_diagram(&p, &p.diagrams[&d]);
|
||||
let preview = route_edge_preview(&p, &p.diagrams[&d], &view, &initial, edge);
|
||||
let full = routed(&p, d);
|
||||
assert_eq!(
|
||||
preview, full,
|
||||
"attachment-only changes must invalidate the label-only path cache"
|
||||
);
|
||||
let n = view.nodes.iter().find(|n| n.element == a).unwrap();
|
||||
assert_eq!(
|
||||
full.edges[&edge].points[0],
|
||||
pos(
|
||||
n.position.x + n.size.width * 0.25,
|
||||
n.position.y + n.size.height
|
||||
)
|
||||
);
|
||||
assert_eq!(full.edges[&edge].pins, route.waypoints);
|
||||
orthogonal(&full.edges[&edge].points);
|
||||
let node = p
|
||||
.diagrams
|
||||
.get_mut(&d)
|
||||
.unwrap()
|
||||
.nodes
|
||||
.values_mut()
|
||||
.find(|n| n.element == a)
|
||||
.unwrap();
|
||||
node.position.x += 75.;
|
||||
node.size.width += 100.;
|
||||
node.size.height += 50.;
|
||||
let moved = routed(&p, d);
|
||||
near(
|
||||
moved.edges[&edge].points[0].x - full.edges[&edge].points[0].x,
|
||||
100.,
|
||||
);
|
||||
near(
|
||||
moved.edges[&edge].points[0].y - full.edges[&edge].points[0].y,
|
||||
50.,
|
||||
);
|
||||
assert_eq!(p.diagrams[&d].routes[0], route);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn attachment_only_preview_cannot_reuse_old_endpoints_with_unchanged_pins() {
|
||||
let (mut p, d, _, _, edge) = fixture();
|
||||
let baseline = routed(&p, d);
|
||||
let mut route = stored(edge);
|
||||
route.source_attachment = Some(anchor(PortAnchorSide::Top, 0.2));
|
||||
p.diagrams.get_mut(&d).unwrap().routes.push(route);
|
||||
let view = project_diagram(&p, &p.diagrams[&d]);
|
||||
let preview = route_edge_preview(&p, &p.diagrams[&d], &view, &baseline, edge);
|
||||
assert_ne!(preview.edges[&edge].points, baseline.edges[&edge].points);
|
||||
assert_eq!(preview, routed(&p, d));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ports_remain_authoritative_even_when_projection_filters_the_port() {
|
||||
let mut p = Project::empty();
|
||||
let a = p
|
||||
.add_element(Kind::Function, Layer::Sa, "Send", None)
|
||||
.unwrap();
|
||||
let b = p
|
||||
.add_element(Kind::Function, Layer::Sa, "Receive", None)
|
||||
.unwrap();
|
||||
let edge = p.relate(RelationKind::FunctionalExchange, "Data", a, b);
|
||||
let d = p.ensure_diagram(Layer::Sa);
|
||||
p.place(d, a, pos(0., 0.));
|
||||
p.place(d, b, pos(600., 0.));
|
||||
let diagram = p.diagrams[&d].clone();
|
||||
let view = project_diagram(&p, &diagram);
|
||||
let expected = route_diagram(&p, &diagram, &view);
|
||||
assert!(semantic_port_endpoint(&p, edge, EdgeEnd::Source).is_some());
|
||||
let mut route = stored(edge);
|
||||
route.source_attachment = Some(anchor(PortAnchorSide::Bottom, 0.1));
|
||||
route.target_attachment = Some(anchor(PortAnchorSide::Top, 0.9));
|
||||
p.diagrams.get_mut(&d).unwrap().routes.push(route);
|
||||
assert_eq!(routed(&p, d), expected);
|
||||
let mut hidden = view.clone();
|
||||
hidden.ports.clear();
|
||||
for e in &mut hidden.edges {
|
||||
e.source_port = None;
|
||||
e.target_port = None;
|
||||
}
|
||||
let absent = route_diagram(&p, &diagram, &hidden);
|
||||
assert_eq!(
|
||||
route_diagram(&p, &p.diagrams[&d], &hidden),
|
||||
absent,
|
||||
"hidden ports must not activate a dormant node preference"
|
||||
);
|
||||
}
|
||||
|
||||
fn state(kind: Kind) -> (Project, Id, Id, Id) {
|
||||
let mut p = Project::empty();
|
||||
let owner = p
|
||||
.add_element(Kind::Entity, Layer::Oa, "Crew", None)
|
||||
.unwrap();
|
||||
let machine = p
|
||||
.add_element(Kind::StateMachine, Layer::Oa, "Modes", Some(owner))
|
||||
.unwrap();
|
||||
let region = p
|
||||
.add_element(Kind::Region, Layer::Oa, "Main", Some(machine))
|
||||
.unwrap();
|
||||
let a = p.add_element(kind, Layer::Oa, "A", Some(region)).unwrap();
|
||||
let b = p
|
||||
.add_element(Kind::State, Layer::Oa, "B", Some(region))
|
||||
.unwrap();
|
||||
let edge = p.relate(RelationKind::StateTransition, "Next", a, b);
|
||||
let d = p.ensure_diagram(Layer::Oa);
|
||||
p.diagrams.get_mut(&d).unwrap().projection = ProjectionKind::StateMachine { machine };
|
||||
p.place(d, a, pos(100., 100.));
|
||||
p.place(d, b, pos(600., 100.));
|
||||
(p, d, a, edge)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nonrectangular_state_attachments_intersect_the_painted_shape() {
|
||||
for kind in [
|
||||
Kind::Initial,
|
||||
Kind::Junction,
|
||||
Kind::Final,
|
||||
Kind::Choice,
|
||||
Kind::ShallowHistory,
|
||||
Kind::DeepHistory,
|
||||
Kind::EntryPoint,
|
||||
Kind::ExitPoint,
|
||||
Kind::Terminate,
|
||||
Kind::Fork,
|
||||
Kind::Join,
|
||||
Kind::State,
|
||||
] {
|
||||
let (p, d, a, _) = state(kind);
|
||||
let diagram = &p.diagrams[&d];
|
||||
let view = project_diagram(&p, diagram);
|
||||
let n = view.nodes.iter().find(|n| n.element == a).unwrap();
|
||||
for side in [
|
||||
PortAnchorSide::Left,
|
||||
PortAnchorSide::Right,
|
||||
PortAnchorSide::Top,
|
||||
PortAnchorSide::Bottom,
|
||||
] {
|
||||
for offset in [0., 0.2, 0.5, 0.8, 1.] {
|
||||
let at = attachment_point(&p, diagram, n, &anchor(side, offset));
|
||||
let x = (at.x - n.position.x) / n.size.width;
|
||||
let y = (at.y - n.position.y) / n.size.height;
|
||||
match kind {
|
||||
Kind::Choice => near((2. * x - 1.).abs() + (2. * y - 1.).abs(), 1.),
|
||||
Kind::Terminate => near((x - y).abs().min((x + y - 1.).abs()), 0.),
|
||||
Kind::Fork | Kind::Join => near(x.min(1. - x).min(y.min(1. - y)), 0.),
|
||||
Kind::State => {
|
||||
assert!((0. ..=1.).contains(&x) && (0. ..=1.).contains(&y));
|
||||
if offset == 0. || offset == 1. {
|
||||
assert!(
|
||||
x != 0. && x != 1. || y != 0. && y != 1.,
|
||||
"rounded corner cannot use bounding-box corner"
|
||||
);
|
||||
}
|
||||
}
|
||||
_ => near((2. * x - 1.).powi(2) + (2. * y - 1.).powi(2), 1.),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inset_contour_leads_keep_pin_fractions_and_labels_on_the_complete_path() {
|
||||
let (mut p, d, _, edge) = state(Kind::Choice);
|
||||
let mut route = stored(edge);
|
||||
route.source_attachment = Some(anchor(PortAnchorSide::Right, 0.));
|
||||
route.waypoints = vec![pos(380., 40.)];
|
||||
route.label = Some(EdgeLabel {
|
||||
fraction: 0.3,
|
||||
offset: pos(0., 0.),
|
||||
});
|
||||
p.diagrams.get_mut(&d).unwrap().routes.push(route);
|
||||
let result = routed(&p, d);
|
||||
let r = &result.edges[&edge];
|
||||
orthogonal(&r.points);
|
||||
assert!(r.warnings.is_empty(), "{:?}", r.warnings);
|
||||
let pin = r.pins[0];
|
||||
let pin_index = r.points.iter().position(|p| *p == pin).unwrap();
|
||||
near(
|
||||
r.pin_fractions[0],
|
||||
length(&r.points[..=pin_index]) / length(&r.points),
|
||||
);
|
||||
assert_eq!(
|
||||
r.label.anchor,
|
||||
point_along_polyline(&r.points, 0.3).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn small_symbol_drag_chooses_the_intended_exit_side_at_low_zoom() {
|
||||
for kind in [
|
||||
Kind::Initial,
|
||||
Kind::Choice,
|
||||
Kind::Terminate,
|
||||
Kind::Fork,
|
||||
Kind::State,
|
||||
] {
|
||||
let (p, d, a, _) = state(kind);
|
||||
let view = project_diagram(&p, &p.diagrams[&d]);
|
||||
let n = view.nodes.iter().find(|n| n.element == a).unwrap();
|
||||
for zoom in [0.5, 1., 2.] {
|
||||
for overshoot in [0., 20.] {
|
||||
let cursor = pos(n.position.x + n.size.width / 2., n.position.y - overshoot);
|
||||
let chosen =
|
||||
attachment_from_point(n, cursor, Some(PortAnchorSide::Right), 6. / zoom);
|
||||
assert_eq!(
|
||||
chosen,
|
||||
anchor(PortAnchorSide::Top, 0.5),
|
||||
"{kind:?}, zoom {zoom}, overshoot {overshoot}"
|
||||
);
|
||||
let painted = attachment_point(&p, &p.diagrams[&d], n, &chosen);
|
||||
near(painted.x, n.position.x + n.size.width / 2.);
|
||||
near(
|
||||
painted.y,
|
||||
n.position.y
|
||||
+ if kind == Kind::Terminate {
|
||||
n.size.height / 2.
|
||||
} else {
|
||||
0.
|
||||
},
|
||||
);
|
||||
}
|
||||
let near_corner = pos(n.position.x + n.size.width - 1., n.position.y + 1.);
|
||||
let stable =
|
||||
attachment_from_point(n, near_corner, Some(PortAnchorSide::Right), 6. / zoom);
|
||||
assert_eq!(
|
||||
stable.side,
|
||||
PortAnchorSide::Right,
|
||||
"corner hysteresis stays stable"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn coincident_self_attachments_retain_hard_pins_and_form_a_visible_loop() {
|
||||
let (mut p, d, a, edge) = state(Kind::State);
|
||||
if let RelationBody::StateTransition { target, .. } =
|
||||
&mut p.relations.get_mut(&edge).unwrap().body
|
||||
{
|
||||
*target = a;
|
||||
}
|
||||
for pins in [vec![], vec![pos(400., 30.)]] {
|
||||
let mut route = stored(edge);
|
||||
route.source_attachment = Some(anchor(PortAnchorSide::Top, 0.5));
|
||||
route.target_attachment = route.source_attachment;
|
||||
route.waypoints = pins.clone();
|
||||
p.diagrams.get_mut(&d).unwrap().routes = vec![route.clone()];
|
||||
let result = routed(&p, d);
|
||||
let r = &result.edges[&edge];
|
||||
orthogonal(&r.points);
|
||||
assert_eq!(r.points.first(), r.points.last());
|
||||
assert!(length(&r.points) > 2. * PORT_STUB + 70.);
|
||||
assert_eq!(r.pins, pins);
|
||||
assert_eq!(r.pin_fractions.len(), pins.len());
|
||||
assert!(
|
||||
r.warnings.contains(&RouteWarning::CoincidentAttachments),
|
||||
"{:?}",
|
||||
r.warnings
|
||||
);
|
||||
assert_eq!(routed(&p, d), result, "deterministic fallback");
|
||||
assert_eq!(p.diagrams[&d].routes[0], route);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn coincident_loop_chooses_clear_side_instead_of_inventing_an_obstructed_pin() {
|
||||
for blocker_side in [-1., 1.] {
|
||||
let (mut p, d, a, edge) = state(Kind::State);
|
||||
if let RelationBody::StateTransition { target, .. } =
|
||||
&mut p.relations.get_mut(&edge).unwrap().body
|
||||
{
|
||||
*target = a;
|
||||
}
|
||||
let mut route = stored(edge);
|
||||
route.source_attachment = Some(anchor(PortAnchorSide::Top, 0.5));
|
||||
route.target_attachment = route.source_attachment;
|
||||
p.diagrams.get_mut(&d).unwrap().routes.push(route);
|
||||
let view = project_diagram(&p, &p.diagrams[&d]);
|
||||
let source = view.nodes.iter().find(|n| n.element == a).unwrap();
|
||||
let tip = attachment_point(
|
||||
&p,
|
||||
&p.diagrams[&d],
|
||||
source,
|
||||
&anchor(PortAnchorSide::Top, 0.5),
|
||||
);
|
||||
let region = p.elements[&a].parent;
|
||||
let blocker = p
|
||||
.add_element(Kind::State, Layer::Oa, "Detour obstruction", region)
|
||||
.unwrap();
|
||||
let left = if blocker_side > 0. {
|
||||
tip.x + 30.
|
||||
} else {
|
||||
tip.x - 30. - 224.
|
||||
};
|
||||
p.place(d, blocker, pos(left, tip.y - 144.));
|
||||
let result = routed(&p, d);
|
||||
let r = &result.edges[&edge];
|
||||
assert_eq!(r.warnings, vec![RouteWarning::CoincidentAttachments]);
|
||||
orthogonal(&r.points);
|
||||
let view = project_diagram(&p, &p.diagrams[&d]);
|
||||
let n = view.nodes.iter().find(|n| n.element == blocker).unwrap();
|
||||
for segment in r.points.windows(2) {
|
||||
for step in 0..=100 {
|
||||
let t = step as f32 / 100.;
|
||||
let q = pos(
|
||||
segment[0].x + (segment[1].x - segment[0].x) * t,
|
||||
segment[0].y + (segment[1].y - segment[0].y) * t,
|
||||
);
|
||||
assert!(
|
||||
!(q.x > n.position.x - CLEARANCE
|
||||
&& q.x < n.position.x + n.size.width + CLEARANCE
|
||||
&& q.y > n.position.y - CLEARANCE
|
||||
&& q.y < n.position.y + n.size.height + CLEARANCE),
|
||||
"route crosses blocker: {q:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
assert!(
|
||||
r.pins.is_empty(),
|
||||
"generated detours must never become authored pins"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,272 @@
|
||||
use oa_core::{language, projection::*, routing::*, *};
|
||||
|
||||
fn pos(x: f32, y: f32) -> Position {
|
||||
Position { x, y }
|
||||
}
|
||||
|
||||
fn id(project: &Project, alias: &str) -> Id {
|
||||
project
|
||||
.identities()
|
||||
.into_iter()
|
||||
.find(|(_, a)| *a == alias)
|
||||
.unwrap()
|
||||
.0
|
||||
}
|
||||
|
||||
fn authored(edge: Id) -> EdgeRoute {
|
||||
EdgeRoute {
|
||||
edge,
|
||||
source_attachment: Some(EdgeAttachment {
|
||||
side: PortAnchorSide::Bottom,
|
||||
offset: 0.2,
|
||||
}),
|
||||
target_attachment: Some(EdgeAttachment {
|
||||
side: PortAnchorSide::Top,
|
||||
offset: 0.8,
|
||||
}),
|
||||
waypoints: vec![pos(520., 420.)],
|
||||
label: Some(EdgeLabel {
|
||||
fraction: 0.35,
|
||||
offset: pos(17., -23.),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
fn routed(project: &Project, diagram: Id) -> RoutedView {
|
||||
let d = &project.diagrams[&diagram];
|
||||
route_diagram(project, d, &project_diagram(project, d))
|
||||
}
|
||||
|
||||
fn fixture() -> (Project, Id, Id, Id, Id, Id, Id) {
|
||||
let mut p = language::parse(
|
||||
r#"arcadia 7;
|
||||
project lifecycle "Attachment lifecycle" {
|
||||
oa_activity group "Group" { oa_activity first "First" {} }
|
||||
oa_activity second "Second" {}
|
||||
oa_activity replacement "Replacement" {}
|
||||
interaction signal "Signal" { source @first; target @second; }
|
||||
diagram view "View" {}
|
||||
diagram other "Other" {}
|
||||
}"#,
|
||||
)
|
||||
.unwrap();
|
||||
let (d, other, group, first, second, replacement, edge) = (
|
||||
id(&p, "view"),
|
||||
id(&p, "other"),
|
||||
id(&p, "group"),
|
||||
id(&p, "first"),
|
||||
id(&p, "second"),
|
||||
id(&p, "replacement"),
|
||||
id(&p, "signal"),
|
||||
);
|
||||
for diagram in [d, other] {
|
||||
p.place(diagram, group, pos(20., 20.));
|
||||
p.place(diagram, first, pos(100., 130.));
|
||||
p.place(diagram, second, pos(750., 150.));
|
||||
p.place(diagram, replacement, pos(750., 570.));
|
||||
p.diagrams
|
||||
.get_mut(&diagram)
|
||||
.unwrap()
|
||||
.routes
|
||||
.push(authored(edge));
|
||||
}
|
||||
(p, d, other, group, first, replacement, edge)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn attachment_fold_promotion_suspends_the_complete_route_and_expand_restores_it() {
|
||||
let (mut p, d, other, group, _, _, edge) = fixture();
|
||||
assert_eq!(semantic_port_endpoint(&p, edge, EdgeEnd::Source), None);
|
||||
assert_eq!(semantic_port_endpoint(&p, edge, EdgeEnd::Target), None);
|
||||
let before = p.clone();
|
||||
let expanded = routed(&p, d);
|
||||
let other_geometry = routed(&p, other);
|
||||
let parent = p.diagrams[&d]
|
||||
.nodes
|
||||
.values()
|
||||
.find(|n| n.element == group)
|
||||
.unwrap()
|
||||
.id;
|
||||
p.diagrams
|
||||
.get_mut(&d)
|
||||
.unwrap()
|
||||
.nodes
|
||||
.get_mut(&parent)
|
||||
.unwrap()
|
||||
.collapsed = true;
|
||||
let folded = routed(&p, d);
|
||||
assert!(folded.edges[&edge].custom_suspended);
|
||||
assert_eq!(folded.edges[&edge].pins, []);
|
||||
assert!(
|
||||
folded.edges[&edge]
|
||||
.warnings
|
||||
.contains(&RouteWarning::PromotedEndpoints)
|
||||
);
|
||||
assert_eq!(p.diagrams[&d].routes, before.diagrams[&d].routes);
|
||||
let mut automatic = p.clone();
|
||||
automatic.diagrams.get_mut(&d).unwrap().routes.clear();
|
||||
assert_eq!(
|
||||
folded,
|
||||
routed(&automatic, d),
|
||||
"attachments, pins and label must all be dormant on promotion"
|
||||
);
|
||||
assert_eq!(p.diagrams[&other], before.diagrams[&other]);
|
||||
assert_eq!(routed(&p, other), other_geometry);
|
||||
p.diagrams
|
||||
.get_mut(&d)
|
||||
.unwrap()
|
||||
.nodes
|
||||
.get_mut(&parent)
|
||||
.unwrap()
|
||||
.collapsed = false;
|
||||
assert_eq!(p, before);
|
||||
assert_eq!(routed(&p, d), expanded);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn attachment_reconnect_retains_slot_preferences_and_other_view_records_with_exact_history() {
|
||||
let (p, d, other, _, _, replacement, edge) = fixture();
|
||||
let before = routed(&p, d);
|
||||
let mut relation = p.relations[&edge].clone();
|
||||
let RelationBody::Interaction { target, .. } = &mut relation.body else {
|
||||
unreachable!()
|
||||
};
|
||||
*target = replacement;
|
||||
let mut expected = p.clone();
|
||||
expected.relations.insert(edge, relation.clone());
|
||||
let mut session = Session::new(p.clone());
|
||||
session
|
||||
.execute(Command::EditRelation(edge, relation))
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
session.project(),
|
||||
&expected,
|
||||
"reconnect changes only the semantic endpoint; all per-view records remain exact"
|
||||
);
|
||||
assert_eq!(session.project().diagrams[&other], p.diagrams[&other]);
|
||||
for diagram in [d, other] {
|
||||
let current = session.project();
|
||||
let view = project_diagram(current, ¤t.diagrams[&diagram]);
|
||||
let node = view
|
||||
.nodes
|
||||
.iter()
|
||||
.find(|n| n.element == replacement)
|
||||
.unwrap();
|
||||
let preference = current.diagrams[&diagram].routes[0]
|
||||
.target_attachment
|
||||
.unwrap();
|
||||
let expected_tip =
|
||||
attachment_point(current, ¤t.diagrams[&diagram], node, &preference);
|
||||
let result = routed(current, diagram);
|
||||
assert_eq!(result.edges[&edge].points.last(), Some(&expected_tip));
|
||||
assert_eq!(
|
||||
result.edges[&edge].pins,
|
||||
p.diagrams[&diagram].routes[0].waypoints
|
||||
);
|
||||
}
|
||||
assert_ne!(
|
||||
routed(session.project(), d).edges[&edge].points.last(),
|
||||
before.edges[&edge].points.last()
|
||||
);
|
||||
session.undo();
|
||||
assert_eq!(session.project(), &p);
|
||||
assert_eq!(routed(session.project(), d), before);
|
||||
session.redo();
|
||||
assert_eq!(session.project(), &expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn attachment_direct_port_endpoints_remain_authoritative_when_their_glyphs_are_filtered() {
|
||||
let mut p = Project::empty();
|
||||
let system = p
|
||||
.add_element(Kind::System, Layer::Sa, "System", None)
|
||||
.unwrap();
|
||||
let actor = p
|
||||
.add_element(Kind::SystemActor, Layer::Sa, "Actor", None)
|
||||
.unwrap();
|
||||
let function = p
|
||||
.add_element(Kind::Function, Layer::Sa, "Send", None)
|
||||
.unwrap();
|
||||
let mut ports = Vec::new();
|
||||
for (owner, name, contract) in [
|
||||
(
|
||||
system,
|
||||
"Output",
|
||||
PortContract::Component {
|
||||
kind: ComponentPortKind::Flow,
|
||||
orientation: ComponentPortOrientation::Out,
|
||||
},
|
||||
),
|
||||
(
|
||||
actor,
|
||||
"Input",
|
||||
PortContract::Component {
|
||||
kind: ComponentPortKind::Flow,
|
||||
orientation: ComponentPortOrientation::In,
|
||||
},
|
||||
),
|
||||
(
|
||||
function,
|
||||
"Function output",
|
||||
PortContract::FunctionOutput {
|
||||
outgoing_items: vec![],
|
||||
},
|
||||
),
|
||||
] {
|
||||
let port = Id::new_v4();
|
||||
p.elements
|
||||
.insert(port, make_port(&p, port, owner, name, contract).unwrap());
|
||||
ports.push(port);
|
||||
}
|
||||
p.relate(
|
||||
RelationKind::Allocation,
|
||||
"Function allocation",
|
||||
system,
|
||||
function,
|
||||
);
|
||||
let boundary = p.relate(
|
||||
RelationKind::BoundaryExchange,
|
||||
"Boundary",
|
||||
ports[0],
|
||||
ports[1],
|
||||
);
|
||||
let allocation = p.relate(
|
||||
RelationKind::PortAllocation,
|
||||
"Port allocation",
|
||||
ports[0],
|
||||
ports[2],
|
||||
);
|
||||
let d = p.ensure_diagram(Layer::Sa);
|
||||
p.place(d, system, pos(0., 0.));
|
||||
p.place(d, actor, pos(700., 0.));
|
||||
p.place(d, function, pos(0., 450.));
|
||||
let original = p.clone();
|
||||
let baseline = routed(&p, d);
|
||||
for (edge, target) in [(boundary, ports[1]), (allocation, ports[2])] {
|
||||
assert!(baseline.edges.contains_key(&edge));
|
||||
assert_eq!(
|
||||
semantic_port_endpoint(&p, edge, EdgeEnd::Source),
|
||||
Some(ports[0])
|
||||
);
|
||||
assert_eq!(
|
||||
semantic_port_endpoint(&p, edge, EdgeEnd::Target),
|
||||
Some(target)
|
||||
);
|
||||
let mut route = authored(edge);
|
||||
route.waypoints.clear();
|
||||
route.label = None;
|
||||
p.diagrams.get_mut(&d).unwrap().routes.push(route);
|
||||
}
|
||||
assert_eq!(routed(&p, d), baseline);
|
||||
let mut hidden = project_diagram(&p, &p.diagrams[&d]);
|
||||
hidden.ports.clear();
|
||||
for edge in &mut hidden.edges {
|
||||
edge.source_port = None;
|
||||
edge.target_port = None;
|
||||
}
|
||||
assert_eq!(
|
||||
route_diagram(&p, &p.diagrams[&d], &hidden),
|
||||
route_diagram(&original, &original.diagrams[&d], &hidden),
|
||||
"filtered direct Port endpoints must not activate their stored preferences"
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
use oa_core::{projection::*, routing::*, *};
|
||||
|
||||
#[test]
|
||||
fn valid_item_trace_follows_manual_port_anchors_and_ignores_dormant_attachments() {
|
||||
let mut project = Project::empty();
|
||||
let oa = project
|
||||
.add_element(Kind::Activity, Layer::Oa, "Send", None)
|
||||
.unwrap();
|
||||
let sa = project
|
||||
.add_element(Kind::Function, Layer::Sa, "Receive", None)
|
||||
.unwrap();
|
||||
let ports = [(oa, Layer::Oa), (sa, Layer::Sa)].map(|(owner, layer)| {
|
||||
let id = Id::new_v4();
|
||||
project.elements.insert(
|
||||
id,
|
||||
Element {
|
||||
id,
|
||||
alias: format!("port_{}", id.simple()),
|
||||
name: "Status port".into(),
|
||||
description: "Existing legacy port retained by Item trace".into(),
|
||||
parent: Some(owner),
|
||||
body: ElementBody::shared_in(
|
||||
layer,
|
||||
SharedBody::Port {
|
||||
contract: PortContract::Legacy,
|
||||
legacy: Some(LegacyPortContract {
|
||||
direction: PortDirection::InOut,
|
||||
interface: None,
|
||||
}),
|
||||
},
|
||||
),
|
||||
},
|
||||
);
|
||||
id
|
||||
});
|
||||
let trace = Trace {
|
||||
id: Id::new_v4(),
|
||||
alias: "status_correspondence".into(),
|
||||
name: "Status correspondence".into(),
|
||||
description: "Preserve this semantic evidence".into(),
|
||||
oa: ports[0],
|
||||
sa: ports[1],
|
||||
kind: TraceKind::Item,
|
||||
baseline: None,
|
||||
};
|
||||
project.traces.insert(trace.id, trace.clone());
|
||||
let diagram = project.ensure_diagram(Layer::Oa);
|
||||
project.diagrams.get_mut(&diagram).unwrap().projection = ProjectionKind::Traceability;
|
||||
let owners = [
|
||||
project.place(diagram, oa, Position { x: 100., y: 100. }),
|
||||
project.place(diagram, sa, Position { x: 800., y: 300. }),
|
||||
];
|
||||
validate_candidate(&project).unwrap();
|
||||
let semantic_elements = project.elements.clone();
|
||||
let semantic_relations = project.relations.clone();
|
||||
let semantic_traces = project.traces.clone();
|
||||
let view = project_diagram(&project, &project.diagrams[&diagram]);
|
||||
let edge = view.edges.iter().find(|edge| edge.id == trace.id).unwrap();
|
||||
assert!(edge.trace);
|
||||
assert_eq!((edge.source, edge.target), (owners[0], owners[1]));
|
||||
assert_eq!((edge.source_port, edge.target_port), (None, None));
|
||||
let initial = route_diagram(&project, &project.diagrams[&diagram], &view);
|
||||
for (index, (side, offset)) in [(PortAnchorSide::Top, 0.25), (PortAnchorSide::Bottom, 0.75)]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
{
|
||||
project
|
||||
.diagrams
|
||||
.get_mut(&diagram)
|
||||
.unwrap()
|
||||
.nodes
|
||||
.get_mut(&owners[index])
|
||||
.unwrap()
|
||||
.port_anchors
|
||||
.push(PortAnchor {
|
||||
port: ports[index],
|
||||
side,
|
||||
offset,
|
||||
});
|
||||
}
|
||||
validate_candidate(&project).unwrap();
|
||||
let moved_view = project_diagram(&project, &project.diagrams[&diagram]);
|
||||
let moved = route_diagram(&project, &project.diagrams[&diagram], &moved_view);
|
||||
for index in 0..2 {
|
||||
let marker = moved_view
|
||||
.ports
|
||||
.iter()
|
||||
.find(|port| port.element == ports[index] && port.owner == owners[index])
|
||||
.unwrap();
|
||||
let points = &moved.edges[&trace.id].points;
|
||||
let tip = if index == 0 {
|
||||
points[0]
|
||||
} else {
|
||||
*points.last().unwrap()
|
||||
};
|
||||
assert_eq!(tip, marker.position);
|
||||
let old = &initial.edges[&trace.id].points;
|
||||
assert_ne!(
|
||||
tip,
|
||||
if index == 0 {
|
||||
old[0]
|
||||
} else {
|
||||
*old.last().unwrap()
|
||||
}
|
||||
);
|
||||
}
|
||||
project
|
||||
.diagrams
|
||||
.get_mut(&diagram)
|
||||
.unwrap()
|
||||
.routes
|
||||
.push(EdgeRoute {
|
||||
edge: trace.id,
|
||||
waypoints: vec![],
|
||||
label: None,
|
||||
source_attachment: Some(EdgeAttachment {
|
||||
side: PortAnchorSide::Bottom,
|
||||
offset: 0.9,
|
||||
}),
|
||||
target_attachment: Some(EdgeAttachment {
|
||||
side: PortAnchorSide::Top,
|
||||
offset: 0.1,
|
||||
}),
|
||||
});
|
||||
validate_candidate(&project).unwrap();
|
||||
let dormant_view = project_diagram(&project, &project.diagrams[&diagram]);
|
||||
assert_eq!(dormant_view, moved_view);
|
||||
assert_eq!(
|
||||
route_diagram(&project, &project.diagrams[&diagram], &dormant_view),
|
||||
moved
|
||||
);
|
||||
assert_eq!(project.elements, semantic_elements);
|
||||
assert_eq!(project.relations, semantic_relations);
|
||||
assert_eq!(project.traces, semantic_traces);
|
||||
assert_eq!(project.traces[&trace.id], trace);
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
//! Route the exact native acceptance fixture and intended saved checkpoints.
|
||||
use oa_core::{projection::project_diagram, routing::route_diagram, *};
|
||||
|
||||
const FIXTURE: &str =
|
||||
include_str!("../../../harness/experiments/edge-attachments-20260922/native-fixture.arcadia");
|
||||
|
||||
fn id(project: &Project, alias: &str) -> Id {
|
||||
project
|
||||
.identities()
|
||||
.into_iter()
|
||||
.find(|(_, name)| *name == alias)
|
||||
.unwrap()
|
||||
.0
|
||||
}
|
||||
|
||||
fn set(
|
||||
project: &mut Project,
|
||||
view: &str,
|
||||
edge: &str,
|
||||
end: EdgeEnd,
|
||||
attachment: Option<(PortAnchorSide, f32)>,
|
||||
) {
|
||||
let view = id(project, view);
|
||||
let edge = id(project, edge);
|
||||
let route = project
|
||||
.diagrams
|
||||
.get_mut(&view)
|
||||
.unwrap()
|
||||
.routes
|
||||
.iter_mut()
|
||||
.find(|route| route.edge == edge)
|
||||
.unwrap();
|
||||
route.set_attachment(
|
||||
end,
|
||||
attachment.map(|(side, offset)| EdgeAttachment { side, offset }),
|
||||
);
|
||||
}
|
||||
|
||||
fn clear(project: &Project, checkpoint: &str) {
|
||||
validate_candidate(project).unwrap();
|
||||
for (view, edges) in [
|
||||
("dispatch_view", &["dispatch_request"][..]),
|
||||
("readiness_view", &["activate", "initialize", "finish"][..]),
|
||||
] {
|
||||
let diagram = &project.diagrams[&id(project, view)];
|
||||
let routed = route_diagram(project, diagram, &project_diagram(project, diagram));
|
||||
for alias in edges {
|
||||
let edge = &routed.edges[&id(project, alias)];
|
||||
assert!(
|
||||
edge.warnings.is_empty(),
|
||||
"{checkpoint}/{view}/{alias}: {:?}",
|
||||
edge.warnings
|
||||
);
|
||||
let stored = diagram
|
||||
.routes
|
||||
.iter()
|
||||
.find(|r| r.edge == id(project, alias))
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
edge.pins, stored.waypoints,
|
||||
"{checkpoint}/{alias}: manual pins retained"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn native_workshop_baseline_and_planned_attachments_have_clear_routes() {
|
||||
use EdgeEnd::{Source, Target};
|
||||
use PortAnchorSide::{Bottom, Top};
|
||||
let mut project = language::parse(FIXTURE).unwrap();
|
||||
let baseline = project.clone();
|
||||
clear(&project, "B");
|
||||
set(
|
||||
&mut project,
|
||||
"dispatch_view",
|
||||
"dispatch_request",
|
||||
Source,
|
||||
Some((Top, 0.25)),
|
||||
);
|
||||
clear(&project, "O1");
|
||||
set(
|
||||
&mut project,
|
||||
"dispatch_view",
|
||||
"dispatch_request",
|
||||
Target,
|
||||
Some((Bottom, 0.75)),
|
||||
);
|
||||
clear(&project, "O2");
|
||||
set(
|
||||
&mut project,
|
||||
"dispatch_view",
|
||||
"dispatch_request",
|
||||
Source,
|
||||
None,
|
||||
);
|
||||
clear(&project, "O3");
|
||||
set(
|
||||
&mut project,
|
||||
"readiness_view",
|
||||
"activate",
|
||||
Source,
|
||||
Some((Top, 0.25)),
|
||||
);
|
||||
clear(&project, "S1");
|
||||
set(
|
||||
&mut project,
|
||||
"readiness_view",
|
||||
"activate",
|
||||
Target,
|
||||
Some((Bottom, 0.75)),
|
||||
);
|
||||
clear(&project, "S2");
|
||||
set(&mut project, "readiness_view", "activate", Target, None);
|
||||
clear(&project, "S3");
|
||||
set(
|
||||
&mut project,
|
||||
"readiness_view",
|
||||
"initialize",
|
||||
Source,
|
||||
Some((Top, 0.5)),
|
||||
);
|
||||
clear(&project, "S4");
|
||||
set(
|
||||
&mut project,
|
||||
"readiness_view",
|
||||
"finish",
|
||||
Source,
|
||||
Some((Top, 0.5)),
|
||||
);
|
||||
clear(&project, "S5");
|
||||
assert_eq!(project.elements, baseline.elements);
|
||||
assert_eq!(project.relations, baseline.relations);
|
||||
for alias in ["dispatch_reference", "readiness_reference", "ports_view"] {
|
||||
let view = id(&project, alias);
|
||||
assert_eq!(project.diagrams[&view], baseline.diagrams[&view]);
|
||||
}
|
||||
for alias in ["dispatch_view", "readiness_view"] {
|
||||
let view = id(&project, alias);
|
||||
assert_eq!(
|
||||
project.diagrams[&view].nodes,
|
||||
baseline.diagrams[&view].nodes
|
||||
);
|
||||
for route in &project.diagrams[&view].routes {
|
||||
let original = baseline.diagrams[&view]
|
||||
.routes
|
||||
.iter()
|
||||
.find(|r| r.edge == route.edge)
|
||||
.unwrap();
|
||||
assert_eq!(route.waypoints, original.waypoints);
|
||||
assert_eq!(route.label, original.label);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,344 @@
|
||||
//! Existing source-7 nested omission compatibility, independently of formatting.
|
||||
//!
|
||||
//! Selected constructors use their own field contracts. These handwritten
|
||||
//! sources and literal models distinguish nullable optional slots from required
|
||||
//! fields; they do not prescribe compact canonical output or broaden admission.
|
||||
|
||||
use oa_core::{source_project::*, *};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
fn id(number: u8) -> Id {
|
||||
Id::parse_str(&format!("00000000-0000-4000-8000-{number:012}")).unwrap()
|
||||
}
|
||||
|
||||
fn bundle(declarations: &str) -> SourceBundle {
|
||||
let source = format!(
|
||||
"arcadia 7;\nproject p \"Admission\" id \"00000000-0000-4000-8000-000000000001\" {{\n{declarations}\n}}\n"
|
||||
);
|
||||
SourceBundle {
|
||||
entry: "project.arcadia".into(),
|
||||
files: BTreeMap::from([("project.arcadia".into(), source)]),
|
||||
}
|
||||
}
|
||||
|
||||
fn element(number: u8, alias: &str, name: &str, parent: Option<Id>, body: ElementBody) -> Element {
|
||||
Element {
|
||||
id: id(number),
|
||||
alias: alias.into(),
|
||||
name: name.into(),
|
||||
description: String::new(),
|
||||
parent,
|
||||
body,
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_admitted(input: &SourceBundle, elements: Vec<Element>) -> Project {
|
||||
let expected = Project {
|
||||
schema_version: 7,
|
||||
id: id(1),
|
||||
alias: "p".into(),
|
||||
name: "Admission".into(),
|
||||
description: String::new(),
|
||||
elements: elements.into_iter().map(|e| (e.id, e)).collect(),
|
||||
relations: BTreeMap::new(),
|
||||
diagrams: BTreeMap::new(),
|
||||
artifact_links: BTreeMap::new(),
|
||||
traces: BTreeMap::new(),
|
||||
};
|
||||
let compiled = compile_bundle(input, ProjectLimits::default()).unwrap();
|
||||
assert_eq!(compiled.decoded.project, expected, "complete literal model");
|
||||
assert_eq!(
|
||||
compiled.bundle, *input,
|
||||
"fixed IDs require no source stabilization"
|
||||
);
|
||||
compiled.decoded.project
|
||||
}
|
||||
|
||||
fn prefix(layer: Layer) -> &'static str {
|
||||
match layer {
|
||||
Layer::Oa => "oa",
|
||||
Layer::Sa => "sa",
|
||||
}
|
||||
}
|
||||
|
||||
fn data_bundle(layer: Layer, definition: &str) -> SourceBundle {
|
||||
bundle(&format!(
|
||||
" {}_data_type subject \"Subject\" id \"00000000-0000-4000-8000-000000000002\" {{ definition {{ {definition}; }}; }}",
|
||||
prefix(layer)
|
||||
))
|
||||
}
|
||||
|
||||
fn admit_data(layer: Layer, source: &str, definition: DataTypeDefinition) -> Project {
|
||||
assert_admitted(
|
||||
&data_bundle(layer, source),
|
||||
vec![element(
|
||||
2,
|
||||
"subject",
|
||||
"Subject",
|
||||
None,
|
||||
ElementBody::shared_in(
|
||||
layer,
|
||||
SharedBody::DataType {
|
||||
definition,
|
||||
default: None,
|
||||
unit: String::new(),
|
||||
},
|
||||
),
|
||||
)],
|
||||
)
|
||||
}
|
||||
|
||||
fn assert_missing(input: &SourceBundle, field: &str) {
|
||||
let errors = compile_bundle(input, ProjectLimits::default()).unwrap_err();
|
||||
assert_eq!(
|
||||
errors.len(),
|
||||
1,
|
||||
"expect the targeted admission error: {errors:?}"
|
||||
);
|
||||
let diagnostic = &errors[0].diagnostic;
|
||||
assert_eq!(diagnostic.code, "invalid_source", "{errors:?}");
|
||||
assert!(
|
||||
diagnostic.message.to_lowercase().contains("missing") && diagnostic.message.contains(field),
|
||||
"must reject the missing constructor field {field}, not an unrelated model rule: {errors:?}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn integer_optional_bounds_can_be_omitted_individually_and_together() {
|
||||
for layer in [Layer::Oa, Layer::Sa] {
|
||||
for (omitted, explicit, minimum, maximum) in [
|
||||
(
|
||||
"Integer {}",
|
||||
"Integer { minimum none; maximum none; }",
|
||||
None,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"Integer { maximum 9; }",
|
||||
"Integer { minimum none; maximum 9; }",
|
||||
None,
|
||||
Some(9),
|
||||
),
|
||||
(
|
||||
"Integer { minimum -3; }",
|
||||
"Integer { minimum -3; maximum none; }",
|
||||
Some(-3),
|
||||
None,
|
||||
),
|
||||
] {
|
||||
let expected = DataTypeDefinition::Integer { minimum, maximum };
|
||||
assert_eq!(
|
||||
admit_data(layer, omitted, expected.clone()),
|
||||
admit_data(layer, explicit, expected),
|
||||
"omitted and explicit optional Integer bounds agree"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn real_optional_bounds_can_be_omitted_individually_and_together() {
|
||||
for layer in [Layer::Oa, Layer::Sa] {
|
||||
for (omitted, explicit, minimum, maximum) in [
|
||||
(
|
||||
"Real {}",
|
||||
"Real { minimum none; maximum none; }",
|
||||
None,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"Real { maximum 2.5; }",
|
||||
"Real { minimum none; maximum 2.5; }",
|
||||
None,
|
||||
Some(2.5),
|
||||
),
|
||||
(
|
||||
"Real { minimum -1.25; }",
|
||||
"Real { minimum -1.25; maximum none; }",
|
||||
Some(-1.25),
|
||||
None,
|
||||
),
|
||||
] {
|
||||
let expected = DataTypeDefinition::Real { minimum, maximum };
|
||||
assert_eq!(
|
||||
admit_data(layer, omitted, expected.clone()),
|
||||
admit_data(layer, explicit, expected),
|
||||
"omitted and explicit optional Real bounds agree"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn string_optional_maximum_can_be_omitted_without_resetting_required_minimum() {
|
||||
for layer in [Layer::Oa, Layer::Sa] {
|
||||
let expected = DataTypeDefinition::String {
|
||||
minimum_length: 4,
|
||||
maximum_length: None,
|
||||
};
|
||||
assert_eq!(
|
||||
admit_data(layer, "String { minimum_length 4; }", expected.clone()),
|
||||
admit_data(
|
||||
layer,
|
||||
"String { minimum_length 4; maximum_length none; }",
|
||||
expected,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicitly_selected_string_requires_minimum_even_when_whole_definition_has_a_default() {
|
||||
for layer in [Layer::Oa, Layer::Sa] {
|
||||
assert_missing(&data_bundle(layer, "String {}"), "minimum_length");
|
||||
assert_missing(
|
||||
&data_bundle(layer, "String { maximum_length none; }"),
|
||||
"minimum_length",
|
||||
);
|
||||
admit_data(
|
||||
layer,
|
||||
"String { minimum_length 0; }",
|
||||
DataTypeDefinition::String {
|
||||
minimum_length: 0,
|
||||
maximum_length: None,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn absent_numeric_maximum_is_distinct_from_an_explicit_zero_bound() {
|
||||
for layer in [Layer::Oa, Layer::Sa] {
|
||||
let unbounded = admit_data(
|
||||
layer,
|
||||
"Integer { minimum -3; }",
|
||||
DataTypeDefinition::Integer {
|
||||
minimum: Some(-3),
|
||||
maximum: None,
|
||||
},
|
||||
);
|
||||
let bounded = admit_data(
|
||||
layer,
|
||||
"Integer { minimum -3; maximum 0; }",
|
||||
DataTypeDefinition::Integer {
|
||||
minimum: Some(-3),
|
||||
maximum: Some(0),
|
||||
},
|
||||
);
|
||||
assert_ne!(unbounded, bounded, "zero is a bound, not omitted syntax");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn record_has_no_required_payload_field_and_omitted_supertype_means_none() {
|
||||
for layer in [Layer::Oa, Layer::Sa] {
|
||||
let expected = DataTypeDefinition::Record { supertype: None };
|
||||
assert_eq!(
|
||||
admit_data(layer, "Record {}", expected.clone()),
|
||||
admit_data(layer, "Record { supertype none; }", expected),
|
||||
);
|
||||
let errors = compile_bundle(
|
||||
&data_bundle(layer, "Record { fields []; }"),
|
||||
ProjectLimits::default(),
|
||||
)
|
||||
.unwrap_err();
|
||||
assert_eq!(errors.len(), 1, "{errors:?}");
|
||||
assert_eq!(errors[0].diagnostic.code, "invalid_source", "{errors:?}");
|
||||
assert!(
|
||||
errors[0]
|
||||
.diagnostic
|
||||
.message
|
||||
.contains("unknown field `fields`"),
|
||||
"Record remains a closed constructor: {errors:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enumeration_still_requires_its_list_even_when_empty_list_is_admitted() {
|
||||
for layer in [Layer::Oa, Layer::Sa] {
|
||||
assert_missing(&data_bundle(layer, "Enumeration {}"), "literals");
|
||||
admit_data(
|
||||
layer,
|
||||
"Enumeration { literals []; }",
|
||||
DataTypeDefinition::Enumeration { literals: vec![] },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn port_bundle(layer: Layer, fields: &str) -> SourceBundle {
|
||||
let owner_kind = match layer {
|
||||
Layer::Oa => "oa_entity",
|
||||
Layer::Sa => "sa_system",
|
||||
};
|
||||
bundle(&format!(
|
||||
" {owner_kind} owner \"Owner\" id \"00000000-0000-4000-8000-000000000002\" {{}}\n {}_port subject \"Subject\" id \"00000000-0000-4000-8000-000000000003\" {{ parent @owner; {fields} }}",
|
||||
prefix(layer)
|
||||
))
|
||||
}
|
||||
|
||||
fn admit_port(layer: Layer, fields: &str) -> Project {
|
||||
let owner_body = match layer {
|
||||
Layer::Oa => ElementBody::Oa(OaBody::Entity),
|
||||
Layer::Sa => ElementBody::Sa(SaBody::System),
|
||||
};
|
||||
assert_admitted(
|
||||
&port_bundle(layer, fields),
|
||||
vec![
|
||||
element(2, "owner", "Owner", None, owner_body),
|
||||
element(
|
||||
3,
|
||||
"subject",
|
||||
"Subject",
|
||||
Some(id(2)),
|
||||
ElementBody::shared_in(
|
||||
layer,
|
||||
SharedBody::Port {
|
||||
contract: PortContract::Legacy,
|
||||
legacy: Some(LegacyPortContract {
|
||||
direction: PortDirection::Out,
|
||||
interface: None,
|
||||
}),
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_port_interface_can_be_omitted_but_preserves_direction() {
|
||||
for layer in [Layer::Oa, Layer::Sa] {
|
||||
assert_eq!(
|
||||
admit_port(layer, "contract Legacy; legacy { direction Out; };"),
|
||||
admit_port(
|
||||
layer,
|
||||
"contract Legacy; legacy { direction Out; interface none; };"
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_port_direction_remains_required_inside_selected_record() {
|
||||
for layer in [Layer::Oa, Layer::Sa] {
|
||||
assert_missing(
|
||||
&port_bundle(layer, "contract Legacy; legacy {};"),
|
||||
"direction",
|
||||
);
|
||||
assert_missing(
|
||||
&port_bundle(layer, "contract Legacy; legacy { interface none; };"),
|
||||
"direction",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn port_declaration_still_requires_explicit_contract() {
|
||||
for layer in [Layer::Oa, Layer::Sa] {
|
||||
assert_missing(
|
||||
&port_bundle(layer, "legacy { direction Out; };"),
|
||||
"contract",
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,445 @@
|
||||
//! Public flat/modular formatter fidelity over frozen input and bounded mutations.
|
||||
//! Legacy fixture migration uses the public parser. The original adapter tests
|
||||
//! and exact inputs remain archived at source commit 2a64344; this suite exercises
|
||||
//! production formatters, not that frozen experiment or lossless model edits.
|
||||
|
||||
use oa_core::{language, source_project::*, *};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
const COASTAL: &str = include_str!("../../../examples/coastal-rescue.arcadia");
|
||||
const KEYED: &str =
|
||||
include_str!("../../../harness/fixtures/release1-native/semantic-keyed.arcadia");
|
||||
const STATES: &str =
|
||||
include_str!("../../../harness/fixtures/release1-native/state-actions.arcadia");
|
||||
const DENSE: &str =
|
||||
include_str!("../../../harness/fixtures/release1-native/dense-40/dense-40.arcadia");
|
||||
const OPERATIONS: &str = include_str!(
|
||||
"../../../harness/fixtures/interface-operation-probe/output/boundary-only.arcadia"
|
||||
);
|
||||
|
||||
fn read(source: &str) -> Project {
|
||||
language::parse(source).unwrap()
|
||||
}
|
||||
|
||||
fn identity(project: &Project, alias: &str) -> Id {
|
||||
project
|
||||
.identities()
|
||||
.into_iter()
|
||||
.find(|(_, name)| *name == alias)
|
||||
.unwrap()
|
||||
.0
|
||||
}
|
||||
|
||||
fn assert_common_omissions(project: &Project, compiled: &CompiledSourceProject) {
|
||||
if project.description.is_empty() {
|
||||
assert!(compiled.index.project_description.is_none());
|
||||
}
|
||||
let descriptions = project
|
||||
.elements
|
||||
.values()
|
||||
.map(|e| (e.id, &e.description))
|
||||
.chain(project.relations.values().map(|r| (r.id, &r.description)))
|
||||
.chain(project.diagrams.values().map(|d| (d.id, &d.description)))
|
||||
.chain(
|
||||
project
|
||||
.artifact_links
|
||||
.values()
|
||||
.map(|a| (a.id, &a.description)),
|
||||
)
|
||||
.chain(project.traces.values().map(|t| (t.id, &t.description)));
|
||||
for (id, description) in descriptions {
|
||||
if description.is_empty() {
|
||||
assert!(
|
||||
!compiled
|
||||
.index
|
||||
.fields
|
||||
.contains_key(&(id, "description".into()))
|
||||
);
|
||||
}
|
||||
}
|
||||
for element in project.elements.values().filter(|e| e.parent.is_none()) {
|
||||
assert!(
|
||||
!compiled
|
||||
.index
|
||||
.fields
|
||||
.contains_key(&(element.id, "parent".into()))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_fidelity(label: &str, project: &Project) -> (Project, String) {
|
||||
let flat = language::format(project);
|
||||
let compact_model = read(&flat);
|
||||
assert_eq!(
|
||||
compact_model, *project,
|
||||
"{label}: every persistent field survives"
|
||||
);
|
||||
|
||||
let input = SourceBundle {
|
||||
entry: "project.arcadia".into(),
|
||||
files: BTreeMap::from([("project.arcadia".into(), flat.clone())]),
|
||||
};
|
||||
let compiled = compile_bundle(&input, ProjectLimits::default()).unwrap();
|
||||
assert_eq!(
|
||||
compiled.decoded.project, *project,
|
||||
"{label}: source-project compile"
|
||||
);
|
||||
assert_eq!(
|
||||
compiled.bundle, input,
|
||||
"{label}: compact identities/source are stable"
|
||||
);
|
||||
|
||||
assert_common_omissions(project, &compiled);
|
||||
assert_eq!(
|
||||
language::format(&compact_model),
|
||||
flat,
|
||||
"{label}: flat idempotence"
|
||||
);
|
||||
|
||||
let modular = format_bundle(project);
|
||||
assert!(
|
||||
modular.files.len() > 1,
|
||||
"{label}: exercise generated includes"
|
||||
);
|
||||
let modular_compiled = compile_bundle(&modular, ProjectLimits::default()).unwrap();
|
||||
assert_eq!(
|
||||
modular_compiled.decoded.project, *project,
|
||||
"{label}: complete modular model"
|
||||
);
|
||||
assert_eq!(
|
||||
modular_compiled.bundle, modular,
|
||||
"{label}: modular source/IDs are stable"
|
||||
);
|
||||
assert_common_omissions(project, &modular_compiled);
|
||||
assert_eq!(
|
||||
format_bundle(&compact_model),
|
||||
modular,
|
||||
"{label}: flat-to-modular determinism"
|
||||
);
|
||||
assert_eq!(
|
||||
format_bundle(&modular_compiled.decoded.project),
|
||||
modular,
|
||||
"{label}: modular idempotence"
|
||||
);
|
||||
|
||||
// Pinned measured compact bytes from the published fidelity-1 stderr.log at
|
||||
// 2a64344, not a comparison against today's (now compact) canonical writer.
|
||||
// A small header-layout allowance avoids enforcing incidental blank lines.
|
||||
let measured_compact_bytes = match label {
|
||||
"coastal-source3" => 28_465,
|
||||
"keyed-source5-history" => 12_066,
|
||||
"state-actions-source5" => 6_673,
|
||||
"dense40-source6" => 19_342,
|
||||
"boundary-operations-source6" => 3_660,
|
||||
"state-negative-zero" => 6_672,
|
||||
"keyed-present-empty-default" => 12_108,
|
||||
"coastal-present-empty-artifact-strings" => 28_483,
|
||||
"boundary-selected-and-unresolved-operations" => 3_806,
|
||||
_ => panic!("missing independent compact measurement for {label}"),
|
||||
};
|
||||
assert!(
|
||||
flat.len() <= measured_compact_bytes + 16,
|
||||
"{label}: {} bytes exceeds compact evidence budget {}",
|
||||
flat.len(),
|
||||
measured_compact_bytes + 16
|
||||
);
|
||||
(compact_model, flat)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn migrated_coastal_oa_sa_views_ports_artifacts_and_traces_roundtrip() {
|
||||
assert!(COASTAL.starts_with("arcadia 3;"));
|
||||
let project = read(COASTAL);
|
||||
assert!(project.elements.values().any(|e| e.layer() == Layer::Oa));
|
||||
assert!(project.elements.values().any(|e| e.layer() == Layer::Sa));
|
||||
assert!(
|
||||
project
|
||||
.elements
|
||||
.values()
|
||||
.any(|e| matches!(e.shared(), Some(SharedBody::Port { .. })))
|
||||
);
|
||||
assert!(project.elements.values().any(
|
||||
|e| matches!(e.shared(), Some(SharedBody::Scenario { steps, .. }) if !steps.is_empty())
|
||||
));
|
||||
assert!(project.diagrams.values().any(|d| d.layer == Layer::Oa
|
||||
&& d.projection == ProjectionKind::FunctionalDataflow
|
||||
&& !d.nodes.is_empty()));
|
||||
assert!(project.diagrams.values().any(|d| d.layer == Layer::Sa
|
||||
&& d.projection == ProjectionKind::Allocation
|
||||
&& !d.nodes.is_empty()));
|
||||
assert!(!project.artifact_links.is_empty());
|
||||
assert!(project.traces.values().any(|t| t.baseline.is_some()));
|
||||
assert_fidelity("coastal-source3", &project);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keyed_scenarios_records_and_historical_binding_annotation_facets_roundtrip() {
|
||||
let project = read(KEYED);
|
||||
for layer in [Layer::Oa, Layer::Sa] {
|
||||
assert!(project.elements.values().any(|e| e.layer() == layer
|
||||
&& matches!(
|
||||
e.shared(),
|
||||
Some(SharedBody::DataType {
|
||||
definition: DataTypeDefinition::Record { .. },
|
||||
..
|
||||
})
|
||||
)));
|
||||
assert!(project.elements.values().any(|e| e.layer() == layer && matches!(e.shared(), Some(SharedBody::Occurrence { body: OccurrenceBody::ScenarioUse { bindings, .. }, .. }) if !bindings.is_empty())));
|
||||
}
|
||||
assert!(project.elements.values().any(|e| matches!(e.shared(), Some(SharedBody::Occurrence { body: OccurrenceBody::Exchange { values, .. }, .. }) if values.iter().any(|v| !v.path.is_empty() && !v.expression.is_empty()))));
|
||||
let facets: Vec<_> = project
|
||||
.traces
|
||||
.values()
|
||||
.filter_map(|t| t.baseline.as_ref()?.semantic.as_ref())
|
||||
.flat_map(|baseline| &baseline.facets)
|
||||
.collect();
|
||||
assert!(
|
||||
facets
|
||||
.iter()
|
||||
.any(|facet| matches!(facet, semantic::FacetReview::Binding { .. }))
|
||||
);
|
||||
assert!(
|
||||
facets
|
||||
.iter()
|
||||
.any(|facet| matches!(facet, semantic::FacetReview::Annotation { .. }))
|
||||
);
|
||||
assert!(
|
||||
KEYED.contains("uuid \""),
|
||||
"fixture contains historical identity atoms"
|
||||
);
|
||||
let (_, source) = assert_fidelity("keyed-source5-history", &project);
|
||||
assert!(
|
||||
source.contains("uuid \""),
|
||||
"historical atoms remain historical"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn state_machine_projection_typed_actions_and_bounded_integer_roundtrip() {
|
||||
let project = read(STATES);
|
||||
let machine = identity(&project, "operating");
|
||||
let view = &project.diagrams[&identity(&project, "state_view")];
|
||||
assert_eq!(view.projection, ProjectionKind::StateMachine { machine });
|
||||
assert!(!view.nodes.is_empty());
|
||||
for phase in [
|
||||
StateActionKind::Entry,
|
||||
StateActionKind::Do,
|
||||
StateActionKind::Exit,
|
||||
] {
|
||||
assert!(project.relations.values().any(|r| matches!(&r.body, RelationBody::StateAction { phase: actual, .. } if *actual == phase)));
|
||||
}
|
||||
assert!(project.relations.values().any(|r| matches!(&r.body, RelationBody::StateTransition { transition_kind: TransitionKind::Internal, triggers, effects, .. } if !triggers.is_empty() && !effects.is_empty())));
|
||||
assert!(
|
||||
matches!(project.elements[&identity(&project, "retry_budget")].shared(), Some(SharedBody::DataType { definition: DataTypeDefinition::Integer { minimum: Some(0), maximum: Some(4) }, unit, .. }) if unit == "attempts")
|
||||
);
|
||||
assert_fidelity("state-actions-source5", &project);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn forty_exchange_diagram_with_categories_and_processes_roundtrip() {
|
||||
let project = read(DENSE);
|
||||
assert_eq!(
|
||||
project
|
||||
.relations
|
||||
.values()
|
||||
.filter(|r| r.kind() == RelationKind::Interaction)
|
||||
.count(),
|
||||
40
|
||||
);
|
||||
assert_eq!(
|
||||
project
|
||||
.elements
|
||||
.values()
|
||||
.filter(|e| e.kind() == Kind::ExchangeCategory)
|
||||
.count(),
|
||||
5
|
||||
);
|
||||
assert_eq!(
|
||||
project
|
||||
.elements
|
||||
.values()
|
||||
.filter(|e| e.kind() == Kind::Process)
|
||||
.count(),
|
||||
3
|
||||
);
|
||||
let view = &project.diagrams[&identity(&project, "forty_exchange_view")];
|
||||
assert_eq!(view.projection, ProjectionKind::FunctionalDataflow);
|
||||
assert_eq!(view.nodes.len(), 2);
|
||||
assert!(view.routes.is_empty());
|
||||
assert_eq!(
|
||||
view.view_options.relation_kinds,
|
||||
view_options::RelationKinds::All
|
||||
);
|
||||
assert_fidelity("dense40-source6", &project);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn component_ports_interface_operations_and_boundary_calls_roundtrip() {
|
||||
let project = read(OPERATIONS);
|
||||
assert_eq!(
|
||||
project
|
||||
.relations
|
||||
.values()
|
||||
.filter(|r| r.kind() == RelationKind::InterfaceItemAllocation)
|
||||
.count(),
|
||||
2
|
||||
);
|
||||
assert_eq!(
|
||||
project
|
||||
.elements
|
||||
.values()
|
||||
.filter(|e| matches!(
|
||||
e.shared(),
|
||||
Some(SharedBody::Port {
|
||||
contract: PortContract::Component {
|
||||
kind: ComponentPortKind::Standard,
|
||||
..
|
||||
},
|
||||
..
|
||||
})
|
||||
))
|
||||
.count(),
|
||||
2
|
||||
);
|
||||
assert!(project.elements.values().any(|e| matches!(
|
||||
e.shared(),
|
||||
Some(SharedBody::ExchangeItem {
|
||||
mechanism: ExchangeMechanism::Operation,
|
||||
..
|
||||
})
|
||||
)));
|
||||
assert!(project.elements.values().any(|e| matches!(e.shared(), Some(SharedBody::Scenario { viewpoint: ScenarioViewpoint::BoundaryInterface, steps, .. }) if steps.len() == 2)));
|
||||
assert_eq!(
|
||||
project
|
||||
.elements
|
||||
.values()
|
||||
.filter(|e| matches!(
|
||||
e.shared(),
|
||||
Some(SharedBody::Occurrence {
|
||||
body: OccurrenceBody::Exchange {
|
||||
message_kind: MessageKind::Call,
|
||||
operation: None,
|
||||
..
|
||||
},
|
||||
..
|
||||
})
|
||||
))
|
||||
.count(),
|
||||
2
|
||||
);
|
||||
assert_fidelity("boundary-operations-source6", &project);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn negative_zero_node_coordinate_survives_canonical_compact_and_bundle_compile() {
|
||||
let mut project = read(STATES);
|
||||
let diagram = identity(&project, "state_view");
|
||||
let node = identity(&project, "view_machine");
|
||||
project
|
||||
.diagrams
|
||||
.get_mut(&diagram)
|
||||
.unwrap()
|
||||
.nodes
|
||||
.get_mut(&node)
|
||||
.unwrap()
|
||||
.position = Position { x: -0.0, y: 0.0 };
|
||||
let (decoded, flat) = assert_fidelity("state-negative-zero", &project);
|
||||
let bundle = SourceBundle {
|
||||
entry: "project.arcadia".into(),
|
||||
files: BTreeMap::from([("project.arcadia".into(), flat)]),
|
||||
};
|
||||
let compiled = compile_bundle(&bundle, ProjectLimits::default()).unwrap();
|
||||
let modular = compile_bundle(&format_bundle(&project), ProjectLimits::default()).unwrap();
|
||||
// Project/Position PartialEq alone equates the signs of zero. Check bits in
|
||||
// each independently decoded representation, including source-project compile.
|
||||
for actual in [
|
||||
&decoded,
|
||||
&compiled.decoded.project,
|
||||
&modular.decoded.project,
|
||||
] {
|
||||
let position = &actual.diagrams[&diagram].nodes[&node].position;
|
||||
assert_eq!(position.x.to_bits(), (-0.0_f32).to_bits());
|
||||
assert_eq!(position.y.to_bits(), 0.0_f32.to_bits());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn present_empty_field_default_and_unbounded_maximum_remain_distinct_from_omission() {
|
||||
let mut project = read(KEYED);
|
||||
let field_id = identity(&project, "oa_navigation_latitude");
|
||||
let Some(SharedBody::DataField {
|
||||
minimum,
|
||||
maximum,
|
||||
default,
|
||||
storage,
|
||||
..
|
||||
}) = project.elements.get_mut(&field_id).unwrap().shared_mut()
|
||||
else {
|
||||
panic!("fixture must contain the claimed DataField");
|
||||
};
|
||||
assert_eq!(*minimum, 0);
|
||||
assert_eq!(*maximum, Some(1));
|
||||
assert_eq!(*default, None);
|
||||
assert_eq!(*storage, FieldStorage::Value);
|
||||
*maximum = None;
|
||||
*default = Some(vec![]);
|
||||
let (decoded, _) = assert_fidelity("keyed-present-empty-default", &project);
|
||||
assert!(
|
||||
matches!(decoded.elements[&field_id].shared(), Some(SharedBody::DataField { maximum: None, default: Some(values), .. }) if values.is_empty())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn present_empty_artifact_revision_and_fragment_survive() {
|
||||
let mut project = read(COASTAL);
|
||||
let artifact_id = identity(&project, "console_enclosure_cad");
|
||||
let artifact = project.artifact_links.get_mut(&artifact_id).unwrap();
|
||||
artifact.revision = Some(String::new());
|
||||
artifact.fragment = Some(String::new());
|
||||
let (decoded, _) = assert_fidelity("coastal-present-empty-artifact-strings", &project);
|
||||
assert_eq!(
|
||||
decoded.artifact_links[&artifact_id].revision.as_deref(),
|
||||
Some("")
|
||||
);
|
||||
assert_eq!(
|
||||
decoded.artifact_links[&artifact_id].fragment.as_deref(),
|
||||
Some("")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn selected_and_unresolved_operation_intent_survive_as_distinct_present_records() {
|
||||
let mut project = read(OPERATIONS);
|
||||
let allocation = identity(&project, "operation_probe_30");
|
||||
assert_eq!(
|
||||
project.relations[&allocation].kind(),
|
||||
RelationKind::InterfaceItemAllocation
|
||||
);
|
||||
let selected = identity(&project, "operation_probe_43");
|
||||
let unresolved = identity(&project, "operation_probe_44");
|
||||
for (subject, value) in [(selected, Some(allocation)), (unresolved, None)] {
|
||||
let Some(SharedBody::Occurrence {
|
||||
body: OccurrenceBody::Exchange { operation, .. },
|
||||
..
|
||||
}) = project.elements.get_mut(&subject).unwrap().shared_mut()
|
||||
else {
|
||||
panic!("fixture must contain a Call Exchange");
|
||||
};
|
||||
assert_eq!(*operation, None);
|
||||
*operation = Some(OperationUse { allocation: value });
|
||||
}
|
||||
let (decoded, _) = assert_fidelity("boundary-selected-and-unresolved-operations", &project);
|
||||
assert!(
|
||||
matches!(decoded.elements[&selected].shared(), Some(SharedBody::Occurrence { body: OccurrenceBody::Exchange { operation: Some(OperationUse { allocation: Some(actual) }), .. }, .. }) if *actual == allocation)
|
||||
);
|
||||
assert!(matches!(
|
||||
decoded.elements[&unresolved].shared(),
|
||||
Some(SharedBody::Occurrence {
|
||||
body: OccurrenceBody::Exchange {
|
||||
operation: Some(OperationUse { allocation: None }),
|
||||
..
|
||||
},
|
||||
..
|
||||
})
|
||||
));
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
//! Focused public-output contracts. Field locations come from the real compiler;
|
||||
//! token comparisons ignore layout while retaining typed tags and required syntax.
|
||||
use oa_core::{language, source_project::*, *};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
fn project(declarations: &str) -> Project {
|
||||
language::parse(&format!(
|
||||
"arcadia 7; project p \"P\" id \"00000000-0000-4000-8000-000000000001\" {{ {declarations} }}"
|
||||
)).unwrap()
|
||||
}
|
||||
|
||||
fn exports(project: &Project) -> Vec<CompiledSourceProject> {
|
||||
let flat = language::format(project);
|
||||
assert_eq!(language::parse(&flat).unwrap(), *project);
|
||||
let flat_bundle = SourceBundle {
|
||||
entry: "project.arcadia".into(),
|
||||
files: BTreeMap::from([("project.arcadia".into(), flat)]),
|
||||
};
|
||||
[flat_bundle, format_bundle(project)]
|
||||
.into_iter()
|
||||
.map(|bundle| {
|
||||
let compiled = compile_bundle(&bundle, ProjectLimits::default()).unwrap();
|
||||
assert_eq!(compiled.decoded.project, *project);
|
||||
assert_eq!(
|
||||
compiled.bundle, bundle,
|
||||
"all identities are explicit and stable"
|
||||
);
|
||||
compiled
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn identity(project: &Project, alias: &str) -> Id {
|
||||
project
|
||||
.identities()
|
||||
.into_iter()
|
||||
.find(|(_, name)| *name == alias)
|
||||
.unwrap()
|
||||
.0
|
||||
}
|
||||
|
||||
fn field(compiled: &CompiledSourceProject, alias: &str, name: &str) -> Option<String> {
|
||||
let location = compiled
|
||||
.index
|
||||
.fields
|
||||
.get(&(identity(&compiled.decoded.project, alias), name.into()))?;
|
||||
let text = &compiled.bundle.files[&location.path][location.span.start..location.span.end];
|
||||
Some(
|
||||
language::tokenize(text)
|
||||
.into_iter()
|
||||
.filter(|token| {
|
||||
!matches!(
|
||||
token.class,
|
||||
language::TokenClass::Whitespace | language::TokenClass::Comment
|
||||
)
|
||||
})
|
||||
.map(|token| &text[token.span.start..token.span.end])
|
||||
.collect::<Vec<_>>()
|
||||
.join(" "),
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_project_has_no_synthetic_description_or_module() {
|
||||
let empty = project("");
|
||||
for compiled in exports(&empty) {
|
||||
assert!(compiled.index.project_description.is_none());
|
||||
assert!(compiled.index.fields.is_empty());
|
||||
assert!(compiled.index.includes.is_empty());
|
||||
assert_eq!(compiled.bundle.files.len(), 1);
|
||||
assert_eq!(compiled.index.declarations.len(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_empty_descriptions_disappear_whitespace_and_text_survive_exactly() {
|
||||
let mut model =
|
||||
project("oa_activity work \"Work\" id \"00000000-0000-4000-8000-000000000002\" {}");
|
||||
let work = identity(&model, "work");
|
||||
for description in ["", " \t\n", "A quoted \"requirement\" — 雨"] {
|
||||
model.description = description.into();
|
||||
model.elements.get_mut(&work).unwrap().description = description.into();
|
||||
for compiled in exports(&model) {
|
||||
assert_eq!(
|
||||
compiled.index.project_description.is_some(),
|
||||
!description.is_empty()
|
||||
);
|
||||
assert_eq!(
|
||||
field(&compiled, "work", "description").is_some(),
|
||||
!description.is_empty()
|
||||
);
|
||||
assert!(field(&compiled, "work", "parent").is_none());
|
||||
// exports compares the complete model, including exact whitespace
|
||||
// and escapes in both project and element descriptions.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sa_view_keeps_its_layer_and_node_references_but_omits_presentation_defaults() {
|
||||
let model = project(
|
||||
r#"
|
||||
sa_function work "Work" id "00000000-0000-4000-8000-000000000002" {}
|
||||
diagram view "View" id "00000000-0000-4000-8000-000000000003" { layer Sa; }
|
||||
node placement id "00000000-0000-4000-8000-000000000004" {
|
||||
diagram @view; element @work;
|
||||
position { x 0.0; y 0.0; }; size { width 224.0; height 94.0; };
|
||||
collapsed false; port_anchors [];
|
||||
}
|
||||
"#,
|
||||
);
|
||||
for compiled in exports(&model) {
|
||||
assert_eq!(field(&compiled, "view", "layer").as_deref(), Some("Sa"));
|
||||
for name in ["description", "projection", "routes", "view_options"] {
|
||||
assert!(field(&compiled, "view", name).is_none(), "view.{name}");
|
||||
}
|
||||
assert_eq!(
|
||||
field(&compiled, "placement", "diagram").as_deref(),
|
||||
Some("@ view")
|
||||
);
|
||||
assert_eq!(
|
||||
field(&compiled, "placement", "element").as_deref(),
|
||||
Some("@ work")
|
||||
);
|
||||
for name in ["position", "size", "collapsed", "port_anchors"] {
|
||||
assert!(
|
||||
field(&compiled, "placement", name).is_none(),
|
||||
"placement.{name}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nested_type_defaults_disappear_without_losing_required_or_present_empty_values() {
|
||||
let model = project(
|
||||
r#"
|
||||
sa_data_type implicit "Implicit" id "00000000-0000-4000-8000-000000000002" {}
|
||||
sa_data_type integer "Integer" id "00000000-0000-4000-8000-000000000003" {
|
||||
definition { Integer { minimum none; maximum none; }; };
|
||||
}
|
||||
sa_data_type text "Text" id "00000000-0000-4000-8000-000000000004" {
|
||||
definition { String { minimum_length 4; maximum_length none; }; };
|
||||
}
|
||||
sa_data_type record "Record" id "00000000-0000-4000-8000-000000000005" {
|
||||
definition { Record { supertype none; }; };
|
||||
}
|
||||
sa_data_type flag "Flag" id "00000000-0000-4000-8000-000000000006" {
|
||||
definition Boolean; default { Boolean false; };
|
||||
}
|
||||
sa_data_field optional "Optional" id "00000000-0000-4000-8000-000000000007" {
|
||||
parent @record; minimum 0; maximum none; default [];
|
||||
}
|
||||
"#,
|
||||
);
|
||||
for compiled in exports(&model) {
|
||||
assert!(field(&compiled, "implicit", "definition").is_none());
|
||||
assert_eq!(
|
||||
field(&compiled, "integer", "definition").as_deref(),
|
||||
Some("{ Integer { } ; }")
|
||||
);
|
||||
assert_eq!(
|
||||
field(&compiled, "text", "definition").as_deref(),
|
||||
Some("{ String { minimum_length 4 ; } ; }")
|
||||
);
|
||||
assert_eq!(
|
||||
field(&compiled, "record", "definition").as_deref(),
|
||||
Some("{ Record { } ; }")
|
||||
);
|
||||
assert_eq!(
|
||||
field(&compiled, "flag", "definition").as_deref(),
|
||||
Some("Boolean")
|
||||
);
|
||||
assert_eq!(
|
||||
field(&compiled, "flag", "default").as_deref(),
|
||||
Some("{ Boolean false ; }")
|
||||
);
|
||||
assert_eq!(
|
||||
field(&compiled, "optional", "minimum").as_deref(),
|
||||
Some("0")
|
||||
);
|
||||
assert_eq!(
|
||||
field(&compiled, "optional", "maximum").as_deref(),
|
||||
Some("none")
|
||||
);
|
||||
assert_eq!(
|
||||
field(&compiled, "optional", "default").as_deref(),
|
||||
Some("[ ]")
|
||||
);
|
||||
assert!(field(&compiled, "optional", "type_ref").is_none());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn required_port_contract_and_empty_item_list_survive_while_optional_interface_disappears() {
|
||||
let model = project(
|
||||
r#"
|
||||
sa_function work "Work" id "00000000-0000-4000-8000-000000000002" {}
|
||||
sa_port sink "Sink" id "00000000-0000-4000-8000-000000000003" {
|
||||
parent @work; contract { FunctionInput { incoming_items []; }; };
|
||||
}
|
||||
sa_system host "Host" id "00000000-0000-4000-8000-000000000004" {}
|
||||
sa_port preserved "Preserved" id "00000000-0000-4000-8000-000000000005" {
|
||||
parent @host; contract Legacy; legacy { direction Out; interface none; };
|
||||
}
|
||||
"#,
|
||||
);
|
||||
for compiled in exports(&model) {
|
||||
assert_eq!(
|
||||
field(&compiled, "sink", "contract").as_deref(),
|
||||
Some("{ FunctionInput { incoming_items [ ] ; } ; }")
|
||||
);
|
||||
assert!(field(&compiled, "sink", "legacy").is_none());
|
||||
assert_eq!(
|
||||
field(&compiled, "preserved", "contract").as_deref(),
|
||||
Some("Legacy")
|
||||
);
|
||||
assert_eq!(
|
||||
field(&compiled, "preserved", "legacy").as_deref(),
|
||||
Some("{ direction Out ; }")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn source_scenario_default_and_selected_occurrence_constructor_remain_distinct() {
|
||||
let model = project(
|
||||
r#"
|
||||
sa_scenario mixed "Mixed" id "00000000-0000-4000-8000-000000000002" { viewpoint MixedLegacy; }
|
||||
sa_scenario strict "Strict" id "00000000-0000-4000-8000-000000000003" { viewpoint Functional; }
|
||||
oa_process flow "Flow" id "00000000-0000-4000-8000-000000000004" { steps [@exchange, @action]; }
|
||||
oa_occurrence exchange "Exchange" id "00000000-0000-4000-8000-000000000005" {
|
||||
parent @flow; body { Exchange {}; };
|
||||
}
|
||||
oa_occurrence action "Action" id "00000000-0000-4000-8000-000000000006" {
|
||||
parent @flow; body { Action { action none; lifeline none; }; };
|
||||
}
|
||||
"#,
|
||||
);
|
||||
for compiled in exports(&model) {
|
||||
assert!(field(&compiled, "mixed", "viewpoint").is_none());
|
||||
assert_eq!(
|
||||
field(&compiled, "strict", "viewpoint").as_deref(),
|
||||
Some("Functional")
|
||||
);
|
||||
assert!(field(&compiled, "exchange", "body").is_none());
|
||||
assert_eq!(
|
||||
field(&compiled, "action", "body").as_deref(),
|
||||
Some("{ Action { } ; }")
|
||||
);
|
||||
assert_eq!(
|
||||
field(&compiled, "action", "parent").as_deref(),
|
||||
Some("@ flow")
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,612 @@
|
||||
//! Exact-source regressions for fields skipped by persistence serialization.
|
||||
//!
|
||||
//! The archived Windows baseline confirmed three exact-source failures after
|
||||
//! full model equality passed. Complete comparison now preserves these fields;
|
||||
//! the former ignored witnesses are normal regression tests.
|
||||
//! No-op and same-record header controls remain normal tests: they must preserve
|
||||
//! the same fixtures without entering the changed-payload record-erasure branch.
|
||||
|
||||
use oa_core::{source_project::*, *};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
const EXCHANGE_SOURCE: &str = r#"arcadia 7;
|
||||
project p "Preservation" id "00000000-0000-4000-8000-000000000001" {
|
||||
oa_activity first "First" id "00000000-0000-4000-8000-000000000002" {}
|
||||
oa_activity second "Second" id "00000000-0000-4000-8000-000000000003" {}
|
||||
interaction flow "Flow" id "00000000-0000-4000-8000-000000000004" {
|
||||
source @first; target @second;
|
||||
}
|
||||
oa_process owner "Owner" id "00000000-0000-4000-8000-000000000005" {
|
||||
steps [@subject];
|
||||
}
|
||||
oa_occurrence subject "Subject" id "00000000-0000-4000-8000-000000000006" {
|
||||
parent @owner;
|
||||
body { Exchange {
|
||||
exchange none;
|
||||
sender none; receiver none;
|
||||
message_kind Asynchronous; reply_to none; values [];
|
||||
operation none ; // Keep this authored default and its spelling.
|
||||
}; };
|
||||
}
|
||||
}
|
||||
"#;
|
||||
|
||||
const NODE_SOURCE: &str = r#"arcadia 7;
|
||||
project p "Preservation" id "00000000-0000-4000-8000-000000000001" {
|
||||
oa_activity work "Work" id "00000000-0000-4000-8000-000000000002" {}
|
||||
diagram view "View" id "00000000-0000-4000-8000-000000000003" {}
|
||||
node placement id "00000000-0000-4000-8000-000000000004" {
|
||||
diagram @view; element @work;
|
||||
position { x 12.5; y -4.0; };
|
||||
port_anchors [] ; // Keep explicit automatic placement.
|
||||
}
|
||||
}
|
||||
"#;
|
||||
|
||||
const TRACE_SOURCE: &str = r#"arcadia 7;
|
||||
project p "Preservation" id "00000000-0000-4000-8000-000000000001" {
|
||||
oa_activity work "Work" id "00000000-0000-4000-8000-000000000002" {}
|
||||
sa_function function "Function" id "00000000-0000-4000-8000-000000000003" {}
|
||||
trace mapping "Mapping" id "00000000-0000-4000-8000-000000000004" {
|
||||
oa @work; sa @function; kind Manual;
|
||||
baseline {
|
||||
oa { name "Work"; description "Old OA snapshot"; };
|
||||
sa { name "Function"; description "Old SA snapshot"; };
|
||||
semantic none ; // Keep the explicit prose-only baseline.
|
||||
};
|
||||
}
|
||||
}
|
||||
"#;
|
||||
|
||||
const CONSTRUCTOR_SOURCE: &str = r#"arcadia 7;
|
||||
project p "Preservation" id "00000000-0000-4000-8000-000000000001" {
|
||||
oa_scenario owner "Owner" id "00000000-0000-4000-8000-000000000002" {
|
||||
steps [@subject];
|
||||
}
|
||||
oa_occurrence subject "Subject" id "00000000-0000-4000-8000-000000000003" {
|
||||
parent @owner;
|
||||
body { Action {
|
||||
action none;
|
||||
lifeline none ; // Keep this shared field's distinctive spelling.
|
||||
}; };
|
||||
}
|
||||
}
|
||||
"#;
|
||||
|
||||
const RELATION_CONTEXT_SOURCE: &str = r#"arcadia 7;
|
||||
project p "Preservation" id "00000000-0000-4000-8000-000000000001" {
|
||||
oa_entity first "First" id "00000000-0000-4000-8000-000000000002" {}
|
||||
oa_entity second "Second" id "00000000-0000-4000-8000-000000000003" {}
|
||||
// These port declarations are untouched by the relation context change.
|
||||
oa_port output "Output" id "00000000-0000-4000-8000-000000000005" {
|
||||
parent @first; contract Legacy;
|
||||
legacy { direction Out; interface none; };
|
||||
}
|
||||
oa_port input "Input" id "00000000-0000-4000-8000-000000000006" {
|
||||
parent @second; contract Legacy;
|
||||
legacy { direction In; interface none; };
|
||||
}
|
||||
boundary_exchange link "Link" id "00000000-0000-4000-8000-000000000004" {
|
||||
source @output; target @input;
|
||||
oriented true ; // Retain this rationale when changing the default value.
|
||||
items [];
|
||||
}
|
||||
}
|
||||
"#;
|
||||
|
||||
fn id(number: u8) -> Id {
|
||||
Id::parse_str(&format!("00000000-0000-4000-8000-{number:012}")).unwrap()
|
||||
}
|
||||
|
||||
fn source_bundle(source: &str) -> SourceBundle {
|
||||
SourceBundle {
|
||||
entry: "project.arcadia".into(),
|
||||
files: BTreeMap::from([("project.arcadia".into(), source.into())]),
|
||||
}
|
||||
}
|
||||
|
||||
fn project() -> Project {
|
||||
Project {
|
||||
schema_version: 7,
|
||||
id: id(1),
|
||||
alias: "p".into(),
|
||||
name: "Preservation".into(),
|
||||
description: String::new(),
|
||||
elements: BTreeMap::new(),
|
||||
relations: BTreeMap::new(),
|
||||
diagrams: BTreeMap::new(),
|
||||
artifact_links: BTreeMap::new(),
|
||||
traces: BTreeMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn element(number: u8, alias: &str, name: &str, parent: Option<Id>, body: ElementBody) -> Element {
|
||||
Element {
|
||||
id: id(number),
|
||||
alias: alias.into(),
|
||||
name: name.into(),
|
||||
description: String::new(),
|
||||
parent,
|
||||
body,
|
||||
}
|
||||
}
|
||||
|
||||
// Handwritten typed expectations are independent of canonical serialization and
|
||||
// source hydration. No model factories or generated/random identities are used.
|
||||
fn exchange_project() -> Project {
|
||||
let mut expected = project();
|
||||
expected.elements = [
|
||||
element(2, "first", "First", None, ElementBody::Oa(OaBody::Activity)),
|
||||
element(
|
||||
3,
|
||||
"second",
|
||||
"Second",
|
||||
None,
|
||||
ElementBody::Oa(OaBody::Activity),
|
||||
),
|
||||
element(
|
||||
5,
|
||||
"owner",
|
||||
"Owner",
|
||||
None,
|
||||
ElementBody::Oa(OaBody::Process { steps: vec![id(6)] }),
|
||||
),
|
||||
element(
|
||||
6,
|
||||
"subject",
|
||||
"Subject",
|
||||
Some(id(5)),
|
||||
ElementBody::Oa(OaBody::Shared(SharedBody::Occurrence {
|
||||
body: OccurrenceBody::Exchange {
|
||||
exchange: None,
|
||||
sender: None,
|
||||
receiver: None,
|
||||
message_kind: MessageKind::Asynchronous,
|
||||
reply_to: None,
|
||||
values: vec![],
|
||||
operation: None,
|
||||
},
|
||||
precondition: String::new(),
|
||||
postcondition: String::new(),
|
||||
})),
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|element| (element.id, element))
|
||||
.collect();
|
||||
expected.relations.insert(
|
||||
id(4),
|
||||
Relation {
|
||||
id: id(4),
|
||||
alias: "flow".into(),
|
||||
name: "Flow".into(),
|
||||
description: String::new(),
|
||||
body: RelationBody::Interaction {
|
||||
source: id(2),
|
||||
target: id(3),
|
||||
items: vec![],
|
||||
},
|
||||
},
|
||||
);
|
||||
expected
|
||||
}
|
||||
|
||||
fn node_project() -> Project {
|
||||
let mut expected = project();
|
||||
expected.elements.insert(
|
||||
id(2),
|
||||
element(2, "work", "Work", None, ElementBody::Oa(OaBody::Activity)),
|
||||
);
|
||||
expected.diagrams.insert(
|
||||
id(3),
|
||||
Diagram {
|
||||
id: id(3),
|
||||
alias: "view".into(),
|
||||
name: "View".into(),
|
||||
description: String::new(),
|
||||
layer: Layer::Oa,
|
||||
projection: ProjectionKind::Overview,
|
||||
view_options: view_options::ViewOptions {
|
||||
hidden_edges: vec![],
|
||||
relation_kinds: view_options::RelationKinds::All,
|
||||
work_categories: view_options::CategorySelection::All,
|
||||
participant_categories: view_options::CategorySelection::All,
|
||||
coverage: view_options::Coverage::All,
|
||||
work_contexts: view_options::ContextSelection::All,
|
||||
exchange_labels: view_options::ExchangeLabels::Name,
|
||||
},
|
||||
nodes: BTreeMap::from([(
|
||||
id(4),
|
||||
NodePlacement {
|
||||
id: id(4),
|
||||
alias: "placement".into(),
|
||||
element: id(2),
|
||||
position: Position { x: 12.5, y: -4.0 },
|
||||
size: Size {
|
||||
width: 224.0,
|
||||
height: 94.0,
|
||||
},
|
||||
collapsed: false,
|
||||
port_anchors: vec![],
|
||||
},
|
||||
)]),
|
||||
routes: vec![],
|
||||
},
|
||||
);
|
||||
expected
|
||||
}
|
||||
|
||||
fn trace_project() -> Project {
|
||||
let mut expected = project();
|
||||
expected.elements = [
|
||||
element(2, "work", "Work", None, ElementBody::Oa(OaBody::Activity)),
|
||||
element(
|
||||
3,
|
||||
"function",
|
||||
"Function",
|
||||
None,
|
||||
ElementBody::Sa(SaBody::Function),
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|element| (element.id, element))
|
||||
.collect();
|
||||
expected.traces.insert(
|
||||
id(4),
|
||||
Trace {
|
||||
id: id(4),
|
||||
alias: "mapping".into(),
|
||||
name: "Mapping".into(),
|
||||
description: String::new(),
|
||||
oa: id(2),
|
||||
sa: id(3),
|
||||
kind: TraceKind::Manual,
|
||||
baseline: Some(TraceBaseline {
|
||||
oa: TracedProperties {
|
||||
name: "Work".into(),
|
||||
description: "Old OA snapshot".into(),
|
||||
},
|
||||
sa: TracedProperties {
|
||||
name: "Function".into(),
|
||||
description: "Old SA snapshot".into(),
|
||||
},
|
||||
semantic: None,
|
||||
}),
|
||||
},
|
||||
);
|
||||
expected
|
||||
}
|
||||
|
||||
fn checked_fixture(source: &str, expected: &Project) -> CompiledSourceProject {
|
||||
let input = source_bundle(source);
|
||||
let compiled = compile_bundle(&input, ProjectLimits::default()).unwrap();
|
||||
assert_eq!(
|
||||
compiled.decoded.project, *expected,
|
||||
"fixture model admission"
|
||||
);
|
||||
assert_eq!(
|
||||
compiled.bundle, input,
|
||||
"fixed IDs must avoid stabilization edits"
|
||||
);
|
||||
compiled
|
||||
}
|
||||
|
||||
fn replacement(source: &str, before: &str, after: &str) -> String {
|
||||
assert_eq!(
|
||||
source.matches(before).count(),
|
||||
1,
|
||||
"unique authored edit token"
|
||||
);
|
||||
source.replacen(before, after, 1)
|
||||
}
|
||||
|
||||
fn assert_preserved_update(
|
||||
original: &CompiledSourceProject,
|
||||
expected: &Project,
|
||||
expected_source: &str,
|
||||
) {
|
||||
// Independently admit the exact expected spelling before testing the updater.
|
||||
let expected_bundle = source_bundle(expected_source);
|
||||
let authored = compile_bundle(&expected_bundle, ProjectLimits::default()).unwrap();
|
||||
assert_eq!(
|
||||
authored.decoded.project, *expected,
|
||||
"expected source/model agree"
|
||||
);
|
||||
assert_eq!(
|
||||
authored.bundle, expected_bundle,
|
||||
"expected source is already stable"
|
||||
);
|
||||
|
||||
let updated = update_bundle(original, expected, ProjectLimits::default()).unwrap();
|
||||
assert_eq!(
|
||||
updated.decoded.project, *expected,
|
||||
"entire intended model survives"
|
||||
);
|
||||
assert_eq!(
|
||||
updated.bundle, expected_bundle,
|
||||
"only the requested token may change; preserve explicit defaults and all trivia"
|
||||
);
|
||||
}
|
||||
|
||||
// Context changes may introduce/remove redundant default syntax. Admit each
|
||||
// narrowly enumerated spelling against the same literal target model, and then
|
||||
// compare complete source bundles. No normalization may mask edits to unrelated
|
||||
// fields, declarations, whitespace, or comments.
|
||||
fn assert_context_update(
|
||||
original: &CompiledSourceProject,
|
||||
expected: &Project,
|
||||
allowed_sources: &[String],
|
||||
) {
|
||||
let allowed: Vec<_> = allowed_sources
|
||||
.iter()
|
||||
.map(|source| {
|
||||
let bundle = source_bundle(source);
|
||||
let authored = compile_bundle(&bundle, ProjectLimits::default()).unwrap();
|
||||
assert_eq!(
|
||||
authored.decoded.project, *expected,
|
||||
"allowed source/model agree"
|
||||
);
|
||||
assert_eq!(authored.bundle, bundle, "allowed source is already stable");
|
||||
bundle
|
||||
})
|
||||
.collect();
|
||||
let updated = update_bundle(original, expected, ProjectLimits::default()).unwrap();
|
||||
assert_eq!(
|
||||
updated.decoded.project, *expected,
|
||||
"entire context-change model survives"
|
||||
);
|
||||
assert!(
|
||||
allowed.contains(&updated.bundle),
|
||||
"preserve unchanged source exactly; only listed changed/default syntax alternatives are allowed\nactual: {:?}\nallowed: {:?}",
|
||||
updated.bundle,
|
||||
allowed
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicit_exchange_operation_none_survives_noop() {
|
||||
let expected = exchange_project();
|
||||
let original = checked_fixture(EXCHANGE_SOURCE, &expected);
|
||||
assert_preserved_update(&original, &expected, EXCHANGE_SOURCE);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicit_exchange_operation_none_survives_header_rename() {
|
||||
let mut expected = exchange_project();
|
||||
let original = checked_fixture(EXCHANGE_SOURCE, &expected);
|
||||
expected.elements.get_mut(&id(6)).unwrap().name = "Renamed subject".into();
|
||||
let source = replacement(EXCHANGE_SOURCE, "\"Subject\"", "\"Renamed subject\"");
|
||||
assert_preserved_update(&original, &expected, &source);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicit_exchange_operation_none_survives_exchange_binding_edit() {
|
||||
let mut expected = exchange_project();
|
||||
let original = checked_fixture(EXCHANGE_SOURCE, &expected);
|
||||
let Some(SharedBody::Occurrence {
|
||||
body: OccurrenceBody::Exchange { exchange, .. },
|
||||
..
|
||||
}) = expected.elements.get_mut(&id(6)).unwrap().body.shared_mut()
|
||||
else {
|
||||
panic!("literal fixture must be an Exchange occurrence");
|
||||
};
|
||||
*exchange = Some(id(4));
|
||||
let source = replacement(EXCHANGE_SOURCE, "exchange none;", "exchange @flow;");
|
||||
assert_preserved_update(&original, &expected, &source);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicit_node_empty_port_anchors_survive_noop() {
|
||||
let expected = node_project();
|
||||
let original = checked_fixture(NODE_SOURCE, &expected);
|
||||
assert_preserved_update(&original, &expected, NODE_SOURCE);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicit_node_empty_port_anchors_survive_header_alias_rename() {
|
||||
let mut expected = node_project();
|
||||
let original = checked_fixture(NODE_SOURCE, &expected);
|
||||
// Nodes have no display-name header. Rename the same node's header alias.
|
||||
expected
|
||||
.diagrams
|
||||
.get_mut(&id(3))
|
||||
.unwrap()
|
||||
.nodes
|
||||
.get_mut(&id(4))
|
||||
.unwrap()
|
||||
.alias = "renamed_placement".into();
|
||||
let source = replacement(
|
||||
NODE_SOURCE,
|
||||
"node placement id",
|
||||
"node renamed_placement id",
|
||||
);
|
||||
assert_preserved_update(&original, &expected, &source);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicit_node_empty_port_anchors_survive_position_edit() {
|
||||
let mut expected = node_project();
|
||||
let original = checked_fixture(NODE_SOURCE, &expected);
|
||||
expected
|
||||
.diagrams
|
||||
.get_mut(&id(3))
|
||||
.unwrap()
|
||||
.nodes
|
||||
.get_mut(&id(4))
|
||||
.unwrap()
|
||||
.position
|
||||
.x = 25.0;
|
||||
let source = replacement(NODE_SOURCE, "x 12.5;", "x 25.0;");
|
||||
assert_preserved_update(&original, &expected, &source);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicit_trace_semantic_none_survives_noop() {
|
||||
let expected = trace_project();
|
||||
let original = checked_fixture(TRACE_SOURCE, &expected);
|
||||
assert_preserved_update(&original, &expected, TRACE_SOURCE);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicit_trace_semantic_none_survives_header_rename() {
|
||||
let mut expected = trace_project();
|
||||
let original = checked_fixture(TRACE_SOURCE, &expected);
|
||||
expected.traces.get_mut(&id(4)).unwrap().name = "Renamed mapping".into();
|
||||
let source = replacement(TRACE_SOURCE, "\"Mapping\"", "\"Renamed mapping\"");
|
||||
assert_preserved_update(&original, &expected, &source);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicit_trace_semantic_none_survives_snapshot_prose_edit() {
|
||||
let mut expected = trace_project();
|
||||
let original = checked_fixture(TRACE_SOURCE, &expected);
|
||||
expected
|
||||
.traces
|
||||
.get_mut(&id(4))
|
||||
.unwrap()
|
||||
.baseline
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.oa
|
||||
.description = "Revised OA snapshot".into();
|
||||
let source = replacement(
|
||||
TRACE_SOURCE,
|
||||
"\"Old OA snapshot\"",
|
||||
"\"Revised OA snapshot\"",
|
||||
);
|
||||
assert_preserved_update(&original, &expected, &source);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn constructor_change_removes_inapplicable_default_and_keeps_shared_default() {
|
||||
let mut expected = project();
|
||||
expected.elements = [
|
||||
element(
|
||||
2,
|
||||
"owner",
|
||||
"Owner",
|
||||
None,
|
||||
ElementBody::Oa(OaBody::Shared(SharedBody::Scenario {
|
||||
viewpoint: ScenarioViewpoint::MixedLegacy,
|
||||
context: None,
|
||||
precondition: String::new(),
|
||||
postcondition: String::new(),
|
||||
steps: vec![id(3)],
|
||||
})),
|
||||
),
|
||||
element(
|
||||
3,
|
||||
"subject",
|
||||
"Subject",
|
||||
Some(id(2)),
|
||||
ElementBody::Oa(OaBody::Shared(SharedBody::Occurrence {
|
||||
body: OccurrenceBody::Action {
|
||||
action: None,
|
||||
lifeline: None,
|
||||
},
|
||||
precondition: String::new(),
|
||||
postcondition: String::new(),
|
||||
})),
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|element| (element.id, element))
|
||||
.collect();
|
||||
let original = checked_fixture(CONSTRUCTOR_SOURCE, &expected);
|
||||
expected.elements.get_mut(&id(3)).unwrap().body =
|
||||
ElementBody::Oa(OaBody::Shared(SharedBody::Occurrence {
|
||||
body: OccurrenceBody::State {
|
||||
state: None,
|
||||
lifeline: None,
|
||||
},
|
||||
precondition: String::new(),
|
||||
postcondition: String::new(),
|
||||
}));
|
||||
// Remove only the inapplicable field's syntax: its separating space and all
|
||||
// surrounding trivia stay. The shared lifeline spelling/comment is exact.
|
||||
let source = replacement(CONSTRUCTOR_SOURCE, "body { Action {", "body { State {");
|
||||
let compact = replacement(&source, "action none;", " ");
|
||||
let expanded = replacement(
|
||||
&compact,
|
||||
" }; };",
|
||||
" state none;\n }; };",
|
||||
);
|
||||
// Omission of newly applicable state and explicit state none both mean the
|
||||
// literal State target; neither may retain the old action field.
|
||||
assert_context_update(&original, &expected, &[compact, expanded]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn relation_kind_change_updates_explicit_value_when_context_default_changes() {
|
||||
let mut expected = project();
|
||||
expected.elements = [
|
||||
element(2, "first", "First", None, ElementBody::Oa(OaBody::Entity)),
|
||||
element(3, "second", "Second", None, ElementBody::Oa(OaBody::Entity)),
|
||||
element(
|
||||
5,
|
||||
"output",
|
||||
"Output",
|
||||
Some(id(2)),
|
||||
ElementBody::Oa(OaBody::Shared(SharedBody::Port {
|
||||
contract: PortContract::Legacy,
|
||||
legacy: Some(LegacyPortContract {
|
||||
direction: PortDirection::Out,
|
||||
interface: None,
|
||||
}),
|
||||
})),
|
||||
),
|
||||
element(
|
||||
6,
|
||||
"input",
|
||||
"Input",
|
||||
Some(id(3)),
|
||||
ElementBody::Oa(OaBody::Shared(SharedBody::Port {
|
||||
contract: PortContract::Legacy,
|
||||
legacy: Some(LegacyPortContract {
|
||||
direction: PortDirection::In,
|
||||
interface: None,
|
||||
}),
|
||||
})),
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|element| (element.id, element))
|
||||
.collect();
|
||||
expected.relations.insert(
|
||||
id(4),
|
||||
Relation {
|
||||
id: id(4),
|
||||
alias: "link".into(),
|
||||
name: "Link".into(),
|
||||
description: String::new(),
|
||||
body: RelationBody::BoundaryExchange {
|
||||
source: id(5),
|
||||
target: id(6),
|
||||
oriented: true,
|
||||
items: vec![],
|
||||
},
|
||||
},
|
||||
);
|
||||
let original = checked_fixture(RELATION_CONTEXT_SOURCE, &expected);
|
||||
// BoundaryExchange connects participant ports; CommunicationMean connects
|
||||
// their OA entity owners. Endpoint changes are explicit parts of this target,
|
||||
// not inferred or normalized away. Port records remain exactly unchanged.
|
||||
expected.relations.get_mut(&id(4)).unwrap().body = RelationBody::CommunicationMean {
|
||||
source: id(2),
|
||||
target: id(3),
|
||||
oriented: false,
|
||||
items: vec![],
|
||||
};
|
||||
let source = replacement(
|
||||
RELATION_CONTEXT_SOURCE,
|
||||
"boundary_exchange link",
|
||||
"communication_mean link",
|
||||
);
|
||||
let source = replacement(&source, "source @output;", "source @first;");
|
||||
let source = replacement(&source, "target @input;", "target @second;");
|
||||
let explicit = replacement(&source, "oriented true ;", "oriented false ;");
|
||||
// Three spaces between name/value plus one before the semicolon survive
|
||||
// syntax removal. The following rationale comment and all other bytes stay.
|
||||
let omitted = replacement(&source, "oriented true ;", " ");
|
||||
assert_context_update(&original, &expected, &[explicit, omitted]);
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
//! Public update witnesses for compact insertion and complete comparison.
|
||||
use oa_core::{language, source_project::*, *};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
fn compile(body: &str) -> CompiledSourceProject {
|
||||
compile_bundle(
|
||||
&SourceBundle {
|
||||
entry: "project.arcadia".into(),
|
||||
files: BTreeMap::from([
|
||||
(
|
||||
"project.arcadia".into(),
|
||||
"arcadia 7; project p \"P\" { include \"model.arcadia\"; }".into(),
|
||||
),
|
||||
("model.arcadia".into(), body.into()),
|
||||
]),
|
||||
},
|
||||
ProjectLimits::default(),
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
fn id(project: &Project, alias: &str) -> Id {
|
||||
project
|
||||
.identities()
|
||||
.into_iter()
|
||||
.find(|(_, a)| *a == alias)
|
||||
.unwrap()
|
||||
.0
|
||||
}
|
||||
fn update(before: &CompiledSourceProject, project: &Project) -> CompiledSourceProject {
|
||||
let result = update_bundle(before, project, ProjectLimits::default()).unwrap();
|
||||
assert_eq!(result.decoded.project, *project);
|
||||
assert_eq!(
|
||||
result.bundle.files["project.arcadia"],
|
||||
before.bundle.files["project.arcadia"]
|
||||
);
|
||||
assert_eq!(
|
||||
compile_bundle(&result.bundle, ProjectLimits::default())
|
||||
.unwrap()
|
||||
.bundle,
|
||||
result.bundle
|
||||
);
|
||||
assert_eq!(
|
||||
update_bundle(&result, project, ProjectLimits::default())
|
||||
.unwrap()
|
||||
.bundle,
|
||||
result.bundle
|
||||
);
|
||||
result
|
||||
}
|
||||
fn words(text: &str) -> Vec<&str> {
|
||||
language::tokenize(text)
|
||||
.into_iter()
|
||||
.filter(|t| {
|
||||
!matches!(
|
||||
t.class,
|
||||
language::TokenClass::Whitespace | language::TokenClass::Comment
|
||||
)
|
||||
})
|
||||
.map(|t| &text[t.span.start..t.span.end])
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn omitted_exchange_body_changes_to_one_compact_action_constructor() {
|
||||
let before = compile(
|
||||
"oa_scenario s \"S\" { steps [@o]; }\noa_occurrence o \"O\" { parent @s; // keep this\n}\n",
|
||||
);
|
||||
let mut project = before.decoded.project.clone();
|
||||
let occurrence = id(&project, "o");
|
||||
let Some(SharedBody::Occurrence { body, .. }) =
|
||||
project.elements.get_mut(&occurrence).unwrap().shared_mut()
|
||||
else {
|
||||
panic!("occurrence")
|
||||
};
|
||||
assert!(matches!(body, OccurrenceBody::Exchange { .. }));
|
||||
*body = OccurrenceBody::Action {
|
||||
action: None,
|
||||
lifeline: None,
|
||||
};
|
||||
let result = update(&before, &project);
|
||||
let text = &result.bundle.files["model.arcadia"];
|
||||
let tokens = words(text);
|
||||
assert_eq!(tokens.iter().filter(|&&t| t == "body").count(), 1);
|
||||
assert!(tokens.contains(&"Action"));
|
||||
for absent in ["Exchange", "action", "lifeline", "operation", "description"] {
|
||||
assert!(!tokens.contains(&absent), "{absent}: {text}");
|
||||
}
|
||||
assert!(text.contains("parent @s; // keep this"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_signal_constructor_still_inserts_its_required_empty_items() {
|
||||
let before =
|
||||
compile("oa_event e \"E\" { body { Time { expression \"1 s\"; kind After; }; }; }\n");
|
||||
let mut project = before.decoded.project.clone();
|
||||
let event = id(&project, "e");
|
||||
let Some(SharedBody::Event { body }) = project.elements.get_mut(&event).unwrap().shared_mut()
|
||||
else {
|
||||
panic!("event")
|
||||
};
|
||||
*body = EventBody::Signal { items: vec![] };
|
||||
let result = update(&before, &project);
|
||||
let tokens = words(&result.bundle.files["model.arcadia"]);
|
||||
assert!(tokens.contains(&"Signal"));
|
||||
assert!(tokens.windows(4).any(|w| w == ["items", "[", "]", ";"]));
|
||||
assert!(!tokens.contains(&"expression"));
|
||||
assert!(!tokens.contains(&"kind"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scalar_to_default_string_record_retains_required_minimum_only() {
|
||||
let before = compile("oa_data_type t \"T\" { definition Boolean; // typed rationale\n}\n");
|
||||
let mut project = before.decoded.project.clone();
|
||||
let datatype = id(&project, "t");
|
||||
let Some(SharedBody::DataType { definition, .. }) =
|
||||
project.elements.get_mut(&datatype).unwrap().shared_mut()
|
||||
else {
|
||||
panic!("data type")
|
||||
};
|
||||
*definition = DataTypeDefinition::String {
|
||||
minimum_length: 0,
|
||||
maximum_length: None,
|
||||
};
|
||||
let result = update(&before, &project);
|
||||
let text = &result.bundle.files["model.arcadia"];
|
||||
let tokens = words(text);
|
||||
assert!(tokens.contains(&"String"));
|
||||
assert!(tokens.windows(3).any(|w| w == ["minimum_length", "0", ";"]));
|
||||
assert!(!tokens.contains(&"maximum_length"));
|
||||
assert!(text.contains("// typed rationale"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inserted_route_list_item_omits_only_optional_fields() {
|
||||
let before = compile(
|
||||
"oa_activity a \"A\" {}\noa_activity b \"B\" {}\ninteraction flow \"Flow\" { source @a; target @b; }\ndiagram d \"D\" { routes []; // routing rationale\n}\n",
|
||||
);
|
||||
let mut project = before.decoded.project.clone();
|
||||
let diagram = id(&project, "d");
|
||||
let edge = id(&project, "flow");
|
||||
// Deserialize only the explicit witness value, independently of omission policy.
|
||||
project.diagrams.get_mut(&diagram).unwrap().routes =
|
||||
serde_json::from_value(serde_json::json!([{"edge":edge,"waypoints":[],"label":null}]))
|
||||
.unwrap();
|
||||
let result = update(&before, &project);
|
||||
let text = &result.bundle.files["model.arcadia"];
|
||||
let tokens = words(text);
|
||||
assert!(tokens.windows(4).any(|w| w == ["edge", "@", "flow", ";"]));
|
||||
assert!(!tokens.contains(&"waypoints"));
|
||||
assert!(!tokens.contains(&"label"));
|
||||
assert!(text.contains("// routing rationale"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zero_sign_change_inserts_position_without_default_siblings() {
|
||||
let before = compile(
|
||||
"oa_activity a \"A\" {}\ndiagram d \"D\" {}\nnode n { diagram @d; element @a; // placement rationale\n}\n",
|
||||
);
|
||||
let mut project = before.decoded.project.clone();
|
||||
let diagram = id(&project, "d");
|
||||
let node = id(&project, "n");
|
||||
assert_eq!(
|
||||
project.diagrams[&diagram].nodes[&node].position.x.to_bits(),
|
||||
0.0_f32.to_bits()
|
||||
);
|
||||
project
|
||||
.diagrams
|
||||
.get_mut(&diagram)
|
||||
.unwrap()
|
||||
.nodes
|
||||
.get_mut(&node)
|
||||
.unwrap()
|
||||
.position
|
||||
.x = -0.0;
|
||||
let result = update(&before, &project);
|
||||
assert_eq!(
|
||||
result.decoded.project.diagrams[&diagram].nodes[&node]
|
||||
.position
|
||||
.x
|
||||
.to_bits(),
|
||||
(-0.0_f32).to_bits()
|
||||
);
|
||||
let text = &result.bundle.files["model.arcadia"];
|
||||
let tokens = words(text);
|
||||
assert!(tokens.windows(3).any(|w| w == ["x", "-0.0", ";"]));
|
||||
for absent in ["size", "collapsed", "port_anchors"] {
|
||||
assert!(!tokens.contains(&absent));
|
||||
}
|
||||
assert!(text.contains("// placement rationale"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn kind_change_materializes_unchanged_value_when_its_old_omission_default_changes() {
|
||||
let before = compile(
|
||||
"oa_entity a \"A\" {}\noa_entity b \"B\" {}\noa_port out \"Out\" { parent @a; contract Legacy; legacy { direction Out; }; }\noa_port input \"In\" { parent @b; contract Legacy; legacy { direction In; }; }\nboundary_exchange flow \"Flow\" { source @out; target @input; // orientation inherited\n}\n",
|
||||
);
|
||||
let mut project = before.decoded.project.clone();
|
||||
let flow = id(&project, "flow");
|
||||
assert!(matches!(
|
||||
project.relations[&flow].body,
|
||||
RelationBody::BoundaryExchange { oriented: true, .. }
|
||||
));
|
||||
project.relations.get_mut(&flow).unwrap().body = RelationBody::CommunicationMean {
|
||||
source: id(&before.decoded.project, "a"),
|
||||
target: id(&before.decoded.project, "b"),
|
||||
oriented: true,
|
||||
items: vec![],
|
||||
};
|
||||
let result = update(&before, &project);
|
||||
let text = &result.bundle.files["model.arcadia"];
|
||||
assert!(
|
||||
words(text)
|
||||
.windows(3)
|
||||
.any(|w| w == ["oriented", "true", ";"])
|
||||
);
|
||||
assert!(text.contains("// orientation inherited"));
|
||||
let before_ports = &before.bundle.files["model.arcadia"];
|
||||
assert_eq!(
|
||||
text.split("communication_mean").next().unwrap(),
|
||||
before_ports.split("boundary_exchange").next().unwrap()
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,290 @@
|
||||
use oa_core::{language, persistence, source_project::*, *};
|
||||
use serde_json::{Value, json};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
const SOURCE: &str = r#"arcadia 7;
|
||||
project attachments "Connection ends" id "70000000-0000-4000-8000-000000000001" {
|
||||
oa_activity first "First" id "70000000-0000-4000-8000-000000000002" {}
|
||||
oa_activity second "Second" id "70000000-0000-4000-8000-000000000003" {}
|
||||
interaction signal "Signal" id "70000000-0000-4000-8000-000000000004" { source @first; target @second; }
|
||||
diagram view "View" id "70000000-0000-4000-8000-000000000005" {
|
||||
routes [{ edge @signal; waypoints [{ x 120; y 80; }];
|
||||
label { fraction 0.5; offset { x 3; y -7; }; };
|
||||
source_attachment { side Left; offset 0.25; };
|
||||
target_attachment { side Bottom; offset 1; };
|
||||
}];
|
||||
}
|
||||
diagram other "Other" id "70000000-0000-4000-8000-000000000006" { routes [{ edge @signal; }]; }
|
||||
}
|
||||
"#;
|
||||
|
||||
fn id(project: &Project, alias: &str) -> Id {
|
||||
project
|
||||
.identities()
|
||||
.into_iter()
|
||||
.find(|(_, a)| *a == alias)
|
||||
.unwrap()
|
||||
.0
|
||||
}
|
||||
|
||||
fn original() -> Project {
|
||||
language::parse(SOURCE).unwrap()
|
||||
}
|
||||
|
||||
fn set(diagram: Id, route: EdgeRoute) -> Command {
|
||||
Command::SetEdgeRoute { diagram, route }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn edge_attachments_roundtrip_source_json_bundle_and_automatic_defaults() {
|
||||
let project = original();
|
||||
let view = id(&project, "view");
|
||||
let route = &project.diagrams[&view].routes[0];
|
||||
assert_eq!(
|
||||
route.source_attachment,
|
||||
Some(EdgeAttachment {
|
||||
side: PortAnchorSide::Left,
|
||||
offset: 0.25
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
route.target_attachment,
|
||||
Some(EdgeAttachment {
|
||||
side: PortAnchorSide::Bottom,
|
||||
offset: 1.0
|
||||
})
|
||||
);
|
||||
for text in [SOURCE.to_owned(), language::format(&project)] {
|
||||
assert_eq!(language::parse(&text).unwrap(), project);
|
||||
}
|
||||
assert_eq!(
|
||||
persistence::decode(&serde_json::to_vec(&project).unwrap()).unwrap(),
|
||||
project
|
||||
);
|
||||
assert_eq!(
|
||||
compile_bundle(&format_bundle(&project), ProjectLimits::default())
|
||||
.unwrap()
|
||||
.decoded
|
||||
.project,
|
||||
project
|
||||
);
|
||||
|
||||
let automatic = &project.diagrams[&id(&project, "other")].routes[0];
|
||||
assert_eq!(automatic.source_attachment, None);
|
||||
assert_eq!(automatic.target_attachment, None);
|
||||
let encoded = serde_json::to_value(automatic).unwrap();
|
||||
assert!(encoded.get("source_attachment").is_none());
|
||||
assert!(encoded.get("target_attachment").is_none());
|
||||
let mut with_null = encoded.clone();
|
||||
with_null["source_attachment"] = Value::Null;
|
||||
with_null["target_attachment"] = Value::Null;
|
||||
assert_eq!(
|
||||
serde_json::from_value::<EdgeRoute>(with_null).unwrap(),
|
||||
*automatic
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::from_value::<EdgeRoute>(encoded).unwrap(),
|
||||
*automatic
|
||||
);
|
||||
|
||||
// Old source without either new field still means automatic presentation.
|
||||
let old = SOURCE
|
||||
.replace(" source_attachment { side Left; offset 0.25; };\n", "")
|
||||
.replace(" target_attachment { side Bottom; offset 1; };\n", "");
|
||||
let old = language::parse(&old).unwrap();
|
||||
assert!(
|
||||
old.diagrams
|
||||
.values()
|
||||
.flat_map(|d| &d.routes)
|
||||
.all(|r| r.source_attachment.is_none() && r.target_attachment.is_none())
|
||||
);
|
||||
assert!(!language::format(&old).contains("_attachment"));
|
||||
assert_eq!(
|
||||
persistence::decode(&serde_json::to_vec(&old).unwrap()).unwrap(),
|
||||
old
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn edge_attachments_reject_malformed_nested_source_and_json_without_defaults() {
|
||||
let project = original();
|
||||
let edge = id(&project, "signal");
|
||||
for bad in [
|
||||
json!({}),
|
||||
json!({"side":"Top"}),
|
||||
json!({"offset":0.5}),
|
||||
json!({"side":"Diagonal","offset":0.5}),
|
||||
json!({"side":"Top","offset":null}),
|
||||
json!({"side":"Top","offset":0.5,"unknown":true}),
|
||||
json!({"side":"Top","offset":"NaN"}),
|
||||
] {
|
||||
for field in ["source_attachment", "target_attachment"] {
|
||||
let mut route = json!({"edge":edge});
|
||||
route[field] = bad.clone();
|
||||
assert!(
|
||||
serde_json::from_value::<EdgeRoute>(route).is_err(),
|
||||
"{field}: {bad}"
|
||||
);
|
||||
}
|
||||
}
|
||||
for bad in [
|
||||
"{}",
|
||||
"{ side Top; }",
|
||||
"{ offset 0.5; }",
|
||||
"{ side Diagonal; offset 0.5; }",
|
||||
"{ side Top; offset null; }",
|
||||
"{ side Top; offset 0.5; unknown true; }",
|
||||
"{ side Top; offset -0.01; }",
|
||||
"{ side Top; offset 1.01; }",
|
||||
"{ side Top; offset NaN; }",
|
||||
"{ side Top; offset 1e999; }",
|
||||
] {
|
||||
let source = SOURCE.replace("{ side Left; offset 0.25; }", bad);
|
||||
assert!(language::parse(&source).is_err(), "{bad}");
|
||||
let bundle = SourceBundle {
|
||||
entry: "p.arcadia".into(),
|
||||
files: BTreeMap::from([("p.arcadia".into(), source)]),
|
||||
};
|
||||
assert!(
|
||||
compile_bundle(&bundle, ProjectLimits::default()).is_err(),
|
||||
"{bad}"
|
||||
);
|
||||
}
|
||||
for version in [1, 2] {
|
||||
let legacy =
|
||||
format!("arcadia {version}; project p \"P\" {{ diagram v \"V\" {{ routes []; }} }}");
|
||||
assert!(
|
||||
language::parse(&legacy).is_err(),
|
||||
"legacy route extension must not be silently admitted"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn edge_attachments_nonfinite_and_out_of_range_commands_reject_atomically() {
|
||||
let project = original();
|
||||
let view = id(&project, "view");
|
||||
let first = id(&project, "first");
|
||||
for offset in [f32::NAN, f32::INFINITY, f32::NEG_INFINITY, -0.01, 1.01] {
|
||||
for end in [EdgeEnd::Source, EdgeEnd::Target] {
|
||||
let mut route = project.diagrams[&view].routes[0].clone();
|
||||
route.set_attachment(
|
||||
end,
|
||||
Some(EdgeAttachment {
|
||||
side: PortAnchorSide::Top,
|
||||
offset,
|
||||
}),
|
||||
);
|
||||
let mut session = Session::new(project.clone());
|
||||
assert!(
|
||||
session
|
||||
.execute(Command::Batch(vec![
|
||||
Command::Rename(first, "Must roll back".into()),
|
||||
set(view, route)
|
||||
]))
|
||||
.is_err()
|
||||
);
|
||||
assert_eq!(session.project(), &project);
|
||||
assert!(!session.can_undo() && !session.can_redo());
|
||||
}
|
||||
}
|
||||
for offset in [-0.01, 1.01] {
|
||||
let mut value = serde_json::to_value(&project).unwrap();
|
||||
value["diagrams"][view.to_string()]["routes"][0]["source_attachment"]["offset"] =
|
||||
json!(offset);
|
||||
assert!(persistence::decode(&serde_json::to_vec(&value).unwrap()).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn edge_attachments_reset_one_end_and_all_routing_have_exact_history_and_view_scope() {
|
||||
let project = original();
|
||||
let view = id(&project, "view");
|
||||
let edge = id(&project, "signal");
|
||||
let mut session = Session::new(project.clone());
|
||||
let mut route = project.diagrams[&view].routes[0].clone();
|
||||
route.source_attachment = Some(EdgeAttachment {
|
||||
side: PortAnchorSide::Right,
|
||||
offset: 0.75,
|
||||
});
|
||||
let command = set(view, route.clone());
|
||||
assert_eq!(
|
||||
serde_json::from_value::<Command>(serde_json::to_value(&command).unwrap()).unwrap(),
|
||||
command
|
||||
);
|
||||
session.execute(command).unwrap();
|
||||
let mut expected = project.clone();
|
||||
expected.diagrams.get_mut(&view).unwrap().routes[0] = route.clone();
|
||||
assert_eq!(
|
||||
session.project(),
|
||||
&expected,
|
||||
"only this view/end changes; semantic fields and other view stay exact"
|
||||
);
|
||||
session.undo();
|
||||
assert_eq!(session.project(), &project);
|
||||
assert!(!session.can_undo() && session.can_redo());
|
||||
session.redo();
|
||||
assert_eq!(session.project(), &expected);
|
||||
route.source_attachment = None;
|
||||
session.execute(set(view, route.clone())).unwrap();
|
||||
let mut reset = expected.clone();
|
||||
reset.diagrams.get_mut(&view).unwrap().routes[0] = route;
|
||||
assert_eq!(
|
||||
session.project(),
|
||||
&reset,
|
||||
"opposite attachment, pins and label survive endpoint reset"
|
||||
);
|
||||
session.undo();
|
||||
assert_eq!(session.project(), &expected);
|
||||
session
|
||||
.execute(Command::RemoveEdgeRoute {
|
||||
diagram: view,
|
||||
edge,
|
||||
})
|
||||
.unwrap();
|
||||
let mut removed = expected.clone();
|
||||
removed.diagrams.get_mut(&view).unwrap().routes.clear();
|
||||
assert_eq!(session.project(), &removed);
|
||||
session.undo();
|
||||
assert_eq!(session.project(), &expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn edge_attachments_nested_writeback_preserves_comments_adjacent_tokens_and_other_files() {
|
||||
let current = compile_bundle(&SourceBundle {
|
||||
entry: "p.arcadia".into(),
|
||||
files: BTreeMap::from([
|
||||
("p.arcadia".into(), "// project rationale\narcadia 7; project p \"P\" { include \"model.arcadia\"; include \"views.arcadia\"; }\n".into()),
|
||||
("model.arcadia".into(), "// untouched semantic ownership\noa_activity a \"A\" {}\noa_activity b \"B\" {}\ninteraction signal \"Signal\" { source @a; target @b; }\n".into()),
|
||||
("views.arcadia".into(), "// view rationale\r\ndiagram view \"View\" {\r\n routes [ { edge @signal; // endpoint explanation\r\n source_attachment { side Left; offset 0.25 ; // exact nested rationale\r\n }; target_attachment { side Bottom; offset 1; };\r\n waypoints [{ x 120; y 80; }]; label { fraction 0.5; offset { x 3; y -7; }; }; } ];\r\n}\r\ndiagram other \"Other\" { routes [{ edge @signal; }]; } // adjacent view\r\n".into()),
|
||||
]),
|
||||
}, ProjectLimits::default()).unwrap();
|
||||
let mut project = current.decoded.project.clone();
|
||||
let view = id(&project, "view");
|
||||
project.diagrams.get_mut(&view).unwrap().routes[0]
|
||||
.source_attachment
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.offset = 0.375;
|
||||
let changed = update_bundle(¤t, &project, ProjectLimits::default()).unwrap();
|
||||
assert_eq!(changed.decoded.project, project);
|
||||
for path in ["p.arcadia", "model.arcadia"] {
|
||||
assert_eq!(changed.bundle.files[path], current.bundle.files[path]);
|
||||
}
|
||||
assert_eq!(
|
||||
changed.bundle.files["views.arcadia"],
|
||||
current.bundle.files["views.arcadia"].replace("offset 0.25 ;", "offset 0.375 ;")
|
||||
);
|
||||
assert_eq!(
|
||||
compile_bundle(&changed.bundle, ProjectLimits::default())
|
||||
.unwrap()
|
||||
.bundle,
|
||||
changed.bundle
|
||||
);
|
||||
assert_eq!(
|
||||
update_bundle(&changed, &project, ProjectLimits::default())
|
||||
.unwrap()
|
||||
.bundle,
|
||||
changed.bundle
|
||||
);
|
||||
}
|
||||
@@ -3,6 +3,16 @@ use oa_core::{language, persistence, validation, *};
|
||||
fn read(source: &str) -> Project {
|
||||
language::parse(source).unwrap_or_else(|e| panic!("{e:?}\n{source}"))
|
||||
}
|
||||
fn replace_once(source: &str, before: &str, after: &str) -> String {
|
||||
assert_eq!(
|
||||
source.matches(before).count(),
|
||||
1,
|
||||
"unique mutation anchor {before:?}"
|
||||
);
|
||||
let changed = source.replacen(before, after, 1);
|
||||
assert_ne!(changed, source, "test mutation must change the source");
|
||||
changed
|
||||
}
|
||||
fn rejected(source: &str, fragment: &str) {
|
||||
let errors = language::parse(source).expect_err(source);
|
||||
assert!(
|
||||
@@ -753,8 +763,8 @@ fn typed_events_vertices_and_transition_kinds_round_trip_in_both_layers() {
|
||||
source.push('}');
|
||||
let model = read(&source);
|
||||
let canonical = language::format(&model);
|
||||
assert!(!canonical.contains("transition_kind External;"));
|
||||
for fragment in [
|
||||
"transition_kind External;",
|
||||
"transition_kind Local;",
|
||||
"transition_kind Internal;",
|
||||
"triggers [@deadline, @assess];",
|
||||
@@ -776,6 +786,7 @@ fn typed_events_vertices_and_transition_kinds_round_trip_in_both_layers() {
|
||||
.find(|r| r.alias == "recover")
|
||||
.unwrap();
|
||||
let RelationBody::StateTransition {
|
||||
transition_kind,
|
||||
trigger,
|
||||
guard,
|
||||
effect,
|
||||
@@ -784,32 +795,42 @@ fn typed_events_vertices_and_transition_kinds_round_trip_in_both_layers() {
|
||||
else {
|
||||
panic!("expected transition")
|
||||
};
|
||||
assert_eq!(*transition_kind, TransitionKind::External);
|
||||
assert_eq!(trigger, "Operator confirms\nНе запускать код");
|
||||
assert_eq!(guard, "available && status == \"Ready\"");
|
||||
assert_eq!(effect, "Record the assessment");
|
||||
// External is omitted in compact output. Insert an explicit invalid
|
||||
// discriminator into Recover using its unique, nondefault trigger list.
|
||||
let invalid_kind = replace_once(
|
||||
&canonical,
|
||||
"triggers [@deadline, @assess];",
|
||||
"transition_kind Unsupported;\n triggers [@deadline, @assess];",
|
||||
);
|
||||
rejected(&invalid_kind, "Unsupported");
|
||||
for invalid in [
|
||||
canonical.replace("transition_kind External;", "transition_kind Unsupported;"),
|
||||
canonical.replace(
|
||||
replace_once(
|
||||
&canonical,
|
||||
"triggers [@deadline, @assess];",
|
||||
"triggers [\"deadline\", @assess];",
|
||||
),
|
||||
canonical.replace(
|
||||
replace_once(
|
||||
&canonical,
|
||||
"triggers [@deadline, @assess];",
|
||||
"triggers [@deadline, @deadline];",
|
||||
),
|
||||
canonical.replace("effects [@assess];", "effects [@payload];"),
|
||||
canonical.replace("kind After;", "kind Relative;"),
|
||||
canonical.replace("items [@payload];", "items [@assess];"),
|
||||
replace_once(&canonical, "effects [@assess];", "effects [@payload];"),
|
||||
replace_once(&canonical, "kind After;", "kind Relative;"),
|
||||
replace_once(&canonical, "items [@payload];", "items [@assess];"),
|
||||
] {
|
||||
assert!(
|
||||
language::parse(&invalid).is_err(),
|
||||
"invalid typed state/event source accepted"
|
||||
);
|
||||
}
|
||||
let legacy = canonical
|
||||
.replace("transition_kind External;", "")
|
||||
.replace("triggers [@deadline, @assess];", "")
|
||||
.replace("effects [@assess];", "");
|
||||
// Canonical source already omits External. Removing the supplied lists
|
||||
// independently exercises their empty omission defaults and retained prose.
|
||||
let legacy = replace_once(&canonical, "triggers [@deadline, @assess];", "");
|
||||
let legacy = replace_once(&legacy, "effects [@assess];", "");
|
||||
let legacy = read(&legacy);
|
||||
let RelationBody::StateTransition {
|
||||
transition_kind,
|
||||
@@ -829,7 +850,7 @@ fn typed_events_vertices_and_transition_kinds_round_trip_in_both_layers() {
|
||||
(retained_trigger, retained_guard, retained_effect),
|
||||
(trigger, guard, effect)
|
||||
);
|
||||
let draft = canonical.replace("expression \"30 s\";", "expression \"\";");
|
||||
let draft = replace_once(&canonical, "expression \"30 s\";", "expression \"\";");
|
||||
assert!(language::parse(&draft).is_ok());
|
||||
let deadline = model
|
||||
.elements
|
||||
@@ -1038,7 +1059,7 @@ fn original_v2_text_and_json_preserve_identity_and_mixed_scenarios_after_extensi
|
||||
"fixture must cover actual old scenario content"
|
||||
);
|
||||
let canonical = language::format(&from_source);
|
||||
assert!(canonical.contains("viewpoint MixedLegacy;"));
|
||||
assert!(!canonical.contains("viewpoint MixedLegacy;"));
|
||||
for relation in from_source.relations.values() {
|
||||
if let RelationBody::StateTransition {
|
||||
transition_kind,
|
||||
|
||||
@@ -441,6 +441,8 @@ fn nested_owner_bounds_group_movement_and_authored_routes_share_the_same_geometr
|
||||
diagram: d,
|
||||
route: EdgeRoute {
|
||||
edge,
|
||||
source_attachment: None,
|
||||
target_attachment: None,
|
||||
waypoints: vec![pos(500., 420.)],
|
||||
label: None,
|
||||
},
|
||||
@@ -767,7 +769,15 @@ fn resetting_last_source_anchors_preserves_comments_and_can_add_a_new_manual_rec
|
||||
assert_eq!(cleared.decoded.project, prepared.project);
|
||||
let text = &cleared.bundle.files["project.arcadia"];
|
||||
assert!(text.contains("// first rationale") && text.contains("// second rationale"));
|
||||
assert!(!text.contains("port_anchors"));
|
||||
// Lossless editing may retain the authored empty field and its annotations.
|
||||
// Canonical export, rather than a model update, normalizes default syntax.
|
||||
assert!(!language::format(&cleared.decoded.project).contains("port_anchors"));
|
||||
assert_eq!(
|
||||
update_bundle(&cleared, &cleared.decoded.project, ProjectLimits::default())
|
||||
.unwrap()
|
||||
.bundle,
|
||||
cleared.bundle
|
||||
);
|
||||
let prepared = prepare_command(
|
||||
&cleared.decoded.project,
|
||||
&Command::SetPortAnchor {
|
||||
|
||||
@@ -70,6 +70,8 @@ fn fixture() -> Fixture {
|
||||
fn route(edge: Id) -> EdgeRoute {
|
||||
EdgeRoute {
|
||||
edge,
|
||||
source_attachment: None,
|
||||
target_attachment: None,
|
||||
waypoints: vec![Position { x: 550., y: 240. }, Position { x: 550., y: 360. }],
|
||||
label: Some(EdgeLabel {
|
||||
fraction: 0.4,
|
||||
@@ -689,6 +691,8 @@ fn old_models_get_empty_routes_and_route_json_is_strict() {
|
||||
serde_json::from_value::<EdgeRoute>(minimal).unwrap(),
|
||||
EdgeRoute {
|
||||
edge: f.edge,
|
||||
source_attachment: None,
|
||||
target_attachment: None,
|
||||
waypoints: vec![],
|
||||
label: None
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ fn route(p: &Project, d: Id) -> RoutedView {
|
||||
fn set_route(p: &mut Project, d: Id, edge: Id, pins: Vec<Position>, label: Option<EdgeLabel>) {
|
||||
p.diagrams.get_mut(&d).unwrap().routes.push(EdgeRoute {
|
||||
edge,
|
||||
source_attachment: None,
|
||||
target_attachment: None,
|
||||
waypoints: pins,
|
||||
label,
|
||||
});
|
||||
|
||||
@@ -117,6 +117,8 @@ fn authored_overlap_is_exact_and_reset_only_repositions_automatic_text() {
|
||||
.routes
|
||||
.push(EdgeRoute {
|
||||
edge: fe,
|
||||
source_attachment: None,
|
||||
target_attachment: None,
|
||||
waypoints: vec![],
|
||||
label: Some(authored.clone()),
|
||||
});
|
||||
|
||||
@@ -301,6 +301,8 @@ fn folding_retains_authored_routes_without_false_self_transitions() {
|
||||
let pins = vec![point(690., 480.), point(690., 230.)];
|
||||
f.p.diagrams.get_mut(&f.d).unwrap().routes.push(EdgeRoute {
|
||||
edge: out,
|
||||
source_attachment: None,
|
||||
target_attachment: None,
|
||||
waypoints: pins.clone(),
|
||||
label: None,
|
||||
});
|
||||
@@ -362,11 +364,15 @@ fn grouped_moves_translate_hidden_descendants_and_pins_only_in_one_view() {
|
||||
let pins = vec![point(570., 460.)];
|
||||
f.p.diagrams.get_mut(&f.d).unwrap().routes.push(EdgeRoute {
|
||||
edge: f.local,
|
||||
source_attachment: None,
|
||||
target_attachment: None,
|
||||
waypoints: pins.clone(),
|
||||
label: Some(label.clone()),
|
||||
});
|
||||
f.p.diagrams.get_mut(&f.d).unwrap().routes.push(EdgeRoute {
|
||||
edge: f.external,
|
||||
source_attachment: None,
|
||||
target_attachment: None,
|
||||
waypoints: vec![point(690., 230.)],
|
||||
label: None,
|
||||
});
|
||||
@@ -422,6 +428,8 @@ fn cross_machine_reparent_requires_atomic_placement_and_route_repair() {
|
||||
let placement = f.p.place(f.d, orphan, point(30., 750.));
|
||||
f.p.diagrams.get_mut(&f.d).unwrap().routes.push(EdgeRoute {
|
||||
edge,
|
||||
source_attachment: None,
|
||||
target_attachment: None,
|
||||
waypoints: vec![],
|
||||
label: None,
|
||||
});
|
||||
@@ -456,6 +464,8 @@ fn cross_machine_reparent_requires_atomic_placement_and_route_repair() {
|
||||
diagram: other,
|
||||
route: EdgeRoute {
|
||||
edge,
|
||||
source_attachment: None,
|
||||
target_attachment: None,
|
||||
waypoints: vec![],
|
||||
label: None,
|
||||
},
|
||||
@@ -583,6 +593,8 @@ fn layout_reserves_internal_rows_and_state_routes_retain_hard_pins() {
|
||||
let pins = vec![point(730., 130.), point(1060., 130.)];
|
||||
f.p.diagrams.get_mut(&f.d).unwrap().routes.push(EdgeRoute {
|
||||
edge: f.self_edge,
|
||||
source_attachment: None,
|
||||
target_attachment: None,
|
||||
waypoints: pins.clone(),
|
||||
label: Some(EdgeLabel {
|
||||
fraction: 0.25,
|
||||
@@ -652,6 +664,8 @@ fn moving_a_region_does_not_translate_pins_attached_to_a_stationary_state_bounda
|
||||
let pins = vec![point(280., 390.), point(280., 470.)];
|
||||
f.p.diagrams.get_mut(&f.d).unwrap().routes.push(EdgeRoute {
|
||||
edge: f.local,
|
||||
source_attachment: None,
|
||||
target_attachment: None,
|
||||
waypoints: pins.clone(),
|
||||
label: None,
|
||||
});
|
||||
@@ -730,6 +744,8 @@ fn initial_transition_attaches_to_the_compact_symbol_and_preview_keeps_settled_g
|
||||
);
|
||||
f.p.diagrams.get_mut(&f.d).unwrap().routes.push(EdgeRoute {
|
||||
edge: f.self_edge,
|
||||
source_attachment: None,
|
||||
target_attachment: None,
|
||||
waypoints: vec![],
|
||||
label: Some(EdgeLabel {
|
||||
fraction: 0.3,
|
||||
|
||||
@@ -748,6 +748,8 @@ fn allocation_artifact_and_manual_trace_cascades_are_named_and_refused() {
|
||||
fn route(edge: Id) -> EdgeRoute {
|
||||
EdgeRoute {
|
||||
edge,
|
||||
source_attachment: None,
|
||||
target_attachment: None,
|
||||
waypoints: vec![xy(420., 400.), xy(420., 550.)],
|
||||
label: Some(EdgeLabel {
|
||||
fraction: 0.4,
|
||||
|
||||
@@ -70,6 +70,7 @@ impl Root<'_> {
|
||||
pan: self.app.pan,
|
||||
context: self.app.route_context().unwrap(),
|
||||
selected_bend: None,
|
||||
selected_attachment: None,
|
||||
editable: false,
|
||||
placing: false,
|
||||
connection: None,
|
||||
|
||||
@@ -493,6 +493,7 @@ pub struct App {
|
||||
pub camera_epoch: u64,
|
||||
camera_boundary_epoch: u64,
|
||||
pub selected_bend: Option<(Id, usize)>,
|
||||
pub selected_attachment: Option<(crate::route_edit::Context, Id, EdgeEnd)>,
|
||||
pub exact_strings: bool,
|
||||
pub document: Document,
|
||||
pub page: Page,
|
||||
@@ -613,6 +614,7 @@ impl App {
|
||||
camera_epoch: 0,
|
||||
camera_boundary_epoch: 0,
|
||||
selected_bend: None,
|
||||
selected_attachment: None,
|
||||
exact_strings: false,
|
||||
document,
|
||||
page: Page::Diagram,
|
||||
@@ -1103,6 +1105,9 @@ impl App {
|
||||
previous != (self.layer, self.active_diagram)
|
||||
}
|
||||
fn select(&mut self, id: Id) {
|
||||
if id != self.selected {
|
||||
self.selected_attachment = None;
|
||||
}
|
||||
if self.selected == id {
|
||||
return;
|
||||
}
|
||||
@@ -2329,6 +2334,15 @@ impl App {
|
||||
} else if self.behavior.creation.has_pending() {
|
||||
self.behavior.creation.acknowledge_commit();
|
||||
self.status = "Behavior creation cancelled".into();
|
||||
} else if self.page == Page::Behavior
|
||||
&& matches!(
|
||||
self.behavior.diagram.tool,
|
||||
behavior::state_edit::Tool::AdjustAttachment { .. }
|
||||
)
|
||||
{
|
||||
// Menu arming invalidates canvas keyboard ownership. Escape
|
||||
// must also cancel before the next canvas click grants it.
|
||||
self.behavior.diagram.tool = behavior::state_edit::Tool::Select;
|
||||
}
|
||||
if self.connection.take().is_some() {
|
||||
self.status = "Drawing cancelled · Select / move is active".into();
|
||||
@@ -4523,7 +4537,7 @@ impl App {
|
||||
}
|
||||
fn edit_route(&mut self, event: crate::route_edit::Event) {
|
||||
use crate::route_edit::{Event, insert_pin, stored_route};
|
||||
if self.connection.is_some() {
|
||||
if self.connection.is_some() || self.page != Page::Diagram {
|
||||
return;
|
||||
}
|
||||
let Some(context) = self.route_context() else {
|
||||
@@ -4551,6 +4565,75 @@ impl App {
|
||||
.filter(|(id, _)| *id == self.selected)
|
||||
.map(|(_, i)| i);
|
||||
let command = match event {
|
||||
Event::ChooseAttachment(end) => {
|
||||
if crate::route_edit::attachment_node(
|
||||
self.project(),
|
||||
diagram,
|
||||
&view,
|
||||
self.selected,
|
||||
end,
|
||||
)
|
||||
.is_some()
|
||||
{
|
||||
self.selected_attachment = Some((context, self.selected, end));
|
||||
self.selected_bend = None;
|
||||
self.status = format!(
|
||||
"Drag the {} attachment handle along its element boundary · Esc cancels",
|
||||
if end == EdgeEnd::Source {
|
||||
"source"
|
||||
} else {
|
||||
"target"
|
||||
}
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
Event::ResetAttachment(end) => {
|
||||
if crate::route_edit::attachment_node(
|
||||
self.project(),
|
||||
diagram,
|
||||
&view,
|
||||
self.selected,
|
||||
end,
|
||||
)
|
||||
.is_none()
|
||||
|| route.attachment(end).is_none()
|
||||
{
|
||||
return;
|
||||
}
|
||||
route.set_attachment(end, None);
|
||||
selected_bend = None;
|
||||
Command::SetEdgeRoute {
|
||||
diagram: context.diagram,
|
||||
route,
|
||||
}
|
||||
}
|
||||
Event::CommitAttachment(expected, changed, end, owner) => {
|
||||
if expected != context
|
||||
|| changed.edge != self.selected
|
||||
|| crate::route_edit::attachment_node(
|
||||
self.project(),
|
||||
diagram,
|
||||
&view,
|
||||
self.selected,
|
||||
end,
|
||||
)
|
||||
.is_none_or(|node| node.id != owner)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// A boundary gesture owns exactly one presentation field.
|
||||
let mut intended = route.clone();
|
||||
intended.set_attachment(end, changed.attachment(end));
|
||||
if changed != intended || intended == route {
|
||||
return;
|
||||
}
|
||||
selected_bend = None;
|
||||
Command::SetEdgeRoute {
|
||||
diagram: context.diagram,
|
||||
route: intended,
|
||||
}
|
||||
}
|
||||
Event::SelectBend(id, index) => {
|
||||
if id == self.selected && index < route.waypoints.len() {
|
||||
self.selected_bend = Some((id, index));
|
||||
|
||||
@@ -69,6 +69,7 @@ fn canvas(app: &App) -> DiagramCanvas<'_> {
|
||||
pan: app.pan,
|
||||
context: app.route_context().unwrap(),
|
||||
selected_bend: None,
|
||||
selected_attachment: None,
|
||||
editable: !app.draft_dirty() && !app.source_dirty(),
|
||||
placing: false,
|
||||
connection: None,
|
||||
|
||||
@@ -75,6 +75,7 @@ fn architecture_f2_routes_selected_node_to_inline_rename_and_exact_undo() {
|
||||
pan: app.pan,
|
||||
context: app.route_context().unwrap(),
|
||||
selected_bend: None,
|
||||
selected_attachment: None,
|
||||
editable: true,
|
||||
placing: false,
|
||||
connection: None,
|
||||
|
||||
@@ -230,6 +230,7 @@ fn architecture_canvas_left_click_uses_world_coordinate_once_at_zoom_and_pan() {
|
||||
pan: app.pan,
|
||||
context: app.route_context().unwrap(),
|
||||
selected_bend: None,
|
||||
selected_attachment: None,
|
||||
editable: true,
|
||||
placing: true,
|
||||
connection: None,
|
||||
@@ -306,6 +307,7 @@ fn architecture_f2_rename_preserves_identity_placement_and_atomic_history() {
|
||||
pan: app.pan,
|
||||
context: app.route_context().unwrap(),
|
||||
selected_bend: None,
|
||||
selected_attachment: None,
|
||||
editable: true,
|
||||
placing: false,
|
||||
connection: None,
|
||||
|
||||
@@ -924,6 +924,8 @@ async fn mounted_bend_delete_has_priority_and_semantic_edge_delete_is_confirmed(
|
||||
diagram,
|
||||
route: EdgeRoute {
|
||||
edge,
|
||||
source_attachment: None,
|
||||
target_attachment: None,
|
||||
waypoints: vec![Position { x: 400., y: -100. }],
|
||||
label: None,
|
||||
},
|
||||
|
||||
@@ -269,9 +269,6 @@ impl App {
|
||||
.map(|request| request.job);
|
||||
return task;
|
||||
}
|
||||
nav::SymbolEvent::Close => {
|
||||
return self.show_text_drawer(None);
|
||||
}
|
||||
nav::SymbolEvent::Back => {
|
||||
self.source_symbol_back();
|
||||
// A successful Back needs no empty results panel. Retain an
|
||||
|
||||
@@ -85,6 +85,11 @@ fn symbol(app: &mut App, event: nav::SymbolEvent) {
|
||||
send(app, message);
|
||||
}
|
||||
|
||||
fn close_drawer(app: &mut App) {
|
||||
let message = Message::TextWorkspace(TextEvent::HideDrawer(app.text_drawer_context()));
|
||||
send(app, message);
|
||||
}
|
||||
|
||||
fn choice(app: &App, stamp: query::QueryStamp, reference: bool, index: usize) -> Message {
|
||||
app.source_symbol_message(nav::SymbolEvent::Choose {
|
||||
stamp,
|
||||
@@ -414,7 +419,7 @@ fn close_during_busy_retains_hidden_completion_without_reopening_or_navigation()
|
||||
let raw = app.source_workspace.bundle();
|
||||
let cursor = app.source_editor.cursor();
|
||||
assert!(references_visible(&app));
|
||||
symbol(&mut app, nav::SymbolEvent::Close);
|
||||
close_drawer(&mut app);
|
||||
assert!(app.text_workspace.drawer().is_none());
|
||||
assert_eq!(app.source_symbols.in_flight, Some(request.job));
|
||||
assert!(app.source_symbols.request.is_none());
|
||||
@@ -561,7 +566,7 @@ fn closed_results_stay_closed_on_exact_back_and_reopen_only_for_a_return_notice(
|
||||
let origin = app.source_editor.cursor();
|
||||
finish(&mut app, query::Action::Definition);
|
||||
reveal(&mut app);
|
||||
symbol(&mut app, nav::SymbolEvent::Close);
|
||||
close_drawer(&mut app);
|
||||
assert!(app.text_workspace.drawer().is_none() && app.source_symbols.results.is_some());
|
||||
if changed {
|
||||
// Use the workspace edit API to give the origin a new generation.
|
||||
@@ -1433,7 +1438,7 @@ fn stale_envelope_trial(reset: bool) {
|
||||
let old_messages = [
|
||||
app.source_symbol_message(nav::SymbolEvent::Query(query::Action::Definition)),
|
||||
app.source_symbol_message(nav::SymbolEvent::Back),
|
||||
app.source_symbol_message(nav::SymbolEvent::Close),
|
||||
Message::TextWorkspace(TextEvent::HideDrawer(app.text_drawer_context())),
|
||||
choice(&app, old_results.stamp, false, 0),
|
||||
];
|
||||
if reset {
|
||||
@@ -1494,7 +1499,7 @@ fn stale_envelope_trial(reset: bool) {
|
||||
// Replay once more with no busy-slot fallback and visible current results.
|
||||
assert_stale_envelopes_preserve_current(&mut app, &old_messages);
|
||||
let interaction = app.source_symbols.interaction;
|
||||
symbol(&mut app, nav::SymbolEvent::Close);
|
||||
close_drawer(&mut app);
|
||||
assert_ne!(app.source_symbols.interaction, interaction);
|
||||
assert!(app.text_workspace.drawer().is_none() && app.source_symbols.results.is_some());
|
||||
let next = begin(&mut app, query::Action::References);
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
//! Production App tree and its actual keyboard subscription, without a canvas click.
|
||||
use super::*;
|
||||
use crate::behavior::canvas_workspace::tests::{Mounted, key};
|
||||
use iced::{
|
||||
advanced::subscription,
|
||||
futures::{StreamExt, stream, task::noop_waker_ref},
|
||||
keyboard::key::Named,
|
||||
mouse,
|
||||
};
|
||||
use std::task::{Context as PollContext, Poll};
|
||||
|
||||
async fn press(mounted: &mut Mounted, app: &mut App, named: Named) -> Vec<Message> {
|
||||
let input = key(named);
|
||||
let (mut messages, statuses) = mounted.input_with_status(
|
||||
app,
|
||||
std::slice::from_ref(&input),
|
||||
mouse::Cursor::Unavailable,
|
||||
);
|
||||
let interaction = subscription::Event::Interaction {
|
||||
window: iced::window::Id::unique(),
|
||||
event: input,
|
||||
status: statuses[0],
|
||||
};
|
||||
for recipe in subscription::into_recipes(app.subscription()) {
|
||||
let mut output = recipe.stream(Box::pin(stream::iter([interaction.clone()])));
|
||||
let mut cx = PollContext::from_waker(noop_waker_ref());
|
||||
while let Poll::Ready(Some(message)) = output.poll_next_unpin(&mut cx) {
|
||||
messages.push(message);
|
||||
}
|
||||
}
|
||||
for message in messages.iter().cloned() {
|
||||
let task = app.update(message);
|
||||
mounted.perform(app, task).await;
|
||||
}
|
||||
mounted.settle(app).await;
|
||||
messages
|
||||
}
|
||||
|
||||
async fn armed() -> (App, Mounted, Id) {
|
||||
let mut f = fixture();
|
||||
let diagram = create_view(&mut f).diagram;
|
||||
let mut project = f.app.project().clone();
|
||||
let relation = project.relate(RelationKind::StateTransition, "Switch", f.a, f.b);
|
||||
let mut app = App::with_project(project);
|
||||
app.window_size = iced::Size::new(1800., 1100.);
|
||||
send(&mut app, Message::RevealInDiagram(diagram, relation));
|
||||
let mut mounted = Mounted::new(&mut app).await;
|
||||
app.behavior.diagram.fit = false;
|
||||
let context = app.state_context().unwrap();
|
||||
event(
|
||||
&mut app,
|
||||
Event::ContextMenu {
|
||||
context,
|
||||
object: relation,
|
||||
placement: None,
|
||||
anchor: iced::Point::new(450., 400.),
|
||||
bend: None,
|
||||
route_segment: None,
|
||||
},
|
||||
);
|
||||
mounted.settle(&mut app).await;
|
||||
let token = app.model_menu.as_ref().unwrap().token;
|
||||
send(
|
||||
&mut app,
|
||||
Message::Menu(crate::model_menu::Event::Invoke(
|
||||
token,
|
||||
Box::new(Message::StateDiagram(Event::Choose(
|
||||
Tool::AdjustAttachment {
|
||||
relation,
|
||||
end: EdgeEnd::Source,
|
||||
},
|
||||
))),
|
||||
)),
|
||||
);
|
||||
mounted.settle(&mut app).await;
|
||||
assert!(app.model_menu.is_none());
|
||||
assert_eq!(
|
||||
app.behavior.diagram.tool,
|
||||
Tool::AdjustAttachment {
|
||||
relation,
|
||||
end: EdgeEnd::Source
|
||||
}
|
||||
);
|
||||
(app, mounted, relation)
|
||||
}
|
||||
|
||||
fn canvas_focus(mounted: &mut Mounted, app: &App) -> (iced::Rectangle, bool) {
|
||||
let id = iced::advanced::widget::Id::from("diagram-keyboard-owner");
|
||||
let (_, bounds, focused) = mounted
|
||||
.geometry(app)
|
||||
.focused
|
||||
.into_iter()
|
||||
.find(|(candidate, _, _)| candidate.as_ref() == Some(&id))
|
||||
.unwrap();
|
||||
(bounds, focused)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn mounted_menu_armed_attachment_escape_without_canvas_click_preserves_document_and_focus() {
|
||||
let (mut app, mut mounted, _) = armed().await;
|
||||
let before = app.document.snapshot();
|
||||
let history = (app.document.can_undo(), app.document.can_redo());
|
||||
let camera = (
|
||||
app.behavior.diagram.zoom,
|
||||
app.behavior.diagram.pan,
|
||||
app.behavior.diagram.fit,
|
||||
);
|
||||
assert!(!canvas_focus(&mut mounted, &app).1);
|
||||
let messages = press(&mut mounted, &mut app, Named::Escape).await;
|
||||
assert!(messages.iter().any(|m| matches!(m, Message::Escape)));
|
||||
assert_eq!(app.behavior.diagram.tool, Tool::Select);
|
||||
assert!(!canvas_focus(&mut mounted, &app).1);
|
||||
press(&mut mounted, &mut app, Named::Delete).await;
|
||||
assert!(
|
||||
!app.delete_pending,
|
||||
"Escape must not grant canvas Delete ownership"
|
||||
);
|
||||
assert!(Arc::ptr_eq(&before, &app.document.snapshot()));
|
||||
assert_eq!(app.document.bundle(), &before.bundle);
|
||||
assert_eq!(app.project(), &before.decoded.project);
|
||||
assert_eq!((app.document.can_undo(), app.document.can_redo()), history);
|
||||
assert_eq!(
|
||||
(
|
||||
app.behavior.diagram.zoom,
|
||||
app.behavior.diagram.pan,
|
||||
app.behavior.diagram.fit
|
||||
),
|
||||
camera
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn mounted_attachment_escape_preserves_modal_priority_and_focused_canvas_control() {
|
||||
let (mut app, mut mounted, _) = armed().await;
|
||||
let before = app.document.snapshot();
|
||||
// Existing modal Escape consumes the first key without canceling the tool underneath.
|
||||
send(&mut app, Message::Delete);
|
||||
assert!(app.delete_pending && app.delete_target.is_some());
|
||||
mounted.settle(&mut app).await;
|
||||
press(&mut mounted, &mut app, Named::Escape).await;
|
||||
assert!(!app.delete_pending);
|
||||
assert!(matches!(
|
||||
app.behavior.diagram.tool,
|
||||
Tool::AdjustAttachment { .. }
|
||||
));
|
||||
// A real canvas click grants ownership; inner-canvas Escape remains live.
|
||||
let bounds = canvas_focus(&mut mounted, &app).0;
|
||||
mounted
|
||||
.click(&mut app, iced::Point::new(bounds.x + 10., bounds.y + 10.))
|
||||
.await;
|
||||
assert!(canvas_focus(&mut mounted, &app).1);
|
||||
let messages = press(&mut mounted, &mut app, Named::Escape).await;
|
||||
assert!(
|
||||
messages
|
||||
.iter()
|
||||
.any(|m| matches!(m, Message::StateDiagram(Event::Choose(Tool::Select))))
|
||||
);
|
||||
assert_eq!(app.behavior.diagram.tool, Tool::Select);
|
||||
assert!(Arc::ptr_eq(&before, &app.document.snapshot()));
|
||||
}
|
||||
@@ -0,0 +1,480 @@
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn state_bend_delayed_commit_after_same_view_selection_is_inert_and_live_commit_works() {
|
||||
let (mut app, _, relation, _) = setup();
|
||||
let context = app.state_context().unwrap();
|
||||
let next = app.project().relations[&relation].target();
|
||||
let waypoints = vec![Position { x: 715., y: -425. }];
|
||||
let delayed = Event::SetBends {
|
||||
context,
|
||||
relation,
|
||||
waypoints: waypoints.clone(),
|
||||
};
|
||||
send(&mut app, Message::Select(next));
|
||||
assert_eq!(app.selected, next);
|
||||
assert_eq!(
|
||||
app.state_context(),
|
||||
Some(context),
|
||||
"same-view selection does not retire the context stamp"
|
||||
);
|
||||
let before = app.document.snapshot();
|
||||
let camera = (
|
||||
app.behavior.diagram.zoom,
|
||||
app.behavior.diagram.pan,
|
||||
app.behavior.diagram.fit,
|
||||
);
|
||||
event(&mut app, delayed);
|
||||
assert_eq!(app.selected, next);
|
||||
assert!(Arc::ptr_eq(&before, &app.document.snapshot()));
|
||||
assert_eq!(app.project(), &before.decoded.project);
|
||||
assert_eq!(app.document.bundle(), &before.bundle);
|
||||
assert!(!app.document.can_undo());
|
||||
assert_eq!(
|
||||
(
|
||||
app.behavior.diagram.zoom,
|
||||
app.behavior.diagram.pan,
|
||||
app.behavior.diagram.fit
|
||||
),
|
||||
camera
|
||||
);
|
||||
send(&mut app, Message::Select(relation));
|
||||
let context = app.state_context().unwrap();
|
||||
event(
|
||||
&mut app,
|
||||
Event::SetBends {
|
||||
context,
|
||||
relation,
|
||||
waypoints: waypoints.clone(),
|
||||
},
|
||||
);
|
||||
let mut expected = before.decoded.project.clone();
|
||||
let route = expected
|
||||
.diagrams
|
||||
.get_mut(&context.diagram)
|
||||
.unwrap()
|
||||
.routes
|
||||
.iter_mut()
|
||||
.find(|route| route.edge == relation)
|
||||
.unwrap();
|
||||
route.waypoints = waypoints;
|
||||
assert_eq!(app.project(), &expected);
|
||||
assert_source_model_agree(&app);
|
||||
send(&mut app, Message::Undo);
|
||||
assert_eq!(app.document.bundle(), &before.bundle);
|
||||
assert!(
|
||||
!app.document.can_undo(),
|
||||
"live drag remains a single transaction"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn state_bend_menu_carries_exact_segment_and_pin_without_changing_delete_action() {
|
||||
let (mut app, _, relation, _) = setup();
|
||||
let context = app.state_context().unwrap();
|
||||
let point = Position { x: 500., y: -400. };
|
||||
event(
|
||||
&mut app,
|
||||
Event::ContextMenu {
|
||||
context,
|
||||
object: relation,
|
||||
placement: None,
|
||||
anchor: iced::Point::ORIGIN,
|
||||
bend: Some(1),
|
||||
route_segment: Some((2, point)),
|
||||
},
|
||||
);
|
||||
let menu = crate::model_menu::popup(&app).unwrap();
|
||||
let mut add = false;
|
||||
let mut remove = false;
|
||||
let mut delete = false;
|
||||
for entry in menu.entries {
|
||||
if let crate::context_menu::Entry::Action {
|
||||
message: Some(Message::Menu(crate::model_menu::Event::Invoke(_, message))),
|
||||
..
|
||||
} = entry
|
||||
{
|
||||
match *message {
|
||||
Message::StateDiagram(Event::AddBend {
|
||||
relation: id,
|
||||
segment: Some((2, at)),
|
||||
..
|
||||
}) => {
|
||||
assert_eq!(id, relation);
|
||||
assert_eq!(at, point);
|
||||
add = true;
|
||||
}
|
||||
Message::StateDiagram(Event::RemoveBend {
|
||||
relation: id,
|
||||
index: 1,
|
||||
..
|
||||
}) => {
|
||||
assert_eq!(id, relation);
|
||||
remove = true;
|
||||
}
|
||||
Message::Delete => delete = true,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
assert!(add && remove && delete);
|
||||
}
|
||||
|
||||
fn setup() -> (App, Id, Id, Id) {
|
||||
let mut f = fixture();
|
||||
let diagram = create_view(&mut f).diagram;
|
||||
let mut project = f.app.project().clone();
|
||||
let relation = project.relate(RelationKind::StateTransition, "Bend trial", f.leaf, f.b);
|
||||
let second = state_edit::create_view(&project, f.machine).unwrap();
|
||||
project = prepare_command(&project, &second.command).unwrap().project;
|
||||
project
|
||||
.diagrams
|
||||
.get_mut(&diagram)
|
||||
.unwrap()
|
||||
.routes
|
||||
.push(EdgeRoute {
|
||||
edge: relation,
|
||||
waypoints: vec![
|
||||
Position { x: 650., y: -400. },
|
||||
Position { x: 300., y: -400. },
|
||||
Position { x: 650., y: -400. },
|
||||
],
|
||||
label: Some(EdgeLabel {
|
||||
fraction: 0.35,
|
||||
offset: Position { x: 9., y: -23. },
|
||||
}),
|
||||
source_attachment: Some(EdgeAttachment {
|
||||
side: PortAnchorSide::Top,
|
||||
offset: 0.234567,
|
||||
}),
|
||||
target_attachment: Some(EdgeAttachment {
|
||||
side: PortAnchorSide::Bottom,
|
||||
offset: 0.75,
|
||||
}),
|
||||
});
|
||||
let mut app = App::with_project(project);
|
||||
send(&mut app, Message::RevealInDiagram(diagram, relation));
|
||||
(app, diagram, relation, f.a)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn state_bend_commands_preserve_other_fields_views_and_exact_history() {
|
||||
let (mut app, diagram, relation, _) = setup();
|
||||
let baseline = app.document.snapshot();
|
||||
let points = vec![Position { x: 715., y: 425. }];
|
||||
let mut expected = app.project().clone();
|
||||
expected.diagrams.get_mut(&diagram).unwrap().routes[0].waypoints = points.clone();
|
||||
let context = app.state_context().unwrap();
|
||||
event(
|
||||
&mut app,
|
||||
Event::SetBends {
|
||||
context,
|
||||
relation,
|
||||
waypoints: points.clone(),
|
||||
},
|
||||
);
|
||||
assert_eq!(app.project(), &expected);
|
||||
assert_source_model_agree(&app);
|
||||
let changed = app.document.snapshot();
|
||||
let context = app.state_context().unwrap();
|
||||
event(
|
||||
&mut app,
|
||||
Event::SetBends {
|
||||
context,
|
||||
relation,
|
||||
waypoints: points,
|
||||
},
|
||||
);
|
||||
assert!(
|
||||
Arc::ptr_eq(&changed, &app.document.snapshot()),
|
||||
"equal bends must not add history"
|
||||
);
|
||||
send(&mut app, Message::Undo);
|
||||
assert_eq!(app.project(), &baseline.decoded.project);
|
||||
assert_eq!(app.document.bundle(), &baseline.bundle);
|
||||
assert!(!app.document.can_undo());
|
||||
send(&mut app, Message::Redo);
|
||||
assert_eq!(app.project(), &expected);
|
||||
assert_eq!(app.document.bundle(), &changed.bundle);
|
||||
let context = app.state_context().unwrap();
|
||||
event(&mut app, Event::ClearBends { context, relation });
|
||||
expected.diagrams.get_mut(&diagram).unwrap().routes[0]
|
||||
.waypoints
|
||||
.clear();
|
||||
assert_eq!(app.project(), &expected);
|
||||
let cleared = app.document.snapshot();
|
||||
let context = app.state_context().unwrap();
|
||||
event(&mut app, Event::ClearBends { context, relation });
|
||||
assert!(Arc::ptr_eq(&cleared, &app.document.snapshot()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn state_bend_self_loop_add_move_remove_clear_preserves_project_and_source_history() {
|
||||
let (app, diagram, relation, _) = setup();
|
||||
let mut project = app.project().clone();
|
||||
let RelationBody::StateTransition { source, target, .. } =
|
||||
&mut project.relations.get_mut(&relation).unwrap().body
|
||||
else {
|
||||
panic!("State transition fixture")
|
||||
};
|
||||
*target = *source;
|
||||
project.diagrams.get_mut(&diagram).unwrap().routes[0]
|
||||
.waypoints
|
||||
.clear();
|
||||
oa_core::validate_candidate(&project).unwrap();
|
||||
let mut app = App::with_project(project);
|
||||
send(&mut app, Message::RevealInDiagram(diagram, relation));
|
||||
let baseline = app.document.snapshot();
|
||||
let geometry = state_edit::bend_route(app.project(), diagram, relation).unwrap();
|
||||
assert!(!geometry.custom_suspended);
|
||||
assert!(geometry.pins.is_empty());
|
||||
assert!(
|
||||
geometry.points.len() >= 4,
|
||||
"actual external self-loop routing"
|
||||
);
|
||||
let segment = 1;
|
||||
let point = Position {
|
||||
x: (geometry.points[segment].x + geometry.points[segment + 1].x) / 2.,
|
||||
y: (geometry.points[segment].y + geometry.points[segment + 1].y) / 2.,
|
||||
};
|
||||
|
||||
// Each operation must alter only the complete Project's waypoint list;
|
||||
// Undo and Redo must restore exact serialized source, not just geometry.
|
||||
fn check(app: &mut App, diagram: Id, mutation: Event, points: Vec<Position>) {
|
||||
let before = app.document.snapshot();
|
||||
let mut expected = before.decoded.project.clone();
|
||||
expected.diagrams.get_mut(&diagram).unwrap().routes[0].waypoints = points;
|
||||
event(app, mutation);
|
||||
assert_eq!(app.project(), &expected);
|
||||
assert_source_model_agree(app);
|
||||
let after = app.document.snapshot();
|
||||
assert_ne!(after.bundle, before.bundle);
|
||||
send(app, Message::Undo);
|
||||
assert_eq!(app.project(), &before.decoded.project);
|
||||
assert_eq!(app.document.bundle(), &before.bundle);
|
||||
send(app, Message::Redo);
|
||||
assert_eq!(app.project(), &expected);
|
||||
assert_eq!(app.document.bundle(), &after.bundle);
|
||||
assert_source_model_agree(app);
|
||||
}
|
||||
|
||||
let context = app.state_context().unwrap();
|
||||
check(
|
||||
&mut app,
|
||||
diagram,
|
||||
Event::AddBend {
|
||||
context,
|
||||
relation,
|
||||
segment: Some((segment, point)),
|
||||
},
|
||||
vec![point],
|
||||
);
|
||||
let moved = Position {
|
||||
x: point.x + 45.,
|
||||
y: point.y - 35.,
|
||||
};
|
||||
let context = app.state_context().unwrap();
|
||||
check(
|
||||
&mut app,
|
||||
diagram,
|
||||
Event::SetBends {
|
||||
context,
|
||||
relation,
|
||||
waypoints: vec![moved],
|
||||
},
|
||||
vec![moved],
|
||||
);
|
||||
let context = app.state_context().unwrap();
|
||||
check(
|
||||
&mut app,
|
||||
diagram,
|
||||
Event::RemoveBend {
|
||||
context,
|
||||
relation,
|
||||
index: 0,
|
||||
},
|
||||
vec![],
|
||||
);
|
||||
assert_eq!(app.project(), &baseline.decoded.project);
|
||||
send(&mut app, Message::Undo);
|
||||
let context = app.state_context().unwrap();
|
||||
check(
|
||||
&mut app,
|
||||
diagram,
|
||||
Event::ClearBends { context, relation },
|
||||
vec![],
|
||||
);
|
||||
assert_eq!(app.project(), &baseline.decoded.project);
|
||||
assert_source_model_agree(&app);
|
||||
// Clear is a new source-preserving edit and may retain empty-list trivia.
|
||||
// Exact original bytes are restored by history, not by reauthoring a value.
|
||||
for _ in 0..3 {
|
||||
assert!(app.document.can_undo());
|
||||
send(&mut app, Message::Undo);
|
||||
}
|
||||
assert_eq!(app.project(), &baseline.decoded.project);
|
||||
assert_eq!(app.document.bundle(), &baseline.bundle);
|
||||
assert!(!app.document.can_undo());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn state_bend_insertion_uses_captured_traversal_segment_and_removal_only_changes_pins() {
|
||||
let (app, diagram, relation, _) = setup();
|
||||
let context = app.state_context().unwrap();
|
||||
let p = app.project();
|
||||
let geometry = state_edit::bend_route(p, diagram, relation).unwrap();
|
||||
let original = &p.diagrams[&diagram].routes[0];
|
||||
let reverse = geometry
|
||||
.points
|
||||
.windows(2)
|
||||
.position(|pair| pair[0] == original.waypoints[0] && pair[1] == original.waypoints[1])
|
||||
.unwrap();
|
||||
for (segment, expected_index) in [(reverse, 1), (reverse + 1, 2)] {
|
||||
let point = Position { x: 500., y: -400. };
|
||||
let planned = state_edit::plan(
|
||||
p,
|
||||
context,
|
||||
&Event::AddBend {
|
||||
context,
|
||||
relation,
|
||||
segment: Some((segment, point)),
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let actual = prepare_command(p, &planned.command).unwrap().project;
|
||||
let mut expected = p.clone();
|
||||
expected.diagrams.get_mut(&diagram).unwrap().routes[0]
|
||||
.waypoints
|
||||
.insert(expected_index, point);
|
||||
assert_eq!(actual, expected);
|
||||
let removed = state_edit::plan(
|
||||
&actual,
|
||||
context,
|
||||
&Event::RemoveBend {
|
||||
context,
|
||||
relation,
|
||||
index: expected_index,
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
prepare_command(&actual, &removed.command).unwrap().project,
|
||||
*p
|
||||
);
|
||||
}
|
||||
let default = state_edit::plan(
|
||||
p,
|
||||
context,
|
||||
&Event::AddBend {
|
||||
context,
|
||||
relation,
|
||||
segment: None,
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let Command::SetEdgeRoute { route, .. } = default.command else {
|
||||
panic!("route command")
|
||||
};
|
||||
assert_eq!(route.waypoints.len(), original.waypoints.len() + 1);
|
||||
assert_eq!(route.source_attachment, original.source_attachment);
|
||||
assert_eq!(route.target_attachment, original.target_attachment);
|
||||
assert_eq!(route.label, original.label);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn state_bend_stale_nonfinite_capacity_hidden_and_folded_requests_are_inert() {
|
||||
let (mut app, diagram, relation, composite) = setup();
|
||||
let context = app.state_context().unwrap();
|
||||
let baseline = app.document.snapshot();
|
||||
for mutation in [
|
||||
Event::SetBends {
|
||||
context: Context {
|
||||
epoch: context.epoch + 1,
|
||||
..context
|
||||
},
|
||||
relation,
|
||||
waypoints: vec![],
|
||||
},
|
||||
Event::SetBends {
|
||||
context,
|
||||
relation,
|
||||
waypoints: vec![Position { x: f32::NAN, y: 0. }],
|
||||
},
|
||||
Event::SetBends {
|
||||
context,
|
||||
relation,
|
||||
waypoints: vec![Position { x: 0., y: 0. }; 129],
|
||||
},
|
||||
Event::AddBend {
|
||||
context,
|
||||
relation,
|
||||
segment: Some((usize::MAX, Position { x: 0., y: 0. })),
|
||||
},
|
||||
Event::RemoveBend {
|
||||
context,
|
||||
relation,
|
||||
index: usize::MAX,
|
||||
},
|
||||
] {
|
||||
event(&mut app, mutation);
|
||||
assert!(Arc::ptr_eq(&baseline, &app.document.snapshot()));
|
||||
}
|
||||
let mut p = app.project().clone();
|
||||
p.diagrams.get_mut(&diagram).unwrap().routes[0].waypoints =
|
||||
vec![Position { x: 500., y: -400. }; 128];
|
||||
assert!(
|
||||
state_edit::plan(
|
||||
&p,
|
||||
context,
|
||||
&Event::AddBend {
|
||||
context,
|
||||
relation,
|
||||
segment: Some((1, Position { x: 500., y: -400. }))
|
||||
}
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
let mut hidden = app.project().clone();
|
||||
hidden
|
||||
.diagrams
|
||||
.get_mut(&diagram)
|
||||
.unwrap()
|
||||
.view_options
|
||||
.hidden_edges
|
||||
.push(relation);
|
||||
assert!(state_edit::bend_route(&hidden, diagram, relation).is_none());
|
||||
assert!(state_edit::plan(&hidden, context, &Event::ClearBends { context, relation }).is_err());
|
||||
let owner = node(&app, diagram, composite);
|
||||
let mut folded = app.project().clone();
|
||||
folded
|
||||
.diagrams
|
||||
.get_mut(&diagram)
|
||||
.unwrap()
|
||||
.nodes
|
||||
.get_mut(&owner)
|
||||
.unwrap()
|
||||
.collapsed = true;
|
||||
assert!(state_edit::bend_route(&folded, diagram, relation).is_none());
|
||||
assert!(state_edit::plan(&folded, context, &Event::ClearBends { context, relation }).is_err());
|
||||
let mut internal = app.project().clone();
|
||||
internal.diagrams.get_mut(&diagram).unwrap().routes.clear();
|
||||
if let RelationBody::StateTransition {
|
||||
source,
|
||||
target,
|
||||
transition_kind,
|
||||
..
|
||||
} = &mut internal.relations.get_mut(&relation).unwrap().body
|
||||
{
|
||||
*target = *source;
|
||||
*transition_kind = TransitionKind::Internal;
|
||||
}
|
||||
assert!(state_edit::bend_route(&internal, diagram, relation).is_none());
|
||||
send(
|
||||
&mut app,
|
||||
Message::Field("/name".into(), "Unapplied bend owner name".into()),
|
||||
);
|
||||
let draft = app.draft.as_ref().unwrap().value.clone();
|
||||
event(&mut app, Event::ClearBends { context, relation });
|
||||
assert!(Arc::ptr_eq(&baseline, &app.document.snapshot()));
|
||||
assert_eq!(app.draft.as_ref().unwrap().value, draft);
|
||||
}
|
||||
@@ -157,10 +157,14 @@ impl App {
|
||||
object,
|
||||
placement,
|
||||
anchor,
|
||||
bend,
|
||||
route_segment,
|
||||
} => {
|
||||
let mut request = crate::model_menu::Request::object(object, anchor);
|
||||
request.canvas = Some(context);
|
||||
request.placement = placement;
|
||||
request.bend = bend;
|
||||
request.route_segment = route_segment;
|
||||
return self.handle(Message::Menu(crate::model_menu::Event::Open(request)));
|
||||
}
|
||||
Event::EditTransition(_, id) => {
|
||||
@@ -172,6 +176,24 @@ impl App {
|
||||
)));
|
||||
}
|
||||
Event::Choose(tool) => {
|
||||
if let Tool::AdjustAttachment { relation, end } = tool {
|
||||
if self.behavior.has_pending() || self.draft_dirty() || self.source_dirty() {
|
||||
self.status =
|
||||
"Apply or cancel pending edits before adjusting an attachment.".into();
|
||||
return Task::none();
|
||||
}
|
||||
let Some(context) = self.state_context() else {
|
||||
return Task::none();
|
||||
};
|
||||
if state_edit::attachment_node(self.project(), context.diagram, relation, end)
|
||||
.is_none()
|
||||
{
|
||||
return Task::none();
|
||||
}
|
||||
self.selected = relation;
|
||||
self.selected_node = None;
|
||||
self.refresh_draft();
|
||||
}
|
||||
if !self.apply() {
|
||||
return Task::none();
|
||||
}
|
||||
@@ -210,8 +232,37 @@ impl App {
|
||||
let Some(context) = self.state_context() else {
|
||||
return Task::none();
|
||||
};
|
||||
if let Event::SetBends { relation, .. } = &mutation
|
||||
&& *relation != self.selected
|
||||
{
|
||||
return Task::none();
|
||||
}
|
||||
if let Event::SetAttachment {
|
||||
relation,
|
||||
end,
|
||||
attachment,
|
||||
..
|
||||
} = &mutation
|
||||
{
|
||||
let existing = self.project().diagrams[&context.diagram]
|
||||
.routes
|
||||
.iter()
|
||||
.find(|route| route.edge == *relation)
|
||||
.and_then(|route| route.attachment(*end));
|
||||
if existing == *attachment {
|
||||
return Task::none();
|
||||
}
|
||||
}
|
||||
match state_edit::plan(self.project(), context, &mutation) {
|
||||
Ok(plan) => {
|
||||
if let Command::SetEdgeRoute { diagram, route } = &plan.command
|
||||
&& crate::route_edit::stored_route(
|
||||
&self.project().diagrams[diagram],
|
||||
route.edge,
|
||||
) == *route
|
||||
{
|
||||
return Task::none();
|
||||
}
|
||||
if self.execute(plan.command) {
|
||||
self.behavior.diagram.diagram = Some(plan.diagram);
|
||||
self.behavior.diagram.placement = plan.placement;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
//! App transaction and draft boundaries for captured state-canvas messages.
|
||||
use super::*;
|
||||
#[path = "state_attachment_escape_tests.rs"]
|
||||
mod attachment_escape;
|
||||
#[path = "state_bend_tests.rs"]
|
||||
mod bends;
|
||||
use crate::behavior::{
|
||||
self,
|
||||
state_edit::{self, Context, Endpoint, Event, Tool},
|
||||
|
||||
@@ -158,6 +158,14 @@ impl Mounted {
|
||||
events: &[iced::Event],
|
||||
cursor: mouse::Cursor,
|
||||
) -> Vec<Message> {
|
||||
self.input_with_status(app, events, cursor).0
|
||||
}
|
||||
pub fn input_with_status(
|
||||
&mut self,
|
||||
app: &App,
|
||||
events: &[iced::Event],
|
||||
cursor: mouse::Cursor,
|
||||
) -> (Vec<Message>, Vec<iced::event::Status>) {
|
||||
let mut messages = vec![];
|
||||
let mut ui = UserInterface::build(
|
||||
app.view(),
|
||||
@@ -165,7 +173,7 @@ impl Mounted {
|
||||
std::mem::take(&mut self.cache),
|
||||
&mut self.renderer,
|
||||
);
|
||||
let _ = ui.update(
|
||||
let (_, statuses) = ui.update(
|
||||
events,
|
||||
cursor,
|
||||
&mut self.renderer,
|
||||
@@ -173,7 +181,7 @@ impl Mounted {
|
||||
&mut messages,
|
||||
);
|
||||
self.cache = ui.into_cache();
|
||||
messages
|
||||
(messages, statuses)
|
||||
}
|
||||
pub async fn perform(&mut self, app: &mut App, task: iced::Task<Message>) {
|
||||
let mut ready = vec![];
|
||||
|
||||
@@ -0,0 +1,656 @@
|
||||
// Included in state_canvas::tests: exercise the real canvas event path.
|
||||
|
||||
fn bend_fixture(authored: bool) -> (Fixture, Id) {
|
||||
let mut f = fixture();
|
||||
let relation = f.project.relate(
|
||||
RelationKind::StateTransition,
|
||||
"Standby to stopped",
|
||||
f.b,
|
||||
f.c,
|
||||
);
|
||||
if authored {
|
||||
f.project
|
||||
.diagrams
|
||||
.get_mut(&f.diagram)
|
||||
.unwrap()
|
||||
.routes
|
||||
.push(EdgeRoute {
|
||||
edge: relation,
|
||||
waypoints: vec![Position {
|
||||
x: 650.25,
|
||||
y: 340.75,
|
||||
}],
|
||||
source_attachment: Some(EdgeAttachment {
|
||||
side: PortAnchorSide::Bottom,
|
||||
offset: 0.5,
|
||||
}),
|
||||
target_attachment: Some(EdgeAttachment {
|
||||
side: PortAnchorSide::Top,
|
||||
offset: 0.25,
|
||||
}),
|
||||
label: Some(EdgeLabel {
|
||||
fraction: 0.43,
|
||||
offset: Position { x: 28., y: -16. },
|
||||
}),
|
||||
});
|
||||
}
|
||||
validate_candidate(&f.project).unwrap();
|
||||
(f, relation)
|
||||
}
|
||||
|
||||
fn bend_segment(scene: &Scene, relation: Id) -> (usize, Point) {
|
||||
let edge = &scene.routed.edges[&relation];
|
||||
edge.points
|
||||
.windows(2)
|
||||
.enumerate()
|
||||
.filter(|(i, _)| *i > 0 && *i + 2 < edge.points.len())
|
||||
.map(|(i, p)| {
|
||||
(
|
||||
i,
|
||||
Point::new((p[0].x + p[1].x) / 2., (p[0].y + p[1].y) / 2.),
|
||||
(p[1].x - p[0].x).abs() + (p[1].y - p[0].y).abs(),
|
||||
)
|
||||
})
|
||||
.filter(|(_, p, length)| {
|
||||
*length > 40. && edge.pins.iter().all(|pin| p.distance(point(*pin)) > 20.)
|
||||
})
|
||||
.max_by(|a, b| a.2.total_cmp(&b.2))
|
||||
.map(|(i, p, _)| (i, p))
|
||||
.expect("fixture has an exposed interior route segment")
|
||||
}
|
||||
|
||||
fn bend_press(canvas: &StateCanvas<'_>, state: &mut State, at: Point) {
|
||||
motion(canvas, state, at, at);
|
||||
let event = input(
|
||||
canvas,
|
||||
state,
|
||||
mouse::Event::ButtonPressed(mouse::Button::Left),
|
||||
at,
|
||||
);
|
||||
assert!(
|
||||
!matches!(event, Some(Event::SetBends { .. })),
|
||||
"press alone cannot commit"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn state_bends_segment_drag_inserts_one_pin_using_ordered_pointer_at_three_zooms() {
|
||||
for zoom in [0.5, 1., 2.] {
|
||||
let (f, relation) = bend_fixture(false);
|
||||
let mut canvas = canvas(&f, Tool::Select, zoom);
|
||||
canvas.selected = relation;
|
||||
let mut state = State::default();
|
||||
let baseline = canvas.scene(&state).unwrap();
|
||||
let (_, midpoint) = bend_segment(&baseline, relation);
|
||||
let start = screen(&canvas, midpoint);
|
||||
let destination = Position {
|
||||
x: ((midpoint.x + 45.) / 5.).round() * 5.,
|
||||
y: ((midpoint.y + 30.) / 5.).round() * 5.,
|
||||
};
|
||||
let release = screen(&canvas, point(destination));
|
||||
let later_batch_cursor = release + Vector::new(137., 83.);
|
||||
motion(&canvas, &mut state, start, later_batch_cursor);
|
||||
input(
|
||||
&canvas,
|
||||
&mut state,
|
||||
mouse::Event::ButtonPressed(mouse::Button::Left),
|
||||
later_batch_cursor,
|
||||
);
|
||||
assert!(f.project.diagrams[&f.diagram].routes.is_empty());
|
||||
motion(&canvas, &mut state, release, later_batch_cursor);
|
||||
assert_eq!(
|
||||
state.bend_preview.as_ref().unwrap().waypoints,
|
||||
vec![destination]
|
||||
);
|
||||
assert_eq!(
|
||||
canvas.scene(&state).unwrap().routed.edges[&relation].pins,
|
||||
vec![destination]
|
||||
);
|
||||
let event = input(
|
||||
&canvas,
|
||||
&mut state,
|
||||
mouse::Event::ButtonReleased(mouse::Button::Left),
|
||||
later_batch_cursor,
|
||||
)
|
||||
.unwrap();
|
||||
assert!(
|
||||
matches!(&event, Event::SetBends { context, relation: id, waypoints }
|
||||
if *context == canvas.context && *id == relation && *waypoints == vec![destination])
|
||||
);
|
||||
assert!(state.bend_preview.is_none());
|
||||
assert!(
|
||||
input(
|
||||
&canvas,
|
||||
&mut state,
|
||||
mouse::Event::ButtonReleased(mouse::Button::Left),
|
||||
later_batch_cursor
|
||||
)
|
||||
.is_none()
|
||||
);
|
||||
let after = prepare_command(
|
||||
&f.project,
|
||||
&state_edit::plan(&f.project, canvas.context, &event)
|
||||
.unwrap()
|
||||
.command,
|
||||
)
|
||||
.unwrap()
|
||||
.project;
|
||||
let stored = &after.diagrams[&f.diagram].routes[0];
|
||||
assert_eq!(stored.waypoints, vec![destination]);
|
||||
assert!(
|
||||
stored.source_attachment.is_none()
|
||||
&& stored.target_attachment.is_none()
|
||||
&& stored.label.is_none()
|
||||
);
|
||||
assert_eq!(after.relations, f.project.relations);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn state_bends_authored_pin_move_preserves_full_project_and_exact_undo_redo() {
|
||||
for zoom in [0.5, 1., 2.] {
|
||||
let (mut f, relation) = bend_fixture(true);
|
||||
let mut other = f.project.diagrams[&f.diagram].clone();
|
||||
other.id = Id::new_v4();
|
||||
other.alias = "bend_reference_view".into();
|
||||
other.nodes = other
|
||||
.nodes
|
||||
.into_values()
|
||||
.map(|mut node| {
|
||||
node.id = Id::new_v4();
|
||||
node.alias = format!("bend_reference_{}", node.alias);
|
||||
(node.id, node)
|
||||
})
|
||||
.collect();
|
||||
let other_id = other.id;
|
||||
f.project.diagrams.insert(other_id, other.clone());
|
||||
validate_candidate(&f.project).unwrap();
|
||||
let original = f.project.diagrams[&f.diagram].routes[0].clone();
|
||||
let mut canvas = canvas(&f, Tool::Select, zoom);
|
||||
canvas.selected = relation;
|
||||
let mut state = State::default();
|
||||
let start = screen(&canvas, point(original.waypoints[0]));
|
||||
let destination = Position { x: 690., y: 365. };
|
||||
let release = screen(&canvas, point(destination));
|
||||
bend_press(&canvas, &mut state, start);
|
||||
motion(&canvas, &mut state, release, release);
|
||||
let preview = state.bend_preview.as_ref().unwrap();
|
||||
let mut intended = original.clone();
|
||||
intended.waypoints[0] = destination;
|
||||
assert_eq!(preview, &intended);
|
||||
assert_eq!(
|
||||
f.project.diagrams[&f.diagram].routes[0], original,
|
||||
"preview is transient"
|
||||
);
|
||||
let preview_scene = canvas.scene(&state).unwrap();
|
||||
let event = input(
|
||||
&canvas,
|
||||
&mut state,
|
||||
mouse::Event::ButtonReleased(mouse::Button::Left),
|
||||
release,
|
||||
)
|
||||
.unwrap();
|
||||
assert!(
|
||||
matches!(&event, Event::SetBends { waypoints, .. } if waypoints == &intended.waypoints)
|
||||
);
|
||||
let plan = state_edit::plan(&f.project, canvas.context, &event).unwrap();
|
||||
let mut expected = f.project.clone();
|
||||
expected.diagrams.get_mut(&f.diagram).unwrap().routes[0] = intended;
|
||||
let mut document = Document::from_project(f.project.clone(), Default::default()).unwrap();
|
||||
let before = document.bundle().clone();
|
||||
document.execute(plan.command).unwrap();
|
||||
assert_eq!(document.project(), &expected);
|
||||
assert_eq!(document.project().diagrams[&other_id], other);
|
||||
let committed_view = projection::project_view(document.project(), f.diagram);
|
||||
let committed = routing::route_diagram(
|
||||
document.project(),
|
||||
&document.project().diagrams[&f.diagram],
|
||||
&committed_view,
|
||||
);
|
||||
let preview_edge = &preview_scene.routed.edges[&relation];
|
||||
let committed_edge = &committed.edges[&relation];
|
||||
assert_eq!(preview_edge.points, committed_edge.points);
|
||||
assert_eq!(preview_edge.pin_fractions, committed_edge.pin_fractions);
|
||||
assert_eq!(preview_edge.warnings, committed_edge.warnings);
|
||||
let edited = document.bundle().clone();
|
||||
assert!(document.undo());
|
||||
assert_eq!(document.project(), &f.project);
|
||||
assert_eq!(document.bundle(), &before);
|
||||
assert!(!document.undo(), "one drag adds one history operation");
|
||||
assert!(document.redo());
|
||||
assert_eq!(document.project(), &expected);
|
||||
assert_eq!(document.bundle(), &edited);
|
||||
assert!(!document.redo());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn state_bends_stationary_and_out_and_back_restore_off_grid_or_automatic_route() {
|
||||
for authored in [false, true] {
|
||||
for zoom in [0.5, 1., 2.] {
|
||||
for travel in [false, true] {
|
||||
let (f, relation) = bend_fixture(authored);
|
||||
let mut canvas = canvas(&f, Tool::Select, zoom);
|
||||
canvas.selected = relation;
|
||||
let mut state = State::default();
|
||||
let scene = canvas.scene(&state).unwrap();
|
||||
let world = if authored {
|
||||
point(scene.routed.edges[&relation].pins[0])
|
||||
} else {
|
||||
bend_segment(&scene, relation).1
|
||||
};
|
||||
let start = screen(&canvas, world);
|
||||
bend_press(&canvas, &mut state, start);
|
||||
if travel {
|
||||
let away = start + Vector::new(45., 30.) * zoom;
|
||||
motion(&canvas, &mut state, away, away);
|
||||
assert!(state.bend_preview.is_some());
|
||||
motion(&canvas, &mut state, start, start);
|
||||
}
|
||||
assert!(
|
||||
input(
|
||||
&canvas,
|
||||
&mut state,
|
||||
mouse::Event::ButtonReleased(mouse::Button::Left),
|
||||
start
|
||||
)
|
||||
.is_none()
|
||||
);
|
||||
assert!(state.bend_preview.is_none());
|
||||
assert_eq!(
|
||||
canvas.scene(&state).unwrap().routed.edges[&relation].points,
|
||||
scene.routed.edges[&relation].points
|
||||
);
|
||||
assert_eq!(
|
||||
f.project.diagrams[&f.diagram].routes.len(),
|
||||
usize::from(authored)
|
||||
);
|
||||
if authored {
|
||||
assert_eq!(
|
||||
f.project.diagrams[&f.diagram].routes[0].waypoints,
|
||||
vec![Position {
|
||||
x: 650.25,
|
||||
y: 340.75
|
||||
}]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn state_bends_cancel_on_camera_context_focus_and_pointer_interruptions() {
|
||||
for cancellation in 0..16 {
|
||||
let (f, relation) = bend_fixture(true);
|
||||
let mut canvas = canvas(&f, Tool::Select, 1.);
|
||||
canvas.selected = relation;
|
||||
let mut state = State::default();
|
||||
let original = f.project.diagrams[&f.diagram].routes[0].clone();
|
||||
let start = screen(&canvas, point(original.waypoints[0]));
|
||||
let release = start + Vector::new(45., 30.);
|
||||
bend_press(&canvas, &mut state, start);
|
||||
motion(&canvas, &mut state, release, release);
|
||||
assert!(state.bend_preview.is_some(), "case {cancellation}");
|
||||
let mut release_bounds = bounds();
|
||||
match cancellation {
|
||||
0 => canvas.zoom = 2.,
|
||||
1 => canvas.pan.x += 10.,
|
||||
2 => canvas.context.epoch += 1,
|
||||
3 => canvas.context.revision += 1,
|
||||
4 => canvas.context.document = Id::new_v4(),
|
||||
5 => canvas.tool = Tool::Transition,
|
||||
6 => canvas.editable = false,
|
||||
7 | 8 => {
|
||||
input(
|
||||
&canvas,
|
||||
&mut state,
|
||||
mouse::Event::ButtonPressed(if cancellation == 7 {
|
||||
mouse::Button::Right
|
||||
} else {
|
||||
mouse::Button::Middle
|
||||
}),
|
||||
release,
|
||||
);
|
||||
}
|
||||
9 => {
|
||||
canvas::Program::update(
|
||||
&canvas,
|
||||
&mut state,
|
||||
&canvas::Event::Window(iced::window::Event::Unfocused),
|
||||
bounds(),
|
||||
mouse::Cursor::Available(release),
|
||||
);
|
||||
}
|
||||
10 => {
|
||||
input(
|
||||
&canvas,
|
||||
&mut state,
|
||||
mouse::Event::WheelScrolled {
|
||||
delta: mouse::ScrollDelta::Lines { x: 0., y: 1. },
|
||||
},
|
||||
release,
|
||||
);
|
||||
}
|
||||
11 => {
|
||||
input(&canvas, &mut state, mouse::Event::CursorLeft, release);
|
||||
}
|
||||
12 => {
|
||||
motion(&canvas, &mut state, Point::new(-100., -100.), release);
|
||||
}
|
||||
13 => release_bounds.x += 25.,
|
||||
15 => canvas.selected = f.b,
|
||||
_ => {
|
||||
let escape = canvas::Event::Keyboard(keyboard::Event::KeyPressed {
|
||||
key: keyboard::Key::Named(keyboard::key::Named::Escape),
|
||||
modified_key: keyboard::Key::Named(keyboard::key::Named::Escape),
|
||||
physical_key: keyboard::key::Physical::Code(keyboard::key::Code::Escape),
|
||||
location: keyboard::Location::Standard,
|
||||
modifiers: keyboard::Modifiers::empty(),
|
||||
text: None,
|
||||
repeat: false,
|
||||
});
|
||||
let event = canvas::Program::update(
|
||||
&canvas,
|
||||
&mut state,
|
||||
&escape,
|
||||
bounds(),
|
||||
mouse::Cursor::Available(release),
|
||||
)
|
||||
.and_then(|action| action.into_inner().0);
|
||||
assert!(matches!(event, Some(Event::Choose(Tool::Select))));
|
||||
}
|
||||
}
|
||||
let event = input_at_bounds(
|
||||
&canvas,
|
||||
&mut state,
|
||||
mouse::Event::ButtonReleased(mouse::Button::Left),
|
||||
release,
|
||||
release_bounds,
|
||||
);
|
||||
assert!(
|
||||
!matches!(event, Some(Event::SetBends { .. })),
|
||||
"late release committed case {cancellation}"
|
||||
);
|
||||
assert!(
|
||||
state.bend_preview.is_none(),
|
||||
"stale preview survived case {cancellation}"
|
||||
);
|
||||
assert_eq!(f.project.diagrams[&f.diagram].routes[0], original);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn state_bends_context_menu_distinguishes_authored_pin_from_computed_segment() {
|
||||
let (f, relation) = bend_fixture(true);
|
||||
let mut canvas = canvas(&f, Tool::Select, 1.);
|
||||
canvas.selected = relation;
|
||||
let mut state = State::default();
|
||||
let scene = canvas.scene(&state).unwrap();
|
||||
let pin = screen(&canvas, point(scene.routed.edges[&relation].pins[0]));
|
||||
motion(&canvas, &mut state, pin, pin);
|
||||
assert!(
|
||||
matches!(input(&canvas, &mut state, mouse::Event::ButtonPressed(mouse::Button::Right), pin),
|
||||
Some(Event::ContextMenu { context, object, placement: None, anchor, bend: Some(0), route_segment: None })
|
||||
if context == canvas.context && object == relation && anchor == pin)
|
||||
);
|
||||
let (index, midpoint) = bend_segment(&scene, relation);
|
||||
let at = screen(&canvas, midpoint);
|
||||
motion(&canvas, &mut state, at, at);
|
||||
assert!(
|
||||
matches!(input(&canvas, &mut state, mouse::Event::ButtonPressed(mouse::Button::Right), at),
|
||||
Some(Event::ContextMenu { context, object, placement: None, anchor, bend: None, route_segment: Some((segment, world)) })
|
||||
if context == canvas.context && object == relation && anchor == at && segment == index && point(world).distance(midpoint) < 0.001)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn state_bends_internal_rows_and_folded_proxies_cannot_acquire_pins() {
|
||||
for internal in [false, true] {
|
||||
let mut f = fixture();
|
||||
let relation = if internal {
|
||||
let id = f
|
||||
.project
|
||||
.relate(RelationKind::StateTransition, "Internal check", f.a, f.a);
|
||||
if let RelationBody::StateTransition {
|
||||
transition_kind, ..
|
||||
} = &mut f.project.relations.get_mut(&id).unwrap().body
|
||||
{
|
||||
*transition_kind = TransitionKind::Internal;
|
||||
}
|
||||
id
|
||||
} else {
|
||||
let id = f.project.relate(
|
||||
RelationKind::StateTransition,
|
||||
"Hidden child to standby",
|
||||
f.leaf,
|
||||
f.b,
|
||||
);
|
||||
let parent = placement(&f, f.a);
|
||||
f.project
|
||||
.diagrams
|
||||
.get_mut(&f.diagram)
|
||||
.unwrap()
|
||||
.nodes
|
||||
.get_mut(&parent)
|
||||
.unwrap()
|
||||
.collapsed = true;
|
||||
id
|
||||
};
|
||||
let mut canvas = canvas(&f, Tool::Select, 1.);
|
||||
canvas.selected = relation;
|
||||
let mut state = State::default();
|
||||
let scene = canvas.scene(&state).unwrap();
|
||||
let world = if internal {
|
||||
assert!(!scene.routed.edges.contains_key(&relation));
|
||||
let node = scene.view.nodes.iter().find(|n| n.element == f.a).unwrap();
|
||||
internal_rows(&f.project, node)
|
||||
.into_iter()
|
||||
.find(|(r, _)| r.id == relation)
|
||||
.unwrap()
|
||||
.1
|
||||
.center()
|
||||
} else {
|
||||
assert!(scene.routed.edges[&relation].custom_suspended);
|
||||
bend_segment(&scene, relation).1
|
||||
};
|
||||
let start = screen(&canvas, world);
|
||||
motion(&canvas, &mut state, start, start);
|
||||
assert!(matches!(
|
||||
input(
|
||||
&canvas,
|
||||
&mut state,
|
||||
mouse::Event::ButtonPressed(mouse::Button::Right),
|
||||
start
|
||||
),
|
||||
Some(Event::ContextMenu {
|
||||
bend: None,
|
||||
route_segment: None,
|
||||
..
|
||||
})
|
||||
));
|
||||
bend_press(&canvas, &mut state, start);
|
||||
let away = start + Vector::new(30., 20.);
|
||||
motion(&canvas, &mut state, away, away);
|
||||
assert!(state.bend_preview.is_none());
|
||||
assert!(!matches!(
|
||||
input(
|
||||
&canvas,
|
||||
&mut state,
|
||||
mouse::Event::ButtonReleased(mouse::Button::Left),
|
||||
away
|
||||
),
|
||||
Some(Event::SetBends { .. })
|
||||
));
|
||||
assert!(f.project.diagrams[&f.diagram].routes.is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn state_bends_right_click_discards_provisional_indexes_before_building_menu() {
|
||||
for click_pin in [true, false] {
|
||||
let (mut f, relation) = bend_fixture(true);
|
||||
let route = &mut f.project.diagrams.get_mut(&f.diagram).unwrap().routes[0];
|
||||
route.waypoints = vec![Position { x: 650., y: 340. }, Position { x: 650., y: 390. }];
|
||||
validate_candidate(&f.project).unwrap();
|
||||
let original = f.project.diagrams[&f.diagram].routes[0].clone();
|
||||
let mut canvas = canvas(&f, Tool::Select, 1.);
|
||||
canvas.selected = relation;
|
||||
let mut state = State::default();
|
||||
let baseline = canvas.scene(&state).unwrap();
|
||||
let edge = &baseline.routed.edges[&relation];
|
||||
let candidates: Vec<_> = edge.points.windows(2).enumerate()
|
||||
.filter(|(i, _)| *i > 0 && *i + 2 < edge.points.len())
|
||||
.map(|(i, p)| (i, Point::new((p[0].x + p[1].x) / 2., (p[0].y + p[1].y) / 2.)))
|
||||
.filter(|(_, p)| edge.pins.iter().all(|pin| p.distance(point(*pin)) > 20.))
|
||||
.filter(|(_, p)| matches!(canvas.hit(&baseline, *p), Some(Hit::Transition(id)) if id == relation))
|
||||
.filter(|(_, p)| !Rectangle::new(point(edge.label.bounds.position), Size::new(edge.label.bounds.size.width, edge.label.bounds.size.height)).contains(*p))
|
||||
.collect();
|
||||
let (_, insertion_at) = candidates
|
||||
.iter()
|
||||
.copied()
|
||||
.find(|(i, p)| routing::pin_insertion_index(edge, *i, position(*p)) == 0)
|
||||
.expect("exposed segment before both authored pins");
|
||||
let menu_segment = candidates
|
||||
.iter()
|
||||
.copied()
|
||||
.find(|(_, p)| p.distance(insertion_at) > 30.)
|
||||
.expect("a distinct committed segment for the menu control");
|
||||
let start = screen(&canvas, insertion_at);
|
||||
bend_press(&canvas, &mut state, start);
|
||||
let away = start + Vector::new(45., 30.);
|
||||
motion(&canvas, &mut state, away, away);
|
||||
let preview = state.bend_preview.as_ref().unwrap();
|
||||
assert_eq!(preview.waypoints.len(), 3);
|
||||
assert_eq!(
|
||||
&preview.waypoints[1..],
|
||||
original.waypoints.as_slice(),
|
||||
"provisional insertion shifts both stored indices"
|
||||
);
|
||||
|
||||
// With the left gesture still active, moving to the last stored pin also
|
||||
// moves provisional pin0 there. The preview's first hit is therefore
|
||||
// pin0, but a menu built after cancellation must identify stored pin1.
|
||||
let menu_world = if click_pin {
|
||||
point(original.waypoints[1])
|
||||
} else {
|
||||
menu_segment.1
|
||||
};
|
||||
let menu_window = screen(&canvas, menu_world);
|
||||
motion(&canvas, &mut state, menu_window, menu_window);
|
||||
assert!(state.bend_preview.is_some());
|
||||
let menu = input(
|
||||
&canvas,
|
||||
&mut state,
|
||||
mouse::Event::ButtonPressed(mouse::Button::Right),
|
||||
menu_window,
|
||||
)
|
||||
.unwrap();
|
||||
let Event::ContextMenu {
|
||||
context,
|
||||
object,
|
||||
bend,
|
||||
route_segment,
|
||||
..
|
||||
} = menu
|
||||
else {
|
||||
panic!("expected context menu after cancelling drag")
|
||||
};
|
||||
assert_eq!(context, canvas.context);
|
||||
assert_eq!(object, relation);
|
||||
assert!(state.bend_preview.is_none());
|
||||
assert_eq!(
|
||||
canvas.scene(&state).unwrap().routed.edges[&relation].points,
|
||||
edge.points
|
||||
);
|
||||
if click_pin {
|
||||
assert_eq!(
|
||||
bend,
|
||||
Some(1),
|
||||
"menu index must address the stored route, not the provisional route"
|
||||
);
|
||||
assert!(route_segment.is_none());
|
||||
let remove = Event::RemoveBend {
|
||||
context,
|
||||
relation,
|
||||
index: bend.unwrap(),
|
||||
};
|
||||
let plan = state_edit::plan(&f.project, context, &remove).unwrap();
|
||||
let after = prepare_command(&f.project, &plan.command).unwrap().project;
|
||||
let mut expected = f.project.clone();
|
||||
expected.diagrams.get_mut(&f.diagram).unwrap().routes[0]
|
||||
.waypoints
|
||||
.remove(1);
|
||||
assert_eq!(
|
||||
after, expected,
|
||||
"remove menu action must delete exactly the addressed original pin"
|
||||
);
|
||||
} else {
|
||||
assert!(
|
||||
bend.is_none(),
|
||||
"provisional pin under cursor must not leak into menu"
|
||||
);
|
||||
let (segment, at) = route_segment.expect("committed route segment remains actionable");
|
||||
assert_eq!(segment, menu_segment.0);
|
||||
assert!(point(at).distance(menu_world) < 0.001);
|
||||
}
|
||||
assert!(
|
||||
input(
|
||||
&canvas,
|
||||
&mut state,
|
||||
mouse::Event::ButtonReleased(mouse::Button::Left),
|
||||
menu_window
|
||||
)
|
||||
.is_none()
|
||||
);
|
||||
assert_eq!(f.project.diagrams[&f.diagram].routes[0], original);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn state_bends_draw_before_update_excludes_preview_after_camera_or_bounds_change() {
|
||||
for change in 0..4 {
|
||||
let (f, relation) = bend_fixture(true);
|
||||
let mut canvas = canvas(&f, Tool::Select, 1.);
|
||||
canvas.selected = relation;
|
||||
let mut state = State::default();
|
||||
let baseline = canvas.scene_with_bounds(&state, Some(bounds())).unwrap();
|
||||
let start = screen(&canvas, point(baseline.routed.edges[&relation].pins[0]));
|
||||
let release = start + Vector::new(45., 30.);
|
||||
bend_press(&canvas, &mut state, start);
|
||||
motion(&canvas, &mut state, release, release);
|
||||
let displayed_preview = canvas.scene_with_bounds(&state, Some(bounds())).unwrap();
|
||||
assert_ne!(
|
||||
displayed_preview.routed.edges[&relation].pins,
|
||||
baseline.routed.edges[&relation].pins
|
||||
);
|
||||
let mut changed_bounds = bounds();
|
||||
match change {
|
||||
0 => canvas.zoom = 2.,
|
||||
1 => canvas.pan.y += 25.,
|
||||
2 => changed_bounds.x += 35.,
|
||||
_ => changed_bounds.width -= 90.,
|
||||
}
|
||||
// No update event between camera/layout change and this draw-time read.
|
||||
let shown = canvas
|
||||
.scene_with_bounds(&state, Some(changed_bounds))
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
shown.routed.edges[&relation].pins, baseline.routed.edges[&relation].pins,
|
||||
"stale draw-time pins for case {change}"
|
||||
);
|
||||
assert_eq!(
|
||||
shown.routed.edges[&relation].points, baseline.routed.edges[&relation].points,
|
||||
"stale cached preview for case {change}"
|
||||
);
|
||||
let event = input_at_bounds(
|
||||
&canvas,
|
||||
&mut state,
|
||||
mouse::Event::ButtonReleased(mouse::Button::Left),
|
||||
release,
|
||||
changed_bounds,
|
||||
);
|
||||
assert!(!matches!(event, Some(Event::SetBends { .. })));
|
||||
assert!(state.bend_preview.is_none());
|
||||
}
|
||||
}
|
||||
@@ -43,8 +43,12 @@ pub struct State {
|
||||
press: Option<Press>,
|
||||
source: Option<Id>,
|
||||
preview: Option<(Id, Position)>,
|
||||
attachment_preview: Option<AttachmentPreview>,
|
||||
bend: Option<BendGesture>,
|
||||
bend_preview: Option<EdgeRoute>,
|
||||
pan_from: Option<(mouse::Button, Point)>,
|
||||
viewport: Option<Size>,
|
||||
attachment_viewport: Option<(f32, Vector, Rectangle)>,
|
||||
scene: RefCell<Option<CachedScene>>,
|
||||
geometry: canvas::Cache,
|
||||
paint_key: RefCell<Option<PaintKey>>,
|
||||
@@ -76,6 +80,30 @@ enum Press {
|
||||
/// Handles require a drag; an explicitly chosen reconnect tool accepts a click.
|
||||
start: Option<Point>,
|
||||
},
|
||||
Attachment {
|
||||
relation: Id,
|
||||
end: EdgeEnd,
|
||||
placement: Id,
|
||||
start: Point,
|
||||
},
|
||||
Bend {
|
||||
relation: Id,
|
||||
},
|
||||
}
|
||||
|
||||
struct BendGesture {
|
||||
start: Point,
|
||||
route: EdgeRoute,
|
||||
index: usize,
|
||||
baseline: Arc<Scene>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
struct AttachmentPreview {
|
||||
relation: Id,
|
||||
end: EdgeEnd,
|
||||
placement: Id,
|
||||
attachment: EdgeAttachment,
|
||||
}
|
||||
|
||||
struct Scene {
|
||||
@@ -86,12 +114,16 @@ struct Scene {
|
||||
struct CachedScene {
|
||||
context: Context,
|
||||
preview: Option<(Id, Position)>,
|
||||
attachment_preview: Option<AttachmentPreview>,
|
||||
bend_preview: Option<EdgeRoute>,
|
||||
scene: Arc<Scene>,
|
||||
}
|
||||
#[derive(PartialEq)]
|
||||
struct PaintKey {
|
||||
context: Context,
|
||||
preview: Option<(Id, Position)>,
|
||||
attachment_preview: Option<AttachmentPreview>,
|
||||
bend_preview: Option<EdgeRoute>,
|
||||
selected: Id,
|
||||
zoom: f32,
|
||||
pan: Vector,
|
||||
@@ -104,9 +136,16 @@ enum Hit {
|
||||
}
|
||||
|
||||
impl State {
|
||||
fn cancel_gesture(&mut self) {
|
||||
fn cancel_edit(&mut self) {
|
||||
self.press = None;
|
||||
self.preview = None;
|
||||
self.attachment_preview = None;
|
||||
self.bend = None;
|
||||
self.bend_preview = None;
|
||||
self.attachment_viewport = None;
|
||||
}
|
||||
fn cancel_gesture(&mut self) {
|
||||
self.cancel_edit();
|
||||
self.pan_from = None;
|
||||
}
|
||||
fn reset(&mut self) {
|
||||
@@ -649,20 +688,36 @@ impl StateCanvas<'_> {
|
||||
&& state_edit::validate_context(self.project, self.context, self.context).is_ok()
|
||||
}
|
||||
fn scene(&self, state: &State) -> Option<Arc<Scene>> {
|
||||
self.scene_with_bounds(state, None)
|
||||
}
|
||||
fn scene_with_bounds(&self, state: &State, bounds: Option<Rectangle>) -> Option<Arc<Scene>> {
|
||||
if !self.valid() {
|
||||
return None;
|
||||
}
|
||||
let route_active = self.gesture_active(state) && self.route_viewport_current(state, bounds);
|
||||
let preview = self
|
||||
.gesture_active(state)
|
||||
.then_some(state.preview)
|
||||
.flatten();
|
||||
let attachment_preview = route_active.then_some(state.attachment_preview).flatten();
|
||||
let bend_preview = route_active.then(|| state.bend_preview.clone()).flatten();
|
||||
if let Some(cached) = state.scene.borrow().as_ref()
|
||||
&& cached.context == self.context
|
||||
&& cached.preview == preview
|
||||
&& cached.attachment_preview == attachment_preview
|
||||
&& cached.bend_preview == bend_preview
|
||||
{
|
||||
return Some(cached.scene.clone());
|
||||
}
|
||||
let mut diagram = self.project.diagrams.get(&self.diagram)?.clone();
|
||||
if let Some(route) = &bend_preview {
|
||||
crate::route_edit::with_route(&mut diagram, route.clone());
|
||||
}
|
||||
if let Some(preview) = attachment_preview {
|
||||
let mut route = crate::route_edit::stored_route(&diagram, preview.relation);
|
||||
route.set_attachment(preview.end, Some(preview.attachment));
|
||||
crate::route_edit::with_route(&mut diagram, route);
|
||||
}
|
||||
if let Some((id, at)) = preview
|
||||
&& let Some(node) = diagram.nodes.get(&id)
|
||||
{
|
||||
@@ -687,7 +742,17 @@ impl StateCanvas<'_> {
|
||||
}
|
||||
}
|
||||
let view = projection::project_diagram(self.project, &diagram);
|
||||
let routed = routing::route_diagram(self.project, &diagram, &view);
|
||||
let routed = if let Some(gesture) = state.bend.as_ref().filter(|_| bend_preview.is_some()) {
|
||||
routing::route_edge_preview(
|
||||
self.project,
|
||||
&diagram,
|
||||
&view,
|
||||
&gesture.baseline.routed,
|
||||
gesture.route.edge,
|
||||
)
|
||||
} else {
|
||||
routing::route_diagram(self.project, &diagram, &view)
|
||||
};
|
||||
let symbol_labels = symbol_labels(self.project, &view, &routed);
|
||||
let scene = Arc::new(Scene {
|
||||
view,
|
||||
@@ -697,6 +762,8 @@ impl StateCanvas<'_> {
|
||||
*state.scene.borrow_mut() = Some(CachedScene {
|
||||
context: self.context,
|
||||
preview,
|
||||
attachment_preview,
|
||||
bend_preview,
|
||||
scene: scene.clone(),
|
||||
});
|
||||
Some(scene)
|
||||
@@ -828,6 +895,84 @@ impl StateCanvas<'_> {
|
||||
.min_by(|a, b| a.1.total_cmp(&b.1))
|
||||
.map(|(endpoint, _)| (route.id, endpoint))
|
||||
}
|
||||
fn bend_at(&self, scene: &Scene, world: Point) -> Option<usize> {
|
||||
let edge = scene.routed.edges.get(&self.selected)?;
|
||||
if edge.custom_suspended {
|
||||
return None;
|
||||
}
|
||||
edge.pins
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(index, pin)| {
|
||||
let distance = world.distance(point(*pin));
|
||||
(distance <= 8. / self.scale()).then_some((index, distance))
|
||||
})
|
||||
.min_by(|a, b| a.1.total_cmp(&b.1).then(a.0.cmp(&b.0)))
|
||||
.map(|(index, _)| index)
|
||||
}
|
||||
/// Preserve the rendered traversal index; overlapping runs can have the
|
||||
/// same world point but different positions among the authored pins.
|
||||
fn segment_at(&self, scene: &Scene, relation: Id, world: Point) -> Option<(usize, Position)> {
|
||||
let edge = scene.routed.edges.get(&relation)?;
|
||||
if edge.custom_suspended {
|
||||
return None;
|
||||
}
|
||||
edge.points
|
||||
.windows(2)
|
||||
.enumerate()
|
||||
.filter(|(index, _)| *index > 0 && index + 2 < edge.points.len())
|
||||
.filter_map(|(index, span)| {
|
||||
let projection = routing::project_onto_polyline(span, position(world))?;
|
||||
(projection.distance <= 7. / self.scale()).then_some((index, projection.distance))
|
||||
})
|
||||
.min_by(|a, b| a.1.total_cmp(&b.1).then(a.0.cmp(&b.0)))
|
||||
.map(|(index, _)| (index, position(world)))
|
||||
}
|
||||
fn begin_bend(
|
||||
&self,
|
||||
state: &mut State,
|
||||
scene: Arc<Scene>,
|
||||
window: Point,
|
||||
route: EdgeRoute,
|
||||
index: usize,
|
||||
bounds: Rectangle,
|
||||
) {
|
||||
state.press = Some(Press::Bend {
|
||||
relation: route.edge,
|
||||
});
|
||||
state.attachment_viewport = Some((self.zoom, self.pan, bounds));
|
||||
state.bend = Some(BendGesture {
|
||||
start: window,
|
||||
route,
|
||||
index,
|
||||
baseline: scene,
|
||||
});
|
||||
state.bend_preview = None;
|
||||
}
|
||||
fn move_bend_pointer(&self, state: &mut State, window: Point, local: Point) {
|
||||
let Some(gesture) = &state.bend else {
|
||||
return;
|
||||
};
|
||||
if window.distance(gesture.start) < 3. {
|
||||
// Also discard a provisional insertion. The exact original route
|
||||
// comes from the model, so an off-grid pin is never quantized here.
|
||||
state.bend_preview = None;
|
||||
return;
|
||||
}
|
||||
let world = self.world(local);
|
||||
if !world.x.is_finite() || !world.y.is_finite() {
|
||||
state.cancel_gesture();
|
||||
return;
|
||||
}
|
||||
let mut changed = gesture.route.clone();
|
||||
changed.waypoints[gesture.index] = Position {
|
||||
x: (world.x / 5.).round() * 5.,
|
||||
y: (world.y / 5.).round() * 5.,
|
||||
};
|
||||
let original =
|
||||
crate::route_edit::stored_route(&self.project.diagrams[&self.diagram], changed.edge);
|
||||
state.bend_preview = (changed != original).then_some(changed);
|
||||
}
|
||||
fn owner_at(&self, scene: &Scene, world: Point, kind: Kind) -> Option<Id> {
|
||||
self.node_at(scene, world)
|
||||
.filter(|n| state_edit::eligible_owner(self.project, self.diagram, n.element, kind))
|
||||
@@ -856,12 +1001,98 @@ impl StateCanvas<'_> {
|
||||
}
|
||||
}
|
||||
fn gesture_active(&self, state: &State) -> bool {
|
||||
self.editable && state.context == Some(self.context) && state.tool == Some(self.tool)
|
||||
self.editable
|
||||
&& state.context == Some(self.context)
|
||||
&& state.tool == Some(self.tool)
|
||||
&& state
|
||||
.bend
|
||||
.as_ref()
|
||||
.is_none_or(|g| g.route.edge == self.selected)
|
||||
}
|
||||
fn route_viewport_current(&self, state: &State, bounds: Option<Rectangle>) -> bool {
|
||||
state
|
||||
.attachment_viewport
|
||||
.is_none_or(|(zoom, pan, captured)| {
|
||||
zoom == self.zoom
|
||||
&& pan == self.pan
|
||||
&& bounds.is_none_or(|current| current == captured)
|
||||
})
|
||||
}
|
||||
fn move_attachment_pointer(&self, state: &mut State, window: Point, local: Point) {
|
||||
let Some(Press::Attachment {
|
||||
relation,
|
||||
end,
|
||||
placement,
|
||||
start,
|
||||
}) = state.press
|
||||
else {
|
||||
return;
|
||||
};
|
||||
if window.distance(start) < 3. {
|
||||
// Returning to the press restores the exact persisted optional value,
|
||||
// without quantizing an existing attachment or pinning an automatic one.
|
||||
state.attachment_preview = None;
|
||||
return;
|
||||
}
|
||||
let Some(owner) = state_edit::attachment_node(self.project, self.diagram, relation, end)
|
||||
.filter(|owner| owner.id == placement)
|
||||
else {
|
||||
state.cancel_gesture();
|
||||
return;
|
||||
};
|
||||
let diagram = &self.project.diagrams[&self.diagram];
|
||||
let previous = state
|
||||
.attachment_preview
|
||||
.map(|preview| preview.attachment.side)
|
||||
.or_else(|| {
|
||||
diagram
|
||||
.routes
|
||||
.iter()
|
||||
.find(|route| route.edge == relation)
|
||||
.and_then(|route| route.attachment(end))
|
||||
.map(|attachment| attachment.side)
|
||||
});
|
||||
let world = self.world(local);
|
||||
if !world.x.is_finite() || !world.y.is_finite() {
|
||||
state.cancel_gesture();
|
||||
return;
|
||||
}
|
||||
let attachment =
|
||||
routing::attachment_from_point(&owner, position(world), previous, 6. / self.scale());
|
||||
state.attachment_preview = Some(AttachmentPreview {
|
||||
relation,
|
||||
end,
|
||||
placement,
|
||||
attachment,
|
||||
});
|
||||
}
|
||||
fn guidance(&self, state: &State, scene: &Scene, world: Option<Point>) -> String {
|
||||
if !self.editable {
|
||||
return "Pending edits · apply or cancel them before editing the diagram".into();
|
||||
}
|
||||
if state.bend.is_some()
|
||||
&& self.gesture_active(state)
|
||||
&& self.route_viewport_current(state, None)
|
||||
{
|
||||
return "Move bend · release to keep · Esc cancels".into();
|
||||
}
|
||||
if self.tool == Tool::Select
|
||||
&& state.press.is_none()
|
||||
&& scene
|
||||
.routed
|
||||
.edges
|
||||
.get(&self.selected)
|
||||
.is_some_and(|edge| !edge.custom_suspended)
|
||||
{
|
||||
return "Drag line to add a bend · squares move bends · right-click a square to remove"
|
||||
.into();
|
||||
}
|
||||
if let Tool::AdjustAttachment { relation, end } = self.tool {
|
||||
return format!(
|
||||
"Adjust {end:?} attachment of {} · drag that tip around its existing vertex boundary · Esc cancels · relation unchanged",
|
||||
self.project.named(relation)
|
||||
);
|
||||
}
|
||||
let hovered = world.and_then(|p| self.vertex_at(scene, p));
|
||||
let press = self.gesture_active(state).then_some(state.press).flatten();
|
||||
let source = self.gesture_active(state).then_some(state.source).flatten();
|
||||
@@ -950,10 +1181,24 @@ impl canvas::Program<Event> for StateCanvas<'_> {
|
||||
state.tool = Some(self.tool);
|
||||
}
|
||||
if !self.editable {
|
||||
state.press = None;
|
||||
state.preview = None;
|
||||
// Pending edits block model changes, but read-only panning remains
|
||||
// available and must survive successive pointer events.
|
||||
state.cancel_edit();
|
||||
state.source = None;
|
||||
}
|
||||
if state
|
||||
.bend
|
||||
.as_ref()
|
||||
.is_some_and(|g| g.route.edge != self.selected)
|
||||
{
|
||||
state.cancel_gesture();
|
||||
}
|
||||
if state
|
||||
.attachment_viewport
|
||||
.is_some_and(|view| view != (self.zoom, self.pan, bounds))
|
||||
{
|
||||
state.cancel_gesture();
|
||||
}
|
||||
// Winit positions are ordered events. The cursor supplied by Iced is the
|
||||
// final cursor for an entire batch and cannot reinterpret earlier clicks.
|
||||
let cursor = match event {
|
||||
@@ -963,6 +1208,9 @@ impl canvas::Program<Event> for StateCanvas<'_> {
|
||||
}
|
||||
canvas::Event::Mouse(mouse::Event::CursorLeft) => {
|
||||
state.pointer = None;
|
||||
if state.bend.is_some() {
|
||||
state.cancel_gesture();
|
||||
}
|
||||
cursor
|
||||
}
|
||||
canvas::Event::Mouse(
|
||||
@@ -981,6 +1229,11 @@ impl canvas::Program<Event> for StateCanvas<'_> {
|
||||
state.reset();
|
||||
return None;
|
||||
}
|
||||
canvas::Event::Window(iced::window::Event::Resized(_)) => {
|
||||
state.cancel_gesture();
|
||||
state.viewport = None;
|
||||
return None;
|
||||
}
|
||||
_ => cursor,
|
||||
};
|
||||
let window = cursor.position();
|
||||
@@ -1053,10 +1306,23 @@ impl canvas::Program<Event> for StateCanvas<'_> {
|
||||
}
|
||||
if *button == mouse::Button::Right {
|
||||
state.reset();
|
||||
let (object, placement) = match self.hit(&scene, world) {
|
||||
Some(Hit::Node { element, placement }) => (element, Some(placement)),
|
||||
Some(Hit::Transition(id) | Hit::StateAction(id)) => (id, None),
|
||||
None => (self.diagram, None),
|
||||
// A canceled provisional pin shifts indices in its preview.
|
||||
// Menu commands must target the committed route instead.
|
||||
let scene = self.scene(state)?;
|
||||
let bend = self.bend_at(&scene, world);
|
||||
let (object, placement) = if bend.is_some() {
|
||||
(self.selected, None)
|
||||
} else {
|
||||
match self.hit(&scene, world) {
|
||||
Some(Hit::Node { element, placement }) => (element, Some(placement)),
|
||||
Some(Hit::Transition(id) | Hit::StateAction(id)) => (id, None),
|
||||
None => (self.diagram, None),
|
||||
}
|
||||
};
|
||||
let route_segment = if bend.is_none() {
|
||||
self.segment_at(&scene, object, world)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
return Some(
|
||||
Action::publish(Event::ContextMenu {
|
||||
@@ -1064,6 +1330,8 @@ impl canvas::Program<Event> for StateCanvas<'_> {
|
||||
object,
|
||||
placement,
|
||||
anchor: window,
|
||||
bend,
|
||||
route_segment,
|
||||
})
|
||||
.and_capture(),
|
||||
);
|
||||
@@ -1081,6 +1349,14 @@ impl canvas::Program<Event> for StateCanvas<'_> {
|
||||
});
|
||||
return Some(Action::capture());
|
||||
}
|
||||
if let Some(index) = self.bend_at(&scene, world) {
|
||||
let route = crate::route_edit::stored_route(
|
||||
&self.project.diagrams[&self.diagram],
|
||||
self.selected,
|
||||
);
|
||||
self.begin_bend(state, scene.clone(), window, route, index, bounds);
|
||||
return Some(Action::capture());
|
||||
}
|
||||
match self.hit(&scene, world) {
|
||||
Some(Hit::Node { placement, element }) => {
|
||||
let original = self
|
||||
@@ -1101,6 +1377,36 @@ impl canvas::Program<Event> for StateCanvas<'_> {
|
||||
)
|
||||
}
|
||||
Some(Hit::Transition(id) | Hit::StateAction(id)) => {
|
||||
if id == self.selected
|
||||
&& let Some(edge) = scene.routed.edges.get(&id)
|
||||
&& !Rectangle::new(
|
||||
point(edge.label.bounds.position),
|
||||
Size::new(
|
||||
edge.label.bounds.size.width,
|
||||
edge.label.bounds.size.height,
|
||||
),
|
||||
)
|
||||
.contains(world)
|
||||
&& let Some((segment, at)) = self.segment_at(&scene, id, world)
|
||||
{
|
||||
let mut route = crate::route_edit::stored_route(
|
||||
&self.project.diagrams[&self.diagram],
|
||||
id,
|
||||
);
|
||||
if let Some(index) = crate::route_edit::insert_pin_on_segment(
|
||||
&mut route, edge, segment, at,
|
||||
) {
|
||||
self.begin_bend(
|
||||
state,
|
||||
scene.clone(),
|
||||
window,
|
||||
route,
|
||||
index,
|
||||
bounds,
|
||||
);
|
||||
return Some(Action::capture());
|
||||
}
|
||||
}
|
||||
Some(Action::publish(Event::Select(self.context, id)).and_capture())
|
||||
}
|
||||
None => {
|
||||
@@ -1142,6 +1448,26 @@ impl canvas::Program<Event> for StateCanvas<'_> {
|
||||
});
|
||||
Some(Action::capture())
|
||||
}
|
||||
Tool::AdjustAttachment { relation, end } => {
|
||||
let owner =
|
||||
state_edit::attachment_node(self.project, self.diagram, relation, end)?;
|
||||
let route = scene.routed.edges.get(&relation)?;
|
||||
let tip = match end {
|
||||
EdgeEnd::Source => route.points.first(),
|
||||
EdgeEnd::Target => route.points.last(),
|
||||
}?;
|
||||
if world.distance(point(*tip)) > 10. / self.scale() {
|
||||
return None;
|
||||
}
|
||||
state.attachment_viewport = Some((self.zoom, self.pan, bounds));
|
||||
state.press = Some(Press::Attachment {
|
||||
relation,
|
||||
end,
|
||||
placement: owner.id,
|
||||
start: window,
|
||||
});
|
||||
Some(Action::capture())
|
||||
}
|
||||
}
|
||||
}
|
||||
canvas::Event::Mouse(mouse::Event::CursorMoved { .. }) => {
|
||||
@@ -1156,6 +1482,10 @@ impl canvas::Program<Event> for StateCanvas<'_> {
|
||||
}
|
||||
}
|
||||
self.move_pointer(state, window);
|
||||
if let Some(local) = local {
|
||||
self.move_attachment_pointer(state, window, local);
|
||||
self.move_bend_pointer(state, window, local);
|
||||
}
|
||||
Some(Action::request_redraw())
|
||||
}
|
||||
canvas::Event::Mouse(mouse::Event::ButtonReleased(button)) => {
|
||||
@@ -1176,16 +1506,49 @@ impl canvas::Program<Event> for StateCanvas<'_> {
|
||||
}
|
||||
if let Some(window) = window {
|
||||
self.move_pointer(state, window);
|
||||
if let Some(local) = local {
|
||||
self.move_attachment_pointer(state, window, local);
|
||||
self.move_bend_pointer(state, window, local);
|
||||
}
|
||||
}
|
||||
let press = state.press.take()?;
|
||||
state.attachment_viewport = None;
|
||||
let preview = state.preview.take();
|
||||
let attachment_preview = state.attachment_preview.take();
|
||||
let bend_preview = state.bend_preview.take();
|
||||
state.bend = None;
|
||||
let world = local.map(|p| self.world(p));
|
||||
let event = match press {
|
||||
Press::Bend { relation } if inside => bend_preview
|
||||
.filter(|route| route.edge == relation)
|
||||
.map(|route| Event::SetBends {
|
||||
context: self.context,
|
||||
relation,
|
||||
waypoints: route.waypoints,
|
||||
}),
|
||||
Press::Move { node, .. } => preview.map(|(_, position)| Event::Move {
|
||||
context: self.context,
|
||||
node,
|
||||
position,
|
||||
}),
|
||||
Press::Attachment {
|
||||
relation,
|
||||
end,
|
||||
placement,
|
||||
..
|
||||
} if inside => attachment_preview
|
||||
.filter(|preview| {
|
||||
preview.relation == relation
|
||||
&& preview.end == end
|
||||
&& preview.placement == placement
|
||||
})
|
||||
.map(|preview| Event::SetAttachment {
|
||||
context: self.context,
|
||||
relation,
|
||||
end,
|
||||
placement,
|
||||
attachment: Some(preview.attachment),
|
||||
}),
|
||||
Press::Create { owner, kind, start }
|
||||
if inside
|
||||
&& window?.distance(start) < 3.
|
||||
@@ -1273,15 +1636,19 @@ impl canvas::Program<Event> for StateCanvas<'_> {
|
||||
bounds: Rectangle,
|
||||
cursor: mouse::Cursor,
|
||||
) -> Vec<canvas::Geometry> {
|
||||
let Some(scene) = self.scene(state) else {
|
||||
let Some(scene) = self.scene_with_bounds(state, Some(bounds)) else {
|
||||
return vec![];
|
||||
};
|
||||
let route_active =
|
||||
self.gesture_active(state) && self.route_viewport_current(state, Some(bounds));
|
||||
let key = PaintKey {
|
||||
context: self.context,
|
||||
preview: self
|
||||
.gesture_active(state)
|
||||
.then_some(state.preview)
|
||||
.flatten(),
|
||||
attachment_preview: route_active.then_some(state.attachment_preview).flatten(),
|
||||
bend_preview: route_active.then(|| state.bend_preview.clone()).flatten(),
|
||||
selected: self.selected,
|
||||
zoom: self.scale(),
|
||||
pan: self.pan,
|
||||
@@ -1361,6 +1728,22 @@ impl canvas::Program<Event> for StateCanvas<'_> {
|
||||
style::MUTED,
|
||||
);
|
||||
if active {
|
||||
if !edge.custom_suspended && self.tool == Tool::Select {
|
||||
for pin in &edge.pins {
|
||||
let radius = 4. / self.scale();
|
||||
let handle = Path::rectangle(
|
||||
point(*pin) - Vector::new(radius, radius),
|
||||
Size::new(radius * 2., radius * 2.),
|
||||
);
|
||||
frame.fill(&handle, Color::WHITE);
|
||||
frame.stroke(
|
||||
&handle,
|
||||
Stroke::default()
|
||||
.with_color(style::TEAL)
|
||||
.with_width(1.6 / self.scale()),
|
||||
);
|
||||
}
|
||||
}
|
||||
for end in [edge.points.first(), edge.points.last()]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
@@ -1391,6 +1774,20 @@ impl canvas::Program<Event> for StateCanvas<'_> {
|
||||
.with_width(2.5 / self.scale()),
|
||||
);
|
||||
}
|
||||
if let Tool::AdjustAttachment { relation, end } = self.tool
|
||||
&& let Some(route) = scene.routed.edges.get(&relation)
|
||||
&& let Some(tip) = match end {
|
||||
EdgeEnd::Source => route.points.first(),
|
||||
EdgeEnd::Target => route.points.last(),
|
||||
}
|
||||
{
|
||||
frame.stroke(
|
||||
&Path::circle(point(*tip), 9. / self.scale()),
|
||||
Stroke::default()
|
||||
.with_color(style::TEAL)
|
||||
.with_width(2. / self.scale()),
|
||||
);
|
||||
}
|
||||
if let Some(at) = world
|
||||
&& self.editable
|
||||
{
|
||||
@@ -1761,6 +2158,8 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::document::Document;
|
||||
|
||||
include!("state_bend_tests.rs");
|
||||
|
||||
struct Fixture {
|
||||
project: Project,
|
||||
diagram: Id,
|
||||
@@ -2216,7 +2615,7 @@ mod tests {
|
||||
motion(&canvas, &mut state, at, at);
|
||||
assert!(matches!(input(&canvas, &mut state,
|
||||
mouse::Event::ButtonPressed(mouse::Button::Right), at),
|
||||
Some(Event::ContextMenu { context, object, placement: Some(node), anchor })
|
||||
Some(Event::ContextMenu { context, object, placement: Some(node), anchor, .. })
|
||||
if context == canvas.context && object == f.b
|
||||
&& node == placement(&f, f.b) && anchor == at));
|
||||
let background = Point::new(
|
||||
@@ -2226,7 +2625,7 @@ mod tests {
|
||||
motion(&canvas, &mut state, background, background);
|
||||
assert!(matches!(input(&canvas, &mut state,
|
||||
mouse::Event::ButtonPressed(mouse::Button::Right), background),
|
||||
Some(Event::ContextMenu { context, object, placement: None, anchor })
|
||||
Some(Event::ContextMenu { context, object, placement: None, anchor, .. })
|
||||
if context == canvas.context && object == f.diagram && anchor == background));
|
||||
}
|
||||
|
||||
@@ -2483,6 +2882,242 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicit_attachment_drag_is_view_only_and_one_source_history_operation() {
|
||||
for end in [EdgeEnd::Source, EdgeEnd::Target] {
|
||||
for zoom in [0.5, 1., 2.] {
|
||||
let mut f = fixture();
|
||||
let relation =
|
||||
f.project
|
||||
.relate(RelationKind::StateTransition, "Go standby", f.a, f.b);
|
||||
let second = state_edit::create_view(&f.project, f.machine).unwrap();
|
||||
let other_id = second.diagram;
|
||||
f.project = prepare_command(&f.project, &second.command)
|
||||
.unwrap()
|
||||
.project;
|
||||
let other = f.project.diagrams[&other_id].clone();
|
||||
let mut canvas = canvas(&f, Tool::AdjustAttachment { relation, end }, zoom);
|
||||
canvas.selected = relation;
|
||||
let mut state = State::default();
|
||||
let scene = canvas.scene(&state).unwrap();
|
||||
let route = &scene.routed.edges[&relation];
|
||||
let tip = match end {
|
||||
EdgeEnd::Source => route.points.first(),
|
||||
EdgeEnd::Target => route.points.last(),
|
||||
}
|
||||
.unwrap();
|
||||
let handle = screen(&canvas, point(*tip));
|
||||
motion(&canvas, &mut state, handle, handle);
|
||||
input(
|
||||
&canvas,
|
||||
&mut state,
|
||||
mouse::Event::ButtonPressed(mouse::Button::Left),
|
||||
handle,
|
||||
);
|
||||
assert!(
|
||||
input(
|
||||
&canvas,
|
||||
&mut state,
|
||||
mouse::Event::ButtonReleased(mouse::Button::Left),
|
||||
handle
|
||||
)
|
||||
.is_none()
|
||||
);
|
||||
assert!(
|
||||
state.attachment_preview.is_none(),
|
||||
"A click must not materialize an automatic endpoint"
|
||||
);
|
||||
let owner =
|
||||
state_edit::attachment_node(&f.project, f.diagram, relation, end).unwrap();
|
||||
let destination = screen(
|
||||
&canvas,
|
||||
Point::new(owner.position.x + owner.size.width * 0.25, owner.position.y),
|
||||
);
|
||||
input(
|
||||
&canvas,
|
||||
&mut state,
|
||||
mouse::Event::ButtonPressed(mouse::Button::Left),
|
||||
handle,
|
||||
);
|
||||
motion(&canvas, &mut state, destination, destination);
|
||||
assert!(state.attachment_preview.is_some());
|
||||
assert!(f.project.diagrams[&f.diagram].routes.is_empty());
|
||||
let event = input(
|
||||
&canvas,
|
||||
&mut state,
|
||||
mouse::Event::ButtonReleased(mouse::Button::Left),
|
||||
destination,
|
||||
)
|
||||
.unwrap();
|
||||
assert!(matches!(event, Event::SetAttachment { end: actual, .. } if actual == end));
|
||||
let plan = state_edit::plan(&f.project, canvas.context, &event).unwrap();
|
||||
let mut document =
|
||||
Document::from_project(f.project.clone(), Default::default()).unwrap();
|
||||
let source = document.bundle().clone();
|
||||
document.execute(plan.command).unwrap();
|
||||
assert_eq!(document.project().relations, f.project.relations);
|
||||
assert_eq!(document.project().diagrams[&other_id], other);
|
||||
let route = &document.project().diagrams[&f.diagram].routes[0];
|
||||
assert_eq!(
|
||||
route.attachment(end),
|
||||
Some(EdgeAttachment {
|
||||
side: PortAnchorSide::Top,
|
||||
offset: 0.25
|
||||
})
|
||||
);
|
||||
let edited = document.bundle().clone();
|
||||
assert!(document.undo());
|
||||
assert_eq!(document.bundle(), &source);
|
||||
assert!(!document.undo());
|
||||
assert!(document.redo());
|
||||
assert_eq!(document.bundle(), &edited);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn attachment_return_to_press_restores_exact_automatic_or_fractional_original() {
|
||||
for original in [
|
||||
None,
|
||||
Some(EdgeAttachment {
|
||||
side: PortAnchorSide::Top,
|
||||
offset: 0.234567,
|
||||
}),
|
||||
] {
|
||||
for end in [EdgeEnd::Source, EdgeEnd::Target] {
|
||||
let mut f = fixture();
|
||||
let relation =
|
||||
f.project
|
||||
.relate(RelationKind::StateTransition, "Go standby", f.a, f.b);
|
||||
if original.is_some() {
|
||||
let mut route =
|
||||
crate::route_edit::stored_route(&f.project.diagrams[&f.diagram], relation);
|
||||
route.set_attachment(end, original);
|
||||
f.project
|
||||
.diagrams
|
||||
.get_mut(&f.diagram)
|
||||
.unwrap()
|
||||
.routes
|
||||
.push(route);
|
||||
}
|
||||
let canvas = canvas(&f, Tool::AdjustAttachment { relation, end }, 1.);
|
||||
let mut state = State::default();
|
||||
let before = canvas.scene(&state).unwrap();
|
||||
let edge = &before.routed.edges[&relation];
|
||||
let tip = match end {
|
||||
EdgeEnd::Source => edge.points.first(),
|
||||
EdgeEnd::Target => edge.points.last(),
|
||||
}
|
||||
.unwrap();
|
||||
let start = screen(&canvas, point(*tip));
|
||||
let away = start + Vector::new(80., 40.);
|
||||
motion(&canvas, &mut state, start, start);
|
||||
input(
|
||||
&canvas,
|
||||
&mut state,
|
||||
mouse::Event::ButtonPressed(mouse::Button::Left),
|
||||
start,
|
||||
);
|
||||
motion(&canvas, &mut state, away, away);
|
||||
assert!(state.attachment_preview.is_some());
|
||||
motion(&canvas, &mut state, start, start);
|
||||
assert!(state.attachment_preview.is_none());
|
||||
assert_eq!(
|
||||
canvas.scene(&state).unwrap().routed.edges[&relation].points,
|
||||
edge.points
|
||||
);
|
||||
assert!(
|
||||
input(
|
||||
&canvas,
|
||||
&mut state,
|
||||
mouse::Event::ButtonReleased(mouse::Button::Left),
|
||||
start
|
||||
)
|
||||
.is_none()
|
||||
);
|
||||
assert_eq!(
|
||||
crate::route_edit::stored_route(&f.project.diagrams[&f.diagram], relation)
|
||||
.attachment(end),
|
||||
original
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn attachment_drag_cancels_on_camera_context_tool_pending_and_focus_changes() {
|
||||
let mut f = fixture();
|
||||
let relation = f
|
||||
.project
|
||||
.relate(RelationKind::StateTransition, "Go standby", f.a, f.b);
|
||||
for cancel in 0..9 {
|
||||
let mut canvas = canvas(
|
||||
&f,
|
||||
Tool::AdjustAttachment {
|
||||
relation,
|
||||
end: EdgeEnd::Source,
|
||||
},
|
||||
1.,
|
||||
);
|
||||
canvas.selected = relation;
|
||||
let mut state = State::default();
|
||||
let scene = canvas.scene(&state).unwrap();
|
||||
let handle = screen(&canvas, point(scene.routed.edges[&relation].points[0]));
|
||||
let destination = handle + Vector::new(40., 30.);
|
||||
motion(&canvas, &mut state, handle, handle);
|
||||
input(
|
||||
&canvas,
|
||||
&mut state,
|
||||
mouse::Event::ButtonPressed(mouse::Button::Left),
|
||||
handle,
|
||||
);
|
||||
motion(&canvas, &mut state, destination, destination);
|
||||
assert!(state.attachment_preview.is_some());
|
||||
match cancel {
|
||||
0 => canvas.zoom = 2.,
|
||||
1 => canvas.pan.x += 10.,
|
||||
2 => canvas.context.epoch += 1,
|
||||
3 => canvas.tool = Tool::Select,
|
||||
4 => canvas.editable = false,
|
||||
5 | 6 => {
|
||||
input(
|
||||
&canvas,
|
||||
&mut state,
|
||||
mouse::Event::ButtonPressed(if cancel == 5 {
|
||||
mouse::Button::Right
|
||||
} else {
|
||||
mouse::Button::Middle
|
||||
}),
|
||||
destination,
|
||||
);
|
||||
}
|
||||
7 => {
|
||||
canvas::Program::update(
|
||||
&canvas,
|
||||
&mut state,
|
||||
&canvas::Event::Window(iced::window::Event::Unfocused),
|
||||
bounds(),
|
||||
mouse::Cursor::Available(destination),
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
motion(&canvas, &mut state, Point::new(-100., -100.), destination);
|
||||
}
|
||||
}
|
||||
assert!(
|
||||
input(
|
||||
&canvas,
|
||||
&mut state,
|
||||
mouse::Event::ButtonReleased(mouse::Button::Left),
|
||||
destination
|
||||
)
|
||||
.is_none()
|
||||
);
|
||||
assert!(state.attachment_preview.is_none());
|
||||
assert!(f.project.diagrams[&f.diagram].routes.is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn selected_endpoint_reconnect_preserves_identity_and_requires_handle_motion() {
|
||||
let mut f = fixture();
|
||||
|
||||
@@ -20,6 +20,7 @@ pub enum Tool {
|
||||
Region,
|
||||
Transition,
|
||||
Reconnect { relation: Id, endpoint: Endpoint },
|
||||
AdjustAttachment { relation: Id, end: EdgeEnd },
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -38,6 +39,8 @@ pub enum Event {
|
||||
object: Id,
|
||||
placement: Option<Id>,
|
||||
anchor: iced::Point,
|
||||
bend: Option<usize>,
|
||||
route_segment: Option<(usize, Position)>,
|
||||
},
|
||||
CreateAt {
|
||||
context: Context,
|
||||
@@ -66,6 +69,32 @@ pub enum Event {
|
||||
endpoint: Endpoint,
|
||||
vertex: Id,
|
||||
},
|
||||
SetAttachment {
|
||||
context: Context,
|
||||
relation: Id,
|
||||
end: EdgeEnd,
|
||||
placement: Id,
|
||||
attachment: Option<EdgeAttachment>,
|
||||
},
|
||||
SetBends {
|
||||
context: Context,
|
||||
relation: Id,
|
||||
waypoints: Vec<Position>,
|
||||
},
|
||||
AddBend {
|
||||
context: Context,
|
||||
relation: Id,
|
||||
segment: Option<(usize, Position)>,
|
||||
},
|
||||
RemoveBend {
|
||||
context: Context,
|
||||
relation: Id,
|
||||
index: usize,
|
||||
},
|
||||
ClearBends {
|
||||
context: Context,
|
||||
relation: Id,
|
||||
},
|
||||
}
|
||||
|
||||
impl Event {
|
||||
@@ -84,7 +113,12 @@ impl Event {
|
||||
| Self::Place { context: c, .. }
|
||||
| Self::Move { context: c, .. }
|
||||
| Self::Connect { context: c, .. }
|
||||
| Self::Reconnect { context: c, .. } => Some(*c),
|
||||
| Self::Reconnect { context: c, .. }
|
||||
| Self::SetAttachment { context: c, .. }
|
||||
| Self::SetBends { context: c, .. }
|
||||
| Self::AddBend { context: c, .. }
|
||||
| Self::RemoveBend { context: c, .. }
|
||||
| Self::ClearBends { context: c, .. } => Some(*c),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -249,6 +283,54 @@ pub fn can_reconnect(
|
||||
.is_ok()
|
||||
}
|
||||
|
||||
/// Only the actual visible transition owner can receive a visual attachment.
|
||||
/// Folded promotion, semantic ports and internal-transition rows are excluded.
|
||||
pub fn attachment_node(
|
||||
project: &Project,
|
||||
diagram: Id,
|
||||
relation: Id,
|
||||
end: EdgeEnd,
|
||||
) -> Option<projection::ProjectedNode> {
|
||||
machine(project, diagram).ok()?;
|
||||
let relation_record = project.relations.get(&relation)?;
|
||||
if relation_record.kind() != RelationKind::StateTransition
|
||||
|| oa_core::routing::semantic_port_endpoint(project, relation, end).is_some()
|
||||
{
|
||||
return None;
|
||||
}
|
||||
let view = projection::project_view(project, diagram);
|
||||
let edge = view.edges.iter().find(|edge| edge.id == relation)?;
|
||||
let stored = project.diagrams.get(&diagram)?;
|
||||
if projection::edge_endpoint_placements(project, stored, relation)?
|
||||
!= (edge.source, edge.target)
|
||||
{
|
||||
return None;
|
||||
}
|
||||
let owner = match end {
|
||||
EdgeEnd::Source => edge.source,
|
||||
EdgeEnd::Target => edge.target,
|
||||
};
|
||||
view.nodes.iter().find(|node| node.id == owner).cloned()
|
||||
}
|
||||
|
||||
/// Actual visible State transition geometry, never an internal row or folded proxy.
|
||||
pub fn bend_route(
|
||||
project: &Project,
|
||||
diagram: Id,
|
||||
relation: Id,
|
||||
) -> Option<oa_core::routing::RoutedEdge> {
|
||||
machine(project, diagram).ok()?;
|
||||
if project.relations.get(&relation)?.kind() != RelationKind::StateTransition {
|
||||
return None;
|
||||
}
|
||||
let stored = project.diagrams.get(&diagram)?;
|
||||
let view = projection::project_diagram(project, stored);
|
||||
let geometry = oa_core::routing::route_diagram(project, stored, &view)
|
||||
.edges
|
||||
.remove(&relation)?;
|
||||
(!geometry.custom_suspended).then_some(geometry)
|
||||
}
|
||||
|
||||
fn checked(project: &Project, plan: Plan) -> Result<Plan, ModelError> {
|
||||
prepare_command(project, &plan.command)?;
|
||||
Ok(plan)
|
||||
@@ -492,6 +574,82 @@ pub fn plan(project: &Project, current: Context, event: &Event) -> Result<Plan,
|
||||
relation,
|
||||
None,
|
||||
),
|
||||
Event::SetAttachment {
|
||||
relation,
|
||||
end,
|
||||
placement,
|
||||
attachment,
|
||||
..
|
||||
} => {
|
||||
attachment_node(project, diagram, relation, end)
|
||||
.filter(|owner| owner.id == placement)
|
||||
.ok_or_else(|| {
|
||||
error("Choose the actual visible transition endpoint in this view.")
|
||||
})?;
|
||||
let mut route = crate::route_edit::stored_route(&project.diagrams[&diagram], relation);
|
||||
route.set_attachment(end, attachment);
|
||||
(Command::SetEdgeRoute { diagram, route }, relation, None)
|
||||
}
|
||||
Event::SetBends { relation, .. }
|
||||
| Event::AddBend { relation, .. }
|
||||
| Event::RemoveBend { relation, .. }
|
||||
| Event::ClearBends { relation, .. } => {
|
||||
let geometry = bend_route(project, diagram, relation)
|
||||
.ok_or_else(|| error("Choose an actual visible transition route in this view."))?;
|
||||
let mut route = crate::route_edit::stored_route(&project.diagrams[&diagram], relation);
|
||||
match event {
|
||||
Event::SetBends { waypoints, .. } => {
|
||||
if waypoints.len() > 128 {
|
||||
return Err(error("A route supports at most 128 bends."));
|
||||
}
|
||||
for &point in waypoints {
|
||||
finite(point)?;
|
||||
}
|
||||
route.waypoints = waypoints.clone();
|
||||
}
|
||||
Event::AddBend { segment, .. } => {
|
||||
let (segment, point) = segment
|
||||
.or_else(|| {
|
||||
geometry
|
||||
.points
|
||||
.windows(2)
|
||||
.enumerate()
|
||||
.filter(|(index, _)| {
|
||||
*index > 0 && index + 2 < geometry.points.len()
|
||||
})
|
||||
.max_by(|(_, a), (_, b)| {
|
||||
let length = |s: &[Position]| {
|
||||
(s[1].x - s[0].x).abs() + (s[1].y - s[0].y).abs()
|
||||
};
|
||||
length(a).total_cmp(&length(b))
|
||||
})
|
||||
.map(|(index, span)| {
|
||||
(
|
||||
index,
|
||||
Position {
|
||||
x: (span[0].x + span[1].x) / 2.,
|
||||
y: (span[0].y + span[1].y) / 2.,
|
||||
},
|
||||
)
|
||||
})
|
||||
})
|
||||
.ok_or_else(|| error("This route has no interior segment for a bend."))?;
|
||||
crate::route_edit::insert_pin_on_segment(&mut route, &geometry, segment, point)
|
||||
.ok_or_else(|| {
|
||||
error("The bend segment is stale, invalid, or at capacity.")
|
||||
})?;
|
||||
}
|
||||
Event::RemoveBend { index, .. } => {
|
||||
if *index >= route.waypoints.len() {
|
||||
return Err(error("This bend no longer exists."));
|
||||
}
|
||||
route.waypoints.remove(*index);
|
||||
}
|
||||
Event::ClearBends { .. } => route.waypoints.clear(),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
(Command::SetEdgeRoute { diagram, route }, relation, None)
|
||||
}
|
||||
_ => {
|
||||
return Err(error(
|
||||
"Handle this navigation or tool request without a model command.",
|
||||
@@ -580,6 +738,85 @@ mod tests {
|
||||
plan.diagram
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn attachment_reset_preserves_other_end_pins_label_and_rejects_ineligible_owners() {
|
||||
let mut f = fixture();
|
||||
let diagram = create(&mut f);
|
||||
let c = context(diagram);
|
||||
let edge = f.project.relate(
|
||||
RelationKind::StateTransition,
|
||||
"Leave work",
|
||||
f.leaf,
|
||||
f.target,
|
||||
);
|
||||
let attachment = EdgeAttachment {
|
||||
side: PortAnchorSide::Top,
|
||||
offset: 0.3,
|
||||
};
|
||||
let mut route = crate::route_edit::stored_route(&f.project.diagrams[&diagram], edge);
|
||||
route.source_attachment = Some(attachment);
|
||||
route.target_attachment = Some(attachment);
|
||||
route.waypoints.push(Position { x: 700., y: 700. });
|
||||
// Retain the exact label value alongside the other route components.
|
||||
route.label = Some(EdgeLabel {
|
||||
fraction: 0.5,
|
||||
offset: Position { x: 10., y: 20. },
|
||||
});
|
||||
f.project
|
||||
.diagrams
|
||||
.get_mut(&diagram)
|
||||
.unwrap()
|
||||
.routes
|
||||
.push(route.clone());
|
||||
let owner = attachment_node(&f.project, diagram, edge, EdgeEnd::Source).unwrap();
|
||||
let event = Event::SetAttachment {
|
||||
context: c,
|
||||
relation: edge,
|
||||
end: EdgeEnd::Source,
|
||||
placement: owner.id,
|
||||
attachment: None,
|
||||
};
|
||||
let accepted = prepare_command(&f.project, &plan(&f.project, c, &event).unwrap().command)
|
||||
.unwrap()
|
||||
.project;
|
||||
route.source_attachment = None;
|
||||
assert_eq!(accepted.diagrams[&diagram].routes, vec![route]);
|
||||
assert_eq!(accepted.relations, f.project.relations);
|
||||
let wrong = Event::SetAttachment {
|
||||
context: c,
|
||||
relation: edge,
|
||||
end: EdgeEnd::Source,
|
||||
placement: node(&f.project, diagram, f.target),
|
||||
attachment: Some(attachment),
|
||||
};
|
||||
assert!(plan(&f.project, c, &wrong).is_err());
|
||||
let composite = node(&f.project, diagram, f.composite);
|
||||
f.project
|
||||
.diagrams
|
||||
.get_mut(&diagram)
|
||||
.unwrap()
|
||||
.nodes
|
||||
.get_mut(&composite)
|
||||
.unwrap()
|
||||
.collapsed = true;
|
||||
assert!(attachment_node(&f.project, diagram, edge, EdgeEnd::Source).is_none());
|
||||
assert!(plan(&f.project, c, &event).is_err());
|
||||
let internal = f.project.relate(
|
||||
RelationKind::StateTransition,
|
||||
"Internal",
|
||||
f.target,
|
||||
f.target,
|
||||
);
|
||||
if let RelationBody::StateTransition {
|
||||
transition_kind, ..
|
||||
} = &mut f.project.relations.get_mut(&internal).unwrap().body
|
||||
{
|
||||
*transition_kind = TransitionKind::Internal;
|
||||
}
|
||||
assert!(attachment_node(&f.project, diagram, internal, EdgeEnd::Source).is_none());
|
||||
assert!(attachment_node(&f.project, diagram, internal, EdgeEnd::Target).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn view_initializes_only_its_machine_in_one_source_and_model_history_entry() {
|
||||
let f = fixture();
|
||||
@@ -763,6 +1000,8 @@ mod tests {
|
||||
.routes
|
||||
.push(EdgeRoute {
|
||||
edge,
|
||||
source_attachment: None,
|
||||
target_attachment: None,
|
||||
waypoints: vec![pin],
|
||||
label: None,
|
||||
});
|
||||
|
||||
@@ -161,6 +161,53 @@ pub fn popup(app: &App, opened: &Opened, clean: bool) -> Option<Menu<Message>> {
|
||||
);
|
||||
entries.push(item("Edit transition", edit, true));
|
||||
if let Some(context) = context {
|
||||
let bend_geometry = state_edit::bend_route(project, context.diagram, id);
|
||||
let bend_count = bend_geometry.as_ref().map_or(0, |route| route.pins.len());
|
||||
let can_add = bend_geometry.as_ref().is_some_and(|route| {
|
||||
bend_count < 128
|
||||
&& request.route_segment.map_or_else(
|
||||
|| route.points.len() >= 4,
|
||||
|(index, point)| {
|
||||
index
|
||||
.checked_add(2)
|
||||
.is_some_and(|end| end <= route.points.len())
|
||||
&& point.x.is_finite()
|
||||
&& point.y.is_finite()
|
||||
},
|
||||
)
|
||||
});
|
||||
entries.push(item(
|
||||
if request.route_segment.is_some() {
|
||||
"Add bend here"
|
||||
} else {
|
||||
"Add bend"
|
||||
},
|
||||
diagram_event(Event::AddBend {
|
||||
context,
|
||||
relation: id,
|
||||
segment: request.route_segment,
|
||||
}),
|
||||
can_add,
|
||||
));
|
||||
if let Some(index) = request.bend {
|
||||
entries.push(item(
|
||||
"Remove bend",
|
||||
diagram_event(Event::RemoveBend {
|
||||
context,
|
||||
relation: id,
|
||||
index,
|
||||
}),
|
||||
bend_geometry.is_some() && index < bend_count,
|
||||
));
|
||||
}
|
||||
entries.push(item(
|
||||
"Clear bends",
|
||||
diagram_event(Event::ClearBends {
|
||||
context,
|
||||
relation: id,
|
||||
}),
|
||||
bend_geometry.is_some() && bend_count > 0,
|
||||
));
|
||||
let visible = projection::project_view(project, context.diagram)
|
||||
.edges
|
||||
.iter()
|
||||
@@ -178,6 +225,44 @@ pub fn popup(app: &App, opened: &Opened, clean: bool) -> Option<Menu<Message>> {
|
||||
visible,
|
||||
));
|
||||
}
|
||||
for (caption, reset, end) in [
|
||||
(
|
||||
"Adjust source attachment",
|
||||
"Reset source attachment",
|
||||
EdgeEnd::Source,
|
||||
),
|
||||
(
|
||||
"Adjust target attachment",
|
||||
"Reset target attachment",
|
||||
EdgeEnd::Target,
|
||||
),
|
||||
] {
|
||||
let owner = state_edit::attachment_node(project, context.diagram, id, end);
|
||||
entries.push(item(
|
||||
caption,
|
||||
diagram_event(Event::Choose(Tool::AdjustAttachment { relation: id, end })),
|
||||
owner.is_some(),
|
||||
));
|
||||
if let Some(owner) = owner {
|
||||
let authored = project.diagrams[&context.diagram]
|
||||
.routes
|
||||
.iter()
|
||||
.find(|route| route.edge == id)
|
||||
.and_then(|route| route.attachment(end))
|
||||
.is_some();
|
||||
entries.push(item(
|
||||
reset,
|
||||
diagram_event(Event::SetAttachment {
|
||||
context,
|
||||
relation: id,
|
||||
end,
|
||||
placement: owner.id,
|
||||
attachment: None,
|
||||
}),
|
||||
authored,
|
||||
));
|
||||
}
|
||||
}
|
||||
if !visible {
|
||||
entries.push(Entry::title(
|
||||
"Use transition details for hidden or internal endpoints",
|
||||
|
||||
@@ -22,6 +22,9 @@ use std::{
|
||||
sync::Arc,
|
||||
};
|
||||
#[cfg(test)]
|
||||
#[path = "diagram/attachment_tests.rs"]
|
||||
mod attachment_tests;
|
||||
#[cfg(test)]
|
||||
#[path = "diagram/lifecycle_tests.rs"]
|
||||
mod lifecycle_tests;
|
||||
#[cfg(test)]
|
||||
@@ -53,6 +56,7 @@ pub struct DiagramCanvas<'a> {
|
||||
pub pan: Vector,
|
||||
pub context: Context,
|
||||
pub selected_bend: Option<usize>,
|
||||
pub selected_attachment: Option<EdgeEnd>,
|
||||
pub editable: bool,
|
||||
pub placing: bool,
|
||||
pub connection: Option<&'a crate::connection_edit::Session>,
|
||||
@@ -67,6 +71,7 @@ pub struct State {
|
||||
pan_start: Option<(mouse::Button, Point)>,
|
||||
context: Option<Context>,
|
||||
route_drag: Option<Gesture>,
|
||||
attachment_viewport: Option<(f32, Vector, Rectangle)>,
|
||||
connection_press: Option<(Id, Point)>,
|
||||
connection_hover: Option<Point>,
|
||||
port_drag: Option<crate::port_edit::Gesture>,
|
||||
@@ -294,6 +299,11 @@ impl DiagramCanvas<'_> {
|
||||
);
|
||||
request.canvas = Some(self.context);
|
||||
request.creation_point = Some(position(world));
|
||||
if self.attachment_at(&scene, world).is_some() {
|
||||
request.object = self.selected;
|
||||
request.route_point = Some(position(world));
|
||||
return request;
|
||||
}
|
||||
if let Some(edge) = scene.routed.edges.get(&self.selected)
|
||||
&& !edge.custom_suspended
|
||||
&& let Some(index) = edge
|
||||
@@ -371,6 +381,39 @@ impl DiagramCanvas<'_> {
|
||||
})
|
||||
.map(|(id, segment, _)| (id, segment))
|
||||
}
|
||||
fn attachment_at<'b>(
|
||||
&self,
|
||||
scene: &'b Scene,
|
||||
world: Point,
|
||||
) -> Option<(EdgeEnd, &'b ProjectedNode)> {
|
||||
let edge = scene.routed.edges.get(&self.selected)?;
|
||||
if edge.custom_suspended {
|
||||
return None;
|
||||
}
|
||||
[
|
||||
(EdgeEnd::Source, edge.points.first()),
|
||||
(EdgeEnd::Target, edge.points.last()),
|
||||
]
|
||||
.into_iter()
|
||||
.filter_map(|(end, at)| {
|
||||
let distance = world.distance(point(*at?));
|
||||
let owner = route_edit::attachment_node(
|
||||
self.project,
|
||||
&self.project.diagrams[&self.diagram],
|
||||
&scene.view,
|
||||
self.selected,
|
||||
end,
|
||||
)?;
|
||||
(distance <= 8. / self.zoom).then_some((end, owner, distance))
|
||||
})
|
||||
.min_by(|a, b| {
|
||||
a.2.total_cmp(&b.2).then_with(|| {
|
||||
(Some(a.0) != self.selected_attachment)
|
||||
.cmp(&(Some(b.0) != self.selected_attachment))
|
||||
})
|
||||
})
|
||||
.map(|(end, owner, _)| (end, owner))
|
||||
}
|
||||
fn hit_label(&self, routed: &RoutedView, p: Point) -> Option<Id> {
|
||||
let p = self.world(p);
|
||||
routed
|
||||
@@ -561,6 +604,24 @@ impl canvas::Program<Message> for DiagramCanvas<'_> {
|
||||
bounds: Rectangle,
|
||||
cursor: mouse::Cursor,
|
||||
) -> Option<Action<Message>> {
|
||||
// An attachment belongs to the boundary geometry captured at press.
|
||||
// Camera/layout changes must not reinterpret its pointer in another space.
|
||||
if matches!(
|
||||
state.route_drag.as_ref().map(|gesture| &gesture.handle),
|
||||
Some(Handle::Attachment { .. })
|
||||
) && (state.attachment_viewport != Some((self.zoom, self.pan, bounds))
|
||||
|| matches!(
|
||||
event,
|
||||
canvas::Event::Window(
|
||||
iced::window::Event::Unfocused | iced::window::Event::Resized(_)
|
||||
) | canvas::Event::Mouse(mouse::Event::CursorLeft)
|
||||
))
|
||||
{
|
||||
state.route_drag = None;
|
||||
state.attachment_viewport = None;
|
||||
state.pointer = None;
|
||||
return Some(Action::request_redraw());
|
||||
}
|
||||
// A completed work click retires App's allocation epoch before the
|
||||
// retained canvas sees a redraw. Its already-idle press must not eat
|
||||
// the first Delete. A live or not-yet-dispatched press stays guarded.
|
||||
@@ -840,6 +901,21 @@ impl canvas::Program<Message> for DiagramCanvas<'_> {
|
||||
&self.project.diagrams[&self.diagram],
|
||||
self.selected,
|
||||
);
|
||||
if let Some((end, owner)) = self.attachment_at(&scene, world) {
|
||||
let original = route.attachment(end);
|
||||
self.begin_route(
|
||||
state,
|
||||
world,
|
||||
Handle::Attachment {
|
||||
end,
|
||||
owner: owner.clone(),
|
||||
original,
|
||||
},
|
||||
route,
|
||||
);
|
||||
state.attachment_viewport = Some((self.zoom, self.pan, bounds));
|
||||
return Some(Action::capture());
|
||||
}
|
||||
if let Some(index) = edge
|
||||
.pins
|
||||
.iter()
|
||||
@@ -963,7 +1039,7 @@ impl canvas::Program<Message> for DiagramCanvas<'_> {
|
||||
return Some(Action::request_redraw());
|
||||
}
|
||||
if let Some(gesture) = &mut state.route_drag {
|
||||
gesture.move_to(self.world(p), self.zoom);
|
||||
gesture.move_attachment_to(self.world(p), self.zoom);
|
||||
return Some(Action::request_redraw().and_capture());
|
||||
}
|
||||
if let Some((_, start, original)) = state.drag {
|
||||
@@ -1040,17 +1116,43 @@ impl canvas::Program<Message> for DiagramCanvas<'_> {
|
||||
return Some(Action::capture());
|
||||
}
|
||||
if let Some(mut gesture) = state.route_drag.take() {
|
||||
if matches!(gesture.handle, Handle::Attachment { .. }) {
|
||||
state.attachment_viewport = None;
|
||||
if !cursor.is_over(bounds) {
|
||||
return Some(Action::request_redraw().and_capture());
|
||||
}
|
||||
}
|
||||
// `local` uses the ordered pointer position at release,
|
||||
// before any later motion in the same native event batch.
|
||||
if let Some(p) = local {
|
||||
gesture.move_to(self.world(p), self.zoom);
|
||||
gesture.move_attachment_to(self.world(p), self.zoom);
|
||||
}
|
||||
if !gesture.changed {
|
||||
return Some(Action::request_redraw().and_capture());
|
||||
}
|
||||
if let Handle::Attachment { end, owner, .. } = &gesture.handle {
|
||||
if gesture.route
|
||||
== route_edit::stored_route(
|
||||
&self.project.diagrams[&self.diagram],
|
||||
self.selected,
|
||||
)
|
||||
{
|
||||
return Some(Action::request_redraw().and_capture());
|
||||
}
|
||||
return Some(
|
||||
Action::publish(Message::Route(RouteEvent::CommitAttachment(
|
||||
gesture.context,
|
||||
gesture.route,
|
||||
*end,
|
||||
owner.id,
|
||||
)))
|
||||
.and_capture(),
|
||||
);
|
||||
}
|
||||
let bend = match gesture.handle {
|
||||
Handle::Bend(index) => Some(index),
|
||||
Handle::Label { .. } => None,
|
||||
Handle::Attachment { .. } => unreachable!(),
|
||||
};
|
||||
return Some(
|
||||
Action::publish(Message::Route(RouteEvent::Commit(
|
||||
@@ -1094,6 +1196,15 @@ impl canvas::Program<Message> for DiagramCanvas<'_> {
|
||||
canvas::Event::Mouse(mouse::Event::WheelScrolled { delta })
|
||||
if cursor.is_over(bounds) =>
|
||||
{
|
||||
// Cancel before publishing Zoom: a release may arrive in this
|
||||
// same event batch, before App applies the new camera.
|
||||
if matches!(
|
||||
state.route_drag.as_ref().map(|gesture| &gesture.handle),
|
||||
Some(Handle::Attachment { .. })
|
||||
) {
|
||||
state.route_drag = None;
|
||||
state.attachment_viewport = None;
|
||||
}
|
||||
let y = match delta {
|
||||
mouse::ScrollDelta::Lines { y, .. } | mouse::ScrollDelta::Pixels { y, .. } => {
|
||||
*y
|
||||
@@ -1336,6 +1447,41 @@ impl canvas::Program<Message> for DiagramCanvas<'_> {
|
||||
if let Some(edge) = scene.routed.edges.get(&self.selected)
|
||||
&& !edge.custom_suspended
|
||||
{
|
||||
for (end, at) in [
|
||||
(EdgeEnd::Source, edge.points.first()),
|
||||
(EdgeEnd::Target, edge.points.last()),
|
||||
] {
|
||||
if let Some(at) = at
|
||||
&& route_edit::attachment_node(
|
||||
project,
|
||||
&project.diagrams[&self.diagram],
|
||||
view,
|
||||
self.selected,
|
||||
end,
|
||||
)
|
||||
.is_some()
|
||||
{
|
||||
let at = point(*at);
|
||||
let handle = Path::rectangle(
|
||||
at - Vector::new(5.5 / self.zoom, 5.5 / self.zoom),
|
||||
Size::new(11. / self.zoom, 11. / self.zoom),
|
||||
);
|
||||
f.fill(
|
||||
&handle,
|
||||
if self.selected_attachment == Some(end) {
|
||||
style::TEAL
|
||||
} else {
|
||||
Color::WHITE
|
||||
},
|
||||
);
|
||||
f.stroke(
|
||||
&handle,
|
||||
Stroke::default()
|
||||
.with_color(style::TEAL)
|
||||
.with_width(1.7 / self.zoom),
|
||||
);
|
||||
}
|
||||
}
|
||||
for (index, pin) in edge.pins.iter().enumerate() {
|
||||
let handle = Path::circle(point(*pin), 5.5 / self.zoom);
|
||||
f.fill(
|
||||
@@ -2042,6 +2188,7 @@ mod tests {
|
||||
epoch: 0,
|
||||
},
|
||||
selected_bend: None,
|
||||
selected_attachment: None,
|
||||
editable: true,
|
||||
placing: false,
|
||||
connection: None,
|
||||
@@ -2118,6 +2265,7 @@ mod tests {
|
||||
epoch: 0,
|
||||
},
|
||||
selected_bend: None,
|
||||
selected_attachment: None,
|
||||
editable: true,
|
||||
placing: false,
|
||||
connection: None,
|
||||
@@ -2243,6 +2391,7 @@ mod tests {
|
||||
selected: p.id,
|
||||
navigation_focus: None,
|
||||
selected_bend: None,
|
||||
selected_attachment: None,
|
||||
zoom,
|
||||
pan: Vector::new(20., 30.),
|
||||
editable: true,
|
||||
@@ -2380,6 +2529,8 @@ mod tests {
|
||||
diagram,
|
||||
route: EdgeRoute {
|
||||
edge,
|
||||
source_attachment: None,
|
||||
target_attachment: None,
|
||||
waypoints: vec![Position { x: 400., y: -100. }],
|
||||
label: None,
|
||||
},
|
||||
@@ -2422,6 +2573,7 @@ mod tests {
|
||||
epoch: 0,
|
||||
},
|
||||
selected_bend: None,
|
||||
selected_attachment: None,
|
||||
editable: true,
|
||||
placing: false,
|
||||
connection: None,
|
||||
@@ -2499,6 +2651,7 @@ mod tests {
|
||||
epoch: 0,
|
||||
},
|
||||
selected_bend: None,
|
||||
selected_attachment: None,
|
||||
editable: true,
|
||||
placing: false,
|
||||
connection: None,
|
||||
@@ -2597,6 +2750,7 @@ mod tests {
|
||||
epoch: 0,
|
||||
},
|
||||
selected_bend: None,
|
||||
selected_attachment: None,
|
||||
editable: true,
|
||||
placing: false,
|
||||
connection: None,
|
||||
@@ -2726,6 +2880,7 @@ mod tests {
|
||||
epoch: 0,
|
||||
},
|
||||
selected_bend: None,
|
||||
selected_attachment: None,
|
||||
editable: true,
|
||||
placing: false,
|
||||
connection: None,
|
||||
@@ -2781,6 +2936,7 @@ mod tests {
|
||||
epoch: 0,
|
||||
},
|
||||
selected_bend: None,
|
||||
selected_attachment: None,
|
||||
editable: true,
|
||||
placing: false,
|
||||
connection: None,
|
||||
@@ -2856,6 +3012,7 @@ mod tests {
|
||||
epoch: 0,
|
||||
},
|
||||
selected_bend: None,
|
||||
selected_attachment: None,
|
||||
editable: true,
|
||||
placing: false,
|
||||
connection: None,
|
||||
@@ -2890,6 +3047,7 @@ mod tests {
|
||||
epoch: 0,
|
||||
},
|
||||
selected_bend: None,
|
||||
selected_attachment: None,
|
||||
editable: true,
|
||||
placing: false,
|
||||
connection: None,
|
||||
|
||||
@@ -0,0 +1,446 @@
|
||||
use super::*;
|
||||
use crate::app::{App, Page};
|
||||
use iced::widget::canvas::Program;
|
||||
|
||||
fn fixture() -> App {
|
||||
let mut p = Project::empty();
|
||||
let a = p.add(Kind::Activity, "Send", 100., 150.);
|
||||
let b = p.add(Kind::Activity, "Receive", 650., 150.);
|
||||
let edge = p.relate(RelationKind::Interaction, "Report", a, b);
|
||||
let diagram = p.ensure_diagram(Layer::Oa);
|
||||
p.diagrams
|
||||
.get_mut(&diagram)
|
||||
.unwrap()
|
||||
.routes
|
||||
.push(EdgeRoute {
|
||||
edge,
|
||||
waypoints: vec![Position { x: 450., y: 350. }],
|
||||
label: Some(EdgeLabel {
|
||||
fraction: 0.4,
|
||||
offset: Position { x: 5., y: 10. },
|
||||
}),
|
||||
source_attachment: None,
|
||||
target_attachment: Some(EdgeAttachment {
|
||||
side: PortAnchorSide::Left,
|
||||
offset: 0.6,
|
||||
}),
|
||||
});
|
||||
let mut app = App::with_project(p);
|
||||
app.page = Page::Diagram;
|
||||
app.active_diagram = Some(diagram);
|
||||
let _ = app.update(Message::Select(edge));
|
||||
app
|
||||
}
|
||||
|
||||
fn canvas(app: &App, zoom: f32) -> DiagramCanvas<'_> {
|
||||
DiagramCanvas {
|
||||
allocation: None,
|
||||
project: app.project(),
|
||||
view_index: None,
|
||||
diagram: app.active_diagram.unwrap(),
|
||||
selected: app.selected,
|
||||
navigation_focus: None,
|
||||
zoom,
|
||||
pan: Vector::new(40., 50.),
|
||||
context: app.route_context().unwrap(),
|
||||
selected_bend: None,
|
||||
selected_attachment: app
|
||||
.selected_attachment
|
||||
.filter(|(c, e, _)| Some(*c) == app.route_context() && *e == app.selected)
|
||||
.map(|(_, _, end)| end),
|
||||
editable: !app.draft_dirty() && !app.source_dirty(),
|
||||
placing: false,
|
||||
connection: None,
|
||||
}
|
||||
}
|
||||
fn bounds() -> Rectangle {
|
||||
Rectangle::new(Point::new(120., 80.), Size::new(2400., 1800.))
|
||||
}
|
||||
fn screen(c: &DiagramCanvas<'_>, p: Position) -> Point {
|
||||
Point::new(
|
||||
bounds().x + p.x * c.zoom + c.pan.x,
|
||||
bounds().y + p.y * c.zoom + c.pan.y,
|
||||
)
|
||||
}
|
||||
fn send(
|
||||
c: &DiagramCanvas<'_>,
|
||||
state: &mut State,
|
||||
event: mouse::Event,
|
||||
final_cursor: Point,
|
||||
) -> Option<Message> {
|
||||
c.update(
|
||||
state,
|
||||
&canvas::Event::Mouse(event),
|
||||
bounds(),
|
||||
mouse::Cursor::Available(final_cursor),
|
||||
)
|
||||
.and_then(|a| a.into_inner().0)
|
||||
}
|
||||
fn positions(c: &DiagramCanvas<'_>) -> (Point, Point) {
|
||||
let scene = c.scene(&State::default());
|
||||
let start = *scene.routed.edges[&c.selected].points.first().unwrap();
|
||||
let node = route_edit::attachment_node(
|
||||
c.project,
|
||||
&c.project.diagrams[&c.diagram],
|
||||
&scene.view,
|
||||
c.selected,
|
||||
EdgeEnd::Source,
|
||||
)
|
||||
.unwrap();
|
||||
let end = oa_core::routing::attachment_point(
|
||||
c.project,
|
||||
&c.project.diagrams[&c.diagram],
|
||||
node,
|
||||
&EdgeAttachment {
|
||||
side: PortAnchorSide::Top,
|
||||
offset: 0.25,
|
||||
},
|
||||
);
|
||||
(screen(c, start), screen(c, end))
|
||||
}
|
||||
fn drag(app: &App, zoom: f32) -> Message {
|
||||
let c = canvas(app, zoom);
|
||||
let (start, end) = positions(&c);
|
||||
let mut state = State::default();
|
||||
let messages = [
|
||||
mouse::Event::CursorMoved { position: start },
|
||||
mouse::Event::ButtonPressed(mouse::Button::Left),
|
||||
mouse::Event::CursorMoved { position: end },
|
||||
mouse::Event::ButtonReleased(mouse::Button::Left),
|
||||
]
|
||||
.into_iter()
|
||||
.filter_map(|e| send(&c, &mut state, e, end))
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(messages.len(), 1);
|
||||
messages.into_iter().next().unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn attachment_event_batches_commit_one_source_history_change_at_three_zooms() {
|
||||
for zoom in [0.4, 1., 2.] {
|
||||
let mut app = fixture();
|
||||
let before = app.document.bundle().clone();
|
||||
let project = app.project().clone();
|
||||
let revision = app.document.revision();
|
||||
let message = drag(&app, zoom);
|
||||
let Message::Route(RouteEvent::CommitAttachment(_, ref route, EdgeEnd::Source, _)) =
|
||||
message
|
||||
else {
|
||||
panic!("attachment commit required")
|
||||
};
|
||||
assert_eq!(
|
||||
route.source_attachment,
|
||||
Some(EdgeAttachment {
|
||||
side: PortAnchorSide::Top,
|
||||
offset: 0.25
|
||||
})
|
||||
);
|
||||
let intended = route.clone();
|
||||
let _ = app.update(message);
|
||||
assert_eq!(app.document.revision(), revision + 1);
|
||||
let mut expected = project;
|
||||
route_edit::with_route(
|
||||
expected
|
||||
.diagrams
|
||||
.get_mut(&app.active_diagram.unwrap())
|
||||
.unwrap(),
|
||||
intended,
|
||||
);
|
||||
assert_eq!(
|
||||
*app.project(),
|
||||
expected,
|
||||
"only the intended view attachment changes"
|
||||
);
|
||||
let after = app.document.bundle().clone();
|
||||
assert_eq!(
|
||||
oa_core::source_project::compile_bundle(&after, Default::default())
|
||||
.unwrap()
|
||||
.decoded
|
||||
.project,
|
||||
expected
|
||||
);
|
||||
let _ = app.update(Message::Undo);
|
||||
assert_eq!(app.document.bundle(), &before);
|
||||
let _ = app.update(Message::Redo);
|
||||
assert_eq!(app.document.bundle(), &after);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn attachment_stationary_return_and_escape_leave_source_unchanged() {
|
||||
let mut app = fixture();
|
||||
let before = app.document.bundle().clone();
|
||||
let c = canvas(&app, 1.);
|
||||
let (start, end) = positions(&c);
|
||||
let mut state = State::default();
|
||||
for event in [
|
||||
mouse::Event::CursorMoved { position: start },
|
||||
mouse::Event::ButtonPressed(mouse::Button::Left),
|
||||
mouse::Event::CursorMoved { position: end },
|
||||
mouse::Event::CursorMoved { position: start },
|
||||
mouse::Event::ButtonReleased(mouse::Button::Left),
|
||||
] {
|
||||
assert!(send(&c, &mut state, event, start).is_none());
|
||||
}
|
||||
for event in [
|
||||
mouse::Event::CursorMoved { position: start },
|
||||
mouse::Event::ButtonPressed(mouse::Button::Left),
|
||||
mouse::Event::CursorMoved { position: end },
|
||||
] {
|
||||
assert!(send(&c, &mut state, event, end).is_none());
|
||||
}
|
||||
let _ = app.update(Message::Escape);
|
||||
assert!(
|
||||
send(
|
||||
&canvas(&app, 1.),
|
||||
&mut state,
|
||||
mouse::Event::ButtonReleased(mouse::Button::Left),
|
||||
end
|
||||
)
|
||||
.is_none()
|
||||
);
|
||||
assert_eq!(app.document.bundle(), &before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn attachment_camera_layout_focus_and_outside_release_cancel_after_motion() {
|
||||
for cancel in 0..8 {
|
||||
let app = fixture();
|
||||
let before = app.document.bundle().clone();
|
||||
let mut c = canvas(&app, 1.);
|
||||
let (start, end) = positions(&c);
|
||||
let mut state = State::default();
|
||||
for event in [
|
||||
mouse::Event::CursorMoved { position: start },
|
||||
mouse::Event::ButtonPressed(mouse::Button::Left),
|
||||
mouse::Event::CursorMoved { position: end },
|
||||
] {
|
||||
assert!(send(&c, &mut state, event, end).is_none());
|
||||
}
|
||||
assert!(state.route_drag.as_ref().is_some_and(|g| g.changed));
|
||||
let mut current_bounds = bounds();
|
||||
let mut release = end;
|
||||
match cancel {
|
||||
0 => c.zoom = 2.,
|
||||
1 => c.pan.x += 20.,
|
||||
2 => current_bounds.x += 20.,
|
||||
3 => current_bounds.height -= 100.,
|
||||
4..=6 => {
|
||||
let event = match cancel {
|
||||
4 => canvas::Event::Window(iced::window::Event::Unfocused),
|
||||
5 => canvas::Event::Window(iced::window::Event::Resized(Size::new(800., 600.))),
|
||||
_ => canvas::Event::Mouse(mouse::Event::CursorLeft),
|
||||
};
|
||||
let message = c
|
||||
.update(
|
||||
&mut state,
|
||||
&event,
|
||||
current_bounds,
|
||||
mouse::Cursor::Available(end),
|
||||
)
|
||||
.and_then(|a| a.into_inner().0);
|
||||
assert!(message.is_none());
|
||||
}
|
||||
_ => {
|
||||
release = Point::new(-100., -100.);
|
||||
assert!(
|
||||
send(
|
||||
&c,
|
||||
&mut state,
|
||||
mouse::Event::CursorMoved { position: release },
|
||||
release
|
||||
)
|
||||
.is_none()
|
||||
);
|
||||
}
|
||||
}
|
||||
let message = c
|
||||
.update(
|
||||
&mut state,
|
||||
&canvas::Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left)),
|
||||
current_bounds,
|
||||
mouse::Cursor::Available(release),
|
||||
)
|
||||
.and_then(|a| a.into_inner().0);
|
||||
assert!(message.is_none(), "cancellation case {cancel}");
|
||||
assert!(state.route_drag.is_none(), "cancellation case {cancel}");
|
||||
assert_eq!(app.document.bundle(), &before);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn attachment_wheel_and_middle_pan_cancel_before_same_batch_left_release() {
|
||||
for wheel in [true, false] {
|
||||
let mut app = fixture();
|
||||
let before = app.document.bundle().clone();
|
||||
let revision = app.document.revision();
|
||||
let c = canvas(&app, 1.);
|
||||
let (start, end) = positions(&c);
|
||||
let mut state = State::default();
|
||||
for event in [
|
||||
mouse::Event::CursorMoved { position: start },
|
||||
mouse::Event::ButtonPressed(mouse::Button::Left),
|
||||
mouse::Event::CursorMoved { position: end },
|
||||
] {
|
||||
assert!(send(&c, &mut state, event, end).is_none());
|
||||
}
|
||||
let camera_message = send(
|
||||
&c,
|
||||
&mut state,
|
||||
if wheel {
|
||||
mouse::Event::WheelScrolled {
|
||||
delta: mouse::ScrollDelta::Lines { x: 0., y: 1. },
|
||||
}
|
||||
} else {
|
||||
mouse::Event::ButtonPressed(mouse::Button::Middle)
|
||||
},
|
||||
end,
|
||||
);
|
||||
assert_eq!(camera_message.is_some(), wheel);
|
||||
assert!(state.route_drag.is_none());
|
||||
// Deliberately retain the same canvas and defer App camera dispatch.
|
||||
assert!(
|
||||
send(
|
||||
&c,
|
||||
&mut state,
|
||||
mouse::Event::ButtonReleased(mouse::Button::Left),
|
||||
end
|
||||
)
|
||||
.is_none()
|
||||
);
|
||||
if !wheel {
|
||||
assert!(
|
||||
send(
|
||||
&c,
|
||||
&mut state,
|
||||
mouse::Event::ButtonReleased(mouse::Button::Middle),
|
||||
end
|
||||
)
|
||||
.is_none()
|
||||
);
|
||||
}
|
||||
if let Some(message) = camera_message {
|
||||
assert!(matches!(message, Message::Zoom(_)));
|
||||
let _ = app.update(message);
|
||||
}
|
||||
assert_eq!(app.document.revision(), revision);
|
||||
assert_eq!(app.document.bundle(), &before);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn attachment_fast_release_uses_release_position_and_stays_in_one_view() {
|
||||
let mut app = fixture();
|
||||
let original = app.active_diagram.unwrap();
|
||||
let _ = app.update(Message::DuplicateDiagram(original));
|
||||
let other = app.active_diagram.unwrap();
|
||||
assert_ne!(original, other);
|
||||
app.active_diagram = Some(original);
|
||||
let edge = app.project().diagrams[&original].routes[0].edge;
|
||||
let _ = app.update(Message::Select(edge));
|
||||
let untouched = app.project().diagrams[&other].clone();
|
||||
let c = canvas(&app, 0.7);
|
||||
let (start, end) = positions(&c);
|
||||
let mut state = State::default();
|
||||
assert!(
|
||||
send(
|
||||
&c,
|
||||
&mut state,
|
||||
mouse::Event::ButtonPressed(mouse::Button::Left),
|
||||
start
|
||||
)
|
||||
.is_none()
|
||||
);
|
||||
let message = send(
|
||||
&c,
|
||||
&mut state,
|
||||
mouse::Event::ButtonReleased(mouse::Button::Left),
|
||||
end,
|
||||
)
|
||||
.expect("release completes drag without final move");
|
||||
let _ = app.update(message);
|
||||
assert_eq!(
|
||||
app.project().diagrams[&original].routes[0].source_attachment,
|
||||
Some(EdgeAttachment {
|
||||
side: PortAnchorSide::Top,
|
||||
offset: 0.25
|
||||
})
|
||||
);
|
||||
assert_eq!(app.project().diagrams[&other], untouched);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn attachment_stale_context_wrong_placement_and_unowned_route_fields_are_rejected() {
|
||||
let mut app = fixture();
|
||||
let before = app.document.bundle().clone();
|
||||
let message = drag(&app, 1.);
|
||||
let Message::Route(RouteEvent::CommitAttachment(context, route, end, node)) = message else {
|
||||
panic!()
|
||||
};
|
||||
let mut changed = route.clone();
|
||||
changed.waypoints.clear();
|
||||
let _ = app.update(Message::Route(RouteEvent::CommitAttachment(
|
||||
context, changed, end, node,
|
||||
)));
|
||||
let _ = app.update(Message::Route(RouteEvent::CommitAttachment(
|
||||
context,
|
||||
route.clone(),
|
||||
end,
|
||||
Id::new_v4(),
|
||||
)));
|
||||
let _ = app.update(Message::Escape);
|
||||
let _ = app.update(Message::Route(RouteEvent::CommitAttachment(
|
||||
context, route, end, node,
|
||||
)));
|
||||
assert_eq!(app.document.bundle(), &before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn attachment_reset_preserves_opposite_end_pins_label_and_semantics() {
|
||||
let mut app = fixture();
|
||||
let before = app.project().clone();
|
||||
let _ = app.update(Message::Route(RouteEvent::ResetAttachment(EdgeEnd::Target)));
|
||||
let mut expected = before;
|
||||
expected
|
||||
.diagrams
|
||||
.get_mut(&app.active_diagram.unwrap())
|
||||
.unwrap()
|
||||
.routes[0]
|
||||
.target_attachment = None;
|
||||
assert_eq!(*app.project(), expected);
|
||||
let revision = app.document.revision();
|
||||
let _ = app.update(Message::Route(RouteEvent::ResetAttachment(EdgeEnd::Target)));
|
||||
assert_eq!(app.document.revision(), revision);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn coincident_attachment_handles_honor_explicit_end_choice() {
|
||||
let mut app = fixture();
|
||||
let _ = app.update(Message::Route(RouteEvent::ChooseAttachment(
|
||||
EdgeEnd::Target,
|
||||
)));
|
||||
let c = canvas(&app, 1.);
|
||||
let mut scene = Scene {
|
||||
work: None,
|
||||
view: projection::project_view(c.project, c.diagram),
|
||||
routed: Arc::new(route_diagram(
|
||||
c.project,
|
||||
&c.project.diagrams[&c.diagram],
|
||||
&projection::project_view(c.project, c.diagram),
|
||||
)),
|
||||
};
|
||||
let routed = Arc::make_mut(&mut scene.routed);
|
||||
let edge = routed.edges.get_mut(&c.selected).unwrap();
|
||||
let start = *edge.points.first().unwrap();
|
||||
*edge.points.last_mut().unwrap() = start;
|
||||
assert_eq!(
|
||||
c.attachment_at(&scene, point(start)).unwrap().0,
|
||||
EdgeEnd::Target
|
||||
);
|
||||
let mut source = c;
|
||||
source.selected_attachment = Some(EdgeEnd::Source);
|
||||
assert_eq!(
|
||||
source.attachment_at(&scene, point(start)).unwrap().0,
|
||||
EdgeEnd::Source
|
||||
);
|
||||
}
|
||||
@@ -78,7 +78,11 @@ impl<Message, R: renderer::Renderer> Widget<Message, Theme, R> for Owner<'_, Mes
|
||||
}
|
||||
if state.context.is_none_or(|previous| {
|
||||
(previous.document, previous.diagram, previous.epoch)
|
||||
!= (self.context.document, self.context.diagram, self.context.epoch)
|
||||
!= (
|
||||
self.context.document,
|
||||
self.context.diagram,
|
||||
self.context.epoch,
|
||||
)
|
||||
}) || !self.enabled
|
||||
{
|
||||
state.focused = false;
|
||||
|
||||
@@ -62,6 +62,7 @@ fn canvas(app: &App) -> DiagramCanvas<'_> {
|
||||
pan: app.pan,
|
||||
context: app.route_context().unwrap(),
|
||||
selected_bend: None,
|
||||
selected_attachment: None,
|
||||
editable: true,
|
||||
placing: false,
|
||||
connection: app.connection.as_ref(),
|
||||
|
||||
@@ -70,6 +70,7 @@ fn canvas(app: &App, zoom: f32) -> DiagramCanvas<'_> {
|
||||
pan: app.pan,
|
||||
context: app.route_context().unwrap(),
|
||||
selected_bend: None,
|
||||
selected_attachment: None,
|
||||
editable: true,
|
||||
placing: false,
|
||||
connection: app.connection.as_ref(),
|
||||
|
||||
@@ -16,6 +16,7 @@ fn canvas(project: &Project, diagram: Id, zoom: f32) -> DiagramCanvas<'_> {
|
||||
epoch: 0,
|
||||
},
|
||||
selected_bend: None,
|
||||
selected_attachment: None,
|
||||
editable: true,
|
||||
placing: false,
|
||||
connection: None,
|
||||
|
||||
@@ -186,6 +186,7 @@ mod tests {
|
||||
pan: Vector::ZERO,
|
||||
context: app.route_context().unwrap(),
|
||||
selected_bend: None,
|
||||
selected_attachment: None,
|
||||
editable: true,
|
||||
placing: false,
|
||||
connection: None,
|
||||
|
||||
@@ -344,7 +344,7 @@ fn article(topic: Topic) -> Article {
|
||||
&[
|
||||
"Select an architecture connection and drag a segment to add a bend. Right-click a line for Add bend here; right-click a circle for Remove bend. With the canvas focused, Insert adds a bend and Delete removes the selected bend. Drag the label independently. Escape cancels a gesture; Undo reverses one completed drag. Shift+F10 opens the selected diagram item's context menu; use arrow keys and Enter to choose an action.",
|
||||
"Automatic orthogonal routing avoids cards and container headers where space permits. Amber connections need attention: move an obstructing element or a bend. In Select / move, drag a port to any border of its owner. Manual positions are per diagram; right-click Reset automatic position restores connection-aware placement. Ports remain attached to their actual owners. Manual routes are saved separately for each diagram and appear in source, API and SVG export.",
|
||||
"Right-click a connection and choose Reset routing to clear its pins and label position in this view. The Properties Actions menu provides the same commands. Auto-layout preserves pins. Moving one endpoint keeps pins fixed; moving a container carrying both endpoints translates their pins. When folding promotes an endpoint, expand it again to resume and edit its saved route.",
|
||||
"Select a connection and drag a square endpoint handle along its element boundary to move its attachment in this view without changing what it connects. If handles overlap, right-click the selected connection or use its Actions menu and choose Move source attachment or Move target attachment, then drag the handle. Connections to semantic ports retain their port attachment; move the port instead. Reset source attachment or Reset target attachment restores that end's automatic placement while preserving the other end, pins and label. Reset routing clears all these route overrides in this view. Auto-layout preserves pins. Moving one endpoint keeps pins fixed; moving a container carrying both endpoints translates their pins. When folding promotes an endpoint, expand it again to resume and edit its saved route.",
|
||||
],
|
||||
),
|
||||
explain(
|
||||
@@ -564,7 +564,8 @@ fn article(topic: Topic) -> Article {
|
||||
"Optionally select Create the first state view, then Create and open. The new machine starts without regions or states. For an existing machine, Create diagram places its existing regions and vertices in a saved view; + View creates another independent layout.",
|
||||
"Choose + Region and click the highlighted machine, or a State/Mode for a nested region. Choose Initial, State, Mode or another kind from + State / symbol, then click its highlighted owning region. Rename the new element in Properties.",
|
||||
"Choose Transition and drag from a source vertex to a compatible target, or click the source and then the target. In Select / move, drag states or containers to arrange them; a container moves its descendant placements without changing ownership.",
|
||||
"Select a drawn transition and drag its endpoint handle to reconnect it. Its right-click menu also offers Reconnect source and Reconnect target; choose one, then click a compatible vertex.",
|
||||
"Select a drawn transition and drag its endpoint handle to reconnect it. Its right-click menu also offers Reconnect source and Reconnect target; choose one, then click a compatible vertex. To change only where a line touches its existing vertex, choose Adjust source attachment or Adjust target attachment, then drag the highlighted tip along the boundary. Reset source attachment or Reset target attachment restores automatic placement for that end without changing the transition's meaning or other route settings. Escape cancels an attachment drag.",
|
||||
"To shape a selected transition, drag an exposed line segment to add a bend, or drag a square bend handle to move it. Right-click a square and choose Remove bend. The transition's Actions menu also offers Add bend and Clear bends; clearing bends keeps its attachment points and label placement. Bends belong to this saved view. A click alone changes nothing, Escape cancels a drag, and Undo restores the complete edit. Internal transition rows and folded connections do not expose bend editing while their route is hidden.",
|
||||
"Right-click a state or the background for New transition with details… to create Local, Internal or timed behavior. Right-click an existing transition and choose Edit transition to edit its kind, triggers, guard and effects. EntryPoint outgoing transitions use Local. Apply accepts the complete form; invalid drafts remain available for correction.",
|
||||
],
|
||||
),
|
||||
|
||||
@@ -14,6 +14,7 @@ pub struct Request {
|
||||
pub placement: Option<Id>,
|
||||
pub bend: Option<usize>,
|
||||
pub route_point: Option<Position>,
|
||||
pub route_segment: Option<(usize, Position)>,
|
||||
pub creation_point: Option<Position>,
|
||||
pub canvas: Option<route_edit::Context>,
|
||||
pub source_file: Option<String>,
|
||||
@@ -26,6 +27,7 @@ impl Request {
|
||||
placement: None,
|
||||
bend: None,
|
||||
route_point: None,
|
||||
route_segment: None,
|
||||
creation_point: None,
|
||||
canvas: None,
|
||||
source_file: None,
|
||||
@@ -240,6 +242,33 @@ pub fn popup(app: &App) -> Option<Menu<Message>> {
|
||||
.is_none_or(|(s, t)| s == e.source && t == e.target)
|
||||
});
|
||||
let route = diagram.and_then(|d| d.routes.iter().find(|r| r.edge == id));
|
||||
if let Some((diagram, view)) = diagram.zip(view.as_ref()) {
|
||||
for (end, choose, reset) in [
|
||||
(
|
||||
EdgeEnd::Source,
|
||||
"Move source attachment",
|
||||
"Reset source attachment",
|
||||
),
|
||||
(
|
||||
EdgeEnd::Target,
|
||||
"Move target attachment",
|
||||
"Reset target attachment",
|
||||
),
|
||||
] {
|
||||
let eligible = editable
|
||||
&& route_edit::attachment_node(p, diagram, view, id, end).is_some();
|
||||
entries.push(item(
|
||||
choose,
|
||||
Message::Route(route_edit::Event::ChooseAttachment(end)),
|
||||
eligible,
|
||||
));
|
||||
entries.push(item(
|
||||
reset,
|
||||
Message::Route(route_edit::Event::ResetAttachment(end)),
|
||||
eligible && route.is_some_and(|route| route.attachment(end).is_some()),
|
||||
));
|
||||
}
|
||||
}
|
||||
if let Some(point) = request.route_point {
|
||||
entries.push(
|
||||
item(
|
||||
@@ -900,6 +929,36 @@ mod tests {
|
||||
assert_eq!(app.document.bundle(), &changed);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn attachment_end_choice_is_captured_without_mutating_source_and_stale_menu_is_rejected() {
|
||||
let mut project = Project::empty();
|
||||
let source = project.add(Kind::Activity, "Send", 0., 0.);
|
||||
let target = project.add(Kind::Activity, "Receive", 650., 0.);
|
||||
let edge = project.relate(RelationKind::Interaction, "Report", source, target);
|
||||
let mut app = App::with_project(project);
|
||||
let before = app.document.bundle().clone();
|
||||
let mut request = Request::object(edge, Point::ORIGIN);
|
||||
request.canvas = app.route_context();
|
||||
send(&mut app, Message::Menu(Event::Open(request.clone())));
|
||||
let action = choose(&app, "Move target attachment");
|
||||
send(&mut app, action);
|
||||
assert_eq!(
|
||||
app.selected_attachment,
|
||||
Some((app.route_context().unwrap(), edge, EdgeEnd::Target))
|
||||
);
|
||||
assert_eq!(app.document.bundle(), &before);
|
||||
request.canvas = app.route_context();
|
||||
send(&mut app, Message::Menu(Event::Open(request)));
|
||||
let stale = choose(&app, "Move source attachment");
|
||||
send(&mut app, Message::Escape);
|
||||
send(&mut app, stale);
|
||||
assert!(
|
||||
app.selected_attachment
|
||||
.is_none_or(|(context, _, _)| Some(context) != app.route_context())
|
||||
);
|
||||
assert_eq!(app.document.bundle(), &before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn show_from_explorer_places_unfolds_and_keeps_semantic_selection() {
|
||||
let mut p = Project::empty();
|
||||
|
||||
@@ -14,6 +14,9 @@ pub struct Context {
|
||||
pub enum Event {
|
||||
SelectBend(Id, usize),
|
||||
Commit(Context, EdgeRoute, Option<usize>),
|
||||
CommitAttachment(Context, EdgeRoute, EdgeEnd, Id),
|
||||
ChooseAttachment(EdgeEnd),
|
||||
ResetAttachment(EdgeEnd),
|
||||
AddBend,
|
||||
AddBendAt(oa_core::Position),
|
||||
RemoveBend,
|
||||
@@ -23,7 +26,14 @@ pub enum Event {
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Handle {
|
||||
Bend(usize),
|
||||
Label { original: Position },
|
||||
Label {
|
||||
original: Position,
|
||||
},
|
||||
Attachment {
|
||||
end: EdgeEnd,
|
||||
owner: projection::ProjectedNode,
|
||||
original: Option<EdgeAttachment>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -58,8 +68,57 @@ impl Gesture {
|
||||
};
|
||||
}
|
||||
}
|
||||
Handle::Attachment { .. } => {}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn move_attachment_to(&mut self, point: Point, zoom: f32) {
|
||||
let Handle::Attachment {
|
||||
end,
|
||||
ref owner,
|
||||
original,
|
||||
} = self.handle
|
||||
else {
|
||||
self.move_to(point, zoom);
|
||||
return;
|
||||
};
|
||||
if point.distance(self.start) * zoom < 3. {
|
||||
self.route.set_attachment(end, original);
|
||||
self.changed = false;
|
||||
return;
|
||||
}
|
||||
self.changed = true;
|
||||
let attachment = attachment_from_point(
|
||||
owner,
|
||||
position(point),
|
||||
self.route.attachment(end).map(|a| a.side),
|
||||
6. / zoom,
|
||||
);
|
||||
self.route.set_attachment(end, Some(attachment));
|
||||
}
|
||||
}
|
||||
|
||||
/// The painted endpoint must still be the actual unported placement, not a folded proxy.
|
||||
pub fn attachment_node<'a>(
|
||||
project: &Project,
|
||||
diagram: &Diagram,
|
||||
view: &'a projection::ProjectedView,
|
||||
edge: Id,
|
||||
end: EdgeEnd,
|
||||
) -> Option<&'a projection::ProjectedNode> {
|
||||
if semantic_port_endpoint(project, edge, end).is_some() {
|
||||
return None;
|
||||
}
|
||||
let projected = view.edges.iter().find(|e| e.id == edge)?;
|
||||
let actual = projection::edge_endpoint_placements(project, diagram, edge)?;
|
||||
if actual != (projected.source, projected.target) {
|
||||
return None;
|
||||
}
|
||||
let placement = match end {
|
||||
EdgeEnd::Source => projected.source,
|
||||
EdgeEnd::Target => projected.target,
|
||||
};
|
||||
view.nodes.iter().find(|node| node.id == placement)
|
||||
}
|
||||
|
||||
pub fn stored_route(diagram: &Diagram, edge: Id) -> EdgeRoute {
|
||||
@@ -72,10 +131,40 @@ pub fn stored_route(diagram: &Diagram, edge: Id) -> EdgeRoute {
|
||||
edge,
|
||||
waypoints: Vec::new(),
|
||||
label: None,
|
||||
source_attachment: None,
|
||||
target_attachment: None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Insert after the pins preceding the clicked segment along the routed path.
|
||||
pub fn insert_pin_on_segment(
|
||||
route: &mut EdgeRoute,
|
||||
geometry: &RoutedEdge,
|
||||
segment: usize,
|
||||
point: Position,
|
||||
) -> Option<usize> {
|
||||
if route.edge != geometry.id
|
||||
|| geometry.custom_suspended
|
||||
|| route.waypoints != geometry.pins
|
||||
|| route.waypoints.len() >= 128
|
||||
|| !point.x.is_finite()
|
||||
|| !point.y.is_finite()
|
||||
|| geometry
|
||||
.points
|
||||
.get(segment..segment.checked_add(2)?)
|
||||
.is_none()
|
||||
{
|
||||
return None;
|
||||
}
|
||||
let index = pin_insertion_index(geometry, segment, point);
|
||||
if index > route.waypoints.len() {
|
||||
return None;
|
||||
}
|
||||
route.waypoints.insert(index, point);
|
||||
Some(index)
|
||||
}
|
||||
|
||||
/// Find a segment when an ordinary caller has only a point, not a captured hit.
|
||||
pub fn insert_pin(route: &mut EdgeRoute, geometry: &RoutedEdge, point: Position) -> usize {
|
||||
let segment = geometry
|
||||
.points
|
||||
|
||||
@@ -10,7 +10,6 @@ pub enum SymbolEvent {
|
||||
DiagramUsages,
|
||||
Query(query::Action),
|
||||
Back,
|
||||
Close,
|
||||
Choose {
|
||||
stamp: query::QueryStamp,
|
||||
visit: Id,
|
||||
|
||||
@@ -329,6 +329,8 @@ fn reopening_canvas_for_a_modal_preserves_viewport_after_route_edits() {
|
||||
diagram,
|
||||
route: EdgeRoute {
|
||||
edge,
|
||||
source_attachment: None,
|
||||
target_attachment: None,
|
||||
waypoints: vec![Position { x: 400., y: 400. }],
|
||||
label: Some(EdgeLabel {
|
||||
fraction: 0.5,
|
||||
|
||||
@@ -112,6 +112,8 @@ mod tests {
|
||||
});
|
||||
view.routes.push(EdgeRoute {
|
||||
edge: exchange,
|
||||
source_attachment: None,
|
||||
target_attachment: None,
|
||||
waypoints: vec![Position { x: 420., y: 440. }],
|
||||
label: Some(EdgeLabel {
|
||||
fraction: 0.4,
|
||||
|
||||
@@ -466,6 +466,12 @@ fn diagram(app: &App) -> View<'_, Message> {
|
||||
zoom: app.zoom,
|
||||
pan: app.pan,
|
||||
context: app.route_context().unwrap(),
|
||||
selected_attachment: app
|
||||
.selected_attachment
|
||||
.filter(|(context, edge, _)| {
|
||||
Some(*context) == app.route_context() && *edge == app.selected
|
||||
})
|
||||
.map(|(_, _, end)| end),
|
||||
selected_bend: app
|
||||
.selected_bend
|
||||
.filter(|(edge, _)| *edge == app.selected)
|
||||
@@ -1531,6 +1537,16 @@ fn checks(app: &App) -> View<'_, Message> {
|
||||
scrollable(out.padding(24)).into()
|
||||
}
|
||||
|
||||
#[cfg(all(test, debug_assertions))]
|
||||
pub(crate) fn captured_text_drawer_resize(app: &App) -> Message {
|
||||
text_workspace::capture_drawer_resize(app)
|
||||
}
|
||||
|
||||
#[cfg(all(test, debug_assertions))]
|
||||
pub(crate) fn captured_source_reference_stale_summary(app: &App) -> bool {
|
||||
text_workspace::summary_visibility_tests::rendered_stale(app)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::short;
|
||||
@@ -1584,13 +1600,3 @@ mod tests {
|
||||
assert_eq!(short("e\u{0301}B", 1), "…");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(test, debug_assertions))]
|
||||
pub(crate) fn captured_text_drawer_resize(app: &App) -> Message {
|
||||
text_workspace::capture_drawer_resize(app)
|
||||
}
|
||||
|
||||
#[cfg(all(test, debug_assertions))]
|
||||
pub(crate) fn captured_source_reference_stale_summary(app: &App) -> bool {
|
||||
text_workspace::summary_visibility_tests::rendered_stale(app)
|
||||
}
|
||||
|
||||
@@ -234,6 +234,8 @@ fn basic_transition_reconcile_keeps_existing_selected_view_placement_and_route_e
|
||||
.routes
|
||||
.push(EdgeRoute {
|
||||
edge: trace,
|
||||
source_attachment: None,
|
||||
target_attachment: None,
|
||||
waypoints: vec![Position { x: 301., y: 507. }],
|
||||
label: Some(EdgeLabel {
|
||||
fraction: 0.35,
|
||||
|
||||
@@ -12,6 +12,8 @@ use tokio::{sync::oneshot, task::JoinHandle};
|
||||
mod communication_limits;
|
||||
#[path = "http/data_contracts.rs"]
|
||||
mod data_contracts;
|
||||
#[path = "http/edge_attachments.rs"]
|
||||
mod edge_attachments;
|
||||
#[path = "http/port_anchors.rs"]
|
||||
mod port_anchors;
|
||||
#[path = "http/semantic_transitions.rs"]
|
||||
|
||||
@@ -0,0 +1,344 @@
|
||||
use super::*;
|
||||
use oa_core::{
|
||||
EdgeAttachment, PortAnchorSide,
|
||||
source_project::{ProjectLimits, SourceBundle, compile_bundle},
|
||||
};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
fn source_bundle() -> SourceBundle {
|
||||
compile_bundle(&SourceBundle {
|
||||
entry: "project.arcadia".into(),
|
||||
files: BTreeMap::from([
|
||||
("project.arcadia".into(), "// project rationale\narcadia 7; project attachments \"Attachments\" { include \"model.arcadia\"; include \"views.arcadia\"; }\n".into()),
|
||||
("model.arcadia".into(), "// semantic ownership\noa_activity first \"First\" {}\noa_activity second \"Second\" {}\ninteraction signal \"Signal\" { source @first; target @second; }\n".into()),
|
||||
("views.arcadia".into(), "// view rationale\ndiagram view \"View\" { routes [{ edge @signal; waypoints [{ x 120; y 80; }]; label { fraction 0.5; offset { x 3; y -7; }; }; }]; }\ndiagram other \"Other\" { routes [{ edge @signal; }]; }\n".into()),
|
||||
]),
|
||||
}, ProjectLimits::default()).unwrap().bundle
|
||||
}
|
||||
|
||||
fn id(project: &Project, alias: &str) -> Id {
|
||||
project
|
||||
.identities()
|
||||
.into_iter()
|
||||
.find(|(_, a)| *a == alias)
|
||||
.unwrap()
|
||||
.0
|
||||
}
|
||||
|
||||
async fn import(server: &TestServer) -> StoredProject {
|
||||
let response = server
|
||||
.client
|
||||
.post(server.url("/projects/import-source-project"))
|
||||
.json(&source_bundle())
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
let status = response.status();
|
||||
let value: Value = response.json().await.unwrap();
|
||||
assert_eq!(status, StatusCode::CREATED, "{value}");
|
||||
server
|
||||
.get(value["resource_id"].as_str().unwrap().parse().unwrap())
|
||||
.await
|
||||
}
|
||||
|
||||
async fn transact(
|
||||
server: &TestServer,
|
||||
current: &StoredProject,
|
||||
commands: Value,
|
||||
dry_run: bool,
|
||||
) -> reqwest::Response {
|
||||
server
|
||||
.client
|
||||
.post(server.url(&format!("/projects/{}/transactions", current.resource_id)))
|
||||
.header("if-match", current.etag())
|
||||
.json(&json!({"commands":commands,"dry_run":dry_run}))
|
||||
.send()
|
||||
.await
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn assert_pair(current: &StoredProject) {
|
||||
let compiled = compile_bundle(¤t.source_project, ProjectLimits::default()).unwrap();
|
||||
assert_eq!(compiled.decoded.project, current.model);
|
||||
assert_eq!(compiled.bundle, current.source_project);
|
||||
}
|
||||
|
||||
async fn assert_unchanged(server: &TestServer, expected: &StoredProject) {
|
||||
let actual = server.get(expected.resource_id).await;
|
||||
assert_eq!(actual.etag(), expected.etag());
|
||||
assert_eq!(
|
||||
serde_json::to_value(actual).unwrap(),
|
||||
serde_json::to_value(expected).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn edge_attachments_http_dry_run_etags_source_parity_and_restart() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let server = TestServer::start(directory.path(), None).await;
|
||||
let original = import(&server).await;
|
||||
let diagram = id(&original.model, "view");
|
||||
let mut expected = original.model.clone();
|
||||
let route = &mut expected.diagrams.get_mut(&diagram).unwrap().routes[0];
|
||||
route.source_attachment = Some(EdgeAttachment {
|
||||
side: PortAnchorSide::Left,
|
||||
offset: 0.25,
|
||||
});
|
||||
route.target_attachment = Some(EdgeAttachment {
|
||||
side: PortAnchorSide::Bottom,
|
||||
offset: 1.0,
|
||||
});
|
||||
let commands = json!([Command::SetEdgeRoute {
|
||||
diagram,
|
||||
route: route.clone()
|
||||
}]);
|
||||
let preview = transact(&server, &original, commands.clone(), true).await;
|
||||
assert_eq!(preview.status(), StatusCode::OK);
|
||||
let preview: Value = preview.json().await.unwrap();
|
||||
assert_eq!(
|
||||
serde_json::from_value::<Project>(preview["model"].clone()).unwrap(),
|
||||
expected
|
||||
);
|
||||
let proposed: SourceBundle = serde_json::from_value(preview["source_project"].clone()).unwrap();
|
||||
assert_eq!(
|
||||
compile_bundle(&proposed, ProjectLimits::default())
|
||||
.unwrap()
|
||||
.decoded
|
||||
.project,
|
||||
expected
|
||||
);
|
||||
assert_unchanged(&server, &original).await;
|
||||
|
||||
let applied = transact(&server, &original, commands.clone(), false).await;
|
||||
assert_eq!(applied.status(), StatusCode::OK);
|
||||
let mut current = server.get(original.resource_id).await;
|
||||
assert_eq!(applied.headers()["etag"], current.etag());
|
||||
assert_eq!(current.revision, original.revision + 1);
|
||||
assert_eq!(
|
||||
current.model, expected,
|
||||
"only the two attachment fields in this view change"
|
||||
);
|
||||
assert_eq!(current.source_project, proposed);
|
||||
assert_pair(¤t);
|
||||
for path in ["project.arcadia", "model.arcadia"] {
|
||||
assert_eq!(
|
||||
current.source_project.files[path],
|
||||
original.source_project.files[path]
|
||||
);
|
||||
}
|
||||
assert!(current.source_project.files["views.arcadia"].contains("// view rationale"));
|
||||
let noop = transact(&server, ¤t, commands.clone(), false).await;
|
||||
assert_eq!(noop.status(), StatusCode::OK);
|
||||
assert_eq!(noop.headers()["etag"], current.etag());
|
||||
assert_eq!(noop.json::<Value>().await.unwrap()["changed"], false);
|
||||
let stale = json!([
|
||||
Command::Rename(id(¤t.model, "first"), "Must not persist".into()),
|
||||
commands[0].clone()
|
||||
]);
|
||||
assert_eq!(
|
||||
transact(&server, &original, stale, false).await.status(),
|
||||
StatusCode::PRECONDITION_FAILED
|
||||
);
|
||||
assert_unchanged(&server, ¤t).await;
|
||||
|
||||
let mut edited = current.source_project.clone();
|
||||
let text = edited.files.get_mut("views.arcadia").unwrap();
|
||||
assert_eq!(text.matches("offset 0.25;").count(), 1);
|
||||
*text = text.replace("offset 0.25;", "offset 0.375;");
|
||||
expected.diagrams.get_mut(&diagram).unwrap().routes[0]
|
||||
.source_attachment
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.offset = 0.375;
|
||||
let response = server
|
||||
.client
|
||||
.put(server.url(&format!("/projects/{}/source-project", current.resource_id)))
|
||||
.header("if-match", current.etag())
|
||||
.json(&edited)
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
response.status(),
|
||||
StatusCode::OK,
|
||||
"{}",
|
||||
response.text().await.unwrap()
|
||||
);
|
||||
current = server.get(current.resource_id).await;
|
||||
assert_eq!(current.model, expected);
|
||||
assert_eq!(current.source_project, edited);
|
||||
assert_pair(¤t);
|
||||
let source = server
|
||||
.client
|
||||
.get(server.url(&format!("/projects/{}/source", current.resource_id)))
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(source.status(), StatusCode::OK);
|
||||
assert_eq!(source.headers()["etag"], current.etag());
|
||||
assert_eq!(
|
||||
oa_core::language::parse(&source.text().await.unwrap()).unwrap(),
|
||||
expected
|
||||
);
|
||||
let bundle = server
|
||||
.client
|
||||
.get(server.url(&format!("/projects/{}/source-project", current.resource_id)))
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(bundle.status(), StatusCode::OK);
|
||||
assert_eq!(bundle.headers()["etag"], current.etag());
|
||||
assert_eq!(
|
||||
bundle.json::<SourceBundle>().await.unwrap(),
|
||||
current.source_project
|
||||
);
|
||||
server.stop().await;
|
||||
|
||||
let server = TestServer::start(directory.path(), None).await;
|
||||
assert_unchanged(&server, ¤t).await;
|
||||
let mut route = expected.diagrams[&diagram].routes[0].clone();
|
||||
route.source_attachment = None;
|
||||
let reset = json!([Command::SetEdgeRoute {
|
||||
diagram,
|
||||
route: route.clone()
|
||||
}]);
|
||||
assert_eq!(
|
||||
transact(&server, ¤t, reset.clone(), false)
|
||||
.await
|
||||
.status(),
|
||||
StatusCode::OK
|
||||
);
|
||||
expected.diagrams.get_mut(&diagram).unwrap().routes[0] = route;
|
||||
let reset_state = server.get(current.resource_id).await;
|
||||
assert_eq!(
|
||||
reset_state.model, expected,
|
||||
"reset preserves pins, label, opposite end, other view and semantics"
|
||||
);
|
||||
assert_pair(&reset_state);
|
||||
let noop = transact(&server, &reset_state, reset, false).await;
|
||||
assert_eq!(noop.status(), StatusCode::OK);
|
||||
assert_eq!(noop.headers()["etag"], reset_state.etag());
|
||||
assert_eq!(noop.json::<Value>().await.unwrap()["changed"], false);
|
||||
server.stop().await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn edge_attachments_http_malformed_and_invalid_offsets_reject_atomically() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let server = TestServer::start(directory.path(), None).await;
|
||||
let current = import(&server).await;
|
||||
let diagram = id(¤t.model, "view");
|
||||
let first = id(¤t.model, "first");
|
||||
for (bad, status) in [
|
||||
(json!({}), StatusCode::BAD_REQUEST),
|
||||
(json!({"side":"Top"}), StatusCode::BAD_REQUEST),
|
||||
(json!({"offset":0.5}), StatusCode::BAD_REQUEST),
|
||||
(
|
||||
json!({"side":"Diagonal","offset":0.5}),
|
||||
StatusCode::BAD_REQUEST,
|
||||
),
|
||||
(json!({"side":"Top","offset":null}), StatusCode::BAD_REQUEST),
|
||||
(
|
||||
json!({"side":"Top","offset":"NaN"}),
|
||||
StatusCode::BAD_REQUEST,
|
||||
),
|
||||
(
|
||||
json!({"side":"Top","offset":0.5,"unknown":true}),
|
||||
StatusCode::BAD_REQUEST,
|
||||
),
|
||||
(
|
||||
json!({"side":"Top","offset":-0.01}),
|
||||
StatusCode::UNPROCESSABLE_ENTITY,
|
||||
),
|
||||
(
|
||||
json!({"side":"Top","offset":1.01}),
|
||||
StatusCode::UNPROCESSABLE_ENTITY,
|
||||
),
|
||||
] {
|
||||
for field in ["source_attachment", "target_attachment"] {
|
||||
let mut route =
|
||||
serde_json::to_value(¤t.model.diagrams[&diagram].routes[0]).unwrap();
|
||||
route[field] = bad.clone();
|
||||
let commands = json!([Command::Rename(first, "Must roll back".into()), {"SetEdgeRoute":{"diagram":diagram,"route":route}}]);
|
||||
let response = transact(&server, ¤t, commands, false).await;
|
||||
assert_eq!(
|
||||
response.status(),
|
||||
status,
|
||||
"{field} {bad}: {}",
|
||||
response.text().await.unwrap()
|
||||
);
|
||||
assert_unchanged(&server, ¤t).await;
|
||||
}
|
||||
}
|
||||
let mut invalid = current.model.clone();
|
||||
invalid.diagrams.get_mut(&diagram).unwrap().routes[0].target_attachment =
|
||||
Some(EdgeAttachment {
|
||||
side: PortAnchorSide::Right,
|
||||
offset: 2.0,
|
||||
});
|
||||
let response = server
|
||||
.client
|
||||
.put(server.url(&format!("/projects/{}/model", current.resource_id)))
|
||||
.header("if-match", current.etag())
|
||||
.json(&invalid)
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::UNPROCESSABLE_ENTITY);
|
||||
assert_unchanged(&server, ¤t).await;
|
||||
server.stop().await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn edge_attachments_served_openapi_matches_required_nested_records_and_optional_ends() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let server = TestServer::start(directory.path(), None).await;
|
||||
let response = server
|
||||
.client
|
||||
.get(server.url("/openapi.json"))
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
let schema: Value = response.json().await.unwrap();
|
||||
let schemas = &schema["components"]["schemas"];
|
||||
let attachment = &schemas["EdgeAttachment"];
|
||||
assert_eq!(attachment["required"], json!(["side", "offset"]));
|
||||
assert_eq!(attachment["additionalProperties"], false);
|
||||
assert_eq!(
|
||||
attachment["properties"]["side"]["$ref"],
|
||||
"#/components/schemas/PortAnchorSide"
|
||||
);
|
||||
assert_eq!(attachment["properties"]["offset"]["minimum"], 0);
|
||||
assert_eq!(attachment["properties"]["offset"]["maximum"], 1);
|
||||
for field in ["source_attachment", "target_attachment"] {
|
||||
assert!(
|
||||
!schemas["EdgeRoute"]["required"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.contains(&json!(field))
|
||||
);
|
||||
let optional = &schemas["EdgeRoute"]["properties"][field];
|
||||
assert_eq!(optional["default"], Value::Null);
|
||||
assert_eq!(
|
||||
optional["oneOf"],
|
||||
json!([{"$ref":"#/components/schemas/EdgeAttachment"},{"type":"null"}])
|
||||
);
|
||||
}
|
||||
let compiled = compile_bundle(&source_bundle(), ProjectLimits::default()).unwrap();
|
||||
let diagram = id(&compiled.decoded.project, "view");
|
||||
let mut route = compiled.decoded.project.diagrams[&diagram].routes[0].clone();
|
||||
let omitted = serde_json::to_value(&route).unwrap();
|
||||
assert!(omitted.get("source_attachment").is_none());
|
||||
assert!(omitted.get("target_attachment").is_none());
|
||||
route.target_attachment = Some(EdgeAttachment {
|
||||
side: PortAnchorSide::Right,
|
||||
offset: 0.0,
|
||||
});
|
||||
let encoded = serde_json::to_value(Command::SetEdgeRoute { diagram, route }).unwrap();
|
||||
assert_eq!(
|
||||
encoded["SetEdgeRoute"]["route"]["target_attachment"],
|
||||
json!({"side":"Right","offset":0.0})
|
||||
);
|
||||
server.stop().await;
|
||||
}
|
||||
@@ -75,6 +75,164 @@ fn assert_pair(current: &StoredProject) {
|
||||
assert_eq!(compiled.bundle, current.source_project);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn explicit_empty_port_anchors_survive_http_move_and_restart_but_export_compactly() {
|
||||
fn replace_once(source: &mut String, before: &str, after: &str) {
|
||||
assert_eq!(
|
||||
source.matches(before).count(),
|
||||
1,
|
||||
"ambiguous or absent anchor: {before}"
|
||||
);
|
||||
let replacement = source.replacen(before, after, 1);
|
||||
assert_ne!(*source, replacement, "fixture mutation must change source");
|
||||
*source = replacement;
|
||||
}
|
||||
|
||||
async fn assert_exports(server: &TestServer, current: &StoredProject, node: Id) -> String {
|
||||
let response = server
|
||||
.client
|
||||
.get(server.url(&format!("/projects/{}/source-project", current.resource_id)))
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
assert_eq!(response.headers()["etag"], current.etag());
|
||||
assert_eq!(
|
||||
response.json::<SourceBundle>().await.unwrap(),
|
||||
current.source_project
|
||||
);
|
||||
|
||||
let response = server
|
||||
.client
|
||||
.get(server.url(&format!("/projects/{}/source", current.resource_id)))
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
let canonical = response.text().await.unwrap();
|
||||
assert_eq!(oa_core::language::parse(&canonical).unwrap(), current.model);
|
||||
assert_eq!(canonical, oa_core::language::format(¤t.model));
|
||||
let exported = compile_bundle(
|
||||
&SourceBundle {
|
||||
entry: "project.arcadia".into(),
|
||||
files: BTreeMap::from([("project.arcadia".into(), canonical.clone())]),
|
||||
},
|
||||
ProjectLimits::default(),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(exported.decoded.project, current.model);
|
||||
assert!(exported.index.declarations.contains_key(&node));
|
||||
assert!(
|
||||
!exported
|
||||
.index
|
||||
.fields
|
||||
.contains_key(&(node, "port_anchors".into()))
|
||||
);
|
||||
canonical
|
||||
}
|
||||
|
||||
let mut authored = source_bundle();
|
||||
replace_once(
|
||||
authored.files.get_mut("views.arcadia").unwrap(),
|
||||
"diagram @architecture; element @vessel;",
|
||||
"diagram @architecture; element @vessel;\n position { x 12.5; y -4.0; };\n port_anchors [] ; // Keep explicit automatic placement.\n",
|
||||
);
|
||||
let compiled = compile_bundle(&authored, ProjectLimits::default()).unwrap();
|
||||
assert_eq!(
|
||||
compiled.bundle, authored,
|
||||
"the HTTP fixture must already be stable"
|
||||
);
|
||||
let diagram = id(&compiled.decoded.project, "architecture");
|
||||
let node = id(&compiled.decoded.project, "actor_view");
|
||||
assert!(
|
||||
compiled
|
||||
.index
|
||||
.fields
|
||||
.contains_key(&(node, "port_anchors".into()))
|
||||
);
|
||||
assert_eq!(
|
||||
compiled.decoded.project.diagrams[&diagram].nodes[&node].position,
|
||||
oa_core::Position { x: 12.5, y: -4.0 }
|
||||
);
|
||||
assert!(
|
||||
compiled.decoded.project.diagrams[&diagram].nodes[&node]
|
||||
.port_anchors
|
||||
.is_empty()
|
||||
);
|
||||
|
||||
// Independent full-model oracle: only this placement coordinate changes.
|
||||
let mut expected_model = compiled.decoded.project.clone();
|
||||
expected_model
|
||||
.diagrams
|
||||
.get_mut(&diagram)
|
||||
.unwrap()
|
||||
.nodes
|
||||
.get_mut(&node)
|
||||
.unwrap()
|
||||
.position
|
||||
.x = 25.0;
|
||||
let mut expected_source = authored.clone();
|
||||
replace_once(
|
||||
expected_source.files.get_mut("views.arcadia").unwrap(),
|
||||
"x 12.5;",
|
||||
"x 25.0;",
|
||||
);
|
||||
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let server = TestServer::start(directory.path(), None).await;
|
||||
let response = server
|
||||
.client
|
||||
.post(server.url("/projects/import-source-project"))
|
||||
.json(&authored)
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
let status = response.status();
|
||||
let value: Value = response.json().await.unwrap();
|
||||
assert_eq!(status, StatusCode::CREATED, "{value}");
|
||||
let original = server
|
||||
.get(value["resource_id"].as_str().unwrap().parse().unwrap())
|
||||
.await;
|
||||
assert_eq!(original.model, compiled.decoded.project);
|
||||
assert_eq!(original.source_project, authored);
|
||||
assert_pair(&original);
|
||||
assert_exports(&server, &original, node).await;
|
||||
|
||||
let response = transact(
|
||||
&server,
|
||||
&original,
|
||||
json!([{"MoveNode": {"diagram": diagram, "node": node,
|
||||
"position": {"x": 25.0, "y": -4.0}, "with_descendants": false}}]),
|
||||
false,
|
||||
)
|
||||
.await;
|
||||
let status = response.status();
|
||||
let value: Value = response.json().await.unwrap();
|
||||
assert_eq!(status, StatusCode::OK, "{value}");
|
||||
assert_eq!(value["changed"], true);
|
||||
let current = server.get(original.resource_id).await;
|
||||
assert_eq!(current.revision, original.revision + 1);
|
||||
assert_eq!(current.model, expected_model);
|
||||
// Exact bundle equality covers the explicit empty field, its rationale,
|
||||
// sibling placement, and all untouched files and source trivia.
|
||||
assert_eq!(current.source_project, expected_source);
|
||||
assert_pair(¤t);
|
||||
let canonical = assert_exports(&server, ¤t, node).await;
|
||||
|
||||
server.stop().await;
|
||||
let server = TestServer::start(directory.path(), None).await;
|
||||
let reopened = server.get(current.resource_id).await;
|
||||
assert_eq!(reopened.model, expected_model);
|
||||
assert_eq!(reopened.source_project, expected_source);
|
||||
assert_eq!(
|
||||
serde_json::to_value(&reopened).unwrap(),
|
||||
serde_json::to_value(¤t).unwrap()
|
||||
);
|
||||
assert_pair(&reopened);
|
||||
assert_eq!(assert_exports(&server, &reopened, node).await, canonical);
|
||||
server.stop().await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn port_anchor_http_commands_and_source_edits_preserve_per_view_state_after_restart() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
|
||||
+28
-1
@@ -2,7 +2,7 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="generator" content="Docutils 0.22.2: https://docutils.sourceforge.io/" />
|
||||
<meta name="generator" content="Docutils 0.23: https://docutils.sourceforge.io/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Arcadia Studio model REST API</title>
|
||||
<style type="text/css">
|
||||
@@ -947,6 +947,33 @@ authored files and revision. JSON/source imports may omit <span class="docutils
|
||||
it defaults to <span class="docutils literal">[]</span> and empty lists are omitted on export. The normative
|
||||
diagram semantics and source spelling are in <span class="docutils literal">language.rst</span> section 5.</p>
|
||||
</section>
|
||||
<section id="diagram-connection-attachments">
|
||||
<h2>Diagram connection attachments</h2>
|
||||
<p><span class="docutils literal">EdgeRoute.source_attachment</span> and <span class="docutils literal">target_attachment</span> are optional
|
||||
<span class="docutils literal"><span class="pre">{"side":"Bottom","offset":0.25}</span></span> records. Side and a finite offset in
|
||||
<span class="docutils literal">[0,1]</span> are required within a supplied record; unknown fields are rejected.
|
||||
Absence/null means automatic placement. Omitted fields in older schema-3
|
||||
models retain that meaning. The normal transaction endpoint accepts:</p>
|
||||
<pre class="literal-block">{"commands":[{"SetEdgeRoute":{
|
||||
"diagram":"<diagram UUID>",
|
||||
"route":{"edge":"<relation or trace UUID>",
|
||||
"source_attachment":{"side":"Bottom","offset":0.25},
|
||||
"waypoints":[],"label":null}
|
||||
}}]}</pre>
|
||||
<p><span class="docutils literal">SetEdgeRoute</span> replaces the complete route entry. Clients changing one end
|
||||
must retain its other attachment, bends and label; omit/null only the intended
|
||||
attachment to restore that end's automatic position. <span class="docutils literal">RemoveEdgeRoute</span> resets
|
||||
all presentation for that edge. Both support ETag checking, dry runs, atomic
|
||||
validation and source-project writeback. Invalid offsets reject the whole
|
||||
transaction without changing files or revision.</p>
|
||||
<p>These are per-view presentation preferences, not a semantic reconnect. Fractions
|
||||
follow the projected shape, including moves/resizes; semantic reconnect retains
|
||||
them as preferences of the same edge-end slots. Real semantic ports take
|
||||
precedence, and promoted folded endpoints suspend authored routing. The complete
|
||||
boundary mapping, lifecycle and generated-view limitations are normative in
|
||||
<span class="docutils literal">language.rst</span> section 5. GET model/source, PUT source, desktop and transactions
|
||||
share this representation; no separate attachment endpoint exists.</p>
|
||||
</section>
|
||||
<section id="contextual-process-and-chain-topology">
|
||||
<h2>Contextual process and chain topology</h2>
|
||||
<p>Operational processes and system functional chains can combine work
|
||||
|
||||
@@ -329,6 +329,37 @@ authored files and revision. JSON/source imports may omit ``port_anchors``;
|
||||
it defaults to ``[]`` and empty lists are omitted on export. The normative
|
||||
diagram semantics and source spelling are in ``language.rst`` section 5.
|
||||
|
||||
Diagram connection attachments
|
||||
-------------------------------
|
||||
|
||||
``EdgeRoute.source_attachment`` and ``target_attachment`` are optional
|
||||
``{"side":"Bottom","offset":0.25}`` records. Side and a finite offset in
|
||||
``[0,1]`` are required within a supplied record; unknown fields are rejected.
|
||||
Absence/null means automatic placement. Omitted fields in older schema-3
|
||||
models retain that meaning. The normal transaction endpoint accepts::
|
||||
|
||||
{"commands":[{"SetEdgeRoute":{
|
||||
"diagram":"<diagram UUID>",
|
||||
"route":{"edge":"<relation or trace UUID>",
|
||||
"source_attachment":{"side":"Bottom","offset":0.25},
|
||||
"waypoints":[],"label":null}
|
||||
}}]}
|
||||
|
||||
``SetEdgeRoute`` replaces the complete route entry. Clients changing one end
|
||||
must retain its other attachment, bends and label; omit/null only the intended
|
||||
attachment to restore that end's automatic position. ``RemoveEdgeRoute`` resets
|
||||
all presentation for that edge. Both support ETag checking, dry runs, atomic
|
||||
validation and source-project writeback. Invalid offsets reject the whole
|
||||
transaction without changing files or revision.
|
||||
|
||||
These are per-view presentation preferences, not a semantic reconnect. Fractions
|
||||
follow the projected shape, including moves/resizes; semantic reconnect retains
|
||||
them as preferences of the same edge-end slots. Real semantic ports take
|
||||
precedence, and promoted folded endpoints suspend authored routing. The complete
|
||||
boundary mapping, lifecycle and generated-view limitations are normative in
|
||||
``language.rst`` section 5. GET model/source, PUT source, desktop and transactions
|
||||
share this representation; no separate attachment endpoint exists.
|
||||
|
||||
Contextual process and chain topology
|
||||
-------------------------------------
|
||||
|
||||
|
||||
+152
-18
@@ -2,7 +2,7 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="generator" content="Docutils 0.22.2: https://docutils.sourceforge.io/" />
|
||||
<meta name="generator" content="Docutils 0.23: https://docutils.sourceforge.io/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Arcadia Studio OA / SA Language and Editing Contract</title>
|
||||
<style type="text/css">
|
||||
@@ -806,11 +806,11 @@ references may be omitted and then mean <span class="docutils literal">none</spa
|
||||
These omissions are accepted in newly authored source 7, not only in schema-2
|
||||
compatibility input. Earlier schema admission of constructors and fields is
|
||||
still governed by its version rules.</p>
|
||||
<p>Canonical formatting writes the hydrated occurrence references and default
|
||||
<span class="docutils literal">message_kind</span>, <span class="docutils literal">reply_to</span> and <span class="docutils literal">values</span> explicitly. An absent
|
||||
<span class="docutils literal">operation</span> remains omitted in canonical output. Lossless no-op updates and
|
||||
unrelated name edits retain authored omissions; canonical formatting is a
|
||||
different operation. An admitted incomplete occurrence can still produce model
|
||||
<p>Canonical formatting omits optional occurrence references equal to <span class="docutils literal">none</span>,
|
||||
the default Asynchronous <span class="docutils literal">message_kind</span>, empty <span class="docutils literal">values</span>, and absent
|
||||
<span class="docutils literal">operation</span>. Required fields of a selected constructor remain present.
|
||||
Lossless updates retain unchanged explicit defaults and authored omissions;
|
||||
canonical formatting is a different operation. An admitted incomplete occurrence can still produce model
|
||||
checks requesting its missing work, exchange, lifeline or referenced scenario.</p>
|
||||
<table>
|
||||
<caption>Occurrence body constructors</caption>
|
||||
@@ -1569,29 +1569,40 @@ has no explicit default, and does not convey ownership or deletion of the type.<
|
||||
<thead>
|
||||
<tr><th class="head"><p>Constructor</p></th>
|
||||
<th class="head"><p>Required fields</p></th>
|
||||
<th class="head"><p>Optional fields (omission value)</p></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr><td><p>Boolean</p></td>
|
||||
<td><p>None</p></td>
|
||||
<td><p>None</p></td>
|
||||
</tr>
|
||||
<tr><td><p>Integer</p></td>
|
||||
<td><p><span class="docutils literal">minimum</span>, <span class="docutils literal">maximum</span>: optional signed 64-bit integers</p></td>
|
||||
<td><p>None</p></td>
|
||||
<td><p><span class="docutils literal">minimum</span>, <span class="docutils literal">maximum</span>: signed 64-bit integers? (none)</p></td>
|
||||
</tr>
|
||||
<tr><td><p>Real</p></td>
|
||||
<td><p><span class="docutils literal">minimum</span>, <span class="docutils literal">maximum</span>: optional finite IEEE-754 binary64 values</p></td>
|
||||
<td><p>None</p></td>
|
||||
<td><p><span class="docutils literal">minimum</span>, <span class="docutils literal">maximum</span>: finite IEEE-754 binary64 values? (none)</p></td>
|
||||
</tr>
|
||||
<tr><td><p>String</p></td>
|
||||
<td><p><span class="docutils literal">minimum_length</span>: u32; <span class="docutils literal">maximum_length</span>: optional u32</p></td>
|
||||
<td><p><span class="docutils literal">minimum_length</span>: u32</p></td>
|
||||
<td><p><span class="docutils literal">maximum_length</span>: u32? (none)</p></td>
|
||||
</tr>
|
||||
<tr><td><p>Enumeration</p></td>
|
||||
<td><p><span class="docutils literal">literals</span>: unique nonempty, case-sensitive strings</p></td>
|
||||
<td><p>None</p></td>
|
||||
</tr>
|
||||
<tr><td><p>Record</p></td>
|
||||
<td><p><span class="docutils literal">supertype</span>: same-layer Record ref?</p></td>
|
||||
<td><p>None</p></td>
|
||||
<td><p><span class="docutils literal">supertype</span>: same-layer Record ref? (none)</p></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>Optional fields may be absent or explicitly <span class="docutils literal">none</span>. Selected String and
|
||||
Enumeration constructors still require <span class="docutils literal">minimum_length</span> and <span class="docutils literal">literals</span>,
|
||||
respectively, including zero and an empty list. Selecting a constructor does
|
||||
not merge fields from the default String definition. Unknown fields reject.</p>
|
||||
<p>Bounds are inclusive and ordered; an absent bound means unbounded within the
|
||||
represented numeric domain. Integer comparisons MUST NOT convert to binary64.
|
||||
NaN, infinities, overflow and reversed bounds reject. String length counts Unicode
|
||||
@@ -1774,14 +1785,16 @@ the Reparent command. Moving, resizing, arranging, or folding an owner retains
|
||||
its authored sides and fractions. Frozen schema-1/schema-2 readers do not accept
|
||||
<span class="docutils literal">port_anchors</span>; their explicit migration supplies an empty list.</p>
|
||||
<p>Each <span class="docutils literal">routes</span> entry is an EdgeRoute record with a required <span class="docutils literal">edge</span> reference
|
||||
to an existing Relation or Trace, <span class="docutils literal">waypoints</span> (default <span class="docutils literal">[]</span>), and <span class="docutils literal">label</span>
|
||||
(default <span class="docutils literal">none</span>). Route records have no separate UUID or alias. An edge occurs
|
||||
to an existing Relation or Trace, <span class="docutils literal">waypoints</span> (default <span class="docutils literal">[]</span>), <span class="docutils literal">label</span>
|
||||
(default <span class="docutils literal">none</span>), and <span class="docutils literal">source_attachment</span> / <span class="docutils literal">target_attachment</span> (each
|
||||
default <span class="docutils literal">none</span>). Route records have no separate UUID or alias. An edge occurs
|
||||
at most once in a diagram's route list; different diagrams MAY store independent
|
||||
routes for the same edge. List order and explicit empty entries are retained by
|
||||
source and JSON round trips, although list order has no routing meaning. Edges
|
||||
need not currently be visible in their diagram.</p>
|
||||
<pre class="code text literal-block"><code>routes [
|
||||
{ edge @report_exchange;
|
||||
source_attachment { side Bottom; offset 0.25; };
|
||||
waypoints [{ x 420; y 260; }, { x 690; y 260; }];
|
||||
label { fraction 0.55; offset { x 0; y -16; }; };
|
||||
}
|
||||
@@ -1798,6 +1811,47 @@ are structural errors. A pinned point that obstructs routing remains stored;
|
||||
geometric routing difficulty is reported separately from structural validity.
|
||||
Each EdgeRoute counts as one record against <span class="docutils literal">ParseLimits.max_records</span>; pinned
|
||||
points are bounded by the per-route limit and aggregate input byte limits.</p>
|
||||
<p>An attachment is an EdgeAttachment record with required <span class="docutils literal">side</span> (Left, Right,
|
||||
Top, Bottom) and required finite binary32 <span class="docutils literal">offset</span> from zero through one.
|
||||
Unknown fields, omitted nested fields and out-of-range offsets are structural
|
||||
errors (<span class="docutils literal">invalid_attachment_offset</span> for the latter). Attachments are bounded
|
||||
inline values, at most two per route, not additional graph objects or records.
|
||||
JSON uses the same field names, enum strings and number values. Omitted or null
|
||||
attachments mean automatic positioning; canonical compact source and JSON omit
|
||||
absent attachments. Earlier schema-3 input hydrates both fields as absent.</p>
|
||||
<p>The end names designate stored source/target slots, even for undirected edges.
|
||||
These values MUST NOT change semantic endpoints, ports, ownership, type,
|
||||
orientation or identity. Each preference belongs to that edge end in that view:
|
||||
another view remains independent. It follows the current endpoint's projected
|
||||
boundary under movement, resize or semantic reconnect; reconnect preserves the
|
||||
preference, as it preserves authored bends. The fraction does not identify the
|
||||
previous semantic endpoint. Deletion/reidentification of the edge follows the
|
||||
existing whole-route rules; moving, hiding or replacing its placement retains
|
||||
the preference. Removing one attachment restores that end's automatic position
|
||||
without changing bends, labels or the opposite attachment.</p>
|
||||
<p>For Left/Right, offset gives the Y fraction of the complete projected bounding
|
||||
box; for Top/Bottom it gives the X fraction. The attachment intersects the painted
|
||||
shape along that cardinal scan line. Rounded cards use radius 10, limited by half
|
||||
their width/height; Regions and fork/join bars are rectangles. State circles use
|
||||
their ellipse boundary and Choice uses its diamond boundary. More precisely, let
|
||||
<span class="docutils literal">t = 2 * offset - 1</span> and <span class="docutils literal">D</span> be width for Left/Right or height for Top/Bottom.
|
||||
The inset from the selected bounding side is <span class="docutils literal">D/2 * (1 - <span class="pre">sqrt(1-t*t))</span></span> for an
|
||||
ellipse and <span class="docutils literal">D/2 * abs(t)</span> for a diamond. A Terminate X uses the outermost
|
||||
painted-stroke intersection, inset <span class="docutils literal">D * min(offset, <span class="pre">1-offset)</span></span>. Zero and one
|
||||
are valid; different side/fraction pairs can describe the same painted point.
|
||||
Routing leads extend in the selected cardinal direction beyond the bounding box
|
||||
before turning. Source/API fractions retain their precision; pointer editing
|
||||
snaps fractions to hundredths without changing the stored semantic record.</p>
|
||||
<p>An actual semantic Port remains authoritative, including when projection hides
|
||||
its port marker. An edge attachment on that end is retained but dormant; use
|
||||
the port's own placement anchor to move a port. When folding promotes an endpoint
|
||||
to an ancestor, all authored route data is suspended and resumes on expansion.
|
||||
Geometric difficulty MUST NOT discard preferences. Coincident authored self-loop
|
||||
tips retain their positions with an external loop and a routing warning; the
|
||||
editor must offer an explicit way to choose either end even when handles overlap.
|
||||
Internal state transitions have no external connection. Process's generated
|
||||
topology and Scenario's lifeline/activation/time-derived tips are not consumers
|
||||
of these diagram route fields; this feature does not redefine their semantics.</p>
|
||||
<p><span class="docutils literal">SetEdgeRoute { diagram, route }</span> upserts an entry by edge identity, retaining
|
||||
the order and contents of unrelated entries. <span class="docutils literal">RemoveEdgeRoute { diagram, edge }</span>
|
||||
removes it; removing an absent entry is a no-op for an existing diagram and edge.
|
||||
@@ -2439,10 +2493,27 @@ references, placements, artifacts, trace baselines, and ordered occurrences.
|
||||
Map order is irrelevant. The writer preserves signed coordinate zero and
|
||||
emits decimals that recover the original binary32 value.</p>
|
||||
<p>Canonical output uses LF, four-space indentation, explicit identities,
|
||||
defaults, and JSON-escaped strings. Elements are emitted in UUID order, then
|
||||
and JSON-escaped strings. It omits fields equal to the omission defaults of
|
||||
their actual declaration or selected constructor, as specified in the field
|
||||
tables. This includes an empty project description. It MUST NOT omit a required
|
||||
field merely because its value is zero, false, empty, or <span class="docutils literal">none</span>. Elements are emitted in UUID order, then
|
||||
relations; diagrams and their nodes follow, then artifacts, then traces.
|
||||
Fields use deterministic name order. Output ends with LF. Alias values come
|
||||
from the model, never from regenerating display names.</p>
|
||||
<p>Omission is context-sensitive: Scenario uses the source default MixedLegacy;
|
||||
BoundaryExchange and CommunicationMean have different orientation defaults;
|
||||
state declarations determine their state-kind discriminator. A nonempty or
|
||||
whitespace-only description remains exact. Present-empty optional strings or
|
||||
collections, unbounded multiplicity versus a finite default, selected operation
|
||||
intent, and negative coordinate zero remain distinct values. A nondefault
|
||||
geometry record retains all required coordinates or dimensions.</p>
|
||||
<p>Only specified optional fields inside selected constructors may be omitted.
|
||||
For example, Integer bounds and LegacyPortContract.interface may be absent;
|
||||
String.minimum_length, Signal.items, port-contract payload lists, and historical
|
||||
snapshot name/description fields remain required. A LegacyPortContract record
|
||||
still requires direction. Historical semantic baseline payloads are retained
|
||||
without generic empty/default pruning. Compact output MUST preserve every
|
||||
persistent model field after parsing, including these distinctions.</p>
|
||||
<p>Comments and input whitespace are lexical trivia to the canonical writer.
|
||||
Canonical export does not preserve them. The source-project editor and compiler
|
||||
preserve authored comments and whitespace on Apply while inserting missing
|
||||
@@ -2484,11 +2555,19 @@ independent parent and child moves are resolved together. Leading whitespace
|
||||
adjusts to the destination scope; other token spelling remains authored.</p>
|
||||
<p>Updates MUST NOT canonicalize surviving declarations in full. Header, field and
|
||||
nested value positions are derived from the existing syntax parser. Unchanged
|
||||
fields retain their exact bytes, including field order, omitted defaults, number
|
||||
fields retain their exact bytes, including field order, explicit and omitted defaults, number
|
||||
and string spelling, comments, indentation and line endings. Changed literals and
|
||||
references replace only the required tokens; a reference with comments between
|
||||
<span class="docutils literal">@</span> and its alias retains those comments. A previously omitted default is
|
||||
inserted only if its semantic value changes. New fields use the existing record's
|
||||
<span class="docutils literal">@</span> and its alias retains those comments. A previously omitted field is
|
||||
inserted only when needed to express the requested value in its new declaration
|
||||
context. This includes an unchanged value whose omission default changes with
|
||||
the declaration kind. For example, changing BoundaryExchange to CommunicationMean
|
||||
while retaining orientation true requires <span class="docutils literal">oriented true;</span> if previously
|
||||
implicit. Unchanged explicit defaults MUST survive unrelated sibling edits,
|
||||
including persistence-serializer omissions such as <span class="docutils literal">operation none</span>,
|
||||
<span class="docutils literal">port_anchors []</span> and <span class="docutils literal">baseline.semantic none</span>. New fields and value fragments
|
||||
use compact generation while retaining required selected-constructor payloads.
|
||||
New fields use the existing record's
|
||||
indentation and line-ending style without reformatting its other fields.</p>
|
||||
<p>A constructor tag change retains shared nested fields in place. Removed fields,
|
||||
constructors and declarations remove syntax tokens, retaining their comments
|
||||
@@ -2618,6 +2697,26 @@ placement move are different transactions. The UI MUST identify which operation
|
||||
will occur. Reparenting work must not silently change its performer. A computed
|
||||
parent summary must remain distinguishable from direct allocation. A collapse
|
||||
operation hides presentation detail without deleting the children.</p>
|
||||
<p>In an Allocation view, dragging an Activity or Function body MAY combine a
|
||||
performer change with diagram placement. The preview MUST identify the
|
||||
destination and preserve readable work and destination identity. Destination
|
||||
identity is shown outside the canvas, independently of explanatory or refusal
|
||||
text. The outlined target's hit region remains fixed throughout the gesture;
|
||||
feedback MUST NOT obscure the work or change its pointer-relative placement.
|
||||
A clean click selects without applying unrelated drafts. A refused work press
|
||||
with an unapplied property draft MUST preserve its text, caret and focused
|
||||
editor. An accepted drag is one atomic model/source/history transaction:
|
||||
semantic ownership and work identities are
|
||||
preserved; only leaf direct Allocation relations, their own retired routes and
|
||||
the affected view geometry change. Existing Allocation identities are retained
|
||||
on reassignment. Role realizations and assignments MUST NOT be silently changed. Uniform work groups
|
||||
may move their leaf responsibilities together; ambiguous or distributed groups
|
||||
and changes requiring collateral record edits MUST be refused with an explanation.
|
||||
Moving outside performer regions removes direct assignment only when the
|
||||
effective role responsibility is also absent. Releasing outside the viewport
|
||||
cancels the gesture. Explicit Arrange next drag applies geometry alone for one
|
||||
gesture. Refused and snapped no-op drops MUST NOT create history entries or
|
||||
discard Redo. Undo restores the exact source bundle and identities together.</p>
|
||||
<p>Applying a reachable source bundle is one model transaction. Graphical edits
|
||||
update its owning declarations through the source-preserving updater. Both
|
||||
paths validate their candidate and model/source equality before
|
||||
@@ -2719,6 +2818,40 @@ leaving dangling references. Deleting a sequence does not delete the semantic
|
||||
exchanges it references. Cross-layer counterparts are not owned descendants.
|
||||
Text edits describe a complete candidate and must remove or repair dependencies
|
||||
explicitly before Apply succeeds.</p>
|
||||
<section id="focused-diagram-removal">
|
||||
<h3>8.1. Focused diagram removal</h3>
|
||||
<p>Delete is scoped to the focused diagram and the exact visible selection.
|
||||
Text fields retain their own Delete behavior; diagram shortcuts MUST NOT apply
|
||||
pending property, source or behavior drafts. Keyboard traversal retires diagram
|
||||
input admission before subsequent keys in the same event batch are processed.
|
||||
Active placement, creation, connection, reorder and pan gestures do not authorize
|
||||
removal. A stale document, revision, owner or selection MUST NOT redirect removal.</p>
|
||||
<p>For an explicit architecture or state placement, Delete removes that placement
|
||||
only. The semantic element and its placements in other views remain. Shift+Delete
|
||||
requests confirmed deletion of the semantic element, including when selection
|
||||
originated from Placement properties. A selected architecture route bend takes
|
||||
priority: plain Delete removes the bend without removing its edge.</p>
|
||||
<p>A visible relation with no placement, including a state action or internal
|
||||
transition row, uses confirmed relation deletion for either key. States and
|
||||
referenced Activity/Function definitions remain. Hidden or collapsed rows are
|
||||
not keyboard deletion targets.</p>
|
||||
<p>Process and scenario projections have no independent occurrence placements.
|
||||
Delete and Shift+Delete request confirmed removal of the selected occurrence,
|
||||
participant or maintained link. A link's endpoints and outbound reusable
|
||||
definitions are preserved. Removing a fragment or branch removes its owned
|
||||
subtree. Removing a scenario participant preserves its represented element and
|
||||
retains occurrences with affected participant references cleared; resulting
|
||||
incomplete references remain visible for repair. The modeled scenario Delete
|
||||
message is a separate domain event and is not this editing shortcut.</p>
|
||||
<p>A qualified selection inside an expanded reusable process MUST NOT silently
|
||||
delete the outer reference or shared definition item. The editor directs the
|
||||
user to open the definition or explicitly select the outer reference.</p>
|
||||
<p>Confirmation identifies the captured object and removal effect. Cancel and
|
||||
Escape preserve model, source and history. A confirmation token belongs to one
|
||||
dialog; changes to its document, revision, owner or selected identity invalidate
|
||||
it. Accepted deletion uses one ordinary model/source transaction, and Undo
|
||||
restores the exact complete accepted source bundle and model.</p>
|
||||
</section>
|
||||
</section>
|
||||
<section id="persistence-and-explicit-migration">
|
||||
<h2>9. Persistence and explicit migration</h2>
|
||||
@@ -2793,8 +2926,9 @@ This compatibility applies equally to source and JSON. It adds explicit
|
||||
defaults without changing any prior identity, name, reference, order, geometry,
|
||||
artifact or trace field. The original V2 golden source/JSON in
|
||||
<span class="docutils literal"><span class="pre">crates/oa-core/tests/fixtures</span></span> MUST NOT be regenerated from the newer demo;
|
||||
they verify that every old persistent field survives. Canonical output writes
|
||||
the added defaults through explicit migration to the current schema 7.</p>
|
||||
they verify that every old persistent field survives. Canonical output uses
|
||||
the current schema 7 and omits values equal to its specified source defaults;
|
||||
parsing recovers the complete migrated model.</p>
|
||||
<p>The V2 adapter preserves every original identity, alias, prose, parent,
|
||||
placement, trace and artifact. Generic ports become Legacy with their original
|
||||
direction/interface record. Existing FE endpoint IDs remain unchanged. For
|
||||
|
||||
+105
-18
@@ -171,11 +171,11 @@ These omissions are accepted in newly authored source 7, not only in schema-2
|
||||
compatibility input. Earlier schema admission of constructors and fields is
|
||||
still governed by its version rules.
|
||||
|
||||
Canonical formatting writes the hydrated occurrence references and default
|
||||
``message_kind``, ``reply_to`` and ``values`` explicitly. An absent
|
||||
``operation`` remains omitted in canonical output. Lossless no-op updates and
|
||||
unrelated name edits retain authored omissions; canonical formatting is a
|
||||
different operation. An admitted incomplete occurrence can still produce model
|
||||
Canonical formatting omits optional occurrence references equal to ``none``,
|
||||
the default Asynchronous ``message_kind``, empty ``values``, and absent
|
||||
``operation``. Required fields of a selected constructor remain present.
|
||||
Lossless updates retain unchanged explicit defaults and authored omissions;
|
||||
canonical formatting is a different operation. An admitted incomplete occurrence can still produce model
|
||||
checks requesting its missing work, exchange, lifeline or referenced scenario.
|
||||
|
||||
.. list-table:: Occurrence body constructors
|
||||
@@ -933,18 +933,30 @@ DataTypeDefinition has exactly the following constructors:
|
||||
|
||||
* - Constructor
|
||||
- Required fields
|
||||
- Optional fields (omission value)
|
||||
* - Boolean
|
||||
- None
|
||||
- None
|
||||
* - Integer
|
||||
- ``minimum``, ``maximum``: optional signed 64-bit integers
|
||||
- None
|
||||
- ``minimum``, ``maximum``: signed 64-bit integers? (none)
|
||||
* - Real
|
||||
- ``minimum``, ``maximum``: optional finite IEEE-754 binary64 values
|
||||
- None
|
||||
- ``minimum``, ``maximum``: finite IEEE-754 binary64 values? (none)
|
||||
* - String
|
||||
- ``minimum_length``: u32; ``maximum_length``: optional u32
|
||||
- ``minimum_length``: u32
|
||||
- ``maximum_length``: u32? (none)
|
||||
* - Enumeration
|
||||
- ``literals``: unique nonempty, case-sensitive strings
|
||||
- None
|
||||
* - Record
|
||||
- ``supertype``: same-layer Record ref?
|
||||
- None
|
||||
- ``supertype``: same-layer Record ref? (none)
|
||||
|
||||
Optional fields may be absent or explicitly ``none``. Selected String and
|
||||
Enumeration constructors still require ``minimum_length`` and ``literals``,
|
||||
respectively, including zero and an empty list. Selecting a constructor does
|
||||
not merge fields from the default String definition. Unknown fields reject.
|
||||
|
||||
Bounds are inclusive and ordered; an absent bound means unbounded within the
|
||||
represented numeric domain. Integer comparisons MUST NOT convert to binary64.
|
||||
@@ -1155,8 +1167,9 @@ its authored sides and fractions. Frozen schema-1/schema-2 readers do not accept
|
||||
``port_anchors``; their explicit migration supplies an empty list.
|
||||
|
||||
Each ``routes`` entry is an EdgeRoute record with a required ``edge`` reference
|
||||
to an existing Relation or Trace, ``waypoints`` (default ``[]``), and ``label``
|
||||
(default ``none``). Route records have no separate UUID or alias. An edge occurs
|
||||
to an existing Relation or Trace, ``waypoints`` (default ``[]``), ``label``
|
||||
(default ``none``), and ``source_attachment`` / ``target_attachment`` (each
|
||||
default ``none``). Route records have no separate UUID or alias. An edge occurs
|
||||
at most once in a diagram's route list; different diagrams MAY store independent
|
||||
routes for the same edge. List order and explicit empty entries are retained by
|
||||
source and JSON round trips, although list order has no routing meaning. Edges
|
||||
@@ -1166,6 +1179,7 @@ need not currently be visible in their diagram.
|
||||
|
||||
routes [
|
||||
{ edge @report_exchange;
|
||||
source_attachment { side Bottom; offset 0.25; };
|
||||
waypoints [{ x 420; y 260; }, { x 690; y 260; }];
|
||||
label { fraction 0.55; offset { x 0; y -16; }; };
|
||||
}
|
||||
@@ -1184,6 +1198,51 @@ geometric routing difficulty is reported separately from structural validity.
|
||||
Each EdgeRoute counts as one record against ``ParseLimits.max_records``; pinned
|
||||
points are bounded by the per-route limit and aggregate input byte limits.
|
||||
|
||||
An attachment is an EdgeAttachment record with required ``side`` (Left, Right,
|
||||
Top, Bottom) and required finite binary32 ``offset`` from zero through one.
|
||||
Unknown fields, omitted nested fields and out-of-range offsets are structural
|
||||
errors (``invalid_attachment_offset`` for the latter). Attachments are bounded
|
||||
inline values, at most two per route, not additional graph objects or records.
|
||||
JSON uses the same field names, enum strings and number values. Omitted or null
|
||||
attachments mean automatic positioning; canonical compact source and JSON omit
|
||||
absent attachments. Earlier schema-3 input hydrates both fields as absent.
|
||||
|
||||
The end names designate stored source/target slots, even for undirected edges.
|
||||
These values MUST NOT change semantic endpoints, ports, ownership, type,
|
||||
orientation or identity. Each preference belongs to that edge end in that view:
|
||||
another view remains independent. It follows the current endpoint's projected
|
||||
boundary under movement, resize or semantic reconnect; reconnect preserves the
|
||||
preference, as it preserves authored bends. The fraction does not identify the
|
||||
previous semantic endpoint. Deletion/reidentification of the edge follows the
|
||||
existing whole-route rules; moving, hiding or replacing its placement retains
|
||||
the preference. Removing one attachment restores that end's automatic position
|
||||
without changing bends, labels or the opposite attachment.
|
||||
|
||||
For Left/Right, offset gives the Y fraction of the complete projected bounding
|
||||
box; for Top/Bottom it gives the X fraction. The attachment intersects the painted
|
||||
shape along that cardinal scan line. Rounded cards use radius 10, limited by half
|
||||
their width/height; Regions and fork/join bars are rectangles. State circles use
|
||||
their ellipse boundary and Choice uses its diamond boundary. More precisely, let
|
||||
``t = 2 * offset - 1`` and ``D`` be width for Left/Right or height for Top/Bottom.
|
||||
The inset from the selected bounding side is ``D/2 * (1 - sqrt(1-t*t))`` for an
|
||||
ellipse and ``D/2 * abs(t)`` for a diamond. A Terminate X uses the outermost
|
||||
painted-stroke intersection, inset ``D * min(offset, 1-offset)``. Zero and one
|
||||
are valid; different side/fraction pairs can describe the same painted point.
|
||||
Routing leads extend in the selected cardinal direction beyond the bounding box
|
||||
before turning. Source/API fractions retain their precision; pointer editing
|
||||
snaps fractions to hundredths without changing the stored semantic record.
|
||||
|
||||
An actual semantic Port remains authoritative, including when projection hides
|
||||
its port marker. An edge attachment on that end is retained but dormant; use
|
||||
the port's own placement anchor to move a port. When folding promotes an endpoint
|
||||
to an ancestor, all authored route data is suspended and resumes on expansion.
|
||||
Geometric difficulty MUST NOT discard preferences. Coincident authored self-loop
|
||||
tips retain their positions with an external loop and a routing warning; the
|
||||
editor must offer an explicit way to choose either end even when handles overlap.
|
||||
Internal state transitions have no external connection. Process's generated
|
||||
topology and Scenario's lifeline/activation/time-derived tips are not consumers
|
||||
of these diagram route fields; this feature does not redefine their semantics.
|
||||
|
||||
``SetEdgeRoute { diagram, route }`` upserts an entry by edge identity, retaining
|
||||
the order and contents of unrelated entries. ``RemoveEdgeRoute { diagram, edge }``
|
||||
removes it; removing an absent entry is a no-op for an existing diagram and edge.
|
||||
@@ -1840,11 +1899,30 @@ Map order is irrelevant. The writer preserves signed coordinate zero and
|
||||
emits decimals that recover the original binary32 value.
|
||||
|
||||
Canonical output uses LF, four-space indentation, explicit identities,
|
||||
defaults, and JSON-escaped strings. Elements are emitted in UUID order, then
|
||||
and JSON-escaped strings. It omits fields equal to the omission defaults of
|
||||
their actual declaration or selected constructor, as specified in the field
|
||||
tables. This includes an empty project description. It MUST NOT omit a required
|
||||
field merely because its value is zero, false, empty, or ``none``. Elements are emitted in UUID order, then
|
||||
relations; diagrams and their nodes follow, then artifacts, then traces.
|
||||
Fields use deterministic name order. Output ends with LF. Alias values come
|
||||
from the model, never from regenerating display names.
|
||||
|
||||
Omission is context-sensitive: Scenario uses the source default MixedLegacy;
|
||||
BoundaryExchange and CommunicationMean have different orientation defaults;
|
||||
state declarations determine their state-kind discriminator. A nonempty or
|
||||
whitespace-only description remains exact. Present-empty optional strings or
|
||||
collections, unbounded multiplicity versus a finite default, selected operation
|
||||
intent, and negative coordinate zero remain distinct values. A nondefault
|
||||
geometry record retains all required coordinates or dimensions.
|
||||
|
||||
Only specified optional fields inside selected constructors may be omitted.
|
||||
For example, Integer bounds and LegacyPortContract.interface may be absent;
|
||||
String.minimum_length, Signal.items, port-contract payload lists, and historical
|
||||
snapshot name/description fields remain required. A LegacyPortContract record
|
||||
still requires direction. Historical semantic baseline payloads are retained
|
||||
without generic empty/default pruning. Compact output MUST preserve every
|
||||
persistent model field after parsing, including these distinctions.
|
||||
|
||||
Comments and input whitespace are lexical trivia to the canonical writer.
|
||||
Canonical export does not preserve them. The source-project editor and compiler
|
||||
preserve authored comments and whitespace on Apply while inserting missing
|
||||
@@ -1890,11 +1968,19 @@ adjusts to the destination scope; other token spelling remains authored.
|
||||
|
||||
Updates MUST NOT canonicalize surviving declarations in full. Header, field and
|
||||
nested value positions are derived from the existing syntax parser. Unchanged
|
||||
fields retain their exact bytes, including field order, omitted defaults, number
|
||||
fields retain their exact bytes, including field order, explicit and omitted defaults, number
|
||||
and string spelling, comments, indentation and line endings. Changed literals and
|
||||
references replace only the required tokens; a reference with comments between
|
||||
``@`` and its alias retains those comments. A previously omitted default is
|
||||
inserted only if its semantic value changes. New fields use the existing record's
|
||||
``@`` and its alias retains those comments. A previously omitted field is
|
||||
inserted only when needed to express the requested value in its new declaration
|
||||
context. This includes an unchanged value whose omission default changes with
|
||||
the declaration kind. For example, changing BoundaryExchange to CommunicationMean
|
||||
while retaining orientation true requires ``oriented true;`` if previously
|
||||
implicit. Unchanged explicit defaults MUST survive unrelated sibling edits,
|
||||
including persistence-serializer omissions such as ``operation none``,
|
||||
``port_anchors []`` and ``baseline.semantic none``. New fields and value fragments
|
||||
use compact generation while retaining required selected-constructor payloads.
|
||||
New fields use the existing record's
|
||||
indentation and line-ending style without reformatting its other fields.
|
||||
|
||||
A constructor tag change retains shared nested fields in place. Removed fields,
|
||||
@@ -2173,7 +2259,7 @@ Text edits describe a complete candidate and must remove or repair dependencies
|
||||
explicitly before Apply succeeds.
|
||||
|
||||
8.1. Focused diagram removal
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Delete is scoped to the focused diagram and the exact visible selection.
|
||||
Text fields retain their own Delete behavior; diagram shortcuts MUST NOT apply
|
||||
@@ -2294,8 +2380,9 @@ This compatibility applies equally to source and JSON. It adds explicit
|
||||
defaults without changing any prior identity, name, reference, order, geometry,
|
||||
artifact or trace field. The original V2 golden source/JSON in
|
||||
``crates/oa-core/tests/fixtures`` MUST NOT be regenerated from the newer demo;
|
||||
they verify that every old persistent field survives. Canonical output writes
|
||||
the added defaults through explicit migration to the current schema 7.
|
||||
they verify that every old persistent field survives. Canonical output uses
|
||||
the current schema 7 and omits values equal to its specified source defaults;
|
||||
parsing recovers the complete migrated model.
|
||||
|
||||
The V2 adapter preserves every original identity, alias, prose, parent,
|
||||
placement, trace and artifact. Generic ports become Legacy with their original
|
||||
|
||||
+45
-1
@@ -2137,15 +2137,59 @@
|
||||
],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"EdgeAttachment": {
|
||||
"type": "object",
|
||||
"description": "Per-view preference on one stored connection end, not a semantic endpoint. Offset is finite and measured along the complete projected bounding-box side. Real semantic ports take precedence; hidden/promoted geometry retains the preference. Reconnect preserves the preference on its source/target slot.",
|
||||
"properties": {
|
||||
"side": {
|
||||
"$ref": "#/components/schemas/PortAnchorSide"
|
||||
},
|
||||
"offset": {
|
||||
"type": "number",
|
||||
"minimum": 0,
|
||||
"maximum": 1,
|
||||
"description": "Left/Right: top-to-bottom fraction. Top/Bottom: left-to-right fraction. Shape-aware geometry derives the actual contour point."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"side",
|
||||
"offset"
|
||||
],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"EdgeRoute": {
|
||||
"type": "object",
|
||||
"description": "One diagram's authored route for an existing Relation or Trace, including currently hidden edges. No separate identity. Only pinned points are stored; explicit empty routes are retained.",
|
||||
"description": "One diagram's authored presentation for an existing Relation or Trace, including currently hidden edges. No separate identity. Stores optional endpoint preferences, pinned points and label placement; explicit empty routes are retained. Removing the route resets all authored presentation.",
|
||||
"properties": {
|
||||
"edge": {
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"description": "Existing Relation or Trace identity, never a node placement."
|
||||
},
|
||||
"source_attachment": {
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/EdgeAttachment"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
],
|
||||
"default": null,
|
||||
"description": "Absent or null means automatic. Omitted when serializing automatic presentation. Resetting this field preserves the other end, pins and label."
|
||||
},
|
||||
"target_attachment": {
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/EdgeAttachment"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
],
|
||||
"default": null,
|
||||
"description": "Absent or null means automatic. Omitted when serializing automatic presentation. Resetting this field preserves the other end, pins and label."
|
||||
},
|
||||
"waypoints": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
|
||||
@@ -1,43 +1,34 @@
|
||||
oa_activity oa_restore_work "Restore safe pressure" id "1b91f8a7-0bdb-514e-b1cd-955658e09927" {
|
||||
description "";
|
||||
parent none;
|
||||
}
|
||||
|
||||
oa_activity oa_assess "Assess pressure alarm" id "61f7bbfb-74a4-5540-9182-2583dfb27a49" {
|
||||
description "";
|
||||
parent @oa_restore_work;
|
||||
}
|
||||
|
||||
oa_activity oa_confirm "Confirm safe pressure" id "727c0b5c-8db6-5eb7-83d6-735519c5949f" {
|
||||
description "";
|
||||
parent @oa_restore_work;
|
||||
}
|
||||
|
||||
oa_activity oa_repair "Repair valve in the field" id "a21465af-05f3-5fb5-8983-de26932422fb" {
|
||||
description "";
|
||||
parent @oa_restore_work;
|
||||
}
|
||||
|
||||
oa_activity oa_reset "Reset valve remotely" id "d0c8be87-d238-503a-a549-7558a210507f" {
|
||||
description "";
|
||||
parent @oa_restore_work;
|
||||
}
|
||||
|
||||
capability_involvement oa_assessment_support "Capability involvement: Assess an alarm" id "ffdbfcd0-d423-5707-a880-0dfbe1400f72" {
|
||||
description "";
|
||||
source @oa_assess;
|
||||
target @oa_triage;
|
||||
}
|
||||
|
||||
interaction oa_repair_request "Request field repair" id "cf423ea2-8b2e-5a27-93d4-5e8542d9db8d" {
|
||||
description "";
|
||||
items [@oa_repair_operation];
|
||||
source @oa_assess;
|
||||
target @oa_repair;
|
||||
}
|
||||
|
||||
interaction oa_repair_report "Report repair result" id "b436d0b3-c824-5a96-af6b-2c269816d1cc" {
|
||||
description "";
|
||||
items [@oa_repair_operation];
|
||||
source @oa_repair;
|
||||
target @oa_confirm;
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
oa_process oa_assessment_procedure "Assess an alarm procedure" id "022d3cfa-bbaf-5e13-924a-8e55099b8745" {
|
||||
description "";
|
||||
parent none;
|
||||
steps [@oa_assessment_action];
|
||||
}
|
||||
|
||||
@@ -8,17 +6,12 @@ oa_occurrence oa_assessment_action "Assess pressure alarm" id "942975b8-0bef-5ae
|
||||
body {
|
||||
Action {
|
||||
action @oa_assess;
|
||||
lifeline none;
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent @oa_assessment_procedure;
|
||||
postcondition "";
|
||||
precondition "";
|
||||
}
|
||||
|
||||
chain_involvement oa_assessment_delivery "Chain involvement: Assess an alarm" id "628cb4fc-fe63-5f6b-b364-6268f26b5740" {
|
||||
description "";
|
||||
source @oa_assessment_procedure;
|
||||
target @oa_triage;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
oa_process oa_field_procedure "Field repair procedure" id "5d3af417-244c-54bb-9588-16daedda4e1f" {
|
||||
description "";
|
||||
parent none;
|
||||
steps [@oa_request_step, @oa_repair_step, @oa_report_step];
|
||||
}
|
||||
|
||||
@@ -8,59 +6,35 @@ oa_occurrence oa_repair_step "Repair the valve" id "c59432fe-6092-5ee0-908d-9dbf
|
||||
body {
|
||||
Action {
|
||||
action @oa_repair;
|
||||
lifeline none;
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent @oa_field_procedure;
|
||||
postcondition "";
|
||||
precondition "";
|
||||
}
|
||||
|
||||
oa_occurrence oa_report_step "Report the measured result" id "df2fd3f8-6bc2-5380-a13f-36643ed35ac7" {
|
||||
body {
|
||||
Exchange {
|
||||
exchange @oa_repair_report;
|
||||
message_kind Asynchronous;
|
||||
receiver none;
|
||||
reply_to none;
|
||||
sender none;
|
||||
values [];
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent @oa_field_procedure;
|
||||
postcondition "";
|
||||
precondition "";
|
||||
}
|
||||
|
||||
oa_occurrence oa_request_step "Request the field repair" id "5ba8079c-2dbe-5e98-ae82-2b60c6020a02" {
|
||||
body {
|
||||
Exchange {
|
||||
exchange @oa_repair_request;
|
||||
message_kind Asynchronous;
|
||||
receiver none;
|
||||
reply_to none;
|
||||
sender none;
|
||||
values [];
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent @oa_field_procedure;
|
||||
postcondition "";
|
||||
precondition "";
|
||||
}
|
||||
|
||||
sequence_link oa_repair_then_report "Sequence link: Report the measured result" id "c8196d35-2168-5fef-8b03-ba0d139bc00f" {
|
||||
description "";
|
||||
guard "";
|
||||
source @oa_repair_step;
|
||||
target @oa_report_step;
|
||||
}
|
||||
|
||||
sequence_link oa_request_then_repair "Sequence link: Repair the valve" id "3f54d890-4ca5-5e36-873b-abb5c92d578c" {
|
||||
description "";
|
||||
guard "";
|
||||
source @oa_request_step;
|
||||
target @oa_repair_step;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
oa_process oa_response "Handle a pressure alarm" id "58bae2b0-f560-50f2-818d-19091d22d18a" {
|
||||
description "";
|
||||
parent none;
|
||||
steps [@oa_assess_step, @oa_decision, @oa_reset_step, @oa_use_field, @oa_merge, @oa_confirm_step];
|
||||
}
|
||||
|
||||
@@ -10,23 +8,16 @@ oa_occurrence oa_assess_step "Assess the alarm" id "0b07b9ed-492d-57f6-b0b1-ce8a
|
||||
sequence @oa_assessment_procedure;
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent @oa_response;
|
||||
postcondition "";
|
||||
precondition "";
|
||||
}
|
||||
|
||||
oa_occurrence oa_confirm_step "Confirm safe pressure" id "e00594a3-6122-5a6b-b3c2-ecb5506c741d" {
|
||||
body {
|
||||
Action {
|
||||
action @oa_confirm;
|
||||
lifeline none;
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent @oa_response;
|
||||
postcondition "";
|
||||
precondition "";
|
||||
}
|
||||
|
||||
oa_occurrence oa_decision "Can a remote reset safely recover pressure?" id "b280c6ca-e5f9-5424-a5c1-5676e01c2371" {
|
||||
@@ -35,10 +26,7 @@ oa_occurrence oa_decision "Can a remote reset safely recover pressure?" id "b280
|
||||
kind Choice;
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent @oa_response;
|
||||
postcondition "";
|
||||
precondition "";
|
||||
}
|
||||
|
||||
oa_occurrence oa_merge "Recovery path completed" id "6b945a6d-6aa0-5dd3-96e6-2e8d757d167d" {
|
||||
@@ -47,23 +35,16 @@ oa_occurrence oa_merge "Recovery path completed" id "6b945a6d-6aa0-5dd3-96e6-2e8
|
||||
kind Merge;
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent @oa_response;
|
||||
postcondition "";
|
||||
precondition "";
|
||||
}
|
||||
|
||||
oa_occurrence oa_reset_step "Try the authorized remote reset" id "d2026fc2-74a8-5e22-9942-ff3eb68a3677" {
|
||||
body {
|
||||
Action {
|
||||
action @oa_reset;
|
||||
lifeline none;
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent @oa_response;
|
||||
postcondition "";
|
||||
precondition "";
|
||||
}
|
||||
|
||||
oa_occurrence oa_use_field "Use the field repair procedure" id "fc6763bf-a534-54bf-afcd-57ab285ff07d" {
|
||||
@@ -72,56 +53,42 @@ oa_occurrence oa_use_field "Use the field repair procedure" id "fc6763bf-a534-54
|
||||
sequence @oa_field_procedure;
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent @oa_response;
|
||||
postcondition "";
|
||||
precondition "";
|
||||
}
|
||||
|
||||
sequence_link oa_assess_then_decide "Continue" id "109e2d6b-7e86-5934-93a5-fab56eced84e" {
|
||||
description "";
|
||||
guard "";
|
||||
source @oa_assess_step;
|
||||
target @oa_decision;
|
||||
}
|
||||
|
||||
sequence_link oa_field_path "else" id "c1adbbd0-a762-5ee3-8b9a-5c18af377771" {
|
||||
description "";
|
||||
guard "else";
|
||||
source @oa_decision;
|
||||
target @oa_use_field;
|
||||
}
|
||||
|
||||
sequence_link oa_remote_path "remote reset is authorized" id "76218d89-68fd-531d-b35b-90c5b769a5ef" {
|
||||
description "";
|
||||
guard "remote reset is authorized";
|
||||
source @oa_decision;
|
||||
target @oa_reset_step;
|
||||
}
|
||||
|
||||
sequence_link oa_confirm_path "Continue" id "229ee94f-d147-50f6-9769-b5bd0c03a084" {
|
||||
description "";
|
||||
guard "";
|
||||
source @oa_merge;
|
||||
target @oa_confirm_step;
|
||||
}
|
||||
|
||||
sequence_link oa_remote_merge "Continue" id "bac43d3b-910b-5bdc-be9b-f78cf973e1ed" {
|
||||
description "";
|
||||
guard "";
|
||||
source @oa_reset_step;
|
||||
target @oa_merge;
|
||||
}
|
||||
|
||||
chain_involvement oa_response_delivery "Chain involvement: Restore a safe supply" id "c7c248f8-28b8-55be-9023-0991d44021e3" {
|
||||
description "";
|
||||
source @oa_response;
|
||||
target @oa_restore;
|
||||
}
|
||||
|
||||
sequence_link oa_field_merge "Continue" id "c8593670-8906-530f-b6a2-3ada77a9c219" {
|
||||
description "";
|
||||
guard "";
|
||||
source @oa_use_field;
|
||||
target @oa_merge;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
oa_scenario oa_conversation "Repair request and measured reply" id "20472233-5ce6-5ffe-b4ad-0bdbccf3e423" {
|
||||
context @oa_restore;
|
||||
description "";
|
||||
parent none;
|
||||
postcondition "The controller has received the measured pressure after repair";
|
||||
precondition "A pressure alarm has been assessed";
|
||||
steps [@oa_call, @oa_reply];
|
||||
@@ -14,23 +12,17 @@ oa_occurrence oa_call "Request valve repair" id "b97437c6-cd7a-5a05-b537-b30a17d
|
||||
exchange @oa_contact;
|
||||
message_kind Call;
|
||||
receiver @oa_responder;
|
||||
reply_to none;
|
||||
sender @oa_caller;
|
||||
values [{
|
||||
expression "420.0";
|
||||
field @oa_pressure_parameter;
|
||||
path [];
|
||||
}];
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent @oa_conversation;
|
||||
postcondition "";
|
||||
precondition "";
|
||||
}
|
||||
|
||||
oa_lifeline oa_caller "Controller" id "41859a65-ded2-547b-ab03-14e2fa740cf9" {
|
||||
description "";
|
||||
parent @oa_conversation;
|
||||
represented @oa_control;
|
||||
}
|
||||
@@ -46,18 +38,13 @@ oa_occurrence oa_reply "Return pressure after repair" id "cc2d497a-fd15-5455-9ee
|
||||
values [{
|
||||
expression "320.0";
|
||||
field @oa_pressure_parameter;
|
||||
path [];
|
||||
}];
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent @oa_conversation;
|
||||
postcondition "";
|
||||
precondition "";
|
||||
}
|
||||
|
||||
oa_lifeline oa_responder "Technician" id "fc81c5f0-0442-5b88-992b-e5b10f351c59" {
|
||||
description "";
|
||||
parent @oa_conversation;
|
||||
represented @oa_technician;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
oa_scenario oa_full_scenario "Restore supply through field repair" id "d6f881a4-95da-54e9-ad97-1b8965532629" {
|
||||
context @oa_restore;
|
||||
description "";
|
||||
parent none;
|
||||
postcondition "The controller has received the measured pressure after repair";
|
||||
precondition "A pressure alarm has been assessed";
|
||||
steps [@oa_use_conversation];
|
||||
@@ -9,13 +7,11 @@ oa_scenario oa_full_scenario "Restore supply through field repair" id "d6f881a4-
|
||||
}
|
||||
|
||||
oa_lifeline oa_outer_controller "Controller" id "2011b3ac-614b-5a47-8891-7ff81965f425" {
|
||||
description "";
|
||||
parent @oa_full_scenario;
|
||||
represented @oa_control;
|
||||
}
|
||||
|
||||
oa_lifeline oa_outer_technician "Technician" id "fffff882-78fd-5415-928d-c1ef7fac6576" {
|
||||
description "";
|
||||
parent @oa_full_scenario;
|
||||
represented @oa_technician;
|
||||
}
|
||||
@@ -33,9 +29,6 @@ oa_occurrence oa_use_conversation "Use the reviewed repair conversation" id "9ff
|
||||
scenario @oa_conversation;
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent @oa_full_scenario;
|
||||
postcondition "";
|
||||
precondition "";
|
||||
}
|
||||
|
||||
|
||||
@@ -1,80 +1,43 @@
|
||||
oa_state_machine oa_monitor "Pressure supervision" id "1970608f-85d1-5234-ac86-5e2b0df27dc3" {
|
||||
description "";
|
||||
parent @oa_control;
|
||||
}
|
||||
|
||||
oa_region oa_monitor_region "Supervision cycle" id "8412e9c6-96fe-5ed6-a903-1d37ec3c3bf7" {
|
||||
description "";
|
||||
parent @oa_monitor;
|
||||
}
|
||||
|
||||
oa_initial oa_monitor_initial "Start" id "a7ffb869-9dde-5e76-b276-c719c5c143a9" {
|
||||
description "";
|
||||
do_activity "";
|
||||
entry "";
|
||||
exit "";
|
||||
kind Initial;
|
||||
parent @oa_monitor_region;
|
||||
}
|
||||
|
||||
oa_state oa_monitoring "Monitoring" id "6cbde0d8-9f5f-510a-a8c1-e29cb99ad4ae" {
|
||||
description "";
|
||||
do_activity "";
|
||||
entry "";
|
||||
exit "";
|
||||
kind State;
|
||||
parent @oa_monitor_region;
|
||||
}
|
||||
|
||||
oa_state oa_waiting "Awaiting repair" id "58c15833-6e75-523a-b57f-a88f19f6d672" {
|
||||
description "";
|
||||
do_activity "";
|
||||
entry "";
|
||||
exit "";
|
||||
kind State;
|
||||
parent @oa_monitor_region;
|
||||
}
|
||||
|
||||
state_transition oa_start_monitoring "State transition: Monitoring" id "2b00270c-79a5-52a5-af96-33346bea531b" {
|
||||
description "";
|
||||
effect "";
|
||||
effects [];
|
||||
guard "";
|
||||
source @oa_monitor_initial;
|
||||
target @oa_monitoring;
|
||||
transition_kind External;
|
||||
trigger "";
|
||||
triggers [];
|
||||
}
|
||||
|
||||
state_transition oa_alarm_transition "State transition: Awaiting repair" id "fbde9d5e-c7e9-55db-a2be-497345c491b3" {
|
||||
description "";
|
||||
effect "";
|
||||
effects [];
|
||||
guard "";
|
||||
source @oa_monitoring;
|
||||
target @oa_waiting;
|
||||
transition_kind External;
|
||||
trigger "";
|
||||
triggers [@oa_high_pressure];
|
||||
}
|
||||
|
||||
state_action oa_assess_on_entry "Assess when repair is needed" id "7fa37e63-db65-5aa7-88f2-31ff4347a787" {
|
||||
description "";
|
||||
phase Entry;
|
||||
source @oa_waiting;
|
||||
target @oa_assess;
|
||||
}
|
||||
|
||||
state_transition oa_normal_transition "State transition: Monitoring" id "21fe5e8e-cbc2-5dad-b3e8-1df46e167d97" {
|
||||
description "";
|
||||
effect "";
|
||||
effects [];
|
||||
guard "repair confirmed and pressure is safe";
|
||||
source @oa_waiting;
|
||||
target @oa_monitoring;
|
||||
transition_kind External;
|
||||
trigger "";
|
||||
triggers [];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,26 +1,18 @@
|
||||
oa_mission oa_mission "Maintain safe water supply" id "c9c61f50-06e0-5d17-973d-dcc57cd5cc90" {
|
||||
description "";
|
||||
parent none;
|
||||
}
|
||||
|
||||
oa_capability oa_restore "Restore a safe supply" id "3dfee23a-148b-5cec-ad2d-b774e84ea5bb" {
|
||||
description "";
|
||||
parent none;
|
||||
}
|
||||
|
||||
oa_capability oa_triage "Assess an alarm" id "6a30b763-cc51-546d-907f-5c63657cfd03" {
|
||||
description "";
|
||||
parent none;
|
||||
}
|
||||
|
||||
mission_capability oa_mission_delivery "Mission capability: Restore a safe supply" id "1f8b1898-65f6-5360-99cf-b78a71bd50ec" {
|
||||
description "";
|
||||
source @oa_mission;
|
||||
target @oa_restore;
|
||||
}
|
||||
|
||||
capability_include oa_include_triage "Capability include: Assess an alarm" id "e21d9a54-ae8e-5618-a4f8-67ee22b92638" {
|
||||
description "";
|
||||
source @oa_restore;
|
||||
target @oa_triage;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
oa_exchange_category oa_contact_category "Field contact" id "19bd3a3a-4d0c-56d5-bf50-a6b43fd81771" {
|
||||
description "";
|
||||
exchanges [@oa_contact];
|
||||
family "Participant";
|
||||
parent none;
|
||||
}
|
||||
|
||||
oa_event oa_high_pressure "Pressure alarm detected" id "65d6b8d6-271a-5c84-8b42-abbe310c955e" {
|
||||
@@ -11,14 +9,9 @@ oa_event oa_high_pressure "Pressure alarm detected" id "65d6b8d6-271a-5c84-8b42-
|
||||
expression "measured_pressure > operating_limit";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent none;
|
||||
}
|
||||
|
||||
oa_exchange_category oa_repair_traffic "Repair work exchanges" id "9349b353-53f2-56f8-b571-a05b09335cdf" {
|
||||
description "";
|
||||
exchanges [@oa_repair_request, @oa_repair_report];
|
||||
family "Work";
|
||||
parent none;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,59 +1,46 @@
|
||||
oa_entity oa_control "Control room" id "32aa9940-df6e-5a12-b9bd-6337e2d2ed22" {
|
||||
description "";
|
||||
parent none;
|
||||
}
|
||||
|
||||
oa_actor oa_technician "Field technician" id "e07c3952-4a1a-5cc7-b7d5-03a01101ce49" {
|
||||
description "";
|
||||
parent none;
|
||||
}
|
||||
|
||||
allocation oa_assess_allocation "Allocation: Assess pressure alarm" id "594c61cd-94e0-5c07-890d-edfd520d7df9" {
|
||||
description "";
|
||||
source @oa_control;
|
||||
target @oa_assess;
|
||||
}
|
||||
|
||||
allocation oa_confirm_allocation "Allocation: Confirm safe pressure" id "bfd4326e-ea65-5269-b5e6-e063a355d1e9" {
|
||||
description "";
|
||||
source @oa_control;
|
||||
target @oa_confirm;
|
||||
}
|
||||
|
||||
communication_mean oa_contact "Technician service conversation" id "27b47887-baf0-518b-bf87-f5acbf7d0b93" {
|
||||
description "";
|
||||
items [@oa_repair_operation];
|
||||
oriented false;
|
||||
source @oa_control;
|
||||
target @oa_technician;
|
||||
}
|
||||
|
||||
exchange_allocation oa_report_carriage "Exchange allocation: Report repair result" id "4549d3fa-5ab9-52a9-b4f9-3a78fc9d625a" {
|
||||
description "";
|
||||
source @oa_contact;
|
||||
target @oa_repair_report;
|
||||
}
|
||||
|
||||
exchange_allocation oa_request_carriage "Exchange allocation: Request field repair" id "094b888c-450c-5c4f-971a-7d75db059574" {
|
||||
description "";
|
||||
source @oa_contact;
|
||||
target @oa_repair_request;
|
||||
}
|
||||
|
||||
mission_involvement oa_mission_participant "Mission involvement: Maintain safe water supply" id "0c4c9e58-ff32-5c00-b82a-d408a4be0183" {
|
||||
description "";
|
||||
source @oa_control;
|
||||
target @oa_mission;
|
||||
}
|
||||
|
||||
allocation oa_reset_allocation "Allocation: Reset valve remotely" id "1853df1f-30f4-5b1a-baac-2dcaf73c7b3a" {
|
||||
description "";
|
||||
source @oa_control;
|
||||
target @oa_reset;
|
||||
}
|
||||
|
||||
allocation oa_repair_allocation "Allocation: Repair valve in the field" id "ae53f363-0dec-5a7c-9afd-8fcd1b778ab2" {
|
||||
description "";
|
||||
source @oa_technician;
|
||||
target @oa_repair;
|
||||
}
|
||||
|
||||
@@ -1,35 +1,22 @@
|
||||
oa_data_type oa_pressure "Measured pressure" id "e7824764-5db9-5384-8198-2fbaea2b10b2" {
|
||||
default none;
|
||||
definition {
|
||||
Real {
|
||||
maximum 600.0;
|
||||
minimum 0.0;
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent none;
|
||||
unit "kPa";
|
||||
}
|
||||
|
||||
oa_exchange_item oa_repair_operation "Valve repair" id "d736c7d6-d369-550a-8ba4-dae223e40bb3" {
|
||||
description "";
|
||||
kind Information;
|
||||
mechanism Operation;
|
||||
parent none;
|
||||
supertype none;
|
||||
}
|
||||
|
||||
oa_data_field oa_pressure_parameter "Pressure before / after repair" id "8bc6d0a4-3e87-559b-8bd7-1b679a2db5b7" {
|
||||
default none;
|
||||
description "";
|
||||
direction InOut;
|
||||
maximum 1;
|
||||
minimum 1;
|
||||
parent @oa_repair_operation;
|
||||
storage Value;
|
||||
type_ref {
|
||||
Named @oa_pressure;
|
||||
};
|
||||
unit "";
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
sa_functional_chain sa_assessment_procedure "Assess an alarm procedure" id "acd5a018-f559-5298-a40d-1cf6e1353e74" {
|
||||
description "";
|
||||
parent none;
|
||||
steps [@sa_assessment_action];
|
||||
}
|
||||
|
||||
@@ -8,17 +6,12 @@ sa_occurrence sa_assessment_action "Assess pressure alarm" id "bae5b192-5b8e-51c
|
||||
body {
|
||||
Action {
|
||||
action @sa_assess;
|
||||
lifeline none;
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent @sa_assessment_procedure;
|
||||
postcondition "";
|
||||
precondition "";
|
||||
}
|
||||
|
||||
chain_involvement sa_assessment_delivery "Chain involvement: Assess an alarm" id "a6d5a6be-fa6e-5fa0-a309-08e87ba40c57" {
|
||||
description "";
|
||||
source @sa_assessment_procedure;
|
||||
target @sa_triage;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
sa_functional_chain sa_field_procedure "Field repair procedure" id "93eb6479-54e9-59cb-ac7b-16912347bfc0" {
|
||||
description "";
|
||||
parent none;
|
||||
steps [@sa_request_step, @sa_repair_step, @sa_report_step];
|
||||
}
|
||||
|
||||
@@ -8,59 +6,35 @@ sa_occurrence sa_repair_step "Repair the valve" id "0f195fea-3493-5ebd-966d-da9e
|
||||
body {
|
||||
Action {
|
||||
action @sa_repair;
|
||||
lifeline none;
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent @sa_field_procedure;
|
||||
postcondition "";
|
||||
precondition "";
|
||||
}
|
||||
|
||||
sa_occurrence sa_report_step "Report the measured result" id "ea32e4ec-8bdc-57ea-8a90-7b09ba4f0eac" {
|
||||
body {
|
||||
Exchange {
|
||||
exchange @sa_repair_report;
|
||||
message_kind Asynchronous;
|
||||
receiver none;
|
||||
reply_to none;
|
||||
sender none;
|
||||
values [];
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent @sa_field_procedure;
|
||||
postcondition "";
|
||||
precondition "";
|
||||
}
|
||||
|
||||
sa_occurrence sa_request_step "Request the field repair" id "40d94322-baa2-5c81-b261-ff47cdc33782" {
|
||||
body {
|
||||
Exchange {
|
||||
exchange @sa_repair_request;
|
||||
message_kind Asynchronous;
|
||||
receiver none;
|
||||
reply_to none;
|
||||
sender none;
|
||||
values [];
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent @sa_field_procedure;
|
||||
postcondition "";
|
||||
precondition "";
|
||||
}
|
||||
|
||||
sequence_link sa_repair_then_report "Sequence link: Report the measured result" id "7fb30b1d-195c-5f0e-a19c-a536f519a899" {
|
||||
description "";
|
||||
guard "";
|
||||
source @sa_repair_step;
|
||||
target @sa_report_step;
|
||||
}
|
||||
|
||||
sequence_link sa_request_then_repair "Sequence link: Repair the valve" id "6a6d968f-26d6-5dbb-b721-5a27d362779a" {
|
||||
description "";
|
||||
guard "";
|
||||
source @sa_request_step;
|
||||
target @sa_repair_step;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
sa_functional_chain sa_response "Handle a pressure alarm" id "5139ce73-56fd-5875-ba3a-e569fc890231" {
|
||||
description "";
|
||||
parent none;
|
||||
steps [@sa_assess_step, @sa_decision, @sa_reset_step, @sa_use_field, @sa_merge, @sa_confirm_step];
|
||||
}
|
||||
|
||||
@@ -10,23 +8,16 @@ sa_occurrence sa_assess_step "Assess the alarm" id "9024243c-ccc1-5edb-8477-2aa1
|
||||
sequence @sa_assessment_procedure;
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent @sa_response;
|
||||
postcondition "";
|
||||
precondition "";
|
||||
}
|
||||
|
||||
sa_occurrence sa_confirm_step "Confirm safe pressure" id "47bec4f9-d6d0-5ed1-adca-fa0d960dc416" {
|
||||
body {
|
||||
Action {
|
||||
action @sa_confirm;
|
||||
lifeline none;
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent @sa_response;
|
||||
postcondition "";
|
||||
precondition "";
|
||||
}
|
||||
|
||||
sa_occurrence sa_decision "Can a remote reset safely recover pressure?" id "30c8fad9-a49b-5692-9542-3148e76afd7b" {
|
||||
@@ -35,10 +26,7 @@ sa_occurrence sa_decision "Can a remote reset safely recover pressure?" id "30c8
|
||||
kind Choice;
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent @sa_response;
|
||||
postcondition "";
|
||||
precondition "";
|
||||
}
|
||||
|
||||
sa_occurrence sa_merge "Recovery path completed" id "4ed0dd9d-c9e0-5652-aedf-5f0ab4328a07" {
|
||||
@@ -47,23 +35,16 @@ sa_occurrence sa_merge "Recovery path completed" id "4ed0dd9d-c9e0-5652-aedf-5f0
|
||||
kind Merge;
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent @sa_response;
|
||||
postcondition "";
|
||||
precondition "";
|
||||
}
|
||||
|
||||
sa_occurrence sa_reset_step "Try the authorized remote reset" id "bfa2ef0b-ce68-55c2-a9e5-31ea8a74fce6" {
|
||||
body {
|
||||
Action {
|
||||
action @sa_reset;
|
||||
lifeline none;
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent @sa_response;
|
||||
postcondition "";
|
||||
precondition "";
|
||||
}
|
||||
|
||||
sa_occurrence sa_use_field "Use the field repair procedure" id "d5e61c5d-510b-5091-a878-da46f3a9e152" {
|
||||
@@ -72,56 +53,42 @@ sa_occurrence sa_use_field "Use the field repair procedure" id "d5e61c5d-510b-50
|
||||
sequence @sa_field_procedure;
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent @sa_response;
|
||||
postcondition "";
|
||||
precondition "";
|
||||
}
|
||||
|
||||
sequence_link sa_assess_then_decide "Continue" id "9d4a131f-36ad-5125-b21f-c3dd033b8c82" {
|
||||
description "";
|
||||
guard "";
|
||||
source @sa_assess_step;
|
||||
target @sa_decision;
|
||||
}
|
||||
|
||||
sequence_link sa_field_path "else" id "1bbd5957-1173-51d8-97e3-ba4f084227ae" {
|
||||
description "";
|
||||
guard "else";
|
||||
source @sa_decision;
|
||||
target @sa_use_field;
|
||||
}
|
||||
|
||||
sequence_link sa_remote_path "remote reset is authorized" id "d8b6710a-e713-5979-934f-e5ca7d155bb4" {
|
||||
description "";
|
||||
guard "remote reset is authorized";
|
||||
source @sa_decision;
|
||||
target @sa_reset_step;
|
||||
}
|
||||
|
||||
sequence_link sa_confirm_path "Continue" id "1e738f27-a3a1-526d-b330-6384088b9689" {
|
||||
description "";
|
||||
guard "";
|
||||
source @sa_merge;
|
||||
target @sa_confirm_step;
|
||||
}
|
||||
|
||||
sequence_link sa_remote_merge "Continue" id "e5279265-8eac-52e8-98dc-571b20475e1f" {
|
||||
description "";
|
||||
guard "";
|
||||
source @sa_reset_step;
|
||||
target @sa_merge;
|
||||
}
|
||||
|
||||
chain_involvement sa_response_delivery "Chain involvement: Restore a safe supply" id "66efc484-53c7-51a3-89e9-422429344b38" {
|
||||
description "";
|
||||
source @sa_response;
|
||||
target @sa_restore;
|
||||
}
|
||||
|
||||
sequence_link sa_field_merge "Continue" id "0f6ac3fb-4ad6-581e-ad14-336472072d5e" {
|
||||
description "";
|
||||
guard "";
|
||||
source @sa_use_field;
|
||||
target @sa_merge;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
sa_scenario sa_conversation "Repair request and measured reply" id "730b27ca-b039-5a3b-8dc6-03418f9061b3" {
|
||||
context @sa_restore;
|
||||
description "";
|
||||
parent none;
|
||||
postcondition "The controller has received the measured pressure after repair";
|
||||
precondition "A pressure alarm has been assessed";
|
||||
steps [@sa_call, @sa_reply];
|
||||
@@ -14,23 +12,17 @@ sa_occurrence sa_call "Request valve repair" id "8bab4783-a098-5984-9e36-493957c
|
||||
exchange @sa_contact;
|
||||
message_kind Call;
|
||||
receiver @sa_responder;
|
||||
reply_to none;
|
||||
sender @sa_caller;
|
||||
values [{
|
||||
expression "420.0";
|
||||
field @sa_pressure_parameter;
|
||||
path [];
|
||||
}];
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent @sa_conversation;
|
||||
postcondition "";
|
||||
precondition "";
|
||||
}
|
||||
|
||||
sa_lifeline sa_caller "Controller" id "98c61788-2fee-51f4-8cf9-de48e8c70e9e" {
|
||||
description "";
|
||||
parent @sa_conversation;
|
||||
represented @sa_control;
|
||||
}
|
||||
@@ -46,18 +38,13 @@ sa_occurrence sa_reply "Return pressure after repair" id "4e1c0a56-ce80-5f13-a93
|
||||
values [{
|
||||
expression "320.0";
|
||||
field @sa_pressure_parameter;
|
||||
path [];
|
||||
}];
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent @sa_conversation;
|
||||
postcondition "";
|
||||
precondition "";
|
||||
}
|
||||
|
||||
sa_lifeline sa_responder "Technician" id "6249b54a-e396-5338-82b9-89266c55670d" {
|
||||
description "";
|
||||
parent @sa_conversation;
|
||||
represented @sa_technician;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
sa_scenario sa_full_scenario "Restore supply through field repair" id "f746a1cd-ff9f-55c0-b325-01c03d2f4fae" {
|
||||
context @sa_restore;
|
||||
description "";
|
||||
parent none;
|
||||
postcondition "The controller has received the measured pressure after repair";
|
||||
precondition "A pressure alarm has been assessed";
|
||||
steps [@sa_use_conversation];
|
||||
@@ -9,13 +7,11 @@ sa_scenario sa_full_scenario "Restore supply through field repair" id "f746a1cd-
|
||||
}
|
||||
|
||||
sa_lifeline sa_outer_controller "Controller" id "1edfcf9e-9bfa-51f1-80d5-62b8fd8bb023" {
|
||||
description "";
|
||||
parent @sa_full_scenario;
|
||||
represented @sa_control;
|
||||
}
|
||||
|
||||
sa_lifeline sa_outer_technician "Technician" id "155e4fe4-9e3b-5f4e-b886-28abcc3f086b" {
|
||||
description "";
|
||||
parent @sa_full_scenario;
|
||||
represented @sa_technician;
|
||||
}
|
||||
@@ -33,9 +29,6 @@ sa_occurrence sa_use_conversation "Use the reviewed repair conversation" id "1c9
|
||||
scenario @sa_conversation;
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent @sa_full_scenario;
|
||||
postcondition "";
|
||||
precondition "";
|
||||
}
|
||||
|
||||
|
||||
@@ -1,80 +1,43 @@
|
||||
sa_state_machine sa_monitor "Pressure supervision" id "132b3f28-3f88-5327-9868-8c8b645ed412" {
|
||||
description "";
|
||||
parent @sa_control;
|
||||
}
|
||||
|
||||
sa_region sa_monitor_region "Supervision cycle" id "3ab11e24-4140-58fc-b3fa-da5f51c7fe2c" {
|
||||
description "";
|
||||
parent @sa_monitor;
|
||||
}
|
||||
|
||||
sa_initial sa_monitor_initial "Start" id "57eb5348-14d8-560e-996a-8dbf993243e2" {
|
||||
description "";
|
||||
do_activity "";
|
||||
entry "";
|
||||
exit "";
|
||||
kind Initial;
|
||||
parent @sa_monitor_region;
|
||||
}
|
||||
|
||||
sa_state sa_monitoring "Monitoring" id "8af21f9b-c21e-5aae-af0d-0958840f6655" {
|
||||
description "";
|
||||
do_activity "";
|
||||
entry "";
|
||||
exit "";
|
||||
kind State;
|
||||
parent @sa_monitor_region;
|
||||
}
|
||||
|
||||
sa_state sa_waiting "Awaiting repair" id "a6bb10b1-f1e5-5b31-8afd-5bad5a7b6c37" {
|
||||
description "";
|
||||
do_activity "";
|
||||
entry "";
|
||||
exit "";
|
||||
kind State;
|
||||
parent @sa_monitor_region;
|
||||
}
|
||||
|
||||
state_transition sa_start_monitoring "State transition: Monitoring" id "47730532-0372-5cc5-9d6d-0b8953aebdd8" {
|
||||
description "";
|
||||
effect "";
|
||||
effects [];
|
||||
guard "";
|
||||
source @sa_monitor_initial;
|
||||
target @sa_monitoring;
|
||||
transition_kind External;
|
||||
trigger "";
|
||||
triggers [];
|
||||
}
|
||||
|
||||
state_transition sa_alarm_transition "State transition: Awaiting repair" id "13c3bfa4-9254-5ab2-b96f-f65f402adf81" {
|
||||
description "";
|
||||
effect "";
|
||||
effects [];
|
||||
guard "";
|
||||
source @sa_monitoring;
|
||||
target @sa_waiting;
|
||||
transition_kind External;
|
||||
trigger "";
|
||||
triggers [@sa_high_pressure];
|
||||
}
|
||||
|
||||
state_action sa_assess_on_entry "Assess when repair is needed" id "a887f96a-37cb-5891-8070-011fa276e5b5" {
|
||||
description "";
|
||||
phase Entry;
|
||||
source @sa_waiting;
|
||||
target @sa_assess;
|
||||
}
|
||||
|
||||
state_transition sa_normal_transition "State transition: Monitoring" id "6e2c1b47-764c-577a-b325-ff66dd2a2768" {
|
||||
description "";
|
||||
effect "";
|
||||
effects [];
|
||||
guard "repair confirmed and pressure is safe";
|
||||
source @sa_waiting;
|
||||
target @sa_monitoring;
|
||||
transition_kind External;
|
||||
trigger "";
|
||||
triggers [];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,26 +1,18 @@
|
||||
sa_mission sa_mission "Maintain safe water supply" id "5ad034b1-084d-5273-9e70-971671766132" {
|
||||
description "";
|
||||
parent none;
|
||||
}
|
||||
|
||||
sa_capability sa_restore "Restore a safe supply" id "81259051-370a-512d-a3b5-6420a6f933b6" {
|
||||
description "";
|
||||
parent none;
|
||||
}
|
||||
|
||||
sa_capability sa_triage "Assess an alarm" id "bad8fa7c-f634-55fd-98d3-e1eb2da05d8f" {
|
||||
description "";
|
||||
parent none;
|
||||
}
|
||||
|
||||
mission_capability sa_mission_delivery "Mission capability: Restore a safe supply" id "a0902e0f-3d18-576a-9aca-975a136dfdd7" {
|
||||
description "";
|
||||
source @sa_mission;
|
||||
target @sa_restore;
|
||||
}
|
||||
|
||||
capability_include sa_include_triage "Capability include: Assess an alarm" id "f3fe7690-734a-5877-8b57-a6599a4033c4" {
|
||||
description "";
|
||||
source @sa_restore;
|
||||
target @sa_triage;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
sa_function sa_audit_thresholds "Audit pressure thresholds" id "4149a872-3440-59de-9879-8981e78d27ab" {
|
||||
description "Deliberately unfinished: assigned to the service, but no behavior context yet. Model checks should expose this one work_without_behavior_context warning.";
|
||||
parent none;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
sa_function sa_restore_work "Restore safe pressure" id "58867e7d-916e-5ebc-9e4c-8dbed1314be3" {
|
||||
description "";
|
||||
parent none;
|
||||
}
|
||||
|
||||
sa_function sa_assess "Assess pressure alarm" id "dddae020-a444-5d48-acc8-139d2696a672" {
|
||||
description "";
|
||||
parent @sa_restore_work;
|
||||
}
|
||||
|
||||
@@ -14,13 +11,10 @@ sa_port sa_repair_request_out "Request field repair output" id "24a6850e-b819-57
|
||||
outgoing_items [@sa_repair_operation];
|
||||
};
|
||||
};
|
||||
description "";
|
||||
legacy none;
|
||||
parent @sa_assess;
|
||||
}
|
||||
|
||||
sa_function sa_confirm "Confirm safe pressure" id "d75eb3fa-a27d-52d5-8782-8b342b3865f6" {
|
||||
description "";
|
||||
parent @sa_restore_work;
|
||||
}
|
||||
|
||||
@@ -30,13 +24,10 @@ sa_port sa_repair_report_in "Report repair result input" id "391af7c4-b07d-53a7-
|
||||
incoming_items [@sa_repair_operation];
|
||||
};
|
||||
};
|
||||
description "";
|
||||
legacy none;
|
||||
parent @sa_confirm;
|
||||
}
|
||||
|
||||
sa_function sa_repair "Repair valve in the field" id "9497e10f-04c4-5586-8738-2464a6f00bd4" {
|
||||
description "";
|
||||
parent @sa_restore_work;
|
||||
}
|
||||
|
||||
@@ -46,8 +37,6 @@ sa_port sa_repair_report_out "Report repair result output" id "994faed7-dbc8-5b9
|
||||
outgoing_items [@sa_repair_operation];
|
||||
};
|
||||
};
|
||||
description "";
|
||||
legacy none;
|
||||
parent @sa_repair;
|
||||
}
|
||||
|
||||
@@ -57,24 +46,19 @@ sa_port sa_repair_request_in "Request field repair input" id "d2113fb0-a531-54ef
|
||||
incoming_items [@sa_repair_operation];
|
||||
};
|
||||
};
|
||||
description "";
|
||||
legacy none;
|
||||
parent @sa_repair;
|
||||
}
|
||||
|
||||
sa_function sa_reset "Reset valve remotely" id "09342ccb-044b-5483-ac58-87dc3cf7831c" {
|
||||
description "";
|
||||
parent @sa_restore_work;
|
||||
}
|
||||
|
||||
capability_involvement sa_assessment_support "Capability involvement: Assess an alarm" id "93eaad8d-83b7-5980-b9bb-86c9e3f31da4" {
|
||||
description "";
|
||||
source @sa_assess;
|
||||
target @sa_triage;
|
||||
}
|
||||
|
||||
functional_exchange sa_repair_request "Request field repair" id "93474111-f23e-56c1-b61b-b7c2396b91bd" {
|
||||
description "";
|
||||
items [@sa_repair_operation];
|
||||
source @sa_assess;
|
||||
source_port @sa_repair_request_out;
|
||||
@@ -83,7 +67,6 @@ functional_exchange sa_repair_request "Request field repair" id "93474111-f23e-5
|
||||
}
|
||||
|
||||
functional_exchange sa_repair_report "Report repair result" id "684eadc3-e670-5779-a60f-bbc9a5bfb062" {
|
||||
description "";
|
||||
items [@sa_repair_operation];
|
||||
source @sa_repair;
|
||||
source_port @sa_repair_report_out;
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
sa_exchange_category sa_contact_category "Field contact" id "781cbe75-410f-5cc5-aeb8-a43491f77b99" {
|
||||
description "";
|
||||
exchanges [@sa_contact];
|
||||
family "Participant";
|
||||
parent none;
|
||||
}
|
||||
|
||||
sa_event sa_high_pressure "Pressure alarm detected" id "01490fa8-2f01-5ac8-9722-d55d45414379" {
|
||||
@@ -11,14 +9,9 @@ sa_event sa_high_pressure "Pressure alarm detected" id "01490fa8-2f01-5ac8-9722-
|
||||
expression "measured_pressure > operating_limit";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent none;
|
||||
}
|
||||
|
||||
sa_exchange_category sa_repair_traffic "Repair work exchanges" id "a9a47e48-100c-57a8-95f0-7fe24da94f94" {
|
||||
description "";
|
||||
exchanges [@sa_repair_request, @sa_repair_report];
|
||||
family "Work";
|
||||
parent none;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
sa_system sa_control "Pressure coordination service" id "435bf87c-73fd-5e4d-978a-4c471bc9eaf0" {
|
||||
description "";
|
||||
parent none;
|
||||
}
|
||||
|
||||
sa_port sa_control_port "Repair service client" id "98d411e7-7c65-5c3f-b543-8bf0f2522ea2" {
|
||||
@@ -11,13 +9,10 @@ sa_port sa_control_port "Repair service client" id "98d411e7-7c65-5c3f-b543-8bf0
|
||||
};
|
||||
};
|
||||
description "Explicitly chosen Standard component port for the repair service.";
|
||||
legacy none;
|
||||
parent @sa_control;
|
||||
}
|
||||
|
||||
sa_actor sa_technician "Field technician" id "c05b9422-b9da-5de5-b21d-07ad23bd2b8a" {
|
||||
description "";
|
||||
parent none;
|
||||
}
|
||||
|
||||
sa_port sa_technician_port "Repair service provider" id "e6d69cbd-99d7-596b-bbe3-dada6118a600" {
|
||||
@@ -28,36 +23,30 @@ sa_port sa_technician_port "Repair service provider" id "e6d69cbd-99d7-596b-bbe3
|
||||
};
|
||||
};
|
||||
description "Explicitly chosen Standard component port for the repair service.";
|
||||
legacy none;
|
||||
parent @sa_technician;
|
||||
}
|
||||
|
||||
allocation sa_assess_allocation "Allocation: Assess pressure alarm" id "9b9356d7-2db2-5a94-a47e-ea892cf02afe" {
|
||||
description "";
|
||||
source @sa_control;
|
||||
target @sa_assess;
|
||||
}
|
||||
|
||||
allocation sa_audit_allocation "Allocation: Audit pressure thresholds" id "1b245065-7242-5d81-8472-aaeb932054c9" {
|
||||
description "";
|
||||
source @sa_control;
|
||||
target @sa_audit_thresholds;
|
||||
}
|
||||
|
||||
allocation sa_confirm_allocation "Allocation: Confirm safe pressure" id "b76bf8de-2fa4-563f-a540-dd30f30e6c49" {
|
||||
description "";
|
||||
source @sa_control;
|
||||
target @sa_confirm;
|
||||
}
|
||||
|
||||
interface_requirement sa_client_requires "Interface requirement: Valve repair service" id "4f85337b-f6eb-533c-a45a-9a5d1d9567ca" {
|
||||
description "";
|
||||
source @sa_control_port;
|
||||
target @sa_repair_interface;
|
||||
}
|
||||
|
||||
boundary_exchange sa_contact "Technician service conversation" id "63009b5f-539e-5914-b630-ec6b7fefb4d5" {
|
||||
description "";
|
||||
items [@sa_repair_operation];
|
||||
oriented false;
|
||||
source @sa_control_port;
|
||||
@@ -65,61 +54,51 @@ boundary_exchange sa_contact "Technician service conversation" id "63009b5f-539e
|
||||
}
|
||||
|
||||
exchange_allocation sa_report_carriage "Exchange allocation: Report repair result" id "ff9897b3-a23a-5994-a5b3-99a5b4d34ceb" {
|
||||
description "";
|
||||
source @sa_contact;
|
||||
target @sa_repair_report;
|
||||
}
|
||||
|
||||
exchange_allocation sa_request_carriage "Exchange allocation: Request field repair" id "4c4c4851-5a3d-5bb9-94df-b19f9cf39819" {
|
||||
description "";
|
||||
source @sa_contact;
|
||||
target @sa_repair_request;
|
||||
}
|
||||
|
||||
port_allocation sa_port_report_in "Port allocation: Report repair result input" id "568c5c01-de21-52a2-83bd-afdddc158085" {
|
||||
description "";
|
||||
source @sa_control_port;
|
||||
target @sa_repair_report_in;
|
||||
}
|
||||
|
||||
port_allocation sa_port_request_out "Port allocation: Request field repair output" id "55ec4dbf-bd17-5b0c-b3a3-95b2194aa8b9" {
|
||||
description "";
|
||||
source @sa_control_port;
|
||||
target @sa_repair_request_out;
|
||||
}
|
||||
|
||||
mission_involvement sa_mission_participant "Mission involvement: Maintain safe water supply" id "1c1e5634-ba8c-591f-b143-90a27cdc6cd2" {
|
||||
description "";
|
||||
source @sa_control;
|
||||
target @sa_mission;
|
||||
}
|
||||
|
||||
allocation sa_reset_allocation "Allocation: Reset valve remotely" id "3cc9ab52-2b00-57fd-8709-aabc75e5d3e3" {
|
||||
description "";
|
||||
source @sa_control;
|
||||
target @sa_reset;
|
||||
}
|
||||
|
||||
allocation sa_repair_allocation "Allocation: Repair valve in the field" id "725f2e1b-aa2c-5615-9b1f-28da178168fa" {
|
||||
description "";
|
||||
source @sa_technician;
|
||||
target @sa_repair;
|
||||
}
|
||||
|
||||
port_allocation sa_port_report_out "Port allocation: Report repair result output" id "e53b7a40-e8a3-5b3f-826d-c2b5c164a84a" {
|
||||
description "";
|
||||
source @sa_technician_port;
|
||||
target @sa_repair_report_out;
|
||||
}
|
||||
|
||||
port_allocation sa_port_request_in "Port allocation: Request field repair input" id "09eaa992-4cdf-5ea3-b748-f10fd74b8cba" {
|
||||
description "";
|
||||
source @sa_technician_port;
|
||||
target @sa_repair_request_in;
|
||||
}
|
||||
|
||||
interface_provision sa_provider_provides "Interface provision: Valve repair service" id "55f89fbf-aa3c-5ae1-95ef-ac676f9c1ada" {
|
||||
description "";
|
||||
source @sa_technician_port;
|
||||
target @sa_repair_interface;
|
||||
}
|
||||
|
||||
@@ -1,48 +1,30 @@
|
||||
sa_data_type sa_pressure "Measured pressure" id "87d0a95b-af1b-5352-b753-e4c6533671a5" {
|
||||
default none;
|
||||
definition {
|
||||
Real {
|
||||
maximum 600.0;
|
||||
minimum 0.0;
|
||||
};
|
||||
};
|
||||
description "";
|
||||
parent none;
|
||||
unit "kPa";
|
||||
}
|
||||
|
||||
sa_interface sa_repair_interface "Valve repair service" id "a4b8942e-a975-5f88-ad14-8f38c345baac" {
|
||||
description "";
|
||||
parent none;
|
||||
supertype none;
|
||||
}
|
||||
|
||||
sa_exchange_item sa_repair_operation "Valve repair" id "a962fc5e-3ab0-5296-8b0d-fd84633f9218" {
|
||||
description "";
|
||||
kind Information;
|
||||
mechanism Operation;
|
||||
parent none;
|
||||
supertype none;
|
||||
}
|
||||
|
||||
sa_data_field sa_pressure_parameter "Pressure before / after repair" id "bb12ba5d-aab5-5a1b-99de-c767f5365b57" {
|
||||
default none;
|
||||
description "";
|
||||
direction InOut;
|
||||
maximum 1;
|
||||
minimum 1;
|
||||
parent @sa_repair_operation;
|
||||
storage Value;
|
||||
type_ref {
|
||||
Named @sa_pressure;
|
||||
};
|
||||
unit "";
|
||||
}
|
||||
|
||||
interface_item_allocation sa_repair_interface_item "Repair operation contract" id "f074e041-23cf-54ad-af9c-f171e30621e7" {
|
||||
acquisition Accept;
|
||||
description "";
|
||||
order 0;
|
||||
source @sa_repair_interface;
|
||||
target @sa_repair_operation;
|
||||
transmission Synchronous;
|
||||
|
||||
@@ -9,7 +9,6 @@ trace trace_oa_alarm_transition "State transition: Awaiting repair ↔ State tra
|
||||
name "State transition: Awaiting repair";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Manual;
|
||||
oa @oa_alarm_transition;
|
||||
sa @sa_alarm_transition;
|
||||
@@ -26,8 +25,6 @@ trace trace_oa_assess "Assess pressure alarm ↔ Assess pressure alarm" id "5309
|
||||
name "Assess pressure alarm";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Refinement;
|
||||
oa @oa_assess;
|
||||
sa @sa_assess;
|
||||
}
|
||||
@@ -43,7 +40,6 @@ trace trace_oa_assess_allocation "Allocation: Assess pressure alarm ↔ Allocati
|
||||
name "Allocation: Assess pressure alarm";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Manual;
|
||||
oa @oa_assess_allocation;
|
||||
sa @sa_assess_allocation;
|
||||
@@ -60,7 +56,6 @@ trace trace_oa_assess_on_entry "Assess when repair is needed ↔ Assess when rep
|
||||
name "Assess when repair is needed";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Manual;
|
||||
oa @oa_assess_on_entry;
|
||||
sa @sa_assess_on_entry;
|
||||
@@ -77,7 +72,6 @@ trace trace_oa_assess_step "Assess the alarm ↔ Assess the alarm" id "e848da41-
|
||||
name "Assess the alarm";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Sequence;
|
||||
oa @oa_assess_step;
|
||||
sa @sa_assess_step;
|
||||
@@ -94,7 +88,6 @@ trace trace_oa_assess_then_decide "Continue ↔ Continue" id "a5c1eb01-a95f-5f7a
|
||||
name "Continue";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Manual;
|
||||
oa @oa_assess_then_decide;
|
||||
sa @sa_assess_then_decide;
|
||||
@@ -111,7 +104,6 @@ trace trace_oa_assessment_action "Assess pressure alarm ↔ Assess pressure alar
|
||||
name "Assess pressure alarm";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Sequence;
|
||||
oa @oa_assessment_action;
|
||||
sa @sa_assessment_action;
|
||||
@@ -128,7 +120,6 @@ trace trace_oa_assessment_delivery "Chain involvement: Assess an alarm ↔ Chain
|
||||
name "Chain involvement: Assess an alarm";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Manual;
|
||||
oa @oa_assessment_delivery;
|
||||
sa @sa_assessment_delivery;
|
||||
@@ -145,7 +136,6 @@ trace trace_oa_assessment_procedure "Assess an alarm procedure ↔ Assess an ala
|
||||
name "Assess an alarm procedure";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Sequence;
|
||||
oa @oa_assessment_procedure;
|
||||
sa @sa_assessment_procedure;
|
||||
@@ -162,7 +152,6 @@ trace trace_oa_assessment_support "Capability involvement: Assess an alarm ↔ C
|
||||
name "Capability involvement: Assess an alarm";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Manual;
|
||||
oa @oa_assessment_support;
|
||||
sa @sa_assessment_support;
|
||||
@@ -179,7 +168,6 @@ trace trace_oa_call "Request valve repair ↔ Request valve repair" id "f0cc86e5
|
||||
name "Request valve repair";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Scenario;
|
||||
oa @oa_call;
|
||||
sa @sa_call;
|
||||
@@ -196,7 +184,6 @@ trace trace_oa_caller "Controller ↔ Controller" id "241dfdac-2450-5704-a4cb-9f
|
||||
name "Controller";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Scenario;
|
||||
oa @oa_caller;
|
||||
sa @sa_caller;
|
||||
@@ -213,8 +200,6 @@ trace trace_oa_confirm "Confirm safe pressure ↔ Confirm safe pressure" id "d77
|
||||
name "Confirm safe pressure";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Refinement;
|
||||
oa @oa_confirm;
|
||||
sa @sa_confirm;
|
||||
}
|
||||
@@ -230,7 +215,6 @@ trace trace_oa_confirm_allocation "Allocation: Confirm safe pressure ↔ Allocat
|
||||
name "Allocation: Confirm safe pressure";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Manual;
|
||||
oa @oa_confirm_allocation;
|
||||
sa @sa_confirm_allocation;
|
||||
@@ -247,7 +231,6 @@ trace trace_oa_confirm_path "Continue ↔ Continue" id "a106d183-c239-5c9f-b1f1-
|
||||
name "Continue";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Manual;
|
||||
oa @oa_confirm_path;
|
||||
sa @sa_confirm_path;
|
||||
@@ -264,7 +247,6 @@ trace trace_oa_confirm_step "Confirm safe pressure ↔ Confirm safe pressure" id
|
||||
name "Confirm safe pressure";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Sequence;
|
||||
oa @oa_confirm_step;
|
||||
sa @sa_confirm_step;
|
||||
@@ -281,7 +263,6 @@ trace trace_oa_contact "Technician service conversation ↔ Technician service c
|
||||
name "Technician service conversation";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Exchange;
|
||||
oa @oa_contact;
|
||||
sa @sa_contact;
|
||||
@@ -298,7 +279,6 @@ trace trace_oa_contact_category "Field contact ↔ Field contact" id "e96ff119-b
|
||||
name "Field contact";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Manual;
|
||||
oa @oa_contact_category;
|
||||
sa @sa_contact_category;
|
||||
@@ -315,7 +295,6 @@ trace trace_oa_control "Control room ↔ Pressure coordination service" id "aba5
|
||||
name "Pressure coordination service";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Participant;
|
||||
oa @oa_control;
|
||||
sa @sa_control;
|
||||
@@ -332,7 +311,6 @@ trace trace_oa_conversation "Repair request and measured reply ↔ Repair reques
|
||||
name "Repair request and measured reply";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Scenario;
|
||||
oa @oa_conversation;
|
||||
sa @sa_conversation;
|
||||
@@ -349,7 +327,6 @@ trace trace_oa_decision "Can a remote reset safely recover pressure? ↔ Can a r
|
||||
name "Can a remote reset safely recover pressure?";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Sequence;
|
||||
oa @oa_decision;
|
||||
sa @sa_decision;
|
||||
@@ -366,7 +343,6 @@ trace trace_oa_field_merge "Continue ↔ Continue" id "d32dd433-9c9e-5b57-9355-2
|
||||
name "Continue";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Manual;
|
||||
oa @oa_field_merge;
|
||||
sa @sa_field_merge;
|
||||
@@ -383,7 +359,6 @@ trace trace_oa_field_path "else ↔ else" id "2e849e31-35aa-5aef-a989-26948038e5
|
||||
name "else";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Manual;
|
||||
oa @oa_field_path;
|
||||
sa @sa_field_path;
|
||||
@@ -400,7 +375,6 @@ trace trace_oa_field_procedure "Field repair procedure ↔ Field repair procedur
|
||||
name "Field repair procedure";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Sequence;
|
||||
oa @oa_field_procedure;
|
||||
sa @sa_field_procedure;
|
||||
@@ -417,7 +391,6 @@ trace trace_oa_full_scenario "Restore supply through field repair ↔ Restore su
|
||||
name "Restore supply through field repair";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Scenario;
|
||||
oa @oa_full_scenario;
|
||||
sa @sa_full_scenario;
|
||||
@@ -434,7 +407,6 @@ trace trace_oa_high_pressure "Pressure alarm detected ↔ Pressure alarm detecte
|
||||
name "Pressure alarm detected";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind State;
|
||||
oa @oa_high_pressure;
|
||||
sa @sa_high_pressure;
|
||||
@@ -451,7 +423,6 @@ trace trace_oa_include_triage "Capability include: Assess an alarm ↔ Capabilit
|
||||
name "Capability include: Assess an alarm";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Manual;
|
||||
oa @oa_include_triage;
|
||||
sa @sa_include_triage;
|
||||
@@ -468,7 +439,6 @@ trace trace_oa_merge "Recovery path completed ↔ Recovery path completed" id "0
|
||||
name "Recovery path completed";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Sequence;
|
||||
oa @oa_merge;
|
||||
sa @sa_merge;
|
||||
@@ -485,7 +455,6 @@ trace trace_oa_mission "Maintain safe water supply ↔ Maintain safe water suppl
|
||||
name "Maintain safe water supply";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Mission;
|
||||
oa @oa_mission;
|
||||
sa @sa_mission;
|
||||
@@ -502,7 +471,6 @@ trace trace_oa_mission_delivery "Mission capability: Restore a safe supply ↔ M
|
||||
name "Mission capability: Restore a safe supply";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Manual;
|
||||
oa @oa_mission_delivery;
|
||||
sa @sa_mission_delivery;
|
||||
@@ -519,7 +487,6 @@ trace trace_oa_mission_participant "Mission involvement: Maintain safe water sup
|
||||
name "Mission involvement: Maintain safe water supply";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Manual;
|
||||
oa @oa_mission_participant;
|
||||
sa @sa_mission_participant;
|
||||
@@ -536,7 +503,6 @@ trace trace_oa_monitor "Pressure supervision ↔ Pressure supervision" id "b5386
|
||||
name "Pressure supervision";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind State;
|
||||
oa @oa_monitor;
|
||||
sa @sa_monitor;
|
||||
@@ -553,7 +519,6 @@ trace trace_oa_monitor_initial "Start ↔ Start" id "48d243f0-553f-507e-acb0-947
|
||||
name "Start";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind State;
|
||||
oa @oa_monitor_initial;
|
||||
sa @sa_monitor_initial;
|
||||
@@ -570,7 +535,6 @@ trace trace_oa_monitor_region "Supervision cycle ↔ Supervision cycle" id "2087
|
||||
name "Supervision cycle";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind State;
|
||||
oa @oa_monitor_region;
|
||||
sa @sa_monitor_region;
|
||||
@@ -587,7 +551,6 @@ trace trace_oa_monitoring "Monitoring ↔ Monitoring" id "12ec320f-2e14-5a5a-8c6
|
||||
name "Monitoring";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind State;
|
||||
oa @oa_monitoring;
|
||||
sa @sa_monitoring;
|
||||
@@ -604,7 +567,6 @@ trace trace_oa_normal_transition "State transition: Monitoring ↔ State transit
|
||||
name "State transition: Monitoring";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Manual;
|
||||
oa @oa_normal_transition;
|
||||
sa @sa_normal_transition;
|
||||
@@ -621,7 +583,6 @@ trace trace_oa_outer_controller "Controller ↔ Controller" id "fd195498-dbba-52
|
||||
name "Controller";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Scenario;
|
||||
oa @oa_outer_controller;
|
||||
sa @sa_outer_controller;
|
||||
@@ -638,7 +599,6 @@ trace trace_oa_outer_technician "Technician ↔ Technician" id "c132a0df-1270-55
|
||||
name "Technician";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Scenario;
|
||||
oa @oa_outer_technician;
|
||||
sa @sa_outer_technician;
|
||||
@@ -655,7 +615,6 @@ trace trace_oa_pressure "Measured pressure ↔ Measured pressure" id "d9d47371-e
|
||||
name "Measured pressure";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Item;
|
||||
oa @oa_pressure;
|
||||
sa @sa_pressure;
|
||||
@@ -672,7 +631,6 @@ trace trace_oa_pressure_parameter "Pressure before / after repair ↔ Pressure b
|
||||
name "Pressure before / after repair";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Item;
|
||||
oa @oa_pressure_parameter;
|
||||
sa @sa_pressure_parameter;
|
||||
@@ -689,7 +647,6 @@ trace trace_oa_remote_merge "Continue ↔ Continue" id "1b788e74-36b2-5c17-a936-
|
||||
name "Continue";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Manual;
|
||||
oa @oa_remote_merge;
|
||||
sa @sa_remote_merge;
|
||||
@@ -706,7 +663,6 @@ trace trace_oa_remote_path "remote reset is authorized ↔ remote reset is autho
|
||||
name "remote reset is authorized";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Manual;
|
||||
oa @oa_remote_path;
|
||||
sa @sa_remote_path;
|
||||
@@ -723,8 +679,6 @@ trace trace_oa_repair "Repair valve in the field ↔ Repair valve in the field"
|
||||
name "Repair valve in the field";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Refinement;
|
||||
oa @oa_repair;
|
||||
sa @sa_repair;
|
||||
}
|
||||
@@ -740,7 +694,6 @@ trace trace_oa_repair_allocation "Allocation: Repair valve in the field ↔ Allo
|
||||
name "Allocation: Repair valve in the field";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Manual;
|
||||
oa @oa_repair_allocation;
|
||||
sa @sa_repair_allocation;
|
||||
@@ -757,7 +710,6 @@ trace trace_oa_repair_operation "Valve repair ↔ Valve repair" id "cf92cedf-ea1
|
||||
name "Valve repair";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Item;
|
||||
oa @oa_repair_operation;
|
||||
sa @sa_repair_operation;
|
||||
@@ -774,7 +726,6 @@ trace trace_oa_repair_report "Report repair result ↔ Report repair result" id
|
||||
name "Report repair result";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Exchange;
|
||||
oa @oa_repair_report;
|
||||
sa @sa_repair_report;
|
||||
@@ -791,7 +742,6 @@ trace trace_oa_repair_request "Request field repair ↔ Request field repair" id
|
||||
name "Request field repair";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Exchange;
|
||||
oa @oa_repair_request;
|
||||
sa @sa_repair_request;
|
||||
@@ -808,7 +758,6 @@ trace trace_oa_repair_step "Repair the valve ↔ Repair the valve" id "ac3aa6b0-
|
||||
name "Repair the valve";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Sequence;
|
||||
oa @oa_repair_step;
|
||||
sa @sa_repair_step;
|
||||
@@ -825,7 +774,6 @@ trace trace_oa_repair_then_report "Sequence link: Report the measured result ↔
|
||||
name "Sequence link: Report the measured result";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Manual;
|
||||
oa @oa_repair_then_report;
|
||||
sa @sa_repair_then_report;
|
||||
@@ -842,7 +790,6 @@ trace trace_oa_repair_traffic "Repair work exchanges ↔ Repair work exchanges"
|
||||
name "Repair work exchanges";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Manual;
|
||||
oa @oa_repair_traffic;
|
||||
sa @sa_repair_traffic;
|
||||
@@ -859,7 +806,6 @@ trace trace_oa_reply "Return pressure after repair ↔ Return pressure after rep
|
||||
name "Return pressure after repair";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Scenario;
|
||||
oa @oa_reply;
|
||||
sa @sa_reply;
|
||||
@@ -876,7 +822,6 @@ trace trace_oa_report_step "Report the measured result ↔ Report the measured r
|
||||
name "Report the measured result";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Sequence;
|
||||
oa @oa_report_step;
|
||||
sa @sa_report_step;
|
||||
@@ -893,7 +838,6 @@ trace trace_oa_request_step "Request the field repair ↔ Request the field repa
|
||||
name "Request the field repair";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Sequence;
|
||||
oa @oa_request_step;
|
||||
sa @sa_request_step;
|
||||
@@ -910,7 +854,6 @@ trace trace_oa_request_then_repair "Sequence link: Repair the valve ↔ Sequence
|
||||
name "Sequence link: Repair the valve";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Manual;
|
||||
oa @oa_request_then_repair;
|
||||
sa @sa_request_then_repair;
|
||||
@@ -927,8 +870,6 @@ trace trace_oa_reset "Reset valve remotely ↔ Reset valve remotely" id "82a5be1
|
||||
name "Reset valve remotely";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Refinement;
|
||||
oa @oa_reset;
|
||||
sa @sa_reset;
|
||||
}
|
||||
@@ -944,7 +885,6 @@ trace trace_oa_reset_allocation "Allocation: Reset valve remotely ↔ Allocation
|
||||
name "Allocation: Reset valve remotely";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Manual;
|
||||
oa @oa_reset_allocation;
|
||||
sa @sa_reset_allocation;
|
||||
@@ -961,7 +901,6 @@ trace trace_oa_reset_step "Try the authorized remote reset ↔ Try the authorize
|
||||
name "Try the authorized remote reset";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Sequence;
|
||||
oa @oa_reset_step;
|
||||
sa @sa_reset_step;
|
||||
@@ -978,7 +917,6 @@ trace trace_oa_responder "Technician ↔ Technician" id "c5051628-b7af-5fb1-a014
|
||||
name "Technician";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Scenario;
|
||||
oa @oa_responder;
|
||||
sa @sa_responder;
|
||||
@@ -995,7 +933,6 @@ trace trace_oa_response "Handle a pressure alarm ↔ Handle a pressure alarm" id
|
||||
name "Handle a pressure alarm";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Sequence;
|
||||
oa @oa_response;
|
||||
sa @sa_response;
|
||||
@@ -1012,7 +949,6 @@ trace trace_oa_response_delivery "Chain involvement: Restore a safe supply ↔ C
|
||||
name "Chain involvement: Restore a safe supply";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Manual;
|
||||
oa @oa_response_delivery;
|
||||
sa @sa_response_delivery;
|
||||
@@ -1029,7 +965,6 @@ trace trace_oa_restore "Restore a safe supply ↔ Restore a safe supply" id "0fb
|
||||
name "Restore a safe supply";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Capability;
|
||||
oa @oa_restore;
|
||||
sa @sa_restore;
|
||||
@@ -1046,8 +981,6 @@ trace trace_oa_restore_work "Restore safe pressure ↔ Restore safe pressure" id
|
||||
name "Restore safe pressure";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Refinement;
|
||||
oa @oa_restore_work;
|
||||
sa @sa_restore_work;
|
||||
}
|
||||
@@ -1063,7 +996,6 @@ trace trace_oa_start_monitoring "State transition: Monitoring ↔ State transiti
|
||||
name "State transition: Monitoring";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Manual;
|
||||
oa @oa_start_monitoring;
|
||||
sa @sa_start_monitoring;
|
||||
@@ -1080,7 +1012,6 @@ trace trace_oa_technician "Field technician ↔ Field technician" id "d47d3c36-5
|
||||
name "Field technician";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Participant;
|
||||
oa @oa_technician;
|
||||
sa @sa_technician;
|
||||
@@ -1097,7 +1028,6 @@ trace trace_oa_triage "Assess an alarm ↔ Assess an alarm" id "6acd072d-431e-58
|
||||
name "Assess an alarm";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Capability;
|
||||
oa @oa_triage;
|
||||
sa @sa_triage;
|
||||
@@ -1114,7 +1044,6 @@ trace trace_oa_use_conversation "Use the reviewed repair conversation ↔ Use th
|
||||
name "Use the reviewed repair conversation";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Scenario;
|
||||
oa @oa_use_conversation;
|
||||
sa @sa_use_conversation;
|
||||
@@ -1131,7 +1060,6 @@ trace trace_oa_use_field "Use the field repair procedure ↔ Use the field repai
|
||||
name "Use the field repair procedure";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind Sequence;
|
||||
oa @oa_use_field;
|
||||
sa @sa_use_field;
|
||||
@@ -1148,7 +1076,6 @@ trace trace_oa_waiting "Awaiting repair ↔ Awaiting repair" id "0754be23-e4b8-5
|
||||
name "Awaiting repair";
|
||||
};
|
||||
};
|
||||
description "";
|
||||
kind State;
|
||||
oa @oa_waiting;
|
||||
sa @sa_waiting;
|
||||
|
||||
@@ -1,21 +1,9 @@
|
||||
diagram oa_allocation_view "1 · OA responsibility and repair traffic" id "103ea62c-ac56-5827-94e7-cf09bca96ccc" {
|
||||
description "Teaching view: positions and filters do not change ownership or exchange identities.";
|
||||
layer Oa;
|
||||
projection Allocation;
|
||||
routes [];
|
||||
view_options {
|
||||
coverage "All";
|
||||
exchange_labels "Name";
|
||||
hidden_edges [];
|
||||
participant_categories "All";
|
||||
relation_kinds "All";
|
||||
work_categories "All";
|
||||
work_contexts "All";
|
||||
};
|
||||
}
|
||||
|
||||
node oa_allocation_view_oa_assess id "5ae1c46d-59a3-50fd-8cc3-b292df21f951" {
|
||||
collapsed false;
|
||||
diagram @oa_allocation_view;
|
||||
element @oa_assess;
|
||||
position {
|
||||
@@ -29,7 +17,6 @@ node oa_allocation_view_oa_assess id "5ae1c46d-59a3-50fd-8cc3-b292df21f951" {
|
||||
}
|
||||
|
||||
node oa_allocation_view_oa_confirm id "edd74060-ac61-5450-a57c-a6577daa5d50" {
|
||||
collapsed false;
|
||||
diagram @oa_allocation_view;
|
||||
element @oa_confirm;
|
||||
position {
|
||||
@@ -43,7 +30,6 @@ node oa_allocation_view_oa_confirm id "edd74060-ac61-5450-a57c-a6577daa5d50" {
|
||||
}
|
||||
|
||||
node oa_allocation_view_oa_control id "3191e05c-1c7f-5f0e-beb0-5f3bded54c48" {
|
||||
collapsed false;
|
||||
diagram @oa_allocation_view;
|
||||
element @oa_control;
|
||||
position {
|
||||
@@ -57,7 +43,6 @@ node oa_allocation_view_oa_control id "3191e05c-1c7f-5f0e-beb0-5f3bded54c48" {
|
||||
}
|
||||
|
||||
node oa_allocation_view_oa_repair id "202ebe37-ddb4-5099-8ce9-ec3e895ab9e9" {
|
||||
collapsed false;
|
||||
diagram @oa_allocation_view;
|
||||
element @oa_repair;
|
||||
position {
|
||||
@@ -71,7 +56,6 @@ node oa_allocation_view_oa_repair id "202ebe37-ddb4-5099-8ce9-ec3e895ab9e9" {
|
||||
}
|
||||
|
||||
node oa_allocation_view_oa_reset id "7066f78c-9736-5349-b94a-0587331b980e" {
|
||||
collapsed false;
|
||||
diagram @oa_allocation_view;
|
||||
element @oa_reset;
|
||||
position {
|
||||
@@ -85,7 +69,6 @@ node oa_allocation_view_oa_reset id "7066f78c-9736-5349-b94a-0587331b980e" {
|
||||
}
|
||||
|
||||
node oa_allocation_view_oa_technician id "d27f28ef-f10a-5355-9a05-6f2fd39b7de6" {
|
||||
collapsed false;
|
||||
diagram @oa_allocation_view;
|
||||
element @oa_technician;
|
||||
position {
|
||||
|
||||
@@ -2,20 +2,9 @@ diagram sa_allocation_view "2 · SA service boundary and functions" id "35d3c24b
|
||||
description "Teaching view: positions and filters do not change ownership or exchange identities.";
|
||||
layer Sa;
|
||||
projection Allocation;
|
||||
routes [];
|
||||
view_options {
|
||||
coverage "All";
|
||||
exchange_labels "Name";
|
||||
hidden_edges [];
|
||||
participant_categories "All";
|
||||
relation_kinds "All";
|
||||
work_categories "All";
|
||||
work_contexts "All";
|
||||
};
|
||||
}
|
||||
|
||||
node sa_allocation_view_sa_assess id "60f6ad74-b69e-5aef-b832-f1bd60b903ae" {
|
||||
collapsed false;
|
||||
diagram @sa_allocation_view;
|
||||
element @sa_assess;
|
||||
position {
|
||||
@@ -29,7 +18,6 @@ node sa_allocation_view_sa_assess id "60f6ad74-b69e-5aef-b832-f1bd60b903ae" {
|
||||
}
|
||||
|
||||
node sa_allocation_view_sa_confirm id "7e3ba36f-bc68-5520-bdb9-77083bb7bba2" {
|
||||
collapsed false;
|
||||
diagram @sa_allocation_view;
|
||||
element @sa_confirm;
|
||||
position {
|
||||
@@ -43,7 +31,6 @@ node sa_allocation_view_sa_confirm id "7e3ba36f-bc68-5520-bdb9-77083bb7bba2" {
|
||||
}
|
||||
|
||||
node sa_allocation_view_sa_control id "8345c76a-8d85-5c31-902e-ec1cd33ed4a3" {
|
||||
collapsed false;
|
||||
diagram @sa_allocation_view;
|
||||
element @sa_control;
|
||||
position {
|
||||
@@ -57,7 +44,6 @@ node sa_allocation_view_sa_control id "8345c76a-8d85-5c31-902e-ec1cd33ed4a3" {
|
||||
}
|
||||
|
||||
node sa_allocation_view_sa_repair id "34630a18-41b0-5fdd-bff4-ee86e93e8651" {
|
||||
collapsed false;
|
||||
diagram @sa_allocation_view;
|
||||
element @sa_repair;
|
||||
position {
|
||||
@@ -71,7 +57,6 @@ node sa_allocation_view_sa_repair id "34630a18-41b0-5fdd-bff4-ee86e93e8651" {
|
||||
}
|
||||
|
||||
node sa_allocation_view_sa_reset id "73406244-ebd7-5995-86c7-e17c73c50b32" {
|
||||
collapsed false;
|
||||
diagram @sa_allocation_view;
|
||||
element @sa_reset;
|
||||
position {
|
||||
@@ -85,7 +70,6 @@ node sa_allocation_view_sa_reset id "73406244-ebd7-5995-86c7-e17c73c50b32" {
|
||||
}
|
||||
|
||||
node sa_allocation_view_sa_technician id "f7225d1c-e506-505d-bb20-916950269d4b" {
|
||||
collapsed false;
|
||||
diagram @sa_allocation_view;
|
||||
element @sa_technician;
|
||||
position {
|
||||
|
||||
@@ -2,20 +2,9 @@ diagram sa_capability_view "4 · SA mission and included capability" id "3e6ad19
|
||||
description "Teaching view: positions and filters do not change ownership or exchange identities.";
|
||||
layer Sa;
|
||||
projection Capabilities;
|
||||
routes [];
|
||||
view_options {
|
||||
coverage "All";
|
||||
exchange_labels "Name";
|
||||
hidden_edges [];
|
||||
participant_categories "All";
|
||||
relation_kinds "All";
|
||||
work_categories "All";
|
||||
work_contexts "All";
|
||||
};
|
||||
}
|
||||
|
||||
node sa_capability_view_sa_control id "41ddb68b-bd2b-5f91-82eb-efde01157828" {
|
||||
collapsed false;
|
||||
diagram @sa_capability_view;
|
||||
element @sa_control;
|
||||
position {
|
||||
@@ -29,7 +18,6 @@ node sa_capability_view_sa_control id "41ddb68b-bd2b-5f91-82eb-efde01157828" {
|
||||
}
|
||||
|
||||
node sa_capability_view_sa_mission id "4b814335-bf98-5b68-85d5-ea549766517a" {
|
||||
collapsed false;
|
||||
diagram @sa_capability_view;
|
||||
element @sa_mission;
|
||||
position {
|
||||
@@ -43,7 +31,6 @@ node sa_capability_view_sa_mission id "4b814335-bf98-5b68-85d5-ea549766517a" {
|
||||
}
|
||||
|
||||
node sa_capability_view_sa_restore id "d3bc13f9-7726-5280-83fe-63f391c45afb" {
|
||||
collapsed false;
|
||||
diagram @sa_capability_view;
|
||||
element @sa_restore;
|
||||
position {
|
||||
@@ -57,7 +44,6 @@ node sa_capability_view_sa_restore id "d3bc13f9-7726-5280-83fe-63f391c45afb" {
|
||||
}
|
||||
|
||||
node sa_capability_view_sa_triage id "069a3fb3-077c-59d8-91da-27b0665143c7" {
|
||||
collapsed false;
|
||||
diagram @sa_capability_view;
|
||||
element @sa_triage;
|
||||
position {
|
||||
|
||||
@@ -2,24 +2,18 @@ diagram sa_service_view "3 · SA service conversation only" id "50af4c9b-93ce-5f
|
||||
description "Teaching view: positions and filters do not change ownership or exchange identities.";
|
||||
layer Sa;
|
||||
projection Allocation;
|
||||
routes [];
|
||||
view_options {
|
||||
coverage "All";
|
||||
exchange_labels "NameAndItems";
|
||||
hidden_edges [];
|
||||
participant_categories {
|
||||
Any [@sa_contact_category];
|
||||
};
|
||||
relation_kinds "All";
|
||||
work_categories {
|
||||
Any [];
|
||||
};
|
||||
work_contexts "All";
|
||||
};
|
||||
}
|
||||
|
||||
node sa_service_view_sa_assess id "439f1e45-e5ed-567c-978b-4c93ef267db1" {
|
||||
collapsed false;
|
||||
diagram @sa_service_view;
|
||||
element @sa_assess;
|
||||
position {
|
||||
@@ -33,7 +27,6 @@ node sa_service_view_sa_assess id "439f1e45-e5ed-567c-978b-4c93ef267db1" {
|
||||
}
|
||||
|
||||
node sa_service_view_sa_confirm id "6f138672-149b-5f88-ab07-7fc413a42262" {
|
||||
collapsed false;
|
||||
diagram @sa_service_view;
|
||||
element @sa_confirm;
|
||||
position {
|
||||
@@ -47,7 +40,6 @@ node sa_service_view_sa_confirm id "6f138672-149b-5f88-ab07-7fc413a42262" {
|
||||
}
|
||||
|
||||
node sa_service_view_sa_control id "f53d4352-b042-56a6-8b3e-c51cd27254f9" {
|
||||
collapsed false;
|
||||
diagram @sa_service_view;
|
||||
element @sa_control;
|
||||
position {
|
||||
@@ -61,7 +53,6 @@ node sa_service_view_sa_control id "f53d4352-b042-56a6-8b3e-c51cd27254f9" {
|
||||
}
|
||||
|
||||
node sa_service_view_sa_repair id "ae36489d-6ec8-5f1c-b603-8b497227efba" {
|
||||
collapsed false;
|
||||
diagram @sa_service_view;
|
||||
element @sa_repair;
|
||||
position {
|
||||
@@ -75,7 +66,6 @@ node sa_service_view_sa_repair id "ae36489d-6ec8-5f1c-b603-8b497227efba" {
|
||||
}
|
||||
|
||||
node sa_service_view_sa_reset id "d52da4e6-40b7-5dbc-84fb-80c443711c69" {
|
||||
collapsed false;
|
||||
diagram @sa_service_view;
|
||||
element @sa_reset;
|
||||
position {
|
||||
@@ -89,7 +79,6 @@ node sa_service_view_sa_reset id "d52da4e6-40b7-5dbc-84fb-80c443711c69" {
|
||||
}
|
||||
|
||||
node sa_service_view_sa_technician id "40210589-69f7-5209-b329-10bb83cf615c" {
|
||||
collapsed false;
|
||||
diagram @sa_service_view;
|
||||
element @sa_technician;
|
||||
position {
|
||||
|
||||
@@ -6,20 +6,9 @@ diagram sa_state_view "5 · SA pressure supervision" id "30d5baf9-6581-5cb6-846a
|
||||
machine @sa_monitor;
|
||||
};
|
||||
};
|
||||
routes [];
|
||||
view_options {
|
||||
coverage "All";
|
||||
exchange_labels "Name";
|
||||
hidden_edges [];
|
||||
participant_categories "All";
|
||||
relation_kinds "All";
|
||||
work_categories "All";
|
||||
work_contexts "All";
|
||||
};
|
||||
}
|
||||
|
||||
node sa_state_view_sa_monitor id "a676fbb9-0833-59a8-98cf-a10d8f4b7434" {
|
||||
collapsed false;
|
||||
diagram @sa_state_view;
|
||||
element @sa_monitor;
|
||||
position {
|
||||
@@ -33,7 +22,6 @@ node sa_state_view_sa_monitor id "a676fbb9-0833-59a8-98cf-a10d8f4b7434" {
|
||||
}
|
||||
|
||||
node sa_state_view_sa_monitor_initial id "5e2326a0-0f6c-5f8d-8a21-fdded18a9281" {
|
||||
collapsed false;
|
||||
diagram @sa_state_view;
|
||||
element @sa_monitor_initial;
|
||||
position {
|
||||
@@ -47,7 +35,6 @@ node sa_state_view_sa_monitor_initial id "5e2326a0-0f6c-5f8d-8a21-fdded18a9281"
|
||||
}
|
||||
|
||||
node sa_state_view_sa_monitor_region id "55a74f91-2025-5001-8db8-9566b1dbe783" {
|
||||
collapsed false;
|
||||
diagram @sa_state_view;
|
||||
element @sa_monitor_region;
|
||||
position {
|
||||
@@ -61,7 +48,6 @@ node sa_state_view_sa_monitor_region id "55a74f91-2025-5001-8db8-9566b1dbe783" {
|
||||
}
|
||||
|
||||
node sa_state_view_sa_monitoring id "b3af7b04-5a45-5b82-ab69-7eada4b876f0" {
|
||||
collapsed false;
|
||||
diagram @sa_state_view;
|
||||
element @sa_monitoring;
|
||||
position {
|
||||
@@ -75,7 +61,6 @@ node sa_state_view_sa_monitoring id "b3af7b04-5a45-5b82-ab69-7eada4b876f0" {
|
||||
}
|
||||
|
||||
node sa_state_view_sa_waiting id "57acbb71-ca86-57fc-ae90-42dad195f0e0" {
|
||||
collapsed false;
|
||||
diagram @sa_state_view;
|
||||
element @sa_waiting;
|
||||
position {
|
||||
|
||||
@@ -456,3 +456,12 @@ Missing global and scoped parameter IDs remain explicit stabilization metadata,
|
||||
not new random identities assigned on each parse. Public source8 integration must
|
||||
thread the same accounting through the outer project and included files; this
|
||||
private checkpoint does not itself admit a complete version8 source bundle.
|
||||
|
||||
## Connection-end presentation preferences — 2026-09-22
|
||||
|
||||
Issue #33 uses optional side/fraction attachments on each view's `EdgeRoute`,
|
||||
with semantic Port precedence and shared shape-aware routing. Visual attachment
|
||||
editing remains separate from semantic reconnect. The [decision and evidence
|
||||
map](edge-attachments-20260922.md) records alternatives, lifecycle rules,
|
||||
independent falsifiers, evaluators and the Process/Scenario applicability limits.
|
||||
This is branch-specific work; it does not establish an integrated release.
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
# Connection attachment editing — issue 33
|
||||
|
||||
Branch-specific work from `3f9e6a18af96b5cd10940da4093be8da28b9c835` on
|
||||
`codex/edge-anchors-ytr83r-20260922`, owned by Codex-ytr83r/root.
|
||||
[Live scope and handoff](http://217.177.34.108:3000/sorokin.oleg.edu/ARCADIA-Studio/issues/33)
|
||||
remain in Gitea. This is not an integrated release checkpoint.
|
||||
|
||||
The user needs to move where a connection touches an element without changing
|
||||
the relationship. The existing ordinary route editor offered bends and labels;
|
||||
unported ends were selected from four side midpoints. SA semantic ports already
|
||||
had per-placement anchors. State endpoint handles instead performed semantic
|
||||
reconnect. These are different operations and remain distinct.
|
||||
|
||||
## Decision and alternatives
|
||||
|
||||
Store optional `source_attachment` and `target_attachment` values on `EdgeRoute`.
|
||||
Each contains a side and normalized fraction, interpreted against the actual
|
||||
projected shape. No additional semantic object, ID or reference is introduced.
|
||||
The precise format, geometry, Port precedence, folding, reconnect and reset rules
|
||||
are in [the normative language contract](../docs/language.rst); REST uses the
|
||||
same data and existing `SetEdgeRoute` transaction.
|
||||
|
||||
Compared alternatives:
|
||||
|
||||
- Absolute endpoint coordinates are easy to store but become detached from the
|
||||
owner after movement/resizing and duplicate derived geometry.
|
||||
- Reusing semantic Port anchors would invent ports for OA/state relationships
|
||||
and conflate each connection's presentation with a shared port's identity.
|
||||
- Binding an attachment to an additional semantic endpoint/placement reference
|
||||
would preserve the old owner's identity after reconnect, but needs stale
|
||||
reference cleanup and a dormant preference lifecycle without a current user
|
||||
need. The selected rule retains the edge-end preference across reconnect,
|
||||
just as authored bends are retained; it is documented, not inferred silently.
|
||||
|
||||
Fractions remain precise in source/API; pointer edits snap to hundredths.
|
||||
Automatic absence and authored values are distinct. Press/release without a
|
||||
drag, Escape, stale context, focus/camera/layout change and outside release do
|
||||
not author a preference. Returning within three screen pixels of the press
|
||||
restores the exact initial optional value, including its original precision.
|
||||
Successful editing changes one field in one route in one view in one history
|
||||
operation. Per-end reset preserves the other end, bends and label.
|
||||
|
||||
Ordinary diagrams expose eligible selected-end handles and explicit source/target
|
||||
menu choice for overlapping handles. State menus expose separately labelled
|
||||
Adjust attachment and Reconnect actions; selecting a transition still retains
|
||||
the existing reconnect gesture. Ports keep their existing movement policy.
|
||||
This work does not adopt or alter the separate #16 resize/port-capacity policy.
|
||||
|
||||
## Review-driven corrections and evaluators
|
||||
|
||||
Independent contract review identified projection-filtered Port markers as an
|
||||
unsafe authority: eligibility and routing now consult semantic endpoint identity.
|
||||
Attachment metadata participates in the route-preview cache key. Inset contours
|
||||
use actual lead lengths for path costs and pin fractions; shape scan-line
|
||||
intersections are shared by routing and pointer gestures. Side choice uses the
|
||||
nearest cardinal bounding segment, avoiding coincident circle scan-line points
|
||||
that otherwise retain the wrong exit direction. Hysteresis is capped by symbol
|
||||
size so small circles can change sides at low zoom; an explicit regression
|
||||
covers midpoint, overshoot and near-corner intent.
|
||||
|
||||
The first frozen gate exposed a remaining overshoot case: distances measured
|
||||
from far outside a small symbol converged, keeping the previous perpendicular
|
||||
side. Measuring side intent at the cursor clamped to the bounding box preserves
|
||||
the intended side under overshoot. The failed gate is retained separately.
|
||||
Valid Port-to-Port Item traces also omit projected port IDs; routing now resolves
|
||||
the semantic port before looking up its visible, owner-qualified marker. An
|
||||
actual trace regression checks moved anchors and unchanged trace metadata.
|
||||
|
||||
Coincident authored self ends previously threatened an empty candidate list.
|
||||
They retain their positions and receive an explicit loop warning. A critic then
|
||||
showed a fixed invented detour point could collide with a neighboring card even
|
||||
though the opposite side was clear. Computed detours now consider both directions
|
||||
and multiple bounded extents, preferring clear candidates. These points never
|
||||
become persisted hard pins. Geometry tests exercise blockers on either side.
|
||||
|
||||
Cross-review found ordinary attachment drags survived camera/focus/layout
|
||||
changes and outside release. They now carry a viewport stamp and cancel on those
|
||||
changes, with an actual pointer-event cancellation matrix. The same review
|
||||
reconciled return-to-press behavior across ordinary and State canvases.
|
||||
|
||||
Meaningful evaluators are `oa-core` integration tests `attachment_geometry`,
|
||||
`attachment_lifecycle`, `attachment_trace_ports`, `attachment_workshop`,
|
||||
`edge_attachments` and the existing routing/port/state suites; desktop ordinary
|
||||
attachment and State pointer/planner tests; server `http::edge_attachments`
|
||||
conditional transactions, exact source exports and restart. Tests compare complete
|
||||
projects/source where applicable, not just attachment fields. Native acceptance
|
||||
uses the [fixture and workflow plan](experiments/edge-attachments-20260922/native-plan.md).
|
||||
Final test/native results and exact tested commit belong in the publication
|
||||
handoff, not an unverified claim in this decision record.
|
||||
|
||||
## Applicability and integration limits
|
||||
|
||||
Process topology uses generated cards and qualified contextual addresses.
|
||||
Scenario endpoints derive from lifelines, activations, lifecycle and time/order
|
||||
notation. Neither renderer consumes ordinary `Diagram.routes`; their visual
|
||||
editing requires separate notation-aware contracts. This change does not claim
|
||||
to implement arbitrary attachment dragging there, or to resolve automatic
|
||||
arrangement (#32) or State bend editing (#23).
|
||||
|
||||
The base includes ordinary Text work, not the separately published Scenario
|
||||
spacing/inspector branches or the latest transition lifecycle branch. Integration
|
||||
owner #27 must compose actual pushed commits and verify the combined result.
|
||||
Linux/WSL verification remains paused by the user.
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user