You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
198 lines
5.4 KiB
198 lines
5.4 KiB
import Viewport from '@/core/engine/Viewport.ts'
|
|
import { compileTypeScript, executeTypeScript } from '@/core/script/ModelScript.ts'
|
|
import * as THREE from 'three'
|
|
import { getMatrixFromTf } from '@/core/ModelUtils.ts'
|
|
import type { Object3DLike } from '@/types/ModelTypes.ts'
|
|
import TaskManager from '../manager/TaskManager.ts'
|
|
import Cl2Entity from '@/modules/amr/ptr/cl2/Cl2Entity.ts'
|
|
import ClxEntity from '@/modules/amr/ptr/clx/ClxEntity.ts'
|
|
import { getRenderer } from '@/core/manager/ModuleManager.ts'
|
|
import { markRaw } from 'vue'
|
|
import ToolProxyManager from '@/runtime/ToolProxyManager.ts'
|
|
|
|
export default class ModelManager implements IControls, Model {
|
|
private viewport: Viewport
|
|
|
|
getCl2(id: string): Cl2If {
|
|
return new Cl2Entity(this.viewport, id)
|
|
}
|
|
|
|
getClx(id: string): ClxIf {
|
|
return new ClxEntity(this.viewport, id)
|
|
}
|
|
|
|
createTask(agv: object): TaskManager {
|
|
if (TaskManager.taskMap.has(agv)) {
|
|
return TaskManager.taskMap.get(agv)
|
|
}
|
|
|
|
return new TaskManager(agv, this.viewport)
|
|
}
|
|
|
|
get selectedObject(): Object3DLike | undefined {
|
|
return this.viewport.state.selectedObject
|
|
}
|
|
|
|
get selectedEntityId(): string | undefined {
|
|
return this.viewport.state.selectedEntityId
|
|
}
|
|
|
|
get selectedItem(): ItemJson | undefined {
|
|
return this.viewport.state.selectedItem
|
|
}
|
|
|
|
get multiSelectedObjects(): Object3DLike[] {
|
|
return this.viewport.state.multiSelectedObjects
|
|
}
|
|
|
|
get multiSelectedItems(): ItemJson[] {
|
|
return this.viewport.state.multiSelectedItems
|
|
}
|
|
|
|
get multiSelectedEntityIds(): string[] {
|
|
return this.viewport.state.multiSelectedEntityIds
|
|
}
|
|
|
|
logger = {
|
|
info: (...args: any[]) => console.info(...args),
|
|
error: (...args: any[]) => console.error(...args),
|
|
warn: (...args: any[]) => console.warn(...args),
|
|
debug: (...args: any[]) => console.debug(...args)
|
|
}
|
|
|
|
init(viewport: Viewport) {
|
|
this.viewport = viewport
|
|
window['Model'] = this
|
|
window['print'] = this.print.bind(this)
|
|
window['executestring'] = this.executestring.bind(this)
|
|
window['logger'] = this.logger
|
|
window['msg'] = this.msg
|
|
}
|
|
|
|
find(entityId: string): ItemJson {
|
|
const item = this.viewport.entityManager.findItemById(entityId)
|
|
if (!item) {
|
|
print(`Item with ID ${entityId} not found in the viewport.`)
|
|
}
|
|
return item
|
|
}
|
|
|
|
find3D(id: string): any {
|
|
return this.viewport.entityManager.findObjectById(id)
|
|
}
|
|
|
|
getPositionByEntityId(entityId: string): THREE.Vector3 {
|
|
const item = this.viewport.entityManager.findItemById(entityId)
|
|
const matrix = getMatrixFromTf(item.tf)
|
|
const position = new THREE.Vector3()
|
|
matrix.decompose(position, new THREE.Quaternion(), new THREE.Vector3())
|
|
return position
|
|
}
|
|
|
|
deleteInv(itemId) {
|
|
this.viewport.runtimeManager.removeEntity(itemId)
|
|
}
|
|
|
|
deleteItem(itemId) {
|
|
if (this.viewport.runtimeManager.has(itemId)) {
|
|
// 临时执行器
|
|
this.viewport.runtimeManager.removeEntity(itemId)
|
|
return
|
|
}
|
|
this.viewport.stateManager.update(({ deleteEntity }) => {
|
|
deleteEntity(itemId)
|
|
})
|
|
}
|
|
|
|
createExecutor(item: ItemJson): void {
|
|
this.viewport.runtimeManager.addEntity(item)
|
|
}
|
|
|
|
createInv(boxType: ContainerT, lpn: string, rack: string, bay?: number, level?: number, cell?: number): void {
|
|
const scale = getRenderer(boxType).defaultScale
|
|
this.viewport.runtimeManager.addEntity({
|
|
id: lpn,
|
|
t: boxType as string,
|
|
tf: [[-5000, -1, 0], [0, 0, 0], [scale.x, scale.y, scale.z]],
|
|
v: true,
|
|
dt: {
|
|
in: [], out: [], center: [],
|
|
storeAt: { item: rack, bay, level, cell }
|
|
}
|
|
})
|
|
|
|
// 这一段代码不要删除,他是用向正式环境提交数据用的
|
|
/*
|
|
this.viewport.stateManager.update(({ getEntity, putEntity, addEntity }) => {
|
|
debugger
|
|
const item = getEntity(lpn)
|
|
if (item) {
|
|
_.extend(item, {
|
|
t: boxType as string,
|
|
tf: [[-5000, -1, 0], [0, 0, 0], [scale.x, scale.y, scale.z]],
|
|
v: true,
|
|
dt: {
|
|
in: [], out: [], center: [],
|
|
storeAt: { item: rack, bay, level, cell }
|
|
}
|
|
})
|
|
putEntity(item)
|
|
} else {
|
|
addEntity({
|
|
id: lpn,
|
|
t: boxType as string,
|
|
tf: [[-5000, -1, 0], [0, 0, 0], [scale.x, scale.y, scale.z]],
|
|
v: true,
|
|
dt: {
|
|
in: [], out: [], center: [],
|
|
storeAt: { item: rack, bay, level, cell }
|
|
}
|
|
})
|
|
}
|
|
})
|
|
*/
|
|
}
|
|
|
|
getPositionByLogicXY(logicX: number, logicY: number): THREE.Vector3 {
|
|
const item = this.viewport.entityManager.findItemByLogicXY(logicX, logicY)
|
|
if (!item) {
|
|
return null
|
|
}
|
|
const matrix = getMatrixFromTf(item.tf)
|
|
const position = new THREE.Vector3()
|
|
matrix.decompose(position, new THREE.Quaternion(), new THREE.Vector3())
|
|
return position
|
|
}
|
|
|
|
getItemByXYZ(x: number, y: number, z: number): ItemJson | undefined {
|
|
const item = this.viewport.entityManager.findItemByLogicXYZ(x, y, z)
|
|
return item
|
|
}
|
|
|
|
dispose() {
|
|
this.viewport = null as any
|
|
window['Model'] = null
|
|
window['print'] = null
|
|
window['executestring'] = null
|
|
window['logger'] = null
|
|
window['msg'] = null
|
|
window['RCS'] = null
|
|
window['LCC'] = null
|
|
}
|
|
|
|
async executestring(script: string) {
|
|
return executeTypeScript.call(this, script, {})
|
|
}
|
|
|
|
print(...data: any[]) {
|
|
console.log(...data)
|
|
}
|
|
|
|
msg(content: string, type: number = 1) {
|
|
if (type === 1) {
|
|
system.showErrorDialog(content)
|
|
} else if (type === 2) {
|
|
system.showInfoDialog(content)
|
|
}
|
|
}
|
|
}
|
|
|