diff --git a/__test__/EdgeSealing/EdgeSealing.test.ts b/__test__/EdgeSealing/EdgeSealing.test.ts index dd3078591..f038a2c24 100644 --- a/__test__/EdgeSealing/EdgeSealing.test.ts +++ b/__test__/EdgeSealing/EdgeSealing.test.ts @@ -145,3 +145,23 @@ test("封边错误板件2", () => expect(con.Area).toMatchSnapshot(); }); +test("封边错误板件3", () => +{ + let data = { "file": [1, "Board", 8, 2, 100, false, 1, 3, 0, [1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 668.6547958775191, 360.34483792621177, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 668.6547958775191, 360.34483792621177, 0, 1], 0, 3, 430.00000000003945, 843.0000701800069, 18, true, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 429.99984841118567, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 6, [843, -429.99984841118567], 0, [843.0000701800067, 0.00015158885375399223], 0, [843.0000701800069, 0.00015158885375399223], 0, [843.0000000000002, 0.00015158881433308125], 0, [0, 0], 0, [0, -429.99984841118567], 0, true, 0, 3, 0, 0, 0, 0, 0, 9, 2, "背板", "", "父母房-衣柜", "兔宝宝洛萨暮影(杉木芯)", "兔宝宝洛萨暮影(杉木芯)", "兔宝宝洛萨暮影(杉木芯)", 0, 1, "三合一", 2, 5, 1, 1, 1, 1, 1, "1", "1", "1", "1", "", "", "", 6, "三合一", "三合一", "三合一", "三合一", "三合一", "三合一", false, true, 0, 0, 0, 0, 0, 0, 0, 0, true], "basePt": { "x": 668.6547958775191, "y": 342.34483792621177, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] }; + let br = LoadBoardsFromFileData(data)[0]; + + let con = GetSealedBoardContour(br, false); + expect(con.IsClose).toBeTruthy(); + + expect(con.Area).toMatchSnapshot(); +}); +test("封边错误板件4", () => +{ + let data = { "file": [1, "Board", 8, 2, 104, false, 1, 4, 0, [1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 1791.2350208071002, 332.28157054709305, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1791.221632944289, 332.28157054709305, -1220.5383064692724, 1], 0, 3, 608.4984929746847, 54, 18, false, "Polyline", 8, 2, 0, false, 0, 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, [0, 0], 0, [53.986612137188786, 0], 0, [54, 0.8772342627713384], 0, [53.99999999999998, 578.4441943321467], 0, [0, 608.4984929746847], 0, true, 0, 3, 0, 0, 0, 0, 0, 9, 2, "左收口条", "主卧", "下柜左收口", "多层板", "多层板", "无语枫木", 0, 0, "三合一", 2, 0, "1", "1", "1", "1", "", "", "", 5, "三合一", "三合一", "三合一", "三合一", "三合一", true, true, 0, 0, 0, 0, 0, 0, 0, 0, true], "basePt": { "x": 1791.2350208071002, "y": 314.28157054709305, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] }; + let br = LoadBoardsFromFileData(data)[0]; + + let con = GetSealedBoardContour(br, false); + expect(con.IsClose).toBeTruthy(); + + expect(con.Area).toMatchSnapshot(); +}); diff --git a/__test__/EdgeSealing/__snapshots__/EdgeSealing.test.ts.snap b/__test__/EdgeSealing/__snapshots__/EdgeSealing.test.ts.snap index 2b434c4c6..2bdd43588 100644 --- a/__test__/EdgeSealing/__snapshots__/EdgeSealing.test.ts.snap +++ b/__test__/EdgeSealing/__snapshots__/EdgeSealing.test.ts.snap @@ -4,10 +4,14 @@ exports[`丢失线段板件 1`] = `554052.5007766777`; exports[`丢失线段板件 2`] = `398758.8789695821`; -exports[`封边错误板件 1`] = `130118.40949065729`; +exports[`封边错误板件 1`] = `130118.4094685434`; exports[`封边错误板件2 1`] = `779770.9650700318`; +exports[`封边错误板件3 1`] = `359947.9512754363`; + +exports[`封边错误板件4 1`] = `30748.998596293524`; + exports[`常规板件,常规坐标系 1`] = `716404`; exports[`常规板件,常规坐标系 2`] = `711624`; diff --git a/src/Add-on/Purge.ts b/src/Add-on/Purge.ts index b4fffd8af..7ee6b6ef6 100644 --- a/src/Add-on/Purge.ts +++ b/src/Add-on/Purge.ts @@ -49,4 +49,10 @@ export function Purge(db: Database) { return g.Entitys.length === 0 || g.Entitys.every(e => !e || e.IsErase); }); + arrayRemoveIf(db.LayoutSpace.Entitys, e => + { + let isErase = e.IsErase; + if (isErase) e.GoodBye(); + return isErase; + }); } diff --git a/src/Common/CurveUtils.ts b/src/Common/CurveUtils.ts index 14fec3b14..5fa6f0c9e 100644 --- a/src/Common/CurveUtils.ts +++ b/src/Common/CurveUtils.ts @@ -15,7 +15,7 @@ import { IntersectOption, IntersectResult } from '../GraphicsSystem/IntersectWit import { OffsetPolyline } from '../GraphicsSystem/OffsetPolyline'; import { arrayLast, changeArrayStartIndex, equalArray } from './ArrayExt'; import { Status } from './Status'; -import { FixIndex } from './Utils'; +import { FixIndex, LINK_FUZZ } from './Utils'; //3点获取圆心 export function getCircleCenter(pt1: Vector3, pt2: Vector3, pt3: Vector3) @@ -570,7 +570,7 @@ export function MergeCurvelist(cus: Curve[]) let c2 = cus[nextI]; - let status = equaln(c2.Length, 0) ? Status.True : c1.Join(c2, false, 1e-4); + let status = equaln(c2.Length, 0, LINK_FUZZ) ? Status.True : c1.Join(c2, false, LINK_FUZZ); if (status === Status.True) { cus.splice(nextI, 1); diff --git a/src/Common/Utils.ts b/src/Common/Utils.ts index 11cdf117b..e87e1f234 100644 --- a/src/Common/Utils.ts +++ b/src/Common/Utils.ts @@ -14,6 +14,9 @@ export const onlyEnExpReg = /[^A-Za-z]/g; export const ClosingStripReg = /[左|右|上]{1}收口$/; export const FileFormatReg = /^\[(\d+,){5}[(true)|(false)].+\]$/; +/**扣除封边是否相连和连接共用精度 */ +export const LINK_FUZZ = 1e-3; + export async function draw(en: Entity | Entity[] | Object3D) { let app = (await import("../ApplicationServices/Application")).app; diff --git a/src/Editor/AutoSave.ts b/src/Editor/AutoSave.ts index a35c97e67..8ae470a19 100644 --- a/src/Editor/AutoSave.ts +++ b/src/Editor/AutoSave.ts @@ -11,7 +11,6 @@ import { TempEditor } from "./TempEditor"; export class AutoSaveServer { - private indexDbStore: IndexedDbStore; //缓存过了 isCached = false; private timeId: NodeJS.Timeout; @@ -58,11 +57,14 @@ export class AutoSaveServer } async SavaData(data: any[]) { - if (!this.indexDbStore) - this.indexDbStore = await IndexedDbStore.CADStore(); + const indexDbStore = await IndexedDbStore.CADStore(); let server = FileServer.GetInstance() as FileServer; - this.indexDbStore.Put(StoreName.FileCache, localStorage.getItem(StoreageKeys.Uid), { time: new Date().toLocaleString(), data, fid: server.m_CurFileId }); - Log("文件缓存成功!"); + const uid = localStorage.getItem(StoreageKeys.Uid); + if (uid) + { + indexDbStore.Put(StoreName.FileCache, uid, { time: new Date().toLocaleString(), data, fid: server.m_CurFileId }); + Log("文件缓存成功!"); + } this.isCached = true; } async Clear() diff --git a/src/GraphicsSystem/CalcEdgeSealing.ts b/src/GraphicsSystem/CalcEdgeSealing.ts index b9d6c709d..cc4888227 100644 --- a/src/GraphicsSystem/CalcEdgeSealing.ts +++ b/src/GraphicsSystem/CalcEdgeSealing.ts @@ -1,5 +1,5 @@ import { EBoardKeyList } from "../Common/BoardKeyList"; -import { FixIndex } from "../Common/Utils"; +import { FixIndex, LINK_FUZZ } from "../Common/Utils"; import { Board } from "../DatabaseServices/Entity/Board"; import { Circle } from "../DatabaseServices/Entity/Circle"; import { Curve } from "../DatabaseServices/Entity/Curve"; @@ -115,8 +115,7 @@ export function ParagraphCulist(cus: Curve[]) } } -/**扣除封边是否相连和连接共用精度 */ -export const LINK_FUZZ = 1e-3; + /** *计算封边 @@ -162,6 +161,8 @@ export function CalcEdgeSealing(cus: Curve[]) { cus.splice(i, 1); i -= 2; + if (i < -1) + i = -1; } else frontLine.EndPoint = iPt; @@ -171,7 +172,7 @@ export function CalcEdgeSealing(cus: Curve[]) if (par > 1) { cus.splice(laterIndex, 1); - i -= 2; + i -= 1; } else laterLine.StartPoint = iPt; @@ -212,6 +213,8 @@ export function GetBoardHighSeal(br: Board, sealcus: Curve[]) /**偏移前后曲线起点没改变 */ export function OffsetOutlineSpNotChange(oldcu: Curve, newCu: Curve) { + if (!newCu) + return false; let sDerv = oldcu.GetFistDeriv(0).normalize(); let eDerv = oldcu.GetFistDeriv(oldcu.EndParam).normalize().negate(); sDerv.add(eDerv).normalize(); diff --git a/src/Production/Product.ts b/src/Production/Product.ts index 2e2b13eb6..4122a3333 100644 --- a/src/Production/Product.ts +++ b/src/Production/Product.ts @@ -28,7 +28,7 @@ import { Hole } from "../DatabaseServices/3DSolid/Hole"; import { lookOverBoardInfosTool } from "../Add-on/LookOverBoardInfos/LookOverBoardInfosTool"; import { Entity } from './../DatabaseServices/Entity/Entity'; import { ICompHardwareOption } from './../UI/Components/RightPanel/RightPanelInterface'; -import { FixedNotZero } from "../Common/Utils"; +import { FixedNotZero, LINK_FUZZ } from "../Common/Utils"; /**板件轮廓数据 */ @@ -445,7 +445,7 @@ export namespace Production } let cus = con.Explode(); MergeCurvelist(cus); - let pl = Polyline.Combine(cus); + let pl = Polyline.Combine(cus, LINK_FUZZ); if (isSplite && pl.Area2 < 0) pl.Reverse(); return pl;