From a2a4696fdbd6440269d576aeba7b25b2ea40d9bf Mon Sep 17 00:00:00 2001
From: Kristóf Marussy <kristof@marussy.com>
Date: Tue, 12 Sep 2023 21:59:50 +0200
Subject: feat: connect model generator to UI

---
 subprojects/frontend/src/index.tsx | 102 ++++++++++++++++++++++++++++++-------
 1 file changed, 84 insertions(+), 18 deletions(-)

(limited to 'subprojects/frontend/src/index.tsx')

diff --git a/subprojects/frontend/src/index.tsx b/subprojects/frontend/src/index.tsx
index e8a22e82..4b251a23 100644
--- a/subprojects/frontend/src/index.tsx
+++ b/subprojects/frontend/src/index.tsx
@@ -16,35 +16,101 @@ import RootStore from './RootStore';
 (window as unknown as { fixViteIssue: unknown }).fixViteIssue = styled;
 
 const initialValue = `% Metamodel
-class Person {
-    contains Post[] posts opposite author
-    Person[] friend opposite friend
+
+abstract class CompositeElement {
+    contains Region[] regions
+}
+
+class Region {
+    contains Vertex[] vertices opposite region
+}
+
+abstract class Vertex {
+    container Region region opposite vertices
+    contains Transition[] outgoingTransition opposite source
+    Transition[] incomingTransition opposite target
 }
 
-class Post {
-    container Person author opposite posts
-    Post replyTo
+class Transition {
+    container Vertex source opposite outgoingTransition
+    Vertex target opposite incomingTransition
 }
 
+abstract class Pseudostate extends Vertex.
+
+abstract class RegularState extends Vertex.
+
+class Entry extends Pseudostate.
+
+class Exit extends Pseudostate.
+
+class Choice extends Pseudostate.
+
+class FinalState extends RegularState.
+
+class State extends RegularState, CompositeElement.
+
+class Statechart extends CompositeElement.
+
 % Constraints
-error replyToNotFriend(Post x, Post y) <->
-    replyTo(x, y),
-    author(x, xAuthor),
-    author(y, yAuthor),
-    xAuthor != yAuthor,
-    !friend(xAuthor, yAuthor).
 
-error replyToCycle(Post x) <-> replyTo+(x, x).
+%% Entry
+
+pred entryInRegion(Region r, Entry e) <->
+    vertices(r, e).
+
+error noEntryInRegion(Region r) <->
+    !entryInRegion(r, _).
+
+error multipleEntryInRegion(Region r) <->
+    entryInRegion(r, e1),
+    entryInRegion(r, e2),
+    e1 != e2.
+
+error incomingToEntry(Transition t, Entry e) <->
+    target(t, e).
+
+error noOutgoingTransitionFromEntry(Entry e) <->
+    !source(_, e).
+
+error multipleTransitionFromEntry(Entry e, Transition t1, Transition t2) <->
+    outgoingTransition(e, t1),
+    outgoingTransition(e, t2),
+    t1 != t2.
+
+%% Exit
+
+error outgoingFromExit(Transition t, Exit e) <->
+    source(t, e).
+
+%% Final
+
+error outgoingFromFinal(Transition t, FinalState e) <->
+    source(t, e).
+
+%% State vs Region
+
+pred stateInRegion(Region r, State s) <->
+    vertices(r, s).
+
+error noStateInRegion(Region r) <->
+    !stateInRegion(r, _).
+
+%% Choice
+
+error choiceHasNoOutgoing(Choice c) <->
+    !source(_, c).
+
+error choiceHasNoIncoming(Choice c) <->
+    !target(_, c).
 
 % Instance model
-friend(a, b).
-author(p1, a).
-author(p2, b).
 
-!author(Post::new, a).
+Statechart(sct).
 
 % Scope
-scope Post = 10..15, Person += 0.
+
+scope node = 20..30, Region = 2..*, Choice = 1..*, Statechart += 0.
 `;
 
 configure({
-- 
cgit v1.2.3-54-g00ecf

