1 line
475 KiB
JavaScript
1 line
475 KiB
JavaScript
function SVGRenderer(){this.svgRoot=null,this.svgPage=null,this.SVG_ROOT_ID="SVG_ROOT",this.SVG_PAGE_ID="SVG_PAGE",this.SVG_PAGE_GRID_ID="SVG_PAGE_GRID",this.TRACKER_COLOR="#63afda",this.BACKGROUND_ID="usrBackground",this.MULTIPLE_SELECTOR_TRACKER_ID="multiple-select-tracker",this.MULTIPLE_SELECTOR_DUMMY_ID="multiple-select-dummy",this.TRACKER_GROUP_ID="tracker-group",this.LINE_TRACKER_GROUP_ID="line-tracker",this.QUOTE_A="quoteA",this.QUOTE_B="quoteB",this.QUOTE_STACK=10,this.QUOTE_TYPE=0,this.QUOTE_DRIVING=!1,this.MAX_WIDTH=1e5,this.MAX_HEIGHT=1e5,this.COORD_X=1e3,this.COORD_Y=1e3,this.COORD_Z=1e3,this.LINE_DELIMITER="\n",this.lastSnapLineOrientation=null,this.shapeFolder="/shapes/svg/",this.propsFolder="/shapes/props/",this.svgNamespace="http://www.w3.org/2000/svg",this.xlinkNamespace="http://www.w3.org/1999/xlink",this.cachedObjects=new E2DCache,this.cachedProperties=new E2DCache,this.snapLine=null,this.polyQuote=null,this.isSnapLineShowing=!1,this.isPolyQuoteShowing=!1,this.textDataHash=[],this.zoom=1,this.enableFloor=!1,this.floorDefinition=null}function E2DEditor(e,t){this.container=e,this.SURROUND_ID="E2DSurround",this.ORIGIN_ID="origin",this.CUSTOM_ORIGIN_ID="customOrigin",this.CONNECTION_POINT_CLASS="connectionPoint",this.unit="mm",this.language="en",this.numberOfDecimal=2,this.width="420mm",this.height="297mm",this.DEFAULT_PAGE_WIDTH="420mm",this.DEFAULT_PAGE_HEIGHT="297mm",this.DPI=96,this.conversionFactor=1/this.DPI*25.4,this.scale=1,this.orientation="LANDSCAPE",this.showGrid=!0,this.GRID_ROTATE=5,this.GRID_SIZE_IN=24,this.GRID_SIZE_MM=this.DPI/25.4*5,this.GRID_SIZE=this.GRID_SIZE_MM,this.zoom=1,this.zoomStep=.1,this.needRefresh=!1,this.prevRect={},this.prevMode="",this.mode="select",this.resizeMode="",this.selectConnectorMode=!1,this.selected=null,this.selectedBehaviour=null,this.includeConnectionPoints=!0,this.checkInclusions=!0,this.checkCollisions=!0,this.checkBackgroundCollisions=!0,this.checkQuotes=!0,this.persistentInclusions=!1,this.persistentCollisions=!1,this.activeBackground=!0,this.textEditMode=!1,this.textToolBeginNew=!0,this.groupInfo={},this.groupProp=null,this.groupPropID=null,this.collidingGhosts=[],this.externalGhosts=[],this.overlappingGhosts=[],this.origin={x:0,y:0,z:0,signX:1,signY:1,signZ:1,position:"tl",background:!1},this.customOrigin=null,this.quotesOff=!1,this.highlightEqualShapes=!1,this.connectorToolsEnabled=!0,this.drawToolsEnabled=!0,this.textToolsEnabled=!0,this.gridPatternToolsEnabled=!0,this.zIndexToolsEnabled=!0,this.showHelpEnabled=!0,this.showHelpPopupEnabled=!0,this.showActionsEnabled=!0,this.polyLinePropertiesEnabled=!0,this.quotePropertiesEnabled=!0,this.shapePropertiesEnabled=!0,this.quoteUOMEnabled=!0,this.snapToObject=!1,this.snapToPolyline=!1,this.snapToShapeCenter=!1,this.snapToThreshold=this.GRID_SIZE,this.clearCacheCount=0,this.connectionPointToolsEnabled=!1,this.zoomFit=!1,this.quickPickIgnoreThreshold=0,this.enterBehaviour="close",this.polyLineProps={table:"polyLineProperties",units:$("#_dpUnits"),length:$("#_dpLength"),rotation:$("#_dpRotation")},this.quoteProps={table:"quoteProperties",units:$("#_qUnits"),value:$("#_qValue"),type:$("#_qType"),driving:$("#_qDriving")},this.shapeProps={table:"shapeProperties",name:$("#_shapeName"),units:$("#_shapeUnits"),image:$("#_shapeImage"),x:$("#_x"),y:$("#_y"),z:$("#_z"),width:$("#_width"),height:$("#_height"),depth:$("#_depth"),rotation:$("#_rotation"),layer:$("#_layer"),pin:$("#_pinShape")},this.events={inserted:!1,pasted:!1,removed:!1,linked:!1,stretched:!1,rotated:!1,regrouped:!1,doubleclick:!1,polyinserted:!1,editconnectionpoints:!1},this.clipboard=null,this.iClipboard=null,this.selectedBounds={x:0,y:0,z:0,width:0,height:0,depth:0},this.multipleSelectShapes=new SelectedShapes(t),this.insertedShapes=new InsertedShapes,this.libraryCategories=[],this.libraryCategoriesTree=null,this.libraryClasses={},this.libraryLanguage={},this.libraryProperties={},this.libraryLayers={},this.shapeLibraryList=["DefaultLibrary"],this.shapeLibraryHideList=[],this.shapeLibraryOpenList=[],this.libraryLoaded=$.Deferred(),this.preferencesLoaded=$.Deferred(),this.viewportLoaded=$.Deferred(),this.shapesLoaded=$.Deferred(),this.onselect=E2DEvents.onSelect,this.onunselect=E2DEvents.onUnselect,this.enable3d=!1,this.enable3dDinamicLights=!1,this.enable3dGround=!0,this.enable3dViewStyle="TOP",this.enable3dFloor=!1,this.enable3dFloorDefinition={color:"#75673f",image:null,thickness:.5},this.enable3dWalls=!1,this.show3dWalls=!0,this.show3dShadows=!0,this.enable3dWallDimensions="3000|1",this.image2DExported=null,this.image3DExported=null,this.exportImage2D=!1,this.exportImage3D=!1,this.renderer=t,this.renderer.init(this.container[0]),this.renderer3d=null,this.undoManager=new E2DUndoManager,this.undoManager.init(10,this.updateUndoRedoButtons),this.attachEditorEvents()}function E2DCache(){var e={};return{get:function(t){return e[t]},contains:function(t){return t in e},remove:function(t){delete e[t]},set:function(t,i){e[t]=i},values:function(){return e},getSet:function(e,t){return this.contains(e)||this.set(e,"function"==typeof t?t():t),this.get(e)}}}function InsertedShape(){this.source=null,this.sourceLibrary=null,this.signature=null,this.id=null,this.group=null,this.name=null,this.family=null,this.description=null,this.layer=null,this.x=0,this.y=0,this.z=0,this.width=0,this.height=0,this.depth=0,this.rotation=0,this.text=null,this.behaviour=null,this.collisionClass=null,this.containerClass=null,this.eventClass=null,this.linkClass=null,this.snapClass=null,this.links=[],this.lineConnections={from:{shapeID:"",pointID:""},to:{shapeID:"",pointID:""}},this.shapeConnections=[],this.connectionPoints=null,this.path="",this.ctrl1x=-1,this.ctrl1y=-1,this.ctrl2x=-1,this.ctrl2y=-1,this.shapeFromId=null,this.shapeFromPointIndex=null,this.shapeToId=null,this.shapeToPointIndex=null,this.dimStack=10,this.dimType=0,this.dimDriving=!1,this.dimValue=0,this.color=null,this.colorOpacity=null,this.lineColor=null,this.lineWidth=null,this.lineOpacity=null,this.color3D=null,this.colorOpacity3D=null,this.lineColor3D=null,this.lineOpacity3D=null,this.image=null,this.imageSVG=null,this.pinned=!1,this.includeInBOM=!1,this.modified=!1,this.selected=!1,this.custom={},this.calculatedBehaviour=null,this.calculatedPinned=null}function InsertedShapes(){this.insertedShapeMap={},this.alwaysInBack={},this.alwaysInFront={},this.origin=null,this.customOrigin=null,E2DEventBus.addEventListener("shapeSelected",this.onShapeSelected,this),E2DEventBus.addEventListener("shapeMultiSelected",this.onShapeSelected,this)}function SelectedShapes(e){this.bbox={x:null,y:null,width:null,height:null,depth:null,right:null,bottom:null,ceiling:null},this.selectedShapeMap={},this.selectedShapeBounds={},this.renderer=e,this.idHighest=null,this.idLowest=null,this.idLowestZ=null,this.idHighestZ=null,this.prevSelected=null,this.firstSelectionGhostID=null}function E2DEventArgument(e,t,i,n,o,s){this.class=e,this.handler=t,this.connectionPointID=i,this.shapeID=n,this.group=o,this.options=s}SVGRenderer.prototype.init=function(e){this.container=e,this.svgRoot=this.createElement("svg"),this.svgRoot.setAttribute("xmlns",this.svgNamespace),this.svgRoot.setAttribute("xmlns:xlink",this.xlinkNamespace),this.svgRoot.setAttribute("xml:space","preserve"),this.svgRoot.id=this.SVG_ROOT_ID,this.svgRoot.style.position="absolute",this.svgRoot.style.zIndex=10,this.svgRoot.style.opacity="1.0",this.svgRoot.style.MozUserSelect="none",this.svgRoot.setAttributeNS(null,"x","0"),this.svgRoot.setAttributeNS(null,"y","0"),this.svgRoot.setAttributeNS(null,"width",this.MAX_WIDTH),this.svgRoot.setAttributeNS(null,"height",this.MAX_HEIGHT);var t=this.container.firstChild;this.container.insertBefore(this.svgRoot,t),this.addSVGRootDefinitions();var i=this.createElement("g");i.id=this.SVG_PAGE_ID,this.svgPage=this.createElement("rect"),this.svgPage.id=this.SVG_PAGE_GRID_ID,this.svgPage.setAttributeNS(null,"x","0"),this.svgPage.setAttributeNS(null,"y","0"),this.svgPage.setAttributeNS(null,"width","500"),this.svgPage.setAttributeNS(null,"height","500"),this.svgPage.setAttributeNS(null,"stroke-width","0"),this.svgPage.setAttributeNS(null,"fill","url(#gridin)"),i.appendChild(this.svgPage),this.svgRoot.appendChild(i)},SVGRenderer.prototype.initFloor=function(e,t){if(this.enableFloor=e,this.floorDefinition=t,e&&t){const e=this.svgRoot.getElementsByTagName("defs")[0],t=this.createFloorPattern();e.appendChild(t)}},SVGRenderer.prototype.dispose=function(){this.removeSystemShapes()},SVGRenderer.prototype.initSystemShapes=function(e){this.loadShape(e[0],"link-line",this),this.loadShape(e[0],"quote-line",this),this.loadShape(e[0],"snap-line",this).done(this.setSnapLine.bind(this)),this.loadShape(e[0],"poly-quote",this).done(this.setPolyQuote.bind(this)),this.loadShape(e[0],this.TRACKER_GROUP_ID,this).done(this.createTracker.bind(this)),this.loadShape(e[0],this.LINE_TRACKER_GROUP_ID,this).done(this.createLineTracker.bind(this)),this.loadShape(e[0],this.MULTIPLE_SELECTOR_TRACKER_ID,this).done(this.createMultipleSelector.bind(this)),this.loadShape(e[0],this.MULTIPLE_SELECTOR_DUMMY_ID,this).done(this.createMultipleSelectorDummyShape.bind(this))},SVGRenderer.prototype.hideSystemShapes=function(){this.hideTracker(),this.hideLineTracker(),this.showMultipleSelector(!1),this.showMultipleSelectorDummyShape(!1)},SVGRenderer.prototype.removeSystemShapes=function(){this.removeTracker(),this.removeLineTracker(),this.removeMultipleSelector(),this.removeMultipleSelectorDummyShape()},SVGRenderer.prototype.setSVGRootSize=function(e,t){this.svgRoot.setAttributeNS(null,"width",e),this.svgRoot.setAttributeNS(null,"height",t)},SVGRenderer.prototype.setSVGRootZoom=function(e){"number"==typeof e&&(this.zoom=e,1===e?(this.setSVGRootSize(this.MAX_WIDTH,this.MAX_HEIGHT),this.svgRoot.removeAttributeNS(null,"viewBox")):(this.setSVGRootSize(this.MAX_WIDTH*this.zoom,this.MAX_HEIGHT*this.zoom),this.svgRoot.setAttributeNS(null,"viewBox","0 0 "+this.MAX_WIDTH+" "+this.MAX_HEIGHT)))},SVGRenderer.prototype.getSVGPageSize=function(){return{width:this.svgPage.width.baseVal.value,height:this.svgPage.height.baseVal.value}},SVGRenderer.prototype.setSVGPageSize=function(e,t){this.svgPage.setAttributeNS(null,"width",e),this.svgPage.setAttributeNS(null,"height",t)},SVGRenderer.prototype.setSVGPageGrid=function(e){var t=e?"url(#grid"+e+")":"#ffffff";this.svgPage.setAttributeNS(null,"fill",t)},SVGRenderer.prototype.cloneSVGRoot=function(e,t,i){var n=this.svgRoot.cloneNode(!0),o=n.getElementById(this.SVG_PAGE_ID);return o&&n.removeChild(o),i||n.removeAttributeNS(null,"viewBox"),e&&n.setAttributeNS(null,"width",e),t&&n.setAttributeNS(null,"height",t),n},SVGRenderer.prototype.addSVGRootDefinitions=function(){var e=this.createElement("defs"),t=this.createElement("marker");t.setAttributeNS(null,"id","markerQuote"),t.setAttributeNS(null,"viewBox","0 0 1 10"),t.setAttributeNS(null,"refX",0),t.setAttributeNS(null,"refY",5),t.setAttributeNS(null,"markerWidth",5),t.setAttributeNS(null,"markerHeight",5),t.setAttributeNS(null,"markerUnits","strokeWidth"),t.setAttributeNS(null,"orient","auto"),t.setAttributeNS(null,"vector-effect","non-scaling-stroke");var i=this.createElement("path");i.setAttributeNS(null,"d","M0,0 L0,10"),i.setAttributeNS(null,"stroke","#872828"),i.setAttributeNS(null,"vector-effect","non-scaling-stroke"),t.appendChild(i),e.appendChild(t),(t=this.createElement("marker")).setAttributeNS(null,"id","markerStart"),t.setAttributeNS(null,"viewBox","0 0 10 10"),t.setAttributeNS(null,"refX",2),t.setAttributeNS(null,"refY",5),t.setAttributeNS(null,"markerWidth",5),t.setAttributeNS(null,"markerHeight",5),t.setAttributeNS(null,"markerUnits","strokeWidth"),t.setAttributeNS(null,"orient","auto"),t.setAttributeNS(null,"vector-effect","non-scaling-stroke"),(i=this.createElement("path")).setAttributeNS(null,"d","M10,0 L0,5 L10,10 z"),i.setAttributeNS(null,"stroke","#872828"),i.setAttributeNS(null,"fill","#872828"),i.setAttributeNS(null,"vector-effect","non-scaling-stroke"),t.appendChild(i),e.appendChild(t),(t=this.createElement("marker")).setAttributeNS(null,"id","markerEnd"),t.setAttributeNS(null,"viewBox","0 0 10 10"),t.setAttributeNS(null,"refX",8),t.setAttributeNS(null,"refY",5),t.setAttributeNS(null,"markerWidth",5),t.setAttributeNS(null,"markerHeight",5),t.setAttributeNS(null,"markerUnits","strokeWidth"),t.setAttributeNS(null,"orient","auto"),t.setAttributeNS(null,"vector-effect","non-scaling-stroke"),(i=this.createElement("path")).setAttributeNS(null,"d","M0,0 L10,5 L0,10 z"),i.setAttributeNS(null,"stroke","#872828"),i.setAttributeNS(null,"fill","#872828"),i.setAttributeNS(null,"vector-effect","non-scaling-stroke"),t.appendChild(i),e.appendChild(t);var n=this.createGridMMPattern();e.appendChild(n),n=this.createGridINPattern(),e.appendChild(n),this.svgRoot.appendChild(e)},SVGRenderer.prototype.createFloorPattern=function(){if(!this.enableFloor||!this.floorDefinition)return null;var e=this.createElement("pattern");e.setAttributeNS(null,"id","imgFloor"),e.setAttributeNS(null,"width","32px"),e.setAttributeNS(null,"height","32px"),e.setAttributeNS(null,"patternUnits","userSpaceOnUse");var t=this.createElement("image");return t.setAttributeNS(null,"x","0"),t.setAttributeNS(null,"y","0"),t.setAttributeNS(null,"width","32px"),t.setAttributeNS(null,"height","32px"),t.setAttributeNS("http://www.w3.org/1999/xlink","href",this.floorDefinition.image),e.appendChild(t),e},SVGRenderer.prototype.createGridINPattern=function(){var e=this.createElement("pattern");e.setAttributeNS(null,"id","gridin"),e.setAttributeNS(null,"width","0.5in"),e.setAttributeNS(null,"height","0.5in"),e.setAttributeNS(null,"patternUnits","userSpaceOnUse");var t=this.createElement("rect");t.setAttributeNS(null,"x","0"),t.setAttributeNS(null,"y","0"),t.setAttributeNS(null,"width","0.5in"),t.setAttributeNS(null,"height","0.5in"),t.setAttributeNS(null,"stroke","var(--baseColor)"),t.setAttributeNS(null,"stroke-width","0.3"),t.setAttributeNS(null,"fill","#ffffff"),t.setAttributeNS(null,"vector-effect","non-scaling-stroke"),e.appendChild(t);var i=this.createElement("line");return i.setAttributeNS(null,"x1","0.25in"),i.setAttributeNS(null,"y1","0"),i.setAttributeNS(null,"x2","0.25in"),i.setAttributeNS(null,"y2","0.5in"),i.setAttributeNS(null,"stroke","var(--baseColor)"),i.setAttributeNS(null,"stroke-width","0.15"),i.setAttributeNS(null,"vector-effect","non-scaling-stroke"),e.appendChild(i),(i=this.createElement("line")).setAttributeNS(null,"x1","0"),i.setAttributeNS(null,"y1","0.25in"),i.setAttributeNS(null,"x2","0.5in"),i.setAttributeNS(null,"y2","0.25in"),i.setAttributeNS(null,"stroke","var(--baseColor)"),i.setAttributeNS(null,"stroke-width","0.15"),i.setAttributeNS(null,"vector-effect","non-scaling-stroke"),e.appendChild(i),e},SVGRenderer.prototype.createGridMMPattern=function(){var e=this.createElement("pattern");e.setAttributeNS(null,"id","gridmm"),e.setAttributeNS(null,"width","25mm"),e.setAttributeNS(null,"height","25mm"),e.setAttributeNS(null,"patternUnits","userSpaceOnUse");var t=this.createElement("rect");t.setAttributeNS(null,"x","0"),t.setAttributeNS(null,"y","0"),t.setAttributeNS(null,"width","25mm"),t.setAttributeNS(null,"height","25mm"),t.setAttributeNS(null,"stroke","var(--baseColor)"),t.setAttributeNS(null,"stroke-width","0.3"),t.setAttributeNS(null,"fill","#ffffff"),t.setAttributeNS(null,"vector-effect","non-scaling-stroke"),e.appendChild(t);for(var i=null,n=0,o=1;o<5;o++)n=5*o,(i=this.createElement("line")).setAttributeNS(null,"x1",n+"mm"),i.setAttributeNS(null,"y1","0"),i.setAttributeNS(null,"x2",n+"mm"),i.setAttributeNS(null,"y2","25mm"),i.setAttributeNS(null,"stroke","var(--baseColor)"),i.setAttributeNS(null,"stroke-width","0.15"),i.setAttributeNS(null,"vector-effect","non-scaling-stroke"),e.appendChild(i),(i=this.createElement("line")).setAttributeNS(null,"x1","0"),i.setAttributeNS(null,"y1",n+"mm"),i.setAttributeNS(null,"x2","25mm"),i.setAttributeNS(null,"y2",n+"mm"),i.setAttributeNS(null,"stroke","var(--baseColor)"),i.setAttributeNS(null,"stroke-width","0.15"),i.setAttributeNS(null,"vector-effect","non-scaling-stroke"),e.appendChild(i);return e},SVGRenderer.prototype.loadBASE=function(e,t){return $.ajax({url:e,cache:!1,data:"e2drequest",dataType:"text",context:t}).done(function(e,t,i){}).fail(function(t,i,n){alert("Error while trying to retrieve BASE: "+e+"\n"+i+"\n"+n)})},SVGRenderer.prototype.loadJSON=function(e,t){return this.loadBASE(e,t).then(function(e){return e?$.parseJSON(e):""})},SVGRenderer.prototype.loadXML=function(e,t){return this.loadBASE(e,t).then(function(e){return e?$.parseXML(e):""})},SVGRenderer.prototype.loadProps=function(e,t,i){var n=this.cachedProperties.get(t);return n||(n=this.loadJSON(e+this.propsFolder+t+".txt",i),this.cachedProperties.set(t,n)),n},SVGRenderer.prototype.loadShape=function(e,t,i){var n=this.cachedObjects.get(t);return n||(n=this.loadXML(e+this.shapeFolder+t+".xml",i),this.cachedObjects.set(t,n)),n.then(function(e){return e?(e=e.getElementsByTagName("g")[0]).cloneNode(!0):null})},SVGRenderer.prototype.loadShapeAndProps=function(e,t,i){var n=$.Deferred();return $.when(this.loadShape(e,t,i),this.loadProps(e,t,i)).done(function(e,t){n.resolve(e,t)}).fail(function(){n.reject()}),n},SVGRenderer.prototype.remove=function(e){e&&e.parentNode&&e.parentNode.removeChild(e)},SVGRenderer.prototype.importAndAppendChild=function(e,t){if(e&&t){var i=e.ownerDocument.importNode(t,!0);return e.appendChild(i),i}},SVGRenderer.prototype.setBackground=function(e,t,i){var n=$.parseXML(e).getElementsByTagName("svg")[0],o=$.map(n.attributes,function(e){return e.name});$.each(o,function(e,t){n.removeAttribute(t)}),n.setAttribute("position","absolute"),n.setAttribute("overflow","visible"),n.setAttribute("preserveAspectRatio","none"),n.setAttribute("viewBox","0 0 100 100");var s=this.createElement("g");s.setAttribute("id",this.BACKGROUND_ID),s.setAttribute("transform","rotate(0,0,0)"),s.appendChild(n);var r=this.importAndAppendChild(this.svgRoot,s);this.setPosition(r,0,0,0),this.setDimensions(r,t,i,0)},SVGRenderer.prototype.getNamespacedElement=function(e,t,i){var n=e.getElementsByTagName(t+":"+i);return n&&0!==n.length||(n=e.getElementsByTagName(i)),n},SVGRenderer.prototype.bounds=function(e){if(e){var t={id:e.id,type:"",x:0,y:0,z:0,width:0,height:0,depth:0,rotation:0,x2:0,y2:0,controlX:0,controlY:0,controlX2:0,controlY2:0,length:0,points:[]};if(this.isConnector(e)){var i=this.getConnectorFrom(e),n=this.getConnectorTo(e);if(t.x=i.x,t.y=i.y,t.x2=n.x,t.y2=n.y,t.width=n.x,t.height=n.y,t.type=this.getConnectorType(e),"curve-line"===t.type){var o=this.getControl1(e),s=this.getControl2(e);t.controlX=o.x,t.controlY=o.y,t.controlX2=s.x,t.controlY2=s.y}else if("quote-line"===t.type){var r=this.getQuoteStackPosition(e);t.stackX=r[0].x,t.stackY=r[0].y,t.stackX2=r[1].x,t.stackY2=r[1].y,t.dimStack=this.getQuoteStack(e),t.dimType=this.getQuoteType(e),t.dimDriving=this.getQuoteDriving(e),t.dimValue=this.getQuoteValue(e)}else if("poly-line"===t.type){var a=this.getPolylinePoints(e),l=a[0],h=a[1],d=a[a.length-2],c=a[a.length-1];t.lengthFrom=0,t.rotationFrom=0,l&&h&&(t.lengthFrom=E2DUtils.getSegmentLength(l.x,l.y,h.x,h.y),t.rotationFrom=(E2DUtils.getSegmentRotation(l.x,l.y,h.x,h.y)+180)%360),t.lengthTo=0,t.rotationTo=0,d&&c&&(t.lengthTo=E2DUtils.getSegmentLength(d.x,d.y,c.x,c.y),t.rotationTo=E2DUtils.getSegmentRotation(d.x,d.y,c.x,c.y)),t.points=a}}else{t.rotation=this.getRotation(e),t.rotation||(t.rotation=0);var u=this.getPosition(e),p=this.getDimensions(e);t.x=u.x,t.y=u.y,t.z=u.z,t.width=p.width,t.height=p.height,t.depth=p.depth}return t}},SVGRenderer.prototype.getBoundingBox=function(e,t){if(!e)return null;var i={};if(this.isConnector(e)){var n=this.bounds(e);"quote-line"!==n.type||t?(i.x=Math.min(n.x,n.x2),i.y=Math.min(n.y,n.y2),i.x2=Math.max(n.x,n.x2),i.y2=Math.max(n.y,n.y2)):(i.x=Math.min(n.x,n.x2,n.stackX,n.stackX2),i.y=Math.min(n.y,n.y2,n.stackY,n.stackY2),i.x2=Math.max(n.x,n.x2,n.stackX,n.stackX2),i.y2=Math.max(n.y,n.y2,n.stackY,n.stackY2)),i.z=0,i.z2=0,i.width=Math.abs(i.x2-i.x),i.height=Math.abs(i.y2-i.y),i.depth=0}else if(0===(i=this.bounds(e)).rotation)i.x2=i.x+i.width,i.y2=i.y+i.height,i.z2=i.z+i.depth;else{var o=this.getRotatedVerticesFromRect(i,0,0),s=Math.min(Math.min(o[0].x,o[3].x),Math.min(o[1].x,o[2].x)),r=Math.min(Math.min(o[0].y,o[3].y),Math.min(o[1].y,o[2].y)),a=Math.max(Math.max(o[0].x,o[3].x),Math.max(o[1].x,o[2].x)),l=Math.max(Math.max(o[0].y,o[3].y),Math.max(o[1].y,o[2].y));i.x=s,i.y=r,i.z=parseInt(i.z),i.width=a-s,i.height=l-r,i.depth=parseInt(i.depth),i.x2=a,i.y2=l,i.z2=i.z+i.depth}return i},SVGRenderer.prototype.getGlobalBoundingBox=function(e){var t=$.merge(this.getAllShapes(this.container),this.getAllConnectors(this.container));if(!t)return null;for(var i=this.MAX_WIDTH,n=-this.MAX_WIDTH,o=this.MAX_HEIGHT,s=-this.MAX_HEIGHT,r=0,a=t.length;r<a;r++){var l=this.getBoundingBox(t[r]);t[r].id!==E2DGlobals.e2d.ORIGIN_ID&&t[r].id!==E2DGlobals.e2d.CUSTOM_ORIGIN_ID?(l.x<i&&(i=l.x),l.x2>n&&(n=l.x2),l.y<o&&(o=l.y),l.y2>s&&(s=l.y2)):(l.x+Math.abs(l.x2-l.x)/2,l.y+Math.abs(l.y2-l.y)/2)}return{x:i,y:o,x2:n,y2:s,width:Math.abs(n-i),height:Math.abs(s-o)}},SVGRenderer.prototype.hasSameRotation=function(e,t){return!(!e||!t)&&e.rotation===t.rotation},SVGRenderer.prototype.hasSameDimensions=function(e,t){return!(!e||!t)&&(Math.abs(e.width-t.width)<1e-6&&Math.abs(e.height-t.height)<1e-6&&Math.abs(e.depth-t.depth)<1e-6)},SVGRenderer.prototype.createLine=function(e,t,i,n){return this.loadShape(e,t,this).then(function(e){if(!e)return null;var o=this.importAndAppendChild(this.svgRoot,e);return"line"!==t&&"curve-line"!==t&&"link-line"!==t&&"quote-line"!==t&&"smart-line"!==t||(this.setLineFrom(o,i,n),this.setLineTo(o,i,n)),"curve-line"===t&&(this.setControl1(o,i,n),this.setControl2(o,i,n)),"poly-line"===t&&this.startPolyline(o,i,n),o}.bind(this))},SVGRenderer.prototype.create=function(e,t,i,n,o,s,r,a){return this.loadShape(e,t,this).then(function(e){var t=this.importAndAppendChild(this.svgRoot,e);return this.setPosition(t,i,n,o),this.setDimensions(t,s,r,a),t}.bind(this))},SVGRenderer.prototype.createElement=function(e){return this.container.ownerDocument.createElementNS(this.svgNamespace,e)},SVGRenderer.prototype.getAttribute=function(e,t){return e.getAttributeNS(null,t)},SVGRenderer.prototype.copy=function(e){if(!e)return null;var t=e.cloneNode(!0);return t.classList.remove("collidingghost"),t.classList.remove("externalghost"),t.classList.remove("firstselectionghost"),t.classList.remove("selectionghost"),t},SVGRenderer.prototype.paste=function(e,t,i){if(e){var n=t||"number"==typeof t?t:10,o=i||"number"==typeof i?i:10,s=e.cloneNode(!0);if(s.id=(this.isConnector(e)?"connector_":"shape_")+E2DUtils.createUUID(),this.isConnector(s)){var r=this.getLineStyle(s);r&&this.setLineStyle(s,r),this.moveCompleteLine(s,this.bounds(s),n,o)}else{var a=this.getPosition(s);this.setPosition(s,a.x+n,a.y+o,a.z),this.updateRotation(s)}this.svgRoot.appendChild(s);var l=this.getTextData(e),h=E2DUtils.cloneObject(l);return this.addTextData(s,h),s}},SVGRenderer.prototype.isMultipleSelect=function(e){return!!e&&("string"==typeof e?e:e.id)===this.MULTIPLE_SELECTOR_TRACKER_ID},SVGRenderer.prototype.isImage=function(e){return!!e&&e.getElementsByTagName("image").length>0},SVGRenderer.prototype.isConnector=function(e){return!!e&&("number"!=typeof e&&("string"==typeof e&&(e=document.getElementById(e)),e.classList.contains("connector")))},SVGRenderer.prototype.isLine=function(e){return!!e&&("string"==typeof e&&(e=document.getElementById(e)),this.isConnector(e)&&e.classList.contains("line"))},SVGRenderer.prototype.isSmartLine=function(e){return!!e&&("string"==typeof e&&(e=document.getElementById(e)),this.isConnector(e)&&e.classList.contains("smart-line"))},SVGRenderer.prototype.isSnapLine=function(e){return!!e&&("string"==typeof e&&(e=document.getElementById(e)),this.isConnector(e)&&e.classList.contains("snap-line"))},SVGRenderer.prototype.isSmartLineHub=function(e){return!!e&&("string"==typeof e&&(e=document.getElementById(e)),!!e&&e.classList.contains("smart-line-hub"))},SVGRenderer.prototype.isPolyline=function(e){return!!e&&("string"==typeof e&&(e=document.getElementById(e)),this.isConnector(e)&&e.classList.contains("poly-line"))},SVGRenderer.prototype.isPolyquote=function(e){return!!e&&("string"==typeof e&&(e=document.getElementById(e)),this.isConnector(e)&&e.classList.contains("poly-quote"))},SVGRenderer.prototype.isLinkLine=function(e){return!!e&&("string"==typeof e&&(e=document.getElementById(e)),this.isConnector(e)&&e.classList.contains("link-line"))},SVGRenderer.prototype.isQuoteLine=function(e){return!!e&&("string"==typeof e&&(e=document.getElementById(e)),this.isConnector(e)&&e.classList.contains("quote-line"))},SVGRenderer.prototype.testInclusion=function(e,t){if(!e||!t)return!1;if(E2DUtils.isRectFarAway(e,t))return!1;for(var i=this.getRotatedVerticesFromRect(e),n=this.getRotatedVerticesFromRect(t),o=0,s=i.length;o<s;o++)if(!E2DUtils.isPointInRect(i[o],n))return!1;return!0},SVGRenderer.prototype.testInclusionSimple=function(e,t){return parseInt(t.x)>parseInt(e.x)&&parseInt(t.y)>parseInt(e.y)&&parseInt(t.x)+parseInt(t.width)<parseInt(e.x)+parseInt(e.width)&&parseInt(t.y)+parseInt(t.height)<parseInt(e.y)+parseInt(e.height)},SVGRenderer.prototype.testCollision=function(e,t,i){if(!e||!t)return!1;if(E2DUtils.isRectFarAway(e,t))return!1;var n=this.getRotatedVerticesFromRect(e),o=this.getRotatedVerticesFromRect(t);if(E2DUtils.areVerticesFarAway(n,o))return!1;var s=this.getCenterPointFromRect(e,0,0);if(E2DUtils.isPointInRect(s,o))return!0;var r=this.getCenterPointFromRect(t,0,0);if(E2DUtils.isPointInRect(r,n))return!0;for(var a=0,l=n.length;a<l;a++)if(E2DUtils.isPointInRect(n[a],o))return!0;for(var h=0,d=o.length;h<d;h++)if(E2DUtils.isPointInRect(o[h],n))return!0;return!!i&&E2DUtils.isIntersecting(n,o)},SVGRenderer.prototype.getRotatedVerticesFromShape=function(e){if(!e)return null;var t=this.bounds(e);return this.getRotatedVerticesFromRect(t,0,0)},SVGRenderer.prototype.getRotatedVerticesFromRect=function(e,t,i){if(!e)return null;t=t||0,i=i||0;var n=[];n[0]={x:e.x,y:e.y,px:0,py:0,D:null},n[1]={x:n[0].x+e.width,y:n[0].y,px:0,py:0,D:null},n[2]={x:n[0].x+e.width,y:n[0].y+e.height,px:0,py:0,D:null},n[3]={x:n[0].x,y:n[0].y+e.height,px:0,py:0,D:null};for(var o=0,s=n.length;o<s;o++){var r=this.getRotatedPoint(n[o].x,n[o].y,e);n[o].x=r.x+t,n[o].y=r.y+i}return n},SVGRenderer.prototype.getCenterPointFromRect=function(e,t,i){t=t||0,i=i||0;var n={x:0,y:0};return e&&(n.x=1*e.x+e.width/2+t,n.y=1*e.y+e.height/2+i),n},SVGRenderer.prototype.getCenterPointFromShape=function(e,t,i){var n=this.bounds(e);return this.getCenterPointFromRect(n,t,i)},SVGRenderer.prototype.getRotatedPoint=function(e,t,i){var n=E2DUtils.deg2rad(i.rotation),o=this.getCenterPointFromRect(i,0,0);e-=o.x,t-=o.y;var s={};return s.x=e*Math.cos(n)-t*Math.sin(n)+1*o.x,s.y=e*Math.sin(n)+t*Math.cos(n)+1*o.y,s},SVGRenderer.prototype.getRotatedPointAroundPoint=function(e,t,i,n,o){var s=E2DUtils.deg2rad(o);e-=i,t-=n;var r={};return r.x=e*Math.cos(s)-t*Math.sin(s)+1*i,r.y=e*Math.sin(s)+t*Math.cos(s)+1*n,r},SVGRenderer.prototype.getProportionalBoundsRotation=function(e,t,i){var n=E2DUtils.cloneObject(e),o=E2DUtils.cloneObject(t);o.rotation=i,n.rotation=i;var s=this.getRotatedPoint(n.x,n.y,n),r=this.getRotatedPoint(n.x,n.y,o);return{x:1*n.x+(r.x-s.x),y:1*n.y+(r.y-s.y)}},SVGRenderer.prototype.createTextLines=function(e,t){for(var i=[],n=0,o=e.length;n<o;n++){var s={},r=e[n];if(r.length<t)s.text=r,s.type="normal",i[i.length]=s;else{var a="",l=r.length/t>>0,h=r.length%t,d=0;for(d=0;d<l;d++)a=r.substr(d*t,t),s.text=a,s.type=0===d?"newline":"normal",i[i.length]=s;h>0&&(a=r.substr(d*t,h),s.text=a,s.type=0===l?"newline":"normal",i[i.length]=s)}}return i},SVGRenderer.prototype.createTextSet=function(e){var t=[];return e&&0!==e.length?t=e.split(this.LINE_DELIMITER):t},SVGRenderer.prototype.createTextShape=function(e,t,i,n,o,s){var r=this.createElement("text");return r.classList.add(e.type),r.setAttribute("xml:space","preserve"),o?(r.setAttributeNS(null,"x",o.x),r.setAttributeNS(null,"y",o.y)):(r.setAttributeNS(null,"x",i),r.setAttributeNS(null,"y",t)),isNaN(1*s)||(o?r.setAttributeNS(null,"transform","rotate("+s+","+o.x+","+o.y+")"):r.setAttributeNS(null,"transform","rotate("+s+","+i+","+t+")")),n.color&&r.setAttributeNS(null,"fill",n.color),n.size&&r.setAttributeNS(null,"font-size",n.size),n.family&&(r.style.fontFamily=n.family),r.setAttributeNS(null,"text-anchor","middle"),r.textContent=e.text,r},SVGRenderer.prototype.getShapeText=function(e){var t="";if(!e||!e.id)return t;var i=this.getTextData(e);return i&&i.text&&(t=i.text),t},SVGRenderer.prototype.setShapeText=function(e,t,i,n,o){var s=null;if(i)s=i;else{var r=this.getTextData(e);r?(s=r.font,n=n||r.position,o=isNaN(1*o)?r.rotation:o):s=this.getFont(e)}var a=this.getTextBounds(e,t,s);a.width=a.width<25?25:a.width,a.height=0===a.height?1:a.height;var l=Math.ceil(a.width/s.size*2),h=t.wordWrap(l,this.LINE_DELIMITER,!1),d=this.createTextSet(h);if(0===d.length)return!1;for(var c=this.createTextLines(d,l),u=Math.ceil(c.length/2),p=this.handleTextLinePositioning(a,u,c,s,n,o),g=0,y=p.length;g<y;g++)p[g]=this.importAndAppendChild(e,p[g]);this.setTextData(e,t,s,n,o)},SVGRenderer.prototype.addTextData=function(e,t){e&&e.id&&t&&(this.textDataHash[e.id]=t)},SVGRenderer.prototype.getTextData=function(e){return e&&e.id?this.textDataHash[e.id]:null},SVGRenderer.prototype.setTextData=function(e,t,i,n,o){e&&e.id&&(t||(t=""),i||(i=E2DFont.get()),this.textDataHash[e.id]={text:t,font:i,position:n,rotation:o})},SVGRenderer.prototype.updateTextData=function(e,t){if(e&&e.id&&t){var i=this.textDataHash[e.id];i&&(i.font=t,this.textDataHash[e.id]=i)}},SVGRenderer.prototype.getTextBounds=function(e,t,i){var n={},o={};if(this.isConnector(e)){o=this.getConnectorTextSize(e,t,i);var s=this.getConnectorCenterPoint(e);n.width=o.width,n.height=o.height,n.x=s.x-n.width/2,n.y=s.y-n.height/2}else{n=this.bounds(e);var r=this.getNamespacedElement(e,"c","text-bound");if(r.length>0){o=this.getConnectorTextSize(e,t,i);var a=r[0],l=this.getAttribute(a,"fromX"),h=this.getAttribute(a,"fromY"),d=l*n.width/this.COORD_X+1*n.x,c=h*n.height/this.COORD_Y+1*n.y;n.x=n.left=d,n.y=n.top=c,n.width=o.width,n.height=o.height}}return n},SVGRenderer.prototype.getConnectorTextSize=function(e,t,i){var n=t;n||(n=this.getShapeText(e));var o=i;o||(o=this.getFont(e)),0===o.size.length&&(o=E2DFont.mergeWithDefault(o));for(var s=n.split("\n"),r=(s.length+1)*o.size*1.2,a=50,l=0,h=s.length;l<h;l++)s[l].length*o.size/2>a&&(a=s[l].length*o.size/2);return{width:a*=1.2,height:r}},SVGRenderer.prototype.getConnectorCenterPoint=function(e){var t=this.bounds(e),i=this.getConnectorType(e),n={};if("line"===i||"link-line"===i||"smart-line"===i||"poly-line"===i)n=E2DUtils.midpointOfLine(t.x,t.y,t.x2,t.y2);else if("curve-line"===i){var o=E2DUtils.midpointOfLine(1*t.controlX,1*t.controlY,1*t.controlX2,1*t.controlY2),s=E2DUtils.midpointOfLine(t.x,t.y,t.x2,t.y2);n=E2DUtils.midpointOfLineEx(o,s)}else if("quote-line"===i){var r=this.getShapeSubject(e);if(r||5===r.length){var a=1*r[1].getAttributeNS(null,"x1"),l=1*r[1].getAttributeNS(null,"y1"),h=1*r[1].getAttributeNS(null,"x2"),d=1*r[1].getAttributeNS(null,"y2");n=E2DUtils.midpointOfLine(a,l,h,d)}}else"ortho-line"===i&&(t=this.getOrthoLineCenterSegment(e),n=E2DUtils.midpointOfLine(t.x,t.y,t.x2,t.y2));return n},SVGRenderer.prototype.sendToBack=function(e){if(e){var t=e.cloneNode(!0);this.remove(e);var i=this.svgRoot.getElementsByTagName("g");return i.length>1?this.svgRoot.insertBefore(t,i[1]):this.svgRoot.appendChild(t),t}},SVGRenderer.prototype.bringToFront=function(e){if(e){var t=e.cloneNode(!0);return this.remove(e),t=this.importAndAppendChild(this.svgRoot,t)}},SVGRenderer.prototype.setLineFrom=function(e,t,i){var n=this.getShapeSubject(e),o=this.getConnectorType(e);if("line"===o||"smart-line"===o||"snap-line"===o)n.setAttributeNS(null,"x1",t),n.setAttributeNS(null,"y1",i);else if("link-line"===o)n.setAttributeNS(null,"x1",t),n.setAttributeNS(null,"y1",i);else if("curve-line"===o){var s=n.getPathData(),r=s[0];r.values[0]=Math.round(1*t),r.values[1]=Math.round(1*i),s[0]=r,n.setPathData(s)}else if("quote-line"===o&&n&&5===n.length){var a=this.getQuoteType(e);switch(n[0].setAttributeNS(null,"x1",t),n[0].setAttributeNS(null,"y1",i),a){case 0:var l=this.getQuoteStack(e),h=1*n[2].getAttributeNS(null,"x1"),d=1*n[2].getAttributeNS(null,"y1"),c=E2DUtils.getPerpendicularPointsAtDistanceFromSegmentEndpoints(t,i,h,d,l);n[0].setAttributeNS(null,"x2",c[0].x),n[0].setAttributeNS(null,"y2",c[0].y),n[1].setAttributeNS(null,"x1",c[0].x),n[1].setAttributeNS(null,"y1",c[0].y),n[1].setAttributeNS(null,"x2",c[1].x),n[1].setAttributeNS(null,"y2",c[1].y),n[2].setAttributeNS(null,"x2",c[1].x),n[2].setAttributeNS(null,"y2",c[1].y);break;case 1:n[0].setAttributeNS(null,"x2",t),n[1].setAttributeNS(null,"x1",t);break;case 2:n[0].setAttributeNS(null,"y2",i),n[1].setAttributeNS(null,"y1",i);break;default:return}const o=n[1].getAttributeNS(null,"x1"),s=n[1].getAttributeNS(null,"y1");n[3].setAttributeNS(null,"cx",o),n[3].setAttributeNS(null,"cy",s),this.updateQuoteStack(e),this.updateQuoteValue(e)}},SVGRenderer.prototype.setLineTo=function(e,t,i){var n=this.getShapeSubject(e),o=this.getConnectorType(e);if("line"===o||"smart-line"===o||"snap-line"===o)n.setAttributeNS(null,"x2",t),n.setAttributeNS(null,"y2",i);else if("link-line"===o)n.setAttributeNS(null,"x2",t),n.setAttributeNS(null,"y2",i);else if("curve-line"===o){var s=n.getPathData(),r=s[1];r.values[4]=Math.round(1*t),r.values[5]=Math.round(1*i),s[1]=r,n.setPathData(s)}else if("quote-line"===o&&n&&5===n.length){var a=this.getQuoteType(e);switch(n[2].setAttributeNS(null,"x1",t),n[2].setAttributeNS(null,"y1",i),a){case 0:var l=this.getQuoteStack(e),h=1*n[0].getAttributeNS(null,"x1"),d=1*n[0].getAttributeNS(null,"y1"),c=E2DUtils.getPerpendicularPointsAtDistanceFromSegmentEndpoints(h,d,t,i,l);n[0].setAttributeNS(null,"x2",c[0].x),n[0].setAttributeNS(null,"y2",c[0].y),n[1].setAttributeNS(null,"x1",c[0].x),n[1].setAttributeNS(null,"y1",c[0].y),n[1].setAttributeNS(null,"x2",c[1].x),n[1].setAttributeNS(null,"y2",c[1].y),n[2].setAttributeNS(null,"x2",c[1].x),n[2].setAttributeNS(null,"y2",c[1].y);break;case 1:n[1].setAttributeNS(null,"x2",t),n[2].setAttributeNS(null,"x2",t);break;case 2:n[1].setAttributeNS(null,"y2",i),n[2].setAttributeNS(null,"y2",i);break;default:return}const o=n[1].getAttributeNS(null,"x2"),s=n[1].getAttributeNS(null,"y2");n[4].setAttributeNS(null,"cx",o),n[4].setAttributeNS(null,"cy",s),this.updateQuoteValue(e)}},SVGRenderer.prototype.setControl1=function(e,t,i){var n=this.getShapeSubject(e),o=n.getPathData(),s=o[1];s.values[0]=Math.round(1*t),s.values[1]=Math.round(1*i),o[1]=s,n.setPathData(o)},SVGRenderer.prototype.getControl1=function(e){var t=this.getShapeSubject(e).getPathData()[1];return{x:1*t.values[0],y:1*t.values[1]}},SVGRenderer.prototype.setControl2=function(e,t,i){var n=this.getShapeSubject(e),o=n.getPathData(),s=o[1];s.values[2]=Math.round(1*t),s.values[3]=Math.round(1*i),o[1]=s,n.setPathData(o)},SVGRenderer.prototype.getControl2=function(e){var t=this.getShapeSubject(e).getPathData()[1];return{x:1*t.values[2],y:1*t.values[3]}},SVGRenderer.prototype.getQuoteStackPosition=function(e){var t=[],i=this.getShapeSubject(e);i&&5===i.length&&(t=[{x:1*i[1].getAttributeNS(null,"x1"),y:1*i[1].getAttributeNS(null,"y1")},{x:1*i[1].getAttributeNS(null,"x2"),y:1*i[1].getAttributeNS(null,"y2")}]);return t},SVGRenderer.prototype.getQuoteStack=function(e){var t=this.getShapeSubject(e);return t&&5===t.length?1*t[1].getAttributeNS(null,"dimStack"):this.QUOTE_STACK},SVGRenderer.prototype.setQuoteStack=function(e,t,i,n){var o=this.getShapeSubject(e);if(t&&o&&5===o.length){var s=1*o[0].getAttributeNS(null,"x1"),r=1*o[0].getAttributeNS(null,"y1"),a=1*o[2].getAttributeNS(null,"x1"),l=1*o[2].getAttributeNS(null,"y1");if(t*=1,t=isNaN(t)||"number"!=typeof t?this.QUOTE_STACK:t,i){const e=E2DGlobals.e2d;switch(t=e.convertGraphDataToUserData(t),n){case 1:t=r-(t=e.convertUserYToGraphY(t));break;case 2:t=e.convertUserXToGraphX(t),t-=s}}o[1].setAttributeNS(null,"dimStack",t);var h=E2DUtils.getPerpendicularPointsAtDistanceFromSegmentEndpoints(s,r,a,l,t);o[0].setAttributeNS(null,"x2",h[0].x),o[0].setAttributeNS(null,"y2",h[0].y),o[1].setAttributeNS(null,"x1",h[0].x),o[1].setAttributeNS(null,"y1",h[0].y),o[1].setAttributeNS(null,"x2",h[1].x),o[1].setAttributeNS(null,"y2",h[1].y),o[2].setAttributeNS(null,"x2",h[1].x),o[2].setAttributeNS(null,"y2",h[1].y),o[3].setAttributeNS(null,"cx",h[0].x),o[3].setAttributeNS(null,"cy",h[0].y),o[4].setAttributeNS(null,"cx",h[1].x),o[4].setAttributeNS(null,"cy",h[1].y),this.updateQuoteValue(e)}},SVGRenderer.prototype.getQuoteType=function(e){var t=this.getShapeSubject(e);return t&&5===t.length?1*t[1].getAttributeNS(null,"dimType"):this.QUOTE_TYPE},SVGRenderer.prototype.setQuoteType=function(e,t){var i=this.getShapeSubject(e);if(i&&5===i.length){t*=1,t=isNaN(t)||"number"!=typeof t?this.QUOTE_TYPE:t,i[1].setAttributeNS(null,"dimType",t);var n=1*i[0].getAttributeNS(null,"x1"),o=1*i[0].getAttributeNS(null,"y1"),s=1*i[2].getAttributeNS(null,"x1"),r=1*i[2].getAttributeNS(null,"y1"),a=this.getQuoteStack(e),l=[];switch(t){case 0:l=E2DUtils.getPerpendicularPointsAtDistanceFromSegmentEndpoints(n,o,s,r,a);break;case 1:l[0]={x:n,y:o-a},l[1]={x:s,y:o-a};break;case 2:l[0]={x:n+a,y:o},l[1]={x:n+a,y:r};break;default:return}i[0].setAttributeNS(null,"x2",l[0].x),i[0].setAttributeNS(null,"y2",l[0].y),i[1].setAttributeNS(null,"x1",l[0].x),i[1].setAttributeNS(null,"y1",l[0].y),i[1].setAttributeNS(null,"x2",l[1].x),i[1].setAttributeNS(null,"y2",l[1].y),i[2].setAttributeNS(null,"x2",l[1].x),i[2].setAttributeNS(null,"y2",l[1].y),i[3].setAttributeNS(null,"cx",l[0].x),i[3].setAttributeNS(null,"cy",l[0].y),i[4].setAttributeNS(null,"cx",l[1].x),i[4].setAttributeNS(null,"cy",l[1].y),this.updateQuoteValue(e)}},SVGRenderer.prototype.getQuoteDriving=function(e){var t=this.getShapeSubject(e);return t&&5===t.length?E2DUtils.toBoolean(t[1].getAttributeNS(null,"dimDriving")):this.QUOTE_DRIVING},SVGRenderer.prototype.setQuoteDriving=function(e,t,i){var n=this.getShapeSubject(e);if(n&&5===n.length){var o=E2DGlobals.e2d,s=o.insertedShapes.getConnectionShape(e.id,"from"),r=o.insertedShapes.getConnectionShape(e.id,"to");if(s.shapeID===r.shapeID&&(t=!1),n[1].setAttributeNS(null,"dimDriving",t),this.setFont(e,{color:t?"red":"black"}),t){var a=this.getConnectorFrom(e),l=document.getElementById(s.shapeID),h=o.insertedShapes.isPinned(s.shapeID,[e.id]),d=this.getConnectorTo(e),c=document.getElementById(r.shapeID),u=o.insertedShapes.isPinned(r.shapeID,[e.id]);if(h.pinnedX&&h.pinnedY&&u.pinnedX&&u.pinnedY)return!1;var p=i-this.getQuoteValue(e);if(Math.abs(p)<1e-6)return!1;var g=!0,y=null,f=null,v=1;switch(this.getQuoteType(e)){case 0:if(h.pinnedX||h.pinnedY){if(u.pinnedX||u.pinnedY)return!1;g=!1,y=c;var m=E2DUtils.getPointAtDistanceAlongSegment(a.x,a.y,d.x,d.y,i);f={x:m.x-d.x,y:m.y-d.y,z:0}}else{g=!0,y=l;var S=E2DUtils.getPointAtDistanceAlongSegment(d.x,d.y,a.x,a.y,i);f={x:S.x-a.x,y:S.y-a.y,z:0}}break;case 1:if(h.pinnedX){if(u.pinnedX)return!1;v=d.x<a.x?-1:1,g=!1,y=c}else v=a.x<d.x?-1:1,g=!0,y=l;f={x:v*p,y:0,z:0};break;case 2:if(h.pinnedY){if(u.pinnedY)return!1;v=d.y<a.y?-1:1,y=c,g=!1}else v=a.y<d.y?-1:1,y=l,g=!0;f={x:0,y:v*p,z:0};break;default:return!1}this.setQuoteValue(e,i),g?this.setLineFrom(e,a.x+f.x,a.y+f.y):this.setLineTo(e,d.x+f.x,d.y+f.y);var E=this.getPosition(y);this.move(y,E.x+f.x,E.y+f.y,E.z),o.moveShapeDependencies(y,f.x,f.y,null,0,[e.id]),o.clearShapeText(y),o.resetShapeText(y),o.updateIShape(y,this.bounds(y),"",!1)}}return!0},SVGRenderer.prototype.getQuoteValue=function(e){var t=this.getShapeSubject(e);return t&&5===t.length?1*t[1].getAttributeNS(null,"dimValue"):0},SVGRenderer.prototype.setQuoteValue=function(e,t){var i=this.getShapeSubject(e);i&&5===i.length&&(t*=1,(t=isNaN(t)||"number"!=typeof t?0:t)!==this.getQuoteValue(e)&&i[1].setAttributeNS(null,"dimValue",t))},SVGRenderer.prototype.getQuoteInfo=function(e){var t={position:null,rotation:null,value:null};if(!this.isQuoteLine(e))return t;var i=this.getShapeSubject(e);if(!i||5!==i.length)return t;var n=1*i[1].getAttributeNS(null,"x1"),o=1*i[1].getAttributeNS(null,"y1"),s=1*i[1].getAttributeNS(null,"x2"),r=1*i[1].getAttributeNS(null,"y2"),a=2,l=E2DUtils.getSegmentRotation(n,o,s,r);return 0<=l&&l<90?a*=-1:90<=l&&l<180?(a*=1,l=(l+180)%360):180<=l&&l<270?(a*=-1,l=(l+180)%360):270<=l&&l<=360&&(a*=1),t.rotation=l,t.position=E2DUtils.getPerpendicularPointAtDistanceFromSegmentMidpoint(n,o,s,r,a),t.value=E2DUtils.pointToPointDistance(n,o,s,r),t},SVGRenderer.prototype.showQuoteValue=function(e,t,i,n){if(this.isQuoteLine(e)){var o=this.getQuoteDriving(e),s=E2DFont.get();s.forced||(s.size="12"),s.color=o?"red":"black";var r=E2DGlobals.e2d;t=E2DUtils.round(r.convertGraphDataToUserData(t),r.numberOfDecimal).toString(),r.quoteUOMEnabled&&(t+=" "+r.unit),this.clearShapeText(e);var a=r.insertedShapes.getShapeById(e.id);a&&(a.text=t),this.setShapeText(e,t,s,i,n)}},SVGRenderer.prototype.updateQuoteValue=function(e){var t=this.getQuoteInfo(e);this.setQuoteValue(e,t.value),this.showQuoteValue(e,t.value,t.position,t.rotation)},SVGRenderer.prototype.updateQuoteStack=function(e){var t=this.getShapeSubject(e);if(t&&5===t.length){var i=1*t[0].getAttributeNS(null,"x1"),n=1*t[0].getAttributeNS(null,"y1"),o=1*t[0].getAttributeNS(null,"x2"),s=1*t[0].getAttributeNS(null,"y2"),r=1*t[2].getAttributeNS(null,"x1"),a=1*t[2].getAttributeNS(null,"y1"),l=E2DUtils.pointToPointDistance(i,n,o,s),h={x:o,y:s},d={x:i,y:n},c={x:r,y:a};switch(this.getQuoteType(e)){case 0:E2DUtils.isPointLeftOfLine(h,d,c)&&(l*=-1);break;case 1:n<s&&(l*=-1);break;case 2:o<i&&(l*=-1)}t[1].setAttributeNS(null,"dimStack",isNaN(l)||"number"!=typeof l?this.QUOTE_STACK:l)}},SVGRenderer.prototype.updateQuoteType=function(e){var t=0,i=this.bounds(e),n=this.getQuoteStack(e),o=Math.abs(i.x2-i.x)/Math.abs(i.y2-i.y);o>1.2?(t=1,n=10):o<.8&&(t=2,n=10);var s=E2DGlobals.e2d,r=s.insertedShapes.getShapeById(e.id);if(r.dimType!==t){r.dimType=t,r.dimStack!==n&&(r.dimStack=n);var a=s.convertUserDataToGraphData(r.dimValue);this.updateQuote(e,r.dimStack,r.dimType,r.dimDriving,a)&&(this.updateTracker(e),s.updateShapeInfo(e))}},SVGRenderer.prototype.moveQuote=function(e,t,i,n,o){var s=this.getShapeSubject(e);s&&5===s.length&&(s[0].setAttributeNS(null,"x2",t),s[0].setAttributeNS(null,"y2",i),s[1].setAttributeNS(null,"x1",t),s[1].setAttributeNS(null,"y1",i),s[1].setAttributeNS(null,"x2",n),s[1].setAttributeNS(null,"y2",o),s[2].setAttributeNS(null,"x2",n),s[2].setAttributeNS(null,"y2",o),s[3].setAttributeNS(null,"cx",t),s[3].setAttributeNS(null,"cy",i),s[4].setAttributeNS(null,"cx",n),s[4].setAttributeNS(null,"cy",o),this.updateQuoteStack(e),this.updateQuoteValue(e))},SVGRenderer.prototype.updateQuote=function(e,t,i,n,o,s){return this.setQuoteStack(e,t,s,i),this.setQuoteType(e,i),this.setQuoteDriving(e,n,o)},SVGRenderer.prototype.setLayer=function(e,t){e&&(t&&!t.visible?e.classList.add("layer-hidden"):e.classList.remove("layer-hidden"))},SVGRenderer.prototype.setPinned=function(e,t){e&&(t?e.classList.add("pinned"):e.classList.remove("pinned"))},SVGRenderer.prototype.moveLine=function(e,t,i,n){if(e&&this.isConnector(e)){var o=this.getConnectorType(e);if("line"===o||"curve-line"===o||"link-line"===o||"quote-line"===o||"smart-line"===o)n?this.setLineFrom(e,t,i):this.setLineTo(e,t,i);else if("poly-line"===o)this.drawPolyline(e,t,i,n);else{var s,r,a=e.getElementsByTagName("polyline")[0].points,l=a.numberOfItems;n?(s=a.getItem(l-1).x,r=a.getItem(l-1).y,this.drawOrthoLine(e,t,i,s,r)):(s=a.getItem(0).x,r=a.getItem(0).y,this.drawOrthoLine(e,s,r,t,i))}}},SVGRenderer.prototype.moveCompleteLine=function(e,t,i,n,o,s){if(this.isConnector(e)){var r,a,l,h,d=t.type;if("poly-line"===d)this.movePolyline(e,t,i,n);else if("quote-line"===d){var c=this.getShapeSubject(e);if(c&&5===c.length)if("number"==typeof o&&"number"==typeof s||E2DEvents.autoScrollIntervalID){r=1*c[1].getAttributeNS(null,"x1"),a=1*c[1].getAttributeNS(null,"y1"),l=1*c[1].getAttributeNS(null,"x2"),h=1*c[1].getAttributeNS(null,"y2");var u=E2DUtils.midpointOfLine(r,a,l,h),p=E2DUtils.getPerpendicularPointAtDistanceFromSegmentPoint(r,a,l,h,u.x,u.y,10),g=("number"==typeof o?o:u.x)+i,y=("number"==typeof s?s:u.y)+n,f=E2DUtils.pointLineIntersection(g,y,u.x,u.y,p.x,p.y),v=f.x-u.x,m=f.y-u.y;this.moveQuote(e,r+v,a+m,l+v,h+m)}else r=1*t.x+i,a=1*t.y+n,l=1*t.x2+i,h=1*t.y2+n,this.moveLine(e,r,a,!0),this.moveLine(e,l,h,!1)}else if(r=1*t.x+i,a=1*t.y+n,l=1*t.x2+i,h=1*t.y2+n,this.moveLine(e,r,a,!0),this.moveLine(e,l,h,!1),"curve-line"===d){var S=1*t.controlX+i,E=1*t.controlY+n,D=1*t.controlX2+i,b=1*t.controlY2+n;this.setControl1(e,S,E),this.setControl2(e,D,b)}}},SVGRenderer.prototype.moveLineWithShape=function(e,t,i,n){if(e){var o=!1,s=E2DGlobals.e2d.insertedShapes.getShapeById(e.id);if(s&&s.shapeConnections&&s.shapeConnections.length>0)for(var r=s.shapeConnections,a=0,l=r.length;a<l;a++){var h=r[a],d="from"===h.type;if((!t||h.lineID===t)&&(!i||h.lineID!==i)){var c=this.getConnectionPointObjByPointId(e,h.cpID),u=document.getElementById(h.lineID);this.isQuoteLine(u)&&this.getQuoteDriving(u)?o=!0:this.moveLine(u,c.x,c.y,d)}}var p=!(n&&n.sList&&n.sList[e.id]);o&&p&&this.moveQuotesWithShape(e.id,i)}},SVGRenderer.prototype.moveQuotesWithShape=function(e,t){var i=E2DGlobals.e2d;i.dragCache||(i.dragCache={}),void 0===i.dragCache.linkedShapesWithQuotesHash&&(i.dragCache.linkedShapesWithQuotesHash=[]);var n=i.insertedShapes.getAttachedShapesWithQuotes(e,t,n),o=n.hList;if(o)for(var s in o)if(o.hasOwnProperty(s)){var r=o[s],a=r.delta.x;if(!E2DUtils.isAlmostZero(a)){r.delta.x=a;var l=this.getPosition(r.shape);this.move(r.shape,l.x+a,l.y,l.z),i.moveShapeDependencies(r.shape,a,0,0,0,[t],n),i.clearShapeText(r.shape),i.resetShapeText(r.shape),i.updateIShape(r.shape,this.bounds(r.shape),"",!1)}}var h=n.vList;if(h)for(var d in h)if(h.hasOwnProperty(d)){var c=h[d],u=c.delta.y;if(!E2DUtils.isAlmostZero(u)){c.delta.y=u;var p=this.getPosition(c.shape);this.move(c.shape,p.x,p.y+u,p.z),i.moveShapeDependencies(c.shape,0,u,0,0,[t],n),i.clearShapeText(c.shape),i.resetShapeText(c.shape),i.updateIShape(c.shape,this.bounds(c.shape),"",!1)}}var g=n.qList;if(g)for(var y in g)if(g.hasOwnProperty(y)){var f=document.getElementById(y);this.validateQuote(f,n.origID,n.hList[y],n.vList[y])}},SVGRenderer.prototype.connectLine=function(e,t,i,n){t&&e&&(this.disconnectLineFromShape(t,i),this.connectLineToShape(e,t,i,n),this.moveLineWithShape(e,t.id,null))},SVGRenderer.prototype.connectLineToShape=function(e,t,i,n){if(e&&t&&!(n<0)){var o=E2DGlobals.e2d;if(o.hasShapeConnectionPoint(e,n)){o.insertedShapes.getShapeById(t.id).addLineConnection(i,e.id,n);var s=o.insertedShapes.getShapeById(e.id);s&&s.addShapeConnection(i,t.id,this.getConnectorType(t),n)}}},SVGRenderer.prototype.disconnectLineFromShape=function(e,t){if(e){var i=E2DGlobals.e2d,n=i.insertedShapes.getShapeById(e.id);if(n){var o=n.lineConnections[t];if(o.shapeID&&o.shapeID.length>0){var s=i.insertedShapes.getShapeById(o.shapeID);s&&s.removeShapeConnection(t,e.id,o.pointID)}o.shapeID="",o.pointID=""}}},SVGRenderer.prototype.getOrthoLineCenterSegment=function(e){var t=this.getShapeSubject(e).points,i=Math.round(t.numberOfItems/2-1),n=t.getItem(i),o=t.getItem(i-1),s=t.getItem(i+1),r=(n.y-o.y)*(n.y-o.y)+(n.x-o.x)*(n.x-o.x)>(n.y-s.y)*(n.y-s.y)+(n.x-s.x)*(n.x-s.x)?o:s;return{x:r.x,y:r.y,x2:n.x,y2:n.y}},SVGRenderer.prototype.drawOrthoLine=function(e,t,i,n,o){var s=this.calculateOrthoLinePath(e,t,i,n,o);this.getShapeSubject(e).setAttributeNS(null,"points",s)},SVGRenderer.prototype.calculateOrthoLinePath=function(e,t,i,n,o){var s=this.getClearancePoints(e,t,i,n,o,"from"),r=this.getClearancePoints(e,n,o,s[s.length-1].x,s[s.length-1].y,"to"),a=s[s.length-1].x,l=(s[s.length-1].y,r[r.length-1].x,r[r.length-1].y);s[s.length]={x:a,y:l};for(var h=r.length-1;h>=0;h--)s[s.length]=r[h];for(var d=[],c=0,u=s.length;c<u;c++)d[d.length]=s[c].x+","+s[c].y;return d.join(" ")},SVGRenderer.prototype.getClearancePoints=function(e,t,i,n,o,s){var r={x:t,y:i},a=[r],l=E2DGlobals.e2d.insertedShapes.getConnectionShape(e.id,s),h=document.getElementById(l.shapeID);if(!h)return a;r={};var d=this.bounds(h),c=Math.abs(i-o)/2,u=this.getConnectionPointLocation(h,l.pointID,d),p=(parseInt(d.rotation/90)+1*u)%4;0===p?(c<12&&(c=12),r.y=a[a.length-1].y-12,r.x=a[a.length-1].x):2===p?(c<12&&(c=12),r.y=a[a.length-1].y+12,r.x=a[a.length-1].x):1===p?(c<12&&(c=12),r.x=a[a.length-1].x+12,r.y=a[a.length-1].y):3===p&&(c<12&&(c=12),r.x=a[a.length-1].x-12,r.y=a[a.length-1].y),a[a.length]=r;var g={},y=this.getRotatedClearancePoints(d,u,12);return 0===p&&r.y<o?(g.x=n<t?n>1*y[0].x-12?n:1*y[0].x-12:n<1*y[1].x+12?n:1*y[1].x+12,g.y=r.y,a[a.length]=g):2===p&&r.y>o?(g.x=n<t?n>1*y[1].x-12?n:1*y[1].x-12:n<1*y[0].x+12?n:1*y[0].x+12,g.y=r.y,a[a.length]=g):1===p&&r.x>n?(g.y=o<i?o>1*y[0].y-12?o:1*y[0].y-12:o<1*y[1].y+12?o:1*y[1].y+12,g.x=r.x,a[a.length]=g):3===p&&r.x<n&&(g.y=o<i?o>1*y[1].y-12?o:1*y[1].y-12:o<1*y[0].y+12?o:1*y[0].y+12,g.x=r.x,a[a.length]=g),a},SVGRenderer.prototype.isPointInCorners=function(e,t){var i=this.getRotatedPoint(t.x,t.y,t);return!!E2DUtils.isPointTooClose(e,i,1)||(i=this.getRotatedPoint(t.x+t.width,t.y,t),!!E2DUtils.isPointTooClose(e,i,1)||(i=this.getRotatedPoint(t.x,t.y+t.height,t),!!E2DUtils.isPointTooClose(e,i,1)||(i=this.getRotatedPoint(t.x+t.width,t.y+t.height,t),!!E2DUtils.isPointTooClose(e,i,1))))},SVGRenderer.prototype.isConnectionPointWithXY=function(e){return this.isConnectionPointWithX(e)||this.isConnectionPointWithY(e)},SVGRenderer.prototype.isConnectionPointWithX=function(e){var t="number"==typeof e.xStep&&e.xStep>0||"string"==typeof e.xStep&&""!==e.xStep&&"0"!==e.xStep,i="number"==typeof e.xMin&&e.xMin>0||"string"==typeof e.xMin&&""!==e.xMin&&"0"!==e.xMin,n="number"==typeof e.xMax&&e.xMax>0||"string"==typeof e.xMax&&""!==e.xMax&&"0"!==e.xMax;return t||i||n},SVGRenderer.prototype.isConnectionPointWithY=function(e){var t="number"==typeof e.yStep&&e.yStep>0||"string"==typeof e.yStep&&""!==e.yStep&&"0"!==e.yStep,i="number"==typeof e.yMin&&e.yMin>0||"string"==typeof e.yMin&&""!==e.yMin&&"0"!==e.yMin,n="number"==typeof e.yMax&&e.yMax>0||"string"==typeof e.yMax&&""!==e.yMax&&"0"!==e.yMax;return t||i||n},SVGRenderer.prototype.isConnectionPointWithZ=function(e){var t="number"==typeof e.zSpot&&e.zSpot>0,i="number"==typeof e.zStep&&e.zStep>0||"string"==typeof e.zStep&&""!==e.zStep&&"0"!==e.zStep,n="number"==typeof e.zMin&&e.zMin>0||"string"==typeof e.zMin&&""!==e.zMin&&"0"!==e.zMin,o="number"==typeof e.zMax&&e.zMax>0||"string"==typeof e.zMax&&""!==e.zMax&&"0"!==e.zMax;return t||i||n||o},SVGRenderer.prototype.isCommonLinkClassWithXY=function(e,t){return this.isCommonLinkClassWithX(e,t)||this.isCommonLinkClassWithY(e,t)},SVGRenderer.prototype.isCommonLinkClassWithX=function(e,t){var i=E2DGlobals.e2d.getCommonLinkClassObj(e,t);if(!i)return!1;var n="number"==typeof i.xStep&&i.xStep>0||"string"==typeof i.xStep&&""!==i.xStep&&"0"!==i.xStep,o="number"==typeof i.xMin&&i.xMin>0||"string"==typeof i.xMin&&""!==i.xMin&&"0"!==i.xMin,s="number"==typeof i.xMax&&i.xMax>0||"string"==typeof i.xMax&&""!==i.xMax&&"0"!==i.xMax;return n||o||s},SVGRenderer.prototype.isCommonLinkClassWithY=function(e,t){var i=E2DGlobals.e2d.getCommonLinkClassObj(e,t);if(!i)return!1;var n="number"==typeof i.yStep&&i.yStep>0||"string"==typeof i.yStep&&""!==i.yStep&&"0"!==i.yStep,o="number"==typeof i.yMin&&i.yMin>0||"string"==typeof i.yMin&&""!==i.yMin&&"0"!==i.yMin,s="number"==typeof i.yMax&&i.yMax>0||"string"==typeof i.yMax&&""!==i.yMax&&"0"!==i.yMax;return n||o||s},SVGRenderer.prototype.isCommonLinkClassWithZ=function(e,t){var i=E2DGlobals.e2d.getCommonLinkClassObj(e,t);if(!i)return!1;var n="number"==typeof i.zStep&&i.zStep>0||"string"==typeof i.zStep&&""!==i.zStep&&"0"!==i.zStep,o="number"==typeof i.zMin&&i.zMin>0||"string"==typeof i.zMin&&""!==i.zMin&&"0"!==i.zMin,s="number"==typeof i.zMax&&i.zMax>0||"string"==typeof i.zMax&&""!==i.zMax&&"0"!==i.zMax;return n||o||s},SVGRenderer.prototype.getConnectionPointObj=function(e,t,i,n){var o=1*i.x+t.x/this.COORD_X*i.width,s=1*i.y+t.y/this.COORD_Y*i.height,r=1*i.z+t.z/this.COORD_Z*i.depth;if(n){var a=this.getSubConnectionPointPosition(o,s,r,t,i,n);o=a.x,s=a.y,r=a.z}var l=this.getRotatedPoint(o,s,i);return{id:e+"--"+t.id,shapeId:e,cpId:t.id,x:l.x,y:l.y,z:r,noRX:o,noRY:s,noRZ:r,xMin:t.xMin,xMax:t.xMax,xStep:t.xStep,yMin:t.yMin,yMax:t.yMax,yStep:t.yStep,zMin:t.zMin,zMax:t.zMax,zStep:t.zStep,zSpot:t.z,direction:t.direction,linkClass:t.linkClass,isDimension:t.isDimension,label:t.label}},SVGRenderer.prototype.getConnectionPointObjByPointId=function(e,t){if(this.isPolyline(e)){"from"===t?t=0:"to"===t?t=this.getPolylineNumberOfPoints(e)-1:t*=1;var i=this.getPolylinePoint(e,t);return i?{id:e.id+"--"+t,shapeId:e.id,cpId:t,x:i.x,y:i.y,z:0}:null}var n=E2DGlobals.e2d.getLibraryProperties(e.id);if(!n||!n.connectionPoints||0===n.connectionPoints.length)return null;for(var o=null,s=this.bounds(e),r=t.split("__"),a=0,l=n.connectionPoints.length;a<l;a++)if(n.connectionPoints[a].id===r[0]){o=n.connectionPoints[a];break}if(!o){var h=parseInt(r[0]);isNaN(h)||(o=n.connectionPoints[h])}var d,c=null;o&&(r.length>=2&&(d=r[1]),c=this.getConnectionPointObj(e.id,o,s,d));return c},SVGRenderer.prototype.getConnectionPointObjs=function(e,t){var i=[],n=E2DGlobals.e2d.getLibraryProperties(e.id);if(!n||!n.connectionPoints||0===n.connectionPoints.length)return i;for(var o=this.bounds(e),s=0,r=n.connectionPoints.length;s<r;s++){var a=this.getConnectionPointObj(e.id,n.connectionPoints[s],o);t&&!a.isDimension||(i[i.length]=a)}return i},SVGRenderer.prototype.getSubConnectionPointObjs=function(e,t,i,n){var o,s=E2DGlobals.e2d,r=this.bounds(e),a=0,l=0,h=0,d=0,c=0,u=0;if(this.isCommonLinkClassWithXY(i,n)){var p=s.getCommonLinkClassObj(i,n);a=p.xMin?p.xMin:0,l=p.xMax?p.xMax:0,h=p.xStep?p.xStep:0,d=p.yMin?p.yMin:0,c=p.yMax?p.yMax:0,u=p.yStep?p.yStep:0}else this.isConnectionPointWithXY(t)&&(a=t.xMin?t.xMin:0,l=t.xMax?t.xMax:0,h=t.xStep?t.xStep:0,d=t.yMin?t.yMin:0,c=t.yMax?t.yMax:0,u=t.yStep?t.yStep:0);a=Math.abs(s.getValueOrEvaluateFormula(a,r)),l=Math.abs(s.getValueOrEvaluateFormula(l,r)),h=Math.abs(s.getValueOrEvaluateFormula(h,r)),l=0===l?r.width:l,a*=s.scale,l*=s.scale,h*=s.scale,d=Math.abs(s.getValueOrEvaluateFormula(d,r)),c=Math.abs(s.getValueOrEvaluateFormula(c,r)),u=Math.abs(s.getValueOrEvaluateFormula(u,r)),c=0===c?r.height:c,d*=s.scale,c*=s.scale,u*=s.scale;var g,y,f=[];if(h>0&&u>0)for(var v=Math.floor((l-a)/h),m=Math.floor((c-d)/u),S=0;S<=v;S++)for(var E=0;E<=m;E++)g={x:t.noRX+a+S*h,y:t.noRY+d+E*u},y=this.getSubConnectionPointObj(t.cpId+"__x"+S+"y"+E,g,t,r),f[f.length]=y;else if(h>0){o=Math.floor((l-a)/h);for(var D=0;D<=o;D++)g={x:t.noRX+a+D*h,y:t.noRY},y=this.getSubConnectionPointObj(t.cpId+"__x"+D,g,t,r),f[f.length]=y}else if(u>0){o=Math.floor((c-d)/u);for(var b=0;b<=o;b++)g={x:t.noRX,y:t.noRY+d+b*u},y=this.getSubConnectionPointObj(t.cpId+"__y"+b,g,t,r),f[f.length]=y}return f},SVGRenderer.prototype.getSubConnectionPointObj=function(e,t,i,n){var o=this.getRotatedPoint(t.x,t.y,n),s=E2DUtils.cloneObject(i);return s.id=i.shapeId+"--"+e,s.cpId=e,s.x=o.x,s.y=o.y,s},SVGRenderer.prototype.getSubConnectionPointPosition=function(e,t,i,n,o,s){const r={x:e,y:t,z:i},a=s.indexOf("x"),l=s.indexOf("y"),h=s.indexOf("z"),d=-1!==a?1*s.substring(a+1,-1!==l?l:void 0):0,c=-1!==l?1*s.substring(l+1,-1!==h?h:void 0):0,u=-1!==h?1*s.substring(h+1):0,p=E2DGlobals.e2d,g=p.getValueOrEvaluateFormula(n.xMin,o)*p.scale,y=p.getValueOrEvaluateFormula(n.xStep,o)*p.scale,f=p.getValueOrEvaluateFormula(n.yMin,o)*p.scale,v=p.getValueOrEvaluateFormula(n.yStep,o)*p.scale,m=p.getValueOrEvaluateFormula(n.zMin,o)*p.scale,S=p.getValueOrEvaluateFormula(n.zStep,o)*p.scale;return y>0&&(r.x+=g+d*y),v>0&&(r.y+=f+c*v),S>0&&(r.z+=m+u*S),r},SVGRenderer.prototype.getOverlappingConnectionPointObjs=function(e,t,i,n,o){n=n||1;var s=[],r=document.getElementById(e);if(!r)return s;var a=E2DGlobals.e2d.getLibraryProperties(e);if(!a||!a.connectionPoints||0===a.connectionPoints.length)return s;for(var l=null,h=[],d=this.bounds(r),c=t.split("__"),u=0,p=a.connectionPoints.length;u<p;u++)if(!i||a.connectionPoints[u].isDimension){var g=this.getConnectionPointObj(r.id,a.connectionPoints[u],d,c[1]);h[h.length]=g,g.cpId===c[0]&&(l=g)}if(!l)return s;for(var y=0,f=h.length;y<f;y++)o&&E2DUtils.isPointTooClose(l,h[y],o)||E2DUtils.isPointTooClose(l,h[y],n)&&(s[s.length]=h[y]);return s},SVGRenderer.prototype.getConnectionPointLocation=function(e,t,i){var n=this.getConnectionPointObjByPointId(e,t);return n.x<1*i.x+i.width/2?3:n.x>1*i.x+i.width/2?1:n.y<=i.y?0:2},SVGRenderer.prototype.getRotatedClearancePoints=function(e,t,i){var n=[{},{}];return 0===t?(n[0].x=e.x,n[0].y=e.y,n[1].x=1*e.x+1*e.width,n[1].y=e.y):1===t?(n[0].x=1*e.x+1*e.width,n[0].y=e.y,n[1].x=1*e.x+1*e.width,n[1].y=1*e.y+1*e.height):2===t?(n[0].x=1*e.x+1*e.width,n[0].y=1*e.y+1*e.height,n[1].x=1*e.x,n[1].y=1*e.y+1*e.height):(n[0].x=1*e.x,n[0].y=1*e.y+1*e.height,n[1].x=1*e.x,n[1].y=1*e.y),n},SVGRenderer.prototype.startPolyline=function(e,t,i){var n=this.getShapeSubject(e);n.setAttributeNS(null,"points",t+","+i+" "+t+","+i),this.enableFloor&&n.setAttributeNS(null,"fill",this.floorDefinition.color?this.floorDefinition.color:"url(#imgFloor)")},SVGRenderer.prototype.drawPolyline=function(e,t,i,n){var o=this.getShapeSubject(e),s=this.isPolylineClosed(e),r=o.points.numberOfItems-1,a=n?0:r,l=o.points.getItem(a);if(l.x=t,l.y=i,s&&a===r){var h=this.getPolylineFirstPoint(e);h.x=l.x,h.y=l.y}},SVGRenderer.prototype.closePolylineSegment=function(e,t,i,n){if(e){var o=this.getShapeSubject(e),s=o.points.getItem(o.points.numberOfItems-1);if(s.x=t,s.y=i,n){var r=o.ownerSVGElement.createSVGPoint();r.x=t,r.y=i,o.points.appendItem(r)}}},SVGRenderer.prototype.finishPolyline=function(e){var t=this.getShapeSubject(e);t.points.removeItem(t.points.numberOfItems-1)},SVGRenderer.prototype.undoPolylineLastSegment=function(e){var t=this.getShapeSubject(e);t.points.numberOfItems>=2&&t.points.removeItem(t.points.numberOfItems-2)},SVGRenderer.prototype.closePolyline=function(e){var t=this.getShapeSubject(e),i=t.points.getItem(0),n=t.points.getItem(t.points.numberOfItems-1);n.x=i.x,n.y=i.y},SVGRenderer.prototype.movePolyline=function(e,t,i,n){var o=this.getShapeSubject(e);o.points.clear();for(var s=0,r=t.points.length;s<r;s++){var a=t.points[s],l=o.ownerSVGElement.createSVGPoint();l.x=1*a.x+1*i,l.y=1*a.y+1*n,o.points.appendItem(l)}},SVGRenderer.prototype.movePolylinePoint=function(e,t,i,n){var o=this.getShapeSubject(e);if((t=-1===t?o.points.numberOfItems-1:t)<o.points.numberOfItems){var s=o.points.getItem(t);s.x=i,s.y=n}},SVGRenderer.prototype.updatePolyline=function(e,t,i,n,o){var s,r,a;n?(i=E2DUtils.deg2rad(i),s=t*Math.cos(i),r=t*Math.sin(i),a=this.getPolylinePoint(e,1),this.setPolylineFirstPoint(e,a.x+s,a.y+r)):(i=E2DUtils.deg2rad(i),s=t*Math.cos(i),r=t*Math.sin(i),a=this.getPolylineLastClosedPoint(e),this.closePolylineSegment(e,a.x+s,a.y+r,o))},SVGRenderer.prototype.updatePolylinePoint=function(e,t,i,n){n=E2DUtils.deg2rad(n);var o=i*Math.cos(n),s=i*Math.sin(n),r=this.getShapeSubject(e),a=this.isPolylineClosed(e),l=r.points.getItem(t-1),h=r.points.getItem(t),d=null,c=h.x,u=h.y;h.x=l.x+o,h.y=l.y+s,a&&t===this.getPolylineNumberOfPoints(e)-1&&((d=this.getPolylineFirstPoint(e)).x=h.x,d.y=h.y);var p=t+1,g=h.x-c,y=h.y-u,f=this.getPolylinePoint(e,p);f&&(f.x+=g,f.y+=y,a&&p===this.getPolylineNumberOfPoints(e)-1&&((d=this.getPolylineFirstPoint(e)).x=f.x,d.y=f.y))},SVGRenderer.prototype.addPolylinePoint=function(e,t,i,n){var o=this.getShapeSubject(e),s=o.points,r=o.ownerSVGElement.createSVGPoint();r.x=i,r.y=n,-1===t?s.appendItem(r):t<s.numberOfItems&&s.insertItemBefore(r,t)},SVGRenderer.prototype.addPolylineMiddlePoint=function(e,t,i){t*=1,i*=1;var n=this.getShapeSubject(e),o=n.points;if(t<o.numberOfItems&&i<o.numberOfItems){var s=o.getItem(t),r=o.getItem(i),a=E2DUtils.midpointOfLineEx(s,r),l=n.ownerSVGElement.createSVGPoint();l.x=a.x,l.y=a.y,o.insertItemBefore(l,i),this.updateTracker(e,[t,i])}},SVGRenderer.prototype.removePolylinePoint=function(e,t){t*=1;var i=this.getShapeSubject(e).points;0<=t&&t<i.numberOfItems&&(i.removeItem(t),t>0&&this.updateTracker(e,[t-1,t]))},SVGRenderer.prototype.removePolylineSegment=function(e,t,i){t*=1,i*=1;var n=this.getShapeSubject(e).points;if(t<i&&0<=t&&t<n.numberOfItems&&0<=i&&i<n.numberOfItems){for(var o=null,s=[],r=i;r<n.numberOfItems;r++)o=n.getItem(r),E2DUtils.isPointInList(o,s)||(s[s.length]=o);for(var a=0;a<=t;a++)o=n.getItem(a),E2DUtils.isPointInList(o,s)||(s[s.length]=o);n.clear();for(var l=0;l<s.length;l++)n.appendItem(s[l])}},SVGRenderer.prototype.splitPolylineBySegment=function(e,t,i){t*=1,i*=1;var n=this.getShapeSubject(e).points,o=[];if(t<i&&0<=t&&t<n.numberOfItems&&0<=i&&i<n.numberOfItems){for(var s=[],r=null,a=i;a<n.numberOfItems;a++)r=n.getItem(a),E2DUtils.isPointInList(r,s)||(s[s.length]=r);o[0]=s;for(var l=[],h=0;h<=t;h++)r=n.getItem(h),E2DUtils.isPointInList(r,l)||(l[l.length]=r);o[1]=l}return o},SVGRenderer.prototype.joinPolylines=function(e,t,i,n){var o=this.getPolylinePoints(e),s=this.getPolylinePoints(t),r=this.getShapeSubject(e),a=null,l=r.points;if(l.clear(),i)for(var h=0,d=o.length-1;h<d;h++)(a=r.ownerSVGElement.createSVGPoint()).x=o[h].x,a.y=o[h].y,l.appendItem(a);else for(var c=o.length-1;c>0;c--)(a=r.ownerSVGElement.createSVGPoint()).x=o[c].x,a.y=o[c].y,l.appendItem(a);if(n)for(var u=0,p=s.length;u<p;u++)(a=r.ownerSVGElement.createSVGPoint()).x=s[u].x,a.y=s[u].y,l.appendItem(a);else for(var g=s.length-1;g>=0;g--)(a=r.ownerSVGElement.createSVGPoint()).x=s[g].x,a.y=s[g].y,l.appendItem(a)},SVGRenderer.prototype.reversePolylinePoints=function(e){var t=this.getPolylinePoints(e),i=this.getShapeSubject(e),n=i.points;n.clear();for(var o=t.length-1;o>=0;o--){var s=i.ownerSVGElement.createSVGPoint();s.x=t[o].x,s.y=t[o].y,n.appendItem(s)}},SVGRenderer.prototype.isPolylineClosed=function(e){var t=this.getShapeSubject(e).points;if(t.numberOfItems<3)return!1;var i=t.getItem(0),n=t.getItem(t.numberOfItems-1);return E2DUtils.isPointTooClose(i,n,1e-4)},SVGRenderer.prototype.isPolylineSegmentSelected=function(e){var t=document.getElementById("resize-from"),i=document.getElementById("resize-to"),n=t.hasAttributeNS(null,"plPoint"),o=i.hasAttributeNS(null,"plPoint");return n&&o},SVGRenderer.prototype.getPolylinePoints=function(e){var t=this.getShapeSubject(e).points,i=[];if(t&&t.numberOfItems>0)for(var n=0,o=t.numberOfItems;n<o;n++){var s=t.getItem(n);i[i.length]={x:1*s.x,y:1*s.y}}return i},SVGRenderer.prototype.setPolylinePoints=function(e,t){var i=this.getShapeSubject(e);if(i.points.clear(),t&&t.length>0)for(var n=0,o=t.length;n<o;n++){var s=i.ownerSVGElement.createSVGPoint();s.x=t[n].x,s.y=t[n].y,i.points.appendItem(s)}},SVGRenderer.prototype.getPolylineConnectionPointObjs=function(e){var t=[],i=this.getPolylinePoints(e);if(i&&i.length>0){var n=0;t[n]={id:e.id+"--from",x:i[n].x,y:i[n].y};var o=i.length-1;for(n=1;n<o;n++)t[n]={id:e.id+"--"+n,x:i[n].x,y:i[n].y};t[n=i.length-1]={id:e.id+"--to",x:i[n].x,y:i[n].y}}return t},SVGRenderer.prototype.getPolylineSegment=function(e,t,i){for(var n=this.getShapeSubject(e).points,o={x:t,y:i},s=0;s<n.numberOfItems-1;s++){var r=n.getItem(s),a=n.getItem(s+1);if(E2DUtils.isPointInLine(o,r,a,2))return[s,s+1]}return null},SVGRenderer.prototype.getPolylineSelectedSegment=function(e){var t=[],i=document.getElementById("resize-from");i.hasAttributeNS(null,"plPoint")&&(t[t.length]=1*i.getAttributeNS(null,"plPoint"));var n=document.getElementById("resize-to");return n.hasAttributeNS(null,"plPoint")&&(t[t.length]=1*n.getAttributeNS(null,"plPoint")),t},SVGRenderer.prototype.getPolylineSegmentInfo=function(e,t){var i=this.getShapeSubject(e).points,n=i.getItem(t-1),o=i.getItem(t);return{x1:n.x,y1:n.y,x2:o.x,y2:o.y,length:E2DUtils.getSegmentLength(n.x,n.y,o.x,o.y),rotation:E2DUtils.getSegmentRotation(n.x,n.y,o.x,o.y)}},SVGRenderer.prototype.getPolylineNumberOfPoints=function(e){return this.getShapeSubject(e).points.numberOfItems},SVGRenderer.prototype.getPolylinePoint=function(e,t){if(null===t||void 0===t)return null;if("number"!=typeof(t*=1))return null;var i=this.getShapeSubject(e);return(t=-1===t?i.points.numberOfItems-1:t)<i.points.numberOfItems?i.points.getItem(t):this.isPolylineClosed(e)?i.points.getItem(1):null},SVGRenderer.prototype.setPolylinePoint=function(e,t,i,n){var o=this.getShapeSubject(e).points.getItem(t);o.x=i,o.y=n},SVGRenderer.prototype.getPolylineFirstPoint=function(e){return this.getPolylinePoint(e,0)},SVGRenderer.prototype.setPolylineFirstPoint=function(e,t,i){this.setPolylinePoint(e,0,t,i)},SVGRenderer.prototype.getPolylineLastClosedPoint=function(e){var t={},i=this.getShapeSubject(e),n=i.points.getItem(i.points.numberOfItems-2);return t.x=n.x,t.y=n.y,t},SVGRenderer.prototype.getPolylineLastPoint=function(e){var t={},i=this.getShapeSubject(e),n=i.points.getItem(i.points.numberOfItems-1);return t.x=n.x,t.y=n.y,t},SVGRenderer.prototype.setPolylineColor=function(e,t){t&&this.getShapeSubject(e).setAttributeNS(null,"stroke",t)},SVGRenderer.prototype.setPolylineWidth=function(e,t){t&&this.getShapeSubject(e).setAttributeNS(null,"stroke-width",t)},SVGRenderer.prototype.getConnectorType=function(e){if(e){if(e.classList.contains("line"))return"line";if(e.classList.contains("curve-line"))return"curve-line";if(e.classList.contains("ortho-line"))return"ortho-line";if(e.classList.contains("smart-line"))return"smart-line";if(e.classList.contains("snap-line"))return"snap-line";if(e.classList.contains("poly-line"))return"poly-line";if(e.classList.contains("poly-quote"))return"poly-quote";if(e.classList.contains("link-line"))return"link-line";if(e.classList.contains("quote-line"))return"quote-line"}return""},SVGRenderer.prototype.getConnectorFrom=function(e){var t={x:-1,y:-1},i=this.getConnectorType(e);if(!i)return t;var n=this.getShapeSubject(e);if(!n)return t;if("line"===i||"link-line"===i||"smart-line"===i)t.x=1*n.getAttributeNS(null,"x1"),t.y=1*n.getAttributeNS(null,"y1");else if("curve-line"===i){var o=n.getPathData()[0];t.x=1*o.values[0],t.y=1*o.values[1]}else if("quote-line"===i&&n&&5===n.length)t.x=1*n[0].getAttributeNS(null,"x1"),t.y=1*n[0].getAttributeNS(null,"y1");else{var s=n.points;s.numberOfItems>0&&(t.x=1*s.getItem(0).x,t.y=1*s.getItem(0).y)}return isNaN(t.x)&&(t.x=0),isNaN(t.y)&&(t.y=0),t},SVGRenderer.prototype.getConnectorTo=function(e){var t={x:-1,y:-1},i=this.getConnectorType(e);if(!i)return t;var n=this.getShapeSubject(e);if(!n)return t;if("line"===i||"link-line"===i||"smart-line"===i)t.x=1*n.getAttributeNS(null,"x2"),t.y=1*n.getAttributeNS(null,"y2");else if("curve-line"===i){var o=n.getPathData()[1];t.x=1*o.values[4],t.y=1*o.values[5]}else if("quote-line"===i&&n&&5===n.length)t.x=1*n[2].getAttributeNS(null,"x1"),t.y=1*n[2].getAttributeNS(null,"y1");else{var s=n.points,r=s.numberOfItems;if(0===r)return null;t.x=1*s.getItem(r-1).x,t.y=1*s.getItem(r-1).y}return isNaN(t.x)&&(t.x=0),isNaN(t.y)&&(t.y=0),t},SVGRenderer.prototype.getAllShapes=function(e){for(var t=e.querySelectorAll("svg#SVG_ROOT > g"),i=[],n=0,o=t.length;n<o;n++)this.isConnector(t[n])||this.isPolyquote(t[n])||this.isSnapLine(t[n])||t[n].id===this.SVG_PAGE_ID||t[n].id===this.SVG_PAGE_GRID_ID||t[n].id===this.MULTIPLE_SELECTOR_DUMMY_ID||t[n].id===this.BACKGROUND_ID||t[n].id.indexOf("tracker")>=0||t[n].id.indexOf("resize-")>=0||t[n].id.indexOf("control")>=0||(i[i.length]=t[n]);return i},SVGRenderer.prototype.getAllConnectors=function(e,t){for(var i=[],n=[],o=0,s=(i=t?e.querySelectorAll("g."+t):e.querySelectorAll("svg#SVG_ROOT > g")).length;o<s;o++)this.isPolyquote(i[o])||this.isSnapLine(i[o])||this.isConnector(i[o])&&(n[n.length]=i[o]);return n},SVGRenderer.prototype.getAllConnectorsForShape=function(e){if(!e)return null;var t=[],i=E2DGlobals.e2d.insertedShapes.getShapeById(e.id);if(i&&i.shapeConnections&&i.shapeConnections.length>0)for(var n=i.shapeConnections,o=0,s=n.length;o<s;o++){var r=n[o],a=document.getElementById(r.lineID);a&&(t[t.length]=a)}return t},SVGRenderer.prototype.getAllLinkedShapes=function(e,t,i,n){var o=[];if(!e)return o;var s=this.bounds(e),r=this.getRotatedVerticesFromRect(s,0,0),a=E2DGlobals.e2d,l=a.insertedShapes.getShapeById(e.id);if(l&&l.shapeConnections&&l.shapeConnections.length>0)for(var h=l.shapeConnection,d=0,c=h.length;d<c;d++){var u=h[d],p=document.getElementById(u.lineID);if(p&&"link-line"===u.lineType){var g=null,y=a.insertedShapes.getConnectionShape(p.id,"from");y.shapeID&&y.shapeID!==e.id&&(g=y.shapeID);var f=a.insertedShapes.getConnectionShape(p.id,"to");if(f.shapeID&&f.shapeID!==e.id&&(g=f.shapeID),g){if(t){var v=document.getElementById(g),m=this.bounds(v),S=this.getRotatedVerticesFromRect(m,0,0);switch(t){case"T":case"TOP":if(!E2DUtils.isRectInLine(S,r[0],r[1],.1))continue;break;case"R":case"RIGHT":if(!E2DUtils.isRectInLine(S,r[1],r[2],.1))continue;break;case"B":case"BOTTOM":if(!E2DUtils.isRectInLine(S,r[2],r[3],.1))continue;break;case"L":case"LEFT":if(!E2DUtils.isRectInLine(S,r[3],r[0],.1))continue}}if(i){var E=a.insertedShapes.getShapeById(g);if(E&&E.group!==i)continue}n&&(o[o.length]=u.lineID),o[o.length]=g}}}return o},SVGRenderer.prototype.getAllPolylines=function(e){for(var t=e.querySelectorAll("svg#SVG_ROOT > g"),i=[],n=0,o=t.length;n<o;n++)this.isPolyline(t[n])&&(i[i.length]=t[n]);return i},SVGRenderer.prototype.validateQuote=function(e,t,i,n){if(!this.isQuoteLine(e))return;var o=E2DGlobals.e2d,s=this.getShapeSubject(e),r=this.getQuoteType(e),a=null,l=this.getConnectorFrom(e),h=o.insertedShapes.getConnectionShape(e.id,"from");if(h.shapeID&&h.pointID){var d=document.getElementById(h.shapeID);d&&(a=this.getConnectionPointObjByPointId(d,h.pointID))}var c=null,u=this.getConnectorTo(e),p=o.insertedShapes.getConnectionShape(e.id,"to");if(p.shapeID&&p.pointID){var g=document.getElementById(p.shapeID);g&&(c=this.getConnectionPointObjByPointId(g,p.pointID))}var y=this.getQuoteStack(e),f=!1;!a||a.x===l.x&&a.y===l.y||(h.shapeID===t?(f=!0,s[0].setAttributeNS(null,"x1",a.x),s[0].setAttributeNS(null,"y1",a.y)):1===r?(i&&!E2DUtils.isAlmostZero(i.delta.x)&&(f=!0,s[0].setAttributeNS(null,"x1",a.x)),s[0].setAttributeNS(null,"y1",a.y)):2===r&&(s[0].setAttributeNS(null,"x1",a.x),n&&!E2DUtils.isAlmostZero(n.delta.y)&&(f=!0,s[0].setAttributeNS(null,"y1",a.y))));var v=!1;if(!c||c.x===u.x&&c.y===u.y||(p.shapeID===t?(v=!0,s[2].setAttributeNS(null,"x1",c.x),s[2].setAttributeNS(null,"y1",c.y)):1===r?(i&&!E2DUtils.isAlmostZero(i.delta.x)&&(v=!0,s[2].setAttributeNS(null,"x1",c.x)),s[2].setAttributeNS(null,"y1",c.y)):2===r&&(s[2].setAttributeNS(null,"x1",c.x),n&&!E2DUtils.isAlmostZero(n.delta.y)&&(v=!0,s[2].setAttributeNS(null,"y1",c.y)))),!f&&!v)return;var m=f?a.x:l.x,S=f?a.y:l.y,E=v?c.x:u.x,D=v?c.y:u.y;switch(r){case 0:var b=E2DUtils.getPerpendicularPointsAtDistanceFromSegmentEndpoints(m,S,E,D,y);s[0].setAttributeNS(null,"x2",b[0].x),s[0].setAttributeNS(null,"y2",b[0].y),s[1].setAttributeNS(null,"x1",b[0].x),s[1].setAttributeNS(null,"y1",b[0].y),s[1].setAttributeNS(null,"x2",b[1].x),s[1].setAttributeNS(null,"y2",b[1].y),s[2].setAttributeNS(null,"x2",b[1].x),s[2].setAttributeNS(null,"y2",b[1].y);break;case 1:s[0].setAttributeNS(null,"x2",m),s[1].setAttributeNS(null,"x1",m),s[1].setAttributeNS(null,"x2",E),s[2].setAttributeNS(null,"x2",E);break;case 2:s[0].setAttributeNS(null,"y2",S),s[1].setAttributeNS(null,"y1",S),s[1].setAttributeNS(null,"y2",D),s[2].setAttributeNS(null,"y2",D)}const x=s[1].getAttributeNS(null,"x1"),I=s[1].getAttributeNS(null,"y1"),C=s[1].getAttributeNS(null,"x2"),T=s[1].getAttributeNS(null,"y2");s[3].setAttributeNS(null,"cx",x),s[3].setAttributeNS(null,"cy",I),s[4].setAttributeNS(null,"cx",C),s[4].setAttributeNS(null,"cy",T),this.updateQuoteValue(e),this.updateQuoteStack(e),o.updateIShape(e,this.bounds(e),"",!1)},SVGRenderer.prototype.validateLink=function(e){if(!this.isLinkLine(e))return;const t=E2DGlobals.e2d,i=t.insertedShapes.getConnectionShape(e.id,"from");if(!i.shapeID)return;const n=t.insertedShapes.getConnectionShape(e.id,"to");if(!n.shapeID)return;const o=document.getElementById(i.shapeID);if(!o)return;const s=document.getElementById(n.shapeID);if(!s)return;const r=this.bounds(o),a=this.bounds(s);let l=null;const h=t.getNewRotationForSnapToLink(o,i.shapeID,i.pointID,s,n.shapeID,n.pointID);"number"==typeof h&&(l=h-r.rotation,E2DUtils.isAlmostZero(l)||(this.setRotation(o,h),r.rotation=h));const d=this.getConnectionPointObjByPointId(o,i.pointID),c=this.getConnectionPointObjByPointId(s,n.pointID),u=this.isCommonLinkClassWithZ(d.linkClass,c.linkClass);if(this.isConnectionPointWithZ(c)||u){const e=t.getNewCoordsForSnapToZ(r,d,a,c);E2DUtils.areAlmostEqual(r.z,e)||(r.z=e,this.move(o,r.x,r.y,r.z),t.updateIShape(o,r,"",!1))}else if(this.isConnectionPointWithZ(d)||u){const e=t.getNewCoordsForSnapToZ(a,c,r,d);E2DUtils.areAlmostEqual(a.z,e)||(a.z=e,this.move(s,a.x,a.y,a.z),t.updateIShape(s,a,"",!1))}const p=c.x-d.x,g=c.y-d.y;E2DUtils.isAlmostZero(p)&&E2DUtils.isAlmostZero(g)&&E2DUtils.isAlmostZero(l)||(r.x+=p,r.y+=g,this.move(o,r.x,r.y,r.z),t.clearShapeText(o),t.resetShapeText(o),t.updateIShape(o,r,"",!1),t.moveShapeDependencies(o,p,g,0,l,[e.id,s.id]))},SVGRenderer.prototype.joinSmartLines=function(e,t,i){var n=E2DGlobals.e2d,o=n.insertedShapes.getConnectionShape(e.id,"from"),s=document.getElementById(o.shapeID),r=n.insertedShapes.getConnectionShape(e.id,"to"),a=document.getElementById(r.shapeID);if(s||a){var l=n.insertedShapes.getConnectionShape(t.id,"from"),h=document.getElementById(l.shapeID),d=n.insertedShapes.getConnectionShape(t.id,"to"),c=document.getElementById(d.shapeID);if(h||c){var u=o.shapeID,p=o.pointID,g=r.shapeID,y=o.pointID,f=l.shapeID,v=l.pointID,m=d.shapeID,S=l.pointID;n.clearConnectionPoints(),n.hideSmartLineMiddleConnectionPoints(e),n.hideSmartLineMiddleConnectionPoints(t),this.disconnectLineFromShape(e,"from"),this.disconnectLineFromShape(e,"to"),this.remove(e),n.insertedShapes.removeShape(e),this.disconnectLineFromShape(t,"from"),this.disconnectLineFromShape(t,"to"),this.remove(t),n.insertedShapes.removeShape(t),this.createLine(n.shapeLibraryList[0],"smart-line",0,0).done(function(n){E2DGlobals.e2d.renderer.joinSmartLinesAsync(n,e,u,p,g,y,t,f,v,m,S,i)})}}},SVGRenderer.prototype.joinSmartLinesAsync=function(e,t,i,n,o,s,r,a,l,h,d,c){e.setAttribute("id","connector_"+E2DUtils.createUUID());var u=E2DGlobals.e2d;u.addNewShapeListeners(e);var p=InsertedShape.CreateShapeFromConnector(e);u.insertedShapes.addShape(p,!0);var g=document.getElementById(i),y=document.getElementById(o);g?this.connectLine(g,e,"from",n):y&&this.connectLine(y,e,"from",s);var f=document.getElementById(a),v=document.getElementById(h);f?this.connectLine(f,e,"to",l):v&&this.connectLine(v,e,"to",d),c||(u.showConnectionPoints(),u.showSmartLineMiddleConnectionPoints())},SVGRenderer.prototype.replaceSmartLineWithSmartLineHub=function(e,t,i,n,o){var s=E2DGlobals.e2d;s.hideSmartLineMiddleConnectionPoints();var r=s.insertedShapes.getConnectionShape(t.id,"from"),a=r.shapeID,l=r.pointID,h=s.insertedShapes.getConnectionShape(t.id,"to"),d=h.shapeID,c=h.pointID,u=this.getConnectorFrom(t),p=this.getConnectorTo(t);this.disconnectLineFromShape(t,"from"),this.disconnectLineFromShape(t,"to"),this.remove(t),s.insertedShapes.removeShape(t);var g=24*s.scale,y=s.convertGraphPointToUserPoint(i),f=s.convertGraphDataToUserData(g),v=s.convertGraphPointToUserPoint(u),m=s.convertGraphPointToUserPoint(p),S=InsertedShape.CreateShape(s.shapeLibraryList[0],"smart-line-hub","smartHub_"+E2DUtils.createUUID(),"Hub","","Hub",y.x,y.y,0,f,f,0,0,"","(NOSTRETCH)(NOROTATE)(ORIGIN=CENTER)",""),E=InsertedShape.CreateShape(s.shapeLibraryList[0],"smart-line","connector_"+E2DUtils.createUUID(),"","","",v.x,v.y,0,v.x,v.y,0,0,"","",""),D=InsertedShape.CreateShape(s.shapeLibraryList[0],"smart-line","connector_"+E2DUtils.createUUID(),"","","",m.x,m.y,0,m.x,m.y,0,0,"","",""),b=this;$.when(s.createNewShape(S),s.createNewConnector(E),s.createNewConnector(D)).done(function(t,s,r){b.replaceSmartLineWithSmartLineHubAsync(t,s,r,e,i,n,a,l,d,c,o)})},SVGRenderer.prototype.replaceSmartLineWithSmartLineHubAsync=function(e,t,i,n,o,s,r,a,l,h,d){var c=E2DGlobals.e2d;c.unselect(),this.connectLine(e,n,s,"cp1");var u=document.getElementById(r);this.connectLine(u,t,"from",a),this.connectLine(e,t,"to","cp1");var p=document.getElementById(l);this.connectLine(p,i,"from",h),this.connectLine(e,i,"to","cp1"),c.selected=n,c.select(n),c.setMode(c.mode),d&&c.container.on("vmousemove",E2DEvents.onDraw)},SVGRenderer.prototype.getLineOpacity=function(e){if(!e)return"1.0";var t=this.getShapeSubject(e);return t.length>0?t[0].getAttributeNS(null,"stroke-opacity"):t.getAttributeNS(null,"stroke-opacity")},SVGRenderer.prototype.setLineOpacity=function(e,t){if(e&&t)if(this.isConnector(e)){var i=this.getShapeSubject(e);if(i.length>0)for(var n=0,o=i.length;n<o;n++)i[n].setAttributeNS(null,"stroke-opacity",t);else i.setAttributeNS(null,"stroke-opacity",t)}else for(var s=this.getAllSubShapes(e),r=0,a=s.length;r<a;r++)s[r].setAttributeNS(null,"stroke-opacity",t)},SVGRenderer.prototype.getLineWidth=function(e){if(!e)return"2px";var t=this.getShapeSubject(e);return t.length>0?t[0].getAttributeNS(null,"stroke-width"):t.getAttributeNS(null,"stroke-width")},SVGRenderer.prototype.setLineWidth=function(e,t){if(e&&t)if(this.isConnector(e)){var i=this.getShapeSubject(e);if(i.length>0)for(var n=0,o=i.length;n<o;n++)i[n].setAttributeNS(null,"stroke-width",t);else i.setAttributeNS(null,"stroke-width",t)}else for(var s=this.getAllSubShapes(e),r=0,a=s.length;r<a;r++)s[r].setAttributeNS(null,"stroke-width",t)},SVGRenderer.prototype.getLineColor=function(e){if(!e)return"#000000";var t=this.getShapeSubject(e);return t.length>0?t[0].getAttributeNS(null,"stroke"):t.getAttributeNS(null,"stroke")},SVGRenderer.prototype.setLineColor=function(e,t){if(e&&t)if(this.isConnector(e)){var i=this.getShapeSubject(e);if(i.length>0)for(var n=0,o=i.length;n<o;n++)i[n].setAttributeNS(null,"stroke",t);else i.setAttributeNS(null,"stroke",t)}else for(var s=this.getAllSubShapes(e),r=0,a=s.length;r<a;r++)s[r].setAttributeNS(null,"stroke",t)},SVGRenderer.prototype.getFillOpacity=function(e){return this.isImage(e)?this.getShapeSubject(e).getAttributeNS(null,"opacity"):this.getShapeSubject(e).getAttributeNS(null,"fill-opacity")},SVGRenderer.prototype.setFillOpacity=function(e,t){if(e&&(t&&!this.isConnector(e)))if(e.getElementsByTagName("image").length>0)this.getShapeSubject(e).setAttributeNS(null,"opacity",t);else for(var i=this.getAllSubShapes(e),n=0,o=i.length;n<o;n++)i[n].setAttributeNS(null,"fill-opacity",t)},SVGRenderer.prototype.getFillColor=function(e){return this.isConnector(e)?null:this.getShapeSubject(e).getAttributeNS(null,"fill")},SVGRenderer.prototype.setFillColor=function(e,t){if(e&&t&&!this.isConnector(e))for(var i=this.getAllSubShapes(e),n=0,o=i.length;n<o;n++)i[n].setAttributeNS(null,"fill",t),0==i[n].getAttributeNS(null,"fill-opacity")&&i[n].setAttributeNS(null,"fill-opacity",1)},SVGRenderer.prototype.setLineStyle=function(e,t){if(this.isConnector(e)&&t&&"none"!==t){var i=null,n=this.getShapeSubject(e);n&&!this.isQuoteLine(e)&&(i=n),i&&("arrow-from"!==t&&"arrow-both"!==t||i.setAttributeNS(null,"marker-start","url(#markerStart)"),"arrow-to"!==t&&"arrow-both"!==t||i.setAttributeNS(null,"marker-end","url(#markerEnd)"))}},SVGRenderer.prototype.getLineStyle=function(e){if(!this.isConnector(e))return"";var t=null,i=null,n=null,o=this.getShapeSubject(e);return o&&(n=this.isQuoteLine(e)&&5===o.length?o[1]:o),n&&(t=n.getAttributeNS(null,"marker-end"),i=n.getAttributeNS(null,"marker-start")),t&&i?"arrow-both":!t&&i?"arrow-from":t&&!i?"arrow-to":""},SVGRenderer.prototype.getShapeSubject=function(e){if(!e)return null;if(!this.isConnector(e))return e.getElementsByTagName("image").length>0?e.getElementsByTagName("image")[0]:e.getElementsByTagName("path").length>0?e.getElementsByTagName("path")[0]:e;var t=this.getConnectorType(e);return"line"===t||"link-line"===t||"smart-line"===t||"snap-line"===t?e.getElementsByTagName("line")[0]:"ortho-line"===t||"poly-line"===t||"poly-quote"===t?e.getElementsByTagName("polyline")[0]:"curve-line"===t?e.getElementsByTagName("path")[0]:"quote-line"===t?e.querySelectorAll("line, circle"):void 0},SVGRenderer.prototype.getAllSubShapes=function(e){return e?e.getElementsByTagName("path"):null},SVGRenderer.prototype.getPosition=function(e){var t={x:0,y:0,z:0};if(!e)return t;var i=e.getElementsByTagName("svg")[0];if(!i)return t;var n=i.x.baseVal.value;n&&(t.x=1*n);var o=i.y.baseVal.value;o&&(t.y=1*o);var s=i.getAttributeNS(null,"z");return s&&(t.z=1*s),t},SVGRenderer.prototype.setPosition=function(e,t,i,n){if(e){var o=e.getElementsByTagName("svg")[0];o&&(null!==t&&void 0!==t&&""!==t&&(o.x.baseVal.value=t),null!==i&&void 0!==i&&""!==i&&(o.y.baseVal.value=i),null!==n&&void 0!==n&&""!==n&&o.setAttributeNS(null,"z",n))}},SVGRenderer.prototype.getDimensions=function(e){var t={width:0,height:0,depth:0};if(!e)return t;var i=e.getElementsByTagName("svg")[0];if(!i)return t;var n=i.getAttributeNS(null,"width");n&&(t.width=1*n);var o=i.getAttributeNS(null,"height");o&&(t.height=1*o);var s=i.getAttributeNS(null,"depth");return s&&(t.depth=1*s),t},SVGRenderer.prototype.setDimensions=function(e,t,i,n){if(e){var o=e.getElementsByTagName("svg")[0];o&&(null!==t&&void 0!==t&&""!==t&&(t<0&&(t*=-1),0===t&&(t=1e-10),o.setAttributeNS(null,"width",t)),null!==i&&void 0!==i&&""!==i&&(i<0&&(i*=-1),0===i&&(i=1e-10),o.setAttributeNS(null,"height",i)),null!==n&&void 0!==n&&""!==n&&(n<0&&(n*=-1),0===n&&(n=1e-10),o.setAttributeNS(null,"depth",n)))}},SVGRenderer.prototype.resize=function(e,t,i,n,o){var s=n-t,r=o-i;if(this.isConnector(e)){var a=this.getConnectorType(e);"line"===a||"link-line"===a||"quote-line"===a||"smart-line"===a?this.setLineTo(e,n,o):"ortho-line"===a?this.drawOrthoLine(e,t,i,n,o):"curve-line"===a?this.drawCurveLine(e,t,i,n,o,!1):"poly-line"===a&&this.drawPolyline(e,n,o,!1)}else s<0?(this.setPosition(e,n,null,null),this.setDimensions(e,-s,null,null)):this.setDimensions(e,s,null,null),r<0?(this.setPosition(e,null,o,null),this.setDimensions(e,null,-r,null)):this.setDimensions(e,null,r,null),this.updateRotation(e)},SVGRenderer.prototype.resizeWidth=function(e,t,i,n,o,s,r){var a=this.bounds(e),l=a.rotation;l||(l=0),l%=360;var h=E2DUtils.deg2rad(-l),d=t*Math.cos(h)-i*Math.sin(h)-(n*Math.cos(h)-o*Math.sin(h));r||(d=-d);var c=1*s+d;if(c<1)return!1;var u=null;u=r?this.getRotatedPoint(a.x,a.y,a):this.getRotatedPoint(1*a.x+1*a.width,1*a.y+1*a.height,a),this.setDimensions(e,c,null,null);var p=this.bounds(e),g=null;g=r?this.getRotatedPoint(p.x,p.y,p):this.getRotatedPoint(1*p.x+1*p.width,1*p.y+1*p.height,p);var y=u.x-g.x,f=u.y-g.y;this.setPosition(e,1*p.x+y,1*p.y+f,1*p.z),this.updateRotation(e)},SVGRenderer.prototype.resizeHeight=function(e,t,i,n,o,s,r){var a=this.bounds(e),l=a.rotation;l||(l=0),l%=360;var h=E2DUtils.deg2rad(-l),d=i*Math.cos(h)+t*Math.sin(h)-(o*Math.cos(h)+n*Math.sin(h));r||(d=-d);var c=1*s+d;if(c<1)return!1;var u=null;u=r?this.getRotatedPoint(a.x,a.y,a):this.getRotatedPoint(1*a.x+1*a.width,1*a.y+1*a.height,a),this.setDimensions(e,null,c,null);var p=this.bounds(e),g=null;g=r?this.getRotatedPoint(p.x,p.y,p):this.getRotatedPoint(1*p.x+1*p.width,1*p.y+1*p.height,p);var y=u.x-g.x,f=u.y-g.y;this.setPosition(e,1*p.x+y,1*p.y+f,1*p.z),this.updateRotation(e)},SVGRenderer.prototype.resizeDepth=function(e,t,i,n,o,s){var r=this.bounds(e).rotation;r||(r=0),r%=360;var a=E2DUtils.deg2rad(-r),l=i*Math.cos(a)+t*Math.sin(a),h=1*s+(o*Math.cos(a)+n*Math.sin(a)-l);if(h<1)return!1;this.setDimensions(e,null,null,h)},SVGRenderer.prototype.resizeZ=function(e,t,i,n,o,s){var r=this.bounds(e).rotation;r||(r=0),r%=360;var a=E2DUtils.deg2rad(-r),l=i*Math.cos(a)+t*Math.sin(a),h=1*s+(o*Math.cos(a)+n*Math.sin(a)-l);if(h<1)return!1;this.setPosition(e,null,null,h)},SVGRenderer.prototype.adjustAspectRatioAfterHorizontalStretch=function(e,t,i,n){var o="right-stretch"===n,s=null;s=o?this.getRotatedPoint(e.x,e.y,e):this.getRotatedPoint(1*e.x+1*e.width,1*e.y+1*e.height,e);var r=this.bounds(t);this.setDimensions(t,null,r.width/i,null),r=this.bounds(t);var a=null;a=o?this.getRotatedPoint(r.x,r.y,r):this.getRotatedPoint(1*r.x+1*r.width,1*r.y+1*r.height,r);var l=s.x-a.x,h=s.y-a.y;this.setPosition(t,1*r.x+l,null,null),o?this.setPosition(t,null,1*r.y+h,null):this.setPosition(t,null,1*r.y,null)},SVGRenderer.prototype.adjustAspectRatioAfterVerticalStretch=function(e,t,i,n){var o="bottom-stretch"===n,s=null;s=o?this.getRotatedPoint(e.x,e.y,e):this.getRotatedPoint(1*e.x+1*e.width,1*e.y+1*e.height,e);var r=this.bounds(t);this.setDimensions(t,r.height*i,null,null),r=this.bounds(t);var a=null;a=o?this.getRotatedPoint(r.x,r.y,r):this.getRotatedPoint(1*r.x+1*r.width,1*r.y+1*r.height,r);var l=s.x-a.x,h=s.y-a.y;this.setPosition(t,1*r.x+l,1*r.y+h,1*r.z)},SVGRenderer.prototype.adjustAspectRatioAfterDiagonalStretch=function(e,t,i,n){var o=null;switch(n){case"bottom-right-stretch":o=this.getRotatedPoint(e.x,e.y,e);break;case"bottom-left-stretch":case"top-left-stretch":case"top-right-stretch":o=this.getRotatedPoint(1*e.x+1*e.width,1*e.y+1*e.height,e)}var s=this.bounds(t);this.setDimensions(t,s.height*i,null,null),s=this.bounds(t);var r=null;switch(n){case"bottom-right-stretch":r=this.getRotatedPoint(s.x,s.y,s);break;case"bottom-left-stretch":case"top-left-stretch":case"top-right-stretch":r=this.getRotatedPoint(1*s.x+1*s.width,1*s.y+1*s.height,s)}var a=o.x-r.x,l=o.y-r.y;switch(n){case"bottom-left-stretch":this.setPosition(t,1*s.x+a,1*s.y,1*s.z);break;case"bottom-right-stretch":case"top-left-stretch":this.setPosition(t,1*s.x+a,1*s.y+l,1*s.z);break;case"top-right-stretch":this.setPosition(t,1*s.x,1*s.y+l,1*s.z)}},SVGRenderer.prototype.getRotation=function(e){if(!e||e.id===this.TRACKER_GROUP_ID)return null;var t=null;try{t=e.transform.baseVal.getItem(0)}catch(e){return null}return 1*t.angle},SVGRenderer.prototype.setRotation=function(e,t){if(!e||e.transform.baseVal.numberOfItems<1)return null;var i=this.bounds(e),n="rotate("+t+","+(1*i.x+i.width/2*1)+","+(1*i.y+i.height/2*1)+")";e.setAttributeNS(null,"transform",n)},SVGRenderer.prototype.updateRotation=function(e){var t=this.getRotation(e);this.setRotation(e,t)},SVGRenderer.prototype.rotate=function(e,t){t||(t=0),(t%=360)<0&&(t=360+t),this.setRotation(e,t)},SVGRenderer.prototype.fineMove=function(e,t,i){if(e&&!this.isConnector(e)){var n=this.getPosition(e);this.setPosition(e,n.x+t,n.y+i,null),this.updateRotation(e)}},SVGRenderer.prototype.fineRotateSelection=function(e,t){if(this.isConnector(e))return 0;var i=this.getRotation(e);return i||(i=0),(i=(i+t)%360)<0&&(i=360+i),this.setRotation(e,i),i},SVGRenderer.prototype.move=function(e,t,i,n){this.setPosition(e,t,i,n),this.updateRotation(e)},SVGRenderer.prototype.drawCurveLine=function(e,t,i,n,o,s){if(this.setLineFrom(e,t,i),this.setLineTo(e,n,o),!s){var r=Math.abs(t-n),a=Math.abs(i-o),l=t<n?1*t+.25*r:1*t-.25*r,h=t<n?1*n-.25*r:1*n+.25*r,d=i<o?1*i+.25*a:1*i-.25*a,c=i<o?1*o-.25*a:1*o+.25*a;this.setControl1(e,l,d),this.setControl2(e,h,c)}},SVGRenderer.prototype.setSnapLine=function(e){this.snapLine=e},SVGRenderer.prototype.setPolyQuote=function(e){this.polyQuote=e},SVGRenderer.prototype.createLineTracker=function(e){e.id=this.LINE_TRACKER_GROUP_ID,this.importAndAppendChild(this.svgRoot,e),this.hideLineTracker()},SVGRenderer.prototype.showLineTracker=function(e,t){var i=document.getElementById(this.LINE_TRACKER_GROUP_ID);return this.updateLineTracker(e,i,t),i},SVGRenderer.prototype.updateLineTracker=function(e,t,i){this.hideLineTracker(),this.isLinkLine(e)||(t.style.visibility="visible");var n=1/this.zoom,o=null,s=null,r=-1,a=-1,l=document.getElementById("resize-from"),h=document.getElementById("resize-to"),d=this.getConnectorType(e);if("line"===d||"link-line"===d||"quote-line"===d||"smart-line"===d)o=this.getConnectorFrom(e),s=this.getConnectorTo(e);else if("curve-line"===d){o=this.getConnectorFrom(e),s=this.getConnectorTo(e);var c=this.getControl1(e),u=document.getElementById("control1");u.setAttributeNS(null,"transform","translate("+c.x+","+c.y+"),scale("+n+")"),u.style.visibility="visible";var p=document.getElementById("control1-line");p.setAttributeNS(null,"x1",o.x),p.setAttributeNS(null,"y1",o.y),p.setAttributeNS(null,"x2",c.x),p.setAttributeNS(null,"y2",c.y),p.style.visibility="visible";var g=this.getControl2(e),y=document.getElementById("control2");y.setAttributeNS(null,"transform","translate("+g.x+","+g.y+"),scale("+n+")"),y.style.visibility="visible";var f=document.getElementById("control2-line");f.setAttributeNS(null,"x1",s.x),f.setAttributeNS(null,"y1",s.y),f.setAttributeNS(null,"x2",g.x),f.setAttributeNS(null,"y2",g.y),f.style.visibility="visible"}else if("ortho-line"===d||"poly-line"===d){if(0===this.getShapeSubject(e).points.numberOfItems)return;i&&2===i.length?(r=i[0],a=i[1]):(r=l.getAttributeNS(null,"plPoint"),a=h.getAttributeNS(null,"plPoint")),o=this.getPolylinePoint(e,r),s=this.getPolylinePoint(e,a),o&&s||(o=this.getConnectorFrom(e),s=this.getConnectorTo(e),r=-1,a=-1)}l.classList.remove("lineTrackerResizeSelected"),l.setAttributeNS(null,"transform","translate("+o.x+", "+o.y+"),scale("+n+")"),-1!==r?l.setAttributeNS(null,"plPoint",r):l.removeAttributeNS(null,"plPoint"),h.classList.remove("lineTrackerResizeSelected"),h.setAttributeNS(null,"transform","translate("+s.x+", "+s.y+"),scale("+n+")"),-1!==a?h.setAttributeNS(null,"plPoint",a):h.removeAttributeNS(null,"plPoint"),this.bringToFront(t)},SVGRenderer.prototype.hideLineTracker=function(){var e=document.getElementById(this.LINE_TRACKER_GROUP_ID);e&&(e.style.visibility="hidden",document.getElementById("control1").style.visibility="hidden",document.getElementById("control2").style.visibility="hidden",document.getElementById("control1-line").style.visibility="hidden",document.getElementById("control2-line").style.visibility="hidden")},SVGRenderer.prototype.removeLineTracker=function(){this.remove(document.getElementById(this.LINE_TRACKER_GROUP_ID)),this.remove(document.getElementById("control1")),this.remove(document.getElementById("control2")),this.remove(document.getElementById("control1-line")),this.remove(document.getElementById("control2-line"))},SVGRenderer.prototype.clearTrackerSegments=function(){var e=document.getElementById("resize-from");e.hasAttributeNS(null,"plPoint")&&e.removeAttributeNS(null,"plPoint");var t=document.getElementById("resize-to");t.hasAttributeNS(null,"plPoint")&&t.removeAttributeNS(null,"plPoint")},SVGRenderer.prototype.createTracker=function(e){e.id=this.TRACKER_GROUP_ID,this.importAndAppendChild(this.svgRoot,e),this.hideTracker()},SVGRenderer.prototype.showTracker=function(e){if(e){if(this.isConnector(e))return this.hideTracker(),this.showLineTracker(e);this.hideLineTracker();var t=document.getElementById(this.TRACKER_GROUP_ID);return this.bringToFront(t),this.updateTracker(e),t}},SVGRenderer.prototype.updateTracker=function(e,t){if(e){if(this.isConnector(e))return this.showLineTracker(e,t);var i=document.getElementById(this.TRACKER_GROUP_ID);if(!i)return this.showTracker(e);var n=1/this.zoom,o=5*n,s=10*n,r=30*n,a=-35*n,l=this.bounds(e),h=document.getElementById("tracker");i.style.visibility="visible";var d=l.x-o,c=l.y-o,u=l.width+s,p=l.height+s,g=1*d+u/2,y=1*c+p/2,f="rotate("+l.rotation+","+g+","+y+")";i.setAttributeNS(null,"transform",f),h.setAttributeNS(null,"width",u+"px"),h.setAttributeNS(null,"height",p+"px"),h.parentNode.setAttributeNS(null,"x",d+"px"),h.parentNode.setAttributeNS(null,"y",c+"px");var v=document.getElementById("tracker-rotate"),m=document.getElementById("resize-left"),S=document.getElementById("resize-top-left"),E=document.getElementById("resize-top"),D=document.getElementById("resize-top-right"),b=document.getElementById("resize-right"),x=document.getElementById("resize-bottom-left"),I=document.getElementById("resize-bottom"),C=document.getElementById("resize-bottom-right"),T=document.getElementById("resize-depth"),P=document.getElementById("resize-z"),L=document.getElementById("tracker-dots");if(v.setAttributeNS(null,"transform","translate("+.5*u+", "+a+"),scale("+n+")"),m.setAttributeNS(null,"transform","translate(0, "+.5*p+"),scale("+n+")"),S.setAttributeNS(null,"transform","scale("+n+")"),E.setAttributeNS(null,"transform","translate("+.5*u+", 0),scale("+n+")"),D.setAttributeNS(null,"transform","translate("+u+", 0),scale("+n+")"),b.setAttributeNS(null,"transform","translate("+u+", "+.5*p+"),scale("+n+")"),x.setAttributeNS(null,"transform","translate(0, "+p+"),scale("+n+")"),I.setAttributeNS(null,"transform","translate("+.5*u+", "+p+"),scale("+n+")"),C.setAttributeNS(null,"transform","translate("+u+", "+p+"),scale("+n+")"),T.setAttributeNS(null,"transform","translate(0, "+(p+r)+"),scale("+n+")"),P.setAttributeNS(null,"transform","translate("+u+", "+(p+r)+"),scale("+n+")"),L.setAttributeNS(null,"transform","translate("+.5*u+", "+(p+r)+"),scale("+n+")"),v.setAttributeNS(null,"class",""),m.setAttributeNS(null,"class",""),S.setAttributeNS(null,"class",""),E.setAttributeNS(null,"class",""),D.setAttributeNS(null,"class",""),b.setAttributeNS(null,"class",""),x.setAttributeNS(null,"class",""),I.setAttributeNS(null,"class",""),C.setAttributeNS(null,"class",""),T.setAttributeNS(null,"class",""),P.setAttributeNS(null,"class",""),L.setAttributeNS(null,"class",""),this.isMultipleSelect(e))return m.setAttributeNS(null,"class","hide"),S.setAttributeNS(null,"class","hide"),E.setAttributeNS(null,"class","hide"),D.setAttributeNS(null,"class","hide"),b.setAttributeNS(null,"class","hide"),x.setAttributeNS(null,"class","hide"),I.setAttributeNS(null,"class","hide"),C.setAttributeNS(null,"class","hide"),T.setAttributeNS(null,"class","hide"),void L.setAttributeNS(null,"class","hide");var O=E2DGlobals.e2d,w=O.getBehaviour(e.id,!1);(w.move.noMove||w.move.noZMove)&&P.setAttributeNS(null,"class","hide"),(w.move.noRotate||w.move.noRotateOnView)&&v.setAttributeNS(null,"class","hide"),(w.stretch.noStretch||w.stretch.noStretchOnView)&&(m.setAttributeNS(null,"class","hide"),S.setAttributeNS(null,"class","hide"),E.setAttributeNS(null,"class","hide"),D.setAttributeNS(null,"class","hide"),b.setAttributeNS(null,"class","hide"),x.setAttributeNS(null,"class","hide"),I.setAttributeNS(null,"class","hide"),C.setAttributeNS(null,"class","hide"),T.setAttributeNS(null,"class","hide")),w.stretch.noWStretch&&(m.setAttributeNS(null,"class","hide"),S.setAttributeNS(null,"class","hide"),D.setAttributeNS(null,"class","hide"),b.setAttributeNS(null,"class","hide"),x.setAttributeNS(null,"class","hide"),C.setAttributeNS(null,"class","hide")),w.stretch.noHStretch&&(S.setAttributeNS(null,"class","hide"),E.setAttributeNS(null,"class","hide"),D.setAttributeNS(null,"class","hide"),x.setAttributeNS(null,"class","hide"),I.setAttributeNS(null,"class","hide"),C.setAttributeNS(null,"class","hide")),w.stretch.noDStretch&&T.setAttributeNS(null,"class","hide"),O.enable3d||(T.setAttributeNS(null,"class","hide"),P.setAttributeNS(null,"class","hide")),0===E2DUtils.objectSize(O.overlappingGhosts)&&L.setAttributeNS(null,"class","hide")}},SVGRenderer.prototype.hideTracker=function(){var e=document.getElementById(this.TRACKER_GROUP_ID);e&&(e.style.visibility="hidden")},SVGRenderer.prototype.removeTracker=function(){this.remove(document.getElementById(this.TRACKER_GROUP_ID))},SVGRenderer.prototype.createMultipleSelector=function(e){e.id=this.MULTIPLE_SELECTOR_TRACKER_ID,this.importAndAppendChild(this.svgRoot,e),this.showMultipleSelector(!1)},SVGRenderer.prototype.getMultipleSelector=function(e,t){var i=document.getElementById(this.MULTIPLE_SELECTOR_TRACKER_ID);return e&&(this.bringToFront(i),i=document.getElementById(this.MULTIPLE_SELECTOR_TRACKER_ID)),t&&(this.sendToBack(i),i=document.getElementById(this.MULTIPLE_SELECTOR_TRACKER_ID)),i},SVGRenderer.prototype.removeMultipleSelector=function(){this.remove(this.getMultipleSelector())},SVGRenderer.prototype.showMultipleSelector=function(e){var t=this.getMultipleSelector();t&&(t.style.visibility=e?"visible":"hidden")},SVGRenderer.prototype.sizeMultipleSelector=function(e){var t=this.getMultipleSelector();this.setRotation(t,0),this.setPosition(t,e.x,e.y,e.z),this.setDimensions(t,e.width,e.height,e.depth)},SVGRenderer.prototype.createMultipleSelectorDummyShape=function(e){e.id=this.MULTIPLE_SELECTOR_DUMMY_ID,this.importAndAppendChild(this.svgRoot,e),this.showMultipleSelectorDummyShape(!1)},SVGRenderer.prototype.getMultipleSelectorDummyShape=function(e,t){var i=document.getElementById(this.MULTIPLE_SELECTOR_DUMMY_ID);return e&&(this.bringToFront(i),i=document.getElementById(this.MULTIPLE_SELECTOR_DUMMY_ID)),t&&(this.sendToBack(i),i=document.getElementById(this.MULTIPLE_SELECTOR_DUMMY_ID)),i},SVGRenderer.prototype.removeMultipleSelectorDummyShape=function(){this.remove(this.getMultipleSelectorDummyShape())},SVGRenderer.prototype.showMultipleSelectorDummyShape=function(e){var t=this.getMultipleSelectorDummyShape();t&&(t.style.visibility=e?"visible":"hidden")},SVGRenderer.prototype.sizeMultipleSelectorDummyShape=function(e){var t=this.getMultipleSelectorDummyShape();this.setRotation(t,0),this.setPosition(t,e.x,e.y,null),this.setDimensions(t,e.width,e.height,null)},SVGRenderer.prototype.showMultipleSelectors=function(e){this.showMultipleSelector(e),this.showMultipleSelectorDummyShape(e)},SVGRenderer.prototype.clearShapeText=function(e){if(!e)return;const t=e.getElementsByTagName("text"),i=$.makeArray(t);for(let e=0,t=i.length;e<t;e++){const t=i[e];(t.classList.contains("normal")||t.classList.contains("newline"))&&this.remove(t)}},SVGRenderer.prototype.handleTextLinePositioning=function(e,t,i,n,o,s){for(var r,a=1*e.y+1*e.height/2,l=1*e.x+1*e.width/2,h=[],d=n.size/4,c=1.1*n.size,u=t;u>0;u--)r=a+c*(u-t)+d,h[h.length]=this.createTextShape(i[u-1],r,l,n,o,s);for(var p=t;p<i.length;p++)r=a+c*(p+1-t)+d,h[h.length]=this.createTextShape(i[p],r,l,n,o,s);return h},SVGRenderer.prototype.getFont=function(e){var t=E2DFont.get();if(!e||!e.id)return t;var i=this.getTextData(e);return i&&i.font&&(t=i.font),t},SVGRenderer.prototype.setFont=function(e,t){var i=this.getShapeText(e);if(!i)return t=E2DFont.mergeWithDefault(t),void this.setShapeText(e," ",t);var n=e.getElementsByTagName("text"),o=this.getFont(e);if(t.size&&t.size!==o.size&&(o.size=t.size,this.clearShapeText(e),this.setShapeText(e,i,t,!0)),t.color&&t.color!==o.color){o.color=t.color;for(var s=0,r=n.length;s<r;s++)n[s].setAttributeNS(null,"fill",t.color)}if(t.family&&t.family!==o.family){o.family=t.family;for(var a=0,l=n.length;a<l;a++)n[a].style.fontFamily=t.family}this.updateTextData(e,o)},SVGRenderer.prototype.getMarkup=function(){return this.container.innerHTML},SVGRenderer.prototype.appendPageAttribute=function(e,t){if(e){var i=e.getElementsByTagName("svg")[0];this.importAndAppendChild(i,t)}},SVGRenderer.prototype.setImage=function(e,t){if(e){var i=e.getElementsByTagName("image")[0];i&&i.setAttribute("xlink:href",t)}},SVGRenderer.prototype.replaceInternalSVG=function(e,t,i){if(e&&i){e.setAttribute("riSVGInProgress",!0);var n=this;this.loadShape(t,i,this).done(function(t){n.replaceInternalSVGAsync(e,t)})}},SVGRenderer.prototype.replaceInternalSVGAsync=function(e,t){if(e&&t){var i=[],n=null,o=$.makeArray(e.children);if(o&&o.length)for(var s=0,r=o.length;s<r;s++)(n=o[s])&&"svg"===n.tagName.toLowerCase()&&(e.removeChild(n),i[i.length]={x:n.getAttributeNS(null,"x"),y:n.getAttributeNS(null,"y"),z:n.getAttributeNS(null,"z"),w:n.getAttributeNS(null,"width"),h:n.getAttributeNS(null,"height"),d:n.getAttributeNS(null,"depth")});if((o=t.children)&&o.length)for(var a=e.firstElementChild,l=0,h=o.length;l<h;l++)if((n=o[l])&&"svg"===n.tagName.toLowerCase()){var d=i.shift();d&&(n.setAttributeNS(null,"x",d.x),n.setAttributeNS(null,"y",d.y),n.setAttributeNS(null,"z",d.z),n.setAttributeNS(null,"width",d.w),n.setAttributeNS(null,"height",d.h),n.setAttributeNS(null,"depth",d.d),e.insertBefore(n,a))}e.removeAttribute("riSVGInProgress")}},SVGRenderer.prototype.showPolyQuote=function(e,t,i,n,o){var s=null,r=null;"A"===e?(s="pq"+this.QUOTE_A,r=$("#"+this.QUOTE_A)):(s="pq"+this.QUOTE_B,r=$("#"+this.QUOTE_B));var a=this.importAndAppendChild(this.svgRoot,this.polyQuote);a.id=s,this.startPolyline(a,0,0),this.setPolylinePoints(a,t);var l=E2DFont.get();l.forced||(l.size="12"),r.html(i),r.css({"font-size":l.size,"margin-left":n,"margin-top":o,"z-index":"1000000",visibility:"visible"}),this.isPolyQuoteShowing=!0},SVGRenderer.prototype.hidePolyQuotes=function(){if(this.isPolyQuoteShowing){var e=document.getElementById("pq"+this.QUOTE_A);e&&this.remove(e),(e=document.getElementById("pq"+this.QUOTE_B))&&this.remove(e),$("#"+this.QUOTE_A).css("visibility","hidden"),$("#"+this.QUOTE_B).css("visibility","hidden"),this.isPolyQuoteShowing=!1}},SVGRenderer.prototype.showSnapLine=function(e){var t,i=[];i[0]=E2DUtils.lineLineIntersectionEx(e.a,e.b,{x:0,y:0},{x:this.MAX_WIDTH,y:0}),i[1]=E2DUtils.lineLineIntersectionEx(e.a,e.b,{x:0,y:0},{x:0,y:this.MAX_HEIGHT}),i[2]=E2DUtils.lineLineIntersectionEx(e.a,e.b,{x:this.MAX_WIDTH,y:0},{x:this.MAX_WIDTH,y:this.MAX_HEIGHT}),i[3]=E2DUtils.lineLineIntersectionEx(e.a,e.b,{x:0,y:this.MAX_HEIGHT},{x:this.MAX_WIDTH,y:this.MAX_HEIGHT});var n,o=i.length;for(t=0;t<o&&!(i[t]&&i[t].x>=0&&i[t].y>=0);t++);for(n=t+1;n<o&&!(i[n]&&i[n].x>=0&&i[n].y>=0);n++);if(i[t]&&i[n]){var s=this.importAndAppendChild(this.svgRoot,this.snapLine);s.id="snap-line",this.setLineFrom(s,i[t].x,i[t].y),this.setLineTo(s,i[n].x,i[n].y)}this.isSnapLineShowing=!0},SVGRenderer.prototype.showSnapLineCoords=function(e){var t=this.importAndAppendChild(this.svgRoot,this.snapLine);t.id="snap-line",!0===e.showX&&!0===e.showY?(!1===this.lastSnapLineOrientation?(this.setLineFrom(t,e.x,0),this.setLineTo(t,e.x,this.MAX_WIDTH)):(this.setLineFrom(t,0,e.y),this.setLineTo(t,this.MAX_HEIGHT,e.y)),this.isSnapLineShowing=!0):!0===e.showX?(this.lastSnapLineOrientation=!0,this.setLineFrom(t,e.x,0),this.setLineTo(t,e.x,this.MAX_WIDTH),this.isSnapLineShowing=!0):!0===e.showY&&(this.lastSnapLineOrientation=!1,this.setLineFrom(t,0,e.y),this.setLineTo(t,this.MAX_HEIGHT,e.y),this.isSnapLineShowing=!0)},SVGRenderer.prototype.hideSnapLine=function(){if(this.isSnapLineShowing){var e=document.getElementById("snap-line");e&&this.remove(e),this.isSnapLineShowing=!1}},SVGInspector={points:[],svgNS:"http://www.w3.org/2000/svg",clear:function(){for(var e in SVGInspector.points)SVGInspector.points.hasOwnProperty(e)&&SVGInspector.removePoint(e);SVGInspector.points=[]},addPoint:function(e,t,i,n){SVGInspector.points[e]&&SVGInspector.removePoint(e),SVGInspector.points[e]={x:t,y:i};var o=document.getElementById("SVG_ROOT"),s=o.ownerDocument,r=s.createElementNS(SVGInspector.svgNS,"circle");r.setAttributeNS(null,"cx",t),r.setAttributeNS(null,"cy",i),r.setAttributeNS(null,"r",5),r.setAttributeNS(null,"fill",n),r.setAttributeNS(null,"stroke","#000000"),r.setAttributeNS(null,"stroke-width","1px");var a=s.createElementNS(SVGInspector.svgNS,"text");a.setAttributeNS(null,"x",t),a.setAttributeNS(null,"y",i),a.setAttributeNS(null,"dx","1em"),a.setAttributeNS(null,"dy","1em"),a.textContent=e;var l=s.createElementNS(SVGInspector.svgNS,"g");l.id=e,l.appendChild(r),l.appendChild(a),o.appendChild(l)},removePoint:function(e){if(SVGInspector.points[e]){delete SVGInspector.points[e];var t=document.getElementById(e);t&&t.parentNode&&t.parentNode.removeChild(t)}}},ThreeDRenderer=function(e,t,i,n,o){this.root=e,this.requestID=null,this.requestTimerID=null,this.camera=null,this.controls=null,this.transformControls=null,this.scene=null,this.ambientLight=null,this.directionalLight=null,this.directionalLightHelper=null,this.hemiLight=null,this.spotLight=null,this.renderer=null,this.raycaster=null,this.floorGrid=null,this.selectedItems=[],this.collidingItems=[],this.externalItems=[],this.multipleSelectorDummy=null,this.edgesBoxes=[],this.colorDefault=16733491,this.colorSelection=65280,this.colorCollision=16711680,this.colorExternal=16776960,this.colorWhite=16777215,this.colorWall=12237498,this.materials=[],this.objects=[],this.objectChildren=[],this.objectMaterials=[],this.objectLineMaterials=[],this.polylines=[],this.width=t||640,this.height=i||480,this.planeWidth=n||2e3,this.planeHeight=o||2e3,this.shapeFolder="/shapes/obj/",this.nearThreshold=1e-6,this.origin={x:0,y:0,z:0,signX:1,signY:1,signZ:1},this.scale=1,this.viewStyle="TOP",this.fieldOfView=50,this.renderLastMove=Date.now(),this.renderRunning=!0,this.renderStandByAfter=2e3,this.enableFloor=!1,this.floorDefinition=null,this.enableWalls=!1,this.enableDinamicLights=!1,this.showWalls=!0,this.wallHeight=3e3,this.wallThickness=1,this.objectCastShadows=!0,this.objectReceiveShadows=!0,this.DEFAULT_BACKGROUND_COLOR=16316664,this.DEFAULT_AMBIENT_LIGHT_COLOR=9342606,this.DEFAULT_DIRECTIONAL_LIGHT_COLOR=16711422,this.DEFAULT_HEMI_LIGHT_SKY_COLOR=268435455,this.DEFAULT_HEMI_LIGHT_GROUND_COLOR=14407628,this.DEFAULT_SPOT_LIGHT_COLOR=16777215},ThreeDRenderer.prototype={init:function(e,t,i,n,o,s,r,a,l,h,d){if(i&&(this.viewStyle=i),t&&(this.scale=t),this.enableFloor=r,this.floorDefinition=a,this.enableWalls=l,this.enableDinamicLights=n,"string"==typeof h&&h.length>0){var c=h.split("|");c.length>=1&&(this.wallHeight=1*c[0]),c.length>=2&&(this.wallThickness=1*c[1])}this.origin={x:e.x/t,y:e.y/t,z:e.z/t,signX:e.signX,signY:-1*e.signY,signZ:e.signZ},this.materials.default=new THREE.MeshPhongMaterial({color:this.colorDefault}),this.materials.multi=new THREE.MeshBasicMaterial({color:this.colorSelection,wireframe:!0}),this.materials.group=new THREE.MeshPhongMaterial({color:this.colorWhite,opacity:.05,transparent:!0}),this.materials.selection=new THREE.MeshPhongMaterial({color:this.colorSelection,opacity:.5,transparent:!0}),this.materials.collision=new THREE.MeshPhongMaterial({color:this.colorCollision,opacity:.5,transparent:!0}),this.materials.external=new THREE.MeshPhongMaterial({color:this.colorExternal,opacity:.5,transparent:!0}),this.materials.white=new THREE.MeshPhongMaterial({color:this.colorWhite}),this.materials.whiteopaque=new THREE.MeshPhongMaterial({color:this.colorWhite,opacity:.25,transparent:!0}),this.materials.edge=new THREE.LineBasicMaterial({color:16776960,linewidth:2}),this.materials.wall=new THREE.MeshPhongMaterial({color:this.colorWall,side:THREE.DoubleSide,opacity:.5,transparent:!0}),this.enableFloor&&(this.floorDefinition.color?this.materials.floor=new THREE.MeshPhongMaterial({color:this.floorDefinition.color,side:THREE.DoubleSide}):this.floorDefinition.image&&(this.materials.floor=new THREE.MeshBasicMaterial({map:null,transparent:!0}))),this.scene=new THREE.Scene,this.scene.background=new THREE.Color(this.DEFAULT_BACKGROUND_COLOR),this.scene.name="Scene";const u=new THREE.AxesHelper(100);switch(u.geometry.attributes.position.array[3]*=this.origin.signX,u.geometry.attributes.position.array[10]*=this.origin.signY,this.scene.add(u),this.renderer=new THREE.WebGLRenderer({antialias:!0,preserveDrawingBuffer:!0}),this.renderer.setSize(this.width,this.height),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=THREE.PCFSoftShadowMap,this.renderer.cachedObjects=new E2DCache,this.renderer.cachedTextures=new E2DCache,this.camera=new THREE.PerspectiveCamera(this.fieldOfView,1,1,1e4),this.camera.cachedCameraLookAt=null,this.camera.cachedCameraPosition=null,this.camera.aspect=this.width/this.heigth,this.camera.lookAt(this.scene.position),this.camera.up.set(0,0,1),this.viewStyle.toLowerCase()){case"front":this.camera.position.set(200*this.origin.signX,200*this.origin.signY,500*this.origin.signZ);break;default:this.camera.position.set(500*this.origin.signX,500*this.origin.signY,200*this.origin.signZ)}if(n?(this.hemiLight=new THREE.HemisphereLight(this.DEFAULT_HEMI_LIGHT_GROUND_COLOR,this.DEFAULT_HEMI_LIGHT_GROUND_COLOR,.7),this.scene.add(this.hemiLight),this.spotLight=new THREE.SpotLight(this.DEFAULT_SPOT_LIGHT_COLOR,.5),this.spotLight.castShadow=!0,this.spotLight.angle=Math.PI/2.5,this.spotLight.penumbra=.5,this.spotLight.decay=2,this.spotLight.shadow.bias=-1e-4,this.spotLight.shadow.mapSize.width=4096,this.spotLight.shadow.mapSize.height=4096,this.spotLight.shadow.camera.near=1,this.spotLight.shadow.camera.far=2e3,this.spotLight.shadow.camera.fov=60,this.scene.add(this.spotLight),this.scene.add(this.spotLight.target)):(this.ambientLight=new THREE.AmbientLight(this.DEFAULT_AMBIENT_LIGHT_COLOR,1),this.scene.add(this.ambientLight),this.directionalLight=new THREE.DirectionalLight(this.DEFAULT_DIRECTIONAL_LIGHT_COLOR,1),this.directionalLight.position.set(100,-500,1e3),this.directionalLight.castShadow=!0,this.directionalLight.shadow.camera.near=1,this.directionalLight.shadow.camera.far=2e3,this.directionalLight.shadow.camera.right=2500,this.directionalLight.shadow.camera.left=-2500,this.directionalLight.shadow.camera.top=2500,this.directionalLight.shadow.camera.bottom=-2500,this.directionalLight.shadow.mapSize.width=2048,this.directionalLight.shadow.mapSize.height=2048,this.scene.add(this.directionalLight)),o){const e=new THREE.Mesh(new THREE.PlaneGeometry(5e3,5e3,25,25),this.materials.white);e.position.set(0,0,-.1),e.castShadow=!1,e.receiveShadow=!0,this.scene.add(e),this.floorGrid=new THREE.GridHelper(5e3,200),this.floorGrid.rotation.x=-Math.PI/2,this.scene.add(this.floorGrid),s||(this.floorGrid.visible=!1)}this.raycaster=new THREE.Raycaster;const p=document.getElementById(this.root);p.appendChild(this.renderer.domElement),$(p).on("vclick",this.onClick.bind(this)),$(p).on("dblclick",this.onDblClick.bind(this)),this.controls=new THREE.OrbitControls(this.camera,p),this.controls.rotateSpeed=1,this.controls.zoomSpeed=1.2,this.controls.panSpeed=.8,this.controls.enablePan=!0,this.controls.enableZoom=!0,this.controls.enableDamping=!0,this.controls.dampingFactor=.3,this.controls.maxPolarAngle=Math.PI/2,this.controls.addEventListener("change",this.onControlsChange.bind(this)),this.transformControls=new THREE.TransformControls(this.camera,p),this.transformControls.setMode("translate"),this.transformControls.addEventListener("objectChange",this.onTransformControlsChange.bind(this)),this.transformControls.addEventListener("mouseDown",this.onTransformControlsMouseDown.bind(this)),this.transformControls.addEventListener("mouseUp",this.onTransformControlsMouseUp.bind(this)),this.scene.add(this.transformControls),E2DEventBus.addEventListener("shapeSelected",this.onShapeSelected,this),E2DEventBus.addEventListener("shapeMultiSelected",this.onShapeMultiSelected,this),E2DEventBus.addEventListener("shapeAddCollision",this.onShapeAddCollision,this),E2DEventBus.addEventListener("shapeClearCollisions",this.onShapeClearCollisions,this),E2DEventBus.addEventListener("shapeAddExternal",this.onShapeAddExternal,this),E2DEventBus.addEventListener("shapeClearExternals",this.onShapeClearExternals,this),this.renderON(d)},dispose:function(){this.requestID&&(cancelAnimationFrame(this.requestID),this.requestID=null);const e=document.getElementById(this.root);e.removeChild(this.renderer.domElement);const t=$(e);t.off("vclick"),t.off("vmousedown"),t.off("vmouseup"),t.off("vmousemove"),t.off("dblclick"),E2DEventBus.removeEventListener("shapeSelected",this.onShapeSelected,this),E2DEventBus.removeEventListener("shapeMultiSelected",this.onShapeMultiSelected,this),E2DEventBus.removeEventListener("shapeAddCollision",this.onShapeAddCollision,this),E2DEventBus.removeEventListener("shapeClearCollisions",this.onShapeClearCollisions,this),E2DEventBus.removeEventListener("shapeAddExternal",this.onShapeAddExternal,this),E2DEventBus.removeEventListener("shapeClearExternals",this.onShapeClearExternals,this),this.root=null,this.camera=null,this.controls=null,this.scene=null,this.renderer.dispose(),this.renderer=null,this.raycaster=null,this.selectedItems=null,this.collidingItems=null,this.externalItems=null,this.multipleSelectorDummy=null,this.edgesBoxes=[],this.objects=[],this.objectChildren=[],this.objectMaterials=[],this.objectLineMaterials=[],this.polylines=[];for(const e in this.materials)this.materials.hasOwnProperty(e)&&this.materials[e]&&this.materials[e].dispose&&"function"==typeof this.materials[e].dispose&&(this.materials[e].dispose(),this.materials[e]=null);this.materials=[]},initSystemShapes:function(){},disposeSystemShapes:function(){this.edgesBoxes=[],this.objects=[],this.objectChildren=[],this.objectMaterials=[],this.objectLineMaterials=[],this.polylines=[]},changeBias:function(e){this.directionalLight&&(this.directionalLight.shadow.bias=1*e)},changeNear:function(e){this.directionalLight&&(this.directionalLight.shadow.camera.near=1*e,this.directionalLight.shadow.camera.updateProjectionMatrix())},changeFar:function(e){this.directionalLight&&(this.directionalLight.shadow.camera.far=1*e,this.directionalLight.shadow.camera.updateProjectionMatrix())},changeRight:function(e){this.directionalLight&&(this.directionalLight.shadow.camera.right=1*e,this.directionalLight.shadow.camera.updateProjectionMatrix())},changeLeft:function(e){this.directionalLight&&(this.directionalLight.shadow.camera.left=1*e,this.directionalLight.shadow.camera.updateProjectionMatrix())},changeTop:function(e){this.directionalLight&&(this.directionalLight.shadow.camera.top=1*e,this.directionalLight.shadow.camera.updateProjectionMatrix())},changeBottom:function(e){this.directionalLight&&(this.directionalLight.shadow.camera.bottom=1*e,this.directionalLight.shadow.camera.updateProjectionMatrix())},changeWidth:function(e){this.directionalLight&&(this.directionalLight.shadow.camera.width=1*e,this.directionalLight.shadow.camera.updateProjectionMatrix())},changeHeight:function(e){this.directionalLight&&(this.directionalLight.shadow.camera.height=1*e,this.directionalLight.shadow.camera.updateProjectionMatrix())},onClick:function(e){e.preventDefault();const t=$(e.target).offset(),i=e.clientX-t.left,n=e.clientY-t.top,o=new THREE.Vector3;o.set(i/this.width*2-1,-n/this.height*2+1,.5),o.unproject(this.camera),this.raycaster.ray.set(this.camera.position,o.sub(this.camera.position).normalize());const s=this.raycaster.intersectObjects(E2DUtils.objectValues(this.objects),!0);if(s.length>0){const t=this.getParentObject3D(s[0].object);if(t){const i=E2DGlobals.e2d.insertedShapes.getShapeById(t.id);if(i&&i.hasBehaviour("(NOSELECT"))return;if(e.shiftKey)this.selectedItems[t.id]?this.removeSelection(t.id,!0,!0):this.addSelection(t.id,!0,!0);else{var r=E2DGlobals.e2d;Object.values(r.insertedShapes.insertedShapeMap).forEach(function(e){e.id!==t.id&&(e.selected=!1)}),this.select(t,!0)}}else this.unselect()}else this.unselect()},onDblClick:function(e){e.preventDefault();const t=this.raycaster.intersectObjects(E2DUtils.objectValues(this.objects),!0);if(t.length>0){if(this.getParentObject3D(t[0].object)){var i=E2DGlobals.e2d;if(!i.selected)return!1;if(!i.renderer.isPolyline(i.selected)){var n=i.insertedShapes.getShapeById(i.selected.id);if(n&&"text"!==n.source&&i.events.doubleclick){var o=null,s=[];if(i.renderer.isMultipleSelect(i.selected)){for(var r=i.multipleSelectShapes.getShapes(),a=0,l=r.length;a<l;a++)(o=i.getEventArgumentByShapeId("DOUBLECLICK",r[a].id))&&(s[s.length]=o);if(s&&s.length>1&&evt&&evt.currentTarget&&evt.currentTarget.id&&!i.renderer.isMultipleSelect(evt.currentTarget)){for(var h=evt.currentTarget.id,d=null,c=-1,u=0,p=s.length;u<p;u++)if(h===(o=s[u]).shapeID){d=o,c=u;break}d&&(s.splice(c,1),s.unshift(d))}}else(o=i.getEventArgumentByShapeId("DOUBLECLICK",i.selected.id))&&(s[s.length]=o);s&&s.length>0&&E2DEvents.doSubmitEvent("OnEditor2DDoubleClick",s,1,"urDoubleClick")}}}}},onControlsChange:function(){},onTransformControlsChange:function(){const e=this.transformControls.object;if(!e)return;let t=e.position.x/this.scale*this.origin.signX,i=e.position.y/this.scale*this.origin.signY,n=e.position.z/this.scale*this.origin.signZ;n<0&&(n=0,e.position.setZ(n)),e.updateMatrix(),E2DGlobals.e2d.updateById(e.id,t,i,n)},onTransformControlsMouseDown:function(){this.controls.enabled=!1},onTransformControlsMouseUp:function(){this.controls.enabled=!0},onShapeSelected:function(e,t){t?this.selectById(e.target):this.unselect()},onShapeMultiSelected:function(e,t){t?this.addSelection(e.target):this.removeSelection(e.target)},onShapeAddCollision:function(e){this.addCollision(e.target)},onShapeClearCollisions:function(e){this.clearCollisions()},onShapeAddExternal:function(e){this.addExternal(e.target)},onShapeClearExternals:function(e){this.clearExternals(e.target)},onObjectAdded:function(e,t,i,n){this.addObject(e.target,t,i,n)},onObjectRemoved:function(e){this.removeObject(e.target)},onObjectUpdated:function(e){this.updateObject(e.target)},onMultipleSelectorAdded:function(e){this.addMultipleSelector(e.target)},onMultipleSelectorRemoved:function(e){this.removeMultipleSelector()},onMultipleSelectorUpdated:function(e,t,i,n,o){this.updateMultipleSelector(t,i,n,o)},selectById:function(e){const t=this.scene.getObjectById(e);this.select(t,!1)},select:function(e,t){e&&(this.selectedItems[e.id]||(this.unselect(),e.material=this.materials.selection,e.updateMatrix(),this.selectedItems[e.id]=!0,"floor"===e.sourceType&&"wall"===e.sourceType||this.attachTransformControlsToObject(e),t&&E2DGlobals.e2d.selectById(e.id)))},unselect:function(){if(this.selectedItems){for(const t in this.selectedItems)if(this.selectedItems.hasOwnProperty(t)){var e=this.scene.getObjectById(t);e.material=this.materials[this.objectMaterials[t]],e.updateMatrix()}this.selectedItems=[],this.detachTransformControlsFromObject()}},addSelection:function(e,t,i){if(e){if(!this.selectedItems[e]){const t=this.scene.getObjectById(e);if(!t)return;t.material=this.materials.selection,t.updateMatrix(),this.selectedItems[t.id]=!0}this.detachTransformControlsFromObject(),t&&E2DGlobals.e2d.addSelectionById(e,i,!0)}},removeSelection:function(e,t,i){if(e){if(this.selectedItems[e]){const t=this.scene.getObjectById(e);t.material=this.materials[this.objectMaterials[e]],t.updateMatrix(),delete this.selectedItems[e]}t&&E2DGlobals.e2d.removeSelectionById(e,i,!0)}},addMultipleSelector:function(e){"number"!=typeof e.rotation&&(e.rotation=0);const t=e.x+e.width/2,i=e.y+e.height/2,n=t*this.scale*this.origin.signX,o=i*this.scale*this.origin.signY,s=e.z*this.scale*this.origin.signZ,r=e.width*this.scale,a=e.height*this.scale,l=e.depth*this.scale;let h=-E2DUtils.deg2rad(1*e.rotation);isNaN(h)&&(h=0);const d=new THREE.BoxGeometry(r,a,l);d.applyMatrix((new THREE.Matrix4).makeTranslation(0,0,l/2)),this.multipleSelectorDummy=new THREE.Mesh(d,this.materials.multi),this.multipleSelectorDummy.id="dsID",this.multipleSelectorDummy.name="dsNM",this.multipleSelectorDummy.sourceType="dsST",this.multipleSelectorDummy.userData={initSize:{width:r,height:a,depth:l}},this.multipleSelectorDummy.position.set(n,o,s),this.multipleSelectorDummy.rotation.set(0,0,h,"XYZ"),this.multipleSelectorDummy.castShadow=!1,this.multipleSelectorDummy.receiveShadow=!1,this.multipleSelectorDummy.matrixAutoUpdate=!1,this.multipleSelectorDummy.updateMatrix(),this.scene.add(this.multipleSelectorDummy)},removeMultipleSelector:function(){this.multipleSelectorDummy&&this.removeAndDisposeObject(this.multipleSelectorDummy)},updateMultipleSelector:function(e,t,i,n){if(!this.multipleSelectorDummy)return;const o=(e*this.scale+this.multipleSelectorDummy.userData.initSize.width/2)*this.origin.signX,s=(t*this.scale+this.multipleSelectorDummy.userData.initSize.height/2)*this.origin.signY,r=i*this.scale*this.origin.signZ;let a=-E2DUtils.deg2rad(1*n);isNaN(a)&&(a=0),this.multipleSelectorDummy.position.setX(o),this.multipleSelectorDummy.position.setY(s),this.multipleSelectorDummy.position.setZ(r),this.multipleSelectorDummy.rotation.set(0,0,a,"XYZ"),this.multipleSelectorDummy.updateMatrix()},addCollision:function(e){if(e&&!this.collidingItems[e]){const t=this.scene.getObjectById(e);if(!t)return;t.material=this.materials.collision,this.collidingItems[t.id]=!0}},clearCollisions:function(){if(this.collidingItems){for(const e in this.collidingItems)if(this.collidingItems.hasOwnProperty(e)){const t=this.scene.getObjectById(e);this.selectedItems[e]?t.material=this.materials.selection:t.material=this.materials[this.objectMaterials[e]]}this.collidingItems=[]}},addExternal:function(e){if(e&&!this.externalItems[e]){const t=this.scene.getObjectById(e);if(!t)return;t.material=this.materials.external,this.externalItems[t.id]=!0}},clearExternals:function(){if(this.externalItems){for(const e in this.externalItems)if(this.externalItems.hasOwnProperty(e)){this.scene.getObjectById(e).material=this.materials[this.objectMaterials[e]]}this.externalItems=[]}},changeViewMode:function(e){if(E2DUtils.objectSize(this.objects)<=0)return!1;this.camera.cachedCameraLookAt||this.camera.cachedCameraPosition||(this.camera.cachedCameraLookAt=this.getCameraLookAt(),this.camera.cachedCameraPosition=this.getCameraPosition());const t=this.getGlobalBoundingBox(),i=t.min,n=t.max,o=n.x-i.x,s=n.y-i.y,r=n.z-i.z,a=Math.sqrt(o*o+s*s+r*r);Math.abs(a/2/Math.tan(this.fieldOfView/2));let l=new THREE.Vector3(.5*(i.x+n.x),.5*(i.y+n.y),.5*(i.z+n.z));switch(e){case"1":this.camera.position.set(a*this.origin.signX+l.x,a*this.origin.signY+l.y,a*this.origin.signZ+l.z);break;case"2":this.camera.position.set(i.x-a,l.y,l.z);break;case"3":this.camera.position.set(n.x+a,l.y,l.z);break;case"4":this.camera.position.set(l.x,l.y,n.z+a);break;case"5":this.camera.position.set(l.x,n.y-1.25*a,l.z);break;default:this.camera.position.set(this.camera.cachedCameraPosition.x,this.camera.cachedCameraPosition.y,this.camera.cachedCameraPosition.z),l=new THREE.Vector3(this.camera.cachedCameraLookAt.x,this.camera.cachedCameraLookAt.y,this.camera.cachedCameraLookAt.z),this.camera.cachedCameraLookAt=null,this.camera.cachedCameraPosition=null}return this.camera.up.set(0,0,1),this.camera.lookAt(l),this.controls.target=l,this.controls.update(),!0},loadStlModel:function(e,t){const i=$.Deferred(),n=e+this.shapeFolder+t+".stl";return(new THREE.STLLoader).load(n,function(e){e.vertices&&0===e.vertices.length?i.resolve(null):i.resolve(e)}),i.promise()},loadTexture:function(e){const t=$.Deferred();return(new THREE.TextureLoader).load(e,function(e){e?t.resolve(e):t.resolve(null)}),t.promise()},_addGroup:function(e,t,i,n,o,s,r){const a=E2DGlobals.e2d;t=a.convertPixelsToUserData(t)*this.scale,i=a.convertPixelsToUserData(i)*this.scale,n=a.convertPixelsToUserData(n)*this.scale;const l=e.getShapeCenter(),h=l.x*this.scale*this.origin.signX,d=l.y*this.scale*this.origin.signY,c=e.z*this.scale*this.origin.signZ,u=e.width*this.scale,p=e.height*this.scale,g=e.depth*this.scale,y=-E2DUtils.deg2rad(1*e.rotation),f=new THREE.BoxGeometry(u,p,g);f.applyMatrix((new THREE.Matrix4).makeTranslation(0,0,g/2));const v=new THREE.Mesh(f,this.materials.group);v.id=e.id,v.name=e.source,v.sourceType="group",v.castShadow=!1,v.receiveShadow=!1,v.userData={initSize:{x:u,y:p,z:g}},v.position.set(h,d,c),v.rotation.set(0,0,y,"XYZ"),this.objects[v.id]=v,this.objectMaterials[v.id]="group",this.scene.add(v),o?this.select(v):s&&this.addSelection(e.id);for(let o=0,s=r.length;o<s;o++){const s=r[o],l=a.convertPixelsToUserData(s.width),h=a.convertPixelsToUserData(s.height),d=a.convertPixelsToUserData(s.depth),c=InsertedShape.CloneShape(e);c.source=s.source,c.id=v.id+"_"+o,c.width=u*l/t,c.height=p*h/i,c.depth=g*d/n,c.x=a.convertPixelsToUserData(s.x)*(c.width/l),c.y=a.convertPixelsToUserData(s.y)*(c.height/h),c.z=a.convertPixelsToUserData(s.z)*(c.depth/d),c.rotation=void 0===s.rotation?0:s.rotation,c.color3D=s.color?s.color:e.color3D,c.colorOpacity3D=s.colorOpacity?s.colorOpacity:e.colorOpacity3D,this._addObject(c,!1,!1,v)}},_addTexturedObject:function(e,t,i,n){let o=this.renderer.cachedTextures.get(e.source);o||(o=this.loadTexture(n),this.renderer.cachedTextures.set(e.source,o));const s=this;o.done(function(o){s._addTexturedObjectAsync(e,t,i,n,o)})},_addTexturedObjectAsync:function(e,t,i,n,o){const s=e.getShapeCenter(),r=s.x*this.scale*this.origin.signX,a=s.y*this.scale*this.origin.signY,l=e.z*this.scale*this.origin.signZ,h=e.width*this.scale,d=e.height*this.scale,c=e.depth*this.scale,u=-E2DUtils.deg2rad(1*e.rotation),p=new THREE.BoxGeometry(h,d,c);p.applyMatrix((new THREE.Matrix4).makeTranslation(0,0,c/2));const g=new THREE.MeshPhongMaterial({map:o,transparent:!0,side:THREE.DoubleSide}),y=[new THREE.Vector2(.5,1),new THREE.Vector2(0,1),new THREE.Vector2(0,.666),new THREE.Vector2(.5,.666)],f=[new THREE.Vector2(.5,.666),new THREE.Vector2(1,.666),new THREE.Vector2(1,1),new THREE.Vector2(.5,1)],v=[new THREE.Vector2(.5,.333),new THREE.Vector2(.5,.666),new THREE.Vector2(0,.666),new THREE.Vector2(0,.333)],m=[new THREE.Vector2(.5,.666),new THREE.Vector2(.5,.333),new THREE.Vector2(1,.333),new THREE.Vector2(1,.666)],S=[new THREE.Vector2(0,.333),new THREE.Vector2(0,0),new THREE.Vector2(.5,0),new THREE.Vector2(.5,.333)],E=[new THREE.Vector2(1,0),new THREE.Vector2(1,.333),new THREE.Vector2(.5,.333),new THREE.Vector2(.5,0)];p.faceVertexUvs[0]=[],p.faceVertexUvs[0][0]=[y[0],y[1],y[3]],p.faceVertexUvs[0][1]=[y[1],y[2],y[3]],p.faceVertexUvs[0][2]=[f[0],f[1],f[3]],p.faceVertexUvs[0][3]=[f[1],f[2],f[3]],p.faceVertexUvs[0][4]=[v[0],v[1],v[3]],p.faceVertexUvs[0][5]=[v[1],v[2],v[3]],p.faceVertexUvs[0][6]=[m[0],m[1],m[3]],p.faceVertexUvs[0][7]=[m[1],m[2],m[3]],p.faceVertexUvs[0][8]=[S[0],S[1],S[3]],p.faceVertexUvs[0][9]=[S[1],S[2],S[3]],p.faceVertexUvs[0][10]=[E[0],E[1],E[3]],p.faceVertexUvs[0][11]=[E[1],E[2],E[3]];const D=new THREE.Mesh(p,g);D.id=e.id,D.name=e.source,D.sourceType="textured",D.castShadow=!0,D.receiveShadow=!0,D.userData={initSize:{x:h,y:d,z:c}},D.position.set(r,a,l),D.rotation.set(0,0,u,"XYZ"),D.matrixAutoUpdate=!1,D.updateMatrix(),this.materials[n]=g,this.objectMaterials[D.id]=n,this.objects[D.id]=D,this.scene.add(D),t?this.select(D):i&&this.addSelection(e.id)},_addBackgroundObject:function(e,t,i){const n=this;(new Converter).svgItemToImage(document.getElementById(e.id),null).done(function(o){n._addBackgroundObjectAsync(e,t,i,o)})},_addBackgroundObjectAsync:function(e,t,i,n){const o=e.getShapeCenter(),s=o.x*this.scale*this.origin.signX,r=o.y*this.scale*this.origin.signY,a=e.z*this.scale*this.origin.signZ,l=e.width*this.scale,h=e.height*this.scale,d=.5*this.scale,c=-E2DUtils.deg2rad(1*e.rotation),u=new THREE.BoxGeometry(l,h,d);u.applyMatrix((new THREE.Matrix4).makeTranslation(0,0,d/2));let p=this.renderer.cachedTextures.get(e.source);p||(p=new THREE.Texture(n),this.renderer.cachedTextures.set(e.source,p)),p.needsUpdate=!0;const g=[new THREE.MeshBasicMaterial({color:16777215}),new THREE.MeshBasicMaterial({color:16777215}),new THREE.MeshBasicMaterial({color:16777215}),new THREE.MeshBasicMaterial({color:16777215}),new THREE.MeshBasicMaterial({map:p,transparent:!0}),new THREE.MeshBasicMaterial({color:16777215})],y=new THREE.Mesh(u,g);y.id=e.id,y.name=e.source,y.sourceType="background",y.userData={initSize:{x:l,y:h,z:d}},y.position.set(s,r,a),y.rotation.set(0,0,c,"XYZ"),this.objects[y.id]=y,this.scene.add(y),t?this.select(y):i&&this.addSelection(e.id)},_addObject:function(e,t,i,n){const o=e.getFullSource?e.getFullSource():e.source;let s=this.renderer.cachedObjects.get(o);s||(s=this.loadStlModel(e.sourceLibrary,e.source),this.renderer.cachedObjects.set(o,s));const r=this;s.done(function(o){r._addObjectAsync(e,t,i,n,o)})},_addObjectAsync:function(e,t,i,n,o){if(!o)return;o.computeVertexNormals();let s=0,r=0;if(n)s=e.x*this.scale*this.origin.signX,r=e.y*this.scale;else{var a=e.getShapeCenter();s=a.x*this.scale*this.origin.signX,r=a.y*this.scale*this.origin.signY}let l=e.z*this.scale*this.origin.signZ;const h=e.width*this.scale,d=e.height*this.scale,c=e.depth*this.scale,u=new THREE.Mesh(o,this.materials.default);u.id=e.id,u.name=e.source,u.sourceType="stl",u.position.set(s,r,l);const p=(new THREE.Box3).setFromObject(u).getSize(new THREE.Vector3),g=1*h/p.x,y=1*d/p.y,f=1*c/p.z;u.scale.set(g,y,f),u.userData={initSize:p};let v=0,m=0,S=0;if("string"==typeof e.rotation&&e.rotation.indexOf(";")>=0){const t=e.rotation.split(";");v=t.length>=1?1*t[0]:0,m=t.length>=2?1*t[1]:0,S=t.length>=3?1*t[2]:0}else S=-E2DUtils.deg2rad(1*e.rotation);u.rotation.set(v,m,S,"XYZ"),this.objectMaterials[u.id]="default",this.objectLineMaterials[u.id]="default",this.updateObjectStyle(u,e),u.matrixAutoUpdate=!1,u.updateMatrix(),u.castShadow=this.objectCastShadows,u.receiveShadow=this.objectReceiveShadows,n?(u.sourceType="groupItem",this.objectChildren[n.id]?this.objectChildren[n.id][this.objectChildren[n.id].length]=u:this.objectChildren[n.id]=[u],n.add(u)):(this.objects[u.id]=u,this.scene.add(u)),t?this.select(u):i&&this.addSelection(e.id)},_addPolyLine:function(e,t,i){this.polylines[e.id]=[],this._addFloor(e),this._addWall(e,t,i)},_addFloor:function(e){if(this.enableFloor&&e.path)if(this.floorDefinition.image){let t=this.renderer.cachedTextures.get("floor");t||(t=this.loadTexture(this.floorDefinition.image),this.renderer.cachedTextures.set("floor",t));const i=this;t.done(function(t){t.wrapS=THREE.RepeatWrapping,t.wrapT=THREE.RepeatWrapping,t.repeat.set(.118,.118),i.materials.floor=new THREE.MeshBasicMaterial({map:t,transparent:!0}),i._addFloorAsync(e)})}else this._addFloorAsync(e)},_addFloorAsync:function(e){const t=E2DUtils.splitPath(e.path);if(!t||0===t.length)return;let i=0,n=(this.floorDefinition.thickness||.5)*this.scale;n<0&&(i=n,n*=-1),t[0].x===t[t.length-1].x&&t[0].y===t[t.length-1].y||(t[t.length]={x:t[0].x,y:t[0].y});for(let e=0,i=t.length;e<i;e++){let i=t[e];i.x*=this.scale*this.origin.signX,i.y*=this.scale*this.origin.signY}const o=new THREE.Shape(t),s={steps:2,depth:n,bevelEnabled:!1},r=new THREE.ExtrudeBufferGeometry(o,s),a=new THREE.Mesh(r,this.materials.floor);a.id=e.id+"_floor",a.name=e.source+"_floor",a.sourceType="floor",a.castShadow=!1,a.receiveShadow=!0,a.visible=this.enableFloor,a.matrixAutoUpdate=!1,a.position.setZ(i),a.updateMatrix(),this.objectMaterials[a.id]="floor",this.objects[a.id]=a,this.polylines[e.id].floor=a.id,this.scene.add(a)},_addWall:function(e,t,i){if(!this.enableWalls||!e.path)return;const n=new THREE.Geometry;this.generateWallGeometryMerge(n,e.path);const o=new THREE.Mesh(n,this.materials.wall);o.id=e.id+"_wall",o.name=e.source+"_wall",o.sourceType="wall",o.castShadow=!1,o.receiveShadow=!1,o.visible=this.showWalls,o.matrixAutoUpdate=!1,o.position.setZ(0),o.updateMatrix(),this.objectMaterials[o.id]="wall",this.objects[o.id]=o,this.polylines[e.id].wall=o.id,this.scene.add(o),t?this.select(o):i&&this.addSelection(e.id)},addObject:function(e,t,i,n){"poly-line"===e.source?this._addPolyLine(e,i,n):t&&e.group3d?this._addGroup(e,t.width,t.height,t.depth,i,n,e.group3d):t&&t.group3d?this._addGroup(e,t.width,t.height,t.depth,i,n,t.group3d):t&&t.srcTexture3D?this._addTexturedObject(e,i,n,t.srcTexture3D):e.hasBehaviour("(BACKGROUND)")?this._addBackgroundObject(e,i,n):this._addObject(e,i,n)},updateObject:function(e){if(!e)return;const t=this.scene.getObjectById(e.id);if(!t)return;const i=e.getShapeCenter(),n=i.x*this.scale*this.origin.signX,o=i.y*this.scale*this.origin.signY,s=e.z*this.scale*this.origin.signZ,r=e.width*this.scale,a=e.height*this.scale,l=e.depth*this.scale,h=-E2DUtils.deg2rad(1*e.rotation);if(this.isBelowThreshold(n,t.position.x)||t.position.setX(n),this.isBelowThreshold(o,t.position.y)||t.position.setY(o),this.isBelowThreshold(s,t.position.z)||t.position.setZ(s),t.userData&&t.userData.initSize){const e=t.userData.initSize,i=r/e.x,n=a/e.y,o=l/e.z;this.isBelowThreshold(i,t.scale.x)||t.scale.setX(i),this.isBelowThreshold(n,t.scale.y)||t.scale.setY(n),"background"===t.sourceType||this.isBelowThreshold(o,t.scale.z)||t.scale.setZ(o)}this.isBelowThreshold(h,t.rotation.z)||t.rotation.set(0,0,h,"XYZ"),this.updateObjectStyle(t,e),t.updateMatrix()},updatePolyLine:function(e){this._updateFloor(e),this._updateWall(e)},_updateFloor:function(e){if(!this.enableFloor||!e||!e.path)return;const t=this.scene.getObjectById(e.id+"_floor");t&&(this.removeObject(t.id),this._addFloor(e),t.updateMatrix())},_updateWall:function(e){if(!this.enableWalls||!e||!e.path)return;const t=this.scene.getObjectById(e.id+"_wall");t&&(this.generateWallGeometryMerge(t.geometry,e.path),t.updateMatrix())},generateWallGeometryVF:function(e,t){e.vertices=[],e.faces=[];const i=E2DUtils.splitPath(t);for(let t=0,n=i.length;t<n;t++){const n=i[t];n.x*=this.scale*this.origin.signX,n.y*=this.scale*this.origin.signY,e.vertices.push(new THREE.Vector3(n.x,n.y,0)),e.vertices.push(new THREE.Vector3(n.x,n.y,this.wallHeight))}let n=e.vertices.length-2;for(let t=0,i=e.vertices.length;t<i;t+=2)e.faces.push(new THREE.Face3(t,t+1,n)),e.faces.push(new THREE.Face3(t+1,n+1,n)),n=t;e.computeVertexNormals(),e.computeFaceNormals(),e.colorsNeedUpdate=!0,e.elementsNeedUpdate=!0,e.groupsNeedUpdate=!0,e.lineDistancesNeedUpdate=!0,e.normalsNeedUpdate=!0,e.uvsNeedUpdate=!0},generateWallGeometryMerge:function(e,t){e.vertices=[],e.faces=[];const i=this.wallHeight*this.scale,n=this.wallThickness*this.scale,o=E2DUtils.splitPath(t);if(2===o.length&&E2DUtils.isPointTooClose(o[0],o[1],.1)){const t=o[0];t.x*=this.scale*this.origin.signX,t.y*=this.scale*this.origin.signY;const s=new THREE.Matrix4;s.makeTranslation(t.x,t.y,i/2);const r=new THREE.BoxGeometry(n,n,i);e.merge(r,s)}else for(let t=0,s=o.length-1;t<s;t++){const s=o[t],r=o[t+1],a=E2DUtils.midpointOfLineEx(s,r);a.x*=this.scale*this.origin.signX,a.y*=this.scale*this.origin.signY;let l=E2DUtils.getSegmentLength(s.x,s.y,r.x,r.y)*this.scale,h=E2DUtils.getSegmentRotation(s.x,s.y,r.x,r.y);h=-E2DUtils.deg2rad(1*h);const d=new THREE.Euler(0,0,h,"XYZ"),c=new THREE.Matrix4;c.makeRotationFromEuler(d);const u=new THREE.Matrix4;u.makeTranslation(a.x,a.y,i/2),u.multiply(c);const p=new THREE.BoxGeometry(l,n,i);e.merge(p,u)}e.colorsNeedUpdate=!0,e.elementsNeedUpdate=!0,e.groupsNeedUpdate=!0,e.lineDistancesNeedUpdate=!0,e.normalsNeedUpdate=!0,e.uvsNeedUpdate=!0},updateObjectStyle:function(e,t){if(!e.material)return;if("textured"===e.sourceType)return;if("group"===e.sourceType&&(!e.children||0===e.children.length))return;let i=null,n=null;if(t.color3D){t.color3D.trim();const o=t.color3D+"_"+t.colorOpacity3D;(i=this.materials[o])||(i=new THREE.MeshPhongMaterial({color:t.color3D}),"number"==typeof(n=1*t.colorOpacity3D)&&(i.opacity=n,i.transparent=0<=n&&n<1),this.materials[o]=i),"group"!==this.objectMaterials[e.id]&&this.objectMaterials[e.id]!==o&&(this.objectMaterials[e.id]=o)}let o=null;if(t.lineColor3D){t.lineColor3D.trim();const i="line_"+t.lineColor3D+"_"+t.lineOpacity3D;this.objectLineMaterials[e.id]!==i&&((o=this.materials[i])||(o=new THREE.LineBasicMaterial({color:t.lineColor3D,linewidth:2}),"number"==typeof(n=1*t.lineOpacity3D)&&(o.opacity=n,o.transparent=0<=n&&n<1),this.materials[i]=o),this.objectLineMaterials[e.id]=i)}if(i||o){let t=e.children;0===t.length&&(t=[e]);for(let e=0,n=t.length;e<n;e++)if(i&&(t[e].material=i),o){let i=this.edgesBoxes[t[e].id];if(!i){const n=new THREE.EdgesGeometry(t[e].geometry);(i=new THREE.LineSegments(n,this.materials.edge)).sourceType="edgeBox",t[e].add(i),this.edgesBoxes[t[e].id]=i}i.material=o}}},removeObject:function(e){if(this.polylines[e])return this.removeObject(this.polylines[e].floor),this.removeObject(this.polylines[e].wall),void delete this.polylines[e];const t=this.scene.getObjectById(e);t&&t.id&&(this.unselect(),this.removeObjectChildren(t.id),this.removeObjectEdges(t.id),this.removeAndDisposeObject(t),delete this.objects[t.id])},displayGrid:function(e){this.floorGrid&&(this.floorGrid.visible=e)},displayShadows:function(e){this.directionalLight&&(this.directionalLight.castShadow=e,this.directionalLight.shadow.camera.updateProjectionMatrix()),this.spotLight&&(this.spotLight.castShadow=e,this.spotLight.shadow.camera.updateProjectionMatrix())},displayWalls:function(e){if(this.showWalls=e,this.objects){const e=Object.values(this.objects);if(e&&e.length>0)for(let t=0,i=e.length;t<i;t++){const i=e[t];"wall"===i.sourceType&&(i.visible=this.showWalls)}}},removeObjectChildren:function(e){const t=this.objectChildren[e.id];if(t&&t.length>0){for(let e=0,i=t.length;e<i;e++)this.removeAndDisposeObject(t[e]);delete this.objectChildren[e.id]}},removeObjectEdges:function(e){const t=this.edgesBoxes[e.id];t&&(e.remove(t),t.geometry&&t.geometry.dispose&&"function"==typeof t.geometry.dispose&&t.geometry.dispose(),delete this.edgesBoxes[e.id])},removeAndDisposeObject:function(e){e&&(e.visible=!1,"background"!==e.sourceType&&"edgeBox"!==e.sourceType&&"textured"!==e.sourceType||(e.material&&e.material.dispose&&"function"==typeof e.material.dispose&&e.material.dispose(),e.geometry&&e.geometry.dispose&&"function"==typeof e.geometry.dispose&&e.geometry.dispose()),e.parent.remove(e))},cloneObject:function(e,t,i,n,o,s,r,a,l,h,d,c,u){const p=e.clone();p.id=i,p.name=e.name,p.sourceFile=e.sourceFile,p.sourceType=e.sourceType,p.position.set(n*this.origin.signX,o*this.origin.signY,s*this.origin.signZ);const g=e.userData.initSize,y=1*r/g.x,f=1*a/g.y,v=1*l/g.z;p.scale.set(y,f,v),p.userData={initSize:g},p.rotation.set(0,0,-E2DUtils.deg2rad(1*h)),u?(this.objectChildren[u.id]?this.objectChildren[u.id][this.objectChildren[u.id].length]=p:this.objectChildren[u.id]=[p],u.add(p)):(this.objects[p.id]=p,this.scene.add(p)),d?this.select(p):c&&this.addSelection(i)},attachTransformControlsToObject:function(e){if("background"===e.sourceType)return;let t=!1,i=!1,n=!1;const o=E2DGlobals.e2d.insertedShapes.getShapeById(e.id);if(o){if(o.hasBehaviour("NOMOVE")||o.hasBehaviour("NOMOVE3D"))return;t=o.hasBehaviour("NOHMOVE")||o.hasBehaviour("NOXMOVE")||o.hasBehaviour("NOXMOVE3D"),i=o.hasBehaviour("NOVMOVE")||o.hasBehaviour("NOYMOVE")||o.hasBehaviour("NOYMOVE3D"),n=o.hasBehaviour("NODMOVE")||o.hasBehaviour("NOZMOVE")||o.hasBehaviour("NOZMOVE3D")}this.transformControls.attach(e,t,i,n)},detachTransformControlsFromObject:function(){this.transformControls.detach()},getGlobalBoundingBox:function(){const e=new THREE.Box3,t=E2DUtils.objectValues(this.objects);for(let i=0,n=t.length;i<n;i++)e.union((new THREE.Box3).setFromObject(t[i]));return e},getCameraPosition:function(){return{x:this.camera.position.x,y:this.camera.position.y,z:this.camera.position.z}},setCameraPosition:function(e){e&&(this.camera.position.set(e.x,e.y,e.z),this.controls.update())},getCameraLookAt:function(){return{x:this.controls.target.x,y:this.controls.target.y,z:this.controls.target.z}},setCameraLookAt:function(e){if(!e)return;const t=new THREE.Vector3(e.x,e.y,e.z);this.camera.lookAt(t),this.controls.target=t,this.controls.update()},getBackgroundColor:function(){return this.scene.background.getHexString?"#"+this.scene.background.getHexString():null},setBackgroundColor:function(e){e&&(this.scene.background=new THREE.Color(e))},setBackgroundImage:function(e){e&&(this.scene.background=(new THREE.TextureLoader).load(e))},getAmbientLightColor:function(){return this.ambientLight&&this.ambientLight.color.getHexString?"#"+this.ambientLight.color.getHexString():null},setAmbientLightColor:function(e){this.ambientLight&&e&&(this.ambientLight.color=new THREE.Color(e))},getDirectionalLightColor:function(){return this.directionalLight&&this.directionalLight.color.getHexString?"#"+this.directionalLight.color.getHexString():null},setDirectionalLightColor:function(e){this.directionalLight&&e&&(this.directionalLight.color=new THREE.Color(e))},getHemiLightSkyColor:function(){return this.hemiLight&&this.hemiLight.color.getHexString?"#"+this.hemiLight.color.getHexString():null},setHemiLightSkyColor:function(e){this.hemiLight&&e&&(this.hemiLight.color=new THREE.Color(e))},getHemiLightGroundColor:function(){return this.hemiLight&&this.hemiLight.groundColor.getHexString?"#"+this.hemiLight.groundColor.getHexString():null},setHemiLightGroundColor:function(e){this.hemiLight&&e&&(this.hemiLight.groundColor=new THREE.Color(e))},getSpotLightColor:function(){return this.spotLight&&this.spotLight.color.getHexString?"#"+this.spotLight.color.getHexString():null},setSpotLightColor:function(e){this.spotLight&&e&&(this.spotLight.color=new THREE.Color(e))},getDirectionalLightShadowMapSize:function(){return this.directionalLight&&this.directionalLight.shadow&&this.directionalLight.shadow.mapSize?this.directionalLight.shadow.mapSize.width:1024},setDirectionalLightShadowMapSize:function(e){this.directionalLight&&e&&(this.directionalLight.shadow.mapSize.width=e,this.directionalLight.shadow.mapSize.height=e)},showDirectionalLightHelper:function(){this.directionalLight&&!this.directionalLightHelper&&(this.directionalLightHelper=new THREE.DirectionalLightHelper(this.directionalLight,10),this.scene.add(this.directionalLightHelper))},hideDirectionalLightHelper:function(){this.directionalLightHelper&&(this.scene.remove(this.directionalLightHelper),this.directionalLightHelper.dispose(),this.directionalLightHelper=null)},getDirectionalLightPosition:function(){return this.directionalLight?{x:this.directionalLight.position.x,y:this.directionalLight.position.y,z:this.directionalLight.position.z}:null},setDirectionalLightPosition:function(e){this.directionalLight&&e&&this.directionalLight.position.set(e.x,e.y,e.z)},getShadows:function(){return{cast:this.objectCastShadows,receive:this.objectReceiveShadows}},setShadows:function(e){e&&(e.hasOwnProperty("cast")&&(this.objectCastShadows=e.cast),e.hasOwnProperty("receive")&&(this.objectReceiveShadows=e.receive))},fitAll:function(e,t){t=t||new THREE.Vector3(0,0,0);const i=e.max,n=e.min,o=[n.x,i.x],s=[n.y,i.y],r=[n.z,i.z],a=new THREE.Matrix4;a.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse);let l=0;for(let e=0;e<2;e++)for(let t=0;t<2;t++)for(let i=0;i<2;i++){const n=new THREE.Vector4(o[e],s[t],r[i]);n.applyMatrix4(a),n.x=(n.x+1)*this.renderer.domElement.clientWidth/2,n.y=(1-n.y)*this.renderer.domElement.clientHeight/2;const h=new THREE.Vector4(o[e],s[t],r[i]);h.applyMatrix4(a),l=Math.abs(h.x)>l?Math.abs(h.x):l,l=Math.abs(h.y)>l?Math.abs(h.y):l}const h=Math.abs(.85-l);if(h>.05){const e=new THREE.Vector3(this.camera.position.x,this.camera.position.y,this.camera.position.z),i=new THREE.Vector3(t.x,t.y,t.z);let n=.1*(1+h);l>.85&&(n*=-1),i.multiplyScalar(n),e.add(i),this.camera.position.set(e.x,e.y,e.z)}},rotateAroundObjectAxis:function(e,t,i){if(!this.isBelowThreshold(e.rotation.z,i)){const n=new THREE.Matrix4;n.makeRotationAxis(t.normalize(),i),e.matrix.multiply(n),e.rotation.setFromRotationMatrix(e.matrix)}},rotateAroundWorldAxis:function(e,t,i){if(!this.isBelowThreshold(e.rotation.z,i)){const n=new THREE.Matrix4;n.makeRotationAxis(t.normalize(),i),n.multiply(e.matrix),e.matrix=n,e.rotation.setFromRotationMatrix(e.matrix)}},rotateAroundWorldX:function(e,t){const i=new THREE.Euler(t,0,0,"XYZ");e.position.applyEuler(i)},rotateAroundWorldY:function(e,t){const i=new THREE.Euler(0,t,0,"XYZ");e.position.applyEuler(i)},rotateAroundWorldZ:function(e,t){const i=new THREE.Euler(0,0,t,"XYZ");e.position.applyEuler(i)},isBelowThreshold:function(e,t){return Math.abs(e-t)<=this.nearThreshold},getInsertedObjectById:function(e){return this.scene.getObjectById(e)},getInsertedObjectByName:function(e){return this.scene.getObjectByName(e)},getParentObject3D:function(e){return e?"Mesh"===e.type&&"group"===e.sourceType?e:"Mesh"===e.type&&"stl"===e.sourceType?e:"Mesh"===e.type&&"textured"===e.sourceType?e:"Mesh"===e.type&&"floor"===e.sourceType?null:"Mesh"===e.type&&"wall"===e.sourceType?e:"Object3D"===e.type&&"obj"===e.sourceType?e:this.getParentObject3D(e.parent):null},getMesh:function(e){return"Object3D"===e.type?e.children[0]:e},renderON:function(e){if(!this.renderer)return;if(this.renderer.render(this.scene,this.camera),this.enableDinamicLights&&this.spotLight){var t=new THREE.Vector3(0,0,200).applyQuaternion(this.camera.quaternion).add(this.camera.position);this.spotLight.position.set(t.x-10,t.y+50,t.z+10);var i=new THREE.Vector3(0,0,-1e4).applyQuaternion(this.camera.quaternion).add(this.camera.position);this.spotLight.target.position.set(i.x,i.y,i.z)}const n=this;this.requestTimerID=setTimeout(function(){n.requestID=requestAnimationFrame(function(){n.renderON(e)})},1e3/e)},renderOFF:function(){this.requestTimerID&&(clearTimeout(this.requestTimerID),this.requestTimerID=null),this.requestID&&(cancelAnimationFrame(this.requestID),this.requestID=null)},renderSingle:function(){const e=this;this.requestID=requestAnimationFrame(function(){e.renderer.render(e.scene,e.camera)})},resize:function(e,t){this.width=e,this.height=t,this.camera.aspect=this.width/this.height,this.camera.updateProjectionMatrix(),this.renderer.setSize(this.width,this.height)},toPng:function(){const e=document.querySelector("#"+this.root+" canvas");return e?(new Converter).canvasToPng(e):null}},$(function(){E2DGlobals.initializeEditor()}),E2DGlobals={e2d:null,e2dLayout:null,visibleProperties:"",doBackgroundCheckOnly:!1,dragFps:4,defaultFps:30,dragTimerMode:!0,initializeEditor:function(){if(window.SVGRenderer){var e=$("#E2DEditor");e.droppable({accept:".paletteItem",greedy:!0,tolerance:"fit",drop:E2DEvents.createNewShape});var t=new SVGRenderer;E2DGlobals.e2d=new E2DEditor(e,t),E2DGlobals.e2dLayout=$("#E2DContainer").layout({livePaneResizing:!0,north__closable:!1,north__resizable:!1,north__slidable:!1,north__spacing_open:0,north__spacing_closed:0,east__initHidden:!0,east__resizable:!0,east__slidable:!1,east__size:"40%",east__onclose:E2DEvents.onCloseEastPanel,east__onresize:E2DEvents.onResizeEastPanel,west__initClosed:!1,west__resizable:!0,west__slidable:!1,west__size:"15%",west__childOptions:{minSize:200,south__initHidden:!0,south__resizable:!0,south__slidable:!0,south__size:"35%"},south__initHidden:!0,south__closable:!1,south__resizable:!1,south__slidable:!1,south__spacing_open:0,south__spacing_closed:0}),$(window).on("resize",E2DEvents.onResizeWindow),$("body").on("keypress",E2DEvents.trapDefaultKeys)}else setTimeout(E2DGlobals.initializeEditor,250)},isShapesLoadPending:function(){return E2DGlobals.e2d.isShapesLoadPending()},getPreferencesData:function(){return"V4"},getShapesData:function(e,t,i){var n=E2DGlobals.e2d;!t&&n.checkCollisions&&n.performCheckCollisionsFULL(),!t&&n.checkInclusions&&n.performCheckInclusionsFULL(),!i&&n.includeConnectionPoints&&n.performIncludeConnectionPoints();var o=n.insertedShapes.getShapes(!0);return e?o:JSON.stringify(o)},getShapePropertyData:function(){var e=E2DGlobals.e2d,t="";return e.groupProp?t=e.groupProp:e.groupPropID&&(t=e.libraryProperties[e.groupPropID]),t&&(t.eventHandlers&&(t.eventHandler=e.getEventHandler("regrouped",t.id),t.eventHandlers=JSON.stringify(t.eventHandlers)),t.custom&&(t.custom=JSON.stringify(t.custom)),t.connectionPoints&&(t.connectionPoints=JSON.stringify(t.connectionPoints)),t.group2d&&t.group2d.shapes&&(t.group2dShapes=JSON.stringify(t.group2d.shapes)),t.group2d&&t.group2d.connectors&&(t.group2dConnectors=JSON.stringify(t.group2d.connectors)),delete t.group2d,t.group3d&&(t.group3d=JSON.stringify(t.group3d)),t=JSON.stringify(t)),t},getDrawingData:function(){var e=E2DGlobals.e2d;e.removeSystemShapes();var t=$("#_pageWidth").val(),i=$("#_pageHeight").val(),n=e.renderer.getGlobalBoundingBox();n&&(t=n.x2,i=n.y2);var o=e.renderer.cloneSVGRoot(t,i);if(o.removeChild&&o.querySelector){var s=o.getElementById(E2DGlobals.e2d.ORIGIN_ID);s&&o.removeChild(s);var r=o.getElementById(E2DGlobals.e2d.CUSTOM_ORIGIN_ID);r&&o.removeChild(r)}return o.outerHTML},getViewportData:function(e){const t=E2DGlobals.e2d,i={};return i.groupInfo=t.groupInfo,i.layers=t.libraryLayers,i.scroll=t.getScroll(),i.splitters=t.getSplitters(),i.toggles=t.getToggles(),i.zoom=t.getZoom(),i.e3dActive=t.getE3DActive(),i.e3dData=t.getE3DViewportData(),e?i:JSON.stringify(i)},setPreferencesData:function(e){if(E2DGlobals.e2d){var t=E2DGlobals.e2d;if(e&&"string"==typeof e){e=e.trim();var i=JSON.parse(e);E2DGlobals.doBackgroundCheckOnly=i.DoBackgroundCheckOnly,E2DGlobals.doBackgroundCheckOnly&&$("#_toolbar").css("display","none"),t.setShapeLibrary(i.ShapeLibrary,i.ShapeLibraryHideList,i.ShapeLibraryOpenList,i.PageLanguage),t.setShapeEvents(i.ShapeEvents),t.setPreferencesData(i)}else t.preferencesLoaded.resolve()}else alert("RD Editor 2D (setPreferencesData): not properly initialized.\nPlease, reload the page.")},setShapesData:function(e){if(E2DGlobals.e2d){var t=E2DGlobals.e2d,i=t.insertedShapes.getCount();if(!e||"string"!=typeof e)return i>0&&t.removeAll(!0),void t.shapesLoaded.resolve();E2DGlobals.showLockLayer(!0),t.shapesLoaded.done(function(){E2DGlobals.showLockLayer(!1)}),e=e.trim();var n=JSON.parse(e);0===i?t.setShapesData(n):t.mergeShapesData(n)}else alert("RD Editor 2D (setShapesData): not properly initialized.\nPlease, reload the page.")},setBackgroundData:function(e,t,i){E2DGlobals.e2d?e&&"string"==typeof e&&(e=e.trim(),E2DGlobals.e2d.setBackgroundData(e,t,i)):alert("RD Editor 2D (setBackgroundData): not properly initialized.\nPlease, reload the page.")},setViewportData:function(e){if(E2DGlobals.e2d){var t=E2DGlobals.e2d;if(!e||"string"!=typeof e||e.length&&e.length<=10)t.viewportLoaded.resolve();else{e=e.trim();var i=JSON.parse(e);t.setViewportData(i)}}else alert("RD Editor 2D (setViewportData): not properly initialized.\nPlease, reload the page.")},disposeEditor:function(e){E2DGlobals.e2d&&E2DGlobals.e2d.disposeEditor(e)},restoreEditor:function(){E2DGlobals.e2d&&E2DGlobals.e2d.restoreEditor()},showSplashScreen:function(e){e?document.getElementById("_splashScreen").classList.remove("hidden"):E2DGlobals.doBackgroundCheckOnly||document.getElementById("_splashScreen").classList.add("hidden")},showLockLayer:function(e){e?document.getElementById("_lockLayer").classList.remove("hidden"):document.getElementById("_lockLayer").classList.add("hidden")},exportImage2D:function(){const e=E2DGlobals.e2d;if(e.exportImage2D){const t=e.container.parent(),i=t.scrollLeft(),n=t.scrollTop(),o=E2DGlobals.e2dLayout.state.center.innerWidth,s=E2DGlobals.e2dLayout.state.center.innerHeight,r=e.zoom;(new Converter).svgToPng(e.renderer.cloneSVGRoot(),i,n,o,s,r,screen).done(E2DGlobals.exportImage2DAsync)}},exportImage2DAsync:function(e){if(E2DGlobals.e2d.exportImage2D&&E2DGlobals.e2d.image2DExported){const t=E2DEvents.doSubmitImageAsync("image2d.png",e);t&&t.always(function(){E2DGlobals.e2d.image2DExported.resolve()})}},exportImage3D:function(){const e=E2DGlobals.e2d;if(e.exportImage3D){(new Converter).canvasToPng(e.renderer3d.renderer.domElement).done(E2DGlobals.exportImage3DAsync)}},exportImage3DAsync:function(e){if(E2DGlobals.e2d.exportImage3D&&E2DGlobals.e2d.image3DExported){const t=E2DEvents.doSubmitImageAsync("image3d.png",e);t&&t.always(function(){E2DGlobals.e2d.image3DExported.resolve()})}}},E2DEditor.prototype.disposeEditor=function(e){this.renderer.dispose(),E2DGlobals.showLockLayer(!0),this.image2DExported=null,this.image3DExported=null,this.shapesLoaded=$.Deferred(),this.detachEditorEvents(),this.clearClipboard(),this.unselect(),e&&this.undoManager.clear(),E2DEvents.checkWestLayout()},E2DEditor.prototype.restoreEditor=function(){this.renderer.initSystemShapes(this.shapeLibraryList),this.attachEditorEvents(),this.clearClipboard(),this.shapesLoaded=$.Deferred(),this.groupProp=null,this.groupPropID=null,this.exportImage2D&&(this.image2DExported=$.Deferred(),E2DEvents.doSubmitImageAsync("image2d.png",null)),this.exportImage3D&&(this.image3DExported=$.Deferred(),E2DEvents.doSubmitImageAsync("image3d.png",null)),window.focus()},E2DEditor.prototype.attachEditorEvents=function(){this.container.on("vmousedown",E2DEvents.onMouseDown),this.container.on("vmouseup",E2DEvents.onMouseUp),this.container.on("selectstart",E2DEvents.onSelectStart),this.container.on("touchstart",E2DEvents.onTouchStart),this.container.on("touchmove",E2DEvents.onTouchMove),this.container.on("touchend",E2DEvents.onTouchEnd),this.container.on("gestureend",E2DEvents.onGestureEnd);var e=$(this.container[0].ownerDocument);e.on("keyup",E2DEvents.onKeyUp),e.on("keydown",E2DEvents.onKeyDown),this.mObserver=new MutationObserver(function(e){$.when(E2DGlobals.e2d.preferencesLoaded,E2DGlobals.e2d.viewportLoaded).done(function(){E2DEvents.checkWestLayout()})});var t=document.getElementById("E2DWestSouthContainer");this.mObserver.observe(t,{attributes:!0,attributeFilter:["style"],subtree:!0})},E2DEditor.prototype.detachEditorEvents=function(){this.container.off("vmousedown",E2DEvents.onMouseDown),this.container.off("vmouseup",E2DEvents.onMouseUp),this.container.off("selectstart",E2DEvents.onSelectStart),this.container.off("touchstart",E2DEvents.onTouchStart),this.container.off("touchmove",E2DEvents.onTouchMove),this.container.off("touchend",E2DEvents.onTouchEnd),this.container.off("gestureend",E2DEvents.onGestureEnd);var e=$(this.container[0].ownerDocument);e.off("keyup",E2DEvents.onKeyUp),e.off("keydown",E2DEvents.onKeyDown),this.mObserver&&this.mObserver.disconnect()},E2DEditor.prototype.detachEditorMoveEvents=function(){this.container.off("vmousemove",E2DEvents.onDraw),this.container.off("vmousemove",E2DEvents.onDrag),this.container.off("vmousemove",E2DEvents.onPageDrag),this.container.off("vmousemove",E2DEvents.onSelectionDrag)},E2DEditor.prototype.clearClipboard=function(){this.clipboard=null,this.iClipboard=null},E2DEditor.prototype.clearDragCache=function(){if(this.dragCache&&this.dragCache.linkedShapesHash)for(var e in this.dragCache.linkedShapesHash)if(this.dragCache.linkedShapesHash.hasOwnProperty(e)){var t=this.dragCache.linkedShapesHash[e];if(t&&t.length>0)for(var i=0,n=t.length;i<n;i++){var o=document.getElementById(t[i]);this.resetShapeText(o)}}this.dragCache=null},E2DEditor.prototype.setPreferencesData=function(e){$.when(this.libraryLoaded).done(function(){E2DGlobals.e2d.setPreferencesDataAsync(e)})},E2DEditor.prototype.setPreferencesDataAsync=function(e){this.includeConnectionPoints=e.PageIncludeConnectionPoints,this.checkCollisions=e.PageCheckCollisions,this.persistentCollisions=e.PagePersistentCollisions,this.checkBackgroundCollisions=e.PageCheckBackgroundCollisions,this.checkInclusions=e.PageCheckInclusions,this.persistentInclusions=e.PagePersistentInclusions,this.checkQuotes=e.PageCheckQuotes,this.activeBackground=e.PageActiveBackground,this.shapePropertiesEnabled=e.PageShowShapeProperties,this.quoteUOMEnabled=e.PageShowQuoteUOM,this.connectionPointToolsEnabled=e.PageShowConnectionPointTools,this.showHelpPopupEnabled=e.PageShowHelpPopup,this.zoomFit=e.PageZoomFit,this.quickPickIgnoreThreshold=e.PageQuickPickIgnoreThreshold?1*e.PageQuickPickIgnoreThreshold:0,this.enable3d=e.PageShowPreview3D,this.enable3dDinamicLights=e.PageShowPreview3DDinamicLights,this.enable3dGround=null==e.PageShowPreview3DGround||void 0==e.PageShowPreview3DGround||e.PageShowPreview3DGround,this.enable3dViewStyle=e.PageShowPreview3DViewStyle,this.enable3dFloor=e.PageShowPreview3DEnableFloor;const t=e.PageShowPreview3DFloorImage?e.PageShowPreview3DFloorImage.split("|"):null;this.enable3dFloor&&(this.enable3dFloorDefinition.thickness=e.PageShowPreview3DFloorThickness,t&&t.length>0&&t[0]&&(this.enable3dFloorDefinition.color=t[0].startsWith("#")?t[0]:null,this.enable3dFloorDefinition.image=this.enable3dFloorDefinition.color?null:t[0])),this.enable3dWalls=e.PageShowPreview3DEnableWalls,this.enable3dWallDimensions=e.PageShowPreview3DWallDimensions,this.enableUndoRedo=e.PageShowUndoRedo,this.undoManager.enable(e.PageShowUndoRedo),this.initializeE2DToolbar(e.PageShowConnectorTools,e.PageShowConnectionPointTools,e.PageShowEditConnectionPointsTools,e.PageShowDrawTools,e.PageShowSmartLineTools,e.PageShowTextTools,e.PageShowGridPatternTools,e.PageShowZIndexTools,e.PageShowHelp,e.PageShowSave,e.PageShowActions,e.PageShowPreview3D,e.PageShowPreview3DDinamicLights,e.PageShowSmartCopyTools,e.PageShowGroupTools,e.PageShowQuoteTools,e.PageShowLinkTools,e.PageShowUtils,e.PageShowCustomOrigin,e.PageShowUndoRedo,e.PageShowToolsOnToolbar,e.DisableTopToolbar,e.DisableLeftToolbar),this.setFontSize(e.PageFontSize),this.setEnterBehaviour(e.EnterBehaviour),this.setUnit(e.PageUnit),this.setNumberOfDecimal(e.PageNumberOfDecimal),this.setScaleFactor(e.PageScaleFactor),this.setPageSizeEx(e.PageFormat),this.setGridSizeEx(e.PageGridSize),this.setRotationalGridSizeEx(e.PageGridRotation),this.setOrientation(e.PageOrientation);var i=this.setOrigin(e.PageOrigin);this.enableGrid(e.PageShowGrid),this.enableSnapToGrid(e.PageSnapToGrid),this.enableSnapToObject(e.PageSnapToObject,e.PageSnapToShapeCenter,e.PageGridSize),this.enableSnapToPolyline(e.PageSnapToPolyline,e.PageSnapToShapeCenter,e.PageGridSize),E2DEvents.onResizeWindow(),this.renderer.initFloor(this.enable3dFloor,this.enable3dFloorDefinition),this.initializeE3DPreview(i.data),e.PageZoomPage&&this.pageZoom(),E2DGlobals.showSplashScreen(!1),window.focus();var n=this;$.when(i.dfd).done(function(){n.origin=i.data,n.centerOrigin(),n.preferencesLoaded.resolve()}),e.DoAutoSave&&setInterval(E2DEvents.doSubmitAsync,3e5),e.DoExportImage2D&&(this.exportImage2D=!0,this.image2DExported=$.Deferred(),E2DEvents.doSubmitImageAsync("image2d.png",null)),e.DoExportImage3D&&(this.exportImage3D=!0,this.image3DExported=$.Deferred(),E2DEvents.doSubmitImageAsync("image3d.png",null))},E2DEditor.prototype.setBackgroundData=function(e,t,i){$.when(this.libraryLoaded,this.preferencesLoaded,this.viewportLoaded).done(function(){E2DGlobals.e2d.setBackgroundDataAsync(e,t,i)})},E2DEditor.prototype.setBackgroundDataAsync=function(e,t,i){t=this.convertUserDataToGraphData(t),i=this.convertUserDataToGraphData(i),this.renderer.setBackground(e,t,i)},E2DEditor.prototype.isShapesLoadPending=function(){return"pending"===this.shapesLoaded.state()},E2DEditor.prototype.setShapesData=function(e){$.when(this.libraryLoaded,this.preferencesLoaded,this.viewportLoaded).done(function(){E2DGlobals.e2d.setShapesDataAsync(e)})},E2DEditor.prototype.setShapesDataAsync=function(e){var t=[],i=[],n=[],o=[];this.renderer3d&&this.renderer3d.renderOFF();for(var s=69,r=0,a=e.length;r<a;r++){var l=InsertedShape.CreateShapeFromObject(e[r],this.shapeLibraryList[0]);if(l.isConnector())l.isPolyline()?i[i.length]=l:l.isQuoteLine()?n[n.length]=l:t[t.length]=l;else{var h=this.createNewShapeSeq(l,s);o[o.length]=h,s=h}}var d=this,c=$.Deferred();$.when.apply($,o).done(function(){d.setConnectorsData(i,c)});var u=$.Deferred();$.when(c).done(function(){d.setConnectorsData(t,u)});var p=$.Deferred();$.when(u).done(function(){d.setConnectorsData(n,p)}),$.when(p).done(function(){d.shapesLoaded.resolve(),d.renderer3d&&d.renderer3d.renderON(E2DGlobals.defaultFps),d.zoomFit&&d.fitZoom(),d.connectionPointToolsEnabled&&d.loadPropsForAssemblies(),d.saveUndoRedoPoint(0,"urInitShapes")})},E2DEditor.prototype.setConnectorsData=function(e,t){if(e&&e.length>0){for(var i=[],n=0,o=e.length;n<o;n++){var s=this.createNewConnector(e[n]);i[i.length]=s}$.when.apply($,i).done(function(){t.resolve()})}else t.resolve()},E2DEditor.prototype.mergeShapesData=function(e,t){var i=[],n=[],o=[],s=[];this.renderer3d&&this.renderer3d.renderOFF();for(var r=this.insertedShapes.getIDs(),a=[],l=0,h=e.length;l<h;l++){var d=this.insertedShapes.getShapeById(e[l].id);d&&d.source===e[l].source&&(a[a.length]=d.id)}var c=r.diff(a);if(c&&c.length>0)for(var u=0,p=c.length;u<p;u++){var g=document.getElementById(c[u]);g&&this.deleteItem(g)}for(var y=69,f=0,v=e.length;f<v;f++){var m=this.insertedShapes.getShapeById(e[f].id);if(!m||!m.equalsObject(e[f])||m.needRefresh){m&&m.needRefresh&&(m.needRefresh=!1);var S=e[f].sourceLibrary||this.shapeLibraryList[0],E=InsertedShape.CreateShapeFromObject(e[f],S);if(E.isConnector())E.isPolyline()?n[n.length]=E:E.isQuoteLine()?o[o.length]=E:i[i.length]=E;else{var D=m&&!this.libraryProperties[m.getFullSource()];if(m&&!D)this.updateShapeEx(m,E);else{D&&this.insertedShapes.removeShapeById(m.id);var b=this.createNewShapeSeq(E,y);s[s.length]=b,y=b}}}}var x=this,I=$.Deferred();$.when.apply($,s).done(function(){x.mergeConnectorsData(n,I)});var C=$.Deferred();$.when(I).done(function(){x.mergeConnectorsData(i,C)});var T=$.Deferred();$.when(C).done(function(){x.mergeConnectorsData(o,T)}),$.when(T).done(function(){x.shapesLoaded.resolve(),x.renderer3d&&x.renderer3d.renderON(E2DGlobals.defaultFps),x.highlightEqualShapes&&x.updateOnTheFlyStyleForHighlightEqualShapes(!0),t||x.saveUndoRedoPoint(0,"urMergeShapes")})},E2DEditor.prototype.mergeConnectorsData=function(e,t){if(e&&e.length>0){for(var i=[],n=0,o=e.length;n<o;n++){var s=this.insertedShapes.getShapeById(e[n].id);if(s)this.updateConnectorEx(s,e[n]);else{var r=this.createNewConnector(e[n]);i[i.length]=r}}$.when.apply($,i).done(function(){t.resolve()})}else t.resolve()},E2DEditor.prototype.setViewportData=function(e){$.when(this.libraryLoaded,this.preferencesLoaded).done(function(){E2DGlobals.e2d.setViewportDataAsync(e)})},E2DEditor.prototype.setViewportDataAsync=function(e){this.groupInfo=e.groupInfo,this.setLibraryLayers(e.layers),this.setZoom(e.zoom),this.setScrollObj(e.scroll),this.setSplitters(e.splitters),this.setToggles(e.toggles),this.setE3DActive(e.e3dActive),this.setE3DViewportData(e.e3dData),this.viewportLoaded.resolve()},E2DEditor.prototype.getE3DActive=function(){return null!==this.renderer3d},E2DEditor.prototype.setE3DActive=function(e){e||this.disposeE3DPreview()},E2DEditor.prototype.getE3DViewportData=function(){if(!this.enable3d||!this.renderer3d)return null;const e={};return e.cameraPosition=this.renderer3d.getCameraPosition(),e.cameraLookAt=this.renderer3d.getCameraLookAt(),e.backgroundColor=this.renderer3d.getBackgroundColor(),this.enable3dDinamicLights?(e.hemiLightSkyColor=this.renderer3d.getHemiLightSkyColor(),e.hemiLightGroundColor=this.renderer3d.getHemiLightGroundColor(),e.spotLightColor=this.renderer3d.getSpotLightColor()):(e.ambientLightColor=this.renderer3d.getAmbientLightColor(),e.directionalLightShadowMapSize=this.renderer3d.getDirectionalLightShadowMapSize(),e.directionalLightColor=this.renderer3d.getDirectionalLightColor(),e.directionalLightPos=this.renderer3d.getDirectionalLightPosition()),e.shadows=this.renderer3d.getShadows(),e},E2DEditor.prototype.setE3DViewportData=function(e){if(!e||!this.enable3d||!this.renderer3d)return null;this.renderer3d.setCameraPosition(e.cameraPosition),this.renderer3d.setCameraLookAt(e.cameraLookAt),this.renderer3d.setBackgroundColor(e.backgroundColor),this.renderer3d.setBackgroundImage(e.backgroundImage),this.enable3dDinamicLights?(this.renderer3d.setHemiLightSkyColor(e.hemiLightSkyColor),this.renderer3d.setHemiLightGroundColor(e.hemiLightGroundColor),this.renderer3d.setSpotLightColor(e.spotLightColor)):(this.renderer3d.setAmbientLightColor(e.ambientLightColor),this.renderer3d.setDirectionalLightColor(e.directionalLightColor),this.renderer3d.setDirectionalLightShadowMapSize(e.directionalLightShadowMapSize),this.renderer3d.setDirectionalLightPosition(e.directionalLightPos)),this.renderer3d.setShadows(e.shadows),this.renderer3d.displayGrid(this.showGrid),this.renderer3d.displayShadows(this.show3dShadows),this.renderer3d.displayWalls(this.show3Walls)},E2DEditor.prototype.setE3DViewMode=function(e){this.enable3d&&this.renderer3d&&e&&this.renderer3d.changeViewMode(e)&&$("#cmb3DView").val(e)},E2DEditor.prototype.initializeE2DToolbar=function(e,t,i,n,o,s,r,a,l,h,d,c,u,p,g,y,f,v,m,S,E,D,b){var x=this.shapeLibraryList[0],I=(new Date).getTime(),C=$(document.createElement("link"));C.attr("rel","stylesheet"),C.attr("type","text/css"),C.attr("href",x+"/theme/jquery-ui.css?"+I),$("head").append(C),(C=$(document.createElement("link"))).attr("rel","stylesheet"),C.attr("type","text/css"),C.attr("href",x+"/theme/jquery-ui-custom.css?"+I),$("head").append(C),$(document.body).on("click",".ui-widget-overlay",E2DEvents.onOverlayClick),$(".toolItem").on("click",E2DEvents.doToolItemAction).on("vmouseover",E2DEvents.onToolItemOver).on("vmouseout",E2DEvents.onToolItemOut),$("input[type=text], input[type=number], textarea").on("click",E2DEvents.selectAll);var T={preferredFormat:"hex",chooseText:this.translate("ok"),cancelText:this.translate("cancel"),showInitial:!0,showInput:!0,allowEmpty:!1,showPalette:!0,showSelectionPalette:!0,palette:[]};if($("#btn3DBackgroundColor").button({label:this.translate("backgroundColor3D"),showLabel:!1,icon:"ui-icon-3d-background-color"}).spectrum(T).on("beforeShow.spectrum",E2DEvents.onE3DBackgroundColorBeforeShow).on("move.spectrum",E2DEvents.onE3DBackgroundColorChange).on("change.spectrum",E2DEvents.onE3DBackgroundColorChange).on("hide.spectrum",E2DEvents.onE3DBackgroundColorChange),$("#btn3DAmbientLightColor").button({label:this.translate("ambientLightColor3D"),showLabel:!1,icon:"ui-icon-3d-ambient-light-color"}).spectrum(T).on("beforeShow.spectrum",E2DEvents.onE3DAmbientLightColorBeforeShow).on("move.spectrum",E2DEvents.onE3DAmbientLightColorChange).on("change.spectrum",E2DEvents.onE3DAmbientLightColorChange).on("hide.spectrum",E2DEvents.onE3DAmbientLightColorChange),$("#btn3DDirectionalLightColor").button({label:this.translate("directionalLightColor3D"),showLabel:!1,icon:"ui-icon-3d-directional-light-color"}).spectrum(T).on("beforeShow.spectrum",E2DEvents.onE3DDirectionalLightColorBeforeShow).on("move.spectrum",E2DEvents.onE3DDirectionalLightColorChange).on("change.spectrum",E2DEvents.onE3DDirectionalLightColorChange).on("hide.spectrum",E2DEvents.onE3DDirectionalLightColorChange),$("#btn3DDirectionalLightMove").button({label:this.translate("directionalLightMove3D"),showLabel:!1,icon:"ui-icon-3d-directional-light-move"}).on("click",E2DEvents.onE3DDirectionalLightMove),$("#btn3DDirectionalLightMoveCancel").button({label:this.translate("cancel"),showLabel:!1,icon:"ui-icon-cancel"}).on("click",E2DEvents.onE3DDirectionalLightMoveCancel),$("#btn3DDirectionalLightMoveOk").button({label:this.translate("ok"),showLabel:!1,icon:"ui-icon-accept"}).on("click",E2DEvents.onE3DDirectionalLightMoveOk),$("#btn3DHemiLightSkyColor").button({label:this.translate("hemiLightSkyColor3D"),showLabel:!1,icon:"ui-icon-3d-hemi-light-sky-color"}).spectrum(T).on("beforeShow.spectrum",E2DEvents.onE3DHemiLightSkyColorBeforeShow).on("move.spectrum",E2DEvents.onE3DHemiLightSkyColorChange).on("change.spectrum",E2DEvents.onE3DHemiLightSkyColorChange).on("hide.spectrum",E2DEvents.onE3DHemiLightSkyColorChange),$("#btn3DHemiLightGroundColor").button({label:this.translate("hemiLightGroundColor3D"),showLabel:!1,icon:"ui-icon-3d-hemi-light-ground-color"}).spectrum(T).on("beforeShow.spectrum",E2DEvents.onE3DHemiLightGroundColorBeforeShow).on("move.spectrum",E2DEvents.onE3DHemiLightGroundColorChange).on("change.spectrum",E2DEvents.onE3DHemiLightGroundColorChange).on("hide.spectrum",E2DEvents.onE3DHemiLightGroundColorChange),$("#btn3DSpotLightColor").button({label:this.translate("spotLightColor3D"),showLabel:!1,icon:"ui-icon-3d-spot-light-color"}).spectrum(T).on("beforeShow.spectrum",E2DEvents.onE3DSpotLightColorBeforeShow).on("move.spectrum",E2DEvents.onE3DSpotLightColorChange).on("change.spectrum",E2DEvents.onE3DSpotLightColorChange).on("hide.spectrum",E2DEvents.onE3DSpotLightColorChange),$("#tb3DDLM_X").on("change",E2DEvents.onE3DDirectionalLightMoveChange),$("#tb3DDLM_Y").on("change",E2DEvents.onE3DDirectionalLightMoveChange),$("#tb3DDLM_Z").on("change",E2DEvents.onE3DDirectionalLightMoveChange),$("label[for='tb3DDLM_X']").text(this.translate("x")),$("label[for='tb3DDLM_Y']").text(this.translate("y")),$("label[for='tb3DDLM_Z']").text(this.translate("z")),$("#cmb3DViewDefault").text(this.translate("view3DDefault")),$("#cmb3DViewIso").text(this.translate("view3DIso")),$("#cmb3DViewLeft").text(this.translate("view3DLeft")),$("#cmb3DViewRight").text(this.translate("view3DRight")),$("#cmb3DViewTop").text(this.translate("view3DTop")),$("#cmb3DViewFront").text(this.translate("view3DFront")),$("#toolSelectGroup").attr("title",this.translate("selectGroup")),$("#toolText").attr("title",this.translate("text")),$("#toolPolyline").attr("title",this.translate("polyLine")),$("#toolSmartLine").attr("title",this.translate("smartLine")),$("#toolLine").attr("title",this.translate("line")),$("#toolLinkLine").attr("title",this.translate("linkLine")),$("#toolLinkLineCancel").attr("title",this.translate("linkLineCancel")),$("#toolQuoteLine").attr("title",this.translate("quoteLine")),$("#toolQuoteLineOff").attr("title",this.translate("quoteLineOff")),$("#toolOrthoLine").attr("title",this.translate("orthoLine")),$("#toolCurveLine").attr("title",this.translate("curveLine")),$("#toolBringForward").attr("title",this.translate("bringFront")),$("#toolSendBack").attr("title",this.translate("sendBack")),$("#toolConnectionPoint").attr("title",this.translate("connectionPoint")),$("#toolEditConnectionPoints").attr("title",this.translate("editConnectionPoints")),$("#toolGroup").attr("title",this.translate("group")).addClass("toolItemDisabled"),$("#toolUngroup").attr("title",this.translate("ungroup")),$("#toolPaint").attr("title",this.translate("paint")),$("#toolSnapshot").attr("title",this.translate("snapshot")),$("#toolGridPattern").attr("title",this.translate("gridPattern")),$("#toolGridToggle").attr("title",this.translate("gridToggle")),$("#toolWallsToggle").attr("title",this.translate("wallsToggle")),$("#toolShadowsToggle").attr("title",this.translate("shadowsToggle")),$("#toolSmartCopy").attr("title",this.translate("smartCopy")),$("#toolCustomOrigin").attr("title",this.translate("customOrigin")),$("#toolPreview3D").attr("title",this.translate("preview3D")),$("#toolInfo").attr("title",this.translate("info")),$("#toolHelp").attr("title",this.translate("help")),$("#toolLayers").attr("title",this.translate("layers")),$("#toolUpload").attr("title",this.translate("upload")),$("#toolDownload").attr("title",this.translate("download")),$("#toolRemoveBackground").attr("title",this.translate("removeBackground")),$("#dlgTools").dialog({title:this.translate("tools"),autoOpen:!1,draggable:!1,resizable:!1,modal:!0,closeOnEscape:!0,dialogClass:"no-dialog-titlebar",width:245,position:{my:"left top",at:"left top",of:window},open:E2DEvents.onToolsDialogOpen}),$("#dlgTools .dlgHeaderIcon").addClass("ui-icon-tools32"),$("#dlgTools .dlgHeaderLabel").text(this.translate("tools")),$("#dlgTools .dlgHeaderBack, #dlgTools .dlgHeaderIcon").on("click",E2DEvents.closeToolsDialog),$("#_shapeNameLabel").text(this.translate("name")),$("#_shapeUnitsLabel").text(this.translate("unit")),$("label[for='_pinShapeLabel']").text(this.translate("pin")),$("label[for='_width']").text(this.translate("width")),$("label[for='_height']").text(this.translate("height")),$("label[for='_depth']").text(this.translate("depth")),$("label[for='_x']").text(this.translate("x")),$("label[for='_y']").text(this.translate("y")),$("label[for='_z']").text(this.translate("z")),$("label[for='_rotation']").text(this.translate("rotation")),$("label[for='_layer']").text(this.translate("layer")),$("#_pinShape").checkboxradio(),$("#_width").on("keydown",E2DEvents.isDecimalFormulaNumberKey),$("#_height").on("keydown",E2DEvents.isDecimalFormulaNumberKey),$("#_depth").on("keydown",E2DEvents.isDecimalFormulaNumberKey),$("#_x").on("keydown",E2DEvents.isDecimalFormulaNumberKey),$("#_y").on("keydown",E2DEvents.isDecimalFormulaNumberKey),$("#_z").on("keydown",E2DEvents.isDecimalFormulaNumberKey),$("#_rotation").on("keydown",E2DEvents.isNumberKey),$("#_layer").autocomplete({source:this.autocompleteLibraryLayers.bind(this)}),$("#btnUpdateShape").button({label:this.translate("update"),showLabel:!1,icon:"ui-icon-accept"}),$("#btnConfigureShape").button({label:this.translate("configure"),showLabel:!1,icon:"ui-icon-configure"}),$("#btnValidateShape").button({label:this.translate("validate"),showLabel:!1,icon:"ui-icon-validate"}),$("#_polylineImage").attr("src",x+"/theme/images/e2d/line-poly32.png"),$("#_dpUnitsLabel").text(this.translate("unit")),$("label[for='_dpLength']").text(this.translate("length")),$("label[for='_dpRotation']").text(this.translate("rotation")),$("#_dpLength").on("keydown",E2DEvents.isDecimalNumberKey),$("#_dpRotation").on("keydown",E2DEvents.isNumberKey),$("#btnAddPolylinePoint").button({label:this.translate("addPolylinePoint"),showLabel:!1,icon:"ui-icon-add-polyline-point"}),$("#btnDeletePolylinePoint").button({label:this.translate("deletePolylinePoint"),showLabel:!1,icon:"ui-icon-delete-polyline-point"}),$("#btnUpdatePolyline").button({label:this.translate("update"),showLabel:!1,icon:"ui-icon-accept"}),$("#_quoteImage").attr("src",x+"/theme/images/e2d/line-quote32.png"),$("#_qUnitsLabel").text(this.translate("unit")),$("label[for='_qValue']").text(this.translate("value")),$("#_qValue").on("keydown",E2DEvents.isDecimalNumberKey),$("label[for='_qType']").text(this.translate("type")),$("#_qType").controlgroup(),$("#_qTypeStandard").checkboxradio(),$("#_qTypeHorizontal").checkboxradio(),$("#_qTypeVertical").checkboxradio(),$("label[for='_qDrivingLabel']").text(this.translate("driving")),$("#_qDriving").checkboxradio().on("change",E2DEvents.onDrivingQuoteChanged),$("#btnUpdateQuote").button({label:this.translate("update"),showLabel:!1,icon:"ui-icon-accept"}),$("#_gridPatternImage").attr("src",x+"/theme/images/e2d/pattern_grid32.png"),$("label[for='gaplessLabel'").text(this.translate("gapless")),$("label[for='linkedLabel'").text(this.translate("linked")),$("label[for='xItems']").text(this.translate("xItems")),$("label[for='xGap']").text(this.translate("xGap")),$("label[for='yItems']").text(this.translate("yItems")),$("label[for='yGap']").text(this.translate("yGap")),$("#gapless").on("change",E2DEvents.onGridPatternGaplessChanged),$("#linked").addClass("toolItemDisabled").prop("checked",!1).prop("disabled",!0),$("#xItems").on("keydown",E2DEvents.isNumberKey),$("#xGap").on("keydown",E2DEvents.isDecimalNumberKey),$("#yItems").on("keydown",E2DEvents.isNumberKey),$("#yGap").on("keydown",E2DEvents.isDecimalNumberKey),$("#btnGridPatternOk").button({label:this.translate("ok"),showLabel:!1,icon:"ui-icon-accept"}),$("#btnGridPatternCancel").button({label:this.translate("cancel"),showLabel:!1,icon:"ui-icon-cancel"}),$("#_groupImage").attr("src",x+"/theme/images/e2d/group32.png"),$("label[for='gId']").text(this.translate("id")),$("label[for='gName']").text(this.translate("name")),$("label[for='gDescription']").text(this.translate("description")),$("#btnGroupOk").button({label:this.translate("ok"),showLabel:!1,icon:"ui-icon-accept"}),$("#btnGroupCancel").button({label:this.translate("cancel"),showLabel:!1,icon:"ui-icon-cancel"}),$("#_regroupImage").attr("src",x+"/theme/images/e2d/group32.png"),$("label[for='rgDiscardChanges']").text(this.translate("rgDiscardChanges")),$("label[for='rgApplyChanges']").text(this.translate("rgApplyChanges")),$("label[for='rgApplyChangesToAll']").text(this.translate("rgApplyChangesToAll")),$("#btnReGroupOk").button({label:this.translate("ok"),showLabel:!1,icon:"ui-icon-accept"}),$("#btnReGroupCancel").button({label:this.translate("cancel"),showLabel:!1,icon:"ui-icon-cancel"}),$("#_quickPickImage").attr("src",x+"/theme/images/e2d/layers32.png"),$("label[for='qpAvailableShapes']").text(this.translate("availableShapes")),$("#btnQuickPickOk").text(this.translate("ok")),$("#_quickPickCPImage").attr("src",x+"/theme/images/e2d/layers32.png"),$("label[for='qpAvailableConnectionPoints']").text(this.translate("availableConnectionPoints")),$("label[for='qpZ']").text(this.translate("z")),$("#qpZ").on("keypress",E2DEvents.onQuickPickCPZ),$("#_layersImage").attr("src",x+"/theme/images/e2d/layers-triple32.png"),$("#_toolbarLayersToggles").controlgroup({direction:"vertical"}),$("#_snapshotImage").attr("src",x+"/theme/images/e2d/snapshot32.png"),$("#_snapshot2DPage").button({label:this.translate("snapshot2dPage"),showLabel:!1,icon:"ui-icon-screenshot-2d-page"}),$("#_snapshot2DScreen").button({label:this.translate("snapshot2dScreen"),showLabel:!1,icon:"ui-icon-screenshot-2d"}),$("#_snapshot3D").button({label:this.translate("snapshot3d"),showLabel:!1,icon:"ui-icon-screenshot-3d"}),$("#_snapshotDownload").text(this.translate("snapshotDownload")),$("#_infoImage").attr("src",x+"/theme/images/e2d/info32.png"),$("#_pageUnitsLabel").text(this.translate("unit")),$("label[for='_pageSize']").text(this.translate("size")),$("label[for='_pageWidth']").text(this.translate("width")),$("label[for='_pageHeight']").text(this.translate("height")),$("label[for='_pageGrid']").text(this.translate("grid")),$("label[for='_pageGridSize']").text(this.translate("gSize")),$("label[for='_pageRotateGrid']").text(this.translate("gRotation")),$("label[for='_pageScaleFactor']").text(this.translate("scaleF")),$("label[for='_pageLandscape']").text(this.translate("landscape")),$("label[for='_pageSnapToGrid']").text(this.translate("snapG")),$("label[for='_pageSnapToObject']").text(this.translate("snapO")),$("label[for='_pageSnapToPolyline']").text(this.translate("snapP")),$(".toolbarBtn").on("mouseup",E2DUtils.safeBlur),$("#btnLogo").button({label:this.translate("poweredBy"),showLabel:!1,icon:"ui-icon-logo"}).on("click",this.togglePalette),!E2DUtils.isStringInList(this.shapeLibraryList,"*")){var P=this;$.when(this.libraryLoaded).done(function(){P.updateOnTheFlyStyleForTree(P.libraryCategories),P.libraryCategoriesTree=$("#TVCategories").rdtree({containerid:"TVCategories",dataset:P.libraryCategories,language:P.libraryLanguage,onnodeexpanded:function(e,t,i){E2DEvents.openShapesNode(e,t)}}),P.libraryCategoriesTree.ExpandNodes(P.shapeLibraryOpenList)})}$("#btnTools").button({label:this.translate("tools"),showLabel:!1,icon:"ui-icon-menu"}).on("click",E2DEvents.doBtnToolsAction),$("#btnToolSelect").button({label:this.translate("select"),showLabel:!1,icon:"ui-icon-select"}).on("click",E2DEvents.doBtnSelectAction),$("#btnToolSelectGroup").button({label:this.translate("selectGroup"),showLabel:!1,icon:"ui-icon-select-group"}),$("#btnToolPageDrag").button({label:this.translate("pageDrag"),showLabel:!1,icon:"ui-icon-move"}),$("#btnToolText").button({label:this.translate("text"),showLabel:!1,icon:"ui-icon-text"}),$("#btnToolPolyLine").button({label:this.translate("polyLine"),showLabel:!1,icon:"ui-icon-line-poly"}),$("#btnToolLine").button({label:this.translate("line"),showLabel:!1,icon:"ui-icon-line-draw"}),$("#btnToolOrthoLine").button({label:this.translate("orthoLine"),showLabel:!1,icon:"ui-icon-ortho-draw"}),$("#btnToolCurveLine").button({label:this.translate("curveLine"),showLabel:!1,icon:"ui-icon-curve-draw"}),$("#btnToolSmartLine").button({label:this.translate("smartLine"),showLabel:!1,icon:"ui-icon-line-smart"}),$("#btnToolGridPattern").button({label:this.translate("gridPattern"),showLabel:!1,icon:"ui-icon-grid-pattern"}),$("#btnToolGridToggle").button({label:this.translate("gridToggle"),showLabel:!1,icon:"ui-icon-grid-toggle"}),$("#btnToolWallsToggle").button({label:this.translate("wallsToggle"),showLabel:!1,icon:"ui-icon-wall-toggle"}),$("#btnToolShadowsToggle").button({label:this.translate("shadowsToggle"),showLabel:!1,icon:"ui-icon-shadow-toggle"}),$("#btnToolSmartCopy").button({label:this.translate("smartCopy"),showLabel:!1,icon:"ui-icon-smart-copy"}),$("#btnToolQuoteLine").button({label:this.translate("quoteLine"),showLabel:!1,icon:"ui-icon-line-quote"}),$("#btnToolQuoteLineOff").button({label:this.translate("quoteLineOff"),showLabel:!1,icon:"ui-icon-line-quote-off"}),$("#btnToolLinkLine").button({label:this.translate("linkLine"),showLabel:!1,icon:"ui-icon-line-link"}),$("#btnToolLinkLineCancel").button({label:this.translate("linkLineCancel"),showLabel:!1,icon:"ui-icon-line-link-cancel"}),$("#btnToolCustomOrigin").button({label:this.translate("customOrigin"),showLabel:!1,icon:"ui-icon-custom-origin"}),$("#btnToolPreview3D").button({label:this.translate("preview3D"),showLabel:!1,icon:"ui-icon-preview-3d"}),$("#btnToolPaint").button({label:this.translate("paint"),showLabel:!1,icon:"ui-icon-paint"}),$("#btnToolSnapshot").button({label:this.translate("snapshot"),showLabel:!1,icon:"ui-icon-snapshot"}),$(".btnToolsOnToolbar").on("click",E2DEvents.doBtnToolItemAction);var L=!0,O=!0,w=!0,G=!0,M=this.enable3d,R=this.enable3d&&this.enable3dWalls;if(E){var A=null;-1!==E.indexOf("text")&&(A=$("#btnToolText").css("display","inline-block"),s=!1),-1!==E.indexOf("selectgroup")&&(A=$("#btnToolSelectGroup").css("display","inline-block"),w=!1),-1!==E.indexOf("poly")&&(A=$("#btnToolPolyLine").css("display","inline-block"),n=!1),-1!==E.indexOf("connector")&&($("#btnToolLine").css("display","inline-block"),$("#btnToolOrthoLine").css("display","inline-block"),A=$("#btnToolCurveLine").css("display","inline-block"),e=!1),-1!==E.indexOf("smartline")&&(A=$("#btnToolSmartLine").css("display","inline-block"),o=!1),-1!==E.indexOf("gridpattern")&&(A=$("#btnToolGridPattern").css("display","inline-block"),r=!1),-1!==E.indexOf("smartcopy")&&(A=$("#btnToolSmartCopy").css("display","inline-block"),p=!1),-1!==E.indexOf("quote")&&($("#btnToolQuoteLine").css("display","inline-block"),A=$("#btnToolQuoteLineOff").css("display","inline-block"),y=!1),-1!==E.indexOf("link")&&($("#btnToolLinkLine").css("display","inline-block"),A=$("#btnToolLinkLineCancel").css("display","inline-block"),f=!1),-1!==E.indexOf("customorigin")&&(A=$("#btnToolCustomOrigin").css("display","inline-block"),m=!1),-1!==E.indexOf("preview3d")&&(A=$("#btnToolPreview3D").css("display","inline-block"),c=!1),-1!==E.indexOf("togglegrid")&&(A=$("#btnToolGridToggle").css("display","inline-block"),G=!1),-1!==E.indexOf("toggleshadows")&&(A=$("#btnToolShadowsToggle").css("display","inline-block"),M=!1),-1!==E.indexOf("togglewalls")&&(A=$("#btnToolWallsToggle").css("display","inline-block"),R=!1),-1!==E.indexOf("paint")&&(A=$("#btnToolPaint").css("display","inline-block"),L=!1),-1!==E.indexOf("snapshot")&&(A=$("#btnToolSnapshot").css("display","inline-block"),O=!1),-1!==E.indexOf("custom1")&&$("#btnCustom1").css("display","inline-block"),-1!==E.indexOf("custom2")&&$("#btnCustom2").css("display","inline-block"),-1!==E.indexOf("custom3")&&$("#btnCustom3").css("display","inline-block"),A&&A.css("margin-right","12px")}$("#btnUndo").button({label:this.translate("undo"),showLabel:!1,disabled:!0,icon:"ui-icon-undo"}).on("click",E2DEvents.doUndo),$("#btnRedo").button({label:this.translate("redo"),showLabel:!1,disabled:!0,icon:"ui-icon-redo"}).on("click",E2DEvents.doRedo),$("#btnCut").button({label:this.translate("cut"),showLabel:!1,icon:"ui-icon-cut"}).on("click",E2DEvents.doCut),$("#btnCopy").button({label:this.translate("copy"),showLabel:!1,icon:"ui-icon-copy"}).on("click",E2DEvents.doCopy),$("#btnPaste").button({label:this.translate("paste"),showLabel:!1,icon:"ui-icon-paste"}).on("click",E2DEvents.doPaste),$("#btnDelete").button({label:this.translate("delete"),showLabel:!1,icon:"ui-icon-delete"}).on("click",E2DEvents.doDelete),$("#btnZoomFit").button({label:this.translate("zoomFit"),showLabel:!1,icon:"ui-icon-zoomfit"}).on("click",E2DEvents.doZoomFit),$("#btnZoomPage").button({label:this.translate("zoomPage"),showLabel:!1,icon:"ui-icon-zoompage"}).on("click",E2DEvents.doZoomPage),$("#btnZoomOrig").button({label:this.translate("zoomOrig"),showLabel:!1,icon:"ui-icon-zoomorig"}).on("click",E2DEvents.doZoomOrig),$("#btnZoomOut").button({label:this.translate("zoomOut"),showLabel:!1,icon:"ui-icon-zoomout"}).on("click",E2DEvents.toggleZoomOut),$("#btnZoomIn").button({label:this.translate("zoomIn"),showLabel:!1,icon:"ui-icon-zoomin"}).on("click",E2DEvents.toggleZoomIn),$("#btnZoomText").button({label:"100%",disabled:!0}),$("#btnAccept").button({label:this.translate("accept"),showLabel:!1,icon:"ui-icon-accept"}).on("click",E2DEvents.doAccept),$("#btnCancel").button({label:this.translate("cancel"),showLabel:!1,icon:"ui-icon-cancel"}).on("click",E2DEvents.doCancel),$("#btnSave").button({label:this.translate("save"),showLabel:!1,icon:"ui-icon-save"}).on("click",E2DEvents.doSave),$("#btnHelp").button({label:this.translate("help"),showLabel:!1,icon:"ui-icon-help"}).on("click",E2DEvents.openHelpDialog),$("#btnCustom1").button({label:this.translate("custom1"),showLabel:!1,icon:"ui-icon-custom1"}).on("click",function(){E2DEvents.doSubmit("CUSTOM1")}),$("#btnCustom2").button({label:this.translate("custom2"),showLabel:!1,icon:"ui-icon-custom2"}).on("click",function(){E2DEvents.doSubmit("CUSTOM2")}),$("#btnCustom3").button({label:this.translate("custom3"),showLabel:!1,icon:"ui-icon-custom3"}).on("click",function(){E2DEvents.doSubmit("CUSTOM3")}),s||$("#toolText").css("display","none"),w||$("#toolSelectGroup").css("display","none"),n||$("#toolPolyline").css("display","none"),o||$("#toolSmartLine").css("display","none"),e||$("div.btnGroupConnector").css("display","none"),t||$("#toolConnectionPoint").css("display","none"),i||$("#toolEditConnectionPoints").css("display","none"),o||e||$("div.btnGroupLines").css("display","none"),a||$("div.btnGroupZIndex").css("display","none"),r||$("#toolGridPattern").css("display","none"),p||$("#toolSmartCopy").css("display","none"),m||$("#toolCustomOrigin").css("display","none"),c||$("#toolPreview3D").css("display","none"),u?($("#btn3DAmbientLightColor").css("display","none"),$("#btn3DDirectionalLightColor").css("display","none"),$("#btn3DDirectionalLightMove").css("display","none")):($("#btn3DHemiLightSkyColor").css("display","none"),$("#btn3DHemiLightGroundColor").css("display","none"),$("#btn3DSpotLightColor").css("display","none")),L||$("#toolPaint").css("display","none"),O||$("#toolSnapshot").css("display","none"),g||($("#toolSelectGroup").css("display","none"),$("#toolGroup").css("display","none"),$("#toolUngroup").css("display","none")),y||($("#toolQuoteLine").css("display","none"),$("#toolQuoteLineOff").css("display","none")),f||($("#toolLinkLine").css("display","none"),$("#toolLinkLineCancel").css("display","none")),v||($("#toolPaint").css("display","none"),$("#toolSnapshot").css("display","none"),$("#toolLayers").css("display","none"),$("#toolUpload").css("display","none"),$("#toolDownload").css("display","none"),$("#toolRemoveBackground").css("display","none"),$("div.btnGroupUtils").css("display","none")),G||$("#toolGridToggle").css("display","none"),R||$("#toolWallsToggle").css("display","none"),M||$("#toolShadowsToggle").css("display","none"),v||g||($("div.btnGroupGroup").css("display","none"),$("div.btnGroupUtils").css("display","none")),L||O||g||$("div.btnGroupGroup").css("display","none"),y||f||$("div.btnGroupExtraLines").css("display","none"),n||w||$("div.btnGroupBase").css("display","none"),s||a||t||$("div.btnGroupExtraText").css("display","none"),r||p||m||c||$("div.btnGroupExtra").css("display","none"),R||M||$("div.btnGroupToggles").css("display","none"),y||f||$("div.btnGroupExtraLines").css("display","none"),l||($("button.btnGroupHelp").css("display","none"),$("div.btnGroupHelp").css("display","none")),h||$("button.btnGroupSave").css("display","none"),d||$("button.btnGroupActions").css("display","none"),S||$("button.btnGroupUndoRedo").css("display","none"),D&&E2DGlobals.e2dLayout.hide("north"),b&&E2DGlobals.e2dLayout.hide("west")},E2DEditor.prototype.updateUndoRedoButtons=function(e,t){$("#btnUndo").button(e?"enable":"disable"),$("#btnRedo").button(t?"enable":"disable")},E2DEditor.prototype.togglePalette=function(){E2DGlobals.e2dLayout.toggle("west")},E2DEditor.prototype.togglePreview3D=function(){this.enable3d&&(this.renderer3d?this.disposeE3DPreview():(this.initializeE3DPreview(),this.populateE3DPreview()))},E2DEditor.prototype.toggleQuotes=function(e){e?this.quotesOff&&(this.quotesOff=!1,this.updateQuotesVisibility(this.quotesOff)):(this.quotesOff=!this.quotesOff,this.updateQuotesVisibility(this.quotesOff))},E2DEditor.prototype.toggleGrid=function(e){e?this.showGrid&&(this.showGrid=!1,this.enableGrid(this.showGrid)):(this.showGrid=!this.showGrid,this.enableGrid(this.showGrid))},E2DEditor.prototype.toggle3dWalls=function(e){this.show3dWalls=!e&&!this.show3dWalls,this.renderer3d&&this.renderer3d.displayWalls(this.show3dWalls)},E2DEditor.prototype.toggle3dShadows=function(e){this.show3dShadows=!e&&!this.show3dShadows,this.renderer3d&&this.renderer3d.displayShadows(this.show3dShadows)},E2DEditor.prototype.updateQuotesVisibility=function(e){var t=document.querySelectorAll("g.connector.quote-line");if(t&&t.length>0)for(var i=0,n=t.length;i<n;i++){var o=t[i];e?o.classList.add("hidden"):o.classList.remove("hidden")}},E2DEditor.prototype.initializeE3DPreview=function(e){if(this.enable3d){e=e||this.origin;var t=$("#_pageWidth").val(),i=$("#_pageHeight").val();E2DGlobals.e2dLayout.show("east");var n=E2DGlobals.e2dLayout.east.pane.width(),o=E2DGlobals.e2dLayout.east.pane.height();this.renderer3d=new ThreeDRenderer("E3DPreview",n,o,t,i);var s="in"===this.unit?25.4*this.scale:this.scale;this.renderer3d.init(e,s,this.enable3dViewStyle,this.enable3dDinamicLights,this.enable3dGround,$("#_pageGrid").prop("checked"),this.enable3dFloor,this.enable3dFloorDefinition,this.enable3dWalls,this.enable3dWallDimensions,E2DGlobals.defaultFps);var r=$("#E3DPreviewMain").data();$.isEmptyObject(r)||this.setE3DViewportData(r)}},E2DEditor.prototype.populateE3DPreview=function(){if(this.enable3d&&this.renderer3d){var e=this.insertedShapes.getShapes();if(e&&0!==e.length){this.renderer3d.renderOFF();for(var t=0,i=e.length;t<i;t++){var n=e[t];if(n.id!==this.ORIGIN_ID&&n.id!==this.CUSTOM_ORIGIN_ID&&n.source!==this.CONNECTION_POINT_CLASS&&"text"!==n.source&&(!n.isConnector()||n.isPolyline())){var o=this.selected&&this.selected.id===n.id,s=this.multipleSelectShapes.containsById(n.id),r=this.libraryProperties[n.getFullSource()];this.renderer3d.addObject(n,r,o,s)}}this.renderer3d.renderON(E2DGlobals.defaultFps)}}},E2DEditor.prototype.disposeE3DPreview=function(){this.enable3d&&this.renderer3d&&($("#E3DPreviewMain").data(this.getE3DViewportData()),E2DGlobals.e2dLayout.hide("east"),this.renderer3d.dispose(),this.renderer3d=null)},E2DEditor.prototype.hasFocusPolyLineProperties=function(){if(!document.activeElement)return!1;var e=document.activeElement;return"_dpLength"===e.id||"_dpRotation"===e.id},E2DEditor.prototype.deleteSelection=function(e,t,i){if("poly-line"!==this.mode)if(this.setMode("select"),this.selected){var n=this.getSelectedShapes();if(!e)for(var o=0,s=n.length;o<s;o++){if(n[o].id===this.ORIGIN_ID||n[o].id===this.CUSTOM_ORIGIN_ID)return void this.setHelp("warning","Origin cannot be removed.");var r=this.insertedShapes.getShapeById(n[o].id);if(r){if(r.hasBehaviour("(BACKGROUND)")&&!this.activeBackground)return void this.setHelp("warning","Background elements cannot be removed.");if(r.hasBehaviour("(NOREMOVE)"))return void this.setHelp("warning","Selected shape cannot be removed.")}}this.unselect(),this.deleteItems(n,t,i)}else this.setHelp("warning","Select a shape to delete");else this.setHelp("warning","Cannot delete in polyline mode")},E2DEditor.prototype.deleteItems=function(e,t,i){if(e&&0!==e.length){var n=[],o=e;if(!t&&this.events.removed){o=[];for(var s=0,r=e.length;s<r;s++){var a=null;if(this.renderer.isLinkLine(e[s])){var l=this.insertedShapes.getConnectionShape(e[s].id,"from"),h=this.getEventArgumentByShapeId("REMOVED",l.shapeID),d=this.insertedShapes.getConnectionShape(e[s].id,"to"),c=this.getEventArgumentByShapeId("REMOVED",d.shapeID);(h||c)&&(a=new E2DEventArgument("REMOVED",{},null,e[s].id,null,null))}else a=this.getEventArgumentByShapeId("REMOVED",e[s].id);a?n[n.length]=a:o[o.length]=e[s]}}if(o&&o.length>0){for(var u=0,p=o.length;u<p;u++)this.deleteItem(o[u],!1);i||this.saveUndoRedoPoint(0,"urDeleteShapes")}!t&&this.events.removed&&n.length>0&&E2DEvents.doSubmitEvent("OnEditor2DRemoved",n,1,"urDeleteShapes")}},E2DEditor.prototype.deleteItem=function(e,t){if(e){this.hideSmartLineMiddleConnectionPoints(e),this.hideSmartLineOrthoConnectionPoints();var i,n,o,s=this.insertedShapes.getShapeById(e.id);if(s)if(s.isLine()||s.isCurveLine()||s.isOrthoLine()||s.isLinkLine()||s.isQuoteLine())this.renderer.disconnectLineFromShape(e,"from"),this.renderer.disconnectLineFromShape(e,"to"),this.renderer.remove(e),this.insertedShapes.removeShape(e);else if(s.isSmartLine()){var r=this.insertedShapes.getConnectionShape(e.id,"from"),a=this.insertedShapes.getShapeById(r.shapeID),l=this.insertedShapes.getConnectionShape(e.id,"to"),h=this.insertedShapes.getShapeById(l.shapeID);this.renderer.remove(e),this.insertedShapes.removeShape(e),a&&h?(a.isSmartLineHub()&&(n=document.getElementById(r.shapeID),this.deleteItem(n,t)),h.isSmartLineHub()&&(o=document.getElementById(l.shapeID),this.deleteItem(o,t))):a&&a.isSmartLineHub()&&this.insertedShapes.getAttachedSmartLines(r.shapeID).length<=2?(n=document.getElementById(r.shapeID),this.deleteItem(n,t)):h&&h.isSmartLineHub()&&this.insertedShapes.getAttachedSmartLines(l.shapeID).length<=2&&(o=document.getElementById(l.shapeID),this.deleteItem(o,t))}else if(s.isSmartLineHub()){var d=this.insertedShapes.getAttachedSmartLines(e.id);switch(d.length){case 0:this.renderer.remove(e),this.insertedShapes.removeShape(e);break;case 1:this.renderer.remove(e),this.insertedShapes.removeShape(e),i=document.getElementById(d[0]),this.deleteItem(i,t);break;case 2:this.renderer.remove(e),this.insertedShapes.removeShape(e);var c=document.getElementById(d[0]),u=document.getElementById(d[1]);this.renderer.joinSmartLines(c,u,t);break;default:for(var p=0,g=d.length;p<g;p++)i=document.getElementById(d[p]),this.deleteItem(i,t)}}else if(s.isPolyline()){this.clearPolylineConnections(e);var y=document.getElementById("resize-from"),f=document.getElementById("resize-to"),v=y.hasAttributeNS(null,"plPoint")?1*y.getAttributeNS(null,"plPoint"):-1,m=f.hasAttributeNS(null,"plPoint")?1*f.getAttributeNS(null,"plPoint"):-1,S=y.classList.contains("lineTrackerResizeSelected")||f.classList.contains("lineTrackerResizeSelected"),E=this.renderer.getPolylineNumberOfPoints(e);S&&E>2?this.deletePolylinePoint(e):-1!==v&&-1!==m?this.deletePolylineSegment(e,v,m):(this.renderer.remove(e),this.insertedShapes.removeShape(e),E2DEvents.polylineStarted&&(E2DEvents.polylineStarted=!1,this.container.off("vmousemove",E2DEvents.onDraw),this.setPropertiesVisible(null)))}else{for(var D=this.insertedShapes.getAttachedLines(e.id),b=0,x=D.length;b<x;b++){var I=this.insertedShapes.getShapeById(D[b]);I&&((I.isLinkLine()||I.isSmartLine())&&(i=document.getElementById(D[b]),this.deleteItem(i,t)))}this.renderer.remove(e),this.insertedShapes.removeShape(e)}}else this.setHelp("info","Select a shape to delete")},E2DEditor.prototype.saveUndoRedoPoint=function(e,t){this.enableUndoRedo&&this.undoManager.save(e,t,this.insertedShapes.getJSONShapes())},E2DEditor.prototype.setUndoRedoNextInfo=function(e,t){this.enableUndoRedo&&this.undoManager.setNextInfo(e,t)},E2DEditor.prototype.undo=function(){if(!this.enableUndoRedo)return;this.setMode("select"),this.unselect();const e=this.undoManager.peekInfo(),t=this.undoManager.undo();t&&(this.setHelp("info",this.translate("urUndo")+": "+this.translate(e.label)),this.shapesLoaded=$.Deferred(),this.mergeShapesData(JSON.parse(t.data),!0),1===e.type&&this.shapesLoaded.done(function(){E2DEvents.doSubmitEvent("OnEditor2DUndo",null,2)}))},E2DEditor.prototype.redo=function(){if(!this.enableUndoRedo)return;this.setMode("select"),this.unselect();const e=this.undoManager.redo();e&&(this.setHelp("info",this.translate("urRedo")+": "+this.translate(e.label)),this.shapesLoaded=$.Deferred(),this.mergeShapesData(JSON.parse(e.data),!0),1===e.type&&this.shapesLoaded.done(function(){E2DEvents.doSubmitEvent("OnEditor2DRedo",null,2)}))},E2DEditor.prototype.cut=function(){this.setMode("select"),this.selected?(this.copy(),this.deleteSelection()):this.setHelp("info","Nothing to cut, please select a shape first")},E2DEditor.prototype.copy=function(){if(this.setMode("select"),this.selected){this.clipboard=[],this.iClipboard=[];for(var e=this.getSelectedShapes(),t=0,i=e.length;t<i;t++)if(e[t].id!==this.CUSTOM_ORIGIN_ID){this.clipboard[this.clipboard.length]=this.renderer.copy(e[t]);var n=this.insertedShapes.getShapeById(e[t].id);n&&(this.iClipboard[n.id]=n)}}else this.setHelp("info","Nothing to copy, please select a shape first")},E2DEditor.prototype.paste=function(e,t){if(this.setMode("select"),this.clipboard&&0!==this.clipboard.length){for(var i={},n=[],o=[],s=0,r=this.clipboard.length;s<r;s++){var a=this.clipboard[s];a.id!==this.CUSTOM_ORIGIN_ID&&(this.renderer.isConnector(a)?n[n.length]=a:o[o.length]=a)}for(var l,h,d,c,u={},p=0,g=o.length;p<g;p++)l=o[p],(h=this.iClipboard[l.id])&&(h.group?u[h.group]?u[h.group].shapes[u[h.group].shapes.length]=l:u[h.group]={shapes:[l],connectors:[]}:this.pasteSingleShape(l,h,i,null,e,t));for(var y=0,f=n.length;y<f;y++)d=n[y],(c=this.iClipboard[d.id])&&(c.group?u[c.group]?u[c.group].connectors[u[c.group].connectors.length]=d:u[c.group]={shapes:[],connectors:[d]}:this.pasteSingleConnector(d,c,i,null,e,t));for(var v=E2DUtils.objectKeys(u),m=0,S=v.length;m<S;m++){var E=v[m],D=null,b=E.split(":")[0],x=u[E],I=this.libraryProperties[b];I&&2===I.shapeMode&&I.group2d&&I.group2d.shapes&&x.shapes&&I.group2d.shapes.length===x.shapes.length&&I.group2d.connectors&&x.connectors&&I.group2d.connectors.length===x.connectors.length&&(D=InsertedShapes.GetNextGroupOccurrence(b));for(var C=0,T=x.shapes.length;C<T;C++)l=x.shapes[C],h=this.insertedShapes.getShapeById(l.id),this.pasteSingleShape(l,h,i,D,e,t);for(var P=0,L=x.connectors.length;P<L;P++)d=x.connectors[P],c=this.insertedShapes.getShapeById(d.id),this.pasteSingleConnector(d,c,i,D,e,t)}var O=null;this.multipleSelectShapes.reset();var w=E2DUtils.objectValues(i);w.length>1?(this.multipleSelectShapes.setSelectedShapes(w),O=this.resetMultipleSelector()):1===w.length&&(this.unselect(),O=w[0]),this.select(O),this.renderer.updateTracker(this.selected),this.copy(),this.clearShapeText(),this.resetShapeText();var G=[];for(var M in i)if(i.hasOwnProperty(M)){var R=this.getEventArgumentByShapeId("PASTED",i[M].id,"(ORIGSHAPEID="+M+")");R&&(G[G.length]=R)}this.handleZIndexPositioning(),this.events.pasted&&G&&G.length>0?E2DEvents.doSubmitEvent("OnEditor2DPasted",G,1,"urPasteShapes"):this.saveUndoRedoPoint(0,"urPasteShapes")}else this.setHelp("info","Nothing to paste, please use copy or cut on selected shape")},E2DEditor.prototype.pasteSingleConnector=function(e,t,i,n,o,s){var r=this.insertedShapes.getConnectionShape(e.id,"from"),a=this.insertedShapes.getConnectionShape(e.id,"to");if(!t.isSmartLine()&&!t.isLinkLine()||i[r.shapeID]&&i[a.shapeID]){this.pasteSingleShape(e,t,i,n,o,s,!0);var l=i[e.id];if(i[r.shapeID]){var h=i[r.shapeID];this.renderer.connectLineToShape(h,l,"from",r.pointID)}if(i[a.shapeID]){var d=i[a.shapeID];this.renderer.connectLineToShape(d,l,"to",a.pointID)}this.insertedShapes.updateConnector(l)}},E2DEditor.prototype.pasteSingleShape=function(e,t,i,n,o,s,r){var a=this.renderer.paste(e,o,s);r||E2DUtils.clearClassList(a),i[e.id]=a,this.addNewShapeListeners(a);var l=!1,h=null;if(this.renderer.isConnector(a))l=!this.renderer.isPolyline(a),h=InsertedShape.CreateShapeFromConnector(a,t.sourceLibrary);else{var d=this.renderer.bounds(a);d=this.convertTrueBoundsToUserBounds(d),d=this.applyRoundingToUserRect(d),h=InsertedShape.CreateShape(t.sourceLibrary,t.source,a.id,t.name,t.family,t.description,d.x,d.y,d.z,d.width,d.height,d.depth,d.rotation,t.text,t.behaviour,E2DUtils.cloneObject(t.custom),t)}h.group=n,this.insertedShapes.addShape(h,l),this.updateOnTheFlyStyleForHighlightEqualShape(h)},E2DEditor.prototype.addNewShapeListeners=function(e){if(e){var t=$(e);t.on("vclick",E2DEvents.onSingleDoubleClick),t.on("vmousedown",E2DEvents.onHit),t.on("vmouseover",E2DEvents.onShapeMouseOver),t.on("vmouseout",E2DEvents.onShapeMouseOut),t.on("touchstart",E2DEvents.onShapeTouchStart),t.on("touchend",E2DEvents.onShapeTouchEnd),t.addClass("shapeCursor")}},E2DEditor.prototype.getToolbarWidth=function(){return 1*$("#_toolbar").css("width").split("px")[0]-66},E2DEditor.prototype.getToolbarHeight=function(){return 1*$("#_toolbar").css("height").split("px")[0]},E2DEditor.prototype.getUrlForHelp=function(){var e=this.shapeLibraryList[0]+"/shapes/help/main.html";if(!this.selected)return e;if(this.renderer.isMultipleSelect(this.selected))return e;var t=this.insertedShapes.getShapeById(this.selected.id);if(!t)return e;var i=(t.sourceLibrary||this.shapeLibraryList[0])+"/shapes/help/"+t.source+".html";return E2DUtils.existsOnServer(i)||(i=e),i},E2DEditor.prototype.cancelLinkLine=function(){for(var e=this.getSelectedShapes(),t=0,i=e.length;t<i;t++)for(var n=this.insertedShapes.getAttachedLinkLines(e[t].id,!1),o=0,s=n.length;o<s;o++){var r=document.getElementById(n[o]);this.deleteItem(r,!0,[])}},E2DEditor.prototype.editConnectionPoints=function(){if(this.isSingleShapeSelected()){var e=this.getSelectedShapeIDs(),t=this.insertedShapes.getShapeById(e[0]);E2DEvents.doSubmitEvent("OnEditor2DEditConnectionPoints",t,1,"urEditor2DEditConnectionPoints")}else this.setHelp("warning","To edit connection points, please select a single shape.")},E2DEditor.prototype.createGridPattern=function(e,t,i,n,o,s){var r=this.getSelectedShapeIDs();r&&0!=r.length?(r.forEach(r=>{if(r!==this.ORIGIN_ID&&r!==this.CUSTOM_ORIGIN_ID){var a=this.insertedShapes.getShapeById(r);this.selectById(r),this.createGridPatternItem(a,e,t,i,n,o,s)}}),this.unselect(),r.forEach(e=>{this.addSelectionById(e,!0)}),this.renderer3d&&this.renderer3d.renderON(E2DGlobals.defaultFps),this.handleZIndexPositioning()):this.setHelp("warning","No shape selected!")},E2DEditor.prototype.createGridPatternItem=function(e,t,i,n,o,s,r){if(e)if(e!==this.origin&&e!==this.customOrigin){var a=e.decodeBehaviour("(ORIGIN="),l=1,h=1;this.customOrigin&&(l=this.customOrigin.signX*this.origin.signX,h=this.customOrigin.signY*this.origin.signY),this.renderer3d&&this.renderer3d.renderOFF(),!0===s&&(i=e.width,o=e.height);var d=new Array;d[0]=this.createGridPatternRow(e,a,t,i,1,l,null);for(var c=1;c<n;c++){var u=1*e.y+o*c*h;d[c]=this.createGridPatternRow(e,a,t,i,0,l,u)}r&&this.tryToLinkShapes(d)}else this.setHelp("warning","Cannot create a Grid Pattern of the origin.");else this.setHelp("warning","To create a Grid Pattern, please select a shape.")},E2DEditor.prototype.createGridPatternRow=function(e,t,i,n,o,s,r){var a=new Array;1===o&&(a[0]=e);for(var l=o;l<i;l++){var h=1*e.x+n*l*s,d=this.convertUserDataToGraphData(e.width),c=this.convertUserDataToGraphData(e.height),u=InsertedShape.CloneShape(e);u.id="shape_"+E2DUtils.createUUID(),u.x=h,u.y=r&&"number"==typeof r?r:u.y;var p=this.renderer.paste(this.selected);p.id=u.id;var g=this.convertUserXToGraphX(u.x),y=this.convertUserYToGraphY(u.y),f=this.convertUserZToGraphZ(u.z);if(t.found){var v=this.applyShapeOriginToGraphData(g,y,d,c,t.value);g=v.x,y=v.y}this.renderer.setRotation(p,0),this.renderer.setPosition(p,g,y,f),this.renderer.setRotation(p,u.rotation),this.insertedShapes.addShape(u),this.addNewShapeListeners(p),this.clearShapeText(p),this.resetShapeText(p),a[l]=u}return a},E2DEditor.prototype.tryToLinkShapes=function(e){for(var t=e.length,i=e[0].length,n=null,o=0;o<t;o++)for(var s=0;s<i;s++)o+1<t&&(n=this.getOverlappingConnectionPointsBetweenShapes(document.getElementById(e[o][s].id),document.getElementById(e[o+1][s].id)))&&n.length>0&&this.linkShapes(e[o][s].id,n[0].from,e[o+1][s].id,n[0].to),s+1<i&&(n=this.getOverlappingConnectionPointsBetweenShapes(document.getElementById(e[o][s].id),document.getElementById(e[o][s+1].id)),cplList&&n.length>0&&this.linkShapes(e[o][s].id,n[0].from,e[o][s+1].id,n[0].to))},E2DEditor.prototype.linkShapes=function(e,t,i,n){let o=new InsertedShape;o.source="link-line",o.shapeFromId=e,o.shapeFromPointIndex=t,o.shapeToId=i,o.shapeToPointIndex=n,this.createNewConnector(o)},E2DEditor.prototype.indexOfConnectingShape=function(e,t){if(this.renderer.isConnector(e))return-1;const i=this.renderer.getConnectionPointObjs(e);for(let e=0,n=t.length;e<n;e++){if(this.renderer.isConnector(t[e]))continue;const n=this.renderer.getConnectionPointObjs(t[e]);for(let t=0,o=i.length;t<o;t++)for(let o=0,s=n.length;o<s;o++)if(E2DUtils.isPointTooClose(i[t],n[o],1))return e}return-1},E2DEditor.prototype.createText=function(e,t){const i=this;this.renderer.create(this.shapeLibraryList[0],"text",e,t,0,1,1,1).done(function(n){i.createTextAsync(n,e,t)})},E2DEditor.prototype.createTextAsync=function(e,t,i){this.select(e),this.selected.setAttribute("id","text_"+E2DUtils.createUUID()),this.addNewShapeListeners(this.selected),this.container.on("vmousemove",E2DEvents.onDraw);var n=this.convertTrueBoundsToUserBounds({x:t,y:i,z:0,width:1,height:1,depth:1}),o=InsertedShape.CreateShape(this.shapeLibraryList[0],"text",this.selected.id,"Note","","Note",n.x,n.y,n.z,n.width,n.height,n.depth,0,"","(NOTE)",{});this.insertedShapes.addShape(o),this.textToolBeginNew=!0,this.handleZIndexPositioning()},E2DEditor.prototype.connectLine=function(e,t,i,n){if(t&&i.length>1){E2DEvents.hideExtraToolbars(),E2DEvents.closeToolsDialog();var o,s=E2DGlobals.e2d;if(E2DEvents.prev_connector){var r=E2DEvents.prev_connector.split("--");if(r&&2==r.length){var a=r[0],l=r[1];o=s.getConnectionPointFromPropertiesById(a,l)}}var h=[],d=0;for(let e=0,t=i.length;e<t;e++){const t=i[e];o&&o.linkClass&&t.linkClass&&o.linkClass!=t.linkClass||(h[d]=t,d++)}if(h.length>1)return E2DEvents.openQuickPickCPDialog(h),!1;if(0==h.length)return!1;t=h[0].id}var c=69,u=null;if(t){var p=t.split("--"),g=this.pointFromConnector(t),y=p[0],f=p[1],v=document.getElementById(y),m=this.renderer.isSmartLine(this.selected),S=this.renderer.isSmartLine(v);if("line-from"===this.resizeMode?m&&S?this.renderer.replaceSmartLineWithSmartLineHub(this.selected,v,g,"from",!1):this.renderer.connectLine(v,this.selected,"from",f):"line-to"===this.resizeMode&&(m&&S?this.renderer.replaceSmartLineWithSmartLineHub(this.selected,v,g,"to",!1):this.renderer.connectLine(v,this.selected,"to",f)),"line"!==this.mode&&"curve-line"!==this.mode&&"ortho-line"!==this.mode&&"smart-line"!==this.mode&&"quote-line"!==this.mode||t!==e&&(this.selected&&this.renderer.isConnector(this.selected)?m&&S?this.renderer.replaceSmartLineWithSmartLineHub(this.selected,v,g,"to",!1):this.renderer.connectLine(v,this.selected,"to",f):c=this.connectNewLine(e,t)),"link-line"===this.mode){if(t!==e)if(this.selected&&this.renderer.isConnector(this.selected)){var E=this.insertedShapes.getConnectionShape(this.selected.id,"from"),D=this.insertedShapes.isPinned(E.shapeID);if(D.pinnedX||D.pinnedY)this.deleteSelection(!0);else if(E.shapeID===v.id)this.deleteSelection(!0);else if(this.insertedShapes.areShapesConnectedWithQuote(E.shapeID,v.id,!0))this.deleteSelection(!0);else{var b=!0;this.insertedShapes.isCircularReference(v.id,this.selected,this.mode)&&(b=this.areOverlappingConnectionPoints(document.getElementById(E.shapeID),E.pointID,document.getElementById(p[0]),p[1])),b?(this.renderer.connectLine(v,this.selected,"to",f),this.renderer.validateLink(this.selected),u=$.Deferred(),this.fireLinkedEvent(this.selected,u)):(E2DEvents.showMessageDialog(this.translate("validation"),this.translate("circularReference")),this.deleteSelection(!0))}}else c=this.connectNewLine(e,t);this.unselect()}this.selected&&this.insertedShapes.updateConnector(this.selected)}else"smart-line"!==this.mode&&"link-line"!==this.mode||this.deleteSelection(!0);var x=this;$.when(c).done(function(i){var o=x.selected||i;if("quote-line"===x.mode&&o&&(0===x.renderer.getQuoteValue(o)?x.deleteSelection(!0):(x.selected||x.select(o),x.renderer.updateQuoteType(o))),n&&!isNaN(n.userZ)){var s=null,r=null;if(n.id===e){var a=t.split("--");s=document.getElementById(a[0]),r=x.insertedShapes.getShapeById(a[0])}else if(n.id===t){var l=e.split("--");s=document.getElementById(l[0]),r=x.insertedShapes.getShapeById(l[0])}if(s&&r){r.z=n.userZ;var h=x.convertUserBoundsToGraphBounds(r);x.updateShapeSingle(s,r,h)}}x.clearShapeText(),x.resetShapeText(),x.hideSmartLineOrthoConnectionPoints(),x.restoreMode(),E2DEvents.active_connector=null,E2DEvents.prev_connector=null,E2DEvents.connector_z=null,x.selected&&x.saveUndoRedoPoint(0,"urConnectShapes"),u&&u.resolve()})},E2DEditor.prototype.createLine=function(e,t,i,n){var o=this;this.renderer.createLine(this.shapeLibraryList[0],e,t,i).done(function(e){o.createLineAsync(e,t,i,n)})},E2DEditor.prototype.createLineAsync=function(e,t,i,n){E2DEvents.lineStarted=!0,this.select(e),this.selected.setAttribute("id","connector_"+E2DUtils.createUUID());var o=InsertedShape.CreateShapeFromConnector(this.selected,this.shapeLibraryList[0]);if(this.insertedShapes.addShape(o,!0),this.addNewShapeListeners(this.selected),this.container.on("vmousemove",E2DEvents.onDraw),this.renderer.moveLine(this.selected,t,i,!0),n){E2DEvents.prev_connector=n;var s=n.split("--"),r=this.pointFromConnector(n),a=s[0],l=s[1];E2DEvents.connectorInactive();var h=document.getElementById(a),d=this.renderer.isSmartLine(this.selected),c=this.renderer.isSmartLine(h);d&&c?this.renderer.replaceSmartLineWithSmartLineHub(this.selected,h,r,"from",!0):this.renderer.connectLine(h,this.selected,"from",l),this.clearConnectionPoints(!0)}o.updateConnector(this.selected),this.showSmartLineOrthoConnectionPoints(!1),this.handleZIndexPositioning()},E2DEditor.prototype.connectPolyline=function(e){if(e){var t=e.split("--"),i=t[0],n=t[1],o=document.getElementById(i),s=this.pointFromConnector(e),r="from"===n,a="to"===n;if("poly-line"===this.mode&&E2DEvents.polylineStarted)this.clearPolylineConnections(this.selected),r||a?(this.joinPolylines(this.selected,o,!0,r),E2DEvents.skipMouseUp=!0,E2DEvents.polylineStarted=!1):this.renderer.closePolylineSegment(this.selected,s.x,s.y,!0);else if("resize"===this.mode)if(this.clearPolylineConnections(this.selected),"polyline-from"===this.resizeMode)r||a?this.joinPolylines(this.selected,o,!1,r):this.renderer.movePolylinePoint(this.selected,0,s.x,s.y);else if("polyline-to"===this.resizeMode)r||a?this.joinPolylines(this.selected,o,!0,r):this.renderer.movePolylinePoint(this.selected,-1,s.x,s.y);else if(this.resizeMode.startsWith("polyline-")){var l=1*this.resizeMode.substring(9);this.renderer.movePolylinePoint(this.selected,l,s.x,s.y)}}this.setPropertiesVisible(null),this.renderer.hideTracker(),this.renderer.hideLineTracker(),this.restoreMode(),E2DEvents.active_connector=null,E2DEvents.prev_connector=null,E2DEvents.connector_z=null,this.selected&&this.saveUndoRedoPoint(0,"urConnectPoly")},E2DEditor.prototype.createPolyline=function(e,t,i){if(this.unselect(),E2DEvents.polylineStarted=!0,i){var n=i.split("--"),o=n[0],s=n[1],r=document.getElementById(o),a=this.pointFromConnector(i),l="to"===s;if("from"===s)return void this.reopenPolyline(r,!0,a.x,a.y);if(l)return void this.reopenPolyline(r,!1,a.x,a.y);e=a.x,t=a.y}var h=this;this.renderer.createLine(this.shapeLibraryList[0],"poly-line",e,t).done(function(i){h.createPolylineAsync(i,e,t)})},E2DEditor.prototype.createPolylineAsync=function(e,t,i){this.clearConnectionPoints(),this.select(e),this.selected.setAttribute("id","polyline_"+E2DUtils.createUUID()),this.renderer.moveLine(this.selected,t,i,!0);var n=InsertedShape.CreateShapeFromConnector(this.selected,this.shapeLibraryList[0]);this.insertedShapes.addShape(n,!(this.enable3dFloor||this.enable3dWalls)),this.addNewShapeListeners(this.selected),this.container.on("vmousemove",E2DEvents.onDraw)},E2DEditor.prototype.reopenPolyline=function(e,t,i,n){this.clearConnectionPoints(),this.clearPolylineConnections(e),this.select(e),t&&this.renderer.reversePolylinePoints(e),this.renderer.addPolylinePoint(e,-1,i,n),this.container.on("vmousemove",E2DEvents.onDraw)},E2DEditor.prototype.closePolyline=function(){if(this.clearSnap(),E2DEvents.polylineStarted&&(E2DEvents.polylineStarted=!1,this.renderer.closePolyline(this.selected),this.insertedShapes.updateConnector(this.selected),this.container.off("vmousemove",E2DEvents.onDraw),this.setPropertiesVisible(null),this.showConnectionPoints(),this.saveUndoRedoPoint(0,"urClosePoly"),this.events.polyinserted)){var e=new E2DEventArgument("OnInserted",{handler:"OnInserted.rdx"},null,this.selected.id,null,null);E2DEvents.doSubmitEvent("OnEditor2DInserted",[e],1,"urNewShapes")}},E2DEditor.prototype.finishPolyline=function(){if(this.clearSnap(),E2DEvents.polylineStarted)if(E2DEvents.polylineStarted=!1,this.renderer.getPolylineNumberOfPoints(this.selected)>2){if(this.renderer.finishPolyline(this.selected),this.insertedShapes.updateConnector(this.selected),this.container.off("vmousemove",E2DEvents.onDraw),this.setPropertiesVisible(null),this.showConnectionPoints(),this.saveUndoRedoPoint(0,"urFinishPoly"),this.events.polyinserted){var e=new E2DEventArgument("OnInserted",{handler:"OnInserted.rdx"},null,this.selected.id,null,null);E2DEvents.doSubmitEvent("OnEditor2DInserted",[e],1,"urNewShapes")}}else this.deleteItem(this.selected),this.saveUndoRedoPoint(0,"urFinishPoly")},E2DEditor.prototype.undoPolyline=function(){E2DEvents.polylineStarted&&(this.renderer.undoPolylineLastSegment(this.selected),this.insertedShapes.updateConnector(this.selected))},E2DEditor.prototype.addPolylinePoint=function(e){if(e=e||this.selected,this.renderer.isPolyline(e)){var t=this.renderer.getPolylineSelectedSegment(e);t&&2===t.length&&(this.clearPolylineConnections(e),this.renderer.addPolylineMiddlePoint(e,t[0],t[1]),this.insertedShapes.updateConnector(e))}},E2DEditor.prototype.deletePolylinePoint=function(e){if(e=e||this.selected,this.renderer.isPolyline(e)&&this.renderer.getPolylineNumberOfPoints(e)>2){var t=document.getElementById("resize-from"),i=document.getElementById("resize-to"),n=-1;t.classList.contains("lineTrackerResizeSelected")?n=1*t.getAttributeNS(null,"plPoint"):i.classList.contains("lineTrackerResizeSelected")&&(n=1*i.getAttributeNS(null,"plPoint")),-1!==n&&(this.renderer.removePolylinePoint(e,n),this.insertedShapes.updateConnector(e))}},E2DEditor.prototype.deletePolylineSegment=function(e,t,i){if(e=e||this.selected,this.renderer.isPolyline(e)){if(t="number"!=typeof t?-1:t,i="number"!=typeof i?-1:i,"number"!=typeof t||-1===t){var n=document.getElementById("resize-from");t=n.hasAttributeNS(null,"plPoint")?1*n.getAttributeNS(null,"plPoint"):-1}if("number"!=typeof i||-1===i){var o=document.getElementById("resize-to");i=o.hasAttributeNS(null,"plPoint")?1*o.getAttributeNS(null,"plPoint"):-1}if(-1===t||-1===i)return;if(this.renderer.isPolylineClosed(e))this.renderer.removePolylineSegment(e,t,i),this.insertedShapes.updateConnector(e);else{var s=this.renderer.splitPolylineBySegment(e,t,i);this.renderer.remove(e);var r,a,l,h=this.insertedShapes.removeShape(e);r=(l=s[0])[0],a=l[l.length-1];var d=InsertedShape.CloneShape(h);d.id="polyline_"+E2DUtils.createUUID(),d.path=this.convertPathToUserString(l),d.x=r.x,d.y=r.y,d.width=a.x,d.height=a.y,this.createNewConnector(d),r=(l=s[1])[0],a=l[l.length-1];var c=InsertedShape.CloneShape(h);c.id="polyline_"+E2DUtils.createUUID(),c.path=this.convertPathToUserString(l),c.x=r.x,c.y=r.y,c.width=a.x,c.height=a.y,this.createNewConnector(c)}}},E2DEditor.prototype.joinPolylines=function(e,t,i,n){this.renderer.isPolyline(e)&&this.renderer.isPolyline(t)&&(this.clearPolylineConnections(e),this.clearPolylineConnections(t),this.renderer.joinPolylines(e,t,i,n),this.insertedShapes.updateConnector(e),this.renderer.remove(t),this.insertedShapes.removeShape(t),this.container.off("vmousemove",E2DEvents.onDraw),this.clearConnectionPoints())},E2DEditor.prototype.clearPolylineConnections=function(e){if(this.renderer.isPolyline(e))for(var t=this.insertedShapes.getAttachedLines(e.id),i=0,n=t.length;i<n;i++){var o=document.getElementById(t[i]);this.deleteItem(o,!0)}},E2DEditor.prototype.connectNewLine=function(e,t){var i=t.split("--"),n=e.split("--"),o=new InsertedShape;return o.source=this.mode,o.shapeFromId=n[0],o.shapeFromPointIndex=n[1],o.shapeToId=i[0],o.shapeToPointIndex=i[1],this.createNewConnector(o)},E2DEditor.prototype.hasShapeConnectionPoint=function(e,t){if(this.renderer.isPolyline(e))return!0;var i=this.getLibraryProperties(e.id);if(!i||!i.connectionPoints||0===i.connectionPoints.length)return!1;for(var n=t.split("__"),o=0,s=i.connectionPoints.length;o<s;o++)if(i.connectionPoints[o].id===n[0])return!0;return!1},E2DEditor.prototype.bringToFront=function(e,t){for(var i=e?[e]:this.getSelectedShapes(),n=0,o=i.length;n<o;n++)i[n]=this.renderer.bringToFront(i[n]),this.addNewShapeListeners(i[n]);t||1!==i.length||this.select(i[0])},E2DEditor.prototype.sendToBack=function(e,t){for(var i=e?[e]:this.getSelectedShapes(),n=0,o=i.length;n<o;n++){var s=this.renderer.sendToBack(i[n]);this.addNewShapeListeners(s)}t||1!==i.length||this.select(document.getElementById(i[0].id))},E2DEditor.prototype.selectById=function(e){if(e){var t=document.getElementById(e);this.select(t)}},E2DEditor.prototype.addSelectionById=function(e,t,i){if(e){var n=document.getElementById(e);E2DEvents.onHitAsync(n,0,0,t,i)}},E2DEditor.prototype.removeSelectionById=function(e,t,i){if(e){var n=document.getElementById(e);E2DEvents.onHitAsync(n,0,0,t,i)}},E2DEditor.prototype.select=function(e){if(!this.isShapesLoadPending()&&e)if(e.id!==this.ORIGIN_ID){var t=this.getBehaviour(e.id,!0);!t.move.background||this.activeBackground?t.move.noSelect||t.noGroup?this.setHelp("warning","Given shape cannot be selected."):e!==this.selected&&(E2DEvents.hideExtraToolbars(),this.clearDragCache(),this.selected=e,this.selectedBehaviour=t,this.multipleSelectShapes.prevSelected=e,this.renderer.showTracker(this.selected),this.renderer.isMultipleSelect(this.selected)||this.renderer.showMultipleSelectors(!1),$("#"+this.renderer.TRACKER_GROUP_ID).on("vmouseover",E2DEvents.onMouseOver),$("#"+this.renderer.LINE_TRACKER_GROUP_ID).on("vmouseover",E2DEvents.onMouseOver),this.setHelp("info","To move the shape, drag it. To resize,use resize boxes.For finer moves use arrow keys."),this.onselect(this),this.updateShapeInfo(this.selected,null,!0),this.performCheckInclusions(this.selected),this.performCheckCollisions(this.selected),this.performCheckPolylineQuotes(this.selected),this.performCheckOverlappings(this.selected),E2DEventBus.dispatch("shapeSelected",this.selected.id,!0)):this.setHelp("warning","Background elements cannot be selected.")}else this.setHelp("warning","Origin cannot be selected.")},E2DEditor.prototype.unselect=function(){this.selected&&(this.textEditMode&&(this.finishTextEdit(),this.textEditMode=!1),"text"!==this.mode&&(this.textModeBeginNew=!1),$("#"+this.renderer.TRACKER_GROUP_ID).off("vmouseover",E2DEvents.onMouseOver),$("#"+this.renderer.LINE_TRACKER_GROUP_ID).off("vmouseover",E2DEvents.onMouseOver),E2DEventBus.dispatch("shapeSelected",this.selected.id,!1),this.selected=null,this.selectedBehaviour=null,this.insertedShapes.clearCalculated(),this.onunselect(this),this.updateShapeInfo(null),this.renderer.hideSnapLine(),this.renderer.hideTracker(),this.renderer.hideLineTracker(),this.renderer.showMultipleSelectors(!1),this.clearCollidingGhosts(),this.clearExternalGhosts(),this.clearPolylineQuotes(),this.clearOverlappingGhosts(),this.multipleSelectShapes.reset(),E2DEvents.hideExtraToolbars())},E2DEditor.prototype.selectAll=function(){var e=$.merge(this.renderer.getAllShapes(this.container[0].ownerDocument),this.renderer.getAllConnectors(this.container[0].ownerDocument));this.selectShapes(e)},E2DEditor.prototype.selectGroup=function(){if(this.selected)if(this.renderer.isMultipleSelect(this.selected))this.setHelp("info","Please, select a single shape");else{var e=this.insertedShapes.getShapeById(this.selected.id);if(e&&e.group){var t=this.insertedShapes.getShapesByGroup(e.group);!t||t.length<=0||this.selectIShapes(t)}}else this.setHelp("info","No shape selected")},E2DEditor.prototype.selectIShapes=function(e){if(e&&!(e.length<=0)){for(var t=[],i=0,n=e.length;i<n;i++){var o=document.getElementById(e[i].id);o&&(t[t.length]=o)}this.selectShapes(t)}},E2DEditor.prototype.selectShapes=function(e){if(e&&!(e.length<=0)){this.unselect(),this.multipleSelectShapes.setSelectedShapes(e);var t=this.resetMultipleSelector();this.updateShapeInfo(t),this.select(t),this.renderer.updateTracker(this.selected),this.selectedBounds=this.renderer.bounds(this.selected)}},E2DEditor.prototype.selectPolylineSegment=function(e,t){if(this.selected&&this.renderer.isPolyline(this.selected)){var i=this.renderer.getPolylineSegment(this.selected,e,t);i&&i.length>0&&(this.renderer.updateTracker(this.selected,i),this.updateShapeInfo(this.selected))}},E2DEditor.prototype.unselectPolylineSegment=function(){this.selected&&this.renderer.isPolyline(this.selected)&&(this.renderer.clearTrackerSegments(),this.renderer.updateTracker(this.selected),this.updateShapeInfo(null))},E2DEditor.prototype.startTextEdit=function(e){this.setHelp("info","Enter text and then click anywhere outside the text area");var t=this.renderer.getShapeText(e),i=this.renderer.getTextBounds(e,""),n=$("#E2DShapeText");n.val(t||""),n.css({visibility:"visible",left:i.x>3?i.x-3:0,top:i.y>3?i.y-3:0,width:i.width>=35?parseInt(i.width):35,height:i.height>=35?parseInt(i.height):35});var o=this.renderer.getFont(this.selected);o=E2DFont.mergeWithDefault(o),n.css({"font-size":o.size,color:o.color,"font-family":o.family}),this.renderer.remove(n[0]),this.container.append(n),n.focus(),this.container.off("vmousedown",E2DEvents.onMouseDown),this.container.off("vmouseup",E2DEvents.onMouseUp),this.container.off("selectstart",E2DEvents.onSelectStart),this.container.off("keyup",E2DEvents.onKeyUp),this.container.off("vmousemove",E2DEvents.onDrag),this.container.on("vmousedown",E2DEvents.onTextEditEnd),this.textEditMode=!0},E2DEditor.prototype.finishTextEdit=function(){this.setHelp("info","Finished editing text");var e=$("#E2DShapeText"),t=e.val();t&&0!==t.length||(t=" "),this.clearShapeText(),this.renderer.setShapeText(this.selected,t);var i=this.insertedShapes.getShapeById(this.selected.id);i&&i.update(null,null,null,null,null,null,null,t),this.renderer.isConnector(this.selected)||this.resetTextForAttachedConnectors(this.selected),e.css("visibility","hidden"),this.container.on("vmousedown",E2DEvents.onMouseDown),this.container.on("vmouseup",E2DEvents.onMouseUp),this.container.on("selectstart",E2DEvents.onSelectStart),this.container.on("keyup",E2DEvents.onKeyUp),this.container.off("vmousedown",E2DEvents.onTextEditEnd),this.textEditMode=!1},E2DEditor.prototype.clearShapeText=function(e){if(e||this.selected)for(var t=null,i=0,n=(t=e?[e]:this.getSelectedShapes()).length;i<n;i++){var o=t[i],s=this.insertedShapes.getShapeById(o.id);s&&s.text&&this.renderer.clearShapeText(o),this.renderer.isConnector(o)||this.clearTextForAttachedConnectors(o)}},E2DEditor.prototype.resetShapeText=function(e){if(e||this.selected)for(var t=null,i=0,n=(t=e?[e]:this.getSelectedShapes()).length;i<n;i++){var o=t[i],s=this.insertedShapes.getShapeById(o.id);s&&s.text&&this.renderer.setShapeText(o,s.text),this.renderer.isConnector(o)||this.resetTextForAttachedConnectors(o)}},E2DEditor.prototype.clearTextForAttachedConnectors=function(e){e||(e=this.selected);for(var t=this.renderer.getAllConnectorsForShape(e),i=0,n=t.length;i<n;i++)t[i]&&this.clearShapeText(t[i])},E2DEditor.prototype.resetTextForAttachedConnectors=function(e){e||(e=this.selected);for(var t=this.renderer.getAllConnectorsForShape(e),i=0,n=t.length;i<n;i++)t[i]&&this.resetShapeText(t[i])},E2DEditor.prototype.getSelectedShapes=function(){var e=this.multipleSelectShapes.getShapes();return 0===e.length&&this.selected&&(e=[this.selected]),e},E2DEditor.prototype.getSelectedShapeIDs=function(){var e=this.multipleSelectShapes.getShapeIDs();return 0===e.length&&this.selected&&(e=[this.selected.id]),e},E2DEditor.prototype.getSelectedIShapes=function(){var e=this.getSelectedShapeIDs();return this.insertedShapes.getShapesByIds(e,!0)},E2DEditor.prototype.isSingleShapeSelected=function(){return!!this.selected&&(!this.renderer.isConnector(this.selected)&&!this.renderer.isMultipleSelect(this.selected))},E2DEditor.prototype.setGridSizeEx=function(e){e&&($("#_pageGridSize").val(e),1!==this.getGridSize()&&this.setGridSize(e))},E2DEditor.prototype.setGridSize=function(e){var t=E2DUtils.splitUnits(e+"");switch(e=0,t[1]){case"in":e=t[0]*this.DPI;break;case"mm":e=t[0]*(this.DPI/25.4);break;default:e=1*t[0]}this.GRID_SIZE=e},E2DEditor.prototype.getGridSize=function(){return this.GRID_SIZE},E2DEditor.prototype.applyGridSize=function(e,t){return t=t||this.getGridSize(),Math.round(e/t)*t},E2DEditor.prototype.setRotationalGridSizeEx=function(e){e&&($("#_pageRotateGrid").val(e),1!==this.GRID_ROTATE&&this.setRotationalGridSize(e))},E2DEditor.prototype.setRotationalGridSize=function(e){this.GRID_ROTATE=e+""},E2DEditor.prototype.reset=function(){this.removeAll(),this.setPageSize(this.DEFAULT_PAGE_WIDTH,this.DEFAULT_PAGE_HEIGHT)},E2DEditor.prototype.removeAll=function(e){this.unselect(),this.clearConnectionPoints(),this.hideSmartLineMiddleConnectionPoints(),this.hideSmartLineOrthoConnectionPoints();for(var t=$.merge(this.renderer.getAllShapes(this.container[0].ownerDocument),this.renderer.getAllConnectors(this.container[0].ownerDocument)),i=0,n=t.length;i<n;i++)e&&t[i].id===this.ORIGIN_ID||(this.renderer.remove(t[i]),this.insertedShapes.removeShape(t[i]))},E2DEditor.prototype.removeBackground=function(){this.unselect(),this.clearConnectionPoints(),this.hideSmartLineMiddleConnectionPoints(),this.hideSmartLineOrthoConnectionPoints();for(var e=$.merge(this.renderer.getAllShapes(this.container[0].ownerDocument),this.renderer.getAllConnectors(this.container[0].ownerDocument)),t=0,i=e.length;t<i;t++){this.insertedShapes.getShapeById(e[t].id).hasBehaviour("(BACKGROUND)")&&(this.renderer.remove(e[t]),this.insertedShapes.removeShape(e[t]))}},E2DEditor.prototype.setMode=function(e){this.mode=e,this.resizeMode="";var t=!1;switch(E2DEvents.lineStarted=!1,E2DEvents.polylineStarted=!1,this.clearConnectionPoints(),e){case"poly-line":this.setHelp("info","Polyline Mode: To Draw a polyline click to set the point, move the mouse to create the line (ESC to exit, RETURN to close, DELETE to undo last segment)"),this.finalizeLineMode(e),t=!0;break;case"smart-line":this.setHelp("info","SmartLine Mode: Connect a smart line to another smart line, a smart line hub or a shape (ESC to exit)"),this.finalizeLineMode(e,!0);break;case"line":this.setHelp("info","Connector Mode: To Draw the connector, move your mouse over to the drawing area, click and drag"),this.finalizeLineMode(e);break;case"link-line":this.setHelp("info","Link Mode: To link two shapes, move your mouse over to the drawing area, click and drag"),this.finalizeLineMode(e);break;case"quote-line":this.setHelp("info","Quote Mode: To quote, move your mouse over to the drawing area, click and drag"),this.toggleQuotes(!0),this.finalizeLineMode(e),t=!0;break;case"ortho-line":case"curve-line":this.setHelp("info","Connector Mode: To Draw the connector, move your mouse over to the drawing area, click and drag"),this.finalizeLineMode(e);break;case"text":this.setHelp("info","Text Mode: To Draw the Text shape, move your mouse over to the drawing area, click and drag"),this.container.css("cursor","default");break;case"PAGE_DRAG":this.setHelp("info","Page drag Mode"),this.container.css("cursor","url(resources/images/e2d/cursor_hand.png),move"),t=!0;break;case"ZOOM_IN":this.setHelp("info","Zoom In Mode: click to zoom"),$(".btnToolsOnToolbarActive").removeClass("btnToolsOnToolbarActive"),$("#btnZoomIn").addClass("btnToolsOnToolbarActive"),this.container.css("cursor","zoom-in"),t=!0;break;case"ZOOM_OUT":this.setHelp("info","Zoom Out Mode: click to zoom"),$(".btnToolsOnToolbarActive").removeClass("btnToolsOnToolbarActive"),$("#btnZoomOut").addClass("btnToolsOnToolbarActive"),this.container.css("cursor","zoom-out"),t=!0;break;case"select":$("#btnTools").button({icons:{primary:"ui-icon-menu"}}),$(".btnToolsOnToolbarActive").removeClass("btnToolsOnToolbarActive"),$("#btnToolSelect").addClass("btnToolsOnToolbarActive"),this.container.css("cursor","default"),t=!0;break;default:t=!0}t||this.setPropertiesVisible(null)},E2DEditor.prototype.restoreMode=function(){"select"!==this.mode&&"text"!==this.mode&&"line"!==this.mode&&"curve-line"!==this.mode&&"ortho-line"!==this.mode&&"smart-line"!==this.mode&&"link-line"!==this.mode&&"quote-line"!==this.mode&&"poly-line"!==this.mode&&"PAGE_DRAG"!==this.mode?this.setMode("select"):this.setMode(this.mode)},E2DEditor.prototype.finalizeLineMode=function(e,t){this.renderer.loadShape(this.shapeLibraryList[0],e,this),this.showConnectionPoints(),t&&this.showSmartLineMiddleConnectionPoints(!1),this.container.css("cursor","crosshair")},E2DEditor.prototype.connectionPointTemplate=function(e,t,i,n){var o=e.x*this.zoom-15,s=e.y*this.zoom-15,r=t.name?t.name+" - ":"";r+=e.label?this.checkTranslation(e.label):e.cpId;var a=1*t.rotation+1*e.direction;return isNaN(a)||(r=E2DUtils.arrowFromRotation(a%360)+" "+r),"<div id='"+e.id+"' class='cp "+i+"' linkClass='"+n+"' title='"+r+"' oX='"+e.x+"' oY='"+e.y+"' oZ='"+e.z+"' style='width:30px;height:30px;position:absolute;left:"+o+"px;top:"+s+"px;z-index:10000' onmouseover='E2DEvents.connectorActive(this)' onmouseout='E2DEvents.connectorInactive()'/>"},E2DEditor.prototype.connectionPointPolylineTemplate=function(e,t,i){return"<div id='"+e+"' class='plcp' oX='"+t+"' oY='"+i+"' oZ='0' style='width:30px;height:30px;position:absolute;left:"+(t*this.zoom-15)+"px;top:"+(i*this.zoom-15)+"px;z-index:10000' onmouseover='E2DEvents.connectorActive(this)' onmouseout='E2DEvents.connectorInactive()'/>"},E2DEditor.prototype.connectionPointSmartlineTemplate=function(e,t,i,n){return"<div id='"+e+"' class='cp "+t+"' oX='"+i+"' oY='"+n+"' oZ='0' style='width:30px;height:30px;position:absolute;left:"+(i*this.zoom-15)+"px;top:"+(n*this.zoom-15)+"px;z-index:10000' onmouseover='E2DEvents.connectorActive(this)' onmouseout='E2DEvents.connectorInactive()'/>"},E2DEditor.prototype.pointFromConnector=function(e){if(!e)return null;var t=$("#"+e);return{x:1*t.attr("oX"),y:1*t.attr("oY"),z:1*t.attr("oZ")}},E2DEditor.prototype.clearConnectionPoints=function(e){var t="link-line"===this.mode,i=this.renderer.isLinkLine(this.selected);if(e&&(t||i)){var n="",o=this.insertedShapes.getConnectionShape(this.selected.id,"from");o.shapeID&&(n=this.getLinkClass(o.shapeID,o.pointID));var s=this.insertedShapes.getConnectionShape(this.selected.id,"to");s.shapeID&&(n=this.getLinkClass(s.shapeID,s.pointID));var r=this.getLinkClassTarget(n);return r&&(n=r),void $("#connectors div").not("[linkClass='']").not("[linkClass=null]").not("[linkClass=undefined]").each(function(){var e=$(this),t=e.attr("id").split("--"),i=E2DGlobals.e2d.getLinkClass(t[0],t[1]);E2DUtils.isInSameClass(i,n)||(delete E2DGlobals.e2d.shapesWithConnectionPoints[t[0]],e.remove())})}$("#connectors").empty(),this.shapesWithConnectionPoints=[],E2DEvents.active_connector=null},E2DEditor.prototype.showConnectionPoints=function(){this.selected&&(this.renderer.isMultipleSelect(this.selected)||(this.renderer.isPolyline(this.selected)?("quote-line"===this.mode||"poly-line"===this.mode||"resize"===this.mode&&this.resizeMode.startsWith("polyline-"))&&this.addConnectionPointsForPolyline(this.selected):this.addConnectionPointsForShape(this.selected)))},E2DEditor.prototype.addConnectionPointsForShape=function(e,t,i,n){if(e&&!this.renderer.isConnector(e)&&!this.shapesWithConnectionPoints[e.id]){i=i||E2DEvents.active_connector,n=n||E2DEvents.prev_connector;var o="quote-line"===this.mode||this.renderer.isQuoteLine(this.selected),s="link-line"===this.mode,r=this.renderer.isLinkLine(this.selected),a=this.insertedShapes.getShapeById(e.id);if(a&&!(a.hasBehaviour("(BACKGROUND)")||(s||r)&&a.hasBehaviour("(NOLINKS)"))){var l="";if(r&&t){var h=this.insertedShapes.getConnectionShape(this.selected.id,"from");h.shapeID&&(l=this.getLinkClass(h.shapeID,h.pointID));var d=this.insertedShapes.getConnectionShape(this.selected.id,"to");d.shapeID&&(l=this.getLinkClass(d.shapeID,d.pointID))}var c=this.getLinkClassTarget(l);c&&(l=c);for(var u="",p=this.renderer.getConnectionPointObjs(e,o),g=0,y=p.length;g<y;g++)if(p[g]){var f="";if((s||r)&&(f=this.getLinkClass(a.id,p[g].cpId)),E2DUtils.isInSameClass(f,l))if((s||r)&&(E2DEvents.lineStarted||i||n)&&(this.renderer.isConnectionPointWithXY(p[g])||this.renderer.isCommonLinkClassWithXY(f,l)))for(var v=this.renderer.getSubConnectionPointObjs(e,p[g],f,l),m=0,S=v.length;m<S;m++)u+=this.connectionPointTemplate(v[m],a,"subcp",f);else u+=this.connectionPointTemplate(p[g],a,"scp",f)}$("#connectors").append(u),this.shapesWithConnectionPoints[e.id]=!0}}},E2DEditor.prototype.addConnectionPointsForPolyline=function(e){if(e&&this.renderer.isPolyline(e)&&!this.shapesWithConnectionPoints[e.id]){for(var t="",i=this.renderer.getPolylineConnectionPointObjs(e),n=0,o=i.length;n<o;n++)i[n]&&(t+=this.connectionPointPolylineTemplate(i[n].id,i[n].x,i[n].y));$("#connectors").append(t),this.shapesWithConnectionPoints[e.id]=!0}},E2DEditor.prototype.removeConnectionPoints=function(e){if(e){if(!this.shapesWithConnectionPoints[e.id])return;$("#connectors div").each(function(){var t=$(this),i=t.attr("id").split("--");e.id===i[0]&&(delete E2DGlobals.e2d.shapesWithConnectionPoints[i[0]],t.remove())})}else $("connector").remove(),$("connection-point").remove(),this.clearConnectionPoints()},E2DEditor.prototype.group=function(e,t,i){if(!$("#toolGroup").hasClass("toolItemDisabled")){for(var n,o,s=[],r=[],a=this.multipleSelectShapes.getShapes(),l=0,h=a.length;l<h;l++)if(n=a[l],!this.renderer.isConnector(n)&&(o=this.insertedShapes.getShapeById(n.id))){r[r.length]=n;var d=o.shapeConnections;if(d&&d.length>0)for(var c=0,u=d.length;c<u;c++){var p=d[c],g=this.insertedShapes.getOtherConnectedShape(p.lineID,o.id);if(g&&!this.multipleSelectShapes.containsById(g.id)){var y=document.getElementById(p.lineID);s[s.length]=y,this.multipleSelectShapes.containsById(p.lineID)&&this.multipleSelectShapes.removeShape(y)}}}for(var f=[],v=0,m=(a=this.multipleSelectShapes.getShapes()).length;v<m;v++)n=a[v],this.renderer.isConnector(n)&&(o=this.insertedShapes.getShapeById(n.id))&&((!o.lineConnections.from.shapeID||this.multipleSelectShapes.containsById(o.lineConnections.from.shapeID))&&(!o.lineConnections.to.shapeID||this.multipleSelectShapes.containsById(o.lineConnections.to.shapeID))?f[f.length]=n:(s[s.length]=n,this.multipleSelectShapes.removeShape(n)));this.deleteItems(s,!0,!0);var S=this.multipleSelectShapes.bbox,E={};E.id=e,E.source=e,E.name=t,E.description=i,E.shapeMode=1,E.group3d=[],E.group2d={},E.group2d.shapes=[],E.group2d.connectors=[],E.width=E2DUtils.round(S.width/this.scale,4),E.height=E2DUtils.round(S.height/this.scale,4),E.depth=E2DUtils.round(S.depth/this.scale,4);for(var D,b,x=E2DUtils.round(this.convertGraphXToUserX(S.x),this.numberOfDecimal),I=E2DUtils.round(this.convertGraphYToUserY(S.y),this.numberOfDecimal),C=E2DUtils.round(this.convertGraphZToUserZ(S.z),this.numberOfDecimal),T=E2DUtils.round(this.convertGraphDataToUserData(S.width),this.numberOfDecimal),P=E2DUtils.round(this.convertGraphDataToUserData(S.height),this.numberOfDecimal),L=E2DUtils.round(this.convertGraphDataToUserData(S.depth),this.numberOfDecimal),O=this.convertUserXToGraphX(x)/this.scale,w=this.convertUserYToGraphY(I)/this.scale,G=this.convertUserZToGraphZ(C)/this.scale,M=0,R=r.length;M<R;M++){n=r[M],D=this.renderer.bounds(n);var A=(o=this.insertedShapes.getShapeById(n.id)).decodeBehaviour("(ORIGIN=");if(A.found){var k=this.applyShapeOriginToUserData(D.x,D.y,D.width,D.height,A.value);D.x=k.x,D.y=k.y}(b={}).id=o.id,b.source=o.source,b.x=E2DUtils.round(D.x/this.scale-O,4),b.y=E2DUtils.round(D.y/this.scale-w,4),b.z=E2DUtils.round(D.z/this.scale-G,4),b.width=E2DUtils.round(D.width/this.scale,4),b.height=E2DUtils.round(D.height/this.scale,4),b.depth=E2DUtils.round(D.depth/this.scale,4),b.rotation=D.rotation,E.group2d.shapes[E.group2d.shapes.length]=b}for(var N=0,U=f.length;N<U;N++){n=f[N],D=this.renderer.bounds(n),o=this.insertedShapes.getShapeById(n.id),(b={}).source=o.source,b.x1=E2DUtils.round(D.x/this.scale-O,4),b.y1=E2DUtils.round(D.y/this.scale-w,4),b.x2=E2DUtils.round(D.x2/this.scale-O,4),b.y2=E2DUtils.round(D.y2/this.scale-w,4),b.ctrl1x=D.controlX>0?E2DUtils.round(D.controlX/this.scale-O,4):-1,b.ctrl1y=D.controlY>0?E2DUtils.round(D.controlY/this.scale-w,4):-1,b.ctrl2x=D.controlX2>0?E2DUtils.round(D.controlX2/this.scale-O,4):-1,b.ctrl2y=D.controlY2>0?E2DUtils.round(D.controlY2/this.scale-w,4):-1,b.shapeFromId=o.shapeFromId,b.shapeFromPointIndex=o.shapeFromPointIndex,b.shapeToId=o.shapeToId,b.shapeToPointIndex=o.shapeToPointIndex,b.path="";for(var B=0,_=D.points.length;B<_;B++){var z=D.points[B],V=E2DUtils.round(z.x/this.scale-O,4),F=E2DUtils.round(z.y/this.scale-w,4);b.path+=V+","+F+" "}b.path=b.path.trim(),E.group2d.connectors[E.group2d.connectors.length]=b}var H=new InsertedShape;H.id="shape_"+E2DUtils.createUUID(),H.source=E.id,H.x=x,H.y=I,H.z=C,H.width=T,H.height=P,H.depth=L,H.needRefresh=!0,this.insertedShapes.addShape(H,!0),this.unselect(),this.deleteItems(f,!0,!0),this.deleteItems(r,!0,!0),this.groupProp=E,this.needRefresh=!0,E2DEvents.doSubmitEvent("OnEditor2DRegrouped",null,1,"urRegroupShapes")}},E2DEditor.prototype.regroup=function(e){if(!$("#toolGroup").hasClass("toolItemDisabled")){for(var t,i,n=[],o=[],s=new SelectedShapes(this.renderer),r=this.insertedShapes.getShapes(!1),a=0,l=r.length;a<l;a++)if((i=r[a]).hasBehaviour("(NOGROUP)"))i.removeBehaviour("(NOGROUP)");else{if(!(t=document.getElementById(i.id)))continue;this.renderer.isConnector(t)?o[o.length]=t:n[n.length]=t,s.addShape(t,this.renderer.getBoundingBox(t))}var h=null,d=this.groupInfo.main.getFullSource();if("APPLY"===e||"APPLYALL"===e){var c,u,p=Date.now(),g=s.bbox,y=this.groupInfo.main.decodeBehaviour("(ORIGIN=");if(y.found){var f=this.applyShapeOriginToGraphData(g.x,g.y,g.width,g.height,y.value);g.x=f.x,g.y=f.y}(h=E2DUtils.cloneObject(this.libraryProperties[d])).id=d+"_"+p,h.source=this.groupInfo.main.source+"_"+p,h.name=this.groupInfo.main.name+" - "+p,h.description=this.groupInfo.main.description,h.shapeMode=1,h.group3d=[],h.group2d={},h.group2d.shapes=[],h.group2d.connectors=[],h.width=E2DUtils.round(g.width,4),h.height=E2DUtils.round(g.height,4),h.depth=E2DUtils.round(g.depth,4),this.groupInfo.main.x=E2DUtils.round(this.convertGraphXToUserX(g.x),this.numberOfDecimal),this.groupInfo.main.y=E2DUtils.round(this.convertGraphYToUserY(g.y),this.numberOfDecimal),this.groupInfo.main.z=E2DUtils.round(this.convertGraphZToUserZ(g.z),this.numberOfDecimal),this.groupInfo.main.width=E2DUtils.round(this.convertGraphDataToUserData(g.width),this.numberOfDecimal),this.groupInfo.main.height=E2DUtils.round(this.convertGraphDataToUserData(g.height),this.numberOfDecimal),this.groupInfo.main.depth=E2DUtils.round(this.convertGraphDataToUserData(g.depth),this.numberOfDecimal);for(var v=this.convertUserXToGraphX(this.groupInfo.main.x),m=this.convertUserYToGraphY(this.groupInfo.main.y),S=this.convertUserZToGraphZ(this.groupInfo.main.z),E=0,D=n.length;E<D;E++)t=n[E],c=this.renderer.bounds(t),i=this.insertedShapes.getShapeById(t.id),(u={}).id=i.id,u.source=i.source,u.x=E2DUtils.round(c.x-v,4),u.y=E2DUtils.round(c.y-m,4),u.z=E2DUtils.round(c.z-S,4),u.width=E2DUtils.round(c.width,4),u.height=E2DUtils.round(c.height,4),u.depth=E2DUtils.round(c.depth,4),u.rotation=c.rotation,h.group2d.shapes[h.group2d.shapes.length]=u;for(var b=0,x=o.length;b<x;b++){t=o[b],c=this.renderer.bounds(t),i=this.insertedShapes.getShapeById(t.id),(u={}).source=i.source,u.x1=E2DUtils.round(c.x-v,4),u.y1=E2DUtils.round(c.y-m,4),u.x2=E2DUtils.round(c.x2-v,4),u.y2=E2DUtils.round(c.y2-m,4),u.ctrl1x=c.controlX>0?E2DUtils.round(c.controlX-v,4):-1,u.ctrl1y=c.controlY>0?E2DUtils.round(c.controlY-m,4):-1,u.ctrl2x=c.controlX2>0?E2DUtils.round(c.controlX2-v,4):-1,u.ctrl2y=c.controlY2>0?E2DUtils.round(c.controlY2-m,4):-1,u.shapeFromId=i.shapeFromId,u.shapeFromPointIndex=i.shapeFromPointIndex,u.shapeToId=i.shapeToId,u.shapeToPointIndex=i.shapeToPointIndex,u.path="";for(var I=0,C=c.points.length;I<C;I++){var T=c.points[I],P=E2DUtils.round(T.x-v,4),L=E2DUtils.round(T.y-m,4);u.path+=P+","+L+" "}u.path=u.path.trim(),h.group2d.connectors[h.group2d.connectors.length]=u}if(this.libraryProperties[h.id]=h,"APPLYALL"===e)for(var O=0,w=r.length;O<w;O++)(i=r[O]).getFullSource()===d&&(i.source=h.source,i.update(null,null,null,this.groupInfo.main.width,this.groupInfo.main.height,this.groupInfo.main.depth,0),(t=document.getElementById(i.id))&&(this.renderer.setDimensions(t,g.width,g.height,g.depth),this.renderer.moveLineWithShape(t,null,null)))}this.deleteItems(o,!0,!0),this.deleteItems(n,!0,!0),this.createNewShape(this.groupInfo.main,!1).done(function(){E2DGlobals.e2d.regroupAsync(e,h)})}},E2DEditor.prototype.regroupAsync=function(e,t){if(this.groupInfo.main&&this.groupInfo.connectors){if(t){var i=this.insertedShapes.getShapeById(this.groupInfo.main.id);i.source=t.source,i.name=t.name}var n=document.getElementById(this.groupInfo.main.id);if(n){for(var o=this.renderer.getConnectionPointObjs(n),s=0,r=o.length;s<r;s++)for(var a=o[s],l=0,h=this.groupInfo.connectors.length;l<h;l++){var d=null,c=InsertedShape.CloneShape(this.groupInfo.connectors[l]);c.shapeFromId===this.groupInfo.main.id&&c.shapeFromPointIndex===a.cpId?(d=document.getElementById(c.id))?(this.insertedShapes.add.addShape(c,!0),this.renderer.connectLine(n,d,"from",c.shapeFromPointIndex)):this.createNewConnector(c):c.shapeToId===this.groupInfo.main.id&&c.shapeToPointIndex===a.cpId&&((d=document.getElementById(c.id))?(this.insertedShapes.add.addShape(c,!0),this.renderer.connectLine(n,d,"to",c.shapeFromToIndex)):this.createNewConnector(c))}this.groupInfo={},!t||"APPLY"!==e&&"APPLYALL"!==e||(this.groupPropID=t.id,E2DEvents.doSubmitEvent("OnEditor2DRegrouped",null,1,"urRegroupShapes"))}}},E2DEditor.prototype.ungroup=function(){if(!$("#toolUngroup").hasClass("toolItemDisabled")&&this.selected&&!this.renderer.isMultipleSelect(this.selected)&&!this.renderer.isConnector(this.selected)){var e=this.insertedShapes.getShapeById(this.selected.id);if(e){var t=this.libraryProperties[e.getFullSource()];if(t&&t.group2d){this.groupInfo={main:E2DUtils.cloneObject(e),connectors:[]};var i=this.renderer.getAllConnectorsForShape(this.selected);if(i&&i.length>0)for(var n=0,o=i.length;n<o;n++){var s=this.insertedShapes.getShapeById(i[n].id);if(!s)return;this.insertedShapes.getConnectionShape(i[n].id,"from").shapeID===this.selected.id&&(s.shapeFromPoint=this.renderer.getConnectorFrom(i[n])),this.insertedShapes.getConnectionShape(i[n].id,"to").shapeID===this.selected.id&&(s.shapeToPoint=this.renderer.getConnectorTo(i[n])),this.groupInfo.connectors[this.groupInfo.connectors.length]=s,this.insertedShapes.removeShapeById(s.id)}this.deleteSelection(!0,!0,!0);for(var r=this.insertedShapes.getShapes(!1),a=0,l=r.length;a<l;a++)r[a].addBehaviour("(NOGROUP)");this.createNewGroup(e,t,null,!1).done(function(e,t){E2DGlobals.e2d.ungroupAsync(e,t)})}}}},E2DEditor.prototype.ungroupAsync=function(e,t){if(e){var i=[],n=[];if(this.groupInfo.connectors&&this.groupInfo.connectors.length>0)for(var o=0,s=e.length;o<s;o++){var r=e[o];if(!this.renderer.isConnector(r))for(var a=this.renderer.getConnectionPointObjs(r),l=0,h=a.length;l<h;l++)for(var d=a[l],c=0,u=this.groupInfo.connectors.length;c<u;c++){var p=null,g=InsertedShape.CloneShape(this.groupInfo.connectors[c]);if(g.shapeFromPoint){if(E2DUtils.isPointTooClose(d,g.shapeFromPoint,.2))if(delete g.shapeFromPoint,g.shapeFromId=d.shapeId,g.shapeFromPointIndex=d.cpId,p=document.getElementById(g.id))i[i.length]=p,this.insertedShapes.addShape(g,!0),this.renderer.connectLine(r,p,"from",g.shapeFromPointIndex);else{var y=this.createNewConnector(g);n[n.length]=y}}else if(g.shapeToPoint&&E2DUtils.isPointTooClose(d,g.shapeToPoint,.2))if(delete g.shapeToPoint,g.shapeToId=d.shapeId,g.shapeToPointIndex=d.cpId,p=document.getElementById(g.id))i[i.length]=p,this.insertedShapes.addShape(g,!0),this.renderer.connectLine(r,p,"to",g.shapeToPointIndex);else{var f=this.createNewConnector(g);n[n.length]=f}}}$.when.apply($,n).done(function(n){E2DGlobals.e2d.ungroupRotateAsync(e,t,i,n)})}},E2DEditor.prototype.ungroupRotateAsync=function(e,t,i,n){var o=$.merge(e,t);o=$.merge(o,i||[]),o=$.merge(o,n||[]),this.selectShapes(o),1*this.groupInfo.main.rotation!=0&&(this.processRotateMultiSelect(this.groupInfo.main.rotation),this.selectShapes(o)),this.groupInfo.bbox=this.multipleSelectShapes.bbox,this.unselect()},E2DEditor.prototype.getConnectionPointFromPropertiesBySource=function(e,t){var i=null,n=this.libraryProperties[e];if(n&&n.connectionPoints)for(var o=t.split("__"),s=0,r=n.connectionPoints.length;s<r;s++){var a=n.connectionPoints[s];if(o[0]===a.id){i=a;break}}return i},E2DEditor.prototype.getConnectionPointFromPropertiesById=function(e,t){var i=null,n=this.insertedShapes.getShapeById(e);return n&&(i=this.getConnectionPointFromPropertiesBySource(n.getFullSource(),t)),i},E2DEditor.prototype.showSmartLineMiddleConnectionPoints=function(e){if(this.hideSmartLineMiddleConnectionPoints(),"smart-line"===this.mode||this.renderer.isSmartLine(this.selected)){for(var t="",i=this.renderer.getAllConnectors(this.container[0],"smart-line"),n=0,o=i.length;n<o;n++){var s=i[n];if(!e||this.selected.id!==s.id){var r=this.renderer.getConnectorCenterPoint(s),a=s.id+"--mid";t+=this.connectionPointSmartlineTemplate(a,"slmcp",r.x,r.y)}}$("#connectors").append(t)}},E2DEditor.prototype.hideSmartLineMiddleConnectionPoints=function(e){e?this.renderer.isConnector(e)&&$("div.slmcp").each(function(){var t=$(this);t.attr("id").split("--")[0]===e.id&&t.remove()}):$("div.slmcp").remove()},E2DEditor.prototype.showSmartLineOrthoConnectionPoints=function(e){if(this.hideSmartLineOrthoConnectionPoints(),"smart-line"===this.mode||this.renderer.isSmartLine(this.selected)){var t="",i=null;i=e?this.renderer.getConnectorFrom(this.selected):this.renderer.getConnectorTo(this.selected);for(var n=this.renderer.getAllConnectors(this.container[0],"smart-line"),o=0,s=n.length;o<s;o++){var r=n[o];if(!this.selected||this.selected.id!==r.id){var a=this.renderer.getConnectorFrom(r),l=this.renderer.getConnectorTo(r),h=E2DUtils.pointLineIntersectionEx(i,a,l);if(E2DUtils.isPointInLine(h,a,l,.1)&&!E2DUtils.isPointTooClose(h,a,2)&&!E2DUtils.isPointTooClose(h,l,2)){var d=r.id+"--ortho";t+=this.connectionPointSmartlineTemplate(d,"slocp",h.x,h.y)}}}$("#connectors").append(t)}},E2DEditor.prototype.hideSmartLineOrthoConnectionPoints=function(){$("div.slocp").remove()},E2DEditor.prototype.setHelp=function(e,t){this.showHelpPopupEnabled&&this.toast!==t&&(this.toast=t,$.toast({icon:e,text:t,loader:!1,position:"bottom-right",stack:3,allowToastClose:!1}))},E2DEditor.prototype.setPropertiesVisible=function(e){if(e!==E2DGlobals.visibleProperties)switch(E2DGlobals.visibleProperties=e,E2DEvents.hideProperties(),E2DUtils.safeBlur(),e){case"shapeProperties":this.shapePropertiesEnabled&&E2DEvents.openShapeProperties();break;case"polyLineProperties":this.polyLinePropertiesEnabled&&E2DEvents.openPolylineProperties();break;case"quoteProperties":this.quotePropertiesEnabled&&E2DEvents.openQuoteProperties()}},E2DEditor.prototype.setFontSize=function(e){e&&(e*=1,isNaN(e)||(E2DFont.size=e,E2DFont.forced=!0))},E2DEditor.prototype.setEnterBehaviour=function(e){this.enterBehaviour=e},E2DEditor.prototype.setUnit=function(e){if(e){var t=this.unit;this.unit=e,this.updateConversionFactor(),$("#_pageUnits").html("<strong>("+this.unit+")</strong>");var i=this.getGridSize();if(1!==i)switch(this.unit){case"in":this.GRID_SIZE_MM=i,this.setGridSize(this.GRID_SIZE_IN);break;case"mm":this.GRID_SIZE_IN=i,this.setGridSize(this.GRID_SIZE_MM)}if(this.updateGrid(),t!==this.unit){var n=0,o=$("#_pageWidth").val(),s=$("#_pageHeight").val();"LANDSCAPE"===this.orientation?o<s&&(n=o,o=s,s=n):s<o&&(n=o,o=s,s=n);var r="in"===this.unit?1/25.4:25.4;o=E2DUtils.round(o*r,2),s=E2DUtils.round(s*r,2),this.updatePageSize(o+"x"+s)}}},E2DEditor.prototype.setNumberOfDecimal=function(e){(e||"number"==typeof e)&&(this.numberOfDecimal=1*e)},E2DEditor.prototype.setScaleFactor=function(e){e&&-1!==e.indexOf(":")?($("#_pageScaleFactor").val(e),e.split(":").length>=2&&(this.scale=e.split(":")[0]/e.split(":")[1])):$("#_pageScaleFactor").val("1:1")},E2DEditor.prototype.setOrigin=function(e){var t={data:this.origin,dfd:69};if(!e)return t;var i=e.replace(/\s/g,"").split(",");if(i.length<2||i.length>5)return t;var n=i[0],o=i[1],s=i[2],r=i[3],a=!1,l="";if(i[4]&&i[4].toLowerCase){var h=i[4].toLowerCase();-1!==h.indexOf("c")&&(l="c",h=h.replace("c","")),-1!==h.indexOf("tl")&&(l="tl",h=h.replace("tl","")),-1!==h.indexOf("tr")&&(l="tr",h=h.replace("tr","")),-1!==h.indexOf("bl")&&(l="bl",h=h.replace("bl","")),-1!==h.indexOf("br")&&(l="br",h=h.replace("br","")),a=-1!==h.indexOf("b")}var d=this.convertGraphDataToUserData(48),c="";s?("+"===s?(s=1,c+="+"):(s=-1,c+="-"),d=this.convertGraphDataToUserData(96)):s=1,r?("+"===r?(r=1,c+="+"):(r=-1,c+="-"),d=this.convertGraphDataToUserData(96)):r=1;var u=d,p=d,g=InsertedShape.CreateShape(this.shapeLibraryList[0],"origin",this.ORIGIN_ID,"","","",n,o,0,d,u,p,0,null,"(ORIGIN=CENTER)",{Orientation:c});return t.data={x:n,y:o,z:0,w:d,h:u,d:p,signX:s,signY:r,signZ:1,position:l,background:a},t.dfd=this.createNewShape(g),t},E2DEditor.prototype.getCurrentOrigin=function(){return this.customOrigin?this.customOrigin:this.origin},E2DEditor.prototype.toggleCustomOrigin=function(){if(this.customOrigin){var e=document.getElementById(this.CUSTOM_ORIGIN_ID);this.unselect(),this.deleteItem(e),this.customOrigin=null}else{var t=this.convertGraphDataToUserData(72),i=t,n=t,o="";this.customOrigin={x:0,y:0,z:0,signX:this.origin.signX,signY:this.origin.signY,signZ:this.origin.signZ},1===this.customOrigin.signX?o+="+":o+="-",1===this.customOrigin.signY?o+="+":o+="-";var s=InsertedShape.CreateShape(this.shapeLibraryList[0],"originCustom",this.CUSTOM_ORIGIN_ID,"O","","",this.customOrigin.x,this.customOrigin.y,this.customOrigin.z,t,i,n,0,null,"",{Orientation:o});this.createNewShape(s)}},E2DEditor.prototype.updateCustomOrigin=function(e){if(e.id===this.CUSTOM_ORIGIN_ID&&(this.customOrigin.x=E2DGlobals.e2d.shapeProps.x.val(),this.customOrigin.y=E2DGlobals.e2d.shapeProps.y.val(),this.customOrigin.z=E2DGlobals.e2d.shapeProps.z.val(),e.custom&&e.custom.Orientation))switch(e.custom.Orientation){case"++":this.customOrigin.signX=1,this.customOrigin.signY=1;break;case"+-":this.customOrigin.signX=1,this.customOrigin.signY=-1;break;case"-+":this.customOrigin.signX=-1,this.customOrigin.signY=1;break;case"--":this.customOrigin.signX=-1,this.customOrigin.signY=-1}},E2DEditor.prototype.toggleHighlightEqualShapes=function(e){e?this.highlightEqualShapes&&(this.highlightEqualShapes=!1,this.updateOnTheFlyStyleForHighlightEqualShapes(this.highlightEqualShapes)):(this.highlightEqualShapes=!this.highlightEqualShapes,this.updateOnTheFlyStyleForHighlightEqualShapes(this.highlightEqualShapes))},E2DEditor.prototype.updateOnTheFlyStyleForHighlightEqualShape=function(e){if(this.highlightEqualShapes&&e&&!e.isConnector()){var t=$("#onTheFly"),i=!1,n=t.text();this.hexToShapeHash||(this.hexToShapeHash=[]);var o=this.shapeToHexHash[e.id],s=E2DUtils.toHexColour(e.getSignature()),r="rgb"+s;if(o!==r){this.hexToShapeHash[s]||(i=!0,n+="\n."+r+" path{fill: #"+s+";}",this.hexToShapeHash[s]=!0),this.shapeToHexHash[e.id]=r;var a=document.getElementById(e.id);a.classList.remove(o),a.classList.add(r)}i&&t.text(n)}},E2DEditor.prototype.updateOnTheFlyStyleForHighlightEqualShapes=function(e){var t=$("#onTheFly"),i=!1,n=t.text();if(this.hexToShapeHash||(this.hexToShapeHash=[]),e){var o=this.insertedShapes.getShapes(!1,!0);if(!o||0===o.length)return;this.shapeToHexHash||(this.shapeToHexHash=[]);for(var s=0,r=o.length;s<r;s++){var a=o[s],l=this.shapeToHexHash[a.id],h=E2DUtils.toHexColour(a.getSignature()),d="rgb"+h;this.hexToShapeHash[h]||(i=!0,n+="\n."+d+" path{fill: #"+h+";}",this.hexToShapeHash[h]=!0),this.shapeToHexHash[a.id]=d;var c=document.getElementById(a.id);c.classList.remove(l),c.classList.add(d)}}else{for(var u=E2DUtils.objectKeys(this.shapeToHexHash),p=0,g=u.length;p<g;p++){var y=this.shapeToHexHash[u[p]],f=document.getElementById(u[p]);f&&f.classList.remove(y)}this.shapeToHexHash=null}i&&t.text(n)},E2DEditor.prototype.updateOnTheFlyStyleForTree=function(e){if(e&&e.length>0){for(var t=$("#onTheFly"),i="",n=0,o=e.length;n<o;n++){var s=e[n];s.hidden=E2DUtils.isStringInList(this.shapeLibraryHideList,s.id),s.icon&&(s.classnodeicon=s.id.replace("|","-"),isNaN(parseInt(s.classnodeicon))||(s.classnodeicon="f"+s.classnodeicon),i+="\n."+s.classnodeicon+"{background-image: url("+s.icon+") !important;}"),s.items&&s.items.length>0&&this.updateOnTheFlyStyleForTree(s.items)}var r=t.text()+i;t.text(r)}},E2DEditor.prototype.addConnectionPoint=function(){var e=this.convertGraphDataToUserData(16),t=e,i=e,n=InsertedShape.CreateShape(this.shapeLibraryList[0],this.CONNECTION_POINT_CLASS,"cp_"+E2DUtils.createUUID(),"Connection Point","","",0,0,0,e,t,i,0,null,"",{Direction:"NONE"});this.createNewShape(n)},E2DEditor.prototype.setOrientation=function(e){if(e&&(e=e.toUpperCase(),$("#_pageLandscape").prop("checked","LANDSCAPE"===e),e!==this.orientation)){this.orientation=e;var t=$("#_pageWidth"),i=$("#_pageHeight"),n=t.val();t.val(i.val()),i.val(n),this.updatePageSize()}},E2DEditor.prototype.setPageSizeEx=function(e){if(e){$("#_pageSize").val(e);var t=e.indexOf("(")+1,i=e.indexOf(")"),n=e.substring(t,i);this.updatePageSize(n)}},E2DEditor.prototype.updatePageSize=function(e){var t=0,i=0;if(e){var n=0;t=1*e.split("x")[0],i=1*e.split("x")[1],"LANDSCAPE"===this.orientation?t<i&&(n=t,t=i,i=n):i<t&&(n=t,t=i,i=n),$("#_pageWidth").val(t),$("#_pageHeight").val(i)}else{if(t=$("#_pageWidth").val(),i=$("#_pageHeight").val(),"in"===this.unit&&(t>43||i>43))return void this.setHelp("warning","Size too large, please use a smaller size");if("mm"===this.unit&&(t>1001||i>1001))return void this.setHelp("warning","Size too large, please use a smaller size")}this.setPageSize(t+this.unit,i+this.unit)},E2DEditor.prototype.setPageSize=function(e,t){this.width=e,this.height=t,this.renderer.setSVGPageSize(e,t),this.updateShapeInfo(null)},E2DEditor.prototype.getPageSize=function(){return{width:this.width,height:this.height}},E2DEditor.prototype.checkScroll=function(e,t,i){var n=E2DGlobals.e2dLayout,o=n.state.center.innerWidth,s=n.state.center.innerHeight,r=n.state.center.offsetTop,a=n.state.center.offsetLeft;E2DEvents.autoScrollIntervalDirection=null,E2DEvents.autoScrollIntervalObject=null,e<=a+90?E2DEvents.autoScrollIntervalDirection="LEFT":a+o-90<=e&&(E2DEvents.autoScrollIntervalDirection="RIGHT"),t<=r+90?E2DEvents.autoScrollIntervalDirection="UP":r+s-90<=t&&(E2DEvents.autoScrollIntervalDirection="DOWN"),!E2DEvents.autoScrollIntervalID&&E2DEvents.autoScrollIntervalDirection&&(E2DEvents.autoScrollIntervalID=setInterval(i,500))},E2DEditor.prototype.setScrollObj=function(e){e&&this.setScroll(e.x,e.y)},E2DEditor.prototype.setScroll=function(e,t){var i=this.container.parent();null!==e&&void 0!==e&&i.scrollLeft(e),null!==t&&void 0!==t&&i.scrollTop(t)},E2DEditor.prototype.getScroll=function(){var e=this.container.parent();return{x:e.scrollLeft(),y:e.scrollTop()}},E2DEditor.prototype.setToggles=function(e){e&&(this.show3dWalls=e.show3dWalls,this.show3dShadows=e.show3dShadows,this.showGrid=e.showGrid,this.enableGrid(this.showGrid))},E2DEditor.prototype.getToggles=function(){var e={};return e.showGrid=this.showGrid,e.show3dWalls=this.show3dWalls,e.show3dShadows=this.show3dShadows,e},E2DEditor.prototype.setSplitters=function(e){if(e){e.westClosed?E2DGlobals.e2dLayout.close("west"):e.westSize&&(E2DGlobals.e2dLayout.open("west"),E2DGlobals.e2dLayout.sizePane("west",e.westSize)),e.eastClosed?E2DGlobals.e2dLayout.close("east"):e.eastSize&&(E2DGlobals.e2dLayout.open("east"),E2DGlobals.e2dLayout.sizePane("east",e.eastSize));var t=E2DGlobals.e2dLayout.panes.west.layout();e.westSouthClosed?t.close("south"):e.westSouthSize&&(t.open("south"),t.sizePane("south",e.westSouthSize))}},E2DEditor.prototype.getSplitters=function(){var e=E2DGlobals.e2dLayout.panes.west.layout();return{westClosed:E2DGlobals.e2dLayout.state.west.isClosed,westSize:E2DGlobals.e2dLayout.state.west.size,eastClosed:E2DGlobals.e2dLayout.state.east.isClosed,eastSize:E2DGlobals.e2dLayout.state.east.size,westSouthClosed:e.state.south.isClosed,westSouthSize:e.state.south.size}},E2DEditor.prototype.fitZoom=function(){this.setMode("select");var e=this.renderer.getGlobalBoundingBox();this.applyFitZoom(e)},E2DEditor.prototype.pageZoom=function(){this.setMode("select");var e=this.renderer.getSVGPageSize(),t={x:0,y:0,x2:e.width,y2:e.height,width:e.width,height:e.height};this.applyFitZoom(t)},E2DEditor.prototype.applyFitZoom=function(e){if(e){var t=this.container.parent(),i=.9*t.width(),n=.9*t.height(),o=E2DUtils.round(i/e.width,5),s=E2DUtils.round(n/e.height,5),r=(e.width,e.height*o<=n?o:s);r=E2DUtils.round(r,1),E2DUtils.isAlmostZero(r)&&(r=.1),1!==r&&(this.setZoom(r),e.x=e.x-16>=0?e.x-16:e.x,e.y=e.y-16>=0?e.y-16:e.y,this.setScroll(e.x*r,e.y*r))}},E2DEditor.prototype.setZoom=function(e){if(e&&!(E2DUtils.isAlmostZero(e)||e<=0||e===this.zoom))return this.zoom=e,this.renderer.setSVGRootZoom(this.zoom),this.renderer.updateTracker(this.selected),$("#btnZoomText").text(Math.round(100*this.zoom)+"%"),this.clearConnectionPoints(),this.clearPolylineQuotes(),this.setMode(this.mode),0!==E2DEvents.mouseDown.x&&0!==E2DEvents.mouseDown.y?this.centerPoint(E2DEvents.mouseDown.x*this.zoom,E2DEvents.mouseDown.y*this.zoom):this.centerOrigin(),!0},E2DEditor.prototype.getZoom=function(){return this.zoom},E2DEditor.prototype.centerOrigin=function(){if(this.origin&&this.origin.position){var e=this.convertUserDataToGraphData(this.origin.x),t=this.convertUserDataToGraphData(this.origin.y),i=(this.convertUserDataToGraphData(this.origin.w),this.convertUserDataToGraphData(this.origin.h)),n=this.container.parent(),o=n.width()/2,s=n.height()/2;switch(this.origin.position){case"tl":e+=o,t+=s;break;case"tr":e-=o,t+=s;break;case"bl":e+=o,t-=s-i/2;break;case"br":e-=o,t-=s-i/2}this.centerPoint(e*this.zoom,t*this.zoom)}},E2DEditor.prototype.centerPoint=function(e,t){var i=this.container.parent(),n=i.width(),o=i.height();this.setScroll(e-n/2,t-o/2)},E2DEditor.prototype.updateGrid=function(){var e=$("#_pageGrid").prop("checked")?this.unit:null;this.renderer.setSVGPageGrid(e),this.renderer3d&&this.renderer3d.displayGrid(this.showGrid)},E2DEditor.prototype.getContainedShapeList=function(e,t){const i=this.renderer.getAllShapes(this.container[0]),n=this.renderer.getAllConnectors(this.container[0]),o=[],s=[],r=[];for(let n=0,r=i.length;n<r;n++){if(i[n].id===this.ORIGIN_ID||i[n].id===this.CUSTOM_ORIGIN_ID||i[n].id===this.renderer.MULTIPLE_SELECTOR_DUMMY_ID||i[n].id===this.renderer.MULTIPLE_SELECTOR_TRACKER_ID||i[n].id===this.renderer.BACKGROUND_ID)continue;const r=this.renderer.bounds(i[n]);if(t){if(!this.renderer.testCollision(r,e,!0))continue}else if(!this.renderer.testInclusion(r,e))continue;const a=this.insertedShapes.getShapeById(i[n].id);a&&(a.hasBehaviour("(BACKGROUND)")||a.hasBehaviour("(NOSELECT")||a.hasBehaviour("NOGROUP"))||(o[o.length]=i[n],s[i[n].id]=!0)}for(let e=0,t=o.length;e<t;e++){const t=this.insertedShapes.getAttachedLines(o[e].id,["link-line"]);if(null!==t&&t.length>0)for(let e=0,i=t.length;e<i;e++){const i=this.insertedShapes.getConnectionShape(t[e],"from"),n=this.insertedShapes.getConnectionShape(t[e],"to");!r[t[e]]&&s[i.shapeID]&&s[n.shapeID]&&(o[o.length]=document.getElementById(t[e]),r[t[e]]=!0)}}for(let i=0,a=n.length;i<a;i++){const a=this.renderer.bounds(n[i]);if(a.width=a.x2-a.x,a.height=a.y2-a.y,t){if(!this.renderer.testCollision(a,e,!0))continue}else if(!this.renderer.testInclusion(a,e))continue;const l=this.insertedShapes.getShapeById(n[i].id);if(!l||!(l.hasBehaviour("(BACKGROUND)")||l.hasBehaviour("(NOSELECT")||l.hasBehaviour("NOGROUP"))){if(l.isLinkLine()){const e=this.insertedShapes.getConnectionShape(n[i].id,"from"),t=this.insertedShapes.getConnectionShape(n[i].id,"to");if(!s[e.shapeID]&&!s[t.shapeID])continue}r[n[i].id]||(o[o.length]=n[i],r[n[i].id]=!0)}}return o},E2DEditor.prototype.resetMultipleSelector=function(){var e=this.renderer.getMultipleSelector(!1,!0);return this.renderer.sizeMultipleSelector(this.multipleSelectShapes.bbox),this.renderer.showMultipleSelector(!0),$(e).off("vmousedown",E2DEvents.onHit).off("vclick",E2DEvents.onSingleDoubleClick),this.addNewShapeListeners(e),e},E2DEditor.prototype.initMultipleSelectorDummy=function(){this.renderer.sizeMultipleSelectorDummyShape(this.multipleSelectShapes.bbox),this.renderer.showMultipleSelectorDummyShape(!0);var e=this.convertTrueBoundsToUserBounds(this.multipleSelectShapes.bbox);this.enable3d&&this.renderer3d&&this.renderer3d.addMultipleSelector(e)},E2DEditor.prototype.resetMultipleSelectorDummy=function(){this.renderer.showMultipleSelectorDummyShape(!1),this.enable3d&&this.renderer3d&&this.renderer3d.removeMultipleSelector();for(var e=this.multipleSelectShapes.bbox,t=this.renderer.bounds(this.renderer.getMultipleSelectorDummyShape()),i=t.x-e.x,n=t.y-e.y,o=t.z-e.z,s=[],r=[],a=this.multipleSelectShapes.getShapes(),l=0,h=a.length;l<h;l++)if(!s[a[l].id]){var d=this.insertedShapes.getShapeById(a[l].id);if(!d.isLinkLine())if(d.isSmartLineHub())this.moveSmartLineHub();else{var c=this.multipleSelectShapes.getSelectedBounds(a[l].id);if(this.renderer.isConnector(a[l])){var u=this.renderer.getConnectorType(a[l]);"link-line"!==u&&"quote-line"!==u&&(this.clearPolylineConnections(a[l]),this.renderer.moveCompleteLine(a[l],c,i,n))}else{var p=i,g=n,y=o,f=null;if(t.rotation>0){var v=c;r[a[l].id]&&(v=this.renderer.bounds(a[l]));var m=1*v.rotation+Math.round(t.rotation),S=this.renderer.getProportionalBoundsRotation(v,t,t.rotation);p=S.x-v.x,g=S.y-v.y,f=m-v.rotation,this.renderer.rotate(a[l],m),this.renderer.move(a[l],S.x,S.y,null)}else{var E=null;if(r[a[l].id]&&(E=this.renderer.getPosition(a[l])),this.renderer.move(a[l],c.x+i,c.y+n,c.z+o),r[a[l].id]){var D=this.renderer.getPosition(a[l]);p=D.x-E.x,g=D.y-E.y}}this.clearShapeText(a[l]),this.resetShapeText(a[l]),this.moveShapeDependencies(a[l],p,g,y,f);var b=this.insertedShapes.getAttachedShapesDeep(a[l].id,["link-line"]);if(b&&b.length)for(var x=0,I=b.length;x<I;x++)s[b[x]]=!0;var C=this.insertedShapes.getAttachedShapesDeep(a[l].id,["quote-line"],{driving:!0});if(C&&C.length)for(var T=0,P=C.length;T<P;T++)r[C[T]]=!0}}}this.selectShapes(a),this.renderer.updateTracker(this.selected),this.updateShapeInfo(this.selected)},E2DEditor.prototype.beginTextToolEdit=function(e){this.renderer.setLineWidth(e,"0px"),this.renderer.setFillOpacity(e,"0.0"),this.startTextEdit(e)},E2DEditor.prototype.enableGrid=function(e){$("#_pageGrid").prop("checked",e),this.showGrid=e,this.updateGrid()},E2DEditor.prototype.enableSnapToGrid=function(e){$("#_pageSnapToGrid").prop("checked",e);var t=e?this.GRID_SIZE:"1",i=e?this.GRID_ROTATE:"1";this.setGridSize(t),this.setRotationalGridSize(i)},E2DEditor.prototype.enableSnapToObject=function(e,t,i){i=i||this.GRID_SIZE,$("#_pageSnapToObject").prop("checked",e),this.snapToObject=e,this.snapToShapeCenter=t,this.setSnapToThreshold(i)},E2DEditor.prototype.enableSnapToPolyline=function(e,t,i){i=i||this.GRID_SIZE,$("#_pageSnapToPolyline").prop("checked",e),this.snapToPolyline=e,this.snapToShapeCenter=t,this.setSnapToThreshold(i)},E2DEditor.prototype.setSnapToThreshold=function(e){var t=E2DUtils.splitUnits(e);switch(e=0,t[1]){case"in":e=t[0]*this.DPI;break;case"mm":e=t[0]*(this.DPI/25.4);break;default:e=t[0]}this.snapToThreshold=1*e},E2DEditor.prototype.getNewCoords=function(e,t,i){var n=this.container.offset(),o=e-n.left,s=t-n.top,r={x:0,y:0,z:0};return i?(r.x=this.applyGridSize(o),r.y=this.applyGridSize(s)):(r.x=Math.round(o),r.y=Math.round(s)),r.x/=this.zoom,r.y/=this.zoom,r},E2DEditor.prototype.getNewCoordsForSnapToObject=function(e,t,i,n){var o={x:t.x+i,y:t.y+n,rotation:null,dx:0,dy:0,snapped:!1,a:null,b:null};this.dragCache||(this.dragCache={});var s=null,r=this.dragCache.shapesToSnapToObject;if(!r){if(this.dragCache.shapesToSnapToObject=[],!this.snapToObject)return o;if(e===this.renderer.MULTIPLE_SELECTOR_TRACKER_ID)return o;if(e===this.ORIGIN_ID||e===this.CUSTOM_ORIGIN_ID)return o;if((s=this.insertedShapes.getShapeById(e))&&(s.hasBehaviour("(NOTE)")||s.hasBehaviour("(NOSNAPS)")||s.hasBehaviour("(BACKGROUND)")))return o;var a=this.insertedShapes.getAttachedQuoteAndLinkLines(e,!0);r=[];for(var l=this.renderer.getAllShapes(this.container[0]),h=0,d=l.length;h<d;h++)if(l[h].id!==this.renderer.MULTIPLE_SELECTOR_TRACKER_ID&&l[h].id!==this.renderer.BACKGROUND_ID&&l[h].id!==this.ORIGIN_ID&&l[h].id!==this.CUSTOM_ORIGIN_ID&&l[h].id!==e){var c=this.insertedShapes.getShapeById(l[h].id);if(c&&c.source!==this.CONNECTION_POINT_CLASS&&!c.hasBehaviour("(NOTE)")&&!c.hasBehaviour("(NOSNAPS)")&&!c.hasBehaviour("(BACKGROUND)")&&s.hasSameSnapClass(c)&&!this.insertedShapes.isShapeConnectedWith(l[h].id,a)){var u=this.renderer.bounds(l[h]),p=null,g=null;this.snapToShapeCenter?g=this.renderer.getCenterPointFromRect(u,0,0):p=this.renderer.getRotatedVerticesFromRect(u,0,0),r[r.length]={id:l[h].id,centerPoint:g,points:p}}}this.dragCache.shapesToSnapToObject=r}if(r&&r.length>0){var y=!1;(s=this.insertedShapes.getShapeById(e))&&(y=s.hasBehaviour("(SNAPPED)"),s.clearPolylineBehaviour(!1,!0));var f,v,m=99999,S={id:"",snappoints:"",snappointsEX:""},E=E2DUtils.round(this.snapToThreshold,10);if(y&&(E*=2),this.snapToShapeCenter)for(var D=this.renderer.getCenterPointFromRect(t,i,n),b=0,x=r.length;b<x;b++){f=r[b].centerPoint.x-D.x,v=r[b].centerPoint.y-D.y;var I=Math.abs(f),C=Math.abs(v);I<E&&I<m&&(m=I,o.x=t.x+i+f,o.y=t.y+n,o.dx=f,o.snapped=!0,o.a={x:r[b].centerPoint.x,y:0},o.b=r[b].centerPoint),C<E&&C<m&&(m=C,o.x=t.x+i,o.y=t.y+n+v,o.dy=v,o.snapped=!0,o.a={x:0,y:r[b].centerPoint.y},o.b=r[b].centerPoint),o.snapped&&(S.id=r[b].id,S.snappoints="CENTER",S.snappointsEX="CENTER")}else for(var T=0,P=this.renderer.getRotatedVerticesFromRect(t,i,n),L=0,O=r.length;L<O;L++)for(var w=0,G=r[L].points.length;w<G;w++){for(var M=!1,R=w,A=w+1<4?w+1:0,k=r[L].points[R],N=r[L].points[A],U=0,B=P.length;U<B;U++){if(k.y===N.y)P[U].px=P[U].x,P[U].py=k.y;else if(k.x===N.x)P[U].px=k.x,P[U].py=P[U].y;else{var _=E2DUtils.pointLineIntersection(P[U].x,P[U].y,k.x,k.y,N.x,N.y);P[U].px=_.x,P[U].py=_.y}if(P[U].D=E2DUtils.getSegmentLength(P[U].px,P[U].py,P[U].x,P[U].y),P[U].D<E&&P[U].D<m){T=U,M=!0,m=P[U].D;var z=E2DUtils.getSegmentRotation(P[U].x,P[U].y,P[U].px,P[U].py);f=P[U].D*Math.cos(E2DUtils.deg2rad(z)),v=P[U].D*Math.sin(E2DUtils.deg2rad(z))}}if(M){var $=0,V=0===T?3:T-1,F=3===T?0:T+1,H=E2DUtils.getVectorFromSegment(P[V].x,P[V].y,P[T].x,P[T].y),j=E2DUtils.getVectorFromSegment(P[T].x,P[T].y,P[F].x,P[F].y),X=E2DUtils.getVectorFromSegment(k.x,k.y,N.x,N.y),Y=E2DUtils.getVectorLength(H),Z=E2DUtils.getVectorLength(j),W=E2DUtils.getVectorLength(X),Q=E2DUtils.dotProduct(H,X),q=E2DUtils.dotProduct(j,X);if(E2DUtils.isNearToThresholdByPercent(Q,Y*W,.1)){switch(T){case 0:S.snappointsEX="BL_TL";break;case 1:S.snappointsEX="TL_TR";break;case 2:S.snappointsEX="TR_BR";break;case 3:S.snappointsEX="BR_BL"}$=-E2DUtils.getDegreeRotation(Q/(Y*W))}else if(E2DUtils.isNearToThresholdByPercent(q,Z*W,.1)){switch(T){case 0:S.snappointsEX="TL_TR";break;case 1:S.snappointsEX="TR_BR";break;case 2:S.snappointsEX="BR_BL";break;case 3:S.snappointsEX="BL_TL"}$=E2DUtils.getDegreeRotation(q/(Z*W))}else{switch(T){case 0:S.snappointsEX="TL";break;case 1:S.snappointsEX="TR";break;case 2:S.snappointsEX="BR";break;case 3:S.snappointsEX="BL"}o.p0=P[T]}$<-90&&($+=180),$>90&&($-=180),Q>=0&&q>=0&&($*=-1),o.x=t.x+i+f,o.y=t.y+n+v,E2DUtils.isAlmostZero($)?o.rotation=null:o.rotation=t.rotation+$,o.dx=f,o.dy=v,o.snapped=!0,o.a=k,o.b=N,S.id=r[L].id,S.snappoints=R+"-"+A}}m<E&&s&&(s.addBehaviour('(SHAPE={"id":"'+S.id+'","snappoints":'+S.snappoints+"})"),s.addBehaviour("(SNAPPOINTS="+S.snappointsEX+")"),s.addBehaviour("(SNAPPED)"),s.lastSnap||(s.lastSnap={id:S.id,snap:S.snappointsEX,obj:o}))}return o},E2DEditor.prototype.getNewCoordsForSnapToPolyline=function(e,t,i,n){var o={x:t.x+i,y:t.y+n,rotation:null,dx:0,dy:0,snapped:!1};this.dragCache||(this.dragCache={});var s=null,r=this.dragCache.shapesToSnapToPolyline;if(!r){if(this.dragCache.shapesToSnapToPolyline=[],!this.snapToPolyline)return o;if(e===this.renderer.MULTIPLE_SELECTOR_TRACKER_ID)return o;if(e===this.ORIGIN_ID||e===this.CUSTOM_ORIGIN_ID)return o;if((s=this.insertedShapes.getShapeById(e))&&(s.hasBehaviour("(NOTE)")||s.hasBehaviour("(BACKGROUND)")))return o;r=[];for(var a=this.renderer.getAllPolylines(this.container[0]),l=0,h=a.length;l<h;l++){var d=this.renderer.getPolylinePoints(a[l]);r[r.length]={id:a[l].id,points:d,pointsNum:d.length}}this.dragCache.shapesToSnapToPolyline=r}if(s=null,r&&r.length>0){var c=!1;(s=this.insertedShapes.getShapeById(e))&&(c=s.hasBehaviour("(SNAPPED)"),s.clearPolylineBehaviour(!0));var u,p,g,y,f,v,m,S=99999,E={id:"",xa:0,ya:0,xb:0,yb:0,snapPoints:""},D=E2DUtils.round(this.snapToThreshold,10);if(c&&(D*=2),this.snapToShapeCenter)for(var b=this.renderer.getCenterPointFromRect(t,i,n),x=0,I=r.length;x<I;x++){u=r[x];for(var C=0;C<u.pointsNum-1;C++)y=u.points[C],f=u.points[C+1],y.y===f.y?(b.px=b.x,b.py=y.y):y.x===f.x?(b.px=y.x,b.py=b.y):(v=E2DUtils.pointLineIntersection(b.x,b.y,y.x,y.y,f.x,f.y),b.px=v.x,b.py=v.y),b.px<Math.min(y.x,f.x)&&(y.x<f.x?(b.px=y.x,b.py=y.y):(b.px=f.x,b.py=f.y)),b.px>Math.max(y.x,f.x)&&(y.x>f.x?(b.px=y.x,b.py=y.y):(b.px=f.x,b.py=f.y)),b.D=E2DUtils.getSegmentLength(b.px,b.py,b.x,b.y),b.D<D&&b.D<S&&(S=b.D,m=E2DUtils.getSegmentRotation(b.x,b.y,b.px,b.py),p=b.D*Math.cos(E2DUtils.deg2rad(m)),g=b.D*Math.sin(E2DUtils.deg2rad(m)),o.x=t.x+i+p,o.y=t.y+n+g,o.dx=p,o.dy=g,o.snapped=!0,o.a=y,o.b=f,E.id=u.id,E.xa=E2DUtils.round(this.convertGraphXToUserX(y.x),this.numberOfDecimal),E.ya=E2DUtils.round(this.convertGraphYToUserY(y.y),this.numberOfDecimal),E.xb=E2DUtils.round(this.convertGraphXToUserX(f.x),this.numberOfDecimal),E.yb=E2DUtils.round(this.convertGraphYToUserY(f.y),this.numberOfDecimal),E.snapPoints="CENTER")}else for(var T=0,P=this.renderer.getRotatedVerticesFromRect(t,i,n),L=0,O=r.length;L<O;L++){u=r[L];for(var w=0;w<u.pointsNum-1;w++){var G=!1;y=u.points[w],f=u.points[w+1];for(var M=0,R=P.length;M<R;M++)y.y===f.y?(P[M].px=P[M].x,P[M].py=y.y):y.x===f.x?(P[M].px=y.x,P[M].py=P[M].y):(v=E2DUtils.pointLineIntersection(P[M].x,P[M].y,y.x,y.y,f.x,f.y),P[M].px=v.x,P[M].py=v.y),P[M].px<Math.min(y.x,f.x)&&(y.x<f.x?(P[M].px=y.x,P[M].py=y.y):(P[M].px=f.x,P[M].py=f.y)),P[M].px>Math.max(y.x,f.x)&&(y.x>f.x?(P[M].px=y.x,P[M].py=y.y):(P[M].px=f.x,P[M].py=f.y)),P[M].D=E2DUtils.getSegmentLength(P[M].px,P[M].py,P[M].x,P[M].y),P[M].D<D&&P[M].D<S&&(T=M,G=!0,S=P[M].D,m=E2DUtils.getSegmentRotation(P[M].x,P[M].y,P[M].px,P[M].py),p=P[M].D*Math.cos(E2DUtils.deg2rad(m)),g=P[M].D*Math.sin(E2DUtils.deg2rad(m)));if(G){var A=0,k=0===T?3:T-1,N=3===T?0:T+1,U=E2DUtils.getVectorFromSegment(P[k].x,P[k].y,P[T].x,P[T].y),B=E2DUtils.getVectorFromSegment(P[T].x,P[T].y,P[N].x,P[N].y),_=E2DUtils.getVectorFromSegment(y.x,y.y,f.x,f.y),z=E2DUtils.getVectorLength(U),$=E2DUtils.getVectorLength(B),V=E2DUtils.getVectorLength(_),F=E2DUtils.dotProduct(U,_),H=E2DUtils.dotProduct(B,_);if(E2DUtils.isNearToThresholdByPercent(F,z*V,.1)){switch(T){case 0:E.snapPoints="BL_TL";break;case 1:E.snapPoints="TL_TR";break;case 2:E.snapPoints="TR_BR";break;case 3:E.snapPoints="BR_BL"}A=-E2DUtils.getDegreeRotation(F/(z*V))}else if(E2DUtils.isNearToThresholdByPercent(H,$*V,.1)){switch(T){case 0:E.snapPoints="TL_TR";break;case 1:E.snapPoints="TR_BR";break;case 2:E.snapPoints="BR_BL";break;case 3:E.snapPoints="BL_TL"}A=E2DUtils.getDegreeRotation(H/($*V))}A<-90&&(A+=180),A>90&&(A-=180),F>=0&&H>=0&&(A*=-1),o.x=t.x+i+p,o.y=t.y+n+g,E2DUtils.isAlmostZero(A)?o.rotation=null:o.rotation=t.rotation+A,o.dx=p,o.dy=g,o.snapped=!0,o.a=y,o.b=f,E.id=u.id,E.xa=E2DUtils.round(this.convertGraphXToUserX(y.x),this.numberOfDecimal),E.ya=E2DUtils.round(this.convertGraphYToUserY(y.y),this.numberOfDecimal),E.xb=E2DUtils.round(this.convertGraphXToUserX(f.x),this.numberOfDecimal),E.yb=E2DUtils.round(this.convertGraphYToUserY(f.y),this.numberOfDecimal)}}}S<D&&s&&(s.addBehaviour('(POLYLINE={"id":"'+E.id+'","xa":'+E.xa+',"ya":'+E.ya+',"xb":'+E.xb+',"yb":'+E.yb+"})"),s.addBehaviour("(SNAPPOINTS="+E.snapPoints+")"),s.addBehaviour("(SNAPPED)"),s.lastPoly={id:E.id,snap:E.snapPoints,obj:o})}return o},E2DEditor.prototype.getNewCoordsForSnapToCenter=function(e,t,i,n){var o={x:t.x+i,y:t.y+n,rotation:null,snapped:!1};this.dragCache||(this.dragCache={});var s=this.dragCache.shapesToSnapToCenter;if(!s){this.dragCache.shapesToSnapToCenter=[],s=[];for(var r=this.renderer.getAllShapes(this.container[0]),a=0,l=r.length;a<l;a++)if(r[a].id!==this.renderer.MULTIPLE_SELECTOR_TRACKER_ID&&r[a].id!==this.renderer.BACKGROUND_ID&&r[a].id!==this.ORIGIN_ID&&r[a].id!==this.CUSTOM_ORIGIN_ID&&r[a].id!==e){var h=this.insertedShapes.getShapeById(r[a].id);if(h&&h.source!==this.CONNECTION_POINT_CLASS&&!h.hasBehaviour("(NOTE)")){var d=this.libraryProperties[h.getFullSource()],c=this.renderer.bounds(r[a]),u=[];if(this.connectionPointToolsEnabled&&1===d.shapeMode){var p=c.width/(d.width*this.scale),g=c.height/(d.height*this.scale),y=c.depth/(d.depth*this.scale);if(d.group2d.shapes&&d.group2d.shapes.length>0)for(var f=0,v=d.group2d.shapes.length;f<v;f++){var m=d.group2d.shapes[f],S=h.sourceLibrary+"|"+m.source,E=this.libraryProperties[S];if(E&&E.connectionPoints&&E.connectionPoints.length>0){var D={x:1*c.x+m.x*p*this.scale,y:1*c.y+m.y*g*this.scale,z:1*c.z+m.z*y*this.scale,width:m.width*p*this.scale,height:m.height*g*this.scale,depth:m.depth*y*this.scale,rotation:1*c.rotation+1*m.rotation},b=this.renderer.getProportionalBoundsRotation(D,c,c.rotation);D.x=b.x,D.y=b.y;for(var x=0,I=E.connectionPoints.length;x<I;x++){var C=E.connectionPoints[x],T=this.renderer.getConnectionPointObj(m.id,C,D);u[u.length]=T}}}}else(u=this.renderer.getRotatedVerticesFromRect(c,0,0))[u.length]=E2DUtils.midpointOfLineEx(u[0],u[1]),u[u.length]=E2DUtils.midpointOfLineEx(u[1],u[2]),u[u.length]=E2DUtils.midpointOfLineEx(u[2],u[3]),u[u.length]=E2DUtils.midpointOfLineEx(u[3],u[0]),u[u.length]=this.renderer.getCenterPointFromRect(c,0,0);s[s.length]={id:r[a].id,points:u}}}this.dragCache.shapesToSnapToCenter=s}if(s&&s.length>0){var P=!1,L=this.insertedShapes.getShapeById(e);L&&(P=L.hasBehaviour("(SNAPPED)"),L.removeBehaviour("(SNAPPED)"));var O=99999,w=E2DUtils.round(this.snapToThreshold,10);P&&(w*=2);for(var G=this.renderer.getCenterPointFromRect(t,i,n),M=0,R=s.length;M<R;M++)for(var A=0,k=s[M].points.length;A<k;A++)G.D=E2DUtils.getSegmentLength(s[M].points[A].x,s[M].points[A].y,G.x,G.y),G.D<w&&G.D<O&&(O=G.D,o.x=s[M].points[A].x-t.width/2,o.y=s[M].points[A].y-t.height/2,o.snapped=!0);O<w&&L&&L.addBehaviour("(SNAPPED)")}return o},E2DEditor.prototype.getNewCoordsForSnapToZ=function(e,t,i,n){if("number"==typeof n.z&&n.z>0){return n.z-(t.z-e.z)}return 0},E2DEditor.prototype.getNewCoordsForPolylinePoint=function(e,t,i,n,o){this.clearSnap();var s={x:i,y:n};if(o||1===this.GRID_ROTATE)return s;var r=0,a=0,l=null;0===t?(l=this.renderer.getPolylinePoint(e,1),r=E2DUtils.getSegmentLength(i,n,l.x,l.y),a=(E2DUtils.getSegmentRotation(i,n,l.x,l.y)+180)%360):(l=this.renderer.getPolylinePoint(e,t-1),r=E2DUtils.getSegmentLength(l.x,l.y,i,n),a=E2DUtils.getSegmentRotation(l.x,l.y,i,n)),a=Math.round(a/this.GRID_ROTATE)*this.GRID_ROTATE,a=E2DUtils.deg2rad(a);var h=r*Math.cos(a),d=r*Math.sin(a);return s.x=l.x+h,s.y=l.y+d,s=this.polylineSnapToPoint(e.id,t,s,l)},E2DEditor.prototype.polylineSnapToPoint=function(e,t,i,n){if(e===this.renderer.MULTIPLE_SELECTOR_TRACKER_ID)return i;if(e===this.ORIGIN_ID||e===this.CUSTOM_ORIGIN_ID)return i;var o=this.insertedShapes.getShapeById(e);if(o&&(o.hasBehaviour("(NOTE)")||o.hasBehaviour("(BACKGROUND)")))return i;o={id:"",points:null,pointsNum:0};for(var s=this.renderer.getAllPolylines(this.container[0]),r=0,a=s.length;r<a;r++)if(e===s[r].id){var l=this.renderer.getPolylinePoints(s[r]);l.splice(t,1),o={id:e,points:l,pointsNum:l.length};break}if(o.pointsNum>0){for(var h=o.points,d=h[0].x,c=h[0].y,u=0,p=0,g=0;g<h.length;g++)Math.abs(h[g].x-i.x)<d&&(d=Math.abs(h[g].x-i.x),u=g),Math.abs(h[g].y-i.y)<c&&(c=Math.abs(h[g].y-i.y),p=g);var y=E2DUtils.round(this.snapToThreshold,10)/4;n.x!==h[u].x&&n.y!==h[p].y||(y*=2);var f={x:0,y:0,showX:!1,showY:!1};if(Math.abs(h[u].x-i.x)<y){var v=h[u].x;0===u&&(v+=.001),i.x=v,f.showX=!0,f.x=i.x}if(Math.abs(h[p].y-i.y)<y){var m=h[p].y;0===p&&(m+=.001),i.y=m,f.showY=!0,f.y=i.y}!0!==f.showX&&!0!==f.showY||this.renderer.showSnapLineCoords(f)}return i},E2DEditor.prototype.getNewRotationForSnapToLink=function(e,t,i,n,o,s){var r=null,a=this.getConnectionPointFromPropertiesById(t,i),l=this.getConnectionPointFromPropertiesById(o,s);if((a.direction||"number"==typeof a.direction)&&a.direction>=0){var h=this.renderer.bounds(n),d=1*l.direction,c=1*a.direction-d-180;r=h.rotation,r-=c,r%=360}return r},E2DEditor.prototype.performIncludeConnectionPoints=function(){if(this.includeConnectionPoints)for(var e=this.renderer.getAllShapes(this.container[0]),t=0,i=e.length;t<i;t++){var n=e[t];if(n.id!==this.renderer.MULTIPLE_SELECTOR_TRACKER_ID&&n.id!==this.ORIGIN_ID&&n.id!==this.CUSTOM_ORIGIN_ID&&n.id!==this.renderer.BACKGROUND_ID){var o=this.insertedShapes.getShapeById(n.id);if(o&&o.source!==this.CONNECTION_POINT_CLASS){var s=this.renderer.getConnectionPointObjs(n,!1);if(s&&0!==s.length){for(var r=0,a=s.length;r<a;r++){var l=s[r];l.x=E2DUtils.round(this.convertGraphXToUserX(l.x),this.numberOfDecimal),l.y=E2DUtils.round(this.convertGraphYToUserY(l.y),this.numberOfDecimal),l.z=E2DUtils.round(this.convertGraphZToUserZ(l.z),this.numberOfDecimal),l.noRX=E2DUtils.round(this.convertGraphXToUserX(l.noRX),this.numberOfDecimal),l.noRY=E2DUtils.round(this.convertGraphYToUserY(l.noRY),this.numberOfDecimal),l.noRZ=E2DUtils.round(this.convertGraphZToUserZ(l.noRZ),this.numberOfDecimal)}o.connectionPoints=JSON.stringify(s)}}}}},E2DEditor.prototype.performCheckCollisionsFULL=function(){if(this.checkCollisions){this.insertedShapes.resetBehaviour("(COLLIDING)");for(var e=this.renderer.getAllShapes(this.container[0]),t=[],i=0,n=e.length;i<n-1;i++)t[t.length]=this.renderer.bounds(e[i]);for(var o=0,s=e.length;o<s-1;o++)if(e[o].id!==this.renderer.MULTIPLE_SELECTOR_TRACKER_ID&&e[o].id!==this.ORIGIN_ID&&e[o].id!==this.CUSTOM_ORIGIN_ID&&e[o].id!==this.renderer.BACKGROUND_ID){var r=this.insertedShapes.getShapeById(e[o].id);if(r&&r.source!==this.CONNECTION_POINT_CLASS&&!r.hasBehaviour("(NOTE)")&&!r.hasBehaviour("(NOCOLLISIONS)")&&(this.checkBackgroundCollisions||!r.hasBehaviour("(BACKGROUND)")))for(var a=this.insertedShapes.getAttachedQuoteAndLinkLines(e[o].id,!0,{ignoreConnectionsWithNOMOVEShapes:!0}),l=o+1;l<s;l++)if(e[l].id!==e[o].id&&e[l].id!==this.renderer.MULTIPLE_SELECTOR_TRACKER_ID&&e[l].id!==this.ORIGIN_ID&&e[l].id!==this.CUSTOM_ORIGIN_ID&&e[l].id!==this.renderer.BACKGROUND_ID&&!this.insertedShapes.isShapeConnectedWith(e[l].id,a)){var h=this.insertedShapes.getShapeById(e[l].id);!h||h.source===this.CONNECTION_POINT_CLASS||h.hasBehaviour("(NOTE)")||h.hasBehaviour("(NOCOLLISIONS)")||!this.checkBackgroundCollisions&&h.hasBehaviour("(BACKGROUND)")||r.hasSameCollisionClass(h)&&this.renderer.testCollision(t[o],t[l],!0)&&(r.hasBehaviour("(COLLIDING)")||r.addBehaviour("(COLLIDING)"),h.hasBehaviour("(COLLIDING)")||h.addBehaviour("(COLLIDING)"))}}}},E2DEditor.prototype.performCheckInclusionsFULL=function(){if(this.checkInclusions){this.insertedShapes.resetBehaviour("(EXTERNAL)");for(var e=this.renderer.getAllShapes(this.container[0]),t=[],i=0,n=e.length;i<n;i++)if(e[i].id!==this.renderer.MULTIPLE_SELECTOR_TRACKER_ID&&e[i].id!==this.ORIGIN_ID&&e[i].id!==this.CUSTOM_ORIGIN_ID&&e[i].id!==this.renderer.BACKGROUND_ID){var o=this.insertedShapes.getShapeById(e[i].id);!o||o.source===this.CONNECTION_POINT_CLASS||o.hasBehaviour("(NOTE)")||o.hasBehaviour("(NOINCLUSIONS)")||o.hasBehaviour("(CONTAINER)")&&(t[t.length]=e[i])}if(t)for(var s=0,r=e.length;s<r;s++)if(e[s].id!==this.renderer.MULTIPLE_SELECTOR_TRACKER_ID&&e[s].id!==this.ORIGIN_ID&&e[s].id!==this.CUSTOM_ORIGIN_ID&&e[s].id!==this.renderer.BACKGROUND_ID){var a=this.insertedShapes.getShapeById(e[s].id);if(a&&a.source!==this.CONNECTION_POINT_CLASS&&!a.hasBehaviour("(NOTE)")&&!a.hasBehaviour("(CONTAINER)")&&!a.hasBehaviour("(NOINCLUSIONS)")){for(var l=!1,h=this.renderer.bounds(e[s]),d=0,c=t.length;d<c;d++)if(e[s].id!==t[d].id){var u=this.renderer.bounds(t[d]),p=this.insertedShapes.getShapeById(t[d].id);if(p&&a.hasSameContainerClass(p)&&this.renderer.testInclusion(h,u)){l=!0;break}}l||a.addBehaviour("(EXTERNAL)")}}}},E2DEditor.prototype.performCheckCollisions=function(e){if(e){this.dragCache||(this.dragCache={});var t=this.dragCache.shapesToCollide;if(!t){if(this.dragCache.shapesToCollide=[],!this.checkCollisions)return;if(this.renderer.isConnector(e))return;if(e.id===this.renderer.MULTIPLE_SELECTOR_TRACKER_ID||e.id===this.ORIGIN_ID||e.id===this.CUSTOM_ORIGIN_ID||e.id===this.renderer.BACKGROUND_ID)return;var i=this.insertedShapes.getShapeById(e.id);if(!i||i.source===this.CONNECTION_POINT_CLASS||i.hasBehaviour("(NOTE)")||i.hasBehaviour("(NOCOLLISIONS)"))return;if(!this.checkBackgroundCollisions&&i.hasBehaviour("(BACKGROUND)"))return;var n=this.insertedShapes.getAttachedQuoteAndLinkLines(e.id,!0,{ignoreConnectionsWithNOMOVEShapes:!0});t=[];for(var o=this.renderer.getAllShapes(this.container[0]),s=0,r=o.length;s<r;s++)if(o[s].id!==e.id&&o[s].id!==this.renderer.MULTIPLE_SELECTOR_TRACKER_ID&&o[s].id!==this.ORIGIN_ID&&o[s].id!==this.CUSTOM_ORIGIN_ID&&o[s].id!==this.renderer.BACKGROUND_ID&&!this.insertedShapes.isShapeConnectedWith(o[s].id,n)){var a=this.insertedShapes.getShapeById(o[s].id);!a||a.source===this.CONNECTION_POINT_CLASS||a.hasBehaviour("(NOTE)")||a.hasBehaviour("(NOCOLLISIONS)")||!this.checkBackgroundCollisions&&a.hasBehaviour("(BACKGROUND)")||i.hasSameCollisionClass(a)&&(t[t.length]={shape:o[s],rect:this.renderer.bounds(o[s])})}this.dragCache.shapesToCollide=t}if(t&&t.length>0){this.dragCache.testCollisionCount=0;for(var l=[e],h=this.renderer.bounds(e),d=0,c=t.length;d<c;d++)this.renderer.testCollision(h,t[d].rect,!0)&&(l[l.length]=t[d].shape);this.clearCollidingGhosts(),l.length>1&&this.createCollidingGhosts(l)}}},E2DEditor.prototype.performCheckInclusions=function(e){if(e){this.dragCache||(this.dragCache={});var t=this.dragCache.shapesToContain;if(!t){if(this.dragCache.shapesToContain=[],!this.checkInclusions)return;if(this.renderer.isConnector(e))return;if(e.id===this.renderer.MULTIPLE_SELECTOR_TRACKER_ID||e.id===this.ORIGIN_ID||e.id===this.CUSTOM_ORIGIN_ID||e.id===this.renderer.BACKGROUND_ID)return;var i=this.insertedShapes.getShapeById(e.id);if(!i||i.source===this.CONNECTION_POINT_CLASS||i.hasBehaviour("(NOTE)")||i.hasBehaviour("(CONTAINER)")||i.hasBehaviour("(NOINCLUSIONS)"))return;t=[];for(var n=this.renderer.getAllShapes(this.container[0]),o=0,s=n.length;o<s;o++)if(n[o].id!==e.id&&n[o].id!==this.renderer.MULTIPLE_SELECTOR_TRACKER_ID&&n[o].id!==this.ORIGIN_ID&&n[o].id!==this.CUSTOM_ORIGIN_ID&&n[o].id!==this.renderer.BACKGROUND_ID){var r=this.insertedShapes.getShapeById(n[o].id);if(r&&r.source!==this.CONNECTION_POINT_CLASS&&!r.hasBehaviour("(NOTE)")&&!r.hasBehaviour("(NOINCLUSIONS)")&&r.hasBehaviour("(CONTAINER)")&&i.hasSameContainerClass(r)){t[t.length]={shape:n[o],rect:this.renderer.bounds(n[o])};break}}this.dragCache.shapesToContain=t}if(t&&t.length){this.dragCache.testInclusionCount=0,this.clearExternalGhosts();for(var a=this.renderer.bounds(e),l=0,h=t.length;l<h;l++)if(!this.renderer.testInclusion(a,t[l].rect)){this.createExternalGhosts([t[l].shape]);break}}}},E2DEditor.prototype.performCheckPolylineQuotes=function(e){if(this.checkQuotes&&e&&e.id!==this.renderer.MULTIPLE_SELECTOR_TRACKER_ID&&e.id!==this.renderer.BACKGROUND_ID&&e.id!==this.ORIGIN_ID&&e.id!==this.CUSTOM_ORIGIN_ID){var t=this.insertedShapes.getShapeById(e.id);if(t&&!t.hasBehaviour("(NOTE)")&&t.source!==this.CONNECTION_POINT_CLASS&&(this.clearPolylineQuotes(),t.lastPoly&&"CENTER"!==t.lastPoly.snap)){var i=t.lastPoly.obj,n=null,o=null,s=this.renderer.getRotatedVerticesFromShape(e);switch(t.lastPoly.snap){case"TL_TR":n=s[2],o=s[3];break;case"TR_BR":n=s[3],o=s[0];break;case"BR_BL":n=s[0],o=s[1];break;case"BL_TL":n=s[1],o=s[2]}if(n&&o){var r,a,l=E2DUtils.pointLineIntersection(i.a.x,i.a.y,n.x,n.y,o.x,o.y),h=E2DUtils.pointLineIntersection(i.b.x,i.b.y,n.x,n.y,o.x,o.y),d=E2DUtils.pointToPointDistanceEx(n,l),c=E2DUtils.pointToPointDistanceEx(o,l),u=E2DUtils.pointToPointDistanceEx(n,h),p=E2DUtils.pointToPointDistanceEx(o,h),g=null,y=null,f=null,v=null;d<c?(g=n,f=d):(g=o,f=c),u<p?(y=n,v=u):(y=o,v=p),f>0&&(f=E2DUtils.round(this.convertGraphDataToUserData(f),this.numberOfDecimal).toString(),this.quoteUOMEnabled&&(f+=" "+this.unit),(r=E2DUtils.midpointOfLine(g.x,g.y,l.x,l.y)).x-=50,(a=l.y-i.a.y)<0?r.y-=20:a>0&&(r.y+=10),r.x*=this.zoom,r.y*=this.zoom,this.renderer.showPolyQuote("A",[g,l,i.a],f,r.x,r.y)),v&&(v=E2DUtils.round(this.convertGraphDataToUserData(v),this.numberOfDecimal).toString(),this.quoteUOMEnabled&&(v+=" "+this.unit),(r=E2DUtils.midpointOfLine(y.x,y.y,h.x,h.y)).x-=50,(a=h.y-i.b.y)<0?r.y-=20:a>0&&(r.y+=10),r.x*=this.zoom,r.y*=this.zoom,this.renderer.showPolyQuote("B",[y,h,i.b],v,r.x,r.y))}}}},E2DEditor.prototype.performCheckOverlappings=function(e){if(e&&!this.renderer.isConnector(e)&&!this.renderer.isMultipleSelect(e)&&e.id!==this.renderer.MULTIPLE_SELECTOR_TRACKER_ID&&e.id!==this.ORIGIN_ID&&e.id!==this.CUSTOM_ORIGIN_ID&&e.id!==this.renderer.BACKGROUND_ID){var t=this.insertedShapes.getShapeById(e.id);if(t&&!t.hasBehaviour("(NOTE)")&&(this.checkBackgroundCollisions||!t.hasBehaviour("(BACKGROUND)"))){for(var i=[e],n=this.renderer.bounds(e),o=this.renderer.getAllShapes(this.container[0]),s=0,r=o.length;s<r;s++)if(o[s].id!==e.id&&o[s].id!==this.renderer.MULTIPLE_SELECTOR_TRACKER_ID&&o[s].id!==this.ORIGIN_ID&&o[s].id!==this.CUSTOM_ORIGIN_ID&&o[s].id!==this.renderer.BACKGROUND_ID){var a=this.insertedShapes.getShapeById(o[s].id);if(a&&!a.hasBehaviour("(NOTE)")&&(this.checkBackgroundCollisions||!a.hasBehaviour("(BACKGROUND)"))){var l=this.renderer.bounds(o[s]);this.renderer.testCollision(n,l)&&(i[i.length]=o[s])}}this.clearOverlappingGhosts(),i.length>1&&this.createOverlappingGhosts(i)}}},E2DEditor.prototype.getOverlappingConnectionPoints=function(e){if(!e)return[];var t=e.split("--");if(2!==t.length)return[];var i=t[0],n=t[1],o=document.getElementById(i),s=this.renderer.getConnectionPointObjByPointId(o,n);if(!s)return[];for(var r="quote-line"===this.mode,a=this.renderer.getOverlappingConnectionPointObjs(i,n,r,15,this.quickPickIgnoreThreshold),l=this.renderer.bounds(o),h=this.renderer.getAllShapes(this.container[0]),d=0,c=h.length;d<c;d++)if(h[d].id!==i&&h[d].id!==this.renderer.MULTIPLE_SELECTOR_TRACKER_ID&&h[d].id!==this.ORIGIN_ID&&h[d].id!==this.CUSTOM_ORIGIN_ID&&h[d].id!==this.renderer.BACKGROUND_ID){var u=this.insertedShapes.getShapeById(h[d].id);if(u&&!u.hasBehaviour("(NOTE)")&&(this.checkBackgroundCollisions||!u.hasBehaviour("(BACKGROUND)"))){var p=this.renderer.bounds(h[d]);if(this.renderer.testCollision(l,p,!0))for(var g=this.renderer.getConnectionPointObjs(h[d],r),y=0,f=g.length;y<f;y++)E2DUtils.isPointTooClose(s,g[y],15)&&(a[a.length]=g[y])}}if(E2DEvents.prev_connector){var v=E2DEvents.prev_connector.split("--"),m=this.getLinkClass(v[0],v[1]);if(m){var S=this.getLinkClassTarget(m);S&&(m=S);for(var E=[],D=0,b=a.length;D<b;D++){var x=a[D],I=this.getLinkClass(x.shapeId,x.cpId);E2DUtils.isInSameClass(m,I)&&(E[E.length]=x)}a=E}}return a},E2DEditor.prototype.areOverlappingConnectionPoints=function(e,t,i,n){var o=this.renderer.getConnectionPointObjByPointId(e,t),s=this.renderer.getConnectionPointObjByPointId(i,n),r={x:o.x,y:o.y},a={x:s.x,y:s.y};return E2DUtils.isPointTooClose(r,a,1.5)},E2DEditor.prototype.getOverlappingConnectionPointsBetweenShapes=function(e,t){for(var i,n=new Array,o=0,s=this.renderer.getConnectionPointObjs(e,!1),r=this.renderer.getConnectionPointObjs(t,!1),a=0;a<s.length;a++)for(var l=0;l<r.length;l++)E2DUtils.isInSameClass(s.linkClass,r.linkClass)&&this.areOverlappingConnectionPoints(e,s[a].cpId,t,r[l].cpId)&&(i={from:s[a].cpId,to:r[l].cpId},n[o]=i,o++);return n},E2DEditor.prototype.createCollidingGhosts=function(e){this.collidingGhosts=[];for(var t=0,i=e.length;t<i;t++)e[t].classList.add("collidingghost"),this.collidingGhosts[t]=e[t],E2DEventBus.dispatch("shapeAddCollision",e[t].id)},E2DEditor.prototype.createExternalGhosts=function(e){this.externalGhosts=[];for(var t=0,i=e.length;t<i;t++)e[t].classList.add("externalghost"),this.externalGhosts[t]=e[t],E2DEventBus.dispatch("shapeAddExternal",e[t].id)},E2DEditor.prototype.createOverlappingGhosts=function(e){this.overlappingGhosts=e},E2DEditor.prototype.clearCollidingGhosts=function(){if(this.collidingGhosts){for(var e=0,t=this.collidingGhosts.length;e<t;e++)this.collidingGhosts[e].classList.remove("collidingghost");E2DEventBus.dispatch("shapeClearCollisions",null),this.collidingGhosts=[]}},E2DEditor.prototype.clearExternalGhosts=function(){if(this.externalGhosts){for(var e=0,t=this.externalGhosts.length;e<t;e++)this.externalGhosts[e].classList.remove("externalghost");E2DEventBus.dispatch("shapeClearExternals",null),this.externalGhosts=[]}},E2DEditor.prototype.clearOverlappingGhosts=function(){this.overlappingGhosts=[]},E2DEditor.prototype.clearPolylineQuotes=function(){this.renderer.hidePolyQuotes()},E2DEditor.prototype.clearSnap=function(){if(this.selected){var e=this.insertedShapes.getShapeById(this.selected.id);e&&(e.lastSnap=null)}this.renderer.hideSnapLine()},E2DEditor.prototype.resizeNewShape=function(e,t){if(this.selected){var i=e?1:this.getGridSize(),n=this.applyGridSize(t.x,i),o=this.applyGridSize(t.y,i),s=this.renderer.bounds(this.selected);this.renderer.resize(this.selected,s.x,s.y,n,o),this.renderer.updateTracker(this.selected),this.updateShapeInfo(this.selected,s)}},E2DEditor.prototype.resizeShape=function(e,t,i){if(!this.selected)return;var n=e?1:this.getGridSize(),o=this.applyGridSize(t.x,n),s=this.applyGridSize(t.y,n),r=this.applyGridSize(this.prevRect.width,n),a=this.applyGridSize(this.prevRect.height,n),l=this.applyGridSize(this.prevRect.depth,n),h=this.prevRect.z,d=this.insertedShapes.getShapeById(this.selected.id);if(d&&(d.id===this.ORIGIN_ID||d.id===this.CUSTOM_ORIGIN_ID))return void this.setHelp("warning","Origin cannot be modified.");if(this.selectedBehaviour.move.background&&!this.activeBackground)return void this.setHelp("warning","Background elements cannot be modified.");var c="rotate"===this.resizeMode,u=this.resizeMode.indexOf("stretch")>=0,p=u&&(this.resizeMode.indexOf("left")>=0||this.resizeMode.indexOf("right")>=0),g=u&&(this.resizeMode.indexOf("top")>=0||this.resizeMode.indexOf("bottom")>=0),y="depth-stretch"===this.resizeMode,f="z-stretch"===this.resizeMode;if(c){if(this.selectedBehaviour.move.noRotate)return void this.setHelp("warning","Selected shape cannot be rotated.");if(this.selectedBehaviour.move.noRotateOnView)return void this.setHelp("warning","Selected shape can be rotated only from the property pane.")}if(u&&!f){if(this.selectedBehaviour.stretch.noStretch)return void this.setHelp("warning","Selected shape cannot be stretched.");if(this.selectedBehaviour.stretch.noStretchOnView)return void this.setHelp("warning","Selected shape can be stretched only from the property pane.")}if(p&&this.selectedBehaviour.stretch.noWStretch)return void this.setHelp("warning","Selected shape cannot be stretched horizontally.");if(g&&this.selectedBehaviour.stretch.noHStretch)return void this.setHelp("warning","Selected shape cannot be stretched vertically.");if(y&&this.selectedBehaviour.stretch.noDStretch)return void this.setHelp("warning","Selected shape cannot be stretched on the z axis.");if(f&&this.selectedBehaviour.move.noZMove)return void this.setHelp("warning","Selected shape cannot be moved on the z axis.");let v=null;c||y||(v=this.getShapeDependenciesBeforeResize(this.selected));const m=this.renderer.bounds(this.selected),S=E2DUtils.round(m.width/m.height,1);if("right-stretch"!==this.resizeMode&&"top-right-stretch"!==this.resizeMode&&"bottom-right-stretch"!==this.resizeMode||(this.renderer.resizeWidth(this.selected,o,s,i.x,i.y,r,!0),E2DEvents.autoScrollIntervalObject=this.selected),"left-stretch"!==this.resizeMode&&"bottom-left-stretch"!==this.resizeMode&&"top-left-stretch"!==this.resizeMode||(this.renderer.resizeWidth(this.selected,o,s,i.x,i.y,r,!1),E2DEvents.autoScrollIntervalObject=this.selected),"bottom-stretch"!==this.resizeMode&&"bottom-left-stretch"!==this.resizeMode&&"bottom-right-stretch"!==this.resizeMode||(this.renderer.resizeHeight(this.selected,o,s,i.x,i.y,a,!0),E2DEvents.autoScrollIntervalObject=this.selected),"top-stretch"!==this.resizeMode&&"top-left-stretch"!==this.resizeMode&&"top-right-stretch"!==this.resizeMode||(this.renderer.resizeHeight(this.selected,o,s,i.x,i.y,a,!1),E2DEvents.autoScrollIntervalObject=this.selected),y&&this.renderer.resizeDepth(this.selected,o,s,i.x,i.y,l),f&&this.renderer.resizeZ(this.selected,o,s,i.x,i.y,h),c){var E=(this.processRotate(this.selected,t.x,t.y,i.x,i.y,e)-m.rotation)%360;this.moveShapeDependencies(this.selected,null,null,null,E)}if(d){var D=d.decodeBehaviour("(SNAPPOINTS=");if(D.found){var b=!1;switch(D.value){case"TL_TR":b="rotate"===this.resizeMode||"top-stretch"===this.resizeMode||"top-left-stretch"===this.resizeMode||"top-right-stretch"===this.resizeMode;break;case"TR_BR":b="rotate"===this.resizeMode||"top-right-stretch"===this.resizeMode||"right-stretch"===this.resizeMode||"bottom-right-stretch"===this.resizeMode;break;case"BR_BL":b="rotate"===this.resizeMode||"bottom-stretch"===this.resizeMode||"bottom-left-stretch"===this.resizeMode||"bottom-right-stretch"===this.resizeMode;break;case"BL_TL":b="rotate"===this.resizeMode||"top-left-stretch"===this.resizeMode||"left-stretch"===this.resizeMode||"bottom-left-stretch"===this.resizeMode}b&&d.clearPolylineBehaviour()}if(d.hasBehaviour("(KEEPASPECTRATIO)")){switch(this.resizeMode){case"right-stretch":case"left-stretch":this.renderer.adjustAspectRatioAfterHorizontalStretch(m,this.selected,S,this.resizeMode);break;case"top-stretch":case"bottom-stretch":this.renderer.adjustAspectRatioAfterVerticalStretch(m,this.selected,S,this.resizeMode);break;case"top-right-stretch":case"bottom-right-stretch":case"top-left-stretch":case"bottom-left-stretch":this.renderer.adjustAspectRatioAfterDiagonalStretch(m,this.selected,S,this.resizeMode)}this.renderer.updateRotation(this.selected)}}v&&v.cpIDs&&v.cpIDs.length>0&&(v=this.updateShapeDependenciesAfterResize(this.selected,v)),this.performCheckInclusions(this.selected),this.performCheckCollisions(this.selected),this.performCheckPolylineQuotes(this.selected),c||y||this.moveShapeDependenciesAfterResize(this.selected,v),this.renderer.updateTracker(this.selected),this.updateShapeInfo(this.selected)},E2DEditor.prototype.resizeMultipleShapes=function(e,t,i){if(this.selected&&this.renderer.isMultipleSelect(this.selected)){if("z-stretch"===this.resizeMode){var n=e?1:this.getGridSize(),o=this.applyGridSize(t.x,n),s=this.applyGridSize(t.y,n);this.renderer.resizeZ(this.selected,o,s,i.x,i.y,this.prevRect.z),this.renderer.resizeZ(this.renderer.getMultipleSelectorDummyShape(),o,s,i.x,i.y,this.prevRect.z)}if("rotate"===this.resizeMode&&(this.processRotate(this.selected,t.x,t.y,i.x,i.y,e),this.processRotate(this.renderer.getMultipleSelectorDummyShape(),t.x,t.y,i.x,i.y,e)),this.renderer.updateTracker(this.selected),this.updateShapeInfo(this.selected),this.enable3d&&this.renderer3d){var r=this.renderer.bounds(this.selected),a=this.convertGraphXToUserX(r.x),l=this.convertGraphYToUserY(r.y),h=this.convertGraphZToUserZ(r.z);this.renderer3d.updateMultipleSelector(a,l,h,r.rotation)}}},E2DEditor.prototype.resizeNewConnector=function(e,t){if(this.selected&&this.renderer.isConnector(this.selected)){this.renderer.hideLineTracker();var i=this.renderer.bounds(this.selected);if(this.renderer.isPolyline(this.selected)){var n=this.renderer.getPolylineNumberOfPoints(this.selected)-1;t=this.getNewCoordsForPolylinePoint(this.selected,n,t.x,t.y,e)}this.renderer.resize(this.selected,i.x,i.y,t.x,t.y),i=this.renderer.bounds(this.selected),this.updateShapeInfo(this.selected,i)}},E2DEditor.prototype.resizeConnector=function(e,t){if(this.selected&&this.renderer.isConnector(this.selected)){if(this.clearPolylineConnections(this.selected),this.renderer.isQuoteLine(this.selected)){var i=this.insertedShapes.getShapeById(this.selected.id);if(i&&i.dimDriving)return}switch(this.renderer.hideLineTracker(),this.resizeMode){case"line-from":this.renderer.disconnectLineFromShape(this.selected,"from"),this.renderer.moveLine(this.selected,e.x,e.y,!0),E2DEvents.autoScrollIntervalObject=this.selected;break;case"line-to":this.renderer.disconnectLineFromShape(this.selected,"to"),this.renderer.moveLine(this.selected,e.x,e.y,!1),E2DEvents.autoScrollIntervalObject=this.selected;break;case"polyline-from":case"polyline-0":e=this.getNewCoordsForPolylinePoint(this.selected,0,e.x,e.y,t),this.renderer.moveLine(this.selected,e.x,e.y,!0);break;case"polyline-to":var n=this.renderer.getPolylineNumberOfPoints(this.selected)-1;e=this.getNewCoordsForPolylinePoint(this.selected,n,e.x,e.y,t),this.renderer.moveLine(this.selected,e.x,e.y,!1);break;case"control1":this.renderer.setControl1(this.selected,e.x,e.y);break;case"control2":this.renderer.setControl2(this.selected,e.x,e.y);break;default:if(this.resizeMode.startsWith("polyline-")){var o=1*this.resizeMode.substring(9);e=this.getNewCoordsForPolylinePoint(this.selected,o,e.x,e.y,t),this.renderer.movePolylinePoint(this.selected,o,e.x,e.y)}}this.updateShapeInfo(this.selected)}},E2DEditor.prototype.performCheckings=function(){if(this.selected)return this.performCheckInclusions(this.selected),this.performCheckCollisions(this.selected),this.performCheckPolylineQuotes(this.selected),this.renderer3d&&this.renderer3d.renderSingle(),E2DEvents.dragStarted},E2DEditor.prototype.moveSmartLineHub=function(){this.selected&&this.renderer.isSmartLineHub(this.selected)&&(this.container.off("vmousemove",E2DEvents.onDrag),this.deleteItem(this.selected,!0),this.unselect(),this.renderer.updateTracker(this.selected),this.updateShapeInfo(this.selected))},E2DEditor.prototype.moveShape=function(e,t,i,n){if(this.selected){var o=this.selectedBehaviour.move.noXMove?0:t,s=this.selectedBehaviour.move.noYMove?0:i,r=this.insertedShapes.getShapeById(this.selected.id),a={x:this.selectedBounds.x+o,y:this.selectedBounds.y+s,rotation:null,snapped:!1};if(E2DUtils.every("SNAPSHAPE",1e3/E2DGlobals.dragFps)){if(this.selected.id===this.CUSTOM_ORIGIN_ID||r.source===this.CONNECTION_POINT_CLASS){var l=this.getNewCoordsForSnapToCenter(this.selected.id,this.selectedBounds,o,s);l.snapped&&(a=l)}else{if(this.snapToObject&&!e){var h=this.getNewCoordsForSnapToObject(this.selected.id,this.selectedBounds,o,s);h.snapped&&(a=h)}if(this.snapToPolyline&&!e){var d=this.getNewCoordsForSnapToPolyline(this.selected.id,this.selectedBounds,o,s);d.snapped&&(a=d)}}if(!a.snapped&&!e){var c=e?1:this.getGridSize();a.x=this.applyGridSize(a.x,c),a.y=this.applyGridSize(a.y,c)}}e||this.setHelp("info","To override snap to grid during drag, press the shift key"),0===o&&(a.x=this.selectedBounds.x),0===s&&(a.y=this.selectedBounds.y);var u=null,p=this.renderer.getPosition(this.selected),g=this.renderer.getRotation(this.selected);this.renderer.move(this.selected,a.x,a.y),a.snapped&&(E2DUtils.every("SNAPSHAPE",0),a.rotation&&(u=a.rotation-g,this.renderer.setRotation(this.selected,a.rotation),this.selectedBounds.x=a.x,this.selectedBounds.y=a.y,this.selectedBounds.rotation=a.rotation,n&&(E2DEvents.mouseDown={x:n.x,y:n.y})),a.a&&a.b&&!r.lastPoly&&this.renderer.showSnapLine(a)),this.moveShapeDependencies(this.selected,a.x-p.x,a.y-p.y,null,u),E2DGlobals.dragTimerMode||this.performCheckings(),this.renderer.updateTracker(this.selected),this.updateShapeInfo(this.selected)}},E2DEditor.prototype.moveShapeSimple=function(e,t,i,n,o){if(!e)return;this.clearShapeText(e);const s=this.renderer.getPosition(e);this.renderer.move(e,s.x+t,s.y+i,s.z+n),this.moveShapeDependencies(e,t,i,n,null,o),this.updateShapeInfo(e),this.resetShapeText(e)},E2DEditor.prototype.moveShapeDependencies=function(e,t,i,n,o,s,r){this.updateAttachedSmartLines(e),this.updateAttachedShapes(e,t,i,n,o,s),this.renderer.moveLineWithShape(e,null,s,r)},E2DEditor.prototype.getShapeDependenciesBeforeResize=function(e,t){if(!e)return null;!t&&this.dragCache||(this.dragCache={});let i=this.dragCache.shapesAfterResize;if(!i){i={cpIDs:[],cpShapeMap:[]};const t=this.insertedShapes.getAttachedLinkLines(e.id,!1,null);if(t&&t.length>0)for(let n of t){const t=this.insertedShapes.getShapeById(n),o=t.shapeFromId===e.id?t.shapeFromPointIndex:t.shapeToPointIndex,s=this.insertedShapes.getOtherConnectedShape(n,e.id);i.cpShapeMap[o]?i.cpShapeMap[o].shapes.push(s.id):(i.cpIDs.push(o),i.cpShapeMap[o]={before:null,after:null,shapes:[s.id]})}this.dragCache.shapesAfterResize=i}for(let t of i.cpIDs)i.cpShapeMap[t].before=this.renderer.getConnectionPointObjByPointId(e,t);return i},E2DEditor.prototype.updateShapeDependenciesAfterResize=function(e,t){if(!e)return null;for(let i of t.cpIDs)t.cpShapeMap[i].after=this.renderer.getConnectionPointObjByPointId(e,i);return t},E2DEditor.prototype.moveShapeDependenciesAfterResize=function(e,t){if(this.renderer.moveLineWithShape(e,null,null),t&&t.cpIDs&&t.cpIDs.length>0){const i=[e.id];for(let e of t.cpIDs){const n=t.cpShapeMap[e],o=n.after.x-n.before.x,s=n.after.y-n.before.y,r=n.after.z-n.before.z;for(let e of n.shapes)this.moveShapeSimple(document.getElementById(e),o,s,r,i)}}},E2DEditor.prototype.moveMultipleShapes=function(e,t){if(this.selected&&this.renderer.isMultipleSelect(this.selected)&&!(this.selectedBehaviour.move.noMove||this.selectedBehaviour.move.noXMove&&this.selectedBehaviour.move.noYMove)){var i=this.selectedBehaviour.move.noXMove?0:e,n=this.selectedBehaviour.move.noYMove?0:t,o=this.selectedBounds.x+i,s=this.selectedBounds.y+n,r=this.selectedBounds.z;this.renderer.move(this.selected,o,s,r),this.renderer.move(this.renderer.getMultipleSelectorDummyShape(),o,s,r),this.renderer.updateTracker(this.selected),this.updateShapeInfo(this.selected),this.enable3d&&this.renderer3d&&(o=this.convertGraphXToUserX(o),s=this.convertGraphYToUserY(s),r=this.convertGraphZToUserZ(r),this.renderer3d.updateMultipleSelector(o,s,r,0))}},E2DEditor.prototype.moveConnector=function(e,t,i){this.selected&&this.renderer.isConnector(this.selected)&&(this.renderer.isPolyline(this.selected)&&this.renderer.isPolylineSegmentSelected(this.selected)||(this.clearPolylineConnections(this.selected),this.renderer.isQuoteLine(this.selected)||(this.renderer.disconnectLineFromShape(this.selected,"to"),this.renderer.disconnectLineFromShape(this.selected,"from")),this.renderer.moveCompleteLine(this.selected,this.selectedBounds,e,t,i.x,i.y),this.renderer.updateTracker(this.selected),this.updateShapeInfo(this.selected)))},E2DEditor.prototype.updateAttachedSmartLines=function(e){for(var t=this.insertedShapes.getAttachedSmartLines(e.id),i=0,n=t.length;i<n;i++){var o=this.insertedShapes.getConnectionShape(t[i],"from"),s=this.insertedShapes.getShapeById(o.shapeID),r=this.insertedShapes.getConnectionShape(t[i],"to"),a=this.insertedShapes.getShapeById(r.shapeID);if(s.isSmartLineHub()||a.isSmartLineHub()){var l=document.getElementById(t[i]);this.deleteItem(l,!0)}}},E2DEditor.prototype.updateAttachedShapes=function(e,t,i,n,o,s){this.dragCache||(this.dragCache={}),void 0===this.dragCache.delta&&(this.dragCache.delta=[]),this.dragCache.delta[e.id]={x:t,y:i,rotation:o},void 0===this.dragCache.linkedShapesHash&&(this.dragCache.linkedShapesHash=[]);var r=this.dragCache.linkedShapesHash[e.id];if(!r){if(r=this.insertedShapes.getAttachedShapesDeep(e.id,["link-line"],{excludeIds:s}),E2DEvents.dragStarted)for(var a=0,l=r.length;a<l;a++){var h=document.getElementById(r[a]);this.clearShapeText(h)}this.dragCache.linkedShapesHash[e.id]=r}if(r&&r.length>0)for(var d=this.renderer.bounds(e),c=this.renderer.getCenterPointFromRect(d,0,0),u=0,p=r.length;u<p;u++)if(e.id!==r[u]){var g=document.getElementById(r[u]);if(g){var y=this.renderer.bounds(g);if(y){if(E2DUtils.isAlmostZero(t)&&E2DUtils.isAlmostZero(i)&&E2DUtils.isAlmostZero(n)||(y.x+=t,y.y+=i,y.z+=n,this.renderer.move(g,y.x,y.y,y.z)),"number"==typeof o&&!E2DUtils.isAlmostZero(o)){var f=(y.rotation+o)%360;f=f<0?(360+f)%360:f;var v=this.renderer.getCenterPointFromRect(y,0,0),m=this.renderer.getRotatedPointAroundPoint(v.x,v.y,c.x,c.y,o);this.renderer.setRotation(g,f);var S=m.x-v.x,E=m.y-v.y;this.renderer.move(g,y.x+S,y.y+E)}E2DUtils.isAlmostZero(t)&&E2DUtils.isAlmostZero(i)&&E2DUtils.isAlmostZero(n)&&E2DUtils.isAlmostZero(o)||(this.renderer.moveLineWithShape(g,null,null),E2DEvents.dragStarted||(this.clearShapeText(g),this.resetShapeText(g)),this.updateIShape(g,this.renderer.bounds(g),"",!1))}}}},E2DEditor.prototype.fineMove=function(e,t,i,n){if(this.selected){var o=t-e,s=n-i;this.renderer.isMultipleSelect(this.selected)?this.fineMoveMultipleShapes(o,s):this.renderer.isConnector(this.selected)?this.fineMoveConnector(o,s):this.fineMoveShape(o,s)}else this.setHelp("info","Select a shape for Fine move")},E2DEditor.prototype.fineMoveByDir=function(e){switch(this.clearShapeText(),e){case"LEFT":this.fineMove(1,0,0,0);break;case"UP":this.fineMove(0,0,1,0);break;case"RIGHT":this.fineMove(0,1,0,0);break;case"DOWN":this.fineMove(0,0,0,1)}this.saveUndoRedoPoint(0,"urMoveShapes")},E2DEditor.prototype.fineMoveShape=function(e,t){if(this.selected)if(this.selectedBehaviour.move.noMove)this.setHelp("warning","Selected shape cannot be moved.");else{var i=this.selectedBehaviour.move.noXMove?0:e,n=this.selectedBehaviour.move.noYMove?0:t,o=this.insertedShapes.getShapeById(this.selected.id);o&&o.clearPolylineBehaviour(),this.renderer.fineMove(this.selected,i,n),this.moveShapeDependencies(this.selected,i,n),this.performCheckPolylineQuotes(this.selected),this.renderer.updateTracker(this.selected),this.updateShapeInfo(this.selected)}},E2DEditor.prototype.fineMoveMultipleShapes=function(e,t){if(this.selected&&this.renderer.isMultipleSelect(this.selected)&&E2DEvents.dragStarted){var i=this.renderer.bounds(this.selected),n=i.x+(this.selectedBehaviour.move.noXMove?0:e),o=i.y+(this.selectedBehaviour.move.noYMove?0:t),s=i.z;this.renderer.move(this.selected,n,o,s),this.renderer.move(this.renderer.getMultipleSelectorDummyShape(),n,o,s),this.renderer.updateTracker(this.selected),this.updateShapeInfo(this.selected),this.enable3d&&this.renderer3d&&(n=this.convertGraphXToUserX(n),o=this.convertGraphYToUserY(o),s=this.convertGraphZToUserZ(s),this.renderer3d.updateMultipleSelector(n,o,s))}},E2DEditor.prototype.fineMoveConnector=function(e,t){if(this.selected&&this.renderer.isConnector(this.selected)){this.clearPolylineConnections(this.selected),this.renderer.isQuoteLine(this.selected)||(this.renderer.disconnectLineFromShape(this.selected,"to"),this.renderer.disconnectLineFromShape(this.selected,"from"));var i=this.renderer.bounds(this.selected);this.renderer.moveCompleteLine(this.selected,i,e,t),this.renderer.updateTracker(this.selected),this.updateShapeInfo(this.selected)}},E2DEditor.prototype.fineMoveLine=function(e,t,i){if(this.renderer.isConnector(e)){var n=null,o=!1;"line-from"===this.resizeMode?(n=this.renderer.getConnectorFrom(e),o=!0):"line-to"===this.resizeMode&&(n=this.renderer.getConnectorTo(e),o=!1),n&&(this.renderer.moveLine(e,n.x+t,n.y+i,o),this.renderer.updateTracker(this.selected),this.updateShapeInfo(this.selected))}},E2DEditor.prototype.fineResize=function(e,t,i,n,o){if(e){var s=this.getStretchBehaviour(e.id),r=this.renderer.bounds(e);i&&!s.noWStretch?n?this.renderer.resizeWidth(e,r.x,r.y,r.x,r.y,r.width+t,n):this.renderer.resizeWidth(e,r.x,r.y,r.x-t,r.y,r.width,n):s.noHStretch||(o?this.renderer.resizeHeight(e,r.x,r.y,r.x,r.y,r.height+t,o):this.renderer.resizeHeight(e,r.x,r.y,r.x,r.y-t,r.height,o)),this.performCheckInclusions(e),this.performCheckCollisions(e),this.performCheckPolylineQuotes(e),this.renderer.moveLineWithShape(e,null,null),this.renderer.updateTracker(e),this.updateShapeInfo(e)}},E2DEditor.prototype.fineRotateSelection=function(e){if(this.selected){if(!this.renderer.isMultipleSelect(this.selected)){var t=this.selected;if(t.id!==this.ORIGIN_ID&&t.id!==this.CUSTOM_ORIGIN_ID)if(this.selectedBehaviour.move.noRotate)this.setHelp("warning","Selected shape cannot be rotated.");else if(this.selectedBehaviour.move.noRotateOnView)this.setHelp("warning","Selected shape can be rotated only from the property pane.");else{var i=this.insertedShapes.getShapeById(t.id);i&&i.clearPolylineBehaviour();var n=this.renderer.getRotation(t),o=(this.renderer.fineRotateSelection(t,e)-n)%360;this.moveShapeDependencies(t,null,null,null,o),this.performCheckInclusions(t),this.performCheckCollisions(t),this.performCheckPolylineQuotes(t),this.renderer.updateTracker(this.selected),this.updateShapeInfo(this.selected),this.selectedBounds=this.renderer.bounds(this.selected)}else this.setHelp("warning","Origin cannot be rotated.")}}else this.setHelp("info","Please select a shape to rotate")},E2DEditor.prototype.processRotate=function(e,t,i,n,o,s){var r=s?1:this.GRID_ROTATE,a=this.getRotationAngle(e,t,i,n,o);return a=Math.round(a/r)*r,this.renderer.rotate(e,a),s||this.setHelp("info","To override rotational grid, press Shift key during rotate"),a},E2DEditor.prototype.processRotateMultiSelect=function(e){if(this.renderer.isMultipleSelect(this.selected))for(var t=null,i=null,n=this.renderer.bounds(this.selected),o=this.multipleSelectShapes.getShapes(),s=0,r=o.length;s<r;s++)if(i=o[s],t=this.insertedShapes.getShapeById(i.id)){var a=this.multipleSelectShapes.getSelectedBounds(i.id),l=this.renderer.getProportionalBoundsRotation(a,n,e),h=1*a.rotation+Math.round(e);t.rotation=h,this.renderer.rotate(i,h),this.renderer.setPosition(i,l.x,l.y,null),this.renderer.updateRotation(i)}},E2DEditor.prototype.getRotationAngle=function(e,t,i,n,o){var s=this.renderer.bounds(e),r=t-(1*s.x+s.width/2),a=i-(1*s.y+s.height/2),l=(0*r+-10*a)/(10*Math.sqrt(Math.pow(r,2)+Math.pow(a,2)));return l=(l=l>1?1:l)<-1?-1:l,l=Math.acos(l),l=E2DUtils.rad2deg(l),r<=0&&(l=360-l),l},E2DEditor.prototype.getLibraryProperties=function(e){const t=this.insertedShapes.getShapeById(e);return t?this.libraryProperties[t.getFullSource()]:null},E2DEditor.prototype.createNewGroup=function(e,t,i,n){i=i||$.Deferred();const o=Date.now(),s=[];let r=69;if(e.group=InsertedShapes.GetNextGroupOccurrence(e.source),t.group2d.shapes&&t.group2d.shapes.length>0)for(let i=0,n=t.group2d.shapes.length;i<n;i++){const n=t.group2d.shapes[i],a=1*e.x+this.convertGraphXToUserX(n.x*this.scale),l=1*e.y+this.convertGraphYToUserY(n.y*this.scale),h=this.convertGraphZToUserZ(n.z*this.scale),d=this.convertGraphDataToUserData(n.width*this.scale),c=this.convertGraphDataToUserData(n.height*this.scale),u=this.convertGraphDataToUserData(n.depth*this.scale),p=InsertedShape.CreateShape(e.sourceLibrary,n.source,"","","","",a,l,h,d,c,u,n.rotation,"","",{});p.id=n.id,document.getElementById(p.id)&&(p.id+="_"+o),p.group=e.group,p.layer=e.layer;const g=this.createNewShapeSeq(p,r);s[s.length]=g,r=g}const a=this;return $.when.apply($,s).done(function(){const s=[];for(let e=0,t=arguments.length;e<t;e++)s[s.length]=arguments[e];a.createNewGroupAsync(i,e,s,t,n,o)}),i.promise()},E2DEditor.prototype.createNewGroupAsync=function(e,t,i,n,o,s){const r=[];if(n.group2d.connectors&&n.group2d.connectors.length>0){t.x*=1,t.y*=1;for(let e=0,i=n.group2d.connectors.length;e<i;e++){const i=n.group2d.connectors[e],o=new InsertedShape;if(o.source=i.source,o.group=t.group,o.x=E2DUtils.round(t.x+this.convertGraphXToUserX(i.x1*this.scale),this.numberOfDecimal),o.y=E2DUtils.round(t.y+this.convertGraphYToUserY(i.y1*this.scale),this.numberOfDecimal),o.width=E2DUtils.round(t.x+this.convertGraphXToUserX(i.x2*this.scale),this.numberOfDecimal),o.height=E2DUtils.round(t.y+this.convertGraphYToUserY(i.y2*this.scale),this.numberOfDecimal),i.path){let e="";const n=i.path.split(" ");for(let i=0,o=n.length;i<o;i++){const o=n[i].split(",");e+=E2DUtils.round(t.x+this.convertGraphXToUserX(o[0]*this.scale),this.numberOfDecimal)+",",e+=E2DUtils.round(t.y+this.convertGraphYToUserY(o[1]*this.scale),this.numberOfDecimal)+" "}o.path=e.trim()}"number"==typeof i.ctrl1x&&-1!==t.ctrl1x&&(o.ctrl1x=E2DUtils.round(t.x+this.convertGraphXToUserX(i.ctrl1x*this.scale),this.numberOfDecimal)),"number"==typeof i.ctrl1y&&-1!==t.ctrl1y&&(o.ctrl1y=E2DUtils.round(t.y+this.convertGraphYToUserY(i.ctrl1y*this.scale),this.numberOfDecimal)),"number"==typeof i.ctrl2x&&-1!==t.ctrl2x&&(o.ctrl2x=E2DUtils.round(t.x+this.convertGraphXToUserX(i.ctrl2x*this.scale),this.numberOfDecimal)),"number"==typeof i.ctrl2y&&-1!==t.ctrl2y&&(o.ctrl2y=E2DUtils.round(t.y+this.convertGraphYToUserY(i.ctrl2y*this.scale),this.numberOfDecimal)),"poly-line"!==i.source&&(i.shapeFromId&&(o.shapeFromId=i.shapeFromId,document.getElementById(i.shapeFromId+"_"+s)&&(o.shapeFromId=i.shapeFromId+"_"+s),o.shapeFromPointIndex=i.shapeFromPointIndex),i.shapeToId&&(o.shapeToId=i.shapeToId,document.getElementById(i.shapeToId+"_"+s)&&(o.shapeToId=i.shapeToId+"_"+s),o.shapeToPointIndex=i.shapeToPointIndex));const a=this.createNewConnector(o);r[r.length]=a}}$.when.apply($,r).done(function(){if(e){const t=[];for(let e=0,i=arguments.length;e<i;e++)t[t.length]=arguments[e];e.resolve(i,t)}const n=E2DGlobals.e2d;if(o){if(n.events.inserted){let e=n.getEventArgumentByShapeId("INSERTED",t.id);if(e)return void E2DEvents.doSubmitEvent("OnEditor2DInserted",[e],1,"urNewGroup");for(let t=0,o=i.length;t<o;t++)if(e=n.getEventArgumentByShapeId("INSERTED",i[t].id))return void E2DEvents.doSubmitEvent("OnEditor2DInserted",[e],1,"urNewGroup")}n.saveUndoRedoPoint(0,"urNewGroup")}})},E2DEditor.prototype.createNewConnector=function(e){if(!e.source)return alert("RD Editor 2D (createNewConnector): source not defined for given connector.\nSkipping connector."),!1;var t=$.Deferred();this.unselect(),this.multipleSelectShapes.reset(),this.renderer.showMultipleSelectors(!1);var i=this.convertUserXToGraphX(e.x),n=this.convertUserYToGraphY(e.y),o=this;return this.renderer.createLine(this.shapeLibraryList[0],e.source,i,n).done(function(i){o.createNewConnectorAsync(i,e,t)}).fail(function(){t.resolve()}),t.promise()},E2DEditor.prototype.createNewConnectorAsync=function(e,t,i){this.select(e),t.id||(t.id="connector_"+E2DUtils.createUUID()),e.setAttribute("id",t.id),e.setAttribute("group",t.group);const n=t.isPolyline()&&(this.enable3dFloor||this.enable3dWalls);this.insertedShapes.addShape(t,!n),t.isPolyline()&&this.enable3dFloor&&(e=this.renderer.sendToBack(e)),this.addNewShapeListeners(e),this.updateConnectorSingle(e,t),this.unselect(),this.handleZIndexPositioning(),i.resolve(e)},E2DEditor.prototype.createNewShapeSeq=function(e,t){var i=$.Deferred();return $.when(t).done(function(){var t=E2DGlobals.e2d.createNewShape(e);t?t.done(function(e){i.resolve(e)}):i.resolve()}),i.promise()},E2DEditor.prototype.createNewShape=function(e,t){if(!e.source){const t="RD Editor 2D (createNewShape): source not defined for given shape (id:"+e.id+").\nSkipping shape.";return console.log(t),alert(t),!1}if(isNaN(1*e.x)||isNaN(1*e.y)||isNaN(1*e.z)){const t="RD Editor 2D (createNewShape): invalid position for given shape (id:"+e.id+"; source:"+e.source+").\nSkipping shape.";return console.log(t),alert(t),!1}if(isNaN(1*e.width)||isNaN(1*e.height)||isNaN(1*e.depth)){const t="RD Editor 2D (createNewShape): invalid dimension for given shape (id:"+e.id+"; source:"+e.source+").\nSkipping shape.";return console.log(t),alert(t),!1}var i=$.Deferred();this.unselect(),this.multipleSelectShapes.reset(),this.renderer.showMultipleSelectors(!1);var n=this;return this.renderer.loadShapeAndProps(e.sourceLibrary,e.source).done(function(o,s){n.loadShapeAndPropsAsync(o,s,e,i,t)}).fail(function(){i.resolve()}),i.promise()},E2DEditor.prototype.loadPropsForAssemblies=function(){var e=this.insertedShapes.getShapes();if(e&&e.length>0)for(var t=0,i=e.length;t<i;t++){var n=e[t],o=this.libraryProperties[n.getFullSource()];if(o&&1===o.shapeMode&&o.group2d.shapes&&o.group2d.shapes.length>0)for(var s=o.group2d.shapes,r=0,a=s.length;r<a;r++)this.loadPropsForAssembliesAsync(n.sourceLibrary,s[r].source)}},E2DEditor.prototype.loadPropsForAssembliesAsync=function(e,t){var i=this;this.renderer.loadProps(e,t,this).done(function(n){var o=e+"|"+t;i.libraryProperties[o]||(i.libraryProperties[o]=n)})},E2DEditor.prototype.loadShapeAndPropsAsync=function(e,t,i,n,o){i.id||(i.id="shape_"+E2DUtils.createUUID());var s=i.getFullSource();this.libraryProperties[s]||(this.libraryProperties[s]=t),2===t.shapeMode&&t.group2d?this.createNewGroup(i,this.libraryProperties[s],n,o):this.createNewSingleShape(e,this.libraryProperties[s],i,n,o)},E2DEditor.prototype.createNewSingleShape=function(e,t,i,n,o){i.id||(i.id="shape_"+E2DUtils.createUUID());var s=this.convertUserXToGraphX(i.x),r=this.convertUserYToGraphY(i.y),a=this.convertUserZToGraphZ(i.z),l=this.convertUserDataToGraphData(i.width),h=this.convertUserDataToGraphData(i.height),d=this.convertUserDataToGraphData(i.depth),c="",u="",p="",g="",y=1,f="",v=1,m="",S=1,E="",D=1;if(t&&(t.width||(t.width=96),l||(l=t.width*this.scale),t.height||(t.height=96),h||(h=t.height*this.scale),t.depth||(t.depth=96),d||(d=t.depth*this.scale),t.behaviour||(t.behaviour=""),i.behaviour||i.setBehaviour(t.behaviour),i.name||(i.name=this.checkTranslation(t.name)),i.family||(i.family=t.family),i.description||(i.description=this.checkTranslation(t.description)),t.text||(t.text=""),c=t.text,t.linkClass||(t.linkClass=""),u=t.linkClass,t.eventClass||(t.eventClass=""),p=t.eventClass,t.color||(t.color=""),g=t.color,t.colorOpacity||(t.colorOpacity=1),y=t.colorOpacity,t.lineColor||(t.lineColor=""),f=t.lineColor,t.lineOpacity||(t.lineOpacity=1),v=t.lineOpacity,t.color3D||(t.color3D=""),m=t.color3D,t.colorOpacity3D||(t.colorOpacity3D=1),S=t.colorOpacity3D,t.lineColor3D||(t.lineColor3D=""),E=t.lineColor3D,t.lineOpacity3D||(t.lineOpacity3D=1),D=t.lineOpacity3D,t.hasOwnProperty("custom")))for(var b in t.custom){var x=t.custom[b];if(!$.isEmptyObject(x)&&!i.custom.hasOwnProperty(b)){var I=this.getDefaultValueForCustomProperty(x);"undefined"!==I&&(i.custom[b]=I)}}let C=null;if(i.id===this.ORIGIN_ID||i.id===this.CUSTOM_ORIGIN_ID)s-=l/2,r-=h/2;else{const e=i.decodeBehaviour("(ORIGIN=");if(e.found){C=e.value;const t=this.applyShapeOriginToGraphData(s,r,l,h,C);s=t.x,r=t.y}}const T={x:s,y:r,width:l,height:h,rotation:i.rotation},P=this.renderer.getRotatedVerticesFromRect(T);if(P[0].x<0||P[0].x>this.renderer.MAX_WIDTH){s=0;const e=C?this.revertShapeOriginToGraphData(s,r,l,h,C).x:s;i.x=E2DUtils.round(this.convertGraphXToUserX(e),this.numberOfDecimal)}if(P[0].y<0||P[0].y>this.renderer.MAX_WIDTH){r=0;const e=C?this.revertShapeOriginToGraphData(s,r,l,h,C).y:r;i.y=E2DUtils.round(this.convertGraphYToUserY(e),this.numberOfDecimal)}if(i.width||(i.width=E2DUtils.round(this.convertGraphDataToUserData(l),this.numberOfDecimal)),i.height||(i.height=E2DUtils.round(this.convertGraphDataToUserData(h),this.numberOfDecimal)),i.depth||(i.depth=E2DUtils.round(this.convertGraphDataToUserData(d),this.numberOfDecimal)),i.text||(i.text=c),i.linkClass||(i.linkClass=u),i.eventClass||(i.eventClass=p),i.color||(i.color=g),i.colorOpacity||(i.colorOpacity=y),i.lineColor||(i.lineColor=f),i.lineOpacity||(i.lineOpacity=v),i.color3D||(i.color3D=m),i.colorOpacity3D||(i.colorOpacity3D=S),i.lineColor3D||(i.lineColor3D=E),i.lineOpacity3D||(i.lineOpacity3D=D),(e=this.renderer.importAndAppendChild(this.renderer.svgRoot,e)).setAttribute("id",i.id),this.renderer.setPosition(e,s,r,a),this.renderer.setDimensions(e,l,h,d),this.renderer.setRotation(e,i.rotation),i.text&&(this.renderer.setShapeText(e,i.text),i.hasBehaviour("(NOTE)")&&(this.renderer.setLineWidth(e,"0px"),this.renderer.setFillOpacity(e,"0.0"))),this.renderer.setLineColor(e,i.lineColor),this.renderer.setLineWidth(e,i.lineWidth),this.renderer.setLineOpacity(e,i.lineOpacity),1!==t.shapeMode&&(this.renderer.setFillColor(e,i.color),this.renderer.setFillOpacity(e,i.colorOpacity)),this.renderer.setLayer(e,this.libraryLayers[i.layer]),this.renderer.setPinned(e,i.pinned),i.custom&&(this.updateShapeAccordingToCustomProperties(e,i),this.renderer.hideSnapLine(),this.renderer.hideTracker(),this.renderer.hideLineTracker()),this.updateLibraryLayers(i.layer),this.insertedShapes.addShape(i),this.addNewShapeListeners(e),i.id!==this.ORIGIN_ID&&i.id!==this.CUSTOM_ORIGIN_ID&&(this.handleZIndexPositioning(),e=document.getElementById(e.id)),o?(this.select(e),this.selectedBounds=this.renderer.bounds(e),E2DEvents.mouseDown={x:this.selectedBounds.x,y:this.selectedBounds.y}):this.unselect(),n&&n.resolve(e),o){if(this.events.inserted){var L=this.getEventArgumentByShapeId("INSERTED",i.id);if(L)return void E2DEvents.doSubmitEvent("OnEditor2DInserted",[L],1,"urNewShapes")}this.saveUndoRedoPoint(0,"urNewShape")}},E2DEditor.prototype.handleZIndexPositioning=function(){let e=null;if(!E2DGlobals.e2d.origin.background){if(e=document.getElementById(this.ORIGIN_ID)){if(e.getAttribute("riSVGInProgress"))return void setTimeout(E2DGlobals.e2d.handleZIndexPositioning,50);(e=this.renderer.bringToFront(e))&&this.addNewShapeListeners(e)}(e=document.getElementById(this.CUSTOM_ORIGIN_ID))&&(e=this.renderer.bringToFront(e))&&this.addNewShapeListeners(e)}if(this.insertedShapes.alwaysInBack)for(let t in this.insertedShapes.alwaysInBack)this.insertedShapes.alwaysInBack.hasOwnProperty(t)&&(e=document.getElementById(t))&&(e=this.renderer.sendToBack(e))&&this.addNewShapeListeners(e);if(this.insertedShapes.alwaysInFront)for(let t in this.insertedShapes.alwaysInFront)this.insertedShapes.alwaysInFront.hasOwnProperty(t)&&(e=document.getElementById(t))&&(e=this.renderer.bringToFront(e))&&this.addNewShapeListeners(e)},E2DEditor.prototype.applyRoundingToUserRect=function(e){var t={};return t.x=E2DUtils.round(e.x,this.numberOfDecimal),t.y=E2DUtils.round(e.y,this.numberOfDecimal),(e.z||"number"==typeof e.z)&&(t.z=E2DUtils.round(1*e.z,this.numberOfDecimal)),t.width=E2DUtils.round(e.width,this.numberOfDecimal),t.height=E2DUtils.round(e.height,this.numberOfDecimal),(e.depth||"number"==typeof e.depth)&&(t.depth=E2DUtils.round(1*e.depth,this.numberOfDecimal)),(e.length||"number"==typeof e.length)&&(t.length=E2DUtils.round(1*e.length,this.numberOfDecimal)),(e.rotation||"number"==typeof e.rotation)&&(t.rotation=e.rotation),t},E2DEditor.prototype.convertTrueBoundsToUserBounds=function(e){var t={};return t.x=this.convertGraphXToUserX(e.x),t.y=this.convertGraphYToUserY(e.y),(e.z||"number"==typeof e.z)&&(t.z=this.convertGraphZToUserZ(e.z)),t.width=this.convertGraphDataToUserData(e.width),t.height=this.convertGraphDataToUserData(e.height),(e.depth||"number"==typeof e.depth)&&(t.depth=this.convertGraphDataToUserData(e.depth)),(e.length||"number"==typeof e.length)&&(t.length=this.convertGraphDataToUserData(e.length)),(e.lengthFrom||"number"==typeof e.lengthFrom)&&(t.lengthFrom=this.convertGraphDataToUserData(e.lengthFrom)),(e.lengthTo||"number"==typeof e.lengthTo)&&(t.lengthTo=this.convertGraphDataToUserData(e.lengthTo)),(e.rotation||"number"==typeof e.rotation)&&(t.rotation=e.rotation),(e.rotationFrom||"number"==typeof e.rotationFrom)&&(t.rotationFrom=e.rotationFrom),(e.rotationTo||"number"==typeof e.rotationTo)&&(t.rotationTo=e.rotationTo),t},E2DEditor.prototype.convertGraphXToUserX=function(e){return(this.convertGraphDataToUserData(e)-this.origin.x)*this.origin.signX},E2DEditor.prototype.convertGraphYToUserY=function(e){return(this.convertGraphDataToUserData(e)-this.origin.y)*this.origin.signY},E2DEditor.prototype.convertGraphZToUserZ=function(e){return(this.convertGraphDataToUserData(e)-this.origin.z)*this.origin.signZ},E2DEditor.prototype.convertGraphPointToUserPoint=function(e){return e.x=this.convertGraphXToUserX(e.x),e.y=this.convertGraphYToUserY(e.y),e.z=this.convertGraphZToUserZ(e.z),e},E2DEditor.prototype.convertGraphDataToUserData=function(e){return e*this.conversionFactor/this.scale},E2DEditor.prototype.convertPixelsToUserData=function(e){return e*this.conversionFactor},E2DEditor.prototype.convertUserBoundsToGraphBounds=function(e){var t={};return t.x=this.convertUserXToGraphX(e.x),t.y=this.convertUserYToGraphY(e.y),(e.z||"number"==typeof e.z)&&(t.z=this.convertUserZToGraphZ(e.z)),t.width=this.convertUserDataToGraphData(e.width),t.height=this.convertUserDataToGraphData(e.height),(e.depth||"number"==typeof e.depth)&&(t.depth=this.convertUserDataToGraphData(e.depth)),(e.length||"number"==typeof e.length)&&(t.length=this.convertUserDataToGraphData(e.length)),(e.rotation||"number"==typeof e.rotation)&&(t.rotation=1*e.rotation),(e.x2||"number"==typeof e.x2)&&(t.x2=e.x2),(e.y2||"number"==typeof e.y2)&&(t.y2=e.y2),(e.controlX||"number"==typeof e.controlX)&&(t.controlX=e.controlX),(e.controlY||"number"==typeof e.controlY)&&(t.controlY=e.controlY),(e.controlX2||"number"==typeof e.controlX2)&&(t.controlX2=e.controlX2),(e.controlY2||"number"==typeof e.controlY2)&&(t.controlY2=e.controlY2),t},E2DEditor.prototype.convertUserXToGraphX=function(e){return this.convertUserDataToGraphData(1*this.origin.x+e*this.origin.signX*1)},E2DEditor.prototype.convertUserYToGraphY=function(e){return this.convertUserDataToGraphData(1*this.origin.y+e*this.origin.signY*1)},E2DEditor.prototype.convertUserZToGraphZ=function(e){return this.convertUserDataToGraphData(1*this.origin.z+e*this.origin.signZ*1)},E2DEditor.prototype.convertUserDataToGraphData=function(e){return e*(1/this.conversionFactor)*this.scale},E2DEditor.prototype.convertUserDataToPixels=function(e){return e/this.conversionFactor},E2DEditor.prototype.convertPathToUserString=function(e){for(var t="",i=0,n=e.length;i<n;i++){var o=e[i];t+=E2DUtils.round(this.convertGraphXToUserX(o.x),this.numberOfDecimal)+","+E2DUtils.round(this.convertGraphYToUserY(o.y),this.numberOfDecimal)+" "}return t.trim()},E2DEditor.prototype.convertUserStringToPath=function(e){for(var t=[],i=e.split(" "),n=0,o=i.length;n<o;n++){var s=i[n].split(",");t[t.length]={x:this.convertUserXToGraphX(s[0]),y:this.convertUserYToGraphY(s[1])}}return t},E2DEditor.prototype.applyShapeOriginToGraphData=function(e,t,i,n,o){var s={x:0,y:0,z:0};switch(o){case"CENTER":s.x=1*e-i/2,s.y=1*t-n/2;break;case"TOPLEFT":s.x=1*e,s.y=1*t;break;case"TOPRIGHT":s.x=1*e-i,s.y=1*t;break;case"BOTTOMLEFT":s.x=1*e,s.y=1*t-n;break;case"BOTTOMRIGHT":s.x=1*e-i,s.y=1*t-n;break;default:var r=o.split(",");2===r.length&&(s.x=1*e-1*r[0],s.y=1*t-1*r[1])}return s},E2DEditor.prototype.applyShapeOriginToUserData=function(e,t,i,n,o){var s={x:0,y:0,z:0};switch(o){case"CENTER":s.x=1*e+i/2*this.origin.signX,s.y=1*t+n/2*this.origin.signY;break;case"TOPLEFT":s.x=1*e,s.y=1*t;break;case"TOPRIGHT":s.x=1*e+i*this.origin.signX,s.y=1*t;break;case"BOTTOMLEFT":s.x=1*e,s.y=1*t+n*this.origin.signY;break;case"BOTTOMRIGHT":s.x=1*e+i*this.origin.signX,s.y=1*t+n*this.origin.signY;break;default:var r=o.split(",");2===r.length&&(s.x=1*e+this.convertGraphDataToUserData(r[0])*this.origin.signX,s.y=1*t+this.convertGraphDataToUserData(r[1])*this.origin.signY)}return s},E2DEditor.prototype.revertShapeOriginToGraphData=function(e,t,i,n,o){var s={x:0,y:0,z:0};switch(o){case"CENTER":s.x=1*e+i/2,s.y=1*t+n/2;break;case"TOPLEFT":s.x=1*e,s.y=1*t;break;case"TOPRIGHT":s.x=1*e+i,s.y=1*t;break;case"BOTTOMLEFT":s.x=1*e,s.y=1*t+n;break;case"BOTTOMRIGHT":s.x=1*e+i,s.y=1*t+n;break;default:var r=o.split(",");2===r.length&&(s.x=1*e+1*r[0],s.y=1*t+1*r[1])}return s},E2DEditor.prototype.revertShapeOriginToUserData=function(e,t,i,n,o){var s={x:0,y:0,z:0};switch(o){case"CENTER":s.x=1*e,s.y=1*t;break;case"TOPLEFT":s.x=1*e-i/2*this.origin.signX,s.y=1*t-n/2*this.origin.signY;break;case"TOPRIGHT":s.x=1*e+i/2*this.origin.signX,s.y=1*t-n/2*this.origin.signY;break;case"BOTTOMLEFT":s.x=1*e-i/2*this.origin.signX,s.y=1*t+n/2*this.origin.signY;break;case"BOTTOMRIGHT":s.x=1*e+i/2*this.origin.signX,s.y=1*t+n/2*this.origin.signY;break;default:var r=o.split(",");2===r.length&&(s.x=1*e-this.convertGraphDataToUserData(r[0])*this.origin.signX,s.y=1*t-this.convertGraphDataToUserData(r[1])*this.origin.signY)}return s},E2DEditor.prototype.updateConversionFactor=function(){this.conversionFactor=1/this.DPI,"mm"===this.unit&&(this.conversionFactor=25.4*this.conversionFactor)},E2DEditor.prototype.updatePolyline=function(){if(this.selected){var e=this.polyLineProps.length.val(),t=this.polyLineProps.rotation.val();e=this.convertUserDataToGraphData(e),t=t?1*t:0;var i="select"!==this.mode&&!this.resizeMode.startsWith("polyline-");if("polyline-from"===this.resizeMode||"polyline-to"===this.resizeMode||"polyline-0"===this.resizeMode){var n="polyline-from"===this.resizeMode||"polyline-0"===this.resizeMode;this.renderer.updatePolyline(this.selected,e,t,n,!1)}else if(this.resizeMode.startsWith("polyline-")){var o=1*this.resizeMode.substring(9);this.renderer.updatePolylinePoint(this.selected,o,e,t)}else if(this.renderer.isPolylineSegmentSelected(this.selected)){var s=this.renderer.getPolylineSelectedSegment(this.selected);this.renderer.updatePolylinePoint(this.selected,s[1],e,t)}else this.renderer.updatePolyline(this.selected,e,t,!1,!0);this.insertedShapes.updateConnector(this.selected),this.saveUndoRedoPoint(0,"urUpdatePoly"),i||(E2DEvents.autoScrollIntervalID&&(clearInterval(E2DEvents.autoScrollIntervalID),E2DEvents.autoScrollIntervalID=null),E2DEvents.mouseDown={x:0,y:0},this.detachEditorMoveEvents(),this.setPropertiesVisible(null),this.restoreMode(),this.renderer.hideTracker(),this.renderer.hideLineTracker())}},E2DEditor.prototype.updateQuote=function(){if(this.selected){var e=this.insertedShapes.getShapeById(this.selected.id);if(e){e.dimType=1*this.quoteProps.type.find("input[name=_qTGroup]:checked").val(),e.dimDriving=this.quoteProps.driving.prop("checked"),e.dimValue=1*this.quoteProps.value.val();var t=this.convertUserDataToGraphData(e.dimValue);this.renderer.updateQuote(this.selected,null,e.dimType,e.dimDriving,t)&&(this.renderer.updateTracker(this.selected),this.updateShapeInfo(this.selected)),this.saveUndoRedoPoint(0,"urUpdateQuote")}}},E2DEditor.prototype.updateShapeAccordingToCustomProperties=function(e,t){if(!this.libraryProperties[t.getFullSource()])return e;var i,n,o=this.libraryProperties[t.getFullSource()].custom;if(!o)return e;var s=this.getUpdateDataFromCustomProperties(e,t,o);(s.width||"number"==typeof s.width)&&(s.noConvert?t.width=this.convertGraphDataToUserData(s.width):(t.width=s.width,s.width=this.convertUserDataToGraphData(s.width)),this.renderer.setDimensions(e,s.width,null,null)),(s.height||"number"==typeof s.height)&&(s.noConvert?t.height=this.convertGraphDataToUserData(s.height):(t.height=s.height,s.height=this.convertUserDataToGraphData(s.height)),this.renderer.setDimensions(e,null,s.height,null)),(s.depth||"number"==typeof s.depth)&&(s.noConvert?t.depth=this.convertGraphDataToUserData(s.depth):(t.depth=s.depth,s.depth=this.convertUserDataToGraphData(s.depth)),this.renderer.setDimensions(e,null,null,s.depth));var r=t.decodeBehaviour("(ORIGIN=");if((s.x||"number"==typeof s.x)&&(s.noConvert?t.x=this.convertGraphXToUserX(s.x):(t.x=s.x,s.x=this.convertUserXToGraphX(s.x)),r.found&&(i=this.renderer.bounds(e),n=this.applyShapeOriginToGraphData(s.x,i.y,i.width,i.height,r.value),s.x=n.x),this.renderer.setPosition(e,s.x,null,null)),(s.y||"number"==typeof s.y)&&(s.noConvert?t.y=this.convertGraphYToUserY(s.y):(t.y=s.y,s.y=this.convertUserYToGraphY(s.y)),r.found&&(i=this.renderer.bounds(e),n=this.applyShapeOriginToGraphData(i.x,s.y,i.width,i.height,r.value),s.y=n.y),this.renderer.setPosition(e,null,s.y,null)),(s.z||"number"==typeof s.z)&&(s.noConvert?t.z=this.convertGraphZToUserZ(s.z):(t.z=s.z,s.z=this.convertUserZToGraphZ(s.z)),this.renderer.setPosition(e,null,null,s.z)),(s.rotation||"number"==typeof s.rotation)&&(t.rotation=s.rotation,this.renderer.setRotation(e,s.rotation)),s.color&&(t.color=s.color,this.renderer.setFillColor(e,s.color)),s.color3d&&(t.color3D=s.color3d),s.image&&t.image!==s.image&&(t.image=s.image,this.renderer.setImage(e,s.image)),s.remBehaviour)for(var a=0,l=s.remBehaviour.length;a<l;a++)t.removeBehaviour("("+s.remBehaviour[a].trim()+")");if(s.addBehaviour)for(var h=0,d=s.addBehaviour.length;h<d;h++)t.addBehaviour("("+s.addBehaviour[h].trim()+")");return s.svg&&t.imageSVG!==s.svg&&(t.imageSVG=s.svg,this.renderer.replaceInternalSVG(e,t.sourceLibrary,s.svg)),this.renderer.updateTracker(e),this.renderer.moveLineWithShape(e,null,null),!1},E2DEditor.prototype.updateById=function(e,t,i,n){const o=document.getElementById(e);if(!o)return;const s=this.insertedShapes.getShapeById(e);let r="TOPLEFT";const a=s.decodeBehaviour("(ORIGIN=");a.found&&(r=a.value);let l=this.revertShapeOriginToUserData(t,i,s.width,s.height,r);l.x=this.convertUserXToGraphX(l.x),l.y=this.convertUserYToGraphY(l.y),l.z=this.convertUserZToGraphZ(n);const h=this.convertUserDataToGraphData(s.width),d=this.convertUserDataToGraphData(s.height);this.convertUserDataToGraphData(s.depth);a.found&&((l=this.applyShapeOriginToGraphData(l.x,l.y,h,d,a.value)).z=this.convertUserZToGraphZ(n));const c=this.renderer.getPosition(o);this.renderer.setPosition(o,l.x,l.y,l.z),this.renderer.setRotation(o,s.rotation),this.moveShapeDependencies(o,l.x-c.x,l.y-c.y,l.z-c.z,0),this.clearShapeText(o),this.resetShapeText(o),this.renderer.updateTracker(o),this.renderer.hideSnapLine(),this.clearPolylineQuotes(),this.performCheckInclusions(o),this.performCheckCollisions(o),this.performCheckPolylineQuotes(o),this.updateShapeInfo(o,null,!1,!0)},E2DEditor.prototype.updateShape=function(){if(!this.selected)return void this.setHelp("info","Please select a shape to update");var e=E2DGlobals.e2d.shapeProps.pin.prop("checked"),t=E2DGlobals.e2d.shapeProps.layer.val();this.updateLibraryLayers(t);var i={width:E2DGlobals.e2d.shapeProps.width.val(),height:E2DGlobals.e2d.shapeProps.height.val(),depth:E2DGlobals.e2d.shapeProps.depth.val(),x:E2DGlobals.e2d.shapeProps.x.val(),y:E2DGlobals.e2d.shapeProps.y.val(),z:E2DGlobals.e2d.shapeProps.z.val(),rotation:E2DGlobals.e2d.shapeProps.rotation.val()};if(i.width=this.evaluateDecimalFormula(i.width),!E2DUtils.isNumeric(i.width))return void E2DGlobals.e2d.shapeProps.width[0].setCustomValidity(this.translate("invalidFormula"));if(i.height=this.evaluateDecimalFormula(i.height),!E2DUtils.isNumeric(i.height))return void E2DGlobals.e2d.shapeProps.height[0].setCustomValidity(this.translate("invalidFormula"));if(i.depth=this.evaluateDecimalFormula(i.depth),!E2DUtils.isNumeric(i.depth))return void E2DGlobals.e2d.shapeProps.depth[0].setCustomValidity(this.translate("invalidFormula"));if(i.x=this.evaluateDecimalFormula(i.x),!E2DUtils.isNumeric(i.x))return void E2DGlobals.e2d.shapeProps.x[0].setCustomValidity(this.translate("invalidFormula"));if(i.y=this.evaluateDecimalFormula(i.y),!E2DUtils.isNumeric(i.y))return void E2DGlobals.e2d.shapeProps.y[0].setCustomValidity(this.translate("invalidFormula"));if(i.z=this.evaluateDecimalFormula(i.z),!E2DUtils.isNumeric(i.z))return void E2DGlobals.e2d.shapeProps.z[0].setCustomValidity(this.translate("invalidFormula"));var n,o,s,r,a=this.convertUserBoundsToGraphBounds(i),l=[],h=[];if(this.renderer.isMultipleSelect(this.selected)){var d,c=[],u=this.multipleSelectShapes.getShapes(),p=this.renderer.bounds(this.selected);p.rotation=a.rotation;for(var g=0,y=u.length;g<y;g++)if(o=u[g],!this.renderer.isConnector(o)&&(!this.customOrigin||o.id===this.CUSTOM_ORIGIN_ID)&&(n=this.insertedShapes.getShapeById(o.id))){var f=E2DUtils.cloneObject(a),v={width:n.width,height:n.height,depth:n.depth,x:n.x,y:n.y,z:n.z,rotation:n.rotation},m=this.convertUserBoundsToGraphBounds(v);f.width=m.width,f.height=m.height,f.depth=m.depth,f.x=m.x+(f.x-p.x),f.y=m.y+(f.y-p.y),f.z=m.z+(f.z-p.z),i.rotation||(f.rotation=m.rotation),c[c.length]={shape:o,iShape:n,rect:f,beforeRect:this.renderer.bounds(o)}}for(var S=[],E=0,D=c.length;E<D;E++){var b=c[E];if(b.iShape.setProps(e,t),!S[b.iShape.id]){if(!(o=this.updateShapeSingle(b.shape,b.iShape,b.rect,!1,p)))break;var x=!1;s=this.renderer.bounds(o),this.events.rotated&&!this.renderer.hasSameRotation(b.beforeRect,s)&&(x=!0,(d=this.getEventArgumentByShapeId("ROTATED",o.id))&&(l[l.length]=d));var I=this.insertedShapes.getAttachedShapesDeep(b.iShape.id,["link-line","quote-line"],{driving:!0});if(I&&I.length)for(var C=0,T=I.length;C<T;C++)S[I[C]]=!0,x&&(d=this.getEventArgumentByShapeId("ROTATED",I[C]))&&(l[l.length]=d)}}this.selectShapes(u),this.renderer.updateTracker(this.selected),this.updateShapeInfo(this.selected)}else{var P=this.selected;if(this.customOrigin&&P.id!==this.CUSTOM_ORIGIN_ID){var L=this.customOrigin.x*this.origin.signX*1+1*this.origin.x,O=this.customOrigin.y*this.origin.signY*1+1*this.origin.y;a.x=this.convertUserDataToGraphData(L+i.x*this.customOrigin.signX*1),a.y=this.convertUserDataToGraphData(O+i.y*this.customOrigin.signY*1)}if(r=this.renderer.bounds(P),(n=this.insertedShapes.getShapeById(P.id)).setProps(e,t),!(P=this.updateShapeSingle(P,n,a)))return;s=this.renderer.bounds(P),this.events.rotated&&!this.renderer.hasSameRotation(r,s)&&(d=this.getEventArgumentByShapeId("ROTATED",P.id))&&(l[l.length]=d),this.events.stretched&&!this.renderer.hasSameDimensions(r,s)&&(d=this.getEventArgumentByShapeId("STRETCHED",P.id))&&(h[h.length]=d),this.renderer.updateTracker(P),this.unselect(),this.select(P),this.updateOnTheFlyStyleForHighlightEqualShape(n)}let w=!0,G="urUpdateShapes";this.events.rotated&&l.length>0&&(w=!1,G="urRotateShapes",E2DEvents.doSubmitEvent("OnEditor2DRotated",l,1,G)),this.events.stretched&&h.length>0&&(w=!1,G="urStretchShapes",E2DEvents.doSubmitEvent("OnEditor2DStretched",h,1,G)),w&&this.saveUndoRedoPoint(0,G)},E2DEditor.prototype.updateShapeEx=function(e,t){if(e&&t){e.copyFrom(t);var i={width:e.width,height:e.height,depth:e.depth,x:e.x,y:e.y,z:e.z,rotation:e.rotation},n=this.convertUserBoundsToGraphBounds(i);if(this.customOrigin&&e.id!==this.CUSTOM_ORIGIN_ID){var o=this.customOrigin.x*this.origin.signX*1+1*this.origin.x,s=this.customOrigin.y*this.origin.signY*1+1*this.origin.y;n.x=this.convertUserDataToGraphData(o+i.x*this.customOrigin.signX*1),n.y=this.convertUserDataToGraphData(s+i.y*this.customOrigin.signY*1)}var r=document.getElementById(e.id);this.updateLibraryLayers(e.layer),this.updateShapeSingle(r,e,n,!0),e.update3D()}},E2DEditor.prototype.updateConnectorEx=function(e,t){if(e&&t){e.copyFrom(t);var i=document.getElementById(e.id);this.updateConnectorSingle(i,e),e.update3D()}},E2DEditor.prototype.updateConnectorSingle=function(e,t){var i=this.convertUserXToGraphX(t.x),n=this.convertUserYToGraphY(t.y),o=this.convertUserXToGraphX(t.width),s=this.convertUserYToGraphY(t.height),r=null,a=null;"number"==typeof t.ctrl1x&&"number"==typeof t.ctrl1y&&-1!==t.ctrl1x&&-1!==t.ctrl1y&&(r=this.convertUserXToGraphX(t.ctrl1x),a=this.convertUserYToGraphY(t.ctrl1y));var l=null,h=null;"number"==typeof t.ctrl2x&&"number"==typeof t.ctrl2y&&-1!==t.ctrl2x&&-1!==t.ctrl2y&&(l=this.convertUserXToGraphX(t.ctrl2x),h=this.convertUserYToGraphY(t.ctrl2y));var d=null,c=null;t.shapeFromId&&(c=document.getElementById(t.shapeFromId)),c&&(d=this.renderer.getConnectionPointObjByPointId(c,t.shapeFromPointIndex))&&(t.x=E2DUtils.round(this.convertGraphXToUserX(d.x),this.numberOfDecimal),t.y=E2DUtils.round(this.convertGraphYToUserY(d.y),this.numberOfDecimal),i=d.x,n=d.y);var u=null;if(t.shapeToId&&(u=document.getElementById(t.shapeToId)),u&&(d=this.renderer.getConnectionPointObjByPointId(u,t.shapeToPointIndex))&&(t.width=E2DUtils.round(this.convertGraphXToUserX(d.x),this.numberOfDecimal),t.height=E2DUtils.round(this.convertGraphYToUserY(d.y),this.numberOfDecimal),o=d.x,s=d.y),"link-line"===t.source){if(!c||!u)return void this.deleteItem(e);if(c.id===u.id)return void this.deleteItem(e)}switch(t.source){case"line":case"link-line":case"ortho-line":case"smart-line":case"quote-line":this.renderer.moveLine(e,i,n,!0),this.renderer.moveLine(e,o,s,!1);break;case"curve-line":this.renderer.moveLine(e,i,n,!0),this.renderer.moveLine(e,o,s,!1),this.renderer.setControl1(e,r,a),this.renderer.setControl2(e,l,h);break;case"poly-line":if(t.path){var p=this.convertUserStringToPath(t.path);this.renderer.setPolylinePoints(e,p),this.renderer.setPolylineColor(e,t.lineColor),this.renderer.setPolylineWidth(e,t.lineWidth)}}if(c&&(this.renderer.disconnectLineFromShape(e,"from"),this.renderer.connectLine(c,e,"from",t.shapeFromPointIndex)),u){this.renderer.disconnectLineFromShape(e,"to");var g=null;if(t.isLinkLine()&&(g=this.insertedShapes.getCircularReference(u.id,e,t.source)).circular&&!this.areOverlappingConnectionPoints(c,t.shapeFromPointIndex,u,t.shapeToPointIndex))return void this.deleteItem(e);this.renderer.connectLine(u,e,"to",t.shapeToPointIndex),t.isLinkLine()&&!g.circular&&this.renderer.validateLink(e)}if(t.isQuoteLine()){this.isShapesLoadPending()&&this.clearDragCache();var y=this.convertUserDataToGraphData(t.dimStack),f=this.convertUserDataToGraphData(t.dimValue),v=E2DTag.isTagInString(t.behaviour,"(DIMSTACKABSOLUTE)");this.renderer.updateQuote(e,y,t.dimType,t.dimDriving,f,v)}!t.text||t.isPolyline()||t.isQuoteLine()||this.renderer.setShapeText(e,t.text),this.clearShapeText(e),this.resetShapeText(e)},E2DEditor.prototype.updateShapeSingle=function(e,t,i,n,o){if(t){if(!n&&!this.updateShapeCustomProperties(t))return null;this.updateCustomOrigin(t),this.updateShapeInfoAccordingToCustomProperties(e,t,i),this.updateShapeInfoAccordingToAspectRatio(e,t,i),this.updateShapeInfoAccordingToOrigin(e,t,i)}let s=null,r=this.renderer.bounds(e);var a,l,h,d;r.width===i.width&&r.height===i.height||(s=this.getShapeDependenciesBeforeResize(e,!0)),this.renderer.setDimensions(e,i.width,i.height,i.depth),s&&(s=this.updateShapeDependenciesAfterResize(e,s),this.moveShapeDependenciesAfterResize(e,s));var c=this.renderer.bounds(e);if(this.renderer.isMultipleSelect(this.selected)&&!this.renderer.isMultipleSelect(e))if(i.rotation>0){var u=1*c.rotation+Math.round(o.rotation),p=this.renderer.getProportionalBoundsRotation(c,o,o.rotation);a=p.x-c.x,l=p.y-c.y,d=u-c.rotation,this.renderer.rotate(e,u),this.renderer.move(e,p.x,p.y,null)}else a=i.x-c.x,l=i.y-c.y,h=i.z-c.z,d=0,this.renderer.move(e,i.x,i.y,i.z);else a=i.x-c.x,l=i.y-c.y,h=i.z-c.z,d=i.rotation-c.rotation,this.renderer.setPosition(e,i.x,i.y,i.z),this.renderer.setRotation(e,i.rotation);this.moveShapeDependencies(e,a,l,h,d),this.renderer.setLayer(e,this.libraryLayers[t.layer]),this.renderer.setPinned(e,!!t&&t.pinned);var g=this.renderer.getShapeText(e);return g&&t.text&&g!==t.text?this.renderer.setShapeText(e,t.text):(this.clearShapeText(e),this.resetShapeText(e)),e},E2DEditor.prototype.updateShapeCustomProperties=function(e){var t=this.libraryProperties[e.getFullSource()].custom;if(!t)return!0;for(var i in e.custom){var n=$("#"+i.replace(" ","_"));if(0!==n.length){var o=null;if(o="select"===n.prop("tagName").toLowerCase()?n.find(":selected").text():n.val()){var s=t[i].UIValidation;if(s&&i&&o){var r=s.replace(/value/gi,o),a=s.replace(/value/gi,i);if(!window.eval(r))return n.addClass("validationError"),n.attr("title",a),!1;n.removeClass("validationError"),n.removeAttr("title")}e.custom[i]=o}}}return!0},E2DEditor.prototype.updateShapeInfoAccordingToCustomProperties=function(e,t,i){if(!this.libraryProperties[t.getFullSource()])return!1;var n=this.libraryProperties[t.getFullSource()].custom;if(!n)return e;var o=this.getUpdateDataFromCustomProperties(e,t,n);if((o.width||"number"==typeof o.width)&&(i.width=o.noConvert?o.width:this.convertUserDataToGraphData(o.width)),(o.height||"number"==typeof o.height)&&(i.height=o.noConvert?o.height:this.convertUserDataToGraphData(o.height)),(o.depth||"number"==typeof o.depth)&&(i.depth=o.noConvert?o.depth:this.convertUserDataToGraphData(o.depth)),(o.x||"number"==typeof o.x)&&(i.x=o.noConvert?o.x:this.convertUserXToGraphX(o.x)),(o.y||"number"==typeof o.y)&&(i.y=o.noConvert?o.y:this.convertUserYToGraphY(o.y)),(o.z||"number"==typeof o.z)&&(i.z=o.noConvert?o.z:this.convertUserZToGraphZ(o.z)),(o.rotation||"number"==typeof o.rotation)&&(i.rotation=o.rotation),o.color&&(t.color=o.color,this.renderer.setFillColor(e,o.color)),o.color3d&&(t.color3D=o.color3d),o.image&&t.image!==o.image&&(t.image=o.image,this.renderer.setImage(e,o.image)),o.remBehaviour)for(var s=0,r=o.remBehaviour.length;s<r;s++)t.removeBehaviour("("+o.remBehaviour[s].trim()+")");if(o.addBehaviour)for(var a=0,l=o.addBehaviour.length;a<l;a++)t.addBehaviour("("+o.addBehaviour[a].trim()+")");return o.svg&&t.imageSVG!==o.svg&&(t.imageSVG=o.svg,this.renderer.replaceInternalSVG(e,t.sourceLibrary,o.svg)),!1},E2DEditor.prototype.updateShapeInfoAccordingToAspectRatio=function(e,t,i){if(t.hasBehaviour("(KEEPASPECTRATIO)")){var n=this.renderer.bounds(e),o=E2DUtils.round(n.width/n.height,1);n.width!==i.width&&n.height!==i.height?i.height=i.width/o:n.width!==i.width?i.height=i.width/o:n.height!==i.height&&(i.width=i.height*o)}},E2DEditor.prototype.updateShapeInfoAccordingToOrigin=function(e,t,i){var n=t.decodeBehaviour("(ORIGIN=");if(n.found){var o=this.applyShapeOriginToGraphData(i.x,i.y,i.width,i.height,n.value);i.x=o.x,i.y=o.y}},E2DEditor.prototype.updateShapeInfo=function(e,t,i,n){if(this.renderer.isMultipleSelect(e)){var o=this.multipleSelectShapes.getShapes();return this.updateMultipleShapeInfo(o),void this.showCommonShapeInfo(o)}var s={};if(e){s=t||this.renderer.bounds(e);var r={x:0,y:0,z:0},a=this.updateIShape(e,s,"",n,r);if(this.renderer.isConnector(e)){if(this.renderer.isPolyline(e)){if(!this.polyLinePropertiesEnabled)return;if("poly-line"===this.mode||this.resizeMode.startsWith("polyline-")||this.renderer.isPolylineSegmentSelected(this.selected)){if(this.polyLineProps.units.html("<strong>("+this.unit+")</strong>"),!this.hasFocusPolyLineProperties()){var l=null;if(s=this.convertTrueBoundsToUserBounds(s),"select"===this.mode&&this.renderer.isPolylineSegmentSelected(this.selected)){var h=this.renderer.getPolylineSelectedSegment(this.selected);(l=this.renderer.getPolylineSegmentInfo(e,h[1])).length=this.convertGraphDataToUserData(l.length),this.polyLineProps.length.val(E2DUtils.round(l.length,this.numberOfDecimal)),this.polyLineProps.rotation.val(l.rotation)}else if("polyline-to"===this.resizeMode||""===this.resizeMode)this.polyLineProps.length.val(E2DUtils.round(s.lengthTo,this.numberOfDecimal)),this.polyLineProps.rotation.val(s.rotationTo);else if("polyline-from"===this.resizeMode||"polyline-0"===this.resizeMode)this.polyLineProps.length.val(E2DUtils.round(s.lengthFrom,this.numberOfDecimal)),this.polyLineProps.rotation.val(s.rotationFrom);else{var d=1*this.resizeMode.substring(9);(l=this.renderer.getPolylineSegmentInfo(e,d)).length=this.convertGraphDataToUserData(l.length),this.polyLineProps.length.val(E2DUtils.round(l.length,this.numberOfDecimal)),this.polyLineProps.rotation.val(l.rotation)}}this.setPropertiesVisible(this.polyLineProps.table)}}else if(this.renderer.isQuoteLine(e)){if(!this.quotePropertiesEnabled)return;this.quoteProps.units.html("<strong>("+this.unit+")</strong>");var c=this.insertedShapes.getShapeById(e.id);if(c){this.quoteProps.driving.prop("checked",c.dimDriving),this.quoteProps.type.find("input[name=_qTGroup]").each(function(){var e=$(this);if(1*e.val()===c.dimType)return e.prop("checked",!0).trigger("change"),!1}),this.quoteProps.value.val(c.dimValue);var u=this.insertedShapes.getConnectionShape(c.id,"from"),p=this.insertedShapes.getConnectionShape(c.id,"to"),g=u.shapeID===p.shapeID;E2DEvents.enableQuoteDriving(c.dimDriving,g)}this.setPropertiesVisible(this.quoteProps.table)}}else{if(!a)return;if(!this.shapePropertiesEnabled)return;this.shapeProps.width[0].setCustomValidity(""),this.shapeProps.height[0].setCustomValidity(""),this.shapeProps.depth[0].setCustomValidity(""),this.shapeProps.x[0].setCustomValidity(""),this.shapeProps.y[0].setCustomValidity(""),this.shapeProps.z[0].setCustomValidity("");var y=this.getBehaviour(e.id,!0);if(!E2DEvents.dragStarted&&(this.shapeProps.units.html("<strong>("+E2DGlobals.e2d.unit+")</strong>"),this.shapeProps.name.html("<strong>"+a.name+"</strong>"),this.shapeProps.pin.prop("checked",!!a.pinned),this.shapeProps.width.attr("readOnly",y.stretch.noStretch||y.stretch.noWStretch),this.shapeProps.height.attr("readOnly",y.stretch.noStretch||y.stretch.noHStretch),this.shapeProps.depth.attr("readOnly",y.stretch.noStretch||y.stretch.noDStretch),this.shapeProps.x.attr("readOnly",y.move.noMove||y.move.noXMove),this.shapeProps.y.attr("readOnly",y.move.noMove||y.move.noYMove),this.shapeProps.z.attr("readOnly",y.move.noMove||y.move.noZMove),this.shapeProps.rotation.attr("readOnly",y.move.noRotate),this.libraryProperties[a.getFullSource()])){var f=this.libraryProperties[a.getFullSource()],v=f.iconBig||f.icon;this.shapeProps.image.attr("src",v||(a.sourceLibrary||this.shapeLibraryList[0])+"/theme/images/e2d/shape.png")}if(this.shapeProps.layer.val(a.layer),this.shapeProps.width.val(a.width),this.shapeProps.height.val(a.height),this.shapeProps.depth.val(a.depth),this.customOrigin&&e.id!==this.CUSTOM_ORIGIN_ID?(r.x=(r.x-this.customOrigin.x)*this.customOrigin.signX*this.origin.signX,r.y=(r.y-this.customOrigin.y)*this.customOrigin.signY*this.origin.signY,r.z=(r.z-this.customOrigin.z)*this.customOrigin.signZ*this.origin.signZ,this.shapeProps.x.val(E2DUtils.round(r.x,this.numberOfDecimal)),this.shapeProps.y.val(E2DUtils.round(r.y,this.numberOfDecimal)),this.shapeProps.z.val(E2DUtils.round(r.z,this.numberOfDecimal))):(this.shapeProps.x.val(a.x),this.shapeProps.y.val(a.y),this.shapeProps.z.val(a.z)),e.id===this.CUSTOM_ORIGIN_ID&&(this.customOrigin.x=a.x,this.customOrigin.y=a.y,this.customOrigin.z=a.z),this.shapeProps.rotation.val(a.rotation),i){var m=a.id===this.CUSTOM_ORIGIN_ID||a.hasBehaviour("(HIDEPIN)")?"none":"";$("#_pin_row").css("display",m);var S=a.hasBehaviour("(HIDEDIMENSIONS)")?"none":"",E=!this.enable3d&&"PROPSONLY"!==this.enable3dViewStyle||a.hasBehaviour("(HIDEDIMENSIONS)")?"none":"";$("#_width_row").css("display",S),$("#_height_row").css("display",S),$("#_depth_row").css("display",E);var D=a.hasBehaviour("(HIDECOORDINATES)")?"none":"",b=!this.enable3d&&"PROPSONLY"!==this.enable3dViewStyle||a.hasBehaviour("(HIDECOORDINATES)")?"none":"";$("#_x_row").css("display",D),$("#_y_row").css("display",D),$("#_z_row").css("display",m||b);var x=a.hasBehaviour("(HIDEROTATION)")?"none":"";$("#_rotation_row").css("display",x);var I=a.hasBehaviour("(HIDELAYER)")?"none":"";$("#_layer_row").css("display",I);var C=a.hasBehaviour("(HIDEUPDATEBUTTON)")?"none":"";$("#btnUpdateShape").css("display",C);var T=a.hasBehaviour("(SHOWCONFIGUREBUTTON)")?"":"none";$("#btnConfigureShape").css("display",T);var P=a.hasBehaviour("(SHOWVALIDATEBUTTON)")?"":"none";$("#btnValidateShape").css("display",P),this.updateShapePropertiesTableWithCustomProperties(a.getFullSource(),a)}this.setPropertiesVisible(this.shapeProps.table)}}else this.setPropertiesVisible(null)},E2DEditor.prototype.updateMultipleShapeInfo=function(e){for(var t={},i=0,n=e.length;i<n;i++)t=this.renderer.bounds(e[i]),this.updateIShape(e[i],t,"",!1)},E2DEditor.prototype.updateIShape=function(e,t,i,n,o){if(!e)return null;var s=this.insertedShapes.getShapeById(e.id);if(!s)return null;t=this.convertTrueBoundsToUserBounds(t);var r=s.decodeBehaviour("(ORIGIN=");if(r.found){var a=this.applyShapeOriginToUserData(t.x,t.y,t.width,t.height,r.value);t.x=a.x,t.y=a.y}if(o&&(o.x=t.x,o.y=t.y,o.z=t.z),this.renderer.isConnector(e))s.updateConnector(e);else{t=this.applyRoundingToUserRect(t),s.update(t.x,t.y,t.z,t.width,t.height,t.depth,t.rotation,i,n);var l=this.renderer.getAllConnectorsForShape(e);if(l&&l.length>0)for(var h=0,d=l.length;h<d;h++)this.insertedShapes.updateConnector(l[h])}return s},E2DEditor.prototype.showCommonShapeInfo=function(e){if(!this.shapePropertiesEnabled)return;const t=this.getMainShapeSourceFromMultipleShapes(e),i=this.getMainShapeValuesFromMultipleShapes(e,t.fullSource);this.shapeProps.name.html("<strong>"+t.name+"</strong>"),this.shapeProps.pin.prop("checked",!1),this.shapeProps.layer.val(i.layer),this.shapeProps.width.val(""),this.shapeProps.height.val(""),this.shapeProps.depth.val("");var n=this.renderer.getMultipleSelector(),o=this.renderer.bounds(n),s=this.convertTrueBoundsToUserBounds(o);if(this.shapeProps.x.val(E2DUtils.round(s.x,this.numberOfDecimal)),this.shapeProps.y.val(E2DUtils.round(s.y,this.numberOfDecimal)),this.shapeProps.z.val(E2DUtils.round(s.z,this.numberOfDecimal)),this.shapeProps.rotation.val(s.rotation),this.libraryProperties&&this.libraryProperties[t.fullSource]){var r=this.libraryProperties[t.fullSource],a=r.iconBig||r.icon;this.shapeProps.image.attr("src",a||this.shapeLibraryList[0]+"/theme/images/e2d/shape.png");var l=this.getBehaviourFromMultipleShapes(e),h=E2DTag.isTagInString(l,"(HIDECOORDINATES)")?"none":"";$("#_x_row").css("display",h),$("#_y_row").css("display",h),$("#_z_row").css("display",h),$("#_width_row").css("display","none"),$("#_height_row").css("display","none"),$("#_depth_row").css("display","none");var d=E2DTag.isTagInString(l,"(HIDEROTATION)")?"none":"";$("#_rotation_row").css("display",d);var c=E2DTag.isTagInString(l,"(HIDELAYER)")?"none":"";$("#_layer_row").css("display",c);var u=E2DTag.isTagInString(l,"(HIDEUPDATEBUTTON)")?"none":"";$("#btnUpdateShape").css("display",u);var p=E2DTag.isTagInString(l,"(SHOWCONFIGUREBUTTON)")?"":"none";$("#btnConfigureShape").css("display",p);var g=E2DTag.isTagInString(l,"(SHOWVALIDATEBUTTON)")?"":"none";$("#btnValidateShape").css("display",g),this.updateShapePropertiesTableWithCustomProperties(t.fullSource,i),this.setPropertiesVisible(this.shapeProps.table)}},E2DEditor.prototype.getBehaviourFromMultipleShapes=function(e){return e&&0!==e.length?e.reduce((e,t)=>{if(this.renderer.isConnector(t))return e;return e+=this.insertedShapes.getShapeById(t.id).behaviour},""):""},E2DEditor.prototype.getBehaviour=function(e,t){var i={move:{},stretch:{}};if(!e||e===this.ORIGIN_ID||e===this.CUSTOM_ORIGIN_ID)return i;if(this.renderer.isMultipleSelect(e))for(var n=this.multipleSelectShapes.getShapes(),o=0,s=n.length;o<s;o++){var r=this.getBehaviour(n[o].id,!1);i.move.background=i.move.background||r.move.background,i.move.noMove=i.move.noMove||r.move.noMove,i.move.noXMove=i.move.noXMove||r.move.noXMove,i.move.noYMove=i.move.noYMove||r.move.noYMove,i.move.noZMove=i.move.noZMove||r.move.noZMove,i.move.noRotate=i.move.noRotate||r.move.noRotate,i.move.noRotateOnView=i.move.noRotateOnView||r.move.noRotateOnView,i.move.noSelect=i.move.noSelect||r.move.noSelect,i.stretch.noStretch=i.stretch.noStretch||r.stretch.noStretch,i.stretch.noStretchOnView=i.stretch.noStretchOnView||r.stretch.noStretchOnView,i.stretch.noWStretch=i.stretch.noWStretch||r.stretch.noWStretch,i.stretch.noHStretch=i.stretch.noHStretch||r.stretch.noHStretch,i.stretch.noDStretch=i.stretch.noDStretch||r.stretch.noDStretch,i.stretch.noSelect=i.stretch.noSelect||r.stretch.noSelect,i.stretch.background=i.stretch.background||r.stretch.background,i.noGroup=i.noGroup||r.noGroup}else{i.move=this.getMoveBehaviour(e,t),i.stretch=this.getStretchBehaviour(e,i.move);var a=this.insertedShapes.getShapeById(e);a&&(i.noGroup=a.hasBehaviour("(NOGROUP)"))}return i},E2DEditor.prototype.getMoveBehaviour=function(e,t){var i={noMove:!1,noXMove:!1,noYMove:!1,noZMove:!1,noRotate:!1,noRotateOnView:!1,noSelect:!1,background:!1};if(!e)return i;var n=this.insertedShapes.getShapeById(e);if(!n)return i;if(n.calculatedBehaviour&&void 0!==n.calculatedBehaviour.move)return n.calculatedBehaviour.move;if(t)i=this.getMoveBehaviourForLinkedShapes(e);else{var o=this.insertedShapes.isPinned(e);(i={noMove:o.pinnedX&&o.pinnedY,noXMove:o.pinnedX,noYMove:o.pinnedY,noZMove:o.pinnedZ||e===this.CUSTOM_ORIGIN_ID,noRotate:o.pinnedX||o.pinnedY,noRotateOnView:o.pinnedX||o.pinnedY,noSelect:!1,background:!1}).noRotate=i.noRotate||n.hasBehaviour("(NOROTATE)"),i.noRotateOnView=i.noRotateOnView||n.hasBehaviour("(NOROTATEONVIEW)"),i.noSelect=n.hasBehaviour("(NOSELECT)"),i.background=n.hasBehaviour("(BACKGROUND)")}return n.setCalculatedBehaviourMove(i),i},E2DEditor.prototype.getMoveBehaviourForLinkedShapes=function(e,t,i){var n=this.getMoveBehaviour(e),o=this.insertedShapes.getAttachedLines(e,["link-line"]);if(o&&o.length>0){t=t||[],i=i||[];for(var s=null,r=0,a=o.length;r<a;r++){if(!t[o[r]]){t[o[r]]=!0;var l=this.insertedShapes.getConnectionShape(o[r],"from");l.shapeID!==e&&(s=this.getMoveBehaviourForLinkedShapes(l.shapeID,t,i),n.noMove=n.noMove||s.noMove,n.noXMove=n.noXMove||s.noXMove,n.noYMove=n.noYMove||s.noYMove,n.noZMove=n.noZMove||s.noZMove,n.noRotate=n.noRotate||s.noRotate,n.noRotateOnView=n.noRotateOnView||s.noRotateOnView)}if(!i[o[r]]){i[o[r]]=!0;var h=this.insertedShapes.getConnectionShape(o[r],"to");h.shapeID!==e&&(s=this.getMoveBehaviourForLinkedShapes(h.shapeID,t,i),n.noMove=n.noMove||s.noMove,n.noXMove=n.noXMove||s.noXMove,n.noYMove=n.noYMove||s.noYMove,n.noZMove=n.noZMove||s.noZMove,n.noRotate=n.noRotate||s.noRotate,n.noRotateOnView=n.noRotateOnView||s.noRotateOnView)}}}return n},E2DEditor.prototype.getStretchBehaviour=function(e,t){var i=(t=t||this.getMoveBehaviour(e,!0)).noMove||t.noXMove||t.noYMove,n={noStretch:i,noStretchOnView:i,noWStretch:i,noHStretch:i,noDStretch:!1,noSelect:!1,background:!1};if(!e)return n;var o=this.insertedShapes.getShapeById(e);return o?o.calculatedBehaviour&&void 0!==o.calculatedBehaviour.stretch?o.calculatedBehaviour.stretch:(n.noStretch=n.noStretch||o.hasBehaviour("(NOSTRETCH)"),n.noStretchOnView=n.noStretchOnView||o.hasBehaviour("(NOSTRETCHONVIEW)"),n.noWStretch=n.noWStretch||o.hasBehaviour("(NOHSTRETCH)")||o.hasBehaviour("(NOWWSTRETCH)"),n.noHStretch=n.noHStretch||o.hasBehaviour("(NOVSTRETCH)")||o.hasBehaviour("(NOHHSTRETCH)"),n.noDStretch=n.noDStretch||o.hasBehaviour("(NODSTRETCH)")||o.hasBehaviour("(NODDSTRETCH)"),n.noSelect=o.hasBehaviour("(NOSELECT)"),n.background=o.hasBehaviour("(BACKGROUND)"),o.setCalculatedBehaviourStretch(n),n):n},E2DEditor.prototype.getMainShapeSourceFromMultipleShapes=function(e){const t={source:"",fullSource:"",name:""};if(!e||0===e.length)return t;const i=e.reduce((e,t)=>{if(e=e||{},this.renderer.isConnector(t))return e;const i=this.insertedShapes.getShapeById(t.id);if(!i)return e;const n=i.getFullSource();return e[n]?e[n].count++:e[n]={count:1,source:i.source,fullSource:n,name:i.name},e},null),n=Object.values(i);if(n&&n.length>0){const e=n.reduce((e,t)=>e.count>t.count?e:t);t.source=e.source,t.fullSource=e.fullSource,t.name=e.name}return t},E2DEditor.prototype.getMainShapeValuesFromMultipleShapes=function(e,t){let i={layer:"",custom:{}};if(!e||0===e.length)return i;const n=e.find(e=>{if(this.renderer.isConnector(e))return!1;const i=this.insertedShapes.getShapeById(e.id);return!!i&&i.getFullSource()===t});if(!n)return i;const o=this.insertedShapes.getShapeById(n.id),s=JSON.parse(JSON.stringify(o));i.layer=s.layer,i.custom=s.custom;const r=i.custom?Object.keys(i.custom):[];return i=e.reduce((e,i)=>{if(this.renderer.isConnector(i))return e;const n=this.insertedShapes.getShapeById(i.id);if(!n)return e;if(n.getFullSource()!==t)return e;const o=JSON.parse(JSON.stringify(n));return e.layer!==o.layer&&(e.layer=null),e.custom&&o.custom?r.forEach(t=>{e.custom[t]!=o.custom[t]&&(e.custom[t]=null)}):e.custom=null,e},i)},E2DEditor.prototype.updateShapePropertiesTableWithCustomProperties=function(e,t){if(this.shapePropertiesEnabled){var i=$("#_toolbarShapePropertiesDetails");if(0!==i.length&&(i.find(".shapeCustomPropertyRow").remove(),this.libraryProperties&&this.libraryProperties[e]&&this.libraryProperties[e].custom)){var n=this.libraryProperties[e].custom;for(var o in n){var s=this.createCustomPropertyRowForShapePropertiesTable(t,o,n[o]);s&&0!==s.length&&i.append(s)}}}},E2DEditor.prototype.createCustomPropertyRowForShapePropertiesTable=function(e,t,i){if($.isEmptyObject(i))return null;if("hide"===i.UIType)return null;var n=$("<div>").addClass("shapeCustomPropertyRow"),o=($("<label>").attr("for",t).text(t).appendTo(n),null);switch(i.UIType){case"number":o=$("<input>").attr({type:"number",step:"any",readOnly:!!i.UIReadOnly,disabled:!!i.UIDisabled}).val(e?e.custom[t]:"").on("click",E2DEvents.selectAll).on("keydown",E2DEvents.isDecimalNumberKey);break;case"text":o=$("<input>").attr({type:"text",readOnly:!!i.UIReadOnly,disabled:!!i.UIDisabled}).val(e?e.custom[t]:"").on("click",E2DEvents.selectAll);break;default:for(var s in o=$("<select>"),i)if("UIType"!==s&&"UIDefault"!==s&&"UIDefaultNoConvert"!==s&&"UINoConvert"!==s&&"UIFormula"!==s)if("UIReadOnly"!==s&&"UIDisabled"!==s){var r=$("<option>").attr("value",s).text(s),a=s;e&&("boolean"==typeof e.custom[t]&&(a="true"===s.toLowerCase()),a==e.custom[t]&&r.prop("selected",!0)),o.append(r)}else o.prop("disabled",!0)}return o.attr({id:t.replace(" ","_"),name:t,class:"text ui-widget-content ui-corner-all"}).appendTo(n),n},E2DEditor.prototype.getUpdateDataFromCustomProperties=function(e,t,i){var n={isNumber:!1,noConvert:null,width:null,height:null,depth:null,x:null,y:null,z:null,rotation:null,color:null,image:null,svg:null,addBehaviour:null,remBehaviour:null};for(var o in t.custom){var s=i[o];if(s){var r=t.custom[o];if(r||"number"==typeof r){var a=s.UIFormula;if(a||(a=s[r]),a){n.isNumber="number"===s.UIType,n.noConvert=!!s.UINoConvert;var l=E2DTag.decodeTagInString(a,"(COLOR=");if(l.found&&(n.color=l.value),(l=E2DTag.decodeTagInString(a,"(COLOR3D=")).found&&(n.color3d=l.value),(l=E2DTag.decodeTagInString(a,"(IMAGE=")).found&&(n.image=l.value),(l=E2DTag.decodeTagInString(a,"(SVG=")).found&&(n.svg=l.value),(l=E2DTag.decodeTagInString(a,"(ADDBEHAVIOUR=")).found&&(n.addBehaviour=l.value.split(",")),(l=E2DTag.decodeTagInString(a,"(REMBEHAVIOUR=")).found&&(n.remBehaviour=l.value.split(",")),(l=E2DTag.decodeTagInString(a,"(WIDTH=")).found){if(n.isNumber)try{t.custom[o]=E2DUtils.round(window.eval(t.custom[o]),this.numberOfDecimal)}catch(e){}var h=this.getCustomPropertyFormula(l.value,r,t);n.width=window.eval(h)}if((l=E2DTag.decodeTagInString(a,"(HEIGHT=")).found){if(n.isNumber)try{t.custom[o]=E2DUtils.round(window.eval(t.custom[o]),this.numberOfDecimal)}catch(e){}var d=this.getCustomPropertyFormula(l.value,r,t);n.height=window.eval(d)}if((l=E2DTag.decodeTagInString(a,"(DEPTH=")).found){if(n.isNumber)try{t.custom[o]=E2DUtils.round(window.eval(t.custom[o]),this.numberOfDecimal)}catch(e){}var c=this.getCustomPropertyFormula(l.value,r,t);n.depth=window.eval(c)}if((l=E2DTag.decodeTagInString(a,"(X=")).found){if(n.isNumber)try{t.custom[o]=E2DUtils.round(window.eval(t.custom[o]),this.numberOfDecimal)}catch(e){}var u=this.getCustomPropertyFormula(l.value,r,t);n.x=window.eval(u)}if((l=E2DTag.decodeTagInString(a,"(Y=")).found){if(n.isNumber)try{t.custom[o]=E2DUtils.round(window.eval(t.custom[o]),this.numberOfDecimal)}catch(e){}var p=this.getCustomPropertyFormula(l.value,r,t);n.y=window.eval(p)}if((l=E2DTag.decodeTagInString(a,"(Z=")).found){if(n.isNumber)try{t.custom[o]=E2DUtils.round(window.eval(t.custom[o]),this.numberOfDecimal)}catch(e){}var g=this.getCustomPropertyFormula(l.value,r,t);n.z=window.eval(g)}if((l=E2DTag.decodeTagInString(a,"(ROTATION=")).found){if(n.isNumber)try{t.custom[o]=E2DUtils.round(window.eval(t.custom[o]),this.numberOfDecimal)}catch(e){}var y=this.getCustomPropertyFormula(l.value,r,t);n.rotation=window.eval(y)}}}}}return n},E2DEditor.prototype.evaluateDecimalFormula=function(e){if(isNaN(e))try{return 1*window.eval(e)}catch(e){return null}return 1*e},E2DEditor.prototype.getValueOrEvaluateFormula=function(e,t){var i=0;if(E2DUtils.isNumeric(e))i=1*e;else if(e){var n=this.getFormula(e,t);i=1*window.eval(n)}return i},E2DEditor.prototype.getFormula=function(e,t){var i=e;return-1===(i=(i=(i=(i=(i=(i=(i=(i=i.replace(/width/gi,t.width/this.scale)).replace(/height/gi,t.height/this.scale)).replace(/depth/gi,t.depth/this.scale)).replace(/x/gi,t.x/this.scale)).replace(/y/gi,t.y/this.scale)).replace(/z/gi,t.z/this.scale)).replace(/rotation/gi,t.rotation)).replace("'","").replace(",",".")).indexOf(";")&&(i+=";"),i},E2DEditor.prototype.getCustomPropertyFormula=function(e,t,i){var n=e;for(var o in i.custom){var s=i.custom[o];s&&(n=n.replace(new RegExp(o+".value","gi"),s))}return-1===(n=(n=(n=(n=(n=(n=(n=(n=(n=n.replace(/value/gi,t)).replace(/width/gi,i.width)).replace(/height/gi,i.height)).replace(/depth/gi,i.depth)).replace(/x/gi,i.x)).replace(/y/gi,i.y)).replace(/z/gi,i.z)).replace(/rotation/gi,i.rotation)).replace("'","").replace(",",".")).indexOf(";")&&(n+=";"),n},E2DEditor.prototype.getDefaultValueForCustomProperty=function(e){if(e.hasOwnProperty("UIDefault")){var t=e.UIDefault;return isNaN(t)?t:isNaN(parseFloat(t))?t:e.hasOwnProperty("UINoConvert")?t:E2DUtils.round(this.convertPixelsToUserData(t),this.numberOfDecimal)}if(e.hasOwnProperty("UIDefaultNoConvert"))return e.UIDefaultNoConvert;if(e.hasOwnProperty("UIType")){if("number"===e.UIType.toLowerCase())return 0;if("text"===e.UIType.toLowerCase())return""}for(var i in e)if("UIType"!==i&&"UIDefault"!==i&&"UIDefaultNoConvert"!==i&&"UINoConvert"!==i&&"UIFormula"!==i&&"UIReadOnly"!==i&&"UIDisabled"!==i)return isNaN(i)?i:isNaN(parseFloat(i))?i:e.hasOwnProperty("UINoConvert")?i:E2DUtils.round(this.convertPixelsToUserData(i),this.numberOfDecimal);return"undefined"},E2DEditor.prototype.appendPageAttribute=function(e,t){this.renderer.appendPageAttribute(e,t)},E2DEditor.prototype.setShapeEvents=function(e){e&&(e=e.toLowerCase(),this.events.inserted=-1!==e.indexOf("inserted"),this.events.pasted=-1!==e.indexOf("pasted"),this.events.removed=-1!==e.indexOf("removed"),this.events.linked=-1!==e.indexOf("linked"),this.events.stretched=-1!==e.indexOf("stretched"),this.events.rotated=-1!==e.indexOf("rotated"),this.events.regrouped=-1!==e.indexOf("regrouped"),this.events.doubleclick=-1!==e.indexOf("doubleclick"),this.events.polyinserted=-1!==e.indexOf("polyinserted"))},E2DEditor.prototype.setShapeLibrary=function(e,t,i,n){e=e||"DefaultLibrary",this.language=n||"en",this.shapeLibraryList=e.split(",");for(var o=0,s=this.shapeLibraryList.length;o<s;o++)this.shapeLibraryList[o]=this.shapeLibraryList[o].trim();if(t){this.shapeLibraryHideList=t.split(",");for(var r=0,a=this.shapeLibraryHideList.length;r<a;r++)this.shapeLibraryHideList[r]=this.shapeLibraryHideList[r].trim()}if(i){this.shapeLibraryOpenList=i.split(",");for(var l=0,h=this.shapeLibraryOpenList.length;l<h;l++)this.shapeLibraryOpenList[l]=this.shapeLibraryOpenList[l].trim()}this.loadShapeLibrary()},E2DEditor.prototype.loadShapeLibrary=function(){this.libraryCategories=[],this.libraryClasses={},this.libraryLanguage={},this.libraryProperties={},this.libraryCategoriesLoaded=$.Deferred(),this.libraryClassesLoaded=$.Deferred(),this.libraryLanguageLoaded=$.Deferred(),this.renderer.initSystemShapes(this.shapeLibraryList),this.renderer3d&&this.renderer3d.initSystemShapes(this.shapeLibraryList);for(var e=69,t=0,i=this.shapeLibraryList.length;t<i;t++)e=this.loadLibraryCategoriesSeq(this.shapeLibraryList[t],e);var n=this.loadLibraryClasses(this.shapeLibraryList[0]),o=this.loadLibraryLanguage(this.shapeLibraryList[0],this.language);$.when(e,n,o).done(function(){E2DGlobals.e2d.libraryLoaded.resolve()})},E2DEditor.prototype.loadLibraryCategoriesSeq=function(e,t){var i=$.Deferred();return $.when(t).done(function(){var t=E2DGlobals.e2d.loadLibraryCategories(e);t?t.done(function(e){i.resolve(e)}):i.resolve()}),i.promise()},E2DEditor.prototype.loadLibraryCategories=function(e){var t=$.Deferred(),i=this;return this.renderer.loadJSON(e+"/shapes/categories.txt",this).done(function(n){i.setLibraryCategoriesAsync(e,n,t)}),t.promise()},E2DEditor.prototype.setLibraryCategoriesAsync=function(e,t,i){t=t.filter(e=>!e.hideName),this.forceLibraryIdInCategories(e,t),this.libraryCategories=$.merge(this.libraryCategories,t),i&&i.resolve()},E2DEditor.prototype.loadLibraryClasses=function(e){var t=$.Deferred(),i=this;return this.renderer.loadJSON(e+"/shapes/classes.txt",this).done(function(e){i.setLibraryClassesAsync(e,t)}),t.promise()},E2DEditor.prototype.setLibraryClassesAsync=function(e,t){this.libraryClasses=e,t&&t.resolve()},E2DEditor.prototype.forceLibraryIdInCategories=function(e,t){for(var i=0,n=t.length;i<n;i++){var o=t[i];o.id=e+"|"+o.id,o.items&&o.items.length>0&&this.forceLibraryIdInCategories(e,o.items)}},E2DEditor.prototype.forceLibraryIdInPalettes=function(e,t){},E2DEditor.prototype.loadLibraryLanguage=function(e,t){var i=$.Deferred(),n=this;return this.renderer.loadJSON(e+"/shapes/language_"+t+".txt",this).done(function(e){n.setLibraryLanguageAsync(e,i)}),i.promise()},E2DEditor.prototype.setLibraryLanguageAsync=function(e,t){this.libraryLanguage=e,t&&t.resolve()},E2DEditor.prototype.hideShapeLibraryCategories=function(){},E2DEditor.prototype.hideShapeLibraryPaletteItems=function(e){if(this.shapeLibraryHideList&&0!==this.shapeLibraryHideList.length){var t=this;(e?$(e).find(".paletteItem img"):$(".paletteItem img")).each(function(){E2DUtils.isStringInList(t.shapeLibraryHideList,this.id)&&$(this).parent().parent().css("display","none")})}},E2DEditor.prototype.getCategory=function(e,t){for(var i=null,n=0,o=(t=t||this.libraryCategories).length;n<o;n++){if(t[n].id===e){i=t[n];break}if(t[n].items&&t[n].items.length>0&&(i=this.getCategory(e,t[n].items)))break}return i},E2DEditor.prototype.showShapeLibraryPaletteOnTree=function(e,t){var i=this,n=e.id.split("|");this.renderer.loadBASE(n[0]+"/shapes/palettes/"+n[1]+".xml",this).done(function(o){i.showShapeLibraryPaletteOnTreeAsync(n[0],n[1],o,e,t)})},E2DEditor.prototype.showShapeLibraryPaletteOnTreeAsync=function(e,t,i,n,o){n.loaded=!0,this.libraryCategoriesTree.AddNewNode(o,i),this.hideShapeLibraryPaletteItems(o),$("li[nodeid='"+n.id+"'] .paletteItem").each(function(){var t=$(this);t.draggable({appendTo:"body",helper:function(e){return $(e.currentTarget).children("div:nth-child(1)").clone()},cursor:"move",cursorAt:{left:25},delay:100,zIndex:1e3}).on("vmouseover",function(){$(this).addClass("paletteItemOver")}).on("vmouseout",function(){$(this).removeClass("paletteItemOver")});var i=t.find("img"),n=i.attr("id");i.attr("id",e+"|"+n);var o=i.attr("shortcutFor");o&&i.attr("shortcutFor",e+"|"+o)})},E2DEditor.prototype.showShapeLibraryCategoriesOnTree=function(e,t){var i=this.getCategory(e);i&&i.hasShapes&&!i.loaded&&this.showShapeLibraryPaletteOnTree(i,t)},E2DEditor.prototype.autocompleteLibraryLayers=function(e,t){const i=new RegExp("^"+$.ui.autocomplete.escapeRegex(e.term),"i");t(Object.keys(this.libraryLayers).filter(function(e){return i.test(e)}))},E2DEditor.prototype.setLibraryLayers=function(e){e&&Object.keys(e).length>0&&(this.libraryLayers=e)},E2DEditor.prototype.updateLibraryLayers=function(e){e&&!this.libraryLayers[e]&&(this.libraryLayers[e]={name:e,visible:!0})},E2DEditor.prototype.checkTranslation=function(e){return e&&e.startsWith("L{")&&e.endsWith("}")?this.translate(e.substring(2,e.length-1)):e},E2DEditor.prototype.translate=function(e){if(!this.libraryLanguage)return"???";var t=this.libraryLanguage[e];return t||"{"+e+"}"},E2DEditor.prototype.clearSystemShapes=function(){this.unselect(),this.clearConnectionPoints(),this.hideSmartLineMiddleConnectionPoints(),this.hideSmartLineOrthoConnectionPoints(),this.renderer.hideSystemShapes()},E2DEditor.prototype.removeSystemShapes=function(){this.unselect(),this.clearConnectionPoints(),this.removeConnectionPoints(),this.hideSmartLineMiddleConnectionPoints(),this.hideSmartLineOrthoConnectionPoints(),this.renderer.removeSystemShapes()},E2DEditor.prototype.getLinkClass=function(e,t){var i="",n=this.insertedShapes.getShapeById(e);if(n){i=n.linkClass;var o=this.getConnectionPointFromPropertiesBySource(n.getFullSource(),t);o&&o.linkClass&&(i=o.linkClass)}return i},E2DEditor.prototype.getLinkClassHandler=function(e){if(!e)return null;var t=this.libraryClasses.links;if(!t)return null;for(var i=e.split(","),n=0,o=i.length;n<o;n++)for(var s=i[n].trim(),r=0,a=t.length;r<a;r++){var l=t[r];if(l.id.trim()===s&&!$.isEmptyObject(l.handler))return l.handler}return null},E2DEditor.prototype.getLinkClassTarget=function(e){if(!e)return null;var t=this.libraryClasses.links;if(!t)return null;for(var i="",n=e.split(","),o=0,s=n.length;o<s;o++)for(var r=n[o].trim(),a=0,l=t.length;a<l;a++){var h=t[a];h.id.trim()===r&&h.targetClass&&(i+=","+h.targetClass)}return i},E2DEditor.prototype.getCommonLinkClassObj=function(e,t){var i=E2DUtils.getCommonClass(e,t);return this.getLinkClassObj(i)},E2DEditor.prototype.getLinkClassObj=function(e){if(!e)return null;var t=this.libraryClasses.links;if(!t)return null;for(var i=e.split(","),n=0,o=i.length;n<o;n++)for(var s=i[n].trim(),r=0,a=t.length;r<a;r++){var l=t[r];if(l.id.trim()===s)return l}return null},E2DEditor.prototype.getEventClass=function(e,t){if(!e||!t)return null;e=e.toLowerCase();for(var i=t.split(","),n=0,o=i.length;n<o;n++)for(var s=i[n].trim(),r=0,a=this.libraryClasses.events.length;r<a;r++){var l=this.libraryClasses.events[r];if(l.id.trim()===s&&l.types)if(l.types.indexOf(e)>=0)return s}return""},E2DEditor.prototype.getEventClassHandler=function(e,t){if(!e||!t)return null;e=e.toLowerCase();for(var i=t.split(","),n=0,o=i.length;n<o;n++)for(var s=i[n].trim(),r=0,a=this.libraryClasses.events.length;r<a;r++){var l=this.libraryClasses.events[r];if(l.id.trim()===s&&l.types)if(l.types.indexOf(e)>=0&&!$.isEmptyObject(l.handler))return l.handler}return null},E2DEditor.prototype.getEventHandler=function(e,t){if(!e)return null;e=e.toLowerCase();var i=null,n=this.libraryProperties[t];return n&&(n.eventHandlers&&((i=n.eventHandlers[e])&&!$.isEmptyObject(i)||(i=n.eventHandlers.generic)),i&&!$.isEmptyObject(i)||(i=this.getEventClassHandler(e,n.eventClass))),i},E2DEditor.prototype.getEventHandlerByShapeId=function(e,t){var i=this.insertedShapes.getShapeById(t);if(i&&this.getEventClass(e,i.eventClass))return this.getEventHandler(e,i.getFullSource());return null},E2DEditor.prototype.getEventArgumentByShapeId=function(e,t,i){var n=this.insertedShapes.getShapeById(t);if(n){var o=this.getEventClass(e,n.eventClass);if(o)return new E2DEventArgument(o,this.getEventHandler(e,n.getFullSource()),null,n.id,n.group,i)}return null},E2DEditor.prototype.fireLinkedEvent=function(e,t){var i=this.insertedShapes.getConnectionShape(e.id,"from"),n=this.insertedShapes.getShapeById(i.shapeID);if(n){var o=this.insertedShapes.getConnectionShape(e.id,"to"),s=this.insertedShapes.getShapeById(o.shapeID);if(s){var r=this.getLinkClass(i.shapeID,i.pointID),a=this.getEventClass("LINKED",n.eventClass),l=this.getLinkClass(o.shapeID,o.pointID),h=(this.getEventClass("LINKED",s.eventClass),[]);if(a){var d=E2DUtils.getCommonClass(r,l),c=this.getLinkClassHandler(d);if(d&&c)h[h.length]=new E2DEventArgument(d,c,i.pointID,n.id,n.group),h[h.length]=new E2DEventArgument(d,c,o.pointID,s.id,s.group);else{var u=this.getEventHandler("LINKED",n.getFullSource()),p=this.getEventHandler("LINKED",s.getFullSource());h[h.length]=new E2DEventArgument(a,u,i.pointID,n.id,n.group),h[h.length]=new E2DEventArgument(a,p,o.pointID,s.id,s.group)}}if(t){var g=this;$.when(t).done(function(){g.fireLinkedEventAsync(h)})}else this.fireLinkedEventAsync(h)}}},E2DEditor.prototype.fireLinkedEventAsync=function(e){this.events.linked&&e.length>0&&E2DEvents.doSubmitEvent("OnEditor2DLinked",e,1,"urLinkShapes")},E2DEditor.prototype.toPng=function(){var e=document.getElementById("SVG_ROOT");return e?(new Converter).svgToPng(e,$("#_pageWidth").val(),$("#_pageHeight").val(),this.zoom):null},E2DEvents={skipMouseUp:!1,mouseDown:{x:0,y:0},touchDown:{x:0,y:0},touchStarted:0,shapeMouseOver:null,active_connector:null,active_connector_qp:[],prev_connector:null,connector_z:null,dragStarted:!1,lineStarted:!1,polylineStarted:!1,autoScrollIntervalID:null,autoScrollIntervalDirection:null,autoScrollIntervalObject:null,prevent:function(e){e.stopPropagation&&e.stopPropagation(),e.preventDefault&&e.preventDefault(),e.returnValue=!1},autoScroll:function(){var e=E2DGlobals.e2d;if(E2DEvents.dragStarted){var t=e.getScroll();switch(E2DEvents.autoScrollIntervalDirection){case"LEFT":t.x>25?(e.setScroll(t.x-25,null),e.fineMove(25,0,0,0)):(e.setScroll(0,null),e.fineMove(t.x,0,0,0));break;case"RIGHT":e.setScroll(t.x+25,null),e.fineMove(0,25,0,0);break;case"UP":t.y>25?(e.setScroll(null,t.y-25),e.fineMove(0,0,25,0)):(e.setScroll(null,0),e.fineMove(0,0,t.y,0));break;case"DOWN":e.setScroll(null,t.y+25),e.fineMove(0,0,0,25);break;default:E2DEvents.autoScrollIntervalID&&(clearInterval(E2DEvents.autoScrollIntervalID),E2DEvents.autoScrollIntervalID=null)}}else E2DEvents.autoScrollIntervalID&&(clearInterval(E2DEvents.autoScrollIntervalID),E2DEvents.autoScrollIntervalID=null)},autoScrollResize:function(){if(E2DEvents.autoScrollIntervalObject){var e=E2DGlobals.e2d,t=e.getScroll(),i=e.renderer.isConnector(E2DEvents.autoScrollIntervalObject);switch(E2DEvents.autoScrollIntervalDirection){case"LEFT":t.x>25?(e.setScroll(t.x-25,null),i?e.fineMoveLine(E2DEvents.autoScrollIntervalObject,-25,0):e.fineResize(E2DEvents.autoScrollIntervalObject,-25,!0,!1,!1)):(e.setScroll(0,null),i?e.fineMoveLine(E2DEvents.autoScrollIntervalObject,-t.x,0):e.fineResize(E2DEvents.autoScrollIntervalObject,-t.x,!0,!1,!1));break;case"RIGHT":e.setScroll(t.x+25,null),i?e.fineMoveLine(E2DEvents.autoScrollIntervalObject,25,0):e.fineResize(E2DEvents.autoScrollIntervalObject,25,!0,!0,!1);break;case"UP":t.y>25?(e.setScroll(null,t.y-25),i?e.fineMoveLine(E2DEvents.autoScrollIntervalObject,0,-25):e.fineResize(E2DEvents.autoScrollIntervalObject,-25,!1,!1,!1)):(e.setScroll(null,0),i?e.fineMoveLine(E2DEvents.autoScrollIntervalObject,0,-t.y):e.fineResize(E2DEvents.autoScrollIntervalObject,-t.y,!1,!1,!1));break;case"DOWN":e.setScroll(null,t.y+25),i?e.fineMoveLine(E2DEvents.autoScrollIntervalObject,0,25):e.fineResize(E2DEvents.autoScrollIntervalObject,25,!1,!1,!0);break;default:E2DEvents.autoScrollIntervalID&&(clearInterval(E2DEvents.autoScrollIntervalID),E2DEvents.autoScrollIntervalID=null,E2DEvents.autoScrollIntervalObject=null)}}else E2DEvents.autoScrollIntervalID&&(clearInterval(E2DEvents.autoScrollIntervalID),E2DEvents.autoScrollIntervalID=null)},trapDefaultKeys:function(e){if(8===("number"==typeof(e=e||window.event).which?e.which:e.keyCode)){var t=e.srcElement?e.srcElement:e.target;if(!t)return!1;if(!$(t).is('input[type="text"]:focus, input[type=password]:focus, input[type=number]:focus, textarea:focus'))return!1}return!0},checkShapeOut:function(e,t){if(E2DEvents.lineStarted&&E2DEvents.shapeMouseOver){var i={x:e,y:t},n=E2DGlobals.e2d,o=n.renderer.getRotatedVerticesFromShape(E2DEvents.shapeMouseOver);E2DUtils.isPointInRect(i,o)||(n.removeConnectionPoints(E2DEvents.shapeMouseOver),E2DEvents.shapeMouseOver=null)}},selectAll:function(e){e.target&&(e=e.target),e.setSelectionRange?e.setSelectionRange(0,9999):e.select()},isDecimalNumberKey:function(e){46===e.keyCode||8===e.keyCode||9===e.keyCode||27===e.keyCode||13===e.keyCode||65===e.keyCode&&!0===e.ctrlKey||88===e.keyCode&&!0===e.ctrlKey||67===e.keyCode&&!0===e.ctrlKey||86===e.keyCode&&!0===e.ctrlKey||110===e.keyCode||190===e.keyCode||109===e.keyCode||189===e.keyCode||e.keyCode>=35&&e.keyCode<=40||(e.altKey||e.ctrlKey||e.shiftKey||(e.keyCode<48||e.keyCode>57)&&(e.keyCode<96||e.keyCode>105))&&E2DEvents.prevent(e)},isDecimalFormulaNumberKey:function(e){46===e.keyCode||8===e.keyCode||9===e.keyCode||27===e.keyCode||13===e.keyCode||65===e.keyCode&&!0===e.ctrlKey||88===e.keyCode&&!0===e.ctrlKey||67===e.keyCode&&!0===e.ctrlKey||86===e.keyCode&&!0===e.ctrlKey||110===e.keyCode||190===e.keyCode||109===e.keyCode||189===e.keyCode||107===e.keyCode||187===e.keyCode||106===e.keyCode||187===e.keyCode&&!0===e.shiftKey||55===e.keyCode&&!0===e.shiftKey||111===e.keyCode||56===e.keyCode&&!0===e.shiftKey||57===e.keyCode&&!0===e.shiftKey||e.keyCode>=35&&e.keyCode<=40||(e.altKey||e.ctrlKey||e.shiftKey||(e.keyCode<48||e.keyCode>57)&&(e.keyCode<96||e.keyCode>105))&&E2DEvents.prevent(e)},isNumberKey:function(e){46===e.keyCode||8===e.keyCode||9===e.keyCode||27===e.keyCode||13===e.keyCode||65===e.keyCode&&!0===e.ctrlKey||88===e.keyCode&&!0===e.ctrlKey||67===e.keyCode&&!0===e.ctrlKey||86===e.keyCode&&!0===e.ctrlKey||e.keyCode>=35&&e.keyCode<=40||(e.altKey||e.ctrlKey||e.shiftKey||(e.keyCode<48||e.keyCode>57)&&(e.keyCode<96||e.keyCode>105))&&E2DEvents.prevent(e)},onOverlayClick:function(){$(".ui-dialog").each(function(){const e=$(this).children(".ui-dialog-content");e.dialog("option","modal")&&e.dialog("close")})},openShapesNode:function(e,t){E2DGlobals.e2d.showShapeLibraryCategoriesOnTree(e,t)},checkWestLayout:function(){const e=E2DGlobals.e2dLayout.panes.west.layout(),t=document.querySelectorAll("#E2DWestSouthContainer div.panel[style*='block']");if(0===t.length)e.hide("south");else{const i=E2DGlobals.e2dLayout.state.west;"_toolbarShapeProperties"!==t[0].id&&"_toolbarPolylineProperties"!==t[0].id&&"_toolbarQuoteProperties"!==t[0].id&&i.isClosed&&E2DGlobals.e2dLayout.open("west"),e.show("south")}},showMessageDialog:function(e,t){$("#_dialogMessageText").text(t),$("#_dialogMessage").dialog({closeOnEscape:!0,closeText:"",draggable:!1,modal:!0,resizable:!1,title:e,buttons:{Ok:function(){$(this).dialog("close")}}})},onToolsDialogOpen:function(){$("#toolGroup").addClass("toolItemDisabled"),$("#toolUngroup").addClass("toolItemDisabled"),$("#toolText").removeClass("toolItemSelected"),$("#toolPolyline").removeClass("toolItemSelected"),$("#toolSmartLine").removeClass("toolItemSelected"),$("#toolLine").removeClass("toolItemSelected"),$("#toolLinkLine").removeClass("toolItemSelected"),$("#toolQuoteLine").removeClass("toolItemSelected"),$("#toolQuoteLineOff").removeClass("toolItemSelected"),$("#toolGridToggle").removeClass("toolItemSelected"),$("#toolWallsToggle").removeClass("toolItemSelected"),$("#toolShadowsToggle").removeClass("toolItemSelected"),$("#toolOrthoLine").removeClass("toolItemSelected"),$("#toolCurveLine").removeClass("toolItemSelected"),$("#toolCustomOrigin").removeClass("toolItemSelected"),$("#toolPaint").removeClass("toolItemSelected");const e=E2DGlobals.e2d;if($.isEmptyObject(e.groupInfo)){if(e.selected)if(e.renderer.isMultipleSelect(e.selected))$("#toolGroup").removeClass("toolItemDisabled");else{var t=e.insertedShapes.getShapeById(e.selected.id);if(t){var i=e.libraryProperties[t.getFullSource()];i&&1===i.shapeMode&&$("#toolUngroup").removeClass("toolItemDisabled")}}}else $("#toolGroup").removeClass("toolItemDisabled");switch(e.mode){case"text":$("#toolText").addClass("toolItemSelected");break;case"poly-line":$("#toolPolyline").addClass("toolItemSelected");break;case"smart-line":$("#toolSmartLine").addClass("toolItemSelected");break;case"line":$("#toolLine").addClass("toolItemSelected");break;case"link-line":$("#toolLinkLine").addClass("toolItemSelected");break;case"quote-line":$("#toolQuoteLine").addClass("toolItemSelected");break;case"ortho-line":$("#toolOrthoLine").addClass("toolItemSelected");break;case"curve-line":$("#toolCurveLine").addClass("toolItemSelected")}e.customOrigin&&$("#toolCustomOrigin").addClass("toolItemSelected"),e.highlightEqualShapes&&$("#toolPaint").addClass("toolItemSelected"),e.quotesOff&&$("#toolQuoteLineOff").addClass("toolItemSelected"),e.showGrid||$("#toolGridToggle").addClass("toolItemSelected"),e.show3dWalls||$("#toolWallsToggle").addClass("toolItemSelected"),e.show3dShadows||$("#toolShadowsToggle").addClass("toolItemSelected")},openToolsDialog:function(){$("#dlgTools").dialog("open")},closeToolsDialog:function(){$("#dlgTools").dialog("close"),$("#btnTools").blur()},openShapeProperties:function(){const e=E2DGlobals.e2d;e.selected&&!e.renderer.isConnector(e.selected)&&($("#_toolbarShapeProperties").css({display:"block"}),$("#_pinShape").checkboxradio("refresh"))},closeShapeProperties:function(){$("#_toolbarShapeProperties").css({display:"none"})},openPolylineProperties:function(){const e=E2DGlobals.e2d;e.selected&&e.renderer.isPolyline(e.selected)&&($("#_toolbarPolylineProperties").css({display:"block"}),E2DEvents.updatePolylinePropertiesButtons())},closePolylineProperties:function(){$("#_toolbarPolylineProperties").css({display:"none"})},updatePolylinePropertiesButtons:function(){0===$("#resize-from.lineTrackerResizeSelected").length&&0===$("#resize-to.lineTrackerResizeSelected").length?($("#btnAddPolylinePoint").removeClass("ui-state-disabled").attr("disabled",!1),$("#btnDeletePolylinePoint").addClass("ui-state-disabled").attr("disabled",!0)):($("#btnAddPolylinePoint").addClass("ui-state-disabled").attr("disabled",!0),$("#btnDeletePolylinePoint").removeClass("ui-state-disabled").attr("disabled",!1))},openQuoteProperties:function(){const e=E2DGlobals.e2d;e.selected&&e.renderer.isQuoteLine(e.selected)&&$("#_toolbarQuoteProperties").css({display:"block"})},closeQuoteProperties:function(){$("#_toolbarQuoteProperties").css({display:"none"})},enableQuoteDriving:function(e,t){$("#_qDriving").checkboxradio({disabled:t}).checkboxradio("refresh"),t||!e?$("#_qValue").addClass("ui-state-disabled").attr("disabled",!0):$("#_qValue").removeClass("ui-state-disabled").attr("disabled",!1)},onDrivingQuoteChanged:function(){const e=$(this),t=e.prop("checked"),i=e.checkboxradio("option","disabled");E2DEvents.enableQuoteDriving(t,i)},openInfoDialog:function(){E2DEvents.hideProperties(),$("#_toolbarInfo").css({display:"block"})},closeInfoDialog:function(){$("#_toolbarInfo").css("display","none")},openHelpDialog:function(){const e=E2DGlobals.e2d;e.setMode("select");const t=e.getUrlForHelp();t&&($("#_toolbarHelp").css({width:e.getToolbarWidth()}).toggle(),$("#iframeHelp").attr("src",t))},closeHelpDialog:function(){$("#_toolbarHelp").css("display","none")},openLayersDialog:function(){E2DEvents.hideProperties();const e=$("#_toolbarLayersToggles");for(let t in E2DGlobals.e2d.libraryLayers){const i=$("<label>").attr({class:"layer-toggle-label",for:t}).text(t),n=$("<input>").attr({type:"checkbox",id:t,name:t,class:"toggle layer-toggle"}).prop("checked",E2DGlobals.e2d.libraryLayers[t].visible).on("click",E2DEvents.selectLayer);e.append(i).append(n)}e.controlgroup({direction:"vertical"}),$("#_toolbarLayers").css("display","block")},closeLayersDialog:function(){E2DEvents.openShapeProperties(),$("#_toolbarLayers").css("display","none"),$("#_toolbarLayersToggles").empty(),E2DUtils.safeBlur()},selectLayer:function(e){console.log("SelectLayer: ",e);const t=E2DGlobals.e2d,i=e.target.id,n=e.target.checked;Object.values(t.insertedShapes.insertedShapeMap).filter(function(e){return e.layer&&e.layer===i}).forEach(function(e){const i=document.getElementById(e.id);t.renderer.setLayer(i,{visible:n})})},openSnapshotDialog:function(){E2DEvents.hideProperties();const e=E2DGlobals.e2d.renderer3d?"inline-block":"none";$("#_snapshot3D").css("display",e),$("#_toolbarSnapshot").css("display","block"),$("#_snapshotDownload").css("display","none").attr("href","")},closeSnapshotDialog:function(){E2DEvents.openShapeProperties(),$("#_toolbarSnapshot").css("display","none"),$("#_snapshotDownload").attr("href",""),E2DUtils.safeBlur()},createSnapshot2D:function(e){const t=E2DGlobals.e2d;var i,n,o,s,r,a;if(e){const e=t.container.parent();i=e.scrollLeft(),n=e.scrollTop(),o=E2DGlobals.e2dLayout.state.center.innerWidth,s=E2DGlobals.e2dLayout.state.center.innerHeight,r="snapshot2DScreen.png",a=t.zoom}else{const e=t.renderer.getSVGPageSize();i=0,n=0,o=e.width,s=e.height,r="snapshot2DPage.png"}return $("#_snapshotDownload").css("display","none").attr("href",""),(new Converter).svgToPng(t.renderer.cloneSVGRoot(),i,n,o,s,a,e).done(function(e){$("#_snapshotDownload").css("display","block").attr("href",e).attr("download",r)}),!1},createSnapshot3D:function(){const e=E2DGlobals.e2d,t=new Converter;$("#_snapshotDownload").css("display","none").attr("href",""),t.canvasToPng(e.renderer3d.renderer.domElement).done(function(e){$("#_snapshotDownload").css("display","block").attr("href",e).attr("download","snapshot3D.png")})},onGridPatternGaplessChanged:function(){$("#gapless").prop("checked")?($("#xGap").addClass("toolItemDisabled").prop("disabled",!0),$("#yGap").addClass("toolItemDisabled").prop("disabled",!0),$("#linked").removeClass("toolItemDisabled").prop("disabled",!1)):($("#xGap").removeClass("toolItemDisabled").prop("disabled",!1),$("#yGap").removeClass("toolItemDisabled").prop("disabled",!1),$("#linked").addClass("toolItemDisabled").prop("checked",!1).prop("disabled",!0))},openGridPatternDialog:function(){const e=E2DGlobals.e2d;e.selected&&e.selected.id!==e.ORIGIN_ID&&e.selected.id!==e.CUSTOM_ORIGIN_ID&&(E2DEvents.hideProperties(),$("#_toolbarCreateGridPattern").css({display:"block"}))},closeGridPatternDialog:function(){E2DEvents.openShapeProperties(),$("#_toolbarCreateGridPattern").css("display","none"),E2DUtils.safeBlur()},doCreateGridPattern:function(){const e=$("#xItems").val(),t=$("#xGap").val(),i=$("#yItems").val(),n=$("#yGap").val(),o=$("#gapless").prop("checked"),s=$("#linked").prop("checked");(e&&t&&i&&n||e&&i&&(o||s))&&E2DGlobals.e2d.createGridPattern(e,t,i,n,o,s),E2DEvents.closeGridPatternDialog()},openGroupDialog:function(){$("#toolGroup").hasClass("toolItemDisabled")||(E2DEvents.hideProperties(),$("#_toolbarGroup").css({display:"block"}))},closeGroupDialog:function(){E2DEvents.openShapeProperties(),$("#_toolbarGroup").css("display","none"),E2DUtils.safeBlur()},doGroup:function(){const e=$("#gId").val(),t=$("#gName").val()||e,i=$("#gDescription").val();E2DEvents.closeGroupDialog(),e&&t&&E2DGlobals.e2d.group(e,t,i)},editConnectionPoints:function(){E2DGlobals.e2d.editConnectionPoints()},openReGroupDialog:function(){$("#toolGroup").hasClass("toolItemDisabled")||(E2DEvents.hideProperties(),$("#_toolbarReGroup").css({display:"block"}))},closeReGroupDialog:function(){E2DEvents.openShapeProperties(),$("#_toolbarReGroup").css("display","none"),E2DUtils.safeBlur()},doReGroup:function(){const e=$("input:radio[name='rdReGroup']:checked").val();E2DEvents.closeReGroupDialog(),E2DGlobals.e2d.regroup(e)},openQuickPickDialog:function(){const e=E2DGlobals.e2d;let t=E2DEvents.mouseDown.x-15,i=E2DEvents.mouseDown.y-15;t=t<0?0:t,i=i<0?0:i;const n={};$("#_toolbarQuickPick").css({display:"block",left:t,top:i});const o=$("#qpAvailableShapes").empty().append($("<option value='--'>"));for(let t=0,i=e.overlappingGhosts.length;t<i;t++){const i=e.overlappingGhosts[t],s=e.insertedShapes.getShapeById(i.id),r=e.libraryProperties[s.getFullSource()];n[s.id]||(n[s.id]=E2DUtils.toHexColour(s.id+"#"+s.getFullSource()));let a=s.name?e.checkTranslation(s.name):"";r.family&&(a+=" - "+e.checkTranslation(r.family)),e.enable3d&&(a+=" - z = "+s.z);const l=$("<option>").css("color","#"+n[s.id]).attr("value",s.id).text(a);e.selected.id===s.id&&l.addClass("qpSelected"),o.append(l)}},closeQuickPickDialog:function(){$("#_toolbarQuickPick").css("display","none"),E2DUtils.safeBlur()},onQuickPickChanged:function(e){if(!e||"--"===e)return;const t=document.getElementById(e);E2DGlobals.e2d.bringToFront(t,!1),E2DUtils.safeBlur()},openQuickPickCPDialog:function(e){if(!e||0===e.length)return;const t=E2DGlobals.e2d,i=E2DEvents.active_connector_qp[0],n=t.container.offset();let o=n.left+i.x*t.zoom-15,s=n.top+i.y*t.zoom-15;o=o<0?0:o,s=s<0?0:s,$("#_toolbarQuickPickCP").css({display:"block",left:o,top:s});let r="quote-line"===t.mode;!r&&t.selected&&(r=t.insertedShapes.getShapeById(t.selected.id).isQuoteLine());const a={},l=$("#qpAvailableConnectionPoints").empty().append($("<option value='--'>"));for(let i=0,n=e.length;i<n;i++){const n=e[i],o=t.insertedShapes.getShapeById(n.shapeId);a[o.id]||(a[o.id]=E2DUtils.toHexColour(o.id+"#"+o.getFullSource()+"#"+o.name));let s=o.name?t.checkTranslation(o.name):"";if(s+=" - "+(n.label?t.checkTranslation(n.label):n.cpId),!r){let e=1*o.rotation+1*n.direction;isNaN(e)||(e%=360,s=E2DUtils.arrowFromRotation(e)+" "+s)}const h=$("<option value='"+n.id+"' style='color: #"+a[o.id]+"'>"+s+"</option>").data(n);l.append(h)}},closeQuickPickCPDialog:function(e){e&&(E2DEvents.active_connector=null,E2DEvents.active_connector_qp=[],E2DEvents.prev_connector=null),$("#_toolbarQuickPickCP").css("display","none"),E2DUtils.safeBlur()},onQuickPickCPChanged:function(e){if(!e)return;if(!e.value||"--"===e.value)return;const t=e.options[e.selectedIndex];if(!t)return;const i=$(t).data();if(!i)return;const n=E2DGlobals.e2d;n.enable3d&&"link-line"===n.mode&&(i.zMin||i.zMax||i.zStep)?($("label[for='qpZ']").css("display","block"),$("#qpZ").css("display","block").val("")):($("label[for='qpZ']").css("display","none"),$("#qpZ").css("display","none").val(""),E2DEvents.active_connector=i.id,E2DEvents.prev_connector?n.connectLine(E2DEvents.prev_connector,E2DEvents.active_connector,E2DEvents.active_connector_qp,E2DEvents.connector_z):(E2DEvents.prev_connector=i.id,n.createLine(n.mode,E2DEvents.mouseDown.x,E2DEvents.mouseDown.y,E2DEvents.active_connector)),E2DUtils.safeBlur(),E2DEvents.closeQuickPickCPDialog())},onQuickPickCPZ:function(e){if(13===e.keyCode){const e=document.getElementById("qpAvailableConnectionPoints");if(!e)return;const t=e.options[e.selectedIndex];if(!t)return;const i=$(t).data();if(!i)return;i.userZ=1*$("#qpZ").val(),E2DEvents.active_connector=i.id,E2DEvents.connector_z=i,E2DEvents.prev_connector?E2DGlobals.e2d.connectLine(E2DEvents.prev_connector,E2DEvents.active_connector,E2DEvents.active_connector_qp,E2DEvents.connector_z):E2DEvents.prev_connector=i.id,E2DUtils.safeBlur(),E2DEvents.closeQuickPickCPDialog()}},hideProperties:function(){E2DEvents.closeShapeProperties(),E2DEvents.closePolylineProperties(),E2DEvents.closeQuoteProperties()},hideExtraToolbars:function(){E2DEvents.closeGridPatternDialog(),E2DEvents.closeReGroupDialog(),E2DEvents.closeQuickPickDialog(),E2DEvents.closeQuickPickCPDialog(),E2DEvents.closeLayersDialog(),E2DEvents.closeSnapshotDialog(),E2DEvents.closeInfoDialog(),E2DEvents.closeHelpDialog()},skipUnselect:function(){return"block"===$("#_toolbarQuickPick").css("display")||"block"===$("#_toolbarQuickPickCP").css("display")},noFocusOnDialog:function(){$("div.ui-dialog button.ui-button").focus()},onUpdateShape:function(){E2DGlobals.e2d.updateShape()},onUpdateQuote:function(){E2DGlobals.e2d.updateQuote()},onUpdatePolyline:function(){E2DGlobals.e2d.updatePolyline()},onAddPolylinePoint:function(){E2DGlobals.e2d.addPolylinePoint()},onDeletePolylinePoint:function(){E2DGlobals.e2d.deletePolylinePoint()},doSubmit:function(e){E2DGlobals.e2d.setMode("select"),E2DGlobals.e2d.isShapesLoadPending()||"function"==typeof RDSubmit&&(RDPageLock(),e=e||"Unknown",E2DGlobals.exportImage2D(),E2DGlobals.exportImage3D(),$.when(E2DGlobals.e2d.image2DExported,E2DGlobals.e2d.image3DExported).done(function(){const t=E2DGlobals.getPreferencesData(),i=E2DGlobals.getShapesData(!1,!1,!0),n=E2DGlobals.getDrawingData(),o=E2DGlobals.getViewportData(),s=E2DGlobals.getShapePropertyData();E2DGlobals.disposeEditor(!0),RDSubmit(e,"[SUBMIT]",t,i,n,o,s,"","")}))},doSubmitAsync:function(){if(E2DGlobals.e2d.setMode("select"),!E2DGlobals.e2d.isShapesLoadPending()&&"function"==typeof RDSubmitAsync){var e=E2DGlobals.getViewportData(!0),t=E2DGlobals.getShapesData(!0,!0);RDSubmitAsync(e,t)}},doSubmitImageAsync:function(e,t){if(E2DGlobals.e2d.setMode("select"),!E2DGlobals.e2d.isShapesLoadPending())return"function"==typeof RDSubmitImageAsync?RDSubmitImageAsync(e,t):null},doSubmitEvent:function(e,t,i,n){if("function"!=typeof RDSubmit)return;const o=E2DGlobals.e2d;if(o.setMode("select"),!o.isShapesLoadPending()){RDPageLock();var s=E2DGlobals.getPreferencesData(),r=E2DGlobals.getShapesData(!1,!0),a=E2DGlobals.getViewportData(),l=E2DGlobals.getShapePropertyData(),h=JSON.stringify(t);E2DGlobals.disposeEditor(),o.setUndoRedoNextInfo(i,n),RDSubmit("EVENT|"+e,"[SUBMIT]",s,r,"",a,l,"",h)}},doSubmitSelection:function(e,t,i){if("function"!=typeof RDSubmit)return;const n=E2DGlobals.e2d;if(n.setMode("select"),n.isShapesLoadPending())return;if(!n.selected)return;var o=null,s=[];if(n.renderer.isMultipleSelect(n.selected))for(var r=n.multipleSelectShapes.getShapes(!0),a=0,l=r.length;a<l;a++)r[a].id!==n.ORIGIN_ID&&r[a].id!==n.CUSTOM_ORIGIN_ID&&(o=n.insertedShapes.getShapeById(r[a].id),s.push(o?o.getIdAndGroupInfo():r[a].id));else o=n.insertedShapes.getShapeById(n.selected.id),s.push(o?o.getIdAndGroupInfo():n.selected.id);const h=E2DGlobals.getPreferencesData(),d=E2DGlobals.getShapesData(!1,!0),c=E2DGlobals.getViewportData(),u=E2DGlobals.getShapePropertyData(),p=JSON.stringify(s);E2DGlobals.disposeEditor(),n.setUndoRedoNextInfo(t,i),RDSubmit("EVENT|"+e,"[SUBMIT]",h,d,"",c,u,p,"")},doAccept:function(){E2DGlobals.e2d.setMode("select"),E2DGlobals.e2d.isShapesLoadPending()||"function"==typeof RDSubmit&&(RDPageLock(),E2DGlobals.exportImage2D(),E2DGlobals.exportImage3D(),$.when(E2DGlobals.e2d.image2DExported,E2DGlobals.e2d.image3DExported).done(function(){const e=E2DGlobals.getPreferencesData(),t=E2DGlobals.getShapesData(!1,!1,!0),i=E2DGlobals.getDrawingData(),n=E2DGlobals.getViewportData(),o=E2DGlobals.getShapePropertyData();E2DGlobals.disposeEditor(!0),RDSubmit("OK","[SUBMIT]",e,t,i,n,o,"","")}))},doCancel:function(){E2DGlobals.e2d.setMode("select"),E2DGlobals.e2d.isShapesLoadPending()||"function"==typeof RDSubmit&&(E2DGlobals.disposeEditor(!0),RDSubmit("CANCEL","[CANCEL]"))},doSave:function(){E2DEvents.doSubmitEvent("OnEditor2DSave",null,-1)},doUndo:function(){E2DGlobals.e2d.undo()},doRedo:function(){E2DGlobals.e2d.redo()},doCut:function(){E2DGlobals.e2d.cut()},doCopy:function(){E2DGlobals.e2d.copy()},doPaste:function(){E2DGlobals.e2d.paste()},doDelete:function(){E2DGlobals.e2d.deleteSelection()},toggleZoomIn:function(){var e=E2DGlobals.e2d;"ZOOM_IN"===e.mode?e.setMode("select"):e.setMode("ZOOM_IN")},toggleZoomOut:function(){var e=E2DGlobals.e2d;"ZOOM_OUT"===e.mode?e.setMode("select"):e.setMode("ZOOM_OUT")},doZoomIn:function(){var e=E2DGlobals.e2d,t=e.zoom+e.zoomStep;e.setZoom(t)},doZoomOut:function(){var e=E2DGlobals.e2d,t=e.zoom-e.zoomStep;e.setZoom(t)},doZoomOrig:function(){var e=E2DGlobals.e2d;e.setMode("select"),e.setZoom(1)},doZoomFit:function(){E2DGlobals.e2d.fitZoom()},doZoomPage:function(){E2DGlobals.e2d.pageZoom()},doBtnSelectAction:function(){E2DGlobals.e2d.setMode("select")},doBtnToolsAction:function(){E2DGlobals.e2d.setMode("select"),E2DEvents.openToolsDialog()},doBtnToolItemAction:function(){E2DEvents.hideExtraToolbars();var e=$(this),t=E2DGlobals.e2d;switch(t.setMode("select"),e.attr("id")){case"btnToolPageDrag":$(".btnToolsOnToolbarActive").removeClass("btnToolsOnToolbarActive"),e.addClass("btnToolsOnToolbarActive"),t.setMode("PAGE_DRAG");break;case"btnToolText":$(".btnToolsOnToolbarActive").removeClass("btnToolsOnToolbarActive"),e.addClass("btnToolsOnToolbarActive"),t.setMode("text");break;case"btnToolSelectGroup":t.selectGroup();break;case"btnToolPolyLine":$(".btnToolsOnToolbarActive").removeClass("btnToolsOnToolbarActive"),e.addClass("btnToolsOnToolbarActive"),t.setMode("poly-line");break;case"btnToolLine":$(".btnToolsOnToolbarActive").removeClass("btnToolsOnToolbarActive"),e.addClass("btnToolsOnToolbarActive"),t.setMode("line");break;case"btnToolOrthoLine":$(".btnToolsOnToolbarActive").removeClass("btnToolsOnToolbarActive"),e.addClass("btnToolsOnToolbarActive"),t.setMode("ortho-line");break;case"btnToolCurveLine":$(".btnToolsOnToolbarActive").removeClass("btnToolsOnToolbarActive"),e.addClass("btnToolsOnToolbarActive"),t.setMode("curve-line");break;case"btnToolSmartLine":$(".btnToolsOnToolbarActive").removeClass("btnToolsOnToolbarActive"),e.addClass("btnToolsOnToolbarActive"),t.setMode("smart-line");break;case"btnToolQuoteLine":$(".btnToolsOnToolbarActive").removeClass("btnToolsOnToolbarActive"),e.addClass("btnToolsOnToolbarActive"),t.setMode("quote-line");break;case"btnToolQuoteLineOff":e.toggleClass("btnToolsOnToolbarActiveQuoteOff"),t.toggleQuotes();break;case"btnToolLinkLine":$(".btnToolsOnToolbarActive").removeClass("btnToolsOnToolbarActive"),e.addClass("btnToolsOnToolbarActive"),t.setMode("link-line");break;case"btnToolLinkLineCancel":E2DEvents.cancelLinkLine();break;case"btnToolGridPattern":E2DEvents.openGridPatternDialog();break;case"btnToolGridToggle":e.toggleClass("btnToolsOnToolbarActiveGridToggle"),t.enableGrid();break;case"btnToolWallsToggle":e.toggleClass("btnToolsOnToolbarActiveWallsToggle"),t.toggle3dWalls();break;case"btnToolShadowsToggle":e.toggleClass("btnToolsOnToolbarActiveShadowsToggle"),t.toggle3dShadows();break;case"btnToolSmartCopy":E2DEvents.doSubmitSelection("OnEditor2DSmartCopy",1,"urSmartCopy");break;case"btnToolCustomOrigin":e.toggleClass("btnToolsOnToolbarActiveCustomOrigin"),t.toggleCustomOrigin();break;case"btnToolPreview3D":t.togglePreview3D();break;case"btnToolPaint":e.toggleClass("btnToolsOnToolbarActivePaint"),t.toggleHighlightEqualShapes();break;case"btnToolSnapshot":E2DEvents.openSnapshotDialog()}},doToggleTVCategories:function(){E2DGlobals.e2dLayout.state.west.isClosed?E2DGlobals.e2dLayout.open("west"):E2DGlobals.e2dLayout.close("west")},doToolItemAction:function(){E2DEvents.hideExtraToolbars(),E2DEvents.closeToolsDialog();var e=$(this).attr("id"),t=E2DGlobals.e2d;switch(t.setMode("select"),e){case"toolSelectGroup":t.selectGroup();break;case"toolText":$("#btnTools").button({icons:{primary:"ui-icon-text"}}),$(".btnToolsOnToolbarActive").removeClass("btnToolsOnToolbarActive"),t.setMode("text");break;case"toolPolyline":$("#btnTools").button({icons:{primary:"ui-icon-line-poly"}}),$(".btnToolsOnToolbarActive").removeClass("btnToolsOnToolbarActive"),t.setMode("poly-line");break;case"toolSmartLine":$("#btnTools").button({icons:{primary:"ui-icon-line-smart"}}),$(".btnToolsOnToolbarActive").removeClass("btnToolsOnToolbarActive"),t.setMode("smart-line");break;case"toolLine":$("#btnTools").button({icons:{primary:"ui-icon-line-draw"}}),$(".btnToolsOnToolbarActive").removeClass("btnToolsOnToolbarActive"),t.setMode("line");break;case"toolLinkLine":$("#btnTools").button({icons:{primary:"ui-icon-line-link"}}),$(".btnToolsOnToolbarActive").removeClass("btnToolsOnToolbarActive"),t.setMode("link-line");break;case"toolLinkLineCancel":E2DEvents.cancelLinkLine();break;case"toolQuoteLine":$("#btnTools").button({icons:{primary:"ui-icon-line-quote"}}),$(".btnToolsOnToolbarActive").removeClass("btnToolsOnToolbarActive"),t.setMode("quote-line");break;case"toolQuoteLineOff":t.toggleQuotes();break;case"toolOrthoLine":$("#btnTools").button({icons:{primary:"ui-icon-ortho-draw"}}),$(".btnToolsOnToolbarActive").removeClass("btnToolsOnToolbarActive"),t.setMode("ortho-line");break;case"toolCurveLine":$("#btnTools").button({icons:{primary:"ui-icon-curve-draw"}}),$(".btnToolsOnToolbarActive").removeClass("btnToolsOnToolbarActive"),t.setMode("curve-line");break;case"toolBringForward":t.bringToFront();break;case"toolSendBack":t.sendToBack();break;case"toolConnectionPoint":t.addConnectionPoint();break;case"toolEditConnectionPoints":t.editConnectionPoints();break;case"toolGroup":$.isEmptyObject(t.groupInfo)?t.selected&&t.renderer.isMultipleSelect(t.selected)&&E2DEvents.openGroupDialog():E2DEvents.openReGroupDialog();break;case"toolUngroup":t.ungroup();break;case"toolPaint":t.toggleHighlightEqualShapes();break;case"toolSnapshot":E2DEvents.openSnapshotDialog();break;case"toolGridPattern":E2DEvents.openGridPatternDialog();break;case"toolGridToggle":t.toggleGrid();break;case"toolWallsToggle":t.toggle3dWalls();break;case"toolShadowsToggle":t.toggle3dShadows();break;case"toolSmartCopy":E2DEvents.doSubmitSelection("OnEditor2DSmartCopy",1,"urSmartCopy");break;case"toolCustomOrigin":t.toggleCustomOrigin();break;case"toolPreview3D":t.togglePreview3D();break;case"toolInfo":E2DEvents.openInfoDialog();break;case"toolHelp":E2DEvents.openHelpDialog();break;case"toolLayers":E2DEvents.openLayersDialog();break;case"toolUpload":E2DEvents.doSubmit("UPLOAD");break;case"toolDownload":E2DEvents.doSubmit("DOWNLOAD");break;case"toolRemoveBackground":t.removeBackground()}},onToolItemOver:function(){$(this).addClass("toolItemOver")},onToolItemOut:function(){$(this).removeClass("toolItemOver")},onTouchStart:function(e){var t=E2DGlobals.e2d;E2DEvents.touchStarted++;var i=e.originalEvent;if(2===i.touches.length){E2DEvents.prevent(e),t.unselect();var n=i.touches[0];E2DEvents.touchDown=t.getNewCoords(n.clientX,n.clientY,!0)}},onTouchMove:function(e){var t=e.originalEvent;if(2===t.touches.length&&(E2DEvents.prevent(e),Math.abs(t.scale-1)<.1)){var i=E2DGlobals.e2d,n=t.touches[0],o=i.getNewCoords(n.clientX,n.clientY,!1),s=E2DEvents.touchDown.x-o.x,r=E2DEvents.touchDown.y-o.y,a=i.getScroll();i.setScroll(a.x+s,a.y+r)}},onTouchEnd:function(e){E2DEvents.touchStarted--},onGestureEnd:function(e){E2DEvents.prevent(e),Math.abs(e.originalEvent.scale-1)>.5&&(e.originalEvent.scale>1?E2DEvents.doZoomIn():e.originalEvent.scale<1&&E2DEvents.doZoomOut())},onE3DViewChanged:function(e){const t=E2DGlobals.e2d;t.enable3d&&t.renderer3d&&t.renderer3d.changeViewMode(e)},onE3DBackgroundColorBeforeShow:function(e,t){E2DEvents.onE3DDirectionalLightMoveCancel();const i=E2DGlobals.e2d;if(i.enable3d&&i.renderer3d){const t=i.renderer3d.getBackgroundColor();$(e.target).spectrum("set",t)}},onE3DBackgroundColorChange:function(e,t){const i=E2DGlobals.e2d;i.enable3d&&i.renderer3d&&i.renderer3d.setBackgroundColor(t.toHexString())},onE3DAmbientLightColorBeforeShow:function(e,t){E2DEvents.onE3DDirectionalLightMoveCancel();const i=E2DGlobals.e2d;if(i.enable3d&&i.renderer3d){const t=i.renderer3d.getAmbientLightColor();$(e.target).spectrum("set",t)}},onE3DAmbientLightColorChange:function(e,t){const i=E2DGlobals.e2d;i.enable3d&&i.renderer3d&&i.renderer3d.setAmbientLightColor(t.toHexString())},onE3DHemiLightSkyColorBeforeShow:function(e,t){E2DEvents.onE3DDirectionalLightMoveCancel();const i=E2DGlobals.e2d;if(i.enable3d&&i.renderer3d){const t=i.renderer3d.getHemiLightSkyColor();$(e.target).spectrum("set",t)}},onE3DHemiLightSkyColorChange:function(e,t){const i=E2DGlobals.e2d;i.enable3d&&i.renderer3d&&i.renderer3d.setHemiLightSkyColor(t.toHexString())},onE3DHemiLightGroundColorBeforeShow:function(e,t){E2DEvents.onE3DDirectionalLightMoveCancel();const i=E2DGlobals.e2d;if(i.enable3d&&i.renderer3d){const t=i.renderer3d.getHemiLightGroundColor();$(e.target).spectrum("set",t)}},onE3DHemiLightGroundColorChange:function(e,t){const i=E2DGlobals.e2d;i.enable3d&&i.renderer3d&&i.renderer3d.setHemiLightGroundColor(t.toHexString())},onE3DSpotLightColorBeforeShow:function(e,t){E2DEvents.onE3DDirectionalLightMoveCancel();const i=E2DGlobals.e2d;if(i.enable3d&&i.renderer3d){const t=i.renderer3d.getSpotLightColor();$(e.target).spectrum("set",t)}},onE3DSpotLightColorChange:function(e,t){const i=E2DGlobals.e2d;i.enable3d&&i.renderer3d&&i.renderer3d.setSpotLightColor(t.toHexString())},onE3DDirectionalLightColorBeforeShow:function(e,t){E2DEvents.onE3DDirectionalLightMoveCancel();const i=E2DGlobals.e2d;if(i.enable3d&&i.renderer3d){const t=i.renderer3d.getDirectionalLightColor();$(e.target).spectrum("set",t)}},onE3DDirectionalLightColorChange:function(e,t){const i=E2DGlobals.e2d;i.enable3d&&i.renderer3d&&i.renderer3d.setDirectionalLightColor(t.toHexString())},onE3DDirectionalLightMove:function(e){$("#btn3DBackgroundColor").spectrum("hide"),$("#btn3DAmbientLightColor").spectrum("hide"),$("#btn3DDirectionalLightColor").spectrum("hide");const t=E2DGlobals.e2d;if(!t.enable3d||!t.renderer3d)return;const i=$("#_toolbar3DDirectionalLightMove");if(0!==i.length){if(i.hasClass("hidden")){t.renderer3d.showDirectionalLightHelper();const e=t.renderer3d.getDirectionalLightPosition();i.data("dl-ip",e),$("#tb3DDLM_X").val(e.x),$("#tb3DDLM_Y").val(e.y),$("#tb3DDLM_Z").val(e.z);const n=$(this).offset();i.css({top:n.top-i.height()-10,left:n.left}),i.removeClass("hidden"),$(document).on("click.dlmove",E2DEvents.onE3DDirectionalLightMoveCancel)}else E2DEvents.onE3DDirectionalLightMoveCancel();E2DEvents.prevent(e)}},onE3DDirectionalLightMoveClose:function(){const e=$("#_toolbar3DDirectionalLightMove");if(0===e.length)return;e.addClass("hidden"),e.data("dl-ip",null);const t=E2DGlobals.e2d;t.enable3d&&t.renderer3d&&t.renderer3d.hideDirectionalLightHelper()},onE3DDirectionalLightMoveOk:function(e){const t=E2DGlobals.e2d;if(t.enable3d&&t.renderer3d){const e={x:1*$("#tb3DDLM_X").val(),y:1*$("#tb3DDLM_Y").val(),z:1*$("#tb3DDLM_Z").val()};t.renderer3d.setDirectionalLightPosition(e)}E2DEvents.onE3DDirectionalLightMoveClose()},onE3DDirectionalLightMoveCancel:function(e){if(e&&e.target){if(E2DUtils.getParentWithID(e.target,"_toolbar3DDirectionalLightMove"))return}const t=E2DGlobals.e2d;if(t.enable3d&&t.renderer3d){const e=$("#_toolbar3DDirectionalLightMove").data("dl-ip");e&&t.renderer3d.setDirectionalLightPosition(e)}E2DEvents.onE3DDirectionalLightMoveClose(),$(document).off("click.dlmove")},onE3DDirectionalLightMoveChange:function(e){const t=E2DGlobals.e2d;if(t.enable3d&&t.renderer3d){const e={x:1*$("#tb3DDLM_X").val(),y:1*$("#tb3DDLM_Y").val(),z:1*$("#tb3DDLM_Z").val()};t.renderer3d.setDirectionalLightPosition(e)}},onResizeWindow:function(e){var t=E2DUtils.getWindowSize();$("#E2DContainer").css({width:t.width-1,height:t.height-1}),E2DGlobals.e2dLayout.resizeAll(),E2DEvents.onResizeToolbars(E2DGlobals.e2d.getToolbarWidth())},onCloseEastPanel:function(e){E2DGlobals.e2d.disposeE3DPreview()},onResizeEastPanel:function(e){var t=E2DGlobals.e2d;if(t.enable3d&&t.renderer3d){var i=E2DGlobals.e2dLayout.east.pane.width(),n=E2DGlobals.e2dLayout.east.pane.height();t.renderer3d.resize(i,n)}},onResizeToolbars:function(e){E2DEvents.onResizeToolbar("#_toolbarHelp",e)},onResizeToolbar:function(e,t){var i=$(e);"block"===i.css("display")&&i.css("width",t)},cancelLinkLine:function(){E2DGlobals.e2d.cancelLinkLine()},connectorActive:function(e){E2DEvents.connectorInactive(),e=$(e);var t=E2DGlobals.e2d.getOverlappingConnectionPoints(e.attr("id"));t&&t.length>1?(e.addClass("activeConnectorQP"),E2DEvents.active_connector_qp=t):(e.addClass("activeConnector"),E2DEvents.active_connector_qp=[]),E2DEvents.active_connector=e.attr("id")},connectorInactive:function(){if(E2DEvents.active_connector){var e=$("#"+E2DEvents.active_connector);E2DEvents.active_connector=null,E2DEvents.active_connector_qp=[],0!==e.length&&e.removeClass("activeConnector").removeClass("activeConnectorQP")}},createNewShape:function(e,t){var i=E2DGlobals.e2d,n=document.getElementById(i.SURROUND_ID).getBoundingClientRect();if(n.left<e.clientX&&e.clientX<n.right&&n.top<e.clientY&&e.clientY<n.bottom){i.setMode("select");var o=t.draggable.find("img:nth-child(1)"),s=o.attr("id"),r=t.draggable.children("div:nth-child(2)").text(),a=o.attr("title"),l=o.attr("family"),h=o.attr("shortcutFor"),d=i.getNewCoords(e.clientX,e.clientY,!0);d.x=E2DUtils.round(i.convertGraphXToUserX(d.x),i.numberOfDecimal),d.y=E2DUtils.round(i.convertGraphYToUserY(d.y),i.numberOfDecimal),d.z=E2DUtils.round(i.convertGraphZToUserZ(d.z),i.numberOfDecimal),h&&(s=h);var c=s.split("|"),u=InsertedShape.CreateShape(c[0],c[1],"",r,l,a,d.x,d.y,d.z,0,0,0,0,"","",{});i.createNewShape(u,!0)}},clickCount:0,clickTimeout:null,onSingleDoubleClick:function(){E2DEvents.clickCount++,1===E2DEvents.clickCount?(E2DEvents.onClick&&E2DEvents.onClick.apply(this,arguments),E2DEvents.clickTimeout=setTimeout(function(){E2DEvents.clickCount=0},400)):(E2DEvents.clickTimeout&&clearTimeout(E2DEvents.clickTimeout),E2DEvents.onDblClick&&E2DEvents.onDblClick.apply(this,arguments),E2DEvents.clickCount=0)},onClick:function(e){},onDblClick:function(e){var t=E2DGlobals.e2d;if(!t.selected)return!1;if(t.renderer.isPolyline(t.selected))t.unselectPolylineSegment();else{var i=t.insertedShapes.getShapeById(t.selected.id);if(i&&"text"===i.source)return t.startTextEdit(t.selected),!1;if(t.events.doubleclick){var n=null,o=[];if(t.renderer.isMultipleSelect(t.selected)){for(var s=t.multipleSelectShapes.getShapes(),r=0,a=s.length;r<a;r++)(n=t.getEventArgumentByShapeId("DOUBLECLICK",s[r].id))&&(o[o.length]=n);if(o&&o.length>1&&e&&e.currentTarget&&e.currentTarget.id&&!t.renderer.isMultipleSelect(e.currentTarget)){for(var l=e.currentTarget.id,h=null,d=-1,c=0,u=o.length;c<u;c++)if(l===(n=o[c]).shapeID){h=n,d=c;break}h&&(o.splice(d,1),o.unshift(h))}}else(n=t.getEventArgumentByShapeId("DOUBLECLICK",t.selected.id))&&(o[o.length]=n);o&&o.length>0&&E2DEvents.doSubmitEvent("OnEditor2DDoubleClick",o,1,"urDoubleClick")}}},onDrag:function(e){var t=E2DGlobals.e2d;if(t.selected){t.renderer.hideSnapLine(),t.clearPolylineQuotes();var i=t.getNewCoords(e.clientX,e.clientY,!1),n=i.x-E2DEvents.mouseDown.x,o=i.y-E2DEvents.mouseDown.y;if(!(Math.abs(n)<=1&&Math.abs(o)<=1)){if(t.checkScroll(e.clientX,e.clientY,E2DEvents.autoScroll),t.selectedBehaviour){if(t.selectedBehaviour.move.background&&!t.activeBackground)return void t.setHelp("warning","Background elements cannot be moved.");if(t.selectedBehaviour.move.noMove||t.selectedBehaviour.move.noXMove&&t.selectedBehaviour.move.noYMove)return void t.setHelp("warning","Selected shape cannot be moved.")}E2DEvents.dragStarted||(E2DEvents.dragStarted=!0,E2DGlobals.dragTimerMode&&(E2DUtils.engageTimer(1e3/E2DGlobals.dragFps,t,t.performCheckings),t.renderer3d&&t.renderer3d.renderOFF()),t.renderer.isMultipleSelect(t.selected)?t.initMultipleSelectorDummy():t.clearShapeText()),t.renderer.isMultipleSelect(t.selected)?t.moveMultipleShapes(n,o):t.renderer.isConnector(t.selected)?t.moveConnector(n,o,E2DEvents.mouseDown):t.renderer.isSmartLineHub(t.selected)?t.moveSmartLineHub():t.moveShape(e.shiftKey,n,o,i)}}else t.container.off("vmousemove",E2DEvents.onDrag)},onDraw:function(e){var t=E2DGlobals.e2d;if(t.selected){t.renderer.hideSnapLine(),t.clearPolylineQuotes();var i=e.shiftKey,n=t.getNewCoords(e.clientX,e.clientY,!1);return t.checkScroll(e.clientX,e.clientY,E2DEvents.autoScrollResize),E2DEvents.dragStarted||(E2DEvents.dragStarted=!0,E2DGlobals.dragTimerMode&&(E2DUtils.engageTimer(1e3/E2DGlobals.dragFps,t,t.performCheckings),t.renderer3d&&t.renderer3d.renderOFF()),t.renderer.isMultipleSelect(t.selected)&&t.initMultipleSelectorDummy()),"resize"!==t.mode&&"select"!==t.mode?t.renderer.isConnector(t.selected)?t.resizeNewConnector(i,n):t.resizeNewShape(i,n):t.renderer.isMultipleSelect(t.selected)?t.resizeMultipleShapes(i,n,E2DEvents.mouseDown):t.renderer.isConnector(t.selected)?t.resizeConnector(n,i):t.resizeShape(i,n,E2DEvents.mouseDown),!1}},onHit:function(e){const t=$.Deferred();t.done(E2DEvents.onHitAsync),t.resolve(e.currentTarget,e.clientX,e.clientY,e.shiftKey)},onHitAsync:function(e,t,i,n,o){const s=E2DGlobals.e2d;if(!s.textEditMode)if("select"===s.mode){if(n||s.renderer.isMultipleSelect(e)||s.multipleSelectShapes.contains(e)||s.selected&&s.selected.id!==e.id&&s.unselect(),s.selected){if(!s.renderer.isMultipleSelect(e)&&n){s.setPropertiesVisible(null),s.renderer.isMultipleSelect(s.selected)?s.multipleSelectShapes.contains(e)?(s.multipleSelectShapes.removeShape(e,o),s.setHelp("info","Shape removed from multiple selector")):(s.multipleSelectShapes.addShape(e,s.renderer.getBoundingBox(e),null,o),s.setHelp("info","New Shape added to multiple selector")):(s.multipleSelectShapes.addShape(s.selected,s.renderer.getBoundingBox(s.selected),null,o),s.multipleSelectShapes.addShape(e,s.renderer.getBoundingBox(e),null,o),s.setHelp("info","New Shape added to multiple selector"));let t=null;const i=s.multipleSelectShapes.getShapes();i.length>1?(s.multipleSelectShapes.reset(o),s.multipleSelectShapes.setSelectedShapes(i,o),t=s.resetMultipleSelector(),s.updateShapeInfo(t)):1===i.length&&(t=i[0],s.multipleSelectShapes.reset(o),s.renderer.showMultipleSelectors(!1)),s.select(t)}else if(s.renderer.isPolyline(s.selected)&&s.renderer.isPolyline(e)&&s.selected.id===e.id){const e=s.getNewCoords(t,i,!0);s.selectPolylineSegment(e.x,e.y)}}else if(s.select(e),s.renderer.updateTracker(s.selected),s.multipleSelectShapes.reset(o),s.renderer.showMultipleSelectors(!1),s.renderer.isPolyline(e)){const e=s.getNewCoords(t,i,!0);s.selectPolylineSegment(e.x,e.y)}s.selectedBounds=s.renderer.bounds(s.selected),t&&i&&(E2DEvents.mouseDown=s.getNewCoords(t,i,!0),s.container.on("vmousemove",E2DEvents.onDrag))}else if("line"===s.mode||"curve-line"===s.mode||"ortho-line"===s.mode||"smart-line"===s.mode||"link-line"===s.mode)s.unselect(),s.selectConnectorMode=!0,s.addConnectionPointsForShape(e,!1,E2DEvents.prev_connector,E2DEvents.active_connector);else if("quote-line"===s.mode)s.unselect(),s.selectConnectorMode=!0,s.renderer.isPolyline(e)?s.addConnectionPointsForPolyline(e):s.addConnectionPointsForShape(e,!1,E2DEvents.prev_connector,E2DEvents.active_connector);else if("ZOOM_IN"===s.mode||"ZOOM_OUT"===s.mode)return},onKeyUp:function(e){var t=E2DGlobals.e2d,i="number"==typeof e.which?e.which:e.keyCode;if((46===i||37===i||38===i||39===i||40===i)&&t.textEditMode)return!0;if(37===i||38===i||39===i||40===i||82===i||76===i){if("_file"===e.target.id||"_DOCUMENT_NAME"===e.target.id||"__imageURL"===e.target.id)return!1;t.clearShapeText(),t.resetShapeText(),t.selectedBounds=t.renderer.bounds(t.selected),t.multipleSelectShapes.updateShapeBounds()}},onKeyDown:function(e){var t=E2DGlobals.e2d,i=e.altKey,n=e.ctrlKey,o=e.shiftKey,s=e.srcElement?e.srcElement:e.target;if(s){var r=s.tagName.toLowerCase();if("input"===r||"select"===r)return!0}switch("number"==typeof e.which?e.which:e.keyCode){case 13:if("poly-line"===t.mode&&E2DEvents.polylineStarted)return t.enterBehaviour&&"finish"==t.enterBehaviour.toLowerCase()?(t.finishPolyline(),!1):(t.closePolyline(),!1);break;case 27:if("poly-line"===t.mode&&E2DEvents.polylineStarted)return t.finishPolyline(),!1;"select"!==t.mode&&"resize"!==t.mode&&t.setMode("select"),E2DEvents.hideExtraToolbars();break;case 8:if("poly-line"===t.mode&&E2DEvents.polylineStarted)return t.undoPolyline(),!1;break;case 46:if(!t.textEditMode)return t.deleteSelection(),!1;break;case 37:if(!t.textEditMode)return t.fineMoveByDir("LEFT"),!1;break;case 38:if(!t.textEditMode)return t.fineMoveByDir("UP"),!1;break;case 39:if(!t.textEditMode)return t.fineMoveByDir("RIGHT"),!1;break;case 40:if(!t.textEditMode)return t.fineMoveByDir("DOWN"),!1;break;case 90:n&&!t.textEditMode&&t.undo();break;case 89:n&&!t.textEditMode&&t.redo();break;case 88:n&&!t.textEditMode&&t.cut();break;case 67:n&&!t.textEditMode&&t.copy();break;case 86:n&&!t.textEditMode&&t.paste();break;case 82:if(t.selected&&!t.textEditMode){if(n)return t.clearShapeText(),t.fineRotateSelection(90),!1;o&&(t.clearShapeText(),t.fineRotateSelection(1))}break;case 76:if(t.selected&&!t.textEditMode){if(n)return t.clearShapeText(),t.fineRotateSelection(-90),!1;o&&(t.clearShapeText(),t.fineRotateSelection(-1))}break;case 109:case 173:case 189:n?(E2DEvents.prevent(e),E2DEvents.doZoomOut()):t.renderer.isPolyline(t.selected)&&t.deletePolylinePoint();break;case 107:case 171:case 187:n?(E2DEvents.prevent(e),E2DEvents.doZoomIn()):t.renderer.isPolyline(t.selected)&&t.addPolylinePoint();break;case 48:case 96:n&&(E2DEvents.prevent(e),E2DEvents.doZoomOrig());break;case 70:n&&(E2DEvents.prevent(e),o?E2DEvents.doZoomFit():i&&E2DEvents.doZoomPage());break;case 49:case 97:n&&(E2DEvents.prevent(e),t.setE3DViewMode("1"));break;case 50:case 98:n&&(E2DEvents.prevent(e),t.setE3DViewMode("2"));break;case 51:case 99:n&&(E2DEvents.prevent(e),t.setE3DViewMode("3"));break;case 52:case 100:n&&(E2DEvents.prevent(e),t.setE3DViewMode("4"));break;case 53:case 101:n&&(E2DEvents.prevent(e),t.setE3DViewMode("5"));break;case 65:if(n&&!t.textEditMode)return E2DEvents.prevent(e),t.selectAll(),!1;break;case 68:if(n)return E2DEvents.prevent(e),E2DEvents.doSubmitSelection("OnEditor2DSmartCopy",1,"urSmartCopy"),!1;break;case 73:n&&(E2DEvents.prevent(e),E2DEvents.onDblClick())}return!0},onMouseDown:function(e){var t=E2DGlobals.e2d,i=t.getNewCoords(e.clientX,e.clientY,!0);if("ZOOM_IN"===t.mode||"ZOOM_OUT"===t.mode)return E2DEvents.mouseDown={x:i.x,y:i.y},"ZOOM_IN"===t.mode?E2DEvents.doZoomIn():"ZOOM_OUT"===t.mode&&E2DEvents.doZoomOut(),!1;var n=e.target.parentNode;if("tracker-dots"===n.id)return E2DEvents.mouseDown={x:e.clientX,y:e.clientY},E2DEvents.hideExtraToolbars(),E2DEvents.closeToolsDialog(),E2DEvents.openQuickPickDialog(),!1;if(!t.selectConnectorMode){if(t.clearOverlappingGhosts(),E2DEvents.polylineStarted||"tracker-rotate"!==n.id&&"resize-right"!==n.id&&"resize-left"!==n.id&&"resize-bottom"!==n.id&&"resize-bottom-left"!==n.id&&"resize-bottom-right"!==n.id&&"resize-top"!==n.id&&"resize-top-left"!==n.id&&"resize-top-right"!==n.id&&"resize-depth"!==n.id&&"resize-z"!==n.id&&"resize-from"!==n.id&&"resize-to"!==n.id&&"control1"!==n.id&&"control2"!==n.id)if("select"!==t.mode&&"resize"!==t.mode&&"PAGE_DRAG"!==t.mode&&"SELECTION_DRAG"!==t.mode){if(t.setHelp("info","Drag your mouse to size the selected shape"),E2DEvents.prev_connector&&"link-line"==t.mode)return!1;if(E2DEvents.active_connector&&E2DEvents.active_connector_qp&&E2DEvents.active_connector_qp.length>1)return E2DEvents.mouseDown={x:e.clientX,y:e.clientY},E2DEvents.hideExtraToolbars(),E2DEvents.closeToolsDialog(),E2DEvents.openQuickPickCPDialog(E2DEvents.active_connector_qp),!1;if(E2DEvents.mouseDown={x:i.x,y:i.y},E2DEvents.active_connector&&E2DEvents.prev_connector)return t.connectLine(E2DEvents.prev_connector,E2DEvents.active_connector,E2DEvents.active_connector_qp,E2DEvents.connector_z),!1;if(E2DEvents.active_connector&&(E2DEvents.mouseDown=t.pointFromConnector(E2DEvents.active_connector)),"line"===t.mode||"ortho-line"===t.mode||"curve-line"===t.mode||"quote-line"===t.mode)t.unselect(),t.createLine(t.mode,E2DEvents.mouseDown.x,E2DEvents.mouseDown.y,E2DEvents.active_connector);else if("smart-line"===t.mode||"link-line"===t.mode)t.unselect(),E2DEvents.active_connector&&t.createLine(t.mode,E2DEvents.mouseDown.x,E2DEvents.mouseDown.y,E2DEvents.active_connector);else if("poly-line"===t.mode&&E2DEvents.polylineStarted)if(E2DEvents.active_connector)t.connectPolyline(E2DEvents.active_connector);else{var o=t.renderer.getPolylineNumberOfPoints(t.selected)-1;E2DEvents.mouseDown=t.getNewCoordsForPolylinePoint(t.selected,o,E2DEvents.mouseDown.x,E2DEvents.mouseDown.y,e.shiftKey),t.renderer.closePolylineSegment(t.selected,E2DEvents.mouseDown.x,E2DEvents.mouseDown.y,!0)}else"text"===t.mode&&(t.unselect(),t.createText(E2DEvents.mouseDown.x,E2DEvents.mouseDown.y))}else if("PAGE_DRAG"===t.mode||e.altKey)E2DEvents.mouseDown={x:i.x,y:i.y},t.container.on("vmousemove",E2DEvents.onPageDrag);else{E2DEvents.mouseDown.x===i.x&&E2DEvents.mouseDown.y===i.y||(E2DEvents.skipUnselect()?E2DEvents.hideExtraToolbars():t.unselect()),t.multipleSelectShapes.recalculateBounds();var s=!1;if(!n.id){var r=E2DUtils.getFirstParentWithID(n);if(r){var a=t.insertedShapes.getShapeById(r.id);s=a&&a.hasBehaviour("(BACKGROUND)")}}(s||n.id===t.container.attr("id")||n.id===t.renderer.SVG_ROOT_ID||n.id===t.renderer.SVG_PAGE_ID||n.id===t.renderer.SVG_PAGE_GRID_ID)&&(t.renderer.sizeMultipleSelector({x:i.x,y:i.y,width:0,height:0}),E2DEvents.mouseDown={x:i.x,y:i.y},t.container.on("vmousemove",E2DEvents.onSelectionDrag),t.mode="SELECTION_DRAG")}else{if(E2DUtils.isMobile()&&event.target.classList.contains("dummy"))return!1;if(t.prevMode=t.mode,t.setMode("resize"),t.selected){E2DEvents.mouseDown={x:i.x,y:i.y};var l=t.renderer.bounds(t.selected);switch(t.prevRect=l,n.id){case"resize-from":t.renderer.isConnector(t.selected)&&(E2DEvents.lineStarted=!0,t.renderer.isPolyline(t.selected)?n.hasAttributeNS(null,"plPoint")?t.resizeMode="polyline-"+n.getAttributeNS(null,"plPoint"):t.resizeMode="polyline-from":(t.resizeMode="line-from",t.showConnectionPoints(),t.showSmartLineMiddleConnectionPoints(!0),t.showSmartLineOrthoConnectionPoints(!1)));break;case"resize-to":t.renderer.isConnector(t.selected)&&(E2DEvents.lineStarted=!0,t.renderer.isPolyline(t.selected)?n.hasAttributeNS(null,"plPoint")?t.resizeMode="polyline-"+n.getAttributeNS(null,"plPoint"):t.resizeMode="polyline-to":(t.resizeMode="line-to",t.showConnectionPoints(),t.showSmartLineMiddleConnectionPoints(!0),t.showSmartLineOrthoConnectionPoints(!0)));break;case"control1":t.resizeMode="control1";break;case"control2":t.resizeMode="control2";break;case"resize-bottom":t.resizeMode="bottom-stretch",t.multipleSelectShapes.recalculateBounds();break;case"resize-top":t.resizeMode="top-stretch",t.multipleSelectShapes.recalculateBounds();break;case"resize-top-left":t.resizeMode="top-left-stretch",t.multipleSelectShapes.recalculateBounds();break;case"resize-bottom-left":t.resizeMode="bottom-left-stretch",t.multipleSelectShapes.recalculateBounds();break;case"resize-bottom-right":t.resizeMode="bottom-right-stretch",t.multipleSelectShapes.recalculateBounds();break;case"resize-top-right":t.resizeMode="top-right-stretch",t.multipleSelectShapes.recalculateBounds();break;case"resize-right":t.resizeMode="right-stretch",t.multipleSelectShapes.recalculateBounds();break;case"resize-left":t.resizeMode="left-stretch",t.multipleSelectShapes.recalculateBounds();break;case"resize-depth":t.resizeMode="depth-stretch",t.multipleSelectShapes.recalculateBounds();break;case"resize-z":t.resizeMode="z-stretch",t.multipleSelectShapes.recalculateBounds();break;case"tracker-rotate":t.resizeMode="rotate",t.multipleSelectShapes.recalculateBounds()}t.clearShapeText()}"rotate"===t.resizeMode&&(t.renderer.isMultipleSelect(t.selected)?(t.setHelp("info","Drag your mouse to rotate this selection"),t.multipleSelectShapes.recalculateBounds()):t.setHelp("info","Drag your mouse to rotate selected shape, For Fine rotation use <B>Shift+R</B> and <B>Shift+L</B>")),t.container.on("vmousemove",E2DEvents.onDraw)}return!1}},onMouseUp:function(e){E2DEvents.lineStarted=!1,E2DEvents.autoScrollIntervalID&&(clearInterval(E2DEvents.autoScrollIntervalID),E2DEvents.autoScrollIntervalID=null);const t=E2DGlobals.e2d;if(t.selectConnectorMode)return void(t.selectConnectorMode=!1);const i=t.getNewCoords(e.clientX,e.clientY,!0),n=E2DUtils.isPointTooClose(E2DEvents.mouseDown,i,.5);let o=E2DEvents.dragStarted&&!n,s="urUpdateShapes";if(t.renderer.isPolyline(t.selected)&&n){const i=e.target.parentNode;if(i.hasAttributeNS(null,"plPoint")){if(i.classList.contains("lineTrackerResizeSelected"))return i.classList.remove("lineTrackerResizeSelected"),t.detachEditorMoveEvents(),!1;if("resize-from"===i.id)return i.classList.add("lineTrackerResizeSelected"),document.getElementById("resize-to").classList.remove("lineTrackerResizeSelected"),t.detachEditorMoveEvents(),E2DEvents.updatePolylinePropertiesButtons(),!1;if("resize-to"===i.id)return document.getElementById("resize-from").classList.remove("lineTrackerResizeSelected"),i.classList.add("lineTrackerResizeSelected"),t.detachEditorMoveEvents(),E2DEvents.updatePolylinePropertiesButtons(),!1}}if(E2DEvents.mouseDown={x:0,y:0},E2DEvents.skipMouseUp)return E2DEvents.skipMouseUp=!1,!1;if("poly-line"===t.mode&&E2DEvents.polylineStarted)return!1;if("ZOOM_IN"===t.mode||"ZOOM_OUT"===t.mode)return!1;"select"!==t.mode&&"resize"!==t.mode&&"line"!==t.mode&&"ortho-line"!==t.mode&&"link-line"!==t.mode&&"quote-line"!==t.mode&&t.mode,t.detachEditorMoveEvents(),E2DEvents.dragStarted&&(E2DEvents.dragStarted=!1,t.clearDragCache(),t.clearShapeText(),t.resetShapeText(),t.renderer3d&&t.renderer3d.renderON(E2DGlobals.defaultFps),t.renderer.isMultipleSelect(t.selected)&&t.resetMultipleSelectorDummy());const r=e.shiftKey,a=[],l=[];if("SELECTION_DRAG"===t.mode){t.mode="select";let e=null;const i=t.getContainedShapeList(t.renderer.bounds(t.renderer.getMultipleSelector(!0)),r);i.length>1?(t.multipleSelectShapes.reset(),t.multipleSelectShapes.setSelectedShapes(i),e=t.resetMultipleSelector()):1===i.length?(e=i[0],t.multipleSelectShapes.reset()):(t.multipleSelectShapes.reset(),t.renderer.showMultipleSelectors(!1)),t.select(e)}else t.clearSnap(),t.renderer.isMultipleSelect(t.selected)||(t.renderer.showMultipleSelectors(!1),t.multipleSelectShapes.reset());if("line"===t.mode||"curve-line"===t.mode||"ortho-line"===t.mode||"smart-line"===t.mode||"link-line"===t.mode||"quote-line"===t.mode||"line-from"===t.resizeMode||"line-to"===t.resizeMode)return t.connectLine(E2DEvents.prev_connector,E2DEvents.active_connector,E2DEvents.active_connector_qp,E2DEvents.connector_z),!1;if(t.resizeMode.startsWith("polyline-"))return t.connectPolyline(E2DEvents.active_connector),!1;if("poly-line"===t.mode&&!E2DEvents.polylineStarted)return t.createPolyline(i.x,i.y,E2DEvents.active_connector),!1;if("text"===t.mode&&(t.renderer.updateTracker(t.selected),t.textToolBeginNew?(t.beginTextToolEdit(t.selected),t.textToolBeginNew=!1):t.setHelp("info","Text Mode: Click again to draw another text shape")),"resize"===t.mode){let e=null,i=null;if(t.events.rotated&&"rotate"===t.resizeMode)for(let n=0,o=(e=t.getSelectedShapes()).length;n<o;n++)(i=t.getEventArgumentByShapeId("ROTATED",e[n].id))&&(a[a.length]=i);if(t.events.stretched&&t.resizeMode&&"z-stretch"!==t.resizeMode&&-1!==t.resizeMode.indexOf("-stretch"))for(let n=0,o=(e=t.getSelectedShapes()).length;n<o;n++)(i=t.getEventArgumentByShapeId("STRETCHED",e[n].id))&&(l[l.length]=i);t.clearShapeText(),t.resetShapeText(),t.setMode(t.prevMode)}if(t.restoreMode(),t.selected){t.performCheckInclusions(t.selected),t.performCheckCollisions(t.selected),t.performCheckPolylineQuotes(t.selected),t.performCheckOverlappings(t.selected),t.renderer.updateTracker(t.selected);const e=t.insertedShapes.getShapeById(t.selected.id);t.updateOnTheFlyStyleForHighlightEqualShape(e)}t.events.rotated&&a.length>0&&(o=!1,s="urRotateShapes",E2DEvents.doSubmitEvent("OnEditor2DRotated",a,1,s)),t.events.stretched&&l.length>0&&(o=!1,s="urStretchShapes",E2DEvents.doSubmitEvent("OnEditor2DStretched",l,1,s)),o&&t.saveUndoRedoPoint(0,s)},onShapeTouchStart:function(e){e.preventDefault()},onShapeMouseOut:function(e){var t=$.Deferred();t.done(E2DEvents.onShapeMouseOutAsync),t.resolve(e.currentTarget)},onShapeMouseOutAsync:function(e){e&&e.classList.add("shapeCursor")},onShapeMouseOver:function(e){var t=$.Deferred();t.done(E2DEvents.onShapeMouseOverAsync),t.resolve(e.currentTarget)},onShapeMouseOverAsync:function(e){if(e){var t=E2DGlobals.e2d;if("select"!=t.mode&&e.classList.remove("shapeCursor"),!(t.textEditMode||t.selected&&t.selected.id===e.id)){var i=E2DEvents.lineStarted,n=E2DEvents.lineStarted&&t.renderer.isQuoteLine(t.selected),o=E2DEvents.polylineStarted||t.resizeMode.startsWith("polyline-"),s=n&&t.renderer.isPolyline(e);(i||o)&&(E2DEvents.shapeMouseOver&&E2DEvents.shapeMouseOver.id!==e.id&&t.removeConnectionPoints(E2DEvents.shapeMouseOver),E2DEvents.shapeMouseOver=e),o||s?t.addConnectionPointsForPolyline(e,!0):i&&t.addConnectionPointsForShape(e,!0,E2DEvents.prev_connector,E2DEvents.active_connector)}}},onMouseOver:function(e){var t=E2DGlobals.e2d,i=e.target.parentNode;if(!i||!i.id)return!1;var n=t.renderer.bounds(t.selected).rotation%360,o=n&&(n>=45&&n<=135||n>=225&&n<=315),s="default";switch(i.id){case"resize-bottom":case"resize-top":case"resize-depth":case"resize-z":s=o?"e-resize":"s-resize";break;case"resize-top-left":s=o?"sw-resize":"nw-resize";break;case"resize-bottom-left":s=o?"nw-resize":"ne-resize";break;case"resize-top-right":s=o?"nw-resize":"sw-resize";break;case"resize-bottom-right":s=o?"ne-resize":"nw-resize";break;case"resize-right":case"resize-left":s=o?"s-resize":"e-resize";break;case"tracker-rotate":s="url(resources/images/e2d/cursor_rotate.png),auto",t.resizeMode="rotate";break;case"tracker-dots":s="pointer"}return i.style.cursor=s,!1},onPageDrag:function(e){var t=E2DGlobals.e2d,i=t.getNewCoords(e.clientX,e.clientY,!1),n=E2DEvents.mouseDown.x-i.x,o=E2DEvents.mouseDown.y-i.y,s=t.getScroll();t.setScroll(s.x+n,s.y+o)},onSelectionDrag:function(e){if(!(E2DEvents.touchStarted>1)){var t=E2DGlobals.e2d;if("SELECTION_DRAG"===t.mode){var i=t.getNewCoords(e.clientX,e.clientY,!1),n=t.renderer.getMultipleSelector();t.renderer.resize(n,E2DEvents.mouseDown.x,E2DEvents.mouseDown.y,i.x,i.y),t.renderer.showMultipleSelector(!0)}}},onSelect:function(){},onUnselect:function(){E2DEvents.onSelect()},onSelectStart:function(e){return!1},onTextEditEnd:function(e){var t=E2DGlobals.e2d;t.selected&&t.textEditMode&&e&&"E2DShapeText"!==e.target.id&&(t.finishTextEdit(),t.unselect())},onShapeUpdateById:function(e,t,i,n){e.target&&E2DGlobals.e2d.updateById(e.target,t,i,n)},onShapeSelectById:function(e){if(e.target){var t=document.getElementById(e.target);E2DGlobals.e2d.select(t)}},onShapeAddSelectionById:function(e,t,i){if(e.target){var n=document.getElementById(e.target);E2DEvents.onHitAsync(n,0,0,t,i)}},onShapeRemoveSelectionById:function(e,t,i){if(e.target){var n=document.getElementById(e.target);E2DEvents.onHitAsync(n,0,0,t,i)}}},E2DUtils={isMobile:function(){return E2DUtils.isAndroid()&&E2DUtils.isIOS()},isAndroid:function(){return/Android/i.test(navigator.userAgent)},isIOS:function(){return/iPad|iPhone|Mac/i.test(navigator.userAgent)},isIE:function(){return navigator.appVersion.match(/MSIE (\d\.\d)/)},isOpera:function(){return-1!==navigator.userAgent.toLowerCase().indexOf("opera")},encode:function(e){var t=e;return t=(t=(t=(t=(t=t.replace(/&/gi,"&")).replace(/"/gi,""")).replace(/</gi,"<")).replace(/>/gi,">")).replace(/'/gi,"'")},decode:function(e){var t=e;return t=(t=(t=(t=(t=(t=t.replace(/&/gi,"&")).replace(/"/gi,'"')).replace(/</gi,"<")).replace(/>/gi,">")).replace(/'/gi,"'")).replace(/ /gi," ")},encodeHTML:function(e){for(var t="",i=0,n=e.length;i<n;i++)t+="&#"+e.charCodeAt(i)+";";return t},decodeHTML:function(e){var t="";if(e.indexOf("&")<0)t=e;else for(var i=0,n=e.length;i<n;i++){var o="";if("&"===e.charAt(i)){var s=e.indexOf(";",i+1);if(s>0){var r=e.substring(i+1,s);if(r.length>1&&"#"===r.charAt(0))try{o="x"===r.charAt(1)||"X"===r.charAt(1)?String.fromCharCode(r.substring(2)):String.fromCharCode(r.substring(1))}catch(e){i++}}}t+=o}return this.decode(t)},deg2rad:function(e){return Math.PI/180*e},rad2deg:function(e){return e*(180/Math.PI)},angle2Bearing:function(e){return(450-e)%360},bearing2Angle:function(e){return(810-e)%360},areAlmostEqual:function(e,t){return Math.abs(e-t)<1e-4},isAlmostZero:function(e){return Math.abs(e)<1e-4},isNearToThresholdByPercent:function(e,t,i){var n=Math.min(e,t);return Math.abs(t)-Math.abs(e)<Math.abs(n)*i},isIncluded:function(e,t){if(!e||!t)return!1;E2DUtils.isPointInRect(e,t)},isIntersecting:function(e,t){if(!e||0===e.length)return!1;if(!t||0===t.length)return!1;var i,n,o,s,r,a,l,h,d=e.length,c=t.length;for(l=0;l<d;l++){for(i=E2DUtils.findNormalAxis(e,l),o=n=E2DUtils.dotProduct(i,e[0]),h=1;h<d;h++)(a=E2DUtils.dotProduct(i,e[h]))<n&&(n=a),a>o&&(o=a);for(r=s=E2DUtils.dotProduct(i,t[0]),h=1;h<c;h++)(a=E2DUtils.dotProduct(i,t[h]))<s&&(s=a),a>r&&(r=a);if(n-r>0||s-o>0)return!1}return!0},isRectFarAway:function(e,t){var i=Math.max(e.width,e.height)+Math.max(t.width,t.height);return Math.abs(e.x-t.x)>=i||Math.abs(e.y-t.y)>=i},areVerticesFarAway:function(e,t){var i=E2DUtils.getBoundingBoxForPolygon(e),n=E2DUtils.getBoundingBoxForPolygon(t);return i.xMax<n.xMin||n.xMax<i.xMin||i.yMax<n.yMin||n.yMax<i.yMin},getBoundingBoxForPolygon:function(e){for(var t={xMin:e[0].x,yMin:e[0].y,xMax:e[0].x,yMax:e[0].y},i=1,n=e.length;i<n;i++)e[i].x<t.xMin&&(t.xMin=e[i].x),e[i].y<t.yMin&&(t.yMin=e[i].y),e[i].x>t.xMax&&(t.xMax=e[i].x),e[i].y>t.yMax&&(t.yMax=e[i].y);return t},normalizeAxis:function(e){var t=Math.sqrt(e.x*e.x+e.y*e.y);return 0===t?{x:1,y:e.y}:{x:e.x/t,y:e.y/t}},findNormalAxis:function(e,t){var i=e[t],n=t>=e.length-1?e[0]:e[t+1],o={x:-(n.y-i.y),y:n.x-i.x};return E2DUtils.normalizeAxis(o)},dotProduct:function(e,t){return e.x*t.x+e.y*t.y},getVectorFromSegment:function(e,t,i,n){var o={x:0,y:0};return o.x=i-e,o.y=n-t,o},getVectorLength:function(e){return Math.sqrt(Math.pow(e.x,2)+Math.pow(e.y,2))},getSegmentLength:function(e,t,i,n){return E2DUtils.pointToPointDistance(e,t,i,n)},getSegmentRotation:function(e,t,i,n){var o=0,s=i-e,r=n-t;return Math.abs(s)<1e-7?r>=0?o=90:r<0&&(o=270):Math.abs(r)<1e-7?s>=0?o=0:s<0&&(o=180):(o=E2DUtils.rad2deg(Math.atan(r/s)),r>=0&&s>=0?o+=0:r>=0&&s<0?o+=180:r<0&&s>=0?o+=360:r<0&&s<0&&(o+=180)),Math.round(o)},getDegreeRotation:function(e){e=(e=e>1?1:e)<-1?-1:e;var t=E2DUtils.rad2deg(Math.acos(e));return Math.round(t)},getAngleBetweenPoints:function(e,t,i,n,o){var s=i-e,r=n-t,a=Math.atan2(r,s)+Math.PI/2;return o&&(a=(a=E2DUtils.rad2deg(a))>=0?a:360+a),a},getAngleBetweenPointsEx:function(e,t,i){return E2DUtils.getAngleBetweenPoints(e.x,e.y,t.x,t.y,i)},lineLineIntersection:function(e,t,i,n,o,s,r,a){var l=(e-i)*(s-a)-(t-n)*(o-r);return Math.abs(l)<1e-7?null:{x:((e*n-t*i)*(o-r)-(e-i)*(o*a-s*r))/l,y:((e*n-t*i)*(s-a)-(t-n)*(o*a-s*r))/l}},lineLineIntersectionEx:function(e,t,i,n){return E2DUtils.lineLineIntersection(e.x,e.y,t.x,t.y,i.x,i.y,n.x,n.y)},pointLineIntersection:function(e,t,i,n,o,s){if(!(o-i))return{x:i,y:t};if(!(s-n))return{x:e,y:n};var r,a=-1/((s-n)/(o-i));return{x:r=(o*(e*a-t+n)+i*(e*-a+t-s))/(a*(o-i)+n-s),y:a*r-a*e+t}},pointLineIntersectionEx:function(e,t,i){return E2DUtils.pointLineIntersection(e.x,e.y,t.x,t.y,i.x,i.y)},pointToLineDistance:function(e,t,i,n,o,s){var r=o-i,a=s-n;if(0===r&&0===a)return r=e-o,a=t-s,Math.sqrt(r*r+a*a);var l=((e-i)*r+(t-n)*a)/(r*r+a*a);return r=e-(i+l*r),a=t-(n+l*a),Math.sqrt(r*r+a*a)},pointToLineDistanceEx:function(e,t,i){return E2DUtils.pointToLineDistance(e.x,e.y,t.x,t.y,i.x,i.y)},pointToSegmentDistance:function(e,t,i,n,o,s){var r=o-i,a=s-n;if(0===r&&0===a)return r=e-o,a=t-s,Math.sqrt(r*r+a*a);var l=((e-i)*r+(t-n)*a)/(r*r+a*a);if(l<0)r=e-i,a=t-n;else if(l>1)r=e-o,a=t-s;else{var h={x:i+l*r,y:n+l*a};r=e-h.x,a=t-h.y}return Math.sqrt(r*r+a*a)},pointToSegmentDistanceEx:function(e,t,i){return E2DUtils.pointToSegmentDistance(e.x,e.y,t.x,t.y,i.x,i.y)},pointToPointDistance:function(e,t,i,n){return Math.sqrt(Math.pow(i-e,2)+Math.pow(n-t,2))},pointToPointDistanceEx:function(e,t){return E2DUtils.pointToPointDistance(e.x,e.y,t.x,t.y)},isPointInRect:function(e,t){if(!t||0===t.length)return!1;for(var i=!0,n=0,o=t.length;n<o;n++)i=i&&E2DUtils.isPointLeftOfLine(e,t[n],t[(n+1)%o]);return i},isRectInLine:function(e,t,i,n){for(var o=0,s=0,r=e.length;s<r;s++)E2DUtils.isPointInLine(e[s],t,i,n)&&o++;return o>=2},isPointLeftOfLine:function(e,t,i){return(e.y-t.y)*(i.x-t.x)-(e.x-t.x)*(i.y-t.y)>0},isPointInLine:function(e,t,i,n){var o=E2DUtils.pointToPointDistanceEx(t,i),s=E2DUtils.pointToPointDistanceEx(t,e),r=E2DUtils.pointToPointDistanceEx(e,i);return Math.abs(o-(s+r))<n},isPointTooClose:function(e,t,i){return Math.abs(e.x-t.x)<i&&Math.abs(e.y-t.y)<i},isPointInList:function(e,t){if(!e)return!1;if(!t||0===t.length)return!1;for(var i=0,n=t.length;i<n;i++)if(e.x===t[i].x&&e.y===t[i].y)return!0;return!1},midpointOfLine:function(e,t,i,n){return{x:(e+i)/2,y:(t+n)/2}},midpointOfLineEx:function(e,t){return E2DUtils.midpointOfLine(e.x,e.y,t.x,t.y)},getRotatedPointAtDistanceFromPoint:function(e,t,i,n){var o=e,s=t;if(0===i)o+=n;else if(90===i)s+=n;else if(180===i)o-=n;else if(270===i)s-=n;else{var r=Math.atan(E2DUtils.deg2rad(i));o-=n*Math.cos(r),s+=n*Math.sin(r)}return{x:o,y:s}},getPointAtDistanceAlongSegment:function(e,t,i,n,o){var s=e,r=t,a=i-e,l=n-t;if(Math.abs(l)<1e-7)s+=a>=0?o:-o;else if(Math.abs(a)<1e-7)r+=l>=0?o:-o;else{var h=l/a,d=Math.atan(h);a>=0?(s+=o*Math.cos(d),r+=o*Math.sin(d)):a<0&&(s-=o*Math.cos(d),r-=o*Math.sin(d))}return{x:s,y:r}},getPerpendicularPointAtDistanceFromSegmentMidpoint:function(e,t,i,n,o){var s=E2DUtils.midpointOfLine(e,t,i,n),r=s.x,a=s.y,l=i-e,h=n-t;if(Math.abs(h)<1e-7)a+=o;else if(Math.abs(l)<1e-7)r-=o;else{var d=1/(h/l),c=Math.atan(d);r-=o*Math.cos(c),a+=o*Math.sin(c)}return{x:r,y:a}},getPerpendicularPointAtDistanceFromSegmentPoint:function(e,t,i,n,o,s,r){var a=o,l=s,h=i-e,d=n-t;if(Math.abs(d)<1e-7)l+=r;else if(Math.abs(h)<1e-7)a-=r;else{var c=1/(d/h),u=Math.atan(c);a-=r*Math.cos(u),l+=r*Math.sin(u)}return{x:a,y:l}},getPerpendicularPointsAtDistanceFromSegmentEndpoints:function(e,t,i,n,o){var s=e,r=t,a=i,l=n,h=E2DUtils.getSegmentRotation(e,t,i,n);if(0===h)r-=o,l-=o;else if(90===h)s+=o,a+=o;else if(180===h)r+=o,l+=o;else if(270===h)s-=o,a-=o;else{var d=n-t,c=1/(d/(i-e)),u=Math.atan(c);d>=0?(s+=o*Math.cos(u),r-=o*Math.sin(u),a+=o*Math.cos(u),l-=o*Math.sin(u)):(s-=o*Math.cos(u),r+=o*Math.sin(u),a-=o*Math.cos(u),l+=o*Math.sin(u))}return[{x:s,y:r},{x:a,y:l}]},realOffset:function(e){var t={top:0,left:0};do{t.top+=e.scrollTop()||0,t.left+=e.scrollLeft()||0,e=e.parent()}while(e.length>0);return t},cumulativeOffset:function(e){var t={top:0,left:0};do{var i=e.offset();t.top+=i.top||0,t.left+=i.left||0,e=e.offsetParent()}while(e.length>0);return t},within:function(e,t,i){var n=e.offset();return i>=n.top&&i<n.top+e[0].offsetHeight&&t>=n.left&&t<n.left+e[0].offsetWidth},createUUID:function(){return[4,2,2,2,6].map(function(e){for(var t="",i=0;i<e;i++){var n=parseInt(256*Math.random()).toString(16);1===n.length&&(n="0"+n),t+=n}return t}).join("-")},toArray:function(e){var t=[];for(var i in e)e.hasOwnProperty(i)&&(t[t.length]=e[i]);return t},toBoolean:function(e){return"boolean"==typeof e?e:"number"==typeof e&&e>0||"string"==typeof e&&"true"===e.toLowerCase()},cloneArray:function(e){return $.extend(!0,[],e)},cloneObject:function(e){return $.extend(!0,{},e)},objectHas:function(e,t){return!!e&&e.hasOwnProperty(t)},objectKeys:function(e){var t=[];for(var i in e)e.hasOwnProperty(i)&&(t[t.length]=i);return t},objectValues:function(e){var t=[];for(var i in e)e.hasOwnProperty(i)&&(t[t.length]=e[i]);return t},objectSize:function(e){var t=0;for(var i in e)e.hasOwnProperty(i)&&t++;return t},unionArray:function(e,t){return e.concat(t.filter(function(t){return e.indexOf(t)<0}))},getWindowSize:function(){var e=0,t=0;return window.innerWidth?(e=window.innerWidth,t=window.innerHeight):0!==document.documentElement.clientWidth?(e=document.documentElement.clientWidth,t=document.documentElement.clientHeight):(e=document.body.clientWidth,t=document.body.clientHeight),{width:e,height:t}},splitUnits:function(e){return e?(e=(e+="").toLowerCase()).indexOf("in")>=0?{0:e.split("in")[0],1:"in"}:e.indexOf("cm")>=0?{0:e.split("cm")[0],1:"cm"}:e.indexOf("mm")>=0?{0:e.split("mm")[0],1:"mm"}:e.indexOf("px")>=0?{0:e.split("px")[0],1:"px"}:{0:e,1:"px"}:null},splitPath:function(e){for(var t=[],i=e.split(" "),n=0,o=i.length;n<o;n++){var s=i[n].split(",");t[t.length]={x:1*s[0],y:1*s[1]}}return t},safeBlur:function(){var e=document.activeElement,t=e.tagName.toLowerCase();"html"!==t&&"head"!==t&&"body"!==t&&e.blur()},existsOnServer:function(e){return 200===$.ajax({url:e,async:!1,cache:!1}).status},isExternalUrl:function(e){return e&&0===e.lastIndexOf("http",0)&&-1===e.lastIndexOf(window.location.host)},isInSameClass:function(e,t){if(!e||!t)return!0;if(e===t)return!0;for(var i=e.split(","),n=i.length,o=0;o<n;o++){var s=i[o].replace(/^[ \s]+|[ \s]+$/,"");if(new RegExp("\\b"+s+"\\b","gi").test(t))return!0}return!1},isStringInList:function(e,t){if(e&&e.length>0)for(var i=t.split("|"),n=0,o=e.length;n<o;n++){var s=e[n];if(E2DUtils.hasWildcards(s)){var r=E2DUtils.WildcardsToRegExp(s);if(r.test(t))return!0;if(i.length>=2&&r.test(i[1]))return!0}else{if(s===t)return!0;if(i.length>=2&&s===i[1])return!0}}return!1},getCommonClass:function(e,t){if("string"==typeof e&&""!==e&&"string"==typeof t&&""!==t)for(var i=e.split(","),n=t.split(","),o=0,s=i.length;o<s;o++){i[o]=i[o].trim();for(var r=0,a=n.length;r<a;r++)if(i[o]===n[r].trim())return i[o]}return""},decimalizer:function(e){return e?Math.pow(10,e):1},round:function(e,t){if(void 0===t||0==+t)return Math.round(e);e=+e;var i=-1*t;return isNaN(e)||"number"!=typeof i||i%1!=0?NaN:(e=e.toString().split("e"),+((e=(e=Math.round(+(e[0]+"e"+(e[1]?+e[1]-i:-i)))).toString().split("e"))[0]+"e"+(e[1]?+e[1]+i:i)))},round2:function(e,t){return(e*(t=E2DUtils.decimalizer(t))<<1>>1)/t},round3:function(e,t){return t=E2DUtils.decimalizer(t),Math.round(e*t)/t},isNumeric:function(e){return e-parseFloat(e)+1>=0},hashCode:function(e){for(var t=0,i=0,n=e.length;i<n;i++)t=e.charCodeAt(i)+((t<<5)-t);return t},intToARGB:function(e){var t=(e>>24&255).toString(16)+(e>>16&255).toString(16)+(e>>8&255).toString(16)+(255&e).toString(16);return(t+="000000").substring(0,6)},HSVtoRGB:function(e,t,i){var n,o,s,r,a,l,h,d;switch(l=i*(1-t),h=i*(1-(a=6*e-(r=Math.floor(6*e)))*t),d=i*(1-(1-a)*t),r%6){case 0:n=i,o=d,s=l;break;case 1:n=h,o=i,s=l;break;case 2:n=l,o=i,s=d;break;case 3:n=l,o=h,s=i;break;case 4:n=d,o=l,s=i;break;case 5:n=i,o=l,s=h}return{r:Math.round(255*n),g:Math.round(255*o),b:Math.round(255*s)}},RGBtoHSV:function(e,t,i){var n,o=Math.max(e,t,i),s=Math.min(e,t,i),r=o-s,a=0===o?0:r/o,l=o/255;switch(o){case s:n=0;break;case e:n=t-i+r*(t<i?6:0),n/=6*r;break;case t:n=i-e+2*r,n/=6*r;break;case i:n=e-t+4*r,n/=6*r}return{h:n,s:a,v:l}},RGBtoHEX:function(e,t,i){return((1<<24)+(e<<16)+(t<<8)+i).toString(16).slice(1)},HEXtoRGB:function(e){e=e.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,function(e,t,i,n){return t+t+i+i+n+n});var t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:null},toHexColour:function(e){return E2DUtils.intToARGB(E2DUtils.hashCode(e))},getFirstParentWithID:function(e){return e?e.id?e:E2DUtils.getFirstParentWithID(e.parentNode):null},getParentWithID:function(e,t){return e?e.id===t?e:E2DUtils.getParentWithID(e.parentNode):null},isEventSupported:function(e){var t=document.createElement({select:"input",change:"input",submit:"form",reset:"form",error:"img",load:"img",abort:"img"}[e]||"div"),i=(e="on"+e)in t;return i||(t.setAttribute(e,"return;"),i="function"==typeof t[e]),t=null,i},arrowFromRotation:function(e){var t="";if(e*=1,isNaN(e))return t;return 337.5<=e&&e<=360||0<=e&&e<22.5?t+="↑":22.5<=e&&e<67.5?t+="↗":67.5<=e&&e<112.5?t+="→":112.5<=e&&e<157.5?t+="↘":157.5<=e&&e<202.5?t+="↓":202.5<=e&&e<247.5?t+="↙":247.5<=e&&e<292.5?t+="←":292.5<=e&&e<337.5&&(t+="↖"),t},hasWildcards:function(e){return-1!==e.indexOf("?")||-1!==e.indexOf("*")},WildcardsToRegExp:function(e){var t=e;return e.startsWith("*")||e.startsWith("?")||(t="^"+t),e.endsWith("*")||e.endsWith("?")||(t+="$"),t=t.replace(/\?/gi,".").replace(/\*/gi,".*"),new RegExp(t,"gi")},clearClassList:function(e){if(e&&e.classList)for(var t=e.classList;t.length>0;)t.remove(t.item(0))},engageTimer:function(e,t,i){return setTimeout(function(){i&&"function"==typeof i&&i.apply(t)&&E2DUtils.engageTimer(e,t,i)},e)},disengageTimer:function(e){e&&clearTimeout(e)},everyHash:[],every:function(e,t){if(0===t)return delete E2DUtils.everyHash[e],!0;if(!E2DUtils.everyHash[e])return E2DUtils.everyHash[e]=Date.now(),!0;var i=Date.now();return i-E2DUtils.everyHash[e]>=t&&(E2DUtils.everyHash[e]=i,!0)}},E2DTag={addTagInString:function(e,t){return e?t?e.toUpperCase().indexOf(t.toUpperCase())>=0?e:e+t:e:t},removeTagInString:function(e,t){if(!e)return"";if(!t)return e;var i=t.charAt(0),n=t.charAt(t.length-1);if("="===n){var o=e.toUpperCase().indexOf(t.toUpperCase());if(o>=0){var s="{"===e.substr(o+t.length,1);switch(i){case"(":n=s?"})":")";break;case"{":n=s?"}}":"}";break;case"[":n=s?"}]":"]";break;case"<":n=s?"}>":">";break;default:return e}var r=e.toUpperCase().indexOf(n,o+1);if(r>=0)return e.substring(0,o)+e.substring(r+n.length)}return e}return E2DTag.replaceTagInString(e,t,"")},replaceTagInString:function(e,t,i){return e?t?e.replace(t,i):e:""},isTagInString:function(e,t){return!!e&&(!!t&&e.toUpperCase().indexOf(t.toUpperCase())>=0)},decodeTagInString:function(e,t){var i={found:!1,value:""};if(!e)return i;if(!t)return i;var n,o=null,s=null;if((n=e.toUpperCase().indexOf(t.toUpperCase()))<0)return i;var r="{"===e.substr(n+t.length,1);switch(t.charAt(0)){case"(":s=r?"})":")";break;case"{":s=r?"}}":"}";break;case"[":s=r?"}]":"]";break;case"<":s=r?"}>":">";break;default:return i}return(o=e.indexOf(s,n+1))<0?i:(2===s.length&&(o+=1),{found:!0,value:e.substr(n+t.length,o-n-t.length)})}},E2DUndoManager=function(){(new Date).getTime();let e,t=[],i=0,n=0,o=0,s=0,r=-1,a=null,l=!0;const h=function(){e&&"function"==typeof e&&e(p(),g())},d=function(){i=c(i)},c=function(e){return++e>=n?0:e},u=function(e){return--e<0?n-1:e},p=function(){return!(i<0)&&(i>o+1||i!==o&&(i<o&&i+n>o))},g=function(){return!(i<0)&&(i<s||i!==s&&(i>s&&s+n>i))},y=function(e){const t={};return t.type=e.type,t.label=e.label,e.data&&(t.data=pako.ungzip(e.data,{to:"string"})),t};this.init=function(t,i){n=t,e=i},this.enable=function(e){l=e},this.save=function(e,n,u){if(!l)return;if(2===r)return void(r=-1);-1!==r&&(e=r,r=-1),a&&(n=a,a=null),d(),o===(s=i)&&(o=c(o)),h();const p={type:e,label:n,data:pako.gzip(u)};t[i]=p},this.peekInfo=function(){if(!l)return-1;const e=t[i];return e?{type:e.type,label:e.label}:{type:-1,label:null}},this.undo=function(){if(!l)return null;if(!p())return null;i=u(i),h();const e=t[i];return e?y(e):null},this.redo=function(){if(!l)return null;if(!g())return null;d(),h();const e=t[i];return e?y(e):null},this.clear=function(){i=-1,o=0,s=0,t=[],h()},this.setNextInfo=function(e,t){r=e,a=t}},E2DEventBus={listeners:{},addEventListener:function(e,t,i){for(var n=[],o=0,s=arguments.length;o<s;o++)n[n.length]=arguments[o];n=n.length>3?n.splice(3,n.length-1):[],void 0!==this.listeners[e]?this.listeners[e][this.listeners[e].length]={scope:i,callback:t,args:n}:this.listeners[e]=[{scope:i,callback:t,args:n}]},removeEventListener:function(e,t,i){if(void 0!==this.listeners[e]){for(var n=this.listeners[e].length,o=[],s=0;s<n;s++){var r=this.listeners[e][s];r.scope==i&&r.callback==t||(o[o.length]=r)}this.listeners[e]=o}},hasEventListener:function(e,t,i){if(void 0!==this.listeners[e]){var n=this.listeners[e].length;if(void 0===t&&void 0===i)return n>0;for(var o=0;o<n;o++){var s=this.listeners[e][o];if((!i||s.scope==i)&&s.callback==t)return!0}}return!1},dispatch:function(e,t){for(var i={type:e,target:t},n=[],o=0,s=arguments.length;o<s;o++)n[n.length]=arguments[o];if(n=n.length>2?n.splice(2,n.length-1):[],n=[i].concat(n),void 0!==this.listeners[e])for(var r=this.listeners[e].length,a=0;a<r;a++){var l=this.listeners[e][a];if(l&&l.callback){var h=n.concat(l.args);l.callback.apply(l.scope,h)}}},getEvents:function(){var e="";for(var t in this.listeners)for(var i=this.listeners[t].length,n=0;n<i;n++){var o=this.listeners[t][n];e+=o.scope&&o.scope.className?o.scope.className:"anonymous",e+=" listen for '"+t+"'\n"}return e}},InsertedShape.CreateShape=function(e,t,i,n,o,s,r,a,l,h,d,c,u,p,g,y,f){var v=new InsertedShape;return v.sourceLibrary=e,v.source=t,v.imageSVG=t,v.id=i,v.name=n,v.family=o,v.description=s,v.x=r,v.y=a,v.z=l,v.width=h,v.height=d,v.depth=c,v.rotation=u||0,v.text=p,v.behaviour=g,v.custom=y,v._updateBehaviour(),f&&(v.linkClass=f.linkClass,v.eventClass=f.eventClass,v.layer=f.layer,v.signature=f.signature,v.color=f.color,v.colorOpacity=f.colorOpacity,v.lineColor=f.lineColor,v.lineOpacity=f.lineOpacity,v.color3D=f.color3D,v.colorOpacity3D=f.colorOpacity3D,v.lineColor3D=f.lineColor3D,v.lineOpacity3D=f.lineOpacity3D),v},InsertedShape.CreateShapeFromConnector=function(e,t){var i=new InsertedShape;return i.id=e.getAttribute("id"),i.group=e.getAttribute("group"),i.source=E2DGlobals.e2d.renderer.getConnectorType(e),i.sourceLibrary=t,i.updateConnector(e),i},InsertedShape.CreateShapeFromObject=function(e,t){var i=["source","sourceLibrary","signature","id","name","family","description","layer","text","path","ctrl1x","ctrl1y","ctrl2x","ctrl2y","shapeFromId","shapeFromPointIndex","shapeToId","shapeToPointIndex","color","colorOpacity","lineColor","lineOpacity","lineWidth","color3D","colorOpacity3D","lineColor3D","lineOpacity3D","custom"],n=new InsertedShape;for(var o in e)if(i.indexOf(o)>=0)n[o]=e[o];else switch(o){case"group":n.group=e[o],InsertedShapes.SetGroupOccurrence(n.group);break;case"x":case"y":case"z":case"width":case"height":case"depth":case"rotation":n[o]=e[o]?e[o]:0;break;case"behaviour":n.behaviour=e[o],n.behaviour&&n._updateBehaviour();break;case"dimStack":n.dimStack=e[o]?e[o]:10;break;case"dimType":n.dimType=e[o]?1*e[o]:0;break;case"dimDriving":n.dimDriving=E2DUtils.toBoolean(e[o]);break;case"dimValue":n.dimValue=e[o]?e[o]:0;break;case"pinned":case"includeInBOM":n.pinned=E2DUtils.toBoolean(e[o]);break;case"connectionPoints":case"links":case"modified":case"selected":break;default:n.custom||(n.custom={}),n.custom[o]=e[o]}return n.imageSVG=n.source,n.sourceLibrary||(n.sourceLibrary=t),n},InsertedShape.CloneShape=function(e){return $.extend(!0,{},e)},InsertedShape.prototype={getFullSource:function(){return this.sourceLibrary?this.sourceLibrary+"|"+this.source:this.source},clearCalculated:function(){this.calculatedBehaviour=null,this.calculatedPinned=null},clearPolylineBehaviour:function(e,t){t||(this.lastPoly=null,this.removeBehaviour("(POLYLINE=")),e||this.removeBehaviour("(SHAPE="),this.removeBehaviour("(SNAPPOINTS="),this.removeBehaviour("(SNAPPED)")},decodeBehaviour:function(e){return E2DTag.decodeTagInString(this.behaviour,e)},setBehaviour:function(e){this.behaviour=e,this._updateBehaviour()},addBehaviour:function(e){this.behaviour=E2DTag.addTagInString(this.behaviour,e),this._updateBehaviour()},hasBehaviour:function(e){return E2DTag.isTagInString(this.behaviour,e)},removeBehaviour:function(e){this.behaviour=E2DTag.removeTagInString(this.behaviour,e),this._updateBehaviour()},updateCollisionClass:function(){var e=this.decodeBehaviour("(COLLISIONCLASS=");e.found&&(this.collisionClass=e.value)},updateContainerClass:function(){var e=this.decodeBehaviour("(CONTAINERCLASS=");e.found&&(this.containerClass=e.value)},updateLinkClass:function(){var e=this.decodeBehaviour("(LINKCLASS=");e.found&&(this.linkClass=e.value)},updateSnapClass:function(){var e=this.decodeBehaviour("(SNAPCLASS=");e.found&&(this.snapClass=e.value)},_updateBehaviour:function(){this.updateCollisionClass(),this.updateContainerClass(),this.updateLinkClass(),this.updateSnapClass()},hasSameDimensions:function(e){return!!e&&(this.width===e.width&&this.height===e.height&&this.depth===e.depth)},hasSameRotation:function(e){return!!e&&this.rotation===e.rotation},hasSameCollisionClass:function(e){return!!e&&E2DUtils.isInSameClass(this.collisionClass,e.collisionClass)},hasSameContainerClass:function(e){return!!e&&E2DUtils.isInSameClass(this.containerClass,e.containerClass)},hasSameLinkClass:function(e){return!!e&&E2DUtils.isInSameClass(this.linkClass,e.linkClass)},hasSameSnapClass:function(e){return!!e&&E2DUtils.isInSameClass(this.snapClass,e.snapClass)},isConnector:function(){return"line"===this.source||"curve-line"===this.source||"ortho-line"===this.source||"smart-line"===this.source||"poly-line"===this.source||"link-line"===this.source||"quote-line"===this.source},isLine:function(){return"line"===this.source},isCurveLine:function(){return"curve-line"===this.source},isOrthoLine:function(){return"ortho-line"===this.source},isSmartLine:function(){return"smart-line"===this.source},isSmartLineHub:function(){return"smart-line-hub"===this.source},isPolyline:function(){return"poly-line"===this.source},isLinkLine:function(){return"link-line"===this.source},isQuoteLine:function(){return"quote-line"===this.source},isText:function(){return"text"===this.source},equals:function(e){if(!e)return!1;if((this.signature||e.signature)&&this.signature!==e.signature)return!1;if((this.group||e.group)&&this.group!==e.group)return!1;if((this.name||e.name)&&this.name!==e.name)return!1;if((this.family||e.family)&&this.family!==e.family)return!1;if((this.description||e.description)&&this.description!==e.description)return!1;if((this.layer||e.layer)&&this.layer!==e.layer)return!1;if((this.x||e.x)&&this.x!==e.x)return!1;if((this.y||e.y)&&this.y!==e.y)return!1;if((this.z||e.z)&&this.z!==e.z)return!1;if((this.width||e.width)&&this.width!==e.width)return!1;if((this.height||e.height)&&this.height!==e.height)return!1;if((this.depth||e.depth)&&this.depth!==e.depth)return!1;if((this.rotation||e.rotation)&&this.rotation!==e.rotation)return!1;if((this.text||e.text)&&this.text!==e.text)return!1;if((this.behaviour||e.behaviour)&&this.behaviour!==e.behaviour)return!1;if((this.collisionClass||e.collisionClass)&&this.collisionClass!==e.collisionClass)return!1;if((this.containerClass||e.containerClass)&&this.containerClass!==e.containerClass)return!1;if((this.eventClass||e.eventClass)&&this.eventClass!==e.eventClass)return!1;if((this.linkClass||e.linkClass)&&this.linkClass!==e.linkClass)return!1;if((this.snapClass||e.snapClass)&&this.snapClass!==e.snapClass)return!1;if((this.links||e.links)&&this.links!==e.links)return!1;if((this.path||e.path)&&this.path!==e.path)return!1;if((this.ctrl1x||e.ctrl1x)&&this.ctrl1x!==e.ctrl1x)return!1;if((this.ctrl1y||e.ctrl1y)&&this.ctrl1y!==e.ctrl1y)return!1;if((this.ctrl2x||e.ctrl2x)&&this.ctrl2x!==e.ctrl2x)return!1;if((this.ctrl2y||e.ctrl2y)&&this.ctrl2y!==e.ctrl2y)return!1;if((this.shapeFromId||e.shapeFromId)&&this.shapeFromId!==e.shapeFromId)return!1;if((this.shapeFromPointIndex||e.shapeFromPointIndex)&&this.shapeFromPointIndex!==e.shapeFromPointIndex)return!1;if((this.shapeToId||e.shapeToId)&&this.shapeToId!==e.shapeToId)return!1;if((this.shapeToPointIndex||e.shapeToPointIndex)&&this.shapeToPointIndex!==e.shapeToPointIndex)return!1;if((this.dimStack||e.dimStack)&&this.dimStack!==e.dimStack)return!1;if((this.dimType||e.dimType)&&this.dimType!==e.dimType)return!1;if((this.dimDriving||e.dimDriving)&&this.dimDriving!==e.dimDriving)return!1;if((this.dimValue||e.dimValue)&&this.dimValue!==e.dimValue)return!1;if((this.color||e.color)&&this.color!==e.color)return!1;if((this.colorOpacity||e.colorOpacity)&&this.colorOpacity!==e.colorOpacity)return!1;if((this.lineColor||e.lineColor)&&this.lineColor!==e.lineColor)return!1;if((this.lineWidth||e.lineWidth)&&this.lineWidth!==e.lineWidth)return!1;if((this.lineOpacity||e.lineOpacity)&&this.lineOpacity!==e.lineOpacity)return!1;if((this.color3D||e.color3D)&&this.color3D!==e.color3D)return!1;if((this.colorOpacity3D||e.colorOpacity3D)&&this.colorOpacity3D!==e.colorOpacity3D)return!1;if((this.lineColor3D||e.lineColor3D)&&this.lineColor3D!==e.lineColor3D)return!1;if((this.lineOpacity3D||e.lineOpacity3D)&&this.lineOpacity3D!==e.lineOpacity3D)return!1;if((this.pinned||e.pinned)&&this.pinned!==e.pinned)return!1;if((this.includeInBOM||e.includeInBOM)&&this.includeInBOM!==e.includeInBOM)return!1;var t="object"==typeof this.custom,i="object"==typeof e.custom;if(t&&i){for(var n in this.custom)if(this.custom.hasOwnProperty(n)&&this.custom[n]!==e.custom[n])return!1}else{if(t)return!1;if(i)return!1}return!0},equalsObject:function(e){if(!e)return!1;if((this.signature||e.signature)&&this.signature!==e.signature)return!1;if((this.group||e.group)&&this.group!==e.group)return!1;if((this.name||e.name)&&this.name!==e.name)return!1;if((this.family||e.family)&&this.family!==e.family)return!1;if((this.description||e.description)&&this.description!==e.description)return!1;if((this.layer||e.layer)&&this.layer!==e.layer)return!1;if((this.x||e.x)&&this.x!==e.x)return!1;if((this.y||e.y)&&this.y!==e.y)return!1;if((this.z||e.z)&&this.z!==e.z)return!1;if((this.width||e.width)&&this.width!==e.width)return!1;if((this.height||e.height)&&this.height!==e.height)return!1;if((this.depth||e.depth)&&this.depth!==e.depth)return!1;if((this.rotation||e.rotation)&&this.rotation!==e.rotation)return!1;if((this.text||e.text)&&this.text!==e.text)return!1;if((this.behaviour||e.behaviour)&&this.behaviour!==e.behaviour)return!1;if((this.path||e.path)&&this.path!==e.path)return!1;if((this.ctrl1x||e.ctrl1x)&&this.ctrl1x!==e.ctrl1x)return!1;if((this.ctrl1y||e.ctrl1y)&&this.ctrl1y!==e.ctrl1y)return!1;if((this.ctrl2x||e.ctrl2x)&&this.ctrl2x!==e.ctrl2x)return!1;if((this.ctrl2y||e.ctrl2y)&&this.ctrl2y!==e.ctrl2y)return!1;if((this.shapeFromId||e.shapeFromId)&&this.shapeFromId!==e.shapeFromId)return!1;if((this.shapeFromPointIndex||e.shapeFromPointIndex)&&this.shapeFromPointIndex!==e.shapeFromPointIndex)return!1;if((this.shapeToId||e.shapeToId)&&this.shapeToId!==e.shapeToId)return!1;if((this.shapeToPointIndex||e.shapeToPointIndex)&&this.shapeToPointIndex!==e.shapeToPointIndex)return!1;if((this.dimStack||e.dimStack)&&this.dimStack!==e.dimStack)return!1;if((this.dimType||e.dimType)&&this.dimType!==e.dimType)return!1;if((this.dimDriving||e.dimDriving)&&this.dimDriving!==e.dimDriving)return!1;if((this.dimValue||e.dimValue)&&this.dimValue!==e.dimValue)return!1;if((this.color||e.color)&&this.color!==e.color)return!1;if((this.colorOpacity||e.colorOpacity)&&this.colorOpacity!==e.colorOpacity)return!1;if((this.lineColor||e.lineColor)&&this.lineColor!==e.lineColor)return!1;if((this.lineWidth||e.lineWidth)&&this.lineWidth!==e.lineWidth)return!1;if((this.lineOpacity||e.lineOpacity)&&this.lineOpacity!==e.lineOpacity)return!1;if((this.color3D||e.color3D)&&this.color3D!==e.color3D)return!1;if((this.colorOpacity3D||e.colorOpacity3D)&&this.colorOpacity3D!==e.colorOpacity3D)return!1;if((this.lineColor3D||e.lineColor3D)&&this.lineColor3D!==e.lineColor3D)return!1;if((this.lineOpacity3D||e.lineOpacity3D)&&this.lineOpacity3D!==e.lineOpacity3D)return!1;if((this.pinned||e.pinned)&&this.pinned!==e.pinned)return!1;if((this.includeInBOM||e.includeInBOM)&&this.includeInBOM!==e.includeInBOM)return!1;if("object"==typeof this.custom)for(var t in this.custom)if(this.custom.hasOwnProperty(t)&&this.custom[t]!==e[t])return!1;var i=JSON.stringify(this);return JSON.stringify(e)==i},copyFrom:function(e){e&&(this.signature=e.signature,this.group=e.group,this.name=e.name,this.family=e.family,this.description=e.description,this.layer=e.layer,this.x=e.x,this.y=e.y,this.z=e.z,this.width=e.width,this.height=e.height,this.depth=e.depth,this.rotation=e.rotation,this.text=e.text,this.behaviour=e.behaviour,e.collisionClass&&(this.collisionClass=e.collisionClass),e.containerClass&&(this.containerClass=e.containerClass),e.eventClass&&(this.eventClass=e.eventClass),e.linkClass&&(this.linkClass=e.linkClass),e.snapClass&&(this.snapClass=e.snapClass),this.links=e.links,this.path=e.path,this.ctrl1x=e.ctrl1x,this.ctrl1y=e.ctrl1y,this.ctrl2x=e.ctrl2x,this.ctrl2y=e.ctrl2y,this.shapeFromId=e.shapeFromId,this.shapeFromPointIndex=e.shapeFromPointIndex,this.shapeToId=e.shapeToId,this.shapeToPointIndex=e.shapeToPointIndex,this.dimStack=e.dimStack,this.dimType=e.dimType,this.dimDriving=e.dimDriving,this.dimValue=e.dimValue,this.color=e.color,this.colorOpacity=e.colorOpacity,this.lineColor=e.lineColor,this.lineWidth=e.lineWidth,this.lineOpacity=e.lineOpacity,this.color3D=e.color3D,this.colorOpacity3D=e.colorOpacity3D,this.lineColor3D=e.lineColor3D,this.lineOpacity3D=e.lineOpacity3D,this.pinned=e.pinned,this.includeInBOM=e.includeInBOM,e.custom&&!$.isEmptyObject(e.custom)&&(this.custom=e.custom),this._updateBehaviour())},update:function(e,t,i,n,o,s,r,a,l){!e&&"number"!=typeof e||e===this.x||(this.x=e,this.modified=!0),!t&&"number"!=typeof t||t===this.y||(this.y=t,this.modified=!0),!i&&"number"!=typeof i||i===this.z||(this.z=i,this.modified=!0),!n&&"number"!=typeof n||n===this.width||(this.width=n,this.modified=!0),!o&&"number"!=typeof o||o===this.height||(this.height=o,this.modified=!0),!s&&"number"!=typeof s||s===this.depth||(this.depth=s,this.modified=!0),!r&&"number"!=typeof r||r===this.rotation||(this.rotation=r,this.modified=!0),a&&a!==this.text&&(this.text=a,this.modified=!0);var h=E2DGlobals.e2d.renderer3d;h&&!l&&this.id!==E2DGlobals.e2d.ORIGIN_ID&&this.id!==E2DGlobals.e2d.CUSTOM_ORIGIN_ID&&h.updateObject(this)},updateConnector:function(e){var t=E2DGlobals.e2d,i=t.renderer.bounds(e),n=E2DUtils.round(t.convertGraphXToUserX(i.x),t.numberOfDecimal),o=E2DUtils.round(t.convertGraphYToUserY(i.y),t.numberOfDecimal),s=E2DUtils.round(t.convertGraphXToUserX(i.x2),t.numberOfDecimal),r=E2DUtils.round(t.convertGraphYToUserY(i.y2),t.numberOfDecimal),a=t.renderer.getShapeText(e);if(n!==this.x&&(this.x=n,this.modified=!0),o!==this.y&&(this.y=o,this.modified=!0),this.z=0,s!==this.width&&(this.width=s,this.modified=!0),r!==this.height&&(this.height=r,this.modified=!0),this.depth=1,a!==this.text&&(this.text=a,this.modified=!0),"ortho-line"===this.source||"poly-line"===this.source){var l=t.renderer.getPolylinePoints(e),h=t.convertPathToUserString(l);h!==this.path&&(this.path=h,this.modified=!0)}else this.path="";if("curve-line"===this.source){var d=t.renderer.getControl1(e),c=E2DUtils.round(t.convertGraphXToUserX(d.x),t.numberOfDecimal),u=E2DUtils.round(t.convertGraphYToUserY(d.y),t.numberOfDecimal);c!==this.ctrl1x&&(this.ctrl1x=c,this.modified=!0),u!==this.ctrl1y&&(this.ctrl1y=u,this.modified=!0),d=t.renderer.getControl2(e),c=E2DUtils.round(t.convertGraphXToUserX(d.x),t.numberOfDecimal),u=E2DUtils.round(t.convertGraphYToUserY(d.y),t.numberOfDecimal),c!==this.ctrl2x&&(this.ctrl2x=c,this.modified=!0),u!==this.ctrl2y&&(this.ctrl2y=u,this.modified=!0)}if("quote-line"===this.source){i.dimType!==this.dimType&&(this.dimType=i.dimType,this.modified=!0),i.dimDriving!==this.dimDriving&&(this.dimDriving=i.dimDriving,this.modified=!0);var p=E2DUtils.round(t.convertGraphDataToUserData(i.dimStack),t.numberOfDecimal);p!==this.dimStack&&(this.dimStack=p,this.modified=!0);var g=E2DUtils.round(t.convertGraphDataToUserData(i.dimValue),t.numberOfDecimal);g!==this.dimValue&&(this.dimValue=g,this.modified=!0)}var y=t.insertedShapes.getConnectionShape(e.id,"from");y.shapeID!==this.shapeFromId&&(this.shapeFromId=y.shapeID,this.modified=!0),y.pointID!==this.shapeFromPointIndex&&(this.shapeFromPointIndex=y.pointID,this.modified=!0);var f=t.insertedShapes.getConnectionShape(e.id,"to");f.shapeID!==this.shapeToId&&(this.shapeToId=f.shapeID,this.modified=!0),f.pointID!==this.shapeToPointIndex&&(this.shapeToPointIndex=f.pointID,this.modified=!0);var v=t.renderer.getLineColor(e);v!==this.lineColor&&(this.lineColor=v,this.modified=!0);var m=t.renderer.getLineWidth(e);m!==this.lineWidth&&(this.lineWidth=m,this.modified=!0),this.lineOpacity=null;var S=E2DGlobals.e2d.renderer3d;S&&"poly-line"===this.source&&S.updatePolyLine(this)},update3D:function(){var e=E2DGlobals.e2d.renderer3d;e&&("poly-line"===this.source?e.updatePolyLine(this):this.id!==E2DGlobals.e2d.ORIGIN_ID&&this.id!==E2DGlobals.e2d.CUSTOM_ORIGIN_ID&&e.updateObject(this))},getShapeCenter:function(){var e=E2DGlobals.e2d,t={x:0,y:0,z:this.z},i="TOPLEFT",n=this.decodeBehaviour("(ORIGIN=");switch(n.found&&(i=n.value),i){case"CENTER":t.x=1*this.x,t.y=1*this.y;break;case"TOPLEFT":t.x=1*this.x+this.width/2*e.origin.signX,t.y=1*this.y+this.height/2*e.origin.signY;break;case"TOPRIGHT":t.x=1*this.x-this.width/2*e.origin.signX,t.y=1*this.y+this.height/2*e.origin.signY;break;case"BOTTOMLEFT":t.x=1*this.x+this.width/2*e.origin.signX,t.y=1*this.y-this.height/2*e.origin.signY;break;case"BOTTOMRIGHT":t.x=1*this.x-this.width/2*e.origin.signX,t.y=1*this.y-this.height/2*e.origin.signY;break;default:var o=i.split(",");2===o.length&&(t.x=1*this.x+e.convertGraphDataToUserData(o[0])*e.origin.signX,t.y=1*this.y+e.convertGraphDataToUserData(o[1])*e.origin.signY)}return t},getIdAndGroupInfo:function(){return this.id+(this.group?";"+this.group:"")},getSignature:function(){return this.signature?this.signature:this.source+"_"+this.width+"_"+this.height+"_"+this.depth},addLineConnection:function(e,t,i){var n=this.lineConnections[e];n.shapeID=t,n.pointID=i},addShapeConnection:function(e,t,i,n){this.shapeConnections[this.shapeConnections.length]={type:e,lineID:t,lineType:i,cpID:n}},removeShapeConnection:function(e,t,i){for(var n=[],o=0,s=this.shapeConnections.length;o<s;o++){var r=this.shapeConnections[o];r.type===e&&r.lineID===t&&r.cpID===i&&(n[n.length]=o)}for(var a=n.length-1;a>=0;a--)this.shapeConnections.splice(n[a],1)},setCalculatedBehaviourMove:function(e){E2DGlobals.e2d.isShapesLoadPending()||(this.calculatedBehaviour||(this.calculatedBehaviour={}),this.calculatedBehaviour.move=e)},setCalculatedBehaviourStretch:function(e){E2DGlobals.e2d.isShapesLoadPending()||(this.calculatedBehaviour||(this.calculatedBehaviour={}),this.calculatedBehaviour.stretch=e)},setCalculatedPinnedX:function(e){E2DGlobals.e2d.isShapesLoadPending()||(this.calculatedPinned||(this.calculatedPinned={}),this.calculatedPinned.pinnedX=e)},setCalculatedPinnedY:function(e){E2DGlobals.e2d.isShapesLoadPending()||(this.calculatedPinned||(this.calculatedPinned={}),this.calculatedPinned.pinnedY=e)},setCalculatedPinnedZ:function(e){E2DGlobals.e2d.isShapesLoadPending()||(this.calculatedPinned||(this.calculatedPinned={}),this.calculatedPinned.pinnedZ=e)},setProps:function(e,t){this.layer=t,void 0!==e&null!==e&&(this.pinned=e)}},InsertedShapes.GroupMap={},InsertedShapes.GetNextGroupOccurrence=function(e){return e?(InsertedShapes.GroupMap[e]||(InsertedShapes.GroupMap[e]=0),e+":"+ ++InsertedShapes.GroupMap[e]):""},InsertedShapes.SetGroupOccurrence=function(e){if(e){var t=e.split(":");2===t.length&&(t[1]*=1,InsertedShapes.GroupMap[t[0]]?t[1]>InsertedShapes.GroupMap[t[0]]&&(InsertedShapes.GroupMap[t[0]]=t[1]):InsertedShapes.GroupMap[t[0]]=t[1])}},InsertedShapes.prototype={removeGroupInfo:function(e){if(e)for(var t=E2DUtils.objectValues(this.insertedShapeMap),i=0,n=t.length;i<n;i++)t[i].group===e&&(t[i].group=null)},reset:function(){this.insertedShapeMap={},this.alwaysInBack={},this.alwaysInFront={},this.origin=null,this.customOrigin=null},clearCalculated:function(){for(var e in this.insertedShapeMap)this.insertedShapeMap.hasOwnProperty(e)&&this.insertedShapeMap[e].clearCalculated()},getCount:function(){return E2DUtils.objectSize(this.insertedShapeMap)},getIDs:function(){return E2DUtils.objectKeys(this.insertedShapeMap)},addShape:function(e,t){if(e&&null!==e.id&&e.id!==E2DGlobals.e2d.renderer.MULTIPLE_SELECTOR_TRACKER_ID)if(e.id!==E2DGlobals.e2d.ORIGIN_ID)if(e.id!==E2DGlobals.e2d.CUSTOM_ORIGIN_ID){if(!this.insertedShapeMap[e.id]){this.insertedShapeMap[e.id]=e,e.hasBehaviour("(ALWAYSBACK)")&&(this.alwaysInBack[e.id]=!0),e.hasBehaviour("(ALWAYSFRONT)")&&(this.alwaysInFront[e.id]=!0);var i=E2DGlobals.e2d;if(i.renderer3d&&!t&&e.id!==i.ORIGIN_ID&&e.id!==i.CUSTOM_ORIGIN_ID&&e.source!==i.CONNECTION_POINT_CLASS&&!e.isText()&&!e.isSmartLineHub()){if(e.isConnector()&&!e.isPolyline())return;var n=i.selected&&i.selected.id===e.id,o=i.libraryProperties[e.getFullSource()];i.renderer3d.addObject(e,o,n,!1)}}}else this.customOrigin=e;else this.origin=e},removeShape:function(e){return e?this.removeShapeById(e.id):null},removeShapeById:function(e){if(null===e||e===E2DGlobals.e2d.renderer.MULTIPLE_SELECTOR_TRACKER_ID)return null;if(e!==E2DGlobals.e2d.ORIGIN_ID){if(e!==E2DGlobals.e2d.CUSTOM_ORIGIN_ID){if(!this.insertedShapeMap[e])return null;var t=this.insertedShapeMap[e];delete this.insertedShapeMap[e];var i=E2DGlobals.e2d.renderer3d;return i&&i.removeObject(e),this.removeGroupInfo(t.group),this.alwaysInBack[e]&&delete this.alwaysInBack[e],this.alwaysInFront[e]&&delete this.alwaysInFront[e],t}this.customOrigin=null}else this.origin=null},contains:function(e){return e.id===E2DGlobals.e2d.ORIGIN_ID?null!==this.origin:e.id===E2DGlobals.e2d.CUSTOM_ORIGIN_ID?null!==this.customOrigin:e&&null!==this.insertedShapeMap[e.id]},containsById:function(e){return e===E2DGlobals.e2d.ORIGIN_ID?null!==this.origin:e===E2DGlobals.e2d.CUSTOM_ORIGIN_ID?null!==this.customOrigin:e&&null!==this.insertedShapeMap[e]},getShapes:function(e,t){for(var i=null,n=E2DUtils.objectValues(this.insertedShapeMap),o=0,s=n.length;o<s;o++){(i=n[o]).links=[];var r=i.shapeConnections;if(r&&r.length>0)for(var a=0,l=r.length;a<l;a++){var h=r[a];if("link-line"===h.lineType){var d=this.getOtherConnectedShape(h.lineID,i.id);d&&(i.links[i.links.length]=h.cpID+";"+d.getIdAndGroupInfo())}}}if(e){for(var c=[],u=0,p=n.length;u<p;u++){(i=InsertedShape.CloneShape(n[u])).collisionClass=null,i.containerClass=null,i.eventClass=null,i.linkClass=null,i.snapClass=null,i.image=null,i.imageSVG=null,i.lineConnections=null,i.shapeConnections=null,i.calculatedBehaviour=null,i.calculatedPinned=null;var g=[];for(var y in i)i.hasOwnProperty(y)&&(i[y]?"function"==typeof i[y]&&(g[g.length]=y):g[g.length]=y);for(var f=0,v=g.length;f<v;f++)delete i[g[f]];if(i.custom){for(var m in i.custom)i.custom.hasOwnProperty(m)&&(i[m]=i.custom[m]);delete i.custom}c.push(i)}n=c}if(t){for(var S=[],E=0,D=n.length;E<D;E++)n[E].isConnector()||S.push(n[E]);n=S}return n},getJSONShapes:function(){const e=Object.values(this.insertedShapeMap);return JSON.stringify(e,function(e,t){if(t)return t})},getShapeById:function(e){return e===E2DGlobals.e2d.ORIGIN_ID?this.origin:e===E2DGlobals.e2d.CUSTOM_ORIGIN_ID?this.customOrigin:this.insertedShapeMap[e]},getShapesByGroup:function(e){var t=[],i=E2DUtils.objectValues(this.insertedShapeMap);if(i&&i.length>0)for(var n=0,o=i.length;n<o;n++)i[n].group===e&&(t[t.length]=i[n]);return t},getShapesByIds:function(e,t){var i=[];if(e&&e.length>0)for(var n=0,o=e.length;n<o;n++){var s=this.insertedShapeMap[e[n]];s&&(i[i.length]=t?InsertedShape.CloneShape(s):s)}return i},isCircularReference:function(e,t,i,n,o){var s=this.getConnectionShape(t.id,"from");if(o&&o.length>0&&s.shapeID===e)return!0;var r=this.getAttachedLines(e,[i],n);if(0===r.length)return!1;o=o||[];for(var a=0,l=r.length;a<l;a++)if(-1===o.indexOf(r[a])){o[o.length]=r[a];var h=this.getConnectionShape(r[a],"from");if(h.shapeID&&h.shapeID!==e&&this.isCircularReference(h.shapeID,t,i,n,o))return!0;var d=this.getConnectionShape(r[a],"to");if(d.shapeID&&d.shapeID!==e&&this.isCircularReference(d.shapeID,t,i,n,o))return!0}return!1},getCircularReference:function(e,t,i,n,o){var s={circular:!1,offendingLine:null},r=this.getConnectionShape(t.id,"from");if(o&&o.length>0&&r.shapeID===e)return s.circular=!0,s.offendingLine=o&&o.length>0?o[o.length-1]:t.id,s;var a=this.getAttachedLines(e,[i],n);if(0===a.length)return s;o=o||[];for(var l=0,h=a.length;l<h;l++)if(-1===o.indexOf(a[l])){o[o.length]=a[l];var d=null,c=this.getConnectionShape(a[l],"from");if(c.shapeID&&c.shapeID!==e&&(d=this.getCircularReference(c.shapeID,t,i,n,o)).circular)return d;var u=this.getConnectionShape(a[l],"to");if(u.shapeID&&u.shapeID!==e&&(d=this.getCircularReference(u.shapeID,t,i,n,o)).circular)return d}return s},getConnectionShape:function(e,t){var i=this.getShapeById(e);return i?i.lineConnections[t]:{shapeID:"",pointID:""}},getOtherConnectedShape:function(e,t){var i=this.getShapeById(e);return i?t===i.shapeFromId&&i.shapeToId?this.getShapeById(i.shapeToId):t===i.shapeToId&&i.shapeFromId?this.getShapeById(i.shapeFromId):null:null},getAttachedLines:function(e,t,i){if(!e)return[];var n=[],o=this.insertedShapeMap[e];if(o&&o.shapeConnections&&o.shapeConnections.length>0)for(var s=o.shapeConnections,r=0,a=s.length;r<a;r++){var l=s[r],h=this.insertedShapeMap[l.lineID];if(h&&(!t||0===t.length||t.length>0&&-1!==t.indexOf(l.lineType)))if(i){if(i.driving&&h.isQuoteLine()&&h.dimDriving&&(n[n.length]=h.id),i.ignoreConnectionsWithNOMOVEShapes){var d=this.getOtherConnectedShape(h.id,o.id);d&&!d.hasBehaviour("(NOMOVE)")&&(n[n.length]=h.id)}}else n[n.length]=h.id}return n},getAttachedLinesDeep:function(e,t,i,n){if(!e)return[];n=n||[];var o=[],s=this.insertedShapeMap[e];if(s&&s.shapeConnections&&s.shapeConnections.length>0)for(var r=s.shapeConnections,a=0,l=r.length;a<l;a++){var h=r[a];if(!n[h.lineID]){var d=this.insertedShapeMap[h.lineID];if(d&&(!t||0===t.length||t.length>0&&-1!==t.indexOf(h.lineType))){n[d.id]=!0;var c=this.getOtherConnectedShape(d.id,s.id);if(i){if(i.driving&&d.isQuoteLine()&&d.dimDriving&&(o[d.id]=!0),i.ignoreConnectionsWithNOMOVEShapes&&(o[d.id]=!0,c&&c.hasBehaviour("(NOMOVE)")))continue}else o[d.id]=!0;if(c){var u=this.getAttachedLinesDeep(c.id,t,i,n);if(u&&u.length>0)for(var p=0,g=u.length;p<g;p++)o[u[p]]=!0}}}}return E2DUtils.objectKeys(o)},getAttachedLinkLines:function(e,t){return t?this.getAttachedLinesDeep(e,["link-line"]):this.getAttachedLines(e,["link-line"])},getAttachedQuoteAndLinkLines:function(e,t,i){return t?this.getAttachedLinesDeep(e,["quote-line","link-line"],i):this.getAttachedLines(e,["quote-line","link-line"],i)},getAttachedQuoteLines:function(e,t){return t?this.getAttachedLinesDeep(e,["quote-line"]):this.getAttachedLines(e,["quote-line"])},getAttachedSmartLines:function(e,t){return t?this.getAttachedLinesDeep(e,["smart-line"]):this.getAttachedLines(e,["smart-line"])},getAttachedShapes:function(e,t,i){if(!e)return[];var n=!(!i||!i.driving),o=!(!i||!i.includeLines),s=i&&i.excludeIds&&i.excludeIds.length>0?i.excludeIds:null,r=[],a=this.insertedShapeMap[e];if(a&&a.shapeConnections&&a.shapeConnections.length>0)for(var l=a.shapeConnections,h=0,d=l.length;h<d;h++){var c=l[h];if(!s||-1===s.indexOf(c.lineID)){var u=this.insertedShapeMap[c.lineID];if(u&&(!t||0===t.length||t.length>0&&-1!==t.indexOf(c.lineType))){if(n&&u.isQuoteLine()&&!u.dimDriving)continue;o&&-1===r.indexOf(u.id)&&(r[r.length]=u.id);var p=this.getOtherConnectedShape(u.id,a.id);!p||s&&-1!==s.indexOf(p.id)||(r[r.length]=p.id)}}}return r},getAttachedShapesDeep:function(e,t,i,n,o){if(!e)return[];n=n||[],o=o||[];var s=!(!i||!i.driving),r=!(!i||!i.includeLines),a=i&&i.excludeIds&&i.excludeIds.length>0?i.excludeIds:null,l=this.insertedShapeMap[e];if(l&&l.shapeConnections&&l.shapeConnections.length>0)for(var h=l.shapeConnections,d=0,c=h.length;d<c;d++){var u=h[d];if(!(o[u.lineID]||a&&-1!==a.indexOf(u.lineID))){var p=this.insertedShapeMap[u.lineID];if(p&&(!t||0===t.length||t.length>0&&-1!==t.indexOf(u.lineType))){if(o[p.id]=!0,s&&p.isQuoteLine()&&!p.dimDriving)continue;r&&!n[p.id]&&(n[p.id]=!0);var g=this.getOtherConnectedShape(p.id,l.id);!g||n[g.id]||a&&-1!==a.indexOf(g.id)||(n[g.id]=!0,this.getAttachedShapesDeep(g.id,t,i,n,o))}}}return E2DUtils.objectKeys(n)},getAttachedShapesWithQuotes:function(e,t,i,n){i=i||{origID:e,hList:[],vList:[],qList:[],sList:[],checkHorizontal:!0,checkVertical:!0};for(var o=E2DGlobals.e2d.renderer,s=this.getAttachedQuoteLines(e,!1),r=0,a=s.length;r<a;r++){var l=s[r];if(!i.qList[l]&&l!==t){var h=this.insertedShapeMap[l];if(h.dimDriving){if(e===i.origID){i.checkHorizontal=0===h.dimType||1===h.dimType,i.checkVertical=0===h.dimType||2===h.dimType;var d=this.getConnectionShape(l,"from"),c=this.getConnectionShape(l,"to"),u=document.getElementById(l),p=null,g=null;if(e===d.shapeID){var y=document.getElementById(d.shapeID);p=o.getConnectionPointObjByPointId(y,d.pointID),g=o.getConnectorFrom(u)}else{var f=document.getElementById(c.shapeID);p=o.getConnectionPointObjByPointId(f,c.pointID),g=o.getConnectorTo(u)}if(n={x:p.x-g.x,y:p.y-g.y},Math.abs(n.x)<1e-6&&Math.abs(n.y)<1e-6)continue}else{if(1===h.dimType&&!i.checkHorizontal)continue;if(2===h.dimType&&!i.checkVertical)continue}var v=this.getOtherConnectedShape(l,e);if(v&&v.id!==i.origID){var m=document.getElementById(v.id);if(m){switch(h.dimType){case 0:i.hList[l]||(i.hList[l]={shape:m,delta:n}),i.vList[l]||(i.vList[l]={shape:m,delta:n});break;case 1:if(i.hList[l])continue;i.hList[l]={shape:m,delta:n};break;case 2:if(i.vList[l])continue;i.vList[l]={shape:m,delta:n}}i.sList[m.id]=!0,i.qList[l]=!0,this.getAttachedShapesWithQuotes(m.id,t,i,n)}}}}}return i},isShapeConnectedWith:function(e,t){if(!e)return!1;if(!t||!t.length)return!1;for(var i=0,n=t.length;i<n;i++){var o=this.getConnectionShape(t[i],"from"),s=this.getConnectionShape(t[i],"to");if(o.shapeID===e||s.shapeID===e)return!0}return!1},areShapesConnectedWithQuote:function(e,t,i){if(!e||!t)return!1;var n=this.getAttachedQuoteLines(e,!1);if(n&&n.length>0)for(var o=0,s=n.length;o<s;o++){var r=this.insertedShapeMap[n[o]];if(r){var a=this.getOtherConnectedShape(r.id,e);if(a&&a.id===t&&i&&r.dimDriving)return!0}}return!1},isPinned:function(e,t){var i={pinnedX:!1,pinnedY:!1,pinnedZ:!1};return e?(i.pinnedX=this.isPinnedX(e,t,null),i.pinnedY=this.isPinnedY(e,t,null),i.pinnedZ=this.isPinnedZ(e,t,null),i):i},isPinnedX:function(e,t,i){if(!e)return null;var n=this.insertedShapeMap[e];if(!n)return!1;if(n.calculatedPinned&&"boolean"==typeof n.calculatedPinned.pinnedX)return n.calculatedPinned.pinnedX;if(n.pinned||n.hasBehaviour("(NOMOVE)")||n.hasBehaviour("(NOXMOVE)")||n.hasBehaviour("(NOHMOVE)")||n.isPolyline())return n.setCalculatedPinnedX(!0),!0;i=i||[];var o=this.getAttachedQuoteAndLinkLines(e,!1);if(o&&o.length>0)for(var s=0,r=o.length;s<r;s++){var a=o[s];if(!(t&&t.length>0&&-1!==t.indexOf(a))){var l=this.insertedShapeMap[a];if(!l.isQuoteLine()||l.dimDriving&&1===l.dimType){var h=this.getOtherConnectedShape(a,e);if(h){if(h.isPolyline())return n.setCalculatedPinnedX(!0),!0;if(!i[h.id])if(i[e]=!0,this.isPinnedX(h.id,t,i))return n.setCalculatedPinnedX(!0),!0}}}}return n.setCalculatedPinnedX(!1),!1},isPinnedY:function(e,t,i){if(!e)return null;var n=this.insertedShapeMap[e];if(!n)return!1;if(n.calculatedPinned&&"boolean"==typeof n.calculatedPinned.pinnedY)return n.calculatedPinned.pinnedY;if(n.pinned||n.hasBehaviour("(NOMOVE)")||n.hasBehaviour("(NOYMOVE)")||n.hasBehaviour("(NOVMOVE)")||n.isPolyline())return n.setCalculatedPinnedY(!0),!0;i=i||[];var o=this.getAttachedQuoteAndLinkLines(e,!1);if(o&&o.length>0)for(var s=0,r=o.length;s<r;s++){var a=o[s];if(!(t&&t.length>0&&-1!==t.indexOf(a))){var l=this.insertedShapeMap[a];if(!l.isQuoteLine()||l.dimDriving&&2===l.dimType){var h=this.getOtherConnectedShape(a,e);if(h){if(h.isPolyline())return n.setCalculatedPinnedY(!0),!0;if(i[h.id])if(i[e]=!0,this.isPinnedY(h.id,t,i))return n.setCalculatedPinnedY(!0),!0}}}}return n.setCalculatedPinnedY(!1),!1},isPinnedZ:function(e,t,i){if(!e)return null;var n=this.insertedShapeMap[e];return!!n&&(n.calculatedPinned&&"boolean"==typeof n.calculatedPinned.pinnedZ?n.calculatedPinned.pinnedZ:n.pinned||n.hasBehaviour("(NOMOVE)")||n.hasBehaviour("(NOZMOVE)")||n.hasBehaviour("(NODMOVE)")||n.isPolyline()?(n.setCalculatedPinnedZ(!0),!0):(n.setCalculatedPinnedZ(!1),!1))},hasBehaviour:function(e,t){return!!this.containsById(e)&&this.insertedShapeMap[e].hasBehaviour(t)},decodeBehaviour:function(e,t){return this.containsById(e)?this.insertedShapeMap[e].decodeBehaviour(t):{found:!1,value:""}},resetBehaviour:function(e){for(var t=E2DUtils.objectValues(this.insertedShapeMap),i=0,n=t.length;i<n;i++)t[i].removeBehaviour(e)},hasSameCollisionClass:function(e,t){return this.hasSameClass("collision",e,t)},hasSameContainerClass:function(e,t){return this.hasSameClass("container",e,t)},hasSameLinkClass:function(e,t){return this.hasSameClass("link",e,t)},hasSameSnapClass:function(e,t){return this.hasSameClass("snap",e,t)},hasSameClass:function(e,t,i){var n=null,o=null;if(this.containsById(t)&&(n=this.insertedShapeMap[t]),!n)return!0;if(this.containsById(i)&&(o=this.insertedShapeMap[i]),!o)return!0;switch(e){case"collision":return n.hasSameCollisionClass(o);case"container":return n.hasSameContainerClass(o);case"link":return n.hasSameLinkClass(o);case"snap":return n.hasSameSnapClass(o)}return!0},updateConnector:function(e){var t=this.insertedShapeMap[e.id];t&&t.updateConnector(e)},onShapeSelected:function(e,t){this.insertedShapeMap[e.target]&&(this.insertedShapeMap[e.target].selected=t)}},SelectedShapes.prototype={recalculateBounds:function(){this.setSelectedShapes(this.getShapes())},reset:function(e){for(var t=E2DUtils.objectKeys(this.selectedShapeMap),i=0,n=t.length;i<n;i++)this.selectedShapeMap[t[i]].classList.remove("firstselectionghost"),this.selectedShapeMap[t[i]].classList.remove("selectionghost"),e||E2DEventBus.dispatch("shapeMultiSelected",t[i],!1);this.bbox={x:null,y:null,width:null,height:null,depth:null,right:null,bottom:null,ceiling:null},this.selectedShapeMap={},this.selectedShapeBounds={},this.idLowest=null,this.idHighest=null,this.idLowestZ=null,this.idHighestZ=null},setSelectedShapes:function(e,t){this.reset();for(var i=[],n=e.length,o=0;o<n;o++)e[o].id&&(i[i.length]=e[o].id);for(var s=0;s<n;s++)this.addShape(e[s],this.renderer.getBoundingBox(e[s]),i,t)},addShape:function(e,t,i,n){if(e&&e.id&&!this.selectedShapeMap[e.id]){var o=this.bbox.x,s=this.bbox.y,r=this.bbox.z;if((!this.bbox.x||t.x<this.bbox.x)&&(this.bbox.x=t.x,this.idLowest=e.id),(!this.bbox.y||t.y<this.bbox.y)&&(this.bbox.y=t.y,this.idLowest=e.id),(!this.bbox.z||t.z<this.bbox.z)&&(this.bbox.z=t.z,this.idLowestZ=e.id),(!this.bbox.width||t.x+t.width>o+this.bbox.width)&&(this.bbox.right=t.x+t.width,this.idHighest=e.id),(!this.bbox.height||t.y+t.height>s+this.bbox.height)&&(this.bbox.bottom=t.y+t.height,this.idHighest=e.id),(!this.bbox.depth||t.z+t.depth>r+this.bbox.depth)&&(this.bbox.ceiling=t.z+t.depth,this.idHighestZ=e.id),this.bbox.width=this.bbox.right-this.bbox.x,this.bbox.height=this.bbox.bottom-this.bbox.y,this.bbox.depth=this.bbox.ceiling-this.bbox.z,this.selectedShapeMap[e.id]=e,this.selectedShapeBounds[e.id]=this.renderer.bounds(e),!E2DGlobals.e2d.renderer.isConnector(e)){var a=E2DUtils.objectKeys(this.selectedShapeMap);if(this.prevSelected&&this.prevSelected.id===e.id){if(this.firstSelectionGhostID&&this.firstSelectionGhostID!==e.id){var l=document.getElementById(this.firstSelectionGhostID);l&&(l.classList.remove("firstselectionghost"),i&&i.indexOf&&-1!==i.indexOf(this.firstSelectionGhostID)&&l.classList.add("selectionghost"))}this.firstSelectionGhostID=e.id,e.classList.add("firstselectionghost")}else 1===a.length?(this.firstSelectionGhostID=e.id,e.classList.add("firstselectionghost")):e.classList.add("selectionghost")}n||E2DEventBus.dispatch("shapeMultiSelected",e.id,!0)}},removeShape:function(e,t){if(delete this.selectedShapeMap[e.id],e.classList.remove("firstselectionghost"),e.classList.remove("selectionghost"),this.prevSelected&&this.prevSelected.id===e.id){this.prevSelected=null;var i=E2DUtils.objectKeys(this.selectedShapeMap);i.length>0&&(this.selectedShapeMap[i[0]].classList.remove("selectionghost"),this.selectedShapeMap[i[0]].classList.add("firstselectionghost"))}return t||E2DEventBus.dispatch("shapeMultiSelected",e.id,!1),(e.id===this.idLowest||e.id===this.idHighest||e.id===this.idLowestZ||e.id===this.idHighestZ)&&(this.recalculateBounds(),!0)},contains:function(e){return e&&null!=this.selectedShapeMap[e.id]},containsById:function(e){return e&&null!=this.selectedShapeMap[e]},getShapeById:function(e){return this.selectedShapeMap[e]},getShapes:function(e){var t=null;if(e&&this.firstSelectionGhostID&&this.selectedShapeMap[this.firstSelectionGhostID]){var i=E2DUtils.cloneObject(this.selectedShapeMap);t=[i[this.firstSelectionGhostID]],delete i[this.firstSelectionGhostID],t=t.concat(E2DUtils.objectValues(i))}else t=E2DUtils.objectValues(this.selectedShapeMap);return t},getShapeIDs:function(){return E2DUtils.objectKeys(this.selectedShapeMap)},updateShapeBounds:function(){for(var e=E2DUtils.objectKeys(this.selectedShapeMap),t=0,i=e.length;t<i;t++)this.selectedShapeBounds[e[t]]=this.renderer.bounds(this.selectedShapeMap[e[t]]),this.setSelectedShapes(E2DUtils.objectValues(this.selectedShapeMap))},getSelectedBounds:function(e){return this.selectedShapeBounds[e]},getProportionalBoundsWidth:function(e,t,i,n){var o=this.selectedShapeBounds[t],s={};return s.width=e.width/i*o.width,n?o.x-this.bbox.x==0?s.x=e.x:s.x=1*e.x+e.width*((o.x-this.bbox.x)/i):s.x=1*o.x+(e.width-i)*((o.x-this.bbox.x)/i),s},getProportionalBoundsHeight:function(e,t,i,n){var o=this.selectedShapeBounds[t],s={};return s.height=e.height/i*o.height,n?o.y-this.bbox.y==0?s.y=e.y:s.y=1*e.y+e.height*((o.y-this.bbox.y)/i):s.y=1*o.y+(e.height-i)*((o.y-this.bbox.y)/i),s}},E2DFont={size:16,family:"sans-serif",color:"black",forced:!1,get:function(){return{size:E2DFont.size,family:E2DFont.family,color:E2DFont.color,forced:E2DFont.forced}},mergeWithDefault:function(e){return e?{size:e.size||E2DFont.size,family:e.family||E2DFont.family,color:e.color||E2DFont.color}:E2DFont.get()}},String.prototype.wordWrap=function(e,t,i){var n,o,s,r=this.split("\n");if(e>0)for(n in r){for(s=r[n],r[n]="";s.length>e;o=i?e:(o=s.substr(0,e).match(/\S*$/)).input.length-o[0].length||e,r[n]+=s.substr(0,o)+((s=s.substr(o)).length?t:""));r[n]+=s}return r.join("\n")},Array.prototype.diff=function(e){return this.filter(function(t){return e.indexOf(t)<0})},Array.prototype.removeFromTo=function(e,t){return this.splice(e,!t||1+t-e+(!(t<0^e>=0)&&(t<0||-1)*this.length)),this.length}; |