优化:捕捉时返回捕捉到的实体

pull/2870/head
ChenX 3 months ago
parent 6da12e126e
commit f6978d9240

@ -160,14 +160,20 @@ export class DrawLine implements Command
//第一个是切点 第二个也是选切点 //第一个是切点 第二个也是选切点
if (ptRes.SnapMode === ObjectSnapMode.Tan && firstTangeCircle && pts.length === 1) if (ptRes.SnapMode === ObjectSnapMode.Tan && firstTangeCircle && pts.length === 1)
{ {
let pick = new SelectPick(app.Viewer, app.Viewer.WorldToScreen(ptRes.Point.clone()), app.Editor.GetPointServices.snapServices.SnapSize); if (!ptRes.SnapEntity)
pick.Select(app.Viewer.VisibleObjects, { filterTypes: [Circle, Arc] });
let secondTangeCircle: Circle = (pick.SelectEntityList as Circle[]).find(c => c.PtInCurve(ptRes.Point));
if (secondTangeCircle)
{ {
AppToaster.show({
message: "程序错误!无法获取捕捉圆,请重试!",
timeout: 3000,
intent: Intent.WARNING,
});
continue;
}
else
{
let secondTangeCircle = ptRes.SnapEntity as Circle;
//计算最优切线 //计算最优切线
let lines = CircleInternalTangentLines(firstTangeCircle as Circle, secondTangeCircle as Circle).concat(CircleOuterTangentLines(firstTangeCircle as Circle, secondTangeCircle as Circle)); let lines = CircleInternalTangentLines(firstTangeCircle as Circle, secondTangeCircle).concat(CircleOuterTangentLines(firstTangeCircle as Circle, secondTangeCircle as Circle));
if (!lines?.length) if (!lines?.length)
{ {
AppToaster.show({ AppToaster.show({
@ -191,9 +197,7 @@ export class DrawLine implements Command
nearestObjectIndex = i; nearestObjectIndex = i;
} }
} }
line = lines[nearestObjectIndex]; line = lines[nearestObjectIndex];
}
app.LayoutTool.AppendDatabaseSpace(line); app.LayoutTool.AppendDatabaseSpace(line);
@ -203,6 +207,7 @@ export class DrawLine implements Command
JigUtils.Destroy(); JigUtils.Destroy();
continue; continue;
} }
}
//正常画线 //正常画线
app.LayoutTool.AppendDatabaseSpace(line); app.LayoutTool.AppendDatabaseSpace(line);

@ -447,6 +447,7 @@ export class Ellipse extends Curve
{ {
return getTanPtsOnEllipse(this, lastPoint); return getTanPtsOnEllipse(this, lastPoint);
} }
return [];
} }
default: default:
return []; return [];

@ -55,7 +55,10 @@ export class GetPointServices implements EditorService
return; return;
} }
this.ReturnPoint(this.curPoint, this.curPointIsSnap ? this.snapServices.SnapType : undefined); this.ReturnPoint(this.curPoint,
this.curPointIsSnap ? this.snapServices.SnapType : undefined,
this.curPointIsSnap ? this.snapServices.SnapEntity : undefined,
);
return true; return true;
} }
else if (e.button === MouseKey.Right) else if (e.button === MouseKey.Right)
@ -480,7 +483,7 @@ export class GetPointServices implements EditorService
} }
//调用promis的回调. //调用promis的回调.
protected ReturnPoint(p: Vector3, snapMode?: ObjectSnapMode) protected ReturnPoint(p: Vector3, snapMode?: ObjectSnapMode, snapEntity?: Entity)
{ {
let retValue = new PromptPointResult(); let retValue = new PromptPointResult();
@ -500,6 +503,7 @@ export class GetPointServices implements EditorService
retValue.intersection = this.intersection; retValue.intersection = this.intersection;
retValue.SnapMode = snapMode; retValue.SnapMode = snapMode;
retValue.SnapEntity = snapEntity;
this.lastPoint = p; this.lastPoint = p;
@ -545,6 +549,7 @@ export class GetPointServices implements EditorService
app.Viewer.PreViewer.Cursor.IsThreeMode = this._oldIsThreeState; app.Viewer.PreViewer.Cursor.IsThreeMode = this._oldIsThreeState;
app.Viewer.PreViewer.Cursor.Mode = CursorMode.None; app.Viewer.PreViewer.Cursor.Mode = CursorMode.None;
this.snapServices.SnapModeEnable = this.snapModeCurrent; this.snapServices.SnapModeEnable = this.snapModeCurrent;
this.snapServices.SnapEntity = undefined;
this._prompt = undefined; this._prompt = undefined;
this.intersection = undefined; this.intersection = undefined;

@ -41,7 +41,7 @@ export class PromptResult
export class PromptPointResult extends PromptResult export class PromptPointResult extends PromptResult
{ {
SnapMode: ObjectSnapMode; SnapMode: ObjectSnapMode;
// SnapEntity: Entity; TODO: SnapEntity: Entity;
intersection: Intersection; intersection: Intersection;
private _point: Vector3; private _point: Vector3;
/** /**

@ -62,7 +62,8 @@ interface SupportSnapEntity
interface SupportSnapPoint interface SupportSnapPoint
{ {
Point?: Vector3; Point?: Vector3;
Entitys?: SupportSnapEntity[]; Entity?: Entity;//捕捉到的实体
Entitys?: SupportSnapEntity[];//辅助捕捉实体
} }
//正交捕捉轴 //正交捕捉轴
@ -82,6 +83,8 @@ export class SnapServices
SnapModeEnable: ObjectSnapMode = ObjectSnapMode.All; SnapModeEnable: ObjectSnapMode = ObjectSnapMode.All;
EnablePolarSnap: boolean = true;//允许极轴捕捉 EnablePolarSnap: boolean = true;//允许极轴捕捉
CustomAxis: Vector3[] = [];//自定义捕捉轴 CustomAxis: Vector3[] = [];//自定义捕捉轴
SnapEntity: Entity;//当前捕捉点来自的实体(仅当切线捕捉时有效)
private _SnapType: ObjectSnapMode = ObjectSnapMode.None;//当前点的捕捉类型 private _SnapType: ObjectSnapMode = ObjectSnapMode.None;//当前点的捕捉类型
private _DynPrompt: PromptBlock; private _DynPrompt: PromptBlock;
private _HasBasePoint: boolean = false; private _HasBasePoint: boolean = false;
@ -235,6 +238,7 @@ export class SnapServices
{ {
this._SupportExtLinePts.length = 0; this._SupportExtLinePts.length = 0;
this._SnapType = ObjectSnapMode.None; this._SnapType = ObjectSnapMode.None;
this.SnapEntity = undefined;
if (this.Disabled) if (this.Disabled)
return; return;
@ -334,6 +338,7 @@ export class SnapServices
if (SnapPoint(pv, vcsP, this.SnapSize)) if (SnapPoint(pv, vcsP, this.SnapSize))
{ {
this.SnapType = ObjectSnapMode.Tan; this.SnapType = ObjectSnapMode.Tan;
this.SnapEntity = e;
return p; return p;
} }
} }
@ -389,6 +394,7 @@ export class SnapServices
); );
this.SnapType = mode; this.SnapType = mode;
this.SnapEntity = snapData.Entity;
return snapData.Point; return snapData.Point;
} }
} }
@ -399,9 +405,9 @@ export class SnapServices
{ {
let cus = sel.SelectEntityList.filter(e => e instanceof Curve || e instanceof RoomWallBase) as Curve[]; let cus = sel.SelectEntityList.filter(e => e instanceof Curve || e instanceof RoomWallBase) as Curve[];
let cuIns = new CurveIntersection(cus); let cuIns = new CurveIntersection(cus);
for (let [, pMap] of cuIns.intersect) for (let [e1, pMap] of cuIns.intersect)
{ {
for (let [, pts] of pMap) for (let [e2, pts] of pMap)
{ {
for (let p of pts) for (let p of pts)
{ {
@ -497,6 +503,7 @@ export class SnapServices
{ {
minZ = z; minZ = z;
snapData.Point = p; snapData.Point = p;
snapData.Entity = en;
snapData.Entitys = this.GetSupportEntity(mode, en, baseP, p, pIndex); snapData.Entitys = this.GetSupportEntity(mode, en, baseP, p, pIndex);
} }
else if (dist < 2 * this.SnapSize ** 2 && dist < minDistance) else if (dist < 2 * this.SnapSize ** 2 && dist < minDistance)
@ -504,6 +511,7 @@ export class SnapServices
minZ = z; minZ = z;
minDistance = dist; minDistance = dist;
snapData.Point = p; snapData.Point = p;
snapData.Entity = en;
snapData.Entitys = this.GetSupportEntity(mode, en, baseP, p, pIndex); snapData.Entitys = this.GetSupportEntity(mode, en, baseP, p, pIndex);
} }
} }

Loading…
Cancel
Save