xushiting пре 2 година
родитељ
комит
c3de40f5ce

+ 19 - 13
src/graphic/Controls/UIControl.js

@@ -17,6 +17,7 @@ import { addRoad } from "../Controls/AddRoad";
 export default class UIControl {
   constructor(layer) {
     this.layer = layer;
+    this.selectUI = null;
   }
 
   /**
@@ -29,24 +30,29 @@ export default class UIControl {
    */
   set currentUI(value) {
     console.log(value);
-    this.value = value;
+    this.updateEventNameForSelectUI(value);
+    this.selectUI = value;
   }
 
   //点击左侧栏后,更新事件
-  updateEventNameForSelectUI() {
-    //elementService.hideAll();
-    //正在添加tag的时候,需要先删除
-    const eventName = stateService.getEventName();
-    if (eventName == LayerEvents.AddTag) {
-      let item = stateService.getDraggingItem();
-      if (item && item.type == VectorType.Tag) {
-        dataService.deleteTag(item.vectorId);
+  updateEventNameForSelectUI(selectUI) {
+    if (selectUI != null) {
+      if (this.selectUI == selectUI) {
+        return;
+      } else if (this.selectUI != selectUI) {
+        if (this.selectUI != null) {
+          //先取消当前事件和进程
+          stateService.clear();
+          //。。。。
+        }
+        //执行新的事件
+        if (this.selectUI == UIEvents.Road) {
+          stateService.setEventName(LayerEvents.AddWall);
+        } else if (this.selectUI == UIEvents.Tag) {
+          stateService.setEventName(LayerEvents.AddTag);
+        }
       }
     }
-    stateService.clearItems();
-    if (this.selectUI == UIEvents.Road) {
-      stateService.setEventName(LayerEvents.AddWall);
-    }
   }
 
   /****************************************************************************针对菜单*******************************************************************************/

+ 37 - 63
src/graphic/Layer.js

@@ -34,14 +34,13 @@ export default class Layer extends mitt {
     this.renderer = new Render(this);
     this.history = new History(this);
 
-    this.startX = null;
-    this.startY = null;
-
     this.display = false;
     this.mousePosition = null;
+
+    this.start();
   }
 
-  init() {
+  start() {
     if (this.canvas) {
       this.canvas.width = this.canvas.clientWidth;
       this.canvas.height = this.canvas.clientHeight;
@@ -64,7 +63,7 @@ export default class Layer extends mitt {
   }
 
   onMouseDown(e) {
-    if (coordinate.defaultCenter == null) {
+    if (coordinate.center == null) {
       return;
     }
 
@@ -85,7 +84,7 @@ export default class Layer extends mitt {
     const eventName = stateService.getEventName();
     //点击第一次
     if (eventName == LayerEvents.AddRoad) {
-      let flag = this.setNewWallPoint("start", {
+      let flag = this.setNewRoadPoint("start", {
         x: this.startX,
         y: this.startY,
       });
@@ -94,8 +93,8 @@ export default class Layer extends mitt {
       }
     }
     //点击第二次
-    else if (eventName == LayerEvents.AddingWall) {
-      let flag = this.setNewWallPoint(
+    else if (eventName == LayerEvents.AddingRoad) {
+      let flag = this.setNewRoadPoint(
         "end",
         coordinate.getScreenXY(elementService.newWall.end)
       );
@@ -103,7 +102,7 @@ export default class Layer extends mitt {
         return;
       }
       if (addRoad.canAdd) {
-        addRoad.buildRoad(this.uiControl.selectUI == UIEvents.OutWall);
+        addRoad.buildRoad();
         this.history.save();
       } else {
         return;
@@ -163,9 +162,6 @@ export default class Layer extends mitt {
         this.lastX = X;
         this.lastY = Y;
         needAutoRedraw = true;
-        let floorPlanAngle = dataService.getAngle();
-        let info = coordinate.getScreenInfoForCAD();
-        info.floorPlanAngle = floorPlanAngle;
         break;
       case LayerEvents.AddRoad:
         stateService.clearDraggingItem();
@@ -182,7 +178,7 @@ export default class Layer extends mitt {
         elementService.setStartAddWall(position);
         elementService.showStartAddWall();
         break;
-      case LayerEvents.AddingWall:
+      case LayerEvents.AddingRoad:
         stateService.clearDraggingItem();
         stateService.clearFocusItem();
         needAutoRedraw = true;
@@ -198,36 +194,36 @@ export default class Layer extends mitt {
           };
         }
 
-        elementService.execute(startPosition, position);
-        elementService.setStartAddWall(position);
-        if (!elementService.newWall.display) {
-          elementService.setNewWall(startPosition, position);
-          elementService.showNewWall(); //画墙
-        } else {
-          if (!listenLayer.modifyPoint && addRoad.startInfo.linkedPointId) {
-            let newEndPosition = elementService.checkAngle(
-              position,
-              addRoad.startInfo.linkedPointId,
-              null
-            );
-            if (newEndPosition) {
-              mathUtil.clonePoint(position, newEndPosition);
-              elementService.execute(startPosition, position);
-            }
-          }
-          elementService.setNewWallEndPosition(position); //改变end位置
-        }
+        // elementService.execute(startPosition, position);
+        // elementService.setStartAddWall(position);
+        // if (!elementService.newWall.display) {
+        //   elementService.setNewWall(startPosition, position);
+        //   elementService.showNewWall(); //画墙
+        // } else {
+        //   if (!listenLayer.modifyPoint && addRoad.startInfo.linkedPointId) {
+        //     let newEndPosition = elementService.checkAngle(
+        //       position,
+        //       addRoad.startInfo.linkedPointId,
+        //       null
+        //     );
+        //     if (newEndPosition) {
+        //       mathUtil.clonePoint(position, newEndPosition);
+        //       elementService.execute(startPosition, position);
+        //     }
+        //   }
+        //   elementService.setNewWallEndPosition(position); //改变end位置
+        // }
 
         addRoad.canAdd = addRoad.canAddWallForEnd(position);
-        if (!addRoad.canAdd) {
-          elementService.setNewWallState("error");
-        } else {
-          if (this.uiControl.selectUI == UIEvents.OutWall) {
-            elementService.setNewWallState("normal-out");
-          } else {
-            elementService.setNewWallState("normal");
-          }
-        }
+        // if (!addRoad.canAdd) {
+        //   elementService.setNewWallState("error");
+        // } else {
+        //   if (this.uiControl.selectUI == UIEvents.OutWall) {
+        //     elementService.setNewWallState("normal-out");
+        //   } else {
+        //     elementService.setNewWallState("normal");
+        //   }
+        // }
         break;
       case LayerEvents.MoveRoad:
         dx = (dx * Constant.defaultZoom) / coordinate.zoom;
@@ -979,28 +975,6 @@ export default class Layer extends mitt {
     elementService.hideAll();
   }
 
-  setNewWallPoint(dir, position) {
-    if (listenLayer.symbolInfo.state == "select") {
-      return false;
-    }
-    if (dir == "start") {
-      if (listenLayer.modifyPoint) {
-        addRoad.setPointInfo(dir, listenLayer.modifyPoint);
-      } else {
-        addRoad.setPointInfo(dir, coordinate.getXYFromScreen(position));
-      }
-      return true;
-    } else if (dir == "end") {
-      if (listenLayer.modifyPoint) {
-        addRoad.setPointInfo(dir, listenLayer.modifyPoint);
-      } else {
-        addRoad.setPointInfo(dir, coordinate.getXYFromScreen(position));
-      }
-      return true;
-    }
-    return false;
-  }
-
   update() {}
 
   revokeHistory() {

+ 22 - 107
src/graphic/Load.js

@@ -15,115 +15,30 @@ export default class Load {
     this.newVectorId = null;
   }
 
-  load(floors) {
-    for (let i = 0; i < floors.length; ++i) {
-      let floor = floors[i];
-      let subgroup = i;
-      if (floor.hasOwnProperty("subgroup")) {
-        subgroup = floor.subgroup;
-      }
-      dataService.initFloor(subgroup);
-      dataService.setCurrentFloor(subgroup);
-      for (let key in floor.points) {
-        wallService.createPoint(
-          floor.points[key].x,
-          floor.points[key].y,
-          floor.points[key].vectorId,
-          subgroup
-        );
-      }
-
-      for (let key in floor.walls) {
-        let wall = wallService.createWall(
-          floor.walls[key].start,
-          floor.walls[key].end,
-          floor.walls[key].vectorId,
-          subgroup
-        );
-        wall.setImportant(floor.walls[key].important);
-        wall.setOut(floor.walls[key].out);
-        wall.setChildren(floor.walls[key].children);
-      }
-
-      dataService.setFloorHeight(
-        dataService.currentFloor,
-        this.layer.player.model.floors.index[dataService.currentFloor].center.y
+  load(data) {
+    for (let key in floor.walls) {
+      let wall = wallService.createWall(
+        floor.walls[key].start,
+        floor.walls[key].end,
+        floor.walls[key].vectorId,
+        subgroup
       );
-      for (let key in floor.symbols) {
-        let symbol = symbolService.createSymbol(
-          floor.symbols[key].startPoint,
-          floor.symbols[key].endPoint,
-          floor.symbols[key].geoType,
-          floor.symbols[key].parent,
-          floor.symbols[key].vectorId
-        );
-        symbol.openSide = floor.symbols[key].openSide;
-        symbol.enter = floor.symbols[key].enter;
-        symbol.points2d = JSON.parse(
-          JSON.stringify(floor.symbols[key].points2d)
-        );
-      }
-
-      for (let key in floor.components) {
-        let component = componentService.createComponent(
-          floor.components[key].center,
-          floor.components[key].geoType,
-          floor.components[key].vectorId
-        );
-        component.angle = floor.components[key].angle;
-        //component.setPoints2d()
-        component.sideThickness = floor.components[key].sideThickness;
-        component.sideWidth = floor.components[key].sideWidth;
-        component.points2d = JSON.parse(
-          JSON.stringify(floor.components[key].points2d)
-        );
-      }
-
-      if (floor.boundingBox) {
-        dataService.setBoundingBox(floor.boundingBox, subgroup);
-      } else {
-        floor.boundingBox = mathUtil.getBoundingBox2(floor.points);
-        dataService.setBoundingBox(floor.boundingBox, subgroup);
-      }
-
-      for (let key in floor.tags) {
-        let tag = tagService.createTag(
-          floor.tags[key].center,
-          floor.tags[key].vectorId,
-          subgroup
-        );
-        tag.setPoints2d();
-        tag.setTitle(floor.tags[key].title);
-        tag.setDes(floor.tags[key].des);
-        tag.setUnit(floor.tags[key].unit);
-        tag.setAdding(false);
-      }
-
-      for (let key in floor.furnitures) {
-        let furniture = furnitureService.createFurniture(
-          floor.furnitures[key].center,
-          floor.furnitures[key].geoType,
-          floor.furnitures[key].vectorId
-        );
-        furniture.angle = floor.furnitures[key].angle;
-        if (floor.furnitures[key].scale) {
-          furniture.zoom = floor.furnitures[key].scale;
-        } else {
-          furniture.zoom = floor.furnitures[key].zoom;
-        }
-      }
-
-      if (floor.hasOwnProperty("name")) {
-        dataService.setFloorName(floor.name, subgroup);
-      }
-
-      if (floor.hasOwnProperty("subgroup")) {
-        dataService.setFloorSubgroup(floor.subgroup, subgroup);
-      }
+      wall.setImportant(floor.walls[key].important);
+      wall.setOut(floor.walls[key].out);
+      wall.setChildren(floor.walls[key].children);
+    }
 
-      if (floor.hasOwnProperty("id")) {
-        dataService.setFloorId(floor.id, subgroup);
-      }
+    for (let key in floor.tags) {
+      let tag = tagService.createTag(
+        floor.tags[key].center,
+        floor.tags[key].vectorId,
+        subgroup
+      );
+      tag.setPoints2d();
+      tag.setTitle(floor.tags[key].title);
+      tag.setDes(floor.tags[key].des);
+      tag.setUnit(floor.tags[key].unit);
+      tag.setAdding(false);
     }
   }
 

+ 9 - 130
src/graphic/Renderer/Draw.js

@@ -43,149 +43,28 @@ export default class Draw {
     this.context.restore();
   }
 
-  // setSVGAttr(svgId,width,height){
-
-  // }
-
-  drawWall(vector, styleType) {
-    let start = dataService.getPoint(vector.start);
-    let end = dataService.getPoint(vector.end);
-
-    let points = [];
-    points.push(start);
-    for (let i = 0; i < vector.children.length; ++i) {
-      let symbol = dataService.getSymbol(vector.children[i]);
-      points.push(symbol.startPoint);
-      points.push(symbol.endPoint);
-    }
-    points.push(end);
-
-    points = points.sort(sortNumber.bind(this));
-    function sortNumber(a, b) {
-      return mathUtil.getDistance(start, a) - mathUtil.getDistance(start, b);
-    }
+  drawRoad(vector) {
+    let start = dataService.getPoint(vector.startId);
+    let end = dataService.getPoint(vector.endId);
 
     this.context.save();
     this.context.beginPath();
     this.context.lineCap = "round"; //线段端点的样式
     //this.context.lineJoin= 'miter';
     this.context.strokeStyle = Style.Wall.strokeStyle;
-
-    if (vector.out || vector.important) {
-      this.context.lineWidth =
-        Style.Wall.important.lineWidth * coordinate.ratio;
-      this.context.strokeStyle = Style.Wall.important.strokeStyle;
-    } else {
-      this.context.lineWidth = Style.Wall.lineWidth * coordinate.ratio;
-      this.context.strokeStyle = Style.Wall.strokeStyle;
-    }
+    this.context.lineWidth = vector.width;
+    this.context.strokeStyle = Style.Wall.strokeStyle;
 
     const selectItem = stateService.getSelectItem();
     const draggingItem = stateService.getDraggingItem();
     const focusItem = stateService.getFocusItem();
 
-    //下载的时候,根据样式
-    if (styleType) {
-      if (styleType == "style-1") {
-        if (vector.out || vector.important) {
-          this.context.lineWidth =
-            Style.DownLoad.style1.Wall.important.lineWidth * coordinate.ratio;
-          this.context.strokeStyle =
-            Style.DownLoad.style1.Wall.important.strokeStyle;
-        } else {
-          this.context.lineWidth =
-            Style.DownLoad.style1.Wall.lineWidth * coordinate.ratio;
-          this.context.strokeStyle = Style.DownLoad.style1.Wall.strokeStyle;
-        }
-      } else if (styleType == "style-2") {
-        if (vector.out || vector.important) {
-          this.context.lineWidth =
-            Style.DownLoad.style2.Wall.important.lineWidth * coordinate.ratio;
-          this.context.strokeStyle =
-            Style.DownLoad.style2.Wall.important.strokeStyle;
-        } else {
-          this.context.lineWidth =
-            Style.DownLoad.style2.Wall.lineWidth * coordinate.ratio;
-          this.context.strokeStyle = Style.DownLoad.style2.Wall.strokeStyle;
-        }
-      } else if (styleType == "style-3") {
-        if (vector.out || vector.important) {
-          this.context.lineWidth =
-            Style.DownLoad.style3.Wall.important.lineWidth * coordinate.ratio;
-          this.context.strokeStyle =
-            Style.DownLoad.style3.Wall.important.strokeStyle;
-        } else {
-          this.context.lineWidth =
-            Style.DownLoad.style3.Wall.lineWidth * coordinate.ratio;
-          this.context.strokeStyle = Style.DownLoad.style3.Wall.strokeStyle;
-        }
-      } else if (styleType == "style-4") {
-        if (vector.out || vector.important) {
-          this.context.lineWidth =
-            Style.DownLoad.style4.Wall.important.lineWidth * coordinate.ratio;
-          this.context.strokeStyle =
-            Style.DownLoad.style4.Wall.important.strokeStyle;
-        } else {
-          this.context.lineWidth =
-            Style.DownLoad.style4.Wall.lineWidth * coordinate.ratio;
-          this.context.strokeStyle = Style.DownLoad.style4.Wall.strokeStyle;
-        }
-      }
-    } else {
-      if (selectItem && selectItem.type == VectorType.Wall) {
-        if (vector.vectorId == selectItem.vectorId) {
-          if (vector.out || vector.important) {
-            this.context.strokeStyle = Style.Select.Wall_out.strokeStyle;
-          } else {
-            this.context.strokeStyle = Style.Select.Wall.strokeStyle;
-          }
-        }
-      } else if (draggingItem && draggingItem.type == VectorType.Wall) {
-        if (vector.vectorId == draggingItem.vectorId) {
-          if (vector.out || vector.important) {
-            this.context.strokeStyle = Style.Select.Wall_out.strokeStyle;
-          } else {
-            this.context.strokeStyle = Style.Select.Wall.strokeStyle;
-          }
-        }
-      }
-
-      if (focusItem && focusItem.type == VectorType.Wall) {
-        if (vector.vectorId == focusItem.vectorId) {
-          this.context.strokeStyle = Style.Focus.Wall.strokeStyle;
-        }
-      }
-    }
-
-    for (let i = 0; i < points.length - 1; i += 2) {
-      let point1 = coordinate.getScreenXY(points[i]);
-      let point2 = coordinate.getScreenXY(points[i + 1]);
-      this.context.moveTo(point1.x, point1.y);
-      this.context.lineTo(point2.x, point2.y);
-    }
+    let point1 = coordinate.getScreenXY(start);
+    let point2 = coordinate.getScreenXY(end);
+    this.context.moveTo(point1.x, point1.y);
+    this.context.lineTo(point2.x, point2.y);
     this.context.stroke();
     this.context.restore();
-
-    // const mid = {
-    //     x: (start.x + end.x) / 2,
-    //     y: (start.y + end.y) / 2,
-    // }
-    // this.drawText(mid, vector.vectorId)
-
-    if (
-      (selectItem &&
-        selectItem.type == VectorType.Wall &&
-        vector.vectorId == selectItem.vectorId) ||
-      (draggingItem &&
-        draggingItem.type == VectorType.Wall &&
-        vector.vectorId == draggingItem.vectorId) ||
-      (focusItem &&
-        focusItem.type == VectorType.Wall &&
-        vector.vectorId == focusItem.vectorId)
-    ) {
-      //添加测量值
-      this.drawMeasureTxt(start, end);
-    }
   }
 
   drawSpecialPoint() {

+ 19 - 0
src/graphic/Service/RoadService.js

@@ -500,6 +500,25 @@ export default class RoadService {
     }
     return true;
   }
+
+  setNewRoadPoint(dir, position) {
+    if (dir == "start") {
+      if (listenLayer.modifyPoint) {
+        addRoad.setPointInfo(dir, listenLayer.modifyPoint);
+      } else {
+        addRoad.setPointInfo(dir, coordinate.getXYFromScreen(position));
+      }
+      return true;
+    } else if (dir == "end") {
+      if (listenLayer.modifyPoint) {
+        addRoad.setPointInfo(dir, listenLayer.modifyPoint);
+      } else {
+        addRoad.setPointInfo(dir, coordinate.getXYFromScreen(position));
+      }
+      return true;
+    }
+    return false;
+  }
 }
 
 const roadService = new RoadService();

+ 5 - 0
src/graphic/Service/StateService.js

@@ -87,6 +87,11 @@ export default class StateService {
     this.focusItem = null;
     this.draggingItem = null;
   }
+
+  clear() {
+    this.clearItems();
+    this.clearEventName();
+  }
 }
 
 const stateService = new StateService();