Forráskód Böngészése

增加绘制设备名称;处理删除设备后对关系item的影响

haojianlong 5 éve
szülő
commit
ef7fd36e10
6 módosított fájl, 102 hozzáadás és 32 törlés
  1. 1 1
      package.json
  2. 15 11
      src/TopoScene.ts
  3. 3 2
      src/index.ts
  4. 6 0
      src/items/EquipItem.ts
  5. 45 18
      src/items/RelationItem.ts
  6. 32 0
      src/types/GraphyData.ts

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/topology",
-    "version": "1.0.76",
+    "version": "1.0.77",
     "description": "上格云拓扑图引擎",
     "main": "lib/index.js",
     "types": "lib/index.d.js",

+ 15 - 11
src/TopoScene.ts

@@ -28,6 +28,7 @@ import { Anchor } from "./types/Anchor";
 import { SMathUtil } from "./util/SMathUtil";
 import { SPoint } from "@saga-web/draw/lib";
 import { AnchorItem } from "./items/AnchorItem";
+import { GraphyData } from "./types/GraphyData";
 
 /**
  * 拓扑图场景
@@ -86,7 +87,14 @@ export class TopoScene extends SGraphyScene {
     /** 当前关系item    */
     relatItem: RelationItem | null = null;
     /** */
-    loadData() {} // Function loadData()
+    loadData(data: GraphyData): void {
+        if (data.equipList && data.equipList.length) {
+            this.addAllEquip(data.equipList);
+        }
+        if (data.relationList && data.relationList.length) {
+            this.addAllRelation(data.relationList);
+        }
+    } // Function loadData()
 
     /**
      * 添加所有设备item
@@ -228,9 +236,10 @@ export class TopoScene extends SGraphyScene {
      * 根据点击设备创建对应item
      *
      * */
-    createItem(data: Equip): void {
+    createItem(data: Equip): SGraphyItem {
         this.isAdding = true;
         this.grabItem = new EquipItem(null, data);
+        return this.grabItem;
     } // Function createItem()
 
     /**
@@ -291,15 +300,10 @@ export class TopoScene extends SGraphyScene {
     } // Function clickIsAnchor()
 
     /**
-     *  根据两点生成折点数据
+     *  绑定设备右键事件
      *
-     *  @param  p1  锚点1
-     *  @param  p2  锚点2
-     *  @return p1到p2折点路径
-     * */
-    pointsToList(p1: Anchor, p2: Anchor): SPoint[] {
-        let arr = [p1];
-        arr.push(p2);
-        return [];
+     */
+    click(item: SGraphyItem, fn: Function) {
+        item.connect("ContextMenu", this, fn);
     }
 } // Class TopoScene

+ 3 - 2
src/index.ts

@@ -1,4 +1,5 @@
 import { TopoView } from "./TopoView";
 import { TopoScene } from "./TopoScene";
-
-export { TopoView, TopoScene };
+import { RelationItem } from "./items/RelationItem";
+import { EquipItem } from "./items/EquipItem";
+export { TopoView, TopoScene, EquipItem, RelationItem };

+ 6 - 0
src/items/EquipItem.ts

@@ -97,6 +97,7 @@ export class EquipItem extends SGraphyItem {
             this.Img.src = data.ImgSource;
         }
         this.data = data;
+        this.name = data.Name || "";
         this.moveable = true;
         this.zOrder = ItemOrder.EquipOrder;
         this.update();
@@ -163,5 +164,10 @@ export class EquipItem extends SGraphyItem {
                 this.height
             );
         }
+        if (this.name) {
+            painter.brush.color = SColor.Black;
+            painter.font.size = 12;
+            painter.drawText(this.name, -20, this.height / 2);
+        }
     } // Function onDraw()
 } // Class EquipItem

+ 45 - 18
src/items/RelationItem.ts

@@ -151,6 +151,25 @@ export class RelationItem extends BaseRelationItem {
     } // Function onKeyUp()
 
     /**
+     * 鼠标右键事件
+     *
+     * @param	event         事件参数
+     * @return	boolean
+     */
+    onContextMenu(event: SMouseEvent): boolean {
+        this.$emit("ContextMenu", event);
+        return true;
+    } // Function onContextMenu()
+
+    /**
+     *
+     *
+     */
+    contains(x: number, y: number): boolean {
+        return false;
+    }
+
+    /**
      * 根据点计算出折线点
      *
      */
@@ -166,29 +185,37 @@ export class RelationItem extends BaseRelationItem {
     change(): void {
         if (this.pointList.length) {
             if (this.Anchor1) {
-                this.pointList[0] = this.Anchor1.mapToScene(
-                    this.Anchor1.X,
-                    this.Anchor1.Y
-                );
-                if (this.pointList[1] && this.pointList[2]) {
-                    this.pointList[1] = this.getPoint(
-                        this.pointList[0],
-                        this.pointList[2]
+                // 判断删除equip后,不移动
+                if (this.Anchor1.parent && this.Anchor1.parent.parent) {
+                    this.pointList[0] = this.Anchor1.mapToScene(
+                        this.Anchor1.X,
+                        this.Anchor1.Y
                     );
+                    if (this.pointList[1] && this.pointList[2]) {
+                        this.pointList[1] = this.getPoint(
+                            this.pointList[0],
+                            this.pointList[2]
+                        );
+                    }
                 }
             }
             if (this.Anchor2) {
-                this.pointList[
-                    this.pointList.length - 1
-                ] = this.Anchor2.mapToScene(this.Anchor2.X, this.Anchor2.Y);
-                if (
-                    this.pointList[this.pointList.length - 1] &&
-                    this.pointList[this.pointList.length - 3]
-                ) {
-                    this.pointList[this.pointList.length - 2] = this.getPoint(
-                        this.pointList[this.pointList.length - 1],
+                // 删除equip后
+                if (this.Anchor2.parent && this.Anchor2.parent.parent) {
+                    this.pointList[
+                        this.pointList.length - 1
+                    ] = this.Anchor2.mapToScene(this.Anchor2.X, this.Anchor2.Y);
+                    if (
+                        this.pointList[this.pointList.length - 1] &&
                         this.pointList[this.pointList.length - 3]
-                    );
+                    ) {
+                        this.pointList[
+                            this.pointList.length - 2
+                        ] = this.getPoint(
+                            this.pointList[this.pointList.length - 1],
+                            this.pointList[this.pointList.length - 3]
+                        );
+                    }
                 }
             }
         }

+ 32 - 0
src/types/GraphyData.ts

@@ -0,0 +1,32 @@
+/*
+ * ********************************************************************************************************************
+ *
+ *                      :*$@@%$*:                         ;:                ;;    ;;
+ *                    :@@%!  :!@@%:                       %!             ;%%@@%$ =@@@@@@@%;     @%@@@%%%%@@@@@
+ *                   :@%;       :$=                       %%$$$%$$         ;$$  ;$@=   !@$
+ *                   =@!                                  %!              @ $=;%   !@@@%:      !$$$$$$$$$$$$$$=
+ *                   =@*                                  %!              @ $= % %@=   =%@!      %=
+ *              *$%%! @@=        ;=$%%%$*:                %!              @ $= % =%%%%%%@$      *%:         =%
+ *            %@@!:    !@@@%=$@@@@%!  :*@@$:              %!              @ $= % $*     ;@      @*          :%*
+ *          ;@@!          ;!!!;:         ;@%:      =======@%========*     @ $$ % $%*****$@     :@$=*********=@$
+ *          $@*   ;@@@%=!:                *@*
+ *          =@$    ;;;!=%@@@@=!           =@!
+ *           %@$:      =@%: :*@@@*       %@=                    Copyright (c) 2016-2020.  北京上格云技术有限公司
+ *            ;%@@$=$@@%*       *@@@$=%@@%;
+ *               ::;::             ::;::                                              All rights reserved.
+ *
+ * ********************************************************************************************************************
+ */
+
+import { Equip } from "./Equip";
+import { Relation } from "./Relation";
+
+/**
+ * 设备item接口
+ *
+ * @author  郝建龙
+ */
+export interface GraphyData {
+    equipList: Equip[];
+    relationList: Relation[];
+} // Interface GraphyData