Skip to content

Commit

Permalink
minor patch to correct issues with placing line ends, such as arrows …
Browse files Browse the repository at this point in the history
…or circles.
  • Loading branch information
roger-castaldo committed Feb 7, 2018
1 parent 9bb9ce6 commit f31f645
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Org.Reddragonit.BpmEngine
{
internal static class Constants
{
public const float PEN_WIDTH = 3.5F;
public const float PEN_WIDTH = 3F;
public static readonly float[] DASH_PATTERN = new float[] { 3.0f, 3.0f };
public const float FONT_SIZE = 9.2F;
public static readonly Font FONT = new Font(FontFamily.GenericSerif, FONT_SIZE,FontStyle.Regular,GraphicsUnit.Point);
Expand Down
1 change: 1 addition & 0 deletions Elements/Diagram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ private Image _Render(ProcessPath path, Definition definition, string elemid)
{
StepStatuses status = path.GetStatus(edge.bpmnElement);
gp.DrawLines(edge.ConstructPen(_GetBrush(status), definition), edge.Points);
edge.AppendEnds(gp, _GetBrush(status), definition);
if (edge.Label != null)
{
IElement elem = definition.LocateElement(edge.bpmnElement);
Expand Down
52 changes: 43 additions & 9 deletions Elements/Diagrams/Edge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private CustomLineCap _defaultFlowCap
get
{
GraphicsPath gp = new GraphicsPath();
gp.AddLine(new PointF(-1.5f,-3.5f),new PointF(1.5f,-1.5f));
gp.AddLine(new PointF(1.5f,-3.5f),new PointF(1.5f,-1.5f));
return new CustomLineCap(null, gp);
}
}
Expand Down Expand Up @@ -64,16 +64,26 @@ public Pen ConstructPen(Brush brush, Definition definition)
IElement elem = _GetLinkedElement(definition);
if (elem != null)
{
if (elem is Association)
if (elem is Association || elem is MessageFlow)
ret.DashPattern = Constants.DASH_PATTERN;
else if (elem is MessageFlow)
}
return ret;
}

internal void AppendEnds(Graphics gp, Brush brush, Definition definition)
{
Pen p = ConstructPen(brush, definition);
IElement elem = _GetLinkedElement(definition);
if (elem != null)
{
Point[] points = Points;
if (elem is MessageFlow)
{
ret.DashPattern = Constants.DASH_PATTERN;
ret.StartCap = System.Drawing.Drawing2D.LineCap.RoundAnchor;
ret.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
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)));
_GenerateTriangle(gp, brush, points[points.Length - 1],points[points.Length-2]);
}
else
ret.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
_GenerateTriangle(gp, brush, points[points.Length - 1], points[points.Length - 2]);
if (elem is SequenceFlow || elem is MessageFlow)
{
string sourceRef = (elem is SequenceFlow ? ((SequenceFlow)elem).sourceRef : ((MessageFlow)elem).sourceRef);
Expand All @@ -83,12 +93,36 @@ public Pen ConstructPen(Brush brush, Definition definition)
if (gelem is AGateway)
{
if ((((AGateway)gelem).Default == null ? "" : ((AGateway)gelem).Default) == elem.id)
ret.CustomStartCap = _defaultFlowCap;
{
PointF centre = new PointF(
((0.5f*(float)points[0].X)+(0.5f*(float)points[1].X)),
((0.5f * (float)points[0].Y) + (0.5f * (float)points[1].Y))
);
gp.DrawLine(p,new PointF(centre.X-3f,centre.Y-3f),new PointF(centre.X+3f,centre.Y+3f));
}
}
}
}
}
return ret;
}

private static readonly float _baseTLength = Constants.PEN_WIDTH*1.5f;

private void _GenerateTriangle(Graphics gp, Brush brush, Point end,Point start)
{
float d = (float)Math.Sqrt(Math.Pow((double)end.X - (double)start.X, 2) + Math.Pow((double)end.Y - (double)start.Y, 2));
float t = _baseTLength / d;
PointF pc = new PointF(((1f - t) * (float)end.X) + (t * (float)start.X), ((1f - t) * (float)end.Y) + (t * (float)start.Y));
PointF fend = new PointF((float)end.X, (float)end.Y);
PointF p1 = new PointF(pc.X-(fend.Y-pc.Y),(fend.X-pc.X)+pc.Y);
PointF p2 = new PointF(fend.Y-pc.Y+pc.X,pc.Y-(fend.X-pc.X));
t = _baseTLength / d;
gp.DrawLine(new Pen(Brushes.White,Constants.PEN_WIDTH), fend, pc);
gp.FillPolygon(brush, new PointF[] {
fend,
p1,
p2
});
}

public override bool IsValid(out string[] err)
Expand Down

0 comments on commit f31f645

Please sign in to comment.