|
|
@ -5,6 +5,8 @@ import { getItemTypeByName } from '@/model/itemType/ItemTypeDefine' |
|
|
import type { ItemTypeDefineOption } from '@/model/itemType/ItemTypeDefine' |
|
|
import type { ItemTypeDefineOption } from '@/model/itemType/ItemTypeDefine' |
|
|
import { markRaw } from 'vue' |
|
|
import { markRaw } from 'vue' |
|
|
import EventBus from '@/runtime/EventBus' |
|
|
import EventBus from '@/runtime/EventBus' |
|
|
|
|
|
import { getInteraction } from '@/core/manager/ModuleManager.ts' |
|
|
|
|
|
import type BaseInteraction from '@/core/base/BaseInteraction.ts' |
|
|
|
|
|
|
|
|
// dragControls 绑定函数
|
|
|
// dragControls 绑定函数
|
|
|
let dragStartFn, dragFn, dragEndFn, clickblankFn |
|
|
let dragStartFn, dragFn, dragEndFn, clickblankFn |
|
|
@ -15,6 +17,7 @@ export default class EsDragControls { |
|
|
private onDownPosition: { x: number; y: number } = { x: -1, y: -1 } |
|
|
private onDownPosition: { x: number; y: number } = { x: -1, y: -1 } |
|
|
|
|
|
|
|
|
viewport: Viewport |
|
|
viewport: Viewport |
|
|
|
|
|
currentInteraction: BaseInteraction |
|
|
isDragging = false |
|
|
isDragging = false |
|
|
|
|
|
|
|
|
constructor(viewport) { |
|
|
constructor(viewport) { |
|
|
@ -68,7 +71,24 @@ export default class EsDragControls { |
|
|
// 拖拽开始
|
|
|
// 拖拽开始
|
|
|
dragControlsStart(e) { |
|
|
dragControlsStart(e) { |
|
|
// 右键拖拽不响应
|
|
|
// 右键拖拽不响应
|
|
|
if (e.e.button === 2 || !e.object.userData.type || !e.object.visible) return |
|
|
if (e.e.button === 2 || !e.object.visible) return |
|
|
|
|
|
|
|
|
|
|
|
const type = e.object.userData?.t |
|
|
|
|
|
const entityId = e.object.userData?.entityId |
|
|
|
|
|
|
|
|
|
|
|
if (!type || !entityId) return |
|
|
|
|
|
|
|
|
|
|
|
this.currentInteraction = getInteraction(e.object.userData?.t) |
|
|
|
|
|
if (!this.currentInteraction) { |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 有效拖拽对象
|
|
|
|
|
|
const enable = this.currentInteraction.dragPointStart(this.viewport, { |
|
|
|
|
|
object: e.object, |
|
|
|
|
|
entityId: entityId |
|
|
|
|
|
}) |
|
|
|
|
|
if (!enable) return |
|
|
|
|
|
|
|
|
e.e.preventDefault() |
|
|
e.e.preventDefault() |
|
|
|
|
|
|
|
|
@ -80,12 +100,10 @@ export default class EsDragControls { |
|
|
// 记录拖拽按下的位置和对象
|
|
|
// 记录拖拽按下的位置和对象
|
|
|
this.onDownPosition = { x: e.e.clientX, y: e.e.clientY } |
|
|
this.onDownPosition = { x: e.e.clientX, y: e.e.clientY } |
|
|
|
|
|
|
|
|
if (e.object.userData?.type) { |
|
|
// const itemType: ItemTypeDefineOption = getItemTypeByName(e.object.userData.type)
|
|
|
const itemType: ItemTypeDefineOption = getItemTypeByName(e.object.userData.type) |
|
|
// if (itemType?.clazz) {
|
|
|
if (itemType?.clazz) { |
|
|
// itemType.clazz.dragPointStart(this.viewport, e.object)
|
|
|
itemType.clazz.dragPointStart(this.viewport, e.object) |
|
|
// }
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
// switch (e.object.userData.type) {
|
|
|
// switch (e.object.userData.type) {
|
|
|
// case Constract.MeasureMarker:
|
|
|
// case Constract.MeasureMarker:
|
|
|
// this.viewport.measure.dragPointStart(e.object)
|
|
|
// this.viewport.measure.dragPointStart(e.object)
|
|
|
@ -95,6 +113,7 @@ export default class EsDragControls { |
|
|
|
|
|
|
|
|
// 拖拽中
|
|
|
// 拖拽中
|
|
|
drag(e) { |
|
|
drag(e) { |
|
|
|
|
|
this.currentInteraction?.dragPointMove(this.viewport, e) |
|
|
EventBus.dispatch('objectChanged', { |
|
|
EventBus.dispatch('objectChanged', { |
|
|
viewport: this, |
|
|
viewport: this, |
|
|
object: e.object |
|
|
object: e.object |
|
|
@ -105,15 +124,9 @@ export default class EsDragControls { |
|
|
dragControlsEnd(e) { |
|
|
dragControlsEnd(e) { |
|
|
// 右键拖拽不响应
|
|
|
// 右键拖拽不响应
|
|
|
if (e.e.button === 2 || !e.object.visible) return |
|
|
if (e.e.button === 2 || !e.object.visible) return |
|
|
|
|
|
if (!e.object.userData?.t) return |
|
|
|
|
|
|
|
|
// 拖拽结束启用其他控制器
|
|
|
// 单选点击
|
|
|
this.viewport.controls.enabled = true |
|
|
|
|
|
|
|
|
|
|
|
this.isDragging = false |
|
|
|
|
|
|
|
|
|
|
|
if (!e.object.userData.type) return |
|
|
|
|
|
|
|
|
|
|
|
// 判断位置是否有变化,没有变化则为点击
|
|
|
|
|
|
if (this.onDownPosition.x === e.e.clientX && this.onDownPosition.y === e.e.clientY) { |
|
|
if (this.onDownPosition.x === e.e.clientX && this.onDownPosition.y === e.e.clientY) { |
|
|
if (e.object.userData.onClick) { |
|
|
if (e.object.userData.onClick) { |
|
|
e.object.userData.onClick(e) |
|
|
e.object.userData.onClick(e) |
|
|
@ -127,12 +140,19 @@ export default class EsDragControls { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (e.object.userData?.type) { |
|
|
const ret = this.currentInteraction?.dragPointComplete(this.viewport, e) |
|
|
const itemType: ItemTypeDefineOption = getItemTypeByName(e.object.userData.type) |
|
|
if (!ret) return |
|
|
if (itemType?.clazz) { |
|
|
|
|
|
itemType.clazz.dragPointComplete(this.viewport) |
|
|
// 拖拽结束启用其他控制器
|
|
|
} |
|
|
this.viewport.controls.enabled = true |
|
|
} |
|
|
this.isDragging = false |
|
|
|
|
|
|
|
|
|
|
|
// if (e.object.userData?.type) {
|
|
|
|
|
|
// const itemType: ItemTypeDefineOption = getItemTypeByName(e.object.userData.type)
|
|
|
|
|
|
// if (itemType?.clazz) {
|
|
|
|
|
|
// itemType.clazz.dragPointComplete(this.viewport)
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
// switch (e.object.userData.type) {
|
|
|
// switch (e.object.userData.type) {
|
|
|
// case Constract.MeasureMarker:
|
|
|
// case Constract.MeasureMarker:
|
|
|
// this.viewport.measure.dragPointComplete()
|
|
|
// this.viewport.measure.dragPointComplete()
|
|
|
|