Beispiel #1
0
 public void AccessTest1()
 {
     IPhysicsCore c = new Core();
     IPhysics p = new Physics(c);
     Vertex v1 = new Vertex(1.0, 1.0);
     Vertex v2 = new Vertex(1.0, 1.0);
     Edge e1 = new Edge(v1, v2);
 }
Beispiel #2
0
 private void MouseUp(object sender, MouseEventArgs e)
 {
     if (GraphMode == GraphMode.DraggingMode)
     {
         if (mouseState == MouseState.MovingVertex && clickedVertex != null)
         {
             clickedVertex = null;
         }
         mouseState = MouseState.Normal;
     }
 }
Beispiel #3
0
        private void MouseDown(object sender, MouseEventArgs e)
        {
            UIElement element = sender as UIElement;
            Line line = sender as Line;
            if (line == null)
            {
                clickedVertex = VertexDict[element];
                clickedEdge = null;
            }
            if (line != null)
            {
                clickedEdge = EdgeDict[line];
                clickedVertex = null;
            }

            SelectionProcessing();
            previousMousePosition = e.GetPosition(canvas);

            if (GraphMode == GraphMode.DraggingMode)
            {
                mouseState = MouseState.MovingVertex;
                ViewWindow.Static = true;
            }
            else //adding new edge
            {
                if (line == null)
                {
                    addedEdge.X1 = addedEdge.X2 = Canvas.GetLeft(clickedVertex.Ellipse) + VertexSize / 2.0;
                    addedEdge.Y1 = addedEdge.Y2 = Canvas.GetTop(clickedVertex.Ellipse) + VertexSize / 2.0;
                    addedEdge.Visibility = Visibility.Visible;
                }
            }
        }
Beispiel #4
0
        private void CanvasMouseDown(object sender, MouseEventArgs e)
        {
            if (!(e.OriginalSource is Canvas)) return;
            if (mouseState != MouseState.Normal) return;

            Point mousePosition = e.GetPosition(canvas);

            mouseShiftDownPosition = mousePosition;
            if (Forms.Control.ModifierKeys == Forms.Keys.Shift || Forms.Control.ModifierKeys == (Forms.Keys.Shift | Forms.Keys.Control))
            {
                mouseShiftDown = true;
                canvas.CaptureMouse();

                Canvas.SetLeft(selectionBox, mouseShiftDownPosition.X);
                Canvas.SetTop(selectionBox, mouseShiftDownPosition.Y);
                selectionBox.Width = 0;
                selectionBox.Height = 0;

                selectionBox.Visibility = Visibility.Visible;
            }

            if (GraphMode == GraphMode.DraggingMode)
            {
                if(!(Forms.Control.ModifierKeys == Forms.Keys.Control || Forms.Control.ModifierKeys == (Forms.Keys.Shift | Forms.Keys.Control)))
                {
                    CleanSelectedVertices();
                    CleanSelectedEdges();
                }
                previousMousePosition = mousePosition;
                mouseState = MouseState.MovingGraph;
                ViewWindow.Static = true;
            }
            else if (GraphMode == GraphMode.InsertingMode)
            {
                if (Forms.Control.ModifierKeys == Forms.Keys.Shift || Forms.Control.ModifierKeys == (Forms.Keys.Shift | Forms.Keys.Control))
                    return;
                Point corePos = ViewWindow.VisualToCorePosition(mousePosition);
                clickedVertex = Core.CreateVertex(corePos.X, corePos.Y);
                SelectionProcessing();
            }
        }
Beispiel #5
0
 private void AddEventHandlers(UIElement element, Vertex v)
 {
     VertexDict.Add(element, v);
     element.MouseLeftButtonDown += MouseDown;
     element.MouseLeftButtonUp += VertexMouseUp;
     element.MouseLeftButtonUp += MouseUp;
     element.MouseMove += MouseMove;
 }
Beispiel #6
0
        /// <summary>
        /// Deletes a vertex from the main canvas.
        /// </summary>
        /// <param name="vertex">Vertex to be deleted</param>
        public void RemoveVisualVertex(Vertex vertex)
        {
            VertexDict.Remove(vertex.Ellipse);
            VertexDict.Remove(vertex.VisualLabel);

            canvas.Children.Remove(vertex.Ellipse);
            canvas.Children.Remove(vertex.VisualLabel);
            vertex.Ellipse = null;
            vertex.VisualLabel = null;
        }
Beispiel #7
0
        /// <summary>
        /// Draws a vertex on the main canvas based on its current position.
        /// </summary>
        /// <param name="v">Vertex to be redrawn</param>
        public void RedrawVertex(Vertex v)
        {
            Point visualPosition = ViewWindow.CoreToVisualPosition(v.Position);
            Canvas.SetLeft(v.Ellipse, visualPosition.X - VertexSize / 2.0);
            Canvas.SetTop(v.Ellipse, visualPosition.Y - VertexSize / 2.0);

            Canvas.SetLeft(v.VisualLabel, visualPosition.X - v.VisualLabel.ActualWidth / 2.0 - VertexSize / 4.0);
            Canvas.SetTop(v.VisualLabel, visualPosition.Y - VertexSize / 1.7);

            if (v == clickedVertex)
            {
                addedEdge.X1 = Canvas.GetLeft(clickedVertex.Ellipse) + VertexSize / 2.0;
                addedEdge.Y1 = Canvas.GetTop(clickedVertex.Ellipse) + VertexSize / 2.0;
            }
        }
Beispiel #8
0
 /// <summary>
 /// Creates Core vertex and related Visual vertex.
 /// </summary>
 /// <param name="x">X coordinate.</param>
 /// <param name="y">Y coordinate.</param>
 /// <param name="label">label of vertex</param>
 public Vertex CreateVertex(double x, double y, string label = "")
 {
     Vertex v = new Vertex(x, y, label);
     Vertices.Add(v);
     visual.CreateVisualVertex(v);
     return v;
 }
Beispiel #9
0
 /// <summary>
 /// Unpins vertex.
 /// </summary>
 /// <param name="vertex">Vertex to be unpinned.</param>
 public void Unpin(Vertex vertex)
 {
     lock (this) { vertex.Pinned = false; }
 }
Beispiel #10
0
 /// <summary>
 /// Removes every edge connected with vertex intended to be removed.
 /// </summary>
 /// <param name="v">Vertex intended to be removed.</param>
 private void RemoveEdgesInVertex(Vertex v)
 {
     while (v.Edges.Count > 0)
         RemoveEdge(v.Edges[0]);
 }
Beispiel #11
0
 /// <summary>
 /// Sets position of a given vertex.
 /// </summary>
 /// <param name="vertex">Vertex whose position should be set.</param>
 /// <param name="x">X coordinate.</param>
 /// <param name="y">Y coordinate.</param>
 public void SetPosition(Vertex vertex, double x, double y)
 {
     lock(this)
     {
         vertex.X = x;
         vertex.Y = y;
     }
 }
Beispiel #12
0
 /// <summary>
 /// Removes Core vertex and related Visual vertex.
 /// </summary>
 /// <param name="v">Vertex to be removed.</param>
 public void RemoveVertex(Vertex v)
 {
     RemoveEdgesInVertex(v);
     Vertices.Remove(v);
     visual.RemoveVisualVertex(v);
 }
Beispiel #13
0
 /// <summary>
 /// Pins vertex, so its position won't be changed by Physics.
 /// </summary>
 /// <param name="vertex">Vertex to be pinned.</param>
 public void Pin(Vertex vertex)
 {
     lock (this) { vertex.Pinned = true; }
 }
Beispiel #14
0
 private void Select(Vertex v)
 {
     if (v == null) return;
     if (v.Pinned)
         SelectedAndPinnedVertices++;
     v.Selected = true;
     v.changeColor(selectVertexColor);
     SelectedVertices.Add(v);
 }
Beispiel #15
0
        /// <summary>
        /// Creates a circle that represents a vertex on a canvas and binds them together.
        /// </summary>
        /// <param name="vertex">Vertex to be visually represented</param>
        public void CreateVisualVertex(Vertex vertex)
        {
            Ellipse e = new Ellipse
            {
                Height = VertexSize,
                Width = VertexSize,
                Fill = vertexBrush,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
            };

            canvas.Children.Add(e);
            Canvas.SetZIndex(e, 2);

            AddEventHandlers(e, vertex);
            vertex.Ellipse = e;

            TextBlock t = new TextBlock
            {
                FontWeight = FontWeights.Bold,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                FontSize = VertexSize * 0.75,
                Height = VertexSize,
                TextWrapping = TextWrapping.Wrap,
                Text = vertex.Label,
                Margin = new Thickness(VertexSize / 4, 0, 0, VertexSize / 10.0),

            };
            canvas.Children.Add(t);
            Canvas.SetZIndex(t, 3);

            AddEventHandlers(t, vertex);
            vertex.VisualLabel = t;

            RedrawVertex(vertex);
        }
Beispiel #16
0
 private void Unselect(Vertex v)
 {
     if (v.Pinned)
         SelectedAndPinnedVertices--;
     v.Selected = false;
     v.changeColor(vertexColor); // TODO: What if there was pinned before select? Back to pinnedColor?
     SelectedVertices.Remove(v);
 }
Beispiel #17
0
 /// <summary>
 /// Creates Core edge and related Visual edge.
 /// </summary>
 /// <param name="v1">Endpoint of creating edge.</param>
 /// <param name="v2">Endpoint of creating edge.</param>
 public Edge CreateEdge(Vertex v1, Vertex v2)
 {
     Edge e = new Edge(v1, v2);
     Edges.Add(e);
     v1.Edges.Add(e);
     v2.Edges.Add(e);
     visual.CreateVisualEdge(e);
     return e;
 }