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: 6711 $
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
import net.sourceforge.plantuml.FontParam;
|
|
|
|
import net.sourceforge.plantuml.ISkinParam;
|
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;
|
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;
|
2015-04-07 18:18:37 +00:00
|
|
|
import net.sourceforge.plantuml.cucadiagram.Stereotype;
|
2013-12-10 19:36:50 +00:00
|
|
|
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;
|
|
|
|
import net.sourceforge.plantuml.graphic.HtmlColor;
|
|
|
|
import net.sourceforge.plantuml.graphic.StringBounder;
|
|
|
|
import net.sourceforge.plantuml.graphic.StringBounderUtils;
|
2015-04-07 18:18:37 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
|
2011-08-08 17:48:29 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.UFont;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
static private final StringBounder stringBounder;
|
|
|
|
|
|
|
|
static {
|
2016-04-04 19:05:10 +00:00
|
|
|
stringBounder = StringBounderUtils.asStringBounder();
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
private CucaDiagramFileMakerSvek2 buildCucaDiagramFileMakerSvek2(DotMode dotMode) {
|
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,
|
|
|
|
diagram.getColorMapper(), diagram.getEntityFactory(), diagram.isHideEmptyDescriptionForState(),
|
|
|
|
dotMode, diagram.getNamespaceSeparator(), diagram.getPragma());
|
2013-12-10 19:36:50 +00:00
|
|
|
final CucaDiagramFileMakerSvek2 svek2 = new CucaDiagramFileMakerSvek2(dotData, diagram.getEntityFactory(),
|
2015-04-07 18:18:37 +00:00
|
|
|
diagram.getSource(), diagram.getPragma());
|
2013-12-10 19:36:50 +00:00
|
|
|
return svek2;
|
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) {
|
|
|
|
new CucaDiagramSimplifierActivity(diagram, dotStrings);
|
|
|
|
} else if (diagram.getUmlDiagramType() == UmlDiagramType.STATE) {
|
|
|
|
new CucaDiagramSimplifierState(diagram, dotStrings);
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 21:31:47 +00:00
|
|
|
// System.err.println("FOO11 type=" + os.getClass());
|
2013-12-10 19:36:50 +00:00
|
|
|
CucaDiagramFileMakerSvek2 svek2 = buildCucaDiagramFileMakerSvek2(DotMode.NORMAL);
|
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);
|
|
|
|
|
|
|
|
TextBlockBackcolored result = svek2.createFile(basefile, diagram.getDotStringSkek());
|
2013-12-10 19:36:50 +00:00
|
|
|
if (result instanceof GraphvizCrash) {
|
|
|
|
svek2 = buildCucaDiagramFileMakerSvek2(DotMode.NO_LEFT_RIGHT);
|
2016-05-11 21:31:47 +00:00
|
|
|
result = svek2.createFile(basefile, diagram.getDotStringSkek());
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
2016-01-30 12:20:07 +00:00
|
|
|
result = new AnnotatedWorker(diagram, diagram.getSkinParam()).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");
|
|
|
|
if (widthwarning != null && widthwarning.matches("\\d+")) {
|
|
|
|
this.warningOrError = svek2.getBibliotekon().getWarningOrError(Integer.parseInt(widthwarning));
|
|
|
|
} else {
|
|
|
|
this.warningOrError = null;
|
|
|
|
}
|
2015-04-07 18:18:37 +00:00
|
|
|
final Dimension2D dim = result.calculateDimension(stringBounder);
|
|
|
|
final double scale = getScale(fileFormatOption, dim);
|
|
|
|
|
|
|
|
final ImageBuilder imageBuilder = new ImageBuilder(diagram.getSkinParam().getColorMapper(), scale,
|
|
|
|
result.getBackcolor(), fileFormatOption.isWithMetadata() ? diagram.getMetadata() : null,
|
|
|
|
warningOrError, 0, 10, diagram.getAnimation(), diagram.getSkinParam().handwritten());
|
2016-03-06 16:47:34 +00:00
|
|
|
imageBuilder.setUDrawable(result);
|
2015-05-31 18:56:03 +00:00
|
|
|
return imageBuilder.writeImageTOBEMOVED(fileFormatOption, os);
|
2013-12-10 19:36:50 +00:00
|
|
|
|
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 String warningOrError;
|
2011-09-07 20:41:58 +00:00
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
private String getWarningOrError() {
|
|
|
|
return warningOrError;
|
2011-09-07 20:41:58 +00:00
|
|
|
}
|
|
|
|
|
2011-08-08 17:48:29 +00:00
|
|
|
private final UFont getFont(FontParam fontParam) {
|
|
|
|
final ISkinParam skinParam = diagram.getSkinParam();
|
2016-01-09 12:15:40 +00:00
|
|
|
return skinParam.getFont(null, false, fontParam);
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 18:18:37 +00:00
|
|
|
private final HtmlColor getFontColor(FontParam fontParam, Stereotype stereo) {
|
2011-08-08 17:48:29 +00:00
|
|
|
final ISkinParam skinParam = diagram.getSkinParam();
|
2016-01-09 12:15:40 +00:00
|
|
|
return skinParam.getFontHtmlColor(stereo, fontParam);
|
2011-08-08 17:48:29 +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) {
|
|
|
|
scale = diagram.getDpiFactor(fileFormatOption);
|
|
|
|
} else {
|
|
|
|
scale = diagScale.getScale(dim.getWidth(), dim.getHeight());
|
|
|
|
}
|
|
|
|
return scale;
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|