Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes release #96

Merged
merged 1 commit into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions OpenSky.Agent.SimConnectMSFS/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("1f9cbede-669d-4510-bca2-e6ad29d6a498")]
[assembly: AssemblyVersion("0.5.12")]
[assembly: AssemblyFileVersion("0.5.12")]
[assembly: AssemblyVersion("0.5.13")]
[assembly: AssemblyFileVersion("0.5.13")]
2 changes: 1 addition & 1 deletion OpenSky.Agent.Simulator/OpenSkyColors.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<SolidColorBrush x:Key="OpenSkyWarningOrangeBrush" Color="{StaticResource OpenSkyWarningOrange}" />
<Color x:Key="OpenSkyWarningOrangeLight">Orange</Color>
<SolidColorBrush x:Key="OpenSkyWarningOrangeLightBrush" Color="{StaticResource OpenSkyWarningOrangeLight}" />
<Color x:Key="OpenSkySimBrief">Black</Color>
<Color x:Key="OpenSkySimBrief">#666</Color>
<SolidColorBrush x:Key="OpenSkySimBriefBrush" Color="{StaticResource OpenSkySimBrief}" />
<Color x:Key="OpenSkySimBriefText">White</Color>
<SolidColorBrush x:Key="OpenSkySimBriefTextBrush" Color="{StaticResource OpenSkySimBriefText}" />
Expand Down
4 changes: 2 additions & 2 deletions OpenSky.Agent.Simulator/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("30c467e8-2eee-41e5-be01-0142a61ba171")]
[assembly: AssemblyVersion("0.5.12")]
[assembly: AssemblyFileVersion("0.5.12")]
[assembly: AssemblyVersion("0.5.13")]
[assembly: AssemblyFileVersion("0.5.13")]
[assembly: InternalsVisibleTo("OpenSky.Agent")]
2 changes: 0 additions & 2 deletions OpenSky.Agent.Simulator/Simulator.Flight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ public Flight Flight
{
if (value.NavlogFixes?.Count > 0)
{
this.SimbriefOfpLoaded = true;
foreach (var flightNavlogFix in value.NavlogFixes)
{
this.SimbriefRouteLocations.Add(new Location(flightNavlogFix.Latitude, flightNavlogFix.Longitude));
Expand Down Expand Up @@ -397,7 +396,6 @@ public Flight Flight
this.flightLoadingTempModels = null;
this.StopTracking(false);
this.lastFlightLogAutoSave = DateTime.MinValue;
this.simbriefOfpLoaded = false;
this.OnlineNetworkConnectionDuration = TimeSpan.Zero;
this.OnlineNetworkConnectionStarted = null;
this.VatsimClientConnection = null;
Expand Down
209 changes: 0 additions & 209 deletions OpenSky.Agent.Simulator/Simulator.simBrief.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@ namespace OpenSky.Agent.Simulator
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Windows;
using System.Xml.Linq;

using Microsoft.Maps.MapControl.WPF;

using OpenSky.Agent.Simulator.Models;
using OpenSky.Agent.Simulator.Tools;

/// -------------------------------------------------------------------------------------------------
/// <content>
Expand All @@ -32,222 +27,18 @@ public partial class Simulator
/// -------------------------------------------------------------------------------------------------
private readonly List<SimbriefWaypointMarker> simbriefWaypointMarkers = new();

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// True if simbrief ofp was loaded for this flight.
/// </summary>
/// -------------------------------------------------------------------------------------------------
private bool simbriefOfpLoaded;

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Occurs when simbrief ofp loaded property changed.
/// </summary>
/// -------------------------------------------------------------------------------------------------
public event EventHandler<bool> SimbriefOfpLoadedChanged;

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Occurs when SimConnect adds a new simbrief waypoint marker.
/// </summary>
/// -------------------------------------------------------------------------------------------------
public event EventHandler<SimbriefWaypointMarker> SimbriefWaypointMarkerAdded;

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Gets a value indicating whether a simbrief ofp was loaded for the current flight.
/// </summary>
/// -------------------------------------------------------------------------------------------------
public bool SimbriefOfpLoaded
{
get => this.simbriefOfpLoaded;

private set
{
if (Equals(this.simbriefOfpLoaded, value))
{
return;
}

this.simbriefOfpLoaded = value;
this.OnPropertyChanged();
this.SimbriefOfpLoadedChanged?.Invoke(this, value);
}
}

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Gets the Simbrief route location collection to draw a poly line on the map.
/// </summary>
/// -------------------------------------------------------------------------------------------------
public LocationCollection SimbriefRouteLocations { get; }

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Import simbrief flight plan navlog fixes.
/// </summary>
/// <remarks>
/// sushi.at, 22/03/2021.
/// </remarks>
/// <param name="ofp">
/// The ofp.
/// </param>
/// -------------------------------------------------------------------------------------------------
[SuppressMessage("ReSharper", "PossibleNullReferenceException")]
public void ImportSimbrief(XElement ofp)
{
if (this.SimbriefOfpLoaded)
{
return;
}

Debug.WriteLine("SimConnect is importing simbrief flight plan");

// Departure airport is not part of the navlog so add a position for the polyline for it
var originLat = double.Parse((string)ofp.Element("origin").Element("pos_lat"));
var originLon = double.Parse((string)ofp.Element("origin").Element("pos_long"));
UpdateGUIDelegate addOriginLocation = () => this.SimbriefRouteLocations.Add(new Location(originLat, originLon));
Application.Current.Dispatcher.Invoke(addOriginLocation);

var fixes = ofp.Element("navlog").Elements("fix");
foreach (var fix in fixes)
{
var ident = (string)fix.Element("ident");
var latitude = double.Parse((string)fix.Element("pos_lat"));
var longitude = double.Parse((string)fix.Element("pos_long"));
var type = (string)fix.Element("type");

UpdateGUIDelegate addLocation = () =>
{
this.SimbriefRouteLocations.Add(new Location(latitude, longitude));
if (type != "apt")
{
Debug.WriteLine($"SimConnect creating simbrief waypoint marker {ident}");
var newMarker = new SimbriefWaypointMarker(latitude, longitude, ident, type);
this.simbriefWaypointMarkers.Add(newMarker);
this.SimbriefWaypointMarkerAdded?.Invoke(this, newMarker);
}
};
Application.Current.Dispatcher.BeginInvoke(addLocation);
}

// Route
var sbOriginICAO = (string)ofp.Element("origin")?.Element("icao_code");
var sbDestinationICAO = (string)ofp.Element("destination")?.Element("icao_code");
var sbRoute = (string)ofp.Element("general")?.Element("route");
if (!string.IsNullOrEmpty(sbRoute))
{
// Add airports and runways to route
var sbOriginRunway = (string)ofp.Element("origin")?.Element("plan_rwy");
var sbDestinationRunway = (string)ofp.Element("destination")?.Element("plan_rwy");
if (!string.IsNullOrEmpty(sbOriginICAO))
{
var prefix = sbOriginICAO;
if (!string.IsNullOrEmpty(sbOriginRunway))
{
prefix += $"/{sbOriginRunway}";
}

sbRoute = $"{prefix} {sbRoute}";
}

if (!string.IsNullOrEmpty(sbDestinationICAO))
{
var postFix = sbDestinationICAO;
if (!string.IsNullOrEmpty(sbDestinationRunway))
{
postFix += $"/{sbDestinationRunway}";
}

sbRoute += $" {postFix}";
}

UpdateGUIDelegate updateRoute = () =>
{
this.Flight.Route = sbRoute;
this.OnPropertyChanged(nameof(this.Flight));
};
Application.Current.Dispatcher.BeginInvoke(updateRoute);
}

// Alternate route
var sbAlternateICAO = (string)ofp.Element("alternate")?.Element("icao_code");
var sbAlternateRoute = (string)ofp.Element("alternate")?.Element("route");
if (!string.IsNullOrEmpty(sbAlternateRoute))
{
// Add airport and runway to route
var sbAlternateRunway = (string)ofp.Element("alternate")?.Element("plan_rwy");
if (!string.IsNullOrEmpty(sbAlternateICAO))
{
var postFix = sbAlternateICAO;
if (!string.IsNullOrEmpty(sbAlternateRunway))
{
postFix += $"/{sbAlternateRunway}";
}

sbAlternateRoute += $" {postFix}";
}

UpdateGUIDelegate updateAlternateRoute = () =>
{
this.Flight.AlternateRoute = sbAlternateRoute;
this.OnPropertyChanged(nameof(this.Flight));
};
Application.Current.Dispatcher.BeginInvoke(updateAlternateRoute);
}

var sbOfpHtml = (string)ofp.Element("text")?.Element("plan_html");
if (!string.IsNullOrEmpty(sbOfpHtml))
{
// todo maybe can use this in the future if we find more performant html rendering control
//if (!sbOfpHtml.StartsWith("<html>"))
//{
// const string style = "body { background-color: #29323c; color: #c2c2c2; margin: -1px; } div { margin-top: 10px; margin-left: 10px; margin-bottom: -10px; }";
// sbOfpHtml = $"<html><head><style type=\"text/css\">{style}</style></head><body>{sbOfpHtml}</body></html>";
//}

// Remove comments
while (sbOfpHtml.Contains("<!--"))
{
var start = sbOfpHtml.IndexOf("<!--", StringComparison.InvariantCultureIgnoreCase);
var end = sbOfpHtml.IndexOf("-->", start, StringComparison.InvariantCultureIgnoreCase);
if (start != -1 && end != -1)
{
sbOfpHtml = sbOfpHtml.Substring(0, start) + sbOfpHtml.Substring(end + 3);
}
}

// Replace page breaks
sbOfpHtml = sbOfpHtml.Replace("<h2 style=\"page-break-after: always;\"> </h2>", "\r\n\r\n");

// Remove html tags
while (sbOfpHtml.Contains("<"))
{
var start = sbOfpHtml.IndexOf("<", StringComparison.InvariantCultureIgnoreCase);
var end = sbOfpHtml.IndexOf(">", start, StringComparison.InvariantCultureIgnoreCase);
if (start != -1 && end != -1)
{
// Are we removing an image?
if (sbOfpHtml.Substring(start, 4) == "<img")
{
sbOfpHtml = sbOfpHtml.Substring(0, start) + "---Image removed---" + sbOfpHtml.Substring(end + 1);
}
else
{
sbOfpHtml = sbOfpHtml.Substring(0, start) + sbOfpHtml.Substring(end + 1);
}
}
}

UpdateGUIDelegate setOfp = () =>
{
this.Flight.OfpHtml = sbOfpHtml;
this.OnPropertyChanged(nameof(this.Flight));
};
Application.Current.Dispatcher.BeginInvoke(setOfp);
}

this.SimbriefOfpLoaded = true;
}
}
}
4 changes: 2 additions & 2 deletions OpenSky.Agent.UdpXPlane11/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("dfbda2b8-5775-4766-be86-d729fcf20de1")]
[assembly: AssemblyVersion("0.5.12")]
[assembly: AssemblyFileVersion("0.5.12")]
[assembly: AssemblyVersion("0.5.13")]
[assembly: AssemblyFileVersion("0.5.13")]
4 changes: 2 additions & 2 deletions OpenSky.Agent/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]
[assembly: AssemblyVersion("0.5.12")]
[assembly: AssemblyFileVersion("0.5.12")]
[assembly: AssemblyVersion("0.5.13")]
[assembly: AssemblyFileVersion("0.5.13")]

// This allows us to detect debug mode in XAML
#if DEBUG
Expand Down
Loading