|
@@ -39,7 +39,10 @@ public class Combine implements AlgorithmStage {
|
|
|
private PseudoCodeNode setNode;
|
|
|
private PseudoCodeNode loopNode;
|
|
|
private boolean inside;
|
|
|
+ private boolean insideSubgraph;
|
|
|
private boolean breakPoint;
|
|
|
+ private ArrayList< PseudoCodeNode > subgraphNodes;
|
|
|
+ private ArrayList< Combine > subgraphAlgs;
|
|
|
|
|
|
public Combine( LayeredGraphNode graph )
|
|
|
{
|
|
@@ -48,6 +51,14 @@ public class Combine implements AlgorithmStage {
|
|
|
vIndex = 0;
|
|
|
actions = new ArrayList<>();
|
|
|
inside = false;
|
|
|
+ insideSubgraph = false;
|
|
|
+ subgraphNodes = new ArrayList<>();
|
|
|
+ subgraphAlgs = new ArrayList<>();
|
|
|
+ for( @SuppressWarnings("unused") LayeredGraphNode n : graph.getContainedNodes() )
|
|
|
+ {
|
|
|
+ subgraphAlgs.add( null );
|
|
|
+ subgraphNodes.add( null );
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -58,10 +69,10 @@ public class Combine implements AlgorithmStage {
|
|
|
inside = false;
|
|
|
if( !alignNode.isSelected() )
|
|
|
breakPoint |= !alignNode.setSelected( true );
|
|
|
- int tblw = (int)graph.getWidth( LayoutType.TOP_BOTTOM_LEFT );
|
|
|
- int tbrw = (int)graph.getWidth( LayoutType.TOP_BOTTOM_RIGHT );
|
|
|
- int btlw = (int)graph.getWidth( LayoutType.BOTTOM_TOP_LEFT );
|
|
|
- int btrw = (int)graph.getWidth( LayoutType.BOTTOM_TOP_RIGHT );
|
|
|
+ int tblw = (int)calcMaxX( LayoutType.TOP_BOTTOM_LEFT );
|
|
|
+ int tbrw = (int)calcMaxX( LayoutType.TOP_BOTTOM_RIGHT );
|
|
|
+ int btlw = (int)calcMaxX( LayoutType.BOTTOM_TOP_LEFT );
|
|
|
+ int btrw = (int)calcMaxX( LayoutType.BOTTOM_TOP_RIGHT );
|
|
|
LayoutType minLayout = LayoutType.TOP_BOTTOM_LEFT;
|
|
|
int minWidth = tblw;
|
|
|
if( tbrw < minWidth )
|
|
@@ -84,7 +95,9 @@ public class Combine implements AlgorithmStage {
|
|
|
tblOffset = minX - calcMinX( LayoutType.TOP_BOTTOM_LEFT );
|
|
|
btrOffset = minWidth - btrw;
|
|
|
tbrOffset = minWidth - tbrw;
|
|
|
- graph.setColor( Color.BLACK, null );
|
|
|
+ Color oldColor = graph.getColor( LayoutType.TOP_BOTTOM_LEFT );
|
|
|
+ if( oldColor == null )
|
|
|
+ graph.setColor( Color.BLACK, null );
|
|
|
actions.add( 0, () -> {
|
|
|
inside = false;
|
|
|
setNode.setSelected( false );
|
|
@@ -92,7 +105,8 @@ public class Combine implements AlgorithmStage {
|
|
|
if( !alignNode.isSelected() )
|
|
|
breakPoint |= !alignNode.setSelected( true );
|
|
|
state = State.ALIGN;
|
|
|
- graph.setColor( null, null );
|
|
|
+ if( oldColor == null )
|
|
|
+ graph.setColor( null, null );
|
|
|
});
|
|
|
state = State.SET_COORDINATES;
|
|
|
alignNode.setSelected( false );
|
|
@@ -114,6 +128,26 @@ public class Combine implements AlgorithmStage {
|
|
|
inside = true;
|
|
|
LayeredGraphNode current = graph.getContainedNodes().get( vIndex );
|
|
|
current.setSelected( null );
|
|
|
+ if( current.getContainedNodes().size() > 0 )
|
|
|
+ {
|
|
|
+ insideSubgraph = true;
|
|
|
+ boolean breakpoint = false;
|
|
|
+ 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 )
|
|
|
+ return StageStatus.BREAKPOINT;
|
|
|
+ return StageStatus.UNFINISHED;
|
|
|
+ case FINISHED:
|
|
|
+ inside = false;
|
|
|
+ subgraphNodes.get( vIndex ).setSelected( false );
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
ArrayList< Integer > positions = new ArrayList<>();
|
|
|
positions.add( (Integer)(int)current.getX( LayoutType.TOP_BOTTOM_LEFT ) + tblOffset );
|
|
|
positions.add( (Integer)(int)current.getX( LayoutType.TOP_BOTTOM_RIGHT ) + tbrOffset );
|
|
@@ -149,8 +183,40 @@ public class Combine implements AlgorithmStage {
|
|
|
return minX;
|
|
|
}
|
|
|
|
|
|
+ private int calcMaxX( LayoutType layout )
|
|
|
+ {
|
|
|
+ int maxX = 0;
|
|
|
+ if( graph.getContainedNodes().size() > 0 )
|
|
|
+ maxX = (int)graph.getContainedNodes().get( 0 ).getX( layout );
|
|
|
+ for( LayeredGraphNode n : graph.getContainedNodes() )
|
|
|
+ maxX = Math.max( maxX, (int)n.getX( layout ) );
|
|
|
+ return maxX;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public StageStatus backwardStep() {
|
|
|
+ if( vIndex < subgraphAlgs.size() && subgraphAlgs.get( vIndex ) != null )
|
|
|
+ {
|
|
|
+ insideSubgraph = true;
|
|
|
+ boolean breakpoint = false;
|
|
|
+ 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 )
|
|
|
+ return StageStatus.BREAKPOINT;
|
|
|
+ return StageStatus.UNFINISHED;
|
|
|
+ case FINISHED:
|
|
|
+ insideSubgraph = false;
|
|
|
+ subgraphNodes.get( vIndex ).setSelected( false );
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
if( actions.size() == 0 )
|
|
|
{
|
|
|
inside = false;
|
|
@@ -169,6 +235,18 @@ public class Combine implements AlgorithmStage {
|
|
|
alignNode = new PseudoCodeNode( "Align Layouts", tree );
|
|
|
setNode = new PseudoCodeNode( "Align to assignment of smallest width", tree );
|
|
|
loopNode = new PseudoCodeNode( "Set coordinates to average median of aligned candidates", tree );
|
|
|
+ for( int i = 0; i < graph.getContainedNodes().size(); i++ )
|
|
|
+ {
|
|
|
+ LayeredGraphNode current = graph.getContainedNodes().get( i );
|
|
|
+ if( current.getContainedNodes().size() > 0 )
|
|
|
+ {
|
|
|
+ Combine extcalc = new Combine( current );
|
|
|
+ PseudoCodeNode subNode = extcalc.createPseudocodeTree( loopNode.getTree() );
|
|
|
+ loopNode.add( subNode );
|
|
|
+ subgraphAlgs.set( i, extcalc );
|
|
|
+ subgraphNodes.set( i, subNode );
|
|
|
+ }
|
|
|
+ }
|
|
|
setNode.add( loopNode );
|
|
|
root.add( alignNode );
|
|
|
root.add( setNode );
|
|
@@ -186,7 +264,30 @@ public class Combine implements AlgorithmStage {
|
|
|
return stage;
|
|
|
}
|
|
|
else
|
|
|
- return forwardStep();
|
|
|
+ {
|
|
|
+ if( !insideSubgraph )
|
|
|
+ return forwardStep();
|
|
|
+ else
|
|
|
+ {
|
|
|
+ boolean breakpoint = false;
|
|
|
+ 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 )
|
|
|
+ return StageStatus.BREAKPOINT;
|
|
|
+ return StageStatus.UNFINISHED;
|
|
|
+ case FINISHED:
|
|
|
+ inside = false;
|
|
|
+ subgraphNodes.get( vIndex ).setSelected( false );
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return StageStatus.UNFINISHED;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -200,11 +301,34 @@ public class Combine implements AlgorithmStage {
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- State oldState = state;
|
|
|
- StageStatus stage = StageStatus.UNFINISHED;
|
|
|
- while( state == oldState && stage == StageStatus.UNFINISHED )
|
|
|
- stage = forwardStep();
|
|
|
- return stage;
|
|
|
+ if( !insideSubgraph )
|
|
|
+ {
|
|
|
+ State oldState = state;
|
|
|
+ StageStatus stage = StageStatus.UNFINISHED;
|
|
|
+ while( state == oldState && stage == StageStatus.UNFINISHED )
|
|
|
+ stage = forwardStep();
|
|
|
+ return stage;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ boolean breakpoint = false;
|
|
|
+ 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 )
|
|
|
+ return StageStatus.BREAKPOINT;
|
|
|
+ return StageStatus.UNFINISHED;
|
|
|
+ case FINISHED:
|
|
|
+ inside = false;
|
|
|
+ subgraphNodes.get( vIndex ).setSelected( false );
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return StageStatus.UNFINISHED;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -219,7 +343,32 @@ public class Combine implements AlgorithmStage {
|
|
|
return stage;
|
|
|
}
|
|
|
else
|
|
|
- return backwardStep();
|
|
|
+ {
|
|
|
+ if( !insideSubgraph )
|
|
|
+ return backwardStep();
|
|
|
+ else
|
|
|
+ {
|
|
|
+ boolean breakpoint = false;
|
|
|
+ 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 )
|
|
|
+ return StageStatus.BREAKPOINT;
|
|
|
+ return StageStatus.UNFINISHED;
|
|
|
+ case FINISHED:
|
|
|
+ inside = false;
|
|
|
+ subgraphNodes.get( vIndex ).setSelected( false );
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return StageStatus.UNFINISHED;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -233,11 +382,36 @@ public class Combine implements AlgorithmStage {
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- State oldState = state;
|
|
|
- StageStatus stage = StageStatus.UNFINISHED;
|
|
|
- while( state == oldState && stage == StageStatus.UNFINISHED )
|
|
|
- stage = backwardStep();
|
|
|
- return stage;
|
|
|
+ if( !insideSubgraph )
|
|
|
+ {
|
|
|
+ State oldState = state;
|
|
|
+ StageStatus stage = StageStatus.UNFINISHED;
|
|
|
+ while( state == oldState && stage == StageStatus.UNFINISHED )
|
|
|
+ stage = backwardStep();
|
|
|
+ return stage;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ boolean breakpoint = false;
|
|
|
+ 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 )
|
|
|
+ return StageStatus.BREAKPOINT;
|
|
|
+ return StageStatus.UNFINISHED;
|
|
|
+ case FINISHED:
|
|
|
+ inside = false;
|
|
|
+ subgraphNodes.get( vIndex ).setSelected( false );
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return StageStatus.UNFINISHED;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -254,6 +428,13 @@ public class Combine implements AlgorithmStage {
|
|
|
"|" + TextLayoutHelper.strToLen( ( n.getX( LayoutType.BOTTOM_TOP_LEFT ) + btlOffset ) + "", 6 ) +
|
|
|
"|" + TextLayoutHelper.strToLen( ( n.getX( LayoutType.BOTTOM_TOP_RIGHT ) + btrOffset ) + "", 6 ) + "|\n";
|
|
|
}
|
|
|
+ if( insideSubgraph && vIndex < graph.getContainedNodes().size() )
|
|
|
+ {
|
|
|
+ info += "Subgraph of " + graph.getContainedNodes().get( vIndex ).getName() + ":\n";
|
|
|
+ String tmp = subgraphAlgs.get( vIndex ).getDebugString();
|
|
|
+ info += tmp;
|
|
|
+ return info;
|
|
|
+ }
|
|
|
return info;
|
|
|
}
|
|
|
}
|