浏览代码

功能添加

haojianlong 4 年之前
父节点
当前提交
9aee23215f
共有 1 个文件被更改,包括 51 次插入5 次删除
  1. 51 5
      src/components/mapClass/EditScence.ts

+ 51 - 5
src/components/mapClass/EditScence.ts

@@ -65,10 +65,10 @@ export class EditScence extends SGraphScene {
     isAbsorbing: boolean = false;
     /** 吸附展示item    */
     highLight: HighlightItem | null = null;
-    /** 矩形选择区域  */
-    rectSelectItem: SRectSelectItem | null = null;
-    /** 框选    */
-    isRectSelection: number = 0;
+    // /** 矩形选择区域  */
+    // rectSelectItem: SRectSelectItem | null = null;
+    // /** 框选    */
+    // isRectSelection: number = 0;
     /** 当前选中焦点Item */
     focusItem: SGraphItem | null = null;
     /** 当前选中焦点ItemList */
@@ -1044,6 +1044,11 @@ export class EditScence extends SGraphScene {
             return this.grabItem.onMouseDown(event);
         }
         switch (this.cmd) {
+            // case 'choice':
+            //     if (!super.onMouseDown(event)){
+            //         this.addRectSelect(event);
+            //     }
+            //     break
             case 'baseLine':
                 this.addLine(event);
                 break;
@@ -1093,6 +1098,8 @@ export class EditScence extends SGraphScene {
                     event.y = p.y;
                     return this.grabItem.onMouseMove(event);
                 }
+            } else if (this.grabItem instanceof SRectSelectItem) {
+                return this.grabItem.onMouseMove(event);
             }
         }
         return super.onMouseMove(event)
@@ -1109,6 +1116,14 @@ export class EditScence extends SGraphScene {
             } else if (this.grabItem instanceof TipelineItem) {
                 this.updateTipeAnc(event);
                 return true;
+            } else if (this.grabItem instanceof SRectSelectItem) {
+                this.groupSelect();
+                this.removeItem(this.grabItem);
+                this.grabItem = null;
+                if (this.view) {
+                    this.view.update()
+                }
+                return true;
             }
             return this.grabItem.onMouseUp(event);
         }
@@ -1885,6 +1900,37 @@ export class EditScence extends SGraphScene {
         let point = new SPoint(event.x, event.y);
         let rect = new SRectSelectItem(null, point);
         this.addItem(rect);
-        this.rectSelectItem = rect;
+        this.grabItem = rect;
+    }
+
+    /**
+     * 计算框选交集
+    */
+    groupSelect(){
+        this.selectContainer.clear()
+        if (this.grabItem instanceof SRectSelectItem) {
+            const rect = this.grabItem.boundingRect();
+            this.arrToSelect(this.Nodes, rect)
+            this.arrToSelect(this.Markers, rect)
+            this.arrToSelect(this.Relations, rect)
+        }    
+    }
+    /**
+     * 选中item:框选
+    */
+    private arrToSelect(arr: SGraphItem[], rect:SRect){
+        if(Array.isArray(arr) && arr.length) {
+            arr.forEach(t => {
+                if (t.parent) {
+                    let temp = t.boundingRect();
+                    let lefttop = t.mapToScene(temp.left, temp.top)
+                    let rightbottom = t.mapToScene(temp.right, temp.bottom)
+                    let r = new SRect(lefttop, rightbottom)
+                    if (rect.isIn(r)){
+                        this.selectContainer.toggleItem(t)
+                    }
+                }
+            })
+        }
     }
 }