优化模版Attach实现

pull/347/head
ChenX 5 years ago
parent 7e68f495b5
commit 3cf98d905f

@ -53,7 +53,7 @@ export abstract class DrawBoardTool implements Command
let selectSpace = new PointSelectSpaceClamp();
await selectSpace.Select();
if (selectSpace.m_GetPointRes.Status === PromptStatus.None)
if (selectSpace.GetPointRes.Status === PromptStatus.None)
{
app.m_Editor.m_ModalManage.RenderModeless(
BoardModal,
@ -64,7 +64,7 @@ export abstract class DrawBoardTool implements Command
if (!selectSpace.ParseOK)
break;
this.space = selectSpace.m_SpaceParse;
this.space = selectSpace.SpaceParse;
//用周围板件加工数据
if (this.store.UseBoardProcessOption && this.space.m_Boards.length > 0)
this.store.GetBoardProcessOption(this.space.m_Boards[0]);

@ -22,7 +22,7 @@ export class DrawDoor implements Command
if (!selectSpace.ParseOK)
return;
let spaceParse = selectSpace.m_SpaceParse;
let spaceParse = selectSpace.SpaceParse;
let size = spaceParse.Size;
let store = DoorStore.GetInstance() as DoorStore;

@ -15,7 +15,7 @@ export class DrawDrawrer implements Command
if (!selectSpace.ParseOK)
return;
let spaceParse = selectSpace.m_SpaceParse;
let spaceParse = selectSpace.SpaceParse;
let size = spaceParse.Size;
let store = DrawerStore.GetInstance() as DrawerStore;

@ -34,7 +34,7 @@ export class DrawTopBottomBoard implements Command
let topOpt = this.store.topBoardOption;
let bottomOpt = this.store.bottomBoardOption;
let space = selectSpace.m_SpaceParse;
let space = selectSpace.SpaceParse;
if (topOpt.isDraw)
{
let basePt = this.GetTopBoardBasePt(topOpt, space);

@ -11,7 +11,7 @@ export class DrawWineRack implements Command
await selectSpace.Select();
if (!selectSpace.ParseOK)
return;
let space = selectSpace.m_SpaceParse;
let space = selectSpace.SpaceParse;
const tool = DrawUprightWineRackTool.GetInstance() as DrawUprightWineRackTool;
tool.Draw(space);
}
@ -24,7 +24,7 @@ export class DrawWineRack2 implements Command
await selectSpace.Select();
if (!selectSpace.ParseOK)
return;
let space = selectSpace.m_SpaceParse;
let space = selectSpace.SpaceParse;
const tool = DrawBlisWineRackTool.GetInstance() as DrawBlisWineRackTool;
tool.Draw(space);
}

@ -24,6 +24,6 @@ export class DrawLattice implements Command
return;
let tool = DrawLatticeDrawerTool.GetInstance() as DrawLatticeDrawerTool;
tool.Draw(selectSpace.m_SpaceParse);
tool.Draw(selectSpace.SpaceParse);
}
}

@ -1,8 +1,6 @@
/**
* ,.
*
* @export
* @enum {number}
*/
export enum InputState

@ -69,6 +69,22 @@ export class TemplateRecord extends SymbolTableRecord
});
}
/**
*
*/
get NodeDepth()
{
let parent = this.Parent;
let depth = 0;
while (parent)
{
depth++;
let template = parent.Object as TemplateRecord;
parent = template.Parent;
}
return depth;
}
get Positioning(): Positioning
{
return this.positioning;

@ -5,14 +5,17 @@ import { commandMachine } from "../../Editor/CommandMachine";
import { PromptSsgetResult, PromptStatus } from "../../Editor/PromptResult";
import { SelectBox, SelectType } from "../../Editor/SelectBox";
import { AsVector3, equalv3, MoveMatrix, ZeroVec } from "../../Geometry/GeUtils";
import { EnableSelectType } from "../../Geometry/SpaceParse/PointSelectSpace";
import { PointSelectSpaceClamp } from "../../Geometry/SpaceParse/PointSelectSpaceClamp";
import { HotCMD } from "../../Hot/HotCommand";
import { Board } from "../Entity/Board";
import { TemplateAction } from "./Action/TemplateAction";
import { TemplateMoveAction } from "./Action/TemplateMoveAction";
import { TemplateStretchGripAction } from "./Action/TemplateStretchGripAction";
import { TemplateStretchScaleBoxAction } from "./Action/TemplateStretchScaleBoxAction";
import { PositioningClampSpace } from "./Positioning/PositioningClampSpace";
import { TemplateRecord } from "./TemplateRecord";
import { ClampSpaceParse } from "../../Geometry/SpaceParse/ClampSpaceParse";
import { PositioningClampSpace } from "./Positioning/PositioningClampSpace";
/**
*
@ -409,39 +412,57 @@ export class TemplateAttach
{
async exec()
{
let en1Res = await app.m_Editor.GetEntity({ Msg: "选择源模板" });
if (en1Res.Status !== PromptStatus.OK) return;
let enRes = await app.m_Editor.GetEntity({
Msg: "选择附加的模版",
NotNone: true,
Filter: {
filterFunction: (obj, ent) =>
{
return ent.Template !== undefined;
}
}
});
if (enRes.Status !== PromptStatus.OK) return;
let en2Res = await app.m_Editor.GetEntity({ Msg: "选择附加的模版" });
if (en2Res.Status !== PromptStatus.OK) return;
let e = enRes.Entity;
let template = e.Template.Object as TemplateRecord;
let e1 = en1Res.Entity;
let e2 = en2Res.Entity;
let selectSpace = new PointSelectSpaceClamp();
selectSpace.Enable = EnableSelectType.Stretch;
await selectSpace.Select();
if (e1.Template && e2.Template && e1.Template !== e2.Template)
if (!selectSpace.ParseOK)
{
let tem1 = e1.Template.Object as TemplateRecord;
let tem2 = e2.Template.Object as TemplateRecord;
let selRes = await app.m_Editor.GetSelection({
Msg: "请选择空间:",
Filter: {
filterTypes: [Board],
filterFunction: (obj, ent) =>
{
return tem1.Objects.includes(ent.Id);
}
}
});
if (selRes.Status === PromptStatus.OK)
app.m_Editor.Prompt("未能分析出有效空间!");
return;
}
let parse = selectSpace.SpaceParse as ClampSpaceParse;
let brs = parse.m_Boards;
let positioning = new PositioningClampSpace();
positioning.FromSpaceParse(parse);
template.Positioning = positioning;
await template.UpdateTemplate();//单独更新 不继承
let tbrs = brs.filter(br => br.Template !== undefined);
if (tbrs.length === 0)
{
app.m_Editor.Prompt("选取的空间不存在模版!");
}
else
{
tbrs.sort((b1, b2) =>
{
let positioning = new PositioningClampSpace();
positioning.Objects = selRes.SelectSet.SelectEntityList.map(e => e.Id);
tem2.Positioning = positioning;
let t1 = b1.Template.Object as TemplateRecord;
let t2 = b2.Template.Object as TemplateRecord;
tem1.Children.push(tem2.Id);
await tem1.UpdateTemplate(null, true);
}
return t2.NodeDepth - t1.NodeDepth;
});
let templateSource = tbrs[0].Template.Object as TemplateRecord;
templateSource.Children.push(template.Id);
}
}
}

@ -22,11 +22,11 @@ import { PromptEntityResult, PromptStatus } from './PromptResult';
*/
export class GetEntityServices implements EditorService
{
m_Editor: Editor;
_Editor: Editor;
private m_Viewer: Viewer;
constructor(ed: Editor)
{
this.m_Editor = ed;
this._Editor = ed;
this.m_Viewer = ed.m_App.m_Viewer;
}
IsReady: boolean = false;
@ -41,22 +41,22 @@ export class GetEntityServices implements EditorService
prompt = prompt || {};
this.prompt = prompt;
this.m_Editor.m_InputState |= InputState.Entsel;
this._Editor.m_InputState |= InputState.Entsel;
if (!prompt.IsSelect)
this.m_Editor.m_SelectCtrl.Cancel();
this._Editor.m_SelectCtrl.Cancel();
//光标变换
this.m_Viewer.m_PreViewer.Cursor.Mode = CursorMode.GetEntity;
let mouseCtrl = this.m_Editor.m_MouseCtrl;
let mouseCtrl = this._Editor.m_MouseCtrl;
//鼠标移动
if (prompt.Callback)
{
prompt.Callback(this.HandleMouseMove());
prompt.Callback(this.PickEntity());
this.removeCalls.push(
end(mouseCtrl, mouseCtrl.onMouseMove,
() => { prompt.Callback(this.HandleMouseMove()) }
() => { prompt.Callback(this.PickEntity()) }
)
)
}
@ -106,7 +106,7 @@ export class GetEntityServices implements EditorService
}
initHandleInput(prompt: GetEntityPrompt)
{
this.removeCalls.push(end(this.m_Editor, this.m_Editor.InputEvent, (input: string) =>
this.removeCalls.push(end(this._Editor, this._Editor.InputEvent, (input: string) =>
{
if (prompt.KeyWordList)
{
@ -130,7 +130,7 @@ export class GetEntityServices implements EditorService
initHandleKeyDown()
{
this.removeCalls.push(
end(this.m_Editor.m_KeyCtrl, this.m_Editor.m_KeyCtrl.OnKeyDown, (e: KeyboardEvent) =>
end(this._Editor.m_KeyCtrl, this._Editor.m_KeyCtrl.OnKeyDown, (e: KeyboardEvent) =>
{
switch (e.keyCode as KeyBoard)
{
@ -153,7 +153,11 @@ export class GetEntityServices implements EditorService
{
case MouseKey.Left:
{
this.Retun(this.HandleMouseMove());
let res = this.PickEntity();
if (!this.prompt.NotNone || res.Status === PromptStatus.OK)
this.Retun(this.PickEntity());
else
this._Editor.Prompt("禁止空选择!");
return true;
}
case MouseKey.Right:
@ -179,28 +183,31 @@ export class GetEntityServices implements EditorService
}));
dyn.SetPostion(mouseCtrl.m_CurMousePointVCS);
}
private HandleMouseMove(): PromptEntityResult
private PickEntity(): PromptEntityResult
{
let pickObj = PointPick(this.m_Editor.m_MouseCtrl.m_CurMousePointVCS, this.m_Viewer, this.prompt.Filter)[0];
let pickObj = PointPick(this._Editor.m_MouseCtrl.m_CurMousePointVCS, this.m_Viewer, this.prompt.Filter)[0];
let ret = new PromptEntityResult();
if (pickObj && IsEntity(pickObj))
ret.Entity = GetEntity(pickObj);
ret.Object = pickObj;
ret.Point = this.m_Editor.m_MouseCtrl.m_CurMousePointWCS.clone();
ret.Point = this._Editor.m_MouseCtrl.m_CurMousePointWCS.clone();
ret.Status = ret.Entity ? PromptStatus.OK : PromptStatus.None;
return ret;
}
//还原状态
private RestState()
{
this.IsReady = false;
this.prompt = undefined;
this.m_Editor.m_InputState &= ~InputState.Entsel;
this._Editor.m_InputState &= ~InputState.Entsel;
this.m_Viewer.m_PreViewer.Cursor.Mode = CursorMode.None;
this.removeCalls.forEach(f => f());
this.removeCalls.length = 0;
}
private Retun(result: PromptEntityResult)
{
if (!this.m_promisResolve)

@ -49,6 +49,7 @@ export interface PromptRectPointOptions extends PromptOptions
export interface GetEntityPrompt extends PromptOptions
{
NotNone?: boolean; //禁止空选择
IsSelect?: boolean;
Filter?: Filter;
Callback?: (res: PromptEntityResult) => void;

@ -3,21 +3,54 @@ import { Board } from "../../DatabaseServices/Entity/Board";
import { PromptStatus, PromptPointResult } from "../../Editor/PromptResult";
import { PointSelectBoards } from "./PointSelectBoards";
import { ISpaceParse } from "./ISpaceParse";
import { KeyWord } from "../../Common/InputState";
export enum EnableSelectType
{
Stretch = 1,
Two = 2,
Three = 4,
All = ~(~0 << 3)
}
const StretchKeyWord = { msg: "框选", key: "S" };
const TwoKeyWord = { msg: "2点", key: "2" };
const ThreeKeyWord = { msg: "3点", key: "3" };
const AllKeyWordList = [StretchKeyWord, TwoKeyWord, ThreeKeyWord, { msg: "放弃", key: "U" }];
export class PointSelectSpace
{
m_SpaceParse: ISpaceParse;
m_GetPointRes: PromptPointResult;
SpaceParse: ISpaceParse;
GetPointRes: PromptPointResult;
Enable = EnableSelectType.All;
async Select()
{
this.m_GetPointRes = await app.m_Editor.GetPoint({
let KeyWordList: KeyWord[];
if (this.Enable === EnableSelectType.All)
KeyWordList = AllKeyWordList;
else
{
KeyWordList = [];
if (this.Enable & EnableSelectType.Stretch)
KeyWordList.push(StretchKeyWord);
if (this.Enable & EnableSelectType.Two)
KeyWordList.push(TwoKeyWord);
if (this.Enable & EnableSelectType.Three)
KeyWordList.push(ThreeKeyWord);
KeyWordList.push({ msg: "放弃", key: "U" });
}
this.GetPointRes = await app.m_Editor.GetPoint({
Msg: "点选画板区域",
AllowNone: true,
KeyWordList: [{ msg: "框选", key: "S" }, { msg: "2点", key: "2" }, { msg: "3点", key: "3" }, { msg: "放弃", key: "U" }]
KeyWordList
});
//点选
if (this.m_GetPointRes.Status === PromptStatus.OK)
if (this.GetPointRes.Status === PromptStatus.OK)
{
let view = app.m_Viewer;
let vcs = app.m_Editor.m_MouseCtrl.m_CurMousePointVCS;
@ -29,20 +62,20 @@ export class PointSelectSpace
await this.ParseByPointSelect(ptSelect);
}
//框选
else if (this.m_GetPointRes.Status === PromptStatus.Keyword)
else if (this.GetPointRes.Status === PromptStatus.Keyword)
{
if (this.m_GetPointRes.StringResult === "S")
if (this.GetPointRes.StringResult === "S")
{
let ssRes = await app.m_Editor.GetSelection({ UseSelect: true, Filter: { filterTypes: [Board] } });
if (ssRes.Status === PromptStatus.OK)
await this.ParseBySelect(ssRes.SelectSet.SelectEntityList as Board[]);
}
else if (this.m_GetPointRes.StringResult === "2")
else if (this.GetPointRes.StringResult === "2")
{
app.m_Editor.GetPointServices.snapServices.Disabled = false;
await this.ParseBy2Point();
}
else if (this.m_GetPointRes.StringResult === "3")
else if (this.GetPointRes.StringResult === "3")
{
app.m_Editor.GetPointServices.snapServices.Disabled = false;
await this.ParseBy3Point();
@ -52,7 +85,7 @@ export class PointSelectSpace
get ParseOK(): boolean
{
return this.m_SpaceParse !== undefined && this.m_SpaceParse.m_ParseOK;
return this.SpaceParse !== undefined && this.SpaceParse.m_ParseOK;
}
/**

@ -10,23 +10,23 @@ export class PointSelectSpaceClamp extends PointSelectSpace
{
protected async ParseBySelect(brs: Board[])
{
this.m_SpaceParse = new ClampSpaceParseKey(brs);
await this.m_SpaceParse.Parse();
this.SpaceParse = new ClampSpaceParseKey(brs);
await this.SpaceParse.Parse();
}
protected async ParseByPointSelect(ptSelect: PointSelectBoards)
{
this.m_SpaceParse = new ClampSpaceParseRay(ptSelect.SelectBoards).SetRay(ptSelect.Ray);
await this.m_SpaceParse.Parse();
this.SpaceParse = new ClampSpaceParseRay(ptSelect.SelectBoards).SetRay(ptSelect.Ray);
await this.SpaceParse.Parse();
}
protected async ParseBy2Point()
{
this.m_SpaceParse = new Point2SpaceParse([]);
await this.m_SpaceParse.Parse();
this.SpaceParse = new Point2SpaceParse([]);
await this.SpaceParse.Parse();
}
protected async ParseBy3Point()
{
this.m_SpaceParse = new Point3SpaceParse([]);
await this.m_SpaceParse.Parse();
this.SpaceParse = new Point3SpaceParse([]);
await this.SpaceParse.Parse();
}
}

@ -7,13 +7,13 @@ export class PointSelectSpaceSurround extends PointSelectSpace
{
protected async ParseBySelect(brs: Board[])
{
this.m_SpaceParse = new SurroundSpaceParse(brs);
await this.m_SpaceParse.Parse();
this.SpaceParse = new SurroundSpaceParse(brs);
await this.SpaceParse.Parse();
}
protected async ParseByPointSelect(ptSelect: PointSelectBoards)
{
this.m_SpaceParse = new SurroundSpaceParse(ptSelect.SelectBoards);
await this.m_SpaceParse.Parse();
this.SpaceParse = new SurroundSpaceParse(ptSelect.SelectBoards);
await this.SpaceParse.Parse();
}
}

Loading…
Cancel
Save