dxfview 0.0.4-beta.9 → 0.0.5-beta

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.
@@ -1,7 +1,11 @@
1
1
  import * as THREE from "three";
2
2
  import { BaseAnnotationDrawable, AnnotationModeType, AnnotationData } from "./BaseAnnotationDrawable";
3
+ import { EventInfo } from "../../core/input/InputManager";
3
4
  import type { BaseViewer } from "../../core/viewers";
4
5
  import { Plugin } from "../../core/viewers/Plugin";
6
+ export interface AnnotationPluginOptions {
7
+ segmentLabelScaleWithZoom?: boolean;
8
+ }
5
9
  export declare class AnnotationPlugin extends Plugin {
6
10
  static DEFAULT_ID: string;
7
11
  selectedDrawable: BaseAnnotationDrawable | undefined;
@@ -13,10 +17,17 @@ export declare class AnnotationPlugin extends Plugin {
13
17
  private snapToleranceInPixel;
14
18
  private annotations;
15
19
  private activeAnnotationType;
20
+ private subtractMode;
21
+ private additionMode;
16
22
  private mobileTouchHelper?;
17
23
  private selectedMaskColor?;
24
+ private snapObjects;
25
+ private snapObjectsDirty;
26
+ private pendingSnapDrawableIds;
27
+ private snapLineMaterial?;
28
+ private segmentLabelScaleWithZoom;
18
29
  private readonly partitionLabels;
19
- constructor(viewer: BaseViewer);
30
+ constructor(viewer: BaseViewer, options?: AnnotationPluginOptions);
20
31
  getDrawableList(): {
21
32
  id: string;
22
33
  position: THREE.Vector3;
@@ -24,7 +35,16 @@ export declare class AnnotationPlugin extends Plugin {
24
35
  details: import("./BaseAnnotationDrawable").ClosedShape;
25
36
  }[];
26
37
  getDrawableDatas(): AnnotationData[];
38
+ getSelectedDrawable(): BaseAnnotationDrawable | undefined;
39
+ setSelectedDrawable(drawable?: BaseAnnotationDrawable | null, fireEvent?: boolean): void;
40
+ clearSelection(): void;
27
41
  setDrawableDatas(datas: AnnotationData[]): void;
42
+ getSnapObjects(excludeId?: string): THREE.Object3D[];
43
+ invalidateSnapObjects(): void;
44
+ private rebuildSnapObjects;
45
+ private disposeSnapObjects;
46
+ private getSnapLineMaterial;
47
+ private collectDrawableSegments;
28
48
  getAigcJson(): {
29
49
  properties: {
30
50
  uuid: number;
@@ -65,6 +85,12 @@ export declare class AnnotationPlugin extends Plugin {
65
85
  * 计算方向角度(基于第一条边)
66
86
  */
67
87
  private calculateDirection;
88
+ /**
89
+ * 根据边界与门的点信息判断门的朝向(第三个点在内:270,反之 90)
90
+ * @param boundaryPoints 边界的点集合
91
+ * @param doorPoints 门的点集合
92
+ */
93
+ calculateDoorDirectionByBoundary(boundaryPoints: number[][], doorPoints: number[][]): number | undefined;
68
94
  /**
69
95
  * 中文标签映射到英文
70
96
  */
@@ -72,6 +98,9 @@ export declare class AnnotationPlugin extends Plugin {
72
98
  private initEvents;
73
99
  protected get canvas(): HTMLCanvasElement;
74
100
  protected get raycaster(): any;
101
+ setSegmentLabelScaleWithZoom(enabled: boolean): void;
102
+ getSegmentLabelScaleWithZoom(): boolean;
103
+ private applyDrawableRuntimeContext;
75
104
  add(drawable: BaseAnnotationDrawable, needFireEvent?: boolean): void;
76
105
  create(data: AnnotationData): BaseAnnotationDrawable;
77
106
  remove(drawable: BaseAnnotationDrawable, needFireEvent?: boolean): void;
@@ -84,6 +113,16 @@ export declare class AnnotationPlugin extends Plugin {
84
113
  * We should call this once camera's zoom, fov or position/target changed, etc.
85
114
  */
86
115
  private updateSnapTolerance;
116
+ /**
117
+ * 设置正交模式开关。
118
+ * 启用后,绘制标注的线条会被约束为水平或垂直方向。
119
+ * @param enabled 是否启用正交模式
120
+ */
121
+ setOrthoModeEnabled(enabled: boolean): void;
122
+ /**
123
+ * 获取正交模式是否启用。
124
+ */
125
+ isOrthoModeEnabled(): boolean;
87
126
  /**
88
127
  *
89
128
  * @param {AnnotationModeType} type
@@ -108,6 +147,30 @@ export declare class AnnotationPlugin extends Plugin {
108
147
  * @returns {boolean} Is annotating now
109
148
  */
110
149
  isAnnotating(): boolean;
150
+ /**
151
+ * 设置挖空模式(减去图形模式)
152
+ * @param enabled 是否启用挖空模式
153
+ * @description {en} Sets subtract mode. When enabled, drawing a new shape inside an existing annotation will subtract/cut out that area.
154
+ * @description {zh} 设置挖空模式。启用后,在现有标注内绘制新图形将从原标注中减去该区域。
155
+ */
156
+ setSubtractMode(enabled: boolean): void;
157
+ /**
158
+ * 获取当前挖空模式状态
159
+ * @returns {boolean} 是否启用挖空模式
160
+ */
161
+ getSubtractMode(): boolean;
162
+ /**
163
+ * 设置添加模式(合并图形模式)
164
+ * @param enabled 是否启用添加模式
165
+ * @description {en} Sets addition mode. When enabled, drawing a new shape that intersects existing annotations will merge/union them together.
166
+ * @description {zh} 设置添加模式。启用后,绘制与现有标注相交的新图形将合并它们。
167
+ */
168
+ setAdditionMode(enabled: boolean): void;
169
+ /**
170
+ * 获取当前添加模式状态
171
+ * @returns {boolean} 是否启用添加模式
172
+ */
173
+ getAdditionMode(): boolean;
111
174
  /**
112
175
  *
113
176
  * @returns {AnnotationData[]}
@@ -121,6 +184,16 @@ export declare class AnnotationPlugin extends Plugin {
121
184
  */
122
185
  cancel(): void;
123
186
  private getLastDrawable;
187
+ /**
188
+ * 公开的撤回方法,和 Ctrl+Z 的逻辑一致
189
+ * 用于工具栏撤回按钮调用
190
+ */
191
+ undo(): void;
192
+ /**
193
+ * 公开的重做方法,和 Ctrl+Y 的逻辑一致
194
+ * 用于工具栏重做按钮调用
195
+ */
196
+ redo(): void;
124
197
  /**
125
198
  *
126
199
  * @param {AnnotationData[]} dataArray
@@ -150,6 +223,10 @@ export declare class AnnotationPlugin extends Plugin {
150
223
  */
151
224
  getById(id: string): BaseAnnotationDrawable;
152
225
  removeById(id: string): void;
226
+ /**
227
+ * 删除当前所选的标注,使用与按下 Delete 键相同的逻辑。如果删除了标注,则返回 true。
228
+ */
229
+ deleteSelectedAnnotation(): boolean;
153
230
  /**
154
231
  * Selects an annotation drawable by id.
155
232
  * @param {string} id
@@ -159,13 +236,28 @@ export declare class AnnotationPlugin extends Plugin {
159
236
  /**
160
237
  * Selects an annotation drawable.
161
238
  */
162
- select(drawable: BaseAnnotationDrawable, fireEvent?: boolean): void;
239
+ select(drawable: BaseAnnotationDrawable, fireEvent?: boolean, eventInfo?: EventInfo): void;
163
240
  /**
164
241
  *
165
242
  * @param renderEnabled If need render annotation
166
243
  * @description Unselects an annotation.
167
244
  */
168
245
  unselect(renderEnabled?: boolean): void;
246
+ private syncViewerOverlaySelection;
247
+ /**
248
+ * 批量吸附世界坐标点到DXF图形
249
+ * 使用标准的OSnapHelper进行吸附,和正常标注绘制时的吸附逻辑完全一致
250
+ *
251
+ * @param worldPoints 世界坐标点数组
252
+ * @param excludeId 排除的标注ID(避免吸附到自己)
253
+ * @returns 吸附后的世界坐标点数组
254
+ */
255
+ snapWorldPoints(worldPoints: THREE.Vector3[], excludeId?: string): THREE.Vector3[];
256
+ /**
257
+ * 停用吸附标记
258
+ * 在AI识别吸附完成后调用,清除视觉反馈标记
259
+ */
260
+ deactivateSnap(): void;
169
261
  /**
170
262
  * @description Destroy annotation plugin
171
263
  */
@@ -175,6 +267,7 @@ export declare class AnnotationPlugin extends Plugin {
175
267
  * 在当前选中图形基础上启动复制预览
176
268
  */
177
269
  startCopyForSelected(): void;
270
+ private shouldIgnoreSelectionWhileAnnotating;
178
271
  /**
179
272
  * 处理 DxfViewer 的统一点击事件,同步插件内部的选择状态
180
273
  * 当用户在非激活状态下点击标注时,DxfViewer 会选择对应的 drawable 并触发此事件
@@ -14,12 +14,10 @@ import type { BaseViewer } from "../../core/viewers";
14
14
  * - 集成对象捕捉功能,提升标注精度
15
15
  *
16
16
  * 标注策略:
17
- * - 矩形类型图形将被忽略,不创建标注
18
- * - 其他多边形使用 FreeDrawDrawable(使用完整的闭合多边形点集)
17
+ * - 与 viewer 当前单击选择/高亮范围保持一致
18
+ * - 仅对可提取闭合轮廓的对象创建 FreeDrawDrawable
19
19
  */
20
20
  export declare class AutoDrawAnnotation extends BaseAnnotation {
21
- private debugEnabled;
22
- private shapeFinder;
23
21
  /**
24
22
  * 构造函数
25
23
  * @param viewer 基础查看器实例,用于图纸显示和交互
@@ -60,4 +58,5 @@ export declare class AutoDrawAnnotation extends BaseAnnotation {
60
58
  * @param e 鼠标事件信息,包含按钮类型、坐标等
61
59
  */
62
60
  protected onMouseClick(e: EventInfo): void;
61
+ private completeFromSelectionRings;
63
62
  }
@@ -3,7 +3,7 @@ import type { BaseAnnotationDrawable } from "./BaseAnnotationDrawable";
3
3
  import { AnnotationModeType } from "./BaseAnnotationDrawable";
4
4
  import { Tooltip } from "../../components/tool-tip";
5
5
  import { DrawableList } from "../../core/canvas/DrawableList";
6
- import type { MobileTouchHelperDrawable, OSnapHelper } from "../../core/helpers";
6
+ import { type MobileTouchHelperDrawable, type OSnapHelper } from "../../core/helpers";
7
7
  import { EventInfo, InputManager } from "../../core/input/InputManager";
8
8
  import { Event } from "../../core/utils";
9
9
  import type { BaseViewer } from "../../core/viewers";
@@ -12,7 +12,10 @@ import type { BaseViewer } from "../../core/viewers";
12
12
  */
13
13
  declare type AnnotationEvents = {
14
14
  /** 点击标注项时触发(选中标注结果) */
15
- ClickedOnAnnotation: BaseAnnotationDrawable;
15
+ ClickedOnAnnotation: {
16
+ drawable: BaseAnnotationDrawable;
17
+ evt: EventInfo;
18
+ };
16
19
  /** 绘制标注完成时触发 */
17
20
  Completed: BaseAnnotationDrawable;
18
21
  /** 停用标注工具时触发,参数为标注类型 */
@@ -56,6 +59,9 @@ export declare abstract class BaseAnnotation extends Event<AnnotationEvents> {
56
59
  protected exitButton?: HTMLButtonElement;
57
60
  protected firstPickedListener?: () => void;
58
61
  protected completedListener?: () => void;
62
+ protected subtractMode: boolean;
63
+ protected allDrawableList?: DrawableList;
64
+ protected additionMode: boolean;
59
65
  constructor(type: AnnotationModeType, viewer: BaseViewer, input: InputManager, drawList: DrawableList, osnapHelper: OSnapHelper);
60
66
  get canvas(): HTMLCanvasElement;
61
67
  get camera(): THREE.Camera;
@@ -70,6 +76,30 @@ export declare abstract class BaseAnnotation extends Event<AnnotationEvents> {
70
76
  */
71
77
  get isAnnotating(): boolean;
72
78
  setTouchHelper(mobileTouchHelper: MobileTouchHelperDrawable): void;
79
+ /**
80
+ * 设置挖空模式
81
+ * @param enabled 是否启用挖空模式
82
+ * @param drawableList 所有标注的列表,用于查找父标注
83
+ */
84
+ setSubtractMode(enabled: boolean, drawableList?: DrawableList): void;
85
+ /**
86
+ * 设置添加模式(合并图形模式)
87
+ * @param enabled 是否启用添加模式
88
+ * @param drawableList 所有标注的列表,用于查找相交的标注
89
+ */
90
+ setAdditionMode(enabled: boolean, drawableList?: DrawableList): void;
91
+ /**
92
+ * 查找包含指定点的父标注
93
+ * @param point 要检查的点
94
+ * @returns 包含该点的标注,如果没有则返回undefined
95
+ */
96
+ protected findParentAnnotationContainingPoint(point: THREE.Vector3): BaseAnnotationDrawable | undefined;
97
+ /**
98
+ * 计算多边形面积
99
+ * @param points 多边形顶点
100
+ * @returns 面积
101
+ */
102
+ protected calculatePolygonArea(points: THREE.Vector3[]): number;
73
103
  /**
74
104
  * 在移动端创建一个退出绘制的按钮(浮层按钮)。
75
105
  * 当用户触摸退出按钮时会结束当前绘制并隐藏按钮。
@@ -91,7 +121,7 @@ export declare abstract class BaseAnnotation extends Event<AnnotationEvents> {
91
121
  touchend: (e: EventInfo) => void;
92
122
  mousedown: (e: EventInfo) => void;
93
123
  mousemove: (e: EventInfo) => void;
94
- mouseup: (e: EventInfo) => void;
124
+ mouseup: () => void;
95
125
  dblclick: () => void;
96
126
  protected onMouseClick(e: EventInfo): void;
97
127
  protected selectAnnotationByEvent(e: EventInfo): void;
@@ -115,5 +145,8 @@ export declare abstract class BaseAnnotation extends Event<AnnotationEvents> {
115
145
  * @param e 事件信息(包含屏幕坐标)
116
146
  */
117
147
  getIntersections: (e: EventInfo) => THREE.Intersection[];
148
+ private getAnnotationSnapObjects;
149
+ protected getMouseWorldPosition(e: EventInfo): THREE.Vector3 | undefined;
150
+ protected getMouseScreenPosition(e: EventInfo): THREE.Vector2;
118
151
  }
119
152
  export {};
@@ -34,6 +34,8 @@ export interface ClosedShape {
34
34
  position: THREE.Vector3;
35
35
  }
36
36
  export declare type AnnotationData = DrawableData & {
37
+ /** 多环几何。rings[0] 是外环,后续 ring 是孔洞。 */
38
+ rings?: number[][][];
37
39
  /** 标注标题 */
38
40
  title?: string;
39
41
  /** 标注类型/属性等业务信息 */
@@ -55,13 +57,20 @@ export declare abstract class BaseAnnotationDrawable extends Drawable {
55
57
  protected selectedFillColor?: number[];
56
58
  protected dragVertexIndex: number | null;
57
59
  protected previewPoints: THREE.Vector3[] | null;
60
+ protected dragRingIndex: number | null;
61
+ protected previewRings: THREE.Vector3[][] | null;
58
62
  protected details: ClosedShape;
63
+ protected rings?: THREE.Vector3[][];
59
64
  protected ctx?: CanvasRenderingContext2D;
60
65
  parent?: BaseAnnotationDrawable;
61
66
  protected segmentLabelOffset: number;
62
67
  protected segmentLabelFontSize: number;
63
68
  protected segmentLabelPaddingX: number;
64
69
  protected segmentLabelPaddingY: number;
70
+ protected segmentLabelScaleWithZoom: boolean;
71
+ protected segmentLabelReferencePixelSizeInWorldCoord?: number;
72
+ protected segmentLabelAdaptiveBaseScale?: number;
73
+ protected segmentLabelAdaptiveBaseScaleSignature?: string;
65
74
  protected annotationType?: AnnotationType;
66
75
  protected titleText?: string;
67
76
  protected annotationProperty?: AnnotationProperty;
@@ -71,12 +80,30 @@ export declare abstract class BaseAnnotationDrawable extends Drawable {
71
80
  * 设置选中态填充颜色
72
81
  */
73
82
  setSelectedFillColor(color: number[]): this;
83
+ setViewer(viewer?: BaseViewer): this;
84
+ setSegmentLabelScaleWithZoom(enabled: boolean): this;
85
+ captureSegmentLabelScaleReference(force?: boolean): this;
86
+ protected getSegmentLabelScaleFactor(): number;
87
+ private getSegmentLabelReferencePixelSize;
88
+ private isSegmentLabelRectOverlap;
89
+ private getSortedSegmentLabelEntries;
90
+ private measureSegmentLabelRect;
91
+ private layoutSegmentLabelEntries;
92
+ private estimateSegmentLabelAdaptiveBaseScale;
93
+ private buildSegmentLabelAdaptiveBaseScaleSignature;
94
+ private resolveSegmentLabelAdaptiveBaseScale;
95
+ private collectSegmentLabelEntries;
96
+ private prepareSegmentLabelEntries;
74
97
  /**
75
- * 开始拖拽顶点
98
+ * 开始拖拽顶点(仅外环 points)
76
99
  */
77
100
  beginDragVertex(index: number): void;
78
101
  /**
79
- * 拖拽过程中更新预览点(不修改真实 points)
102
+ * 开始拖拽指定环上的顶点(0=外环,>=1=洞)
103
+ */
104
+ beginDragVertexAt(ringIndex: number, vertexIndex: number): void;
105
+ /**
106
+ * 拖拽过程中更新预览点(支持 points 与 rings)
80
107
  */
81
108
  updateDragPreview(position: THREE.Vector3, eventInfo?: EventInfo): void;
82
109
  /**
@@ -111,6 +138,12 @@ export declare abstract class BaseAnnotationDrawable extends Drawable {
111
138
  setData(data: AnnotationData): void;
112
139
  setParent(parent: BaseAnnotationDrawable): void;
113
140
  setParentId(parentId: string): void;
141
+ /**
142
+ * Update using multi-rings (outer + holes). Points will be set to the outer ring for compatibility.
143
+ */
144
+ updateRings(rings: THREE.Vector3[][]): this;
145
+ /** Get rings if present; fallback to single ring [points] */
146
+ getRings(): THREE.Vector3[][];
114
147
  update(points: THREE.Vector3[]): this;
115
148
  /**
116
149
  * 对封闭图形的点按从左上角顺时针方向排序
@@ -129,10 +162,13 @@ export declare abstract class BaseAnnotationDrawable extends Drawable {
129
162
  * 获取与场景的交点列表(用于吸附)
130
163
  */
131
164
  getIntersections(e: EventInfo): THREE.Intersection[];
165
+ private getAnnotationSnapObjects;
132
166
  /**
133
167
  * 处理鼠标移动时的吸附逻辑
134
168
  */
135
169
  handleSnapOnMove(e: EventInfo): THREE.Vector3 | undefined;
170
+ private getMouseWorldPosition;
171
+ private getMouseScreenPosition;
136
172
  /**
137
173
  * 激活射线检测器(用于吸附)
138
174
  */
@@ -141,6 +177,10 @@ export declare abstract class BaseAnnotationDrawable extends Drawable {
141
177
  * 停用射线检测器
142
178
  */
143
179
  deactivateRaycaster(): void;
180
+ private static readonly AREA_SCALE_RATIO;
181
+ private static readonly MIN_LABEL_SCALE;
182
+ private static readonly SCREEN_HIDE_THRESHOLD;
183
+ private static readonly MIN_SCREEN_SEGMENT;
144
184
  protected drawSegmentLengths(ctx: CanvasRenderingContext2D, camera: THREE.Camera): void;
145
185
  private drawSegmentLengthLabel;
146
186
  private drawRoundedRect;
@@ -2,66 +2,92 @@ import * as THREE from "three";
2
2
  import { BaseAnnotation } from "./BaseAnnotation";
3
3
  import { BaseAnnotationDrawable } from "./BaseAnnotationDrawable";
4
4
  import { DrawableList } from "../../core/canvas/DrawableList";
5
- import type { OSnapHelper } from "../../core/helpers";
5
+ import { type OSnapHelper } from "../../core/helpers";
6
6
  import { EventInfo, InputManager } from "../../core/input/InputManager";
7
7
  import type { BaseViewer } from "../../core/viewers";
8
8
  /**
9
- * 自由绘制标注类
10
- * 用于处理自由绘制的标注功能
9
+ * 自由绘制标注工具
10
+ * 支持用户通过连续点击创建自由形状的标注,可实现复杂多边形的绘制
11
+ * 具备点击闭合、双击结束、智能点距控制等功能
11
12
  */
12
13
  export declare class FreeDrawAnnotation extends BaseAnnotation {
14
+ /** 相邻点之间的最小距离阈值(像素单位),用于避免冗余点 */
13
15
  private minPointDistance;
14
16
  constructor(viewer: BaseViewer, input: InputManager, drawList: DrawableList, osnapHelper: OSnapHelper);
15
17
  /**
16
- * 退出绘制
18
+ * 退出自由绘制模式
19
+ * 根据当前绘制状态决定是完成绘制还是取消绘制
17
20
  */
18
21
  exitDrawing(): void;
19
22
  /**
20
- * 取消当前绘制
23
+ * 取消当前自由绘制操作
24
+ * 清理所有绘制相关的状态和对象
21
25
  */
22
26
  cancel(): void;
23
27
  /**
24
- * 完成当前绘制
28
+ * 完成当前自由绘制操作
29
+ * 处理挖空模式、添加模式或正常完成流程
25
30
  */
26
31
  protected complete(): void;
27
32
  /**
28
- * 设置提示内容
33
+ * 处理挖空模式操作
34
+ * 从已存在的标注中减去当前绘制的自由图形区域,实现复杂图形的挖空效果
35
+ */
36
+ private handleSubtractMode;
37
+ /**
38
+ * 处理添加模式操作
39
+ * 将当前绘制的自由图形与相交的标注合并,实现图形的扩展和洞的填充
40
+ */
41
+ private handleAdditionMode;
42
+ /**
43
+ * 设置工具提示内容
44
+ * 根据当前绘制状态显示相应的操作提示
29
45
  */
30
46
  protected setTooltipContent(): void;
31
47
  /**
32
- * 创建标注drawable
48
+ * 创建自由绘制标注的可绘制对象
49
+ * @returns 创建的自由绘制可绘制对象,如果创建失败则返回undefined
33
50
  */
34
51
  protected createAnnotationDrawable(): BaseAnnotationDrawable | undefined;
35
52
  /**
36
- * 重写鼠标点击处理,用于开始绘制
53
+ * 处理鼠标点击事件,实现自由绘制的交互式操作
54
+ * @param e 鼠标事件信息
37
55
  */
38
56
  protected onMouseClick(e: EventInfo): void;
39
57
  /**
40
- * 开始绘制
58
+ * 开始自由绘制流程
59
+ * 通过第一次点击确定绘制的起始点,并初始化绘制状态
60
+ * @param e 鼠标事件信息
41
61
  */
42
62
  private startDrawing;
43
63
  /**
44
- * 继续绘制(添加点)
64
+ * 继续自由绘制流程
65
+ * 通过后续点击向绘制路径中添加新的顶点,支持闭合检测和智能点距控制
66
+ * @param e 鼠标事件信息
45
67
  */
46
68
  private continueDrawing;
47
69
  /**
48
- * 重写鼠标移动处理,用于连续绘制
70
+ * 处理鼠标移动事件,实现自由绘制的实时预览效果
71
+ * @param position 鼠标当前位置的世界坐标
49
72
  */
50
73
  protected onMouseMove(position: THREE.Vector3): void;
51
74
  /**
52
- * 重写双击处理,用于快速结束绘制
75
+ * 双击事件处理器,提供快速完成绘制的便捷方式
53
76
  */
54
77
  dblclick: () => void;
55
78
  /**
56
- * 将世界坐标转换为屏幕坐标
79
+ * 世界坐标到屏幕坐标的转换工具方法
80
+ * 用于计算点间距离以实现智能点距控制
81
+ * @param worldPos 世界坐标系中的3D位置
82
+ * @returns 对应的屏幕坐标2D位置
57
83
  */
58
84
  private worldToScreen;
59
85
  /**
60
- * 从数据恢复标注
61
- * 专用于JSON数据恢复,支持保持原始ID不变
62
- * @param points 点集合
63
- * @param customId 自定义ID,用于保持JSON中的原始ID
64
- * @returns 创建的标注ID
86
+ * 从外部数据恢复自由绘制标注
87
+ * 专用于从JSON等持久化数据中恢复标注对象,支持保持原始标注ID不变
88
+ * @param points 标注的顶点集合
89
+ * @param customId 自定义标注ID,用于保持JSON中存储的原始ID
90
+ * @returns 成功创建的标注ID,失败时返回undefined
65
91
  */
66
92
  restoreFromData(points: THREE.Vector3[], customId?: string): string | undefined;
67
93
  }
@@ -2,7 +2,7 @@ import * as THREE from "three";
2
2
  import { BaseAnnotation } from "./BaseAnnotation";
3
3
  import { AnnotationModeType, BaseAnnotationDrawable } from "./BaseAnnotationDrawable";
4
4
  import type { DrawableList } from "../../core/canvas/DrawableList";
5
- import type { OSnapHelper } from "../../core/helpers";
5
+ import { type OSnapHelper } from "../../core/helpers";
6
6
  import type { EventInfo, InputManager } from "../../core/input/InputManager";
7
7
  import type { BaseViewer } from "../../core/viewers";
8
8
  /**
@@ -12,43 +12,69 @@ import type { BaseViewer } from "../../core/viewers";
12
12
  */
13
13
  export declare class RectAnnotation extends BaseAnnotation {
14
14
  type: AnnotationModeType;
15
+ /** 矩形绘制的起始点坐标 */
15
16
  private startPoint?;
16
17
  constructor(viewer: BaseViewer, inputManager: InputManager, drawList: DrawableList, osnapHelper: OSnapHelper);
17
18
  /**
18
- * 重写鼠标点击处理,用于矩形绘制
19
+ * 处理鼠标点击事件,实现矩形的交互式绘制
20
+ * @param e 鼠标事件信息
19
21
  */
20
22
  protected onMouseClick(e: EventInfo): void;
21
23
  /**
22
- * 开始绘制矩形
24
+ * 开始矩形绘制流程
25
+ * 通过第一次点击确定矩形的起始点,并初始化绘制状态
26
+ * @param e 鼠标事件信息
23
27
  */
24
28
  private startDrawing;
25
29
  /**
26
- * 完成绘制矩形
30
+ * 完成矩形绘制流程
31
+ * 通过第二次点击确定矩形的结束点,并完成绘制
32
+ * @param e 鼠标事件信息
27
33
  */
28
34
  private finishDrawing;
29
35
  /**
30
- * 退出绘制
36
+ * 退出矩形绘制模式
37
+ * 根据当前绘制状态决定是完成绘制还是取消绘制
31
38
  */
32
39
  exitDrawing(): void;
33
40
  /**
34
- * 取消当前绘制
41
+ * 取消当前矩形绘制操作
42
+ * 清理所有绘制相关的状态和对象
35
43
  */
36
44
  cancel(): void;
37
45
  /**
38
- * 完成当前绘制
46
+ * 完成当前矩形绘制操作
47
+ * 处理挖空模式、添加模式或正常完成流程
39
48
  */
40
49
  protected complete(): void;
41
50
  /**
42
- * 设置提示内容
51
+ * 处理挖空模式操作
52
+ * 从已存在的标注中减去当前绘制的矩形区域,实现图形挖空效果
53
+ */
54
+ private handleSubtractMode;
55
+ /**
56
+ * 处理添加模式操作
57
+ * 将当前绘制的矩形与相交的标注合并,实现图形的扩展和洞的填充
58
+ */
59
+ private handleAdditionMode;
60
+ /**
61
+ * 设置工具提示内容
62
+ * 根据当前绘制状态显示相应的操作提示
43
63
  */
44
64
  protected setTooltipContent(): void;
45
65
  /**
46
- * 创建标注drawable
66
+ * 创建矩形标注的可绘制对象
67
+ * @returns 创建的矩形可绘制对象,如果创建失败则返回undefined
47
68
  */
48
69
  protected createAnnotationDrawable(): BaseAnnotationDrawable | undefined;
49
70
  /**
50
- * 重写鼠标移动处理,用于实时预览
71
+ * 处理鼠标移动事件,实现矩形绘制的实时预览效果
72
+ * @param position 鼠标当前位置的世界坐标
51
73
  */
52
74
  protected onMouseMove(position: THREE.Vector3): void;
75
+ /**
76
+ * 根据起始点和对角点更新矩形的四个顶点坐标
77
+ * @param opposite 矩形的对角点坐标
78
+ */
53
79
  private updateRectanglePoints;
54
80
  }
@@ -18,7 +18,6 @@ export declare class RectDrawable extends BaseAnnotationDrawable {
18
18
  private getRectPoints;
19
19
  isPointInPath(p: THREE.Vector3): boolean;
20
20
  getVertexes(): THREE.Vector3[];
21
- protected getPointsForSegmentLength(): THREE.Vector3[];
22
21
  getClassType(): string;
23
22
  /**
24
23
  * 重写更新方法,绘制时保持2个对角点,完成时转换为4个顶点
@@ -28,6 +27,12 @@ export declare class RectDrawable extends BaseAnnotationDrawable {
28
27
  * 完成绘制时,确保使用完整的4个顶点
29
28
  */
30
29
  finalizePoints(): void;
30
+ /**
31
+ * 支持环顶点拖拽:
32
+ * - 若已有 rings(包含洞),则按多环顶点拖拽处理
33
+ * - 若无 rings(经典矩形),则走矩形四角拖拽逻辑
34
+ */
35
+ beginDragVertexAt(ringIndex: number, vertexIndex: number): void;
31
36
  /**
32
37
  * 重写拖拽开始方法,处理4个顶点的拖拽
33
38
  */
@@ -178,7 +178,7 @@ export declare class DividePlugin extends Plugin {
178
178
  * 取消图框创建
179
179
  * @param drawable 要取消的绘制数据
180
180
  */
181
- cancelFrameCreation(drawable: FrameDrawable): void;
181
+ cancelFrameCreation(drawable?: FrameDrawable): void;
182
182
  /**
183
183
  * 从JSON数据恢复图框
184
184
  * 根据保存的角点坐标重新创建图框
@@ -138,5 +138,6 @@ export declare class FrameAnnotation extends Event<FrameAnnotationEvents> {
138
138
  * 完全按照 BaseAnnotation.ts 的实现
139
139
  */
140
140
  getIntersections: (e: EventInfo) => THREE.Intersection[];
141
+ private getMouseWorldPosition;
141
142
  }
142
143
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dxfview",
3
- "version": "0.0.4-beta.9",
3
+ "version": "0.0.5-beta",
4
4
  "homepage": "",
5
5
  "module": "dist/dxfview.esm.min.js",
6
6
  "main": "dist/dxfview.esm.min.js",
@@ -56,7 +56,6 @@
56
56
  "regenerator-runtime": "^0.13.11",
57
57
  "screenfull": "^6.0.0",
58
58
  "stream": "^0.0.2",
59
- "three": "^0.155.0",
60
59
  "three-mesh-bvh": "^0.5.21"
61
60
  },
62
61
  "devDependencies": {
@@ -86,5 +85,8 @@
86
85
  "tsc-alias": "^1.8.2",
87
86
  "typedoc": "^0.22.12",
88
87
  "typescript": "^4.5.2"
88
+ },
89
+ "peerDependencies": {
90
+ "three": ">=0.155.0 <0.170.0"
89
91
  }
90
92
  }