!2019 优化:在修改板轮廓时,保持封边和排钻属性(尽量)

pull/1911/MERGE
ChenX 2 years ago
parent 2fa51dba46
commit 3f391f9002

@ -21,7 +21,7 @@ import { TemplateRecord } from "../../../DatabaseServices/Template/TemplateRecor
import { Command, CommandWrap } from "../../../Editor/CommandMachine";
import { userConfig } from "../../../Editor/UserConfig";
import { equaln, ZAxis } from "../../../Geometry/GeUtils";
import { HandleRectBoardSealingData, ParagraphSealinglist } from "../../../GraphicsSystem/CalcEdgeSealing";
import { ParagraphSealinglist, SetBoardTopDownLeftRightSealData } from "../../../GraphicsSystem/CalcEdgeSealing";
import { BoardModalType } from "../../../UI/Components/Board/BoardModalType";
import { AppConfirm } from "../../../UI/Components/Common/Confirm";
import { AppToaster } from "../../../UI/Components/Toaster";
@ -337,7 +337,7 @@ async function ParseModel(model: KJL_ParamModel,
sealeds.push(last);
let edges = ParagraphSealinglist(sealeds, cus);
br.BoardProcessOption.highSealed = edges;
HandleRectBoardSealingData(br, edges);
SetBoardTopDownLeftRightSealData(br, edges);
}
for (let i = 1; i < pls.length; i++)

@ -7,7 +7,7 @@ import { Box3Ext } from "../../Geometry/Box";
import { BoardFaceType, BoardGetFace, GetSideFaceMtx } from "../../Geometry/DrillParse/BoardGetFace";
import { Face } from "../../Geometry/DrillParse/Face";
import { equaln, equalv3 } from "../../Geometry/GeUtils";
import { GetBoardHighSeal, GetBoardSealingCurves, HandleRectBoardSealingData } from "../../GraphicsSystem/CalcEdgeSealing";
import { GetBoardHighSeal, GetBoardSealingCurves, SetBoardTopDownLeftRightSealData } from "../../GraphicsSystem/CalcEdgeSealing";
import { IHighSealedItem, ISmoothEdgeOption } from "../../UI/Store/BoardInterface";
class SetSmoothEdgeFaces extends BoardGetFace
@ -179,7 +179,7 @@ class SetSmoothEdgeFaces extends BoardGetFace
this.highSealingData[i].size = option.edge;
}
HandleRectBoardSealingData(this.Board, this.highSealingData, this.sealCus);
SetBoardTopDownLeftRightSealData(this.Board, this.highSealingData, this.sealCus);
this.Board.BoardProcessOption.highSealed = this.highSealingData;
}
}

@ -13,10 +13,10 @@ import { boardUVGenerator, boardUVGenerator2 } from '../../Geometry/BoardUVGener
import { BufferGeometryUtils } from '../../Geometry/BufferGeometryUtils';
import { equaln, equalv3, IdentityMtx4, XAxis, XAxisN, YAxis, YAxisN, ZAxis, ZeroVec } from '../../Geometry/GeUtils';
import { PointShapeUtils } from '../../Geometry/PointShapeUtils';
import { GetBoardHighSeal, GetBoardSealingCurves, HandleRectBoardSealingData } from '../../GraphicsSystem/CalcEdgeSealing';
import { GetBoardHighSeal, GetBoardSealingCurves, SetBoardTopDownLeftRightSealData } from '../../GraphicsSystem/CalcEdgeSealing';
import { RenderType } from '../../GraphicsSystem/RenderType';
import { VData2Curve, VKnifToolPath } from '../../GraphicsSystem/ToolPath/VKnifToolPath';
import { BoardOpenDir, BoardProcessOption, BoardType, ComposingType, DrillType, FaceDirection, IHighSealedItem, LinesType } from '../../UI/Store/BoardInterface';
import { BoardOpenDir, BoardProcessOption, BoardType, ComposingType, DrillType, FaceDirection, LinesType } from '../../UI/Store/BoardInterface';
import { CylinderHole } from '../3DSolid/CylinderHole';
import { ExtrudeHole } from '../3DSolid/ExtrudeHole';
import { AutoRecord } from '../AutoRecord';
@ -34,10 +34,10 @@ import { ExtrudeContourCurve, ExtrudeSolid } from './Extrude';
import { Polyline } from './Polyline';
//排钻配置名是合法的
//排钻配置名是合法的 可用的
function IsValidDriName(name: string): boolean
{
return name === DrillType.None || name === DrillType.More || HostApplicationServices.DrillConfigs.has(name);
return name === DrillType.None || HostApplicationServices.DrillConfigs.has(name);
}
export interface IModeling
@ -753,66 +753,100 @@ export class Board extends ExtrudeSolid
/**
* ,.
*/
get ContourCurve()
override get ContourCurve()
{
return super.ContourCurve;
}
set ContourCurve(cu: ExtrudeContourCurve)
//设置新的板件轮廓,这里重载为了保持正确的排钻封边映射
override set ContourCurve(newContour: ExtrudeContourCurve)
{
//标识是否被初始化
/**
*
* (2x2)
* ->
* ->
* ->
* ->
*/
//上下左右排钻属性(在矩形时生效)
TempRectHoleOption.up = undefined;
ParseBoardRectHoleType(this, TempRectHoleOption);//分析旧的上下左右排钻
let oldHightSealCurves = GetBoardSealingCurves(this);//旧的封边轮廓
let hightSealDatas = GetBoardHighSeal(this, oldHightSealCurves);//旧的封边数据
let oldContour = this.ContourCurve;//旧的轮廓
let defaultDrillType = this._BoardProcessOption.drillType;
if (!IsValidDriName(defaultDrillType) && this._BoardProcessOption.highDrill)
for (let name of this._BoardProcessOption.highDrill)
if (IsValidDriName(name))
{
defaultDrillType = name;
break;
}
if (!IsValidDriName(defaultDrillType))
defaultDrillType = HostApplicationServices.DrillConfigs.size ? HostApplicationServices.DrillConfigs.entries().next().value[0] : DrillType.None;
let needRename = !IsValidDriName(this.BoardProcessOption.drillType);
if (!this.contourCurve || cu.EndParam !== this.contourCurve.EndParam || needRename)
super.ContourCurve = newContour;//设置新的轮廓
//保持排钻边属性
if (this.isRect && TempRectHoleOption.up)//矩形->矩形
SetBrHighHoleTypeFromRectHoleType(this, TempRectHoleOption);//直接应用旧的矩形数据
else//异形->矩形 矩形->异形 异形->异形
{
let defaultType = this._BoardProcessOption.drillType;
if (needRename)
let indexMap: number[] = [];
for (let i = 0; i < newContour.EndParam; i++)
{
defaultType = HostApplicationServices.DrillConfigs.size ? HostApplicationServices.DrillConfigs.entries().next().value[0] : "不排";
this._BoardProcessOption.drillType = defaultType;
let p = newContour.GetPointAtParam(i + 0.5);
let cp = oldContour.GetClosestPointTo(p, false);
let cparam = oldContour.GetParamAtPoint2(cp);
indexMap.push(Math.floor(cparam));
}
this._BoardProcessOption.highDrill = Array(cu.EndParam).fill(defaultType);
let highDrill: string[] = [];
for (let index of indexMap)
highDrill.push(this._BoardProcessOption.highDrill[index] ?? defaultDrillType);
this._BoardProcessOption.highDrill = highDrill;
}
else
{
if (this.isRect)
ParseBoardRectHoleType(this, TempRectHoleOption);
else//之前不是异形,现在也不是异形时,对排钻边和封边进行映射,避免错误
{
let size = cu.BoundingBox.getSize(new Vector3);
let isRect = equaln(size.x * size.y, cu.Area, 0.1);
if (!isRect)
{
let indexMap: number[] = [];
this._BoardProcessOption.highSealed.length = 0;
//保持封边属性
if (this.isRect)
{
SetBoardTopDownLeftRightSealData(this, hightSealDatas, oldHightSealCurves);
}
else//变成了异形
{
let newhightSealCurves = GetBoardSealingCurves(this);
for (let i = 0; i < cu.EndParam; i++)
{
let p = cu.GetPointAtParam(i + 0.5);
for (let i = 0; i < newhightSealCurves.length; i++)
{
let newC = newhightSealCurves[i];
let p = newC.GetPointAtParam(newC.EndParam * 0.5);
let cp = this.contourCurve.GetClosestPointTo(p, false);
let cparam = this.contourCurve.GetParamAtPoint2(cp);
indexMap.push(Math.floor(cparam));
}
let closesIndex = 0;
let closesDistance = Infinity;
let highDrill = [];
let highSealed = [];
for (let index of indexMap)
for (let j = 0; j < oldHightSealCurves.length; j++)
{
let oldC = oldHightSealCurves[j];
let d = oldC.GetClosestPointTo(p, false).distanceTo(p);
if (d < closesDistance)
{
highDrill.push(this._BoardProcessOption.highDrill[index] ?? this._BoardProcessOption.drillType);
highSealed.push(this._BoardProcessOption.highSealed[index] ?? 0);
closesIndex = j;
closesDistance = d;
}
this._BoardProcessOption.highDrill = highDrill;
this._BoardProcessOption.highSealed = highSealed;
}
this._BoardProcessOption.highSealed.push(hightSealDatas[closesIndex]);
}
}
super.ContourCurve = cu;
if (this.isRect && TempRectHoleOption.up)
SetBrHighHoleTypeFromRectHoleType(this, TempRectHoleOption);
}
Explode()
@ -832,9 +866,7 @@ export class Board extends ExtrudeSolid
this.WriteAllObjectRecord();
let highSeals: IHighSealedItem[];
// if (this.isRect)
highSeals = GetBoardHighSeal(this, GetBoardSealingCurves(this));
let highSeals = GetBoardHighSeal(this, GetBoardSealingCurves(this));
let a = Math.atan2(x.y, x.x);
@ -858,8 +890,7 @@ export class Board extends ExtrudeSolid
if (this.contourCurve instanceof Polyline)
this.contourCurve.UpdateOCSTo(IdentityMtx4);
// if (this.isRect)
HandleRectBoardSealingData(this, highSeals);//这里不可以用缓存的曲线 否则分析错误,必须重新开始分析曲线
SetBoardTopDownLeftRightSealData(this, highSeals);//这里不可以用缓存的曲线 否则分析错误,必须重新开始分析曲线
this.Update();
return this;
@ -896,8 +927,8 @@ export class Board extends ExtrudeSolid
{
if (!this.Id)
{
// super.ApplyMirrorMatrix(m); //这个变更导致镜像错误 因为实体没有正常的被更新. 所以需要注意的是,如果需要镜像变更,需要给实体一个id!!!
return this;
// super.ApplyMirrorMatrix(m); //这个变更导致镜像错误 因为实体没有正常的被更新(更新下面的属性?). 所以需要注意的是,如果需要镜像变更,需要给实体一个id!!!
return this;//为了优化性能,在jig模式下不去计算封边排钻等属性,不重绘板
}
this.ContourCurve;//因为下面翻转孔面的代码,所以必须初始化这个
@ -941,7 +972,7 @@ export class Board extends ExtrudeSolid
this.BoardProcessOption.highSealed = highSeals;
if (!hasSplitSize)//&& this.isRect
HandleRectBoardSealingData(this, highSeals);
SetBoardTopDownLeftRightSealData(this, highSeals);
//重新构建SpaceOCS
this._SpaceOCS.multiplyMatrices(this._Matrix, new Matrix4().getInverse(this.RotateMat));

@ -222,7 +222,7 @@ export class ExtrudeSolid extends Entity
for (let g of this.grooves)
{
g._SpaceOCS.copy(this._SpaceOCS);//因为在镜像的时候 没有设置这个会导致错误 所以拷贝一下
g._SpaceOCS.copy(this._SpaceOCS);//因为在镜像(Extrude.ApplyMirrorMatrix)的时候 没有设置这个会导致错误(参考该函数的代码,似乎是为了实现柜子镜像) 所以拷贝一下
g.objectId = new ObjectId;
g.ApplyMatrix(m);
g.objectId = undefined;
@ -253,53 +253,47 @@ export class ExtrudeSolid extends Entity
this.CheckContourCurve();
return this;
}
//实现了这个函数后 实现了柜子的镜像
protected ApplyMirrorMatrix(m: Matrix4)
{
this.WriteAllObjectRecord();
const curve = this.ContourCurve;
if (curve instanceof Polyline && !equalv3(curve.Position, ZeroVec))
if (curve instanceof Polyline && !equalv3(curve.Position, ZeroVec))//移除多段线的OCS(目前只判断了基点)
{
let pts = curve.LineData;
if (equalv2(pts[0].pt, arrayLast(pts).pt))
pts.pop();
let ocs = curve.OCSNoClone;
for (let p of pts)
{
Vector2ApplyMatrix4(ocs, p.pt);
}
curve.OCS = IdentityMtx4;
}
let nor = this.Normal.applyMatrix4(this.SpaceOCSInv.setPosition(ZeroVec));
if (equaln(Math.abs(nor.z), 1))
let nor = this.Normal.applyMatrix4(this.SpaceOCSInv.setPosition(ZeroVec));//法向量在柜子坐标系中的表示
if (equaln(Math.abs(nor.z), 1))//在柜子中是一个层板
{
reviseMirrorMatrix(this._Matrix, 1);
if (curve instanceof Circle)
{
curve.ApplyMatrix(new Matrix4().makeRotationX(Math.PI));
}
else
{
reviseMirrorMatrix(curve.OCSNoClone, 1);
}
this.SetContourCurve(curve);
}
else if (equaln(Math.abs(nor.x), 1))
else if (equaln(Math.abs(nor.x), 1))//立板
{
reviseMirrorMatrix(this._Matrix, 2);
this._Matrix.setPosition(this.Position.add(this.Normal.multiplyScalar(-this.Thickness)));
}
else
else//背板?
{
reviseMirrorMatrix(this._Matrix, 0);
if (curve instanceof Circle)
{
curve.ApplyMatrix(new Matrix4().makeRotationY(Math.PI));
}
else
{
reviseMirrorMatrix(curve.OCSNoClone, 0);
}
this.SetContourCurve(curve);
}

@ -1,5 +1,5 @@
import { arrayClone } from "../../../Common/ArrayExt";
import { GetBoardHighSeal, GetBoardSealingCurves, HandleRectBoardSealingData } from "../../../GraphicsSystem/CalcEdgeSealing";
import { GetBoardHighSeal, GetBoardSealingCurves, SetBoardTopDownLeftRightSealData } from "../../../GraphicsSystem/CalcEdgeSealing";
import { Factory } from "../../CADFactory";
import { CADFiler } from "../../CADFiler";
import { Board } from "../../Entity/Board";
@ -24,8 +24,8 @@ export class TemplateSetSealAction extends TemplateAction
if (entity?.Object && !entity.IsErase)
{
let br = entity.Object;
let highSealData = GetBoardSealingCurves(br, true);
let highseals = GetBoardHighSeal(br, highSealData);
let highSealCurves = GetBoardSealingCurves(br, true);
let highseals = GetBoardHighSeal(br, highSealCurves);
for (let i of indexs)
{
@ -33,7 +33,7 @@ export class TemplateSetSealAction extends TemplateAction
highseals[i].size = newV;
}
HandleRectBoardSealingData(br, highseals, highSealData);
SetBoardTopDownLeftRightSealData(br, highseals, highSealCurves);
br.BoardProcessOption.highSealed = highseals;
}
}

@ -592,12 +592,11 @@ export function ParagraphSealinglist(hightSeal: IHighSealedItem[], cus: Curve[])
return newHighSeal;
}
/**处理常规板件封边数据和上下左右封边值 */
export function HandleRectBoardSealingData(br: Board, edges: IHighSealedItem[], cus?: Curve[])
/** 设置板的上下左右封边 */
export function SetBoardTopDownLeftRightSealData(br: Board, sealDatas: IHighSealedItem[], sealCurves?: Curve[])
{
let dir = Math.sign(br.ContourCurve.Area2);
if (!cus)
cus = GetBoardSealingCurves(br);
sealCurves = sealCurves ?? GetBoardSealingCurves(br);
//现在我们不管是否有拆单尺寸,我们总是关系封边值
// let param = { L: br.Height, W: br.Width, H: br.Thickness };
@ -606,33 +605,33 @@ export function HandleRectBoardSealingData(br: Board, edges: IHighSealedItem[],
// let spliteThickness = safeEval(br.BoardProcessOption.spliteThickness, param, "H");
// if ((spliteHeight && spliteWidth && spliteThickness) || !br.IsSpecialShape && cus.length === 4)
if (!br.IsSpecialShape && cus.length === 4)
if (br.IsRect && sealCurves.length === 4)
{
for (let i = 0; i < 4; i++)
{
let derv = cus[i].GetFistDeriv(0).normalize();
let derv = sealCurves[i].GetFistDeriv(0).normalize();
if (isParallelTo(derv, XAxis, 1e-4))
{
if (derv.x * dir > 0)
br.BoardProcessOption[EBoardKeyList.DownSealed] = edges[i].size.toString();
br.BoardProcessOption[EBoardKeyList.DownSealed] = sealDatas[i].size.toString();
else
br.BoardProcessOption[EBoardKeyList.UpSealed] = edges[i].size.toString();
br.BoardProcessOption[EBoardKeyList.UpSealed] = sealDatas[i].size.toString();
}
else
{
if (derv.y * dir > 0)
br.BoardProcessOption[EBoardKeyList.RightSealed] = edges[i].size.toString();
br.BoardProcessOption[EBoardKeyList.RightSealed] = sealDatas[i].size.toString();
else
br.BoardProcessOption[EBoardKeyList.LeftSealed] = edges[i].size.toString();
br.BoardProcessOption[EBoardKeyList.LeftSealed] = sealDatas[i].size.toString();
}
}
}
else
{
let [left, right, top, bottom] = ParseEdgeSealDir(cus);
br.BoardProcessOption[EBoardKeyList.LeftSealed] = edges[left].size.toString();
br.BoardProcessOption[EBoardKeyList.RightSealed] = edges[right].size.toString();
br.BoardProcessOption[EBoardKeyList.UpSealed] = edges[top].size.toString();
br.BoardProcessOption[EBoardKeyList.DownSealed] = edges[bottom].size.toString();
let [left, right, top, bottom] = ParseEdgeSealDir(sealCurves);
br.BoardProcessOption[EBoardKeyList.LeftSealed] = sealDatas[left].size.toString();
br.BoardProcessOption[EBoardKeyList.RightSealed] = sealDatas[right].size.toString();
br.BoardProcessOption[EBoardKeyList.UpSealed] = sealDatas[top].size.toString();
br.BoardProcessOption[EBoardKeyList.DownSealed] = sealDatas[bottom].size.toString();
}
}

@ -7,7 +7,7 @@ import { Log } from "../../../Common/Log";
import { Board } from "../../../DatabaseServices/Entity/Board";
import { Entity } from "../../../DatabaseServices/Entity/Entity";
import { CommandWrap } from "../../../Editor/CommandMachine";
import { GetBoardHighSeal, GetBoardSealingCurves, GetSealedBoardContour, HandleRectBoardSealingData } from "../../../GraphicsSystem/CalcEdgeSealing";
import { GetBoardHighSeal, GetBoardSealingCurves, GetSealedBoardContour, SetBoardTopDownLeftRightSealData } from "../../../GraphicsSystem/CalcEdgeSealing";
import { IConfigOption } from "../../Components/Board/UserConfig";
import { AppToaster, ShowLinesToaster } from "../../Components/Toaster";
import { IHighSealedItem } from "../BoardInterface";
@ -159,7 +159,7 @@ export class SealingStore extends BoardEdgesEditor implements IConfigStore
{
let data = this._dataMap.get(b);
let ocsInv = b.OCSInv;
HandleRectBoardSealingData(b, data, cus.map(c => c.ApplyMatrix(ocsInv)));
SetBoardTopDownLeftRightSealData(b, data, cus.map(c => c.ApplyMatrix(ocsInv)));
b.BoardProcessOption.highSealed = data;
}
this._dataMap.clear();

Loading…
Cancel
Save