@@ -605,17 +605,22 @@ private void smallUpdate(boolean relayout) {
605
605
}
606
606
607
607
private boolean isVisible (Connection c ) {
608
- if (getModel ().getShowCFG ()) {
609
- return c .isAlwaysVisible ();
610
- }
611
- FigureWidget w1 = getWidget (c .getFrom ().getVertex ());
612
- FigureWidget w2 = getWidget (c .getTo ().getVertex ());
613
-
614
- if (w1 .isVisible () && w2 .isVisible ()) {
615
- return true ;
608
+ // Generally, a connection is visible if its source and destination
609
+ // widgets are visible. An exception is Figure connections in the CFG
610
+ // view, which are never shown.
611
+ if (getModel ().getShowCFG () && c instanceof FigureConnection ) {
612
+ return false ;
613
+ }
614
+ Widget w1 , w2 ;
615
+ if (c instanceof BlockConnection ) {
616
+ w1 = getWidget (((Block )c .getFromCluster ()).getInputBlock ());
617
+ w2 = getWidget (((Block )c .getToCluster ()).getInputBlock ());
618
+ } else {
619
+ assert (c instanceof FigureConnection );
620
+ w1 = getWidget (c .getFrom ().getVertex ());
621
+ w2 = getWidget (c .getTo ().getVertex ());
616
622
}
617
-
618
- return false ;
623
+ return w1 .isVisible () && w2 .isVisible ();
619
624
}
620
625
621
626
private void relayout (Set <Widget > oldVisibleWidgets ) {
@@ -697,10 +702,21 @@ private void doCFGLayout(HashSet<Figure> figures, HashSet<Connection> edges) {
697
702
}
698
703
}
699
704
}
700
- // Add connections for CFG edges.
701
- edges .addAll (diagram .getBlockConnections ());
705
+ // Add visible connections for CFG edges.
706
+ for (BlockConnection c : diagram .getBlockConnections ()) {
707
+ if (isVisible (c )) {
708
+ edges .add (c );
709
+ }
710
+ }
702
711
m .setSubManager (new LinearLayoutManager (figureRank ));
703
- m .setClusters (new HashSet <>(diagram .getBlocks ()));
712
+ Set <Block > visibleBlocks = new HashSet <>();
713
+ for (Block b : diagram .getBlocks ()) {
714
+ BlockWidget w = getWidget (b .getInputBlock ());
715
+ if (w .isVisible ()) {
716
+ visibleBlocks .add (b );
717
+ }
718
+ }
719
+ m .setClusters (new HashSet <>(visibleBlocks ));
704
720
m .doLayout (new LayoutGraph (edges , figures ));
705
721
}
706
722
@@ -795,8 +811,9 @@ private void relayoutWithoutLayout(Set<Widget> oldVisibleWidgets) {
795
811
796
812
if (getModel ().getShowCFG ()) {
797
813
for (BlockConnection c : diagram .getBlockConnections ()) {
798
- SceneAnimator anim = animator ;
799
- processOutputSlot (lastLineCache , null , Collections .singletonList (c ), 0 , null , null , offx2 , offy2 , anim );
814
+ if (isVisible (c )) {
815
+ processOutputSlot (lastLineCache , null , Collections .singletonList (c ), 0 , null , null , offx2 , offy2 , animator );
816
+ }
800
817
}
801
818
}
802
819
@@ -1211,18 +1228,19 @@ private void updateHiddenNodes(Set<Integer> newHiddenNodes, boolean doRelayout)
1211
1228
w .setVisible (false );
1212
1229
}
1213
1230
}
1214
- visibleBlocks .clear ();
1215
- for (InputBlock b : diagram .getGraph ().getBlocks ()) {
1216
- if (!b .isArtificial ()) {
1217
- visibleBlocks .add (b );
1218
- }
1231
+ if (getModel ().getShowEmptyBlocks ()) {
1232
+ // Add remaining blocks.
1233
+ visibleBlocks .addAll (diagram .getGraph ().getBlocks ());
1219
1234
}
1220
1235
}
1221
1236
1222
1237
if (getModel ().getShowBlocks () || getModel ().getShowCFG ()) {
1223
1238
for (InputBlock b : diagram .getGraph ().getBlocks ()) {
1224
1239
1225
- boolean visibleAfter = visibleBlocks .contains (b );
1240
+ // A block is visible if it is marked as such, except for
1241
+ // artificial or null blocks in the CFG view.
1242
+ boolean visibleAfter = visibleBlocks .contains (b ) &&
1243
+ !(getModel ().getShowCFG () && (b .isArtificial () || b .getNodes ().isEmpty ()));
1226
1244
1227
1245
BlockWidget w = getWidget (b );
1228
1246
if (visibleAfter ) {
0 commit comments