plantuml/src/net/sourceforge/plantuml/svek/GeneralImageBuilder.java

643 lines
24 KiB
Java
Raw Normal View History

2011-08-08 17:48:29 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2022-03-07 19:33:46 +00:00
* (C) Copyright 2009-2023, Arnaud Roques
2011-08-08 17:48:29 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
2022-08-17 17:34:24 +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:
2022-08-17 17:34:24 +00:00
*
2017-03-15 19:13:31 +00:00
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
2022-08-17 17:34:24 +00:00
*
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
* Contribution : Hisashi Miyashita
2020-05-18 20:01:37 +00:00
* Contribution : Serge Wenger
2022-08-17 17:34:24 +00:00
*
2011-08-08 17:48:29 +00:00
*
*/
package net.sourceforge.plantuml.svek;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
2016-07-25 19:25:28 +00:00
import java.util.Map;
2013-12-10 19:36:50 +00:00
import java.util.regex.Matcher;
import java.util.regex.Pattern;
2011-08-08 17:48:29 +00:00
2016-05-11 21:31:47 +00:00
import net.sourceforge.plantuml.BaseFile;
2019-03-29 22:14:07 +00:00
import net.sourceforge.plantuml.Guillemet;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.ISkinParam;
2020-06-14 20:35:42 +00:00
import net.sourceforge.plantuml.LineParam;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.OptionFlags;
import net.sourceforge.plantuml.Pragma;
2022-10-18 20:57:44 +00:00
import net.sourceforge.plantuml.SkinParam;
2022-12-17 11:10:05 +00:00
import net.sourceforge.plantuml.StringUtils;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.UmlDiagramType;
2022-09-12 20:08:34 +00:00
import net.sourceforge.plantuml.awt.geom.XDimension2D;
import net.sourceforge.plantuml.awt.geom.XRectangle2D;
2022-11-07 19:27:11 +00:00
import net.sourceforge.plantuml.baraye.EntityFactory;
import net.sourceforge.plantuml.baraye.EntityImp;
import net.sourceforge.plantuml.baraye.IEntity;
import net.sourceforge.plantuml.baraye.IGroup;
import net.sourceforge.plantuml.baraye.ILeaf;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.cucadiagram.EntityPosition;
2019-09-22 17:20:16 +00:00
import net.sourceforge.plantuml.cucadiagram.GroupRoot;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.cucadiagram.GroupType;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.LeafType;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.cucadiagram.Link;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.PortionShower;
import net.sourceforge.plantuml.cucadiagram.Stereotype;
import net.sourceforge.plantuml.cucadiagram.UnparsableGraphvizException;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.cucadiagram.dot.DotData;
2016-07-25 19:25:28 +00:00
import net.sourceforge.plantuml.cucadiagram.dot.ExeState;
2020-09-19 15:43:24 +00:00
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizUtils;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizVersion;
import net.sourceforge.plantuml.cucadiagram.dot.Neighborhood;
2018-05-21 19:15:19 +00:00
import net.sourceforge.plantuml.descdiagram.EntityImageDesignedDomain;
import net.sourceforge.plantuml.descdiagram.EntityImageDomain;
import net.sourceforge.plantuml.descdiagram.EntityImageMachine;
import net.sourceforge.plantuml.descdiagram.EntityImageRequirement;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.graphic.FontConfiguration;
import net.sourceforge.plantuml.graphic.GraphicStrings;
2019-09-22 17:20:16 +00:00
import net.sourceforge.plantuml.graphic.InnerStrategy;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.graphic.StringBounder;
2021-02-02 10:12:15 +00:00
import net.sourceforge.plantuml.graphic.USymbolHexagon;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.graphic.USymbolInterface;
2022-08-17 17:34:24 +00:00
import net.sourceforge.plantuml.log.Logme;
import net.sourceforge.plantuml.security.SecurityProfile;
import net.sourceforge.plantuml.security.SecurityUtils;
2020-06-07 10:03:18 +00:00
import net.sourceforge.plantuml.style.PName;
2019-08-26 17:07:21 +00:00
import net.sourceforge.plantuml.style.SName;
import net.sourceforge.plantuml.style.Style;
2022-05-04 17:52:00 +00:00
import net.sourceforge.plantuml.style.StyleSignature;
2022-03-01 18:11:51 +00:00
import net.sourceforge.plantuml.style.StyleSignatureBasic;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.svek.image.EntityImageActivity;
import net.sourceforge.plantuml.svek.image.EntityImageArcCircle;
import net.sourceforge.plantuml.svek.image.EntityImageAssociation;
import net.sourceforge.plantuml.svek.image.EntityImageAssociationPoint;
import net.sourceforge.plantuml.svek.image.EntityImageBranch;
import net.sourceforge.plantuml.svek.image.EntityImageCircleEnd;
import net.sourceforge.plantuml.svek.image.EntityImageCircleStart;
import net.sourceforge.plantuml.svek.image.EntityImageClass;
2020-05-18 20:01:37 +00:00
import net.sourceforge.plantuml.svek.image.EntityImageDeepHistory;
2015-07-11 09:32:49 +00:00
import net.sourceforge.plantuml.svek.image.EntityImageDescription;
2015-08-05 20:17:01 +00:00
import net.sourceforge.plantuml.svek.image.EntityImageEmptyPackage;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.svek.image.EntityImageGroup;
2022-03-01 18:11:51 +00:00
import net.sourceforge.plantuml.svek.image.EntityImageJson;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.svek.image.EntityImageLollipopInterface;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.svek.image.EntityImageLollipopInterfaceEye1;
import net.sourceforge.plantuml.svek.image.EntityImageLollipopInterfaceEye2;
2020-04-05 15:13:04 +00:00
import net.sourceforge.plantuml.svek.image.EntityImageMap;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.svek.image.EntityImageNote;
import net.sourceforge.plantuml.svek.image.EntityImageObject;
import net.sourceforge.plantuml.svek.image.EntityImagePort;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.svek.image.EntityImagePseudoState;
import net.sourceforge.plantuml.svek.image.EntityImageState;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.svek.image.EntityImageState2;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.svek.image.EntityImageStateBorder;
import net.sourceforge.plantuml.svek.image.EntityImageStateEmptyDescription;
import net.sourceforge.plantuml.svek.image.EntityImageSynchroBar;
2015-05-31 18:56:03 +00:00
import net.sourceforge.plantuml.svek.image.EntityImageTips;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.svek.image.EntityImageUseCase;
2019-09-22 17:20:16 +00:00
import net.sourceforge.plantuml.ugraphic.MinMax;
import net.sourceforge.plantuml.ugraphic.UGraphic;
2020-06-14 20:35:42 +00:00
import net.sourceforge.plantuml.ugraphic.UStroke;
2020-03-18 10:50:02 +00:00
import net.sourceforge.plantuml.ugraphic.color.HColor;
2022-12-17 11:01:10 +00:00
import net.sourceforge.plantuml.utils.Log;
2011-08-08 17:48:29 +00:00
2018-08-26 12:09:50 +00:00
public final class GeneralImageBuilder {
2011-08-08 17:48:29 +00:00
2019-08-26 17:07:21 +00:00
public static IEntityImage createEntityImageBlock(ILeaf leaf, ISkinParam skinParam,
boolean isHideEmptyDescriptionForState, PortionShower portionShower, Bibliotekon bibliotekon,
GraphvizVersion graphvizVersion, UmlDiagramType umlDiagramType, Collection<Link> links) {
2021-04-02 17:26:59 +00:00
final IEntityImage result = createEntityImageBlockInternal(leaf, skinParam, isHideEmptyDescriptionForState,
portionShower, bibliotekon, graphvizVersion, umlDiagramType, links);
// System.err.println("leaf " + leaf + " " + result.getClass());
return result;
}
private static IEntityImage createEntityImageBlockInternal(ILeaf leaf, ISkinParam skinParam,
boolean isHideEmptyDescriptionForState, PortionShower portionShower, Bibliotekon bibliotekon,
GraphvizVersion graphvizVersion, UmlDiagramType umlDiagramType, Collection<Link> links) {
2022-05-21 09:41:00 +00:00
if (leaf.isRemoved())
2019-08-26 17:07:21 +00:00
throw new IllegalStateException();
2022-05-21 09:41:00 +00:00
2019-08-26 17:07:21 +00:00
if (leaf.getLeafType().isLikeClass()) {
2022-08-26 16:00:28 +00:00
final EntityImageClass entityImageClass = new EntityImageClass((ILeaf) leaf, skinParam, portionShower);
2019-08-26 17:07:21 +00:00
final Neighborhood neighborhood = leaf.getNeighborhood();
2022-05-21 09:41:00 +00:00
if (neighborhood != null)
2019-08-26 17:07:21 +00:00
return new EntityImageProtected(entityImageClass, 20, neighborhood, bibliotekon);
2022-05-21 09:41:00 +00:00
2019-08-26 17:07:21 +00:00
return entityImageClass;
}
2022-05-21 09:41:00 +00:00
if (leaf.getLeafType() == LeafType.NOTE)
2021-09-19 17:05:24 +00:00
return new EntityImageNote(leaf, skinParam, umlDiagramType);
2022-05-21 09:41:00 +00:00
if (leaf.getLeafType() == LeafType.ACTIVITY)
2019-08-26 17:07:21 +00:00
return new EntityImageActivity(leaf, skinParam, bibliotekon);
2022-05-21 09:41:00 +00:00
2022-09-15 17:24:26 +00:00
if (/* (leaf.getLeafType() == LeafType.PORT) || */leaf.getLeafType() == LeafType.PORTIN
2022-09-01 17:40:58 +00:00
|| leaf.getLeafType() == LeafType.PORTOUT) {
final Cluster parent = bibliotekon.getCluster(leaf.getParentContainer());
2022-02-10 18:16:18 +00:00
return new EntityImagePort(leaf, skinParam, parent, bibliotekon, umlDiagramType.getStyleName());
}
2022-05-21 09:41:00 +00:00
2019-08-26 17:07:21 +00:00
if (leaf.getLeafType() == LeafType.STATE) {
if (leaf.getEntityPosition() != EntityPosition.NORMAL) {
final Cluster stateParent = bibliotekon.getCluster(leaf.getParentContainer());
2022-02-10 18:16:18 +00:00
return new EntityImageStateBorder(leaf, skinParam, stateParent, bibliotekon,
umlDiagramType.getStyleName());
2019-08-26 17:07:21 +00:00
}
2022-05-21 09:41:00 +00:00
if (isHideEmptyDescriptionForState && leaf.getBodier().getRawBody().size() == 0)
2019-08-26 17:07:21 +00:00
return new EntityImageStateEmptyDescription(leaf, skinParam);
2022-05-21 09:41:00 +00:00
2019-08-26 17:07:21 +00:00
if (leaf.getStereotype() != null
2022-05-21 09:41:00 +00:00
&& "<<sdlreceive>>".equals(leaf.getStereotype().getLabel(Guillemet.DOUBLE_COMPARATOR)))
2022-02-12 17:27:51 +00:00
return new EntityImageState2(leaf, skinParam, umlDiagramType.getStyleName());
2022-05-21 09:41:00 +00:00
2019-08-26 17:07:21 +00:00
return new EntityImageState(leaf, skinParam);
}
2022-05-21 09:41:00 +00:00
if (leaf.getLeafType() == LeafType.CIRCLE_START)
return new EntityImageCircleStart(leaf, skinParam);
if (leaf.getLeafType() == LeafType.CIRCLE_END)
return new EntityImageCircleEnd(leaf, skinParam);
if (leaf.getLeafType() == LeafType.BRANCH || leaf.getLeafType() == LeafType.STATE_CHOICE)
2019-08-26 17:07:21 +00:00
return new EntityImageBranch(leaf, skinParam);
2022-05-21 09:41:00 +00:00
if (leaf.getLeafType() == LeafType.LOLLIPOP_FULL || leaf.getLeafType() == LeafType.LOLLIPOP_HALF)
2022-02-10 18:16:18 +00:00
return new EntityImageLollipopInterface(leaf, skinParam, umlDiagramType.getStyleName());
2022-05-21 09:41:00 +00:00
if (leaf.getLeafType() == LeafType.CIRCLE)
2020-06-14 20:35:42 +00:00
return new EntityImageDescription(leaf, skinParam, portionShower, links, umlDiagramType.getStyleName(),
2021-03-07 12:23:24 +00:00
bibliotekon);
2019-08-26 17:07:21 +00:00
if (leaf.getLeafType() == LeafType.DESCRIPTION) {
if (OptionFlags.USE_INTERFACE_EYE1 && leaf.getUSymbol() instanceof USymbolInterface) {
return new EntityImageLollipopInterfaceEye1(leaf, skinParam, bibliotekon);
} else if (OptionFlags.USE_INTERFACE_EYE2 && leaf.getUSymbol() instanceof USymbolInterface) {
return new EntityImageLollipopInterfaceEye2(leaf, skinParam, portionShower);
} else {
2020-06-14 20:35:42 +00:00
return new EntityImageDescription(leaf, skinParam, portionShower, links, umlDiagramType.getStyleName(),
2021-03-07 12:23:24 +00:00
bibliotekon);
2019-08-26 17:07:21 +00:00
}
}
2022-05-21 09:41:00 +00:00
if (leaf.getLeafType() == LeafType.USECASE)
2019-08-26 17:07:21 +00:00
return new EntityImageUseCase(leaf, skinParam, portionShower);
2022-05-21 09:41:00 +00:00
if (leaf.getLeafType() == LeafType.USECASE_BUSINESS)
2020-10-12 20:56:58 +00:00
return new EntityImageUseCase(leaf, skinParam, portionShower);
2022-05-21 09:41:00 +00:00
2019-08-26 17:07:21 +00:00
// if (leaf.getEntityType() == LeafType.CIRCLE_INTERFACE) {
// return new EntityImageCircleInterface(leaf, skinParam);
// }
2022-05-21 09:41:00 +00:00
if (leaf.getLeafType() == LeafType.OBJECT)
2019-08-26 17:07:21 +00:00
return new EntityImageObject(leaf, skinParam, portionShower);
2022-05-21 09:41:00 +00:00
if (leaf.getLeafType() == LeafType.MAP)
2020-04-05 15:13:04 +00:00
return new EntityImageMap(leaf, skinParam, portionShower);
2022-05-21 09:41:00 +00:00
if (leaf.getLeafType() == LeafType.JSON)
2022-03-01 18:11:51 +00:00
return new EntityImageJson(leaf, skinParam, portionShower);
2022-05-21 09:41:00 +00:00
if (leaf.getLeafType() == LeafType.SYNCHRO_BAR || leaf.getLeafType() == LeafType.STATE_FORK_JOIN)
2021-11-21 11:09:15 +00:00
return new EntityImageSynchroBar(leaf, skinParam, umlDiagramType.getStyleName());
2022-05-21 09:41:00 +00:00
if (leaf.getLeafType() == LeafType.ARC_CIRCLE)
2019-08-26 17:07:21 +00:00
return new EntityImageArcCircle(leaf, skinParam);
2022-05-21 09:41:00 +00:00
if (leaf.getLeafType() == LeafType.POINT_FOR_ASSOCIATION)
2019-08-26 17:07:21 +00:00
return new EntityImageAssociationPoint(leaf, skinParam);
2022-05-21 09:41:00 +00:00
if (leaf.isGroup())
2019-08-26 17:07:21 +00:00
return new EntityImageGroup(leaf, skinParam);
2022-05-21 09:41:00 +00:00
2019-08-26 17:07:21 +00:00
if (leaf.getLeafType() == LeafType.EMPTY_PACKAGE) {
2022-05-21 09:41:00 +00:00
if (leaf.getUSymbol() != null)
return new EntityImageDescription(leaf, skinParam, portionShower, links, umlDiagramType.getStyleName(),
bibliotekon);
return new EntityImageEmptyPackage(leaf, skinParam, portionShower, umlDiagramType.getStyleName());
2019-08-26 17:07:21 +00:00
}
2022-05-21 09:41:00 +00:00
if (leaf.getLeafType() == LeafType.ASSOCIATION)
2022-02-12 17:27:51 +00:00
return new EntityImageAssociation(leaf, skinParam, umlDiagramType.getStyleName());
2022-05-21 09:41:00 +00:00
if (leaf.getLeafType() == LeafType.PSEUDO_STATE)
2022-02-12 17:27:51 +00:00
return new EntityImagePseudoState(leaf, skinParam, umlDiagramType.getStyleName());
2022-05-21 09:41:00 +00:00
if (leaf.getLeafType() == LeafType.DEEP_HISTORY)
2022-02-12 17:27:51 +00:00
return new EntityImageDeepHistory(leaf, skinParam, umlDiagramType.getStyleName());
2020-05-30 15:20:23 +00:00
2022-05-21 09:41:00 +00:00
if (leaf.getLeafType() == LeafType.TIPS)
2021-09-19 17:05:24 +00:00
return new EntityImageTips(leaf, skinParam, bibliotekon, umlDiagramType);
2022-05-21 09:41:00 +00:00
2019-08-26 17:07:21 +00:00
// TODO Clean
if (leaf.getLeafType() == LeafType.DOMAIN && leaf.getStereotype() != null
2022-05-21 09:41:00 +00:00
&& leaf.getStereotype().isMachineOrSpecification())
2019-08-26 17:07:21 +00:00
return new EntityImageMachine(leaf, skinParam);
2022-05-21 09:41:00 +00:00
else if (leaf.getLeafType() == LeafType.DOMAIN && leaf.getStereotype() != null
&& leaf.getStereotype().isDesignedOrSolved())
2019-08-26 17:07:21 +00:00
return new EntityImageDesignedDomain(leaf, skinParam);
2022-05-21 09:41:00 +00:00
else if (leaf.getLeafType() == LeafType.REQUIREMENT)
2019-08-26 17:07:21 +00:00
return new EntityImageRequirement(leaf, skinParam);
2022-05-21 09:41:00 +00:00
else if (leaf.getLeafType() == LeafType.DOMAIN && leaf.getStereotype() != null
&& leaf.getStereotype().isLexicalOrGiven())
2019-08-26 17:07:21 +00:00
return new EntityImageDomain(leaf, skinParam, 'X');
2022-05-21 09:41:00 +00:00
else if (leaf.getLeafType() == LeafType.DOMAIN && leaf.getStereotype() != null
&& leaf.getStereotype().isCausal())
2019-08-26 17:07:21 +00:00
return new EntityImageDomain(leaf, skinParam, 'C');
2022-05-21 09:41:00 +00:00
else if (leaf.getLeafType() == LeafType.DOMAIN && leaf.getStereotype() != null
&& leaf.getStereotype().isBiddableOrUncertain())
2019-08-26 17:07:21 +00:00
return new EntityImageDomain(leaf, skinParam, 'B');
2022-05-21 09:41:00 +00:00
else if (leaf.getLeafType() == LeafType.DOMAIN)
2019-08-26 17:07:21 +00:00
return new EntityImageDomain(leaf, skinParam, 'P');
2022-05-21 09:41:00 +00:00
else
2019-08-26 17:07:21 +00:00
throw new UnsupportedOperationException(leaf.getLeafType().toString());
}
2020-06-14 20:35:42 +00:00
public static UStroke getForcedStroke(Stereotype stereotype, ISkinParam skinParam) {
UStroke stroke = skinParam.getThickness(LineParam.packageBorder, stereotype);
2022-03-07 19:33:46 +00:00
if (stroke == null)
2020-06-14 20:35:42 +00:00
stroke = new UStroke(1.5);
2022-03-07 19:33:46 +00:00
2020-06-14 20:35:42 +00:00
return stroke;
}
2011-08-08 17:48:29 +00:00
private final DotData dotData;
2013-12-10 19:36:50 +00:00
private final EntityFactory entityFactory;
private final UmlSource source;
private final Pragma pragma;
2019-09-22 17:20:16 +00:00
private final boolean strictUmlStyle;
2019-12-10 21:45:49 +00:00
private Map<String, Double> maxX;
2011-08-08 17:48:29 +00:00
2016-08-25 20:45:37 +00:00
private final StringBounder stringBounder;
2020-02-18 21:24:31 +00:00
private final boolean mergeIntricated;
private final SName styleName;
2011-08-08 17:48:29 +00:00
2020-02-18 21:24:31 +00:00
public GeneralImageBuilder(boolean mergeIntricated, DotData dotData, EntityFactory entityFactory, UmlSource source,
Pragma pragma, StringBounder stringBounder, SName styleName) {
2011-08-08 17:48:29 +00:00
this.dotData = dotData;
this.styleName = styleName;
2013-12-10 19:36:50 +00:00
this.entityFactory = entityFactory;
this.source = source;
this.pragma = pragma;
2016-08-25 20:45:37 +00:00
this.stringBounder = stringBounder;
2019-09-22 17:20:16 +00:00
this.strictUmlStyle = dotData.getSkinParam().strictUmlStyle();
2020-02-18 21:24:31 +00:00
this.mergeIntricated = mergeIntricated;
2011-08-08 17:48:29 +00:00
}
2021-03-07 12:23:24 +00:00
final public StyleSignature getDefaultStyleDefinitionArrow(Stereotype stereotype) {
2022-03-01 18:11:51 +00:00
StyleSignature result = StyleSignatureBasic.of(SName.root, SName.element, styleName, SName.arrow);
2022-03-07 19:33:46 +00:00
if (stereotype != null)
2022-03-01 18:11:51 +00:00
result = result.withTOBECHANGED(stereotype);
2022-03-07 19:33:46 +00:00
2021-03-07 12:23:24 +00:00
return result;
2019-08-26 17:07:21 +00:00
}
2019-09-22 17:20:16 +00:00
private boolean isOpalisable(IEntity entity) {
2022-03-07 19:33:46 +00:00
if (strictUmlStyle)
2019-09-22 17:20:16 +00:00
return false;
2022-03-07 19:33:46 +00:00
2023-01-09 19:13:37 +00:00
if (entity.isGroup())
return false;
if (entity.getLeafType() != LeafType.NOTE)
return false;
final Link single = onlyOneLink(entity);
if (single == null)
return false;
return single.getOther(entity).getLeafType() != LeafType.NOTE;
2019-09-22 17:20:16 +00:00
}
static class EntityImageSimpleEmpty implements IEntityImage {
private final HColor backColor;
EntityImageSimpleEmpty(HColor backColor) {
this.backColor = backColor;
}
2019-09-22 17:20:16 +00:00
public boolean isHidden() {
return false;
}
2020-03-18 10:50:02 +00:00
public HColor getBackcolor() {
return backColor;
2019-09-22 17:20:16 +00:00
}
2022-09-12 20:08:34 +00:00
public XDimension2D calculateDimension(StringBounder stringBounder) {
return new XDimension2D(10, 10);
2019-09-22 17:20:16 +00:00
}
public MinMax getMinMax(StringBounder stringBounder) {
return MinMax.fromDim(calculateDimension(stringBounder));
}
2022-09-12 20:08:34 +00:00
public XRectangle2D getInnerPosition(String member, StringBounder stringBounder, InnerStrategy strategy) {
2019-09-22 17:20:16 +00:00
return null;
}
public void drawU(UGraphic ug) {
}
public ShapeType getShapeType() {
return ShapeType.RECTANGLE;
}
public Margins getShield(StringBounder stringBounder) {
return Margins.NONE;
}
public double getOverscanX(StringBounder stringBounder) {
return 0;
}
}
2020-06-07 10:03:18 +00:00
// Duplicate SvekResult / GeneralImageBuilder
private HColor getBackcolor() {
2022-05-21 09:41:00 +00:00
final Style style = StyleSignatureBasic.of(SName.root, SName.document)
.getMergedStyle(dotData.getSkinParam().getCurrentStyleBuilder());
2022-09-18 17:08:06 +00:00
return style.value(PName.BackGroundColor).asColor(dotData.getSkinParam().getIHtmlColorSet());
2020-06-07 10:03:18 +00:00
}
2020-06-14 20:35:42 +00:00
2016-07-25 19:25:28 +00:00
public IEntityImage buildImage(BaseFile basefile, String dotStrings[]) {
2022-03-07 19:33:46 +00:00
if (dotData.isDegeneratedWithFewEntities(0))
return new EntityImageSimpleEmpty(dotData.getSkinParam().getBackgroundColor());
2022-03-07 19:33:46 +00:00
2019-09-22 17:20:16 +00:00
if (dotData.isDegeneratedWithFewEntities(1) && dotData.getUmlDiagramType() != UmlDiagramType.STATE) {
final ILeaf single = dotData.getLeafs().iterator().next();
final IGroup group = single.getParentContainer();
2021-02-02 10:12:15 +00:00
if (group instanceof GroupRoot && single.getUSymbol() instanceof USymbolHexagon == false) {
2020-06-07 10:03:18 +00:00
final IEntityImage tmp = GeneralImageBuilder.createEntityImageBlock(single, dotData.getSkinParam(),
2019-09-22 17:20:16 +00:00
dotData.isHideEmptyDescriptionForState(), dotData, null, null, dotData.getUmlDiagramType(),
2020-06-07 10:03:18 +00:00
dotData.getLinks());
return new EntityImageDegenerated(tmp, getBackcolor());
2019-09-22 17:20:16 +00:00
}
}
2015-04-07 18:18:37 +00:00
dotData.removeIrrelevantSametail();
2016-07-25 19:25:28 +00:00
final DotStringFactory dotStringFactory = new DotStringFactory(stringBounder, dotData);
2011-08-08 17:48:29 +00:00
2016-07-25 19:25:28 +00:00
printGroups(dotStringFactory, dotData.getRootGroup());
printEntities(dotStringFactory, getUnpackagedEntities());
2011-08-08 17:48:29 +00:00
for (Link link : dotData.getLinks()) {
2022-03-07 19:33:46 +00:00
if (link.isRemoved())
2013-12-10 19:36:50 +00:00
continue;
2022-03-07 19:33:46 +00:00
2013-12-10 19:36:50 +00:00
try {
final ISkinParam skinParam = dotData.getSkinParam();
2021-04-20 20:19:49 +00:00
final FontConfiguration labelFont = getFontForLink(link, skinParam);
2013-12-10 19:36:50 +00:00
2021-04-20 20:19:49 +00:00
final SvekLine line = new SvekLine(link, dotStringFactory.getColorSequence(), skinParam, stringBounder,
2022-08-26 16:00:28 +00:00
labelFont, dotStringFactory.getBibliotekon(), pragma, dotStringFactory.getGraphvizVersion());
2013-12-10 19:36:50 +00:00
2016-07-25 19:25:28 +00:00
dotStringFactory.getBibliotekon().addLine(line);
2013-12-10 19:36:50 +00:00
2019-09-22 17:20:16 +00:00
if (isOpalisable(link.getEntity1())) {
2021-02-02 10:12:15 +00:00
final SvekNode node = dotStringFactory.getBibliotekon().getNode(link.getEntity1());
final SvekNode other = dotStringFactory.getBibliotekon().getNode(link.getEntity2());
2016-01-09 12:15:40 +00:00
if (other != null) {
2020-02-18 21:24:31 +00:00
((EntityImageNote) node.getImage()).setOpaleLine(line, node, other);
2016-01-09 12:15:40 +00:00
line.setOpale(true);
}
2019-09-22 17:20:16 +00:00
} else if (isOpalisable(link.getEntity2())) {
2021-02-02 10:12:15 +00:00
final SvekNode node = dotStringFactory.getBibliotekon().getNode(link.getEntity2());
final SvekNode other = dotStringFactory.getBibliotekon().getNode(link.getEntity1());
2016-01-09 12:15:40 +00:00
if (other != null) {
2020-02-18 21:24:31 +00:00
((EntityImageNote) node.getImage()).setOpaleLine(line, node, other);
2016-01-09 12:15:40 +00:00
line.setOpale(true);
}
2013-12-10 19:36:50 +00:00
}
} catch (IllegalStateException e) {
2022-08-17 17:34:24 +00:00
Logme.error(e);
2011-09-08 10:42:27 +00:00
}
2011-08-08 17:48:29 +00:00
}
2022-03-07 19:33:46 +00:00
if (dotStringFactory.illegalDotExe())
2011-08-08 17:48:29 +00:00
return error(dotStringFactory.getDotExe());
if (basefile == null && isSvekTrace()
&& (SecurityUtils.getSecurityProfile() == SecurityProfile.UNSECURE
|| SecurityUtils.getSecurityProfile() == SecurityProfile.LEGACY
|| SecurityUtils.getSecurityProfile() == SecurityProfile.SANDBOX))
2022-03-19 12:48:23 +00:00
basefile = new BaseFile(null);
2019-09-22 17:20:16 +00:00
2015-04-07 18:18:37 +00:00
final String svg;
try {
2016-05-11 21:31:47 +00:00
svg = dotStringFactory.getSvg(basefile, dotStrings);
2015-04-07 18:18:37 +00:00
} catch (IOException e) {
2020-12-14 18:31:06 +00:00
return new GraphvizCrash(source.getPlainString(), GraphvizUtils.graphviz244onWindows(), e);
2015-04-07 18:18:37 +00:00
}
2022-03-07 19:33:46 +00:00
if (svg.length() == 0)
2020-12-14 18:31:06 +00:00
return new GraphvizCrash(source.getPlainString(), GraphvizUtils.graphviz244onWindows(),
new EmptySvgException());
2022-03-07 19:33:46 +00:00
2013-12-10 19:36:50 +00:00
final String graphvizVersion = extractGraphvizVersion(svg);
try {
2020-06-07 10:03:18 +00:00
dotStringFactory.solve(mergeIntricated, dotData.getEntityFactory(), svg);
final SvekResult result = new SvekResult(dotData, dotStringFactory);
2016-07-25 19:25:28 +00:00
this.maxX = dotStringFactory.getBibliotekon().getMaxX();
2013-12-10 19:36:50 +00:00
return result;
} catch (Exception e) {
Log.error("Exception " + e);
throw new UnparsableGraphvizException(e, graphvizVersion, svg, source.getPlainString());
}
}
2011-09-08 10:42:27 +00:00
2021-04-20 20:19:49 +00:00
private FontConfiguration getFontForLink(Link link, final ISkinParam skinParam) {
2022-05-21 09:41:00 +00:00
final Style style = getDefaultStyleDefinitionArrow(link.getStereotype()).getMergedStyle(link.getStyleBuilder());
2022-09-18 17:08:06 +00:00
return style.getFontConfiguration(skinParam.getIHtmlColorSet());
2021-04-20 20:19:49 +00:00
}
2013-12-10 19:36:50 +00:00
private boolean isSvekTrace() {
final String value = pragma.getValue("svek_trace");
return "true".equalsIgnoreCase(value) || "on".equalsIgnoreCase(value);
}
private String extractGraphvizVersion(String svg) {
final Pattern pGraph = Pattern.compile("(?mi)!-- generated by graphviz(.*)");
final Matcher mGraph = pGraph.matcher(svg);
2022-03-07 19:33:46 +00:00
if (mGraph.find())
2015-05-31 18:56:03 +00:00
return StringUtils.trin(mGraph.group(1));
2022-03-07 19:33:46 +00:00
2013-12-10 19:36:50 +00:00
return null;
2011-09-08 10:42:27 +00:00
}
2011-08-08 17:48:29 +00:00
2023-01-09 19:13:37 +00:00
private Link onlyOneLink(IEntity ent) {
Link single = null;
2013-12-10 19:36:50 +00:00
for (Link link : dotData.getLinks()) {
2022-03-07 19:33:46 +00:00
if (link.isInvis())
2013-12-10 19:36:50 +00:00
continue;
2023-01-09 19:13:37 +00:00
if (link.contains(ent) == false)
continue;
2022-03-07 19:33:46 +00:00
2023-01-09 19:13:37 +00:00
if (single != null)
return null;
single = link;
2013-12-10 19:36:50 +00:00
}
2023-01-09 19:13:37 +00:00
return single;
2011-08-08 17:48:29 +00:00
}
private IEntityImage error(File dotExe) {
2021-05-14 08:42:57 +00:00
final List<String> msg = new ArrayList<>();
2011-08-08 17:48:29 +00:00
msg.add("Dot Executable: " + dotExe);
2016-07-25 19:25:28 +00:00
final ExeState exeState = ExeState.checkFile(dotExe);
msg.add(exeState.getTextMessage());
2011-08-08 17:48:29 +00:00
msg.add("Cannot find Graphviz. You should try");
msg.add(" ");
msg.add("@startuml");
msg.add("testdot");
msg.add("@enduml");
msg.add(" ");
msg.add(" or ");
msg.add(" ");
msg.add("java -jar plantuml.jar -testdot");
2013-12-10 19:36:50 +00:00
msg.add(" ");
2016-11-18 21:12:09 +00:00
return GraphicStrings.createForError(msg, false);
2011-08-08 17:48:29 +00:00
}
2016-07-25 19:25:28 +00:00
private void printEntities(DotStringFactory dotStringFactory, Collection<ILeaf> entities2) {
2013-12-10 19:36:50 +00:00
for (ILeaf ent : entities2) {
2022-03-07 19:33:46 +00:00
if (ent.isRemoved())
2013-12-10 19:36:50 +00:00
continue;
2022-03-07 19:33:46 +00:00
2016-07-25 19:25:28 +00:00
printEntity(dotStringFactory, ent);
2011-08-08 17:48:29 +00:00
}
}
2016-07-25 19:25:28 +00:00
private void printEntity(DotStringFactory dotStringFactory, ILeaf ent) {
2022-03-07 19:33:46 +00:00
if (ent.isRemoved())
2013-12-10 19:36:50 +00:00
throw new IllegalStateException();
2022-03-07 19:33:46 +00:00
2016-07-25 19:25:28 +00:00
final IEntityImage image = printEntityInternal(dotStringFactory, ent);
2021-03-07 12:23:24 +00:00
final SvekNode node = dotStringFactory.getBibliotekon().createNode(ent, image,
dotStringFactory.getColorSequence(), stringBounder);
2020-02-18 21:24:31 +00:00
dotStringFactory.addNode(node);
2013-12-10 19:36:50 +00:00
}
2016-07-25 19:25:28 +00:00
private IEntityImage printEntityInternal(DotStringFactory dotStringFactory, ILeaf ent) {
2022-03-07 19:33:46 +00:00
if (ent.isRemoved())
2013-12-10 19:36:50 +00:00
throw new IllegalStateException();
2022-03-07 19:33:46 +00:00
2013-12-10 19:36:50 +00:00
if (ent.getSvekImage() == null) {
ISkinParam skinParam = dotData.getSkinParam();
2016-03-06 16:47:34 +00:00
if (skinParam.sameClassWidth()) {
2022-08-24 16:46:33 +00:00
final double width = getMaxWidth();
2022-10-18 20:57:44 +00:00
((SkinParam) skinParam).setParamSameClassWidth(width);
2013-12-10 19:36:50 +00:00
}
return createEntityImageBlock(ent, skinParam, dotData.isHideEmptyDescriptionForState(), dotData,
2022-08-26 16:00:28 +00:00
dotStringFactory.getBibliotekon(), dotStringFactory.getGraphvizVersion(),
dotData.getUmlDiagramType(), dotData.getLinks());
2013-12-10 19:36:50 +00:00
}
return ent.getSvekImage();
}
2022-08-24 16:46:33 +00:00
private double getMaxWidth() {
2013-12-10 19:36:50 +00:00
double result = 0;
for (ILeaf ent : dotData.getLeafs()) {
2022-03-07 19:33:46 +00:00
if (ent.getLeafType().isLikeClass() == false)
2013-12-10 19:36:50 +00:00
continue;
2022-03-07 19:33:46 +00:00
2022-08-26 16:00:28 +00:00
final IEntityImage im = new EntityImageClass(ent, dotData.getSkinParam(), dotData);
2013-12-10 19:36:50 +00:00
final double w = im.calculateDimension(stringBounder).getWidth();
2022-03-07 19:33:46 +00:00
if (w > result)
2013-12-10 19:36:50 +00:00
result = w;
2022-03-07 19:33:46 +00:00
2013-12-10 19:36:50 +00:00
}
return result;
2011-08-08 17:48:29 +00:00
}
2013-12-10 19:36:50 +00:00
private Collection<ILeaf> getUnpackagedEntities() {
2021-05-14 08:42:57 +00:00
final List<ILeaf> result = new ArrayList<>();
2022-03-07 19:33:46 +00:00
for (ILeaf ent : dotData.getLeafs())
if (dotData.getTopParent() == ent.getParentContainer())
2011-08-08 17:48:29 +00:00
result.add(ent);
2022-03-07 19:33:46 +00:00
2011-08-08 17:48:29 +00:00
return result;
}
2016-07-25 19:25:28 +00:00
private void printGroups(DotStringFactory dotStringFactory, IGroup parent) {
2020-02-18 21:24:31 +00:00
final Collection<IGroup> groups = dotData.getGroupHierarchy().getChildrenGroups(parent);
for (IGroup g : groups) {
2022-03-07 19:33:46 +00:00
if (g.isRemoved())
2013-12-10 19:36:50 +00:00
continue;
2022-03-07 19:33:46 +00:00
2023-01-09 19:13:37 +00:00
if (dotData.isEmpty(g)
&& (g.getGroupType() == GroupType.PACKAGE || g.getGroupType() == GroupType.TOGETHER)) {
2020-02-18 21:24:31 +00:00
final ISkinParam skinParam = dotData.getSkinParam();
final ILeaf folder = entityFactory.createLeafForEmptyGroup(g, skinParam);
2016-07-25 19:25:28 +00:00
printEntity(dotStringFactory, folder);
2011-08-08 17:48:29 +00:00
} else {
2016-07-25 19:25:28 +00:00
printGroup(dotStringFactory, g);
2011-08-08 17:48:29 +00:00
}
}
}
2016-07-25 19:25:28 +00:00
private void printGroup(DotStringFactory dotStringFactory, IGroup g) {
2022-03-07 19:33:46 +00:00
if (g.getGroupType() == GroupType.CONCURRENT_STATE)
2011-08-08 17:48:29 +00:00
return;
2022-03-07 19:33:46 +00:00
2020-02-18 21:24:31 +00:00
if (mergeIntricated) {
final IGroup intricated = dotData.getEntityFactory().isIntricated(g);
if (intricated != null) {
printGroup(dotStringFactory, intricated);
return;
}
}
2013-12-10 19:36:50 +00:00
2022-11-04 17:36:03 +00:00
final ClusterHeader clusterHeader = new ClusterHeader((EntityImp) g, dotData.getSkinParam(), dotData,
2022-09-15 17:24:26 +00:00
stringBounder);
dotStringFactory.openCluster(g, clusterHeader);
2016-07-25 19:25:28 +00:00
this.printEntities(dotStringFactory, g.getLeafsDirect());
2013-12-10 19:36:50 +00:00
2016-07-25 19:25:28 +00:00
printGroups(dotStringFactory, g);
2011-08-08 17:48:29 +00:00
dotStringFactory.closeCluster();
}
2016-07-25 19:25:28 +00:00
public String getWarningOrError(int warningOrError) {
2022-03-07 19:33:46 +00:00
if (maxX == null)
2016-07-25 19:25:28 +00:00
return "";
2022-03-07 19:33:46 +00:00
2016-07-25 19:25:28 +00:00
final StringBuilder sb = new StringBuilder();
2022-03-07 19:33:46 +00:00
for (Map.Entry<String, Double> ent : maxX.entrySet())
2016-07-25 19:25:28 +00:00
if (ent.getValue() > warningOrError) {
sb.append(ent.getKey() + " is overpassing the width limit.");
sb.append("\n");
}
2022-03-07 19:33:46 +00:00
2016-07-25 19:25:28 +00:00
return sb.length() == 0 ? "" : sb.toString();
}
2011-08-08 17:48:29 +00:00
}