/[cits3200i]/branches/metadata-branch-rvvs89/UWAPlugins/MetadataPlugin/Source/MetadataList.cs


UCC Code Repository

Contents of /branches/metadata-branch-rvvs89/UWAPlugins/MetadataPlugin/Source/MetadataList.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 90 - (show annotations) (download)
Tue Oct 12 21:18:41 2010 UTC (11 years, 1 month ago) by rvvs89
File size: 4896 byte(s)
Attaching metadata now works.
Saving metadata now works.
Loading metadata now works.
Editing metadata and cancelling your changes now works.
MetadataList now only commits on change.
Icons appear on the track when metadata is added.
Icons can be double clicked to launch the editor.
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.IO;
5 using System.Runtime.Serialization;
6 using ZoneFiveSoftware.Common.Data.Fitness;
7 using ZoneFiveSoftware.Common.Visuals.Mapping;
8 using System.Drawing;
9 using System.Windows.Forms;
10 using ZoneFiveSoftware.Common.Data.GPS;
11 using ZoneFiveSoftware.Common.Data;
12 using ZoneFiveSoftware.Common.Visuals.Util;
13
14 namespace MetadataPlugin.Source
15 {
16 [Serializable]
17 class MetadataList : IDeserializationCallback
18 {
19 private IList<IMetadata> items = new List<IMetadata>();
20 [NonSerialized]
21 private IActivity activity;
22 [NonSerialized]
23 private MapIcon icon;
24
25 public MetadataList()
26 {
27 icon = MakeMapIcon("MetadataPlugin\\Data\\start.png", new Size(64, 64));
28 }
29
30 private MapIcon MakeMapIcon(string name, Size size)
31 {
32 string testPath = Plugin.Instance.Application.Configuration.CommonPluginsInstalledFolder + "\\" + Plugin.Instance.Id.ToString("D") + "\\" + name;
33 if (File.Exists(testPath))
34 {
35 return new MapIcon(testPath, size, new Point(size.Width / 2, size.Height / 2));
36 }
37 return null;
38 }
39
40 public IActivity Activity
41 {
42 set { activity = value; }
43 }
44
45 public void Commit()
46 {
47 activity.SetExtensionData(Plugin.Instance.Id, MetadataListSerializer.Serialize(this));
48 }
49
50 public void OnDeserialization(object sender)
51 {
52 icon = MakeMapIcon("MetadataPlugin\\Data\\start.png", new Size(64, 64));
53 activity = CollectionUtils.GetSingleItemOfType<IActivity>(MetadataActivityReportPages.View.SelectionProvider.SelectedItems);
54 InvalidateAll();
55 }
56
57 public static MetadataList LoadFromActivity(IActivity activity)
58 {
59 if (activity == null)
60 return null;
61 MetadataList ret = MetadataListSerializer.Deserialize(activity.GetExtensionData(Plugin.Instance.Id));
62 if (ret == null)
63 ret = new MetadataList();
64 return ret;
65 }
66
67 public void Add(IMetadata item)
68 {
69 items.Add(item);
70 CreateMarker(item);
71 }
72
73 public void Remove(IMetadata item)
74 {
75 items.Remove(item);
76 RemoveMarker(item);
77 }
78
79 public void Invalidate(IMetadata item)
80 {
81 RemoveMarker(item);
82 CreateMarker(item);
83 }
84
85 public void InvalidateAll()
86 {
87 foreach (IMetadata item in items)
88 {
89 Invalidate(item);
90 }
91 }
92
93 private void RemoveMarker(IMetadata item)
94 {
95 if (item.FormData != null)
96 {
97 IMapOverlay marker = (MapMarker)item.FormData;
98 MetadataRouteControlLayer.Instances[0].Control.MapControl.RemoveOverlay(marker);
99 }
100 }
101
102 private void CreateMarker(IMetadata item)
103 {
104 MapMarker marker = new MapMarker(FindSuitablePoint(item), icon, true);
105 marker.MouseUp += new MouseEventHandler(marker_MouseUp);
106 marker.DoubleClick += new MouseEventHandler(marker_DoubleClick);
107 item.FormData = marker;
108 MetadataRouteControlLayer.Instances[0].Control.MapControl.AddOverlay(marker);
109 }
110
111 void marker_DoubleClick(object sender, MouseEventArgs e)
112 {
113 if (e.Button == MouseButtons.Left)
114 {
115 IMetadata data = FindMetadataFromMarker((MapMarker)sender);
116 EditMetadataDialog.Instance.Control.Editor = data.Editor;
117 EditMetadataDialog.Instance.ShowDialog();
118 }
119 }
120
121 void marker_MouseUp(object sender, MouseEventArgs e)
122 {
123 throw new NotImplementedException();
124 }
125
126 private IMetadata FindMetadataFromMarker(MapMarker marker)
127 {
128 IMetadata reference = null;
129 foreach (IMetadata item in items)
130 {
131 if (item.FormData == marker)
132 {
133 reference = item;
134 break;
135 }
136 }
137 if (reference == null)
138 {
139 MetadataRouteControlLayer.Instances[0].Control.MapControl.RemoveOverlay(marker);
140 }
141 return reference;
142 }
143
144 private IGPSPoint FindSuitablePoint(IMetadata item)
145 {
146 IEnumerator<ITimeValueEntry<IGPSPoint>> enumerator = activity.GPSRoute.GetEnumerator();
147 enumerator.MoveNext();
148 return enumerator.Current.Value;
149 }
150 }
151 }

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26