dxfview 0.0.4-beta.10 → 0.0.4-beta.11

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.
@@ -32,11 +32,11 @@ export declare class Offset {
32
32
  /**
33
33
  * Decides by the sign if it's a padding or a margin
34
34
  */
35
- offset(dist: number): Pair | Ring | Polygon | MultiPolygon;
35
+ offset(dist: number): MultiPolygon | Polygon | Ring | Pair;
36
36
  private offsetSegment;
37
37
  private margin;
38
38
  private padding;
39
- offsetLine(dist: number): Pair | Ring | Polygon | MultiPolygon;
39
+ offsetLine(dist: number): MultiPolygon | Polygon | Ring | Pair;
40
40
  /**
41
41
  * Just offsets lines, no fill
42
42
  */
@@ -13,6 +13,8 @@ export declare class AnnotationPlugin extends Plugin {
13
13
  private snapToleranceInPixel;
14
14
  private annotations;
15
15
  private activeAnnotationType;
16
+ private subtractMode;
17
+ private additionMode;
16
18
  private mobileTouchHelper?;
17
19
  private selectedMaskColor?;
18
20
  private readonly partitionLabels;
@@ -108,6 +110,30 @@ export declare class AnnotationPlugin extends Plugin {
108
110
  * @returns {boolean} Is annotating now
109
111
  */
110
112
  isAnnotating(): boolean;
113
+ /**
114
+ * 设置挖空模式(减去图形模式)
115
+ * @param enabled 是否启用挖空模式
116
+ * @description {en} Sets subtract mode. When enabled, drawing a new shape inside an existing annotation will subtract/cut out that area.
117
+ * @description {zh} 设置挖空模式。启用后,在现有标注内绘制新图形将从原标注中减去该区域。
118
+ */
119
+ setSubtractMode(enabled: boolean): void;
120
+ /**
121
+ * 获取当前挖空模式状态
122
+ * @returns {boolean} 是否启用挖空模式
123
+ */
124
+ getSubtractMode(): boolean;
125
+ /**
126
+ * 设置添加模式(合并图形模式)
127
+ * @param enabled 是否启用添加模式
128
+ * @description {en} Sets addition mode. When enabled, drawing a new shape that intersects existing annotations will merge/union them together.
129
+ * @description {zh} 设置添加模式。启用后,绘制与现有标注相交的新图形将合并它们。
130
+ */
131
+ setAdditionMode(enabled: boolean): void;
132
+ /**
133
+ * 获取当前添加模式状态
134
+ * @returns {boolean} 是否启用添加模式
135
+ */
136
+ getAdditionMode(): boolean;
111
137
  /**
112
138
  *
113
139
  * @returns {AnnotationData[]}
@@ -121,6 +147,11 @@ export declare class AnnotationPlugin extends Plugin {
121
147
  */
122
148
  cancel(): void;
123
149
  private getLastDrawable;
150
+ /**
151
+ * 公开的撤回方法,和 Ctrl+Z 的逻辑一致
152
+ * 用于工具栏撤回按钮调用
153
+ */
154
+ undo(): void;
124
155
  /**
125
156
  *
126
157
  * @param {AnnotationData[]} dataArray
@@ -150,6 +181,10 @@ export declare class AnnotationPlugin extends Plugin {
150
181
  */
151
182
  getById(id: string): BaseAnnotationDrawable;
152
183
  removeById(id: string): void;
184
+ /**
185
+ * 删除当前所选的标注,使用与按下 Delete 键相同的逻辑。如果删除了标注,则返回 true。
186
+ */
187
+ deleteSelectedAnnotation(): boolean;
153
188
  /**
154
189
  * Selects an annotation drawable by id.
155
190
  * @param {string} id
@@ -56,6 +56,9 @@ export declare abstract class BaseAnnotation extends Event<AnnotationEvents> {
56
56
  protected exitButton?: HTMLButtonElement;
57
57
  protected firstPickedListener?: () => void;
58
58
  protected completedListener?: () => void;
59
+ protected subtractMode: boolean;
60
+ protected allDrawableList?: DrawableList;
61
+ protected additionMode: boolean;
59
62
  constructor(type: AnnotationModeType, viewer: BaseViewer, input: InputManager, drawList: DrawableList, osnapHelper: OSnapHelper);
60
63
  get canvas(): HTMLCanvasElement;
61
64
  get camera(): THREE.Camera;
@@ -70,6 +73,30 @@ export declare abstract class BaseAnnotation extends Event<AnnotationEvents> {
70
73
  */
71
74
  get isAnnotating(): boolean;
72
75
  setTouchHelper(mobileTouchHelper: MobileTouchHelperDrawable): void;
76
+ /**
77
+ * 设置挖空模式
78
+ * @param enabled 是否启用挖空模式
79
+ * @param drawableList 所有标注的列表,用于查找父标注
80
+ */
81
+ setSubtractMode(enabled: boolean, drawableList?: DrawableList): void;
82
+ /**
83
+ * 设置添加模式(合并图形模式)
84
+ * @param enabled 是否启用添加模式
85
+ * @param drawableList 所有标注的列表,用于查找相交的标注
86
+ */
87
+ setAdditionMode(enabled: boolean, drawableList?: DrawableList): void;
88
+ /**
89
+ * 查找包含指定点的父标注
90
+ * @param point 要检查的点
91
+ * @returns 包含该点的标注,如果没有则返回undefined
92
+ */
93
+ protected findParentAnnotationContainingPoint(point: THREE.Vector3): BaseAnnotationDrawable | undefined;
94
+ /**
95
+ * 计算多边形面积
96
+ * @param points 多边形顶点
97
+ * @returns 面积
98
+ */
99
+ protected calculatePolygonArea(points: THREE.Vector3[]): number;
73
100
  /**
74
101
  * 在移动端创建一个退出绘制的按钮(浮层按钮)。
75
102
  * 当用户触摸退出按钮时会结束当前绘制并隐藏按钮。
@@ -91,7 +118,7 @@ export declare abstract class BaseAnnotation extends Event<AnnotationEvents> {
91
118
  touchend: (e: EventInfo) => void;
92
119
  mousedown: (e: EventInfo) => void;
93
120
  mousemove: (e: EventInfo) => void;
94
- mouseup: (e: EventInfo) => void;
121
+ mouseup: (_e: EventInfo) => void;
95
122
  dblclick: () => void;
96
123
  protected onMouseClick(e: EventInfo): void;
97
124
  protected selectAnnotationByEvent(e: EventInfo): void;
@@ -55,7 +55,10 @@ export declare abstract class BaseAnnotationDrawable extends Drawable {
55
55
  protected selectedFillColor?: number[];
56
56
  protected dragVertexIndex: number | null;
57
57
  protected previewPoints: THREE.Vector3[] | null;
58
+ protected dragRingIndex: number | null;
59
+ protected previewRings: THREE.Vector3[][] | null;
58
60
  protected details: ClosedShape;
61
+ protected rings?: THREE.Vector3[][];
59
62
  protected ctx?: CanvasRenderingContext2D;
60
63
  parent?: BaseAnnotationDrawable;
61
64
  protected segmentLabelOffset: number;
@@ -72,11 +75,15 @@ export declare abstract class BaseAnnotationDrawable extends Drawable {
72
75
  */
73
76
  setSelectedFillColor(color: number[]): this;
74
77
  /**
75
- * 开始拖拽顶点
78
+ * 开始拖拽顶点(仅外环 points)
76
79
  */
77
80
  beginDragVertex(index: number): void;
78
81
  /**
79
- * 拖拽过程中更新预览点(不修改真实 points)
82
+ * 开始拖拽指定环上的顶点(0=外环,>=1=洞)
83
+ */
84
+ beginDragVertexAt(ringIndex: number, vertexIndex: number): void;
85
+ /**
86
+ * 拖拽过程中更新预览点(支持 points 与 rings)
80
87
  */
81
88
  updateDragPreview(position: THREE.Vector3, eventInfo?: EventInfo): void;
82
89
  /**
@@ -111,6 +118,12 @@ export declare abstract class BaseAnnotationDrawable extends Drawable {
111
118
  setData(data: AnnotationData): void;
112
119
  setParent(parent: BaseAnnotationDrawable): void;
113
120
  setParentId(parentId: string): void;
121
+ /**
122
+ * Update using multi-rings (outer + holes). Points will be set to the outer ring for compatibility.
123
+ */
124
+ updateRings(rings: THREE.Vector3[][]): this;
125
+ /** Get rings if present; fallback to single ring [points] */
126
+ getRings(): THREE.Vector3[][];
114
127
  update(points: THREE.Vector3[]): this;
115
128
  /**
116
129
  * 对封闭图形的点按从左上角顺时针方向排序
@@ -6,62 +6,88 @@ 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
  }
@@ -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
  * 根据保存的角点坐标重新创建图框
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dxfview",
3
- "version": "0.0.4-beta.10",
3
+ "version": "0.0.4-beta.11",
4
4
  "homepage": "",
5
5
  "module": "dist/dxfview.esm.min.js",
6
6
  "main": "dist/dxfview.esm.min.js",