!561 优化槽校验

pull/561/MERGE
ChenX 5 years ago
parent 2c70166f3c
commit 6b83c01537

@ -1,19 +1,7 @@
import { LoadBoardsFromFileData } from "../Utils/LoadEntity.util";
import { CuttingBoard } from "../../src/Add-on/BoardCutting/CuttingUtils";
import { Board } from "../../src/DatabaseServices/Entity/Board";
import "../Utils/jest.util";
function CuttingBoard(orgBoard: Board, cutBoards: Board[])
{
for (let br of cutBoards)
{
let gs = orgBoard.ConverToLocalGroove(br.Clone());
for (let g of gs)
orgBoard.AppendGroove(g);
}
let splitBoard: Board[] = [];
orgBoard.GrooveCheckAll(splitBoard);
return splitBoard;
}
import { LoadBoardsFromFileData } from "../Utils/LoadEntity.util";
test('板件与板件切割_分裂成多个', () =>
{

@ -33,7 +33,6 @@ export class AutoCuttingReactor
}
StartReactor(ents: Board[])
{
let nc = new NonAssociativeCutting();
let brs: Board[] = [];
for (let ent of app.Database.ModelSpace.Entitys)
{
@ -41,6 +40,6 @@ export class AutoCuttingReactor
brs.push(ent);
}
for (let br of brs)
nc.CuttingBoard(br, ents);
br.Subtract(ents);
}
}

@ -1,22 +1,14 @@
import { ExtrudeSolid } from "../../DatabaseServices/Entity/Extrude";
import { Board } from "../../DatabaseServices/Entity/Board";
export function CuttingBoard(orgBoard: Board, knifBoards: Board[])
export function CuttingBoard(orgBoard: ExtrudeSolid, knifBoards: ExtrudeSolid[]): ExtrudeSolid[]
{
let addgs: ExtrudeSolid[] = [];
for (let br of knifBoards)
{
let gs = orgBoard.ConverToLocalGroove(br.Clone());
addgs.push(...gs);
let gs = orgBoard.ConverToLocalGroove(br);
for (let g of gs)
orgBoard.AppendGroove(g);
}
if (addgs.length === 0)
return [];
for (let g of addgs)
orgBoard.AppendGroove(g);
let splitBoard: Board[] = [];
let splitBoard: ExtrudeSolid[] = [];
orgBoard.GrooveCheckAll(splitBoard);
return splitBoard;
}

@ -1,6 +1,5 @@
import { app } from "../../ApplicationServices/Application";
import { Board } from "../../DatabaseServices/Entity/Board";
import { ExtrudeSolid } from "../../DatabaseServices/Entity/Extrude";
import { Command } from "../../Editor/CommandMachine";
import { PromptStatus } from "../../Editor/PromptResult";
@ -47,30 +46,6 @@ export class NonAssociativeCutting implements Command
app.Editor.Prompt(`选择了被切割的板件: 总计${brs.length}`);
for (let br of brs)
this.CuttingBoard(br, brs2);
}
CuttingBoard(orgBoard: Board, knifBoards: Board[])
{
let addgs: ExtrudeSolid[] = [];
for (let br of knifBoards)
{
let gs = orgBoard.ConverToLocalGroove(br.Clone());
addgs.push(...gs);
}
if (addgs.length === 0)
return [];
for (let g of addgs)
orgBoard.AppendGroove(g);
let splitBoard: Board[] = [];
orgBoard.GrooveCheckAll(splitBoard);
for (let br of splitBoard)
{
app.Database.ModelSpace.Append(br);
}
return splitBoard;
br.Subtract(brs2);
}
}

@ -1,5 +1,6 @@
import { Euler, Matrix4, Vector2, Vector3 } from "three";
import { app } from "../ApplicationServices/Application";
import { arrayRemoveDuplicateBySort } from "../Common/ArrayExt";
import { EBoardKeyList } from "../Common/BoardKeyList";
import { FileSystem } from "../Common/FileSystem";
import { JigMoveEntity } from "../Common/JigMove";
@ -14,8 +15,6 @@ import { AsVector2, equaln, equalv2 } from "../Geometry/GeUtils";
import { Vec3 } from "../Geometry/IVec3";
import { HotCMD } from "../Hot/HotCommand";
import { FaceDirection, LinesType } from "../UI/Store/BoardInterface";
import { NonAssociativeCutting } from "./BoardCutting/NonAssociativeCutting";
import { arrayRemoveDuplicateBySort } from "../Common/ArrayExt";
/** 模型类型 */
enum KJL_ModelType
@ -143,9 +142,8 @@ export class Command_KJLImport implements Command
allBrs.push(br);
}
let nc = new NonAssociativeCutting();
for (let br of allBrs)
nc.CuttingBoard(br, bbrs);
br.Subtract(bbrs);
}
return !ok;

@ -6,6 +6,7 @@ import { CADFiler } from "../DatabaseServices/CADFiler";
import { Entity } from "../DatabaseServices/Entity/Entity";
import { JigUtils } from "../Editor/JigUtils";
import { PromptStatus } from "../Editor/PromptResult";
import { arrayLast } from "../Common/ArrayExt";
export class PasteClip
{
@ -17,6 +18,10 @@ export class PasteClip
let str = await readClipboardText();
if (str.startsWith("zip:"))
str = inflate(str.slice(4));
str = str.trimRight();
if (arrayLast(str))
str = str.slice(0, -1);
data = JSON.parse(str);
}
catch (error)

@ -51,7 +51,7 @@ export function arrayFirst<T>(arr: Array<T>): T
return arr[0];
}
export function arrayLast<T>(arr: Array<T>): T
export function arrayLast<T>(arr: { [key: number]: T, length: number }): T
{
return arr[arr.length - 1];
}

@ -13,7 +13,7 @@ import { Box3Ext } from "../../Geometry/Box";
import { BSPGroupParse } from "../../Geometry/BSPGroupParse";
import { FastWireframe } from "../../Geometry/CreateWireframe";
import { EdgesGeometry } from "../../Geometry/EdgeGeometry";
import { equaln, equalv2, equalv3, isIntersect, isParallelTo, MoveMatrix, ZeroVec } from "../../Geometry/GeUtils";
import { equaln, equalv2, equalv3, isIntersect, isParallelTo, MoveMatrix, ZeroVec, IdentityMtx4 } from "../../Geometry/GeUtils";
import { OBB } from "../../Geometry/OBB/obb";
import { ScaleUV } from "../../Geometry/UVUtils";
import { RenderType } from "../../GraphicsSystem/RenderType";
@ -420,14 +420,32 @@ export class ExtrudeSolid extends Entity
return Status.False;
}
AppendGroove(groove: ExtrudeSolid)
Subtract(extrudes: ExtrudeSolid[])
{
if (groove.Width < 1e-3 || groove.Height < 1e-3 || groove.Thickness < 1e-3) return;
this.WriteAllObjectRecord();
if (this.GrooveCheckPosition(groove) === Status.True)
let grooves: ExtrudeSolid[] = [];
for (let br of extrudes)
{
this.grooves.push(groove);
let gs = this.ConverToLocalGroove(br);
grooves.push(...gs);
}
this.AppendGrooves(grooves);
}
AppendGroove(groove: ExtrudeSolid)
{
this.WriteAllObjectRecord();
this.grooves.push(groove);
}
/** ,.
* ,
*/
AppendGrooves(grooves: ExtrudeSolid[])
{
if (grooves.length === 0) return;
this.WriteAllObjectRecord();
this.grooves.push(...grooves);
this.GrooveCheckAllAutoSplit();
}
GetObjectSnapPoints(
@ -725,10 +743,11 @@ export class ExtrudeSolid extends Entity
* @param target ()
* @param useClone
*/
ConverToLocalGroove(target: this, useClone = false): ExtrudeSolid[]
ConverToLocalGroove(target: ExtrudeSolid): ExtrudeSolid[]
{
if (isParallelTo(this.Normal, target.Normal))
{
target = target.Clone();
if (this.GrooveCheckPosition(target) !== Status.True)
return [];
@ -753,9 +772,10 @@ export class ExtrudeSolid extends Entity
let box = new Box3().setFromPoints(pts);
let size = box.getSize(new Vector3());
let ext = useClone ? target.Clone() : new ExtrudeSolid();
if (useClone)
ext.grooves.length = 0;
let ext = new ExtrudeSolid();
ext.groovesAddDepth = target.groovesAddDepth;
ext.groovesAddLength = target.groovesAddLength;
ext.knifeRadius = target.knifeRadius;
ext.ConverToRectSolid(size.x, size.y, size.z);
ext.OCS = m.clone().setPosition(box.min.applyMatrix4(m));
@ -772,7 +792,7 @@ export class ExtrudeSolid extends Entity
*/
GrooveCheckPosition(target: ExtrudeSolid): Status
{
if (target.thickness <= 1e-3)
if (target.Width < 1e-3 || target.Height < 1e-3 || target.Thickness < 1e-3)
return Status.False;
let tp = target.Position.applyMatrix4(this.OCSInv);
@ -789,9 +809,10 @@ export class ExtrudeSolid extends Entity
}
else if (maxZ >= (this.thickness - 1e-3) && minZ > 0)//正面
target.Thickness = this.thickness - minZ;
else return Status.False;
else
return Status.False;
return target.Thickness > 0 ? Status.True : Status.False;
return Status.True;
}
/**
@ -853,9 +874,6 @@ export class ExtrudeSolid extends Entity
*/
GrooveCheckContour(target: ExtrudeSolid): ExtrudeSolid[]
{
if (equaln(target.thickness, this.thickness))
return [target];
let matrixToTarget = target.OCSInv.multiply(this.OCS);
matrixToTarget.elements[14] = 0;//z->0
@ -984,6 +1002,8 @@ export class ExtrudeSolid extends Entity
this.IsNeedGrooveCheck = true;
return;
}
this.IsNeedGrooveCheck = false;
this.WriteAllObjectRecord();
//校验Z轴位置
arrayRemoveIf(this.grooves, g =>
@ -1019,30 +1039,38 @@ export class ExtrudeSolid extends Entity
}
//修正凹槽轮廓
let splitGrooves = [];
let splitGrooves: ExtrudeSolid[] = [];
for (let g of this.grooves)
splitGrooves.push(...this.GrooveCheckContour(g));
{
if (equaln(g.thickness, this.thickness))
splitGrooves.push(g);
else
splitGrooves.push(...this.GrooveCheckContour(g));
}
this.grooves = splitGrooves;
this.Update();
}
LazyGrooveCheckAll()
/** 校验内部槽并且自动分裂 */
GrooveCheckAllAutoSplit()
{
if (this.IsNeedGrooveCheck)
{
let splitEntitys: this[] = [];
this.GrooveCheckAll(splitEntitys);
let splitEntitys: this[] = [];
this.GrooveCheckAll(splitEntitys);
if (this._Owner)
{
let record = this._Owner.Object as BlockTableRecord;
for (let e of splitEntitys)
record.Add(e);
}
if (this._Owner)
{
let record = this._Owner.Object as BlockTableRecord;
for (let e of splitEntitys)
record.Add(e);
}
this.IsNeedGrooveCheck = false;
}
LazyGrooveCheckAll()
{
if (this.IsNeedGrooveCheck)
this.GrooveCheckAllAutoSplit();
this.IsLazyGrooveCheck = false;
}

Loading…
Cancel
Save