package com.sybotan.android.demo.graphy

import android.content.Context
import android.graphics.PointF
import cn.sagacloud.android.cadengine.FloorScene
import cn.sagacloud.android.cadengine.items.*
import cn.sagacloud.android.cadengine.types.PipeLine
import cn.sagacloud.android.cadengine.types.Point
import com.sybotan.android.demo.activities.GraphyActivity

/**
 * Created by lihao.
 * Date: 2021/9/22
 */
class GraphyHelper(var scene: FloorScene, var context: Context) {

    /**
     * 绘制新设备
     */
    fun addEquip(point: Point): EquipItem {
        val item = EquipItem(context, point)
        item.isVisible = true
        item.zOrder = 1000001f
        scene.equipList.add(item)
        scene.addItem(item)
        return item
    }

    /**
     * 删除所有设备
     */
    fun removeAllEquip() {
        for (item in scene.equipList) {
            scene.removeItem(item)
        }
        scene.equipList.clear()
    }

    /**
     * 绘制管线
     */
    fun addPipeline(pipe: PipeLine): PipeLineItem {
        val pipeItem = PipeLineItem(pipe, null)
        pipeItem.isVisible = true
        pipeItem.zOrder = 100000f
        scene.pipeItemList.add(pipeItem)
        scene.addItem(pipeItem)
        return pipeItem
    }

    /**
     * 删除所有管线
     */
    fun removeAllPipeline() {
        for (item in scene.pipeItemList) {
            scene.removeItem(item)
        }
        scene.pipeItemList.clear()
    }

    /**
     * 增加管道节点
     */
    fun addPipeNode(point: PointF): PipeNodeItem {
        val pipeNodeItem = PipeNodeItem(point, null)
        pipeNodeItem.isVisible = true
        pipeNodeItem.zOrder = 100000f
        scene.addItem(pipeNodeItem)
        scene.pipeNodeList.add(pipeNodeItem)
        return pipeNodeItem
    }

    /**
     * 添加问题点
     */
    fun addPoint(point: Point): PointItem {
        val item = PointItem(point, null, scene.defaultPointScale)
        item.isVisible = true
        item.zOrder = 100000f
        scene.pointItemList.add(item)
        scene.addItem(item)
        return item
    }

    /**
     * 删除所有问题点
     */
    fun removeAllPoint() {
        for (item in scene.pointItemList) {
            scene.removeItem(item)
        }
        scene.pointItemList.clear()
    }

    /**
     * 绘制二维码
     */
    fun addQrcode(context: Context, point: Point) {
        val item = QrcodeItem(context, point)
        item.isVisible = true
        item.zOrder = 100000f
        scene.qrcodeItemList.add(item)
        scene.addItem(item)
    }

    /**
     * 删除所有二维码
     */
    fun removeAllQrcode() {
        for (item in scene.qrcodeItemList) {
            scene.removeItem(item)
        }
        scene.qrcodeItemList.clear()
    }
}