增加拾取距离功能

pull/2/head
ChenX 7 years ago
parent 51684bb7da
commit 931df2fb63

@ -220,28 +220,18 @@ export class DrawCircle implements Command
KeyWordList: [{ key: "3P", msg: "三点" }, { key: "2P", msg: "二点" }, { key: "T", msg: "切点、切点、半径" }]
});
if (ptRes.Status != PromptStatus.OK)
{
return;
}
app.m_Database.ModelSpace.Append(cir);
app.m_Editor.AddNoSnapEntity(cir.Draw(RenderType.Wireframe));
app.m_Editor.m_CommandStore.Prompt("指定圆的半径:");
ptRes = await app.m_Editor.GetPoint(
{
let disRes = await app.m_Editor.GetDistend({
Msg: "指定圆的半径:",
KeyWordList: [{ key: "D", msg: "直径" }],
Default: 10,
BasePoint: ptRes.Value,
Callback: (p) =>
{
cir.Radius = p.distanceTo(cir.Center);
},
AllowDrawRubberBand: true
}
);
Callback: (v) => cir.Radius = v,
});
app.m_Database.hm.EndCmd();
}
}

@ -15,11 +15,22 @@ export interface KeyWord
msg: string;
key: string;
}
export interface GetPointPrompt
interface GetAnyPrompt
{
Msg?: string
KeyWordList?: KeyWord[]
}
export interface GetPointPrompt extends GetAnyPrompt
{
BasePoint?: Vector3
Callback?: (pt: THREE.Vector3) => void
AllowDrawRubberBand?: Boolean;
KeyWordList?: KeyWord[]
}
export interface GetDistendPrompt extends GetAnyPrompt
{
BasePoint?: Vector3
Callback?: (pt: number) => void
Default?: number
}

@ -1,16 +1,16 @@
//用户交互编辑工具
import * as THREE from 'three';
import { Vector3 } from 'three';
import * as THREE from 'three';
import * as xaop from 'xaop';
import { app, ApplicationService } from '../ApplicationServices/Application';
import { GetPointPrompt, InputState } from '../Common/InputState';
import { GetDistendPrompt, GetPointPrompt, InputState } from '../Common/InputState';
import { Entity } from '../DatabaseServices/Entity';
import { CommandStore } from '../UI/Store/CommandStore';
import { GetPointServices } from './GetPointServices';
import { GetDistendsServices, GetPointServices } from './GetPointServices';
import { KeyBoardControls } from './KeyBoardControls';
import { MouseControls } from './MouseControls';
import { PromptPointResult } from './PromptResult';
import { PromptDistendResult, PromptPointResult } from './PromptResult';
import { SelectControls } from './SelectControls';
//TODO: 增加鼠标状态. 鼠标位置.
@ -24,6 +24,7 @@ export class Editor
m_CommandStore: CommandStore;
private m_GetpointServices: GetPointServices;
private m_GetDistendsServices: GetDistendsServices;
constructor(app: ApplicationService)
{
@ -33,15 +34,20 @@ export class Editor
this.m_SelectCtrl = new SelectControls(app.m_Viewer, this)
this.m_CommandStore = new CommandStore(this);
this.m_GetpointServices = new GetPointServices();
this.m_GetDistendsServices = new GetDistendsServices();
xaop.end(this.m_MouseCtrl, this.m_MouseCtrl.onMouseMove, () =>
{
app.m_Viewer.m_PreViewer.SerCursorPostion(this.m_MouseCtrl.m_CurMousePointVCS);
})
}
GetPoint(prompt?: GetPointPrompt): Promise<PromptPointResult>
GetPoint(prompt?: GetPointPrompt, showDyn: boolean = true): Promise<PromptPointResult>
{
return this.m_GetpointServices.Doit(prompt, showDyn);
}
GetDistend(prompt?: GetDistendPrompt): Promise<PromptDistendResult>
{
return this.m_GetpointServices.Doit(prompt);
return this.m_GetDistendsServices.Doit(prompt);
}
AddNoSnapEntity(e)
{

@ -1,14 +1,15 @@
import * as THREE from 'three';
import { Vector3 } from 'three';
import * as THREE from 'three';
import * as xaop from 'xaop';
import { app } from '../ApplicationServices/Application';
import { GetPointPrompt, InputState } from '../Common/InputState';
import { GetDistendPrompt, GetPointPrompt, InputState } from '../Common/InputState';
import { KeyBoard, MouseKey } from '../Common/KeyEnum';
import { equaln, fixAngle, Intersect, polar } from '../Geometry/GeUtils';
import { equaln, fixAngle, Intersect, midPoint, polar } from '../Geometry/GeUtils';
import { DynamicInputManage } from '../UI/DynamicPrompt/DynamicInputManage';
import { GetDistancePromptBlock } from '../UI/DynamicPrompt/GetDistancePromptBlock';
import { GetPointPromptBlock } from '../UI/DynamicPrompt/GetPointPromptBlock';
import { PromptPointResult, PromptStatus } from './PromptResult';
import { PromptDistendResult, PromptPointResult, PromptStatus } from './PromptResult';
/**
* ,Editor.
@ -20,8 +21,8 @@ export class GetPointServices
{
private promisResolve: (PromptPointResult) => void;//promis回调
private removeCalls: Function[] = []; //结束回调
Doit(prompt?: GetPointPrompt): Promise<PromptPointResult>
protected removeCalls: Function[] = []; //结束回调
Doit(prompt?: GetPointPrompt, showDyn: boolean = false): Promise<PromptPointResult>
{
prompt = prompt ? prompt : {};
//程序状态
@ -33,7 +34,7 @@ export class GetPointServices
//消息显示.
this.initPrompt(prompt);
//动态输入框.
this.initDynInput(prompt);
if (showDyn) this.initDynInput(prompt);
//设置关键字
this.initKeyword(prompt);
//处理用户输入
@ -203,7 +204,7 @@ export class GetPointServices
}
//初始化动态输入框,包括处理事件
private initDynInput(prompt: GetPointPrompt)
protected initDynInput(prompt: GetPointPrompt)
{
let dynPrompt = new GetPointPromptBlock(DynamicInputManage.GetManage());
dynPrompt.updatePrompt(prompt.Msg);
@ -227,7 +228,7 @@ export class GetPointServices
}
//调用promis的回调.
private _return(v?: THREE.Vector3 | string)
protected _return(v?: THREE.Vector3 | string)
{
this.restAppState();
@ -562,3 +563,102 @@ export class GetPointServices
return undefined;
}
}
export class GetDistendsServices
{
private removeCalls: Function[] = [];
private promisResolve: (PromptDistendResult) => void;
Doit(prompt?: GetDistendPrompt): Promise<PromptDistendResult>
{
prompt = prompt || {};
let dynInput = this.initDynInput(prompt);
return new Promise<PromptDistendResult>(async (resolve, reject) =>
{
this.promisResolve = resolve;
let p1 = prompt.BasePoint;
if (!p1)
{
let ptRes = await app.m_Editor.GetPoint(
{
Msg: "请输入距离或者点取距离:",
BasePoint: prompt.BasePoint,
Callback: (p) =>
{
dynInput.SetPostion(app.m_Editor.m_MouseCtrl.m_CurMousePointVCS);
}
}, false);
if (ptRes.Status == PromptStatus.OK)
p1 = ptRes.Value;
else
{
this._return();
return;
}
}
let ptRes = await app.m_Editor.GetPoint({
Msg: "请输入距离或者点取距离:",
BasePoint: p1,
AllowDrawRubberBand: true,
Callback: (p) =>
{
let midp = midPoint(p1, p);
app.m_Viewer.WorldToScreen(midp);
dynInput.SetPostion(app.m_Editor.m_MouseCtrl.m_CurMousePointVCS);
dynInput.ValuePostion = midp;
dynInput.Value = p1.distanceTo(p);
if (prompt.Callback)
prompt.Callback(dynInput.Value);
}
}, false);
if (ptRes.Status == PromptStatus.OK)
this._return(p1.distanceTo(ptRes.Value));
else
this._return();
});
}
//初始化动态输入框,包括处理事件
protected initDynInput(prompt: GetDistendPrompt)
{
let dynManage = DynamicInputManage.GetManage();
let dynInput = new GetDistancePromptBlock(dynManage);
dynInput.Value = prompt.Default;
dynInput.updatePrompt(prompt.Msg);
this.removeCalls.push(() =>
{
dynInput.Destroy();
});
this.removeCalls.push(
xaop.end(dynManage, dynManage.HandleInputEvent, () =>
{
let v = dynInput.Value;
if (!isNaN(v))
this._return(v);
})
)
return dynInput;
}
protected _return(v?: number | string)
{
this.removeCalls.forEach(f => f());
let res = new PromptDistendResult();
if (!v)
{
res.Status = PromptStatus.Cancel;
}
else if (v instanceof Number)
{
res.Status = PromptStatus.OK
}
else
{
res.Status = PromptStatus.Keyword
res.StringResult = v;
}
this.promisResolve(res);
}
}

@ -41,3 +41,16 @@ export class PromptPointResult extends PromptResult
this._value = new THREE.Vector3();
}
}
export class PromptDistendResult extends PromptResult
{
private _value: number;
get Value()
{
return this._value;
}
set Value(v)
{
this._value = v;
}
}

@ -0,0 +1,39 @@
import { PromptBlock } from "./PromptBlock";
import { DynamicInputManage } from "./DynamicInputManage";
import { RealDynamicInput } from "./RealDynamicInput";
export class GetDistancePromptBlock extends PromptBlock
{
private valueDynIpt: RealDynamicInput;
constructor(dynamicInputManage: DynamicInputManage)
{
super(dynamicInputManage);
this.valueDynIpt = new RealDynamicInput(this.promptContainer);
dynamicInputManage.AddDynamicInput(this.valueDynIpt);
this.updatePrompt("请点击或者输入距离:");
}
//设置输入距离的位置
set ValuePostion(v: THREE.Vector3)
{
this.valueDynIpt.Fixed = true;
this.valueDynIpt.SetPosition(v.x, v.y);
}
set Value(v: number)
{
if (v && !isNaN(v))
this.valueDynIpt.Value = v;
}
get Value(): number
{
return this.valueDynIpt.Value;
}
Destroy()
{
super.Destroy();
this.dynamicInputManage.RemoveDynamicInput(this.valueDynIpt);
}
}

@ -4,7 +4,6 @@ import { DynamicInputManage } from './DynamicInputManage';
import { PromptBlock } from './PromptBlock';
import { RealDynamicInput } from './RealDynamicInput';
/**
* ,.
*

@ -14,7 +14,7 @@ export class PromptBlock
public promptContainer: HTMLElement;
//提示信息
private promptEl: HTMLElement;
private dynamicInputManage: DynamicInputManage;
protected dynamicInputManage: DynamicInputManage;
private dynInputList: DynamicInput[] = [];
constructor(dynamicInputManage: DynamicInputManage)
{

Loading…
Cancel
Save