1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-12-22 02:49:06 +00:00
Arnaud Roques 2023-03-22 19:25:52 +01:00
parent cdec3380ec
commit 003222a00f
9 changed files with 111 additions and 17 deletions

View File

@ -719,4 +719,32 @@ final public class Entity implements SpecificBackcolorable, Hideable, Removeable
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;
}
}

View File

@ -334,23 +334,19 @@ public class Link extends WithLinkType implements Hideable, Removeable {
}
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();

View File

@ -45,6 +45,7 @@ import net.sourceforge.plantuml.abel.Link;
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;
@ -118,10 +119,37 @@ public class ClassDiagram extends AbstractClassOrObjectDiagram {
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) {

View File

@ -416,6 +416,12 @@ public class Display implements Iterable<CharSequence> {
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);

View File

@ -317,14 +317,18 @@ public class CucaDiagramFileMakerSmetana implements CucaDiagramFileMaker {
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) {
@ -361,8 +365,8 @@ public class CucaDiagramFileMakerSmetana implements CucaDiagramFileMaker {
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;
}
@ -373,7 +377,6 @@ public class CucaDiagramFileMakerSmetana implements CucaDiagramFileMaker {
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);
@ -484,9 +487,14 @@ public class CucaDiagramFileMakerSmetana implements CucaDiagramFileMaker {
}
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());

View File

@ -74,6 +74,10 @@ public class Pragma {
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"));
}
@ -86,4 +90,8 @@ public class Pragma {
return isTrue(getValue("kermor"));
}
public boolean useIntermediatePackages() {
return !isFalse(getValue("useintermediatepackages"));
}
}

View File

@ -66,6 +66,10 @@ public class ClusterDotString {
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()) {
@ -73,6 +77,14 @@ public class ClusterDotString {
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
@ -154,6 +166,8 @@ public class ClusterDotString {
SvekUtils.println(sb);
}
SvekUtils.println(sb);
// -----------
cluster.printCluster1(sb, lines, stringBounder);
final SvekNode added = cluster.printCluster2(sb, lines, stringBounder, dotMode, graphvizVersion, type);
@ -167,6 +181,8 @@ public class ClusterDotString {
}
SvekUtils.println(sb);
// -----------
sb.append("}");
if (protection1)
sb.append("}");

View File

@ -415,6 +415,9 @@ public class DotStringFactory implements Moveable {
}
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);

View File

@ -72,7 +72,8 @@ public final class SvekResult extends AbstractTextBlock implements IEntityImage
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());