From 42dc1d36235292786322d28340a81c6cb3fd46c0 Mon Sep 17 00:00:00 2001 From: hurter Date: Wed, 31 Aug 2011 16:25:05 +0000 Subject: --- Data/Route.cs | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 Data/Route.cs (limited to 'Data/Route.cs') diff --git a/Data/Route.cs b/Data/Route.cs new file mode 100644 index 0000000..6a8cbf6 --- /dev/null +++ b/Data/Route.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Drawing; +using System.Xml.Serialization; +using System.IO; + +namespace Data +{ + public class Route + { + #region Attributes + + public static float Ratio = Config.coordinatesRatio; + + private string _b1; + private string _b2; + + private AppDatabase app; + + #endregion + + #region Constructor + + public Route(routesRoute route, AppDatabase app1) + { + this._b1 = route.b1; + this._b2 = route.b2; + this.app = app1; + } + + #endregion + + #region Methods + + public void Draw(Graphics g) + { + Beacon startBeacon = getCorrespondingBeacon(this.B1); + Beacon endBeacon = getCorrespondingBeacon(this.B2); + + if ((startBeacon != null) && (endBeacon != null)) + { + PointF locationPointB1 = startBeacon.toPointF(); + PointF locationPointB2 = endBeacon.toPointF(); + g.DrawLine(Config.drawRoutesPen, (float)PanAndZoomX(locationPointB1.X / Ratio), (float)PanAndZoomY(locationPointB1.Y / Ratio), (float)PanAndZoomX(locationPointB2.X / Ratio), (float)PanAndZoomY(locationPointB2.Y / Ratio)); + } + } + + public Beacon getCorrespondingBeacon(string bCode) + { + Beacon correspondingBeacon = null; + foreach (Beacon b in app.getBeacons()) + { + if (b.Code == bCode) + { + correspondingBeacon = b; + break; + } + } + return correspondingBeacon; + } + + #endregion + + #region Getters and Setters + + public string B1 + { + get { return _b1; } + set { _b1 = value; } + } + + public string B2 + { + get { return _b2; } + set { _b2 = value; } + } + + #endregion + + #region Delegate Pan And Zoom + + public delegate double PanAndZoom(double input); + + [NonSerialized] + static public PanAndZoom PanAndZoomX; + [NonSerialized] + static public PanAndZoom PanAndZoomY; + + #endregion + + #region createList + public static Route[] LoadRoutesFile(string fileName, AppDatabase app) + { + XmlSerializer serializer = new XmlSerializer(typeof(routes)); + TextReader reader = new StreamReader(fileName); + + Route[] Routes = null; + if (reader != null) + { + routes routesXml = (routes)serializer.Deserialize(reader); + reader.Close(); + Routes = new Route[routesXml.Items.Length]; + int indexSec = 0; + foreach (routesRoute r in routesXml.Items) + { + Routes[indexSec++] = new Route(r, app); + //Console.WriteLine("Route : " + r.b1 + " / " + r.b2); + } + //Console.WriteLine("Routes : " + routesXml.Items.Length); + } + return Routes; + } + #endregion + } +} -- cgit v1.1