diff --git a/src/Add-on/Command_Modeling.ts b/src/Add-on/Command_Modeling.ts new file mode 100644 index 000000000..d4706b65b --- /dev/null +++ b/src/Add-on/Command_Modeling.ts @@ -0,0 +1,61 @@ +import { Intent } from "@blueprintjs/core"; +import { app } from "../ApplicationServices/Application"; +import { GroupEntitysByBox } from "../Common/GroupEntitysByBox"; +import { Board } from "../DatabaseServices/Entity/Board"; +import { Entity } from "../DatabaseServices/Entity/Entity"; +import { HardwareCompositeEntity } from "../DatabaseServices/Hardware/HardwareCompositeEntity"; +import { InitTempateBoardThicknessActions, InitTempateSizeActions, InitTemplate } from "../DatabaseServices/Template/TempateUtils"; +import { Command } from "../Editor/CommandMachine"; +import { PromptStatus } from "../Editor/PromptResult"; +import { AppToaster } from "../UI/Components/Toaster"; + +export class Command_Modeling implements Command +{ + async exec() + { + let enRes = await app.Editor.GetSelection({ + Filter: { filterTypes: [Entity] }, + Msg: "选择板件" + }); + if (enRes.Status !== PromptStatus.OK) return; + + let brs = enRes.SelectSet.SelectEntityList as Entity[]; + let box2entitys_map = GroupEntitysByBox(brs); + + AppToaster.show({ + message: "选择的实体存在多个模块时,将忽略原先模块!", + timeout: 5000, + intent: Intent.PRIMARY, + }, "modeling_tip"); + + for (let [box, ents] of box2entitys_map) + { + if (ents.length < 2) continue; + + //按实体的绘制顺序 + ents.sort((a, b) => a.objectId?.Index - b.objectId?.Index); + //初始化模块 + let newTemp = await InitTemplate(ents, true); + //初始化模块的大小动作 + InitTempateSizeActions(newTemp, false); + //初始化模块的板厚动作 + await InitTempateBoardThicknessActions(newTemp, true); + + //模块名称使用柜名 + let tempName = ""; + for (let ent of ents) + { + if (ent instanceof Board) + tempName = ent.BoardProcessOption.cabinetName; + else if (ent instanceof HardwareCompositeEntity) + tempName = ent.HardwareOption.cabinetName; + if (tempName) + { + newTemp.Name = tempName; + break; + } + } + } + app.Editor.SetSelection(brs); + } +} diff --git a/src/Common/CommandNames.ts b/src/Common/CommandNames.ts index 07eef2cbd..749c133ec 100644 --- a/src/Common/CommandNames.ts +++ b/src/Common/CommandNames.ts @@ -381,5 +381,6 @@ export enum CommandNames Show2DPathObject = "SHOW2DPATHOBJECT",//显示二维刀路差集 Hide2DPathObject = "HIDE2DPATHOBJECT",//隐藏二维刀路差集 PickUp2DModelCsgs = "PICKUP2DMODELCSGS",//提取二维刀路的刀具轮廓 - TemplateGroup = "TEMPLATEGROUP" //模块组合 + TemplateGroup = "TEMPLATEGROUP", //模块组合 + Modeling = "MODELING"//一键建模 } diff --git a/src/DatabaseServices/Template/TempateUtils.ts b/src/DatabaseServices/Template/TempateUtils.ts index 4a637d7f9..00f9cbaac 100644 --- a/src/DatabaseServices/Template/TempateUtils.ts +++ b/src/DatabaseServices/Template/TempateUtils.ts @@ -118,9 +118,10 @@ export function GetTempateEntitys(template: TemplateRecord): Entity[] * @param ents 板件列表 * @returns 模块记录 */ -export async function InitTemplate(ents: Entity[]): Promise +export async function InitTemplate(ents: Entity[], buildNewTemp: boolean = false): Promise { let templates: Set = new Set(); + for (let br of ents) { if (!br.Template) @@ -134,38 +135,41 @@ export async function InitTemplate(ents: Entity[]): Promise 1) + if (!buildNewTemp) { - let keyRes = await app.Editor.GetKeyWords({ - Msg: "选择的实体存在多个模块内,是否忽略原先模块,创建新的模块?", - KeyWordList: [ - { key: "1", msg: "是" }, - { key: "2", msg: "否" }, - ], - Default: "1" - }); - - if (keyRes.StringResult !== "1") - return undefined; - - templates.delete(undefined); - } - else // (templates.size === 1)//都在一个模块内或者都不在模块内 - { - templates.delete(undefined); - if (templates.size === 1)//都在模块内 + if (templates.size > 1) { let keyRes = await app.Editor.GetKeyWords({ - Msg: "编辑当前模块或者重新创建", + Msg: "选择的实体存在多个模块内,是否忽略原先模块,创建新的模块?", KeyWordList: [ - { key: "Y", msg: "创建新模块" }, - { key: "N", msg: "编辑当前模块" }, + { key: "1", msg: "是" }, + { key: "2", msg: "否" }, ], - Default: "N" + Default: "1" }); - if (keyRes.Status === PromptStatus.Cancel) return; - if (keyRes.StringResult === "N") - return [...templates][0]; + + if (keyRes.StringResult !== "1") + return undefined; + + templates.delete(undefined); + } + else // (templates.size === 1)//都在一个模块内或者都不在模块内 + { + templates.delete(undefined); + if (templates.size === 1)//都在模块内 + { + let keyRes = await app.Editor.GetKeyWords({ + Msg: "编辑当前模块或者重新创建", + KeyWordList: [ + { key: "Y", msg: "创建新模块" }, + { key: "N", msg: "编辑当前模块" }, + ], + Default: "N" + }); + if (keyRes.Status === PromptStatus.Cancel) return; + if (keyRes.StringResult === "N") + return [...templates][0]; + } } } diff --git a/src/Editor/CommandRegister.ts b/src/Editor/CommandRegister.ts index 099ce6ad3..7586716c9 100644 --- a/src/Editor/CommandRegister.ts +++ b/src/Editor/CommandRegister.ts @@ -214,6 +214,7 @@ import { ShowEditorBBS } from "../Add-on/showModal/ShowModal"; // import { RevTarget, SaveTarget } from '../Add-on/RenderTarget'; import { ChangeColorByRoomCabinet } from "../Add-on/ChangeColorByRoomOrCabinet/ChangeColorByRoomOrCabinet"; import { Command_RemovePolylineRepeatPos } from "../Add-on/Cmd_RemovePolylineRepeatPos"; +import { Command_Modeling } from "../Add-on/Command_Modeling"; import { Command_PickUp2DModelCsgs } from "../Add-on/Command_PickUp2DModelCsgs"; import { Command_TemplateGroup } from "../Add-on/Command_TemplateGroup"; import { ApplyModel2ToBoard } from "../Add-on/DrawBoard/ApplyModel2ToBoard"; @@ -676,6 +677,7 @@ export function registerCommand() commandMachine.RegisterCommand(CommandNames.Template, new ShowTemplate("Administration")); commandMachine.RegisterCommand(CommandNames.TemplateCollection, new ShowTemplate("Collection")); commandMachine.RegisterCommand(CommandNames.TemplateDesign, new ShowTemplateDesign()); + commandMachine.RegisterCommand(CommandNames.Modeling, new Command_Modeling()); commandMachine.RegisterCommand(CommandNames.templateDelete, new Command_DeleteTemplate()); commandMachine.RegisterCommand(CommandNames.TemplateCheck, new Command_TemplateSearch(true)); commandMachine.RegisterCommand(CommandNames.TemplateGroup, new Command_TemplateGroup()); diff --git a/src/UI/Components/CommandPanel/CommandList.ts b/src/UI/Components/CommandPanel/CommandList.ts index 6e7ea98d9..c9281e059 100644 --- a/src/UI/Components/CommandPanel/CommandList.ts +++ b/src/UI/Components/CommandPanel/CommandList.ts @@ -2728,6 +2728,16 @@ export const CommandList: ICommand[] = [ chName: "模板设计", chDes: "", }, + { + icon: IconEnum.Modeling, + typeId: "temp", + link: `#`, + defaultCustom: CommandNames.Modeling, + command: CommandNames.Modeling, + type: "模板", + chName: "一键建模", + chDes: "一键建模", + }, { icon: IconEnum.CutSpace, typeId: "temp", diff --git a/src/UI/Components/RightPanel/TemplateParamPanel.tsx b/src/UI/Components/RightPanel/TemplateParamPanel.tsx index d982b32cf..3eef1cff5 100644 --- a/src/UI/Components/RightPanel/TemplateParamPanel.tsx +++ b/src/UI/Components/RightPanel/TemplateParamPanel.tsx @@ -461,14 +461,14 @@ export class TemplateParamDetail extends React.Component<{}> { //获取关联板件数 GetAssociateBrNums(tr: TemplateRecord): number { - let p = tr.Positioning as PositioningClampSpace; + let p = tr?.Positioning as PositioningClampSpace; return p?.Objects?.length ?? 0; } //获取板件切割方式 ShowSplitType = (tr: TemplateRecord) => { - switch (tr.SplitType) + switch (tr?.SplitType) { case TemplateSplitType.None: return "空"; @@ -478,6 +478,8 @@ export class TemplateParamDetail extends React.Component<{}> { return "Y"; case TemplateSplitType.Z: return "Z"; + default: + return "空"; } };