Skip to content

Commit

Permalink
mka feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakae committed Sep 18, 2023
1 parent 5471d0d commit 7391c6b
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 103 deletions.
32 changes: 25 additions & 7 deletions extension/src-language-server/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,27 @@ import { elementWithName } from "./stpa/utils";
*/
export function addNotificationHandler(connection: Connection, shared: LangiumSprottySharedServices): void {
// diagram
connection.onNotification('diagram/selected', async (msg: {label: string, uri: string}) => {
connection.onNotification("diagram/selected", async (msg: { label: string; uri: string }) => {
// get the current model
const model = await getModel(msg.uri, shared);

// determine the range in the editor of the component identified by "label"
const range = getRangeOfNode(model, msg.label);
if (range) {
// notify extension to highlight the range in the editor
connection.sendNotification('editor/highlight', ({ startLine: range.start.line, startChar: range.start.character, endLine: range.end.line, endChar: range.end.character, uri: msg.uri }));
connection.sendNotification("editor/highlight", {
startLine: range.start.line,
startChar: range.start.character,
endLine: range.end.line,
endChar: range.end.character,
uri: msg.uri,
});
} else {
console.log("The selected UCA could not be found in the editor.");
}
});
}


/**
* Determines the range of the component identified by {@code label} in the editor,
* @param model The current STPA model.
Expand All @@ -52,16 +57,29 @@ export function addNotificationHandler(connection: Connection, shared: LangiumSp
*/
function getRangeOfNode(model: Model, label: string): Range | undefined {
let range: Range | undefined = undefined;
const elements: elementWithName[] = [...model.losses, ...model.hazards, ...model.hazards.flatMap(hazard => hazard.subComps), ...model.systemLevelConstraints, ...model.systemLevelConstraints.flatMap(constraint => constraint.subComps), ...model.responsibilities.flatMap(resp => resp.responsiblitiesForOneSystem),
...model.allUCAs.flatMap(ucas => ucas.providingUcas.concat(ucas.notProvidingUcas, ucas.wrongTimingUcas, ucas.continousUcas)), ...model.rules.flatMap(rule => rule.contexts), ...model.controllerConstraints, ...model.scenarios, ...model.safetyCons];
const elements: elementWithName[] = [
...model.losses,
...model.hazards,
...model.hazards.flatMap((hazard) => hazard.subComponents),
...model.systemLevelConstraints,
...model.systemLevelConstraints.flatMap((constraint) => constraint.subComponents),
...model.responsibilities.flatMap((resp) => resp.responsiblitiesForOneSystem),
...model.allUCAs.flatMap((ucas) =>
ucas.providingUcas.concat(ucas.notProvidingUcas, ucas.wrongTimingUcas, ucas.continousUcas)
),
...model.rules.flatMap((rule) => rule.contexts),
...model.controllerConstraints,
...model.scenarios,
...model.safetyCons,
];
if (model.controlStructure) {
elements.push(...model.controlStructure.nodes);
}
elements.forEach(component => {
elements.forEach((component) => {
if (component.name === label) {
range = component.$cstNode?.range;
return;
}
});
return range;
}
}
18 changes: 9 additions & 9 deletions extension/src-language-server/stpa.langium
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ entry Model:
('Hazards' hazards+=Hazard*)?
('SystemConstraints' systemLevelConstraints+=SystemConstraint*)?
('ControlStructure' controlStructure=Graph)?
('Responsibilities' responsibilities+=Resps*)?
('Responsibilities' responsibilities+=SystemResponsibilities*)?
(('UCAs' allUCAs+=ActionUCAs*) | ('Context-Table' rules+=Rule*))?
('DCAs' allDCAs+=DCARule*)?
('ControllerConstraints' controllerConstraints+=ContConstraint*)?
('ControllerConstraints' controllerConstraints+=ControllerConstraint*)?
('LossScenarios' scenarios+=LossScenario*)?
('SafetyRequirements' safetyCons+=SafetyConstraint*)?;

Expand All @@ -48,14 +48,14 @@ Loss:
Hazard:
name=SubID description=STRING
('['refs+=[Loss] (',' refs+=[Loss])*']')?
('{' (header=STRING? subComps+=Hazard+)*'}')?;
('{' (header=STRING? subComponents+=Hazard+)*'}')?;

SystemConstraint:
name=SubID description=STRING
'['
refs+=[Hazard:SubID] (',' refs+=[Hazard:SubID])*
']'
('{' (header=STRING? subComps+=SystemConstraint+)*'}')?;
('{' (header=STRING? subComponents+=SystemConstraint+)*'}')?;

Graph:
name=ID '{'(nodes+=Node /* | edges+=Edge */)*'}';
Expand All @@ -67,8 +67,8 @@ Node:
('processModel' '{'variables+=Variable*'}')?
('input' '[' inputs+=Command (',' inputs+=Command)* ']')?
('output' '[' outputs+=Command (',' outputs+=Command)* ']')?
('controlActions' '{'actions+=VE*'}')?
('feedback' '{'feedbacks+=VE*'}')?
('controlActions' '{'actions+=VerticalEdge*'}')?
('feedback' '{'feedbacks+=VerticalEdge*'}')?
'}';

/* Edge:
Expand All @@ -85,13 +85,13 @@ VariableValue:
firstValue=(QualifiedName | INT | 'MIN' | 'true' | 'false') (',' secondValue=(QualifiedName | INT | 'MAX'))?
secondParenthesis=(']'|')'))?;

VE:
VerticalEdge:
'[' comms+=Command (',' comms+=Command)* ']' '->' target=[Node];

Command:
name=ID label=STRING;

Resps:
SystemResponsibilities:
system=[Node] '{'responsiblitiesForOneSystem+=Responsibility*'}';

Responsibility:
Expand Down Expand Up @@ -123,7 +123,7 @@ DCARule:
DCAContext:
name=ID '['vars+=[Variable] '=' values+=QualifiedName (',' vars+=[Variable] '=' values+=QualifiedName)*']';

ContConstraint:
ControllerConstraint:
name=ID description=STRING '['refs+=[UCA] (',' refs+=[UCA])*']';

LossScenario:
Expand Down
8 changes: 4 additions & 4 deletions extension/src-language-server/stpa/ID-enforcer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,9 @@ export class IDEnforcer {
edits = edits.concat(edit.changes[this.currentUri]);
}
// rename children
if ((isHazard(element) || isSystemConstraint(element)) && element.subComps.length !== 0) {
if ((isHazard(element) || isSystemConstraint(element)) && element.subComponents.length !== 0) {
let index = 1;
for (const child of element.subComps) {
for (const child of element.subComponents) {
edits = edits.concat(await this.renameID(child, prefix + counter + ".", index));
index++;
}
Expand Down Expand Up @@ -380,8 +380,8 @@ export class IDEnforcer {
// check whether the children are affected
// if the children are affected, it must be checked whether they have again affected children
// otherwise the current elements are the affected ones
if (element.subComps.length !== 0 && element.subComps[0].$cstNode && element.subComps[0].$cstNode.offset <= offset) {
const modified = this.findAffectedSubComponents(element.subComps, element.name + ".", offset);
if (element.subComponents.length !== 0 && element.subComponents[0].$cstNode && element.subComponents[0].$cstNode.offset <= offset) {
const modified = this.findAffectedSubComponents(element.subComponents, element.name + ".", offset);
elements = modified.elements;
prefix = modified.prefix;
}
Expand Down
14 changes: 7 additions & 7 deletions extension/src-language-server/stpa/diagram/diagram-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
Model,
Node,
SystemConstraint,
VE,
VerticalEdge,
isContext,
isHazard,
isSystemConstraint,
Expand Down Expand Up @@ -128,7 +128,7 @@ export class StpaDiagramGenerator extends LangiumDiagramGenerator {
)
.flat(1),
...filteredModel.systemLevelConstraints
?.map((sc) => sc.subComps?.map((ssc) => this.generateEdgesForSTPANode(ssc, args)))
?.map((sc) => sc.subComponents?.map((ssc) => this.generateEdgesForSTPANode(ssc, args)))
.flat(2),
]);
}
Expand Down Expand Up @@ -296,7 +296,7 @@ export class StpaDiagramGenerator extends LangiumDiagramGenerator {
* @param args GeneratorContext of the STPA model.
* @returns A list of edges representing the commands.
*/
protected translateCommandsToEdges(commands: VE[], edgetype: EdgeType, args: GeneratorContext<Model>): CSEdge[] {
protected translateCommandsToEdges(commands: VerticalEdge[], edgetype: EdgeType, args: GeneratorContext<Model>): CSEdge[] {
const idCache = args.idCache;
const edges: CSEdge[] = [];
for (const edge of commands) {
Expand Down Expand Up @@ -495,16 +495,16 @@ export class StpaDiagramGenerator extends LangiumDiagramGenerator {
isContext(node) ? createUCAContextDescription(node) : node.description
);
// if the hierarchy option is true, the subcomponents are added as children to the parent
if (this.options.getHierarchy() && isHazard(node) && node.subComps.length !== 0) {
if (this.options.getHierarchy() && isHazard(node) && node.subComponents.length !== 0) {
// adds subhazards
children = children.concat(
node.subComps?.map((sc: Hazard) => this.generateSTPANode(sc, showDescription, args))
node.subComponents?.map((sc: Hazard) => this.generateSTPANode(sc, showDescription, args))
);
}
if (this.options.getHierarchy() && isSystemConstraint(node) && node.subComps.length !== 0) {
if (this.options.getHierarchy() && isSystemConstraint(node) && node.subComponents.length !== 0) {
// adds subconstraints
children = children.concat(
node.subComps?.map((sc: SystemConstraint) => this.generateSTPANode(sc, showDescription, args))
node.subComponents?.map((sc: SystemConstraint) => this.generateSTPANode(sc, showDescription, args))
);
}

Expand Down
8 changes: 4 additions & 4 deletions extension/src-language-server/stpa/diagram/filtering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

import {
ActionUCAs,
ContConstraint,
ControllerConstraint,
Graph,
Hazard,
Loss,
LossScenario,
Model,
Resps,
SystemResponsibilities,
Rule,
SafetyConstraint,
SystemConstraint,
Expand All @@ -37,9 +37,9 @@ export class CustomModel {
losses: Loss[] = [];
hazards: Hazard[] = [];
systemLevelConstraints: SystemConstraint[] = [];
responsibilities: Resps[] = [];
responsibilities: SystemResponsibilities[] = [];
allUCAs: ActionUCAs[] = [];
controllerConstraints: ContConstraint[] = [];
controllerConstraints: ControllerConstraint[] = [];
scenarios: LossScenario[] = [];
safetyCons: SafetyConstraint[] = [];
controlStructure?: Graph;
Expand Down
6 changes: 3 additions & 3 deletions extension/src-language-server/stpa/diagram/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { AstNode } from "langium";
import {
Context,
Node,
isContConstraint,
isControllerConstraint,
isContext,
isHazard,
isLoss,
Expand All @@ -42,7 +42,7 @@ import { groupValue } from "./synthesis-options";
export function getTargets(node: AstNode, hierarchy: boolean): AstNode[] {
if (node) {
const targets: AstNode[] = [];
if (isHazard(node) || isResponsibility(node) || isSystemConstraint(node) || isContConstraint(node) || isSafetyConstraint(node)) {
if (isHazard(node) || isResponsibility(node) || isSystemConstraint(node) || isControllerConstraint(node) || isSafetyConstraint(node)) {
for (const ref of node.refs) {
if (ref?.ref) { targets.push(ref.ref); }
}
Expand Down Expand Up @@ -239,7 +239,7 @@ export function getAspect(node: AstNode): STPAAspect {
return STPAAspect.UCA;
} else if (isResponsibility(node)) {
return STPAAspect.RESPONSIBILITY;
} else if (isContConstraint(node)) {
} else if (isControllerConstraint(node)) {
return STPAAspect.CONTROLLERCONSTRAINT;
} else if (isLossScenario(node)) {
return STPAAspect.SCENARIO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { AstNode, Reference } from "langium";
import { LangiumSprottySharedServices } from "langium-sprotty";
import {
ActionUCAs,
ContConstraint,
ControllerConstraint,
Hazard,
LossScenario,
Responsibility,
Expand Down Expand Up @@ -66,7 +66,7 @@ export async function createResultData(uri: string, shared: LangiumSprottyShared
});

// safety constraints
result.safetyCons = createResultComponents(model.safetyCons);
result.safetyConstraints = createResultComponents(model.safetyCons);

// responsibilities
model.responsibilities.forEach((component) => {
Expand Down Expand Up @@ -128,7 +128,7 @@ function createSingleListComponent(component: LossScenario | UCA): StpaComponent
* @returns the result components for the given {@code components}.
*/
function createResultComponents(
components: Hazard[] | SystemConstraint[] | ContConstraint[] | SafetyConstraint[] | Responsibility[]
components: Hazard[] | SystemConstraint[] | ControllerConstraint[] | SafetyConstraint[] | Responsibility[]
): StpaComponent[] {
const resultList: StpaComponent[] = [];
components.forEach((component) => {
Expand All @@ -146,7 +146,7 @@ function createHazardOrSystemConstraintComponents(components: Hazard[] | SystemC
const resultList: StpaComponent[] = [];
components.forEach((component) => {
const resultComponent = createSingleComponent(component);
resultComponent.subComponents = createHazardOrSystemConstraintComponents(component.subComps);
resultComponent.subComponents = createHazardOrSystemConstraintComponents(component.subComponents);
resultList.push(resultComponent);
});
return resultList;
Expand All @@ -158,7 +158,7 @@ function createHazardOrSystemConstraintComponents(components: Hazard[] | SystemC
* @returns the result component for the given {@code component}.
*/
function createSingleComponent(
component: Hazard | SystemConstraint | ContConstraint | SafetyConstraint | Responsibility
component: Hazard | SystemConstraint | ControllerConstraint | SafetyConstraint | Responsibility
): StpaComponent {
return {
id: component.name,
Expand Down
47 changes: 9 additions & 38 deletions extension/src-language-server/stpa/result-report/svg-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,34 +146,11 @@ export function setFilteredUcaGraphOptions(options: StpaSynthesisOptions, value:
options.setHideSafetyConstraints(true);
}

export function setUcaGraphOptions(options: StpaSynthesisOptions): void {
options.setShowRelationshipGraph(true);
options.setShowControlStructure(false);
options.setFilteringUCAs("all UCAs");
options.setHideSysCons(true);
options.setHideResps(false);
options.setHideUCAs(false);
options.setHideContCons(true);
options.setHideScenarios(true);
options.setHideSafetyConstraints(true);
}

/**
* Sets the values of {@code options} such that the relationship graph is reduced to the controller constraints without system-level constraints.
* Sets the values of {@code options} such that the relationship graph is reduced to the controller constraints without
* system-level constraints. The relationship graph is filtered based on {@code value} for the UCA filter.
* @param options The synthesis options.
*/
export function setControllerConstraintGraphOptions(options: StpaSynthesisOptions): void {
options.setShowRelationshipGraph(true);
options.setShowControlStructure(false);
options.setFilteringUCAs("all UCAs");
options.setHideSysCons(true);
options.setHideResps(false);
options.setHideUCAs(false);
options.setHideContCons(false);
options.setHideScenarios(true);
options.setHideSafetyConstraints(true);
}

export function setControllerConstraintWithFilteredUcaGraphOptions(options: StpaSynthesisOptions, value: string): void {
options.setShowRelationshipGraph(true);
options.setShowControlStructure(false);
Expand All @@ -187,21 +164,10 @@ export function setControllerConstraintWithFilteredUcaGraphOptions(options: Stpa
}

/**
* Sets the values of {@code options} such that the relationship graph is reduced to the loss scenarios without system-level constraints.
* Sets the values of {@code options} such that the relationship graph is reduced to the loss scenarios without
* system-level constraints. The relationship graph is filtered based on {@code value} for the UCA filter.
* @param options The synthesis options.
*/
function setScenarioGraphOptions(options: StpaSynthesisOptions): void {
options.setShowRelationshipGraph(true);
options.setShowControlStructure(false);
options.setFilteringUCAs("all UCAs");
options.setHideSysCons(true);
options.setHideResps(false);
options.setHideUCAs(false);
options.setHideContCons(false);
options.setHideScenarios(false);
options.setHideSafetyConstraints(true);
}

export function setScenarioWithFilteredUCAGraphOptions(options: StpaSynthesisOptions, value: string): void {
options.setShowRelationshipGraph(true);
options.setShowControlStructure(false);
Expand All @@ -215,6 +181,11 @@ export function setScenarioWithFilteredUCAGraphOptions(options: StpaSynthesisOpt
options.setHideSafetyConstraints(true);
}

/**
* Sets the values of {@code options} such that the relationship graph is reduced to the loss scenarios that are not
* connected to a UCA without system-level constraints.
* @param options The synthesis options.
*/
export function setScenarioWithNoUCAGraphOptions(options: StpaSynthesisOptions): void {
options.setShowRelationshipGraph(true);
options.setShowControlStructure(false);
Expand Down
Loading

0 comments on commit 7391c6b

Please sign in to comment.