diff --git a/src/Add-on/CF/Import/CFImport.ts b/src/Add-on/CF/Import/CFImport.ts index 4fe3f4249..ed3de7561 100644 --- a/src/Add-on/CF/Import/CFImport.ts +++ b/src/Add-on/CF/Import/CFImport.ts @@ -24,37 +24,42 @@ export class ImportCFData implements Command for (let i = 0; i < files.length; i++) { let file = files.item(i); - let data = await file.text(); - try - { - let doc = JSON.parse(data); - if (doc.ModelSpace) - { - await ParseCFDoc(doc, app.Database); - } - else - { - AppToaster.show({ - message: `${file.name}不是有效的晨丰JSON文件!`, - timeout: 5000, - intent: Intent.WARNING, - }); - } - } - catch (error) - { - AppToaster.show({ - message: `${file.name}导入失败!`, - timeout: 5000, - intent: Intent.WARNING, - }); - } + await ImportCFFile(file); } } }); } } +export async function ImportCFFile(file: File) +{ + let data = await file.text(); + try + { + let doc = JSON.parse(data); + if (doc.ModelSpace) + { + await ParseCFDoc(doc, app.Database); + } + else + { + AppToaster.show({ + message: `${file.name}不是有效的晨丰JSON文件!`, + timeout: 5000, + intent: Intent.WARNING, + }); + } + } + catch (error) + { + AppToaster.show({ + message: `${file.name}导入失败!`, + timeout: 5000, + intent: Intent.WARNING, + }); + } +} + export async function ParseCFDoc(document: ICFDoc, cuDb: Database) { await CommandWrap(async () => diff --git a/src/Add-on/CF/Import/CFInterface.ts b/src/Add-on/CF/Import/CFInterface.ts index ddb061e49..7409cdff4 100644 --- a/src/Add-on/CF/Import/CFInterface.ts +++ b/src/Add-on/CF/Import/CFInterface.ts @@ -161,8 +161,8 @@ export interface ICFTopline extends ICFTemplate Spec?: string; //规格 Comments?: string; //备注 - Contour?: { pt: [number, number], bul: 0; }[]; //横截面轮廓曲线 - PathCurve?: ICFExtrudeContour; //绘制路径曲线 + Contour?: ICFPolylineContour; //横截面轮廓曲线 + PathCurve?: ICFExtrudeContour; //绘制路径曲线 } @@ -182,7 +182,7 @@ export interface ICFLine extends ICFCurve export interface ICFPolyline extends ICFCurve { // Type: "Polyline"; //类型多段线(必填) - ContourCurve?: { pt: [number, number], bul: 0; }[]; //轮廓曲线 + ContourCurve?: ICFPolylineContour; //轮廓曲线 } export interface ICFRect extends ICFCurve diff --git a/src/Add-on/CF/doc.md b/src/Add-on/CF/doc.md index ac777bdbf..374c6fcc7 100644 --- a/src/Add-on/CF/doc.md +++ b/src/Add-on/CF/doc.md @@ -8,10 +8,11 @@ type EntityType = "Entity" | "ExtrudeSolid" | "Board" | "Template" | "EntityTree // pt为点坐标,bul为弯曲度(区间-1~1),俗称弓弦比 // bul为0时为直线,bul为0.5时为半圆,正负为上下弯曲的方向 // bul值为(弧线两点直线的中点到弧线中点的距离)除以(弧线两点直线的中点到弧线起点的距离) -type PolylineContour = { pt: [number, number], bul: 0; }[]; //多段线轮廓 -type CircleContour = { Radius: number, Center: [number, number, number]; }; //圆形轮廓 -type ExtrudeContour = PolylineContour | CircleContour; +type ICFPolylineContour = { pt: [number, number], bul: 0; }[]; //多段线轮廓 +type ICFCircleContour = { Radius: number, Center: [number, number, number]; }; //圆形轮廓 + +type ICFExtrudeContour = ICFPolylineContour | ICFCircleContour; 图纸结构 1.模型空间 ModelSpace 结构 @@ -73,7 +74,7 @@ type ExtrudeContour = PolylineContour | CircleContour; Width?: number; //宽 Height?: number; //高 // Or - ContourCurve?: ExtrudeContour; //轮廓曲线 + ContourCurve?: ICFExtrudeContour; //轮廓曲线 Thickness?: number; //厚度 GroovesAddLength?: number; //槽加长 @@ -354,7 +355,7 @@ type ExtrudeContour = PolylineContour | CircleContour; Comments?: string; //备注 Contour?: { pt: [number, number], bul: 0; }[]; //横截面轮廓曲线 - PathCurve?: ExtrudeContour; //绘制路径曲线 + PathCurve?: ICFExtrudeContour; //绘制路径曲线 } 例1: diff --git a/src/ApplicationServices/Application.ts b/src/ApplicationServices/Application.ts index c0340adc8..13cc68266 100644 --- a/src/ApplicationServices/Application.ts +++ b/src/ApplicationServices/Application.ts @@ -3,6 +3,7 @@ import hotkeys from 'hotkeys-js-ext'; import { MathUtils, Matrix4, Object3D, PerspectiveCamera, Vector3 } from 'three'; import { begin, end } from 'xaop'; import { HardwareCuttingReactor } from '../Add-on/BoardCutting/HardwareCuttingReactor'; +import { ImportCFFile } from '../Add-on/CF/Import/CFImport'; import { DwgDxfImport } from '../Add-on/DXFLoad'; import { DrillingReactor } from '../Add-on/DrawDrilling/DrillingReactor'; import { AppendUserInfo } from '../Add-on/ExportData'; @@ -419,6 +420,8 @@ export class ApplicationService if (obj.paramModel) if (tpStore.canKJLImport) await ImportKJLData(obj); + if (obj.ModelSpace) + await ImportCFFile(f); } } if (xmlFiles.length)