Skip to content

Commit

Permalink
fix: wip on various issues
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudroques committed Mar 22, 2023
1 parent cdec338 commit 003222a
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 17 deletions.
28 changes: 28 additions & 0 deletions src/net/sourceforge/plantuml/abel/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -719,4 +719,32 @@ public boolean isAutarkic() {
return true;
}

public boolean canBePacked() {
if (isPacked())
return false;
if (countChildren() != 1)
return false;
if (leafs().size() != 0)
return false;
for (Link link : entityFactory.getLinks())
if (link.contains(this))
return false;

final Entity child = groups().iterator().next();
if (child.countChildren() == 0)
return false;

return true;
}

private boolean packed;

public final void setPacked(boolean packed) {
this.packed = true;
}

public final boolean isPacked() {
return packed;
}

}
12 changes: 4 additions & 8 deletions src/net/sourceforge/plantuml/abel/Link.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,23 +334,19 @@ public boolean containsType(LeafType type) {
}

public boolean contains(Entity entity) {
if (isSame(getEntity1(), entity))
if (getEntity1() == entity)
return true;
if (isSame(getEntity2(), entity))
if (getEntity2() == entity)
return true;

return false;
}

static private boolean isSame(Entity a, Entity b) {
return a == b;
}

public Entity getOther(Entity entity) {
if (isSame(getEntity1(), entity))
if (getEntity1() == entity)
return getEntity2();

if (isSame(getEntity2(), entity))
if (getEntity2() == entity)
return getEntity1();

throw new IllegalArgumentException();
Expand Down
28 changes: 28 additions & 0 deletions src/net/sourceforge/plantuml/classdiagram/ClassDiagram.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.klimt.creole.Display;
import net.sourceforge.plantuml.klimt.shape.TextBlock;
import net.sourceforge.plantuml.objectdiagram.AbstractClassOrObjectDiagram;
import net.sourceforge.plantuml.plasma.Quark;
Expand Down Expand Up @@ -118,10 +119,37 @@ public String checkFinalError() {
link2.setLength(1);

}

if (getPragma().useIntermediatePackages() == false)
packSomePackage();

this.applySingleStrategy();
return super.checkFinalError();
}

private void packSomePackage() {
String separator = getNamespaceSeparator();
if (separator == null)
separator = ".";

while (true) {
boolean changed = false;
for (Entity group : this.entityFactory.groups()) {
if (group.canBePacked()) {
final Entity child = group.groups().iterator().next();
final String appended = group.getDisplay().get(0) + separator;
final Display newDisplay = child.getDisplay().appendFirstLine(appended);
child.setDisplay(newDisplay);
group.setPacked(true);
changed = true;
}
}
if (changed == false)
return;
}

}

public CommandExecutionResult checkIfPackageHierarchyIfOk(Entity entity) {
Quark<Entity> current = entity.getQuark().getParent();
while (current.isRoot() == false) {
Expand Down
6 changes: 6 additions & 0 deletions src/net/sourceforge/plantuml/klimt/creole/Display.java
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,12 @@ public Display addFirst(CharSequence s) {
return result;
}

public Display appendFirstLine(String appended) {
final Display result = new Display(this.showStereotype, this, this.defaultCreoleMode);
result.displayData.set(0, appended + result.displayData.get(0));
return result;
}

public Display add(CharSequence s) {
final Display result = new Display(this.showStereotype, this, this.defaultCreoleMode);
result.displayData.add(s);
Expand Down
24 changes: 16 additions & 8 deletions src/net/sourceforge/plantuml/sdot/CucaDiagramFileMakerSmetana.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,18 @@ private void printSingleGroup(Entity g) {
if (g.getGroupType() == GroupType.CONCURRENT_STATE)
return;

final ClusterHeader clusterHeader = new ClusterHeader((Entity) g, diagram.getSkinParam(), diagram,
stringBounder);
dotStringFactory.openCluster(g, clusterHeader);
if (g.isPacked() == false) {
final ClusterHeader clusterHeader = new ClusterHeader(g, diagram.getSkinParam(), diagram, stringBounder);
dotStringFactory.openCluster(g, clusterHeader);
}

this.printEntities(g.leafs());

printAllSubgroups(g);

dotStringFactory.closeCluster();
if (g.isPacked() == false) {
dotStringFactory.closeCluster();
}
}

private void printEntities(Collection<Entity> entities) {
Expand Down Expand Up @@ -361,8 +365,8 @@ private ST_Agnode_s getCoreFromGroup(Globals zz, Entity group) {

result = agnode(zz, cluster, new CString("z" + group.getUid()), true);
agsafeset(zz, result, new CString("shape"), new CString("box"), new CString(""));
agsafeset(zz, result, new CString("width"), new CString("1"), new CString(""));
agsafeset(zz, result, new CString("height"), new CString("1"), new CString(""));
agsafeset(zz, result, new CString("width"), new CString("0.1"), new CString(""));
agsafeset(zz, result, new CString("height"), new CString("0.1"), new CString(""));
coreNodes.put(group, result);
return result;
}
Expand All @@ -373,7 +377,6 @@ private void exportEntity(Globals zz, ST_Agraph_s cluster, Entity leaf) {
System.err.println("CANNOT FIND NODE");
return;
}
System.err.println("exportEntity " + leaf);
final ST_Agnode_s agnode = agnode(zz, cluster, new CString(node.getUid()), true);
agsafeset(zz, agnode, new CString("shape"), new CString("box"), new CString(""));
final XDimension2D dim = getDim(node);
Expand Down Expand Up @@ -484,9 +487,14 @@ private void exportGroups(Globals zz, ST_Agraph_s graph, Entity parent) {
}

private void exportGroup(Globals zz, ST_Agraph_s graph, Entity group) {
if (group.isPacked()) {
this.exportEntities(zz, graph, group.leafs());
this.exportGroups(zz, graph, group);
return;
}
final Cluster cluster = getBibliotekon().getCluster(group);
if (cluster == null) {
System.err.println("CucaDiagramFileMakerJDot::exportGroup issue");
System.err.println("CucaDiagramFileMakerSmetana::exportGroup issue");
return;
}
JUtils.LOG2("cluster = " + cluster.getClusterId());
Expand Down
8 changes: 8 additions & 0 deletions src/net/sourceforge/plantuml/skin/Pragma.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ private boolean isTrue(final String s) {
return "true".equalsIgnoreCase(s) || "on".equalsIgnoreCase(s);
}

private boolean isFalse(final String s) {
return "false".equalsIgnoreCase(s) || "off".equalsIgnoreCase(s);
}

public boolean useVerticalIf() {
return isTrue(getValue("useverticalif"));
}
Expand All @@ -86,4 +90,8 @@ public boolean useKermor() {
return isTrue(getValue("kermor"));
}

public boolean useIntermediatePackages() {
return !isFalse(getValue("useintermediatepackages"));
}

}
16 changes: 16 additions & 0 deletions src/net/sourceforge/plantuml/svek/ClusterDotString.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,25 @@ public ClusterDotString(Cluster cluster, ISkinParam skinParam) {
this.skinParam = skinParam;
}

private boolean isPacked() {
return cluster.getGroup().isPacked();
}

void printInternal(StringBuilder sb, Collection<SvekLine> lines, StringBounder stringBounder, DotMode dotMode,
GraphvizVersion graphvizVersion, UmlDiagramType type) {
if (cluster.diagram.getPragma().useKermor()) {
new ClusterDotStringKermor(cluster, skinParam).printInternal(sb, lines, stringBounder, dotMode,
graphvizVersion, type);
return;
}
final boolean packed = isPacked();

if (packed) {
cluster.printCluster1(sb, lines, stringBounder);
final SvekNode added = cluster.printCluster2(sb, lines, stringBounder, dotMode, graphvizVersion, type);
return;

}
final boolean thereALinkFromOrToGroup2 = isThereALinkFromOrToGroup(lines);
boolean thereALinkFromOrToGroup1 = thereALinkFromOrToGroup2;
final boolean useProtectionWhenThereALinkFromOrToGroup = graphvizVersion
Expand Down Expand Up @@ -154,6 +166,8 @@ void printInternal(StringBuilder sb, Collection<SvekLine> lines, StringBounder s
SvekUtils.println(sb);
}
SvekUtils.println(sb);

// -----------
cluster.printCluster1(sb, lines, stringBounder);

final SvekNode added = cluster.printCluster2(sb, lines, stringBounder, dotMode, graphvizVersion, type);
Expand All @@ -167,6 +181,8 @@ void printInternal(StringBuilder sb, Collection<SvekLine> lines, StringBounder s
}
SvekUtils.println(sb);

// -----------

sb.append("}");
if (protection1)
sb.append("}");
Expand Down
3 changes: 3 additions & 0 deletions src/net/sourceforge/plantuml/svek/DotStringFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ public void solve(EntityFactory entityFactory, final String svg) throws IOExcept
}

for (Cluster cluster : bibliotekon.allCluster()) {
if (cluster.getGroup().isPacked())
continue;

int idx = getClusterIndex(svg, cluster.getColor());
final int starting = idx;
final List<XPoint2D> points = svgResult.substring(starting).extractList(SvgResult.POINTS_EQUALS);
Expand Down
3 changes: 2 additions & 1 deletion src/net/sourceforge/plantuml/svek/SvekResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public SvekResult(DotData dotData, DotStringFactory dotStringFactory) {
public void drawU(UGraphic ug) {

for (Cluster cluster : dotStringFactory.getBibliotekon().allCluster())
cluster.drawU(ug, dotData.getUmlDiagramType());
if (cluster.getGroup().isPacked() == false)
cluster.drawU(ug, dotData.getUmlDiagramType());

final Style style2 = getDefaultStyleDefinition(null)
.getMergedStyle(dotData.getSkinParam().getCurrentStyleBuilder());
Expand Down

0 comments on commit 003222a

Please sign in to comment.