@maqiuyao/dxf-viewer 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Viewer2d } from '../viewers/Viewer2d';
|
|
2
|
+
import * as THREE from "three";
|
|
3
|
+
/**
|
|
4
|
+
* 一条文本搜索结果。
|
|
5
|
+
*/
|
|
6
|
+
export interface TextSearchResult {
|
|
7
|
+
/** 实体句柄 */
|
|
8
|
+
handle: string;
|
|
9
|
+
/** 图层名 */
|
|
10
|
+
layer: string;
|
|
11
|
+
/** 所属布局名(Model / Layout1 ...) */
|
|
12
|
+
layoutName: string;
|
|
13
|
+
/** 文本内容(已去除 MTEXT 格式码) */
|
|
14
|
+
text: string;
|
|
15
|
+
/** 世界坐标包围盒 */
|
|
16
|
+
box: THREE.Box3;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 搜索模式:
|
|
20
|
+
* - exact:精准匹配,文本内容(去首尾空格后)与关键字完全相等才算命中(不区分大小写);
|
|
21
|
+
* - fuzzy:模糊匹配,关键字作为连续子串出现即命中,还支持跳字子序列(如"铁院"命中"铁一院")。
|
|
22
|
+
*/
|
|
23
|
+
export type TextSearchMode = "exact" | "fuzzy";
|
|
24
|
+
/**
|
|
25
|
+
* 图纸文本搜索辅助类:在已加载的模型中检索文本实体(TEXT/MTEXT/ATTRIB),
|
|
26
|
+
* 支持定位(切换布局 + 缩放)与高亮(叠加层云线框)。
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const helper = new TextSearchHelper(viewer);
|
|
31
|
+
* const results = helper.search("道岔");
|
|
32
|
+
* helper.focus(results[0]);
|
|
33
|
+
* helper.clearHighlight();
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare class TextSearchHelper {
|
|
37
|
+
private viewer;
|
|
38
|
+
private overlayRender?;
|
|
39
|
+
private drawableList?;
|
|
40
|
+
private indexedModelObject?;
|
|
41
|
+
private index;
|
|
42
|
+
constructor(viewer: Viewer2d);
|
|
43
|
+
private getMasterModel;
|
|
44
|
+
/**
|
|
45
|
+
* 遍历主模型场景图,收集所有带 userData.textContent 的文本对象。
|
|
46
|
+
*/
|
|
47
|
+
private buildIndex;
|
|
48
|
+
/** 向上查找布局层对象名 */
|
|
49
|
+
private findLayoutName;
|
|
50
|
+
/**
|
|
51
|
+
* 按关键字搜索文本(不区分大小写)。
|
|
52
|
+
* - mode = "exact"(精准):关键字作为连续子串出现即命中;
|
|
53
|
+
* - mode = "fuzzy"(模糊,默认):在精准基础上还支持跳字子序列,例如"铁院"匹配"铁一院"。
|
|
54
|
+
* 结果按匹配度从高到低排序(完全相等 > 靠前子串 > 短跳字 > 长跳字)。
|
|
55
|
+
* @param keyword 搜索关键字
|
|
56
|
+
* @param options.mode 匹配模式,默认 "fuzzy"
|
|
57
|
+
* @param options.layer 限定图层名(不区分大小写,可选)
|
|
58
|
+
* @param options.maxResults 最大返回条数,默认 200
|
|
59
|
+
*/
|
|
60
|
+
search(keyword: string, options?: {
|
|
61
|
+
mode?: TextSearchMode;
|
|
62
|
+
layer?: string;
|
|
63
|
+
maxResults?: number;
|
|
64
|
+
}): TextSearchResult[];
|
|
65
|
+
/**
|
|
66
|
+
* 定位到一条搜索结果:切换到其所在布局、缩放至包围盒,并在叠加层高亮。
|
|
67
|
+
*/
|
|
68
|
+
focus(result: TextSearchResult): void;
|
|
69
|
+
/**
|
|
70
|
+
* 在叠加层用云线框高亮指定结果(替换上一个高亮)。
|
|
71
|
+
*/
|
|
72
|
+
highlight(result: TextSearchResult): void;
|
|
73
|
+
/**
|
|
74
|
+
* 清除当前高亮。
|
|
75
|
+
*/
|
|
76
|
+
clearHighlight(): void;
|
|
77
|
+
/**
|
|
78
|
+
* 模型重新加载后调用,强制重建索引。
|
|
79
|
+
*/
|
|
80
|
+
invalidate(): void;
|
|
81
|
+
destroy(): void;
|
|
82
|
+
}
|
|
@@ -5,6 +5,7 @@ import { Drawable } from '../../core/canvas';
|
|
|
5
5
|
import { DxfLayer } from '../../core/dxf';
|
|
6
6
|
import { EventInfo } from '../../core/input-manager/InputManager';
|
|
7
7
|
import { Model2d } from '../../core/model';
|
|
8
|
+
import { TextSearchMode, TextSearchResult } from '../../core/helpers/TextSearchHelper';
|
|
8
9
|
import * as THREE from "three";
|
|
9
10
|
export interface EntityData {
|
|
10
11
|
modelId: string;
|
|
@@ -169,6 +170,7 @@ export declare class Viewer2d extends BaseViewer {
|
|
|
169
170
|
* Used to indicate how many dxf is loading
|
|
170
171
|
*/
|
|
171
172
|
private loadingDxfCount;
|
|
173
|
+
private textSearchHelper?;
|
|
172
174
|
constructor(viewerCfg: Viewer2dConfig);
|
|
173
175
|
get camera(): THREE.OrthographicCamera;
|
|
174
176
|
private setupDefaultEvents;
|
|
@@ -325,6 +327,34 @@ export declare class Viewer2d extends BaseViewer {
|
|
|
325
327
|
* ```
|
|
326
328
|
*/
|
|
327
329
|
getActiveLayoutName(): string | undefined;
|
|
330
|
+
/**
|
|
331
|
+
* @description {en} Searches text entities (TEXT/MTEXT/ATTRIB) in the loaded drawing.
|
|
332
|
+
* @description {zh} 在已加载的图纸中搜索文本实体(TEXT/MTEXT/ATTRIB)。
|
|
333
|
+
* @param keyword 搜索关键字(不区分大小写、子串匹配)
|
|
334
|
+
* @param options.layer 限定图层名(可选)
|
|
335
|
+
* @param options.maxResults 最大返回条数,默认 200
|
|
336
|
+
* @returns 匹配的文本结果列表
|
|
337
|
+
* @example
|
|
338
|
+
* ```typescript
|
|
339
|
+
* const results = viewer.searchText("道岔");
|
|
340
|
+
* results.length > 0 && viewer.focusText(results[0]);
|
|
341
|
+
* ```
|
|
342
|
+
*/
|
|
343
|
+
searchText(keyword: string, options?: {
|
|
344
|
+
mode?: TextSearchMode;
|
|
345
|
+
layer?: string;
|
|
346
|
+
maxResults?: number;
|
|
347
|
+
}): TextSearchResult[];
|
|
348
|
+
/**
|
|
349
|
+
* @description {en} Zooms to a text search result and highlights it with a cloud border.
|
|
350
|
+
* @description {zh} 定位到一条文本搜索结果并高亮(云线框)。
|
|
351
|
+
*/
|
|
352
|
+
focusText(result: TextSearchResult): void;
|
|
353
|
+
/**
|
|
354
|
+
* @description {en} Clears the highlight of text search results.
|
|
355
|
+
* @description {zh} 清除文本搜索结果的高亮。
|
|
356
|
+
*/
|
|
357
|
+
clearTextHighlight(): void;
|
|
328
358
|
zoomIn(step?: number): void;
|
|
329
359
|
zoomOut(step?: number): void;
|
|
330
360
|
/**
|