diff --git a/src/Add-on/DrawViewport.ts b/src/Add-on/DrawViewport.ts index b3d1c10eb..bd16feac4 100644 --- a/src/Add-on/DrawViewport.ts +++ b/src/Add-on/DrawViewport.ts @@ -1,83 +1,80 @@ -import { Command } from "../Editor/CommandMachine"; -import { app } from "../ApplicationServices/Application"; -import { PromptStatus } from "../Editor/PromptResult"; -import { ViewportEntity } from "../DatabaseServices/ViewportEntity"; -import { Log } from "../Common/Log"; -import { Vector3 } from "three"; -import { DownPanelStore } from "../UI/Store/DownPanelStore"; -import { Entity } from "../DatabaseServices/Entity/Entity"; -import { ObjectId } from "../DatabaseServices/ObjectId"; -import { AppToaster } from "../UI/Components/Toaster"; import { Intent } from "@blueprintjs/core"; +import { Vector3 } from "three"; +import { app } from "../ApplicationServices/Application"; import { Sleep } from "../Common/Sleep"; +import { Hole } from "../DatabaseServices/3DSolid/Hole"; import { Board } from "../DatabaseServices/Entity/Board"; -import { BoardOpenDir } from "../UI/Store/BoardInterface"; +import { Entity } from "../DatabaseServices/Entity/Entity"; import { HardwareCompositeEntity } from "../DatabaseServices/Hardware/HardwareCompositeEntity"; -import { Hole } from "../DatabaseServices/3DSolid/Hole"; +import { ObjectId } from "../DatabaseServices/ObjectId"; +import { ViewportEntity } from "../DatabaseServices/ViewportEntity"; +import { Command } from "../Editor/CommandMachine"; +import { PromptStatus } from "../Editor/PromptResult"; import { RenderType } from "../GraphicsSystem/RenderType"; +import { AppToaster } from "../UI/Components/Toaster"; +import { BoardOpenDir } from "../UI/Store/BoardInterface"; +import { DownPanelStore } from "../UI/Store/DownPanelStore"; -async function GetViewportInfo() +async function GetViewportInfo(): Promise<{ p1: Vector3; p2: Vector3; ens: Entity[]; }> { - let isAll = false; - let ens: Entity[] = []; const downStore = (DownPanelStore.GetInstance() as DownPanelStore); + let bak = downStore.isLayout; downStore.isLayout = false; - const SelectEns = async () => { let enRes = await app.Editor.GetSelection({ - Msg: "选择指定布局的柜体", + Msg: "选择指定布局的柜体<空格选择全部>:", + UseSelect: true, + AllowNone: true, }); if (enRes.Status === PromptStatus.Cancel) - { - downStore.isLayout = true; - isAll = true; return; - } else { - ens = enRes.SelectSet.SelectEntityList; downStore.isLayout = true; + return enRes.SelectSet.SelectEntityList; } }; - await SelectEns(); + let ens = await SelectEns();//当ens.length===0时,表示选择全部 + if (!ens) + { + downStore.isLayout = bak; + return; + } + downStore.isLayout = true; while (true) { let rectRes = await app.Editor.GetRectPoint({ - KeyWordList: [{ key: "T", msg: isAll ? "指定柜体<当前为全部>" : "全部柜体<当前为指定柜体>" }] + KeyWordList: [{ key: "T", msg: ens.length === 0 ? "指定柜体<当前为全部>" : "全部柜体<当前为指定柜体>" }] }); if (rectRes.Status === PromptStatus.OK) { let p1 = rectRes.Point1UCS; let p2 = rectRes.Point2UCS; + let retEntitys = ens.length === 0 ? app.Database.ModelSpace.Entitys.filter(e => !e.IsErase) : ens; return { - p1, p2, ens + p1, p2, ens: retEntitys }; } else if (rectRes.Status === PromptStatus.Keyword) { if (rectRes.StringResult === "T") { - isAll = !isAll; - if (!isAll) - { - downStore.isLayout = false; - await SelectEns(); - } + if (ens.length === 0) + ens = await SelectEns(); else - { ens = []; - } } } else break; } - return null; + + downStore.isLayout = bak; } @@ -85,12 +82,6 @@ export class DrawViewport implements Command { async exec() { - if (!app.Viewer.isLayout) - { - Log("仅能在布局模式下使用"); - return; - } - const data = await GetViewportInfo(); if (data) @@ -106,7 +97,6 @@ export class DrawViewport implements Command ids.push(en.Id); } vp.AppendShowObjects(ids); - app.Database.LayoutSpace.Append(vp); vp.ZoomAll(); } @@ -116,12 +106,6 @@ export class Draw4Viewport implements Command { async exec() { - if (!app.Viewer.isLayout) - { - Log("仅能在布局模式下使用"); - return; - } - const data = await GetViewportInfo(); if (data) diff --git a/src/DatabaseServices/ViewportEntity.ts b/src/DatabaseServices/ViewportEntity.ts index 8c9fb3ec2..66df2429b 100644 --- a/src/DatabaseServices/ViewportEntity.ts +++ b/src/DatabaseServices/ViewportEntity.ts @@ -3,7 +3,7 @@ import { app } from "../ApplicationServices/Application"; import { ColorMaterial } from "../Common/ColorPalette"; import { DisposeThreeObj, Object3DRemoveAll } from "../Common/Dispose"; import { UpdateDraw } from "../Common/Status"; -import { clamp } from "../Common/Utils"; +import { clamp, GetEntity } from "../Common/Utils"; import { ObjectSnapMode } from "../Editor/ObjectSnapMode"; import { VisualSpaceBox } from "../Editor/VisualSpaceBox"; import { BufferGeometryUtils } from "../Geometry/BufferGeometryUtils"; @@ -270,7 +270,14 @@ export class ViewportEntity extends Entity } ZoomAll() { - let box = GetBox(this.scene, true); + let box = new Box3; + for (let obj of this.scene.children) + { + let ent = GetEntity(obj); + if (ent) box.union(ent.BoundingBox); + else box.union(GetBox(obj)); + } + if (box.isEmpty()) box.set(new Vector3(), new Vector3(1000 * (this.Width / this.Height), 1000, 1000)); this.camera.ZoomExtensBox3(box);