Explorar el Código

修改拖动问题。

庞利祥 hace 5 años
padre
commit
3d4c773521

BIN
.idea/caches/build_file_checksums.ser


+ 1 - 1
cadengine/build/generated/source/buildConfig/debug/cn/sagacloud/android/cadengine/BuildConfig.java

@@ -9,5 +9,5 @@ public final class BuildConfig {
   public static final String BUILD_TYPE = "debug";
   public static final String FLAVOR = "";
   public static final int VERSION_CODE = 5;
-  public static final String VERSION_NAME = "1.2.31";
+  public static final String VERSION_NAME = "1.2.34";
 }

+ 14 - 21
cadengine/src/main/java/cn/sagacloud/android/cadengine/FloorScene.kt

@@ -12,13 +12,12 @@ import android.util.SizeF
 import cn.sagacloud.android.cadengine.items.*
 import com.sybotan.android.graphy.items.SGraphyClockItem
 
-
 /**
  * 楼层场景
  *
  * @author  庞利祥(sybotan@126.com)
  */
-class FloorScene : SGraphyScene() {
+open class FloorScene : SGraphyScene() {
     /** item 数据  */
     var data: FloorData? = null
         set(value) {
@@ -160,25 +159,19 @@ class FloorScene : SGraphyScene() {
             }
         }
 
+        // 添加门
+        if (elements.doors != null) {
+            for (door in elements.doors!!) {
+                addDoor(door);
+            }
+        }
+
         // 添加窗户
         if (elements.windows != null) {
             for (window in elements.windows!!) {
                 addWindow(window);
             }
         }
-
-//        data.Windows.map((t: Casement) => {
-//            this.addCasement(t)
-//        })
-//        data.VirtualWalls.map((t: VirtualWall) => {
-//            this.addVirtualWall(t)
-//        })
-//        data.Doors.map((t: Door) => {
-//            this.addDoor(t)
-//        })
-//        data.Spaces.map((t: Space) => {
-//            this.addSpace(t)
-//        })
     } // Function addBaseMapItem()
 
     /**
@@ -186,7 +179,7 @@ class FloorScene : SGraphyScene() {
      *
      *  @param  column   柱子
      */
-    fun addColumn(column: Column){
+    open fun addColumn(column: Column){
         val item = ColumnItem(column)
         item.isVisible = isShowColumn
         columnList.add(item)
@@ -198,7 +191,7 @@ class FloorScene : SGraphyScene() {
      *
      *  @param  wall   墙
      */
-    fun addWall(wall: Wall){
+    open fun addWall(wall: Wall){
         val item = WallItem(wall)
         item.isVisible = isShowWall
         wallList.add(item)
@@ -210,7 +203,7 @@ class FloorScene : SGraphyScene() {
      *
      *  @param  wall   墙
      */
-    fun addVirtualWall(wall: VirtualWall){
+    open fun addVirtualWall(wall: VirtualWall){
         val item = VirtualWallItem(wall)
         item.isVisible = isShowVirtualWall
         virtualWallList.add(item)
@@ -222,7 +215,7 @@ class FloorScene : SGraphyScene() {
      *
      *  @param  space       空间
      */
-    fun addSpace(space: Space){
+    open fun addSpace(space: Space){
         val item = SpaceItem(space)
         item.isVisible = isShowSpace
         spaceList.add(item)
@@ -234,7 +227,7 @@ class FloorScene : SGraphyScene() {
      *
      *  @param  door        门
      */
-    fun addDoor(door: Door){
+    open fun addDoor(door: Door){
         val item = DoorItem(door)
         item.isVisible = isShowSpace
         doorList.add(item)
@@ -246,7 +239,7 @@ class FloorScene : SGraphyScene() {
      *
      *  @param  window     窗户
      */
-    fun addWindow(window: Window){
+    open fun addWindow(window: Window){
         val item = WindowItem(window)
         item.isVisible = isShowSpace
         windowList.add(item)

+ 79 - 52
cadengine/src/main/java/cn/sagacloud/android/cadengine/items/DoorItem.kt

@@ -1,12 +1,15 @@
 package cn.sagacloud.android.cadengine.items
 
-import android.graphics.Canvas
-import android.graphics.Paint
-import android.graphics.Path
-import android.graphics.RectF
+import android.graphics.*
 import cn.sagacloud.android.cadengine.types.Door
 import cn.sagacloud.android.cadengine.types.Opt
 import com.sybotan.android.graphy.SGraphyItem
+import kotlin.math.atan
+import kotlin.math.atan2
+import kotlin.math.sqrt
+import android.view.View.X
+import kotlin.math.abs
+
 
 /**
  * 门item
@@ -15,53 +18,82 @@ import com.sybotan.android.graphy.SGraphyItem
  */
 class DoorItem(private val data: Door, parent: SGraphyItem? = null) : SGraphyItem(parent) {
     /** 画笔 */
-    private val paint = Paint()
-    /** 墙轮廓 */
-    private val pathList = ArrayList<Path>()
-    /** X坐标最小值  */
-    private var minX = 0f
-    /** X坐标最大值  */
-    private var maxX = 0f
-    /** Y坐标最小值  */
-    private var minY = 0f
-    /** Y坐标最大值  */
-    private var maxY = 0f
+    private val paint1 = Paint()
+    private val paint2 = Paint()
+    /** 门长度 */
+    private var d = 0f
+
+    /** 角度  */
+    private var angle = 0f
+    /** 旋转点 */
+    private var p = PointF(0f, 0f)
+    /** 旋转起始角度 */
+    private var startAng = 0f
 
     /**
      * 构造
      */
     init {
+
         try {
-            if (data.outLine != null && data.outLine!!.size > 0 && data.outLine!![0].size > 0) {
-                minX = data.outLine!![0][0].x
-                maxX = data.outLine!![0][0].x
-                minY = data.outLine!![0][0].y
-                maxY = data.outLine!![0][0].y
+            paint1.style = Paint.Style.STROKE
+            paint1.color = Opt.doorColor
+            paint1.strokeWidth = 100f
+            paint2.style = Paint.Style.STROKE
+            paint2.color = Opt.doorColor
+            paint2.strokeWidth = 50f
+            paint2.pathEffect = DashPathEffect(floatArrayOf(200f, 200f), 0f)
 
-                for (line in data.outLine!!) {
-                    if (line.size < 1) {
-                        continue
-                    }
+            zOrder = 2f
+            if (data.outLine != null && data.outLine!!.size > 0 && data.outLine!![0].size >= 2) {
+                // 取门的两个端点
+                val p1 = PointF(data.outLine!![0][0].x, -data.outLine!![0][0].y)
+                val p2 = PointF(data.outLine!![0][1].x, -data.outLine!![0][1].y)
+                d = sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y))
 
-                    val path = Path()
-                    path.moveTo(line[0].x, -line[0].y)
-                    for (p in line) {
-                        if (p.x < minX) {
-                            minX = p.x
+                // 角度为
+                val fo = atan2(-data.faceDirection!!.y, data.faceDirection!!.x)
+                // 门朝向角度
+                angle = if(data.faceDirection!!.x > 0) {
+                    fo
+                } else {
+                    fo + Math.PI.toFloat()
+                }
+
+//                val dir = data.faceDirection!!.x * (data.handDirection!!.y - data.faceDirection!!.y) - data.faceDirection!!.y * (data.handDirection!!.x - data.faceDirection!!.x)
+//                if (dir < 0) {
+//                    startAng = -90f
+//                }
+
+                // 计算旋转点
+                if (abs(data.handDirection!!.x) > abs(data.handDirection!!.y)) {
+                    p = if (data.handDirection!!.x > 0) {
+                        if (p1.x > p2.x) {
+                            p1
+                        } else {
+                            p2
                         }
-                        if (p.x > maxX) {
-                            maxX = p.x
+                    } else {
+                        if (p1.x < p2.x) {
+                            p1
+                        } else {
+                            p2
                         }
-                        if (-p.y < minY) {
-                            minY = -p.y
+                    }
+                } else {
+                    p = if (data.handDirection!!.y > 0) {
+                        if (p1.y > p2.y) {
+                            p1
+                        } else {
+                            p2
                         }
-                        if (-p.y > maxY) {
-                            maxY = -p.y
+                    } else {
+                        if (p1.y < p2.y) {
+                            p1
+                        } else {
+                            p2
                         }
-                        path.lineTo(p.x, -p.y)
                     }
-                    path.close()
-                    pathList.add(path)
                 }
             }
         } catch (e: Exception) {
@@ -70,26 +102,21 @@ class DoorItem(private val data: Door, parent: SGraphyItem? = null) : SGraphyIte
     } // Constructor
 
     /**
-     * Item对象边界区域
-     *
-     * @return  边界区域
-     */
-    override fun boundingRect(): RectF {
-        return RectF(minX, minY, maxX, maxY)
-    } // Function boundingRect()
-
-    /**
      * Item绘制操作
      *
      * @param   canvas          画布
      * @param   rect            绘制区域
      */
     override fun onDraw(canvas : Canvas, rect: RectF) {
-        paint.style = Paint.Style.FILL
-        paint.color = Opt.windowColor
-        for (path in pathList) {
-            canvas.drawPath(path, paint);
-        }
+        canvas.translate(p.x, p.y);
+        canvas.rotate(angle * 180f / Math.PI.toFloat())
+
+        paint1.style = Paint.Style.FILL
+        canvas.drawArc(-d, -d, d, d, 0f, 360f ,false, paint1)
+
+//        canvas.drawLine(0f, 0f, d, 0f, paint1)
+//
+//        canvas.drawArc(-d, -d, d, d, startAng, 90f ,false, paint2)
         super.onDraw(canvas, rect)
     } // Function onDraw()
 } // Class DoorItem

+ 1 - 0
cadengine/src/main/java/cn/sagacloud/android/cadengine/items/SpaceItem.kt

@@ -28,6 +28,7 @@ class SpaceItem(private val data: Space, parent: SGraphyItem? = null) : SGraphyI
 
     init {
         try {
+            zOrder = 1f
             if (data.outLine != null && data.outLine!!.size > 0 && data.outLine!![0].size > 0) {
                 minX = data.outLine!![0][0].x
                 maxX = data.outLine!![0][0].x

+ 1 - 3
cadengine/src/main/java/cn/sagacloud/android/cadengine/items/WallItem.kt

@@ -1,11 +1,9 @@
 package cn.sagacloud.android.cadengine.items
 
 import android.graphics.*
-import android.util.Log
 import cn.sagacloud.android.cadengine.types.Opt
 import cn.sagacloud.android.cadengine.types.Wall
 import com.sybotan.android.graphy.SGraphyItem
-import com.sybotan.base.extensions.toJson
 
 /**
  * 墙item
@@ -87,7 +85,7 @@ class WallItem(private val data: Wall, parent: SGraphyItem? = null) : SGraphyIte
         paint.style = Paint.Style.FILL
         paint.color = Opt.wallColor
         for (path in pathList) {
-            canvas.drawPath(path, paint);
+            canvas.drawPath(path, paint)
         }
         super.onDraw(canvas, rect)
     } // Function onDraw()

+ 1 - 1
gradle.properties

@@ -3,7 +3,7 @@ org.gradle.jvmargs = -Xmx1536m
 
 SYBOTAN_URL = http://www.sybotan.com
 SYBOTAN_KOTLIN_VERSION = 1.4.63
-SYBOTAN_ANDROID_VERSION = 1.2.31
+SYBOTAN_ANDROID_VERSION = 1.2.34
 SAGACLOUD_VERSION = 1.0.0
 SYBOTAN_CODE = 5