コード例 #1
0
        static void gviewer_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            Microsoft.Msagl.GraphViewerGdi.GViewer gviewer = sender as Microsoft.Msagl.GraphViewerGdi.GViewer;
            float viewerX, viewerY;

            if (gviewer != null)
            {
                gviewer.ScreenToSource(e.Location.X, e.Location.Y, out viewerX, out viewerY);
                gviewer.SetToolTip(tt, new Point(viewerX, viewerY).ToString());
                tt.ShowAlways = true;
            }
        }
コード例 #2
0
        public LogReaderControl()
        {
            InitializeComponent();

            m_Culture = new CultureInfo("en-US");

            m_Viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer
            {
                Dock = DockStyle.Fill,
                LayoutEditingEnabled = false
            };
            m_CallGraphPanel.Controls.Add(m_Viewer);

            m_Viewer.ObjectUnderMouseCursorChanged += (sender, args) =>
            {
                if (args.NewObject?.DrawingObject.UserData == null)
                {
                    m_Viewer.SetToolTip(m_ToolTip, null);
                    return;
                }

                if (args.NewObject.DrawingObject.UserData is Change change)
                {
                    if (change.Result != null)
                    {
                        m_Viewer.SetToolTip(m_ToolTip,
                                            $"{change.Result.Expression}\r\n{change.Result.BlockName}.{change.Result.MethodName}\r\n{change.Key.Data.ItemID}\r\n{change.Key.Data.CycleIndex}");
                    }
                    else
                    {
                        m_Viewer.SetToolTip(m_ToolTip,
                                            $"Set by client\r\n{change.Key.Data.ItemID}\r\n{change.Key.Data.CycleIndex}");
                    }
                }
                else
                {
                    m_Viewer.SetToolTip(m_ToolTip, null);
                }
            };

            m_Viewer.MouseDoubleClick += (sender, args) =>
            {
                if (m_Viewer.SelectedObject is Node node)
                {
                    if (node.UserData is Change change)
                    {
                        SelectListItemFromRowKey(change.Key);
                    }
                }
            };

            m_TimingMeasurements.OnPointClicked += (sender, args) =>
            {
                int index = m_RowKeys.FindIndex(row =>
                                                row.Data.ItemID == args.StartItemId && row.Data.TimeStamp == args.Timestamp);
                if (index >= 0)
                {
                    SelectListItemFromRowKey(m_RowKeys[index]);
                }
            };
            //RetrieveVirtualItem += new RetrieveVirtualItemEventHandler(listView1_RetrieveVirtualItem);
            //CacheVirtualItems += new CacheVirtualItemsEventHandler(listView1_CacheVirtualItems);
            //SearchForVirtualItem += new SearchForVirtualItemEventHandler(listView1_SearchForVirtualItem);

            m_SplitContainer.Panel2Collapsed = true;

            // Adding comparison operators
            this.comboBoxComparisonOperators.Items.AddRange(new object[]
            {
                new ValueComparison("None", (value, constant) => throw new InvalidOperationException()),
                new ValueComparison("==", (value, constant) =>
                {
                    if (!TryParseDecimalInvariant(value, out decimal decimalValue))
                    {
                        return(false);
                    }

                    return(decimalValue == constant);
                }),
                new ValueComparison("!=", (value, constant) =>
                {
                    if (!TryParseDecimalInvariant(value, out decimal decimalValue))
                    {
                        return(false);
                    }

                    return(decimalValue != constant);
                }),
                new ValueComparison(">", (value, constant) =>
                {
                    if (!TryParseDecimalInvariant(value, out decimal decimalValue))
                    {
                        return(false);
                    }

                    return(decimalValue > constant);
                }),
                new ValueComparison(">=", (value, constant) =>
                {
                    if (!TryParseDecimalInvariant(value, out decimal decimalValue))
                    {
                        return(false);
                    }

                    return(decimalValue >= constant);
                }),
                new ValueComparison("<", (value, constant) =>
                {
                    if (!TryParseDecimalInvariant(value, out decimal decimalValue))
                    {
                        return(false);
                    }

                    return(decimalValue < constant);
                }),
                new ValueComparison("<=", (value, constant) =>
                {
                    if (!TryParseDecimalInvariant(value, out decimal decimalValue))
                    {
                        return(false);
                    }

                    return(decimalValue <= constant);
                })
            });
コード例 #3
0
        /// <summary>
        /// Allows Object Identification by moving the mouse over a node or edge.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Viewer_ObjectUnderMouseCursorChanged(object sender, ObjectUnderMouseCursorChangedEventArgs e)
        {
            //////viewer.ObjectUnderMouseCursor vs viewer.SelectedObject??
            if (viewer.SelectedObject != null && viewer.SelectedObject is DrawingNode)
            {
                viewer.Focus();
                //    // toolTip1.SetToolTip(viewer, (viewer.SelectedObject as Microsoft.Msagl.Drawing.Node).Id);
                //    viewer.SetToolTip(toolTip1, getTip(e.NewObject.DrawingObject.UserData));
                selectedNode = (viewer.SelectedObject as DrawingNode).Id;
                //    lblSelectedNode.Text = "Selected Node: " + selectedNode;
            }
            //else
            //{
            //    viewer.SetToolTip(toolTip1, "");
            //}
            selectedObject = e.OldObject != null ? e.OldObject.DrawingObject : null;
            //Clear Selected Object
            if (selectedObject != null && Form.ModifierKeys != Keys.Control)
            {
                RestoreSelectedObjAttr();
                viewer.Invalidate(e.OldObject);
                selectedObject = null;
            }

            if (viewer.ObjectUnderMouseCursor == null)
            {
                lblSelectedNode.Text = "Selected Object: ";
                viewer.SetToolTip(toolTip1, "");
                infoTip1.ClearData();
                RemoveHighlightedPath();
            }
            else
            {
                selectedObject = viewer.ObjectUnderMouseCursor.DrawingObject;


                if (selectedObject is DrawingEdge && Form.ModifierKeys != Keys.Control)
                {
                    DrawingEdge edge = selectedObject as DrawingEdge;
                    selectedObjectAttr = edge.Attr.Clone();
                    //edge.Attr.Color = DrawingColor.Blue;
                    edge.Attr.LineWidth += 3;
                    viewer.Invalidate(e.NewObject);
                    lblSelectedNode.Text = "Selected Edge: " + selectedObject.ToString();
                    //         here we can use e.Attr.Id or e.UserData to get back to the user data
                    // viewer.SetToolTip(toolTip1, String.Format("edge from {0} to {1}", edge.Source, edge.Target));
                }
                if (selectedObject is DrawingNode && Form.ModifierKeys != Keys.Control)
                {
                    DrawingNode node = selectedObject as DrawingNode;
                    selectedObjectAttr = node.Attr.Clone();

                    //node.Attr.Color = DrawingColor.Blue;
                    node.Attr.LineWidth += 4;
                    // //   here you can use e.Attr.Id to get back to your data
                    infoTip1.SetData(e.NewObject.DrawingObject.UserData);
                    //viewer.SetToolTip(toolTip1, getTip(e.NewObject.DrawingObject.UserData));

                    selectedNode         = (viewer.SelectedObject as DrawingNode).Id;
                    lblSelectedNode.Text = "Selected Node: " + selectedNode;
                    //viewer.SetToolTip(toolTip1,
                    //                   String.Format("node {0}",
                    //                                 (selectedObject as Microsoft.Msagl.Drawing.Node).Attr.Id));
                    viewer.Invalidate(e.NewObject);


                    RemoveHighlightedPath();             //Remove last path - Incase traveled by edge to this node.
                    HighlightFullPath(node, true, true); // Recursive
                    foreach (IViewerObject ee in viewer.Entities.Where(ee => ee is IViewerEdge))
                    {
                        viewer.Invalidate(ee);
                    }
                }
            }
        }
コード例 #4
0
ファイル: Graph.cs プロジェクト: fabianusharry/BFS
        public void BFS(int input)
        {
            // Inisialisasi Queue Awal
            Queue <Tuple <char, char> > QueueBFS = new Queue <Tuple <char, char> >();

            listOfCity.Find(x => x.cityName == this.initialCity).infected           = true;
            listOfCity.Find(x => x.cityName == this.initialCity).infectedPopulation = listOfCity.Find(x => x.cityName == this.initialCity).calcInfected();

            System.Console.WriteLine("============== KONDISI AWAL ==============");
            this.printAll();

            foreach (Neighbor neighbor in listOfCity.Find(x => x.cityName == this.initialCity).listOfNeighbor)
            {
                Tuple <char, char> init = new Tuple <char, char>(this.initialCity, neighbor.neighborName);
                QueueBFS.Enqueue(init);
            }

            // Debug Inisialisasi Queue Awal

            // Start Form dan Viewer Awal
            Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer();
            //create a graph object
            Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph");
            //create the graph content
            //create a form
            System.Windows.Forms.Form form = new System.Windows.Forms.Form();
            //create a viewer object
            // End Form dan Viewer Awal

            // Start of Setup Graph Awal
            foreach (var item in listOfCity)
            {
                graph.AddNode(Convert.ToString(item.cityName));
                var edited = graph.FindNode(Convert.ToString(item.cityName));
                if (item.infected)
                {
                    edited.Attr.FillColor = Microsoft.Msagl.Drawing.Color.DarkRed;
                }
                else
                {
                    edited.Attr.FillColor = Microsoft.Msagl.Drawing.Color.DarkGreen;
                }
                edited.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Circle;
            }

            foreach (City item in this.listOfCity)
            {
                foreach (Neighbor item2 in item.listOfNeighbor)
                {
                    string temp1 = Convert.ToString(item.cityName);
                    string temp2 = Convert.ToString(item2.neighborName);
                    graph.AddEdge(temp1, temp2).Attr.Color = Microsoft.Msagl.Drawing.Color.Green;
                }
            }

            string  buffer   = printQueueBFSBuffer(QueueBFS);
            ToolTip toolTip1 = new ToolTip();

            toolTip1.Active       = true;
            toolTip1.AutoPopDelay = 5000;
            toolTip1.InitialDelay = 1000;
            toolTip1.ReshowDelay  = 500;
            viewer.SetToolTip(toolTip1, buffer);
            viewer.Graph = graph;
            //associate the viewer with the form
            form.SuspendLayout();
            viewer.Dock = System.Windows.Forms.DockStyle.Fill;
            form.Controls.Add(viewer);



            form.Size = new System.Drawing.Size(1080, 720);

            form.ResumeLayout();
            //show the form
            form.ShowDialog();
            // End of Viewing and Buffer Node (BFS Queue)
            // End of Setup Graph Awal

            System.Console.WriteLine();
            System.Console.WriteLine("============== PERSEBARAN DIMULAI =================");
            printQueueBFS(QueueBFS);


            // Proses BFS
            while (QueueBFS.Count != 0)
            {
                buffer = "";
                Tuple <char, char> temp = QueueBFS.Dequeue();
                char infectingCityName  = temp.Item1;
                char cityToInfectName   = temp.Item2;


                /* Kalo berhasil menginfeksi kota dan kota yang terinfeksi belum terinfeksi sebelumnya */
                if ((listOfCity.Find(x => x.cityName == infectingCityName).infecting(listOfCity.Find(x => x.cityName == infectingCityName).listOfNeighbor.Find(x => x.neighborName == cityToInfectName))) && (!listOfCity.Find(x => x.cityName == cityToInfectName).infected))
                {
                    System.Console.WriteLine("{0} berhasil menginfeksi {1}", infectingCityName, cityToInfectName);
                    graph.AddEdge(Convert.ToString(infectingCityName), Convert.ToString(cityToInfectName)).Attr.Color = Microsoft.Msagl.Drawing.Color.Red;
                    Microsoft.Msagl.Drawing.Node edited = graph.FindNode(Convert.ToString(cityToInfectName));
                    edited.Attr.FillColor = Microsoft.Msagl.Drawing.Color.DarkRed;
                    /* ======================== QUEUE MANAGER ========================== */

                    /* Tambahkan <kota terinfeksi,tetangga dari kota terinfeksi> ke dalam queue */
                    foreach (Neighbor neighbor in listOfCity.Find(x => x.cityName == cityToInfectName).listOfNeighbor)
                    {
                        char infectedNeighbors      = neighbor.neighborName;
                        Tuple <char, char> newTuple = new Tuple <char, char>(cityToInfectName, infectedNeighbors);


                        QueueBFS.Enqueue(newTuple);
                    }

                    buffer = buffer + printQueueBFSBuffer(QueueBFS);

                    /* ====================== ATTRIBUTE CHANGE MANAGER =========================== */
                    listOfCity.Find(x => x.cityName == cityToInfectName).infected    = true;
                    listOfCity.Find(x => x.cityName == cityToInfectName).infectedDay = listOfCity.Find(x => x.cityName == infectingCityName).lamaInfeksi(listOfCity.Find(x => x.cityName == infectingCityName).listOfNeighbor.Find(x => x.neighborName == cityToInfectName)) + listOfCity.Find(x => x.cityName == infectingCityName).infectedDay;
                    System.Console.WriteLine("Berapa nih Infected Day? " + listOfCity.Find(x => x.cityName == cityToInfectName).infectedDay);
                    listOfCity.Find(x => x.cityName == cityToInfectName).infectedDuration = input - listOfCity.Find(x => x.cityName == cityToInfectName).infectedDay;
                    System.Console.WriteLine("Berapa nih Infected Duration? " + listOfCity.Find(x => x.cityName == cityToInfectName).infectedDuration);
                    listOfCity.Find(x => x.cityName == cityToInfectName).infectedPopulation = listOfCity.Find(x => x.cityName == cityToInfectName).calcInfected();

                    if (listOfCity.Find(x => x.cityName == cityToInfectName).infectedFrom == ' ')
                    {
                        listOfCity.Find(x => x.cityName == cityToInfectName).infectedFrom = infectingCityName;
                    }

                    /* Debug Queue */
                    //printQueueBFS(QueueBFS);
                }

                /* Kalo kota yang akan diinfeksi sudah terinfeksi sebelumnya */
                else if (listOfCity.Find(x => x.cityName == cityToInfectName).infected)
                {
                    System.Console.WriteLine("Kota {0} sudah terinfeksi sebelumnya! Serangan tidak akan berpengaruh", cityToInfectName);
                    //printQueueBFS(QueueBFS);

                    buffer = buffer + printQueueBFSBuffer(QueueBFS);
                }

                /* Kalo kota tidak berhasil diinfeksi */
                else
                {
                    System.Console.WriteLine("{0} tidak berhasil menginfeksi {1}", infectingCityName, cityToInfectName);
                    //printQueueBFS(QueueBFS);


                    buffer = buffer + printQueueBFSBuffer(QueueBFS);
                }


                //Microsoft.Msagl.Drawing.Node bfsDisplay= graph.AddNode(buffer);

                //bfsDisplay.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Plaintext;


                // Start of Viewing and Buffer Node (BFS Queue)

                //Microsoft.Msagl.Drawing.Node remover = graph.FindNode(buffer);
                //graph.RemoveNode(remover);
                //Microsoft.Msagl.Drawing.Node bfsDisplay= graph.AddNode(buffer);

                //bfsDisplay.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Plaintext;
                //bind the graph to the viewer


                viewer.SetToolTip(toolTip1, buffer);
                viewer.Graph = graph;
                //associate the viewer with the form
                form.SuspendLayout();
                viewer.Dock = System.Windows.Forms.DockStyle.Fill;
                form.Controls.Add(viewer);



                form.Size = new System.Drawing.Size(1080, 720);

                form.ResumeLayout();
                //show the form
                form.ShowDialog();
                // End of Viewing and Buffer Node (BFS Queue)
                System.Console.WriteLine();
                printQueueBFS(QueueBFS);
            }
            System.Console.WriteLine("============== PERSEBARAN SELESAI ==============");
            System.Console.WriteLine();

            System.Console.WriteLine("============== KONDISI AKHIR ==============");
            this.printAll();
        }