From 5aea7ae83c120137340822dbfd6505a17abf16eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=B8=89?= <940119273@qq.com> Date: Wed, 17 Jul 2024 07:56:12 +0000 Subject: [PATCH] =?UTF-8?q?!2283=20=E4=BC=98=E5=8C=96:=20=E4=B8=A4?= =?UTF-8?q?=E7=82=B9=E7=A9=BA=E9=97=B4=E7=BB=98=E5=88=B6=EF=BC=8C=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=88=86=E6=9E=90=E6=B7=B1=E5=BA=A6=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE=E5=91=BD=E4=BB=A4=E9=80=89?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Editor/DefaultConfig.ts | 6 + src/Geometry/SpaceParse/Point2SpaceParse.ts | 141 +++++++++++-------- src/Geometry/SpaceParse/Point3SpaceParse,.ts | 37 ++++- src/Geometry/SpaceParse/SpaceParseStore.ts | 57 ++++++++ src/UI/Components/Board/BoardModalType.ts | 3 +- 5 files changed, 181 insertions(+), 63 deletions(-) create mode 100644 src/Geometry/SpaceParse/SpaceParseStore.ts diff --git a/src/Editor/DefaultConfig.ts b/src/Editor/DefaultConfig.ts index 854af2ffc..ee52b294b 100644 --- a/src/Editor/DefaultConfig.ts +++ b/src/Editor/DefaultConfig.ts @@ -3,6 +3,7 @@ import { Curve2RecOption } from "../Add-on/twoD2threeD/Modals/Curve2RecOption"; import { IParseBoardNameOption, IRec2BrOption, IRect2Br2Option } from "../Add-on/twoD2threeD/R2bInterface"; import { EBoardKeyList } from "../Common/BoardKeyList"; import { BoardOpenDir, BoardType, BrRelativePos, ComposingType, LinesType } from "../DatabaseServices/Entity/BoardInterface"; +import { SpaceParseOption } from "../Geometry/SpaceParse/SpaceParseStore"; import { RenderType } from "../GraphicsSystem/RenderType"; import { IUpdateBoardInfosOption } from "../UI/Components/Board/UpdateBoardInfointerface"; import { EMetalsType, ICompHardwareOption, ICylMetalsOption, IExtMetalsOption, IToplineOption } from "../UI/Components/RightPanel/RightPanelInterface"; @@ -1144,3 +1145,8 @@ export const DefaultArcBoardGrooveOption: IArcBoardGrooveOption = { grooveAddDepth: "0", }; Object.freeze(DefaultArcBoardGrooveOption); + +export const DefaultSpaceParseOption: SpaceParseOption = { + autoParseDepth: false, +}; +Object.freeze(DefaultSpaceParseOption); diff --git a/src/Geometry/SpaceParse/Point2SpaceParse.ts b/src/Geometry/SpaceParse/Point2SpaceParse.ts index e03b79f47..5da9a0b39 100644 --- a/src/Geometry/SpaceParse/Point2SpaceParse.ts +++ b/src/Geometry/SpaceParse/Point2SpaceParse.ts @@ -7,27 +7,52 @@ import { Intent } from "../../Common/Toaster"; import { GetEntity } from "../../Common/Utils"; import { Board } from "../../DatabaseServices/Entity/Board"; import { PointPick, Raycast } from "../../Editor/PointPick"; -import { PromptStatus } from "../../Editor/PromptResult"; +import { PromptRectResult, PromptStatus } from "../../Editor/PromptResult"; import { Filter } from "../../Editor/SelectFilter"; import { userConfig } from "../../Editor/UserConfig"; import { RenderType } from "../../GraphicsSystem/RenderType"; +import { BoardModalType } from "../../UI/Components/Board/BoardModalType"; +import { DialogUserConfig } from "../../UI/Components/Board/UserConfigComponent"; import { AppToaster } from "../../UI/Components/Toaster"; +import { userConfigStore } from "../../UI/Store/UserConfigStore"; import { Box3Ext } from "../Box"; import { isParallelTo, isPerpendicularityTo } from "../GeUtils"; import { ClampSpaceParseRay } from "./ClampSpaceParseRay"; import { ISpaceParse } from "./ISpaceParse"; import { PointSelectBoards } from "./PointSelectBoards"; +import { spaceParseStore } from "./SpaceParseStore"; let lastDepth = 600; export class Point2SpaceParse extends ISpaceParse { async Parse() { - let rectRes = await app.Editor.GetRectPoint(); + let store = spaceParseStore; + let config = new DialogUserConfig(store, BoardModalType.SpaceParse); + await config.LoadAndInitConfig();//载入或者初始化 - if (rectRes.Status !== PromptStatus.OK) return; + let rectRes: PromptRectResult; + while (true) + { + rectRes = await app.Editor.GetRectPoint({ + Msg: `请输入一个点${store.m_Option.autoParseDepth ? ",(当前为自动分析深度)" : ""}`, + KeyWordList: [{ key: "A", msg: `${store.m_Option.autoParseDepth ? "关闭自动分析深度" : "开启自动分析深度"}` }] + }); + if (rectRes.Status === PromptStatus.Keyword) + { + if (rectRes.StringResult === "A") + { + store.m_Option.autoParseDepth = !store.m_Option.autoParseDepth; + userConfigStore.SaveConfig(BoardModalType.SpaceParse, store, { toaster: false }); + } + } + else if (rectRes.Status === PromptStatus.OK) + break; + else + return; + } - let depth = await GetSpaceDepth(rectRes.Point1UCS, rectRes.Point2UCS, rectRes.UCS, lastDepth); + let depth = await GetSpaceDepth(rectRes.Point1UCS, rectRes.Point2UCS, rectRes.UCS, lastDepth, store.m_Option.autoParseDepth); if (!depth) return; lastDepth = depth; @@ -94,72 +119,78 @@ const RayVec = [ * @param p2UCS * @param UCSMatrix * @param lastDepth + * @param autoParseDepth //是否解析深度 */ -export async function GetSpaceDepth(p1UCS: Vector3, p2UCS: Vector3, UCSMatrix: Matrix4, lastDepth: number) +export async function GetSpaceDepth(p1UCS: Vector3, p2UCS: Vector3, UCSMatrix: Matrix4, lastDepth: number, autoParseDepth: boolean) { let autoDepth = 0; - let size = p2UCS.clone().sub(p1UCS); - let ray = new Vector3().setFromMatrixColumn(UCSMatrix, 2).negate(); - let boardObjects: Object3D[] = []; - for (let obj of app.Viewer.VisibleObjects)//获取真实视图的绘制对象 + if (autoParseDepth) { - let en = GetEntity(obj); - if (en && !en.IsErase && en.Id && en instanceof Board) + let size = p2UCS.clone().sub(p1UCS); + let ray = new Vector3().setFromMatrixColumn(UCSMatrix, 2).negate(); + let boardObjects: Object3D[] = []; + for (let obj of app.Viewer.VisibleObjects)//获取真实视图的绘制对象 { - let normal = en.Normal; - if (isParallelTo(normal, ray) || isPerpendicularityTo(normal, ray)) - boardObjects.push(en.GetDrawObjectFromRenderType(RenderType.Physical)); + let en = GetEntity(obj); + if (en && !en.IsErase && en.Id && en instanceof Board) + { + let normal = en.Normal; + if (isParallelTo(normal, ray) || isPerpendicularityTo(normal, ray)) + boardObjects.push(en.GetDrawObjectFromRenderType(RenderType.Physical)); + } } - } - let pts: Vector3[] = []; - for (let v of RayVec)//使用射线投射 - { - let p = p1UCS.clone().add(size.multiply(v)); - p.applyMatrix4(UCSMatrix); - - let rayCast = new Raycaster(p, ray); - let f: Filter = { filterErase: true, filterTypes: [Board] }; - let i = Raycast(rayCast, boardObjects, f); - pts.push(p); - if (i && i.distance < 1200 && i.distance > 0.1)//深度太大是没有意义的 + let pts: Vector3[] = []; + for (let v of RayVec)//使用射线投射 { - autoDepth = i.distance; - break; + let p = p1UCS.clone().add(size.multiply(v)); + p.applyMatrix4(UCSMatrix); + + let rayCast = new Raycaster(p, ray); + let f: Filter = { filterErase: true, filterTypes: [Board] }; + let i = Raycast(rayCast, boardObjects, f); + pts.push(p); + if (i && i.distance < 1200 && i.distance > 0.1)//深度太大是没有意义的 + { + autoDepth = i.distance; + break; + } } - } - if (autoDepth < 0.1) - { - let dcsMtx = app.Viewer.DCS; - let ucsInv = new Matrix4().getInverse(UCSMatrix); - for (let p of pts)//使用点选空间 + if (autoDepth < 0.1) { - let dcsPoint = p.applyMatrix4(dcsMtx); - let ptSelect = new PointSelectBoards(dcsPoint, app.Viewer, boardObjects); - let spaceParse = new ClampSpaceParseRay(ptSelect.SelectBoards).SetRay(ptSelect.Ray); - spaceParse.IsDynamic = true; - await spaceParse.Parse(); - if (spaceParse.ParseOK) + let dcsMtx = app.Viewer.DCS; + let ucsInv = new Matrix4().getInverse(UCSMatrix); + for (let p of pts)//使用点选空间 { - let mtx = new Matrix4().multiplyMatrices(ucsInv, spaceParse.SpaceOCS); - spaceParse.SpaceBox.applyMatrix4(mtx); - autoDepth = p1UCS.z - spaceParse.SpaceBox.min.z; - break; + let dcsPoint = p.applyMatrix4(dcsMtx); + let ptSelect = new PointSelectBoards(dcsPoint, app.Viewer, boardObjects); + let spaceParse = new ClampSpaceParseRay(ptSelect.SelectBoards).SetRay(ptSelect.Ray); + spaceParse.IsDynamic = true; + await spaceParse.Parse(); + if (spaceParse.ParseOK) + { + let mtx = new Matrix4().multiplyMatrices(ucsInv, spaceParse.SpaceOCS); + spaceParse.SpaceBox.applyMatrix4(mtx); + autoDepth = p1UCS.z - spaceParse.SpaceBox.min.z; + break; + } } } - } + //保留两位有效数字 + autoDepth = parseFloat(autoDepth.toFixed(2)); - if (autoDepth > 0.1) - { - Log(`自动分析深度为:${autoDepth}`); - AppToaster.show({ - message: `自动分析深度为:${autoDepth}`, - timeout: 5000, - intent: Intent.SUCCESS, - }); + if (autoDepth > 0.1) + { + Log(`自动分析深度为:${autoDepth}`); + AppToaster.show({ + message: `自动分析深度为:${autoDepth}`, + timeout: 5000, + intent: Intent.SUCCESS, + }); + } + else + autoDepth = 0; } - else - autoDepth = 0; let keyword: KeyWord[] = []; if (autoDepth) diff --git a/src/Geometry/SpaceParse/Point3SpaceParse,.ts b/src/Geometry/SpaceParse/Point3SpaceParse,.ts index a8fe60b2d..4ba9bd682 100644 --- a/src/Geometry/SpaceParse/Point3SpaceParse,.ts +++ b/src/Geometry/SpaceParse/Point3SpaceParse,.ts @@ -1,13 +1,17 @@ import { Matrix4 } from "three"; import { app } from "../../ApplicationServices/Application"; import { Board } from "../../DatabaseServices/Entity/Board"; -import { PromptStatus } from "../../Editor/PromptResult"; +import { PromptPointResult, PromptStatus } from "../../Editor/PromptResult"; +import { BoardModalType } from "../../UI/Components/Board/BoardModalType"; +import { DialogUserConfig } from "../../UI/Components/Board/UserConfigComponent"; import { AppToaster } from "../../UI/Components/Toaster"; +import { userConfigStore } from "../../UI/Store/UserConfigStore"; import { Box3Ext } from "../Box"; import { isPerpendicularityTo } from "../GeUtils"; import { ISpaceParse } from "./ISpaceParse"; import { GetSpaceDepth } from "./Point2SpaceParse"; import { PointSelectBoards } from "./PointSelectBoards"; +import { spaceParseStore } from "./SpaceParseStore"; let lastDepth = 600; @@ -15,11 +19,30 @@ export class Point3SpaceParse extends ISpaceParse { async Parse() { - let ptRes = await app.Editor.GetPoint({ - Msg: "选择基点" - }); - if (ptRes.Status !== PromptStatus.OK) - return; + let store = spaceParseStore; + let config = new DialogUserConfig(store, BoardModalType.SpaceParse); + await config.LoadAndInitConfig();//载入或者初始化 + + let ptRes: PromptPointResult; + while (true) + { + ptRes = await app.Editor.GetPoint({ + Msg: `选择基点${store.m_Option.autoParseDepth ? ",(当前为自动分析深度)" : ""}`, + KeyWordList: [{ key: "A", msg: `${store.m_Option.autoParseDepth ? "关闭自动分析深度" : "开启自动分析深度"}` }] + }); + if (ptRes.Status === PromptStatus.Keyword) + { + if (ptRes.StringResult === "A") + { + store.m_Option.autoParseDepth = !store.m_Option.autoParseDepth; + userConfigStore.SaveConfig(BoardModalType.SpaceParse, store, { toaster: false }); + } + } + else if (ptRes.Status === PromptStatus.OK) + break; + else + return; + } let basePt = ptRes.Point; @@ -76,7 +99,7 @@ export class Point3SpaceParse extends ISpaceParse p1.applyMatrix4(ucsInv); p2.applyMatrix4(ucsInv); - let depth = await GetSpaceDepth(p1, p2, ucs, lastDepth); + let depth = await GetSpaceDepth(p1, p2, ucs, lastDepth, store.m_Option.autoParseDepth); if (!depth) return; lastDepth = depth; } diff --git a/src/Geometry/SpaceParse/SpaceParseStore.ts b/src/Geometry/SpaceParse/SpaceParseStore.ts new file mode 100644 index 000000000..bc5b1304c --- /dev/null +++ b/src/Geometry/SpaceParse/SpaceParseStore.ts @@ -0,0 +1,57 @@ +import { observable } from "mobx"; +import { CADFiler } from "../../DatabaseServices/CADFiler"; +import { DefaultSpaceParseOption } from "../../Editor/DefaultConfig"; +import { IConfigStore } from "../../UI/Store/BoardStore"; + +export interface SpaceParseOption +{ + autoParseDepth: boolean; +} + +export class SpaceParseStore implements IConfigStore +{ + @observable configName = "默认"; + @observable m_Option: SpaceParseOption = { ...DefaultSpaceParseOption }; + @observable configsNames: string[] = []; + + InitOption() + { + Object.assign(this.m_Option, DefaultSpaceParseOption); + } + + SaveConfig() + { + return this.WriteFile() as any; + } + + UpdateOption(confData: any) + { + let file = new CADFiler(confData); + this.ReadFile(file); + } + + private static _SingleInstance: SpaceParseStore; + + static GetInstance(): SpaceParseStore + { + if (this._SingleInstance) return this._SingleInstance; + this._SingleInstance = new SpaceParseStore; + return this._SingleInstance; + } + + ReadFile = (file: CADFiler) => + { + let ver = file.Read(); + this.m_Option.autoParseDepth = file.Read(); + }; + + WriteFile(file: CADFiler = new CADFiler) + { + file.Write(1); + file.Write(this.m_Option.autoParseDepth); + + return file.Data; + } +} + +export const spaceParseStore = SpaceParseStore.GetInstance(); diff --git a/src/UI/Components/Board/BoardModalType.ts b/src/UI/Components/Board/BoardModalType.ts index 97d180744..9ea52137e 100644 --- a/src/UI/Components/Board/BoardModalType.ts +++ b/src/UI/Components/Board/BoardModalType.ts @@ -76,5 +76,6 @@ export enum BoardModalType BoardInfoDim = "BoardInfoDim", //板件信息标注 FastDim = "FastDim",//自由标注 AlignLineGroupStore = "AlignLineGroupStore",//对纹组 - ResourceStoreIcon = "resourceStoreIcon"//模型库列表的显示方式 + ResourceStoreIcon = "resourceStoreIcon",//模型库列表的显示方式 + SpaceParse = "SpaceParse",//空间解析配置 }