Quellcode durchsuchen

Merge branch 'master' of http://39.106.8.246:3003/web/sagacloud-web

haojianlong vor 5 Jahren
Ursprung
Commit
381990bc04

+ 51 - 40
saga-web-big/src/factories/SItemFactory.ts

@@ -12,20 +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 { ImageData } from "../types/ImageData";
 import { Legend } from "../types/topology/Legend";
 import { Marker } from "../types/topology/Marker";
 import { Relation } from "../types/topology/Relation";
-import { Anchor } from "../types/topology/Anchor";
-import { SLineType } from "../enums/SLineType";
-import { SAnchorItem, SEntityItem, SImageItem, SMarkerItem } from "..";
 import {
-    SRelation,
-    SLineRelation,
     SVerticalRelation,
-    SCurveRelation
+    SNoneLegendItem,
+    SLineLegendItem,
+    SZoneLegendItem,
+    SImageLegendItem,
+    SImageMarkerItem,
+    SLineMarkerItem,
+    STextMarkerItem
 } from "..";
-import {SGraphElementType} from "../enums/SGraphElementType";
 
 /**
  * 拓扑图信息解析器
@@ -110,46 +109,67 @@ export class SItemFactory {
     } // Function createZone()
 
     /**
-     * 创建图片item
+     * 创建图例节点item(非图例类型)
      *
-     * @param   data    图片数据
+     * @param   data    图例节点数据
+     * */
+    createNoneLegend(data: Legend): SNoneLegendItem {
+        return new SNoneLegendItem(null, data);
+    } // Function createNoneLegend()
+
+    /**
+     * 创建图例节点item(线类型)
+     *
+     * @param   data    图例节点数据
      * */
-    createImage(data: ImageData): SImageItem {
-        return new SImageItem(null);
-    } // Function createImage()
+    createLineLegend(data: Legend): SLineLegendItem {
+        return new SLineLegendItem(null, data);
+    } // Function createLineLegend()
 
     /**
-     * 创建文本item
+     * 创建图例节点item(区域类型)
      *
-     * @param   data    文本数据
+     * @param   data    图例节点数据
      * */
-    // createText(data: TextData): STextItem {
-    //     return new STextItem(null);
-    // } // Function createImage()
+    createZoneLegend(data: Legend): SZoneLegendItem {
+        return new SZoneLegendItem(null, data);
+    } // Function createZoneLegend()
 
     /**
-     * 创建图例节点item
+     * 创建图例节点item(图标类型)
      *
      * @param   data    图例节点数据
      * */
-    createNode(data: Legend): SEntityItem {
-        if (data.GraphElementType == SGraphElementType.None) {
-            return new SEntityItem(null, data);
-        }
-        if (data.GraphElementType == SGraphElementType.Line) {
+    createImageLegend(data: Legend): SImageLegendItem {
+        return new SImageLegendItem(null, data);
+    } // Function createImageLegend()
+
+    /**
+     * 创建标识item(图类型)
+     *
+     * @param   data    标识对象数据
+     * */
+    createImageMarker(data: Marker): SImageMarkerItem {
+        return new SImageMarkerItem(null, data);
+    } // Function createImageMarker()
 
-        }
-        return new SEntityItem(null, data);
-    } // Function createNode()
+    /**
+     * 创建标识item(线类型)
+     *
+     * @param   data    标识对象数据
+     * */
+    createLineMarker(data: Marker): SLineMarkerItem {
+        return new SLineMarkerItem(null, data);
+    } // Function createLineMarker()
 
     /**
-     * 创建标识item
+     * 创建标识item(文本类型)
      *
      * @param   data    标识对象数据
      * */
-    createMarker(data: Marker): SMarkerItem {
-        return new SMarkerItem(null, data);
-    } // Function createMarker()
+    createTextMarker(data: Marker): STextMarkerItem {
+        return new STextMarkerItem(null, data);
+    } // Function createTextMarker()
 
     /**
      * 创建管线关系item
@@ -159,13 +179,4 @@ export class SItemFactory {
     createRelation(data: Relation): SVerticalRelation {
         return new SVerticalRelation(null, data);
     } // Function createRelation()
-
-    /**
-     * 创建锚点item
-     *
-     * @param   data    锚点数据
-     * */
-    createAnchor(data: Anchor): SAnchorItem {
-        return new SAnchorItem(null);
-    } // Function createAnchor()
 } // class SItemFactory

+ 25 - 4
saga-web-big/src/items/SLineItem.ts

@@ -1,11 +1,12 @@
 import { SColor, SLine, SPainter, SPoint, SRect } from "@saga-web/draw/lib";
-import { SMouseEvent, SUndoStack, SMouseButton } from "@saga-web/base";
+import { SMouseButton, SMouseEvent, SUndoStack } from "@saga-web/base";
 import { SMathUtil } from "../utils/SMathUtil";
 import { SItemStatus } from "..";
 import {
     SGraphItem,
     SGraphPointListInsert,
-    SGraphPointListUpdate
+    SGraphPointListUpdate,
+    SLineStyle
 } from "@saga-web/graph/lib";
 
 /**
@@ -35,7 +36,7 @@ export class SLineItem extends SGraphItem {
     }
 
     /** 是否完成绘制  */
-    _status: SItemStatus = SItemStatus.Create;
+    _status: SItemStatus = SItemStatus.Normal;
     get status(): SItemStatus {
         return this._status;
     }
@@ -54,6 +55,16 @@ export class SLineItem extends SGraphItem {
         this.update();
     }
 
+    /** 线条样式    */
+    _lineStyle: SLineStyle = SLineStyle.Soild;
+    get lineStyle(): SLineStyle {
+        return this._lineStyle;
+    }
+    set lineStyle(v: SLineStyle) {
+        this._lineStyle = v;
+        this.update();
+    }
+
     /** 端点填充色 */
     _fillColor: string = "#ffffff";
     get fillColor(): string {
@@ -403,8 +414,18 @@ export class SLineItem extends SGraphItem {
 
             // 绘制直线
             painter.pen.color = new SColor(this.strokeColor);
+            if (this.lineStyle == SLineStyle.Dashed) {
+                painter.pen.lineDash = [
+                    painter.toPx(this.lineWidth * 3),
+                    painter.toPx(this.lineWidth * 7)
+                ];
+            } else if (this.lineStyle == SLineStyle.Dotted) {
+                painter.pen.lineDash = [
+                    painter.toPx(this.lineWidth),
+                    painter.toPx(this.lineWidth)
+                ];
+            }
             painter.drawLine(this.line[0], this.line[1]);
-
             if (
                 this.status == SItemStatus.Edit ||
                 this.status == SItemStatus.Create

+ 134 - 2
saga-web-big/src/items/topology/SImageMarkerItem.ts

@@ -1,5 +1,6 @@
 import { Marker } from "../../types/topology/Marker";
-import { SGraphItem, SImageItem } from "@saga-web/graph/lib";
+import { SGraphItem, SImageItem, SImageShowType } from "@saga-web/graph/lib";
+import { SPainter } from "@saga-web/draw";
 
 /**
  * 标识对象Item(图标类型)
@@ -10,6 +11,75 @@ 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();
+    }
+
+    /** 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();
+    }
+
+    /** 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();
+    }
+
+    set name(v: string) {
+        this.data.Name = v;
+    }
+
+    set url(v: string) {
+        if (this.data.Properties) {
+            this.data.Properties.Url = v;
+        }
+    }
+
+    set x(v: number) {
+        this.data.Pos.X = v;
+    }
+
+    set y(v: number) {
+        this.data.Pos.Y = v;
+    }
+
+    set width(v: number) {
+        if (this.data.Size) {
+            this.data.Size.Width = v;
+        }
+    }
+
+    set height(v: number) {
+        if (this.data.Size) {
+            this.data.Size.Height = v;
+        }
+    }
+
     /**
      * 构造函数
      *
@@ -19,5 +89,67 @@ export class SImageMarkerItem extends SImageItem {
     constructor(parent: SGraphItem | null, data: Marker) {
         super(parent);
         this.data = data;
-    }
+        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.Size) {
+            this.width = this.data.Size.Width;
+            this.height = this.data.Size.Height;
+        }
+        if (this.data.Properties && this.data.Properties.Url) {
+            if (this.data.Properties.Url instanceof String) {
+                this.url = this.data.Properties.Url;
+            }
+        }
+    } // Constructor
+
+    /**
+     * Item绘制操作
+     *
+     * @param   painter      绘画类
+     */
+    onDraw(painter: SPainter): void {
+        if (this.img) {
+            // 要绘制图片的宽度
+            let width: number = 0;
+            // 要绘制图片的宽度
+            let height: number = 0;
+            // 图片item的宽高比
+            let itemAspectRatio: number = this.width / this.height;
+            // 原始图片的宽高比
+            let imgAspectRatio: number =
+                (this.img.width as number) / (this.img.height as number);
+            // 原始图片的高宽比
+            let imgHwRatio: number =
+                (this.img.height as number) / (this.img.width as number);
+            if (this.showType == SImageShowType.Full) {
+                width = this.width;
+                height = this.height;
+            } else if (this.showType == SImageShowType.Equivalency) {
+                if (itemAspectRatio > imgAspectRatio) {
+                    height = this.height;
+                    width = imgAspectRatio * height;
+                } else if (itemAspectRatio < imgAspectRatio) {
+                    width = this.width;
+                    height = width * imgHwRatio;
+                } else {
+                    width = this.width;
+                    height = this.height;
+                }
+            } else if (this.showType == SImageShowType.AutoFit) {
+                this.width = this.img.width as number;
+                this.height = this.img.height as number;
+                width = this.width;
+                height = this.height;
+            }
+            painter.scale(this.scaleX, this.scaleY);
+            painter.rotate(this.rolate);
+            painter.drawImage(this.img, -width / 2, -height / 2, width, height);
+        }
+    } // Function onDraw()
 } // Class SImageMarkerItem

+ 85 - 0
saga-web-big/src/items/topology/SLineLegendItem.ts

@@ -1,6 +1,7 @@
 import { Legend } from "../../types/topology/Legend";
 import { SGraphItem } from "@saga-web/graph/lib";
 import { SLineItem } from "../SLineItem";
+import {SPoint} from "@saga-web/draw/lib";
 
 /**
  * 图例节点Item(线类型)
@@ -11,6 +12,75 @@ export class SLineLegendItem extends SLineItem {
     /** 图例节点对象数据 */
     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();
+    }
+
+    /** 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();
+    }
+
+    /** 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();
+    }
+
+    set name(v: string) {
+        this.data.Name = v;
+    }
+
+    set line(arr: SPoint[]) {
+        if (this.data.Properties) {
+            this.data.Properties.Line = arr;
+        }
+    }
+
+    set x(v: number) {
+        this.data.Pos.X = v;
+    }
+
+    set y(v: number) {
+        this.data.Pos.Y = v;
+    }
+
+    set width(v: number) {
+        if (this.data.Size) {
+            this.data.Size.Width = v;
+        }
+    }
+
+    set height(v: number) {
+        if (this.data.Size) {
+            this.data.Size.Height = v;
+        }
+    }
+
     /**
      * 构造函数
      *
@@ -20,5 +90,20 @@ export class SLineLegendItem extends SLineItem {
     constructor(parent: SGraphItem | null, data: Legend) {
         super(parent);
         this.data = data;
+        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.Size) {
+            this.width = this.data.Size.Width;
+            this.height = this.data.Size.Height;
+        }
+        if (this.data.Properties && this.data.Properties.Line) {
+            this.line = this.data.Properties.Line;
+        }
     }
 } // Class SLineLegendItem

+ 86 - 1
saga-web-big/src/items/topology/SLineMarkerItem.ts

@@ -1,6 +1,7 @@
 import { Marker } from "../../types/topology/Marker";
 import { SGraphItem } from "@saga-web/graph/lib";
 import { SLineItem } from "../SLineItem";
+import { SPoint } from "@saga-web/draw/lib";
 
 /**
  * 标识对象Item(线类型)
@@ -11,6 +12,75 @@ export class SLineMarkerItem extends SLineItem {
     /** 标识对象数据 */
     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();
+    }
+
+    /** 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();
+    }
+
+    /** 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();
+    }
+
+    set name(v: string) {
+        this.data.Name = v;
+    }
+
+    set line(arr: SPoint[]) {
+        if (this.data.Properties) {
+            this.data.Properties.Line = arr;
+        }
+    }
+
+    set x(v: number) {
+        this.data.Pos.X = v;
+    }
+
+    set y(v: number) {
+        this.data.Pos.Y = v;
+    }
+
+    set width(v: number) {
+        if (this.data.Size) {
+            this.data.Size.Width = v;
+        }
+    }
+
+    set height(v: number) {
+        if (this.data.Size) {
+            this.data.Size.Height = v;
+        }
+    }
+
     /**
      * 构造函数
      *
@@ -20,5 +90,20 @@ export class SLineMarkerItem extends SLineItem {
     constructor(parent: SGraphItem | null, data: Marker) {
         super(parent);
         this.data = data;
-    }
+        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.Size) {
+            this.width = this.data.Size.Width;
+            this.height = this.data.Size.Height;
+        }
+        if (this.data.Properties && this.data.Properties.Line) {
+            this.line = this.data.Properties.Line;
+        }
+    } // Constructor
 } // Class SLineMarkerItem

+ 102 - 1
saga-web-big/src/items/topology/STextMarkerItem.ts

@@ -1,5 +1,6 @@
 import { Marker } from "../../types/topology/Marker";
 import { SGraphItem, STextItem } from "@saga-web/graph/lib";
+import { SPainter, SColor } from "@saga-web/draw";
 
 /**
  * 标识对象Item(文本类型)
@@ -10,6 +11,75 @@ export class STextMarkerItem extends STextItem {
     /** 标识对象数据 */
     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();
+    }
+
+    /** 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();
+    }
+
+    /** 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();
+    }
+
+    set name(v: string) {
+        this.data.Name = v;
+    }
+
+    set text(v: string) {
+        if (this.data.Properties) {
+            this.data.Properties.Text = v;
+        }
+    }
+
+    set x(v: number) {
+        this.data.Pos.X = v;
+    }
+
+    set y(v: number) {
+        this.data.Pos.Y = v;
+    }
+
+    set width(v: number) {
+        if (this.data.Size) {
+            this.data.Size.Width = v;
+        }
+    }
+
+    set height(v: number) {
+        if (this.data.Size) {
+            this.data.Size.Height = v;
+        }
+    }
+
     /**
      * 构造函数
      *
@@ -19,5 +89,36 @@ export class STextMarkerItem extends STextItem {
     constructor(parent: SGraphItem | null, data: Marker) {
         super(parent);
         this.data = data;
-    }
+        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.Size) {
+            this.width = this.data.Size.Width;
+            this.height = this.data.Size.Height;
+        }
+        if (this.data.Properties && this.data.Properties.Text) {
+            if (this.data.Properties.Text instanceof String) {
+                this.text = this.data.Properties.Text;
+            }
+        }
+    } // Constructor
+
+    /**
+     * Item绘制操作
+     *
+     * @param   painter      绘画类
+     */
+    onDraw(painter: SPainter): void {
+        // 绘制文本
+        painter.brush.color = new SColor(this.color);
+        painter.font = this.font;
+        painter.scale(this.scaleX, this.scaleY);
+        painter.rotate(this.rolate);
+        this.drawFormatText(painter);
+    } // Function onDraw()
 } // Class STextMarkerItem

+ 27 - 6
saga-web-big/src/parser/STopologyParser.ts

@@ -13,6 +13,8 @@ import {
     SLineMarkerItem,
     STextMarkerItem
 } from "..";
+import { SGraphElementType } from "../enums/SGraphElementType";
+import {SMarkerType} from "../enums/SMarkerType";
 
 /**
  * 拓扑图信息解析器
@@ -46,7 +48,7 @@ export class STopologyParser extends SParser {
     parseData(data: ElementData): void {
         if (data.Nodes) {
             data.Nodes.forEach((t: Legend): void => {
-                this.addNode(t);
+                this.addLegend(t);
             });
         }
         if (data.Markers) {
@@ -66,9 +68,20 @@ export class STopologyParser extends SParser {
      *
      * @param   t       图例节点数据
      * */
-    private addNode(t: Legend): void {
-        let item = this.factory.createNode(t);
-        // this.nodeList.push(item);
+    private addLegend(t: Legend): void {
+        if (t.GraphElementType == SGraphElementType.None) {
+            let item = this.factory.createNoneLegend(t);
+            this.noneLegendList.push(item);
+        } else if (t.GraphElementType == SGraphElementType.Line) {
+            let item = this.factory.createLineLegend(t);
+            this.lineLegendList.push(item);
+        } else if (t.GraphElementType == SGraphElementType.Zone) {
+            let item = this.factory.createZoneLegend(t);
+            this.zoneLegendList.push(item);
+        } else if (t.GraphElementType == SGraphElementType.Image) {
+            let item = this.factory.createImageLegend(t);
+            this.imageLegendList.push(item);
+        }
     } // Function addNode()
 
     /**
@@ -77,8 +90,16 @@ export class STopologyParser extends SParser {
      * @param   t       标识对象数据
      * */
     private addMarker(t: Marker): void {
-        let item = this.factory.createMarker(t);
-        // this.markersList.push(item);
+        if (t.Type == SMarkerType.Image) {
+            let item = this.factory.createImageMarker(t);
+            this.imageMarkerList.push(item);
+        } else if (t.Type == SMarkerType.Line) {
+            let item = this.factory.createLineMarker(t);
+            this.lineMarkerList.push(item);
+        } else if (t.Type == SMarkerType.Text) {
+            let item = this.factory.createTextMarker(t);
+            this.textMarkerList.push(item);
+        }
     } // Function addMarker()
 
     /**

+ 1 - 1
saga-web-big/src/types/topology/Legend.ts

@@ -52,5 +52,5 @@ export interface Legend {
     /** 轮廓线  */
     OutLine?: Point[][];
     /** 由应用自己定义  */
-    Properties?: {};
+    Properties?: any;
 } // Interface Legend

+ 1 - 1
saga-web-big/src/types/topology/Marker.ts

@@ -43,5 +43,5 @@ export interface Marker {
     /** 大小  */
     Size?: Size;
     /** 由应用自己定义  */
-    Properties?: {};
+    Properties?: any;
 } // Interface Marker

+ 13 - 0
saga-web-graph/src/enums/SLineStyle.ts

@@ -0,0 +1,13 @@
+/**
+ * 线样式
+ *
+ * @author  张宇
+ */
+export enum SLineStyle {
+    /** 实线    */
+    Soild,
+    /** 虚线    */
+    Dashed,
+    /** 点线    */
+    Dotted
+} // Enum SLineStyle

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

@@ -43,6 +43,7 @@ import { SObjectItem } from "./items/SObjectItem";
 import { SAnchorItem } from "./items/SAnchorItem";
 import { STextItem } from "./items/STextItem";
 import { SImageShowType } from "./enums/SImageShowType";
+import { SLineStyle } from "./enums/SLineStyle";
 
 export {
     SGraphItem,
@@ -60,5 +61,6 @@ export {
     SObjectItem,
     SAnchorItem,
     STextItem,
-    SImageShowType
+    SImageShowType,
+    SLineStyle
 };

+ 2 - 2
saga-web-graph/src/items/SImageItem.ts

@@ -79,9 +79,9 @@ export class SImageItem extends SObjectItem {
     onDraw(painter: SPainter): void {
         if (this.img) {
             // 要绘制图片的宽度
-            let width = 0;
+            let width: number = 0;
             // 要绘制图片的宽度
-            let height = 0;
+            let height: number = 0;
             // 图片item的宽高比
             let itemAspectRatio: number = this.width / this.height;
             // 原始图片的宽高比

+ 58 - 24
saga-web-graph/src/items/STextItem.ts

@@ -1,6 +1,7 @@
 import { SObjectItem } from "./SObjectItem";
 import { SPainter, SRect, SColor, SFont } from "@saga-web/draw/lib";
 import { SGraphItem } from "../SGraphItem";
+import { SLineStyle } from "../enums/SLineStyle";
 
 /**
  * 文本item
@@ -38,6 +39,46 @@ export class STextItem extends SObjectItem {
         this.update();
     }
 
+    /** 背景色 */
+    private _backgroundColor: string = "#00000000";
+    get backgroundColor(): string {
+        return this._backgroundColor;
+    }
+    set backgroundColor(v: string) {
+        this._backgroundColor = v;
+        this.update();
+    }
+
+    /** 边框宽度 */
+    private _borderWidth: number = 1;
+    get borderWidth(): number {
+        return this._borderWidth;
+    }
+    set borderWidth(v: number) {
+        this._borderWidth = v;
+        this.update();
+    }
+
+    /** 边框色 */
+    private _borderColor: string = "#00000000";
+    get borderColor(): string {
+        return this._borderColor;
+    }
+    set borderColor(v: string) {
+        this._borderColor = v;
+        this.update();
+    }
+
+    /** 边框样式    */
+    private _borderStyle: SLineStyle = SLineStyle.Soild;
+    get borderStyle(): SLineStyle {
+        return this._borderStyle;
+    }
+    set borderStyle(v: SLineStyle) {
+        this._borderStyle = v;
+        this.update();
+    }
+
     /** 文本绘制最大宽 */
     maxWidth: number | undefined = undefined;
 
@@ -64,39 +105,32 @@ export class STextItem extends SObjectItem {
     } // Function boundingRect()
 
     /**
-     * 绘制编辑和创建状态文本Item
+     * 绘制显示状态文本Item
      *
      * @param painter    绘制类
      */
-    protected drawEditText(painter: SPainter): void {
-        //绘制文本
-        painter.brush.color = new SColor(this.color);
-        painter.font = this.font;
-        this.drawFormatText(painter);
-
+    protected drawShowText(painter: SPainter): void {
         //绘制矩形轮廓
-        painter.brush.color = SColor.Transparent;
-        painter.pen.color = new SColor("#17B8EA");
-        painter.pen.lineDash = [3, 2];
-        painter.pen.lineWidth = painter.toPx(1);
+        painter.brush.color = new SColor(this.backgroundColor);
+        painter.pen.color = new SColor(this.borderColor);
+        painter.pen.lineWidth = painter.toPx(this.borderWidth);
+        if (this.borderStyle == SLineStyle.Dashed) {
+            painter.pen.lineDash = [
+                painter.toPx(this.borderWidth * 3),
+                painter.toPx(this.borderWidth * 7)
+            ];
+        } else if (this.borderStyle == SLineStyle.Dotted) {
+            painter.pen.lineDash = [
+                painter.toPx(this.borderWidth),
+                painter.toPx(this.borderWidth)
+            ];
+        }
         painter.drawRect(this.boundingRect());
-    } // Function drawEditText()
 
-    /**
-     * 绘制显示状态文本Item
-     *
-     * @param painter    绘制类
-     */
-    protected drawShowText(painter: SPainter): void {
-        // 绘制文本
+        //绘制文本
         painter.brush.color = new SColor(this.color);
         painter.font = this.font;
         this.drawFormatText(painter);
-
-        // 绘制矩形轮廓
-        painter.brush.color = SColor.Transparent;
-        painter.pen.color = SColor.Transparent;
-        painter.drawRect(this.boundingRect());
     } // Function drawShowText()
 
     /**