xushiting 2 роки тому
батько
коміт
2ddafaec22

+ 24 - 0
src/views/draw-file/board/editCAD/Controls/MoveTable.js

@@ -0,0 +1,24 @@
+import { floorplanService } from '../Service/FloorplanService'
+import { mathUtil } from '../MathUtil.js'
+import { coordinate } from '../Coordinate'
+import Constant from '../Constant'
+
+export default class MoveTable {
+    constructor() {
+
+    }
+
+    moveFullTable(dx,dy, tableId) {
+        let table = floorplanService.getTable(tableId)
+
+        table.center = {
+            x:table.center.x + dx/coordinate.res * Constant.defaultZoom/coordinate.zoom,
+            y:table.center.y - dy/coordinate.res * Constant.defaultZoom/coordinate.zoom,
+        }
+
+        table.setPoints2d()
+    }
+}
+
+const moveTable = new MoveTable()
+export { moveTable }

+ 12 - 3
src/views/draw-file/board/editCAD/Controls/MoveTag.js

@@ -1,12 +1,21 @@
 import { floorplanService } from '../Service/FloorplanService'
 import { mathUtil } from '../MathUtil.js'
+import { coordinate } from '../Coordinate'
+import Constant from '../Constant'
 
 export default class MoveTag {
-    constructor() {}
+    constructor() {
 
-    moveFullTag(position, tagId) {
+    }
+
+    moveFullTag(dx,dy, tagId) {
         let tag = floorplanService.getTag(tagId)
-        mathUtil.clonePoint(tag.center, position)
+
+        tag.center = {
+            x:tag.center.x + dx/coordinate.res * Constant.defaultZoom/coordinate.zoom,
+            y:tag.center.y - dy/coordinate.res * Constant.defaultZoom/coordinate.zoom,
+        }
+
         tag.setPoints2d()
     }
 }

+ 1 - 1
src/views/draw-file/board/editCAD/Controls/UIControl.js

@@ -42,7 +42,7 @@ export default class UIControl{
         } 
         else if (this.selectUI == UIEvents.Table ) 
         {
-            stateService.setEventName(LayerEvents.Table)
+            stateService.setEventName(LayerEvents.AddTable)
         } 
         else if (this.selectUI == UIEvents.Rectangle ) 
         {

+ 1 - 0
src/views/draw-file/board/editCAD/FloorplanData.js

@@ -10,6 +10,7 @@ export default class FloorplanData {
         this.floors[floorNum].walls = {}
         this.floors[floorNum].tags = {}
         this.floors[floorNum].tables = {}
+        this.floors[floorNum].cells = {}         //表里面的格子
         this.floors[floorNum].rectangles = {}
         this.floors[floorNum].circles = {}
         this.floors[floorNum].arrows = {}

+ 36 - 0
src/views/draw-file/board/editCAD/Geometry/Cell.js

@@ -0,0 +1,36 @@
+import VectorType from '../enum/VectorType.js'
+import Geometry from './Geometry.js'
+
+export default class Cell extends Geometry {
+    constructor(parent,vectorId) {
+        super()
+        this.width = 60;    //每个格子默认宽度是60像素
+        this.height = 30;   //每个格子默认高度是30像素
+        this.value = "";
+        this.colIndex = 0;
+        this.rowIndex = 0;
+        this.parent = parent;
+        this.geoType = VectorType.Cell
+        this.setId(vectorId)
+    }
+
+    setWidth(width){
+        this.width = width;
+    }
+
+    setHeight(height){
+        this.height = height;
+    }
+
+    setValue(value){
+        this.value = value;
+    }
+
+    setColIndex(colIndex){
+        this.colIndex = colIndex;
+    }
+
+    setRowIndex(rowIndex){
+        this.rowIndex = rowIndex;
+    }
+}

+ 127 - 0
src/views/draw-file/board/editCAD/Geometry/Table.js

@@ -0,0 +1,127 @@
+import VectorType from '../enum/VectorType.js'
+import Geometry from './Geometry'
+import { mathUtil } from '../MathUtil.js'
+import { coordinate } from '../Coordinate'
+import Constant from '../Constant.js'
+import Cell from './Cell'
+import { floorplanService } from '../Service/FloorplanService.js'
+import { tableService } from '../Service/TableService.js'
+
+//不靠墙
+export default class Table extends Geometry {
+    constructor(center, vectorId) {
+        super()
+        this.center = center
+        this.rowLen = 1;
+        this.colLen = 2;
+        this.points = []         
+        //this.size = [[]];          //保存全部cell的尺寸,方便查询
+        this.cells = [];           //cell的数组,里面存放cell.vectorId
+        this.geoType = VectorType.Table
+        this.setId(vectorId)
+        this.init();
+    }
+
+    //初始化两个cell
+    init(){
+        let cell1 = tableService.createCell(this.vectorId)
+        let cell2 = tableService.createCell(this.vectorId)
+        cell1.rowIndex = 0;
+        cell1.colIndex = 0;
+        cell2.rowIndex = 0;
+        cell2.colIndex = 1;
+
+        this.cells[0] = []
+        this.cells[0][0] = cell1.vectorId
+        this.cells[0][1] = cell2.vectorId
+        this.setPoints2d()
+    }
+
+    isContain(position) {
+        let points = []
+        points.push(this.points[0])
+        points.push(this.points[1])
+        points.push(this.points[2])
+        points.push(this.points[3])
+        return mathUtil.isPointInPoly(position, points)
+    }
+
+    setPoints2d() {
+        let rows = [];
+        let cols = [];
+        let height = 0;
+        let width = 0;
+
+        for(let i=0;i<this.cells.length;++i){
+            for(let j=0;j<this.cells[i].length;++j){
+                const cell = floorplanService.getCell(this.cells[i][j]);
+                if(!rows.includes(cell.rowIndex)){
+                    rows.push(cell.rowIndex);
+                    height += cell.height
+                }
+    
+                if(!cols.includes(cell.colIndex)){
+                    cols.push(cell.colIndex);
+                    width += cell.width
+                }
+            }
+        }
+
+        this.points = []
+
+        this.points[0] = {
+            x:this.center.x - ((width / coordinate.res) * Constant.defaultZoom) / coordinate.zoom / 2,
+            y:this.center.y + ((height / coordinate.res) * Constant.defaultZoom) / coordinate.zoom / 2
+        }
+
+        this.points[1] = {
+            x:this.center.x + ((width / coordinate.res) * Constant.defaultZoom) / coordinate.zoom / 2,
+            y:this.center.y + ((height / coordinate.res) * Constant.defaultZoom) / coordinate.zoom / 2
+        }
+
+        this.points[2] = {
+            x:this.center.x + ((width / coordinate.res) * Constant.defaultZoom) / coordinate.zoom / 2,
+            y:this.center.y - ((height / coordinate.res) * Constant.defaultZoom) / coordinate.zoom / 2
+        }
+
+        this.points[3] = {
+            x:this.center.x - ((width / coordinate.res) * Constant.defaultZoom) / coordinate.zoom / 2,
+            y:this.center.y - ((height / coordinate.res) * Constant.defaultZoom) / coordinate.zoom / 2
+        }
+    }
+
+    setValue(value) {
+        for(let i=0;i<value.length;++i){
+            const item = value[i]
+            let cell = this.cells[item.rowIndex][item.colIndex]
+            if(!cell){
+                cell = tableService.createCell(this.vectorId)
+                this.cells[item.rowIndex][item.colIndex] = cell.vectorId
+            }
+            cell.width = item.width
+            cell.height = item.width
+            cell.value = item.value
+            cell.colIndex = item.colIndex
+            cell.rowIndex = item.rowIndex
+        }
+    }
+
+    getCellPos(vectorId){
+        let height = 0;
+        let width = 0;
+        const cell = floorplanService.getCell(vectorId)
+        for(let i=0;i<cell.rowIndex;++i){
+            const _cell = floorplanService.getCell(this.cells[cell.rowIndex][0])
+            height += _cell.height;
+        }
+        for(let i=0;i<cell.colIndex;++i){
+            const _cell = floorplanService.getCell(this.cells[0][cell.colIndex])
+            width += _cell.width;
+        }
+
+        return {
+            x:width,
+            y:height
+        }
+    }
+}

+ 70 - 9
src/views/draw-file/board/editCAD/Layer.js

@@ -3,10 +3,12 @@ import { stateService } from './Service/StateService'
 import { elementService } from './Service/ElementService'
 import { floorplanService } from './Service/FloorplanService'
 import { tagService } from './Service/TagService'
+import { tableService } from './Service/TableService'
 import { historyService } from './Service/HistoryService'
 
 import UIControl from './Controls/UIControl'
 import { moveTag } from './Controls/MoveTag'
+import { moveTable } from './Controls/MoveTable'
 import { addWall } from './Controls/AddWall'
 import { moveWall } from './Controls/MoveWall'
 import { addRectangle } from './Controls/AddRectangle'
@@ -151,6 +153,12 @@ export default class Layer {
     onMouseMove(e) {
         const X = e.offsetX || e.layerX
         const Y = e.offsetY || e.layerY
+        if(this.lastX == null){
+            this.lastX = X;
+        }
+        if(this.lastY == null){
+            this.lastY = Y;
+        }
         let dx = X - this.lastX
         let dy = Y - this.lastY
 
@@ -420,13 +428,39 @@ export default class Layer {
                         stateService.setDraggingItem(stateService.selectItem)
                     }
                 } else {
-                    moveTag.moveFullTag(position, draggingItem.vectorId)
+                    moveTag.moveFullTag(dx,dy, draggingItem.vectorId)
+                    this.lastX = X
+                    this.lastY = Y
                 }
                 break
             case LayerEvents.MoveTag:
                 needAutoRedraw = true
                 if (draggingItem != null) {
-                    moveTag.moveFullTag(position, draggingItem.vectorId)
+                    moveTag.moveFullTag(dx,dy, draggingItem.vectorId)
+                    this.lastX = X
+                    this.lastY = Y
+                }
+                break
+            case LayerEvents.AddTable:
+                needAutoRedraw = true
+                if (draggingItem == null) {
+                    const table = tableService.createTable(position)
+                    if (table.vectorId) {
+                        stateService.setSelectItem(table.vectorId, VectorType.Table, SelectState.All)
+                        stateService.setDraggingItem(stateService.selectItem)
+                    }
+                } else {
+                    moveTable.moveFullTable(dx,dy, draggingItem.vectorId)
+                    this.lastX = X
+                    this.lastY = Y
+                }
+                break
+            case LayerEvents.MoveTable:
+                needAutoRedraw = true
+                if (draggingItem != null) {
+                    moveTable.moveFullTable(dx,dy, draggingItem.vectorId)
+                    this.lastX = X
+                    this.lastY = Y
                 }
                 break
             case LayerEvents.AddSign:
@@ -659,6 +693,21 @@ export default class Layer {
                 break
             case LayerEvents.AddTag:
                 needAutoRedraw = true
+                this.uiControl.showAttributes(focusItem)
+                this.history.save()
+                break
+            case LayerEvents.MoveTable:
+                if(focusItem == null){
+                    needAutoRedraw = true
+                    this.history.save()
+                }
+                else{
+                    this.uiControl.showAttributes(focusItem);
+                }
+                break
+            case LayerEvents.AddTable:
+                needAutoRedraw = true
+                this.uiControl.showAttributes(focusItem)
                 this.history.save()
                 break
             case LayerEvents.AddSign:
@@ -676,7 +725,8 @@ export default class Layer {
                 }
                 break
         }
-
+        this.lastX = null;
+        this.lastY = null;
         this.setEventName('mouseUp')
         stateService.clearDraggingItem()
         this.renderer.autoRedraw()
@@ -768,7 +818,9 @@ export default class Layer {
                     else{
                         stateService.setEventName(LayerEvents.moveArrowVertex)
                     }
-                } 
+                } else if (selectItem.type == VectorType.Table) {
+                    stateService.setEventName(LayerEvents.MoveTable)
+                }
             } 
             else if (eventName == LayerEvents.AddWall) {
                 stateService.setEventName(LayerEvents.AddingWall)
@@ -795,10 +847,10 @@ export default class Layer {
             {
                 stateService.setEventName(LayerEvents.AddingArrow)
             }
-            // else if (eventName == LayerEvents.AddingRectangle) 
-            // {
-            //     stateService.clearEventName()
-            // } 
+            else if (eventName == LayerEvents.AddTable) 
+            {
+                stateService.clearEventName()
+            } 
             else if (eventName != LayerEvents.AddWall && eventName != LayerEvents.AddingWall ) {  //&& eventName != LayerEvents.AddRectangle && eventName != LayerEvents.AddingRectangle && eventName != LayerEvents.AddCircle && eventName != LayerEvents.AddingCircle && eventName != LayerEvents.AddArrow && eventName != LayerEvents.AddingArrow && eventName != LayerEvents.AddIcon && eventName != LayerEvents.AddingIcon
                 stateService.clearEventName()
             } 
@@ -821,7 +873,14 @@ export default class Layer {
                     tagService.deleteTag(draggingItem.vectorId)
                     this.uiControl.clearUI();
                 }
-            } else if (eventName == LayerEvents.AddSign) {
+            } 
+            else if (eventName == LayerEvents.AddTable) {
+                if (draggingItem && draggingItem.vectorId) {
+                    tableService.deleteTable(draggingItem.vectorId)
+                    this.uiControl.clearUI();
+                }
+            }
+            else if (eventName == LayerEvents.AddSign) {
                 if (draggingItem && draggingItem.vectorId) {
                     floorplanService.deleteSign(draggingItem.vectorId)
                 }
@@ -843,6 +902,8 @@ export default class Layer {
                 floorplanService.deleteComponent(item.vectorId)
             } else if (item.type == VectorType.Tag) {
                 floorplanService.deleteTag(item.vectorId)
+            } else if (item.type == VectorType.Table) {
+                floorplanService.deleteTable(item.vectorId)
             } else if (signService.isSign(item.type)) {
                 floorplanService.deleteSign(item.vectorId)
             } else if (item.type == VectorType.WallCorner) {

+ 62 - 19
src/views/draw-file/board/editCAD/ListenLayer.js

@@ -285,28 +285,24 @@ export default class ListenLayer {
             }
         }
 
-        // const tables = floorplanService.getTables()
-        // for (const tableId in tables) {
-        //     const table = floorplanService.getTable(tableId)
-        //     const location = table.isContain(position)
-        //     if (location) {
-        //         result.tableInfo = {
-        //             tableId: tableId,
-        //             state: 'all',
-        //         }
-        //         break
-        //     }
-        // }
+        const tables = floorplanService.getTables()
+        for (const tableId in tables) {
+            const table = floorplanService.getTable(tableId)
+            const location = table.isContain(position)
+            if (location) {
+                result.tableInfo = {
+                    tableId: tableId,
+                    state: 'all',
+                }
+                break
+            }
+        }
 
         const rectangles = floorplanService.getRectangles()
         for (const rectangleId in rectangles) {
             const rectangle = floorplanService.getRectangle(rectangleId)
             const location = rectangle.isContain(position)
             if (location) {
-                // result.rectangleInfo = {
-                //     rectangleId: rectangleId,
-                //     state: 'all',
-                // }
                 result.rectangleInfo.rectangleId = rectangleId
                 if(location == SelectState.All){
                     result.rectangleInfo.state = SelectState.All;
@@ -477,7 +473,13 @@ export default class ListenLayer {
             this.iconInfo.index = nearest.iconInfo.index
         }
 
-        return flag1 || flag2 || flag3 || flag4  || flag5 || flag6 || flag7 || flag8
+        const flag9 = this.isChanged(nearest.tableInfo.tableId, nearest.tableInfo.state, 9)
+        this.tableInfo = {
+            tableId: nearest.tableInfo.tableId,
+            state: nearest.tableInfo.state,
+        }
+
+        return flag1 || flag2 || flag3 || flag4  || flag5 || flag6 || flag7 || flag8 || flag9
     }
 
     isChanged(vectorId, state, type, index) {
@@ -574,7 +576,15 @@ export default class ListenLayer {
                 flag = true
             }
         }
-
+        else if (type == 9) {
+            if (state == null && state == this.tableInfo.state) {
+                flag = false
+            } else if (this.tableInfo.tableId == vectorId && state == this.tableInfo.state) {
+                flag = false
+            } else {
+                flag = true
+            }
+        } 
         return flag
     }
 
@@ -619,6 +629,9 @@ export default class ListenLayer {
         } else if (this.signInfo.signsId != null && this.signInfo.state != null) {
             const sign = floorplanService.getSign(this.signInfo.signsId)
             stateService.setSelectItem(this.signInfo.signsId, sign.geoType, this.signInfo.state)
+        } else if (this.tableInfo.tableId != null && this.tableInfo.state != null) {
+            const table = floorplanService.getTable(this.tableInfo.tableId)
+            stateService.setSelectItem(this.tableInfo.tableId, table.geoType, this.tableInfo.state)
         } 
         else {
             stateService.clearSelectItem()
@@ -628,7 +641,7 @@ export default class ListenLayer {
     clear() {
         this.wallInfo = {
             wallId: null,
-            state: null,
+            state: null, 
         }
 
         this.pointInfo = {
@@ -636,6 +649,36 @@ export default class ListenLayer {
             state: null,
         }
 
+        this.tagInfo = {
+            tagId: null,
+            state: null,
+        }
+
+        this.tableInfo = {
+            tableId: null,
+            state: null,
+        }
+
+        this.rectangleInfo = {
+            rectangleId: null,
+            state: null,
+        }
+
+        this.circleInfo = {
+            circleId: null,
+            state: null,
+        }
+
+        this.arrowInfo = {
+            arrowId: null,
+            state: null,
+        }
+
+        this.iconInfo = {
+            iconId: null,
+            state: null,
+        }
+
         this.signInfo = {
             signsId: null,
             state: null,

+ 64 - 8
src/views/draw-file/board/editCAD/Renderer/Draw.js

@@ -252,6 +252,62 @@ export default class Draw {
         this.context.restore()
     }
 
+    drawTable(geometry){
+        const leftTop = coordinate.getScreenXY({
+            x:geometry.center.x - Math.abs(geometry.points[0].x - geometry.points[1].x)/2,
+            y:geometry.center.y + Math.abs(geometry.points[0].y - geometry.points[3].y)/2,
+        })
+
+        for(let i=0;i<geometry.cells.length;++i){
+            for(let j=0;j<geometry.cells[i].length;++j)
+            {
+                const cell = floorplanService.getCell(geometry.cells[i][j])
+                const position = geometry.getCellPos(cell.vectorId)
+                this.drawCell(cell,position.x + leftTop.x,position.y + leftTop.y)
+            }
+        }
+    }
+
+    drawCell(geometry,width,height){
+
+        this.context.save()
+        this.context.lineWidth = Style.Table.lineWidth * coordinate.ratio
+        this.context.strokeStyle = Style.Table.strokeStyle
+        this.context.fillStyle = Style.Table.fillStyle
+
+        const selectItem = stateService.getSelectItem()
+        const draggingItem = stateService.getDraggingItem()
+        const focusItem = stateService.getFocusItem()
+
+        if (selectItem && selectItem.type == VectorType.Table) {
+            if (geometry.parent == selectItem.vectorId) {
+                this.context.strokeStyle = Style.Select.Table.strokeStyle
+                this.context.fillStyle = Style.Select.Table.fillStyle
+            }
+        } else if (draggingItem && draggingItem.type == VectorType.Table) {
+            if (geometry.parent == draggingItem.vectorId) {
+                this.context.strokeStyle = Style.Select.Table.strokeStyle
+                this.context.fillStyle = Style.Select.Table.fillStyle
+            }
+        }
+
+        if (focusItem && focusItem.type == VectorType.Table) {
+            if (geometry.parent == focusItem.vectorId) {
+                this.context.strokeStyle = Style.Focus.Table.strokeStyle
+                this.context.fillStyle = Style.Focus.Table.fillStyle
+            }
+        }
+        this.context.translate(width, height)
+        this.context.beginPath()
+        this.context.moveTo(0,0)
+        this.context.lineTo(geometry.width,0)
+        this.context.lineTo(geometry.width,geometry.height)
+        this.context.lineTo(0,geometry.height)
+        this.context.closePath();
+        this.context.stroke()
+        this.context.restore()
+    }
+
     drawRectangle(geometry){
         let points = []
         for(let i=0;i<geometry.points.length;++i){
@@ -294,17 +350,17 @@ export default class Draw {
             }
         } else if (draggingItem && draggingItem.type == VectorType.Rectangle) {
             if (geometry.vectorId == draggingItem.vectorId) {
-                if(selectItem.selectIndex == SelectState.All){
+                if(draggingItem.selectIndex == SelectState.All){
                     this.context.strokeStyle = Style.Select.Rectangle.strokeStyle
                     this.context.fillStyle = Style.Select.Rectangle.fillStyle
                     fillFlag = true;
                 }
-                else if(selectItem.selectIndex.indexOf(SelectState.Side)>-1){
+                else if(draggingItem.selectIndex.indexOf(SelectState.Side)>-1){
                     this.context.strokeStyle = Style.Select.Rectangle.strokeStyle
                 }
-                else if(selectItem.selectIndex.indexOf(SelectState.Vertex)>-1){
+                else if(draggingItem.selectIndex.indexOf(SelectState.Vertex)>-1){
                     this.context.strokeStyle = Style.Select.Rectangle.strokeStyle
-                    let vertexIndex = selectItem.selectIndex.replace(SelectState.Vertex+'_','');
+                    let vertexIndex = draggingItem.selectIndex.replace(SelectState.Vertex+'_','');
                     this.drawCircle({
                         x:geometry.points[vertexIndex].x,
                         y:geometry.points[vertexIndex].y,
@@ -316,17 +372,17 @@ export default class Draw {
 
         if (focusItem && focusItem.type == VectorType.Rectangle) {
             if (geometry.vectorId == focusItem.vectorId) {
-                if(selectItem.selectIndex == SelectState.All){
+                if(focusItem.selectIndex == SelectState.All){
                     this.context.strokeStyle = Style.Focus.Rectangle.strokeStyle
                     this.context.fillStyle = Style.Focus.Rectangle.fillStyle
                     fillFlag = true;
                 }
-                else if(selectItem.selectIndex.indexOf(SelectState.Side)>-1){
+                else if(focusItem.selectIndex.indexOf(SelectState.Side)>-1){
                     this.context.strokeStyle = Style.Focus.Rectangle.strokeStyle
                 }
-                else if(selectItem.selectIndex.indexOf(SelectState.Vertex)>-1){
+                else if(focusItem.selectIndex.indexOf(SelectState.Vertex)>-1){
                     this.context.strokeStyle = Style.Focus.Rectangle.strokeStyle
-                    let vertexIndex = selectItem.selectIndex.replace(SelectState.Vertex+'_','');
+                    let vertexIndex = focusItem.selectIndex.replace(SelectState.Vertex+'_','');
                     this.drawCircle({
                         x:geometry.points[vertexIndex].x,
                         y:geometry.points[vertexIndex].y,

+ 2 - 0
src/views/draw-file/board/editCAD/Renderer/Render.js

@@ -40,6 +40,8 @@ export default class Render {
             case VectorType.Arrow:
                 draw.drawArrow(vector)    
                 return
+            case VectorType.Table:
+                draw.drawTable(vector)
         }
 
         if (signService.isSign(vector.geoType)) {

+ 0 - 130
src/views/draw-file/board/editCAD/Service/AnalyService.js

@@ -1,130 +0,0 @@
-//解析来自算法部的数据:https://4dkk.4dage.com/data/datat-uXiVK7k/floorplan_cad.json?_=0
-import { floorplanService } from './FloorplanService'
-import { wallService } from './WallService'
-import { floorplanData } from '../FloorplanData'
-import VectorType from '../enum/VectorType.js'
-
-export default class AnalyService {
-    constructor(layer) {
-        this.layer = layer
-        this.app = this.layer.app
-        this.houseData = null
-    }
-
-    initVectors(data) {
-        let floors = data.floors
-        let currentId = -1
-        let offWallId = 0 //算法部的id都是从0开始,且每层楼的id都是从0开始
-        let offPointId = 0
-        for (let i = 0; i < floors.length; ++i) {
-            let floorNum = floors[i].subgroup
-            let floor = floors[i]
-            floorplanData.floors[floorNum] = {}
-            floorplanData.floors[floorNum].points = {}
-            floorplanData.floors[floorNum].walls = {}
-            floorplanData.floors[floorNum].tables = {}
-            floorplanData.floors[floorNum].rectangles = {}
-            floorplanData.floors[floorNum].circles = {}
-            floorplanData.floors[floorNum].arrows = {}
-            floorplanData.floors[floorNum].icons = {}
-            floorplanData.floors[floorNum].tags = {}
-            floorplanData.floors[floorNum].signs = {}
-            let minX = null,
-                minY = null,
-                maxX = null,
-                maxY = null
-
-            for (let j = 0; j < floor['vertex-xy'].length; ++j) {
-                let vectorId = floor['vertex-xy'][j].id + offPointId
-                if (currentId < vectorId) {
-                    currentId = vectorId
-                }
-                vectorId = VectorType.Point + vectorId
-                let point = {
-                    x: floor['vertex-xy'][j].x,
-                    y: floor['vertex-xy'][j].y,
-                }
-                wallService.createPoint(point.x, point.y, vectorId, floorNum)
-                if (minX == null || minX > point.x) {
-                    minX = point.x
-                }
-                if (minY == null || minY > point.y) {
-                    minY = point.y
-                }
-
-                if (maxX == null || maxX < point.x) {
-                    maxX = point.x
-                }
-                if (maxY == null || maxY < point.y) {
-                    maxY = point.y
-                }
-            }
-            offWallId = currentId + 1
-
-            floorplanData.floors[floorNum].boundingBox.minX = minX
-            floorplanData.floors[floorNum].boundingBox.minY = minY
-            floorplanData.floors[floorNum].boundingBox.maxX = maxX
-            floorplanData.floors[floorNum].boundingBox.maxY = maxY
-
-            for (let j = 0; j < floor['segment'].length; ++j) {
-                let vectorId = floor['segment'][j].id + offWallId
-                if (currentId < vectorId) {
-                    currentId = vectorId
-                }
-                vectorId = VectorType.Wall + vectorId
-                let start = VectorType.Point + (floor['segment'][j].a + offPointId)
-                let end = VectorType.Point + (floor['segment'][j].b + offPointId)
-
-                wallService.createWall(start, end, vectorId, floorNum)
-            }
-
-            offWallId = currentId + 1
-            offPointId = currentId + 1
-        }
-        floorplanService.setCurrentId(currentId + 1)
-        const currentFloorNum = this.app.core.get('Player').model.currentFloor.floorIndex
-        floorplanService.setCurrentFloor(currentFloorNum)
-        //随心装的json数据
-        //this.houseData = this.createDecorateData(floorplanData)
-    }
-
-    //随心装数据,houseType.json
-    createDecorateData(floorplanData) {
-        let house = {}
-        house.name = 'houseType.json'
-        house.version = '2.1'
-        house.floors = []
-
-        for (let i = 0; i < floorplanData.floors.length; ++i) {
-            let item = {}
-            item.points = []
-            item.walls = []
-
-            //floorplanData.floors.points
-            //floorplanData.floors.walls
-            for (let key in floorplanData.floors[i].points) {
-                let point = {}
-                point.x = floorplanData.floors[i].points[key].x
-                point.y = floorplanData.floors[i].points[key].y
-                point.parent = floorplanData.floors[i].points[key].parent
-                point.vectorId = floorplanData.floors[i].points[key].vectorId
-
-                item.points.push(point)
-            }
-
-            for (let key in floorplanData.floors[i].walls) {
-                let wall = {}
-                wall.start = floorplanData.floors[i].walls[key].start
-                wall.end = floorplanData.floors[i].walls[key].end
-
-                wall.vectorId = floorplanData.floors[i].walls[key].vectorId
-                wall.width = 0.2
-
-                item.walls.push(wall)
-            }
-
-            house.floors.push(item)
-        }
-        return house
-    }
-}

+ 62 - 0
src/views/draw-file/board/editCAD/Service/FloorplanService.js

@@ -288,6 +288,66 @@ export class FloorplanService {
         return floorplanData.floors[floor].tags
     }
 
+    addTable(table, floor) {
+        if (floor == null || typeof floor == 'undefined') {
+            floor = this.currentFloor
+        }
+        floorplanData.floors[floor].tables[table.vectorId] = table
+    }
+
+    getTable(tableId, floor) {
+        if (floor == null || typeof floor == 'undefined') {
+            floor = this.currentFloor
+        }
+        return floorplanData.floors[floor].tables[tableId]
+    }
+
+    deleteTable(tableId, floor) {
+        if (floor == null || typeof floor == 'undefined') {
+            floor = this.currentFloor
+        }
+        let table = this.getTable(tableId, floor)
+        table = null
+        delete floorplanData.floors[floor].tables[tableId]
+    }
+
+    getTables(floor) {
+        if (floor == null || typeof floor == 'undefined') {
+            floor = this.currentFloor
+        }
+        return floorplanData.floors[floor].tables
+    }
+
+    addCell(cell, floor) {
+        if (floor == null || typeof floor == 'undefined') {
+            floor = this.currentFloor
+        }
+        floorplanData.floors[floor].cells[cell.vectorId] = cell
+    }
+
+    getCell(cellId, floor) {
+        if (floor == null || typeof floor == 'undefined') {
+            floor = this.currentFloor
+        }
+        return floorplanData.floors[floor].cells[cellId]
+    }
+
+    deleteCell(cellId, floor) {
+        if (floor == null || typeof floor == 'undefined') {
+            floor = this.currentFloor
+        }
+        let cell = this.getCell(cellId, floor)
+        cell = null
+        delete floorplanData.floors[floor].cells[cellId]
+    }
+
+    getCells(floor) {
+        if (floor == null || typeof floor == 'undefined') {
+            floor = this.currentFloor
+        }
+        return floorplanData.floors[floor].cells
+    }
+
     getRectangles(floor) {
         if (floor == null || typeof floor == 'undefined') {
             floor = this.currentFloor
@@ -329,6 +389,8 @@ export class FloorplanService {
             floorplanData.floors[this.currentFloor].rectangles = {}
             floorplanData.floors[this.currentFloor].circles = {}
             floorplanData.floors[this.currentFloor].tags = {}
+            floorplanData.floors[this.currentFloor].tables = {}
+            floorplanData.floors[this.currentFloor].cells = {}
             floorplanData.floors[this.currentFloor].signs = {}
             floorplanData.floors[this.currentFloor].arrows = {}
             floorplanData.floors[this.currentFloor].icons = []

+ 53 - 0
src/views/draw-file/board/editCAD/Service/TableService.js

@@ -0,0 +1,53 @@
+import Table from '../Geometry/Table.js'
+import Cell from '../Geometry/Cell.js'
+import { floorplanService } from './FloorplanService'
+import { floorplanData } from '../FloorplanData'
+import { mathUtil } from '../MathUtil.js'
+
+export default class TableService {
+    constructor() {}
+
+    // 新建cell
+    createCell(parent,cellId, floor) {
+        let cell = new Cell(parent,cellId)
+        floorplanService.addCell(cell, floor)
+        return cell
+    }
+
+    // 新建table
+    createTable(position, tableId, floor) {
+        let table = new Table(position, tableId)
+        table.setPoints2d()
+        floorplanService.addTable(table, floor)
+        return table
+    }
+
+    setTableInfo(tableInfo) {
+        let table = floorplanService.getTable(tableInfo.vectorId)
+        table.vectorId = tableInfo.vectorId
+        table.center = JSON.parse(JSON.stringify(tableInfo.center))
+        table.points = JSON.parse(JSON.stringify(tableInfo.points))
+        table.rowLen = tableInfo.rowLen;
+        table.colLen = tableInfo.colLen;      
+        table.cells = tableInfo.cells;  
+    }
+
+    deleteTable(tableId, floorNum) {
+        floorplanService.deleteTable(tableId, floorNum)
+    }
+
+    clearDefaultTables() {
+        for (let i = 0; i < floorplanData.floors.length; ++i) {
+            let tables = floorplanData.floors[i].tables
+            for (let key in tables) {
+                let table = tables[key]
+                if ((table.value == null || table.value.trim() == '')) {
+                    this.deleteTable(table.vectorId, i)
+                }
+            }
+        }
+    }
+}
+
+const tableService = new TableService()
+export { tableService }

+ 26 - 14
src/views/draw-file/board/editCAD/Style.js

@@ -40,29 +40,37 @@ const Style = {
         strokeStyle: '#000000',
         lineWidth: 2,
     },
+    Table:{
+        strokeStyle: '#000000',
+        lineWidth: 2,
+    },
     Select: {
         Wall: {
-            strokeStyle: 'rgba(243, 255, 0, 1)',
+            strokeStyle: 'green',
         },
         Rectangle: {
-            strokeStyle: 'rgba(243, 255, 0, 0.8)',
+            strokeStyle: 'green',
             fillStyle: 'rgba(243, 255, 0, 0.5)',
         },
         Circle: {
-            strokeStyle: 'rgba(243, 255, 0, 0.8)',
+            strokeStyle: 'green',
             fillStyle: 'rgba(243, 255, 0, 0.5)',
         },
         Icon: {
-            strokeStyle: 'rgba(243, 255, 0, 0.8)',
+            strokeStyle: 'green',
             fillStyle: 'rgba(243, 255, 0, 0.5)',
         },
         Arrow: {
-            strokeStyle: 'rgba(243, 255, 0, 1)',
+            strokeStyle: 'green',
         },
         Tag: {
             strokeStyle: '#00C8AF',
             fillStyle: '#00C8AF',
         },
+        Table: {
+            strokeStyle: 'green',
+            fillStyle: 'rgba(243, 255, 0, 0.5)',
+        },
         Sign: {
             strokeStyle: 'rgba(243, 255, 0, 0.8)',
             fillStyle: 'rgba(243, 255, 0, 0.5)',
@@ -70,33 +78,37 @@ const Style = {
         Point: {
             radius: 4,
             lineWidth: 2,
-            fillStyle: 'rgba(245, 255, 0, 1)',
-            strokeStyle: 'rgba(245, 255, 255, 1)',
+            fillStyle: 'rgb(0, 200, 175)',
+            strokeStyle: 'green',
         },
     },
     Focus: {
         Wall: {
-            strokeStyle: 'rgba(243, 255, 0, 1)',
+            strokeStyle: 'green',
         },
         Rectangle: {
-            strokeStyle: 'rgba(243, 255, 0, 0.8)',
+            strokeStyle: 'green',
             fillStyle: 'rgba(243, 255, 0, 0.5)',
         },
         Circle: {
-            strokeStyle: 'rgba(243, 255, 0, 0.8)',
+            strokeStyle: 'green',
             fillStyle: 'rgba(243, 255, 0, 0.5)',
         },
         Icon: {
-            strokeStyle: 'rgba(243, 255, 0, 0.8)',
+            strokeStyle: 'green',
             fillStyle: 'rgba(243, 255, 0, 0.5)',
         },
         Arrow: {
-            strokeStyle: 'rgba(243, 255, 0, 1)',
+            strokeStyle: 'green',
         },
         Tag: {
             strokeStyle: '#00C8AF',
             fillStyle: '#00C8AF',
         },
+        Table: {
+            strokeStyle: 'green',
+            fillStyle: 'rgba(243, 255, 0, 0.5)',
+        },
         Sign: {
             strokeStyle: 'rgba(243, 255, 0, 0.8)',
             fillStyle: 'rgba(243, 255, 0, 0.5)',
@@ -105,13 +117,13 @@ const Style = {
             radius: 4,
             lineWidth: 2,
             fillStyle: 'rgba(245, 255, 0, 1)',
-            strokeStyle: 'rgba(245, 255, 255, 1)',
+            strokeStyle: 'green',
         },
     },
     Element: {
         StartAddWall: {
             radius: 4,
-            fillStyle: 'yellow',
+            fillStyle: 'rgb(0, 200, 175)',
             strokeStyle: 'green',
         },
         NewWall: {

+ 3 - 0
src/views/draw-file/board/editCAD/enum/LayerEvents.js

@@ -29,6 +29,9 @@ const LayerEvents = {
     MoveIcon: 'moveIcon',
     MoveIconVertex: 'moveIconVertex',
 
+    AddTable: 'addTable',
+    MoveTable: 'moveTable',
+
     AddSign: 'addSign',
     MoveSign: 'moveSign',
 }

+ 2 - 1
src/views/draw-file/board/editCAD/enum/VectorType.js

@@ -3,7 +3,8 @@ const VectorType = {
     WallCorner: 'WallCorner',
     Wall: 'Wall',
     Tag: 'Tag',
-    Table:'Table',          
+    Table:'Table', 
+    Cell:'Cell',         
     Rectangle:'Rectangle',
     Circle:'Circle',
     Arrow:'Arrow',