/[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 92 - (show annotations) (download)
Tue Oct 12 22:01:08 2010 UTC (11 years, 1 month ago) by rvvs89
File size: 5565 byte(s)
Added conditions to IActions to ensure that points/ranges are only addable when a point/range is selected.
Fixed metadata deletion not triggeting MetadataList commit.
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 // TODO
89 }
90
91 public void Invalidate(IMetadata item)
92 {
93 RemoveMarker(item);
94 CreateMarker(item);
95 }
96
97 public void InvalidateAll()
98 {
99 foreach (IMetadata item in items)
100 {
101 Invalidate(item);
102 }
103 }
104
105 private void RemoveMarker(IMetadata item)
106 {
107 if (item.FormData != null)
108 {
109 IMapOverlay marker = (MapMarker)item.FormData;
110 MetadataRouteControlLayer.Instances[0].Control.MapControl.RemoveOverlay(marker);
111 }
112 }
113
114 private void CreateMarker(IMetadata item)
115 {
116 MapMarker marker = new MapMarker(FindStartPoint(item), icon, true);
117 marker.MouseUp += new MouseEventHandler(marker_MouseUp);
118 marker.DoubleClick += new MouseEventHandler(marker_DoubleClick);
119 item.FormData = marker;
120 MetadataRouteControlLayer.Instances[0].Control.MapControl.AddOverlay(marker);
121 }
122
123 void marker_DoubleClick(object sender, MouseEventArgs e)
124 {
125 if (e.Button == MouseButtons.Left)
126 {
127 Edit(FindMetadataFromMarker((MapMarker)sender));
128 }
129 }
130
131 void marker_MouseUp(object sender, MouseEventArgs e)
132 {
133 IMetadata data = FindMetadataFromMarker((MapMarker)sender);
134 switch (e.Button)
135 {
136 case MouseButtons.Left:
137 SelectRegion(data);
138 break;
139 case MouseButtons.Right:
140 EditMetadataDialog.Instance.MapMarkerReference = data;
141 EditMetadataDialog.Instance.MapMarkerContextMenu.Show(MetadataRouteControlLayer.Instances[0].Control.MapControl.Control, e.Location);
142 break;
143 }
144 }
145
146 private IMetadata FindMetadataFromMarker(MapMarker marker)
147 {
148 IMetadata reference = null;
149 foreach (IMetadata item in items)
150 {
151 if (item.FormData == marker)
152 {
153 reference = item;
154 break;
155 }
156 }
157 if (reference == null)
158 {
159 MetadataRouteControlLayer.Instances[0].Control.MapControl.RemoveOverlay(marker);
160 }
161 return reference;
162 }
163
164 private IGPSPoint FindStartPoint(IMetadata item)
165 {
166
167 IEnumerator<ITimeValueEntry<IGPSPoint>> enumerator = activity.GPSRoute.GetEnumerator();
168 enumerator.MoveNext();
169 return enumerator.Current.Value;
170 }
171 }
172 }

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26