Subversion Repositories amilis

Rev

Blame | Last modification | View Log | RSS feed

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 Beacon
    {
        #region Attributes

        public static float Ratio = Config.coordinatesRatio;

        private string _code;
        private string _type;
        private double _lat;
        private double _lon;
        private bool _isSelected = false;

        #endregion

        #region Constructor

        public Beacon(pointsPoint beacon)
        {
            this._code = beacon.code;
            this._type = beacon.type;
            this._lat = beacon.lat;
            this._lon = beacon.lon;
        }

        #endregion

        #region Methods

        public void Draw(Graphics g)
        {
            //Pen drawBeaconsPen = new Pen(Config.drawBeaconCodeColor, 0.1f);
            SolidBrush drawBeaconBrush = new SolidBrush(Config.drawBeaconColor);
            SolidBrush drawBeaconCodeBrush = new SolidBrush(Config.drawBeaconCodeColor);
            Font beaconsCodesFont = Config.unselectedBeaconsCodesFont;

            if (this._isSelected)
            {
                //drawBeaconsPen = new Pen(Config.drawSelectedBeaconCodeColor, 0.1f);
                drawBeaconBrush = new SolidBrush(Config.drawSelectedBeaconColor);
                drawBeaconCodeBrush = new SolidBrush(Config.drawSelectedBeaconCodeColor);
                beaconsCodesFont = Config.selectedBeaconsCodesFont;
            }

            PointF locationPointF = this.toPointF();
            if (this.Type != "unpublished")
            {
                //g.DrawEllipse(drawBeaconsPen, (float)PanAndZoomX(locationPointF.X / Ratio), (float)PanAndZoomY(locationPointF.Y / Ratio), Config.beaconsCirclesSize, Config.beaconsCirclesSize);
                g.FillEllipse(drawBeaconBrush, (float)PanAndZoomX(locationPointF.X / Ratio), (float)PanAndZoomY(locationPointF.Y / Ratio), Config.beaconsCirclesSize, Config.beaconsCirclesSize);
                g.DrawString(this.Code, beaconsCodesFont, drawBeaconCodeBrush, new PointF((float)PanAndZoomX(locationPointF.X / Ratio) + 5, (float)PanAndZoomY(locationPointF.Y / Ratio) + 5));
            }
        }

        public PointF toPointF()
        {
            return MathCautra.ToCautra4(this._lat, this._lon);
        }

        #endregion

        #region Getters and Setters

        public string Code
        {
            get { return _code; }
            set { _code = value; }
        }

        public string Type
        {
            get { return _type; }
            set { _type = value; }
        }

        public double Lat
        {
            get { return _lat; }
            set { _lat = value; }
        }

        public double Lon
        {
            get { return _lon; }
            set { _lon = value; }
        }

        public bool isBeaconSelected
        {
            get { return _isSelected; }
            set { _isSelected = 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 Beacon[] LoadBeaconsFile(string fileName)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(points));
            TextReader reader = new StreamReader(fileName);

            Beacon[] Beacons = null;
            if (reader != null)
            {
                points beaconsXml = (points)serializer.Deserialize(reader);
                reader.Close();
                Beacons = new Beacon[beaconsXml.Items.Length];
                int indexSec = 0;
                foreach (pointsPoint s in beaconsXml.Items)
                {
                    Beacons[indexSec++] = new Beacon(s);
                    //Console.WriteLine("Balise : " + s.code + " --> lat : " + s.lat + " & lon : " + s.lon);
                }
                //Console.WriteLine("Beacons : " + beaconsXml.Items.Length);
            }
            return Beacons;
        }
        #endregion
    }
}