kitchen-simulator 4.0.6 → 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.
Files changed (47) hide show
  1. package/es/actions/project-actions.js +2 -1
  2. package/es/catalog/factories/wall-factory.js +1 -1
  3. package/es/catalog/utils/exporter.js +23 -11
  4. package/es/catalog/utils/item-loader.js +4 -9
  5. package/es/class/item.js +3 -0
  6. package/es/class/layer.js +1 -1
  7. package/es/class/project.js +9 -7
  8. package/es/components/viewer2d/line.js +5 -5
  9. package/es/components/viewer2d/ruler.js +16 -13
  10. package/es/components/viewer2d/rulerDist.js +38 -52
  11. package/es/components/viewer2d/viewer2d.js +10 -5
  12. package/es/components/viewer3d/scene-creator.js +213 -53
  13. package/es/components/viewer3d/viewer3d.js +21 -14
  14. package/es/constants.js +1 -0
  15. package/es/index.js +26 -5
  16. package/es/models.js +10 -6
  17. package/es/reducers/project-reducer.js +1 -1
  18. package/es/reducers/viewer2d-reducer.js +3 -1
  19. package/es/reducers/viewer3d-reducer.js +3 -1
  20. package/es/utils/geometry.js +7 -7
  21. package/es/utils/isolate-event-handler.js +8 -8
  22. package/es/utils/molding.js +4 -2
  23. package/es/utils/ruler.js +58 -0
  24. package/lib/actions/project-actions.js +2 -1
  25. package/lib/catalog/factories/wall-factory.js +1 -1
  26. package/lib/catalog/utils/exporter.js +23 -11
  27. package/lib/catalog/utils/item-loader.js +4 -9
  28. package/lib/class/item.js +3 -0
  29. package/lib/class/layer.js +1 -1
  30. package/lib/class/project.js +9 -7
  31. package/lib/components/viewer2d/line.js +5 -5
  32. package/lib/components/viewer2d/ruler.js +15 -12
  33. package/lib/components/viewer2d/rulerDist.js +38 -52
  34. package/lib/components/viewer2d/viewer2d.js +10 -5
  35. package/lib/components/viewer3d/scene-creator.js +212 -52
  36. package/lib/components/viewer3d/viewer3d.js +21 -14
  37. package/lib/constants.js +5 -4
  38. package/lib/index.js +28 -5
  39. package/lib/models.js +10 -6
  40. package/lib/reducers/project-reducer.js +1 -1
  41. package/lib/reducers/viewer2d-reducer.js +3 -1
  42. package/lib/reducers/viewer3d-reducer.js +3 -1
  43. package/lib/utils/geometry.js +7 -7
  44. package/lib/utils/isolate-event-handler.js +8 -8
  45. package/lib/utils/molding.js +4 -2
  46. package/lib/utils/ruler.js +63 -0
  47. package/package.json +1 -1
package/es/models.js CHANGED
@@ -358,6 +358,7 @@ export var Catalog = /*#__PURE__*/function (_Record10) {
358
358
  return _createClass(Catalog, [{
359
359
  key: "factoryElement",
360
360
  value: function factoryElement(type, options, initialProperties, state) {
361
+ var _element$structure_js, _element$structure_js2, _element$structure_js3, _element$structure_js4, _element$structure_js5, _element$structure_js6;
361
362
  if (!this.elements.has(type)) {
362
363
  var catList = this.elements.map(function (element) {
363
364
  return element.name;
@@ -365,6 +366,9 @@ export var Catalog = /*#__PURE__*/function (_Record10) {
365
366
  throw new Error("Element ".concat(type, " does not exist in catalog ").concat(catList));
366
367
  }
367
368
  var element = this.elements.get(type);
369
+ var widthUnit = (_element$structure_js = element === null || element === void 0 || (_element$structure_js2 = element.structure_json) === null || _element$structure_js2 === void 0 ? void 0 : _element$structure_js2.width_unit) !== null && _element$structure_js !== void 0 ? _element$structure_js : 'in';
370
+ var heightUnit = (_element$structure_js3 = element === null || element === void 0 || (_element$structure_js4 = element.structure_json) === null || _element$structure_js4 === void 0 ? void 0 : _element$structure_js4.height_unit) !== null && _element$structure_js3 !== void 0 ? _element$structure_js3 : 'in';
371
+ var lengthUnit = (_element$structure_js5 = element === null || element === void 0 || (_element$structure_js6 = element.structure_json) === null || _element$structure_js6 === void 0 ? void 0 : _element$structure_js6.length_unit) !== null && _element$structure_js5 !== void 0 ? _element$structure_js5 : 'in';
368
372
  var properties = element.properties.map(function (value, key) {
369
373
  return initialProperties && initialProperties.has(key) ? initialProperties.get(key) : value.get('defaultValue');
370
374
  });
@@ -391,18 +395,18 @@ export var Catalog = /*#__PURE__*/function (_Record10) {
391
395
  var _sizeinfo = {
392
396
  width: new Map({
393
397
  _length: temp.width,
394
- _unit: 'in',
395
- length: convert(temp.width).from('in').to('cm')
398
+ _unit: widthUnit,
399
+ length: convert(temp.width).from(widthUnit).to('cm') // unit of size in dataBundle is inch
396
400
  }),
397
401
  height: new Map({
398
402
  _length: temp.height,
399
- _unit: 'in',
400
- length: convert(temp.height).from('in').to('cm')
403
+ _unit: heightUnit,
404
+ length: convert(temp.height).from(heightUnit).to('cm')
401
405
  }),
402
406
  depth: new Map({
403
407
  _length: temp.depth,
404
- _unit: 'in',
405
- length: convert(temp.depth).from('in').to('cm')
408
+ _unit: lengthUnit,
409
+ length: convert(temp.depth).from(lengthUnit).to('cm')
406
410
  })
407
411
  };
408
412
  properties = properties.set('width', _sizeinfo.width).set('height', _sizeinfo.height).set('depth', _sizeinfo.depth);
@@ -129,7 +129,7 @@ export default function (state, action) {
129
129
  state = state.merge({
130
130
  sceneHistory: history.historyPush(state.sceneHistory, state.scene)
131
131
  });
132
- return Project.createRoomWithShape(state, action.roomShapeType, action.width, action.height, action.doorStyle).updatedState;
132
+ return Project.createRoomWithShape(state, action.roomShapeType, action.width, action.height, action.measurementUnit, action.doorStyle).updatedState;
133
133
  default:
134
134
  return state;
135
135
  }
@@ -29,8 +29,10 @@ export default function (state, action) {
29
29
  if (item.type.includes('Light')) {
30
30
  var height = item.properties.getIn(['height', '_length']);
31
31
  var heightUnit = item.properties.getIn(['height', '_unit']);
32
- var newAltitude = action.value - convert(height).from(heightUnit).to('in');
32
+ var newAltitude = convert(action.value).from(_layer.unit).to('in') - convert(height).from(heightUnit).to('in');
33
33
  item = item.setIn(['properties', 'altitude', '_length'], convert(newAltitude).from('in').to(_layer.unit));
34
+ item = item.setIn(['properties', 'altitude', '_unit'], _layer.unit);
35
+ item = item.setIn(['properties', 'altitude', 'length'], convert(newAltitude).from('in').to('cm'));
34
36
  }
35
37
  return item;
36
38
  });
@@ -34,8 +34,10 @@ export default function (state, action) {
34
34
  if (item.type.includes('Light')) {
35
35
  var height = item.properties.getIn(['height', '_length']);
36
36
  var heightUnit = item.properties.getIn(['height', '_unit']);
37
- var newAltitude = action.value - convert(height).from(heightUnit).to('in');
37
+ var newAltitude = convert(action.value).from(_layer.unit).to('in') - convert(height).from(heightUnit).to('in');
38
38
  item = item.setIn(['properties', 'altitude', '_length'], convert(newAltitude).from('in').to(_layer.unit));
39
+ item = item.setIn(['properties', 'altitude', '_unit'], _layer.unit);
40
+ item = item.setIn(['properties', 'altitude', 'length'], convert(newAltitude).from('in').to('cm'));
39
41
  }
40
42
  return item;
41
43
  });
@@ -741,9 +741,9 @@ export function getAllItemSpecified(scene, catalog, filter) {
741
741
  var info = cat === null || cat === void 0 ? void 0 : cat.info;
742
742
  var props = item.properties;
743
743
  var getSize = function getSize(key) {
744
- var _props$getIn;
744
+ var _props$getIn, _props$getIn2, _props$getIn3;
745
745
  var length = props === null || props === void 0 || (_props$getIn = props.getIn) === null || _props$getIn === void 0 ? void 0 : _props$getIn.call(props, [key, '_length']);
746
- return length != null ? convert(length).from('in').to(scene.unit) : 0;
746
+ return length != null ? convert(length).from((_props$getIn2 = props === null || props === void 0 || (_props$getIn3 = props.getIn) === null || _props$getIn3 === void 0 ? void 0 : _props$getIn3.call(props, [key, '_unit'])) !== null && _props$getIn2 !== void 0 ? _props$getIn2 : 'in').to(scene.unit) : 0;
747
747
  };
748
748
  val.size = {
749
749
  width: getSize('width'),
@@ -2486,7 +2486,7 @@ function getAllItems2(curItem, layer) {
2486
2486
  var itemTall = convert(item.properties.getIn(['height', '_length'])).from(item.get('properties').get('height').get('_unit')).to('cm');
2487
2487
  var zMinItem = convert(item.properties.getIn(['altitude', '_length'])).from(item.get('properties').get('altitude').get('_unit')).to('cm');
2488
2488
  var zMaxItem = zMinItem + itemTall;
2489
- if (zMinItem >= zMinCurItem && zMinItem < zMaxCurItem || zMinCurItem >= zMinItem && zMinCurItem < zMaxItem) detectObjectsAtSameAltitudeFlag = true;
2489
+ if (zMinItem - zMinCurItem >= 0 && zMaxCurItem - zMinItem > EPSILON || zMinCurItem - zMinItem >= 0 && zMaxItem - zMinCurItem > EPSILON) detectObjectsAtSameAltitudeFlag = true;
2490
2490
  if (detectObjectsAtSameAltitudeFlag) {
2491
2491
  var x = val.pos.x;
2492
2492
  var y = val.pos.y;
@@ -2550,10 +2550,10 @@ export function calcDistancesFromItemToWalls(curItem, layer) {
2550
2550
  height: height
2551
2551
  };
2552
2552
  var curiteminfo = getCalcRectFromItem2(itemInfo);
2553
- var allItemRect = getAllItems2(curItem, layer);
2554
- var allLines = getAllLines(layer);
2555
- var allLineRects = buildRectFromLines(layer, allLines);
2556
- var allRect = allLineRects.concat(allItemRect.others);
2553
+ var allItemRect = getAllItems2(curItem, layer); // get all item edge rects
2554
+ var allLines = getAllLines(layer); // get all wall lines
2555
+ var allLineRects = buildRectFromLines(layer, allLines); // make line rects from wall lines
2556
+ var allRect = allLineRects.concat(allItemRect.others); // item edges + wall lines
2557
2557
  var _loop = function _loop(i) {
2558
2558
  // [rectCenterPoint] has four middle points of cabinet rect edges
2559
2559
  var centerpoint = curiteminfo.rectCenterPoint[i];
@@ -1234,7 +1234,7 @@ export function handleExternalEvent(_x10) {
1234
1234
  function _handleExternalEvent() {
1235
1235
  _handleExternalEvent = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee0(props) {
1236
1236
  var _evt$payload3, _evt$payload4;
1237
- var evt, state, layerId, layer, _evt$payload, cdsItems, itemKeys, _loop6, i, newScene, _props$onInternalEven, sLineCnt, element, _state$viewer2D, _evt$payload$initialP, mouseX, mouseY, v2d, vPosX, vPosY, layerID, defaulTitle, _Object$keys, _evt$payload5, doorStyle, itemCDS, isAll, _layerId, _cdsItems, allItems, selectedItemId, _itemKeys, _loop7, _i2, _props$onInternalEven2, _evt$payload6, roomShapeType, width, height, _doorStyle, value, _value, _evt$payload7, moldingInfo, isGlobal, distElement, _distElement, _evt$payload8, option, _value2, _layerId2, _layer, _layer$getIn, selectedLines, selectedHoles, selectedItems, _i4, _i5, _i6, _evt$payload9, _evt$payload0, _evt$payload1, _evt$payload10, _layerID, _layer2, orginalItemInfo, originalItem, originalItemPos, replaceItem, _props$onInternalEven3, sceneData, currentTexture, _t5, _t6;
1237
+ var evt, state, layerId, layer, _evt$payload, _state$catalog, cdsItems, itemKeys, _loop6, i, newScene, tempState, _props$onInternalEven, sLineCnt, element, _state$viewer2D, _evt$payload$initialP, mouseX, mouseY, v2d, vPosX, vPosY, layerID, defaulTitle, _Object$keys, _evt$payload5, doorStyle, itemCDS, isAll, _layerId, _cdsItems, allItems, selectedItemId, _itemKeys, _loop7, _i2, _props$onInternalEven2, _evt$payload6, roomShapeType, width, height, measurementUnit, _doorStyle, value, _value, _evt$payload7, moldingInfo, isGlobal, distElement, _distElement, _evt$payload8, option, _value2, _layerId2, _layer, _layer$getIn, selectedLines, selectedHoles, selectedItems, _i4, _i5, _i6, _evt$payload9, _evt$payload0, _evt$payload1, _evt$payload10, _layerID, _layer2, orginalItemInfo, originalItem, originalItemPos, replaceItem, _props$onInternalEven3, sceneData, currentTexture, _t5, _t6;
1238
1238
  return _regeneratorRuntime.wrap(function (_context11) {
1239
1239
  while (1) switch (_context11.prev = _context11.next) {
1240
1240
  case 0:
@@ -1302,10 +1302,10 @@ function _handleExternalEvent() {
1302
1302
  break;
1303
1303
  case 5:
1304
1304
  newScene = new Scene(evt === null || evt === void 0 ? void 0 : evt.payload);
1305
- state = new State({
1306
- scene: newScene.toJS()
1307
- });
1308
- // request item catalog data to host app
1305
+ tempState = new State({
1306
+ scene: newScene.toJS(),
1307
+ catalog: (_state$catalog = state.catalog) === null || _state$catalog === void 0 ? void 0 : _state$catalog.toJS()
1308
+ }); // request item catalog data to host app
1309
1309
  if (cdsItems.length > 0) {
1310
1310
  (_props$onInternalEven = props.onInternalEvent) === null || _props$onInternalEven === void 0 || _props$onInternalEven.call(props, {
1311
1311
  type: INTERNAL_EVENT_ITEMS_CATALOG,
@@ -1326,7 +1326,7 @@ function _handleExternalEvent() {
1326
1326
  break;
1327
1327
  }
1328
1328
  _context9.next = 2;
1329
- return addItemToCatalog(rt[_i], state, props.catalog, props.projectActions);
1329
+ return addItemToCatalog(rt[_i], tempState, props.catalog, props.projectActions);
1330
1330
  case 2:
1331
1331
  _i++;
1332
1332
  _context9.next = 1;
@@ -1492,8 +1492,8 @@ function _handleExternalEvent() {
1492
1492
  } else props.itemsActions.setDoorStyle(doorStyle, itemCDS, isAll);
1493
1493
  return _context11.abrupt("continue", 45);
1494
1494
  case 21:
1495
- _evt$payload6 = evt.payload, roomShapeType = _evt$payload6.roomShapeType, width = _evt$payload6.width, height = _evt$payload6.height, _doorStyle = _evt$payload6.doorStyle;
1496
- props.projectActions.createRoomWithShape(roomShapeType, width, height, _doorStyle);
1495
+ _evt$payload6 = evt.payload, roomShapeType = _evt$payload6.roomShapeType, width = _evt$payload6.width, height = _evt$payload6.height, measurementUnit = _evt$payload6.measurementUnit, _doorStyle = _evt$payload6.doorStyle;
1496
+ props.projectActions.createRoomWithShape(roomShapeType, width, height, measurementUnit, _doorStyle);
1497
1497
  return _context11.abrupt("continue", 45);
1498
1498
  case 22:
1499
1499
  value = state.getIn(['viewer2D']).toJS();
@@ -305,6 +305,7 @@ export function getLinesOfItem(item, allLineRects, catalog) {
305
305
  return lines;
306
306
  }
307
307
  export function getLinesOfItem2(item, allLineRects, catalog) {
308
+ var _lines;
308
309
  var lines = [];
309
310
  var outline = null;
310
311
  var element = catalog.elements[item.get('type')];
@@ -317,8 +318,9 @@ export function getLinesOfItem2(item, allLineRects, catalog) {
317
318
  var hUnit = item.properties.get('depth').get('_unit') || 'cm';
318
319
  newDepth = convert(newDepth).from(hUnit).to('cm');
319
320
  if (item) {
321
+ var _element;
320
322
  // Get Outline Data of Selected Item
321
- outline = element.info.outline;
323
+ outline = (_element = element) === null || _element === void 0 ? void 0 : _element.info.outline;
322
324
  if (outline) {
323
325
  // Extract Points from `outline`
324
326
  var outlinePaths = outline.paths;
@@ -359,7 +361,7 @@ export function getLinesOfItem2(item, allLineRects, catalog) {
359
361
  }
360
362
  }
361
363
  }
362
- lines = lines.filter(function (line) {
364
+ lines = (_lines = lines) === null || _lines === void 0 ? void 0 : _lines.filter(function (line) {
363
365
  return !GeometryUtils.isSnappedLine({
364
366
  rect: [{
365
367
  x: 0,
@@ -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
+ }
@@ -339,11 +339,12 @@ function selectAll() {
339
339
  value: value
340
340
  };
341
341
  }
342
- function createRoomWithShape(roomShapeType, width, height, doorStyle) {
342
+ function createRoomWithShape(roomShapeType, width, height, measurementUnit, doorStyle) {
343
343
  return {
344
344
  type: _constants.CREATE_ROOM_WITH_SHAPE,
345
345
  width: width,
346
346
  height: height,
347
+ measurementUnit: measurementUnit,
347
348
  roomShapeType: roomShapeType,
348
349
  doorStyle: doorStyle
349
350
  };
@@ -27,7 +27,7 @@ var STYLE_LINE = {
27
27
  // strokeWidth:1
28
28
  };
29
29
  var STYLE_INTERIOR_LINE = {
30
- strokeWidth: 2,
30
+ strokeWidth: 4,
31
31
  stroke: SharedStyle.INTERIOR_LINE.unselected
32
32
  };
33
33
  var STYLE_INTERIOR_LINE_SELECTED = {
@@ -27,9 +27,18 @@ function _default(_ref) {
27
27
  alti = _ref.alti,
28
28
  obj_property = _ref.obj_property,
29
29
  outlineSVGData = _ref.outlineSVGData,
30
- cds = _ref.cds;
30
+ cds = _ref.cds,
31
+ _ref$width_unit = _ref.width_unit,
32
+ width_unit = _ref$width_unit === void 0 ? 'in' : _ref$width_unit,
33
+ _ref$height_unit = _ref.height_unit,
34
+ height_unit = _ref$height_unit === void 0 ? 'in' : _ref$height_unit,
35
+ _ref$length_unit = _ref.length_unit,
36
+ length_unit = _ref$length_unit === void 0 ? 'in' : _ref$length_unit;
37
+ var widthUnit = width_unit === 'inch' ? 'in' : width_unit;
38
+ var heightUnit = height_unit === 'inch' ? 'in' : height_unit;
39
+ var lengthUnit = length_unit === 'inch' ? 'in' : length_unit;
31
40
  var _length = alti || 0;
32
- var length = (0, _convertUnitsLite.convert)(_length).from('in').to('cm');
41
+ var length = (0, _convertUnitsLite.convert)(_length).from(lengthUnit).to('cm');
33
42
  // const length = _length;
34
43
 
35
44
  var additional_props = [];
@@ -40,8 +49,8 @@ function _default(_ref) {
40
49
  type: 'length-measure',
41
50
  defaultValue: {
42
51
  _length: sizeinfo.width,
43
- _unit: 'in',
44
- length: (0, _convertUnitsLite.convert)(sizeinfo.width).from('in').to('cm')
52
+ _unit: widthUnit,
53
+ length: (0, _convertUnitsLite.convert)(sizeinfo.width).from(widthUnit).to('cm')
45
54
  }
46
55
  }
47
56
  };
@@ -53,8 +62,8 @@ function _default(_ref) {
53
62
  type: 'length-measure',
54
63
  defaultValue: {
55
64
  _length: sizeinfo.width,
56
- _unit: 'in',
57
- length: (0, _convertUnitsLite.convert)(sizeinfo.width).from('in').to('cm')
65
+ _unit: widthUnit,
66
+ length: (0, _convertUnitsLite.convert)(sizeinfo.width).from(widthUnit).to('cm')
58
67
  }
59
68
  },
60
69
  depth: {
@@ -62,8 +71,8 @@ function _default(_ref) {
62
71
  type: 'length-measure',
63
72
  defaultValue: {
64
73
  _length: sizeinfo.depth,
65
- _unit: 'in',
66
- length: (0, _convertUnitsLite.convert)(sizeinfo.depth).from('in').to('cm')
74
+ _unit: lengthUnit,
75
+ length: (0, _convertUnitsLite.convert)(sizeinfo.depth).from(lengthUnit).to('cm')
67
76
  }
68
77
  },
69
78
  height: {
@@ -71,8 +80,8 @@ function _default(_ref) {
71
80
  type: 'length-measure',
72
81
  defaultValue: {
73
82
  _length: sizeinfo.height,
74
- _unit: 'in',
75
- length: (0, _convertUnitsLite.convert)(sizeinfo.height).from('in').to('cm')
83
+ _unit: heightUnit,
84
+ length: (0, _convertUnitsLite.convert)(sizeinfo.height).from(heightUnit).to('cm')
76
85
  }
77
86
  }
78
87
  };
@@ -104,7 +113,7 @@ function _default(_ref) {
104
113
  type: 'length-measure',
105
114
  defaultValue: {
106
115
  _length: _length,
107
- _unit: 'in',
116
+ _unit: lengthUnit,
108
117
  length: length
109
118
  }
110
119
  },
@@ -145,6 +154,9 @@ function _default(_ref) {
145
154
  obj: obj_property,
146
155
  cds: cds,
147
156
  structure_json: structure_json,
157
+ width_unit: widthUnit,
158
+ length_unit: lengthUnit,
159
+ height_unit: heightUnit,
148
160
  render2D: function render2D(element, layer, scene) {
149
161
  return render2DItem.call(this, element, layer, scene, sizeinfo, layoutpos, is_corner, shape_svg);
150
162
  },
@@ -1015,18 +1015,13 @@ function render3DItem(element, layer, scene, sizeinfo, structure_json, is_corner
1015
1015
  if (!(0, _helper.isEmpty)(doorStyles)) {
1016
1016
  var _layer$toJS;
1017
1017
  var normalMap = doorStyles.get('base') || INITIAL_NORMAL_MAP;
1018
- if ((0, _helper.isEmpty)(counterTop.uri)) {
1019
- try {
1020
- counterTop = counterTop.toJS();
1021
- } catch (error) {
1022
- //@todo THIS IS A TEMPORARY FIX FOR COUNTERTOP TEXTURE UNDEFINED ISSUE
1023
- counterTop.uri = 'https://media.test.diydesignspace.com/uploads/CountTop/202105074107_5/texture/Unique_Calcatta_texture.jpg';
1024
- console.log(error);
1025
- }
1026
- }
1027
1018
  if ((0, _helper.isEmpty)(counterTop.uri) && !(0, _helper.isEmpty)(layer === null || layer === void 0 || (_layer$toJS = layer.toJS()) === null || _layer$toJS === void 0 ? void 0 : _layer$toJS.counterTop.uri)) {
1028
1019
  counterTop.uri = layer.toJS().counterTop.uri;
1029
1020
  }
1021
+ if ((0, _helper.isEmpty)(counterTop.uri)) {
1022
+ //@todo THIS IS A TEMPORARY FIX FOR COUNTERTOP TEXTURE UNDEFINED ISSUE
1023
+ counterTop.uri = 'https://media.test.diydesignspace.com/uploads/CountTop/202105074107_5/texture/Unique_Calcatta_texture.jpg';
1024
+ }
1030
1025
  var countTopMap = counterTop.uri;
1031
1026
  var interiorMap = doorStyles.get('interior');
1032
1027
  var countT = loadTexture(countTopMap);
package/lib/class/item.js CHANGED
@@ -499,6 +499,9 @@ var Item = exports["default"] = /*#__PURE__*/function () {
499
499
  }, {
500
500
  key: "storeDistArray",
501
501
  value: function storeDistArray(state, layerID, itemID, distArray) {
502
+ if ((0, _utils.isEmpty)(distArray)) return {
503
+ updatedState: state
504
+ };
502
505
  var curDistArray = state.getIn(['scene', 'layers', layerID, 'items', itemID, 'distArray']);
503
506
  distArray.forEach(function (dist) {
504
507
  dist[0] < 0 ? dist[0] = 0 : dist[0];
@@ -574,7 +574,7 @@ var Layer = exports["default"] = /*#__PURE__*/function () {
574
574
  return v.id !== vertexID && _export2.GeometryUtils.samePoints(vertex, v) // &&
575
575
  //!v.lines.contains( vertexID ) &&
576
576
  //!v.areas.contains( vertexID )
577
- ;
577
+ ;
578
578
  });
579
579
  if (doubleVertices.isEmpty()) return {
580
580
  updatedState: state
@@ -112,6 +112,8 @@ var Project = exports["default"] = /*#__PURE__*/function () {
112
112
  // sceneJSON && (sceneJSON.layers[layerID] = newlayer);
113
113
  // }
114
114
 
115
+ // check type of ceilHeight and make it to Number
116
+ if (typeof sceneJSON.layers[layerID].ceilHeight !== 'number') sceneJSON.layers[layerID].ceilHeight = Number(sceneJSON.layers[layerID].ceilHeight);
115
117
  var newScene = new _models.Scene(sceneJSON);
116
118
  state = new _models.State({
117
119
  scene: newScene.toJS(),
@@ -177,6 +179,8 @@ var Project = exports["default"] = /*#__PURE__*/function () {
177
179
  // Matching state.doorStyle with layer.doorStyle
178
180
  if (state.getIn(['scene', 'layers', layerID, 'doorStyle'])) {
179
181
  doorStyle = state.getIn(['scene', 'layers', layerID, 'doorStyle']);
182
+ } else if (!(0, _helper.isEmpty)(doorStyle)) {
183
+ state = state.setIn(['scene', 'layers', layerID, 'doorStyle'], doorStyle);
180
184
  }
181
185
  state = state.merge({
182
186
  doorStyle: doorStyle,
@@ -837,11 +841,10 @@ var Project = exports["default"] = /*#__PURE__*/function () {
837
841
  }
838
842
  }, {
839
843
  key: "createRoomWithShape",
840
- value: function createRoomWithShape(state, roomShapeType, width, height, doorStyle) {
844
+ value: function createRoomWithShape(state, roomShapeType, width, height, measurementUnit, doorStyle) {
841
845
  var catalog = state.catalog;
842
- // keep measurement unit, sceneHistory
846
+ // keep sceneHistory
843
847
  var curLayerID = state.scene.selectedLayer;
844
- var layerUnit = state.getIn(['scene', 'layers', curLayerID, 'unit']);
845
848
  var ceilHeight = state.getIn(['scene', 'layers', curLayerID, 'ceilHeight']);
846
849
  var sceneHistory = state.getIn(['sceneHistory']);
847
850
  state = this.newProject(state).updatedState;
@@ -856,8 +859,8 @@ var Project = exports["default"] = /*#__PURE__*/function () {
856
859
  if ((0, _helper.isEmpty)(viewer)) return {
857
860
  updatedState: state
858
861
  };
859
- width = (0, _convertUnitsLite.convert)(width).from(state.getIn(['scene', 'layers', 'layer-1', 'unit'])).to('cm');
860
- height = (0, _convertUnitsLite.convert)(height).from(state.getIn(['scene', 'layers', 'layer-1', 'unit'])).to('cm');
862
+ width = (0, _convertUnitsLite.convert)(width).from(measurementUnit).to('cm');
863
+ height = (0, _convertUnitsLite.convert)(height).from(measurementUnit).to('cm');
861
864
  var halfWidth = width / 2;
862
865
  var halfHeight = height / 2;
863
866
  var viewerWidth = viewer.SVGWidth;
@@ -930,8 +933,7 @@ var Project = exports["default"] = /*#__PURE__*/function () {
930
933
  }
931
934
  }
932
935
 
933
- // copy keeped measurement unit, sceneHistory
934
- state = state.setIn(['scene', 'layers', layerID, 'unit'], layerUnit);
936
+ // copy keeped sceneHistory
935
937
  state = state.setIn(['scene', 'layers', layerID, 'ceilHeight'], ceilHeight);
936
938
  state = state.setIn(['sceneHistory'], sceneHistory);
937
939
  state = (0, _helper.centering2D)(state);
@@ -45,28 +45,28 @@ var STYLE_ROOM_SHAPE = exports.STYLE_ROOM_SHAPE = {
45
45
  var STYLE_DASH = {
46
46
  stroke: _constants.DASH_LINE_COLOR,
47
47
  strokeDasharray: '4 4',
48
- strokeWidth: '2px',
48
+ strokeWidth: '1px',
49
49
  strokeLinecap: 'round'
50
50
  };
51
51
  var STYLE_ROOM_ELEMENT = {
52
52
  fill: _constants.ROOM_ELEMENT_MEASUREMENT_LINE_COLOR,
53
53
  stroke: _constants.ROOM_ELEMENT_MEASUREMENT_LINE_COLOR,
54
- strokeWidth: '2px'
54
+ strokeWidth: '1.5px'
55
55
  };
56
56
  var STYLE_BASE_ITEM = {
57
57
  fill: _constants.BASE_ITEM_MEASUREMENT_LINE_COLOR,
58
58
  stroke: _constants.BASE_ITEM_MEASUREMENT_LINE_COLOR,
59
- strokeWidth: '2px'
59
+ strokeWidth: '1.5px'
60
60
  };
61
61
  var STYLE_WALL_ITEM = {
62
62
  fill: _constants.WALL_ITEM_MEASUREMENT_LINE_COLOR,
63
63
  stroke: _constants.WALL_ITEM_MEASUREMENT_LINE_COLOR,
64
- strokeWidth: '2px'
64
+ strokeWidth: '1.5px'
65
65
  };
66
66
  var STYLE_DISTANCE = {
67
67
  fill: _constants.DISTANCE_MEASUREMENT_LINE_COLOR,
68
68
  stroke: _constants.DISTANCE_MEASUREMENT_LINE_COLOR,
69
- strokeWidth: '2px'
69
+ strokeWidth: '1.5px'
70
70
  };
71
71
  var selectStyle = function selectStyle(element, style) {
72
72
  return element.iFlag ? style : STYLE_DISTANCE;
@@ -7,14 +7,10 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports["default"] = Ruler;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _propTypes = _interopRequireDefault(require("prop-types"));
10
- var _convertUnitsLite = require("../../utils/convert-units-lite");
11
10
  var _idBroker = _interopRequireDefault(require("../../utils/id-broker"));
12
11
  var _constants = require("../../constants");
13
12
  var _line = require("./line");
14
- var STYLE = {
15
- stroke: _constants.TEXT_COLOR_NEUTRAL_7,
16
- strokeWidth: '1px'
17
- };
13
+ var _ruler = require("../../utils/ruler");
18
14
  var BACKGROUNDSTYLE = {
19
15
  fill: 'transparent',
20
16
  fillOpacity: 0.8
@@ -38,13 +34,20 @@ function Ruler(_ref) {
38
34
  rulerUnit = _ref.rulerUnit,
39
35
  transform = _ref.transform,
40
36
  style = _ref.style;
41
- var ruLength = (0, _convertUnitsLite.convert)(length).from(unit).to(rulerUnit);
42
- var fixedLength = layer.unit === _constants.UNIT_METER || layer.unit === _constants.UNIT_FOOT ? 2 : 0;
43
- var distanceText = (Math.round((0, _convertUnitsLite.convert)(ruLength).from(rulerUnit).to(layer.unit) * 100) / 100).toFixed(fixedLength);
44
- var textLength = (distanceText.length + layer.unit.length) * 9;
37
+ var _getRulerDisplayData = (0, _ruler.getRulerDisplayData)({
38
+ length: length,
39
+ unit: unit,
40
+ rulerUnit: rulerUnit,
41
+ layerUnit: layer.unit
42
+ }),
43
+ distanceText = _getRulerDisplayData.distanceText,
44
+ unitStr = _getRulerDisplayData.unitStr,
45
+ textLength = _getRulerDisplayData.textLength,
46
+ bShowText = _getRulerDisplayData.bShowText,
47
+ bShowLine = _getRulerDisplayData.bShowLine;
45
48
  return /*#__PURE__*/_react["default"].createElement("g", {
46
49
  transform: transform
47
- }, /*#__PURE__*/_react["default"].createElement("g", {
50
+ }, bShowText && /*#__PURE__*/_react["default"].createElement("g", {
48
51
  id: "ruler"
49
52
  }, /*#__PURE__*/_react["default"].createElement("rect", {
50
53
  id: "ruler_rect_".concat(_idBroker["default"].acquireID()),
@@ -61,7 +64,7 @@ function Ruler(_ref) {
61
64
  transform: "scale(1, -1)",
62
65
  style: STYLE_TEXT,
63
66
  fill: _constants.TEXT_COLOR_NEUTRAL_7
64
- }, distanceText, layer.unit === 'in' ? '"' : layer.unit)), /*#__PURE__*/_react["default"].createElement("line", {
67
+ }, distanceText, unitStr)), bShowLine && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("line", {
65
68
  x1: style === _line.STYLE_ROOM_SHAPE ? 0 : 4,
66
69
  y1: "0",
67
70
  x2: (length - textLength) / 2 < 0 ? 0 : (length - textLength) / 2,
@@ -79,7 +82,7 @@ function Ruler(_ref) {
79
82
  }), /*#__PURE__*/_react["default"].createElement("polygon", {
80
83
  points: "".concat(length - 3, ", 0, ").concat(length - 6.5, ", 2, ").concat(length - 6.5, ", -2"),
81
84
  style: style
82
- })));
85
+ }))));
83
86
  }
84
87
  Ruler.propTypes = {
85
88
  length: _propTypes["default"].number.isRequired,