2020-02-18 21:24:31 +00:00
|
|
|
/* ========================================================================
|
|
|
|
* PlantUML : a free UML diagram generator
|
|
|
|
* ========================================================================
|
|
|
|
*
|
|
|
|
* (C) Copyright 2009-2020, Arnaud Roques
|
|
|
|
*
|
|
|
|
* Project Info: http://plantuml.com
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
|
|
* 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.wire;
|
|
|
|
|
|
|
|
import java.awt.geom.Dimension2D;
|
|
|
|
import java.awt.geom.Rectangle2D;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.OutputStream;
|
2020-12-19 21:21:54 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2020-02-18 21:24:31 +00:00
|
|
|
|
|
|
|
import net.sourceforge.plantuml.AnnotatedWorker;
|
|
|
|
import net.sourceforge.plantuml.FileFormatOption;
|
|
|
|
import net.sourceforge.plantuml.ISkinParam;
|
|
|
|
import net.sourceforge.plantuml.Scale;
|
2020-05-07 14:12:08 +00:00
|
|
|
import net.sourceforge.plantuml.SkinParam;
|
2020-02-18 21:24:31 +00:00
|
|
|
import net.sourceforge.plantuml.UmlDiagram;
|
|
|
|
import net.sourceforge.plantuml.UmlDiagramType;
|
2020-12-01 21:39:27 +00:00
|
|
|
import net.sourceforge.plantuml.UseStyle;
|
2020-02-18 21:24:31 +00:00
|
|
|
import net.sourceforge.plantuml.command.CommandExecutionResult;
|
|
|
|
import net.sourceforge.plantuml.core.DiagramDescription;
|
|
|
|
import net.sourceforge.plantuml.core.ImageData;
|
|
|
|
import net.sourceforge.plantuml.graphic.InnerStrategy;
|
|
|
|
import net.sourceforge.plantuml.graphic.StringBounder;
|
|
|
|
import net.sourceforge.plantuml.graphic.TextBlock;
|
2020-05-07 14:12:08 +00:00
|
|
|
import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft;
|
2020-02-18 21:24:31 +00:00
|
|
|
import net.sourceforge.plantuml.svek.TextBlockBackcolored;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
|
2020-12-06 21:43:09 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.ImageParameter;
|
2020-02-18 21:24:31 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.MinMax;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UGraphic;
|
2020-03-18 10:50:02 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.color.HColor;
|
2020-02-18 21:24:31 +00:00
|
|
|
|
|
|
|
public class WireDiagram extends UmlDiagram {
|
|
|
|
|
2020-12-19 21:21:54 +00:00
|
|
|
private final WBlock root = new WBlock("", 0, 0);
|
|
|
|
private final List<Spot> spots = new ArrayList<Spot>();
|
|
|
|
private final List<WLink> links = new ArrayList<WLink>();
|
2020-02-18 21:24:31 +00:00
|
|
|
|
|
|
|
public DiagramDescription getDescription() {
|
|
|
|
return new DiagramDescription("Wire Diagram");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public UmlDiagramType getUmlDiagramType() {
|
|
|
|
return UmlDiagramType.WIRE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected ImageData exportDiagramInternal(OutputStream os, int index, FileFormatOption fileFormatOption)
|
|
|
|
throws IOException {
|
|
|
|
final Scale scale = getScale();
|
|
|
|
|
|
|
|
final double dpiFactor = scale == null ? getScaleCoef(fileFormatOption) : scale.getScale(100, 100);
|
|
|
|
final ISkinParam skinParam = getSkinParam();
|
2020-09-30 20:57:58 +00:00
|
|
|
|
2020-05-07 14:12:08 +00:00
|
|
|
final int margin1;
|
|
|
|
final int margin2;
|
2020-12-01 21:39:27 +00:00
|
|
|
if (UseStyle.useBetaStyle()) {
|
2020-05-07 14:12:08 +00:00
|
|
|
margin1 = SkinParam.zeroMargin(10);
|
|
|
|
margin2 = SkinParam.zeroMargin(10);
|
|
|
|
} else {
|
|
|
|
margin1 = 10;
|
|
|
|
margin2 = 10;
|
|
|
|
}
|
2020-12-06 21:43:09 +00:00
|
|
|
HColor backcolor = skinParam.getBackgroundColor(false);
|
|
|
|
|
|
|
|
final ClockwiseTopRightBottomLeft margins = ClockwiseTopRightBottomLeft.margin1margin2(margin1, margin2);
|
|
|
|
final String metadata = fileFormatOption.isWithMetadata() ? getMetadata() : null;
|
|
|
|
final ImageParameter imageParameter = new ImageParameter(skinParam.getColorMapper(), skinParam.handwritten(),
|
|
|
|
null, dpiFactor, metadata, "", margins, backcolor);
|
|
|
|
|
|
|
|
final ImageBuilder imageBuilder = ImageBuilder.build(imageParameter);
|
2020-02-18 21:24:31 +00:00
|
|
|
TextBlock result = getTextBlock();
|
|
|
|
|
2020-12-06 21:43:09 +00:00
|
|
|
result = new AnnotatedWorker(this, skinParam, fileFormatOption.getDefaultStringBounder(getSkinParam()))
|
|
|
|
.addAdd(result);
|
2020-02-18 21:24:31 +00:00
|
|
|
imageBuilder.setUDrawable(result);
|
|
|
|
|
|
|
|
return imageBuilder.writeImageTOBEMOVED(fileFormatOption, seed(), os);
|
|
|
|
}
|
|
|
|
|
|
|
|
private TextBlockBackcolored getTextBlock() {
|
|
|
|
return new TextBlockBackcolored() {
|
|
|
|
|
|
|
|
public void drawU(UGraphic ug) {
|
|
|
|
drawMe(ug);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Rectangle2D getInnerPosition(String member, StringBounder stringBounder, InnerStrategy strategy) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Dimension2D calculateDimension(StringBounder stringBounder) {
|
2020-12-19 21:21:54 +00:00
|
|
|
// return getDrawingElement().calculateDimension(stringBounder);
|
|
|
|
throw new UnsupportedOperationException();
|
2020-02-18 21:24:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public MinMax getMinMax(StringBounder stringBounder) {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
2020-03-18 10:50:02 +00:00
|
|
|
public HColor getBackcolor() {
|
2020-02-18 21:24:31 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
private void drawMe(UGraphic ug) {
|
2020-12-19 21:21:54 +00:00
|
|
|
root.drawMe(ug);
|
|
|
|
for (Spot spot : spots) {
|
|
|
|
spot.drawMe(ug);
|
|
|
|
}
|
|
|
|
for (WLink link : links) {
|
|
|
|
link.drawMe(ug);
|
|
|
|
}
|
2020-02-18 21:24:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-12-19 21:21:54 +00:00
|
|
|
public CommandExecutionResult addComponent(String indent, String name, int width, int height) {
|
|
|
|
final int level = indent.replace(" ", "\t").length();
|
|
|
|
return this.root.addComponent(level, name, width, height);
|
2020-02-18 21:24:31 +00:00
|
|
|
}
|
|
|
|
|
2020-12-19 21:21:54 +00:00
|
|
|
public CommandExecutionResult newColumn(String indent) {
|
|
|
|
final int level = indent.replace(" ", "\t").length();
|
|
|
|
return this.root.newColumn(level);
|
2020-02-18 21:24:31 +00:00
|
|
|
}
|
|
|
|
|
2020-12-19 21:21:54 +00:00
|
|
|
public CommandExecutionResult spot(String name, HColor color, String x, String y) {
|
|
|
|
final WBlock block = this.root.getBlock(name);
|
|
|
|
if (block == null) {
|
|
|
|
return CommandExecutionResult.error("No such element " + name);
|
|
|
|
}
|
|
|
|
final Spot spot = new Spot(block, color, x, y);
|
|
|
|
this.spots.add(spot);
|
2020-02-18 21:24:31 +00:00
|
|
|
return CommandExecutionResult.ok();
|
|
|
|
}
|
|
|
|
|
2020-12-19 21:21:54 +00:00
|
|
|
public CommandExecutionResult wgoto(String indent, double x, double y) {
|
|
|
|
final int level = indent.replace(" ", "\t").length();
|
|
|
|
return this.root.wgoto(level, x, y);
|
2020-02-18 21:24:31 +00:00
|
|
|
}
|
|
|
|
|
2020-12-19 21:21:54 +00:00
|
|
|
public CommandExecutionResult wmove(String indent, double x, double y) {
|
|
|
|
final int level = indent.replace(" ", "\t").length();
|
|
|
|
return this.root.wmove(level, x, y);
|
2020-02-18 21:24:31 +00:00
|
|
|
}
|
|
|
|
|
2020-12-19 21:21:54 +00:00
|
|
|
public CommandExecutionResult link(String name1, String x1, String y1, String name2, WLinkType type, HColor color) {
|
|
|
|
final WBlock block1 = this.root.getBlock(name1);
|
|
|
|
if (block1 == null) {
|
|
|
|
return CommandExecutionResult.error("No such element " + name1);
|
|
|
|
}
|
|
|
|
final WBlock block2 = this.root.getBlock(name2);
|
|
|
|
if (block2 == null) {
|
|
|
|
return CommandExecutionResult.error("No such element " + name2);
|
|
|
|
}
|
|
|
|
final WLink link = new WLink(block1, x1, y1, block2, type, color);
|
|
|
|
this.links.add(link);
|
2020-02-18 21:24:31 +00:00
|
|
|
|
|
|
|
return CommandExecutionResult.ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|