!2283 优化: 两点空间绘制,自动分析深度功能增加配置命令选项

pull/2800/MERGE
林三 3 months ago committed by ChenX
parent aa36ccb7cf
commit 5aea7ae83c

@ -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);

@ -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)

@ -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;
}

@ -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();

@ -76,5 +76,6 @@ export enum BoardModalType
BoardInfoDim = "BoardInfoDim", //板件信息标注
FastDim = "FastDim",//自由标注
AlignLineGroupStore = "AlignLineGroupStore",//对纹组
ResourceStoreIcon = "resourceStoreIcon"//模型库列表的显示方式
ResourceStoreIcon = "resourceStoreIcon",//模型库列表的显示方式
SpaceParse = "SpaceParse",//空间解析配置
}

Loading…
Cancel
Save