/// <summary>
 /// Retourne True si outil est supprimé du circuit
 /// </summary>
 /// <param name="outil"></param>
 /// <returns></returns>
 public bool DeleteComponent(Outils outil)
 {
     if (Circuit.ContainsVertex(outil))// Si outil figure dans le circuit
     {
         //Mettre à jour les entrées des outils auxquelles l'outil était connecté
         foreach (var sortie in outil.getListesorties())
         {
             sortie.getSortie().ForEach((outstruct) => { outstruct.GetEntree().setRelated(false); });
         }
         //Mettre à jour les sorties des outils auxquelles l'outil était connecté
         foreach (var edge in Circuit.InEdges(outil))
         {
             foreach (var sortie in edge.Source.getListesorties())
             {
                 sortie.DeleteOustruct(outil);
             }
         }
         Circuit.ClearEdges(outil);
         Circuit.RemoveVertex(outil);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 2
0
        public void ClearEdges()
        {
            int edgesRemoved = 0;

            var graph = new BidirectionalGraph <int, Edge <int> >();

            graph.EdgeRemoved += e =>
            {
                Assert.IsNotNull(e);
                // ReSharper disable once AccessToModifiedClosure
                ++edgesRemoved;
            };

            AssertEmptyGraph(graph);

            // Clear 1 => not in graph
            graph.ClearEdges(1);
            AssertEmptyGraph(graph);
            CheckCounter(0);

            // Clear 1 => In graph but not in/out edges
            graph.AddVertex(1);
            graph.ClearEdges(1);
            AssertHasVertices(graph, new[] { 1 });
            AssertNoEdge(graph);
            CheckCounter(0);

            var edge12 = new Edge <int>(1, 2);
            var edge23 = new Edge <int>(2, 3);

            graph.AddVerticesAndEdgeRange(new[] { edge12, edge23 });

            // Clear 2
            graph.ClearEdges(2);

            AssertNoEdge(graph);
            CheckCounter(2);

            var edge13 = new Edge <int>(1, 3);
            var edge31 = new Edge <int>(3, 1);
            var edge32 = new Edge <int>(3, 2);

            graph.AddVerticesAndEdgeRange(new[] { edge12, edge13, edge31, edge32 });

            // Clear 3
            graph.ClearEdges(3);

            AssertHasEdges(graph, new[] { edge12 });
            CheckCounter(3);

            // Clear 1 = clear
            graph.ClearEdges(1);

            AssertNoEdge(graph);
            CheckCounter(1);

            #region Local function

            void CheckCounter(int expectedRemovedEdges)
            {
                Assert.AreEqual(expectedRemovedEdges, edgesRemoved);
                edgesRemoved = 0;
            }

            #endregion
        }