@labelbee/lb-annotation 1.14.0-alpha.2 → 1.14.0-alpha.3

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.
Files changed (187) hide show
  1. package/dist/_virtual/MathUtilsWorker.js +8 -1
  2. package/dist/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +35 -2
  3. package/dist/_virtual/filterBoxWorker.js +8 -1
  4. package/dist/_virtual/highlightWorker.js +8 -1
  5. package/dist/assets/attributeIcon/icon_canvasEdit0.svg.js +5 -1
  6. package/dist/assets/attributeIcon/icon_canvasEdit1.svg.js +5 -1
  7. package/dist/assets/attributeIcon/icon_canvasEdit2.svg.js +5 -1
  8. package/dist/assets/attributeIcon/icon_canvasEdit3.svg.js +5 -1
  9. package/dist/assets/attributeIcon/icon_canvasEdit4.svg.js +5 -1
  10. package/dist/assets/attributeIcon/icon_canvasEdit5.svg.js +5 -1
  11. package/dist/assets/attributeIcon/icon_canvasEdit6.svg.js +5 -1
  12. package/dist/assets/attributeIcon/icon_canvasEdit7.svg.js +5 -1
  13. package/dist/assets/attributeIcon/icon_canvasEdit8.svg.js +5 -1
  14. package/dist/assets/attributeIcon/icon_canvasEdit_miss.svg.js +5 -1
  15. package/dist/assets/attributeIcon/icon_cuboidFAB.svg.js +5 -5
  16. package/dist/assets/attributeIcon/icon_cuboidLeft.svg.js +5 -7
  17. package/dist/assets/attributeIcon/icon_cuboidMore.svg.js +5 -5
  18. package/dist/assets/attributeIcon/icon_cuboidRight.svg.js +5 -5
  19. package/dist/assets/attributeIcon/icon_cuboidTop.svg.js +5 -12
  20. package/dist/assets/attributeIcon/icon_editFEN.svg.js +5 -1
  21. package/dist/assets/attributeIcon/icon_editHUANG.svg.js +5 -1
  22. package/dist/assets/attributeIcon/icon_editLAN.svg.js +5 -1
  23. package/dist/assets/attributeIcon/icon_editLV.svg.js +5 -1
  24. package/dist/assets/attributeIcon/icon_editQING.svg.js +5 -1
  25. package/dist/constant/annotation.js +127 -1
  26. package/dist/constant/annotationTask.js +30 -1
  27. package/dist/constant/defaultConfig.js +266 -1
  28. package/dist/constant/keyCode.js +38 -1
  29. package/dist/constant/style.js +98 -1
  30. package/dist/constant/tool.js +236 -1
  31. package/dist/core/index.js +150 -1
  32. package/dist/core/pointCloud/OrbitControls.js +665 -1
  33. package/dist/core/pointCloud/PCDLoader.js +260 -2
  34. package/dist/core/pointCloud/annotation.js +215 -1
  35. package/dist/core/pointCloud/cache.js +53 -1
  36. package/dist/core/pointCloud/index.js +991 -5
  37. package/dist/core/pointCloud/matrix.js +138 -1
  38. package/dist/core/pointCloud/segmentation.js +144 -0
  39. package/dist/core/pointCloud/selector/Sse3dLassoSelector.js +26 -0
  40. package/dist/core/pointCloud/selector/Sse3dSelector.js +16 -0
  41. package/dist/core/scheduler.js +233 -1
  42. package/dist/core/toolOperation/LineToolOperation.js +1434 -1
  43. package/dist/core/toolOperation/ScribbleTool.js +292 -1
  44. package/dist/core/toolOperation/TextToolOperation.js +131 -1
  45. package/dist/core/toolOperation/ViewOperation.js +556 -1
  46. package/dist/core/toolOperation/basicToolOperation.js +881 -1
  47. package/dist/core/toolOperation/checkOperation.js +208 -1
  48. package/dist/core/toolOperation/cuboidOperation.js +754 -1
  49. package/dist/core/toolOperation/cuboidToggleButtonClass.js +152 -7
  50. package/dist/core/toolOperation/eventListener.js +37 -1
  51. package/dist/core/toolOperation/measureOperation.js +41 -1
  52. package/dist/core/toolOperation/pointCloud2dOperation.js +365 -1
  53. package/dist/core/toolOperation/pointOperation.js +696 -1
  54. package/dist/core/toolOperation/polygonOperation.js +1251 -1
  55. package/dist/core/toolOperation/rectOperation.js +1233 -1
  56. package/dist/core/toolOperation/segmentByRect.js +174 -1
  57. package/dist/core/toolOperation/tagOperation.js +201 -3
  58. package/dist/core/toolOperation/textAttributeClass.js +182 -16
  59. package/dist/index.js +185 -1
  60. package/dist/locales/constants.js +24 -1
  61. package/dist/locales/en_US/message.js +25 -1
  62. package/dist/locales/index.js +19 -1
  63. package/dist/locales/zh_CN/message.js +25 -1
  64. package/dist/newCore/CanvasScheduler.js +35 -1
  65. package/dist/types/core/pointCloud/segmentation.d.ts +0 -0
  66. package/dist/types/core/pointCloud/selector/Sse3dLassoSelector.d.ts +0 -0
  67. package/dist/types/core/pointCloud/selector/Sse3dSelector.d.ts +0 -0
  68. package/dist/utils/ActionsHistory.js +84 -1
  69. package/dist/utils/ImgUtils.js +23 -1
  70. package/dist/utils/MathUtils.js +385 -2
  71. package/dist/utils/VectorUtils.js +25 -1
  72. package/dist/utils/tool/AttributeUtils.js +218 -1
  73. package/dist/utils/tool/AxisUtils.js +340 -1
  74. package/dist/utils/tool/CanvasUtils.js +62 -1
  75. package/dist/utils/tool/CommonToolUtils.js +174 -1
  76. package/dist/utils/tool/CuboidUtils.js +704 -1
  77. package/dist/utils/tool/DblClickEventListener.js +102 -1
  78. package/dist/utils/tool/DrawUtils.js +492 -3
  79. package/dist/utils/tool/EnhanceCommonToolUtils.js +53 -1
  80. package/dist/utils/tool/ImgPosUtils.js +58 -1
  81. package/dist/utils/tool/LineToolUtils.js +261 -1
  82. package/dist/utils/tool/MarkerUtils.js +56 -1
  83. package/dist/utils/tool/PolygonUtils.js +460 -1
  84. package/dist/utils/tool/RectUtils.js +155 -1
  85. package/dist/utils/tool/RenderDomClass.js +57 -7
  86. package/dist/utils/tool/RenderDomUtils.js +21 -4
  87. package/dist/utils/tool/StyleUtils.js +31 -1
  88. package/dist/utils/tool/TagUtils.js +129 -1
  89. package/dist/utils/tool/UnitUtils.js +12 -1
  90. package/dist/utils/tool/ZoomUtils.js +72 -1
  91. package/dist/utils/tool/polygonTool.js +133 -1
  92. package/dist/utils/uuid.js +26 -1
  93. package/es/_virtual/MathUtilsWorker.js +6 -1
  94. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +12 -0
  95. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +7 -0
  96. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +31 -2
  97. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +11 -0
  98. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +18 -0
  99. package/es/_virtual/filterBoxWorker.js +6 -1
  100. package/es/_virtual/highlightWorker.js +6 -1
  101. package/es/assets/attributeIcon/icon_canvasEdit0.svg.js +3 -1
  102. package/es/assets/attributeIcon/icon_canvasEdit1.svg.js +3 -1
  103. package/es/assets/attributeIcon/icon_canvasEdit2.svg.js +3 -1
  104. package/es/assets/attributeIcon/icon_canvasEdit3.svg.js +3 -1
  105. package/es/assets/attributeIcon/icon_canvasEdit4.svg.js +3 -1
  106. package/es/assets/attributeIcon/icon_canvasEdit5.svg.js +3 -1
  107. package/es/assets/attributeIcon/icon_canvasEdit6.svg.js +3 -1
  108. package/es/assets/attributeIcon/icon_canvasEdit7.svg.js +3 -1
  109. package/es/assets/attributeIcon/icon_canvasEdit8.svg.js +3 -1
  110. package/es/assets/attributeIcon/icon_canvasEdit_miss.svg.js +3 -1
  111. package/es/assets/attributeIcon/icon_cuboidFAB.svg.js +3 -5
  112. package/es/assets/attributeIcon/icon_cuboidLeft.svg.js +3 -7
  113. package/es/assets/attributeIcon/icon_cuboidMore.svg.js +3 -5
  114. package/es/assets/attributeIcon/icon_cuboidRight.svg.js +3 -5
  115. package/es/assets/attributeIcon/icon_cuboidTop.svg.js +3 -12
  116. package/es/assets/attributeIcon/icon_editFEN.svg.js +3 -1
  117. package/es/assets/attributeIcon/icon_editHUANG.svg.js +3 -1
  118. package/es/assets/attributeIcon/icon_editLAN.svg.js +3 -1
  119. package/es/assets/attributeIcon/icon_editLV.svg.js +3 -1
  120. package/es/assets/attributeIcon/icon_editQING.svg.js +3 -1
  121. package/es/constant/annotation.js +113 -1
  122. package/es/constant/annotationTask.js +25 -1
  123. package/es/constant/defaultConfig.js +260 -1
  124. package/es/constant/keyCode.js +36 -1
  125. package/es/constant/style.js +74 -1
  126. package/es/constant/tool.js +220 -1
  127. package/es/core/index.js +148 -1
  128. package/es/core/pointCloud/OrbitControls.js +661 -1
  129. package/es/core/pointCloud/PCDLoader.js +256 -2
  130. package/es/core/pointCloud/annotation.js +211 -1
  131. package/es/core/pointCloud/cache.js +49 -1
  132. package/es/core/pointCloud/index.js +962 -5
  133. package/es/core/pointCloud/matrix.js +109 -1
  134. package/es/core/pointCloud/segmentation.js +120 -0
  135. package/es/core/pointCloud/selector/Sse3dLassoSelector.js +24 -0
  136. package/es/core/pointCloud/selector/Sse3dSelector.js +14 -0
  137. package/es/core/scheduler.js +228 -1
  138. package/es/core/toolOperation/LineToolOperation.js +1421 -1
  139. package/es/core/toolOperation/ScribbleTool.js +290 -1
  140. package/es/core/toolOperation/TextToolOperation.js +129 -1
  141. package/es/core/toolOperation/ViewOperation.js +549 -1
  142. package/es/core/toolOperation/basicToolOperation.js +877 -1
  143. package/es/core/toolOperation/checkOperation.js +206 -1
  144. package/es/core/toolOperation/cuboidOperation.js +752 -1
  145. package/es/core/toolOperation/cuboidToggleButtonClass.js +150 -7
  146. package/es/core/toolOperation/eventListener.js +35 -1
  147. package/es/core/toolOperation/measureOperation.js +39 -1
  148. package/es/core/toolOperation/pointCloud2dOperation.js +359 -1
  149. package/es/core/toolOperation/pointOperation.js +690 -1
  150. package/es/core/toolOperation/polygonOperation.js +1245 -1
  151. package/es/core/toolOperation/rectOperation.js +1228 -1
  152. package/es/core/toolOperation/scribbleTool2.js +249 -0
  153. package/es/core/toolOperation/segmentByRect.js +172 -1
  154. package/es/core/toolOperation/tagOperation.js +199 -3
  155. package/es/core/toolOperation/textAttributeClass.js +180 -16
  156. package/es/index.js +46 -1
  157. package/es/locales/constants.js +22 -1
  158. package/es/locales/en_US/message.js +23 -1
  159. package/es/locales/index.js +17 -1
  160. package/es/locales/zh_CN/message.js +23 -1
  161. package/es/newCore/CanvasScheduler.js +31 -1
  162. package/es/utils/ActionsHistory.js +78 -1
  163. package/es/utils/ImgUtils.js +21 -1
  164. package/es/utils/MathUtils.js +380 -2
  165. package/es/utils/VectorUtils.js +23 -1
  166. package/es/utils/tool/AttributeUtils.js +212 -1
  167. package/es/utils/tool/AxisUtils.js +335 -1
  168. package/es/utils/tool/CanvasUtils.js +60 -1
  169. package/es/utils/tool/CommonToolUtils.js +172 -1
  170. package/es/utils/tool/CuboidUtils.js +680 -1
  171. package/es/utils/tool/DblClickEventListener.js +100 -1
  172. package/es/utils/tool/DrawUtils.js +490 -3
  173. package/es/utils/tool/EnhanceCommonToolUtils.js +48 -1
  174. package/es/utils/tool/ImgPosUtils.js +56 -1
  175. package/es/utils/tool/LineToolUtils.js +255 -1
  176. package/es/utils/tool/MarkerUtils.js +54 -1
  177. package/es/utils/tool/PolygonUtils.js +458 -1
  178. package/es/utils/tool/RectUtils.js +153 -1
  179. package/es/utils/tool/RenderDomClass.js +55 -7
  180. package/es/utils/tool/RenderDomUtils.js +19 -4
  181. package/es/utils/tool/StyleUtils.js +29 -1
  182. package/es/utils/tool/TagUtils.js +127 -1
  183. package/es/utils/tool/UnitUtils.js +10 -1
  184. package/es/utils/tool/ZoomUtils.js +70 -1
  185. package/es/utils/tool/polygonTool.js +126 -1
  186. package/es/utils/uuid.js +24 -1
  187. package/package.json +7 -5
@@ -1 +1,1251 @@
1
- "use strict";var lbUtils=require("@labelbee/lb-utils"),MathUtils=require("../../utils/MathUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),_=require("lodash"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),tool=require("../../constant/tool.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js");function _interopDefaultLegacy(c){return c&&typeof c=="object"&&"default"in c?c:{default:c}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(c,t,e)=>t in c?__defProp(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e,__spreadValues=(c,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(c,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(c,e,t[e]);return c},__spreadProps=(c,t)=>__defProps(c,__getOwnPropDescs(t));const TEXT_MAX_WIDTH=164;class PolygonOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.isAllowDouble=e=>{const{selectedID:i}=this,s=this.getHoverID(e);return!!(i&&i===s)},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.setPolygonList(AttributeUtils.default.textChange(e,this.selectedID,this.polygonList)),this.emit("selectedChange"),this.render())},this.emitUpdatePolygonByDrag=()=>{if(this.dragInfo){const{originPolygon:e}=this.dragInfo;this.emit("updatePolygonByDrag",[{newPolygon:this.selectedPolygon,originPolygon:e}])}},this.config=CommonToolUtils.jsonParser(t.config),this.drawingPointList=[],this.polygonList=[],this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.drawingHistory=new ActionsHistory,this.isCtrl=!1,this.isAlt=!1,this.isCombined=!1,this.pattern=tool.EPolygonPattern.Normal,this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this)}eventBinding(){super.eventBinding(),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseup",this.dragMouseUp),this.dblClickListener.addEvent(this.onMouseUp,this.onLeftDblClick,this.onRightDblClick,this.isAllowDouble)}eventUnbinding(){super.eventUnbinding(),this.container.removeEventListener("mouseup",this.dragMouseUp)}destroy(){super.destroy(),this._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}get selectedPolygon(){return PolygonUtils.getPolygonByID(this.visiblePolygonList,this.selectedID)}get hoverPolygon(){return this.visiblePolygonList.find(t=>t.id===this.hoverID&&t.id!==this.selectedID)}get enableDrag(){return Boolean(this.selectedID&&this.dragInfo)}get visiblePolygonList(){return this.polygonList}get polygonListUnderZoom(){return this.visiblePolygonList.map(t=>__spreadProps(__spreadValues({},t),{pointList:AxisUtils.default.changePointListByZoom(t.pointList,this.zoom)}))}get selectedText(){var t;return(t=this.selectedPolygon)==null?void 0:t.textAttribute}get dataList(){return this.polygonList}setPattern(t,e=!1){var i;((i=this.drawingPointList)==null?void 0:i.length)>0&&e===!0||(this.pattern=t)}get currentShowList(){let t=[];const[e,i]=CommonToolUtils.getRenderResultList(this.visiblePolygonList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=e,this.isHidden&&(t=[]),i&&t.push(i),t}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}setResult(t){this.clearActiveStatus(),this.setPolygonList(t),this.render()}setPolygonDataByID(t,e){return this.polygonList.map(i=>i.id===e?__spreadValues(__spreadValues({},i),t):i)}rotatePolygon(t=1,e=annotation.ERotateDirection.Clockwise,i=this.selectedID){if(!i)return;const s=PolygonUtils.getPolygonByID(this.polygonList,i);if(!s)return;const o=PolygonUtils.updatePolygonByRotate(e,t,s==null?void 0:s.pointList);this.setPolygonList(this.setPolygonDataByID({pointList:o},i)),this.render()}addPointInDrawing(t){if(!this.imgInfo||this.forbidAddNewPolygonFuc&&this.forbidAddNewPolygonFuc(t))return;const{upperLimitPointNum:e,edgeAdsorption:i}=this.config;if(e&&this.drawingPointList.length>=e){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UpperLimitErrorNotice,this.lang)}${e}`);return}this.deleteSelectedID();const s=this.getCoordinateUnderZoom(t),o=AxisUtils.default.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(AxisUtils.default.returnClosePointIndex(o,AxisUtils.default.changePointListByZoom(this.drawingPointList,this.zoom))===0){this.addDrawingPointToPolygonList();return}const{dropFoot:n}=PolygonUtils.getClosestPoint(o,this.polygonListUnderZoom,this.config.lineType,tool.edgeAdsorptionScope),r=AxisUtils.default.changePointByZoom(n&&t.altKey===!1&&i?n:o,1/this.zoom);if(this.pattern===tool.EPolygonPattern.Rect&&this.drawingPointList.length===2){const a=MathUtils.default.getRectangleByRightAngle(r,this.drawingPointList);if(this.drawingPointList=a,this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(this.drawingPointList)){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.ForbiddenCreationOutsideBoundary,this.lang)}`),this.drawingPointList=[];return}this.addDrawingPointToPolygonList(!0);return}this.drawingPointList.push(r),this.drawingPointList.length===1?this.drawingHistory.initRecord(this.drawingPointList):this.drawingHistory.pushHistory(this.drawingPointList)}clearResult(){this.setPolygonList([]),this.deleteSelectedID(),this.render()}clearPolygonDrag(){this.drawingPointList=[],this.dragInfo=void 0,this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,this.hoverID=""}clearActiveStatus(){this.clearPolygonDrag(),this.deleteSelectedID()}clearDrawingStatus(){this.drawingPointList=[]}setPolygonList(t){const e=this.polygonList.length;this.polygonList=t,e!==t.length&&this.emit("updatePageNumber")}setSelectedID(t){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.render(),this.emit("selectedChange")}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedID:i}=this;if(i&&(this.selectedPolygon&&(this.selectedPolygon.attribute=t),this.history.pushHistory(this.polygonList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}setPolygonValidAndRender(t){if(!t)return;const e=this.polygonList.map(i=>{var s;if(i.id===t){const o=(s=i==null?void 0:i.valid)!=null?s:!0;return __spreadProps(__spreadValues({},i),{valid:!o})}return i});this.setPolygonList(e),this.history.pushHistory(this.polygonList),this.render(),this.emit("updateResult")}addDrawingPointToPolygonList(t){let{lowerLimitPointNum:e=3}=this.config;e<3&&(e=3);let i;if(this.drawingPointList.length<e){this.drawingPointList=[],this.editPolygonID="";return}const s=CommonToolUtils.getSourceID(this.basicResult),o=[...this.polygonList];if(this.editPolygonID){const l=o.find(n=>n.id===this.editPolygonID);if(!l)return;l.pointList=this.drawingPointList,this.editPolygonID=""}else{const l=uuid(8,62);let n={id:l,sourceID:s,valid:!this.isCtrl,textAttribute:"",pointList:this.drawingPointList,attribute:this.defaultAttribute,order:CommonToolUtils.getMaxOrder(o.filter(r=>CommonToolUtils.isSameSourceID(r.sourceID,s)))+1};if(this.config.textConfigurable){let r="";r=AttributeUtils.default.getTextAttribute(this.polygonList.filter(a=>CommonToolUtils.isSameSourceID(a.sourceID,s)),this.config.textCheckType),n=__spreadProps(__spreadValues({},n),{textAttribute:r})}this.pattern===tool.EPolygonPattern.Rect&&t===!0&&(n=__spreadProps(__spreadValues({},n),{isRect:!0})),o.push(n),i=n,this.setSelectedIdAfterAddingDrawing(l)}this.setPolygonList(o),this.isCtrl=!1,this.drawingPointList=[],this.history.pushHistory(o),i&&this.emit("polygonCreated",i,this.zoom,this.currentPos)}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&(this.config.textConfigurable?this.setSelectedID(t):this.deleteSelectedID())}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),s=this.currentShowList.map(o=>__spreadProps(__spreadValues({},o),{pointList:AxisUtils.default.changePointListByZoom(o.pointList,this.zoom)}));return PolygonUtils.getHoverPolygonID(i,s,10,(e=this.config)==null?void 0:e.lineType)}getHoverEdgeIndex(t){var e;if(!this.selectedID)return-1;const i=this.selectedPolygon;if(!i)return-1;const s=this.getCoordinateUnderZoom(t),o=AxisUtils.default.changePointListByZoom(i.pointList,this.zoom);return PolygonUtils.getHoverEdgeIndex(s,o,(e=this.config)==null?void 0:e.lineType)}getHoverPointIndex(t){if(!this.selectedID)return-1;const e=this.selectedPolygon;if(!e)return-1;const i=this.getCoordinateUnderZoom(t),s=AxisUtils.default.changePointListByZoom(e.pointList,this.zoom);return AxisUtils.default.returnClosePointIndex(i,s)}deletePolygon(t){var e;if(!t)return;const i=this.polygonList.find(s=>s.id===t);this.emit("deletedObject",{deletedObject:i,id:t}),this.setPolygonList(this.polygonList.filter(s=>s.id!==t)),this.history.pushHistory(this.polygonList),(e=this._textAttributInstance)==null||e.clearTextAttribute(),this.emit("selectedChange"),this.render()}deletePolygonPoint(t){if(!this.selectedID)return;const{selectedPolygon:e}=this;if(!e)return;let{lowerLimitPointNum:i}=this.config;if(i<3&&(i=3),e.pointList.length<=i){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.LowerLimitErrorNotice,this.lang)}${i}`);return}e==null||e.pointList.splice(t,1),this.history.pushHistory(this.polygonList),this.render()}spaceKeydown(){var t,e,i;if(this.selectedID){if(((t=this.selectedPolygon)==null?void 0:t.isRect)===!0){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UnableToReannotation,this.lang)}`);return}this.editPolygonID=this.selectedID,this.drawingPointList=(i=(e=this.selectedPolygon)==null?void 0:e.pointList)!=null?i:[],this.drawingHistory.empty(),this.drawingHistory.initRecord(this.drawingPointList),this.hoverID="",this.deleteSelectedID(),this.render()}}onTabKeyDown(t){t.preventDefault();let e=annotation.ESortDirection.ascend;t.shiftKey&&(e=annotation.ESortDirection.descend),this.switchToNextPolygon(e)}switchToNextPolygon(t){if(this.drawingPointList.length>0)return;const[e,i]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let s=[...e];i&&(s=[...s,i]);const o=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom),l=s.map(r=>{var a,d,g,h;return __spreadProps(__spreadValues({},r),{x:(d=(a=r.pointList[0])==null?void 0:a.x)!=null?d:0,y:(h=(g=r.pointList[0])==null?void 0:g.y)!=null?h:0})}).filter(r=>CanvasUtils.inViewPort({x:r.x,y:r.y},o)),n=CommonToolUtils.getNextSelectedRectID(l,t,this.selectedID);if(n){this.setSelectedID(n.id);const{selectedPolygon:r}=this;r&&this.setDefaultAttribute(r.attribute)}this.render()}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case keyCode.Space:this.spaceKeydown();break;case keyCode.Esc:this.drawingPointList=[],this.editPolygonID="";break;case keyCode.F:this.selectedID&&this.setPolygonValidAndRender(this.selectedID);break;case keyCode.Z:if(t.altKey){this.onCombinedExecute();return}this.setIsHidden(!this.isHidden),this.render();break;case keyCode.Delete:this.deletePolygon(this.selectedID),this.render();break;case keyCode.Ctrl:this.isCtrl=!0;break;case keyCode.Alt:this.isAlt===!1&&(t.preventDefault(),this.isAlt=!0,this.render());break;case keyCode.Tab:{this.onTabKeyDown(t);break}case keyCode.X:t.altKey&&this.segment();break;default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case keyCode.Ctrl:this.isCtrl=!1;break;case keyCode.Alt:{const e=this.isAlt;this.isAlt=!1,e===!0&&this.render();break}}}rightMouseUp(t){if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.setSelectedID(this.hoverID);const{selectedPolygon:e}=this;e&&this.setDefaultAttribute(e.attribute)}onLeftDblClick(t){if(this.hoverEdgeIndex>-1){const e=this.getCoordinateUnderZoom(t),{selectedPolygon:i}=this;if(!i)return;if(i.isRect===!0){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.ForbidAddNewPoint,this.lang)}`),this.clearPolygonDrag();return}const{dropFoot:s}=PolygonUtils.getClosestPoint(e,this.polygonListUnderZoom,this.config.lineType,tool.edgeAdsorptionScope);if(!s)return;const{upperLimitPointNum:o}=this.config;if(o&&i.pointList.length>=o){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UpperLimitErrorNotice,this.lang)}${o}`),this.clearPolygonDrag();return}i==null||i.pointList.splice(this.hoverEdgeIndex+1,0,AxisUtils.default.changePointByZoom(s,1/this.zoom)),this.setPolygonDataByID(i,this.selectedID),this.history.pushHistory(this.polygonList),this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.render()}this.dragInfo=void 0}onRightDblClick(t){this.dragInfo=void 0,this.clearImgDrag();const e=this.getHoverID(t),i=this.getHoverPointIndex(t);if(this.hoverPointIndex>-1&&this.hoverPointIndex===i){this.deletePolygonPoint(i),this.dragInfo=void 0,this.hoverPointIndex=-1,this.render();return}this.hoverID===this.selectedID&&this.deletePolygon(e),this.render()}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0))return this.dragMouseDown(t),!0}dragMouseDown(t){const e=this.selectedPolygon;if(!e||t.button!==0||this.getHoverID(t)!==this.selectedID)return;const s=e.pointList,o=this.getCoordinateUnderZoom(t);let l=[0],n=annotation.EDragTarget.Plane;this.dragStatus=annotation.EDragStatus.Start;const r=this.getHoverPointIndex(t),a=this.getHoverEdgeIndex(t);r>-1?(n=annotation.EDragTarget.Point,l=[r]):a>-1&&this.hoverEdgeIndex>-1&&(n=annotation.EDragTarget.Line,l=[a,(a+1)%s.length]),this.dragInfo={dragStartCoord:o,dragTarget:n,initPointList:s,changePointIndex:l,originPolygon:this.selectedPolygon,dragPrevCoord:o,originPolygonList:this.polygonList}}segment(){var t;if(!this.selectedID||((t=this.config)==null?void 0:t.lineType)!==tool.ELineTypes.Line)return;const e=PolygonUtils.getPolygonPointList(this.selectedID,this.currentShowList),i=this.currentShowList.filter(l=>l.id!==this.selectedID);if(i.length===0||e.length===0)return;const s=PolygonUtils.getWrapPolygonIndex(e,i);let o=[...this.polygonList];if(s===-1){const l=PolygonUtils.segmentPolygonByPolygon(e,i);if(!l)return;const n=l.shift();if(!n)return;let r="",a=!0;const d=CommonToolUtils.getSourceID(this.basicResult);let g="";o=this.polygonList.map(h=>{var u,f;return h.id===this.selectedID?(r=h.attribute,a=(u=h==null?void 0:h.valid)!=null?u:!0,g=(f=h==null?void 0:h.textAttribute)!=null?f:"",__spreadProps(__spreadValues({},h),{pointList:n})):h}),l.length>0&&l.forEach((h,u)=>{o.push({sourceID:d,id:uuid(8,62),pointList:h,valid:a,order:CommonToolUtils.getMaxOrder(this.currentShowList)+1+u,attribute:r,textAttribute:g})})}else o[s].pointList=PolygonUtils.clipPolygonFromWrapPolygon(e,o[s].pointList),o=o.filter(l=>l.id!==this.selectedID);this.setPolygonList(o),this.history.pushHistory(o),this.render()}onCombinedExecute(){if(!this.selectedID){this.emit("messageInfo",lbUtils.i18n.t("PolygonsToBeCombinedNeedToBeSelected"));return}this.isCombined=!this.isCombined}combine(t){var e;const i=this.getHoverID(t);if(!i||!this.selectedID||this.selectedID===i)return;if(((e=this.config)==null?void 0:e.lineType)!==tool.ELineTypes.Line){this.emit("messageInfo",lbUtils.i18n.t("CurveModeDoesNotSupportCutting"));return}const s=this.polygonList.find(a=>a.id===this.selectedID),o=this.currentShowList.find(a=>a.id===i);if(!o||!s)return;const l=PolygonUtils.combinePolygonWithPolygon(s,o);if(!l)return;const{newPolygon:n,unionList:r}=l;if(r.length===1&&n){const a=this.polygonList.filter(d=>!r.includes(d.id)).map(d=>d.id===this.selectedID?n:d);this.setPolygonList(a),this.history.pushHistory(a),this.render(),this.emit("messageInfo",lbUtils.i18n.t("CombineSuccess"))}else this.emit("messageInfo",lbUtils.i18n.t("CombiningFailedNotify"));this.isCombined=!1}isPolygonOutSide(t){if(this.dependToolName&&this.basicCanvas&&this.basicResult){let n=!1;switch(this.dependToolName){case tool.EToolName.Rect:{n=t.filter(r=>!RectUtils.isInRect(r,this.basicResult)).length>0;break}case tool.EToolName.Polygon:{n=PolygonUtils.isPointListOutSidePolygon(t,this.basicResult.pointList,this.config.lineType);break}}return n}if(!this.imgInfo)return!1;const{left:e,top:i,right:s,bottom:o}=MathUtils.default.calcViewportBoundaries(AxisUtils.default.changePointListByZoom(t,this.zoom)),l=1e-5;return e<0||i<0||s>this.imgInfo.width+l||o>this.imgInfo.height+l}getDragOffset(t,e){var i;const s=this.getCoordinateUnderZoom(t),{dragTarget:o,dragPrevCoord:l,changePointIndex:n,initPointList:r,dragStartCoord:a}=this.dragInfo;if(this.pattern===tool.EPolygonPattern.Rect&&(e==null?void 0:e.isRect)===!0&&n&&[annotation.EDragTarget.Line].includes(o)){const d=MathUtils.default.getArrayIndex(n[0]-2,4),g=MathUtils.default.getArrayIndex(n[0]-1,4),h=[r[d],r[g]],u=MathUtils.default.getRectPerpendicularOffset(a,s,h);return{x:u.x/this.zoom,y:u.y/this.zoom}}return((i=this.dragInfo)==null?void 0:i.dragTarget)===annotation.EDragTarget.Plane?{x:(s.x-l.x)/this.zoom,y:(s.y-l.y)/this.zoom}:{x:(s.x-a.x)/this.zoom,y:(s.y-a.y)/this.zoom}}dragPolygon(t,e){let i=___default.default.cloneDeep(e==null?void 0:e.pointList);if(!i||!this.dragInfo)return;const{initPointList:s,dragTarget:o,changePointIndex:l}=this.dragInfo,n=this.getDragOffset(t,e);switch(this.dragStatus=annotation.EDragStatus.Move,o){case annotation.EDragTarget.Plane:i=i.map(r=>__spreadProps(__spreadValues({},r),{x:r.x+n.x,y:r.y+n.y}));break;case annotation.EDragTarget.Point:case annotation.EDragTarget.Line:i=i.map((r,a)=>l&&l.includes(a)?__spreadProps(__spreadValues({},r),{x:s[a].x+n.x,y:s[a].y+n.y}):r);break}if(this.pattern===tool.EPolygonPattern.Rect&&(e==null?void 0:e.isRect)===!0&&o===annotation.EDragTarget.Point&&l&&(i=MathUtils.default.getPointListFromPointOffset(s,l[0],n)),!(this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(i)))return i}onDragMove(t){const e=this.polygonList.map(i=>{if(i.id===this.selectedID){const s=this.dragPolygon(t,i);if(!s)return i;const o=__spreadProps(__spreadValues({},i),{pointList:s});return i.isRect===!0&&this.pattern===tool.EPolygonPattern.Normal&&Object.assign(o,{isRect:!1}),o}return i});this.dragInfo.dragPrevCoord=this.getCoordinateUnderZoom(t),this.setPolygonList(e),this.render()}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;if(this.enableDrag){this.onDragMove(t);return}let e=-1,i=-1;const{selectedID:s}=this;if(s&&(this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,e=this.getHoverPointIndex(t),e>-1?this.hoverPointIndex=e:(i=this.getHoverEdgeIndex(t),this.hoverEdgeIndex=i)),this.drawingPointList.length>0)return;const o=this.getHoverID(t);this.hoverID!==o&&(this.hoverID=o,this.render())}leftMouseUpdateValid(t){const e=this.getHoverID(t);return this.drawingPointList.length===0&&t.ctrlKey===!0&&e?(this.setPolygonValidAndRender(e),!0):!1}leftMouseUp(t){this.leftMouseUpdateValid(t)||this.addPointInDrawing(t)}onMouseUp(t){if(this.isCombined){switch(t.button){case 0:this.combine(t);break;case 2:this.isCombined=!1;break;default:return}return}if(!(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.dragInfo&&this.dragStatus===annotation.EDragStatus.Move){this.emit("updateResult"),this.emitUpdatePolygonByDrag(),this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.history.pushHistory(this.polygonList);return}switch(t.button){case 0:{this.leftMouseUp(t);break}case 2:{this.rightMouseUp(t);break}}this.render()}}dragMouseUp(){this.dragStatus===annotation.EDragStatus.Start&&(this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait)}exportData(){const{polygonList:t}=this;return[t,this.basicImgInfo]}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}getCurrentSelectedData(){const{selectedPolygon:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:TEXT_MAX_WIDTH,textAttribute:t.textAttribute,color:i}}updateSelectedTextAttribute(t){if(this._textAttributInstance&&t&&this.selectedID){let e=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPolygonList(AttributeUtils.default.textChange(e,this.selectedID,this.polygonList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t;const{selectedPolygon:e}=this;if(!this.ctx||this.config.textConfigurable===!1||!e)return;const{pointList:i,attribute:s,valid:o,textAttribute:l}=e,{x:n,y:r}=i[i.length-1],a=TEXT_MAX_WIDTH,d=AxisUtils.default.getOffsetCoordinate({x:n,y:r},this.currentPos,this.zoom),g=this.getColor(s),h=o?g==null?void 0:g.valid.stroke:g==null?void 0:g.invalid.stroke;this._textAttributInstance||(this._textAttributInstance=new textAttributeClass({width:a,container:this.container,icon:this.getTextIconSvg(s),color:h,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${l}`,{left:d.x,top:d.y,color:h,width:a})}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.visiblePolygonList)==null||t.forEach(e=>{var i,s,o,l,n;if([this.selectedID,this.editPolygonID].includes(e.id))return;const{textAttribute:r,attribute:a}=e,d=this.getColor(a),g=StyleUtils.getStrokeAndFill(d,e.valid),h=AxisUtils.default.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);DrawUtils.drawPolygonWithFillAndLine(this.canvas,h,{fillColor:g.fill,strokeColor:g.stroke,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(o=this.config)==null?void 0:o.lineType});let u=`${(l=AttributeUtils.default.getAttributeShowText(a,this.config.attributeList))!=null?l:""}`;((n=this.config)==null?void 0:n.isShowOrder)&&(e==null?void 0:e.order)>0&&(u=`${e.order} ${u}`),DrawUtils.drawText(this.canvas,h[0],u,__spreadValues({color:g.stroke},annotation.DEFAULT_TEXT_OFFSET));const f=h[h.length-1];DrawUtils.drawText(this.canvas,{x:f.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:f.y+annotation.TEXT_ATTRIBUTE_OFFSET.y},r,__spreadValues({color:g.stroke},annotation.DEFAULT_TEXT_OFFSET))}))}renderSelectedPolygon(){var t,e,i;const{selectedPolygon:s}=this;if(s){const o=this.getColor(s.attribute),l=StyleUtils.getStrokeAndFill(o,s.valid,{isSelected:!0});DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,AxisUtils.default.changePointListByZoom(s.pointList,this.zoom,this.currentPos),{fillColor:l.fill,strokeColor:l.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(t=this.config)==null?void 0:t.lineType});let n=`${(e=AttributeUtils.default.getAttributeShowText(s.attribute,this.config.attributeList))!=null?e:""}`;((i=this.config)==null?void 0:i.isShowOrder)&&(s==null?void 0:s.order)>0&&(n=`${s.order} ${n}`),DrawUtils.drawText(this.canvas,AxisUtils.default.changePointByZoom(s.pointList[0],this.zoom,this.currentPos),n,__spreadValues({color:l.stroke},annotation.DEFAULT_TEXT_OFFSET)),this.renderTextAttribute()}}renderHoverPolygon(){var t;if(this.hoverID&&this.hoverID!==this.editPolygonID){const{hoverPolygon:e}=this;if(e){let i="";const s=this.getColor(e.attribute);e.valid?i=s.validHover.fill:i=StyleUtils.getStrokeAndFill(s,!1,{isHover:!0}).fill,DrawUtils.drawPolygonWithFill(this.canvas,AxisUtils.default.changePointListByZoom(e.pointList,this.zoom,this.currentPos),{color:i,lineType:(t=this.config)==null?void 0:t.lineType})}}}renderPolygon(){var t,e,i,s;this.renderStaticPolygon(),this.renderHoverPolygon(),this.renderSelectedPolygon();const o=this.getColor(this.defaultAttribute),l=StyleUtils.getStrokeAndFill(o,!this.isCtrl);if(((t=this.drawingPointList)==null?void 0:t.length)>0){let n=[...this.drawingPointList],r=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.pattern===tool.EPolygonPattern.Rect&&n.length===2)n=MathUtils.default.getRectangleByRightAngle(r,n);else{if(((e=this.config)==null?void 0:e.edgeAdsorption)&&this.isAlt===!1){const{dropFoot:a}=PolygonUtils.getClosestPoint(r,this.polygonList,(i=this.config)==null?void 0:i.lineType,tool.edgeAdsorptionScope/this.zoom);a&&(r=a)}n.push(r)}DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,AxisUtils.default.changePointListByZoom(n,this.zoom,this.currentPos),{fillColor:l.fill,strokeColor:l.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!1,lineType:this.config.lineType})}if(this.hoverPointIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const r=StyleUtils.getStrokeAndFill(o,n.valid,{isSelected:!0}),a=n==null?void 0:n.pointList[this.hoverPointIndex];if(a){const{x:d,y:g}=AxisUtils.default.changePointByZoom(a,this.zoom,this.currentPos);DrawUtils.drawCircleWithFill(this.canvas,{x:d,y:g},5,{color:r.fill})}}if(this.hoverEdgeIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const r=StyleUtils.getStrokeAndFill(o,n.valid,{isSelected:!0});DrawUtils.drawLineWithPointList(this.canvas,AxisUtils.default.changePointListByZoom(n.pointList,this.zoom,this.currentPos),{color:r.stroke,thickness:10,hoverEdgeIndex:this.hoverEdgeIndex,lineType:(s=this.config)==null?void 0:s.lineType})}}render(){!this.ctx||(super.render(),this.renderPolygon(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}renderCursorLine(t){if(super.renderCursorLine(t),this.isCombined){const{x:e,y:i}=this.coord,s=10,o=186,l=32;DrawUtils.drawRectWithFill(this.canvas,{x:e+s,y:i-s*4-1,width:o,height:l},{color:"black"}),DrawUtils.drawText(this.canvas,{x:e,y:i},lbUtils.i18n.t("ClickAnotherPolygon"),{textAlign:"center",color:"white",offsetX:o/2+s,offsetY:-(l/2+s/2)}),DrawUtils.drawRect(this.canvas,{x:e-s,y:i-s,width:s*2,height:s*2},{lineDash:[6],color:"white"})}}undo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.undo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.undo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}redo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.redo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.redo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}deleteSelectedID(){this.setSelectedID("")}}module.exports=PolygonOperation;
1
+ 'use strict';
2
+
3
+ var lbUtils = require('@labelbee/lb-utils');
4
+ var MathUtils = require('../../utils/MathUtils.js');
5
+ var RectUtils = require('../../utils/tool/RectUtils.js');
6
+ var _ = require('lodash');
7
+ var annotation = require('../../constant/annotation.js');
8
+ var keyCode = require('../../constant/keyCode.js');
9
+ var tool = require('../../constant/tool.js');
10
+ var index = require('../../locales/index.js');
11
+ var constants = require('../../locales/constants.js');
12
+ var ActionsHistory = require('../../utils/ActionsHistory.js');
13
+ var AttributeUtils = require('../../utils/tool/AttributeUtils.js');
14
+ var AxisUtils = require('../../utils/tool/AxisUtils.js');
15
+ var CanvasUtils = require('../../utils/tool/CanvasUtils.js');
16
+ var CommonToolUtils = require('../../utils/tool/CommonToolUtils.js');
17
+ var DrawUtils = require('../../utils/tool/DrawUtils.js');
18
+ var PolygonUtils = require('../../utils/tool/PolygonUtils.js');
19
+ var StyleUtils = require('../../utils/tool/StyleUtils.js');
20
+ var uuid = require('../../utils/uuid.js');
21
+ var basicToolOperation = require('./basicToolOperation.js');
22
+ var textAttributeClass = require('./textAttributeClass.js');
23
+
24
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
25
+
26
+ var ___default = /*#__PURE__*/_interopDefaultLegacy(_);
27
+
28
+ var __defProp = Object.defineProperty;
29
+ var __defProps = Object.defineProperties;
30
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
31
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
32
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
33
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
34
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
35
+ var __spreadValues = (a, b) => {
36
+ for (var prop in b || (b = {}))
37
+ if (__hasOwnProp.call(b, prop))
38
+ __defNormalProp(a, prop, b[prop]);
39
+ if (__getOwnPropSymbols)
40
+ for (var prop of __getOwnPropSymbols(b)) {
41
+ if (__propIsEnum.call(b, prop))
42
+ __defNormalProp(a, prop, b[prop]);
43
+ }
44
+ return a;
45
+ };
46
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
47
+ const TEXT_MAX_WIDTH = 164;
48
+ class PolygonOperation extends basicToolOperation.BasicToolOperation {
49
+ constructor(props) {
50
+ super(props);
51
+ this.isAllowDouble = (e) => {
52
+ const {selectedID} = this;
53
+ const currentSelectedID = this.getHoverID(e);
54
+ if (selectedID && selectedID === currentSelectedID) {
55
+ return true;
56
+ }
57
+ return false;
58
+ };
59
+ this.textChange = (v) => {
60
+ if (this.config.textConfigurable === false || !this.selectedID) {
61
+ return;
62
+ }
63
+ this.setPolygonList(AttributeUtils["default"].textChange(v, this.selectedID, this.polygonList));
64
+ this.emit("selectedChange");
65
+ this.render();
66
+ };
67
+ this.emitUpdatePolygonByDrag = () => {
68
+ if (this.dragInfo) {
69
+ const {originPolygon} = this.dragInfo;
70
+ this.emit("updatePolygonByDrag", [{newPolygon: this.selectedPolygon, originPolygon}]);
71
+ }
72
+ };
73
+ this.config = CommonToolUtils.jsonParser(props.config);
74
+ this.drawingPointList = [];
75
+ this.polygonList = [];
76
+ this.hoverPointIndex = -1;
77
+ this.hoverEdgeIndex = -1;
78
+ this.drawingHistory = new ActionsHistory();
79
+ this.isCtrl = false;
80
+ this.isAlt = false;
81
+ this.isCombined = false;
82
+ this.pattern = tool.EPolygonPattern.Normal;
83
+ this.getCurrentSelectedData = this.getCurrentSelectedData.bind(this);
84
+ this.updateSelectedTextAttribute = this.updateSelectedTextAttribute.bind(this);
85
+ }
86
+ eventBinding() {
87
+ super.eventBinding();
88
+ this.container.removeEventListener("mouseup", this.onMouseUp);
89
+ this.container.addEventListener("mouseup", this.dragMouseUp);
90
+ this.dblClickListener.addEvent(this.onMouseUp, this.onLeftDblClick, this.onRightDblClick, this.isAllowDouble);
91
+ }
92
+ eventUnbinding() {
93
+ super.eventUnbinding();
94
+ this.container.removeEventListener("mouseup", this.dragMouseUp);
95
+ }
96
+ destroy() {
97
+ super.destroy();
98
+ if (this._textAttributInstance) {
99
+ this._textAttributInstance.clearTextAttribute();
100
+ }
101
+ }
102
+ get selectedPolygon() {
103
+ return PolygonUtils.getPolygonByID(this.visiblePolygonList, this.selectedID);
104
+ }
105
+ get hoverPolygon() {
106
+ return this.visiblePolygonList.find((v) => v.id === this.hoverID && v.id !== this.selectedID);
107
+ }
108
+ get enableDrag() {
109
+ return Boolean(this.selectedID && this.dragInfo);
110
+ }
111
+ get visiblePolygonList() {
112
+ return this.polygonList;
113
+ }
114
+ get polygonListUnderZoom() {
115
+ return this.visiblePolygonList.map((polygon) => __spreadProps(__spreadValues({}, polygon), {
116
+ pointList: AxisUtils["default"].changePointListByZoom(polygon.pointList, this.zoom)
117
+ }));
118
+ }
119
+ get selectedText() {
120
+ var _a;
121
+ return (_a = this.selectedPolygon) == null ? void 0 : _a.textAttribute;
122
+ }
123
+ get dataList() {
124
+ return this.polygonList;
125
+ }
126
+ setPattern(pattern, isForce = false) {
127
+ var _a;
128
+ if (((_a = this.drawingPointList) == null ? void 0 : _a.length) > 0 && isForce === true) {
129
+ return;
130
+ }
131
+ this.pattern = pattern;
132
+ }
133
+ get currentShowList() {
134
+ let polygon = [];
135
+ const [showingPolygon, selectdPolygon] = CommonToolUtils.getRenderResultList(this.visiblePolygonList, CommonToolUtils.getSourceID(this.basicResult), this.attributeLockList, this.selectedID);
136
+ polygon = showingPolygon;
137
+ if (this.isHidden) {
138
+ polygon = [];
139
+ }
140
+ if (selectdPolygon) {
141
+ polygon.push(selectdPolygon);
142
+ }
143
+ return polygon;
144
+ }
145
+ get currentPageResult() {
146
+ const [showingPolygon] = CommonToolUtils.getRenderResultList(this.polygonList, CommonToolUtils.getSourceID(this.basicResult), []);
147
+ return showingPolygon;
148
+ }
149
+ setResult(polygonList) {
150
+ this.clearActiveStatus();
151
+ this.setPolygonList(polygonList);
152
+ this.render();
153
+ }
154
+ setPolygonDataByID(newPolygonData, id) {
155
+ return this.polygonList.map((polygon) => {
156
+ if (polygon.id === id) {
157
+ return __spreadValues(__spreadValues({}, polygon), newPolygonData);
158
+ }
159
+ return polygon;
160
+ });
161
+ }
162
+ rotatePolygon(angle = 1, direction = annotation.ERotateDirection.Clockwise, selectedID = this.selectedID) {
163
+ if (!selectedID) {
164
+ return;
165
+ }
166
+ const selectedPolygon = PolygonUtils.getPolygonByID(this.polygonList, selectedID);
167
+ if (!selectedPolygon) {
168
+ return;
169
+ }
170
+ const rotatePointList = PolygonUtils.updatePolygonByRotate(direction, angle, selectedPolygon == null ? void 0 : selectedPolygon.pointList);
171
+ this.setPolygonList(this.setPolygonDataByID({pointList: rotatePointList}, selectedID));
172
+ this.render();
173
+ }
174
+ addPointInDrawing(e) {
175
+ if (!this.imgInfo) {
176
+ return;
177
+ }
178
+ if (this.forbidAddNewPolygonFuc && this.forbidAddNewPolygonFuc(e)) {
179
+ return;
180
+ }
181
+ const {upperLimitPointNum, edgeAdsorption} = this.config;
182
+ if (upperLimitPointNum && this.drawingPointList.length >= upperLimitPointNum) {
183
+ this.emit("messageInfo", `${index.getMessagesByLocale(constants.EMessage.UpperLimitErrorNotice, this.lang)}${upperLimitPointNum}`);
184
+ return;
185
+ }
186
+ this.deleteSelectedID();
187
+ const coordinateZoom = this.getCoordinateUnderZoom(e);
188
+ const coordinate = AxisUtils["default"].changeDrawOutsideTarget(coordinateZoom, {x: 0, y: 0}, this.imgInfo, this.config.drawOutsideTarget, this.basicResult, this.zoom);
189
+ const calculateHoverPointIndex = AxisUtils["default"].returnClosePointIndex(coordinate, AxisUtils["default"].changePointListByZoom(this.drawingPointList, this.zoom));
190
+ if (calculateHoverPointIndex === 0) {
191
+ this.addDrawingPointToPolygonList();
192
+ return;
193
+ }
194
+ const {dropFoot} = PolygonUtils.getClosestPoint(coordinate, this.polygonListUnderZoom, this.config.lineType, tool.edgeAdsorptionScope);
195
+ const coordinateWithOrigin = AxisUtils["default"].changePointByZoom(dropFoot && e.altKey === false && edgeAdsorption ? dropFoot : coordinate, 1 / this.zoom);
196
+ if (this.pattern === tool.EPolygonPattern.Rect && this.drawingPointList.length === 2) {
197
+ const rect = MathUtils["default"].getRectangleByRightAngle(coordinateWithOrigin, this.drawingPointList);
198
+ this.drawingPointList = rect;
199
+ if (this.config.drawOutsideTarget === false && this.imgInfo) {
200
+ const isOutSide = this.isPolygonOutSide(this.drawingPointList);
201
+ if (isOutSide) {
202
+ this.emit("messageInfo", `${index.getMessagesByLocale(constants.EMessage.ForbiddenCreationOutsideBoundary, this.lang)}`);
203
+ this.drawingPointList = [];
204
+ return;
205
+ }
206
+ }
207
+ this.addDrawingPointToPolygonList(true);
208
+ return;
209
+ }
210
+ this.drawingPointList.push(coordinateWithOrigin);
211
+ if (this.drawingPointList.length === 1) {
212
+ this.drawingHistory.initRecord(this.drawingPointList);
213
+ } else {
214
+ this.drawingHistory.pushHistory(this.drawingPointList);
215
+ }
216
+ }
217
+ clearResult() {
218
+ this.setPolygonList([]);
219
+ this.deleteSelectedID();
220
+ this.render();
221
+ }
222
+ clearPolygonDrag() {
223
+ this.drawingPointList = [];
224
+ this.dragInfo = void 0;
225
+ this.dragInfo = void 0;
226
+ this.dragStatus = annotation.EDragStatus.Wait;
227
+ this.hoverEdgeIndex = -1;
228
+ this.hoverPointIndex = -1;
229
+ this.hoverID = "";
230
+ }
231
+ clearActiveStatus() {
232
+ this.clearPolygonDrag();
233
+ this.deleteSelectedID();
234
+ }
235
+ clearDrawingStatus() {
236
+ this.drawingPointList = [];
237
+ }
238
+ setPolygonList(polygonList) {
239
+ const oldLen = this.polygonList.length;
240
+ this.polygonList = polygonList;
241
+ if (oldLen !== polygonList.length) {
242
+ this.emit("updatePageNumber");
243
+ }
244
+ }
245
+ setSelectedID(newID) {
246
+ var _a, _b;
247
+ const oldID = this.selectedID;
248
+ if (newID !== oldID && oldID) {
249
+ (_a = this._textAttributInstance) == null ? void 0 : _a.changeSelected();
250
+ }
251
+ if (!newID) {
252
+ (_b = this._textAttributInstance) == null ? void 0 : _b.clearTextAttribute();
253
+ }
254
+ this.selectedID = newID;
255
+ this.render();
256
+ this.emit("selectedChange");
257
+ }
258
+ setDefaultAttribute(defaultAttribute = "") {
259
+ const oldDefault = this.defaultAttribute;
260
+ this.defaultAttribute = defaultAttribute;
261
+ if (oldDefault !== defaultAttribute) {
262
+ this.changeStyle(defaultAttribute);
263
+ this.emit("changeAttributeSidebar");
264
+ const {selectedID} = this;
265
+ if (selectedID) {
266
+ if (this.selectedPolygon) {
267
+ this.selectedPolygon.attribute = defaultAttribute;
268
+ }
269
+ this.history.pushHistory(this.polygonList);
270
+ this.render();
271
+ }
272
+ if (this._textAttributInstance) {
273
+ if (this.attributeLockList.length > 0 && !this.attributeLockList.includes(defaultAttribute)) {
274
+ this._textAttributInstance.clearTextAttribute();
275
+ return;
276
+ }
277
+ this._textAttributInstance.updateIcon(this.getTextIconSvg(defaultAttribute));
278
+ }
279
+ }
280
+ }
281
+ setStyle(toolStyle) {
282
+ var _a;
283
+ super.setStyle(toolStyle);
284
+ if (this._textAttributInstance && this.config.attributeConfigurable === false) {
285
+ (_a = this._textAttributInstance) == null ? void 0 : _a.updateIcon(this.getTextIconSvg());
286
+ }
287
+ }
288
+ setPolygonValidAndRender(id) {
289
+ if (!id) {
290
+ return;
291
+ }
292
+ const newPolygonList = this.polygonList.map((polygon) => {
293
+ var _a;
294
+ if (polygon.id === id) {
295
+ const valid = (_a = polygon == null ? void 0 : polygon.valid) != null ? _a : true;
296
+ return __spreadProps(__spreadValues({}, polygon), {
297
+ valid: !valid
298
+ });
299
+ }
300
+ return polygon;
301
+ });
302
+ this.setPolygonList(newPolygonList);
303
+ this.history.pushHistory(this.polygonList);
304
+ this.render();
305
+ this.emit("updateResult");
306
+ }
307
+ addDrawingPointToPolygonList(isRect) {
308
+ let {lowerLimitPointNum = 3} = this.config;
309
+ if (lowerLimitPointNum < 3) {
310
+ lowerLimitPointNum = 3;
311
+ }
312
+ let createPolygon;
313
+ if (this.drawingPointList.length < lowerLimitPointNum) {
314
+ this.drawingPointList = [];
315
+ this.editPolygonID = "";
316
+ return;
317
+ }
318
+ const basicSourceID = CommonToolUtils.getSourceID(this.basicResult);
319
+ const polygonList = [...this.polygonList];
320
+ if (this.editPolygonID) {
321
+ const samePolygon = polygonList.find((polygon) => polygon.id === this.editPolygonID);
322
+ if (!samePolygon) {
323
+ return;
324
+ }
325
+ samePolygon.pointList = this.drawingPointList;
326
+ this.editPolygonID = "";
327
+ } else {
328
+ const id = uuid(8, 62);
329
+ let newPolygon = {
330
+ id,
331
+ sourceID: basicSourceID,
332
+ valid: !this.isCtrl,
333
+ textAttribute: "",
334
+ pointList: this.drawingPointList,
335
+ attribute: this.defaultAttribute,
336
+ order: CommonToolUtils.getMaxOrder(polygonList.filter((v) => CommonToolUtils.isSameSourceID(v.sourceID, basicSourceID))) + 1
337
+ };
338
+ if (this.config.textConfigurable) {
339
+ let textAttribute = "";
340
+ textAttribute = AttributeUtils["default"].getTextAttribute(this.polygonList.filter((polygon) => CommonToolUtils.isSameSourceID(polygon.sourceID, basicSourceID)), this.config.textCheckType);
341
+ newPolygon = __spreadProps(__spreadValues({}, newPolygon), {
342
+ textAttribute
343
+ });
344
+ }
345
+ if (this.pattern === tool.EPolygonPattern.Rect && isRect === true) {
346
+ newPolygon = __spreadProps(__spreadValues({}, newPolygon), {
347
+ isRect: true
348
+ });
349
+ }
350
+ polygonList.push(newPolygon);
351
+ createPolygon = newPolygon;
352
+ this.setSelectedIdAfterAddingDrawing(id);
353
+ }
354
+ this.setPolygonList(polygonList);
355
+ this.isCtrl = false;
356
+ this.drawingPointList = [];
357
+ this.history.pushHistory(polygonList);
358
+ if (createPolygon) {
359
+ this.emit("polygonCreated", createPolygon, this.zoom, this.currentPos);
360
+ }
361
+ }
362
+ setSelectedIdAfterAddingDrawing(newID) {
363
+ if (this.drawingPointList.length === 0) {
364
+ return;
365
+ }
366
+ if (this.config.textConfigurable) {
367
+ this.setSelectedID(newID);
368
+ } else {
369
+ this.deleteSelectedID();
370
+ }
371
+ }
372
+ getHoverID(e) {
373
+ var _a;
374
+ const coordinate = this.getCoordinateUnderZoom(e);
375
+ const polygonListWithZoom = this.currentShowList.map((polygon) => __spreadProps(__spreadValues({}, polygon), {
376
+ pointList: AxisUtils["default"].changePointListByZoom(polygon.pointList, this.zoom)
377
+ }));
378
+ return PolygonUtils.getHoverPolygonID(coordinate, polygonListWithZoom, 10, (_a = this.config) == null ? void 0 : _a.lineType);
379
+ }
380
+ getHoverEdgeIndex(e) {
381
+ var _a;
382
+ if (!this.selectedID) {
383
+ return -1;
384
+ }
385
+ const selectPolygon = this.selectedPolygon;
386
+ if (!selectPolygon) {
387
+ return -1;
388
+ }
389
+ const currentCoord = this.getCoordinateUnderZoom(e);
390
+ const editPointListUnderZoom = AxisUtils["default"].changePointListByZoom(selectPolygon.pointList, this.zoom);
391
+ return PolygonUtils.getHoverEdgeIndex(currentCoord, editPointListUnderZoom, (_a = this.config) == null ? void 0 : _a.lineType);
392
+ }
393
+ getHoverPointIndex(e) {
394
+ if (!this.selectedID) {
395
+ return -1;
396
+ }
397
+ const selectPolygon = this.selectedPolygon;
398
+ if (!selectPolygon) {
399
+ return -1;
400
+ }
401
+ const currentCoord = this.getCoordinateUnderZoom(e);
402
+ const editPointListUnderZoom = AxisUtils["default"].changePointListByZoom(selectPolygon.pointList, this.zoom);
403
+ return AxisUtils["default"].returnClosePointIndex(currentCoord, editPointListUnderZoom);
404
+ }
405
+ deletePolygon(id) {
406
+ var _a;
407
+ if (!id) {
408
+ return;
409
+ }
410
+ const deletedPolygon = this.polygonList.find((p) => p.id === id);
411
+ this.emit("deletedObject", {deletedObject: deletedPolygon, id});
412
+ this.setPolygonList(this.polygonList.filter((polygon) => polygon.id !== id));
413
+ this.history.pushHistory(this.polygonList);
414
+ (_a = this._textAttributInstance) == null ? void 0 : _a.clearTextAttribute();
415
+ this.emit("selectedChange");
416
+ this.render();
417
+ }
418
+ deletePolygonPoint(index$1) {
419
+ if (!this.selectedID) {
420
+ return;
421
+ }
422
+ const {selectedPolygon} = this;
423
+ if (!selectedPolygon) {
424
+ return;
425
+ }
426
+ let {lowerLimitPointNum} = this.config;
427
+ if (lowerLimitPointNum < 3) {
428
+ lowerLimitPointNum = 3;
429
+ }
430
+ if (selectedPolygon.pointList.length <= lowerLimitPointNum) {
431
+ this.emit("messageInfo", `${index.getMessagesByLocale(constants.EMessage.LowerLimitErrorNotice, this.lang)}${lowerLimitPointNum}`);
432
+ return;
433
+ }
434
+ selectedPolygon == null ? void 0 : selectedPolygon.pointList.splice(index$1, 1);
435
+ this.history.pushHistory(this.polygonList);
436
+ this.render();
437
+ }
438
+ spaceKeydown() {
439
+ var _a, _b, _c;
440
+ if (this.selectedID) {
441
+ if (((_a = this.selectedPolygon) == null ? void 0 : _a.isRect) === true) {
442
+ this.emit("messageInfo", `${index.getMessagesByLocale(constants.EMessage.UnableToReannotation, this.lang)}`);
443
+ return;
444
+ }
445
+ this.editPolygonID = this.selectedID;
446
+ this.drawingPointList = (_c = (_b = this.selectedPolygon) == null ? void 0 : _b.pointList) != null ? _c : [];
447
+ this.drawingHistory.empty();
448
+ this.drawingHistory.initRecord(this.drawingPointList);
449
+ this.hoverID = "";
450
+ this.deleteSelectedID();
451
+ this.render();
452
+ }
453
+ }
454
+ onTabKeyDown(e) {
455
+ e.preventDefault();
456
+ let sort = annotation.ESortDirection.ascend;
457
+ if (e.shiftKey) {
458
+ sort = annotation.ESortDirection.descend;
459
+ }
460
+ this.switchToNextPolygon(sort);
461
+ }
462
+ switchToNextPolygon(sort) {
463
+ if (this.drawingPointList.length > 0) {
464
+ return;
465
+ }
466
+ const [showingResult, selectedResult] = CommonToolUtils.getRenderResultList(this.polygonList, CommonToolUtils.getSourceID(this.basicResult), this.attributeLockList, this.selectedID);
467
+ let polygonList = [...showingResult];
468
+ if (selectedResult) {
469
+ polygonList = [...polygonList, selectedResult];
470
+ }
471
+ const viewPort = CanvasUtils.getViewPort(this.canvas, this.currentPos, this.zoom);
472
+ const sortList = polygonList.map((v) => {
473
+ var _a, _b, _c, _d;
474
+ return __spreadProps(__spreadValues({}, v), {
475
+ x: (_b = (_a = v.pointList[0]) == null ? void 0 : _a.x) != null ? _b : 0,
476
+ y: (_d = (_c = v.pointList[0]) == null ? void 0 : _c.y) != null ? _d : 0
477
+ });
478
+ }).filter((polygon) => CanvasUtils.inViewPort({x: polygon.x, y: polygon.y}, viewPort));
479
+ const nextSelectedResult = CommonToolUtils.getNextSelectedRectID(sortList, sort, this.selectedID);
480
+ if (nextSelectedResult) {
481
+ this.setSelectedID(nextSelectedResult.id);
482
+ const {selectedPolygon} = this;
483
+ if (selectedPolygon) {
484
+ this.setDefaultAttribute(selectedPolygon.attribute);
485
+ }
486
+ }
487
+ this.render();
488
+ }
489
+ onKeyDown(e) {
490
+ if (!CommonToolUtils.hotkeyFilter(e)) {
491
+ return;
492
+ }
493
+ if (super.onKeyDown(e) === false) {
494
+ return;
495
+ }
496
+ const {keyCode: keyCode$1} = e;
497
+ switch (keyCode$1) {
498
+ case keyCode.Space:
499
+ this.spaceKeydown();
500
+ break;
501
+ case keyCode.Esc:
502
+ this.drawingPointList = [];
503
+ this.editPolygonID = "";
504
+ break;
505
+ case keyCode.F:
506
+ if (this.selectedID) {
507
+ this.setPolygonValidAndRender(this.selectedID);
508
+ }
509
+ break;
510
+ case keyCode.Z:
511
+ if (e.altKey) {
512
+ this.onCombinedExecute();
513
+ return;
514
+ }
515
+ this.setIsHidden(!this.isHidden);
516
+ this.render();
517
+ break;
518
+ case keyCode.Delete:
519
+ this.deletePolygon(this.selectedID);
520
+ this.render();
521
+ break;
522
+ case keyCode.Ctrl:
523
+ this.isCtrl = true;
524
+ break;
525
+ case keyCode.Alt:
526
+ if (this.isAlt === false) {
527
+ e.preventDefault();
528
+ this.isAlt = true;
529
+ this.render();
530
+ }
531
+ break;
532
+ case keyCode.Tab: {
533
+ this.onTabKeyDown(e);
534
+ break;
535
+ }
536
+ case keyCode.X:
537
+ if (e.altKey) {
538
+ this.segment();
539
+ }
540
+ break;
541
+ default: {
542
+ if (this.config.attributeConfigurable) {
543
+ const keyCode2Attribute = AttributeUtils["default"].getAttributeByKeycode(keyCode$1, this.config.attributeList);
544
+ if (keyCode2Attribute !== void 0) {
545
+ this.setDefaultAttribute(keyCode2Attribute);
546
+ }
547
+ }
548
+ break;
549
+ }
550
+ }
551
+ }
552
+ onKeyUp(e) {
553
+ super.onKeyUp(e);
554
+ switch (e.keyCode) {
555
+ case keyCode.Ctrl:
556
+ this.isCtrl = false;
557
+ break;
558
+ case keyCode.Alt: {
559
+ const oldAlt = this.isAlt;
560
+ this.isAlt = false;
561
+ if (oldAlt === true) {
562
+ this.render();
563
+ }
564
+ break;
565
+ }
566
+ }
567
+ }
568
+ rightMouseUp(e) {
569
+ if (this.drawingPointList.length > 0) {
570
+ this.addDrawingPointToPolygonList();
571
+ return;
572
+ }
573
+ this.setSelectedID(this.hoverID);
574
+ const {selectedPolygon} = this;
575
+ if (selectedPolygon) {
576
+ this.setDefaultAttribute(selectedPolygon.attribute);
577
+ }
578
+ }
579
+ onLeftDblClick(e) {
580
+ if (this.hoverEdgeIndex > -1) {
581
+ const currentCoord = this.getCoordinateUnderZoom(e);
582
+ const {selectedPolygon} = this;
583
+ if (!selectedPolygon) {
584
+ return;
585
+ }
586
+ if (selectedPolygon.isRect === true) {
587
+ this.emit("messageInfo", `${index.getMessagesByLocale(constants.EMessage.ForbidAddNewPoint, this.lang)}`);
588
+ this.clearPolygonDrag();
589
+ return;
590
+ }
591
+ const {dropFoot} = PolygonUtils.getClosestPoint(currentCoord, this.polygonListUnderZoom, this.config.lineType, tool.edgeAdsorptionScope);
592
+ if (!dropFoot) {
593
+ return;
594
+ }
595
+ const {upperLimitPointNum} = this.config;
596
+ if (upperLimitPointNum && selectedPolygon.pointList.length >= upperLimitPointNum) {
597
+ this.emit("messageInfo", `${index.getMessagesByLocale(constants.EMessage.UpperLimitErrorNotice, this.lang)}${upperLimitPointNum}`);
598
+ this.clearPolygonDrag();
599
+ return;
600
+ }
601
+ selectedPolygon == null ? void 0 : selectedPolygon.pointList.splice(this.hoverEdgeIndex + 1, 0, AxisUtils["default"].changePointByZoom(dropFoot, 1 / this.zoom));
602
+ this.setPolygonDataByID(selectedPolygon, this.selectedID);
603
+ this.history.pushHistory(this.polygonList);
604
+ this.hoverPointIndex = -1;
605
+ this.hoverEdgeIndex = -1;
606
+ this.render();
607
+ }
608
+ this.dragInfo = void 0;
609
+ }
610
+ onRightDblClick(e) {
611
+ this.dragInfo = void 0;
612
+ this.clearImgDrag();
613
+ const hoverID = this.getHoverID(e);
614
+ const hoverPointIndex = this.getHoverPointIndex(e);
615
+ if (this.hoverPointIndex > -1 && this.hoverPointIndex === hoverPointIndex) {
616
+ this.deletePolygonPoint(hoverPointIndex);
617
+ this.dragInfo = void 0;
618
+ this.hoverPointIndex = -1;
619
+ this.render();
620
+ return;
621
+ }
622
+ if (this.hoverID === this.selectedID) {
623
+ this.deletePolygon(hoverID);
624
+ }
625
+ this.render();
626
+ }
627
+ onMouseDown(e) {
628
+ if (super.onMouseDown(e) || this.forbidMouseOperation || e.ctrlKey === true) {
629
+ return;
630
+ }
631
+ this.dragMouseDown(e);
632
+ return true;
633
+ }
634
+ dragMouseDown(e) {
635
+ const firstPolygon = this.selectedPolygon;
636
+ if (!firstPolygon || e.button !== 0) {
637
+ return;
638
+ }
639
+ const hoverID = this.getHoverID(e);
640
+ if (hoverID !== this.selectedID) {
641
+ return;
642
+ }
643
+ const initPointList = firstPolygon.pointList;
644
+ const dragStartCoord = this.getCoordinateUnderZoom(e);
645
+ let changePointIndex = [0];
646
+ let dragTarget = annotation.EDragTarget.Plane;
647
+ this.dragStatus = annotation.EDragStatus.Start;
648
+ const closePointIndex = this.getHoverPointIndex(e);
649
+ const closeEdgeIndex = this.getHoverEdgeIndex(e);
650
+ if (closePointIndex > -1) {
651
+ dragTarget = annotation.EDragTarget.Point;
652
+ changePointIndex = [closePointIndex];
653
+ } else if (closeEdgeIndex > -1 && this.hoverEdgeIndex > -1) {
654
+ dragTarget = annotation.EDragTarget.Line;
655
+ changePointIndex = [closeEdgeIndex, (closeEdgeIndex + 1) % initPointList.length];
656
+ }
657
+ this.dragInfo = {
658
+ dragStartCoord,
659
+ dragTarget,
660
+ initPointList,
661
+ changePointIndex,
662
+ originPolygon: this.selectedPolygon,
663
+ dragPrevCoord: dragStartCoord,
664
+ originPolygonList: this.polygonList
665
+ };
666
+ }
667
+ segment() {
668
+ var _a;
669
+ if (!this.selectedID) {
670
+ return;
671
+ }
672
+ if (((_a = this.config) == null ? void 0 : _a.lineType) !== tool.ELineTypes.Line) {
673
+ return;
674
+ }
675
+ const selectedPointList = PolygonUtils.getPolygonPointList(this.selectedID, this.currentShowList);
676
+ const backgroundPolygonList = this.currentShowList.filter((v) => v.id !== this.selectedID);
677
+ if (backgroundPolygonList.length === 0 || selectedPointList.length === 0) {
678
+ return;
679
+ }
680
+ const wrapIndex = PolygonUtils.getWrapPolygonIndex(selectedPointList, backgroundPolygonList);
681
+ let newPolygonList = [...this.polygonList];
682
+ if (wrapIndex === -1) {
683
+ const newPointListArray = PolygonUtils.segmentPolygonByPolygon(selectedPointList, backgroundPolygonList);
684
+ if (!newPointListArray) {
685
+ return;
686
+ }
687
+ const newPointList = newPointListArray.shift();
688
+ if (!newPointList) {
689
+ return;
690
+ }
691
+ let defaultAttribute = "";
692
+ let valid = true;
693
+ const sourceID = CommonToolUtils.getSourceID(this.basicResult);
694
+ let textAttribute = "";
695
+ newPolygonList = this.polygonList.map((v) => {
696
+ var _a2, _b;
697
+ if (v.id === this.selectedID) {
698
+ defaultAttribute = v.attribute;
699
+ valid = (_a2 = v == null ? void 0 : v.valid) != null ? _a2 : true;
700
+ textAttribute = (_b = v == null ? void 0 : v.textAttribute) != null ? _b : "";
701
+ return __spreadProps(__spreadValues({}, v), {
702
+ pointList: newPointList
703
+ });
704
+ }
705
+ return v;
706
+ });
707
+ if (newPointListArray.length > 0) {
708
+ newPointListArray.forEach((v, i) => {
709
+ newPolygonList.push({
710
+ sourceID,
711
+ id: uuid(8, 62),
712
+ pointList: v,
713
+ valid,
714
+ order: CommonToolUtils.getMaxOrder(this.currentShowList) + 1 + i,
715
+ attribute: defaultAttribute,
716
+ textAttribute
717
+ });
718
+ });
719
+ }
720
+ } else {
721
+ newPolygonList[wrapIndex].pointList = PolygonUtils.clipPolygonFromWrapPolygon(selectedPointList, newPolygonList[wrapIndex].pointList);
722
+ newPolygonList = newPolygonList.filter((v) => v.id !== this.selectedID);
723
+ }
724
+ this.setPolygonList(newPolygonList);
725
+ this.history.pushHistory(newPolygonList);
726
+ this.render();
727
+ }
728
+ onCombinedExecute() {
729
+ if (!this.selectedID) {
730
+ this.emit("messageInfo", lbUtils.i18n.t("PolygonsToBeCombinedNeedToBeSelected"));
731
+ return;
732
+ }
733
+ this.isCombined = !this.isCombined;
734
+ }
735
+ combine(e) {
736
+ var _a;
737
+ const hoverID = this.getHoverID(e);
738
+ if (!hoverID || !this.selectedID || this.selectedID === hoverID) {
739
+ return;
740
+ }
741
+ if (((_a = this.config) == null ? void 0 : _a.lineType) !== tool.ELineTypes.Line) {
742
+ this.emit("messageInfo", lbUtils.i18n.t("CurveModeDoesNotSupportCutting"));
743
+ return;
744
+ }
745
+ const selectedPolygon = this.polygonList.find((v) => v.id === this.selectedID);
746
+ const combinedPolygon = this.currentShowList.find((v) => v.id === hoverID);
747
+ if (!combinedPolygon || !selectedPolygon) {
748
+ return;
749
+ }
750
+ const composeData = PolygonUtils.combinePolygonWithPolygon(selectedPolygon, combinedPolygon);
751
+ if (!composeData) {
752
+ return;
753
+ }
754
+ const {newPolygon, unionList} = composeData;
755
+ if (unionList.length === 1 && newPolygon) {
756
+ const newPolygonList = this.polygonList.filter((v) => !unionList.includes(v.id)).map((v) => {
757
+ if (v.id === this.selectedID) {
758
+ return newPolygon;
759
+ }
760
+ return v;
761
+ });
762
+ this.setPolygonList(newPolygonList);
763
+ this.history.pushHistory(newPolygonList);
764
+ this.render();
765
+ this.emit("messageInfo", lbUtils.i18n.t("CombineSuccess"));
766
+ } else {
767
+ this.emit("messageInfo", lbUtils.i18n.t("CombiningFailedNotify"));
768
+ }
769
+ this.isCombined = false;
770
+ }
771
+ isPolygonOutSide(selectedPointList) {
772
+ if (this.dependToolName && this.basicCanvas && this.basicResult) {
773
+ let isOutSide = false;
774
+ switch (this.dependToolName) {
775
+ case tool.EToolName.Rect: {
776
+ isOutSide = selectedPointList.filter((v) => !RectUtils.isInRect(v, this.basicResult)).length > 0;
777
+ break;
778
+ }
779
+ case tool.EToolName.Polygon: {
780
+ isOutSide = PolygonUtils.isPointListOutSidePolygon(selectedPointList, this.basicResult.pointList, this.config.lineType);
781
+ break;
782
+ }
783
+ }
784
+ return isOutSide;
785
+ }
786
+ if (!this.imgInfo) {
787
+ return false;
788
+ }
789
+ const {left, top, right, bottom} = MathUtils["default"].calcViewportBoundaries(AxisUtils["default"].changePointListByZoom(selectedPointList, this.zoom));
790
+ const scope = 1e-5;
791
+ if (left < 0 || top < 0 || right > this.imgInfo.width + scope || bottom > this.imgInfo.height + scope) {
792
+ return true;
793
+ }
794
+ return false;
795
+ }
796
+ getDragOffset(e, selectedPolygon) {
797
+ var _a;
798
+ const coordinate = this.getCoordinateUnderZoom(e);
799
+ const {dragTarget, dragPrevCoord, changePointIndex, initPointList, dragStartCoord} = this.dragInfo;
800
+ if (this.pattern === tool.EPolygonPattern.Rect && (selectedPolygon == null ? void 0 : selectedPolygon.isRect) === true && changePointIndex && [annotation.EDragTarget.Line].includes(dragTarget)) {
801
+ const firstPointIndex = MathUtils["default"].getArrayIndex(changePointIndex[0] - 2, 4);
802
+ const secondPointIndex = MathUtils["default"].getArrayIndex(changePointIndex[0] - 1, 4);
803
+ const basicLine = [initPointList[firstPointIndex], initPointList[secondPointIndex]];
804
+ const perpendicularOffset = MathUtils["default"].getRectPerpendicularOffset(dragStartCoord, coordinate, basicLine);
805
+ return {
806
+ x: perpendicularOffset.x / this.zoom,
807
+ y: perpendicularOffset.y / this.zoom
808
+ };
809
+ }
810
+ if (((_a = this.dragInfo) == null ? void 0 : _a.dragTarget) === annotation.EDragTarget.Plane) {
811
+ return {
812
+ x: (coordinate.x - dragPrevCoord.x) / this.zoom,
813
+ y: (coordinate.y - dragPrevCoord.y) / this.zoom
814
+ };
815
+ }
816
+ return {
817
+ x: (coordinate.x - dragStartCoord.x) / this.zoom,
818
+ y: (coordinate.y - dragStartCoord.y) / this.zoom
819
+ };
820
+ }
821
+ dragPolygon(e, selectedPolygon) {
822
+ let selectedPointList = ___default["default"].cloneDeep(selectedPolygon == null ? void 0 : selectedPolygon.pointList);
823
+ if (!selectedPointList || !this.dragInfo) {
824
+ return;
825
+ }
826
+ const {initPointList, dragTarget, changePointIndex} = this.dragInfo;
827
+ const offset = this.getDragOffset(e, selectedPolygon);
828
+ this.dragStatus = annotation.EDragStatus.Move;
829
+ switch (dragTarget) {
830
+ case annotation.EDragTarget.Plane:
831
+ selectedPointList = selectedPointList.map((v) => __spreadProps(__spreadValues({}, v), {
832
+ x: v.x + offset.x,
833
+ y: v.y + offset.y
834
+ }));
835
+ break;
836
+ case annotation.EDragTarget.Point:
837
+ case annotation.EDragTarget.Line:
838
+ selectedPointList = selectedPointList.map((n, i) => {
839
+ if (changePointIndex && changePointIndex.includes(i)) {
840
+ return __spreadProps(__spreadValues({}, n), {
841
+ x: initPointList[i].x + offset.x,
842
+ y: initPointList[i].y + offset.y
843
+ });
844
+ }
845
+ return n;
846
+ });
847
+ break;
848
+ }
849
+ if (this.pattern === tool.EPolygonPattern.Rect && (selectedPolygon == null ? void 0 : selectedPolygon.isRect) === true && dragTarget === annotation.EDragTarget.Point && changePointIndex) {
850
+ const newPointList = MathUtils["default"].getPointListFromPointOffset(initPointList, changePointIndex[0], offset);
851
+ selectedPointList = newPointList;
852
+ }
853
+ if (this.config.drawOutsideTarget === false && this.imgInfo) {
854
+ const isOutSide = this.isPolygonOutSide(selectedPointList);
855
+ if (isOutSide) {
856
+ return;
857
+ }
858
+ }
859
+ return selectedPointList;
860
+ }
861
+ onDragMove(e) {
862
+ const newPolygonList = this.polygonList.map((v) => {
863
+ if (v.id === this.selectedID) {
864
+ const selectedPointList = this.dragPolygon(e, v);
865
+ if (!selectedPointList) {
866
+ return v;
867
+ }
868
+ const newData = __spreadProps(__spreadValues({}, v), {
869
+ pointList: selectedPointList
870
+ });
871
+ if (v.isRect === true && this.pattern === tool.EPolygonPattern.Normal) {
872
+ Object.assign(newData, {isRect: false});
873
+ }
874
+ return newData;
875
+ }
876
+ return v;
877
+ });
878
+ this.dragInfo.dragPrevCoord = this.getCoordinateUnderZoom(e);
879
+ this.setPolygonList(newPolygonList);
880
+ this.render();
881
+ }
882
+ onMouseMove(e) {
883
+ if (super.onMouseMove(e) || this.forbidMouseOperation || !this.imgInfo) {
884
+ return;
885
+ }
886
+ if (this.enableDrag) {
887
+ this.onDragMove(e);
888
+ return;
889
+ }
890
+ let hoverPointIndex = -1;
891
+ let hoverEdgeIndex = -1;
892
+ const {selectedID} = this;
893
+ if (selectedID) {
894
+ this.hoverEdgeIndex = -1;
895
+ this.hoverPointIndex = -1;
896
+ hoverPointIndex = this.getHoverPointIndex(e);
897
+ if (hoverPointIndex > -1) {
898
+ this.hoverPointIndex = hoverPointIndex;
899
+ } else {
900
+ hoverEdgeIndex = this.getHoverEdgeIndex(e);
901
+ this.hoverEdgeIndex = hoverEdgeIndex;
902
+ }
903
+ }
904
+ if (this.drawingPointList.length > 0) {
905
+ return;
906
+ }
907
+ const newHoverID = this.getHoverID(e);
908
+ if (this.hoverID !== newHoverID) {
909
+ this.hoverID = newHoverID;
910
+ this.render();
911
+ }
912
+ }
913
+ leftMouseUpdateValid(e) {
914
+ const hoverID = this.getHoverID(e);
915
+ if (this.drawingPointList.length === 0 && e.ctrlKey === true && hoverID) {
916
+ this.setPolygonValidAndRender(hoverID);
917
+ return true;
918
+ }
919
+ return false;
920
+ }
921
+ leftMouseUp(e) {
922
+ const isCtrl = this.leftMouseUpdateValid(e);
923
+ if (isCtrl) {
924
+ return;
925
+ }
926
+ this.addPointInDrawing(e);
927
+ }
928
+ onMouseUp(e) {
929
+ if (this.isCombined) {
930
+ switch (e.button) {
931
+ case 0:
932
+ this.combine(e);
933
+ break;
934
+ case 2:
935
+ this.isCombined = false;
936
+ break;
937
+ default:
938
+ return;
939
+ }
940
+ return;
941
+ }
942
+ if (super.onMouseUp(e) || this.forbidMouseOperation || !this.imgInfo) {
943
+ return void 0;
944
+ }
945
+ if (this.dragInfo && this.dragStatus === annotation.EDragStatus.Move) {
946
+ this.emit("updateResult");
947
+ this.emitUpdatePolygonByDrag();
948
+ this.dragInfo = void 0;
949
+ this.dragStatus = annotation.EDragStatus.Wait;
950
+ this.history.pushHistory(this.polygonList);
951
+ return;
952
+ }
953
+ switch (e.button) {
954
+ case 0: {
955
+ this.leftMouseUp(e);
956
+ break;
957
+ }
958
+ case 2: {
959
+ this.rightMouseUp(e);
960
+ break;
961
+ }
962
+ }
963
+ this.render();
964
+ }
965
+ dragMouseUp() {
966
+ if (this.dragStatus === annotation.EDragStatus.Start) {
967
+ this.dragInfo = void 0;
968
+ this.dragStatus = annotation.EDragStatus.Wait;
969
+ }
970
+ }
971
+ exportData() {
972
+ const {polygonList} = this;
973
+ return [polygonList, this.basicImgInfo];
974
+ }
975
+ getTextIconSvg(attribute = "") {
976
+ return AttributeUtils["default"].getTextIconSvg(attribute, this.config.attributeList, this.config.attributeConfigurable, this.baseIcon);
977
+ }
978
+ getCurrentSelectedData() {
979
+ const {selectedPolygon} = this;
980
+ if (!selectedPolygon) {
981
+ return;
982
+ }
983
+ const toolColor = this.getColor(selectedPolygon.attribute);
984
+ const color = selectedPolygon.valid ? toolColor == null ? void 0 : toolColor.valid.stroke : toolColor == null ? void 0 : toolColor.invalid.stroke;
985
+ return {
986
+ width: TEXT_MAX_WIDTH,
987
+ textAttribute: selectedPolygon.textAttribute,
988
+ color
989
+ };
990
+ }
991
+ updateSelectedTextAttribute(newTextAttribute) {
992
+ if (this._textAttributInstance && newTextAttribute && this.selectedID) {
993
+ let textAttribute = newTextAttribute;
994
+ if (AttributeUtils["default"].textAttributeValidate(this.config.textCheckType, "", textAttribute) === false) {
995
+ this.emit("messageError", AttributeUtils["default"].getErrorNotice(this.config.textCheckType, this.lang));
996
+ textAttribute = "";
997
+ }
998
+ this.setPolygonList(AttributeUtils["default"].textChange(textAttribute, this.selectedID, this.polygonList));
999
+ this.emit("updateTextAttribute");
1000
+ this.render();
1001
+ }
1002
+ }
1003
+ renderTextAttribute() {
1004
+ var _a;
1005
+ const {selectedPolygon} = this;
1006
+ if (!this.ctx || this.config.textConfigurable === false || !selectedPolygon) {
1007
+ return;
1008
+ }
1009
+ const {pointList, attribute, valid, textAttribute} = selectedPolygon;
1010
+ const {x, y} = pointList[pointList.length - 1];
1011
+ const newWidth = TEXT_MAX_WIDTH;
1012
+ const coordinate = AxisUtils["default"].getOffsetCoordinate({x, y}, this.currentPos, this.zoom);
1013
+ const toolColor = this.getColor(attribute);
1014
+ const color = valid ? toolColor == null ? void 0 : toolColor.valid.stroke : toolColor == null ? void 0 : toolColor.invalid.stroke;
1015
+ if (!this._textAttributInstance) {
1016
+ this._textAttributInstance = new textAttributeClass({
1017
+ width: newWidth,
1018
+ container: this.container,
1019
+ icon: this.getTextIconSvg(attribute),
1020
+ color,
1021
+ getCurrentSelectedData: this.getCurrentSelectedData,
1022
+ updateSelectedTextAttribute: this.updateSelectedTextAttribute
1023
+ });
1024
+ }
1025
+ if (this._textAttributInstance && !((_a = this._textAttributInstance) == null ? void 0 : _a.isExit)) {
1026
+ this._textAttributInstance.appendToContainer();
1027
+ }
1028
+ this._textAttributInstance.update(`${textAttribute}`, {
1029
+ left: coordinate.x,
1030
+ top: coordinate.y,
1031
+ color,
1032
+ width: newWidth
1033
+ });
1034
+ }
1035
+ renderStaticPolygon() {
1036
+ var _a;
1037
+ if (this.isHidden === false) {
1038
+ (_a = this.visiblePolygonList) == null ? void 0 : _a.forEach((polygon) => {
1039
+ var _a2, _b, _c, _d, _e;
1040
+ if ([this.selectedID, this.editPolygonID].includes(polygon.id)) {
1041
+ return;
1042
+ }
1043
+ const {textAttribute, attribute} = polygon;
1044
+ const toolColor = this.getColor(attribute);
1045
+ const toolData = StyleUtils.getStrokeAndFill(toolColor, polygon.valid);
1046
+ const transformPointList = AxisUtils["default"].changePointListByZoom(polygon.pointList || [], this.zoom, this.currentPos);
1047
+ DrawUtils.drawPolygonWithFillAndLine(this.canvas, transformPointList, {
1048
+ fillColor: toolData.fill,
1049
+ strokeColor: toolData.stroke,
1050
+ pointColor: "white",
1051
+ thickness: (_b = (_a2 = this.style) == null ? void 0 : _a2.width) != null ? _b : 2,
1052
+ lineCap: "round",
1053
+ isClose: true,
1054
+ lineType: (_c = this.config) == null ? void 0 : _c.lineType
1055
+ });
1056
+ let showText = `${(_d = AttributeUtils["default"].getAttributeShowText(attribute, this.config.attributeList)) != null ? _d : ""}`;
1057
+ if (((_e = this.config) == null ? void 0 : _e.isShowOrder) && (polygon == null ? void 0 : polygon.order) > 0) {
1058
+ showText = `${polygon.order} ${showText}`;
1059
+ }
1060
+ DrawUtils.drawText(this.canvas, transformPointList[0], showText, __spreadValues({
1061
+ color: toolData.stroke
1062
+ }, annotation.DEFAULT_TEXT_OFFSET));
1063
+ const endPoint = transformPointList[transformPointList.length - 1];
1064
+ DrawUtils.drawText(this.canvas, {x: endPoint.x + annotation.TEXT_ATTRIBUTE_OFFSET.x, y: endPoint.y + annotation.TEXT_ATTRIBUTE_OFFSET.y}, textAttribute, __spreadValues({
1065
+ color: toolData.stroke
1066
+ }, annotation.DEFAULT_TEXT_OFFSET));
1067
+ });
1068
+ }
1069
+ }
1070
+ renderSelectedPolygon() {
1071
+ var _a, _b, _c;
1072
+ const {selectedPolygon} = this;
1073
+ if (selectedPolygon) {
1074
+ const toolColor = this.getColor(selectedPolygon.attribute);
1075
+ const toolData = StyleUtils.getStrokeAndFill(toolColor, selectedPolygon.valid, {isSelected: true});
1076
+ DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas, AxisUtils["default"].changePointListByZoom(selectedPolygon.pointList, this.zoom, this.currentPos), {
1077
+ fillColor: toolData.fill,
1078
+ strokeColor: toolData.stroke,
1079
+ pointColor: "white",
1080
+ thickness: 2,
1081
+ lineCap: "round",
1082
+ isClose: true,
1083
+ lineType: (_a = this.config) == null ? void 0 : _a.lineType
1084
+ });
1085
+ let showText = `${(_b = AttributeUtils["default"].getAttributeShowText(selectedPolygon.attribute, this.config.attributeList)) != null ? _b : ""}`;
1086
+ if (((_c = this.config) == null ? void 0 : _c.isShowOrder) && (selectedPolygon == null ? void 0 : selectedPolygon.order) > 0) {
1087
+ showText = `${selectedPolygon.order} ${showText}`;
1088
+ }
1089
+ DrawUtils.drawText(this.canvas, AxisUtils["default"].changePointByZoom(selectedPolygon.pointList[0], this.zoom, this.currentPos), showText, __spreadValues({
1090
+ color: toolData.stroke
1091
+ }, annotation.DEFAULT_TEXT_OFFSET));
1092
+ this.renderTextAttribute();
1093
+ }
1094
+ }
1095
+ renderHoverPolygon() {
1096
+ var _a;
1097
+ if (this.hoverID && this.hoverID !== this.editPolygonID) {
1098
+ const {hoverPolygon} = this;
1099
+ if (hoverPolygon) {
1100
+ let color = "";
1101
+ const toolColor = this.getColor(hoverPolygon.attribute);
1102
+ if (hoverPolygon.valid) {
1103
+ color = toolColor.validHover.fill;
1104
+ } else {
1105
+ color = StyleUtils.getStrokeAndFill(toolColor, false, {isHover: true}).fill;
1106
+ }
1107
+ DrawUtils.drawPolygonWithFill(this.canvas, AxisUtils["default"].changePointListByZoom(hoverPolygon.pointList, this.zoom, this.currentPos), {
1108
+ color,
1109
+ lineType: (_a = this.config) == null ? void 0 : _a.lineType
1110
+ });
1111
+ }
1112
+ }
1113
+ }
1114
+ renderPolygon() {
1115
+ var _a, _b, _c, _d;
1116
+ this.renderStaticPolygon();
1117
+ this.renderHoverPolygon();
1118
+ this.renderSelectedPolygon();
1119
+ const defaultColor = this.getColor(this.defaultAttribute);
1120
+ const toolData = StyleUtils.getStrokeAndFill(defaultColor, !this.isCtrl);
1121
+ if (((_a = this.drawingPointList) == null ? void 0 : _a.length) > 0) {
1122
+ let drawingPointList = [...this.drawingPointList];
1123
+ let coordinate = AxisUtils["default"].getOriginCoordinateWithOffsetCoordinate(this.coord, this.zoom, this.currentPos);
1124
+ if (this.pattern === tool.EPolygonPattern.Rect && drawingPointList.length === 2) {
1125
+ drawingPointList = MathUtils["default"].getRectangleByRightAngle(coordinate, drawingPointList);
1126
+ } else {
1127
+ if (((_b = this.config) == null ? void 0 : _b.edgeAdsorption) && this.isAlt === false) {
1128
+ const {dropFoot} = PolygonUtils.getClosestPoint(coordinate, this.polygonList, (_c = this.config) == null ? void 0 : _c.lineType, tool.edgeAdsorptionScope / this.zoom);
1129
+ if (dropFoot) {
1130
+ coordinate = dropFoot;
1131
+ }
1132
+ }
1133
+ drawingPointList.push(coordinate);
1134
+ }
1135
+ DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas, AxisUtils["default"].changePointListByZoom(drawingPointList, this.zoom, this.currentPos), {
1136
+ fillColor: toolData.fill,
1137
+ strokeColor: toolData.stroke,
1138
+ pointColor: "white",
1139
+ thickness: 2,
1140
+ lineCap: "round",
1141
+ isClose: false,
1142
+ lineType: this.config.lineType
1143
+ });
1144
+ }
1145
+ if (this.hoverPointIndex > -1 && this.selectedID) {
1146
+ const selectdPolygon = this.selectedPolygon;
1147
+ if (!selectdPolygon) {
1148
+ return;
1149
+ }
1150
+ const hoverColor = StyleUtils.getStrokeAndFill(defaultColor, selectdPolygon.valid, {isSelected: true});
1151
+ const point = selectdPolygon == null ? void 0 : selectdPolygon.pointList[this.hoverPointIndex];
1152
+ if (point) {
1153
+ const {x, y} = AxisUtils["default"].changePointByZoom(point, this.zoom, this.currentPos);
1154
+ DrawUtils.drawCircleWithFill(this.canvas, {x, y}, 5, {
1155
+ color: hoverColor.fill
1156
+ });
1157
+ }
1158
+ }
1159
+ if (this.hoverEdgeIndex > -1 && this.selectedID) {
1160
+ const selectdPolygon = this.selectedPolygon;
1161
+ if (!selectdPolygon) {
1162
+ return;
1163
+ }
1164
+ const selectedColor = StyleUtils.getStrokeAndFill(defaultColor, selectdPolygon.valid, {isSelected: true});
1165
+ DrawUtils.drawLineWithPointList(this.canvas, AxisUtils["default"].changePointListByZoom(selectdPolygon.pointList, this.zoom, this.currentPos), {
1166
+ color: selectedColor.stroke,
1167
+ thickness: 10,
1168
+ hoverEdgeIndex: this.hoverEdgeIndex,
1169
+ lineType: (_d = this.config) == null ? void 0 : _d.lineType
1170
+ });
1171
+ }
1172
+ }
1173
+ render() {
1174
+ if (!this.ctx) {
1175
+ return;
1176
+ }
1177
+ super.render();
1178
+ this.renderPolygon();
1179
+ this.renderCursorLine(this.getLineColor(this.defaultAttribute));
1180
+ }
1181
+ renderCursorLine(lineColor) {
1182
+ super.renderCursorLine(lineColor);
1183
+ if (this.isCombined) {
1184
+ const {x, y} = this.coord;
1185
+ const padding = 10;
1186
+ const rectWidth = 186;
1187
+ const rectHeight = 32;
1188
+ DrawUtils.drawRectWithFill(this.canvas, {
1189
+ x: x + padding,
1190
+ y: y - padding * 4 - 1,
1191
+ width: rectWidth,
1192
+ height: rectHeight
1193
+ }, {color: "black"});
1194
+ DrawUtils.drawText(this.canvas, {x, y}, lbUtils.i18n.t("ClickAnotherPolygon"), {
1195
+ textAlign: "center",
1196
+ color: "white",
1197
+ offsetX: rectWidth / 2 + padding,
1198
+ offsetY: -(rectHeight / 2 + padding / 2)
1199
+ });
1200
+ DrawUtils.drawRect(this.canvas, {
1201
+ x: x - padding,
1202
+ y: y - padding,
1203
+ width: padding * 2,
1204
+ height: padding * 2
1205
+ }, {lineDash: [6], color: "white"});
1206
+ }
1207
+ }
1208
+ undo() {
1209
+ if (this.drawingPointList.length > 0) {
1210
+ const drawingPointList = this.drawingHistory.undo();
1211
+ if (!drawingPointList) {
1212
+ return;
1213
+ }
1214
+ this.drawingPointList = drawingPointList;
1215
+ this.render();
1216
+ return;
1217
+ }
1218
+ const polygonList = this.history.undo();
1219
+ if (polygonList) {
1220
+ if (polygonList.length !== this.polygonList.length) {
1221
+ this.deleteSelectedID();
1222
+ }
1223
+ this.setPolygonList(polygonList);
1224
+ this.render();
1225
+ }
1226
+ }
1227
+ redo() {
1228
+ if (this.drawingPointList.length > 0) {
1229
+ const drawingPointList = this.drawingHistory.redo();
1230
+ if (!drawingPointList) {
1231
+ return;
1232
+ }
1233
+ this.drawingPointList = drawingPointList;
1234
+ this.render();
1235
+ return;
1236
+ }
1237
+ const polygonList = this.history.redo();
1238
+ if (polygonList) {
1239
+ if (polygonList.length !== this.polygonList.length) {
1240
+ this.deleteSelectedID();
1241
+ }
1242
+ this.setPolygonList(polygonList);
1243
+ this.render();
1244
+ }
1245
+ }
1246
+ deleteSelectedID() {
1247
+ this.setSelectedID("");
1248
+ }
1249
+ }
1250
+
1251
+ module.exports = PolygonOperation;