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

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

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

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

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

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

@ -1,8 +1,6 @@
/** /**
* ,. * ,.
*
* @export
* @enum {number} * @enum {number}
*/ */
export enum InputState 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 get Positioning(): Positioning
{ {
return this.positioning; return this.positioning;

@ -5,14 +5,17 @@ import { commandMachine } from "../../Editor/CommandMachine";
import { PromptSsgetResult, PromptStatus } from "../../Editor/PromptResult"; import { PromptSsgetResult, PromptStatus } from "../../Editor/PromptResult";
import { SelectBox, SelectType } from "../../Editor/SelectBox"; import { SelectBox, SelectType } from "../../Editor/SelectBox";
import { AsVector3, equalv3, MoveMatrix, ZeroVec } from "../../Geometry/GeUtils"; 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 { HotCMD } from "../../Hot/HotCommand";
import { Board } from "../Entity/Board"; import { Board } from "../Entity/Board";
import { TemplateAction } from "./Action/TemplateAction"; import { TemplateAction } from "./Action/TemplateAction";
import { TemplateMoveAction } from "./Action/TemplateMoveAction"; import { TemplateMoveAction } from "./Action/TemplateMoveAction";
import { TemplateStretchGripAction } from "./Action/TemplateStretchGripAction"; import { TemplateStretchGripAction } from "./Action/TemplateStretchGripAction";
import { TemplateStretchScaleBoxAction } from "./Action/TemplateStretchScaleBoxAction"; import { TemplateStretchScaleBoxAction } from "./Action/TemplateStretchScaleBoxAction";
import { PositioningClampSpace } from "./Positioning/PositioningClampSpace";
import { TemplateRecord } from "./TemplateRecord"; import { TemplateRecord } from "./TemplateRecord";
import { ClampSpaceParse } from "../../Geometry/SpaceParse/ClampSpaceParse";
import { PositioningClampSpace } from "./Positioning/PositioningClampSpace";
/** /**
* *
@ -409,39 +412,57 @@ export class TemplateAttach
{ {
async exec() async exec()
{ {
let en1Res = await app.m_Editor.GetEntity({ Msg: "选择源模板" }); let enRes = await app.m_Editor.GetEntity({
if (en1Res.Status !== PromptStatus.OK) return; 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: "选择附加的模版" }); let e = enRes.Entity;
if (en2Res.Status !== PromptStatus.OK) return; let template = e.Template.Object as TemplateRecord;
let e1 = en1Res.Entity; let selectSpace = new PointSelectSpaceClamp();
let e2 = en2Res.Entity; 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; app.m_Editor.Prompt("未能分析出有效空间!");
let tem2 = e2.Template.Object as TemplateRecord; return;
}
let selRes = await app.m_Editor.GetSelection({
Msg: "请选择空间:", let parse = selectSpace.SpaceParse as ClampSpaceParse;
Filter: { let brs = parse.m_Boards;
filterTypes: [Board],
filterFunction: (obj, ent) => let positioning = new PositioningClampSpace();
{ positioning.FromSpaceParse(parse);
return tem1.Objects.includes(ent.Id); template.Positioning = positioning;
} await template.UpdateTemplate();//单独更新 不继承
}
}); let tbrs = brs.filter(br => br.Template !== undefined);
if (selRes.Status === PromptStatus.OK) if (tbrs.length === 0)
{
app.m_Editor.Prompt("选取的空间不存在模版!");
}
else
{
tbrs.sort((b1, b2) =>
{ {
let positioning = new PositioningClampSpace(); let t1 = b1.Template.Object as TemplateRecord;
positioning.Objects = selRes.SelectSet.SelectEntityList.map(e => e.Id); let t2 = b2.Template.Object as TemplateRecord;
tem2.Positioning = positioning;
tem1.Children.push(tem2.Id); return t2.NodeDepth - t1.NodeDepth;
await tem1.UpdateTemplate(null, true); });
}
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 export class GetEntityServices implements EditorService
{ {
m_Editor: Editor; _Editor: Editor;
private m_Viewer: Viewer; private m_Viewer: Viewer;
constructor(ed: Editor) constructor(ed: Editor)
{ {
this.m_Editor = ed; this._Editor = ed;
this.m_Viewer = ed.m_App.m_Viewer; this.m_Viewer = ed.m_App.m_Viewer;
} }
IsReady: boolean = false; IsReady: boolean = false;
@ -41,22 +41,22 @@ export class GetEntityServices implements EditorService
prompt = prompt || {}; prompt = prompt || {};
this.prompt = prompt; this.prompt = prompt;
this.m_Editor.m_InputState |= InputState.Entsel; this._Editor.m_InputState |= InputState.Entsel;
if (!prompt.IsSelect) if (!prompt.IsSelect)
this.m_Editor.m_SelectCtrl.Cancel(); this._Editor.m_SelectCtrl.Cancel();
//光标变换 //光标变换
this.m_Viewer.m_PreViewer.Cursor.Mode = CursorMode.GetEntity; 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) if (prompt.Callback)
{ {
prompt.Callback(this.HandleMouseMove()); prompt.Callback(this.PickEntity());
this.removeCalls.push( this.removeCalls.push(
end(mouseCtrl, mouseCtrl.onMouseMove, end(mouseCtrl, mouseCtrl.onMouseMove,
() => { prompt.Callback(this.HandleMouseMove()) } () => { prompt.Callback(this.PickEntity()) }
) )
) )
} }
@ -106,7 +106,7 @@ export class GetEntityServices implements EditorService
} }
initHandleInput(prompt: GetEntityPrompt) 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) if (prompt.KeyWordList)
{ {
@ -130,7 +130,7 @@ export class GetEntityServices implements EditorService
initHandleKeyDown() initHandleKeyDown()
{ {
this.removeCalls.push( 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) switch (e.keyCode as KeyBoard)
{ {
@ -153,7 +153,11 @@ export class GetEntityServices implements EditorService
{ {
case MouseKey.Left: 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; return true;
} }
case MouseKey.Right: case MouseKey.Right:
@ -179,28 +183,31 @@ export class GetEntityServices implements EditorService
})); }));
dyn.SetPostion(mouseCtrl.m_CurMousePointVCS); 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(); let ret = new PromptEntityResult();
if (pickObj && IsEntity(pickObj)) if (pickObj && IsEntity(pickObj))
ret.Entity = GetEntity(pickObj); ret.Entity = GetEntity(pickObj);
ret.Object = 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; ret.Status = ret.Entity ? PromptStatus.OK : PromptStatus.None;
return ret; return ret;
} }
//还原状态 //还原状态
private RestState() private RestState()
{ {
this.IsReady = false; this.IsReady = false;
this.prompt = undefined; 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.m_Viewer.m_PreViewer.Cursor.Mode = CursorMode.None;
this.removeCalls.forEach(f => f()); this.removeCalls.forEach(f => f());
this.removeCalls.length = 0; this.removeCalls.length = 0;
} }
private Retun(result: PromptEntityResult) private Retun(result: PromptEntityResult)
{ {
if (!this.m_promisResolve) if (!this.m_promisResolve)

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

@ -3,21 +3,54 @@ import { Board } from "../../DatabaseServices/Entity/Board";
import { PromptStatus, PromptPointResult } from "../../Editor/PromptResult"; import { PromptStatus, PromptPointResult } from "../../Editor/PromptResult";
import { PointSelectBoards } from "./PointSelectBoards"; import { PointSelectBoards } from "./PointSelectBoards";
import { ISpaceParse } from "./ISpaceParse"; 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 export class PointSelectSpace
{ {
m_SpaceParse: ISpaceParse; SpaceParse: ISpaceParse;
m_GetPointRes: PromptPointResult; GetPointRes: PromptPointResult;
Enable = EnableSelectType.All;
async Select() 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: "点选画板区域", Msg: "点选画板区域",
AllowNone: true, 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 view = app.m_Viewer;
let vcs = app.m_Editor.m_MouseCtrl.m_CurMousePointVCS; let vcs = app.m_Editor.m_MouseCtrl.m_CurMousePointVCS;
@ -29,20 +62,20 @@ export class PointSelectSpace
await this.ParseByPointSelect(ptSelect); 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] } }); let ssRes = await app.m_Editor.GetSelection({ UseSelect: true, Filter: { filterTypes: [Board] } });
if (ssRes.Status === PromptStatus.OK) if (ssRes.Status === PromptStatus.OK)
await this.ParseBySelect(ssRes.SelectSet.SelectEntityList as Board[]); 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; app.m_Editor.GetPointServices.snapServices.Disabled = false;
await this.ParseBy2Point(); await this.ParseBy2Point();
} }
else if (this.m_GetPointRes.StringResult === "3") else if (this.GetPointRes.StringResult === "3")
{ {
app.m_Editor.GetPointServices.snapServices.Disabled = false; app.m_Editor.GetPointServices.snapServices.Disabled = false;
await this.ParseBy3Point(); await this.ParseBy3Point();
@ -52,7 +85,7 @@ export class PointSelectSpace
get ParseOK(): boolean 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[]) protected async ParseBySelect(brs: Board[])
{ {
this.m_SpaceParse = new ClampSpaceParseKey(brs); this.SpaceParse = new ClampSpaceParseKey(brs);
await this.m_SpaceParse.Parse(); await this.SpaceParse.Parse();
} }
protected async ParseByPointSelect(ptSelect: PointSelectBoards) protected async ParseByPointSelect(ptSelect: PointSelectBoards)
{ {
this.m_SpaceParse = new ClampSpaceParseRay(ptSelect.SelectBoards).SetRay(ptSelect.Ray); this.SpaceParse = new ClampSpaceParseRay(ptSelect.SelectBoards).SetRay(ptSelect.Ray);
await this.m_SpaceParse.Parse(); await this.SpaceParse.Parse();
} }
protected async ParseBy2Point() protected async ParseBy2Point()
{ {
this.m_SpaceParse = new Point2SpaceParse([]); this.SpaceParse = new Point2SpaceParse([]);
await this.m_SpaceParse.Parse(); await this.SpaceParse.Parse();
} }
protected async ParseBy3Point() protected async ParseBy3Point()
{ {
this.m_SpaceParse = new Point3SpaceParse([]); this.SpaceParse = new Point3SpaceParse([]);
await this.m_SpaceParse.Parse(); await this.SpaceParse.Parse();
} }
} }

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

Loading…
Cancel
Save