83 lines
2.1 KiB
TypeScript
83 lines
2.1 KiB
TypeScript
|
import { NestFiler } from '../Filer'
|
||
|
import { Part } from './Part'
|
||
|
import { Path } from './Path'
|
||
|
import { PathGeneratorSingle } from './PathGenerator'
|
||
|
|
||
|
export const DefaultComparePointKeys = ['xy', 'yx']
|
||
|
|
||
|
/**
|
||
|
* 排料数据库,用这个类来序列化需要排料的数据
|
||
|
* 用于在Work间传输
|
||
|
*/
|
||
|
export class NestDatabase {
|
||
|
Bin: Path // 默认的容器
|
||
|
OddmentsBins: Path[]// 余料容器列表
|
||
|
Paths: Path[] // 所有的Path都在这里
|
||
|
Parts: Part[] // 所有的零件
|
||
|
ComparePointKeys: string[] = DefaultComparePointKeys// 用来决定零件靠边模式
|
||
|
|
||
|
// #region -------------------------File-------------------------
|
||
|
// 对象从文件中读取数据,初始化自身
|
||
|
ReadFile(file: NestFiler) {
|
||
|
const ver = file.Read()
|
||
|
let count = file.Read() as number
|
||
|
this.Paths = []
|
||
|
for (let i = 0; i < count; i++) {
|
||
|
const path = new Path()
|
||
|
path.ReadFile(file)
|
||
|
this.Paths.push(path)
|
||
|
}
|
||
|
this.Bin = this.Paths[file.Read()]
|
||
|
PathGeneratorSingle.paths = this.Paths
|
||
|
count = file.Read()
|
||
|
this.Parts = []
|
||
|
for (let i = 0; i < count; i++) {
|
||
|
const part = new Part()
|
||
|
part.ReadFile(file)
|
||
|
this.Parts.push(part)
|
||
|
}
|
||
|
|
||
|
count = file.Read()
|
||
|
this.OddmentsBins = []
|
||
|
for (let i = 0; i < count; i++) {
|
||
|
const path = new Path()
|
||
|
path.ReadFile(file)
|
||
|
this.OddmentsBins.push(path)
|
||
|
}
|
||
|
|
||
|
if (ver > 1)
|
||
|
this.ComparePointKeys = file.Read()
|
||
|
return this
|
||
|
}
|
||
|
|
||
|
// 对象将自身数据写入到文件.
|
||
|
WriteFile(file: NestFiler) {
|
||
|
file.Write(2)
|
||
|
file.Write(this.Paths.length)
|
||
|
for (const path of this.Paths)
|
||
|
path.WriteFile(file)
|
||
|
|
||
|
file.Write(this.Bin.Id)
|
||
|
file.Write(this.Parts.length)
|
||
|
for (const part of this.Parts)
|
||
|
part.WriteFile(file)
|
||
|
|
||
|
if (!this.OddmentsBins)
|
||
|
this.OddmentsBins = []
|
||
|
file.Write(this.OddmentsBins.length)
|
||
|
for (const path of this.OddmentsBins)
|
||
|
path.WriteFile(file)
|
||
|
|
||
|
file.Write(this.ComparePointKeys)
|
||
|
|
||
|
return this
|
||
|
}
|
||
|
// #endregion
|
||
|
|
||
|
get File() {
|
||
|
const f = new NestFiler()
|
||
|
this.WriteFile(f)
|
||
|
return f
|
||
|
}
|
||
|
}
|