kitchen-simulator 4.0.6-react-18 → 4.0.7-measurement-unit-payload
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/es/AppContext.js +1 -1
- package/es/LiteKitchenConfigurator.js +162 -107
- package/es/LiteRenderer.js +162 -137
- package/es/actions/export.js +25 -12
- package/es/actions/project-actions.js +2 -1
- package/es/assets/gltf/door_sliding.bin +0 -0
- package/es/assets/img/png/helper/video_preview_start.png +0 -0
- package/es/assets/img/svg/bottombar/elevation.svg +12 -5
- package/es/catalog/catalog.js +21 -5
- package/es/catalog/factories/wall-factory.js +1 -1
- package/es/catalog/holes/window-clear/planner-element.js +2 -2
- package/es/catalog/properties/export.js +21 -0
- package/es/catalog/properties/property-checkbox.js +68 -0
- package/es/catalog/properties/property-color.js +39 -0
- package/es/catalog/properties/property-enum.js +50 -0
- package/es/catalog/properties/property-hidden.js +19 -0
- package/es/catalog/properties/property-lenght-measure.js +100 -0
- package/es/catalog/properties/property-length-measure.js +84 -0
- package/es/catalog/properties/property-length-measure_hole.js +100 -0
- package/es/catalog/properties/property-number.js +48 -0
- package/es/catalog/properties/property-read-only.js +26 -0
- package/es/catalog/properties/property-string.js +48 -0
- package/es/catalog/properties/property-toggle.js +39 -0
- package/es/catalog/properties/shared-property-style.js +14 -0
- package/es/catalog/utils/exporter.js +24 -11
- package/es/catalog/utils/item-loader.js +38 -34
- package/es/class/hole.js +0 -2
- package/es/class/item.js +99 -70
- package/es/class/layer.js +1 -1
- package/es/class/line.js +4 -8
- package/es/class/project.js +96 -81
- package/es/components/content.js +5 -93
- package/es/components/export.js +4 -6
- package/es/components/style/button.js +106 -0
- package/es/components/style/cancel-button.js +21 -0
- package/es/components/style/content-container.js +30 -0
- package/es/components/style/content-title.js +25 -0
- package/es/components/style/delete-button.js +24 -0
- package/es/components/style/export.js +28 -2
- package/es/components/style/form-block.js +20 -0
- package/es/components/style/form-color-input.js +26 -0
- package/es/components/style/form-label.js +22 -0
- package/es/components/style/form-number-input.js +29 -27
- package/es/components/style/form-number-input_2.js +200 -0
- package/es/components/style/form-select.js +19 -0
- package/es/components/style/form-slider.js +60 -0
- package/es/components/style/form-submit-button.js +25 -0
- package/es/components/style/form-text-input.js +69 -0
- package/es/components/viewer2d/grids/grid-streak.js +1 -1
- package/es/components/viewer2d/group.js +5 -4
- package/es/components/viewer2d/item.js +155 -359
- package/es/components/viewer2d/layer.js +1 -1
- package/es/components/viewer2d/line.js +22 -52
- package/es/components/viewer2d/ruler.js +16 -11
- package/es/components/viewer2d/rulerDist.js +38 -51
- package/es/components/viewer2d/rulerX.js +4 -2
- package/es/components/viewer2d/rulerY.js +3 -0
- package/es/components/viewer2d/scene.js +17 -12
- package/es/components/viewer2d/state.js +1 -1
- package/es/components/viewer2d/utils.js +2 -2
- package/es/components/viewer2d/vertex.js +3 -2
- package/es/components/viewer2d/viewer2d.js +56 -87
- package/es/components/viewer3d/ruler-utils/scene3D.js +1 -1
- package/es/components/viewer3d/scene-creator.js +270 -69
- package/es/components/viewer3d/viewer3d-first-person.js +24 -26
- package/es/components/viewer3d/viewer3d.js +115 -120
- package/es/constants.js +7 -2
- package/es/devLiteRenderer.js +491 -150
- package/es/index.js +627 -1
- package/es/models.js +13 -8
- package/es/plugins/SVGLoader.js +1414 -0
- package/es/plugins/console-debugger.js +34 -0
- package/es/plugins/export.js +7 -0
- package/es/plugins/keyboard.js +110 -0
- package/es/reducers/project-reducer.js +4 -1
- package/es/reducers/viewer2d-reducer.js +3 -1
- package/es/reducers/viewer3d-reducer.js +3 -1
- package/es/styles/export.js +5 -0
- package/es/styles/tabs.css +40 -0
- package/es/utils/geometry.js +77 -119
- package/es/utils/helper.js +38 -1
- package/es/utils/isolate-event-handler.js +829 -609
- package/es/utils/molding.js +459 -11
- package/es/utils/ruler.js +58 -0
- package/lib/AppContext.js +1 -1
- package/lib/LiteKitchenConfigurator.js +161 -107
- package/lib/LiteRenderer.js +161 -137
- package/lib/actions/export.js +35 -39
- package/lib/actions/project-actions.js +2 -1
- package/lib/assets/gltf/door_sliding.bin +0 -0
- package/lib/assets/img/png/helper/video_preview_start.png +0 -0
- package/lib/assets/img/svg/bottombar/elevation.svg +12 -5
- package/lib/catalog/catalog.js +20 -4
- package/lib/catalog/factories/wall-factory.js +1 -1
- package/lib/catalog/holes/window-clear/planner-element.js +2 -2
- package/lib/catalog/properties/export.js +81 -0
- package/lib/catalog/properties/property-checkbox.js +76 -0
- package/lib/catalog/properties/property-color.js +47 -0
- package/lib/catalog/properties/property-enum.js +58 -0
- package/lib/catalog/properties/property-hidden.js +27 -0
- package/lib/catalog/properties/property-lenght-measure.js +108 -0
- package/lib/catalog/properties/property-length-measure.js +92 -0
- package/lib/catalog/properties/property-length-measure_hole.js +108 -0
- package/lib/catalog/properties/property-number.js +56 -0
- package/lib/catalog/properties/property-read-only.js +34 -0
- package/lib/catalog/properties/property-string.js +56 -0
- package/lib/catalog/properties/property-toggle.js +47 -0
- package/lib/catalog/properties/shared-property-style.js +21 -0
- package/lib/catalog/utils/exporter.js +24 -11
- package/lib/catalog/utils/item-loader.js +38 -34
- package/lib/class/hole.js +0 -2
- package/lib/class/item.js +97 -68
- package/lib/class/layer.js +1 -1
- package/lib/class/line.js +3 -7
- package/lib/class/project.js +96 -81
- package/lib/components/content.js +5 -93
- package/lib/components/export.js +6 -26
- package/lib/components/style/button.js +115 -0
- package/lib/components/style/cancel-button.js +29 -0
- package/lib/components/style/content-container.js +38 -0
- package/lib/components/style/content-title.js +35 -0
- package/lib/components/style/delete-button.js +34 -0
- package/lib/components/style/export.js +105 -1
- package/lib/components/style/form-block.js +28 -0
- package/lib/components/style/form-color-input.js +34 -0
- package/lib/components/style/form-label.js +30 -0
- package/lib/components/style/form-number-input.js +29 -27
- package/lib/components/style/form-number-input_2.js +209 -0
- package/lib/components/style/form-select.js +29 -0
- package/lib/components/style/form-slider.js +68 -0
- package/lib/components/style/form-submit-button.js +35 -0
- package/lib/components/style/form-text-input.js +78 -0
- package/lib/components/viewer2d/grids/grid-streak.js +1 -1
- package/lib/components/viewer2d/group.js +5 -4
- package/lib/components/viewer2d/item.js +152 -356
- package/lib/components/viewer2d/layer.js +1 -1
- package/lib/components/viewer2d/line.js +22 -52
- package/lib/components/viewer2d/ruler.js +15 -10
- package/lib/components/viewer2d/rulerDist.js +38 -51
- package/lib/components/viewer2d/rulerX.js +4 -2
- package/lib/components/viewer2d/rulerY.js +3 -0
- package/lib/components/viewer2d/scene.js +17 -12
- package/lib/components/viewer2d/state.js +1 -1
- package/lib/components/viewer2d/utils.js +2 -2
- package/lib/components/viewer2d/vertex.js +3 -2
- package/lib/components/viewer2d/viewer2d.js +54 -84
- package/lib/components/viewer3d/ruler-utils/scene3D.js +1 -1
- package/lib/components/viewer3d/scene-creator.js +267 -66
- package/lib/components/viewer3d/viewer3d-first-person.js +24 -26
- package/lib/components/viewer3d/viewer3d.js +112 -116
- package/lib/constants.js +12 -7
- package/lib/devLiteRenderer.js +489 -148
- package/lib/index.js +630 -6
- package/lib/models.js +13 -8
- package/lib/plugins/SVGLoader.js +1419 -0
- package/lib/plugins/console-debugger.js +42 -0
- package/lib/plugins/export.js +25 -0
- package/lib/plugins/keyboard.js +117 -0
- package/lib/reducers/project-reducer.js +4 -1
- package/lib/reducers/viewer2d-reducer.js +3 -1
- package/lib/reducers/viewer3d-reducer.js +3 -1
- package/lib/styles/export.js +13 -0
- package/lib/styles/tabs.css +40 -0
- package/lib/utils/geometry.js +77 -119
- package/lib/utils/helper.js +40 -1
- package/lib/utils/isolate-event-handler.js +829 -608
- package/lib/utils/molding.js +460 -9
- package/lib/utils/ruler.js +63 -0
- package/package.json +21 -20
- package/es/mocks/appliancePayload.json +0 -27
- package/es/mocks/cabinetPayload.json +0 -1914
- package/es/mocks/cabinetPayload2.json +0 -76
- package/es/mocks/dataBundle2.json +0 -4
- package/es/mocks/distancePayload.json +0 -6
- package/es/mocks/doorStylePayload2.json +0 -84
- package/es/mocks/furnishingPayload.json +0 -23
- package/es/mocks/itemCDSPayload.json +0 -27
- package/es/mocks/lightingPayload.json +0 -23
- package/es/mocks/mockProps.json +0 -43
- package/es/mocks/mockProps2.json +0 -9
- package/es/mocks/moldingPayload.json +0 -19
- package/es/mocks/projectItemsCatalog.json +0 -133
- package/es/mocks/rectangleShape.json +0 -238
- package/es/mocks/replaceCabinetPayload.json +0 -81
- package/es/mocks/roomShapePayload.json +0 -5
- package/es/useAppContext.js +0 -8
- package/lib/mocks/appliancePayload.json +0 -27
- package/lib/mocks/cabinetPayload.json +0 -1914
- package/lib/mocks/cabinetPayload2.json +0 -76
- package/lib/mocks/dataBundle2.json +0 -4
- package/lib/mocks/distancePayload.json +0 -6
- package/lib/mocks/doorStylePayload2.json +0 -84
- package/lib/mocks/furnishingPayload.json +0 -23
- package/lib/mocks/itemCDSPayload.json +0 -27
- package/lib/mocks/lightingPayload.json +0 -23
- package/lib/mocks/mockProps.json +0 -43
- package/lib/mocks/mockProps2.json +0 -9
- package/lib/mocks/moldingPayload.json +0 -19
- package/lib/mocks/projectItemsCatalog.json +0 -133
- package/lib/mocks/rectangleShape.json +0 -238
- package/lib/mocks/replaceCabinetPayload.json +0 -81
- package/lib/mocks/roomShapePayload.json +0 -5
- package/lib/useAppContext.js +0 -16
package/es/utils/molding.js
CHANGED
|
@@ -5,11 +5,11 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
5
5
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
6
6
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
7
7
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
8
|
-
import { BASE_CABINET_LAYOUTPOS, BOTTOM_MOLDING_LOCATION, EPSILON, MIDDLE_MOLDING_LOCATION, MOLDING_LOCATIONS, OVERLAP_INCLUDED, OVERLAP_LINK, OVERLAP_SAME, OVERLAP_SOME, TALL_CABINET_LAYOUTPOS, TOP_MOLDING_LOCATION, WALL_CABINET_LAYOUTPOS } from "../constants";
|
|
8
|
+
import { BASE_CABINET_LAYOUTPOS, BOTTOM_MOLDING_LOCATION, EPSILON, ITEM_TYPE, MIDDLE_MOLDING_LOCATION, MOLDING_LOCATIONS, OVERLAP_INCLUDED, OVERLAP_LINK, OVERLAP_SAME, OVERLAP_SOME, TALL_CABINET_LAYOUTPOS, TOE_KICK_MOLDING, TOP_MOLDING_LOCATION, WALL_CABINET_LAYOUTPOS } from "../constants";
|
|
9
9
|
import * as Three from 'three';
|
|
10
10
|
import { convert } from "./convert-units-lite";
|
|
11
11
|
import IDBroker from "./id-broker";
|
|
12
|
-
import { returnReplaceableDeepSearchType } from "../components/viewer2d/utils";
|
|
12
|
+
import { getToeKickSKU, isEqualInstallationType, returnReplaceableDeepSearchType } from "../components/viewer2d/utils";
|
|
13
13
|
import { GeometryUtils } from "./export";
|
|
14
14
|
import { isEmpty } from "./helper";
|
|
15
15
|
export function getItemRect(item) {
|
|
@@ -304,6 +304,76 @@ export function getLinesOfItem(item, allLineRects, catalog) {
|
|
|
304
304
|
}
|
|
305
305
|
return lines;
|
|
306
306
|
}
|
|
307
|
+
export function getLinesOfItem2(item, allLineRects, catalog) {
|
|
308
|
+
var _lines;
|
|
309
|
+
var lines = [];
|
|
310
|
+
var outline = null;
|
|
311
|
+
var element = catalog.elements[item.get('type')];
|
|
312
|
+
if (!element) element = catalog.elements[returnReplaceableDeepSearchType(item.get('type'))];
|
|
313
|
+
// get edge lines
|
|
314
|
+
var newWidth = item.properties.get('width').get('_length');
|
|
315
|
+
var wUnit = item.properties.get('width').get('_unit') || 'cm';
|
|
316
|
+
newWidth = convert(newWidth).from(wUnit).to('cm');
|
|
317
|
+
var newDepth = item.properties.get('depth').get('_length');
|
|
318
|
+
var hUnit = item.properties.get('depth').get('_unit') || 'cm';
|
|
319
|
+
newDepth = convert(newDepth).from(hUnit).to('cm');
|
|
320
|
+
if (item) {
|
|
321
|
+
var _element;
|
|
322
|
+
// Get Outline Data of Selected Item
|
|
323
|
+
outline = (_element = element) === null || _element === void 0 ? void 0 : _element.info.outline;
|
|
324
|
+
if (outline) {
|
|
325
|
+
// Extract Points from `outline`
|
|
326
|
+
var outlinePaths = outline.paths;
|
|
327
|
+
var outlineWidth = outline.svgWidth;
|
|
328
|
+
var outlineHeight = outline.svgHeight;
|
|
329
|
+
var outlinePoints = []; // Hold Points Of SVG
|
|
330
|
+
var _iterator3 = _createForOfIteratorHelper(outlinePaths),
|
|
331
|
+
_step3;
|
|
332
|
+
try {
|
|
333
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
334
|
+
var path = _step3.value;
|
|
335
|
+
var _iterator4 = _createForOfIteratorHelper(path.subPaths),
|
|
336
|
+
_step4;
|
|
337
|
+
try {
|
|
338
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
339
|
+
var subPath = _step4.value;
|
|
340
|
+
outlinePoints = outlinePoints.concat(subPath.getPoints());
|
|
341
|
+
}
|
|
342
|
+
} catch (err) {
|
|
343
|
+
_iterator4.e(err);
|
|
344
|
+
} finally {
|
|
345
|
+
_iterator4.f();
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
} catch (err) {
|
|
349
|
+
_iterator3.e(err);
|
|
350
|
+
} finally {
|
|
351
|
+
_iterator3.f();
|
|
352
|
+
}
|
|
353
|
+
outline.reverse && outlinePoints.reverse();
|
|
354
|
+
for (var i = 0; i < outlinePoints.length - 1; i++) {
|
|
355
|
+
lines.push([GeometryUtils.rotatePointAroundPoint((outlinePoints[i].x / outlineWidth - 0.5) * newWidth + item.x, (outlinePoints[i].y / outlineHeight - 0.5) * newDepth + item.y, item.x, item.y, item.rotation + 90), GeometryUtils.rotatePointAroundPoint((outlinePoints[i + 1].x / outlineWidth - 0.5) * newWidth + item.x, (outlinePoints[i + 1].y / outlineHeight - 0.5) * newDepth + item.y, item.x, item.y, item.rotation + 90), IDBroker.acquireID()]);
|
|
356
|
+
}
|
|
357
|
+
} else {
|
|
358
|
+
var pos = [[-1, -1], [1, -1], [1, 1], [-1, 1]];
|
|
359
|
+
for (var _i2 = 0; _i2 < 4; _i2++) {
|
|
360
|
+
lines.push([GeometryUtils.rotatePointAroundPoint(pos[_i2][0] * newWidth / 2 + item.x, pos[_i2][1] * newDepth / 2 + item.y, item.x, item.y, item.rotation), GeometryUtils.rotatePointAroundPoint(pos[(_i2 + 1) % 4][0] * newWidth / 2 + item.x, pos[(_i2 + 1) % 4][1] * newDepth / 2 + item.y, item.x, item.y, item.rotation), IDBroker.acquireID()]);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
lines = (_lines = lines) === null || _lines === void 0 ? void 0 : _lines.filter(function (line) {
|
|
365
|
+
return !GeometryUtils.isSnappedLine({
|
|
366
|
+
rect: [{
|
|
367
|
+
x: 0,
|
|
368
|
+
y: 0
|
|
369
|
+
}, {
|
|
370
|
+
x: 0,
|
|
371
|
+
y: 0
|
|
372
|
+
}, line[0], line[1]]
|
|
373
|
+
}, allLineRects);
|
|
374
|
+
});
|
|
375
|
+
return lines;
|
|
376
|
+
}
|
|
307
377
|
function isParallelLines(line1, line2) {
|
|
308
378
|
var isParallel = false;
|
|
309
379
|
if (Math.abs(line1[0].y - line1[1].y) <= EPSILON && Math.abs(line2[0].y - line2[1].y) <= EPSILON) isParallel = true;
|
|
@@ -485,20 +555,20 @@ export function getLinesFromItems2(moldingGroup, layer, catalog) {
|
|
|
485
555
|
// merge the collinear linked lines to one line
|
|
486
556
|
var newMGlines = [];
|
|
487
557
|
var filteredMGlines = MGlines;
|
|
488
|
-
var _loop3 = function _loop3(
|
|
558
|
+
var _loop3 = function _loop3(_i3) {
|
|
489
559
|
if (filteredMGlines.length < 1) return 0; // break
|
|
490
560
|
if (!filteredMGlines.some(function (v) {
|
|
491
|
-
return v[2] === MGlines[
|
|
561
|
+
return v[2] === MGlines[_i3][2];
|
|
492
562
|
})) return 1; // continue
|
|
493
|
-
var mergedResult = getMergedLine(MGlines[
|
|
563
|
+
var mergedResult = getMergedLine(MGlines[_i3], filteredMGlines, 0);
|
|
494
564
|
if (mergedResult) {
|
|
495
565
|
newMGlines.push(mergedResult.mergedLine);
|
|
496
566
|
filteredMGlines = mergedResult.filteredMGlines;
|
|
497
567
|
}
|
|
498
568
|
},
|
|
499
569
|
_ret;
|
|
500
|
-
for (var
|
|
501
|
-
_ret = _loop3(
|
|
570
|
+
for (var _i3 = 0; _i3 < MGlines.length; _i3++) {
|
|
571
|
+
_ret = _loop3(_i3);
|
|
502
572
|
if (_ret === 0) break;
|
|
503
573
|
if (_ret === 1) continue;
|
|
504
574
|
}
|
|
@@ -587,11 +657,12 @@ function getTrimmedContourLineSegs(lineSegs, otherLines, cnt) {
|
|
|
587
657
|
};
|
|
588
658
|
var bContourSeg = true;
|
|
589
659
|
var _loop6 = function _loop6(j) {
|
|
660
|
+
var _otherLines$j$0$x, _otherLines$j$, _otherLines$j$line$, _otherLines$j$0$y, _otherLines$j$2, _otherLines$j$line$2, _otherLines$j$1$x, _otherLines$j$3, _otherLines$j$line$3, _otherLines$j$1$y, _otherLines$j$4, _otherLines$j$line$4;
|
|
590
661
|
var destLine = {
|
|
591
|
-
x1: otherLines[j][0].x,
|
|
592
|
-
y1: otherLines[j][0].y,
|
|
593
|
-
x2: otherLines[j][1].x,
|
|
594
|
-
y2: otherLines[j][1].y
|
|
662
|
+
x1: (_otherLines$j$0$x = (_otherLines$j$ = otherLines[j][0]) === null || _otherLines$j$ === void 0 ? void 0 : _otherLines$j$.x) !== null && _otherLines$j$0$x !== void 0 ? _otherLines$j$0$x : (_otherLines$j$line$ = otherLines[j].line[0]) === null || _otherLines$j$line$ === void 0 ? void 0 : _otherLines$j$line$.x,
|
|
663
|
+
y1: (_otherLines$j$0$y = (_otherLines$j$2 = otherLines[j][0]) === null || _otherLines$j$2 === void 0 ? void 0 : _otherLines$j$2.y) !== null && _otherLines$j$0$y !== void 0 ? _otherLines$j$0$y : (_otherLines$j$line$2 = otherLines[j].line[0]) === null || _otherLines$j$line$2 === void 0 ? void 0 : _otherLines$j$line$2.y,
|
|
664
|
+
x2: (_otherLines$j$1$x = (_otherLines$j$3 = otherLines[j][1]) === null || _otherLines$j$3 === void 0 ? void 0 : _otherLines$j$3.x) !== null && _otherLines$j$1$x !== void 0 ? _otherLines$j$1$x : (_otherLines$j$line$3 = otherLines[j].line[1]) === null || _otherLines$j$line$3 === void 0 ? void 0 : _otherLines$j$line$3.x,
|
|
665
|
+
y2: (_otherLines$j$1$y = (_otherLines$j$4 = otherLines[j][1]) === null || _otherLines$j$4 === void 0 ? void 0 : _otherLines$j$4.y) !== null && _otherLines$j$1$y !== void 0 ? _otherLines$j$1$y : (_otherLines$j$line$4 = otherLines[j].line[1]) === null || _otherLines$j$line$4 === void 0 ? void 0 : _otherLines$j$line$4.y
|
|
595
666
|
};
|
|
596
667
|
var rst = GeometryUtils.relationshipOfTwoOverlappedLines(srcLine, destLine);
|
|
597
668
|
if (rst.result == OVERLAP_SAME || rst.result == OVERLAP_INCLUDED) {
|
|
@@ -866,4 +937,381 @@ export function createMonldingGroup(oldMG, layer, molding, catalog) {
|
|
|
866
937
|
newMG.lines.reverse();
|
|
867
938
|
newMG = getMDPoints(newMG);
|
|
868
939
|
return newMG;
|
|
940
|
+
}
|
|
941
|
+
export function getMoldingDataOfScene2(layer, catalog, doorStyle) {
|
|
942
|
+
var moldingData = [];
|
|
943
|
+
var items = layer.items.toArray();
|
|
944
|
+
var allLineRects = GeometryUtils.buildRectFromLines(layer, GeometryUtils.getAllLines(layer));
|
|
945
|
+
|
|
946
|
+
// get all molding line segments
|
|
947
|
+
var moldingLines = [];
|
|
948
|
+
items.forEach(function (item) {
|
|
949
|
+
if (item.category === ITEM_TYPE.CABINET) {
|
|
950
|
+
var _item$molding;
|
|
951
|
+
var MGlines = getLinesOfItem2(item, allLineRects, catalog); // exclude overlayed to wall
|
|
952
|
+
// z position of molding line
|
|
953
|
+
var z = item.properties.get('altitude').get('_length');
|
|
954
|
+
var zUnit = item.properties.get('altitude').get('_unit') || 'cm';
|
|
955
|
+
z = convert(z).from(zUnit).to('cm');
|
|
956
|
+
var h = item.properties.get('height').get('_length');
|
|
957
|
+
var hUnit = item.properties.get('height').get('_unit') || 'cm';
|
|
958
|
+
h = convert(h).from(hUnit).to('cm');
|
|
959
|
+
if (!isEmpty(item.molding) && isEnableItemForMolding(layer, item)) {
|
|
960
|
+
// calc normal molding line
|
|
961
|
+
item === null || item === void 0 || item.molding.forEach(function (molding) {
|
|
962
|
+
var lineZ = z;
|
|
963
|
+
switch (molding.location_type) {
|
|
964
|
+
case TOP_MOLDING_LOCATION:
|
|
965
|
+
lineZ = z + h;
|
|
966
|
+
break;
|
|
967
|
+
case MIDDLE_MOLDING_LOCATION:
|
|
968
|
+
lineZ = z + h / 2;
|
|
969
|
+
break;
|
|
970
|
+
}
|
|
971
|
+
MGlines === null || MGlines === void 0 || MGlines.forEach(function (line) {
|
|
972
|
+
return moldingLines.push({
|
|
973
|
+
molding: _objectSpread({}, molding),
|
|
974
|
+
doorStyle: item.doorStyle.hasOwnProperty('id') ? item.doorStyle : !isEmpty(item.doorStyle) && item.doorStyle.toJS(),
|
|
975
|
+
line: line,
|
|
976
|
+
z: lineZ
|
|
977
|
+
});
|
|
978
|
+
});
|
|
979
|
+
});
|
|
980
|
+
} else if (
|
|
981
|
+
// calc toe kick molding line
|
|
982
|
+
item.layoutpos === BASE_CABINET_LAYOUTPOS && (isEmpty(item.molding) || ((_item$molding = item.molding) === null || _item$molding === void 0 ? void 0 : _item$molding.length) < 1 || !isEnableItemForMolding(layer, item))) {
|
|
983
|
+
var skuName = getToeKickSKU(item.doorStyle, catalog);
|
|
984
|
+
var thumbnail = skuName ? skuName : '';
|
|
985
|
+
MGlines === null || MGlines === void 0 || MGlines.forEach(function (line) {
|
|
986
|
+
return moldingLines.push({
|
|
987
|
+
molding: {
|
|
988
|
+
name: TOE_KICK_MOLDING,
|
|
989
|
+
sku: getToeKickSKU(item.doorStyle, catalog),
|
|
990
|
+
thumbnail: thumbnail,
|
|
991
|
+
category: 'molding',
|
|
992
|
+
type: 'cabinet'
|
|
993
|
+
},
|
|
994
|
+
doorStyle: item.doorStyle.hasOwnProperty('id') ? item.doorStyle : !isEmpty(item.doorStyle) && item.doorStyle.toJS(),
|
|
995
|
+
line: line,
|
|
996
|
+
z: z
|
|
997
|
+
});
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
});
|
|
1002
|
+
|
|
1003
|
+
// filter the real molding line segments
|
|
1004
|
+
var removeLineIds = []; // remove the line that fully overlapped to other line
|
|
1005
|
+
var newLines = []; // new countour line segment that except the overlapped part
|
|
1006
|
+
var _loop9 = function _loop9(i) {
|
|
1007
|
+
var srcLine = {
|
|
1008
|
+
x1: moldingLines[i].line[0].x,
|
|
1009
|
+
y1: moldingLines[i].line[0].y,
|
|
1010
|
+
x2: moldingLines[i].line[1].x,
|
|
1011
|
+
y2: moldingLines[i].line[1].y
|
|
1012
|
+
};
|
|
1013
|
+
var _loop1 = function _loop1(j) {
|
|
1014
|
+
if (i === j) return 0; // continue
|
|
1015
|
+
if (Math.abs(moldingLines[i].z - moldingLines[j].z) > EPSILON) return 0; // continue
|
|
1016
|
+
var destLine = {
|
|
1017
|
+
x1: moldingLines[j].line[0].x,
|
|
1018
|
+
y1: moldingLines[j].line[0].y,
|
|
1019
|
+
x2: moldingLines[j].line[1].x,
|
|
1020
|
+
y2: moldingLines[j].line[1].y
|
|
1021
|
+
};
|
|
1022
|
+
var rst = GeometryUtils.relationshipOfTwoOverlappedLines(srcLine, destLine);
|
|
1023
|
+
if (rst.result === OVERLAP_SAME || rst.result === OVERLAP_INCLUDED) {
|
|
1024
|
+
removeLineIds.push(i);
|
|
1025
|
+
return 1; // break
|
|
1026
|
+
} else if (rst.result === OVERLAP_SOME) {
|
|
1027
|
+
removeLineIds.push(i);
|
|
1028
|
+
var lineSegs = getTrimmedContourLineSegs(rst.trimmedSegs, moldingLines.filter(function (v, idx) {
|
|
1029
|
+
return idx !== i && idx !== j && Math.abs(v.z - moldingLines[i].z) < EPSILON;
|
|
1030
|
+
}), 0);
|
|
1031
|
+
if (lineSegs.length > 0) {
|
|
1032
|
+
lineSegs.forEach(function (ls) {
|
|
1033
|
+
return newLines.push({
|
|
1034
|
+
molding: _objectSpread({}, moldingLines[i].molding),
|
|
1035
|
+
doorStyle: moldingLines[i].doorStyle,
|
|
1036
|
+
line: _toConsumableArray(ls),
|
|
1037
|
+
z: moldingLines[i].z
|
|
1038
|
+
});
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
return 1; // break
|
|
1042
|
+
}
|
|
1043
|
+
},
|
|
1044
|
+
_ret4;
|
|
1045
|
+
for (var j = 0; j < moldingLines.length; j++) {
|
|
1046
|
+
_ret4 = _loop1(j);
|
|
1047
|
+
if (_ret4 === 0) continue;
|
|
1048
|
+
if (_ret4 === 1) break;
|
|
1049
|
+
}
|
|
1050
|
+
};
|
|
1051
|
+
for (var i = 0; i < moldingLines.length; i++) {
|
|
1052
|
+
_loop9(i);
|
|
1053
|
+
}
|
|
1054
|
+
moldingLines = moldingLines.filter(function (line, idx) {
|
|
1055
|
+
return !removeLineIds.some(function (id) {
|
|
1056
|
+
return idx === id;
|
|
1057
|
+
});
|
|
1058
|
+
});
|
|
1059
|
+
if (newLines.length > 0) moldingLines = [].concat(_toConsumableArray(moldingLines), newLines);
|
|
1060
|
+
// console.log('moldingLines: ', moldingLines);
|
|
1061
|
+
|
|
1062
|
+
// make molding data with sorting molding & doorStyle
|
|
1063
|
+
var _loop0 = function _loop0() {
|
|
1064
|
+
var ml = moldingLines[k];
|
|
1065
|
+
var mlLength = convert(GeometryUtils.verticesDistance(ml.line[0], ml.line[1])).from('cm').to('in');
|
|
1066
|
+
var idx = moldingData.findIndex(function (v) {
|
|
1067
|
+
var _ml$molding, _v$doorStyle, _ml$doorStyle;
|
|
1068
|
+
return (v === null || v === void 0 ? void 0 : v.name) === ((_ml$molding = ml.molding) === null || _ml$molding === void 0 ? void 0 : _ml$molding.name) && ((_v$doorStyle = v.doorStyle) === null || _v$doorStyle === void 0 ? void 0 : _v$doorStyle.id) === ((_ml$doorStyle = ml.doorStyle) === null || _ml$doorStyle === void 0 ? void 0 : _ml$doorStyle.id);
|
|
1069
|
+
});
|
|
1070
|
+
if (idx < 0) moldingData.push(_objectSpread(_objectSpread({}, ml.molding), {}, {
|
|
1071
|
+
doorStyle: ml.doorStyle,
|
|
1072
|
+
totalLength: mlLength,
|
|
1073
|
+
count: Math.ceil(mlLength * 1.1 / 96)
|
|
1074
|
+
}));else {
|
|
1075
|
+
moldingData[idx].totalLength += mlLength;
|
|
1076
|
+
moldingData[idx].count = Math.ceil(moldingData[idx].totalLength * 1.1 / 96);
|
|
1077
|
+
}
|
|
1078
|
+
};
|
|
1079
|
+
for (var k = 0; k < moldingLines.length; k++) {
|
|
1080
|
+
_loop0();
|
|
1081
|
+
}
|
|
1082
|
+
// console.log('moldingData: ', moldingData);
|
|
1083
|
+
|
|
1084
|
+
return moldingData;
|
|
1085
|
+
}
|
|
1086
|
+
export function getMoldingDataOfScene(layer, catalog, doorStyle) {
|
|
1087
|
+
var moldingData = [];
|
|
1088
|
+
var items = layer.items.toArray();
|
|
1089
|
+
var moldings = [];
|
|
1090
|
+
// get all moldings info
|
|
1091
|
+
items.forEach(function (itemCat) {
|
|
1092
|
+
var _itemCat$molding;
|
|
1093
|
+
itemCat === null || itemCat === void 0 || (_itemCat$molding = itemCat.molding) === null || _itemCat$molding === void 0 || _itemCat$molding.forEach(function (molding) {
|
|
1094
|
+
if (!moldings.some(function (m) {
|
|
1095
|
+
return m.name === molding.name;
|
|
1096
|
+
})) moldings.push(molding);
|
|
1097
|
+
});
|
|
1098
|
+
});
|
|
1099
|
+
|
|
1100
|
+
// calc normal molding
|
|
1101
|
+
moldings.forEach(function (molding) {
|
|
1102
|
+
var itemGroups = [];
|
|
1103
|
+
var temp_items = [];
|
|
1104
|
+
items.forEach(function (item) {
|
|
1105
|
+
if (item.molding.some(function (mol) {
|
|
1106
|
+
return mol.itemID === molding.itemID;
|
|
1107
|
+
}) && isEnableItemForMolding(layer, item)) {
|
|
1108
|
+
temp_items.push(item);
|
|
1109
|
+
}
|
|
1110
|
+
});
|
|
1111
|
+
if (temp_items.length) {
|
|
1112
|
+
while (temp_items.length > 0) {
|
|
1113
|
+
var itemGroup = [temp_items[0]];
|
|
1114
|
+
var _loop10 = function _loop10(_idx) {
|
|
1115
|
+
if (!itemGroup.some(function (it) {
|
|
1116
|
+
return it.id === temp_items[_idx].id;
|
|
1117
|
+
}) && isItemSnappedGroup(temp_items[_idx], itemGroup)) {
|
|
1118
|
+
itemGroup.push(temp_items[_idx]);
|
|
1119
|
+
_idx = 0;
|
|
1120
|
+
}
|
|
1121
|
+
idx = _idx;
|
|
1122
|
+
};
|
|
1123
|
+
for (var idx = 0; idx < temp_items.length; idx++) {
|
|
1124
|
+
_loop10(idx);
|
|
1125
|
+
}
|
|
1126
|
+
itemGroup.forEach(function (item) {
|
|
1127
|
+
var index = temp_items.findIndex(function (it) {
|
|
1128
|
+
return it.id === item.id;
|
|
1129
|
+
});
|
|
1130
|
+
if (index > -1) {
|
|
1131
|
+
temp_items.splice(index, 1);
|
|
1132
|
+
}
|
|
1133
|
+
});
|
|
1134
|
+
itemGroups.push(itemGroup);
|
|
1135
|
+
}
|
|
1136
|
+
var molding_totalLength = 0;
|
|
1137
|
+
itemGroups.forEach(function (itemgroup) {
|
|
1138
|
+
var allLineRects = GeometryUtils.buildRectFromLines(layer, GeometryUtils.getAllLines(layer));
|
|
1139
|
+
var items = _toConsumableArray(itemgroup);
|
|
1140
|
+
var MGlines = getLinesOfItem(items[0], allLineRects, catalog);
|
|
1141
|
+
items = sortItemsByDistance(items, items[0]);
|
|
1142
|
+
var _loop11 = function _loop11() {
|
|
1143
|
+
var itemLines = getLinesOfItem(items[i], allLineRects, catalog);
|
|
1144
|
+
var temp_MGLines = [];
|
|
1145
|
+
MGlines.forEach(function (line) {
|
|
1146
|
+
var idx = itemLines.findIndex(function (itemLine) {
|
|
1147
|
+
return isLinesOverlapped(line, itemLine);
|
|
1148
|
+
});
|
|
1149
|
+
var curItemLine = itemLines[idx];
|
|
1150
|
+
if (idx > -1) {
|
|
1151
|
+
if (!(GeometryUtils.samePoints(line[0], curItemLine[0]) && GeometryUtils.samePoints(line[1], curItemLine[1]) || GeometryUtils.samePoints(line[0], curItemLine[1]) && GeometryUtils.samePoints(line[1], curItemLine[0]))) {
|
|
1152
|
+
var MGLine = mergeOverlappedLines(line, curItemLine);
|
|
1153
|
+
temp_MGLines.push(MGLine);
|
|
1154
|
+
}
|
|
1155
|
+
itemLines.splice(idx, 1);
|
|
1156
|
+
} else {
|
|
1157
|
+
temp_MGLines.push(line);
|
|
1158
|
+
}
|
|
1159
|
+
});
|
|
1160
|
+
itemLines.forEach(function (itemLine) {
|
|
1161
|
+
return temp_MGLines.push(itemLine);
|
|
1162
|
+
});
|
|
1163
|
+
MGlines = [].concat(temp_MGLines);
|
|
1164
|
+
};
|
|
1165
|
+
for (var i = 1; i < items.length; i++) {
|
|
1166
|
+
_loop11();
|
|
1167
|
+
}
|
|
1168
|
+
MGlines.forEach(function (line) {
|
|
1169
|
+
molding_totalLength += GeometryUtils.verticesDistance(line[0], line[1]);
|
|
1170
|
+
});
|
|
1171
|
+
});
|
|
1172
|
+
molding_totalLength = convert(molding_totalLength).from('cm').to('in');
|
|
1173
|
+
moldingData.push(_objectSpread(_objectSpread({}, molding), {}, {
|
|
1174
|
+
doorStyle: doorStyle,
|
|
1175
|
+
count: Math.ceil(molding_totalLength * 1.1 / 96)
|
|
1176
|
+
}));
|
|
1177
|
+
}
|
|
1178
|
+
});
|
|
1179
|
+
|
|
1180
|
+
// calc toe kick molding
|
|
1181
|
+
var tmp = [];
|
|
1182
|
+
items.forEach(function (item) {
|
|
1183
|
+
if (item.category === 'cabinet' && !item.cabinet_category.toLowerCase().includes('microwave')) {
|
|
1184
|
+
tmp.push(item);
|
|
1185
|
+
}
|
|
1186
|
+
});
|
|
1187
|
+
var tmpMoldingData = [];
|
|
1188
|
+
var toedoorStyles = [];
|
|
1189
|
+
tmp.map(function (item) {
|
|
1190
|
+
var _item$molding2;
|
|
1191
|
+
if (item.layoutpos === BASE_CABINET_LAYOUTPOS && (isEmpty(item.molding) || ((_item$molding2 = item.molding) === null || _item$molding2 === void 0 ? void 0 : _item$molding2.length) < 1 || !isEnableItemForMolding(layer, item))) {
|
|
1192
|
+
var w = item.properties.get('width').get('_length');
|
|
1193
|
+
var wUnit = item.properties.get('width').get('_unit') || 'cm';
|
|
1194
|
+
w = convert(w / 2).from(wUnit).to('cm');
|
|
1195
|
+
var h = item.properties.get('depth').get('_length');
|
|
1196
|
+
var hUnit = item.properties.get('depth').get('_unit') || 'cm';
|
|
1197
|
+
h = convert(h / 2).from(hUnit).to('cm');
|
|
1198
|
+
var outline = null;
|
|
1199
|
+
var element = catalog.elements[item.get('type')];
|
|
1200
|
+
if (!element) element = catalog.elements[returnReplaceableDeepSearchType(item.get('type'))];
|
|
1201
|
+
outline = element.info.outline;
|
|
1202
|
+
var len = 0;
|
|
1203
|
+
if (outline) {
|
|
1204
|
+
// Extract Points from `outline`
|
|
1205
|
+
var outlinePaths = outline.paths;
|
|
1206
|
+
var outlineWidth = outline.svgWidth;
|
|
1207
|
+
var outlineHeight = outline.svgHeight;
|
|
1208
|
+
var outlinePoints = []; // Hold Points Of SVG
|
|
1209
|
+
var _iterator5 = _createForOfIteratorHelper(outlinePaths),
|
|
1210
|
+
_step5;
|
|
1211
|
+
try {
|
|
1212
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
1213
|
+
var path = _step5.value;
|
|
1214
|
+
var _iterator6 = _createForOfIteratorHelper(path.subPaths),
|
|
1215
|
+
_step6;
|
|
1216
|
+
try {
|
|
1217
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
1218
|
+
var subPath = _step6.value;
|
|
1219
|
+
outlinePoints = outlinePoints.concat(subPath.getPoints());
|
|
1220
|
+
}
|
|
1221
|
+
} catch (err) {
|
|
1222
|
+
_iterator6.e(err);
|
|
1223
|
+
} finally {
|
|
1224
|
+
_iterator6.f();
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
} catch (err) {
|
|
1228
|
+
_iterator5.e(err);
|
|
1229
|
+
} finally {
|
|
1230
|
+
_iterator5.f();
|
|
1231
|
+
}
|
|
1232
|
+
var maxX = outlinePoints[0].x,
|
|
1233
|
+
minX = outlinePoints[0].x;
|
|
1234
|
+
var maxY = outlinePoints[0].y,
|
|
1235
|
+
minY = outlinePoints[0].y;
|
|
1236
|
+
outlinePoints.forEach(function (point) {
|
|
1237
|
+
if (point.x > maxX) {
|
|
1238
|
+
maxX = point.x;
|
|
1239
|
+
}
|
|
1240
|
+
if (point.x < minX) {
|
|
1241
|
+
minX = point.x;
|
|
1242
|
+
}
|
|
1243
|
+
if (point.y > maxY) {
|
|
1244
|
+
maxY = point.y;
|
|
1245
|
+
}
|
|
1246
|
+
if (point.y < minY) {
|
|
1247
|
+
minY = point.y;
|
|
1248
|
+
}
|
|
1249
|
+
});
|
|
1250
|
+
outlinePoints.forEach(function (point) {
|
|
1251
|
+
if (GeometryUtils.isPointInRect([{
|
|
1252
|
+
x: minX,
|
|
1253
|
+
y: minY
|
|
1254
|
+
}, {
|
|
1255
|
+
x: minX,
|
|
1256
|
+
y: maxY
|
|
1257
|
+
}, {
|
|
1258
|
+
x: maxX,
|
|
1259
|
+
y: maxY
|
|
1260
|
+
}, {
|
|
1261
|
+
x: maxX,
|
|
1262
|
+
y: minY
|
|
1263
|
+
}], point)) {
|
|
1264
|
+
if (point.x > 10) len += (point.x / outlineWidth - 0.5) * w * 2 + h * 2 - (point.y / outlineHeight - 0.5) * h * 2;
|
|
1265
|
+
}
|
|
1266
|
+
});
|
|
1267
|
+
len = convert(len).from('cm').to('in');
|
|
1268
|
+
} else {
|
|
1269
|
+
w = convert(w * 2).from('cm').to('in');
|
|
1270
|
+
len += w;
|
|
1271
|
+
}
|
|
1272
|
+
var doorIndex = toedoorStyles.findIndex(function (a) {
|
|
1273
|
+
var iDS = item === null || item === void 0 ? void 0 : item.doorStyle;
|
|
1274
|
+
if (!iDS) return false;
|
|
1275
|
+
if (!iDS.hasOwnProperty('id')) {
|
|
1276
|
+
iDS = iDS.toJS();
|
|
1277
|
+
}
|
|
1278
|
+
return a.doorStyle.id === iDS.id && isEqualInstallationType(a.doorStyle, iDS);
|
|
1279
|
+
});
|
|
1280
|
+
if (doorIndex > -1) {
|
|
1281
|
+
toedoorStyles[doorIndex].totalLength += len;
|
|
1282
|
+
} else {
|
|
1283
|
+
toedoorStyles.push({
|
|
1284
|
+
doorStyle: item.doorStyle.hasOwnProperty('id') ? item.doorStyle : item.doorStyle && item.doorStyle.toJS(),
|
|
1285
|
+
totalLength: len
|
|
1286
|
+
});
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
});
|
|
1290
|
+
toedoorStyles.forEach(function (doorStyle) {
|
|
1291
|
+
var skuName = getToeKickSKU(doorStyle.doorStyle, catalog);
|
|
1292
|
+
var thumbnail = skuName ? skuName : '';
|
|
1293
|
+
// moldings.forEach(molding => {
|
|
1294
|
+
// if (
|
|
1295
|
+
// molding.name ===
|
|
1296
|
+
// getToeKickSKU(
|
|
1297
|
+
// doorStyle.doorStyle,
|
|
1298
|
+
// catalog,
|
|
1299
|
+
// true
|
|
1300
|
+
// )
|
|
1301
|
+
// )
|
|
1302
|
+
// thumbnail = molding.thumbnail;
|
|
1303
|
+
// });
|
|
1304
|
+
|
|
1305
|
+
doorStyle.totalLength && tmpMoldingData.push({
|
|
1306
|
+
name: TOE_KICK_MOLDING,
|
|
1307
|
+
sku: getToeKickSKU(doorStyle.doorStyle, catalog),
|
|
1308
|
+
thumbnail: thumbnail,
|
|
1309
|
+
category: 'molding',
|
|
1310
|
+
type: 'cabinet',
|
|
1311
|
+
doorStyle: doorStyle.doorStyle,
|
|
1312
|
+
count: Math.ceil(doorStyle.totalLength * 1.1 / 96)
|
|
1313
|
+
});
|
|
1314
|
+
});
|
|
1315
|
+
if (tmpMoldingData.length > 0) moldingData = [].concat(_toConsumableArray(moldingData), tmpMoldingData);
|
|
1316
|
+
return moldingData;
|
|
869
1317
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { convert } from "../utils/convert-units-lite.js";
|
|
2
|
+
import { UNIT_CENTIMETER, UNIT_INCH, UNIT_MILLIMETER } from "../constants";
|
|
3
|
+
|
|
4
|
+
// Below this length, the measurement LINE is hidden
|
|
5
|
+
var MIN_LENGTH_TO_SHOW_RULER_LINE_INCH = 13;
|
|
6
|
+
|
|
7
|
+
// Below this length, the measurement VALUE (text) is hidden
|
|
8
|
+
var MIN_LENGTH_TO_SHOW_RULER_VALUE_INCH = 5;
|
|
9
|
+
function formatDistance(value, fixed) {
|
|
10
|
+
// format with fixed decimals first
|
|
11
|
+
var text = value.toFixed(fixed);
|
|
12
|
+
|
|
13
|
+
// remove trailing zeros AFTER decimal, then remove trailing dot if needed
|
|
14
|
+
// examples:
|
|
15
|
+
// 2.00 -> 2
|
|
16
|
+
// 2.50 -> 2.5
|
|
17
|
+
// 200.00 -> 200
|
|
18
|
+
text = text.replace(/\.?0+$/, '');
|
|
19
|
+
return text;
|
|
20
|
+
}
|
|
21
|
+
function getUnitString(unit) {
|
|
22
|
+
if (unit === 'cm' || unit === 'mm') return '';
|
|
23
|
+
if (unit === 'in') return '"';
|
|
24
|
+
return unit;
|
|
25
|
+
}
|
|
26
|
+
export function getRulerDisplayData(_ref) {
|
|
27
|
+
var length = _ref.length,
|
|
28
|
+
unit = _ref.unit,
|
|
29
|
+
rulerUnit = _ref.rulerUnit,
|
|
30
|
+
layerUnit = _ref.layerUnit,
|
|
31
|
+
_ref$charWidth = _ref.charWidth,
|
|
32
|
+
charWidth = _ref$charWidth === void 0 ? 8 : _ref$charWidth;
|
|
33
|
+
// 7.62 cm -> ruLength 2.99 in
|
|
34
|
+
var ruLength = convert(length).from(unit).to(rulerUnit);
|
|
35
|
+
var fixedLength = layerUnit === UNIT_MILLIMETER ? 0 : layerUnit === UNIT_CENTIMETER ? 1 : 2;
|
|
36
|
+
|
|
37
|
+
// 2.99 in -> valueInLayerUnit 2.99 in
|
|
38
|
+
var valueInLayerUnit = convert(ruLength).from(rulerUnit).to(layerUnit);
|
|
39
|
+
|
|
40
|
+
// 2.99 -> "3"
|
|
41
|
+
var distanceText = formatDistance(valueInLayerUnit, fixedLength);
|
|
42
|
+
var unitStr = getUnitString(layerUnit);
|
|
43
|
+
var textCount = distanceText.length + unitStr.length;
|
|
44
|
+
// textLength = (3 + ") * 8 = 16
|
|
45
|
+
var textLength = textCount * charWidth;
|
|
46
|
+
|
|
47
|
+
// lengthInInch = 7.62 cm -> 2.99 inch
|
|
48
|
+
var lengthInInch = convert(length).from(unit).to(UNIT_INCH);
|
|
49
|
+
var bShowText = lengthInInch > MIN_LENGTH_TO_SHOW_RULER_VALUE_INCH && length - textLength + 24 > 0;
|
|
50
|
+
var bShowLine = lengthInInch > MIN_LENGTH_TO_SHOW_RULER_LINE_INCH && length - textLength - 8 > 0;
|
|
51
|
+
return {
|
|
52
|
+
distanceText: distanceText,
|
|
53
|
+
unitStr: unitStr,
|
|
54
|
+
textLength: textLength,
|
|
55
|
+
bShowText: bShowText,
|
|
56
|
+
bShowLine: bShowLine
|
|
57
|
+
};
|
|
58
|
+
}
|
package/lib/AppContext.js
CHANGED
|
@@ -6,6 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports["default"] = void 0;
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
var AppContext = /*#__PURE__*/_react["default"].createContext(
|
|
9
|
+
var AppContext = /*#__PURE__*/_react["default"].createContext({});
|
|
10
10
|
var _default = exports["default"] = AppContext;
|
|
11
11
|
module.exports = exports.default;
|