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