|
@@ -7,6 +7,9 @@ import javax.swing.JTree;
|
|
|
|
|
|
import animation.AlgorithmStage;
|
|
|
import animation.BackwardAction;
|
|
|
+import animation.CodeLine;
|
|
|
+import animation.ControlFlow;
|
|
|
+import animation.Memory;
|
|
|
import animation.PseudoCodeNode;
|
|
|
import animation.PseudoCodeNode.CodeAction;
|
|
|
import bk.ExtremalLayoutCalc.LayoutType;
|
|
@@ -27,9 +30,7 @@ public class BlockCalc implements AlgorithmStage {
|
|
|
private LayeredGraphNode graph;
|
|
|
private ArrayList< ArrayList< PseudoCodeNode > > subgraphNodes;
|
|
|
private ArrayList< ArrayList< ExtremalLayoutCalc > > subgraphAlgs;
|
|
|
- private ArrayList< BackwardAction > backwards; // TODO: evtl richtigen "Stack" benutzen
|
|
|
private LayoutType layout;
|
|
|
- private PseudoCodeNode loopNode;
|
|
|
private boolean inside;
|
|
|
int step;
|
|
|
|
|
@@ -296,8 +297,42 @@ public class BlockCalc implements AlgorithmStage {
|
|
|
|
|
|
@Override
|
|
|
public PseudoCodeNode createPseudocodeTree( JTree tree ) {
|
|
|
- PseudoCodeNode root = new PseudoCodeNode( TextLayoutHelper.setupPseudoCodeStage("Vertical alignment"), tree );
|
|
|
- loopNode = new PseudoCodeNode( "Loop through all nodes...", tree );
|
|
|
+ String[] vars = { "graph" };
|
|
|
+ PseudoCodeNode root = new PseudoCodeNode( TextLayoutHelper.setupPseudoCode( "calculateBlockGraph( graph )", vars ), tree, CodeLine.DEFAULT_STEP_INTO_STACK );
|
|
|
+ PseudoCodeNode[] nodes = new PseudoCodeNode[12];
|
|
|
+ if( layout == LayoutType.TOP_BOTTOM_LEFT || layout == LayoutType.TOP_BOTTOM_RIGHT )
|
|
|
+ nodes[ 0 ] = new PseudoCodeNode( TextLayoutHelper.setupPseudoCode( "for i=0 to |L|-1 do", vars ), tree, new CodeLine() {
|
|
|
+
|
|
|
+ private boolean initialized = false;
|
|
|
+ private Integer i;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ControlFlow runForward(Memory m) {
|
|
|
+ if( !initialized )
|
|
|
+ {
|
|
|
+ initialized = true;
|
|
|
+ i = 0;
|
|
|
+ m.declare( "i", i, false );
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ if( i >= m.<LayeredGraphNode>read( "graph", false ).getContainedLayers().size() )
|
|
|
+ {
|
|
|
+ m.undeclare( "i", false );
|
|
|
+ return new ControlFlow( ControlFlow.STEP_OVER );
|
|
|
+ }
|
|
|
+ else
|
|
|
+ return new ControlFlow( ControlFlow.STEP_INTO_LOOP );
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ControlFlow runBackward(Memory m) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
do {
|
|
|
LayeredGraphNode current = graph.getContainedLayers().get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) );
|
|
|
if( current.getContainedNodes().size() > 0 )
|
|
@@ -315,144 +350,6 @@ public class BlockCalc implements AlgorithmStage {
|
|
|
root.add( loopNode );
|
|
|
return root;
|
|
|
}
|
|
|
-
|
|
|
- @Override
|
|
|
- public StageStatus forwardStepOver() {
|
|
|
- if( !inside )
|
|
|
- return forwardStep();
|
|
|
- else
|
|
|
- {
|
|
|
- boolean breakpoint = false;
|
|
|
- boolean selected = subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).isSelected();
|
|
|
- CodeAction action = subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( true );
|
|
|
- if( !selected )
|
|
|
- breakpoint |= action == CodeAction.STOP;
|
|
|
- do {
|
|
|
- switch( subgraphAlgs.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).forwardStepOver() )
|
|
|
- {
|
|
|
- case BREAKPOINT:
|
|
|
- return StageStatus.BREAKPOINT;
|
|
|
- case UNFINISHED:
|
|
|
- if( breakpoint )
|
|
|
- return StageStatus.BREAKPOINT;
|
|
|
- return StageStatus.UNFINISHED;
|
|
|
- case FINISHED:
|
|
|
- inside = false;
|
|
|
- subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( false );
|
|
|
- action = null;
|
|
|
- break;
|
|
|
- }
|
|
|
- } while( !breakpoint && action == CodeAction.SKIP );
|
|
|
- return StageStatus.UNFINISHED;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public StageStatus forwardStepOut() {
|
|
|
- if( !inside )
|
|
|
- {
|
|
|
- StageStatus status = StageStatus.UNFINISHED;
|
|
|
- while( status == StageStatus.UNFINISHED )
|
|
|
- status = forwardStep();
|
|
|
- return status;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- boolean breakpoint = false;
|
|
|
- boolean selected = subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).isSelected();
|
|
|
- CodeAction action = subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( true );
|
|
|
- if( !selected )
|
|
|
- breakpoint |= action == CodeAction.STOP;
|
|
|
- do {
|
|
|
- switch( subgraphAlgs.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).forwardStepOut() )
|
|
|
- {
|
|
|
- case BREAKPOINT:
|
|
|
- return StageStatus.BREAKPOINT;
|
|
|
- case UNFINISHED:
|
|
|
- if( breakpoint )
|
|
|
- return StageStatus.BREAKPOINT;
|
|
|
- return StageStatus.UNFINISHED;
|
|
|
- case FINISHED:
|
|
|
- inside = false;
|
|
|
- subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( false );
|
|
|
- action = null;
|
|
|
- break;
|
|
|
- }
|
|
|
- } while( !breakpoint && action == CodeAction.SKIP );
|
|
|
- return StageStatus.UNFINISHED;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public StageStatus backwardStepOver() {
|
|
|
- if( !inside )
|
|
|
- return backwardStep();
|
|
|
- else
|
|
|
- {
|
|
|
- boolean breakpoint = false;
|
|
|
- boolean selected = subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).isSelected();
|
|
|
- CodeAction action = subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( true );
|
|
|
- if( !selected )
|
|
|
- breakpoint |= action == CodeAction.STOP;
|
|
|
- do {
|
|
|
- switch( subgraphAlgs.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).backwardStepOver() )
|
|
|
- {
|
|
|
- case BREAKPOINT:
|
|
|
- return StageStatus.BREAKPOINT;
|
|
|
- case UNFINISHED:
|
|
|
- LayeredGraphNode current = graph.getContainedLayers().get( calcLayerIndex() ).get( nodeIndex );
|
|
|
- current.setSelected( layout );
|
|
|
- if( breakpoint )
|
|
|
- return StageStatus.BREAKPOINT;
|
|
|
- return StageStatus.UNFINISHED;
|
|
|
- case FINISHED:
|
|
|
- inside = false;
|
|
|
- subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( false );
|
|
|
- action = null;
|
|
|
- break;
|
|
|
- }
|
|
|
- } while( !breakpoint && action == CodeAction.SKIP );
|
|
|
- return StageStatus.UNFINISHED;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public StageStatus backwardStepOut() {
|
|
|
- if( !inside )
|
|
|
- {
|
|
|
- StageStatus status = StageStatus.UNFINISHED;
|
|
|
- while( status == StageStatus.UNFINISHED )
|
|
|
- status = backwardStep();
|
|
|
- return status;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- boolean breakpoint = false;
|
|
|
- boolean selected = subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).isSelected();
|
|
|
- CodeAction action = subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( true );
|
|
|
- if( !selected )
|
|
|
- breakpoint |= action == CodeAction.STOP;
|
|
|
- do {
|
|
|
- switch( subgraphAlgs.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).backwardStepOut() )
|
|
|
- {
|
|
|
- case BREAKPOINT:
|
|
|
- return StageStatus.BREAKPOINT;
|
|
|
- case UNFINISHED:
|
|
|
- LayeredGraphNode current = graph.getContainedLayers().get( calcLayerIndex() ).get( nodeIndex );
|
|
|
- current.setSelected( layout );
|
|
|
- if( breakpoint )
|
|
|
- return StageStatus.BREAKPOINT;
|
|
|
- return StageStatus.UNFINISHED;
|
|
|
- case FINISHED:
|
|
|
- inside = false;
|
|
|
- subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( false );
|
|
|
- action = null;
|
|
|
- break;
|
|
|
- }
|
|
|
- } while( !breakpoint && action == CodeAction.SKIP );
|
|
|
- return StageStatus.UNFINISHED;
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
public String getDebugString()
|