2011-08-08 17:48:29 +00:00
|
|
|
/* ========================================================================
|
|
|
|
* PlantUML : a free UML diagram generator
|
|
|
|
* ========================================================================
|
|
|
|
*
|
2019-01-16 18:34:41 +00:00
|
|
|
* (C) Copyright 2009-2020, 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
|
|
|
*
|
2017-03-15 19:13:31 +00:00
|
|
|
* If you like this project or if you find it useful, you can support us at:
|
|
|
|
*
|
|
|
|
* http://plantuml.com/patreon (only 1$ per month!)
|
|
|
|
* http://plantuml.com/paypal
|
|
|
|
*
|
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 java.awt.geom.Dimension2D;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.OutputStream;
|
2013-12-10 19:36:50 +00:00
|
|
|
import java.util.ArrayList;
|
2011-08-08 17:48:29 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
2016-01-30 12:20:07 +00:00
|
|
|
import net.sourceforge.plantuml.AnnotatedWorker;
|
2016-05-11 21:31:47 +00:00
|
|
|
import net.sourceforge.plantuml.BaseFile;
|
2011-08-08 17:48:29 +00:00
|
|
|
import net.sourceforge.plantuml.FileFormatOption;
|
2016-05-11 21:31:47 +00:00
|
|
|
import net.sourceforge.plantuml.NamedOutputStream;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.Scale;
|
2011-08-08 17:48:29 +00:00
|
|
|
import net.sourceforge.plantuml.UmlDiagramType;
|
2020-12-01 21:39:27 +00:00
|
|
|
import net.sourceforge.plantuml.UseStyle;
|
2018-05-01 17:26:04 +00:00
|
|
|
import net.sourceforge.plantuml.api.ImageDataAbstract;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.core.ImageData;
|
2011-08-08 17:48:29 +00:00
|
|
|
import net.sourceforge.plantuml.cucadiagram.CucaDiagram;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.cucadiagram.Link;
|
|
|
|
import net.sourceforge.plantuml.cucadiagram.dot.CucaDiagramSimplifierActivity;
|
|
|
|
import net.sourceforge.plantuml.cucadiagram.dot.CucaDiagramSimplifierState;
|
2011-08-08 17:48:29 +00:00
|
|
|
import net.sourceforge.plantuml.cucadiagram.dot.DotData;
|
2016-08-25 20:45:37 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.StringBounder;
|
2020-05-07 14:12:08 +00:00
|
|
|
import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft;
|
|
|
|
import net.sourceforge.plantuml.style.SName;
|
|
|
|
import net.sourceforge.plantuml.style.Style;
|
|
|
|
import net.sourceforge.plantuml.style.StyleSignature;
|
2015-04-07 18:18:37 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
|
2020-05-07 14:12:08 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.color.HColor;
|
2011-08-08 17:48:29 +00:00
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
public final class CucaDiagramFileMakerSvek implements CucaDiagramFileMaker {
|
2011-08-08 17:48:29 +00:00
|
|
|
|
|
|
|
private final CucaDiagram diagram;
|
|
|
|
|
2015-04-07 18:18:37 +00:00
|
|
|
public CucaDiagramFileMakerSvek(CucaDiagram diagram) throws IOException {
|
2011-08-08 17:48:29 +00:00
|
|
|
this.diagram = diagram;
|
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
public ImageData createFile(OutputStream os, List<String> dotStrings, FileFormatOption fileFormatOption)
|
2011-08-08 17:48:29 +00:00
|
|
|
throws IOException {
|
|
|
|
try {
|
2011-09-07 20:41:58 +00:00
|
|
|
return createFileInternal(os, dotStrings, fileFormatOption);
|
2011-08-08 17:48:29 +00:00
|
|
|
} catch (InterruptedException e) {
|
|
|
|
e.printStackTrace();
|
2013-12-10 19:36:50 +00:00
|
|
|
throw new IOException(e);
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
|
|
|
|
2018-08-26 12:09:50 +00:00
|
|
|
private GeneralImageBuilder createDotDataImageBuilder(DotMode dotMode, StringBounder stringBounder) {
|
2015-04-07 18:18:37 +00:00
|
|
|
final DotData dotData = new DotData(diagram.getEntityFactory().getRootGroup(), getOrderedLinks(),
|
|
|
|
diagram.getLeafsvalues(), diagram.getUmlDiagramType(), diagram.getSkinParam(), diagram, diagram,
|
2020-02-18 21:24:31 +00:00
|
|
|
diagram.getColorMapper(), diagram.getEntityFactory(), diagram.isHideEmptyDescriptionForState(), dotMode,
|
|
|
|
diagram.getNamespaceSeparator(), diagram.getPragma());
|
|
|
|
final boolean intricated = diagram.mergeIntricated();
|
|
|
|
return new GeneralImageBuilder(intricated, dotData, diagram.getEntityFactory(), diagram.getSource(),
|
2020-05-07 14:12:08 +00:00
|
|
|
diagram.getPragma(), stringBounder, diagram.getUmlDiagramType().getStyleName());
|
2011-08-08 17:48:29 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
private ImageData createFileInternal(OutputStream os, List<String> dotStrings, FileFormatOption fileFormatOption)
|
2011-08-08 17:48:29 +00:00
|
|
|
throws IOException, InterruptedException {
|
2013-12-10 19:36:50 +00:00
|
|
|
if (diagram.getUmlDiagramType() == UmlDiagramType.ACTIVITY) {
|
2016-08-25 20:45:37 +00:00
|
|
|
new CucaDiagramSimplifierActivity(diagram, dotStrings, fileFormatOption.getDefaultStringBounder());
|
2013-12-10 19:36:50 +00:00
|
|
|
} else if (diagram.getUmlDiagramType() == UmlDiagramType.STATE) {
|
2016-08-25 20:45:37 +00:00
|
|
|
new CucaDiagramSimplifierState(diagram, dotStrings, fileFormatOption.getDefaultStringBounder());
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 21:31:47 +00:00
|
|
|
// System.err.println("FOO11 type=" + os.getClass());
|
2018-08-26 12:09:50 +00:00
|
|
|
GeneralImageBuilder svek2 = createDotDataImageBuilder(DotMode.NORMAL,
|
2016-11-04 21:39:29 +00:00
|
|
|
fileFormatOption.getDefaultStringBounder());
|
2016-05-11 21:31:47 +00:00
|
|
|
BaseFile basefile = null;
|
|
|
|
if (fileFormatOption.isDebugSvek() && os instanceof NamedOutputStream) {
|
|
|
|
basefile = ((NamedOutputStream) os).getBasefile();
|
|
|
|
}
|
|
|
|
// System.err.println("FOO11 basefile=" + basefile);
|
|
|
|
|
2016-07-25 19:25:28 +00:00
|
|
|
TextBlockBackcolored result = svek2.buildImage(basefile, diagram.getDotStringSkek());
|
2013-12-10 19:36:50 +00:00
|
|
|
if (result instanceof GraphvizCrash) {
|
2016-11-04 21:39:29 +00:00
|
|
|
svek2 = createDotDataImageBuilder(DotMode.NO_LEFT_RIGHT_AND_XLABEL,
|
|
|
|
fileFormatOption.getDefaultStringBounder());
|
2016-07-25 19:25:28 +00:00
|
|
|
result = svek2.buildImage(basefile, diagram.getDotStringSkek());
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
2018-05-01 17:26:04 +00:00
|
|
|
final boolean isGraphvizCrash = result instanceof GraphvizCrash;
|
2018-11-26 18:46:22 +00:00
|
|
|
result = new AnnotatedWorker(diagram, diagram.getSkinParam(), fileFormatOption.getDefaultStringBounder())
|
|
|
|
.addAdd(result);
|
2011-08-08 17:48:29 +00:00
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
final String widthwarning = diagram.getSkinParam().getValue("widthwarning");
|
2016-07-25 19:25:28 +00:00
|
|
|
String warningOrError = null;
|
2013-12-10 19:36:50 +00:00
|
|
|
if (widthwarning != null && widthwarning.matches("\\d+")) {
|
2016-07-25 19:25:28 +00:00
|
|
|
warningOrError = svek2.getWarningOrError(Integer.parseInt(widthwarning));
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
2016-08-25 20:45:37 +00:00
|
|
|
final Dimension2D dim = result.calculateDimension(fileFormatOption.getDefaultStringBounder());
|
2015-04-07 18:18:37 +00:00
|
|
|
final double scale = getScale(fileFormatOption, dim);
|
|
|
|
|
2020-05-07 14:12:08 +00:00
|
|
|
final HColor backcolor = result.getBackcolor();
|
|
|
|
final ClockwiseTopRightBottomLeft margins;
|
2020-12-01 21:39:27 +00:00
|
|
|
if (UseStyle.useBetaStyle()) {
|
2020-05-07 14:12:08 +00:00
|
|
|
final Style style = StyleSignature.of(SName.root, SName.document)
|
|
|
|
.getMergedStyle(diagram.getSkinParam().getCurrentStyleBuilder());
|
|
|
|
margins = style.getMargin();
|
|
|
|
} else {
|
2020-09-30 20:57:58 +00:00
|
|
|
margins = ClockwiseTopRightBottomLeft.topRightBottomLeft(0, 5, 5, 0);
|
2020-05-07 14:12:08 +00:00
|
|
|
}
|
|
|
|
final ImageBuilder imageBuilder = ImageBuilder.buildC(diagram.getSkinParam(), margins, diagram.getAnimation(),
|
|
|
|
fileFormatOption.isWithMetadata() ? diagram.getMetadata() : null, warningOrError, scale, backcolor);
|
2016-03-06 16:47:34 +00:00
|
|
|
imageBuilder.setUDrawable(result);
|
2018-05-01 17:26:04 +00:00
|
|
|
final ImageData imageData = imageBuilder.writeImageTOBEMOVED(fileFormatOption, diagram.seed(), os);
|
|
|
|
if (isGraphvizCrash) {
|
|
|
|
((ImageDataAbstract) imageData).setStatus(503);
|
|
|
|
}
|
|
|
|
return imageData;
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
private List<Link> getOrderedLinks() {
|
|
|
|
final List<Link> result = new ArrayList<Link>();
|
|
|
|
for (Link l : diagram.getLinks()) {
|
|
|
|
addLinkNew(result, l);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2011-09-07 20:41:58 +00:00
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
private void addLinkNew(List<Link> result, Link link) {
|
|
|
|
for (int i = 0; i < result.size(); i++) {
|
|
|
|
final Link other = result.get(i);
|
|
|
|
if (other.sameConnections(link)) {
|
|
|
|
while (i < result.size() && result.get(i).sameConnections(link)) {
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (i == result.size()) {
|
|
|
|
result.add(link);
|
|
|
|
} else {
|
|
|
|
result.add(i, link);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.add(link);
|
|
|
|
}
|
2011-09-07 20:41:58 +00:00
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
private double getScale(FileFormatOption fileFormatOption, final Dimension2D dim) {
|
|
|
|
final double scale;
|
|
|
|
final Scale diagScale = diagram.getScale();
|
|
|
|
if (diagScale == null) {
|
2019-03-29 22:14:07 +00:00
|
|
|
scale = diagram.getScaleCoef(fileFormatOption);
|
2013-12-10 19:36:50 +00:00
|
|
|
} else {
|
|
|
|
scale = diagScale.getScale(dim.getWidth(), dim.getHeight());
|
|
|
|
}
|
|
|
|
return scale;
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|