mirror of https://gitee.com/cf-fz/WebCAD.git
!495 顶底板模块
parent
c3d1b9c9c4
commit
43d91f2179
@ -0,0 +1,150 @@
|
||||
import { Vector3 } from "three";
|
||||
import { Board, BoardType } from "../../DatabaseServices/Entity/Board";
|
||||
import { MoveMatrix } from "../../Geometry/GeUtils";
|
||||
import { ISpaceParse } from "../../Geometry/SpaceParse/ISpaceParse";
|
||||
import { TBBoardOption } from "../../UI/Store/BoardInterface";
|
||||
|
||||
export function BuildTopBottomBoards(topOpt: TBBoardOption, bottomOpt: TBBoardOption, space: ISpaceParse)
|
||||
{
|
||||
let brs: Board[] = [];
|
||||
if (topOpt.isDraw)
|
||||
{
|
||||
let basePt = GetTopBoardBasePt(topOpt, space);
|
||||
brs.push(GetTopOrDownBoard(space, topOpt, basePt, true));
|
||||
}
|
||||
if (bottomOpt.isDraw)
|
||||
{
|
||||
let basePt = GetBottomBoardBasePt(bottomOpt, space);
|
||||
brs.push(GetTopOrDownBoard(space, bottomOpt, basePt, false));
|
||||
|
||||
let size = space.Size;
|
||||
let refSize = size.y;
|
||||
const thickness = bottomOpt.footThickness;
|
||||
|
||||
//绘制前地脚
|
||||
if (bottomOpt.isDrawFooter && !bottomOpt.isWrapSide)
|
||||
{
|
||||
brs.push(GetFootBoard(bottomOpt, space, false));
|
||||
refSize -= thickness + bottomOpt.footBehindShrink;
|
||||
}
|
||||
|
||||
//绘制后地脚
|
||||
if (bottomOpt.isDrawBackFooter && !bottomOpt.isWrapSide)
|
||||
{
|
||||
brs.push(GetFootBoard(bottomOpt, space, true));
|
||||
refSize -= thickness + bottomOpt.footerOffset;
|
||||
}
|
||||
//绘制加强条
|
||||
brs.push(...GetStrengthenStrips(bottomOpt, space, refSize));
|
||||
}
|
||||
return brs;
|
||||
}
|
||||
function GetTopOrDownBoard(spaceParse: ISpaceParse, opt: TBBoardOption, basePt: Vector3, isTop = true)
|
||||
{
|
||||
//前
|
||||
let frontDist = opt.frontDist;
|
||||
//左右延伸
|
||||
let leftExt = opt.leftExt;
|
||||
let rightExt = opt.rightExt;
|
||||
|
||||
//大小
|
||||
let size = spaceParse.Size;
|
||||
let length = size.x;
|
||||
let width = size.y + frontDist + opt.behindDistance;
|
||||
let thickness = opt.thickness;
|
||||
if (opt.isWrapSide)
|
||||
{
|
||||
let leftBoardThickness = spaceParse.LeftBoard ? spaceParse.LeftBoard.Thickness : opt.thickness;
|
||||
let rightBoardThickness = spaceParse.RightBoard ? spaceParse.RightBoard.Thickness : opt.thickness;
|
||||
length += leftBoardThickness + rightBoardThickness + leftExt + rightExt;
|
||||
}
|
||||
else
|
||||
{
|
||||
leftExt = 0;
|
||||
rightExt = 0;
|
||||
}
|
||||
|
||||
let board = Board.CreateBoard(length, width, thickness, BoardType.Layer);
|
||||
board.Name = "顶板";
|
||||
|
||||
if (!isTop)
|
||||
{
|
||||
board.Name = "底板";
|
||||
}
|
||||
//移动右缩和前距的距离
|
||||
basePt.add(new Vector3(rightExt, -frontDist));
|
||||
board.ApplyMatrix(MoveMatrix(basePt));
|
||||
board.ApplyMatrix(spaceParse.SpaceOCS);
|
||||
|
||||
return board;
|
||||
}
|
||||
function GetTopBoardBasePt(opt: TBBoardOption, spc: ISpaceParse)
|
||||
{
|
||||
let box = spc.SpaceBox;
|
||||
let min = box.min;
|
||||
let max = box.max;
|
||||
let basePoint = new Vector3();
|
||||
if (opt.isWrapSide)
|
||||
{
|
||||
let rightBoardThickness = spc.RightBoard ? spc.RightBoard.Thickness : opt.thickness;
|
||||
basePoint.set(max.x + rightBoardThickness, min.y, max.z);
|
||||
}
|
||||
else
|
||||
{
|
||||
basePoint.set(max.x, min.y, max.z - (opt.thickness + opt.offset));
|
||||
}
|
||||
return basePoint;
|
||||
}
|
||||
function GetBottomBoardBasePt(opt: TBBoardOption, spc: ISpaceParse)
|
||||
{
|
||||
let box = spc.SpaceBox;
|
||||
let min = box.min;
|
||||
let max = box.max;
|
||||
let basePoint = new Vector3();
|
||||
if (opt.isWrapSide)
|
||||
{
|
||||
let rightBoardThickness = spc.RightBoard ? spc.RightBoard.Thickness : opt.thickness;
|
||||
basePoint.set(max.x + rightBoardThickness, min.y, min.z - opt.thickness);
|
||||
}
|
||||
else
|
||||
{
|
||||
basePoint.set(max.x, min.y, min.z + opt.offset);
|
||||
}
|
||||
return basePoint;
|
||||
}
|
||||
function GetFootBoard(opt: TBBoardOption, spaceParse: ISpaceParse, isBack: boolean)
|
||||
{
|
||||
let offset = opt.offset;
|
||||
if (offset > 0)
|
||||
{
|
||||
let thickness = opt.footThickness;
|
||||
let footBoard = Board.CreateBoard(offset, spaceParse.Size.x, opt.footThickness, BoardType.Behind);
|
||||
footBoard.Name = isBack ? "后地脚" : "地脚线";
|
||||
let moveDist = isBack ? spaceParse.Size.y - opt.footerOffset : thickness + opt.footBehindShrink;
|
||||
footBoard.ApplyMatrix(MoveMatrix(spaceParse.SpaceBox.min.clone().add(new Vector3(0, moveDist))))
|
||||
.ApplyMatrix(spaceParse.SpaceOCS);
|
||||
|
||||
return footBoard;
|
||||
}
|
||||
}
|
||||
|
||||
function GetStrengthenStrips(opt: TBBoardOption, spaceParse: ISpaceParse, width: number)
|
||||
{
|
||||
let brs: Board[] = [];
|
||||
if (opt.isDrawStrengthenStrip && !opt.isWrapSide && opt.offset > 0)
|
||||
{
|
||||
const thickness = opt.footThickness;
|
||||
let count = opt.divCount;
|
||||
let spaceSize = (spaceParse.Size.x - count * thickness) / (count + 1);
|
||||
let br = Board.CreateBoard(opt.offset, width, thickness, BoardType.Vertical);
|
||||
for (let i = 1; i <= count; i++)
|
||||
{
|
||||
let b = br.Clone();
|
||||
b.Name = "加强条" + i;
|
||||
b.ApplyMatrix(MoveMatrix(spaceParse.SpaceBox.min.clone().add(new Vector3(spaceSize * i + (i - 1) * thickness, thickness + opt.footBehindShrink))))
|
||||
.ApplyMatrix(spaceParse.SpaceOCS);
|
||||
brs.push(b);
|
||||
}
|
||||
}
|
||||
return brs;
|
||||
}
|
@ -0,0 +1,245 @@
|
||||
import { Vector3 } from "three";
|
||||
import { BuildTopBottomBoards } from "../../../Add-on/DrawBoard/BuildTopBottomBoardTool";
|
||||
import { app } from "../../../ApplicationServices/Application";
|
||||
import { EBoardKeyList } from "../../../Common/BoardKeyList";
|
||||
import { DefaultBottomBoardOption, DefaultTopBoardOption } from "../../../Editor/DefaultConfig";
|
||||
import { Box3Ext } from "../../../Geometry/Box";
|
||||
import { ISpaceParse } from "../../../Geometry/SpaceParse/ISpaceParse";
|
||||
import { BoardProcessOption, ComposingType, FaceDirection, LinesType, TBBoardOption } from "../../../UI/Store/BoardInterface";
|
||||
import { AutoRecord } from "../../AutoRecord";
|
||||
import { CADFiler } from "../../CADFiler";
|
||||
import { Board } from "../../Entity/Board";
|
||||
import { TemplateRecord } from "../TemplateRecord";
|
||||
|
||||
/**顶底板模板 */
|
||||
export class TemplateTopBottomBoard extends TemplateRecord
|
||||
{
|
||||
private _topOption: TBBoardOption;
|
||||
private _bottomOption: TBBoardOption;
|
||||
UseBoardProcessOption = false;
|
||||
BoardProcessOption: BoardProcessOption;
|
||||
@AutoRecord DrawCounts: [number, number, number] = [1, 1, 1]
|
||||
constructor()
|
||||
{
|
||||
super();
|
||||
this.name = "顶底板";
|
||||
}
|
||||
get TopOption()
|
||||
{
|
||||
return Object.assign({}, this._topOption);
|
||||
}
|
||||
set TopOption(option: TBBoardOption)
|
||||
{
|
||||
//@ts-ignore
|
||||
if (!this._topOption) this._topOption = {};
|
||||
|
||||
this.WriteAllObjectRecord();
|
||||
Object.assign(this._topOption, option);
|
||||
}
|
||||
get BottomOption()
|
||||
{
|
||||
return Object.assign({}, this._bottomOption);
|
||||
}
|
||||
set BottomOption(option: TBBoardOption)
|
||||
{
|
||||
//@ts-ignore
|
||||
if (!this._bottomOption) this._bottomOption = {};
|
||||
|
||||
this.WriteAllObjectRecord();
|
||||
Object.assign(this._bottomOption, option);
|
||||
}
|
||||
InitBaseParams()
|
||||
{
|
||||
super.InitBaseParams();
|
||||
this._topOption = Object.assign({}, DefaultTopBoardOption);
|
||||
this._bottomOption = Object.assign({}, DefaultBottomBoardOption);
|
||||
return this;
|
||||
}
|
||||
protected async Update()
|
||||
{
|
||||
await super.Update();
|
||||
let space = new ISpaceParse();
|
||||
space.SpaceOCS = this._CacheSpaceCS;
|
||||
space.ParseOK = true;
|
||||
space.SpaceBox = new Box3Ext(new Vector3(), this._CacheSpaceSize);
|
||||
let nbrs = BuildTopBottomBoards(this._topOption, this._bottomOption, space);
|
||||
|
||||
let sbrs = this.PositioningSupportBoards;
|
||||
|
||||
if (this.BoardProcessOption)
|
||||
{
|
||||
for (let br of nbrs)
|
||||
{
|
||||
br.BoardProcessOption = this.BoardProcessOption;
|
||||
this.SetBoardProcess(br);
|
||||
}
|
||||
this.BoardProcessOption = undefined;
|
||||
}
|
||||
if (this.UseBoardProcessOption && sbrs.length > 0)
|
||||
{
|
||||
let cname = sbrs[0].BoardProcessOption[EBoardKeyList.CabinetName];
|
||||
let rname = sbrs[0].BoardProcessOption[EBoardKeyList.RoomName];
|
||||
for (let br of nbrs)
|
||||
{
|
||||
br.BoardProcessOption[EBoardKeyList.CabinetName] = cname;
|
||||
br.BoardProcessOption[EBoardKeyList.RoomName] = rname;
|
||||
}
|
||||
|
||||
this.UseBoardProcessOption = false;
|
||||
}
|
||||
|
||||
let oldBrss: [Board[], Board[], Board[]] = [[], [], []];
|
||||
for (let id of this.Objects)
|
||||
{
|
||||
let b = id.Object as Board;
|
||||
oldBrss[b.BoardType].push(b);
|
||||
}
|
||||
let newBrss: [Board[], Board[], Board[]] = [[], [], []];
|
||||
|
||||
for (let b of nbrs)
|
||||
{
|
||||
newBrss[b.BoardType].push(b);
|
||||
}
|
||||
for (let i = 0; i < oldBrss.length; i++)
|
||||
{
|
||||
let oldBrs = oldBrss[i];
|
||||
let newBrs = newBrss[i];
|
||||
let refBr: Board;
|
||||
if (oldBrs.length > 0)
|
||||
refBr = oldBrs[0];
|
||||
|
||||
let oldLen = oldBrs.length;
|
||||
for (let j = newBrs.length; j < oldLen; j++)
|
||||
oldBrs[j].Erase();
|
||||
|
||||
for (let j = 0; j < newBrs.length; j++)
|
||||
{
|
||||
if (j < oldLen)
|
||||
{
|
||||
if (j >= this.DrawCounts[i])
|
||||
{
|
||||
oldBrs[j].Erase(false);
|
||||
}
|
||||
oldBrs[j].Name = newBrs[j].Name;
|
||||
oldBrs[j].Position = newBrs[j].Position;
|
||||
oldBrs[j].Width = newBrs[j].Width;
|
||||
oldBrs[j].Height = newBrs[j].Height;
|
||||
oldBrs[j].Thickness = newBrs[j].Thickness;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (refBr)
|
||||
{
|
||||
newBrs[j].BoardProcessOption = refBr.BoardProcessOption;
|
||||
this.SetBoardProcess(newBrs[j]);
|
||||
}
|
||||
app.Database.ModelSpace.Append(newBrs[j]);
|
||||
this.Objects.push(newBrs[j].Id);
|
||||
}
|
||||
}
|
||||
this.DrawCounts[i] = newBrs.length;
|
||||
}
|
||||
}
|
||||
private SetBoardProcess(br: Board)
|
||||
{
|
||||
if (br.Name === "底板")
|
||||
{
|
||||
br.BoardProcessOption[EBoardKeyList.BigHole] = FaceDirection.Back;
|
||||
}
|
||||
else if (br.Name.includes("地脚"))
|
||||
{
|
||||
br.BoardProcessOption.lines = LinesType.Reverse;
|
||||
br.BoardProcessOption.composingFace = ComposingType.Reverse;
|
||||
br.BoardProcessOption.bigHoleDir = FaceDirection.Back;
|
||||
br.BoardProcessOption.lines = LinesType.Reverse;
|
||||
}
|
||||
else if (br.Name.includes("加强条"))
|
||||
{
|
||||
br.BoardProcessOption.lines = LinesType.Reverse;
|
||||
br.BoardProcessOption.composingFace = ComposingType.Reverse;
|
||||
br.BoardProcessOption.bigHoleDir = FaceDirection.Back;
|
||||
br.BoardProcessOption.lines = LinesType.Reverse;
|
||||
}
|
||||
}
|
||||
ReadFile(file: CADFiler)
|
||||
{
|
||||
let ver = file.Read();
|
||||
super.ReadFile(file);
|
||||
this.DrawCounts[0] = file.Read();
|
||||
this.DrawCounts[1] = file.Read();
|
||||
this.DrawCounts[2] = file.Read();
|
||||
|
||||
this._topOption = {} as any;
|
||||
this._topOption.type = file.Read();
|
||||
this._topOption.name = file.Read();
|
||||
this._topOption.isDraw = file.Read();
|
||||
this._topOption.thickness = file.Read();
|
||||
this._topOption.frontDist = file.Read();
|
||||
this._topOption.behindDistance = file.Read();
|
||||
this._topOption.isWrapSide = file.Read();
|
||||
this._topOption.useLFData = file.Read();
|
||||
this._topOption.leftExt = file.Read();
|
||||
this._topOption.rightExt = file.Read();
|
||||
this._topOption.offset = file.Read();
|
||||
|
||||
this._bottomOption = {} as any;
|
||||
this._bottomOption.type = file.Read();
|
||||
this._bottomOption.name = file.Read();
|
||||
this._bottomOption.isDraw = file.Read();
|
||||
this._bottomOption.thickness = file.Read();
|
||||
this._bottomOption.frontDist = file.Read();
|
||||
this._bottomOption.behindDistance = file.Read();
|
||||
this._bottomOption.isWrapSide = file.Read();
|
||||
this._bottomOption.useLFData = file.Read();
|
||||
this._bottomOption.leftExt = file.Read();
|
||||
this._bottomOption.rightExt = file.Read();
|
||||
this._bottomOption.offset = file.Read();
|
||||
this._bottomOption.footThickness = file.Read();
|
||||
this._bottomOption.isDrawFooter = file.Read();
|
||||
this._bottomOption.footBehindShrink = file.Read();
|
||||
this._bottomOption.isDrawBackFooter = file.Read();
|
||||
this._bottomOption.isDrawStrengthenStrip = file.Read();
|
||||
this._bottomOption.footerOffset = file.Read();
|
||||
this._bottomOption.divCount = file.Read();
|
||||
|
||||
}
|
||||
WriteFile(file: CADFiler)
|
||||
{
|
||||
file.Write(1);
|
||||
super.WriteFile(file);
|
||||
file.Write(this.DrawCounts[0]);
|
||||
file.Write(this.DrawCounts[1]);
|
||||
file.Write(this.DrawCounts[2]);
|
||||
|
||||
file.Write(this._topOption.type);
|
||||
file.Write(this._topOption.name);
|
||||
file.Write(this._topOption.isDraw);
|
||||
file.Write(this._topOption.thickness);
|
||||
file.Write(this._topOption.frontDist);
|
||||
file.Write(this._topOption.behindDistance);
|
||||
file.Write(this._topOption.isWrapSide);
|
||||
file.Write(this._topOption.useLFData);
|
||||
file.Write(this._topOption.leftExt);
|
||||
file.Write(this._topOption.rightExt);
|
||||
file.Write(this._topOption.offset);
|
||||
|
||||
file.Write(this._bottomOption.type);
|
||||
file.Write(this._bottomOption.name);
|
||||
file.Write(this._bottomOption.isDraw);
|
||||
file.Write(this._bottomOption.thickness);
|
||||
file.Write(this._bottomOption.frontDist);
|
||||
file.Write(this._bottomOption.behindDistance);
|
||||
file.Write(this._bottomOption.isWrapSide);
|
||||
file.Write(this._bottomOption.useLFData);
|
||||
file.Write(this._bottomOption.leftExt);
|
||||
file.Write(this._bottomOption.rightExt);
|
||||
file.Write(this._bottomOption.offset);
|
||||
file.Write(this._bottomOption.footThickness);
|
||||
file.Write(this._bottomOption.isDrawFooter);
|
||||
file.Write(this._bottomOption.footBehindShrink);
|
||||
file.Write(this._bottomOption.isDrawBackFooter);
|
||||
file.Write(this._bottomOption.isDrawStrengthenStrip);
|
||||
file.Write(this._bottomOption.footerOffset);
|
||||
file.Write(this._bottomOption.divCount);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue