!21 完善trim命令,使用了选择集功能. 修复删除对象后撤销无法还原显示. 完善选择集的动态提示. 添加待解决的TODO代码.

Merge pull request !21 from ChenX/trim_ss
pull/650642/MERGE
ChenX 7 years ago
parent a3d19d9229
commit ed472edf69

@ -1,8 +1,17 @@
import { Command } from "../Editor/CommandMachine";
import { SelectSet } from "../Editor/SelectSet";
import { SelectSet, SelectType } from "../Editor/SelectSet";
import { Curve } from "../DatabaseServices/Curve";
import { Intersect } from "../GraphicsSystem/IntersectWith";
import { app } from "../ApplicationServices/Application";
import { PromptStatus } from "../Editor/PromptResult";
import { SelectPick } from "../Editor/SelectPick";
import { Vector3 } from "three";
import { SelectBox } from "../Editor/SelectBox";
import { RenderType } from "../GraphicsSystem/Enum";
//TODO: 需要全部计算完成后在打断.
//并且计算打断后需要更新裁剪对象.
export class Command_Trim implements Command
@ -11,50 +20,137 @@ export class Command_Trim implements Command
{
let cus: Array<Curve> = [];
for (let en of ss.SelectEntityList)
fillerCus(ss, cus);
if (cus.length === 0)
{
if (en instanceof Curve)
while (true)
{
cus.push(en)
let ssRes = await app.m_Editor.GetSelection({ Msg: "请选择切割对象<全部选择>:" });
if (ssRes.Status === PromptStatus.Cancel)
{
//取消
return;
}
else if (ssRes.Status === PromptStatus.None)
{
//全部选择
}
else if (ssRes.Status === PromptStatus.OK)
{
fillerCus(ssRes.SelectSet, cus);
if (cus.length === 0)
{
for (let en of app.m_Database.ModelSpace.objectCol)
{
if (en instanceof Curve)
{
cus.push(en);
}
}
}
break;
}
}
}
for (let i = 0; i < cus.length; i++)
while (true)
{
let cu1 = cus[i];
for (let j = i + 1; j < cus.length; j++)
{
let cu2 = cus[j];
let pts = cu1.IntersectWith(cu2, Intersect.OnBothOperands);
//选择裁剪的对象.
let trSsRes = await app.m_Editor.GetSelection({ Msg: "请选择被切割对象:", Once: true });
if (trSsRes.Status === PromptStatus.Cancel)
return;
if (!trSsRes.SelectSet)
continue;
let param1: number[] = [];
let param2: number[] = [];
for (let p of pts)
{
param1.push(cu1.GetParamAtPoint(p));
param2.push(cu2.GetParamAtPoint(p));
}
app.m_Viewer.m_OutlinePass.selectedObjects = [];
let cus1 = cu1.GetSplitCurves(param1);
if (cus1.length > 0)
for (let s of trSsRes.SelectSet.SelectSetList)
{
for (let obj of s.m_SelectList)
{
for (let cu of cus1)
let cu = obj.userData as Curve;
if (!cu)
continue;
let inPts: Vector3[] = [];
for (let icu of cus)
{
app.m_Database.ModelSpace.Append(cu);
inPts.push(...cu.IntersectWith(icu, Intersect.OnBothOperands));
}
cu1.Erase();
}
let cus2 = cu2.GetSplitCurves(param2);
if (cus2.length > 0)
{
for (let cu of cus2)
//打断.
let paramS = inPts.map(p => cu.GetParamAtPoint(p));
let splitCus = cu.GetSplitCurves(paramS);
if (splitCus.length <= 1)
continue;
if (s instanceof SelectPick)
{
app.m_Database.ModelSpace.Append(cu);
}
else if (s instanceof SelectBox)
{
let sbox = s;
if (s.m_SelectType === SelectType.W)
continue;
let needBreakCus = splitCus.filter(c =>
{
return sbox.IntersectObject(c.Draw(RenderType.Wireframe));
})
if (needBreakCus.length === 0)
continue;
//打断原先的曲线
let lastCu = cu;
for (let breakCu of needBreakCus)
{
let breakParams = [breakCu.StartPoint, breakCu.EndPoint].map(p => lastCu.GetParamAtPoint(p));
let breakCus = lastCu.GetSplitCurves(breakParams);
if (breakCus.length === 2)
{
if (breakParams[0] == 0)
{
lastCu = breakCus[1];
}
else
lastCu = breakCus[0];
}
else if (breakCus.length === 3)
{
app.m_Database.ModelSpace.Append(breakCus[0]);
lastCu = breakCus[breakCus.length - 1];
}
else// 可能造成的错误.
{
console.warn("未预料到的.")
cu.Erase();
continue;
}
}
cu.CopyFrom(lastCu);
}
cu2.Erase();
}
}
app.m_Editor.UpdateScreen();
app.m_Viewer.m_GripScene.Clear();
app.m_Editor.m_SelectCtrl.Cancel();
}
}
}
function fillerCus(ss: SelectSet, cus: Curve[])
{
for (let en of ss.SelectEntityList)
{
if (en instanceof Curve)
{
cus.push(en);
}
}
}

@ -54,7 +54,7 @@ export interface GetEntityPrompt extends GetAnyPrompt
Callback?: (res: PromptEntityResult) => void;
}
export interface SsgetPrompt extends GetAnyPrompt
export interface GetSelectionPrompt extends GetAnyPrompt
{
Once?: boolean;//只选一次
}

@ -102,6 +102,7 @@ export class Entity extends CADObject
let ver = file.Read();
super.ReadFile(file);
this.m_Color = file.Read();
this.Update();
}
//对象将自身数据写入到文件.
WriteFile(file: CADFile)

@ -38,6 +38,7 @@ export class Line extends Curve
Update()
{
super.Update();
for (let [, obj] of this.m_DrawEntity)
{
let lineObj = (<THREE.Line>obj);

@ -3,7 +3,7 @@ import { Vector3 } from 'three';
import * as xaop from 'xaop';
import { app, ApplicationService } from '../ApplicationServices/Application';
import { GetDistendPrompt, GetEntityPrompt, GetPointPrompt, InputState } from '../Common/InputState';
import { GetDistendPrompt, GetEntityPrompt, GetPointPrompt, InputState, GetSelectionPrompt } from '../Common/InputState';
import { Entity } from '../DatabaseServices/Entity';
import { CommandStore } from '../UI/Store/CommandStore';
import { GetEntityServices } from './GetEntityServices';
@ -13,7 +13,7 @@ import { MouseControls } from './MouseControls';
import { PromptDistendResult, PromptEntityResult, PromptPointResult, PromptSsgetResult } from './PromptResult';
import { SelectControls } from './SelectControls';
import { SnapDragServices } from './SnapDragServices';
import { SsgetServiecs } from './SsgetServices';
import { SsgetServiecs } from './GetSelectionServices';
import { TransformServicess } from './TranstrolControl/TransformServices';
import { UCSServices } from './UCSServices';
@ -104,9 +104,9 @@ export class Editor
{
return this.m_GetEntitytServices.Start(prompt);
}
async GetSelection(): Promise<PromptSsgetResult>
async GetSelection(prompt?: GetSelectionPrompt): Promise<PromptSsgetResult>
{
return this.m_SsgetServices.Start();
return this.m_SsgetServices.Start(prompt);
}
SelectWindow(p1: THREE.Vector3, p2: THREE.Vector3): Array<Entity>
{

@ -1,6 +1,6 @@
import { end } from 'xaop';
import { InputState, SsgetPrompt } from '../Common/InputState';
import { InputState, GetSelectionPrompt } from '../Common/InputState';
import { KeyBoard } from '../Common/KeyEnum';
import { RenderType } from '../GraphicsSystem/Enum';
import { Editor } from './Editor';
@ -15,7 +15,6 @@ import { SelectPick } from './SelectPick';
export class SsgetServiecs
{
m_Editor: Editor;
constructor(ed: Editor)
{
@ -23,7 +22,7 @@ export class SsgetServiecs
}
private promisResolve: (res: PromptSsgetResult) => void;//promis回调
Start(prompt?: SsgetPrompt): Promise<PromptSsgetResult>
Start(prompt: GetSelectionPrompt = {}): Promise<PromptSsgetResult>
{
this.m_Editor.m_InputState &= InputState.Select;
@ -34,7 +33,7 @@ export class SsgetServiecs
while (true)
{
let enRes = await this.m_Editor.GetEntity();
let enRes = await this.m_Editor.GetEntity({ Msg: prompt.Msg });
switch (enRes.Status)
{
@ -46,7 +45,7 @@ export class SsgetServiecs
case PromptStatus.Other://结束 (右键),或者(空格).
{
//结束并且确认选择
this.Return({ Status: PromptStatus.OK, SelectSet: this.m_Editor.m_SelectCtrl.SelectSet });
this.ReturnOk();
return;
}
case PromptStatus.OK:
@ -58,8 +57,17 @@ export class SsgetServiecs
this.m_Editor.m_SelectCtrl.SelectSet.RemoveSelect(ssEnt);
else
this.m_Editor.m_SelectCtrl.SelectSet.AddSelect(ssEnt);
this.m_Editor.m_SelectCtrl.UpdateView();
break;
if (prompt.Once)
{
this.ReturnOk();
return;
}
else
{
this.m_Editor.m_SelectCtrl.UpdateView();
break;
}
}
case PromptStatus.None:
{
@ -71,6 +79,11 @@ export class SsgetServiecs
this.CanelRetun();
return;
}
else if (prompt.Once)
{
this.ReturnOk();
return;
}
break;
}
default:
@ -82,6 +95,11 @@ export class SsgetServiecs
}
private ReturnOk()
{
this.Return({ Status: PromptStatus.OK, SelectSet: this.m_Editor.m_SelectCtrl.SelectSet });
}
//返回取消状态
private CanelRetun()
{

@ -122,6 +122,7 @@ export class SelectBox extends SelectSetBase
//测试对象是否和平截头体相交.如果不存在Geometry则返回true;
FrustomIntersectObject(obj: THREE.Object3D): Boolean
{
if (!obj.visible) return false;
if (obj.hasOwnProperty("geometry"))
return this.m_Frustom.intersectsObject(obj);
return true;

Loading…
Cancel
Save