Skip to content

Commit

Permalink
Merge pull request #81 from lacmus-foundation/dev
Browse files Browse the repository at this point in the history
Dev: hotfix geoposition and filtering
  • Loading branch information
gosha20777 authored Apr 3, 2020
2 parents e5c34a5 + 54d6038 commit 12fef02
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 56 deletions.
4 changes: 2 additions & 2 deletions src/LacmusApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<Company>Lacmus Foundation</Company>
<AssemblyVersion>0.3.3.3</AssemblyVersion>
<FileVersion>0.3.3.3</FileVersion>
<AssemblyVersion>0.3.3.4</AssemblyVersion>
<FileVersion>0.3.3.4</FileVersion>
</PropertyGroup>
<ItemGroup>
<Compile Update="**\*.xaml.cs">
Expand Down
6 changes: 6 additions & 0 deletions src/Services/VM/PhotoVMReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ public async Task<PhotoViewModel[]> ReadAllFromDirByAnnotation(PhotoLoadType loa
var photo = await photoLoader.Load(photoPath, loadType);
var photoViewModel = new PhotoViewModel(id, photo, annotation);
photoViewModel.BoundBoxes = photoViewModel.GetBoundingBoxes();

if (photoViewModel.BoundBoxes.Any())
{
photoViewModel.Photo.Attribute = Attribute.WithObject;
photoViewModel.IsHasObject = true;
}
photoList.Add(photoViewModel);
id++;
count++;
Expand Down
11 changes: 11 additions & 0 deletions src/ViewModels/AboutViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Runtime.InteropServices;
using Avalonia.Controls;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Serilog;

namespace LacmusApp.ViewModels
Expand All @@ -16,6 +17,8 @@ public AboutViewModel(Window window)
OpenGithubCommand = ReactiveCommand.Create(OpenGithub);
OpenSiteCommand = ReactiveCommand.Create(OpenSite);
}

[Reactive] public string TextVersion { get; set; } = GetVersion() + ".";
public ReactiveCommand<Unit, Unit> OpenLicenseCommand { get; set; }
public ReactiveCommand<Unit, Unit> OpenGithubCommand { get; set; }
public ReactiveCommand<Unit, Unit> OpenSiteCommand { get; set; }
Expand Down Expand Up @@ -57,5 +60,13 @@ private void OpenUrl(string url)
Log.Error(e,$"Unable to ope url {url}.");
}
}

private static string GetVersion()
{
var revision = "";
if (typeof(Program).Assembly.GetName().Version.Revision != 0)
revision = $"preview-{typeof(Program).Assembly.GetName().Version.Revision}";
return $"{typeof(Program).Assembly.GetName().Version.Major}.{typeof(Program).Assembly.GetName().Version.Minor}.{typeof(Program).Assembly.GetName().Version.Build}.{revision}";
}
}
}
51 changes: 5 additions & 46 deletions src/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ private void SetupCommand(IObservable<bool> canExecute, IObservable<bool> canSwi
LastPageCommand = ReactiveCommand.Create(ShowLastPage);

ImportAllCommand = ReactiveCommand.Create(ImportFromXml, canExecute);
SaveAllImagesWithObjectsCommand = ReactiveCommand.Create(SaveAllImagesWithObjects, canExecute);
SaveFavoritesImagesCommand = ReactiveCommand.Create(SaveFavoritesImages, canExecute);
SaveAsCommand = ReactiveCommand.Create(SaveAs, canExecute);
ShowGeoDataCommand = ReactiveCommand.Create(ShowGeoData, canExecute);
AddToFavoritesCommand = ReactiveCommand.Create(AddToFavorites, canExecute);
HelpCommand = ReactiveCommand.Create(Help);
Expand Down Expand Up @@ -181,13 +180,11 @@ [Reactive] public int TotalPages
public ReactiveCommand<Unit, Unit> ImportAllCommand { get; set; }
public ReactiveCommand<Unit, Unit> LoadModelCommand { get; set; }
public ReactiveCommand<Unit, Unit> UpdateModelCommand { get; set; }
public ReactiveCommand<Unit, Unit> SaveAllImagesWithObjectsCommand { get; set; }
public ReactiveCommand<Unit, Unit> SaveFavoritesImagesCommand { get; set; }
public ReactiveCommand<Unit, Unit> SaveAsCommand { get; set; }
public ReactiveCommand<Unit, Unit> FirstPageCommand { get; set; }
public ReactiveCommand<Unit, Unit> PreviousPageCommand { get; set; }
public ReactiveCommand<Unit, Unit> NextPageCommand { get; set; }
public ReactiveCommand<Unit, Unit> LastPageCommand { get; set; }
public ReactiveCommand<Unit, Unit> ShowAllMetadataCommand { get; set; }
public ReactiveCommand<Unit, Unit> ShowGeoDataCommand { get; set; }
public ReactiveCommand<Unit, Unit> AddToFavoritesCommand { get; set; }
public ReactiveCommand<Unit, Unit> HelpCommand { get; set; }
Expand Down Expand Up @@ -508,48 +505,10 @@ private async void SaveAll()
_applicationStatusManager.ChangeCurrentAppStatus(Enums.Status.Ready, "");
}

private async void SaveAllImagesWithObjects()
private async void SaveAs()
{
try
{
if (!_photos.Items.Any())
{
Log.Warning("There are no photos to save.");
return;
}
_applicationStatusManager.ChangeCurrentAppStatus(Enums.Status.Working, "");
var writer = new PhotoVMWriter(_window);
await writer.WriteMany(_photos.Items.Where(x => x.Photo.Attribute == Attribute.WithObject));
_applicationStatusManager.ChangeCurrentAppStatus(Enums.Status.Ready, "Success | saved");
Log.Information($"Saved {_photos.Items.Count()} photos.");
}
catch (Exception ex)
{
Log.Error(ex, "Unable to save photos.");
}
_applicationStatusManager.ChangeCurrentAppStatus(Enums.Status.Ready, "");
}

private async void SaveFavoritesImages()
{
try
{
if (!_photos.Items.Any())
{
Log.Warning("There are no photos to save.");
return;
}
_applicationStatusManager.ChangeCurrentAppStatus(Enums.Status.Working, "");
var writer = new PhotoVMWriter(_window);
await writer.WriteMany(_photos.Items.Where(x => x.Photo.Attribute == Attribute.Favorite));
_applicationStatusManager.ChangeCurrentAppStatus(Enums.Status.Ready, "Success | saved");
Log.Information($"Saved {_photos.Items.Count()} photos.");
}
catch (Exception ex)
{
Log.Error(ex, "Unable to save photos.");
}
_applicationStatusManager.ChangeCurrentAppStatus(Enums.Status.Ready, "");
SaveAsWindow window = new SaveAsWindow();
window.Show();
}

public void OpenWizard()
Expand Down
15 changes: 13 additions & 2 deletions src/ViewModels/MetadataViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,28 @@ public MetadataViewModel(Window window, IReadOnlyList<Directory> metadata)

OpenYandexCommand = ReactiveCommand.Create(OpenYandex, this.IsValid());
OpenGoogleCommand = ReactiveCommand.Create(OpenGoogle, this.IsValid());
OpenOSMCommand = ReactiveCommand.Create(OpenOSM, this.IsValid());
}
public ReactiveCommand<Unit, Unit> OpenYandexCommand { get; set; }
public ReactiveCommand<Unit, Unit> OpenGoogleCommand { get; set; }
public ReactiveCommand<Unit, Unit> OpenOSMCommand { get; set; }

public void OpenYandex()
{
OpenUrl($"https://yandex.ru/maps/?ll={Longitude.Replace(',', '.')}%2C{Latitude.Replace(',', '.')}&z=15");
OpenUrl($"https://yandex.ru/maps/?ll={Longitude.Replace(',', '.')}%2C{Latitude.Replace(',', '.')}&z=15"+
$"&mode=whatshere&whatshere%5Bpoint%5D={Longitude.Replace(',', '.')}%2C{Latitude.Replace(',', '.')}&whatshere%5Bzoom%5D=15");
}
public void OpenGoogle()
{
OpenUrl($"https://www.google.ru/maps/@{Latitude.Replace(',', '.')},{Longitude.Replace(',', '.')},15z");
//https://www.google.com/maps/place/"&[Latitude]&"+"&[Longitude]&"/@"&[Latitude]&","&[Longitude]&",15z
OpenUrl($"https://www.google.ru/maps/place/{Latitude.Replace(',', '.')}+{Longitude.Replace(',', '.')}"+
$"/@{Latitude.Replace(',', '.')},{Longitude.Replace(',', '.')},15z");
}

public void OpenOSM()
{
OpenUrl($"https://www.openstreetmap.org/?mlat={Latitude.Replace(',', '.')}&mlon={Longitude.Replace(',', '.')}"+
$"#map=15/{Latitude.Replace(',', '.')}/{Longitude.Replace(',', '.')}");
}

private string TranslateGeoTag(string tag)
Expand Down
33 changes: 33 additions & 0 deletions src/ViewModels/SaveAsWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.IO;
using System.Reactive;
using Avalonia.Controls;
using DynamicData;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using ReactiveUI.Validation.Extensions;
using ReactiveUI.Validation.Helpers;

namespace LacmusApp.ViewModels
{
public class SaveAsWindowViewModel : ReactiveValidationObject<SaveAsWindowViewModel>
{
private readonly SourceList<PhotoViewModel> _photos;
public SaveAsWindowViewModel(Window window, SourceList<PhotoViewModel> photos)
{
_photos = photos;
this.ValidationRule(
viewModel => viewModel.OutputPath,
Directory.Exists,
path => $"Incorrect path {path}");

SaveCommand = ReactiveCommand.Create(OpenLicense);
}
[Reactive] public string OutputPath { get; set; }
public ReactiveCommand<Unit, Unit> SaveCommand { get; set; }

public void OpenLicense()
{

}
}
}
2 changes: 1 addition & 1 deletion src/ViewModels/SecondWizardViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private async void Save()
var dig = new OpenFolderDialog()
{
//TODO: Multi language support
Title = "CSelect folder to save"
Title = "Select folder to save"
};
var dirPath = await dig.ShowAsync(new Window());
OutputPath = dirPath;
Expand Down
2 changes: 1 addition & 1 deletion src/Views/AboutWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<TextBlock TextWrapping="Wrap" Classes="Caption" Text="Copyright (c) 2020 Lacmus Foundation." />
<StackPanel Orientation="Horizontal">
<TextBlock FontWeight="Heavy" Text="Version: " />
<TextBlock Text="0.3.3.preview-3 alpha." />
<TextBlock Text="{Binding TextVersion}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock FontWeight="Heavy" Text="Github page: " />
Expand Down
7 changes: 3 additions & 4 deletions src/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@
<Menu>
<MenuItem Name="mFile" Header="File">
<MenuItem Name="mFileOpen" Header="Open directory..." Command="{Binding OpenFileCommand}"/>
<MenuItem Name="mFileExportAll" Header="Import all from XML..." Command="{Binding ImportAllCommand}"/>
<MenuItem Name="mFileSave" Header="Export to XML..." Command="{Binding SaveAllCommand}"/>
<!-- <MenuItem Name="mFileSaveAllImagesWithObjects" Header="Save only images with pedestrians" Command="{Binding SaveAllImagesWithObjectsCommand}"/> -->
<MenuItem Name="mFileSaveFavorites" Header="Export favorites to XML..." Command="{Binding SaveFavoritesImagesCommand}"/>
<MenuItem Name="mFileExportAll" Header="Import from XML..." Command="{Binding ImportAllCommand}"/>
<MenuItem Name="mFileSave" Header="Save all" Command="{Binding SaveAllCommand}"/>
<!--<MenuItem Name="mFileSaveAs" Header="Save as..." Command="{Binding SaveAsCommand}"/>-->
<Separator></Separator>
<MenuItem Name="mFileExit" Header="Exit" Command="{Binding ExitCommand}"/>
</MenuItem>
Expand Down
5 changes: 5 additions & 0 deletions src/Views/MetadataWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,18 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button Grid.Column="0"
Content="Yandex"
Command="{Binding OpenYandexCommand}"/>
<Button Grid.Column="2"
Content="Google Maps"
Command="{Binding OpenGoogleCommand}"/>
<Button Grid.Column="4"
Content="Open Street Map"
Command="{Binding OpenOSMCommand}"/>
</Grid>
<Expander Grid.Row="6" Header="All metadata" IsExpanded="False" Margin="0 5 0 0">
<DataGrid Items="{Binding MetaDataCollection}">
Expand Down
34 changes: 34 additions & 0 deletions src/Views/SaveAsWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Icon="resm:LacmusApp.Assets.avalonia-logo.ico"
x:Class="LacmusApp.Views.SaveAsWindow"
CanResize="False"
Title="Save as"
Width="500"
Height="325">
<StackPanel>
<Border Classes="Card">
<StackPanel>
<TextBlock Margin="0 2" Classes="Heading" Text="Select options to save:" />
<TextBlock Margin="0 2" Classes="Caption" Text="Type of photos to save:" />
<ComboBox Margin="0 2 0 5" SelectedIndex="{Binding FilterIndex, Mode=TwoWay}">
<ComboBoxItem Content="All photos" />
<ComboBoxItem Content="Photos with objects" />
<ComboBoxItem Content="Favorite photos" />
</ComboBox>
<CheckBox Margin="0 2" IsChecked="True"
Content="Save source photos." />
<CheckBox Margin="0 2" IsChecked="True"
Content="Save XML annotations." />
<CheckBox Margin="0 2" IsChecked="False"
Content="Save photo with drawn bboxes." />
<CheckBox Margin="0 2" IsChecked="False"
Content="Save bbox crops." />
<TextBox Margin="0 5" UseFloatingWatermark="True"
Watermark="Enter input path here."
Text="{Binding OutputPath, Mode=TwoWay}" />
<Button Margin="0 2 0 5" Content="Save photos"/>
</StackPanel>
</Border>
</StackPanel>
</Window>
16 changes: 16 additions & 0 deletions src/Views/SaveAsWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Avalonia.Markup.Xaml;
using Avalonia.ReactiveUI;
using LacmusApp.ViewModels;
using ReactiveUI;

namespace LacmusApp.Views
{
public class SaveAsWindow : ReactiveWindow<SaveAsWindowViewModel>
{
public SaveAsWindow()
{
this.WhenActivated(disposables => { });
AvaloniaXamlLoader.Load(this);
}
}
}

0 comments on commit 12fef02

Please sign in to comment.