Przeglądaj źródła

解析器修改

zhangyu 5 lat temu
rodzic
commit
57cfdb0b0a

+ 1 - 1
saga-web-big/.eslintrc.js

@@ -20,7 +20,7 @@ module.exports = {
     },
     rules: {
         // 缩进
-        'indent': ['error', 4],                         // 缩进控制4空格
+        'indent': ['error', 4, { SwitchCase: 1 }],                         // 缩进控制4空格
         'max-len': ['error', 120],                      // 每行字符不超过120
         'no-mixed-spaces-and-tabs': 'error',            // 禁止使用空格和tab混合缩进
         // 语句

+ 12 - 30
saga-web-big/src/factories/SItemFactory.ts

@@ -12,19 +12,19 @@ import { SWindowItem } from "../items/floor/SWindowItem";
 import { Casement } from "../types/floor/Casement";
 import { SZoneItem } from "../items/floor/ZoneItem";
 import { Zone } from "../types/floor/Zone";
-import { SImageItem } from "..";
 import { ImageData } from "../types/ImageData";
 import { Node } from "../types/topology/Node";
 import { Marker } from "../types/topology/Marker";
 import { Relation } from "../types/topology/Relation";
-import { SEntityItem } from "..";
-import { SRelation } from "..";
-import { SLineRelation } from "..";
-import { SVerticalRelation } from "..";
-import { SCurveRelation } from "..";
 import { Anchor } from "../types/topology/Anchor";
-import { SAnchorItem } from "..";
 import { SLineType } from "../enums/SLineType";
+import { SAnchorItem, SEntityItem, SImageItem, SMarkerItem } from "..";
+import {
+    SRelation,
+    SLineRelation,
+    SVerticalRelation,
+    SCurveRelation
+} from "..";
 
 /**
  * 拓扑图信息解析器
@@ -132,16 +132,7 @@ export class SItemFactory {
      * @param   data    图例节点数据
      * */
     createNode(data: Node): SEntityItem {
-        let entityItem = new SEntityItem(null);
-        if (data.AnchorList && data.AnchorList.length) {
-            data.AnchorList.forEach((anchor: Anchor) => {
-                let anchorItem = new SAnchorItem(entityItem);
-                if (anchor && anchor.Pos) {
-                    anchorItem.moveTo(anchor.Pos.X, anchor.Pos.Y);
-                }
-            });
-        }
-        return entityItem;
+        return new SEntityItem(null, data);
     } // Function createNode()
 
     /**
@@ -149,8 +140,8 @@ export class SItemFactory {
      *
      * @param   data    标识对象数据
      * */
-    createMarker(data: Marker): SImageItem {
-        return new SImageItem(null);
+    createMarker(data: Marker): SMarkerItem {
+        return new SMarkerItem(null, data);
     } // Function createMarker()
 
     /**
@@ -158,17 +149,8 @@ export class SItemFactory {
      *
      * @param   data    管线关系对象数据
      * */
-    createRelation(data: Relation): SRelation {
-        switch (data.LineType) {
-            case SLineType.Line:
-                return new SLineRelation(null);
-            case SLineType.Angle:
-                return new SVerticalRelation(null);
-            case SLineType.Curve:
-                return new SCurveRelation(null);
-            default:
-                return new SLineRelation(null);
-        }
+    createRelation(data: Relation): SVerticalRelation {
+        return new SVerticalRelation(null, data);
     } // Function createRelation()
 
     /**

+ 3 - 1
saga-web-big/src/index.ts

@@ -2,6 +2,7 @@ import { SAnchorItem } from "./items/topology/SAnchorItem";
 import { SCompassItem } from "./items/floor/SCompassItem";
 import { SCurveRelation } from "./items/topology/SCurveRelation";
 import { SEntityItem } from "./items/topology/SEntityItem";
+import { SMarkerItem } from "./items/topology/SMarkerItem";
 import { SFloorItem } from "./items/floor/SFloorItem";
 import { SImageItem } from "./items/SImageItem";
 import { SLayerItem } from "./items/SLayerItem";
@@ -55,5 +56,6 @@ export {
     SBigParser,
     SIconTextItem,
     SRelationState,
-    SItemStatus
+    SItemStatus,
+    SMarkerItem
 };

+ 17 - 7
saga-web-big/src/items/SLineItem.ts

@@ -103,6 +103,13 @@ export class SLineItem extends SGraphItem {
      * 构造函数
      *
      * @param   parent  父级
+     * */
+    constructor(parent: SGraphItem | null);
+
+    /**
+     * 构造函数
+     *
+     * @param   parent  父级
      * @param   line    坐标集合
      * */
     constructor(parent: SGraphItem | null, line: SPoint[]);
@@ -121,12 +128,16 @@ export class SLineItem extends SGraphItem {
      * @param   parent  父级
      * @param   l       坐标集合|第一个点坐标
      * */
-    constructor(parent: SGraphItem | null, l: SPoint | SPoint[]) {
+    constructor(parent: SGraphItem | null, l?: SPoint | SPoint[]) {
         super(parent);
-        if (l instanceof SPoint) {
-            this.line.push(l);
+        if (l) {
+            if (l instanceof SPoint) {
+                this.line.push(l);
+            } else {
+                this.line = l;
+            }
         } else {
-            this.line = l;
+            this.line = [];
         }
     }
 
@@ -159,12 +170,11 @@ export class SLineItem extends SGraphItem {
         // 判断是否点击到线上
         if (this.contains(event.x, event.y)) {
             if (this.status == SItemStatus.Normal) {
-                if (this.scene) {
-                    this.scene.grabItem = this;
-                }
                 this.status = SItemStatus.Edit;
+                this.grabItem(this);
             } else if (this.status == SItemStatus.Edit) {
                 this.status = SItemStatus.Normal;
+                this.releaseItem();
             }
             this.update();
         }

+ 15 - 1
saga-web-big/src/items/topology/SEntityItem.ts

@@ -1,4 +1,6 @@
 import { SObjectItem } from "../SObjectItem";
+import { Node } from "../../types/topology/Node";
+import { SGraphItem } from "@saga-web/graph/lib";
 
 /**
  * 实例item,与物理世界对应
@@ -7,11 +9,23 @@ import { SObjectItem } from "../SObjectItem";
  */
 export class SEntityItem extends SObjectItem {
     /** 与物理世界对应的实例的所有数据 */
-    data: {} = {};
+    data: Node;
     /** 实例id    */
     id: string = "";
     /** 本地编码    */
     localId: string = "";
     /** 本地名称    */
     localName: string = "";
+
+    /**
+     * 构造函数
+     *
+     * @param parent    指向父对象
+     * @param data      图例节点数据
+     */
+    constructor(parent: SGraphItem | null, data: Node) {
+        super(parent);
+        this.data = data;
+        this.id = data.ID;
+    }
 } // Class SEntityItem

+ 24 - 0
saga-web-big/src/items/topology/SMarkerItem.ts

@@ -0,0 +1,24 @@
+import { SObjectItem } from "../SObjectItem";
+import { Marker } from "../../types/topology/Marker";
+import { SGraphItem } from "@saga-web/graph/lib";
+
+/**
+ * 实例item,与物理世界对应
+ *
+ * * @author  张宇(taohuzy@163.com)
+ */
+export class SMarkerItem extends SGraphItem {
+    /** 标识对象数据 */
+    data: Marker;
+
+    /**
+     * 构造函数
+     *
+     * @param parent    指向父对象
+     * @param data      标识数据
+     */
+    constructor(parent: SGraphItem | null, data: Marker) {
+        super(parent);
+        this.data = data;
+    }
+} // Class SMarkerItem

+ 16 - 0
saga-web-big/src/items/topology/SVerticalRelation.ts

@@ -1,4 +1,6 @@
 import { SRelation } from "./SRelation";
+import { SGraphItem } from "@saga-web/graph/lib";
+import { Relation } from "../../types/topology/Relation";
 
 /**
  * 垂直线关系线item
@@ -6,6 +8,20 @@ import { SRelation } from "./SRelation";
  * * @author  郝建龙(1061851420@qq.com)
  */
 export class SVerticalRelation extends SRelation {
+    /** 对象关系数据 */
+    data: Relation;
+
+    /**
+     * 构造函数
+     *
+     * @param parent    指向父对象
+     * @param data      对象关系数据
+     */
+    constructor(parent: SGraphItem | null, data: Relation) {
+        super(parent);
+        this.data = data;
+    }
+
     /**
      * 垂直线转曲线
      *

+ 17 - 20
saga-web-big/src/parser/STopologyParser.ts

@@ -1,25 +1,23 @@
 import { SParser } from "./SParser";
-import { SEntityItem } from "./../items/topology/SEntityItem";
-import { SRelation } from "./../items/topology/SRelation";
-import { SImageItem } from "./../items/SImageItem";
 import { ElementData } from "../types/ElementData";
 import { Node } from "../types/topology/Node";
 import { Marker } from "../types/topology/Marker";
 import { Relation } from "../types/topology/Relation";
+import { SMarkerItem, SEntityItem, SRelation } from "..";
 
 /**
  * 拓扑图信息解析器
  *
  */
 export class STopologyParser extends SParser {
-	/** 图例节点list   */
-	nodeList: SEntityItem[] = [];
-	/** 标识对象list   */
-	markersList: SImageItem[] = [];
-	/** 管线关系对象关系list   */
-	relationList: SRelation[] = [];
+    /** 图例节点list   */
+    nodeList: SEntityItem[] = [];
+    /** 标识对象list   */
+    markersList: SMarkerItem[] = [];
+    /** 管线关系对象关系list   */
+    relationList: SRelation[] = [];
 
-	/**
+    /**
      * 解析数据
      *
      * @param   data    系统图数据
@@ -40,9 +38,9 @@ export class STopologyParser extends SParser {
                 this.addRelation(t);
             });
         }
-	} // Function parseData()
-	
-	/**
+    } // Function parseData()
+
+    /**
      * 添加图例节点至场景中
      *
      * @param   t       图例节点数据
@@ -50,9 +48,9 @@ export class STopologyParser extends SParser {
     private addNode(t: Node): void {
         let item = this.factory.createNode(t);
         this.nodeList.push(item);
-	} // Function addNode()
-	
-	/**
+    } // Function addNode()
+
+    /**
      * 添加标识对象至场景中
      *
      * @param   t       标识对象数据
@@ -60,9 +58,9 @@ export class STopologyParser extends SParser {
     private addMarker(t: Marker): void {
         let item = this.factory.createMarker(t);
         this.markersList.push(item);
-	} // Function addMarker()
-	
-	/**
+    } // Function addMarker()
+
+    /**
      * 添加管线关系至场景中
      *
      * @param   t       管线关系对象数据
@@ -71,5 +69,4 @@ export class STopologyParser extends SParser {
         let item = this.factory.createRelation(t);
         this.relationList.push(item);
     } // Function addRelation()
-
 } // class STopologyParser