mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 08:36:29 +00:00
fix bugs with UI for gps denied
This commit is contained in:
@@ -52,7 +52,6 @@ public partial class Annotator
|
||||
|
||||
private readonly TimeSpan _thresholdBefore = TimeSpan.FromMilliseconds(50);
|
||||
private readonly TimeSpan _thresholdAfter = TimeSpan.FromMilliseconds(150);
|
||||
private readonly IGpsMatcherService _gpsMatcherService;
|
||||
private static readonly Guid SaveConfigTaskId = Guid.NewGuid();
|
||||
|
||||
public ObservableCollection<MediaFileInfo> AllMediaFiles { get; set; } = new();
|
||||
@@ -88,7 +87,6 @@ public partial class Annotator
|
||||
_dbFactory = dbFactory;
|
||||
_inferenceService = inferenceService;
|
||||
_inferenceClient = inferenceClient;
|
||||
_gpsMatcherService = gpsMatcherService;
|
||||
|
||||
Loaded += OnLoaded;
|
||||
Closed += OnFormClosed;
|
||||
@@ -101,7 +99,7 @@ public partial class Annotator
|
||||
{
|
||||
_appConfig.DirectoriesConfig.VideosDirectory = TbFolder.Text;
|
||||
await ReloadFiles();
|
||||
await SaveUserSettings();
|
||||
SaveUserSettings();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -132,7 +130,7 @@ public partial class Annotator
|
||||
_inferenceClient.Send(RemoteCommand.Create(CommandType.AIAvailabilityCheck));
|
||||
|
||||
Editor.GetTimeFunc = () => TimeSpan.FromMilliseconds(_mediaPlayer.Time);
|
||||
MapMatcherComponent.Init(_appConfig, _gpsMatcherService);
|
||||
MapMatcherComponent.Init(_appConfig, gpsMatcherService);
|
||||
}
|
||||
|
||||
private void OnLoaded(object sender, RoutedEventArgs e)
|
||||
@@ -217,9 +215,9 @@ public partial class Annotator
|
||||
Volume.ValueChanged += (_, newValue) =>
|
||||
_mediator.Publish(new VolumeChangedEvent((int)newValue));
|
||||
|
||||
SizeChanged += async (_, _) => await SaveUserSettings();
|
||||
LocationChanged += async (_, _) => await SaveUserSettings();
|
||||
StateChanged += async (_, _) => await SaveUserSettings();
|
||||
SizeChanged += (_, _) => SaveUserSettings();
|
||||
LocationChanged += (_, _) => SaveUserSettings();
|
||||
StateChanged += (_, _) => SaveUserSettings();
|
||||
|
||||
DgAnnotations.MouseDoubleClick += (sender, args) =>
|
||||
{
|
||||
@@ -269,10 +267,10 @@ public partial class Annotator
|
||||
|
||||
ShowAnnotations(res.Annotation, showImage: true);
|
||||
}
|
||||
private Task SaveUserSettings()
|
||||
private void SaveUserSettings()
|
||||
{
|
||||
if (_suspendLayout)
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
|
||||
_appConfig.UIConfig.LeftPanelWidth = MainGrid.ColumnDefinitions.FirstOrDefault()!.Width.Value;
|
||||
_appConfig.UIConfig.RightPanelWidth = MainGrid.ColumnDefinitions.LastOrDefault()!.Width.Value;
|
||||
@@ -282,7 +280,6 @@ public partial class Annotator
|
||||
_configUpdater.Save(_appConfig);
|
||||
return Task.CompletedTask;
|
||||
}, SaveConfigTaskId, TimeSpan.FromSeconds(5));
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private void ShowTimeAnnotations(TimeSpan time)
|
||||
@@ -508,7 +505,7 @@ public partial class Annotator
|
||||
_helpWindow.Activate();
|
||||
}
|
||||
|
||||
private void Thumb_OnDragCompleted(object sender, DragCompletedEventArgs e) => _ = SaveUserSettings();
|
||||
private void Thumb_OnDragCompleted(object sender, DragCompletedEventArgs e) => SaveUserSettings();
|
||||
|
||||
private void LvFilesContextOpening(object sender, ContextMenuEventArgs e)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Threading;
|
||||
using Azaion.Annotator.Controls;
|
||||
using Azaion.Annotator.DTO;
|
||||
using Azaion.Common;
|
||||
using Azaion.Common.Database;
|
||||
@@ -11,6 +14,8 @@ using Azaion.Common.Extensions;
|
||||
using Azaion.Common.Services;
|
||||
using Azaion.CommonSecurity.DTO;
|
||||
using Azaion.CommonSecurity.Services;
|
||||
using GMap.NET;
|
||||
using GMap.NET.WindowsPresentation;
|
||||
using LibVLCSharp.Shared;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -38,7 +43,9 @@ public class AnnotatorEventHandler(
|
||||
INotificationHandler<AnnotatorControlEvent>,
|
||||
INotificationHandler<VolumeChangedEvent>,
|
||||
INotificationHandler<AnnotationsDeletedEvent>,
|
||||
INotificationHandler<AnnotationAddedEvent>
|
||||
INotificationHandler<AnnotationAddedEvent>,
|
||||
INotificationHandler<SetStatusTextEvent>,
|
||||
INotificationHandler<GPSMatcherResultEvent>
|
||||
{
|
||||
private const int STEP = 20;
|
||||
private const int LARGE_STEP = 5000;
|
||||
@@ -363,4 +370,35 @@ public class AnnotatorEventHandler(
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Handle(SetStatusTextEvent e, CancellationToken cancellationToken)
|
||||
{
|
||||
mainWindow.Dispatcher.Invoke(() =>
|
||||
{
|
||||
mainWindow.StatusHelp.Text = e.Text;
|
||||
if (e.Color.HasValue)
|
||||
mainWindow.StatusHelp.Foreground = new SolidColorBrush(e.Color.Value);
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Handle(GPSMatcherResultEvent e, CancellationToken cancellationToken)
|
||||
{
|
||||
mainWindow.Dispatcher.Invoke(() =>
|
||||
{
|
||||
var mapMatcher = mainWindow.MapMatcherComponent;
|
||||
var marker = new GMapMarker(new PointLatLng(e.Latitude, e.Longitude));
|
||||
var ann = mapMatcher.Annotations[e.Index];
|
||||
marker.Shape = new CircleVisual(marker, Brushes.Blue)
|
||||
{
|
||||
Text = e.Image
|
||||
};
|
||||
mapMatcher.SatelliteMap.Markers.Add(marker);
|
||||
ann.Lat = e.Latitude;
|
||||
ann.Lon = e.Longitude;
|
||||
mapMatcher.SatelliteMap.Position = new PointLatLng(e.Latitude, e.Longitude);
|
||||
mapMatcher.SatelliteMap.ZoomAndCenterMarkers(null);
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
using Azaion.Common.Services;
|
||||
using GMap.NET;
|
||||
using GMap.NET.WindowsPresentation;
|
||||
using MediatR;
|
||||
|
||||
namespace Azaion.Annotator.Controls;
|
||||
|
||||
public class MapMatcherEventHandler(MapMatcher mapMatcher) : INotificationHandler<GPSMatcherResultEvent>
|
||||
{
|
||||
public Task Handle(GPSMatcherResultEvent result, CancellationToken cancellationToken)
|
||||
{
|
||||
mapMatcher.Dispatcher.Invoke(() =>
|
||||
{
|
||||
var marker = new GMapMarker(new PointLatLng(result.Latitude, result.Longitude));
|
||||
var ann = mapMatcher.Annotations[result.Index];
|
||||
marker.Shape = new CircleVisual(marker, System.Windows.Media.Brushes.Blue)
|
||||
{
|
||||
Text = result.Image
|
||||
};
|
||||
mapMatcher.SatelliteMap.Markers.Add(marker);
|
||||
ann.Lat = result.Latitude;
|
||||
ann.Lon = result.Longitude;
|
||||
mapMatcher.SatelliteMap.Position = new PointLatLng(result.Latitude, result.Longitude);
|
||||
mapMatcher.SatelliteMap.ZoomAndCenterMarkers(null);
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.Windows.Media;
|
||||
using MediatR;
|
||||
|
||||
namespace Azaion.Common.Events;
|
||||
|
||||
public class SetStatusTextEvent(string text, Color? color = null) : INotification
|
||||
{
|
||||
public string Text { get; set; } = text;
|
||||
public Color? Color { get; set; } = color;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using MediatR;
|
||||
|
||||
namespace Azaion.Common.Services;
|
||||
|
||||
public class GPSMatcherEventHandler(IGpsMatcherService gpsMatcherService) :
|
||||
INotificationHandler<GPSMatcherResultEvent>,
|
||||
INotificationHandler<GPSMatcherFinishedEvent>
|
||||
{
|
||||
public async Task Handle(GPSMatcherResultEvent result, CancellationToken cancellationToken) =>
|
||||
await gpsMatcherService.SetGpsResult(result, cancellationToken);
|
||||
|
||||
public async Task Handle(GPSMatcherFinishedEvent notification, CancellationToken cancellationToken) =>
|
||||
await gpsMatcherService.FinishGPS(notification, cancellationToken);
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
using System.IO;
|
||||
using Azaion.CommonSecurity;
|
||||
using Azaion.CommonSecurity.DTO;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
namespace Azaion.Common.Services;
|
||||
|
||||
@@ -11,12 +9,11 @@ public interface IGpsMatcherService
|
||||
{
|
||||
Task RunGpsMatching(string userRouteDir, double initialLatitude, double initialLongitude, CancellationToken detectToken = default);
|
||||
void StopGpsMatching();
|
||||
Task SetGpsResult(GPSMatcherResultEvent result, CancellationToken detectToken = default);
|
||||
Task FinishGPS(GPSMatcherFinishedEvent notification, CancellationToken cancellationToken);
|
||||
}
|
||||
|
||||
public class GpsMatcherService(IGpsMatcherClient gpsMatcherClient, ISatelliteDownloader satelliteTileDownloader, IOptions<DirectoriesConfig> dirConfig)
|
||||
: IGpsMatcherService,
|
||||
INotificationHandler<GPSMatcherResultEvent>,
|
||||
INotificationHandler<GPSMatcherFinishedEvent>
|
||||
public class GpsMatcherService(IGpsMatcherClient gpsMatcherClient, ISatelliteDownloader satelliteTileDownloader, IOptions<DirectoriesConfig> dirConfig) : IGpsMatcherService
|
||||
{
|
||||
private readonly DirectoriesConfig _dirConfig = dirConfig.Value;
|
||||
private const int ZOOM_LEVEL = 18;
|
||||
@@ -63,7 +60,7 @@ public class GpsMatcherService(IGpsMatcherClient gpsMatcherClient, ISatelliteDow
|
||||
{
|
||||
var filename = Path.GetFileName(fullName);
|
||||
File.Copy(Path.Combine(_userRouteDir, filename), Path.Combine(_routeDir, filename));
|
||||
return new { Filename = filename, Index = startIndex + index };
|
||||
return new { Filename = Path.GetFileNameWithoutExtension(fullName), Index = startIndex + index };
|
||||
})
|
||||
.ToDictionary(x => x.Filename, x => x.Index);
|
||||
|
||||
@@ -83,16 +80,16 @@ public class GpsMatcherService(IGpsMatcherClient gpsMatcherClient, ISatelliteDow
|
||||
gpsMatcherClient.Stop();
|
||||
}
|
||||
|
||||
public Task Handle(GPSMatcherResultEvent result, CancellationToken cancellationToken)
|
||||
public async Task SetGpsResult(GPSMatcherResultEvent result, CancellationToken detectToken = default)
|
||||
{
|
||||
_currentIndex = _currentRouteImages[result.Image];
|
||||
_currentRouteImages.Remove(result.Image);
|
||||
_currentLat = result.Latitude;
|
||||
_currentLon = result.Longitude;
|
||||
_currentIndex = _currentRouteImages[result.Image];
|
||||
return Task.CompletedTask;
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task Handle(GPSMatcherFinishedEvent notification, CancellationToken cancellationToken)
|
||||
public async Task FinishGPS(GPSMatcherFinishedEvent notification, CancellationToken cancellationToken)
|
||||
{
|
||||
if (_currentRouteImages.Count == 0 && _currentIndex < _allRouteImages.Count)
|
||||
await StartMatchingRound(_currentIndex);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using Azaion.CommonSecurity;
|
||||
using Azaion.CommonSecurity.DTO;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NetMQ;
|
||||
using NetMQ.Sockets;
|
||||
@@ -32,15 +34,17 @@ public class StartMatchingEvent
|
||||
public class GpsMatcherClient : IGpsMatcherClient
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly ILogger<GpsMatcherClient> _logger;
|
||||
private readonly string _requestAddress;
|
||||
private readonly RequestSocket _requestSocket = new();
|
||||
private readonly string _subscriberAddress;
|
||||
private readonly SubscriberSocket _subscriberSocket = new();
|
||||
private readonly NetMQPoller _poller = new();
|
||||
|
||||
|
||||
public GpsMatcherClient(IMediator mediator, IOptions<GpsDeniedClientConfig> gpsConfig)
|
||||
public GpsMatcherClient(IMediator mediator, IOptions<GpsDeniedClientConfig> gpsConfig, ILogger<GpsMatcherClient> logger)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_logger = logger;
|
||||
try
|
||||
{
|
||||
using var process = new Process();
|
||||
@@ -67,15 +71,20 @@ public class GpsMatcherClient : IGpsMatcherClient
|
||||
_requestAddress = $"tcp://{gpsConfig.Value.ZeroMqHost}:{gpsConfig.Value.ZeroMqPort}";
|
||||
_requestSocket.Connect(_requestAddress);
|
||||
|
||||
_subscriberAddress = $"tcp://{gpsConfig.Value.ZeroMqHost}:{gpsConfig.Value.ZeroMqSubscriberPort}";
|
||||
_subscriberAddress = $"tcp://{gpsConfig.Value.ZeroMqHost}:{gpsConfig.Value.ZeroMqReceiverPort}";
|
||||
_subscriberSocket.Connect(_subscriberAddress);
|
||||
_subscriberSocket.Subscribe("");
|
||||
_subscriberSocket.ReceiveReady += async (_, e) => await ProcessClientCommand(e.Socket);
|
||||
_subscriberSocket.ReceiveReady += async (sender, e) => await ProcessClientCommand(sender, e);
|
||||
|
||||
_poller.Add(_subscriberSocket);
|
||||
_poller.RunAsync();
|
||||
}
|
||||
|
||||
private async Task ProcessClientCommand(NetMQSocket socket)
|
||||
private async Task ProcessClientCommand(object? sender, NetMQSocketEventArgs e)
|
||||
{
|
||||
while (socket.TryReceiveFrameString(TimeSpan.Zero, out var str))
|
||||
while (e.Socket.TryReceiveFrameString(TimeSpan.FromMilliseconds(100), out var str))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(str))
|
||||
continue;
|
||||
@@ -93,10 +102,11 @@ public class GpsMatcherClient : IGpsMatcherClient
|
||||
if (parts.Length != 5)
|
||||
throw new Exception("Matching Result Failed");
|
||||
|
||||
var filename = Path.GetFileNameWithoutExtension(parts[1]);
|
||||
await _mediator.Publish(new GPSMatcherResultEvent
|
||||
{
|
||||
Index = int.Parse(parts[0]),
|
||||
Image = parts[1],
|
||||
Image = filename,
|
||||
Latitude = double.Parse(parts[2]),
|
||||
Longitude = double.Parse(parts[3]),
|
||||
MatchType = parts[4]
|
||||
@@ -104,6 +114,11 @@ public class GpsMatcherClient : IGpsMatcherClient
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void StartMatching(StartMatchingEvent e)
|
||||
|
||||
@@ -5,9 +5,11 @@ using System.Net.Http;
|
||||
using System.Net.Http.Json;
|
||||
using Azaion.Common.DTO;
|
||||
using Azaion.Common.DTO.Config;
|
||||
using Azaion.Common.Events;
|
||||
using Azaion.Common.Extensions;
|
||||
using Azaion.CommonSecurity;
|
||||
using Azaion.CommonSecurity.DTO;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
@@ -26,7 +28,8 @@ public class SatelliteDownloader(
|
||||
ILogger<SatelliteDownloader> logger,
|
||||
IOptions<MapConfig> mapConfig,
|
||||
IOptions<DirectoriesConfig> directoriesConfig,
|
||||
IHttpClientFactory httpClientFactory)
|
||||
IHttpClientFactory httpClientFactory,
|
||||
IMediator mediator)
|
||||
: ISatelliteDownloader
|
||||
{
|
||||
private const int INPUT_TILE_SIZE = 256;
|
||||
@@ -45,14 +48,18 @@ public class SatelliteDownloader(
|
||||
|
||||
public async Task GetTiles(double centerLat, double centerLon, double radiusM, int zoomLevel, CancellationToken token = default)
|
||||
{
|
||||
await mediator.Publish(new SetStatusTextEvent($"Завантажується супутникові зображення по координатах: центр: lat: {centerLat:F3} lon: {centerLon:F3} квадрат {radiusM}м * {radiusM}м, zoom: {zoomLevel}..."), token);
|
||||
//empty Satellite directory
|
||||
if (Directory.Exists(_satDirectory))
|
||||
Directory.Delete(_satDirectory, true);
|
||||
Directory.CreateDirectory(_satDirectory);
|
||||
|
||||
var downloadTilesResult = await DownloadTiles(centerLat, centerLon, radiusM, zoomLevel, token);
|
||||
await mediator.Publish(new SetStatusTextEvent("Завершено! Склеюється в 1 зображення..."), token);
|
||||
var image = ComposeTiles(downloadTilesResult.Tiles, token);
|
||||
if (image != null)
|
||||
if (image == null)
|
||||
return;
|
||||
await mediator.Publish(new SetStatusTextEvent("Розбиття на малі зображення для опрацювання..."), token);
|
||||
await SplitToTiles(image, downloadTilesResult, token);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,5 +15,5 @@ public class InferenceClientConfig : ExternalClientConfig
|
||||
|
||||
public class GpsDeniedClientConfig : ExternalClientConfig
|
||||
{
|
||||
public int ZeroMqSubscriberPort { get; set; }
|
||||
public int ZeroMqReceiverPort { get; set; }
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using Azaion.Common.DTO.Config;
|
||||
using Azaion.Common.Services;
|
||||
using Azaion.CommonSecurity.DTO;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
@@ -11,6 +12,13 @@ namespace Azaion.Annotator.Test;
|
||||
|
||||
public class GetTilesTestClass
|
||||
{
|
||||
[Fact]
|
||||
public void TestPath()
|
||||
{
|
||||
var filename = "./input/images-scaled\\AD000010.tif";
|
||||
filename = Path.GetFileName(filename);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetTilesTest()
|
||||
{
|
||||
@@ -26,7 +34,7 @@ public class GetTilesTestClass
|
||||
}), new OptionsWrapper<DirectoriesConfig>(new DirectoriesConfig
|
||||
{
|
||||
GpsSatDirectory = "satelliteMaps"
|
||||
}), httpClientFactory);
|
||||
}), httpClientFactory, Mock.Of<IMediator>());
|
||||
|
||||
await satelliteDownloader.GetTiles(48.2748909, 37.3834877, 600, 18);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user