plantuml/src/net/sourceforge/plantuml/svek/DotStringFactory.java

501 lines
16 KiB
Java
Raw Normal View History

2011-08-08 17:48:29 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2023-02-22 18:43:48 +00:00
* (C) Copyright 2009-2024, Arnaud Roques
2011-08-08 17:48:29 +00:00
*
2023-02-22 18:43:48 +00:00
* Project Info: https://plantuml.com
2011-08-08 17:48:29 +00:00
*
2017-03-15 19:13:31 +00:00
* If you like this project or if you find it useful, you can support us at:
*
2023-02-22 18:43:48 +00:00
* https://plantuml.com/patreon (only 1$ per month!)
* https://plantuml.com/paypal
2017-03-15 19:13:31 +00:00
*
2011-08-08 17:48:29 +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
2013-12-10 19:36:50 +00:00
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
2011-08-08 17:48:29 +00:00
* 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
*
*
*/
package net.sourceforge.plantuml.svek;
import static java.nio.charset.StandardCharsets.UTF_8;
2011-08-08 17:48:29 +00:00
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
2022-12-17 11:10:05 +00:00
import net.sourceforge.plantuml.StringUtils;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.abel.Entity;
import net.sourceforge.plantuml.abel.EntityFactory;
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.dot.DotData;
import net.sourceforge.plantuml.dot.DotSplines;
import net.sourceforge.plantuml.dot.Graphviz;
import net.sourceforge.plantuml.dot.GraphvizUtils;
import net.sourceforge.plantuml.dot.GraphvizVersion;
import net.sourceforge.plantuml.dot.GraphvizVersions;
import net.sourceforge.plantuml.dot.ProcessState;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.klimt.font.StringBounder;
import net.sourceforge.plantuml.klimt.geom.Moveable;
import net.sourceforge.plantuml.klimt.geom.Rankdir;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.klimt.geom.XPoint2D;
2020-05-30 15:20:23 +00:00
import net.sourceforge.plantuml.security.SFile;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.skin.UmlDiagramType;
import net.sourceforge.plantuml.style.ISkinParam;
import net.sourceforge.plantuml.utils.Position;
2016-06-19 14:16:41 +00:00
import net.sourceforge.plantuml.vizjs.GraphvizJs;
import net.sourceforge.plantuml.vizjs.GraphvizJsRuntimeException;
2011-08-08 17:48:29 +00:00
2011-09-08 10:42:27 +00:00
public class DotStringFactory implements Moveable {
2011-08-08 17:48:29 +00:00
2013-12-10 19:36:50 +00:00
private final Bibliotekon bibliotekon = new Bibliotekon();
2011-08-08 17:48:29 +00:00
private final ColorSequence colorSequence;
private final Cluster root;
2013-12-10 19:36:50 +00:00
2011-08-08 17:48:29 +00:00
private Cluster current;
2016-03-06 16:47:34 +00:00
private final UmlDiagramType umlDiagramType;
private final ISkinParam skinParam;
private final DotMode dotMode;
2021-08-30 17:13:54 +00:00
private DotSplines dotSplines;
2011-08-08 17:48:29 +00:00
private final StringBounder stringBounder;
2016-07-25 19:25:28 +00:00
public DotStringFactory(StringBounder stringBounder, DotData dotData) {
2016-03-06 16:47:34 +00:00
this.skinParam = dotData.getSkinParam();
this.umlDiagramType = dotData.getUmlDiagramType();
this.dotMode = dotData.getDotMode();
2016-07-25 19:25:28 +00:00
this.colorSequence = new ColorSequence();
2016-03-06 16:47:34 +00:00
this.stringBounder = stringBounder;
2022-09-01 17:40:58 +00:00
this.root = new Cluster(dotData.getEntityFactory().getDiagram(), colorSequence, skinParam,
dotData.getRootGroup());
2016-03-06 16:47:34 +00:00
this.current = root;
}
2022-11-04 17:36:03 +00:00
public DotStringFactory(StringBounder stringBounder, ICucaDiagram diagram) {
2016-03-06 16:47:34 +00:00
this.skinParam = diagram.getSkinParam();
this.umlDiagramType = diagram.getUmlDiagramType();
this.dotMode = DotMode.NORMAL;
2016-07-25 19:25:28 +00:00
this.colorSequence = new ColorSequence();
2011-08-08 17:48:29 +00:00
this.stringBounder = stringBounder;
this.root = new Cluster(diagram, colorSequence, skinParam, diagram.getEntityFactory().getRootGroup());
2011-08-08 17:48:29 +00:00
this.current = root;
}
2021-02-02 10:12:15 +00:00
public void addNode(SvekNode node) {
2020-02-18 21:24:31 +00:00
current.addNode(node);
2011-08-08 17:48:29 +00:00
}
private double getHorizontalDzeta() {
double max = 0;
2021-04-20 20:19:49 +00:00
for (SvekLine l : bibliotekon.allLines()) {
2011-08-08 17:48:29 +00:00
final double c = l.getHorizontalDzeta(stringBounder);
2022-02-17 18:27:32 +00:00
if (c > max)
2011-08-08 17:48:29 +00:00
max = c;
2022-02-17 18:27:32 +00:00
2011-08-08 17:48:29 +00:00
}
return max / 10;
}
private double getVerticalDzeta() {
double max = 0;
2021-04-20 20:19:49 +00:00
for (SvekLine l : bibliotekon.allLines()) {
2011-08-08 17:48:29 +00:00
final double c = l.getVerticalDzeta(stringBounder);
2022-02-17 18:27:32 +00:00
if (c > max)
2011-08-08 17:48:29 +00:00
max = c;
2022-02-17 18:27:32 +00:00
2011-08-08 17:48:29 +00:00
}
2022-09-12 20:08:34 +00:00
if (root.diagram.getPragma().useKermor())
2022-09-06 08:49:43 +00:00
return max / 100;
2011-08-08 17:48:29 +00:00
return max / 10;
}
2023-02-06 21:04:53 +00:00
// ::comment when CORE
2013-12-10 19:36:50 +00:00
String createDotString(String... dotStrings) {
2011-08-08 17:48:29 +00:00
final StringBuilder sb = new StringBuilder();
double nodesep = getHorizontalDzeta();
2022-02-17 18:27:32 +00:00
if (nodesep < getMinNodeSep())
2011-08-08 17:48:29 +00:00
nodesep = getMinNodeSep();
2022-02-17 18:27:32 +00:00
if (skinParam.getNodesep() != 0)
2016-03-06 16:47:34 +00:00
nodesep = skinParam.getNodesep();
2022-02-17 18:27:32 +00:00
2011-08-08 17:48:29 +00:00
final String nodesepInches = SvekUtils.pixelToInches(nodesep);
2013-12-10 19:36:50 +00:00
// Log.println("nodesep=" + nodesepInches);
2011-08-08 17:48:29 +00:00
double ranksep = getVerticalDzeta();
2022-02-17 18:27:32 +00:00
if (ranksep < getMinRankSep())
2011-08-08 17:48:29 +00:00
ranksep = getMinRankSep();
2022-02-17 18:27:32 +00:00
if (skinParam.getRanksep() != 0)
2016-03-06 16:47:34 +00:00
ranksep = skinParam.getRanksep();
2022-02-17 18:27:32 +00:00
2011-08-08 17:48:29 +00:00
final String ranksepInches = SvekUtils.pixelToInches(ranksep);
2013-12-10 19:36:50 +00:00
// Log.println("ranksep=" + ranksepInches);
2011-08-08 17:48:29 +00:00
sb.append("digraph unix {");
SvekUtils.println(sb);
for (String s : dotStrings) {
if (s.startsWith("ranksep"))
2011-08-08 17:48:29 +00:00
sb.append("ranksep=" + ranksepInches + ";");
else if (s.startsWith("nodesep"))
2011-08-08 17:48:29 +00:00
sb.append("nodesep=" + nodesepInches + ";");
else
2011-08-08 17:48:29 +00:00
sb.append(s);
2011-08-08 17:48:29 +00:00
SvekUtils.println(sb);
}
2015-04-07 18:18:37 +00:00
// sb.append("newrank=true;");
// SvekUtils.println(sb);
2011-08-08 17:48:29 +00:00
sb.append("remincross=true;");
SvekUtils.println(sb);
sb.append("searchsize=500;");
SvekUtils.println(sb);
2016-03-06 16:47:34 +00:00
// if (OptionFlags.USE_COMPOUND) {
// sb.append("compound=true;");
// SvekUtils.println(sb);
// }
2016-01-30 12:20:07 +00:00
2021-08-30 17:13:54 +00:00
dotSplines = skinParam.getDotSplines();
2016-01-30 12:20:07 +00:00
if (dotSplines == DotSplines.POLYLINE) {
sb.append("splines=polyline;");
SvekUtils.println(sb);
} else if (dotSplines == DotSplines.ORTHO) {
sb.append("splines=ortho;");
2021-08-30 17:13:54 +00:00
sb.append("forcelabels=true;");
2016-01-30 12:20:07 +00:00
SvekUtils.println(sb);
}
2016-03-06 16:47:34 +00:00
if (skinParam.getRankdir() == Rankdir.LEFT_TO_RIGHT) {
2013-12-10 19:36:50 +00:00
sb.append("rankdir=LR;");
SvekUtils.println(sb);
}
manageMinMaxCluster(sb);
2022-09-12 20:08:34 +00:00
if (root.diagram.getPragma().useKermor()) {
2022-09-06 08:49:43 +00:00
for (SvekLine line : bibliotekon.lines0())
line.appendLine(getGraphvizVersion(), sb, dotMode, dotSplines);
for (SvekLine line : bibliotekon.lines1())
line.appendLine(getGraphvizVersion(), sb, dotMode, dotSplines);
root.printCluster3_forKermor(sb, bibliotekon.allLines(), stringBounder, dotMode, getGraphvizVersion(),
umlDiagramType);
2022-02-17 18:27:32 +00:00
2022-09-06 08:49:43 +00:00
} else {
root.printCluster1(sb, bibliotekon.allLines(), stringBounder);
2011-08-08 17:48:29 +00:00
2022-09-06 08:49:43 +00:00
for (SvekLine line : bibliotekon.lines0())
line.appendLine(getGraphvizVersion(), sb, dotMode, dotSplines);
root.printCluster2(sb, bibliotekon.allLines(), stringBounder, dotMode, getGraphvizVersion(),
umlDiagramType);
for (SvekLine line : bibliotekon.lines1())
line.appendLine(getGraphvizVersion(), sb, dotMode, dotSplines);
}
2022-02-17 18:27:32 +00:00
2011-08-08 17:48:29 +00:00
SvekUtils.println(sb);
sb.append("}");
return sb.toString();
}
// ::done
2011-08-08 17:48:29 +00:00
2013-12-10 19:36:50 +00:00
private void manageMinMaxCluster(final StringBuilder sb) {
2021-05-14 08:42:57 +00:00
final List<String> minPointCluster = new ArrayList<>();
final List<String> maxPointCluster = new ArrayList<>();
2013-12-10 19:36:50 +00:00
for (Cluster cluster : bibliotekon.allCluster()) {
2016-03-06 16:47:34 +00:00
final String minPoint = cluster.getMinPoint(umlDiagramType);
2022-02-17 18:27:32 +00:00
if (minPoint != null)
2013-12-10 19:36:50 +00:00
minPointCluster.add(minPoint);
2022-02-17 18:27:32 +00:00
2016-03-06 16:47:34 +00:00
final String maxPoint = cluster.getMaxPoint(umlDiagramType);
2022-02-17 18:27:32 +00:00
if (maxPoint != null)
2013-12-10 19:36:50 +00:00
maxPointCluster.add(maxPoint);
2022-02-17 18:27:32 +00:00
2013-12-10 19:36:50 +00:00
}
if (minPointCluster.size() > 0) {
sb.append("{rank=min;");
for (String s : minPointCluster) {
sb.append(s);
sb.append(" [shape=point,width=.01,label=\"\"]");
sb.append(";");
}
sb.append("}");
SvekUtils.println(sb);
}
if (maxPointCluster.size() > 0) {
sb.append("{rank=max;");
for (String s : maxPointCluster) {
sb.append(s);
sb.append(" [shape=point,width=.01,label=\"\"]");
sb.append(";");
}
sb.append("}");
SvekUtils.println(sb);
}
}
2011-08-08 17:48:29 +00:00
private int getMinRankSep() {
2016-03-06 16:47:34 +00:00
if (umlDiagramType == UmlDiagramType.ACTIVITY) {
2013-12-10 19:36:50 +00:00
// return 29;
return 40;
2011-08-08 17:48:29 +00:00
}
2022-09-12 20:08:34 +00:00
if (root.diagram.getPragma().useKermor())
2022-09-06 08:49:43 +00:00
return 40;
2011-08-08 17:48:29 +00:00
return 60;
}
private int getMinNodeSep() {
2016-03-06 16:47:34 +00:00
if (umlDiagramType == UmlDiagramType.ACTIVITY) {
2013-12-10 19:36:50 +00:00
// return 15;
return 20;
2011-08-08 17:48:29 +00:00
}
2013-12-10 19:36:50 +00:00
return 35;
}
2023-02-06 21:04:53 +00:00
// ::uncomment when CORE
// public GraphvizVersion getGraphvizVersion() {
// return null;
// }
// ::done
2023-02-06 21:04:53 +00:00
// ::comment when CORE
2022-08-26 16:00:28 +00:00
private GraphvizVersion graphvizVersion;
public GraphvizVersion getGraphvizVersion() {
if (graphvizVersion == null)
graphvizVersion = getGraphvizVersionInternal();
return graphvizVersion;
}
private GraphvizVersion getGraphvizVersionInternal() {
final Graphviz graphviz = GraphvizUtils.create(skinParam, "foo;", "svg");
if (graphviz instanceof GraphvizJs)
return GraphvizJs.getGraphvizVersion(false);
final File f = graphviz.getDotExe();
return GraphvizVersions.getInstance().getVersion(f);
}
2016-06-19 14:16:41 +00:00
public String getSvg(BaseFile basefile, String[] dotOptions) throws IOException {
String dotString = createDotString(dotOptions);
2013-12-10 19:36:50 +00:00
2016-05-11 21:31:47 +00:00
if (basefile != null) {
2020-05-30 15:20:23 +00:00
final SFile f = basefile.getTraceFile("svek.dot");
2016-05-11 21:31:47 +00:00
SvekUtils.traceString(f, dotString);
2013-12-10 19:36:50 +00:00
}
2011-08-08 17:48:29 +00:00
2016-06-19 14:16:41 +00:00
Graphviz graphviz = GraphvizUtils.create(skinParam, dotString, "svg");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
final ProcessState state = graphviz.createFile3(baos);
baos.close();
if (state.differs(ProcessState.TERMINATED_OK()))
2016-06-19 14:16:41 +00:00
throw new IllegalStateException("Timeout4 " + state, state.getCause());
2016-06-19 14:16:41 +00:00
} catch (GraphvizJsRuntimeException e) {
System.err.println("GraphvizJsRuntimeException");
2022-08-26 16:00:28 +00:00
graphvizVersion = GraphvizJs.getGraphvizVersion(true);
2016-06-19 14:16:41 +00:00
dotString = createDotString(dotOptions);
graphviz = GraphvizUtils.create(skinParam, dotString, "svg");
baos = new ByteArrayOutputStream();
final ProcessState state = graphviz.createFile3(baos);
baos.close();
2022-02-17 18:27:32 +00:00
if (state.differs(ProcessState.TERMINATED_OK()))
2016-06-19 14:16:41 +00:00
throw new IllegalStateException("Timeout4 " + state, state.getCause());
2022-02-17 18:27:32 +00:00
2013-12-10 19:36:50 +00:00
}
2011-08-08 17:48:29 +00:00
final byte[] result = baos.toByteArray();
final String s = new String(result, UTF_8);
2011-08-08 17:48:29 +00:00
2016-05-11 21:31:47 +00:00
if (basefile != null) {
2020-05-30 15:20:23 +00:00
final SFile f = basefile.getTraceFile("svek.svg");
2016-05-11 21:31:47 +00:00
SvekUtils.traceString(f, s);
2013-12-10 19:36:50 +00:00
}
2011-08-08 17:48:29 +00:00
return s;
}
public boolean illegalDotExe() {
2016-04-04 19:05:10 +00:00
final Graphviz graphviz = GraphvizUtils.create(skinParam, "svg");
2022-02-17 18:27:32 +00:00
if (graphviz instanceof GraphvizJs)
2016-06-19 14:16:41 +00:00
return false;
2022-02-17 18:27:32 +00:00
2011-08-08 17:48:29 +00:00
final File dotExe = graphviz.getDotExe();
return dotExe == null || dotExe.isFile() == false || dotExe.canRead() == false;
}
public File getDotExe() {
2016-04-04 19:05:10 +00:00
final Graphviz graphviz = GraphvizUtils.create(skinParam, "svg");
2011-08-08 17:48:29 +00:00
return graphviz.getDotExe();
}
2023-01-11 21:47:15 +00:00
public void solve(EntityFactory entityFactory, final String svg) throws IOException, InterruptedException {
2022-02-17 18:27:32 +00:00
if (svg.length() == 0)
2013-12-10 19:36:50 +00:00
throw new EmptySvgException();
2011-08-08 17:48:29 +00:00
final Pattern pGraph = Pattern.compile("(?m)\\<svg\\s+width=\"(\\d+)pt\"\\s+height=\"(\\d+)pt\"");
final Matcher mGraph = pGraph.matcher(svg);
2022-02-17 18:27:32 +00:00
if (mGraph.find() == false)
2011-08-08 17:48:29 +00:00
throw new IllegalStateException();
2022-02-17 18:27:32 +00:00
final int fullHeight = Integer.parseInt(mGraph.group(2));
2013-12-10 19:36:50 +00:00
2018-03-09 21:37:34 +00:00
final Point2DFunction move = new YDelta(fullHeight);
final SvgResult svgResult = new SvgResult(svg, move);
2021-02-02 10:12:15 +00:00
for (SvekNode node : bibliotekon.allNodes()) {
2020-02-18 21:24:31 +00:00
int idx = svg.indexOf("<title>" + node.getUid() + "</title>");
if (node.getType() == ShapeType.RECTANGLE || node.getType() == ShapeType.RECTANGLE_HTML_FOR_PORTS
|| node.getType() == ShapeType.RECTANGLE_WITH_CIRCLE_INSIDE || node.getType() == ShapeType.FOLDER
|| node.getType() == ShapeType.DIAMOND || node.getType() == ShapeType.RECTANGLE_PORT) {
2022-09-12 20:08:34 +00:00
final List<XPoint2D> points = svgResult.substring(idx).extractList(SvgResult.POINTS_EQUALS);
final XPoint2D min = SvekUtils.getMinXY(points);
2022-09-06 08:49:43 +00:00
node.moveSvek(min.getX(), min.getY());
2020-02-18 21:24:31 +00:00
} else if (node.getType() == ShapeType.ROUND_RECTANGLE) {
2013-12-10 19:36:50 +00:00
final int idx2 = svg.indexOf("d=\"", idx + 1);
2011-08-08 17:48:29 +00:00
idx = svg.indexOf("points=\"", idx + 1);
2022-09-12 20:08:34 +00:00
final List<XPoint2D> points;
2015-04-07 18:18:37 +00:00
if (idx2 != -1 && (idx == -1 || idx2 < idx)) {
2013-12-10 19:36:50 +00:00
// GraphViz 2.30
2018-03-09 21:37:34 +00:00
points = svgResult.substring(idx2).extractList(SvgResult.D_EQUALS);
2013-12-10 19:36:50 +00:00
} else {
2018-03-09 21:37:34 +00:00
points = svgResult.substring(idx).extractList(SvgResult.POINTS_EQUALS);
2013-12-10 19:36:50 +00:00
for (int i = 0; i < 3; i++) {
idx = svg.indexOf("points=\"", idx + 1);
2018-03-09 21:37:34 +00:00
points.addAll(svgResult.substring(idx).extractList(SvgResult.POINTS_EQUALS));
2013-12-10 19:36:50 +00:00
}
2011-08-08 17:48:29 +00:00
}
2022-09-12 20:08:34 +00:00
final XPoint2D min = SvekUtils.getMinXY(points);
2022-09-06 08:49:43 +00:00
node.moveSvek(min.getX(), min.getY());
2021-02-02 10:12:15 +00:00
} else if (node.getType() == ShapeType.OCTAGON || node.getType() == ShapeType.HEXAGON) {
2015-04-07 18:18:37 +00:00
idx = svg.indexOf("points=\"", idx + 1);
2018-03-09 21:37:34 +00:00
final int starting = idx;
2022-09-12 20:08:34 +00:00
final List<XPoint2D> points = svgResult.substring(starting).extractList(SvgResult.POINTS_EQUALS);
final XPoint2D min = SvekUtils.getMinXY(points);
2020-06-07 10:03:18 +00:00
// corner1.manage(minX, minY);
2022-09-06 08:49:43 +00:00
node.moveSvek(min.getX(), min.getY());
node.setPolygon(min.getX(), min.getY(), points);
2022-09-01 17:40:58 +00:00
} else if (node.getType() == ShapeType.CIRCLE || node.getType() == ShapeType.OVAL) {
2011-08-08 17:48:29 +00:00
final double cx = SvekUtils.getValue(svg, idx, "cx");
final double cy = SvekUtils.getValue(svg, idx, "cy") + fullHeight;
final double rx = SvekUtils.getValue(svg, idx, "rx");
final double ry = SvekUtils.getValue(svg, idx, "ry");
2020-02-18 21:24:31 +00:00
node.moveSvek(cx - rx, cy - ry);
2011-08-08 17:48:29 +00:00
} else {
2020-02-18 21:24:31 +00:00
throw new IllegalStateException(node.getType().toString() + " " + node.getUid());
2011-08-08 17:48:29 +00:00
}
}
2013-12-10 19:36:50 +00:00
for (Cluster cluster : bibliotekon.allCluster()) {
int idx = getClusterIndex(svg, cluster.getColor());
2018-03-09 21:37:34 +00:00
final int starting = idx;
2022-09-12 20:08:34 +00:00
final List<XPoint2D> points = svgResult.substring(starting).extractList(SvgResult.POINTS_EQUALS);
final XPoint2D min = SvekUtils.getMinXY(points);
final XPoint2D max = SvekUtils.getMaxXY(points);
2022-09-06 08:49:43 +00:00
cluster.setPosition(min, max);
2011-08-08 17:48:29 +00:00
2022-02-17 18:27:32 +00:00
if (cluster.getTitleAndAttributeWidth() == 0 || cluster.getTitleAndAttributeHeight() == 0)
2011-08-08 17:48:29 +00:00
continue;
2022-02-17 18:27:32 +00:00
2013-12-10 19:36:50 +00:00
idx = getClusterIndex(svg, cluster.getTitleColor());
2022-09-12 20:08:34 +00:00
final List<XPoint2D> pointsTitle = svgResult.substring(idx).extractList(SvgResult.POINTS_EQUALS);
2022-09-06 08:49:43 +00:00
cluster.setTitlePosition(SvekUtils.getMinXY(pointsTitle));
2022-09-12 20:08:34 +00:00
if (root.diagram.getPragma().useKermor()) {
if (cluster.getGroup().getNotes(Position.TOP).size() > 0) {
final List<XPoint2D> noteUp = svgResult.substring(getClusterIndex(svg, cluster.getColorNoteTop()))
.extractList(SvgResult.POINTS_EQUALS);
cluster.setNoteTopPosition(SvekUtils.getMinXY(noteUp));
}
if (cluster.getGroup().getNotes(Position.BOTTOM).size() > 0) {
final List<XPoint2D> noteBottom = svgResult
.substring(getClusterIndex(svg, cluster.getColorNoteBottom()))
.extractList(SvgResult.POINTS_EQUALS);
cluster.setNoteBottomPosition(SvekUtils.getMinXY(noteBottom));
2022-09-06 08:49:43 +00:00
}
}
2011-08-08 17:48:29 +00:00
}
2022-02-17 18:27:32 +00:00
for (SvekLine line : bibliotekon.allLines())
2020-06-07 10:03:18 +00:00
line.solveLine(svgResult);
2011-09-07 20:41:58 +00:00
2022-02-17 18:27:32 +00:00
for (SvekLine line : bibliotekon.allLines())
2020-02-18 21:24:31 +00:00
line.manageCollision(bibliotekon.allNodes());
2022-02-17 18:27:32 +00:00
2011-08-08 17:48:29 +00:00
}
2013-12-10 19:36:50 +00:00
private int getClusterIndex(final String svg, int colorInt) {
2022-02-17 18:27:32 +00:00
final String colorString = StringUtils.goLowerCase(StringUtils.sharp000000(colorInt));
2013-12-10 19:36:50 +00:00
final String keyTitle1 = "=\"" + colorString + "\"";
int idx = svg.indexOf(keyTitle1);
if (idx == -1) {
final String keyTitle2 = "stroke:" + colorString + ";";
idx = svg.indexOf(keyTitle2);
2011-09-08 10:42:27 +00:00
}
2022-02-17 18:27:32 +00:00
if (idx == -1)
2013-12-10 19:36:50 +00:00
throw new IllegalStateException("Cannot find color " + colorString);
2011-08-08 17:48:29 +00:00
2022-02-17 18:27:32 +00:00
return idx;
2020-04-26 18:31:41 +00:00
}
// ::done
2020-04-26 18:31:41 +00:00
2023-02-06 21:04:53 +00:00
public void openCluster(Entity g, ClusterHeader clusterHeader) {
2022-09-15 17:24:26 +00:00
this.current = current.createChild(clusterHeader, colorSequence, skinParam, g);
2013-12-10 19:36:50 +00:00
bibliotekon.addCluster(this.current);
2011-08-08 17:48:29 +00:00
}
public void closeCluster() {
2022-02-17 18:27:32 +00:00
if (current.getParentCluster() == null)
2011-08-08 17:48:29 +00:00
throw new IllegalStateException();
2022-02-17 18:27:32 +00:00
2020-02-18 21:24:31 +00:00
this.current = current.getParentCluster();
2011-08-08 17:48:29 +00:00
}
2011-09-08 10:42:27 +00:00
public void moveSvek(double deltaX, double deltaY) {
2022-02-17 18:27:32 +00:00
for (SvekNode sh : bibliotekon.allNodes())
2011-09-08 10:42:27 +00:00
sh.moveSvek(deltaX, deltaY);
2022-02-17 18:27:32 +00:00
for (SvekLine line : bibliotekon.allLines())
2011-09-08 10:42:27 +00:00
line.moveSvek(deltaX, deltaY);
2022-02-17 18:27:32 +00:00
for (Cluster cl : bibliotekon.allCluster())
2011-09-08 10:42:27 +00:00
cl.moveSvek(deltaX, deltaY);
}
2013-12-10 19:36:50 +00:00
public final Bibliotekon getBibliotekon() {
return bibliotekon;
}
2016-04-04 19:05:10 +00:00
public ColorSequence getColorSequence() {
return colorSequence;
}
2011-08-08 17:48:29 +00:00
}