[longomatch] Make filters work again



commit 73778e4bbbe57223640a0d7c75ae3f007e175ab8
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Sun Sep 7 16:37:30 2014 +0200

    Make filters work again

 LongoMatch.Core/Common/EventsFilter.cs             |    7 ++++-
 LongoMatch.Drawing/CanvasObjects/CategoryLabel.cs  |   13 ++------
 LongoMatch.Drawing/CanvasObjects/TimelineObject.cs |   30 ++++++++++++++++---
 LongoMatch.Drawing/Utils.cs                        |   19 ++++++++++--
 LongoMatch.Drawing/Widgets/CategoriesLabels.cs     |    4 +--
 LongoMatch.Drawing/Widgets/PlaysTimeline.cs        |   15 +--------
 LongoMatch.Drawing/Widgets/PositionTagger.cs       |   25 ++++++++++++++++
 LongoMatch.GUI/Gui/Component/CodingWidget.cs       |    2 +-
 .../Gui/Component/PlaysPositionViewer.cs           |    6 +++-
 LongoMatch.GUI/Gui/MainWindow.cs                   |    2 +-
 LongoMatch.GUI/Gui/Panel/NewProjectPanel.cs        |    2 +-
 .../Gui/TreeView/CategoriesFilterTreeView.cs       |    9 ++++--
 LongoMatch.GUI/Gui/TreeView/ListTreeViewBase.cs    |    2 +-
 .../Gui/TreeView/PlayersFilterTreeView.cs          |    6 ++-
 LongoMatch.GUI/gtk-gui/objects.xml                 |    8 ++++-
 LongoMatch.Services/Services/ProjectsManager.cs    |    3 --
 16 files changed, 103 insertions(+), 50 deletions(-)
---
diff --git a/LongoMatch.Core/Common/EventsFilter.cs b/LongoMatch.Core/Common/EventsFilter.cs
index 051f83f..9961fac 100644
--- a/LongoMatch.Core/Common/EventsFilter.cs
+++ b/LongoMatch.Core/Common/EventsFilter.cs
@@ -42,6 +42,11 @@ namespace LongoMatch.Core.Common
                        UpdateFilters();
                }
                
+               public bool Silent {
+                       set;
+                       get;
+               }
+
                public List<EventType> VisibleEventTypes {
                        get;
                        protected set;
@@ -183,7 +188,7 @@ namespace LongoMatch.Core.Common
                }
                
                void EmitFilterUpdated () {
-                       if (FilterUpdated != null)
+                       if (!Silent && FilterUpdated != null)
                                FilterUpdated ();
                }
        }
diff --git a/LongoMatch.Drawing/CanvasObjects/CategoryLabel.cs 
b/LongoMatch.Drawing/CanvasObjects/CategoryLabel.cs
index 0634e3a..5c664cf 100644
--- a/LongoMatch.Drawing/CanvasObjects/CategoryLabel.cs
+++ b/LongoMatch.Drawing/CanvasObjects/CategoryLabel.cs
@@ -45,7 +45,7 @@ namespace LongoMatch.Drawing.CanvasObjects
                        set;
                }
 
-               public bool Even {
+               public Color BackgroundColor {
                        get;
                        set;
                }
@@ -57,16 +57,9 @@ namespace LongoMatch.Drawing.CanvasObjects
 
                public override void Draw (IDrawingToolkit tk, Area area)
                {
-                       Color color;
                        double hs, vs, to, rectSize;
                        double y;
                        
-                       if (Even) {
-                               color = Config.Style.PaletteBackground;
-                       } else {
-                               color = Config.Style.PaletteBackgroundLight;
-                       }
-                       
                        hs = StyleConf.TimelineLabelHSpacing;
                        vs = StyleConf.TimelineLabelVSpacing;
                        rectSize = Height - vs * 2;
@@ -74,8 +67,8 @@ namespace LongoMatch.Drawing.CanvasObjects
                        
                        y = OffsetY - Math.Floor (Scroll);
                        tk.Begin ();
-                       tk.FillColor = color;
-                       tk.StrokeColor = color;
+                       tk.FillColor = BackgroundColor;
+                       tk.StrokeColor = BackgroundColor;
                        tk.LineWidth = 0;
                        tk.DrawRectangle (new Point (0, y), width, Height);
                        
diff --git a/LongoMatch.Drawing/CanvasObjects/TimelineObject.cs 
b/LongoMatch.Drawing/CanvasObjects/TimelineObject.cs
index a56388b..0cbb523 100644
--- a/LongoMatch.Drawing/CanvasObjects/TimelineObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/TimelineObject.cs
@@ -28,7 +28,6 @@ namespace LongoMatch.Drawing.CanvasObjects
 {
        public abstract class TimelineObject: CanvasObject, ICanvasSelectableObject
        {
-               Color background;
                List<TimeNodeObject> nodes;
                double secondsPerPixel;
                protected Time maxTime;
@@ -36,7 +35,7 @@ namespace LongoMatch.Drawing.CanvasObjects
 
                public TimelineObject (Time maxTime, double offsetY, Color background)
                {
-                       this.background = background;
+                       this.BackgroundColor = background;
                        this.nodes = new List<TimeNodeObject> ();
                        this.maxTime = maxTime;
                        selectionBorderL = LoadBorder (StyleConf.TimelineSelectionLeft);
@@ -70,6 +69,11 @@ namespace LongoMatch.Drawing.CanvasObjects
                        }
                }
 
+               public Color BackgroundColor {
+                       get;
+                       set;
+               }
+
                public Time CurrentTime {
                        set;
                        protected get;
@@ -101,10 +105,15 @@ namespace LongoMatch.Drawing.CanvasObjects
                        nodes.RemoveAll (po => po.TimeNode == node);
                }
                
+               protected virtual bool TimeNodeObjectIsVisible (TimeNodeObject tn)
+               {
+                       return true;
+               }
+               
                protected virtual void DrawBackground (IDrawingToolkit tk, Area area)
                {
-                       tk.FillColor = background;
-                       tk.StrokeColor = background;
+                       tk.FillColor = BackgroundColor;
+                       tk.StrokeColor = BackgroundColor;
                        tk.LineWidth = 0;
                        
                        tk.DrawRectangle (new Point (area.Start.X, OffsetY), area.Width, Height);
@@ -120,13 +129,17 @@ namespace LongoMatch.Drawing.CanvasObjects
                        tk.Begin ();
                        DrawBackground (tk, area);
                        foreach (TimeNodeObject p in nodes) {
+                               if (!TimeNodeObjectIsVisible (p))
+                                       continue;
                                if (p.Selected) {
                                        selected.Add (p);
                                        continue;
                                }
+                               p.OffsetY = OffsetY;
                                p.Draw (tk, area);
                        }
                        foreach (TimeNodeObject p in selected) {
+                               p.OffsetY = OffsetY;
                                p.Draw (tk, area);
                        }
 
@@ -178,15 +191,22 @@ namespace LongoMatch.Drawing.CanvasObjects
 
        public class CategoryTimeline: TimelineObject
        {
+               EventsFilter filter;
 
-               public CategoryTimeline (List<TimelineEvent> plays, Time maxTime, double offsetY, Color 
background):
+               public CategoryTimeline (List<TimelineEvent> plays, Time maxTime, double offsetY, Color 
background, EventsFilter filter):
                        base (maxTime, offsetY, background)
                {
+                       this.filter = filter;
                        foreach (TimelineEvent p in plays) {
                                AddPlay (p);
                        }
                }
 
+               protected override bool TimeNodeObjectIsVisible (TimeNodeObject tn)
+               {
+                       return filter.IsVisible ((tn as PlayObject).Play);
+               }
+
                public void AddPlay (TimelineEvent play)
                {
                        PlayObject po = new PlayObject (play);
diff --git a/LongoMatch.Drawing/Utils.cs b/LongoMatch.Drawing/Utils.cs
index 47a93d8..caee032 100644
--- a/LongoMatch.Drawing/Utils.cs
+++ b/LongoMatch.Drawing/Utils.cs
@@ -27,6 +27,19 @@ namespace LongoMatch.Drawing
 {
        public class Utils
        {
+       
+               public static Color ColorForRow (int row)
+               {
+                       Color c;
+
+                       if (row % 2 == 0) {
+                               c = Config.Style.PaletteBackground;
+                       } else {
+                               c = Config.Style.PaletteBackgroundLight;
+                       }
+                       return c;
+               }
+
                public static double Round (double n, int multiple)
                {
                        if (n % multiple > multiple / 2) {
@@ -84,17 +97,17 @@ namespace LongoMatch.Drawing
                        surface.Dispose ();
                        return img;
                }
-               
+
                public static Image RenderFrameDrawing (IDrawingToolkit tk, int width, int height, 
FrameDrawing fd)
                {
                        return RenderFrameDrawing (tk, width, height, fd, null);
                }
-               
+
                public static Image RenderFrameDrawingToImage (IDrawingToolkit tk, Image image, FrameDrawing 
fd)
                {
                        return RenderFrameDrawing (tk, image.Width, image.Height, fd, image);
                }
-               
+
                public static Point ToUserCoords (Point p, Point offset, double scaleX, double scaleY)
                {
                        return new Point ((p.X - offset.X) / scaleX,
diff --git a/LongoMatch.Drawing/Widgets/CategoriesLabels.cs b/LongoMatch.Drawing/Widgets/CategoriesLabels.cs
index 5eefcbf..6f2f381 100644
--- a/LongoMatch.Drawing/Widgets/CategoriesLabels.cs
+++ b/LongoMatch.Drawing/Widgets/CategoriesLabels.cs
@@ -84,9 +84,7 @@ namespace LongoMatch.Drawing.Widgets
                                if (filter.VisibleEventTypes.Contains (type)) {
                                        label.OffsetY = i * label.Height;
                                        label.Visible = true;
-                                       if (i % 2 == 0) {
-                                               label.Even = true;
-                                       }
+                                       label.BackgroundColor = Utils.ColorForRow (i);
                                        i++;
                                } else {
                                        label.Visible = false;
diff --git a/LongoMatch.Drawing/Widgets/PlaysTimeline.cs b/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
index db706a5..aae6b4f 100644
--- a/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
+++ b/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
@@ -110,18 +110,6 @@ namespace LongoMatch.Drawing.Widgets
                        }
                }
 
-               Color ColorForRow (int row)
-               {
-                       Color c;
-
-                       if (row % 2 == 0) {
-                               c = Config.Style.PaletteBackground;
-                       } else {
-                               c = Config.Style.PaletteBackgroundLight;
-                       }
-                       return c;
-               }
-
                void FillCanvas ()
                {
                        CategoryTimeline tl;
@@ -130,7 +118,7 @@ namespace LongoMatch.Drawing.Widgets
                        foreach (EventType type in project.EventTypes) {
                                tl = new CategoryTimeline (project.EventsByType (type), duration,
                                                           i * StyleConf.TimelineCategoryHeight,
-                                                          ColorForRow (i));
+                                                          Utils.ColorForRow (i), playsFilter);
                                eventsTimelines [type] = tl;
                                Objects.Add (tl);
                                i++;
@@ -147,6 +135,7 @@ namespace LongoMatch.Drawing.Widgets
                                if (playsFilter.VisibleEventTypes.Contains (type)) {
                                        timeline.OffsetY = i * timeline.Height;
                                        timeline.Visible = true;
+                                       timeline.BackgroundColor = Utils.ColorForRow (i);
                                        i++;
                                } else {
                                        timeline.Visible = false;
diff --git a/LongoMatch.Drawing/Widgets/PositionTagger.cs b/LongoMatch.Drawing/Widgets/PositionTagger.cs
index c688fba..f3cdff1 100644
--- a/LongoMatch.Drawing/Widgets/PositionTagger.cs
+++ b/LongoMatch.Drawing/Widgets/PositionTagger.cs
@@ -32,6 +32,7 @@ namespace LongoMatch.Drawing.Widgets
        
                public event ShowTaggerMenuHandler ShowMenuEvent;
 
+               EventsFilter filter;
                TimelineEvent playSelected;
 
                public PositionTagger (IWidget widget): base (widget)
@@ -48,6 +49,19 @@ namespace LongoMatch.Drawing.Widgets
                        FieldPosition = position;
                }
 
+               public EventsFilter Filter {
+                       get {
+                               return filter;
+                       }
+                       set {
+                               if (filter != null) {
+                                       filter.FilterUpdated -= HandleFilterUpdated;
+                               }
+                               filter = value;
+                               filter.FilterUpdated += HandleFilterUpdated;
+                       }
+               }
+               
                public FieldPositionType FieldPosition {
                        get;
                        set;
@@ -104,6 +118,9 @@ namespace LongoMatch.Drawing.Widgets
                        po = new PositionObject (coords.Points, Background.Width,
                                                 Background.Height);
                        po.Play = play;
+                       if (Filter != null) {
+                               po.Visible = Filter.IsVisible (play);
+                       }
                        Objects.Add (po);
                }
 
@@ -112,6 +129,14 @@ namespace LongoMatch.Drawing.Widgets
                        Objects.RemoveAll (o => plays.Contains ((o as PositionObject).Play));
                }
 
+               void HandleFilterUpdated ()
+               {
+                       foreach (PositionObject po in Objects) {
+                               po.Visible = Filter.IsVisible (po.Play);
+                       }
+                       widget.ReDraw ();
+               }
+
                protected override void SelectionChanged (List<Selection> selections)
                {
                        if (selections.Count > 0) {
diff --git a/LongoMatch.GUI/Gui/Component/CodingWidget.cs b/LongoMatch.GUI/Gui/Component/CodingWidget.cs
index 3a98e58..3e87df8 100644
--- a/LongoMatch.GUI/Gui/Component/CodingWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/CodingWidget.cs
@@ -115,7 +115,7 @@ namespace LongoMatch.Gui.Component
                        if (projectType == ProjectType.FileProject) {
                                timeline.SetProject (project, filter);
                        }
-                       playspositionviewer1.LoadProject (project);
+                       playspositionviewer1.LoadProject (project, filter);
                }
 
                public void AddPlay (TimelineEvent play)
diff --git a/LongoMatch.GUI/Gui/Component/PlaysPositionViewer.cs 
b/LongoMatch.GUI/Gui/Component/PlaysPositionViewer.cs
index 0c69d07..fa9a045 100644
--- a/LongoMatch.GUI/Gui/Component/PlaysPositionViewer.cs
+++ b/LongoMatch.GUI/Gui/Component/PlaysPositionViewer.cs
@@ -29,6 +29,7 @@ namespace LongoMatch.Gui.Component
        
                PlaysMenu menu;
                Project project;
+               EventsFilter filter;
 
                public PlaysPositionViewer ()
                {
@@ -43,7 +44,7 @@ namespace LongoMatch.Gui.Component
                        menu = new PlaysMenu ();
                }
                
-               public void LoadProject (Project project) {
+               public void LoadProject (Project project, EventsFilter filter) {
                        this.project = project;
                        if (project != null) {
                                field.Tagger.Background = project.GetBackground (FieldPositionType.Field);
@@ -52,6 +53,9 @@ namespace LongoMatch.Gui.Component
                                field.Tagger.Plays = project.Timeline;
                                hfield.Tagger.Plays = project.Timeline;
                                goal.Tagger.Plays = project.Timeline;
+                               field.Tagger.Filter = filter;
+                               hfield.Tagger.Filter = filter;
+                               goal.Tagger.Filter = filter;
                        }
                }
                
diff --git a/LongoMatch.GUI/Gui/MainWindow.cs b/LongoMatch.GUI/Gui/MainWindow.cs
index 71b0be8..bcb8bd3 100644
--- a/LongoMatch.GUI/Gui/MainWindow.cs
+++ b/LongoMatch.GUI/Gui/MainWindow.cs
@@ -119,8 +119,8 @@ namespace LongoMatch.Gui
                        }
                        MakeActionsSensitive(true, projectType);
                        analysisWindow = new AnalysisComponent();
-                       analysisWindow.SetProject (project, projectType, props, filter);
                        SetPanel (analysisWindow as Widget);
+                       analysisWindow.SetProject (project, projectType, props, filter);
                        return analysisWindow;
                }
                
diff --git a/LongoMatch.GUI/Gui/Panel/NewProjectPanel.cs b/LongoMatch.GUI/Gui/Panel/NewProjectPanel.cs
index 64c10ea..1c84bfc 100644
--- a/LongoMatch.GUI/Gui/Panel/NewProjectPanel.cs
+++ b/LongoMatch.GUI/Gui/Panel/NewProjectPanel.cs
@@ -58,7 +58,7 @@ namespace LongoMatch.Gui.Panel
                Dashboard analysisTemplate;
                TeamTagger teamtagger;
 
-               public NewProjectPanel (Project project)
+               public NewProjectPanel (Project oroject)
                {
                        this.Build ();
                        this.mtoolkit = Config.MultimediaToolkit;
diff --git a/LongoMatch.GUI/Gui/TreeView/CategoriesFilterTreeView.cs 
b/LongoMatch.GUI/Gui/TreeView/CategoriesFilterTreeView.cs
index 6a60e72..4aea15f 100644
--- a/LongoMatch.GUI/Gui/TreeView/CategoriesFilterTreeView.cs
+++ b/LongoMatch.GUI/Gui/TreeView/CategoriesFilterTreeView.cs
@@ -31,7 +31,6 @@ namespace LongoMatch.Gui.Component
        [System.ComponentModel.ToolboxItem(true)]
        public class CategoriesFilterTreeView: FilterTreeViewBase
        {
-               Dashboard categories;
                Project project;
                
                public CategoriesFilterTreeView (): base()
@@ -42,7 +41,6 @@ namespace LongoMatch.Gui.Component
                
                public override void SetFilter (EventsFilter filter, Project project) {
                        this.project = project;
-                       this.categories = project.Dashboard;
                        base.SetFilter(filter, project);
                }
                
@@ -54,9 +52,11 @@ namespace LongoMatch.Gui.Component
                                TreeIter catIter;
                                
                                catIter = store.AppendValues (evType, true);
+                               filter.FilterEventType (evType, true);
 
                                if (evType is AnalysisEventType) {
                                        foreach (Tag tag in (evType as AnalysisEventType).Tags) {
+                                               filter.FilterEventTag (evType, tag, true);
                                                store.AppendValues(catIter, tag, true);
                                        }
                                }
@@ -74,7 +74,7 @@ namespace LongoMatch.Gui.Component
                                EventType evType = store.GetValue (parent, 0) as EventType;
                                filter.FilterEventTag (evType, o as Tag, active);
                        } else {
-                               /* don't do anything here and let the children do the filtering */
+                               filter.FilterEventType (o as EventType, active);
                        }
                        store.SetValue(iter, 1, active);
                        
@@ -119,11 +119,14 @@ namespace LongoMatch.Gui.Component
                protected override void Select(bool select_all) {
                        TreeIter iter;
                        
+                       filter.Silent = true;
                        store.GetIterFirst(out iter);
                        while (store.IterIsValid(iter)){
                                UpdateSelection(iter, select_all);
                                store.IterNext(ref iter);
                        }
+                       filter.Silent = false;
+                       filter.Update ();
                }
        }
 }
diff --git a/LongoMatch.GUI/Gui/TreeView/ListTreeViewBase.cs b/LongoMatch.GUI/Gui/TreeView/ListTreeViewBase.cs
index b669338..2a29912 100644
--- a/LongoMatch.GUI/Gui/TreeView/ListTreeViewBase.cs
+++ b/LongoMatch.GUI/Gui/TreeView/ListTreeViewBase.cs
@@ -157,7 +157,7 @@ namespace LongoMatch.Gui.Component
                }
 
                protected void OnFilterUpdated() {
-                       modelFilter.Refilter();
+                       Refilter ();
                }
                
                protected void RenderElement (TreeViewColumn column, CellRenderer cell, TreeModel model, 
TreeIter iter)
diff --git a/LongoMatch.GUI/Gui/TreeView/PlayersFilterTreeView.cs 
b/LongoMatch.GUI/Gui/TreeView/PlayersFilterTreeView.cs
index d5a6f19..6788a64 100644
--- a/LongoMatch.GUI/Gui/TreeView/PlayersFilterTreeView.cs
+++ b/LongoMatch.GUI/Gui/TreeView/PlayersFilterTreeView.cs
@@ -58,11 +58,13 @@ namespace LongoMatch.Gui.Component
                        store.SetValue(visitorIter, 1, false);
                        
                        foreach (Player player in local.PlayingPlayersList) {
-                               store.AppendValues (localIter, player, 
filter.VisiblePlayers.Contains(player));
+                               filter.FilterPlayer (player, true);
+                               store.AppendValues (localIter, player, true);
                        }
                        
                        foreach (Player player in visitor.PlayingPlayersList) {
-                               store.AppendValues (visitorIter, player, 
filter.VisiblePlayers.Contains(player));
+                               filter.FilterPlayer (player, true);
+                               store.AppendValues (visitorIter, player, true);
                        }
                        Model = store;
                }
diff --git a/LongoMatch.GUI/gtk-gui/objects.xml b/LongoMatch.GUI/gtk-gui/objects.xml
index 0dca80c..b57a19f 100644
--- a/LongoMatch.GUI/gtk-gui/objects.xml
+++ b/LongoMatch.GUI/gtk-gui/objects.xml
@@ -341,13 +341,17 @@
     </signals>
   </object>
   <object type="LongoMatch.Gui.VideoWindow" palette-category="General" allow-children="false" 
base-type="Gtk.Bin">
-    <itemgroups />
+    <itemgroups>
+      <itemgroup label="VideoWindow Properties">
+        <property name="Ready" />
+      </itemgroup>
+    </itemgroups>
     <signals>
       <itemgroup label="VideoWindow Signals">
-        <signal name="Realized" />
         <signal name="ExposeEvent" />
         <signal name="ButtonPressEvent" />
         <signal name="ScrollEvent" />
+        <signal name="ReadyEvent" />
       </itemgroup>
     </signals>
   </object>
diff --git a/LongoMatch.Services/Services/ProjectsManager.cs b/LongoMatch.Services/Services/ProjectsManager.cs
index 9093912..77943bb 100644
--- a/LongoMatch.Services/Services/ProjectsManager.cs
+++ b/LongoMatch.Services/Services/ProjectsManager.cs
@@ -177,9 +177,6 @@ namespace LongoMatch.Services
                        OpenedProject = project;
                        OpenedProjectType = projectType;
                
-                       if (Player != null) {
-                       }
-                       
                        if (projectType == ProjectType.FileProject) {
                                // Check if the file associated to the project exists
                                if (!File.Exists (project.Description.File.FilePath)) {


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