完成 netlist 保存

This commit is contained in:
锦恢 2025-01-04 00:10:50 +08:00
parent 353794d99c
commit 0d7b5acf03
16 changed files with 184 additions and 22 deletions

View File

@ -104,5 +104,7 @@
"error.cannot-gen-netlist": "Netlist-Datei konnte nicht generiert werden!", "error.cannot-gen-netlist": "Netlist-Datei konnte nicht generiert werden!",
"info.common.confirm": "Bestätigen", "info.common.confirm": "Bestätigen",
"info.command.structure.reload-vscode": "Vscode neu starten", "info.command.structure.reload-vscode": "Vscode neu starten",
"error.look-up-log": "Fehlerprotokoll anzeigen" "error.look-up-log": "Fehlerprotokoll anzeigen",
"netlist.save-as-svg": "Als SVG speichern",
"svg-file": "SVG-Datei"
} }

View File

@ -104,5 +104,7 @@
"error.cannot-gen-netlist": "Unable to generate Netlist file!", "error.cannot-gen-netlist": "Unable to generate Netlist file!",
"info.common.confirm": "Confirm", "info.common.confirm": "Confirm",
"info.command.structure.reload-vscode": "Restart Vscode", "info.command.structure.reload-vscode": "Restart Vscode",
"error.look-up-log": "View error log" "error.look-up-log": "View error log",
"netlist.save-as-svg": "Save as SVG",
"svg-file": "SVG file"
} }

View File

@ -104,5 +104,7 @@
"error.cannot-gen-netlist": "ネットリストファイルを生成できません!", "error.cannot-gen-netlist": "ネットリストファイルを生成できません!",
"info.common.confirm": "確認", "info.common.confirm": "確認",
"info.command.structure.reload-vscode": "Vscodeを再起動", "info.command.structure.reload-vscode": "Vscodeを再起動",
"error.look-up-log": "エラーログを表示" "error.look-up-log": "エラーログを表示",
"netlist.save-as-svg": "SVGとして保存",
"svg-file": "SVGファイル"
} }

View File

@ -104,5 +104,7 @@
"error.cannot-gen-netlist": "无法生成 Netlist 文件!", "error.cannot-gen-netlist": "无法生成 Netlist 文件!",
"info.common.confirm": "确认", "info.common.confirm": "确认",
"info.command.structure.reload-vscode": "重启 Vscode", "info.command.structure.reload-vscode": "重启 Vscode",
"error.look-up-log": "查看错误日志" "error.look-up-log": "查看错误日志",
"netlist.save-as-svg": "保存为 Svg",
"svg-file": "svg 文件"
} }

View File

@ -104,5 +104,7 @@
"error.cannot-gen-netlist": "無法生成Netlist檔案", "error.cannot-gen-netlist": "無法生成Netlist檔案",
"info.common.confirm": "確認", "info.common.confirm": "確認",
"info.command.structure.reload-vscode": "重啟 Vscode", "info.command.structure.reload-vscode": "重啟 Vscode",
"error.look-up-log": "查看錯誤日誌" "error.look-up-log": "查看錯誤日誌",
"netlist.save-as-svg": "保存為Svg",
"svg-file": "SVG 檔案"
} }

26
package-lock.json generated
View File

@ -12,6 +12,7 @@
"bson": "^6.8.0", "bson": "^6.8.0",
"chokidar": "^4.0.1", "chokidar": "^4.0.1",
"minimatch": "^10.0.1", "minimatch": "^10.0.1",
"pako": "^2.1.0",
"puppeteer-core": "^19.4.1", "puppeteer-core": "^19.4.1",
"showdown": "^2.1.0", "showdown": "^2.1.0",
"state-machine-cat": "^9.2.5", "state-machine-cat": "^9.2.5",
@ -26,6 +27,7 @@
"devDependencies": { "devDependencies": {
"@types/mocha": "^10.0.0", "@types/mocha": "^10.0.0",
"@types/node": "16.x", "@types/node": "16.x",
"@types/pako": "^2.0.3",
"@types/showdown": "^2.0.0", "@types/showdown": "^2.0.0",
"@types/vscode": "^1.72.0", "@types/vscode": "^1.72.0",
"@typescript-eslint/eslint-plugin": "^5.42.0", "@typescript-eslint/eslint-plugin": "^5.42.0",
@ -37,7 +39,7 @@
"webpack-cli": "^5.1.4" "webpack-cli": "^5.1.4"
}, },
"engines": { "engines": {
"vscode": "^1.95.0" "vscode": "^1.94.0"
} }
}, },
"node_modules/@discoveryjs/json-ext": { "node_modules/@discoveryjs/json-ext": {
@ -386,6 +388,12 @@
"integrity": "sha512-3oJbGBUWuS6ahSnEq1eN2XrCyf4YsWI8OyCvo7c64zQJNplk3mO84t53o8lfTk+2ji59g5ycfc6qQ3fdHliHuA==", "integrity": "sha512-3oJbGBUWuS6ahSnEq1eN2XrCyf4YsWI8OyCvo7c64zQJNplk3mO84t53o8lfTk+2ji59g5ycfc6qQ3fdHliHuA==",
"devOptional": true "devOptional": true
}, },
"node_modules/@types/pako": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/@types/pako/-/pako-2.0.3.tgz",
"integrity": "sha512-bq0hMV9opAcrmE0Byyo0fY3Ew4tgOevJmQ9grUhpXQhYfyLJ1Kqg3P33JT5fdbT2AjeAjR51zqqVjAL/HMkx7Q==",
"dev": true
},
"node_modules/@types/semver": { "node_modules/@types/semver": {
"version": "7.3.13", "version": "7.3.13",
"resolved": "https://registry.npmmirror.com/@types/semver/-/semver-7.3.13.tgz", "resolved": "https://registry.npmmirror.com/@types/semver/-/semver-7.3.13.tgz",
@ -3092,6 +3100,11 @@
"resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.1.tgz", "resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.1.tgz",
"integrity": "sha512-UEZIS3/by4OC8vL3P2dTXRETpebLI2NiI5vIrjaD/5UtrkFX/tNbwjTSRAGC/+7CAo2pIcBaRgWmcBBHcsaCIw==" "integrity": "sha512-UEZIS3/by4OC8vL3P2dTXRETpebLI2NiI5vIrjaD/5UtrkFX/tNbwjTSRAGC/+7CAo2pIcBaRgWmcBBHcsaCIw=="
}, },
"node_modules/pako": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/pako/-/pako-2.1.0.tgz",
"integrity": "sha512-w+eufiZ1WuJYgPXbV/PO3NCMEc3xqylkKHzp8bxp1uW4qaSNQUkwmLLEc3kKsfz8lpV1F8Ht3U1Cm+9Srog2ug=="
},
"node_modules/parent-module": { "node_modules/parent-module": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmmirror.com/parent-module/-/parent-module-1.0.1.tgz", "resolved": "https://registry.npmmirror.com/parent-module/-/parent-module-1.0.1.tgz",
@ -4961,6 +4974,12 @@
"integrity": "sha512-3oJbGBUWuS6ahSnEq1eN2XrCyf4YsWI8OyCvo7c64zQJNplk3mO84t53o8lfTk+2ji59g5ycfc6qQ3fdHliHuA==", "integrity": "sha512-3oJbGBUWuS6ahSnEq1eN2XrCyf4YsWI8OyCvo7c64zQJNplk3mO84t53o8lfTk+2ji59g5ycfc6qQ3fdHliHuA==",
"devOptional": true "devOptional": true
}, },
"@types/pako": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/@types/pako/-/pako-2.0.3.tgz",
"integrity": "sha512-bq0hMV9opAcrmE0Byyo0fY3Ew4tgOevJmQ9grUhpXQhYfyLJ1Kqg3P33JT5fdbT2AjeAjR51zqqVjAL/HMkx7Q==",
"dev": true
},
"@types/semver": { "@types/semver": {
"version": "7.3.13", "version": "7.3.13",
"resolved": "https://registry.npmmirror.com/@types/semver/-/semver-7.3.13.tgz", "resolved": "https://registry.npmmirror.com/@types/semver/-/semver-7.3.13.tgz",
@ -7049,6 +7068,11 @@
"resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.1.tgz", "resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.1.tgz",
"integrity": "sha512-UEZIS3/by4OC8vL3P2dTXRETpebLI2NiI5vIrjaD/5UtrkFX/tNbwjTSRAGC/+7CAo2pIcBaRgWmcBBHcsaCIw==" "integrity": "sha512-UEZIS3/by4OC8vL3P2dTXRETpebLI2NiI5vIrjaD/5UtrkFX/tNbwjTSRAGC/+7CAo2pIcBaRgWmcBBHcsaCIw=="
}, },
"pako": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/pako/-/pako-2.1.0.tgz",
"integrity": "sha512-w+eufiZ1WuJYgPXbV/PO3NCMEc3xqylkKHzp8bxp1uW4qaSNQUkwmLLEc3kKsfz8lpV1F8Ht3U1Cm+9Srog2ug=="
},
"parent-module": { "parent-module": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmmirror.com/parent-module/-/parent-module-1.0.1.tgz", "resolved": "https://registry.npmmirror.com/parent-module/-/parent-module-1.0.1.tgz",

View File

@ -755,11 +755,6 @@
"command": "digital-ide.tool.instance", "command": "digital-ide.tool.instance",
"group": "navigation@3" "group": "navigation@3"
}, },
{
"when": "editorLangId == verilog || editorLangId == systemverilog || editorLangId == vhdl",
"command": "digital-ide.tool.testbench",
"group": "navigation@4"
},
{ {
"when": "editorLangId == verilog || editorLangId == systemverilog || editorLangId == vhdl", "when": "editorLangId == verilog || editorLangId == systemverilog || editorLangId == vhdl",
"command": "digital-ide.tool.icarus.simulateFile", "command": "digital-ide.tool.icarus.simulateFile",
@ -792,11 +787,6 @@
"command": "digital-ide.pl.setSimTop", "command": "digital-ide.pl.setSimTop",
"group": "navigation@6" "group": "navigation@6"
}, },
{
"when": "editorLangId == verilog || editorLangId == systemverilog || editorLangId == vhdl",
"command": "digital-ide.tool.testbench",
"group": "navigation@7"
},
{ {
"when": "resourceLangId == verilog || resourceLangId == systemverilog || resourceLangId == vhdl", "when": "resourceLangId == verilog || resourceLangId == systemverilog || resourceLangId == vhdl",
"command": "digital-ide.tool.instance", "command": "digital-ide.tool.instance",
@ -1248,6 +1238,7 @@
"devDependencies": { "devDependencies": {
"@types/mocha": "^10.0.0", "@types/mocha": "^10.0.0",
"@types/node": "16.x", "@types/node": "16.x",
"@types/pako": "^2.0.3",
"@types/showdown": "^2.0.0", "@types/showdown": "^2.0.0",
"@types/vscode": "^1.72.0", "@types/vscode": "^1.72.0",
"@typescript-eslint/eslint-plugin": "^5.42.0", "@typescript-eslint/eslint-plugin": "^5.42.0",
@ -1263,6 +1254,7 @@
"bson": "^6.8.0", "bson": "^6.8.0",
"chokidar": "^4.0.1", "chokidar": "^4.0.1",
"minimatch": "^10.0.1", "minimatch": "^10.0.1",
"pako": "^2.1.0",
"puppeteer-core": "^19.4.1", "puppeteer-core": "^19.4.1",
"showdown": "^2.1.0", "showdown": "^2.1.0",
"state-machine-cat": "^9.2.5", "state-machine-cat": "^9.2.5",

View File

@ -276,7 +276,7 @@ async function exportCurrentFileDocAsHTML() {
} }
const wsPath = opeParam.workspacePath; const wsPath = opeParam.workspacePath;
const markdownFolderPath = hdlPath.join(wsPath, 'html'); const markdownFolderPath = hdlPath.join(wsPath, 'doc');
if (!fs.existsSync(markdownFolderPath)) { if (!fs.existsSync(markdownFolderPath)) {
fs.mkdirSync(markdownFolderPath); fs.mkdirSync(markdownFolderPath);
} }

View File

@ -364,7 +364,7 @@ async function exportCurrentFileDocAsMarkdown() {
} }
const wsPath = opeParam.workspacePath; const wsPath = opeParam.workspacePath;
const markdownFolderPath = hdlPath.join(wsPath, 'markdown'); const markdownFolderPath = hdlPath.join(wsPath, 'doc');
if (!fs.existsSync(markdownFolderPath)) { if (!fs.existsSync(markdownFolderPath)) {
fs.mkdirSync(markdownFolderPath); fs.mkdirSync(markdownFolderPath);
} }

View File

@ -8,6 +8,10 @@ import { AbsPath, MainOutput, opeParam, ReportType } from '../../global';
// TODO : finish it in each platform // TODO : finish it in each platform
function getDefaultBrowerPath(): AbsPath { function getDefaultBrowerPath(): AbsPath {
const browserPath = vscode.workspace.getConfiguration().get<string>('digital-ide.function.doc.pdf.browserPath.title');
if (browserPath && fs.existsSync(browserPath)) {
return browserPath;
}
switch (opeParam.os) { switch (opeParam.os) {
case 'win32': return 'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe'; case 'win32': return 'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe';
case 'linux': return ''; case 'linux': return '';
@ -79,7 +83,7 @@ async function exportCurrentFileDocAsPDF(uri: vscode.Uri) {
return; return;
} }
const pdfFolderPath = hdlPath.join(wsPath, 'pdf'); const pdfFolderPath = hdlPath.join(wsPath, 'doc');
if (!fs.existsSync(pdfFolderPath)) { if (!fs.existsSync(pdfFolderPath)) {
fs.mkdirSync(pdfFolderPath); fs.mkdirSync(pdfFolderPath);
} }

View File

@ -0,0 +1,132 @@
import * as vscode from 'vscode';
import * as path from 'path';
import * as fs from 'fs';
import pako from 'pako';
import puppeteer, { LowerCasePaperFormat, PDFOptions } from 'puppeteer-core';
import { AbsPath, opeParam } from '../../global';
import { hdlPath } from '../../hdlFs';
import { t } from '../../i18n';
// TODO : finish it in each platform
function getDefaultBrowerPath(): AbsPath {
const browserPath = vscode.workspace.getConfiguration().get<string>('digital-ide.function.doc.pdf.browserPath.title');
if (browserPath && fs.existsSync(browserPath)) {
return browserPath;
}
switch (opeParam.os) {
case 'win32': return 'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe';
case 'linux': return '';
default: return '';
}
}
export async function saveAsSvg(data: any, panel: vscode.WebviewPanel) {
try {
const { svgBuffer, moduleName } = data;
const svgString = pako.ungzip(svgBuffer, { to: 'string' });
// 询问新的路径
const defaultFilename = moduleName + '.svg';
const defaultPath = hdlPath.join(opeParam.workspacePath, defaultFilename);
const vcdFilters: Record<string, string[]> = {};
vcdFilters[""] = ['svg'];
vcdFilters[t('info.vcd-viewer.all-file')] = ['*'];
const saveUri = await vscode.window.showSaveDialog({
title: t('info.vcd-viewer.save-as-view'),
defaultUri: vscode.Uri.file(defaultPath),
saveLabel: t('info.vcd-viewer.save'),
filters: {
[t('svg-file')]: ['svg'],
[t("info.vcd-viewer.all-file")]: ['*']
}
});
if (saveUri) {
const savePath = saveUri.fsPath;
fs.writeFileSync(savePath, svgString);
panel.webview.postMessage({
command: 'save-as-svg',
arguments: [{ success: true }]
});
} else {
panel.webview.postMessage({
command: 'save-as-svg',
arguments: [{ success: false }]
});
}
} catch (error) {
console.log('error happen in /save-as-svg, ' + error);
panel.webview.postMessage({
command: 'save-as-svg',
arguments: [{ success: false }]
});
}
}
export async function saveAsPdf(req: Request, res: Response) {
try {
const { svgBuffer, moduleName, width, height } = req.body;
const svgString = pako.ungzip(svgBuffer, { to: 'string' });
// 询问新的路径
const defaultFilename = moduleName + '.pdf';
const savePath = await showSaveViewDialog({
title: 'Save As pdf',
defaultPath: path.resolve(__dirname, '../test', defaultFilename),
buttonLabel: 'Save',
filters: [
{ name: 'pdf', extensions: ['pdf'] },
{ name: 'All Files', extensions: ['*'] },
],
});
if (savePath) {
// 先保存 html
const htmlPath = savePath.slice(0, -4) + '.html';
fs.writeFileSync(htmlPath, svgString);
await html2pdf(htmlPath, savePath, moduleName, width, height);
// removeBlankPages(savePath);
res.send({
savePath,
success: true
});
} else {
res.send({
success: false
});
}
} catch (error) {
console.log('error happen in /save-as-pdf, ' + error);
res.send({
success: false
});
}
}
async function html2pdf(htmlPath: string, pdfPath: string, moduleName: string, width: number, height: number) {
const browser = await puppeteer.launch({
executablePath: browserPath,
args: ['--lang=en-US', '--no-sandbox', '--disable-setuid-sandbox']
});
const page = await browser.newPage();
const uriFilePath = 'file:///' + path.resolve(htmlPath).replace(/\\/g, "/");
await page.goto(uriFilePath, { waitUntil: 'networkidle0' });
const options: PDFOptions = {
path: pdfPath,
scale: 1,
displayHeaderFooter: true,
// headerTemplate: `<div style="font-size: 12px; margin-left: 1cm;">module ${moduleName}</div>`,
footerTemplate: `<div style="font-size: 15px; margin: 0 auto;">Netlist for <code>${moduleName}</code> - 由 Digital IDE 生成 </div>`,
printBackground: true,
landscape: true,
width: width
};
await page.pdf(options);
await browser.close();
}

View File

@ -163,7 +163,7 @@ export async function loadView(data: any, uri: vscode.Uri, panel: vscode.Webview
panel.title = path.basename(viewPath); panel.title = path.basename(viewPath);
panel.iconPath = getIconConfig('view'); panel.iconPath = getIconConfig('view');
const recoverJson = BSON.deserialize(buffer); const recoverJson = BSON.deserialize(new Uint8Array(buffer));
panel.webview.postMessage({ panel.webview.postMessage({
command: 'load-view', command: 'load-view',
recoverJson, recoverJson,

View File

@ -1,7 +1,7 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import * as path from 'path'; import * as path from 'path';
import * as hdlDoc from './hdlDoc'; import * as hdlDoc from './dide-doc';
import * as sim from './sim'; import * as sim from './sim';
import * as treeView from './treeView'; import * as treeView from './treeView';