diff --git a/src/Add-on/LookOverBoardInfos/LookOverBoardInfos.ts b/src/Add-on/LookOverBoardInfos/LookOverBoardInfos.ts index 65ba57edc..762fb56d9 100644 --- a/src/Add-on/LookOverBoardInfos/LookOverBoardInfos.ts +++ b/src/Add-on/LookOverBoardInfos/LookOverBoardInfos.ts @@ -2,10 +2,10 @@ import { app } from "../../ApplicationServices/Application"; import { Board } from "../../DatabaseServices/Entity/Board"; import { Command } from "../../Editor/CommandMachine"; import { PromptStatus } from "../../Editor/PromptResult"; +import { IHardwareType } from "../../Production/Product"; import { LookOverBoardInfosModal } from "../../UI/Components/BBS/LookOverBoardInfos"; import { HardwareCompositeEntity } from './../../DatabaseServices/Hardware/HardwareCompositeEntity'; import { HardwareTopline } from './../../DatabaseServices/Hardware/HardwareTopline'; -import { IHardwareType, Production } from "../../Production/Product"; export class LookOverBoardInfos implements Command { async exec() diff --git a/src/Add-on/MoveToWCS0.ts b/src/Add-on/MoveToWCS0.ts index 1d1c8287b..16502a5a2 100644 --- a/src/Add-on/MoveToWCS0.ts +++ b/src/Add-on/MoveToWCS0.ts @@ -1,8 +1,11 @@ -import { Box3, Matrix4 } from "three"; +import Flatbush from 'flatbush'; +import { Box3, Matrix4, Vector3 } from "three"; import { app } from "../ApplicationServices/Application"; import { Entity } from "../DatabaseServices/Entity/Entity"; import { Command } from "../Editor/CommandMachine"; import { PromptStatus } from "../Editor/PromptResult"; +import { comparePoint } from '../Geometry/GeUtils'; +import { HotCMD } from '../Hot/HotCommand'; export class Command_M0 implements Command @@ -26,3 +29,80 @@ export class Command_M0 implements Command e.ApplyMatrix(m); } } + +@HotCMD +export class Command_PackageMove implements Command +{ + async exec() + { + let ents = app.Database.ModelSpace.Entitys.filter(e => !e.IsErase); + if (ents.length === 0) return; + let oents = ents.concat(); + this.PackageMove(ents, oents, 0, 1); + this.PackageMove(oents.concat(), oents, 1, 2, 5000, 1e10); + this.PackageMove(oents.concat(), oents, 2, 0, 5000, 1e10); + app.Viewer.ZoomAll(); + } + + PackageMove(ents: Entity[], oents: Entity[], i1: number, i2: number, i1d = 1000, i2d = 1000) + { + for (let i = 0; i < ents.length; i++) + { + let en = ents[i]; + en.TempData = { i, b: en.BoundingBox, u: false }; + } + + let fb = new Flatbush(ents.length); + for (let en of ents) + { + let box = en.TempData.b as Box3; + fb.add(box.min.getComponent(i1) - 10, box.min.getComponent(i2) - 10, box.max.getComponent(i1) + 10, box.max.getComponent(i2) + 10); + } + fb.finish(); + + let groups: { ens: Entity[], box: Box3; }[] = []; + while (ents.length) + { + let arr = [ents.pop()]; + arr[0].TempData.u = true; + let b = new Box3; + + for (let i = 0; i < arr.length; i++) + { + let e = arr[i]; + b.union(e.TempData.b); + + let ids = fb.search(b.min.getComponent(i1) - i1d, b.min.getComponent(i2) - i2d, b.max.getComponent(i1) + i1d, b.max.getComponent(i2) + i2d, id => oents[id].TempData.u === false); + + for (let id of ids) + { + let e = oents[id]; + e.TempData.u = true; + arr.push(e); + b.union(e.TempData.b); + } + + if (ids.length) + ents = ents.filter(e => e.TempData.u === false); + } + + groups.push({ ens: arr, box: b }); + } + + groups.sort((g1, g2) => g1.box.min.getComponent(i1) - g2.box.min.getComponent(i1)); + + let movex = new Vector3; + let size = new Vector3; + let mmtz = new Matrix4; + for (let g of groups) + { + let b = g.box; + mmtz.setPosition(b.min.clone().negate().add(movex)); + + movex.setComponent(i1, movex.getComponent(i1) + b.getSize(size).getComponent(i1) + 1000); + + for (let e of g.ens) + e.ApplyMatrix(mmtz); + } + } +} diff --git a/src/Common/CommandNames.ts b/src/Common/CommandNames.ts index 7fa855c82..d6da0486a 100644 --- a/src/Common/CommandNames.ts +++ b/src/Common/CommandNames.ts @@ -224,5 +224,6 @@ export enum CommandNames UploadConfig = "UPLOADCONFIG", TestM = "TESTM", M0 = "M0", + PackageGroupMove0 = "PACKAGEGROUPMOVE0", ApplyMtl = "APPLYMTL",//应用材质 } diff --git a/src/DatabaseServices/Entity/Extrude.ts b/src/DatabaseServices/Entity/Extrude.ts index 7c727f4c9..20e0cdea8 100644 --- a/src/DatabaseServices/Entity/Extrude.ts +++ b/src/DatabaseServices/Entity/Extrude.ts @@ -127,7 +127,10 @@ export class ExtrudeSolid extends Entity } get BoundingBoxInOCS(): Box3Ext { - return new Box3Ext(new Vector3(), new Vector3(this.width, this.height, this.thickness)); + if (this.width > 0 && this.height > 0 && this.thickness > 0) + return new Box3Ext(new Vector3, new Vector3(this.width, this.height, this.thickness)); + else + return new Box3Ext().setFromPoints([new Vector3, new Vector3(this.width, this.height, this.thickness)]); } get OBB(): OBB diff --git a/src/Editor/CommandRegister.ts b/src/Editor/CommandRegister.ts index d25cd94ec..751a5326f 100644 --- a/src/Editor/CommandRegister.ts +++ b/src/Editor/CommandRegister.ts @@ -136,7 +136,7 @@ import { Fbx } from "../Add-on/loadfbx"; import { LookOverBoardInfos } from "../Add-on/LookOverBoardInfos/LookOverBoardInfos"; import { MirrorCommand } from "../Add-on/Mirror"; import { Command_Move } from "../Add-on/Move"; -import { Command_M0 } from "../Add-on/MoveToWCS0"; +import { Command_M0, Command_PackageMove } from "../Add-on/MoveToWCS0"; import { Command_DynOffset, Command_DynOffsetToolPath, Command_Offset } from "../Add-on/Offset"; import { OffsetX } from "../Add-on/OffsetX"; import { Open } from "../Add-on/Open"; @@ -277,6 +277,7 @@ export function registerCommand() commandMachine.RegisterCommand(CommandNames.Move, new Command_Move()); commandMachine.RegisterCommand("z0", new Command_EntitytMoveToZ0()); commandMachine.RegisterCommand(CommandNames.M0, new Command_M0()); + commandMachine.RegisterCommand(CommandNames.PackageGroupMove0, new Command_PackageMove()); commandMachine.RegisterCommand(CommandNames.Rotate, new Command_Rotate()); commandMachine.RegisterCommand(CommandNames.RotateRefer, new Command_RotateRefer()); commandMachine.RegisterCommand(CommandNames.Revolve, new Command_DrawRevolve()); diff --git a/src/Editor/GetPointServices.ts b/src/Editor/GetPointServices.ts index dccf8fcd9..172679741 100644 --- a/src/Editor/GetPointServices.ts +++ b/src/Editor/GetPointServices.ts @@ -23,6 +23,9 @@ import { PromptPointResult, PromptStatus } from './PromptResult'; import { SnapMenuKW, SNAPMODE } from './ShowSnapMenu'; import { SnapServices } from './SnapServices'; +const MinP = new Vector3(-2e6, -2e6, -2e6); +const MaxP = new Vector3(2e6, 2e6, 2e6); + /** * 为拾取点提供服务,提供一个类以供Editor引用. */ @@ -467,6 +470,8 @@ export class GetPointServices implements EditorService { if (!this.promisResolve) return; this.RestState(); + if (retValue.Status === PromptStatus.OK) + retValue.Point.clamp(MinP, MaxP); this.promisResolve(retValue); this.promisResolve = undefined; } diff --git a/src/UI/Components/CommandPanel/CommandList.ts b/src/UI/Components/CommandPanel/CommandList.ts index b67f5db5c..328402b7d 100644 --- a/src/UI/Components/CommandPanel/CommandList.ts +++ b/src/UI/Components/CommandPanel/CommandList.ts @@ -1570,6 +1570,15 @@ export const CommandList: ICommand[] = [ chName: "移动到0点", chDes: "移动到0点", }, + { + typeId: "util", + link: "#", + defaultCustom: "PM0", + command: CommandNames.PackageGroupMove0, + type: "工具", + chName: "按柜子移动到0点", + chDes: "按柜子移动到0点", + }, { icon: IconEnum.ExportView, typeId: "util",