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

@ -1,6 +1,6 @@
import React = require("react"); import React = require("react");
import '../Css/batchCurtailModal.less'; 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 { app } from "../../ApplicationServices/Application";
import { BoardStore } from "../Store/BoardStore"; import { BoardStore } from "../Store/BoardStore";
import { observable } from "mobx"; import { observable } from "mobx";
@ -9,25 +9,35 @@ import { AppToaster, ToasterInput } from "./Toaster";
import { ModalState } from "./Modal/ModalsManage"; import { ModalState } from "./Modal/ModalsManage";
import { UserConfig } from "./Board/UserConfig"; import { UserConfig } from "./Board/UserConfig";
import { BoardModalType } from "./Board/BoardModal"; import { BoardModalType } from "./Board/BoardModal";
import { observer } from "mobx-react";
export interface IBoardBatchCurtailProps export interface IBoardBatchCurtailProps
{ {
store: BoardBatchCurtailStore; store: BoardBatchCurtailStore;
} }
export enum CurtailType
{
PerBr = "0",
Total = "1",
}
interface IBoardBatchCurtailOption interface IBoardBatchCurtailOption
{ {
type: CurtailType;
front: number; front: number;
back: number; back: number;
left: number; left: number;
right: number; right: number;
moveBrs: boolean;
} }
export class BoardBatchCurtailStore extends BoardStore export class BoardBatchCurtailStore extends BoardStore
{ {
@observable m_Option: IBoardBatchCurtailOption = { @observable m_Option: IBoardBatchCurtailOption = {
type: CurtailType.Total,
front: 0, front: 0,
back: 0, back: 0,
left: 0, left: 0,
right: 0, right: 0,
moveBrs: false,
} }
checkValue: IBoardBatchCurtailOption = JSON.parse(JSON.stringify(this.m_Option)); checkValue: IBoardBatchCurtailOption = JSON.parse(JSON.stringify(this.m_Option));
HasInvailValue() HasInvailValue()
@ -35,7 +45,7 @@ export class BoardBatchCurtailStore extends BoardStore
let flag = false; let flag = false;
for (let key in this.m_Option) 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; flag = true;
break; break;
@ -44,6 +54,7 @@ export class BoardBatchCurtailStore extends BoardStore
return CheckoutValid.HasInvailValue(this.UIOption, CheckObjectType.BBC) || flag; return CheckoutValid.HasInvailValue(this.UIOption, CheckObjectType.BBC) || flag;
} }
} }
@observer
export class BoardBatchCurtailModal extends React.Component<IBoardBatchCurtailProps, {}> export class BoardBatchCurtailModal extends React.Component<IBoardBatchCurtailProps, {}>
{ {
private CONFIG_CURTAIL = "curtail"; private CONFIG_CURTAIL = "curtail";
@ -56,6 +67,7 @@ export class BoardBatchCurtailModal extends React.Component<IBoardBatchCurtailPr
} }
app.Editor.ModalManage.m_PromisRes({ app.Editor.ModalManage.m_PromisRes({
Status: ModalState.Ok, Data: { Status: ModalState.Ok, Data: {
type: this.props.store.m_Option.type,
front: this.props.store.m_Option.front, front: this.props.store.m_Option.front,
back: this.props.store.m_Option.back, back: this.props.store.m_Option.back,
left: this.props.store.m_Option.left, left: this.props.store.m_Option.left,
@ -82,6 +94,21 @@ export class BoardBatchCurtailModal extends React.Component<IBoardBatchCurtailPr
<Card className="batchCurtailModal"> <Card className="batchCurtailModal">
<header data-id="dragArea"></header> <header data-id="dragArea"></header>
<div> <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> <div>
<Label className={Classes.INLINE}> <Label className={Classes.INLINE}>
<span> </span> <span> </span>
@ -133,6 +160,16 @@ export class BoardBatchCurtailModal extends React.Component<IBoardBatchCurtailPr
</Label> </Label>
</div> </div>
</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> <footer>
<div> <div>
<Button intent={Intent.SUCCESS} text="确定" onClick={this.Ok} /> <Button intent={Intent.SUCCESS} text="确定" onClick={this.Ok} />

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

Loading…
Cancel
Save