1
0
mirror of https://github.com/octoleo/plantuml.git synced 2025-01-03 15:17:23 +00:00

fix: multiple breaks in repeat

https://github.com/plantuml/plantuml/issues/1369
This commit is contained in:
Arnaud Roques 2023-04-03 23:29:34 +02:00
parent 7062ec070b
commit 5600f0999e
7 changed files with 79 additions and 67 deletions

View File

@ -134,27 +134,27 @@ public class InstructionIf extends WithNote implements Instruction, InstructionC
@Override @Override
public Ftile createFtile(FtileFactory factory) { public Ftile createFtile(FtileFactory factory) {
for (Branch branch : thens) { for (Branch branch : thens)
branch.updateFtile(factory); branch.updateFtile(factory);
}
if (elseBranch == null) if (elseBranch == null)
this.elseBranch = new Branch(skinParam.getCurrentStyleBuilder(), swimlane, LinkRendering.none(), this.elseBranch = new Branch(skinParam.getCurrentStyleBuilder(), swimlane, LinkRendering.none(),
Display.NULL, null, LinkRendering.none()); Display.NULL, null, LinkRendering.none());
elseBranch.updateFtile(factory); elseBranch.updateFtile(factory);
Ftile result = factory.createIf(swimlane, thens, elseBranch, outColor, topInlinkRendering, url); Ftile result = factory.createIf(swimlane, thens, elseBranch, outColor, topInlinkRendering, url);
if (getPositionedNotes().size() > 0) { if (getPositionedNotes().size() > 0)
result = FtileWithNoteOpale.create(result, getPositionedNotes(), skinParam, false, result = FtileWithNoteOpale.create(result, getPositionedNotes(), skinParam, false,
VerticalAlignment.CENTER); VerticalAlignment.CENTER);
}
final List<WeldingPoint> weldingPoints = new ArrayList<>(); final List<WeldingPoint> weldingPoints = new ArrayList<>();
for (Branch branch : thens) { for (Branch branch : thens)
weldingPoints.addAll(branch.getWeldingPoints()); weldingPoints.addAll(branch.getWeldingPoints());
}
weldingPoints.addAll(elseBranch.getWeldingPoints()); weldingPoints.addAll(elseBranch.getWeldingPoints());
if (weldingPoints.size() > 0) { if (weldingPoints.size() > 0)
result = new FtileDecorateWelding(result, weldingPoints); result = new FtileDecorateWelding(result, weldingPoints);
}
return result; return result;
} }
@ -163,9 +163,9 @@ public class InstructionIf extends WithNote implements Instruction, InstructionC
} }
public boolean swithToElse2(LinkRendering whenElse, LinkRendering nextLinkRenderer) { public boolean swithToElse2(LinkRendering whenElse, LinkRendering nextLinkRenderer) {
if (elseBranch != null) { if (elseBranch != null)
return false; return false;
}
this.current.setInlinkRendering(nextLinkRenderer); this.current.setInlinkRendering(nextLinkRenderer);
this.elseBranch = new Branch(skinParam.getCurrentStyleBuilder(), swimlane, whenElse, Display.NULL, null, this.elseBranch = new Branch(skinParam.getCurrentStyleBuilder(), swimlane, whenElse, Display.NULL, null,
LinkRendering.none()); LinkRendering.none());
@ -175,9 +175,9 @@ public class InstructionIf extends WithNote implements Instruction, InstructionC
public boolean elseIf(LinkRendering inlabel, Display test, LinkRendering whenThen, LinkRendering nextLinkRenderer, public boolean elseIf(LinkRendering inlabel, Display test, LinkRendering whenThen, LinkRendering nextLinkRenderer,
HColor color) { HColor color) {
if (elseBranch != null) { if (elseBranch != null)
return false; return false;
}
// this.current.setInlinkRendering(nextLinkRenderer); // this.current.setInlinkRendering(nextLinkRenderer);
this.current.setSpecial(nextLinkRenderer); this.current.setSpecial(nextLinkRenderer);
this.current = new Branch(skinParam.getCurrentStyleBuilder(), swimlane, whenThen, test, color, inlabel); this.current = new Branch(skinParam.getCurrentStyleBuilder(), swimlane, whenThen, test, color, inlabel);
@ -188,10 +188,10 @@ public class InstructionIf extends WithNote implements Instruction, InstructionC
public void endif(LinkRendering nextLinkRenderer) { public void endif(LinkRendering nextLinkRenderer) {
endifCalled = true; endifCalled = true;
if (elseBranch == null) { if (elseBranch == null)
this.elseBranch = new Branch(skinParam.getCurrentStyleBuilder(), swimlane, LinkRendering.none(), this.elseBranch = new Branch(skinParam.getCurrentStyleBuilder(), swimlane, LinkRendering.none(),
Display.NULL, null, LinkRendering.none()); Display.NULL, null, LinkRendering.none());
}
this.elseBranch.setSpecial(nextLinkRenderer); this.elseBranch.setSpecial(nextLinkRenderer);
this.current.setInlinkRendering(nextLinkRenderer); this.current.setInlinkRendering(nextLinkRenderer);
} }
@ -200,12 +200,12 @@ public class InstructionIf extends WithNote implements Instruction, InstructionC
final public boolean kill() { final public boolean kill() {
if (endifCalled) { if (endifCalled) {
for (Branch branch : thens) { for (Branch branch : thens) {
if (branch.getLast() != null && branch.getLast().kill() == false) { if (branch.getLast() != null && branch.getLast().kill() == false)
return false; return false;
}
if (elseBranch != null && elseBranch.getLast() != null && elseBranch.getLast().kill() == false) { if (elseBranch != null && elseBranch.getLast() != null && elseBranch.getLast().kill() == false)
return false; return false;
}
return true; return true;
} }
} }
@ -219,25 +219,25 @@ public class InstructionIf extends WithNote implements Instruction, InstructionC
@Override @Override
public boolean addNote(Display note, NotePosition position, NoteType type, Colors colors, Swimlane swimlaneNote) { public boolean addNote(Display note, NotePosition position, NoteType type, Colors colors, Swimlane swimlaneNote) {
if (endifCalled || current.isEmpty()) { if (endifCalled || current.isEmpty())
return super.addNote(note, position, type, colors, swimlaneNote); return super.addNote(note, position, type, colors, swimlaneNote);
} else { else
return current.addNote(note, position, type, colors, swimlaneNote); return current.addNote(note, position, type, colors, swimlaneNote);
}
} }
@Override @Override
public Set<Swimlane> getSwimlanes() { public Set<Swimlane> getSwimlanes() {
final Set<Swimlane> result = new HashSet<>(); final Set<Swimlane> result = new HashSet<>();
if (swimlane != null) { if (swimlane != null)
result.add(swimlane); result.add(swimlane);
}
for (Branch branch : thens) { for (Branch branch : thens)
result.addAll(branch.getSwimlanes()); result.addAll(branch.getSwimlanes());
}
if (elseBranch != null) { if (elseBranch != null)
result.addAll(elseBranch.getSwimlanes()); result.addAll(elseBranch.getSwimlanes());
}
return Collections.unmodifiableSet(result); return Collections.unmodifiableSet(result);
} }
@ -253,9 +253,9 @@ public class InstructionIf extends WithNote implements Instruction, InstructionC
@Override @Override
public Instruction getLast() { public Instruction getLast() {
if (elseBranch == null) { if (elseBranch == null)
return thens.get(thens.size() - 1).getLast(); return thens.get(thens.size() - 1).getLast();
}
return elseBranch.getLast(); return elseBranch.getLast();
} }

View File

@ -44,9 +44,9 @@ public class FtileUtils {
} }
public static Ftile addConnection(Ftile ftile, Collection<Connection> connections) { public static Ftile addConnection(Ftile ftile, Collection<Connection> connections) {
if (connections.size() == 0) { if (connections.size() == 0)
return ftile; return ftile;
}
return new FtileWithConnection(ftile, connections); return new FtileWithConnection(ftile, connections);
} }
@ -59,23 +59,23 @@ public class FtileUtils {
} }
public static Ftile addVerticalMargin(Ftile ftile, double marginTop, double marginBottom) { public static Ftile addVerticalMargin(Ftile ftile, double marginTop, double marginBottom) {
if (marginTop == 0 && marginBottom == 0) { if (marginTop == 0 && marginBottom == 0)
return ftile; return ftile;
}
return new FtileMargedVertically(ftile, marginTop, marginBottom); return new FtileMargedVertically(ftile, marginTop, marginBottom);
} }
public static Ftile addHorizontalMargin(Ftile ftile, double margin1, double margin2) { public static Ftile addHorizontalMargin(Ftile ftile, double margin1, double margin2) {
if (margin1 == 0 && margin2 == 0) { if (margin1 == 0 && margin2 == 0)
return ftile; return ftile;
}
return new FtileMarged(ftile, margin1, margin2); return new FtileMarged(ftile, margin1, margin2);
} }
public static Ftile addHorizontalMargin(Ftile ftile, double margin) { public static Ftile addHorizontalMargin(Ftile ftile, double margin) {
if (margin == 0) { if (margin == 0)
return ftile; return ftile;
}
return new FtileMarged(ftile, margin, margin); return new FtileMarged(ftile, margin, margin);
} }

View File

@ -35,6 +35,8 @@
*/ */
package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact; package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import net.sourceforge.plantuml.activitydiagram3.LinkRendering; import net.sourceforge.plantuml.activitydiagram3.LinkRendering;
@ -95,25 +97,34 @@ public class FtileFactoryDelegatorRepeat extends FtileFactoryDelegator {
final List<WeldingPoint> weldingPoints = repeat.getWeldingPoints(); final List<WeldingPoint> weldingPoints = repeat.getWeldingPoints();
if (weldingPoints.size() > 0) { if (weldingPoints.size() > 0) {
// printAllChild(repeat);
final Ftile diamondBreak = new FtileDiamond(repeat.skinParam(), diamondColor, borderColor, swimlane); final Ftile diamondBreak = new FtileDiamond(repeat.skinParam(), diamondColor, borderColor, swimlane);
result = assembly(FtileUtils.addHorizontalMargin(result, 10, 0), diamondBreak); result = assembly(FtileUtils.addHorizontalMargin(result, 10, 0), diamondBreak);
final Genealogy genealogy = new Genealogy(result); final Genealogy genealogy = new Genealogy(result);
final FtileBreak ftileBreak = (FtileBreak) weldingPoints.get(0); final Collection<Connection> connections = new ArrayList<Connection>();
result = FtileUtils.addConnection(result, new Connection() { for (int i = 0; i < weldingPoints.size(); i++) {
final FtileBreak ftileBreak = (FtileBreak) weldingPoints.get(i);
final boolean first = i == 0;
connections.add(new Connection() {
public void drawU(UGraphic ug) { public void drawU(UGraphic ug) {
final UTranslate tr1 = genealogy.getTranslate(ftileBreak, ug.getStringBounder()); final UTranslate tr1 = genealogy.getTranslate(ftileBreak, ug.getStringBounder());
final UTranslate tr2 = genealogy.getTranslate(diamondBreak, ug.getStringBounder()); final UTranslate tr2 = genealogy.getTranslate(diamondBreak, ug.getStringBounder());
final XDimension2D dimDiamond = diamondBreak.calculateDimension(ug.getStringBounder()); final XDimension2D dimDiamond = diamondBreak.calculateDimension(ug.getStringBounder());
final Snake snake = Snake.create(skinParam(), arrowColor, skinParam().arrows().asToRight()); final Snake snake;
if (first) {
snake = Snake.create(skinParam(), arrowColor, skinParam().arrows().asToRight());
snake.addPoint(tr1.getDx(), tr1.getDy()); snake.addPoint(tr1.getDx(), tr1.getDy());
snake.addPoint(0, tr1.getDy()); snake.addPoint(0, tr1.getDy());
snake.addPoint(0, tr2.getDy() + dimDiamond.getHeight() / 2); snake.addPoint(0, tr2.getDy() + dimDiamond.getHeight() / 2);
snake.addPoint(tr2.getDx(), tr2.getDy() + dimDiamond.getHeight() / 2); snake.addPoint(tr2.getDx(), tr2.getDy() + dimDiamond.getHeight() / 2);
} else {
snake = Snake.create(skinParam(), arrowColor, skinParam().arrows().asToLeft());
snake.addPoint(tr1.getDx(), tr1.getDy());
snake.addPoint(0, tr1.getDy());
}
ug.draw(snake); ug.draw(snake);
} }
@ -126,6 +137,9 @@ public class FtileFactoryDelegatorRepeat extends FtileFactoryDelegator {
} }
}); });
}
result = FtileUtils.addConnection(result, connections);
} }
return result; return result;

View File

@ -267,13 +267,15 @@ public class ArrowConfiguration {
} }
public final int getInclination1() { public final int getInclination1() {
if (dressing2.getHead() == ArrowHead.NONE) if (dressing2.getHead() == ArrowHead.NONE || dressing2.getHead() == ArrowHead.CROSSX)
return inclination; return inclination;
return 0; return 0;
} }
public final int getInclination2() { public final int getInclination2() {
if (dressing1.getHead() == ArrowHead.NONE) if (dressing1.getHead() == ArrowHead.NONE || dressing1.getHead() == ArrowHead.CROSSX)
return inclination;
if (dressing1.getHead() == ArrowHead.NORMAL || dressing1.getHead() == ArrowHead.NORMAL)
return inclination; return inclination;
return 0; return 0;
} }

View File

@ -63,8 +63,7 @@ public abstract class AbstractEntityImageBorder extends AbstractEntityImage {
protected abstract StyleSignatureBasic getSignature(); protected abstract StyleSignatureBasic getSignature();
final protected Style getStyle() { final protected Style getStyle() {
final Entity leaf = (Entity) getEntity(); final Stereotype stereotype = getEntity().getStereotype();
final Stereotype stereotype = leaf.getStereotype();
return getSignature().withTOBECHANGED(stereotype).getMergedStyle(getSkinParam().getCurrentStyleBuilder()); return getSignature().withTOBECHANGED(stereotype).getMergedStyle(getSkinParam().getCurrentStyleBuilder());
} }

View File

@ -58,17 +58,14 @@ import net.sourceforge.plantuml.svek.SvekNode;
public class EntityImageStateBorder extends AbstractEntityImageBorder { public class EntityImageStateBorder extends AbstractEntityImageBorder {
private final SName sname;
public EntityImageStateBorder(Entity leaf, ISkinParam skinParam, Cluster stateParent, final Bibliotekon bibliotekon, public EntityImageStateBorder(Entity leaf, ISkinParam skinParam, Cluster stateParent, final Bibliotekon bibliotekon,
SName sname) { SName sname) {
super(leaf, skinParam, stateParent, bibliotekon, FontParam.STATE); super(leaf, skinParam, stateParent, bibliotekon, FontParam.STATE);
this.sname = sname;
} }
@Override @Override
protected StyleSignatureBasic getSignature() { protected StyleSignatureBasic getSignature() {
return StyleSignatureBasic.of(SName.root, SName.element, sname); return StyleSignatureBasic.of(SName.root, SName.element, SName.stateDiagram, SName.state);
} }
private boolean upPosition() { private boolean upPosition() {

View File

@ -82,7 +82,7 @@ public class Version {
} }
public static int beta() { public static int beta() {
final int beta = 1; final int beta = 2;
return beta; return beta;
} }