mirror of https://gitee.com/cf-fz/WebCAD.git
!1463 功能:DXF导入和黏贴进WebCAD时,自动对复杂的多段线进行简化
parent
41153a3a14
commit
e94d18fafa
@ -0,0 +1,201 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`小恐龙简化 1`] = `723`;
|
||||
|
||||
exports[`小恐龙简化 2`] = `671`;
|
||||
|
||||
exports[`小恐龙简化 3`] = `"7392.79910"`;
|
||||
|
||||
exports[`小恐龙简化 4`] = `"7397.08024"`;
|
||||
|
||||
exports[`小恐龙简化 5`] = `5`;
|
||||
|
||||
exports[`小恐龙简化 6`] = `11`;
|
||||
|
||||
exports[`小恐龙简化 7`] = `"312.62650"`;
|
||||
|
||||
exports[`小恐龙简化 8`] = `"312.60195"`;
|
||||
|
||||
exports[`小恐龙简化 9`] = `35`;
|
||||
|
||||
exports[`小恐龙简化 10`] = `30`;
|
||||
|
||||
exports[`小恐龙简化 11`] = `"1274.39343"`;
|
||||
|
||||
exports[`小恐龙简化 12`] = `"1275.37625"`;
|
||||
|
||||
exports[`小恐龙简化 13`] = `12`;
|
||||
|
||||
exports[`小恐龙简化 14`] = `17`;
|
||||
|
||||
exports[`小恐龙简化 15`] = `"682.96871"`;
|
||||
|
||||
exports[`小恐龙简化 16`] = `"682.97027"`;
|
||||
|
||||
exports[`小恐龙简化 17`] = `41`;
|
||||
|
||||
exports[`小恐龙简化 18`] = `34`;
|
||||
|
||||
exports[`小恐龙简化 19`] = `"1976.93033"`;
|
||||
|
||||
exports[`小恐龙简化 20`] = `"1976.92695"`;
|
||||
|
||||
exports[`小恐龙简化 21`] = `55`;
|
||||
|
||||
exports[`小恐龙简化 22`] = `47`;
|
||||
|
||||
exports[`小恐龙简化 23`] = `"1220.90675"`;
|
||||
|
||||
exports[`小恐龙简化 24`] = `"1220.88609"`;
|
||||
|
||||
exports[`小恐龙简化 25`] = `5`;
|
||||
|
||||
exports[`小恐龙简化 26`] = `12`;
|
||||
|
||||
exports[`小恐龙简化 27`] = `"1024.58103"`;
|
||||
|
||||
exports[`小恐龙简化 28`] = `"1024.58094"`;
|
||||
|
||||
exports[`小恐龙简化 29`] = `21`;
|
||||
|
||||
exports[`小恐龙简化 30`] = `21`;
|
||||
|
||||
exports[`小恐龙简化 31`] = `"1644.30507"`;
|
||||
|
||||
exports[`小恐龙简化 32`] = `"1644.30507"`;
|
||||
|
||||
exports[`小恐龙简化 33`] = `5`;
|
||||
|
||||
exports[`小恐龙简化 34`] = `5`;
|
||||
|
||||
exports[`小恐龙简化 35`] = `"1049.95998"`;
|
||||
|
||||
exports[`小恐龙简化 36`] = `"1049.95998"`;
|
||||
|
||||
exports[`小恐龙简化 37`] = `51`;
|
||||
|
||||
exports[`小恐龙简化 38`] = `46`;
|
||||
|
||||
exports[`小恐龙简化 39`] = `"1225.55997"`;
|
||||
|
||||
exports[`小恐龙简化 40`] = `"1225.54790"`;
|
||||
|
||||
exports[`小恐龙简化 41`] = `23`;
|
||||
|
||||
exports[`小恐龙简化 42`] = `17`;
|
||||
|
||||
exports[`小恐龙简化 43`] = `"783.79812"`;
|
||||
|
||||
exports[`小恐龙简化 44`] = `"783.80056"`;
|
||||
|
||||
exports[`小恐龙简化 45`] = `46`;
|
||||
|
||||
exports[`小恐龙简化 46`] = `41`;
|
||||
|
||||
exports[`小恐龙简化 47`] = `"1308.96068"`;
|
||||
|
||||
exports[`小恐龙简化 48`] = `"1308.92526"`;
|
||||
|
||||
exports[`小恐龙简化 49`] = `34`;
|
||||
|
||||
exports[`小恐龙简化 50`] = `35`;
|
||||
|
||||
exports[`小恐龙简化 51`] = `"646.03175"`;
|
||||
|
||||
exports[`小恐龙简化 52`] = `"645.95028"`;
|
||||
|
||||
exports[`小恐龙简化 53`] = `87`;
|
||||
|
||||
exports[`小恐龙简化 54`] = `75`;
|
||||
|
||||
exports[`小恐龙简化 55`] = `"949.48587"`;
|
||||
|
||||
exports[`小恐龙简化 56`] = `"948.69812"`;
|
||||
|
||||
exports[`小恐龙简化 57`] = `4`;
|
||||
|
||||
exports[`小恐龙简化 58`] = `4`;
|
||||
|
||||
exports[`小恐龙简化 59`] = `"341.03322"`;
|
||||
|
||||
exports[`小恐龙简化 60`] = `"341.03322"`;
|
||||
|
||||
exports[`小恐龙简化 61`] = `41`;
|
||||
|
||||
exports[`小恐龙简化 62`] = `25`;
|
||||
|
||||
exports[`小恐龙简化 63`] = `"503.59965"`;
|
||||
|
||||
exports[`小恐龙简化 64`] = `"503.15867"`;
|
||||
|
||||
exports[`小恐龙简化 65`] = `3`;
|
||||
|
||||
exports[`小恐龙简化 66`] = `3`;
|
||||
|
||||
exports[`小恐龙简化 67`] = `"158.44290"`;
|
||||
|
||||
exports[`小恐龙简化 68`] = `"158.44290"`;
|
||||
|
||||
exports[`简化多段线成为圆弧 1`] = `43`;
|
||||
|
||||
exports[`简化多段线成为圆弧 2`] = `33`;
|
||||
|
||||
exports[`简化多段线成为圆弧 3`] = `"1107.92600"`;
|
||||
|
||||
exports[`简化多段线成为圆弧 4`] = `"1107.90911"`;
|
||||
|
||||
exports[`简化多段线成为圆弧 5`] = `43`;
|
||||
|
||||
exports[`简化多段线成为圆弧 6`] = `33`;
|
||||
|
||||
exports[`简化多段线成为圆弧 7`] = `"1107.92600"`;
|
||||
|
||||
exports[`简化多段线成为圆弧 8`] = `"1107.90911"`;
|
||||
|
||||
exports[`简化多段线成为圆弧 9`] = `81`;
|
||||
|
||||
exports[`简化多段线成为圆弧 10`] = `59`;
|
||||
|
||||
exports[`简化多段线成为圆弧 11`] = `"2215.88135"`;
|
||||
|
||||
exports[`简化多段线成为圆弧 12`] = `"2215.85712"`;
|
||||
|
||||
exports[`简化多段线成为圆弧 13`] = `44`;
|
||||
|
||||
exports[`简化多段线成为圆弧 14`] = `34`;
|
||||
|
||||
exports[`简化多段线成为圆弧 15`] = `"1628.59895"`;
|
||||
|
||||
exports[`简化多段线成为圆弧 16`] = `"1628.58206"`;
|
||||
|
||||
exports[`简化多段线成为圆弧 17`] = `47`;
|
||||
|
||||
exports[`简化多段线成为圆弧 18`] = `37`;
|
||||
|
||||
exports[`简化多段线成为圆弧 19`] = `"1422.40410"`;
|
||||
|
||||
exports[`简化多段线成为圆弧 20`] = `"1422.38721"`;
|
||||
|
||||
exports[`简化多段线成为圆弧 21`] = `6`;
|
||||
|
||||
exports[`简化多段线成为圆弧 22`] = `23`;
|
||||
|
||||
exports[`简化多段线成为圆弧 23`] = `"2077.93854"`;
|
||||
|
||||
exports[`简化多段线成为圆弧 24`] = `"2078.01268"`;
|
||||
|
||||
exports[`简化多段线成为圆弧 25`] = `9`;
|
||||
|
||||
exports[`简化多段线成为圆弧 26`] = `97`;
|
||||
|
||||
exports[`简化多段线成为圆弧 27`] = `"2041.09919"`;
|
||||
|
||||
exports[`简化多段线成为圆弧 28`] = `"2041.97439"`;
|
||||
|
||||
exports[`简化多段线成为圆弧 29`] = `2`;
|
||||
|
||||
exports[`简化多段线成为圆弧 30`] = `39`;
|
||||
|
||||
exports[`简化多段线成为圆弧 31`] = `"705.34043"`;
|
||||
|
||||
exports[`简化多段线成为圆弧 32`] = `"705.83666"`;
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,37 @@
|
||||
import { Polyline } from "../../src/DatabaseServices/Entity/Polyline";
|
||||
import { PointsSimplify2PolylineAndParseArc } from "../../src/DatabaseServices/SplineConver2Polyline";
|
||||
import { LoadEntityFromFileData } from "../Utils/LoadEntity.util";
|
||||
import "../Utils/jest.util";
|
||||
test('简化多段线成为圆弧', () =>
|
||||
{
|
||||
let ents = LoadEntityFromFileData(require("./points_polyline_file.json")) as Polyline[];
|
||||
|
||||
for (let pl of ents)
|
||||
{
|
||||
let pl1 = PointsSimplify2PolylineAndParseArc(pl.LineData.map(p => p.pt), undefined, 0.1, true);
|
||||
let pl2 = PointsSimplify2PolylineAndParseArc(pl.LineData.map(p => p.pt), undefined, 0.1, false);
|
||||
|
||||
expect(pl1.LineData.length).toMatchSnapshot();
|
||||
expect(pl2.LineData.length).toMatchSnapshot();
|
||||
|
||||
expect(pl1.Length).toMatchNumberSnapshot();
|
||||
expect(pl2.Length).toMatchNumberSnapshot();
|
||||
}
|
||||
});
|
||||
|
||||
test('小恐龙简化', () =>
|
||||
{
|
||||
let ents = LoadEntityFromFileData(require("./kl.json")) as Polyline[];
|
||||
|
||||
for (let pl of ents)
|
||||
{
|
||||
let pl1 = PointsSimplify2PolylineAndParseArc(pl.LineData.map(p => p.pt), undefined, 0.1, true);
|
||||
let pl2 = PointsSimplify2PolylineAndParseArc(pl.LineData.map(p => p.pt), undefined, 0.1, false);
|
||||
|
||||
expect(pl1.LineData.length).toMatchSnapshot();
|
||||
expect(pl2.LineData.length).toMatchSnapshot();
|
||||
|
||||
expect(pl1.Length).toMatchNumberSnapshot();
|
||||
expect(pl2.Length).toMatchNumberSnapshot();
|
||||
}
|
||||
});
|
@ -1,22 +1,42 @@
|
||||
import { app } from "../ApplicationServices/Application";
|
||||
import { Ellipse } from "../DatabaseServices/Entity/Ellipse";
|
||||
import { Polyline } from "../DatabaseServices/Entity/Polyline";
|
||||
import { Spline } from "../DatabaseServices/Spline";
|
||||
import { SmartPolylineSimply2Polyline } from "../DatabaseServices/SplineConver2Polyline";
|
||||
import { Command } from "../Editor/CommandMachine";
|
||||
import { PromptStatus } from "../Editor/PromptResult";
|
||||
import { equaln } from "../Geometry/GeUtils";
|
||||
|
||||
export class Command_Conver2Polyline implements Command
|
||||
{
|
||||
async exec()
|
||||
{
|
||||
let ssRes = await app.Editor.GetSelection({ Filter: { filterTypes: [Spline, Ellipse] } });
|
||||
let ssRes = await app.Editor.GetSelection({
|
||||
Filter: {
|
||||
filterFunction: (obj, ent) =>
|
||||
{
|
||||
if (ent instanceof Spline || ent instanceof Ellipse) return true;
|
||||
if (ent instanceof Polyline && ent.EndParam > 150 && ent.LineData.every(p => equaln(p.bul, 0, 1e-4))) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (ssRes.Status !== PromptStatus.OK) return;
|
||||
let ents = ssRes.SelectSet.SelectEntityList as (Spline | Ellipse)[];
|
||||
let ents = ssRes.SelectSet.SelectEntityList as (Spline | Ellipse | Polyline)[];
|
||||
|
||||
for (let e of ents)
|
||||
{
|
||||
e.Erase();
|
||||
let pl = e.Convert2Polyline();
|
||||
app.Database.ModelSpace.Append(pl);
|
||||
if (e instanceof Polyline)
|
||||
{
|
||||
let pl = SmartPolylineSimply2Polyline(e);
|
||||
app.Database.ModelSpace.Append(pl);
|
||||
}
|
||||
else
|
||||
{
|
||||
let pl = e.Convert2Polyline();
|
||||
app.Database.ModelSpace.Append(pl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,41 @@
|
||||
import { app } from "../../ApplicationServices/Application";
|
||||
import { Polyline } from "../../DatabaseServices/Entity/Polyline";
|
||||
import { SmartPolylineSimply2Polyline } from "../../DatabaseServices/SplineConver2Polyline";
|
||||
import { Command } from "../../Editor/CommandMachine";
|
||||
import { PromptStatus } from "../../Editor/PromptResult";
|
||||
import { Path2Polyline } from "../../Nest/Converter/Path2Polyline";
|
||||
import { TestDraw } from "../test/TestUtil";
|
||||
|
||||
//将多段线转换为碎点多段线
|
||||
export class Command_TestPolyline2PointsPolyline implements Command
|
||||
{
|
||||
async exec()
|
||||
{
|
||||
let enRes = await app.Editor.GetEntity({ Filter: { filterTypes: [Polyline] } });
|
||||
if (enRes.Status !== PromptStatus.OK) return;
|
||||
let pl = enRes.Entity as Polyline;
|
||||
let npl = Path2Polyline(pl.Shape.getPoints(8));
|
||||
npl.OCS = pl.OCSNoClone;
|
||||
await TestDraw(npl);
|
||||
}
|
||||
}
|
||||
|
||||
export class Command_SimplifyPolyline implements Command
|
||||
{
|
||||
async exec()
|
||||
{
|
||||
let ssRes = await app.Editor.GetSelection({ Filter: { filterTypes: [Polyline] } });
|
||||
if (ssRes.Status !== PromptStatus.OK) return;
|
||||
let pls = ssRes.SelectSet.SelectEntityList as Polyline[];
|
||||
|
||||
for (let pl of pls)
|
||||
{
|
||||
let npl = SmartPolylineSimply2Polyline(pl);
|
||||
if (npl.EndParam < pl.EndParam)
|
||||
{
|
||||
pl.Erase();
|
||||
app.Database.ModelSpace.Append(npl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue