!730 绘制可视化空间盒子

pull/730/MERGE
ZoeLeeFZ 5 years ago committed by ChenX
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();
};
}

@ -154,6 +154,7 @@ import { Command_TestYHWorker } from "../Nest/Test/TestYH3";
import { ICommand } from '../UI/Components/CommandPanel/CommandList';
import { commandMachine } from './CommandMachine';
import { Text2Curve } from "../Add-on/Text2Curve";
import { DrawVisualSpaceBox } from "../Add-on/Template/DrawVisualSpaceBox";
export function registerCommand()
{
@ -422,6 +423,8 @@ export function registerCommand()
commandMachine.RegisterCommand("Text2Curve", new Text2Curve());
commandMachine.RegisterCommand("drawvsbox", new DrawVisualSpaceBox());
RegistCustomCommand();
}

@ -6,6 +6,7 @@ import { app } from '../../../ApplicationServices/Application';
import { KeyBoard } from '../../../Common/KeyEnum';
import { EntityStore } from '../../Store/EntityStore';
import { ColorModal } from './EntityColorList';
import { Curve } from '../../../DatabaseServices/Entity/Curve';
@observer
export class EntityModal extends React.Component<{ store?: EntityStore; }, {}> {
@ -45,7 +46,7 @@ export class EntityModal extends React.Component<{ store?: EntityStore; }, {}> {
{
options.unshift({ label: "全部" + count.toString(), value: "all" });
}
let ents = this.props.store.GetEntitys();
let ents = this.props.store.GetEntitys() as Curve[];
return (
<div id="entityModal" className={Classes.CARD} >
@ -64,13 +65,13 @@ export class EntityModal extends React.Component<{ store?: EntityStore; }, {}> {
<ColorModal store={this.props.store} />
</li>
{
ents.length > 0 && this.props.store.GetEntitys()[0]['Length'] !== undefined &&
ents.length > 0 && (ents[0] instanceof Curve) &&
<>
<li>
: {this.props.store.GetEntitys()[0]['Length'].toFixed(2)}
: {ents[0].Length.toFixed(2)}
</li>
<li>
: {this.props.store.GetEntitys()[0]['Area'].toFixed(2)}
: {ents[0].Area.toFixed(2)}
</li>
</>
}
@ -80,4 +81,3 @@ export class EntityModal extends React.Component<{ store?: EntityStore; }, {}> {
);
}
}

@ -477,6 +477,7 @@ export class TemplateParamDetail extends React.Component<{ updateParams: INeedUp
private onKeydown = async (e: React.KeyboardEvent<HTMLInputElement>, par: INeedUpdateParams) =>
{
e.stopPropagation();
if (e.keyCode === KeyBoard.Enter)
{
par.expr = par.expr.toString().trim();
@ -490,7 +491,6 @@ export class TemplateParamDetail extends React.Component<{ updateParams: INeedUp
this.ChangeInputUIClass(e.currentTarget, par);
await this.ApplyParamExpr();
}
e.stopPropagation();
};
//获取基点表达式和旋转表达式参数

@ -127,6 +127,7 @@ export class TopToolBar extends React.Component<{}, {}>
];
store.iconList.template = [
{ svg: IconEnum.TemplateDesign, title: "模板设计", command: "TEMPLATEDESIGN" },
{ svg: IconEnum.TemplateDesign, title: "绘制空间", command: "DRAWVSBOX" }
];
store.iconList.module = [
{ svg: IconEnum.ModuleManage, title: "模块管理", command: "TEMPLATE" },

Loading…
Cancel
Save