@labelbee/lb-annotation 1.14.0-alpha.0 → 1.14.0-alpha.10
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/constant/defaultConfig.js +1 -1
- package/dist/core/pointCloud/annotation.js +1 -1
- package/dist/core/pointCloud/index.js +2 -2
- package/dist/core/scheduler.js +1 -1
- package/dist/core/toolOperation/LineToolOperation.js +1 -1
- package/dist/core/toolOperation/ViewOperation.js +1 -1
- package/dist/core/toolOperation/cuboidOperation.js +1 -1
- package/dist/core/toolOperation/pointOperation.js +1 -1
- package/dist/core/toolOperation/polygonOperation.js +1 -1
- package/dist/index.js +1 -1
- package/dist/locales/constants.js +1 -1
- package/dist/locales/en_US/message.js +1 -1
- package/dist/locales/zh_CN/message.js +1 -1
- package/dist/types/core/pointCloud/annotation.d.ts +9 -3
- package/dist/types/core/pointCloud/index.d.ts +36 -6
- package/dist/types/core/pointCloud/matrix.d.ts +1 -1
- package/dist/types/core/scheduler.d.ts +17 -1
- package/dist/types/core/toolOperation/LineToolOperation.d.ts +13 -1
- package/dist/types/core/toolOperation/cuboidOperation.d.ts +21 -2
- package/dist/types/core/toolOperation/pointOperation.d.ts +6 -1
- package/dist/types/core/toolOperation/textAttributeClass.d.ts +9 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/locales/constants.d.ts +2 -0
- package/dist/types/utils/tool/CuboidUtils.d.ts +1 -1
- package/dist/types/utils/tool/DrawUtils.d.ts +19 -1
- package/dist/types/utils/tool/LineToolUtils.d.ts +1 -0
- package/dist/utils/tool/AxisUtils.js +1 -1
- package/dist/utils/tool/CuboidUtils.js +1 -1
- package/dist/utils/tool/DrawUtils.js +3 -3
- package/dist/utils/tool/LineToolUtils.js +1 -1
- package/es/constant/defaultConfig.js +1 -1
- package/es/core/pointCloud/annotation.js +1 -1
- package/es/core/pointCloud/index.js +2 -2
- package/es/core/scheduler.js +1 -1
- package/es/core/toolOperation/LineToolOperation.js +1 -1
- package/es/core/toolOperation/ViewOperation.js +1 -1
- package/es/core/toolOperation/cuboidOperation.js +1 -1
- package/es/core/toolOperation/pointOperation.js +1 -1
- package/es/core/toolOperation/polygonOperation.js +1 -1
- package/es/index.js +1 -1
- package/es/locales/constants.js +1 -1
- package/es/locales/en_US/message.js +1 -1
- package/es/locales/zh_CN/message.js +1 -1
- package/es/utils/tool/AttributeUtils.js +1 -1
- package/es/utils/tool/AxisUtils.js +1 -1
- package/es/utils/tool/CuboidUtils.js +1 -1
- package/es/utils/tool/DrawUtils.js +3 -3
- package/es/utils/tool/LineToolUtils.js +1 -1
- package/package.json +7 -6
- package/LICENSE +0 -203
- package/dist/types/core/pointCloud/segmentation.d.ts +0 -0
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +0 -12
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +0 -7
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +0 -11
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +0 -18
- package/es/core/pointCloud/segmentation.js +0 -50
- package/es/core/toolOperation/scribbleTool2.js +0 -249
|
@@ -1 +1 @@
|
|
|
1
|
-
import g from"lodash";import{ELineTypes as D,ELineColor as U,EToolName as w,ETextType as B}from"../../constant/tool.js";import M from"../../utils/ActionsHistory.js";import S from"../../utils/uuid.js";import f from"../../constant/keyCode.js";import L from"../../utils/MathUtils.js";import{BasicToolOperation as V}from"./basicToolOperation.js";import v from"../../utils/tool/LineToolUtils.js";import{createSmoothCurvePointsFromPointList as R,isInPolygon as j,createSmoothCurvePoints as W}from"../../utils/tool/polygonTool.js";import z from"../../utils/tool/CommonToolUtils.js";import N from"../../utils/tool/CanvasUtils.js";import F from"../../utils/tool/DrawUtils.js";import K from"../../utils/tool/StyleUtils.js";import b from"../../utils/tool/AttributeUtils.js";import $ from"./textAttributeClass.js";var J=Object.defineProperty,q=Object.defineProperties,G=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,Y=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable,k=(d,i,t)=>i in d?J(d,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):d[i]=t,T=(d,i)=>{for(var t in i||(i={}))Y.call(i,t)&&k(d,t,i[t]);if(O)for(var t of O(i))Z.call(i,t)&&k(d,t,i[t]);return d},_=(d,i)=>q(d,G(i)),E;(function(d){d[d.Create=0]="Create",d[d.Active=1]="Active",d[d.None=2]="None"})(E||(E={}));const p=16,C={x:0,y:20},m=3,x=5,H=2;class Q extends V{constructor(i){super(i);this.drawActivatedLine=(t,e,n)=>{const s=g.cloneDeep(this.activeLine);if(!s||s.length===0)return;const r=this.isActiveLineValid();let o;const h=this.selectedID?this.lineList.find(l=>l.id===this.selectedID):void 0;h?o=h.order:o=this.nextOrder();const a=this.getLineColorByAttribute({attribute:this.defaultAttribute,valid:!!r});s.map(l=>Object.assign(l,{actual:{x:l.x,y:l.y}},this.coordUtils.getRenderCoord(l))),this.isActive&&this.drawLineLength(s,a),this.updateActiveArea(),this.drawLine(s,t,a,!0,!0),this.drawLineNumber(s[0],o,a,"",this.defaultAttribute,r),t&&this.isCreate&&this.arc(t,m,a),this.cursor&&!this.selectedPoint&&!n&&!this.isShift&&this.arc(this.cursor,x,a)},this.drawHoverPoint=t=>{if(!this.isMousedown&&t&&this.isLineSelected){const e=this.getPointList(this.activeLine),n=this.activeLine.find(r=>v.calcDistance(this.coordUtils.getRenderCoord(r),t)<=x);let s;!n&&this.activeLine&&(s=this.findNearestPoint(e,t)),this.hoverPointID=n?n.id:void 0,this.cursor=n||s==null?void 0:s.point}},this.lineList=[],this.activeLine=[],this.coordsInsideActiveArea=!1,this.hoverLineSegmentIndex=-1,this.isShift=!1,this.isReference=!1,this.drawCurveLine=(t,e,n,s=!0,r=!1,o)=>{const h=R(e,p);t.save(),t.lineCap="round",t.lineJoin="round",t.strokeStyle=n.color,s&&(t.lineWidth=n.lineWidth),r&&v.setReferenceCtx(t),e.forEach(({specialEdge:a},l)=>{const c=h.splice(0,p+1);t.save(),t.beginPath(),o===l&&(t.lineWidth=4),c.forEach(({x:u,y:A},I)=>{const P=I>0?"lineTo":"moveTo";a&&v.setSpecialEdgeStyle(t),t[P](u,A)}),t.stroke(),t.restore()}),t.restore()},this.drawLine=(t,e,n,s=!1,r=!1)=>{const o=e?t.concat(e):t,h={color:n,lineWidth:r?1:this.lineStyle.lineWidth};this.isCurve?v.drawCurveLine(this.ctx,o,h,!s,this.isReference,r?this.hoverLineSegmentIndex:-1):this.drawStraightLine(o,h,r),s&&t.forEach(a=>{var l,c;const u=a.id,A=u&&[this.hoverPointID,(l=this.selectedPoint)==null?void 0:l.id].includes(u)?x:m;this.arc(a,A,n),[this.hoverPointID,(c=this.selectedPoint)==null?void 0:c.id].includes(u)||this.arc(a,H,"white")})},this.drawStraightLine=(t,e,n=!1)=>{const{ctx:s}=this;s&&(s.save(),s.lineCap="round",s.lineJoin="round",s.strokeStyle=e.color,s.lineWidth=e.lineWidth,this.isReference&&v.setReferenceCtx(s),t.forEach((r,o)=>{if(s.beginPath(),o>0){const h=t[o-1];s.save(),(h==null?void 0:h.specialEdge)&&v.setSpecialEdgeStyle(s),n&&this.hoverLineSegmentIndex+1===o&&(s.lineWidth=4),s.moveTo(h.x,h.y),s.lineTo(r.x,r.y),s.stroke(),s.restore()}}),s.restore())},this.drawLines=()=>{try{const t=g.cloneDeep(this.attributeFilteredLines);if(this.isHidden)return;t.forEach(e=>{if(e.id!==this.selectedID&&e.pointList){e.pointList.map(h=>Object.assign(h,{actual:{x:h.x,y:h.y}},this.coordUtils.getRenderCoord(h)));const{order:n,label:s}=e,r=n,o=e&&this.getLineColorByAttribute(e);this.drawLine(e.pointList,void 0,o,!1),this.drawLineNumber(e.pointList[0],r,o,s,e.attribute,e.valid),e.id!==this.textEditingID&&(this.drawLineTextAttribute(e.pointList[1],o,e==null?void 0:e.textAttribute),this.drawLineLength(e.pointList,o))}})}catch(t){console.error(t,"\u7EBF\u6761\u5DE5\u5177\u6570\u636E\u89E3\u6790\u9519\u8BEF"),this.lineList=[],this.clearCanvas()}},this.render=t=>{super.render(),this.drawLines(),this.drawActivatedLine(t,void 0,!0),this.renderTextAttribute(),this.renderCursorLine(this.getLineColor(this.defaultAttribute))},this.moveLineInPolygon=(t,e)=>{var n;if(!Array.isArray(this.activeLine))return!1;((n=this.activeLine)==null?void 0:n.every(r=>this.isInBasicPolygon({x:r.x+t,y:r.y+e})))&&(this.lineDragging=!0,this.moveActiveArea(t,e))},this.moveLineInRectRange=(t,e,n,s)=>{if(this.activeArea===void 0)return;const{top:r,left:o,right:h,bottom:a}=this.activeArea,l=[o,h].map(y=>g.isNumber(y)?y+t:0),c=[r,a].map(y=>g.isNumber(y)?y+e:0),u=o>=0&&h&&L.isInRange(l,n),A=r>=0&&a&&L.isInRange(c,s),I=u?t:0,P=A?e:0;this.lineDragging=!0,this.moveActiveArea(I,P)},this.onRightClick=t=>{if(this.cursor=void 0,this.isCreate){if(this.isLinePointsNotEnough())return;this.stopLineCreating(!0);return}this.setActiveArea(this.getCoordinate(t),!0),this.emit("contextmenu")},this.updateSelectedAttributeAfterHistoryChanged=()=>{if(this.selectedID){const t=this.lineList.find(n=>n.id===this.selectedID),e=t==null?void 0:t.attribute;typeof e=="string"&&(this.defaultAttribute=e,this.updateAttribute(e),this.render())}},this.onLeftClick=t=>{const e=this.getCoordinate(t),{lineDragging:n}=this;if(this.lineDragging=!1,this.isSpaceKey)return;if(this.isNone&&t.ctrlKey){const r=this.findHoverLine(e);r&&this.setInvalidLine(r.id);return}if(this.isLinePointsExceed())return;const s=this.getNextPoint(t,e);if(this.isCreate||this.isNone){this.setCreatStatusAndAddPoint(s);return}if(this.isActive){if(n)return;if(this.isMouseCoordOutsideActiveArea()){this.setNoneStatus(!1),this.setCreatStatusAndAddPoint(s);return}if(t.shiftKey){this.updateLineSegmentSpecial(e);return}if(this.coordsInsideActiveArea&&t.ctrlKey){this.setInvalidLine(this.selectedID);return}this.addLinePointToActiveLine()}},this.onDblclick=()=>{},this.onKeyUp=t=>{if(super.onKeyUp(t),this.isShift=!1,this.hoverLineSegmentIndex=-1,t.keyCode===f.Esc){this.stopLineCreating(!1);return}if(this.isActive){if(t.keyCode===f.Delete){this.deleteLine();return}if(t.keyCode===f.F){this.setInvalidLine(this.selectedID);return}if(t.keyCode===f.Space){this.continueToEdit();return}}this.keyboardEventWhileLineCreating(t)},this.onRightDblClick=t=>{super.onRightDblClick(t);const e=this.getCoordinate(t);if(this.isActive){const n=this.findHoveredPoint(e);if(n){this.deleteSelectedLinePoint(n.id);return}this.deleteSelectedLine(e)}},this.setReference=t=>{this.isReference=t},this.pointsWithinRange=t=>!(this.lowerLimitPointNum&&t<this.lowerLimitPointNum||this.upperLimitPointNum&&t>this.upperLimitPointNum),this.setLineList=t=>{const e=t.length!==this.lineListLen;this.lineList=t,e&&this.emit("updatePageNumber")},this.textChange=t=>{this.config.textConfigurable===!1||!this.selectedID||(this.updateSelectedTextAttribute(t),this.emit("selectedChange"))},this.status=2,this.isMousedown=!1,this.lineDragging=!1,this.isLineValid=!0,this.setConfig(i.config),this.prevAxis={x:0,y:0},this.textEditingID="",this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.actionsHistory=new M,this.dependToolConfig={lineType:D.Line}}get isLineSelected(){return this.selectedID&&this.activeLine}get selectedLinePoints(){return this.activeLine?this.getPointList(this.activeLine):[]}get isCreate(){return this.status===0}get isActive(){return this.status===1}get isNone(){return this.status===2}get isCurve(){return this.config.lineType===D.Curve}get isMultipleColor(){return this.config.lineColor===U.MultiColor}get imageSize(){return this.rotate%180==0?this.basicImgInfo:{width:this.basicImgInfo.height,height:this.basicImgInfo.width}}get lineListLen(){return this.lineList.length}get edgeAdsorptionEnabled(){return this.edgeAdsorption&&!this.isCurve&&this.lineListLen>0}get attributeConfigurable(){return this.config.attributeConfigurable}get isTextConfigurable(){return this.config.textConfigurable}get isDependPolygon(){return this.dependToolName===w.Polygon}get isDependRect(){return this.dependToolName===w.Rect}get isCurrentAttributeLocked(){return this.attributeLockList.includes(this.defaultAttribute)}get attributeFilteredLines(){return this.attributeLockList.length>0?this.lineList.filter(i=>this.attributeLockList.includes((i==null?void 0:i.attribute)||"")):this.lineList}get enableOutOfTarget(){return this.config.enableOutOfTarget||this.config.outOfTarget||this.config.drawOutsideTarget}get showOrder(){var i;return(i=this.config.showOrder)!=null?i:this.config.isShowOrder}get edgeAdsorption(){return this.config.edgeAdsorption}get attributeList(){return this.config.attributeList}get lowerLimitPointNum(){return this.config.lowerLimitPointNum}get upperLimitPointNum(){return this.config.upperLimitPointNum}get textCheckType(){return this.config.textCheckType}get customFormat(){return this.config.customFormat}get dataList(){return this.lineList}get hasActiveLine(){return this.activeLine&&this.activeLine.length>0}get viewPortLines(){const i=N.getViewPort(this.canvas,this.currentPos,this.zoom);return this.isHidden?[]:this.attributeFilteredLines.filter(t=>{var e;return(e=t==null?void 0:t.pointList)==null?void 0:e.some(n=>N.inViewPort(n,i))})}get lineStyle(){return{lineWidth:this.style.width,color:this.getLineColor(this.defaultAttribute),opacity:this.style.opacity}}get selectedText(){var i,t;return(t=(i=this.lineList.find(e=>e.id===this.selectedID))==null?void 0:i.textAttribute)!=null?t:""}get currentPageResult(){return this.lineList}updateStatus(i,t=!1){if(i!==this.status){if(t){let e="";this.textCheckType===B.Order&&this.isTextConfigurable&&(e=b.getTextAttribute(this.lineList,this.textCheckType)),this.emit("updateText",e)}this.status=i,this.lineStatusChanged()}}isInBasicPolygon(i){var t,e;return j(i,((t=this.basicResult)==null?void 0:t.pointList)||[],(e=this.dependToolConfig)==null?void 0:e.lineType)}getPolygonPointList(){if(!this.basicResult)return[];const{pointList:i}=this.basicResult,{lineType:t}=this.dependToolConfig;return t===D.Curve?W(i.reduce((e,n)=>[...e,n.x,n.y],[]),.5,!0,20):i}getNextCoordByRenderCoord(i){return this.getNextCoordByAbsCoord(this.coordUtils.getAbsCoord(i))}getNextCoordByAbsCoord(i){var t;const e=(t=this.activeLine)==null?void 0:t.slice(-1)[0];return e?this.coordUtils.getNextCoordByDependTool(i,e):i}pointInLine(i,t,e){return i.filter(n=>n).length<2?!1:i.some((n,s)=>{if(s===0)return!1;const r=this.coordUtils.getRenderCoord(i[s-1]),o=this.coordUtils.getRenderCoord(n);return v.isInLine(t,r,o,e)})}arc(i,t=m,e){var n,s,r,o,h,a;if(this.ctx){const{x:l,y:c}=i;(n=this.ctx)==null||n.save(),(s=this.ctx)==null||s.beginPath(),this.ctx.fillStyle=e||this.lineStyle.color,(r=this.ctx)==null||r.arc(l,c,t,0,360),(o=this.ctx)==null||o.closePath(),(h=this.ctx)==null||h.fill(),(a=this.ctx)==null||a.restore()}}renderActiveArea(){if(this.isActive&&this.activeArea&&this.ctx){const{top:i,left:t,right:e,bottom:n}=this.activeArea,{x:s,y:r}=this.coordUtils.getRenderCoord({x:t,y:i});this.ctx.save(),this.ctx.beginPath(),this.ctx.strokeStyle="#B3B8FF",this.ctx.rect(s,r,(e-t)*this.zoom,(n-i)*this.zoom),this.ctx.stroke(),this.ctx.restore()}}addLinePoint(i){var t,e,n,s;this.arc(i),(t=this.activeLine)==null||t.push(_(T({},i),{id:S()})),((e=this.activeLine)==null?void 0:e.length)===1?(n=this.actionsHistory)==null||n.initRecord(this.activeLine):(s=this.actionsHistory)==null||s.pushHistory(this.activeLine),this.render()}setCreatStatusAndAddPoint(i,t=!1){this.updateStatus(0,t),this.addLinePoint(i)}isActiveLineValid(){var i;return this.selectedID?(i=this.lineList.find(t=>t.id===this.selectedID))==null?void 0:i.valid:this.isLineValid}nextOrder(){return this.lineListLen===0?1:this.lineList.slice(-1)[0].order+1}getLineColorByAttribute(i,t=!1){return K.getStrokeAndFill(this.getColor(i.attribute),i.valid,{isSelected:t}).stroke}updateActiveArea(){this.activeArea=this.getActiveArea(),this.renderActiveArea()}getActiveArea(){return this.hasActiveLine?L.calcViewportBoundaries(this.activeLine,this.isCurve,p,this.zoom):void 0}drawLineNumber(i,t=1,e,n="",s,r=!0){var o,h,a;if((this.showOrder||this.attributeConfigurable)&&this.ctx){let l=this.showOrder?t.toString():`${n}`;if(this.attributeConfigurable){const c=s?(a=(h=(o=this.attributeList)==null?void 0:o.find(u=>u.value===s))==null?void 0:h.key)!=null?a:s:"";l=[l,`${!r&&c?"\u65E0\u6548":""}${c}`].filter(u=>u).join("_")}this.drawText(i,l,e)}}drawLineTextAttribute(i,t,e){if(i&&e)return this.drawText(i,e,t,200)}drawLineLength(i,t){var e;if(((e=this.config)==null?void 0:e.showLineLength)&&i){const n=i.reduce((r,o,h)=>h<=0||!i[h-1].actual||!o.actual?r:r+v.calcDistance(i[h-1].actual,o.actual),0),s=i[i.length-1];this.drawText(s,`l = ${n.toFixed(2)}`,t)}}drawText(i,t,e,n){var s,r;this.ctx&&((s=this.ctx)==null||s.save(),this.ctx.font="italic bold 14px SourceHanSansCN-Regular",this.ctx.fillStyle=e,this.ctx.strokeStyle=e,this.ctx.shadowColor="rgba(0, 0, 0, 0.6)",this.ctx.shadowOffsetY=2,this.ctx.shadowBlur=4,n?F.wrapText(this.canvas,t,i.x-C.x,i.y-C.y,n):this.ctx.fillText(t,i.x-C.x,i.y-C.y),(r=this.ctx)==null||r.restore())}moveActiveArea(i,t){this.activeArea&&(this.activeArea=Object.assign(this.activeArea,{top:this.activeArea.top+t,bottom:this.activeArea.bottom+t,right:this.activeArea.right+i,left:this.activeArea.left+i})),this.activeLine&&(this.activeLine.map(e=>Object.assign(e,{x:e.x+i,y:e.y+t})),this.updateLines())}findHoveredPoint(i){if(!!this.activeLine)return this.activeLine.find(t=>{const e=this.coordUtils.getRenderCoord(t);return v.calcDistance(e,i)<=x})}findHoverLine(i){return g.cloneDeep(this.lineList).reverse().find(({pointList:e})=>{const n=e?this.getPointList(e):[],s=this.getLineWidthScope();return n.some((r,o)=>{if(o===0)return!1;const h=this.coordUtils.getRenderCoord(r),a=this.coordUtils.getRenderCoord(n[o-1]);return v.isInLine(i,h,a,s)})})}getAdsorptionPoint(i){let t,e,n;return g.cloneDeep(this.lineList).reverse().forEach(({pointList:s,id:r})=>{if(r===this.selectedID||!s||(s==null?void 0:s.length)<2)return;const o=this.findNearestPoint(s,i);if(o){if(o.minDistance===0){t=o.point;return}(e===void 0||o.minDistance<e)&&(t=o.point,e=o.minDistance)}}),n||t}findNearestPoint(i,t,e=7){let n;const s=e;for(let r=1;r<=i.length-1;r++){const o=this.coordUtils.getRenderCoord(i[r]),h=this.coordUtils.getRenderCoord(i[r-1]),{length:a,footPoint:l}=L.getFootOfPerpendicular(t,o,h),c=v.calcTwoPointDistance(o,t),u=v.calcTwoPointDistance(h,t);if(c<=e*2){n=o,e=0;break}if(u<=e*2){n=h,e=0;break}a<e&&(n=l,e=a)}return n?{point:n,minDistance:s}:void 0}getPointList(i){return this.isCurve?R(i,p):i}moveSelectedLine(i){const t=(i.x-this.prevAxis.x)/this.zoom,e=(i.y-this.prevAxis.y)/this.zoom;if(this.enableOutOfTarget){this.lineDragging=!0,this.moveActiveArea(t,e);return}if(this.isDependPolygon){this.moveLineInPolygon(t,e);return}let n=[0,this.imageSize.width],s=[0,this.imageSize.height];if(this.isDependRect){const{x:r,y:o,width:h,height:a}=this.basicResult;n=[r,r+h],s=[o,o+a]}this.moveLineInRectRange(t,e,n,s)}moveSelectPoint(i){if(!this.selectedPoint)return;const t=i.x-this.prevAxis.x,e=i.y-this.prevAxis.y,n=(this.selectedPoint?this.selectedPoint.x:0)+t/this.zoom,s=(this.selectedPoint?this.selectedPoint.y:0)+e/this.zoom,r={x:n,y:s};Object.assign(this.selectedPoint,this.getNextCoordByAbsCoord(r)),this.updateLines(),this.render()}getCoordByConfig(i,t){var e;const n=!!i.shiftKey,s=i.altKey;if(((e=this.activeLine)==null?void 0:e.length)>0&&n){const r=this.activeLine.slice(-1)[0];return v.getVHPoint(r,t,this.coordUtils.getAbsCoord(t),this.coordUtils.getRenderCoord(r))}return this.edgeAdsorptionEnabled&&!s?this.getAdsorptionPoint(t):t}getNextPoint(i,t){const e=this.getCoordByConfig(i,t)||t;return this.enableOutOfTarget?this.coordUtils.getAbsCoord(e):this.getNextCoordByRenderCoord(e)}lineHover(){this.render()}mouseMoveHandler(i){const t=this.getCoordinate(i),e=i.which===1;if(this.isCreate){this.hasActiveLine&&this.renderNextPoint(i,t);return}if(this.isNone&&(this.lineHover(),this.edgeAdsorptionEnabled&&!i.altKey)){const n=this.getAdsorptionPoint(t);n&&this.arc(n)}if(this.isActive){if(this.isMousedown&&e){if(this.selectedPoint){this.moveSelectPoint(t);return}if(this.coordsInsideActiveArea){this.moveSelectedLine(t),this.drawActivatedLine(void 0,void 0,!0);return}}this.drawHoverPoint(t),this.render()}}onMouseMove(i){if(super.onMouseMove(i)||this.forbidMouseOperation||!this.imgInfo)return;const t=this.getCoordinate(i);this.mouseMoveHandler(i),this.prevAxis=t}setActiveArea(i,t=!1){const e=this.findHoverLine(i);if(e){const n=this.lineList.findIndex(o=>o.id===(e==null?void 0:e.id)),s=L.calcViewportBoundaries((e==null?void 0:e.pointList)||[],this.isCurve,p,this.zoom),r=this.lineList[n];this.updateStatus(1),this.setActiveLine(r.pointList),this.setSelectedLineID(r.id),this.activeArea=s,this.updateLineAttributes(r)}else t&&this.setNoneStatus();this.render()}setActiveLineByID(i){const t=this.lineList.find(e=>e.id===i);if(t){const e=L.calcViewportBoundaries((t==null?void 0:t.pointList)||[],this.isCurve,p,this.zoom);this.updateStatus(1),this.setActiveLine(t.pointList),this.setSelectedLineID(t.id),this.activeArea=e,this.updateLineAttributes(t)}this.render()}setActiveLine(i){this.activeLine=i?g.cloneDeep(i):void 0}historyChanged(i){const t=`${i}Enabled`;if(this.isCreate){if(this.actionsHistory&&this.actionsHistory[t]){const e=this.actionsHistory&&this.actionsHistory[i]();this.setActiveLine(e),this.render()}return}if(this.history&&this.history[t]){const e=this.history[i](),n=e==null?void 0:e.find(s=>s.id===this.selectedID);this.lineList=e,this.selectedID&&n?this.setActiveLine(n==null?void 0:n.pointList):this.setNoneStatus(),this.render()}this.emit("dataUpdated",this.lineList)}undo(){this.historyChanged("undo"),this.updateSelectedAttributeAfterHistoryChanged()}redo(){this.historyChanged("redo"),this.updateSelectedAttributeAfterHistoryChanged()}isCoordInsideTarget(i){if(this.isDependPolygon)return this.isInBasicPolygon(i);if(this.isDependRect){const{x:t,y:e,width:n,height:s}=this.basicResult,r=[t,t+n],o=[e,e+s];return L.isInRange(i.x,r)&&L.isInRange(i.y,o)}return L.isInRange(i.x,[0,this.imageSize.width])&&L.isInRange(i.y,[0,this.imageSize.height])}getPointInsertIndex(i,t){if(i&&this.activeLine){const e=this.getPointList(this.activeLine);return this.activeLine.length===2?1:this.activeLine.findIndex((n,s)=>{if(s>0){const r=this.activeLine?this.activeLine[s-1]:void 0,o=this.isCurve?e.slice((s-1)*(p+1),s*(p+1)):[r,n];return this.pointInLine(o,i,t||this.getLineWidthScope())}return!1})}return-1}getLineWidthScope(){return this.lineStyle.lineWidth}isMouseCoordOutsideActiveArea(){return!this.coordsInsideActiveArea&&!this.selectedPoint}isLinePointsExceed(){return this.isCreate&&this.activeLine&&this.upperLimitPointNum&&~~this.upperLimitPointNum<=this.activeLine.length}isLinePointsNotEnough(){var i;return this.activeLine&&((i=this.activeLine)==null?void 0:i.length)<this.lowerLimitPointNum}updateLineSegmentSpecial(i){const t=this.getPointInsertIndex(i,2)-1;if(t>-1){const e=this.activeLine[t];e.specialEdge=!e.specialEdge,this.hoverLineSegmentIndex=-1,this.render()}}addLinePointToActiveLine(){var i;const t=this.getPointInsertIndex(this.cursor),e=this.pointsWithinRange(this.activeLine.length+1);this.cursor&&t>-1&&e&&(this.activeLine.splice(t,0,_(T({},this.coordUtils.getAbsCoord(this.cursor)),{id:S()})),this.updateLines(),(i=this.history)==null||i.pushHistory(this.lineList),this.render(),this.cursor=void 0)}onMouseDown(i){if(super.onMouseDown(i)||this.forbidMouseOperation||!this.imgInfo)return;const t=this.getCoordinate(i);if(this.isMousedown=!0,this.prevAxis=t,i.which===3){this.cursor=void 0;return}this.selectedPoint=this.findHoveredPoint(t),this.coordsInsideActiveArea=this.isActive&&this.activeArea?v.inArea(this.activeArea,this.coordUtils.getAbsCoord(t)):!1,this.lineDragging=!1}lineHasChanged(){const i=this.lineList.find(t=>t.id===this.selectedID);return i?JSON.stringify(i.pointList)!==JSON.stringify(this.activeLine):!1}updateLines(){const i=this.lineList.find(t=>t.id===this.selectedID);i&&(i.pointList=g.cloneDeep(this.activeLine),this.emit("dataUpdated",this.lineList))}onMouseUp(i){const t=()=>{this.isMousedown=!1,this.hoverPointID=void 0,this.cursor=void 0,this.selectedPoint=void 0};if(this.hoverPointID=void 0,super.onMouseUp(i)||this.forbidMouseOperation||!this.imgInfo){t();return}i.which===1&&this.onLeftClick(i),i.which===3&&this.onRightClick(i),t()}isTextValid(i){return b.textAttributeValidate(this.textCheckType,this.customFormat,i)}createLineData(){const i=S(),t={pointList:g.cloneDeep(this.activeLine),id:i,valid:this.isLineValid,order:this.nextOrder()};return t.attribute=this.defaultAttribute,t}stopLineCreating(i=!0){var t,e,n,s;const r=this.selectedID?!0:!!this.isTextConfigurable;let o;if(i){if(this.selectedID){const h=this.lineList.find(a=>a.id===this.selectedID);o=this.selectedID,h&&(h.pointList=g.cloneWith(this.activeLine),g.isEqual(h.pointList,(t=this.history)==null?void 0:t.pushHistory(this.lineList))||(e=this.history)==null||e.pushHistory(this.lineList))}else if(this.isCreate&&this.activeLine&&this.activeLine.length>1){const h=this.createLineData();o=h.id,this.setLineList([...this.lineList,h]),(n=this.history)==null||n.pushHistory(this.lineList)}}r?this.setActiveStatus(o):this.setNoneStatus(),(s=this.actionsHistory)==null||s.empty(),this.emit("dataUpdated",this.lineList),this.render()}setActiveStatus(i){const t=i?this.lineList.find(e=>e.id===i):void 0;if(t){const e=t==null?void 0:t.pointList;this.updateStatus(1),this.setActiveLine(e),this.setSelectedLineID(i)}else this.setNoneStatus()}setNoneStatus(i=!0){i&&this.updateStatus(2),this.activeLine=[],this.setSelectedLineID(void 0),this.activeArea=void 0,this.isLineValid=!0,this.cursor=void 0}setKeyDownStatus(i,t){this.isShift=t!=null?t:i.keyCode===f.Shift}continueToEdit(){var i;this.updateStatus(0),this.cursor=void 0,(i=this.actionsHistory)==null||i.pushHistory(this.activeLine),this.render()}setInvalidLineOnCreating(i){if(this.selectedID&&i.keyCode!==f.Ctrl||!this.isCreate)return;const t=!i.ctrlKey;this.selectedID?this.setInvalidLine(this.selectedID,t,!1):this.isLineValid=t}onKeyDown(i){if(super.onKeyDown(i),this.setKeyDownStatus(i),i.keyCode===f.Z&&!i.ctrlKey&&this.toggleIsHide(),i.keyCode===f.Shift&&this.render(),i.keyCode===f.Tab){i.preventDefault(),this.selectToNextLine(i);return}if(this.isCreate&&this.keyboardEventWhileLineCreating(i),this.config.attributeConfigurable){const t=b.getAttributeByKeycode(i.keyCode,this.config.attributeList);t!==void 0&&this.setDefaultAttribute(t)}}selectToNextLine(i){const t=z.getNextSelectedRectIDByEvent(this.viewPortLines.map(e=>{var n,s,r,o;return _(T({},e),{x:(s=(n=e.pointList[0])==null?void 0:n.x)!=null?s:0,y:(o=(r=e.pointList[0])==null?void 0:r.y)!=null?o:0})}),i,this.selectedID);t&&this.setActiveLineByID(t.id)}keyboardEventWhileLineCreating(i){!this.isCreate||(i.keyCode===f.Ctrl&&this.setInvalidLineOnCreating(i),[f.Shift,f.Alt].includes(i.keyCode)&&this.renderNextPoint(i,this.prevAxis))}renderNextPoint(i,t){const e=this.coordUtils.getRenderCoord(this.getNextPoint(i,t));this.render(e)}deleteSelectedLine(i){const t=L.calcViewportBoundaries(this.activeLine,this.isCurve,p,this.zoom);v.inArea(t,this.coordUtils.getAbsCoord(i))&&this.deleteLine()}deleteSelectedLinePoint(i){var t;this.pointsWithinRange(this.activeLine.length-1)&&i&&(this.setActiveLine(this.activeLine.filter(n=>n.id!==i)),this.updateLines(),(t=this.history)==null||t.pushHistory(this.lineList)),this.cursor=void 0,this.render()}deleteLine(){var i;this.lineList=this.lineList.filter(t=>t.id!==this.selectedID),(i=this.history)==null||i.pushHistory(this.lineList),this.setNoneStatus(),this.emit("dataUpdated",this.lineList),this.render()}setInvalidLine(i,t,e=!0){var n;const s=this.lineList.find(r=>r.id===i);s&&(s.valid=t!==void 0?t:!s.valid,(n=this.history)==null||n.pushHistory(this.lineList),e&&this.render())}empty(){var i,t;this.lineList=[],this.setNoneStatus(),this.selectedPoint=void 0,(i=this.actionsHistory)==null||i.empty(),(t=this.history)==null||t.init(),this.emit("dataUpdated",this.lineList),this.render()}setAttribute(i){var t;this.attributeConfigurable&&(this.defaultAttribute=i,this.setLineAttribute("attribute",i),this.selectedID&&((t=this.history)==null||t.pushHistory(this.lineList)))}setTextAttribute(i){var t;this.isTextConfigurable&&(this.setLineAttribute("textAttribute",i),(t=this.history)==null||t.applyAttribute(this.selectedID,"textAttribute",i))}setLineAttribute(i,t,e){const n=e||this.selectedID;if(n){const s=this.lineList.find(r=>r.id===n);s&&(s[i]=t)}this.render()}updateAttribute(i){this.emit("updateAttribute",i)}updateLineAttributes(i){var t;if(this.attributeConfigurable&&i){const e=(i==null?void 0:i.attribute)||"";this.defaultAttribute=e,this.updateAttribute(e)}if(this.isTextConfigurable&&i){const e=(i==null?void 0:i.textAttribute)||"";this.updateTextAttribute(e)}(t=this.history)==null||t.updateHistory(this.lineList)}lineStatusChanged(){this.emit("lineStatusChanged",{status:this.status,selectedLineID:this.selectedID})}updateTextAttribute(i){if(this.selectedID){const t=this.lineList.find(e=>e.id===this.selectedID);t&&(t.textAttribute=i)}this.emit("updateText",i)}saveData(){this.stopLineCreating(),this.setNoneStatus(),this.render()}setTextEditingID(i){this.textEditingID=i,this.render()}setSelectedLineID(i){var t,e;if(this.selectedID===i)return;const n=this.selectedID;i!==n&&n&&((t=this._textAttributeInstance)==null||t.changeSelected()),i||(e=this._textAttributeInstance)==null||e.clearTextAttribute(),this.selectedID=i,this.emit("selectedChange")}attributeLockListChange(i){this.attributeLockList=i,this.render()}setResult(i){this.setNoneStatus(),this.setLineList(i),this.render()}setConfig(i){super.setConfig(i)}toggleIsHide(){this.setIsHidden(!this.isHidden),this.render()}clearCanvas(){super.clearCanvas()}clearResult(){this.setResult([]),this.setSelectedLineID(void 0),this.render()}exportData(){return[this.lineList,this.basicImgInfo]}setDefaultAttribute(i=""){var t;this.attributeConfigurable&&(this.defaultAttribute=i,this.setLineAttribute("attribute",i),this.selectedID&&((t=this.history)==null||t.pushHistory(this.lineList)),this.emit("changeAttributeSidebar"))}getCurrentSelectedData(){var i,t;const e=this.isActiveLineValid(),n=this.defaultAttribute,s=this.getColor(n),r=e?s==null?void 0:s.valid.stroke:s==null?void 0:s.invalid.stroke,o=(t=(i=this.lineList.find(h=>h.id===this.selectedID))==null?void 0:i.textAttribute)!=null?t:"";return{color:r,textAttribute:o}}renderTextAttribute(){var i,t,e,n;if(!this.ctx||!this.activeLine||((i=this.activeLine)==null?void 0:i.length)<2||this.isCreate)return;const s=this.isActiveLineValid(),r=this.defaultAttribute,{x:o,y:h}=this.activeLine[1],a=this.coordUtils.getRenderCoord({x:o,y:h}),l=this.getColor(r),c=s?l==null?void 0:l.valid.stroke:l==null?void 0:l.invalid.stroke,u=(e=(t=this.lineList.find(A=>A.id===this.selectedID))==null?void 0:t.textAttribute)!=null?e:"";this._textAttributeInstance||(this._textAttributeInstance=new $({container:this.container,icon:this.getTextIconSvg(r),color:c,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((n=this._textAttributeInstance)==null?void 0:n.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${u}`,{left:a.x,top:a.y,color:c}),this._textAttributeInstance.updateIcon(this.getTextIconSvg(r))}getTextIconSvg(i=""){return b.getTextIconSvg(i,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}updateSelectedTextAttribute(i){if(this._textAttributeInstance&&i&&this.selectedID){let t=i;!b.textAttributeValidate(this.config.textCheckType,"",t)&&(this.emit("messageError",b.getErrorNotice(this.config.textCheckType,this.lang)),t=""),this.setTextAttribute(t),this.emit("updateTextAttribute"),this.render()}}}export{H as INNER_POINT_RADIUS,C as LINE_ORDER_OFFSET,x as POINT_ACTIVE_RADIUS,m as POINT_RADIUS,p as SEGMENT_NUMBER,Q as default};
|
|
1
|
+
import g from"lodash";import{ELineTypes as P,ELineColor as U,EToolName as w,ETextType as B}from"../../constant/tool.js";import M from"../../utils/ActionsHistory.js";import S from"../../utils/uuid.js";import f from"../../constant/keyCode.js";import L from"../../utils/MathUtils.js";import{BasicToolOperation as j}from"./basicToolOperation.js";import u from"../../utils/tool/LineToolUtils.js";import{createSmoothCurvePointsFromPointList as R,isInPolygon as V,createSmoothCurvePoints as W}from"../../utils/tool/polygonTool.js";import z from"../../utils/tool/CommonToolUtils.js";import N from"../../utils/tool/CanvasUtils.js";import F from"../../utils/tool/DrawUtils.js";import K from"../../utils/tool/StyleUtils.js";import b from"../../utils/tool/AttributeUtils.js";import $ from"./textAttributeClass.js";import J from"../../locales/index.js";import{EMessage as q}from"../../locales/constants.js";var G=Object.defineProperty,Y=Object.defineProperties,Z=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,Q=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable,E=(d,t,i)=>t in d?G(d,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):d[t]=i,_=(d,t)=>{for(var i in t||(t={}))Q.call(t,i)&&E(d,i,t[i]);if(O)for(var i of O(t))X.call(t,i)&&E(d,i,t[i]);return d},T=(d,t)=>Y(d,Z(t)),k;(function(d){d[d.Create=0]="Create",d[d.Active=1]="Active",d[d.None=2]="None"})(k||(k={}));const p=16,C={x:0,y:20},m=3,x=5,H=2;class tt extends j{constructor(t){super(t);this.drawActivatedLine=(i,e,s)=>{const n=g.cloneDeep(this.activeLine);if(!n||n.length===0)return;const r=this.isActiveLineValid();let o;const h=this.selectedID?this.lineList.find(l=>l.id===this.selectedID):void 0;h?o=h.order:o=this.nextOrder();const a=this.getLineColorByAttribute({attribute:this.defaultAttribute,valid:!!r});n.map(l=>Object.assign(l,{actual:{x:l.x,y:l.y}},this.coordUtils.getRenderCoord(l))),this.isActive&&this.drawLineLength(n,a),this.updateActiveArea(),this.drawLine(n,i,a,!0,!0),this.drawLineNumber(n[0],o,a,"",this.defaultAttribute,r),i&&this.isCreate&&this.arc(i,m,a),this.cursor&&!this.selectedPoint&&!s&&!this.isShift&&this.arc(this.cursor,x,a)},this.drawHoverPoint=i=>{if(!this.isMousedown&&i&&this.isLineSelected){const e=this.getPointList(this.activeLine),s=this.activeLine.find(r=>u.calcDistance(this.coordUtils.getRenderCoord(r),i)<=x);let n;!s&&this.activeLine&&(n=this.findNearestPoint(e,i)),this.hoverPointID=s?s.id:void 0,this.cursor=s||n==null?void 0:n.point}},this.updatedLine={id:"",valid:!1,order:0},this.toolName="lineTool",this.lineList=[],this.activeLine=[],this.coordsInsideActiveArea=!1,this.hoverLineSegmentIndex=-1,this.isShift=!1,this.isReference=!1,this.selectedIDs=[],this.drawCurveLine=(i,e,s,n=!0,r=!1,o)=>{const h=R(e,p);i.save(),i.lineCap="round",i.lineJoin="round",i.strokeStyle=s.color,n&&(i.lineWidth=s.lineWidth),r&&u.setReferenceCtx(i),e.forEach(({specialEdge:a},l)=>{const c=h.splice(0,p+1);i.save(),i.beginPath(),o===l&&(i.lineWidth=4),c.forEach(({x:v,y:A},I)=>{const D=I>0?"lineTo":"moveTo";a&&u.setSpecialEdgeStyle(i),i[D](v,A)}),i.stroke(),i.restore()}),i.restore()},this.drawLine=(i,e,s,n=!1,r=!1)=>{const o=e?i.concat(e):i,h={color:s,lineWidth:r?1:this.lineStyle.lineWidth};this.isCurve?u.drawCurveLine(this.ctx,o,h,!n,this.isReference,r?this.hoverLineSegmentIndex:-1):this.drawStraightLine(o,h,r),n&&i.forEach(a=>{var l,c;const v=a.id,A=v&&[this.hoverPointID,(l=this.selectedPoint)==null?void 0:l.id].includes(v)?x:m;this.arc(a,A,s),[this.hoverPointID,(c=this.selectedPoint)==null?void 0:c.id].includes(v)||this.arc(a,H,"white")})},this.drawStraightLine=(i,e,s=!1)=>{const{ctx:n}=this;n&&(n.save(),n.lineCap="round",n.lineJoin="round",n.strokeStyle=e.color,n.lineWidth=e.lineWidth,this.isReference&&u.setReferenceCtx(n),i.forEach((r,o)=>{if(n.beginPath(),o>0){const h=i[o-1];n.save(),(h==null?void 0:h.specialEdge)&&u.setSpecialEdgeStyle(n),s&&this.hoverLineSegmentIndex+1===o&&(n.lineWidth=4),n.moveTo(h.x,h.y),n.lineTo(r.x,r.y),n.stroke(),n.restore()}}),n.restore())},this.drawLines=()=>{try{const i=g.cloneDeep(this.attributeFilteredLines);if(this.isHidden)return;i.forEach(e=>{if(e.id!==this.selectedID&&e.pointList){e.pointList.map(h=>Object.assign(h,{actual:{x:h.x,y:h.y}},this.coordUtils.getRenderCoord(h)));const{order:s,label:n}=e,r=s,o=e&&this.getLineColorByAttribute(e);this.drawLine(e.pointList,void 0,o,!1),this.drawLineNumber(e.pointList[0],r,o,n,e.attribute,e.valid),e.id!==this.textEditingID&&(this.drawLineTextAttribute(e.pointList[1],o,e==null?void 0:e.textAttribute),this.drawLineLength(e.pointList,o))}})}catch(i){console.error(i,"\u7EBF\u6761\u5DE5\u5177\u6570\u636E\u89E3\u6790\u9519\u8BEF"),this.lineList=[],this.clearCanvas()}},this.render=i=>{super.render(),this.drawLines(),this.drawActivatedLine(i,void 0,!0),this.renderTextAttribute(),this.renderCursorLine(this.getLineColor(this.defaultAttribute))},this.moveLineInPolygon=(i,e)=>{var s;if(!Array.isArray(this.activeLine))return!1;((s=this.activeLine)==null?void 0:s.every(r=>this.isInBasicPolygon({x:r.x+i,y:r.y+e})))&&(this.lineDragging=!0,this.moveActiveArea(i,e))},this.moveLineInRectRange=(i,e,s,n)=>{if(this.activeArea===void 0)return;const{top:r,left:o,right:h,bottom:a}=this.activeArea,l=[o,h].map(y=>g.isNumber(y)?y+i:0),c=[r,a].map(y=>g.isNumber(y)?y+e:0),v=o>=0&&h&&L.isInRange(l,s),A=r>=0&&a&&L.isInRange(c,n),I=v?i:0,D=A?e:0;this.lineDragging=!0,this.moveActiveArea(I,D)},this.onRightClick=i=>{if(this.cursor=void 0,this.isCreate){if(this.isLinePointsNotEnough())return;if(u.lineLengthSum(this.activeLine||[])<this.minLength)return this.emit("messageInfo",`${J.getMessagesByLocale(q.MinLengthLimitErrorNotice,this.lang)}${this.minLength}`),!0;this.stopLineCreating(!0);return}this.setActiveArea(this.getCoordinate(i),!0),this.emit("contextmenu")},this.updateSelectedAttributeAfterHistoryChanged=()=>{if(this.selectedID){const i=this.lineList.find(s=>s.id===this.selectedID),e=i==null?void 0:i.attribute;typeof e=="string"&&(this.defaultAttribute=e,this.updateAttribute(e),this.render())}},this.onLeftClick=i=>{const e=this.getCoordinate(i),{lineDragging:s}=this;if(this.lineDragging=!1,this.isSpaceKey)return;if(this.isNone&&i.ctrlKey){const r=this.findHoverLine(e);r&&this.setInvalidLine(r.id);return}if(this.isLinePointsExceed())return;const n=this.getNextPoint(i,e);if(this.isCreate||this.isNone){this.setCreatStatusAndAddPoint(n);return}if(this.isActive){if(s)return;if(this.isMouseCoordOutsideActiveArea()){this.setNoneStatus(!1),this.setCreatStatusAndAddPoint(n);return}if(i.shiftKey){this.updateLineSegmentSpecial(e);return}if(this.coordsInsideActiveArea&&i.ctrlKey){this.setInvalidLine(this.selectedID);return}this.addLinePointToActiveLine()}},this.onDblclick=()=>{},this.onKeyUp=i=>{if(super.onKeyUp(i),this.isShift=!1,this.hoverLineSegmentIndex=-1,i.keyCode===f.Esc){this.stopLineCreating(!1);return}if(this.isActive){if(i.keyCode===f.Delete){this.deleteLine();return}if(i.keyCode===f.F){this.setInvalidLine(this.selectedID);return}if(i.keyCode===f.Space){this.continueToEdit();return}}this.keyboardEventWhileLineCreating(i)},this.onRightDblClick=i=>{super.onRightDblClick(i);const e=this.getCoordinate(i);if(this.isActive){const s=this.findHoveredPoint(e);if(s){this.deleteSelectedLinePoint(s.id);return}this.deleteSelectedLine(e)}},this.setReference=i=>{this.isReference=i},this.pointsWithinRange=i=>!(this.lowerLimitPointNum&&i<this.lowerLimitPointNum||this.upperLimitPointNum&&i>this.upperLimitPointNum),this.setLineList=i=>{const e=i.length!==this.lineListLen;this.lineList=i,e&&this.emit("updatePageNumber")},this.textChange=i=>{this.config.textConfigurable===!1||!this.selectedID||(this.updateSelectedTextAttribute(i),this.emit("selectedChange"))},this.status=2,this.isMousedown=!1,this.lineDragging=!1,this.isLineValid=!0,this.setConfig(t.config),this.prevAxis={x:0,y:0},this.textEditingID="",this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.actionsHistory=new M,this.dependToolConfig={lineType:P.Line}}get isLineSelected(){return this.selectedID&&this.activeLine}get selectedLinePoints(){return this.activeLine?this.getPointList(this.activeLine):[]}get isCreate(){return this.status===0}get isActive(){return this.status===1}get isNone(){return this.status===2}get isCurve(){return this.config.lineType===P.Curve}get isMultipleColor(){return this.config.lineColor===U.MultiColor}get imageSize(){return this.rotate%180==0?this.basicImgInfo:{width:this.basicImgInfo.height,height:this.basicImgInfo.width}}get lineListLen(){return this.lineList.length}get edgeAdsorptionEnabled(){return this.edgeAdsorption&&!this.isCurve&&this.lineListLen>0}get attributeConfigurable(){return this.config.attributeConfigurable}get isTextConfigurable(){return this.config.textConfigurable}get isDependPolygon(){return this.dependToolName===w.Polygon}get isDependRect(){return this.dependToolName===w.Rect}get isCurrentAttributeLocked(){return this.attributeLockList.includes(this.defaultAttribute)}get attributeFilteredLines(){return this.attributeLockList.length>0?this.lineList.filter(t=>this.attributeLockList.includes((t==null?void 0:t.attribute)||"")):this.lineList}get enableOutOfTarget(){return this.config.enableOutOfTarget||this.config.outOfTarget||this.config.drawOutsideTarget}get showOrder(){var t;return(t=this.config.showOrder)!=null?t:this.config.isShowOrder}get edgeAdsorption(){return this.config.edgeAdsorption}get attributeList(){return this.config.attributeList}get lowerLimitPointNum(){return this.config.lowerLimitPointNum}get minLength(){var t;return((t=this.config)==null?void 0:t.minLength)||1}get upperLimitPointNum(){return this.config.upperLimitPointNum}get textCheckType(){return this.config.textCheckType}get customFormat(){return this.config.customFormat}get dataList(){return this.lineList}get hasActiveLine(){return this.activeLine&&this.activeLine.length>0}get viewPortLines(){const t=N.getViewPort(this.canvas,this.currentPos,this.zoom);return this.isHidden?[]:this.attributeFilteredLines.filter(i=>{var e;return(e=i==null?void 0:i.pointList)==null?void 0:e.some(s=>N.inViewPort(s,t))})}get lineStyle(){return{lineWidth:this.style.width,color:this.getLineColor(this.defaultAttribute),opacity:this.style.opacity}}get selectedText(){var t,i;return(i=(t=this.lineList.find(e=>e.id===this.selectedID))==null?void 0:t.textAttribute)!=null?i:""}get currentPageResult(){return this.lineList}updateStatus(t,i=!1){if(t!==this.status){if(i){let e="";this.textCheckType===B.Order&&this.isTextConfigurable&&(e=b.getTextAttribute(this.lineList,this.textCheckType)),this.emit("updateText",e)}this.status=t,this.lineStatusChanged()}}isInBasicPolygon(t){var i,e;return V(t,((i=this.basicResult)==null?void 0:i.pointList)||[],(e=this.dependToolConfig)==null?void 0:e.lineType)}getPolygonPointList(){if(!this.basicResult)return[];const{pointList:t}=this.basicResult,{lineType:i}=this.dependToolConfig;return i===P.Curve?W(t.reduce((e,s)=>[...e,s.x,s.y],[]),.5,!0,20):t}getNextCoordByRenderCoord(t){return this.getNextCoordByAbsCoord(this.coordUtils.getAbsCoord(t))}getNextCoordByAbsCoord(t){var i;const e=(i=this.activeLine)==null?void 0:i.slice(-1)[0];return e?this.coordUtils.getNextCoordByDependTool(t,e):t}pointInLine(t,i,e){return t.filter(s=>s).length<2?!1:t.some((s,n)=>{if(n===0)return!1;const r=this.coordUtils.getRenderCoord(t[n-1]),o=this.coordUtils.getRenderCoord(s);return u.isInLine(i,r,o,e)})}arc(t,i=m,e){var s,n,r,o,h,a;if(this.ctx){const{x:l,y:c}=t;(s=this.ctx)==null||s.save(),(n=this.ctx)==null||n.beginPath(),this.ctx.fillStyle=e||this.lineStyle.color,(r=this.ctx)==null||r.arc(l,c,i,0,360),(o=this.ctx)==null||o.closePath(),(h=this.ctx)==null||h.fill(),(a=this.ctx)==null||a.restore()}}renderActiveArea(){if(this.isActive&&this.activeArea&&this.ctx){const{top:t,left:i,right:e,bottom:s}=this.activeArea,{x:n,y:r}=this.coordUtils.getRenderCoord({x:i,y:t});this.ctx.save(),this.ctx.beginPath(),this.ctx.strokeStyle="#B3B8FF",this.ctx.rect(n,r,(e-i)*this.zoom,(s-t)*this.zoom),this.ctx.stroke(),this.ctx.restore()}}setSelectedIDs(t){this.selectedIDs=t,this.selectedIDs.length<2&&this.setSelectedID(this.selectedIDs.length===1?this.selectedIDs[0]:""),this.render()}setSelectedID(t){var i,e;const s=this.selectedID;t!==s&&s&&((i=this._textAttributInstance)==null||i.changeSelected()),t||(e=this._textAttributInstance)==null||e.clearTextAttribute(),this.selectedID=t,this.render(),this.emit("selectedChange")}addLinePoint(t){var i,e,s,n;this.arc(t),(i=this.activeLine)==null||i.push(T(_({},t),{id:S()})),((e=this.activeLine)==null?void 0:e.length)===1?(s=this.actionsHistory)==null||s.initRecord(this.activeLine):(n=this.actionsHistory)==null||n.pushHistory(this.activeLine),this.render()}setCreatStatusAndAddPoint(t,i=!1){this.updateStatus(0,i),this.addLinePoint(t)}isActiveLineValid(){var t;return this.selectedID?(t=this.lineList.find(i=>i.id===this.selectedID))==null?void 0:t.valid:this.isLineValid}nextOrder(){return this.lineListLen===0?1:this.lineList.slice(-1)[0].order+1}getLineColorByAttribute(t,i=!1){return K.getStrokeAndFill(this.getColor(t.attribute),t.valid,{isSelected:i}).stroke}updateActiveArea(){this.activeArea=this.getActiveArea(),this.renderActiveArea()}getActiveArea(){return this.hasActiveLine?L.calcViewportBoundaries(this.activeLine,this.isCurve,p,this.zoom):void 0}drawLineNumber(t,i=1,e,s="",n,r=!0){var o,h,a;if((this.showOrder||this.attributeConfigurable)&&this.ctx){let l=this.showOrder?i.toString():`${s}`;if(this.attributeConfigurable){const c=n?(a=(h=(o=this.attributeList)==null?void 0:o.find(v=>v.value===n))==null?void 0:h.key)!=null?a:n:"";l=[l,`${!r&&c?"\u65E0\u6548":""}${c}`].filter(v=>v).join("_")}this.drawText(t,l,e)}}drawLineTextAttribute(t,i,e){if(t&&e)return this.drawText(t,e,i,200)}drawLineLength(t,i){var e;if(((e=this.config)==null?void 0:e.showLineLength)&&t){const s=t.reduce((r,o,h)=>h<=0||!t[h-1].actual||!o.actual?r:r+u.calcDistance(t[h-1].actual,o.actual),0),n=t[t.length-1];this.drawText(n,`l = ${s.toFixed(2)}`,i)}}drawText(t,i,e,s){var n,r;this.ctx&&((n=this.ctx)==null||n.save(),this.ctx.font="italic bold 14px SourceHanSansCN-Regular",this.ctx.fillStyle=e,this.ctx.strokeStyle=e,this.ctx.shadowColor="rgba(0, 0, 0, 0.6)",this.ctx.shadowOffsetY=2,this.ctx.shadowBlur=4,s?F.wrapText(this.canvas,i,t.x-C.x,t.y-C.y,s):this.ctx.fillText(i,t.x-C.x,t.y-C.y),(r=this.ctx)==null||r.restore())}moveActiveArea(t,i){this.activeArea&&(this.activeArea=Object.assign(this.activeArea,{top:this.activeArea.top+i,bottom:this.activeArea.bottom+i,right:this.activeArea.right+t,left:this.activeArea.left+t})),this.activeLine&&(this.activeLine.map(e=>Object.assign(e,{x:e.x+t,y:e.y+i})),this.updateLines()),this.emit("updateLineByDrag",this.updatedLine)}findHoveredPoint(t){if(!!this.activeLine)return this.activeLine.find(i=>{const e=this.coordUtils.getRenderCoord(i);return u.calcDistance(e,t)<=x})}findHoverLine(t){return g.cloneDeep(this.lineList).reverse().find(({pointList:e})=>{const s=e?this.getPointList(e):[],n=this.getLineWidthScope();return s.some((r,o)=>{if(o===0)return!1;const h=this.coordUtils.getRenderCoord(r),a=this.coordUtils.getRenderCoord(s[o-1]);return u.isInLine(t,h,a,n)})})}getAdsorptionPoint(t){let i,e,s;return g.cloneDeep(this.lineList).reverse().forEach(({pointList:n,id:r})=>{if(r===this.selectedID||!n||(n==null?void 0:n.length)<2)return;const o=this.findNearestPoint(n,t);if(o){if(o.minDistance===0){i=o.point;return}(e===void 0||o.minDistance<e)&&(i=o.point,e=o.minDistance)}}),s||i}findNearestPoint(t,i,e=7){let s;const n=e;for(let r=1;r<=t.length-1;r++){const o=this.coordUtils.getRenderCoord(t[r]),h=this.coordUtils.getRenderCoord(t[r-1]),{length:a,footPoint:l}=L.getFootOfPerpendicular(i,o,h),c=u.calcTwoPointDistance(o,i),v=u.calcTwoPointDistance(h,i);if(c<=e*2){s=o,e=0;break}if(v<=e*2){s=h,e=0;break}a<e&&(s=l,e=a)}return s?{point:s,minDistance:n}:void 0}getPointList(t){return this.isCurve?R(t,p):t}moveSelectedLine(t){const i=(t.x-this.prevAxis.x)/this.zoom,e=(t.y-this.prevAxis.y)/this.zoom;if(this.enableOutOfTarget){this.lineDragging=!0,this.moveActiveArea(i,e);return}if(this.isDependPolygon){this.moveLineInPolygon(i,e);return}let s=[0,this.imageSize.width],n=[0,this.imageSize.height];if(this.isDependRect){const{x:r,y:o,width:h,height:a}=this.basicResult;s=[r,r+h],n=[o,o+a]}this.moveLineInRectRange(i,e,s,n)}moveSelectPoint(t){if(!this.selectedPoint)return;const i=t.x-this.prevAxis.x,e=t.y-this.prevAxis.y,s=(this.selectedPoint?this.selectedPoint.x:0)+i/this.zoom,n=(this.selectedPoint?this.selectedPoint.y:0)+e/this.zoom,r={x:s,y:n};Object.assign(this.selectedPoint,this.getNextCoordByAbsCoord(r)),this.updateLines(),this.render()}getCoordByConfig(t,i){var e;const s=!!t.shiftKey,n=t.altKey;if(((e=this.activeLine)==null?void 0:e.length)>0&&s){const r=this.activeLine.slice(-1)[0];return u.getVHPoint(r,i,this.coordUtils.getAbsCoord(i),this.coordUtils.getRenderCoord(r))}return this.edgeAdsorptionEnabled&&!n?this.getAdsorptionPoint(i):i}getNextPoint(t,i){const e=this.getCoordByConfig(t,i)||i;return this.enableOutOfTarget?this.coordUtils.getAbsCoord(e):this.getNextCoordByRenderCoord(e)}lineHover(){this.render()}mouseMoveHandler(t){const i=this.getCoordinate(t),e=t.which===1;if(this.isCreate){this.hasActiveLine&&this.renderNextPoint(t,i);return}if(this.isNone&&(this.lineHover(),this.edgeAdsorptionEnabled&&!t.altKey)){const s=this.getAdsorptionPoint(i);s&&this.arc(s)}if(this.isActive){if(this.isMousedown&&e){if(this.selectedPoint){this.moveSelectPoint(i);return}if(this.coordsInsideActiveArea){this.moveSelectedLine(i),this.drawActivatedLine(void 0,void 0,!0);return}}this.drawHoverPoint(i),this.render()}}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const i=this.getCoordinate(t);this.mouseMoveHandler(t),this.prevAxis=i}setActiveArea(t,i=!1){const e=this.findHoverLine(t);if(e){const s=this.lineList.findIndex(o=>o.id===(e==null?void 0:e.id)),n=L.calcViewportBoundaries((e==null?void 0:e.pointList)||[],this.isCurve,p,this.zoom),r=this.lineList[s];this.updateStatus(1),this.setActiveLine(r.pointList),this.setSelectedLineID(r.id),this.activeArea=n,this.updateLineAttributes(r)}else i&&this.setNoneStatus();this.render()}setActiveLineByID(t){const i=this.lineList.find(e=>e.id===t);if(i){const e=L.calcViewportBoundaries((i==null?void 0:i.pointList)||[],this.isCurve,p,this.zoom);this.updateStatus(1),this.setActiveLine(i.pointList),this.setSelectedLineID(i.id),this.activeArea=e,this.updateLineAttributes(i)}this.render()}setActiveLine(t){this.activeLine=t?g.cloneDeep(t):void 0}historyChanged(t){const i=`${t}Enabled`;if(this.isCreate){if(this.actionsHistory&&this.actionsHistory[i]){const e=this.actionsHistory&&this.actionsHistory[t]();this.setActiveLine(e),this.render()}return}if(this.history&&this.history[i]){const e=this.history[t](),s=e==null?void 0:e.find(n=>n.id===this.selectedID);this.lineList=e,this.selectedID&&s?this.setActiveLine(s==null?void 0:s.pointList):this.setNoneStatus(),this.render()}this.emit("dataUpdated",this.lineList)}undo(){this.historyChanged("undo"),this.updateSelectedAttributeAfterHistoryChanged()}redo(){this.historyChanged("redo"),this.updateSelectedAttributeAfterHistoryChanged()}isCoordInsideTarget(t){if(this.isDependPolygon)return this.isInBasicPolygon(t);if(this.isDependRect){const{x:i,y:e,width:s,height:n}=this.basicResult,r=[i,i+s],o=[e,e+n];return L.isInRange(t.x,r)&&L.isInRange(t.y,o)}return L.isInRange(t.x,[0,this.imageSize.width])&&L.isInRange(t.y,[0,this.imageSize.height])}getPointInsertIndex(t,i){if(t&&this.activeLine){const e=this.getPointList(this.activeLine);return this.activeLine.length===2?1:this.activeLine.findIndex((s,n)=>{if(n>0){const r=this.activeLine?this.activeLine[n-1]:void 0,o=this.isCurve?e.slice((n-1)*(p+1),n*(p+1)):[r,s];return this.pointInLine(o,t,i||this.getLineWidthScope())}return!1})}return-1}getLineWidthScope(){return this.lineStyle.lineWidth}isMouseCoordOutsideActiveArea(){return!this.coordsInsideActiveArea&&!this.selectedPoint}isLinePointsExceed(){return this.isCreate&&this.activeLine&&this.upperLimitPointNum&&~~this.upperLimitPointNum<=this.activeLine.length}isLinePointsNotEnough(){var t;return this.activeLine&&((t=this.activeLine)==null?void 0:t.length)<this.lowerLimitPointNum}updateLineSegmentSpecial(t){const i=this.getPointInsertIndex(t,2)-1;if(i>-1){const e=this.activeLine[i];e.specialEdge=!e.specialEdge,this.hoverLineSegmentIndex=-1,this.render()}}addLinePointToActiveLine(){var t;const i=this.getPointInsertIndex(this.cursor),e=this.pointsWithinRange(this.activeLine.length+1);this.cursor&&i>-1&&e&&(this.activeLine.splice(i,0,T(_({},this.coordUtils.getAbsCoord(this.cursor)),{id:S()})),this.updateLines(),(t=this.history)==null||t.pushHistory(this.lineList),this.render(),this.cursor=void 0)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return;const i=this.getCoordinate(t);if(this.isMousedown=!0,this.prevAxis=i,t.which===3){this.cursor=void 0;return}this.selectedPoint=this.findHoveredPoint(i),this.coordsInsideActiveArea=this.isActive&&this.activeArea?u.inArea(this.activeArea,this.coordUtils.getAbsCoord(i)):!1,this.lineDragging=!1}lineHasChanged(){const t=this.lineList.find(i=>i.id===this.selectedID);return t?JSON.stringify(t.pointList)!==JSON.stringify(this.activeLine):!1}updateLines(){const t=this.lineList.find(i=>i.id===this.selectedID);t&&(t.pointList=g.cloneDeep(this.activeLine),this.updatedLine=t,this.emit("dataUpdated",this.lineList))}onMouseUp(t){const i=()=>{this.isMousedown=!1,this.hoverPointID=void 0,this.cursor=void 0,this.selectedPoint=void 0};if(this.hoverPointID=void 0,super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo){i();return}t.which===1&&this.onLeftClick(t),t.which===3&&this.onRightClick(t),i()}isTextValid(t){return b.textAttributeValidate(this.textCheckType,this.customFormat,t)}createLineData(){const t=S(),i={pointList:g.cloneDeep(this.activeLine),id:t,valid:this.isLineValid,order:this.nextOrder()};return i.attribute=this.defaultAttribute,i}stopLineCreating(t=!0){var i,e,s,n;const r=this.selectedID?!0:!!this.isTextConfigurable;let o;if(t){if(this.selectedID){const h=this.lineList.find(a=>a.id===this.selectedID);o=this.selectedID,h&&(h.pointList=g.cloneWith(this.activeLine),g.isEqual(h.pointList,(i=this.history)==null?void 0:i.pushHistory(this.lineList))||(e=this.history)==null||e.pushHistory(this.lineList))}else if(this.isCreate&&this.activeLine&&this.activeLine.length>1){const h=this.createLineData();o=h.id,this.setLineList([...this.lineList,h]),this.emit("lineCreated",h,this.zoom,this.currentPos),(s=this.history)==null||s.pushHistory(this.lineList)}}r?this.setActiveStatus(o):this.setNoneStatus(),(n=this.actionsHistory)==null||n.empty(),this.emit("dataUpdated",this.lineList),this.render()}setActiveStatus(t){const i=t?this.lineList.find(e=>e.id===t):void 0;if(i){const e=i==null?void 0:i.pointList;this.updateStatus(1),this.setActiveLine(e),this.setSelectedLineID(t)}else this.setNoneStatus()}setNoneStatus(t=!0){t&&this.updateStatus(2),this.activeLine=[],this.setSelectedLineID(void 0),this.activeArea=void 0,this.isLineValid=!0,this.cursor=void 0}setKeyDownStatus(t,i){this.isShift=i!=null?i:t.keyCode===f.Shift}continueToEdit(){var t;this.updateStatus(0),this.cursor=void 0,(t=this.actionsHistory)==null||t.pushHistory(this.activeLine),this.render()}setInvalidLineOnCreating(t){if(this.selectedID&&t.keyCode!==f.Ctrl||!this.isCreate)return;const i=!t.ctrlKey;this.selectedID?this.setInvalidLine(this.selectedID,i,!1):this.isLineValid=i}onKeyDown(t){if(super.onKeyDown(t),this.setKeyDownStatus(t),t.keyCode===f.Z&&!t.ctrlKey&&this.toggleIsHide(),t.keyCode===f.Shift&&this.render(),t.keyCode===f.Tab){t.preventDefault(),this.selectToNextLine(t);return}if(this.isCreate&&this.keyboardEventWhileLineCreating(t),this.config.attributeConfigurable){const i=b.getAttributeByKeycode(t.keyCode,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}}selectToNextLine(t){const i=z.getNextSelectedRectIDByEvent(this.viewPortLines.map(e=>{var s,n,r,o;return T(_({},e),{x:(n=(s=e.pointList[0])==null?void 0:s.x)!=null?n:0,y:(o=(r=e.pointList[0])==null?void 0:r.y)!=null?o:0})}),t,this.selectedID);i&&this.setActiveLineByID(i.id)}keyboardEventWhileLineCreating(t){!this.isCreate||(t.keyCode===f.Ctrl&&this.setInvalidLineOnCreating(t),[f.Shift,f.Alt].includes(t.keyCode)&&this.renderNextPoint(t,this.prevAxis))}renderNextPoint(t,i){const e=this.coordUtils.getRenderCoord(this.getNextPoint(t,i));this.render(e)}deleteSelectedLine(t){const i=L.calcViewportBoundaries(this.activeLine,this.isCurve,p,this.zoom);u.inArea(i,this.coordUtils.getAbsCoord(t))&&this.deleteLine()}deleteSelectedLinePoint(t){var i;this.pointsWithinRange(this.activeLine.length-1)&&t&&(this.setActiveLine(this.activeLine.filter(s=>s.id!==t)),this.updateLines(),(i=this.history)==null||i.pushHistory(this.lineList)),this.cursor=void 0,this.render()}deleteLine(){var t;this.lineList=this.lineList.filter(i=>i.id!==this.selectedID),(t=this.history)==null||t.pushHistory(this.lineList),this.setNoneStatus(),this.emit("dataUpdated",this.lineList),this.emit("lineDeleted",this.selectedID),this.render()}setInvalidLine(t,i,e=!0){var s;const n=this.lineList.find(r=>r.id===t);n&&(n.valid=i!==void 0?i:!n.valid,(s=this.history)==null||s.pushHistory(this.lineList),e&&this.render())}empty(){var t,i;this.lineList=[],this.setNoneStatus(),this.selectedPoint=void 0,(t=this.actionsHistory)==null||t.empty(),(i=this.history)==null||i.init(),this.emit("dataUpdated",this.lineList),this.render()}setAttribute(t){var i;this.attributeConfigurable&&(this.defaultAttribute=t,this.setLineAttribute("attribute",t),this.selectedID&&((i=this.history)==null||i.pushHistory(this.lineList)))}setTextAttribute(t){var i;this.isTextConfigurable&&(this.setLineAttribute("textAttribute",t),(i=this.history)==null||i.applyAttribute(this.selectedID,"textAttribute",t))}setLineAttribute(t,i,e){const s=e||this.selectedID;if(s){const n=this.lineList.find(r=>r.id===s);n&&(n[t]=i)}this.render()}updateAttribute(t){this.emit("updateAttribute",t)}updateLineAttributes(t){var i;if(this.attributeConfigurable&&t){const e=(t==null?void 0:t.attribute)||"";this.defaultAttribute=e,this.updateAttribute(e)}if(this.isTextConfigurable&&t){const e=(t==null?void 0:t.textAttribute)||"";this.updateTextAttribute(e)}(i=this.history)==null||i.updateHistory(this.lineList)}lineStatusChanged(){this.emit("lineStatusChanged",{status:this.status,selectedLineID:this.selectedID})}updateTextAttribute(t){if(this.selectedID){const i=this.lineList.find(e=>e.id===this.selectedID);i&&(i.textAttribute=t)}this.emit("updateText",t)}saveData(){this.stopLineCreating(),this.setNoneStatus(),this.render()}setTextEditingID(t){this.textEditingID=t,this.render()}setSelectedLineID(t){var i,e;if(this.selectedID===t)return;const s=this.selectedID;t!==s&&s&&((i=this._textAttributeInstance)==null||i.changeSelected()),t||(e=this._textAttributeInstance)==null||e.clearTextAttribute(),this.selectedID=t,this.emit("selectedChange")}attributeLockListChange(t){this.attributeLockList=t,this.render()}setResult(t){this.setNoneStatus(),this.setLineList(t),this.render()}setConfig(t){super.setConfig(t)}toggleIsHide(){this.setIsHidden(!this.isHidden),this.render()}clearCanvas(){super.clearCanvas()}clearResult(){this.setResult([]),this.setSelectedLineID(void 0),this.render()}exportData(){return[this.lineList,this.basicImgInfo]}setDefaultAttribute(t=""){var i;this.attributeConfigurable&&(this.defaultAttribute=t,this.changeStyle(this.defaultAttribute),this.setLineAttribute("attribute",t),this.selectedID&&((i=this.history)==null||i.pushHistory(this.lineList)),this.emit("changeAttributeSidebar"))}getCurrentSelectedData(){var t,i;const e=this.isActiveLineValid(),s=this.defaultAttribute,n=this.getColor(s),r=e?n==null?void 0:n.valid.stroke:n==null?void 0:n.invalid.stroke,o=(i=(t=this.lineList.find(h=>h.id===this.selectedID))==null?void 0:t.textAttribute)!=null?i:"";return{color:r,textAttribute:o}}renderTextAttribute(){var t,i,e,s;if(!this.ctx||!this.activeLine||((t=this.activeLine)==null?void 0:t.length)<2||this.isCreate)return;const n=this.isActiveLineValid(),r=this.defaultAttribute,{x:o,y:h}=this.activeLine[1],a=this.coordUtils.getRenderCoord({x:o,y:h}),l=this.getColor(r),c=n?l==null?void 0:l.valid.stroke:l==null?void 0:l.invalid.stroke,v=(e=(i=this.lineList.find(A=>A.id===this.selectedID))==null?void 0:i.textAttribute)!=null?e:"";this._textAttributeInstance||(this._textAttributeInstance=new $({container:this.container,icon:this.getTextIconSvg(r),color:c,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((s=this._textAttributeInstance)==null?void 0:s.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${v}`,{left:a.x,top:a.y,color:c}),this._textAttributeInstance.updateIcon(this.getTextIconSvg(r))}getTextIconSvg(t=""){return b.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let i=t;!b.textAttributeValidate(this.config.textCheckType,"",i)&&(this.emit("messageError",b.getErrorNotice(this.config.textCheckType,this.lang)),i=""),this.setTextAttribute(i),this.emit("updateTextAttribute"),this.render()}}}export{H as INNER_POINT_RADIUS,C as LINE_ORDER_OFFSET,x as POINT_ACTIVE_RADIUS,m as POINT_RADIUS,p as SEGMENT_NUMBER,tt as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import $ from"lodash";import M from"color-rgba";import h from"../../utils/tool/DrawUtils.js";import _ from"../../utils/tool/AxisUtils.js";import W from"../../utils/tool/RectUtils.js";import E from"../../utils/tool/PolygonUtils.js";import O from"../../utils/MathUtils.js";import Z from"../../utils/tool/RenderDomClass.js";import{ELineTypes as L,DEFAULT_FONT as j,SEGMENT_NUMBER as U}from"../../constant/tool.js";import{DEFAULT_TEXT_OFFSET as F,TEXT_ATTRIBUTE_OFFSET as A,DEFAULT_TEXT_SHADOW as H}from"../../constant/annotation.js";import N from"../../utils/tool/ImgPosUtils.js";import{BasicToolOperation as K}from"./basicToolOperation.js";import{pointCloudLidar2image as V}from"../pointCloud/matrix.js";import X from"../../utils/tool/AttributeUtils.js";import{getCuboidTextAttributeOffset as G}from"../../utils/tool/CuboidUtils.js";var Y=Object.defineProperty,q=Object.defineProperties,J=Object.getOwnPropertyDescriptors,B=Object.getOwnPropertySymbols,Q=Object.prototype.hasOwnProperty,tt=Object.prototype.propertyIsEnumerable,z=(w,t,e)=>t in w?Y(w,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):w[t]=e,v=(w,t)=>{for(var e in t||(t={}))Q.call(t,e)&&z(w,e,t[e]);if(B)for(var e of B(t))tt.call(t,e)&&z(w,e,t[e]);return w},S=(w,t)=>q(w,J(t));const et=3,ot=3,I="#6371FF";class nt extends K{constructor(t){super(S(v({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.connectionPoints=[],this.getHoverRectID=o=>{var r,a;const c=this.getCoordinateUnderZoom(o),n=_.changePointByZoom(c,1/this.zoom);if(((r=this.annotations)==null?void 0:r.length)<=0||!((a=this.annotations)==null?void 0:a.length))return;let d="",i=Number.MAX_SAFE_INTEGER;for(let l=0;l<this.annotations.length;l++){const s=this.annotations[l];switch(s.type){case"rect":{const u=s.annotation;if(W.isInRect(c,u,et,this.zoom)){const f=u.width*u.height;f<i&&(d=u.id,i=f)}break}case"polygon":{const u=s.annotation;if(E.isInPolygon(n,u.pointList)){const f=E.getPolygonArea(u.pointList);f<i&&(d=u.id,i=f)}break}}}return d};var e;this.style=(e=t.style)!=null?e:{stroke:I,thickness:3},this.annotations=t.annotations,this.loading=!1,this.renderDomInstance=new Z({container:this.container,height:this.canvas.height})}clearConnectionPoints(){this.connectionPoints=[],this.render()}checkConnectionPoints(t=this.annotations){var e,o;this.connectPointsStatus&&((o=(e=this.connectPointsStatus).close)==null||o.call(e)),this.emit("connectionPointsStatusUpdate",()=>new Promise(r=>{const{promise:a,close:c}=O.getCollectionPointByAnnotationDataPromise(t);this.connectPointsStatus={close:c},a.then(n=>{this.connectionPoints=n.connectionPoints,this.render(),this.connectPointsStatus=void 0,r({connectionPoints:n.connectionPoints})})}))}setLoading(t){this.loading=t,this.render()}onMouseLeave(){super.onMouseLeave(),this.mouseHoverID=void 0,this.emit("onChange","hover",[])}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return!0;const e=this.mouseHoverID;if(t.button===0){let o=[];e&&(o=[e]),this.emit("onChange","selected",o),this.render()}}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.mouseHoverID,o=this.getHoverRectID(t);if(e!==o){this.mouseHoverID=o;let r=[];o&&(r=[o]),this.emit("onChange","hover",r),this.render()}}updateData(t){this.annotations=t,this.render()}getSpecificStyle(t){const e=$.pick(t,["stroke","thickness","fill","radius"]),o=v(v({},this.style),e);return o.stroke&&Object.assign(o,{color:o.stroke}),o}getFontStyle(t,e){var o,r;const a=(o=t==null?void 0:t.fontSize)!=null?o:14,c=(r=t==null?void 0:t.fontFamily)!=null?r:"Arial";return S(v({},H),{color:e.stroke,font:`normal normal 600 ${a}px ${c}`})}appendOffset({x:t,y:e}){return{x:t+F.offsetX,y:e+F.offsetY}}getRenderText(t,e=!1){let o="",r="";return!t||e===!0?{headerText:o,bottomText:r}:((t==null?void 0:t.order)&&(o=`${t.order}`),(t==null?void 0:t.label)&&(o?o=`${o}_${t.label}`:o=`${t.label}`),(t==null?void 0:t.attribute)&&(o?o=`${o} ${t.attribute}`:o=`${t.attribute}`),(t==null?void 0:t.textAttribute)&&(r=t==null?void 0:t.textAttribute),{headerText:o,bottomText:r})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){const e=O.calcViewportBoundaries(t),o={x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top},r=N.getBasicRecPos(this.imgNode,o,this.size,.5);if(r){this.setCurrentPos(r.currentPos),this.setCurrentPosStorage(r.currentPos);const{imgInfo:a}=this,{innerZoom:c}=this.innerPosAndZoom;a&&this.setImgInfo(S(v({},a),{width:a.width/c*r.innerZoom,height:a.height/c*r.innerZoom})),this.setZoom(r.innerZoom),this.render(),this.renderBasicCanvas()}}renderConnectionPoints(){this.connectionPoints.forEach(t=>{const e=_.changePointByZoom(t,this.zoom,this.currentPos);h.drawCircleWithFill(this.canvas,e,4,{color:"#fff"}),h.drawCircleWithFill(this.canvas,e,2,{color:"#000"})})}getRenderStyle(t){const e=this.getSpecificStyle(t.annotation),o=this.getFontStyle(t.annotation,e);return{style:e,fontStyle:o}}renderLine(t){var e,o,r;if(t.type!=="line")return;const{style:a,fontStyle:c}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=2))return;const{lineType:d=L.Line}=n,i=_.changePointListByZoom((o=n==null?void 0:n.pointList)!=null?o:[],this.zoom,this.currentPos),l=S(v(v({},a),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:d,strokeColor:a.stroke});let s=[];if(n.showKeyPoint?s=h.drawPolygonWithKeyPoint(this.canvas,i,l):s=h.drawPolygon(this.canvas,i,l),(n==null?void 0:n.showDirection)===!0&&((r=n==null?void 0:n.pointList)==null?void 0:r.length)>=2){let g=i[0],y=O.getLineCenterPoint([i[0],i[1]]);if(d===L.Curve){const p=Math.floor(U/2);g=s[p],y=s[p+1]}h.drawArrowByCanvas(this.canvas,g,y,{color:a.stroke,thickness:a.thickness}),h.drawCircle(this.canvas,i[0],a.thickness+6,{color:a.stroke,thickness:a.thickness})}const{headerText:f,bottomText:m}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(f&&h.drawText(this.canvas,this.appendOffset(i[0]),f,c),m){const g=i[i.length-1];h.drawText(this.canvas,this.appendOffset({x:g.x+A.x,y:g.y+A.y}),m,c)}}renderPolygon(t){var e,o,r,a,c;if(t.type!=="polygon")return;const{style:n,fontStyle:d}=this.getRenderStyle(t),i=t.annotation;if(!(((e=i==null?void 0:i.pointList)==null?void 0:e.length)>=3))return;const{lineType:l=L.Line}=i,s=_.changePointListByZoom((o=i==null?void 0:i.pointList)!=null?o:[],this.zoom,this.currentPos);if(i.id===this.mouseHoverID||n.fill){const p=M((a=(r=n==null?void 0:n.fill)!=null?r:n==null?void 0:n.stroke)!=null?a:I),x=`rgba(${p[0]}, ${p[1]}, ${p[2]},${p[3]*.8})`;h.drawPolygonWithFill(this.canvas,s,{color:x,lineType:l})}const u=S(v(S(v({},n),{isClose:!0}),this.getReferenceOptions(i==null?void 0:i.isReference)),{lineType:l,strokeColor:n.stroke});let f=[];if(i.showKeyPoint?f=h.drawPolygonWithKeyPoint(this.canvas,s,u):f=h.drawPolygon(this.canvas,s,u),(i==null?void 0:i.showDirection)===!0&&((c=i==null?void 0:i.pointList)==null?void 0:c.length)>=2){let p=s[0],x=O.getLineCenterPoint([s[0],s[1]]);if(l===L.Curve){const P=Math.floor(U/2);p=f[P],x=f[P+1]}h.drawArrowByCanvas(this.canvas,p,x,{color:n.stroke,thickness:n.thickness}),h.drawCircle(this.canvas,s[0],n.thickness+6,{color:n.stroke,thickness:n.thickness})}const{headerText:g,bottomText:y}=this.getRenderText(i,i==null?void 0:i.hiddenText);if(g&&h.drawText(this.canvas,this.appendOffset(s[0]),g,d),y){const p=s[s.length-1];h.drawText(this.canvas,this.appendOffset({x:p.x+A.x,y:p.y+A.y}),y,d)}}renderSingleCuboid(t){var e,o,r,a;const{style:c}=this.getRenderStyle(t),n=t.annotation,d=M((o=(e=c==null?void 0:c.fill)!=null?e:c==null?void 0:c.stroke)!=null?o:I),i=`rgba(${d[0]}, ${d[1]}, ${d[2]},${d[3]*.8})`,l=c.stroke,s=_.changeCuboidByZoom(n,this.zoom,this.currentPos),u=l,{headerText:f,bottomText:m}=this.getRenderText(n,n==null?void 0:n.hiddenText),{backPoints:g,frontPoints:y,textAttribute:p}=s,x=y.br.x-y.bl.x;h.drawCuboid(this.canvas,s,{strokeColor:l,fillColor:i,thickness:c.thickness});let P="";((r=this.config)==null?void 0:r.isShowOrder)&&s.order&&(s==null?void 0:s.order)>0&&(P=`${s.order}`),s.attribute&&(P=`${P} ${X.getAttributeShowText(s.attribute,(a=this.config)==null?void 0:a.attributeList)}`),f&&g&&h.drawText(this.canvas,{x:g.tl.x,y:g.tl.y-5},P,{color:l,textMaxWidth:300});const b=G({cuboid:n,currentPos:this.currentPos,zoom:this.zoom,topOffset:16,leftOffset:0});if(m){const C=Math.max(20,x*.8);h.drawText(this.canvas,{x:b.left,y:b.top},p,{color:u,textMaxWidth:C})}}renderBox3d(t){if(t.type!=="box3d")return;const e=t.annotation,o=V(e,e.calib),r={fill:"transparent"},a=$.pick(e,["stroke","thickness"]);o.forEach((c,n)=>{const d=v(S(v({},a),{id:`${t.annotation.id}-${n}`,pointList:c.pointList}),r);switch(c.type){case"line":this.renderLine({type:"line",annotation:d});break;case"polygon":this.renderPolygon({type:"polygon",annotation:d});break}})}render(){try{if(super.render(),this.loading===!0)return;const t=this.annotations.filter(e=>e.type==="text"&&e.annotation.position==="rt").map(e=>e.annotation);this.renderDomInstance.render(t),this.annotations.forEach(e=>{var o,r,a,c,n;const d=this.getSpecificStyle(e.annotation),i=this.getFontStyle(e.annotation,d);switch(e.type){case"rect":{const l=e.annotation,{hiddenText:s=!1,isReference:u,hiddenRectSize:f=!1}=l,{zoom:m}=this,g=_.changeRectByZoom(l,this.zoom,this.currentPos),{x:y,y:p,width:x,height:P}=g;if(l.id===this.mouseHoverID||d.fill){const T=M((r=(o=d==null?void 0:d.fill)!=null?o:d==null?void 0:d.stroke)!=null?r:I),D=`rgba(${T[0]}, ${T[1]}, ${T[2]},${T[3]*.8})`;h.drawRectWithFill(this.canvas,g,{color:D})}h.drawRect(this.canvas,g,v(S(v({},d),{hiddenText:!0}),this.getReferenceOptions(u)));const{headerText:b,bottomText:C}=this.getRenderText(l,l==null?void 0:l.hiddenText);b&&h.drawText(this.canvas,{x:y,y:p-6},b,v({textMaxWidth:300},i));const k=`${Math.round(x/m)} * ${Math.round(P/m)}`,R=k.length*7;if(!s&&!f&&h.drawText(this.canvas,{x:y+x-R,y:p+P+15},k,i),C){const T=20,D=Math.max(20,x-R);h.drawText(this.canvas,{x:y,y:p+P+T},l.textAttribute,v({textMaxWidth:D},i))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const l=e.annotation,s=_.changePointByZoom(l,this.zoom,this.currentPos),u=(a=d.radius)!=null?a:ot;h.drawCircle(this.canvas,s,u,d);const{headerText:f,bottomText:m}=this.getRenderText(l,l==null?void 0:l.hiddenText);f&&h.drawText(this.canvas,{x:s.x+u/2,y:s.y-u-4},f,v({textAlign:"center"},i)),m&&h.drawText(this.canvas,this.appendOffset({x:s.x+u,y:s.y+u+24}),m,i);break}case"text":{const l=e.annotation,{text:s,x:u,y:f,textMaxWidth:m,color:g="white",background:y="rgba(0, 0, 0, 0.6)",lineHeight:p=25,font:x=j,position:P}=l,b=10,C=10,k=_.changePointByZoom({x:u,y:f},this.zoom,this.currentPos),{width:R,height:T,fontHeight:D=0}=O.getTextArea(this.canvas,l.text,m,x,p);if(P==="rt")break;h.drawRectWithFill(this.canvas,{x:k.x,y:k.y,width:R+C*2,height:T+b*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:y}),h.drawText(this.canvas,{x:k.x+C,y:k.y+D+b},s,{color:g,lineHeight:p,font:x,textMaxWidth:m});break}case"box3d":{this.renderBox3d(e);break}case"cuboid":{this.renderSingleCuboid(e);break}default:break}(n=(c=e.annotation)==null?void 0:c.renderEnhance)==null||n.call(c,{ctx:this.ctx,canvas:this.canvas,currentPos:this.currentPos,zoom:this.zoom,data:e,toolInstance:this})}),this.renderConnectionPoints()}catch(t){console.error("ViewOperation Render Error",t)}}}export{nt as default};
|
|
1
|
+
import M from"lodash";import E from"color-rgba";import h from"../../utils/tool/DrawUtils.js";import b from"../../utils/tool/AxisUtils.js";import Z from"../../utils/tool/RectUtils.js";import $ from"../../utils/tool/PolygonUtils.js";import C from"../../utils/MathUtils.js";import W from"../../utils/tool/RenderDomClass.js";import{ELineTypes as L,DEFAULT_FONT as j,SEGMENT_NUMBER as F}from"../../constant/tool.js";import{DEFAULT_TEXT_OFFSET as B,TEXT_ATTRIBUTE_OFFSET as A,DEFAULT_TEXT_SHADOW as H}from"../../constant/annotation.js";import N from"../../utils/tool/ImgPosUtils.js";import{BasicToolOperation as K}from"./basicToolOperation.js";import{pointCloudLidar2image as V}from"../pointCloud/matrix.js";var X=Object.defineProperty,G=Object.defineProperties,Y=Object.getOwnPropertyDescriptors,U=Object.getOwnPropertySymbols,q=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable,z=(P,t,e)=>t in P?X(P,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):P[t]=e,p=(P,t)=>{for(var e in t||(t={}))q.call(t,e)&&z(P,e,t[e]);if(U)for(var e of U(t))J.call(t,e)&&z(P,e,t[e]);return P},_=(P,t)=>G(P,Y(t));const Q=3,tt=3,I="#6371FF";class et extends K{constructor(t){super(_(p({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.connectionPoints=[],this.getHoverRectID=o=>{var i,r;const c=this.getCoordinateUnderZoom(o),n=b.changePointByZoom(c,1/this.zoom);if(((i=this.annotations)==null?void 0:i.length)<=0||!((r=this.annotations)==null?void 0:r.length))return;let d="",s=Number.MAX_SAFE_INTEGER;for(let l=0;l<this.annotations.length;l++){const a=this.annotations[l];switch(a.type){case"rect":{const u=a.annotation;if(Z.isInRect(c,u,Q,this.zoom)){const f=u.width*u.height;f<s&&(d=u.id,s=f)}break}case"polygon":{const u=a.annotation;if($.isInPolygon(n,u.pointList)){const f=$.getPolygonArea(u.pointList);f<s&&(d=u.id,s=f)}break}}}return d};var e;this.style=(e=t.style)!=null?e:{stroke:I,thickness:3},this.annotations=t.annotations,this.loading=!1,this.renderDomInstance=new W({container:this.container,height:this.canvas.height})}clearConnectionPoints(){this.connectionPoints=[],this.render()}checkConnectionPoints(t=this.annotations){var e,o;this.connectPointsStatus&&((o=(e=this.connectPointsStatus).close)==null||o.call(e)),this.emit("connectionPointsStatusUpdate",()=>new Promise(i=>{const{promise:r,close:c}=C.getCollectionPointByAnnotationDataPromise(t);this.connectPointsStatus={close:c},r.then(n=>{this.connectionPoints=n.connectionPoints,this.render(),this.connectPointsStatus=void 0,i({connectionPoints:n.connectionPoints})})}))}setLoading(t){this.loading=t,this.render()}onMouseLeave(){super.onMouseLeave(),this.mouseHoverID=void 0,this.emit("onChange","hover",[])}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return!0;const e=this.mouseHoverID;if(t.button===0){let o=[];e&&(o=[e]),this.emit("onChange","selected",o),this.render()}}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.mouseHoverID,o=this.getHoverRectID(t);if(e!==o){this.mouseHoverID=o;let i=[];o&&(i=[o]),this.emit("onChange","hover",i),this.render()}}updateData(t){this.annotations=t,this.render()}getSpecificStyle(t){const e=M.pick(t,["stroke","thickness","fill","radius"]),o=p(p({},this.style),e);return o.stroke&&Object.assign(o,{color:o.stroke}),o}getFontStyle(t,e){var o,i;const r=(o=t==null?void 0:t.fontSize)!=null?o:14,c=(i=t==null?void 0:t.fontFamily)!=null?i:"Arial";return _(p({},H),{color:e.stroke,font:`normal normal 600 ${r}px ${c}`})}appendOffset({x:t,y:e}){return{x:t+B.offsetX,y:e+B.offsetY}}getRenderText(t,e=!1){let o="",i="";return!t||e===!0?{headerText:o,bottomText:i}:((t==null?void 0:t.order)&&(o=`${t.order}`),(t==null?void 0:t.label)&&(o?o=`${o}_${t.label}`:o=`${t.label}`),(t==null?void 0:t.attribute)&&(o?o=`${o} ${t.attribute}`:o=`${t.attribute}`),(t==null?void 0:t.textAttribute)&&(i=t==null?void 0:t.textAttribute),{headerText:o,bottomText:i})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){const e=C.calcViewportBoundaries(t),o={x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top},i=N.getBasicRecPos(this.imgNode,o,this.size,.5);if(i){this.setCurrentPos(i.currentPos),this.setCurrentPosStorage(i.currentPos);const{imgInfo:r}=this,{innerZoom:c}=this.innerPosAndZoom;r&&this.setImgInfo(_(p({},r),{width:r.width/c*i.innerZoom,height:r.height/c*i.innerZoom})),this.setZoom(i.innerZoom),this.render(),this.renderBasicCanvas()}}renderConnectionPoints(){this.connectionPoints.forEach(t=>{const e=b.changePointByZoom(t,this.zoom,this.currentPos);h.drawCircleWithFill(this.canvas,e,4,{color:"#fff"}),h.drawCircleWithFill(this.canvas,e,2,{color:"#000"})})}getRenderStyle(t){const e=this.getSpecificStyle(t.annotation),o=this.getFontStyle(t.annotation,e);return{style:e,fontStyle:o}}renderLine(t){var e,o,i;if(t.type!=="line")return;const{style:r,fontStyle:c}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=2))return;const{lineType:d=L.Line}=n,s=b.changePointListByZoom((o=n==null?void 0:n.pointList)!=null?o:[],this.zoom,this.currentPos),l=_(p(p({},r),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:d,strokeColor:r.stroke});let a=[];if(n.showKeyPoint?a=h.drawPolygonWithKeyPoint(this.canvas,s,l):a=h.drawPolygon(this.canvas,s,l),(n==null?void 0:n.showDirection)===!0&&((i=n==null?void 0:n.pointList)==null?void 0:i.length)>=2){let v=s[0],m=C.getLineCenterPoint([s[0],s[1]]);if(d===L.Curve){const g=Math.floor(F/2);v=a[g],m=a[g+1]}h.drawArrowByCanvas(this.canvas,v,m,{color:r.stroke,thickness:r.thickness}),h.drawCircle(this.canvas,s[0],r.thickness+6,{color:r.stroke,thickness:r.thickness})}const{headerText:f,bottomText:y}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(f&&h.drawText(this.canvas,this.appendOffset(s[0]),f,c),y){const v=s[s.length-1];h.drawText(this.canvas,this.appendOffset({x:v.x+A.x,y:v.y+A.y}),y,c)}}renderPolygon(t){var e,o,i,r,c;if(t.type!=="polygon")return;const{style:n,fontStyle:d}=this.getRenderStyle(t),s=t.annotation;if(!(((e=s==null?void 0:s.pointList)==null?void 0:e.length)>=3))return;const{lineType:l=L.Line}=s,a=b.changePointListByZoom((o=s==null?void 0:s.pointList)!=null?o:[],this.zoom,this.currentPos);if(s.id===this.mouseHoverID||n.fill){const g=E((r=(i=n==null?void 0:n.fill)!=null?i:n==null?void 0:n.stroke)!=null?r:I),x=`rgba(${g[0]}, ${g[1]}, ${g[2]},${g[3]*.8})`;h.drawPolygonWithFill(this.canvas,a,{color:x,lineType:l})}const u=_(p(_(p({},n),{isClose:!0}),this.getReferenceOptions(s==null?void 0:s.isReference)),{lineType:l,strokeColor:n.stroke});let f=[];if(s.showKeyPoint?f=h.drawPolygonWithKeyPoint(this.canvas,a,u):f=h.drawPolygon(this.canvas,a,u),(s==null?void 0:s.showDirection)===!0&&((c=s==null?void 0:s.pointList)==null?void 0:c.length)>=2){let g=a[0],x=C.getLineCenterPoint([a[0],a[1]]);if(l===L.Curve){const w=Math.floor(F/2);g=f[w],x=f[w+1]}h.drawArrowByCanvas(this.canvas,g,x,{color:n.stroke,thickness:n.thickness}),h.drawCircle(this.canvas,a[0],n.thickness+6,{color:n.stroke,thickness:n.thickness})}const{headerText:v,bottomText:m}=this.getRenderText(s,s==null?void 0:s.hiddenText);if(v&&h.drawText(this.canvas,this.appendOffset(a[0]),v,d),m){const g=a[a.length-1];h.drawText(this.canvas,this.appendOffset({x:g.x+A.x,y:g.y+A.y}),m,d)}}renderSingleCuboid(t){var e,o;const{style:i}=this.getRenderStyle(t),r=t.annotation,c=E((o=(e=i==null?void 0:i.fill)!=null?e:i==null?void 0:i.stroke)!=null?o:I),n=`rgba(${c[0]}, ${c[1]}, ${c[2]},${c[3]*.8})`,d=i.stroke,s=b.changeCuboidByZoom(r,this.zoom,this.currentPos),{headerText:l,bottomText:a}=this.getRenderText(r,r==null?void 0:r.hiddenText);h.drawCuboidWithText(this.canvas,s,{strokeColor:d,fillColor:n,thickness:i.thickness},{config:this.config,hiddenText:r==null?void 0:r.hiddenText,headerText:l,bottomText:a})}renderBox3d(t){if(t.type!=="box3d")return;const e=t.annotation,o=V(e,e.calib),i={fill:"transparent"},r=M.pick(e,["stroke","thickness"]);o.forEach((c,n)=>{const d=p(_(p({},r),{id:`${t.annotation.id}-${n}`,pointList:c.pointList}),i);switch(c.type){case"line":this.renderLine({type:"line",annotation:d});break;case"polygon":this.renderPolygon({type:"polygon",annotation:d});break}})}render(){try{if(super.render(),this.loading===!0)return;const t=this.annotations.filter(e=>e.type==="text"&&e.annotation.position==="rt").map(e=>e.annotation);this.renderDomInstance.render(t),this.annotations.forEach(e=>{var o,i,r,c,n;const d=this.getSpecificStyle(e.annotation),s=this.getFontStyle(e.annotation,d);switch(e.type){case"rect":{const l=e.annotation,{hiddenText:a=!1,isReference:u,hiddenRectSize:f=!1}=l,{zoom:y}=this,v=b.changeRectByZoom(l,this.zoom,this.currentPos),{x:m,y:g,width:x,height:w}=v;if(l.id===this.mouseHoverID||d.fill){const T=E((i=(o=d==null?void 0:d.fill)!=null?o:d==null?void 0:d.stroke)!=null?i:I),D=`rgba(${T[0]}, ${T[1]}, ${T[2]},${T[3]*.8})`;h.drawRectWithFill(this.canvas,v,{color:D})}h.drawRect(this.canvas,v,p(_(p({},d),{hiddenText:!0}),this.getReferenceOptions(u)));const{headerText:S,bottomText:R}=this.getRenderText(l,l==null?void 0:l.hiddenText);S&&h.drawText(this.canvas,{x:m,y:g-6},S,p({textMaxWidth:300},s));const k=`${Math.round(x/y)} * ${Math.round(w/y)}`,O=k.length*7;if(!a&&!f&&h.drawText(this.canvas,{x:m+x-O,y:g+w+15},k,s),R){const T=20,D=Math.max(20,x-O);h.drawText(this.canvas,{x:m,y:g+w+T},l.textAttribute,p({textMaxWidth:D},s))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const l=e.annotation,a=b.changePointByZoom(l,this.zoom,this.currentPos),u=(r=d.radius)!=null?r:tt;h.drawCircle(this.canvas,a,u,d);const{headerText:f,bottomText:y}=this.getRenderText(l,l==null?void 0:l.hiddenText);f&&h.drawText(this.canvas,{x:a.x+u/2,y:a.y-u-4},f,p({textAlign:"center"},s)),y&&h.drawText(this.canvas,this.appendOffset({x:a.x+u,y:a.y+u+24}),y,s);break}case"text":{const l=e.annotation,{text:a,x:u,y:f,textMaxWidth:y,color:v="white",background:m="rgba(0, 0, 0, 0.6)",lineHeight:g=25,font:x=j,position:w}=l,S=10,R=10,k=b.changePointByZoom({x:u,y:f},this.zoom,this.currentPos),{width:O,height:T,fontHeight:D=0}=C.getTextArea(this.canvas,l.text,y,x,g);if(w==="rt")break;h.drawRectWithFill(this.canvas,{x:k.x,y:k.y,width:O+R*2,height:T+S*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:m}),h.drawText(this.canvas,{x:k.x+R,y:k.y+D+S},a,{color:v,lineHeight:g,font:x,textMaxWidth:y});break}case"box3d":{this.renderBox3d(e);break}case"cuboid":{this.renderSingleCuboid(e);break}default:break}(n=(c=e.annotation)==null?void 0:c.renderEnhance)==null||n.call(c,{ctx:this.ctx,canvas:this.canvas,currentPos:this.currentPos,zoom:this.zoom,data:e,toolInstance:this})}),this.renderConnectionPoints()}catch(t){console.error("ViewOperation Render Error",t)}}}export{et as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import c from"../../utils/tool/CommonToolUtils.js";import l from"../../utils/tool/AxisUtils.js";import H from"../../utils/uuid.js";import{getCuboidHoverRange as U,getPlainPointsByDiagonalPoints as z,getPointsByBottomRightPoint as F,getCuboidDragMove as j,isCuboidWithInLimits as E,getHighlightPoints as W,getCuboidTextAttributeOffset as A,getToggleDirectionButtonOffset as N}from"../../utils/tool/CuboidUtils.js";import Z from"../../utils/tool/PolygonUtils.js";import{EDragStatus as v,EDragTarget as w,ECuboidDirection as K}from"../../constant/annotation.js";import g from"../../utils/tool/AttributeUtils.js";import{DEFAULT_TEXT_MAX_WIDTH as V}from"../../constant/tool.js";import D from"../../constant/keyCode.js";import{BasicToolOperation as X}from"./basicToolOperation.js";import b from"../../utils/tool/DrawUtils.js";import $ from"./cuboidToggleButtonClass.js";import G from"./textAttributeClass.js";import q from"../../locales/index.js";import{EMessage as J}from"../../locales/constants.js";var Q=Object.defineProperty,Y=Object.defineProperties,tt=Object.getOwnPropertyDescriptors,_=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,et=Object.prototype.propertyIsEnumerable,T=(n,t,i)=>t in n?Q(n,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):n[t]=i,u=(n,t)=>{for(var i in t||(t={}))it.call(t,i)&&T(n,i,t[i]);if(_)for(var i of _(t))et.call(t,i)&&T(n,i,t[i]);return n},a=(n,t)=>Y(n,tt(t)),k;(function(n){n[n.Ready=1]="Ready",n[n.FirstPoint=2]="FirstPoint",n[n.Cuboid=3]="Cuboid"})(k||(k={}));const ot=164;class st extends X{constructor(t){super(t);this.drawingStatus=1,this.cuboidList=[],this.hoverID="",this.getHoverData=i=>{const e=this.getCoordinateUnderZoom(i),{currentShowList:s}=this;if((s==null?void 0:s.length)>0){const r=s.map(d=>({id:d.id,pointList:l.changePointListByZoom(U(d),this.zoom)})),o=Z.getHoverPolygonID(e,r);if(o)return{hoverID:o,hoverCuboid:s.find(d=>d.id===o)}}return{}},this.textChange=i=>{this.config.textConfigurable===!1||!this.selectedID||(this.setCuboidList(g.textChange(i,this.selectedID,this.cuboidList)),this.emit("selectedChange"),this.render())},this.config=c.jsonParser(t.config),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this)}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}get currentShowList(){let t=[];const[i,e]=c.getRenderResultList(this.cuboidList,c.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=i,this.isHidden&&(t=[]),e&&t.push(e),t}get selectedCuboid(){return this.cuboidList.find(t=>t.id===this.selectedID)}get dataList(){return this.cuboidList}get isNeedCheckCuboidSize(){var t,i;return((t=this.config)==null?void 0:t.minWidth)>=0&&((i=this.config)==null?void 0:i.minHeight)>=0}getIsHoverSelectedCuboid(t){const i=this.getCoordinateUnderZoom(t),{selectedCuboid:e}=this;return e&&l.isCloseCuboid(i,l.changeCuboidByZoom(e,this.zoom))}isForbiddenMove(t,i){return this.getCoordinateInOrigin(t).y>i.frontPoints.br.y}updateSelectedCuboid(t){this.cuboidList=this.cuboidList.map(i=>i.id===this.selectedID?t:i)}getColorToRender(t,i){const e=this.getColor(t),s=i?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke,r=i?e==null?void 0:e.valid.fill:e==null?void 0:e.invalid.fill;return{strokeColor:s,toolColor:e,fillColor:r}}getCurrentSelectedData(){const{selectedCuboid:t}=this;if(!t)return;const{strokeColor:i}=this.getColorToRender(t.attribute,t.valid);return{width:ot,textAttribute:t.textAttribute,color:i}}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let i=t;g.textAttributeValidate(this.config.textCheckType,"",i)===!1&&(this.emit("messageError",g.getErrorNotice(this.config.textCheckType,this.lang)),i=""),this.setCuboidList(g.textChange(i,this.selectedID,this.cuboidList)),this.history.pushHistory(this.cuboidList),this.emit("updateTextAttribute"),this.render()}}setResult(t){this.clearDrawingStatus(),this.setCuboidList(t),this.render()}get currentPageResult(){return this.cuboidList}clearResult(){this.setCuboidList([],!0),this.setSelectedID(void 0)}exportData(){const{cuboidList:t}=this;return[t,this.basicImgInfo]}setSelectedID(t){var i,e;const s=this.selectedID;t!==s&&s&&((i=this._textAttributeInstance)==null||i.changeSelected()),t||(e=this._textAttributeInstance)==null||e.clearTextAttribute(),this.selectedID=t,this.emit("selectedChange")}setSelectedIDAndRender(t){this.setSelectedID(t),this.render()}setCuboidValidAndRender(t){if(!t)return;const i=this.cuboidList.map(e=>e.id===t?a(u({},e),{valid:!e.valid}):e);this.setCuboidList(i,!0),this.history.pushHistory(this.cuboidList),this.render()}onRightDblClick(t){super.onRightDblClick(t);const{hoverID:i}=this.getHoverData(t);this.selectedID&&this.selectedID===i&&this.deleteCuboid(i)}setCuboidList(t,i=!1){const e=this.cuboidList.length;this.cuboidList=t,e!==t.length&&this.emit("updatePageNumber"),i&&this.emit("updateResult")}deleteCuboid(t){var i;!t||(this.setCuboidList(this.cuboidList.filter(e=>e.id!==t)),this.history.pushHistory(this.cuboidList),this.setSelectedID(""),(i=this._textAttributeInstance)==null||i.clearTextAttribute(),this.render())}onKeyDown(t){if(!c.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:i}=t;switch(i){case D.Ctrl:this.drawingCuboid&&(this.drawingCuboid=a(u({},this.drawingCuboid),{valid:!1}),this.render());break;case D.F:this.selectedID&&this.setCuboidValidAndRender(this.selectedID);break;default:if(this.config.attributeConfigurable){const e=g.getAttributeByKeycode(i,this.config.attributeList);e!==void 0&&this.setDefaultAttribute(e)}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case D.Ctrl:this.drawingCuboid&&(this.drawingCuboid=a(u({},this.drawingCuboid),{valid:!0}),this.render());break}}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const{selectedCuboid:i}=this;if(!i||t.button===2||t.button===0&&this.isSpaceKey===!0||!this.getIsHoverSelectedCuboid(t))return;this.dragStatus=v.Start;const e=this.getCoordinateUnderZoom(t),s={initCuboid:i,dragStartCoord:e},r=l.returnClosePointOrLineInCuboid(e,l.changeCuboidByZoom(i,this.zoom)),o=r==null?void 0:r[0];switch(o==null?void 0:o.type){case"point":this.dragInfo=a(u({},s),{dragTarget:w.Point,positions:o.positions});break;case"line":this.dragInfo=a(u({},s),{dragTarget:w.Line,positions:o.positions});break;default:this.dragInfo=a(u({},s),{dragTarget:w.Cuboid})}}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return;if(this.dragInfo&&this.dragStatus===v.Move){this.dragInfo=void 0,this.dragStatus=v.Wait,this.history.pushHistory(this.cuboidList),this.emit("updateResult");return}const i=c.getSourceID(this.basicResult);if(t.button===0){if(this.hoverID&&t.ctrlKey&&!this.drawingCuboid){this.setCuboidValidAndRender(this.hoverID);return}if(!this.drawingCuboid){this.createNewDrawingCuboid(t,i);return}if(this.drawingCuboid)switch(this.drawingStatus){case 2:this.closeNewDrawingFrontPlane();break;case 3:this.closeAndCreateNewCuboid();break}}t.button===2&&this.rightMouseUp(t)}onMouseMove(t){var i;if(!(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.selectedID&&this.dragInfo){this.onDragMove(t);return}if(this.drawingCuboid){if(this.drawingFrontPlanesMove(t))return;this.drawingBackPlaneMove(t);return}this.hoverID=(i=this.getHoverData(t).hoverID)!=null?i:"",this.onHoverMove(t)}}drawingFrontPlanesMove(t){if(this.drawingCuboid&&this.firstClickCoord&&this.drawingStatus===2){const i=this.getCoordinateInOrigin(t);return this.drawingCuboid=a(u({},this.drawingCuboid),{frontPoints:z(this.firstClickCoord,i)}),this.render(),!0}}drawingBackPlaneMove(t){if(this.drawingCuboid&&this.firstClickCoord&&this.drawingStatus===3){const i=this.getCoordinateInOrigin(t);if(this.isForbiddenMove(t,this.drawingCuboid))return;this.drawingCuboid=a(u({},this.drawingCuboid),{backPoints:F({coord:i,points:this.drawingCuboid.frontPoints})}),this.render()}}onDragMove(t){if(!this.dragInfo||!this.selectedID)return;const{dragTarget:i,initCuboid:e,dragStartCoord:s,positions:r}=this.dragInfo,o=this.getCoordinateUnderZoom(t),d={x:(o.x-s.x)/this.zoom,y:(o.y-s.y)/this.zoom};this.dragStatus=v.Move;const h=j({offset:d,cuboid:e,dragTarget:i,positions:r});(h==null?void 0:h.backPoints)&&(h==null?void 0:h.backPoints.br.y)>(h==null?void 0:h.frontPoints.br.y)||(h&&this.updateSelectedCuboid(h),this.render())}onHoverMove(t){const{selectedCuboid:i}=this;if(i){const e=this.getCoordinateUnderZoom(t),s=l.returnClosePointOrLineInCuboid(e,l.changeCuboidByZoom(i,this.zoom),{zoom:1/this.zoom,scope:5});this.highlightInfo=s,this.render()}}createNewDrawingCuboid(t,i){if(!this.imgInfo)return;const e=this.getCoordinateInOrigin(t);this.drawingCuboid={attribute:this.defaultAttribute,direction:K.Front,valid:!t.ctrlKey,id:H(8,62),sourceID:i,textAttribute:"",order:c.getMaxOrder(this.cuboidList.filter(s=>c.isSameSourceID(s.sourceID,i)))+1,frontPoints:{tl:e,bl:e,tr:e,br:e}},this.firstClickCoord=u({},e),this.drawingStatus=2}closeNewDrawingFrontPlane(){this.drawingStatus=3}closeAndCreateNewCuboid(){var t,i;!((t=this.drawingCuboid)==null?void 0:t.frontPoints)||!this.drawingCuboid.backPoints||(this.isNeedCheckCuboidSize&&E({cuboid:this.drawingCuboid,config:this.config})===!1?this.emit("messageInfo",q.getMessagesByLocale(J.RectErrorSizeNotice,this.lang)):(this.setCuboidList([...this.cuboidList,this.drawingCuboid]),this.setSelectedID((i=this.drawingCuboid)==null?void 0:i.id),this.history.pushHistory(this.cuboidList)),this.clearDrawingStatus(),this.render())}clearDrawingStatus(){this.drawingCuboid&&(this.drawingCuboid=void 0,this.drawingStatus=1)}rightMouseUp(t){const{hoverID:i,hoverCuboid:e}=this.getHoverData(t);this.setSelectedID(i),e&&this.setDefaultAttribute(e.attribute),this.drawingCuboid&&this.clearDrawingStatus(),this.render()}renderSingleCuboid(t){var i,e,s,r;const o=l.changeCuboidByZoom(t,this.zoom,this.currentPos),d=o.id===this.hoverID,h=o.id===this.selectedID,{strokeColor:f,fillColor:M}=this.getColorToRender(o.attribute,o.valid),O=f,x=(e=(i=this.style)==null?void 0:i.width)!=null?e:2,{hiddenText:y=!1}=this.style,B={color:f,thickness:x},{backPoints:m,frontPoints:L,textAttribute:S}=o,R=L.br.x-L.bl.x;if(b.drawCuboid(this.canvas,o,{strokeColor:f,fillColor:M,thickness:x}),d||h){const p=W(o);p.forEach(I=>{b.drawCircleWithFill(this.canvas,I.point,5,u({},B))}),h&&p.forEach(I=>{b.drawCircleWithFill(this.canvas,I.point,3,{color:"white"})})}let C="";((s=this.config)==null?void 0:s.isShowOrder)&&o.order&&(o==null?void 0:o.order)>0&&(C=`${o.order}`),o.attribute&&(C=`${C} ${g.getAttributeShowText(o.attribute,(r=this.config)==null?void 0:r.attributeList)}`),!y&&m&&b.drawText(this.canvas,{x:m.tl.x,y:m.tl.y-5},C,{color:f,textMaxWidth:300});const P=A({cuboid:t,currentPos:this.currentPos,zoom:this.zoom,topOffset:16,leftOffset:0});if(!y&&S&&t.id!==this.selectedID){const p=Math.max(20,R*.8);b.drawText(this.canvas,{x:P.left,y:P.top},S,{color:O,textMaxWidth:p})}this.renderTextAttribute()}setDefaultAttribute(t){const i=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",i!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedCuboid:e}=this;if(e&&(this.setCuboidList(this.cuboidList.map(s=>s.id===this.selectedID?a(u({},s),{attribute:this.defaultAttribute}):s)),this.history.pushHistory(this.cuboidList),this.render()),this.drawingCuboid&&(this.drawingCuboid=a(u({},this.drawingCuboid),{attribute:this.defaultAttribute}),this.render()),this._textAttributeInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))}}}renderToggleButton(){const{selectedCuboid:t}=this;if(!this.ctx||this.config.textConfigurable!==!0||!t)return;const{attribute:i,valid:e}=t,{strokeColor:s}=this.getColorToRender(i,e);this.toggleButtonInstance||(this.toggleButtonInstance=new $({container:this.container,cuboidButtonMove:o=>this.updateMouseOperation(o),toggleDirection:o=>this.toggleDirection(o)}));const r=N({cuboid:t,zoom:this.zoom,currentPos:this.currentPos});this.toggleButtonInstance.update({left:r.left,top:r.top,color:s})}renderTextAttribute(){var t;const{selectedCuboid:i}=this;if(!this.ctx||this.config.textConfigurable===!1||!i)return;const{strokeColor:e}=this.getColorToRender(i.attribute,i.valid),{attribute:s,textAttribute:r,frontPoints:o}=i,d=A({cuboid:i,currentPos:this.currentPos,zoom:this.zoom}),h=(o.br.x-o.bl.x)*this.zoom*.8;this._textAttributeInstance||(this._textAttributeInstance=new G({width:V,container:this.container,icon:this.getTextIconSvg(s),color:e,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${r}`,{left:d.left,top:d.top,color:e,width:h})}renderDrawing(){this.drawingCuboid&&this.renderSingleCuboid(this.drawingCuboid)}renderStatic(){this.cuboidList.forEach(t=>this.renderSingleCuboid(t))}renderSelected(){var t;const{selectedCuboid:i}=this;i?(this.renderSingleCuboid(i),this.renderToggleButton()):((t=this.toggleButtonInstance)==null||t.clearCuboidButtonDOM(),this.toggleButtonInstance=void 0)}updateMouseOperation(t){t==="in"?(this.setForbidCursorLine(!0),this.setForbidOperation(!0),this.setShowDefaultCursor(!0)):(this.setForbidCursorLine(!1),this.setShowDefaultCursor(!1),this.setForbidOperation(!1))}toggleDirection(t){this.cuboidList&&this.selectedCuboid&&(this.setCuboidList(this.cuboidList.map(i=>{var e;return i.id===((e=this.selectedCuboid)==null?void 0:e.id)?a(u({},i),{direction:t}):i})),this.history.pushHistory(this.cuboidList),this.render())}renderHover(){var t;this.dragInfo||(t=this.highlightInfo)==null||t.forEach(i=>{var e,s;const{strokeColor:r}=this.getColorToRender(i.originCuboid.attribute,i.originCuboid.valid),o=8;switch(i.type){case"point":(e=i.points)==null||e.forEach(d=>{b.drawCircleWithFill(this.canvas,l.changePointByZoom(d,this.zoom,this.currentPos),o,{color:r})});break;case"line":{const d=(s=i.points)==null?void 0:s.map(h=>l.changePointByZoom(h,this.zoom,this.currentPos));d&&b.drawLineWithPointList(this.canvas,d,{color:r,thickness:o});break}}})}renderCuboid(){this.renderStatic(),this.renderDrawing(),this.renderSelected(),this.renderHover()}render(){!this.ctx||(super.render(),this.renderCuboid(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}undo(){const t=this.history.undo();t&&(t.length!==this.cuboidList.length&&this.setSelectedID(""),this.setCuboidList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.cuboidList.length&&this.setSelectedID(""),this.setCuboidList(t,!0),this.render())}}export{st as default};
|
|
1
|
+
import c from"../../utils/tool/CommonToolUtils.js";import l from"../../utils/tool/AxisUtils.js";import y from"../../utils/uuid.js";import{getCuboidHoverRange as S,getPlainPointsByDiagonalPoints as L,getPointsByBottomRightPoint as x,getCuboidDragMove as A,isCuboidWithInLimits as P,getHighlightPoints as _,getHighlightLines as T,getToggleDirectionButtonOffset as k,getCuboidTextAttributeOffset as M}from"../../utils/tool/CuboidUtils.js";import O from"../../utils/tool/PolygonUtils.js";import{EDragStatus as p,EDragTarget as v,ECuboidDirection as H}from"../../constant/annotation.js";import g from"../../utils/tool/AttributeUtils.js";import{DEFAULT_TEXT_MAX_WIDTH as B}from"../../constant/tool.js";import f from"../../constant/keyCode.js";import{BasicToolOperation as R}from"./basicToolOperation.js";import b from"../../utils/tool/DrawUtils.js";import U from"./cuboidToggleButtonClass.js";import F from"./textAttributeClass.js";import j from"../../locales/index.js";import{EMessage as z}from"../../locales/constants.js";var E=Object.defineProperty,W=Object.defineProperties,Z=Object.getOwnPropertyDescriptors,m=Object.getOwnPropertySymbols,N=Object.prototype.hasOwnProperty,K=Object.prototype.propertyIsEnumerable,D=(h,t,i)=>t in h?E(h,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):h[t]=i,u=(h,t)=>{for(var i in t||(t={}))N.call(t,i)&&D(h,i,t[i]);if(m)for(var i of m(t))K.call(t,i)&&D(h,i,t[i]);return h},a=(h,t)=>W(h,Z(t)),w;(function(h){h[h.Ready=1]="Ready",h[h.FirstPoint=2]="FirstPoint",h[h.Cuboid=3]="Cuboid"})(w||(w={}));const V=164;class X extends R{constructor(t){super(t);this.drawingStatus=1,this.cuboidList=[],this.hoverID="",this.getHoverData=i=>{const e=this.getCoordinateUnderZoom(i),{currentShowList:s}=this;if((s==null?void 0:s.length)>0){const o=s.map(n=>({id:n.id,pointList:l.changePointListByZoom(S(n),this.zoom)})),r=O.getHoverPolygonID(e,o);if(r)return{hoverID:r,hoverCuboid:s.find(n=>n.id===r)}}return{}},this.textChange=i=>{this.config.textConfigurable===!1||!this.selectedID||(this.setCuboidList(g.textChange(i,this.selectedID,this.cuboidList)),this.emit("selectedChange"),this.render())},this.config=c.jsonParser(t.config),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this)}get selectedText(){var t,i;return(i=(t=this.selectedCuboid)==null?void 0:t.textAttribute)!=null?i:""}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}get currentShowList(){let t=[];const[i,e]=c.getRenderResultList(this.cuboidList,c.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=i,this.isHidden&&(t=[]),e&&t.push(e),t}get selectedCuboid(){return this.cuboidList.find(t=>t.id===this.selectedID)}get dataList(){return this.cuboidList}get isNeedCheckCuboidSize(){var t,i;return((t=this.config)==null?void 0:t.minWidth)>=0&&((i=this.config)==null?void 0:i.minHeight)>=0}getIsHoverSelectedCuboid(t){const i=this.getCoordinateUnderZoom(t),{selectedCuboid:e}=this;return e&&l.isCloseCuboid(i,l.changeCuboidByZoom(e,this.zoom))}isForbiddenMove(t,i){return this.getCoordinateInOrigin(t).y>i.frontPoints.br.y}updateSelectedCuboid(t){this.cuboidList=this.cuboidList.map(i=>i.id===this.selectedID?t:i)}getStylesToRender(t,i){var e,s;const o=this.getColor(t),r=i?o==null?void 0:o.valid.stroke:o==null?void 0:o.invalid.stroke,n=i?o==null?void 0:o.valid.fill:o==null?void 0:o.invalid.fill,d=(s=(e=this.style)==null?void 0:e.width)!=null?s:2;return{strokeColor:r,toolColor:o,fillColor:n,lineWidth:d}}getCurrentSelectedData(){const{selectedCuboid:t}=this;if(!t)return;const{strokeColor:i}=this.getStylesToRender(t.attribute,t.valid);return{width:V,textAttribute:t.textAttribute,color:i}}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let i=t;g.textAttributeValidate(this.config.textCheckType,"",i)===!1&&(this.emit("messageError",g.getErrorNotice(this.config.textCheckType,this.lang)),i=""),this.setCuboidList(g.textChange(i,this.selectedID,this.cuboidList)),this.history.pushHistory(this.cuboidList),this.emit("updateTextAttribute"),this.render()}}setResult(t){this.clearActiveStatus(),this.setCuboidList(t),this.render()}get currentPageResult(){return this.cuboidList}clearResult(){this.setCuboidList([],!0),this.deleteSelectedID(),this.render()}exportData(){const{cuboidList:t}=this;return[t,this.basicImgInfo]}setSelectedID(t){var i,e;const s=this.selectedID;t!==s&&s&&((i=this._textAttributeInstance)==null||i.changeSelected()),t||(e=this._textAttributeInstance)==null||e.clearTextAttribute(),this.selectedID=t,this.emit("selectedChange")}setSelectedIDAndRender(t){this.setSelectedID(t),this.render()}setCuboidValidAndRender(t){if(!t)return;const i=this.cuboidList.map(e=>e.id===t?a(u({},e),{valid:!e.valid}):e);this.setCuboidList(i,!0),this.history.pushHistory(this.cuboidList),this.render()}onRightDblClick(t){super.onRightDblClick(t);const{hoverID:i}=this.getHoverData(t);this.selectedID&&this.selectedID===i&&this.deleteCuboid(i)}setCuboidList(t,i=!1){const e=this.cuboidList.length;this.cuboidList=t,e!==t.length&&this.emit("updatePageNumber"),i&&this.emit("updateResult")}deleteCuboid(t){var i;!t||(this.setCuboidList(this.cuboidList.filter(e=>e.id!==t)),this.history.pushHistory(this.cuboidList),this.setSelectedID(""),(i=this._textAttributeInstance)==null||i.clearTextAttribute(),this.render())}onKeyDown(t){if(!c.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:i}=t;switch(i){case f.Ctrl:this.drawingCuboid&&(this.drawingCuboid=a(u({},this.drawingCuboid),{valid:!1}),this.render());break;case f.Delete:this.selectedID&&this.deleteCuboid(this.selectedID);break;case f.Z:this.setIsHidden(!this.isHidden),this.render();break;case f.F:this.selectedID&&this.setCuboidValidAndRender(this.selectedID);break;default:if(this.config.attributeConfigurable){const e=g.getAttributeByKeycode(i,this.config.attributeList);e!==void 0&&this.setDefaultAttribute(e)}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case f.Ctrl:this.drawingCuboid&&(this.drawingCuboid=a(u({},this.drawingCuboid),{valid:!0}),this.render());break}}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const{selectedCuboid:i}=this;if(!i||t.button===2||t.button===0&&this.isSpaceKey===!0||!this.getIsHoverSelectedCuboid(t))return;this.dragStatus=p.Start;const e=this.getCoordinateUnderZoom(t),s={initCuboid:i,dragStartCoord:e},o=l.returnClosePointOrLineInCuboid(e,l.changeCuboidByZoom(i,this.zoom)),r=o==null?void 0:o[0];switch(r==null?void 0:r.type){case"point":this.dragInfo=a(u({},s),{dragTarget:v.Point,positions:r.positions});break;case"line":this.dragInfo=a(u({},s),{dragTarget:v.Line,positions:r.positions});break;default:this.dragInfo=a(u({},s),{dragTarget:v.Cuboid})}}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return;if(this.dragInfo&&this.dragStatus===p.Move){this.dragInfo=void 0,this.dragStatus=p.Wait,this.history.pushHistory(this.cuboidList),this.emit("updateResult");return}const i=c.getSourceID(this.basicResult);if(t.button===0){if(this.hoverID&&t.ctrlKey&&!this.drawingCuboid){this.setCuboidValidAndRender(this.hoverID);return}if(!this.drawingCuboid){this.createNewDrawingCuboid(t,i);return}if(this.drawingCuboid)switch(this.drawingStatus){case 2:this.closeNewDrawingFrontPlane();break;case 3:this.closeAndCreateNewCuboid();break}}t.button===2&&this.rightMouseUp(t)}onMouseMove(t){var i;if(!(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.selectedID&&this.dragInfo){this.onDragMove(t);return}if(this.drawingCuboid){if(this.drawingFrontPlanesMove(t))return;this.drawingBackPlaneMove(t);return}this.hoverID=(i=this.getHoverData(t).hoverID)!=null?i:"",this.onHoverMove(t)}}drawingFrontPlanesMove(t){if(this.drawingCuboid&&this.firstClickCoord&&this.drawingStatus===2){const i=this.getCoordinateInOrigin(t);return this.drawingCuboid=a(u({},this.drawingCuboid),{frontPoints:L(this.firstClickCoord,i)}),this.render(),!0}}drawingBackPlaneMove(t){if(this.drawingCuboid&&this.firstClickCoord&&this.drawingStatus===3){const i=this.getCoordinateInOrigin(t);if(this.isForbiddenMove(t,this.drawingCuboid))return;this.drawingCuboid=a(u({},this.drawingCuboid),{backPoints:x({coord:i,points:this.drawingCuboid.frontPoints})}),this.render()}}onDragMove(t){if(!this.dragInfo||!this.selectedID)return;const{dragTarget:i,initCuboid:e,dragStartCoord:s,positions:o}=this.dragInfo,r=this.getCoordinateUnderZoom(t),n={x:(r.x-s.x)/this.zoom,y:(r.y-s.y)/this.zoom};this.dragStatus=p.Move;const d=A({offset:n,cuboid:e,dragTarget:i,positions:o});(d==null?void 0:d.backPoints)&&(d==null?void 0:d.backPoints.br.y)>(d==null?void 0:d.frontPoints.br.y)||(d&&this.updateSelectedCuboid(d),this.render())}onHoverMove(t){const{selectedCuboid:i}=this;if(i){const e=this.getCoordinateUnderZoom(t),s=l.returnClosePointOrLineInCuboid(e,l.changeCuboidByZoom(i,this.zoom),{zoom:1/this.zoom,scope:5});this.highlightInfo=s,this.render()}}createNewDrawingCuboid(t,i){if(!this.imgInfo)return;const e=this.getCoordinateInOrigin(t);if(this.drawingCuboid={attribute:this.defaultAttribute,direction:H.Front,valid:!t.ctrlKey,id:y(8,62),sourceID:i,textAttribute:"",order:c.getMaxOrder(this.cuboidList.filter(s=>c.isSameSourceID(s.sourceID,i)))+1,frontPoints:{tl:e,bl:e,tr:e,br:e}},this.firstClickCoord=u({},e),this.drawingStatus=2,this.config.textConfigurable){let s="";s=g.getTextAttribute(this.cuboidList.filter(o=>c.isSameSourceID(o.sourceID,i)),this.config.textCheckType),this.drawingCuboid=a(u({},this.drawingCuboid),{textAttribute:s})}}closeNewDrawingFrontPlane(){this.drawingStatus=3}closeAndCreateNewCuboid(){var t,i;!((t=this.drawingCuboid)==null?void 0:t.frontPoints)||!this.drawingCuboid.backPoints||(this.isNeedCheckCuboidSize&&P({cuboid:this.drawingCuboid,config:this.config})===!1?this.emit("messageInfo",j.getMessagesByLocale(z.RectErrorSizeNotice,this.lang)):(this.setCuboidList([...this.cuboidList,this.drawingCuboid]),this.setSelectedID((i=this.drawingCuboid)==null?void 0:i.id),this.history.pushHistory(this.cuboidList)),this.clearDrawingStatus(),this.render())}deleteSelectedID(){this.setSelectedID("")}clearDrawingStatus(){this.drawingCuboid&&(this.drawingCuboid=void 0,this.drawingStatus=1)}clearActiveStatus(){this.clearDrawingStatus(),this.deleteSelectedID()}rightMouseUp(t){const{hoverID:i,hoverCuboid:e}=this.getHoverData(t);this.setSelectedID(i),e&&this.setDefaultAttribute(e.attribute),this.drawingCuboid&&this.clearDrawingStatus(),this.render()}renderHighlightCuboidCom(t){const i=l.changeCuboidByZoom(t,this.zoom,this.currentPos),e=i.id===this.hoverID,s=i.id===this.selectedID,{strokeColor:o,lineWidth:r}=this.getStylesToRender(i.attribute,i.valid),n={color:o,thickness:r};if(e||s){const d=_(i);d.forEach(I=>{b.drawCircleWithFill(this.canvas,I.point,5,u({},n))}),s&&(T(i).forEach(C=>{b.drawLine(this.canvas,C.p1,C.p2,{color:o,thickness:r+2})}),d.forEach(C=>{b.drawCircleWithFill(this.canvas,C.point,3,{color:"white"})}))}}renderSingleCuboid(t){var i,e;const s=l.changeCuboidByZoom(t,this.zoom,this.currentPos),{strokeColor:o,fillColor:r}=this.getStylesToRender(s.attribute,s.valid),n=(e=(i=this.style)==null?void 0:i.width)!=null?e:2,{hiddenText:d=!1}=this.style;b.drawCuboidWithText(this.canvas,s,{strokeColor:o,fillColor:r,thickness:n},{config:this.config,hiddenText:d,selectedID:this.selectedID}),this.renderTextAttribute()}setDefaultAttribute(t){const i=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",i!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedCuboid:e}=this;if(this._textAttributeInstance&&(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)?this._textAttributeInstance.clearTextAttribute():this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))),e){this.setCuboidList(this.cuboidList.map(s=>s.id===this.selectedID?a(u({},s),{attribute:this.defaultAttribute}):s)),this.history.pushHistory(this.cuboidList),this.render();return}this.drawingCuboid&&(this.drawingCuboid=a(u({},this.drawingCuboid),{attribute:this.defaultAttribute}),this.render())}}renderToggleButton(){const{selectedCuboid:t}=this;if(!this.ctx||!t)return;const{attribute:i,valid:e}=t,{strokeColor:s}=this.getStylesToRender(i,e);this.toggleButtonInstance||(this.toggleButtonInstance=new U({container:this.container,cuboidButtonMove:r=>this.updateMouseOperation(r),toggleDirection:r=>this.toggleDirection(r)}));const o=k({cuboid:t,zoom:this.zoom,currentPos:this.currentPos});this.toggleButtonInstance.update({left:o.left,top:o.top,color:s})}renderTextAttribute(){var t;const{selectedCuboid:i}=this;if(!this.ctx||this.config.textConfigurable===!1||!i)return;const{strokeColor:e}=this.getStylesToRender(i.attribute,i.valid),{attribute:s,textAttribute:o,frontPoints:r}=i,n=M({cuboid:i,currentPos:this.currentPos,zoom:this.zoom}),d=(r.br.x-r.bl.x)*this.zoom*.8;this._textAttributeInstance||(this._textAttributeInstance=new F({width:B,container:this.container,icon:this.getTextIconSvg(s),color:e,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${o}`,{left:n.left,top:n.top,color:e,width:d})}renderDrawing(){this.drawingCuboid&&this.renderSingleCuboid(this.drawingCuboid)}renderStatic(){this.isHidden||this.currentShowList.forEach(t=>this.renderSingleCuboid(t))}renderSelected(){var t;const{selectedCuboid:i}=this;i?(this.renderSingleCuboid(i),this.renderHighlightCuboidCom(i),this.renderToggleButton()):((t=this.toggleButtonInstance)==null||t.clearCuboidButtonDOM(),this.toggleButtonInstance=void 0)}updateMouseOperation(t){t==="in"?(this.setForbidCursorLine(!0),this.setForbidOperation(!0),this.setShowDefaultCursor(!0)):(this.setForbidCursorLine(!1),this.setShowDefaultCursor(!1),this.setForbidOperation(!1))}toggleDirection(t){this.cuboidList&&this.selectedCuboid&&(this.setCuboidList(this.cuboidList.map(i=>{var e;return i.id===((e=this.selectedCuboid)==null?void 0:e.id)?a(u({},i),{direction:t}):i})),this.history.pushHistory(this.cuboidList),this.render())}renderHover(){var t;this.dragInfo||(t=this.highlightInfo)==null||t.forEach(i=>{var e,s;const{strokeColor:o}=this.getStylesToRender(i.originCuboid.attribute,i.originCuboid.valid),r=8;switch(i.type){case"point":(e=i.points)==null||e.forEach(n=>{b.drawCircleWithFill(this.canvas,l.changePointByZoom(n,this.zoom,this.currentPos),r,{color:o})});break;case"line":{const n=(s=i.points)==null?void 0:s.map(d=>l.changePointByZoom(d,this.zoom,this.currentPos));n&&b.drawLineWithPointList(this.canvas,n,{color:o,thickness:r});break}}})}renderCuboid(){this.renderStatic(),this.renderDrawing(),this.renderSelected(),this.renderHover()}render(){!this.ctx||(super.render(),this.renderCuboid(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}undo(){const t=this.history.undo();t&&(t.length!==this.cuboidList.length&&this.setSelectedID(""),this.setCuboidList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.cuboidList.length&&this.setSelectedID(""),this.setCuboidList(t,!0),this.render())}}export{X as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EToolName as p,ELineTypes as k,edgeAdsorptionScope as _,EOperationMode as E}from"../../constant/tool.js";import j from"../../utils/tool/RectUtils.js";import D from"../../utils/tool/PolygonUtils.js";import P from"../../utils/tool/MarkerUtils.js";import z from"../../utils/MathUtils.js";import{EDragStatus as g,ESortDirection as w,DEFAULT_TEXT_OFFSET as N}from"../../constant/annotation.js";import S from"../../constant/keyCode.js";import C from"../../locales/index.js";import{EMessage as A}from"../../locales/constants.js";import I from"../../utils/tool/AttributeUtils.js";import c from"../../utils/tool/AxisUtils.js";import r from"../../utils/tool/CommonToolUtils.js";import x from"../../utils/tool/DrawUtils.js";import B from"../../utils/tool/StyleUtils.js";import Z from"../../utils/uuid.js";import{BasicToolOperation as H}from"./basicToolOperation.js";import W from"./textAttributeClass.js";var F=Object.defineProperty,K=Object.defineProperties,$=Object.getOwnPropertyDescriptors,T=Object.getOwnPropertySymbols,V=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable,R=Math.pow,O=(m,t,e)=>t in m?F(m,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):m[t]=e,L=(m,t)=>{for(var e in t||(t={}))V.call(t,e)&&O(m,e,t[e]);if(T)for(var e of T(t))X.call(t,e)&&O(m,e,t[e]);return m},y=(m,t)=>K(m,$(t));const U=200;class q extends H{constructor(t){super(t);this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,s=this.currentPageResult.find(o=>o.label===i);s&&(this.setSelectedID(s.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(s.attribute)),this.emit("markIndexChange")},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedID||(this.setPointList(I.textChange(e,this.selectedID,this.pointList)),this.emit("selectedChange"),this.render())},this.isMinDistance=e=>{const i=c.changePointByZoom(e,this.zoom);return this.pointList.some(s=>{const o=c.changePointByZoom(s,this.zoom);return z.getLineLength(o,i)<.2})},this.config=r.jsonParser(t.config),this.pointList=[],this.markerIndex=0,this.setStyle(t.style),this.createPoint=this.createPoint.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this)}get dataList(){return this.pointList}get drawOutsideTarget(){var t;return(t=this.config.drawOutsideTarget)!=null?t:this.config.drawPointOut}setNextMarker(t=this.pointList){if(this.hasMarkerConfig){const e=r.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndexAndSelect(e.index)}}setResult(t){this.clearActiveStatus(),this.setPointList(t),this.setNextMarker(t),this.recoverOperationMode(),this.render()}setPointList(t,e=!1){const i=this.pointList.length;this.pointList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}setConfig(t,e=!1){this.config=r.jsonParser(t),e===!0&&this.clearResult()}clearResult(){this.setPointList([]),this.setSelectedID(void 0),this.history.pushHistory([]),this.hoverID="",this.render()}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.pointList.forEach(s=>{s.id===i&&(s.attribute=t)}),this.history.pushHistory(this.pointList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}get selectedText(){var t;return(t=this.pointList.find(e=>e.id===this.selectedID))==null?void 0:t.textAttribute}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}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")}getTextIconSvg(t=""){return I.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}clearActiveStatus(){this.hoverID=void 0,this.dragStatus=g.Wait,this.setSelectedID(void 0)}setBasicResult(t){super.setBasicResult(t),this.setNextMarker(),this.clearActiveStatus()}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originPointList)==null?void 0:i.length)||(this.setPointList(this.dragInfo.originPointList.map(s=>y(L({},s),{x:s.x+t.x/this.zoom,y:s.y+t.y/this.zoom}))),this.render())}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation)){if(t.button===0&&!this.hoverID){this.recoverOperationMode(),this.createPoint(t),this.render();return}if((this.hoverID===this.selectedID||this.isMultiMoveMode&&this.hoverID)&&t.button===0){this.dragStatus=g.Start,this.isMultiMoveMode&&(this.dragInfo={dragStartCoord:this.getCoordinateUnderZoom(t),originPointList:this.pointList});return}return this.render(),!0}}onMouseMove(t){super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo||(this.hoverID=this.getHoverId(),(this.dragStatus===g.Start||this.dragStatus===g.Move)&&this.onDragMove(t),this.hoverID&&this.render())}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;t.button===2&&this.rightMouseUp(),this.dragStatus===g.Move&&(this.history.pushHistory(this.pointList),this.dragInfo=void 0),this.dragStatus=g.Wait,this.render()}onDragMove(t){var e,i;if(!this.imgInfo)return;this.dragStatus=g.Move;const s=this.getCoordinateUnderZoom(t);if(this.isMultiMoveMode&&this.dragInfo){const a={x:s.x-this.dragInfo.dragStartCoord.x,y:s.y-this.dragInfo.dragStartCoord.y};this.onDragMoveAll(a);return}const o=c.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutsideTarget,this.basicResult,this.zoom),l=this.drawOutsideTarget?c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos):c.changePointByZoom(o,1/this.zoom);this.drawOutsideTarget===!1&&this.dependToolName===p.Polygon&&((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&!D.isInPolygon(l,this.basicResult.pointList)||(this.pointList.forEach(a=>{a.id===this.selectedID&&(a.x=l.x,a.y=l.y)}),this.render())}onKeyDown(t){if(!r.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case S.Delete:this.deletePoint();break;case S.Tab:{this.onTabKeyDown(t);break}case S.Z:this.setIsHidden(!this.isHidden),this.render();break;default:{if(this.config.attributeConfigurable){const i=I.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}createPoint(t){var e,i,s,o;if(!this.imgInfo)return;const{upperLimit:l}=this.config;if(l&&this.currentPageResult.length>=l){this.emit("messageInfo",`${C.getMessagesByLocale(A.LowerLimitPoint,this.lang)}`);return}const a=r.getSourceID(this.basicResult),u=this.getCoordinateUnderZoom(t);let d=c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.config.edgeAdsorption&&this.referenceData&&[p.Polygon,p.Line].includes((e=this.referenceData)==null?void 0:e.toolName)){const b=((i=this.referenceData)==null?void 0:i.toolName)===p.Polygon,{dropFoot:v,hasClosed:M}=D.getClosestPoint(d,this.referenceData.result,(o=(s=this.referenceData.config)==null?void 0:s.lineType)!=null?o:k.Line,_/this.zoom,{isClose:b});v&&(d=v),M&&this.emit("messageSuccess",`${C.getMessagesByLocale(A.SuccessfulEdgeAdsorption,this.lang)}`)}if(this.drawOutsideTarget===!1){if(this.dependToolName&&this.basicCanvas){let h=!1;switch(this.dependToolName){case p.Rect:{h=!j.isInRect(d,this.basicResult);break}case p.Polygon:{h=!D.isInPolygon(d,this.basicResult.pointList);break}}if(h)return}if(u.x<0||u.y<0||u.x>this.imgInfo.width||u.y>this.imgInfo.height)return}if(this.isMinDistance(d))return;let n=y(L({},d),{attribute:this.defaultAttribute,valid:!t.ctrlKey,id:Z(8,62),sourceID:a,textAttribute:"",order:r.getMaxOrder(this.pointList.filter(h=>r.isSameSourceID(h.sourceID,a)))+1});if(this.config.textConfigurable){let h="";h=I.getTextAttribute(this.pointList.filter(b=>r.isSameSourceID(b.sourceID,a)),this.config.textCheckType),n=y(L({},n),{textAttribute:h})}if(this.hasMarkerConfig){const h=r.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(h)n=y(L({},n),{label:h.label}),this.markerIndex=h.index,this.emit("markIndexChange");else{this.emit("messageInfo",C.getMessagesByLocale(A.MarkerFinish,this.lang));return}}this.hoverID=n.id;const f=[...this.pointList,n];this.setPointList(f),this.history.pushHistory(f),this.setSelectedID(n.id)}isInPoint(t,e,i=this.zoom){return(this.style.width+2)/i>=Math.sqrt(R(t.x-e.x,2)+R(t.y-e.y,2))}getHoverId(){var t;const e=c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos),i=(t=this.pointList)==null?void 0:t.find(s=>this.isInPoint(e,s));return i==null?void 0:i.id}rightMouseUp(){if(this.recoverOperationMode(),this.selectedID===this.hoverID){const e=this.pointList.filter(i=>i.id!==this.selectedID);this.setPointList(e),this.history.pushHistory(e),this.setSelectedID(""),this.hoverID="";return}const t=this.pointList.find(e=>e.id===this.hoverID);if(this.setSelectedID(this.hoverID),this.setDefaultAttribute(t==null?void 0:t.attribute),(t==null?void 0:t.label)&&this.hasMarkerConfig){const e=r.getCurrentMarkerIndex(t.label,this.config.markerList);e>=0&&(this.setMarkerIndex(e),this.emit("markIndexChange"))}}onTabKeyDown(t){if(t.preventDefault(),this.dragStatus===g.Move||this.dragStatus===g.Start)return;let e=w.ascend;t.shiftKey&&(e=w.descend);const[i,s]=r.getRenderResultList(this.pointList,r.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let o=[...i];s&&(o=[...o,s]);const l=r.getNextSelectedRectID(o,e,this.selectedID);l&&this.setSelectedID(l.id)}get currentPageResult(){const[t]=r.getRenderResultList(this.pointList,r.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=r.getRenderResultList(t,r.getSourceID(this.basicResult),[]);return e}exportData(){const{pointList:t}=this;return[t,this.basicImgInfo]}deletePoint(){var t;this.selectedID&&(this.setPointList(this.pointList.filter(e=>e.id!==this.selectedID)),this.history.pushHistory(this.pointList),(t=this._textAttributInstance)==null||t.clearTextAttribute(),this.emit("selectedChange"),this.render())}undoAndRedo(t){var e,i;if(this.dragStatus===g.Move||this.dragStatus===g.Start)return;const s=(i=(e=this.history)[t])==null?void 0:i.call(e);(s==null?void 0:s.some(o=>o.id===this.selectedID))||this.setSelectedID(""),s&&(this.setPointList(s,!0),this.render())}undo(){this.undoAndRedo("undo")}redo(){this.undoAndRedo("redo")}getCurrentSelectedData(){var t;if(!this.selectedID)return;const e=(t=this.pointList)==null?void 0:t.find(o=>o.id===this.selectedID),i=this.getColor(e==null?void 0:e.attribute),s=(e==null?void 0:e.valid)?i==null?void 0:i.valid.stroke:i==null?void 0:i.invalid.stroke;return this.dragStatus=g.Wait,{width:U*this.zoom*.6,textAttribute:(e==null?void 0:e.textAttribute)||"",color:s}}updateSelectedTextAttribute(t){if(this._textAttributInstance&&t&&this.selectedID){let e=t;I.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",I.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPointList(I.textChange(e,this.selectedID,this.pointList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t,e;const i=(t=this.pointList)==null?void 0:t.find(b=>b.id===this.selectedID);if(!this.ctx||this.config.textConfigurable!==!0||!i)return;const{x:s,y:o,attribute:l,valid:a}=i,u=U*this.zoom*.6,d=c.getOffsetCoordinate({x:s,y:o},this.currentPos,this.zoom),n=this.getColor(l),f=a?n==null?void 0:n.valid.stroke:n==null?void 0:n.invalid.stroke,h=4;this._textAttributInstance||(this._textAttributInstance=new W({width:u,container:this.container,icon:this.getTextIconSvg(l),color:f,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((e=this._textAttributInstance)==null?void 0:e.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${i.textAttribute}`,{left:d.x,top:d.y+h,color:f,width:u})}renderPoint(t,e=!1){var i,s,o;const{textAttribute:l="",attribute:a}=t,u=e||t.id===this.selectedID,d=this.getColor(a),n=c.changePointByZoom(t,this.zoom,this.currentPos),{width:f=2,hiddenText:h=!1}=this.style,b=B.getStrokeAndFill(d,t.valid,{isSelected:u||t.id===this.hoverID});x.drawCircle(this.canvas,n,f,{startAngleDeg:0,endAngleDeg:360,thickness:1,color:b.stroke,fill:b.fill});let v="";(((i=this.config)==null?void 0:i.isShowOrder)||((s=this.config)==null?void 0:s.showOrder))&&t.order&&(t==null?void 0:t.order)>0&&(v=`${t.order}`),t.label&&this.hasMarkerConfig&&(v=`${r.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${P.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(v=`${v} ${I.getAttributeShowText(t.attribute,(o=this.config)==null?void 0:o.attributeList)}`),h||x.drawText(this.canvas,{x:n.x+f/2,y:n.y-f-4},v,{textAlign:"center",color:b.stroke}),u?this.renderTextAttribute():h||x.drawText(this.canvas,{x:n.x+f,y:n.y+f+24},l,L({color:b.stroke},N))}renderMultiSelectedPoint(){!this.isMultiMoveMode||this.pointList.forEach(t=>{this.renderPoint(t,!0)})}renderPointList(){switch(this.operationMode){case E.MultiMove:this.renderMultiSelectedPoint();break;default:{const[t,e]=r.getRenderResultList(this.pointList,r.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);this.isHidden||t.forEach(i=>{this.renderPoint(i)}),e&&this.renderPoint(e)}}}renderAuxiliaryLine(){var t;if(!this.config.markerConfigurable||!((t=this.config.markerList)==null?void 0:t.length))return;const[e,i]=r.getRenderResultList(this.pointList,r.getSourceID(this.basicResult),this.attributeLockList,this.selectedID),s=e;if(i&&s.push(i),s.length<2)return;const o=P.getAuxiliaryLineByMarkerList(this.config.markerList,"value");P.getAuxiliaryLineCoord(o,s).forEach(a=>{const{start:u,end:d}=a,n=c.changePointListByZoom([u,d],this.zoom,this.currentPos);x.drawLine(this.canvas,n[0],n[1],{color:"#C5C5C5"})})}renderTop(){var t,e,i;const s=this.getLineColor(this.defaultAttribute);if(this.renderCursorLine(s),this.config.edgeAdsorption&&this.referenceData){let o=c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const l=((t=this.referenceData)==null?void 0:t.toolName)===p.Polygon,{dropFoot:a}=D.getClosestPoint(o,this.referenceData.result,(i=(e=this.referenceData.config)==null?void 0:e.lineType)!=null?i:k.Line,_/this.zoom,{isClose:l});a&&o!==a&&o!==a&&(o=a,x.drawCircle(this.canvas,c.changePointByZoom(o,this.zoom,this.currentPos),5,{color:"white",fill:"white"}),x.drawCircle(this.canvas,c.changePointByZoom(o,this.zoom,this.currentPos),3,{fill:s,color:s}))}}render(){!this.ctx||(super.render(),this.renderAuxiliaryLine(),this.renderPointList(),this.renderTop())}}export{q as default};
|
|
1
|
+
import{EToolName as p,ELineTypes as _,edgeAdsorptionScope as k,EOperationMode as E}from"../../constant/tool.js";import j from"../../utils/tool/RectUtils.js";import L from"../../utils/tool/PolygonUtils.js";import P from"../../utils/tool/MarkerUtils.js";import z from"../../utils/MathUtils.js";import N from"lodash";import{EDragStatus as f,ESortDirection as w,DEFAULT_TEXT_OFFSET as B}from"../../constant/annotation.js";import S from"../../constant/keyCode.js";import C from"../../locales/index.js";import{EMessage as A}from"../../locales/constants.js";import v from"../../utils/tool/AttributeUtils.js";import c from"../../utils/tool/AxisUtils.js";import h from"../../utils/tool/CommonToolUtils.js";import x from"../../utils/tool/DrawUtils.js";import Z from"../../utils/tool/StyleUtils.js";import H from"../../utils/uuid.js";import{BasicToolOperation as W}from"./basicToolOperation.js";import F from"./textAttributeClass.js";var K=Object.defineProperty,$=Object.defineProperties,V=Object.getOwnPropertyDescriptors,T=Object.getOwnPropertySymbols,X=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable,R=Math.pow,O=(m,t,e)=>t in m?K(m,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):m[t]=e,D=(m,t)=>{for(var e in t||(t={}))X.call(t,e)&&O(m,e,t[e]);if(T)for(var e of T(t))q.call(t,e)&&O(m,e,t[e]);return m},y=(m,t)=>$(m,V(t));const U=200;class G extends W{constructor(t){super(t);this.setMarkerIndex=s=>{this.markerIndex=s},this.setMarkerIndexAndSelect=s=>{if(!this.config.markerList)return;this.markerIndex=s;const o=this.config.markerList[s].value,n=this.currentPageResult.find(r=>r.label===o);n&&(this.setSelectedID(n.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(n.attribute)),this.emit("markIndexChange")},this.textChange=s=>{this.config.textConfigurable!==!0||!this.selectedID||(this.setPointList(v.textChange(s,this.selectedID,this.pointList)),this.emit("selectedChange"),this.render())},this.isMinDistance=s=>{const o=c.changePointByZoom(s,this.zoom);return this.pointList.some(n=>{const r=c.changePointByZoom(n,this.zoom);return z.getLineLength(r,o)<.2})};var e,i;this.config=h.jsonParser(t.config),this.pointList=[],this.markerIndex=0,this.setStyle(t.style),this.createPoint=this.createPoint.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this),this.forbidAddNew=(e=t.forbidAddNew)!=null?e:!1,this.forbidDelete=(i=t.forbidDelete)!=null?i:!1}get dataList(){return this.pointList}get drawOutsideTarget(){var t;return(t=this.config.drawOutsideTarget)!=null?t:this.config.drawPointOut}setNextMarker(t=this.pointList){if(this.hasMarkerConfig){const e=h.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndexAndSelect(e.index)}}setResult(t){this.clearActiveStatus(),this.setPointList(t),this.setNextMarker(t),this.recoverOperationMode(),this.render()}setPointList(t,e=!1){const i=this.pointList.length;this.pointList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}setConfig(t,e=!1){this.config=h.jsonParser(t),e===!0&&this.clearResult()}clearResult(){this.setPointList([]),this.setSelectedID(void 0),this.history.pushHistory([]),this.hoverID="",this.render()}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.pointList.forEach(s=>{s.id===i&&(s.attribute=t)}),this.history.pushHistory(this.pointList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}get selectedText(){var t;return(t=this.pointList.find(e=>e.id===this.selectedID))==null?void 0:t.textAttribute}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}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")}getTextIconSvg(t=""){return v.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}clearActiveStatus(){this.hoverID=void 0,this.dragStatus=f.Wait,this.setSelectedID(void 0)}setBasicResult(t){super.setBasicResult(t),this.setNextMarker(),this.clearActiveStatus()}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originPointList)==null?void 0:i.length)||(this.setPointList(this.dragInfo.originPointList.map(s=>y(D({},s),{x:s.x+t.x/this.zoom,y:s.y+t.y/this.zoom}))),this.render())}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation)){if(t.button===0&&!this.hoverID){this.recoverOperationMode(),this.createPoint(t),this.render();return}if((this.hoverID===this.selectedID||this.isMultiMoveMode&&this.hoverID)&&t.button===0){this.dragStatus=f.Start,this.dragInfo={dragStartCoord:this.getCoordinateUnderZoom(t),originPointList:N.cloneDeep(this.pointList)};return}return this.render(),!0}}onMouseMove(t){super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo||(this.hoverID=this.getHoverId(),(this.dragStatus===f.Start||this.dragStatus===f.Move)&&this.onDragMove(t),this.hoverID&&this.render())}onMouseUp(t){var e;if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;t.button===2&&this.rightMouseUp(),this.dragStatus===f.Move&&(this.history.pushHistory(this.pointList),this.emit("updatePointByDrag",this.pointList.find(i=>(i==null?void 0:i.id)===this.selectedID),(e=this.dragInfo)==null?void 0:e.originPointList),this.dragInfo=void 0),this.dragStatus=f.Wait,this.render()}onDragMove(t){var e,i;if(!this.imgInfo)return;this.dragStatus=f.Move;const s=this.getCoordinateUnderZoom(t);if(this.isMultiMoveMode&&this.dragInfo){const r={x:s.x-this.dragInfo.dragStartCoord.x,y:s.y-this.dragInfo.dragStartCoord.y};this.onDragMoveAll(r);return}const o=c.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutsideTarget,this.basicResult,this.zoom),n=this.drawOutsideTarget?c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos):c.changePointByZoom(o,1/this.zoom);this.drawOutsideTarget===!1&&this.dependToolName===p.Polygon&&((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&!L.isInPolygon(n,this.basicResult.pointList)||(this.pointList.forEach(r=>{r.id===this.selectedID&&(r.x=n.x,r.y=n.y)}),this.render())}onKeyDown(t){if(!h.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case S.Delete:this.deletePoint();break;case S.Tab:{this.onTabKeyDown(t);break}case S.Z:this.setIsHidden(!this.isHidden),this.render();break;default:{if(this.config.attributeConfigurable){const i=v.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}createPoint(t){var e,i,s,o;if(!this.imgInfo||this.forbidAddNew)return;const{upperLimit:n}=this.config;if(n&&this.currentPageResult.length>=n){this.emit("messageInfo",`${C.getMessagesByLocale(A.LowerLimitPoint,this.lang)}`);return}const r=h.getSourceID(this.basicResult),u=this.getCoordinateUnderZoom(t);let d=c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.config.edgeAdsorption&&this.referenceData&&[p.Polygon,p.Line].includes((e=this.referenceData)==null?void 0:e.toolName)){const b=((i=this.referenceData)==null?void 0:i.toolName)===p.Polygon,{dropFoot:I,hasClosed:M}=L.getClosestPoint(d,this.referenceData.result,(o=(s=this.referenceData.config)==null?void 0:s.lineType)!=null?o:_.Line,k/this.zoom,{isClose:b});I&&(d=I),M&&this.emit("messageSuccess",`${C.getMessagesByLocale(A.SuccessfulEdgeAdsorption,this.lang)}`)}if(this.drawOutsideTarget===!1){if(this.dependToolName&&this.basicCanvas){let l=!1;switch(this.dependToolName){case p.Rect:{l=!j.isInRect(d,this.basicResult);break}case p.Polygon:{l=!L.isInPolygon(d,this.basicResult.pointList);break}}if(l)return}if(u.x<0||u.y<0||u.x>this.imgInfo.width||u.y>this.imgInfo.height)return}if(this.isMinDistance(d))return;let a=y(D({},d),{attribute:this.defaultAttribute,valid:!t.ctrlKey,id:H(8,62),sourceID:r,textAttribute:"",order:h.getMaxOrder(this.pointList.filter(l=>h.isSameSourceID(l.sourceID,r)))+1});if(this.config.textConfigurable){let l="";l=v.getTextAttribute(this.pointList.filter(b=>h.isSameSourceID(b.sourceID,r)),this.config.textCheckType),a=y(D({},a),{textAttribute:l})}if(this.hasMarkerConfig){const l=h.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(l)a=y(D({},a),{label:l.label}),this.markerIndex=l.index,this.emit("markIndexChange");else{this.emit("messageInfo",C.getMessagesByLocale(A.MarkerFinish,this.lang));return}}this.hoverID=a.id;const g=[...this.pointList,a];this.setPointList(g),this.emit("pointCreated",a,this.zoom),this.history.pushHistory(g),this.setSelectedID(a.id)}isInPoint(t,e,i=this.zoom){return(this.style.width+2)/i>=Math.sqrt(R(t.x-e.x,2)+R(t.y-e.y,2))}getHoverId(){var t;const e=c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos),i=(t=this.pointList)==null?void 0:t.find(s=>this.isInPoint(e,s));return i==null?void 0:i.id}get selectedPoint(){return this.pointList.find(t=>t.id===this.selectedID)}rightMouseUp(){if(this.recoverOperationMode(),this.selectedID===this.hoverID){if(this.forbidDelete)return;const e=this.pointList.filter(i=>i.id!==this.selectedID);this.setPointList(e),this.history.pushHistory(e),this.emit("pointDeleted",this.selectedID),this.setSelectedID(""),this.hoverID="";return}const t=this.pointList.find(e=>e.id===this.hoverID);if(this.setSelectedID(this.hoverID),this.emit("pointSelected",this.hoverID),t&&this.setDefaultAttribute(t==null?void 0:t.attribute),(t==null?void 0:t.label)&&this.hasMarkerConfig){const e=h.getCurrentMarkerIndex(t.label,this.config.markerList);e>=0&&(this.setMarkerIndex(e),this.emit("markIndexChange"))}}onTabKeyDown(t){if(t.preventDefault(),this.dragStatus===f.Move||this.dragStatus===f.Start)return;let e=w.ascend;t.shiftKey&&(e=w.descend);const[i,s]=h.getRenderResultList(this.pointList,h.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let o=[...i];s&&(o=[...o,s]);const n=h.getNextSelectedRectID(o,e,this.selectedID);n&&this.setSelectedID(n.id)}get currentPageResult(){const[t]=h.getRenderResultList(this.pointList,h.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=h.getRenderResultList(t,h.getSourceID(this.basicResult),[]);return e}exportData(){const{pointList:t}=this;return[t,this.basicImgInfo]}deletePoint(){var t;this.selectedID&&(this.setPointList(this.pointList.filter(e=>e.id!==this.selectedID)),this.history.pushHistory(this.pointList),(t=this._textAttributInstance)==null||t.clearTextAttribute(),this.emit("selectedChange"),this.emit("pointDeleted",this.selectedID),this.render())}undoAndRedo(t){var e,i;if(this.dragStatus===f.Move||this.dragStatus===f.Start)return;const s=(i=(e=this.history)[t])==null?void 0:i.call(e);(s==null?void 0:s.some(o=>o.id===this.selectedID))||this.setSelectedID(""),s&&(this.setPointList(s,!0),this.render())}undo(){this.undoAndRedo("undo")}redo(){this.undoAndRedo("redo")}getCurrentSelectedData(){var t;if(!this.selectedID)return;const e=(t=this.pointList)==null?void 0:t.find(o=>o.id===this.selectedID),i=this.getColor(e==null?void 0:e.attribute),s=(e==null?void 0:e.valid)?i==null?void 0:i.valid.stroke:i==null?void 0:i.invalid.stroke;return this.dragStatus=f.Wait,{width:U*this.zoom*.6,textAttribute:(e==null?void 0:e.textAttribute)||"",color:s}}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.setPointList(v.textChange(e,this.selectedID,this.pointList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t,e;const i=(t=this.pointList)==null?void 0:t.find(b=>b.id===this.selectedID);if(!this.ctx||this.config.textConfigurable!==!0||!i)return;const{x:s,y:o,attribute:n,valid:r}=i,u=U*this.zoom*.6,d=c.getOffsetCoordinate({x:s,y:o},this.currentPos,this.zoom),a=this.getColor(n),g=r?a==null?void 0:a.valid.stroke:a==null?void 0:a.invalid.stroke,l=4;this._textAttributInstance||(this._textAttributInstance=new F({width:u,container:this.container,icon:this.getTextIconSvg(n),color:g,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((e=this._textAttributInstance)==null?void 0:e.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${i.textAttribute}`,{left:d.x,top:d.y+l,color:g,width:u})}renderPoint(t,e=!1){var i,s,o;const{textAttribute:n="",attribute:r}=t,u=e||t.id===this.selectedID,d=this.getColor(r),a=c.changePointByZoom(t,this.zoom,this.currentPos),{width:g=2,hiddenText:l=!1}=this.style,b=Z.getStrokeAndFill(d,t.valid,{isSelected:u||t.id===this.hoverID});x.drawCircle(this.canvas,a,g,{startAngleDeg:0,endAngleDeg:360,thickness:1,color:b.stroke,fill:b.fill});let I="";(((i=this.config)==null?void 0:i.isShowOrder)||((s=this.config)==null?void 0:s.showOrder))&&t.order&&(t==null?void 0:t.order)>0&&(I=`${t.order}`),t.label&&this.hasMarkerConfig&&(I=`${h.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${P.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&!this.config.hideAttribute&&(I=`${I} ${v.getAttributeShowText(t.attribute,(o=this.config)==null?void 0:o.attributeList)}`),l||x.drawText(this.canvas,{x:a.x+g/2,y:a.y-g-4},I,{textAlign:"center",color:b.stroke}),u?this.renderTextAttribute():l||x.drawText(this.canvas,{x:a.x+g,y:a.y+g+24},n,D({color:b.stroke},B))}renderMultiSelectedPoint(){!this.isMultiMoveMode||this.pointList.forEach(t=>{this.renderPoint(t,!0)})}renderPointList(){switch(this.operationMode){case E.MultiMove:this.renderMultiSelectedPoint();break;default:{const[t,e]=h.getRenderResultList(this.pointList,h.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);this.isHidden||t.forEach(i=>{this.renderPoint(i)}),e&&this.renderPoint(e)}}}renderAuxiliaryLine(){var t;if(!this.config.markerConfigurable||!((t=this.config.markerList)==null?void 0:t.length))return;const[e,i]=h.getRenderResultList(this.pointList,h.getSourceID(this.basicResult),this.attributeLockList,this.selectedID),s=e;if(i&&s.push(i),s.length<2)return;const o=P.getAuxiliaryLineByMarkerList(this.config.markerList,"value");P.getAuxiliaryLineCoord(o,s).forEach(r=>{const{start:u,end:d}=r,a=c.changePointListByZoom([u,d],this.zoom,this.currentPos);x.drawLine(this.canvas,a[0],a[1],{color:"#C5C5C5"})})}renderTop(){var t,e,i;const s=this.getLineColor(this.defaultAttribute);if(this.renderCursorLine(s),this.config.edgeAdsorption&&this.referenceData){let o=c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const n=((t=this.referenceData)==null?void 0:t.toolName)===p.Polygon,{dropFoot:r}=L.getClosestPoint(o,this.referenceData.result,(i=(e=this.referenceData.config)==null?void 0:e.lineType)!=null?i:_.Line,k/this.zoom,{isClose:n});r&&o!==r&&o!==r&&(o=r,x.drawCircle(this.canvas,c.changePointByZoom(o,this.zoom,this.currentPos),5,{color:"white",fill:"white"}),x.drawCircle(this.canvas,c.changePointByZoom(o,this.zoom,this.currentPos),3,{fill:s,color:s}))}}render(){!this.ctx||(super.render(),this.renderAuxiliaryLine(),this.renderPointList(),this.renderTop())}}export{G as default};
|
|
@@ -1 +1 @@
|
|
|
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};
|
|
1
|
+
import{i18n as _}from"@labelbee/lb-utils";import j from"lodash";import D from"../../utils/MathUtils.js";import N from"../../utils/tool/RectUtils.js";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 $ from"../../utils/ActionsHistory.js";import b from"../../utils/tool/AttributeUtils.js";import c 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 f from"../../utils/tool/PolygonUtils.js";import A from"../../utils/tool/StyleUtils.js";import M from"../../utils/uuid.js";import{BasicToolOperation as K}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,y=(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 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(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 $,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 f.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(y({},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.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?y(y({},i),t):i)}rotatePolygon(t=1,e=W.Clockwise,i=this.selectedID){if(!i)return;const s=f.getPolygonByID(this.polygonList,i);if(!s)return;const o=f.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}=f.getClosestPoint(o,this.polygonListUnderZoom,this.config.lineType,R),r=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(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(y({},i),{valid:!o})}return i});this.setPolygonList(e),this.history.pushHistory(this.polygonList),this.render(),this.emit("updateResult")}addDrawingPointToPolygonList(t){let{lowerLimitPointNum:e=3,minArea:i=1}=this.config;e<3&&(e=3),i<1&&(i=1);let s;if(this.drawingPointList.length<e){this.drawingPointList=[],this.editPolygonID="";return}if(f.calcPolygonSize(this.drawingPointList||[])<i){this.emit("messageInfo",`${C.getMessagesByLocale(S.MinAreaLimitErrorNotice,this.lang)}${i}`);return}const o=u.getSourceID(this.basicResult),l=[...this.polygonList];if(this.editPolygonID){const n=l.find(r=>r.id===this.editPolygonID);if(!n)return;n.pointList=this.drawingPointList,this.editPolygonID=""}else{const n=M(8,62);let r={id:n,sourceID:o,valid:!this.isCtrl,textAttribute:"",pointList:this.drawingPointList,attribute:this.defaultAttribute,order:u.getMaxOrder(l.filter(h=>u.isSameSourceID(h.sourceID,o)))+1};if(this.config.textConfigurable){let h="";h=b.getTextAttribute(this.polygonList.filter(d=>u.isSameSourceID(d.sourceID,o)),this.config.textCheckType),r=m(y({},r),{textAttribute:h})}this.pattern===w.Rect&&t===!0&&(r=m(y({},r),{isRect:!0})),l.push(r),s=r,this.setSelectedIdAfterAddingDrawing(n)}this.setPolygonList(l),this.isCtrl=!1,this.drawingPointList=[],this.history.pushHistory(l),s&&this.emit("polygonCreated",s,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(y({},o),{pointList:c.changePointListByZoom(o.pointList,this.zoom)}));return f.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 f.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=B.getViewPort(this.canvas,this.currentPos,this.zoom),l=s.map(r=>{var h,d,g,a;return m(y({},r),{x:(d=(h=r.pointList[0])==null?void 0:h.x)!=null?d:0,y:(a=(g=r.pointList[0])==null?void 0:g.y)!=null?a:0})}).filter(r=>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}=f.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 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=f.getPolygonPointList(this.selectedID,this.currentShowList),i=this.currentShowList.filter(l=>l.id!==this.selectedID);if(i.length===0||e.length===0)return;const s=f.getWrapPolygonIndex(e,i);let o=[...this.polygonList];if(s===-1){const l=f.segmentPolygonByPolygon(e,i);if(!l)return;const n=l.shift();if(!n)return;let r="",h=!0;const d=u.getSourceID(this.basicResult);let g="";o=this.polygonList.map(a=>{var p,T;return a.id===this.selectedID?(r=a.attribute,h=(p=a==null?void 0:a.valid)!=null?p:!0,g=(T=a==null?void 0:a.textAttribute)!=null?T:"",m(y({},a),{pointList:n})):a}),l.length>0&&l.forEach((a,p)=>{o.push({sourceID:d,id:M(8,62),pointList:a,valid:h,order:u.getMaxOrder(this.currentShowList)+1+p,attribute:r,textAttribute:g})})}else o[s].pointList=f.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=f.combinePolygonWithPolygon(s,o);if(!l)return;const{newPolygon:n,unionList:r}=l;if(r.length===1&&n){const h=this.polygonList.filter(d=>!r.includes(d.id)).map(d=>d.id===this.selectedID?n:d);this.setPolygonList(h),this.history.pushHistory(h),this.render(),this.emit("messageInfo",_.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=>!N.isInRect(r,this.basicResult)).length>0;break}case H.Polygon:{n=f.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)),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 d=D.getArrayIndex(n[0]-2,4),g=D.getArrayIndex(n[0]-1,4),a=[r[d],r[g]],p=D.getRectPerpendicularOffset(h,s,a);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=j.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(y({},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(y({},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(y({},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,d=c.getOffsetCoordinate({x:n,y:r},this.currentPos,this.zoom),g=this.getColor(s),a=o?g==null?void 0:g.valid.stroke:g==null?void 0:g.invalid.stroke;this._textAttributInstance||(this._textAttributInstance=new V({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(`${l}`,{left:d.x,top:d.y,color:a,width:h})}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.visiblePolygonList)==null||t.forEach(e=>{var i,s,o,l,n;if([this.selectedID,this.editPolygonID].includes(e.id))return;const{textAttribute:r,attribute:h}=e,d=this.getColor(h),g=A.getStrokeAndFill(d,e.valid),a=c.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);P.drawPolygonWithFillAndLine(this.canvas,a,{fillColor:g.fill,strokeColor:g.stroke,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(o=this.config)==null?void 0:o.lineType});let 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,a[0],p,y({color:g.stroke},k));const T=a[a.length-1];P.drawText(this.canvas,{x:T.x+E.x,y:T.y+E.y},r,y({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,c.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,c.changePointByZoom(s.pointList[0],this.zoom,this.currentPos),n,y({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,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),l=A.getStrokeAndFill(o,!this.isCtrl);if(((t=this.drawingPointList)==null?void 0:t.length)>0){let n=[...this.drawingPointList],r=c.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}=f.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,c.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:d,y:g}=c.changePointByZoom(h,this.zoom,this.currentPos);P.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=A.getStrokeAndFill(o,n.valid,{isSelected:!0});P.drawLineWithPointList(this.canvas,c.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/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{RectOperation}from"./core/toolOperation/rectOperation.js";export{default as TagOperation}from"./core/toolOperation/tagOperation.js";export{default as PointOperation}from"./core/toolOperation/pointOperation.js";export{default as LineToolOperation}from"./core/toolOperation/LineToolOperation.js";export{default as TextToolOperation}from"./core/toolOperation/TextToolOperation.js";export{default as PolygonOperation}from"./core/toolOperation/polygonOperation.js";export{default as MeasureOperation}from"./core/toolOperation/measureOperation.js";export{BasicToolOperation}from"./core/toolOperation/basicToolOperation.js";export{default as ViewOperation}from"./core/toolOperation/ViewOperation.js";export{default as ScribbleTool}from"./core/toolOperation/ScribbleTool.js";export{default as PointCloud2dOperation}from"./core/toolOperation/pointCloud2dOperation.js";import*as t from"./constant/annotation.js";export{t as cAnnotation};import*as e from"./constant/annotationTask.js";export{e as cAnnotationTask};import*as r from"./constant/keyCode.js";export{r as cKeyCode};import*as a from"./constant/style.js";export{a as cStyle};import*as i from"./constant/tool.js";export{i as cTool};export{CLIENT_TOOL_HEAD_TYPE,CLIENT_TOOL_NAME,DEFAULT_FONT,DEFAULT_TEXT_MAX_WIDTH,EAnnotationMode,EAuditStatus,ECheckModel,EDependPattern,EDragTarget,EDrawPointPattern,EFilterToolOperation,ELineColor,ELineTypes,EOperationMode,EPageOperator,EPointCloudName,EPolygonPattern,ERectPattern,EScribblePattern,ESelectedType,ETextType,EThumbnailOption,EToolName,EToolType,EVideoToolName,OPERATION_LIST,SEGMENT_NUMBER,TEXT_ATTRIBUTE_LINE_HEIGHT,TEXT_ATTRIBUTE_MAX_LENGTH,TEXT_TYPE,TOOL_NAME,TOOL_NAME_EN,edgeAdsorptionScope,editStepWidth}from"./constant/tool.js";export{default as TagUtils}from"./utils/tool/TagUtils.js";export{default as uuid}from"./utils/uuid.js";import o from"./utils/tool/EnhanceCommonToolUtils.js";export{default as MarkerUtils}from"./utils/tool/MarkerUtils.js";export{default as RectUtils}from"./utils/tool/RectUtils.js";export{default as AxisUtils}from"./utils/tool/AxisUtils.js";export{default as DrawUtils}from"./utils/tool/DrawUtils.js";export{default as ImgUtils}from"./utils/ImgUtils.js";export{default as MathUtils}from"./utils/MathUtils.js";export{default as AttributeUtils}from"./utils/tool/AttributeUtils.js";export{default as ActionsHistory}from"./utils/ActionsHistory.js";export{default as DblClickEventListener}from"./utils/tool/DblClickEventListener.js";export{default as AnnotationEngine}from"./core/index.js";export{default as UnitUtils}from"./utils/tool/UnitUtils.js";export{CanvasScheduler}from"./newCore/CanvasScheduler.js";export{PointCloud}from"./core/pointCloud/index.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,lidar2image,pointCloudLidar2image,rotatePoint,transferKitti2Matrix}from"./core/pointCloud/matrix.js";export{PointCloudAnnotation}from"./core/pointCloud/annotation.js";const s=o,
|
|
1
|
+
export{RectOperation}from"./core/toolOperation/rectOperation.js";export{default as TagOperation}from"./core/toolOperation/tagOperation.js";export{default as PointOperation}from"./core/toolOperation/pointOperation.js";export{default as LineToolOperation}from"./core/toolOperation/LineToolOperation.js";export{default as TextToolOperation}from"./core/toolOperation/TextToolOperation.js";export{default as PolygonOperation}from"./core/toolOperation/polygonOperation.js";export{default as MeasureOperation}from"./core/toolOperation/measureOperation.js";export{BasicToolOperation}from"./core/toolOperation/basicToolOperation.js";export{default as ViewOperation}from"./core/toolOperation/ViewOperation.js";export{default as ScribbleTool}from"./core/toolOperation/ScribbleTool.js";export{default as PointCloud2dOperation}from"./core/toolOperation/pointCloud2dOperation.js";import*as t from"./constant/annotation.js";export{t as cAnnotation};import*as e from"./constant/annotationTask.js";export{e as cAnnotationTask};import*as r from"./constant/keyCode.js";export{r as cKeyCode};import*as a from"./constant/style.js";export{a as cStyle};import*as i from"./constant/tool.js";export{i as cTool};export{CLIENT_TOOL_HEAD_TYPE,CLIENT_TOOL_NAME,DEFAULT_FONT,DEFAULT_TEXT_MAX_WIDTH,EAnnotationMode,EAuditStatus,ECheckModel,EDependPattern,EDragTarget,EDrawPointPattern,EFilterToolOperation,ELineColor,ELineTypes,EOperationMode,EPageOperator,EPointCloudName,EPolygonPattern,ERectPattern,EScribblePattern,ESelectedType,ETextType,EThumbnailOption,EToolName,EToolType,EVideoToolName,OPERATION_LIST,SEGMENT_NUMBER,TEXT_ATTRIBUTE_LINE_HEIGHT,TEXT_ATTRIBUTE_MAX_LENGTH,TEXT_TYPE,TOOL_NAME,TOOL_NAME_EN,edgeAdsorptionScope,editStepWidth}from"./constant/tool.js";export{default as TagUtils}from"./utils/tool/TagUtils.js";export{default as uuid}from"./utils/uuid.js";import o from"./utils/tool/EnhanceCommonToolUtils.js";export{default as MarkerUtils}from"./utils/tool/MarkerUtils.js";export{default as RectUtils}from"./utils/tool/RectUtils.js";export{default as AxisUtils}from"./utils/tool/AxisUtils.js";export{default as DrawUtils}from"./utils/tool/DrawUtils.js";export{default as ImgUtils}from"./utils/ImgUtils.js";export{default as MathUtils}from"./utils/MathUtils.js";export{default as AttributeUtils}from"./utils/tool/AttributeUtils.js";export{default as ActionsHistory}from"./utils/ActionsHistory.js";export{default as DblClickEventListener}from"./utils/tool/DblClickEventListener.js";export{default as AnnotationEngine}from"./core/index.js";export{default as UnitUtils}from"./utils/tool/UnitUtils.js";export{default as StyleUtils}from"./utils/tool/StyleUtils.js";export{CanvasScheduler}from"./newCore/CanvasScheduler.js";export{PointCloud}from"./core/pointCloud/index.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,lidar2image,pointCloudLidar2image,rotatePoint,transferKitti2Matrix}from"./core/pointCloud/matrix.js";export{PointCloudAnnotation}from"./core/pointCloud/annotation.js";const s=o,l=o;export{s as CommonToolUtils,l as toolUtils};
|
package/es/locales/constants.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var i;(function(r){r.NoRotateNotice="noRotateNotice",r.RectErrorSizeNotice="rectErrorSizeNotice",r.TextCheckNumberErrorNotice="textCheckNumberErrorNotice",r.TextCheckEnglishErrorNotice="textCheckEnglishErrorNotice",r.TextCheckCustomErrorNotice="textCheckCustomErrorNotice",r.UpperLimitErrorNotice="UpperLimitErrorNotice",r.LowerLimitErrorNotice="LowerLimitErrorNotice",r.MinAreaLimitErrorNotice="MinAreaLimitErrorNotice",r.MinLengthLimitErrorNotice="MinLengthLimitErrorNotice",r.InvalidImage="InvalidImage",r.DisableDelete="DisableDelete",r.ClearPartialData="ClearPartialData",r.MarkerFinish="MarkerFinish",r.LowerLimitPoint="LowerLimitPoint",r.NoRotateInDependence="noRotateInDependence",r.UnableToReannotation="unableToReannotation",r.ForbiddenCreationOutsideBoundary="ForbiddenCreationOutsideBoundary",r.SuccessfulEdgeAdsorption="SuccessfulEdgeAdsorption",r.ForbidAddNewPoint="ForbidAddNewPoint"})(i||(i={}));export{i as EMessage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EMessage as e}from"../constants.js";const t={[e.NoRotateNotice]:"This Image contains data and cannot be rotated",[e.RectErrorSizeNotice]:"The drawing frame size is smaller than the minimum drawing size",[e.TextCheckNumberErrorNotice]:"Please enter in number-only format",[e.TextCheckEnglishErrorNotice]:"Please enter in English only format",[e.TextCheckCustomErrorNotice]:"Please enter in the required format",[e.UpperLimitErrorNotice]:"The number of vertices is not more than",[e.LowerLimitErrorNotice]:"The number of vertices is not less than",[e.InvalidImage]:"Invalid image, please skip this image",[e.DisableDelete]:"Disable delete",[e.ClearPartialData]:"Clear partial data",[e.MarkerFinish]:"ListAnnotation is finished",[e.LowerLimitPoint]:"The maximum number of points has been reached",[e.NoRotateInDependence]:"Disallow rotation in dependent cases",[e.UnableToReannotation]:"Unabled to reannotation",[e.ForbiddenCreationOutsideBoundary]:"Fobid creation outside boundary",[e.SuccessfulEdgeAdsorption]:"Successful edge adsorption",[e.ForbidAddNewPoint]:"Forbid to add new point in rect-polygon"};export{t as default};
|
|
1
|
+
import{EMessage as e}from"../constants.js";const t={[e.NoRotateNotice]:"This Image contains data and cannot be rotated",[e.RectErrorSizeNotice]:"The drawing frame size is smaller than the minimum drawing size",[e.TextCheckNumberErrorNotice]:"Please enter in number-only format",[e.TextCheckEnglishErrorNotice]:"Please enter in English only format",[e.TextCheckCustomErrorNotice]:"Please enter in the required format",[e.UpperLimitErrorNotice]:"The number of vertices is not more than",[e.LowerLimitErrorNotice]:"The number of vertices is not less than",[e.MinAreaLimitErrorNotice]:"Minimum area is not less than",[e.MinLengthLimitErrorNotice]:"Length is not less than",[e.InvalidImage]:"Invalid image, please skip this image",[e.DisableDelete]:"Disable delete",[e.ClearPartialData]:"Clear partial data",[e.MarkerFinish]:"ListAnnotation is finished",[e.LowerLimitPoint]:"The maximum number of points has been reached",[e.NoRotateInDependence]:"Disallow rotation in dependent cases",[e.UnableToReannotation]:"Unabled to reannotation",[e.ForbiddenCreationOutsideBoundary]:"Fobid creation outside boundary",[e.SuccessfulEdgeAdsorption]:"Successful edge adsorption",[e.ForbidAddNewPoint]:"Forbid to add new point in rect-polygon"};export{t as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EMessage as u}from"../constants.js";const
|
|
1
|
+
import{EMessage as u}from"../constants.js";const E={[u.NoRotateNotice]:"\u672C\u56FE\u542B\u6709\u6570\u636E\uFF0C\u65E0\u6CD5\u8FDB\u884C\u65CB\u8F6C",[u.RectErrorSizeNotice]:"\u7ED8\u5236\u6846\u5C3A\u5BF8\u5C0F\u4E8E\u6700\u5C0F\u7ED8\u5236\u5C3A\u5BF8",[u.TextCheckNumberErrorNotice]:"\u8BF7\u6309\u4EC5\u6570\u5B57\u7684\u683C\u5F0F\u8F93\u5165",[u.TextCheckEnglishErrorNotice]:"\u8BF7\u6309\u4EC5\u82F1\u6587\u7684\u683C\u5F0F\u8F93\u5165",[u.TextCheckCustomErrorNotice]:"\u8BF7\u6309\u8981\u6C42\u7684\u683C\u5F0F\u8F93\u5165",[u.UpperLimitErrorNotice]:"\u9876\u70B9\u6570\u4E0D\u591A\u4E8E",[u.LowerLimitErrorNotice]:"\u9876\u70B9\u6570\u4E0D\u5C11\u4E8E",[u.MinAreaLimitErrorNotice]:"\u6700\u5C0F\u9762\u79EF\u4E0D\u5C0F\u4E8E",[u.MinLengthLimitErrorNotice]:"\u957F\u5EA6\u4E0D\u5C0F\u4E8E",[u.InvalidImage]:"\u65E0\u6548\u56FE\u7247\uFF0C\u8BF7\u8DF3\u8FC7\u6B64\u56FE",[u.DisableDelete]:"\u8BE5\u6570\u636E\u7981\u6B62\u5220\u9664",[u.ClearPartialData]:"\u5B58\u5728\u90E8\u5206\u6570\u636E\u65E0\u6CD5\u6E05\u9664",[u.MarkerFinish]:"\u5217\u8868\u6807\u6CE8\u5DF2\u5B8C\u6210",[u.LowerLimitPoint]:"\u5DF2\u5230\u8FBE\u6807\u70B9\u6570\u91CF\u4E0A\u9650",[u.NoRotateInDependence]:"\u4F9D\u8D56\u60C5\u51B5\u4E0B\u65E0\u6CD5\u8FDB\u884C\u65CB\u8F6C",[u.UnableToReannotation]:"\u65E0\u6CD5\u8FDB\u884C\u7EED\u6807\u64CD\u4F5C",[u.ForbiddenCreationOutsideBoundary]:"\u8FB9\u754C\u5916\u7981\u6B62\u521B\u5EFA",[u.SuccessfulEdgeAdsorption]:"\u8FB9\u7F18\u5438\u9644\u6210\u529F",[u.ForbidAddNewPoint]:"\u6846\u4F53\u65E0\u6CD5\u6DFB\u52A0\u70B9"};export{E as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isNumber as I}from"lodash";import{ToolStyleUtils as O}from"@labelbee/lb-utils";import{
|
|
1
|
+
import{isNumber as I}from"lodash";import{ToolStyleUtils as O}from"@labelbee/lb-utils";import{ICON_ARRAY as c,NULL_ICON as E,NULL_COLOR as f,COLORS_ARRAY as d}from"../../constant/style.js";import{ETextType as s}from"../../constant/tool.js";import g from"../../locales/index.js";import{EMessage as p}from"../../locales/constants.js";import h from"../MathUtils.js";import y from"../../assets/attributeIcon/icon_canvasEdit_miss.svg.js";var w=Object.defineProperty,N=Object.defineProperties,P=Object.getOwnPropertyDescriptors,v=Object.getOwnPropertySymbols,R=Object.prototype.hasOwnProperty,T=Object.prototype.propertyIsEnumerable,x=(l,t,r)=>t in l?w(l,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):l[t]=r,b=(l,t)=>{for(var r in t||(t={}))R.call(t,r)&&x(l,r,t[r]);if(v)for(var r of v(t))T.call(t,r)&&x(l,r,t[r]);return l},m=(l,t)=>N(l,P(t));const _="^[0-9]+$",A="^[A-Za-z]+$";class M{static getAttributeIcon(t,r,e=!0){var n;const a=r.findIndex(o=>o.value===t);let i=(n=c[a%c.length])!=null?n:E;e||(i=y),i="";const u=new Image;return u.src=i,u}static checkString(t,r){let e="";switch(t){case s.Order:case s.NumberOnly:e=_;break;case s.EnglishOnly:e=A;break;case s.CustomFormat:e=r;break}return e}static checkTextAttibute(t,r){if(t===void 0||t==="")return!0;try{return new RegExp(r).test(t)}catch(e){return!1}}static getAttributeShowText(t,r=[]){var e,n;try{const a=r.findIndex(i=>i.value===t);return(n=(e=r[a])==null?void 0:e.key)!=null?n:t}catch(a){return t}}static getAttributeIndex(t,r){try{const e=r.findIndex(n=>n.value===t);return e>=8?e%8:e}catch(e){return-1}}static getAttributeColor(t,r){try{const e=this.getAttributeIndex(t,r);return e===-1?f:d[e%d.length]}catch(e){return f}}static getTextAttribute(t,r){try{if(r===s.Order){const e=t.map(a=>parseInt(a.textAttribute,10)).filter(a=>I(a)&&a<Number.MAX_SAFE_INTEGER&&a>=0);return e.sort((a,i)=>a-i),`${(e.pop()||0)+1}`}return""}catch(e){return""}}static textChange(t,r,e){return e.map(n=>n.id===r?m(b({},n),{textAttribute:t}):n)}static getErrorNotice(t,r){switch(t){case s.Order:case s.NumberOnly:return g.getMessagesByLocale(p.TextCheckNumberErrorNotice,r);case s.EnglishOnly:return g.getMessagesByLocale(p.TextCheckEnglishErrorNotice,r);case s.CustomFormat:return g.getMessagesByLocale(p.TextCheckCustomErrorNotice,r);default:return""}}static textAttributeValidate(t,r,e){try{return new RegExp(this.checkString(t,r)).test(e)}catch(n){}}static checkTextAttribute(t,r,e,n){let a=!1;return e.forEach(i=>{(i==null?void 0:i.textAttribute)===void 0||(i==null?void 0:i.textAttribute)===""||(n?i.id===n:!0)&&!this.textAttributeValidate(t,r,i.textAttribute)&&(a=!0)}),!!a}static changeTextAttributeInLog(t,r){return t==null?void 0:t.map(e=>e==null?void 0:e.map(n=>{if((r==null?void 0:r.findIndex(a=>(a==null?void 0:a.id)===(n==null?void 0:n.id)))>-1){const a=r==null?void 0:r.find(i=>(i==null?void 0:i.id)===(n==null?void 0:n.id));return m(b({},n),{textAttribute:a==null?void 0:a.textAttribute})}return n}))}static getTextIconSvg(t="",r,e=!1,n){var a;if(e===!0){const i=(r==null?void 0:r.findIndex(o=>(o==null?void 0:o.value)===t))%d.length+1,u=(a=r==null?void 0:r.find(o=>o.value===t))==null?void 0:a.color;if(u){const o=O.rgbaStringToHex(u);return this.generateIconAttribute({fill:o})}return c[i]}return n}static generateIconAttribute({fill:t,width:r=16,height:e=16,xmlns:n="http://www.w3.org/2000/svg",xlink:a="http://www.w3.org/1999/xlink"}){return`<span style={color:${t}}><svg xmlns=${n} xmlns:xlink=${a} width=${r} height=${e} viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill='currentColor'/></g></g></svg></span>`}static getAttributeByKeycode(t,r){var e;let n;return h.isInRange(t,[48,57])&&(n=t-48),h.isInRange(t,[96,105])&&(n=t-96),n===0?"":n?(e=r[n-1])==null?void 0:e.value:void 0}}export{A as REGEXP_ENGLISH,_ as REGEXP_NUMBER,M as default};
|