Refactored shape data property

This commit is contained in:
Wiesław Šoltés 2015-08-03 16:44:17 +02:00
Родитель f0ade6fe3b
Коммит 87e2e3e81f
2 изменённых файлов: 16 добавлений и 19 удалений

Просмотреть файл

@ -49,15 +49,10 @@ namespace SpiroNet
public bool IsTagged { get; set; }
/// <summary>
/// The generated Path data.
/// Try to generate Path shape data from Points using path bezier context implementation.
/// </summary>
public string Data { get; set; }
/// <summary>
/// Generate Path shape data using path bezier context implementation.
/// </summary>
/// <returns>True when Data was generated successfully.</returns>
public bool UpdateData()
/// <returns>True when output data was generated successfully.</returns>
public bool TryGetData(out string data)
{
var points = this.Points.ToArray();
var bc = new PathBezierContext();
@ -66,9 +61,9 @@ namespace SpiroNet
{
var success = Spiro.TaggedSpiroCPsToBezier0(points, bc);
if (success)
this.Data = bc.ToString();
data = bc.ToString();
else
this.Data = string.Empty;
data = null;
return success;
}
@ -76,9 +71,9 @@ namespace SpiroNet
{
var success = Spiro.SpiroCPsToBezier0(points, points.Length, this.IsClosed, bc);
if (success)
this.Data = bc.ToString();
data = bc.ToString();
else
this.Data = string.Empty;
data = null;
return success;
}

Просмотреть файл

@ -32,6 +32,7 @@ namespace SpiroNet.Wpf
public class SpiroCanvas : Canvas
{
public IList<PathShape> Shapes { get; set; }
public IDictionary<PathShape, string> Data { get; set; }
private Brush _geometryBrush;
private Brush _geometryPenBrush;
@ -78,18 +79,19 @@ namespace SpiroNet.Wpf
if (shape == null)
return;
if (!string.IsNullOrEmpty(shape.Data))
string data;
if (Data.TryGetValue(shape, out data) && !string.IsNullOrEmpty(data))
{
var geometry = Geometry.Parse(shape.Data);
var geometry = Geometry.Parse(data);
dc.DrawGeometry(shape.IsClosed ? _geometryBrush : null, _geometryPen, geometry);
}
if (shape.Points == null)
return;
foreach (var point in shape.Points)
if (shape.Points != null)
{
dc.DrawEllipse(_pointBrush, null, new Point(point.X, point.Y), 4.0, 4.0);
foreach (var point in shape.Points)
{
dc.DrawEllipse(_pointBrush, null, new Point(point.X, point.Y), 4.0, 4.0);
}
}
}
}