顶底板空间分析

pull/93/head
Zoe 6 years ago
parent dc49453a90
commit 65e83b8758

@ -19,10 +19,14 @@ export class DrawLeftRight implements Command
if (state === ModalState.Ok)
{
let data = sideBoardStore.boardOption;
let leftBarod = Board.CreateBoard(data.height, data.width, data.thickness, BoardType.Vertical)
let rightBoard = Board.CreateBoard(data.height, data.width, data.thickness, BoardType.Vertical);
rightBoard.ApplyMatrix(MoveMatrix(new Vector3(data.spacing + data.thickness)));
let lenght = data.lenght ? parseFloat(data.lenght) : 0;
let width = data.width ? parseFloat(data.width) : 0;
let thickness = data.thickness ? parseFloat(data.thickness) : 0;
let spacing = data.spacing ? parseFloat(data.spacing) : 0;
let leftBarod = Board.CreateBoard(lenght, width, thickness, BoardType.Vertical)
let rightBoard = Board.CreateBoard(lenght, width, thickness, BoardType.Vertical);
rightBoard.ApplyMatrix(MoveMatrix(new Vector3(spacing + thickness)));
app.m_Database.ModelSpace.Append(leftBarod);
app.m_Database.ModelSpace.Append(rightBoard);

@ -5,6 +5,7 @@ import { PromptStatus } from '../Editor/PromptResult';
import { MoveMatrix } from '../Geometry/GeUtils';
import { TopAndBottomSpaceParse } from '../Geometry/SpaceParse';
import { ModalState, TopBottomBoardStore } from '../UI/Store/BoardStore';
import { Matrix4, Vector3 } from 'three';
export class DrawTopBottomBoard implements Command
{
@ -20,6 +21,9 @@ export class DrawTopBottomBoard implements Command
if (boardCus.length === 2)
{
let spaceParse = new TopAndBottomSpaceParse(boardCus);
await spaceParse.SpaceParse();
if (spaceParse.IsVail)
{
app.m_Editor.m_ModalManage.RenderTopBottomBoard();
@ -29,11 +33,21 @@ export class DrawTopBottomBoard implements Command
{
let opt = store.boardOption;
let topBarod = Board.CreateBoard(spaceParse.SpaceLength, spaceParse.SpaceWidth - opt.forwardDistance + opt.behindDistance, opt.thickness, BoardType.Layer)
let topBarod: Board;
topBarod.ApplyMatrix(MoveMatrix(spaceParse.BasePoint));
topBarod.ApplyMatrix(spaceParse.OCS);
if (opt.isTopWrapSide)
{
topBarod = Board.CreateBoard(spaceParse.TotalLength, spaceParse.SpaceWidth - parseFloat(opt.forwardDistance) + parseFloat(opt.behindDistance), parseFloat(opt.thickness), BoardType.Layer);
spaceParse.BaseTopUpPoint.add(new Vector3(0, 0, parseFloat(opt.thickness)));
topBarod.ApplyMatrix(MoveMatrix(spaceParse.BaseTopUpPoint));
}
else
{
topBarod = Board.CreateBoard(spaceParse.SpaceLength, spaceParse.SpaceWidth - parseFloat(opt.forwardDistance) + parseFloat(opt.behindDistance), parseFloat(opt.thickness), BoardType.Layer)
topBarod.ApplyMatrix(MoveMatrix(spaceParse.BaseTopDownPoint));
}
topBarod.ApplyMatrix(new Matrix4().extractRotation(spaceParse.OCS))
app.m_Database.ModelSpace.Append(topBarod);
}
}

@ -25,9 +25,9 @@ export class Test implements Command
b1.ApplyMatrix(MoveMatrix(new Vector3(10, 10, 10)))
b2.ApplyMatrix(MoveMatrix(new Vector3(10, 10, 10)))
b3.ApplyMatrix(MoveMatrix(new Vector3(10, 10, 10)))
// b1.ApplyMatrix(rotate)
// b2.ApplyMatrix(rotate)
// b3.ApplyMatrix(rotate)
b1.ApplyMatrix(rotate)
b2.ApplyMatrix(rotate)
b3.ApplyMatrix(rotate)
app.m_Database.ModelSpace.Append(b1);
app.m_Database.ModelSpace.Append(b2);
@ -35,12 +35,12 @@ export class Test implements Command
// console.log(b1.MinPoint);
// console.log(b2.MinPoint);
// console.log(b3.MinPoint);
// console.log(b1.MaxPoint);
// console.log(b2.MaxPoint);
// console.log(b3.MaxPoint);
console.log(b1.BoardOCS);
console.log(b2.BoardOCS);
console.log(b3.BoardOCS);
console.log(b1.MaxPoint);
console.log(b2.MaxPoint);
console.log(b3.MaxPoint);
// console.log(b1.BoardOCS);
// console.log(b2.BoardOCS);
// console.log(b3.BoardOCS);
// let ssRes = await app.m_Editor.GetSelection({ UseSelect: true });

@ -1,6 +1,8 @@
import { Matrix4, Vector3 } from "three";
import { Board, BoardType } from "../DatabaseServices/Board";
import { equal, equaln } from "./GeUtils";
import { app } from "../ApplicationServices/Application";
import { PromptStatus } from "../Editor/PromptResult";
/**
@ -31,7 +33,7 @@ export class SpaceParse
constructor(boards: Board[])
{
this.m_Boards = boards || [];
this.SpaceParse();
}
SpaceParse()
{
@ -66,7 +68,10 @@ export class TopAndBottomSpaceParse extends SpaceParse
private m_Spacelength: number;
private m_TotalLength: number;
private m_SpaceWidth: number;
private m_BasePoint: Vector3;
//侧包顶顶板基点
private m_BaseTopDownPoint: Vector3;
// 顶包侧顶板基点
private m_BaseTopUpPoint: Vector3;
constructor(boards: Board[])
{
@ -88,15 +93,19 @@ export class TopAndBottomSpaceParse extends SpaceParse
{
return this.m_SpaceWidth
}
get BasePoint()
get BaseTopDownPoint()
{
return this.m_BaseTopDownPoint;
}
get BaseTopUpPoint()
{
return this.m_BasePoint;
return this.m_BaseTopUpPoint;
}
get OCS()
{
return this.m_LeftBoard ? this.m_LeftBoard.BoardOCS : new Matrix4();
return this.m_StandardBoard ? this.m_StandardBoard.BoardOCS : new Matrix4();
}
SpaceParse()
async SpaceParse()
{
super.SpaceParse();
let lrBoards = this.boardMap.get(BoardType.Vertical);
@ -105,70 +114,122 @@ export class TopAndBottomSpaceParse extends SpaceParse
let b1 = lrBoards[0].Clone() as Board;
let b2 = lrBoards[1].Clone() as Board;
b1.ApplyMatrix(b1.BoardOCSInv);
b2.ApplyMatrix(b1.BoardOCSInv);
b1.ApplyMatrix(new Matrix4().extractRotation(b1.BoardOCSInv));
b2.ApplyMatrix(new Matrix4().extractRotation(b2.BoardOCSInv));
[this.m_LeftBoard, this.m_RightBoard] =
b1.Position.x < b2.Position.x ? [lrBoards[0], lrBoards[1]] : [lrBoards[1], lrBoards[0]];
if (this.ParseLRBoards())
if (this.ParseLRBoards(b1, b2))
{
let res = await this.GetStandardBoard(b1, b2);
//选择基准板错误
if (res)
{
this.m_IsVail = true;
this.GetStandardBoard();
this.ParseGeometry();
this.ParseGeometry(b1, b2);
}
}
else
this.m_IsVail = false;
}
}
ParseLRBoards()
ParseLRBoards(b1: Board, b2: Board)
{
if (this.m_LeftBoard && this.m_RightBoard)
if (b1 && b2)
{
// 左右侧板位置相等,无效
if (equal(this.m_LeftBoard.Position, this.m_RightBoard.Position))
if (equal(b1.Position, b2.Position))
return false;
//左右侧板不平行,无效
if (!equaln(Math.abs(this.m_LeftBoard.Normal.dot(this.m_RightBoard.Normal)), 1, 1e-6))
if (!equaln(Math.abs(b1.Normal.dot(b2.Normal)), 1, 1e-6))
{
return false;
}
let lMinPt = this.m_LeftBoard.MinPoint;
let rMinPt = this.m_RightBoard.MinPoint;
let dist = lMinPt.distanceToSquared(rMinPt);
let vec = lMinPt.sub(rMinPt).normalize();
if (!equaln(Math.abs(this.m_LeftBoard.Normal.dot(vec)), 1, 1e-6))
{
return false;
}
let lMinPt = b1.MinPoint;
let rMinPt = b2.MinPoint;
return Math.abs(lMinPt.x + rMinPt.x) > Math.max(b1.Thickness, b2.Thickness)
&& Math.abs(lMinPt.y - rMinPt.y) + 1e-6 < Math.max(b1.Width, b2.Width)
&& Math.abs(lMinPt.z - rMinPt.z) + 1e-6 < Math.max(b1.Lenght, b2.Lenght);
//左右侧板不能重合
return dist - 1e-2 > this.m_LeftBoard.Thickness ** 2
}
return false;
}
ParseGeometry()
ParseGeometry(b1: Board, b2: Board)
{
let lMinPt = b1.MinPoint;
let rMinPt = b2.MinPoint;
let lMaxPt = b1.MaxPoint;
let rMaxPt = b2.MaxPoint;
let lB = this.m_LeftBoard;
let rB = this.m_RightBoard;
let vec = rMinPt.clone().sub(lMinPt);
let ang = b1.Normal.angleTo(vec);
let dist = vec.length() * Math.cos(ang);
let lMinPt = lB.MinPoint;
let rMinPt = rB.MinPoint;
let dist = lMinPt.distanceTo(rMinPt);
//空间净长
this.m_Spacelength = dist - lB.Thickness;
this.m_Spacelength = dist - b1.Thickness;
//总宽
this.m_TotalLength = dist + lB.Thickness + rB.Thickness;
this.m_TotalLength = dist + b2.Thickness;
//空间宽度
this.m_SpaceWidth = this.m_StandardBoard.Width;
this.m_BasePoint = new Vector3(this.m_Spacelength, 0, this.m_StandardBoard.Lenght);
if (this.m_StandardBoard === this.m_LeftBoard)
{
this.m_BaseTopDownPoint = new Vector3(rMinPt.x, lMinPt.y);
this.m_BaseTopUpPoint = new Vector3(rMinPt.x + b2.Thickness, lMinPt.y)
}
GetStandardBoard()
else
{
this.m_BaseTopDownPoint = new Vector3(rMinPt.x, rMinPt.y);
this.m_BaseTopUpPoint = new Vector3(rMinPt.x + b2.Thickness, rMinPt.y)
}
this.m_BaseTopDownPoint.setZ(lMaxPt.z < rMaxPt.z ? lMaxPt.z : rMaxPt.z);
this.m_BaseTopUpPoint.setZ(lMaxPt.z > rMaxPt.z ? lMaxPt.z : rMaxPt.z);
//分析背板
let behindBoards = this.boardMap.get(BoardType.Behind);
if (behindBoards && behindBoards.length === 1)
{
let behindBoard = behindBoards[0];
}
}
async GetStandardBoard(b1: Board, b2: Board)
{
let lMinPt = b1.MinPoint;
let rMinPt = b2.MinPoint;
if (equaln(lMinPt.y, rMinPt.y)
&& equaln(lMinPt.z, rMinPt.z)
&& equaln(b1.Width, b2.Width)
&& equaln(b1.Lenght, b2.Lenght))
{
this.m_StandardBoard = this.m_LeftBoard;
return true;
}
else
{
while (true)
{
let ssRes = await app.m_Editor.GetEntity({ Msg: "请选择基准板" });
if (ssRes.Status === PromptStatus.Cancel) return false;
let baseBoard = ssRes.Entity;
if (baseBoard instanceof Board)
{
if ([this.m_LeftBoard, this.m_RightBoard].includes(baseBoard))
{
this.m_StandardBoard = baseBoard;
return true;
}
}
}
}
}
}

@ -1,4 +1,4 @@
import { Button, Dialog } from '@blueprintjs/core';
import { Button, Dialog, RadioGroup, Radio } from '@blueprintjs/core';
import * as React from 'react';
import { TopBottomBoardStore, ModalState } from '../../Store/BoardStore';
import { inject, observer } from 'mobx-react';
@ -16,43 +16,34 @@ export class TopBottomBaordDiaLog extends React.Component<{ store?: TopBottomBoa
isOpen={true}
canOutsideClickClose={false}
enforceFocus={false}
title="顶底板"
title={store.title}
>
<div className="pt-dialog-body" onKeyDown={e => e.stopPropagation()}>
<div>
<label htmlFor=""></label>
<input
type="number"
value={store.boardOption.thickness}
onChange={e =>
<RadioGroup
onChange={e => store.boardOption.isTopWrapSide = e.currentTarget.value === "1"}
selectedValue={store.boardOption.isTopWrapSide ? "1" : "0"}
>
<Radio label="侧包顶" value="0" />
<Radio label="顶包侧" value="1" />
</RadioGroup>
{
store.boardOption.thickness = parseFloat(e.target.value);
}}
/>
</div>
<div>
<label htmlFor=""></label>
<input
type="number"
value={store.boardOption.forwardDistance}
onChange={e =>
Array.from(store.m_Parameter.keys()).map(k =>
{
store.boardOption.forwardDistance = parseFloat(e.target.value);
}}
/>
</div >
<div>
<label htmlFor=""></label>
return (
<div key={k}>
<label htmlFor="">{store.m_Parameter.get(k)}:</label>
<input
type="number"
value={store.boardOption.behindDistance}
value={store.boardOption[k]}
onChange={e =>
{
store.boardOption.behindDistance = parseFloat(e.target.value);
store.boardOption[k] = e.target.value;
}}
/>
</div>
)
})
}
</div>

@ -1,12 +1,31 @@
import { Button, Dialog } from '@blueprintjs/core';
import { inject, observer } from 'mobx-react';
import * as React from 'react';
import { KeyBoard } from '../../../Common/KeyEnum';
import { ModalState, SideBoardStore } from '../../Store/BoardStore';
interface LRState
{
lenght: string,
width: string,
thickness: string,
spacing: string
}
@inject("store")
@observer
export class LeftRightBaordDialog extends React.Component<{ store?: SideBoardStore }, {}> {
export class LeftRightBaordDialog extends React.Component<{ store?: SideBoardStore }, LRState> {
constructor(props)
{
super(props);
let store = this.props.store;
this.state = {
lenght: store.boardOption.lenght + "",
width: store.boardOption.width + "",
thickness: store.boardOption.thickness + "",
spacing: store.boardOption.spacing + ""
}
}
render()
{
let store = this.props.store;
@ -18,55 +37,36 @@ export class LeftRightBaordDialog extends React.Component<{ store?: SideBoardSto
onClose={() => store.OnOk(ModalState.Cancel)}
canOutsideClickClose={false}
enforceFocus={false}
title="左右侧板"
title={store.title}
>
<div className="pt-dialog-body" onKeyDown={e => e.stopPropagation()}>
<div>
<label htmlFor=""></label>
<input
type="number"
value={store.boardOption.height}
onChange={e =>
<div className="pt-dialog-body" onKeyDown={e =>
{
store.boardOption.height = parseFloat(e.target.value);
}}
/>
</div>
<div>
<label htmlFor=""></label>
<input
type="number"
value={store.boardOption.width}
onChange={e =>
if (e.keyCode === KeyBoard.Enter)
{
store.boardOption.width = parseFloat(e.target.value);
}}
/>
</div >
store.OnOk(ModalState.Ok);
}
e.stopPropagation();
}
}>
<div>
<label htmlFor=""></label>
<input
type="number"
value={store.boardOption.thickness}
onChange={e =>
{
store.boardOption.thickness = parseFloat(e.target.value);
}}
/>
</div >
<div>
<label htmlFor=""></label>
Array.from(store.m_Parameter.keys()).map(k =>
{
return (
<div key={k}>
<label htmlFor="">{store.m_Parameter.get(k)}:</label>
<input
type="number"
value={store.boardOption.spacing}
value={store.boardOption[k]}
onChange={e =>
{
store.boardOption.spacing = parseFloat(e.target.value);
store.boardOption[k] = e.target.value;
}}
/>
</div>
)
})
}
</div>
<div className="pt-dialog-footer">

@ -6,13 +6,13 @@ import { KeyBoard } from '../../Common/KeyEnum';
interface BoardOption
{
thickness: number, //厚度
height: number, //长
width: number //宽
thickness: string, //厚度
lenght: string, //长
width: string //宽
}
interface SideBoardOption extends BoardOption
{
spacing: number
spacing: string
}
export enum ModalState
@ -56,11 +56,13 @@ export class SideBoardStore extends BoardStore
{
//板数据
@observable boardOption: SideBoardOption = {
height: 12,
width: 6,
thickness: 0.18,
spacing: 8
lenght: "12",
width: "6",
thickness: "0.18",
spacing: "8"
};
m_Parameter = new Map([["lenght", "柜长"], ["width", "柜宽"], ["thickness", "板厚"], ["spacing", "间距"]]);
title = "左右侧板";
private static _store: SideBoardStore;
static Store()
{
@ -72,10 +74,13 @@ export class SideBoardStore extends BoardStore
export class TopBottomBoardStore extends BoardStore
{
@observable boardOption = {
thickness: 0.18,
forwardDistance: 0,
behindDistance: -0.18
thickness: "0.18",
forwardDistance: "0",
behindDistance: "-0.18",
isTopWrapSide: false
};
m_Parameter = new Map([["thickness", "板厚"], ["forwardDistance", "前距"], ["behindDistance", "后距"]]);
title = "顶底板";
private static _store: TopBottomBoardStore;
static Store()
{

Loading…
Cancel
Save