package com.ys.bdtp.cad.items

import android.graphics.*
import com.ys.bdtp.cad.types.PipeLine
import com.ys.bdtp.graph.SGraphyItem
import java.util.*

/**
 * Created by lihao.
 * Date: 2021/6/7
 */
class PipeLineItem(val data: PipeLine, parent: SGraphyItem? = null) : SGraphyItem(parent) {
    /** 画笔 */
    val paint = Paint()
    val mPaint_inner = Paint()

    /** 管道轮廓 */
    private var pipePath: Path? = null

    /** 管道轮廓线坐标list  */
    private val pointArr = ArrayList<ArrayList<PointF>>()

    val outPaint = Paint()

    var mPoints = ArrayList<PointF>()

    /** X坐标最小值  */
    private var minX = 0f

    /** X坐标最大值  */
    private var maxX = 0f

    /** Y坐标最小值  */
    private var minY = 0f

    /** Y坐标最大值  */
    private var maxY = 0f

    init {
        try {
            zOrder = 1f

            minX = data.points!![0].x
            maxX = data.points!![0].x
            minY = data.points!![0].y
            maxY = data.points!![0].y
            val path = Path()
            path.moveTo(data.points!![0].x, -data.points!![0].y)
            for (line in data.points!!) {

                path.lineTo(line.x, -line.y)

                if (pipePath == null) {
                    pipePath = path;
                } else {
                    // spacePath.b
                }
            }

        } catch (e: Exception) {
            e.printStackTrace()
        }
        outPaint.style = Paint.Style.STROKE
        outPaint.strokeJoin = Paint.Join.ROUND
        outPaint.isAntiAlias = true
        outPaint.color = Color.rgb(0x66, 0x66, 0xff)
        outPaint.strokeWidth = 150f

        //内圈
        mPaint_inner.color = Color.parseColor("#0c90eb")
        mPaint_inner.isAntiAlias = true
        mPaint_inner.style = Paint.Style.FILL
    } // Constructor


    /**
     * Item绘制操作
     *
     * @param   canvas          画布
     * @param   rect            绘制区域
     */
    override fun onDraw(canvas: Canvas) {
        if (null != pipePath) {
//            paint.style = Paint.Style.FILL

//            canvas.drawPath(pipePath!!, paint)


            canvas.drawPath(pipePath!!, outPaint)
            val size = data.points!!.size - 1
            val get = data.points!!.get(size)
            val get1 = data.points!!.get(0)
            canvas.drawCircle(get1.x, -get1.y, 60f, mPaint_inner)
            canvas.drawCircle(get.x, -get.y, 60f, mPaint_inner)
        }
    } // Function onDraw()
}