!154 trim动态预览结果,控制GetSelction为栏选(C)模式.

Merge pull request !154 from ChenX/trimJig2
pull/154/MERGE
ChenX 6 years ago
parent 5ad127f23f
commit 1d1bcc0eaa

@ -1,5 +1,127 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`三维空间圆圆相交测试 1`] = `
Array [
Vector3 {
"x": 3.8465654731285666,
"y": -0.48984005103149847,
"z": 0.3777515851723183,
},
Vector3 {
"x": 4.518686772594938,
"y": -2.26435797895917,
"z": -0.09066385360916496,
},
]
`;
exports[`三维空间圆圆相交测试 2`] = `
Array [
Vector3 {
"x": 1.25,
"y": -4.841229182759271,
"z": 0,
},
Vector3 {
"x": 1.25,
"y": 4.841229182759271,
"z": 0,
},
]
`;
exports[`三维空间圆圆相交测试 3`] = `
Array [
Vector3 {
"x": 1.25,
"y": 0,
"z": -4.841229182759271,
},
Vector3 {
"x": 1.25,
"y": 0,
"z": 4.841229182759271,
},
]
`;
exports[`三维空间圆圆相交测试 4`] = `
Array [
Vector3 {
"x": 0,
"y": -11.313088368701884,
"z": -9.556275638274851,
},
Vector3 {
"x": 0,
"y": -9.579281670837858,
"z": -2.8986776905615708,
},
]
`;
exports[`三维空间圆圆相交测试 5`] = `Array []`;
exports[`三维空间直线和圆相交测试 1`] = `
Array [
Vector3 {
"x": 7.265045456946406,
"y": 0,
"z": 1.5147084845720027,
},
Vector3 {
"x": 3.9357458826357803,
"y": 0,
"z": 4.789429377336553,
},
]
`;
exports[`三维空间直线和圆相交测试 2`] = `
Array [
Vector3 {
"x": -3.622627029705465,
"y": -3.4462404738565997,
"z": 0,
},
Vector3 {
"x": -3.622627029705464,
"y": 3.446240473856601,
"z": 0,
},
]
`;
exports[`三维空间直线和圆相交测试 3`] = `
Array [
Vector3 {
"x": 9.796270630192112,
"y": -13.16305455920182,
"z": 4.841809080303142,
},
Vector3 {
"x": 9.796270630192113,
"y": -6.270573611488619,
"z": 4.841809080303142,
},
]
`;
exports[`三维空间直线和圆相交测试 4`] = `
Array [
Vector3 {
"x": 12.384261138056765,
"y": -13.16305455920182,
"z": 6.346016491847222,
},
Vector3 {
"x": 12.384261138056765,
"y": -6.27057361148862,
"z": 6.346016491847221,
},
]
`;
exports[`三维空间直线相交测试 1`] = ` exports[`三维空间直线相交测试 1`] = `
Vector3 { Vector3 {
"x": 5, "x": 5,
@ -17,3 +139,31 @@ Vector3 {
"z": 5, "z": 5,
} }
`; `;
exports[`直线和圆相切 1`] = `
Array [
Vector3 {
"x": 34450.21257120082,
"y": 3606.7814824644443,
"z": 0,
},
]
`;
exports[`相交测试 1`] = `
Vector3 {
"x": 0.5,
"y": 0,
"z": 0,
}
`;
exports[`相交测试 2`] = `undefined`;
exports[`相交测试 3`] = `
Vector3 {
"x": 0.5,
"y": 5,
"z": 0,
}
`;

@ -8,8 +8,9 @@ import { Curve } from '../DatabaseServices/Curve';
import { Line } from '../DatabaseServices/Line'; import { Line } from '../DatabaseServices/Line';
import { Polyline } from '../DatabaseServices/Polyline'; import { Polyline } from '../DatabaseServices/Polyline';
import { Command } from '../Editor/CommandMachine'; import { Command } from '../Editor/CommandMachine';
import { PromptStatus } from '../Editor/PromptResult'; import { Jig } from '../Editor/Jig';
import { SelectBox } from '../Editor/SelectBox'; import { PromptSsgetResult, PromptStatus } from '../Editor/PromptResult';
import { SelectBox, SelectType } from '../Editor/SelectBox';
import { IntersectOption } from '../GraphicsSystem/IntersectWith'; import { IntersectOption } from '../GraphicsSystem/IntersectWith';
export class Command_Trim implements Command export class Command_Trim implements Command
@ -27,53 +28,96 @@ export class Command_Trim implements Command
//剪刀对象 //剪刀对象
let kniefCus = knifeSsRes.SelectSet.SelectEntityList as Curve[]; let kniefCus = knifeSsRes.SelectSet.SelectEntityList as Curve[];
kniefCus.forEach(c => c.UpdateJigMaterial());
while (true) while (true)
{ {
// kniefCus.forEach(c => c.UpdateJigMaterial(6));
let lastCurves: Curve[] = [];
//选择裁剪的对象. //选择裁剪的对象.
let trSsRes = await app.m_Editor.GetSelection({ let trSsRes = await app.m_Editor.GetSelection({
Msg: "请选择被切割对象:", Msg: "请选择被切割对象:",
Once: true, Once: true,
Filter: { filterTypes: [Curve] }, Filter: {
filterTypes: [Curve],
},
SelectType: SelectType.C,
Callback: (res) => Callback: (res) =>
{ {
console.log(res); Jig.End();
for (let c of lastCurves)
c.RestoreJigMaterial();
lastCurves = res.SelectSet.SelectEntityList as Curve[];
let cuMap = this.JigTrim(res, kniefCus);
for (let [c, cus] of cuMap)
{
c.UpdateJigMaterial();
for (let c of cus)
Jig.Draw(c);
}
app.m_Editor.UpdateScreen();
} }
}); });
for (let c of lastCurves)
c.RestoreJigMaterial();
// for (let c of kniefCus)
// c.RestoreJigMaterial();
if (trSsRes.Status === PromptStatus.Cancel || trSsRes.Status === PromptStatus.None) if (trSsRes.Status === PromptStatus.Cancel || trSsRes.Status === PromptStatus.None)
break; break;
if (!trSsRes.SelectSet) if (!trSsRes.SelectSet)
continue; continue;
for (let s of trSsRes.SelectSet.SelectSetList) let newCus = this.JigTrim(trSsRes, kniefCus, false);
for (let [c, cus] of newCus)
{ {
for (let obj of s.m_SelectList) c.Erase();
let len = kniefCus.length;
arrayRemove(kniefCus, c);
if (kniefCus.length !== len)
kniefCus.push(...cus);
for (let c of cus)
app.m_Database.ModelSpace.Append(c);
}
app.m_Editor.UpdateScreen();
}
// kniefCus.forEach(c => c.RestoreJigMaterial());
}
private JigTrim(trSsRes: PromptSsgetResult, kniefCus: Curve[], isJig = true)
{
let resCus: Map<Curve, Curve[]> = new Map();
for (let s of trSsRes.SelectSet.SelectSetList)
{
for (let obj of s.m_SelectList)
{
let cu = obj.userData as Curve;
if (s instanceof SelectBox)
{ {
let cu = obj.userData as Curve; let isKniefSelect = kniefCus.indexOf(cu) > -1;//被切割者自身也是刀.
if (s instanceof SelectBox) let isPolyline = cu instanceof Polyline; //被切割者是多段线
{ if (!cu || (isKniefSelect && !isPolyline)) //如果对象被第一轮选中,那么不切割它
let isKniefSelect = kniefCus.indexOf(cu) > -1;//被切割者自身也是刀. continue;
let isPolyline = cu instanceof Polyline; //被切割者是多段线
if (!cu || (isKniefSelect && !isPolyline)) //如果对象被第一轮选中,那么不切割它 let newCus: Curve[] = [];
continue; if (cu instanceof Polyline && (kniefCus.includes(cu) || kniefCus.length === 0))
newCus = this.TrimPolyline(cu, kniefCus, s);
let newCus: Curve[] = []; else if (cu instanceof Circle || cu instanceof Arc || cu instanceof Line || cu instanceof Polyline)
if (cu instanceof Polyline) newCus = this.TrimCurve(cu, kniefCus, s);
newCus = this.TrimPolyline(cu, kniefCus, s);
else if (cu instanceof Circle || cu instanceof Arc || cu instanceof Line) resCus.set(cu, newCus);
newCus = this.TrimCurve(cu, kniefCus, s);
newCus.forEach(c => { app.m_Database.ModelSpace.Append(c) });
}
cu.Erase();
arrayRemove(kniefCus, cu);
} }
} }
} }
kniefCus.forEach(c => c.RestoreJigMaterial()); return resCus;
} }
//得到曲线和刀曲线的切割点表 //得到曲线和刀曲线的切割点表
private GetIntersetPoints(kniefCus: Curve[], cu: Curve, thisCurve = cu) private GetIntersetPoints(kniefCus: Curve[], cu: Curve, thisCurve = cu)
{ {
@ -94,7 +138,7 @@ export class Command_Trim implements Command
* @param selBox * @param selBox
* @param [isSelect] * @param [isSelect]
*/ */
TrimCurve(curve: Line | Circle | Arc, kniefCus: Curve[], selBox: SelectBox, thisCurve: Curve = curve, insSelfPts: Vector3[] = []): Curve[] TrimCurve(curve: Line | Circle | Arc | Polyline, kniefCus: Curve[], selBox: SelectBox, thisCurve: Curve = curve, insSelfPts: Vector3[] = []): Curve[]
{ {
//求交 //求交
let intPts = this.GetIntersetPoints(kniefCus, curve, thisCurve); let intPts = this.GetIntersetPoints(kniefCus, curve, thisCurve);

@ -1,6 +1,7 @@
import { Vector3 } from 'three'; import { Vector3 } from 'three';
import { PromptEntityResult, PromptSsgetResult } from '../Editor/PromptResult'; import { PromptEntityResult, PromptSsgetResult } from '../Editor/PromptResult';
import { Filter } from '../Editor/SelectFilter'; import { Filter } from '../Editor/SelectFilter';
import { SelectType } from '../Editor/SelectBox';
/** /**
* ,. * ,.
@ -74,5 +75,6 @@ export interface GetSelectionPrompt extends GetAnyPrompt
Once?: boolean;//只选一次 Once?: boolean;//只选一次
UseSelect?: boolean;//使用当前已经选中的实体. UseSelect?: boolean;//使用当前已经选中的实体.
Filter?: Filter; Filter?: Filter;
SelectType?: SelectType;
Callback?: (res: PromptSsgetResult) => void; Callback?: (res: PromptSsgetResult) => void;
} }

@ -164,12 +164,12 @@ export abstract class Curve extends Entity
m.material = ColorMaterial.GetLineMaterial(this.m_Color); m.material = ColorMaterial.GetLineMaterial(this.m_Color);
} }
UpdateJigMaterial() UpdateJigMaterial(color = 8)
{ {
for (let [type, en] of this.m_DrawEntity) for (let [type, en] of this.m_DrawEntity)
{ {
let l = en as Line; let l = en as Line;
l.material = ColorMaterial.GetLineMaterial(8); l.material = ColorMaterial.GetLineMaterial(color);
} }
} }
} }

@ -210,7 +210,7 @@ export class Entity extends CADObject
* *
* @memberof Entity * @memberof Entity
*/ */
UpdateJigMaterial() UpdateJigMaterial(color = 8)
{ {
} }
RestoreJigMaterial() RestoreJigMaterial()

@ -8,6 +8,7 @@ import { PromptSsgetResult, PromptStatus } from './PromptResult';
import { SelectPick } from './SelectPick'; import { SelectPick } from './SelectPick';
import { Filter } from './SelectFilter'; import { Filter } from './SelectFilter';
import { SelectSet } from './SelectSet'; import { SelectSet } from './SelectSet';
import { SelectType } from './SelectBox';
/** /**
* . ed.Ssget * . ed.Ssget
@ -38,6 +39,9 @@ export class SsgetServiecs
set.Filter(prompt.Filter); set.Filter(prompt.Filter);
selectCtrl.UpdateView(); selectCtrl.UpdateView();
} }
if (prompt.SelectType)
selectCtrl.SelectType = prompt.SelectType;
//如果使用当前选择,并且已经存在选择对象,那么直接返回. //如果使用当前选择,并且已经存在选择对象,那么直接返回.
if (prompt.UseSelect && set.SelectEntityList.length > 0) if (prompt.UseSelect && set.SelectEntityList.length > 0)
{ {
@ -55,10 +59,11 @@ export class SsgetServiecs
Filter: prompt.Filter, Filter: prompt.Filter,
Callback: (res) => Callback: (res) =>
{ {
if (res.Entity && prompt.Callback) if (prompt.Callback)
{ {
let ssEnt = new SelectPick(this.m_Editor.m_App.m_Viewer, res.Point); let ssEnt = new SelectPick(this.m_Editor.m_App.m_Viewer, this.m_Editor.m_MouseCtrl.m_CurMousePointVCS);
ssEnt.m_SelectList.push(res.Entity.Draw(RenderType.Wireframe)); if (res.Entity)
ssEnt.m_SelectList.push(res.Entity.Draw(RenderType.Wireframe));
let set = new SelectSet(); let set = new SelectSet();
set.AddSelect(ssEnt); set.AddSelect(ssEnt);
prompt.Callback({ Status: PromptStatus.OK, SelectSet: set }); prompt.Callback({ Status: PromptStatus.OK, SelectSet: set });
@ -166,6 +171,7 @@ export class SsgetServiecs
this.promisResolve(res); this.promisResolve(res);
this.m_Editor.m_SelectCtrl.Cancel(); this.m_Editor.m_SelectCtrl.Cancel();
this.m_Editor.m_SelectCtrl.m_Filter = undefined; this.m_Editor.m_SelectCtrl.m_Filter = undefined;
this.m_Editor.m_SelectCtrl.SelectType = SelectType.None;
} }
private m_AwaitRemoveCalls: Function[] = []; private m_AwaitRemoveCalls: Function[] = [];

@ -1,10 +1,8 @@
import * as THREE from 'three'; import * as THREE from 'three';
import { Vector3 } from 'three'; import { Vector3 } from 'three';
import { Entity } from '../DatabaseServices/Entity'; import { Entity } from '../DatabaseServices/Entity';
import { SelectSet } from './SelectSet'; import { SelectSet } from './SelectSet';
export enum PromptStatus export enum PromptStatus
{ {
None = 0, None = 0,
@ -83,4 +81,3 @@ export class PromptSsgetResult extends PromptResult
{ {
SelectSet?: SelectSet; SelectSet?: SelectSet;
} }

@ -30,6 +30,7 @@ export class SelectControls implements EditorService
private m_Viewer: Viewer; private m_Viewer: Viewer;
private m_SelectSet: SelectSet = new SelectSet(); private m_SelectSet: SelectSet = new SelectSet();
m_Filter: Filter; m_Filter: Filter;
private m_SelectType: SelectType = SelectType.None;
constructor(view: Viewer, ed: Editor) constructor(view: Viewer, ed: Editor)
{ {
@ -42,6 +43,11 @@ export class SelectControls implements EditorService
{ {
return this.m_SelectSet; return this.m_SelectSet;
} }
set SelectType(type: SelectType)
{
this.m_SelectType = type;
this.m_SelectCss.selectType = type;
}
RegisterEvent() RegisterEvent()
{ {
let ed = this.m_Editor; let ed = this.m_Editor;
@ -145,7 +151,10 @@ export class SelectControls implements EditorService
SelectByCss() SelectByCss()
{ {
let selectBox = new SelectBox(this.m_Viewer, this.m_SelectCss.start, this.m_SelectCss.end); let selectBox = new SelectBox(this.m_Viewer, this.m_SelectCss.start, this.m_SelectCss.end);
selectBox.m_SelectType = this.m_SelectCss.end.x > this.m_SelectCss.start.x ? SelectType.W : SelectType.C; if (this.m_SelectType !== SelectType.None)
selectBox.m_SelectType = this.m_SelectType;
else
selectBox.m_SelectType = this.m_SelectCss.end.x > this.m_SelectCss.start.x ? SelectType.W : SelectType.C;
selectBox.Select(undefined, this.m_Filter); selectBox.Select(undefined, this.m_Filter);
return selectBox; return selectBox;
} }

@ -1,5 +1,6 @@
import * as THREE from 'three'; import * as THREE from 'three';
import { Viewer } from '../../GraphicsSystem/Viewer'; import { Viewer } from '../../GraphicsSystem/Viewer';
import { SelectType } from '../../Editor/SelectBox';
//矩形选框 //矩形选框
export class SelectMarquee export class SelectMarquee
@ -13,8 +14,9 @@ export class SelectMarquee
dom: HTMLElement; dom: HTMLElement;
width: number; width: number;
height: number; height: number;
viewer: Viewer;
selectType: SelectType = SelectType.None;
viewer: Viewer
constructor(view: Viewer) constructor(view: Viewer)
{ {
this.viewer = view; this.viewer = view;
@ -55,7 +57,16 @@ export class SelectMarquee
this.dom.style.width = this.width + "px" this.dom.style.width = this.width + "px"
this.dom.style.height = this.height + "px" this.dom.style.height = this.height + "px"
if (this.start.x > this.end.x) let type = this.selectType;
if (this.selectType === SelectType.None)
{
if (this.start.x > this.end.x)
type = SelectType.C;
else
type = SelectType.W;
}
if (type === SelectType.C)
{ {
this.dom.style.background = this.leftColor; this.dom.style.background = this.leftColor;
this.dom.style.border = this.leftBorder; this.dom.style.border = this.leftBorder;
@ -76,4 +87,4 @@ export class SelectMarquee
this.end.set(x, y) this.end.set(x, y)
this.Update() this.Update()
} }
} }

Loading…
Cancel
Save