feat: 提交
This commit is contained in:
2
src/index.ts
Normal file
2
src/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
// holeToModel
|
||||
export * from "./processors/holeToModel/holeToModel";
|
63
src/processors/holeToModel/holeToModel.test.ts
Normal file
63
src/processors/holeToModel/holeToModel.test.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { test } from "vitest";
|
||||
import { HoleToModelInput, HoleToModelProc, HoleToModelProcConfig, HoleToModelProcessingItem } from "./holeToModel";
|
||||
|
||||
const data = [
|
||||
{
|
||||
"id": "1",
|
||||
"faceType": 0,
|
||||
"holeType": 10,
|
||||
"startX": 8,
|
||||
"startY": 549,
|
||||
"radius": 3,
|
||||
"depth": 13.5,
|
||||
"knifeRadius": 1
|
||||
},
|
||||
{
|
||||
"id": "2",
|
||||
"faceType": 0,
|
||||
"holeType": 10,
|
||||
"startX": 8,
|
||||
"startY": 49,
|
||||
"radius": 3,
|
||||
"depth": 13.5,
|
||||
"knifeRadius": 2.5
|
||||
},
|
||||
{
|
||||
"id": "2",
|
||||
"faceType": 0,
|
||||
"holeType": 10,
|
||||
"startX": 8,
|
||||
"startY": 209,
|
||||
"radius": 3,
|
||||
"depth": 18,
|
||||
"knifeRadius": 1
|
||||
}
|
||||
]
|
||||
test('holeToModelTest', async () => {
|
||||
let holeData: HoleToModelProcessingItem[] = []
|
||||
data.forEach(e => {
|
||||
let temp: HoleToModelProcessingItem = {
|
||||
radius: e.radius,
|
||||
depth: e.depth,
|
||||
pts: [{ x: e.startX, y: e.startY }],
|
||||
buls: [0],
|
||||
knifeRadius: e.knifeRadius
|
||||
}
|
||||
holeData.push(temp)
|
||||
})
|
||||
|
||||
let conf: HoleToModelProcConfig = {}
|
||||
let input: HoleToModelInput = {
|
||||
thickness: 18,
|
||||
holeData
|
||||
}
|
||||
|
||||
let proc = new HoleToModelProc()
|
||||
let context = {
|
||||
input,
|
||||
params: conf
|
||||
}
|
||||
await proc.exec(context)
|
||||
|
||||
console.log(context);
|
||||
})
|
218
src/processors/holeToModel/holeToModel.ts
Normal file
218
src/processors/holeToModel/holeToModel.ts
Normal file
@@ -0,0 +1,218 @@
|
||||
import { ConfigBase, ProcessorBase, ProcessorContext } from "cut-abstractions";
|
||||
|
||||
/**
|
||||
* 孔转造型
|
||||
*/
|
||||
export class HoleToModelProc extends ProcessorBase<HoleToModelInput, HoleToModelOutput, HoleToModelProcConfig> {
|
||||
get name(): string {
|
||||
return 'holeToModel';
|
||||
}
|
||||
get version(): string {
|
||||
return '1.0.0';
|
||||
}
|
||||
exec(context: ProcessorContext<HoleToModelInput, HoleToModelOutput, HoleToModelProcConfig>): Promise<any> | any | void {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
let res: HoleToModelOutput | string = ''
|
||||
if (!context.input) {
|
||||
res = 'holeToModel: input is undefined!'
|
||||
reject(res)
|
||||
return res
|
||||
}
|
||||
|
||||
if (Array.isArray(context.input.holeData)) {
|
||||
let thickness = context.input.thickness
|
||||
|
||||
let modelData: HoleToModelProcessingItem[] = []
|
||||
let noHandleItem: noHandleItemType[] = []
|
||||
for (const hole of context.input.holeData) {
|
||||
let data = this.toModel(thickness, hole)
|
||||
if (data.code == 1) {
|
||||
modelData.push(data.item)
|
||||
} else {
|
||||
noHandleItem.push({
|
||||
info: data.info,
|
||||
holeData: hole
|
||||
})
|
||||
}
|
||||
}
|
||||
let output: HoleToModelOutput = {
|
||||
modelData,
|
||||
noHandleItem
|
||||
}
|
||||
context.output = output
|
||||
} else {
|
||||
res = 'holeToModel: input.holeData is invalid!'
|
||||
reject(res)
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
resolve(res)
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @param t 板件的厚度
|
||||
* @param hole 孔的 加工项
|
||||
*/
|
||||
private toModel(t: number, hole: HoleToModelProcessingItem) {
|
||||
let depth = hole.depth
|
||||
let radius = hole.radius
|
||||
let knifeRadius = hole.knifeRadius
|
||||
let resData: any = {
|
||||
code: -1,
|
||||
item: null,
|
||||
info: ''
|
||||
}
|
||||
|
||||
if (radius == knifeRadius) {
|
||||
resData.code = -1
|
||||
resData.item = hole
|
||||
resData.info = 'HoleToModel =》toModel : transform fail,radius is same as knifeRadius,do not need handle.'
|
||||
return resData
|
||||
} else if (radius < knifeRadius) {
|
||||
resData.code = -1
|
||||
resData.item = hole
|
||||
resData.info = 'HoleToModel =》toModel : transform fail,knifeRadius is more then radius,can not handle.'
|
||||
return resData
|
||||
} else if (radius > knifeRadius) {
|
||||
let p = hole.pts[0]
|
||||
if (p == undefined) {
|
||||
resData.code = -1
|
||||
resData.item = hole
|
||||
resData.info = 'HoleToModel =》toModel : transform fail,hole.pts has no data,can not handle.'
|
||||
return resData
|
||||
} else {
|
||||
let model: HoleToModelProcessingItem = {
|
||||
depth: depth,
|
||||
radius: knifeRadius,
|
||||
pts: [],
|
||||
buls: [],
|
||||
knifeRadius: knifeRadius,
|
||||
}
|
||||
/** 圆点 x */
|
||||
let cx = p.x
|
||||
/** 圆点 y */
|
||||
let cy = p.y
|
||||
|
||||
let r0 = hole.radius - hole.knifeRadius
|
||||
/** 最外层走一圈 */
|
||||
let bul = 0.41421356237309503
|
||||
model.pts.push({ x: cx - r0, y: cy })
|
||||
model.buls.push(-bul)
|
||||
|
||||
model.pts.push({ x: cx, y: cy + r0 })
|
||||
model.buls.push(-bul)
|
||||
|
||||
model.pts.push({ x: cx + r0, y: cy })
|
||||
model.buls.push(-bul)
|
||||
|
||||
model.pts.push({ x: cx, y: cy - r0 })
|
||||
model.buls.push(-bul)
|
||||
|
||||
model.pts.push({ x: cx - r0, y: cy })
|
||||
model.buls.push(0)
|
||||
|
||||
if (depth >= t - 0.001) {
|
||||
// 挖穿 输出结果
|
||||
resData.code = 1
|
||||
resData.item = model
|
||||
resData.info = 'success'
|
||||
return resData
|
||||
} else {
|
||||
// 非挖穿 需要铣
|
||||
r0 = r0 - knifeRadius
|
||||
while (r0 > 0) {
|
||||
|
||||
model.pts.push({ x: cx - r0, y: cy })
|
||||
model.buls.push(bul)
|
||||
|
||||
model.pts.push({ x: cx, y: cy - r0 })
|
||||
model.buls.push(bul)
|
||||
|
||||
model.pts.push({ x: cx + r0, y: cy })
|
||||
model.buls.push(bul)
|
||||
|
||||
model.pts.push({ x: cx, y: cy + r0 })
|
||||
model.buls.push(bul)
|
||||
|
||||
model.pts.push({ x: cx, y: cy + r0 })
|
||||
model.buls.push(0)
|
||||
r0 = r0 - knifeRadius
|
||||
}
|
||||
|
||||
// 移动到圆心
|
||||
model.pts.push({ x: cx, y: cy })
|
||||
model.buls.push(0)
|
||||
|
||||
resData.code = 1
|
||||
resData.item = model
|
||||
resData.info = 'success'
|
||||
return resData
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
/** 处理器输入 -孔转造型*/
|
||||
export type HoleToModelInput = {
|
||||
/** 孔信息 */
|
||||
holeData: HoleToModelProcessingItem[],
|
||||
/** 孔所在板件的优化后的坐标 X (可选)*/
|
||||
placeX?: number,
|
||||
/** 孔所在板件的优化后的坐标 Y (可选)*/
|
||||
placeY?: number,
|
||||
/** 孔所在板件的 厚度 */
|
||||
thickness: number
|
||||
}
|
||||
/** 处理器输出-- 获取造型在大板的刀路 */
|
||||
export type HoleToModelOutput = {
|
||||
/** 孔转造型 后的 造型数据 */
|
||||
modelData: HoleToModelProcessingItem[],
|
||||
/** 未处理的孔数据 以及信息 */
|
||||
noHandleItem: noHandleItemType[]
|
||||
}
|
||||
export type noHandleItemType = {
|
||||
/** 未处理的孔信息 */
|
||||
holeData: HoleToModelProcessingItem,
|
||||
/** 未处理 说明 */
|
||||
info: string
|
||||
}
|
||||
/** 处理器配置-- 获取造型在大板的刀路 */
|
||||
export declare class HoleToModelProcConfig extends ConfigBase {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 点阵数据 加工项
|
||||
*/
|
||||
export interface IProcessingItem {
|
||||
/**
|
||||
* 加工点数组
|
||||
*/
|
||||
pts: IPoint[];
|
||||
/**
|
||||
* 凸度数组
|
||||
*/
|
||||
buls: number[];
|
||||
/** 半径 (孔) */
|
||||
radius: number,
|
||||
/** 深度 */
|
||||
depth: number
|
||||
}
|
||||
/** 加工项的类型 */
|
||||
export type HoleToModelProcessingItem = IProcessingItem & {
|
||||
/** 使用刀具的刀半径 */
|
||||
knifeRadius: number
|
||||
}
|
||||
|
||||
export interface IPoint { x: number, y: number; }
|
1
src/vite-env.d.ts
vendored
Normal file
1
src/vite-env.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/// <reference types="vite/client" />
|
Reference in New Issue
Block a user