|
|
|
@ -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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|