Skip to content

Commit

Permalink
added color highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
yannisgu committed Aug 18, 2015
1 parent 0705ecc commit 1178935
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
34 changes: 33 additions & 1 deletion src/OcadDiff.WPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
using System.Windows.Shapes;
using OcadDiff.Logic;
using OcadParser.Renderer;
using Svg;
using Svg.Transforms;
using Color = System.Drawing.Color;

namespace OcadDiff.WPF
Expand All @@ -30,7 +32,7 @@ public partial class MainWindow : Window
public MainWindow()
{
InitializeComponent();
DataContext = new DiffViewModel() {ShowMaxWarning = Visibility.Hidden};
DataContext = new DiffViewModel {ShowMaxWarning = Visibility.Hidden};
}

private void BrowseSourceFile_OnClick(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -68,6 +70,8 @@ private void UpdateDiff()
var diff = diffGenerator.GetDiff();
var sourceRenderer = new OcadRenderer(diff.Source);
var targetRenderer = new OcadRenderer(diff.Target);
sourceRenderer.EnsureSvg();
targetRenderer.EnsureSvg();

var viewModel = new DiffViewModel();

Expand All @@ -79,13 +83,26 @@ private void UpdateDiff()
var minY = -obj.Poly.Max(p => p.Y.Coordinate) - 1000;
var maxX = obj.Poly.Max(p => p.X.Coordinate) + 1000;
var maxY = -obj.Poly.Min(p => p.Y.Coordinate) + 1000;
var addedElements = new List<SvgElement>();
foreach (var element in sourceRenderer.ObjectElementMapping[obj])
{
var highlightElement = element.DeepCopy();
highlightElement.StrokeWidth = highlightElement.StrokeWidth + 100;
highlightElement.Stroke = new SvgColourServer(Color.Red);
highlightElement.StrokeOpacity= (float)0.5;
var index = sourceRenderer.Svg.Children.IndexOf(element);
sourceRenderer.Svg.Children.Insert(index, highlightElement);
addedElements.Add(highlightElement);
}

viewModel.Diffs.Add(new DiffViewModelItems()
{
LeftBitmap = sourceRenderer.GetBitmap(minX, minY, maxX, maxY, 300),
RightBitmap = targetRenderer.GetBitmap(minX, minY, maxX, maxY, 300),
Status = "Removed"
});

addedElements.ForEach(_ => sourceRenderer.Svg.Children.Remove(_));
}

foreach (var obj in diff.AddedObjects.Take(limit - diff.DeletedObjects.Count))
Expand All @@ -95,12 +112,27 @@ private void UpdateDiff()
var maxX = obj.Poly.Max(p => p.X.Coordinate) + 1000;
var maxY = -obj.Poly.Min(p => p.Y.Coordinate) + 1000;


var addedElements = new List<SvgElement>();
foreach (var element in targetRenderer.ObjectElementMapping[obj])
{
var highlightElement = element.DeepCopy();
highlightElement.StrokeWidth = highlightElement.StrokeWidth + 100;
highlightElement.Stroke = new SvgColourServer(Color.Green);
highlightElement.StrokeOpacity = (float)0.5;
highlightElement.Fill = SvgPaintServer.None;
var index = targetRenderer.Svg.Children.IndexOf(element);
targetRenderer.Svg.Children.Insert(index, highlightElement);
addedElements.Add(highlightElement);
}
viewModel.Diffs.Add(new DiffViewModelItems()
{
LeftBitmap = sourceRenderer.GetBitmap(minX, minY, maxX, maxY, 300),
RightBitmap = targetRenderer.GetBitmap(minX, minY, maxX, maxY, 300),
Status = "Added"
});

addedElements.ForEach(_ => targetRenderer.Svg.Children.Remove(_));
}

viewModel.ShowMaxWarning =
Expand Down
4 changes: 2 additions & 2 deletions src/OcadDiff.WPF/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.1.0.0")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyVersion("0.2.0.0")]
[assembly: AssemblyFileVersion("0.2.0.0")]

0 comments on commit 1178935

Please sign in to comment.