195
|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Windows.Media; |
|
6 |
|
|
7 |
namespace FingersDance.Data |
|
8 |
{ |
|
9 |
public class DataDictionary |
|
10 |
{ |
|
11 |
Dictionary<int, List<Color>> _Data = new Dictionary<int, List<Color>>(); |
|
12 |
|
|
13 |
public DataDictionary() |
|
14 |
{ |
|
15 |
if (_Data == null) |
|
16 |
_Data = new Dictionary<int, List<Color>>(); |
|
17 |
} |
|
18 |
|
|
19 |
public void AddAnnotation(Annotation annotation) |
|
20 |
{ |
|
21 |
try |
|
22 |
{ |
|
23 |
// Recherche de l'élément qui précède le TC de début |
|
24 |
List<Color> temp = new List<Color>(); |
|
25 |
int value = 0; |
|
26 |
for (int i = (int)annotation.TcBegin; i >= 0; i--) |
|
27 |
if (_Data.ContainsKey(i)) |
|
28 |
{ |
|
29 |
value = i; |
|
30 |
i = -1; |
|
31 |
} |
|
32 |
|
|
33 |
// Ajout des couleurs de l'élément qui précède |
|
34 |
if (!_Data.ContainsKey((int)annotation.TcBegin)) |
|
35 |
{ |
|
36 |
if (_Data.ContainsKey(value)) |
|
37 |
foreach (Color elt in _Data[value]) |
|
38 |
temp.Add(elt); |
|
39 |
_Data.Add((int)annotation.TcBegin, temp); |
|
40 |
} |
|
41 |
|
|
42 |
// Ajout de la couleur à tous les éléments entre le début et la fin de l'annotation |
|
43 |
foreach (KeyValuePair<int, List<Color>> elt in _Data) |
|
44 |
if (elt.Key >= (int)annotation.TcBegin && elt.Key < (int)(annotation.TcBegin + annotation.Dur) && !elt.Value.Contains(annotation.Color)) |
|
45 |
elt.Value.Add(annotation.Color); |
|
46 |
|
|
47 |
// Vérification que début et fin correspondent à deux éléments distincts et ajout de la fin de l'annotation si nécessaire (tc de fin inexistant) |
|
48 |
if (((int)annotation.TcBegin) != ((int)(annotation.TcBegin + annotation.Dur))) |
|
49 |
{ |
|
50 |
temp = new List<Color>(); |
|
51 |
if (!_Data.ContainsKey((int)(annotation.TcBegin + annotation.Dur))) |
|
52 |
{ |
|
53 |
for (int i = (int)(annotation.TcBegin + annotation.Dur); i >= 0; i--) |
|
54 |
if (_Data.ContainsKey(i)) |
|
55 |
{ |
|
56 |
value = i; |
|
57 |
i = -1; |
|
58 |
} |
|
59 |
if (_Data.ContainsKey(value)) |
|
60 |
foreach (Color elt in _Data[value]) |
|
61 |
temp.Add(elt); |
|
62 |
temp.Remove(annotation.Color); |
|
63 |
_Data.Add((int)(annotation.TcBegin + annotation.Dur), temp); |
|
64 |
} |
|
65 |
} |
|
66 |
else if (!_Data.ContainsKey((int)(annotation.TcBegin + 1))) |
|
67 |
{ |
|
68 |
temp = new List<Color>(); |
|
69 |
foreach (Color elt in _Data[(int)annotation.TcBegin]) |
|
70 |
temp.Add(elt); |
|
71 |
_Data.Add((int)(annotation.TcBegin + 1), temp); |
|
72 |
} |
|
73 |
} |
|
74 |
catch { } |
|
75 |
} |
|
76 |
|
|
77 |
public void RemoveAnnotation(Annotation annotation) |
|
78 |
{ |
|
79 |
try |
|
80 |
{ |
|
81 |
// Suppression de la couleur à tous les éléments entre le début et la fin de l'annotation |
|
82 |
foreach (KeyValuePair<int, List<Color>> elt in _Data) |
|
83 |
if (elt.Key >= (int)annotation.TcBegin && elt.Key < (int)(annotation.TcBegin + annotation.Dur) && elt.Value.Contains(annotation.Color)) |
|
84 |
elt.Value.Remove(annotation.Color); |
|
85 |
} |
|
86 |
catch { } |
|
87 |
} |
|
88 |
|
|
89 |
public List<Color> GetColors(int TC) |
|
90 |
{ |
|
91 |
try |
|
92 |
{ |
|
93 |
for (int i = TC; i >= 0; i--) |
|
94 |
if (_Data.ContainsKey(i)) |
|
95 |
return _Data[i]; |
|
96 |
return new List<Color>(); |
|
97 |
} |
|
98 |
catch (Exception) |
|
99 |
{ |
|
100 |
return new List<Color>(); |
|
101 |
} |
|
102 |
} |
|
103 |
} |
|
104 |
} |