xushiting 1 рік тому
батько
коміт
8bd552c69a

+ 63 - 4
src/view/case/draw/board/editCAD/Geometry/CustomImage.js

@@ -7,7 +7,7 @@ import { coordinate } from '../Coordinate'
 export default class CustomImage extends Geometry {
     constructor(url,center,vectorId) {
         super()
-        this.center = center
+        this.center = center   //实际上是左下角
         this.url = url;
         this.image = null;
         this.width = 40;
@@ -15,19 +15,78 @@ export default class CustomImage extends Geometry {
         this.angle = 0 //逆时针为负,顺时针为正。单位是:°
         this.scale = 1 //缩放比例
         this.ratio = 1;
+        this.points = [];
         this.geoType = VectorType.CustomImage
         this.setId(vectorId)
     }
 
     isContain(position) {
-        if(Math.abs(position.x - this.center.x)* coordinate.res * coordinate.zoom/ 100 <this.ratio*this.width/2 && Math.abs(position.y - this.center.y)* coordinate.res * coordinate.zoom/ 100<this.ratio*this.height/2)
-        {
+        // if(Math.abs(position.x - this.center.x)* coordinate.res * coordinate.zoom/ 100 <this.ratio*this.width/2 && Math.abs(position.y - this.center.y)* coordinate.res * coordinate.zoom/ 100<this.ratio*this.height/2)
+        // {
+        //     return SelectState.Select
+        // } else {
+        //     return null
+        // }
+        // this.context.arc(pt.x-geometry.ratio * geometry.width/4*geometry.scale, pt.y-geometry.ratio * geometry.height/4*geometry.scale, 2 * coordinate.ratio, 0, Math.PI * 2, true)
+    
+        let p0 = {
+            x:this.center.x - this.ratio*this.width/2/coordinate.res*this.scale,
+            y:this.center.y + this.ratio*this.height/2/coordinate.res*this.scale
+        }
+
+        let p1 = {
+            x:this.center.x,
+            y:this.center.y + this.ratio*this.height/2/coordinate.res*this.scale
+        }
+
+        let p2 = {
+            x:this.center.x,
+            y:this.center.y
+        }
+
+        let p3 = {
+            x:this.center.x- this.ratio*this.width/2/coordinate.res*this.scale,
+            y:this.center.y
+        }
+        let center = {
+            x:this.center.x - this.ratio*this.width/4/coordinate.res*this.scale,
+            y:this.center.y + this.ratio*this.height/4/coordinate.res*this.scale
+        }
+
+        p0 = this.rotatePoint(p0, center, this.angle)
+        p1 = this.rotatePoint(p1, center, this.angle)
+        p2 = this.rotatePoint(p2, center, this.angle)
+        p3 = this.rotatePoint(p3, center, this.angle)
+
+        //let points = [];
+        this.points = [];
+        this.points.push(p0)
+        this.points.push(p3)
+        this.points.push(p2)
+        this.points.push(p1)
+        if(mathUtil.isPointInPoly(position, this.points)){
             return SelectState.Select
-        } else {
+        }else {
             return null
         }
     }
 
+    // ptSrc: 圆上某点(初始点);
+    // ptRotationCenter: 圆心点;
+    // angle: 旋转角度°  -- [angle * M_PI / 180]:将角度换算为弧度
+    // 【注意】angle 逆时针为正,顺时针为负
+    rotatePoint(ptSrc, ptRotationCenter, angle) {
+        angle = -1 * angle //设计是逆时针为负,顺时针为正
+        var a = ptRotationCenter.x
+        var b = ptRotationCenter.y
+        var x0 = ptSrc.x
+        var y0 = ptSrc.y
+        var rx = a + (x0 - a) * Math.cos((angle * Math.PI) / 180) - (y0 - b) * Math.sin((angle * Math.PI) / 180)
+        var ry = b + (x0 - a) * Math.sin((angle * Math.PI) / 180) + (y0 - b) * Math.cos((angle * Math.PI) / 180)
+        var json = { x: rx, y: ry }
+        return json
+    }
+
     setImageData(imgData){
         this.image = imgData;
     }

+ 30 - 1
src/view/case/draw/board/editCAD/Renderer/Draw.js

@@ -920,8 +920,18 @@ export default class Draw {
                 
             }
             const focusItem = stateService.getFocusItem()
+            const selectItem = stateService.getSelectItem()
             if (focusItem && focusItem.type == VectorType.CustomImage) {
                 if (geometry.vectorId == focusItem.vectorId) {
+                    this.context.lineWidth = 2/geometry.scale;
+                    this.context.strokeStyle = Style.Select.Tag.strokeStyle
+                    this.context.fillStyle = Style.Select.Tag.fillStyle
+                    this.context.strokeRect( -geometry.ratio * geometry.width/2, -geometry.ratio * geometry.height/2, geometry.ratio * geometry.width/2, geometry.ratio * geometry.height/2)
+                }
+            }
+            else if (selectItem && selectItem.type == VectorType.CustomImage) {
+                if (geometry.vectorId == selectItem.vectorId) {
+                    this.context.lineWidth = 2/geometry.scale;
                     this.context.strokeStyle = Style.Select.Tag.strokeStyle
                     this.context.fillStyle = Style.Select.Tag.fillStyle
                     this.context.strokeRect( -geometry.ratio * geometry.width/2, -geometry.ratio * geometry.height/2, geometry.ratio * geometry.width/2, geometry.ratio * geometry.height/2)
@@ -929,8 +939,27 @@ export default class Draw {
             }
 
             this.context.restore()
+
+            // this.context.save()
+            // if(geometry.points.length>1){
+                
+            //     this.context.strokeStyle = 'red'
+            //     this.context.lineWidth = 4
+            //     let p0 = coordinate.getScreenXY(geometry.points[0])
+            //     let p1 = coordinate.getScreenXY(geometry.points[1])
+            //     let p2 = coordinate.getScreenXY(geometry.points[2])
+            //     let p3 = coordinate.getScreenXY(geometry.points[3])
+            //     this.context.beginPath()
+            //     this.context.moveTo(p0.x,p0.y);
+            //     this.context.lineTo(p3.x,p3.y);
+            //     this.context.lineTo(p2.x,p2.y);
+            //     this.context.lineTo(p1.x,p1.y);
+            //     this.context.closePath()
+            //     this.context.stroke();
+            // }
+            // this.context.restore()
             // this.context.beginPath()
-            // this.context.arc(pt.x, pt.y, 2 * coordinate.ratio, 0, Math.PI * 2, true)
+            // this.context.arc(pt.x-geometry.ratio * geometry.width/4*geometry.scale, pt.y-geometry.ratio * geometry.height/4*geometry.scale, 2 * coordinate.ratio, 0, Math.PI * 2, true)
             // this.context.stroke()
             // this.context.fill()
             // this.context.restore()