public MainWindowViewModel()
        {
            Graph = new PocGraph(true);

            Missioni  = new List <MissioneTreno>();
            Posizioni = new List <int>();


            //Add Layout Algorithm Types
            layoutAlgorithmTypes.Add("BoundedFR");
            layoutAlgorithmTypes.Add("Circular");
            layoutAlgorithmTypes.Add("CompoundFDP");
            layoutAlgorithmTypes.Add("EfficientSugiyama");
            layoutAlgorithmTypes.Add("FR");
            layoutAlgorithmTypes.Add("ISOM");
            layoutAlgorithmTypes.Add("KK");
            layoutAlgorithmTypes.Add("LinLog");
            layoutAlgorithmTypes.Add("Tree");

            //Pick a default Layout Algorithm Type
            LayoutAlgorithmType = "FR";
        }
        private void Refresh()
        {
            //List<PocVertex> existingVertices = new List<PocVertex>();
            //existingVertices.Add(new PocVertex(String.Format("Barn Rubble{0}", count), Colors.Green)); //0
            //existingVertices.Add(new PocVertex(String.Format("Frank Zappa{0}", count), Colors.Red)); //1
            //existingVertices.Add(new PocVertex(String.Format("Gerty CrinckleBottom{0}", count), Colors.Orange)); //2


            //foreach (PocVertex vertex in existingVertices)
            //    Graph.AddVertex(vertex);


            ////add some edges to the graph
            //AddNewGraphEdge(existingVertices[0], existingVertices[1]);
            //AddNewGraphEdge(existingVertices[0], existingVertices[2]);


            //NotifyPropertyChanged("Graph");



            if (Missioni == null)
            {
                return;
            }

            graph = new PocGraph(true);
            count++;

            List <PocVertex>            existingVertices = new List <PocVertex>();
            Dictionary <int, PocVertex> cdbInseriti      = new Dictionary <int, PocVertex>();

            foreach (MissioneTreno missione in Missioni)
            {
                foreach (int cdb in missione.CdbList)
                {
                    if (!cdbInseriti.ContainsKey(cdb))
                    {
                        string txt         = cdb.ToString();
                        Color  vertexColor = Colors.Black;
                        if (Posizioni.Contains(cdb))
                        {
                            vertexColor = Colors.Red;

                            int           idx = Posizioni.IndexOf(cdb);
                            MissioneTreno m   = Missioni[idx];
                            txt = txt + "(" + m.NomeTreno + ")";
                        }

                        PocVertex v = new PocVertex(txt, vertexColor);
                        existingVertices.Add(v);
                        cdbInseriti.Add(cdb, v);
                    }
                }
            }

            foreach (PocVertex vertex in existingVertices)
            {
                Graph.AddVertex(vertex);
            }

            Dictionary <KeyValuePair <int, int>, PocEdge> edgeInseriti = new Dictionary <KeyValuePair <int, int>, PocEdge>();

            for (int i = 0; i < Missioni.Count; i++)
            {
                MissioneTreno missione = Missioni[i];
                int           cdbprec  = -1;
                int           posTreno = -1;
                if (Posizioni.Count == Missioni.Count)
                {
                    posTreno = Posizioni[i];
                }


                foreach (int cdb in missione.CdbList)
                {
                    if (cdbprec != -1)
                    {
                        bool colorato = posTreno == cdbprec;

                        string  edgeString = string.Format("{0}-{1} Connected", cdbInseriti[cdbprec].ID, cdbInseriti[cdb].ID);
                        PocEdge newEdge    = new PocEdge(edgeString, cdbInseriti[cdbprec], cdbInseriti[cdb], colorato);

                        KeyValuePair <int, int> pair = new KeyValuePair <int, int>(cdbprec, cdb);

                        //se un edge c'è già ma io lo voglio colorato, tolgo quello che c'è già
                        if (colorato && edgeInseriti.ContainsKey(pair))
                        {
                            edgeInseriti.Remove(pair);
                        }

                        if (!edgeInseriti.ContainsKey(pair))
                        {
                            edgeInseriti.Add(pair, newEdge);
                        }
                    }
                    cdbprec = cdb;
                }
            }

            foreach (PocEdge edge in edgeInseriti.Values)
            {
                Graph.AddEdge(edge);
            }

            NotifyPropertyChanged("Graph");
        }