See sample code at the end of this topic -
http://www.mindfusion.eu/onlinehelp/wpfdiagram/index.htm?T_MindFusion_Diagrammin...Your shape string converted to that format looks like this -
var myShape = new Shape(
new ElementTemplate[]
{
new LineTemplate(49, 0, 51, 0),
new BezierTemplate(51, 0, 78.06195, 5.2154064E-07, 100, 12.7598854, 100, 28.5),
new BezierTemplate(100, 28.5, 100, 28.99188, 99.978576, 29.480846, 99.936242, 29.966606),
new LineTemplate(99.936242, 29.966606, 99.932602, 30),
new LineTemplate(99.932602, 30, 100, 30),
new LineTemplate(99.932602, 30, 100, 90),
new LineTemplate(99.932602, 30, 80, 90),
new LineTemplate(99.932602, 30, 80, 51.472736),
new LineTemplate(99.932602, 30, 79.365486, 51.741902),
new BezierTemplate(99.932602, 30, 74.862572, 53.604394, 69.795174, 55.035278, 64.34166, 55.93081),
new LineTemplate(64.34166, 55.93081, 63.11636, 56.117116),
new LineTemplate(63.11636, 56.117116, 63.249928, 56.373452),
new BezierTemplate(63.11636, 56.117116, 64.366028, 58.640542, 65, 61.238576, 65, 64),
new BezierTemplate(65, 64, 65, 72.836556, 58.50813, 80, 50.5, 80),
new BezierTemplate(50.5, 80, 42.49187, 80, 36, 72.836556, 36, 64),
new BezierTemplate(36, 64, 36, 61.238576, 36.633972, 58.640542, 37.750072, 56.373452),
new LineTemplate(37.750072, 56.373452, 37.81398, 56.250802),
new LineTemplate(37.81398, 56.250802, 37.49023, 56.209348),
new BezierTemplate(37.81398, 56.250802, 31.337884, 55.347924, 25.637752, 53.811338, 20.634512, 51.741902),
new LineTemplate(20.634512, 51.741902, 20, 51.472736),
new LineTemplate(20, 51.472736, 20, 90),
new LineTemplate(20, 51.472736, 0, 90),
new LineTemplate(20, 51.472736, 0, 30),
new LineTemplate(20, 51.472736, 0.067397952, 30),
new LineTemplate(20, 51.472736, 0.063759088, 29.966608),
new BezierTemplate(20, 51.472736, 0.021423874, 29.480846, 0, 28.99188, 0, 28.5),
new BezierTemplate(0, 28.5, 0, 12.7598854, 21.938048, 5.2154064E-07, 49, 0)
},
FillRule.Nonzero, "test");
If by shape panel you mean NodeListView instance, you can add the shape there like this -
nodeListView.Items.Add(
new ShapeNode
{
Bounds = new Rect(0, 0, 50, 50),
Shape = myShape
});
FYI I've converted your shape string to Shape constructor's format using this method -
Shape FromPathString(string path, string id, double scale)
{
var elements = new List<ElementTemplate>();
path = path.ToLower();
var parts = Regex.Matches(path, @"[mlcz]|[^mlcz]+")
.Cast<Match>()
.Select(m => m.Value)
.ToArray();
var lastPoint = new Point();
List<Point> points;
for (int c = 0; c < parts.Length; c+=2)
{
var command = parts[c];
switch (command)
{
case "m":
lastPoint = ParsePoints(parts[c + 1], scale)[0];
break;
case "l":
points = ParsePoints(parts[c + 1], scale);
for (int p = 0; p < points.Count; p++)
{
elements.Add(new LineTemplate(
lastPoint.X, lastPoint.Y, points[p].X, points[p].Y));
Debug.WriteLine(
string.Format(
"new LineTemplate({0}, {1}, {2}, {3}),",
lastPoint.X, lastPoint.Y, points[p].X, points[p].Y));
lastPoint = points[0];
}
break;
case "c":
points = ParsePoints(parts[c + 1], scale);
for (int p = 0; p < points.Count; p += 3)
{
elements.Add(new BezierTemplate(
lastPoint.X, lastPoint.Y,
points[p + 0].X, points[p + 0].Y,
points[p + 1].X, points[p + 1].Y,
points[p + 2].X, points[p + 2].Y));
Debug.WriteLine(
string.Format(
"new BezierTemplate({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}),",
lastPoint.X, lastPoint.Y,
points[p + 0].X, points[p + 0].Y,
points[p + 1].X, points[p + 1].Y,
points[p + 2].X, points[p + 2].Y));
lastPoint = points[p + 2];
}
break;
}
}
return new Shape(elements.ToArray(), FillRule.Nonzero, id);
}
List<Point> ParsePoints(string coords, double scale)
{
coords = coords.Trim();
var points = new List<Point>();
var pointStrings = coords.Split(new [] { ' ' });
foreach (var pointString in pointStrings)
{
var cs = pointString.Split(new[] { ',' });
points.Add(
new Point(
scale * double.Parse(cs[0]),
scale * double.Parse(cs[1])));
}
return points;
}
You could as well call it directly with the string for shorter syntax, especially if you have more strings like that -
var myShape =
FromPathString(
"M24.5,0 L25.5,0 C39.030975,2.6077032E-07 50,6.3799427 50,14.25 50,14.49594 49.989288,14.740423 49.968121,14.983303 L49.966301,15 50,15 50,45 40,45 40,25.736368 39.682743,25.870951 C37.431286,26.802197 34.897587,27.517639 32.17083,27.965405 L31.55818,28.058558 31.624964,28.186726 C32.183014,29.320271 32.5,30.619288 32.5,32 32.5,36.418278 29.254065,40 25.25,40 21.245935,40 18,36.418278 18,32 18,30.619288 18.316986,29.320271 18.875036,28.186726 L18.90699,28.125401 18.745115,28.104674 C15.668942,27.673962 12.818876,26.905669 10.317256,25.870951 L10,25.736368 10,45 0,45 0,15 0.033698976,15 0.031879544,14.983304 C0.010711937,14.740423 0,14.49594 0,14.25 0,6.3799427 10.969024,2.6077032E-07 24.5,0 z",
"test", 2);
I scaled coordinates by 2 because Shape constructor expects them as percentage.
Regards,
Slavcho