From c2b8ad131f9556b1044134725404352ba4b3ff3d Mon Sep 17 00:00:00 2001 From: gosha20777 Date: Thu, 26 Sep 2019 21:09:29 +0300 Subject: [PATCH] feat: add geo tags exec --- RescuerLaApp/Models/TextTableBuilder.cs | 118 ++++++++++++++++++ RescuerLaApp/RescuerLaApp.csproj | 1 + .../ViewModels/MainWindowViewModel.cs | 66 ++++++++++ RescuerLaApp/Views/MainWindow.xaml | 11 +- 4 files changed, 194 insertions(+), 2 deletions(-) create mode 100644 RescuerLaApp/Models/TextTableBuilder.cs diff --git a/RescuerLaApp/Models/TextTableBuilder.cs b/RescuerLaApp/Models/TextTableBuilder.cs new file mode 100644 index 0000000..12410e5 --- /dev/null +++ b/RescuerLaApp/Models/TextTableBuilder.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace RescuerLaApp.Models +{ + public interface ITextRow + { + String Output(); + void Output(StringBuilder sb); + Object Tag { get; set; } + } + + public class TextTableBuilder : IEnumerable + { + protected class TextRow : List, ITextRow + { + protected TextTableBuilder owner = null; + public TextRow(TextTableBuilder Owner) + { + owner = Owner; + if (owner == null) throw new ArgumentException("Owner"); + } + public String Output() + { + StringBuilder sb = new StringBuilder(); + Output(sb); + return sb.ToString(); + } + public void Output(StringBuilder sb) + { + sb.AppendFormat(owner.FormatString, this.ToArray()); + } + public Object Tag { get; set; } + } + + public String Separator { get; set; } + + protected List rows = new List(); + protected List colLength = new List(); + + public TextTableBuilder() + { + Separator = " "; + } + + public TextTableBuilder(String separator) + : this() + { + Separator = separator; + } + + public ITextRow AddRow(params object[] cols) + { + TextRow row = new TextRow(this); + foreach (object o in cols) + { + String str = o.ToString().Trim(); + row.Add(str); + if (colLength.Count >= row.Count) + { + int curLength = colLength[row.Count - 1]; + if (str.Length > curLength) colLength[row.Count - 1] = str.Length; + } + else + { + colLength.Add(str.Length); + } + } + rows.Add(row); + return row; + } + + protected String _fmtString = null; + public String FormatString + { + get + { + if (_fmtString == null) + { + String format = ""; + int i = 0; + foreach (int len in colLength) + { + format += String.Format("{{{0},-{1}}}{2}", i++, len, Separator); + } + format += "\r\n"; + _fmtString = format; + } + return _fmtString; + } + } + + public String Output() + { + StringBuilder sb = new StringBuilder(); + foreach (TextRow row in rows) + { + row.Output(sb); + } + return sb.ToString(); + } + + #region IEnumerable Members + + public IEnumerator GetEnumerator() + { + return rows.GetEnumerator(); + } + + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + { + return rows.GetEnumerator(); + } + + #endregion + } +} \ No newline at end of file diff --git a/RescuerLaApp/RescuerLaApp.csproj b/RescuerLaApp/RescuerLaApp.csproj index 47b8fb7..fca7e35 100755 --- a/RescuerLaApp/RescuerLaApp.csproj +++ b/RescuerLaApp/RescuerLaApp.csproj @@ -22,6 +22,7 @@ + diff --git a/RescuerLaApp/ViewModels/MainWindowViewModel.cs b/RescuerLaApp/ViewModels/MainWindowViewModel.cs index 585e124..4c7e306 100755 --- a/RescuerLaApp/ViewModels/MainWindowViewModel.cs +++ b/RescuerLaApp/ViewModels/MainWindowViewModel.cs @@ -7,6 +7,7 @@ using System.Reactive; using System.Reactive.Linq; using System.Runtime.InteropServices; +using System.Text; using System.Threading.Tasks; using Avalonia; using Avalonia.Controls; @@ -15,9 +16,11 @@ using MessageBox.Avalonia.DTO; using MessageBox.Avalonia.Enums; using MessageBox.Avalonia.Models; +using MetadataExtractor; using ReactiveUI; using ReactiveUI.Fody.Helpers; using Newtonsoft.Json; +using Directory = System.IO.Directory; namespace RescuerLaApp.ViewModels { @@ -68,6 +71,8 @@ public MainWindowViewModel() ShowPerestriansCommand = ReactiveCommand.Create(ShowPedestrians, canExecute); ImportAllCommand = ReactiveCommand.Create(ImportAll, canExecute); SaveAllImagesWithObjectsCommand = ReactiveCommand.Create(SaveAllImagesWithObjects, canExecute); + ShowAllMetadataCommand = ReactiveCommand.Create(ShowAllMetadata, canExecute); + ShowGeoDataCommand = ReactiveCommand.Create(ShowGeoData, canExecute); HelpCommand = ReactiveCommand.Create(Help); AboutCommand = ReactiveCommand.Create(About); ExitCommand = ReactiveCommand.Create(Exit, canExecute); @@ -130,6 +135,9 @@ public void UpdateFramesRepo() public ReactiveCommand ShowPerestriansCommand { get; } public ReactiveCommand SaveAllImagesWithObjectsCommand { get; } + + public ReactiveCommand ShowAllMetadataCommand { get; } + public ReactiveCommand ShowGeoDataCommand { get; } public ReactiveCommand HelpCommand { get; } public ReactiveCommand AboutCommand { get; } public ReactiveCommand ExitCommand { get; } @@ -542,6 +550,64 @@ public void Help() { OpenUrl("https://github.com/lizaalert/lacmus/wiki"); } + + public void ShowGeoData() + { + string msg = string.Empty; + int rows = 0; + var directories = ImageMetadataReader.ReadMetadata(Frames[SelectedIndex].Patch); + foreach (var directory in directories) + foreach (var tag in directory.Tags) + { + if (directory.Name.ToLower() == "gps") + { + if (tag.Name.ToLower() == "gps latitude" || + tag.Name.ToLower() == "gps longitude" || + tag.Name.ToLower() == "gps altitude") + { + rows++; + msg += $"{tag.Name}: {tag.Description}\n"; + } + } + } + + if (rows != 3) + msg = "This image have hot geo tags.\nUse `Show all metadata` more for more details."; + var msgbox = new MessageBox.Avalonia.MessageBoxWindow(new MessageBoxParams + { + Button = ButtonEnum.Ok, + ContentTitle = $"Geo position of {Path.GetFileName(Frames[SelectedIndex].Patch)}", + ContentMessage = msg, + Icon = Icon.Info, + Style = Style.None, + ShowInCenter = true + }); + msgbox.Show(); + } + + public void ShowAllMetadata() + { + var tb = new TextTableBuilder(); + tb.AddRow("Group", "Tag name", "Description"); + tb.AddRow("-----", "--------", "-----------"); + + + var directories = ImageMetadataReader.ReadMetadata(Frames[SelectedIndex].Patch); + foreach (var directory in directories) + foreach (var tag in directory.Tags) + tb.AddRow(directory.Name, tag.Name, tag.Description); + + var msgbox = new MessageBox.Avalonia.MessageBoxWindow(new MessageBoxParams + { + Button = ButtonEnum.Ok, + ContentTitle = $"Metadata of {Path.GetFileName(Frames[SelectedIndex].Patch)}", + ContentMessage = tb.Output(), + Icon = Icon.Info, + Style = Style.None, + ShowInCenter = true + }); + msgbox.Show(); + } public async void About() { diff --git a/RescuerLaApp/Views/MainWindow.xaml b/RescuerLaApp/Views/MainWindow.xaml index 14161ee..193bd5c 100755 --- a/RescuerLaApp/Views/MainWindow.xaml +++ b/RescuerLaApp/Views/MainWindow.xaml @@ -113,8 +113,15 @@ VerticalAlignment="Stretch" Background="{Binding ImageBrush}" Height="{Binding CanvasHeight, Mode=TwoWay}" - Width="{Binding CanvasWidth, Mode=TwoWay}" - /> + Width="{Binding CanvasWidth, Mode=TwoWay}"> + + + + + + + +