!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 { Board } from "../../src/DatabaseServices/Entity/Board";
import "../Utils/jest.util"; import "../Utils/jest.util";
import { LoadBoardsFromFileData } from "../Utils/LoadEntity.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;
}
test('板件与板件切割_分裂成多个', () => test('板件与板件切割_分裂成多个', () =>
{ {

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

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

@ -1,6 +1,5 @@
import { app } from "../../ApplicationServices/Application"; import { app } from "../../ApplicationServices/Application";
import { Board } from "../../DatabaseServices/Entity/Board"; import { Board } from "../../DatabaseServices/Entity/Board";
import { ExtrudeSolid } from "../../DatabaseServices/Entity/Extrude";
import { Command } from "../../Editor/CommandMachine"; import { Command } from "../../Editor/CommandMachine";
import { PromptStatus } from "../../Editor/PromptResult"; import { PromptStatus } from "../../Editor/PromptResult";
@ -47,30 +46,6 @@ export class NonAssociativeCutting implements Command
app.Editor.Prompt(`选择了被切割的板件: 总计${brs.length}`); app.Editor.Prompt(`选择了被切割的板件: 总计${brs.length}`);
for (let br of brs) for (let br of brs)
this.CuttingBoard(br, brs2); br.Subtract(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;
} }
} }

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

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

@ -51,7 +51,7 @@ export function arrayFirst<T>(arr: Array<T>): T
return arr[0]; 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]; return arr[arr.length - 1];
} }

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

Loading…
Cancel
Save