优化:封边分段代码优化,酷家乐导入后封边计算错误进行错误提示

pull/2039/head
ChenX 2 years ago
parent 23beab2b49
commit bc03b1c4a4

@ -1,7 +1,7 @@
import { Board } from "../../src/DatabaseServices/Entity/Board"; import { Board } from "../../src/DatabaseServices/Entity/Board";
import { Curve } from "../../src/DatabaseServices/Entity/Curve"; import { Curve } from "../../src/DatabaseServices/Entity/Curve";
import { Polyline } from "../../src/DatabaseServices/Entity/Polyline"; import { Polyline } from "../../src/DatabaseServices/Entity/Polyline";
import { CalcEdgeSealing, GetBoardSealingData, GetSealedBoardContour, ParagraphCulist } from "../../src/GraphicsSystem/CalcEdgeSealing"; import { CalcEdgeSealing, GetBoardSealingData, GetSealedBoardContour, SubsectionCurvesOfHightSeal } from "../../src/GraphicsSystem/CalcEdgeSealing";
import { ConverToPtsBul } from "../../src/Production/Convert2PtsBul"; import { ConverToPtsBul } from "../../src/Production/Convert2PtsBul";
import "../Utils/jest.util"; import "../Utils/jest.util";
import { LoadBoardsFromFileData } from "../Utils/LoadEntity.util"; import { LoadBoardsFromFileData } from "../Utils/LoadEntity.util";
@ -11,7 +11,7 @@ function testBrSealing(br: Board, sealingSize: number[])
let originCurve = br.ContourCurve; let originCurve = br.ContourCurve;
let dir = Math.sign(originCurve.Area2) * -1; let dir = Math.sign(originCurve.Area2) * -1;
let calcCus = originCurve.Explode() as Curve[]; let calcCus = originCurve.Explode() as Curve[];
ParagraphCulist(calcCus); SubsectionCurvesOfHightSeal(calcCus);
let offsetCus: Curve[] = []; let offsetCus: Curve[] = [];
for (let i = 0; i < calcCus.length; i++) for (let i = 0; i < calcCus.length; i++)

@ -1,4 +1,3 @@
import { Intent } from "@blueprintjs/core";
import { Box3, Euler, Matrix4, Vector3 } from "three"; import { Box3, Euler, Matrix4, Vector3 } from "three";
import { app } from "../../../ApplicationServices/Application"; import { app } from "../../../ApplicationServices/Application";
import { arrayLast, arrayRemoveIf } from "../../../Common/ArrayExt"; import { arrayLast, arrayRemoveIf } from "../../../Common/ArrayExt";
@ -9,6 +8,7 @@ import { BuyZengZhiBao } from "../../../Common/HostUrl";
import { JigMoveEntity } from "../../../Common/JigMove"; import { JigMoveEntity } from "../../../Common/JigMove";
import { MakeMirrorMtx, NormalMatrix, RoundMatrix } from "../../../Common/Matrix4Utils"; import { MakeMirrorMtx, NormalMatrix, RoundMatrix } from "../../../Common/Matrix4Utils";
import { DuplicateRecordCloning } from "../../../Common/Status"; import { DuplicateRecordCloning } from "../../../Common/Status";
import { Intent, ToasterShowEntityMsg } from "../../../Common/Toaster";
import { Board } from "../../../DatabaseServices/Entity/Board"; import { Board } from "../../../DatabaseServices/Entity/Board";
import { Entity } from "../../../DatabaseServices/Entity/Entity"; import { Entity } from "../../../DatabaseServices/Entity/Entity";
import { ExtrudeSolid } from "../../../DatabaseServices/Entity/Extrude"; import { ExtrudeSolid } from "../../../DatabaseServices/Entity/Extrude";
@ -21,7 +21,7 @@ import { TemplateRecord } from "../../../DatabaseServices/Template/TemplateRecor
import { Command, CommandWrap } from "../../../Editor/CommandMachine"; import { Command, CommandWrap } from "../../../Editor/CommandMachine";
import { userConfig } from "../../../Editor/UserConfig"; import { userConfig } from "../../../Editor/UserConfig";
import { equaln, ZAxis } from "../../../Geometry/GeUtils"; import { equaln, ZAxis } from "../../../Geometry/GeUtils";
import { ParagraphSealinglist, SetBoardTopDownLeftRightSealData } from "../../../GraphicsSystem/CalcEdgeSealing"; import { ConverEachSeal2HightSealData, SetBoardTopDownLeftRightSealData } from "../../../GraphicsSystem/CalcEdgeSealing";
import { BoardModalType } from "../../../UI/Components/Board/BoardModalType"; import { BoardModalType } from "../../../UI/Components/Board/BoardModalType";
import { AppConfirm } from "../../../UI/Components/Common/Confirm"; import { AppConfirm } from "../../../UI/Components/Common/Confirm";
import { AppToaster } from "../../../UI/Components/Toaster"; import { AppToaster } from "../../../UI/Components/Toaster";
@ -340,9 +340,25 @@ async function ParseModel(model: KJL_ParamModel,
let last = arrayLast(sealeds); let last = arrayLast(sealeds);
for (let i = sealeds.length; i < cus.length; i++) for (let i = sealeds.length; i < cus.length; i++)
sealeds.push(last); sealeds.push(last);
let edges = ParagraphSealinglist(sealeds, cus);
br.BoardProcessOption.highSealed = edges; let hightSeals = ConverEachSeal2HightSealData(sealeds, cus);
SetBoardTopDownLeftRightSealData(br, edges); br.BoardProcessOption.highSealed = hightSeals;
try
{
SetBoardTopDownLeftRightSealData(br, hightSeals);
}
catch (error)
{
setTimeout(() =>
{
ToasterShowEntityMsg({
intent: Intent.DANGER,
msg: "无法计算板的上下左右封边,请检查板的轮廓是否正常!",
ent: br,
timeout: 60000
});
}, 1000);
}
} }
for (let i = 1; i < pls.length; i++) for (let i = 1; i < pls.length; i++)

@ -16,119 +16,128 @@ import { IHighSealedItem, ISealingData } from "../UI/Store/BoardInterface";
import { IntersectOption } from "./IntersectWith"; import { IntersectOption } from "./IntersectWith";
import { ParseEdgeSealDir } from "./ParseEdgeSealDir"; import { ParseEdgeSealDir } from "./ParseEdgeSealDir";
type CurveGroups = (Curve[])[];
/** /**
*线 * 线( (使,线,))
* @l-arc-l,l-arc-arc-l,l-arc-l-arc-l.... * @l-arc-l,l-arc-arc-l,l-arc-l-arc-l....
* @param in_out_curves 线( )
* @returns curveGroups
*/ */
export function ParagraphCulist(cus: Curve[]) export function SubsectionCurvesOfHightSeal(in_out_curves: Curve[]): CurveGroups
{ {
let newCulist: (Curve[])[] = []; let curveGroups: CurveGroups = [];
let usedCu: WeakSet<Curve> = new WeakSet(); let usedCu: WeakSet<Curve> = new WeakSet();
//归类曲线,返回归类是否成功 //归类曲线,返回归类是否成功
const paragraph = (cu: Curve, originCu: Curve, cuList: Curve[], isBack: boolean) => const paragraph = (nextCurve: Curve, curCurve: Curve, curvesGroup: Curve[], isBack: boolean) =>
{ {
const cuIsLine = cu instanceof Line; const curIsLine = curCurve instanceof Line;
const originCuIsLine = originCu instanceof Line; const nextIsLine = nextCurve instanceof Line;
if (usedCu.has(cu)) if (usedCu.has(nextCurve))
return false; return false;
if (originCuIsLine !== cuIsLine) if (curIsLine !== nextIsLine)//直线和圆弧
{ {
if (originCuIsLine) if (curIsLine)
{ {
if (isBack) if (isBack)
{ {
if (!isParallelTo(originCu.GetFistDeriv(0), cu.GetFistDeriv(0))) if (!isParallelTo(curCurve.GetFistDeriv(0), nextCurve.GetFistDeriv(0)))
return false; return false;
} }
else else
{ {
if (!isParallelTo(originCu.GetFistDeriv(0), cu.GetFistDeriv(1))) if (!isParallelTo(curCurve.GetFistDeriv(0), nextCurve.GetFistDeriv(1)))
return false; return false;
} }
} }
if (cuIsLine) if (nextIsLine)
{ {
if (isBack) if (isBack)
{ {
if (!isParallelTo(originCu.GetFistDeriv(1), cu.GetFistDeriv(0))) if (!isParallelTo(curCurve.GetFistDeriv(1), nextCurve.GetFistDeriv(0)))
return false; return false;
} }
else else
{ {
if (!isParallelTo(originCu.GetFistDeriv(0), cu.GetFistDeriv(0))) if (!isParallelTo(curCurve.GetFistDeriv(0), nextCurve.GetFistDeriv(0)))
return false; return false;
} }
} }
} }
else if (cuIsLine) else if (nextIsLine)//都是直线
{ {
//共线且相连的直线分为一组 #I11T1Z //共线且相连的直线分为一组 #I11T1Z
if (!isParallelTo(cu.GetFistDeriv(0).normalize(), originCu.GetFistDeriv(0).normalize())) if (!isParallelTo(nextCurve.GetFistDeriv(0).normalize(), curCurve.GetFistDeriv(0).normalize()))
return false; return false;
let pts = [originCu.StartPoint, originCu.EndPoint];
let pts2 = [cu.StartPoint, cu.EndPoint]; let pts = [curCurve.StartPoint, curCurve.EndPoint];
if (pts.every(p => pts2.every(p2 => !equalv3(p, p2, 1e-6)))) let pts2 = [nextCurve.StartPoint, nextCurve.EndPoint];
if (pts.every(p => pts2.every(p2 => !equalv3(p, p2, 1e-6))))//2条线完全分离 没有共同点
return false; return false;
} }
//else 都是圆弧 必然成组
if (isBack) if (isBack)
cuList.push(cu); curvesGroup.push(nextCurve);
else else
cuList.unshift(cu); curvesGroup.unshift(nextCurve);
usedCu.add(cu);
usedCu.add(nextCurve);
return true; return true;
}; };
let caclCus = cus.filter(c => !equaln(c.Length, 0)); let caclCus = in_out_curves.filter(c => !equaln(c.Length, 0));
while (caclCus.length > 0) while (caclCus.length > 0)
{ {
let originCu = caclCus.shift(); let curCurve = caclCus.shift();
if (usedCu.has(originCu)) if (usedCu.has(curCurve))
continue; continue;
let originCus = [originCu]; let curvesGroup = [curCurve];//编组
usedCu.add(originCu); usedCu.add(curCurve);
//往后搜索 //往后搜索
for (let i = 0; i < caclCus.length; i++) for (let i = 0; i < caclCus.length; i++)
{ {
if (!paragraph(caclCus[i], originCu, originCus, true)) if (!paragraph(caclCus[i], curCurve, curvesGroup, true))
break; break;
originCu = caclCus[i]; curCurve = caclCus[i];
} }
//只有第一条才需要往前搜索 //只有第一条才需要往前搜索
if (caclCus.length === cus.length - 1) if (caclCus.length === in_out_curves.length - 1)
{ {
originCu = originCus[0]; curCurve = curvesGroup[0];
//往前搜索 //往前搜索
for (let i = caclCus.length - 1; i >= 0; i--) for (let i = caclCus.length - 1; i >= 0; i--)
{ {
if (!paragraph(caclCus[i], originCu, originCus, false)) if (!paragraph(caclCus[i], curCurve, curvesGroup, false))
break; break;
originCu = caclCus[i]; curCurve = caclCus[i];
} }
} }
newCulist.push(originCus); curveGroups.push(curvesGroup);
} }
cus.length = 0;
in_out_curves.length = 0;
//同组多条曲线连接为多段线 //同组多条曲线连接为多段线
for (let g of newCulist) for (let g of curveGroups)
{ {
if (g.length === 1) if (g.length === 1)
cus.push(g[0]); in_out_curves.push(g[0]);
else else
{ {
let pl = new Polyline(); let pl = new Polyline();
for (let c of g) for (let c of g)
{
pl.Join(c); pl.Join(c);
} in_out_curves.push(pl);
cus.push(pl);
} }
} }
return curveGroups;
} }
/** /**
@ -351,13 +360,14 @@ export function GetBoardSealingCurves(br: Board, isOffset = false): Curve[]
{ {
cus = cu.Explode() as Curve[]; cus = cu.Explode() as Curve[];
if (br.IsSpecialShape) if (br.IsSpecialShape)
ParagraphCulist(cus); SubsectionCurvesOfHightSeal(cus);
return cus; return cus;
} }
} }
const SEAL_VALUE_KEY = "__highSeals__"; //曲线的每段封边值
const __CURVE_EACH_SEAL_VALUE_KEY__ = "__CURVE_EACH_SEAL_VALUE__";
/** /**
@ -477,7 +487,7 @@ export function GetSealedBoardContour(br: Board, hasSealing: boolean, isParseSea
{ {
let cir = offsetCus[0]; let cir = offsetCus[0];
if (highSealsExpd) cir[SEAL_VALUE_KEY] = highSealsExpd; if (highSealsExpd) cir[__CURVE_EACH_SEAL_VALUE_KEY__] = highSealsExpd;
return cir; return cir;
} }
@ -490,14 +500,14 @@ export function GetSealedBoardContour(br: Board, hasSealing: boolean, isParseSea
highSealsExpd?.reverse(); highSealsExpd?.reverse();
} }
if (highSealsExpd) pl[SEAL_VALUE_KEY] = highSealsExpd; if (highSealsExpd) pl[__CURVE_EACH_SEAL_VALUE_KEY__] = highSealsExpd;
return pl; return pl;
} }
export function GetBoardSealingData(curve: Polyline | Circle) export function GetBoardSealingData(curve: Polyline | Circle)
{ {
let sealData = curve[SEAL_VALUE_KEY] as ISealingData[]; let sealData = curve[__CURVE_EACH_SEAL_VALUE_KEY__] as ISealingData[];
if (curve instanceof Circle) if (curve instanceof Circle)
{ {
sealData[0].length *= 0.5; sealData[0].length *= 0.5;
@ -507,90 +517,28 @@ export function GetBoardSealingData(curve: Polyline | Circle)
} }
export function ParagraphSealinglist(hightSeal: IHighSealedItem[], cus: Curve[]) /**
* 11WebCAD
* @param seals 线
* @param curves 线
* @returns ()
*/
export function ConverEachSeal2HightSealData(seals: IHighSealedItem[], curves: Curve[]): IHighSealedItem[]
{ {
if (hightSeal.length !== cus.length) return hightSeal; curves = curves.concat();
seals = seals.concat();
let usedCu: WeakSet<Curve> = new WeakSet(); let s = seals[seals.length - 1];
let newHighSeal: IHighSealedItem[] = []; for (let i = seals.length; i < curves.length; i++)
seals.push(s);
//归类曲线,返回归类是否成功
const paragraph = (cu: Curve, originCu: Curve, isBack: boolean) =>
{
const cuIsLine = cu instanceof Line;
const originCuIsLine = originCu instanceof Line;
if (usedCu.has(cu)) const KEY = "__CURVE_SEAL_DATA__";
return false;
if (originCuIsLine !== cuIsLine) for (let i = 0; i < curves.length; i++)
{ curves[i][KEY] = seals[i];
if (originCuIsLine &&
!isParallelTo(originCu.GetFistDeriv(0), cu.GetFistDeriv(0))
&& !isParallelTo(originCu.GetFistDeriv(0), cu.GetFistDeriv(1))
)
{
return false;
}
if (cuIsLine
&& !isParallelTo(originCu.GetFistDeriv(1), cu.GetFistDeriv(0))
&& !isParallelTo(originCu.GetFistDeriv(0), cu.GetFistDeriv(0)
))
{
return false;
}
}
else if (cuIsLine)
{
//共线且相连的直线分为一组 #I11T1Z
if (!isParallelTo(cu.GetFistDeriv(0).normalize(), originCu.GetFistDeriv(0).normalize()))
return false;
let pts = [originCu.StartPoint, originCu.EndPoint];
let pts2 = [cu.StartPoint, cu.EndPoint];
if (pts.every(p => pts2.every(p2 => !equalv3(p, p2, 1e-6))))
return false;
}
if (isBack)
hightSeal.shift();
else
hightSeal.pop();
usedCu.add(cu);
return true;
};
let caclCus = cus.slice();
while (caclCus.length > 0) let groups = SubsectionCurvesOfHightSeal(curves);
{
let originCu = caclCus.shift();
if (usedCu.has(originCu))
continue;
let oldCu = originCu;
let originSeal = hightSeal.shift();
newHighSeal.push(originSeal);
usedCu.add(originCu);
//往后搜索
for (let i = 0; i < caclCus.length; i++)
{
if (!paragraph(caclCus[i], originCu, true))
break;
originCu = caclCus[i];
}
//只有第一条才需要往前搜索
if (caclCus.length === cus.length - 1)
{
originCu = oldCu;
//往前搜索
for (let i = caclCus.length - 1; i >= 0; i--)
{
if (!paragraph(caclCus[i], originCu, false))
break;
originCu = caclCus[i];
}
}
}
return newHighSeal; return groups.map(g => g[0][KEY]);
} }
/** 设置板的上下左右封边 */ /** 设置板的上下左右封边 */

@ -3,10 +3,10 @@ import { action, observable } from 'mobx';
import { observer } from 'mobx-react'; import { observer } from 'mobx-react';
import React, { Component } from 'react'; import React, { Component } from 'react';
import { end } from 'xaop'; import { end } from 'xaop';
import { CADFiler } from '../../../../api';
import { app } from '../../../../ApplicationServices/Application'; import { app } from '../../../../ApplicationServices/Application';
import { equalArray } from '../../../../Common/ArrayExt'; import { equalArray } from '../../../../Common/ArrayExt';
import { GetCurrentViewPreViewImage } from '../../../../Common/SerializeMaterial'; import { GetCurrentViewPreViewImage } from '../../../../Common/SerializeMaterial';
import { CADFiler } from '../../../../DatabaseServices/CADFiler';
import { CameraSnapshootRecord } from '../../../../DatabaseServices/CameraSnapshoot/CameraSnapshootRecord'; import { CameraSnapshootRecord } from '../../../../DatabaseServices/CameraSnapshoot/CameraSnapshootRecord';
import { RestoreCameraSnapshootRecord, SaveCameraSnapshootRecord } from '../../../../DatabaseServices/CameraSnapshoot/CameraSnapshootRecordUtil'; import { RestoreCameraSnapshootRecord, SaveCameraSnapshootRecord } from '../../../../DatabaseServices/CameraSnapshoot/CameraSnapshootRecordUtil';
import { userConfig } from '../../../../Editor/UserConfig'; import { userConfig } from '../../../../Editor/UserConfig';

Loading…
Cancel
Save