Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Zytek committed Dec 17, 2014
1 parent c0fda30 commit 22c72dd
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ namespace NumberRecognizer.App.Common
public static class ItemClickCommand
{
/// <summary>
/// The command property
/// The command property.
/// </summary>
public static readonly DependencyProperty CommandProperty = DependencyProperty.RegisterAttached("Command", typeof(ICommand), typeof(ItemClickCommand), new PropertyMetadata(null, OnCommandPropertyChanged));

/// <summary>
/// Sets the command.
/// </summary>
/// <param name="d">The d.</param>
/// <param name="d">The dependent.</param>
/// <param name="value">The value.</param>
public static void SetCommand(DependencyObject d, ICommand value)
{
Expand All @@ -44,7 +44,7 @@ public static ICommand GetCommand(DependencyObject d)
/// <summary>
/// Called when [command property changed].
/// </summary>
/// <param name="d">The d.</param>
/// <param name="d">The dependent.</param>
/// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
private static void OnCommandPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ namespace NumberRecognizer.App.Common
public static class SelectionChangedCommand
{
/// <summary>
/// The command property
/// The command property.
/// </summary>
public static readonly DependencyProperty CommandProperty = DependencyProperty.RegisterAttached("Command", typeof(ICommand), typeof(SelectionChangedCommand), new PropertyMetadata(null, OnCommandPropertyChanged));

/// <summary>
/// Sets the command.
/// </summary>
/// <param name="d">The d.</param>
/// <param name="d">The dependent.</param>
/// <param name="value">The value.</param>
public static void SetCommand(DependencyObject d, ICommand value)
{
Expand All @@ -49,7 +49,7 @@ public static ICommand GetCommand(DependencyObject d)
/// <summary>
/// Called when [command property changed].
/// </summary>
/// <param name="d">The d.</param>
/// <param name="d">The dependent.</param>
/// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
private static void OnCommandPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
Source="{Binding ImageGroups}"
IsSourceGrouped="true"
ItemsPath="Images"/>

</Page.Resources>

<!--
Expand Down Expand Up @@ -106,8 +106,9 @@
<TextBlock x:Name="pageSubtitle" Text="- Training Images" Style="{StaticResource CustomSecondaryHeaderTextBlockStyle}" />
</StackPanel>
<AppBarButton Grid.Column="2" Command="{Binding UploadCommand}" HorizontalAlignment="Center"
VerticalAlignment="Center" Icon="Accept" Label="Create Network">
</AppBarButton>
VerticalAlignment="Center" Icon="Accept" Label="Create Network"/>
<ProgressRing Grid.Column="2" IsActive="{Binding IsLoading}" HorizontalAlignment="Center"
VerticalAlignment="Center" Width="100" Height="100" Foreground="Orange"/>
</Grid>
</Grid>
<Page.BottomAppBar>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<RowDefinition Height="140"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<ProgressRing IsActive="{Binding IsLoading}" Foreground="Orange" Grid.RowSpan="2" Height="100" Width="100"/>
<!--
TODO: Content should be placed within the following grid
to show details for the current item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
Padding="0" Margin="0" Height="110" Label="Reset Canvas"/>
<AppBarButton Command="{Binding RecognizeNumber}" Grid.Column="2" Grid.Row="1" Grid.RowSpan="2" Icon="Globe"
Padding="0" Margin="0" Height="110" Label="Recognize Number"/>
<ProgressRing IsActive="{Binding IsLoading}" Foreground="Orange" Grid.Column="2" Grid.Row="1" Grid.RowSpan="2"
Padding="0" Margin="0" Height="110" VerticalAlignment="Top" Width="100"/>
<TextBlock Grid.Row="3" Grid.Column="0" Text="Recognized Number" Style="{StaticResource CustomTextBlockStyle}" VerticalAlignment="Center"/>
<TextBox Text="{Binding Result.Number}" IsEnabled="False" FontSize="50" Grid.Column="0" Grid.Row="4" TextAlignment="Center" CharacterSpacing="500"/>
<!--<StackPanel Grid.Row="5" Grid.Column="0" Orientation="Horizontal" HorizontalAlignment="Center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace NumberRecognizer.App.ViewModel
using System.Windows.Input;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Mutzl.MvvmLight;
using NumberRecognition.Labeling;
using NumberRecognizer.App.Control;
using NumberRecognizer.App.DataModel;
Expand All @@ -24,7 +25,6 @@ namespace NumberRecognizer.App.ViewModel
using PropertyChanged;
using Windows.System.UserProfile;
using Windows.UI.Xaml.Media.Imaging;
using Mutzl.MvvmLight;

/// <summary>
/// Create Network Page ViewModel.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ public bool IsImageSelected
}
}

/// <summary>
/// Gets or sets a value indicating whether this instance is loading.
/// </summary>
/// <value>
/// <c>true</c> if this instance is loading; otherwise, <c>false</c>.
/// </value>
public bool IsLoading { get; set; }

/// <summary>
/// Gets or sets the name of the network.
/// </summary>
Expand Down Expand Up @@ -146,8 +154,8 @@ public LocalTrainingImage SelectedImage
/// </summary>
private void InitializeCommands()
{
this.UploadCommand = new DependentRelayCommand(this.CreateNetwork, () => this.ImageGroups.Count == 10, this, () => this);
this.DeleteImageCommand = new DependentRelayCommand(this.DeleteImage, () => this.SelectedImage != null, this, () => this);
this.UploadCommand = new DependentRelayCommand(this.CreateNetwork, () => this.ImageGroups.Count == 10 && this.IsLoading == false, this, () => this.ImageGroups, () => this.IsLoading);
this.DeleteImageCommand = new DependentRelayCommand(this.DeleteImage, () => this.SelectedImage != null && this.IsLoading == false, this, () => this.selectedImage, () => this.IsLoading);
}

/// <summary>
Expand All @@ -174,6 +182,7 @@ private void GroupImages()
/// </summary>
private async void CreateNetwork()
{
this.IsLoading = true;
ObservableCollection<TrainingImage> trainingImages = new ObservableCollection<TrainingImage>();

foreach (LocalTrainingImage trainingImageRT in this.Images)
Expand All @@ -193,6 +202,7 @@ private async void CreateNetwork()
Debug.WriteLine(ex.Message);
}

this.IsLoading = false;
App.RootFrame.Navigate(typeof(GroupedNetworksPage));
}

Expand All @@ -201,9 +211,11 @@ private async void CreateNetwork()
/// </summary>
private void DeleteImage()
{
this.IsLoading = true;
this.Images.Remove(this.SelectedImage);
this.selectedImage = null;
this.GroupImages();
this.IsLoading = false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace NumberRecognizer.App.ViewModel
public class GroupedNetworksPageViewModel : ViewModelBase
{
/// <summary>
/// The is synchronize enabled
/// The is synchronize enabled.
/// </summary>
private static bool isSyncEnabled = false;

Expand Down Expand Up @@ -216,8 +216,8 @@ private void InitializeDispatcherTimer()
/// <summary>
/// Dispatchers the timer_ tick.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
/// <param name="sender">The sender parameter.</param>
/// <param name="e">The event parameter.</param>
private async void DispatcherTimer_Tick(object sender, object e)
{
if (isSyncEnabled && !this.IsLoading)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ public NetworkDetailPageViewModel(NetworkInfo network)
/// </value>
public NetworkInfo Network { get; set; }

/// <summary>
/// Gets or sets a value indicating whether this instance is loading.
/// </summary>
/// <value>
/// <c>true</c> if this instance is loading; otherwise, <c>false</c>.
/// </value>
public bool IsLoading { get; set; }

/// <summary>
/// Gets or sets the chart fitness trend.
/// </summary>
Expand Down Expand Up @@ -91,6 +99,7 @@ private async Task<NetworkInfo> LoadNetworkDetails()
/// </summary>
private async void InitializeProperties()
{
this.IsLoading = true;
this.Network = await this.LoadNetworkDetails();

if (this.Network.Calculated && this.Network.FinalPoolFitnessLog != null)
Expand All @@ -115,6 +124,8 @@ private async void InitializeProperties()
this.MultiplePoolFitnessTrends.Add(list);
}
}

this.IsLoading = false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace NumberRecognizer.App.ViewModel
using System.Linq;
using System.Windows.Input;
using GalaSoft.MvvmLight;
using Mutzl.MvvmLight;
using NumberRecognition.Labeling;
using NumberRecognizer.App.Control;
using NumberRecognizer.App.Help;
Expand Down Expand Up @@ -62,6 +63,14 @@ public NetworkRecognizeViewModel(NetworkInfo networkInfo)
/// </value>
public NumberRecognitionResult Result { get; private set; }

/// <summary>
/// Gets or sets a value indicating whether this instance is loading.
/// </summary>
/// <value>
/// <c>true</c> if this instance is loading; otherwise, <c>false</c>.
/// </value>
public bool IsLoading { get; set; }

/// <summary>
/// Gets or sets the recognize number.
/// </summary>
Expand Down Expand Up @@ -107,7 +116,7 @@ public NetworkRecognizeViewModel(NetworkInfo networkInfo)
/// </summary>
private void InitializeCommands()
{
this.RecognizeNumber = new RelayCommand(this.ExecuteRecognizeNumber);
this.RecognizeNumber = new DependentRelayCommand(this.ExecuteRecognizeNumber, () => this.IsLoading == false, this, () => this.IsLoading);
this.ClearResult = new RelayCommand(this.ClearPage);
this.ResetInkCanvasCommand = new RelayCommand(this.ResetInkCanvas);
}
Expand All @@ -132,39 +141,44 @@ private async void ExecuteRecognizeNumber()
{
return;
}
else
{
this.IsLoading = true;
this.RecognitionImages = new ObservableCollection<RecognitionImage>();

this.RecognitionImages = new ObservableCollection<RecognitionImage>();
await LabelingHelperRT.ConnectedComponentLabelingForInkCanvasRT(this.InkCanvas);
foreach (ConnectedComponent component in this.InkCanvas.Labeling.ConnectedComponents.OrderBy(p => p.MinBoundingRect.Left).ToList())
{
try
{
RecognitionImage recognitionImage = new RecognitionImage
{
Height = (int)ImageHelperRT.ImageHeight,
Width = (int)ImageHelperRT.ImageWidth
};
recognitionImage.TransformFrom2DArrayToImageData(component.ScaledPixels);

this.RecognitionImages.Add(recognitionImage);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}

await LabelingHelperRT.ConnectedComponentLabelingForInkCanvasRT(this.InkCanvas);
foreach (ConnectedComponent component in this.InkCanvas.Labeling.ConnectedComponents.OrderBy(p => p.MinBoundingRect.Left).ToList())
{
try
{
RecognitionImage recognitionImage = new RecognitionImage
{
Height = (int)ImageHelperRT.ImageHeight,
Width = (int)ImageHelperRT.ImageWidth
};
recognitionImage.TransformFrom2DArrayToImageData(component.ScaledPixels);
NumberRecognizerServiceClient serviceProxy = new NumberRecognizerServiceClient();
this.Result = await serviceProxy.RecognizePhoneNumberAsync(this.Network.NetworkId, this.RecognitionImages);

this.RecognitionImages.Add(recognitionImage);
this.CreateChartData();
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}

try
{
NumberRecognizerServiceClient serviceProxy = new NumberRecognizerServiceClient();
this.Result = await serviceProxy.RecognizePhoneNumberAsync(this.Network.NetworkId, this.RecognitionImages);

this.CreateChartData();
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
this.IsLoading = false;
}
}

Expand Down

0 comments on commit 22c72dd

Please sign in to comment.