Skip to content

Commit

Permalink
19.2 (#6)
Browse files Browse the repository at this point in the history
* 19.2 Release changes
  • Loading branch information
AsposeOmrDeveloper authored Mar 1, 2019
1 parent 37d2e9c commit 3d78705
Show file tree
Hide file tree
Showing 14 changed files with 189 additions and 51 deletions.
12 changes: 11 additions & 1 deletion Aspose.OMR.Client/Aspose.OMR.Client/Controls/CustomCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,17 @@ protected override void OnMouseDown(MouseButtonEventArgs e)
{
base.OnMouseDown(e);

if (Equals(e.Source, this))
if (e.ChangedButton == MouseButton.Right)
{
// remember right click point position for precise paste and other context operations
var context = (TemplateViewModel)this.DataContext;
if (context != null)
{
context.PasteContextPosition = Mouse.GetPosition(this);
}
}

if (e.ChangedButton == MouseButton.Left && Equals(e.Source, this))
{
// remember click point in case of dragging
this.dragStartPoint = e.GetPosition(this);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,6 @@
<value>RootCanvas</value>
</data>
<data name="Version" xml:space="preserve">
<value>18.12</value>
<value>19.2</value>
</data>
</root>
8 changes: 4 additions & 4 deletions Aspose.OMR.Client/Aspose.OMR.Client/Utility/NamingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
namespace Aspose.OMR.Client.Utility
{
using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using ViewModels;

/// <summary>
Expand Down Expand Up @@ -44,7 +44,7 @@ public static class NamingManager
/// </summary>
/// <param name="pageQuestions">Existing page questions</param>
/// <returns>A new unused name for an element</returns>
public static string GetNextAvailableElementName(ObservableCollection<BaseQuestionViewModel> pageQuestions)
public static string GetNextAvailableElementName(IEnumerable<BaseQuestionViewModel> pageQuestions)
{
int currentTopNumber = 0;
foreach (BaseQuestionViewModel element in pageQuestions)
Expand All @@ -68,7 +68,7 @@ public static string GetNextAvailableElementName(ObservableCollection<BaseQuesti
/// </summary>
/// <param name="pageQuestions">Existing page questions</param>
/// <returns>A new unused name for the barcode</returns>
public static string GetNextAvailableBarcodeName(ObservableCollection<BaseQuestionViewModel> pageQuestions)
public static string GetNextAvailableBarcodeName(IEnumerable<BaseQuestionViewModel> pageQuestions)
{
int currentTopNumber = 0;
foreach (BaseQuestionViewModel element in pageQuestions)
Expand All @@ -92,7 +92,7 @@ public static string GetNextAvailableBarcodeName(ObservableCollection<BaseQuesti
/// </summary>
/// <param name="pageQuestions">Existing page questions</param>
/// <returns>A new unused name for the clip area</returns>
public static string GetNextAvailableAreaName(ObservableCollection<BaseQuestionViewModel> pageQuestions)
public static string GetNextAvailableAreaName(IEnumerable<BaseQuestionViewModel> pageQuestions)
{
int currentTopNumber = 0;
foreach (BaseQuestionViewModel element in pageQuestions)
Expand Down
23 changes: 16 additions & 7 deletions Aspose.OMR.Client/Aspose.OMR.Client/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -664,16 +664,25 @@ private bool CanMove()
return false;
}

private void OnPasteCommand(object control)
private void OnPasteCommand(object parameter)
{
// find parent canvas
UIElement uiItem = (UIElement)control;
var canvas = uiItem.FindChild<CustomCanvas>(Properties.Resources.RootCanvasName);
if (parameter is UIElement)
{
// find parent canvas
UIElement uiItem = (UIElement)parameter;
var canvas = uiItem.FindChild<CustomCanvas>(Properties.Resources.RootCanvasName);

// get mouse position to use for paste questions
Point mousePos = Mouse.GetPosition(canvas);
// get mouse position to use for paste questions
Point mousePos = Mouse.GetPosition(canvas);

((TemplateViewModel) this.SelectedTab).PasteElementsCommand.Execute(mousePos);
((TemplateViewModel)this.SelectedTab).PasteElementsCommand.Execute(mousePos);
}
else
{
// we have string parameter -> command comes from menu, pass string as it is
string stringPar = (string)parameter;
((TemplateViewModel)this.SelectedTab).PasteElementsCommand.Execute(stringPar);
}
}

private bool CanPaste()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ private void OnScanImage()
}
catch (Exception e)
{
DialogManager.ShowErrorDialog("Error occured : " + e.Message);
DialogManager.ShowErrorDialog("Error occurred : " + e.Message);
}
}

Expand Down
137 changes: 111 additions & 26 deletions Aspose.OMR.Client/Aspose.OMR.Client/ViewModels/TemplateViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,16 @@ public bool FinalizationComplete
}
}

/// <summary>
/// Position to paste using context menu
/// </summary>
public Point PasteContextPosition { get; set; }

/// <summary>
/// Position to paste based on viewport
/// </summary>
public Point PasteViewPortPosition { get; set; }

/// <summary>
/// Gets or sets the path that template was loaded from
/// </summary>
Expand Down Expand Up @@ -657,6 +667,8 @@ public bool CanValidate
/// </summary>
public event FinalizationApprovedDelegate ValidationSuccessful;

public double ViewportWidth { get; set; }

#region Commands

public RelayCommand LoadTemplateImageCommand { get; private set; }
Expand Down Expand Up @@ -884,6 +896,7 @@ private void OnLoadTemplateImage()
}

this.LoadTemplateImageFromFile(imagePath);
this.OnFitPageWidth(ViewportWidth);
}

/// <summary>
Expand Down Expand Up @@ -1032,12 +1045,7 @@ private void InitCommands()

this.CopyElementsCommand = new RelayCommand(x => this.OnCopyQuestions(), x => this.SelectedElements.Any());

this.PasteElementsCommand = new RelayCommand(x =>
{
if (x == null)
x = new Point(30, 30);
this.OnPasteQuestions((Point) x);
}, x => this.copiedQuestionsBuffer.Any());
this.PasteElementsCommand = new RelayCommand(x => this.ProcessPaste(x), x => this.copiedQuestionsBuffer.Any());

this.FitPageWidthCommand = new RelayCommand(x => this.OnFitPageWidth((double)x));
this.FitPageHeightCommand = new RelayCommand(x => this.OnFitPageHeight((Size)x));
Expand Down Expand Up @@ -1456,6 +1464,41 @@ private void OnCopyQuestions()
}
}

/// <summary>
/// Determine target position and call paste
/// </summary>
/// <param name="parameter"></param>
private void ProcessPaste(object parameter)
{
// default paste point
Point pastePoint = new Point(50, 50);

// in case of shortcut paste position is already specified as parameter
if (parameter is Point)
{
var temp = (Point)parameter;
if (temp.X >= 0 || temp.Y >= 0)
{
pastePoint = temp;
}
}
else if (parameter is string)
{
// based on source of command decide paste point
string parameterValue = (string)parameter;
if (string.Equals(parameterValue, "menu"))
{
pastePoint = PasteViewPortPosition;
}
else if (string.Equals(parameterValue, "context"))
{
pastePoint = PasteContextPosition;
}
}

this.OnPasteQuestions(pastePoint);
}

/// <summary>
/// Paste questions in certain position
/// </summary>
Expand All @@ -1464,59 +1507,101 @@ private void OnPasteQuestions(Point position)
{
this.ClearSelection();

// for the case when mouse position was out of UI change start position
if (position.X < 0 || position.Y < 0)
{
position.X = position.Y = 30;
}
Point pastePosition = position;
int count = this.copiedQuestionsBuffer.Count;

// calculate delta between topmost item and paste position
BaseQuestionViewModel topmostItem = this.copiedQuestionsBuffer.OrderByDescending(x => x.Top).Last();
double deltaTop = topmostItem.Top - position.Y;
double deltaLeft = topmostItem.Left - position.X;
double deltaTop = topmostItem.Top - pastePosition.Y;
double deltaLeft = topmostItem.Left - pastePosition.X;

// buffer for undo/redo
BaseQuestionViewModel[] copiedElements = new BaseQuestionViewModel[this.copiedQuestionsBuffer.Count];
// first, create copies and set their top and left according to initial paste position
List<BaseQuestionViewModel> copies = new List<BaseQuestionViewModel>();

for (int i = 0; i < this.copiedQuestionsBuffer.Count; i++)
for (int i = 0; i < count; i++)
{
// create new copy and update name and position
BaseQuestionViewModel copy = this.copiedQuestionsBuffer[i].CreateCopy();

copy.Name = GetNextElementName(copy);
copy.Top -= deltaTop;
copy.Left -= deltaLeft;
copies.Add(copy);
copy.Name = GetNextElementName(copy, copies);
}

// then, check out of bounds for all copies
double lowest = copies.OrderByDescending(x => x.Top + x.Height).Select(x => x.Top + x.Height).First();
double topmost = copies.OrderBy(x => x.Top).Select(x => x.Top).First();
double rightmost = copies.OrderByDescending(x => x.Left + x.Width).Select(x => x.Left + x.Width).First();
double leftmost = copies.OrderBy(x => x.Left).Select(x => x.Left).First();

// if any element is out of bounds, move all items accordingly
if (lowest > PageHeight)
{
double correctTop = lowest - PageHeight;
for (int i = 0; i < count; i++)
{
copies[i].Top -= correctTop;
}
}

if (topmost < 0)
{
for (int i = 0; i < count; i++)
{
copies[i].Top -= topmost;
}
}

this.OnAddQuestion(copy, true);
copy.IsSelected = true;
if (rightmost > PageWidth)
{
double correctLeft = rightmost - PageWidth;
for (int i = 0; i < count; i++)
{
copies[i].Left -= correctLeft;
}
}

copiedElements[i] = copy;
if (leftmost < 0)
{
for (int i = 0; i < count; i++)
{
copies[i].Left -= leftmost;
}
}

ActionTracker.TrackAction(new AddElementsAction(copiedElements, this.PageQuestions));
// finally, add copies on page
for (int i = 0; i < count; i++)
{
this.OnAddQuestion(copies[i], true);
copies[i].IsSelected = true;
}

// undo/redo tracker
ActionTracker.TrackAction(new AddElementsAction(copies.ToArray(), this.PageQuestions));
}

/// <summary>
/// Get next element name based on element type
/// </summary>
/// <param name="element">The element to get name for</param>
/// <param name="copies"></param>
/// <returns>Next avialable name for the element</returns>
private string GetNextElementName(BaseQuestionViewModel element)
private string GetNextElementName(BaseQuestionViewModel element, List<BaseQuestionViewModel> copies)
{
string nextName = string.Empty;
var type = element.GetType();

if (type == typeof(ChoiceBoxViewModel) || type == typeof(GridViewModel))
{
nextName = NamingManager.GetNextAvailableElementName(this.PageQuestions);
nextName = NamingManager.GetNextAvailableElementName(this.PageQuestions.Union(copies).ToList());
}
else if (type == typeof(BarcodeViewModel))
{
nextName = NamingManager.GetNextAvailableBarcodeName(this.PageQuestions);
nextName = NamingManager.GetNextAvailableBarcodeName(this.PageQuestions.Union(copies).ToList());
}
else if (type == typeof(ClipAreaViewModel))
{
nextName = NamingManager.GetNextAvailableAreaName(this.PageQuestions);
nextName = NamingManager.GetNextAvailableAreaName(this.PageQuestions.Union(copies).ToList());
}

return nextName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
TextAlignment="Center">
<TextBlock.Inlines>
<Run Text="Errors occured during Template correction. Some of the bubbles seem to be in invalid position." />
<Run Text="Errors occurred during Template correction. Some of the bubbles seem to be in invalid position." />
<Run FontStyle="Normal" Foreground="Black" Text="It could be caused by inaccurate mark-up and"/>
<Run FontStyle="Normal" Foreground="Red" Text="might greatly affect recognition quality." />
</TextBlock.Inlines>
Expand Down
2 changes: 1 addition & 1 deletion Aspose.OMR.Client/Aspose.OMR.Client/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
</MenuItem.Icon>
</MenuItem>

<MenuItem Header="_Paste" Command="{Binding PasteCommand}" ToolTipService.ShowOnDisabled="True" InputGestureText="Ctrl+V" ToolTip="Paste Copied Elements">
<MenuItem Header="_Paste" Command="{Binding PasteCommand}" CommandParameter="menu" ToolTipService.ShowOnDisabled="True" InputGestureText="Ctrl+V" ToolTip="Paste Copied Elements">
<MenuItem.Icon>
<Image Source="/Icons/Paste.png" Style="{StaticResource OpacityChangedImage}"/>
</MenuItem.Icon>
Expand Down
5 changes: 3 additions & 2 deletions Aspose.OMR.Client/Aspose.OMR.Client/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ private void OnWindowClosing(object sender, System.ComponentModel.CancelEventArg
if (!result)
{
e.Cancel = true;
return;
}
}

Expand All @@ -53,7 +54,7 @@ private void OnWindowClosing(object sender, System.ComponentModel.CancelEventArg
if (filesCount > 0)
{
if (DialogManager.ShowConfirmDialog("During Your session " + filesCount +
" files were uploaded for recognition to Aspose.Cloud Storage. Would like to delete them?"))
" files were uploaded for the recognition to the Aspose.Cloud Storage. Would you like to delete them?"))
{
try
{
Expand All @@ -62,7 +63,7 @@ private void OnWindowClosing(object sender, System.ComponentModel.CancelEventArg
}
catch
{
DialogManager.ShowErrorDialog("An error occured while attempting to delete files from storage. Please visit Cloud Dashboard to manage storage files.");
DialogManager.ShowErrorDialog("An error occurred while attempting to delete files from the storage. Please visit Cloud Dashboard to manage storage files.");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<Image Source="/Icons/Copy.png" />
</Button>

<Button ToolTip="Paste" Command="{Binding PasteElementsCommand}" Style="{StaticResource ImageButton}" Margin="0,0,5,0">
<Button ToolTip="Paste" Command="{Binding PasteElementsCommand}" CommandParameter="menu" Style="{StaticResource ImageButton}" Margin="0,0,5,0">
<Image Source="/Icons/Paste.png" />
</Button>
<Button ToolTip="Remove Selected Items" Command="{Binding RemoveElementCommand}" Style="{StaticResource ImageButton}">
Expand Down
6 changes: 3 additions & 3 deletions Aspose.OMR.Client/Aspose.OMR.Client/Views/TemplateView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
<!--Main area-->
<ScrollViewer Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" x:Name="MainScroll" KeyboardNavigation.DirectionalNavigation="None"
HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Focusable="False"
CanContentScroll="True" PreviewMouseWheel="OnPreviewMouseWheel"
AllowDrop="True" Drop="OnImageDrop" IsTabStop="False">
CanContentScroll="True" PreviewMouseWheel="OnPreviewMouseWheel" ScrollChanged="OnScrollChange"
AllowDrop="True" Drop="OnImageDrop" IsTabStop="False" Loaded="ScrollViewLoaded">

<Grid Background="{StaticResource BackgroundBrush}">
<Grid.LayoutTransform>
Expand All @@ -45,7 +45,7 @@
<Image Source="/Icons/Copy.png" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="_Paste" Command="{Binding PasteElementsCommand}"
<MenuItem Header="_Paste" Command="{Binding PasteElementsCommand}" CommandParameter="context"
ToolTipService.ShowOnDisabled="True" InputGestureText="Ctrl+V" ToolTip="Paste Copied Elements">
<MenuItem.Icon>
<Image Source="/Icons/Paste.png" />
Expand Down
Loading

0 comments on commit 3d78705

Please sign in to comment.