!2645 新增:虚拟空间绘制功能插入空间选项

pull/2682/MERGE
钱若寒 6 months ago committed by ChenX
parent 62c04621ff
commit c0a6d2b47f

@ -7,16 +7,19 @@ import * as xaop from 'xaop';
import { app } from "../../ApplicationServices/Application"; import { app } from "../../ApplicationServices/Application";
import { CheckObjectType } from '../../Common/CheckoutVaildValue'; import { CheckObjectType } from '../../Common/CheckoutVaildValue';
import { KeyBoard } from '../../Common/KeyEnum'; import { KeyBoard } from '../../Common/KeyEnum';
import { Log, LogType } from '../../Common/Log';
import { TransformVector } from '../../Common/Matrix4Utils'; import { TransformVector } from '../../Common/Matrix4Utils';
import { GetEntity } from '../../Common/Utils'; import { GetEntity } from '../../Common/Utils';
import { RoomBase } from '../../DatabaseServices/Room/Entity/RoomBase'; import { RoomBase } from '../../DatabaseServices/Room/Entity/RoomBase';
import { TemplateVisualSpace } from '../../DatabaseServices/Template/ProgramTempate/TemplateVisualSpace'; import { TemplateVisualSpace } from '../../DatabaseServices/Template/ProgramTempate/TemplateVisualSpace';
import { SetTemplatePositionAndSetParent } from '../../DatabaseServices/Template/TempateUtils';
import { Command } from "../../Editor/CommandMachine"; import { Command } from "../../Editor/CommandMachine";
import { JigUtils } from '../../Editor/JigUtils'; import { JigUtils } from '../../Editor/JigUtils';
import { PromptPointResult, PromptStatus } from "../../Editor/PromptResult"; import { PromptPointResult, PromptStatus } from "../../Editor/PromptResult";
import { ParsePlacePos, ParsePlacePosWithTemplate, ParsePlacePosWithTemplate2 } from '../../Editor/TranstrolControl/ParsePlacePos'; import { ParsePlacePos, ParsePlacePosWithTemplate, ParsePlacePosWithTemplate2 } from '../../Editor/TranstrolControl/ParsePlacePos';
import { VisualSpaceBox } from '../../Editor/VisualSpaceBox'; import { VisualSpaceBox } from '../../Editor/VisualSpaceBox';
import { ZeroVec, equalv3 } from '../../Geometry/GeUtils'; import { ZeroVec, equalv3 } from '../../Geometry/GeUtils';
import { PointSelectSpaceClamp } from '../../Geometry/SpaceParse/PointSelectSpaceClamp';
import { GetCompoentObjectIdString } from '../../UI/Components/ComponentObjectId'; import { GetCompoentObjectIdString } from '../../UI/Components/ComponentObjectId';
import { ModalState } from '../../UI/Components/Modal/ModalInterface'; import { ModalState } from '../../UI/Components/Modal/ModalInterface';
import { ToasterInput } from '../../UI/Components/Toaster'; import { ToasterInput } from '../../UI/Components/Toaster';
@ -40,120 +43,138 @@ export class DrawVisualSpaceBox implements Command
let res = await app.Editor.ModalManage.Wait(); let res = await app.Editor.ModalManage.Wait();
if (res.Status === ModalState.Ok) if (res.Status === ModalState.Ok)
{ {
let jigBox = new VisualSpaceBox(option.length, option.width, option.height); if (res.Data?.isInsertSpace)
JigUtils.Draw(jigBox);
let parsePosTypes = [ParsePlacePosWithTemplate2, ParsePlacePosWithTemplate, ParsePlacePos];
let parseType = 0;
let baseP = new Vector3;
const ApplyPos = (p: Vector3, i: Intersection) =>
{ {
if (i && (GetEntity(i.object) instanceof RoomBase)) let selectSpace = new PointSelectSpaceClamp();
await selectSpace.Select();
if (!selectSpace.ParseOK)
{ {
new (parsePosTypes[parseType])(jigBox, i, Log("请选择有效板件", LogType.Error);
(newLength: number) => return;
{
if (newLength < option.length)
jigBox.SetSize(newLength, jigBox.Width, jigBox.Height);
else
jigBox.SetSize(option.length, jigBox.Width, jigBox.Height);
return jigBox.Length;
},
(newWidth: number) =>
{
if (newWidth < option.width)
jigBox.SetSize(jigBox.Length, newWidth, jigBox.Height);
else
jigBox.SetSize(jigBox.Length, option.width, jigBox.Height);
return jigBox.Width;
},
(newHeight: number) =>
{
if (newHeight < option.height)
jigBox.SetSize(jigBox.Length, jigBox.Width, newHeight);
else
jigBox.SetSize(jigBox.Length, jigBox.Width, option.height);
return jigBox.Height;
}
);
} }
else localStorage.setItem(VS_BOX_KEY, JSON.stringify(toJS(option)));
let template = new TemplateVisualSpace();
template.InitBaseParams();
app.Database.TemplateTable.Append(template);
await SetTemplatePositionAndSetParent(selectSpace.SpaceParse, template);
}
else
{
let jigBox = new VisualSpaceBox(option.length, option.width, option.height);
JigUtils.Draw(jigBox);
let parsePosTypes = [ParsePlacePosWithTemplate2, ParsePlacePosWithTemplate, ParsePlacePos];
let parseType = 0;
let baseP = new Vector3;
const ApplyPos = (p: Vector3, i: Intersection) =>
{ {
if (equalv3(baseP, ZeroVec)) if (i && (GetEntity(i.object) instanceof RoomBase))
jigBox.Position = p; {
new (parsePosTypes[parseType])(jigBox, i,
(newLength: number) =>
{
if (newLength < option.length)
jigBox.SetSize(newLength, jigBox.Width, jigBox.Height);
else
jigBox.SetSize(option.length, jigBox.Width, jigBox.Height);
return jigBox.Length;
},
(newWidth: number) =>
{
if (newWidth < option.width)
jigBox.SetSize(jigBox.Length, newWidth, jigBox.Height);
else
jigBox.SetSize(jigBox.Length, option.width, jigBox.Height);
return jigBox.Width;
},
(newHeight: number) =>
{
if (newHeight < option.height)
jigBox.SetSize(jigBox.Length, jigBox.Width, newHeight);
else
jigBox.SetSize(jigBox.Length, jigBox.Width, option.height);
return jigBox.Height;
}
);
}
else else
jigBox.Position = TransformVector(baseP.clone(), jigBox.OCSNoClone).multiplyScalar(-1).add(p); {
} if (equalv3(baseP, ZeroVec))
}; jigBox.Position = p;
else
jigBox.Position = TransformVector(baseP.clone(), jigBox.OCSNoClone).multiplyScalar(-1).add(p);
}
};
let ptRes: PromptPointResult; let ptRes: PromptPointResult;
while (true) while (true)
{
let keys = [
{ key: "1", msg: "模块碰撞(实际尺寸)" },
{ key: "2", msg: "模块碰撞(参数尺寸)" },
{ key: "3", msg: "实体碰撞(无视模块)" },
];
keys[parseType].msg += "<当前>";
ptRes = await app.Editor.GetPoint({
Msg: "点击选择空间位置:",
Raycast: true,
KeyWordList: [
{ key: "S", msg: "插入空间" },
{ key: "B", msg: "基点" },
...keys
],
Callback: ApplyPos
});
if (ptRes.Status === PromptStatus.Keyword)
{ {
if (ptRes.StringResult === "B") let keys = [
{ key: "1", msg: "模块碰撞(实际尺寸)" },
{ key: "2", msg: "模块碰撞(参数尺寸)" },
{ key: "3", msg: "实体碰撞(无视模块)" },
];
keys[parseType].msg += "<当前>";
ptRes = await app.Editor.GetPoint({
Msg: "点击选择空间位置:",
Raycast: true,
KeyWordList: [
{ key: "S", msg: "插入空间" },
{ key: "B", msg: "基点" },
...keys
],
Callback: ApplyPos
});
if (ptRes.Status === PromptStatus.Keyword)
{ {
app.Editor.GetPointServices.snapServices.FilterErase = false; if (ptRes.StringResult === "B")
//给个id保证能被捕捉
jigBox.objectId = app.Database.ModelSpace.Id as any;
let baseRes = await app.Editor.GetPoint({ Msg: "点取新基点:" });
jigBox.objectId = undefined;
app.Editor.GetPointServices.snapServices.FilterErase = true;
if (baseRes.Status === PromptStatus.OK)
{ {
baseP.copy(baseRes.Point); app.Editor.GetPointServices.snapServices.FilterErase = false;
baseP.applyMatrix4(jigBox.OCSInv); //给个id保证能被捕捉
jigBox.objectId = app.Database.ModelSpace.Id as any;
let baseRes = await app.Editor.GetPoint({ Msg: "点取新基点:" });
jigBox.objectId = undefined;
app.Editor.GetPointServices.snapServices.FilterErase = true;
if (baseRes.Status === PromptStatus.OK)
{
baseP.copy(baseRes.Point);
baseP.applyMatrix4(jigBox.OCSInv);
}
} }
} else if (ptRes.StringResult === "1" || ptRes.StringResult === "2" || ptRes.StringResult === "3")
else if (ptRes.StringResult === "1" || ptRes.StringResult === "2" || ptRes.StringResult === "3") {
{ parseType = parseInt(ptRes.StringResult) - 1;
parseType = parseInt(ptRes.StringResult) - 1; }
else
break;
} }
else else
break; break;
} }
else
break;
}
if (ptRes.Status === PromptStatus.OK) if (ptRes.Status === PromptStatus.OK)
{ {
ApplyPos(ptRes.Point, ptRes.intersection); ApplyPos(ptRes.Point, ptRes.intersection);
localStorage.setItem(VS_BOX_KEY, JSON.stringify(toJS(option))); localStorage.setItem(VS_BOX_KEY, JSON.stringify(toJS(option)));
let template = new TemplateVisualSpace(); let template = new TemplateVisualSpace();
template.InitBaseParams(); template.InitBaseParams();
app.Database.TemplateTable.Append(template); app.Database.TemplateTable.Append(template);
template.LParam.expr = jigBox.Length; template.LParam.expr = jigBox.Length;
template.WParam.expr = jigBox.Width; template.WParam.expr = jigBox.Width;
template.HParam.expr = jigBox.Height; template.HParam.expr = jigBox.Height;
await template.UpdateTemplateTree(); await template.UpdateTemplateTree();
let boxEnt = template.Objects[0].Object as VisualSpaceBox; let boxEnt = template.Objects[0].Object as VisualSpaceBox;
boxEnt.ApplyMatrix(jigBox.OCSNoClone); boxEnt.ApplyMatrix(jigBox.OCSNoClone);
}
} }
} }
} }
} }
@ -208,11 +229,16 @@ class DrawVisualSpaceBoxModal extends React.Component<{ option: IVSProps; }, {}>
</Label> </Label>
) )
} }
<div className="right"> <div className="right flex-between" style={{ width: 180 }}>
<Button
className={Classes.INTENT_PRIMARY}
text="插入空间"
onClick={() => this.onOk({ isInsertSpace: true })}
/>
<Button <Button
text="确定" text="确定"
intent={Intent.SUCCESS} intent={Intent.SUCCESS}
onClick={this.onOk} onClick={() => this.onOk()}
/> />
<Button <Button
text="取消" text="取消"
@ -223,7 +249,7 @@ class DrawVisualSpaceBoxModal extends React.Component<{ option: IVSProps; }, {}>
</Card> </Card>
); );
} }
private onOk = () => private onOk = (isInsertSpace?) =>
{ {
const option = this.props.option; const option = this.props.option;
if (option.length <= 0 || option.width <= 0 || option.height <= 0) if (option.length <= 0 || option.width <= 0 || option.height <= 0)
@ -236,7 +262,10 @@ class DrawVisualSpaceBoxModal extends React.Component<{ option: IVSProps; }, {}>
return; return;
} }
app.Editor.ModalManage.m_PromisRes({ app.Editor.ModalManage.m_PromisRes({
Status: ModalState.Ok Status: ModalState.Ok,
Data: {
isInsertSpace
}
}); });
app.Editor.ModalManage.Destory(); app.Editor.ModalManage.Destory();
}; };

Loading…
Cancel
Save