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.
112 lines
3.1 KiB
112 lines
3.1 KiB
import Viewport from '@/core/engine/Viewport.ts'
|
|
import { executeTypeScript } from '@/core/script/ScriptSupport.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/cl2/Cl2Entity.ts'
|
|
import ClxEntity from '@/modules/clx/ClxEntity.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
|
|
}
|
|
|
|
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
|
|
}
|
|
getPositionByLogicXY(logicX: number, logicY: number): THREE.Vector3 {
|
|
const item = this.viewport.entityManager.findItemByLogicXY(logicX, logicY)
|
|
const matrix = getMatrixFromTf(item.tf)
|
|
const position = new THREE.Vector3()
|
|
matrix.decompose(position, new THREE.Quaternion(), new THREE.Vector3())
|
|
return position
|
|
}
|
|
|
|
dispose() {
|
|
this.viewport = null as any
|
|
window['Model'] = 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)
|
|
}
|
|
}
|
|
}
|
|
|