|
|
|
@ -1,8 +1,10 @@
|
|
|
|
|
import { Intent } from "@blueprintjs/core";
|
|
|
|
|
import { Vector3 } from "three";
|
|
|
|
|
import { arrayLast } from "../Common/ArrayExt";
|
|
|
|
|
import { Draw } from "../Common/Draw";
|
|
|
|
|
import { FileSystem } from "../Common/FileSystem";
|
|
|
|
|
import { CommandWrap } from "../Editor/CommandMachine";
|
|
|
|
|
import { GetBox } from "../Geometry/GeUtils";
|
|
|
|
|
import { AppToaster } from "../UI/Components/Toaster";
|
|
|
|
|
import { Dxf2Entitys } from "./ACAD/DxfEntityConvert";
|
|
|
|
|
import { Dwg2Dxf } from "./DwgLoader/DwgLoader";
|
|
|
|
@ -31,31 +33,28 @@ export class Command_DWGDXFImport
|
|
|
|
|
export async function DwgDxfImport(f: File)
|
|
|
|
|
{
|
|
|
|
|
let ext = arrayLast(f.name.split(".")).toUpperCase();
|
|
|
|
|
let dxfStr: string;
|
|
|
|
|
if (ext === "DXF")
|
|
|
|
|
{
|
|
|
|
|
let str = await FileSystem.ReadFileAsText(f);
|
|
|
|
|
|
|
|
|
|
for (let e of Dxf2Entitys(str))
|
|
|
|
|
Draw(e);
|
|
|
|
|
|
|
|
|
|
AppToaster.show({
|
|
|
|
|
message: `成功导入${f.name}`,
|
|
|
|
|
intent: Intent.SUCCESS,
|
|
|
|
|
timeout: 3000,
|
|
|
|
|
});
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
dxfStr = await FileSystem.ReadFileAsText(f);
|
|
|
|
|
else if (ext === "DWG")
|
|
|
|
|
dxfStr = await Dwg2Dxf(f);
|
|
|
|
|
|
|
|
|
|
let size = new Vector3;
|
|
|
|
|
for (let e of Dxf2Entitys(dxfStr))
|
|
|
|
|
{
|
|
|
|
|
let dxfStr = await Dwg2Dxf(f);
|
|
|
|
|
for (let e of Dxf2Entitys(dxfStr))
|
|
|
|
|
Draw(e);
|
|
|
|
|
//校验实体有效性 避免出现nan的情况
|
|
|
|
|
let obj = e.DrawObject;
|
|
|
|
|
GetBox(obj).getSize(size);
|
|
|
|
|
if (isNaN(size.x) || isNaN(size.y) || isNaN(size.z))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
AppToaster.show({
|
|
|
|
|
message: `成功导入${f.name}`,
|
|
|
|
|
intent: Intent.SUCCESS,
|
|
|
|
|
timeout: 3000,
|
|
|
|
|
});
|
|
|
|
|
return true;
|
|
|
|
|
Draw(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AppToaster.show({
|
|
|
|
|
message: `成功导入${f.name}`,
|
|
|
|
|
intent: Intent.SUCCESS,
|
|
|
|
|
timeout: 3000,
|
|
|
|
|
});
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|