浏览代码

fix 空间多个数组显示

lihao1 3 年之前
父节点
当前提交
bef6a5b347

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

@@ -275,14 +275,14 @@ open class FloorScene : SGraphyScene() {
             tunableSpace.zOrder = 99996f
             addItem(tunableSpace)
 
-            val space = Space()
-            space.outLine = tunableSpace.data.outLine
-            space.name = tunableSpace.data.name
-            val item = SpaceNameItem(space)
-            item.zOrder = 99999f
-            item.isVisible = isShowSpace
-            spaceNameList.add(item)
-            addItem(item)
+//            val space = Space()
+//            space.outLine = tunableSpace.data.outLine
+//            space.name = tunableSpace.data.name
+//            val item = SpaceNameItem(space)
+//            item.zOrder = 99999f
+//            item.isVisible = isShowSpace
+//            spaceNameList.add(item)
+//            addItem(item)
         }
     } // Function addBaseMapItem()
 

+ 51 - 51
cadengine/src/main/java/cn/sagacloud/android/cadengine/items/SpaceNameItem.kt

@@ -36,59 +36,59 @@ class SpaceNameItem(val data: Space, parent: SGraphyItem? = null) : SGraphyItem(
     private var textY = 0f
 
 
-    init {
-        try {
-            zOrder = 1f
-            if (data.outLine != null && data.outLine!!.size > 0 && data.outLine!![0].size > 0) {
-                minX = 9999999f
-                maxX = -9999999f
-                minY = 9999999f
-                maxY = -9999999f
-
-                for (line in data.outLine!!) {
-                    if (line.size < 1) {
-                        continue
-                    }
-                    for (p in line) {
-                        if (p.x < minX) {
-                            minX = p.x
-                        }
-                        if (p.x > maxX) {
-                            maxX = p.x
-                        }
-                        if (-p.y < minY) {
-                            minY = -p.y
-                        }
-                        if (-p.y > maxY) {
-                            maxY = -p.y
-                        }
-                    }
-                }
-            }
-        } catch (e: Exception) {
-            e.printStackTrace()
-        }
-        paintText.style = Paint.Style.FILL
-        paintText.flags = Paint.ANTI_ALIAS_FLAG
-        paintText.color = Opt.textColor
-        paintText.textSize = 700f
-        val font: Typeface = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD)
-        paintText.setTypeface(font)
-//        paintText.textSkewX - 0.5f
-
-//        textX = (minX + ((maxX - minX) / 2)) /*- 250*/
-//        textY = (minY + ((maxY - minY) / 2)) - paintText.measureText(data.name!!) / 2
+//    init {
+//        try {
+//            zOrder = 1f
+//            if (data.outLine != null && data.outLine!!.size > 0 && data.outLine!![0].size > 0) {
+//                minX = 9999999f
+//                maxX = -9999999f
+//                minY = 9999999f
+//                maxY = -9999999f
 //
-//        if (data.name!!.contains("走廊2")) {
-//            textX -= 400f
-//        } else if (data.name!!.contains("走廊1")) {
-//            textY -= 5000f
-//        } else if (data.name!!.contains("财务室旁开间办公区")) {
-//            textY -= 2000f
+//                for (line in data.outLine!!) {
+//                    if (line.size < 1) {
+//                        continue
+//                    }
+//                    for (p in line) {
+//                        if (p.x < minX) {
+//                            minX = p.x
+//                        }
+//                        if (p.x > maxX) {
+//                            maxX = p.x
+//                        }
+//                        if (-p.y < minY) {
+//                            minY = -p.y
+//                        }
+//                        if (-p.y > maxY) {
+//                            maxY = -p.y
+//                        }
+//                    }
+//                }
+//            }
+//        } catch (e: Exception) {
+//            e.printStackTrace()
 //        }
-        textX = (minX + ((maxX - minX) / 2)) - paintText.measureText(data.name!!) / 2 /*- 250*/
-        textY = (minY + ((maxY - minY) / 2)) + 125f
-    } // Constructor
+//        paintText.style = Paint.Style.FILL
+//        paintText.flags = Paint.ANTI_ALIAS_FLAG
+//        paintText.color = Opt.textColor
+//        paintText.textSize = 700f
+//        val font: Typeface = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD)
+//        paintText.setTypeface(font)
+////        paintText.textSkewX - 0.5f
+//
+////        textX = (minX + ((maxX - minX) / 2)) /*- 250*/
+////        textY = (minY + ((maxY - minY) / 2)) - paintText.measureText(data.name!!) / 2
+////
+////        if (data.name!!.contains("走廊2")) {
+////            textX -= 400f
+////        } else if (data.name!!.contains("走廊1")) {
+////            textY -= 5000f
+////        } else if (data.name!!.contains("财务室旁开间办公区")) {
+////            textY -= 2000f
+////        }
+//        textX = (minX + ((maxX - minX) / 2)) - paintText.measureText(data.name!!) / 2 /*- 250*/
+//        textY = (minY + ((maxY - minY) / 2)) + 125f
+//    } // Constructor
 
 
     /**

+ 38 - 35
cadengine/src/main/java/cn/sagacloud/android/cadengine/items/TunableSpaceItem.kt

@@ -3,6 +3,8 @@ package cn.sagacloud.android.cadengine.items
 import android.graphics.*
 import android.os.Parcelable
 import android.text.TextPaint
+import android.util.Log
+import android.widget.Toast
 import cn.sagacloud.android.cadengine.Opt
 import cn.sagacloud.android.cadengine.types.TunableSpace
 import com.sybotan.android.graphy.SGraphyItem
@@ -20,7 +22,7 @@ class TunableSpaceItem(val data: TunableSpace, parent: SGraphyItem? = null) : SG
     private val paintText = TextPaint()
 
     /** 墙轮廓 */
-    private var spacePath: Path? = null
+    private var spacePathList: ArrayList<Path> = ArrayList()
     /** 空间轮廓线坐标list  */
     //private val pointArr = ArrayList<ArrayList<PointF>>()
     /** X坐标最小值  */
@@ -40,42 +42,41 @@ class TunableSpaceItem(val data: TunableSpace, parent: SGraphyItem? = null) : SG
     init {
         try {
             zOrder = 1f
-            if (data.outLine != null && data.outLine!!.size > 0 && data.outLine!![0].size > 0) {
-                minX = 9999999f
-                maxX = -9999999f
-                minY = 9999999f
-                maxY = -9999999f
-
-                for (line in data.outLine!!) {
-                    if (line.size < 1) {
-                        mPoints.add(PointF(data.outLine!![0][0].x, data.outLine!![0][0].y))
-                        continue
-                    }
-                    var path = Path()
-                    path.moveTo(line[0].x, -line[0].y)
-                    for (p in line) {
-                        if (p.x < minX) {
-                            minX = p.x
-                        }
-                        if (p.x > maxX) {
-                            maxX = p.x
-                        }
-                        if (-p.y < minY) {
-                            minY = -p.y
+            if (data.outLine != null && data.outLine!!.size > 0) {
+                for (outLineList in data.outLine!!){
+                    minX = 9999999f
+                    maxX = -9999999f
+                    minY = 9999999f
+                    maxY = -9999999f
+
+                    for (line in outLineList) {
+                        if (line.size < 1) {
+                            mPoints.add(PointF(line[0].x, line[0].y))
+                            continue
                         }
-                        if (-p.y > maxY) {
-                            maxY = -p.y
+                        var path = Path()
+                        path.moveTo(line[0].x, -line[0].y)
+                        for (p in line) {
+                            if (p.x < minX) {
+                                minX = p.x
+                            }
+                            if (p.x > maxX) {
+                                maxX = p.x
+                            }
+                            if (-p.y < minY) {
+                                minY = -p.y
+                            }
+                            if (-p.y > maxY) {
+                                maxY = -p.y
+                            }
+                            mPoints.add(PointF(p.x, p.y))
+                            path.lineTo(p.x, -p.y)
                         }
-                        mPoints.add(PointF(p.x, p.y))
-                        path.lineTo(p.x, -p.y)
-                    }
-                    path.close()
-                    if (spacePath == null) {
-                        spacePath = path
-                    } else {
-                        // spacePath.b
+                        path.close()
+                        spacePathList.add(path)
                     }
                 }
+
             }
         } catch (e: Exception) {
             e.printStackTrace()
@@ -200,7 +201,7 @@ class TunableSpaceItem(val data: TunableSpace, parent: SGraphyItem? = null) : SG
      * @param   rect            绘制区域
      */
     override fun onDraw(canvas: Canvas) {
-        if (null != spacePath) {
+        if (spacePathList != null && spacePathList.size > 0) {
             if (data.isShow) {
                 paint.color = Color.parseColor("#FFDAAD")
             } else if (paint.color == Opt.spaceChoseColor) {
@@ -219,7 +220,9 @@ class TunableSpaceItem(val data: TunableSpace, parent: SGraphyItem? = null) : SG
             }
             outPaint.color = Color.parseColor("#7E96FF")
 //            canvas.drawPath(spacePath!!, outPaint)
-            canvas.drawPath(spacePath!!, paint)
+            for (spacePath in spacePathList) {
+                canvas.drawPath(spacePath, paint)
+            }
         }
         super.onDraw(canvas)
     } // Function onDraw()

+ 1 - 1
cadengine/src/main/java/cn/sagacloud/android/cadengine/types/TunableSpace.kt

@@ -10,7 +10,7 @@ import android.os.Parcelable
  */
 class TunableSpace() :Parcelable {
     /** 轮廓线  */
-    var outLine: ArrayList<ArrayList<PointZ>>? = null
+    var outLine: ArrayList<ArrayList<ArrayList<PointZ>>> = ArrayList()
     var name: String? = null
     var floorName: String? = null
     var floorId: String? = null

+ 3 - 3
demo/src/main/java/com/framework/mvvm/model/db/dao/JobSpaceDao.kt

@@ -14,13 +14,13 @@ interface JobSpaceDao {
     @Query("select * from job_space where id = :id")
     suspend fun getSpaceById(id: String): JobSpaceEntity
 
-    @Query("select * from job_space where space_id = :id")
+    @Query("select * from job_space where space_id = :id and valid = 1")
     suspend fun getSpaceBySpaceId(id: String): JobSpaceEntity
 
-    @Query("select * from job_space where floor_id = :id and arch_state =:archState")
+    @Query("select * from job_space where floor_id = :id and arch_state =:archState and valid = 1")
     suspend fun getSpaceByArchStateFloorId(id: String, archState: String): List<JobSpaceEntity>
 
-    @Query("select * from job_space where floor_id = :id and equip_state =:equipState")
+    @Query("select * from job_space where floor_id = :id and equip_state =:equipState and valid = 1")
     suspend fun getSpaceByEquipStateFloorId(id: String, equipState: String): List<JobSpaceEntity>
 
     @Query("select * from job_space where building_id = :id")

+ 1 - 1
demo/src/main/java/com/framework/mvvm/model/db/dao/ObjectDao.kt

@@ -11,7 +11,7 @@ interface ObjectDao {
     @Query("select * from object")
     suspend fun getObjects(): List<ObjectEntity>
 
-    @Query("select * from object where id = :id")
+    @Query("select * from object where id = :id and valid = 1")
     suspend fun getObjectById(id: String): ObjectEntity?
 
     @Query("select * from object where bim_id = :bimId")

+ 1 - 1
demo/src/main/java/com/sybotan/android/demo/activities/ChooseSpaceActivity.kt

@@ -308,7 +308,7 @@ class ChooseSpaceActivity : BaseActivity(), DIAware {
                             val info = gson.fromJson(space.infos, SpaceInfo::class.java)
                             if (!CommonUtils.IsNull(info.outline)) {
                                 val tunableSpace = TunableSpace()
-                                tunableSpace.outLine = info.outline[0]
+                                tunableSpace.outLine = info.outline
                                 tunableSpace.isShow = true
                                 tunableSpace.id = space.id
                                 tunableSpace.name = ObjectNameUtils.getEquipName(space)

+ 30 - 30
demo/src/main/java/com/sybotan/android/demo/activities/GraphyActivity.kt

@@ -1181,34 +1181,34 @@ class GraphyActivity : BaseActivity(), ICaptureStatusListener, ICameraChangedCal
             piprRv.layoutManager = GridLayoutManager(this, 3, LinearLayoutManager.HORIZONTAL, false)
             graphyVM.pipeList()
         }
-//        roof.setOnCheckedChangeListener { buttonView, isChecked ->
-//            if (isChecked) {
-//                equipEdit.setText("")
-//                equipEdit.isEnabled = false
-//                equipEdit.alpha = 0.5f
-//            }
-//        }
-//        wall.setOnCheckedChangeListener { buttonView, isChecked ->
-//            if (isChecked) {
-//                equipEdit.setText("")
-//                equipEdit.isEnabled = true
-//                equipEdit.alpha = 1f
-//            }
-//        }
-//        air.setOnCheckedChangeListener { buttonView, isChecked ->
-//            if (isChecked) {
-//                equipEdit.setText("")
-//                equipEdit.isEnabled = true
-//                equipEdit.alpha = 1f
-//            }
-//        }
-//        floor.setOnCheckedChangeListener { buttonView, isChecked ->
-//            if (isChecked) {
-//                equipEdit.setText("0")
-//                equipEdit.isEnabled = true
-//                equipEdit.alpha = 1f
-//            }
-//        }
+        roof.setOnCheckedChangeListener { buttonView, isChecked ->
+            if (isChecked) {
+                equipEdit.setText("")
+                equipEdit.isEnabled = false
+                equipEdit.alpha = 0.5f
+            }
+        }
+        wall.setOnCheckedChangeListener { buttonView, isChecked ->
+            if (isChecked) {
+                equipEdit.setText("")
+                equipEdit.isEnabled = true
+                equipEdit.alpha = 1f
+            }
+        }
+        air.setOnCheckedChangeListener { buttonView, isChecked ->
+            if (isChecked) {
+                equipEdit.setText("")
+                equipEdit.isEnabled = true
+                equipEdit.alpha = 1f
+            }
+        }
+        floor.setOnCheckedChangeListener { buttonView, isChecked ->
+            if (isChecked) {
+                equipEdit.setText("0")
+                equipEdit.isEnabled = true
+                equipEdit.alpha = 1f
+            }
+        }
     }
 
     private fun initProblemPicture(point: PointItem?) {
@@ -1259,7 +1259,7 @@ class GraphyActivity : BaseActivity(), ICaptureStatusListener, ICameraChangedCal
                     for (model in list) {
                         if (model.outline != null && !model.outline!!.isEmpty()) {
                             val space = Space()
-                            space.outLine = model.outline.get(0)
+                            space.outLine = model.outline[0]
                             space.name = model.name
                             val nameItem = SpaceNameItem(space)
                             nameItem.zOrder = 99999f
@@ -1269,7 +1269,7 @@ class GraphyActivity : BaseActivity(), ICaptureStatusListener, ICameraChangedCal
 
                             val tunableSpace = TunableSpace()
                             tunableSpace.apply {
-                                outLine = model.outline.get(0)
+                                outLine = model.outline
                                 objectEntity = gson.toJson(model.objectEntity)
                                 this.name = model.name
 //                                initSpaceState(tunableSpace, model.archState!!, model.equipState!!)

+ 4 - 4
demo/src/main/java/com/sybotan/android/demo/activities/ServeAreaActivity.kt

@@ -199,7 +199,7 @@ class ServeAreaActivity : BaseActivity(), DIAware {
                         val isContain = Lasso.isPolygonContainsPoint(space.mPoints, android.graphics.Point(x.toInt(), -y.toInt()))
                         if (isContain) {
                             val tunableSpace = TunableSpace()
-                            tunableSpace.outLine = space.data.outLine
+                            tunableSpace.outLine!!.add(space.data.outLine!!)
                             val item = TunableSpaceItem(tunableSpace)
                             item.zOrder = 99996f
                             tunableSpaceList.add(item)
@@ -304,7 +304,7 @@ class ServeAreaActivity : BaseActivity(), DIAware {
                     for (model in list) {
                         if (model.outline != null && !model.outline!!.isEmpty()) {
                             val space = Space()
-                            space.outLine = model.outline.get(0)
+                            space.outLine = model.outline[0]
                             space.name = model.name
                             val nameItem = SpaceNameItem(space)
                             nameItem.zOrder = 99999f
@@ -314,7 +314,7 @@ class ServeAreaActivity : BaseActivity(), DIAware {
 
                             val tunableSpace = TunableSpace()
                             tunableSpace.apply {
-                                outLine = model.outline.get(0)
+                                outLine = model.outline
                                 objectEntity = gson.toJson(model.objectEntity)
                                 this.name = model.name
                                 jobStatus = model.job
@@ -374,7 +374,7 @@ class ServeAreaActivity : BaseActivity(), DIAware {
                     val param = params as ArrayList<ArrayList<ArrayList<PointZ>>>
                     for (space in param) {
                         val tunableSpace = TunableSpace()
-                        tunableSpace.outLine = space
+                        tunableSpace.outLine = param
                         val item = TunableSpaceItem(tunableSpace)
                         item.zOrder = 99996f
                         tunableSpaceList.add(item)

+ 14 - 9
demo/src/main/java/com/sybotan/android/demo/activities/SpaceMapActivity.kt

@@ -764,18 +764,18 @@ class SpaceMapActivity : BaseActivity(), DIAware {
                     val list = params as (List<SpaceJobModel>)
                     for (model in list) {
                         if (model.outline != null && model.outline!!.isNotEmpty()) {
-                            val space = Space()
-                            space.outLine = model.outline[0]
-                            space.name = model.name
-                            val nameItem = SpaceNameItem(space)
-                            nameItem.zOrder = 99999f
-                            nameItem.isVisible = scene.isShowSpace
-                            scene.spaceNameList.add(nameItem)
-                            scene.addItem(nameItem)
+//                            val space = Space()
+//                            space.outLine = model.outline
+//                            space.name = model.name
+//                            val nameItem = SpaceNameItem(space)
+//                            nameItem.zOrder = 99999f
+//                            nameItem.isVisible = scene.isShowSpace
+//                            scene.spaceNameList.add(nameItem)
+//                            scene.addItem(nameItem)
 
                             val tunableSpace = TunableSpace()
                             tunableSpace.apply {
-                                outLine = model.outline[0]
+                                outLine = model.outline
                                 objectEntity = gson.toJson(model.objectEntity)
                                 this.name = model.name
                                 jobStatus = model.job
@@ -893,6 +893,11 @@ class SpaceMapActivity : BaseActivity(), DIAware {
             }
         }, this, buildingId, floorId, projectId)
         spaceMapVM.getMap()
+//        spaceMapVM.getSpaceJob()
+    }
+
+    override fun onResume() {
+        super.onResume()
         spaceMapVM.getSpaceJob()
     }
 

+ 2 - 2
demo/src/main/java/com/sybotan/android/demo/viewmodel/ChooseSpaceVM.kt

@@ -78,7 +78,7 @@ class ChooseSpaceVM(
         viewModelScope.launch {
             val geom = ArrayList<ArrayList<ArrayList<PointZ>>>()
             for (space in spaces) {
-                geom.add(space.data.outLine!!)
+                geom.addAll(space.data.outLine!!)
             }
             var entity = repo.getServeAreaByObjId(deviceId)
             if (entity == null) {
@@ -263,7 +263,7 @@ class ChooseSpaceVM(
 //                spaces.add(info.outline[0])
 
                 val tunableSpace = TunableSpace()
-                tunableSpace.outLine = info.outline[0]
+                tunableSpace.outLine = info.outline
                 tunableSpace.name = ObjectNameUtils.getEquipName(objEntity)
                 tunableSpace.id = objEntity.id
                 val floor = repo.getFloorById(objEntity.floorId!!)

+ 4 - 1
demo/src/main/java/com/sybotan/android/demo/viewmodel/SpaceMapVM.kt

@@ -65,6 +65,9 @@ class SpaceMapVM(
             val spaceJobList = ArrayList<SpaceJobModel>()
             for (spaceEntity in spaceList) {
                 val spaceJobModel = SpaceJobModel()
+                if (spaceEntity.spaceId == "Sp990999000243492b7ec38c4fdd98e9779f3c3757ba"){
+                    ToastUtils.showMyToast("123")
+                }
                 val objectEntity = repo.getObject(spaceEntity.spaceId)
                 if (objectEntity != null) {
                     spaceJobModel.buildingId = buildingId
@@ -420,7 +423,7 @@ class SpaceMapVM(
         viewModelScope.launch {
             val geom = ArrayList<ArrayList<ArrayList<PointZ>>>()
             for (space in spaces) {
-                geom.add(space.data.outLine!!)
+                geom.addAll(space.data.outLine!!)
             }
             var entity = repo.getServeAreaByObjId(deviceId)
             if (entity == null) {