From 1f1b62b49bc346c7c8905e6629c041f3ecac9325 Mon Sep 17 00:00:00 2001 From: FObermaier Date: Fri, 18 Apr 2014 21:56:25 +0200 Subject: [PATCH] Initial commit --- .gitignore | 4 + CategoryTheme.cs | 154 ++++++++++++++++++ CategoryThemeItem.cs | 104 ++++++++++++ CategoryThemeRangeItem.cs | 121 ++++++++++++++ CategoryThemeValuesItem.cs | 91 +++++++++++ ICategoryThemeItem.cs | 53 ++++++ Properties/AssemblyInfo.cs | 31 ++++ ...p.Rendering.Thematics.CategoryTheme.csproj | 104 ++++++++++++ packages.config | 12 ++ 9 files changed, 674 insertions(+) create mode 100644 .gitignore create mode 100644 CategoryTheme.cs create mode 100644 CategoryThemeItem.cs create mode 100644 CategoryThemeRangeItem.cs create mode 100644 CategoryThemeValuesItem.cs create mode 100644 ICategoryThemeItem.cs create mode 100644 Properties/AssemblyInfo.cs create mode 100644 SharpMap.Rendering.Thematics.CategoryTheme.csproj create mode 100644 packages.config diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8a1f245 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +bin +obj +/packages/* +*.suo \ No newline at end of file diff --git a/CategoryTheme.cs b/CategoryTheme.cs new file mode 100644 index 0000000..877f952 --- /dev/null +++ b/CategoryTheme.cs @@ -0,0 +1,154 @@ +// Copyright 2014 - Felix Obermaier (www.ivv-aachen.de) +// +// This file is part of SharpMap.Rendering.Thematics.CategoryTheme. +// SharpMap.Rendering.Decoration.Legend is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// SharpMap.Rendering.Thematics.CategoryTheme is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with SharpMap; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +using System; +using System.Collections.Generic; + +namespace SharpMap.Rendering.Thematics +{ + using System; + using System.Collections.Generic; + using System.ComponentModel; + using System.Diagnostics; + + using SharpMap.Data; + using SharpMap.Styles; + using SharpMap.Utilities; + /// + /// + [Serializable] + public class CategoryTheme : /*NotificationObject,*/ ITheme + where T: IComparable + { + private readonly List> _items = new List> (); + + private string _columnName; + + private bool _sorted; + + public bool UseDefaultStyleForDbNull; + + /// + /// The column name to get the value from + /// + public string ColumnName + { + get + { + return _columnName; + } + set + { + if (string.IsNullOrWhiteSpace(value)) + throw new ArgumentNullException("value"); + if (value.Equals(_columnName)) + return; + + _columnName = value; + //this.OnPropertyChanged("ColumnName"); + } + } + + private ICategoryThemeItem _default; + + /// + /// Gets or sets the default , used when the attribute value does not match the criteria + /// + public ICategoryThemeItem Default + { + get + { + return this._default; + } + set + { + this._default = value; + //this.OnPropertyChanged("Default"); + } + } + + /// + /// + /// + public void Add(ICategoryThemeItem cti) + { + _items.Add(cti); + _sorted = false; + //this.OnPropertyChanged("Items"); + } + + /// + /// + public void Clear() + { + _items.Clear(); + //this.OnPropertyChanged("Items"); + } + + /// + /// Method to evaluate the style + /// + public IStyle GetStyle(FeatureDataRow attribute) + { + Debug.Assert(!String.IsNullOrEmpty(_columnName)); + Debug.Assert(_default != null); + + if (attribute == null) + throw new ArgumentNullException("attribute", "The attribute row must not be null!"); + + // If the row has no value return the default style + if (attribute.IsNull(_columnName) && UseDefaultStyleForDbNull) return _default.Style; + + // Sort the list + if (!_sorted) + { + _items.Sort(); + _sorted = true; + } + + object val = attribute[_columnName]; + if (val is T) + { + var tval = (T)val; + try + { + var cti = _items.Find(c => c.Matches(tval)); + return cti.Style; + } + catch(ArgumentNullException) + { + } + //foreach (ICategoryThemeItem categoryThemeItem in _items) + //{ + // if (categoryThemeItem.Matches(tval)) return categoryThemeItem.Style; + //} + } + + return Default.Style; + } + + /// + /// Method to expose all s. + /// + /// + public System.Collections.ObjectModel.ReadOnlyCollection> ItemsAsReadOnly() + { + return _items.AsReadOnly(); + } + + } +} diff --git a/CategoryThemeItem.cs b/CategoryThemeItem.cs new file mode 100644 index 0000000..d6704d4 --- /dev/null +++ b/CategoryThemeItem.cs @@ -0,0 +1,104 @@ +// Copyright 2014 - Felix Obermaier (www.ivv-aachen.de) +// +// This file is part of SharpMap.Rendering.Thematics.CategoryTheme. +// SharpMap.Rendering.Decoration.Legend is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// SharpMap.Rendering.Thematics.CategoryTheme is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with SharpMap; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; + +using SharpMap.Data; +using SharpMap.Styles; +using SharpMap.Utilities; +namespace SharpMap.Rendering.Thematics +{ + + /// + /// Abstract base class for + /// + /// + [Serializable] + public abstract class CategoryThemeItem : ICategoryThemeItem + where T : IComparable + { + private string _title; + private IStyle _style; + + + /// + /// Compares the current object with another of type . + /// + /// + /// A value, that indicates the relative order of the compared objects. The value has the following meaning: + /// + /// < 0This object is less than the . + /// 0The object is equal + /// >This object is greater than the . + /// + /// Wert Bedeutung Kleiner als 0 (null) Dieses Objekt ist kleiner als der -Parameter.Zero Dieses Objekt ist gleich . Größer als 0 (null) Dieses Objekt ist größer als . + /// + /// An Object of type that should be compared with this item. + public abstract int CompareTo(ICategoryThemeItem other); + + /// + /// Evaluate that matches this + /// + /// The value to test. + /// true, if + public abstract bool Matches(T value); + + /// + /// Gets or sets the title for this + /// + public string Title + { + get + { + return this._title ?? this.ToString(); + } + set + { + if (value.Equals(_title)) + return; + this._title = value; + //this.OnPropertyChanged("Title"); + } + } + + /// + /// Gets or sets the for this + /// + public IStyle Style + { + get + { + return this._style; + } + set + { + if (value == null) + throw new ArgumentNullException("value"); + + if (value.Equals(_style)) + return; + + this._style = value; + //this.OnPropertyChanged("Style"); + } + } + + } +} diff --git a/CategoryThemeRangeItem.cs b/CategoryThemeRangeItem.cs new file mode 100644 index 0000000..07ca37d --- /dev/null +++ b/CategoryThemeRangeItem.cs @@ -0,0 +1,121 @@ +// Copyright 2014 - Felix Obermaier (www.ivv-aachen.de) +// +// This file is part of SharpMap.Rendering.Thematics.CategoryTheme. +// SharpMap.Rendering.Decoration.Legend is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// SharpMap.Rendering.Thematics.CategoryTheme is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with SharpMap; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; + +using SharpMap.Data; +using SharpMap.Styles; +using SharpMap.Utilities; + +namespace SharpMap.Rendering.Thematics +{ + /// + /// Implementation that + /// + /// + [Serializable] + public class CategoryThemeRangeItem : CategoryThemeItem + where T : IComparable + { + private T _lowerBound; + private T _upperBound; + + /// + /// Gets or sets the lower bound for this + /// + public T LowerBound + { + get + { + return this._lowerBound; + } + set + { + if (_lowerBound.CompareTo(value) == 0) + return; + this._lowerBound = value; + //this.OnPropertyChanged("LowerBound"); + } + } + + + /// + /// Gets or sets the upper bound for this + /// + public T UpperBound + { + get + { + return this._upperBound; + } + set + { + if (_upperBound.CompareTo(value) == 0) + return; + this._upperBound = value; + //this.OnPropertyChanged("UpperBound"); + } + } + + /// + /// Compares the current object with another of type . + /// + /// + /// A value, that indicates the relative order of the compared objects. The value has the following meaning: + /// + /// < 0This object is less than the . + /// 0The object is equal + /// >This object is greater than the . + /// + /// + /// An Object of type that should be compared with this item. + public override int CompareTo(ICategoryThemeItem other) + { + var o = other as CategoryThemeRangeItem; + if (o == null) return -1; + + if (this.Matches(o.LowerBound)) return 0; + if (this.Matches(o.UpperBound)) return 0; + + return _lowerBound.CompareTo(o.LowerBound); + } + + + /// + /// Evaluate that matches this + /// + /// + /// matches if it is in the range [LowerBound, UpperBound[ + /// + /// The value to test. + /// true, if matches. + public override bool Matches(T value) + { + if (_lowerBound.CompareTo(value) < 0) return false; + if (_upperBound.CompareTo(value) >= 0) return false; + return true; + } + + public override string ToString() + { + return string.Format("{0} - {1}", _lowerBound, _upperBound); + } + } +} diff --git a/CategoryThemeValuesItem.cs b/CategoryThemeValuesItem.cs new file mode 100644 index 0000000..ebd1278 --- /dev/null +++ b/CategoryThemeValuesItem.cs @@ -0,0 +1,91 @@ +// Copyright 2014 - Felix Obermaier (www.ivv-aachen.de) +// +// This file is part of SharpMap.Rendering.Thematics.CategoryTheme. +// SharpMap.Rendering.Decoration.Legend is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// SharpMap.Rendering.Thematics.CategoryTheme is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with SharpMap; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; + +using SharpMap.Data; +using SharpMap.Styles; +using SharpMap.Utilities; + +namespace SharpMap.Rendering.Thematics +{ + + /// + /// A + /// + ///The type of the values + [Serializable] + public class CategoryThemeValuesItem: CategoryThemeItem + where T: IComparable + { + private List _values; + + /// + /// Gets or sets the + /// + public List Values + { + get + { + return this._values; + } + set + { + this._values = value; + //this.OnPropertyChanged("Values"); + _values.Sort(); + } + } + + /// + /// Compares the current object with another of type . + /// + /// + /// A value, that indicates the relative order of the compared objects. The value has the following meaning: + /// + /// < 0This object is less than the . + /// 0The object is equal + /// >This object is greater than the . + /// + /// + /// An Object of type that should be compared with this item. + public override int CompareTo(ICategoryThemeItem other) + { + //This does not have a specific order to it + return 0; + } + + /// + /// Evaluate that matches this + /// + /// The value to test. + /// true, if + public override bool Matches(T value) + { + return (_values.Contains(value)); + } + + public override string ToString() + { + return string.Join(",", _values.ToArray()); + } + + } +} diff --git a/ICategoryThemeItem.cs b/ICategoryThemeItem.cs new file mode 100644 index 0000000..3ccc073 --- /dev/null +++ b/ICategoryThemeItem.cs @@ -0,0 +1,53 @@ +// Copyright 2014 - Felix Obermaier (www.ivv-aachen.de) +// +// This file is part of SharpMap.Rendering.Thematics.CategoryTheme. +// SharpMap.Rendering.Decoration.Legend is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// SharpMap.Rendering.Thematics.CategoryTheme is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with SharpMap; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; + +using SharpMap.Data; +using SharpMap.Styles; +using SharpMap.Utilities; + +namespace SharpMap.Rendering.Thematics +{ + /// + /// Interface for an item in a . + /// + ///The Type of the value to compare + public interface ICategoryThemeItem : IComparable> + where T: IComparable + { + /// + /// Evaluate that matches this + /// + /// The value to test. + /// true, if + bool Matches(T value); + + /// + /// Gets the title for this + /// + string Title { get; } + + /// + /// Gets the style applicable for this item + /// + IStyle Style { get; } + } +} diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..89aaf04 --- /dev/null +++ b/Properties/AssemblyInfo.cs @@ -0,0 +1,31 @@ +#region Using directives + +using System; +using System.Reflection; +using System.Runtime.InteropServices; + +#endregion + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("SharpMap.Rendering.Thematics.CategoryTheme")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SharpMap.Rendering.Thematics.CategoryTheme")] +[assembly: AssemblyCopyright("Copyright 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// This sets the default COM visibility of types in the assembly to invisible. +// If you need to expose a type to COM, use [ComVisible(true)] on that type. +[assembly: ComVisible(false)] + +// The assembly version has following format : +// +// Major.Minor.Build.Revision +// +// You can specify all the values or you can use the default the Revision and +// Build Numbers by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.*")] diff --git a/SharpMap.Rendering.Thematics.CategoryTheme.csproj b/SharpMap.Rendering.Thematics.CategoryTheme.csproj new file mode 100644 index 0000000..57de210 --- /dev/null +++ b/SharpMap.Rendering.Thematics.CategoryTheme.csproj @@ -0,0 +1,104 @@ + + + + {565E0DA8-F456-486E-96B6-19C1C273295D} + Debug + AnyCPU + Library + SharpMap.Rendering.Thematics.CategoryTheme + SharpMap.Rendering.Thematics.CategoryTheme + v4.0 + Properties + + + AnyCPU + + + bin\Debug\ + True + Full + False + True + DEBUG;TRACE + + + bin\Release\ + False + None + True + False + TRACE + + + + ..\SharpMap.Rendering.Decorations.Legend\packages\BruTile.0.7.4.4\lib\net40\BruTile.dll + + + ..\SharpMap.Rendering.Decorations.Legend\packages\BruTile.0.7.4.4\lib\net40\BruTile.Desktop.dll + + + ..\SharpMap.Rendering.Decorations.Legend\packages\BruTile.0.7.4.4\lib\net40\BruTile.MbTiles.dll + + + ..\SharpMap.Rendering.Decorations.Legend\packages\BruTile.0.7.4.4\lib\net40\BruTile.Serialization.dll + + + ..\SharpMap.Rendering.Decorations.Legend\packages\Common.Logging.2.0.0\lib\2.0\Common.Logging.dll + + + ..\SharpMap.Rendering.Decorations.Legend\packages\GeoAPI.1.7.2\lib\net40-client\GeoAPI.dll + + + ..\SharpMap.Rendering.Decorations.Legend\packages\NetTopologySuite.1.13.2\lib\net40-client\NetTopologySuite.dll + + + ..\SharpMap.Rendering.Decorations.Legend\packages\NetTopologySuite.IO.1.13.2\lib\net40-client\NetTopologySuite.IO.GeoTools.dll + + + ..\SharpMap.Rendering.Decorations.Legend\packages\NetTopologySuite.IO.1.13.2\lib\net40-client\NetTopologySuite.IO.MsSqlSpatial.dll + + + ..\SharpMap.Rendering.Decorations.Legend\packages\NetTopologySuite.IO.1.13.2\lib\net40-client\NetTopologySuite.IO.PostGis.dll + + + ..\SharpMap.Rendering.Decorations.Legend\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll + + + ..\SharpMap.Rendering.Decorations.Legend\packages\NetTopologySuite.1.13.2\lib\net40-client\PowerCollections.dll + + + ..\SharpMap.Rendering.Decorations.Legend\packages\ProjNET4GeoAPI.1.3.0.3\lib\net40-client\ProjNet.dll + + + ..\SharpMap.Rendering.Decorations.Legend\packages\SharpMap.1.1.0\lib\net40-client\SharpMap.dll + + + + 3.5 + + + + ..\SharpMap.Rendering.Decorations.Legend\packages\System.Data.SQLite.MSIL.1.0.86.0\lib\net40\System.Data.SQLite.dll + + + ..\SharpMap.Rendering.Decorations.Legend\packages\System.Data.SQLite.MSIL.1.0.86.0\lib\net40\System.Data.SQLite.Linq.dll + + + + + 3.5 + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages.config b/packages.config new file mode 100644 index 0000000..63d059c --- /dev/null +++ b/packages.config @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file