!2525 功能:一键建模 命令:Modeling

pull/2550/MERGE
林三 9 months ago committed by ChenX
parent b910d02332
commit 2387dcb32e

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

@ -381,5 +381,6 @@ export enum CommandNames
Show2DPathObject = "SHOW2DPATHOBJECT",//显示二维刀路差集 Show2DPathObject = "SHOW2DPATHOBJECT",//显示二维刀路差集
Hide2DPathObject = "HIDE2DPATHOBJECT",//隐藏二维刀路差集 Hide2DPathObject = "HIDE2DPATHOBJECT",//隐藏二维刀路差集
PickUp2DModelCsgs = "PICKUP2DMODELCSGS",//提取二维刀路的刀具轮廓 PickUp2DModelCsgs = "PICKUP2DMODELCSGS",//提取二维刀路的刀具轮廓
TemplateGroup = "TEMPLATEGROUP" //模块组合 TemplateGroup = "TEMPLATEGROUP", //模块组合
Modeling = "MODELING"//一键建模
} }

@ -118,9 +118,10 @@ export function GetTempateEntitys(template: TemplateRecord): Entity[]
* @param ents * @param ents
* @returns * @returns
*/ */
export async function InitTemplate(ents: Entity[]): Promise<TemplateRecord | undefined> export async function InitTemplate(ents: Entity[], buildNewTemp: boolean = false): Promise<TemplateRecord | undefined>
{ {
let templates: Set<TemplateRecord> = new Set(); let templates: Set<TemplateRecord> = new Set();
for (let br of ents) for (let br of ents)
{ {
if (!br.Template) if (!br.Template)
@ -134,38 +135,41 @@ export async function InitTemplate(ents: Entity[]): Promise<TemplateRecord | und
let templateSize: Vector3; let templateSize: Vector3;
if (templates.size > 1) if (!buildNewTemp)
{ {
let keyRes = await app.Editor.GetKeyWords({ if (templates.size > 1)
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)//都在模块内
{ {
let keyRes = await app.Editor.GetKeyWords({ let keyRes = await app.Editor.GetKeyWords({
Msg: "编辑当前模块或者重新创建", Msg: "选择的实体存在多个模块内,是否忽略原先模块,创建新的模块?",
KeyWordList: [ KeyWordList: [
{ key: "Y", msg: "创建新模块" }, { key: "1", msg: "是" },
{ key: "N", msg: "编辑当前模块" }, { key: "2", msg: "否" },
], ],
Default: "N" Default: "1"
}); });
if (keyRes.Status === PromptStatus.Cancel) return;
if (keyRes.StringResult === "N") if (keyRes.StringResult !== "1")
return [...templates][0]; 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];
}
} }
} }

@ -214,6 +214,7 @@ import { ShowEditorBBS } from "../Add-on/showModal/ShowModal";
// import { RevTarget, SaveTarget } from '../Add-on/RenderTarget'; // import { RevTarget, SaveTarget } from '../Add-on/RenderTarget';
import { ChangeColorByRoomCabinet } from "../Add-on/ChangeColorByRoomOrCabinet/ChangeColorByRoomOrCabinet"; import { ChangeColorByRoomCabinet } from "../Add-on/ChangeColorByRoomOrCabinet/ChangeColorByRoomOrCabinet";
import { Command_RemovePolylineRepeatPos } from "../Add-on/Cmd_RemovePolylineRepeatPos"; 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_PickUp2DModelCsgs } from "../Add-on/Command_PickUp2DModelCsgs";
import { Command_TemplateGroup } from "../Add-on/Command_TemplateGroup"; import { Command_TemplateGroup } from "../Add-on/Command_TemplateGroup";
import { ApplyModel2ToBoard } from "../Add-on/DrawBoard/ApplyModel2ToBoard"; import { ApplyModel2ToBoard } from "../Add-on/DrawBoard/ApplyModel2ToBoard";
@ -676,6 +677,7 @@ export function registerCommand()
commandMachine.RegisterCommand(CommandNames.Template, new ShowTemplate("Administration")); commandMachine.RegisterCommand(CommandNames.Template, new ShowTemplate("Administration"));
commandMachine.RegisterCommand(CommandNames.TemplateCollection, new ShowTemplate("Collection")); commandMachine.RegisterCommand(CommandNames.TemplateCollection, new ShowTemplate("Collection"));
commandMachine.RegisterCommand(CommandNames.TemplateDesign, new ShowTemplateDesign()); commandMachine.RegisterCommand(CommandNames.TemplateDesign, new ShowTemplateDesign());
commandMachine.RegisterCommand(CommandNames.Modeling, new Command_Modeling());
commandMachine.RegisterCommand(CommandNames.templateDelete, new Command_DeleteTemplate()); commandMachine.RegisterCommand(CommandNames.templateDelete, new Command_DeleteTemplate());
commandMachine.RegisterCommand(CommandNames.TemplateCheck, new Command_TemplateSearch(true)); commandMachine.RegisterCommand(CommandNames.TemplateCheck, new Command_TemplateSearch(true));
commandMachine.RegisterCommand(CommandNames.TemplateGroup, new Command_TemplateGroup()); commandMachine.RegisterCommand(CommandNames.TemplateGroup, new Command_TemplateGroup());

@ -2728,6 +2728,16 @@ export const CommandList: ICommand[] = [
chName: "模板设计", chName: "模板设计",
chDes: "", chDes: "",
}, },
{
icon: IconEnum.Modeling,
typeId: "temp",
link: `#`,
defaultCustom: CommandNames.Modeling,
command: CommandNames.Modeling,
type: "模板",
chName: "一键建模",
chDes: "一键建模",
},
{ {
icon: IconEnum.CutSpace, icon: IconEnum.CutSpace,
typeId: "temp", typeId: "temp",

@ -461,14 +461,14 @@ export class TemplateParamDetail extends React.Component<{}> {
//获取关联板件数 //获取关联板件数
GetAssociateBrNums(tr: TemplateRecord): number GetAssociateBrNums(tr: TemplateRecord): number
{ {
let p = tr.Positioning as PositioningClampSpace; let p = tr?.Positioning as PositioningClampSpace;
return p?.Objects?.length ?? 0; return p?.Objects?.length ?? 0;
} }
//获取板件切割方式 //获取板件切割方式
ShowSplitType = (tr: TemplateRecord) => ShowSplitType = (tr: TemplateRecord) =>
{ {
switch (tr.SplitType) switch (tr?.SplitType)
{ {
case TemplateSplitType.None: case TemplateSplitType.None:
return "空"; return "空";
@ -478,6 +478,8 @@ export class TemplateParamDetail extends React.Component<{}> {
return "Y"; return "Y";
case TemplateSplitType.Z: case TemplateSplitType.Z:
return "Z"; return "Z";
default:
return "空";
} }
}; };

Loading…
Cancel
Save