!343 重构右键菜单的触发方式

Merge pull request !343 from ChenX/editor_mouse_handle
pull/343/MERGE
ChenX 5 years ago
parent f32dc18486
commit 6be21fb7be

@ -45,8 +45,8 @@ export abstract class DrawBoardTool implements Command
private async SelectAndBuildBoard()
{
//原来禁用捕捉开启状态
let oldSnapState = app.m_Editor.m_GetpointServices.snapServices.Disabled;
app.m_Editor.m_GetpointServices.snapServices.Disabled = true;
let oldSnapState = app.m_Editor.GetPointServices.snapServices.Disabled;
app.m_Editor.GetPointServices.snapServices.Disabled = true;
while (true)
{
@ -77,7 +77,7 @@ export abstract class DrawBoardTool implements Command
break;
}
//恢复原先状态
app.m_Editor.m_GetpointServices.snapServices.Disabled = oldSnapState;
app.m_Editor.GetPointServices.snapServices.Disabled = oldSnapState;
}
//构建板件

@ -81,8 +81,8 @@ export class Command_Offset implements Command
{
let oldDir = 0;
let oldSnap = app.m_Editor.m_GetpointServices.snapServices.Disabled;
app.m_Editor.m_GetpointServices.snapServices.Disabled = true;
let oldSnap = app.m_Editor.GetPointServices.snapServices.Disabled;
app.m_Editor.GetPointServices.snapServices.Disabled = true;
let ptRes = await app.m_Editor.GetPoint({
Msg: "指定要偏移的那一侧的点",
Callback: (p: Vector3) =>
@ -97,7 +97,7 @@ export class Command_Offset implements Command
}
}
});
app.m_Editor.m_GetpointServices.snapServices.Disabled = oldSnap;
app.m_Editor.GetPointServices.snapServices.Disabled = oldSnap;
let status = { Status: ptRes.Status, offsetDist: 0 };
if (ptRes.Status === PromptStatus.OK)
{

@ -1,5 +1,6 @@
import { Matrix4, Vector3 } from 'three';
import { begin, end } from 'xaop';
import { AutoCuttingReactor } from '../Add-on/BoardCutting/AutoCuttingReactor';
import { DrillingReactor } from '../Add-on/DrawDrilling/DrillingReactor';
import { KeyCode, MouseKey } from '../Common/KeyEnum';
import { CADFiler } from '../DatabaseServices/CADFiler';
@ -8,7 +9,6 @@ import { Entity } from '../DatabaseServices/Entity';
import { FontLoader } from '../DatabaseServices/Text/FontLoader';
import { CameraControls } from '../Editor/CameraControls';
import { commandMachine } from '../Editor/CommandMachine';
import { ContextMenu } from '../Editor/ContextMenu';
import { Editor } from '../Editor/Editor';
import { Gesture } from '../Editor/Gesture';
import { RegisterGesture } from '../Editor/RegisterGesture';
@ -19,7 +19,6 @@ import { CommandReactor } from '../Reactor/CommandReactor';
import { appUi } from '../UI/Layout/ApplicationLayout';
import { DownPanelStore } from '../UI/Store/DownPanelStore';
import { HostApplicationServices } from './HostApplicationServices';
import { AutoCuttingReactor } from '../Add-on/BoardCutting/AutoCuttingReactor';
export let app: ApplicationService;
/**
@ -57,7 +56,6 @@ export class ApplicationService
this.m_Editor = new Editor(this);
new ContextMenu(this.m_Editor);
let gt = new Gesture(this.m_Editor);
RegisterGesture(gt);

@ -1,11 +1,9 @@
import { end } from "xaop";
import { app } from "../ApplicationServices/Application";
import { KeyWord, MenuDividerKWD } from "../Common/InputState";
import { KeyCode, MouseKey } from "../Common/KeyEnum";
import { Board } from "../DatabaseServices/Board";
import { commandMachine } from "./CommandMachine";
import { CommandState } from "./CommandState";
import { Editor } from "./Editor";
import { Editor, EditorService } from "./Editor";
import { PromptStatus } from "./PromptResult";
const KeyWordCommandMap: Map<string, string> = new Map(Object.entries({
@ -33,25 +31,33 @@ const KeyWordCommandMap: Map<string, string> = new Map(Object.entries({
/**
* ,
*/
export class ContextMenu
export class ContextMenuServices implements EditorService
{
IsReady: boolean = true;
constructor(private editor: Editor)
{
end(editor.m_MouseCtrl, editor.m_MouseCtrl.onMouseUp, (e: MouseEvent) =>
}
async Doit(e: MouseEvent)
{
if (e.button === MouseKey.Right)
{
if (e.button === MouseKey.Right)
{
this.ShowMenu();
}
});
this.ShowMenu();
return true;
}
}
Cancel()
{
}
HandleMouseUp(e: MouseEvent)
{
if (e.button === MouseKey.Right)
{
if ((app.m_Editor.m_KeyCtrl.KeyIsDown(KeyCode.ControlLeft)
|| app.m_Editor.m_KeyCtrl.KeyIsDown(KeyCode.ShiftLeft))
if ((this.editor.m_KeyCtrl.KeyIsDown(KeyCode.ControlLeft)
|| this.editor.m_KeyCtrl.KeyIsDown(KeyCode.ShiftLeft))
|| CommandState.CommandIng
)
return;
@ -63,7 +69,7 @@ export class ContextMenu
async ShowMenu()
{
let kws = this.GeneralKeywords();
let kwRes = await app.m_Editor.GetKeyWords({
let kwRes = await this.editor.GetKeyWords({
Msg: "",
KeyWordList: kws,
Modal: true,
@ -85,9 +91,9 @@ export class ContextMenu
GeneralKeywords()
{
let selects = app.m_Editor.m_SelectCtrl.SelectSet.SelectEntityList;
let selects = this.editor.m_SelectCtrl.SelectSet.SelectEntityList;
let historyCmdList = app.m_Editor.m_CommandStore.historyCmdList.slice(-10);
let historyCmdList = this.editor.m_CommandStore.historyCmdList.slice(-10);
let lastCmd = historyCmdList[0] || "HELP";
KeyWordCommandMap.set("R", lastCmd);

@ -1,28 +1,29 @@
import * as THREE from 'three';
import { Math, Matrix4, Vector3 } from 'three';
import * as xaop from 'xaop';
import { ApplicationService } from '../ApplicationServices/Application';
import { InputState } from '../Common/InputState';
import { GetDistendPrompt, GetEntityPrompt, GetKeyWordPrommpt, GetPointPrompt, GetSelectionPrompt, PromptRectPointOptions } from "./PromptOptions";
import { Entity } from '../DatabaseServices/Entity';
import { angle } from '../Geometry/GeUtils';
import { CommandInputManage } from '../UI/Components/CommandInput/CommandInputManage';
import { MaskManage } from '../UI/Components/Modal/MaskManage';
import { ModalManage } from '../UI/Components/Modal/ModalsManage';
import { CommandStore } from '../UI/Store/CommandStore';
import { ContextMenuServices } from './ContextMenu';
import { GetDistanceServices } from './GetDistanceServices';
import { GetEntityServices } from './GetEntityServices';
import { GetKeyWordsServices } from './GetKeyWordService';
import { GetPointServices } from './GetPointServices';
import { GetRectPointServices } from './GetRectServices';
import { SsgetServiecs } from './GetSelectionServices';
import { GripDragServices } from './GripDragServices';
import { KeyBoardControls } from './KeyBoardControls';
import { MouseControls } from './MouseControls';
import { PromptDistendResult, PromptEntityResult, PromptPointResult, PromptResult, PromptSsgetResult, PromptRectResult } from './PromptResult';
import { GetDistendPrompt, GetEntityPrompt, GetKeyWordPrommpt, GetPointPrompt, GetSelectionPrompt, PromptRectPointOptions } from "./PromptOptions";
import { PromptDistendResult, PromptEntityResult, PromptPointResult, PromptRectResult, PromptResult, PromptSsgetResult } from './PromptResult';
import { SelectControls } from './SelectControls';
import { GripDragServices } from './GripDragServices';
import { TransformServicess } from './TranstrolControl/TransformServices';
import { UCSServices } from './UCSServices';
import { angle } from '../Geometry/GeUtils';
import { Vector3, Math, Matrix4 } from 'three';
import { MaskManage } from '../UI/Components/Modal/MaskManage';
import { GetRectPointServices } from './GetRectServices';
import { CommandInputManage } from '../UI/Components/CommandInput/CommandInputManage';
//用户交互编辑工具
@ -35,7 +36,7 @@ export class Editor
m_App: ApplicationService;
m_InputState: InputState = InputState.None;
m_CommandStore: CommandStore;
m_GetpointServices: GetPointServices;
GetPointServices: GetPointServices;
m_GetDistanceServices: GetDistanceServices;
getRectPointServices: GetRectPointServices;
m_GetEntitytServices: GetEntityServices;
@ -48,6 +49,8 @@ export class Editor
m_SsgetServices: SsgetServiecs;
m_KeywordsServices: GetKeyWordsServices;
ContextMenuServices: ContextMenuServices;
InteractiveServices: EditorService[] = [];
//用户坐标系
constructor(app: ApplicationService)
@ -57,7 +60,7 @@ export class Editor
this.m_KeyCtrl = new KeyBoardControls();
this.m_SelectCtrl = new SelectControls(app.m_Viewer, this)
this.m_CommandStore = new CommandStore(this);
this.m_GetpointServices = new GetPointServices();
this.GetPointServices = new GetPointServices();
this.m_GetDistanceServices = new GetDistanceServices();
this.getRectPointServices = new GetRectPointServices();
@ -67,6 +70,7 @@ export class Editor
this.m_SsgetServices = new SsgetServiecs(this);
this.m_KeywordsServices = new GetKeyWordsServices(this);
this.ContextMenuServices = new ContextMenuServices(this);
xaop.end(this.m_MouseCtrl, this.m_MouseCtrl.onMouseMove, () =>
{
@ -78,6 +82,16 @@ export class Editor
this.m_MaskManage = new MaskManage();
this.m_ModalManage = new ModalManage(this);
this.m_CommandInput = new CommandInputManage();
this.InteractiveServices = [
this.m_SnapDragServices,
this.m_GetEntitytServices,
this.GetPointServices,
this.transCtrl,
this.m_SelectCtrl,
this.m_KeywordsServices,
this.ContextMenuServices
];
}
/**
@ -105,14 +119,12 @@ export class Editor
//尝试取消当前的操作
Canel()
{
[this.m_GetpointServices, this.m_GetDistanceServices, this.m_GetEntitytServices, this.m_SsgetServices, this.m_KeywordsServices].forEach(ser =>
{
ser.Cancel();
})
for (let service of this.InteractiveServices)
service.Cancel();
}
GetPoint(prompt?: GetPointPrompt): Promise<PromptPointResult>
{
return this.m_GetpointServices.Start(prompt);
return this.GetPointServices.Start(prompt);
}
GetDistance(prompt?: GetDistendPrompt): Promise<PromptDistendResult>
{
@ -180,4 +192,5 @@ export interface EditorService
IsReady: boolean;
//开始执行,交给服务. 返回布尔值, 如果为真 那么继续执行.
Doit: (e: MouseEvent) => Promise<boolean>;
Cancel: () => void;
}

@ -189,7 +189,7 @@ export class GetDistanceServices
let promisResFunc = this.promisResolve;
this.promisResolve = undefined; //先将回调函数设置为空,避免对GetPoint取消时重复触发本函数
app.m_Editor.m_GetpointServices.Cancel();//取消掉点选服务.
app.m_Editor.GetPointServices.Cancel();//取消掉点选服务.
promisResFunc(res);
}
}

@ -15,15 +15,10 @@ import { GetEntityPrompt } from "./PromptOptions";
import { PromptEntityResult, PromptStatus } from './PromptResult';
/**
*
* :
* Ok .
* Other 退
* None ,
*
* @export
* @class GetEntityServices
* @implements {EditorService}
*/
export class GetEntityServices implements EditorService
{
@ -39,13 +34,13 @@ export class GetEntityServices implements EditorService
private m_promisResolve: (PromptEntityResult) => void;
private removeCalls: Function[] = [];
private m_prompt: GetEntityPrompt;
private prompt: GetEntityPrompt;
Start(prompt?: GetEntityPrompt): Promise<PromptEntityResult>
{
this.IsReady = true;
prompt = prompt || {};
this.m_prompt = prompt;
this.prompt = prompt;
this.m_Editor.m_InputState |= InputState.Entsel;
if (!prompt.IsSelect)
@ -77,29 +72,12 @@ export class GetEntityServices implements EditorService
//动态提示.
this.InitDynPrompt(prompt, mouseCtrl);
//处理右键
this.initHandleRightClick(prompt);
return new Promise<PromptEntityResult>((res, rej) =>
{
this.m_promisResolve = res;
});
}
initHandleRightClick(prompt: GetEntityPrompt): any
{
this.removeCalls.push(end(app.m_Editor.m_MouseCtrl, app.m_Editor.m_MouseCtrl.onMouseDown, (e: MouseEvent) =>
{
if (e.button === MouseKey.Right)
{
if (prompt.KeyWordList === undefined)
this.Cancel();
else
this.handleRightClick(prompt.KeyWordList);
return true;
}
}));
return true;
}
//处理右键点击事件
private async handleRightClick(kwList: KeyWord[])
{
@ -176,12 +154,15 @@ export class GetEntityServices implements EditorService
case MouseKey.Left:
{
this.Retun(this.HandleMouseMove());
break;
return true;
}
case MouseKey.Right:
{
this.Retun({ Status: PromptStatus.Other })
break;
if (!this.prompt.KeyWordList || this.prompt.KeyWordList.length === 0)
this.Retun({ Status: PromptStatus.Other });
else
this.handleRightClick(this.prompt.KeyWordList);
return true;
}
}
return false;
@ -200,7 +181,7 @@ export class GetEntityServices implements EditorService
}
private HandleMouseMove(): PromptEntityResult
{
let pickObj = PointPick(this.m_Editor.m_MouseCtrl.m_CurMousePointVCS, this.m_Viewer, this.m_prompt.Filter)[0];
let pickObj = PointPick(this.m_Editor.m_MouseCtrl.m_CurMousePointVCS, this.m_Viewer, this.prompt.Filter)[0];
let ret = new PromptEntityResult();
if (pickObj && IsEntity(pickObj))
ret.Entity = GetEntity(pickObj);
@ -213,7 +194,7 @@ export class GetEntityServices implements EditorService
private RestState()
{
this.IsReady = false;
this.m_prompt = undefined;
this.prompt = undefined;
this.m_Editor.m_InputState &= ~InputState.Entsel;
this.m_Viewer.m_PreViewer.Cursor.Mode = CursorMode.None;

@ -23,19 +23,26 @@ import { SnapServices } from './SnapServices';
/**
* ,Editor.
*
* @export
* @class GetPointServices
*/
export class GetPointServices implements EditorService
{
IsReady: boolean = false;
async Doit(e: MouseEvent)
{
if (e.button == MouseKey.Left)
if (e.button === MouseKey.Left)
{
this.ReturnPoint(this.curPoint, this.curPointIsSnap ? this.snapServices.SnapMode : undefined);
return true;
}
else if (e.button === MouseKey.Right)
{
if (this._prompt.KeyWordList === undefined)
DynamicInputManage.GetManage().HandleInputEvent("");
else if (!app.m_Editor.m_KeyCtrl.KeyIsDown(KeyCode.ControlLeft))
this.handleRightClick(this._prompt.KeyWordList);
return true;
}
return false;
}
private promisResolve: (res: PromptPointResult) => void;//promis回调
@ -44,9 +51,12 @@ export class GetPointServices implements EditorService
public snapServices = new SnapServices();
public snapModeCurrent: ObjectSnapMode = ObjectSnapMode.All;
private _prompt: GetPointPrompt;
Start(prompt?: GetPointPrompt): Promise<PromptPointResult>
{
prompt = prompt ? prompt : {};
this._prompt = prompt;
//初始化捕捉状态
this.snapServices.Start(prompt);
@ -76,29 +86,12 @@ export class GetPointServices implements EditorService
this.initHandleKeyDown();
//监听鼠标移动
this.initUpdateCurPoint();
//处理右键
this.initHandleRightClick(prompt);
return new Promise<PromptPointResult>((resolve, reject) =>
{
this.promisResolve = resolve;
});
}
//监听右键点击事件
private initHandleRightClick(prompt: GetPointPrompt)
{
this.removeCalls.push(xaop.end(app.m_Editor.m_MouseCtrl, app.m_Editor.m_MouseCtrl.onMouseDown, (e: MouseEvent) =>
{
if (e.button == MouseKey.Right)
{
if (prompt.KeyWordList === undefined)
DynamicInputManage.GetManage().HandleInputEvent("");
else if (!app.m_Editor.m_KeyCtrl.KeyIsDown(KeyCode.ControlLeft))
this.handleRightClick(prompt.KeyWordList);
}
}));
}
//处理右键点击事件
private async handleRightClick(keywords: KeyWord[])
{
@ -131,7 +124,7 @@ export class GetPointServices implements EditorService
if (res.StringResult === "O")
app.m_Editor.m_ModalManage.RenderModal(SnapModal, ModalPosition.Center, {});
else
app.m_Editor.m_GetpointServices.snapServices.SnapModeEnable = SNAPMODE[res.StringResult];
app.m_Editor.GetPointServices.snapServices.SnapModeEnable = SNAPMODE[res.StringResult];
}
break;
}

@ -231,7 +231,7 @@ export class GetRectPointServices
let promisResFunc = this.promisResolve;
this.promisResolve = undefined; //先将回调函数设置为空,避免对GetPoint取消时重复触发本函数
app.m_Editor.m_GetpointServices.Cancel();//取消掉点选服务
app.m_Editor.GetPointServices.Cancel();//取消掉点选服务
promisResFunc(result);
}
}

@ -91,7 +91,7 @@ export class SsgetServiecs
this.ReturnOk(true);
return;
}
this.m_Editor.Prompt(prompt.Msg);
this.m_Editor.Prompt("禁止空选择!");
break;
}
case PromptStatus.OK:
@ -161,7 +161,6 @@ export class SsgetServiecs
);
}
private HasSelection(set: SelectSet)
{
return set.SelectSetList.length > 0;

@ -163,6 +163,11 @@ export class GripDragServices implements EditorService
return true;
}
Cancel()
{
}
/**
*
* @returns

@ -36,12 +36,13 @@ export class MouseControls
//防止影响双击事件
if (e.detail > 1)
return;
for (let s of [app.m_Editor.m_SnapDragServices, app.m_Editor.m_GetEntitytServices, app.m_Editor.m_GetpointServices, app.m_Editor.transCtrl, app.m_Editor.m_SelectCtrl, app.m_Editor.m_KeywordsServices])
for (let s of app.m_Editor.InteractiveServices)
{
if (s.IsReady)
{
await s.Doit(e);
return;
let isBreak = await s.Doit(e);
if (isBreak)
break;
}
}
this.updateWordPoint(e);

@ -25,8 +25,7 @@ export class SelectControls implements EditorService
}
async Doit(e: MouseEvent)
{
this.onMouseDown(e);
return true;
return this.onMouseDown(e);
}
private m_SelectCss: SelectMarquee;
private m_Editor: Editor;
@ -109,16 +108,17 @@ export class SelectControls implements EditorService
}
onMouseDown(e: MouseEvent)
{
if (e.button === MouseKey.Right)
if ((this.m_Editor.m_InputState & InputState.SelectIng) && e.button === MouseKey.Right)
{
this.RestState();
return;
return true;
}
//左键 并且准备好时.
if (e.button !== MouseKey.Left || !this.IsReady)
return;
return false;
this.LeftClick();
return true;
}
/**

@ -49,7 +49,7 @@ export async function ShowSnapMenu()
app.m_Editor.m_ModalManage.RenderModal(SnapModal, ModalPosition.Center, {});
else
{
let snapService = app.m_Editor.m_GetpointServices.snapServices;
let snapService = app.m_Editor.GetPointServices.snapServices;
snapService.SnapModeEnable = SNAPMODE[res.StringResult];
}
}

@ -65,10 +65,10 @@ export class SnapMenuFixed extends React.Component<{}>
icon={data.enable ? "tick" : "blank"}
onClick={() =>
{
let snapServices = app.m_Editor.m_GetpointServices.snapServices;
let snapServices = app.m_Editor.GetPointServices.snapServices;
data.enable = !data.enable;
snapServices.SnapModeEnable ^= SNAPMODE[data.mode];
app.m_Editor.m_GetpointServices.snapModeCurrent = snapServices.SnapModeEnable;
app.m_Editor.GetPointServices.snapModeCurrent = snapServices.SnapModeEnable;
}}
/>
)

@ -39,12 +39,12 @@ export class PointSelectSpace
}
else if (this.m_GetPointRes.StringResult === "2")
{
app.m_Editor.m_GetpointServices.snapServices.Disabled = false;
app.m_Editor.GetPointServices.snapServices.Disabled = false;
await this.ParseBy2Point();
}
else if (this.m_GetPointRes.StringResult === "3")
{
app.m_Editor.m_GetpointServices.snapServices.Disabled = false;
app.m_Editor.GetPointServices.snapServices.Disabled = false;
await this.ParseBy3Point();
}
}

@ -128,7 +128,7 @@ export class SnapModal extends React.Component<{}, {}>
}
OnOK = () =>
{
let snapServices = app.m_Editor.m_GetpointServices.snapServices;
let snapServices = app.m_Editor.GetPointServices.snapServices;
if (!this.isF3Checked)
{
snapServices.SnapModeEnable = ObjectSnapMode.NotEntitySnap;
@ -141,7 +141,7 @@ export class SnapModal extends React.Component<{}, {}>
if (data.enable === true)
{
snapServices.SnapModeEnable |= SNAPMODE[data.mode];
app.m_Editor.m_GetpointServices.snapModeCurrent = snapServices.SnapModeEnable;
app.m_Editor.GetPointServices.snapModeCurrent = snapServices.SnapModeEnable;
}
}
app.m_Editor.m_ModalManage.Clear();

@ -36,8 +36,8 @@ export class DownPanelStore extends Singleton
});
autorun(() =>
{
app.m_Editor.m_GetpointServices.snapServices.Disabled = !this.useDynSnap;
app.m_Editor.m_GetpointServices.snapServices.AxisSnapMode = this.useOrtho ? AxisSnapMode.Ortho : AxisSnapMode.Polar;
app.m_Editor.GetPointServices.snapServices.Disabled = !this.useDynSnap;
app.m_Editor.GetPointServices.snapServices.AxisSnapMode = this.useOrtho ? AxisSnapMode.Ortho : AxisSnapMode.Polar;
app.m_Viewer.m_bUsePass = this.usePass;
});
}

Loading…
Cancel
Save