package bk;

import javax.swing.JTree;

import animation.AlgorithmStage;
import animation.AnimatedAlgorithm;
import animation.CodeLine;
import animation.ControlFlow;
import animation.Memory;
import animation.PseudoCodeNode;
import graph.LayeredGraphNode;
import lib.TextLayoutHelper;

/**
 * The stage of the BK node placement algorithm where the blocks are computed.
 * @author kolja
 *
 */
public class BlockCalc implements AlgorithmStage {

    private LayeredGraphNode graph;
    private AnimatedAlgorithm alg;

    public BlockCalc( LayeredGraphNode graph, AnimatedAlgorithm alg  )
    {
        this.graph = graph;
        this.alg = alg;
    }

    @Override
    public PseudoCodeNode createPseudocodeTree( JTree tree ) {
        String[] vars = { "graph", "L", "v", "r", "neighbors" };
        PseudoCodeNode root = new PseudoCodeNode( TextLayoutHelper.setupPseudoCode( "calculateBlockGraph( graph )", vars ), tree, new CodeLine() {

        	private LayeredGraphNode param;
        	
			@Override
			public ControlFlow runForward(Memory m) {
				param = m.<LayeredGraphNode>read( "param1", true );
				m.declare( "graph", param, false );
				m.declare( "Layers", param.getContainedLayers(), false );
				return new ControlFlow( ControlFlow.STEP_INTO );
			}
        	
        }, alg);
        return root;
    }
    
    @Override
    public String getDebugString()
    {
        return "";
    }
}
