|
@@ -24,10 +24,12 @@ public class BlockCalc implements AlgorithmStage {
|
|
|
private int nodeIndex;
|
|
|
private int r;
|
|
|
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;
|
|
|
|
|
|
public BlockCalc( LayeredGraphNode graph, LayoutType layout )
|
|
@@ -38,14 +40,21 @@ public class BlockCalc implements AlgorithmStage {
|
|
|
layerIndex = 0;
|
|
|
nodeIndex = 0;
|
|
|
r = 0;
|
|
|
+ subgraphNodes = new ArrayList<>();
|
|
|
subgraphAlgs = new ArrayList<>();
|
|
|
for( ArrayList<LayeredGraphNode> l : graph.getContainedLayers() )
|
|
|
{
|
|
|
+ ArrayList< PseudoCodeNode > nodes = new ArrayList<>();
|
|
|
ArrayList< ExtremalLayoutCalc > algs = new ArrayList<>();
|
|
|
for( int i = 0; i < l.size(); i++ )
|
|
|
+ {
|
|
|
+ nodes.add( null );
|
|
|
algs.add( null );
|
|
|
+ }
|
|
|
subgraphAlgs.add( algs );
|
|
|
+ subgraphNodes.add( nodes );
|
|
|
}
|
|
|
+ inside = false;
|
|
|
backwards = new ArrayList<>();
|
|
|
}
|
|
|
|
|
@@ -91,20 +100,22 @@ public class BlockCalc implements AlgorithmStage {
|
|
|
current.setSelected( layout );
|
|
|
if( current.getContainedNodes().size() > 0 )
|
|
|
{
|
|
|
- if( subgraphAlgs.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ) == null )
|
|
|
- {
|
|
|
- ExtremalLayoutCalc extcalc = new ExtremalLayoutCalc( layout, current );
|
|
|
- loopNode.add( extcalc.createPseudocodeTree( loopNode.getTree() ) );
|
|
|
- subgraphAlgs.get( calcLayerIndex() ).set( calcNodeIndex( nodeIndex ), extcalc );
|
|
|
- }
|
|
|
+ inside = true;
|
|
|
+ boolean breakpoint = false;
|
|
|
+ if( !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).isSelected() )
|
|
|
+ breakpoint |= !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( true );
|
|
|
switch( subgraphAlgs.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).forwardStep() )
|
|
|
{
|
|
|
case BREAKPOINT:
|
|
|
return StageStatus.BREAKPOINT;
|
|
|
case UNFINISHED:
|
|
|
+ if( breakpoint )
|
|
|
+ return StageStatus.BREAKPOINT;
|
|
|
return StageStatus.UNFINISHED;
|
|
|
- default:
|
|
|
- break;
|
|
|
+ case FINISHED:
|
|
|
+ inside = false;
|
|
|
+ subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( false );
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
ArrayList< LayeredGraphEdge > incommingEdges = null;
|
|
@@ -210,12 +221,24 @@ public class BlockCalc implements AlgorithmStage {
|
|
|
public StageStatus backwardStep() {
|
|
|
if( subgraphAlgs.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ) != null )
|
|
|
{
|
|
|
- if( subgraphAlgs.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).backwardStep() == StageStatus.UNFINISHED )
|
|
|
+ inside = true;
|
|
|
+ boolean breakpoint = false;
|
|
|
+ if( !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).isSelected() )
|
|
|
+ breakpoint |= !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( true );
|
|
|
+ switch( subgraphAlgs.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).backwardStep() )
|
|
|
{
|
|
|
+ case BREAKPOINT:
|
|
|
+ return StageStatus.BREAKPOINT;
|
|
|
+ case UNFINISHED:
|
|
|
LayeredGraphNode current = graph.getContainedLayers().get( calcLayerIndex() ).get( nodeIndex );
|
|
|
current.setSelected( layout );
|
|
|
- //current.update();
|
|
|
+ if( breakpoint )
|
|
|
+ return StageStatus.BREAKPOINT;
|
|
|
return StageStatus.UNFINISHED;
|
|
|
+ case FINISHED:
|
|
|
+ inside = false;
|
|
|
+ subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( false );
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
StageStatus status = calcBeforeState();
|
|
@@ -260,33 +283,139 @@ public class BlockCalc implements AlgorithmStage {
|
|
|
public PseudoCodeNode createPseudocodeTree( JTree tree ) {
|
|
|
PseudoCodeNode root = new PseudoCodeNode( "Vertical alignment", tree );
|
|
|
loopNode = new PseudoCodeNode( "Loop through all nodes...", tree );
|
|
|
+ do {
|
|
|
+ LayeredGraphNode current = graph.getContainedLayers().get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) );
|
|
|
+ if( current.getContainedNodes().size() > 0 )
|
|
|
+ {
|
|
|
+ ExtremalLayoutCalc extcalc = new ExtremalLayoutCalc( layout, current );
|
|
|
+ PseudoCodeNode subNode = extcalc.createPseudocodeTree( loopNode.getTree() );
|
|
|
+ loopNode.add( subNode );
|
|
|
+ subgraphAlgs.get( calcLayerIndex() ).set( calcNodeIndex( nodeIndex ), extcalc );
|
|
|
+ subgraphNodes.get( calcLayerIndex() ).set( calcNodeIndex( nodeIndex ), subNode );
|
|
|
+ }
|
|
|
+ } while( calcNextState() != StageStatus.FINISHED );
|
|
|
+ layerIndex = 0;
|
|
|
+ nodeIndex = 0;
|
|
|
+ backwards.clear();
|
|
|
root.add( loopNode );
|
|
|
return root;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public StageStatus forwardStepOver() {
|
|
|
- return forwardStep();
|
|
|
+ if( !inside )
|
|
|
+ return forwardStep();
|
|
|
+ else
|
|
|
+ {
|
|
|
+ boolean breakpoint = false;
|
|
|
+ if( !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).isSelected() )
|
|
|
+ breakpoint |= !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( true );
|
|
|
+ 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 );
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return StageStatus.UNFINISHED;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public StageStatus forwardStepOut() {
|
|
|
- StageStatus status = StageStatus.UNFINISHED;
|
|
|
- while( status == StageStatus.UNFINISHED )
|
|
|
- status = forwardStep();
|
|
|
- return status;
|
|
|
+ if( !inside )
|
|
|
+ {
|
|
|
+ StageStatus status = StageStatus.UNFINISHED;
|
|
|
+ while( status == StageStatus.UNFINISHED )
|
|
|
+ status = forwardStep();
|
|
|
+ return status;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ boolean breakpoint = false;
|
|
|
+ if( !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).isSelected() )
|
|
|
+ breakpoint |= !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( true );
|
|
|
+ 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 );
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return StageStatus.UNFINISHED;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public StageStatus backwardStepOver() {
|
|
|
- return backwardStep();
|
|
|
+ if( !inside )
|
|
|
+ return backwardStep();
|
|
|
+ else
|
|
|
+ {
|
|
|
+ boolean breakpoint = false;
|
|
|
+ if( !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).isSelected() )
|
|
|
+ breakpoint |= !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( true );
|
|
|
+ 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 );
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return StageStatus.UNFINISHED;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public StageStatus backwardStepOut() {
|
|
|
- StageStatus status = StageStatus.UNFINISHED;
|
|
|
- while( status == StageStatus.UNFINISHED )
|
|
|
- status = backwardStep();
|
|
|
- return status;
|
|
|
+ if( !inside )
|
|
|
+ {
|
|
|
+ StageStatus status = StageStatus.UNFINISHED;
|
|
|
+ while( status == StageStatus.UNFINISHED )
|
|
|
+ status = backwardStep();
|
|
|
+ return status;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ boolean breakpoint = false;
|
|
|
+ if( !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).isSelected() )
|
|
|
+ breakpoint |= !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( true );
|
|
|
+ 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 );
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return StageStatus.UNFINISHED;
|
|
|
+ }
|
|
|
}
|
|
|
}
|