开发:清理代码格式

pull/1240/MERGE
ChenX 4 years ago
parent e342a4058f
commit b111b71cac

@ -90,14 +90,11 @@ export class Entsel implements Command
dyn.Visible = false;
}
});
if (en.Status == PromptStatus.OK)
if (en.Status === PromptStatus.OK)
{
en.Entity.ColorIndex = 1;
app.Viewer.UpdateRender();
window["en"] = en.Entity;
}
dyn.Destroy();
window["en"] = en.Entity;
}
}

@ -181,7 +181,6 @@ export async function GetProductsEntitys()
{
if (en instanceof Board)
{
boardList.push(...Production.GetSpliteBoards(en));
en.RelativeHardware.forEach(id => !id.IsErase && (id.Object instanceof HardwareCompositeEntity || id.Object instanceof HardwareTopline) && metalsIds.add(id));
}

@ -63,9 +63,7 @@ export class Print implements Command
for (let e of ens)
{
if (e instanceof Board)
{
printEnts.push(...e.SplitBoards);
}
else
printEnts.push(e);
}

@ -186,10 +186,12 @@ export class Board extends ExtrudeSolid
{
return this._DrillList;
}
get LayerNails()
{
return this._LayerNails;
}
AppendNails(ids: ObjectId[])
{
this.WriteAllObjectRecord();

@ -1588,6 +1588,7 @@ export class ExtrudeSolid extends Entity
this.__CacheKnifVersion__[e.Index] = (<Entity>e?.Object)?.__UpdateVersion__;
}
}
ClearRelevance(en?: ExtrudeSolid)
{
if (en)

@ -219,9 +219,7 @@ export class ViewportEntity extends Entity
let ens: Entity[];
if (en instanceof Board)
{
ens = en.SplitBoards;
}
else
ens = [en];

@ -0,0 +1,277 @@
import { Vector3 } from "three";
import { EBoardKeyList } from "../Common/BoardKeyList";
import { CylinderHole, GangDrillType } from "../DatabaseServices/3DSolid/CylinderHole";
import { ExtrudeHole } from "../DatabaseServices/3DSolid/ExtrudeHole";
import { Board } from "../DatabaseServices/Entity/Board";
import { Circle } from "../DatabaseServices/Entity/Circle";
import { ExtureContourCurve } from "../DatabaseServices/Entity/Extrude";
import { Line } from "../DatabaseServices/Entity/Line";
import { angleTo, equaln, equalv3, isParallelTo, XAxis } from "../Geometry/GeUtils";
import { FaceDirection } from "../UI/Store/BoardInterface";
import { DrillingFace, IBoardHoleInfo, IDrillingOption } from "./Product";
/**
* ,
*/
export class ParseBoardHoleData
{
frontBackHoles: IDrillingOption[] = [];
sideHoles: IDrillingOption[] = [];
constructor(
private _Board: Board,
private _offsetTanslation: Vector3,
private _SealedContour: ExtureContourCurve,//已经计算封边的轮廓
private _Normal = _Board.Normal,
private _OCSInv = _Board.OCSInv,
private _OCSInvRo = _OCSInv.clone().setPosition(0, 0, 0),
private _ContourBox = _SealedContour.BoundingBox,
)
{
for (let [, driss] of _Board.DrillList)
{
for (let dris of driss)
{
for (let dId of dris)
{
if (!dId || dId.IsErase)
continue;
let d = dId.Object as CylinderHole;
if (d instanceof ExtrudeHole)
this.ParseExtrudeHoles(d, _offsetTanslation);
else
this.ParseCylHoles(d, _offsetTanslation);
}
}
}
}
GetData(): IBoardHoleInfo
{
return { frontBackHoles: this.frontBackHoles, sideHoles: this.sideHoles };
}
/**分析常规排钻 */
ParseCylHoles(d: CylinderHole, offsetTanslation: Vector3): void
{
let processData = this._Board.BoardProcessOption;
let brNormal = this._Normal;
let roMat = this._OCSInvRo;
let position = d.Position.applyMatrix4(this._OCSInv);
let holes = this.frontBackHoles;
let face: number;
let isPush = false;
let endPt: Vector3;
let depth = d.Height;
let diffMat = d.OCS.premultiply(this._OCSInv);
let x = new Vector3().setFromMatrixColumn(diffMat, 0);
let angle = angleTo(XAxis, x);
if (d.Type === GangDrillType.Pxl || d.Type === GangDrillType.WoodPXL)
{
if (isParallelTo(d.Normal, brNormal))
{
if (position.x <= 0 || position.x >= this._Board.Width || position.y <= 0 || position.y >= this._Board.Height || !this.PointInBoard(position.clone().setZ(0))) return;
position.sub(offsetTanslation);
face = processData[EBoardKeyList.BigHole];
isPush = true;
}
}
else if (d.Type === GangDrillType.Ljg || d.Type === GangDrillType.Wood)
{
if (!isParallelTo(d.Normal, brNormal))
{
let z = position.z;
let line = new Line(position.clone().setZ(0), position.clone().setZ(0).add(d.Normal.multiplyScalar(d.Height).applyMatrix4(roMat)));
let pt = this._SealedContour.IntersectWith(line, 0)[0];
if (!pt)
{
return;
}
position = pt.clone().setZ(z);
for (let p of [line.StartPoint, line.EndPoint])
{
if (this._SealedContour.PtInCurve(p))
{
endPt = p.setZ(z);
break;
}
}
if (!endPt)
{
console.warn("排钻位置有问题");
return;
}
holes = this.sideHoles;
face = Math.floor(this._SealedContour.GetParamAtPoint(pt));
isPush = true;
depth = position.distanceTo(endPt);
angle = undefined;
this.InvertPosition(position, this._Board.Thickness);
this.InvertPosition(endPt, this._Board.Thickness);
}
else if (d.Type === GangDrillType.Wood)
{
if (!this._SealedContour.PtInCurve(position.clone().setZ(0))) return;
face = position.z > 0 ? FaceDirection.Front : FaceDirection.Back;
holes = this.frontBackHoles;
if (position.z > 0)
{
let z1 = position.z - d.Height;
if (z1 > 0 && z1 < this._Board.Thickness)
{
depth = this._Board.Thickness - z1;
isPush = true;
}
}
else
{
let z1 = position.z + d.Height;
if (z1 > 0 && z1 < this._Board.Thickness)
{
depth = z1;
isPush = true;
}
}
position.sub(offsetTanslation);
}
}
else
{
if (isParallelTo(d.Normal, this._Normal))
{
if (position.x <= 0 || position.x >= this._Board.Width || position.y <= 0 || position.y >= this._Board.Height) return;
position.sub(offsetTanslation);
holes = this.frontBackHoles;
face = !equalv3(d.Normal, brNormal, 1e-3) ? 0 : 1;
isPush = true;
}
}
isPush && holes.push({
type: d.Type,
position,
radius: d.Radius,
depth,
face,
endPt,
angle
});
}
/**分析自定义圆柱排钻 */
ParseExtrudeHoles(d: ExtrudeHole, offsetTanslation: Vector3): void
{
if (!d.isHole)
return;
let outline = this._SealedContour;
let brNormal = this._Normal;
let cir = d.ContourCurve;
if (cir instanceof Circle)
{
let diffMtx = d.OCS.premultiply(this._OCSInv);
let nor = d.Normal;
let sp = cir.Center.applyMatrix4(diffMtx);
let ep = cir.Center.add(new Vector3(0, 0, d.Height)).applyMatrix4(diffMtx);
let x = new Vector3().setFromMatrixColumn(diffMtx, 0);
if (isParallelTo(nor, brNormal))
{
let z0 = Math.min(sp.z, ep.z);
let z1 = Math.max(sp.z, ep.z);
let p = sp.clone().setZ(0).sub(offsetTanslation);
if (Math.max(z0, 0) < Math.min(z1, this._Board.Thickness) - 1e-6 && outline.PtInCurve(p))
{
this.frontBackHoles.push({
type: GangDrillType.Pxl,
position: z0 < 1e-6 ? p : p.setZ(this._Board.Thickness),
radius: cir.Radius,
depth: z0 < 1e-6 ? z1 : this._Board.Thickness - z0,
face: z0 < 1e-6 ? DrillingFace.Back : DrillingFace.Front,
angle: angleTo(XAxis, x),
});
}
}
else
{
let oldZ = sp.z;
let [minX, maxX] = sp.x < ep.x ? [sp.x, ep.x] : [ep.x, sp.x];
let [minY, maxY] = sp.y < ep.y ? [sp.y, ep.y] : [ep.y, sp.y];
if (sp.z > cir.Radius
&& sp.z < this._Board.Thickness - cir.Radius
&& Math.max(minX, 0) < Math.min(this._Board.Width, maxX) + 1e-6
&& Math.max(minY, 0) < Math.min(this._Board.Height, maxY) + 1e-6
)
{
sp.setZ(0);
ep.setZ(0);
let line = new Line(sp, ep);
let pt = outline.IntersectWith(line, 0)[0];
if (!pt)
{
console.error("排钻嵌在板件内部");
return;
}
let position = pt.clone().setZ(oldZ);
let endPt: Vector3;
let face = Math.floor(outline.GetParamAtPoint(pt));
for (let p of [line.StartPoint, line.EndPoint])
{
if (outline.PtInCurve(p))
{
endPt = p.setZ(oldZ);
break;
}
}
if (!endPt)
return;
let depth = position.distanceTo(endPt);
if (equaln(depth, 0))
return;
this.InvertPosition(position, this._Board.Thickness);
this.InvertPosition(endPt, this._Board.Thickness);
this.sideHoles.push({
type: GangDrillType.Ljg,
endPt,
position,
radius: cir.Radius,
depth,
face,
});
}
}
}
}
/**拆单那边需要把侧孔 z 坐标转换为从上到下 */
private InvertPosition(pos: Vector3, thickness: number)
{
pos.z = thickness - pos.z;
}
//由于我们现在的数据结构有了个多余的圆柱,所以我们为了优化这个的计算性能,进行了缓存
PointCheckCache: Map<string, boolean> = new Map();
private PointInBoard(p: Vector3): boolean
{
if (!this._ContourBox.containsPoint(p)) return false;
let key = `${Math.floor(p.x)},${Math.floor(p.y)}`;
if (this.PointCheckCache.has(key)) return this.PointCheckCache.get(key);
let inBr = this._SealedContour.PtInCurve(p);
this.PointCheckCache.set(key, inBr);
return inBr;
}
}

@ -1,34 +1,34 @@
import { Matrix4, Vector2, Vector3, Box3 } from "three";
import { Intent } from "@blueprintjs/core";
import { Box3, Matrix4, Vector2, Vector3 } from "three";
import { lookOverBoardInfosTool } from "../Add-on/LookOverBoardInfos/LookOverBoardInfosTool";
import { arrayLast } from "../Common/ArrayExt";
import { EBoardKeyList } from "../Common/BoardKeyList";
import { MergeCurvelist } from "../Common/CurveUtils";
import { ParseExpr, safeEval } from "../Common/eval";
import { Vector2ApplyMatrix4 } from "../Common/Matrix4Utils";
import { FixedNotZero, LINK_FUZZ } from "../Common/Utils";
import { CylinderHole, GangDrillType } from "../DatabaseServices/3DSolid/CylinderHole";
import { ExtrudeHole } from "../DatabaseServices/3DSolid/ExtrudeHole";
import { Hole } from "../DatabaseServices/3DSolid/Hole";
import { Arc } from "../DatabaseServices/Entity/Arc";
import { Board, IModeling } from "../DatabaseServices/Entity/Board";
import { Circle } from "../DatabaseServices/Entity/Circle";
import { Curve } from "../DatabaseServices/Entity/Curve";
import { ExtureContourCurve } from "../DatabaseServices/Entity/Extrude";
import { Line } from "../DatabaseServices/Entity/Line";
import { Polyline } from "../DatabaseServices/Entity/Polyline";
import { HardwareCompositeEntity } from "../DatabaseServices/Hardware/HardwareCompositeEntity";
import { HardwareTopline } from "../DatabaseServices/Hardware/HardwareTopline";
import { userConfig } from "../Editor/UserConfig";
import { Vec2 } from "../Geometry/CheckIntersect";
import { AsVector2, equaln, equalv3, isParallelTo, MoveMatrix, angleTo, XAxis } from "../Geometry/GeUtils";
import { angleTo, AsVector2, equaln, equalv3, isParallelTo, MoveMatrix, XAxis } from "../Geometry/GeUtils";
import { GetBoardHighSeal, GetBoardSealingCurves, GetSealedBoardContour as GetSealedBoardContour } from "../GraphicsSystem/CalcEdgeSealing";
import { FeedingToolPath, GetModelingFromCustomDrill } from "../GraphicsSystem/ToolPath/FeedingToolPath";
import { FaceDirection, IHighSealedItem, BoardOpenDir } from "../UI/Store/BoardInterface";
import { arrayLast } from "../Common/ArrayExt";
import { userConfig } from "../Editor/UserConfig";
import { ExtrudeHole } from "../DatabaseServices/3DSolid/ExtrudeHole";
import { EMetalsType, IHardwareOption, IToplineOption } from "../UI/Components/RightPanel/RightPanelInterface";
import { AppToaster } from "../UI/Components/Toaster";
import { Intent } from "@blueprintjs/core";
import { ExtureContourCurve } from "../DatabaseServices/Entity/Extrude";
import { MergeCurvelist } from "../Common/CurveUtils";
import { safeEval, ParseExpr } from "../Common/eval";
import { HardwareTopline } from "../DatabaseServices/Hardware/HardwareTopline";
import { HardwareCompositeEntity } from "../DatabaseServices/Hardware/HardwareCompositeEntity";
import { IHardwareOption, EMetalsType, IToplineOption } from "../UI/Components/RightPanel/RightPanelInterface";
import { Hole } from "../DatabaseServices/3DSolid/Hole";
import { lookOverBoardInfosTool } from "../Add-on/LookOverBoardInfos/LookOverBoardInfosTool";
import { BoardOpenDir, FaceDirection, IHighSealedItem } from "../UI/Store/BoardInterface";
import { Entity } from './../DatabaseServices/Entity/Entity';
import { ICompHardwareOption } from './../UI/Components/RightPanel/RightPanelInterface';
import { FixedNotZero, LINK_FUZZ } from "../Common/Utils";
/**板件轮廓数据 */
@ -71,7 +71,7 @@ export interface IDrillingOption
angle?: number;
}
interface IBoardHoleInfo
export interface IBoardHoleInfo
{
frontBackHoles: IDrillingOption[];
sideHoles: IDrillingOption[];
@ -134,8 +134,8 @@ export namespace Production
/**获取板件拆单数据 */
export function GetBoardSplitOrderData(br: Board): ISpliteOrderData | undefined
{
let con = GetSealedBoardContour(br, true);
if (!con || equaln(con.Area, 0))
let sealedContour = GetSealedBoardContour(br, true);
if (!sealedContour || equaln(sealedContour.Area, 0))
{
AppToaster.show({
message: br.Name + " 轮廓错误,可能存在轮廓自交,请检查后重新拆单",
@ -165,7 +165,7 @@ export namespace Production
let size = outline.BoundingBox.getSize(new Vector3);
//不扣除封边的轮廓信息
let originOutlinePtsBul = ConverToPolylineAndSplitArc(con);
let originOutlinePtsBul = ConverToPolylineAndSplitArc(sealedContour);
originOutlinePtsBul.pts.pop();
originOutlinePtsBul.buls.pop();
@ -181,7 +181,7 @@ export namespace Production
outline: outlinePtsBul,
sealing: GetBoardSealingData(br),
modeling,
holes: GetBoardHolesData(br, offsetTanslation),
holes: GetBoardHolesData(br, offsetTanslation, sealedContour),
sideModeling,
offsetTanslation,
metalsData: GetBoardMetals(br),
@ -360,6 +360,7 @@ export namespace Production
sealData.reverse();
return sealData;
}
export function GetMetalTotalEntitys(md: HardwareCompositeEntity, isHole = false, filter?: (e: Entity) => boolean)
{
let holes: Entity[] = [];
@ -382,6 +383,7 @@ export namespace Production
}
return holes;
}
export function GetBoardModelingData(br: Board, offsetTanslation: Vector3)
{
const tool = FeedingToolPath.GetInstance() as FeedingToolPath;
@ -429,6 +431,7 @@ export namespace Production
return { modeling, sideModeling };
}
/**
*
* */
@ -477,6 +480,7 @@ export namespace Production
else
return;
}
export function GetSpliteOutlineBySpliteSize(br: Board)
{
let size = GetSpiteSize(br);
@ -487,17 +491,18 @@ export namespace Production
}
/**孔信息,侧孔的z 均为 从上到下距离 */
export function GetBoardHolesData(br: Board, offsetTanslation: Vector3): IBoardHoleInfo
export function GetBoardHolesData(br: Board, offsetTanslation: Vector3, sealedContour: ExtureContourCurve): IBoardHoleInfo
{
let drillList = br.DrillList;
let data: IBoardHoleInfo = {
frontBackHoles: [],
sideHoles: []
};
let brNormal = br.Normal;
let outline = GetSealedBoardContour(br, true);
for (let [, driss] of drillList)
// 性能优化的解析板件网洞类
// new ParseBoardHoleData(br, offsetTanslation, sealedContour);
for (let [, driss] of br.DrillList)
{
for (let dris of driss)
{
@ -507,9 +512,9 @@ export namespace Production
continue;
let d = dId.Object as CylinderHole;
if (d instanceof ExtrudeHole)
ParseExtrudeHoles(d, br, offsetTanslation, data, outline);
ParseExtrudeHoles(d, br, offsetTanslation, data, sealedContour);
else
ParseCylHoles(d, br, offsetTanslation, data, outline);
ParseCylHoles(d, br, offsetTanslation, data, sealedContour);
}
}
}
@ -528,9 +533,9 @@ export namespace Production
for (let h of holes)
{
if (h instanceof ExtrudeHole)
ParseExtrudeHoles(h, br, offsetTanslation, data, outline);
ParseExtrudeHoles(h, br, offsetTanslation, data, sealedContour);
else
ParseCylHoles(h as CylinderHole, br, offsetTanslation, data, outline);
ParseCylHoles(h as CylinderHole, br, offsetTanslation, data, sealedContour);
}
}
}
@ -699,6 +704,7 @@ export namespace Production
angle
});
}
/**分析自定义圆柱排钻 */
function ParseExtrudeHoles(d: ExtrudeHole, br: Board, offsetTanslation: Vector3, data: IBoardHoleInfo, outline: ExtureContourCurve)
{
@ -787,6 +793,7 @@ export namespace Production
}
}
}
function GetBoardMetals(br: Board)
{
let mids = br.RelativeHardware;
@ -812,6 +819,7 @@ export namespace Production
}
return metalsData;
}
export function GetHardwareCompositeData(en: HardwareCompositeEntity): ISpliteHardwareData
{
let size = en.BoundingBoxInOCS.getSize(new Vector3);
@ -846,6 +854,7 @@ export namespace Production
return metalData;
}
export function GetHardwareToplineData(en: HardwareTopline)
{
let data = { ...en.HardwareOption } as IToplineOption;
@ -888,11 +897,13 @@ export namespace Production
}
return datas;
}
/**获取排钻数量 */
export function GetTotalDrillCount(brs: (Board | IHardwareType)[])
{
return lookOverBoardInfosTool.GetCount(brs);
}
export function GetCabSize(brList: Board[]): Map<Board, Vector3>
{
let brMap: Map<string, Board[]> = new Map();
@ -922,4 +933,5 @@ export namespace Production
}
return sizeData;
}
}

Loading…
Cancel
Save