mirror of https://gitee.com/cf-fz/WebCAD.git
!1384 优化:自交轮廓拆单.新增命令:FIXINTSELFCONTOUR,处理板件自交轮廓
parent
3fa82e6e25
commit
80bfee373f
@ -0,0 +1,30 @@
|
||||
import { Polyline } from "../../src/api";
|
||||
import { LoadCurvesFromFileData } from "../Utils/LoadEntity.util";
|
||||
|
||||
describe("多段线自交测试", () =>
|
||||
{
|
||||
test("1", () =>
|
||||
{
|
||||
let data = { "file": [1, "Polyline", 8, 2, 100, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 5, [-405.4658285340993, 346.15614953113254], 0, [199.05178654403426, 293.2185491719283], 0, [-41.37296878534835, -275.93381387612317], 0, [-295.29944682260975, -125.79927409254014], 0, [-405.4658285340993, 346.15614953113254], 0, false], "basePt": { "x": -405.4658285340993, "y": -275.93381387612317, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
|
||||
let l = LoadCurvesFromFileData(data)[0] as Polyline;
|
||||
expect(l.IsIntersectSelf()).toBeFalsy();
|
||||
});
|
||||
test("2", () =>
|
||||
{
|
||||
let data = { "file": [1, "Polyline", 8, 2, 100, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 5, [-405.4658285340993, 346.15614953113254], 0, [199.05178654403426, 293.2185491719283], 0, [-41.37296878534835, -275.93381387612317], 0, [-329.7340533770039, -149.1338534587412], 0, [-168.03429997805506, 499.10567020310555], 0, false], "basePt": { "x": -405.4658285340993, "y": -275.93381387612317, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
|
||||
let l = LoadCurvesFromFileData(data)[0] as Polyline;
|
||||
expect(l.IsIntersectSelf()).toBeTruthy();
|
||||
});
|
||||
test("3", () =>
|
||||
{
|
||||
let data = { "file": [2, "Polyline", 8, 2, 100, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 5, [-405.4658285340993, 346.15614953113254], 0, [199.05178654403426, 293.2185491719283], 0, [-41.37296878534835, -275.93381387612317], 0, [-329.7340533770039, -149.1338534587412], 0, [-168.03429997805506, 499.10567020310555], 0, false, "Polyline", 8, 2, 101, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 3, [350.9080380477244, -198.03631544369273], 0, [602.9728936312604, -450.10117102722876], 0, [450.7051441358635, -297.83342153183185], 0, false], "basePt": { "x": -405.4658285340993, "y": -450.10117102722876, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
|
||||
let l = LoadCurvesFromFileData(data)[0] as Polyline;
|
||||
expect(l.IsIntersectSelf()).toBeTruthy();
|
||||
});
|
||||
test("4", () =>
|
||||
{
|
||||
let data = { "file": [1, "Polyline", 8, 2, 102, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 4, [299.09997619187925, -843.5733706604224], 0, [975.021500869887, -932.7190956496634], -0.9667799920499004, [909.3278130216058, -1605.3849557429785], 0.9667799920499004, [975.021500869887, -932.7190956496634], 0, false], "basePt": { "x": 299.09997619187925, "y": -1606.0680424764628, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
|
||||
let l = LoadCurvesFromFileData(data)[0] as Polyline;
|
||||
expect(l.IsIntersectSelf()).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,38 @@
|
||||
import { app } from "../../ApplicationServices/Application";
|
||||
import { Log } from "../../Common/Log";
|
||||
import { Board } from "../../DatabaseServices/Entity/Board";
|
||||
import { Polyline } from "../../DatabaseServices/Entity/Polyline";
|
||||
import { Command } from "../../Editor/CommandMachine";
|
||||
import { PromptStatus } from "../../Editor/PromptResult";
|
||||
import { CreateContour2 } from "../../Geometry/CreateContour2";
|
||||
|
||||
export class FixIntersectSelfContour implements Command
|
||||
{
|
||||
async exec()
|
||||
{
|
||||
let brRes = await app.Editor.GetSelection({
|
||||
Msg: "选择板件",
|
||||
Filter: { filterTypes: [Board] },
|
||||
UseSelect: true,
|
||||
});
|
||||
|
||||
if (brRes.Status === PromptStatus.Cancel) return;
|
||||
|
||||
let brs = brRes.SelectSet.SelectEntityList as Board[];
|
||||
|
||||
for (let br of brs)
|
||||
{
|
||||
let contour = br.ContourCurve;
|
||||
if (contour instanceof Polyline &&
|
||||
(contour.TempData?.IntSelf || contour.IsIntersectSelf()))
|
||||
{
|
||||
let newContor = CreateContour2(contour.Explode());
|
||||
if (newContor)
|
||||
br.ContourCurve = newContor.Curve;
|
||||
else
|
||||
Log("修正自交失败," + br.Name + " 板件可能仍存在自交,请手动修复");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in new issue