1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-01 16:10:48 +00:00
plantuml/src/net/sourceforge/plantuml/svek/CucaDiagramFileMakerSvek.java

156 lines
6.0 KiB
Java
Raw Normal View History

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.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;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.UmlDiagramType;
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;
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(),
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 {
2020-12-06 21:43:09 +00:00
final StringBounder stringBounder = fileFormatOption.getDefaultStringBounder(diagram.getSkinParam());
2013-12-10 19:36:50 +00:00
if (diagram.getUmlDiagramType() == UmlDiagramType.ACTIVITY) {
2020-12-06 21:43:09 +00:00
new CucaDiagramSimplifierActivity(diagram, dotStrings, stringBounder);
2013-12-10 19:36:50 +00:00
} else if (diagram.getUmlDiagramType() == UmlDiagramType.STATE) {
2020-12-06 21:43:09 +00:00
new CucaDiagramSimplifierState(diagram, dotStrings, stringBounder);
2011-08-08 17:48:29 +00:00
}
2016-05-11 21:31:47 +00:00
// System.err.println("FOO11 type=" + os.getClass());
2020-12-06 21:43:09 +00:00
GeneralImageBuilder svek2 = createDotDataImageBuilder(DotMode.NORMAL, stringBounder);
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) {
2020-12-06 21:43:09 +00:00
svek2 = createDotDataImageBuilder(DotMode.NO_LEFT_RIGHT_AND_XLABEL, stringBounder);
2016-07-25 19:25:28 +00:00
result = svek2.buildImage(basefile, diagram.getDotStringSkek());
2013-12-10 19:36:50 +00:00
}
// TODO There is something strange with the left margin of mainframe, I think because AnnotatedWorker is used here
// It can be looked at in another PR
2020-12-06 21:43:09 +00:00
result = new AnnotatedWorker(diagram, diagram.getSkinParam(), stringBounder).addAdd(result);
2011-08-08 17:48:29 +00:00
// TODO UmlDiagram.getWarningOrError() looks similar so this might be simplified? - will leave for a separate PR
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
}
2021-03-19 16:58:09 +00:00
// Sorry about this hack. There is a side effect in SvekResult::calculateDimension()
result.calculateDimension(stringBounder); // Ensure text near the margins is not cut off
2015-04-07 18:18:37 +00:00
return diagram.createImageBuilder(fileFormatOption)
.annotations(false) // backwards compatibility (AnnotatedWorker is used above)
.drawable(result)
.status(result instanceof GraphvizCrash ? 503 : 0)
.warningOrError(warningOrError)
.write(os);
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
2011-08-08 17:48:29 +00:00
}