
import { iconService } from '../Service/IconService'
import { coordinate } from '../Coordinate'
import { floorplanService } from '../Service/FloorplanService'
import { mathUtil } from '../MathUtil';

//独立的，不会和线条以及其他构件融合
export default class AddIcon {
    constructor() {
        this.start = null
        this.end = null;
        this.currentVectorId = null
    }

    execute(position){
        if(this.start == null){
            this.start = coordinate.getXYFromScreen(position)
        }
        else if(this.currentVectorId == null){
            this.end = {
                x:position.x,
                y:position.y
            };
            const icon = iconService.createIcon(this.start,position)
            this.currentVectorId = icon.vectorId
        }
        else {
            this.end = {
                x:position.x,
                y:position.y
            };
            const icon = floorplanService.getIcon(this.currentVectorId)
            icon.updatePoints(position,2)
        }
    }

    clear(){
        this.start = null
        this.end = null;
        this.currentVectorId = null
    }
}

const addIcon = new AddIcon()
export { addIcon }