!2635 优化:重构缺口板件功能

pull/2693/head
林三 6 months ago committed by ChenX
parent 938a25f6cf
commit e8d470a9a1

@ -1,20 +1,20 @@
import { ExtrudeHole } from "../../DatabaseServices/3DSolid/ExtrudeHole";
import { Board } from "../../DatabaseServices/Entity/Board";
import { Entity } from "../../DatabaseServices/Entity/Entity";
import { ExtrudeSolid } from "../../DatabaseServices/Entity/Extrude";
import { HardwareCompositeEntity } from "../../DatabaseServices/Hardware/HardwareCompositeEntity";
import { ISpaceParse } from "../../Geometry/SpaceParse/ISpaceParse";
/**
* ()0
*
*
* @param {ISpaceParse} paceParse
* @param {Entity} knifeBrs
* @param {Board[]} brs
*/
export function CuttingProtrudingPart(paceParse: ISpaceParse, brs: Board[])
export function CuttingProtrudingPart(knifeBrs: Set<Entity>, brs: Board[]): Board[]
{
// 获取包围框里的实体
let intersectsEnt = paceParse.IntersectSpaceEntitys || [];
let intersectsEnt = Array.from(knifeBrs) || [];
// 获取包围框里的实体与需要绘制实体碰撞的实体
let brKfs = intersectsEnt.filter((ent) => ent instanceof Board) as Board[];
// 处理碰撞的复合实体
@ -32,7 +32,18 @@ export function CuttingProtrudingPart(paceParse: ISpaceParse, brs: Board[])
hardwareKfs.push(e);
}
}
let newBrs: Board[] = [];
//直接切掉
for (let br of brs)
br.Subtract([...hardwareKfs, ...brKfs]);
{
let splitBrs: Board[] = [];
br.Subtract([...hardwareKfs, ...brKfs], splitBrs);
splitBrs.push(br);
splitBrs.sort((b1, b2) => b2.Volume - b1.Volume);
//切割后留下大块的
newBrs.push(splitBrs[0]);
}
return newBrs;
}

@ -16,8 +16,6 @@ import { BehindBoardStore, LayerBoardStore, VerticalBoardStore } from '../../UI/
import { PointToString } from '../../UI/Store/PointToString';
import { AutoCutting } from '../BoardCutting/AutoCuttingReactor';
const CacheSpaceEntitysMap: Map<string, Entity[]> = new Map();
export abstract class DrawBoardTool implements Command
{
//画板件类型,默认画层板
@ -25,10 +23,13 @@ export abstract class DrawBoardTool implements Command
protected modalType: BoardModalType;
protected store: LayerBoardStore | VerticalBoardStore | BehindBoardStore;
protected space: ISpaceParse;
protected IntersectSpaceEntitys: Set<Entity>;
CacheSpaceEntitysMap: Map<string, Set<Entity>> = new Map();
async exec()
{
let helpUrlName = "";
CacheSpaceEntitysMap.clear();
this.CacheSpaceEntitysMap.clear();
switch (this.drawType)
{
@ -73,7 +74,7 @@ export abstract class DrawBoardTool implements Command
if (selectSpace.ParseOK)
{
if (selectSpace.AutoCutting)
selectSpace.SpaceParse.IntersectSpaceEntitys = this.GetIntersectSpaceEntitys(selectSpace.SpaceParse);
this.IntersectSpaceEntitys = this.GetIntersectSpaceEntitys(selectSpace.SpaceParse);
this.buildBoard(false);
}
@ -100,7 +101,7 @@ export abstract class DrawBoardTool implements Command
return;
if (selectSpace.AutoCutting)
selectSpace.SpaceParse.IntersectSpaceEntitys = this.GetIntersectSpaceEntitys(selectSpace.SpaceParse);
this.IntersectSpaceEntitys = this.GetIntersectSpaceEntitys(selectSpace.SpaceParse);
this.space = selectSpace.SpaceParse;
this.store.m_Option.cuttingProtrudingPart = selectSpace.AutoCutting;
@ -116,16 +117,15 @@ export abstract class DrawBoardTool implements Command
{
let box = spaceParse.SpaceBox.clone().applyMatrix4(spaceParse.SpaceOCS);
let key = `${PointToString(box.min)}${PointToString(box.max)}`;
let ents = CacheSpaceEntitysMap.get(key);
let ents = this.CacheSpaceEntitysMap.get(key);
if (!ents)
{
ents = app.Database.ModelSpace.Entitys.filter((ent) =>
ents = new Set(app.Database.ModelSpace.Entitys.filter((ent) =>
{
return !ent.IsErase && (ent instanceof Board || ent instanceof HardwareCompositeEntity) && box.intersectsBox(ent.BoundingBox);
});
CacheSpaceEntitysMap.set(key, ents);
}));
this.CacheSpaceEntitysMap.set(key, ents);
}
return ents;
}

@ -21,6 +21,10 @@ export class DrawLayerBoard extends DrawBoardTool
temp.NailOption = store.layerNailOption;
temp.UseBoardProcessOption = this.store.BoardProcessOption.useBoardProcessOption;
temp.BoardProcessOption = this.store.BoardProcessOption;
if (this.store.m_Option.cuttingProtrudingPart)
temp.IntersectSpaceEntitys = this.IntersectSpaceEntitys;
app.Database.TemplateTable.Append(temp);
await SetTemplatePositionAndSetParent(this.space, temp);
}
@ -28,7 +32,8 @@ export class DrawLayerBoard extends DrawBoardTool
{
let brs = BuildLayerBoards(this.store.m_Option as LayerBoardOption, this.space);
if (this.store.m_Option.cuttingProtrudingPart)
CuttingProtrudingPart(this.space, brs);
CuttingProtrudingPart(this.IntersectSpaceEntitys, brs);
brs.forEach(b => JigUtils.Draw(b));
}
}

@ -20,6 +20,10 @@ export class DrawVerticalBoard extends DrawBoardTool
temp.UseBoardProcessOption = this.store.BoardProcessOption.useBoardProcessOption;;
temp.BoardProcessOption = this.store.BoardProcessOption;
temp.GrooveOption = this.store.grooveOption;
if (this.store.m_Option.cuttingProtrudingPart)
temp.IntersectSpaceEntitys = this.IntersectSpaceEntitys;
app.Database.TemplateTable.Append(temp);
await SetTemplatePositionAndSetParent(this.space, temp);
}
@ -28,7 +32,7 @@ export class DrawVerticalBoard extends DrawBoardTool
let brs = BuildVerticalBoards(this.store.m_Option as VerticalBoardOption, this.space);
if (this.store.m_Option.cuttingProtrudingPart)
CuttingProtrudingPart(this.space, brs);
CuttingProtrudingPart(this.IntersectSpaceEntitys, brs);
brs.forEach(b => JigUtils.Draw(b));
}

@ -5,7 +5,6 @@ import { AutoRecord } from "../../AutoRecord";
import { Factory } from "../../CADFactory";
import { CADFiler } from "../../CADFiler";
import { Board } from "../../Entity/Board";
import { Entity } from "../../Entity/Entity";
import { ObjectId } from "../../ObjectId";
import { Positioning, PositioningParam } from "./Positioning";
@ -18,19 +17,12 @@ export class PositioningClampSpace extends Positioning
@AutoRecord SelectBoxIndex: number[] = [0, 0, 0];//左右下
@AutoRecord SignalDist = 100;//默认为100 防止空
//与空间相交的实体
IntersectSpaceEntitys: Entity[];
FromSpaceParse(parse: ClampSpaceParse)
{
this.SignalDist = parse.SignalDist || 100;
this.Objects = parse.Boards.map(br => br.Id);
for (let [splitType, index] of parse.SelectBoxRecord)
this.SelectBoxIndex[splitType] = index;
//与空间相交的实体
if (parse.IntersectSpaceEntitys)
this.IntersectSpaceEntitys = parse.IntersectSpaceEntitys;
}
_SpaceParse: ClampSpaceParseFix;

@ -1,5 +1,4 @@
import { Factory } from "../../CADFactory";
import { Entity } from "../../Entity/Entity";
import { Positioning } from "./Positioning";
/**
@ -9,6 +8,5 @@ import { Positioning } from "./Positioning";
@Factory
export class PositioningTemporary extends Positioning
{
//与绘制的空间相交的实体
IntersectSpaceEntitys: Entity[];
}

@ -1,4 +1,5 @@
import { ExtendsBoardThickness } from "../../../Add-on/DrawBoard/BuildBoardTool";
import { CuttingProtrudingPart } from "../../../Add-on/DrawBoard/CuttingProtrudingPart";
import { EBoardKeyList } from "../../../Common/BoardKeyList";
import { ISpaceParse } from "../../../Geometry/SpaceParse/ISpaceParse";
import { BoardProcessOption } from "../../../UI/Store/OptionInterface/BoardProcessOption";
@ -22,6 +23,11 @@ export class TemplateBoardRecord extends TemplateRecord
@AutoRecord DrawBoardCount = 1;
//空间分析缺口切割需要的板件
protected IntersectSpaceEntitys: Set<Entity>;
//空间分析缺口切割需要原板件排钻信息
protected IntersectHighDrill: string[];
protected _option: BoardConfigOption;
// InitBaseParams()
// {
@ -80,7 +86,23 @@ export class TemplateBoardRecord extends TemplateRecord
this.UseBoardProcessOption = false;
}
//记录按缺口切割前的板轮廓
const OldContour = nbrs[0].ContourCurve.Clone();
//是否是被缺口切割
const IsIntersectSpaceEntitys = !!this.IntersectSpaceEntitys?.size;
if (IsIntersectSpaceEntitys)
{
if (!this.IntersectHighDrill?.length)
this.IntersectHighDrill = nbrs[0].BoardProcessOption.highDrill;
nbrs = CuttingProtrudingPart(this.IntersectSpaceEntitys, nbrs);
}
//继承refBr的BoardProcessOption/IsChaiDan/RelevanceMeats属性
let refBr: Board;
//记录生成的异型缺口板高级排钻列表
const HighDrill: string[] = [];
if (this.Objects.length > 0)
refBr = this.Objects[0].Object as Board;
@ -89,11 +111,18 @@ export class TemplateBoardRecord extends TemplateRecord
for (let i = 0; i < nbrs.length; i++)
{
let br: Board;
if (i < this.Objects.length)
{
let br = this.Objects[i].Object as Board;
br = this.Objects[i].Object as Board;
if (i >= this.DrawBoardCount)
br.Erase(false);
//缺口切割旧板 使用切割后的的轮廓信息
if (IsIntersectSpaceEntitys)
br.ContourCurve = nbrs[i].ContourCurve.Clone();
br.Position = nbrs[i].Position;
br.Width = nbrs[i].Width;
br.Height = nbrs[i].Height;
@ -101,16 +130,21 @@ export class TemplateBoardRecord extends TemplateRecord
}
else
{
let br = nbrs[i];
br = nbrs[i];
if (refBr)
{
br.ContourCurve = refBr.ContourCurve.Clone();
//新生成的缺口切割板 不使用原有的轮廓信息
if (!IsIntersectSpaceEntitys)
br.ContourCurve = refBr.ContourCurve.Clone();
br.BoardProcessOption = refBr.BoardProcessOption;
br.IsChaiDan = refBr.IsChaiDan;
br.RelevanceMeats = refBr.RelevanceMeats;
}
this._db.ModelSpace.Append(nbrs[i]);
this.Objects.push(nbrs[i].Id);
this._db.ModelSpace.Append(br);
this.Objects.push(br.Id);
//新创建的板 关联切割
for (let meat of br.RelevanceMeats)
@ -120,7 +154,30 @@ export class TemplateBoardRecord extends TemplateRecord
meatBr.RelevanceKnifs.push(br.objectId);
}
}
//缺口生成的异型板 分析排钻
if (IsIntersectSpaceEntitys && !br.IsRect)
{
if (!HighDrill.length)
{
let indexMap: number[] = [];
let newContour = br.ContourCurve;
for (let i = 0; i < newContour.EndParam; i++)
{
let p = newContour.GetPointAtParam(i + 0.5);
let cp = OldContour.GetClosestPointTo(p, false);
let cparam = OldContour.GetParamAtPoint2(cp);
indexMap.push(Math.floor(cparam));
}
for (let index of indexMap)
HighDrill.push(this.IntersectHighDrill[index]);
}
br.BoardProcessOption.highDrill = HighDrill;
}
}
this.DrawBoardCount = nbrs.length;
//保持SpaceCS

@ -1,12 +1,12 @@
import { activityLayerBoardTool } from "../../../Add-on/DrawBoard/ActivityLayerBoardTool";
import { BuildLayerBoards } from "../../../Add-on/DrawBoard/BuildBoardTool";
import { CuttingProtrudingPart } from "../../../Add-on/DrawBoard/CuttingProtrudingPart";
import { DefaultLayerBoardConfig, DefaultNailOption } from "../../../Editor/DefaultConfig";
import { ISpaceParse } from "../../../Geometry/SpaceParse/ISpaceParse";
import { IGrooveOption, LayerBoardOption, LayerNailOption } from "../../../UI/Store/OptionInterface/IOptionInterface";
import { Factory } from "../../CADFactory";
import { CADFiler } from "../../CADFiler";
import { Board } from "../../Entity/Board";
import { Entity } from "../../Entity/Entity";
import { TemplateBoardRecord } from "./TemplateBoard";
/**
@ -28,6 +28,10 @@ export class TemplateLayerBoard extends TemplateBoardRecord
grooveAddDepth: "0",
knifeRadius: "3",
};
//空间分析缺口切割需要的板件
IntersectSpaceEntitys: Set<Entity> = new Set();
IntersectHighDrill: string[] = [];
set GrooveOption(option: IGrooveOption)
{
this.WriteAllObjectRecord();
@ -45,10 +49,7 @@ export class TemplateLayerBoard extends TemplateBoardRecord
GeneralBoardList(space: ISpaceParse)
{
let brs = BuildLayerBoards(this._option, space, this.grooveOption);
if (this._option.cuttingProtrudingPart)
CuttingProtrudingPart(space, brs);
return brs;
return BuildLayerBoards(this._option, space, this.grooveOption);;
}
protected async Update()
@ -128,11 +129,26 @@ export class TemplateLayerBoard extends TemplateBoardRecord
this.grooveOption.grooveAddDepth = this.grooveOption.grooveAddDepth.toString();
this.grooveOption.knifeRadius = this.grooveOption.knifeRadius.toString();
}
this.IntersectSpaceEntitys.clear();
if (ver > 4)
{
let size = file.Read();
for (let i = 0; i < size; i++)
{
let ent = file.ReadObjectId().Object as Entity;
if (ent && !ent.IsErase)
this.IntersectSpaceEntitys.add(ent);
}
size = file.Read();
this.IntersectHighDrill = file.ReadArray(size);
}
}
WriteFile(file: CADFiler)
{
file.Write(4);
file.Write(5);
super.WriteFile(file);
file.Write(this._option.type);
file.Write(this._option.name);
@ -170,5 +186,14 @@ export class TemplateLayerBoard extends TemplateBoardRecord
file.Write(this.grooveOption.grooveAddWidth);
file.Write(this.grooveOption.grooveAddDepth);
file.Write(this.grooveOption.knifeRadius);
//ver5
file.Write(this.IntersectSpaceEntitys.size);
for (let ent of this.IntersectSpaceEntitys)
file.WriteObjectId(ent?.objectId);
file.Write(this.IntersectHighDrill.length);
for (let type of this.IntersectHighDrill)
file.Write(type);
}
}

@ -4,6 +4,7 @@ import { ISpaceParse } from "../../../Geometry/SpaceParse/ISpaceParse";
import { IGrooveOption, VerticalBoardOption } from "../../../UI/Store/OptionInterface/IOptionInterface";
import { Factory } from "../../CADFactory";
import { CADFiler } from "../../CADFiler";
import { Entity } from "../../Entity/Entity";
import { TemplateBoardRecord } from "./TemplateBoard";
/**
@ -29,10 +30,16 @@ export class TemplateVerticalBoard extends TemplateBoardRecord
this.WriteAllObjectRecord();
Object.assign(this.grooveOption, option);
}
//空间分析缺口切割需要的板件
IntersectSpaceEntitys: Set<Entity> = new Set();
IntersectHighDrill: string[] = [];
GeneralBoardList(space: ISpaceParse)
{
return BuildVerticalBoards(this._option, space, this.grooveOption);
return BuildVerticalBoards(this._option, space, this.grooveOption);;
}
ReadFile(file: CADFiler)
{
let ver = file.Read();
@ -76,10 +83,21 @@ export class TemplateVerticalBoard extends TemplateBoardRecord
this.grooveOption.grooveAddDepth = this.grooveOption.grooveAddDepth.toString();
this.grooveOption.knifeRadius = this.grooveOption.knifeRadius.toString();
}
this.IntersectSpaceEntitys.clear();
if (ver > 3)
{
let size = file.Read();
for (let i = 0; i < size; i++)
this.IntersectSpaceEntitys.add(file.ReadObject());
size = file.Read();
this.IntersectHighDrill = file.ReadArray(size);
}
}
WriteFile(file: CADFiler)
{
file.Write(3);
file.Write(4);
super.WriteFile(file);
file.Write(this._option.type);
file.Write(this._option.name);
@ -102,5 +120,15 @@ export class TemplateVerticalBoard extends TemplateBoardRecord
file.Write(this.grooveOption.grooveAddWidth);
file.Write(this.grooveOption.grooveAddDepth);
file.Write(this.grooveOption.knifeRadius);
//ver4
file.Write(this.IntersectSpaceEntitys.size);
for (let ent of this.IntersectSpaceEntitys)
file.WriteObject(ent);
file.Write(this.IntersectHighDrill.length);
for (let type of this.IntersectHighDrill)
file.Write(type);
}
}

@ -1588,11 +1588,6 @@ export async function SetTemplatePositionAndSetParent(spaceParse: ISpaceParse, t
let positioning = new PositioningTemporary();
positioning.SpaceCS = spaceParse.SpaceOCS;
positioning.SpaceSize = spaceParse.Size;
//与空间相交的实体
if (spaceParse.IntersectSpaceEntitys)
positioning.IntersectSpaceEntitys = spaceParse.IntersectSpaceEntitys;
template.Positioning = positioning;
//可能需要把父节点设置为空

@ -393,11 +393,6 @@ export class TemplateRecord extends SymbolTableRecord
if (this.HParam.expr)
this._CacheSpaceSize.z = this.HParam.EvalUpdate(this._CacheParamVars, paramMap, evaled, false);
//@ts-ignore
if (this._Positioning.IntersectSpaceEntitys)
//@ts-ignore
this._CacheIntersectSpaceEntitys = this._Positioning.IntersectSpaceEntitys;
if (this._Positioning instanceof PositioningTemporary)
this._Positioning = undefined;
}
@ -624,7 +619,6 @@ export class TemplateRecord extends SymbolTableRecord
protected _CacheSpaceCS: Matrix4;
protected _CacheSpaceSize: Vector3;
protected _CatchRootParam: Set<TemplateParam>;
protected _CacheIntersectSpaceEntitys: Entity[]; //空间box相交的实体
/**
* .()
* @param [useCache=true] ,使,()
@ -700,8 +694,6 @@ export class TemplateRecord extends SymbolTableRecord
spaceParse.ParseOK = true;
spaceParse.SpaceBox = new Box3Ext(new Vector3(), this._CacheSpaceSize);
if (this._CacheIntersectSpaceEntitys)
spaceParse.IntersectSpaceEntitys = this._CacheIntersectSpaceEntitys;
return spaceParse;
}
@ -841,7 +833,6 @@ export class TemplateRecord extends SymbolTableRecord
this._CacheSpaceSize = undefined;
this._CatchRootParam = undefined;
this._NodeDepthCache = undefined;
this._CacheIntersectSpaceEntitys = undefined;
}
//对象将自身数据写入到文件.
WriteFile(file: CADFiler)

@ -2,7 +2,6 @@ import { Matrix4, Vector3 } from "three";
import { arrayRemoveDuplicateBySort } from "../../Common/ArrayExt";
import { Board } from "../../DatabaseServices/Entity/Board";
import { BoardType } from "../../DatabaseServices/Entity/BoardInterface";
import { Entity } from "../../DatabaseServices/Entity/Entity";
import { Box3Ext, SplitType } from "../Box";
import { XAxis, YAxis, ZAxis, equaln, isParallelTo } from "../GeUtils";
import { VisualSpaceBox } from './../../Editor/VisualSpaceBox';
@ -46,9 +45,6 @@ export class ISpaceParse
VisualSpaceBox: VisualSpaceBox;
Rotation = { x: 0, y: 0, z: 0 };
//周围与空间盒子相交的板件
IntersectSpaceEntitys: Entity[];
/**
* # Parse().
* @param boards

Loading…
Cancel
Save