From 5121434f1330e1e570b559d63ff0e0b972bbe7ff Mon Sep 17 00:00:00 2001 From: mkonicek Date: Mon, 14 Mar 2011 12:21:16 +0100 Subject: [PATCH] Object graph - zoom using Ctrl+mouse wheel. Fixed edge labels. --- .../Visualizers/Controls/DragScrollViewer.cs | 12 +++++++++--- .../Visualizers/Graph/Drawing/GraphDrawer.cs | 13 +++++++------ .../Graph/Layout/GraphEdgeRouter.cs | 9 +++------ .../Graph/Layout/PositionedEdge.cs | 18 ++++-------------- .../Graph/Layout/SplineRouting/EdgeRouter.cs | 19 ++++++++++--------- .../Visualizers/Graph/ObjectGraphControl.xaml | 6 ++++-- .../Graph/ObjectGraphControl.xaml.cs | 9 +++++++++ 7 files changed, 46 insertions(+), 40 deletions(-) diff --git a/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Controls/DragScrollViewer.cs b/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Controls/DragScrollViewer.cs index 465e5fd4ac..53b59333a1 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Controls/DragScrollViewer.cs +++ b/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Controls/DragScrollViewer.cs @@ -22,9 +22,15 @@ namespace Debugger.AddIn.Visualizers.Controls this.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; this.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto; - this.PreviewMouseDown += new System.Windows.Input.MouseButtonEventHandler(DragScrollViewer_PreviewMouseDown); - this.PreviewMouseMove += new System.Windows.Input.MouseEventHandler(DragScrollViewer_PreviewMouseMove); - this.PreviewMouseUp += new System.Windows.Input.MouseButtonEventHandler(DragScrollViewer_PreviewMouseUp); + this.PreviewMouseDown += DragScrollViewer_PreviewMouseDown; + this.PreviewMouseMove += DragScrollViewer_PreviewMouseMove; + this.PreviewMouseUp += DragScrollViewer_PreviewMouseUp; + this.MouseWheel += DragScrollViewer_MouseWheel; + } + + void DragScrollViewer_MouseWheel(object sender, MouseWheelEventArgs e) + { + MessageBox.Show("w"); } void DragScrollViewer_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) diff --git a/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Drawing/GraphDrawer.cs b/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Drawing/GraphDrawer.cs index 04fad609e2..9ab700fba7 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Drawing/GraphDrawer.cs +++ b/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Drawing/GraphDrawer.cs @@ -137,8 +137,7 @@ namespace Debugger.AddIn.Visualizers.Graph Path AddEdgeToCanvas(PositionedEdge edge) { - PathFigure edgeSplineFigure = CreateEdgeSpline(edge); - + var edgeSplineFigure = CreateEdgeSpline(edge); PathGeometry geometryVisible = new PathGeometry(); geometryVisible.Figures.Add(edgeSplineFigure); geometryVisible.Figures.Add(CreateEdgeArrow(edge)); @@ -149,6 +148,11 @@ namespace Debugger.AddIn.Visualizers.Graph pathVisible.StrokeThickness = 1; pathVisible.Data = geometryVisible; + // remember this spline Path at PositionedEdge to be able to highlight edge from PositionedNodeProperty + edge.Spline = pathVisible; + // and remember the the edge for the spline, so that we can get edge name on spline mouse-over + pathVisible.Tag = edge; + PathGeometry geometryInVisible = new PathGeometry(); geometryInVisible.Figures.Add(edgeSplineFigure); @@ -179,12 +183,9 @@ namespace Debugger.AddIn.Visualizers.Graph Canvas.SetTop(this.edgeTooltip, mousePos.Y - 20); }; - // remember this spline Path at PositionedEdge to be able to highlight edge from PositionedNodeProperty - edge.Spline = pathVisible; - canvas.Children.Add(pathVisible); canvas.Children.Add(pathInVisible); - pathVisible.Tag = edge; + return pathVisible; } diff --git a/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Layout/GraphEdgeRouter.cs b/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Layout/GraphEdgeRouter.cs index 8a4ca5c266..471870cb1b 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Layout/GraphEdgeRouter.cs +++ b/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Layout/GraphEdgeRouter.cs @@ -23,12 +23,9 @@ namespace Debugger.AddIn.Visualizers.Graph.Layout public void RouteEdges(PositionedGraph posGraph) { - List routedEdges = router.RouteEdges(posGraph.Nodes, posGraph.Edges); - int i = 0; - // assume routedEdges come in the same order as posGraph.Edges - foreach (var edge in posGraph.Edges) { - SetEdgeSplinePoints(edge, routedEdges[i]); - i++; + Dictionary routedEdges = router.RouteEdges(posGraph.Nodes, posGraph.Edges); + foreach (var edgePair in routedEdges) { + SetEdgeSplinePoints(edgePair.Key, edgePair.Value); } } diff --git a/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Layout/PositionedEdge.cs b/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Layout/PositionedEdge.cs index fa9966dac8..0236c6835e 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Layout/PositionedEdge.cs +++ b/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Layout/PositionedEdge.cs @@ -19,14 +19,8 @@ namespace Debugger.AddIn.Visualizers.Graph.Layout /// public IList SplinePoints { - get - { - return splinePoints; - } - set - { - splinePoints = value; - } + get { return splinePoints; } + set { splinePoints = value; } } /// @@ -35,15 +29,11 @@ namespace Debugger.AddIn.Visualizers.Graph.Layout public System.Windows.Shapes.Path Spline { get; set; } public SplineRouting.IRect From { - get { - return this.Source.ContainingNode; - } + get { return this.Source.ContainingNode; } } public SplineRouting.IRect To { - get { - return this.Target; - } + get { return this.Target; } } } } diff --git a/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Layout/SplineRouting/EdgeRouter.cs b/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Layout/SplineRouting/EdgeRouter.cs index c7a87e840f..9cec3b0919 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Layout/SplineRouting/EdgeRouter.cs +++ b/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Layout/SplineRouting/EdgeRouter.cs @@ -16,24 +16,25 @@ namespace Debugger.AddIn.Visualizers.Graph.SplineRouting { } - public List RouteEdges(IEnumerable nodes, IEnumerable edges) + public Dictionary RouteEdges(IEnumerable nodes, IEnumerable edges) where TEdge : class, IEdge { var routeGraph = RouteGraph.InitializeVertices(nodes, edges); - List routedEdges = new List(); - var occludedEdges = new List(); - foreach (IEdge edge in edges) { + var routedEdges = new Dictionary(); + var occludedEdges = new List(); + foreach (var edge in edges) { var straightEdge = routeGraph.TryRouteEdgeStraight(edge); - if (straightEdge != null) - routedEdges.Add(straightEdge); - else + if (straightEdge != null) { + routedEdges[edge] = straightEdge; + } else { occludedEdges.Add(edge); + } } if (occludedEdges.Count > 0) { // there are some edges that couldn't be routed as straight lines routeGraph.ComputeVisibilityGraph(); - foreach (IEdge edge in occludedEdges) { + foreach (var edge in occludedEdges) { RoutedEdge routedEdge = routeGraph.RouteEdge(edge); - routedEdges.Add(routedEdge); + routedEdges[edge] = routedEdge; } } return routedEdges; diff --git a/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/ObjectGraphControl.xaml b/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/ObjectGraphControl.xaml index 5143bbf507..1495a27854 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/ObjectGraphControl.xaml +++ b/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/ObjectGraphControl.xaml @@ -39,8 +39,10 @@ - - + + diff --git a/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/ObjectGraphControl.xaml.cs b/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/ObjectGraphControl.xaml.cs index 449e4fc08e..923554febc 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/ObjectGraphControl.xaml.cs +++ b/src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/ObjectGraphControl.xaml.cs @@ -36,6 +36,8 @@ namespace Debugger.AddIn.Visualizers.Graph private PositionedGraph currentPosGraph; private GraphDrawer graphDrawer; + static double mouseWheelZoomSpeed = 0.05; + /// Long-lived map telling which graph nodes and content nodes the user expanded. private Expanded expanded = new Expanded(); @@ -220,5 +222,12 @@ namespace Debugger.AddIn.Visualizers.Graph e.Property.ObjectGraphProperty.TargetNode = null; LayoutGraph(this.objectGraph); } + + void Canvas_MouseWheel(object sender, MouseWheelEventArgs e) + { + if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) { + zoomSlider.Value += e.Delta > 0 ? mouseWheelZoomSpeed : -mouseWheelZoomSpeed; + } + } } }