Skip to content

Commit

Permalink
single opoints of failure can be shown
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakae committed Sep 29, 2023
1 parent 1909d09 commit 1f6947c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { GeneratorContext, IdCache, LangiumDiagramGenerator } from "langium-spro
import { SLabel, SModelElement, SModelRoot } from "sprotty-protocol";
import { ModelFTA, isComponent, isCondition, isKNGate } from "../../generated/ast";
import { FtaServices } from "../fta-module";
import { FtaSynthesisOptions, noCutSet } from "../fta-synthesis-options";
import { FtaSynthesisOptions, noCutSet, spofsSet } from "../fta-synthesis-options";
import { namedFtaElement } from "../utils";
import { FTAEdge, FTANode } from "./fta-interfaces";
import { FTA_EDGE_TYPE, FTA_GRAPH_TYPE, FTA_NODE_TYPE } from "./fta-model";
Expand Down Expand Up @@ -121,8 +121,14 @@ export class FtaDiagramGenerator extends LangiumDiagramGenerator {
const children: SModelElement[] = this.createNodeLabel(node.name, nodeId, idCache);
const description = isComponent(node) || isCondition(node) ? node.description : "";
const set = this.options.getCutSet();
const includedInCutSet = set !== noCutSet.id ? set.includes(node.name) : false;
const notConnected = set !== noCutSet.id ? !includedInCutSet : false;
let includedInCutSet = set !== noCutSet.id ? set.includes(node.name) : false;
let notConnected = set !== noCutSet.id ? !includedInCutSet : false;
// single points of failure should be shown
if (set === spofsSet.id) {
const spofs = this.options.getSpofs();
includedInCutSet = spofs.includes(node.name);
notConnected = false;
}

const ftNode = {
type: FTA_NODE_TYPE,
Expand Down
9 changes: 9 additions & 0 deletions extension/src-language-server/fta/fta-message-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ async function cutSetsRequested(
const model = (await getModel(uri, sharedServices)) as ModelFTA;
const nodes = [model.topEvent, ...model.components, ...model.conditions, ...model.gates];
const cutSets = minimal ? determineMinimalCutSets(nodes) : determineCutSetsForFT(nodes);
// determine single points of failure
const spofs: string[] = [];
for (const cutSet of cutSets) {
if (cutSet.size === 1) {
spofs.push([...cutSet][0].name);
}
}
ftaServices.options.SynthesisOptions.setSpofs(spofs);
// create dropdown values
const cutSetsString = cutSetsToString(cutSets);
const dropdownValues = cutSetsString.map((cutSet) => {
return { displayName: cutSet, id: cutSet };
Expand Down
16 changes: 14 additions & 2 deletions extension/src-language-server/fta/fta-synthesis-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { SynthesisOptions } from "../synthesis-options";
const cutSetsID = "cutSets";

export const noCutSet = { displayName: "---", id: "---" };
/* Single Point of Failure */
export const spofsSet = { displayName: "SPoFs", id: "SPoFs" };

const cutSets: ValuedSynthesisOption = {
synthesisOption: {
Expand All @@ -31,12 +33,13 @@ const cutSets: ValuedSynthesisOption = {
availableValues: [noCutSet],
initialValue: noCutSet.id,
currentValue: noCutSet.id,
values: [],
values: [noCutSet],
} as DropDownOption,
currentValue: noCutSet.id,
};

export class FtaSynthesisOptions extends SynthesisOptions {
protected spofs: string[];
constructor() {
super();
this.options = [cutSets];
Expand All @@ -49,7 +52,8 @@ export class FtaSynthesisOptions extends SynthesisOptions {
updateCutSetsOption(values: { displayName: string; id: string }[]): void {
const option = this.getOption(cutSetsID);
if (option) {
(option.synthesisOption as DropDownOption).availableValues = [noCutSet, ...values];
(option.synthesisOption as DropDownOption).availableValues = [noCutSet, spofsSet, ...values];
(option.synthesisOption as DropDownOption).values = [noCutSet, spofsSet, ...values];
// if the last selected cut set is not available anymore, set the option to no cut set
if (!values.find((val) => val.id === (option.synthesisOption as DropDownOption).currentId)) {
(option.synthesisOption as DropDownOption).currentId = noCutSet.id;
Expand All @@ -72,4 +76,12 @@ export class FtaSynthesisOptions extends SynthesisOptions {
getCutSet(): string {
return this.getOption(cutSetsID)?.currentValue;
}

setSpofs(spofs: string[]): void {
this.spofs = spofs;
}

getSpofs(): string[] {
return this.spofs;
}
}

0 comments on commit 1f6947c

Please sign in to comment.