diff --git a/src/core/Constract.ts b/src/core/Constract.ts
index a957ae6..b97c525 100644
--- a/src/core/Constract.ts
+++ b/src/core/Constract.ts
@@ -12,8 +12,8 @@ export default Object.freeze({
// 测量相关的光标模式
CursorModeMeasure: 'measure',
-
CursorModeWay: 'way',
+ CursorModeGstore: 'gstore',
// 选择模式
CursorModeSelectByRec: 'selectByRec'
diff --git a/src/core/base/BaseInteraction.ts b/src/core/base/BaseInteraction.ts
index 05a4dc5..9255dfc 100644
--- a/src/core/base/BaseInteraction.ts
+++ b/src/core/base/BaseInteraction.ts
@@ -54,10 +54,41 @@ export default abstract class BaseInteraction {
alphaToCoverage: true
})
+ /**
+ * 物品是否"单点", 不允许连线
+ */
+ get isSinglePointMode(): boolean {
+ return false
+ }
+
constructor(itemTypeName: string) {
this.itemTypeName = itemTypeName
}
+ createPointOfItem(catchPoint: ItemJson, point: THREE.Vector3): ItemJson {
+ const renderer = getRenderer(this.itemTypeName)
+
+ const defaultScale = renderer.defaultScale
+ const defaultRotation = renderer.defaultRotation
+
+ _.extend(catchPoint, {
+ id: system.createUUID(),
+ t: this.itemTypeName,
+ v: true,
+ tf: [
+ [point.x, point.y, point.z],
+ [defaultRotation.x, defaultRotation.y, defaultRotation.z],
+ [defaultScale.x, defaultScale.y, defaultScale.z]
+ ],
+ dt: {
+ in: [] as string[],
+ out: [] as string[],
+ center: [] as string[]
+ }
+ })
+ return catchPoint
+ }
+
/**
* 拖拽点开始
*/
@@ -125,7 +156,14 @@ export default abstract class BaseInteraction {
}
if (this.linkStartPointId) {
- this.linkStartPointObject = this.viewport.entityManager.findObjectsById(this.linkStartPointId)?.[0]
+ if (this.isSinglePointMode) {
+ // 单点模式不需要起始点
+ this.linkStartPointId = undefined
+ this.linkStartPointObject = undefined
+
+ } else {
+ this.linkStartPointObject = this.viewport.entityManager.findObjectsById(this.linkStartPointId)?.[0]
+ }
}
pdFn = this.mousedown.bind(this)
@@ -266,9 +304,29 @@ export default abstract class BaseInteraction {
}
this.lastClickTime = now
+
// 如果正式的点命中到同类型的节点上,则不添加新的点,只牵线到该点
let catchPoint: ItemJson | null = this.viewport.stateManager.findItemByPosition(point, this.itemTypeName)
+
+ if (this.isSinglePointMode) {
+ // 单点模式,直接添加点
+ if (catchPoint) {
+ // 如果已经有点了,则不再添加
+ system.msg('Point already exists at this position.')
+ return
+ }
+
+ // 则添加一个新的点
+ const stateManager = this.viewport.stateManager
+ stateManager.beginStateUpdate({ createFromInteraction: true })
+ catchPoint = {} as ItemJson
+ catchPoint = this.createPointOfItem(catchPoint, point)
+ stateManager.vdata.items.push(catchPoint)
+ stateManager.endStateUpdate()
+ return
+ }
+
let from: ItemJson | undefined = undefined
if (this.linkStartPointId) {
from = this.viewport.stateManager.findItemById(this.linkStartPointId)
@@ -300,28 +358,9 @@ export default abstract class BaseInteraction {
stateManager.endStateUpdate()
} else {
- const renderer = getRenderer(this.itemTypeName)
-
- const defaultScale = renderer.defaultScale
- const defaultRotation = renderer.defaultRotation
-
// 添加正式点
- catchPoint = {
- id: system.createUUID(),
- t: this.itemTypeName,
- v: true,
- tf: [
- [point.x, point.y, point.z],
- [defaultRotation.x, defaultRotation.y, defaultRotation.z],
- [defaultScale.x, defaultScale.y, defaultScale.z]
- ],
- dt: {
- in: [] as string[],
- out: [] as string[],
- center: [] as string[]
- }
- } as ItemJson
-
+ catchPoint = {} as ItemJson
+ catchPoint = this.createPointOfItem(catchPoint, point)
// 提交状态管理器
const stateManager = this.viewport.stateManager
@@ -396,6 +435,8 @@ export default abstract class BaseInteraction {
const obj = new CSS2DObject(div)
return obj
}
+
+
}
export interface DragOption {
diff --git a/src/core/manager/WorldModel.ts b/src/core/manager/WorldModel.ts
index 446fd8b..8b6f429 100644
--- a/src/core/manager/WorldModel.ts
+++ b/src/core/manager/WorldModel.ts
@@ -3,6 +3,7 @@ import { reactive, watch } from 'vue'
import EventBus from '@/runtime/EventBus'
import Measure from '@/modules/measure'
import Way from '@/modules/way'
+import Gstore from '@/modules/gstore'
import StateManager from '@/core/manager/StateManager.ts'
export interface WorldModelState {
@@ -62,7 +63,8 @@ export default class WorldModel {
return Promise.all([
Measure,
- Way
+ Way,
+ Gstore
]).then(() => {
console.log('世界模型初始化完成')
diff --git a/src/editor/Model2DEditor.vue b/src/editor/Model2DEditor.vue
index 527b932..364a4fd 100644
--- a/src/editor/Model2DEditor.vue
+++ b/src/editor/Model2DEditor.vue
@@ -32,13 +32,18 @@
:type="state?.cursorMode===Constract.CursorModeSLink?'primary':''"
@click="()=>state.cursorMode = Constract.CursorModeSLink">
-