!1182 功能:二维转三维生产异型背板,修复r2b配置问题

pull/1182/MERGE
ZoeLeeFZ 4 years ago committed by ChenX
parent debfded9ba
commit 98de6de3ec

@ -1,7 +1,6 @@
import { Box3, Matrix4, Vector3 } from "three";
import { app } from "../../ApplicationServices/Application";
import { arrayRemoveIf } from "../../Common/ArrayExt";
import { IsDev } from "../../Common/Deving";
import { safeEval } from "../../Common/eval";
import { matrixSetVector } from "../../Common/Matrix4Utils";
import { Board } from "../../DatabaseServices/Entity/Board";
@ -9,7 +8,7 @@ import { Polyline } from "../../DatabaseServices/Entity/Polyline";
import { TemplateRecord } from "../../DatabaseServices/Template/TemplateRecord";
import { Command } from "../../Editor/CommandMachine";
import { PromptStatus } from "../../Editor/PromptResult";
import { equaln } from "../../Geometry/GeUtils";
import { equaln, isParallelTo, XAxis, YAxis, ZAxis } from "../../Geometry/GeUtils";
import { IntersectOption } from "../../GraphicsSystem/IntersectWith";
import { HotCMD } from "../../Hot/HotCommand";
import { BoardType } from "../../UI/Store/BoardInterface";
@ -24,6 +23,7 @@ import { userConfigStore } from "../../UI/Store/UserConfigStore";
import { BoardModalType } from "../../UI/Components/Board/BoardModal";
import { UpdateBoardInfos } from "../BoardEditor/UpdateBoardInfos";
import { FixDigits } from "../../Common/Utils";
import { GetRectData } from "../../Common/CurveUtils";
const MaxBoardDistance = 200;//左右侧板,顶底板距离边缘的最大距离
@ -146,10 +146,8 @@ export class Polyline2Board implements Command
for (let pl of pls)
{
pl.ApplyMatrix(ucsinv);
let box = pl.BoundingBox;
let size = box.getSize(new Vector3);
pl.__CacheSize__ = size;
pl.__CacheBox__ = box;
this.ParsePolyline(pl);
let size = pl.__CacheSize__;
if (this.IsBackBoard(size))
backPls.push(pl);
else if (this.IsFaceBoard(size))
@ -590,10 +588,23 @@ export class Polyline2Board implements Command
}
let box = pl.__CacheBox__;
let minp = box.min.clone();
let ocs: Matrix4;
if (pl.TempData)
{
ocs = pl.TempData.OCS.clone();
minp.applyMatrix4(pl.TempData.OCS);
}
let br: Board;
let mtx = new Matrix4().makeBasis(XAxis, ZAxis.clone().negate(), YAxis);
if (x > y && y <= this.maxThickness) //层板
{
br = Board.CreateBoard(x, depth, y, BoardType.Layer);
mtx.setPosition(new Vector3(x));
[minp.x, minp.y, minp.z] = [minp.x + x, minp.z, minp.y];
}
else if (x < y && x <= this.maxThickness)//立板
@ -604,6 +615,9 @@ export class Polyline2Board implements Command
else
{
[minp.x, minp.y, minp.z] = [minp.x, minp.z + this.backBoardThick, minp.y];
mtx.setPosition(new Vector3(0, this.backBoardThick));
if (isBack)
{
minp.y += this.boardDepth - this.backBoardThick - this.backBoardMoveDis;//移动到后面
@ -613,10 +627,25 @@ export class Polyline2Board implements Command
x += this.backLeftExtend + this.backRightExtend;
y += this.backTopExtend + this.backDownExtend;
mtx.setPosition(new Vector3(-this.backLeftExtend, -this.backDownExtend, this.boardDepth - this.backBoardMoveDis));
}
br = Board.CreateBoard(y, x, this.backBoardThick, BoardType.Behind);
br.Name = this.backBrName;
if (!pl.TempData && !GetRectData(pl).isRect)
{
pl.Position = pl.Position.sub(box.min);
let con = pl.Clone();
con.Erase(false);
br.ContourCurve = con;
}
}
//被旋转的矩形
let mtxInv = new Matrix4().getInverse(mtx);
if (ocs)
br.ApplyMatrix(mtx).ApplyMatrix(ocs).ApplyMatrix(mtxInv);
let m = new Matrix4().setPosition(minp);
br.ApplyMatrix(m);
br.ApplyMatrix(this.SpaceOCS);
@ -634,8 +663,13 @@ export class Polyline2Board implements Command
//pl1是否包含pl2
IsPolyLineContain(pl1: Polyline, pl2: Polyline)
{
let box1 = pl1.__CacheBox__;
let box2 = pl2.__CacheBox__;
let box1 = pl1.__CacheBox__.clone();
let box2 = pl2.__CacheBox__.clone();
if (pl1.TempData)
box1.applyMatrix4(pl1.TempData.OCS);
if (pl2.TempData)
box2.applyMatrix4(pl2.TempData.OCS);
let box = box1.clone().intersect(box2);
let s = box.getSize(new Vector3);
if (s.x < 1 || s.y < 1) return false;
@ -651,6 +685,34 @@ export class Polyline2Board implements Command
private IsFaceBoard(size: Vector3): boolean
{
return size.x > this.maxThickness && size.y > this.maxThickness;
return size.x > this.maxThickness + 1e-3 && size.y > this.maxThickness + 1e-3;
}
private ParsePolyline(pl: Polyline)
{
let firstDev = pl.GetFistDeriv(0);
let size: Vector3;
let box: Box3;
if (isParallelTo(firstDev, XAxis) || isParallelTo(firstDev, YAxis))
{
box = pl.BoundingBox;
size = box.getSize(new Vector3);
}
else
{
let rd = GetRectData(pl);
if (rd.isRect)
{
pl.TempData = rd;
box = rd.box;
size = rd.size;
}
else
{
box = pl.BoundingBox;
size = box.getSize(new Vector3);
}
}
pl.__CacheSize__ = size;
pl.__CacheBox__ = box;
}
}

@ -122,7 +122,7 @@ export class R2BProcessComponent extends React.Component<IR2BProcessComponentPro
<Notes remarks={store.m_Option.remarks} />
</div>
<SelectBrConfigName store={store} />
<div>
{/* <div>
<div style={{ display: "flex", flexDirection: "row", justifyContent: "space-between", paddingTop: 10 }}>
<Checkbox
checked={store.m_Option.backBrUseTemplate}
@ -144,7 +144,7 @@ export class R2BProcessComponent extends React.Component<IR2BProcessComponentPro
onClick={() => this.props.getOption(GetOptionState.GetTemplate)}
></button>
</div>
</div>
</div> */}
</Card>
);

@ -8,7 +8,7 @@ import { Polyline } from '../DatabaseServices/Entity/Polyline';
import { IsPointInBowArc } from '../DatabaseServices/PointInPolyline';
import { Count } from '../Geometry/Count';
import { CurveMap, Vertice } from '../Geometry/CurveMap';
import { AsVector2, AsVector3, equaln, equalv2, equalv3, isParallelTo, ZeroVec, XAxis, YAxis, isIntersect } from '../Geometry/GeUtils';
import { AsVector2, AsVector3, equaln, equalv2, equalv3, isParallelTo, XAxis, ZeroVec, isPerpendicularityTo, YAxis, isIntersect } from '../Geometry/GeUtils';
import { Orbit } from '../Geometry/Orbit';
import { PlaneExt } from '../Geometry/Plane';
import { IntersectOption, IntersectResult } from '../GraphicsSystem/IntersectWith';
@ -685,6 +685,119 @@ export function Pts2Polyline(pts: (Vector3 | Vector2)[], isClose: boolean)
return pl;
}
/**获取矩形信息 */
export function GetRectData(cu: Curve): { isRect: boolean, size?: Vector3, box?: Box3, OCS?: Matrix4; }
{
if (cu instanceof Polyline)
{
if (!cu.IsClose) return { isRect: false };
let pts = cu.GetStretchPoints();
if (cu.Area2 < 0)
pts.reverse();
if (equalv3(pts[0], arrayLast(pts)))
pts.pop();
if (pts.length < 4) return { isRect: false };
let xVec: Vector3;
let p1 = pts[0];
let originIndex = 0;
for (let i = 1; i < pts.length; i++)
{
if (pts[i].y < p1.y)
{
p1 = pts[i];
originIndex = i;
}
else if (equaln(pts[i].y, p1.y))
{
if (pts[i].x < p1.x)
{
p1 = pts[i];
originIndex = i;
}
}
}
let tempPts = pts.splice(0, originIndex);
pts.push(...tempPts);
p1 = pts[0];
for (let i = 1; i < pts.length; i++)
{
let v = pts[i].clone().sub(p1);
if (equalv3(v, ZeroVec))
continue;
if (!xVec)
xVec = v;
else
{
if (isParallelTo(v, xVec))
xVec.copy(v);
else
break;
}
}
let yVec: Vector3;
for (let i = pts.length - 1; i > 0; i--)
{
let v = pts[i].clone().sub(p1);
if (equalv3(v, ZeroVec))
continue;
if (!yVec)
yVec = v;
else
{
if (isParallelTo(v, yVec))
yVec.copy(v);
else
break;
}
}
if (!xVec || !yVec) return { isRect: false };
//2向量必须垂直
if (!isPerpendicularityTo(xVec.clone().normalize(), yVec.clone().normalize()))
return { isRect: false };
if (yVec.length() > xVec.length())
[xVec, yVec] = [yVec.negate(), xVec];
if (xVec.angleTo(XAxis) > Math.PI / 4)
[xVec, yVec] = [yVec.negate(), xVec];
let rectOCS = new Matrix4().makeBasis(xVec.normalize(), yVec.normalize(), xVec.clone().cross(yVec));
let rectOCSInv = new Matrix4().getInverse(rectOCS);
for (let p of pts)
p.applyMatrix4(rectOCSInv);
let box = new Box3().setFromPoints(pts);
let size = box.getSize(new Vector3);
if (equaln(size.x * size.y, cu.Area, 0.1))
{
return {
isRect: true,
size,
box,
OCS: rectOCS,
};
}
}
return { isRect: false };
}
const PolylineSpliteRectFuzz = 1e-3;
/**封闭多段线 分割成矩形 */
export function PolylineSpliteRect(outline: Polyline): Polyline[]

@ -188,9 +188,9 @@ export function isParallelTo(v1: Vector3, v2: Vector3, fuzz = 1e-8): boolean
/**
*
*/
export function isPerpendicularityTo(v1: Vector3, v2: Vector3)
export function isPerpendicularityTo(v1: Vector3, v2: Vector3, fuzz = 1e-8)
{
return equaln(v1.dot(v2), 0, 1e-8);
return equaln(v1.dot(v2), 0, fuzz);
}
export function ptToString(v: Vector3, fractionDigits: number = 3): string

@ -70,6 +70,17 @@ export class UserConfigStore extends Singleton
else
await this.SaveConfig(BoardModalType.Dr, drillStore, { isInit: true });
}
async InitUpdateBoardInfoConfigs()
{
let config = await this.GetConfig(BoardModalType.UpdateBoardInfo);
if (!config)
{
await this.SaveConfig(BoardModalType.UpdateBoardInfo, updateBoardInfoStore, { isInit: true, toaster: false });
updateBoardInfoStore.configsNames.length = 0;
updateBoardInfoStore.configsNames.push("默认");
}
}
async InitWinerackConfig()
{
let config = await this.GetConfig(BoardModalType.JG);
@ -114,6 +125,7 @@ export class UserConfigStore extends Singleton
await this.CacheAllConfigs();
await this.GetUserConfigNames();
await this.InitDrillConfig();
await this.InitUpdateBoardInfoConfigs();
(DoorStore.GetInstance() as DoorStore).selectTemplateInfo = null;
(DrawerStore.GetInstance() as DrawerStore).selectTemplateInfo = null;

Loading…
Cancel
Save