mirror of https://gitee.com/cf-fz/WebCAD.git
!730 绘制可视化空间盒子
parent
7f78f8dc37
commit
12c372ccd5
@ -0,0 +1,153 @@
|
||||
import { Button, Classes, Intent, Label } from '@blueprintjs/core';
|
||||
import { observable, toJS } from 'mobx';
|
||||
import { observer } from 'mobx-react';
|
||||
import * as React from 'react';
|
||||
import { Matrix4 } from "three";
|
||||
import * as xaop from 'xaop';
|
||||
import { app } from "../../ApplicationServices/Application";
|
||||
import { CheckObjectType } from '../../Common/CheckoutVaildValue';
|
||||
import { KeyBoard } from '../../Common/KeyEnum';
|
||||
import { TemplateVisualSpace } from '../../DatabaseServices/Template/ProgramTempate/TemplateVisualSpace';
|
||||
import { Command } from "../../Editor/CommandMachine";
|
||||
import { JigUtils } from '../../Editor/JigUtils';
|
||||
import { PromptStatus } from "../../Editor/PromptResult";
|
||||
import { VisualSpaceBox } from '../../Editor/VisualSpaceBox';
|
||||
import { ModalPosition, ModalState } from '../../UI/Components/Modal/ModalsManage';
|
||||
import { ToasterInput } from '../../UI/Components/Toaster';
|
||||
import { DataAdapter } from './../../Common/DataAdapter';
|
||||
import { AppToaster } from './../../UI/Components/Toaster';
|
||||
import { IBaseOption, IUiOption } from './../../UI/Store/BoardInterface';
|
||||
|
||||
const VS_BOX_KEY = "vsBoxKey";
|
||||
|
||||
export class DrawVisualSpaceBox implements Command
|
||||
{
|
||||
async exec()
|
||||
{
|
||||
let option = observable({ length: 2000, width: 600, height: 2800 });
|
||||
const optCache = localStorage.getItem(VS_BOX_KEY);
|
||||
if (optCache)
|
||||
Object.assign(option, JSON.parse(optCache));
|
||||
|
||||
app.Editor.ModalManage.RenderModal(DrawVisualSpaceBoxModal, ModalPosition.Center, { option });
|
||||
|
||||
let res = await app.Editor.ModalManage.Wait();
|
||||
if (res.Status === ModalState.Ok)
|
||||
{
|
||||
let jigBox = new VisualSpaceBox(option.length, option.width, option.height);
|
||||
JigUtils.Draw(jigBox);
|
||||
let m = new Matrix4();
|
||||
let ptRes = await app.Editor.GetPoint({
|
||||
Msg: "点击选择空间位置:",
|
||||
Callback: (p) =>
|
||||
{
|
||||
m.setPosition(p);
|
||||
jigBox.OCS = m;
|
||||
jigBox.Update();
|
||||
}
|
||||
});
|
||||
|
||||
if (ptRes.Status === PromptStatus.OK)
|
||||
{
|
||||
localStorage.setItem(VS_BOX_KEY, JSON.stringify(toJS(option)));
|
||||
let template = new TemplateVisualSpace();
|
||||
template.InitBaseParams();
|
||||
app.Database.TemplateTable.Append(template);
|
||||
template.LParam.expr = option.length;
|
||||
template.WParam.expr = option.width;
|
||||
template.HParam.expr = option.height;
|
||||
await template.UpdateTemplateTree();
|
||||
let pt = ptRes.Point;
|
||||
let box = template.Objects[0].Object as VisualSpaceBox;
|
||||
m.setPosition(pt);
|
||||
box.ApplyMatrix(m);
|
||||
box.SpaceOCS = m;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
interface IVSProps extends IBaseOption
|
||||
{
|
||||
length: number;
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
@observer
|
||||
class DrawVisualSpaceBoxModal extends React.Component<{ option: IVSProps; }, {}>
|
||||
{
|
||||
@observable private data: IUiOption<IVSProps> = DataAdapter.ConvertUIData(this.props.option);
|
||||
componentDidMount()
|
||||
{
|
||||
app.Editor.ModalManage.events.push(
|
||||
xaop.begin(app.Editor.ModalManage, app.Editor.ModalManage.OnKeyDown, (e: KeyboardEvent) =>
|
||||
{
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
if (e.keyCode === KeyBoard.Enter || e.keyCode === KeyBoard.Space)
|
||||
this.onOk();
|
||||
}));
|
||||
}
|
||||
render()
|
||||
{
|
||||
return (
|
||||
<div style={{
|
||||
background: "#fff",
|
||||
padding: 20,
|
||||
}}>
|
||||
<h3>可视化盒子</h3>
|
||||
{
|
||||
[["长", "length"], ["宽", "width"], ["高", "height"]].map(([t, k]) =>
|
||||
<Label className={Classes.INLINE}>
|
||||
<span>{t}</span>
|
||||
<ToasterInput
|
||||
type={CheckObjectType.OnlyNumber}
|
||||
option={this.props.option}
|
||||
uiOption={this.data}
|
||||
optKey={k}
|
||||
/>
|
||||
</Label>
|
||||
)
|
||||
}
|
||||
<div className="right">
|
||||
<Button
|
||||
text="确定"
|
||||
intent={Intent.SUCCESS}
|
||||
onClick={this.onOk}
|
||||
/>
|
||||
<Button
|
||||
text="取消"
|
||||
intent={Intent.DANGER}
|
||||
onClick={this.onCancel}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
private onOk = () =>
|
||||
{
|
||||
const option = this.props.option;
|
||||
if (option.length <= 0 || option.width <= 0 || option.height <= 0)
|
||||
{
|
||||
AppToaster.show({
|
||||
message: "长宽高必须大于0",
|
||||
timeout: 2000,
|
||||
intent: Intent.DANGER
|
||||
});
|
||||
return;
|
||||
}
|
||||
app.Editor.ModalManage.m_PromisRes({
|
||||
Status: ModalState.Ok
|
||||
});
|
||||
app.Editor.ModalManage.Clear();
|
||||
};
|
||||
private onCancel = () =>
|
||||
{
|
||||
app.Editor.ModalManage.m_PromisRes({
|
||||
Status: ModalState.Cancel
|
||||
});
|
||||
app.Editor.ModalManage.Clear();
|
||||
};
|
||||
}
|
Loading…
Reference in new issue