//火灾 控制类
import vtkUnstructuredDataReader from "../reader/UnstructuredDataReader.js";

export class waterControl {
    constructor(){
        //事故编号
        this.aid=5 ;
        //当前步数
        this.step;
        //总步数
        this.stepsum=10;
        //url
        this._url ="http://192.168.0.131:8187/TransServlet?channelNo=service&clientToken=e47b87eec69545559d1e81e56626da68&userId=5f06c8bc77234f969d13e160b54c27e3&aid=5&stype=Water";
        //几何数据
        this.polydata;
        //Scalars 数据 array[setp]=Map(scalars,value[points]=array),
        this.scalars=new Array();
        this.reader =vtkUnstructuredDataReader.newInstance();
    }
    //几何数据初始化
   async initGemetry() {
    await this.reader.setUrl(this._url+"&transCode=D000014" ).then(() => {
            this.polydata= this.reader.getOutputData(0);
        });
        console.log( this.polydata);
    }
    //标量数据初始化
    async initScalrs(){
        //火灾
        for (let index = 0; index <= this.stepsum; index++) {
           await this.reader.setUrl(this._url+"&transCode=D00009&step="+ index ).then(() => {
            const scalarMap = this.reader.getOutputData(1);
            this.scalars.push(scalarMap);
            });
        }
        console.log( this.scalars);
    }
    //获取第几步标量数据
    async getScalrsByStep(step){
        this.step =step;
        this.reader.setUrl(this._url+"&transCode=D00009&step="+ this.step ).then(() => {
            const scalarMap = this.reader.getOutputData(1);
            this.scalars[step]=scalarMap;
        });
    }
    
}

export function createWaterControl(){
    return new waterControl();
}