haojianlong 5 سال پیش
والد
کامیت
fe6b6dab46

+ 6 - 11
saga-web-big/.eslintrc.js

@@ -19,18 +19,13 @@ module.exports = {
         sourceType: "module"
     },
     rules: {
-        // 注释
-        // 文件
-        "max-classes-per-file": ["error", 1],           // 一个文件中只能定义一个类
-        "max-lines-per-function": ["error", 200],       // 一个函数最多200行代码
-        "max-statements-per-line": ["error", {max: 1}], // 一行只允许有一条语句
         // 缩进
-        "indent": ["error", 4],                         // 缩进控制4空格
-        "max-len": ["error", 120],                      // 每行字符不超过120
-        "no-mixed-spaces-and-tabs": "error",            // 禁止使用空格和tab混合缩进
+        'indent': ['error', 4],                         // 缩进控制4空格
+        'max-len': ['error', 120],                      // 每行字符不超过120
+        'no-mixed-spaces-and-tabs': 'error',            // 禁止使用空格和tab混合缩进
         // 语句
-        "curly": ["error", "multi-line"],               // if、else if、else、for、while强制使用大括号,但允许在单行中省略大括号。
-        "semi": ["error", "always"],                    // 不得省略语句结束的分号
-        "@typescript-eslint/explicit-member-accessibility": ["error", { accessibility: "no-public" }],       // public访问不需加访问修饰符
+        'curly': ["error", "multi-line"],               // if、else if、else、for、while强制使用大括号,但允许在单行中省略大括号。
+        'semi': ['error', 'always'],                    //不得省略语句结束的分号
+        '@typescript-eslint/explicit-member-accessibility': ['error', { accessibility: 'no-public' }]       // public访问不需加访问修饰符
     }
 };

+ 2 - 2
saga-web-big/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/big",
-    "version": "1.0.24",
+    "version": "1.0.26",
     "description": "上格云建筑信息化库",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -42,6 +42,6 @@
         "typescript": "^3.9.3"
     },
     "dependencies": {
-        "@saga-web/graph": "2.1.68"
+        "@saga-web/graph": "2.1.69"
     }
 }

+ 1 - 1
saga-web-big/src/enums/SItemStatus.ts

@@ -1,5 +1,5 @@
 /**
- * item状态状态
+ * item状态
  *
  * @author
  */

+ 6 - 6
saga-web-big/src/enums/SLineType.ts

@@ -4,10 +4,10 @@
  * @author  张宇
  */
 export enum SLineType {
-	/** 直线    */
-	Line,
-	/** 水平/垂直线    */
-	Angle,
-	/** 曲线    */
-	Curve
+    /** 直线    */
+    Line,
+    /** 水平/垂直线    */
+    Angle,
+    /** 曲线    */
+    Curve
 } // Enum SLineType

+ 4 - 4
saga-web-big/src/enums/SMarkerType.ts

@@ -4,10 +4,10 @@
  * @author  张宇
  */
 export enum SMarkerType {
-		/** 图标    */
-		Image,
-		/** 线类型    */
-		Line,
+    /** 图标    */
+    Image,
+    /** 线类型    */
+    Line,
     /** 文本类型    */
     Text
 } // Enum SMarkerType

+ 13 - 0
saga-web-big/src/enums/SRelationDir.ts

@@ -0,0 +1,13 @@
+/**
+ * 关系方向
+ *
+ * @author  张宇
+ */
+export enum SRelationDir {
+    /** 无向    */
+    Undirected,
+    /** 正向(节点1到节点2)    */
+    Forward,
+    /** 逆向(节点2到节点1)    */
+    Reverse
+} // Enum SRelationDir

+ 0 - 13
saga-web-big/src/enums/SRlationDir.ts

@@ -1,13 +0,0 @@
-/**
- * 关系方向
- *
- * @author  张宇
- */
-export enum SRlationDir {
-	/** 无向    */
-	Undirected,
-	/** 正向(节点1到节点2)    */
-	Forward,
-	/** 逆向(节点2到节点1)    */
-	Reverse
-} // Enum SRlationDir

+ 13 - 16
saga-web-big/src/factories/SItemFactory.ts

@@ -12,19 +12,18 @@ 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, STextItem } from "..";
+import { SImageItem } from "..";
 import { ImageData } from "../types/ImageData";
-import { TextData } from "../types/TextData";
 import { Node } from "../types/topology/Node";
 import { Marker } from "../types/topology/Marker";
 import { Relation } from "../types/topology/Relation";
-import { SEntityItem } from "./../items/topology/SEntityItem";
-import { SRelation } from "./../items/topology/SRelation";
-import { SLineRelation } from "./../items/topology/SLineRelation";
-import { SVerticalRelation } from "./../items/topology/SVerticalRelation";
-import { SCurveRelation } from "./../items/topology/SCurveRelation";
+import { SEntityItem } from "..";
+import { SRelation } from "..";
+import { SLineRelation } from "..";
+import { SVerticalRelation } from "..";
+import { SCurveRelation } from "..";
 import { Anchor } from "../types/topology/Anchor";
-import { SAnchorItem } from "../items/topology/SAnchorItem";
+import { SAnchorItem } from "..";
 import { SLineType } from "../enums/SLineType";
 
 /**
@@ -134,13 +133,13 @@ export class SItemFactory {
      * */
     createNode(data: Node): SEntityItem {
         let entityItem = new SEntityItem(null);
-        if (data.AnchorList && data.AnchorList.length ) {
+        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)
+                    anchorItem.moveTo(anchor.Pos.X, anchor.Pos.Y);
                 }
-            }) 
+            });
         }
         return entityItem;
     } // Function createNode()
@@ -160,10 +159,10 @@ export class SItemFactory {
      * @param   data    管线关系对象数据
      * */
     createRelation(data: Relation): SRelation {
-        switch(data.LineType) {
-            case SLineType.Straight:
+        switch (data.LineType) {
+            case SLineType.Line:
                 return new SLineRelation(null);
-            case SLineType.Angle: 
+            case SLineType.Angle:
                 return new SVerticalRelation(null);
             case SLineType.Curve:
                 return new SCurveRelation(null);
@@ -172,7 +171,6 @@ export class SItemFactory {
         }
     } // Function createRelation()
 
-    
     /**
      * 创建锚点item
      *
@@ -181,5 +179,4 @@ export class SItemFactory {
     createAnchor(data: Anchor): SAnchorItem {
         return new SAnchorItem(null);
     } // Function createAnchor()
-
 } // class SItemFactory

+ 4 - 4
saga-web-big/src/items/SImageItem.ts

@@ -44,7 +44,7 @@ export class SImageItem extends SObjectItem {
      */
     constructor(parent: SGraphItem | null, url?: string) {
         super(parent);
-        if (url) this._url = url;
+        if (url) this.url = url;
     } // Constructor
 
     /**
@@ -79,9 +79,9 @@ export class SImageItem extends SObjectItem {
     onDraw(painter: SPainter): void {
         if (this.img) {
             // 要绘制图片的宽度
-            let width: number = 0;
+            let width = 0;
             // 要绘制图片的宽度
-            let height: number = 0;
+            let height = 0;
             // 图片item的宽高比
             let itemAspectRatio: number = this.width / this.height;
             // 原始图片的宽高比
@@ -110,7 +110,7 @@ export class SImageItem extends SObjectItem {
                 width = this.width;
                 height = this.height;
             }
-            painter.drawImage(this.img, - width / 2, - height / 2, width, height);
+            painter.drawImage(this.img, -width / 2, -height / 2, width, height);
         }
     } // Function onDraw()
 } // Class SImageItem

+ 88 - 6
saga-web-big/src/items/SPolylineItem.ts

@@ -1,8 +1,12 @@
 import { SColor, SLine, SPainter, SPoint } from "@saga-web/draw/lib";
-import { SMouseEvent } from "@saga-web/base";
+import { SMouseEvent, SUndoStack } from "@saga-web/base";
 import { SItemStatus } from "..";
 import { SMathUtil } from "../utils/SMathUtil";
-import { SGraphItem } from "@saga-web/graph/lib";
+import {
+    SGraphItem,
+    SGraphPointListDelete,
+    SGraphPointListInsert, SGraphPointListUpdate
+} from "@saga-web/graph/lib";
 
 /**
  * 直线item
@@ -22,7 +26,7 @@ export class SPolylineItem extends SGraphItem {
         this.update();
     }
     /** 鼠标移动时的点 */
-    lastPoint: SPoint | null = null;
+    private lastPoint: SPoint | null = null;
     /** 线条颜色    */
     _strokeColor: string = "#000000";
     get strokeColor(): string {
@@ -53,9 +57,13 @@ export class SPolylineItem extends SGraphItem {
     /** 全局灵敏度   */
     dis: number = 10;
     /** 灵敏度转换为场景长度  */
-    sceneDis: number = 10;
+    private sceneDis: number = 10;
     /** 当前点索引   */
-    curIndex: number = -1;
+    private curIndex: number = -1;
+    /** 当前点索引   */
+    private curPoint: SPoint | null = null;
+    /** undo/redo堆栈 */
+    private undoStack: SUndoStack | null = new SUndoStack();
 
     /**
      * 构造函数
@@ -97,8 +105,14 @@ export class SPolylineItem extends SGraphItem {
     private addPoint(p: SPoint, index?: number): void {
         if (index && this.canHandle(index)) {
             this.pointList.splice(index, 0, p);
+            this.recordAction(SGraphPointListInsert, [
+                this.pointList,
+                p,
+                index
+            ]);
         } else {
             this.pointList.push(p);
+            this.recordAction(SGraphPointListInsert, [this.pointList, p]);
         }
         this.update();
     } // Function addPoint()
@@ -120,7 +134,16 @@ export class SPolylineItem extends SGraphItem {
      * */
     private delPoint(index: number): void {
         if (this.canHandle(index) && this.pointList.length > 2) {
+            const p = new SPoint(
+                this.pointList[this.curIndex].x,
+                this.pointList[this.curIndex].y
+            );
             this.pointList.splice(index, 0);
+            this.recordAction(SGraphPointListDelete, [
+                this.pointList,
+                p,
+                index
+            ]);
             this.update();
         }
     } // Function delPoint
@@ -133,6 +156,7 @@ export class SPolylineItem extends SGraphItem {
      * */
     onMouseDown(event: SMouseEvent): boolean {
         this.curIndex = -1;
+        this.curPoint = null;
         if (event.buttons == 1) {
             if (this.status == SItemStatus.Create) {
                 this.addPoint(new SPoint(event.x, event.y));
@@ -148,6 +172,7 @@ export class SPolylineItem extends SGraphItem {
                 if (event.altKey && this.canHandle(this.curIndex)) {
                     this.pointList.splice(this.curIndex, 1);
                     this.curIndex = -1;
+                    this.curPoint = null;
                 }
                 this.update();
                 return true;
@@ -193,7 +218,22 @@ export class SPolylineItem extends SGraphItem {
      * @return  boolean 是否处理事件
      * */
     onMouseUp(event: SMouseEvent): boolean {
+        if (this.status == SItemStatus.Edit) {
+            if (this.curIndex > -1) {
+                const p = new SPoint(
+                    this.pointList[this.curIndex].x,
+                    this.pointList[this.curIndex].y
+                );
+                this.recordAction(SGraphPointListUpdate, [
+                    this.pointList,
+                    this.curPoint,
+                    p,
+                    this.curIndex
+                ]);
+            }
+        }
         this.curIndex = -1;
+        this.curPoint = null;
         return true;
     } // Function onMouseMove()
 
@@ -228,7 +268,7 @@ export class SPolylineItem extends SGraphItem {
      */
     onKeyUp(event: KeyboardEvent): void {
         if (event.keyCode == 13) {
-            this.status = SItemStatus.Edit;
+            this.status = SItemStatus.Normal;
         }
     } // Function onKeyUp()
 
@@ -249,6 +289,10 @@ export class SPolylineItem extends SGraphItem {
             if (dis < len) {
                 len = dis;
                 this.curIndex = i;
+                this.curPoint = new SPoint(
+                    this.pointList[this.curIndex].x,
+                    this.pointList[this.curIndex].y
+                );
             }
         }
     } // Function findNearestPoint()
@@ -284,6 +328,20 @@ export class SPolylineItem extends SGraphItem {
     } // Function findAddPos()
 
     /**
+     * 记录相关动作并推入栈中
+     *
+     * @param	SGraphCommand   相关命令类
+     * @param	any             对应传入参数
+     */
+    protected recordAction(SGraphCommand: any, any: any[]): void {
+        // 记录相关命令并推入堆栈中
+        const command = new SGraphCommand(this, ...any);
+        if (this.undoStack) {
+            this.undoStack.push(command);
+        }
+    } // Function recordAction()
+
+    /**
      * 判断点是否在区域内
      *
      * @param   x
@@ -310,6 +368,30 @@ export class SPolylineItem extends SGraphItem {
     } // Function contains()
 
     /**
+     * 撤销操作
+     *
+     */
+    undo(): void {
+        if (this._status != SItemStatus.Normal) {
+            if (this.undoStack) {
+                this.undoStack.undo();
+            }
+        }
+    } // Function undo()
+
+    /**
+     * 重做操作
+     *
+     */
+    redo(): void {
+        if (this._status != SItemStatus.Normal) {
+            if (this.undoStack) {
+                this.undoStack.redo();
+            }
+        }
+    } // Function redo()
+
+    /**
      * Item绘制操作
      *
      * @param   painter painter对象

+ 7 - 7
saga-web-big/src/types/topology/Relation.ts

@@ -19,7 +19,7 @@
  */
 
 import { Point } from "../Point";
-import { SRlationDir } from "../../enums/SRlationDir";
+import { SRelationDir } from "../../enums/SRelationDir";
 import { SLineType } from "../../enums/SLineType";
 
 /**
@@ -28,11 +28,11 @@ import { SLineType } from "../../enums/SLineType";
  * @author  张宇
  */
 export interface Relation {
-     /** ID */
-     ID: string;
-     /** 名称 */
-     Name?: string;
-     /** 对应的图例ID */
+    /** ID */
+    ID: string;
+    /** 名称 */
+    Name?: string;
+    /** 对应的图例ID */
     GraphElementId?: string;
     /** 关联节点1_id */
     Node1ID?: string;
@@ -43,7 +43,7 @@ export interface Relation {
     /** 关联锚点2_id */
     Anchor2ID?: string;
     /** 方向(0:无向,1:节点1到节点2,2:节点2到节点1) */
-    Dir?: SRlationDir;
+    Dir?: SRelationDir;
     /** 线类型(0:直线,1:水平/垂直线,2:曲线) */
     LineType?: SLineType;
     /** 线的顶点坐标 */

+ 1 - 1
saga-web-graph/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/graph",
-    "version": "2.1.68",
+    "version": "2.1.69",
     "description": "上格云二维图形引擎。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",

+ 6 - 0
saga-web-graph/src/SGraphItem.ts

@@ -519,6 +519,12 @@ export class SGraphItem extends SObject {
      */
     onKeyUp(event: KeyboardEvent): void {} // Function onKeyUp()
 
+    /**
+     * 取消操作item事件
+     *
+     * */
+    cancelOperate(): void {} // Function cancelOperate()
+
     // =================================================================================================================
     // 私有方法
     /**