ShapeSpatialData.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System;
  2. using System.ComponentModel;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using FastReport.Data;
  6. namespace FastReport.Map
  7. {
  8. /// <summary>
  9. /// Represents the spatial data of a shape.
  10. /// </summary>
  11. [TypeConverter(typeof(ShapeSpatialDataConverter))]
  12. public class ShapeSpatialData
  13. {
  14. #region Fields
  15. private Dictionary<string, string> dictionary;
  16. #endregion
  17. #region Public Methods
  18. internal string GetAsString()
  19. {
  20. StringBuilder result = new StringBuilder();
  21. foreach (KeyValuePair<string, string> keyValue in dictionary)
  22. {
  23. result.Append(keyValue.Key).Append("=").Append(keyValue.Value).Append("\r\n");
  24. }
  25. if (result.Length > 2)
  26. result.Remove(result.Length - 2, 2);
  27. return result.ToString();
  28. }
  29. internal void SetAsString(string value)
  30. {
  31. dictionary.Clear();
  32. if (String.IsNullOrEmpty(value))
  33. return;
  34. string[] lines = value.Split(new string[] { "\r\n" }, StringSplitOptions.None);
  35. foreach (string line in lines)
  36. {
  37. string[] keyValue = line.Split('=');
  38. if (keyValue != null && keyValue.Length == 2)
  39. dictionary.Add(keyValue[0], keyValue[1]);
  40. }
  41. }
  42. /// <summary>
  43. /// Copies contents from another spatial data object.
  44. /// </summary>
  45. /// <param name="src">The object to copy contents from.</param>
  46. public void Assign(ShapeSpatialData src)
  47. {
  48. SetAsString(src.GetAsString());
  49. }
  50. /// <summary>
  51. /// Compares two spatial data objects.
  52. /// </summary>
  53. /// <param name="src">The spatial object to compare with.</param>
  54. /// <returns><b>true</b> if spatial objects are identical.</returns>
  55. public bool IsEqual(ShapeSpatialData src)
  56. {
  57. if (src == null)
  58. return false;
  59. return GetAsString() == src.GetAsString();
  60. }
  61. /// <summary>
  62. /// Gets a value by its key.
  63. /// </summary>
  64. /// <param name="key">The key of value.</param>
  65. /// <returns>The value.</returns>
  66. public string GetValue(string key)
  67. {
  68. if (dictionary.ContainsKey(key))
  69. return dictionary[key];
  70. return "";
  71. }
  72. /// <summary>
  73. /// Sets a value by its key.
  74. /// </summary>
  75. /// <param name="key">The key of value.</param>
  76. /// <param name="value">The value.</param>
  77. public void SetValue(string key, string value)
  78. {
  79. dictionary[key] = value;
  80. }
  81. /// <summary>
  82. /// Gets a list of keys.
  83. /// </summary>
  84. /// <returns>The list of keys.</returns>
  85. public List<string> GetKeys()
  86. {
  87. List<string> result = new List<string>();
  88. foreach (string key in dictionary.Keys)
  89. {
  90. result.Add(key);
  91. }
  92. return result;
  93. }
  94. #endregion // Public Methods
  95. /// <summary>
  96. /// Creates a new instance of the <see cref="ShapeSpatialData"/> class.
  97. /// </summary>
  98. public ShapeSpatialData()
  99. {
  100. dictionary = new Dictionary<string, string>();
  101. }
  102. }
  103. }