//read command name and based on that do execute command with special conditions private void executeCommand(Command c, string choice) { DataVertex dv = new DataVertex(); DataEdge de = new DataEdge(); VertexControl vc; VertexControl vc2; if (choice == "undo") { graphViewModel.graphState = GraphViewModel.GraphState.UNDO; } else { graphViewModel.graphState = GraphViewModel.GraphState.REDO; } switch (c.Name) { case "AddVertex": dv = c.Operands as DataVertex; int id = int.Parse(dv.Element_id); while (_mn.GlobalVertices.ContainsKey(dv.Element_id)) { id++; dv.Element_id = id.ToString(); } graphViewModel.CreateDataVertexBase(dv.typeOfVertex, dv.Element_id); vc = graphViewModel.GetVertexControlWithDataVertex(dv.Element_id); vc.SetPosition(c.Position); break; case "DeleteVertex": dv = c.Operands as DataVertex; vc = graphViewModel.GetVertexControlWithDataVertex(dv.Element_id); if (vc == null) { break; } Point p = new Point(); p.X = vc.GetPosition().X; p.Y = vc.GetPosition().Y; graphViewModel.DeleteVertex(dv); c.Position = p; break; case "AddEdge": de = c.Operands as DataEdge; if (de == null) { graphViewModel.graphState = GraphViewModel.GraphState.NORMAL; return; } vc = graphViewModel.GetVertexControlWithDataVertex(de.Source.Element_id); vc2 = graphViewModel.GetVertexControlWithDataVertex(de.Target.Element_id); if (vc == null) { vc = new VertexControl(de.Source); } EdgeControl ec = new EdgeControl(vc, vc2, de); graphViewModel.AddEdge(de, ec, vc); break; case "DeleteEdge": de = c.Operands as DataEdge; if (c.IsActive == false) { return; } graphViewModel.DeleteConnection(de.Source, de.Target.Element_id); break; } graphViewModel.graphState = GraphViewModel.GraphState.NORMAL; }