@maqiuyao/dxf-viewer 0.2.32 → 0.2.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/dist/dxf-viewer.cjs +65 -47
- package/dist/dxf-viewer.js +4239 -3620
- package/dist/src/dxfViewer/core/dxf-splitter/DxfSplitter.d.ts +151 -0
- package/dist/src/dxfViewer/core/dxf-splitter/index.d.ts +1 -0
- package/dist/src/dxfViewer/core/index.d.ts +1 -0
- package/package.json +5 -2
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DXF 大图拆分引擎。
|
|
3
|
+
*
|
|
4
|
+
* 基于原始 DXF 文本做「组码级」切割,不依赖解析后的场景结构:
|
|
5
|
+
* 1. 扫描 ENTITIES 段,把每个实体切成「组码块」(POLYLINE..SEQEND 视为一个块);
|
|
6
|
+
* 2. 识别图框候选(INSERT 图框块 / LINE 四边矩形 / 闭合 LWPOLYLINE);
|
|
7
|
+
* 3. 按实体包围盒把实体归属到图框;
|
|
8
|
+
* 4. 按图框重建 ENTITIES 段,其余段(HEADER/TABLES/BLOCKS/OBJECTS 等)整段原文保留,
|
|
9
|
+
* 组装出若干张独立 DXF 文本。
|
|
10
|
+
*/
|
|
11
|
+
/** 二维包围盒 */
|
|
12
|
+
export interface DxfBBox {
|
|
13
|
+
minX: number;
|
|
14
|
+
minY: number;
|
|
15
|
+
maxX: number;
|
|
16
|
+
maxY: number;
|
|
17
|
+
}
|
|
18
|
+
/** 图框识别来源 */
|
|
19
|
+
export type DxfFrameSource = "insert" | "line-rect" | "closed-polyline";
|
|
20
|
+
/** 识别出的图框信息 */
|
|
21
|
+
export interface DxfFrameInfo {
|
|
22
|
+
/** 图框序号(0 起,按阅读顺序排列) */
|
|
23
|
+
index: number;
|
|
24
|
+
/** 图框名:INSERT 块名或自动命名(图框1、图框2…) */
|
|
25
|
+
name: string;
|
|
26
|
+
/** 识别来源 */
|
|
27
|
+
source: DxfFrameSource;
|
|
28
|
+
/** 图框包围盒(图纸坐标) */
|
|
29
|
+
bbox: DxfBBox;
|
|
30
|
+
/** 归属到该图框的实体数 */
|
|
31
|
+
entityCount: number;
|
|
32
|
+
}
|
|
33
|
+
/** 拆分结果:一张子 DXF */
|
|
34
|
+
export interface DxfSplitPiece {
|
|
35
|
+
frame: DxfFrameInfo;
|
|
36
|
+
/** 子 DXF 文本(可直接保存为 .dxf 文件) */
|
|
37
|
+
text: string;
|
|
38
|
+
}
|
|
39
|
+
/** 拆分选项 */
|
|
40
|
+
export interface DxfSplitterOptions {
|
|
41
|
+
/**
|
|
42
|
+
* 图框最小边长(图纸单位)。小于该边长的候选会被忽略。
|
|
43
|
+
* 默认自动估计:max(50, 整图短边的 4%)。
|
|
44
|
+
*/
|
|
45
|
+
minEdge?: number;
|
|
46
|
+
/**
|
|
47
|
+
* 候选图框面积占最大候选面积的最小比例(0-1),用于过滤零碎小框。
|
|
48
|
+
* @default 0.02
|
|
49
|
+
*/
|
|
50
|
+
minAreaRatio?: number;
|
|
51
|
+
/**
|
|
52
|
+
* 模板单元格过滤阈值:同一水平带内「内联绘制」(非块引用)的同高候选
|
|
53
|
+
* 数量达到该值时,整带视为重复模板(如配线表格单元格)而丢弃。
|
|
54
|
+
* 块引用(INSERT)候选不受此规则限制。设为 0 关闭该过滤。
|
|
55
|
+
* @default 10
|
|
56
|
+
*/
|
|
57
|
+
templateGroupThreshold?: number;
|
|
58
|
+
/** INSERT 图框名关键词(不区分大小写),命中关键词的块优先视为图框 */
|
|
59
|
+
frameKeywords?: string[];
|
|
60
|
+
/** 进度回调(pct: 0-100) */
|
|
61
|
+
onProgress?: (pct: number, message: string) => void;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* DXF 大图拆分器。
|
|
65
|
+
*
|
|
66
|
+
* 用法:
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const splitter = new DxfSplitter(dxfText);
|
|
69
|
+
* const frames = splitter.detectFrames(); // 识别图框
|
|
70
|
+
* const pieces = splitter.split([0, 1, 2]); // 按图框切出子 DXF(不传则全部)
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare class DxfSplitter {
|
|
74
|
+
private readonly lines;
|
|
75
|
+
private readonly options;
|
|
76
|
+
private sections;
|
|
77
|
+
private entityBlocks;
|
|
78
|
+
private blockDefs;
|
|
79
|
+
private drawingBBox;
|
|
80
|
+
private frames;
|
|
81
|
+
/** 实体块索引 -> 图框索引(-1 表示未归属) */
|
|
82
|
+
private assignments;
|
|
83
|
+
private detected;
|
|
84
|
+
constructor(text: string, options?: DxfSplitterOptions);
|
|
85
|
+
/** 从 URL 加载并创建拆分器 */
|
|
86
|
+
static fromUrl(url: string, options?: DxfSplitterOptions): Promise<DxfSplitter>;
|
|
87
|
+
/** 从 File 对象创建拆分器 */
|
|
88
|
+
static fromFile(file: File, options?: DxfSplitterOptions): Promise<DxfSplitter>;
|
|
89
|
+
/** 识别到的图框(需先调用 detectFrames) */
|
|
90
|
+
getFrames(): DxfFrameInfo[];
|
|
91
|
+
/** 未归属到任何图框的实体数(需先调用 detectFrames) */
|
|
92
|
+
getUnassignedCount(): number;
|
|
93
|
+
/**
|
|
94
|
+
* 识别图框并完成实体归属。重复调用安全(内部有缓存)。
|
|
95
|
+
*/
|
|
96
|
+
detectFrames(): DxfFrameInfo[];
|
|
97
|
+
/**
|
|
98
|
+
* 按图框拆分为多张子 DXF。
|
|
99
|
+
* @param frameIndices 要导出的图框序号数组;不传则导出全部图框。
|
|
100
|
+
*/
|
|
101
|
+
split(frameIndices?: number[]): DxfSplitPiece[];
|
|
102
|
+
/**
|
|
103
|
+
* 按图框范围重写 HEADER 的视图变量($EXTMIN/$EXTMAX/$VIEWCTR/$VIEWSIZE,外扩 2%)。
|
|
104
|
+
* 否则所有子图沿用整图范围(可达数千单位),AutoCAD 打开子图时初始取景基于整图、
|
|
105
|
+
* 内容缩成一小块;重写后打开即取景到本图框。
|
|
106
|
+
*/
|
|
107
|
+
private rewriteHeaderExtent;
|
|
108
|
+
/**
|
|
109
|
+
* 删除所有 {ACAD_REACTORS ...} 与 {BLKREFS ...} 扩展块。
|
|
110
|
+
* 二者都指向可能已被分到其他子图的实体(331 反应器/块引用列表),
|
|
111
|
+
* 拆分后必然悬空;这些块对 AutoCAD 是可选的(打开/审计时会自行重建),
|
|
112
|
+
* 删除使子图自包含,避免严格模式下拒绝打开。
|
|
113
|
+
*/
|
|
114
|
+
private stripReactors;
|
|
115
|
+
/** 扫描各 SECTION 的行号范围(组码行位于偶数行,与官方解析器假设一致) */
|
|
116
|
+
private scanSections;
|
|
117
|
+
private findSection;
|
|
118
|
+
/** 扫描 BLOCKS 段,记录每个块定义相对基点的包围盒 */
|
|
119
|
+
private scanBlockDefs;
|
|
120
|
+
/** 扫描 ENTITIES 段,把实体切为组码块(POLYLINE..SEQEND 合并) */
|
|
121
|
+
private scanEntityBlocks;
|
|
122
|
+
/** 计算实体块的世界坐标包围盒(INSERT 按块定义换算) */
|
|
123
|
+
private computeEntityBBox;
|
|
124
|
+
/**
|
|
125
|
+
* 解析 POLYLINE 的顶点序列:只收集 "0 VERTEX" 子实体内的 10/20,
|
|
126
|
+
* 跳过头部标高与 SEQEND。返回空数组表示无有效顶点。
|
|
127
|
+
*/
|
|
128
|
+
private parsePolylineVertices;
|
|
129
|
+
/**
|
|
130
|
+
* 从行范围 [start, end) 提取几何信息。
|
|
131
|
+
* 返回 points = [xs[], ys[]],包括主点(10/20)、副点(11/21)、尺寸标注点(13/23、14/24)。
|
|
132
|
+
*/
|
|
133
|
+
private extractGeometry;
|
|
134
|
+
/** 由点集和半径计算包围盒(半径用于圆/弧的外接) */
|
|
135
|
+
private bboxFromPoints;
|
|
136
|
+
/** 对原始行范围(BLOCKS 段内部实体)计算包围盒 */
|
|
137
|
+
private bboxOfRawRange;
|
|
138
|
+
private collectCandidates;
|
|
139
|
+
/** 自动估计最小边长 */
|
|
140
|
+
private resolveMinEdge;
|
|
141
|
+
/**
|
|
142
|
+
* LINE 四边矩形检测:
|
|
143
|
+
* 过滤出长度足够的长横线/竖线,两横两纵端点对齐即构成矩形候选。
|
|
144
|
+
*/
|
|
145
|
+
private detectLineRects;
|
|
146
|
+
/** 候选去重、过滤、排序并命名 */
|
|
147
|
+
private filterAndSortCandidates;
|
|
148
|
+
/** 把每个实体块归属到重叠率最大的图框 */
|
|
149
|
+
private assignEntities;
|
|
150
|
+
private report;
|
|
151
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './DxfSplitter';
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
{
|
|
2
2
|
"name": "@maqiuyao/dxf-viewer",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.34",
|
|
4
4
|
"description": "基于 three.js 的 DXF 图纸 2D/3D 查看与对比库(Viewer2d / DxfCompareHelper)",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"prepublishOnly": "node ../scripts/check-bom.mjs"
|
|
8
|
+
},
|
|
6
9
|
"main": "./dist/dxf-viewer.cjs",
|
|
7
10
|
"module": "./dist/dxf-viewer.js",
|
|
8
11
|
"types": "./dist/src/dxfViewer/lib.d.ts",
|