From 679a2616bbf67d26e916e61e4b36275b1de795ad Mon Sep 17 00:00:00 2001 From: khaledsherkawi Date: Tue, 10 May 2022 12:11:06 +0200 Subject: [PATCH] Revert "SW-1155 g code files created via pixel based images sv gs engrave some parts more than once (#1475)" This reverts commit 973c1119e7f67ab6ffd26b02477f82f2e72921b8. --- octoprint_mrbeam/static/js/render_fills.js | 40 ++++++++-------------- octoprint_mrbeam/static/js/snap_helpers.js | 15 -------- octoprint_mrbeam/static/js/working_area.js | 25 +++++--------- 3 files changed, 24 insertions(+), 56 deletions(-) diff --git a/octoprint_mrbeam/static/js/render_fills.js b/octoprint_mrbeam/static/js/render_fills.js index 919a25d64..2fd2f944b 100644 --- a/octoprint_mrbeam/static/js/render_fills.js +++ b/octoprint_mrbeam/static/js/render_fills.js @@ -127,12 +127,10 @@ Snap.plugin(function (Snap, Element, Paper, global) { let rasterEl = marked[i]; let bbox; try { - bbox = rasterEl.get_total_bbox(); - } catch (error) { - console.warn( - `Getting bounding box for ${rasterEl} failed.`, - error - ); + bbox = rasterEl.get_total_bbox(); + } + catch(error) { + console.warn(`Getting bounding box for ${rasterEl} failed.`, error); continue; } // find overlaps @@ -174,14 +172,13 @@ Snap.plugin(function (Snap, Element, Paper, global) { rasterEl.addClass(`rasterCluster${c}`) ); let tmpSvg = svg.clone(); - tmpSvg.selectAll(`.toRaster:not(.rasterCluster${c})`).remove(); - // tmpSvg.selectAll(`.toRaster:not(.rasterCluster${c})`).forEach((element) => { - // let elementToBeRemoved = tmpSvg.select('#' + element.attr('id')); - // let elementsToBeExcluded = ["text", "tspan"] - // if (elementToBeRemoved && !elementsToBeExcluded.includes(elementToBeRemoved.type)) { - // elementToBeRemoved.remove(); - // } - // }); + tmpSvg.selectAll(`.toRaster:not(.rasterCluster${c})`).forEach((element) => { + let elementToBeRemoved = tmpSvg.select('#' + element.attr('id')); + let elementsToBeExcluded = ["text", "tspan"] + if (elementToBeRemoved && !elementsToBeExcluded.includes(elementToBeRemoved.type)) { + elementToBeRemoved.remove(); + } + }); // Fix IDs of filter references, those are not cloned correct (probably because reference is in style="..." definition) tmpSvg.fixIds("defs filter[mb\\:id]", "mb:id"); // namespace attribute selectors syntax: [ns\\:attrname] // DON'T fix IDs of textPath references, they're cloned correct. @@ -338,17 +335,10 @@ Snap.plugin(function (Snap, Element, Paper, global) { // ); } - // only enlarge on fonts, images not necessary. - const doEnlargeBBox = - elem.selectAll("text").filter((e) => { - const bb = e.getBBox(); - // this filter is required, as every quick text creates an empty text element (for switching between curved and straight text) - return bb.width > 0 && bb.height > 0; - }).length > 0; - - // Quick fix: in some browsers the bbox is too tight, so we just add an extra margin to all the sides, making the height and width larger in total - const enlargement_x = doEnlargeBBox ? 0.4 : 0; // percentage of the width added to each side - const enlargement_y = doEnlargeBBox ? 0.4 : 0; // percentage of the height added to each side + // TODO only enlarge on images and fonts + // Quick fix: in some browsers the bbox is too tight, so we just add an extra 10% to all the sides, making the height and width 20% larger in total + const enlargement_x = 0.4; // percentage of the width added to each side + const enlargement_y = 0.4; // percentage of the height added to each side const x1 = Math.max(0, bbox.x - bbox.width * enlargement_x); const x2 = Math.min(wMM, bbox.x2 + bbox.width * enlargement_x); const w = x2 - x1; diff --git a/octoprint_mrbeam/static/js/snap_helpers.js b/octoprint_mrbeam/static/js/snap_helpers.js index 99aec5265..dea6f94b4 100644 --- a/octoprint_mrbeam/static/js/snap_helpers.js +++ b/octoprint_mrbeam/static/js/snap_helpers.js @@ -66,19 +66,4 @@ Snap.plugin(function (Snap, Element, Paper, global) { const bb = el.getBBox(); return Snap.path.getBBoxWithTransformation(bb, mat); }; - - /** - * filter method for Snap Set like we know it from Array - * @param f function which decides wether to keep or discard set elements - * @returns {Set} a new Snap set - */ - Snap.Set.prototype.filter = function (f) { - const s = new Snap.Set(); - this.forEach((e) => { - if (f(e)) { - s.push(e); - } - }); - return s; - }; }); diff --git a/octoprint_mrbeam/static/js/working_area.js b/octoprint_mrbeam/static/js/working_area.js index 5aab39df8..07b192375 100644 --- a/octoprint_mrbeam/static/js/working_area.js +++ b/octoprint_mrbeam/static/js/working_area.js @@ -1201,23 +1201,16 @@ $(function () { if (generator.generator === "inkscape") { let isOldInkscapeVersion = NaN; try { - isOldInkscapeVersion = - window.compareVersions( - // 1.1.2 (1:1.1+202202050950+0a00cf5339) -> 1.1 - generator.version - .split(".") - .slice(0, 2) - .join("."), - "0.91" - ) <= 0; - } catch (e) { + isOldInkscapeVersion= window.compareVersions( + // 1.1.2 (1:1.1+202202050950+0a00cf5339) -> 1.1 + generator.version.split('.').slice(0,2).join('.'), + "0.91" + ) <= 0; + } catch(e) { let payload = { error: e.message, }; - self._sendAnalytics( - "inkscape_version_comparison_error", - payload - ); + self._sendAnalytics("inkscape_version_comparison_error", payload); console.log("inkscape_version_comparison_error: ", e); // In case the comparison fails, we assume the version to be above 0.91 // This assumption (the scaling) does not have a major impact as it has @@ -1722,7 +1715,7 @@ $(function () { } else if ( event.target.classList.contains("unit_percent") ) { - let newWidth = + const newWidth = ((currentWidth / Math.abs(currentSx)) * value) / 100.0; if (Math.abs(newWidth) < 0.1) @@ -1766,7 +1759,7 @@ $(function () { } else if ( event.target.classList.contains("unit_percent") ) { - let newHeight = + const newHeight = ((currentHeight / Math.abs(currentSy)) * value) / 100.0; if (Math.abs(newHeight) < 0.1)