From c853a7fed7ccb8cc4b5c6cd3540af075e8a0b640 Mon Sep 17 00:00:00 2001 From: ChenX Date: Thu, 25 Jul 2019 15:43:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E9=85=92=E6=A0=BC=E6=A8=A1?= =?UTF-8?q?=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Template/TemplateRecord.ts | 8 +- src/DatabaseServices/Template/TemplateTest.ts | 50 ++++- .../Template/TemplateWineRackRecord.ts | 178 ++++++++++++++++++ 3 files changed, 230 insertions(+), 6 deletions(-) create mode 100644 src/DatabaseServices/Template/TemplateWineRackRecord.ts diff --git a/src/DatabaseServices/Template/TemplateRecord.ts b/src/DatabaseServices/Template/TemplateRecord.ts index 1541aec61..fe7b040c8 100644 --- a/src/DatabaseServices/Template/TemplateRecord.ts +++ b/src/DatabaseServices/Template/TemplateRecord.ts @@ -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; /** * 本节点可用的所有变量定义.(包括变量继承) diff --git a/src/DatabaseServices/Template/TemplateTest.ts b/src/DatabaseServices/Template/TemplateTest.ts index 198a06370..d7ef3ea40 100644 --- a/src/DatabaseServices/Template/TemplateTest.ts +++ b/src/DatabaseServices/Template/TemplateTest.ts @@ -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()); diff --git a/src/DatabaseServices/Template/TemplateWineRackRecord.ts b/src/DatabaseServices/Template/TemplateWineRackRecord.ts new file mode 100644 index 000000000..b38d5ac44 --- /dev/null +++ b/src/DatabaseServices/Template/TemplateWineRackRecord.ts @@ -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 +}