summaryrefslogtreecommitdiff
path: root/Data/Beacon.cs
blob: fe9314abdcc5d74b14c92a60bacca45c3c111cc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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
    }
}