plantuml/src/net/sourceforge/plantuml/elk/CucaDiagramFileMakerElk.java

564 lines
20 KiB
Java
Raw Normal View History

/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2023-02-22 18:43:48 +00:00
* (C) Copyright 2009-2024, Arnaud Roques
*
2023-02-22 18:43:48 +00:00
* Project Info: https://plantuml.com
2022-08-17 17:34:24 +00:00
*
* If you like this project or if you find it useful, you can support us at:
2022-08-17 17:34:24 +00:00
*
2023-02-22 18:43:48 +00:00
* https://plantuml.com/patreon (only 1$ per month!)
* https://plantuml.com/paypal
2022-08-17 17:34:24 +00:00
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*
* Original Author: Arnaud Roques
2022-08-17 17:34:24 +00:00
*
*
*/
package net.sourceforge.plantuml.elk;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
2021-04-17 11:19:39 +00:00
import java.util.Collection;
import java.util.EnumSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import net.sourceforge.plantuml.FileFormatOption;
2022-12-17 11:10:05 +00:00
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.UmlDiagram;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.abel.Entity;
import net.sourceforge.plantuml.abel.GroupType;
import net.sourceforge.plantuml.abel.LeafType;
import net.sourceforge.plantuml.abel.Link;
import net.sourceforge.plantuml.api.ImageDataSimple;
import net.sourceforge.plantuml.core.ImageData;
2022-11-04 17:36:03 +00:00
import net.sourceforge.plantuml.cucadiagram.ICucaDiagram;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.decoration.symbol.USymbolFolder;
import net.sourceforge.plantuml.eggs.QuoteUtils;
2021-04-20 20:19:49 +00:00
/*
* You can choose between real "org.eclipse.elk..." classes or proxied "net.sourceforge.plantuml.elk.proxy..."
2022-08-17 17:34:24 +00:00
*
2021-04-20 20:19:49 +00:00
* Using proxied classes allows to compile PlantUML without having ELK available on the classpath.
* Since GraphViz is the default layout engine up to now, we do not want to enforce the use of ELK just for compilation.
* (for people not using maven)
2022-08-17 17:34:24 +00:00
*
2021-04-20 20:19:49 +00:00
* If you are debugging, you should probably switch to "org.eclipse.elk..." classes
2022-08-17 17:34:24 +00:00
*
2021-04-20 20:19:49 +00:00
*/
/*
import org.eclipse.elk.core.RecursiveGraphLayoutEngine;
import org.eclipse.elk.core.math.ElkPadding;
2021-04-20 20:19:49 +00:00
import org.eclipse.elk.core.options.CoreOptions;
import org.eclipse.elk.core.options.Direction;
import org.eclipse.elk.core.options.EdgeLabelPlacement;
import org.eclipse.elk.core.options.HierarchyHandling;
import org.eclipse.elk.core.options.NodeLabelPlacement;
import org.eclipse.elk.core.util.NullElkProgressMonitor;
import org.eclipse.elk.graph.ElkEdge;
import org.eclipse.elk.graph.ElkLabel;
import org.eclipse.elk.graph.ElkNode;
import org.eclipse.elk.graph.util.ElkGraphUtil;
*/
import net.sourceforge.plantuml.elk.proxy.core.RecursiveGraphLayoutEngine;
import net.sourceforge.plantuml.elk.proxy.core.math.ElkPadding;
2021-04-20 20:19:49 +00:00
import net.sourceforge.plantuml.elk.proxy.core.options.CoreOptions;
import net.sourceforge.plantuml.elk.proxy.core.options.Direction;
import net.sourceforge.plantuml.elk.proxy.core.options.EdgeLabelPlacement;
import net.sourceforge.plantuml.elk.proxy.core.options.HierarchyHandling;
import net.sourceforge.plantuml.elk.proxy.core.options.NodeLabelPlacement;
import net.sourceforge.plantuml.elk.proxy.core.util.NullElkProgressMonitor;
import net.sourceforge.plantuml.elk.proxy.graph.ElkEdge;
import net.sourceforge.plantuml.elk.proxy.graph.ElkLabel;
import net.sourceforge.plantuml.elk.proxy.graph.ElkNode;
import net.sourceforge.plantuml.elk.proxy.graph.util.ElkGraphUtil;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.klimt.UStroke;
import net.sourceforge.plantuml.klimt.UTranslate;
import net.sourceforge.plantuml.klimt.color.HColor;
import net.sourceforge.plantuml.klimt.color.HColors;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.klimt.creole.Display;
import net.sourceforge.plantuml.klimt.drawing.UGraphic;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.klimt.font.FontConfiguration;
import net.sourceforge.plantuml.klimt.font.FontParam;
import net.sourceforge.plantuml.klimt.font.StringBounder;
import net.sourceforge.plantuml.klimt.geom.HorizontalAlignment;
import net.sourceforge.plantuml.klimt.geom.MinMax;
2023-02-26 18:51:17 +00:00
import net.sourceforge.plantuml.klimt.geom.RectangleArea;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.klimt.geom.XDimension2D;
import net.sourceforge.plantuml.klimt.geom.XPoint2D;
import net.sourceforge.plantuml.klimt.shape.AbstractTextBlock;
import net.sourceforge.plantuml.klimt.shape.TextBlock;
import net.sourceforge.plantuml.klimt.shape.TextBlockUtils;
import net.sourceforge.plantuml.klimt.shape.URectangle;
2022-08-17 17:34:24 +00:00
import net.sourceforge.plantuml.log.Logme;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.skin.AlignmentParam;
import net.sourceforge.plantuml.skin.UmlDiagramType;
import net.sourceforge.plantuml.style.ISkinParam;
2021-04-20 20:19:49 +00:00
import net.sourceforge.plantuml.style.PName;
import net.sourceforge.plantuml.style.SName;
import net.sourceforge.plantuml.style.Style;
import net.sourceforge.plantuml.svek.Bibliotekon;
2021-04-20 20:19:49 +00:00
import net.sourceforge.plantuml.svek.Cluster;
import net.sourceforge.plantuml.svek.ClusterDecoration;
import net.sourceforge.plantuml.svek.CucaDiagramFileMaker;
import net.sourceforge.plantuml.svek.DotStringFactory;
import net.sourceforge.plantuml.svek.GeneralImageBuilder;
import net.sourceforge.plantuml.svek.GraphvizCrash;
import net.sourceforge.plantuml.svek.IEntityImage;
2021-04-20 20:19:49 +00:00
import net.sourceforge.plantuml.svek.PackageStyle;
2021-04-17 11:19:39 +00:00
/*
* Some notes:
2022-08-17 17:34:24 +00:00
*
2021-04-17 11:19:39 +00:00
https://www.eclipse.org/elk/documentation/tooldevelopers/graphdatastructure.html
https://www.eclipse.org/elk/documentation/tooldevelopers/graphdatastructure/coordinatesystem.html
Long hierarchical edge
https://rtsys.informatik.uni-kiel.de/~biblio/downloads/theses/yab-bt.pdf
https://rtsys.informatik.uni-kiel.de/~biblio/downloads/theses/thw-bt.pdf
*/
public class CucaDiagramFileMakerElk implements CucaDiagramFileMaker {
2023-02-06 21:04:53 +00:00
// ::remove folder when CORE
2022-11-04 17:36:03 +00:00
private final ICucaDiagram diagram;
private final StringBounder stringBounder;
private final DotStringFactory dotStringFactory;
2023-02-06 21:04:53 +00:00
private final Map<Entity, ElkNode> nodes = new LinkedHashMap<Entity, ElkNode>();
private final Map<Entity, ElkNode> clusters = new LinkedHashMap<Entity, ElkNode>();
2021-04-14 18:08:29 +00:00
private final Map<Link, ElkEdge> edges = new LinkedHashMap<Link, ElkEdge>();
2022-11-04 17:36:03 +00:00
public CucaDiagramFileMakerElk(ICucaDiagram diagram, StringBounder stringBounder) {
this.diagram = diagram;
this.stringBounder = stringBounder;
this.dotStringFactory = new DotStringFactory(stringBounder, diagram);
}
2021-04-14 18:08:29 +00:00
private TextBlock getLabel(Link link) {
2021-04-17 11:19:39 +00:00
if (Display.isNull(link.getLabel())) {
return null;
}
final ISkinParam skinParam = diagram.getSkinParam();
2022-03-19 12:48:23 +00:00
final FontConfiguration labelFont = FontConfiguration.create(skinParam, FontParam.ARROW, null);
2021-04-14 18:08:29 +00:00
final TextBlock label = link.getLabel().create(labelFont,
skinParam.getDefaultTextAlignment(HorizontalAlignment.CENTER), skinParam);
2022-04-10 19:24:55 +00:00
if (TextBlockUtils.isEmpty(label, stringBounder))
2021-04-17 11:19:39 +00:00
return null;
2022-04-10 19:24:55 +00:00
2021-04-17 11:19:39 +00:00
return label;
2021-04-14 18:08:29 +00:00
}
2022-10-05 20:32:57 +00:00
private TextBlock getQuantifier(Link link, int n) {
final String tmp = n == 1 ? link.getQuantifier1() : link.getQuantifier2();
2022-04-10 19:24:55 +00:00
if (tmp == null)
2021-04-14 18:08:29 +00:00
return null;
2022-04-10 19:24:55 +00:00
2021-04-17 11:19:39 +00:00
final ISkinParam skinParam = diagram.getSkinParam();
2022-03-19 12:48:23 +00:00
final FontConfiguration labelFont = FontConfiguration.create(skinParam, FontParam.ARROW, null);
2021-04-14 18:08:29 +00:00
final TextBlock label = Display.getWithNewlines(tmp).create(labelFont,
skinParam.getDefaultTextAlignment(HorizontalAlignment.CENTER), skinParam);
2022-04-10 19:24:55 +00:00
if (TextBlockUtils.isEmpty(label, stringBounder))
2021-04-17 11:19:39 +00:00
return null;
2022-04-10 19:24:55 +00:00
2021-04-17 11:19:39 +00:00
return label;
}
// Retrieve the real position of a node, depending on its parents
2022-09-12 20:08:34 +00:00
private XPoint2D getPosition(ElkNode elkNode) {
2021-04-17 11:19:39 +00:00
final ElkNode parent = elkNode.getParent();
final double x = elkNode.getX();
final double y = elkNode.getY();
// This nasty test checks that parent is "root"
if (parent == null || parent.getLabels().size() == 0) {
2022-09-12 20:08:34 +00:00
return new XPoint2D(x, y);
2021-04-17 11:19:39 +00:00
}
// Right now, this is recursive
2022-09-12 20:08:34 +00:00
final XPoint2D parentPosition = getPosition(parent);
return new XPoint2D(parentPosition.getX() + x, parentPosition.getY() + y);
2021-04-17 11:19:39 +00:00
2021-04-14 18:08:29 +00:00
}
// The Drawing class does the real drawing
2023-02-26 18:51:17 +00:00
class Drawing extends AbstractTextBlock {
// min and max of all coord
private final MinMax minMax;
public Drawing(MinMax minMax) {
this.minMax = minMax;
}
public void drawU(UGraphic ug) {
2021-04-20 20:19:49 +00:00
drawAllClusters(ug);
drawAllNodes(ug);
drawAllEdges(ug);
}
2021-04-20 20:19:49 +00:00
private void drawAllClusters(UGraphic ug) {
2023-02-06 21:04:53 +00:00
for (Entry<Entity, ElkNode> ent : clusters.entrySet())
2021-04-20 20:19:49 +00:00
drawSingleCluster(ug, ent.getKey(), ent.getValue());
2022-04-10 19:24:55 +00:00
2021-04-20 20:19:49 +00:00
}
2021-04-17 11:19:39 +00:00
2021-04-20 20:19:49 +00:00
private void drawAllNodes(UGraphic ug) {
2023-02-06 21:04:53 +00:00
for (Entry<Entity, ElkNode> ent : nodes.entrySet())
2021-04-20 20:19:49 +00:00
drawSingleNode(ug, ent.getKey(), ent.getValue());
2022-04-10 19:24:55 +00:00
2021-04-20 20:19:49 +00:00
}
2021-04-20 20:19:49 +00:00
private void drawAllEdges(UGraphic ug) {
2021-04-14 18:08:29 +00:00
for (Entry<Link, ElkEdge> ent : edges.entrySet()) {
final Link link = ent.getKey();
2022-04-10 19:24:55 +00:00
if (link.isInvis())
2021-04-14 18:08:29 +00:00
continue;
2022-04-10 19:24:55 +00:00
2021-04-20 20:19:49 +00:00
drawSingleEdge(ug, link, ent.getValue());
}
}
2023-02-06 21:04:53 +00:00
private void drawSingleCluster(UGraphic ug, Entity group, ElkNode elkNode) {
2022-09-12 20:08:34 +00:00
final XPoint2D corner = getPosition(elkNode);
2021-04-20 20:19:49 +00:00
final URectangle rect = new URectangle(elkNode.getWidth(), elkNode.getHeight());
PackageStyle packageStyle = group.getPackageStyle();
final ISkinParam skinParam = diagram.getSkinParam();
2022-04-10 19:24:55 +00:00
if (packageStyle == null)
2021-04-20 20:19:49 +00:00
packageStyle = skinParam.packageStyle();
final UmlDiagramType umlDiagramType = diagram.getUmlDiagramType();
2022-04-10 19:24:55 +00:00
final Style style = Cluster.getDefaultStyleDefinition(umlDiagramType.getStyleName(), group.getUSymbol())
.getMergedStyle(skinParam.getCurrentStyleBuilder());
final double shadowing = style.value(PName.Shadowing).asDouble();
2022-05-04 17:52:00 +00:00
final UStroke stroke = Cluster.getStrokeInternal(group, style);
2022-04-10 19:24:55 +00:00
2021-04-20 20:19:49 +00:00
HColor backColor = getBackColor(umlDiagramType);
2022-08-19 16:34:21 +00:00
backColor = Cluster.getBackColor(backColor, group.getStereotype(), umlDiagramType.getStyleName(),
2022-09-18 17:08:06 +00:00
group.getUSymbol(), skinParam.getCurrentStyleBuilder(), skinParam.getIHtmlColorSet());
2021-04-20 20:19:49 +00:00
2022-05-21 09:41:00 +00:00
final double roundCorner = style.value(PName.RoundCorner).asDouble();
// final double roundCorner = group.getUSymbol() == null ? 0
// : group.getUSymbol().getSkinParameter().getRoundCorner(skinParam, group.getStereotype());
2021-04-20 20:19:49 +00:00
final TextBlock ztitle = getTitleBlock(group);
final TextBlock zstereo = TextBlockUtils.empty(0, 0);
2023-02-26 18:51:17 +00:00
final RectangleArea rectangleArea = new RectangleArea(0, 0, elkNode.getWidth(), elkNode.getHeight());
2021-04-20 20:19:49 +00:00
final ClusterDecoration decoration = new ClusterDecoration(packageStyle, group.getUSymbol(), ztitle,
2023-02-26 18:51:17 +00:00
zstereo, rectangleArea, stroke);
2021-04-17 11:19:39 +00:00
2022-08-19 16:34:21 +00:00
final HColor borderColor = HColors.BLACK;
2021-04-20 20:19:49 +00:00
decoration.drawU(ug.apply(new UTranslate(corner)), backColor, borderColor, shadowing, roundCorner,
2021-06-27 16:50:40 +00:00
skinParam.getHorizontalAlignment(AlignmentParam.packageTitleAlignment, null, false, null),
2022-02-24 18:18:19 +00:00
skinParam.getStereotypeAlignment(), 0);
2021-04-17 11:19:39 +00:00
2021-04-20 20:19:49 +00:00
// // Print a simple rectangle right now
// ug.apply(HColorUtils.BLACK).apply(new UStroke(1.5)).apply(new UTranslate(corner)).draw(rect);
}
2021-04-17 11:19:39 +00:00
2023-02-06 21:04:53 +00:00
private TextBlock getTitleBlock(Entity g) {
2021-04-20 20:19:49 +00:00
final Display label = g.getDisplay();
2022-04-10 19:24:55 +00:00
if (label == null)
2021-04-20 20:19:49 +00:00
return TextBlockUtils.empty(0, 0);
2021-04-14 18:08:29 +00:00
2021-04-20 20:19:49 +00:00
final ISkinParam skinParam = diagram.getSkinParam();
final FontConfiguration fontConfiguration = g.getFontConfigurationForTitle(skinParam);
return label.create(fontConfiguration, HorizontalAlignment.CENTER, skinParam);
}
private HColor getBackColor(UmlDiagramType umlDiagramType) {
return null;
}
2023-02-06 21:04:53 +00:00
private void drawSingleNode(UGraphic ug, Entity leaf, ElkNode elkNode) {
2021-04-20 20:19:49 +00:00
final IEntityImage image = printEntityInternal(leaf);
// Retrieve coord from ELK
2022-09-12 20:08:34 +00:00
final XPoint2D corner = getPosition(elkNode);
2021-04-20 20:19:49 +00:00
// Print the node image at right coord
image.drawU(ug.apply(new UTranslate(corner)));
}
private void drawSingleEdge(UGraphic ug, Link link, ElkEdge edge) {
// Unfortunately, we have to translate "edge" in its own "cluster" coordinate
2022-09-12 20:08:34 +00:00
final XPoint2D translate = getPosition(edge.getContainingNode());
2021-04-20 20:19:49 +00:00
2022-06-27 16:33:45 +00:00
final double magicY2 = 0;
2023-02-06 21:04:53 +00:00
final Entity dest = link.getEntity2();
2022-06-27 16:33:45 +00:00
if (dest.getUSymbol() instanceof USymbolFolder) {
// System.err.println("dest=" + dest);
// final IEntityImage image = printEntityInternal((ILeaf) dest);
// System.err.println("image=" + image);
}
2021-04-20 20:19:49 +00:00
final ElkPath elkPath = new ElkPath(diagram, SName.classDiagram, link, edge, getLabel(link),
2022-10-05 20:32:57 +00:00
getQuantifier(link, 1), getQuantifier(link, 2), magicY2);
2021-04-20 20:19:49 +00:00
elkPath.drawU(ug.apply(new UTranslate(translate)));
}
2022-09-12 20:08:34 +00:00
public XDimension2D calculateDimension(StringBounder stringBounder) {
2022-04-10 19:24:55 +00:00
if (minMax == null)
throw new UnsupportedOperationException();
2022-04-10 19:24:55 +00:00
return minMax.getDimension();
}
public HColor getBackcolor() {
return null;
}
}
2023-02-06 21:04:53 +00:00
private Collection<Entity> getUnpackagedEntities() {
final List<Entity> result = new ArrayList<>();
for (Entity ent : diagram.getEntityFactory().leafs())
2022-04-10 19:24:55 +00:00
if (diagram.getEntityFactory().getRootGroup() == ent.getParentContainer())
2021-04-17 11:19:39 +00:00
result.add(ent);
2022-04-10 19:24:55 +00:00
2021-04-17 11:19:39 +00:00
return result;
}
2023-02-06 21:04:53 +00:00
private ElkNode getElkNode(final Entity entity) {
2021-04-20 20:19:49 +00:00
ElkNode node = nodes.get(entity);
2022-04-10 19:24:55 +00:00
if (node == null)
2021-04-20 20:19:49 +00:00
node = clusters.get(entity);
2022-04-10 19:24:55 +00:00
2021-04-20 20:19:49 +00:00
return node;
}
@Override
public ImageData createFile(OutputStream os, List<String> dotStrings, FileFormatOption fileFormatOption)
throws IOException {
2021-04-17 11:19:39 +00:00
// https://www.eclipse.org/forums/index.php/t/1095737/
try {
final ElkNode root = ElkGraphUtil.createGraph();
root.setProperty(CoreOptions.DIRECTION, Direction.DOWN);
2021-04-20 20:19:49 +00:00
root.setProperty(CoreOptions.HIERARCHY_HANDLING, HierarchyHandling.INCLUDE_CHILDREN);
2021-04-14 18:08:29 +00:00
2021-04-17 11:19:39 +00:00
printAllSubgroups(root, diagram.getRootGroup());
printEntities(root, getUnpackagedEntities());
2021-04-17 11:19:39 +00:00
manageAllEdges();
2021-04-17 11:19:39 +00:00
new RecursiveGraphLayoutEngine().layout(root, new NullElkProgressMonitor());
2021-04-17 11:19:39 +00:00
final MinMax minMax = TextBlockUtils.getMinMax(new Drawing(null), stringBounder, false);
2021-04-17 11:19:39 +00:00
final TextBlock drawable = new Drawing(minMax);
return diagram.createImageBuilder(fileFormatOption) //
.drawable(drawable) //
.write(os); //
2021-04-14 18:08:29 +00:00
2021-04-17 11:19:39 +00:00
} catch (Throwable e) {
UmlDiagram.exportDiagramError(os, e, fileFormatOption, diagram.seed(), diagram.getMetadata(),
diagram.getFlashData(), getFailureText3(e));
return ImageDataSimple.error();
}
2021-04-17 11:19:39 +00:00
}
2023-02-06 21:04:53 +00:00
private void printAllSubgroups(ElkNode cluster, Entity group) {
for (Entity g : diagram.getChildrenGroups(group)) {
2021-04-17 11:19:39 +00:00
if (g.isRemoved()) {
continue;
}
if (diagram.isEmpty(g) && g.getGroupType() == GroupType.PACKAGE) {
2023-02-06 21:04:53 +00:00
g.muteToType(LeafType.EMPTY_PACKAGE);
2021-04-17 11:19:39 +00:00
System.err.println("STILL IN PROGRESS");
// printEntityNew(folder);
} else {
// We create the "cluster" in ELK for this group
final ElkNode elkCluster = ElkGraphUtil.createNode(cluster);
elkCluster.setProperty(CoreOptions.DIRECTION, Direction.DOWN);
elkCluster.setProperty(CoreOptions.PADDING, new ElkPadding(40, 15, 15, 15));
2021-04-17 11:19:39 +00:00
// Not sure this is usefull to put a label on a "cluster"
final ElkLabel label = ElkGraphUtil.createLabel(elkCluster);
label.setText("C");
// We need it anyway to recurse up to the real "root"
this.clusters.put(g, elkCluster);
printSingleGroup(g);
}
2021-04-17 11:19:39 +00:00
}
2021-04-17 11:19:39 +00:00
}
2021-04-14 18:08:29 +00:00
2023-02-06 21:04:53 +00:00
private void printSingleGroup(Entity g) {
2022-04-10 19:24:55 +00:00
if (g.getGroupType() == GroupType.CONCURRENT_STATE)
2021-04-17 11:19:39 +00:00
return;
2022-04-10 19:24:55 +00:00
2023-02-06 21:04:53 +00:00
this.printEntities(clusters.get(g), g.leafs());
2021-04-17 11:19:39 +00:00
printAllSubgroups(clusters.get(g), g);
}
2023-02-06 21:04:53 +00:00
private void printEntities(ElkNode parent, Collection<Entity> entities) {
2021-04-17 11:19:39 +00:00
// Convert all "leaf" to ELK node
2023-02-06 21:04:53 +00:00
for (Entity ent : entities) {
2022-04-10 19:24:55 +00:00
if (ent.isRemoved())
2021-04-17 11:19:39 +00:00
continue;
2022-04-10 19:24:55 +00:00
2021-04-17 11:19:39 +00:00
manageSingleNode(parent, ent);
}
}
2021-04-17 11:19:39 +00:00
private void manageAllEdges() {
// Convert all "link" to ELK edge
2022-04-10 19:24:55 +00:00
for (final Link link : diagram.getLinks())
2021-04-17 11:19:39 +00:00
manageSingleEdge(link);
2022-04-10 19:24:55 +00:00
2021-04-17 11:19:39 +00:00
}
2023-02-06 21:04:53 +00:00
private void manageSingleNode(final ElkNode root, Entity leaf) {
2021-04-17 11:19:39 +00:00
final IEntityImage image = printEntityInternal(leaf);
2021-04-17 11:19:39 +00:00
// Expected dimension of the node
2022-09-12 20:08:34 +00:00
final XDimension2D dimension = image.calculateDimension(stringBounder);
2021-04-17 11:19:39 +00:00
// Here, we try to tell ELK to use this dimension as node dimension
final ElkNode node = ElkGraphUtil.createNode(root);
node.setDimensions(dimension.getWidth(), dimension.getHeight());
2021-04-17 11:19:39 +00:00
// There is no real "label" here
// We just would like to force node dimension
final ElkLabel label = ElkGraphUtil.createLabel(node);
label.setText("X");
// I don't know why we have to do this hack, but somebody has to fix it
final double VERY_STRANGE_OFFSET = 10;
label.setDimensions(dimension.getWidth(), dimension.getHeight() - VERY_STRANGE_OFFSET);
// No idea of what we are doing here :-)
label.setProperty(CoreOptions.NODE_LABELS_PLACEMENT,
EnumSet.of(NodeLabelPlacement.INSIDE, NodeLabelPlacement.H_CENTER, NodeLabelPlacement.V_CENTER));
2021-04-20 20:19:49 +00:00
2021-04-17 11:19:39 +00:00
// This padding setting have no impact ?
// label.setProperty(CoreOptions.NODE_LABELS_PADDING, new ElkPadding(100.0));
2021-04-20 20:19:49 +00:00
// final EnumSet<SizeConstraint> constraints =
// EnumSet.of(SizeConstraint.NODE_LABELS);
// node.setProperty(CoreOptions.NODE_SIZE_CONSTRAINTS, constraints);
// node.setProperty(CoreOptions.NODE_SIZE_OPTIONS,
// EnumSet.noneOf(SizeOptions.class));
2021-04-17 11:19:39 +00:00
// Let's store this
nodes.put(leaf, node);
}
private void manageSingleEdge(final Link link) {
2021-04-20 20:19:49 +00:00
final ElkNode node1 = getElkNode(link.getEntity1());
final ElkNode node2 = getElkNode(link.getEntity2());
2021-04-17 11:19:39 +00:00
2021-04-20 20:19:49 +00:00
final ElkEdge edge = ElkGraphUtil.createSimpleEdge(node1, node2);
2021-04-17 11:19:39 +00:00
final TextBlock labelLink = getLabel(link);
if (labelLink != null) {
final ElkLabel edgeLabel = ElkGraphUtil.createLabel(edge);
2022-09-12 20:08:34 +00:00
final XDimension2D dim = labelLink.calculateDimension(stringBounder);
2021-04-17 11:19:39 +00:00
edgeLabel.setText("X");
edgeLabel.setDimensions(dim.getWidth(), dim.getHeight());
// Duplicated, with qualifier, but who cares?
edge.setProperty(CoreOptions.EDGE_LABELS_INLINE, true);
2021-04-20 20:19:49 +00:00
// edge.setProperty(CoreOptions.EDGE_TYPE, EdgeType.ASSOCIATION);
2021-04-17 11:19:39 +00:00
}
2022-10-05 20:32:57 +00:00
if (link.getQuantifier1() != null) {
2021-04-17 11:19:39 +00:00
final ElkLabel edgeLabel = ElkGraphUtil.createLabel(edge);
2022-10-05 20:32:57 +00:00
final XDimension2D dim = getQuantifier(link, 1).calculateDimension(stringBounder);
2021-04-17 11:19:39 +00:00
// Nasty trick, we store the kind of label in the text
edgeLabel.setText("1");
edgeLabel.setDimensions(dim.getWidth(), dim.getHeight());
edgeLabel.setProperty(CoreOptions.EDGE_LABELS_PLACEMENT, EdgeLabelPlacement.TAIL);
// Duplicated, with main label, but who cares?
edge.setProperty(CoreOptions.EDGE_LABELS_INLINE, true);
2021-04-20 20:19:49 +00:00
// edge.setProperty(CoreOptions.EDGE_TYPE, EdgeType.ASSOCIATION);
2021-04-17 11:19:39 +00:00
}
2022-10-05 20:32:57 +00:00
if (link.getQuantifier2() != null) {
2021-04-17 11:19:39 +00:00
final ElkLabel edgeLabel = ElkGraphUtil.createLabel(edge);
2022-10-05 20:32:57 +00:00
final XDimension2D dim = getQuantifier(link, 2).calculateDimension(stringBounder);
2021-04-17 11:19:39 +00:00
// Nasty trick, we store the kind of label in the text
edgeLabel.setText("2");
edgeLabel.setDimensions(dim.getWidth(), dim.getHeight());
edgeLabel.setProperty(CoreOptions.EDGE_LABELS_PLACEMENT, EdgeLabelPlacement.HEAD);
// Duplicated, with main label, but who cares?
edge.setProperty(CoreOptions.EDGE_LABELS_INLINE, true);
2021-04-20 20:19:49 +00:00
// edge.setProperty(CoreOptions.EDGE_TYPE, EdgeType.ASSOCIATION);
2021-04-17 11:19:39 +00:00
}
2021-04-20 20:19:49 +00:00
2021-04-17 11:19:39 +00:00
edges.put(link, edge);
}
static private List<String> getFailureText3(Throwable exception) {
2022-08-17 17:34:24 +00:00
Logme.error(exception);
2021-05-14 08:42:57 +00:00
final List<String> strings = new ArrayList<>();
strings.add("An error has occured : " + exception);
final String quote = StringUtils.rot(QuoteUtils.getSomeQuote());
strings.add("<i>" + quote);
strings.add(" ");
GraphvizCrash.addProperties(strings);
strings.add(" ");
strings.add("Sorry, ELK intregration is really alpha feature...");
strings.add(" ");
strings.add("You should send this diagram and this image to <b>plantuml@gmail.com</b> or");
2023-02-22 18:43:48 +00:00
strings.add("post to <b>https://plantuml.com/qa</b> to solve this issue.");
strings.add(" ");
return strings;
}
private Bibliotekon getBibliotekon() {
return dotStringFactory.getBibliotekon();
}
2023-02-06 21:04:53 +00:00
private IEntityImage printEntityInternal(Entity ent) {
2022-04-10 19:24:55 +00:00
if (ent.isRemoved())
throw new IllegalStateException();
2022-04-10 19:24:55 +00:00
if (ent.getSvekImage() == null) {
final ISkinParam skinParam = diagram.getSkinParam();
2022-04-10 19:24:55 +00:00
if (skinParam.sameClassWidth())
System.err.println("NOT YET IMPLEMENED");
return GeneralImageBuilder.createEntityImageBlock(ent, skinParam, diagram.isHideEmptyDescriptionForState(),
diagram, getBibliotekon(), null, diagram.getUmlDiagramType(), diagram.getLinks());
}
return ent.getSvekImage();
}
@Override
2023-02-22 18:43:48 +00:00
public void createOneGraphic(UGraphic ug) {
throw new UnsupportedOperationException();
}
}