Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
hauerCodes committed Dec 17, 2014
1 parent a7e336d commit a68218e
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static async Task ConnectedComponentLabelingForInkCanvasRT(InkCanvasRT in
MinimumBoundingRectangle mbr = connectedComponent.MinBoundingRect;
Rectangle rectangle = new Rectangle()
{
Stroke = new SolidColorBrush(Colors.OrangeRed),
Stroke = new SolidColorBrush(Colors.Orange),
StrokeThickness = 2.0,
Width = mbr.Width / scale,
Height = mbr.Height / scale,
Expand Down
4 changes: 2 additions & 2 deletions NumberRecognizer/NumberRecognizer.App/Style/AppStyle.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<Setter Property="FontSize" Value="56"/>
<Setter Property="FontWeight" Value="Light"/>
<Setter Property="LineHeight" Value="40"/>
<Setter Property="Foreground" Value="OrangeRed" />
<Setter Property="Foreground" Value="Orange" />
<Setter Property="IsHitTestVisible" Value="false" />
<Setter Property="TextWrapping" Value="NoWrap" />
<Setter Property="VerticalAlignment" Value="Bottom" />
Expand All @@ -27,7 +27,7 @@
<Setter Property="FontSize" Value="26.667"/>
<Setter Property="FontWeight" Value="Light"/>
<Setter Property="LineHeight" Value="30"/>
<Setter Property="Foreground" Value="OrangeRed" />
<Setter Property="Foreground" Value="Orange" />
<Setter Property="IsHitTestVisible" Value="false" />
<Setter Property="TextWrapping" Value="NoWrap" />
<Setter Property="VerticalAlignment" Value="Bottom" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="Name &#42;" FontSize="28" Margin="2" VerticalAlignment="Bottom" Foreground="OrangeRed"/>
<TextBlock Grid.Row="0" Grid.Column="0" Text="Name &#42;" FontSize="28" Margin="2" VerticalAlignment="Bottom" Foreground="Orange"/>
<TextBox Grid.Row="0" Grid.Column="1" Name="NetworkNameTextBox" Text="{Binding NetworkName, Mode=TwoWay}" FontSize="30" Margin="0,0,240,0"/>
<AppBarButton Grid.Column="1" Grid.Row="0" Grid.RowSpan="2" Command="{Binding LabelingCommand}" Label="Show Bounding Rectangles" Icon="Crop" HorizontalAlignment="Right" Margin="0,-10,110,0"/>
<AppBarButton Grid.Column="1" Grid.Row="0" Grid.RowSpan="2" Command="{Binding NextCommand}" Label="View Training Data" Icon="Forward" HorizontalAlignment="Right" Margin="0,-10,0,0" />
<TextBlock Grid.Row="1" Grid.Column="1" Visibility="{Binding IsShowHint, Converter={StaticResource boolToVisibilityConverter}}"
Text="Please write at least one number on each canvas."
Style="{StaticResource SubheaderTextBlockStyle}" VerticalAlignment="Center" Foreground="OrangeRed"/>
Style="{StaticResource SubheaderTextBlockStyle}" VerticalAlignment="Center" Foreground="Orange"/>
<ScrollViewer Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<Grid>
<Grid.ColumnDefinitions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private void InitializePage()
{
Text = string.Format("{0} *", inkCanvasRT.Name),
FontSize = 28,
Foreground = new SolidColorBrush(Colors.OrangeRed),
Foreground = new SolidColorBrush(Colors.Orange),
VerticalAlignment = VerticalAlignment.Center,
Margin = inkCanvasRT.Margin
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<GroupStyle.HeaderTemplate>
<DataTemplate>
<Grid Margin="0,0,0,2">
<Button Foreground="OrangeRed"
<Button Foreground="Orange"
AutomationProperties.Name="Group Title"
Style="{StaticResource TextBlockButtonStyle}" >
<StackPanel Orientation="Horizontal">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
<AppBarButton Label="Create new Network" Icon="Add" Command="{Binding CreateNetworkCommand}"/>
<AppBarButton Label="Delete selected Network" Icon="Delete" Command="{Binding DeleteNetworkCommand}"/>
<AppBarSeparator/>
<AppBarButton Icon="Sync" Label="Refresh" Command="{Binding RefreshCommand}"/>
<AppBarButton Icon="Refresh" Label="Refresh Networks" Command="{Binding RefreshCommand}"/>
<AppBarToggleButton Icon="Sync" Label="Sync Networks (20 sec.)" IsChecked="{Binding IsSyncEnabled}" Command="{Binding ToggleSyncCommand}"/>
</StackPanel>
</Grid>
</AppBar>
Expand Down Expand Up @@ -146,7 +147,7 @@
<GroupStyle.HeaderTemplate>
<DataTemplate>
<Grid Margin="0,0,0,2">
<Button Foreground="OrangeRed"
<Button Foreground="Orange"
Style="{StaticResource TextBlockButtonStyle}" >
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Title}" Margin="0,-11,10,10" Style="{StaticResource SubheaderTextBlockStyle}" TextWrapping="NoWrap" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
/// <param name="e">The e.</param>
private void AppBar_Closed(object sender, object e)
{
networkGridView.SelectedItem = null;
//networkGridView.SelectedItem = null;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
Expand All @@ -56,9 +57,11 @@
<RowDefinition Height="50"/>
<RowDefinition Height="100"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="Please write your phone number on the canvas." Style="{StaticResource CustomTextBlockStyle}" VerticalAlignment="Center"/>
<control:InkCanvasRT x:Name="inkCanvas" Grid.Column="0" Grid.Row="1" />
<AppBarButton Command="{Binding RecognizeNumber}" Grid.Column="1" Grid.Row="1" Grid.RowSpan="2" Icon="Globe"
<TextBlock Grid.Row="0" Grid.ColumnSpan="3" Grid.Column="0" Text="Please write your phone number on the canvas." Style="{StaticResource CustomTextBlockStyle}" VerticalAlignment="Center"/>
<control:InkCanvasRT x:Name="InkCanvas" Grid.Column="0" Grid.Row="1" />
<AppBarButton Command="{Binding ResetInkCanvasCommand}" Grid.Column="1" Grid.Row="1" Grid.RowSpan="2" Icon="Delete"
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"/>
<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"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected override void OnNavigatedFrom(NavigationEventArgs e)
private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
this.viewModel = new NetworkRecognizeViewModel(e.NavigationParameter as NetworkInfo);
this.viewModel.InkCanvas = this.inkCanvas;
this.viewModel.InkCanvas = this.InkCanvas;
this.DataContext = viewModel;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ namespace NumberRecognizer.App.ViewModel
[ImplementPropertyChanged]
public class GroupedNetworksPageViewModel : ViewModelBase
{
/// <summary>
/// Gets or sets a value indicating whether [is synchronize enabled].
/// </summary>
/// <value>
/// <c>true</c> if [is synchronize enabled]; otherwise, <c>false</c>.
/// </value>
public static bool isSyncEnabled = false;

/// <summary>
/// Initializes a new instance of the <see cref="GroupedNetworksPageViewModel"/> class.
Expand Down Expand Up @@ -98,6 +105,14 @@ public bool IsNetworkSelected
/// </value>
public ICommand CreateNetworkCommand { get; private set; }

/// <summary>
/// Gets the toggle synchronize command.
/// </summary>
/// <value>
/// The toggle synchronize command.
/// </value>
public ICommand ToggleSyncCommand { get; private set; }

/// <summary>
/// Gets the delete network command.
/// </summary>
Expand Down Expand Up @@ -147,15 +162,76 @@ public bool IsNetworkSelected
[AlsoNotifyFor("IsNetworkSelected")]
public NetworkInfo SelectedNetwork { get; set; }

/// <summary>
/// Gets or sets a value indicating whether [is synchronize enabled].
/// </summary>
/// <value>
/// <c>true</c> if [is synchronize enabled]; otherwise, <c>false</c>.
/// </value>
public bool IsSyncEnabled
{
get
{
return isSyncEnabled;
}
set
{
isSyncEnabled = value;
if (isSyncEnabled)
{
this.dispatcherTimer.Start();
}
else if (this.dispatcherTimer.IsEnabled)
{
this.dispatcherTimer.Stop();
}
}
}

/// <summary>
/// The dispatcher timer.
/// </summary>
private DispatcherTimer dispatcherTimer;

/// <summary>
/// Initializes the properties.
/// </summary>
private async void InitializeProperties()
{
await this.LoadNetworksAsync();
this.InitializeDispatcherTimer();
this.SelectedNetwork = null;
}

/// <summary>
/// Initializes the dispatcher timer.
/// </summary>
private void InitializeDispatcherTimer()
{
this.dispatcherTimer = new DispatcherTimer();
this.dispatcherTimer.Tick += this.DispatcherTimer_Tick;
this.dispatcherTimer.Interval = new TimeSpan(0, 0, 20);
if (isSyncEnabled)
{
this.dispatcherTimer.Start();
}
}

/// <summary>
/// Dispatchers the timer_ tick.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
private async void DispatcherTimer_Tick(object sender, object e)
{
if (isSyncEnabled && !this.IsLoading){
await this.LoadNetworksAsync();
}else if (this.dispatcherTimer.IsEnabled && !isSyncEnabled){
this.dispatcherTimer.Stop();
}

}

/// <summary>
/// Synchronizes the networks asynchronous.
/// </summary>
Expand All @@ -175,6 +251,14 @@ private async Task LoadNetworksAsync()
return;
}

CreateNetworkGroups();

this.IsLoading = false;
RaisePropertyChanged(() => IsLoading);
}

private void CreateNetworkGroups()
{
this.NetworkGroups = new ObservableCollection<NetworkInfoGroup>();
NetworkInfoGroup calculated = new NetworkInfoGroup("calculated", "Calculated Networks");
foreach (NetworkInfo network in this.Networks.Where(p => p.Status == NetworkStatusType.Ready))
Expand All @@ -185,7 +269,7 @@ private async Task LoadNetworksAsync()
network.ChartFitness.Add(new ChartPopulation()
{
Name = key,
Value = network.FinalPatternFittness[key] * 100
Value = network.FinalPatternFittness[key]*100
});
}
calculated.Networks.Add(network);
Expand All @@ -199,17 +283,16 @@ private async Task LoadNetworksAsync()


NetworkInfoGroup uncalculated = new NetworkInfoGroup("uncalculated", "Uncalculated Networks");
foreach (NetworkInfo network in this.Networks.Where(p => p.Status != NetworkStatusType.Ready && p.Status != NetworkStatusType.Running))
foreach (
NetworkInfo network in
this.Networks.Where(p => p.Status != NetworkStatusType.Ready && p.Status != NetworkStatusType.Running))
{
uncalculated.Networks.Add(network);
}

this.NetworkGroups.Add(calculated);
this.NetworkGroups.Add(runnning);
this.NetworkGroups.Add(uncalculated);

this.IsLoading = false;
RaisePropertyChanged(() => IsLoading);
}

/// <summary>
Expand All @@ -223,12 +306,12 @@ private void InitializeCommands()
this.DeleteNetworkCommand = new DependentRelayCommand(this.DeleteNetwork,
() => this.SelectedNetwork != null, this,
() => this.SelectedNetwork);
this.RefreshCommand = new RelayCommand(() => LoadNetworksAsync());
this.NetworkClicked = new RelayCommand<NetworkInfo>((item) => App.RootFrame.Navigate(typeof(NetworkRecognizePage), item));
this.NetworkDetails = new DependentRelayCommand(() =>App.RootFrame.Navigate(typeof(NetworkDetailPage), SelectedNetwork),
this.RefreshCommand = new DependentRelayCommand(() => LoadNetworksAsync(), () => this.IsLoading == false && this.IsSyncEnabled == false, this, ()=> this.IsLoading, ()=> this.IsSyncEnabled );
this.NetworkClicked = new RelayCommand<NetworkInfo>((item) => App.RootFrame.Navigate(typeof(NetworkRecognizePage), item), (item) => item.Status == NetworkStatusType.Ready);
this.NetworkDetails = new DependentRelayCommand(() => App.RootFrame.Navigate(typeof(NetworkDetailPage), SelectedNetwork),
() => this.SelectedNetwork != null && this.SelectedNetwork.Calculated, this,
() => this.SelectedNetwork);

this.ToggleSyncCommand = new RelayCommand(() => this.IsSyncEnabled = !this.IsSyncEnabled);
this.SelectionChanged = new RelayCommand<SelectionChangedEventArgs>((args) =>
{
if (args.AddedItems.Count > 0)
Expand All @@ -252,8 +335,12 @@ private async void DeleteNetwork()
UICommand ok = new UICommand("OK");
ok.Invoked = async delegate(IUICommand command)
{
int delnetworkid = this.SelectedNetwork.NetworkId;
this.SelectedNetwork.Calculated = false;
this.SelectedNetwork.Status = NetworkStatusType.NotStarted;
CreateNetworkGroups();
NumberRecognizerServiceClient serviceClient = new NumberRecognizerServiceClient();
await serviceClient.DeleteNetworkAsync(this.SelectedNetwork.NetworkId);
await serviceClient.DeleteNetworkAsync(delnetworkid);
this.SelectedNetwork = null;

//refresh data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ private void InitializeCommands()
{
this.RecognizeNumber = new RelayCommand(this.ExecuteRecognizeNumber);
this.ClearResult = new RelayCommand(this.ClearPage);
this.ResetInkCanvasCommand = new RelayCommand(this.ResetInkCanvas);
}

/// <summary>
Expand Down Expand Up @@ -77,6 +78,14 @@ private void InitializeCommands()
/// </value>
public ICommand RecognizeNumber { get; set; }

/// <summary>
/// Gets or sets the reset ink canvas command.
/// </summary>
/// <value>
/// The reset ink canvas command.
/// </value>
public ICommand ResetInkCanvasCommand { get; set; }

/// <summary>
/// Gets or sets the clear result.
/// </summary>
Expand All @@ -101,6 +110,17 @@ private void InitializeCommands()
/// </value>
public ObservableCollection<RecognitionImage> RecognitionImages { get; set; }

/// <summary>
/// Resets the ink canvas.
/// </summary>
private void ResetInkCanvas()
{
if (this.InkCanvas != null)
{
this.InkCanvas.ClearInk();
}
}

/// <summary>
/// Executes the recognize number.
/// </summary>
Expand Down Expand Up @@ -159,7 +179,8 @@ private void CreateChartData()
var numberPropabilities = new ObservableCollection<ChartPopulation>();
foreach (KeyValuePair<char, double> pair in item.Probabilities)
{
numberPropabilities.Add(new ChartPopulation(){
numberPropabilities.Add(new ChartPopulation()
{
Name = pair.Key.ToString(),
Value = pair.Value < 0 ? 0 : pair.Value * 100,
});
Expand All @@ -171,7 +192,7 @@ private void CreateChartData()
});
}

RaisePropertyChanged(() => ChartResult);
RaisePropertyChanged(() => ChartResult);
}

/// <summary>
Expand Down

0 comments on commit a68218e

Please sign in to comment.