1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-05-31 23:50:49 +00:00
plantuml/src/net/sourceforge/plantuml/baraye/CucaDiagram.java

754 lines
21 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2022-03-07 19:33:46 +00:00
* (C) Copyright 2009-2023, Arnaud Roques
2010-11-15 20:35:36 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
2010-11-15 20:35:36 +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
*
2010-11-15 20:35:36 +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
2010-11-15 20:35:36 +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
*
*
*/
2022-11-07 19:27:11 +00:00
package net.sourceforge.plantuml.baraye;
2010-11-15 20:35:36 +00:00
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
2011-03-20 21:40:07 +00:00
import java.util.HashSet;
2010-11-15 20:35:36 +00:00
import java.util.List;
2022-09-20 20:35:41 +00:00
import java.util.Map;
2021-05-09 21:14:40 +00:00
import java.util.Objects;
2010-11-15 20:35:36 +00:00
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
2010-11-15 20:35:36 +00:00
2017-06-05 11:27:21 +00:00
import net.sourceforge.plantuml.BackSlash;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.FileFormat;
2011-01-05 18:23:06 +00:00
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.StringUtils;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.UmlDiagram;
import net.sourceforge.plantuml.UmlDiagramType;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.api.ImageDataSimple;
2020-02-18 21:24:31 +00:00
import net.sourceforge.plantuml.command.CommandExecutionResult;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.core.ImageData;
2021-05-23 15:35:13 +00:00
import net.sourceforge.plantuml.core.UmlSource;
2022-11-04 17:36:03 +00:00
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.cucadiagram.EntityGender;
import net.sourceforge.plantuml.cucadiagram.EntityPortion;
import net.sourceforge.plantuml.cucadiagram.EntityPosition;
import net.sourceforge.plantuml.cucadiagram.GroupHierarchy;
import net.sourceforge.plantuml.cucadiagram.GroupType;
import net.sourceforge.plantuml.cucadiagram.HideOrShow2;
import net.sourceforge.plantuml.cucadiagram.ICucaDiagram;
import net.sourceforge.plantuml.cucadiagram.LeafType;
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.LinkConstraint;
import net.sourceforge.plantuml.cucadiagram.Magma;
import net.sourceforge.plantuml.cucadiagram.MagmaList;
import net.sourceforge.plantuml.cucadiagram.PortionShower;
2023-01-11 21:47:15 +00:00
import net.sourceforge.plantuml.cucadiagram.Together;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.cucadiagram.dot.CucaDiagramTxtMaker;
import net.sourceforge.plantuml.elk.CucaDiagramFileMakerElk;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.graphic.USymbol;
import net.sourceforge.plantuml.graphml.CucaDiagramGraphmlMaker;
2020-12-21 19:05:24 +00:00
import net.sourceforge.plantuml.sdot.CucaDiagramFileMakerSmetana;
2020-05-30 15:20:23 +00:00
import net.sourceforge.plantuml.security.SecurityUtils;
2011-03-20 21:40:07 +00:00
import net.sourceforge.plantuml.skin.VisibilityModifier;
2016-04-22 20:36:08 +00:00
import net.sourceforge.plantuml.statediagram.StateDiagram;
import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.svek.CucaDiagramFileMaker;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.svek.CucaDiagramFileMakerSvek;
2011-01-05 18:23:06 +00:00
import net.sourceforge.plantuml.xmi.CucaDiagramXmiMaker;
2016-04-22 20:36:08 +00:00
import net.sourceforge.plantuml.xmlsc.StateDiagramScxmlMaker;
2010-11-15 20:35:36 +00:00
2022-11-04 17:36:03 +00:00
public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy, PortionShower, ICucaDiagram {
2010-11-15 20:35:36 +00:00
2020-02-18 21:24:31 +00:00
private String namespaceSeparator = null;
private boolean namespaceSeparatorHasBeenSet = false;
public final boolean mergeIntricated() {
return false;
2022-11-15 23:15:21 +00:00
}
2021-05-14 08:42:57 +00:00
private final List<HideOrShow2> hides2 = new ArrayList<>();
private final List<HideOrShow2> removed = new ArrayList<>();
2020-01-12 22:13:17 +00:00
protected final EntityFactory entityFactory = new EntityFactory(hides2, removed, this);
private List<Quark> stacks = new ArrayList<>();
2010-11-15 20:35:36 +00:00
private boolean visibilityModifierPresent;
// private NamespaceStrategy lastNamespaceStrategy;
2023-01-13 17:36:46 +00:00
private Together currentTogether;
2022-09-20 20:35:41 +00:00
public CucaDiagram(UmlSource source, UmlDiagramType type, Map<String, String> orig) {
2022-09-18 17:08:06 +00:00
super(source, type, orig);
this.stacks.add(entityFactory.getPlasma().root());
2019-12-10 21:45:49 +00:00
}
public String getPortFor(String entString, Quark ident) {
final int x = entString.lastIndexOf("::");
if (x == -1)
return null;
if (entString.startsWith(ident.getName()))
return entString.substring(x + 2);
2022-11-08 18:45:10 +00:00
return null;
}
public Quark currentQuark() {
return this.stacks.get(stacks.size() - 1);
}
public String cleanIdForQuark(String id) {
if (id == null)
return null;
return StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(id);
2019-06-26 19:24:49 +00:00
}
2017-11-20 16:10:36 +00:00
final public void setNamespaceSeparator(String namespaceSeparator) {
2020-02-18 21:24:31 +00:00
this.namespaceSeparatorHasBeenSet = true;
2017-11-20 16:10:36 +00:00
this.namespaceSeparator = namespaceSeparator;
getPlasma().setSeparator(namespaceSeparator);
2017-11-20 16:10:36 +00:00
}
final public String getNamespaceSeparator() {
2022-02-14 17:44:01 +00:00
if (namespaceSeparatorHasBeenSet == false)
2023-01-11 21:47:15 +00:00
return ".";
2022-02-14 17:44:01 +00:00
2017-11-20 16:10:36 +00:00
return namespaceSeparator;
2015-04-07 18:18:37 +00:00
}
2013-12-10 19:36:50 +00:00
@Override
2010-11-15 20:35:36 +00:00
public boolean hasUrl() {
for (Quark quark : getPlasma().quarks()) {
final EntityImp ent = (EntityImp) quark.getData();
if (ent != null && ent.hasUrl())
2010-11-15 20:35:36 +00:00
return true;
}
2022-02-14 17:44:01 +00:00
2010-11-15 20:35:36 +00:00
return false;
}
final public void setLastEntity(EntityImp foo) {
this.lastEntity = (EntityImp) foo;
2020-02-18 21:24:31 +00:00
}
protected void updateLasts(EntityImp result) {
}
2022-02-14 17:44:01 +00:00
final public EntityImp reallyCreateLeaf(Quark ident, Display display, LeafType type, USymbol symbol) {
Objects.requireNonNull(type);
if (ident.getData() != null)
throw new IllegalStateException();
if (Display.isNull(display))
throw new IllegalArgumentException();
2022-02-14 17:44:01 +00:00
final EntityImp result = entityFactory.createLeaf(ident, display, type, getHides());
result.setUSymbol(symbol);
ident.setData(result);
2013-12-10 19:36:50 +00:00
this.lastEntity = result;
result.setTogether(currentTogether);
updateLasts(result);
// if (type == LeafType.OBJECT)
// ((EntityImp) parent.getData()).muteToType2(type);
2010-11-15 20:35:36 +00:00
return result;
2010-11-15 20:35:36 +00:00
}
final public Quark quarkInContext(String full, boolean specialForCreateClass) {
final String sep = getNamespaceSeparator();
if (sep == null) {
final Quark result = getPlasma().getIfExistsFromName(full);
if (result != null)
return result;
return currentQuark().child(full);
2010-11-15 20:35:36 +00:00
}
final Quark currentQuark = currentQuark();
if (full.startsWith(sep))
return getPlasma().root().child(full.substring(sep.length()));
final int x = full.indexOf(sep);
if (x == -1) {
if (specialForCreateClass == false && getPlasma().countByName(full) == 1) {
final Quark byName = getPlasma().getIfExistsFromName(full);
assert byName != null;
if (byName != currentQuark)
return byName;
}
return currentQuark.child(full);
}
2022-02-14 17:44:01 +00:00
final String first = full.substring(0, x);
final boolean firstPackageDoesExist = getPlasma().root().childIfExists(first) != null;
2010-11-15 20:35:36 +00:00
if (firstPackageDoesExist)
return getPlasma().root().child(full);
return currentQuark.child(full);
2019-12-10 21:45:49 +00:00
2020-06-14 20:35:42 +00:00
}
public String removePortId(String id) {
// To be kept
if ("::".equals(namespaceSeparator))
return id;
final int x = id.lastIndexOf("::");
if (x == -1)
return id;
return id.substring(0, x);
2022-11-07 19:27:11 +00:00
}
public String getPortId(String id) {
// To be kept
if ("::".equals(namespaceSeparator))
return null;
final int x = id.lastIndexOf("::");
if (x == -1)
return null;
return id.substring(x + 2);
2020-01-12 22:13:17 +00:00
}
public /* protected */ Plasma getPlasma() {
return entityFactory.getPlasma();
2019-12-10 21:45:49 +00:00
}
final public Collection<EntityImp> getChildrenGroups(EntityImp parent) {
final Collection<EntityImp> result = new ArrayList<>();
2019-12-10 21:45:49 +00:00
final Quark parent__;
if (parent.instanceofGroupRoot())
parent__ = getPlasma().root();
else
parent__ = ((EntityImp) parent).getQuark();
2010-11-15 20:35:36 +00:00
for (EntityImp gg : getGroups(false))
if (gg.getQuark().getParent() == parent__)
2013-12-10 19:36:50 +00:00
result.add(gg);
2022-02-14 17:44:01 +00:00
2010-11-15 20:35:36 +00:00
return Collections.unmodifiableCollection(result);
}
2018-03-09 21:37:34 +00:00
private void eventuallyBuildPhantomGroups() {
for (Quark quark : getPlasma().quarks()) {
if (quark.getData() != null)
continue;
int countChildren = quark.countChildren();
if (countChildren > 0) {
final Display display = Display.getWithNewlines(quark.getQualifiedName());
final EntityImp result = entityFactory.createGroup(quark, display, GroupType.PACKAGE, getHides());
quark.setData(result);
}
}
}
2023-01-13 17:36:46 +00:00
final public CommandExecutionResult gotoTogether() {
2023-01-11 21:47:15 +00:00
if (currentTogether != null)
return CommandExecutionResult.error("Cannot nest together");
2020-01-12 22:13:17 +00:00
2023-01-13 17:36:46 +00:00
this.currentTogether = new Together();
2023-01-11 21:47:15 +00:00
return CommandExecutionResult.ok();
}
2023-01-09 19:13:37 +00:00
final public CommandExecutionResult gotoGroup(Quark ident, Display display, GroupType type) {
2023-01-13 17:36:46 +00:00
if (currentTogether != null)
return CommandExecutionResult.error("Cannot be done inside 'together'");
if (ident.getData() == null) {
final EntityImp result = entityFactory.createGroup(ident, display, type, getHides());
ident.setData(result);
2017-11-20 16:10:36 +00:00
}
final EntityImp ent = (EntityImp) ident.getData();
ent.setDisplay(display);
ent.muteToType2(type);
2019-08-26 17:07:21 +00:00
this.stacks.add(ident);
2020-01-12 22:13:17 +00:00
return CommandExecutionResult.ok();
2019-08-26 17:07:21 +00:00
}
2023-01-11 21:47:15 +00:00
public boolean endGroup() {
if (this.currentTogether != null) {
this.currentTogether = null;
return true;
2023-01-09 19:13:37 +00:00
}
if (stacks.size() > 0) {
stacks.remove(stacks.size() - 1);
return true;
2017-11-20 16:10:36 +00:00
}
2010-11-15 20:35:36 +00:00
return false;
2020-01-12 22:13:17 +00:00
}
public final EntityImp getCurrentGroup() {
return (EntityImp) currentQuark().getData();
2019-12-10 21:45:49 +00:00
}
public final EntityImp getGroup(String code) {
final Quark quark = getPlasma().getIfExistsFromName(code);
if (quark == null)
return null;
return (EntityImp) quark.getData();
2020-01-12 22:13:17 +00:00
}
public final boolean isGroup(String code) {
final Quark quark = getPlasma().getIfExistsFromName(code);
if (quark == null)
return false;
return isGroup(quark);
2010-11-15 20:35:36 +00:00
}
public final boolean isGroup(final Quark quark) {
final EntityImp ent = (EntityImp) quark.getData();
if (ent == null)
return false;
return ent.isGroup();
}
public final Collection<EntityImp> getGroups(boolean withRootGroup) {
final List<EntityImp> result = new ArrayList<>();
for (Quark quark : getPlasma().quarks()) {
if (quark.isRoot()) {
if (withRootGroup)
result.add((EntityImp) quark.getData());
} else {
final EntityImp data = (EntityImp) quark.getData();
if (data != null && data.isGroup())
result.add(data);
}
}
2013-12-10 19:36:50 +00:00
return Collections.unmodifiableCollection(result);
2010-11-15 20:35:36 +00:00
}
public EntityImp getRootGroup() {
return (EntityImp) getPlasma().root().getData();
2010-11-15 20:35:36 +00:00
}
public final Collection<EntityImp> getLeafsvalues() {
final List<EntityImp> result = new ArrayList<>();
for (Quark quark : getPlasma().quarks()) {
if (quark.isRoot())
continue;
final EntityImp data = (EntityImp) quark.getData();
if (data != null && data.isGroup() == false)
result.add(data);
}
return Collections.unmodifiableCollection(result);
2015-04-07 18:18:37 +00:00
}
public final int getLeafssize() {
2018-03-09 21:37:34 +00:00
return getLeafsvalues().size();
2015-04-07 18:18:37 +00:00
}
2010-11-15 20:35:36 +00:00
final public void addLink(Link link) {
2013-12-10 19:36:50 +00:00
entityFactory.addLink(link);
2010-11-15 20:35:36 +00:00
}
final protected void removeLink(Link link) {
2013-12-10 19:36:50 +00:00
entityFactory.removeLink(link);
2010-11-15 20:35:36 +00:00
}
final public List<Link> getLinks() {
2013-12-10 19:36:50 +00:00
return entityFactory.getLinks();
2010-11-15 20:35:36 +00:00
}
abstract protected List<String> getDotStrings();
2011-08-08 17:48:29 +00:00
final public String[] getDotStringSkek() {
2021-05-14 08:42:57 +00:00
final List<String> result = new ArrayList<>();
2022-02-14 17:44:01 +00:00
for (String s : getDotStrings())
if (s.startsWith("nodesep") || s.startsWith("ranksep") || s.startsWith("layout"))
2011-08-08 17:48:29 +00:00
result.add(s);
2022-02-14 17:44:01 +00:00
2020-12-14 18:31:06 +00:00
String aspect = getPragma().getValue("aspect");
2013-12-10 19:36:50 +00:00
if (aspect != null) {
2020-12-14 18:31:06 +00:00
aspect = aspect.replace(',', '.');
2013-12-10 19:36:50 +00:00
result.add("aspect=" + aspect + ";");
}
2017-04-05 17:37:42 +00:00
final String ratio = getPragma().getValue("ratio");
2022-02-14 17:44:01 +00:00
if (ratio != null)
2017-04-05 17:37:42 +00:00
result.add("ratio=" + ratio + ";");
2022-02-14 17:44:01 +00:00
2011-08-08 17:48:29 +00:00
return result.toArray(new String[result.size()]);
}
// ::comment when WASM
private void createFilesGraphml(OutputStream suggestedFile) throws IOException {
final CucaDiagramGraphmlMaker maker = new CucaDiagramGraphmlMaker(this);
maker.createFiles(suggestedFile);
}
2011-04-19 16:50:40 +00:00
private void createFilesXmi(OutputStream suggestedFile, FileFormat fileFormat) throws IOException {
final CucaDiagramXmiMaker maker = new CucaDiagramXmiMaker(this, fileFormat);
maker.createFiles(suggestedFile);
}
2011-03-20 21:40:07 +00:00
2016-04-22 20:36:08 +00:00
private void createFilesScxml(OutputStream suggestedFile) throws IOException {
final StateDiagramScxmlMaker maker = new StateDiagramScxmlMaker((StateDiagram) this);
maker.createFiles(suggestedFile);
}
private void createFilesTxt(OutputStream os, int index, FileFormat fileFormat) throws IOException {
final CucaDiagramTxtMaker maker = new CucaDiagramTxtMaker(this, fileFormat);
maker.createFiles(os, index);
}
// ::done
2011-04-19 16:50:40 +00:00
@Override
2015-04-07 18:18:37 +00:00
protected ImageData exportDiagramInternal(OutputStream os, int index, FileFormatOption fileFormatOption)
throws IOException {
2011-01-05 18:23:06 +00:00
final FileFormat fileFormat = fileFormatOption.getFileFormat();
2013-12-10 19:36:50 +00:00
// ::comment when WASM
2010-11-15 20:35:36 +00:00
if (fileFormat == FileFormat.ATXT || fileFormat == FileFormat.UTXT) {
2011-08-08 17:48:29 +00:00
try {
createFilesTxt(os, index, fileFormat);
} catch (Throwable t) {
2020-05-30 15:20:23 +00:00
t.printStackTrace(SecurityUtils.createPrintStream(os));
2011-08-08 17:48:29 +00:00
}
2018-05-01 17:26:04 +00:00
return ImageDataSimple.ok();
2010-11-15 20:35:36 +00:00
}
if (fileFormat == FileFormat.GRAPHML) {
createFilesGraphml(os);
return ImageDataSimple.ok();
}
2011-04-19 16:50:40 +00:00
if (fileFormat.name().startsWith("XMI")) {
createFilesXmi(os, fileFormat);
2018-05-01 17:26:04 +00:00
return ImageDataSimple.ok();
2011-04-19 16:50:40 +00:00
}
2016-04-22 20:36:08 +00:00
if (fileFormat == FileFormat.SCXML) {
createFilesScxml(os);
2018-05-01 17:26:04 +00:00
return ImageDataSimple.ok();
2016-04-22 20:36:08 +00:00
}
// ::done
2016-04-22 20:36:08 +00:00
2010-11-15 20:35:36 +00:00
if (getUmlDiagramType() == UmlDiagramType.COMPOSITE) {
2013-12-10 19:36:50 +00:00
throw new UnsupportedOperationException();
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
this.eventuallyBuildPhantomGroups();
final CucaDiagramFileMaker maker;
// ::comment when WASM
2022-02-14 17:44:01 +00:00
if (this.isUseElk())
maker = new CucaDiagramFileMakerElk(this, fileFormatOption.getDefaultStringBounder(getSkinParam()));
2022-02-14 17:44:01 +00:00
else if (this.isUseSmetana())
// ::done
maker = new CucaDiagramFileMakerSmetana(this, fileFormatOption.getDefaultStringBounder(getSkinParam()));
// ::comment when WASM
2022-02-14 17:44:01 +00:00
else
maker = new CucaDiagramFileMakerSvek(this);
// ::done
2022-02-14 17:44:01 +00:00
2013-12-10 19:36:50 +00:00
final ImageData result = maker.createFile(os, getDotStrings(), fileFormatOption);
2022-02-14 17:44:01 +00:00
if (result == null)
2018-05-01 17:26:04 +00:00
return ImageDataSimple.error();
2022-02-14 17:44:01 +00:00
2013-12-10 19:36:50 +00:00
this.warningOrError = result.getWarningOrError();
return result;
}
private String warningOrError;
@Override
public String getWarningOrError() {
final String generalWarningOrError = super.getWarningOrError();
2022-02-14 17:44:01 +00:00
if (warningOrError == null)
2013-12-10 19:36:50 +00:00
return generalWarningOrError;
2022-02-14 17:44:01 +00:00
if (generalWarningOrError == null)
2013-12-10 19:36:50 +00:00
return warningOrError;
2022-02-14 17:44:01 +00:00
2017-06-05 11:27:21 +00:00
return generalWarningOrError + BackSlash.NEWLINE + warningOrError;
2010-11-15 20:35:36 +00:00
}
public boolean isAutarkic(EntityImp g) {
2022-02-14 17:44:01 +00:00
if (g.getGroupType() == GroupType.PACKAGE)
2010-11-15 20:35:36 +00:00
return false;
2022-02-14 17:44:01 +00:00
if (g.getGroupType() == GroupType.INNER_ACTIVITY)
2010-11-15 20:35:36 +00:00
return true;
2022-02-14 17:44:01 +00:00
if (g.getGroupType() == GroupType.CONCURRENT_ACTIVITY)
2010-11-15 20:35:36 +00:00
return true;
2022-02-14 17:44:01 +00:00
if (g.getGroupType() == GroupType.CONCURRENT_STATE)
2010-11-15 20:35:36 +00:00
return true;
2022-02-14 17:44:01 +00:00
if (getChildrenGroups(g).size() > 0)
2010-11-15 20:35:36 +00:00
return false;
2022-02-14 17:44:01 +00:00
for (Link link : getLinks())
if (EntityUtils.isPureInnerLink3(g, link) == false)
2010-11-15 20:35:36 +00:00
return false;
2022-02-14 17:44:01 +00:00
for (EntityImp leaf : g.getLeafsDirect())
2022-02-14 17:44:01 +00:00
if (leaf.getEntityPosition() != EntityPosition.NORMAL)
2010-11-15 20:35:36 +00:00
return false;
2022-02-14 17:44:01 +00:00
2010-11-15 20:35:36 +00:00
return true;
}
private static boolean isNumber(String s) {
return s.matches("[+-]?(\\.?\\d+|\\d+\\.\\d*)");
}
public void resetPragmaLabel() {
getPragma().undefine("labeldistance");
getPragma().undefine("labelangle");
}
public String getLabeldistance() {
if (getPragma().isDefine("labeldistance")) {
final String s = getPragma().getValue("labeldistance");
2022-02-14 17:44:01 +00:00
if (isNumber(s))
2010-11-15 20:35:36 +00:00
return s;
2022-02-14 17:44:01 +00:00
2010-11-15 20:35:36 +00:00
}
if (getPragma().isDefine("defaultlabeldistance")) {
final String s = getPragma().getValue("defaultlabeldistance");
2022-02-14 17:44:01 +00:00
if (isNumber(s))
2010-11-15 20:35:36 +00:00
return s;
2022-02-14 17:44:01 +00:00
2010-11-15 20:35:36 +00:00
}
// Default in dot 1.0
return "1.7";
}
public String getLabelangle() {
if (getPragma().isDefine("labelangle")) {
final String s = getPragma().getValue("labelangle");
2022-02-14 17:44:01 +00:00
if (isNumber(s))
2010-11-15 20:35:36 +00:00
return s;
2022-02-14 17:44:01 +00:00
2010-11-15 20:35:36 +00:00
}
if (getPragma().isDefine("defaultlabelangle")) {
final String s = getPragma().getValue("defaultlabelangle");
2022-02-14 17:44:01 +00:00
if (isNumber(s))
2010-11-15 20:35:36 +00:00
return s;
2022-02-14 17:44:01 +00:00
2010-11-15 20:35:36 +00:00
}
// Default in dot -25
return "25";
}
final public boolean isEmpty(EntityImp gToTest) {
for (EntityImp gg : getGroups(false)) {
2022-02-14 17:44:01 +00:00
if (gg == gToTest)
2010-11-15 20:35:36 +00:00
continue;
2022-02-14 17:44:01 +00:00
if (gg.getParentContainer() == gToTest)
2010-11-15 20:35:36 +00:00
return false;
2022-02-14 17:44:01 +00:00
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
return gToTest.size() == 0;
2010-11-15 20:35:36 +00:00
}
public final boolean isVisibilityModifierPresent() {
return visibilityModifierPresent;
}
public final void setVisibilityModifierPresent(boolean visibilityModifierPresent) {
this.visibilityModifierPresent = visibilityModifierPresent;
}
public final boolean showPortion(EntityPortion portion, EntityImp entity) {
2022-02-14 17:44:01 +00:00
if (getSkinParam().strictUmlStyle() && portion == EntityPortion.CIRCLED_CHARACTER)
2013-12-10 19:36:50 +00:00
return false;
2022-02-14 17:44:01 +00:00
2010-11-15 20:35:36 +00:00
boolean result = true;
2022-02-14 17:44:01 +00:00
for (HideOrShow cmd : hideOrShows)
if (cmd.portion == portion && cmd.gender.contains(entity))
2010-11-15 20:35:36 +00:00
result = cmd.show;
2022-02-14 17:44:01 +00:00
2010-11-15 20:35:36 +00:00
return result;
}
2019-09-14 18:12:04 +00:00
public final void hideOrShow(EntityGender gender, EntityPortion portions, boolean show) {
2022-02-14 17:44:01 +00:00
for (EntityPortion portion : portions.asSet())
2010-11-15 20:35:36 +00:00
this.hideOrShows.add(new HideOrShow(gender, portion, show));
2022-02-14 17:44:01 +00:00
2010-11-15 20:35:36 +00:00
}
2011-03-20 21:40:07 +00:00
public void hideOrShow(Set<VisibilityModifier> visibilities, boolean show) {
2022-02-14 17:44:01 +00:00
if (show)
2011-03-20 21:40:07 +00:00
hides.removeAll(visibilities);
2022-02-14 17:44:01 +00:00
else
2011-03-20 21:40:07 +00:00
hides.addAll(visibilities);
}
2018-03-09 21:37:34 +00:00
public void hideOrShow2(String what, boolean show) {
this.hides2.add(new HideOrShow2(what, show));
2016-03-06 16:47:34 +00:00
}
2018-03-09 21:37:34 +00:00
public void removeOrRestore(String what, boolean show) {
this.removed.add(new HideOrShow2(what, show));
2015-04-07 18:18:37 +00:00
}
2021-05-14 08:42:57 +00:00
private final List<HideOrShow> hideOrShows = new ArrayList<>();
private final Set<VisibilityModifier> hides = new HashSet<>();
2010-11-15 20:35:36 +00:00
static class HideOrShow {
private final EntityGender gender;
private final EntityPortion portion;
private final boolean show;
public HideOrShow(EntityGender gender, EntityPortion portion, boolean show) {
this.gender = gender;
this.portion = portion;
this.show = show;
}
}
2011-03-20 21:40:07 +00:00
public final Set<VisibilityModifier> getHides() {
return Collections.unmodifiableSet(hides);
}
2011-08-08 17:48:29 +00:00
final public boolean isStandalone(EntityImp ent) {
2022-02-14 17:44:01 +00:00
for (final Link link : getLinks())
if (link.getEntity1() == ent || link.getEntity2() == ent)
2013-12-10 19:36:50 +00:00
return false;
2022-02-14 17:44:01 +00:00
2013-12-10 19:36:50 +00:00
return true;
2011-08-08 17:48:29 +00:00
}
final public boolean isStandaloneForArgo(EntityImp ent) {
for (final Link link : getLinks()) {
if (link.isHidden() || link.isInvis())
continue;
if (link.getEntity1() == ent || link.getEntity2() == ent)
return false;
}
return true;
}
2013-12-10 19:36:50 +00:00
final public Link getLastLink() {
final List<Link> links = getLinks();
for (int i = links.size() - 1; i >= 0; i--) {
final Link link = links.get(i);
2022-02-14 17:44:01 +00:00
if (link.getEntity1().getLeafType() != LeafType.NOTE && link.getEntity2().getLeafType() != LeafType.NOTE)
2013-12-10 19:36:50 +00:00
return link;
2022-02-14 17:44:01 +00:00
2011-08-08 17:48:29 +00:00
}
2013-12-10 19:36:50 +00:00
return null;
2011-08-08 17:48:29 +00:00
}
2020-02-18 21:24:31 +00:00
final public List<Link> getTwoLastLinks() {
2021-05-14 08:42:57 +00:00
final List<Link> result = new ArrayList<>();
2020-02-18 21:24:31 +00:00
final List<Link> links = getLinks();
for (int i = links.size() - 1; i >= 0; i--) {
final Link link = links.get(i);
if (link.getEntity1().getLeafType() != LeafType.NOTE && link.getEntity2().getLeafType() != LeafType.NOTE) {
result.add(link);
2022-02-14 17:44:01 +00:00
if (result.size() == 2)
2020-02-18 21:24:31 +00:00
return Collections.unmodifiableList(result);
2022-02-14 17:44:01 +00:00
2020-02-18 21:24:31 +00:00
}
}
return null;
}
protected EntityImp lastEntity = null;
2011-08-08 17:48:29 +00:00
final public EntityImp getLastEntity() {
2013-12-10 19:36:50 +00:00
return lastEntity;
}
final public EntityFactory getEntityFactory() {
// throw new UnsupportedOperationException();
2013-12-10 19:36:50 +00:00
return entityFactory;
}
public void applySingleStrategy() {
final MagmaList magmaList = new MagmaList();
for (EntityImp g : getGroups(true)) {
final List<EntityImp> standalones = new ArrayList<>();
2013-12-10 19:36:50 +00:00
for (EntityImp ent : g.getLeafsDirect())
2022-02-14 17:44:01 +00:00
if (isStandalone(ent))
2013-12-10 19:36:50 +00:00
standalones.add(ent);
2022-02-14 17:44:01 +00:00
if (standalones.size() < 3)
2013-12-10 19:36:50 +00:00
continue;
2022-02-14 17:44:01 +00:00
2013-12-10 19:36:50 +00:00
final Magma magma = new Magma(this, standalones);
magma.putInSquare();
magmaList.add(magma);
}
for (EntityImp g : getGroups(true)) {
2013-12-10 19:36:50 +00:00
final MagmaList magmas = magmaList.getMagmas(g);
2022-02-14 17:44:01 +00:00
if (magmas.size() < 3)
2013-12-10 19:36:50 +00:00
continue;
2022-02-14 17:44:01 +00:00
2013-12-10 19:36:50 +00:00
magmas.putInSquare();
2011-08-08 17:48:29 +00:00
}
2013-12-10 19:36:50 +00:00
2011-08-08 17:48:29 +00:00
}
2013-12-10 19:36:50 +00:00
public boolean isHideEmptyDescriptionForState() {
return false;
2011-08-08 17:48:29 +00:00
}
2015-04-07 18:18:37 +00:00
protected void incRawLayout() {
entityFactory.incRawLayout();
}
2020-02-18 21:24:31 +00:00
public CommandExecutionResult constraintOnLinks(Link link1, Link link2, Display display) {
final LinkConstraint linkConstraint = new LinkConstraint(link1, link2, display);
link1.setLinkConstraint(linkConstraint);
link2.setLinkConstraint(linkConstraint);
return CommandExecutionResult.ok();
}
@Override
public ClockwiseTopRightBottomLeft getDefaultMargins() {
// Strange numbers here for backwards compatibility
return ClockwiseTopRightBottomLeft.topRightBottomLeft(0, 5, 5, 0);
}
2022-08-24 16:46:33 +00:00
private final AtomicInteger cpt = new AtomicInteger(1);
public int getUniqueSequence() {
return cpt.addAndGet(1);
}
public String getUniqueSequence(String prefix) {
return prefix + getUniqueSequence();
}
2010-11-15 20:35:36 +00:00
}