Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional SVG normalizer #17

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions main/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
const axios = require('axios').default;
const http = require('http');
const path = require('path');
const svgPreProcessor = require('@deepnest/svg-preprocessor');

ready(async function () {
// main navigation
Expand Down Expand Up @@ -90,7 +91,8 @@
dxfImportScale: "1",
dxfExportScale: "72",
endpointTolerance: 0.36,
conversionServer: defaultConversionServer
conversionServer: defaultConversionServer,
useSvgPreProcessor: false,
};

// Removed `electron-settings` while keeping the same interface to minimize changes
Expand Down Expand Up @@ -133,7 +135,7 @@
}
}

if (key == 'mergeLines' || key == 'simplify') {
if (key == 'mergeLines' || key == 'simplify' || key == 'useSvgPreProcessor') {
val = i.checked;
}

Expand Down Expand Up @@ -232,7 +234,7 @@
else if (i.getAttribute('data-conversion') == 'true') {
i.value = c[i.getAttribute('data-config')] / scale.value;
}
else if (key == 'mergeLines' || key == 'simplify') {
else if (key == 'mergeLines' || key == 'simplify' || key == 'useSvgPreProcessor') {
i.checked = c[i.getAttribute('data-config')];
}
else {
Expand Down Expand Up @@ -668,7 +670,17 @@

// dirpath is used for loading images embedded in svg files
// converted svgs will not have images
importData(body, filename, null, con, dxfFlag);
if (config.getSync('useSvgPreProcessor')) {
const svgResult = svgPreProcessor.loadSvgString(body);
if (!svgResult.success) {
message(svgResult.result, true);
} else {
importData(svgResult.result, filename, null, con, dxfFlag);
}
} else {
importData(body, filename, null, con, dxfFlag);
}

}
}).catch(err => {
message('could not contact file conversion server', true);
Expand All @@ -684,8 +696,16 @@
}
var filename = path.basename(filepath);
var dirpath = path.dirname(filepath);

importData(data, filename, dirpath, null);
if (config.getSync('useSvgPreProcessor')) {
const svgResult = svgPreProcessor.loadSvgString(data);
if (!svgResult.success) {
message(svgResult.result, true);
} else {
importData(svgResult.result, filename, null);
}
} else {
importData(data, filename, dirpath, null);
}
});
};

Expand Down Expand Up @@ -1807,6 +1827,11 @@ <h1>Nesting configuration</h1>

<h1>Import/Export</h1>
<dl class="formgroup">
<dt>Use SVG Normalizer?</dt>
<dd>
<input id="useSvgPreProcessor" type="checkbox" data-config="useSvgPreProcessor" />
</dd>

<dt>SVG scale</dt>
<dd>
<input id="inputscale" type="number" value="72" min="1" step="any" data-config="scale" required />
Expand Down
217 changes: 217 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"dependencies": {
"@electron/remote": "^2.1.2",
"@deepnest/calculate-nfp": "*",
"@deepnest/svg-preprocessor": "*",
"axios": "^1.7.9",
"form-data": "^4.0.1",
"graceful-fs": "^4.2.11"
Expand Down
Loading