build-dxf 0.0.2 → 0.0.4
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 +15 -0
- package/package.json +1 -1
- package/src/index.d.ts +10 -4
- package/src/index.js +71 -8
package/README.md
CHANGED
|
@@ -1 +1,16 @@
|
|
|
1
1
|
# build-dxf
|
|
2
|
+
|
|
3
|
+
# 安装
|
|
4
|
+
```
|
|
5
|
+
npm i build-dxf
|
|
6
|
+
```
|
|
7
|
+
|
|
8
|
+
# 使用
|
|
9
|
+
```typescript
|
|
10
|
+
import { DxfSystem } from "build-dxf"
|
|
11
|
+
|
|
12
|
+
const dxfSystem = new DxfSystem()
|
|
13
|
+
dxfSystem.Dxf.set(data)
|
|
14
|
+
dxfSystem.Dxf.lineOffset()
|
|
15
|
+
dxfSystem.Dxf.download("01.dxf")
|
|
16
|
+
```
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -180,7 +180,7 @@ declare class Dxf extends Component<{
|
|
|
180
180
|
* @param width
|
|
181
181
|
* @param scale
|
|
182
182
|
*/
|
|
183
|
-
set(data: OriginalDataItem[], width?: number, scale?: number):
|
|
183
|
+
set(data: OriginalDataItem[] | string, width?: number, scale?: number): Promise<any>;
|
|
184
184
|
/** 创建分组
|
|
185
185
|
* @description 根据相交数组insetionArr, 把相交的线段,划分到一组内,方便后续路径查找合并使用
|
|
186
186
|
* @returns
|
|
@@ -212,17 +212,17 @@ declare class Dxf extends Component<{
|
|
|
212
212
|
/**
|
|
213
213
|
* 将点云结构转换为string
|
|
214
214
|
*/
|
|
215
|
-
toDxfString(): string;
|
|
215
|
+
toDxfString(unit?: Unit): string;
|
|
216
216
|
/**
|
|
217
217
|
* 将点云结构转换为DXF格式
|
|
218
218
|
* @returns
|
|
219
219
|
*/
|
|
220
|
-
toDxfBlob(): Blob;
|
|
220
|
+
toDxfBlob(unit?: Unit): Blob;
|
|
221
221
|
/**
|
|
222
222
|
* 下载
|
|
223
223
|
* @param filename
|
|
224
224
|
*/
|
|
225
|
-
download(filename: string,
|
|
225
|
+
download(filename: string, unit?: Unit): Promise<void>;
|
|
226
226
|
/**
|
|
227
227
|
* 计算原始数据的边界框
|
|
228
228
|
* @description 计算所有线段的起点和终点的最小最大值,形成一个边界框
|
|
@@ -241,6 +241,10 @@ export declare class DxfSystem extends ComponentManager {
|
|
|
241
241
|
Dxf: Dxf;
|
|
242
242
|
Variable: Variable;
|
|
243
243
|
wallWidth: number;
|
|
244
|
+
/** 构造函数
|
|
245
|
+
* @param wallWidth 输出墙壁厚度,该墙壁厚度不受缩放影响
|
|
246
|
+
* @param scale 原始数据缩放比例
|
|
247
|
+
*/
|
|
244
248
|
constructor(wallWidth?: number, scale?: number);
|
|
245
249
|
usePlugin(plugin: (this: DxfSystem, dxfSystem: DxfSystem) => void): this;
|
|
246
250
|
destroy(): void;
|
|
@@ -465,6 +469,8 @@ declare class Rectangle {
|
|
|
465
469
|
static fromByLineSegment(line: LineSegment, width?: number, horizontal?: boolean, hScale?: number): Rectangle;
|
|
466
470
|
}
|
|
467
471
|
|
|
472
|
+
declare type Unit = "Unitless" | "Inches" | "Feet" | "Miles" | "Millimeters" | "Centimeters" | "Meters" | "Kilometers" | "Microinches" | "Mils" | "Yards" | "Angstroms" | "Nanometers" | "Microns" | "Decimeters" | "Decameters" | "Hectometers" | "Gigameters" | "Astronomical units" | "Light years" | "Parsecs";
|
|
473
|
+
|
|
468
474
|
declare class Variable extends Component<EventType> {
|
|
469
475
|
originalLineVisible: boolean;
|
|
470
476
|
dxfVisible: boolean;
|
package/src/index.js
CHANGED
|
@@ -12956,6 +12956,50 @@ class Box2 {
|
|
|
12956
12956
|
);
|
|
12957
12957
|
}
|
|
12958
12958
|
}
|
|
12959
|
+
const units = {
|
|
12960
|
+
Unitless: 1,
|
|
12961
|
+
// 无单位,1米 = 1(无单位)
|
|
12962
|
+
Inches: 39.37007874015748,
|
|
12963
|
+
// 英寸,1米 = 39.37007874015748英寸
|
|
12964
|
+
Feet: 3.280839895013123,
|
|
12965
|
+
// 英尺,1米 = 3.280839895013123英尺
|
|
12966
|
+
Miles: 6213711922373339e-19,
|
|
12967
|
+
// 英里,1米 = 0.0006213711922373339英里
|
|
12968
|
+
Millimeters: 1e3,
|
|
12969
|
+
// 毫米,1米 = 1000毫米
|
|
12970
|
+
Centimeters: 100,
|
|
12971
|
+
// 厘米,1米 = 100厘米
|
|
12972
|
+
Meters: 1,
|
|
12973
|
+
// 米,1米 = 1米
|
|
12974
|
+
Kilometers: 1e-3,
|
|
12975
|
+
// 千米,1米 = 0.001千米
|
|
12976
|
+
Microinches: 3937007874015748e-8,
|
|
12977
|
+
// 微英寸,1米 = 39370078.74015748微英寸
|
|
12978
|
+
Mils: 39370.07874015748,
|
|
12979
|
+
// 密耳,1米 = 39370.07874015748密耳
|
|
12980
|
+
Yards: 1.0936132983377078,
|
|
12981
|
+
// 码,1米 = 1.0936132983377078码
|
|
12982
|
+
Angstroms: 1e10,
|
|
12983
|
+
// 埃,1米 = 10^10埃
|
|
12984
|
+
Nanometers: 1e9,
|
|
12985
|
+
// 纳米,1米 = 10^9纳米
|
|
12986
|
+
Microns: 1e6,
|
|
12987
|
+
// 微米,1米 = 10^6微米
|
|
12988
|
+
Decimeters: 10,
|
|
12989
|
+
// 分米,1米 = 10分米
|
|
12990
|
+
Decameters: 0.1,
|
|
12991
|
+
// 十米,1米 = 0.1十米
|
|
12992
|
+
Hectometers: 0.01,
|
|
12993
|
+
// 百米,1米 = 0.01百米
|
|
12994
|
+
Gigameters: 1e-9,
|
|
12995
|
+
// 吉米,1米 = 10^-9吉米
|
|
12996
|
+
"Astronomical units": 6684587122268445e-27,
|
|
12997
|
+
// 天文单位,1米 = 0.000000000006684587122268445天文单位
|
|
12998
|
+
"Light years": 10570008340246154e-32,
|
|
12999
|
+
// 光年,1米 ≈ 0.00000000000000010570008340246154光年
|
|
13000
|
+
Parsecs: 3240779289666404e-32
|
|
13001
|
+
// 秒差距,1米 ≈ 0.00000000000000003240779289666404秒差距
|
|
13002
|
+
};
|
|
12959
13003
|
class Dxf extends Component {
|
|
12960
13004
|
width = 0.04;
|
|
12961
13005
|
scale = 1;
|
|
@@ -13000,7 +13044,21 @@ class Dxf extends Component {
|
|
|
13000
13044
|
* @param width
|
|
13001
13045
|
* @param scale
|
|
13002
13046
|
*/
|
|
13003
|
-
set(data, width = this.width, scale = this.scale) {
|
|
13047
|
+
async set(data, width = this.width, scale = this.scale) {
|
|
13048
|
+
if (typeof data === "string") {
|
|
13049
|
+
if (typeof global !== "undefined") {
|
|
13050
|
+
const packageName = "fs";
|
|
13051
|
+
const { default: fs } = await import(
|
|
13052
|
+
/* @vite-ignore */
|
|
13053
|
+
packageName
|
|
13054
|
+
);
|
|
13055
|
+
const buffer = fs.readFileSync(data);
|
|
13056
|
+
const json = JSON.parse(buffer.toString("utf-8"));
|
|
13057
|
+
return this.set(json, width, scale);
|
|
13058
|
+
} else {
|
|
13059
|
+
throw new Error("非node环境不允许使用路径");
|
|
13060
|
+
}
|
|
13061
|
+
}
|
|
13004
13062
|
this.scale = scale;
|
|
13005
13063
|
this.width = width;
|
|
13006
13064
|
this.originalData = data;
|
|
@@ -13181,15 +13239,16 @@ class Dxf extends Component {
|
|
|
13181
13239
|
/**
|
|
13182
13240
|
* 将点云结构转换为string
|
|
13183
13241
|
*/
|
|
13184
|
-
toDxfString() {
|
|
13242
|
+
toDxfString(unit = "Millimeters") {
|
|
13185
13243
|
const d = new Drawing();
|
|
13186
13244
|
d.setUnits("Millimeters");
|
|
13245
|
+
const s = units[unit];
|
|
13187
13246
|
this.wallsGroup.forEach((points) => {
|
|
13188
13247
|
for (let i = 0; i < points.length; i++) {
|
|
13189
13248
|
const point1 = points[i];
|
|
13190
13249
|
const nextIndex = i === points.length - 1 ? 0 : i + 1;
|
|
13191
13250
|
const point2 = points[nextIndex];
|
|
13192
|
-
d.drawLine(point1.X *
|
|
13251
|
+
d.drawLine(point1.X * s, point1.Y * s, point2.X * s, point2.Y * s);
|
|
13193
13252
|
}
|
|
13194
13253
|
});
|
|
13195
13254
|
return d.toDxfString();
|
|
@@ -13198,17 +13257,17 @@ class Dxf extends Component {
|
|
|
13198
13257
|
* 将点云结构转换为DXF格式
|
|
13199
13258
|
* @returns
|
|
13200
13259
|
*/
|
|
13201
|
-
toDxfBlob() {
|
|
13202
|
-
const blob = new Blob([this.toDxfString()]);
|
|
13260
|
+
toDxfBlob(unit = "Millimeters") {
|
|
13261
|
+
const blob = new Blob([this.toDxfString(unit)]);
|
|
13203
13262
|
return blob;
|
|
13204
13263
|
}
|
|
13205
13264
|
/**
|
|
13206
13265
|
* 下载
|
|
13207
13266
|
* @param filename
|
|
13208
13267
|
*/
|
|
13209
|
-
async download(filename,
|
|
13268
|
+
async download(filename, unit = "Millimeters") {
|
|
13210
13269
|
if (typeof window !== "undefined") {
|
|
13211
|
-
const blob = this.toDxfBlob();
|
|
13270
|
+
const blob = this.toDxfBlob(unit);
|
|
13212
13271
|
const a = document.createElement("a");
|
|
13213
13272
|
a.href = URL.createObjectURL(blob);
|
|
13214
13273
|
a.download = filename + ".dxf";
|
|
@@ -13219,7 +13278,7 @@ class Dxf extends Component {
|
|
|
13219
13278
|
/* @vite-ignore */
|
|
13220
13279
|
packageName
|
|
13221
13280
|
);
|
|
13222
|
-
fs.writeFileSync(
|
|
13281
|
+
fs.writeFileSync(filename, this.toDxfString(unit));
|
|
13223
13282
|
}
|
|
13224
13283
|
}
|
|
13225
13284
|
/**
|
|
@@ -13863,6 +13922,10 @@ class DxfSystem extends ComponentManager {
|
|
|
13863
13922
|
Dxf;
|
|
13864
13923
|
Variable;
|
|
13865
13924
|
wallWidth;
|
|
13925
|
+
/** 构造函数
|
|
13926
|
+
* @param wallWidth 输出墙壁厚度,该墙壁厚度不受缩放影响
|
|
13927
|
+
* @param scale 原始数据缩放比例
|
|
13928
|
+
*/
|
|
13866
13929
|
constructor(wallWidth = 0.1, scale = 1) {
|
|
13867
13930
|
super();
|
|
13868
13931
|
this.wallWidth = wallWidth;
|