@labelbee/lb-annotation 1.28.0-alpha.7 → 1.28.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/toolOperation/basicToolOperation.js +1 -1
- package/dist/core/toolOperation/pointCloud2dOperation.js +1 -1
- package/dist/core/toolOperation/polygonOperation.js +1 -1
- package/dist/core/toolOperation/rectOperation.js +2 -2
- package/dist/types/core/toolOperation/ScribbleTool.d.ts +1 -9
- package/dist/types/core/toolOperation/basicToolOperation.d.ts +6 -1
- package/dist/types/core/toolOperation/polygonOperation.d.ts +6 -11
- package/dist/types/core/toolOperation/rectOperation.d.ts +4 -2
- package/dist/types/utils/tool/AxisUtils.d.ts +3 -27
- package/dist/utils/tool/AxisUtils.js +1 -1
- package/dist/utils/tool/DrawUtils.js +1 -1
- package/dist/utils/tool/PolygonUtils.js +1 -1
- package/dist/utils/tool/polygonTool.js +1 -1
- package/es/core/toolOperation/basicToolOperation.js +1 -1
- package/es/core/toolOperation/pointCloud2dOperation.js +1 -1
- package/es/core/toolOperation/polygonOperation.js +1 -1
- package/es/core/toolOperation/rectOperation.js +2 -2
- package/es/utils/tool/AxisUtils.js +1 -1
- package/es/utils/tool/DrawUtils.js +3 -3
- package/es/utils/tool/PolygonUtils.js +1 -1
- package/es/utils/tool/polygonTool.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),_=require("lodash"),tool=require("../../constant/tool.js"),MathUtils=require("../../utils/MathUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),LineToolUtils=require("../../utils/tool/LineToolUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),style=require("../../constant/style.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),DblClickEventListener=require("../../utils/tool/DblClickEventListener.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),RenderDomUtils=require("../../utils/tool/RenderDomUtils.js"),ZoomUtils=require("../../utils/tool/ZoomUtils.js"),eventListener=require("./eventListener.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(u,t,i)=>t in u?__defProp(u,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):u[t]=i,__spreadValues=(u,t)=>{for(var i in t||(t={}))__hasOwnProp.call(t,i)&&__defNormalProp(u,i,t[i]);if(__getOwnPropSymbols)for(var i of __getOwnPropSymbols(t))__propIsEnum.call(t,i)&&__defNormalProp(u,i,t[i]);return u},__spreadProps=(u,t)=>__defProps(u,__getOwnPropDescs(t)),__async=(u,t,i)=>new Promise((e,o)=>{var n=r=>{try{a(i.next(r))}catch(l){o(l)}},c=r=>{try{a(i.throw(r))}catch(l){o(l)}},a=r=>r.done?e(r.value):Promise.resolve(r.value).then(n,c);a((i=i.apply(u,t)).next())});const LANGUAGE_MAP={[annotation.ELang.Zh]:"cn",[annotation.ELang.US]:"en"},DEFAULT_ZOOM_INFO={min:.2,max:1e3,ratio:.4};class BasicToolOperation extends eventListener{constructor(t){super();this.isDrag=!1,this.isSpaceKey=!1,this.staticMode=!1,this.operationMode=tool.EOperationMode.General,this.innerZoom=1,this.basicZoom=.01,this.isSpaceClick=!1,this.isDragStart=!1,this.startTime=0,this.zoomInfo=DEFAULT_ZOOM_INFO,this.initImgPos=()=>__async(this,null,function*(){var d,h;if(!this.imgNode)return;const s=(d=this._imgAttribute)==null?void 0:d.zoomRatio,g=(h=this._imgAttribute)==null?void 0:h.isOriginalSize,{currentPos:m,imgInfo:f,zoom:v}=lbUtils.ImgPosUtils.getInitImgPos(this.size,{width:this.imgNode.width,height:this.imgNode.height},this.rotate,s,g);this.setCurrentPos(m),this.currentPosStorage=m,this.setImgInfo(f),this.setZoom(v),this.render(),this.renderBasicCanvas(),this.emit("dependRender"),this.emit("renderZoom",v,m,f)}),this.getCurrentPos=d=>{const{_firstClickCoordinate:h,currentPosStorage:s}=this;try{let g;return h&&s?g={y:s.y+d.y-h.y,x:s.x+d.x-h.x}:g={x:0,y:0},g}catch(g){return console.error(g),{x:0,y:0}}},this.wheelChangePos=(d,h,s)=>{const{currentPos:g,imgNode:m}=this;if(!m){console.error("unable to load image");return}if(this.zoom===this.basicZoom&&h===-1)return;const f=ZoomUtils.wheelChangePos(m,d,h,g,{zoom:s||this.zoom,innerZoom:this.innerZoom,basicZoom:this.basicZoom,zoomMax:this.zoomInfo.max,rotate:this.rotate});if(!f)return;const{currentPos:v,ratio:w,zoom:y,imgInfo:P}=f;this.setZoom(y),this.setCurrentPos(v),this.currentPosStorage=v,this.setImgInfo(P),this.zoomInfo.ratio=w,this.emit("renderZoom",y,v,P)},this.zoomChanged=(d,h=annotation.EGrowthMode.Linear)=>{const s=ZoomUtils.zoomChanged(this.zoom,d,h);this.wheelChangePos(this.getGetCenterCoordinate(),s>this.zoom?1:-1,s),this.render(),this.renderBasicCanvas()},this.zoomChangeOnCenter=d=>{this.wheelChangePos(this.getGetCenterCoordinate(),0,d),this.render(),this.renderBasicCanvas()},this.drawStraightLine=(d,h)=>{const{ctx:s}=this;s&&(s.save(),s.lineCap="round",s.lineJoin="round",s.strokeStyle=h.color,s.lineWidth=h.lineWidth,s.globalAlpha=h.globalAlpha,d.forEach((g,m)=>{if(s.beginPath(),m>0){const f=d[m-1];s.save(),s.moveTo(f.x,f.y),s.lineTo(g.x,g.y),s.stroke(),s.restore()}}),s.restore())},this.drawImg=()=>{!this.imgNode||this.hiddenImg===!0||(DrawUtils.drawImg(this.basicCanvas,this.imgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}),this.drawStaticImg())},this.drawStaticImg=()=>{!this.staticImgNode||!this.staticMode||(this.clearCanvas(),DrawUtils.drawImg(this.canvas,this.staticImgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}))};var i,e,o,n,c,a,r,l,C,b,I;this.container=t.container,this.config=CommonToolUtils.jsonParser(t.config),this.showDefaultCursor=t.showDefaultCursor||!1,this.destroyCanvas(),this.createCanvas(t.size,t.isAppend),this.imgNode=t.imgNode,this.staticMode=(i=t.staticMode)!=null?i:!1,this.isImgError=!t.imgNode,this.basicImgInfo={width:(o=(e=t.imgNode)==null?void 0:e.width)!=null?o:0,height:(c=(n=t.imgNode)==null?void 0:n.height)!=null?c:0,valid:!0,rotate:0},this.forbidOperation=(a=t.forbidOperation)!=null?a:!1,this.forbidBasicResultRender=(r=t.forbidBasicResultRender)!=null?r:!1,this.size=t.size,this.currentPos={x:0,y:0},this.zoom=1,this.coord={x:-1,y:-1},this.currentPosStorage={x:0,y:0},this.isShowCursor=!1,this.attributeLockList=[],this.history=new ActionsHistory,this.style=(l=t.style)!=null?l:CommonToolUtils.jsonParser(style.styleString),this._imgAttribute=(C=t.imgAttribute)!=null?C:{},this.isHidden=!1,this.dragStatus=annotation.EDragStatus.Wait,this.defaultAttribute=(b=t==null?void 0:t.defaultAttribute)!=null?b:"",this.forbidCursorLine=!!t.forbidCursorLine,this.lang=(I=t==null?void 0:t.language)!=null?I:annotation.ELang.Zh,lbUtils.i18n.changeLanguage(LANGUAGE_MAP[this.lang]),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseLeave=this.onMouseLeave.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onKeyUp=this.onKeyUp.bind(this),this.onWheel=this.onWheel.bind(this),this.onLeftDblClick=this.onLeftDblClick.bind(this),this.onRightDblClick=this.onRightDblClick.bind(this),this.onClick=this.onClick.bind(this),this.onRightClick=this.onRightClick.bind(this),this.clearImgDrag=this.clearImgDrag.bind(this),this.dblClickListener=new DblClickEventListener(this.container,200),this.coordUtils=new AxisUtils.CoordinateUtils(this),this.coordUtils.setBasicImgInfo(this.basicImgInfo),this.hiddenImg=t.hiddenImg||!1,t.zoomInfo&&(this.zoomInfo=t.zoomInfo)}onContextmenu(t){t.preventDefault()}get ctx(){var t;return this._ctx||((t=this.canvas)==null?void 0:t.getContext("2d"))}get basicCtx(){var t;return(t=this.basicCanvas)==null?void 0:t.getContext("2d")}get rotate(){var t,i;return(i=(t=this.basicImgInfo)==null?void 0:t.rotate)!=null?i:0}get valid(){var t,i;return(i=(t=this.basicImgInfo)==null?void 0:t.valid)!=null?i:!0}get baseIcon(){return style.BASE_ICON[this.style.color]}get defaultCursor(){return this.showDefaultCursor?"default":"none"}get dataList(){return[]}get innerPosAndZoom(){return{innerZoom:this.innerZoom,currentPosStorage:this.currentPosStorage}}get isShowDefaultCursor(){return this.showDefaultCursor}get isMultiMoveMode(){return this.operationMode===tool.EOperationMode.MultiMove}get hasMarkerConfig(){return this.config.markerConfigurable===!0&&this.config.markerList&&this.config.markerList.length>0}setZoom(t){this.zoom=t,this.innerZoom=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setCurrentPos(t){this.currentPos=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setReferenceData(t){this.referenceData=t}setImgInfo(t){this.imgInfo=t}setCurrentPosStorage(t){this.currentPosStorage=t}setOperationMode(t){this.operationMode=t}recoverOperationMode(){this.operationMode===tool.EOperationMode.MultiMove&&this.setOperationMode(tool.EOperationMode.General)}updatePosition(t){const{zoom:i,currentPos:e}=t;this.setZoom(i),this.setCurrentPos(e),this.currentPosStorage=e,this.renderBasicCanvas(),this.render()}setLang(t){this.lang=t;const i=LANGUAGE_MAP[t];lbUtils.i18n.changeLanguage(i)}setShowDefaultCursor(t){this.showDefaultCursor=t,this.container.style.cursor=this.defaultCursor}setCustomCursor(t){this.container.style.cursor=t}get forbidMouseOperation(){return this.forbidOperation||this.valid===!1}get pixelRatio(){var t;return CanvasUtils.getPixelRatio((t=this.canvas)==null?void 0:t.getContext("2d"))}init(){this.eventUnbinding(),this.initPosition(),this.eventBinding(),this.render(),this.renderBasicCanvas()}destroy(){this.destroyCanvas(),this.eventUnbinding()}updateCanvasBasicStyle(t,i,e){const o=this.pixelRatio;t.style.position="absolute",t.width=i.width*o,t.height=i.height*o,t.style.width=`${i.width}px`,t.style.height=`${i.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${e} `}createCanvas(t,i=!0){var e,o;const n=this.pixelRatio,c=document.createElement("canvas");this.updateCanvasBasicStyle(c,t,0),this.basicCanvas=c;const a=document.createElement("canvas");this.updateCanvasBasicStyle(a,t,10),i&&(this.container.hasChildNodes()?(this.container.insertBefore(a,this.container.childNodes[0]),this.container.insertBefore(c,this.container.childNodes[0])):(this.container.appendChild(c),this.container.appendChild(a))),this.canvas=a,this.container.style.cursor=this.defaultCursor,(e=this.ctx)==null||e.scale(n,n),(o=this.basicCtx)==null||o.scale(n,n),this.ctx&&(this.ctx.imageSmoothingEnabled=!1)}destroyCanvas(){this.canvas&&this.container.contains(this.canvas)&&this.container.removeChild(this.canvas),this.basicCanvas&&this.container.contains(this.basicCanvas)&&this.container.removeChild(this.basicCanvas),this.clearInvalidPage(),this.clearImgDrag()}setStyle(t){this.style=t,this.render()}setImgNode(t,i={}){this.imgNode=t,this.setBasicImgInfo(__spreadValues({width:t.width,height:t.height,valid:!0,rotate:0},i)),this.updateZoomInfo(),this.isImgError===!0&&(this.isImgError=!1,this.emit("changeAnnotationShow")),typeof i.valid=="boolean"&&this.setValid(i.valid),this.initImgPos(),this.render(),this.renderBasicCanvas()}updateZoomInfo(t=this.imgNode,i=this.size){var e;if(!t||!i)return;const{min:o}=lbUtils.ImgPosUtils.getMinZoomByImgAndSize({canvasSize:i,imgSize:{width:t.width,height:t.height},rotate:this.rotate,zoomRatio:(e=this._imgAttribute)==null?void 0:e.zoomRatio});this.zoomInfo=__spreadProps(__spreadValues({},this.zoomInfo),{min:o})}setErrorImg(){const t=this.isImgError;this.isImgError=!0,this.imgNode=void 0,this.setBasicImgInfo({width:0,height:0,valid:!0,rotate:0}),t===!1&&this.emit("changeAnnotationShow")}setBasicImgInfo(t){this.basicImgInfo=t,this.coordUtils.setBasicImgInfo(t)}setForbidOperation(t){this.forbidOperation=t,this.setShowDefaultCursor(t),this.render()}setForbidCursorLine(t){this.forbidCursorLine=t,this.render()}setIsHidden(t){this.isHidden=t,this.emit("hiddenChange")}setDefaultAttribute(t){this.defaultAttribute=t}getCoordinateInOrigin(t){const i=this.canvas.getBoundingClientRect();return{x:(t.clientX-i.left-this.currentPos.x)/this.zoom,y:(t.clientY-i.top-this.currentPos.y)/this.zoom}}getTextIconSvg(t=""){var i;return AttributeUtils.default.getTextIconSvg(t,(i=this.config)==null?void 0:i.attributeList,this.config.attributeConfigurable,this.baseIcon)}setIsShowOrder(t){this.config.isShowOrder=t,this.render()}getCoordinate(t){const i=this.canvas.getBoundingClientRect();return{x:t.clientX-i.left,y:t.clientY-i.top}}getCoordinateUnderZoom(t){const i=this.canvas.getBoundingClientRect();return{x:t.clientX-i.left-this.currentPos.x,y:t.clientY-i.top-this.currentPos.y}}getCoordinateUnderZoomByRotate(t){const{x:i,y:e}=this.getCoordinateUnderZoom(t);return this.basicImgInfo.rotate===90?{x:e,y:this.basicImgInfo.height*this.zoom-i}:this.basicImgInfo.rotate===180?{x:this.basicImgInfo.width*this.zoom-i,y:this.basicImgInfo.height*this.zoom-e}:this.basicImgInfo.rotate===270?{x:this.basicImgInfo.width*this.zoom-e,y:i}:{x:i,y:e}}getCoordinateUnderZoomByRotateFromImgPoint(t){const{x:i,y:e}=t;return this.basicImgInfo.rotate===90?{x:(this.basicImgInfo.height-e)*this.zoom+this.currentPos.x,y:i*this.zoom+this.currentPos.y}:this.basicImgInfo.rotate===180?{x:(this.basicImgInfo.width-i)*this.zoom+this.currentPos.x,y:(this.basicImgInfo.height-e)*this.zoom+this.currentPos.y}:this.basicImgInfo.rotate===270?{x:e*this.zoom+this.currentPos.x,y:(this.basicImgInfo.width-i)*this.zoom+this.currentPos.y}:{x:i*this.zoom+this.currentPos.x,y:e*this.zoom+this.currentPos.y}}getGetCenterCoordinate(){return{x:this.size.width/2,y:this.size.height/2}}initPosition(){if(this.basicResult&&this.imgInfo){const{basicResult:t,size:i,imgNode:e,_imgAttribute:o,imgInfo:n,dependToolName:c}=this;if(t&&e&&c){let a=t;switch(c){case tool.EToolName.Polygon:case tool.EToolName.Line:{if(t.pointList){const l=MathUtils.default.calcViewportBoundaries(t.pointList);a={x:l.left,y:l.top,width:l.right-l.left,height:l.bottom-l.top}}break}}const r=lbUtils.ImgPosUtils.getBasicRecPos(e,a,i,void 0,o==null?void 0:o.zoomRatio,o==null?void 0:o.isOriginalSize);r&&(this.setCurrentPos(r.currentPos),this.currentPosStorage=this.currentPos,this.setImgInfo(__spreadProps(__spreadValues({},n),{width:n.width/this.innerZoom*r.innerZoom,height:n.height/this.innerZoom*r.innerZoom})),this.setZoom(r.innerZoom),this.render(),this.renderBasicCanvas())}}else this.initImgPos()}undo(){this.history.undo()}redo(){this.history.redo()}clearCanvas(){var t;(t=this.ctx)==null||t.clearRect(0,0,this.size.width,this.size.height)}clearBasicCanvas(){var t;(t=this.basicCtx)==null||t.clearRect(0,0,this.size.width,this.size.height)}eventBinding(){this.dblClickListener.addEvent(()=>{},this.onLeftDblClick,this.onRightDblClick),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseleave",this.onMouseLeave),this.container.addEventListener("click",this.onClick),this.container.addEventListener("wheel",this.onWheel),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("keyup",this.onKeyUp),window.parent.document.addEventListener("contextmenu",this.onContextmenu,!1)}eventUnbinding(){this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.removeEventListener("mouseleave",this.onMouseLeave),this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("click",this.onClick),document.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("keyup",this.onKeyUp),window.parent.document.removeEventListener("contextmenu",this.onContextmenu,!1),this.dblClickListener.removeEvent()}clearImgDrag(){this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime=0,this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1}clearCursorLine(){this.coord={x:-1,y:-1}}onMouseDown(t){if(!this.canvas||this.isImgError)return!0;const i=this.getCoordinate(t);(this.isSpaceKey&&t.button===0||t.button===2)&&(t.stopPropagation(),this._firstClickCoordinate=i,this.currentPosStorage=this.currentPos,this.isSpaceClick=!0,this.isDragStart=!0,this.startTime=new Date().getTime())}onMouseMove(t){if(!this.canvas||this.isImgError)return!0;const i=this.getCoordinate(t);this.isShowCursor&&(this.coord=i);try{if(!i||!_.isNumber(i==null?void 0:i.x)||!_.isNumber(i==null?void 0:i.y))throw new Error("coord error");if(this.coord=i,(this.isSpaceClick||this.isDragStart)&&this._firstClickCoordinate){const e=this.getCurrentPos(i);this.setCurrentPos(e),this.isDrag=!0,this.container.style.cursor="grabbing",this.forbidCursorLine=!0,this.renderBasicCanvas(),this.emit("dependRender"),this.emit("dragMove",{currentPos:e,zoom:this.zoom,imgInfo:this.imgInfo})}this.render()}catch(e){console.error(e)}}onMouseUp(t){if(!this.canvas||this.isImgError)return!0;if(this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1,this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime!==0&&this._firstClickCoordinate){const i=new Date().getTime(),e=this.getCoordinate(t);if(i-this.startTime>1e3||this.isSpaceKey===!0||LineToolUtils.default.calcTwoPointDistance(e,this._firstClickCoordinate)>10)return t.stopPropagation(),this.startTime=0,this.render(),!0}this.startTime=0,t.button===2&&this.onRightClick(t),this.render()}onMouseLeave(){this.clearImgDrag()}onClick(t){}onRightClick(t){}onLeftDblClick(t){}onRightDblClick(t){this.clearImgDrag()}onKeyDown(t){switch((t.keyCode===keyCode.Alt||t.keyCode===keyCode.A)&&t.preventDefault(),t.keyCode){case keyCode.Space:this.isSpaceKey=!0,t.preventDefault();break;case keyCode.Z:if(t.ctrlKey)return t.shiftKey?this.redo():this.undo(),!1;break}return!0}onKeyUp(t){switch(t.keyCode){case keyCode.Space:this.isSpaceKey=!1;break}}exportCustomData(){return{}}onWheel(t,i=!0){if(!this.imgNode||!this.coord)return;t.preventDefault(),t.stopPropagation();const e=this.getCoordinate(t),o=t.deltaY||t.wheelDelta;let n=0;o>0&&this.zoom>this.zoomInfo.min&&(n=-1),o<0&&this.zoom<this.zoomInfo.max&&(n=1),this.wheelChangePos(e,n),this.emit("dependRender"),i&&this.render(),this.renderBasicCanvas()}renderCursorLine(t=(i=>(i=this.style.lineColor[0])!=null?i:"")()){if(!this.ctx||this.forbidCursorLine||this.forbidOperation)return;const{x:i,y:e}=this.coord;DrawUtils.drawLine(this.canvas,{x:0,y:e},{x:1e4,y:e},{color:t}),DrawUtils.drawLine(this.canvas,{x:i,y:0},{x:i,y:1e4},{color:t}),DrawUtils.drawCircleWithFill(this.canvas,{x:i,y:e},1,{color:"white"})}setSize(t){var i;this.size=t,this.updateZoomInfo(),this.container.contains(this.canvas)&&(this.destroyCanvas(),this.createCanvas(t),this.eventUnbinding(),this.init(),((i=this.basicImgInfo)==null?void 0:i.valid)===!1&&this.renderInvalidPage())}setImgAttribute(t){const i=this._imgAttribute;if(this._imgAttribute=t,(i==null?void 0:i.zoomRatio)!==t.zoomRatio||i.isOriginalSize!==t.isOriginalSize){this.initImgPos();return}this.renderBasicCanvas(),this.render()}clearResult(t){}setValid(t){this.basicImgInfo.valid=t,t===!1?(this.renderInvalidPage(),this.clearResult(!1)):this.clearInvalidPage()}setRotate(t){this.basicImgInfo.rotate=t}setBasicResult(t){this.basicResult=t,this.coordUtils.setBasicResult(t),this.initPosition(),this.emit("dependRender")}setDependName(t,i){this.dependToolName=t,this.coordUtils.setDependInfo(t,i)}filterCacheContext(){}setAttributeLockList(t){this.attributeLockList=t,this.filterCacheContext(),this.render()}setConfig(t){this.config=CommonToolUtils.jsonParser(t)}setDataInjectionAtCreation(t){this.dataInjectionAtCreation=t}setRenderEnhance(t){this.renderEnhance=t}setCustomRenderStyle(t){this.customRenderStyle=t}updateRotate(){if(this.dependToolName)return this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.NoRotateInDependence,this.lang)),!1;if(this.dataList.length>0)return this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.NoRotateNotice,this.lang)),!1;const t=MathUtils.default.getRotate(this.basicImgInfo.rotate);this.basicImgInfo.rotate=t,this.initImgPos(),this.emit("updateResult")}getColor(t="",i=this.config){return lbUtils.toolStyleConverter.getColorByConfig({attribute:t,config:i,style:this.style})}getLineColor(t=""){var i,e,o,n,c,a,r,l;if(((i=this.config)==null?void 0:i.attributeConfigurable)===!0){const I=AttributeUtils.default.getAttributeIndex(t,(o=(e=this.config)==null?void 0:e.attributeList)!=null?o:[])+1;return((a=(c=(n=this.config)==null?void 0:n.attributeList)==null?void 0:c.find(h=>h.value===t))==null?void 0:a.color)?(l=(r=lbUtils.toolStyleConverter.getColorByConfig({attribute:t,config:this.config}))==null?void 0:r.valid)==null?void 0:l.stroke:this.style.attributeLineColor?this.style.attributeLineColor[I]:""}const{color:C,lineColor:b}=this.style;return C&&b?b[C]:""}clearInvalidPage(){this._invalidDOM&&this.container&&this.container.contains(this._invalidDOM)&&(this.container.removeChild(this._invalidDOM),this._invalidDOM=void 0)}renderInvalidPage(){!this.container||this._invalidDOM||(this._invalidDOM=RenderDomUtils.renderInvalidPage(this.container,this.size,this.lang))}renderBasicCanvas(){if(!this.basicCanvas)return;this.clearBasicCanvas(),this.drawImg();const t=3;if(!this.forbidBasicResultRender&&this.basicResult&&this.dependToolName)switch(this.dependToolName){case tool.EToolName.Rect:{DrawUtils.drawRect(this.basicCanvas,AxisUtils.default.changeRectByZoom(this.basicResult,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}case tool.EToolName.Polygon:{DrawUtils.drawPolygonWithFillAndLine(this.basicCanvas,AxisUtils.default.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{fillColor:"transparent",strokeColor:"rgba(204,204,204,1.00)",isClose:!0,thickness:t});break}case tool.EToolName.Line:{DrawUtils.drawLineWithPointList(this.basicCanvas,AxisUtils.default.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}}}render(){!this.canvas||!this.ctx||!this.imgNode||this.clearCanvas()}changeStyle(t=this.defaultAttribute){this.emit("changeStyle",{attribute:t})}}exports.BasicToolOperation=BasicToolOperation;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),_=require("lodash"),tool=require("../../constant/tool.js"),MathUtils=require("../../utils/MathUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),LineToolUtils=require("../../utils/tool/LineToolUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),style=require("../../constant/style.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),DblClickEventListener=require("../../utils/tool/DblClickEventListener.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),RenderDomUtils=require("../../utils/tool/RenderDomUtils.js"),ZoomUtils=require("../../utils/tool/ZoomUtils.js"),eventListener=require("./eventListener.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(u,t,i)=>t in u?__defProp(u,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):u[t]=i,__spreadValues=(u,t)=>{for(var i in t||(t={}))__hasOwnProp.call(t,i)&&__defNormalProp(u,i,t[i]);if(__getOwnPropSymbols)for(var i of __getOwnPropSymbols(t))__propIsEnum.call(t,i)&&__defNormalProp(u,i,t[i]);return u},__spreadProps=(u,t)=>__defProps(u,__getOwnPropDescs(t)),__async=(u,t,i)=>new Promise((e,s)=>{var a=n=>{try{l(i.next(n))}catch(r){s(r)}},h=n=>{try{l(i.throw(n))}catch(r){s(r)}},l=n=>n.done?e(n.value):Promise.resolve(n.value).then(a,h);l((i=i.apply(u,t)).next())});const LANGUAGE_MAP={[annotation.ELang.Zh]:"cn",[annotation.ELang.US]:"en"},DEFAULT_ZOOM_INFO={min:.2,max:1e3,ratio:.4};class BasicToolOperation extends eventListener{constructor(t){super();this.isDrag=!1,this.isSpaceKey=!1,this.staticMode=!1,this.operationMode=tool.EOperationMode.General,this.innerZoom=1,this.basicZoom=.01,this.isSpaceClick=!1,this.isDragStart=!1,this.startTime=0,this.zoomInfo=DEFAULT_ZOOM_INFO,this.isOffscreenCanvas=!1,this.initImgPos=()=>__async(this,null,function*(){var d,c;if(!this.imgNode)return;const o=(d=this._imgAttribute)==null?void 0:d.zoomRatio,g=(c=this._imgAttribute)==null?void 0:c.isOriginalSize,{currentPos:m,imgInfo:f,zoom:v}=lbUtils.ImgPosUtils.getInitImgPos(this.size,{width:this.imgNode.width,height:this.imgNode.height},this.rotate,o,g);this.setCurrentPos(m),this.currentPosStorage=m,this.setImgInfo(f),this.setZoom(v),this.render(),this.renderBasicCanvas(),this.emit("dependRender"),this.emit("renderZoom",v,m,f)}),this.getCurrentPos=d=>{const{_firstClickCoordinate:c,currentPosStorage:o}=this;try{let g;return c&&o?g={y:o.y+d.y-c.y,x:o.x+d.x-c.x}:g={x:0,y:0},g}catch(g){return console.error(g),{x:0,y:0}}},this.wheelChangePos=(d,c,o)=>{const{currentPos:g,imgNode:m}=this;if(!m){console.error("unable to load image");return}if(this.zoom===this.basicZoom&&c===-1)return;const f=ZoomUtils.wheelChangePos(m,d,c,g,{zoom:o||this.zoom,innerZoom:this.innerZoom,basicZoom:this.basicZoom,zoomMax:this.zoomInfo.max,rotate:this.rotate});if(!f)return;const{currentPos:v,ratio:w,zoom:y,imgInfo:P}=f;this.setZoom(y),this.setCurrentPos(v),this.currentPosStorage=v,this.setImgInfo(P),this.zoomInfo.ratio=w,this.emit("renderZoom",y,v,P)},this.zoomChanged=(d,c=annotation.EGrowthMode.Linear)=>{const o=ZoomUtils.zoomChanged(this.zoom,d,c);this.wheelChangePos(this.getGetCenterCoordinate(),o>this.zoom?1:-1,o),this.render(),this.renderBasicCanvas()},this.zoomChangeOnCenter=d=>{this.wheelChangePos(this.getGetCenterCoordinate(),0,d),this.render(),this.renderBasicCanvas()},this.drawStraightLine=(d,c)=>{const{ctx:o}=this;o&&(o.save(),o.lineCap="round",o.lineJoin="round",o.strokeStyle=c.color,o.lineWidth=c.lineWidth,o.globalAlpha=c.globalAlpha,d.forEach((g,m)=>{if(o.beginPath(),m>0){const f=d[m-1];o.save(),o.moveTo(f.x,f.y),o.lineTo(g.x,g.y),o.stroke(),o.restore()}}),o.restore())},this.drawImg=()=>{!this.imgNode||this.hiddenImg===!0||(DrawUtils.drawImg(this.basicCanvas,this.imgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}),this.drawStaticImg())},this.drawStaticImg=()=>{!this.staticImgNode||!this.staticMode||(this.clearCanvas(),DrawUtils.drawImg(this.canvas,this.staticImgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}))};var i,e,s,a,h,l,n,r,C,b,I;this.isOffscreenCanvas=!!t.isOffscreenCanvas,this.container=t.container,this.config=CommonToolUtils.jsonParser(t.config),this.showDefaultCursor=t.showDefaultCursor||!1,this.destroyCanvas(),this.createCanvas(t.size,t.isAppend),this.imgNode=t.imgNode,this.staticMode=(i=t.staticMode)!=null?i:!1,this.isImgError=!t.imgNode,this.basicImgInfo={width:(s=(e=t.imgNode)==null?void 0:e.width)!=null?s:0,height:(h=(a=t.imgNode)==null?void 0:a.height)!=null?h:0,valid:!0,rotate:0},this.forbidOperation=(l=t.forbidOperation)!=null?l:!1,this.forbidBasicResultRender=(n=t.forbidBasicResultRender)!=null?n:!1,this.size=t.size,this.currentPos={x:0,y:0},this.zoom=1,this.coord={x:-1,y:-1},this.currentPosStorage={x:0,y:0},this.isShowCursor=!1,this.attributeLockList=[],this.history=new ActionsHistory,this.style=(r=t.style)!=null?r:CommonToolUtils.jsonParser(style.styleString),this._imgAttribute=(C=t.imgAttribute)!=null?C:{},this.isHidden=!1,this.dragStatus=annotation.EDragStatus.Wait,this.defaultAttribute=(b=t==null?void 0:t.defaultAttribute)!=null?b:"",this.forbidCursorLine=!!t.forbidCursorLine,this.lang=(I=t==null?void 0:t.language)!=null?I:annotation.ELang.Zh,lbUtils.i18n.changeLanguage(LANGUAGE_MAP[this.lang]),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseLeave=this.onMouseLeave.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onKeyUp=this.onKeyUp.bind(this),this.onWheel=this.onWheel.bind(this),this.onLeftDblClick=this.onLeftDblClick.bind(this),this.onRightDblClick=this.onRightDblClick.bind(this),this.onClick=this.onClick.bind(this),this.onRightClick=this.onRightClick.bind(this),this.clearImgDrag=this.clearImgDrag.bind(this),this.dblClickListener=new DblClickEventListener(this.container,200),this.coordUtils=new AxisUtils.CoordinateUtils(this),this.coordUtils.setBasicImgInfo(this.basicImgInfo),this.hiddenImg=t.hiddenImg||!1,t.zoomInfo&&(this.zoomInfo=t.zoomInfo)}onContextmenu(t){t.preventDefault()}get ctx(){var t;return this._ctx||((t=this.canvas)==null?void 0:t.getContext("2d"))}get basicCtx(){var t;return(t=this.basicCanvas)==null?void 0:t.getContext("2d")}get offscreenCtx(){var t;return(t=this.offscreenCanvas)==null?void 0:t.getContext("2d")}get rotate(){var t,i;return(i=(t=this.basicImgInfo)==null?void 0:t.rotate)!=null?i:0}get valid(){var t,i;return(i=(t=this.basicImgInfo)==null?void 0:t.valid)!=null?i:!0}get baseIcon(){return style.BASE_ICON[this.style.color]}get defaultCursor(){return this.showDefaultCursor?"default":"none"}get dataList(){return[]}get innerPosAndZoom(){return{innerZoom:this.innerZoom,currentPosStorage:this.currentPosStorage}}get isShowDefaultCursor(){return this.showDefaultCursor}get isMultiMoveMode(){return this.operationMode===tool.EOperationMode.MultiMove}get hasMarkerConfig(){return this.config.markerConfigurable===!0&&this.config.markerList&&this.config.markerList.length>0}setZoom(t){this.zoom=t,this.innerZoom=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setCurrentPos(t){this.currentPos=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setReferenceData(t){this.referenceData=t}setImgInfo(t){this.imgInfo=t}setCurrentPosStorage(t){this.currentPosStorage=t}setOperationMode(t){this.operationMode=t}recoverOperationMode(){this.operationMode===tool.EOperationMode.MultiMove&&this.setOperationMode(tool.EOperationMode.General)}updatePosition(t){const{zoom:i,currentPos:e}=t;this.setZoom(i),this.setCurrentPos(e),this.currentPosStorage=e,this.renderBasicCanvas(),this.render()}setLang(t){this.lang=t;const i=LANGUAGE_MAP[t];lbUtils.i18n.changeLanguage(i)}setShowDefaultCursor(t){this.showDefaultCursor=t,this.container.style.cursor=this.defaultCursor}setCustomCursor(t){this.container.style.cursor=t}get forbidMouseOperation(){return this.forbidOperation||this.valid===!1}get pixelRatio(){var t;return CanvasUtils.getPixelRatio((t=this.canvas)==null?void 0:t.getContext("2d"))}init(){this.eventUnbinding(),this.initPosition(),this.eventBinding(),this.render(),this.renderBasicCanvas()}destroy(){this.destroyCanvas(),this.eventUnbinding()}updateCanvasBasicStyle(t,i,e){const s=this.pixelRatio;t.style.position="absolute",t.width=i.width*s,t.height=i.height*s,t.style.width=`${i.width}px`,t.style.height=`${i.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${e} `}createCanvas(t,i=!0){var e,s,a;const h=this.pixelRatio,l=document.createElement("canvas");this.updateCanvasBasicStyle(l,t,0),this.basicCanvas=l;const n=document.createElement("canvas");this.updateCanvasBasicStyle(n,t,10);let r;this.isOffscreenCanvas&&(r=document.createElement("canvas"),this.updateCanvasBasicStyle(r,t,20),this.offscreenCanvas=r),i&&(this.container.hasChildNodes()?(this.isOffscreenCanvas&&r&&this.container.insertBefore(r,this.container.childNodes[0]),this.container.insertBefore(n,this.container.childNodes[0]),this.container.insertBefore(l,this.container.childNodes[0])):(this.container.appendChild(l),this.container.appendChild(n),this.isOffscreenCanvas&&r&&this.container.appendChild(r))),this.canvas=n,this.container.style.cursor=this.defaultCursor,(e=this.ctx)==null||e.scale(h,h),(s=this.basicCtx)==null||s.scale(h,h),(a=this.offscreenCtx)==null||a.scale(h,h),this.ctx&&(this.ctx.imageSmoothingEnabled=!1)}destroyCanvas(){this.canvas&&this.container.contains(this.canvas)&&this.container.removeChild(this.canvas),this.basicCanvas&&this.container.contains(this.basicCanvas)&&this.container.removeChild(this.basicCanvas),this.offscreenCanvas&&this.container.contains(this.offscreenCanvas)&&this.container.removeChild(this.offscreenCanvas),this.clearInvalidPage(),this.clearImgDrag()}setStyle(t){this.style=t,this.render()}setImgNode(t,i={}){this.imgNode=t,this.setBasicImgInfo(__spreadValues({width:t.width,height:t.height,valid:!0,rotate:0},i)),this.updateZoomInfo(),this.isImgError===!0&&(this.isImgError=!1,this.emit("changeAnnotationShow")),typeof i.valid=="boolean"&&this.setValid(i.valid),this.initImgPos(),this.render(),this.renderBasicCanvas()}updateZoomInfo(t=this.imgNode,i=this.size){var e;if(!t||!i)return;const{min:s}=lbUtils.ImgPosUtils.getMinZoomByImgAndSize({canvasSize:i,imgSize:{width:t.width,height:t.height},rotate:this.rotate,zoomRatio:(e=this._imgAttribute)==null?void 0:e.zoomRatio});this.zoomInfo=__spreadProps(__spreadValues({},this.zoomInfo),{min:s})}setErrorImg(){const t=this.isImgError;this.isImgError=!0,this.imgNode=void 0,this.setBasicImgInfo({width:0,height:0,valid:!0,rotate:0}),t===!1&&this.emit("changeAnnotationShow")}setBasicImgInfo(t){this.basicImgInfo=t,this.coordUtils.setBasicImgInfo(t)}setForbidOperation(t){this.forbidOperation=t,this.setShowDefaultCursor(t),this.render()}setForbidCursorLine(t){this.forbidCursorLine=t,this.render()}setIsHidden(t){this.isHidden=t,this.emit("hiddenChange")}setDefaultAttribute(t){this.defaultAttribute=t}getCoordinateInOrigin(t){const i=this.canvas.getBoundingClientRect();return{x:(t.clientX-i.left-this.currentPos.x)/this.zoom,y:(t.clientY-i.top-this.currentPos.y)/this.zoom}}getTextIconSvg(t=""){var i;return AttributeUtils.default.getTextIconSvg(t,(i=this.config)==null?void 0:i.attributeList,this.config.attributeConfigurable,this.baseIcon)}setIsShowOrder(t){this.config.isShowOrder=t,this.render()}getCoordinate(t){const i=this.canvas.getBoundingClientRect();return{x:t.clientX-i.left,y:t.clientY-i.top}}getCoordinateUnderZoom(t){const i=this.canvas.getBoundingClientRect();return{x:t.clientX-i.left-this.currentPos.x,y:t.clientY-i.top-this.currentPos.y}}getCoordinateUnderZoomByRotate(t){const{x:i,y:e}=this.getCoordinateUnderZoom(t);return this.basicImgInfo.rotate===90?{x:e,y:this.basicImgInfo.height*this.zoom-i}:this.basicImgInfo.rotate===180?{x:this.basicImgInfo.width*this.zoom-i,y:this.basicImgInfo.height*this.zoom-e}:this.basicImgInfo.rotate===270?{x:this.basicImgInfo.width*this.zoom-e,y:i}:{x:i,y:e}}getCoordinateUnderZoomByRotateFromImgPoint(t){const{x:i,y:e}=t;return this.basicImgInfo.rotate===90?{x:(this.basicImgInfo.height-e)*this.zoom+this.currentPos.x,y:i*this.zoom+this.currentPos.y}:this.basicImgInfo.rotate===180?{x:(this.basicImgInfo.width-i)*this.zoom+this.currentPos.x,y:(this.basicImgInfo.height-e)*this.zoom+this.currentPos.y}:this.basicImgInfo.rotate===270?{x:e*this.zoom+this.currentPos.x,y:(this.basicImgInfo.width-i)*this.zoom+this.currentPos.y}:{x:i*this.zoom+this.currentPos.x,y:e*this.zoom+this.currentPos.y}}getGetCenterCoordinate(){return{x:this.size.width/2,y:this.size.height/2}}initPosition(){if(this.basicResult&&this.imgInfo){const{basicResult:t,size:i,imgNode:e,_imgAttribute:s,imgInfo:a,dependToolName:h}=this;if(t&&e&&h){let l=t;switch(h){case tool.EToolName.Polygon:case tool.EToolName.Line:{if(t.pointList){const r=MathUtils.default.calcViewportBoundaries(t.pointList);l={x:r.left,y:r.top,width:r.right-r.left,height:r.bottom-r.top}}break}}const n=lbUtils.ImgPosUtils.getBasicRecPos(e,l,i,void 0,s==null?void 0:s.zoomRatio,s==null?void 0:s.isOriginalSize);n&&(this.setCurrentPos(n.currentPos),this.currentPosStorage=this.currentPos,this.setImgInfo(__spreadProps(__spreadValues({},a),{width:a.width/this.innerZoom*n.innerZoom,height:a.height/this.innerZoom*n.innerZoom})),this.setZoom(n.innerZoom),this.render(),this.renderBasicCanvas())}}else this.initImgPos()}undo(){this.history.undo()}redo(){this.history.redo()}clearCanvas(){var t;(t=this.ctx)==null||t.clearRect(0,0,this.size.width,this.size.height)}clearBasicCanvas(){var t;(t=this.basicCtx)==null||t.clearRect(0,0,this.size.width,this.size.height)}clearOffscreenCanvas(){var t;(t=this.offscreenCtx)==null||t.clearRect(0,0,this.size.width,this.size.height)}eventBinding(){this.dblClickListener.addEvent(()=>{},this.onLeftDblClick,this.onRightDblClick),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseleave",this.onMouseLeave),this.container.addEventListener("click",this.onClick),this.container.addEventListener("wheel",this.onWheel),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("keyup",this.onKeyUp),window.parent.document.addEventListener("contextmenu",this.onContextmenu,!1)}eventUnbinding(){this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.removeEventListener("mouseleave",this.onMouseLeave),this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("click",this.onClick),document.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("keyup",this.onKeyUp),window.parent.document.removeEventListener("contextmenu",this.onContextmenu,!1),this.dblClickListener.removeEvent()}clearImgDrag(){this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime=0,this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1}clearCursorLine(){this.coord={x:-1,y:-1}}onMouseDown(t){if(!this.canvas||this.isImgError)return!0;const i=this.getCoordinate(t);(this.isSpaceKey&&t.button===0||t.button===2)&&(t.stopPropagation(),this._firstClickCoordinate=i,this.currentPosStorage=this.currentPos,this.isSpaceClick=!0,this.isDragStart=!0,this.startTime=new Date().getTime())}onMouseMove(t,i=!0){if(!this.canvas||this.isImgError)return!0;const e=this.getCoordinate(t);this.isShowCursor&&(this.coord=e);try{if(!e||!_.isNumber(e==null?void 0:e.x)||!_.isNumber(e==null?void 0:e.y))throw new Error("coord error");if(this.coord=e,(this.isSpaceClick||this.isDragStart)&&this._firstClickCoordinate){const s=this.getCurrentPos(e);this.setCurrentPos(s),this.isDrag=!0,this.container.style.cursor="grabbing",this.forbidCursorLine=!0,this.renderBasicCanvas(),this.emit("dependRender"),this.emit("dragMove",{currentPos:s,zoom:this.zoom,imgInfo:this.imgInfo})}i&&this.render()}catch(s){console.error(s)}}onMouseUp(t){if(!this.canvas||this.isImgError)return!0;if(this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1,this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime!==0&&this._firstClickCoordinate){const i=new Date().getTime(),e=this.getCoordinate(t);if(i-this.startTime>1e3||this.isSpaceKey===!0||LineToolUtils.default.calcTwoPointDistance(e,this._firstClickCoordinate)>10)return t.stopPropagation(),this.startTime=0,this.render(),!0}this.startTime=0,t.button===2&&this.onRightClick(t),this.render()}onMouseLeave(){this.clearImgDrag()}onClick(t){}onRightClick(t){}onLeftDblClick(t){}onRightDblClick(t){this.clearImgDrag()}onKeyDown(t){switch((t.keyCode===keyCode.Alt||t.keyCode===keyCode.A)&&t.preventDefault(),t.keyCode){case keyCode.Space:this.isSpaceKey=!0,t.preventDefault();break;case keyCode.Z:if(t.ctrlKey)return t.shiftKey?this.redo():this.undo(),!1;break}return!0}onKeyUp(t){switch(t.keyCode){case keyCode.Space:this.isSpaceKey=!1;break}}exportCustomData(){return{}}onWheel(t,i=!0){if(!this.imgNode||!this.coord)return;t.preventDefault(),t.stopPropagation();const e=this.getCoordinate(t),s=t.deltaY||t.wheelDelta;let a=0;s>0&&this.zoom>this.zoomInfo.min&&(a=-1),s<0&&this.zoom<this.zoomInfo.max&&(a=1),this.wheelChangePos(e,a),this.emit("dependRender"),i&&this.render(),this.renderBasicCanvas()}renderCursorLine(t=(i=>(i=this.style.lineColor[0])!=null?i:"")()){if(!this.ctx||this.forbidCursorLine||this.forbidOperation)return;const{x:i,y:e}=this.coord;DrawUtils.drawLine(this.canvas,{x:0,y:e},{x:1e4,y:e},{color:t}),DrawUtils.drawLine(this.canvas,{x:i,y:0},{x:i,y:1e4},{color:t}),DrawUtils.drawCircleWithFill(this.canvas,{x:i,y:e},1,{color:"white"})}setSize(t){var i;this.size=t,this.updateZoomInfo(),this.container.contains(this.canvas)&&(this.destroyCanvas(),this.createCanvas(t),this.eventUnbinding(),this.init(),((i=this.basicImgInfo)==null?void 0:i.valid)===!1&&this.renderInvalidPage())}setImgAttribute(t){const i=this._imgAttribute;if(this._imgAttribute=t,(i==null?void 0:i.zoomRatio)!==t.zoomRatio||i.isOriginalSize!==t.isOriginalSize){this.initImgPos();return}this.renderBasicCanvas(),this.render()}clearResult(t){}setValid(t){this.basicImgInfo.valid=t,t===!1?(this.renderInvalidPage(),this.clearResult(!1)):this.clearInvalidPage()}setRotate(t){this.basicImgInfo.rotate=t}setBasicResult(t){this.basicResult=t,this.coordUtils.setBasicResult(t),this.initPosition(),this.emit("dependRender")}setDependName(t,i){this.dependToolName=t,this.coordUtils.setDependInfo(t,i)}filterCacheContext(){}setAttributeLockList(t){this.attributeLockList=t,this.filterCacheContext(),this.render()}setConfig(t){this.config=CommonToolUtils.jsonParser(t)}setDataInjectionAtCreation(t){this.dataInjectionAtCreation=t}setRenderEnhance(t){this.renderEnhance=t}setCustomRenderStyle(t){this.customRenderStyle=t}updateRotate(){if(this.dependToolName)return this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.NoRotateInDependence,this.lang)),!1;if(this.dataList.length>0)return this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.NoRotateNotice,this.lang)),!1;const t=MathUtils.default.getRotate(this.basicImgInfo.rotate);this.basicImgInfo.rotate=t,this.initImgPos(),this.emit("updateResult")}getColor(t="",i=this.config){return lbUtils.toolStyleConverter.getColorByConfig({attribute:t,config:i,style:this.style})}getLineColor(t=""){var i,e,s,a,h,l,n,r;if(((i=this.config)==null?void 0:i.attributeConfigurable)===!0){const I=AttributeUtils.default.getAttributeIndex(t,(s=(e=this.config)==null?void 0:e.attributeList)!=null?s:[])+1;return((l=(h=(a=this.config)==null?void 0:a.attributeList)==null?void 0:h.find(c=>c.value===t))==null?void 0:l.color)?(r=(n=lbUtils.toolStyleConverter.getColorByConfig({attribute:t,config:this.config}))==null?void 0:n.valid)==null?void 0:r.stroke:this.style.attributeLineColor?this.style.attributeLineColor[I]:""}const{color:C,lineColor:b}=this.style;return C&&b?b[C]:""}clearInvalidPage(){this._invalidDOM&&this.container&&this.container.contains(this._invalidDOM)&&(this.container.removeChild(this._invalidDOM),this._invalidDOM=void 0)}renderInvalidPage(){!this.container||this._invalidDOM||(this._invalidDOM=RenderDomUtils.renderInvalidPage(this.container,this.size,this.lang))}renderBasicCanvas(){if(!this.basicCanvas)return;this.clearBasicCanvas(),this.drawImg();const t=3;if(!this.forbidBasicResultRender&&this.basicResult&&this.dependToolName)switch(this.dependToolName){case tool.EToolName.Rect:{DrawUtils.drawRect(this.basicCanvas,AxisUtils.default.changeRectByZoom(this.basicResult,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}case tool.EToolName.Polygon:{DrawUtils.drawPolygonWithFillAndLine(this.basicCanvas,AxisUtils.default.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{fillColor:"transparent",strokeColor:"rgba(204,204,204,1.00)",isClose:!0,thickness:t});break}case tool.EToolName.Line:{DrawUtils.drawLineWithPointList(this.basicCanvas,AxisUtils.default.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}}}render(){!this.canvas||!this.ctx||!this.imgNode||this.clearCanvas()}changeStyle(t=this.defaultAttribute){this.emit("changeStyle",{attribute:t})}}exports.BasicToolOperation=BasicToolOperation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var _=require("lodash"),lbUtils=require("@labelbee/lb-utils"),annotation=require("../../constant/annotation.js"),tool=require("../../constant/tool.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),defaultConfig=require("../../constant/defaultConfig.js"),polygonOperation=require("./polygonOperation.js"),basicToolOperation=require("./basicToolOperation.js");function _interopDefaultLegacy(n){return n&&typeof n=="object"&&"default"in n?n:{default:n}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(n,t,e)=>t in n?__defProp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,__spreadValues=(n,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(n,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(n,e,t[e]);return n},__spreadProps=(n,t)=>__defProps(n,__getOwnPropDescs(t));class PointCloud2dOperation extends polygonOperation{constructor(t){super(t);this.highlightAttributeList=[],this.rightMouseUp=o=>{var d;if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.selection.setSelectedIDs(this.hoverID,o.ctrlKey),this.emit("setSelectedIDs",this.selection.selectedIDs);const a=(d=this.polygonList.find(u=>u.id===this.hoverID))==null?void 0:d.attribute;a&&a!==this.defaultAttribute&&this.emit("syncAttribute",a)},this.onKeyDown=()=>{},this.onKeyUp=()=>{},this.renderSingleSelectedPolygon=o=>{var d;if(o){const a=this.getPointCloudLineColor(o),u=AxisUtils.default.changePointListByZoom(o.pointList,this.zoom,this.currentPos);DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,u,{fillColor:"transparent",strokeColor:a,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(d=this.config)==null?void 0:d.lineType}),o.isRect===!0&&this.showDirectionLine===!0&&(this.renderRectPolygonDirection(u),_.isNumber(o==null?void 0:o.trackID)&&(o==null?void 0:o.trackID)>=0&&this.renderdrawTrackID(o))}},this.emitUpdatePolygonByDrag=()=>{if(this.dragInfo){const{originPolygonList:o}=this.dragInfo;if(this.selectedIDs.length>0){const d=[];this.polygonList.forEach(a=>{if(this.selectedIDs.includes(a.id)){const u=o.find(c=>c.id===a.id);u&&d.push({newPolygon:a,originPolygon:u})}}),this.emit("updatePolygonByDrag",d)}}};var e,i,s,l,r,h;this.showDirectionLine=(e=t.showDirectionLine)!=null?e:!0,this.forbidAddNew=(i=t.forbidAddNew)!=null?i:!1,this.pointCloudConfig=(s=CommonToolUtils.jsonParser(t.config))!=null?s:{},this.hideAttributes=[],this.checkMode=(l=t.checkMode)!=null?l:!1,this.forbidAddNew===!1&&t.checkMode===!0&&(this.forbidAddNew=!0),this.config=__spreadProps(__spreadValues({},defaultConfig.polygonConfig),{textConfigurable:!1,attributeConfigurable:!0,attributeList:(h=(r=this.pointCloudConfig)==null?void 0:r.attributeList)!=null?h:[]})}get getSelectedIDs(){return this.selectedIDs}get enableDrag(){return Boolean(this.selectedIDs.length>0&&this.dragInfo)}get visiblePolygonList(){return this.polygonList.filter(t=>!this.hideAttributes.includes(t.attribute))}setHiddenAttributes(t){this.hideAttributes=t}setConfig(t){var e;const i=CommonToolUtils.jsonParser(t);this.pointCloudConfig=i,this.config=__spreadProps(__spreadValues({},this.config),{attributeList:(e=i==null?void 0:i.attributeList)!=null?e:[]})}dragMouseDown(t){this.checkMode||super.dragMouseDown(t)}deletePolygon(t){this.checkMode||super.deletePolygons(t?[t]:void 0)}deletePolygonPoint(t){this.checkMode||super.deletePolygonPoint(t)}setSelectedIDs(t){this.selection.hardSetSelectedIDs(t),this.selectedIDs.length<2&&this.setSelectedID(this.selectedIDs.length===1?this.selectedIDs[0]:""),this.render()}deleteSelectedID(){super.deleteSelectedID(),this.selection.setSelectedIDs(),this.emit("deleteSelectedIDs")}get selectedPolygons(){return PolygonUtils.getPolygonByIDs(this.polygonList,this.selectedIDs)}updateSelectedPolygonsPoints(t){var e,i;if(this.selectedPolygons&&((e=this.selectedPolygons)==null?void 0:e.length)>0){const s=___default.default.cloneDeep(this.selectedPolygons),l=[];(i=this.selectedPolygons)==null||i.forEach((r,h)=>{r.pointList=r.pointList.map(o=>{var d,a;const{x:u,y:c}=o;return __spreadProps(__spreadValues({},o),{x:u+((d=t.x)!=null?d:0),y:c+((a=t.y)!=null?a:0)})}),l.push({originPolygon:s[h],newPolygon:r})}),this.emit("updateResult"),this.emit("updatePolygonByDrag",l),this.render(),this.history.pushHistory(this.polygonList)}}getLineColor(){return"rgba(0, 255, 255, 0.5)"}getPointCloudLineColor(t){return t.valid===!1?lbUtils.INVALID_COLOR:lbUtils.toolStyleConverter.getColorFromConfig({attribute:t.attribute},__spreadProps(__spreadValues({},this.pointCloudConfig),{attributeConfigurable:!0}),{}).stroke}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.visiblePolygonList)==null||t.forEach(e=>{var i,s,l;if([...this.selectedIDs,this.editPolygonID].includes(e.id))return;const r=this.getPointCloudLineColor(e),h=AxisUtils.default.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos),o=this.highlightAttributeList.includes(e.attribute);DrawUtils.drawPolygonWithFillAndLine(this.canvas,h,{fillColor:o?r:"transparent",strokeColor:r,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(l=this.config)==null?void 0:l.lineType}),_.isNumber(e==null?void 0:e.trackID)&&(e==null?void 0:e.trackID)>=0&&this.renderdrawTrackID(e),e.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(h)}))}renderSelectedPolygon(){var t;(t=this.selectedPolygons)==null||t.forEach(e=>{this.renderSingleSelectedPolygon(e)})}renderdrawTrackID(t){
|
|
1
|
+
"use strict";var _=require("lodash"),lbUtils=require("@labelbee/lb-utils"),annotation=require("../../constant/annotation.js"),tool=require("../../constant/tool.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),defaultConfig=require("../../constant/defaultConfig.js"),polygonOperation=require("./polygonOperation.js"),basicToolOperation=require("./basicToolOperation.js");function _interopDefaultLegacy(n){return n&&typeof n=="object"&&"default"in n?n:{default:n}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(n,t,e)=>t in n?__defProp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,__spreadValues=(n,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(n,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(n,e,t[e]);return n},__spreadProps=(n,t)=>__defProps(n,__getOwnPropDescs(t));class PointCloud2dOperation extends polygonOperation{constructor(t){super(t);this.highlightAttributeList=[],this.rightMouseUp=o=>{var d;if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.selection.setSelectedIDs(this.hoverID,o.ctrlKey),this.emit("setSelectedIDs",this.selection.selectedIDs);const a=(d=this.polygonList.find(u=>u.id===this.hoverID))==null?void 0:d.attribute;a&&a!==this.defaultAttribute&&this.emit("syncAttribute",a)},this.onKeyDown=()=>{},this.onKeyUp=()=>{},this.renderSingleSelectedPolygon=o=>{var d;if(o){const a=this.getPointCloudLineColor(o),u=AxisUtils.default.changePointListByZoom(o.pointList,this.zoom,this.currentPos);DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,u,{fillColor:"transparent",strokeColor:a,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(d=this.config)==null?void 0:d.lineType}),o.isRect===!0&&this.showDirectionLine===!0&&(this.renderRectPolygonDirection(u),_.isNumber(o==null?void 0:o.trackID)&&(o==null?void 0:o.trackID)>=0&&this.renderdrawTrackID(o))}},this.emitUpdatePolygonByDrag=()=>{if(this.dragInfo){const{originPolygonList:o}=this.dragInfo;if(this.selectedIDs.length>0){const d=[];this.polygonList.forEach(a=>{if(this.selectedIDs.includes(a.id)){const u=o.find(c=>c.id===a.id);u&&d.push({newPolygon:a,originPolygon:u})}}),this.emit("updatePolygonByDrag",d)}}};var e,i,s,l,r,h;this.showDirectionLine=(e=t.showDirectionLine)!=null?e:!0,this.forbidAddNew=(i=t.forbidAddNew)!=null?i:!1,this.pointCloudConfig=(s=CommonToolUtils.jsonParser(t.config))!=null?s:{},this.hideAttributes=[],this.checkMode=(l=t.checkMode)!=null?l:!1,this.forbidAddNew===!1&&t.checkMode===!0&&(this.forbidAddNew=!0),this.config=__spreadProps(__spreadValues({},defaultConfig.polygonConfig),{textConfigurable:!1,attributeConfigurable:!0,attributeList:(h=(r=this.pointCloudConfig)==null?void 0:r.attributeList)!=null?h:[]})}get getSelectedIDs(){return this.selectedIDs}get enableDrag(){return Boolean(this.selectedIDs.length>0&&this.dragInfo)}get visiblePolygonList(){return this.polygonList.filter(t=>!this.hideAttributes.includes(t.attribute))}setHiddenAttributes(t){this.hideAttributes=t}setConfig(t){var e;const i=CommonToolUtils.jsonParser(t);this.pointCloudConfig=i,this.config=__spreadProps(__spreadValues({},this.config),{attributeList:(e=i==null?void 0:i.attributeList)!=null?e:[]})}dragMouseDown(t){this.checkMode||super.dragMouseDown(t)}deletePolygon(t){this.checkMode||super.deletePolygons(t?[t]:void 0)}deletePolygonPoint(t){this.checkMode||super.deletePolygonPoint(t)}setSelectedIDs(t){this.selection.hardSetSelectedIDs(t),this.selectedIDs.length<2&&this.setSelectedID(this.selectedIDs.length===1?this.selectedIDs[0]:""),this.render()}deleteSelectedID(){super.deleteSelectedID(),this.selection.setSelectedIDs(),this.emit("deleteSelectedIDs")}get selectedPolygons(){return PolygonUtils.getPolygonByIDs(this.polygonList,this.selectedIDs)}updateSelectedPolygonsPoints(t){var e,i;if(this.selectedPolygons&&((e=this.selectedPolygons)==null?void 0:e.length)>0){const s=___default.default.cloneDeep(this.selectedPolygons),l=[];(i=this.selectedPolygons)==null||i.forEach((r,h)=>{r.pointList=r.pointList.map(o=>{var d,a;const{x:u,y:c}=o;return __spreadProps(__spreadValues({},o),{x:u+((d=t.x)!=null?d:0),y:c+((a=t.y)!=null?a:0)})}),l.push({originPolygon:s[h],newPolygon:r})}),this.emit("updateResult"),this.emit("updatePolygonByDrag",l),this.render(),this.history.pushHistory(this.polygonList)}}getLineColor(){return"rgba(0, 255, 255, 0.5)"}getPointCloudLineColor(t){return t.valid===!1?lbUtils.INVALID_COLOR:lbUtils.toolStyleConverter.getColorFromConfig({attribute:t.attribute},__spreadProps(__spreadValues({},this.pointCloudConfig),{attributeConfigurable:!0}),{}).stroke}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.visiblePolygonList)==null||t.forEach(e=>{var i,s,l;if([...this.selectedIDs,this.editPolygonID].includes(e.id))return;const r=this.getPointCloudLineColor(e),h=AxisUtils.default.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos),o=this.highlightAttributeList.includes(e.attribute);DrawUtils.drawPolygonWithFillAndLine(this.canvas,h,{fillColor:o?r:"transparent",strokeColor:r,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(l=this.config)==null?void 0:l.lineType}),_.isNumber(e==null?void 0:e.trackID)&&(e==null?void 0:e.trackID)>=0&&this.renderdrawTrackID(e),e.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(h)}))}renderSelectedPolygon(){var t;(t=this.selectedPolygons)==null||t.forEach(e=>{this.renderSingleSelectedPolygon(e)})}renderdrawTrackID(t){var e,i;if(!((e=t==null?void 0:t.pointList)==null?void 0:e.length))return;const s=t.pointList[t.pointList.length-1],l=AxisUtils.default.changePointByZoom(s,this.zoom,this.currentPos),r=((i=t==null?void 0:t.trackID)==null?void 0:i.toString())||"";DrawUtils.drawText(this.canvas,l,r,__spreadValues({textAlign:"center",color:"white"},annotation.DEFAULT_TEXT_OFFSET))}renderRectPolygonDirection(t){t.length<2||DrawUtils.drawLine(this.canvas,t[0],t[1],{color:"white",thickness:3,lineDash:[6]})}get currentPolygonListByPattern(){return this.polygonList.filter(t=>this.pattern===tool.EPolygonPattern.Rect?t.isRect===!0:this.pattern===tool.EPolygonPattern.Normal?t.isRect!==!0:!0)}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),l=this.currentPolygonListByPattern.map(r=>__spreadProps(__spreadValues({},r),{pointList:AxisUtils.default.changePointListByZoom(r.pointList,this.zoom)}));return PolygonUtils.getHoverPolygonID(i,l,10,(e=this.config)==null?void 0:e.lineType)}switchToNextPolygon(t=annotation.ESortDirection.ascend){if(this.drawingPointList.length>0)return;const e=this.currentPolygonListByPattern.map(s=>{var l,r,h,o;return __spreadProps(__spreadValues({},s),{x:(r=(l=s.pointList[0])==null?void 0:l.x)!=null?r:0,y:(o=(h=s.pointList[0])==null?void 0:h.y)!=null?o:0})}),i=CommonToolUtils.getNextSelectedRectID(e,t,this.selectedID);if(i)return this.setSelectedIDs([i.id]),this.render(),[i.id]}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&this.setSelectedID(t)}updateTextAttribute(t){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributeInstance)==null||e.changeSelected()),t||(i=this._textAttributeInstance)==null||i.clearTextAttribute()}setSelectedID(t){this.updateTextAttribute(t),this.selection.setSelectedIDs(t),this.render()}addPointInDrawing(t){this.forbidAddNew||super.addPointInDrawing(t)}setCanvasSize(t){var e,i;const s=this.pixelRatio;this.size=t,this.setImgInfo(t),this.updateCanvasBasicStyle(this.basicCanvas,t,0),this.updateCanvasBasicStyle(this.canvas,t,10),(e=this.ctx)==null||e.scale(s,s),(i=this.basicCtx)==null||i.scale(s,s),this.initImgPos(),this.renderBasicCanvas(),this.render()}setPolygonValidAndRender(t,e=!1,i){if(e){super.setPolygonValidAndRender(t,i);return}this.emit("validUpdate",t)}onMouseDown(t){if(basicToolOperation.BasicToolOperation.prototype.onMouseDown.call(this,t)||this.forbidMouseOperation||t.ctrlKey===!0||t.button!==0)return;if(this.selectedIDs.length<2)return super.onMouseDown(t);const e=this.getCoordinateUnderZoom(t);this.dragInfo={dragStartCoord:e,dragTarget:annotation.EDragTarget.Plane,initPointList:[],changePointIndex:[0],originPolygon:this.selectedPolygon,dragPrevCoord:e,originPolygonList:this.polygonList,selectedPolygons:this.selectedPolygons}}setResultAndSelectedID(t,e){this.setPolygonList(t),this.setSelectedIDs([e])}setHighlightAttribute(t){this.highlightAttributeList=[t],this.render()}}module.exports=PointCloud2dOperation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var _=require("lodash"),lbUtils=require("@labelbee/lb-utils"),MathUtils=require("../../utils/MathUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),tool=require("../../constant/tool.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js"),Selection=require("./Selection.js");function _interopDefaultLegacy(c){return c&&typeof c=="object"&&"default"in c?c:{default:c}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(c,t,e)=>t in c?__defProp(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e,__spreadValues=(c,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(c,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(c,e,t[e]);return c},__spreadProps=(c,t)=>__defProps(c,__getOwnPropDescs(t));const TEXT_MAX_WIDTH=164;class PolygonOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.isAllowDouble=e=>{const{selectedID:i}=this,s=this.getHoverID(e);return!!(i&&i===s)},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.setPolygonList(AttributeUtils.default.textChange(e,this.selectedID,this.polygonList)),this.emit("selectedChange"),this.render())},this.emitUpdatePolygonByDrag=()=>{if(this.dragInfo){const{originPolygon:e}=this.dragInfo;this.emit("updatePolygonByDrag",[{newPolygon:this.selectedPolygon,originPolygon:e}])}},this.config=CommonToolUtils.jsonParser(t.config),this.drawingPointList=[],this.polygonList=[],this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.drawingHistory=new ActionsHistory,this.isCtrl=!1,this.isAlt=!1,this.isCombined=!1,this.pattern=tool.EPolygonPattern.Normal,this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.selection=new Selection(this)}get selectedIDs(){return this.selection.selectedIDs}get selectedID(){return this.selection.selectedID}get minArea(){return this.config.minArea||0}eventBinding(){super.eventBinding(),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseup",this.dragMouseUp),this.dblClickListener.addEvent(this.onMouseUp,this.onLeftDblClick,this.onRightDblClick,this.isAllowDouble)}eventUnbinding(){super.eventUnbinding(),this.container.removeEventListener("mouseup",this.dragMouseUp)}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}get selectedPolygon(){return PolygonUtils.getPolygonByID(this.visiblePolygonList,this.selectedID)}get selectedPolygons(){return PolygonUtils.getPolygonByIDs(this.polygonList,this.selectedIDs)}get hoverPolygon(){return this.visiblePolygonList.find(t=>t.id===this.hoverID&&t.id!==this.selectedID)}get enableDrag(){return Boolean(this.selectedID&&this.dragInfo)}get visiblePolygonList(){return this.polygonList}get polygonListUnderZoom(){return this.visiblePolygonList.map(t=>__spreadProps(__spreadValues({},t),{pointList:AxisUtils.default.changePointListByZoom(t.pointList,this.zoom)}))}get selectedText(){var t;return(t=this.selectedPolygon)==null?void 0:t.textAttribute}get isThreePointsMode(){return this.pattern===tool.EPolygonPattern.Rect&&this.drawingPointList.length===2}get isTwoPointsMode(){return this.pattern===tool.EPolygonPattern.Rect&&this.rectToolMode===tool.ERectToolModeType.TwoPoints&&this.drawingPointList.length===1}get dataList(){return this.polygonList}setPattern(t,e=!1){var i;((i=this.drawingPointList)==null?void 0:i.length)>0&&e===!0||(this.pattern=t)}get currentShowList(){let t=[];const[e,i]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);return t=e,this.isHidden&&(t=[]),i&&t.push(...i),t}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}setResultAndSelectedID(t,e){this.setPolygonList(t),e&&this.setSelectedID(e),this.render()}setResult(t){this.clearActiveStatus(),this.setPolygonList(t),this.render()}setPolygonDataByID(t,e){return this.polygonList.map(i=>i.id===e?__spreadValues(__spreadValues({},i),t):i)}rotatePolygon(t=1,e=annotation.ERotateDirection.Clockwise,i=this.selectedID){if(!i)return;const s=PolygonUtils.getPolygonByID(this.polygonList,i);if(!s)return;const o=PolygonUtils.updatePolygonByRotate(e,t,s==null?void 0:s.pointList);this.setPolygonList(this.setPolygonDataByID({pointList:o},i)),this.render()}rotatePolygonEdge(t,e=this.selectedID){!e||!PolygonUtils.getPolygonByID(this.polygonList,e)||(this.setPolygonList(this.setPolygonDataByID({pointList:t},e)),this.render())}addPointInDrawing(t){if(!this.imgInfo||this.forbidAddNewPolygonFuc&&this.forbidAddNewPolygonFuc(t))return;const{upperLimitPointNum:e,edgeAdsorption:i}=this.config;if(e&&this.drawingPointList.length>=e){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UpperLimitErrorNotice,this.lang)}${e}`);return}this.rectToolMode=localStorage.getItem(tool.RECT_TOOL_MODE_NAME),this.deleteSelectedID();const s=this.getCoordinateUnderZoom(t),o=AxisUtils.default.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(AxisUtils.default.returnClosePointIndex(o,AxisUtils.default.changePointListByZoom(this.drawingPointList,this.zoom))===0){this.addDrawingPointToPolygonList();return}const{dropFoot:n}=PolygonUtils.getClosestPoint(o,this.polygonListUnderZoom,this.config.lineType,tool.edgeAdsorptionScope),r=AxisUtils.default.changePointByZoom(n&&t.altKey===!1&&i?n:o,1/this.zoom);if(this.isThreePointsMode||this.isTwoPointsMode){if(this.isThreePointsMode){const h=MathUtils.default.getRectangleByRightAngle(r,this.drawingPointList);this.drawingPointList=h}else this.isTwoPointsMode&&(this.drawingPointList=this.createRectByTwoPointsMode(this.drawingPointList,r));if(this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(this.drawingPointList)){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.ForbiddenCreationOutsideBoundary,this.lang)}`),this.drawingPointList=[];return}this.addDrawingPointToPolygonList(!0);return}this.drawingPointList.push(r),this.drawingPointList.length===1?this.drawingHistory.initRecord(this.drawingPointList):this.drawingHistory.pushHistory(this.drawingPointList)}clearResult(){this.setPolygonList([]),this.deleteSelectedID(),this.render()}clearPolygonDrag(){this.drawingPointList=[],this.stopDrag(),this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,this.hoverID=""}clearActiveStatus(){this.clearPolygonDrag(),this.deleteSelectedID()}clearDrawingStatus(){this.drawingPointList=[]}setPolygonList(t){const e=this.polygonList.length;this.polygonList=t,e!==t.length&&this.emit("updatePageNumber")}setSelectedID(t,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t&&(this.changeStyle(t),this.emit("changeAttributeSidebar"),this.selectedPolygons.length>0&&(this.selectedPolygons.forEach(i=>{i.attribute=t}),this.history.pushHistory(this.polygonList),this.render()),this._textAttributeInstance)){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))}}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}setPolygonValidAndRender(t,e){if(!t)return;const i=this.polygonList.map(s=>{var o;if(s.id===t){const l=(o=s==null?void 0:s.valid)!=null?o:!0;return __spreadProps(__spreadValues({},s),{valid:e!=null?e:!l})}return s});this.setPolygonList(i),this.history.pushHistory(this.polygonList),this.render(),this.emit("updateResult")}addDrawingPointToPolygonList(t){let{lowerLimitPointNum:e=3}=this.config;e<3&&(e=3);let i;if(this.drawingPointList.length<e){this.drawingPointList=[],this.editPolygonID="";return}if(PolygonUtils.calcPolygonSize(this.drawingPointList||[])<this.minArea){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.MinAreaLimitErrorNotice,this.lang)}${this.minArea}`);return}const s=CommonToolUtils.getSourceID(this.basicResult),o=[...this.polygonList];if(this.editPolygonID){const l=o.find(n=>n.id===this.editPolygonID);if(!l)return;l.pointList=this.drawingPointList,this.editPolygonID=""}else{const l=uuid(8,62);let n={id:l,sourceID:s,valid:!this.isCtrl,textAttribute:"",pointList:this.drawingPointList,attribute:this.defaultAttribute,order:CommonToolUtils.getMaxOrder(o.filter(r=>CommonToolUtils.isSameSourceID(r.sourceID,s)))+1};if(this.config.textConfigurable){let r="";r=AttributeUtils.default.getTextAttribute(this.polygonList.filter(h=>CommonToolUtils.isSameSourceID(h.sourceID,s)),this.config.textCheckType),n=__spreadProps(__spreadValues({},n),{textAttribute:r})}this.pattern===tool.EPolygonPattern.Rect&&t===!0&&(n=__spreadProps(__spreadValues({},n),{isRect:!0})),o.push(n),i=n,this.setSelectedIdAfterAddingDrawing(l)}this.setPolygonList(o),this.isCtrl=!1,this.drawingPointList=[],this.history.pushHistory(o),i&&this.emit("polygonCreated",i,this.zoom,this.currentPos)}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&(this.config.textConfigurable?this.setSelectedID(t):this.deleteSelectedID())}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),s=this.currentShowList.map(o=>__spreadProps(__spreadValues({},o),{pointList:AxisUtils.default.changePointListByZoom(o.pointList,this.zoom)}));return PolygonUtils.getHoverPolygonID(i,s,10,(e=this.config)==null?void 0:e.lineType)}getHoverEdgeIndex(t){var e;if(!this.selectedID)return-1;const i=this.selectedPolygon;if(!i)return-1;const s=this.getCoordinateUnderZoom(t),o=AxisUtils.default.changePointListByZoom(i.pointList,this.zoom);return PolygonUtils.getHoverEdgeIndex(s,o,(e=this.config)==null?void 0:e.lineType)}getHoverPointIndex(t){if(!this.selectedID)return-1;const e=this.selectedPolygon;if(!e)return-1;const i=this.getCoordinateUnderZoom(t),s=AxisUtils.default.changePointListByZoom(e.pointList,this.zoom);return AxisUtils.default.returnClosePointIndex(i,s)}deletePolygons(t){var e;if(!t||t.length===0)return;const i=this.polygonList.filter(s=>this.selection.isIdSelected(s.id));this.emit("deletedObject",{deletedObject:i[0],id:i[0].id}),this.setPolygonList(this.polygonList.filter(s=>!this.selection.isIdSelected(s.id))),this.history.pushHistory(this.polygonList),(e=this._textAttributeInstance)==null||e.clearTextAttribute(),this.emit("selectedChange"),this.render()}deletePolygonPoint(t){if(!this.selectedID)return;const{selectedPolygon:e}=this;if(!e)return;let{lowerLimitPointNum:i}=this.config;if(i<3&&(i=3),e.pointList.length<=i){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.LowerLimitErrorNotice,this.lang)}${i}`);return}e==null||e.pointList.splice(t,1),this.history.pushHistory(this.polygonList),this.render()}spaceKeydown(){var t,e,i;if(this.selectedID){if(((t=this.selectedPolygon)==null?void 0:t.isRect)===!0){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UnableToReannotation,this.lang)}`);return}this.editPolygonID=this.selectedID,this.drawingPointList=(i=(e=this.selectedPolygon)==null?void 0:e.pointList)!=null?i:[],this.drawingHistory.empty(),this.drawingHistory.initRecord(this.drawingPointList),this.hoverID="",this.deleteSelectedID(),this.render()}}onTabKeyDown(t){t.preventDefault();let e=annotation.ESortDirection.ascend;t.shiftKey&&(e=annotation.ESortDirection.descend),this.switchToNextPolygon(e)}switchToNextPolygon(t){if(this.drawingPointList.length>0)return;const[e,i]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let s=[...e];i&&(s=[...s,...i]);const o=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom),l=s.map(r=>{var h,d,g,a;return __spreadProps(__spreadValues({},r),{x:(d=(h=r.pointList[0])==null?void 0:h.x)!=null?d:0,y:(a=(g=r.pointList[0])==null?void 0:g.y)!=null?a:0})}).filter(r=>CanvasUtils.inViewPort({x:r.x,y:r.y},o)),n=CommonToolUtils.getNextSelectedRectID(l,t,this.selectedID);if(n){this.setSelectedID(n.id);const{selectedPolygon:r}=this;r&&this.setDefaultAttribute(r.attribute)}this.render()}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1||this.selection.triggerKeyboardEvent(t,this.setPolygonList.bind(this)))return;const{keyCode:e}=t;switch(e){case keyCode.Space:this.spaceKeydown();break;case keyCode.Esc:this.drawingPointList=[],this.editPolygonID="";break;case keyCode.F:this.selectedID&&this.setPolygonValidAndRender(this.selectedID);break;case keyCode.Z:if(t.altKey){this.onCombinedExecute();return}this.setIsHidden(!this.isHidden),this.render();break;case keyCode.Delete:this.deletePolygons(this.selectedIDs),this.render();break;case keyCode.Ctrl:this.isCtrl=!0;break;case keyCode.Alt:this.isAlt===!1&&(t.preventDefault(),this.isAlt=!0,this.render());break;case keyCode.Tab:{this.onTabKeyDown(t);break}case keyCode.X:t.altKey&&this.segment();break;default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case keyCode.Ctrl:this.isCtrl=!1;break;case keyCode.Alt:{const e=this.isAlt;this.isAlt=!1,e===!0&&this.render();break}}}rightMouseUp(t){if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.setSelectedID(this.hoverID,t.ctrlKey);const{selectedPolygon:e}=this;e&&this.setDefaultAttribute(e.attribute)}onLeftDblClick(t){if(this.hoverEdgeIndex>-1){const e=this.getCoordinateUnderZoom(t),{selectedPolygon:i}=this;if(!i)return;if(i.isRect===!0){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.ForbidAddNewPoint,this.lang)}`),this.clearPolygonDrag();return}const{dropFoot:s}=PolygonUtils.getClosestPoint(e,this.polygonListUnderZoom,this.config.lineType,tool.edgeAdsorptionScope);if(!s)return;const{upperLimitPointNum:o}=this.config;if(o&&i.pointList.length>=o){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UpperLimitErrorNotice,this.lang)}${o}`),this.clearPolygonDrag();return}i==null||i.pointList.splice(this.hoverEdgeIndex+1,0,AxisUtils.default.changePointByZoom(s,1/this.zoom)),this.setPolygonDataByID(i,this.selectedID),this.history.pushHistory(this.polygonList),this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.render()}this.dragInfo=void 0}onRightDblClick(t){this.dragInfo=void 0,this.clearImgDrag();const e=this.getHoverID(t),i=this.getHoverPointIndex(t);if(this.hoverPointIndex>-1&&this.hoverPointIndex===i){this.deletePolygonPoint(i),this.dragInfo=void 0,this.hoverPointIndex=-1,this.render();return}this.hoverID===this.selectedID&&this.deletePolygons([e]),this.render()}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0))return this.dragMouseDown(t),!0}onMouseLeave(){this.dragInfo&&(this.emitUpdatePolygonByDrag(),this.clearPolygonDrag(),this.history.pushHistory(this.polygonList))}dragMouseDown(t){if(t.button!==0)return;const e=this.getHoverID(t);if(!this.selection.isIdSelected(e))return;let i=[0],s=annotation.EDragTarget.Plane;const o=this.selectedPolygons[0].pointList,l=this.getCoordinateUnderZoom(t);if(this.selectedPolygons.length===1){this.dragStatus=annotation.EDragStatus.Start;const n=this.getHoverPointIndex(t),r=this.getHoverEdgeIndex(t);n>-1?(s=annotation.EDragTarget.Point,i=[n]):r>-1&&this.hoverEdgeIndex>-1&&(s=annotation.EDragTarget.Line,i=[r,(r+1)%o.length])}this.dragInfo={dragStartCoord:l,dragTarget:s,initPointList:o,changePointIndex:i,originPolygon:this.selectedPolygon,selectedPolygons:this.selectedPolygons,dragPrevCoord:l,originPolygonList:this.polygonList}}segment(){var t;if(!this.selectedID||((t=this.config)==null?void 0:t.lineType)!==tool.ELineTypes.Line)return;const e=PolygonUtils.getPolygonPointList(this.selectedID,this.currentShowList),i=this.currentShowList.filter(l=>l.id!==this.selectedID);if(i.length===0||e.length===0)return;const s=PolygonUtils.getWrapPolygonIndex(e,i);let o=[...this.polygonList];if(s===-1){const l=PolygonUtils.segmentPolygonByPolygon(e,i);if(!l)return;const n=l.shift();if(!n)return;let r="",h=!0;const d=CommonToolUtils.getSourceID(this.basicResult);let g="";o=this.polygonList.map(a=>{var u,f;return a.id===this.selectedID?(r=a.attribute,h=(u=a==null?void 0:a.valid)!=null?u:!0,g=(f=a==null?void 0:a.textAttribute)!=null?f:"",__spreadProps(__spreadValues({},a),{pointList:n})):a}),l.length>0&&l.forEach((a,u)=>{o.push({sourceID:d,id:uuid(8,62),pointList:a,valid:h,order:CommonToolUtils.getMaxOrder(this.currentShowList)+1+u,attribute:r,textAttribute:g})})}else o[s].pointList=PolygonUtils.clipPolygonFromWrapPolygon(e,o[s].pointList),o=o.filter(l=>l.id!==this.selectedID);this.setPolygonList(o),this.history.pushHistory(o),this.render()}onCombinedExecute(){if(!this.selectedID){this.emit("messageInfo",lbUtils.i18n.t("PolygonsToBeCombinedNeedToBeSelected"));return}this.isCombined=!this.isCombined}combine(t){var e;const i=this.getHoverID(t);if(!i||!this.selectedID||this.selectedID===i)return;if(((e=this.config)==null?void 0:e.lineType)!==tool.ELineTypes.Line){this.emit("messageInfo",lbUtils.i18n.t("CurveModeDoesNotSupportCutting"));return}const s=this.polygonList.find(h=>h.id===this.selectedID),o=this.currentShowList.find(h=>h.id===i);if(!o||!s)return;const l=PolygonUtils.combinePolygonWithPolygon(s,o);if(!l)return;const{newPolygon:n,unionList:r}=l;if(r.length===1&&n){const h=this.polygonList.filter(d=>!r.includes(d.id)).map(d=>d.id===this.selectedID?n:d);this.setPolygonList(h),this.history.pushHistory(h),this.render(),this.emit("messageInfo",lbUtils.i18n.t("CombineSuccess"))}else this.emit("messageInfo",lbUtils.i18n.t("CombiningFailedNotify"));this.isCombined=!1}isPolygonOutSide(t){if(this.dependToolName&&this.basicCanvas&&this.basicResult){let n=!1;switch(this.dependToolName){case tool.EToolName.Rect:{n=t.filter(r=>!RectUtils.isInRect(r,this.basicResult)).length>0;break}case tool.EToolName.Polygon:{n=PolygonUtils.isPointListOutSidePolygon(t,this.basicResult.pointList,this.config.lineType);break}}return n}if(!this.imgInfo)return!1;const{left:e,top:i,right:s,bottom:o}=MathUtils.default.calcViewportBoundaries(AxisUtils.default.changePointListByZoom(t,this.zoom)),l=1e-5;return e<0||i<0||s>this.imgInfo.width+l||o>this.imgInfo.height+l}onDragMove(t){const e=this.polygonList.map(i=>{if(this.selectedIDs.includes(i.id)){const s=this.dragPolygon(t,i);if(!s)return i;const o=__spreadProps(__spreadValues({},i),{pointList:s});return i.isRect===!0&&this.pattern===tool.EPolygonPattern.Normal&&Object.assign(o,{isRect:!1}),o}return i});this.dragInfo.dragPrevCoord=this.getCoordinateUnderZoom(t),this.setPolygonList(e),this.render()}getDragOffset(t,e){var i;const s=this.getCoordinateUnderZoom(t),{dragTarget:o,dragPrevCoord:l,changePointIndex:n,initPointList:r,dragStartCoord:h}=this.dragInfo;if(this.pattern===tool.EPolygonPattern.Rect&&(e==null?void 0:e.isRect)===!0&&n&&[annotation.EDragTarget.Line].includes(o)){const d=MathUtils.default.getArrayIndex(n[0]-2,4),g=MathUtils.default.getArrayIndex(n[0]-1,4),a=[r[d],r[g]],u=MathUtils.default.getRectPerpendicularOffset(h,s,a);return{x:u.x/this.zoom,y:u.y/this.zoom}}return((i=this.dragInfo)==null?void 0:i.dragTarget)===annotation.EDragTarget.Plane?{x:(s.x-l.x)/this.zoom,y:(s.y-l.y)/this.zoom}:{x:(s.x-h.x)/this.zoom,y:(s.y-h.y)/this.zoom}}dragPolygon(t,e){let i=___default.default.cloneDeep(e==null?void 0:e.pointList);if(!i||!this.dragInfo)return;const{initPointList:s,dragTarget:o,changePointIndex:l}=this.dragInfo,n=this.getDragOffset(t,e);switch(this.dragStatus=annotation.EDragStatus.Move,o){case annotation.EDragTarget.Plane:i=i.map(r=>__spreadProps(__spreadValues({},r),{x:r.x+n.x,y:r.y+n.y}));break;case annotation.EDragTarget.Point:case annotation.EDragTarget.Line:i=i.map((r,h)=>l&&l.includes(h)?__spreadProps(__spreadValues({},r),{x:s[h].x+n.x,y:s[h].y+n.y}):r);break}if(this.pattern===tool.EPolygonPattern.Rect&&(e==null?void 0:e.isRect)===!0&&o===annotation.EDragTarget.Point&&l&&(i=MathUtils.default.getPointListFromPointOffset(s,l[0],n)),!(this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(i)))return i}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;let e=-1,i=-1;const{selectedID:s}=this;if(s&&(this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,e=this.getHoverPointIndex(t),e>-1?this.hoverPointIndex=e:(i=this.getHoverEdgeIndex(t),this.hoverEdgeIndex=i)),this.drawingPointList.length>0)return;const o=this.getHoverID(t);this.hoverID!==o&&(this.hoverID=o,this.render()),this.selectedIDs.length>0&&this.dragInfo&&this.onDragMove(t)}leftMouseUpdateValid(t){const e=this.getHoverID(t);return this.drawingPointList.length===0&&t.ctrlKey===!0&&e?(this.setPolygonValidAndRender(e),!0):!1}stopDrag(){this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait}leftMouseUp(t){this.leftMouseUpdateValid(t)||this.addPointInDrawing(t)}onMouseUp(t){if(this.isCombined){switch(t.button){case 0:this.combine(t);break;case 2:this.isCombined=!1;break;default:return}return}if(!(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.dragInfo&&this.dragStatus===annotation.EDragStatus.Move){this.emit("updateResult"),this.emitUpdatePolygonByDrag(),this.stopDrag(),this.history.pushHistory(this.polygonList);return}if(this.dragInfo&&this.dragStatus===annotation.EDragStatus.Start){this.stopDrag();return}switch(t.button){case 0:{this.leftMouseUp(t);break}case 2:{this.rightMouseUp(t);break}}this.render()}}dragMouseUp(){this.dragStatus===annotation.EDragStatus.Start&&this.stopDrag()}exportData(){const{polygonList:t}=this;return[t,this.basicImgInfo]}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}getCurrentSelectedData(){const{selectedPolygon:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:TEXT_MAX_WIDTH,textAttribute:t.textAttribute,color:i}}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let e=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPolygonList(AttributeUtils.default.textChange(e,this.selectedID,this.polygonList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t;const{selectedPolygon:e}=this;if(!this.ctx||this.config.textConfigurable===!1||!e)return;const{pointList:i,attribute:s,valid:o,textAttribute:l}=e,{x:n,y:r}=i[i.length-1],h=TEXT_MAX_WIDTH,d=AxisUtils.default.getOffsetCoordinate({x:n,y:r},this.currentPos,this.zoom),g=this.getColor(s),a=o?g==null?void 0:g.valid.stroke:g==null?void 0:g.invalid.stroke;this._textAttributeInstance||(this._textAttributeInstance=new textAttributeClass({width:h,container:this.container,icon:this.getTextIconSvg(s),color:a,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${l}`,{left:d.x,top:d.y,color:a,width:h})}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.visiblePolygonList)==null||t.forEach(e=>{var i,s,o,l,n;if([this.selectedID,this.editPolygonID].includes(e.id))return;const{textAttribute:r,attribute:h}=e,d=this.getColor(h),g=StyleUtils.getStrokeAndFill(d,e.valid),a=AxisUtils.default.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);DrawUtils.drawPolygonWithFillAndLine(this.canvas,a,{fillColor:g.fill,strokeColor:g.stroke,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(o=this.config)==null?void 0:o.lineType});let u=`${(l=AttributeUtils.default.getAttributeShowText(h,this.config.attributeList))!=null?l:""}`;((n=this.config)==null?void 0:n.isShowOrder)&&(e==null?void 0:e.order)>0&&(u=`${e.order} ${u}`),DrawUtils.drawText(this.canvas,a[0],u,__spreadValues({color:g.stroke},annotation.DEFAULT_TEXT_OFFSET));const f=a[a.length-1];DrawUtils.drawText(this.canvas,{x:f.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:f.y+annotation.TEXT_ATTRIBUTE_OFFSET.y},r,__spreadValues({color:g.stroke},annotation.DEFAULT_TEXT_OFFSET))}))}renderSelectedPolygons(){this.selectedPolygons.forEach(t=>{this.renderSelectedPolygon(t)})}renderSelectedPolygon(t){var e,i,s;if(t){const o=this.getColor(t.attribute),l=StyleUtils.getStrokeAndFill(o,t.valid,{isSelected:!0});DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,AxisUtils.default.changePointListByZoom(t.pointList,this.zoom,this.currentPos),{fillColor:l.fill,strokeColor:l.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(e=this.config)==null?void 0:e.lineType});let n=`${(i=AttributeUtils.default.getAttributeShowText(t.attribute,this.config.attributeList))!=null?i:""}`;((s=this.config)==null?void 0:s.isShowOrder)&&(t==null?void 0:t.order)>0&&(n=`${t.order} ${n}`),DrawUtils.drawText(this.canvas,AxisUtils.default.changePointByZoom(t.pointList[0],this.zoom,this.currentPos),n,__spreadValues({color:l.stroke},annotation.DEFAULT_TEXT_OFFSET)),this.renderTextAttribute()}}renderHoverPolygon(){var t;if(this.hoverID&&this.hoverID!==this.editPolygonID){const{hoverPolygon:e}=this;if(e){let i="";const s=this.getColor(e.attribute);e.valid?i=s.validHover.fill:i=StyleUtils.getStrokeAndFill(s,!1,{isHover:!0}).fill,DrawUtils.drawPolygonWithFill(this.canvas,AxisUtils.default.changePointListByZoom(e.pointList,this.zoom,this.currentPos),{color:i,lineType:(t=this.config)==null?void 0:t.lineType})}}}renderPolygon(){var t,e,i,s;this.renderStaticPolygon(),this.renderHoverPolygon(),this.renderSelectedPolygons();const o=this.getColor(this.defaultAttribute),l=StyleUtils.getStrokeAndFill(o,!this.isCtrl);if(((t=this.drawingPointList)==null?void 0:t.length)>0){let n=[...this.drawingPointList],r=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.isThreePointsMode)n=MathUtils.default.getRectangleByRightAngle(r,n);else if(((e=this.config)==null?void 0:e.edgeAdsorption)&&this.isAlt===!1){const{dropFoot:d}=PolygonUtils.getClosestPoint(r,this.polygonList,(i=this.config)==null?void 0:i.lineType,tool.edgeAdsorptionScope/this.zoom);d&&(r=d),n.push(r)}else this.isTwoPointsMode?n=this.createRectByTwoPointsMode(n,r):n.push(r);const h=AxisUtils.default.changePointListByZoom(n,this.zoom,this.currentPos);DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,h,{fillColor:l.fill,strokeColor:l.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!1,lineType:this.config.lineType}),this.isTwoPointsMode&&DrawUtils.drawLine(this.canvas,h[0],h[1],{color:"white",thickness:3,lineDash:[6]})}if(this.hoverPointIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const r=StyleUtils.getStrokeAndFill(o,n.valid,{isSelected:!0}),h=n==null?void 0:n.pointList[this.hoverPointIndex];if(h){const{x:d,y:g}=AxisUtils.default.changePointByZoom(h,this.zoom,this.currentPos);DrawUtils.drawCircleWithFill(this.canvas,{x:d,y:g},5,{color:r.fill})}}if(this.hoverEdgeIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const r=StyleUtils.getStrokeAndFill(o,n.valid,{isSelected:!0});DrawUtils.drawLineWithPointList(this.canvas,AxisUtils.default.changePointListByZoom(n.pointList,this.zoom,this.currentPos),{color:r.stroke,thickness:10,hoverEdgeIndex:this.hoverEdgeIndex,lineType:(s=this.config)==null?void 0:s.lineType})}}createRectByTwoPointsMode(t,e){const i=t[0],s=[...t],o=e.x>i.x&&e.y>i.y,l=e.x<i.x&&e.y<i.y;return o||l?s.push({x:i.x,y:e.y},e,{x:e.x,y:i.y}):s.push({x:e.x,y:i.y},e,{x:i.x,y:e.y}),s}render(){!this.ctx||(super.render(),this.renderPolygon(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}renderCursorLine(t){if(super.renderCursorLine(t),this.isCombined){const{x:e,y:i}=this.coord,s=10,o=186,l=32;DrawUtils.drawRectWithFill(this.canvas,{x:e+s,y:i-s*4-1,width:o,height:l},{color:"black"}),DrawUtils.drawText(this.canvas,{x:e,y:i},lbUtils.i18n.t("ClickAnotherPolygon"),{textAlign:"center",color:"white",offsetX:o/2+s,offsetY:-(l/2+s/2)}),DrawUtils.drawRect(this.canvas,{x:e-s,y:i-s,width:s*2,height:s*2},{lineDash:[6],color:"white"})}}undo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.undo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.undo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}redo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.redo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.redo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}deleteSelectedID(){this.setSelectedID("")}}module.exports=PolygonOperation;
|
|
1
|
+
"use strict";var _=require("lodash"),lbUtils=require("@labelbee/lb-utils"),MathUtils=require("../../utils/MathUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),tool=require("../../constant/tool.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js"),Selection=require("./Selection.js");function _interopDefaultLegacy(c){return c&&typeof c=="object"&&"default"in c?c:{default:c}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(c,t,e)=>t in c?__defProp(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e,__spreadValues=(c,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(c,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(c,e,t[e]);return c},__spreadProps=(c,t)=>__defProps(c,__getOwnPropDescs(t));const TEXT_MAX_WIDTH=164;class PolygonOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(__spreadProps(__spreadValues({},t),{isOffscreenCanvas:!0}));this.isAllowDouble=e=>{const{selectedID:i}=this,s=this.getHoverID(e);return!!(i&&i===s)},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.setPolygonList(AttributeUtils.default.textChange(e,this.selectedID,this.polygonList)),this.emit("selectedChange"),this.render())},this.lastMouseMoveTime=0,this.mouseMoveThrottle=16,this.emitUpdatePolygonByDrag=()=>{if(this.dragInfo){const{originPolygon:e}=this.dragInfo;this.emit("updatePolygonByDrag",[{newPolygon:this.selectedPolygon,originPolygon:e}])}},this.config=CommonToolUtils.jsonParser(t.config),this.drawingPointList=[],this.polygonList=[],this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.drawingHistory=new ActionsHistory,this.isCtrl=!1,this.isAlt=!1,this.isCombined=!1,this.pattern=tool.EPolygonPattern.Normal,this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.selection=new Selection(this)}get selectedIDs(){return this.selection.selectedIDs}get selectedID(){return this.selection.selectedID}get minArea(){return this.config.minArea||0}eventBinding(){super.eventBinding(),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseup",this.dragMouseUp),this.dblClickListener.addEvent(this.onMouseUp,this.onLeftDblClick,this.onRightDblClick,this.isAllowDouble)}eventUnbinding(){super.eventUnbinding(),this.container.removeEventListener("mouseup",this.dragMouseUp)}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}get selectedPolygon(){return PolygonUtils.getPolygonByID(this.visiblePolygonList,this.selectedID)}get selectedPolygons(){return PolygonUtils.getPolygonByIDs(this.polygonList,this.selectedIDs)}get hoverPolygon(){return this.visiblePolygonList.find(t=>t.id===this.hoverID&&t.id!==this.selectedID)}get enableDrag(){return Boolean(this.selectedID&&this.dragInfo)}get visiblePolygonList(){return this.polygonList}get polygonListUnderZoom(){return this.visiblePolygonList.map(t=>__spreadProps(__spreadValues({},t),{pointList:AxisUtils.default.changePointListByZoom(t.pointList,this.zoom)}))}get selectedText(){var t;return(t=this.selectedPolygon)==null?void 0:t.textAttribute}get isThreePointsMode(){return this.pattern===tool.EPolygonPattern.Rect&&this.drawingPointList.length===2}get isTwoPointsMode(){return this.pattern===tool.EPolygonPattern.Rect&&this.rectToolMode===tool.ERectToolModeType.TwoPoints&&this.drawingPointList.length===1}get dataList(){return this.polygonList}setPattern(t,e=!1){var i;((i=this.drawingPointList)==null?void 0:i.length)>0&&e===!0||(this.pattern=t)}get currentShowList(){let t=[];const[e,i]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);return t=e,this.isHidden&&(t=[]),i&&t.push(...i),t}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}setResultAndSelectedID(t,e){this.setPolygonList(t),e&&this.setSelectedID(e),this.render()}setResult(t){this.clearActiveStatus(),this.setPolygonList(t),this.render()}setPolygonDataByID(t,e){return this.polygonList.map(i=>i.id===e?__spreadValues(__spreadValues({},i),t):i)}rotatePolygon(t=1,e=annotation.ERotateDirection.Clockwise,i=this.selectedID){if(!i)return;const s=PolygonUtils.getPolygonByID(this.polygonList,i);if(!s)return;const o=PolygonUtils.updatePolygonByRotate(e,t,s==null?void 0:s.pointList);this.setPolygonList(this.setPolygonDataByID({pointList:o},i)),this.render()}rotatePolygonEdge(t,e=this.selectedID){!e||!PolygonUtils.getPolygonByID(this.polygonList,e)||(this.setPolygonList(this.setPolygonDataByID({pointList:t},e)),this.render())}addPointInDrawing(t){if(!this.imgInfo||this.forbidAddNewPolygonFuc&&this.forbidAddNewPolygonFuc(t))return;const{upperLimitPointNum:e,edgeAdsorption:i}=this.config;if(e&&this.drawingPointList.length>=e){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UpperLimitErrorNotice,this.lang)}${e}`);return}this.rectToolMode=localStorage.getItem(tool.RECT_TOOL_MODE_NAME),this.deleteSelectedID();const s=this.getCoordinateUnderZoom(t),o=AxisUtils.default.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(AxisUtils.default.returnClosePointIndex(o,AxisUtils.default.changePointListByZoom(this.drawingPointList,this.zoom))===0){this.addDrawingPointToPolygonList();return}const{dropFoot:l}=PolygonUtils.getClosestPoint(o,this.polygonListUnderZoom,this.config.lineType,tool.edgeAdsorptionScope),n=AxisUtils.default.changePointByZoom(l&&t.altKey===!1&&i?l:o,1/this.zoom);if(this.isThreePointsMode||this.isTwoPointsMode){if(this.isThreePointsMode){const h=MathUtils.default.getRectangleByRightAngle(n,this.drawingPointList);this.drawingPointList=h}else this.isTwoPointsMode&&(this.drawingPointList=this.createRectByTwoPointsMode(this.drawingPointList,n));if(this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(this.drawingPointList)){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.ForbiddenCreationOutsideBoundary,this.lang)}`),this.drawingPointList=[];return}this.addDrawingPointToPolygonList(!0);return}this.drawingPointList.push(n),this.drawingPointList.length===1?this.drawingHistory.initRecord(this.drawingPointList):this.drawingHistory.pushHistory(this.drawingPointList)}clearResult(){this.setPolygonList([]),this.deleteSelectedID(),this.render()}clearPolygonDrag(){this.drawingPointList=[],this.stopDrag(),this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,this.hoverID=""}clearActiveStatus(){this.clearPolygonDrag(),this.deleteSelectedID()}clearDrawingStatus(){this.drawingPointList=[]}setPolygonList(t){const e=this.polygonList.length;this.polygonList=t,e!==t.length&&this.emit("updatePageNumber")}setSelectedID(t,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t&&(this.changeStyle(t),this.emit("changeAttributeSidebar"),this.selectedPolygons.length>0&&(this.selectedPolygons.forEach(i=>{i.attribute=t}),this.history.pushHistory(this.polygonList),this.render()),this._textAttributeInstance)){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))}}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}setPolygonValidAndRender(t,e){if(!t)return;const i=this.polygonList.map(s=>{var o;if(s.id===t){const r=(o=s==null?void 0:s.valid)!=null?o:!0;return __spreadProps(__spreadValues({},s),{valid:e!=null?e:!r})}return s});this.setPolygonList(i),this.history.pushHistory(this.polygonList),this.render(),this.emit("updateResult")}addDrawingPointToPolygonList(t){let{lowerLimitPointNum:e=3}=this.config;e<3&&(e=3);let i;if(this.drawingPointList.length<e){this.drawingPointList=[],this.editPolygonID="";return}if(PolygonUtils.calcPolygonSize(this.drawingPointList||[])<this.minArea){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.MinAreaLimitErrorNotice,this.lang)}${this.minArea}`);return}const s=CommonToolUtils.getSourceID(this.basicResult),o=[...this.polygonList];if(this.editPolygonID){const r=o.find(l=>l.id===this.editPolygonID);if(!r)return;r.pointList=this.drawingPointList,this.editPolygonID=""}else{const r=uuid(8,62);let l={id:r,sourceID:s,valid:!this.isCtrl,textAttribute:"",pointList:this.drawingPointList,attribute:this.defaultAttribute,order:CommonToolUtils.getMaxOrder(o.filter(n=>CommonToolUtils.isSameSourceID(n.sourceID,s)))+1};if(this.config.textConfigurable){let n="";n=AttributeUtils.default.getTextAttribute(this.polygonList.filter(h=>CommonToolUtils.isSameSourceID(h.sourceID,s)),this.config.textCheckType),l=__spreadProps(__spreadValues({},l),{textAttribute:n})}this.pattern===tool.EPolygonPattern.Rect&&t===!0&&(l=__spreadProps(__spreadValues({},l),{isRect:!0})),o.push(l),i=l,this.setSelectedIdAfterAddingDrawing(r)}this.setPolygonList(o),this.isCtrl=!1,this.drawingPointList=[],this.history.pushHistory(o),i&&this.emit("polygonCreated",i,this.zoom,this.currentPos)}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&(this.config.textConfigurable?this.setSelectedID(t):this.deleteSelectedID())}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),s=this.currentShowList.map(o=>__spreadProps(__spreadValues({},o),{pointList:AxisUtils.default.changePointListByZoom(o.pointList,this.zoom)}));return PolygonUtils.getHoverPolygonID(i,s,10,(e=this.config)==null?void 0:e.lineType)}getHoverEdgeIndex(t){var e;if(!this.selectedID)return-1;const i=this.selectedPolygon;if(!i)return-1;const s=this.getCoordinateUnderZoom(t),o=AxisUtils.default.changePointListByZoom(i.pointList,this.zoom);return PolygonUtils.getHoverEdgeIndex(s,o,(e=this.config)==null?void 0:e.lineType)}getHoverPointIndex(t){if(!this.selectedID)return-1;const e=this.selectedPolygon;if(!e)return-1;const i=this.getCoordinateUnderZoom(t),s=AxisUtils.default.changePointListByZoom(e.pointList,this.zoom);return AxisUtils.default.returnClosePointIndex(i,s)}deletePolygons(t){var e;if(!t||t.length===0)return;const i=this.polygonList.filter(s=>this.selection.isIdSelected(s.id));this.emit("deletedObject",{deletedObject:i[0],id:i[0].id}),this.setPolygonList(this.polygonList.filter(s=>!this.selection.isIdSelected(s.id))),this.history.pushHistory(this.polygonList),(e=this._textAttributeInstance)==null||e.clearTextAttribute(),this.emit("selectedChange"),this.render()}deletePolygonPoint(t){if(!this.selectedID)return;const{selectedPolygon:e}=this;if(!e)return;let{lowerLimitPointNum:i}=this.config;if(i<3&&(i=3),e.pointList.length<=i){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.LowerLimitErrorNotice,this.lang)}${i}`);return}e==null||e.pointList.splice(t,1),this.history.pushHistory(this.polygonList),this.render()}spaceKeydown(){var t,e,i;if(this.selectedID){if(((t=this.selectedPolygon)==null?void 0:t.isRect)===!0){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UnableToReannotation,this.lang)}`);return}this.editPolygonID=this.selectedID,this.drawingPointList=(i=(e=this.selectedPolygon)==null?void 0:e.pointList)!=null?i:[],this.drawingHistory.empty(),this.drawingHistory.initRecord(this.drawingPointList),this.hoverID="",this.deleteSelectedID(),this.render()}}onTabKeyDown(t){t.preventDefault();let e=annotation.ESortDirection.ascend;t.shiftKey&&(e=annotation.ESortDirection.descend),this.switchToNextPolygon(e)}switchToNextPolygon(t){if(this.drawingPointList.length>0)return;const[e,i]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let s=[...e];i&&(s=[...s,...i]);const o=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom),r=s.map(n=>{var h,d,g,a;return __spreadProps(__spreadValues({},n),{x:(d=(h=n.pointList[0])==null?void 0:h.x)!=null?d:0,y:(a=(g=n.pointList[0])==null?void 0:g.y)!=null?a:0})}).filter(n=>CanvasUtils.inViewPort({x:n.x,y:n.y},o)),l=CommonToolUtils.getNextSelectedRectID(r,t,this.selectedID);if(l){this.setSelectedID(l.id);const{selectedPolygon:n}=this;n&&this.setDefaultAttribute(n.attribute)}this.render()}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1||this.selection.triggerKeyboardEvent(t,this.setPolygonList.bind(this)))return;const{keyCode:e}=t;switch(e){case keyCode.Space:this.spaceKeydown();break;case keyCode.Esc:this.drawingPointList=[],this.editPolygonID="";break;case keyCode.F:this.selectedID&&this.setPolygonValidAndRender(this.selectedID);break;case keyCode.Z:if(t.altKey){this.onCombinedExecute();return}this.setIsHidden(!this.isHidden),this.render();break;case keyCode.Delete:this.deletePolygons(this.selectedIDs),this.render();break;case keyCode.Ctrl:this.isCtrl=!0;break;case keyCode.Alt:this.isAlt===!1&&(t.preventDefault(),this.isAlt=!0,this.render());break;case keyCode.Tab:{this.onTabKeyDown(t);break}case keyCode.X:t.altKey&&this.segment();break;default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case keyCode.Ctrl:this.isCtrl=!1;break;case keyCode.Alt:{const e=this.isAlt;this.isAlt=!1,e===!0&&this.render();break}}}rightMouseUp(t){if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.setSelectedID(this.hoverID,t.ctrlKey);const{selectedPolygon:e}=this;e&&this.setDefaultAttribute(e.attribute)}onLeftDblClick(t){if(this.hoverEdgeIndex>-1){const e=this.getCoordinateUnderZoom(t),{selectedPolygon:i}=this;if(!i)return;if(i.isRect===!0){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.ForbidAddNewPoint,this.lang)}`),this.clearPolygonDrag();return}const{dropFoot:s}=PolygonUtils.getClosestPoint(e,this.polygonListUnderZoom,this.config.lineType,tool.edgeAdsorptionScope);if(!s)return;const{upperLimitPointNum:o}=this.config;if(o&&i.pointList.length>=o){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UpperLimitErrorNotice,this.lang)}${o}`),this.clearPolygonDrag();return}i==null||i.pointList.splice(this.hoverEdgeIndex+1,0,AxisUtils.default.changePointByZoom(s,1/this.zoom)),this.setPolygonDataByID(i,this.selectedID),this.history.pushHistory(this.polygonList),this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.render()}this.dragInfo=void 0}onRightDblClick(t){this.dragInfo=void 0,this.clearImgDrag();const e=this.getHoverID(t),i=this.getHoverPointIndex(t);if(this.hoverPointIndex>-1&&this.hoverPointIndex===i){this.deletePolygonPoint(i),this.dragInfo=void 0,this.hoverPointIndex=-1,this.render();return}this.hoverID===this.selectedID&&this.deletePolygons([e]),this.render()}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0))return this.dragMouseDown(t),!0}onMouseLeave(){this.dragInfo&&(this.emitUpdatePolygonByDrag(),this.clearPolygonDrag(),this.history.pushHistory(this.polygonList))}dragMouseDown(t){if(t.button!==0)return;const e=this.getHoverID(t);if(!this.selection.isIdSelected(e))return;let i=[0],s=annotation.EDragTarget.Plane;const o=this.selectedPolygons[0].pointList,r=this.getCoordinateUnderZoom(t);if(this.selectedPolygons.length===1){this.dragStatus=annotation.EDragStatus.Start;const l=this.getHoverPointIndex(t),n=this.getHoverEdgeIndex(t);l>-1?(s=annotation.EDragTarget.Point,i=[l]):n>-1&&this.hoverEdgeIndex>-1&&(s=annotation.EDragTarget.Line,i=[n,(n+1)%o.length])}this.dragInfo={dragStartCoord:r,dragTarget:s,initPointList:o,changePointIndex:i,originPolygon:this.selectedPolygon,selectedPolygons:this.selectedPolygons,dragPrevCoord:r,originPolygonList:this.polygonList}}segment(){var t;if(!this.selectedID||((t=this.config)==null?void 0:t.lineType)!==tool.ELineTypes.Line)return;const e=PolygonUtils.getPolygonPointList(this.selectedID,this.currentShowList),i=this.currentShowList.filter(r=>r.id!==this.selectedID);if(i.length===0||e.length===0)return;const s=PolygonUtils.getWrapPolygonIndex(e,i);let o=[...this.polygonList];if(s===-1){const r=PolygonUtils.segmentPolygonByPolygon(e,i);if(!r)return;const l=r.shift();if(!l)return;let n="",h=!0;const d=CommonToolUtils.getSourceID(this.basicResult);let g="";o=this.polygonList.map(a=>{var u,f;return a.id===this.selectedID?(n=a.attribute,h=(u=a==null?void 0:a.valid)!=null?u:!0,g=(f=a==null?void 0:a.textAttribute)!=null?f:"",__spreadProps(__spreadValues({},a),{pointList:l})):a}),r.length>0&&r.forEach((a,u)=>{o.push({sourceID:d,id:uuid(8,62),pointList:a,valid:h,order:CommonToolUtils.getMaxOrder(this.currentShowList)+1+u,attribute:n,textAttribute:g})})}else o[s].pointList=PolygonUtils.clipPolygonFromWrapPolygon(e,o[s].pointList),o=o.filter(r=>r.id!==this.selectedID);this.setPolygonList(o),this.history.pushHistory(o),this.render()}onCombinedExecute(){if(!this.selectedID){this.emit("messageInfo",lbUtils.i18n.t("PolygonsToBeCombinedNeedToBeSelected"));return}this.isCombined=!this.isCombined}combine(t){var e;const i=this.getHoverID(t);if(!i||!this.selectedID||this.selectedID===i)return;if(((e=this.config)==null?void 0:e.lineType)!==tool.ELineTypes.Line){this.emit("messageInfo",lbUtils.i18n.t("CurveModeDoesNotSupportCutting"));return}const s=this.polygonList.find(h=>h.id===this.selectedID),o=this.currentShowList.find(h=>h.id===i);if(!o||!s)return;const r=PolygonUtils.combinePolygonWithPolygon(s,o);if(!r)return;const{newPolygon:l,unionList:n}=r;if(n.length===1&&l){const h=this.polygonList.filter(d=>!n.includes(d.id)).map(d=>d.id===this.selectedID?l:d);this.setPolygonList(h),this.history.pushHistory(h),this.render(),this.emit("messageInfo",lbUtils.i18n.t("CombineSuccess"))}else this.emit("messageInfo",lbUtils.i18n.t("CombiningFailedNotify"));this.isCombined=!1}isPolygonOutSide(t){if(this.dependToolName&&this.basicCanvas&&this.basicResult){let l=!1;switch(this.dependToolName){case tool.EToolName.Rect:{l=t.filter(n=>!RectUtils.isInRect(n,this.basicResult)).length>0;break}case tool.EToolName.Polygon:{l=PolygonUtils.isPointListOutSidePolygon(t,this.basicResult.pointList,this.config.lineType);break}}return l}if(!this.imgInfo)return!1;const{left:e,top:i,right:s,bottom:o}=MathUtils.default.calcViewportBoundaries(AxisUtils.default.changePointListByZoom(t,this.zoom)),r=1e-5;return e<0||i<0||s>this.imgInfo.width+r||o>this.imgInfo.height+r}onDragMove(t){const e=this.polygonList.map(i=>{if(this.selectedIDs.includes(i.id)){const s=this.dragPolygon(t,i);if(!s)return i;const o=__spreadProps(__spreadValues({},i),{pointList:s});return i.isRect===!0&&this.pattern===tool.EPolygonPattern.Normal&&Object.assign(o,{isRect:!1}),o}return i});this.dragInfo.dragPrevCoord=this.getCoordinateUnderZoom(t),this.setPolygonList(e)}getDragOffset(t,e){var i;const s=this.getCoordinateUnderZoom(t),{dragTarget:o,dragPrevCoord:r,changePointIndex:l,initPointList:n,dragStartCoord:h}=this.dragInfo;if(this.pattern===tool.EPolygonPattern.Rect&&(e==null?void 0:e.isRect)===!0&&l&&[annotation.EDragTarget.Line].includes(o)){const d=MathUtils.default.getArrayIndex(l[0]-2,4),g=MathUtils.default.getArrayIndex(l[0]-1,4),a=[n[d],n[g]],u=MathUtils.default.getRectPerpendicularOffset(h,s,a);return{x:u.x/this.zoom,y:u.y/this.zoom}}return((i=this.dragInfo)==null?void 0:i.dragTarget)===annotation.EDragTarget.Plane?{x:(s.x-r.x)/this.zoom,y:(s.y-r.y)/this.zoom}:{x:(s.x-h.x)/this.zoom,y:(s.y-h.y)/this.zoom}}dragPolygon(t,e){let i=___default.default.cloneDeep(e==null?void 0:e.pointList);if(!i||!this.dragInfo)return;const{initPointList:s,dragTarget:o,changePointIndex:r}=this.dragInfo,l=this.getDragOffset(t,e);switch(this.dragStatus=annotation.EDragStatus.Move,o){case annotation.EDragTarget.Plane:i=i.map(n=>__spreadProps(__spreadValues({},n),{x:n.x+l.x,y:n.y+l.y}));break;case annotation.EDragTarget.Point:case annotation.EDragTarget.Line:i=i.map((n,h)=>r&&r.includes(h)?__spreadProps(__spreadValues({},n),{x:s[h].x+l.x,y:s[h].y+l.y}):n);break}if(this.pattern===tool.EPolygonPattern.Rect&&(e==null?void 0:e.isRect)===!0&&o===annotation.EDragTarget.Point&&r&&(i=MathUtils.default.getPointListFromPointOffset(s,r[0],l)),!(this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(i)))return i}determineTrigger(t){if(this.isDrag)return"drag";if(this.dragInfo)return"dragSingle";let e="";const i=this.getHoverID(t);this.hoverID!==i?(this.hoverID=i,e=""):e="move";let s=-1,o=-1;const{selectedID:r}=this;return r&&(s=this.getHoverPointIndex(t),s>-1?this.hoverPointIndex!==s?e="":e="noRender":(o=this.getHoverEdgeIndex(t),this.hoverEdgeIndex!==o?e="":e="noRender"),this.hoverEdgeIndex=o,this.hoverPointIndex=s),e}onMouseMove(t){requestAnimationFrame(()=>{const e=Date.now();if(e-this.lastMouseMoveTime<this.mouseMoveThrottle||(this.lastMouseMoveTime=e,super.onMouseMove(t,!1)||this.forbidMouseOperation||!this.imgInfo))return;if(this.drawingPointList.length>0){this.render();return}const i=this.determineTrigger(t);this.selectedIDs.length>0&&this.dragInfo&&this.onDragMove(t),this.render(i)})}leftMouseUpdateValid(t){const e=this.getHoverID(t);return this.drawingPointList.length===0&&t.ctrlKey===!0&&e?(this.setPolygonValidAndRender(e),!0):!1}stopDrag(){this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait}leftMouseUp(t){this.leftMouseUpdateValid(t)||this.addPointInDrawing(t)}onMouseUp(t){if(this.isCombined){switch(t.button){case 0:this.combine(t);break;case 2:this.isCombined=!1;break;default:return}return}if(!(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.dragInfo&&this.dragStatus===annotation.EDragStatus.Move){this.emit("updateResult"),this.emitUpdatePolygonByDrag(),this.stopDrag(),this.history.pushHistory(this.polygonList);return}if(this.dragInfo&&this.dragStatus===annotation.EDragStatus.Start){this.stopDrag();return}switch(t.button){case 0:{this.leftMouseUp(t);break}case 2:{this.rightMouseUp(t);break}}this.render()}}dragMouseUp(){this.dragStatus===annotation.EDragStatus.Start&&this.stopDrag()}exportData(){const{polygonList:t}=this;return[t,this.basicImgInfo]}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}getCurrentSelectedData(){const{selectedPolygon:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:TEXT_MAX_WIDTH,textAttribute:t.textAttribute,color:i}}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let e=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPolygonList(AttributeUtils.default.textChange(e,this.selectedID,this.polygonList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t;const{selectedPolygon:e}=this;if(!this.ctx||this.config.textConfigurable===!1||!e)return;const{pointList:i,attribute:s,valid:o,textAttribute:r}=e,{x:l,y:n}=i[i.length-1],h=TEXT_MAX_WIDTH,d=AxisUtils.default.getOffsetCoordinate({x:l,y:n},this.currentPos,this.zoom),g=this.getColor(s),a=o?g==null?void 0:g.valid.stroke:g==null?void 0:g.invalid.stroke;this._textAttributeInstance||(this._textAttributeInstance=new textAttributeClass({width:h,container:this.container,icon:this.getTextIconSvg(s),color:a,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${r}`,{left:d.x,top:d.y,color:a,width:h})}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.visiblePolygonList)==null||t.forEach(e=>{var i,s,o,r,l;if([this.selectedID,this.editPolygonID].includes(e.id))return;const{textAttribute:n,attribute:h}=e,d=this.getColor(h),g=StyleUtils.getStrokeAndFill(d,e.valid),a=AxisUtils.default.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);DrawUtils.drawPolygonWithFillAndLine(this.canvas,a,{fillColor:g.fill,strokeColor:g.stroke,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(o=this.config)==null?void 0:o.lineType});let u=`${(r=AttributeUtils.default.getAttributeShowText(h,this.config.attributeList))!=null?r:""}`;((l=this.config)==null?void 0:l.isShowOrder)&&(e==null?void 0:e.order)>0&&(u=`${e.order} ${u}`),DrawUtils.drawText(this.canvas,a[0],u,__spreadValues({color:g.stroke},annotation.DEFAULT_TEXT_OFFSET));const f=a[a.length-1];DrawUtils.drawText(this.canvas,{x:f.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:f.y+annotation.TEXT_ATTRIBUTE_OFFSET.y},n,__spreadValues({color:g.stroke},annotation.DEFAULT_TEXT_OFFSET))}))}renderSelectedPolygons(){this.selectedPolygons.forEach(t=>{this.renderSelectedPolygon(t)})}renderSelectedPolygon(t){var e,i,s;if(t){const o=this.getColor(t.attribute),r=StyleUtils.getStrokeAndFill(o,t.valid,{isSelected:!0});DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,AxisUtils.default.changePointListByZoom(t.pointList,this.zoom,this.currentPos),{fillColor:r.fill,strokeColor:r.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(e=this.config)==null?void 0:e.lineType});let l=`${(i=AttributeUtils.default.getAttributeShowText(t.attribute,this.config.attributeList))!=null?i:""}`;((s=this.config)==null?void 0:s.isShowOrder)&&(t==null?void 0:t.order)>0&&(l=`${t.order} ${l}`),DrawUtils.drawText(this.canvas,AxisUtils.default.changePointByZoom(t.pointList[0],this.zoom,this.currentPos),l,__spreadValues({color:r.stroke},annotation.DEFAULT_TEXT_OFFSET)),this.renderTextAttribute()}}renderHoverPolygon(){var t;if(this.hoverID&&this.hoverID!==this.editPolygonID){const{hoverPolygon:e}=this;if(e){let i="";const s=this.getColor(e.attribute);e.valid?i=s.validHover.fill:i=StyleUtils.getStrokeAndFill(s,!1,{isHover:!0}).fill,DrawUtils.drawPolygonWithFill(this.canvas,AxisUtils.default.changePointListByZoom(e.pointList,this.zoom,this.currentPos),{color:i,lineType:(t=this.config)==null?void 0:t.lineType})}}}renderPolygon(t){var e,i,s,o;t!=="move"&&this.renderStaticPolygon(),this.renderHoverPolygon(),this.renderSelectedPolygons();const r=this.getColor(this.defaultAttribute),l=StyleUtils.getStrokeAndFill(r,!this.isCtrl);if(((e=this.drawingPointList)==null?void 0:e.length)>0){let n=[...this.drawingPointList],h=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.isThreePointsMode)n=MathUtils.default.getRectangleByRightAngle(h,n);else if(((i=this.config)==null?void 0:i.edgeAdsorption)&&this.isAlt===!1){const{dropFoot:g}=PolygonUtils.getClosestPoint(h,this.polygonList,(s=this.config)==null?void 0:s.lineType,tool.edgeAdsorptionScope/this.zoom);g&&(h=g),n.push(h)}else this.isTwoPointsMode?n=this.createRectByTwoPointsMode(n,h):n.push(h);const d=AxisUtils.default.changePointListByZoom(n,this.zoom,this.currentPos);DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,d,{fillColor:l.fill,strokeColor:l.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!1,lineType:this.config.lineType}),this.isTwoPointsMode&&DrawUtils.drawLine(this.canvas,d[0],d[1],{color:"white",thickness:3,lineDash:[6]})}if(this.hoverPointIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const h=StyleUtils.getStrokeAndFill(r,n.valid,{isSelected:!0}),d=n==null?void 0:n.pointList[this.hoverPointIndex];if(d){const{x:g,y:a}=AxisUtils.default.changePointByZoom(d,this.zoom,this.currentPos);DrawUtils.drawCircleWithFill(this.canvas,{x:g,y:a},5,{color:h.fill})}}if(this.hoverEdgeIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const h=StyleUtils.getStrokeAndFill(r,n.valid,{isSelected:!0});DrawUtils.drawLineWithPointList(this.canvas,AxisUtils.default.changePointListByZoom(n.pointList,this.zoom,this.currentPos),{color:h.stroke,thickness:10,hoverEdgeIndex:this.hoverEdgeIndex,lineType:(o=this.config)==null?void 0:o.lineType})}}createRectByTwoPointsMode(t,e){const i=t[0],s=[...t],o=e.x>i.x&&e.y>i.y,r=e.x<i.x&&e.y<i.y;return o||r?s.push({x:i.x,y:e.y},e,{x:e.x,y:i.y}):s.push({x:e.x,y:i.y},e,{x:i.x,y:e.y}),s}render(t){!this.ctx||(t!=="move"&&super.render(),t!=="drag"&&t!=="dragSingle"&&this.renderPolygon(t),t==="dragSingle"&&this.renderSelectedPolygons(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}renderCursorLine(t){requestAnimationFrame(()=>{this.clearOffscreenCanvas();const{x:e,y:i}=this.coord;if(DrawUtils.drawLine(this.offscreenCanvas,{x:0,y:i},{x:1e4,y:i},{color:t}),DrawUtils.drawLine(this.offscreenCanvas,{x:e,y:0},{x:e,y:1e4},{color:t}),DrawUtils.drawCircleWithFill(this.offscreenCanvas,{x:e,y:i},1,{color:"white"}),this.isCombined){const s=10,o=186,r=32;DrawUtils.drawRectWithFill(this.canvas,{x:e+s,y:i-s*4-1,width:o,height:r},{color:"black"}),DrawUtils.drawText(this.canvas,{x:e,y:i},lbUtils.i18n.t("ClickAnotherPolygon"),{textAlign:"center",color:"white",offsetX:o/2+s,offsetY:-(r/2+s/2)}),DrawUtils.drawRect(this.canvas,{x:e-s,y:i-s,width:s*2,height:s*2},{lineDash:[6],color:"white"})}})}undo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.undo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.undo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}redo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.redo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.redo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}deleteSelectedID(){this.setSelectedID("")}}module.exports=PolygonOperation;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _=require("lodash"),turf=require("@turf/turf"),MathUtils=require("../../utils/MathUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),TagUtils=require("../../utils/tool/TagUtils.js"),annotation=require("../../constant/annotation.js"),tool=require("../../constant/tool.js"),keyCode=require("../../constant/keyCode.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),MarkerUtils=require("../../utils/tool/MarkerUtils.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js"),Selection=require("./Selection.js");function _interopDefaultLegacy(f){return f&&typeof f=="object"&&"default"in f?f:{default:f}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(f,t,e)=>t in f?__defProp(f,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):f[t]=e,__spreadValues=(f,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(f,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(f,e,t[e]);return f},__spreadProps=(f,t)=>__defProps(f,__getOwnPropDescs(t));const scope=6;class RectOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.highlightVisible=!1,this.enableAddRect=!0,this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,r=this.currentPageResult.find(n=>n.label===i);r&&(this.setSelectedRectID(r.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(r.attribute)),this.emit("markIndexChange")},this.getHoverRectID=e=>{const i=this.getCoordinateUnderZoom(e),r=scope,{currentShowList:n}=this;if(n.length>0){if(this.selectedRectID){const{selectedRect:a}=this;if(a&&RectUtils.isInRect(i,a,r,this.zoom))return a.id}const s=n.filter(a=>RectUtils.isInRect(i,a,r,this.zoom));if(s.length===0)return"";if(s.length===1)return s[0].id;if(s.length>1)return s.map(o=>({size:o.width*o.height,id:o.id})).sort((o,h)=>o.size-h.size)[0].id}return""},this.getSelectedRectTextAttribute=e=>{if(e){const i=this.rectList.find(r=>r.id===e);return(i==null?void 0:i.textAttribute)||""}return""},this.setDefaultSubAttribute=()=>{var e,i,r,n;if(((e=this.config)==null?void 0:e.secondaryAttributeConfigurable)&&((i=this.config)==null?void 0:i.subAttributeList)){const s=TagUtils.getDefaultResultByConfig((n=(r=this.config)==null?void 0:r.subAttributeList)!=null?n:[]);this.setRectList(this.rectList.map(a=>{var o;if(a.id===this.selectedRectID){const h=(o=a==null?void 0:a.subAttribute)!=null?o:s;return __spreadProps(__spreadValues({},a),{subAttribute:h})}return a}),!0)}},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedRectID||(this.setRectList(AttributeUtils.default.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this._drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=CommonToolUtils.jsonParser(t.config),this.hoverRectEdgeIndex=-1,this.hoverRectPointIndex=-1,this.selectedRectTextAttribute="",this.markerIndex=0,this.createNewDrawingRect=this.createNewDrawingRect.bind(this),this.getDrawingRectWithRectList=this.getDrawingRectWithRectList.bind(this),this.setSelectedIdAfterAddingDrawingRect=this.setSelectedIdAfterAddingDrawingRect.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedRectTextAttribute=this.updateSelectedRectTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this),this.updateSelectedRectSubAttribute=this.updateSelectedRectSubAttribute.bind(this),this.selection=new Selection(this)}renderPointCloud2DHighlight(){}setResult(t){if(this.clearActiveStatus(),this.setRectList(t),this.hasMarkerConfig){const e=CommonToolUtils.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndex(e.index)}this.render()}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}setConfig(t,e=!1){this.config=CommonToolUtils.jsonParser(t),e===!0&&this.clearResult(!1)}setRectList(t,e=!1){const i=this.rectList.length;this.rectList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}get selectedRectID(){return this.selectedIDs.length===1?this.selectedIDs[0]:void 0}get selectedID(){return this.selectedRectID}get drawOutSideTarget(){return this._drawOutSideTarget||this.config.drawOutsideTarget}get selectedRect(){return this.selectedRects.length===1?this.selectedRects[0]:void 0}get selectedIDs(){return this.selection.selectedIDs}get selectedRects(){return this.rectList.filter(t=>this.selectedIDs.includes(t.id))}get selectedText(){var t;return(t=this.selectedRect)==null?void 0:t.textAttribute}get dataList(){return this.rectList}get currentShowList(){let t=[];const[e,i]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);return t=e,this.isHidden&&(t=[]),i&&t.push(...i),t}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=CommonToolUtils.getRenderResultList(t,CommonToolUtils.getSourceID(this.basicResult),[]);return e}setSelectedID(t){this.setSelectedRectID(t)}setSelectedRectID(t,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}updateSelectedRectTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedRectID){let e=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setRectList(this.rectList.map(i=>i.id===this.selectedRectID?__spreadProps(__spreadValues({},i),{textAttribute:e}):i),!0),this.emit("updateTextAttribute"),this.render()}}updateSelectedRectSubAttribute(t,e){e&&this.config.secondaryAttributeConfigurable===!0&&this.selectedRectID&&(this.setRectList(this.rectList.map(i=>{var r;if(i.id===this.selectedRectID){const n=(r=i==null?void 0:i.subAttribute)!=null?r:{};return __spreadProps(__spreadValues({},i),{subAttribute:__spreadProps(__spreadValues({},n),{[t]:e})})}return i}),!0),this.render())}getHoverRectPointIndex(t){return this.selectedRect?AxisUtils.default.returnClosePointIndex(this.getCoordinateUnderZoom(t),RectUtils.getRectPointList(this.selectedRect,this.zoom),scope+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:i}=this,r=RectUtils.getRectEdgeList(i,this.zoom),n=this.getCoordinateUnderZoom(t);for(let s=0;s<r.length;s++){const a=r[s],{length:o}=MathUtils.default.getFootOfPerpendicular(n,a.begin,a.end);o<scope+10&&(e=s)}return e}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.getCoordinateUnderZoom(t),i=this.getHoverRectID(t);if(!(t.button===2||t.button===0&&this.isSpaceKey===!0)){if(this.selectedRectID){const r=this.currentShowList.find(n=>n.id===this.selectedRectID);if(!r)return;if(this.getHoverRectPointIndex(t)>-1){const n=tool.EDragTarget.Point;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:r},this.dragStatus=annotation.EDragStatus.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const n=tool.EDragTarget.Line;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:r},this.dragStatus=annotation.EDragStatus.Start;return}}if(this.selection.isIdSelected(i)&&!this.drawingRect){const r=tool.EDragTarget.Plane;this.dragInfo={dragStartCoord:e,dragTarget:r,firstRect:this.selectedRect,startTime:+new Date,originRectList:this.selectedRects},this.dragStatus=annotation.EDragStatus.Start}}}appendOffsetRect(t,e){return __spreadProps(__spreadValues({},t),{x:t.x+e.x/this.zoom,y:t.y+e.y/this.zoom})}getRectsBoundaries(t,e){const i=t.reduce((r,n)=>r.concat(...RectUtils.getRectPointList(this.appendOffsetRect(n,e))),[]);return MathUtils.default.calcViewportBoundaries(i)}isRectsOutOfTarget(t,e){var i,r,n,s;if(this.drawOutSideTarget!==!1)return!1;const a=this.getRectsBoundaries(t,e),o={y:a.top,x:a.left,height:a.bottom-a.top,width:a.right-a.left};if(((r=(i=this.basicResult)==null?void 0:i.pointList)==null?void 0:r.length)>0)return RectUtils.isRectNotInPolygon(o,polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom));if(this.basicResult||this.imgInfo){const h=this.basicResult?this.basicResult:{x:0,y:0,height:(n=this.imgNode)==null?void 0:n.height,width:(s=this.imgNode)==null?void 0:s.width};if(h)return[{x:a.left,y:a.top},{x:a.right,y:a.bottom}].some(d=>!RectUtils.isInRect(d,h))}return!1}moveRects(t){var e;if((e=this.dragInfo)==null?void 0:e.originRectList){let i=___default.default.cloneDeep(this.dragInfo.originRectList);if(this.isRectsOutOfTarget(i,t))return;i=this.dragInfo.originRectList.map(r=>__spreadProps(__spreadValues({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom})),this.setRectList(this.rectList.map(r=>{const n=i.find(s=>s.id===r.id);return n||r}))}}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originRectList)==null?void 0:i.length)||(this.setRectList(this.dragInfo.originRectList.map(r=>__spreadProps(__spreadValues({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom}))),this.render())}onDragMove(t){var e,i,r,n;if(!this.dragInfo)return;const s={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};if(this.dragStatus=annotation.EDragStatus.Move,this.dragInfo.dragTarget===tool.EDragTarget.Plane){this.moveRects(s);return}if(!this.dragInfo.firstRect)return;const a=RectUtils.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:o,y:h,width:d,height:c}=a;let l=this.rectList.filter(u=>u.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case tool.EDragTarget.Point:{let u=o,g=h,R=d,b=c;switch(this.hoverRectPointIndex){case 0:{u=d-s.x<0?o+d:o+s.x,g=c-s.y<0?h+c:h+s.y,R=Math.abs(s.x-d),b=Math.abs(s.y-c);break}case 1:{u=d+s.x>0?o:o+d+s.x,g=c-s.y<0?h+c:h+s.y,R=Math.abs(d+s.x),b=Math.abs(c-s.y);break}case 2:{u=d+s.x>0?o:o+d+s.x,g=c+s.y>0?h:h+c+s.y,R=Math.abs(d+s.x),b=c+s.y>0?c+s.y:Math.abs(c+s.y);break}case 3:{u=d-s.x<0?o+d:o+s.x,g=c+s.y>0?h:h+c+s.y,R=Math.abs(s.x-d),b=c+s.y>0?c+s.y:Math.abs(c+s.y);break}default:return}l=__spreadProps(__spreadValues({},l),{x:u,y:g,width:R,height:b})}break;case tool.EDragTarget.Line:{let u=o,g=h,R=d,b=c;switch(this.hoverRectEdgeIndex){case 0:{g=c-s.y<0?h+c:h+s.y,b=Math.abs(s.y-c);break}case 1:{u=d+s.x>0?o:o+d+s.x,R=Math.abs(d+s.x);break}case 2:{g=c+s.y>0?h:h+c+s.y,b=c+s.y>0?c+s.y:Math.abs(c+s.y);break}case 3:{u=d-s.x<0?o+d:o+s.x,R=Math.abs(s.x-d);break}default:return}l=__spreadProps(__spreadValues({},l),{x:u,y:g,width:R,height:b});break}default:return}if(this.drawOutSideTarget===!1){if(this.basicResult){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&RectUtils.isRectNotInPolygon(l,polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;const u=this.basicResult.x*this.zoom,g=this.basicResult.y*this.zoom,R=this.basicResult.width*this.zoom,b=this.basicResult.height*this.zoom;if(l.x<u-.01||l.y<g-.01||l.width>u+R-l.x+.01||l.height>g+b-l.y+.01)return;if(l.x<u&&(l.x=u),l.y<g&&(l.y=g),l.width>u+R-l.x)switch(this.dragInfo.dragTarget){case tool.EDragTarget.Point:case tool.EDragTarget.Line:s.x>0&&s.y>0&&(l.width=u+R-l.x);break;default:return}if(l.height>g+b-l.y)switch(this.dragInfo.dragTarget){}}else if(l.x<0&&(l.x=0),l.y<0&&(l.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){default:if(l.x+l.width>((r=this.imgInfo)==null?void 0:r.width)+.01||l.y+l.height>((n=this.imgInfo)==null?void 0:n.height)+.01)return}}this.setRectList(this.rectList.map(u=>u.id===l.id?RectUtils.getRectUnderZoom(l,1/this.zoom):u)),this.render()}onMouseMove(t){var e,i;if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const r=this.getCoordinateUnderZoom(t),n=AxisUtils.default.changeDrawOutsideTarget(r,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.selectedIDs.length>0&&this.dragInfo){this.onDragMove(n);return}if(this.selectedRectID){const o=this.getHoverRectPointIndex(t);if(o!==this.hoverRectPointIndex){this.hoverRectPointIndex=o,this.hoverRectEdgeIndex=-1,this.render();return}if(this.hoverRectPointIndex===-1){const h=this.getHoverRectEdgeIndex(t);if(h!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=h,this.render();return}}}const s=this.getHoverRectID(t),a=this.hoverRectID;if(this.hoverRectID=s,s!==a&&this.render(),this.enableAddRect&&this.drawingRect&&this.firstClickCoord){let{x:o,y:h}=this.firstClickCoord,{width:d,height:c}=this.drawingRect;if(d=Math.abs(o-n.x),c=Math.abs(h-n.y),n.x<o&&(o=n.x),n.y<h&&(h=n.y),this.drawOutSideTarget===!1){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&RectUtils.isRectNotInPolygon(__spreadProps(__spreadValues({},this.drawingRect),{x:o,y:h,width:d,height:c}),polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;n.x<0&&(d=Math.abs(this.firstClickCoord.x),o=0),n.y<0&&(c=Math.abs(this.firstClickCoord.y),h=0),this.imgInfo&&(o+d>this.imgInfo.width&&(d=Math.abs(this.imgInfo.width-o)),h+c>this.imgInfo.height&&(c=Math.abs(this.imgInfo.height-h)))}this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{x:o,y:h,width:d,height:c}),this.render()}}setHighlightVisible(t){this.highlightVisible=t,this.setAttributeLockList([])}setAttributeLockList(t){this.setSelectedRectID(void 0),(t==null?void 0:t.length)&&(this.highlightVisible=!1),super.setAttributeLockList(t)}setBasicResult(t){super.setBasicResult(t),this.clearActiveStatus()}setRectValidAndRender(t){!t||(this.setRectList(this.rectList.map(e=>e.id===t?__spreadProps(__spreadValues({},e),{valid:!e.valid}):e),!0),this.render(),this.emit("updateResult"))}createNewDrawingRect(t,e){var i,r,n,s;if(!this.imgInfo)return;const a=this.getCoordinateUnderZoom(t),o=AxisUtils.default.changeDrawOutsideTarget(a,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.setSelectedRectID(""),this.hoverRectID="",this.drawOutSideTarget&&(o.x<0&&(o.x=0),o.y<0&&(o.y=0)),this.drawingRect=__spreadProps(__spreadValues({},o),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:uuid(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const h=CommonToolUtils.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(h)this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{label:h.label})),this.markerIndex=h.index,this.emit("markIndexChange");else{this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let h="";h=AttributeUtils.default.getTextAttribute(this.rectList.filter(d=>CommonToolUtils.isSameSourceID(d.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{textAttribute:h}))}if(((i=this.config)==null?void 0:i.secondaryAttributeConfigurable)&&((r=this.config)==null?void 0:r.subAttributeList)){const h=TagUtils.getDefaultResultByConfig((s=(n=this.config)==null?void 0:n.subAttributeList)!=null?s:[]);this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{subAttribute:h})}if(Object.assign(this.drawingRect,{order:CommonToolUtils.getMaxOrder(this.rectList.filter(h=>CommonToolUtils.isSameSourceID(h.sourceID,e)))+1}),this.firstClickCoord=__spreadValues({},o),this.firstCurrentPos=__spreadValues({},this.currentPos),this.dataInjectionAtCreation){const h=this.dataInjectionAtCreation(this.drawingRect);h&&Object.assign(this.drawingRect,h)}}addDrawingRectToRectList(){if(!this.drawingRect)return;let{width:t,height:e}=this.drawingRect;if(t/=this.zoom,e/=this.zoom,Math.round(t)<this.config.minWidth||Math.round(e)<this.config.minHeight){this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.RectErrorSizeNotice,this.lang)),this.clearDrawingStatus(),this.render();return}const i=this.getDrawingRectWithRectList();this.setRectList(i,!0),this.history.pushHistory(this.rectList),this.setSelectedIdAfterAddingDrawingRect(),this.clearDrawingStatus()}setSelectedIdAfterAddingDrawingRect(){var t;!this.drawingRect||(this.config.textConfigurable||((t=this.config)==null?void 0:t.secondaryAttributeConfigurable)?this.setSelectedRectID(this.drawingRect.id):this.setSelectedRectID())}getDrawingRectWithRectList(){if(!this.drawingRect)return this.rectList;let{x:t,y:e,width:i,height:r}=this.drawingRect;return t/=this.zoom,e/=this.zoom,i/=this.zoom,r/=this.zoom,[...this.rectList,__spreadProps(__spreadValues({},this.drawingRect),{x:t,y:e,width:i,height:r})]}rightMouseUp(t){var e,i,r,n,s;const a=this.getHoverRectID(t),o=this.rectList.find(h=>h.id===a);if(this.selectedRectTextAttribute="",this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else{if(((e=this.dragInfo)==null?void 0:e.dragStartCoord)&&turf.distance((i=this.dragInfo)==null?void 0:i.dragStartCoord,this.getCoordinateUnderZoom(t))>3&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(a,t.ctrlKey),o&&((r=this.selectedIDs)==null?void 0:r.length)===1&&(this.selectedRectTextAttribute=this.getSelectedRectTextAttribute(a),this.setDefaultAttribute(o.attribute)),this.hoverRectID="",(o==null?void 0:o.label)&&this.hasMarkerConfig){const h=CommonToolUtils.getCurrentMarkerIndex(o.label,this.config.markerList);h>=0&&(this.setMarkerIndex(h),this.emit("markIndexChange"))}((n=this.config)==null?void 0:n.secondaryAttributeConfigurable)&&((s=this.config)==null?void 0:s.subAttributeList)&&this.setDefaultSubAttribute()}return this.render(),o}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}updateDragResult(){this.emit("updateDragResult",__spreadValues({},this.selectedRect))}setEnableAddRect(t){this.enableAddRect=t}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===annotation.EDragStatus.Move){this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.history.pushHistory(this.rectList),this.emit("updateResult"),this.updateDragResult();return}if(t.button===2&&t.shiftKey===!0){this.shiftRightMouseUp(t);return}if(t.button===2){this.rightMouseUp(t);return}const e=CommonToolUtils.getSourceID(this.basicResult);if(this.drawingRect){this.enableAddRect?this.addDrawingRectToRectList():(this.clearDrawingStatus(),this.render());return}if(t.ctrlKey===!0&&t.button===0&&this.hoverRectID){this.setRectValidAndRender(this.hoverRectID);return}this.enableAddRect&&(this.createNewDrawingRect(t,e),this.render())}onRightDblClick(t){super.onRightDblClick(t);const e=this.getHoverRectID(t);this.selection.isIdSelected(e)&&this.deleteSelectedRect(t)}deleteSelectedRect(t){this.selectedRects.forEach(e=>{this.deleteRect(e.id)})}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1||this.selection.triggerKeyboardEvent(t,this.setRectList.bind(this)))return;const{keyCode:e}=t;switch(e){case keyCode.Ctrl:this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case keyCode.F:this.selectedRectID&&this.setRectValidAndRender(this.selectedRectID);break;case keyCode.Z:this.setIsHidden(!this.isHidden),this.render();break;case keyCode.Delete:this.deleteSelectedRect(t);break;case keyCode.Tab:{if(t.preventDefault(),this.drawingRect)return;let i=annotation.ESortDirection.ascend;t.shiftKey&&(i=annotation.ESortDirection.descend);const[r,n]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let s=[...r];n&&(s=[...s,...n]);const a=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom);s=s.filter(h=>CanvasUtils.inViewPort({x:h.x,y:h.y},a));const o=CommonToolUtils.getNextSelectedRectID(s,i,this.selectedRectID);o&&(this.setSelectedRectID(o.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(o.attribute));break}default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}return!0}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case keyCode.Ctrl:this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let i,r;this.drawingRect&&this.firstClickCoord&&(i=RectUtils.getRectUnderZoom(this.drawingRect,1/e),r=AxisUtils.default.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),i&&r&&(this.drawingRect=RectUtils.getRectUnderZoom(i,this.zoom),this.firstClickCoord=AxisUtils.default.changePointByZoom(r,this.zoom)),this.render()}getCurrentSelectedData(){const{selectedRect:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:t.width*this.zoom*.6,textAttribute:t.textAttribute,color:i}}getRenderStyle(t){const e=this.customRenderStyle&&this.customRenderStyle(t);if(e)return e;const i=this.getColor(t.attribute);let r,n;return t.valid===!1?(r=i==null?void 0:i.invalid.stroke,n=i==null?void 0:i.invalid.fill):(r=i==null?void 0:i.valid.stroke,n=i==null?void 0:i.valid.fill),{strokeColor:r,fillColor:n,textColor:r,toolColor:i}}renderTextAttribute(){var t;const{selectedRect:e}=this;if(!this.ctx||this.config.textConfigurable!==!0||!e)return;const{x:i,y:r,width:n,height:s,attribute:a,valid:o}=e,h=n*this.zoom*.6,d=AxisUtils.default.getOffsetCoordinate({x:i,y:r+s},this.currentPos,this.zoom),c=this.getColor(a),l=o?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke,u=4;this._textAttributeInstance||(this._textAttributeInstance=new textAttributeClass({width:h,container:this.container,icon:this.getTextIconSvg(a),color:l,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedRectTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${e.textAttribute}`,{left:d.x,top:d.y+u,color:l,width:h})}renderSelectedRect(t){if(!this.ctx||!t)return;const{ctx:e}=this;let i=10;const r=RectUtils.getRectPointList(t),n=r.length,s=this.getColor(t.attribute);r.forEach((a,o)=>{var h,d;if(e.save(),e.moveTo(a.x,a.y),e.beginPath(),this.hoverRectPointIndex===o?i=scope+6:i=scope,t.valid===!1?(e.strokeStyle=s==null?void 0:s.invalid.stroke,e.fillStyle=s==null?void 0:s.invalid.stroke):(e.strokeStyle=s==null?void 0:s.valid.stroke,e.fillStyle=s==null?void 0:s.valid.stroke),e.arc(a.x*this.zoom+this.currentPos.x,a.y*this.zoom+this.currentPos.y,i,0,2*Math.PI),e.fill(),this.hoverRectEdgeIndex===o){e.beginPath(),e.lineWidth=10;const c=this.getColor(t.attribute),l=t.valid===!1?(h=c==null?void 0:c.invalid)==null?void 0:h.stroke:(d=c==null?void 0:c.valid)==null?void 0:d.stroke;e.strokeStyle=l,e.moveTo(r[o].x*this.zoom+this.currentPos.x,r[o].y*this.zoom+this.currentPos.y),e.lineTo(r[(o+1)%n].x*this.zoom+this.currentPos.x,r[(o+1)%n].y*this.zoom+this.currentPos.y),e.stroke()}e.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,i=!1,r=!1){var n,s,a,o,h,d;if(this.ctx&&t){const{ctx:c,style:l}=this,{hiddenText:u=!1}=l;c.save();const{strokeColor:g,fillColor:R,textColor:b}=this.getRenderStyle(t);c.font="lighter 14px Arial";let v="";((n=this.config)==null?void 0:n.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(v=`${t.order}`),t.label&&this.hasMarkerConfig&&(v=`${CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${MarkerUtils.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(v=`${v} ${AttributeUtils.default.getAttributeShowText(t.attribute,(s=this.config)==null?void 0:s.attributeList)}`,(t==null?void 0:t.subAttribute)&&((a=this.config)==null?void 0:a.secondaryAttributeConfigurable)&&((o=this.config)==null?void 0:o.subAttributeList)&&TagUtils.getTagNameList(t.subAttribute,this.config.subAttributeList).forEach(I=>{v+=`
|
|
2
|
-
${I.keyName}: ${I.value.join("\u3001")}`}));const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _=require("lodash"),turf=require("@turf/turf"),MathUtils=require("../../utils/MathUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),TagUtils=require("../../utils/tool/TagUtils.js"),annotation=require("../../constant/annotation.js"),tool=require("../../constant/tool.js"),keyCode=require("../../constant/keyCode.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),MarkerUtils=require("../../utils/tool/MarkerUtils.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js"),Selection=require("./Selection.js");function _interopDefaultLegacy(f){return f&&typeof f=="object"&&"default"in f?f:{default:f}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(f,t,e)=>t in f?__defProp(f,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):f[t]=e,__spreadValues=(f,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(f,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(f,e,t[e]);return f},__spreadProps=(f,t)=>__defProps(f,__getOwnPropDescs(t));const scope=6;class RectOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.highlightVisible=!1,this.enableAddRect=!0,this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,r=this.currentPageResult.find(o=>o.label===i);r&&(this.setSelectedRectID(r.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(r.attribute)),this.emit("markIndexChange")},this.getHoverRectID=e=>{const i=this.getCoordinateUnderZoom(e),r=scope,{currentShowList:o}=this;if(o.length>0){if(this.selectedRectID){const{selectedRect:a}=this;if(a&&RectUtils.isInRect(i,a,r,this.zoom))return a.id}const s=o.filter(a=>RectUtils.isInRect(i,a,r,this.zoom));if(s.length===0)return"";if(s.length===1)return s[0].id;if(s.length>1)return s.map(h=>({size:h.width*h.height,id:h.id})).sort((h,n)=>h.size-n.size)[0].id}return""},this.getSelectedRectTextAttribute=e=>{if(e){const i=this.rectList.find(r=>r.id===e);return(i==null?void 0:i.textAttribute)||""}return""},this.lastMouseMoveTime=0,this.mouseMoveThrottle=16,this.setDefaultSubAttribute=()=>{var e,i,r,o;if(((e=this.config)==null?void 0:e.secondaryAttributeConfigurable)&&((i=this.config)==null?void 0:i.subAttributeList)){const s=TagUtils.getDefaultResultByConfig((o=(r=this.config)==null?void 0:r.subAttributeList)!=null?o:[]);this.setRectList(this.rectList.map(a=>{var h;if(a.id===this.selectedRectID){const n=(h=a==null?void 0:a.subAttribute)!=null?h:s;return __spreadProps(__spreadValues({},a),{subAttribute:n})}return a}),!0)}},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedRectID||(this.setRectList(AttributeUtils.default.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this._drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=CommonToolUtils.jsonParser(t.config),this.hoverRectEdgeIndex=-1,this.hoverRectPointIndex=-1,this.selectedRectTextAttribute="",this.markerIndex=0,this.createNewDrawingRect=this.createNewDrawingRect.bind(this),this.getDrawingRectWithRectList=this.getDrawingRectWithRectList.bind(this),this.setSelectedIdAfterAddingDrawingRect=this.setSelectedIdAfterAddingDrawingRect.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedRectTextAttribute=this.updateSelectedRectTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this),this.updateSelectedRectSubAttribute=this.updateSelectedRectSubAttribute.bind(this),this.selection=new Selection(this)}renderPointCloud2DHighlight(){}setResult(t){if(this.clearActiveStatus(),this.setRectList(t),this.hasMarkerConfig){const e=CommonToolUtils.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndex(e.index)}this.render()}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}setConfig(t,e=!1){this.config=CommonToolUtils.jsonParser(t),e===!0&&this.clearResult(!1)}setRectList(t,e=!1){const i=this.rectList.length;this.rectList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}get selectedRectID(){return this.selectedIDs.length===1?this.selectedIDs[0]:void 0}get selectedID(){return this.selectedRectID}get drawOutSideTarget(){return this._drawOutSideTarget||this.config.drawOutsideTarget}get selectedRect(){return this.selectedRects.length===1?this.selectedRects[0]:void 0}get selectedIDs(){return this.selection.selectedIDs}get selectedRects(){return this.rectList.filter(t=>this.selectedIDs.includes(t.id))}get selectedText(){var t;return(t=this.selectedRect)==null?void 0:t.textAttribute}get dataList(){return this.rectList}get currentShowList(){let t=[];const[e,i]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);return t=e,this.isHidden&&(t=[]),i&&t.push(...i),t}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=CommonToolUtils.getRenderResultList(t,CommonToolUtils.getSourceID(this.basicResult),[]);return e}setSelectedID(t){this.setSelectedRectID(t)}setSelectedRectID(t,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}updateSelectedRectTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedRectID){let e=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setRectList(this.rectList.map(i=>i.id===this.selectedRectID?__spreadProps(__spreadValues({},i),{textAttribute:e}):i),!0),this.emit("updateTextAttribute"),this.render()}}updateSelectedRectSubAttribute(t,e){e&&this.config.secondaryAttributeConfigurable===!0&&this.selectedRectID&&(this.setRectList(this.rectList.map(i=>{var r;if(i.id===this.selectedRectID){const o=(r=i==null?void 0:i.subAttribute)!=null?r:{};return __spreadProps(__spreadValues({},i),{subAttribute:__spreadProps(__spreadValues({},o),{[t]:e})})}return i}),!0),this.render())}getHoverRectPointIndex(t){return this.selectedRect?AxisUtils.default.returnClosePointIndex(this.getCoordinateUnderZoom(t),RectUtils.getRectPointList(this.selectedRect,this.zoom),scope+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:i}=this,r=RectUtils.getRectEdgeList(i,this.zoom),o=this.getCoordinateUnderZoom(t);for(let s=0;s<r.length;s++){const a=r[s],{length:h}=MathUtils.default.getFootOfPerpendicular(o,a.begin,a.end);h<scope+10&&(e=s)}return e}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.getCoordinateUnderZoom(t),i=this.getHoverRectID(t);if(!(t.button===2||t.button===0&&this.isSpaceKey===!0)){if(this.selectedRectID){const r=this.currentShowList.find(o=>o.id===this.selectedRectID);if(!r)return;if(this.getHoverRectPointIndex(t)>-1){const o=tool.EDragTarget.Point;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=annotation.EDragStatus.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const o=tool.EDragTarget.Line;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=annotation.EDragStatus.Start;return}}if(this.selection.isIdSelected(i)&&!this.drawingRect){const r=tool.EDragTarget.Plane;this.dragInfo={dragStartCoord:e,dragTarget:r,firstRect:this.selectedRect,startTime:+new Date,originRectList:this.selectedRects},this.dragStatus=annotation.EDragStatus.Start}}}appendOffsetRect(t,e){return __spreadProps(__spreadValues({},t),{x:t.x+e.x/this.zoom,y:t.y+e.y/this.zoom})}getRectsBoundaries(t,e){const i=t.reduce((r,o)=>r.concat(...RectUtils.getRectPointList(this.appendOffsetRect(o,e))),[]);return MathUtils.default.calcViewportBoundaries(i)}isRectsOutOfTarget(t,e){var i,r,o,s;if(this.drawOutSideTarget!==!1)return!1;const a=this.getRectsBoundaries(t,e),h={y:a.top,x:a.left,height:a.bottom-a.top,width:a.right-a.left};if(((r=(i=this.basicResult)==null?void 0:i.pointList)==null?void 0:r.length)>0)return RectUtils.isRectNotInPolygon(h,polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom));if(this.basicResult||this.imgInfo){const n=this.basicResult?this.basicResult:{x:0,y:0,height:(o=this.imgNode)==null?void 0:o.height,width:(s=this.imgNode)==null?void 0:s.width};if(n)return[{x:a.left,y:a.top},{x:a.right,y:a.bottom}].some(d=>!RectUtils.isInRect(d,n))}return!1}moveRects(t){var e;if((e=this.dragInfo)==null?void 0:e.originRectList){let i=___default.default.cloneDeep(this.dragInfo.originRectList);if(this.isRectsOutOfTarget(i,t))return;i=this.dragInfo.originRectList.map(r=>__spreadProps(__spreadValues({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom})),this.setRectList(this.rectList.map(r=>{const o=i.find(s=>s.id===r.id);return o||r}))}}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originRectList)==null?void 0:i.length)||(this.setRectList(this.dragInfo.originRectList.map(r=>__spreadProps(__spreadValues({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom}))),this.render())}onDragMove(t){var e,i,r,o;if(!this.dragInfo)return;const s={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};if(this.dragStatus=annotation.EDragStatus.Move,this.dragInfo.dragTarget===tool.EDragTarget.Plane){this.moveRects(s);return}if(!this.dragInfo.firstRect)return;const a=RectUtils.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:h,y:n,width:d,height:c}=a;let l=this.rectList.filter(u=>u.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case tool.EDragTarget.Point:{let u=h,g=n,R=d,b=c;switch(this.hoverRectPointIndex){case 0:{u=d-s.x<0?h+d:h+s.x,g=c-s.y<0?n+c:n+s.y,R=Math.abs(s.x-d),b=Math.abs(s.y-c);break}case 1:{u=d+s.x>0?h:h+d+s.x,g=c-s.y<0?n+c:n+s.y,R=Math.abs(d+s.x),b=Math.abs(c-s.y);break}case 2:{u=d+s.x>0?h:h+d+s.x,g=c+s.y>0?n:n+c+s.y,R=Math.abs(d+s.x),b=c+s.y>0?c+s.y:Math.abs(c+s.y);break}case 3:{u=d-s.x<0?h+d:h+s.x,g=c+s.y>0?n:n+c+s.y,R=Math.abs(s.x-d),b=c+s.y>0?c+s.y:Math.abs(c+s.y);break}default:return}l=__spreadProps(__spreadValues({},l),{x:u,y:g,width:R,height:b})}break;case tool.EDragTarget.Line:{let u=h,g=n,R=d,b=c;switch(this.hoverRectEdgeIndex){case 0:{g=c-s.y<0?n+c:n+s.y,b=Math.abs(s.y-c);break}case 1:{u=d+s.x>0?h:h+d+s.x,R=Math.abs(d+s.x);break}case 2:{g=c+s.y>0?n:n+c+s.y,b=c+s.y>0?c+s.y:Math.abs(c+s.y);break}case 3:{u=d-s.x<0?h+d:h+s.x,R=Math.abs(s.x-d);break}default:return}l=__spreadProps(__spreadValues({},l),{x:u,y:g,width:R,height:b});break}default:return}if(this.drawOutSideTarget===!1){if(this.basicResult){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&RectUtils.isRectNotInPolygon(l,polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;const u=this.basicResult.x*this.zoom,g=this.basicResult.y*this.zoom,R=this.basicResult.width*this.zoom,b=this.basicResult.height*this.zoom;if(l.x<u-.01||l.y<g-.01||l.width>u+R-l.x+.01||l.height>g+b-l.y+.01)return;if(l.x<u&&(l.x=u),l.y<g&&(l.y=g),l.width>u+R-l.x)switch(this.dragInfo.dragTarget){case tool.EDragTarget.Point:case tool.EDragTarget.Line:s.x>0&&s.y>0&&(l.width=u+R-l.x);break;default:return}if(l.height>g+b-l.y)switch(this.dragInfo.dragTarget){}}else if(l.x<0&&(l.x=0),l.y<0&&(l.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){default:if(l.x+l.width>((r=this.imgInfo)==null?void 0:r.width)+.01||l.y+l.height>((o=this.imgInfo)==null?void 0:o.height)+.01)return}}this.setRectList(this.rectList.map(u=>u.id===l.id?RectUtils.getRectUnderZoom(l,1/this.zoom):u)),this.render()}onMouseMove(t){requestAnimationFrame(()=>{var e,i;const r=Date.now();if(r-this.lastMouseMoveTime<this.mouseMoveThrottle||(this.lastMouseMoveTime=r,super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo))return;const o=this.getCoordinateUnderZoom(t),s=AxisUtils.default.changeDrawOutsideTarget(o,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.selectedIDs.length>0&&this.dragInfo){this.onDragMove(s);return}if(this.selectedRectID){const n=this.getHoverRectPointIndex(t);if(n!==this.hoverRectPointIndex){this.hoverRectPointIndex=n,this.hoverRectEdgeIndex=-1,this.render();return}if(this.hoverRectPointIndex===-1){const d=this.getHoverRectEdgeIndex(t);if(d!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=d,this.render();return}}}const a=this.getHoverRectID(t),h=this.hoverRectID;if(this.hoverRectID=a,a!==h&&this.render(),this.enableAddRect&&this.drawingRect&&this.firstClickCoord){let{x:n,y:d}=this.firstClickCoord,{width:c,height:l}=this.drawingRect;if(c=Math.abs(n-s.x),l=Math.abs(d-s.y),s.x<n&&(n=s.x),s.y<d&&(d=s.y),this.drawOutSideTarget===!1){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&RectUtils.isRectNotInPolygon(__spreadProps(__spreadValues({},this.drawingRect),{x:n,y:d,width:c,height:l}),polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;s.x<0&&(c=Math.abs(this.firstClickCoord.x),n=0),s.y<0&&(l=Math.abs(this.firstClickCoord.y),d=0),this.imgInfo&&(n+c>this.imgInfo.width&&(c=Math.abs(this.imgInfo.width-n)),d+l>this.imgInfo.height&&(l=Math.abs(this.imgInfo.height-d)))}this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{x:n,y:d,width:c,height:l}),this.render()}})}setHighlightVisible(t){this.highlightVisible=t,this.setAttributeLockList([])}setAttributeLockList(t){this.setSelectedRectID(void 0),(t==null?void 0:t.length)&&(this.highlightVisible=!1),super.setAttributeLockList(t)}setBasicResult(t){super.setBasicResult(t),this.clearActiveStatus()}setRectValidAndRender(t){const e=this.rectList.some(i=>i==null?void 0:i.valid);this.setRectList(this.rectList.map(i=>i.id===t?__spreadProps(__spreadValues({},i),{valid:!i.valid}):(this.selection.isIdSelected(i.id)&&(i.valid=!e),i)),!0),this.render(),this.emit("updateResult")}createNewDrawingRect(t,e){var i,r,o,s;if(!this.imgInfo)return;const a=this.getCoordinateUnderZoom(t),h=AxisUtils.default.changeDrawOutsideTarget(a,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.setSelectedRectID(""),this.hoverRectID="",this.drawOutSideTarget&&(h.x<0&&(h.x=0),h.y<0&&(h.y=0)),this.drawingRect=__spreadProps(__spreadValues({},h),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:uuid(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const n=CommonToolUtils.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(n)this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{label:n.label})),this.markerIndex=n.index,this.emit("markIndexChange");else{this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let n="";n=AttributeUtils.default.getTextAttribute(this.rectList.filter(d=>CommonToolUtils.isSameSourceID(d.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{textAttribute:n}))}if(((i=this.config)==null?void 0:i.secondaryAttributeConfigurable)&&((r=this.config)==null?void 0:r.subAttributeList)){const n=TagUtils.getDefaultResultByConfig((s=(o=this.config)==null?void 0:o.subAttributeList)!=null?s:[]);this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{subAttribute:n})}if(Object.assign(this.drawingRect,{order:CommonToolUtils.getMaxOrder(this.rectList.filter(n=>CommonToolUtils.isSameSourceID(n.sourceID,e)))+1}),this.firstClickCoord=__spreadValues({},h),this.firstCurrentPos=__spreadValues({},this.currentPos),this.dataInjectionAtCreation){const n=this.dataInjectionAtCreation(this.drawingRect);n&&Object.assign(this.drawingRect,n)}}addDrawingRectToRectList(){if(!this.drawingRect)return;let{width:t,height:e}=this.drawingRect;if(t/=this.zoom,e/=this.zoom,Math.round(t)<this.config.minWidth||Math.round(e)<this.config.minHeight){this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.RectErrorSizeNotice,this.lang)),this.clearDrawingStatus(),this.render();return}const i=this.getDrawingRectWithRectList();this.setRectList(i,!0),this.history.pushHistory(this.rectList),this.setSelectedIdAfterAddingDrawingRect(),this.clearDrawingStatus()}setSelectedIdAfterAddingDrawingRect(){var t;!this.drawingRect||(this.config.textConfigurable||((t=this.config)==null?void 0:t.secondaryAttributeConfigurable)?this.setSelectedRectID(this.drawingRect.id):this.setSelectedRectID())}getDrawingRectWithRectList(){if(!this.drawingRect)return this.rectList;let{x:t,y:e,width:i,height:r}=this.drawingRect;return t/=this.zoom,e/=this.zoom,i/=this.zoom,r/=this.zoom,[...this.rectList,__spreadProps(__spreadValues({},this.drawingRect),{x:t,y:e,width:i,height:r})]}rightMouseUp(t){var e,i,r,o,s;const a=this.getHoverRectID(t),h=this.rectList.find(n=>n.id===a);if(this.selectedRectTextAttribute="",this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else{if(((e=this.dragInfo)==null?void 0:e.dragStartCoord)&&turf.distance((i=this.dragInfo)==null?void 0:i.dragStartCoord,this.getCoordinateUnderZoom(t))>3&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(a,t.ctrlKey),h&&((r=this.selectedIDs)==null?void 0:r.length)===1&&(this.selectedRectTextAttribute=this.getSelectedRectTextAttribute(a),this.setDefaultAttribute(h.attribute)),this.hoverRectID="",(h==null?void 0:h.label)&&this.hasMarkerConfig){const n=CommonToolUtils.getCurrentMarkerIndex(h.label,this.config.markerList);n>=0&&(this.setMarkerIndex(n),this.emit("markIndexChange"))}((o=this.config)==null?void 0:o.secondaryAttributeConfigurable)&&((s=this.config)==null?void 0:s.subAttributeList)&&this.setDefaultSubAttribute()}return this.render(),h}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}updateDragResult(){this.emit("updateDragResult",__spreadValues({},this.selectedRect))}setEnableAddRect(t){this.enableAddRect=t}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===annotation.EDragStatus.Move){this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.history.pushHistory(this.rectList),this.emit("updateResult"),this.updateDragResult();return}if(t.button===2&&t.shiftKey===!0){this.shiftRightMouseUp(t);return}if(t.button===2){this.rightMouseUp(t);return}const e=CommonToolUtils.getSourceID(this.basicResult);if(this.drawingRect){this.enableAddRect?this.addDrawingRectToRectList():(this.clearDrawingStatus(),this.render());return}if(t.ctrlKey===!0&&t.button===0&&this.hoverRectID){this.setRectValidAndRender(this.hoverRectID);return}this.enableAddRect&&(this.createNewDrawingRect(t,e),this.render())}onRightDblClick(t){super.onRightDblClick(t);const e=this.getHoverRectID(t);this.selection.isIdSelected(e)&&this.deleteSelectedRect(t)}deleteSelectedRect(t){this.selectedRects.forEach(e=>{this.deleteRect(e.id)})}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1||this.selection.triggerKeyboardEvent(t,this.setRectList.bind(this)))return;const{keyCode:e}=t;switch(e){case keyCode.Ctrl:this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case keyCode.F:this.selectedIDs.length>0&&this.setRectValidAndRender(this.selectedRectID);break;case keyCode.Z:this.setIsHidden(!this.isHidden),this.render();break;case keyCode.Delete:this.deleteSelectedRect(t);break;case keyCode.Tab:{if(t.preventDefault(),this.drawingRect)return;let i=annotation.ESortDirection.ascend;t.shiftKey&&(i=annotation.ESortDirection.descend);const[r,o]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let s=[...r];o&&(s=[...s,...o]);const a=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom);s=s.filter(n=>CanvasUtils.inViewPort({x:n.x,y:n.y},a));const h=CommonToolUtils.getNextSelectedRectID(s,i,this.selectedRectID);h&&(this.setSelectedRectID(h.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(h.attribute));break}default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}return!0}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case keyCode.Ctrl:this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let i,r;this.drawingRect&&this.firstClickCoord&&(i=RectUtils.getRectUnderZoom(this.drawingRect,1/e),r=AxisUtils.default.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),i&&r&&(this.drawingRect=RectUtils.getRectUnderZoom(i,this.zoom),this.firstClickCoord=AxisUtils.default.changePointByZoom(r,this.zoom)),this.render()}getCurrentSelectedData(){const{selectedRect:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:t.width*this.zoom*.6,textAttribute:t.textAttribute,color:i}}getRenderStyle(t){const e=this.customRenderStyle&&this.customRenderStyle(t);if(e)return e;const i=this.getColor(t.attribute);let r,o;return t.valid===!1?(r=i==null?void 0:i.invalid.stroke,o=i==null?void 0:i.invalid.fill):(r=i==null?void 0:i.valid.stroke,o=i==null?void 0:i.valid.fill),{strokeColor:r,fillColor:o,textColor:r,toolColor:i}}renderTextAttribute(){var t;const{selectedRect:e}=this;if(!this.ctx||this.config.textConfigurable!==!0||!e)return;const{x:i,y:r,width:o,height:s,attribute:a,valid:h}=e,n=o*this.zoom*.6,d=AxisUtils.default.getOffsetCoordinate({x:i,y:r+s},this.currentPos,this.zoom),c=this.getColor(a),l=h?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke,u=4;this._textAttributeInstance||(this._textAttributeInstance=new textAttributeClass({width:n,container:this.container,icon:this.getTextIconSvg(a),color:l,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedRectTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${e.textAttribute}`,{left:d.x,top:d.y+u,color:l,width:n})}renderSelectedRect(t){if(!this.ctx||!t)return;const{ctx:e}=this;let i=10;const r=RectUtils.getRectPointList(t),o=r.length,s=this.getColor(t.attribute);r.forEach((a,h)=>{var n,d;if(e.save(),e.moveTo(a.x,a.y),e.beginPath(),this.hoverRectPointIndex===h?i=scope+6:i=scope,t.valid===!1?(e.strokeStyle=s==null?void 0:s.invalid.stroke,e.fillStyle=s==null?void 0:s.invalid.stroke):(e.strokeStyle=s==null?void 0:s.valid.stroke,e.fillStyle=s==null?void 0:s.valid.stroke),e.arc(a.x*this.zoom+this.currentPos.x,a.y*this.zoom+this.currentPos.y,i,0,2*Math.PI),e.fill(),this.hoverRectEdgeIndex===h){e.beginPath(),e.lineWidth=10;const c=this.getColor(t.attribute),l=t.valid===!1?(n=c==null?void 0:c.invalid)==null?void 0:n.stroke:(d=c==null?void 0:c.valid)==null?void 0:d.stroke;e.strokeStyle=l,e.moveTo(r[h].x*this.zoom+this.currentPos.x,r[h].y*this.zoom+this.currentPos.y),e.lineTo(r[(h+1)%o].x*this.zoom+this.currentPos.x,r[(h+1)%o].y*this.zoom+this.currentPos.y),e.stroke()}e.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,i=!1,r=!1){var o,s,a,h,n,d;if(this.ctx&&t){const{ctx:c,style:l}=this,{hiddenText:u=!1}=l;c.save();const{strokeColor:g,fillColor:R,textColor:b}=this.getRenderStyle(t);c.font="lighter 14px Arial";let x="";((o=this.config)==null?void 0:o.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(x=`${t.order}`),t.label&&this.hasMarkerConfig&&(x=`${CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${MarkerUtils.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(x=`${x} ${AttributeUtils.default.getAttributeShowText(t.attribute,(s=this.config)==null?void 0:s.attributeList)}`,(t==null?void 0:t.subAttribute)&&((a=this.config)==null?void 0:a.secondaryAttributeConfigurable)&&((h=this.config)==null?void 0:h.subAttributeList)&&TagUtils.getTagNameList(t.subAttribute,this.config.subAttributeList).forEach(I=>{x+=`
|
|
2
|
+
${I.keyName}: ${I.value.join("\u3001")}`}));const v=AxisUtils.default.changeRectByZoom(t,i?e:this.zoom,this.currentPos);u||DrawUtils.drawText(this.canvas,{x:v.x,y:v.y-6},x,__spreadProps(__spreadValues({color:g,font:"normal normal 900 14px SourceHanSansCN-Regular"},annotation.DEFAULT_TEXT_SHADOW),{textMaxWidth:300})),this.highlightVisible&&(t==null?void 0:t.isHighlight)&&DrawUtils.drawHighlightFlag({canvas:this.canvas,color:g,position:{x:v.x-5,y:v.y-16}});const D=(d=(n=this.style)==null?void 0:n.width)!=null?d:2,S=this.config.textConfigurable&&this.config.isHighlightSameTextAttribute&&this.selectedRectTextAttribute!==""&&t.textAttribute===this.selectedRectTextAttribute;(t.id===this.hoverRectID||S||t.id===this.selectedRectID||this.isMultiMoveMode||r)&&DrawUtils.drawRectWithFill(this.canvas,v,{color:R}),DrawUtils.drawRect(this.canvas,v,{color:g,thickness:D,hiddenText:!0,lineDash:t.lineDash}),c.restore();let m=`${Math.round(t.width)} * ${Math.round(t.height)}`;i===!0&&(m=`${Math.round(t.width/this.zoom)} * ${Math.round(v.height/this.zoom)}`);const y=m.length*7;if(u||DrawUtils.drawText(this.canvas,{x:v.x+v.width-y,y:v.y+v.height+15},m,__spreadValues({color:b,font:"normal normal 600 14px Arial"},annotation.DEFAULT_TEXT_SHADOW)),!u&&t.textAttribute&&t.id!==this.selectedRectID){const w=0,I=Math.max(20,v.width-y);DrawUtils.drawText(this.canvas,{x:v.x,y:v.y+v.height+20+w},t.textAttribute,__spreadValues({color:b,font:"italic normal 900 14px Arial",textMaxWidth:I},annotation.DEFAULT_TEXT_SHADOW))}}}renderStaticRect(){var t;if(!(((t=this.rectList)==null?void 0:t.length)>0&&JSON.stringify(this.rectList)))return;const{renderEnhance:e={}}=this,[i,r]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs,this.highlightVisible);this.isHidden||i==null||i.forEach(o=>{this.renderDrawingRect(o),e.staticRender&&e.staticRender(this.canvas,AxisUtils.default.changeRectByZoom(o,this.zoom,this.currentPos),this.getRenderStyle(o))}),r&&r.forEach(o=>{this.renderDrawingRect(o),this.renderSelectedRect(o),e.selectedRender&&e.selectedRender(this.canvas,AxisUtils.default.changeRectByZoom(o,this.zoom,this.currentPos),this.getRenderStyle(o))}),this.renderPointCloud2DHighlight()}renderCreatingRect(){if(!this.drawingRect)return;const{renderEnhance:t={}}=this;this.renderDrawingRect(this.drawingRect,1,!0),t.creatingRender&&t.creatingRender(this.canvas,AxisUtils.default.changeRectByZoom(this.drawingRect,1,this.currentPos),this.getRenderStyle(this.drawingRect))}renderRect(){this.renderStaticRect(),this.renderCreatingRect()}render(){!this.ctx||(super.render(),this.renderRect(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}setDefaultAttribute(t){const e=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",e!==t&&(this.changeStyle(t),this.emit("changeAttributeSidebar"),this.selectedRects&&(this.setRectList(this.rectList.map(i=>this.selection.isIdSelected(i.id)?__spreadProps(__spreadValues({},i),{attribute:this.defaultAttribute}):i),!0),this.history.pushHistory(this.rectList),this.render()),this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{attribute:this.defaultAttribute}),this.render()),this._textAttributeInstance)){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))}}setValid(t){super.setValid(t),this.emit("updateResult")}clearDrawingStatus(){this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait}clearActiveStatus(){this.clearDrawingStatus(),this.setSelectedRectID(void 0),this.setOperationMode(tool.EOperationMode.General)}clearResult(t=!0){const e=this.rectList.filter(i=>i.disableDelete===!0);e.length>0&&t&&this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.ClearPartialData,this.lang)),this.setRectList(e,!0),this.setSelectedRectID(void 0)}deleteRect(t){var e;if(!t)return;const i=this.rectList.find(r=>r.id===t);if((i==null?void 0:i.disableDelete)===!0){this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.DisableDelete,this.lang));return}this.setRectList(this.rectList.filter(r=>r.id!==t),!0),this.history.pushHistory(this.rectList),this.setSelectedRectID(void 0),(e=this._textAttributeInstance)==null||e.clearTextAttribute(),this.render()}exportData(){const{rectList:t}=this;return[t,this.basicImgInfo]}undo(){const t=this.history.undo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}setHoverRectID(t){this.hoverRectID=t}}exports.RectOperation=RectOperation,exports.default=RectOperation;
|
|
@@ -25,15 +25,7 @@ declare class ScribbleTool extends BasicToolOperation {
|
|
|
25
25
|
get color(): string;
|
|
26
26
|
get penSizeWithZoom(): number;
|
|
27
27
|
get cacheCanvasToDataUrl(): string | undefined;
|
|
28
|
-
getOriginCoordinate: (e: MouseEvent) =>
|
|
29
|
-
x: number;
|
|
30
|
-
y: number;
|
|
31
|
-
specialPoint?: boolean | undefined;
|
|
32
|
-
specialEdge?: boolean | undefined;
|
|
33
|
-
} | {
|
|
34
|
-
x: number;
|
|
35
|
-
y: number;
|
|
36
|
-
};
|
|
28
|
+
getOriginCoordinate: (e: MouseEvent) => IPoint;
|
|
37
29
|
setPenSize(size: number): void;
|
|
38
30
|
initCacheCanvas(imgNode?: HTMLImageElement): void;
|
|
39
31
|
updateCacheCanvasSize(imgNode: HTMLImageElement): void;
|
|
@@ -28,6 +28,7 @@ interface IBasicToolOperationProps {
|
|
|
28
28
|
ratio: number;
|
|
29
29
|
};
|
|
30
30
|
language?: ELang;
|
|
31
|
+
isOffscreenCanvas?: boolean;
|
|
31
32
|
}
|
|
32
33
|
/**
|
|
33
34
|
* 参考显示数据
|
|
@@ -91,10 +92,13 @@ declare class BasicToolOperation extends EventListener {
|
|
|
91
92
|
max: number;
|
|
92
93
|
ratio: number;
|
|
93
94
|
};
|
|
95
|
+
offscreenCanvas: HTMLCanvasElement;
|
|
96
|
+
private isOffscreenCanvas;
|
|
94
97
|
constructor(props: IBasicToolOperationProps);
|
|
95
98
|
onContextmenu(e: MouseEvent): void;
|
|
96
99
|
get ctx(): CanvasRenderingContext2D | null;
|
|
97
100
|
get basicCtx(): CanvasRenderingContext2D | null;
|
|
101
|
+
get offscreenCtx(): CanvasRenderingContext2D | null;
|
|
98
102
|
get rotate(): any;
|
|
99
103
|
get valid(): any;
|
|
100
104
|
get baseIcon(): any;
|
|
@@ -224,13 +228,14 @@ declare class BasicToolOperation extends EventListener {
|
|
|
224
228
|
redo(): void;
|
|
225
229
|
clearCanvas(): void;
|
|
226
230
|
clearBasicCanvas(): void;
|
|
231
|
+
clearOffscreenCanvas(): void;
|
|
227
232
|
/** 事件绑定 */
|
|
228
233
|
eventBinding(): void;
|
|
229
234
|
eventUnbinding(): void;
|
|
230
235
|
clearImgDrag(): void;
|
|
231
236
|
clearCursorLine(): void;
|
|
232
237
|
onMouseDown(e: MouseEvent): void | boolean;
|
|
233
|
-
onMouseMove(e: MouseEvent): boolean | void;
|
|
238
|
+
onMouseMove(e: MouseEvent, isRender?: boolean): boolean | void;
|
|
234
239
|
onMouseUp(e: MouseEvent): boolean | void;
|
|
235
240
|
onMouseLeave(): void;
|
|
236
241
|
onClick(e: MouseEvent): void;
|
|
@@ -46,15 +46,7 @@ declare class PolygonOperation extends BasicToolOperation {
|
|
|
46
46
|
get enableDrag(): boolean;
|
|
47
47
|
get visiblePolygonList(): IPolygonData[];
|
|
48
48
|
get polygonListUnderZoom(): {
|
|
49
|
-
pointList:
|
|
50
|
-
x: number;
|
|
51
|
-
y: number;
|
|
52
|
-
specialPoint?: boolean | undefined;
|
|
53
|
-
specialEdge?: boolean | undefined;
|
|
54
|
-
} | {
|
|
55
|
-
x: number;
|
|
56
|
-
y: number;
|
|
57
|
-
})[];
|
|
49
|
+
pointList: IPoint[];
|
|
58
50
|
sourceID: string;
|
|
59
51
|
id: string;
|
|
60
52
|
valid: boolean;
|
|
@@ -181,6 +173,9 @@ declare class PolygonOperation extends BasicToolOperation {
|
|
|
181
173
|
y: number;
|
|
182
174
|
};
|
|
183
175
|
dragPolygon(e: MouseEvent, selectedPolygon: IPolygonData): IPolygonPoint[] | undefined;
|
|
176
|
+
private lastMouseMoveTime;
|
|
177
|
+
private mouseMoveThrottle;
|
|
178
|
+
private determineTrigger;
|
|
184
179
|
onMouseMove(e: MouseEvent): void;
|
|
185
180
|
/**
|
|
186
181
|
* Emit updateList for views update
|
|
@@ -210,14 +205,14 @@ declare class PolygonOperation extends BasicToolOperation {
|
|
|
210
205
|
renderSelectedPolygons(): void;
|
|
211
206
|
renderSelectedPolygon(polygon: IPolygonData): void;
|
|
212
207
|
renderHoverPolygon(): void;
|
|
213
|
-
renderPolygon(): void;
|
|
208
|
+
renderPolygon(trigger?: string): void;
|
|
214
209
|
/**
|
|
215
210
|
* used in isTwoPointsMode;
|
|
216
211
|
* Effect:Determine the order of the four points, because the orientation is drawn along the line between the starting point and the first point;
|
|
217
212
|
* Orientation Logic: to the first point, adjacent to the two sides take one for orientation, such as side 1, Side 2, if side 1 clockwise rotation 90 degrees can get side 2, then take side 1 for orientation;
|
|
218
213
|
*/
|
|
219
214
|
private createRectByTwoPointsMode;
|
|
220
|
-
render(): void;
|
|
215
|
+
render(trigger?: string): void;
|
|
221
216
|
renderCursorLine(lineColor: string): void;
|
|
222
217
|
/** 撤销 */
|
|
223
218
|
undo(): void;
|
|
@@ -137,11 +137,13 @@ declare class RectOperation extends BasicToolOperation {
|
|
|
137
137
|
*/
|
|
138
138
|
onDragMoveAll(offset: ICoordinate): void;
|
|
139
139
|
onDragMove(coordinate: ICoordinate): void;
|
|
140
|
-
|
|
140
|
+
private lastMouseMoveTime;
|
|
141
|
+
private mouseMoveThrottle;
|
|
142
|
+
onMouseMove(e: MouseEvent): void;
|
|
141
143
|
setHighlightVisible(highlightVisible: boolean): void;
|
|
142
144
|
setAttributeLockList(attributeLockList: string[]): void;
|
|
143
145
|
setBasicResult(basicResult: any): void;
|
|
144
|
-
setRectValidAndRender(id
|
|
146
|
+
setRectValidAndRender(id?: string): void;
|
|
145
147
|
setDefaultSubAttribute: () => void;
|
|
146
148
|
createNewDrawingRect(e: MouseEvent, basicSourceID: string): void;
|
|
147
149
|
/**
|