2011-08-08 17:48:29 +00:00
|
|
|
/* ========================================================================
|
|
|
|
* PlantUML : a free UML diagram generator
|
|
|
|
* ========================================================================
|
|
|
|
*
|
2016-01-09 12:15:40 +00:00
|
|
|
* (C) Copyright 2009-2017, Arnaud Roques
|
2011-08-08 17:48:29 +00:00
|
|
|
*
|
2016-03-06 16:47:34 +00:00
|
|
|
* Project Info: http://plantuml.com
|
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.
|
|
|
|
*
|
|
|
|
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
|
|
|
|
* in the United States and other countries.]
|
|
|
|
*
|
|
|
|
* Original Author: Arnaud Roques
|
|
|
|
*
|
|
|
|
* Revision $Revision: 4236 $
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package net.sourceforge.plantuml.svek;
|
|
|
|
|
|
|
|
import java.awt.geom.Point2D;
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
2016-05-11 21:31:47 +00:00
|
|
|
import net.sourceforge.plantuml.BaseFile;
|
2016-03-06 16:47:34 +00:00
|
|
|
import net.sourceforge.plantuml.ISkinParam;
|
|
|
|
import net.sourceforge.plantuml.StringUtils;
|
2011-08-08 17:48:29 +00:00
|
|
|
import net.sourceforge.plantuml.UmlDiagramType;
|
2016-03-06 16:47:34 +00:00
|
|
|
import net.sourceforge.plantuml.cucadiagram.CucaDiagram;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.cucadiagram.IGroup;
|
|
|
|
import net.sourceforge.plantuml.cucadiagram.Rankdir;
|
|
|
|
import net.sourceforge.plantuml.cucadiagram.dot.DotData;
|
2016-01-30 12:20:07 +00:00
|
|
|
import net.sourceforge.plantuml.cucadiagram.dot.DotSplines;
|
2011-08-08 17:48:29 +00:00
|
|
|
import net.sourceforge.plantuml.cucadiagram.dot.Graphviz;
|
|
|
|
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizUtils;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizVersion;
|
|
|
|
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizVersions;
|
|
|
|
import net.sourceforge.plantuml.cucadiagram.dot.ProcessState;
|
2011-08-08 17:48:29 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.StringBounder;
|
|
|
|
import net.sourceforge.plantuml.graphic.TextBlock;
|
2011-09-08 10:42:27 +00:00
|
|
|
import net.sourceforge.plantuml.posimo.Moveable;
|
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
|
|
|
|
|
|
|
final private Set<String> rankMin = new HashSet<String>();
|
|
|
|
|
|
|
|
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;
|
2011-08-08 17:48:29 +00:00
|
|
|
|
|
|
|
private final StringBounder stringBounder;
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
public DotStringFactory(ColorSequence colorSequence, StringBounder stringBounder, DotData dotData) {
|
2016-03-06 16:47:34 +00:00
|
|
|
this.skinParam = dotData.getSkinParam();
|
|
|
|
this.umlDiagramType = dotData.getUmlDiagramType();
|
|
|
|
this.dotMode = dotData.getDotMode();
|
|
|
|
|
|
|
|
this.colorSequence = colorSequence;
|
|
|
|
this.stringBounder = stringBounder;
|
|
|
|
this.root = new Cluster(colorSequence, skinParam, dotData.getRootGroup());
|
|
|
|
this.current = root;
|
|
|
|
}
|
|
|
|
|
|
|
|
public DotStringFactory(ColorSequence colorSequence, StringBounder stringBounder, CucaDiagram diagram) {
|
|
|
|
this.skinParam = diagram.getSkinParam();
|
|
|
|
this.umlDiagramType = diagram.getUmlDiagramType();
|
|
|
|
this.dotMode = DotMode.NORMAL;
|
|
|
|
|
2011-08-08 17:48:29 +00:00
|
|
|
this.colorSequence = colorSequence;
|
|
|
|
this.stringBounder = stringBounder;
|
2016-03-06 16:47:34 +00:00
|
|
|
this.root = new Cluster(colorSequence, skinParam, diagram.getEntityFactory().getRootGroup());
|
2011-08-08 17:48:29 +00:00
|
|
|
this.current = root;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addShape(Shape shape) {
|
|
|
|
current.addShape(shape);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void printMinRanking(StringBuilder sb) {
|
|
|
|
if (rankMin.size() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sb.append("{ rank = min;");
|
|
|
|
for (String id : rankMin) {
|
|
|
|
sb.append(id);
|
|
|
|
sb.append(";");
|
|
|
|
}
|
|
|
|
sb.append("}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private double getHorizontalDzeta() {
|
|
|
|
double max = 0;
|
2013-12-10 19:36:50 +00:00
|
|
|
for (Line l : bibliotekon.allLines()) {
|
2011-08-08 17:48:29 +00:00
|
|
|
final double c = l.getHorizontalDzeta(stringBounder);
|
|
|
|
if (c > max) {
|
|
|
|
max = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return max / 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
private double getVerticalDzeta() {
|
|
|
|
double max = 0;
|
2013-12-10 19:36:50 +00:00
|
|
|
for (Line l : bibliotekon.allLines()) {
|
2011-08-08 17:48:29 +00:00
|
|
|
final double c = l.getVerticalDzeta(stringBounder);
|
|
|
|
if (c > max) {
|
|
|
|
max = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return max / 10;
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
if (nodesep < getMinNodeSep()) {
|
|
|
|
nodesep = getMinNodeSep();
|
|
|
|
}
|
2016-03-06 16:47:34 +00:00
|
|
|
if (skinParam.getNodesep() != 0) {
|
|
|
|
nodesep = skinParam.getNodesep();
|
2013-12-10 19:36:50 +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();
|
|
|
|
if (ranksep < getMinRankSep()) {
|
|
|
|
ranksep = getMinRankSep();
|
|
|
|
}
|
2016-03-06 16:47:34 +00:00
|
|
|
if (skinParam.getRanksep() != 0) {
|
|
|
|
ranksep = skinParam.getRanksep();
|
2013-12-10 19:36:50 +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")) {
|
|
|
|
sb.append("ranksep=" + ranksepInches + ";");
|
|
|
|
} else if (s.startsWith("nodesep")) {
|
|
|
|
sb.append("nodesep=" + nodesepInches + ";");
|
|
|
|
} else {
|
|
|
|
sb.append(s);
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2016-03-06 16:47:34 +00:00
|
|
|
final DotSplines 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;");
|
|
|
|
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);
|
|
|
|
|
|
|
|
root.printCluster1(sb, bibliotekon.allLines());
|
|
|
|
for (Line line : bibliotekon.lines0()) {
|
2011-09-08 10:42:27 +00:00
|
|
|
line.appendLine(sb);
|
|
|
|
}
|
2011-08-08 17:48:29 +00:00
|
|
|
root.fillRankMin(rankMin);
|
2016-03-06 16:47:34 +00:00
|
|
|
root.printCluster2(sb, bibliotekon.allLines(), stringBounder, dotMode, getGraphvizVersion(), umlDiagramType);
|
2011-08-08 17:48:29 +00:00
|
|
|
printMinRanking(sb);
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
for (Line line : bibliotekon.lines1()) {
|
2011-08-08 17:48:29 +00:00
|
|
|
line.appendLine(sb);
|
|
|
|
}
|
|
|
|
SvekUtils.println(sb);
|
|
|
|
sb.append("}");
|
|
|
|
|
|
|
|
return sb.toString();
|
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
private void manageMinMaxCluster(final StringBuilder sb) {
|
|
|
|
final List<String> minPointCluster = new ArrayList<String>();
|
|
|
|
final List<String> maxPointCluster = new ArrayList<String>();
|
|
|
|
for (Cluster cluster : bibliotekon.allCluster()) {
|
2016-03-06 16:47:34 +00:00
|
|
|
final String minPoint = cluster.getMinPoint(umlDiagramType);
|
2013-12-10 19:36:50 +00:00
|
|
|
if (minPoint != null) {
|
|
|
|
minPointCluster.add(minPoint);
|
|
|
|
}
|
2016-03-06 16:47:34 +00:00
|
|
|
final String maxPoint = cluster.getMaxPoint(umlDiagramType);
|
2013-12-10 19:36:50 +00:00
|
|
|
if (maxPoint != null) {
|
|
|
|
maxPointCluster.add(maxPoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
public GraphvizVersion getGraphvizVersion() {
|
2016-04-04 19:05:10 +00:00
|
|
|
final Graphviz graphviz = GraphvizUtils.create(skinParam, "foo;", "svg");
|
2013-12-10 19:36:50 +00:00
|
|
|
final File f = graphviz.getDotExe();
|
|
|
|
return GraphvizVersions.getInstance().getVersion(f);
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 21:31:47 +00:00
|
|
|
public String getSvg(BaseFile basefile, String[] dotStrings) throws IOException {
|
2011-08-08 17:48:29 +00:00
|
|
|
final String dotString = createDotString(dotStrings);
|
2013-12-10 19:36:50 +00:00
|
|
|
|
2016-05-11 21:31:47 +00:00
|
|
|
if (basefile != null) {
|
|
|
|
final File f = basefile.getTraceFile("svek.dot");
|
|
|
|
SvekUtils.traceString(f, dotString);
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
2011-08-08 17:48:29 +00:00
|
|
|
|
2016-04-04 19:05:10 +00:00
|
|
|
final Graphviz graphviz = GraphvizUtils.create(skinParam, dotString, "svg");
|
2011-08-08 17:48:29 +00:00
|
|
|
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
2013-12-10 19:36:50 +00:00
|
|
|
final ProcessState state = graphviz.createFile3(baos);
|
2011-08-08 17:48:29 +00:00
|
|
|
baos.close();
|
2015-04-07 18:18:37 +00:00
|
|
|
if (state.differs(ProcessState.TERMINATED_OK())) {
|
|
|
|
throw new IllegalStateException("Timeout4 " + state, state.getCause());
|
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");
|
|
|
|
|
2016-05-11 21:31:47 +00:00
|
|
|
if (basefile != null) {
|
|
|
|
final File f = basefile.getTraceFile("svek.svg");
|
|
|
|
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");
|
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();
|
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
public ClusterPosition solve(String svg) throws IOException, InterruptedException {
|
|
|
|
if (svg.length() == 0) {
|
|
|
|
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);
|
|
|
|
if (mGraph.find() == false) {
|
|
|
|
throw new IllegalStateException();
|
|
|
|
}
|
|
|
|
final int fullWidth = Integer.parseInt(mGraph.group(1));
|
|
|
|
final int fullHeight = Integer.parseInt(mGraph.group(2));
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
final MinFinder corner1 = new MinFinder();
|
|
|
|
|
|
|
|
for (Shape sh : bibliotekon.allShapes()) {
|
2011-08-08 17:48:29 +00:00
|
|
|
int idx = svg.indexOf("<title>" + sh.getUid() + "</title>");
|
2015-09-28 20:42:17 +00:00
|
|
|
if (sh.getType() == ShapeType.RECTANGLE || sh.getType() == ShapeType.FOLDER
|
|
|
|
|| sh.getType() == ShapeType.DIAMOND) {
|
2011-08-08 17:48:29 +00:00
|
|
|
final List<Point2D.Double> points = SvekUtils.extractPointsList(svg, idx, fullHeight);
|
|
|
|
final double minX = SvekUtils.getMinX(points);
|
|
|
|
final double minY = SvekUtils.getMinY(points);
|
2013-12-10 19:36:50 +00:00
|
|
|
corner1.manage(minX, minY);
|
|
|
|
sh.moveSvek(minX, minY);
|
2011-08-08 17:48:29 +00:00
|
|
|
} else if (sh.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);
|
2013-12-10 19:36:50 +00:00
|
|
|
final List<Point2D.Double> 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
|
|
|
|
points = SvekUtils.extractD(svg, idx2, fullHeight);
|
|
|
|
} else {
|
|
|
|
points = SvekUtils.extractPointsList(svg, idx, fullHeight);
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
idx = svg.indexOf("points=\"", idx + 1);
|
|
|
|
points.addAll(SvekUtils.extractPointsList(svg, idx, fullHeight));
|
|
|
|
}
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
|
|
|
final double minX = SvekUtils.getMinX(points);
|
|
|
|
final double minY = SvekUtils.getMinY(points);
|
2013-12-10 19:36:50 +00:00
|
|
|
corner1.manage(minX, minY);
|
|
|
|
sh.moveSvek(minX, minY);
|
2015-04-07 18:18:37 +00:00
|
|
|
} else if (sh.getType() == ShapeType.OCTAGON) {
|
|
|
|
idx = svg.indexOf("points=\"", idx + 1);
|
|
|
|
final List<Point2D.Double> points = SvekUtils.extractPointsList(svg, idx, fullHeight);
|
|
|
|
final double minX = SvekUtils.getMinX(points);
|
|
|
|
final double minY = SvekUtils.getMinY(points);
|
|
|
|
corner1.manage(minX, minY);
|
|
|
|
sh.moveSvek(minX, minY);
|
|
|
|
sh.setOctagon(minX, minY, points);
|
2011-08-08 17:48:29 +00:00
|
|
|
} else if (sh.getType() == ShapeType.CIRCLE || sh.getType() == ShapeType.CIRCLE_IN_RECT
|
|
|
|
|| sh.getType() == ShapeType.OVAL) {
|
|
|
|
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");
|
2013-12-10 19:36:50 +00:00
|
|
|
sh.moveSvek(cx - rx, cy - ry);
|
2011-08-08 17:48:29 +00:00
|
|
|
} else {
|
|
|
|
throw new IllegalStateException(sh.getType().toString() + " " + sh.getUid());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
for (Cluster cluster : bibliotekon.allCluster()) {
|
|
|
|
int idx = getClusterIndex(svg, cluster.getColor());
|
2011-08-08 17:48:29 +00:00
|
|
|
final List<Point2D.Double> points = SvekUtils.extractPointsList(svg, idx, fullHeight);
|
|
|
|
final double minX = SvekUtils.getMinX(points);
|
|
|
|
final double minY = SvekUtils.getMinY(points);
|
|
|
|
final double maxX = SvekUtils.getMaxX(points);
|
|
|
|
final double maxY = SvekUtils.getMaxY(points);
|
|
|
|
cluster.setPosition(minX, minY, maxX, maxY);
|
2013-12-10 19:36:50 +00:00
|
|
|
corner1.manage(minX, minY);
|
2011-08-08 17:48:29 +00:00
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
if (cluster.getTitleAndAttributeWidth() == 0 || cluster.getTitleAndAttributeHeight() == 0) {
|
2011-08-08 17:48:29 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-12-10 19:36:50 +00:00
|
|
|
idx = getClusterIndex(svg, cluster.getTitleColor());
|
2011-08-08 17:48:29 +00:00
|
|
|
final List<Point2D.Double> pointsTitle = SvekUtils.extractPointsList(svg, idx, fullHeight);
|
|
|
|
final double minXtitle = SvekUtils.getMinX(pointsTitle);
|
|
|
|
final double minYtitle = SvekUtils.getMinY(pointsTitle);
|
|
|
|
cluster.setTitlePosition(minXtitle, minYtitle);
|
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
for (Line line : bibliotekon.allLines()) {
|
2016-03-06 16:47:34 +00:00
|
|
|
line.solveLine(svg, fullHeight, corner1);
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
2011-09-07 20:41:58 +00:00
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
for (Line line : bibliotekon.allLines()) {
|
|
|
|
line.manageCollision(bibliotekon.allShapes());
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
2013-12-10 19:36:50 +00:00
|
|
|
corner1.manage(0, 0);
|
|
|
|
return new ClusterPosition(corner1.getMinX(), corner1.getMinY(), fullWidth, fullHeight);
|
|
|
|
// return new ClusterPosition(0, 0, fullWidth, fullHeight);
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
private int getClusterIndex(final String svg, int colorInt) {
|
2015-04-07 18:18:37 +00:00
|
|
|
final String colorString = StringUtils.goLowerCase(StringUtils.getAsHtml(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
|
|
|
}
|
2013-12-10 19:36:50 +00:00
|
|
|
if (idx == -1) {
|
|
|
|
throw new IllegalStateException("Cannot find color " + colorString);
|
2011-09-08 10:42:27 +00:00
|
|
|
}
|
2013-12-10 19:36:50 +00:00
|
|
|
return idx;
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
public void openCluster(IGroup g, int titleAndAttributeWidth, int titleAndAttributeHeight, TextBlock title,
|
|
|
|
TextBlock stereo) {
|
|
|
|
this.current = current.createChild(g, titleAndAttributeWidth, titleAndAttributeHeight, title, stereo,
|
2016-03-06 16:47:34 +00:00
|
|
|
colorSequence, skinParam);
|
2013-12-10 19:36:50 +00:00
|
|
|
bibliotekon.addCluster(this.current);
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void closeCluster() {
|
|
|
|
if (current.getParent() == null) {
|
|
|
|
throw new IllegalStateException();
|
|
|
|
}
|
|
|
|
this.current = current.getParent();
|
|
|
|
}
|
|
|
|
|
2011-09-08 10:42:27 +00:00
|
|
|
public void moveSvek(double deltaX, double deltaY) {
|
2013-12-10 19:36:50 +00:00
|
|
|
for (Shape sh : bibliotekon.allShapes()) {
|
2011-09-08 10:42:27 +00:00
|
|
|
sh.moveSvek(deltaX, deltaY);
|
|
|
|
}
|
2013-12-10 19:36:50 +00:00
|
|
|
for (Line line : bibliotekon.allLines()) {
|
2011-09-08 10:42:27 +00:00
|
|
|
line.moveSvek(deltaX, deltaY);
|
|
|
|
}
|
2013-12-10 19:36:50 +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
|
|
|
}
|