Skip to content

Commit

Permalink
fixed input/output translation to graph
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakae committed Feb 15, 2024
1 parent c8eb27a commit 0816bf1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions extension/src-language-server/stpa/diagram/diagram-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ export class StpaDiagramGenerator extends LangiumDiagramGenerator {
edges.push(...this.translateCommandsToEdges(node.actions, EdgeType.CONTROL_ACTION, args));
// create edges representing feedback
edges.push(...this.translateCommandsToEdges(node.feedbacks, EdgeType.FEEDBACK, args));
// FIXME: input/output does not work anymore
// create edges representing the other inputs
edges.push(...this.translateIOToEdgeAndNode(node.inputs, node, EdgeType.INPUT, args));
// create edges representing the other outputs
Expand Down Expand Up @@ -519,7 +518,7 @@ export class StpaDiagramGenerator extends LangiumDiagramGenerator {
* @param node The node of the inputs or outputs.
* @param edgetype The type of the edge (input or output).
* @param args GeneratorContext of the STPA model.
* @returns a list of edges representing the inputs or outputs.
* @returns a list of edges representing the inputs or outputs that should be added at the top level.
*/
protected translateIOToEdgeAndNode(
io: Command[],
Expand Down Expand Up @@ -582,7 +581,13 @@ export class StpaDiagramGenerator extends LangiumDiagramGenerator {
console.error("EdgeType is not INPUT or OUTPUT");
break;
}
return graphComponents;
if (node.$container?.$type === "Graph") {
return graphComponents;
} else {
const parent = this.idToSNode.get(idCache.getId(node.$container)!);
const invisibleChild = parent?.children?.find(child => child.type === CS_INVISIBLE_SUBCOMPONENT_TYPE);
invisibleChild?.children?.push(...graphComponents);
}
}
return [];
}
Expand Down
2 changes: 1 addition & 1 deletion extension/src-language-server/stpa/diagram/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export function getAncestors(node: Node): (Node | Graph)[] {
export function sortPorts(nodes: CSNode[]): void {
for (const node of nodes) {
// sort the ports of the children
const children = node.children?.filter(child => child.type.startsWith("node")) as CSNode[];
const children = node.children?.filter(child => child.type.startsWith("node")) as CSNode[] ?? [];
sortPorts(children);

// separate the ports from the other children
Expand Down

0 comments on commit 0816bf1

Please sign in to comment.