mirror of https://gitee.com/cf-fz/WebCAD.git
parent
f4605cf382
commit
2bd87a62e0
@ -0,0 +1,15 @@
|
||||
import { Command } from "../Editor/CommandMachine";
|
||||
import { app } from "../ApplicationServices/Application";
|
||||
|
||||
|
||||
export class Command_Ssget implements Command
|
||||
{
|
||||
constructor()
|
||||
{
|
||||
|
||||
}
|
||||
async exec()
|
||||
{
|
||||
let ss = app.m_Editor.GetSelection();
|
||||
}
|
||||
}
|
@ -0,0 +1,125 @@
|
||||
import { begin, end } from 'xaop';
|
||||
|
||||
import { InputState, SsgetPrompt } from '../Common/InputState';
|
||||
import { KeyBoard, MouseKey } from '../Common/KeyEnum';
|
||||
import { RenderType } from '../GraphicsSystem/Enum';
|
||||
import { Editor } from './Editor';
|
||||
import { PromptSsgetResult, PromptStatus } from './PromptResult';
|
||||
import { SelectPick } from './SelectPick';
|
||||
|
||||
/**
|
||||
* 提供选择状态的服务. ed.Ssget
|
||||
*
|
||||
* @class SsgetServiecs
|
||||
*/
|
||||
export class SsgetServiecs
|
||||
{
|
||||
|
||||
|
||||
m_Editor: Editor;
|
||||
constructor(ed: Editor)
|
||||
{
|
||||
this.m_Editor = ed;
|
||||
}
|
||||
|
||||
private promisResolve: (res: PromptSsgetResult) => void;//promis回调
|
||||
Start(prompt?: SsgetPrompt): Promise<PromptSsgetResult>
|
||||
{
|
||||
this.m_Editor.m_InputState &= InputState.Select;
|
||||
|
||||
return new Promise<PromptSsgetResult>(
|
||||
async (res, rej) =>
|
||||
{
|
||||
this.promisResolve = res;
|
||||
|
||||
while (true)
|
||||
{
|
||||
let enRes = await this.m_Editor.GetEntity();
|
||||
|
||||
if (enRes.Status === PromptStatus.Cancel) //取消.(esc)
|
||||
{
|
||||
this.CanelRetun();
|
||||
//取消选择
|
||||
break;
|
||||
}
|
||||
else if (enRes.Status === PromptStatus.None)//结束 (右键),或者(空格).
|
||||
{
|
||||
//结束并且确认选择
|
||||
this.Return({ Status: PromptStatus.OK, SelectSet: this.m_Editor.m_SelectCtrl.SelectSet });
|
||||
break;
|
||||
}
|
||||
else if (enRes.Status === PromptStatus.OK)//点击选择 (左键)
|
||||
{
|
||||
if (enRes.Entity)//选到了实体
|
||||
{
|
||||
let ssEnt = new SelectPick(this.m_Editor.m_App.m_Viewer, this.m_Editor.m_MouseCtrl.m_CurMousePointVCS);
|
||||
ssEnt.m_SelectList.push(enRes.Entity.Draw(RenderType.Wireframe));
|
||||
|
||||
if (this.m_Editor.m_KeyCtrl.KeyIsDown(KeyBoard.Shift))
|
||||
this.m_Editor.m_SelectCtrl.SelectSet.RemoveSelect(ssEnt);
|
||||
else
|
||||
this.m_Editor.m_SelectCtrl.SelectSet.AddSelect(ssEnt);
|
||||
|
||||
this.m_Editor.m_SelectCtrl.UpdateView();
|
||||
}
|
||||
else//没有选择到实体,触发框选
|
||||
{
|
||||
this.m_Editor.m_SelectCtrl.LeftClick();
|
||||
//等待用户选到
|
||||
let isOk = await this.AwaitSelect();
|
||||
if (!isOk)
|
||||
{
|
||||
this.CanelRetun();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
//返回取消状态
|
||||
private CanelRetun()
|
||||
{
|
||||
this.Return({ Status: PromptStatus.Cancel });
|
||||
}
|
||||
|
||||
protected Return(res: PromptSsgetResult)
|
||||
{
|
||||
if (!this.promisResolve) return;
|
||||
this.promisResolve(res);
|
||||
}
|
||||
|
||||
|
||||
private m_AwaitRemoveCalls: Function[] = [];
|
||||
private m_AwaitRes: (state: boolean) => void;
|
||||
async AwaitSelect(): Promise<boolean>
|
||||
{
|
||||
return new Promise<boolean>((res, rej) =>
|
||||
{
|
||||
this.m_AwaitRes = res;
|
||||
this.m_AwaitRemoveCalls.push(
|
||||
end(this.m_Editor.m_SelectCtrl, this.m_Editor.m_SelectCtrl.EndSelectEvent, () =>
|
||||
{
|
||||
this._AwaitSelctReturn(true);
|
||||
}),
|
||||
end(this.m_Editor.m_SelectCtrl, this.m_Editor.m_SelectCtrl.CanenEvent, () =>
|
||||
{
|
||||
this._AwaitSelctReturn(false);
|
||||
}),
|
||||
)
|
||||
});
|
||||
}
|
||||
private _AwaitSelctReturn(state: boolean)
|
||||
{
|
||||
if (!this.m_AwaitRes) return;
|
||||
this.m_AwaitRemoveCalls.forEach(f => f());
|
||||
this.m_AwaitRemoveCalls.length = 0;
|
||||
this.m_AwaitRes(state);
|
||||
this.m_AwaitRes = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in new issue