diff --git a/Editor2DLibrary/SSG/shapes/palettes/c_Parts.xml b/Editor2DLibrary/SSG/shapes/palettes/c_Parts.xml index 519f20c..0ff8e7d 100644 --- a/Editor2DLibrary/SSG/shapes/palettes/c_Parts.xml +++ b/Editor2DLibrary/SSG/shapes/palettes/c_Parts.xml @@ -6,4 +6,6 @@

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 =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 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 0){for(var i=[],n=0,o=e.length;n 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 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;i0)for(var n=i.shapeConnections,o=0,s=n.length;o0)for(var h=l.shapeConnection,d=0,c=h.length;d=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;e0)for(let t=0,i=e.length;t0){for(let e=0,i=t.length;el?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("+this.unit+")");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=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;s0&&(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;s0){t=t||[],i=i||[];for(var s=null,r=0,a=o.length;r{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=$("