!351 Fixbug批量内缩跟踪测试

Merge pull request !351 from 肖诗雅/curtail_bug
pull/351/MERGE
肖诗雅 5 years ago committed by ChenX
parent ee22b9fe64
commit 6acc22ea1b

@ -3,15 +3,14 @@ import { app } from "../ApplicationServices/Application";
import { Board } from "../DatabaseServices/Entity/Board";
import { Command } from "../Editor/CommandMachine";
import { PromptStatus } from "../Editor/PromptResult";
import { ZeroVec, equalv3, isParallelTo, MoveMatrix } from "../Geometry/GeUtils";
import { BoardBatchCurtailModal, BoardBatchCurtailStore } from "../UI/Components/BoardBatchCurtailModal";
import { ZeroVec, equalv3, isParallelTo } from "../Geometry/GeUtils";
import { BoardBatchCurtailModal, BoardBatchCurtailStore, CurtailType } from "../UI/Components/BoardBatchCurtailModal";
import { ModalPosition, ModalState } from "../UI/Components/Modal/ModalsManage";
import { HotCMD } from "../Hot/HotCommand";
interface CurtailDataItem
{
vec: Vector3;
box: Box3;
indexs: number[];
}
interface CurtailData
{
@ -20,7 +19,13 @@ interface CurtailData
left: CurtailDataItem;
right: CurtailDataItem;
}
interface CurtailBox
{
front: Box3;
back: Box3;
left: Box3;
right: Box3;
}
export class BoardBatchCurtail implements Command
{
async exec()
@ -49,21 +54,27 @@ export class BoardBatchCurtail implements Command
sizeBox.union(box);
}
//构造内缩盒子
const GenCurtailBox = (sizeBox: Box3): CurtailBox =>
{
let size = sizeBox.getSize(new Vector3);
let v = new Vector3(1, 1, 1);
//构造内缩盒子
let frontBox = new Box3(sizeBox.min.clone().sub(v), sizeBox.max.clone().sub(new Vector3(-1, size.y / 2, -1)));
let rightBox = new Box3(sizeBox.min.clone().add(new Vector3(size.x / 2, -1, -1)), sizeBox.max.clone().add(v));
let backBox = new Box3(sizeBox.min.clone().add(new Vector3(-1, size.y / 2, -1)), sizeBox.max.clone().add(v));
let leftBox = new Box3(sizeBox.min.clone().sub(v), sizeBox.max.sub(new Vector3(size.x / 2, -1, -1)));
let leftBox = new Box3(sizeBox.min.clone().sub(v), sizeBox.max.clone().sub(new Vector3(size.x / 2, -1, -1)));
return { front: frontBox, right: rightBox, left: leftBox, back: backBox }
}
let curBox = GenCurtailBox(sizeBox);
//解析前后左右能够拉伸的范围.
let dx = {
front: { box: frontBox, index: 1 },
back: { box: backBox, index: 1 },
left: { box: leftBox, index: 0 },
right: { box: rightBox, index: 0 },
front: { box: curBox.front, index: 1 },
back: { box: curBox.back, index: 1 },
left: { box: curBox.left, index: 0 },
right: { box: curBox.right, index: 0 },
};
for (let key in dx)
{
@ -91,40 +102,76 @@ export class BoardBatchCurtail implements Command
if (res.Status === ModalState.Ok)
{
// 各方向拉伸所需数据: 拉伸向量, 拉伸盒子
// 各方向拉伸所需数据: 拉伸向量, 拉伸索引
let curtailData: CurtailData = {
front: { vec: new Vector3(0, store.m_Option.front), box: frontBox },
back: { vec: new Vector3(0, -store.m_Option.back), box: backBox },
left: { vec: new Vector3(store.m_Option.left), box: leftBox },
right: { vec: new Vector3(-store.m_Option.right), box: rightBox }
front: { vec: new Vector3(0, store.m_Option.front), indexs: [] },
back: { vec: new Vector3(0, -store.m_Option.back), indexs: [] },
left: { vec: new Vector3(store.m_Option.left), indexs: [] },
right: { vec: new Vector3(-store.m_Option.right), indexs: [] }
};
//逐板内缩
if (store.m_Option.type === CurtailType.PerBr)
{
for (let br of brs)
{
//逐板计算拉伸盒子
let box = br.BoundingBox;
let curBox2 = GenCurtailBox(box);
let pts = br.GetStretchPoints();
for (let key in curtailData)
{
let d = curtailData[key] as CurtailDataItem;
if (equalv3(d.vec, ZeroVec))
continue;
d.indexs = [];
//获取索引
for (let i = 0, length = pts.length; i < length; i++)
{
if (curBox2[key].containsPoint(pts[i]))
d.indexs.push(i);
}
if (!isParallelTo(d.vec, br.Normal))
br.MoveStretchPoints(d.indexs, d.vec);
else if (store.m_Option.moveBrs)
br.MoveStretchPoints(br.GetStretchPoints().map((v, i) => { return i }), d.vec);
}
}
}
//整体内缩
else
{
for (let br of brs)
{
//获取索引
//先获取索引
for (let key in curtailData)
{
let box = curBox[key] as Box3;
let d = curtailData[key] as CurtailDataItem;
d.indexs = [];
if (equalv3(d.vec, ZeroVec))
continue;
let spts = br.GetStretchPoints();
let indexs: number[] = [];
for (let i = 0; i < spts.length; i++)
{
let p = spts[i];
p.applyMatrix4(spaceOcsInv);
if (d.box.containsPoint(p))
indexs.push(i);
if (box.containsPoint(p))
d.indexs.push(i);
}
}
if (indexs.length === 0) continue;
//进行内缩
for (let key in curtailData)
{
let d = curtailData[key] as CurtailDataItem;
if (d.indexs.length === 0) continue;
//禁止拉伸厚度
if (br.IsStretchThickness(indexs))
if (br.IsStretchThickness(d.indexs))
continue;
// br.ApplyMatrix(MoveMatrix(d.vec.clone().multiplyScalar(0.5)));
//进行内缩
br.MoveStretchPoints(indexs, d.vec);
br.MoveStretchPoints(d.indexs, d.vec);
}
}
}
}

@ -1,6 +1,6 @@
import React = require("react");
import '../Css/batchCurtailModal.less';
import { Card, Intent, Button, Label, Classes, Divider } from "@blueprintjs/core";
import { Card, Intent, Button, Label, Classes, Divider, RadioGroup, Radio, H5, Checkbox } from "@blueprintjs/core";
import { app } from "../../ApplicationServices/Application";
import { BoardStore } from "../Store/BoardStore";
import { observable } from "mobx";
@ -9,25 +9,35 @@ import { AppToaster, ToasterInput } from "./Toaster";
import { ModalState } from "./Modal/ModalsManage";
import { UserConfig } from "./Board/UserConfig";
import { BoardModalType } from "./Board/BoardModal";
import { observer } from "mobx-react";
export interface IBoardBatchCurtailProps
{
store: BoardBatchCurtailStore;
}
export enum CurtailType
{
PerBr = "0",
Total = "1",
}
interface IBoardBatchCurtailOption
{
type: CurtailType;
front: number;
back: number;
left: number;
right: number;
moveBrs: boolean;
}
export class BoardBatchCurtailStore extends BoardStore
{
@observable m_Option: IBoardBatchCurtailOption = {
type: CurtailType.Total,
front: 0,
back: 0,
left: 0,
right: 0,
moveBrs: false,
}
checkValue: IBoardBatchCurtailOption = JSON.parse(JSON.stringify(this.m_Option));
HasInvailValue()
@ -35,7 +45,7 @@ export class BoardBatchCurtailStore extends BoardStore
let flag = false;
for (let key in this.m_Option)
{
if (this.m_Option[key] > this.checkValue[key])
if (key !== "moveBrs" && this.m_Option[key] > this.checkValue[key])
{
flag = true;
break;
@ -44,6 +54,7 @@ export class BoardBatchCurtailStore extends BoardStore
return CheckoutValid.HasInvailValue(this.UIOption, CheckObjectType.BBC) || flag;
}
}
@observer
export class BoardBatchCurtailModal extends React.Component<IBoardBatchCurtailProps, {}>
{
private CONFIG_CURTAIL = "curtail";
@ -56,6 +67,7 @@ export class BoardBatchCurtailModal extends React.Component<IBoardBatchCurtailPr
}
app.Editor.ModalManage.m_PromisRes({
Status: ModalState.Ok, Data: {
type: this.props.store.m_Option.type,
front: this.props.store.m_Option.front,
back: this.props.store.m_Option.back,
left: this.props.store.m_Option.left,
@ -82,6 +94,21 @@ export class BoardBatchCurtailModal extends React.Component<IBoardBatchCurtailPr
<Card className="batchCurtailModal">
<header data-id="dragArea"></header>
<div>
<H5></H5>
<RadioGroup
className="radio"
inline
selectedValue={this.props.store.UIOption["type"]}
onChange={(e) =>
{
this.props.store.m_Option.type = e.currentTarget.value as CurtailType;
this.props.store.UIOption["type"] = e.currentTarget.value as CurtailType;
}}
>
<Radio label={`整体内缩`} value={CurtailType.Total} />
<Radio label={`按板内缩`} value={CurtailType.PerBr} />
</RadioGroup>
<H5></H5>
<div>
<Label className={Classes.INLINE}>
<span> </span>
@ -133,6 +160,16 @@ export class BoardBatchCurtailModal extends React.Component<IBoardBatchCurtailPr
</Label>
</div>
</div>
<Checkbox
style={{
marginRight: 10
}}
disabled={this.props.store.m_Option.type === CurtailType.Total}
checked={this.props.store.m_Option.moveBrs}
label="是否向内缩方向移动板件"
inline={true}
onChange={() => this.props.store.m_Option.moveBrs = !this.props.store.m_Option.moveBrs}
/>
<footer>
<div>
<Button intent={Intent.SUCCESS} text="确定" onClick={this.Ok} />

@ -4,6 +4,9 @@
margin-bottom: 20px;
font-size: 16px;
}
.radio{
margin: 10px;
}
&>div
{
input{
@ -36,6 +39,10 @@
text-align: left;
margin-left: 5px;
}
.bp3-popover-content{
height: 90px;
overflow: auto;
}
}
.bp3-divider{
margin-top: 10px;

Loading…
Cancel
Save