酷家乐文件导入

pull/472/MERGE
ChenX 5 years ago
parent 46a3856c1b
commit e068f46fde

@ -0,0 +1,145 @@
import { Command } from "../Editor/CommandMachine";
import { Vec2 } from "../Geometry/CheckIntersect";
import { Vec3 } from "../Geometry/IVec3";
import { HotCMD } from "../Hot/HotCommand";
import { AsVector2 } from "../Geometry/GeUtils";
import { FixIndex } from "../Common/Utils";
import { Matrix4, Euler, Vector3 } from "three";
import { Board } from "../DatabaseServices/Entity/Board";
import { Polyline, PolylineProps } from "../DatabaseServices/Entity/Polyline";
import { app } from "../ApplicationServices/Application";
import { FileSystem } from "../Common/FileSystem";
/** 模型类型 */
enum KJL_ModelType
{
ParamModel = 1,//参数化模型
Max3DModel = 2, //3DMax模型
BaseModel = 3, //元件
VirtualModel = 4,//虚拟模型
}
/** 参数模型 */
interface KJL_ParamModel
{
modelTypeId: KJL_ModelType;
modelName: string;
parameters: [];
position: Vec3;
center: Vec3;
rotate: Vec3;
absPosition: Vec3;
absRotation: Vec3;
subModels: KJL_ParamModel[];
}
/** 曲线类型 */
enum KJL_LineType
{
Line = 0,
Arc = 1,
}
/** 板件数据(元件,可能) */
interface KJL_ParamModel_Board extends KJL_ParamModel
{
thickness: number;
points: Vec2[];
productionOldPath: {
points: Vec2[];
lines: {
type: KJL_LineType;
clockwise: boolean;
radius: number;
}[];
};
}
interface KJL_JsonFile
{
paramModel: KJL_ParamModel[];
}
@HotCMD
export class Command_KJLImport implements Command
{
async exec()
{
let flist = await FileSystem.ChooseFile(".json", false);
if (flist.length > 0)
{
let f = flist.item(0);
let fstr = await FileSystem.ReadFileAsText(f);
let json = JSON.parse(fstr) as KJL_JsonFile;
json.paramModel.forEach(ParseModel);
}
}
}
function ParseModel(model: KJL_ParamModel)
{
if (model.modelTypeId === KJL_ModelType.BaseModel)
{
let bmodel = model as KJL_ParamModel_Board;
if (!bmodel.productionOldPath)
{
return;
}
let pts = bmodel.productionOldPath.points.map(AsVector2);
let radiuss = bmodel.productionOldPath.lines.map(d =>
{
if (d.type === KJL_LineType.Line)
return 0;
else
{
let radius = d.radius;
if (d.clockwise)
radius = -radius;
return radius;
}
});
let buls: number[] = [];
for (let i = 0; i < radiuss.length; i++)
{
let radius = radiuss[i];
if (radius === 0)
buls.push(0);
else
{
let nextIndex = FixIndex(i + 1, radiuss.length);
let dist = pts[i].distanceTo(pts[nextIndex]);
let bul = Math.tan(0.5 * Math.asin(dist / Math.abs(radius))) * Math.sign(radius);
buls.push(bul);
}
}
let lined: PolylineProps[] = [];
for (let i = 0; i < pts.length; i++)
lined.push({ pt: pts[i], bul: buls[i] });
let pl = new Polyline(lined);
pl.CloseMark = true;
let br = new Board();
br.Name = bmodel.modelName;
br.Thickness = bmodel.thickness;
br.ContourCurve = pl;
br.Position = new Vector3(0, 0, bmodel.thickness * -0.5);
let mtx = new Matrix4().makeRotationFromEuler(new Euler(bmodel.absRotation.x, bmodel.absRotation.y, bmodel.absRotation.z, "ZYX"))
.setPosition(bmodel.absPosition.x, bmodel.absPosition.y, bmodel.absPosition.z);
br.ApplyMatrix(mtx);
app.Database.ModelSpace.Append(br);
}
if (model.subModels)
model.subModels.forEach(ParseModel);
}

@ -81,6 +81,7 @@ import { Command_HideSelected, Command_HideUnselected, Command_ShowAll } from ".
import { Command_Insert } from "../Add-on/Insert"; import { Command_Insert } from "../Add-on/Insert";
import { Command_INsTest } from "../Add-on/instest"; import { Command_INsTest } from "../Add-on/instest";
import { Command_Join } from "../Add-on/Join"; import { Command_Join } from "../Add-on/Join";
import { Command_KJLImport } from "../Add-on/KJLImport";
import { DrawLattice } from "../Add-on/LatticeDrawer/DrawLatticeDrawer"; import { DrawLattice } from "../Add-on/LatticeDrawer/DrawLatticeDrawer";
import { Command_Length } from "../Add-on/Length"; import { Command_Length } from "../Add-on/Length";
import { Command_Lisp } from "../Add-on/Lisp"; import { Command_Lisp } from "../Add-on/Lisp";
@ -118,6 +119,7 @@ import { Command_TestBox } from "../Add-on/testEntity/TestBox";
import { TestCollision } from "../Add-on/testEntity/testCollision"; import { TestCollision } from "../Add-on/testEntity/testCollision";
import { TestTargeOnCurve } from "../Add-on/testEntity/TestCurve"; import { TestTargeOnCurve } from "../Add-on/testEntity/TestCurve";
import { TestFillet } from "../Add-on/testEntity/TestFilletCode"; import { TestFillet } from "../Add-on/testEntity/TestFilletCode";
import { Command_DeleteTemplate } from "../Add-on/testEntity/TestTemplateDelete";
import { TestFb } from "../Add-on/TestFb"; import { TestFb } from "../Add-on/TestFb";
import { Command_TestPointPickParse } from "../Add-on/TestPointPickParse"; import { Command_TestPointPickParse } from "../Add-on/TestPointPickParse";
import { Command_Trim } from "../Add-on/Trim"; import { Command_Trim } from "../Add-on/Trim";
@ -129,10 +131,11 @@ import { CommandServer } from "../DatabaseServices/CommandServer";
import { AutoTempateSizeAction } from "../DatabaseServices/Template/TemplateTest"; import { AutoTempateSizeAction } from "../DatabaseServices/Template/TemplateTest";
import { ICommand } from "../UI/Components/CommandPanel/CommandList"; import { ICommand } from "../UI/Components/CommandPanel/CommandList";
import { commandMachine } from "./CommandMachine"; import { commandMachine } from "./CommandMachine";
import { Command_DeleteTemplate } from "../Add-on/testEntity/TestTemplateDelete";
export function registerCommand() export function registerCommand()
{ {
commandMachine.RegisterCommand("kjl", new Command_KJLImport());
commandMachine.RegisterCommand("group", new Command_Group()); commandMachine.RegisterCommand("group", new Command_Group());
commandMachine.RegisterCommand("dxf", new Command_DXFImport()); commandMachine.RegisterCommand("dxf", new Command_DXFImport());

Loading…
Cancel
Save