haojianlong 5 лет назад
Родитель
Сommit
e934e4cfb9

+ 2 - 2
package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/topology",
-    "version": "1.0.0",
+    "version": "1.0.62",
     "description": "上格云拓扑图引擎",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -33,7 +33,7 @@
     "dependencies": {
         "@saga-web/base": "2.1.9",
         "@saga-web/draw": "2.1.75",
-        "@saga-web/graphy": "2.1.42",
+        "@saga-web/graphy": "2.1.45",
         "axios": "^0.18.0",
         "pako": "^1.0.10",
         "poly-decomp": "^0.3.0",

+ 196 - 1
src/TopoScene.ts

@@ -18,12 +18,17 @@
  * ********************************************************************************************************************
  */
 
-import { SGraphyScene } from "@saga-web/graphy/lib";
+import { SGraphyItem, SGraphyScene } from "@saga-web/graphy/lib";
 import Axios from "axios";
 import { Equip } from "./types/Equip";
 import { Relation } from "./types/Relation";
 import { EquipItem } from "./items/EquipItem";
 import { RelationItem } from "./items/RelationItem";
+import { SMouseEvent } from "@saga-web/base/lib";
+import { Anchor } from "./types/Anchor";
+import { SMathUtil } from "./util/SMathUtil";
+import { SPoint } from "@saga-web/draw/lib";
+import { AnchorItem } from "./items/AnchorItem";
 
 /**
  * 拓扑图场景
@@ -35,6 +40,8 @@ export class TopoScene extends SGraphyScene {
     EquipList: EquipItem[] = [];
     /** 所有关系item    */
     RelationList: RelationItem[] = [];
+    /** 所有锚点    */
+    AnchorList: AnchorItem[] = [];
     /** 设备是否隐藏  */
     _isShowEquip: boolean = true;
     get isShowEquip(): boolean {
@@ -71,6 +78,14 @@ export class TopoScene extends SGraphyScene {
         );
     } // Set isShowEquip
 
+    /** 添加item状态    */
+    isAdding: boolean = false;
+    /** 划线状态    */
+    isLining: boolean = false;
+
+    /** 当前关系item    */
+    relatItem: RelationItem | null = null;
+    /** */
     loadData() {} // Function loadData()
 
     /**
@@ -84,15 +99,42 @@ export class TopoScene extends SGraphyScene {
             });
         }
     } // Function addAllEquip()
+
     /**
      *  添加设备item
      */
     addEquip(equip: Equip): void {
         let item = new EquipItem(null, equip);
+        item.moveTo(equip.Pos.X, equip.Pos.Y);
         item.visible = this.isShowEquip;
         this.EquipList.push(item);
+        if (equip.AnchorList.length) {
+            this.addAllAnchor(item, equip.AnchorList);
+        }
         this.addItem(item);
     } // Function addEquip()
+
+    /**
+     * 添加单个设备item的锚点
+     *
+     */
+    addAllAnchor(parent: SGraphyItem, list: Anchor[]): void {
+        if (list.length) {
+            list.forEach(t => {
+                this.addAnchor(parent, t);
+            });
+        }
+    } // Function addAllAnchor()
+
+    /**
+     *  添加设备item的锚点
+     */
+    addAnchor(parent: SGraphyItem, anchor: Anchor): void {
+        let item = new AnchorItem(parent, anchor);
+        item.visible = this.isShowEquip;
+        this.AnchorList.push(item);
+    } // Function addAnchor()
+
     /**
      * 添加所有设备item
      *
@@ -104,6 +146,7 @@ export class TopoScene extends SGraphyScene {
             });
         }
     } // Function addAllRelation()
+
     /**
      *  添加设备item
      */
@@ -113,4 +156,156 @@ export class TopoScene extends SGraphyScene {
         this.RelationList.push(item);
         this.addItem(item);
     } // Function addRelation()
+
+    /**
+     *  点击事件
+     *
+     */
+    onMouseDown(event: SMouseEvent): boolean {
+        console.log("mousedown");
+        if (this.isAdding) {
+            this.addSelectItem(event);
+        } else if (this.isLining) {
+            let anc = this.clickIsAnchor(event);
+            if (anc) {
+                // 点击的是锚点,直接处理添加到关系item点数据中
+                let ancPoint = anc.mapToScene(anc.X, anc.Y);
+                if (this.relatItem) {
+                    console.log("第二次点击锚点");
+                    this.relatItem.Anchor2 = anc;
+                    if (anc.parent) {
+                        anc.parent.connect(
+                            "changePos",
+                            this.relatItem,
+                            this.relatItem.change
+                        );
+                    }
+                    this.relatItem.onMouseDown(event);
+                    this.isLining = false;
+                    this.relatItem = null;
+                    this.grabItem = null;
+                } else {
+                    let data = {
+                        Anchor1: anc
+                    };
+                    let item = new RelationItem(null, data);
+                    this.addItem(item);
+                    if (anc.parent) {
+                        anc.parent.connect("changePos", item, item.change);
+                    }
+                    this.RelationList.push(item);
+                    this.relatItem = item;
+                    this.grabItem = item;
+                }
+            } else {
+                console.log("未点击锚点");
+                // 点击的不是锚点,处理点击点与
+                // if (this.grabItem) {
+                //     this.grabItem.onMouseDown(event);
+                // }
+            }
+        } else {
+            super.onMouseDown(event);
+        }
+        return false;
+    } // Function onClick
+
+    /**
+     *  点击事件
+     *
+     */
+    onMouseMove(event: SMouseEvent): boolean {
+        if (this.isLining && this.relatItem) {
+            this.relatItem.onMouseMove(event);
+        } else {
+            super.onMouseMove(event);
+        }
+        return false;
+    }
+
+    /**
+     * 根据点击设备创建对应item
+     *
+     * */
+    createItem(data: Equip): void {
+        this.isAdding = true;
+        this.grabItem = new EquipItem(null, data);
+    } // Function createItem()
+
+    /**
+     * 根据当前选中的item添加到场景
+     *
+     * @param event 点击事件
+     * @return 是否添加成功
+     * */
+    addSelectItem(event: SMouseEvent): boolean {
+        if (this.grabItem && this.grabItem instanceof EquipItem) {
+            // @ts-ignore
+            this.grabItem.data.Pos = {};
+            // @ts-ignore
+            this.grabItem.data.Pos.X = event.x;
+            // @ts-ignore
+            this.grabItem.data.Pos.Y = event.y;
+            this.grabItem.moveTo(event.x, event.y);
+            this.addItem(this.grabItem);
+            this.EquipList.push(this.grabItem);
+            if (this.grabItem.data && this.grabItem.data.AnchorList.length) {
+                this.addAllAnchor(this.grabItem, this.grabItem.data.AnchorList);
+            }
+            this.isAdding = false;
+            this.grabItem = null;
+            return true;
+        }
+        return false;
+    } // Function addSelectItem()
+
+    /**
+     *  划线时点击位置是否是锚点
+     *
+     *  @param  event   事件
+     *  @param  len     限制距离
+     *  @return 点击的锚点
+     * */
+    clickIsAnchor(event: SMouseEvent, len: number = 100): AnchorItem | null {
+        let minAnchor = null;
+        if (this.view) {
+            len = 100 / this.view.scale;
+        }
+        this.AnchorList.forEach(anchor => {
+            if (anchor.data) {
+                let anchorPoint = anchor.mapToScene(anchor.X, anchor.Y);
+                let dis = SMathUtil.pointDistance(
+                    event.x,
+                    event.y,
+                    anchorPoint.x,
+                    anchorPoint.y
+                );
+                if (dis < len) {
+                    minAnchor = anchor;
+                    len = dis;
+                }
+            }
+        });
+        return minAnchor;
+    } // Function clickIsAnchor()
+
+    /**
+     * 设备item位置改变时,触发修改relation连线
+     */
+    changeEquipPos(){
+
+    } // Function changeEquipPos()
+
+    /**
+     *  根据两点生成折点数据
+     *
+     *  @param  p1  锚点1
+     *  @param  p2  锚点2
+     *  @return p1到p2折点路径
+     * */
+    pointsToList(p1: Anchor, p2: Anchor): SPoint[] {
+        let arr = [p1];
+        arr.push(p2);
+        return [];
+    }
 } // Class TopoScene

src/index.js → src/index.ts


+ 81 - 0
src/items/AnchorItem.ts

@@ -0,0 +1,81 @@
+/*
+ * ********************************************************************************************************************
+ *
+ *                      :*$@@%$*:                         ;:                ;;    ;;
+ *                    :@@%!  :!@@%:                       %!             ;%%@@%$ =@@@@@@@%;     @%@@@%%%%@@@@@
+ *                   :@%;       :$=                       %%$$$%$$         ;$$  ;$@=   !@$
+ *                   =@!                                  %!              @ $=;%   !@@@%:      !$$$$$$$$$$$$$$=
+ *                   =@*                                  %!              @ $= % %@=   =%@!      %=
+ *              *$%%! @@=        ;=$%%%$*:                %!              @ $= % =%%%%%%@$      *%:         =%
+ *            %@@!:    !@@@%=$@@@@%!  :*@@$:              %!              @ $= % $*     ;@      @*          :%*
+ *          ;@@!          ;!!!;:         ;@%:      =======@%========*     @ $$ % $%*****$@     :@$=*********=@$
+ *          $@*   ;@@@%=!:                *@*
+ *          =@$    ;;;!=%@@@@=!           =@!
+ *           %@$:      =@%: :*@@@*       %@=                    Copyright (c) 2016-2020.  北京上格云技术有限公司
+ *            ;%@@$=$@@%*       *@@@$=%@@%;
+ *               ::;::             ::;::                                              All rights reserved.
+ *
+ * ********************************************************************************************************************
+ */
+
+import { SGraphyItem } from "@saga-web/graphy/lib";
+import { SColor, SPainter, SPoint, SRect } from "@saga-web/draw/lib";
+import { Anchor } from "../types/Anchor";
+
+/**
+ * 关系item-折线画法-横平竖直
+ *
+ * @author  郝建龙
+ */
+export class AnchorItem extends SGraphyItem {
+    /** 所有数据    */
+    data: Anchor | null = null;
+    /** 相对于父级的x坐标   */
+    X: number;
+    /** 相对于父级的y坐标   */
+    Y: number;
+    /** 宽度  */
+    Width: number = 10;
+    /** 高度  */
+    Height: number = 10;
+    /** */
+
+    /**
+     * 构造函数
+     *
+     * @param parent    指向父对象
+     * @param data      Relation数据
+     */
+    constructor(parent: SGraphyItem | null, data: Anchor) {
+        super(parent);
+        this.data = data;
+        this.X = data.Pos.X;
+        this.Y = data.Pos.Y;
+        if (data.Width) {
+            this.Width = data.Width;
+        }
+        if (data.Height) {
+            this.Height = data.Height;
+        }
+        if (parent) {
+            this.zOrder = parent.zOrder + 1;
+        }
+    } // Constructor
+
+    /**
+     * Item绘制操作
+     *
+     * @param   painter       painter对象
+     */
+    onDraw(painter: SPainter): void {
+        painter.pen.lineWidth = 2;
+        painter.brush.color = SColor.White;
+        painter.pen.color = new SColor("#409EFF");
+        painter.drawRect(
+            this.X - this.Width / 2,
+            this.Y - this.Height / 2,
+            this.Width,
+            this.Height
+        );
+    } // Function onDraw()
+} // Class RelationItem

+ 54 - 0
src/items/BaseRelationItem.ts

@@ -0,0 +1,54 @@
+/*
+ * ********************************************************************************************************************
+ *
+ *                      :*$@@%$*:                         ;:                ;;    ;;
+ *                    :@@%!  :!@@%:                       %!             ;%%@@%$ =@@@@@@@%;     @%@@@%%%%@@@@@
+ *                   :@%;       :$=                       %%$$$%$$         ;$$  ;$@=   !@$
+ *                   =@!                                  %!              @ $=;%   !@@@%:      !$$$$$$$$$$$$$$=
+ *                   =@*                                  %!              @ $= % %@=   =%@!      %=
+ *              *$%%! @@=        ;=$%%%$*:                %!              @ $= % =%%%%%%@$      *%:         =%
+ *            %@@!:    !@@@%=$@@@@%!  :*@@$:              %!              @ $= % $*     ;@      @*          :%*
+ *          ;@@!          ;!!!;:         ;@%:      =======@%========*     @ $$ % $%*****$@     :@$=*********=@$
+ *          $@*   ;@@@%=!:                *@*
+ *          =@$    ;;;!=%@@@@=!           =@!
+ *           %@$:      =@%: :*@@@*       %@=                    Copyright (c) 2016-2020.  北京上格云技术有限公司
+ *            ;%@@$=$@@%*       *@@@$=%@@%;
+ *               ::;::             ::;::                                              All rights reserved.
+ *
+ * ********************************************************************************************************************
+ */
+
+import { SGraphyItem } from "@saga-web/graphy/lib";
+import { SPainter, SPoint, SRect } from "@saga-web/draw/lib";
+import { Relation } from "../types/Relation";
+import { SMouseEvent } from "@saga-web/base/lib";
+
+/**
+ * 关系item
+ *
+ * @author  郝建龙
+ */
+export class BaseRelationItem extends SGraphyItem {
+    /** X坐标最小值  */
+    minX = Number.MAX_SAFE_INTEGER;
+    /** X坐标最大值  */
+    maxX = Number.MIN_SAFE_INTEGER;
+    /** Y坐标最小值  */
+    minY = Number.MAX_SAFE_INTEGER;
+    /** Y坐标最大值  */
+    maxY = Number.MIN_SAFE_INTEGER;
+
+    /**
+     * Item对象边界区域
+     *
+     * @return SRect
+     */
+    boundingRect(): SRect {
+        return new SRect(
+            this.minX,
+            this.minY,
+            this.maxX - this.minX,
+            this.maxY - this.minY
+        );
+    } // Function boundingRect()
+} // Class BaseRelationItem

+ 32 - 29
src/items/EquipItem.ts

@@ -22,6 +22,7 @@ import { SGraphyItem } from "@saga-web/graphy/lib";
 import { SColor, SPainter, SPoint, SRect } from "@saga-web/draw/lib";
 import { SMouseEvent } from "@saga-web/base/lib";
 import { Equip } from "../types/Equip";
+import { Point } from "../types/Point";
 
 /**
  * 柱子item
@@ -37,8 +38,11 @@ export class EquipItem extends SGraphyItem {
     } // Get width
     set width(v: number) {
         this._width = v;
-        this.minX = this.pos.x - v / 2;
-        this.maxX = this.pos.x + v / 2;
+        if (this.data) {
+            this.data.Size.Width = v;
+        }
+        // this.minX = this.pos.x - v / 2;
+        // this.maxX = this.pos.x + v / 2;
         this.update();
     } // Set width
     /** 高度  */
@@ -49,20 +53,13 @@ export class EquipItem extends SGraphyItem {
     } // Get width
     set height(v: number) {
         this._height = v;
-        this.minY = this.pos.y - v / 2;
-        this.maxY = this.pos.y + v / 2;
+        if (this.data) {
+            this.data.Size.Height = v;
+        }
         this.update();
     } // Set width
     /** 设备数据    */
     data: Equip | null = null;
-    /** X坐标最小值  */
-    private minX = Number.MAX_SAFE_INTEGER;
-    /** X坐标最大值  */
-    private maxX = Number.MIN_SAFE_INTEGER;
-    /** Y坐标最小值  */
-    private minY = Number.MAX_SAFE_INTEGER;
-    /** Y坐标最大值  */
-    private maxY = Number.MIN_SAFE_INTEGER;
     /** 位置 */
     pos: SPoint = new SPoint(0, 0);
     /** X轴坐标 */
@@ -71,8 +68,7 @@ export class EquipItem extends SGraphyItem {
     } // Get x
     set x(v: number) {
         this.pos.x = v;
-        this.minX = v - this.width / 2;
-        this.maxX = v + this.width / 2;
+        this.$emit("changePos");
         this.update();
     } // Set x
     /** Y轴坐标 */
@@ -81,21 +77,21 @@ export class EquipItem extends SGraphyItem {
     } // Get y
     set y(v: number) {
         this.pos.y = v;
-        this.minY = v - this.height / 2;
-        this.maxY = v + this.height / 2;
+        this.$emit("changePos");
         this.update();
     } // Set y
 
     constructor(parent: SGraphyItem | null, data: Equip) {
         super(parent);
-        if (data.width) {
-            this.width = data.width;
+        if (data.Size.Width) {
+            this.width = data.Size.Width;
         }
-        if (data.height) {
-            this.height = data.height;
+        if (data.Size.Height) {
+            this.height = data.Size.Height;
         }
         this.data = data;
-        this.pos = data.pos;
+        this.moveable = true;
+        this.update();
     } // Constructor
 
     /**
@@ -105,24 +101,25 @@ export class EquipItem extends SGraphyItem {
      */
     boundingRect(): SRect {
         return new SRect(
-            this.minX,
-            this.minY,
-            this.maxX - this.minX,
-            this.maxY - this.minY
+            -this.width / 2,
+            -this.height / 2,
+            this.width,
+            this.height
         );
     } // Function boundingRect()
 
     /**
-     *  点击事件
+     *  鼠标按下事件
      *
      */
-    onClick(event: SMouseEvent): boolean {
+    onMouseDown(event: SMouseEvent): boolean {
         if (this.selectable) {
             this.selected = !this.selected;
         }
         this.$emit("click", event);
+        super.onMouseDown(event);
         return true;
-    } // Function onClick
+    } // Function onMouseDown
 
     /**
      * Item绘制操作
@@ -130,6 +127,12 @@ export class EquipItem extends SGraphyItem {
      * @param   painter       painter对象
      */
     onDraw(painter: SPainter): void {
-        painter.drawRect(this.minX, this.minY, this.width, this.height);
+        painter.brush.color = SColor.White;
+        painter.drawRect(
+            -this.width / 2,
+            -this.height / 2,
+            this.width,
+            this.height
+        );
     } // Function onDraw()
 } // Class EquipItem

+ 129 - 45
src/items/RelationItem.ts

@@ -19,76 +19,155 @@
  */
 
 import { SGraphyItem } from "@saga-web/graphy/lib";
-import { SPainter, SPoint, SRect } from "@saga-web/draw/lib";
+import { SColor, SPainter, SPoint, SRect } from "@saga-web/draw/lib";
 import { Relation } from "../types/Relation";
 import { SMouseEvent } from "@saga-web/base/lib";
+import { BaseRelationItem } from "./BaseRelationItem";
+import { AnchorItem } from "./AnchorItem";
 
 /**
- * 关系item
+ * 关系item-折线画法-横平竖直
  *
  * @author  郝建龙
  */
-export class RelationItem extends SGraphyItem {
+export class RelationItem extends BaseRelationItem {
     /** 关系数据    */
     data: Relation | null = null;
     /** 折点信息    */
     pointList: SPoint[] = [];
-    /** X坐标最小值  */
-    private minX = Number.MAX_SAFE_INTEGER;
-    /** X坐标最大值  */
-    private maxX = Number.MIN_SAFE_INTEGER;
-    /** Y坐标最小值  */
-    private minY = Number.MAX_SAFE_INTEGER;
-    /** Y坐标最大值  */
-    private maxY = Number.MIN_SAFE_INTEGER;
-
+    /** 尾端折点3   */
+    lastPointList: SPoint[] = [];
+    /** 是否结束    */
+    closeFlag = false;
+    //
+    Anchor1: AnchorItem | null = null;
+    //
+    Anchor2: AnchorItem | null = null;
+    /**
+     * 构造函数
+     *
+     * @param parent    指向父对象
+     * @param data      Relation数据
+     */
     constructor(parent: SGraphyItem | null, data: Relation) {
         super(parent);
         this.data = data;
-        this.pointList = data.pointList;
-        data.pointList.forEach(it => {
-            let x = it.x,
-                y = it.y;
-            if (x < this.minX) {
-                this.minX = x;
-            }
-            if (y < this.minY) {
-                this.minY = y;
-            }
-            if (x > this.maxX) {
-                this.maxX = x;
-            }
-            if (y > this.maxY) {
-                this.maxY = y;
+        this.Anchor1 = data.Anchor1 || null;
+        this.Anchor2 = data.Anchor2 || null;
+        if (data.PointList) {
+            this.pointList = data.PointList.map(it => {
+                let x = it.X,
+                    y = it.Y;
+                if (x < this.minX) {
+                    this.minX = x;
+                }
+                if (y < this.minY) {
+                    this.minY = y;
+                }
+                if (x > this.maxX) {
+                    this.maxX = x;
+                }
+                if (y > this.maxY) {
+                    this.maxY = y;
+                }
+                return new SPoint(x, y);
+            });
+        } else {
+            if (this.Anchor1) {
+                this.pointList.push(
+                    this.Anchor1.mapToScene(this.Anchor1.X, this.Anchor1.Y)
+                );
+                this.lastPointList = [
+                    this.Anchor1.mapToScene(this.Anchor1.X, this.Anchor1.Y)
+                ];
             }
-        });
+        }
     } // Constructor
 
     /**
-     * Item对象边界区域
+     * 鼠标按下事件
      *
-     * @return SRect
+     * @param	event         事件参数
+     * @return	boolean
      */
-    boundingRect(): SRect {
-        return new SRect(
-            this.minX,
-            this.minY,
-            this.maxX - this.minX,
-            this.maxY - this.minY
-        );
-    } // Function boundingRect()
+    onMouseDown(event: SMouseEvent): boolean {
+        if (!this.closeFlag && event.buttons == 1) {
+            if (this.lastPointList.length > 1) {
+                for (let i = 1; i < this.lastPointList.length; i++) {
+                    this.pointList.push(this.lastPointList[i]);
+                }
+            }
+        }
+        if (this.Anchor2) {
+            this.closeFlag = true;
+        }
+        this.update();
+        return true;
+    } // Function onMouseDown()
 
     /**
-     *  点击事件
+     * 鼠标移动事件
      *
+     * @param	event         事件参数
+     * @return	boolean
      */
-    onClick(event: SMouseEvent): boolean {
-        if (this.selectable) {
-            this.selected = !this.selected;
+    onMouseMove(event: SMouseEvent): boolean {
+        if (this.pointList.length) {
+            this.lastPointList = [
+                this.pointList[this.pointList.length - 1],
+                this.getPoint(
+                    this.pointList[this.pointList.length - 1],
+                    new SPoint(event.x, event.y)
+                ),
+                new SPoint(event.x, event.y)
+            ];
         }
-        this.$emit("click", event);
+        this.update();
         return true;
-    } // Function onClick
+    } // Function onMouseMove()
+
+    /***
+     * 键盘按键弹起事件
+     *
+     * @param	event         事件参数
+     */
+    onKeyUp(event: KeyboardEvent): void {
+        if (event.keyCode == 13) {
+            this.closeFlag = true;
+        }
+    } // Function onKeyUp()
+
+    /**
+     * 根据点计算出折线点
+     *
+     */
+    getPoint(p1: SPoint, p2: SPoint): SPoint {
+        if (Math.abs(p1.x - p2.x) >= Math.abs(p1.y - p2.y)) {
+            return new SPoint(p2.x, p1.y);
+        } else {
+            return new SPoint(p1.x, p2.y);
+        }
+    }
+
+    /***/
+    change(): void {
+        if (this.pointList.length) {
+            if (this.Anchor1) {
+                this.pointList[0] = this.Anchor1.mapToScene(
+                    this.Anchor1.X,
+                    this.Anchor1.Y
+                );
+                console.log(this.pointList[0]);
+            }
+            if (this.Anchor2) {
+                this.pointList[
+                    this.pointList.length - 1
+                ] = this.Anchor2.mapToScene(this.Anchor2.X, this.Anchor2.Y);
+                console.log(this.pointList);
+            }
+        }
+        this.update();
+    } // Function change()
 
     /**
      * Item绘制操作
@@ -96,7 +175,12 @@ export class RelationItem extends SGraphyItem {
      * @param   painter       painter对象
      */
     onDraw(painter: SPainter): void {
-        painter.pen.lineWidth = 50;
+        painter.pen.lineWidth = 2;
+        painter.pen.color = new SColor("#409EFF");
+        painter.brush.color = new SColor("#409EFF");
         painter.drawPolyline(this.pointList);
+        if (!this.closeFlag) {
+            painter.drawPolyline(this.lastPointList);
+        }
     } // Function onDraw()
 } // Class RelationItem

+ 8 - 6
src/types/Anchor.ts

@@ -18,7 +18,7 @@
  * ********************************************************************************************************************
  */
 
-import { SPoint } from "@saga-web/draw/lib";
+import { Point } from "./Point";
 
 /**
  * 锚点item接口
@@ -27,13 +27,15 @@ import { SPoint } from "@saga-web/draw/lib";
  */
 export interface Anchor {
     /** 宽度  */
-    width?: number;
+    Width?: number;
     /** 高度  */
-    height?: number;
+    Height?: number;
     /** 名称  */
-    name?: string;
+    Name?: string;
     /** 位置-锚点中心点  */
-    pos: SPoint;
+    Pos: Point;
     /** 联机条数限制  */
-    connectNum?: number;
+    ConnectNum?: number;
+    /** 朝向  */
+    FaceType: number;
 } // Interface Anchor

+ 15 - 7
src/types/Equip.ts

@@ -18,7 +18,9 @@
  * ********************************************************************************************************************
  */
 
-import { SPoint } from "@saga-web/draw/lib";
+import { Anchor } from "./Anchor";
+import { Size } from "./Size";
+import { Point } from "./Point";
 
 /**
  * 设备item接口
@@ -26,12 +28,18 @@ import { SPoint } from "@saga-web/draw/lib";
  * @author  郝建龙
  */
 export interface Equip {
-    /** 宽度  */
-    width?: number;
-    /** 高度  */
-    height?: number;
+    /** ID   */
+    ID?: string;
+    /** 大小  */
+    Size: Size;
     /** 名称  */
-    name?: string;
+    Name?: string;
     /** 位置-equip中心点  */
-    pos: SPoint;
+    Pos: Point;
+    /** 锚点位置    */
+    AnchorList: Anchor[];
+    /** 依赖的数据中心对象id */
+    AttachID?: string;
+    /** 类型  */
+    Type?: string;
 } // Interface Equip

+ 36 - 0
src/types/FaceType.ts

@@ -0,0 +1,36 @@
+/*
+ * ********************************************************************************************************************
+ *
+ *                      :*$@@%$*:                         ;:                ;;    ;;
+ *                    :@@%!  :!@@%:                       %!             ;%%@@%$ =@@@@@@@%;     @%@@@%%%%@@@@@
+ *                   :@%;       :$=                       %%$$$%$$         ;$$  ;$@=   !@$
+ *                   =@!                                  %!              @ $=;%   !@@@%:      !$$$$$$$$$$$$$$=
+ *                   =@*                                  %!              @ $= % %@=   =%@!      %=
+ *              *$%%! @@=        ;=$%%%$*:                %!              @ $= % =%%%%%%@$      *%:         =%
+ *            %@@!:    !@@@%=$@@@@%!  :*@@$:              %!              @ $= % $*     ;@      @*          :%*
+ *          ;@@!          ;!!!;:         ;@%:      =======@%========*     @ $$ % $%*****$@     :@$=*********=@$
+ *          $@*   ;@@@%=!:                *@*
+ *          =@$    ;;;!=%@@@@=!           =@!
+ *           %@$:      =@%: :*@@@*       %@=                    Copyright (c) 2016-2019.  北京上格云技术有限公司
+ *            ;%@@$=$@@%*       *@@@$=%@@%;
+ *               ::;::             ::;::                                              All rights reserved.
+ *
+ * ********************************************************************************************************************
+ */
+
+/**
+ * 锚点朝向
+ *
+ * @author 郝建龙
+ */
+enum FaceType {
+    UP = 0,
+    DOWN = 1,
+    RIGHT = 2,
+    LEFT = 3,
+    LEFT_TOP = 4,
+    RIGHT_TOP = 5,
+    LEFT_DOWN = 6,
+    RIGHT_DOWN = 7,
+    ANY = 8
+} // Enum FaceType

+ 30 - 0
src/types/Point.ts

@@ -0,0 +1,30 @@
+/*
+ * ********************************************************************************************************************
+ *
+ *                      :*$@@%$*:                         ;:                ;;    ;;
+ *                    :@@%!  :!@@%:                       %!             ;%%@@%$ =@@@@@@@%;     @%@@@%%%%@@@@@
+ *                   :@%;       :$=                       %%$$$%$$         ;$$  ;$@=   !@$
+ *                   =@!                                  %!              @ $=;%   !@@@%:      !$$$$$$$$$$$$$$=
+ *                   =@*                                  %!              @ $= % %@=   =%@!      %=
+ *              *$%%! @@=        ;=$%%%$*:                %!              @ $= % =%%%%%%@$      *%:         =%
+ *            %@@!:    !@@@%=$@@@@%!  :*@@$:              %!              @ $= % $*     ;@      @*          :%*
+ *          ;@@!          ;!!!;:         ;@%:      =======@%========*     @ $$ % $%*****$@     :@$=*********=@$
+ *          $@*   ;@@@%=!:                *@*
+ *          =@$    ;;;!=%@@@@=!           =@!
+ *           %@$:      =@%: :*@@@*       %@=                    Copyright (c) 2016-2020.  北京上格云技术有限公司
+ *            ;%@@$=$@@%*       *@@@$=%@@%;
+ *               ::;::             ::;::                                              All rights reserved.
+ *
+ * ********************************************************************************************************************
+ */
+
+/**
+ * Point接口
+ *
+ * @author  郝建龙
+ */
+export interface Point {
+    X: number;
+    Y: number;
+    Z?: number;
+} // Interface Equip

+ 12 - 3
src/types/Relation.ts

@@ -18,7 +18,8 @@
  * ********************************************************************************************************************
  */
 
-import { SPoint } from "@saga-web/draw/lib";
+import { Point } from "./Point";
+import { AnchorItem } from "../items/AnchorItem";
 
 /**
  * 关系item接口
@@ -29,7 +30,15 @@ export interface Relation {
     /** 类型  */
     type?: number;
     /** id  */
-    id?: string;
+    ID?: string;
+    /** 锚点1ID   */
+    Anchor1ID?: string;
+    /** 锚点2ID   */
+    Anchor2ID?: string;
+    /** 锚点1     */
+    Anchor1?: AnchorItem;
+    /** 锚点2     */
+    Anchor2?: AnchorItem;
     /** 名称  */
-    pointList: SPoint[];
+    PointList?: Point[];
 } // Interface Relation

+ 31 - 0
src/types/Size.ts

@@ -0,0 +1,31 @@
+/*
+ * ********************************************************************************************************************
+ *
+ *                      :*$@@%$*:                         ;:                ;;    ;;
+ *                    :@@%!  :!@@%:                       %!             ;%%@@%$ =@@@@@@@%;     @%@@@%%%%@@@@@
+ *                   :@%;       :$=                       %%$$$%$$         ;$$  ;$@=   !@$
+ *                   =@!                                  %!              @ $=;%   !@@@%:      !$$$$$$$$$$$$$$=
+ *                   =@*                                  %!              @ $= % %@=   =%@!      %=
+ *              *$%%! @@=        ;=$%%%$*:                %!              @ $= % =%%%%%%@$      *%:         =%
+ *            %@@!:    !@@@%=$@@@@%!  :*@@$:              %!              @ $= % $*     ;@      @*          :%*
+ *          ;@@!          ;!!!;:         ;@%:      =======@%========*     @ $$ % $%*****$@     :@$=*********=@$
+ *          $@*   ;@@@%=!:                *@*
+ *          =@$    ;;;!=%@@@@=!           =@!
+ *           %@$:      =@%: :*@@@*       %@=                    Copyright (c) 2016-2020.  北京上格云技术有限公司
+ *            ;%@@$=$@@%*       *@@@$=%@@%;
+ *               ::;::             ::;::                                              All rights reserved.
+ *
+ * ********************************************************************************************************************
+ */
+
+/**
+ *  大小item接口
+ *
+ * @author  郝建龙
+ */
+export interface Size {
+    /** 宽度  */
+    Width?: number;
+    /** 高度  */
+    Height?: number;
+} // Interface Size

+ 1 - 189
src/util/SMathUtil.ts

@@ -19,12 +19,6 @@
  */
 
 import { SLine, SPoint, SRect } from "@saga-web/draw/lib";
-import { MinDis } from "../types/MinDis";
-import { Point } from "../types/Point";
-import { PointToLine } from "../types/PointToLine";
-import { Outline } from "../types/Outline";
-// @ts-ignore
-import { intersect } from "polybooljs";
 
 export class SMathUtil {
     /**
@@ -46,113 +40,6 @@ export class SMathUtil {
     } // Function pointDistance()
 
     /**
-     * 计算点到点集中点最小距离,返回该点和该距离
-     *
-     * @param   p       第一个点
-     * @param   arr     点集
-     * @return  距离,点坐标
-     */
-    static getMinDisPoint(p: SPoint, arr: Point[]): MinDis | null {
-        if (!arr.length) {
-            return null;
-        }
-        let minDis = {
-            MinDis: SMathUtil.pointDistance(p.x, p.y, arr[0].X, -arr[0].Y),
-            Point: arr[0]
-        };
-        for (let i = 1; i < arr.length; i++) {
-            let ds = SMathUtil.pointDistance(p.x, p.y, arr[i].X, -arr[i].Y);
-            if (ds < minDis.MinDis) {
-                minDis.MinDis = ds;
-                minDis.Point = arr[i];
-            }
-        }
-        return minDis;
-    } // Function getMinDisPoint()
-
-    /**
-     * 计算点到线段垂线与线段的交点
-     *
-     * @param   p   点
-     * @param   l   线段
-     * @return  距离
-     */
-    static pointToLine(p: SPoint, l: SLine): PointToLine {
-        let d = {
-            MinDis: Number.MAX_SAFE_INTEGER,
-            Line: new SLine(),
-            Point: new SPoint()
-        };
-        let bgX = Math.max(l.x1, l.x2);
-        let smX = Math.min(l.x1, l.x2);
-        if (l.dx == 0) {
-            // l.dx为0 说明线段是垂直于x轴的
-            let bgY = Math.max(l.y1, l.y2);
-            let smY = Math.min(l.y1, l.y2);
-            if (p.y > smY && p.y < bgY) {
-                d.MinDis = Math.abs(p.x - l.x1);
-                d.Line = l;
-                d.Point = new SPoint(l.x1, p.y);
-            }
-        } else if (l.dy == 0) {
-            // l.dy为0 说明线段是平行于x轴的
-            if (p.x > smX && p.x < bgX) {
-                d.MinDis = Math.abs(p.y - l.y1);
-                d.Line = l;
-                d.Point = new SPoint(p.x, l.y1);
-            }
-        } else {
-            // 直线1
-            let k1 = (l.y1 - l.y2) / (l.x1 - l.x2);
-            let b1 = l.y1 - k1 * l.x1;
-            // 直线2
-            let k2 = -1 / k1;
-            let b2 = p.y - k2 * p.x;
-            // 交点
-            let x = (b1 - b2) / (k2 - k1);
-            let y = k1 * x + b1;
-            if (x > smX && x < bgX) {
-                d.MinDis = SMathUtil.pointDistance(p.x, p.y, x, y);
-                d.Line = l;
-                d.Point = new SPoint(x, y);
-            }
-        }
-        return d;
-    } // Function pointDistance()
-
-    /**
-     * 计算点到点集中线段最小距离,返回该点和该距离
-     *
-     * @param   p       第一个点
-     * @param   arr     点集
-     * @return  距离,点坐标
-     */
-    static getMinDisLine(p: SPoint, arr: Point[]): PointToLine | null {
-        if (arr.length < 2) {
-            return null;
-        }
-        let PTL = SMathUtil.pointToLine(
-            p,
-            new SLine(
-                arr[arr.length - 1].X,
-                -arr[arr.length - 1].Y,
-                arr[0].X,
-                -arr[0].Y
-            )
-        );
-        for (let i = 0; i < arr.length - 1; i++) {
-            let temp = SMathUtil.pointToLine(
-                p,
-                new SLine(arr[i].X, -arr[i].Y, arr[i + 1].X, -arr[i + 1].Y)
-            );
-            if (temp.MinDis < PTL.MinDis) {
-                PTL = temp;
-            }
-        }
-        return PTL;
-    } // Function getMinDisPoint()
-
-    /**
      * 计算矩形是否有交集(外包矩形算法)
      *
      * @param   rect1   矩形1
@@ -228,81 +115,6 @@ export class SMathUtil {
     } // Function transferToSPoint()
 
     /**
-     * 计算数组中每一项的交集,并返回外轮廓与内轮廓
-     *
-     */
-    static getIntersectInArray(array: number[][][]): Outline[] {
-        let outlineList: Outline[] = [];
-        if (!array.length) {
-            // 无数据不做处理
-        } else if (array.length == 1) {
-            // 只有一条则为外轮廓
-            let outline: Outline = {
-                Outer: [],
-                Inner: []
-            };
-            outline.Outer = array[0].map(
-                (t): SPoint => {
-                    return new SPoint(t[0], t[1]);
-                }
-            );
-            outlineList.push(outline);
-        } else {
-            // 多条的时候,最后一条未外轮廓,倒序遍历与之相交的为内轮廓,不相交为另外的外轮廓
-            let poly2 = {
-                regions: [],
-                inverted: false
-            };
-            // @ts-ignore
-            poly2.regions.push(array[array.length - 1]);
-            let indexArr: number[] = [array.length - 1];
-            for (let i = array.length - 2; i > 0; i--) {
-                let poly1 = {
-                    regions: [],
-                    inverted: false
-                };
-                // @ts-ignore
-                poly1.regions.push(array[i]);
-                let intersectObj = intersect(poly1, poly2);
-                console.log(intersectObj);
-                if (!intersectObj.regions.length) {
-                    indexArr.unshift(i);
-                    poly2.regions = [];
-                    // @ts-ignore
-                    poly2.regions.push(array[i]);
-                }
-            }
-            indexArr.unshift(0);
-            console.log(indexArr);
-            for (let i = 0; i < indexArr.length - 1; i++) {
-                let axArr = array.slice(
-                    i == 0 ? 0 : indexArr[i] + 1,
-                    indexArr[i + 1]
-                );
-                let outline: Outline = {
-                    Outer: [],
-                    Inner: []
-                };
-                outline.Outer = array[indexArr[i + 1]].map(
-                    (t): SPoint => {
-                        return new SPoint(t[0], t[1]);
-                    }
-                );
-                outline.Inner = axArr.map((t): SPoint[] => {
-                    return t.map(
-                        (item): SPoint => {
-                            return new SPoint(item[0], item[1]);
-                        }
-                    );
-                });
-                outlineList.push(outline);
-            }
-        }
-        console.log(outlineList);
-        return outlineList;
-    } // Function getIntersectInArray()
-
-    /**
      * 计算轮廓线面积
      * */
     static calculateArea(arr: SPoint[]): number {
@@ -312,6 +124,6 @@ export class SMathUtil {
         for (let i = 1; i <= n; i++) {
             sum += arr[i].x * arr[i - 1].y - arr[i - 1].x * arr[i].y;
         }
-        return sum / 2;
+        return Math.abs(sum / 2);
     }
 } // Class SMathUtil