From 97d42c1cefd9684eefb27f1860b9ce75d9701257 Mon Sep 17 00:00:00 2001 From: Joeri Exelmans Date: Tue, 21 Oct 2025 14:37:55 +0200 Subject: [PATCH] show internal events in side panel: --- src/App/AST.css | 10 ++++++++ src/App/App.tsx | 6 ++++- src/App/BottomPanel.tsx | 1 - src/App/ShowAST.tsx | 7 ++++++ src/VisualEditor/VisualEditor.tsx | 7 +++--- src/statecharts/parser.ts | 39 ++++++++++++++++--------------- todo.txt | 1 + 7 files changed, 47 insertions(+), 24 deletions(-) diff --git a/src/App/AST.css b/src/App/AST.css index 598bfd1..3e0b061 100644 --- a/src/App/AST.css +++ b/src/App/AST.css @@ -53,6 +53,16 @@ details > summary:hover { display: inline-block; } +.internalEvent { + border: 1px black solid; + border-radius: 6px; + margin-left: 4px; + padding-left: 2px; + padding-right: 2px; + background-color: rgb(255, 218, 252); + display: inline-block; +} + .inputEvent { border: 1px black solid; border-radius: 6px; diff --git a/src/App/App.tsx b/src/App/App.tsx index a044ffe..844209b 100644 --- a/src/App/App.tsx +++ b/src/App/App.tsx @@ -13,7 +13,7 @@ import Stack from "@mui/material/Stack"; import Box from "@mui/material/Box"; import { TopPanel } from "./TopPanel"; import { RTHistory } from "./RTHistory"; -import { ShowAST, ShowInputEvents, ShowOutputEvents } from "./ShowAST"; +import { ShowAST, ShowInputEvents, ShowInternalEvents, ShowOutputEvents } from "./ShowAST"; import { TraceableError } from "../statecharts/parser"; import { getKeyHandler } from "./shortcut_handler"; import { BottomPanel } from "./BottomPanel"; @@ -258,6 +258,10 @@ export function App() { input events + + internal events + + output events diff --git a/src/App/BottomPanel.tsx b/src/App/BottomPanel.tsx index 27d31ce..5cc03eb 100644 --- a/src/App/BottomPanel.tsx +++ b/src/App/BottomPanel.tsx @@ -4,7 +4,6 @@ import { TraceableError } from "../statecharts/parser"; import "./BottomPanel.css"; import head from "../head.svg" ; -import { usePersistentState } from "@/util/persistent_state"; import { PersistentDetails } from "./PersistentDetails"; import { DigitalWatch } from "@/Plant/DigitalWatch/DigitalWatch"; diff --git a/src/App/ShowAST.tsx b/src/App/ShowAST.tsx index 232f48f..c858005 100644 --- a/src/App/ShowAST.tsx +++ b/src/App/ShowAST.tsx @@ -106,6 +106,13 @@ export function ShowInputEvents({inputEvents, onRaise, disabled}: {inputEvents: ) } +export function ShowInternalEvents(props: {internalEvents: EventTrigger[]}) { + return [...props.internalEvents].map(({event, paramName}) => { + return <>
{event}{paramName===undefined?<>:<>({paramName})}
; + }); +} + + export function ShowOutputEvents(props: {outputEvents: Set}) { return [...props.outputEvents].map(eventName => { return <>
{eventName}
; diff --git a/src/VisualEditor/VisualEditor.tsx b/src/VisualEditor/VisualEditor.tsx index e2c3d61..529a0b3 100644 --- a/src/VisualEditor/VisualEditor.tsx +++ b/src/VisualEditor/VisualEditor.tsx @@ -79,6 +79,8 @@ export function VisualEditor({state, setState, ast, setAST, rt, errors, setError const [dragging, setDragging] = useState(false); + console.log(ast); + // uid's of selected rountangles // const [selection, setSelection] = useState([]); const selection = state.selection || []; @@ -122,14 +124,13 @@ export function VisualEditor({state, setState, ast, setAST, rt, errors, setError useEffect(() => { // bit of a hacky way to force the animation on fired transitions to replay, if the new 'rt' contains the same fired transitions as the previous one requestAnimationFrame(() => { - console.log('rt changed'); document.querySelectorAll(".arrow.fired").forEach(el => { + // @ts-ignore el.style.animation = 'none'; requestAnimationFrame(() => { + // @ts-ignore el.style.animation = ''; }) - setTimeout(() => { - }, 10); // <- small timeout seems to be necessary or the animation won't restart }); }) }, [rt]); diff --git a/src/statecharts/parser.ts b/src/statecharts/parser.ts index 8a64763..a148b2d 100644 --- a/src/statecharts/parser.ts +++ b/src/statecharts/parser.ts @@ -286,25 +286,6 @@ export function parseStatechart(state: VisualEditorState, conns: Connections): [ errors.push({shapeUid: text.uid, message: "triggerless transitions only allowed on pseudo-states"}); } } - - // raise-actions - for (const action of parsed.actions) { - if (action.kind === "raise") { - const {event} = action; - if (event.startsWith("_")) { - // internalEvents.add(event); - } - else { - outputEvents.add(event); - } - } - } - - // collect variables - variables = variables.union(findVariables(parsed.guard)); - for (const action of parsed.actions) { - variables = variables.union(findVariablesAction(action)); - } } } else { @@ -334,6 +315,26 @@ export function parseStatechart(state: VisualEditorState, conns: Connections): [ belongsToState.comments.push([text.uid, parsed.text]); } } + + if (parsed.kind === "transitionLabel") { + // collect output events + for (const action of parsed.actions) { + if (action.kind === "raise") { + const {event} = action; + if (event.startsWith("_")) { + // internalEvents.add({event: event}); + } + else { + outputEvents.add(event); + } + } + } + // collect variables + variables = variables.union(findVariables(parsed.guard)); + for (const action of parsed.actions) { + variables = variables.union(findVariablesAction(action)); + } + } } for (const transition of uid2Transition.values()) { diff --git a/todo.txt b/todo.txt index 66c42c3..6578174 100644 --- a/todo.txt +++ b/todo.txt @@ -28,6 +28,7 @@ TODO - must have: + - event parameters on output / internal events - explicit order of: - outgoing transitions - regions in AND-state