Esempio n. 1
0
        public void graphique(MouseButtonEventArgs monEvenement, int monMode)
        {
            NodeGraphic monSommet;
            Point monPoint = monEvenement.GetPosition(monCanvas);
            //ajout d'un point
            if (monMode == 2)
            {
                monSommet = new NodeGraphic("", monPoint.Y - 10, monPoint.X - 10, new Ellipse());
                monSommet.DrawNode(monCanvas);
                mesNoeud.Add(monSommet);
            }

            else if (monMode == 1)
            {

            }
            //ajout d'un arc
            else if (monMode == 5)
            {
                Ellipse monEllipse = new Ellipse();
                if (booleen == false)
                {
                    //test si l'ellipse est bien cliqué.
                    HitTestResult result = VisualTreeHelper.HitTest(monCanvas, monPoint);
                    if ((result != null) && (result.VisualHit is Ellipse))
                    {
                        monEllipse = (Ellipse)result.VisualHit;
                        foreach (NodeGraphic i in mesNoeud)
                        {
                            if (i.PositionX == Canvas.GetLeft(monEllipse) && i.PositionY == Canvas.GetTop(monEllipse))
                            {
                                sommetSelect = i;
                            }
                        }
                        booleen = true;
                    }
                }
                else
                {
                    //test si l'ellipse est bien cliqué.
                    HitTestResult result = VisualTreeHelper.HitTest(monCanvas, monPoint);
                    if ((result != null) && (result.VisualHit is Ellipse))
                    {
                        monEllipse = (Ellipse)result.VisualHit;
                        foreach (NodeGraphic i in mesNoeud)
                        {
                            if (i.PositionX == Canvas.GetLeft(monEllipse) && i.PositionY == Canvas.GetTop(monEllipse))
                            {
                                ArcGraphic monArc = new ArcGraphic(0, sommetSelect, i);
                                monArc.DrawArc(monCanvas);
                                mesArcs.Add(monArc);
                            }
                        }
                    }
                    booleen = false;
                }
            }
            else if (monMode == 4)
            {

                Ellipse monEllipse = new Ellipse();
                //test si l'ellipse est bien cliqué.
                HitTestResult result = VisualTreeHelper.HitTest(monCanvas, monPoint);
                if ((result != null) && (result.VisualHit is Ellipse))
                {
                    List<ArcGraphic> arcaSupprimer = new List<ArcGraphic>();
                    List<NodeGraphic> nodeaSupprimer = new List<NodeGraphic>();
                    monEllipse = (Ellipse)result.VisualHit;
                    foreach (NodeGraphic i in mesNoeud)
                    {
                        if (i.PositionX == Canvas.GetLeft(monEllipse) && i.PositionY == Canvas.GetTop(monEllipse))
                        {
                            nodeaSupprimer.Add(i);
                            if (mesArcs.Count != 0)
                            {
                                foreach (ArcGraphic j in mesArcs)
                                {
                                    if (j.Arrivee == i || j.Origine == i)
                                    {
                                        arcaSupprimer.Add(j);
                                    }
                                }
                            }
                        }
                    }

                    foreach (NodeGraphic i in nodeaSupprimer)
                    {
                        monCanvas.Children.Remove(i.EllipseSommet);
                        mesNoeud.Remove(i);
                    }
                    foreach (ArcGraphic j in arcaSupprimer)
                    {
                        monCanvas.Children.Remove(j.LigneArc);
                        mesArcs.Remove(j);
                    }
                }
            }
        }
Esempio n. 2
0
 public ArcGraphic(Int32 coutA, NodeGraphic origineA, NodeGraphic arriveeA)
 {
     this.cout = coutA;
     this.origine = origineA;
     this.arrivee = arriveeA;
 }