Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakae committed Sep 20, 2023
1 parent 4c68201 commit d166423
Show file tree
Hide file tree
Showing 13 changed files with 398 additions and 380 deletions.
202 changes: 106 additions & 96 deletions extension/src-language-server/fta/fta-cutSet-generator.ts

Large diffs are not rendered by default.

134 changes: 70 additions & 64 deletions extension/src-language-server/fta/fta-diagram-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,29 @@
* SPDX-License-Identifier: EPL-2.0
*/

import { AstNode } from 'langium';
import { GeneratorContext, IdCache, LangiumDiagramGenerator } from 'langium-sprotty';
import { SLabel, SModelElement, SModelRoot } from 'sprotty-protocol';
import { Component, Condition, Gate, ModelFTA, TopEvent, isComponent, isCondition, isGate, isKNGate } from '../generated/ast';
import { FTAEdge, FTANode } from './fta-interfaces';
import { FTA_EDGE_TYPE, FTA_NODE_TYPE, TREE_TYPE } from './fta-model';
import { FtaServices } from './fta-module';
import { getAllGateTypes, getFTNodeType, getTargets } from './fta-utils';


export class FtaDiagramGenerator extends LangiumDiagramGenerator{

allNodes:AstNode[];
import { AstNode } from "langium";
import { GeneratorContext, IdCache, LangiumDiagramGenerator } from "langium-sprotty";
import { SLabel, SModelElement, SModelRoot } from "sprotty-protocol";
import {
Component,
Condition,
Gate,
ModelFTA,
TopEvent,
isComponent,
isCondition,
isGate,
isKNGate,
} from "../generated/ast";
import { FTAEdge, FTANode } from "./fta-interfaces";
import { FTA_EDGE_TYPE, FTA_NODE_TYPE, TREE_TYPE } from "./fta-model";
import { FtaServices } from "./fta-module";
import { getAllGateTypes, getFTNodeType, getTargets } from "./fta-utils";

export class FtaDiagramGenerator extends LangiumDiagramGenerator {
allNodes: AstNode[];
idCache: IdCache<AstNode>;
constructor(services: FtaServices){
constructor(services: FtaServices) {
super(services);
}

Expand All @@ -43,71 +51,66 @@ export class FtaDiagramGenerator extends LangiumDiagramGenerator{
const model: ModelFTA = document.parseResult.value;
//set filter for later maybe


let ftaChildren: SModelElement[] = model.components?.map(comps => this.generateFTANode(comps, args));
let ftaChildren: SModelElement[] = model.components?.map((comps) => this.generateFTANode(comps, args));

//returns a Map with the gate types as the key and all instances of that type as the value.
const allGates: Map<string, AstNode[]> = getAllGateTypes(model.gates);

//first create the ftaNode for the topevent, conditions and all gates
ftaChildren = ftaChildren.concat([
this.generateFTANode(model.topEvent, args),
...model.conditions?.map(cond => this.generateFTANode(cond,args)).flat(1)
...model.conditions?.map((cond) => this.generateFTANode(cond, args)).flat(1),
]);
allGates.forEach((value:AstNode[]) => {

allGates.forEach((value: AstNode[]) => {
ftaChildren = ftaChildren.concat([
...value?.map(gates => this.generateFTANode(gates as Gate,args)).flat(1),
...value?.map((gates) => this.generateFTANode(gates as Gate, args)).flat(1),
]);
});

//after that create the edges of the gates and the top event
allGates.forEach((value:AstNode[]) => {
allGates.forEach((value: AstNode[]) => {
ftaChildren = ftaChildren.concat([
...value?.map(gates => this.generateEdgesForFTANode(gates,args)).flat(1),
...value?.map((gates) => this.generateEdgesForFTANode(gates, args)).flat(1),
]);
});

ftaChildren = ftaChildren.concat([...this.generateEdgesForFTANode(model.topEvent, args),]);


ftaChildren = ftaChildren.concat([...this.generateEdgesForFTANode(model.topEvent, args)]);

this.allNodes = model.components;
this.allNodes = this.allNodes.concat(model.topEvent, ...model.conditions);
allGates.forEach((value:AstNode[]) => {
allGates.forEach((value: AstNode[]) => {
this.allNodes = this.allNodes.concat(...value);
});

this.idCache = args.idCache;



return {
type: 'graph',
id: 'root',
type: "graph",
id: "root",
children: [
{
type: TREE_TYPE,
id: 'faultTree',
children: ftaChildren
}
]
id: "faultTree",
children: ftaChildren,
},
],
};

}

/**
* Getter method for every FTANode in the Fault Tree.
* @returns every FTANode in the Fault Tree.
*/
public getNodes():AstNode[]{
public getNodes(): AstNode[] {
return this.allNodes;
}

/**
* Getter method for the idCache to get the ids for every node.
* @returns the idCache of generator context.
*/
public getCache():IdCache<AstNode>{
public getCache(): IdCache<AstNode> {
return this.idCache;
}

Expand All @@ -127,12 +130,11 @@ export class FtaDiagramGenerator extends LangiumDiagramGenerator{
const targetId = idCache.getId(target);
const edgeId = idCache.uniqueId(`${sourceId}:-:${targetId}`, undefined);
if (sourceId && targetId) {
const e = this.generateFTAEdge(edgeId, sourceId, targetId, '', args);
const e = this.generateFTAEdge(edgeId, sourceId, targetId, "", args);
elements.push(e);
}
}
return elements;

}

/**
Expand All @@ -144,15 +146,21 @@ export class FtaDiagramGenerator extends LangiumDiagramGenerator{
* @param param4 GeneratorContext of the FTA model.
* @returns an FTAEdge.
*/
private generateFTAEdge(edgeId: string, sourceId: string, targetId: string, label: string, { idCache }: GeneratorContext<ModelFTA>): FTAEdge {
private generateFTAEdge(
edgeId: string,
sourceId: string,
targetId: string,
label: string,
{ idCache }: GeneratorContext<ModelFTA>
): FTAEdge {
let children: SModelElement[] = [];
if (label !== '') {
if (label !== "") {
children = [
<SLabel>{
type: 'label:xref',
id: idCache.uniqueId(edgeId + '.label'),
text: label
}
type: "label:xref",
id: idCache.uniqueId(edgeId + ".label"),
text: label,
},
];
}
return {
Expand All @@ -173,24 +181,23 @@ export class FtaDiagramGenerator extends LangiumDiagramGenerator{
*/
private generateFTANode(node: TopEvent | Gate | Component | Condition, args: GeneratorContext<ModelFTA>): FTANode {
const idCache = args.idCache;

const nodeId = idCache.uniqueId(node.name, node);

const children: SModelElement[] = [
<SLabel>{
type: 'label',
id: idCache.uniqueId(nodeId + '.label'),
text: node.name
}
type: "label",
id: idCache.uniqueId(nodeId + ".label"),
text: node.name,
},
];

let desc = "";
if(isComponent(node) || isCondition(node)){
if (isComponent(node) || isCondition(node)) {
desc = node.description;
}


if(isGate(node) && isKNGate(node.type)){
if (isGate(node) && isKNGate(node.type)) {
return {
type: FTA_NODE_TYPE,
id: nodeId,
Expand All @@ -200,31 +207,30 @@ export class FtaDiagramGenerator extends LangiumDiagramGenerator{
highlight: true,
k: node.type.k,
n: node.type.children.length,
layout: 'stack',
layout: "stack",
layoutOptions: {
paddingTop: 10.0,
paddingBottom: 10.0,
paddngLeft: 10.0,
paddingRight: 10.0
}
paddingRight: 10.0,
},
};
}else{
} else {
return {
type: FTA_NODE_TYPE,
id: nodeId,
nodeType: getFTNodeType(node),
description: desc,
children: children,
highlight: true,
layout: 'stack',
layout: "stack",
layoutOptions: {
paddingTop: 10.0,
paddingBottom: 10.0,
paddngLeft: 10.0,
paddingRight: 10.0
}
paddingRight: 10.0,
},
};
}

}
}
}
28 changes: 13 additions & 15 deletions extension/src-language-server/fta/fta-layout-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,28 @@
* SPDX-License-Identifier: EPL-2.0
*/

import { LayoutOptions } from 'elkjs';
import { DefaultLayoutConfigurator } from 'sprotty-elk/lib/elk-layout';
import { SGraph, SModelIndex, SNode } from 'sprotty-protocol';
import { LayoutOptions } from "elkjs";
import { DefaultLayoutConfigurator } from "sprotty-elk/lib/elk-layout";
import { SGraph, SModelIndex, SNode } from "sprotty-protocol";

export class FtaLayoutConfigurator extends DefaultLayoutConfigurator {


protected graphOptions(sgraph: SGraph, index: SModelIndex): LayoutOptions {
//options for the entire graph.
return {
'org.eclipse.elk.spacing.nodeNode': '30.0',
'org.eclipse.elk.direction': 'DOWN',
"org.eclipse.elk.spacing.nodeNode": "30.0",
"org.eclipse.elk.direction": "DOWN",
};
}

protected nodeOptions(snode: SNode, index: SModelIndex): LayoutOptions | undefined {
//options for the nodes.
//options for the nodes.
return {
'org.eclipse.elk.nodeLabels.placement': "INSIDE V_CENTER H_CENTER",
"org.eclipse.elk.nodeLabels.placement": "INSIDE V_CENTER H_CENTER",

//'org.eclipse.elk.nodeSize.constraints': 'NODE_LABELS',
'org.eclipse.elk.direction' : 'DOWN',
'org.eclipse.elk.layered.nodePlacement.strategy': 'NETWORK_SIMPLEX',

};
}
}
"org.eclipse.elk.direction": "DOWN",
"org.eclipse.elk.layered.nodePlacement.strategy": "NETWORK_SIMPLEX",
};
}
}
32 changes: 14 additions & 18 deletions extension/src-language-server/fta/fta-message-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,43 @@

import { Connection } from "vscode-languageserver";
import { FtaDiagramGenerator } from "./fta-diagram-generator";
import { FtaServices } from './fta-module';
import { cutSetToString, minimalCutSetToString } from './fta-utils';

import { FtaServices } from "./fta-module";
import { cutSetToString, minimalCutSetToString } from "./fta-utils";

/**
* Adds handlers for notifications regarding fta.
* @param connection
* @param ftaServices
* @param connection
* @param ftaServices
*/
export function addFTANotificationHandler(connection: Connection, ftaServices: FtaServices): void {
addCutSetsHandler(connection, ftaServices);

}


/**
* Adds handlers for requests regarding the cut sets.
* @param connection
* @param ftaServices
* @param connection
* @param ftaServices
*/
function addCutSetsHandler(connection: Connection, ftaServices: FtaServices):void{
connection.onRequest('generate/getCutSets', () =>{
const diagramGenerator = (ftaServices.diagram.DiagramGenerator) as FtaDiagramGenerator;
function addCutSetsHandler(connection: Connection, ftaServices: FtaServices): void {
connection.onRequest("generate/getCutSets", () => {
const diagramGenerator = ftaServices.diagram.DiagramGenerator as FtaDiagramGenerator;
const nodes = diagramGenerator.getNodes();
const idCache = diagramGenerator.getCache();

const cutSets = ftaServices.bdd.Bdd.generateCutSets(nodes, idCache);
const cutSetsToString = cutSetToString(cutSets, idCache);

return cutSetsToString;
});
});

connection.onRequest('generate/getMinimalCutSets', () =>{
const diagramGenerator = (ftaServices.diagram.DiagramGenerator) as FtaDiagramGenerator;
connection.onRequest("generate/getMinimalCutSets", () => {
const diagramGenerator = ftaServices.diagram.DiagramGenerator as FtaDiagramGenerator;
const nodes = diagramGenerator.getNodes();
const idCache = diagramGenerator.getCache();

const minimalCutSets = ftaServices.bdd.Bdd.determineMinimalCutSet(nodes, idCache);
const minCutSetToString = minimalCutSetToString(minimalCutSets, idCache);

return minCutSetToString;
});
}

12 changes: 5 additions & 7 deletions extension/src-language-server/fta/fta-model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* KIELER - Kiel Integrated Environment for Layout Eclipse RichClient
*
Expand All @@ -17,10 +16,9 @@
*/

//diagram elements
export const FTA_NODE_TYPE = 'node:fta';
export const FTA_EDGE_TYPE = 'edge:fta';
export const TREE_TYPE = 'node:tree';

export const FTA_NODE_TYPE = "node:fta";
export const FTA_EDGE_TYPE = "edge:fta";
export const TREE_TYPE = "node:tree";

/**
* The different types of nodes of FTA.
Expand All @@ -33,5 +31,5 @@ export enum FTNodeType {
OR,
KN,
INHIBIT,
UNDEFINED
}
UNDEFINED,
}
Loading

0 comments on commit d166423

Please sign in to comment.