private void CreateConvexGraph_Click(object sender, RoutedEventArgs e)
 {
     if ((string)this.CreateCovexGraph.Header == "Create Convex Graph")
     {
         this.Visibility = System.Windows.Visibility.Visible;
         #region clearing the nodes and edges in case of reset
         foreach (Node node in this.JGNodes)
         {
             node.Clear();
         }
         Node.LineToUVGuide.Clear();
         this.JGNodes.Clear();
         JGEdge.LineToEdgeGuide.Clear();
         foreach (JGEdge edge in this.edges)
         {
             edge.Clear();
         }
         this.edges.Clear();
         #endregion
         this._host.Menues.IsEnabled     = false;
         this._host.CommandReset.Click  += endBtn_Click;
         this._host.UIMessage.Text       = "Select points at the center of convex spaces";
         this._host.UIMessage.Visibility = System.Windows.Visibility.Visible;
         //this.JGraphMode = true;
         this._host.Cursor = Cursors.Pen;
         this._host.FloorScene.MouseLeftButtonDown += FloorScene_MouseLeftButtonDown;
     }
     else
     {
         this.Hide_show_Menu.IsEnabled = false;
         this.EditGraph.IsEnabled      = false;
         this.DrawJG.IsEnabled         = false;
         this.CreateCovexGraph.Header  = "Create Convex Graph";
         this.Children.Clear();
         //resetting the graph
         this.JGNodes.Clear();
         this.jgGraph = null;
         this.edges.Clear();
         this.nodeRemovingMode = false;
         edgeLine       = null;
         node1          = null;
         node2          = null;
         edgeRemoveMode = false;
         relatedEdges   = null;
         root           = null;
         JGHierarchy    = null;
     }
 }
        private void Mark_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this._host.Menues.IsEnabled     = true;
            this._host.UIMessage.Visibility = Visibility.Hidden;
            foreach (Node node in this.JGNodes)
            {
                node.Mark.MouseLeftButtonDown -= Mark_MouseLeftButtonDown;
            }
            Node n = null;

            Node.LineToUVGuide.TryGetValue((Line)sender, out n);
            if (n != null)
            {
                foreach (JGVertex item in jgGraph.Vertices)
                {
                    if (item.Point == n.Coordinates)
                    {
                        root = item;
                        break;
                    }
                }
            }
            if (root == null)
            {
                MessageBox.Show("Vertex not tracked");
                return;
            }
            n.Mark.Stroke = Brushes.DarkRed;
            #region create hierarchy
            HashSet <JGVertex> unExplored = new HashSet <JGVertex>();
            JGHierarchy = new List <HashSet <JGVertex> >();
            foreach (JGVertex item in jgGraph.Vertices)
            {
                if (item.Point != root.Point)
                {
                    unExplored.Add(item);
                }
            }
            HashSet <JGVertex> firstLevel = new HashSet <JGVertex>();
            firstLevel.Add(root);
            JGHierarchy.Add(firstLevel);
            HashSet <JGVertex> newLevel = new HashSet <JGVertex>();
            HashSet <JGVertex> level    = new HashSet <JGVertex>();
            level.Add(root);
            while (unExplored.Count != 0)
            {
                foreach (JGVertex item in level)
                {
                    foreach (JGVertex vertex in item.Connections)
                    {
                        if (unExplored.Contains(vertex))
                        {
                            newLevel.Add(vertex);
                        }
                    }
                }
                foreach (JGVertex vertex in newLevel)
                {
                    unExplored.Remove(vertex);
                }
                if (newLevel.Count == 0 && unExplored.Count != 0)
                {
                    MessageBox.Show("Justified Graph is not a linked graph!\nTry adding connections or removing unconnected nodes...");
                    return;
                }
                level.Clear();
                level.UnionWith(newLevel);
                HashSet <JGVertex> thisLevel = new HashSet <JGVertex>();
                foreach (JGVertex item in level)
                {
                    thisLevel.Add(item);
                }
                JGHierarchy.Add(thisLevel);
                newLevel.Clear();
            }

            #endregion
            drawGraph();
        }
 /// <summary>
 /// Clears this instance.
 /// </summary>
 public void Clear()
 {
     this._host = null;
     foreach (Node item in JGNodes)
     {
         item.Clear();
     }
     JGNodes.Clear();
     Node.LineToUVGuide.Clear();
     foreach (JGEdge item in edges)
     {
         item.Clear();
     }
     edges.Clear();
     JGEdge.LineToEdgeGuide.Clear();
     this.CreateCovexGraph.Click -= CreateConvexGraph_Click;
     this.Hide_show_Menu.Click   -= Hide_show_Menu_Click;
     this.AddVertex.Click        -= AddVertex_Click;
     this.RemoveVertex.Click     -= RemoveVertex_Click;
     this.MoveVertex.Click       -= MoveVertex_Click;
     this.AddEdge.Click          -= AddEdge_Click;
     this.RemoveEdge.Click       -= RemoveEdge_Click;
     this.DrawJG.Click           -= DrawJG_Click;
     this.JustifiedGraphMenu      = null;
     this.CreateCovexGraph        = null;
     this.EditGraph      = null;
     this.AddVertex      = null;
     this.RemoveVertex   = null;
     this.MoveVertex     = null;
     this.AddEdge        = null;
     this.RemoveEdge     = null;
     this.DrawJG         = null;
     this.Hide_show_Menu = null;
     if (this.JGNodes != null)
     {
         this.JGNodes.Clear();
         this.JGNodes = null;
     }
     this.jgGraph = null;
     if (this.edges != null)
     {
         this.edges.Clear();
         this.edges = null;
     }
     this.edgeLine = null;
     this.node1    = null;
     this.node2    = null;
     if (this.relatedEdges != null)
     {
         this.relatedEdges.Clear();
         this.relatedEdges = null;
     }
     this.root = null;
     if (this.JGHierarchy != null)
     {
         this.JGHierarchy.Clear();
         this.JGHierarchy = null;
     }
     Node.FloorScene   = null;
     Node.Transform    = null;
     JGEdge.FloorScene = null;
     JGEdge.Transform  = null;
 }