实现酒格模版

pull/428/head
ChenX 5 years ago
parent 3175c14eed
commit c853a7fed7

@ -217,7 +217,7 @@ export class TemplateRecord extends SymbolTableRecord
* - (),().
*
*/
private async Update()
protected async Update()
{
let vardefines = this.GetParameterDefinition(false);
let brs = this.Objects.filter(id => !id.IsErase).map(id => id.Object as Board);
@ -317,6 +317,7 @@ export class TemplateRecord extends SymbolTableRecord
//Cache
this._CacheParamVars = vardefines;
this._CacheSpaceCS = spaceCS;
this._CacheSpaceSize = spaceSize;
}
/**
@ -405,8 +406,9 @@ export class TemplateRecord extends SymbolTableRecord
}
/** 缓存本节点的变量定义值,当子层需要本层的参数时,可以直接获取 */
private _CacheParamVars: any;
private _CacheSpaceCS: Matrix4;
protected _CacheParamVars: any;
protected _CacheSpaceCS: Matrix4;
protected _CacheSpaceSize: Vector3;
/**
* .()

@ -26,6 +26,7 @@ import { IntersectOption } from "../../GraphicsSystem/IntersectWith";
import { TemplateFilletAction } from "./Action/TemplateFilletAction";
import { Database } from "../Database";
import { DuplicateRecordCloning } from "../../Common/Status";
import { TemplateWineRackRecord } from "./TemplateWineRackRecord";
export function GetDefaultTemplate()
{
@ -408,7 +409,7 @@ export class UpdateParam2
let p = ["L", "W", "H"];
this.timer = setInterval(() =>
{
if (index === 300) index = 0;
if (index === 30) index = 0;
let mx = Math.floor(index / 100);
@ -416,11 +417,11 @@ export class UpdateParam2
let param = template.GetParam(p[mx]);
if (i < 50)
{
param.UpdateParam(param.value as number + 150);
param.UpdateParam(param.value as number + 15);
}
if (i >= 50)
{
param.UpdateParam(param.value as number - 150);
param.UpdateParam(param.value as number - 15);
}
template.UpdateTemplateTree();
@ -750,10 +751,53 @@ export class TemplateAddFilletAction
}
}
export class Command_TemplateWineRack
{
async exec()
{
let selectSpace = new PointSelectSpaceClamp();
selectSpace.Enable = EnableSelectType.Stretch;
await selectSpace.Select();
if (!selectSpace.ParseOK)
{
app.Editor.Prompt("未能分析出有效空间!");
return;
}
let brs = selectSpace.SpaceParse.m_Boards;
let tbrs = brs.filter(br => br.Template !== undefined);
tbrs.sort((b1, b2) =>
{
let t1 = b1.Template.Object as TemplateRecord;
let t2 = b2.Template.Object as TemplateRecord;
return t2.NodeDepth - t1.NodeDepth;
});
let templateSource: TemplateRecord;
if (tbrs.length > 0)
templateSource = tbrs[0].Template.Object as TemplateRecord;
let parse = selectSpace.SpaceParse as ClampSpaceParse;
let positioning = new PositioningClampSpace();
positioning.FromSpaceParse(parse);
let wineRack = new TemplateWineRackRecord().InitBaseParams();
app.Database.TemplateTable.Append(wineRack);
wineRack.Positioning = positioning;
if (templateSource)
templateSource.Children.push(wineRack.Id);
wineRack.UpdateTemplateTree();
}
}
commandMachine.RegisterCommand("Attach", new TemplateAttach());
commandMachine.RegisterCommand("Attach2", new TemplateAttach2());
commandMachine.RegisterCommand("Attach3", new TemplateAttach3());
commandMachine.RegisterCommand("Attach4", new Command_TemplateWineRack());
commandMachine.RegisterCommand("templateAddFilletAction", new TemplateAddFilletAction());

@ -0,0 +1,178 @@
import { Vector3 } from "three";
import { DrawBlisWineRackTool } from "../../Add-on/DrawWineRack/DrawBlisWineRackTool";
import { app } from "../../ApplicationServices/Application";
import { Box3Ext } from "../../Geometry/Box";
import { ISpaceParse } from "../../Geometry/SpaceParse/ISpaceParse";
import { EFullDir, EFullType, EWineRackType, EWRackArrayType, IWineRackOption } from "../../UI/Store/WineRackInterface";
import { Factory } from "../CADFactory";
import { CADFiler } from "../CADFiler";
import { Board } from "../Entity/Board";
import { PositioningClampSpace } from "./Positioning/PositioningClampSpace";
import { TemplateRecord } from "./TemplateRecord";
@Factory
export class TemplateWineRackRecord extends TemplateRecord
{
option: IWineRackOption;
constructor()
{
super();
}
InitBaseParams()
{
super.InitBaseParams();
this.option = {
type: EWineRackType.Bias,
arrayType: EWRackArrayType.ByWidth,
fullType: EFullType.ByWidth,
isFull: false,
isLock: false,
fullDir: EFullDir.Left,
heightCount: 3.5,
widthCount: 3.5,
isTotalDepth: true,
depth: 0,
gripWidth: 100,
calcDepth: "L",
boardThick: 18,
grooveWidthAdd: 0,
leftEdge: 1,
rightEdge: 1,
topEdge: 1,
bottomEdge: 1,
frontCut: 0,
leftCut: 0,
rightCut: 0,
topCut: 0,
grooveLengthAdd: 3,
isDrawLy: false,
isDrawVer: false,
brThick2: 18,
};
return this;
}
protected async Update()
{
await super.Update();
let wineRack = DrawBlisWineRackTool.GetInstance() as DrawBlisWineRackTool;
let brs: Board[] = [];
if (this.Positioning && this.Positioning instanceof PositioningClampSpace)
{
brs = this.Positioning.Objects.map(id => id.Object as Board);
}
let space = new ISpaceParse(brs, this._CacheSpaceCS);
space.m_ParseOK = true;
space.m_SpaceBox = new Box3Ext(new Vector3(), this._CacheSpaceSize);
wineRack.Parse(space, this.option);
let nbrs = wineRack.boardlist;
for (let i = nbrs.length; i < this.Objects.length; i++)
this.Objects[i].Object.Erase();
if (this.Objects.length > nbrs.length)
this.Objects.length = nbrs.length;
for (let i = 0; i < nbrs.length; i++)
{
if (i < this.Objects.length)
{
let br = this.Objects[i].Object as Board;
br.Erase(false);
br.CopyFrom(nbrs[i]);
}
else
{
app.Database.ModelSpace.Append(nbrs[i]);
this.Objects.push(nbrs[i].Id);
}
}
}
//#region -------------------------File-------------------------
//对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化
//对象从文件中读取数据,初始化自身
ReadFile(file: CADFiler)
{
let ver = file.Read();
super.ReadFile(file);
if (!this.option)
//@ts-ignore
this.option = {};
this.option.type = file.Read();
this.option.arrayType = file.Read();
this.option.fullType = file.Read();
this.option.isFull = file.Read();
this.option.fullDir = file.Read();
this.option.isLock = file.Read();
this.option.heightCount = file.Read();
this.option.widthCount = file.Read();
this.option.isTotalDepth = file.Read();
this.option.depth = file.Read();
this.option.calcDepth = file.Read();
this.option.gripWidth = file.Read();
this.option.boardThick = file.Read();
this.option.grooveWidthAdd = file.Read();
this.option.leftEdge = file.Read();
this.option.rightEdge = file.Read();
this.option.topEdge = file.Read();
this.option.bottomEdge = file.Read();
this.option.frontCut = file.Read();
this.option.leftCut = file.Read();
this.option.rightCut = file.Read();
this.option.topCut = file.Read();
this.option.grooveLengthAdd = file.Read();
this.option.isDrawLy = file.Read();
this.option.isDrawVer = file.Read();
this.option.brThick2 = file.Read();
}
//对象将自身数据写入到文件.
WriteFile(file: CADFiler)
{
file.Write(1);
super.WriteFile(file);
file.Write(this.option.type);
file.Write(this.option.arrayType);
file.Write(this.option.fullType);
file.Write(this.option.isFull);
file.Write(this.option.fullDir);
file.Write(this.option.isLock);
file.Write(this.option.heightCount);
file.Write(this.option.widthCount);
file.Write(this.option.isTotalDepth);
file.Write(this.option.depth);
file.Write(this.option.calcDepth);
file.Write(this.option.gripWidth);
file.Write(this.option.boardThick);
file.Write(this.option.grooveWidthAdd);
file.Write(this.option.leftEdge);
file.Write(this.option.rightEdge);
file.Write(this.option.topEdge);
file.Write(this.option.bottomEdge);
file.Write(this.option.frontCut);
file.Write(this.option.leftCut);
file.Write(this.option.rightCut);
file.Write(this.option.topCut);
file.Write(this.option.grooveLengthAdd);
file.Write(this.option.isDrawLy);
file.Write(this.option.isDrawVer);
file.Write(this.option.brThick2);
}
//#endregion
}
Loading…
Cancel
Save