kitchen-simulator 2.0.3 → 2.0.4-op-event

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.
@@ -5,20 +5,20 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.handleExternalEvent = handleExternalEvent;
8
- exports.parseTempPlaceholdersFromCabinetPayload = parseTempPlaceholdersFromCabinetPayload;
9
- exports.updateCabinetPayload = updateCabinetPayload;
10
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
12
11
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
12
  var _immutable = require("immutable");
14
13
  var _constants = require("../constants");
15
14
  var _helper = require("./helper");
16
15
  var _exporter = _interopRequireDefault(require("../catalog/utils/exporter"));
17
16
  var _itemLoader = require("../catalog/utils/item-loader");
18
- var _catalog = _interopRequireDefault(require("../catalog/catalog"));
19
- var _models = require("../models");
17
+ var _convertUnitsLite = require("./convert-units-lite");
18
+ var _export = require("./export");
20
19
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
21
20
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
21
+ var PRECISION = 2;
22
22
  var loadSVGsByItem = /*#__PURE__*/function () {
23
23
  var _ref = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee(item) {
24
24
  var _parsed$xml$viewBox, _parsed$xml$viewBox2, response, svgText, loader, parsed, _t;
@@ -74,12 +74,12 @@ var loadSVGsByItem = /*#__PURE__*/function () {
74
74
  var compareSVGRect = function compareSVGRect(value) {
75
75
  return value.e <= 10 && value.e + value.a * value.SVGWidth + 10 >= value.viewerWidth && value.f <= 80 && value.f + value.d * value.SVGHeight + 10 >= value.viewerHeight ? true : false;
76
76
  };
77
- function loadJSON(_x2, _x3, _x4) {
77
+ function loadJSON(_x2) {
78
78
  return _loadJSON.apply(this, arguments);
79
79
  }
80
80
  /********Parse TempPlaceholder from cabinetPayloadData **************/
81
81
  function _loadJSON() {
82
- _loadJSON = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2(path, success, error) {
82
+ _loadJSON = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2(path) {
83
83
  return _regenerator["default"].wrap(function (_context2) {
84
84
  while (1) switch (_context2.prev = _context2.next) {
85
85
  case 0:
@@ -105,7 +105,7 @@ function _loadJSON() {
105
105
  }));
106
106
  return _loadJSON.apply(this, arguments);
107
107
  }
108
- function parseTempPlaceholdersFromCabinetPayload(_x5) {
108
+ function parseTempPlaceholdersFromCabinetPayload(_x3) {
109
109
  return _parseTempPlaceholdersFromCabinetPayload.apply(this, arguments);
110
110
  }
111
111
  /***** Update cabinetPayloadData with updatedTempPlaceholders *****/
@@ -437,7 +437,8 @@ function _parseTempPlaceholdersFromCabinetPayload() {
437
437
  });
438
438
  tempPlaceholdersData.push({
439
439
  id: parseInt(el, 10),
440
- placeholders: tempData
440
+ placeholders: tempData,
441
+ structure: cabinetPayload.structure_json.tempPlaceholders[0].structure
441
442
  });
442
443
  return _context3.abrupt("return", tempPlaceholdersData);
443
444
  case 5:
@@ -448,7 +449,7 @@ function _parseTempPlaceholdersFromCabinetPayload() {
448
449
  }));
449
450
  return _parseTempPlaceholdersFromCabinetPayload.apply(this, arguments);
450
451
  }
451
- function updateCabinetPayload(_x6) {
452
+ function updateCabinetPayload(_x4) {
452
453
  return _updateCabinetPayload.apply(this, arguments);
453
454
  }
454
455
  function _updateCabinetPayload() {
@@ -478,9 +479,9 @@ function _updateCabinetPayload() {
478
479
  }));
479
480
  return _updateCabinetPayload.apply(this, arguments);
480
481
  }
481
- function addItemToCatalog(_x7, _x8, _x9, _x0) {
482
+ function addItemToCatalog(_x5, _x6, _x7, _x8) {
482
483
  return _addItemToCatalog.apply(this, arguments);
483
- }
484
+ } // Get attributs of current selected element
484
485
  function _addItemToCatalog() {
485
486
  _addItemToCatalog = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee5(element, state, catalogInstance, projectActions) {
486
487
  var elementJs, catalog, updatedStructureJson, outlineSVGData;
@@ -526,105 +527,470 @@ function _addItemToCatalog() {
526
527
  }));
527
528
  return _addItemToCatalog.apply(this, arguments);
528
529
  }
530
+ function initAttrData(element, layer, state) {
531
+ element = (0, _typeof2["default"])(element.misc) === 'object' ? element.set('misc', new _immutable.Map(element.misc)) : element;
532
+ switch (element.prototype) {
533
+ case 'items':
534
+ {
535
+ return new _immutable.Map(element);
536
+ }
537
+ case 'lines':
538
+ {
539
+ var v_a = layer.vertices.get(element.vertices.get(0));
540
+ var v_b = layer.vertices.get(element.vertices.get(1));
541
+ var distance = _export.GeometryUtils.pointsDistance(v_a.x, v_a.y, v_b.x, v_b.y);
542
+ var _unit = element.misc.get('_unitLength') || _constants.UNIT_INCH;
543
+ var _length = (0, _convertUnitsLite.convert)(distance).from(_constants.UNIT_CENTIMETER).to(_unit);
544
+ if (state.mode == _constants.MODE_DRAWING_LINE) {
545
+ return new _immutable.Map({
546
+ vertexOne: v_a,
547
+ vertexTwo: v_b,
548
+ lineLength: new _immutable.Map({
549
+ length: distance,
550
+ _length: _length,
551
+ _unit: _unit
552
+ }),
553
+ focus: element.focus
554
+ });
555
+ } else {
556
+ var allLines = layer.lines.toArray();
557
+ var relatedLine = allLines.filter(function (line) {
558
+ return line.vertices.toArray().includes(v_b.id) && line.id != element.id;
559
+ })[0];
560
+ var relatedVertexID = relatedLine && (relatedLine.vertices.toArray()[0] == v_b.id ? relatedLine.vertices.toArray()[1] : relatedLine.vertices.toArray()[0]);
561
+ var v_d = relatedVertexID && layer.getIn(['vertices', relatedVertexID]);
562
+ var lineToExtend = relatedVertexID && allLines.filter(function (line) {
563
+ return line.vertices.toArray().includes(relatedVertexID) && line.id != relatedLine.id;
564
+ })[0];
565
+ var v_c = lineToExtend && layer.getIn(['vertices', lineToExtend.vertices.toArray()[0] == v_d.id ? lineToExtend.vertices.toArray()[1] : lineToExtend.vertices.toArray()[0]]);
566
+ return new _immutable.Map({
567
+ vertexOne: v_a,
568
+ vertexTwo: v_b,
569
+ vertexThree: v_c,
570
+ vertexFour: v_d,
571
+ lineToExtend: lineToExtend,
572
+ lineLength: new _immutable.Map({
573
+ length: distance,
574
+ _length: _length,
575
+ _unit: _unit
576
+ }),
577
+ focus: element.focus
578
+ });
579
+ }
580
+ }
581
+ case 'holes':
582
+ {
583
+ var line = layer.lines.get(element.line);
584
+ var _layer$vertices$get = layer.vertices.get(line.vertices.get(0)),
585
+ x0 = _layer$vertices$get.x,
586
+ y0 = _layer$vertices$get.y;
587
+ var _layer$vertices$get2 = layer.vertices.get(line.vertices.get(1)),
588
+ x1 = _layer$vertices$get2.x,
589
+ y1 = _layer$vertices$get2.y;
590
+ var lineLength = _export.GeometryUtils.pointsDistance(x0, y0, x1, y1);
591
+ var startAt = lineLength * element.offset - element.properties.get('width').get('length') / 2;
592
+ var endAt = lineLength - lineLength * element.offset - element.properties.get('width').get('length') / 2;
593
+ var _unitA = element.misc.get('_unitA') || _constants.UNIT_INCH;
594
+ var _lengthA = (0, _convertUnitsLite.convert)(x0 > x1 ? endAt : startAt).from(_constants.UNIT_CENTIMETER).to(_unitA);
595
+ var _unitB = element.misc.get('_unitB') || _constants.UNIT_INCH;
596
+ var _lengthB = (0, _convertUnitsLite.convert)(x0 > x1 ? startAt : endAt).from(_constants.UNIT_CENTIMETER).to(_unitB);
597
+ return new _immutable.Map({
598
+ offset: element.offset,
599
+ offsetA: new _immutable.Map({
600
+ length: MathUtils.toFixedFloat(x0 > x1 ? endAt : startAt, PRECISION),
601
+ _length: MathUtils.toFixedFloat(_lengthA, PRECISION),
602
+ _unit: _unitA
603
+ }),
604
+ offsetB: new _immutable.Map({
605
+ length: MathUtils.toFixedFloat(x0 > x1 ? startAt : endAt, PRECISION),
606
+ _length: MathUtils.toFixedFloat(_lengthB, PRECISION),
607
+ _unit: _unitB
608
+ })
609
+ });
610
+ }
611
+ case 'areas':
612
+ {
613
+ return new _immutable.Map({});
614
+ }
615
+ default:
616
+ return null;
617
+ }
618
+ }
619
+ function updateAttributeOfSelectedElement(element, attrPayload, state, layer, projectActions) {
620
+ var attributesFormData = initAttrData(element, layer, state);
621
+ var value = attrPayload.value;
622
+ var attributeName = attrPayload.attributeName;
623
+ // pre process
624
+ if (attributeName === _constants.ATT_ITEM_POS) {
625
+ // calculate the new position of movement
626
+ var rotRad = (value.directionAng + element.rotation) / 180 * Math.PI;
627
+ var newX = element.x + (0, _convertUnitsLite.convert)((value.oldDistance - value.newDistance) * Math.cos(rotRad)).from('in').to('cm');
628
+ var newY = element.y + (0, _convertUnitsLite.convert)((value.oldDistance - value.newDistance) * Math.sin(rotRad)).from('in').to('cm');
629
+ // const reversedDirection =
630
+ // value.directionAng === LEFT_DIST_ANG
631
+ // ? RIGHT_DIST_ANG
632
+ // : value.directionAng === RIGHT_DIST_ANG
633
+ // ? LEFT_DIST_ANG
634
+ // : value.directionAng === BACK_DIST_ANG
635
+ // ? FRONT_DIST_ANG
636
+ // : BACK_DIST_ANG;
637
+ // let dist = convert(
638
+ // element.distArray?.find(v => v[1] === reversedDirection)
639
+ // ? element.distArray?.find(v => v[1] === reversedDirection)[0]
640
+ // : 0
641
+ // )
642
+ // .from('cm')
643
+ // .to('in');
644
+ // if (dist + (value.oldDistance - value.newDistance) <= 0 || value.newDistance < 0) {
645
+ // // confirm "The item will be placed outside the floor plan. Are you sure?"
646
+ // setPopupOpen(true);
647
+ // return;
648
+ // }
649
+ value = {
650
+ x: newX,
651
+ y: newY
652
+ };
653
+ } else if (attributeName === _constants.ATT_LINE_LENGTH || attributeName === _constants.ATT_HOLE_OFFSET_A || attributeName === _constants.ATT_HOLE_OFFSET_B) {
654
+ var att = attributesFormData.has(attributeName) ? attributesFormData.get(attributeName) : element[attributeName];
655
+ if (att) value = att.merge({
656
+ _length: value,
657
+ _unit: _constants.UNIT_INCH,
658
+ length: (0, _convertUnitsLite.convert)(value).from(_constants.UNIT_INCH).to(_constants.UNIT_CENTIMETER)
659
+ });
660
+ }
661
+ // make the new attrivutes
662
+ switch (element.prototype) {
663
+ case 'items':
664
+ {
665
+ if (attributeName == _constants.ATT_ITEM_POS) {
666
+ var xVal = value.x;
667
+ var yVal = value.y;
668
+ attributesFormData = attributesFormData.set('x', xVal);
669
+ attributesFormData = attributesFormData.set('y', yVal);
670
+ } else {
671
+ attributesFormData = attributesFormData.set(attributeName, value);
672
+ }
673
+ break;
674
+ }
675
+ case 'lines':
676
+ {
677
+ switch (attributeName) {
678
+ case _constants.ATT_LINE_LENGTH:
679
+ {
680
+ var v_0 = attributesFormData.get('vertexOne');
681
+ var v_1 = attributesFormData.get('vertexTwo');
682
+ var v_b_new = _export.GeometryUtils.extendLine(v_0.x, v_0.y, v_1.x, v_1.y, value.get('length'), PRECISION);
683
+ attributesFormData = attributesFormData.withMutations(function (attr) {
684
+ attr.set('vertexTwo', v_1.merge(v_b_new));
685
+ attr.set('lineLength', value);
686
+ });
687
+ break;
688
+ }
689
+ case _constants.ATT_VERTEXT_ONE:
690
+ case _constants.ATT_VERTEXT_TWO:
691
+ {
692
+ attributesFormData = attributesFormData.withMutations(function (attr) {
693
+ attr.set(attributeName, attr.get(attributeName).merge(value));
694
+ var newDistance = _export.GeometryUtils.verticesDistance(attr.get('vertexOne'), attr.get('vertexTwo'));
695
+ attr.mergeIn(['lineLength'], attr.get('lineLength').merge({
696
+ length: newDistance,
697
+ _length: (0, _convertUnitsLite.convert)(newDistance).from(_constants.UNIT_CENTIMETER).to(attr.get('lineLength').get('_unit'))
698
+ }));
699
+ });
700
+ break;
701
+ }
702
+ default:
703
+ {
704
+ attributesFormData = attributesFormData.set(attributeName, value);
705
+ break;
706
+ }
707
+ }
708
+ break;
709
+ }
710
+ case 'holes':
711
+ {
712
+ switch (attributeName) {
713
+ case _constants.ATT_HOLE_OFFSET_A:
714
+ {
715
+ var line = layer.lines.get(element.line);
716
+ var _layer$vertices$get3 = layer.vertices.get(line.vertices.get(0)),
717
+ x0 = _layer$vertices$get3.x,
718
+ y0 = _layer$vertices$get3.y;
719
+ var _layer$vertices$get4 = layer.vertices.get(line.vertices.get(1)),
720
+ x1 = _layer$vertices$get4.x,
721
+ y1 = _layer$vertices$get4.y;
722
+ var alpha = _export.GeometryUtils.angleBetweenTwoPoints(x0, y0, x1, y1);
723
+ var lineLength = _export.GeometryUtils.pointsDistance(x0, y0, x1, y1);
724
+ var widthLength = element.properties.get('width').get('length');
725
+ var halfWidthLength = widthLength / 2;
726
+ var lengthValue = value.get('length');
727
+ lengthValue = Math.max(lengthValue, 0);
728
+ lengthValue = Math.min(lengthValue, lineLength - widthLength);
729
+ var xp = (lengthValue + halfWidthLength) * Math.cos(alpha) + x0;
730
+ var yp = (lengthValue + halfWidthLength) * Math.sin(alpha) + y0;
731
+ var offset = _export.GeometryUtils.pointPositionOnLineSegment(x0, y0, x1, y1, xp, yp);
732
+ /*
733
+ if (x0 > x1) offset = 1 - offset;
734
+ */
735
+ var endAt = MathUtils.toFixedFloat(lineLength - lineLength * offset - halfWidthLength, PRECISION);
736
+ var offsetUnit = attributesFormData.getIn(['offsetB', '_unit']);
737
+ var offsetB = new _immutable.Map({
738
+ length: endAt,
739
+ _length: (0, _convertUnitsLite.convert)(endAt).from(_constants.UNIT_CENTIMETER).to(offsetUnit),
740
+ _unit: offsetUnit
741
+ });
742
+ attributesFormData = attributesFormData.set('offsetB', offsetB).set('offset', offset);
743
+ var offsetAttribute = new _immutable.Map({
744
+ length: MathUtils.toFixedFloat(lengthValue, PRECISION),
745
+ _unit: value.get('_unit'),
746
+ _length: MathUtils.toFixedFloat((0, _convertUnitsLite.convert)(lengthValue).from(_constants.UNIT_CENTIMETER).to(value.get('_unit')), PRECISION)
747
+ });
748
+ attributesFormData = attributesFormData.set(attributeName, offsetAttribute);
749
+ break;
750
+ }
751
+ case _constants.ATT_HOLE_OFFSET_B:
752
+ {
753
+ var _line = layer.lines.get(element.line);
754
+ var _layer$vertices$get5 = layer.vertices.get(_line.vertices.get(0)),
755
+ _x9 = _layer$vertices$get5.x,
756
+ _y = _layer$vertices$get5.y;
757
+ var _layer$vertices$get6 = layer.vertices.get(_line.vertices.get(1)),
758
+ _x0 = _layer$vertices$get6.x,
759
+ _y2 = _layer$vertices$get6.y;
760
+ var _alpha = _export.GeometryUtils.angleBetweenTwoPoints(_x9, _y, _x0, _y2);
761
+ var _lineLength = _export.GeometryUtils.pointsDistance(_x9, _y, _x0, _y2);
762
+ var _widthLength = element.properties.get('width').get('length');
763
+ var _halfWidthLength = _widthLength / 2;
764
+ var _lengthValue = value.get('length');
765
+ _lengthValue = Math.max(_lengthValue, 0);
766
+ _lengthValue = Math.min(_lengthValue, _lineLength - _widthLength);
767
+ var _xp = _x0 - (_lengthValue + _halfWidthLength) * Math.cos(_alpha);
768
+ var _yp = _y2 - (_lengthValue + _halfWidthLength) * Math.sin(_alpha);
769
+ var _offset = _export.GeometryUtils.pointPositionOnLineSegment(_x9, _y, _x0, _y2, _xp, _yp);
770
+ /*
771
+ if (x0 > x1) offset = 1 - offset;
772
+ */
773
+ var startAt = MathUtils.toFixedFloat(_lineLength * _offset - _halfWidthLength, PRECISION);
774
+ var _offsetUnit = attributesFormData.getIn(['offsetA', '_unit']);
775
+ var offsetA = new _immutable.Map({
776
+ length: startAt,
777
+ _length: (0, _convertUnitsLite.convert)(startAt).from(_constants.UNIT_CENTIMETER).to(_offsetUnit),
778
+ _unit: _offsetUnit
779
+ });
780
+ attributesFormData = attributesFormData.set('offsetA', offsetA).set('offset', _offset);
781
+ var _offsetAttribute = new _immutable.Map({
782
+ length: MathUtils.toFixedFloat(_lengthValue, PRECISION),
783
+ _unit: value.get('_unit'),
784
+ _length: MathUtils.toFixedFloat((0, _convertUnitsLite.convert)(_lengthValue).from(_constants.UNIT_CENTIMETER).to(value.get('_unit')), PRECISION)
785
+ });
786
+ attributesFormData = attributesFormData.set(attributeName, _offsetAttribute);
787
+ break;
788
+ }
789
+ default:
790
+ {
791
+ attributesFormData = attributesFormData.set(attributeName, value);
792
+ break;
793
+ }
794
+ }
795
+ break;
796
+ }
797
+ default:
798
+ break;
799
+ }
800
+
801
+ // update attribute action
802
+ switch (element.prototype) {
803
+ case 'items':
804
+ {
805
+ projectActions.setItemsAttributes(attributesFormData);
806
+ break;
807
+ }
808
+ case 'lines':
809
+ {
810
+ projectActions.setLinesAttributes(attributesFormData);
811
+ break;
812
+ }
813
+ case 'holes':
814
+ {
815
+ projectActions.setHolesAttributes(attributesFormData);
816
+ break;
817
+ }
818
+ }
819
+ }
529
820
  function handleExternalEvent(_x1) {
530
821
  return _handleExternalEvent.apply(this, arguments);
531
822
  }
532
823
  function _handleExternalEvent() {
533
- _handleExternalEvent = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee6(props) {
534
- var evt, state, i, _evt$payload, _evt$payload2, sLineCnt, element, _evt$payload3, moveType, moveValue, value, defaulTitle, _evt$payload4, doorStyle, itemCDS, isAll, _doorStyle, _value, _zoomValue, _value2, _zoomValue2, _evt$payload5, moldingInfo, isGlobal, _evt$payload6, option, _value3, distancePayload, _props$onInternalEven, _t5, _t6;
535
- return _regenerator["default"].wrap(function (_context6) {
536
- while (1) switch (_context6.prev = _context6.next) {
824
+ _handleExternalEvent = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee7(props) {
825
+ var evt, state, _evt$payload, cdsItems, itemKeys, _loop3, i, _props$onInternalEven, sLineCnt, element, _state$viewer2D, _evt$payload$initialP, mouseX, mouseY, v2d, vPosX, vPosY, layerID, _evt$payload3, moveType, moveValue, value, defaulTitle, _evt$payload4, doorStyle, itemCDS, isAll, _doorStyle, _value, _zoomValue, _value2, _zoomValue2, _evt$payload5, moldingInfo, isGlobal, _evt$payload6, option, _value3, layerId, layer, _layer$getIn, selectedLines, selectedHoles, selectedItems, _i2, _i3, _i4, _props$onInternalEven2, _t5, _t6;
826
+ return _regenerator["default"].wrap(function (_context8) {
827
+ while (1) switch (_context8.prev = _context8.next) {
537
828
  case 0:
538
829
  console.log('***external event****', props.externalEvent);
539
830
  evt = props.externalEvent;
540
831
  state = props.state.get('KitchenConfigurator');
541
832
  _t5 = evt === null || evt === void 0 ? void 0 : evt.type;
542
- _context6.next = _t5 === _constants.EXTERNAL_EVENT_LOAD_PROJECT ? 1 : _t5 === _constants.EXTERNAL_EVENT_TOGGLE_TO_3D ? 5 : _t5 === _constants.EXTERNAL_EVENT_TOGGLE_TO_2D ? 6 : _t5 === _constants.EXTERNAL_EVENT_TOGGLE_TO_ELEVATION ? 7 : _t5 === _constants.EXTERNAL_EVENT_ADD_WALL ? 8 : _t5 === _constants.EXTERNAL_EVENT_ADD_ITEM ? 9 : _t5 === _constants.EXTERNAL_EVENT_MOVE_PAN ? 12 : _t5 === _constants.EXTERNAL_EVENT_NEW_PROJECT ? 18 : _t5 === _constants.EXTERNAL_EVENT_CHANGE_DOORSTYLE ? 19 : _t5 === _constants.EXTERNAL_EVENT_SET_INITIAL_DATA ? 20 : _t5 === _constants.EXTERNAL_EVENT_ADD_ROOM_SHAPE ? 21 : _t5 === _constants.EXTERNAL_EVENT_ZOOM_IN ? 22 : _t5 === _constants.EXTERNAL_EVENT_ZOOM_OUT ? 25 : _t5 === _constants.EXTERNAL_EVENT_UNDO ? 28 : _t5 === _constants.EXTERNAL_EVENT_REDO ? 29 : _t5 === _constants.EXTERNAL_EVENT_SET_MOLDING ? 30 : _t5 === _constants.EXTERNAL_EVENT_PROJECT_SETTING ? 31 : _t5 === _constants.EXTERNAL_EVENT_CHANGE_DISTANCE ? 32 : _t5 === _constants.EXTERNAL_EVENT_SYNC_SCENE ? 33 : 34;
833
+ _context8.next = _t5 === _constants.EXTERNAL_EVENT_LOAD_PROJECT ? 1 : _t5 === _constants.EXTERNAL_EVENT_TOGGLE_TO_3D ? 5 : _t5 === _constants.EXTERNAL_EVENT_TOGGLE_TO_2D ? 6 : _t5 === _constants.EXTERNAL_EVENT_TOGGLE_TO_ELEVATION ? 7 : _t5 === _constants.EXTERNAL_EVENT_ADD_WALL ? 8 : _t5 === _constants.EXTERNAL_EVENT_ADD_ITEM ? 9 : _t5 === _constants.EXTERNAL_EVENT_MOVE_PAN ? 12 : _t5 === _constants.EXTERNAL_EVENT_NEW_PROJECT ? 18 : _t5 === _constants.EXTERNAL_EVENT_CHANGE_DOORSTYLE ? 19 : _t5 === _constants.EXTERNAL_EVENT_SET_INITIAL_DATA ? 20 : _t5 === _constants.EXTERNAL_EVENT_ADD_ROOM_SHAPE ? 21 : _t5 === _constants.EXTERNAL_EVENT_ZOOM_IN ? 22 : _t5 === _constants.EXTERNAL_EVENT_ZOOM_OUT ? 25 : _t5 === _constants.EXTERNAL_EVENT_UNDO ? 28 : _t5 === _constants.EXTERNAL_EVENT_REDO ? 29 : _t5 === _constants.EXTERNAL_EVENT_SET_MOLDING ? 30 : _t5 === _constants.EXTERNAL_EVENT_PROJECT_SETTING ? 31 : _t5 === _constants.EXTERNAL_EVENT_UPDATE_ATTRIBUTE ? 32 : _t5 === _constants.EXTERNAL_EVENT_SYNC_SCENE ? 33 : 34;
543
834
  break;
544
835
  case 1:
836
+ // prepare item data request
837
+ cdsItems = [];
838
+ itemKeys = Object.keys(evt === null || evt === void 0 || (_evt$payload = evt.payload) === null || _evt$payload === void 0 || (_evt$payload = _evt$payload.layers['layer-1']) === null || _evt$payload === void 0 ? void 0 : _evt$payload.items) || [];
839
+ _loop3 = /*#__PURE__*/_regenerator["default"].mark(function _loop3() {
840
+ var _evt$payload2, _it$doorStyle2;
841
+ var it;
842
+ return _regenerator["default"].wrap(function (_context7) {
843
+ while (1) switch (_context7.prev = _context7.next) {
844
+ case 0:
845
+ it = evt === null || evt === void 0 || (_evt$payload2 = evt.payload) === null || _evt$payload2 === void 0 || (_evt$payload2 = _evt$payload2.layers['layer-1']) === null || _evt$payload2 === void 0 ? void 0 : _evt$payload2.items[itemKeys[i]];
846
+ if (!cdsItems.some(function (v) {
847
+ var _it$doorStyle;
848
+ return it.type === v.type && ((_it$doorStyle = it.doorStyle) === null || _it$doorStyle === void 0 || (_it$doorStyle = _it$doorStyle.doorStyles) === null || _it$doorStyle === void 0 ? void 0 : _it$doorStyle.cabinet_door_style_id) === v.cdsId;
849
+ })) cdsItems.push({
850
+ type: it.type,
851
+ cdsId: (_it$doorStyle2 = it.doorStyle) === null || _it$doorStyle2 === void 0 || (_it$doorStyle2 = _it$doorStyle2.doorStyles) === null || _it$doorStyle2 === void 0 ? void 0 : _it$doorStyle2.cabinet_door_style_id
852
+ });
853
+ case 1:
854
+ case "end":
855
+ return _context7.stop();
856
+ }
857
+ }, _loop3);
858
+ });
545
859
  i = 0;
546
860
  case 2:
547
- if (!(i < (evt === null || evt === void 0 || (_evt$payload = evt.payload) === null || _evt$payload === void 0 || (_evt$payload = _evt$payload.catalogItems) === null || _evt$payload === void 0 || (_evt$payload = _evt$payload.elements) === null || _evt$payload === void 0 ? void 0 : _evt$payload.length))) {
548
- _context6.next = 4;
861
+ if (!(i < itemKeys.length)) {
862
+ _context8.next = 4;
549
863
  break;
550
864
  }
551
- _context6.next = 3;
552
- return addItemToCatalog(evt === null || evt === void 0 || (_evt$payload2 = evt.payload) === null || _evt$payload2 === void 0 || (_evt$payload2 = _evt$payload2.catalogItems) === null || _evt$payload2 === void 0 ? void 0 : _evt$payload2.elements[i], state, props.catalog, props.projectActions);
865
+ return _context8.delegateYield(_loop3(), "t0", 3);
553
866
  case 3:
554
867
  i++;
555
- _context6.next = 2;
868
+ _context8.next = 2;
556
869
  break;
557
870
  case 4:
558
- props.projectActions.loadProject(evt.payload.sceneData);
559
- return _context6.abrupt("continue", 34);
871
+ // request item catalog data to host app
872
+ if (cdsItems.length > 0) {
873
+ (_props$onInternalEven = props.onInternalEvent) === null || _props$onInternalEven === void 0 || _props$onInternalEven.call(props, {
874
+ type: _constants.INTERNAL_EVENT_ITEMS_CATALOG,
875
+ value: {
876
+ cdsItems: cdsItems
877
+ }
878
+ }, /*#__PURE__*/function () {
879
+ var _ref2 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee6(result) {
880
+ var _i, _result$elements;
881
+ return _regenerator["default"].wrap(function (_context6) {
882
+ while (1) switch (_context6.prev = _context6.next) {
883
+ case 0:
884
+ _i = 0;
885
+ case 1:
886
+ if (!(_i < (result === null || result === void 0 || (_result$elements = result.elements) === null || _result$elements === void 0 ? void 0 : _result$elements.length))) {
887
+ _context6.next = 3;
888
+ break;
889
+ }
890
+ _context6.next = 2;
891
+ return addItemToCatalog(result.elements[_i], state, props.catalog, props.projectActions);
892
+ case 2:
893
+ _i++;
894
+ _context6.next = 1;
895
+ break;
896
+ case 3:
897
+ props.projectActions.loadProject(evt.payload);
898
+ case 4:
899
+ case "end":
900
+ return _context6.stop();
901
+ }
902
+ }, _callee6);
903
+ }));
904
+ return function (_x10) {
905
+ return _ref2.apply(this, arguments);
906
+ };
907
+ }());
908
+ }
909
+ return _context8.abrupt("continue", 34);
560
910
  case 5:
561
911
  props.projectActions.setMode(_constants.MODE_IDLE_3D);
562
- return _context6.abrupt("continue", 34);
912
+ return _context8.abrupt("continue", 34);
563
913
  case 6:
564
914
  props.projectActions.setMode(_constants.MODE_IDLE);
565
- return _context6.abrupt("continue", 34);
915
+ return _context8.abrupt("continue", 34);
566
916
  case 7:
567
917
  sLineCnt = state.getIn(['scene', 'layers', 'layer-1', 'selected', 'lines']).size;
568
918
  if (sLineCnt > 0) props.projectActions.setMode(_constants.MODE_ELEVATION_VIEW);
569
- return _context6.abrupt("continue", 34);
919
+ return _context8.abrupt("continue", 34);
570
920
  case 8:
571
921
  if (state.mode === _constants.MODE_IDLE || state.mode === _constants.MODE_2D_PAN) props.linesActions.selectToolDrawingLine('wall');else {
572
922
  props.projectActions.setMode(_constants.MODE_IDLE);
573
923
  props.linesActions.selectToolDrawingLine('wall');
574
924
  }
575
- return _context6.abrupt("continue", 34);
925
+ return _context8.abrupt("continue", 34);
576
926
  case 9:
577
927
  if ((0, _helper.isEmpty)(evt === null || evt === void 0 ? void 0 : evt.payload)) {
578
- _context6.next = 11;
928
+ _context8.next = 11;
579
929
  break;
580
930
  }
581
931
  element = evt.payload;
582
- _context6.next = 10;
932
+ _context8.next = 10;
583
933
  return addItemToCatalog(element, state, props.catalog, props.projectActions);
584
934
  case 10:
585
935
  // start drawing item
586
- _constants.ARRAY_3D_MODES.includes(state.mode) ? props.itemsActions.selectToolDrawingItem3D(element.name) : props.itemsActions.selectToolDrawingItem(element.name);
936
+ if (_constants.ARRAY_3D_MODES.includes(state.mode)) {
937
+ // in 3d view
938
+ props.itemsActions.selectToolDrawingItem3D(element.name);
939
+ } else {
940
+ // in 2d view
941
+ // create cabinet
942
+ props.itemsActions.selectToolDrawingItem(element.name);
943
+ // mapping the initial position of client coord to viewer2D coord
944
+ _evt$payload$initialP = evt.payload.initialPosition, mouseX = _evt$payload$initialP.mouseX, mouseY = _evt$payload$initialP.mouseY;
945
+ v2d = (_state$viewer2D = state.viewer2D) === null || _state$viewer2D === void 0 ? void 0 : _state$viewer2D.toJS();
946
+ if (mouseX && mouseY && v2d) {
947
+ vPosX = (mouseX - v2d.e) / v2d.a;
948
+ vPosY = (mouseY - v2d.f) / v2d.d;
949
+ layerID = state.scene.selectedLayer; // move cabinet to initial position
950
+ props.itemsActions.updateDrawingItem(layerID, vPosX, -vPosY + state.scene.height);
951
+ }
952
+ }
587
953
  props.projectActions.pushLastSelectedCatalogElementToHistory(element);
588
954
  props.projectActions.setIsCabinetDrawing(true);
589
955
  case 11:
590
- return _context6.abrupt("continue", 34);
956
+ return _context8.abrupt("continue", 34);
591
957
  case 12:
592
958
  _evt$payload3 = evt.payload, moveType = _evt$payload3.moveType, moveValue = _evt$payload3.moveValue;
593
959
  value = state.getIn(['viewer2D']).toJS();
594
960
  _t6 = moveType;
595
- _context6.next = _t6 === _constants.TOP ? 13 : _t6 === _constants.BOTTOM ? 14 : _t6 === _constants.RIGHT ? 15 : _t6 === _constants.LEFT ? 16 : 17;
961
+ _context8.next = _t6 === _constants.TOP ? 13 : _t6 === _constants.BOTTOM ? 14 : _t6 === _constants.RIGHT ? 15 : _t6 === _constants.LEFT ? 16 : 17;
596
962
  break;
597
963
  case 13:
598
964
  value.f -= moveValue;
599
- return _context6.abrupt("continue", 17);
965
+ return _context8.abrupt("continue", 17);
600
966
  case 14:
601
967
  value.f += moveValue;
602
- return _context6.abrupt("continue", 17);
968
+ return _context8.abrupt("continue", 17);
603
969
  case 15:
604
970
  value.e += moveValue;
605
- return _context6.abrupt("continue", 17);
971
+ return _context8.abrupt("continue", 17);
606
972
  case 16:
607
973
  value.e -= moveValue;
608
- return _context6.abrupt("continue", 17);
974
+ return _context8.abrupt("continue", 17);
609
975
  case 17:
610
976
  if (compareSVGRect(value)) props.viewer2DActions.updateCameraView(value);
611
- return _context6.abrupt("continue", 34);
977
+ return _context8.abrupt("continue", 34);
612
978
  case 18:
613
979
  defaulTitle = 'Untitle';
614
980
  props.projectActions.newProject();
615
981
  props.projectActions.rename(defaulTitle);
616
- return _context6.abrupt("continue", 34);
982
+ return _context8.abrupt("continue", 34);
617
983
  case 19:
618
984
  _evt$payload4 = evt.payload, doorStyle = _evt$payload4.doorStyle, itemCDS = _evt$payload4.itemCDS, isAll = _evt$payload4.isAll;
619
985
  props.itemsActions.setDoorStyle(doorStyle, itemCDS, isAll);
620
- return _context6.abrupt("continue", 34);
986
+ return _context8.abrupt("continue", 34);
621
987
  case 20:
622
988
  _doorStyle = evt.payload.doorStyle;
623
989
  props.itemsActions.setInitialDoorStyle(_doorStyle.doorStyle);
624
- return _context6.abrupt("continue", 34);
990
+ return _context8.abrupt("continue", 34);
625
991
  case 21:
626
992
  props.projectActions.loadProject(evt.payload);
627
- return _context6.abrupt("continue", 34);
993
+ return _context8.abrupt("continue", 34);
628
994
  case 22:
629
995
  _value = state.getIn(['viewer2D']).toJS();
630
996
  _value.a -= 0.1;
@@ -633,16 +999,16 @@ function _handleExternalEvent() {
633
999
  _value.f += _value.SVGHeight * 0.1 / 2;
634
1000
  _zoomValue = parseInt((_value.a - 0.5) / _constants.ZOOM_VARIABLE);
635
1001
  if (!(_zoomValue > 404)) {
636
- _context6.next = 23;
1002
+ _context8.next = 23;
637
1003
  break;
638
1004
  }
639
- return _context6.abrupt("return");
1005
+ return _context8.abrupt("return");
640
1006
  case 23:
641
1007
  if (!(_zoomValue < 35 || Number.isNaN(_zoomValue))) {
642
- _context6.next = 24;
1008
+ _context8.next = 24;
643
1009
  break;
644
1010
  }
645
- return _context6.abrupt("return");
1011
+ return _context8.abrupt("return");
646
1012
  case 24:
647
1013
  while (!(_value.e <= 10)) {
648
1014
  _value.e -= 0.1;
@@ -657,7 +1023,7 @@ function _handleExternalEvent() {
657
1023
  _value.f += 0.1;
658
1024
  }
659
1025
  if (compareSVGRect(_value)) props.viewer2DActions.updateCameraView(_value);
660
- return _context6.abrupt("continue", 34);
1026
+ return _context8.abrupt("continue", 34);
661
1027
  case 25:
662
1028
  _value2 = state.getIn(['viewer2D']).toJS();
663
1029
  _value2.a += 0.1;
@@ -666,29 +1032,29 @@ function _handleExternalEvent() {
666
1032
  _value2.f -= _value2.SVGHeight * 0.1 / 2;
667
1033
  _zoomValue2 = parseInt((_value2.a - 0.5) / _constants.ZOOM_VARIABLE);
668
1034
  if (!(_zoomValue2 > 404)) {
669
- _context6.next = 26;
1035
+ _context8.next = 26;
670
1036
  break;
671
1037
  }
672
- return _context6.abrupt("return");
1038
+ return _context8.abrupt("return");
673
1039
  case 26:
674
1040
  if (!(_zoomValue2 < 35 || Number.isNaN(_zoomValue2))) {
675
- _context6.next = 27;
1041
+ _context8.next = 27;
676
1042
  break;
677
1043
  }
678
- return _context6.abrupt("return");
1044
+ return _context8.abrupt("return");
679
1045
  case 27:
680
1046
  if (compareSVGRect(_value2)) props.viewer2DActions.updateCameraView(_value2);
681
- return _context6.abrupt("continue", 34);
1047
+ return _context8.abrupt("continue", 34);
682
1048
  case 28:
683
1049
  props.projectActions.undo();
684
- return _context6.abrupt("continue", 34);
1050
+ return _context8.abrupt("continue", 34);
685
1051
  case 29:
686
1052
  props.projectActions.redo();
687
- return _context6.abrupt("continue", 34);
1053
+ return _context8.abrupt("continue", 34);
688
1054
  case 30:
689
1055
  _evt$payload5 = evt.payload, moldingInfo = _evt$payload5.moldingInfo, isGlobal = _evt$payload5.isGlobal;
690
1056
  props.itemsActions.setMolding(moldingInfo, isGlobal);
691
- return _context6.abrupt("continue", 34);
1057
+ return _context8.abrupt("continue", 34);
692
1058
  case 31:
693
1059
  _evt$payload6 = evt.payload, option = _evt$payload6.option, _value3 = _evt$payload6.value;
694
1060
  if (option === _constants.PROJECT_SETTING_OPTION.UPDATE_CEIL_HEIGHT) {
@@ -703,13 +1069,18 @@ function _handleExternalEvent() {
703
1069
  } else if (option === _constants.PROJECT_SETTING_OPTION.CHANGE_WINDOW_DOOR_MEASURE) {
704
1070
  props.viewer2DActions.changeWindowDoorMeasure(_value3);
705
1071
  }
706
- return _context6.abrupt("continue", 34);
1072
+ return _context8.abrupt("continue", 34);
707
1073
  case 32:
708
- distancePayload = evt.payload;
709
- props.itemsActions.changeDistance(distancePayload);
1074
+ layerId = state.getIn(['scene', 'selectedLayer']);
1075
+ layer = state.getIn(['scene', 'layers', layerId]);
1076
+ _layer$getIn = layer.getIn(['selected']), selectedLines = _layer$getIn.lines, selectedHoles = _layer$getIn.holes, selectedItems = _layer$getIn.items;
1077
+ for (_i2 = 0; _i2 < selectedLines.size; _i2++) updateAttributeOfSelectedElement(layer.getIn(['lines', selectedLines.get(_i2)]), evt.payload, state, layer, props.projectActions);
1078
+ for (_i3 = 0; _i3 < selectedHoles.size; _i3++) updateAttributeOfSelectedElement(layer.getIn(['holes', selectedHoles.get(_i3)]), evt.payload, state, layer, props.projectActions);
1079
+ for (_i4 = 0; _i4 < selectedItems.size; _i4++) updateAttributeOfSelectedElement(layer.getIn(['items', selectedItems.get(_i4)]), evt.payload, state, layer, props.projectActions);
1080
+ return _context8.abrupt("continue", 34);
710
1081
  case 33:
711
1082
  // send scene object from 3DTool to HostApp using internalEvent
712
- (_props$onInternalEven = props.onInternalEvent) === null || _props$onInternalEven === void 0 || _props$onInternalEven.call(props, {
1083
+ (_props$onInternalEven2 = props.onInternalEvent) === null || _props$onInternalEven2 === void 0 || _props$onInternalEven2.call(props, {
713
1084
  type: _constants.INTERNAL_EVENT_SYNC_SCENE,
714
1085
  value: {
715
1086
  scene: state.scene.toJS()
@@ -717,9 +1088,9 @@ function _handleExternalEvent() {
717
1088
  });
718
1089
  case 34:
719
1090
  case "end":
720
- return _context6.stop();
1091
+ return _context8.stop();
721
1092
  }
722
- }, _callee6);
1093
+ }, _callee7);
723
1094
  }));
724
1095
  return _handleExternalEvent.apply(this, arguments);
725
1096
  }