[longomatch] Add support for coordinates subcategories



commit 664695cd2f68ff016ff1ae6eeaaa63160cefe599
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Fri Jan 25 13:33:40 2013 +0100

    Add support for coordinates subcategories

 LongoMatch.Core/Common/Coordinates.cs              |   58 ++++++++++++++++++++
 LongoMatch.Core/Common/Image.cs                    |    1 +
 LongoMatch.Core/Interfaces/ITemplatesService.cs    |    2 +
 LongoMatch.Core/LongoMatch.Core.mdp                |    1 +
 LongoMatch.Core/Makefile.am                        |    1 +
 LongoMatch.Core/Store/Play.cs                      |    5 ++
 LongoMatch.Core/Store/SubCategory.cs               |   17 ++++++
 LongoMatch.Core/Store/Tag.cs                       |   19 +++++++
 LongoMatch.Core/Store/TagStore.cs                  |    3 +
 .../Store/Templates/CategoriesTemplate.cs          |    5 ++
 LongoMatch.GUI/Gui/Component/CategoryProperties.cs |   12 ++++-
 LongoMatch.GUI/Gui/Dialog/TemplatesManager.cs      |    8 +++-
 LongoMatch.Services/Services/TemplatesService.cs   |   22 ++++++++
 13 files changed, 151 insertions(+), 3 deletions(-)
---
diff --git a/LongoMatch.Core/Common/Coordinates.cs b/LongoMatch.Core/Common/Coordinates.cs
new file mode 100644
index 0000000..85d2b34
--- /dev/null
+++ b/LongoMatch.Core/Common/Coordinates.cs
@@ -0,0 +1,58 @@
+// 
+//  Copyright (C) 2013 Andoni Morales Alastruey
+// 
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+// 
+//  This program 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 General Public License for more details.
+//  
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+// 
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+
+namespace LongoMatch.Common
+{
+	public class Coordinates: List<Point>
+	{
+		public Coordinates ()
+		{
+		}
+		
+		public override bool Equals (object obj)
+		{
+			Coordinates c = obj as Coordinates;
+            if (c == null)
+				return false;
+				
+			if (c.Count != Count)
+				return false;
+			
+			for (int i=0; i<Count; i++) {
+				if (c[i].X != this[i].X || c[i].Y != this[i].X)
+					return false;
+			}
+			return true;
+		}
+		
+		public override int GetHashCode ()
+		{
+			string s = "";
+			
+			for (int i=0; i<Count; i++) {
+				s += this[i].X.ToString() +  this[i].Y.ToString();
+			}
+			
+			return int.Parse(s);
+		}
+	}
+}
+
diff --git a/LongoMatch.Core/Common/Image.cs b/LongoMatch.Core/Common/Image.cs
index 940cfca..9b993ed 100644
--- a/LongoMatch.Core/Common/Image.cs
+++ b/LongoMatch.Core/Common/Image.cs
@@ -27,6 +27,7 @@ namespace LongoMatch.Common
 	using SImage = System.Drawing.Image;
 #endif
 
+	[Serializable]
 	public class Image
 	{
 		SImage image;
diff --git a/LongoMatch.Core/Interfaces/ITemplatesService.cs b/LongoMatch.Core/Interfaces/ITemplatesService.cs
index 0dbf170..d812e73 100644
--- a/LongoMatch.Core/Interfaces/ITemplatesService.cs
+++ b/LongoMatch.Core/Interfaces/ITemplatesService.cs
@@ -35,6 +35,8 @@ namespace LongoMatch.Interfaces
 		List<PlayerSubCategory> PlayerSubcategories {get;}
 		
 		List<TeamSubCategory> TeamSubcategories {get;}
+		
+		List<CoordinatesSubCategory> CoordinatesSubcategories {get;}
 	}
 }
 
diff --git a/LongoMatch.Core/LongoMatch.Core.mdp b/LongoMatch.Core/LongoMatch.Core.mdp
index 0a7ed3b..0c4e5ba 100644
--- a/LongoMatch.Core/LongoMatch.Core.mdp
+++ b/LongoMatch.Core/LongoMatch.Core.mdp
@@ -100,6 +100,7 @@
     <File subtype="Code" buildaction="Compile" name="Stats/GameUnitsStats.cs" />
     <File subtype="Code" buildaction="Compile" name="Common/PlaysFilter.cs" />
     <File subtype="Code" buildaction="Compile" name="Interfaces/Multimedia/IRemuxer.cs" />
+    <File subtype="Code" buildaction="Compile" name="Common/Coordinates.cs" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
diff --git a/LongoMatch.Core/Makefile.am b/LongoMatch.Core/Makefile.am
index 97b0573..c7b0a1c 100644
--- a/LongoMatch.Core/Makefile.am
+++ b/LongoMatch.Core/Makefile.am
@@ -9,6 +9,7 @@ SOURCES = \
 	Common/Color.cs \
 	Common/ConsoleCrayon.cs \
 	Common/Constants.cs \
+	Common/Coordinates.cs \
 	Common/Device.cs \
 	Common/EncodingProfiles.cs \
 	Common/EncodingSettings.cs \
diff --git a/LongoMatch.Core/Store/Play.cs b/LongoMatch.Core/Store/Play.cs
index 60c1f3b..e8eae1d 100644
--- a/LongoMatch.Core/Store/Play.cs
+++ b/LongoMatch.Core/Store/Play.cs
@@ -187,6 +187,11 @@ namespace LongoMatch.Store
 			set;
 		}
 		
+		public CoordinatesTagStore Coordinates {
+			get;
+			set;
+		}
+		
 		#endregion
 
 		#region Public methods
diff --git a/LongoMatch.Core/Store/SubCategory.cs b/LongoMatch.Core/Store/SubCategory.cs
index b9f6dce..97443ce 100644
--- a/LongoMatch.Core/Store/SubCategory.cs
+++ b/LongoMatch.Core/Store/SubCategory.cs
@@ -164,4 +164,21 @@ namespace LongoMatch.Store
 			return RenderDesc(Catalog.GetString("Team selection"), "");
 		}
 	}
+	
+	/// <summary>
+	/// SubCategory to tag locations or trajectories in the game field
+	/// </summary>
+	[Serializable]
+	public class CoordinatesSubCategory: SubCategory<Coordinates> {
+	
+		/* Use 1 for locations or 2 for trajectories */
+		public int NumCoordinates {
+			get;
+			set;
+		}
+		
+		public override string ToMarkupString(){
+			return RenderDesc(Catalog.GetString("Coordinates"), "");
+		}
+	}
 }
\ No newline at end of file
diff --git a/LongoMatch.Core/Store/Tag.cs b/LongoMatch.Core/Store/Tag.cs
index e066f23..0f87028 100644
--- a/LongoMatch.Core/Store/Tag.cs
+++ b/LongoMatch.Core/Store/Tag.cs
@@ -100,4 +100,23 @@ namespace LongoMatch.Store
 			return Value.GetHashCode ();
 		}
 	}
+	
+	[Serializable]
+	public class CoordinatesTag: Tag<Coordinates>
+	{
+		public CoordinatesTag() {}
+		
+		public override bool Equals (object obj)
+		{
+			CoordinatesTag tag = obj as CoordinatesTag;
+            if (tag == null)
+				return false;
+			return Value.Equals (tag.Value) && SubCategory.Equals(tag.SubCategory);
+		}
+		
+		public override int GetHashCode ()
+		{
+			return Value.GetHashCode ();
+		}
+	}
 }
diff --git a/LongoMatch.Core/Store/TagStore.cs b/LongoMatch.Core/Store/TagStore.cs
index c4edf0e..e736baa 100644
--- a/LongoMatch.Core/Store/TagStore.cs
+++ b/LongoMatch.Core/Store/TagStore.cs
@@ -98,5 +98,8 @@ namespace LongoMatch.Store
 	
 	[Serializable]
 	public class TeamsTagStore: TagsStore<TeamTag, Team> {}
+	
+	[Serializable]
+	public class CoordinatesTagStore: TagsStore<CoordinatesTag, Coordinates> {}
 }
 
diff --git a/LongoMatch.Core/Store/Templates/CategoriesTemplate.cs b/LongoMatch.Core/Store/Templates/CategoriesTemplate.cs
index 0ded69c..30a4bab 100644
--- a/LongoMatch.Core/Store/Templates/CategoriesTemplate.cs
+++ b/LongoMatch.Core/Store/Templates/CategoriesTemplate.cs
@@ -66,6 +66,11 @@ namespace LongoMatch.Store.Templates
 			}
 		}
 		
+		public LongoMatch.Common.Image FieldBackgroundImage {
+			get;
+			set;
+		}
+		
 		public void Save(string filePath) {
 			SerializableObject.Save(this, filePath);
 		}
diff --git a/LongoMatch.GUI/Gui/Component/CategoryProperties.cs b/LongoMatch.GUI/Gui/Component/CategoryProperties.cs
index 081e23e..f7b4a98 100644
--- a/LongoMatch.GUI/Gui/Component/CategoryProperties.cs
+++ b/LongoMatch.GUI/Gui/Component/CategoryProperties.cs
@@ -65,10 +65,11 @@ namespace LongoMatch.Gui.Component
 		
 		public void LoadSubcategories(ITemplatesService ts) {
 			subcategoriesProvider = ts.SubCategoriesTemplateProvider;
-			LoadSubcategories(ts.PlayerSubcategories);
+			LoadSubcategories(ts.PlayerSubcategories, ts.CoordinatesSubcategories);
 		}
 		
-		private void LoadSubcategories(List<PlayerSubCategory> playerSubcategories) {
+		private void LoadSubcategories(List<PlayerSubCategory> playerSubcategories,
+		                               List<CoordinatesSubCategory> coordinatesSubcategories) {
 			model = new ListStore(typeof(string), typeof(ISubCategory));
 			
 			model.AppendValues(Catalog.GetString("Create new..."), "");
@@ -86,6 +87,13 @@ namespace LongoMatch.Gui.Component
 				                                 subcat.Name),
 				                   subcat);
 			}
+			foreach (CoordinatesSubCategory subcat in coordinatesSubcategories) {
+				Log.Debug("Adding coordinates subcategory: ", subcat.Name);
+				model.AppendValues(String.Format("[{0}] {1}", 
+				                                 Catalog.GetString("Coordinates"),
+				                                 subcat.Name),
+				                   subcat);
+			}
 			
 			subcatcombobox.Model = model;
 			var cell = new CellRendererText();
diff --git a/LongoMatch.GUI/Gui/Dialog/TemplatesManager.cs b/LongoMatch.GUI/Gui/Dialog/TemplatesManager.cs
index c766e29..63a622b 100644
--- a/LongoMatch.GUI/Gui/Dialog/TemplatesManager.cs
+++ b/LongoMatch.GUI/Gui/Dialog/TemplatesManager.cs
@@ -131,7 +131,13 @@ namespace LongoMatch.Gui.Dialog
 		}
 		
 		private void UpdateSelectedTemplate() {
-			templatesWidget.Template = templatesProvider.Load(templateName); 
+			try {
+				templatesWidget.Template = templatesProvider.Load(templateName); 
+			} catch (Exception e) {
+				Log.Exception (e);
+				MessagePopup.PopupMessage(this.Toplevel, Gtk.MessageType.Error,
+				                          "Error loading template");
+			}
 		}
 		
 		private void SaveTemplate() {
diff --git a/LongoMatch.Services/Services/TemplatesService.cs b/LongoMatch.Services/Services/TemplatesService.cs
index 4a223b9..b05027a 100644
--- a/LongoMatch.Services/Services/TemplatesService.cs
+++ b/LongoMatch.Services/Services/TemplatesService.cs
@@ -35,6 +35,7 @@ namespace LongoMatch.Services
 		private Dictionary<Type, ITemplateProvider> dict;
 		private List<PlayerSubCategory> playerSubcatList;
 		private List<TeamSubCategory> teamSubcatList;
+		private List<CoordinatesSubCategory> coordinatesSubcatList;
 		
 		public TemplatesService (string basePath)
 		{
@@ -45,6 +46,7 @@ namespace LongoMatch.Services
 			CheckDefaultTemplates();
 			CreateDefaultPlayerSubCategories();
 			CreateDefaultTeamSubCategories();
+			CreateDefaultCoordinatesSubCategories();
 			
 		}
 		
@@ -76,6 +78,20 @@ namespace LongoMatch.Services
 			subcat.Add(Team.VISITOR);
 			playerSubcatList.Add(subcat);
 		}
+		
+		private void CreateDefaultCoordinatesSubCategories () {
+			CoordinatesSubCategory subcat;
+			
+			coordinatesSubcatList = new List<CoordinatesSubCategory>();
+			
+			/* Position */
+			subcat = new CoordinatesSubCategory {Name=Catalog.GetString("Position"), FastTag=true, NumCoordinates=1};
+			coordinatesSubcatList.Add(subcat);
+
+			/* Trajectory */
+			subcat = new CoordinatesSubCategory {Name=Catalog.GetString("Trajectory"), FastTag=true, NumCoordinates=2};
+			coordinatesSubcatList.Add(subcat);
+		}
 
 		private void CreateDefaultTeamSubCategories () {
 			teamSubcatList = new List<TeamSubCategory>();
@@ -117,6 +133,12 @@ namespace LongoMatch.Services
 				return teamSubcatList;
 			}
 		}
+		
+		public List<CoordinatesSubCategory> CoordinatesSubcategories {
+			get{
+				return coordinatesSubcatList;
+			}
+		}
 	}
 	
 	public class TemplatesProvider<T, U>: ITemplateProvider<T, U> where T: ITemplate<U>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]