Skip to content

Commit f31f645

Browse files
minor patch to correct issues with placing line ends, such as arrows or circles.
1 parent 9bb9ce6 commit f31f645

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

Constants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Org.Reddragonit.BpmEngine
77
{
88
internal static class Constants
99
{
10-
public const float PEN_WIDTH = 3.5F;
10+
public const float PEN_WIDTH = 3F;
1111
public static readonly float[] DASH_PATTERN = new float[] { 3.0f, 3.0f };
1212
public const float FONT_SIZE = 9.2F;
1313
public static readonly Font FONT = new Font(FontFamily.GenericSerif, FONT_SIZE,FontStyle.Regular,GraphicsUnit.Point);

Elements/Diagram.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ private Image _Render(ProcessPath path, Definition definition, string elemid)
331331
{
332332
StepStatuses status = path.GetStatus(edge.bpmnElement);
333333
gp.DrawLines(edge.ConstructPen(_GetBrush(status), definition), edge.Points);
334+
edge.AppendEnds(gp, _GetBrush(status), definition);
334335
if (edge.Label != null)
335336
{
336337
IElement elem = definition.LocateElement(edge.bpmnElement);

Elements/Diagrams/Edge.cs

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ private CustomLineCap _defaultFlowCap
2323
get
2424
{
2525
GraphicsPath gp = new GraphicsPath();
26-
gp.AddLine(new PointF(-1.5f,-3.5f),new PointF(1.5f,-1.5f));
26+
gp.AddLine(new PointF(1.5f,-3.5f),new PointF(1.5f,-1.5f));
2727
return new CustomLineCap(null, gp);
2828
}
2929
}
@@ -64,16 +64,26 @@ public Pen ConstructPen(Brush brush, Definition definition)
6464
IElement elem = _GetLinkedElement(definition);
6565
if (elem != null)
6666
{
67-
if (elem is Association)
67+
if (elem is Association || elem is MessageFlow)
6868
ret.DashPattern = Constants.DASH_PATTERN;
69-
else if (elem is MessageFlow)
69+
}
70+
return ret;
71+
}
72+
73+
internal void AppendEnds(Graphics gp, Brush brush, Definition definition)
74+
{
75+
Pen p = ConstructPen(brush, definition);
76+
IElement elem = _GetLinkedElement(definition);
77+
if (elem != null)
78+
{
79+
Point[] points = Points;
80+
if (elem is MessageFlow)
7081
{
71-
ret.DashPattern = Constants.DASH_PATTERN;
72-
ret.StartCap = System.Drawing.Drawing2D.LineCap.RoundAnchor;
73-
ret.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
82+
gp.FillEllipse(brush, new RectangleF(new PointF((float)points[0].X - 0.5f, (float)points[0].Y - 0.5f), new SizeF(1.5f, 1.5f)));
83+
_GenerateTriangle(gp, brush, points[points.Length - 1],points[points.Length-2]);
7484
}
7585
else
76-
ret.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
86+
_GenerateTriangle(gp, brush, points[points.Length - 1], points[points.Length - 2]);
7787
if (elem is SequenceFlow || elem is MessageFlow)
7888
{
7989
string sourceRef = (elem is SequenceFlow ? ((SequenceFlow)elem).sourceRef : ((MessageFlow)elem).sourceRef);
@@ -83,12 +93,36 @@ public Pen ConstructPen(Brush brush, Definition definition)
8393
if (gelem is AGateway)
8494
{
8595
if ((((AGateway)gelem).Default == null ? "" : ((AGateway)gelem).Default) == elem.id)
86-
ret.CustomStartCap = _defaultFlowCap;
96+
{
97+
PointF centre = new PointF(
98+
((0.5f*(float)points[0].X)+(0.5f*(float)points[1].X)),
99+
((0.5f * (float)points[0].Y) + (0.5f * (float)points[1].Y))
100+
);
101+
gp.DrawLine(p,new PointF(centre.X-3f,centre.Y-3f),new PointF(centre.X+3f,centre.Y+3f));
102+
}
87103
}
88104
}
89105
}
90106
}
91-
return ret;
107+
}
108+
109+
private static readonly float _baseTLength = Constants.PEN_WIDTH*1.5f;
110+
111+
private void _GenerateTriangle(Graphics gp, Brush brush, Point end,Point start)
112+
{
113+
float d = (float)Math.Sqrt(Math.Pow((double)end.X - (double)start.X, 2) + Math.Pow((double)end.Y - (double)start.Y, 2));
114+
float t = _baseTLength / d;
115+
PointF pc = new PointF(((1f - t) * (float)end.X) + (t * (float)start.X), ((1f - t) * (float)end.Y) + (t * (float)start.Y));
116+
PointF fend = new PointF((float)end.X, (float)end.Y);
117+
PointF p1 = new PointF(pc.X-(fend.Y-pc.Y),(fend.X-pc.X)+pc.Y);
118+
PointF p2 = new PointF(fend.Y-pc.Y+pc.X,pc.Y-(fend.X-pc.X));
119+
t = _baseTLength / d;
120+
gp.DrawLine(new Pen(Brushes.White,Constants.PEN_WIDTH), fend, pc);
121+
gp.FillPolygon(brush, new PointF[] {
122+
fend,
123+
p1,
124+
p2
125+
});
92126
}
93127

94128
public override bool IsValid(out string[] err)

0 commit comments

Comments
 (0)