This project is read-only.

Manually changing vertex position

Apr 21, 2011 at 11:42 PM

I'm working on an application where I am manually processing the multitouch manipulation events. This is causing me to move, resize, and rotate the vertex objects through RenderTransforms affecting the RenderTransform matrix of the object. The objects respond correctly to the multitouch now, however the graph does not update. I realized I most likely need have the vertex that has changed alert the graph that it is changing, however that is where I am getting stuck.

I have been digging through the Graph# source code and found its "Graphsharp.Controls.PositionChangedEventArgs" and noticed that the PositionChanged event is actually declared in GraphSharp.Controls.GraphCanvas. However, it appears that no matter what I have raise the event, I cannot get the event to occur. Either that or the event is occuring and the case is that I have been looking in the wrong area. Here is the event that is manipulating the Vertex (more accurately it is manipulating the VertexControl). I just want to update the graph (ie move the edges) whenever I perform this event 


void controlManipulationDelta(object sender, ManipulationDeltaEventArgs e)
            GraphSharp.Controls.VertexControl element = e.Source as GraphSharp.Controls.VertexControl;

            NetVertex curVertex = element.Vertex as NetVertex;

            NetStateLayout curNetStateLayout = element.Parent as NetStateLayout;

            if (curVertex != null)
                //e.DeltaManipulation has the changes 
                // Scale is a delta multiplier; 1.0 is last size,  (so 1.1 == scale 10%, 0.8 = shrink 20%) 
                // Rotate = Rotation, in degrees
                // Pan = Translation, == Translate offset, in Device Independent Pixels 

                var deltaManipulation = e.DeltaManipulation;
                MatrixTransform curTransform = element.RenderTransform as MatrixTransform;
                System.Windows.Media.Matrix matrix = curTransform.Matrix;
                // find the old center; arguaby this could be cached 
                Point center = new Point(element.ActualWidth / 2, element.ActualHeight / 2);
                // transform it to take into account transforms from previous manipulations 
                center = matrix.Transform(center);
                //this will be a Zoom. 
                matrix.ScaleAt(deltaManipulation.Scale.X, deltaManipulation.Scale.Y, center.X, center.Y);
                // Rotation 
                matrix.RotateAt(e.DeltaManipulation.Rotation, center.X, center.Y);
                //Translation (pan) 
                matrix.Translate(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y);

                if (e.DeltaManipulation.Translation.X != 0 || e.DeltaManipulation.Translation.Y != 0)           //translation occured

                    GraphSharp.Controls.GraphCanvas curCanvas = element.RootCanvas as GraphSharp.Controls.GraphCanvas;

                    element.RootCanvas.RaiseEvent(new GraphSharp.Controls.PositionChangedEventArgs(GraphSharp.Controls.GraphCanvas.PositionChangedEvent, element, deltaManipulation.Translation.X, deltaManipulation.Translation.Y));
		    element.RaiseEvent(new GraphSharp.Controls.PositionChangedEventArgs(GraphSharp.Controls.GraphCanvas.PositionChangedEvent, element, deltaManipulation.Translation.X, deltaManipulation.Translation.Y))

                element.RenderTransform = new MatrixTransform(matrix);

                e.Handled = true;