using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using IvyBus;
using System.Xml.Serialization;
using System.IO;
using Data;
using System.Globalization;
namespace SimpleRadar
{
public partial class FormSimpleRadar : Form
{
public static FormSimpleRadar FormRadarInstance;
UserControlRadarView userControlRadarView1;
public static IvyBus.Ivy TheIvyBus;
#region Attributes
#endregion
#region Constructor
public FormSimpleRadar()
{
FormRadarInstance = this;
userControlRadarView1 = new UserControlRadarView();
this.Controls.Add(userControlRadarView1);
userControlRadarView1.Dock = DockStyle.Fill;
InitializeComponent();
AppDatabase data = new AppDatabase(IvyBus);
data.addAircraftView(userControlRadarView1);
userControlRadarView1.setData(data);
}
#endregion
#region Events handlers
private void FormRadar_Load(object sender, EventArgs e)
{
IvyBus.ivy.Start(ivyDomain.Domain);
Bind();
FormSimpleRadar.TheIvyBus = IvyBus.ivy;
}
#endregion
#region Ivy messages binding
private void Bind()
{
int regexp_id = IvyBus.ivy.BindMsg(@"^RadarScreenPenDown PenId=(.*) X=(.*) Y=(.*)",
RadarScreenPenDown, null);
// ajoute la nouvelle regex
regexp_id = IvyBus.ivy.BindMsg(@"^SelectionEvent Flight=([0-9]+) Perform=(True|False)",
SelectAircraft, null);
regexp_id = IvyBus.ivy.BindMsg(@"^WarningEvent Flight=([0-9]+) Perform=(True|False|Change)",
WarningAircraft, null);
regexp_id = IvyBus.ivy.BindMsg(@"^PartEvent Flight=([0-9]+) Perform=(True|False|Change)",
PartAircraft, null);
regexp_id = IvyBus.ivy.BindMsg(@"^DisplayRoadEvent Flight1=([0-9]+) Route1=(.*) Distance1=([0-9]+) Thicks1=(.*) Flight2=([0-9]+) Route2=(.*) Distance2=([0-9]+) Thicks2=(.*) Distance=([0-9]+) Perform=(True|False)",
DisplayAircraftRoad, null);
regexp_id = IvyBus.ivy.BindMsg(@"^AFLFilterEvent AFL=([0-9]+) Range=(-?[0-9]+) Perform=(True|False)",
AFLFilter, null);
regexp_id = IvyBus.ivy.BindMsg(@"^AFLFilterEvent Flight=([0-9]+) Perform=(True|False)",
AFLAircraftFilter, null);
regexp_id = IvyBus.ivy.BindMsg(@"^ModS Flight=([0-9]+) Level=([0-9]+) NextSector=(.*) Succeed=(True|False)",
ModS, null);
regexp_id = IvyBus.ivy.BindMsg(@"^InformationMessage Beginning Flight=([0-9]+) NumberOfWords=([0-9]+)",
InformationMessageBegin, null);
regexp_id = IvyBus.ivy.BindMsg(@"^InformationMessage Flight=([0-9]+) Word=(([0-9]+)(( [0-9]+)+))",
InformationMessageStream, null);
regexp_id = IvyBus.ivy.BindMsg(@"^InformationMessage Flight=([0-9]+) End",
InformationMessageEnd, null);
regexp_id = IvyBus.ivy.BindMsg(@"^InformationMessage Flight=([0-9]+) Remove",
InformationMessageRemove, null);
regexp_id = IvyBus.ivy.BindMsg(@"^AlarmClock Flight=([0-9]+) Hour=([0-9]+) Min=([0-9]+) Perform=(True|False)",
AlarmClock, null);
regexp_id = IvyBus.BindMsg(@"^TrackMovedEvent (.*) Time=([0-9]+):([0-9]+):([0-9]+)",
UpdateClock, null);
regexp_id = IvyBus.BindMsg(@"^FollowPlane Flight=([0-9]+) Perform=(True|False)",
FollowPlane, null);
regexp_id = IvyBus.ivy.BindMsg(@"^SetTag Flight=([0-9]+) Strip=([0-9]+) Perform=(True|False)",
TagMessageInit, null);
regexp_id = IvyBus.ivy.BindMsg(@"^SetTag Beginning Flight=([0-9]+) NumberOfWords=([0-9]+)",
TagMessageBegin, null);
regexp_id = IvyBus.ivy.BindMsg(@"^SetTag Flight=([0-9]+) Word=(([0-9]+)(( [0-9]+)+))",
TagMessageStream, null);
regexp_id = IvyBus.ivy.BindMsg(@"^SetTag Flight=([0-9]+) End",
TagMessageEnd, null);
regexp_id = IvyBus.ivy.BindMsg(@"^SetTag Flight=([0-9]+) Remove",
TagMessageRemove, null);
}
private void TagMessageRemove(object sender, IvyMessageEventArgs e)
{
userControlRadarView1.manageAircraftTagMessageDictionary("remove", e[0], 0, 0);
}
private void TagMessageEnd(object sender, IvyMessageEventArgs e)
{
userControlRadarView1.updateAircraftTagMessage(e[0], false, "");
}
private void TagMessageStream(object sender, IvyMessageEventArgs e)
{
userControlRadarView1.updateAircraftTagMessage(e[0], true, e[1]);
}
private void TagMessageBegin(object sender, IvyMessageEventArgs e)
{
userControlRadarView1.manageAircraftTagMessageDictionary("update", e[0], 0, int.Parse(e[1]));
}
private void TagMessageInit(object sender, IvyMessageEventArgs e)
{
if (e[2].ToLower() == "true")
{
userControlRadarView1.manageAircraftTagMessageDictionary("add", e[0], int.Parse(e[1]), 0);
}
else
{
userControlRadarView1.manageAircraftTagMessageDictionary("remove", e[0], 0, 0);
}
}
private void FollowPlane(object sender, IvyMessageEventArgs e)
{
if (e[1].ToLower() == "true")
userControlRadarView1.manageFollowedAircraftList("add", e[0]);
else
userControlRadarView1.manageFollowedAircraftList("remove", e[0]);
}
private void UpdateClock(object sender, IvyMessageEventArgs e)
{
userControlRadarView1.updateClock(Int32.Parse(e[1]), Int32.Parse(e[2]), Int32.Parse(e[3]));
}
private void AlarmClock(object sender, IvyMessageEventArgs e)
{
if (e[3].ToLower() == "true")
{
userControlRadarView1.manageAircraftAlarmsDictionary("add", e[0], Int32.Parse(e[1]), Int32.Parse(e[2]), 0);
}
else
{
userControlRadarView1.manageAircraftAlarmsDictionary("remove", e[0], Int32.Parse(e[1]), Int32.Parse(e[2]), 0);
}
}
private void InformationMessageRemove(object sender, IvyMessageEventArgs e)
{
userControlRadarView1.manageAircraftInformationMessagesDictionary("remove", e[0], 0);
}
private void InformationMessageEnd(object sender, IvyMessageEventArgs e)
{
userControlRadarView1.updateAircraftInformationMessage(e[0], false, "");
}
private void InformationMessageStream(object sender, IvyMessageEventArgs e)
{
userControlRadarView1.updateAircraftInformationMessage(e[0], true, e[1]);
}
private void InformationMessageBegin(object sender, IvyMessageEventArgs e)
{
userControlRadarView1.manageAircraftInformationMessagesDictionary("add", e[0], int.Parse(e[1]));
}
private void ModS(object sender, IvyMessageEventArgs e)
{
userControlRadarView1.manageAircraftModSDictionary(e[0], e[1], e[2], e[3]);
}
private void AFLFilter(object sender, IvyMessageEventArgs e)
{
if (e[2].ToLower() == "true")
{
userControlRadarView1.manageFlightLevelFilter("add", int.Parse(e[0]), int.Parse(e[1]));
}
else
{
userControlRadarView1.manageFlightLevelFilter("clear", 0, 0);
userControlRadarView1.manageFollowedAircraftList("clear", "");
}
}
private void AFLAircraftFilter(object sender, IvyMessageEventArgs e)
{
if (e[1].ToLower() == "true")
{
userControlRadarView1.manageAircraftFlightLevelFilterList("add", e[0]);
}
else
{
userControlRadarView1.manageAircraftFlightLevelFilterList("remove", e[0]);
}
}
private void DisplayAircraftRoad(object sender, IvyMessageEventArgs e)
{
if (e[9].ToLower() == "true")
userControlRadarView1.manageAircraftSeparationList("add", e[0], e[1], e[2], e[3], e[4], e[5], e[6], e[7], e[8]);
else
userControlRadarView1.manageAircraftSeparationList("clear", "", "", "", "", "", "", "", "", "");
}
private void PartAircraft(object sender, IvyMessageEventArgs e)
{
if (e[1].ToLower() == "true")
userControlRadarView1.managePartAircraftList("add", e[0]);
else if (e[1].ToLower() == "false")
userControlRadarView1.managePartAircraftList("remove", e[0]);
else
userControlRadarView1.managePartAircraftList("change", e[0]);
}
private void WarningAircraft(object sender, IvyMessageEventArgs e)
{
if (e[1].ToLower() == "true")
userControlRadarView1.manageWarningAircraftList("add", e[0]);
else if (e[1].ToLower() == "false")
userControlRadarView1.manageWarningAircraftList("remove", e[0]);
else
userControlRadarView1.manageWarningAircraftList("change", e[0]);
}
private void SelectAircraft(object sender, IvyMessageEventArgs e)
{
if (e[1].ToLower() == "true")
userControlRadarView1.manageSelectedAircraftTimer("add", e[0]);
else
userControlRadarView1.manageSelectedAircraftTimer("clear", e[0]);
}
CultureInfo ci = new CultureInfo("en-US");
///
/// The anoto supervision sent a pendown event
///
///
///
private void RadarScreenPenDown(object sender, IvyMessageEventArgs e)
{
string penId = e[0];
float x = float.Parse(e[1],ci);
float y = float.Parse(e[2],ci);
userControlRadarView1.AddNewPenDown(new PointF(x, y));
}
#endregion
#region Other methods
public void sendIvyMessage(string txt)
{
int resp = IvyBus.ivy.SendMsg(txt);
Console.WriteLine("Message sent on Ivy : " + txt + " with response : " + resp);
}
#endregion }
}
}