From 1f6947c8a21de591f5f492081e48fd65e4224928 Mon Sep 17 00:00:00 2001 From: Jette Petzold Date: Fri, 29 Sep 2023 13:47:03 +0200 Subject: [PATCH] single opoints of failure can be shown --- .../fta/diagram/fta-diagram-generator.ts | 12 +++++++++--- .../fta/fta-message-handler.ts | 9 +++++++++ .../fta/fta-synthesis-options.ts | 16 ++++++++++++++-- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/extension/src-language-server/fta/diagram/fta-diagram-generator.ts b/extension/src-language-server/fta/diagram/fta-diagram-generator.ts index 369d7a80..fc894f84 100644 --- a/extension/src-language-server/fta/diagram/fta-diagram-generator.ts +++ b/extension/src-language-server/fta/diagram/fta-diagram-generator.ts @@ -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"; @@ -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, diff --git a/extension/src-language-server/fta/fta-message-handler.ts b/extension/src-language-server/fta/fta-message-handler.ts index b10cc3b1..0a2c6791 100644 --- a/extension/src-language-server/fta/fta-message-handler.ts +++ b/extension/src-language-server/fta/fta-message-handler.ts @@ -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 }; diff --git a/extension/src-language-server/fta/fta-synthesis-options.ts b/extension/src-language-server/fta/fta-synthesis-options.ts index bb85b06f..df433e10 100644 --- a/extension/src-language-server/fta/fta-synthesis-options.ts +++ b/extension/src-language-server/fta/fta-synthesis-options.ts @@ -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: { @@ -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]; @@ -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; @@ -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; + } }