|
@@ -12,6 +12,7 @@ import animation.Memory;
|
|
|
import animation.PseudoCodeNode;
|
|
|
import animation.Memory.MemoryType;
|
|
|
import animation.Memory.ReadOnlyMemory;
|
|
|
+import bk.BKNodePlacement.State;
|
|
|
import codelines.AbstractForLoop;
|
|
|
import codelines.DeclareVariable;
|
|
|
import codelines.ForEachLoop;
|
|
@@ -29,10 +30,55 @@ import lib.TextLayoutHelper;
|
|
|
*/
|
|
|
public class BlockCalc implements AlgorithmStage {
|
|
|
|
|
|
+ BKNodePlacement alg;
|
|
|
+
|
|
|
+ public BlockCalc( BKNodePlacement a )
|
|
|
+ {
|
|
|
+ alg = a;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public PseudoCodeNode createPseudocodeTree( JTree tree ) {
|
|
|
String[] vars = { "graph", "L", "r", "neighbors", "layout", "m", "i", "k", "mids" };
|
|
|
- PseudoCodeNode root = new PseudoCodeNode( TextLayoutHelper.setupPseudoCode( "function calculateBlockGraph( layout, graph )", vars ), tree, new FunctionDefinition( new String[]{ "layout", "graph" } ) );
|
|
|
+ @SuppressWarnings("serial")
|
|
|
+ PseudoCodeNode root = new PseudoCodeNode( TextLayoutHelper.setupPseudoCode( "function calculateBlockGraph( layout, graph )", vars ), tree, new FunctionDefinition( new String[]{ "layout", "graph" } ) ) {
|
|
|
+ @Override
|
|
|
+ public String getDebugOutput( Memory m )
|
|
|
+ {
|
|
|
+ switch( m.<String>read( "layout", MemoryType.LOCAL ) )
|
|
|
+ {
|
|
|
+ case "DOWN_RIGHT":
|
|
|
+ alg.setAlgorithmState( State.LAYOUT1 );
|
|
|
+ break;
|
|
|
+ case "DOWN_LEFT":
|
|
|
+ alg.setAlgorithmState( State.LAYOUT2 );
|
|
|
+ break;
|
|
|
+ case "UP_RIGHT":
|
|
|
+ alg.setAlgorithmState( State.LAYOUT3 );
|
|
|
+ break;
|
|
|
+ case "UP_LEFT":
|
|
|
+ alg.setAlgorithmState( State.LAYOUT4 );
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if( m.isSomewhereDefined( "i", MemoryType.LOCAL ) && m.isSomewhereDefined( "k", MemoryType.LOCAL ) )
|
|
|
+ m.<LayeredGraphNode>read( "graph", MemoryType.LOCAL).getContainedLayers().get(m.read( "i", MemoryType.LOCAL )).get(m.<Integer>read( "k", MemoryType.LOCAL ) ).setSelected( LayoutType.fromString( m.read( "layout", MemoryType.LOCAL ) ) );
|
|
|
+ String info = "| Node | Shift | Sink | Root | Align | x | xDef |\n";
|
|
|
+ info += "|------|-------|------|------|-------|-----|--------|\n";
|
|
|
+ LayeredGraphNode graph = m.read( "graph", MemoryType.LOCAL );
|
|
|
+ LayoutType layout = LayoutType.fromString( m.read( "layout", MemoryType.LOCAL ) );
|
|
|
+ for( LayeredGraphNode n : graph.getContainedNodes() )
|
|
|
+ {
|
|
|
+ info += "|" + TextLayoutHelper.strToLen( n.getName(), 6 ) +
|
|
|
+ "|" + TextLayoutHelper.strToLen( n.getShift( layout ) + "", 7 ) +
|
|
|
+ "|" + TextLayoutHelper.strToLen( n.getSink( layout ).getName(), 6 ) +
|
|
|
+ "|" + TextLayoutHelper.strToLen( n.getRoot( layout ).getName(), 6 ) +
|
|
|
+ "|" + TextLayoutHelper.strToLen( n.getAlign( layout ).getName(), 7 ) +
|
|
|
+ "|" + TextLayoutHelper.strToLen( n.getX( layout ) + "", 5 ) +
|
|
|
+ "|" + TextLayoutHelper.strToLen( !n.isXUndefined( layout ) + "", 8 ) + "|\n";
|
|
|
+ }
|
|
|
+ return info;
|
|
|
+ }
|
|
|
+ };
|
|
|
root.add( new PseudoCodeNode(TextLayoutHelper.setupPseudoCode( "L = graph.getContainedLayers();", vars), tree, new DeclareVariable<ArrayList<ArrayList<LayeredGraphNode>>>( "L" ) {
|
|
|
@Override
|
|
|
protected ArrayList<ArrayList<LayeredGraphNode>> value(ReadOnlyMemory m) {
|