Skip to content

Commit

Permalink
mka feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakae committed Oct 13, 2023
1 parent 03f25ab commit 6d6485c
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 40 deletions.
2 changes: 1 addition & 1 deletion extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@
"editor/title": [
{
"command": "pasta.diagram.open",
"when": "editorLangId == 'stpa' || editorLangId == 'fta'",
"when": "editorLangId in pasta.languages",
"group": "navigation"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ 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 {
protected graphOptions(_sgraph: SGraph, _index: SModelIndex): LayoutOptions {
return {
"org.eclipse.elk.direction": "DOWN",
"org.eclipse.elk.layered.nodePlacement.strategy": "NETWORK_SIMPLEX",
};
}

protected nodeOptions(snode: SNode, index: SModelIndex): LayoutOptions | undefined {
protected nodeOptions(_snode: SNode, _index: SModelIndex): LayoutOptions | undefined {
return {
"org.eclipse.elk.nodeLabels.placement": "INSIDE V_CENTER H_CENTER",
};
Expand Down
4 changes: 2 additions & 2 deletions extension/src-webview/css/fta-diagram.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
}

.fta-text{
fill: var(--fta-kn-dark);
stroke-width: 0.5;
fill: dimgrey;
stroke-width: 0;
font-size: 10px;
}

Expand Down
1 change: 0 additions & 1 deletion extension/src-webview/options/render-options-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ export class RenderOptionsRegistry extends Registry {
handle(action: Action): void | Action | ICommand {
if (SetRenderOptionAction.isThisAction(action)) {
const option = this._renderOptions.get(action.id);

if (!option) {return;}
option.currentValue = action.value;
const sendAction = { kind: SendConfigAction.KIND, options: [{ id: action.id, value: action.value }] };
Expand Down
49 changes: 21 additions & 28 deletions extension/src-webview/views-rendering.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ export function renderOval(node: SNode): VNode {
cy={Math.max(node.size.height, 0) / 2.0}
rx={Math.max(nodeWidth, 0) / 2.0}
ry={Math.max(node.size.height, 0) / 2.0} />;
/* return <circle
r={Math.max(node.size.width, 0) / 2.0}
cx={Math.max(node.size.width, 0) / 2.0} cy={Math.max(node.size.height, 0) / 2.0}
/>; */
}

/**
Expand Down Expand Up @@ -73,9 +69,9 @@ export function renderTriangle(node: SNode): VNode {
const rightX = Math.max(node.size.width, 0);
const botY = Math.max(node.size.height, 0);
const topY = 0;
const d = 'M' + leftX + " " + botY + " L " + midX + " " + topY + " L " + rightX + " " + botY + 'Z';
const path = 'M' + leftX + " " + botY + " L " + midX + " " + topY + " L " + rightX + " " + botY + 'Z';
return <path
d={d}
d={path}
/>;
}

Expand All @@ -90,9 +86,9 @@ export function renderMirroredTriangle(node: SNode): VNode {
const rightX = Math.max(node.size.width, 0);
const botY = Math.max(node.size.height, 0);
const topY = 0;
const d = 'M' + leftX + " " + topY + " L " + midX + " " + botY + " L " + rightX + " " + topY + 'Z';
const path = 'M' + leftX + " " + topY + " L " + midX + " " + botY + " L " + rightX + " " + topY + 'Z';
return <path
d={d}
d={path}
/>;
}

Expand All @@ -108,10 +104,10 @@ export function renderTrapez(node: SNode): VNode {
const rightX = Math.max(node.size.width, 0);
const botY = Math.max(node.size.height, 0);
const topY = 0;
const d = 'M' + leftX + " " + botY + " L " + midX1 + " " + topY + " L " + midX2 + " " + topY
const path = 'M' + leftX + " " + botY + " L " + midX1 + " " + topY + " L " + midX2 + " " + topY
+ " L " + rightX + " " + botY + 'Z';
return <path
d={d}
d={path}
/>;
}

Expand All @@ -127,10 +123,10 @@ export function renderDiamond(node: SNode): VNode {
const topY = 0;
const midY = Math.max(node.size.height, 0) / 2.0;
const botY = Math.max(node.size.height, 0);
const d = 'M' + leftX + " " + midY + " L " + midX + " " + topY + " L " + rightX + " " + midY
const path = 'M' + leftX + " " + midY + " L " + midX + " " + topY + " L " + rightX + " " + midY
+ " L " + midX + " " + botY + 'Z';
return <path
d={d}
d={path}
/>;
}

Expand All @@ -148,10 +144,10 @@ export function renderPentagon(node: SNode): VNode {
const topY = 0;
const midY = Math.max(node.size.height, 0) / 3.0;
const botY = Math.max(node.size.height, 0);
const d = 'M' + startX + " " + botY + " L " + leftX + " " + midY + " L " + midX + " " + topY
const path = 'M' + startX + " " + botY + " L " + leftX + " " + midY + " L " + midX + " " + topY
+ " L " + rightX + " " + midY + " L " + endX + " " + botY + 'Z';
return <path
d={d}
d={path}
/>;
}

Expand All @@ -168,10 +164,10 @@ export function renderHexagon(node: SNode): VNode {
const topY = 0;
const midY = Math.max(node.size.height, 0) / 2.0;
const botY = Math.max(node.size.height, 0);
const d = 'M' + leftX + " " + midY + " L " + midX1 + " " + botY + " L " + midX2 + " " + botY
const path = 'M' + leftX + " " + midY + " L " + midX1 + " " + botY + " L " + midX2 + " " + botY
+ " L " + rightX + " " + midY + " L " + midX2 + " " + topY + " L " + midX1 + " " + topY + 'Z';
return <path
d={d}
d={path}
/>;
}

Expand All @@ -188,12 +184,10 @@ export function renderAndGate(node: SNode): VNode {
const midY = Math.max(node.size.height, 0) / 2.0;
const topY = 0;

const d = `M ${leftX}, ${midY} V ${botY} H ${rightX} V ${midY} C ${rightX}, ${midY} ${rightX}, ${topY} ${midX}, ${topY} ${leftX}, ${topY} ${leftX}, ${midY} ${leftX}, ${midY} Z`;
// 'M' + leftX + " " + midY + " V " + botY + " H " + rightX + " V " + midY + " C " + rightX + " " + midY + " " + rightX + " "
// + topY + " " + midX + " " + topY + " " + leftX + " " + topY + " " + leftX + " " + midY + " " + leftX + " " + midY + 'Z';
const path = `M ${leftX}, ${midY} V ${botY} H ${rightX} V ${midY} C ${rightX}, ${midY} ${rightX}, ${topY} ${midX}, ${topY} ${leftX}, ${topY} ${leftX}, ${midY} ${leftX}, ${midY} Z`;

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

Expand All @@ -210,11 +204,11 @@ export function renderOrGate(node: SNode): VNode {
const nearBotY = botY - 5;
const midY = Math.max(node.size.height, 0) / 2;
const topY = 0;
const d = `M${leftX},${midY} V ${botY}` + `C ${leftX}, ${botY} ${leftX+10}, ${nearBotY} ${midX}, ${nearBotY} ${rightX-10}, ${nearBotY} ${rightX}, ${botY} ${rightX}, ${botY}`
const path = `M${leftX},${midY} V ${botY}` + `C ${leftX}, ${botY} ${leftX+10}, ${nearBotY} ${midX}, ${nearBotY} ${rightX-10}, ${nearBotY} ${rightX}, ${botY} ${rightX}, ${botY}`
+ `V ${midY} A ${node.size.width},${node.size.height-10},${0},${0},${0},${midX},${topY} A ${node.size.width},${node.size.height-10},${0},${0},${0},${leftX},${midY} Z`;

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

Expand All @@ -231,13 +225,13 @@ export function renderKnGate(node: SNode, k: number, n: number): VNode {
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},${midY} V ${botY}` + `C ${leftX}, ${botY} ${leftX+10}, ${nearBotY} ${midX}, ${nearBotY} ${rightX-10}, ${nearBotY} ${rightX}, ${botY} ${rightX}, ${botY}`
const path = `M${leftX},${midY} V ${botY}` + `C ${leftX}, ${botY} ${leftX+10}, ${nearBotY} ${midX}, ${nearBotY} ${rightX-10}, ${nearBotY} ${rightX}, ${botY} ${rightX}, ${botY}`
+ `V ${midY} A ${node.size.width},${node.size.height-10},${0},${0},${0},${midX},${topY} A ${node.size.width},${node.size.height-10},${0},${0},${0},${leftX},${midY} Z`;

return (
<g>
<path d={d} />
<text x={midX - 7.0} y={botY - 5} text-anchor="middle" class-fta-text={true}>
<path d={path} />
<text x={midX - 7.0} y={botY - 4.5} text-anchor="middle" class-fta-text={true}>
{`${k}/${n}`}
</text>
</g>
Expand All @@ -258,10 +252,9 @@ export function renderInhibitGate(node: SNode): VNode {
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 path = `M${leftX},${lowY} L ${leftX} ${highY} L ${midX} ${highestY} L ${rightX} ${highY} L ${rightX} ${lowY} L ${midX} ${lowestY} Z`;

return <path
d={d}
d={path}
/>;
}
18 changes: 16 additions & 2 deletions extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ import { createOutputChannel, createQuickPickForWorkspaceOptions } from './utils

let languageClient: LanguageClient;

/**
* All file endings of the languages that are supported by pasta.
* The file ending should also be the language id, since it is also used to
* register document selectors in the language client.
*/
const supportedFileEndings = ['stpa', 'fta'];

export function activate(context: vscode.ExtensionContext): void {
vscode.window.showInformationMessage('Activating STPA extension');

Expand All @@ -40,6 +47,8 @@ export function activate(context: vscode.ExtensionContext): void {
}

languageClient = createLanguageClient(context);
// Create context key of supported languages
vscode.commands.executeCommand('setContext', 'pasta.languages', supportedFileEndings);

if (diagramMode === 'panel') {
// Set up webview panel manager for freestyle webviews
Expand All @@ -53,6 +62,7 @@ export function activate(context: vscode.ExtensionContext): void {
registerDefaultCommands(webviewPanelManager, context, { extensionPrefix: 'pasta' });
registerTextEditorSync(webviewPanelManager, context);
registerSTPACommands(webviewPanelManager, context, { extensionPrefix: 'pasta' });
registerFTACommands(webviewPanelManager, context, { extensionPrefix: 'pasta' });
}

if (diagramMode === 'editor') {
Expand Down Expand Up @@ -186,7 +196,9 @@ function registerSTPACommands(manager: StpaLspVscodeExtension, context: vscode.E
return formulas;
})
);
}

function registerFTACommands(manager: StpaLspVscodeExtension, context: vscode.ExtensionContext, options: { extensionPrefix: string; }): void {
// commands for computing and displaying the (minimal) cut sets of the fault tree.
context.subscriptions.push(
vscode.commands.registerCommand(options.extensionPrefix + ".fta.cutSets", async (uri: vscode.Uri) => {
Expand Down Expand Up @@ -228,8 +240,10 @@ function createLanguageClient(context: vscode.ExtensionContext): LanguageClient

// Options to control the language client
const clientOptions: LanguageClientOptions = {
documentSelector: [{ scheme: 'file', language: 'stpa' },
{ scheme: 'file', language: 'fta' }],
documentSelector: supportedFileEndings.map((ending) => ({
scheme: 'file',
language: ending,
})),
synchronize: {
// Notify the server about file changes to files contained in the workspace
fileEvents: fileSystemWatcher
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@
"@jridgewell/resolve-uri" "^3.0.3"
"@jridgewell/sourcemap-codec" "^1.4.10"

"@kieler/table-webview@^0.0.3":
version "0.0.3"
resolved "https://registry.yarnpkg.com/@kieler/table-webview/-/table-webview-0.0.3.tgz#33199d9b0d8cd88d0aad6d4230617b94942482aa"
integrity sha512-XiDfn/MwHzVEpXLWC5DT6Ysg/5Zke3GlbtjBDDPRD1mLFXIekOCxkGYAKu068djqSAg3hsoiIhwLwWBfm48VNQ==
"@kieler/table-webview@^0.0.4":
version "0.0.4"
resolved "https://registry.yarnpkg.com/@kieler/table-webview/-/table-webview-0.0.4.tgz#c68a0652423a3c5f74a635fc5432e1430f758ee3"
integrity sha512-ZUAdX8dUCq72UdpFJz61bPX8eoJqnRuiJBOIFgOb+NqUke13zo4QmkeapmgA4zSKFBx5GC6nhSDQvVr9CMD4AQ==
dependencies:
"@types/vscode" "^1.56.0"
reflect-metadata "^0.1.13"
Expand Down

0 comments on commit 6d6485c

Please sign in to comment.