/[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 91 - (show annotations) (download)
Tue Oct 12 21:38:57 2010 UTC (11 years, 1 month ago) by rvvs89
File size: 5457 byte(s)
Right click on map markers now displays a context menu.
Metadata can now be deleted using the context menu.
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 Edit(IMetadata item)
80 {
81 EditMetadataDialog.Instance.Control.Editor = item.Editor;
82 EditMetadataDialog.Instance.ShowDialog();
83 }
84
85 public void Invalidate(IMetadata item)
86 {
87 RemoveMarker(item);
88 CreateMarker(item);
89 }
90
91 public void InvalidateAll()
92 {
93 foreach (IMetadata item in items)
94 {
95 Invalidate(item);
96 }
97 }
98
99 private void RemoveMarker(IMetadata item)
100 {
101 if (item.FormData != null)
102 {
103 IMapOverlay marker = (MapMarker)item.FormData;
104 MetadataRouteControlLayer.Instances[0].Control.MapControl.RemoveOverlay(marker);
105 }
106 }
107
108 private void CreateMarker(IMetadata item)
109 {
110 MapMarker marker = new MapMarker(FindSuitablePoint(item), icon, true);
111 marker.MouseUp += new MouseEventHandler(marker_MouseUp);
112 marker.DoubleClick += new MouseEventHandler(marker_DoubleClick);
113 item.FormData = marker;
114 MetadataRouteControlLayer.Instances[0].Control.MapControl.AddOverlay(marker);
115 }
116
117 void marker_DoubleClick(object sender, MouseEventArgs e)
118 {
119 if (e.Button == MouseButtons.Left)
120 {
121 Edit(FindMetadataFromMarker((MapMarker)sender));
122 }
123 }
124
125 void marker_MouseUp(object sender, MouseEventArgs e)
126 {
127 IMetadata data = FindMetadataFromMarker((MapMarker)sender);
128 switch (e.Button)
129 {
130 case MouseButtons.Left:
131 // TODO: select relevant route section
132 break;
133 case MouseButtons.Right:
134 EditMetadataDialog.Instance.MapMarkerReference = data;
135 EditMetadataDialog.Instance.MapMarkerContextMenu.Show(MetadataRouteControlLayer.Instances[0].Control.MapControl.Control, e.Location);
136 break;
137 }
138 }
139
140 private IMetadata FindMetadataFromMarker(MapMarker marker)
141 {
142 IMetadata reference = null;
143 foreach (IMetadata item in items)
144 {
145 if (item.FormData == marker)
146 {
147 reference = item;
148 break;
149 }
150 }
151 if (reference == null)
152 {
153 MetadataRouteControlLayer.Instances[0].Control.MapControl.RemoveOverlay(marker);
154 }
155 return reference;
156 }
157
158 private IGPSPoint FindSuitablePoint(IMetadata item)
159 {
160 IEnumerator<ITimeValueEntry<IGPSPoint>> enumerator = activity.GPSRoute.GetEnumerator();
161 enumerator.MoveNext();
162 return enumerator.Current.Value;
163 }
164 }
165 }

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26