diff --git a/__test__/Winerack/__snapshots__/winerack.test.ts.snap b/__test__/Winerack/__snapshots__/winerack.test.ts.snap new file mode 100644 index 000000000..508e3fd90 --- /dev/null +++ b/__test__/Winerack/__snapshots__/winerack.test.ts.snap @@ -0,0 +1,5 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`酒格功能测试 斜酒格1 1`] = `24`; + +exports[`酒格功能测试 斜酒格1 2`] = `33`; diff --git a/__test__/Winerack/winerack.test.ts b/__test__/Winerack/winerack.test.ts new file mode 100644 index 000000000..74f9777a1 --- /dev/null +++ b/__test__/Winerack/winerack.test.ts @@ -0,0 +1,57 @@ +import { DrawUprightWineRackTool } from "../../src/Add-on/DrawWineRack/DrawUprightWineRackTool"; +import { DrawBlisWineRackTool } from "../../src/Add-on/DrawWineRack/DrawBlisWineRackTool"; +import { IWineRackOption, EWineRackType, EWRackArrayType, EFullType, EFullDir } from "../../src/UI/Store/WineRackInterface"; +import { ISpaceParse } from "../../src/Geometry/SpaceParse/ISpaceParse"; +import { Box3, Vector3, Matrix4 } from "three"; +import { Box3Ext } from "../../src/Geometry/Box"; +import { LoadEntityFromFileData } from "../Utils/LoadEntity.util"; +import { Board } from "../../src/DatabaseServices/Entity/Board"; +const UprightTool = DrawUprightWineRackTool.GetInstance() as DrawUprightWineRackTool; +const blisTool = DrawBlisWineRackTool.GetInstance() as DrawBlisWineRackTool; + +const option: IWineRackOption = { + 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, +} + +describe("酒格功能测试", () => +{ + test("斜酒格1", () => + { + let data = + [2, "Board", 5, 2, 102, false, 1, 11, 0, [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 580.3050847457629, -214.2857142857143, 0, 1], 0, 0, 2, 2000, 600, 18, true, "Polyline", 5, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 2, 4, [0, 0], 0, [600, 0], 0, [600, 2000], 0, [0, 2000], 0, true, 0, 3, 0, 0, 0, 4, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 580.3050847457629, -214.2857142857143, 0, 1], 1, "右侧板", "主卧", "下柜", "", "", "", 0, 0, "三合一", 2, 0, "1", "1", "1", "1", "", "", "", 4, "三合一", "三合一", "三合一", "三合一", true, true, 0, 0, "Board", 5, 2, 101, false, 1, 11, 0, [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, -601.6949152542372, -214.2857142857143, 0, 1], 0, 0, 2, 2000, 600, 18, true, "Polyline", 5, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 2, 4, [0, 0], 0, [600, 0], 0, [600, 2000], 0, [0, 2000], 0, true, 0, 3, 0, 0, 0, 4, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -601.6949152542372, -214.2857142857143, 0, 1], 1, "左侧板", "主卧", "下柜", "", "", "", 0, 0, "三合一", 2, 0, "1", "1", "1", "1", "", "", "", 4, "三合一", "三合一", "三合一", "三合一", true, true, 0, 0] + + let spaceParse = new ISpaceParse(); + spaceParse.m_Boards = LoadEntityFromFileData(data) as Board[]; + spaceParse.m_SpaceBox = new Box3Ext(new Vector3(), new Vector3(1200, 600, 2000)); + spaceParse.Parse(); + UprightTool.Parse(spaceParse, option); + blisTool.Parse(spaceParse, option); + expect(UprightTool.boardlist.length).toMatchSnapshot(); + expect(blisTool.boardlist.length).toMatchSnapshot(); + }) +}) diff --git a/src/Add-on/DrawWineRack/DrawBlisWineRackTool.ts b/src/Add-on/DrawWineRack/DrawBlisWineRackTool.ts index 10cd0446e..54ac1a623 100644 --- a/src/Add-on/DrawWineRack/DrawBlisWineRackTool.ts +++ b/src/Add-on/DrawWineRack/DrawBlisWineRackTool.ts @@ -1,5 +1,4 @@ import { Matrix4, Vector2, Vector3 } from "three"; -import { app } from "../../ApplicationServices/Application"; import { arrayLast, arrayRemoveDuplicateBySort, arraySortByNumber } from "../../Common/ArrayExt"; import { Board } from "../../DatabaseServices/Entity/Board"; import { Line } from "../../DatabaseServices/Entity/Line"; @@ -7,9 +6,9 @@ import { Polyline } from "../../DatabaseServices/Entity/Polyline"; import { equaln, MoveMatrix, polar, XAxis, YAxis, ZAxis, AsVector2 } from "../../Geometry/GeUtils"; import { ISpaceParse } from "../../Geometry/SpaceParse/ISpaceParse"; import { IntersectOption } from "../../GraphicsSystem/IntersectWith"; -import { EFullDir, EFullType, EWRackArrayType } from "../../UI/Store/WineRackInterface"; -import { GetMirrorMat } from "../Mirror"; +import { EFullDir, EFullType, EWRackArrayType, IWineRackOption } from "../../UI/Store/WineRackInterface"; import { DrawWineRackTool, SIN45 } from "./DrawWinRackTool"; +import { GetMirrorMat } from "../../Common/Matrix4Utils"; export interface IWineRackData { @@ -29,10 +28,9 @@ export interface IParsePlRes export class DrawBlisWineRackTool extends DrawWineRackTool { - Draw(space: ISpaceParse) + Parse(space: ISpaceParse, config: IWineRackOption) { - super.Draw(space); - const config = this.getConfig(); + super.Parse(space, config); const size = space.Size; const spaceHeight = size.z; const spaceWidth = size.x; @@ -130,22 +128,21 @@ export class DrawBlisWineRackTool extends DrawWineRackTool //补板 this.AddLayerOrVerticalBoard(res.width, res.height); } - this.config = null; } private CalGridWidth(length: number) { - const count = (length - this.config.boardThick * 2 / SIN45) / ((this.config.boardThick + this.config.gripWidth) * Math.sqrt(2)); - this.config.gripWidth = ((length - this.config.boardThick / SIN45) / Math.floor(count)) / Math.sqrt(2) - this.config.boardThick; + const count = (length - this.Config.boardThick * 2 / SIN45) / ((this.Config.boardThick + this.Config.gripWidth) * Math.sqrt(2)); + this.Config.gripWidth = ((length - this.Config.boardThick / SIN45) / Math.floor(count)) / Math.sqrt(2) - this.Config.boardThick; } /**获取矩形多段线的4个对角点并判断是否有效 */ private GetRect4Pts(xline: Line, rectPl: Polyline, p1: Vector3, p2: Vector3, p3: Vector3, p4: Vector3) { let res1 = this.GetRect2Pts(xline, rectPl, p1, p2); - let vec = polar(new Vector3(), Math.PI * 0.75, this.config.boardThick); + let vec = polar(new Vector3(), Math.PI * 0.75, this.Config.boardThick); xline.ApplyMatrix(MoveMatrix(vec)); let res2 = this.GetRect2Pts(xline, rectPl, p3, p4); - return res1 && res2 && p1.distanceTo(p2) > this.config.gripWidth; + return res1 && res2 && p1.distanceTo(p2) > this.Config.gripWidth; } /**获取矩形一边的点 */ private GetRect2Pts(xline: Line, rectPl: Polyline, p1: Vector3, p2: Vector3) @@ -169,55 +166,55 @@ export class DrawBlisWineRackTool extends DrawWineRackTool private CalcWineRackDataByWidth(lWRDataList: IWineRackData[], rWRDataList: IWineRackData[]) { let size = this.space.Size; - let config = this.getConfig(); + let Config = this.Config; let widthCount = 0, heightCount = 0, gripWidth = 0; - let width = size.x - 2 * config.boardThick * SIN45; - let height = size.z - 2 * config.boardThick * SIN45; - if (config.fullType === EFullType.ByWidth) + let width = size.x - 2 * Config.boardThick * SIN45; + let height = size.z - 2 * Config.boardThick * SIN45; + if (Config.fullType === EFullType.ByWidth) { - widthCount = Math.floor(width / ((config.gripWidth + config.boardThick) * SIN45)); + widthCount = Math.floor(width / ((Config.gripWidth + Config.boardThick) * SIN45)); gripWidth = width / widthCount; //处理锁定个数 - if (!config.isLock) + if (!Config.isLock) { heightCount = Math.floor(height / gripWidth); } else { - heightCount = Math.floor(config.heightCount * 2); + heightCount = Math.floor(Config.heightCount * 2); } - height = heightCount * gripWidth + 2 * config.boardThick * SIN45; + height = heightCount * gripWidth + 2 * Config.boardThick * SIN45; width = size.x; } else { - heightCount = Math.floor(height / ((config.gripWidth + config.boardThick) * SIN45)); + heightCount = Math.floor(height / ((Config.gripWidth + Config.boardThick) * SIN45)); gripWidth = height / heightCount; //处理锁定个数 - if (!config.isLock) + if (!Config.isLock) { widthCount = Math.floor(width / gripWidth); } else { - widthCount = Math.floor(config.widthCount * 2); + widthCount = Math.floor(Config.widthCount * 2); } - width = widthCount * gripWidth + 2 * config.boardThick * SIN45; + width = widthCount * gripWidth + 2 * Config.boardThick * SIN45; height = size.z; } - this.GetWineRackData(width, height, gripWidth, config.boardThick, widthCount, heightCount, lWRDataList, rWRDataList); + this.GetWineRackData(width, height, gripWidth, Config.boardThick, widthCount, heightCount, lWRDataList, rWRDataList); return { width: width, height: height } } private CalcWineRackDataByCount(lWRDataList: IWineRackData[], rWRDataList: IWineRackData[]) { - const config = this.getConfig(); + const config = this.Config; const size = this.space.Size; let widthCount = Math.floor(config.widthCount * 2); let heightCount = Math.floor(config.heightCount * 2); @@ -253,7 +250,7 @@ export class DrawBlisWineRackTool extends DrawWineRackTool } CalcWineRackDataByFixed(lWRDataList: IWineRackData[], rWRDataList: IWineRackData[]) { - const config = this.getConfig(); + const config = this.Config; let widthCount = Math.floor(config.widthCount * 2); let heightCount = Math.floor(config.heightCount * 2); let gripWidth = config.gripWidth * SIN45; @@ -293,28 +290,28 @@ export class DrawBlisWineRackTool extends DrawWineRackTool return null; } - let minDis = this.config.boardThick / Math.sqrt(2); + let minDis = this.Config.boardThick / Math.sqrt(2); //如果左边停靠 if (p1.x < minDis) { - p1.copy(polar(p3.clone(), Math.PI * -0.25, this.config.boardThick)); + p1.copy(polar(p3.clone(), Math.PI * -0.25, this.Config.boardThick)); } else { - p3.copy(polar(p1.clone(), Math.PI * 0.75, this.config.boardThick)); + p3.copy(polar(p1.clone(), Math.PI * 0.75, this.Config.boardThick)); } //右边点 上面停靠 let size = this.space.Size; if (p2.y > size.z - minDis) { - p2.copy(polar(p4.clone(), -Math.PI * 0.25, this.config.boardThick)); + p2.copy(polar(p4.clone(), -Math.PI * 0.25, this.Config.boardThick)); } else { - p4.copy(polar(p2.clone(), Math.PI * 0.75, this.config.boardThick)); + p4.copy(polar(p2.clone(), Math.PI * 0.75, this.Config.boardThick)); } - if (p1.distanceTo(p2) < (this.config.gripWidth + this.config.boardThick * 1.8) && p1.y > this.config.boardThick * 2) + if (p1.distanceTo(p2) < (this.Config.gripWidth + this.Config.boardThick * 1.8) && p1.y > this.Config.boardThick * 2) return null; let lineData = [p1, p2, p4, p3].map(p => @@ -478,7 +475,7 @@ export class DrawBlisWineRackTool extends DrawWineRackTool /**根据酒格数据获取多段线 */ private CreatePolylineByWineData(data: IWineRackData, isLeft = true) { - let thick = this.config.boardThick; + let thick = this.Config.boardThick; let lineData = [ { pt: new Vector2(), @@ -606,7 +603,7 @@ export class DrawBlisWineRackTool extends DrawWineRackTool if (!lData.length) return; - const config = this.getConfig(); + const config = this.Config; for (let i = 0; i < lData.length; i++) { @@ -642,7 +639,7 @@ export class DrawBlisWineRackTool extends DrawWineRackTool br.ApplyMatrix(MoveMatrix(new Vector3(this.space.Size.x - actualWidth))); } br.ApplyMatrix(this.space.m_SpaceOCS); - app.Database.ModelSpace.Append(br); + this.boardlist.push(br); } } } @@ -654,7 +651,7 @@ export class DrawBlisWineRackTool extends DrawWineRackTool pl.Create2Pt(new Vector3(), new Vector3(size.y, len)); pl.CloseMark = true; - const config = this.getConfig(); + const config = this.Config; let addWidth = config.grooveWidthAdd; let leftEdge = config.leftEdge; let rightEdge = config.rightEdge; diff --git a/src/Add-on/DrawWineRack/DrawUprightWineRackTool.ts b/src/Add-on/DrawWineRack/DrawUprightWineRackTool.ts index d6fcad21e..c3bccc36a 100644 --- a/src/Add-on/DrawWineRack/DrawUprightWineRackTool.ts +++ b/src/Add-on/DrawWineRack/DrawUprightWineRackTool.ts @@ -1,17 +1,15 @@ import { Vector3 } from "three"; -import { app } from "../../ApplicationServices/Application"; import { Board, BoardType } from "../../DatabaseServices/Entity/Board"; import { Polyline } from "../../DatabaseServices/Entity/Polyline"; import { MoveMatrix, AsVector2 } from "../../Geometry/GeUtils"; import { ISpaceParse } from "../../Geometry/SpaceParse/ISpaceParse"; -import { EWRackArrayType } from "../../UI/Store/WineRackInterface"; +import { EWRackArrayType, IWineRackOption } from "../../UI/Store/WineRackInterface"; import { DrawWineRackTool } from "./DrawWinRackTool"; export class DrawUprightWineRackTool extends DrawWineRackTool { - Draw(space: ISpaceParse) + Parse(space: ISpaceParse, config: IWineRackOption) { - super.Draw(space); - let config = this.getConfig(); + super.Parse(space, config); let size = space.Size; let gripWidth = config.gripWidth; let brThick = config.boardThick; @@ -83,11 +81,10 @@ export class DrawUprightWineRackTool extends DrawWineRackTool config.heightCount--; this.BuildBoard(gripHeight, actualWidth, actualHeight, space); this.AddLayerOrVerticalBoard(actualWidth, actualHeight); - this.config = null; } BuildBoard(gripHeight: number, spaceWidth: number, spaceHeight: number, space: ISpaceParse) { - const config = this.getConfig(); + const config = this.Config; let min = space.m_SpaceBox.min; let size = space.Size; let brThick = config.boardThick; @@ -99,8 +96,7 @@ export class DrawUprightWineRackTool extends DrawWineRackTool let br = verBr.Clone(); br.Name = "右板" + i; br.ApplyMatrix(MoveMatrix(min.clone().add(new Vector3(config.gripWidth * i + (i - 1) * brThick)))).ApplyMatrix(space.m_SpaceOCS); - app.Database.ModelSpace.Append(br); - + this.boardlist.push(br); } let lyBr = Board.CreateBoard(spaceWidth, size.y, brThick); @@ -112,12 +108,12 @@ export class DrawUprightWineRackTool extends DrawWineRackTool br.ApplyMatrix(MoveMatrix( min.clone().add(new Vector3(spaceWidth, 0, gripHeight * i + (i - 1) * brThick)))) .ApplyMatrix(space.m_SpaceOCS); - app.Database.ModelSpace.Append(br); + this.boardlist.push(br); } } ParseBrTooth(br: Board, gripHeight?: number) { - const config = this.getConfig(); + const config = this.Config; let initPts: Vector3[] = []; let addWidth = config.grooveWidthAdd; diff --git a/src/Add-on/DrawWineRack/DrawWinRackTool.ts b/src/Add-on/DrawWineRack/DrawWinRackTool.ts index 1eb7cbae2..793d47bfd 100644 --- a/src/Add-on/DrawWineRack/DrawWinRackTool.ts +++ b/src/Add-on/DrawWineRack/DrawWinRackTool.ts @@ -1,29 +1,27 @@ import { Singleton } from "../../Common/Singleton"; import { ISpaceParse } from "../../Geometry/SpaceParse/ISpaceParse"; -import { IWineRackOption, EWRackArrayType, EFullType, EFullDir } from "../../UI/Store/WineRackInterface"; -import { WineRackStore } from "../../UI/Store/WineRackStore"; +import { EWRackArrayType, EFullType, EFullDir, IWineRackOption } from "../../UI/Store/WineRackInterface"; import { Vector3 } from "three"; import { operationExpReg } from "../../Common/Utils"; import { Board, BoardType } from "../../DatabaseServices/Entity/Board"; import { IHighSealedItem, DrillType, FaceDirection } from "../../UI/Store/BoardInterface"; -import { app } from "../../ApplicationServices/Application"; export const SIN45 = Math.sin(Math.PI / 4); export class DrawWineRackTool extends Singleton { - protected config: IWineRackOption; + private _config: IWineRackOption; protected space: ISpaceParse; - protected getConfig() + public boardlist: Board[] = []; + get Config() { - if (!this.config) - this.config = Object.assign({}, (WineRackStore.GetInstance() as WineRackStore).m_Option); - return this.config; + return this._config; } - Draw(space: ISpaceParse) + Parse(space: ISpaceParse, config: IWineRackOption) { + this._config = config; + this.boardlist.length = 0; this.space = space; - const config = this.getConfig(); //处理格子深 if (!config.isTotalDepth) { @@ -100,7 +98,7 @@ export class DrawWineRackTool extends Singleton /**补板 */ protected AddLayerOrVerticalBoard(actWidth: number, actHeight: number) { - const config = this.getConfig(); + const config = this.Config; const size = this.space.Size; let isDrawLy = false; //是否补层板 @@ -135,7 +133,7 @@ export class DrawWineRackTool extends Singleton br.BoardProcessOption.bigHoleDir = FaceDirection.Back; br.Position = position; br.ApplyMatrix(this.space.m_SpaceOCS); - app.Database.ModelSpace.Append(br); + this.boardlist.push(br); } if (config.isDrawVer && (config.arrayType === EWRackArrayType.Fixed || config.fullType === EFullType.ByHeight)) { @@ -157,7 +155,7 @@ export class DrawWineRackTool extends Singleton this.GetBoardProcessOption(br); br.Position = position; br.ApplyMatrix(this.space.m_SpaceOCS); - app.Database.ModelSpace.Append(br); + this.boardlist.push(br); } } } diff --git a/src/Add-on/DrawWineRack/DrawWineRack.ts b/src/Add-on/DrawWineRack/DrawWineRack.ts index 903a1630d..1bbe93dc9 100644 --- a/src/Add-on/DrawWineRack/DrawWineRack.ts +++ b/src/Add-on/DrawWineRack/DrawWineRack.ts @@ -2,6 +2,9 @@ import { Command } from "../../Editor/CommandMachine"; import { PointSelectSpaceClamp } from "../../Geometry/SpaceParse/PointSelectSpaceClamp"; import { DrawBlisWineRackTool } from "./DrawBlisWineRackTool"; import { DrawUprightWineRackTool } from "./DrawUprightWineRackTool"; +import { app } from "../../ApplicationServices/Application"; +import { userConfig } from "../../Editor/UserConfig"; +import { userConfigStore } from "../../UI/Store/UserConfigStore"; export class DrawWineRack implements Command { @@ -11,9 +14,13 @@ export class DrawWineRack implements Command await selectSpace.Select(); if (!selectSpace.ParseOK) return; + + if (!userConfig.winerackConfig) + await userConfigStore.InitWinerackConfig(); let space = selectSpace.SpaceParse; const tool = DrawUprightWineRackTool.GetInstance() as DrawUprightWineRackTool; - tool.Draw(space); + tool.Parse(space, userConfig.winerackConfig); + tool.boardlist.forEach(b => app.Database.ModelSpace.Append(b)); } } export class DrawWineRack2 implements Command @@ -24,8 +31,11 @@ export class DrawWineRack2 implements Command await selectSpace.Select(); if (!selectSpace.ParseOK) return; + if (!userConfig.winerackConfig) + await userConfigStore.InitWinerackConfig(); let space = selectSpace.SpaceParse; const tool = DrawBlisWineRackTool.GetInstance() as DrawBlisWineRackTool; - tool.Draw(space); + tool.Parse(space, userConfig.winerackConfig); + tool.boardlist.forEach(b => app.Database.ModelSpace.Append(b)); } } diff --git a/src/Add-on/Mirror.ts b/src/Add-on/Mirror.ts index b85cc1338..b8760a83a 100644 --- a/src/Add-on/Mirror.ts +++ b/src/Add-on/Mirror.ts @@ -4,16 +4,9 @@ import { Command } from "../Editor/CommandMachine"; import { JigUtils } from "../Editor/JigUtils"; import { PromptStatus } from "../Editor/PromptResult"; import { MoveMatrix } from "../Geometry/GeUtils"; +import { GetMirrorMat } from "../Common/Matrix4Utils"; + -export function GetMirrorMat(v: Vector3) -{ - let mirrorMat = new Matrix4(); - let xAxis = new Vector3(1 - 2 * v.x ** 2, -2 * v.x * v.y, -2 * v.x * v.z); - let yAxis = new Vector3(-2 * v.x * v.y, 1 - 2 * v.y ** 2, -2 * v.y * v.z); - let zAxis = new Vector3(-2 * v.x * v.z, -2 * v.y * v.z, 1 - 2 * v.z ** 2); - mirrorMat.makeBasis(xAxis, yAxis, zAxis); - return mirrorMat; -} export class MirrorCommand implements Command { async exec() diff --git a/src/Common/Matrix4Utils.ts b/src/Common/Matrix4Utils.ts index 46f58896b..7697d9bed 100644 --- a/src/Common/Matrix4Utils.ts +++ b/src/Common/Matrix4Utils.ts @@ -94,3 +94,12 @@ export function Vector2ApplyMatrix4(mtx: Matrix4, vec: Vector2) vec.x = cacheVec.x; vec.y = cacheVec.y; } +export function GetMirrorMat(v: Vector3) +{ + let mirrorMat = new Matrix4(); + let xAxis = new Vector3(1 - 2 * v.x ** 2, -2 * v.x * v.y, -2 * v.x * v.z); + let yAxis = new Vector3(-2 * v.x * v.y, 1 - 2 * v.y ** 2, -2 * v.y * v.z); + let zAxis = new Vector3(-2 * v.x * v.z, -2 * v.y * v.z, 1 - 2 * v.z ** 2); + mirrorMat.makeBasis(xAxis, yAxis, zAxis); + return mirrorMat; +} diff --git a/src/Editor/UserConfig.ts b/src/Editor/UserConfig.ts index 8fb7c8380..f4ea12f2d 100644 --- a/src/Editor/UserConfig.ts +++ b/src/Editor/UserConfig.ts @@ -2,6 +2,7 @@ import { RenderType } from "../GraphicsSystem/RenderType"; import { DrillingOption } from "../UI/Store/drillInterface"; import { observable } from "mobx"; import { StoreageKeys } from "../Common/KeyEnum"; +import { IWineRackOption } from "../UI/Store/WineRackInterface"; /** * //TODO:保存用户的配置,先保存在sessionStroage @@ -12,9 +13,10 @@ export class UserConfig @observable maxHeight = 2440; @observable maxWidth = 1220; isContinuousDraw = false; //是否连续绘制层板立板背板... - @observable _drillConfigs: Map = new Map(); + @observable private _drillConfigs: Map = new Map(); @observable openDrillingReactor = true; @observable openAutoCuttingReactor = true; + winerackConfig: IWineRackOption; constructor() { this.Init(); diff --git a/src/Geometry/DrillParse/BoardGetFace.ts b/src/Geometry/DrillParse/BoardGetFace.ts index c4496de1b..a807347f2 100644 --- a/src/Geometry/DrillParse/BoardGetFace.ts +++ b/src/Geometry/DrillParse/BoardGetFace.ts @@ -1,6 +1,5 @@ import { Matrix4, Vector3 } from "three"; -import { GetMirrorMat } from "../../Add-on/Mirror"; -import { matrixIsCoplane } from "../../Common/Matrix4Utils"; +import { matrixIsCoplane, GetMirrorMat } from "../../Common/Matrix4Utils"; import { Board } from "../../DatabaseServices/Entity/Board"; import { Curve } from "../../DatabaseServices/Entity/Curve"; import { Region } from "../../DatabaseServices/Entity/Region"; diff --git a/src/UI/Components/Board/WineRack.tsx b/src/UI/Components/Board/WineRack.tsx index 1de6b0862..866f42161 100644 --- a/src/UI/Components/Board/WineRack.tsx +++ b/src/UI/Components/Board/WineRack.tsx @@ -14,6 +14,7 @@ import { UserConfig } from './UserConfig'; import { AppToaster } from '../Toaster'; import { KeyBoard } from '../../../Common/KeyEnum'; import { FixedNotZero } from '../../../Common/Utils'; +import { userConfig } from '../../../Editor/UserConfig'; @inject("store") @observer @@ -33,6 +34,7 @@ export class WineRackModal extends React.Component<{ store?: WineRackStore }, {} else { app.Editor.ModalManage.Clear(); + userConfig.winerackConfig = this.props.store.m_Option; if (this.props.store.m_Option.type === EWineRackType.Upright) commandMachine.ExecCommand("DRAWWINERACK"); else diff --git a/src/UI/Store/UserConfigStore.ts b/src/UI/Store/UserConfigStore.ts index b86109393..5a785af0c 100644 --- a/src/UI/Store/UserConfigStore.ts +++ b/src/UI/Store/UserConfigStore.ts @@ -11,6 +11,8 @@ import { IConfigStore } from "./BoardStore"; import { BoardProcessOption, BehindBoardOption, BehindHeightPositon, LinesType, BrRelativePos, IGrooveOption } from "./BoardInterface"; import { EBoardKeyList } from "../../Common/BoardKeyList"; import { DrillStore } from "./DrillStore"; +import { IWineRackOption } from "./WineRackInterface"; +import { WineRackStore } from "./WineRackStore"; type BehindConfigType = { option: BehindBoardOption, processData: BoardProcessOption, grooveData: IGrooveOption }; @@ -89,6 +91,14 @@ export class UserConfigStore extends Singleton else await userConfigStore.SaveConfig(BoardModalType.Dr, DrillStore.GetInstance(), true); } + async InitWinerackConfig() + { + let config = await this.GetConfig(BoardModalType.JG); + if (config) + userConfig.winerackConfig = config.option as IWineRackOption; + else + await userConfigStore.SaveConfig(BoardModalType.JG, WineRackStore.GetInstance(), true); + } async GetConfig(type: BoardModalType): Promise { let configs = await this.GetAllConfigs(type); @@ -167,8 +177,7 @@ export class UserConfigStore extends Singleton timeout: 1000 }); localStorage.setItem("configName_" + type, name); - if (type === BoardModalType.Dr) - userConfig.DrillConfigs = newConfig.ruleMap; + this.UpdateUserConfig(type, newConfig); } } //删除配置 @@ -205,8 +214,7 @@ export class UserConfigStore extends Singleton await this.UpdateBoardOption(newName, type, store); localStorage.setItem("configName_" + type, newName); - if (type === BoardModalType.Dr) - userConfig.DrillConfigs = configs[newName].ruleMap; + this.UpdateUserConfig(type, configs[newName]); } else { @@ -225,12 +233,16 @@ export class UserConfigStore extends Singleton { store.UpdateOption(conf); localStorage.setItem("configName_" + type, k); - if (type === BoardModalType.Dr) - { - userConfig.DrillConfigs = conf.ruleMap; - } + this.UpdateUserConfig(type, conf); } } + private UpdateUserConfig(type: BoardModalType, newConfig: IConfigOption) + { + if (type === BoardModalType.Dr) + userConfig.DrillConfigs = newConfig.ruleMap; + else if (type === BoardModalType.JG) + userConfig.winerackConfig = newConfig.option as IWineRackOption; + } }