/[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 93 - (show annotations) (download)
Tue Oct 12 22:22:23 2010 UTC (11 years, 1 month ago) by rvvs89
File size: 6430 byte(s)
Selected points and ranges are now recoverable by clicking on metadata map markers.
The precise time point or range is displayed in the editor form.
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 Commit();
78 }
79
80 public void Edit(IMetadata item)
81 {
82 EditMetadataDialog.Instance.Control.Editor = item.Editor;
83 EditMetadataDialog.Instance.ShowDialog();
84 }
85
86 public void SelectRegion(IMetadata item)
87 {
88 IRouteControlItem selected = MetadataRouteControlLayer.Instances[0].Control.Items[0];
89 DateTime start = selected.Item.GPSRoute.StartTime;
90 DateTime end = selected.Item.GPSRoute.StartTime.AddSeconds(selected.Item.GPSRoute.TotalElapsedSeconds);
91 switch(item.Location)
92 {
93 case MetadataLocation.POINT:
94 start = item.Point;
95 end = item.Point;
96 break;
97 case MetadataLocation.RANGE:
98 start = item.Point;
99 end = item.End;
100 break;
101 }
102 MetadataRouteControlSelection selection = new MetadataRouteControlSelection(selected, start, end);
103 MetadataRouteControlLayer.Instances[0].Control.SelectedItems = new List<IRouteControlSelection> { selection };
104 }
105
106 public void Invalidate(IMetadata item)
107 {
108 RemoveMarker(item);
109 CreateMarker(item);
110 }
111
112 public void InvalidateAll()
113 {
114 foreach (IMetadata item in items)
115 {
116 Invalidate(item);
117 }
118 }
119
120 private void RemoveMarker(IMetadata item)
121 {
122 if (item.FormData != null)
123 {
124 IMapOverlay marker = (MapMarker)item.FormData;
125 MetadataRouteControlLayer.Instances[0].Control.MapControl.RemoveOverlay(marker);
126 }
127 }
128
129 private void CreateMarker(IMetadata item)
130 {
131 MapMarker marker = new MapMarker(FindStartPoint(item), icon, true);
132 marker.MouseUp += new MouseEventHandler(marker_MouseUp);
133 marker.DoubleClick += new MouseEventHandler(marker_DoubleClick);
134 item.FormData = marker;
135 MetadataRouteControlLayer.Instances[0].Control.MapControl.AddOverlay(marker);
136 }
137
138 void marker_DoubleClick(object sender, MouseEventArgs e)
139 {
140 if (e.Button == MouseButtons.Left)
141 {
142 Edit(FindMetadataFromMarker((MapMarker)sender));
143 }
144 }
145
146 void marker_MouseUp(object sender, MouseEventArgs e)
147 {
148 IMetadata data = FindMetadataFromMarker((MapMarker)sender);
149 switch (e.Button)
150 {
151 case MouseButtons.Left:
152 SelectRegion(data);
153 break;
154 case MouseButtons.Right:
155 EditMetadataDialog.Instance.MapMarkerReference = data;
156 EditMetadataDialog.Instance.MapMarkerContextMenu.Show(MetadataRouteControlLayer.Instances[0].Control.MapControl.Control, e.Location);
157 break;
158 }
159 }
160
161 private IMetadata FindMetadataFromMarker(MapMarker marker)
162 {
163 IMetadata reference = null;
164 foreach (IMetadata item in items)
165 {
166 if (item.FormData == marker)
167 {
168 reference = item;
169 break;
170 }
171 }
172 if (reference == null)
173 {
174 MetadataRouteControlLayer.Instances[0].Control.MapControl.RemoveOverlay(marker);
175 }
176 return reference;
177 }
178
179 private IGPSPoint FindStartPoint(IMetadata item)
180 {
181
182 IEnumerator<ITimeValueEntry<IGPSPoint>> enumerator = activity.GPSRoute.GetEnumerator();
183 enumerator.MoveNext();
184 return enumerator.Current.Value;
185 }
186 }
187 }

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26