@labelbee/lb-annotation 1.12.0-alpha.9 → 1.13.0-alpha.0
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/pointCloud/index.js +1 -1
- package/dist/core/toolOperation/pointCloud2dOperation.js +1 -1
- package/dist/core/toolOperation/polygonOperation.js +1 -1
- package/dist/types/constant/tool.d.ts +1 -1
- package/dist/types/core/scheduler.d.ts +1 -1
- package/dist/types/core/toolOperation/ViewOperation.d.ts +1 -1
- package/dist/types/core/toolOperation/pointCloud2dOperation.d.ts +14 -0
- package/dist/types/core/toolOperation/polygonOperation.d.ts +36 -7
- package/dist/types/core/toolOperation/segmentByRect.d.ts +1 -1
- package/dist/types/utils/tool/CommonToolUtils.d.ts +1 -1
- package/dist/utils/ImgUtils.js +1 -1
- package/es/core/pointCloud/index.js +1 -1
- package/es/core/toolOperation/MultipleSelect.js +73 -0
- package/es/core/toolOperation/Selection.js +98 -0
- package/es/core/toolOperation/pointCloud2dOperation.js +1 -1
- package/es/core/toolOperation/polygonOperation.js +1 -1
- package/es/utils/ImgUtils.js +1 -1
- package/package.json +3 -3
- package/es/core/toolOperation/scribbleTool2.js +0 -249
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),highlightWorker$1=require("../../_virtual/highlightWorker.js"),filterBoxWorker=require("../../_virtual/filterBoxWorker.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),PCDLoader=require("./PCDLoader.js"),OrbitControls=require("./OrbitControls.js"),cache=require("./cache.js"),matrix=require("./matrix.js");require("../../constant/tool.js"),require("../../constant/annotation.js"),require("../../utils/MathUtils.js"),require("@turf/turf"),require("../../utils/tool/CommonToolUtils.js"),require("../../utils/tool/LineToolUtils.js"),require("../../utils/tool/DrawUtils.js"),require("../../constant/keyCode.js"),require("../../locales/index.js"),require("../../locales/constants.js"),require("
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),highlightWorker$1=require("../../_virtual/highlightWorker.js"),filterBoxWorker=require("../../_virtual/filterBoxWorker.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),PCDLoader=require("./PCDLoader.js"),OrbitControls=require("./OrbitControls.js"),cache=require("./cache.js"),matrix=require("./matrix.js");require("../../constant/tool.js"),require("../../constant/annotation.js"),require("../../utils/MathUtils.js"),require("@turf/turf"),require("../../utils/tool/CommonToolUtils.js"),require("../../utils/tool/LineToolUtils.js"),require("../../utils/tool/DrawUtils.js"),require("lodash"),require("../../constant/keyCode.js"),require("../../locales/index.js"),require("../../locales/constants.js"),require("../../constant/style.js"),require("../../utils/tool/CanvasUtils.js"),require("../../utils/tool/ZoomUtils.js");function _interopNamespace(d){if(d&&d.__esModule)return d;var t=Object.create(null);return d&&Object.keys(d).forEach(function(e){if(e!=="default"){var r=Object.getOwnPropertyDescriptor(d,e);Object.defineProperty(t,e,r.get?r:{enumerable:!0,get:function(){return d[e]}})}}),t.default=d,Object.freeze(t)}var THREE__namespace=_interopNamespace(THREE),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(d,t,e)=>t in d?__defProp(d,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[t]=e,__spreadValues=(d,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(d,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(d,e,t[e]);return d},__spreadProps=(d,t)=>__defProps(d,__getOwnPropDescs(t)),__async=(d,t,e)=>new Promise((r,n)=>{var s=o=>{try{i(e.next(o))}catch(c){n(c)}},a=o=>{try{i(e.throw(o))}catch(c){n(c)}},i=o=>o.done?r(o.value):Promise.resolve(o.value).then(s,a);i((e=e.apply(d,t)).next())});const DEFAULT_DISTANCE=30,highlightWorker=new highlightWorker$1({type:"module"});class PointCloud{constructor({container:t,noAppend:e,isOrthographicCamera:r,orthographicParams:n,backgroundColor:s="black",config:a}){this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.showDirection=!0,this.AddBoxToSense=(i,o=16777215)=>{var c;const h=(c=i.id)!=null?c:uuid();this.removeObjectByName(h);const{center:l,width:u,height:m,depth:x,rotation:y}=i,p=new THREE__namespace.Group,w=new THREE__namespace.BoxGeometry(u,m,x),g=new THREE__namespace.MeshBasicMaterial({color:"blue"}),f=new THREE__namespace.Mesh(w,g),C=new THREE__namespace.BoxHelper(f,o),P=this.generateBoxArrow(i);p.add(C),p.add(P),p.position.set(l.x,l.y,l.z),p.rotation.set(0,0,y),p.name=h,this.scene.add(p)},this.overridePointShader=i=>{i.vertexShader=`
|
|
2
2
|
attribute float sizes;
|
|
3
3
|
attribute float visibility;
|
|
4
4
|
varying float vVisible;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var 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"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(
|
|
1
|
+
"use strict";var 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"),_=require("lodash"),polygonOperation=require("./polygonOperation.js"),basicToolOperation=require("./basicToolOperation.js");function _interopDefaultLegacy(s){return s&&typeof s=="object"&&"default"in s?s:{default:s}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(s,t,e)=>t in s?__defProp(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,__spreadValues=(s,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(s,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(s,e,t[e]);return s},__spreadProps=(s,t)=>__defProps(s,__getOwnPropDescs(t));class PointCloud2dOperation extends polygonOperation{constructor(t){super(t);this.selectedIDs=[],this.rightMouseUp=l=>{var d;if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}if(l.ctrlKey){this.emit("addSelectedIDs",this.hoverID);return}this.emit("setSelectedIDs",this.hoverID);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=l=>{var d;if(l){const a=this.getPointCloudLineColor(l),u=AxisUtils.default.changePointListByZoom(l.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}),l.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(u)}},this.emitUpdatePolygonByDrag=()=>{if(this.dragInfo){const{originPolygonList:l}=this.dragInfo;if(this.selectedIDs.length>0){const d=[];this.polygonList.forEach(a=>{if(this.selectedIDs.includes(a.id)){const u=l.find(c=>c.id===a.id);u&&d.push({newPolygon:a,originPolygon:u})}}),this.emit("updatePolygonByDrag",d)}}};var e,i,o,n,r,h;this.showDirectionLine=(e=t.showDirectionLine)!=null?e:!0,this.forbidAddNew=(i=t.forbidAddNew)!=null?i:!1,this.pointCloudConfig=(o=CommonToolUtils.jsonParser(t.config))!=null?o:{},this.hideAttributes=[],this.checkMode=(n=t.checkMode)!=null?n:!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.deletePolygon(t)}deletePolygonPoint(t){this.checkMode||super.deletePolygonPoint(t)}setSelectedIDs(t){this.selectedIDs=t,this.selectedIDs.length<2&&this.setSelectedID(this.selectedIDs.length===1?this.selectedIDs[0]:""),this.render()}deleteSelectedID(){super.deleteSelectedID(),this.selectedIDs=[],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 o=___default.default.cloneDeep(this.selectedPolygons),n=[];(i=this.selectedPolygons)==null||i.forEach((r,h)=>{r.pointList=r.pointList.map(l=>{var d,a;const{x:u,y:c}=l;return __spreadProps(__spreadValues({},l),{x:u+((d=t.x)!=null?d:0),y:c+((a=t.y)!=null?a:0)})}),n.push({originPolygon:o[h],newPolygon:r})}),this.emit("updateResult"),this.emit("updatePolygonByDrag",n),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,o,n;if([...this.selectedIDs,this.editPolygonID].includes(e.id))return;const r=this.getPointCloudLineColor(e),h=AxisUtils.default.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);DrawUtils.drawPolygonWithFillAndLine(this.canvas,h,{fillColor:"transparent",strokeColor:r,pointColor:"white",thickness:(o=(i=this.style)==null?void 0:i.width)!=null?o:2,lineCap:"round",isClose:!0,lineType:(n=this.config)==null?void 0:n.lineType}),e.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(h)}))}renderSelectedPolygon(){var t;(t=this.selectedPolygons)==null||t.forEach(e=>{this.renderSingleSelectedPolygon(e)})}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),n=this.currentPolygonListByPattern.map(r=>__spreadProps(__spreadValues({},r),{pointList:AxisUtils.default.changePointListByZoom(r.pointList,this.zoom)}));return PolygonUtils.getHoverPolygonID(i,n,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(o=>{var n,r,h,l;return __spreadProps(__spreadValues({},o),{x:(r=(n=o.pointList[0])==null?void 0:n.x)!=null?r:0,y:(l=(h=o.pointList[0])==null?void 0:h.y)!=null?l: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 o=this.selectedID;t!==o&&o&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute()}setSelectedID(t){this.updateTextAttribute(t),this.selectedID=t,this.render()}addPointInDrawing(t){this.forbidAddNew||super.addPointInDrawing(t)}setCanvasSize(t){var e,i;const o=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(o,o),(i=this.basicCtx)==null||i.scale(o,o),this.initImgPos(),this.renderBasicCanvas(),this.render()}setPolygonValidAndRender(t,e=!1){if(e){super.setPolygonValidAndRender(t);return}this.emit("validUpdate",t)}onDragMove(t){const e=this.polygonList.map(i=>{if(this.selectedIDs.includes(i.id)){const o=this.dragPolygon(t,i);if(!o)return i;const n=__spreadProps(__spreadValues({},i),{pointList:o});return i.isRect===!0&&this.pattern===tool.EPolygonPattern.Normal&&Object.assign(n,{isRect:!1}),n}return i});this.dragInfo.dragPrevCoord=this.getCoordinateUnderZoom(t),this.setPolygonList(e),this.render()}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}}setResultAndSelectedID(t,e){this.setPolygonList(t),this.setSelectedIDs([e])}}module.exports=PointCloud2dOperation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var 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"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(g,t,e)=>t in g?__defProp(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,__spreadValues=(g,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(g,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(g,e,t[e]);return g},__spreadProps=(g,t)=>__defProps(g,__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.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)}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._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}get selectedPolygon(){return PolygonUtils.getPolygonByID(this.polygonList,this.selectedID)}get hoverPolygon(){return this.polygonList.find(t=>t.id===this.hoverID&&t.id!==this.selectedID)}get polygonListUnderZoom(){return this.polygonList.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 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.selectedID);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.selectedID=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()}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.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),l=AxisUtils.default.changePointByZoom(n&&t.altKey===!1&&i?n:o,1/this.zoom);if(this.pattern===tool.EPolygonPattern.Rect&&this.drawingPointList.length===2){const h=MathUtils.default.getRectangleByRightAngle(l,this.drawingPointList);if(this.drawingPointList=h,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(l),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.dragInfo=void 0,this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,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){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.render(),this.emit("selectedChange")}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedID:i}=this;if(i&&(this.selectedPolygon&&(this.selectedPolygon.attribute=t),this.history.pushHistory(this.polygonList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}setPolygonValidAndRender(t){if(!t)return;const e=this.polygonList.map(i=>{var s;if(i.id===t){const o=(s=i==null?void 0:i.valid)!=null?s:!0;return __spreadProps(__spreadValues({},i),{valid:!o})}return i});this.setPolygonList(e),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}const s=CommonToolUtils.getSourceID(this.basicResult),o=[...this.polygonList];if(this.editPolygonID){const r=o.find(n=>n.id===this.editPolygonID);if(!r)return;r.pointList=this.drawingPointList,this.editPolygonID=""}else{const r=uuid(8,62);let n={id:r,sourceID:s,valid:!this.isCtrl,textAttribute:"",pointList:this.drawingPointList,attribute:this.defaultAttribute,order:CommonToolUtils.getMaxOrder(o.filter(l=>CommonToolUtils.isSameSourceID(l.sourceID,s)))+1};if(this.config.textConfigurable){let l="";l=AttributeUtils.default.getTextAttribute(this.polygonList.filter(h=>CommonToolUtils.isSameSourceID(h.sourceID,s)),this.config.textCheckType),n=__spreadProps(__spreadValues({},n),{textAttribute:l})}this.pattern===tool.EPolygonPattern.Rect&&t===!0&&(n=__spreadProps(__spreadValues({},n),{isRect:!0})),o.push(n),i=n,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)}deletePolygon(t){var e;if(!t)return;const i=this.polygonList.find(s=>s.id===t);this.emit("deletedObject",{deletedObject:i,id:t}),this.setPolygonList(this.polygonList.filter(s=>s.id!==t)),this.history.pushHistory(this.polygonList),(e=this._textAttributInstance)==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.selectedID);let s=[...e];i&&(s=[...s,i]);const o=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom),r=s.map(l=>{var h,c,d,a;return __spreadProps(__spreadValues({},l),{x:(c=(h=l.pointList[0])==null?void 0:h.x)!=null?c:0,y:(a=(d=l.pointList[0])==null?void 0:d.y)!=null?a:0})}).filter(l=>CanvasUtils.inViewPort({x:l.x,y:l.y},o)),n=CommonToolUtils.getNextSelectedRectID(r,t,this.selectedID);if(n){this.setSelectedID(n.id);const{selectedPolygon:l}=this;l&&this.setDefaultAttribute(l.attribute)}this.render()}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)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.deletePolygon(this.selectedID),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);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.deletePolygon(e),this.render()}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0))return this.dragMouseDown(t),!0}dragMouseDown(t){const e=this.selectedPolygon;if(!e||t.button!==0||this.getHoverID(t)!==this.selectedID)return;const s=e.pointList,o=this.getCoordinateUnderZoom(t);let r=[0],n=annotation.EDragTarget.Plane;this.dragStatus=annotation.EDragStatus.Start;const l=this.getHoverPointIndex(t),h=this.getHoverEdgeIndex(t);l>-1?(n=annotation.EDragTarget.Point,r=[l]):h>-1&&this.hoverEdgeIndex>-1&&(n=annotation.EDragTarget.Line,r=[h,(h+1)%s.length]),this.dragInfo={dragStartCoord:o,dragTarget:n,initPointList:s,changePointIndex:r,originPolygon:this.selectedPolygon}}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 n=r.shift();if(!n)return;let l="",h=!0;const c=CommonToolUtils.getSourceID(this.basicResult);let d="";o=this.polygonList.map(a=>{var u,f;return a.id===this.selectedID?(l=a.attribute,h=(u=a==null?void 0:a.valid)!=null?u:!0,d=(f=a==null?void 0:a.textAttribute)!=null?f:"",__spreadProps(__spreadValues({},a),{pointList:n})):a}),r.length>0&&r.forEach((a,u)=>{o.push({sourceID:c,id:uuid(8,62),pointList:a,valid:h,order:CommonToolUtils.getMaxOrder(this.currentShowList)+1+u,attribute:l,textAttribute:d})})}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:n,unionList:l}=r;if(l.length===1&&n){const h=this.polygonList.filter(c=>!l.includes(c.id)).map(c=>c.id===this.selectedID?n:c);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(l=>!RectUtils.isInRect(l,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)),r=1e-5;return e<0||i<0||s>this.imgInfo.width+r||o>this.imgInfo.height+r}onDragMove(t){if(!this.dragInfo||!this.selectedID)return;const{selectedPolygon:e}=this;let i=e==null?void 0:e.pointList;if(!i)return;const{initPointList:s,dragStartCoord:o,dragTarget:r,changePointIndex:n}=this.dragInfo,l=this.getCoordinateUnderZoom(t);let h={x:(l.x-o.x)/this.zoom,y:(l.y-o.y)/this.zoom};if(this.pattern===tool.EPolygonPattern.Rect&&(e==null?void 0:e.isRect)===!0&&n&&[annotation.EDragTarget.Line].includes(r)){const d=MathUtils.default.getArrayIndex(n[0]-2,4),a=MathUtils.default.getArrayIndex(n[0]-1,4),u=[s[d],s[a]];h=MathUtils.default.getRectPerpendicularOffset(o,l,u),h={x:h.x/this.zoom,y:h.y/this.zoom}}switch(this.dragStatus=annotation.EDragStatus.Move,r){case annotation.EDragTarget.Plane:i=i.map((d,a)=>__spreadProps(__spreadValues({},d),{x:s[a].x+h.x,y:s[a].y+h.y}));break;case annotation.EDragTarget.Point:case annotation.EDragTarget.Line:i=i.map((d,a)=>n&&n.includes(a)?__spreadProps(__spreadValues({},d),{x:s[a].x+h.x,y:s[a].y+h.y}):d);break}if(this.pattern===tool.EPolygonPattern.Rect&&(e==null?void 0:e.isRect)===!0&&r===annotation.EDragTarget.Point&&n&&(i=MathUtils.default.getPointListFromPointOffset(s,n[0],h)),this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(i))return;const c=this.polygonList.map(d=>{if(d.id===this.selectedID){const a=__spreadProps(__spreadValues({},d),{pointList:i});return d.isRect===!0&&this.pattern===tool.EPolygonPattern.Normal&&Object.assign(a,{isRect:!1}),a}return d});this.setPolygonList(c),this.render()}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;if(this.selectedID&&this.dragInfo){this.onDragMove(t);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())}leftMouseUpdateValid(t){const e=this.getHoverID(t);return this.drawingPointList.length===0&&t.ctrlKey===!0&&e?(this.setPolygonValidAndRender(e),!0):!1}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){const{originPolygon:e}=this.dragInfo;this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.history.pushHistory(this.polygonList),this.emit("updateResult"),this.emit("updatePolygonByDrag",{newPolygon:this.selectedPolygon,originPolygon:e});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.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait)}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._textAttributInstance&&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:n,y:l}=i[i.length-1],h=TEXT_MAX_WIDTH,c=AxisUtils.default.getOffsetCoordinate({x:n,y:l},this.currentPos,this.zoom),d=this.getColor(s),a=o?d==null?void 0:d.valid.stroke:d==null?void 0:d.invalid.stroke;this._textAttributInstance||(this._textAttributInstance=new textAttributeClass({width:h,container:this.container,icon:this.getTextIconSvg(s),color:a,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${r}`,{left:c.x,top:c.y,color:a,width:h})}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.polygonList)==null||t.forEach(e=>{var i,s,o,r,n;if([this.selectedID,this.editPolygonID].includes(e.id))return;const{textAttribute:l,attribute:h}=e,c=this.getColor(h),d=StyleUtils.getStrokeAndFill(c,e.valid),a=AxisUtils.default.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);DrawUtils.drawPolygonWithFillAndLine(this.canvas,a,{fillColor:d.fill,strokeColor:d.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:""}`;((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:d.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},l,__spreadValues({color:d.stroke},annotation.DEFAULT_TEXT_OFFSET))}))}renderSelectedPolygon(){var t,e,i;if(this.selectedID){const s=this.selectedPolygon;if(s){const o=this.getColor(s.attribute),r=StyleUtils.getStrokeAndFill(o,s.valid,{isSelected:!0});DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,AxisUtils.default.changePointListByZoom(s.pointList,this.zoom,this.currentPos),{fillColor:r.fill,strokeColor:r.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(t=this.config)==null?void 0:t.lineType});let n=`${(e=AttributeUtils.default.getAttributeShowText(s.attribute,this.config.attributeList))!=null?e:""}`;((i=this.config)==null?void 0:i.isShowOrder)&&(s==null?void 0:s.order)>0&&(n=`${s.order} ${n}`),DrawUtils.drawText(this.canvas,AxisUtils.default.changePointByZoom(s.pointList[0],this.zoom,this.currentPos),n,__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(){var t,e,i,s;this.renderStaticPolygon(),this.renderHoverPolygon(),this.renderSelectedPolygon();const o=this.getColor(this.defaultAttribute),r=StyleUtils.getStrokeAndFill(o,!this.isCtrl);if(((t=this.drawingPointList)==null?void 0:t.length)>0){let n=[...this.drawingPointList],l=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.pattern===tool.EPolygonPattern.Rect&&n.length===2)n=MathUtils.default.getRectangleByRightAngle(l,n);else{if(((e=this.config)==null?void 0:e.edgeAdsorption)&&this.isAlt===!1){const{dropFoot:h}=PolygonUtils.getClosestPoint(l,this.polygonList,(i=this.config)==null?void 0:i.lineType,tool.edgeAdsorptionScope/this.zoom);h&&(l=h)}n.push(l)}DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,AxisUtils.default.changePointListByZoom(n,this.zoom,this.currentPos),{fillColor:r.fill,strokeColor:r.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!1,lineType:this.config.lineType})}if(this.hoverPointIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const l=StyleUtils.getStrokeAndFill(o,n.valid,{isSelected:!0}),h=n==null?void 0:n.pointList[this.hoverPointIndex];if(h){const{x:c,y:d}=AxisUtils.default.changePointByZoom(h,this.zoom,this.currentPos);DrawUtils.drawCircleWithFill(this.canvas,{x:c,y:d},5,{color:l.fill})}}if(this.hoverEdgeIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const l=StyleUtils.getStrokeAndFill(o,n.valid,{isSelected:!0});DrawUtils.drawLineWithPointList(this.canvas,AxisUtils.default.changePointListByZoom(n.pointList,this.zoom,this.currentPos),{color:l.stroke,thickness:10,hoverEdgeIndex:this.hoverEdgeIndex,lineType:(s=this.config)==null?void 0:s.lineType})}}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,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
|
+
"use strict";var lbUtils=require("@labelbee/lb-utils"),MathUtils=require("../../utils/MathUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),_=require("lodash"),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");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)}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._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}get selectedPolygon(){return PolygonUtils.getPolygonByID(this.visiblePolygonList,this.selectedID)}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 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.visiblePolygonList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);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}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()}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.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.pattern===tool.EPolygonPattern.Rect&&this.drawingPointList.length===2){const a=MathUtils.default.getRectangleByRightAngle(r,this.drawingPointList);if(this.drawingPointList=a,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.dragInfo=void 0,this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,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){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.render(),this.emit("selectedChange")}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedID:i}=this;if(i&&(this.selectedPolygon&&(this.selectedPolygon.attribute=t),this.history.pushHistory(this.polygonList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}setPolygonValidAndRender(t){if(!t)return;const e=this.polygonList.map(i=>{var s;if(i.id===t){const o=(s=i==null?void 0:i.valid)!=null?s:!0;return __spreadProps(__spreadValues({},i),{valid:!o})}return i});this.setPolygonList(e),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}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(a=>CommonToolUtils.isSameSourceID(a.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)}deletePolygon(t){var e;if(!t)return;const i=this.polygonList.find(s=>s.id===t);this.emit("deletedObject",{deletedObject:i,id:t}),this.setPolygonList(this.polygonList.filter(s=>s.id!==t)),this.history.pushHistory(this.polygonList),(e=this._textAttributInstance)==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.selectedID);let s=[...e];i&&(s=[...s,i]);const o=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom),l=s.map(r=>{var a,d,g,h;return __spreadProps(__spreadValues({},r),{x:(d=(a=r.pointList[0])==null?void 0:a.x)!=null?d:0,y:(h=(g=r.pointList[0])==null?void 0:g.y)!=null?h: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)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.deletePolygon(this.selectedID),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);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.deletePolygon(e),this.render()}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0))return this.dragMouseDown(t),!0}dragMouseDown(t){const e=this.selectedPolygon;if(!e||t.button!==0||this.getHoverID(t)!==this.selectedID)return;const s=e.pointList,o=this.getCoordinateUnderZoom(t);let l=[0],n=annotation.EDragTarget.Plane;this.dragStatus=annotation.EDragStatus.Start;const r=this.getHoverPointIndex(t),a=this.getHoverEdgeIndex(t);r>-1?(n=annotation.EDragTarget.Point,l=[r]):a>-1&&this.hoverEdgeIndex>-1&&(n=annotation.EDragTarget.Line,l=[a,(a+1)%s.length]),this.dragInfo={dragStartCoord:o,dragTarget:n,initPointList:s,changePointIndex:l,originPolygon:this.selectedPolygon,dragPrevCoord:o,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="",a=!0;const d=CommonToolUtils.getSourceID(this.basicResult);let g="";o=this.polygonList.map(h=>{var u,f;return h.id===this.selectedID?(r=h.attribute,a=(u=h==null?void 0:h.valid)!=null?u:!0,g=(f=h==null?void 0:h.textAttribute)!=null?f:"",__spreadProps(__spreadValues({},h),{pointList:n})):h}),l.length>0&&l.forEach((h,u)=>{o.push({sourceID:d,id:uuid(8,62),pointList:h,valid:a,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(a=>a.id===this.selectedID),o=this.currentShowList.find(a=>a.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 a=this.polygonList.filter(d=>!r.includes(d.id)).map(d=>d.id===this.selectedID?n:d);this.setPolygonList(a),this.history.pushHistory(a),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}getDragOffset(t,e){var i;const s=this.getCoordinateUnderZoom(t),{dragTarget:o,dragPrevCoord:l,changePointIndex:n,initPointList:r,dragStartCoord:a}=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),h=[r[d],r[g]],u=MathUtils.default.getRectPerpendicularOffset(a,s,h);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-a.x)/this.zoom,y:(s.y-a.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,a)=>l&&l.includes(a)?__spreadProps(__spreadValues({},r),{x:s[a].x+n.x,y:s[a].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}onDragMove(t){const e=this.polygonList.map(i=>{if(i.id===this.selectedID){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()}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;if(this.enableDrag){this.onDragMove(t);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())}leftMouseUpdateValid(t){const e=this.getHoverID(t);return this.drawingPointList.length===0&&t.ctrlKey===!0&&e?(this.setPolygonValidAndRender(e),!0):!1}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.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.history.pushHistory(this.polygonList);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.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait)}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._textAttributInstance&&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],a=TEXT_MAX_WIDTH,d=AxisUtils.default.getOffsetCoordinate({x:n,y:r},this.currentPos,this.zoom),g=this.getColor(s),h=o?g==null?void 0:g.valid.stroke:g==null?void 0:g.invalid.stroke;this._textAttributInstance||(this._textAttributInstance=new textAttributeClass({width:a,container:this.container,icon:this.getTextIconSvg(s),color:h,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${l}`,{left:d.x,top:d.y,color:h,width:a})}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:a}=e,d=this.getColor(a),g=StyleUtils.getStrokeAndFill(d,e.valid),h=AxisUtils.default.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);DrawUtils.drawPolygonWithFillAndLine(this.canvas,h,{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(a,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,h[0],u,__spreadValues({color:g.stroke},annotation.DEFAULT_TEXT_OFFSET));const f=h[h.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))}))}renderSelectedPolygon(){var t,e,i;const{selectedPolygon:s}=this;if(s){const o=this.getColor(s.attribute),l=StyleUtils.getStrokeAndFill(o,s.valid,{isSelected:!0});DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,AxisUtils.default.changePointListByZoom(s.pointList,this.zoom,this.currentPos),{fillColor:l.fill,strokeColor:l.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(t=this.config)==null?void 0:t.lineType});let n=`${(e=AttributeUtils.default.getAttributeShowText(s.attribute,this.config.attributeList))!=null?e:""}`;((i=this.config)==null?void 0:i.isShowOrder)&&(s==null?void 0:s.order)>0&&(n=`${s.order} ${n}`),DrawUtils.drawText(this.canvas,AxisUtils.default.changePointByZoom(s.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.renderSelectedPolygon();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.pattern===tool.EPolygonPattern.Rect&&n.length===2)n=MathUtils.default.getRectangleByRightAngle(r,n);else{if(((e=this.config)==null?void 0:e.edgeAdsorption)&&this.isAlt===!1){const{dropFoot:a}=PolygonUtils.getClosestPoint(r,this.polygonList,(i=this.config)==null?void 0:i.lineType,tool.edgeAdsorptionScope/this.zoom);a&&(r=a)}n.push(r)}DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,AxisUtils.default.changePointListByZoom(n,this.zoom,this.currentPos),{fillColor:l.fill,strokeColor:l.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!1,lineType:this.config.lineType})}if(this.hoverPointIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const r=StyleUtils.getStrokeAndFill(o,n.valid,{isSelected:!0}),a=n==null?void 0:n.pointList[this.hoverPointIndex];if(a){const{x:d,y:g}=AxisUtils.default.changePointByZoom(a,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})}}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;
|
|
@@ -62,7 +62,7 @@ export declare enum ERectPattern {
|
|
|
62
62
|
'RectBG' = 1,
|
|
63
63
|
'showOrder' = 2
|
|
64
64
|
}
|
|
65
|
-
export type ToolName = EToolName | EVideoToolName | EPointCloudName;
|
|
65
|
+
export declare type ToolName = EToolName | EVideoToolName | EPointCloudName;
|
|
66
66
|
export declare const TOOL_NAME: {
|
|
67
67
|
[a: string]: string;
|
|
68
68
|
};
|
|
@@ -7,7 +7,7 @@ import { EToolName } from '@/constant/tool';
|
|
|
7
7
|
import { RectOperation } from './toolOperation/rectOperation';
|
|
8
8
|
import PolygonOperation from './toolOperation/polygonOperation';
|
|
9
9
|
import SegmentByRect from './toolOperation/segmentByRect';
|
|
10
|
-
export type THybridToolName = EToolName | Array<EToolName>;
|
|
10
|
+
export declare type THybridToolName = EToolName | Array<EToolName>;
|
|
11
11
|
interface IToolSchedulerOperation {
|
|
12
12
|
}
|
|
13
13
|
interface IToolSchedulerProps {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { TAnnotationViewData, TAnnotationViewLine, TAnnotationViewPolygon, TAnnotationViewBox3d, IBasicStyle } from '@labelbee/lb-utils';
|
|
5
5
|
import { BasicToolOperation, IBasicToolOperationProps } from './basicToolOperation';
|
|
6
|
-
type IViewOperationProps = {
|
|
6
|
+
declare type IViewOperationProps = {
|
|
7
7
|
style: IBasicStyle;
|
|
8
8
|
annotations: TAnnotationViewData[];
|
|
9
9
|
} & IBasicToolOperationProps;
|
|
@@ -16,12 +16,16 @@ interface IPointCloud2dOperationProps {
|
|
|
16
16
|
}
|
|
17
17
|
declare class PointCloud2dOperation extends PolygonOperation {
|
|
18
18
|
showDirectionLine: boolean;
|
|
19
|
+
hideAttributes: string[];
|
|
19
20
|
forbidAddNew: boolean;
|
|
20
21
|
pointCloudConfig: IPointCloudConfig;
|
|
21
22
|
private checkMode;
|
|
22
23
|
private selectedIDs;
|
|
23
24
|
constructor(props: IPolygonOperationProps & IPointCloud2dOperationProps);
|
|
24
25
|
get getSelectedIDs(): string[];
|
|
26
|
+
get enableDrag(): boolean;
|
|
27
|
+
get visiblePolygonList(): IPolygonData[];
|
|
28
|
+
setHiddenAttributes(hideAttributes: string[]): void;
|
|
25
29
|
setConfig(config: string): void;
|
|
26
30
|
dragMouseDown(e: MouseEvent): void;
|
|
27
31
|
deletePolygon(id?: string): void;
|
|
@@ -38,6 +42,7 @@ declare class PointCloud2dOperation extends PolygonOperation {
|
|
|
38
42
|
*/
|
|
39
43
|
rightMouseUp: (e: MouseEvent) => void;
|
|
40
44
|
get selectedPolygons(): IPolygonData[] | undefined;
|
|
45
|
+
updateSelectedPolygonsPoints(offset: Partial<ICoordinate>): void;
|
|
41
46
|
/**
|
|
42
47
|
* keydown event
|
|
43
48
|
* @override
|
|
@@ -79,6 +84,7 @@ declare class PointCloud2dOperation extends PolygonOperation {
|
|
|
79
84
|
* @override
|
|
80
85
|
*/
|
|
81
86
|
setSelectedIdAfterAddingDrawing(newID: string): void;
|
|
87
|
+
updateTextAttribute(newID?: string): void;
|
|
82
88
|
/**
|
|
83
89
|
* Overwrite and prevent selectedChange emit
|
|
84
90
|
* @override
|
|
@@ -100,6 +106,14 @@ declare class PointCloud2dOperation extends PolygonOperation {
|
|
|
100
106
|
* @returns
|
|
101
107
|
*/
|
|
102
108
|
setPolygonValidAndRender(id: string, isUpdate?: boolean): void;
|
|
109
|
+
onDragMove(e: MouseEvent): void;
|
|
110
|
+
onMouseDown(e: MouseEvent): true | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* Just Update Data. Not Clear Status
|
|
113
|
+
* @param polygonList
|
|
114
|
+
*/
|
|
115
|
+
setResultAndSelectedID(polygonList: IPolygonData[], selectedID: string): void;
|
|
116
|
+
emitUpdatePolygonByDrag: () => void;
|
|
103
117
|
}
|
|
104
118
|
export default PointCloud2dOperation;
|
|
105
119
|
export { IPointCloud2dOperationProps };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ERotateDirection, ESortDirection } from '../../constant/annotation';
|
|
1
|
+
import { EDragTarget, ERotateDirection, ESortDirection } from '../../constant/annotation';
|
|
2
2
|
import { EPolygonPattern } from '../../constant/tool';
|
|
3
3
|
import { IPolygonConfig, IPolygonData, IPolygonPoint } from '../../types/tool/polygon';
|
|
4
4
|
import { BasicToolOperation, IBasicToolOperationProps } from './basicToolOperation';
|
|
@@ -16,7 +16,15 @@ declare class PolygonOperation extends BasicToolOperation {
|
|
|
16
16
|
editPolygonID?: string;
|
|
17
17
|
pattern: EPolygonPattern;
|
|
18
18
|
isCombined: boolean;
|
|
19
|
-
|
|
19
|
+
dragInfo?: {
|
|
20
|
+
dragStartCoord: ICoordinate;
|
|
21
|
+
initPointList: IPolygonPoint[];
|
|
22
|
+
changePointIndex?: number[];
|
|
23
|
+
dragTarget: EDragTarget;
|
|
24
|
+
originPolygon?: IPolygonData;
|
|
25
|
+
dragPrevCoord: ICoordinate;
|
|
26
|
+
originPolygonList: IPolygonData[];
|
|
27
|
+
};
|
|
20
28
|
private drawingHistory;
|
|
21
29
|
isCtrl: boolean;
|
|
22
30
|
isAlt: boolean;
|
|
@@ -28,6 +36,8 @@ declare class PolygonOperation extends BasicToolOperation {
|
|
|
28
36
|
destroy(): void;
|
|
29
37
|
get selectedPolygon(): IPolygonData | undefined;
|
|
30
38
|
get hoverPolygon(): IPolygonData | undefined;
|
|
39
|
+
get enableDrag(): boolean;
|
|
40
|
+
get visiblePolygonList(): IPolygonData[];
|
|
31
41
|
get polygonListUnderZoom(): {
|
|
32
42
|
pointList: ({
|
|
33
43
|
x: number;
|
|
@@ -61,11 +71,6 @@ declare class PolygonOperation extends BasicToolOperation {
|
|
|
61
71
|
* @memberof RectOperation
|
|
62
72
|
*/
|
|
63
73
|
get currentPageResult(): IPolygonData[];
|
|
64
|
-
/**
|
|
65
|
-
* Just Update Data. Not Clear Status
|
|
66
|
-
* @param polygonList
|
|
67
|
-
*/
|
|
68
|
-
setResultAndSelectedID(polygonList: IPolygonData[], selectedID: string): void;
|
|
69
74
|
setResult(polygonList: IPolygonData[]): void;
|
|
70
75
|
/**
|
|
71
76
|
* 外层 sidabr 调用
|
|
@@ -137,8 +142,28 @@ declare class PolygonOperation extends BasicToolOperation {
|
|
|
137
142
|
* @returns
|
|
138
143
|
*/
|
|
139
144
|
isPolygonOutSide(selectedPointList: IPolygonPoint[]): boolean;
|
|
145
|
+
/**
|
|
146
|
+
* According to the mode of dragTarget, get the offset when dragging
|
|
147
|
+
* @param e {MouseEvent}
|
|
148
|
+
* @param selectedPolygon {IPolygonData}
|
|
149
|
+
* @returns
|
|
150
|
+
*/
|
|
151
|
+
getDragOffset(e: MouseEvent, selectedPolygon: IPolygonData): {
|
|
152
|
+
x: number;
|
|
153
|
+
y: number;
|
|
154
|
+
};
|
|
155
|
+
dragPolygon(e: MouseEvent, selectedPolygon: IPolygonData): IPolygonPoint[] | undefined;
|
|
156
|
+
/**
|
|
157
|
+
* Update polygon position while enableDrag is true
|
|
158
|
+
* @param e {MouseEvent}
|
|
159
|
+
*/
|
|
140
160
|
onDragMove(e: MouseEvent): void;
|
|
141
161
|
onMouseMove(e: MouseEvent): void;
|
|
162
|
+
/**
|
|
163
|
+
* Emit updateList for views update
|
|
164
|
+
* @Emit updateList {UpdatePolygonByDragList}
|
|
165
|
+
*/
|
|
166
|
+
emitUpdatePolygonByDrag: () => void;
|
|
142
167
|
leftMouseUpdateValid(e: MouseEvent): boolean;
|
|
143
168
|
leftMouseUp(e: MouseEvent): void;
|
|
144
169
|
onMouseUp(e: MouseEvent): undefined;
|
|
@@ -158,6 +183,10 @@ declare class PolygonOperation extends BasicToolOperation {
|
|
|
158
183
|
updateSelectedTextAttribute(newTextAttribute?: string): void;
|
|
159
184
|
renderTextAttribute(): void;
|
|
160
185
|
renderStaticPolygon(): void;
|
|
186
|
+
/**
|
|
187
|
+
* Render selected polygon
|
|
188
|
+
* @param selectedPolygon
|
|
189
|
+
*/
|
|
161
190
|
renderSelectedPolygon(): void;
|
|
162
191
|
renderHoverPolygon(): void;
|
|
163
192
|
renderPolygon(): void;
|
package/dist/utils/ImgUtils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";class ImgUtils{static load(s){return new Promise((o,
|
|
1
|
+
"use strict";class ImgUtils{static load(s){return new Promise((o,r)=>{const e=new Image;e.crossOrigin="anonymous",s.startsWith("file")?e.src=encodeURI(s):e.src=s,e.onload=()=>{o(e)},e.onerror=()=>{r(e)}})}}module.exports=ImgUtils;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import*as c from"three";import{toolStyleConverter as S,PerspectiveShiftUtils as w,EPerspectiveView as g}from"@labelbee/lb-utils";import V from"../../_virtual/highlightWorker.js";import k from"../../_virtual/filterBoxWorker.js";import{isInPolygon as L}from"../../utils/tool/polygonTool.js";import I from"../../utils/uuid.js";import{PCDLoader as N}from"./PCDLoader.js";import{OrbitControls as D}from"./OrbitControls.js";import{PointCloudCache as F}from"./cache.js";import{getCuboidFromPointCloudBox as z}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,lidar2image,pointCloudLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import"../../constant/tool.js";import"../../constant/annotation.js";import"../../utils/MathUtils.js";import"@turf/turf";import"../../utils/tool/CommonToolUtils.js";import"../../utils/tool/LineToolUtils.js";import"../../utils/tool/DrawUtils.js";import"../../constant/keyCode.js";import"../../locales/index.js";import"../../locales/constants.js";import"
|
|
1
|
+
import*as c from"three";import{toolStyleConverter as S,PerspectiveShiftUtils as w,EPerspectiveView as g}from"@labelbee/lb-utils";import V from"../../_virtual/highlightWorker.js";import k from"../../_virtual/filterBoxWorker.js";import{isInPolygon as L}from"../../utils/tool/polygonTool.js";import I from"../../utils/uuid.js";import{PCDLoader as N}from"./PCDLoader.js";import{OrbitControls as D}from"./OrbitControls.js";import{PointCloudCache as F}from"./cache.js";import{getCuboidFromPointCloudBox as z}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,lidar2image,pointCloudLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import"../../constant/tool.js";import"../../constant/annotation.js";import"../../utils/MathUtils.js";import"@turf/turf";import"../../utils/tool/CommonToolUtils.js";import"../../utils/tool/LineToolUtils.js";import"../../utils/tool/DrawUtils.js";import"lodash";import"../../constant/keyCode.js";import"../../locales/index.js";import"../../locales/constants.js";import"../../constant/style.js";import"../../utils/tool/CanvasUtils.js";import"../../utils/tool/ZoomUtils.js";var E=Object.defineProperty,R=Object.defineProperties,U=Object.getOwnPropertyDescriptors,A=Object.getOwnPropertySymbols,W=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable,j=(u,t,e)=>t in u?E(u,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):u[t]=e,P=(u,t)=>{for(var e in t||(t={}))W.call(t,e)&&j(u,e,t[e]);if(A)for(var e of A(t))H.call(t,e)&&j(u,e,t[e]);return u},M=(u,t)=>R(u,U(t)),B=(u,t,e)=>new Promise((r,n)=>{var s=o=>{try{i(e.next(o))}catch(h){n(h)}},a=o=>{try{i(e.throw(o))}catch(h){n(h)}},i=o=>o.done?r(o.value):Promise.resolve(o.value).then(s,a);i((e=e.apply(u,t)).next())});const Z=30,T=new V({type:"module"});class G{constructor({container:t,noAppend:e,isOrthographicCamera:r,orthographicParams:n,backgroundColor:s="black",config:a}){this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.showDirection=!0,this.AddBoxToSense=(i,o=16777215)=>{var h;const l=(h=i.id)!=null?h:I();this.removeObjectByName(l);const{center:d,width:m,height:y,depth:f,rotation:C}=i,p=new c.Group,b=new c.BoxGeometry(m,y,f),x=new c.MeshBasicMaterial({color:"blue"}),v=new c.Mesh(b,x),O=new c.BoxHelper(v,o),_=this.generateBoxArrow(i);p.add(O),p.add(_),p.position.set(d.x,d.y,d.z),p.rotation.set(0,0,C),p.name=l,this.scene.add(p)},this.overridePointShader=i=>{i.vertexShader=`
|
|
2
2
|
attribute float sizes;
|
|
3
3
|
attribute float visibility;
|
|
4
4
|
varying float vVisible;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import CommonToolUtils from '../../utils/tool/CommonToolUtils.js';
|
|
3
|
+
|
|
4
|
+
class Selection {
|
|
5
|
+
constructor(toolInstance) {
|
|
6
|
+
if (!toolInstance) {
|
|
7
|
+
console.error("MultipleSelect is require an tool instance");
|
|
8
|
+
}
|
|
9
|
+
this._selectedIDs = [];
|
|
10
|
+
this.toolInstance = toolInstance;
|
|
11
|
+
}
|
|
12
|
+
get selectedIDs() {
|
|
13
|
+
return this._selectedIDs;
|
|
14
|
+
}
|
|
15
|
+
set selectedIDs(selectedIDs) {
|
|
16
|
+
this._selectedIDs = selectedIDs;
|
|
17
|
+
this.toolInstance.render();
|
|
18
|
+
}
|
|
19
|
+
get visibleDataList() {
|
|
20
|
+
const {dataList, attributeLockList, basicResult} = this.toolInstance;
|
|
21
|
+
const [showingDataList] = CommonToolUtils.getRenderResultList(dataList, CommonToolUtils.getSourceID(basicResult), attributeLockList);
|
|
22
|
+
return showingDataList;
|
|
23
|
+
}
|
|
24
|
+
get dataList() {
|
|
25
|
+
return this.toolInstance.dataList;
|
|
26
|
+
}
|
|
27
|
+
updateSelectedIDs(selectedID) {
|
|
28
|
+
if (this.selectedIDs.includes(selectedID)) {
|
|
29
|
+
this.selectedIDs = this.selectedIDs.filter((id) => id !== selectedID);
|
|
30
|
+
} else {
|
|
31
|
+
this.selectedIDs = [...this.selectedIDs, selectedID];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
updateSelectedGraphProps(updateList) {
|
|
35
|
+
const updatedDataList = _.cloneDeep(this.dataList).map((i) => {
|
|
36
|
+
const updatedData = updateList.find((s) => s.id === i.id);
|
|
37
|
+
if (updatedData) {
|
|
38
|
+
return _.merge(i, updatedData);
|
|
39
|
+
}
|
|
40
|
+
return i;
|
|
41
|
+
});
|
|
42
|
+
this.setResultAndRender(updatedDataList);
|
|
43
|
+
}
|
|
44
|
+
selectAll() {
|
|
45
|
+
this.selectedIDs = this.visibleDataList.map((i) => i.id);
|
|
46
|
+
this.toolInstance.render();
|
|
47
|
+
}
|
|
48
|
+
toStashDataList() {
|
|
49
|
+
if (this.selectedIDs.length > 0) {
|
|
50
|
+
this.stashDataList = _.cloneDeep(this.dataList.filter((i) => this.selectedIDs.includes(i.id)));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
toUnStashDataList() {
|
|
54
|
+
if (this.stashDataList) {
|
|
55
|
+
const _stashDataList = this.stashDataList;
|
|
56
|
+
this.stashDataList = [];
|
|
57
|
+
return _stashDataList;
|
|
58
|
+
}
|
|
59
|
+
return void 0;
|
|
60
|
+
}
|
|
61
|
+
mergeStashData() {
|
|
62
|
+
const stashList = this.toUnStashDataList();
|
|
63
|
+
const mergedDataList = _(this.dataList).keyBy("id").merge(_.keyBy(stashList, "id")).values().value();
|
|
64
|
+
this.setResultAndRender(mergedDataList);
|
|
65
|
+
}
|
|
66
|
+
setResultAndRender(dataList) {
|
|
67
|
+
}
|
|
68
|
+
isSelectedID(id) {
|
|
69
|
+
return this.selectedIDs.includes(id);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { Selection as default };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import CommonToolUtils from '../../utils/tool/CommonToolUtils.js';
|
|
3
|
+
|
|
4
|
+
class Selection {
|
|
5
|
+
constructor(toolInstance) {
|
|
6
|
+
if (!toolInstance) {
|
|
7
|
+
console.error("MultipleSelect is require a tool instance");
|
|
8
|
+
}
|
|
9
|
+
this._selectedIDs = [];
|
|
10
|
+
this.toolInstance = toolInstance;
|
|
11
|
+
}
|
|
12
|
+
get selectedIDs() {
|
|
13
|
+
return this._selectedIDs;
|
|
14
|
+
}
|
|
15
|
+
get selectedID() {
|
|
16
|
+
return this._selectedIDs.length === 1 ? this._selectedIDs[0] : void 0;
|
|
17
|
+
}
|
|
18
|
+
get visibleDataList() {
|
|
19
|
+
const {dataList, attributeLockList, basicResult} = this.toolInstance;
|
|
20
|
+
const [showingDataList] = CommonToolUtils.getRenderResultList(dataList, CommonToolUtils.getSourceID(basicResult), attributeLockList);
|
|
21
|
+
return showingDataList;
|
|
22
|
+
}
|
|
23
|
+
get dataList() {
|
|
24
|
+
return this.toolInstance.dataList;
|
|
25
|
+
}
|
|
26
|
+
set selectedIDs(selectedIDs) {
|
|
27
|
+
var _a;
|
|
28
|
+
(_a = this.toolInstance._textAttributeInstance) == null ? void 0 : _a.selectedIDsChanged(this.selectedIDs, selectedIDs);
|
|
29
|
+
this._selectedIDs = selectedIDs;
|
|
30
|
+
this.toolInstance.render();
|
|
31
|
+
}
|
|
32
|
+
updateSelectedIDs(selectedID) {
|
|
33
|
+
if (!selectedID) {
|
|
34
|
+
this._selectedIDs = [];
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (this.selectedIDs.includes(selectedID)) {
|
|
38
|
+
this.selectedIDs = this.selectedIDs.filter((id) => id !== selectedID);
|
|
39
|
+
} else {
|
|
40
|
+
this.selectedIDs = [...this.selectedIDs, selectedID];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
setSelectedIDs(id, isAppend = false) {
|
|
44
|
+
if (isAppend) {
|
|
45
|
+
this.updateSelectedIDs(id);
|
|
46
|
+
} else {
|
|
47
|
+
this.selectedIDs = id ? [id] : [];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
selectAll() {
|
|
51
|
+
this.selectedIDs = this.visibleDataList.map((i) => i.id);
|
|
52
|
+
this.toolInstance.render();
|
|
53
|
+
}
|
|
54
|
+
toStashDataList() {
|
|
55
|
+
if (this.selectedIDs.length > 0) {
|
|
56
|
+
this.stashDataList = _.cloneDeep(this.dataList.filter((i) => this.selectedIDs.includes(i.id)));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
toUnStashDataList() {
|
|
60
|
+
if (this.stashDataList) {
|
|
61
|
+
const _stashDataList = this.stashDataList;
|
|
62
|
+
this.stashDataList = void 0;
|
|
63
|
+
return _stashDataList;
|
|
64
|
+
}
|
|
65
|
+
return void 0;
|
|
66
|
+
}
|
|
67
|
+
mergeStashData(setDataList) {
|
|
68
|
+
const stashList = this.toUnStashDataList();
|
|
69
|
+
if (!stashList) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const mergedDataList = _(this.dataList).keyBy("id").merge(_.keyBy(stashList, "id")).values().value();
|
|
73
|
+
setDataList(mergedDataList);
|
|
74
|
+
this.toolInstance.render();
|
|
75
|
+
}
|
|
76
|
+
isIdSelected(id) {
|
|
77
|
+
return this.selectedIDs.includes(id);
|
|
78
|
+
}
|
|
79
|
+
triggerKeyboardEvent(e, setDataList) {
|
|
80
|
+
if (e.ctrlKey) {
|
|
81
|
+
if (e.key === "v") {
|
|
82
|
+
this.mergeStashData(setDataList);
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
if (e.key === "a") {
|
|
86
|
+
this.selectAll();
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
if (e.key === "c") {
|
|
90
|
+
this.toStashDataList();
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export { Selection as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{INVALID_COLOR as
|
|
1
|
+
import{INVALID_COLOR as I,toolStyleConverter as b}from"@labelbee/lb-utils";import{ESortDirection as C,EDragTarget as _}from"../../constant/annotation.js";import{EPolygonPattern as P}from"../../constant/tool.js";import y from"../../utils/tool/AxisUtils.js";import p from"../../utils/tool/CommonToolUtils.js";import D from"../../utils/tool/DrawUtils.js";import m from"../../utils/tool/PolygonUtils.js";import{polygonConfig as w}from"../../constant/defaultConfig.js";import S from"lodash";import A from"./polygonOperation.js";import{BasicToolOperation as x}from"./basicToolOperation.js";var O=Object.defineProperty,R=Object.defineProperties,j=Object.getOwnPropertyDescriptors,L=Object.getOwnPropertySymbols,T=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable,v=(a,t,e)=>t in a?O(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e,u=(a,t)=>{for(var e in t||(t={}))T.call(t,e)&&v(a,e,t[e]);if(L)for(var e of L(t))U.call(t,e)&&v(a,e,t[e]);return a},g=(a,t)=>R(a,j(t));class B extends A{constructor(t){super(t);this.selectedIDs=[],this.rightMouseUp=r=>{var d;if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}if(r.ctrlKey){this.emit("addSelectedIDs",this.hoverID);return}this.emit("setSelectedIDs",this.hoverID);const l=(d=this.polygonList.find(c=>c.id===this.hoverID))==null?void 0:d.attribute;l&&l!==this.defaultAttribute&&this.emit("syncAttribute",l)},this.onKeyDown=()=>{},this.onKeyUp=()=>{},this.renderSingleSelectedPolygon=r=>{var d;if(r){const l=this.getPointCloudLineColor(r),c=y.changePointListByZoom(r.pointList,this.zoom,this.currentPos);D.drawSelectedPolygonWithFillAndLine(this.canvas,c,{fillColor:"transparent",strokeColor:l,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(d=this.config)==null?void 0:d.lineType}),r.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(c)}},this.emitUpdatePolygonByDrag=()=>{if(this.dragInfo){const{originPolygonList:r}=this.dragInfo;if(this.selectedIDs.length>0){const d=[];this.polygonList.forEach(l=>{if(this.selectedIDs.includes(l.id)){const c=r.find(f=>f.id===l.id);c&&d.push({newPolygon:l,originPolygon:c})}}),this.emit("updatePolygonByDrag",d)}}};var e,i,o,s,n,h;this.showDirectionLine=(e=t.showDirectionLine)!=null?e:!0,this.forbidAddNew=(i=t.forbidAddNew)!=null?i:!1,this.pointCloudConfig=(o=p.jsonParser(t.config))!=null?o:{},this.hideAttributes=[],this.checkMode=(s=t.checkMode)!=null?s:!1,this.forbidAddNew===!1&&t.checkMode===!0&&(this.forbidAddNew=!0),this.config=g(u({},w),{textConfigurable:!1,attributeConfigurable:!0,attributeList:(h=(n=this.pointCloudConfig)==null?void 0:n.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=p.jsonParser(t);this.pointCloudConfig=i,this.config=g(u({},this.config),{attributeList:(e=i==null?void 0:i.attributeList)!=null?e:[]})}dragMouseDown(t){this.checkMode||super.dragMouseDown(t)}deletePolygon(t){this.checkMode||super.deletePolygon(t)}deletePolygonPoint(t){this.checkMode||super.deletePolygonPoint(t)}setSelectedIDs(t){this.selectedIDs=t,this.selectedIDs.length<2&&this.setSelectedID(this.selectedIDs.length===1?this.selectedIDs[0]:""),this.render()}deleteSelectedID(){super.deleteSelectedID(),this.selectedIDs=[],this.emit("deleteSelectedIDs")}get selectedPolygons(){return m.getPolygonByIDs(this.polygonList,this.selectedIDs)}updateSelectedPolygonsPoints(t){var e,i;if(this.selectedPolygons&&((e=this.selectedPolygons)==null?void 0:e.length)>0){const o=S.cloneDeep(this.selectedPolygons),s=[];(i=this.selectedPolygons)==null||i.forEach((n,h)=>{n.pointList=n.pointList.map(r=>{var d,l;const{x:c,y:f}=r;return g(u({},r),{x:c+((d=t.x)!=null?d:0),y:f+((l=t.y)!=null?l:0)})}),s.push({originPolygon:o[h],newPolygon:n})}),this.emit("updateResult"),this.emit("updatePolygonByDrag",s),this.render(),this.history.pushHistory(this.polygonList)}}getLineColor(){return"rgba(0, 255, 255, 0.5)"}getPointCloudLineColor(t){return t.valid===!1?I:b.getColorFromConfig({attribute:t.attribute},g(u({},this.pointCloudConfig),{attributeConfigurable:!0}),{}).stroke}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.visiblePolygonList)==null||t.forEach(e=>{var i,o,s;if([...this.selectedIDs,this.editPolygonID].includes(e.id))return;const n=this.getPointCloudLineColor(e),h=y.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);D.drawPolygonWithFillAndLine(this.canvas,h,{fillColor:"transparent",strokeColor:n,pointColor:"white",thickness:(o=(i=this.style)==null?void 0:i.width)!=null?o:2,lineCap:"round",isClose:!0,lineType:(s=this.config)==null?void 0:s.lineType}),e.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(h)}))}renderSelectedPolygon(){var t;(t=this.selectedPolygons)==null||t.forEach(e=>{this.renderSingleSelectedPolygon(e)})}renderRectPolygonDirection(t){t.length<2||D.drawLine(this.canvas,t[0],t[1],{color:"white",thickness:3,lineDash:[6]})}get currentPolygonListByPattern(){return this.polygonList.filter(t=>this.pattern===P.Rect?t.isRect===!0:this.pattern===P.Normal?t.isRect!==!0:!0)}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),s=this.currentPolygonListByPattern.map(n=>g(u({},n),{pointList:y.changePointListByZoom(n.pointList,this.zoom)}));return m.getHoverPolygonID(i,s,10,(e=this.config)==null?void 0:e.lineType)}switchToNextPolygon(t=C.ascend){if(this.drawingPointList.length>0)return;const e=this.currentPolygonListByPattern.map(o=>{var s,n,h,r;return g(u({},o),{x:(n=(s=o.pointList[0])==null?void 0:s.x)!=null?n:0,y:(r=(h=o.pointList[0])==null?void 0:h.y)!=null?r:0})}),i=p.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 o=this.selectedID;t!==o&&o&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute()}setSelectedID(t){this.updateTextAttribute(t),this.selectedID=t,this.render()}addPointInDrawing(t){this.forbidAddNew||super.addPointInDrawing(t)}setCanvasSize(t){var e,i;const o=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(o,o),(i=this.basicCtx)==null||i.scale(o,o),this.initImgPos(),this.renderBasicCanvas(),this.render()}setPolygonValidAndRender(t,e=!1){if(e){super.setPolygonValidAndRender(t);return}this.emit("validUpdate",t)}onDragMove(t){const e=this.polygonList.map(i=>{if(this.selectedIDs.includes(i.id)){const o=this.dragPolygon(t,i);if(!o)return i;const s=g(u({},i),{pointList:o});return i.isRect===!0&&this.pattern===P.Normal&&Object.assign(s,{isRect:!1}),s}return i});this.dragInfo.dragPrevCoord=this.getCoordinateUnderZoom(t),this.setPolygonList(e),this.render()}onMouseDown(t){if(x.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:_.Plane,initPointList:[],changePointIndex:[0],originPolygon:this.selectedPolygon,dragPrevCoord:e,originPolygonList:this.polygonList}}setResultAndSelectedID(t,e){this.setPolygonList(t),this.setSelectedIDs([e])}}export{B as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i18n as _}from"@labelbee/lb-utils";import D from"../../utils/MathUtils.js";import z from"../../utils/tool/RectUtils.js";import{ERotateDirection as N,EDragStatus as x,ESortDirection as U,EDragTarget as b,TEXT_ATTRIBUTE_OFFSET as E,DEFAULT_TEXT_OFFSET as k}from"../../constant/annotation.js";import p from"../../constant/keyCode.js";import{EPolygonPattern as w,edgeAdsorptionScope as R,ELineTypes as H,EToolName as O}from"../../constant/tool.js";import C from"../../locales/index.js";import{EMessage as S}from"../../locales/constants.js";import W from"../../utils/ActionsHistory.js";import v from"../../utils/tool/AttributeUtils.js";import c from"../../utils/tool/AxisUtils.js";import M from"../../utils/tool/CanvasUtils.js";import u from"../../utils/tool/CommonToolUtils.js";import P from"../../utils/tool/DrawUtils.js";import y from"../../utils/tool/PolygonUtils.js";import A from"../../utils/tool/StyleUtils.js";import B from"../../utils/uuid.js";import{BasicToolOperation as K}from"./basicToolOperation.js";import $ from"./textAttributeClass.js";var V=Object.defineProperty,X=Object.defineProperties,Y=Object.getOwnPropertyDescriptors,Z=Object.getOwnPropertySymbols,q=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable,F=(L,t,e)=>t in L?V(L,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):L[t]=e,f=(L,t)=>{for(var e in t||(t={}))q.call(t,e)&&F(L,e,t[e]);if(Z)for(var e of Z(t))G.call(t,e)&&F(L,e,t[e]);return L},m=(L,t)=>X(L,Y(t));const j=164;class J extends K{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(v.textChange(e,this.selectedID,this.polygonList)),this.emit("selectedChange"),this.render())},this.config=u.jsonParser(t.config),this.drawingPointList=[],this.polygonList=[],this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.drawingHistory=new W,this.isCtrl=!1,this.isAlt=!1,this.isCombined=!1,this.pattern=w.Normal,this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this)}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._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}get selectedPolygon(){return y.getPolygonByID(this.polygonList,this.selectedID)}get hoverPolygon(){return this.polygonList.find(t=>t.id===this.hoverID&&t.id!==this.selectedID)}get polygonListUnderZoom(){return this.polygonList.map(t=>m(f({},t),{pointList:c.changePointListByZoom(t.pointList,this.zoom)}))}get selectedText(){var t;return(t=this.selectedPolygon)==null?void 0:t.textAttribute}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]=u.getRenderResultList(this.polygonList,u.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=e,this.isHidden&&(t=[]),i&&t.push(i),t}get currentPageResult(){const[t]=u.getRenderResultList(this.polygonList,u.getSourceID(this.basicResult),[]);return t}setResultAndSelectedID(t,e){this.setPolygonList(t),e&&(this.selectedID=e),this.render()}setResult(t){this.clearActiveStatus(),this.setPolygonList(t),this.render()}setPolygonDataByID(t,e){return this.polygonList.map(i=>i.id===e?f(f({},i),t):i)}rotatePolygon(t=1,e=N.Clockwise,i=this.selectedID){if(!i)return;const s=y.getPolygonByID(this.polygonList,i);if(!s)return;const o=y.updatePolygonByRotate(e,t,s==null?void 0:s.pointList);this.setPolygonList(this.setPolygonDataByID({pointList:o},i)),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",`${C.getMessagesByLocale(S.UpperLimitErrorNotice,this.lang)}${e}`);return}this.deleteSelectedID();const s=this.getCoordinateUnderZoom(t),o=c.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(c.returnClosePointIndex(o,c.changePointListByZoom(this.drawingPointList,this.zoom))===0){this.addDrawingPointToPolygonList();return}const{dropFoot:n}=y.getClosestPoint(o,this.polygonListUnderZoom,this.config.lineType,R),l=c.changePointByZoom(n&&t.altKey===!1&&i?n:o,1/this.zoom);if(this.pattern===w.Rect&&this.drawingPointList.length===2){const h=D.getRectangleByRightAngle(l,this.drawingPointList);if(this.drawingPointList=h,this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(this.drawingPointList)){this.emit("messageInfo",`${C.getMessagesByLocale(S.ForbiddenCreationOutsideBoundary,this.lang)}`),this.drawingPointList=[];return}this.addDrawingPointToPolygonList(!0);return}this.drawingPointList.push(l),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.dragInfo=void 0,this.dragInfo=void 0,this.dragStatus=x.Wait,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){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.render(),this.emit("selectedChange")}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedID:i}=this;if(i&&(this.selectedPolygon&&(this.selectedPolygon.attribute=t),this.history.pushHistory(this.polygonList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}setPolygonValidAndRender(t){if(!t)return;const e=this.polygonList.map(i=>{var s;if(i.id===t){const o=(s=i==null?void 0:i.valid)!=null?s:!0;return m(f({},i),{valid:!o})}return i});this.setPolygonList(e),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}const s=u.getSourceID(this.basicResult),o=[...this.polygonList];if(this.editPolygonID){const r=o.find(n=>n.id===this.editPolygonID);if(!r)return;r.pointList=this.drawingPointList,this.editPolygonID=""}else{const r=B(8,62);let n={id:r,sourceID:s,valid:!this.isCtrl,textAttribute:"",pointList:this.drawingPointList,attribute:this.defaultAttribute,order:u.getMaxOrder(o.filter(l=>u.isSameSourceID(l.sourceID,s)))+1};if(this.config.textConfigurable){let l="";l=v.getTextAttribute(this.polygonList.filter(h=>u.isSameSourceID(h.sourceID,s)),this.config.textCheckType),n=m(f({},n),{textAttribute:l})}this.pattern===w.Rect&&t===!0&&(n=m(f({},n),{isRect:!0})),o.push(n),i=n,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=>m(f({},o),{pointList:c.changePointListByZoom(o.pointList,this.zoom)}));return y.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=c.changePointListByZoom(i.pointList,this.zoom);return y.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=c.changePointListByZoom(e.pointList,this.zoom);return c.returnClosePointIndex(i,s)}deletePolygon(t){var e;if(!t)return;const i=this.polygonList.find(s=>s.id===t);this.emit("deletedObject",{deletedObject:i,id:t}),this.setPolygonList(this.polygonList.filter(s=>s.id!==t)),this.history.pushHistory(this.polygonList),(e=this._textAttributInstance)==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",`${C.getMessagesByLocale(S.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",`${C.getMessagesByLocale(S.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=U.ascend;t.shiftKey&&(e=U.descend),this.switchToNextPolygon(e)}switchToNextPolygon(t){if(this.drawingPointList.length>0)return;const[e,i]=u.getRenderResultList(this.polygonList,u.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let s=[...e];i&&(s=[...s,i]);const o=M.getViewPort(this.canvas,this.currentPos,this.zoom),r=s.map(l=>{var h,g,a,d;return m(f({},l),{x:(g=(h=l.pointList[0])==null?void 0:h.x)!=null?g:0,y:(d=(a=l.pointList[0])==null?void 0:a.y)!=null?d:0})}).filter(l=>M.inViewPort({x:l.x,y:l.y},o)),n=u.getNextSelectedRectID(r,t,this.selectedID);if(n){this.setSelectedID(n.id);const{selectedPolygon:l}=this;l&&this.setDefaultAttribute(l.attribute)}this.render()}onKeyDown(t){if(!u.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case p.Space:this.spaceKeydown();break;case p.Esc:this.drawingPointList=[],this.editPolygonID="";break;case p.F:this.selectedID&&this.setPolygonValidAndRender(this.selectedID);break;case p.Z:if(t.altKey){this.onCombinedExecute();return}this.setIsHidden(!this.isHidden),this.render();break;case p.Delete:this.deletePolygon(this.selectedID),this.render();break;case p.Ctrl:this.isCtrl=!0;break;case p.Alt:this.isAlt===!1&&(t.preventDefault(),this.isAlt=!0,this.render());break;case p.Tab:{this.onTabKeyDown(t);break}case p.X:t.altKey&&this.segment();break;default:{if(this.config.attributeConfigurable){const i=v.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case p.Ctrl:this.isCtrl=!1;break;case p.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);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",`${C.getMessagesByLocale(S.ForbidAddNewPoint,this.lang)}`),this.clearPolygonDrag();return}const{dropFoot:s}=y.getClosestPoint(e,this.polygonListUnderZoom,this.config.lineType,R);if(!s)return;const{upperLimitPointNum:o}=this.config;if(o&&i.pointList.length>=o){this.emit("messageInfo",`${C.getMessagesByLocale(S.UpperLimitErrorNotice,this.lang)}${o}`),this.clearPolygonDrag();return}i==null||i.pointList.splice(this.hoverEdgeIndex+1,0,c.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.deletePolygon(e),this.render()}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0))return this.dragMouseDown(t),!0}dragMouseDown(t){const e=this.selectedPolygon;if(!e||t.button!==0||this.getHoverID(t)!==this.selectedID)return;const s=e.pointList,o=this.getCoordinateUnderZoom(t);let r=[0],n=b.Plane;this.dragStatus=x.Start;const l=this.getHoverPointIndex(t),h=this.getHoverEdgeIndex(t);l>-1?(n=b.Point,r=[l]):h>-1&&this.hoverEdgeIndex>-1&&(n=b.Line,r=[h,(h+1)%s.length]),this.dragInfo={dragStartCoord:o,dragTarget:n,initPointList:s,changePointIndex:r,originPolygon:this.selectedPolygon}}segment(){var t;if(!this.selectedID||((t=this.config)==null?void 0:t.lineType)!==H.Line)return;const e=y.getPolygonPointList(this.selectedID,this.currentShowList),i=this.currentShowList.filter(r=>r.id!==this.selectedID);if(i.length===0||e.length===0)return;const s=y.getWrapPolygonIndex(e,i);let o=[...this.polygonList];if(s===-1){const r=y.segmentPolygonByPolygon(e,i);if(!r)return;const n=r.shift();if(!n)return;let l="",h=!0;const g=u.getSourceID(this.basicResult);let a="";o=this.polygonList.map(d=>{var I,T;return d.id===this.selectedID?(l=d.attribute,h=(I=d==null?void 0:d.valid)!=null?I:!0,a=(T=d==null?void 0:d.textAttribute)!=null?T:"",m(f({},d),{pointList:n})):d}),r.length>0&&r.forEach((d,I)=>{o.push({sourceID:g,id:B(8,62),pointList:d,valid:h,order:u.getMaxOrder(this.currentShowList)+1+I,attribute:l,textAttribute:a})})}else o[s].pointList=y.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",_.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)!==H.Line){this.emit("messageInfo",_.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=y.combinePolygonWithPolygon(s,o);if(!r)return;const{newPolygon:n,unionList:l}=r;if(l.length===1&&n){const h=this.polygonList.filter(g=>!l.includes(g.id)).map(g=>g.id===this.selectedID?n:g);this.setPolygonList(h),this.history.pushHistory(h),this.render(),this.emit("messageInfo",_.t("CombineSuccess"))}else this.emit("messageInfo",_.t("CombiningFailedNotify"));this.isCombined=!1}isPolygonOutSide(t){if(this.dependToolName&&this.basicCanvas&&this.basicResult){let n=!1;switch(this.dependToolName){case O.Rect:{n=t.filter(l=>!z.isInRect(l,this.basicResult)).length>0;break}case O.Polygon:{n=y.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}=D.calcViewportBoundaries(c.changePointListByZoom(t,this.zoom)),r=1e-5;return e<0||i<0||s>this.imgInfo.width+r||o>this.imgInfo.height+r}onDragMove(t){if(!this.dragInfo||!this.selectedID)return;const{selectedPolygon:e}=this;let i=e==null?void 0:e.pointList;if(!i)return;const{initPointList:s,dragStartCoord:o,dragTarget:r,changePointIndex:n}=this.dragInfo,l=this.getCoordinateUnderZoom(t);let h={x:(l.x-o.x)/this.zoom,y:(l.y-o.y)/this.zoom};if(this.pattern===w.Rect&&(e==null?void 0:e.isRect)===!0&&n&&[b.Line].includes(r)){const a=D.getArrayIndex(n[0]-2,4),d=D.getArrayIndex(n[0]-1,4),I=[s[a],s[d]];h=D.getRectPerpendicularOffset(o,l,I),h={x:h.x/this.zoom,y:h.y/this.zoom}}switch(this.dragStatus=x.Move,r){case b.Plane:i=i.map((a,d)=>m(f({},a),{x:s[d].x+h.x,y:s[d].y+h.y}));break;case b.Point:case b.Line:i=i.map((a,d)=>n&&n.includes(d)?m(f({},a),{x:s[d].x+h.x,y:s[d].y+h.y}):a);break}if(this.pattern===w.Rect&&(e==null?void 0:e.isRect)===!0&&r===b.Point&&n&&(i=D.getPointListFromPointOffset(s,n[0],h)),this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(i))return;const g=this.polygonList.map(a=>{if(a.id===this.selectedID){const d=m(f({},a),{pointList:i});return a.isRect===!0&&this.pattern===w.Normal&&Object.assign(d,{isRect:!1}),d}return a});this.setPolygonList(g),this.render()}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;if(this.selectedID&&this.dragInfo){this.onDragMove(t);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())}leftMouseUpdateValid(t){const e=this.getHoverID(t);return this.drawingPointList.length===0&&t.ctrlKey===!0&&e?(this.setPolygonValidAndRender(e),!0):!1}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===x.Move){const{originPolygon:e}=this.dragInfo;this.dragInfo=void 0,this.dragStatus=x.Wait,this.history.pushHistory(this.polygonList),this.emit("updateResult"),this.emit("updatePolygonByDrag",{newPolygon:this.selectedPolygon,originPolygon:e});return}switch(t.button){case 0:{this.leftMouseUp(t);break}case 2:{this.rightMouseUp(t);break}}this.render()}}dragMouseUp(){this.dragStatus===x.Start&&(this.dragInfo=void 0,this.dragStatus=x.Wait)}exportData(){const{polygonList:t}=this;return[t,this.basicImgInfo]}getTextIconSvg(t=""){return v.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:j,textAttribute:t.textAttribute,color:i}}updateSelectedTextAttribute(t){if(this._textAttributInstance&&t&&this.selectedID){let e=t;v.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",v.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPolygonList(v.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:n,y:l}=i[i.length-1],h=j,g=c.getOffsetCoordinate({x:n,y:l},this.currentPos,this.zoom),a=this.getColor(s),d=o?a==null?void 0:a.valid.stroke:a==null?void 0:a.invalid.stroke;this._textAttributInstance||(this._textAttributInstance=new $({width:h,container:this.container,icon:this.getTextIconSvg(s),color:d,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${r}`,{left:g.x,top:g.y,color:d,width:h})}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.polygonList)==null||t.forEach(e=>{var i,s,o,r,n;if([this.selectedID,this.editPolygonID].includes(e.id))return;const{textAttribute:l,attribute:h}=e,g=this.getColor(h),a=A.getStrokeAndFill(g,e.valid),d=c.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);P.drawPolygonWithFillAndLine(this.canvas,d,{fillColor:a.fill,strokeColor:a.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 I=`${(r=v.getAttributeShowText(h,this.config.attributeList))!=null?r:""}`;((n=this.config)==null?void 0:n.isShowOrder)&&(e==null?void 0:e.order)>0&&(I=`${e.order} ${I}`),P.drawText(this.canvas,d[0],I,f({color:a.stroke},k));const T=d[d.length-1];P.drawText(this.canvas,{x:T.x+E.x,y:T.y+E.y},l,f({color:a.stroke},k))}))}renderSelectedPolygon(){var t,e,i;if(this.selectedID){const s=this.selectedPolygon;if(s){const o=this.getColor(s.attribute),r=A.getStrokeAndFill(o,s.valid,{isSelected:!0});P.drawSelectedPolygonWithFillAndLine(this.canvas,c.changePointListByZoom(s.pointList,this.zoom,this.currentPos),{fillColor:r.fill,strokeColor:r.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(t=this.config)==null?void 0:t.lineType});let n=`${(e=v.getAttributeShowText(s.attribute,this.config.attributeList))!=null?e:""}`;((i=this.config)==null?void 0:i.isShowOrder)&&(s==null?void 0:s.order)>0&&(n=`${s.order} ${n}`),P.drawText(this.canvas,c.changePointByZoom(s.pointList[0],this.zoom,this.currentPos),n,f({color:r.stroke},k)),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=A.getStrokeAndFill(s,!1,{isHover:!0}).fill,P.drawPolygonWithFill(this.canvas,c.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.renderSelectedPolygon();const o=this.getColor(this.defaultAttribute),r=A.getStrokeAndFill(o,!this.isCtrl);if(((t=this.drawingPointList)==null?void 0:t.length)>0){let n=[...this.drawingPointList],l=c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.pattern===w.Rect&&n.length===2)n=D.getRectangleByRightAngle(l,n);else{if(((e=this.config)==null?void 0:e.edgeAdsorption)&&this.isAlt===!1){const{dropFoot:h}=y.getClosestPoint(l,this.polygonList,(i=this.config)==null?void 0:i.lineType,R/this.zoom);h&&(l=h)}n.push(l)}P.drawSelectedPolygonWithFillAndLine(this.canvas,c.changePointListByZoom(n,this.zoom,this.currentPos),{fillColor:r.fill,strokeColor:r.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!1,lineType:this.config.lineType})}if(this.hoverPointIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const l=A.getStrokeAndFill(o,n.valid,{isSelected:!0}),h=n==null?void 0:n.pointList[this.hoverPointIndex];if(h){const{x:g,y:a}=c.changePointByZoom(h,this.zoom,this.currentPos);P.drawCircleWithFill(this.canvas,{x:g,y:a},5,{color:l.fill})}}if(this.hoverEdgeIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const l=A.getStrokeAndFill(o,n.valid,{isSelected:!0});P.drawLineWithPointList(this.canvas,c.changePointListByZoom(n.pointList,this.zoom,this.currentPos),{color:l.stroke,thickness:10,hoverEdgeIndex:this.hoverEdgeIndex,lineType:(s=this.config)==null?void 0:s.lineType})}}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,r=32;P.drawRectWithFill(this.canvas,{x:e+s,y:i-s*4-1,width:o,height:r},{color:"black"}),P.drawText(this.canvas,{x:e,y:i},_.t("ClickAnotherPolygon"),{textAlign:"center",color:"white",offsetX:o/2+s,offsetY:-(r/2+s/2)}),P.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("")}}export{J as default};
|
|
1
|
+
import{i18n as _}from"@labelbee/lb-utils";import D from"../../utils/MathUtils.js";import j from"../../utils/tool/RectUtils.js";import N from"lodash";import{ERotateDirection as W,EDragStatus as x,ESortDirection as U,EDragTarget as v,TEXT_ATTRIBUTE_OFFSET as E,DEFAULT_TEXT_OFFSET as k}from"../../constant/annotation.js";import L from"../../constant/keyCode.js";import{EPolygonPattern as w,edgeAdsorptionScope as R,ELineTypes as O,EToolName as H}from"../../constant/tool.js";import C from"../../locales/index.js";import{EMessage as S}from"../../locales/constants.js";import K from"../../utils/ActionsHistory.js";import b from"../../utils/tool/AttributeUtils.js";import a from"../../utils/tool/AxisUtils.js";import B from"../../utils/tool/CanvasUtils.js";import u from"../../utils/tool/CommonToolUtils.js";import P from"../../utils/tool/DrawUtils.js";import y from"../../utils/tool/PolygonUtils.js";import A from"../../utils/tool/StyleUtils.js";import M from"../../utils/uuid.js";import{BasicToolOperation as $}from"./basicToolOperation.js";import V from"./textAttributeClass.js";var X=Object.defineProperty,Y=Object.defineProperties,q=Object.getOwnPropertyDescriptors,Z=Object.getOwnPropertySymbols,G=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable,F=(I,t,e)=>t in I?X(I,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):I[t]=e,f=(I,t)=>{for(var e in t||(t={}))G.call(t,e)&&F(I,e,t[e]);if(Z)for(var e of Z(t))J.call(t,e)&&F(I,e,t[e]);return I},m=(I,t)=>Y(I,q(t));const z=164;class Q extends ${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(b.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=u.jsonParser(t.config),this.drawingPointList=[],this.polygonList=[],this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.drawingHistory=new K,this.isCtrl=!1,this.isAlt=!1,this.isCombined=!1,this.pattern=w.Normal,this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this)}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._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}get selectedPolygon(){return y.getPolygonByID(this.visiblePolygonList,this.selectedID)}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=>m(f({},t),{pointList:a.changePointListByZoom(t.pointList,this.zoom)}))}get selectedText(){var t;return(t=this.selectedPolygon)==null?void 0:t.textAttribute}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]=u.getRenderResultList(this.visiblePolygonList,u.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=e,this.isHidden&&(t=[]),i&&t.push(i),t}get currentPageResult(){const[t]=u.getRenderResultList(this.polygonList,u.getSourceID(this.basicResult),[]);return t}setResult(t){this.clearActiveStatus(),this.setPolygonList(t),this.render()}setPolygonDataByID(t,e){return this.polygonList.map(i=>i.id===e?f(f({},i),t):i)}rotatePolygon(t=1,e=W.Clockwise,i=this.selectedID){if(!i)return;const s=y.getPolygonByID(this.polygonList,i);if(!s)return;const o=y.updatePolygonByRotate(e,t,s==null?void 0:s.pointList);this.setPolygonList(this.setPolygonDataByID({pointList:o},i)),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",`${C.getMessagesByLocale(S.UpperLimitErrorNotice,this.lang)}${e}`);return}this.deleteSelectedID();const s=this.getCoordinateUnderZoom(t),o=a.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(a.returnClosePointIndex(o,a.changePointListByZoom(this.drawingPointList,this.zoom))===0){this.addDrawingPointToPolygonList();return}const{dropFoot:n}=y.getClosestPoint(o,this.polygonListUnderZoom,this.config.lineType,R),r=a.changePointByZoom(n&&t.altKey===!1&&i?n:o,1/this.zoom);if(this.pattern===w.Rect&&this.drawingPointList.length===2){const h=D.getRectangleByRightAngle(r,this.drawingPointList);if(this.drawingPointList=h,this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(this.drawingPointList)){this.emit("messageInfo",`${C.getMessagesByLocale(S.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.dragInfo=void 0,this.dragInfo=void 0,this.dragStatus=x.Wait,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){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.render(),this.emit("selectedChange")}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedID:i}=this;if(i&&(this.selectedPolygon&&(this.selectedPolygon.attribute=t),this.history.pushHistory(this.polygonList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}setPolygonValidAndRender(t){if(!t)return;const e=this.polygonList.map(i=>{var s;if(i.id===t){const o=(s=i==null?void 0:i.valid)!=null?s:!0;return m(f({},i),{valid:!o})}return i});this.setPolygonList(e),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}const s=u.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=M(8,62);let n={id:l,sourceID:s,valid:!this.isCtrl,textAttribute:"",pointList:this.drawingPointList,attribute:this.defaultAttribute,order:u.getMaxOrder(o.filter(r=>u.isSameSourceID(r.sourceID,s)))+1};if(this.config.textConfigurable){let r="";r=b.getTextAttribute(this.polygonList.filter(h=>u.isSameSourceID(h.sourceID,s)),this.config.textCheckType),n=m(f({},n),{textAttribute:r})}this.pattern===w.Rect&&t===!0&&(n=m(f({},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=>m(f({},o),{pointList:a.changePointListByZoom(o.pointList,this.zoom)}));return y.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=a.changePointListByZoom(i.pointList,this.zoom);return y.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=a.changePointListByZoom(e.pointList,this.zoom);return a.returnClosePointIndex(i,s)}deletePolygon(t){var e;if(!t)return;const i=this.polygonList.find(s=>s.id===t);this.emit("deletedObject",{deletedObject:i,id:t}),this.setPolygonList(this.polygonList.filter(s=>s.id!==t)),this.history.pushHistory(this.polygonList),(e=this._textAttributInstance)==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",`${C.getMessagesByLocale(S.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",`${C.getMessagesByLocale(S.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=U.ascend;t.shiftKey&&(e=U.descend),this.switchToNextPolygon(e)}switchToNextPolygon(t){if(this.drawingPointList.length>0)return;const[e,i]=u.getRenderResultList(this.polygonList,u.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let s=[...e];i&&(s=[...s,i]);const o=B.getViewPort(this.canvas,this.currentPos,this.zoom),l=s.map(r=>{var h,c,g,d;return m(f({},r),{x:(c=(h=r.pointList[0])==null?void 0:h.x)!=null?c:0,y:(d=(g=r.pointList[0])==null?void 0:g.y)!=null?d:0})}).filter(r=>B.inViewPort({x:r.x,y:r.y},o)),n=u.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(!u.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case L.Space:this.spaceKeydown();break;case L.Esc:this.drawingPointList=[],this.editPolygonID="";break;case L.F:this.selectedID&&this.setPolygonValidAndRender(this.selectedID);break;case L.Z:if(t.altKey){this.onCombinedExecute();return}this.setIsHidden(!this.isHidden),this.render();break;case L.Delete:this.deletePolygon(this.selectedID),this.render();break;case L.Ctrl:this.isCtrl=!0;break;case L.Alt:this.isAlt===!1&&(t.preventDefault(),this.isAlt=!0,this.render());break;case L.Tab:{this.onTabKeyDown(t);break}case L.X:t.altKey&&this.segment();break;default:{if(this.config.attributeConfigurable){const i=b.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case L.Ctrl:this.isCtrl=!1;break;case L.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);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",`${C.getMessagesByLocale(S.ForbidAddNewPoint,this.lang)}`),this.clearPolygonDrag();return}const{dropFoot:s}=y.getClosestPoint(e,this.polygonListUnderZoom,this.config.lineType,R);if(!s)return;const{upperLimitPointNum:o}=this.config;if(o&&i.pointList.length>=o){this.emit("messageInfo",`${C.getMessagesByLocale(S.UpperLimitErrorNotice,this.lang)}${o}`),this.clearPolygonDrag();return}i==null||i.pointList.splice(this.hoverEdgeIndex+1,0,a.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.deletePolygon(e),this.render()}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0))return this.dragMouseDown(t),!0}dragMouseDown(t){const e=this.selectedPolygon;if(!e||t.button!==0||this.getHoverID(t)!==this.selectedID)return;const s=e.pointList,o=this.getCoordinateUnderZoom(t);let l=[0],n=v.Plane;this.dragStatus=x.Start;const r=this.getHoverPointIndex(t),h=this.getHoverEdgeIndex(t);r>-1?(n=v.Point,l=[r]):h>-1&&this.hoverEdgeIndex>-1&&(n=v.Line,l=[h,(h+1)%s.length]),this.dragInfo={dragStartCoord:o,dragTarget:n,initPointList:s,changePointIndex:l,originPolygon:this.selectedPolygon,dragPrevCoord:o,originPolygonList:this.polygonList}}segment(){var t;if(!this.selectedID||((t=this.config)==null?void 0:t.lineType)!==O.Line)return;const e=y.getPolygonPointList(this.selectedID,this.currentShowList),i=this.currentShowList.filter(l=>l.id!==this.selectedID);if(i.length===0||e.length===0)return;const s=y.getWrapPolygonIndex(e,i);let o=[...this.polygonList];if(s===-1){const l=y.segmentPolygonByPolygon(e,i);if(!l)return;const n=l.shift();if(!n)return;let r="",h=!0;const c=u.getSourceID(this.basicResult);let g="";o=this.polygonList.map(d=>{var p,T;return d.id===this.selectedID?(r=d.attribute,h=(p=d==null?void 0:d.valid)!=null?p:!0,g=(T=d==null?void 0:d.textAttribute)!=null?T:"",m(f({},d),{pointList:n})):d}),l.length>0&&l.forEach((d,p)=>{o.push({sourceID:c,id:M(8,62),pointList:d,valid:h,order:u.getMaxOrder(this.currentShowList)+1+p,attribute:r,textAttribute:g})})}else o[s].pointList=y.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",_.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)!==O.Line){this.emit("messageInfo",_.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=y.combinePolygonWithPolygon(s,o);if(!l)return;const{newPolygon:n,unionList:r}=l;if(r.length===1&&n){const h=this.polygonList.filter(c=>!r.includes(c.id)).map(c=>c.id===this.selectedID?n:c);this.setPolygonList(h),this.history.pushHistory(h),this.render(),this.emit("messageInfo",_.t("CombineSuccess"))}else this.emit("messageInfo",_.t("CombiningFailedNotify"));this.isCombined=!1}isPolygonOutSide(t){if(this.dependToolName&&this.basicCanvas&&this.basicResult){let n=!1;switch(this.dependToolName){case H.Rect:{n=t.filter(r=>!j.isInRect(r,this.basicResult)).length>0;break}case H.Polygon:{n=y.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}=D.calcViewportBoundaries(a.changePointListByZoom(t,this.zoom)),l=1e-5;return e<0||i<0||s>this.imgInfo.width+l||o>this.imgInfo.height+l}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===w.Rect&&(e==null?void 0:e.isRect)===!0&&n&&[v.Line].includes(o)){const c=D.getArrayIndex(n[0]-2,4),g=D.getArrayIndex(n[0]-1,4),d=[r[c],r[g]],p=D.getRectPerpendicularOffset(h,s,d);return{x:p.x/this.zoom,y:p.y/this.zoom}}return((i=this.dragInfo)==null?void 0:i.dragTarget)===v.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=N.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=x.Move,o){case v.Plane:i=i.map(r=>m(f({},r),{x:r.x+n.x,y:r.y+n.y}));break;case v.Point:case v.Line:i=i.map((r,h)=>l&&l.includes(h)?m(f({},r),{x:s[h].x+n.x,y:s[h].y+n.y}):r);break}if(this.pattern===w.Rect&&(e==null?void 0:e.isRect)===!0&&o===v.Point&&l&&(i=D.getPointListFromPointOffset(s,l[0],n)),!(this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(i)))return i}onDragMove(t){const e=this.polygonList.map(i=>{if(i.id===this.selectedID){const s=this.dragPolygon(t,i);if(!s)return i;const o=m(f({},i),{pointList:s});return i.isRect===!0&&this.pattern===w.Normal&&Object.assign(o,{isRect:!1}),o}return i});this.dragInfo.dragPrevCoord=this.getCoordinateUnderZoom(t),this.setPolygonList(e),this.render()}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;if(this.enableDrag){this.onDragMove(t);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())}leftMouseUpdateValid(t){const e=this.getHoverID(t);return this.drawingPointList.length===0&&t.ctrlKey===!0&&e?(this.setPolygonValidAndRender(e),!0):!1}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===x.Move){this.emit("updateResult"),this.emitUpdatePolygonByDrag(),this.dragInfo=void 0,this.dragStatus=x.Wait,this.history.pushHistory(this.polygonList);return}switch(t.button){case 0:{this.leftMouseUp(t);break}case 2:{this.rightMouseUp(t);break}}this.render()}}dragMouseUp(){this.dragStatus===x.Start&&(this.dragInfo=void 0,this.dragStatus=x.Wait)}exportData(){const{polygonList:t}=this;return[t,this.basicImgInfo]}getTextIconSvg(t=""){return b.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:z,textAttribute:t.textAttribute,color:i}}updateSelectedTextAttribute(t){if(this._textAttributInstance&&t&&this.selectedID){let e=t;b.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",b.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPolygonList(b.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=z,c=a.getOffsetCoordinate({x:n,y:r},this.currentPos,this.zoom),g=this.getColor(s),d=o?g==null?void 0:g.valid.stroke:g==null?void 0:g.invalid.stroke;this._textAttributInstance||(this._textAttributInstance=new V({width:h,container:this.container,icon:this.getTextIconSvg(s),color:d,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${l}`,{left:c.x,top:c.y,color:d,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,c=this.getColor(h),g=A.getStrokeAndFill(c,e.valid),d=a.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);P.drawPolygonWithFillAndLine(this.canvas,d,{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 p=`${(l=b.getAttributeShowText(h,this.config.attributeList))!=null?l:""}`;((n=this.config)==null?void 0:n.isShowOrder)&&(e==null?void 0:e.order)>0&&(p=`${e.order} ${p}`),P.drawText(this.canvas,d[0],p,f({color:g.stroke},k));const T=d[d.length-1];P.drawText(this.canvas,{x:T.x+E.x,y:T.y+E.y},r,f({color:g.stroke},k))}))}renderSelectedPolygon(){var t,e,i;const{selectedPolygon:s}=this;if(s){const o=this.getColor(s.attribute),l=A.getStrokeAndFill(o,s.valid,{isSelected:!0});P.drawSelectedPolygonWithFillAndLine(this.canvas,a.changePointListByZoom(s.pointList,this.zoom,this.currentPos),{fillColor:l.fill,strokeColor:l.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(t=this.config)==null?void 0:t.lineType});let n=`${(e=b.getAttributeShowText(s.attribute,this.config.attributeList))!=null?e:""}`;((i=this.config)==null?void 0:i.isShowOrder)&&(s==null?void 0:s.order)>0&&(n=`${s.order} ${n}`),P.drawText(this.canvas,a.changePointByZoom(s.pointList[0],this.zoom,this.currentPos),n,f({color:l.stroke},k)),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=A.getStrokeAndFill(s,!1,{isHover:!0}).fill,P.drawPolygonWithFill(this.canvas,a.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.renderSelectedPolygon();const o=this.getColor(this.defaultAttribute),l=A.getStrokeAndFill(o,!this.isCtrl);if(((t=this.drawingPointList)==null?void 0:t.length)>0){let n=[...this.drawingPointList],r=a.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.pattern===w.Rect&&n.length===2)n=D.getRectangleByRightAngle(r,n);else{if(((e=this.config)==null?void 0:e.edgeAdsorption)&&this.isAlt===!1){const{dropFoot:h}=y.getClosestPoint(r,this.polygonList,(i=this.config)==null?void 0:i.lineType,R/this.zoom);h&&(r=h)}n.push(r)}P.drawSelectedPolygonWithFillAndLine(this.canvas,a.changePointListByZoom(n,this.zoom,this.currentPos),{fillColor:l.fill,strokeColor:l.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!1,lineType:this.config.lineType})}if(this.hoverPointIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const r=A.getStrokeAndFill(o,n.valid,{isSelected:!0}),h=n==null?void 0:n.pointList[this.hoverPointIndex];if(h){const{x:c,y:g}=a.changePointByZoom(h,this.zoom,this.currentPos);P.drawCircleWithFill(this.canvas,{x:c,y:g},5,{color:r.fill})}}if(this.hoverEdgeIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const r=A.getStrokeAndFill(o,n.valid,{isSelected:!0});P.drawLineWithPointList(this.canvas,a.changePointListByZoom(n.pointList,this.zoom,this.currentPos),{color:r.stroke,thickness:10,hoverEdgeIndex:this.hoverEdgeIndex,lineType:(s=this.config)==null?void 0:s.lineType})}}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;P.drawRectWithFill(this.canvas,{x:e+s,y:i-s*4-1,width:o,height:l},{color:"black"}),P.drawText(this.canvas,{x:e,y:i},_.t("ClickAnotherPolygon"),{textAlign:"center",color:"white",offsetX:o/2+s,offsetY:-(l/2+s/2)}),P.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("")}}export{Q as default};
|
package/es/utils/ImgUtils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class
|
|
1
|
+
class r{static load(o){return new Promise((s,n)=>{const e=new Image;e.crossOrigin="anonymous",o.startsWith("file")?e.src=encodeURI(o):e.src=o,e.onload=()=>{s(e)},e.onerror=()=>{n(e)}})}}export{r as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@labelbee/lb-annotation",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0-alpha.0",
|
|
4
4
|
"description": "Annotation tool collection",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"annotation",
|
|
@@ -92,11 +92,11 @@
|
|
|
92
92
|
"typescript": "^4.2.3"
|
|
93
93
|
},
|
|
94
94
|
"dependencies": {
|
|
95
|
-
"@labelbee/lb-utils": "^1.
|
|
95
|
+
"@labelbee/lb-utils": "^1.6.0-alpha.0",
|
|
96
96
|
"@turf/turf": "5.1.6",
|
|
97
97
|
"color-rgba": "^2.3.0",
|
|
98
98
|
"lodash": "^4.17.20",
|
|
99
99
|
"three": ">=0.141.0"
|
|
100
100
|
},
|
|
101
|
-
"gitHead": "
|
|
101
|
+
"gitHead": "64d6eb967546eab89016dc7dbc4b854bcb115037"
|
|
102
102
|
}
|
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
import { ImgConversionUtils } from '@labelbee/lb-utils';
|
|
2
|
-
import AxisUtils from '../../utils/tool/AxisUtils.js';
|
|
3
|
-
import DrawUtils from '../../utils/tool/DrawUtils.js';
|
|
4
|
-
import { EToolName, EScribblePattern } from '../../constant/tool.js';
|
|
5
|
-
import CommonToolUtils from '../../utils/tool/CommonToolUtils.js';
|
|
6
|
-
import AttributeUtils from '../../utils/tool/AttributeUtils.js';
|
|
7
|
-
import { BasicToolOperation } from './basicToolOperation.js';
|
|
8
|
-
|
|
9
|
-
const DEFAULT_PEN_SIZE = 20;
|
|
10
|
-
const DEFAULT_COLOR = "white";
|
|
11
|
-
class ScribbleTool extends BasicToolOperation {
|
|
12
|
-
constructor(props) {
|
|
13
|
-
super(props);
|
|
14
|
-
this.toolName = EToolName.ScribbleTool;
|
|
15
|
-
this.action = EScribblePattern.Scribble;
|
|
16
|
-
this.getOriginCoordinate = (e) => {
|
|
17
|
-
return AxisUtils.changePointByZoom(this.getCoordinateUnderZoom(e), 1 / this.zoom);
|
|
18
|
-
};
|
|
19
|
-
this.onMouseDown = (e) => {
|
|
20
|
-
if (super.onMouseDown(e) || this.forbidMouseOperation || !this.imgInfo) {
|
|
21
|
-
return void 0;
|
|
22
|
-
}
|
|
23
|
-
this.initCacheCanvas(this.imgNode);
|
|
24
|
-
this.mouseEvents("onMouseDown").call(this, e);
|
|
25
|
-
};
|
|
26
|
-
this.onMouseMove = (e) => {
|
|
27
|
-
if (super.onMouseMove(e) || this.forbidMouseOperation || !this.imgInfo) {
|
|
28
|
-
return void 0;
|
|
29
|
-
}
|
|
30
|
-
this.mouseEvents("onMouseMove").call(this, e);
|
|
31
|
-
};
|
|
32
|
-
this.onMouseUp = (e) => {
|
|
33
|
-
if (super.onMouseUp(e) || this.forbidMouseOperation || !this.imgInfo) {
|
|
34
|
-
return void 0;
|
|
35
|
-
}
|
|
36
|
-
this.mouseEvents("onMouseUp").call(this, e);
|
|
37
|
-
};
|
|
38
|
-
this.mouseEvents = (eventType) => {
|
|
39
|
-
const events = {
|
|
40
|
-
[EScribblePattern.Scribble]: {
|
|
41
|
-
onMouseMove: this.onScribbleMove,
|
|
42
|
-
onMouseUp: this.onScribbleEnd,
|
|
43
|
-
onMouseDown: this.onScribbleStart
|
|
44
|
-
},
|
|
45
|
-
[EScribblePattern.Erase]: {
|
|
46
|
-
onMouseMove: this.onEraseMove,
|
|
47
|
-
onMouseUp: this.onEraseEnd,
|
|
48
|
-
onMouseDown: this.onEraseStart
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
return events[this.action][eventType];
|
|
52
|
-
};
|
|
53
|
-
this.setPattern = (pattern) => {
|
|
54
|
-
this.action = pattern;
|
|
55
|
-
};
|
|
56
|
-
this.penSize = DEFAULT_PEN_SIZE;
|
|
57
|
-
}
|
|
58
|
-
get color() {
|
|
59
|
-
var _a, _b;
|
|
60
|
-
return (_b = (_a = this == null ? void 0 : this.defaultAttributeInfo) == null ? void 0 : _a.color) != null ? _b : DEFAULT_COLOR;
|
|
61
|
-
}
|
|
62
|
-
get penSizeWithZoom() {
|
|
63
|
-
return this.penSize / this.zoom;
|
|
64
|
-
}
|
|
65
|
-
setPenSize(size) {
|
|
66
|
-
this.penSize = size;
|
|
67
|
-
}
|
|
68
|
-
initCacheCanvas(imgNode) {
|
|
69
|
-
if (this.cacheCanvas || !imgNode) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
const {canvas, ctx} = ImgConversionUtils.createCanvas(imgNode);
|
|
73
|
-
this.cacheCanvas = canvas;
|
|
74
|
-
this.cacheContext = ctx;
|
|
75
|
-
}
|
|
76
|
-
updateCacheCanvasSize(imgNode) {
|
|
77
|
-
if (this.cacheCanvas) {
|
|
78
|
-
this.cacheCanvas.width = imgNode.width;
|
|
79
|
-
this.cacheCanvas.height = imgNode.height;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
updateUrl2CacheContext(url) {
|
|
83
|
-
ImgConversionUtils.createImgDom(url).then((img) => {
|
|
84
|
-
if (!this.cacheContext) {
|
|
85
|
-
this.initCacheCanvas(img);
|
|
86
|
-
}
|
|
87
|
-
if (this.cacheContext) {
|
|
88
|
-
this.cacheContext.save();
|
|
89
|
-
this.clearResult();
|
|
90
|
-
this.cacheContext.drawImage(img, 0, 0, img.width, img.height);
|
|
91
|
-
this.cacheContext.restore();
|
|
92
|
-
this.render();
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
setImgNode(imgNode, basicImgInfo) {
|
|
97
|
-
super.setImgNode(imgNode, basicImgInfo);
|
|
98
|
-
if (this.cacheCanvas) {
|
|
99
|
-
this.updateCacheCanvasSize(imgNode);
|
|
100
|
-
} else {
|
|
101
|
-
this.initCacheCanvas(imgNode);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
setResult(data) {
|
|
105
|
-
var _a;
|
|
106
|
-
const {url} = (_a = data == null ? void 0 : data[0]) != null ? _a : {};
|
|
107
|
-
this.history.initRecord([url], !!url);
|
|
108
|
-
this.clearResult();
|
|
109
|
-
if (!url) {
|
|
110
|
-
this.render();
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
this.updateUrl2CacheContext(url);
|
|
114
|
-
}
|
|
115
|
-
onKeyDown(e) {
|
|
116
|
-
if (!CommonToolUtils.hotkeyFilter(e) || super.onKeyDown(e) === false) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
const {keyCode} = e;
|
|
120
|
-
const keyCode2Attribute = AttributeUtils.getAttributeByKeycode(keyCode, this.config.attributeList);
|
|
121
|
-
if (keyCode2Attribute !== void 0) {
|
|
122
|
-
this.setDefaultAttribute(keyCode2Attribute);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
eventBinding() {
|
|
126
|
-
super.eventBinding();
|
|
127
|
-
}
|
|
128
|
-
setDefaultAttribute(attributeValue) {
|
|
129
|
-
const attributeInfo = this.config.attributeList.find((v) => v.value === attributeValue);
|
|
130
|
-
if (attributeInfo) {
|
|
131
|
-
this.defaultAttribute = attributeInfo.value;
|
|
132
|
-
this.defaultAttributeInfo = attributeInfo;
|
|
133
|
-
this.emit("changeAttributeSidebar");
|
|
134
|
-
this.render();
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
clearStatusAfterLeave() {
|
|
138
|
-
this.onScribbleEnd();
|
|
139
|
-
this.startPoint = void 0;
|
|
140
|
-
}
|
|
141
|
-
onMouseLeave() {
|
|
142
|
-
super.onMouseLeave();
|
|
143
|
-
this.clearStatusAfterLeave();
|
|
144
|
-
}
|
|
145
|
-
onScribbleStart(e) {
|
|
146
|
-
if (!this.cacheContext) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
this.cacheContext.save();
|
|
150
|
-
this.cacheContext.beginPath();
|
|
151
|
-
this.cacheContext.strokeStyle = this.color;
|
|
152
|
-
this.cacheContext.lineWidth = this.penSizeWithZoom;
|
|
153
|
-
this.cacheContext.lineCap = "round";
|
|
154
|
-
this.cacheContext.lineJoin = "round";
|
|
155
|
-
const originCoordinate = AxisUtils.changePointByZoom(this.getCoordinateUnderZoom(e), 1 / this.zoom);
|
|
156
|
-
this.cacheContext.moveTo(originCoordinate.x, originCoordinate.y);
|
|
157
|
-
this.startPoint = originCoordinate;
|
|
158
|
-
}
|
|
159
|
-
onScribbleMove(e) {
|
|
160
|
-
if (e.buttons === 1 && this.cacheContext && this.startPoint) {
|
|
161
|
-
const originCoordinate = this.getOriginCoordinate(e);
|
|
162
|
-
this.cacheContext.lineTo(originCoordinate.x, originCoordinate.y);
|
|
163
|
-
this.cacheContext.stroke();
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
onScribbleEnd() {
|
|
167
|
-
var _a, _b, _c;
|
|
168
|
-
if (this.startPoint) {
|
|
169
|
-
(_a = this.cacheContext) == null ? void 0 : _a.closePath();
|
|
170
|
-
(_b = this.cacheContext) == null ? void 0 : _b.restore();
|
|
171
|
-
this.startPoint = void 0;
|
|
172
|
-
this.history.pushHistory((_c = this.cacheCanvas) == null ? void 0 : _c.toDataURL("image/png", 0));
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
eraseArc(e) {
|
|
176
|
-
var _a;
|
|
177
|
-
if (this.cacheContext) {
|
|
178
|
-
const originCoordinate = this.getOriginCoordinate(e);
|
|
179
|
-
this.cacheContext.save();
|
|
180
|
-
this.cacheContext.beginPath();
|
|
181
|
-
this.cacheContext.arc(originCoordinate.x, originCoordinate.y, this.penSizeWithZoom / 2, 0, Math.PI * 2, false);
|
|
182
|
-
this.cacheContext.clip();
|
|
183
|
-
this.cacheContext.clearRect(0, 0, this.cacheContext.canvas.width, this.cacheContext.canvas.height);
|
|
184
|
-
(_a = this.cacheContext) == null ? void 0 : _a.restore();
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
onEraseStart(e) {
|
|
188
|
-
if (!this.cacheContext || e.buttons !== 1) {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
this.eraseArc(e);
|
|
192
|
-
}
|
|
193
|
-
onEraseMove(e) {
|
|
194
|
-
if (!this.cacheContext || e.buttons !== 1) {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
this.eraseArc(e);
|
|
198
|
-
}
|
|
199
|
-
onEraseEnd() {
|
|
200
|
-
}
|
|
201
|
-
exportData() {
|
|
202
|
-
var _a;
|
|
203
|
-
const imgBase64 = (_a = this.cacheCanvas) == null ? void 0 : _a.toDataURL("image/png", 0);
|
|
204
|
-
return [[], this.basicImgInfo, {imgBase64}];
|
|
205
|
-
}
|
|
206
|
-
clearCacheCanvas() {
|
|
207
|
-
var _a;
|
|
208
|
-
(_a = this.cacheContext) == null ? void 0 : _a.clearRect(0, 0, this.cacheContext.canvas.width, this.cacheContext.canvas.height);
|
|
209
|
-
this.render();
|
|
210
|
-
}
|
|
211
|
-
clearResult() {
|
|
212
|
-
this.clearCacheCanvas();
|
|
213
|
-
}
|
|
214
|
-
renderPoint(radius) {
|
|
215
|
-
DrawUtils.drawCircleWithFill(this.canvas, this.coord, radius, {color: this.color});
|
|
216
|
-
}
|
|
217
|
-
render() {
|
|
218
|
-
super.render();
|
|
219
|
-
if (!this.ctx || !this.cacheCanvas) {
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
this.ctx.save();
|
|
223
|
-
this.ctx.globalAlpha = 0.5;
|
|
224
|
-
DrawUtils.drawImg(this.canvas, this.cacheCanvas, {
|
|
225
|
-
zoom: this.zoom,
|
|
226
|
-
currentPos: this.currentPos,
|
|
227
|
-
rotate: this.rotate
|
|
228
|
-
});
|
|
229
|
-
this.ctx.restore();
|
|
230
|
-
if (this.forbidOperation || this.forbidCursorLine) {
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
this.renderPoint(this.penSize / 2);
|
|
234
|
-
}
|
|
235
|
-
undo() {
|
|
236
|
-
const url = this.history.undo();
|
|
237
|
-
if (url && this.cacheCanvas) {
|
|
238
|
-
this.updateUrl2CacheContext(url);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
redo() {
|
|
242
|
-
const url = this.history.redo();
|
|
243
|
-
if (url && this.cacheCanvas) {
|
|
244
|
-
this.updateUrl2CacheContext(url);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
export { ScribbleTool as default };
|