'use strict';

var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
var _createClass = require('@babel/runtime/helpers/createClass');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _regeneratorRuntime = require('@babel/runtime/regenerator');
var index = require('./index-7d6992d6.js');
var DivaUtils = require('@crystaldesign/diva-utils');
var PlannerHandler2D = require('./PlannerHandler2D-84b798d7.js');
require('@babel/runtime/helpers/slicedToArray');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/toConsumableArray');
require('axios');
require('@crystaldesign/basket-model');
require('@crystaldesign/basket-handler');
require('socket.io-client');
require('@babel/runtime/helpers/typeof');
require('fabric');
require('w3c-xmlserializer');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator);
var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck);
var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);
var DivaUtils__default = /*#__PURE__*/_interopDefaultLegacy(DivaUtils);

var LOG = DivaUtils__default["default"].initLog('Planner', 'WEB-PLANNER-LOGIC');
var ACC_DOCK_TYPES = ['AVO', 'AVU', 'AVC', 'AVS', 'AVN'];
var DivaStandardPlanner = /*#__PURE__*/function () {
  /*
    This function updates te planner data of all Elements if they changed. 
    It returns true if some values changed - otherwise it returns false
    */
  /*private updatePlannerData(): boolean {
        return true;
    }*/

  function DivaStandardPlanner(set, updatePlannerMsgContainer, plannerId, globalBoundingBox, doDisablePlanner2D, plannerHasStaticBackground) {
    var _this = this;
    _classCallCheck__default["default"](this, DivaStandardPlanner);
    _defineProperty__default["default"](this, "plannerID", void 0);
    _defineProperty__default["default"](this, "set", void 0);
    _defineProperty__default["default"](this, "plannerBoundingBox", void 0);
    _defineProperty__default["default"](this, "plannerElements", void 0);
    //speichert alle Renderings
    _defineProperty__default["default"](this, "doDisablePlanner2D", false);
    //Do not load any SVGs or 2DPlanner things
    _defineProperty__default["default"](this, "plannerHasStaticBackground", void 0);
    //IDM
    _defineProperty__default["default"](this, "isIDM3DCat", false);
    _defineProperty__default["default"](this, "IDM3DCatCodex", '');
    _defineProperty__default["default"](this, "nextElementId", 1);
    _defineProperty__default["default"](this, "collisionHandler", void 0);
    _defineProperty__default["default"](this, "dockToAVUorAVOororAVNorAVSorAVC", function (plannerElement, targetElements) {
      if (plannerElement.HasAVU) {
        //Try to dock Element to free AVR
        var successDP = PlannerHandler2D.dockingPointHandlerInst.tryDockElement(plannerElement, 'AVU', targetElements);
        if (successDP) {
          _this.updateWorldPos(plannerElement, successDP);
          return true;
        }
        for (var i = 0; i < targetElements.length; i++) {
          var accessories = targetElements[i].getCurrentAccessorires();
          var newTargetElements = accessories.map(function (item) {
            return _this.plannerElements.get(item.getElementId());
          });
          var _successDP = _this.dockToAVUorAVOororAVNorAVSorAVC(plannerElement, newTargetElements);
          if (_successDP) return true;
        }
      }
      if (plannerElement.HasAVO) {
        var _successDP2 = PlannerHandler2D.dockingPointHandlerInst.tryDockElement(plannerElement, 'AVO', targetElements);
        if (_successDP2) {
          _this.updateWorldPos(plannerElement, _successDP2);
          return true;
        }
      }
      if (plannerElement.HasAVN) {
        var _successDP3 = PlannerHandler2D.dockingPointHandlerInst.tryDockElement(plannerElement, 'AVN', targetElements);
        if (_successDP3) {
          _this.updateWorldPos(plannerElement, _successDP3);
          return true;
        }
      }
      if (plannerElement.HasAVS) {
        var _successDP4 = PlannerHandler2D.dockingPointHandlerInst.tryDockElement(plannerElement, 'AVS', targetElements);
        if (_successDP4) {
          _this.updateWorldPos(plannerElement, _successDP4);
          return true;
        }
      }
      if (plannerElement.HasAVC) {
        var _successDP5 = PlannerHandler2D.dockingPointHandlerInst.tryDockElement(plannerElement, 'AVC', targetElements);
        if (_successDP5) {
          _this.updateWorldPos(plannerElement, _successDP5);
          return true;
        }
      }
      return false;
    });
    this.set = set;
    this.plannerID = plannerId;
    this.plannerElements = new Map();
    this.plannerBoundingBox = new index.BoundingBox();
    this.plannerBoundingBox.initPlannerBBox(globalBoundingBox);
    this.doDisablePlanner2D = doDisablePlanner2D;
    this.collisionHandler = {
      updatePlannerMsgContainer: updatePlannerMsgContainer,
      collisionDetected: false,
      collisionPairs: []
    };
    this.plannerHasStaticBackground = plannerHasStaticBackground;
  }

  /**
   * This function updates all position numbers of all planner elements.
   * The sorting of the position number depends on element chains. When Elements are docked via AVR and AVL - this is one chain.
   * The positioning starts with the chain with the smalles x.
   * The position of the accessoires are saved in a separate accPosNr.
   */
  return _createClass__default["default"](DivaStandardPlanner, [{
    key: "updatePlannerPosNr",
    value: function updatePlannerPosNr() {
      var _this2 = this;
      //Bilde zuerst Ketten
      //Suche alle Elemente, die kein AVL haben, oder deren AVL nicht dockt.
      //All diese Werden anschließend der reihe nach sortiert.
      var startChainElements = [];
      var allElementsToUpdate = new Map();
      var that = this;
      this.plannerElements.forEach(function (plannerElement, elementId) {
        allElementsToUpdate.set(elementId, true);
        if (!plannerElement.IsDockedAccessoire) {
          if (!plannerElement.HasAVL || !plannerElement.dockingTypeIsDocking('AVL')) {
            startChainElements.push(plannerElement);
          }
        }
      });

      //Nun muss ich die Elemente so sortieren, dass die mit world pos ganz links sind.
      if (!this.getCatalogData().dontSetPosNrFromPlanner) startChainElements = startChainElements.sort(function (a, b) {
        return a.WorldPosCenter.x - b.WorldPosCenter.x;
      });
      var posNrAcc;
      var _updateAccessoiresOfElement = function updateAccessoiresOfElement(curElement, posNrParent) {
        //Nun habe ich ein Element und muss überprüfen, ob es Accessoires hat. Das sind Elemente, die über AVO, AVU oder AVC gedockt sind.
        var accElements = [];
        var setPosNrForElementsOnDock = function setPosNrForElementsOnDock(d, accElements) {
          if (!curElement['Has' + d]) return;
          var dps = curElement.getDockingDockingPointsByType(d);
          dps = dps.sort(function (a, b) {
            return that.plannerElements.get(a.OnElementId).WorldPosCorner.x - that.plannerElements.get(b.OnElementId).WorldPosCorner.x;
          });
          for (var i = 0; i < dps.length; i++) {
            var refElementId = dps[i].OnElementId;
            if (allElementsToUpdate.has(refElementId)) {
              var refElement = that.plannerElements.get(refElementId);
              refElement.PosNr = posNrParent;
              refElement.AccessoirePosNr = posNrAcc;
              allElementsToUpdate["delete"](refElementId);
              posNrAcc++;
              accElements.push(refElement);
            }
          }
        };
        for (var _i = 0; _i < ACC_DOCK_TYPES.length; _i++) {
          setPosNrForElementsOnDock(ACC_DOCK_TYPES[_i], accElements);
        }
        _this2.plannerElements.forEach(function (element) {
          if (element.getIsNotDockedAccessoire() && element.getParentElementId() === curElement.getElementId()) {
            element.PosNr = posNrParent;
            element.AccessoirePosNr = posNrAcc;
            allElementsToUpdate["delete"](element.getElementId());
            posNrAcc++;
            accElements.push(element);
          }
        });

        //ACHTUNG ich darf nicht immer AVO AVU und AVC abfragen. Am Ende habe ich alles doppelt gemacht!!!!
        for (var i = 0; i < accElements.length; i++) {
          _updateAccessoiresOfElement(accElements[i], posNrParent);
        }
      };
      /**
       * This function sets the posNr of each element in a chain. At the end it returns the currentPosNr
       * @param curElementInChain
       * @param posNr
       */
      var _updatePosInChain = function updatePosInChain(curElementInChain, posNr) {
        if (curElementInChain == undefined) return posNr;
        curElementInChain.PosNr = posNr;
        posNrAcc = 1;
        allElementsToUpdate["delete"](curElementInChain.ElementId);
        _updateAccessoiresOfElement(curElementInChain, posNr);
        posNr++;
        if (!curElementInChain.HasAVR || !curElementInChain.dockingTypeIsDocking('AVR')) {
          //End of chain
          return posNr;
        } else {
          //Not end of chain Get nextElement
          var dps = curElementInChain.getDockingDockingPointsByType('AVR');
          var refElementId = dps[0].OnElementId;
          return _updatePosInChain(that.plannerElements.get(refElementId), posNr);
        }
      };
      var posNr = 1;
      for (var i = 0; i < startChainElements.length; i++) {
        posNr = _updatePosInChain(startChainElements[i], posNr);
      }
    }

    /**
     * This function updates the world pos of a planner Element depending on the docking Point.
     * The docking Point contains all necessary information
     * @param plannerElement
     * @param dockingPoint
     */
  }, {
    key: "updateWorldPos",
    value: function updateWorldPos(plannerElement, dockingPoint) {
      var updateConfig = false;
      var refElement = this.plannerElements.get(dockingPoint.OnElementId);
      var refDockingPoint = refElement.getDockingPointById(dockingPoint.OnDP.DpId);
      if (refDockingPoint == undefined) return updateConfig;
      var worldPosNewElement = new index.Vector3(0, 0, 0);
      var worldPosNewElementIgnoreOLF = new index.Vector3(0, 0, 0);

      // DP LocalWorldPos is OLF-corner-relative when HasOLFPolygon (from SVG). Convert to OLT-corner-relative for WorldPosCornerIgnoreOLF.
      var refDPLocalOlt = refElement.HasOLFPolygon ? new index.Vector2(refDockingPoint.LocalWorldPos.x - refElement.getOltLeft(), refDockingPoint.LocalWorldPos.z - refElement.getOltTop()) : new index.Vector2(refDockingPoint.LocalWorldPos.x, refDockingPoint.LocalWorldPos.z);
      var newDPLocalOlt = plannerElement.HasOLFPolygon ? new index.Vector2(dockingPoint.LocalWorldPos.x - plannerElement.getOltLeft(), dockingPoint.LocalWorldPos.z - plannerElement.getOltTop()) : new index.Vector2(dockingPoint.LocalWorldPos.x, dockingPoint.LocalWorldPos.z);
      var rotatedLocalRefDP = new index.Vector2(refDockingPoint.LocalWorldPos.x, refDockingPoint.LocalWorldPos.z);
      rotatedLocalRefDP = index.Vector2.rotateOrigin(rotatedLocalRefDP, refElement.RotDeg);
      var angleToRot = refElement.RotDeg + refDockingPoint.RotDeg - dockingPoint.RotDeg;
      plannerElement.RotDeg = angleToRot;
      var refWorldPosCor = refElement.WorldPosCorner;
      // For ref without OLF: use same corner for both alignments (no OLF/OLT split; WorldPosCornerIgnoreOLF getter also does this).
      var refWorldPosCorIgnoreOLF = refElement.HasOLFPolygon ? refElement.WorldPosCornerIgnoreOLF : refWorldPosCor;
      var rotatedLocalDP2D = index.Vector2.rotateOrigin(new index.Vector2(dockingPoint.LocalWorldPos.x, dockingPoint.LocalWorldPos.z), angleToRot);
      worldPosNewElement.x = refWorldPosCor.x + rotatedLocalRefDP.x - rotatedLocalDP2D.x;
      worldPosNewElement.y = refWorldPosCor.y + refDockingPoint.LocalWorldPos.y - dockingPoint.LocalWorldPos.y;
      worldPosNewElement.z = refWorldPosCor.z + rotatedLocalRefDP.y - rotatedLocalDP2D.y;
      var rotatedRefDPOlt = index.Vector2.rotateOrigin(refDPLocalOlt, refElement.RotDeg);
      var rotatedNewDPOlt = index.Vector2.rotateOrigin(newDPLocalOlt, angleToRot);
      worldPosNewElementIgnoreOLF.x = refWorldPosCorIgnoreOLF.x + rotatedRefDPOlt.x - rotatedNewDPOlt.x;
      worldPosNewElementIgnoreOLF.z = refWorldPosCorIgnoreOLF.z + rotatedRefDPOlt.y - rotatedNewDPOlt.y;
      worldPosNewElementIgnoreOLF.y = refWorldPosCorIgnoreOLF.y + refDockingPoint.LocalWorldPos.y - dockingPoint.LocalWorldPos.y;
      plannerElement.WorldPosCorner = worldPosNewElement;
      plannerElement.WorldPosCornerIgnoreOLF = worldPosNewElementIgnoreOLF;
      updateConfig = this.set.onDockingChanged(plannerElement.ElementId, refElement.ElementId, 'DOCK', dockingPoint.Type);
      var data = this.set.getPlannerData(plannerElement.ElementId);
      plannerElement.updatePlannerData(data);
      var refData = this.set.getPlannerData(refElement.ElementId);
      refElement.updatePlannerData(refData);
      return updateConfig;
    }

    /**
     * This function updates the position information of all elements. It is called after updating the SVG of 1 element.
     * The position is updated based on the posNr.
     * At the end - the collision is calculated
     */
  }, {
    key: "updateAllElementsWorldPos",
    value: function updateAllElementsWorldPos(checkCollisionSingleElementId) {
      if (this.doDisablePlanner2D) return false;
      var updateConfig = false;
      var sortedPlannerElementsbyPosNr = [];
      var accElems = [];
      this.plannerElements.forEach(function (plannerElement, elementId) {
        if (!plannerElement.IsDockedAccessoire) {
          sortedPlannerElementsbyPosNr[plannerElement.PosNr - 1] = plannerElement;
        } else {
          accElems.push(plannerElement);
        }
      });
      sortedPlannerElementsbyPosNr = sortedPlannerElementsbyPosNr.concat(accElems);
      var alreadyCorrectedId = [];
      var firstI = 0;
      for (var i = 0; i < sortedPlannerElementsbyPosNr.length; i++) {
        if (!sortedPlannerElementsbyPosNr[i]) {
          firstI = i;
        } else {
          var element = sortedPlannerElementsbyPosNr[i];
          alreadyCorrectedId.push(element.ElementId);
          if (i > firstI) {
            var dockingPoints = element.getDockingDockingPointsByType('AVL').concat(element.getDockingDockingPointsByType('AVR')).concat(element.getDockingDockingPointsByType('AVU')).concat(element.getDockingDockingPointsByType('AVO')).concat(element.getDockingDockingPointsByType('AVN')).concat(element.getDockingDockingPointsByType('AVS')).concat(element.getDockingDockingPointsByType('AVC'));
            for (var j = 0; j < dockingPoints.length; j++) {
              //Nur wenn er auf ein element schaut das schon gedockt ist korrigieren
              if (alreadyCorrectedId.indexOf(dockingPoints[j].OnElementId) >= 0) {
                updateConfig = this.updateWorldPos(element, dockingPoints[j]);
                break;
              }
            }
          }
        }
      }
      this.checkCollision(false, checkCollisionSingleElementId);
      return updateConfig;
    }

    /**
     * this function tries to position a planner element to the current planner elements in the world.
     * If a element is selected it tries to dock the new planner Element to the selected planner element.
     * If additional a docking Point is selected - it only docks to the selected docking point.
     * If no element or DP is selected - it docks to the first free element.
     * @param plannerElement    The planner Element that is added to the planning scene
     * @param dockToElementId   A planner element the new plannerElement should be docked to.
     * @param docktToAVName     The AV Name of the dockToElement to dock.
     */
  }, {
    key: "addElementToWorld",
    value: (function () {
      var _addElementToWorld = _asyncToGenerator__default["default"](/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(plannerElement, dockingPointInfos, suppressDock, globalBoundingBox) {
        var xOffset,
          setToTransform,
          dockingFound,
          i,
          targetElemIdToDock,
          targetDockingPointId,
          targetElem,
          targetDP,
          successDP,
          success,
          allPlannerElements,
          _success,
          _args = arguments;
        return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
          while (1) switch (_context.prev = _context.next) {
            case 0:
              xOffset = _args.length > 4 && _args[4] !== undefined ? _args[4] : 100;
              setToTransform = _args.length > 5 ? _args[5] : undefined;
              if (!(setToTransform && setToTransform.forceSetToTrans)) {
                _context.next = 8;
                break;
              }
              plannerElement.WorldPosCenter = setToTransform.transform.worldPosCenter;
              plannerElement.RotDeg = setToTransform.transform.rotDeg;
              this.set.onDockingChanged(plannerElement.ElementId, -1, 'NOT_DOCKED');
              _context.next = 47;
              break;
            case 8:
              //Nun unterscheidet man, ob man das Element zu einem bestimmten vorselektierten Element Docken will , zu einem vorselektierten DockingPoint oder an eine Freie Planung.
              dockingFound = false;
              if (!dockingPointInfos) {
                _context.next = 46;
                break;
              }
              i = 0;
            case 11:
              if (!(i < dockingPointInfos.length)) {
                _context.next = 46;
                break;
              }
              targetElemIdToDock = dockingPointInfos[i].targetElemIdToDock;
              targetDockingPointId = dockingPointInfos[i].targetDockingPointId;
              if (!(targetElemIdToDock && targetElemIdToDock > -1 && this.plannerElements.has(targetElemIdToDock))) {
                _context.next = 43;
                break;
              }
              if (!(targetDockingPointId && targetDockingPointId != '')) {
                _context.next = 31;
                break;
              }
              targetElem = this.plannerElements.get(targetElemIdToDock);
              if (!targetElem) {
                _context.next = 29;
                break;
              }
              targetDP = targetElem.getDockingPointById(targetDockingPointId);
              if (!targetDP) {
                _context.next = 29;
                break;
              }
              successDP = PlannerHandler2D.dockingPointHandlerInst.tryDockElementToDP(plannerElement, targetElem, targetDP);
              if (!successDP) {
                _context.next = 26;
                break;
              }
              this.updateWorldPos(plannerElement, successDP);
              dockingFound = true;
              _context.next = 29;
              break;
            case 26:
              _context.next = 28;
              return this.tryToDockWithDifferentSVGWithFormula(plannerElement, targetElemIdToDock);
            case 28:
              success = _context.sent;
            case 29:
              _context.next = 43;
              break;
            case 31:
              success = false;
              if (plannerElement.HasAVL || plannerElement.HasAVR) {
                success = this.dockToAVLorAVR(plannerElement, [this.plannerElements.get(targetElemIdToDock)]);
              }
              if (!success) {
                success = this.dockToAVUorAVOororAVNorAVSorAVC(plannerElement, [this.plannerElements.get(targetElemIdToDock)]);
              }
              if (success) {
                _context.next = 42;
                break;
              }
              _context.next = 37;
              return this.tryToDockWithDifferentSVGWithFormula(plannerElement, targetElemIdToDock);
            case 37:
              success = _context.sent;
              if (success) {
                _context.next = 42;
                break;
              }
              _context.next = 41;
              return this.addElementToWorld(plannerElement, undefined, undefined, undefined, 50);
            case 41:
              return _context.abrupt("return");
            case 42:
              if (success) dockingFound = true;
            case 43:
              i++;
              _context.next = 11;
              break;
            case 46:
              if (!dockingFound) {
                allPlannerElements = this.getAllPlannerElements();
                _success = this.dockToAVLorAVR(plannerElement, allPlannerElements);
                if (suppressDock) _success = false;
                if (!_success) {
                  //No free AVR or AVL Docking Point
                  _success = this.dockToAVUorAVOororAVNorAVSorAVC(plannerElement, allPlannerElements);
                  if (suppressDock) _success = false;
                  if (!_success) {
                    //This is the center position of the element - This is needed in order to set the static room layout correctly

                    if (globalBoundingBox == undefined) {
                      plannerElement.WorldPosCenter = new index.Vector3(this.plannerBoundingBox.WorldPos.x + this.plannerBoundingBox.Size.x + (this.plannerBoundingBox.Size.x == 0 ? 0 : plannerElement.Width / 2 + xOffset), this.plannerBoundingBox.WorldPos.y + plannerElement.Height / 2, this.plannerBoundingBox.WorldPos.z + plannerElement.Depth / 2);
                    }

                    //Tell the set this the element was not docked
                    this.set.onDockingChanged(plannerElement.ElementId, -1, 'NOT_DOCKED');
                  }
                }
              }
            case 47:
              this.updatePlannerPosNr();
              this.updateAllElementsWorldPos();
              this.updatePlannerPosNr();
              this.checkCollision(false, plannerElement.getElementId());
              this.updatePlannerBoundingBox();
            case 52:
            case "end":
              return _context.stop();
          }
        }, _callee, this);
      }));
      function addElementToWorld(_x, _x2, _x3, _x4) {
        return _addElementToWorld.apply(this, arguments);
      }
      return addElementToWorld;
    }())
  }, {
    key: "tryToDockWithDifferentSVGWithFormula",
    value: function () {
      var _tryToDockWithDifferentSVGWithFormula = _asyncToGenerator__default["default"](/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(plannerElement, targetElemIdToDock) {
        var success, article, origVariantValues, svgsWithFormula, i, elements, variantValues, vv, key, v, _i2, _vv, _elements, _variantValues, _key, _elements2, _variantValues2, _key2;
        return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) {
          while (1) switch (_context2.prev = _context2.next) {
            case 0:
              //this is done for elements with different sitztiefen in the svgsWithFormula
              success = false;
              article = this.set.getArticleByElementId(plannerElement.ElementId);
              origVariantValues = article === null || article === void 0 ? void 0 : article.VariantValues;
              svgsWithFormula = plannerElement.getSVGsWithFormula();
              if (!(plannerElement.FilterAVL.length || plannerElement.FilterAVR.length)) {
                _context2.next = 47;
                break;
              }
              if (!(svgsWithFormula !== null && svgsWithFormula !== void 0 && svgsWithFormula.length)) {
                _context2.next = 22;
                break;
              }
              i = 0;
            case 7:
              if (!(i < svgsWithFormula.length)) {
                _context2.next = 22;
                break;
              }
              elements = new Map();
              variantValues = new Map();
              vv = DivaUtils__default["default"].getVariantValuesFromRule(svgsWithFormula[i].JsFormula, {});
              for (key in vv) {
                variantValues.set(key, vv[key]);
              }
              elements.set(plannerElement.ElementId, variantValues);
              _context2.next = 15;
              return this.set.updateCfgValuesByPlanner(elements, true);
            case 15:
              success = this.dockToAVLorAVR(plannerElement, [this.plannerElements.get(targetElemIdToDock)]);
              if (!success) {
                _context2.next = 19;
                break;
              }
              //svg did match
              LOG.debug('svgWithFormula nr: ' + i + ' did dock: ' + svgsWithFormula[i].SVG);
              return _context2.abrupt("break", 22);
            case 19:
              i++;
              _context2.next = 7;
              break;
            case 22:
              //other logic. look for decisions with featrue 90 or 89 and try change the options that influence 90 - 89
              v = plannerElement.getVaraintValuesInfluencingAVLAVRFilter();
              if (!(v !== null && v !== void 0 && v.length && !success)) {
                _context2.next = 40;
                break;
              }
              _i2 = 0;
            case 25:
              if (!(_i2 < v.length && _i2 < 20)) {
                _context2.next = 40;
                break;
              }
              _vv = v[_i2];
              _elements = new Map();
              _variantValues = new Map();
              for (_key in _vv) {
                _variantValues.set(_key, _vv[_key]);
              }
              _elements.set(plannerElement.ElementId, _variantValues);
              _context2.next = 33;
              return this.set.updateCfgValuesByPlanner(_elements, true);
            case 33:
              success = this.dockToAVLorAVR(plannerElement, [this.plannerElements.get(targetElemIdToDock)]);
              if (!success) {
                _context2.next = 37;
                break;
              }
              //variantValues did match
              LOG.debug('following variantValues did dock: ', _variantValues);
              return _context2.abrupt("break", 40);
            case 37:
              _i2++;
              _context2.next = 25;
              break;
            case 40:
              if (success) {
                _context2.next = 47;
                break;
              }
              _elements2 = new Map();
              _variantValues2 = new Map();
              for (_key2 in origVariantValues) {
                _variantValues2.set(_key2, origVariantValues[_key2]);
              }
              _elements2.set(plannerElement.ElementId, _variantValues2);
              _context2.next = 47;
              return this.set.updateCfgValuesByPlanner(_elements2, true);
            case 47:
              return _context2.abrupt("return", success);
            case 48:
            case "end":
              return _context2.stop();
          }
        }, _callee2, this);
      }));
      function tryToDockWithDifferentSVGWithFormula(_x5, _x6) {
        return _tryToDockWithDifferentSVGWithFormula.apply(this, arguments);
      }
      return tryToDockWithDifferentSVGWithFormula;
    }()
  }, {
    key: "dockToAVLorAVR",
    value: function dockToAVLorAVR(plannerElement, targetElements) {
      var successfullyDockedAVL = false;
      var successfullyDockedAVR = false;
      if (plannerElement.HasAVL) {
        //Try to dock Element to free AVR
        var successDP = PlannerHandler2D.dockingPointHandlerInst.tryDockElement(plannerElement, 'AVL', targetElements);
        if (successDP) {
          this.updateWorldPos(plannerElement, successDP);
          successfullyDockedAVL = true; //Wenn es funktioniert
        }
      }
      if (!successfullyDockedAVL) {
        if (plannerElement.HasAVR) {
          var _successDP6 = PlannerHandler2D.dockingPointHandlerInst.tryDockElement(plannerElement, 'AVR', targetElements);
          if (_successDP6) {
            successfullyDockedAVR = true;
            this.updateWorldPos(plannerElement, _successDP6);
          }
        }
      }
      return successfullyDockedAVL || successfullyDockedAVR;
    }
  }, {
    key: "getAllViewPlannerElements",
    value: function getAllViewPlannerElements() {
      return this.getAllPlannerElements();
    }
  }, {
    key: "getFreeDockingPointsByElementId",
    value: function getFreeDockingPointsByElementId(elementId, dockingType) {
      if (!this.plannerElements.has(elementId)) return {
        dockingPoints: [],
        filter: []
      };
      var element = this.plannerElements.get(elementId);
      var dockingPoints = element.getFreeDockingPointsByType(dockingType);
      var filter = [];
      switch (dockingType) {
        case 'AVR':
          filter = element.getFilterAVR();
          break;
        case 'AVL':
          filter = element.getFilterAVL();
          break;
      }
      return {
        dockingPoints: dockingPoints,
        filter: filter
      };
    }
  }, {
    key: "getDockedDockingPointsByElementId",
    value: function getDockedDockingPointsByElementId(elementId, dockingTypes) {
      if (!this.plannerElements.has(elementId)) return [];
      var element = this.plannerElements.get(elementId);
      var dockingPoints = [];
      for (var i = 0; i < dockingTypes.length; i++) {
        dockingPoints = dockingPoints.concat(element.getDockingDockingPointsByType(dockingTypes[i]));
      }
      return dockingPoints;
    }
  }, {
    key: "getNeighborElements",
    value: function getNeighborElements(elementId, dockingType) {
      if (!this.plannerElements.has(elementId)) return [];
      var element = this.plannerElements.get(elementId);
      var dockingPoints = element === null || element === void 0 ? void 0 : element.getDockingDockingPointsByType(dockingType);
      if (!dockingPoints) return [];
      var neighbors = [];
      for (var i = 0; i < (dockingPoints === null || dockingPoints === void 0 ? void 0 : dockingPoints.length); i++) {
        if (dockingPoints[i] != undefined) neighbors.push(dockingPoints[i].OnElementId);
      }
      return neighbors;
    }

    /**
     * This function returns all grouped elements.
     * It contains also all Accessoires of the elements
     */
  }, {
    key: "getDockedGroups",
    value: function getDockedGroups() {
      var startChainElements = [];
      var allElements = this.getAllPlannerElements();
      var elementsToAdd = [];

      //Search start elements for each chain
      for (var i = 0; i < this.getAllPlannerElements().length; i++) {
        var element = allElements[i];
        elementsToAdd.push(element.getElementId());
        if (element.IsAccessoire) continue;
        var dpsAVL = element.getDockingPointsByType('AVL');
        if (!dpsAVL || dpsAVL.length == 0) {
          startChainElements.push(element);
          continue;
        } else {
          for (var j = 0; j < dpsAVL.length; j++) {
            if (!dpsAVL[j].IsDocking) startChainElements.push(element);
            continue;
          }
        }
      }
      startChainElements.sort(function (a, b) {
        return a.WorldPosCorner.x < b.WorldPosCorner.x ? 1 : 0;
      });
      var groupElements = [];

      //Create groups for all chains
      for (var i = 0; i < startChainElements.length; i++) {
        var startChainElement = startChainElements[i];
        var group = [];
        elementsToAdd.splice(elementsToAdd.indexOf(startChainElement.getElementId()), 1);
        var groupIsFinished = false;
        var curElementInGroup = startChainElement;
        while (!groupIsFinished) {
          group.push(curElementInGroup.getElementId());
          elementsToAdd.splice(elementsToAdd.indexOf(curElementInGroup.getElementId()), 1);
          var accsOfElement = this.getAccessoiresRecursive(curElementInGroup.getElementId());
          for (var j = 0; j < accsOfElement.length; j++) {
            group.push(accsOfElement[j]);
            elementsToAdd.splice(elementsToAdd.indexOf(accsOfElement[j]), 1);
          }
          var AVRElements = this.getNeighborElements(curElementInGroup.getElementId(), 'AVR');
          if (!AVRElements || AVRElements.length == 0) groupIsFinished = true;else curElementInGroup = this.plannerElements.get(AVRElements[0]);
        }
        groupElements.push(group);
      }
      //Add lost elements e.g accesoires that dock to nothing
      for (var i = 0; i < elementsToAdd.length; i++) {
        groupElements.push([elementsToAdd[i]]);
      }
      return groupElements;
    }
  }, {
    key: "getAccessoiresRecursive",
    value: function getAccessoiresRecursive(plannerElementId) {
      var that = this;
      var _calcAccs = function calcAccs(plannerElementId, listOfAccessoires, visitedElements) {
        visitedElements.push(plannerElementId);
        var AVCs = that.getNeighborElements(plannerElementId, 'AVC');
        var AVOs = that.getNeighborElements(plannerElementId, 'AVO');
        var AVUs = that.getNeighborElements(plannerElementId, 'AVU');
        var AVNs = that.getNeighborElements(plannerElementId, 'AVN');
        var AVSs = that.getNeighborElements(plannerElementId, 'AVS');
        var accs = AVCs.concat(AVOs).concat(AVUs).concat(AVNs).concat(AVSs);
        for (var i = 0; i < accs.length; i++) {
          if (visitedElements.indexOf(accs[i]) >= 0) continue;
          listOfAccessoires.push(accs[i]);
          visitedElements.push(accs[i]);
          _calcAccs(accs[i], listOfAccessoires, visitedElements);
        }
      };
      var listOfAccs = [];
      _calcAccs(plannerElementId, listOfAccs, []);
      return listOfAccs;
    }
  }, {
    key: "getBoundingBox",
    value: function getBoundingBox() {
      return this.plannerBoundingBox;
    }
  }, {
    key: "initIDM3DMeta",
    value: function initIDM3DMeta(IDM3DCatCodex) {
      this.isIDM3DCat = true;
      if (IDM3DCatCodex != '' && IDM3DCatCodex != undefined) {
        this.IDM3DCatCodex = IDM3DCatCodex;
      } else {
        this.IDM3DCatCodex = this.set.getCatalogCodex();
      }
    }
  }, {
    key: "updatePlanner",
    value: function () {
      var _updatePlanner = _asyncToGenerator__default["default"](/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3() {
        var allPlannerElements, elemtsWhereSomethingChanged, i, elem, doReload, elementsToDelete, elementsLostDockingRelation;
        return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context3) {
          while (1) switch (_context3.prev = _context3.next) {
            case 0:
              allPlannerElements = this.getAllPlannerElements();
              elemtsWhereSomethingChanged = [];
              i = 0;
            case 3:
              if (!(i < allPlannerElements.length)) {
                _context3.next = 13;
                break;
              }
              elem = allPlannerElements[i];
              doReload = elem.updatePlannerData(this.set.getPlannerData(elem.getElementId()));
              if (!doReload) {
                _context3.next = 10;
                break;
              }
              elemtsWhereSomethingChanged.push(elem.ElementId);
              _context3.next = 10;
              return PlannerHandler2D.handler2D.loadSVG(elem, this.set);
            case 10:
              i++;
              _context3.next = 3;
              break;
            case 13:
              elementsToDelete = [];
              if (elemtsWhereSomethingChanged.length) {
                LOG.debug('Configuration changed one plannerElement. UpdateDockingRelations', 'DivaStandardPlanner - updatePlanner');
                elementsLostDockingRelation = PlannerHandler2D.dockingPointHandlerInst.updateDockingRelations(this.plannerElements);
                for (i = 0; i < elementsLostDockingRelation.length; i++) {
                  if (elementsLostDockingRelation[i].IsDockedAccessoire) {
                    //Todo delete article
                    elementsToDelete.push(elementsLostDockingRelation[i].ElementId);
                  }
                }
                this.updateAllElementsWorldPos();
                this.updatePlannerPosNr();
                this.updatePlannerBoundingBox();
              }
              return _context3.abrupt("return", {
                doDeleteBackGrid: false,
                elemIdsToDelete: elementsToDelete,
                elementIdsToUpdateSelection: elemtsWhereSomethingChanged,
                failed: false
              });
            case 16:
            case "end":
              return _context3.stop();
          }
        }, _callee3, this);
      }));
      function updatePlanner() {
        return _updatePlanner.apply(this, arguments);
      }
      return updatePlanner;
    }()
    /**
     * This function extends one set. In order to position the new element correctly, use the information of the global Bounding box instead of the local bounding Box of the set.
     * @param setPlanData
     * @param globalBoundingBox
     */
  }, {
    key: "extendPlanner",
    value: (function () {
      var _extendPlanner = _asyncToGenerator__default["default"](/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4(setPlanData, globalBoundingBox) {
        var planDataString, planData, jsonElements, elementsSortedbyPosNr, accElements, oldElementidMapping, i, _jsonElement$Accessoi, jsonElement, catalogArticle, plannerElement, data, curElement, DPsInfo, j, dpInfo, sourceDP, targetElement, targetDP;
        return _regeneratorRuntime__default["default"].wrap(function _callee4$(_context4) {
          while (1) switch (_context4.prev = _context4.next) {
            case 0:
              planDataString = DivaUtils__default["default"].decodeBase64(setPlanData);
              planData = JSON.parse(planDataString);
              if (!(planData.v != null && planData.v == 2)) {
                _context4.next = 40;
                break;
              }
              jsonElements = planData.set.elements;
              elementsSortedbyPosNr = [];
              accElements = [];
              oldElementidMapping = new Map(); //First reset planner element values in jsonElement so that every set is planned to be set to origin
              i = 0;
            case 8:
              if (!(i < jsonElements.length)) {
                _context4.next = 36;
                break;
              }
              _context4.prev = 9;
              jsonElement = jsonElements[i];
              catalogArticle = this.set.CatalogData.getCatalogArticleByArticleCodex(jsonElement.articleCodex || jsonElement.Codex);
              if (!(!catalogArticle && (_jsonElement$Accessoi = jsonElement.AccessoireInitParams) !== null && _jsonElement$Accessoi !== void 0 && _jsonElement$Accessoi.RelatedToBasketID && !this.set.getSetState.onlyRunLogic)) {
                _context4.next = 15;
                break;
              }
              LOG.error(new DivaUtils.DivaError('Error initializing element nr ' + i + ' in the Standard Web Planner. PlanData V2', {
                code: 'WC_0012'
              }));
              return _context4.abrupt("continue", 33);
            case 15:
              plannerElement = new index.PlannerElementData(this.set.getSetId(), jsonElement.basketID, this.nextElementId, DivaStandardPlanner.plannerType);
              oldElementidMapping.set(parseInt(jsonElement.elementID), plannerElement);
              this.nextElementId = plannerElement.getElementId() + 1;
              this.plannerElements.set(plannerElement.ElementId, plannerElement);
              this.set.setElementId(jsonElement.basketID, plannerElement.ElementId);
              data = this.set.getPlannerData(plannerElement.ElementId);
              plannerElement.updatePlannerData(data);
              if (this.doDisablePlanner2D) {
                _context4.next = 25;
                break;
              }
              _context4.next = 25;
              return PlannerHandler2D.handler2D.loadSVG(plannerElement, this.set);
            case 25:
              plannerElement.WorldPosCenter = new index.Vector3(globalBoundingBox.WorldPos.x + globalBoundingBox.Size.x + jsonElement.x + 100, globalBoundingBox.WorldPos.y + jsonElement.y, globalBoundingBox.WorldPos.z + jsonElement.z);
              plannerElement.RotDeg = jsonElement.rot;
              if (plannerElement.IsDockedAccessoire) {
                accElements.push(jsonElement);
                plannerElement.PosNr = jsonElement.posNr;
                plannerElement.AccessoirePosNr = jsonElement.accNr;
              } else {
                elementsSortedbyPosNr[jsonElement.posNr - 1] = jsonElement;
                plannerElement.PosNr = jsonElement.posNr;
              }
              _context4.next = 33;
              break;
            case 30:
              _context4.prev = 30;
              _context4.t0 = _context4["catch"](9);
              LOG.error(new DivaUtils.DivaError('Error initializing element nr ' + i + ' in the Standard Web Planner. PlanData V2', {
                cause: _context4.t0,
                code: 'WC_0012'
              }));
            case 33:
              i++;
              _context4.next = 8;
              break;
            case 36:
              elementsSortedbyPosNr = elementsSortedbyPosNr.concat(accElements);
              for (i = 0; i < elementsSortedbyPosNr.length; i++) {
                curElement = oldElementidMapping.get(elementsSortedbyPosNr[i].elementID);
                if (elementsSortedbyPosNr.length > 1) {
                  //This is the case when a complex product is loaded
                  //First element is already positioned correctly not docket
                  if (i > 0) {
                    //The other elements are docked to the First element.
                    DPsInfo = elementsSortedbyPosNr[i].DP;
                    for (j = 0; j < DPsInfo.length; j++) {
                      dpInfo = DPsInfo[j];
                      sourceDP = curElement === null || curElement === void 0 ? void 0 : curElement.getDockingPointById(dpInfo.id);
                      targetElement = oldElementidMapping.get(dpInfo.onID);
                      targetDP = targetElement === null || targetElement === void 0 ? void 0 : targetElement.getDockingPointById(dpInfo.onDPID);
                      if (sourceDP && targetDP) {
                        PlannerHandler2D.dockingPointHandlerInst.tryDockElementDPToDP(curElement, targetElement, sourceDP, targetDP);
                      }
                    }
                  }
                }
              }
              _context4.next = 41;
              break;
            case 40:
              LOG.error(new DivaUtils.DivaError('The function extend Planner works only with products that are saved in the configurator 2.0', {
                code: 'WC_0012'
              }));
            case 41:
            case "end":
              return _context4.stop();
          }
        }, _callee4, this, [[9, 30]]);
      }));
      function extendPlanner(_x7, _x8) {
        return _extendPlanner.apply(this, arguments);
      }
      return extendPlanner;
    }())
  }, {
    key: "initPlanner",
    value: function () {
      var _initPlanner = _asyncToGenerator__default["default"](/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee5(setPlanData) {
        var planDataString, planData, jsonElements, elementsSortedbyPosNr, accElements, i, _jsonElement$Accessoi2, jsonElement, catalogArticle, elementID, plannerElement, data, onlyOneBaseElement, element, DPsInfo, j, dpInfo, sourceElement, sourceDP, targetElement, targetDP, _jsonElements, _elementsSortedbyPosNr, _accElements, _jsonElement$Accessoi3, _jsonElement, _catalogArticle, basketID, elementId, _plannerElement, _data, centerWorldPos, parentPosNr, accPosNr, _DPsInfo, _dpInfo, _this$plannerElements, targetElementId, dpType, curElement, _targetElement;
        return _regeneratorRuntime__default["default"].wrap(function _callee5$(_context5) {
          while (1) switch (_context5.prev = _context5.next) {
            case 0:
              planDataString = DivaUtils__default["default"].decodeBase64(setPlanData);
              planData = JSON.parse(planDataString);
              if (!(planData.v != null && planData.v == 2)) {
                _context5.next = 61;
                break;
              }
              LOG.debug('Initialize set Plan Data - V2\n' + planData, 'DivaStandardPlanner initPlanner');
              if (!(!planData.set || !planData.set.elements || planData.set.elements.length == 0)) {
                _context5.next = 6;
                break;
              }
              return _context5.abrupt("return");
            case 6:
              //Init new saved Plannings
              jsonElements = planData.set.elements;
              elementsSortedbyPosNr = [];
              accElements = [];
              i = 0;
            case 10:
              if (!(i < jsonElements.length)) {
                _context5.next = 38;
                break;
              }
              _context5.prev = 11;
              jsonElement = jsonElements[i];
              catalogArticle = this.set.CatalogData.getCatalogArticleByArticleCodex(jsonElement.articleCodex || jsonElement.Codex);
              if (!(!catalogArticle && (_jsonElement$Accessoi2 = jsonElement.AccessoireInitParams) !== null && _jsonElement$Accessoi2 !== void 0 && _jsonElement$Accessoi2.RelatedToBasketID && !this.set.getSetState.onlyRunLogic)) {
                _context5.next = 17;
                break;
              }
              LOG.error(new DivaUtils.DivaError('Error initializing element nr ' + i + ' in the Standard Web Planner. PlanData V2', {
                code: 'WC_0012'
              }));
              return _context5.abrupt("continue", 35);
            case 17:
              elementID = parseInt(jsonElement.elementID);
              plannerElement = new index.PlannerElementData(this.set.getSetId(), jsonElement.basketID, elementID, DivaStandardPlanner.plannerType);
              this.nextElementId = elementID + 1;
              this.plannerElements.set(plannerElement.ElementId, plannerElement);
              this.set.setElementId(jsonElement.basketID, plannerElement.ElementId);
              data = this.set.getPlannerData(plannerElement.ElementId);
              plannerElement.updatePlannerData(data);
              if (this.doDisablePlanner2D) {
                _context5.next = 27;
                break;
              }
              _context5.next = 27;
              return PlannerHandler2D.handler2D.loadSVG(plannerElement, this.set);
            case 27:
              //Im neuen speichern ist die Position hinten link - nicht mehr im Centrum wie im alten Planer
              //plannerElement.WorldPosCenter = new Vector3(jsonElement.x, jsonElement.y, jsonElement.z);
              plannerElement.WorldPosCenter = new index.Vector3(this.plannerBoundingBox.WorldPos.x + jsonElement.x, this.plannerBoundingBox.WorldPos.y + jsonElement.y, this.plannerBoundingBox.WorldPos.z + jsonElement.z);
              plannerElement.RotDeg = jsonElement.rot;
              if (plannerElement.IsDockedAccessoire) {
                accElements.push(jsonElement);
                plannerElement.PosNr = jsonElement.posNr;
                plannerElement.AccessoirePosNr = jsonElement.accNr;
              } else {
                elementsSortedbyPosNr[jsonElement.posNr - 1] = jsonElement;
                plannerElement.PosNr = jsonElement.posNr;
              }
              _context5.next = 35;
              break;
            case 32:
              _context5.prev = 32;
              _context5.t0 = _context5["catch"](11);
              LOG.error(new DivaUtils.DivaError('Error initializing element nr ' + i + ' in the Standard Web Planner. PlanData V2', {
                cause: _context5.t0,
                code: 'WC_0012'
              }));
            case 35:
              i++;
              _context5.next = 10;
              break;
            case 38:
              onlyOneBaseElement = elementsSortedbyPosNr.length == 1; //Saves if only one base element is in the planning. All the others are only accessoires
              elementsSortedbyPosNr = elementsSortedbyPosNr.concat(accElements);
              i = 0;
            case 41:
              if (!(i < elementsSortedbyPosNr.length)) {
                _context5.next = 59;
                break;
              }
              _context5.prev = 42;
              if (!(i == 0 && onlyOneBaseElement && this.plannerHasStaticBackground)) {
                _context5.next = 47;
                break;
              }
              //if the planner has a static background room and there is only one base element (ignore docked ACCs) then it should be forced positioned in the center of the room
              element = this.plannerElements.get(elementsSortedbyPosNr[i].elementID);
              if (element) element.WorldPosCenter = new index.Vector3(0, element.Height / 2, element.Depth / 2);
              return _context5.abrupt("continue", 56);
            case 47:
              if (!(elementsSortedbyPosNr[i].DP == null || elementsSortedbyPosNr[i].DP.length == 0)) {
                _context5.next = 49;
                break;
              }
              return _context5.abrupt("continue", 56);
            case 49:
              DPsInfo = elementsSortedbyPosNr[i].DP;
              for (j = 0; j < DPsInfo.length; j++) {
                dpInfo = DPsInfo[j];
                if (dpInfo.id && dpInfo.id != '' && dpInfo.onID && dpInfo.onID != '' && dpInfo.onDPID && dpInfo.onDPID != '') {
                  sourceElement = this.plannerElements.get(elementsSortedbyPosNr[i].elementID);
                  sourceDP = sourceElement === null || sourceElement === void 0 ? void 0 : sourceElement.getDockingPointById(dpInfo.id);
                  targetElement = this.plannerElements.get(dpInfo.onID);
                  targetDP = targetElement === null || targetElement === void 0 ? void 0 : targetElement.getDockingPointById(dpInfo.onDPID);
                  if (sourceDP && targetDP) {
                    PlannerHandler2D.dockingPointHandlerInst.tryDockElementDPToDP(sourceElement, targetElement, sourceDP, targetDP);
                  } else {
                    if (!this.doDisablePlanner2D) LOG.error(new DivaUtils.DivaError('Error initializing docking point between source element with id: ' + (sourceElement === null || sourceElement === void 0 ? void 0 : sourceElement.ElementId) + ' and target Element with id: ' + (targetElement === null || targetElement === void 0 ? void 0 : targetElement.ElementId) + '. SourceDPID: ' + dpInfo.id + '; targetDPID: ' + dpInfo.onDPID));
                  }
                }
              }
              _context5.next = 56;
              break;
            case 53:
              _context5.prev = 53;
              _context5.t1 = _context5["catch"](42);
              LOG.error(new DivaUtils.DivaError('Error initializing dockingPoints of element with elementID ' + elementsSortedbyPosNr[i].elementID, {
                cause: _context5.t1,
                code: 'WC_0012'
              }));
            case 56:
              i++;
              _context5.next = 41;
              break;
            case 59:
              _context5.next = 112;
              break;
            case 61:
              LOG.debug('Initialize set Plan Data - old V1\n' + planData, 'DivaStandardPlanner initPlanner');
              if (!(!planData.Sets || planData.Sets.length == 0 || !planData.Sets[0].Elements || planData.Sets[0].Elements.length == 0)) {
                _context5.next = 64;
                break;
              }
              return _context5.abrupt("return");
            case 64:
              //Init old Plannings - saved with the old planner
              _jsonElements = planData.Sets[0].Elements;
              _elementsSortedbyPosNr = [];
              _accElements = []; //Zuerst initialisiere alle Elemente
              //Dann positioniere sie richtig
              i = 0;
            case 68:
              if (!(i < _jsonElements.length)) {
                _context5.next = 102;
                break;
              }
              _context5.prev = 69;
              _jsonElement = _jsonElements[i];
              _catalogArticle = this.set.CatalogData.getCatalogArticleByArticleCodex(_jsonElement.articleCodex || _jsonElement.Codex);
              if (!(!_catalogArticle && (_jsonElement$Accessoi3 = _jsonElement.AccessoireInitParams) !== null && _jsonElement$Accessoi3 !== void 0 && _jsonElement$Accessoi3.RelatedToBasketID && !this.set.getSetState.onlyRunLogic)) {
                _context5.next = 75;
                break;
              }
              LOG.error(new DivaUtils.DivaError('Error initializing element nr ' + i + ' in the Standard Web Planner. PlanData V2', {
                code: 'WC_0012'
              }));
              return _context5.abrupt("continue", 99);
            case 75:
              basketID = _jsonElement.BasketID;
              if (this.set.getElementId(basketID) == -1) this.set.setElementId(basketID, Number(_jsonElement.ID));
              elementId = this.set.getElementId(basketID);
              _jsonElement.elementId = elementId;
              if (!(elementId == -1)) {
                _context5.next = 82;
                break;
              }
              LOG.error(new DivaUtils.DivaError('Error when initializing planner. The elementID Was not saved in the article. ', {
                code: 'WC_0012'
              }));
              return _context5.abrupt("continue", 99);
            case 82:
              _plannerElement = new index.PlannerElementData(this.set.getSetId(), basketID, elementId, DivaStandardPlanner.plannerType);
              this.nextElementId = elementId + 1;
              this.plannerElements.set(_plannerElement.ElementId, _plannerElement);
              _data = this.set.getPlannerData(_plannerElement.ElementId);
              _plannerElement.updatePlannerData(_data);
              if (this.doDisablePlanner2D) {
                _context5.next = 90;
                break;
              }
              _context5.next = 90;
              return PlannerHandler2D.handler2D.loadSVG(_plannerElement, this.set);
            case 90:
              //Achtung die Pos Infos im alten Planer waren Zentrumskoordinaten!!! Nicht hinten oben.
              centerWorldPos = new index.Vector3(_jsonElement.PosX, _jsonElement.PosZ, _jsonElement.PosY);
              _plannerElement.WorldPosCenter = new index.Vector3(this.plannerBoundingBox.WorldPos.x + centerWorldPos.x, this.plannerBoundingBox.WorldPos.y + centerWorldPos.y, this.plannerBoundingBox.WorldPos.z + centerWorldPos.z);
              _plannerElement.RotDeg = _jsonElement.Rot;
              if (_plannerElement.IsDockedAccessoire) {
                _accElements.push(_jsonElement);
                if (_jsonElement.PosNum.toString().indexOf('.') > 0) {
                  parentPosNr = _jsonElement.PosNum.toString().split('.')[0];
                  accPosNr = _jsonElement.PosNum.toString().split('.')[1];
                  _plannerElement.PosNr = parentPosNr;
                  _plannerElement.AccessoirePosNr = accPosNr;
                }
              } else {
                _elementsSortedbyPosNr[_jsonElement.PosNum - 1] = _jsonElement;
                _plannerElement.PosNr = _jsonElement.PosNum;
              }
              _context5.next = 99;
              break;
            case 96:
              _context5.prev = 96;
              _context5.t2 = _context5["catch"](69);
              LOG.error(new DivaUtils.DivaError('Error initializing element nr ' + i + ' in the Standard Web Planner - Plan Data old Planner', {
                cause: _context5.t2,
                code: 'WC_0012'
              }));
            case 99:
              i++;
              _context5.next = 68;
              break;
            case 102:
              _elementsSortedbyPosNr = _elementsSortedbyPosNr.concat(_accElements);
              //Dann werden die DockingPoints durchgegangen und die jeweils richtigen müssen gesucht werden.
              i = 0;
            case 104:
              if (!(i < _elementsSortedbyPosNr.length)) {
                _context5.next = 112;
                break;
              }
              if (!(_elementsSortedbyPosNr[i].DP == null || _elementsSortedbyPosNr[i].DP.length == 0)) {
                _context5.next = 107;
                break;
              }
              return _context5.abrupt("continue", 109);
            case 107:
              _DPsInfo = _elementsSortedbyPosNr[i].DP;
              for (j = 0; j < _DPsInfo.length; j++) {
                _dpInfo = _DPsInfo[j];
                if (_dpInfo.DP && _dpInfo.DP != '' && _dpInfo.onID && _dpInfo.onID != '') {
                  targetElementId = parseInt(_dpInfo.onID);
                  dpType = _dpInfo.DP;
                  curElement = this.plannerElements.get(_elementsSortedbyPosNr[i].elementId);
                  _targetElement = (_this$plannerElements = this.plannerElements.get(targetElementId)) !== null && _this$plannerElements !== void 0 ? _this$plannerElements : this.getPlannerElementByIndex(targetElementId - 1);
                  if (curElement && _targetElement) {
                    PlannerHandler2D.dockingPointHandlerInst.initDockingPointRelationByArea(curElement, _targetElement, dpType);
                  } else {
                    LOG.error(new DivaUtils.DivaError('Error initializing dockingPoints of element with elementID ' + _elementsSortedbyPosNr[i].elementId, {
                      code: 'WC_0012'
                    }));
                  }
                }
              }
            case 109:
              i++;
              _context5.next = 104;
              break;
            case 112:
              this.updateAllElementsWorldPos();
              this.updatePlannerPosNr();
            case 114:
            case "end":
              return _context5.stop();
          }
        }, _callee5, this, [[11, 32], [42, 53], [69, 96]]);
      }));
      function initPlanner(_x9) {
        return _initPlanner.apply(this, arguments);
      }
      return initPlanner;
    }()
  }, {
    key: "getPlannerElementByIndex",
    value: function getPlannerElementByIndex(index) {
      var ele = undefined;
      var count = 0;
      this.plannerElements.forEach(function (e, i) {
        if (index == count) ele = e;
        count++;
      });
      return ele;
    }
  }, {
    key: "addPlannerElement",
    value: function () {
      var _addPlannerElement = _asyncToGenerator__default["default"](/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee6(basketID, params) {
        var _params$dockingPointI, _t$, _t$2, _t$3;
        var plannerElement, data, t;
        return _regeneratorRuntime__default["default"].wrap(function _callee6$(_context6) {
          while (1) switch (_context6.prev = _context6.next) {
            case 0:
              // _elementId: number, _setId: string, _basketId: string, elementInitProp: any, catalogElement: CatalogPlannerArticleData
              plannerElement = new index.PlannerElementData(this.set.getSetId(), basketID, this.nextElementId, DivaStandardPlanner.plannerType /*, this.set.getSetId(), basketID, elementInitProp, catalogElement*/);
              this.nextElementId++;
              this.plannerElements.set(plannerElement.ElementId, plannerElement);
              this.set.setElementId(basketID, plannerElement.ElementId);
              data = this.set.getPlannerData(plannerElement.ElementId);
              plannerElement.updatePlannerData(data);
              //Do load the svg
              if (this.doDisablePlanner2D) {
                _context6.next = 9;
                break;
              }
              _context6.next = 9;
              return PlannerHandler2D.handler2D.loadSVG(plannerElement, this.set);
            case 9:
              t = (_params$dockingPointI = params.dockingPointInfos) !== null && _params$dockingPointI !== void 0 ? _params$dockingPointI : [{
                targetDockingPointId: params.targetDockingPointId,
                targetElemIdToDock: params.targetElemIdToDock
              }];
              if (!(t !== null && t !== void 0 && (_t$ = t[0]) !== null && _t$ !== void 0 && _t$.targetElemIdToDock && t !== null && t !== void 0 && (_t$2 = t[0]) !== null && _t$2 !== void 0 && _t$2.targetDockingPointId)) {
                _context6.next = 15;
                break;
              }
              _context6.next = 13;
              return this.addElementToWorld(plannerElement, t);
            case 13:
              _context6.next = 27;
              break;
            case 15:
              if (!(t !== null && t !== void 0 && (_t$3 = t[0]) !== null && _t$3 !== void 0 && _t$3.targetElemIdToDock)) {
                _context6.next = 20;
                break;
              }
              _context6.next = 18;
              return this.addElementToWorld(plannerElement, t);
            case 18:
              _context6.next = 27;
              break;
            case 20:
              if (!params.oldPlannerTransform) {
                _context6.next = 25;
                break;
              }
              _context6.next = 23;
              return this.addElementToWorld(plannerElement, undefined, undefined, undefined, undefined, {
                forceSetToTrans: true,
                transform: params.oldPlannerTransform
              });
            case 23:
              _context6.next = 27;
              break;
            case 25:
              _context6.next = 27;
              return this.addElementToWorld(plannerElement);
            case 27:
              this.updatePlannerBoundingBox();
            case 28:
            case "end":
              return _context6.stop();
          }
        }, _callee6, this);
      }));
      function addPlannerElement(_x10, _x11) {
        return _addPlannerElement.apply(this, arguments);
      }
      return addPlannerElement;
    }()
  }, {
    key: "movePlannerElement",
    value: function movePlannerElement() {
      throw Error('move planner not implemented in standard');
    }

    /**
     * Handles copyying the planner Element. it can happen that also other planner elements are influenced
     * @param articleCopyRelation Holds the relation - which element with elementID is copyed and has a new Article. ElementToCopyID -> BasketID of new Article
     * @param params
     */
  }, {
    key: "copyPlannerElement",
    value: (function () {
      var _copyPlannerElement = _asyncToGenerator__default["default"](/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee7(articleCopyRelation, copyInfo) {
        var articlesToLoad, i;
        return _regeneratorRuntime__default["default"].wrap(function _callee7$(_context7) {
          while (1) switch (_context7.prev = _context7.next) {
            case 0:
              articlesToLoad = [];
              articleCopyRelation.forEach(function (rel) {
                if (copyInfo == undefined) articlesToLoad.push(rel.value);
              });
              i = 0;
            case 3:
              if (!(i < articlesToLoad.length)) {
                _context7.next = 9;
                break;
              }
              _context7.next = 6;
              return this.addPlannerElement(articlesToLoad[i], {});
            case 6:
              i++;
              _context7.next = 3;
              break;
            case 9:
            case "end":
              return _context7.stop();
          }
        }, _callee7, this);
      }));
      function copyPlannerElement(_x12, _x13) {
        return _copyPlannerElement.apply(this, arguments);
      }
      return copyPlannerElement;
    }()
    /**
     * This function returns all Planner Elements that are influenced when deletingan element ID.
     * Forthe standard planner it is nothing.
     * @param elementId
     */
    )
  }, {
    key: "getPlannerElementsInfluencedByDeletion",
    value: function getPlannerElementsInfluencedByDeletion(elementId, deletionType) {
      return [];
    }
  }, {
    key: "getPlannerElementsInfluencedByCopy",
    value: function getPlannerElementsInfluencedByCopy(elementId, copyInfo) {
      if (!copyInfo || copyInfo.copyType != 'BoxPlanner_backside') throw new Error('copyType needs to be BoxPlanner_backside here');
      if (this.plannerElements.has(elementId)) return [elementId];
      return [];
    }
    /**
     * deletes a planner element
     * @param elementId     The elementId of the plannerelement.
     * @param autoCorrectAVL_AVR    If true the dockingpoints of the neighbor elements are tried to dock together. if a zwischenelement is deleted, the parents match again
     * @returns Returns the element id of the element that should be selected next
     */
  }, {
    key: "deletePlannerElement",
    value: (function () {
      var _deletePlannerElement = _asyncToGenerator__default["default"](/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee8(elementId, autoCorrectAVL_AVR) {
        var plannerElement, parent, prevPosNum, nextPosNum, newSelElemIdPrev, newSelElemIdNext, endForEach, removeDockingRelation, avlVec, avrVec, elementLeft, elementRight, avrElementLeft, avlElementRight, transform;
        return _regeneratorRuntime__default["default"].wrap(function _callee8$(_context8) {
          while (1) switch (_context8.prev = _context8.next) {
            case 0:
              _context8.next = 2;
              return DivaUtils__default["default"].Sleep(1);
            case 2:
              if (this.plannerElements.has(elementId)) {
                _context8.next = 4;
                break;
              }
              return _context8.abrupt("return", {});
            case 4:
              plannerElement = this.plannerElements.get(elementId);
              parent = this.getParentElement(plannerElement);
              prevPosNum = -1;
              nextPosNum = 999;
              newSelElemIdPrev = -1;
              newSelElemIdNext = -1; //Compute the element with the preview posNum for new element selection
              endForEach = false;
              this.plannerElements.forEach(function (value, key) {
                if (!endForEach) {
                  if (plannerElement !== null && plannerElement !== void 0 && plannerElement.IsAccessoire && plannerElement.PosNr == value.PosNr) {
                    newSelElemIdPrev = value.getElementId();
                    endForEach = true;
                  }
                  if (value.getPosNr() < plannerElement.getPosNr() && value.getPosNr() > prevPosNum) {
                    prevPosNum = value.getPosNr();
                    newSelElemIdPrev = value.getElementId();
                  } else if (value.getPosNr() > plannerElement.getPosNr() && value.getPosNr() < nextPosNum) {
                    nextPosNum = value.getPosNr();
                    newSelElemIdNext = value.getElementId();
                  }
                }
              });
              removeDockingRelation = false;
              if (autoCorrectAVL_AVR) {
                avlVec = plannerElement.getDockingDockingPointsByType('AVL');
                avrVec = plannerElement.getDockingDockingPointsByType('AVR');
                if (avlVec.length > 0 && avrVec.length > 0) {
                  elementLeft = this.plannerElements.get(avlVec[0].OnElementId);
                  elementRight = this.plannerElements.get(avrVec[0].OnElementId);
                  if (elementLeft && elementRight) {
                    avrElementLeft = elementLeft.getDockingDockingPointsByType('AVR');
                    avlElementRight = elementRight.getDockingDockingPointsByType('AVL');
                    if (avrElementLeft.length > 0 && avlElementRight.length > 0) {
                      //Now try dock left to right
                      PlannerHandler2D.dockingPointHandlerInst.removeDockingPointRelations(plannerElement);
                      removeDockingRelation = true;
                      PlannerHandler2D.dockingPointHandlerInst.tryDockElementDPToDP(elementLeft, elementRight, avrElementLeft[0], avlElementRight[0]);
                    }
                  }
                }
              }
              transform = {
                rotDeg: plannerElement.getRotDeg(),
                worldPosCenter: plannerElement.WorldPosCenter
              };
              if (!removeDockingRelation) {
                PlannerHandler2D.dockingPointHandlerInst.removeDockingPointRelations(plannerElement);
              }
              this.plannerElements["delete"](elementId);
              this.tryToDockForNotDockedAccessoire(parent);
              this.updatePlannerPosNr();
              this.updateAllElementsWorldPos();
              this.updatePlannerPosNr();
              this.checkCollision(false, plannerElement.getElementId());
              this.updatePlannerBoundingBox();
              return _context8.abrupt("return", {
                newElementToSelect: newSelElemIdPrev >= 0 ? newSelElemIdPrev : newSelElemIdNext >= 0 ? newSelElemIdNext : undefined,
                transform: transform
              });
            case 24:
            case "end":
              return _context8.stop();
          }
        }, _callee8, this);
      }));
      function deletePlannerElement(_x14, _x15) {
        return _deletePlannerElement.apply(this, arguments);
      }
      return deletePlannerElement;
    }()
    /**
     * This functions tries to dock not docked accessories when another accessoire got deleted. Now check if a dockingpoint got freed
     * @param parent
     * @returns
     */
    )
  }, {
    key: "tryToDockForNotDockedAccessoire",
    value: function tryToDockForNotDockedAccessoire(parent) {
      if (!parent) return;
      var notDockedAccessoires = parent.getCurrentAccessorires().filter(function (accessoire) {
        return accessoire.getIsNotDockedAccessoire();
      });
      for (var i = 0; i < notDockedAccessoires.length; i++) {
        var elementId = notDockedAccessoires[i].getElementId();
        var element = this.plannerElements.get(elementId);
        if (!element) continue;
        var success = this.dockToAVUorAVOororAVNorAVSorAVC(element, [parent]);
        if (success) break;
      }
    }

    /**
     *  This function calculates if any element collides with another element. It returns one or more collision pairs.
     * The result of the function is saved in the collisionHandler Variable.
     * Furthermore, this function informs the view if the collision has changed
     * @param calcCollisionPairs    If true, the collision with all elements is computed. If false - the algorithm stops when the first collision is detected
     * @param checkSingleElementId  If this parameter is set, the collision is only detected with this element
     */
  }, {
    key: "checkCollision",
    value: function checkCollision(calcCollisionPairs, checkSingleElementId) {
      if (this.doDisablePlanner2D) return;
      var allElements = this.getAllPlannerElements();
      var collisionDetected = false;
      var collisionPairs = [];
      for (var i = 0; i < allElements.length; i++) {
        var element1 = allElements[i];
        if (!checkSingleElementId || element1.getElementId() == checkSingleElementId) {
          var initialIndex = checkSingleElementId ? 0 : i + 1;
          for (var j = initialIndex; j < allElements.length; j++) {
            var _this$set$CatalogData, _this$set$CatalogData2;
            var element2 = allElements[j];
            if (element1.getElementId() == element2.getElementId()) continue;
            if (PlannerHandler2D.dockingPointHandlerInst.checkElementsAreDocking(element1, element2)) continue;
            var collision = false;
            if (this.set.CatalogData.doCheckConstructionWarnings || (_this$set$CatalogData = this.set.CatalogData.forceConstructionWarningForArticles) !== null && _this$set$CatalogData !== void 0 && _this$set$CatalogData.includes(element1.ArticleCodex) || (_this$set$CatalogData2 = this.set.CatalogData.forceConstructionWarningForArticles) !== null && _this$set$CatalogData2 !== void 0 && _this$set$CatalogData2.includes(element2.ArticleCodex)) {
              collision = PlannerHandler2D.handler2D.checkCollision(element1, element2, this.set.CatalogData.checkCollisionForDifferentLayers);
            }
            if (collision) {
              collisionDetected = true;
              collisionPairs.push({
                elementId1: element1.getElementId(),
                elementId2: element2.getElementId()
              });
              LOG.debug('Collision Found between element1: ' + element1.ElementId + '; and element2: ' + element2.ElementId);
              if (!calcCollisionPairs) break;
            }
          }
        }
      }
      if (this.collisionHandler.collisionDetected && !collisionDetected) {
        var _this$collisionHandle, _this$collisionHandle2;
        //Collision has changed
        (_this$collisionHandle = (_this$collisionHandle2 = this.collisionHandler).updatePlannerMsgContainer) === null || _this$collisionHandle === void 0 || _this$collisionHandle.call(_this$collisionHandle2, 'COLLISION_MSG', false, 'WARNING', 'COLLISION_MSG', false);
      } else if (!this.collisionHandler.collisionDetected && collisionDetected) {
        var _this$collisionHandle3, _this$collisionHandle4;
        (_this$collisionHandle3 = (_this$collisionHandle4 = this.collisionHandler).updatePlannerMsgContainer) === null || _this$collisionHandle3 === void 0 || _this$collisionHandle3.call(_this$collisionHandle4, 'COLLISION_MSG', true, 'WARNING', 'COLLISION_MSG', false /*this.collisionHandler.collisionPairs*/);
      }
      this.collisionHandler.collisionPairs = collisionPairs;
      this.collisionHandler.collisionDetected = collisionDetected;
    }

    /**
     * Updates the overall set posNr
     * @param startSetPosNr   Indicates the start PosNr for the planner
     * @returns The count of elements in this planner. Used to calculate the startSetPosNr for the next Planner
     */
  }, {
    key: "updateSetPosNr",
    value: function updateSetPosNr(startSetPosNr) {
      var elements = this.getAllPlannerElements();
      for (var i = 0; i < elements.length; i++) {
        var element = elements[i];
        element.SetPosNr = startSetPosNr + element.PosNr - 1;
        this.set.setPosNr(element.ElementId, element.getPosNr());
      }
      for (var _i3 = 0; _i3 < elements.length; _i3++) {
        if (!elements[_i3].IsAccessoire) this.set.giveAccNewPosNrByBasketId(elements[_i3].getBasketId());
      }
      return elements.length;
    }

    /**
     * This function is called every time the transformation of a planner Element is changed in the view. For example when the user moves the 2D Shape around.
     * When it is the first action, all AVL and AVR docking Points are removed. When it is the last action "END" then the planner is updated an dockable docking points are searched.
     *
     * @param elementId
     * @param deltaMove
     * @param deltaAngleDeg
     * @param transState
     * @param autoDockingDistance    //Gibt an in welchem Radius automatisch gedockt werden muss
     */
  }, {
    key: "updatePlannerTrans",
    value: function updatePlannerTrans(elementId, deltaMove, deltaAngleDeg, rotCorrection, transState, autoDockingDistance) {
      var _this3 = this;
      var updateConfig = false;
      if (this.plannerElements.has(elementId)) {
        var plannerElement = this.plannerElements.get(elementId);
        plannerElement === null || plannerElement === void 0 || plannerElement.updateDeltaTrans(deltaMove, deltaAngleDeg, rotCorrection, transState == 'END');
        if (transState == 'START') {
          if (plannerElement) {
            var dpsToUndock = ['AVR', 'AVL'];
            if (plannerElement.IsDockedAccessoire) dpsToUndock = dpsToUndock.concat(['AVO', 'AVU', 'AVN', 'AVS', 'AVC']);
            var undockedElements = PlannerHandler2D.dockingPointHandlerInst.removeDockingPointRelationsByType(plannerElement, dpsToUndock);
            for (var i = 0; i < undockedElements.length; i++) {
              updateConfig = this.set.onDockingChanged(plannerElement.ElementId, undockedElements[i], 'UNDOCK');
            }
          }
        } else if (transState == 'END') {
          var dockablePairs = PlannerHandler2D.dockingPointHandlerInst.searchDockableElementsInArea(plannerElement, this.getAllPlannerElements(), autoDockingDistance); //hier kann jetzt ein DP drinnen stehen - docke alle
          if (dockablePairs != null && dockablePairs.size > 0) {
            dockablePairs.forEach(function (dockPair, type) {
              var targetPlannerElement = _this3.plannerElements.get(dockPair.targetDP.ElementId);
              if (targetPlannerElement) {
                PlannerHandler2D.dockingPointHandlerInst.tryDockElementDPToDP(plannerElement, targetPlannerElement, dockPair.sourceDP, dockPair.targetDP);
              }
            });
          }
          updateConfig = this.updateAllElementsWorldPos(elementId);
          this.updatePlannerPosNr();
          this.updatePlannerBoundingBox();
        }
      }
      return updateConfig;
    }

    /**
     * Destroy all plannerinformation
     */
  }, {
    key: "destroyPlanner",
    value: function destroyPlanner() {
      this.plannerElements.forEach(function (elem, elemId) {
        elem.destroy();
      });
      this.plannerElements.clear();
    }

    /*
      This function returns the current Planning (it is one set)
      */
  }, {
    key: "saveSetPlanner",
    value: function saveSetPlanner() {
      var _this4 = this;
      if (this.plannerElements.size == 0) return null;
      var plannerElements = [];
      this.plannerElements.forEach(function (elem, elemId) {
        var dockingDPs = elem.getDockingDockingPoints();
        var dpArr = [];
        for (var i = 0; i < dockingDPs.length; i++) {
          var _dockingDPs$i$OnDP;
          var saveDP = {
            id: dockingDPs[i].DpId,
            onID: dockingDPs[i].OnElementId,
            onDPID: (_dockingDPs$i$OnDP = dockingDPs[i].OnDP) === null || _dockingDPs$i$OnDP === void 0 ? void 0 : _dockingDPs$i$OnDP.DpId
          };
          dpArr.push(saveDP);
        }
        var plannerElement = {
          elementID: elem.getElementId(),
          basketID: _this4.set.getBasketId(elem.getElementId()),
          CatalogCodex: _this4.set.getCatalogCodex(),
          Codex: _this4.set.getArticleCodex(elem.getElementId()),
          posNr: elem.PosNr,
          accNr: elem.IsDockedAccessoire ? elem.AccessoirePosNr : undefined,
          x: elem.WorldPosCenter.x,
          y: elem.WorldPosCenter.y,
          z: elem.WorldPosCenter.z,
          rot: elem.RotDeg,
          width: elem.Width ? elem.Width : -1,
          height: elem.Height ? elem.Height : -1,
          depth: elem.Depth ? elem.Depth : -1,
          DP: dpArr
        };
        if (elem.IsAccessoire) {
          var parentBasketId = _this4.set.getParentBasketIdOfElementId(elem.getElementId());
          if (parentBasketId != undefined) {
            plannerElement.AccessoireInitParams = {
              RelatedToBasketID: parentBasketId
            };
          }
        }
        plannerElements.push(plannerElement);
      });
      var saveSet = {
        setId: this.set.getSetId(),
        x: 0,
        y: 0,
        z: 0,
        width: this.plannerBoundingBox.Size.x,
        height: this.plannerBoundingBox.Size.y,
        depth: this.plannerBoundingBox.Size.z,
        rot: 0,
        elements: plannerElements
      };
      return saveSet;
    }
  }, {
    key: "getPlannerId",
    value: function getPlannerId() {
      return this.plannerID;
    }

    /*
      This function returns all informations that are needed to visualize the set in 3D
      */
  }, {
    key: "getSetData",
    value: function getSetData(only3DCompatible, useSetPlanner, doShow3DDimensionLines, alternateRenderInfo) {
      var _this5 = this;
      var setId = useSetPlanner ? this.set.getSetId() : 'S1';
      var setData = {
        //ID: "S" + this.plannerID,
        ID: setId,
        H: '',
        x: 0,
        y: 0,
        z: 0,
        w: 0,
        ELE: [],
        Blob: this.set.CatalogData.supplierILN,
        Cat: this.set.getCatalogCodex()
      };
      var allAlternateRenderings = this.set.getAlternateRenderInfo();
      if (allAlternateRenderings) {
        setData.AlternateImg = allAlternateRenderings;
      }
      if (doShow3DDimensionLines) {
        setData.ShowDim = doShow3DDimensionLines;
      }
      if (this.isIDM3DCat) {
        setData.IsIDM3D = true;
        setData.IDM3DCatCodex = this.IDM3DCatCodex;
      }
      this.plannerElements.forEach(function (elem, elemId) {
        var config = _this5.set.getPlannerConfigData(elemId, alternateRenderInfo);
        var elemCfg = config.config;
        var accElements = [];
        if (config.accs && config.accs.length > 0) {
          for (var i = 0; i < config.accs.length; i++) {
            if (_this5.plannerElements.has(config.accs[i])) {
              accElements.push('E' + config.accs[i]);
            }
          }
        }
        if (!only3DCompatible || elemCfg.Model != undefined) {
          var _elemCfg$MOVE;
          var article = _this5.set.getArticleByElementId(elemId);
          var elemJson = {
            ID: 'E' + elemId,
            // N: elemCfg.N,
            Model: elemCfg.Model,
            x: -Math.round(elem.WorldPosCenterIgnoreOLF.x * 100) / 100,
            y: Math.round(elem.WorldPosCenterIgnoreOLF.y * 100) / 100,
            z: Math.round(elem.WorldPosCenterIgnoreOLF.z * 100) / 100,
            PosPivot: 'Center',
            w: Math.round(elem.getRotDeg() * 100) / 100,
            RotPivot: 'Center',
            DP: elem.getDockingPointJS3D(),
            MAT: elemCfg.MAT,
            MOVE: (_elemCfg$MOVE = elemCfg.MOVE) !== null && _elemCfg$MOVE !== void 0 ? _elemCfg$MOVE : undefined,
            CFG: elemCfg.CFG,
            H: '',
            ACCs: accElements.length > 0 ? accElements : undefined
          };
          if (doShow3DDimensionLines) {
            var _article$width, _article$height, _article$depth;
            elemJson.TechSize = {
              Width: elem.Width != undefined && !isNaN(elem.Width) ? elem.Width : (_article$width = article === null || article === void 0 ? void 0 : article.width) !== null && _article$width !== void 0 ? _article$width : 0,
              Height: elem.Height != undefined && !isNaN(elem.Height) ? elem.Height : (_article$height = article === null || article === void 0 ? void 0 : article.height) !== null && _article$height !== void 0 ? _article$height : 0,
              Depth: elem.Depth != undefined && !isNaN(elem.Depth) ? elem.Depth : (_article$depth = article === null || article === void 0 ? void 0 : article.depth) !== null && _article$depth !== void 0 ? _article$depth : 0
            };
          }
          var hash = DivaUtils.md5(JSON.stringify(elemJson));
          elemJson.H = hash;
          setData.ELE.push(elemJson);
        }
        var shelfPlannerElements = _this5.set.getShelfPlannerData(elemId);
        if (shelfPlannerElements) {
          for (var _i4 = 0; _i4 < shelfPlannerElements.length; _i4++) {
            var accessorire = shelfPlannerElements[_i4];
            var shelfConfig = _this5.set.getShelfPlannerConfigData(accessorire.basketId).config;
            var _accElements2 = [];
            if (shelfConfig.accs && shelfConfig.accs.length > 0) {
              for (var j = 0; j < shelfConfig.accs.length; j++) {
                if (_this5.plannerElements.has(shelfConfig.accs[j])) {
                  _accElements2.push('E' + shelfConfig.accs[j]);
                }
              }
            }
            var shelfJson = {
              ID: 'E' + accessorire.parentElementId + '.' + accessorire.gridId + '.' + accessorire.rh,
              H: '',
              Model: accessorire.model,
              x: 0,
              y: 0,
              z: 1,
              w: 0,
              PosPivot: 'Center',
              RotPivot: 'Center',
              DP: 'RH' + accessorire.rh + ':' + 'E' + accessorire.parentElementId,
              GN: accessorire.gridName,
              MAT: shelfConfig.MAT,
              CFG: shelfConfig.CFG,
              ACCs: _accElements2.length > 0 ? _accElements2 : undefined
            };
            var hash = DivaUtils.md5(JSON.stringify(shelfJson));
            shelfJson.H = hash;
            setData.ELE.push(shelfJson);
          }
        }
      });
      var hash = DivaUtils.md5(JSON.stringify(setData));
      setData.H = hash;
      return {
        constructionSet: setData
      };
    }

    /**
     * This function returns the position information for each element. The infomration is returned as an object with elementId: posNr.
     */
  }, {
    key: "getElementPosInfo",
    value: function getElementPosInfo() {
      var ret = {};
      this.plannerElements.forEach(function (value, key) {
        if (value.IsDockedAccessoire) {
          ret[key] = {
            pos: value.PosNr,
            isAcc: true,
            accPos: value.AccessoirePosNr
          };
        } else {
          ret[key] = {
            pos: value.PosNr,
            isAcc: false
          };
        }
      });
      return ret;
    }
    /**
     * Returns true if all AVL and AVR Filter are set. Specifies if a planning is complete
     */
  }, {
    key: "getPlanningIsComplete",
    value: function getPlanningIsComplete(forceCheck) {
      var _this6 = this;
      var dontCheck = !forceCheck && (this.set.CatalogData.doHideCompletenessWarning || !this.set.CatalogData.doCheckConstructionWarnings);
      var elemNotComplete = false;
      this.plannerElements.forEach(function (plannerElement, key) {
        var _this6$set$CatalogDat;
        if (dontCheck && !((_this6$set$CatalogDat = _this6.set.CatalogData.forceConstructionWarningForArticles) !== null && _this6$set$CatalogDat !== void 0 && _this6$set$CatalogDat.includes(plannerElement.ArticleCodex))) return;
        if (!elemNotComplete && (plannerElement.getFreeDockingPointsByType('AVL').length > 0 || plannerElement.getFreeDockingPointsByType('AVR').length > 0)) {
          elemNotComplete = true;
        }
      });
      return !elemNotComplete;
    }
  }, {
    key: "getPlannerBoundingBox",
    value: function getPlannerBoundingBox() {
      var catalog = this.set.CatalogData;
      var width = this.plannerBoundingBox.getWidth(catalog.PlannerMeasureDigits);
      var depth = this.plannerBoundingBox.getDepth(catalog.PlannerMeasureDigits);
      var height = this.plannerBoundingBox.getHeight(catalog.PlannerMeasureDigits);
      var widthIgnoreOLF = this.plannerBoundingBox.getWidth(catalog.PlannerMeasureDigits, true);
      var depthIgnoreOLF = this.plannerBoundingBox.getDepth(catalog.PlannerMeasureDigits, true);
      var heightIgnoreOLF = this.plannerBoundingBox.getHeight(catalog.PlannerMeasureDigits, true);
      var olfDefined = widthIgnoreOLF !== width || depthIgnoreOLF !== depth || heightIgnoreOLF !== height;
      return {
        width: width,
        height: height,
        depth: depth,
        widthIgnoreOLF: olfDefined ? widthIgnoreOLF : undefined,
        depthIgnoreOLF: olfDefined ? depthIgnoreOLF : undefined,
        heightIgnoreOLF: olfDefined ? heightIgnoreOLF : undefined
      };
    }
  }, {
    key: "updatePlannerBoundingBox",
    value: function updatePlannerBoundingBox() {
      this.plannerBoundingBox.calcPlannerBoundingBox(this.getAllPlannerElements());
      this.plannerBoundingBox.calcPlannerBoundingBoxIgnoreOLF(this.getAllPlannerElements());
    }
  }, {
    key: "getCatalogData",
    value: function getCatalogData() {
      return this.set.CatalogData;
    }
  }, {
    key: "getAllPlannerElements",
    value: function getAllPlannerElements() {
      var plannerElements = [];
      this.plannerElements.forEach(function (value, key) {
        plannerElements.push(value);
      });
      return plannerElements;
    }
  }, {
    key: "getParentElement",
    value: function getParentElement(curPlannerElement) {
      var parent = undefined;
      var parentElementId = curPlannerElement.getParentElementId();
      if (parentElementId) {
        parent = this.plannerElements.get(parentElementId);
      }
      return parent;
    }

    /***Debug tools  */
  }, {
    key: "getPositionOfPlannerElements",
    value: function getPositionOfPlannerElements() {
      var setid = this.set.getSetId();
      this.plannerElements.forEach(function (value, key) {
        LOG.log('SetID:', setid);
        LOG.log('Elementid:', value.ElementId);
        LOG.log('X:', value.WorldPosCenter.x);
        LOG.log('Y:', value.WorldPosCenter.y);
        LOG.log('X:', value.WorldPosCenter.z);
        LOG.log('ROT:', value.RotDeg);
        LOG.log('___________________________');
      });
    }
  }, {
    key: "clonePlanner",
    value: function clonePlanner(set, plannerId) {
      var clone = new DivaStandardPlanner(set, function () {}, plannerId, new index.BoundingBox(), true, false);
      return clone;
    }
  }, {
    key: "getPlannerInteractionInformation",
    value: function getPlannerInteractionInformation() {
      LOG.error(new DivaUtils.DivaError('The function getPlannerInteractionInformation is not implemented yet for standard planner. Dont call it or ask roadmap when its its turn', {
        code: 'WC_0012'
      }));
      return {
        boxPlannerInteractionInformationPerElement: new Map()
      };
    }
  }, {
    key: "getGeneralPlanningState",
    value: function getGeneralPlanningState(selectedElementId) {
      LOG.error(new DivaUtils.DivaError('The function getGeneralPlanningState is not implemented yet for standard planner. Dont call it or ask roadmap when its its turn', {
        code: 'WC_0012'
      }));
      return {
        grids: []
      };
    }
  }]);
}();
_defineProperty__default["default"](DivaStandardPlanner, "plannerType", 'STD');

exports["default"] = DivaStandardPlanner;
