Skip to content

Commit

Permalink
revision (extension)
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakae committed Sep 25, 2023
1 parent 6064b42 commit c85553d
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ import { namedFtaElement } from "../utils";
* @param allNodes All nodes in the fault tree.
* @returns the minimal cut sets for a fault tree.
*/
export function determineMinimalCutSet(allNodes: AstNode[]): Set<namedFtaElement>[] {
export function determineMinimalCutSets(allNodes: AstNode[]): Set<namedFtaElement>[] {
// TODO: add minimal flag (could reduce computation cost)
const allCutSets = generateCutSetsForFT(allNodes);
const allCutSets = determineCutSetsForFT(allNodes);

// Cut sets are minimal if removing one element destroys the cut set
// If cut set contains another cut set from the array, remove it since it is not minimal
Expand Down Expand Up @@ -71,7 +71,7 @@ function checkMinimalCutSet(cutSet: Set<namedFtaElement>, allCutSets: Set<namedF
* @param allNodes All nodes of the fault tree.
* @returns the cut sets of the fault tree.
*/
export function generateCutSetsForFT(allNodes: AstNode[]): Set<namedFtaElement>[] {
export function determineCutSetsForFT(allNodes: AstNode[]): Set<namedFtaElement>[] {
/* Idea:
Start from the top event.
Get the only child of top event (will always be only one) as our starting node.
Expand Down
9 changes: 4 additions & 5 deletions extension/src-language-server/fta/fta-message-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import { LangiumSprottySharedServices } from "langium-sprotty";
import { Connection } from "vscode-languageserver";
import { getFTAModel } from "../utils";
import { determineMinimalCutSet, generateCutSetsForFT } from "./analysis/fta-cutSet-calculator";
import { determineMinimalCutSets, determineCutSetsForFT } from "./analysis/fta-cutSet-calculator";
import { FtaServices } from "./fta-module";
import { cutSetsToString } from "./utils";

Expand All @@ -44,14 +44,13 @@ function addCutSetsHandler(connection: Connection, sharedServices: LangiumSprott
connection.onRequest("generate/getCutSets", async (uri: string) => {
const model = await getFTAModel(uri, sharedServices);
const nodes = [model.topEvent, ...model.components, ...model.conditions, ...model.gates];
const cutSets = generateCutSetsForFT(nodes);
const cutSets = determineCutSetsForFT(nodes);
return cutSetsToString(cutSets);
});

connection.onRequest("generate/getMinimalCutSets", async (uri: string) => {
const model = await getFTAModel(uri, sharedServices);
const nodes = [model.topEvent, ...model.components, ...model.conditions, ...model.gates];
const minimalCutSets = determineMinimalCutSet(nodes);
return cutSetsToString(minimalCutSets, true);
const minimalCutSets = determineMinimalCutSets(nodes);
return cutSetsToString(minimalCutSets);
});
}
23 changes: 11 additions & 12 deletions extension/src-language-server/fta/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ import { Component, Condition, Gate, TopEvent } from "../generated/ast";
export type namedFtaElement = Component | Condition | Gate | TopEvent;

/**
* Translates the given {@code cutSets} to a string.
* @param cutSets The cut sets to translate.
* @param minimal Determines whether the given {@code cutSets} are minimal.
* @returns a string that contains every cut set.
* Translates the cut sets in the given {@code cutSets} to lists.
* @param cutSets The list containing the cut sets to translate.
* @returns a list containing the cut sets in {@code cutSets} as a list.
*/
export function cutSetsToString(cutSets: Set<namedFtaElement>[], minimal?: boolean): string {
let text = `The resulting ${cutSets.length}`;
if (minimal) {
text += ` minimal`;
export function cutSetsToString(cutSets: Set<namedFtaElement>[]): string[][] {
const result: string[][] = [];
for (const set of cutSets) {
const newSet: string[] = [];
set.forEach((element) => newSet.push(element.name));
result.push(newSet);
}
text += ` cut sets are:\n`;
text += `[${cutSets.map((cutSet) => `[${[...cutSet].map((element) => element.name).join(", ")}]`).join(",\n")}]`;
return text;
}
return result;
}
4 changes: 1 addition & 3 deletions extension/src-webview/stpa-views.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ import { IView, IViewArgs, Point, PolylineEdgeView, RectangularNodeView, Renderi
import { DISymbol } from './di.symbols';
import { collectAllChildren } from './helper-methods';
import { ColorStyleOption, DifferentFormsOption, RenderOptionsRegistry } from './options/render-options-registry';
import { CSEdge, CS_EDGE_TYPE, CS_NODE_TYPE, EdgeType, PARENT_TYPE, STPAAspect, STPAEdge, STPANode, STPA_EDGE_TYPE, STPA_INTERMEDIATE_EDGE_TYPE, STPA_NODE_TYPE } from './stpa-model';
import { CSEdge, CS_EDGE_TYPE, EdgeType, STPAAspect, STPAEdge, STPANode, STPA_EDGE_TYPE, STPA_INTERMEDIATE_EDGE_TYPE } from './stpa-model';
import { renderCircle, renderDiamond, renderHexagon, renderMirroredTriangle, renderPentagon, renderRectangle, renderRoundedRectangle, renderTrapez, renderTriangle } from './views-rendering';


/** Determines if path/aspect highlighting is currently on. */
let highlighting: boolean;


@injectable()
export class PolylineArrowEdgeView extends PolylineEdgeView {

Expand Down
81 changes: 40 additions & 41 deletions extension/src-webview/views-rendering.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* http://rtsys.informatik.uni-kiel.de/kieler
*
* Copyright 2021 by
* Copyright 2021-2023 by
* + Kiel University
* + Department of Computer Science
* + Real-Time and Embedded Systems Group
Expand All @@ -21,7 +21,7 @@ import { SNode, svg } from 'sprotty';

/**
* Creates a circle for {@code node}.
* @param node The node whch should be represented by a circle.
* @param node The node that should be represented by a circle.
* @returns A circle for {@code node}.
*/
export function renderCircle(node: SNode): VNode {
Expand All @@ -33,7 +33,7 @@ export function renderCircle(node: SNode): VNode {

/**
* Creates a rectangle for {@code node}.
* @param node The node whch should be represented by a rectangle.
* @param node The node that should be represented by a rectangle.
* @returns A rectangle for {@code node}.
*/
export function renderRectangle(node: SNode): VNode {
Expand All @@ -45,7 +45,7 @@ export function renderRectangle(node: SNode): VNode {

/**
* Creates a rounded rectangle for {@code node}.
* @param node The node whch should be represented by a rounded rectangle.
* @param node The node that should be represented by a rounded rectangle.
* @returns A rounded rectangle for {@code node}.
*/
export function renderRoundedRectangle(node: SNode): VNode {
Expand All @@ -59,7 +59,7 @@ export function renderRoundedRectangle(node: SNode): VNode {

/**
* Creates a triangle for {@code node}.
* @param node The node whch should be represented by a triangle.
* @param node The node that should be represented by a triangle.
* @returns A triangle for {@code node}.
*/
export function renderTriangle(node: SNode): VNode {
Expand All @@ -76,7 +76,7 @@ export function renderTriangle(node: SNode): VNode {

/**
* Creates a mirrored triangle for {@code node}.
* @param node The node whch should be represented by a mirrored triangle.
* @param node The node that should be represented by a mirrored triangle.
* @returns A mrrored triangle for {@code node}.
*/
export function renderMirroredTriangle(node: SNode): VNode {
Expand All @@ -93,7 +93,7 @@ export function renderMirroredTriangle(node: SNode): VNode {

/**
* Creates a trapez for {@code node}.
* @param node The node whch should be represented by a trapez.
* @param node The node that should be represented by a trapez.
* @returns A trapez for {@code node}.
*/
export function renderTrapez(node: SNode): VNode {
Expand All @@ -112,7 +112,7 @@ export function renderTrapez(node: SNode): VNode {

/**
* Creates a diamond for {@code node}.
* @param node The node whch should be represented by a diamond.
* @param node The node that should be represented by a diamond.
* @returns A diamond for {@code node}.
*/
export function renderDiamond(node: SNode): VNode {
Expand All @@ -131,7 +131,7 @@ export function renderDiamond(node: SNode): VNode {

/**
* Creates a pentagon for {@code node}.
* @param node The node whch should be represented by a pentagon.
* @param node The node that should be represented by a pentagon.
* @returns A pentagon for {@code node}.
*/
export function renderPentagon(node: SNode): VNode {
Expand All @@ -152,7 +152,7 @@ export function renderPentagon(node: SNode): VNode {

/**
* Creates a hexagon for {@code node}.
* @param node The node whch should be represented by a hexagon.
* @param node The node that should be represented by a hexagon.
* @returns A hexagon for {@code node}.
*/
export function renderHexagon(node: SNode): VNode {
Expand All @@ -172,89 +172,88 @@ export function renderHexagon(node: SNode): VNode {

/**
* Creates an And-Gate for {@code node}.
* @param node The node whch should be represented by an And-Gate.
* @param node The node that should be represented by an And-Gate.
* @returns An And-Gate for {@code node}.
*/
export function renderAndGate(node:SNode): VNode{
export function renderAndGate(node: SNode): VNode {
const leftX = 0;
const rightX = Math.max(node.size.width, 0);
const midX = Math.max(node.size.width, 0) / 2.0;
const botY = Math.max(node.size.height, 0);
const midY = Math.max(node.size.height, 0) / 2.0;
const topY = 0;
const d = 'M' + leftX + " " + botY + " L " + leftX + " " + midY + " C " + leftX + " " + topY + " " + rightX + " " + topY + " " + rightX + " " + midY +
" L " + rightX + " " + botY + 'Z';
const d = 'M' + leftX + " " + botY + " L " + leftX + " " + midY + " C " + leftX + " " + topY + " " + rightX + " "
+ topY + " " + rightX + " " + midY + " L " + rightX + " " + botY + 'Z';

return <path
d = {d}
return <path
d={d}
/>;
}

/**
* Creates an Or-Gate for {@code node}.
* @param node The node whch should be represented by an Or-Gate.
* @param node The node that should be represented by an Or-Gate.
* @returns An Or-Gate for {@code node}.
*/
export function renderOrGate(node:SNode): VNode{
export function renderOrGate(node: SNode): VNode {
const leftX = 0;
const rightX = Math.max(node.size.width, 0);
const midX = rightX / 2.0;
const botY = Math.max(node.size.height, 0);
const nearBotY = Math.max(node.size.height, 0) - (Math.max(node.size.height, 0) / 10.0);
const nearBotY = Math.max(node.size.height, 0) - (Math.max(node.size.height, 0) / 10.0);
const midY = Math.max(node.size.height, 0) / 2;
const topY = 0;
const d = 'M' + leftX + " " + botY + " L " + leftX + " " + midY + " C " + midX + " " + topY + " "+ midX + " " + topY + " " + rightX + " " + midY +
" L " + rightX + " " + botY + " L " + midX + " " + nearBotY + " Z ";
const d = 'M' + leftX + " " + botY + " L " + leftX + " " + midY + " C " + midX + " " + topY + " " + midX + " "
+ topY + " " + rightX + " " + midY + " L " + rightX + " " + botY + " L " + midX + " " + nearBotY + " Z ";

return <path
d= {d}
/>
d={d}
/>;
}

/**
* Creates an Kn-Gate for {@code node}.
* @param node The node whch should be represented by an Kn-Gate.
* @param node The node that should be represented by an Kn-Gate.
* @returns An Kn-Gate for {@code node}.
*/
export function renderKnGate(node:SNode, k:number, n:number): VNode{
export function renderKnGate(node: SNode, k: number, n: number): VNode {
const leftX = 0;
const rightX = Math.max(node.size.width, 0);
const midX = rightX / 2.0;
const botY = Math.max(node.size.height, 0);
const nearBotY = Math.max(node.size.height, 0) - (Math.max(node.size.height, 0) / 10.0);
const nearBotY = Math.max(node.size.height, 0) - (Math.max(node.size.height, 0) / 10.0);
const midY = Math.max(node.size.height, 0) / 2;
const topY = 0;
const d = 'M' + leftX + " " + botY + " L " + leftX + " " + midY + " C " + midX + " " + topY + " "+ midX + " " + topY + " " + rightX + " " + midY +
" L " + rightX + " " + botY + " L " + midX + " " + nearBotY + " Z ";
const d = 'M' + leftX + " " + botY + " L " + leftX + " " + midY + " C " + midX + " " + topY + " " + midX + " "
+ topY + " " + rightX + " " + midY + " L " + rightX + " " + botY + " L " + midX + " " + nearBotY + " Z ";

return (
<g>
<path d={d} />
<text x={midX -7.0} y={botY-5} text-anchor="middle" class-fta-text={true}>
{`${k}/${n}`}
</text>
<path d={d} />
<text x={midX - 7.0} y={botY - 5} text-anchor="middle" class-fta-text={true}>
{`${k}/${n}`}
</text>
</g>
);
);
}

/**
* Creates an Inhibit-Gate for {@code node}.
* @param node The node whch should be represented by an Inhibit-Gate.
* @param node The node that should be represented by an Inhibit-Gate.
* @returns An Inhibit-Gate for {@code node}.
*/
export function renderInhibitGate(node:SNode): VNode{
export function renderInhibitGate(node: SNode): VNode {
const leftX = 0;
const midX = Math.max(node.size.width, 0) / 2.0 ;
const midX = Math.max(node.size.width, 0) / 2.0;
const rightX = Math.max(node.size.width, 0);
const lowestY = Math.max(node.size.height, 0);
const lowY = Math.max(node.size.height, 0) - (Math.max(node.size.height, 0) / 4.0);
const highY = Math.max(node.size.height, 0) / 4.0;
const highestY = 0;

const d = 'M' + leftX + " " + lowY + " L " + leftX + " " + highY + " L " + midX + " " + highestY + " L " + rightX + " " + highY +
" L " + rightX + " " + lowY + " L " + midX + " " + lowestY + "Z";
const d = 'M' + leftX + " " + lowY + " L " + leftX + " " + highY + " L " + midX + " " + highestY + " L " + rightX
+ " " + highY + " L " + rightX + " " + lowY + " L " + midX + " " + lowestY + "Z";

return <path
d= {d}
/>
d={d}
/>;
}
2 changes: 1 addition & 1 deletion extension/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export namespace GenerateSVGsAction {
}
}

// TODO: better type for cut sets
// TODO: better type for cut sets?
/** Contains the cut sets for a fault tree */
export interface SendCutSetAction extends Action {
kind: typeof SendCutSetAction.KIND;
Expand Down
Loading

0 comments on commit c85553d

Please sign in to comment.