diff --git a/src/Add-on/TemplateSearch.tsx b/src/Add-on/TemplateSearch.tsx new file mode 100644 index 000000000..6f308fd9c --- /dev/null +++ b/src/Add-on/TemplateSearch.tsx @@ -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 ( +
+
+
+

模块购买

+
+
+