|
@@ -9,6 +9,7 @@ import javax.swing.JTree;
|
|
|
import animation.AlgorithmStage;
|
|
|
import animation.BackwardAction;
|
|
|
import animation.PseudoCodeNode;
|
|
|
+import animation.PseudoCodeNode.CodeAction;
|
|
|
import bk.ExtremalLayoutCalc.LayoutType;
|
|
|
import graph.LayeredGraphNode;
|
|
|
import lib.TextLayoutHelper;
|
|
@@ -41,6 +42,7 @@ public class Combine implements AlgorithmStage {
|
|
|
private boolean inside;
|
|
|
private boolean insideSubgraph;
|
|
|
private boolean breakPoint;
|
|
|
+ private boolean skipBackwards;
|
|
|
private ArrayList< PseudoCodeNode > subgraphNodes;
|
|
|
private ArrayList< Combine > subgraphAlgs;
|
|
|
|
|
@@ -52,6 +54,7 @@ public class Combine implements AlgorithmStage {
|
|
|
actions = new ArrayList<>();
|
|
|
inside = false;
|
|
|
insideSubgraph = false;
|
|
|
+ skipBackwards = false;
|
|
|
subgraphNodes = new ArrayList<>();
|
|
|
subgraphAlgs = new ArrayList<>();
|
|
|
for( @SuppressWarnings("unused") LayeredGraphNode n : graph.getContainedNodes() )
|
|
@@ -67,8 +70,9 @@ public class Combine implements AlgorithmStage {
|
|
|
if( state == State.ALIGN )
|
|
|
{
|
|
|
inside = false;
|
|
|
+ CodeAction action = alignNode.setSelected( true );
|
|
|
if( !alignNode.isSelected() )
|
|
|
- breakPoint |= !alignNode.setSelected( true );
|
|
|
+ breakPoint |= action == CodeAction.STOP;
|
|
|
int tblw = (int)calcMaxX( LayoutType.TOP_BOTTOM_LEFT );
|
|
|
int tbrw = (int)calcMaxX( LayoutType.TOP_BOTTOM_RIGHT );
|
|
|
int btlw = (int)calcMaxX( LayoutType.BOTTOM_TOP_LEFT );
|
|
@@ -103,21 +107,30 @@ public class Combine implements AlgorithmStage {
|
|
|
loopNode.setSelected( false );
|
|
|
setNode.setSelected( false );
|
|
|
breakPoint = false;
|
|
|
+ CodeAction ac = alignNode.setSelected( true );
|
|
|
if( !alignNode.isSelected() )
|
|
|
- breakPoint |= !alignNode.setSelected( true );
|
|
|
+ breakPoint |= ac == CodeAction.STOP;
|
|
|
+ skipBackwards = ac == CodeAction.SKIP;
|
|
|
state = State.ALIGN;
|
|
|
if( oldColor == null )
|
|
|
graph.setColor( null, null );
|
|
|
});
|
|
|
state = State.SET_COORDINATES;
|
|
|
alignNode.setSelected( false );
|
|
|
+ CodeAction ac = setNode.setSelected( true );
|
|
|
+ boolean skip = ac == CodeAction.SKIP;
|
|
|
if( !setNode.isSelected() )
|
|
|
- breakPoint |= !setNode.setSelected( true );
|
|
|
- breakPoint |= !loopNode.setSelected( true );
|
|
|
+ breakPoint |= ac == CodeAction.STOP;
|
|
|
+ ac = loopNode.setSelected( true );
|
|
|
+ breakPoint |= ac == CodeAction.STOP;
|
|
|
+ skip |= ac == CodeAction.SKIP;
|
|
|
+ if( (action == CodeAction.SKIP || skip) && !breakPoint )
|
|
|
+ return forwardStep();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- breakPoint = !loopNode.setSelected( true );
|
|
|
+ CodeAction action = loopNode.setSelected( true );
|
|
|
+ breakPoint = action == CodeAction.STOP;
|
|
|
if( vIndex >= graph.getContainedNodes().size() )
|
|
|
{
|
|
|
inside = false;
|
|
@@ -133,21 +146,25 @@ public class Combine implements AlgorithmStage {
|
|
|
{
|
|
|
insideSubgraph = true;
|
|
|
boolean breakpoint = false;
|
|
|
+ CodeAction ac = subgraphNodes.get( vIndex ).setSelected( true );
|
|
|
if( !subgraphNodes.get( vIndex ).isSelected() )
|
|
|
- breakpoint |= !subgraphNodes.get( vIndex ).setSelected( true );
|
|
|
- switch( subgraphAlgs.get( vIndex ).forwardStep() )
|
|
|
- {
|
|
|
- case BREAKPOINT:
|
|
|
- return StageStatus.BREAKPOINT;
|
|
|
- case UNFINISHED:
|
|
|
- if( breakpoint )
|
|
|
+ breakpoint |= ac == CodeAction.STOP;
|
|
|
+ do {
|
|
|
+ switch( subgraphAlgs.get( vIndex ).forwardStep() )
|
|
|
+ {
|
|
|
+ case BREAKPOINT:
|
|
|
return StageStatus.BREAKPOINT;
|
|
|
- return StageStatus.UNFINISHED;
|
|
|
- case FINISHED:
|
|
|
- inside = false;
|
|
|
- subgraphNodes.get( vIndex ).setSelected( false );
|
|
|
- break;
|
|
|
- }
|
|
|
+ case UNFINISHED:
|
|
|
+ if( breakpoint )
|
|
|
+ return StageStatus.BREAKPOINT;
|
|
|
+ return StageStatus.UNFINISHED;
|
|
|
+ case FINISHED:
|
|
|
+ inside = false;
|
|
|
+ subgraphNodes.get( vIndex ).setSelected( false );
|
|
|
+ ac = null;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } while( ac == CodeAction.SKIP && !breakPoint );
|
|
|
}
|
|
|
ArrayList< Integer > positions = new ArrayList<>();
|
|
|
positions.add( (Integer)(int)current.getX( LayoutType.TOP_BOTTOM_LEFT ) + tblOffset );
|
|
@@ -160,14 +177,20 @@ public class Combine implements AlgorithmStage {
|
|
|
actions.add( 0, () -> {
|
|
|
inside = true;
|
|
|
breakPoint = false;
|
|
|
+ CodeAction ac = setNode.setSelected( true );
|
|
|
if( !setNode.isSelected() )
|
|
|
- breakPoint |= !setNode.setSelected( true );
|
|
|
- breakPoint |= !loopNode.setSelected( true );
|
|
|
+ breakPoint |= ac == CodeAction.STOP;
|
|
|
+ skipBackwards = ac == CodeAction.SKIP;
|
|
|
+ ac = loopNode.setSelected( true );
|
|
|
+ breakPoint |= ac == CodeAction.STOP;
|
|
|
+ skipBackwards |= ac == CodeAction.SKIP;
|
|
|
vIndex--;
|
|
|
current.setX( oldX, true, LayoutType.COMBINED );
|
|
|
current.setSelected( null );
|
|
|
});
|
|
|
vIndex++;
|
|
|
+ if( action == CodeAction.SKIP && !breakPoint )
|
|
|
+ return forwardStep();
|
|
|
}
|
|
|
if( breakPoint )
|
|
|
return StageStatus.BREAKPOINT;
|
|
@@ -200,23 +223,27 @@ public class Combine implements AlgorithmStage {
|
|
|
{
|
|
|
insideSubgraph = true;
|
|
|
boolean breakpoint = false;
|
|
|
+ CodeAction action = subgraphNodes.get( vIndex ).setSelected( true );
|
|
|
if( !subgraphNodes.get( vIndex ).isSelected() )
|
|
|
- breakpoint |= !subgraphNodes.get( vIndex ).setSelected( true );
|
|
|
- switch( subgraphAlgs.get( vIndex ).backwardStep() )
|
|
|
- {
|
|
|
- case BREAKPOINT:
|
|
|
- return StageStatus.BREAKPOINT;
|
|
|
- case UNFINISHED:
|
|
|
- LayeredGraphNode current = graph.getContainedNodes().get( vIndex );
|
|
|
- current.setSelected( null );
|
|
|
- if( breakpoint )
|
|
|
+ breakpoint |= action == CodeAction.STOP;
|
|
|
+ do {
|
|
|
+ switch( subgraphAlgs.get( vIndex ).backwardStep() )
|
|
|
+ {
|
|
|
+ case BREAKPOINT:
|
|
|
return StageStatus.BREAKPOINT;
|
|
|
- return StageStatus.UNFINISHED;
|
|
|
- case FINISHED:
|
|
|
- insideSubgraph = false;
|
|
|
- subgraphNodes.get( vIndex ).setSelected( false );
|
|
|
- break;
|
|
|
- }
|
|
|
+ case UNFINISHED:
|
|
|
+ LayeredGraphNode current = graph.getContainedNodes().get( vIndex );
|
|
|
+ current.setSelected( null );
|
|
|
+ if( breakpoint )
|
|
|
+ return StageStatus.BREAKPOINT;
|
|
|
+ return StageStatus.UNFINISHED;
|
|
|
+ case FINISHED:
|
|
|
+ insideSubgraph = false;
|
|
|
+ subgraphNodes.get( vIndex ).setSelected( false );
|
|
|
+ action = null;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } while( !breakpoint && action == CodeAction.SKIP );
|
|
|
}
|
|
|
if( actions.size() == 0 )
|
|
|
{
|
|
@@ -228,6 +255,8 @@ public class Combine implements AlgorithmStage {
|
|
|
actions.remove( 0 );
|
|
|
if( breakPoint )
|
|
|
return StageStatus.BREAKPOINT;
|
|
|
+ if( skipBackwards )
|
|
|
+ return backwardStep();
|
|
|
return StageStatus.UNFINISHED;
|
|
|
}
|
|
|
|
|
@@ -272,21 +301,25 @@ public class Combine implements AlgorithmStage {
|
|
|
else
|
|
|
{
|
|
|
boolean breakpoint = false;
|
|
|
+ CodeAction action = subgraphNodes.get( vIndex ).setSelected( true );
|
|
|
if( !subgraphNodes.get( vIndex ).isSelected() )
|
|
|
- breakpoint |= !subgraphNodes.get( vIndex ).setSelected( true );
|
|
|
- switch( subgraphAlgs.get( vIndex ).forwardStepOver() )
|
|
|
- {
|
|
|
- case BREAKPOINT:
|
|
|
- return StageStatus.BREAKPOINT;
|
|
|
- case UNFINISHED:
|
|
|
- if( breakpoint )
|
|
|
+ breakpoint |= action == CodeAction.STOP;
|
|
|
+ do {
|
|
|
+ switch( subgraphAlgs.get( vIndex ).forwardStepOver() )
|
|
|
+ {
|
|
|
+ case BREAKPOINT:
|
|
|
return StageStatus.BREAKPOINT;
|
|
|
- return StageStatus.UNFINISHED;
|
|
|
- case FINISHED:
|
|
|
- inside = false;
|
|
|
- subgraphNodes.get( vIndex ).setSelected( false );
|
|
|
- break;
|
|
|
- }
|
|
|
+ case UNFINISHED:
|
|
|
+ if( breakpoint )
|
|
|
+ return StageStatus.BREAKPOINT;
|
|
|
+ return StageStatus.UNFINISHED;
|
|
|
+ case FINISHED:
|
|
|
+ inside = false;
|
|
|
+ subgraphNodes.get( vIndex ).setSelected( false );
|
|
|
+ action = null;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } while( !breakpoint && action == CodeAction.SKIP );
|
|
|
return StageStatus.UNFINISHED;
|
|
|
}
|
|
|
}
|
|
@@ -314,21 +347,25 @@ public class Combine implements AlgorithmStage {
|
|
|
else
|
|
|
{
|
|
|
boolean breakpoint = false;
|
|
|
+ CodeAction action = subgraphNodes.get( vIndex ).setSelected( true );
|
|
|
if( !subgraphNodes.get( vIndex ).isSelected() )
|
|
|
- breakpoint |= !subgraphNodes.get( vIndex ).setSelected( true );
|
|
|
- switch( subgraphAlgs.get( vIndex ).forwardStepOut() )
|
|
|
- {
|
|
|
- case BREAKPOINT:
|
|
|
- return StageStatus.BREAKPOINT;
|
|
|
- case UNFINISHED:
|
|
|
- if( breakpoint )
|
|
|
+ breakpoint |= action == CodeAction.STOP;
|
|
|
+ do {
|
|
|
+ switch( subgraphAlgs.get( vIndex ).forwardStepOut() )
|
|
|
+ {
|
|
|
+ case BREAKPOINT:
|
|
|
return StageStatus.BREAKPOINT;
|
|
|
- return StageStatus.UNFINISHED;
|
|
|
- case FINISHED:
|
|
|
- inside = false;
|
|
|
- subgraphNodes.get( vIndex ).setSelected( false );
|
|
|
- break;
|
|
|
- }
|
|
|
+ case UNFINISHED:
|
|
|
+ if( breakpoint )
|
|
|
+ return StageStatus.BREAKPOINT;
|
|
|
+ return StageStatus.UNFINISHED;
|
|
|
+ case FINISHED:
|
|
|
+ inside = false;
|
|
|
+ subgraphNodes.get( vIndex ).setSelected( false );
|
|
|
+ action = null;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } while( !breakpoint && action == CodeAction.SKIP );
|
|
|
return StageStatus.UNFINISHED;
|
|
|
}
|
|
|
}
|
|
@@ -351,23 +388,27 @@ public class Combine implements AlgorithmStage {
|
|
|
else
|
|
|
{
|
|
|
boolean breakpoint = false;
|
|
|
+ CodeAction action = subgraphNodes.get( vIndex ).setSelected( true );
|
|
|
if( !subgraphNodes.get( vIndex ).isSelected() )
|
|
|
- breakpoint |= !subgraphNodes.get( vIndex ).setSelected( true );
|
|
|
- switch( subgraphAlgs.get( vIndex ).backwardStepOver() )
|
|
|
- {
|
|
|
- case BREAKPOINT:
|
|
|
- return StageStatus.BREAKPOINT;
|
|
|
- case UNFINISHED:
|
|
|
- LayeredGraphNode current = graph.getContainedNodes().get( vIndex );
|
|
|
- current.setSelected( null );
|
|
|
- if( breakpoint )
|
|
|
+ breakpoint |= action == CodeAction.STOP;
|
|
|
+ do {
|
|
|
+ switch( subgraphAlgs.get( vIndex ).backwardStepOver() )
|
|
|
+ {
|
|
|
+ case BREAKPOINT:
|
|
|
return StageStatus.BREAKPOINT;
|
|
|
- return StageStatus.UNFINISHED;
|
|
|
- case FINISHED:
|
|
|
- inside = false;
|
|
|
- subgraphNodes.get( vIndex ).setSelected( false );
|
|
|
- break;
|
|
|
- }
|
|
|
+ case UNFINISHED:
|
|
|
+ LayeredGraphNode current = graph.getContainedNodes().get( vIndex );
|
|
|
+ current.setSelected( null );
|
|
|
+ if( breakpoint )
|
|
|
+ return StageStatus.BREAKPOINT;
|
|
|
+ return StageStatus.UNFINISHED;
|
|
|
+ case FINISHED:
|
|
|
+ inside = false;
|
|
|
+ subgraphNodes.get( vIndex ).setSelected( false );
|
|
|
+ action = null;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } while( !breakpoint && action == CodeAction.SKIP );
|
|
|
return StageStatus.UNFINISHED;
|
|
|
}
|
|
|
}
|
|
@@ -395,23 +436,27 @@ public class Combine implements AlgorithmStage {
|
|
|
else
|
|
|
{
|
|
|
boolean breakpoint = false;
|
|
|
+ CodeAction action = subgraphNodes.get( vIndex ).setSelected( true );
|
|
|
if( !subgraphNodes.get( vIndex ).isSelected() )
|
|
|
- breakpoint |= !subgraphNodes.get( vIndex ).setSelected( true );
|
|
|
- switch( subgraphAlgs.get( vIndex ).backwardStepOut() )
|
|
|
- {
|
|
|
- case BREAKPOINT:
|
|
|
- return StageStatus.BREAKPOINT;
|
|
|
- case UNFINISHED:
|
|
|
- LayeredGraphNode current = graph.getContainedNodes().get( vIndex );
|
|
|
- current.setSelected( null );
|
|
|
- if( breakpoint )
|
|
|
+ breakpoint |= action == CodeAction.STOP;
|
|
|
+ do {
|
|
|
+ switch( subgraphAlgs.get( vIndex ).backwardStepOut() )
|
|
|
+ {
|
|
|
+ case BREAKPOINT:
|
|
|
return StageStatus.BREAKPOINT;
|
|
|
- return StageStatus.UNFINISHED;
|
|
|
- case FINISHED:
|
|
|
- inside = false;
|
|
|
- subgraphNodes.get( vIndex ).setSelected( false );
|
|
|
- break;
|
|
|
- }
|
|
|
+ case UNFINISHED:
|
|
|
+ LayeredGraphNode current = graph.getContainedNodes().get( vIndex );
|
|
|
+ current.setSelected( null );
|
|
|
+ if( breakpoint )
|
|
|
+ return StageStatus.BREAKPOINT;
|
|
|
+ return StageStatus.UNFINISHED;
|
|
|
+ case FINISHED:
|
|
|
+ inside = false;
|
|
|
+ subgraphNodes.get( vIndex ).setSelected( false );
|
|
|
+ action = null;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } while( !breakpoint && action == CodeAction.SKIP );
|
|
|
return StageStatus.UNFINISHED;
|
|
|
}
|
|
|
}
|