mirror of https://gitee.com/cf-fz/WebCAD.git
parent
faba50f391
commit
a83ab45dfd
@ -0,0 +1,97 @@
|
||||
import { Command, CommandWrap } from "../Editor/CommandMachine";
|
||||
import * as React from 'react';
|
||||
import { Classes, Button } from "@blueprintjs/core";
|
||||
import { TemplateUrls } from "../Common/HostUrl";
|
||||
import { app } from "../ApplicationServices/Application";
|
||||
import { ModalPosition } from "../UI/Components/Modal/ModalsManage";
|
||||
import { PostJson, RequestStatus } from "../Common/Request";
|
||||
import { inflate, TemplateIn } from "../Common/SerializeMaterial";
|
||||
import { Board } from "../DatabaseServices/Entity/Board";
|
||||
import { JigUtils } from "../Editor/JigUtils";
|
||||
import { Vector3 } from "three";
|
||||
import { MoveMatrix } from "../Geometry/GeUtils";
|
||||
import { PromptStatus } from "../Editor/PromptResult";
|
||||
import { DuplicateRecordCloning } from "../Common/Status";
|
||||
|
||||
export class Command_TemplateSearch implements Command
|
||||
{
|
||||
async exec()
|
||||
{
|
||||
app.Editor.ModalManage.RenderModal(TemplateSearchDialog, ModalPosition.Center, {});
|
||||
}
|
||||
}
|
||||
|
||||
export class TemplateSearchDialog extends React.Component<{}, {}>{
|
||||
|
||||
|
||||
OnMessage = (e: MessageEvent) =>
|
||||
{
|
||||
CommandWrap(async () =>
|
||||
{
|
||||
let data = await PostJson(TemplateUrls.detail, { module_id: e.data.module_id });
|
||||
if (data.err_code === RequestStatus.Ok)
|
||||
{
|
||||
app.Editor.ModalManage.Clear();
|
||||
app.Editor.MaskManage.Clear();
|
||||
|
||||
|
||||
let file = JSON.parse(inflate(data.modules.file));
|
||||
let template = TemplateIn(file).Root;
|
||||
|
||||
let ens = template.Db.ModelSpace.Entitys as Board[];
|
||||
let nens = ens.map(e => JigUtils.Draw(e));
|
||||
|
||||
let pos = new Vector3();
|
||||
let ptRes = await app.Editor.GetPoint({
|
||||
Msg: "点取位置",
|
||||
Callback: (p: Vector3) =>
|
||||
{
|
||||
nens.forEach(en => en.ApplyMatrix(MoveMatrix(p.clone().sub(pos))));
|
||||
pos.copy(p);
|
||||
}
|
||||
});
|
||||
if (ptRes.Status === PromptStatus.OK)
|
||||
{
|
||||
nens = app.Database.WblockCloneObejcts(ens, app.Database.ModelSpace, new Map(), DuplicateRecordCloning.Ignore) as Board[];
|
||||
pos = new Vector3();
|
||||
nens.forEach(en => en.ApplyMatrix(MoveMatrix(ptRes.Point.clone().sub(pos))));
|
||||
}
|
||||
}
|
||||
}, "购买模块并插入");
|
||||
}
|
||||
|
||||
componentDidMount()
|
||||
{
|
||||
window.addEventListener("message", this.OnMessage);
|
||||
}
|
||||
componentWillUnmount()
|
||||
{
|
||||
window.removeEventListener("message", this.OnMessage);
|
||||
}
|
||||
|
||||
render()
|
||||
{
|
||||
return (
|
||||
<div className={Classes.DIALOG_CONTAINER}>
|
||||
<div className={Classes.DIALOG + " board-config"}>
|
||||
<div className={Classes.DIALOG_HEADER} data-id="dragArea">
|
||||
<h4 className="bp3-heading">模块购买</h4>
|
||||
<Button
|
||||
aria-label="Close"
|
||||
minimal
|
||||
icon="cross"
|
||||
className={Classes.DIALOG_CLOSE_BUTTON}
|
||||
/>
|
||||
</div>
|
||||
<div className={Classes.DIALOG_BODY}>
|
||||
<iframe
|
||||
width="1000"
|
||||
height="600"
|
||||
src={TemplateUrls.search}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue