1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-10 20:22:26 +00:00
plantuml/src/net/sourceforge/plantuml/activitydiagram/ActivityDiagram.java

216 lines
7.3 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2019-01-16 18:34:41 +00:00
* (C) Copyright 2009-2020, 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
*
*
*/
package net.sourceforge.plantuml.activitydiagram;
import java.util.Arrays;
import java.util.List;
import net.sourceforge.plantuml.Direction;
2019-06-26 19:24:49 +00:00
import net.sourceforge.plantuml.ISkinSimple;
2020-01-12 22:13:17 +00:00
import net.sourceforge.plantuml.OptionFlags;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.UmlDiagramType;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.core.DiagramDescription;
import net.sourceforge.plantuml.cucadiagram.Code;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.cucadiagram.CucaDiagram;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.Display;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.cucadiagram.GroupType;
import net.sourceforge.plantuml.cucadiagram.IEntity;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.ILeaf;
2019-12-10 21:45:49 +00:00
import net.sourceforge.plantuml.cucadiagram.Ident;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.LeafType;
2018-03-09 21:37:34 +00:00
import net.sourceforge.plantuml.cucadiagram.NamespaceStrategy;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.graphic.USymbol;
import net.sourceforge.plantuml.utils.UniqueSequence;
2010-11-15 20:35:36 +00:00
public class ActivityDiagram extends CucaDiagram {
private IEntity lastEntityConsulted;
private IEntity lastEntityBrancheConsulted;
private ConditionalContext currentContext;
2019-06-26 19:24:49 +00:00
public ActivityDiagram(ISkinSimple skinParam) {
super(skinParam);
2019-12-10 21:45:49 +00:00
setNamespaceSeparator(null);
2019-06-26 19:24:49 +00:00
}
2019-12-10 21:45:49 +00:00
public ILeaf getOrCreateLeaf(Ident ident, Code code, LeafType type, USymbol symbol) {
checkNotNull(ident);
return getOrCreateLeafDefault(ident, code, type, symbol);
2013-12-10 19:36:50 +00:00
}
2010-11-15 20:35:36 +00:00
private String getAutoBranch() {
return "#" + UniqueSequence.getValue();
}
2019-12-10 21:45:49 +00:00
public IEntity getOrCreate(Ident idNewLong, Code code, Display display, LeafType type) {
2010-11-15 20:35:36 +00:00
final IEntity result;
2020-01-12 22:13:17 +00:00
final boolean leafExist = this.V1972() ? leafExistSmart(idNewLong) : leafExist(code);
if (leafExist) {
2019-12-10 21:45:49 +00:00
result = getOrCreateLeafDefault(idNewLong, code, type, null);
2017-04-05 17:37:42 +00:00
if (result.getLeafType() != type) {
2013-12-10 19:36:50 +00:00
return null;
2010-11-15 20:35:36 +00:00
}
} else {
2019-12-10 21:45:49 +00:00
result = createLeaf(idNewLong, code, display, type, null);
2010-11-15 20:35:36 +00:00
}
updateLasts(result);
return result;
}
2020-01-12 22:13:17 +00:00
@Override
public /*final*/ ILeaf getLeafVerySmart(Ident ident) {
final ILeaf result = super.getLeafVerySmart(ident);
updateLasts(result);
return result;
}
2010-11-15 20:35:36 +00:00
2019-12-10 21:45:49 +00:00
public void startIf(String optionalCodeString) {
final String idShort = optionalCodeString == null ? getAutoBranch() : optionalCodeString;
final Ident idNewLong = buildLeafIdent(idShort);
2020-01-12 22:13:17 +00:00
final Code code = this.V1972() ? idNewLong : buildCode(idShort);
final IEntity br = createLeaf(idNewLong, code, Display.create(""), LeafType.BRANCH, null);
2010-11-15 20:35:36 +00:00
currentContext = new ConditionalContext(currentContext, br, Direction.DOWN);
}
public void endif() {
currentContext = currentContext.getParent();
}
2013-12-10 19:36:50 +00:00
public ILeaf getStart() {
2020-01-12 22:13:17 +00:00
final Ident ident = buildLeafIdent("start");
final Code code = this.V1972() ? ident : buildCode("start");
return (ILeaf) getOrCreate(ident, code, Display.getWithNewlines("start"), LeafType.CIRCLE_START);
2010-11-15 20:35:36 +00:00
}
2015-04-07 18:18:37 +00:00
public ILeaf getEnd(String suppId) {
2019-12-10 21:45:49 +00:00
final String tmp = suppId == null ? "end" : "end$" + suppId;
2020-01-12 22:13:17 +00:00
final Ident ident = buildLeafIdent(tmp);
final Code code = this.V1972() ? ident : buildCode(tmp);
return (ILeaf) getOrCreate(ident, code, Display.getWithNewlines("end"), LeafType.CIRCLE_END);
2010-11-15 20:35:36 +00:00
}
private void updateLasts(final IEntity result) {
2018-05-21 13:07:09 +00:00
if (result == null || result.getLeafType() == LeafType.NOTE) {
2010-11-15 20:35:36 +00:00
return;
}
this.lastEntityConsulted = result;
2017-04-05 17:37:42 +00:00
if (result.getLeafType() == LeafType.BRANCH) {
2010-11-15 20:35:36 +00:00
lastEntityBrancheConsulted = result;
}
}
@Override
2019-12-10 21:45:49 +00:00
public ILeaf createLeaf(Ident idNewLong, Code code, Display display, LeafType type, USymbol symbol) {
checkNotNull(idNewLong);
final ILeaf result = super.createLeaf(idNewLong, code, display, type, symbol);
2010-11-15 20:35:36 +00:00
updateLasts(result);
return result;
}
2019-12-10 21:45:49 +00:00
public IEntity createNote(Ident idNewLong, Code code, Display display) {
checkNotNull(idNewLong);
return super.createLeaf(idNewLong, code, display, LeafType.NOTE, null);
2010-11-15 20:35:36 +00:00
}
final protected List<String> getDotStrings() {
return Arrays.asList("nodesep=.20;", "ranksep=0.4;", "edge [fontsize=11,labelfontsize=11];",
"node [fontsize=11];");
}
2013-12-10 19:36:50 +00:00
public DiagramDescription getDescription() {
2017-03-12 17:22:02 +00:00
return new DiagramDescription("(" + getLeafssize() + " activities)");
2010-11-15 20:35:36 +00:00
}
public IEntity getLastEntityConsulted() {
return lastEntityConsulted;
}
@Deprecated
public IEntity getLastEntityBrancheConsulted() {
return lastEntityBrancheConsulted;
}
@Override
public UmlDiagramType getUmlDiagramType() {
return UmlDiagramType.ACTIVITY;
}
public final ConditionalContext getCurrentContext() {
return currentContext;
}
public final void setLastEntityConsulted(IEntity lastEntityConsulted) {
this.lastEntityConsulted = lastEntityConsulted;
}
public IEntity createInnerActivity() {
2013-12-10 19:36:50 +00:00
// Log.println("createInnerActivity A");
2019-12-10 21:45:49 +00:00
final String idShort = "##" + UniqueSequence.getValue();
final Ident idNewLong = buildLeafIdent(idShort);
2020-01-12 22:13:17 +00:00
final Code code = this.V1972() ? idNewLong : buildCode(idShort);
2019-12-10 21:45:49 +00:00
gotoGroup(idNewLong, code, Display.getWithNewlines(code), GroupType.INNER_ACTIVITY, getCurrentGroup(),
2018-03-09 21:37:34 +00:00
NamespaceStrategy.SINGLE);
final IEntity g = getCurrentGroup();
2010-11-15 20:35:36 +00:00
// g.setRankdir(Rankdir.LEFT_TO_RIGHT);
lastEntityConsulted = null;
lastEntityBrancheConsulted = null;
2013-12-10 19:36:50 +00:00
// Log.println("createInnerActivity B "+getCurrentGroup());
return g;
2010-11-15 20:35:36 +00:00
}
public void concurrentActivity(String name) {
2013-12-10 19:36:50 +00:00
// Log.println("concurrentActivity A name=" + name+" "+getCurrentGroup());
if (getCurrentGroup().getGroupType() == GroupType.CONCURRENT_ACTIVITY) {
2010-11-15 20:35:36 +00:00
// getCurrentGroup().setRankdir(Rankdir.LEFT_TO_RIGHT);
endGroup();
2013-12-10 19:36:50 +00:00
// Log.println("endgroup");
2010-11-15 20:35:36 +00:00
}
2019-12-10 21:45:49 +00:00
final String idShort = "##" + UniqueSequence.getValue();
2013-12-10 19:36:50 +00:00
// Log.println("concurrentActivity A name=" + name+" "+getCurrentGroup());
2019-12-10 21:45:49 +00:00
final Code code = buildCode(idShort);
2013-12-10 19:36:50 +00:00
if (getCurrentGroup().getGroupType() != GroupType.INNER_ACTIVITY) {
throw new IllegalStateException("type=" + getCurrentGroup().getGroupType());
2010-11-15 20:35:36 +00:00
}
2019-12-10 21:45:49 +00:00
final Ident idNewLong = buildLeafIdent(idShort);
gotoGroup(idNewLong, code, Display.getWithNewlines("code"), GroupType.CONCURRENT_ACTIVITY, getCurrentGroup(),
2018-03-09 21:37:34 +00:00
NamespaceStrategy.SINGLE);
2010-11-15 20:35:36 +00:00
lastEntityConsulted = null;
lastEntityBrancheConsulted = null;
}
}