package cl.jtv;

/*
 * ComandoIMG.java
 *
 * Created on 18 de febrero de 2003, 10:36 PM
 */

/**
 *
 * @author  Administrador
 * @version 
 */
public class ComandoIMG extends Comando {
    
    private Maquina insertedMachine;
    boolean leftInsert;
    int xOld,yOld;
    /** Creates new ComandoIMG */
    public ComandoIMG(Object newArtefacto, Vector2 newVector2,Maquina newInsertedMachine,boolean newLeftInsert) {
        super(newArtefacto,newVector2);
        insertedMachine = newInsertedMachine;
        leftInsert = newLeftInsert;
        xOld = insertedMachine.x0;
        yOld = insertedMachine.y0;
        Maquina previa = insertedMachine.previa;
        
        inverse = new ComandoEM(insertedMachine,vector2);
        
        while(previa!=null){
            ComandoMM2 comandoMM2 = new ComandoMM2(previa,null);
            this.addComando(comandoMM2);
            //inverse.addComando(comandoMM2);
            previa = previa.previa;
        }
        Maquina proxima = insertedMachine.proxima;
        while(proxima!=null && !(proxima instanceof EnlaceCompuesto)){
            ComandoMM2 comandoMM2 = new ComandoMM2(proxima,null);
            this.addComando(comandoMM2);
            //inverse.addComando(comandoMM2);
            proxima = proxima.proxima;
        }
            
        
    }

    public void doIt() {
        
        Maquina maquina = (Maquina)artefacto;
        
        maquina.insertMachine(this.insertedMachine,this.leftInsert,vector2);
        this.insertedMachine.x0 = xOld; //this.leftInsert?maquina.x0-this.insertedMachine.getDelta():maquina.x0+maquina.getDelta();
        this.insertedMachine.y0 = yOld;
        this.insertedMachine.updateBounds();
        //maquina.insertMachine(this.insertedMachine,this.leftInsert,vector2);        
        super.doIt();       
    }
    
    
}
