using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Text;
using FastReport.Data;
namespace FastReport.Map
{
///
/// Represents the spatial data of a shape.
///
[TypeConverter(typeof(ShapeSpatialDataConverter))]
public class ShapeSpatialData
{
#region Fields
private Dictionary dictionary;
#endregion
#region Public Methods
internal string GetAsString()
{
StringBuilder result = new StringBuilder();
foreach (KeyValuePair keyValue in dictionary)
{
result.Append(keyValue.Key).Append("=").Append(keyValue.Value).Append("\r\n");
}
if (result.Length > 2)
result.Remove(result.Length - 2, 2);
return result.ToString();
}
internal void SetAsString(string value)
{
dictionary.Clear();
if (String.IsNullOrEmpty(value))
return;
string[] lines = value.Split(new string[] { "\r\n" }, StringSplitOptions.None);
foreach (string line in lines)
{
string[] keyValue = line.Split('=');
if (keyValue != null && keyValue.Length == 2)
dictionary.Add(keyValue[0], keyValue[1]);
}
}
///
/// Copies contents from another spatial data object.
///
/// The object to copy contents from.
public void Assign(ShapeSpatialData src)
{
SetAsString(src.GetAsString());
}
///
/// Compares two spatial data objects.
///
/// The spatial object to compare with.
/// true if spatial objects are identical.
public bool IsEqual(ShapeSpatialData src)
{
if (src == null)
return false;
return GetAsString() == src.GetAsString();
}
///
/// Gets a value by its key.
///
/// The key of value.
/// The value.
public string GetValue(string key)
{
if (dictionary.ContainsKey(key))
return dictionary[key];
return "";
}
///
/// Sets a value by its key.
///
/// The key of value.
/// The value.
public void SetValue(string key, string value)
{
dictionary[key] = value;
}
///
/// Gets a list of keys.
///
/// The list of keys.
public List GetKeys()
{
List result = new List();
foreach (string key in dictionary.Keys)
{
result.Add(key);
}
return result;
}
#endregion // Public Methods
///
/// Creates a new instance of the class.
///
public ShapeSpatialData()
{
dictionary = new Dictionary();
}
}
}