Merge pull request '新增优化相关数据模型,新增矩形优化处理器数据模型' (#1) from feature/layout_model into main
Reviewed-on: #1
This commit is contained in:
92
README.md
92
README.md
@@ -1,7 +1,81 @@
|
||||
## 生产接口协议
|
||||
本项目使用typescript编写,IDE推荐使用vscode。
|
||||
# Cut Abstractions
|
||||
|
||||
这是一个用于MES新版生产的抽象库,提供了一套可扩展的处理器和解析器,用于处理各种切割相关的指令和数据。
|
||||
|
||||
## 核心概念
|
||||
|
||||
- **处理器 (Processor)**: 负责执行具体的加工任务。每个处理器都包含名称、版本和执行方法。开发者可以继承 `ProcessorBase` 来实现自定义的处理器。
|
||||
|
||||
- **解析器 (Parser)**: 负责解析文本指令,并调用相应的处理代码。`ParserBase` 提供了解析和执行指令的基本框架。
|
||||
|
||||
- **上下文 (Context)**: 在处理器执行期间传递数据,包含输入、参数和输出。
|
||||
|
||||
## 主要功能
|
||||
|
||||
- **可扩展的处理器架构**: 允许开发者轻松添加新的加工处理器,以适应不同的业务需求。
|
||||
- **灵活的指令解析**: 支持自定义指令集,可以解析文本格式的指令并执行相应的操作。
|
||||
- **清晰的数据流**: 通过上下文对象在处理器之间传递数据,使得数据流清晰可控。
|
||||
|
||||
## 使用示例
|
||||
|
||||
以下是一个简单的示例,展示了如何使用本库:
|
||||
|
||||
```typescript
|
||||
import { ProcessorBase, ProcessorContext } from 'cut-abstractions';
|
||||
|
||||
// 定义输入、输出和配置类型
|
||||
interface MyInput {
|
||||
data: string;
|
||||
}
|
||||
|
||||
interface MyOutput {
|
||||
result: string;
|
||||
}
|
||||
|
||||
interface MyConfig {
|
||||
param: string;
|
||||
}
|
||||
|
||||
// 创建一个自定义处理器
|
||||
class MyProcessor extends ProcessorBase<MyInput, MyOutput, MyConfig> {
|
||||
get name() {
|
||||
return 'my-processor';
|
||||
}
|
||||
|
||||
get version() {
|
||||
return '1.0.0';
|
||||
}
|
||||
|
||||
exec(context: ProcessorContext<MyInput, MyOutput, MyConfig>) {
|
||||
// 执行处理逻辑
|
||||
const inputData = context.input?.data || '';
|
||||
const param = context.params?.param || '';
|
||||
context.output = {
|
||||
result: `Processed: ${inputData} with param: ${param}`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 使用处理器
|
||||
const processor = new MyProcessor();
|
||||
const context: ProcessorContext<MyInput, MyOutput, MyConfig> = {
|
||||
input: { data: 'hello' },
|
||||
params: { param: 'world' },
|
||||
};
|
||||
|
||||
processor.exec(context);
|
||||
|
||||
console.log(context.output?.result); // "Processed: hello with param: world"
|
||||
```
|
||||
|
||||
## 模块
|
||||
|
||||
- `base`: 提供了处理器的基本抽象。
|
||||
- `parsers`: 提供了指令解析器的基本抽象。
|
||||
- `models`: 定义了项目中使用的数据模型,如 `Config`、`Knife` 和 `File`。
|
||||
|
||||
## 术语表
|
||||
|
||||
### 术语表
|
||||
| 中文 | CAD | MES | IMES | 备注 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| 房名 | RoomName | roomName | roomName | |
|
||||
@@ -11,15 +85,3 @@
|
||||
| 大板名 | 无 | boardName | goodsName | |
|
||||
| 余料 | 无 | scrap | remain | |
|
||||
| 排单 | 无 | planOrder |planOrder | |
|
||||
|
||||
|
||||
### 编译与发布
|
||||
更新 package.json 版本号
|
||||
```shell
|
||||
pnpm clean
|
||||
pnpm build
|
||||
pnpm release
|
||||
```
|
||||
|
||||
### 开发建议
|
||||
MES与IMES存在不少命名上的差异,可以考虑 接口类型独立, 参数与配置单独创建类型
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cut-abstractions",
|
||||
"version": "0.1.7",
|
||||
"version": "0.1.8",
|
||||
"description": "",
|
||||
"files": [
|
||||
"dist/**/*"
|
||||
|
127
src/models/processors/rectLayout.ts
Normal file
127
src/models/processors/rectLayout.ts
Normal file
@@ -0,0 +1,127 @@
|
||||
/**
|
||||
* @file 矩形板件布局优化处理器使用的数据模型,包含优化输入、输出、大板、小板以及各类枚举
|
||||
* @todo 目前仅适配了矩形优化,后续还需要对数据结构进行扩展
|
||||
* @since 0.1.8
|
||||
* @author CZY
|
||||
*/
|
||||
|
||||
import { ConfigBase } from "../config";
|
||||
|
||||
export interface RectLayoutProcInput {
|
||||
/** 小板列表 */
|
||||
blocks: LayoutBlock[];
|
||||
/** 余料大板列表,可选,余料大板将会被优先优化,当余料大板被用尽时,则会使用配置中的大板尺寸进行优化 */
|
||||
scrapBoards?: Array<{
|
||||
/** 余料大板 */
|
||||
board: LayoutBoard,
|
||||
/** 大板张数 */
|
||||
count: number;
|
||||
}>;
|
||||
}
|
||||
|
||||
export class RectLayoutProcConfig extends ConfigBase {
|
||||
/** 大板高度 */
|
||||
boardHeight: number = 1220;
|
||||
/** 大板宽度 */
|
||||
boardWidth: number = 2440;
|
||||
/** 优化迭代次数 */
|
||||
iterations: number = 50;
|
||||
/** 双面加工优先排版 */
|
||||
doubleSidedFirst: boolean = false;
|
||||
/** 刀路间隙 */
|
||||
gap: number = 0;
|
||||
/** 运行标识 */
|
||||
_runFlag: 'running' | 'stopped' | 'terminated' = 'running';
|
||||
}
|
||||
|
||||
export type RectLayoutProcOutput = LayoutResult;
|
||||
|
||||
/** 优化小板输入 */
|
||||
export interface LayoutBlock {
|
||||
/** 小板ID */
|
||||
id: number;
|
||||
/** 长 */
|
||||
length: number;
|
||||
/** 宽 */
|
||||
width: number;
|
||||
/** 纹路类型 */
|
||||
waveType: WaveType;
|
||||
/** 排版面类型 */
|
||||
composingType: ComposingType;
|
||||
/** 孔洞类型 */
|
||||
holeType: HoleType;
|
||||
/** 是否为矩形板 */
|
||||
isRect?: boolean;
|
||||
/** 是否需要双面加工 */
|
||||
isdtwosided?: boolean;
|
||||
}
|
||||
|
||||
/** 优化大板输入 */
|
||||
export interface LayoutBoard {
|
||||
length: number;
|
||||
width: number;
|
||||
}
|
||||
|
||||
/** 纹路类型 */
|
||||
export enum WaveType {
|
||||
/** 正纹 */
|
||||
Positive = 0,
|
||||
/** 反纹 */
|
||||
Reverse = 1,
|
||||
/** 可翻转 */
|
||||
CanReversal = 2,
|
||||
}
|
||||
|
||||
/** 排版面 */
|
||||
export enum ComposingType {
|
||||
/** 正面 */
|
||||
Positive = 0,
|
||||
Reverse = 1, //反面
|
||||
Arbitrary = 2 //任意
|
||||
}
|
||||
|
||||
/** 孔类型 */
|
||||
export enum HoleType {
|
||||
/** 没有孔 */
|
||||
None = 0,
|
||||
/** 正面 */
|
||||
Positive = 1,
|
||||
/** 反面 */
|
||||
Reverse = 2,
|
||||
/** 正反皆有 */
|
||||
Two = 3
|
||||
}
|
||||
|
||||
/** 布局大板 */
|
||||
export interface LayoutResultBoard {
|
||||
id: string;
|
||||
/** 大板宽度 */
|
||||
boardWidth: number;
|
||||
/** 大板高度 */
|
||||
boardHeight: number;
|
||||
}
|
||||
|
||||
/** 布局小板 */
|
||||
export interface LayoutResultBlock {
|
||||
id: string;
|
||||
/** x坐标 */
|
||||
x: number;
|
||||
/** y坐标 */
|
||||
y: number;
|
||||
/** 宽度 */
|
||||
width: number;
|
||||
/** 高度 */
|
||||
height: number;
|
||||
/** 纹路类型 */
|
||||
waveType: WaveType;
|
||||
}
|
||||
|
||||
/** 优化布局结果 */
|
||||
export type LayoutResult = {
|
||||
/** 大板列表 */
|
||||
boards: LayoutResultBoard[],
|
||||
/** 小板列表,其一维与boards长度对应,二维为小板列表 */
|
||||
blocks: LayoutResultBlock[][],
|
||||
/** 优化中被使用的余料大板,这个列表中的每一个元素代表使用了一片该规格的大板 */
|
||||
usedScrapBoard: LayoutResultBoard[];
|
||||
};
|
Reference in New Issue
Block a user