Example #1
0
 public MainWindow()
 {
     InitializeComponent();
     DataContext = new DiffViewModel {
         ShowMaxWarning = Visibility.Hidden
     };
 }
Example #2
0
        private void UpdateDiff()
        {
            if (!string.IsNullOrEmpty(SourceFile.Text) && !string.IsNullOrEmpty(TargetFile.Text))
            {
                Status.Text = "Loading... This will take a moment.";
                var diffGenerator = new OcadDiffGenerator(SourceFile.Text, TargetFile.Text);
                Task.Run(() =>
                {
                    var diff           = diffGenerator.GetDiff();
                    var sourceRenderer = new OcadRenderer(diff.Source);
                    var targetRenderer = new OcadRenderer(diff.Target);
                    sourceRenderer.EnsureSvg();
                    targetRenderer.EnsureSvg();

                    var viewModel = new DiffViewModel();

                    var limit = 200;

                    foreach (var obj in diff.DeletedObjects.Take(limit))
                    {
                        var minX          = obj.Poly.Min(p => p.X.Coordinate) - 1000;
                        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))
                    {
                        var minX = obj.Poly.Min(p => p.X.Coordinate) - 1000;
                        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 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 =
                        limit < diff.AddedObjects.Count + diff.DeletedObjects.Count
                            ? Visibility.Visible
                            : Visibility.Hidden;

                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        this.DataContext = viewModel;
                        Status.Text      = "";
                    }
                                                          );
                });
            }
        }
Example #3
0
        private void UpdateDiff()
        {
            if (!string.IsNullOrEmpty(SourceFile.Text) && !string.IsNullOrEmpty(TargetFile.Text))
            {
                Status.Text = "Loading... This will take a moment.";
                var diffGenerator = new OcadDiffGenerator(SourceFile.Text, TargetFile.Text);
                Task.Run(() =>
                {
                    var diff = diffGenerator.GetDiff();
                    var sourceRenderer = new OcadRenderer(diff.Source);
                    var targetRenderer = new OcadRenderer(diff.Target);
                    sourceRenderer.EnsureSvg();
                    targetRenderer.EnsureSvg();

                    var viewModel = new DiffViewModel();

                    var limit = 200;

                    foreach (var obj in diff.DeletedObjects.Take(limit))
                    {
                        var minX = obj.Poly.Min(p => p.X.Coordinate) - 1000;
                        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))
                    {
                        var minX = obj.Poly.Min(p => p.X.Coordinate) - 1000;
                        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 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 =
                        limit < diff.AddedObjects.Count + diff.DeletedObjects.Count
                            ? Visibility.Visible
                            : Visibility.Hidden;

                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        this.DataContext = viewModel;
                        Status.Text = "";
                    }
                );
                });

            }
        }
Example #4
0
 public MainWindow()
 {
     InitializeComponent();
     DataContext = new DiffViewModel {ShowMaxWarning = Visibility.Hidden};
 }