|
@@ -1,5 +1,6 @@
|
|
|
package cn.sagacloud.android.cadengine
|
|
|
|
|
|
+import android.graphics.Color
|
|
|
import android.graphics.PointF
|
|
|
import android.util.Log
|
|
|
import cn.sagacloud.android.cadengine.types.*
|
|
@@ -10,8 +11,10 @@ import com.sybotan.base.utils.SHttpUtil
|
|
|
import com.sybotan.base.utils.SJsonUtil
|
|
|
import android.text.TextUtils
|
|
|
import android.util.SizeF
|
|
|
+import android.view.MotionEvent
|
|
|
import cn.sagacloud.android.cadengine.items.*
|
|
|
import cn.sagacloud.android.cadengine.test.GraphyFmItem
|
|
|
+import com.sybotan.android.graphy.SMotionEvent
|
|
|
import com.sybotan.android.graphy.events.SGraphyViewMoveEvent
|
|
|
import com.sybotan.android.graphy.items.SGraphyClockItem
|
|
|
import org.greenrobot.eventbus.Subscribe
|
|
@@ -23,6 +26,11 @@ import org.greenrobot.eventbus.ThreadMode
|
|
|
* @author 庞利祥(sybotan@126.com)
|
|
|
*/
|
|
|
open class FloorScene : SGraphyScene() {
|
|
|
+ //点击事件回调到界面
|
|
|
+ lateinit var topUp: OnSingleTopUp
|
|
|
+ var item: PointItem? = null
|
|
|
+ val point = Point()
|
|
|
+ var canEdit = true
|
|
|
/** item 数据 */
|
|
|
var data: FloorData? = null
|
|
|
set(value) {
|
|
@@ -52,6 +60,7 @@ open class FloorScene : SGraphyScene() {
|
|
|
wall.isVisible = value
|
|
|
}
|
|
|
} // Set isShowWall
|
|
|
+
|
|
|
/** 是否显示虚拟墙 */
|
|
|
var isShowVirtualWall: Boolean = true
|
|
|
set(value) {
|
|
@@ -90,27 +99,36 @@ open class FloorScene : SGraphyScene() {
|
|
|
|
|
|
/** 墙 list */
|
|
|
val wallList = ArrayList<WallItem>()
|
|
|
+
|
|
|
/** 虚拟墙 list */
|
|
|
val virtualWallList = ArrayList<VirtualWallItem>()
|
|
|
+
|
|
|
/** 柱子 list */
|
|
|
var columnList = ArrayList<ColumnItem>()
|
|
|
+
|
|
|
/** 空间 list */
|
|
|
var spaceList = ArrayList<SpaceItem>()
|
|
|
+
|
|
|
/** 空间名称 list */
|
|
|
val spaceNameList = ArrayList<SpatialCenterItem>()
|
|
|
+
|
|
|
/** 门 list */
|
|
|
var doorList = ArrayList<DoorItem>()
|
|
|
+
|
|
|
/** 空间 list */
|
|
|
var windowList = ArrayList<WindowItem>()
|
|
|
|
|
|
+ /** 点 */
|
|
|
+ val pointItemList = java.util.ArrayList<PointItem>()
|
|
|
+
|
|
|
/**
|
|
|
* 获取底图压缩文件
|
|
|
*
|
|
|
* @param url 请求数据文件路径
|
|
|
* @param isGzip 是否为压缩格式
|
|
|
*/
|
|
|
- fun loadUrl(url: String, isGzip: Boolean = true){
|
|
|
- Log.e("PLX","url = $url")
|
|
|
+ fun loadUrl(url: String, isGzip: Boolean = true) {
|
|
|
+ Log.e("PLX", "url = $url")
|
|
|
try {
|
|
|
val json = if (isGzip) {
|
|
|
SHttpUtil.getZipRequest(url)
|
|
@@ -127,7 +145,7 @@ open class FloorScene : SGraphyScene() {
|
|
|
}
|
|
|
} // Function loadUrl()
|
|
|
|
|
|
- fun loadData(json : FloorData){
|
|
|
+ fun loadData(json: FloorData) {
|
|
|
try {
|
|
|
// SJsonUtil.propertyNamingStrategy = PropertyNamingStrategy.PascalCase
|
|
|
Log.e("PLX", "json = ${json?.toJson()}")
|
|
@@ -139,21 +157,12 @@ open class FloorScene : SGraphyScene() {
|
|
|
} // Function loadUrl()
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 增添所有底图 item;
|
|
|
*
|
|
|
* @param data itemList对象
|
|
|
*/
|
|
|
- private fun addBaseMapItem(data: FloorData){
|
|
|
+ private fun addBaseMapItem(data: FloorData) {
|
|
|
if (data.entityList.size < 1) {
|
|
|
return;
|
|
|
}
|
|
@@ -207,6 +216,13 @@ open class FloorScene : SGraphyScene() {
|
|
|
addWindow(window);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ //添加问题点
|
|
|
+ for (item in pointItemList) {
|
|
|
+ item.isVisible = isShowSpace
|
|
|
+ item.zOrder = 100000f
|
|
|
+ addItem(item)
|
|
|
+ }
|
|
|
} // Function addBaseMapItem()
|
|
|
|
|
|
/**
|
|
@@ -214,7 +230,7 @@ open class FloorScene : SGraphyScene() {
|
|
|
*
|
|
|
* @param column 柱子
|
|
|
*/
|
|
|
- open fun addColumn(column: Column){
|
|
|
+ open fun addColumn(column: Column) {
|
|
|
val item = ColumnItem(column)
|
|
|
item.isVisible = isShowColumn
|
|
|
columnList.add(item)
|
|
@@ -226,7 +242,7 @@ open class FloorScene : SGraphyScene() {
|
|
|
*
|
|
|
* @param wall 墙
|
|
|
*/
|
|
|
- open fun addWall(wall: Wall){
|
|
|
+ open fun addWall(wall: Wall) {
|
|
|
val item = WallItem(wall)
|
|
|
item.isVisible = isShowWall
|
|
|
wallList.add(item)
|
|
@@ -238,7 +254,7 @@ open class FloorScene : SGraphyScene() {
|
|
|
*
|
|
|
* @param wall 墙
|
|
|
*/
|
|
|
- open fun addVirtualWall(wall: VirtualWall){
|
|
|
+ open fun addVirtualWall(wall: VirtualWall) {
|
|
|
val item = VirtualWallItem(wall)
|
|
|
item.isVisible = isShowVirtualWall
|
|
|
virtualWallList.add(item)
|
|
@@ -250,9 +266,9 @@ open class FloorScene : SGraphyScene() {
|
|
|
*
|
|
|
* @param space 空间
|
|
|
*/
|
|
|
- open fun addSpace(space: Space){
|
|
|
+ open fun addSpace(space: Space) {
|
|
|
val item = SpaceItem(space)
|
|
|
- Log.e("打印数据",space.toJson())
|
|
|
+ Log.e("打印数据", space.toJson())
|
|
|
item.isVisible = isShowSpace
|
|
|
spaceList.add(item)
|
|
|
addItem(item)
|
|
@@ -263,14 +279,14 @@ open class FloorScene : SGraphyScene() {
|
|
|
*
|
|
|
* @param space 空间
|
|
|
*/
|
|
|
- open fun addSpaceName(space: Space){
|
|
|
- if (space.outLine!=null){
|
|
|
- val scitem= SpatialCenterItem(space.name!!)
|
|
|
- scitem.moveTo(PointF(space.location!!.points!![0].x, -space.location!!.points!![0].y))
|
|
|
- scitem.zOrder= 100f
|
|
|
- scitem.isVisible = true
|
|
|
- spaceNameList.add(scitem)
|
|
|
- this.addItem(scitem)
|
|
|
+ open fun addSpaceName(space: Space) {
|
|
|
+ if (space.outLine != null) {
|
|
|
+ val scitem = SpatialCenterItem(space.name!!)
|
|
|
+ scitem.moveTo(PointF(space.location!!.points!![0].x, -space.location!!.points!![0].y))
|
|
|
+ scitem.zOrder = 100f
|
|
|
+ scitem.isVisible = true
|
|
|
+ spaceNameList.add(scitem)
|
|
|
+ this.addItem(scitem)
|
|
|
|
|
|
}
|
|
|
} // Function addSpace()
|
|
@@ -280,7 +296,7 @@ open class FloorScene : SGraphyScene() {
|
|
|
*
|
|
|
* @param door 门
|
|
|
*/
|
|
|
- open fun addDoor(door: Door){
|
|
|
+ open fun addDoor(door: Door) {
|
|
|
val item = DoorItem(door)
|
|
|
item.isVisible = isShowSpace
|
|
|
doorList.add(item)
|
|
@@ -288,13 +304,12 @@ open class FloorScene : SGraphyScene() {
|
|
|
} // Function addWindow()
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 添加窗户到 scene 中
|
|
|
*
|
|
|
* @param window 窗户
|
|
|
*/
|
|
|
- open fun addWindow(window: Window){
|
|
|
+ open fun addWindow(window: Window) {
|
|
|
val item = WindowItem(window)
|
|
|
item.isVisible = isShowSpace
|
|
|
windowList.add(item)
|
|
@@ -328,12 +343,73 @@ open class FloorScene : SGraphyScene() {
|
|
|
*/
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
fun onMoveEvent(event: SGraphyViewMoveEvent) {
|
|
|
- Log.e("x",event.x.toString())
|
|
|
- Log.e("y",event.y.toString())
|
|
|
+ Log.e("x", event.x.toString())
|
|
|
+ Log.e("y", event.y.toString())
|
|
|
// mapToScene = this.mapToScene( PointF(this.width/2f,this.height/2f))
|
|
|
// if (cadViewMovePointF!=null){
|
|
|
// cadViewMovePointF!!.viewMovePointF(mapToScene)
|
|
|
// }
|
|
|
}
|
|
|
|
|
|
+ override fun onSingleTapUp(e: SMotionEvent): Boolean {
|
|
|
+ var outSide = false
|
|
|
+ //计算控制点的边界
|
|
|
+ //是否已经拥有该点
|
|
|
+ if (canEdit) {
|
|
|
+ //便利该点所在的空间
|
|
|
+ for (space in spaceList) {
|
|
|
+ val polygonContainsPoint = Lasso.isPolygonContainsPoint(
|
|
|
+ space.mPoints,
|
|
|
+ android.graphics.Point(e.x.toInt(), -e.y.toInt())
|
|
|
+ )
|
|
|
+// if (polygonContainsPoint) {
|
|
|
+ outSide = true
|
|
|
+ space.paint.color = Opt.spaceChoseColor
|
|
|
+ space.outPaint.color = Color.rgb(0xbd, 0xe8, 0xfe)
|
|
|
+ point.mX = e.x
|
|
|
+ point.mY = e.y
|
|
|
+ if (item != null) {
|
|
|
+ removeItem(item!!)
|
|
|
+ }
|
|
|
+ item = PointItem(point, null)
|
|
|
+ item!!.isVisible = true
|
|
|
+ item!!.zOrder = 100000f
|
|
|
+ addItem(item!!)
|
|
|
+// } else {
|
|
|
+// space!!.paint.color = Opt.spaceColor
|
|
|
+// space.outPaint.color = Color.rgb(0xff, 0xff, 0xff)
|
|
|
+// }
|
|
|
+ }
|
|
|
+ if (!outSide) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (space in spaceList) {
|
|
|
+ val polygonContainsPoint = Lasso.isPolygonContainsPoint(
|
|
|
+ space.mPoints,
|
|
|
+ android.graphics.Point(e.x.toInt(), -e.y.toInt())
|
|
|
+ )
|
|
|
+ if (polygonContainsPoint) {
|
|
|
+ outSide = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!outSide) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (topUp != null) {
|
|
|
+ topUp.onSingUp(e.x, e.y)
|
|
|
+ }
|
|
|
+ return super.onSingleTapUp(e)
|
|
|
+ }
|
|
|
+
|
|
|
+ interface OnSingleTopUp {
|
|
|
+ fun onSingUp(x: Float, y: Float)
|
|
|
+ }
|
|
|
+
|
|
|
+ fun setOnSingleTopUp(topUp: OnSingleTopUp) {
|
|
|
+ this.topUp = topUp
|
|
|
+ }
|
|
|
+
|
|
|
} // Class FloorScene
|