From 719927895bd02fe9e1a531e76255b48caa41538e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A1lm=C3=A1n=20Vince?= <30904009+DRKV333@users.noreply.github.com> Date: Wed, 2 Aug 2023 19:43:17 +0200 Subject: [PATCH 1/2] Fixed nested togethers not working --- .../sourceforge/plantuml/svek/Cluster.java | 33 +++++++++++++------ .../plantuml/svek/ClusterDotString.java | 7 ++-- .../plantuml/svek/DotStringFactory.java | 2 +- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/net/sourceforge/plantuml/svek/Cluster.java b/src/net/sourceforge/plantuml/svek/Cluster.java index 8bcd1519d..e3ef695e0 100644 --- a/src/net/sourceforge/plantuml/svek/Cluster.java +++ b/src/net/sourceforge/plantuml/svek/Cluster.java @@ -485,7 +485,7 @@ public class Cluster implements Moveable { private int togetherCounter = 0; - private void printTogether(Together together, StringBuilder sb, List nodesOrderedWithoutTop, + private void printTogether(Together together, Collection otherTogethers, StringBuilder sb, List nodesOrderedWithoutTop, StringBounder stringBounder, Collection lines, DotMode dotMode, GraphvizVersion graphvizVersion, UmlDiagramType type) { sb.append("subgraph " + getClusterId() + "t" + togetherCounter + " {\n"); @@ -495,7 +495,11 @@ public class Cluster implements Moveable { for (Cluster child : children) if (child.group.getTogether() == together) - child.printInternal(sb, lines, stringBounder, dotMode, graphvizVersion, type); + child.printInternal(sb, lines, stringBounder, dotMode, graphvizVersion, type, together); + + for (Together otherTogether : otherTogethers) + if (otherTogether.getParent() == together) + printTogether(otherTogether, otherTogethers, sb, nodesOrderedWithoutTop, stringBounder, lines, dotMode, graphvizVersion, type); sb.append("}\n"); togetherCounter++; @@ -503,7 +507,7 @@ public class Cluster implements Moveable { } public SvekNode printCluster2(StringBuilder sb, Collection lines, StringBounder stringBounder, - DotMode dotMode, GraphvizVersion graphvizVersion, UmlDiagramType type) { + DotMode dotMode, GraphvizVersion graphvizVersion, UmlDiagramType type, Together parentTogether) { SvekNode added = null; final Collection togethers = new LinkedHashSet<>(); @@ -513,16 +517,17 @@ public class Cluster implements Moveable { if (together == null) node.appendShape(sb, stringBounder); else - togethers.add(together); + addTogetherWithParents(togethers, together); added = node; } for (Cluster child : children) if (child.group.getTogether() != null) - togethers.add(child.group.getTogether()); + addTogetherWithParents(togethers, child.group.getTogether()); for (Together together : togethers) - printTogether(together, sb, nodesOrderedWithoutTop, stringBounder, lines, dotMode, graphvizVersion, type); + if (together.getParent() == parentTogether) + printTogether(together, togethers, sb, nodesOrderedWithoutTop, stringBounder, lines, dotMode, graphvizVersion, type); if (skinParam.useRankSame() && dotMode != DotMode.NO_LEFT_RIGHT_AND_XLABEL && graphvizVersion.ignoreHorizontalLinks() == false) @@ -530,11 +535,19 @@ public class Cluster implements Moveable { for (Cluster child : children) if (child.group.getTogether() == null) - child.printInternal(sb, lines, stringBounder, dotMode, graphvizVersion, type); + child.printInternal(sb, lines, stringBounder, dotMode, graphvizVersion, type, parentTogether); return added; } + private static void addTogetherWithParents(Collection collection, Together together) { + Together t = together; + while (t != null) { + collection.add(t); + t = t.getParent(); + } + } + public void printCluster3_forKermor(StringBuilder sb, Collection lines, StringBounder stringBounder, DotMode dotMode, GraphvizVersion graphvizVersion, UmlDiagramType type) { final List tmp = getNodes(EntityPosition.getNormals()); @@ -548,12 +561,12 @@ public class Cluster implements Moveable { } for (Cluster child : getChildren()) - child.printInternal(sb, lines, stringBounder, dotMode, graphvizVersion, type); + child.printInternal(sb, lines, stringBounder, dotMode, graphvizVersion, type, null); } private void printInternal(StringBuilder sb, Collection lines, StringBounder stringBounder, - DotMode dotMode, GraphvizVersion graphvizVersion, UmlDiagramType type) { - new ClusterDotString(this, skinParam).printInternal(sb, lines, stringBounder, dotMode, graphvizVersion, type); + DotMode dotMode, GraphvizVersion graphvizVersion, UmlDiagramType type, Together parentTogether) { + new ClusterDotString(this, skinParam).printInternal(sb, lines, stringBounder, dotMode, graphvizVersion, type, parentTogether); } private void appendRankSame(StringBuilder sb, Collection lines) { diff --git a/src/net/sourceforge/plantuml/svek/ClusterDotString.java b/src/net/sourceforge/plantuml/svek/ClusterDotString.java index 4a0f8dd76..e0a910fcb 100644 --- a/src/net/sourceforge/plantuml/svek/ClusterDotString.java +++ b/src/net/sourceforge/plantuml/svek/ClusterDotString.java @@ -46,6 +46,7 @@ import java.util.Set; import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.abel.EntityPosition; +import net.sourceforge.plantuml.abel.Together; import net.sourceforge.plantuml.decoration.symbol.USymbols; import net.sourceforge.plantuml.dot.GraphvizVersion; import net.sourceforge.plantuml.klimt.font.StringBounder; @@ -71,7 +72,7 @@ public class ClusterDotString { } void printInternal(StringBuilder sb, Collection lines, StringBounder stringBounder, DotMode dotMode, - GraphvizVersion graphvizVersion, UmlDiagramType type) { + GraphvizVersion graphvizVersion, UmlDiagramType type, Together parentTogether) { if (cluster.diagram.getPragma().useKermor()) { new ClusterDotStringKermor(cluster, skinParam).printInternal(sb, lines, stringBounder, dotMode, graphvizVersion, type); @@ -81,7 +82,7 @@ public class ClusterDotString { if (packed) { cluster.printCluster1(sb, lines, stringBounder); - final SvekNode added = cluster.printCluster2(sb, lines, stringBounder, dotMode, graphvizVersion, type); + final SvekNode added = cluster.printCluster2(sb, lines, stringBounder, dotMode, graphvizVersion, type, parentTogether); return; } @@ -170,7 +171,7 @@ public class ClusterDotString { // ----------- cluster.printCluster1(sb, lines, stringBounder); - final SvekNode added = cluster.printCluster2(sb, lines, stringBounder, dotMode, graphvizVersion, type); + final SvekNode added = cluster.printCluster2(sb, lines, stringBounder, dotMode, graphvizVersion, type, parentTogether); if (entityPositionsExceptNormal.size() > 0) if (hasPort()) { sb.append(empty() + " [shape=rect,width=.01,height=.01,label="); diff --git a/src/net/sourceforge/plantuml/svek/DotStringFactory.java b/src/net/sourceforge/plantuml/svek/DotStringFactory.java index ba93eb3cb..16faceb96 100644 --- a/src/net/sourceforge/plantuml/svek/DotStringFactory.java +++ b/src/net/sourceforge/plantuml/svek/DotStringFactory.java @@ -214,7 +214,7 @@ public class DotStringFactory implements Moveable { line.appendLine(getGraphvizVersion(), sb, dotMode, dotSplines); root.printCluster2(sb, bibliotekon.allLines(), stringBounder, dotMode, getGraphvizVersion(), - umlDiagramType); + umlDiagramType, null); for (SvekLine line : bibliotekon.lines1()) line.appendLine(getGraphvizVersion(), sb, dotMode, dotSplines); From 5096c1b9a47165489405500f284c39941ef708d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A1lm=C3=A1n=20Vince?= <30904009+DRKV333@users.noreply.github.com> Date: Fri, 4 Aug 2023 00:32:23 +0200 Subject: [PATCH 2/2] Fixed printing togethers in nested groups --- src/net/sourceforge/plantuml/svek/Cluster.java | 14 +++++++------- .../plantuml/svek/ClusterDotString.java | 7 +++---- .../plantuml/svek/DotStringFactory.java | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/net/sourceforge/plantuml/svek/Cluster.java b/src/net/sourceforge/plantuml/svek/Cluster.java index e3ef695e0..0a4908806 100644 --- a/src/net/sourceforge/plantuml/svek/Cluster.java +++ b/src/net/sourceforge/plantuml/svek/Cluster.java @@ -495,7 +495,7 @@ public class Cluster implements Moveable { for (Cluster child : children) if (child.group.getTogether() == together) - child.printInternal(sb, lines, stringBounder, dotMode, graphvizVersion, type, together); + child.printInternal(sb, lines, stringBounder, dotMode, graphvizVersion, type); for (Together otherTogether : otherTogethers) if (otherTogether.getParent() == together) @@ -507,7 +507,7 @@ public class Cluster implements Moveable { } public SvekNode printCluster2(StringBuilder sb, Collection lines, StringBounder stringBounder, - DotMode dotMode, GraphvizVersion graphvizVersion, UmlDiagramType type, Together parentTogether) { + DotMode dotMode, GraphvizVersion graphvizVersion, UmlDiagramType type) { SvekNode added = null; final Collection togethers = new LinkedHashSet<>(); @@ -526,7 +526,7 @@ public class Cluster implements Moveable { addTogetherWithParents(togethers, child.group.getTogether()); for (Together together : togethers) - if (together.getParent() == parentTogether) + if (together.getParent() == null) printTogether(together, togethers, sb, nodesOrderedWithoutTop, stringBounder, lines, dotMode, graphvizVersion, type); if (skinParam.useRankSame() && dotMode != DotMode.NO_LEFT_RIGHT_AND_XLABEL @@ -535,7 +535,7 @@ public class Cluster implements Moveable { for (Cluster child : children) if (child.group.getTogether() == null) - child.printInternal(sb, lines, stringBounder, dotMode, graphvizVersion, type, parentTogether); + child.printInternal(sb, lines, stringBounder, dotMode, graphvizVersion, type); return added; } @@ -561,12 +561,12 @@ public class Cluster implements Moveable { } for (Cluster child : getChildren()) - child.printInternal(sb, lines, stringBounder, dotMode, graphvizVersion, type, null); + child.printInternal(sb, lines, stringBounder, dotMode, graphvizVersion, type); } private void printInternal(StringBuilder sb, Collection lines, StringBounder stringBounder, - DotMode dotMode, GraphvizVersion graphvizVersion, UmlDiagramType type, Together parentTogether) { - new ClusterDotString(this, skinParam).printInternal(sb, lines, stringBounder, dotMode, graphvizVersion, type, parentTogether); + DotMode dotMode, GraphvizVersion graphvizVersion, UmlDiagramType type) { + new ClusterDotString(this, skinParam).printInternal(sb, lines, stringBounder, dotMode, graphvizVersion, type); } private void appendRankSame(StringBuilder sb, Collection lines) { diff --git a/src/net/sourceforge/plantuml/svek/ClusterDotString.java b/src/net/sourceforge/plantuml/svek/ClusterDotString.java index e0a910fcb..4a0f8dd76 100644 --- a/src/net/sourceforge/plantuml/svek/ClusterDotString.java +++ b/src/net/sourceforge/plantuml/svek/ClusterDotString.java @@ -46,7 +46,6 @@ import java.util.Set; import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.abel.EntityPosition; -import net.sourceforge.plantuml.abel.Together; import net.sourceforge.plantuml.decoration.symbol.USymbols; import net.sourceforge.plantuml.dot.GraphvizVersion; import net.sourceforge.plantuml.klimt.font.StringBounder; @@ -72,7 +71,7 @@ public class ClusterDotString { } void printInternal(StringBuilder sb, Collection lines, StringBounder stringBounder, DotMode dotMode, - GraphvizVersion graphvizVersion, UmlDiagramType type, Together parentTogether) { + GraphvizVersion graphvizVersion, UmlDiagramType type) { if (cluster.diagram.getPragma().useKermor()) { new ClusterDotStringKermor(cluster, skinParam).printInternal(sb, lines, stringBounder, dotMode, graphvizVersion, type); @@ -82,7 +81,7 @@ public class ClusterDotString { if (packed) { cluster.printCluster1(sb, lines, stringBounder); - final SvekNode added = cluster.printCluster2(sb, lines, stringBounder, dotMode, graphvizVersion, type, parentTogether); + final SvekNode added = cluster.printCluster2(sb, lines, stringBounder, dotMode, graphvizVersion, type); return; } @@ -171,7 +170,7 @@ public class ClusterDotString { // ----------- cluster.printCluster1(sb, lines, stringBounder); - final SvekNode added = cluster.printCluster2(sb, lines, stringBounder, dotMode, graphvizVersion, type, parentTogether); + final SvekNode added = cluster.printCluster2(sb, lines, stringBounder, dotMode, graphvizVersion, type); if (entityPositionsExceptNormal.size() > 0) if (hasPort()) { sb.append(empty() + " [shape=rect,width=.01,height=.01,label="); diff --git a/src/net/sourceforge/plantuml/svek/DotStringFactory.java b/src/net/sourceforge/plantuml/svek/DotStringFactory.java index 16faceb96..ba93eb3cb 100644 --- a/src/net/sourceforge/plantuml/svek/DotStringFactory.java +++ b/src/net/sourceforge/plantuml/svek/DotStringFactory.java @@ -214,7 +214,7 @@ public class DotStringFactory implements Moveable { line.appendLine(getGraphvizVersion(), sb, dotMode, dotSplines); root.printCluster2(sb, bibliotekon.allLines(), stringBounder, dotMode, getGraphvizVersion(), - umlDiagramType, null); + umlDiagramType); for (SvekLine line : bibliotekon.lines1()) line.appendLine(getGraphvizVersion(), sb, dotMode, dotSplines);