Skip to content

Commit ac33da3

Browse files
authored
[MPQEditor] Use MPQCircleSelector (#1538)
This commit implements usage of MPQCircleSelector for manual mixed precision quantization task. ONE-vscode-DCO-1.0-Signed-off-by: s.malakhov <[email protected]>
1 parent 6332265 commit ac33da3

File tree

1 file changed

+114
-2
lines changed

1 file changed

+114
-2
lines changed

src/MPQEditor/MPQEditor.ts

+114-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,17 @@ import { Logger } from "../Utils/Logger";
2525
import { getNonce } from "../Utils/external/Nonce";
2626
import { getUri } from "../Utils/external/Uri";
2727
import { MPQData } from "./MPQData";
28-
29-
export class MPQEditorProvider implements vscode.CustomTextEditorProvider {
28+
import {
29+
MPQSelectionPanel,
30+
MPQSelectionEvent,
31+
MPQSelectionCmdCloseArgs,
32+
MPQSelectionCmdOpenArgs,
33+
MPQSelectionCmdLayersChangedArgs,
34+
} from "./MPQCircleSelector";
35+
36+
export class MPQEditorProvider
37+
implements vscode.CustomTextEditorProvider, MPQSelectionEvent
38+
{
3039
public static readonly viewType = "one.editor.mpq";
3140
public static readonly fileExtension = ".mpq.json";
3241

@@ -319,6 +328,12 @@ export class MPQEditorProvider implements vscode.CustomTextEditorProvider {
319328
case "removeLayer":
320329
this.handleRemoveLayerFromLayers(e.name, document);
321330
break;
331+
case "showModelNodes":
332+
this.handleShowModelNodes(document, webviewPanel);
333+
break;
334+
case "toggleCircleGraphIsShown":
335+
this.toggleCircleGraphIsShown(e.show, document, webviewPanel);
336+
break;
322337
default:
323338
break;
324339
}
@@ -397,6 +412,20 @@ export class MPQEditorProvider implements vscode.CustomTextEditorProvider {
397412
e.document.uri.toString() === document.uri.toString()
398413
) {
399414
this.updateWebview(document, webviewPanel.webview);
415+
416+
{
417+
// synchronize circle view
418+
const args: MPQSelectionCmdLayersChangedArgs = {
419+
modelPath: this.getModelFilePath(document),
420+
document: document,
421+
names: this._mpqDataMap[document.uri.toString()].getLayers(),
422+
};
423+
vscode.commands.executeCommand(
424+
MPQSelectionPanel.cmdChanged,
425+
args,
426+
this
427+
);
428+
}
400429
}
401430
}
402431
);
@@ -414,6 +443,8 @@ export class MPQEditorProvider implements vscode.CustomTextEditorProvider {
414443
);
415444

416445
webviewPanel.onDidDispose(() => {
446+
this.closeModelGraphView(document);
447+
417448
changeDocumentSubscription.dispose();
418449
while (this._disposables.length) {
419450
const x = this._disposables.pop();
@@ -544,4 +575,85 @@ export class MPQEditorProvider implements vscode.CustomTextEditorProvider {
544575
);
545576
await vscode.workspace.applyEdit(edit);
546577
}
578+
579+
/**
580+
* @brief Called when selection changed in SelectionView
581+
*/
582+
onSelection(names: string[], document: vscode.TextDocument): void {
583+
let docUri = document.uri.toString();
584+
this._mpqDataMap[docUri].setLayers(names);
585+
this.updateDocument(document);
586+
}
587+
588+
/**
589+
* @brief Called when MPQCircleSelector was closed
590+
*/
591+
onClosed(panel: vscode.WebviewPanel): void {
592+
panel.webview.postMessage({
593+
type: "modelGraphIsShown",
594+
shown: false,
595+
});
596+
}
597+
598+
/**
599+
* @brief Called when MPQCircleSelector was opened
600+
*/
601+
onOpened(panel: vscode.WebviewPanel): void {
602+
panel.webview.postMessage({
603+
type: "modelGraphIsShown",
604+
shown: true,
605+
});
606+
}
607+
608+
/**
609+
* @brief Close MPQCircleSelector
610+
*/
611+
private closeModelGraphView(document: vscode.TextDocument): void {
612+
const args: MPQSelectionCmdCloseArgs = {
613+
modelPath: this.getModelFilePath(document),
614+
document: document,
615+
};
616+
vscode.commands.executeCommand(MPQSelectionPanel.cmdClose, args);
617+
}
618+
619+
/**
620+
* @brief Open MPQCircleSelector panel
621+
*/
622+
private showCircleModelGraph(
623+
document: vscode.TextDocument,
624+
webviewPanel: vscode.WebviewPanel
625+
) {
626+
const args: MPQSelectionCmdOpenArgs = {
627+
modelPath: this.getModelFilePath(document),
628+
document: document,
629+
names: this._mpqDataMap[document.uri.toString()].getLayers(),
630+
panel: webviewPanel,
631+
};
632+
vscode.commands.executeCommand(MPQSelectionPanel.cmdOpen, args, this);
633+
}
634+
635+
/**
636+
* @brief Called when webview requests to Show Model Graph
637+
*/
638+
private handleShowModelNodes(
639+
document: vscode.TextDocument,
640+
webviewPanel: vscode.WebviewPanel
641+
) {
642+
this.showCircleModelGraph(document, webviewPanel);
643+
}
644+
645+
/**
646+
* @brief Called when webview toggles whether Model Graph is shown
647+
*/
648+
private toggleCircleGraphIsShown(
649+
show: boolean,
650+
document: vscode.TextDocument,
651+
webviewPanel: vscode.WebviewPanel
652+
) {
653+
if (show) {
654+
this.showCircleModelGraph(document, webviewPanel);
655+
} else {
656+
this.closeModelGraphView(document);
657+
}
658+
}
547659
}

0 commit comments

Comments
 (0)