kitchen-simulator 2.0.4 → 2.0.6-add-door-window-appliance

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,22 @@ 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");
19
+ var _utils = require("../components/viewer2d/utils");
20
+ var _SVGLoader = require("three/addons/loaders/SVGLoader");
20
21
  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
22
  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; }
23
+ var PRECISION = 2;
22
24
  var loadSVGsByItem = /*#__PURE__*/function () {
23
25
  var _ref = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee(item) {
24
26
  var _parsed$xml$viewBox, _parsed$xml$viewBox2, response, svgText, loader, parsed, _t;
@@ -42,7 +44,7 @@ var loadSVGsByItem = /*#__PURE__*/function () {
42
44
  return response.text();
43
45
  case 3:
44
46
  svgText = _context.sent;
45
- loader = new SVGLoader();
47
+ loader = new _SVGLoader.SVGLoader();
46
48
  parsed = loader.parse(svgText);
47
49
  if (!(0, _helper.isEmpty)(parsed.paths)) {
48
50
  _context.next = 4;
@@ -74,12 +76,12 @@ var loadSVGsByItem = /*#__PURE__*/function () {
74
76
  var compareSVGRect = function compareSVGRect(value) {
75
77
  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
78
  };
77
- function loadJSON(_x2, _x3, _x4) {
79
+ function loadJSON(_x2) {
78
80
  return _loadJSON.apply(this, arguments);
79
81
  }
80
82
  /********Parse TempPlaceholder from cabinetPayloadData **************/
81
83
  function _loadJSON() {
82
- _loadJSON = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2(path, success, error) {
84
+ _loadJSON = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2(path) {
83
85
  return _regenerator["default"].wrap(function (_context2) {
84
86
  while (1) switch (_context2.prev = _context2.next) {
85
87
  case 0:
@@ -105,7 +107,7 @@ function _loadJSON() {
105
107
  }));
106
108
  return _loadJSON.apply(this, arguments);
107
109
  }
108
- function parseTempPlaceholdersFromCabinetPayload(_x5) {
110
+ function parseTempPlaceholdersFromCabinetPayload(_x3) {
109
111
  return _parseTempPlaceholdersFromCabinetPayload.apply(this, arguments);
110
112
  }
111
113
  /***** Update cabinetPayloadData with updatedTempPlaceholders *****/
@@ -449,9 +451,9 @@ function _parseTempPlaceholdersFromCabinetPayload() {
449
451
  }));
450
452
  return _parseTempPlaceholdersFromCabinetPayload.apply(this, arguments);
451
453
  }
452
- function updateCabinetPayload(_x6) {
454
+ function updateCabinetPayload(_x4) {
453
455
  return _updateCabinetPayload.apply(this, arguments);
454
- }
456
+ } // Get attributs of current selected element
455
457
  function _updateCabinetPayload() {
456
458
  _updateCabinetPayload = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee4(cabinetPayload) {
457
459
  var tempPlaceholders, cabinetPayloadKeys, i;
@@ -479,47 +481,400 @@ function _updateCabinetPayload() {
479
481
  }));
480
482
  return _updateCabinetPayload.apply(this, arguments);
481
483
  }
484
+ function initAttrData(element, layer, state) {
485
+ element = (0, _typeof2["default"])(element.misc) === 'object' ? element.set('misc', new _immutable.Map(element.misc)) : element;
486
+ switch (element.prototype) {
487
+ case 'items':
488
+ {
489
+ return new _immutable.Map(element);
490
+ }
491
+ case 'lines':
492
+ {
493
+ var v_a = layer.vertices.get(element.vertices.get(0));
494
+ var v_b = layer.vertices.get(element.vertices.get(1));
495
+ var distance = _export.GeometryUtils.pointsDistance(v_a.x, v_a.y, v_b.x, v_b.y);
496
+ var _unit = element.misc.get('_unitLength') || _constants.UNIT_INCH;
497
+ var _length = (0, _convertUnitsLite.convert)(distance).from(_constants.UNIT_CENTIMETER).to(_unit);
498
+ if (state.mode == _constants.MODE_DRAWING_LINE) {
499
+ return new _immutable.Map({
500
+ vertexOne: v_a,
501
+ vertexTwo: v_b,
502
+ lineLength: new _immutable.Map({
503
+ length: distance,
504
+ _length: _length,
505
+ _unit: _unit
506
+ }),
507
+ focus: element.focus
508
+ });
509
+ } else {
510
+ var allLines = layer.lines.toArray();
511
+ var relatedLine = allLines.filter(function (line) {
512
+ return line.vertices.toArray().includes(v_b.id) && line.id != element.id;
513
+ })[0];
514
+ var relatedVertexID = relatedLine && (relatedLine.vertices.toArray()[0] == v_b.id ? relatedLine.vertices.toArray()[1] : relatedLine.vertices.toArray()[0]);
515
+ var v_d = relatedVertexID && layer.getIn(['vertices', relatedVertexID]);
516
+ var lineToExtend = relatedVertexID && allLines.filter(function (line) {
517
+ return line.vertices.toArray().includes(relatedVertexID) && line.id != relatedLine.id;
518
+ })[0];
519
+ var v_c = lineToExtend && layer.getIn(['vertices', lineToExtend.vertices.toArray()[0] == v_d.id ? lineToExtend.vertices.toArray()[1] : lineToExtend.vertices.toArray()[0]]);
520
+ return new _immutable.Map({
521
+ vertexOne: v_a,
522
+ vertexTwo: v_b,
523
+ vertexThree: v_c,
524
+ vertexFour: v_d,
525
+ lineToExtend: lineToExtend,
526
+ lineLength: new _immutable.Map({
527
+ length: distance,
528
+ _length: _length,
529
+ _unit: _unit
530
+ }),
531
+ focus: element.focus
532
+ });
533
+ }
534
+ }
535
+ case 'holes':
536
+ {
537
+ var line = layer.lines.get(element.line);
538
+ var _layer$vertices$get = layer.vertices.get(line.vertices.get(0)),
539
+ x0 = _layer$vertices$get.x,
540
+ y0 = _layer$vertices$get.y;
541
+ var _layer$vertices$get2 = layer.vertices.get(line.vertices.get(1)),
542
+ x1 = _layer$vertices$get2.x,
543
+ y1 = _layer$vertices$get2.y;
544
+ var lineLength = _export.GeometryUtils.pointsDistance(x0, y0, x1, y1);
545
+ var startAt = lineLength * element.offset - element.properties.get('width').get('length') / 2;
546
+ var endAt = lineLength - lineLength * element.offset - element.properties.get('width').get('length') / 2;
547
+ var _unitA = element.misc.get('_unitA') || _constants.UNIT_INCH;
548
+ var _lengthA = (0, _convertUnitsLite.convert)(x0 > x1 ? endAt : startAt).from(_constants.UNIT_CENTIMETER).to(_unitA);
549
+ var _unitB = element.misc.get('_unitB') || _constants.UNIT_INCH;
550
+ var _lengthB = (0, _convertUnitsLite.convert)(x0 > x1 ? startAt : endAt).from(_constants.UNIT_CENTIMETER).to(_unitB);
551
+ return new _immutable.Map({
552
+ offset: element.offset,
553
+ offsetA: new _immutable.Map({
554
+ length: MathUtils.toFixedFloat(x0 > x1 ? endAt : startAt, PRECISION),
555
+ _length: MathUtils.toFixedFloat(_lengthA, PRECISION),
556
+ _unit: _unitA
557
+ }),
558
+ offsetB: new _immutable.Map({
559
+ length: MathUtils.toFixedFloat(x0 > x1 ? startAt : endAt, PRECISION),
560
+ _length: MathUtils.toFixedFloat(_lengthB, PRECISION),
561
+ _unit: _unitB
562
+ })
563
+ });
564
+ }
565
+ case 'areas':
566
+ {
567
+ return new _immutable.Map({});
568
+ }
569
+ default:
570
+ return null;
571
+ }
572
+ }
573
+ // Get properties of current selected element
574
+ function initPropData(element, catalog) {
575
+ var mapped = {};
576
+ if (!catalog.elements.hasOwnProperty(element.type) && !(!catalog.elements[element.type] && !!catalog.elements[(0, _utils.returnReplaceableDeepSearchType)(element.type)])) {
577
+ console.log("Last Selected ".concat(element.type, " Element does not exist in catalog."));
578
+ return new _immutable.Map(mapped);
579
+ }
580
+ var catalogElement = catalog.getElement(element.type);
581
+ var isFiller = catalogElement.long_name ? catalogElement.long_name.toUpperCase().includes('FILLER') : false;
582
+ if (isFiller) {
583
+ var height = {
584
+ defaultValue: element.properties.get('height').toJS(),
585
+ label: 'Height',
586
+ type: 'length-measure'
587
+ };
588
+ var depth = {
589
+ defaultValue: element.properties.get('depth').toJS(),
590
+ label: 'Depth',
591
+ type: 'length-measure'
592
+ };
593
+ catalogElement.properties = {
594
+ altitude: catalogElement.properties.altitude,
595
+ width: catalogElement.properties.width,
596
+ height: height,
597
+ depth: depth,
598
+ flip_doorhandle: catalogElement.properties.flip_doorhandle,
599
+ resize_and_scaling: catalogElement.properties.resize_and_scaling
600
+ };
601
+ }
602
+ for (var name in catalogElement.properties) {
603
+ mapped[name] = new _immutable.Map({
604
+ currentValue: element.properties.has(name) ? element.properties.get(name) : fromJS(catalogElement.properties[name].defaultValue),
605
+ configs: catalogElement.properties[name]
606
+ });
607
+ }
608
+ return new _immutable.Map(mapped);
609
+ }
610
+ function updateAttributeOfSelectedElement(element, attrPayload, state, layer, projectActions) {
611
+ var attributesFormData = initAttrData(element, layer, state);
612
+ var value = attrPayload.value;
613
+ var attributeName = attrPayload.attributeName;
614
+ // pre process
615
+ if (attributeName === _constants.ATT_ITEM_POS) {
616
+ // calculate the new position of movement
617
+ var rotRad = (value.directionAng + element.rotation) / 180 * Math.PI;
618
+ var newX = element.x + (0, _convertUnitsLite.convert)((value.oldDistance - value.newDistance) * Math.cos(rotRad)).from('in').to('cm');
619
+ var newY = element.y + (0, _convertUnitsLite.convert)((value.oldDistance - value.newDistance) * Math.sin(rotRad)).from('in').to('cm');
620
+ // const reversedDirection =
621
+ // value.directionAng === LEFT_DIST_ANG
622
+ // ? RIGHT_DIST_ANG
623
+ // : value.directionAng === RIGHT_DIST_ANG
624
+ // ? LEFT_DIST_ANG
625
+ // : value.directionAng === BACK_DIST_ANG
626
+ // ? FRONT_DIST_ANG
627
+ // : BACK_DIST_ANG;
628
+ // let dist = convert(
629
+ // element.distArray?.find(v => v[1] === reversedDirection)
630
+ // ? element.distArray?.find(v => v[1] === reversedDirection)[0]
631
+ // : 0
632
+ // )
633
+ // .from('cm')
634
+ // .to('in');
635
+ // if (dist + (value.oldDistance - value.newDistance) <= 0 || value.newDistance < 0) {
636
+ // // confirm "The item will be placed outside the floor plan. Are you sure?"
637
+ // setPopupOpen(true);
638
+ // return;
639
+ // }
640
+ value = {
641
+ x: newX,
642
+ y: newY
643
+ };
644
+ } else if (attributeName === _constants.ATT_LINE_LENGTH || attributeName === _constants.ATT_HOLE_OFFSET_A || attributeName === _constants.ATT_HOLE_OFFSET_B) {
645
+ var att = attributesFormData.has(attributeName) ? attributesFormData.get(attributeName) : element[attributeName];
646
+ if (att) value = att.merge({
647
+ _length: value,
648
+ _unit: _constants.UNIT_INCH,
649
+ length: (0, _convertUnitsLite.convert)(value).from(_constants.UNIT_INCH).to(_constants.UNIT_CENTIMETER)
650
+ });
651
+ }
652
+ // make the new attrivutes
653
+ switch (element.prototype) {
654
+ case 'items':
655
+ {
656
+ if (attributeName == _constants.ATT_ITEM_POS) {
657
+ var xVal = value.x;
658
+ var yVal = value.y;
659
+ attributesFormData = attributesFormData.set('x', xVal);
660
+ attributesFormData = attributesFormData.set('y', yVal);
661
+ } else {
662
+ attributesFormData = attributesFormData.set(attributeName, value);
663
+ }
664
+ break;
665
+ }
666
+ case 'lines':
667
+ {
668
+ switch (attributeName) {
669
+ case _constants.ATT_LINE_LENGTH:
670
+ {
671
+ var v_0 = attributesFormData.get('vertexOne');
672
+ var v_1 = attributesFormData.get('vertexTwo');
673
+ var v_b_new = _export.GeometryUtils.extendLine(v_0.x, v_0.y, v_1.x, v_1.y, value.get('length'), PRECISION);
674
+ attributesFormData = attributesFormData.withMutations(function (attr) {
675
+ attr.set('vertexTwo', v_1.merge(v_b_new));
676
+ attr.set('lineLength', value);
677
+ });
678
+ break;
679
+ }
680
+ case _constants.ATT_VERTEXT_ONE:
681
+ case _constants.ATT_VERTEXT_TWO:
682
+ {
683
+ attributesFormData = attributesFormData.withMutations(function (attr) {
684
+ attr.set(attributeName, attr.get(attributeName).merge(value));
685
+ var newDistance = _export.GeometryUtils.verticesDistance(attr.get('vertexOne'), attr.get('vertexTwo'));
686
+ attr.mergeIn(['lineLength'], attr.get('lineLength').merge({
687
+ length: newDistance,
688
+ _length: (0, _convertUnitsLite.convert)(newDistance).from(_constants.UNIT_CENTIMETER).to(attr.get('lineLength').get('_unit'))
689
+ }));
690
+ });
691
+ break;
692
+ }
693
+ default:
694
+ {
695
+ attributesFormData = attributesFormData.set(attributeName, value);
696
+ break;
697
+ }
698
+ }
699
+ break;
700
+ }
701
+ case 'holes':
702
+ {
703
+ switch (attributeName) {
704
+ case _constants.ATT_HOLE_OFFSET_A:
705
+ {
706
+ var line = layer.lines.get(element.line);
707
+ var _layer$vertices$get3 = layer.vertices.get(line.vertices.get(0)),
708
+ x0 = _layer$vertices$get3.x,
709
+ y0 = _layer$vertices$get3.y;
710
+ var _layer$vertices$get4 = layer.vertices.get(line.vertices.get(1)),
711
+ x1 = _layer$vertices$get4.x,
712
+ y1 = _layer$vertices$get4.y;
713
+ var alpha = _export.GeometryUtils.angleBetweenTwoPoints(x0, y0, x1, y1);
714
+ var lineLength = _export.GeometryUtils.pointsDistance(x0, y0, x1, y1);
715
+ var widthLength = element.properties.get('width').get('length');
716
+ var halfWidthLength = widthLength / 2;
717
+ var lengthValue = value.get('length');
718
+ lengthValue = Math.max(lengthValue, 0);
719
+ lengthValue = Math.min(lengthValue, lineLength - widthLength);
720
+ var xp = (lengthValue + halfWidthLength) * Math.cos(alpha) + x0;
721
+ var yp = (lengthValue + halfWidthLength) * Math.sin(alpha) + y0;
722
+ var offset = _export.GeometryUtils.pointPositionOnLineSegment(x0, y0, x1, y1, xp, yp);
723
+ /*
724
+ if (x0 > x1) offset = 1 - offset;
725
+ */
726
+ var endAt = MathUtils.toFixedFloat(lineLength - lineLength * offset - halfWidthLength, PRECISION);
727
+ var offsetUnit = attributesFormData.getIn(['offsetB', '_unit']);
728
+ var offsetB = new _immutable.Map({
729
+ length: endAt,
730
+ _length: (0, _convertUnitsLite.convert)(endAt).from(_constants.UNIT_CENTIMETER).to(offsetUnit),
731
+ _unit: offsetUnit
732
+ });
733
+ attributesFormData = attributesFormData.set('offsetB', offsetB).set('offset', offset);
734
+ var offsetAttribute = new _immutable.Map({
735
+ length: MathUtils.toFixedFloat(lengthValue, PRECISION),
736
+ _unit: value.get('_unit'),
737
+ _length: MathUtils.toFixedFloat((0, _convertUnitsLite.convert)(lengthValue).from(_constants.UNIT_CENTIMETER).to(value.get('_unit')), PRECISION)
738
+ });
739
+ attributesFormData = attributesFormData.set(attributeName, offsetAttribute);
740
+ break;
741
+ }
742
+ case _constants.ATT_HOLE_OFFSET_B:
743
+ {
744
+ var _line = layer.lines.get(element.line);
745
+ var _layer$vertices$get5 = layer.vertices.get(_line.vertices.get(0)),
746
+ _x5 = _layer$vertices$get5.x,
747
+ _y = _layer$vertices$get5.y;
748
+ var _layer$vertices$get6 = layer.vertices.get(_line.vertices.get(1)),
749
+ _x6 = _layer$vertices$get6.x,
750
+ _y2 = _layer$vertices$get6.y;
751
+ var _alpha = _export.GeometryUtils.angleBetweenTwoPoints(_x5, _y, _x6, _y2);
752
+ var _lineLength = _export.GeometryUtils.pointsDistance(_x5, _y, _x6, _y2);
753
+ var _widthLength = element.properties.get('width').get('length');
754
+ var _halfWidthLength = _widthLength / 2;
755
+ var _lengthValue = value.get('length');
756
+ _lengthValue = Math.max(_lengthValue, 0);
757
+ _lengthValue = Math.min(_lengthValue, _lineLength - _widthLength);
758
+ var _xp = _x6 - (_lengthValue + _halfWidthLength) * Math.cos(_alpha);
759
+ var _yp = _y2 - (_lengthValue + _halfWidthLength) * Math.sin(_alpha);
760
+ var _offset = _export.GeometryUtils.pointPositionOnLineSegment(_x5, _y, _x6, _y2, _xp, _yp);
761
+ /*
762
+ if (x0 > x1) offset = 1 - offset;
763
+ */
764
+ var startAt = MathUtils.toFixedFloat(_lineLength * _offset - _halfWidthLength, PRECISION);
765
+ var _offsetUnit = attributesFormData.getIn(['offsetA', '_unit']);
766
+ var offsetA = new _immutable.Map({
767
+ length: startAt,
768
+ _length: (0, _convertUnitsLite.convert)(startAt).from(_constants.UNIT_CENTIMETER).to(_offsetUnit),
769
+ _unit: _offsetUnit
770
+ });
771
+ attributesFormData = attributesFormData.set('offsetA', offsetA).set('offset', _offset);
772
+ var _offsetAttribute = new _immutable.Map({
773
+ length: MathUtils.toFixedFloat(_lengthValue, PRECISION),
774
+ _unit: value.get('_unit'),
775
+ _length: MathUtils.toFixedFloat((0, _convertUnitsLite.convert)(_lengthValue).from(_constants.UNIT_CENTIMETER).to(value.get('_unit')), PRECISION)
776
+ });
777
+ attributesFormData = attributesFormData.set(attributeName, _offsetAttribute);
778
+ break;
779
+ }
780
+ default:
781
+ {
782
+ attributesFormData = attributesFormData.set(attributeName, value);
783
+ break;
784
+ }
785
+ }
786
+ break;
787
+ }
788
+ default:
789
+ break;
790
+ }
791
+
792
+ // update attribute action
793
+ switch (element.prototype) {
794
+ case 'items':
795
+ {
796
+ projectActions.setItemsAttributes(attributesFormData);
797
+ break;
798
+ }
799
+ case 'lines':
800
+ {
801
+ projectActions.setLinesAttributes(attributesFormData);
802
+ break;
803
+ }
804
+ case 'holes':
805
+ {
806
+ projectActions.setHolesAttributes(attributesFormData);
807
+ break;
808
+ }
809
+ }
810
+ }
811
+ function updatePropertyOfSelectedElement(element, propertyPayload, catalog,
812
+ // class instance of Catalog, get from props
813
+ projectActions) {
814
+ var propertiesFormData = initPropData(element, catalog);
815
+ var value = propertyPayload.value;
816
+ var propertyName = propertyPayload.propertyName;
817
+ // make new properties
818
+ if (propertyName === _constants.PROP_FLIP_DOOR_HANDLE && element.properties.get(_constants.PROP_OPEN_DOORS)) {
819
+ alert('Doors are already open.');
820
+ return;
821
+ }
822
+ propertiesFormData = propertiesFormData.setIn([propertyName, 'currentValue'], value);
823
+
824
+ // update property action
825
+ if (propertiesFormData) {
826
+ var properties = propertiesFormData.map(function (data) {
827
+ return data.get('currentValue');
828
+ });
829
+ projectActions.setProperties(properties);
830
+ }
831
+ }
482
832
  function addItemToCatalog(_x7, _x8, _x9, _x0) {
483
833
  return _addItemToCatalog.apply(this, arguments);
484
834
  }
485
835
  function _addItemToCatalog() {
486
836
  _addItemToCatalog = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee5(element, state, catalogInstance, projectActions) {
487
- var elementJs, catalog, updatedStructureJson, outlineSVGData;
837
+ var elementJs, catalog, outlineSVGData, updatedStructureJson;
488
838
  return _regenerator["default"].wrap(function (_context5) {
489
839
  while (1) switch (_context5.prev = _context5.next) {
490
840
  case 0:
841
+ elementJs = element;
491
842
  catalog = state.getIn(['catalog']).toJS(); // add item to catalog of state
843
+ // if (isEmpty(catalog?.elements[element.name])) {
844
+ _context5.next = 1;
845
+ return loadSVGsByItem(element);
846
+ case 1:
847
+ outlineSVGData = _context5.sent;
848
+ if (!(element.type === 'cabinet')) {
849
+ _context5.next = 3;
850
+ break;
851
+ }
492
852
  updatedStructureJson = _objectSpread(_objectSpread({}, element.structure_json), element.structure_json.tempPlaceholders[0].structure);
853
+ element.structure_json = updatedStructureJson;
493
854
  element = _objectSpread(_objectSpread({}, element), {}, {
494
855
  cds: {
495
856
  data: [_objectSpread({}, element.customer_property)],
496
857
  itemID: element.itemID
497
858
  }
498
859
  });
499
- element.structure_json = updatedStructureJson;
500
- if (!(0, _helper.isEmpty)(catalog === null || catalog === void 0 ? void 0 : catalog.elements[element.name])) {
501
- _context5.next = 3;
502
- break;
503
- }
504
- _context5.next = 1;
505
- return loadSVGsByItem(element);
506
- case 1:
507
- outlineSVGData = _context5.sent;
508
860
  _context5.next = 2;
509
861
  return updateCabinetPayload(element);
510
862
  case 2:
511
863
  elementJs = _context5.sent;
512
- elementJs = (0, _exporter["default"])(_objectSpread(_objectSpread({}, elementJs), {}, {
864
+ case 3:
865
+ elementJs = _objectSpread(_objectSpread({}, elementJs), {}, {
513
866
  outlineSVGData: outlineSVGData,
514
- type: 'cabinet',
515
- render2DItem: _itemLoader.render2DItem,
516
- render3DItem: _itemLoader.render3DItem
517
- }));
867
+ type: element.type,
868
+ render2DItem: _itemLoader.render2DItem
869
+ });
870
+ if (element.type === 'appliance' || element.type === 'furnishing') elementJs.render3DItem = _itemLoader.render3DApplianceItem;else if (element.type === 'lighting') elementJs.render3DItem = _itemLoader.render3DLightingItem;else elementJs.render3DItem = _itemLoader.render3DItem;
871
+ elementJs = (0, _exporter["default"])(elementJs);
518
872
  if (catalogInstance !== null && catalogInstance !== void 0 && catalogInstance.validateElement(elementJs)) {
519
873
  catalogInstance.registerElement(elementJs);
520
874
  projectActions.addElementToCatalog(elementJs);
521
875
  }
522
- case 3:
876
+ // }
877
+ case 4:
523
878
  case "end":
524
879
  return _context5.stop();
525
880
  }
@@ -532,15 +887,16 @@ function handleExternalEvent(_x1) {
532
887
  }
533
888
  function _handleExternalEvent() {
534
889
  _handleExternalEvent = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee7(props) {
535
- var evt, state, _evt$payload, cdsItems, itemKeys, _loop3, i, _props$onInternalEven, 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$onInternalEven2, _t5, _t6;
890
+ var _evt$payload3, _evt$payload4;
891
+ 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$payload5, moveType, moveValue, value, defaulTitle, _evt$payload6, doorStyle, itemCDS, isAll, _doorStyle, _value, _zoomValue, _value2, _zoomValue2, _evt$payload7, moldingInfo, isGlobal, _evt$payload8, option, _value3, layerId, layer, _layer$getIn, selectedLines, selectedHoles, selectedItems, _i2, _i3, _i4, _props$onInternalEven2, _t5, _t6;
536
892
  return _regenerator["default"].wrap(function (_context8) {
537
893
  while (1) switch (_context8.prev = _context8.next) {
538
894
  case 0:
539
- console.log('***external event****', props.externalEvent);
895
+ // console.log('***external event****', props);
540
896
  evt = props.externalEvent;
541
897
  state = props.state.get('KitchenConfigurator');
542
898
  _t5 = evt === null || evt === void 0 ? void 0 : evt.type;
543
- _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_CHANGE_DISTANCE ? 32 : _t5 === _constants.EXTERNAL_EVENT_SYNC_SCENE ? 33 : 34;
899
+ _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_ADD_HOLE ? 12 : _t5 === _constants.EXTERNAL_EVENT_MOVE_PAN ? 13 : _t5 === _constants.EXTERNAL_EVENT_NEW_PROJECT ? 19 : _t5 === _constants.EXTERNAL_EVENT_CHANGE_DOORSTYLE ? 20 : _t5 === _constants.EXTERNAL_EVENT_SET_INITIAL_DATA ? 21 : _t5 === _constants.EXTERNAL_EVENT_ADD_ROOM_SHAPE ? 22 : _t5 === _constants.EXTERNAL_EVENT_ZOOM_IN ? 23 : _t5 === _constants.EXTERNAL_EVENT_ZOOM_OUT ? 26 : _t5 === _constants.EXTERNAL_EVENT_UNDO ? 29 : _t5 === _constants.EXTERNAL_EVENT_REDO ? 30 : _t5 === _constants.EXTERNAL_EVENT_SET_MOLDING ? 31 : _t5 === _constants.EXTERNAL_EVENT_PROJECT_SETTING ? 32 : _t5 === _constants.EXTERNAL_EVENT_UPDATE_ATTRIBUTE ? 33 : _t5 === _constants.EXTERNAL_EVENT_UPDATE_PROPERTY ? 33 : _t5 === _constants.EXTERNAL_EVENT_SYNC_SCENE ? 34 : 35;
544
900
  break;
545
901
  case 1:
546
902
  // prepare item data request
@@ -616,23 +972,23 @@ function _handleExternalEvent() {
616
972
  };
617
973
  }());
618
974
  }
619
- return _context8.abrupt("continue", 34);
975
+ return _context8.abrupt("continue", 35);
620
976
  case 5:
621
977
  props.projectActions.setMode(_constants.MODE_IDLE_3D);
622
- return _context8.abrupt("continue", 34);
978
+ return _context8.abrupt("continue", 35);
623
979
  case 6:
624
980
  props.projectActions.setMode(_constants.MODE_IDLE);
625
- return _context8.abrupt("continue", 34);
981
+ return _context8.abrupt("continue", 35);
626
982
  case 7:
627
983
  sLineCnt = state.getIn(['scene', 'layers', 'layer-1', 'selected', 'lines']).size;
628
984
  if (sLineCnt > 0) props.projectActions.setMode(_constants.MODE_ELEVATION_VIEW);
629
- return _context8.abrupt("continue", 34);
985
+ return _context8.abrupt("continue", 35);
630
986
  case 8:
631
987
  if (state.mode === _constants.MODE_IDLE || state.mode === _constants.MODE_2D_PAN) props.linesActions.selectToolDrawingLine('wall');else {
632
988
  props.projectActions.setMode(_constants.MODE_IDLE);
633
989
  props.linesActions.selectToolDrawingLine('wall');
634
990
  }
635
- return _context8.abrupt("continue", 34);
991
+ return _context8.abrupt("continue", 35);
636
992
  case 9:
637
993
  if ((0, _helper.isEmpty)(evt === null || evt === void 0 ? void 0 : evt.payload)) {
638
994
  _context8.next = 11;
@@ -643,49 +999,68 @@ function _handleExternalEvent() {
643
999
  return addItemToCatalog(element, state, props.catalog, props.projectActions);
644
1000
  case 10:
645
1001
  // start drawing item
646
- _constants.ARRAY_3D_MODES.includes(state.mode) ? props.itemsActions.selectToolDrawingItem3D(element.name) : props.itemsActions.selectToolDrawingItem(element.name);
1002
+ if (_constants.ARRAY_3D_MODES.includes(state.mode)) {
1003
+ // in 3d view
1004
+ props.itemsActions.selectToolDrawingItem3D(element.name);
1005
+ } else {
1006
+ // in 2d view
1007
+ // create cabinet
1008
+ props.itemsActions.selectToolDrawingItem(element.name);
1009
+ // mapping the initial position of client coord to viewer2D coord
1010
+ _evt$payload$initialP = evt.payload.initialPosition, mouseX = _evt$payload$initialP.mouseX, mouseY = _evt$payload$initialP.mouseY;
1011
+ v2d = (_state$viewer2D = state.viewer2D) === null || _state$viewer2D === void 0 ? void 0 : _state$viewer2D.toJS();
1012
+ if (mouseX && mouseY && v2d) {
1013
+ vPosX = (mouseX - v2d.e) / v2d.a;
1014
+ vPosY = (mouseY - v2d.f) / v2d.d;
1015
+ layerID = state.scene.selectedLayer; // move cabinet to initial position
1016
+ props.itemsActions.updateDrawingItem(layerID, vPosX, -vPosY + state.scene.height);
1017
+ }
1018
+ }
647
1019
  props.projectActions.pushLastSelectedCatalogElementToHistory(element);
648
1020
  props.projectActions.setIsCabinetDrawing(true);
649
1021
  case 11:
650
- return _context8.abrupt("continue", 34);
1022
+ return _context8.abrupt("continue", 35);
651
1023
  case 12:
652
- _evt$payload3 = evt.payload, moveType = _evt$payload3.moveType, moveValue = _evt$payload3.moveValue;
1024
+ _constants.ARRAY_3D_MODES.includes(state.mode) ? props.holesActions.selectToolDrawingHole3D(evt === null || evt === void 0 || (_evt$payload3 = evt.payload) === null || _evt$payload3 === void 0 ? void 0 : _evt$payload3.holeName) : props.holesActions.selectToolDrawingHole(evt === null || evt === void 0 || (_evt$payload4 = evt.payload) === null || _evt$payload4 === void 0 ? void 0 : _evt$payload4.holeName);
1025
+ return _context8.abrupt("continue", 35);
1026
+ case 13:
1027
+ _evt$payload5 = evt.payload, moveType = _evt$payload5.moveType, moveValue = _evt$payload5.moveValue;
653
1028
  value = state.getIn(['viewer2D']).toJS();
654
1029
  _t6 = moveType;
655
- _context8.next = _t6 === _constants.TOP ? 13 : _t6 === _constants.BOTTOM ? 14 : _t6 === _constants.RIGHT ? 15 : _t6 === _constants.LEFT ? 16 : 17;
1030
+ _context8.next = _t6 === _constants.TOP ? 14 : _t6 === _constants.BOTTOM ? 15 : _t6 === _constants.RIGHT ? 16 : _t6 === _constants.LEFT ? 17 : 18;
656
1031
  break;
657
- case 13:
658
- value.f -= moveValue;
659
- return _context8.abrupt("continue", 17);
660
1032
  case 14:
661
- value.f += moveValue;
662
- return _context8.abrupt("continue", 17);
1033
+ value.f -= moveValue;
1034
+ return _context8.abrupt("continue", 18);
663
1035
  case 15:
664
- value.e += moveValue;
665
- return _context8.abrupt("continue", 17);
1036
+ value.f += moveValue;
1037
+ return _context8.abrupt("continue", 18);
666
1038
  case 16:
667
- value.e -= moveValue;
668
- return _context8.abrupt("continue", 17);
1039
+ value.e += moveValue;
1040
+ return _context8.abrupt("continue", 18);
669
1041
  case 17:
670
- if (compareSVGRect(value)) props.viewer2DActions.updateCameraView(value);
671
- return _context8.abrupt("continue", 34);
1042
+ value.e -= moveValue;
1043
+ return _context8.abrupt("continue", 18);
672
1044
  case 18:
1045
+ if (compareSVGRect(value)) props.viewer2DActions.updateCameraView(value);
1046
+ return _context8.abrupt("continue", 35);
1047
+ case 19:
673
1048
  defaulTitle = 'Untitle';
674
1049
  props.projectActions.newProject();
675
1050
  props.projectActions.rename(defaulTitle);
676
- return _context8.abrupt("continue", 34);
677
- case 19:
678
- _evt$payload4 = evt.payload, doorStyle = _evt$payload4.doorStyle, itemCDS = _evt$payload4.itemCDS, isAll = _evt$payload4.isAll;
679
- props.itemsActions.setDoorStyle(doorStyle, itemCDS, isAll);
680
- return _context8.abrupt("continue", 34);
1051
+ return _context8.abrupt("continue", 35);
681
1052
  case 20:
1053
+ _evt$payload6 = evt.payload, doorStyle = _evt$payload6.doorStyle, itemCDS = _evt$payload6.itemCDS, isAll = _evt$payload6.isAll;
1054
+ props.itemsActions.setDoorStyle(doorStyle, itemCDS, isAll);
1055
+ return _context8.abrupt("continue", 35);
1056
+ case 21:
682
1057
  _doorStyle = evt.payload.doorStyle;
683
1058
  props.itemsActions.setInitialDoorStyle(_doorStyle.doorStyle);
684
- return _context8.abrupt("continue", 34);
685
- case 21:
686
- props.projectActions.loadProject(evt.payload);
687
- return _context8.abrupt("continue", 34);
1059
+ return _context8.abrupt("continue", 35);
688
1060
  case 22:
1061
+ props.projectActions.loadProject(evt.payload);
1062
+ return _context8.abrupt("continue", 35);
1063
+ case 23:
689
1064
  _value = state.getIn(['viewer2D']).toJS();
690
1065
  _value.a -= 0.1;
691
1066
  _value.d -= 0.1;
@@ -693,17 +1068,17 @@ function _handleExternalEvent() {
693
1068
  _value.f += _value.SVGHeight * 0.1 / 2;
694
1069
  _zoomValue = parseInt((_value.a - 0.5) / _constants.ZOOM_VARIABLE);
695
1070
  if (!(_zoomValue > 404)) {
696
- _context8.next = 23;
1071
+ _context8.next = 24;
697
1072
  break;
698
1073
  }
699
1074
  return _context8.abrupt("return");
700
- case 23:
1075
+ case 24:
701
1076
  if (!(_zoomValue < 35 || Number.isNaN(_zoomValue))) {
702
- _context8.next = 24;
1077
+ _context8.next = 25;
703
1078
  break;
704
1079
  }
705
1080
  return _context8.abrupt("return");
706
- case 24:
1081
+ case 25:
707
1082
  while (!(_value.e <= 10)) {
708
1083
  _value.e -= 0.1;
709
1084
  }
@@ -717,8 +1092,8 @@ function _handleExternalEvent() {
717
1092
  _value.f += 0.1;
718
1093
  }
719
1094
  if (compareSVGRect(_value)) props.viewer2DActions.updateCameraView(_value);
720
- return _context8.abrupt("continue", 34);
721
- case 25:
1095
+ return _context8.abrupt("continue", 35);
1096
+ case 26:
722
1097
  _value2 = state.getIn(['viewer2D']).toJS();
723
1098
  _value2.a += 0.1;
724
1099
  _value2.d += 0.1;
@@ -726,31 +1101,31 @@ function _handleExternalEvent() {
726
1101
  _value2.f -= _value2.SVGHeight * 0.1 / 2;
727
1102
  _zoomValue2 = parseInt((_value2.a - 0.5) / _constants.ZOOM_VARIABLE);
728
1103
  if (!(_zoomValue2 > 404)) {
729
- _context8.next = 26;
1104
+ _context8.next = 27;
730
1105
  break;
731
1106
  }
732
1107
  return _context8.abrupt("return");
733
- case 26:
1108
+ case 27:
734
1109
  if (!(_zoomValue2 < 35 || Number.isNaN(_zoomValue2))) {
735
- _context8.next = 27;
1110
+ _context8.next = 28;
736
1111
  break;
737
1112
  }
738
1113
  return _context8.abrupt("return");
739
- case 27:
740
- if (compareSVGRect(_value2)) props.viewer2DActions.updateCameraView(_value2);
741
- return _context8.abrupt("continue", 34);
742
1114
  case 28:
743
- props.projectActions.undo();
744
- return _context8.abrupt("continue", 34);
1115
+ if (compareSVGRect(_value2)) props.viewer2DActions.updateCameraView(_value2);
1116
+ return _context8.abrupt("continue", 35);
745
1117
  case 29:
746
- props.projectActions.redo();
747
- return _context8.abrupt("continue", 34);
1118
+ props.projectActions.undo();
1119
+ return _context8.abrupt("continue", 35);
748
1120
  case 30:
749
- _evt$payload5 = evt.payload, moldingInfo = _evt$payload5.moldingInfo, isGlobal = _evt$payload5.isGlobal;
750
- props.itemsActions.setMolding(moldingInfo, isGlobal);
751
- return _context8.abrupt("continue", 34);
1121
+ props.projectActions.redo();
1122
+ return _context8.abrupt("continue", 35);
752
1123
  case 31:
753
- _evt$payload6 = evt.payload, option = _evt$payload6.option, _value3 = _evt$payload6.value;
1124
+ _evt$payload7 = evt.payload, moldingInfo = _evt$payload7.moldingInfo, isGlobal = _evt$payload7.isGlobal;
1125
+ props.itemsActions.setMolding(moldingInfo, isGlobal);
1126
+ return _context8.abrupt("continue", 35);
1127
+ case 32:
1128
+ _evt$payload8 = evt.payload, option = _evt$payload8.option, _value3 = _evt$payload8.value;
754
1129
  if (option === _constants.PROJECT_SETTING_OPTION.UPDATE_CEIL_HEIGHT) {
755
1130
  props.viewer2DActions.updateCeilHeight(_value3);
756
1131
  props.viewer3DActions.update3DCeilHeight(_value3);
@@ -763,11 +1138,16 @@ function _handleExternalEvent() {
763
1138
  } else if (option === _constants.PROJECT_SETTING_OPTION.CHANGE_WINDOW_DOOR_MEASURE) {
764
1139
  props.viewer2DActions.changeWindowDoorMeasure(_value3);
765
1140
  }
766
- return _context8.abrupt("continue", 34);
767
- case 32:
768
- distancePayload = evt.payload;
769
- props.itemsActions.changeDistance(distancePayload);
1141
+ return _context8.abrupt("continue", 35);
770
1142
  case 33:
1143
+ layerId = state.getIn(['scene', 'selectedLayer']);
1144
+ layer = state.getIn(['scene', 'layers', layerId]);
1145
+ _layer$getIn = layer.getIn(['selected']), selectedLines = _layer$getIn.lines, selectedHoles = _layer$getIn.holes, selectedItems = _layer$getIn.items;
1146
+ for (_i2 = 0; _i2 < selectedLines.size; _i2++) (evt === null || evt === void 0 ? void 0 : evt.type) === _constants.EXTERNAL_EVENT_UPDATE_ATTRIBUTE ? updateAttributeOfSelectedElement(layer.getIn(['lines', selectedLines.get(_i2)]), evt.payload, state, layer, props.projectActions) : updatePropertyOfSelectedElement(layer.getIn(['lines', selectedLines.get(_i2)]), evt.payload, props.catalog, props.projectActions);
1147
+ for (_i3 = 0; _i3 < selectedHoles.size; _i3++) (evt === null || evt === void 0 ? void 0 : evt.type) === _constants.EXTERNAL_EVENT_UPDATE_ATTRIBUTE ? updateAttributeOfSelectedElement(layer.getIn(['holes', selectedHoles.get(_i3)]), evt.payload, state, layer, props.projectActions) : updatePropertyOfSelectedElement(layer.getIn(['holes', selectedHoles.get(_i3)]), evt.payload, props.catalog, props.projectActions);
1148
+ for (_i4 = 0; _i4 < selectedItems.size; _i4++) (evt === null || evt === void 0 ? void 0 : evt.type) === _constants.EXTERNAL_EVENT_UPDATE_ATTRIBUTE ? updateAttributeOfSelectedElement(layer.getIn(['items', selectedItems.get(_i4)]), evt.payload, state, layer, props.projectActions) : updatePropertyOfSelectedElement(layer.getIn(['items', selectedItems.get(_i4)]), evt.payload, props.catalog, props.projectActions);
1149
+ return _context8.abrupt("continue", 35);
1150
+ case 34:
771
1151
  // send scene object from 3DTool to HostApp using internalEvent
772
1152
  (_props$onInternalEven2 = props.onInternalEvent) === null || _props$onInternalEven2 === void 0 || _props$onInternalEven2.call(props, {
773
1153
  type: _constants.INTERNAL_EVENT_SYNC_SCENE,
@@ -775,7 +1155,7 @@ function _handleExternalEvent() {
775
1155
  scene: state.scene.toJS()
776
1156
  }
777
1157
  });
778
- case 34:
1158
+ case 35:
779
1159
  case "end":
780
1160
  return _context8.stop();
781
1161
  }