Browse Source

对象关系item派生

zhangyu 4 years ago
parent
commit
c324e4df2e

+ 11 - 10
src/components/mapClass/EditScence.ts

@@ -1,11 +1,11 @@
-import { SMouseEvent, SUndoStack } from "@saga-web/base";
-import { SGraphScene, SGraphLayoutType } from '@saga-web/graph/lib';
-import { SFloorParser, SLineItem, SPolylineItem, SItemStatus, ItemOrder } from "@saga-web/big";
-import { SGraphItem, SImageItem, STextItem, SGraphPointListInsert, SGraphPointListDelete, SGraphPointListUpdate, SGraphAddCommand } from "@saga-web/graph/lib";
-import { SZoneLegendItem } from "@/lib/items/SZoneLegendItem";
-import { TipelineItem } from "@/lib/items/TipelineItem";
-import { SImgTextItem } from "@/lib/items/SImgTextItem"
-import { SPoint, SFont } from '@saga-web/draw/lib';
+import {SMouseEvent, SUndoStack} from "@saga-web/base";
+import {SGraphAddCommand, SGraphItem, SGraphLayoutType, SGraphScene, SImageItem, STextItem} from '@saga-web/graph/lib';
+import {ItemOrder, SLineItem, SPolylineItem} from "@saga-web/big";
+import {SZoneLegendItem} from "@/lib/items/SZoneLegendItem";
+import {TipelineItem} from "@/lib/items/TipelineItem";
+import {SImgTextItem} from "@/lib/items/SImgTextItem"
+import {SFont, SPoint} from '@saga-web/draw/lib';
+import {SItemStatus} from "@saga-web/big/lib";
 
 
 /**
@@ -95,10 +95,11 @@ export class EditScence extends SGraphScene {
      */
     addLine(event: SMouseEvent): boolean {
         const item = new SLineItem(null, new SPoint(event.x, event.y));
-        this.addItem(item);
-        item.connect("finishCreated", this, this.finishCreated);
+        item.status = SItemStatus.Create;
         item.zOrder = ItemOrder.lineOrder;
         item.selectable = true;
+        this.addItem(item);
+        item.connect("finishCreated", this, this.finishCreated);
         this.grabItem = item;
         this.undoStack.push(new SGraphAddCommand(this, item));
         // item.connect("onMove", this, this.onItemMove.bind(this));

+ 1 - 0
src/lib/items/SImageLegendItem.ts

@@ -21,5 +21,6 @@ export class SImageLegendItem extends SIconTextItem {
     constructor(parent: SGraphItem | null, data: Legend) {
         super(parent);
         this.data = data;
+        this.id = data.ID;
     }
 } // Class SImageLegendItem

+ 43 - 42
src/lib/items/SImageMarkerItem.ts

@@ -13,43 +13,43 @@ export class SImageMarkerItem extends SImageItem {
     data: Marker;
 
     /** x轴缩放属性 */
-    _scaleX: number = 1;
-    get scaleX(): number {
-        return this._scaleX;
-    }
-    set scaleX(v: number) {
-        this._scaleX = v;
-        if (this.data.Scale) {
-            this.data.Scale.X = v;
-        }
-        this.update();
-    }
+    // _scaleX: number = 1;
+    // get scaleX(): number {
+    //     return this._scaleX;
+    // }
+    // set scaleX(v: number) {
+    //     this._scaleX = v;
+    //     if (this.data.Scale) {
+    //         this.data.Scale.X = v;
+    //     }
+    //     this.update();
+    // }
 
     /** y轴缩放属性 */
-    _scaleY: number = 1;
-    get scaleY(): number {
-        return this._scaleY;
-    }
-    set scaleY(v: number) {
-        this._scaleY = v;
-        if (this.data.Scale) {
-            this.data.Scale.Y = v;
-        }
-        this.update();
-    }
+    // _scaleY: number = 1;
+    // get scaleY(): number {
+    //     return this._scaleY;
+    // }
+    // set scaleY(v: number) {
+    //     this._scaleY = v;
+    //     if (this.data.Scale) {
+    //         this.data.Scale.Y = v;
+    //     }
+    //     this.update();
+    // }
 
     /** y轴旋转属性 */
-    _rolate: number = 0;
-    get rolate(): number {
-        return this._rolate;
-    }
-    set rolate(v: number) {
-        this._rolate = v;
-        if (this.data.Rolate) {
-            this.data.Rolate.Z = v;
-        }
-        this.update();
-    }
+    // _rolate: number = 0;
+    // get rolate(): number {
+    //     return this._rolate;
+    // }
+    // set rolate(v: number) {
+    //     this._rolate = v;
+    //     if (this.data.Rolate) {
+    //         this.data.Rolate.Z = v;
+    //     }
+    //     this.update();
+    // }
 
     set name(v: string) {
         this.data.Name = v;
@@ -90,14 +90,15 @@ export class SImageMarkerItem extends SImageItem {
     constructor(parent: SGraphItem | null, data: Marker) {
         super(parent);
         this.data = data;
+        this.id = data.ID;
         this.moveTo(data.Pos.X, data.Pos.Y);
-        if (this.data.Scale) {
-            this.scaleX = this.data.Scale.X;
-            this.scaleY = this.data.Scale.Y;
-        }
-        if (this.data.Rolate && this.data.Rolate.Z) {
-            this.rolate = this.data.Rolate.Z;
-        }
+        // if (this.data.Scale) {
+        //     this.scaleX = this.data.Scale.X;
+        //     this.scaleY = this.data.Scale.Y;
+        // }
+        // if (this.data.Rolate && this.data.Rolate.Z) {
+        //     this.rolate = this.data.Rolate.Z;
+        // }
         if (this.data.Size) {
             this.width = this.data.Size.Width;
             this.height = this.data.Size.Height;
@@ -148,8 +149,8 @@ export class SImageMarkerItem extends SImageItem {
                 width = this.width;
                 height = this.height;
             }
-            painter.scale(this.scaleX, this.scaleY);
-            painter.rotate(this.rolate);
+            // painter.scale(this.scaleX, this.scaleY);
+            // painter.rotate(this.rolate);
             painter.drawImage(this.img, -width / 2, -height / 2, width, height);
         }
     } // Function onDraw()

+ 41 - 40
src/lib/items/SLineLegendItem.ts

@@ -14,43 +14,43 @@ export class SLineLegendItem extends SPolylineItem {
     data: Legend;
 
     /** x轴缩放属性 */
-    _scaleX: number = 1;
-    get scaleX(): number {
-        return this._scaleX;
-    }
-    set scaleX(v: number) {
-        this._scaleX = v;
-        if (this.data.Scale) {
-            this.data.Scale.X = v;
-        }
-        this.update();
-    }
+    // _scaleX: number = 1;
+    // get scaleX(): number {
+    //     return this._scaleX;
+    // }
+    // set scaleX(v: number) {
+    //     this._scaleX = v;
+    //     if (this.data.Scale) {
+    //         this.data.Scale.X = v;
+    //     }
+    //     this.update();
+    // }
 
     /** y轴缩放属性 */
-    _scaleY: number = 1;
-    get scaleY(): number {
-        return this._scaleY;
-    }
-    set scaleY(v: number) {
-        this._scaleY = v;
-        if (this.data.Scale) {
-            this.data.Scale.Y = v;
-        }
-        this.update();
-    }
+    // _scaleY: number = 1;
+    // get scaleY(): number {
+    //     return this._scaleY;
+    // }
+    // set scaleY(v: number) {
+    //     this._scaleY = v;
+    //     if (this.data.Scale) {
+    //         this.data.Scale.Y = v;
+    //     }
+    //     this.update();
+    // }
 
     /** y轴旋转属性 */
-    _rolate: number = 0;
-    get rolate(): number {
-        return this._rolate;
-    }
-    set rolate(v: number) {
-        this._rolate = v;
-        if (this.data.Rolate) {
-            this.data.Rolate.Z = v;
-        }
-        this.update();
-    }
+    // _rolate: number = 0;
+    // get rolate(): number {
+    //     return this._rolate;
+    // }
+    // set rolate(v: number) {
+    //     this._rolate = v;
+    //     if (this.data.Rolate) {
+    //         this.data.Rolate.Z = v;
+    //     }
+    //     this.update();
+    // }
 
     set name(v: string) {
         this.data.Name = v;
@@ -91,14 +91,15 @@ export class SLineLegendItem extends SPolylineItem {
     constructor(parent: SGraphItem | null, data: Legend) {
         super(parent,[]);
         this.data = data;
+        this.id = data.ID;
         this.moveTo(data.Pos.X, data.Pos.Y);
-        if (this.data.Scale) {
-            this.scaleX = this.data.Scale.X;
-            this.scaleY = this.data.Scale.Y;
-        }
-        if (this.data.Rolate && this.data.Rolate.Z) {
-            this.rolate = this.data.Rolate.Z;
-        }
+        // if (this.data.Scale) {
+        //     this.scaleX = this.data.Scale.X;
+        //     this.scaleY = this.data.Scale.Y;
+        // }
+        // if (this.data.Rolate && this.data.Rolate.Z) {
+        //     this.rolate = this.data.Rolate.Z;
+        // }
         if (this.data.Size) {
             this.width = this.data.Size.Width;
             this.height = this.data.Size.Height;

+ 41 - 40
src/lib/items/SLineMarkerItem.ts

@@ -14,43 +14,43 @@ export class SLineMarkerItem extends SPolylineItem {
     data: Marker;
 
     /** x轴缩放属性 */
-    _scaleX: number = 1;
-    get scaleX(): number {
-        return this._scaleX;
-    }
-    set scaleX(v: number) {
-        this._scaleX = v;
-        if (this.data.Scale) {
-            this.data.Scale.X = v;
-        }
-        this.update();
-    }
+    // _scaleX: number = 1;
+    // get scaleX(): number {
+    //     return this._scaleX;
+    // }
+    // set scaleX(v: number) {
+    //     this._scaleX = v;
+    //     if (this.data.Scale) {
+    //         this.data.Scale.X = v;
+    //     }
+    //     this.update();
+    // }
 
     /** y轴缩放属性 */
-    _scaleY: number = 1;
-    get scaleY(): number {
-        return this._scaleY;
-    }
-    set scaleY(v: number) {
-        this._scaleY = v;
-        if (this.data.Scale) {
-            this.data.Scale.Y = v;
-        }
-        this.update();
-    }
+    // _scaleY: number = 1;
+    // get scaleY(): number {
+    //     return this._scaleY;
+    // }
+    // set scaleY(v: number) {
+    //     this._scaleY = v;
+    //     if (this.data.Scale) {
+    //         this.data.Scale.Y = v;
+    //     }
+    //     this.update();
+    // }
 
     /** y轴旋转属性 */
-    _rolate: number = 0;
-    get rolate(): number {
-        return this._rolate;
-    }
-    set rolate(v: number) {
-        this._rolate = v;
-        if (this.data.Rolate) {
-            this.data.Rolate.Z = v;
-        }
-        this.update();
-    }
+    // _rolate: number = 0;
+    // get rolate(): number {
+    //     return this._rolate;
+    // }
+    // set rolate(v: number) {
+    //     this._rolate = v;
+    //     if (this.data.Rolate) {
+    //         this.data.Rolate.Z = v;
+    //     }
+    //     this.update();
+    // }
 
     set name(v: string) {
         this.data.Name = v;
@@ -91,14 +91,15 @@ export class SLineMarkerItem extends SPolylineItem {
     constructor(parent: SGraphItem | null, data: Marker) {
         super(parent,[]);
         this.data = data;
+        this.id = data.ID;
         this.moveTo(data.Pos.X, data.Pos.Y);
-        if (this.data.Scale) {
-            this.scaleX = this.data.Scale.X;
-            this.scaleY = this.data.Scale.Y;
-        }
-        if (this.data.Rolate && this.data.Rolate.Z) {
-            this.rolate = this.data.Rolate.Z;
-        }
+        // if (this.data.Scale) {
+        //     this.scaleX = this.data.Scale.X;
+        //     this.scaleY = this.data.Scale.Y;
+        // }
+        // if (this.data.Rolate && this.data.Rolate.Z) {
+        //     this.rolate = this.data.Rolate.Z;
+        // }
         if (this.data.Size) {
             this.width = this.data.Size.Width;
             this.height = this.data.Size.Height;

+ 1 - 0
src/lib/items/SNoneLegendItem.ts

@@ -19,5 +19,6 @@ export class SNoneLegendItem extends SGraphItem {
     constructor(parent: SGraphItem | null, data: Legend) {
         super(parent);
         this.data = data;
+        this.id = data.ID;
     }
 } // Class SNoneLegendItem

+ 43 - 42
src/lib/items/STextMarkerItem.ts

@@ -33,43 +33,43 @@ export class STextMarkerItem extends STextItem {
     }
 
     /** x轴缩放属性 */
-    _scaleX: number = 1;
-    get scaleX(): number {
-        return this._scaleX;
-    }
-    set scaleX(v: number) {
-        this._scaleX = v;
-        if (this.data.Scale) {
-            this.data.Scale.X = v;
-        }
-        this.update();
-    }
+    // _scaleX: number = 1;
+    // get scaleX(): number {
+    //     return this._scaleX;
+    // }
+    // set scaleX(v: number) {
+    //     this._scaleX = v;
+    //     if (this.data.Scale) {
+    //         this.data.Scale.X = v;
+    //     }
+    //     this.update();
+    // }
 
     /** y轴缩放属性 */
-    _scaleY: number = 1;
-    get scaleY(): number {
-        return this._scaleY;
-    }
-    set scaleY(v: number) {
-        this._scaleY = v;
-        if (this.data.Scale) {
-            this.data.Scale.Y = v;
-        }
-        this.update();
-    }
+    // _scaleY: number = 1;
+    // get scaleY(): number {
+    //     return this._scaleY;
+    // }
+    // set scaleY(v: number) {
+    //     this._scaleY = v;
+    //     if (this.data.Scale) {
+    //         this.data.Scale.Y = v;
+    //     }
+    //     this.update();
+    // }
 
     /** y轴旋转属性 */
-    _rolate: number = 0;
-    get rolate(): number {
-        return this._rolate;
-    }
-    set rolate(v: number) {
-        this._rolate = v;
-        if (this.data.Rolate) {
-            this.data.Rolate.Z = v;
-        }
-        this.update();
-    }
+    // _rolate: number = 0;
+    // get rolate(): number {
+    //     return this._rolate;
+    // }
+    // set rolate(v: number) {
+    //     this._rolate = v;
+    //     if (this.data.Rolate) {
+    //         this.data.Rolate.Z = v;
+    //     }
+    //     this.update();
+    // }
 
     set name(v: string) {
         this.data.Name = v;
@@ -110,14 +110,15 @@ export class STextMarkerItem extends STextItem {
     constructor(parent: SGraphItem | null, data: Marker) {
         super(parent);
         this.data = data;
+        this.id = data.ID;
         this.moveTo(data.Pos.X, data.Pos.Y);
-        if (this.data.Scale) {
-            this.scaleX = this.data.Scale.X;
-            this.scaleY = this.data.Scale.Y;
-        }
-        if (this.data.Rolate && this.data.Rolate.Z) {
-            this.rolate = this.data.Rolate.Z;
-        }
+        // if (this.data.Scale) {
+        //     this.scaleX = this.data.Scale.X;
+        //     this.scaleY = this.data.Scale.Y;
+        // }
+        // if (this.data.Rolate && this.data.Rolate.Z) {
+        //     this.rolate = this.data.Rolate.Z;
+        // }
         if (this.data.Size) {
             this.width = this.data.Size.Width;
             this.height = this.data.Size.Height;
@@ -138,8 +139,8 @@ export class STextMarkerItem extends STextItem {
         // 绘制文本
         painter.brush.color = new SColor(this.color);
         painter.font = this.font;
-        painter.scale(this.scaleX, this.scaleY);
-        painter.rotate(this.rolate);
+        // painter.scale(this.scaleX, this.scaleY);
+        // painter.rotate(this.rolate);
         if (this.borderStyle == SLineStyle.Dashed) {
             painter.pen.lineDash = [
                 painter.toPx(this.lineWidth * 3),

+ 1 - 0
src/lib/items/SZoneLegendItem.ts

@@ -62,6 +62,7 @@ export class SZoneLegendItem extends SPolygonItem {
     constructor(parent: SGraphItem | null, data: Legend) {
         super(parent);
         this.data = data;
+        this.id = data.ID;
         if (data) {
             // 设置轮廓线
             this.setPointList = data.OutLine ? data.OutLine[0] : [];

+ 97 - 4
src/lib/items/TipelineItem.ts

@@ -2,6 +2,8 @@ import { SPolylineItem } from '@saga-web/big/lib';
 import { SPainter, SColor } from '@saga-web/draw';
 import { SAnchorItem, SGraphItem } from '@saga-web/graph/lib';
 import { Relation } from '../types/Relation';
+import { SPoint } from "@saga-web/draw/lib";
+import {Point} from "@saga-web/big/lib/types/Point";
 
 /**
  * 管道item
@@ -12,6 +14,61 @@ export class TipelineItem extends SPolylineItem {
   startAnchor: SAnchorItem | null = null;
   /** 结束锚点  */
   endAnchor: SAnchorItem | null = null;
+  /** 对应的图例ID  */
+  _graphElementId: string = "";
+  get graphElementId(): string {
+    return this._graphElementId;
+  }
+  set graphElementId(v: string) {
+    this._graphElementId = v;
+    if (this.data) {
+      this.data.GraphElementId = this._graphElementId;
+    }
+  }
+  /** 关联节点1ID  */
+  _node1Id: string = "";
+  get node1Id(): string {
+    return this._node1Id;
+  }
+  set node1Id(v: string) {
+    this._node1Id = v;
+    if (this.data) {
+      this.data.Node1ID = this._node1Id;
+    }
+  }
+  /** 关联节点2ID  */
+  _node2Id: string = "";
+  get node2Id(): string {
+    return this._node2Id;
+  }
+  set node2Id(v: string) {
+    this._node2Id = v;
+    if (this.data) {
+      this.data.Node2ID = this._node2Id;
+    }
+  }
+  /** 关联锚点1ID  */
+  _anchor1ID: string = "";
+  get anchor1ID(): string {
+    return this._anchor1ID;
+  }
+  set anchor1ID(v: string) {
+    this._anchor1ID = v;
+    if (this.data) {
+      this.data.Anchor1ID = this._anchor1ID;
+    }
+  }
+  /** 关联锚点2ID  */
+  _anchor2ID: string = "";
+  get anchor2ID(): string {
+    return this._anchor2ID;
+  }
+  set anchor2ID(v: string) {
+    this._anchor2ID = v;
+    if (this.data) {
+      this.data.Anchor2ID = this._anchor2ID;
+    }
+  }
   /** 数据存储  */
   data: Relation | null = null;
   /** 接收事件作出修改  */
@@ -32,8 +89,44 @@ export class TipelineItem extends SPolylineItem {
     }
   }
 
-  // constructor(parent: SGraphItem | null, data: Relation) {
-  //   super(parent, data.PointList);
-  //   this.data = data;
-  // }
+  constructor(parent: SGraphItem | null, data: Relation) {
+    super(parent, []);
+    this.pointList = data.PointList.map(item => {
+      return new SPoint(item.X,item.Y);
+    });
+    this.data = data;
+    this.id = data.ID;
+    if (data.GraphElementId) {
+      this._graphElementId = data.GraphElementId
+    }
+    if (data.Node1ID) {
+      this._node1Id = data.Node1ID
+    }
+    if (data.Node2ID) {
+      this._node2Id = data.Node2ID
+    }
+    if (data.Anchor1ID) {
+      this._anchor1ID = data.Anchor1ID
+    }
+    if (data.Anchor2ID) {
+      this._anchor2ID = data.Anchor2ID
+    }
+
+  }
+
+  /** 获取data数据  */
+  getData(): Relation | null {
+    let pointList:Point[] = this.pointList.map(item => {
+      return {
+        X: item.x,
+        Y: item.y
+      }
+    });
+
+    if (this.data) {
+      this.data.PointList = pointList;
+    }
+
+    return this.data
+  }
 }

+ 3 - 1
src/lib/types/Anchor.ts

@@ -18,7 +18,9 @@
  * ********************************************************************************************************************
  */
 
-import { Point } from "../Point";
+
+
+import { Point } from "@saga-web/big/lib/types/Point";
 
 /**
  * 锚点item接口

+ 5 - 3
src/lib/types/ElementData.ts

@@ -18,9 +18,11 @@
  * ********************************************************************************************************************
  */
 
-import { Legend } from "./topology/Legend";
-import { Marker } from "./topology/Marker";
-import { Relation } from "./topology/Relation";
+
+
+import { Legend } from "./Legend";
+import { Marker } from "./Marker";
+import { Relation } from "./Relation";
 
 /**
  * 系统图数据接口

+ 3 - 2
src/lib/types/Legend.ts

@@ -18,10 +18,11 @@
  * ********************************************************************************************************************
  */
 
-import { Point } from "../Point";
-import { Size } from "../Size";
+
 import { Anchor } from "./Anchor";
 import { SGraphElementType } from "./../enums/SGraphElementType";
+import { Point } from "@saga-web/big/lib/types/Point";
+import { Size } from "@saga-web/big/lib/types/Size";
 
 /**
  * 图例节点接口

+ 5 - 3
src/lib/types/Marker.ts

@@ -18,9 +18,11 @@
  * ********************************************************************************************************************
  */
 
-import { Point } from "../Point";
-import { Size } from "../Size";
-import { SMarkerType } from "../../enums/SMarkerType";
+
+
+import { SMarkerType } from "@saga-web/big/lib/enums/SMarkerType";
+import { Point } from "@saga-web/big/lib/types/Point";
+import { Size } from "@saga-web/big/lib/types/Size";
 
 /**
  * 标识对象接口

+ 5 - 3
src/lib/types/Relation.ts

@@ -18,9 +18,11 @@
  * ********************************************************************************************************************
  */
 
-import { Point } from "../Point";
-import { SRelationDir } from "../../enums/SRelationDir";
-import { SLineType } from "../../enums/SLineType";
+
+
+import { SRelationDir } from "@saga-web/big/lib/enums/SRelationDir";
+import { SLineType } from "@saga-web/big/lib/enums/SLineType";
+import { Point } from "@saga-web/big/lib/types/Point";
 
 /**
  * 管线对象关系接口