mirror of https://gitee.com/cf-fz/WebCAD.git
!2429 拆单增加保存图纸文件,mes可调用分享图纸界面展示图形
parent
2705367ddf
commit
eae63a98b4
@ -0,0 +1,175 @@
|
||||
import { Matrix4, Vector2, Vector3 } from "three";
|
||||
import { ExtrudeHole } from "../../DatabaseServices/3DSolid/ExtrudeHole";
|
||||
import { Board } from "../../DatabaseServices/Entity/Board";
|
||||
import { LinesType } from "../../DatabaseServices/Entity/BoardInterface";
|
||||
import { Circle } from "../../DatabaseServices/Entity/Circle";
|
||||
import { ExtrudeSolid } from "../../DatabaseServices/Entity/Extrude";
|
||||
import { Polyline } from "../../DatabaseServices/Entity/Polyline";
|
||||
import { JigUtils } from "../../Editor/JigUtils";
|
||||
import { boardUVGenerator2 } from "../../Geometry/BoardUVGenerator";
|
||||
|
||||
function getVec(data: object): Vector3
|
||||
{
|
||||
return new Vector3(data["x"], data["y"], data["z"]);
|
||||
}
|
||||
enum BoardType
|
||||
{
|
||||
Layer = 0,
|
||||
Vertical = 1,
|
||||
Behind = 2
|
||||
}
|
||||
export class SimpleBoard
|
||||
{
|
||||
BoardName: string;
|
||||
boardPts: any[];
|
||||
boardBuls: any[];
|
||||
xD: Vector3;
|
||||
yD: Vector3;
|
||||
zD: Vector3;
|
||||
height: number;
|
||||
width: number;
|
||||
thickness: number;
|
||||
pBase: Vector3;
|
||||
SubBoardLocal: any[];
|
||||
Drillings: any[];
|
||||
DataID: number;
|
||||
_BoardType: BoardType;
|
||||
_CustomNumber: string;
|
||||
RoomName: string = '';
|
||||
BoxName: string = '';
|
||||
Wave: number = 0;
|
||||
PaiKong: number = 0;
|
||||
HoleFace: number = 0;
|
||||
SealedDown: number = 0;
|
||||
SealedLeft: number = 0;
|
||||
SealedUp: number = 0;
|
||||
SealedRight: number = 0;
|
||||
Color: string = '';
|
||||
Material: string = '';
|
||||
MaterialName: string = '';
|
||||
BlockNo: string = '';
|
||||
constructor(boardData: any)
|
||||
{
|
||||
this.boardPts = boardData["Pts"];
|
||||
this.boardBuls = boardData["Buls"];
|
||||
this.pBase = getVec(boardData["BasePoint"]);
|
||||
|
||||
this.xD = getVec(boardData["XVec"]);
|
||||
this.yD = getVec(boardData["YVec"]);
|
||||
this.zD = getVec(boardData["ZVec"]);
|
||||
this.SubBoardLocal = boardData["SubBoardLocal"] ?? [];
|
||||
this.Drillings = boardData["Drillings"] ?? [];
|
||||
this.height = boardData["L"];
|
||||
this.width = boardData["W"];
|
||||
this.thickness = boardData["H"];
|
||||
this.BoardName = boardData["BoardName"];
|
||||
this.DataID = boardData['DataID'];
|
||||
this._BoardType = boardData['BoardType'];
|
||||
this._CustomNumber = boardData['CustomNumber'];
|
||||
this.RoomName = boardData['RoomName'];
|
||||
this.BoxName = boardData['BoxName'];
|
||||
this.Color = boardData['Color'];
|
||||
this.Material = boardData['Material'];
|
||||
this.MaterialName = boardData['MaterialName'];
|
||||
this.SealedDown = boardData['SealedDown'];
|
||||
this.SealedUp = boardData['SealedUp'];
|
||||
this.SealedLeft = boardData['SealedLeft'];
|
||||
this.SealedRight = boardData['SealedRight'];
|
||||
this.BlockNo = boardData['BlockNo'];
|
||||
}
|
||||
//生成板的拉伸实体
|
||||
public Conver2Ext(): ExtrudeSolid
|
||||
{
|
||||
let pts: Vector2[] = [];
|
||||
let buls: number[] = [];
|
||||
let boardMat = new Matrix4();
|
||||
let matInv: Matrix4 = new Matrix4();
|
||||
this.pBase.add(this.zD.clone().multiplyScalar(-this.thickness));
|
||||
boardMat.makeBasis(this.xD, this.yD, this.zD);
|
||||
boardMat.setPosition(this.pBase);
|
||||
matInv.getInverse(boardMat);
|
||||
if (this.boardPts && this.boardPts.length !== 0)
|
||||
for (let i = 0; i < this.boardPts.length; i++)
|
||||
{
|
||||
let pt = getVec(this.boardPts[i]);
|
||||
if (this.boardPts[i].z !== undefined)
|
||||
pt.applyMatrix4(matInv);
|
||||
pts.push(new Vector2(pt.x, pt.y));
|
||||
buls.push(this.boardBuls[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
pts.push(new Vector2(0, 0),
|
||||
new Vector2(this.width, 0),
|
||||
new Vector2(this.width, this.height),
|
||||
new Vector2(0, this.height),
|
||||
new Vector2(0, 0)
|
||||
);
|
||||
buls.push(0, 0, 0, 0, 0);
|
||||
}
|
||||
let ext = new ExtrudeSolid();
|
||||
ext.OCSNoClone.copy(boardMat);
|
||||
let pl = new Polyline(pts.map((p, i) => { return { pt: p, bul: buls[i] }; }));
|
||||
ext.Thickness = this.thickness;
|
||||
ext.ContourCurve = pl;
|
||||
if (this.SubBoardLocal.length > 0)
|
||||
ext.Grooves.push(...this.SubBoardLocal.map(sub => new SimpleBoard(sub).Conver2Ext()));
|
||||
return ext;
|
||||
}
|
||||
//创建Board实体
|
||||
createBoardEntity()
|
||||
{
|
||||
let board = Board.CreateBoard(this.height, this.width, this.thickness, this._BoardType);
|
||||
board.BoardProcessOption.roomName = this.RoomName;
|
||||
board.BoardProcessOption.cabinetName = this.BoxName;
|
||||
const waveMap = { 0: LinesType.Positive, 1: LinesType.CanReversal, 2: LinesType.Reverse };
|
||||
board.BoardProcessOption.lines = waveMap[this.Wave];
|
||||
board.BoardProcessOption.composingFace = this.PaiKong;
|
||||
board.BoardProcessOption.bigHoleDir = this.HoleFace;
|
||||
board.BoardProcessOption.sealedDown = this.SealedDown.toString();
|
||||
board.BoardProcessOption.sealedLeft = this.SealedLeft.toString();
|
||||
board.BoardProcessOption.sealedUp = this.SealedUp.toString();
|
||||
board.BoardProcessOption.sealedRight = this.SealedRight.toString();
|
||||
board.BoardProcessOption.color = this.Color;
|
||||
board.BoardProcessOption.material = this.Material;
|
||||
board.BoardProcessOption.boardName = this.MaterialName;
|
||||
const bp = this.pBase.add(this.zD.clone().multiplyScalar(-this.thickness));
|
||||
board.OCS = new Matrix4().makeBasis(this.xD, this.yD, this.zD).setPosition(bp);
|
||||
const groove = this.Conver2Ext();
|
||||
board.ContourCurve = groove.ContourCurve;
|
||||
board.AppendGrooves(groove.Grooves);
|
||||
let ext = this.Conver2Ext();
|
||||
if (this.BoardName === "地脚线")
|
||||
Object.defineProperty(ext, "UCGenerator",
|
||||
{
|
||||
get: function ()
|
||||
{
|
||||
return boardUVGenerator2;
|
||||
},
|
||||
});
|
||||
|
||||
//孔位处理
|
||||
let holes: ExtrudeHole[] = [];
|
||||
if (this.Drillings.length > 0)
|
||||
{
|
||||
let dris = this.Drillings;
|
||||
for (let dri of dris)
|
||||
{
|
||||
let hole = JigUtils.Draw(new ExtrudeHole());
|
||||
let p: Vector3;
|
||||
if (dri.f === 0) //0正
|
||||
p = new Vector3(dri.x, dri.y, -dri.h + this.thickness);
|
||||
else //1反
|
||||
p = new Vector3(dri.x, dri.y, 0);
|
||||
const circle = new Circle(new Vector3(), dri.r);
|
||||
circle.Position = p;
|
||||
circle.ApplyMatrix(board.OCS);
|
||||
hole.ContourCurve = circle;
|
||||
hole.Height = dri.h;
|
||||
hole.ColorIndex = 1;
|
||||
holes.push(hole);
|
||||
}
|
||||
}
|
||||
return { board, holes };
|
||||
}
|
||||
}
|
Loading…
Reference in new issue