private void TT_start()
        {
            DataTable     dt            = new DataTable();
            int           nbrPinEntree  = 0;
            int           nbrDiodSortie = 0;
            string        ch1           = "Noyau.PinOut";
            string        ch2           = "Noyau.PinIn";
            List <Outils> PinEntreeLLC  = new List <Outils>();
            List <Outils> DiodSortieLLC = new List <Outils>();

            foreach (Outils noeud in circuit.Vertices)
            {
                if (noeud.GetType().ToString().CompareTo(ch1) == 0)
                {
                    nbrDiodSortie++;
                    DiodSortieLLC.Add(noeud);
                }
                else
                {
                    if (noeud.GetType().ToString().CompareTo(ch2) == 0)
                    {
                        nbrPinEntree++;
                        PinEntreeLLC.Add(noeud);
                    }
                }
            }

            int numberOfVariables  = nbrPinEntree;
            int biggestvalue       = Convert.ToInt32(Math.Pow(2, numberOfVariables)) - 1;
            int biggestDigitLength = Convert.ToString(biggestvalue, 2).Length;


            int cpt = 1;

            //Creating the columns des PinIns
            foreach (Outils elmnt in circuit.Vertices)
            {
                if (elmnt.GetType().ToString().CompareTo(ch2) == 0)
                {
                    string nom = elmnt.getname();
                    dt.Columns.Add(new DataColumn(nom, typeof(string)));
                    cpt++;
                }
            }

            cpt = 1;
            //Creating the columns des PinOut
            foreach (Outils elmnt in circuit.Vertices)
            {
                if (elmnt.GetType().ToString().CompareTo(ch1) == 0)
                {
                    DataColumn output = new DataColumn(elmnt.getname());
                    dt.Columns.Add(output);
                    cpt++;
                }
            }

            for (int i = 0; i < Math.Pow(2, numberOfVariables); i++)
            {
                string binary = Convert.ToString(i, 2);

                //Pour remplir les bits forts non atteints avec des 0 ,indiquants false
                binary = binary.PadLeft(biggestDigitLength, '0');

                bool[] binaryExpression = binary.Select(c => c == '1').ToArray();

                DataRow inputRow = dt.NewRow();

                //Add
                for (int j = 0; j < binaryExpression.Length; j++)
                {
                    if (binaryExpression[j] == true)
                    {
                        inputRow[j] = "True";
                    }
                    else if (binaryExpression[j] == false)
                    {
                        inputRow[j] = "False";
                    }
                }

                int l = 0;
                foreach (Outils elmnt in circuit.Vertices)
                {
                    if (elmnt.GetType().ToString().CompareTo(ch2) == 0)
                    {
                        elmnt.getEntreeSpecifique(0).setEtat(binaryExpression[l]);
                        l++;
                    }
                }

                CircuitPersonnalise essaie = new CircuitPersonnalise(circuit);
                essaie.EvaluateCircuit();
                l = 0;

                //La recuperation des etats des diodes apres la simulation
                foreach (Outils elmnt in circuit.Vertices)
                {
                    if (elmnt.GetType().ToString().CompareTo(ch1) == 0)
                    {
                        inputRow[binaryExpression.Length + l] = elmnt.getEntreeSpecifique(0).getEtat().ToString();
                        l++;
                    }
                }
                dt.Rows.Add(inputRow);
            }

            tVerite.ItemsSource = dt.DefaultView;
        }
示例#2
0
        //SIMULER
        private void simuler_click(object sender, RoutedEventArgs e)
        {
            circuit.setSimulation(false);

            if (circuit.getCircuit().VertexCount != 0)
            {
                if (circuit.getUnrelatedGates().Count != 0)
                {
                    try
                    {
                        throw new RelatedException(Grille);
                    }
                    catch (RelatedException exception)
                    {
                        exception.Gerer();
                    }
                }
                else
                {
                    bool pinsortie = false;
                    foreach (Outils elmnt in circuit.GetCircuit().Vertices)
                    {
                        if (elmnt is PinOut)
                        {
                            pinsortie = true;
                            break;
                        }
                    }

                    if (!pinsortie)
                    {
                        try
                        {
                            throw new AucunPinSortieException(Grille);
                        }
                        catch (AucunPinSortieException exception)
                        {
                            exception.Gerer();
                        }
                    }
                    else
                    {
                        //To remove the exceptions
                        if (Exceptions.set.Count != 0)
                        {
                            Close(null, null);
                        }


                        //In order to show the pause/stop buttons --------------------------------------------
                        if (pause.Visibility == Visibility.Collapsed)
                        {
                            pause.Visibility = Visibility.Visible;
                        }
                        if (stop.Visibility == Visibility.Collapsed)
                        {
                            stop.Visibility = Visibility.Visible;
                        }
                        simuler.Visibility = Visibility.Collapsed;
                        clock.Visibility   = Visibility.Collapsed;
                        //-----------------------------------------------------------------------------------

                        //To stop changes while simulating
                        Tools.IsEnabled         = false;            //désactiver le pnale des outils
                        FichierButton.IsEnabled = false;            //désactiver le bouton de suavegrade,  ....
                        foreach (UserControl uc in Grille.Children) //désactiver le context menu de tous les composants sur la grille
                        {
                            if (uc is Gate)
                            {
                                (uc as Gate).path.ContextMenuOpening += HitContextMenu;
                            }
                            if (uc is Wire)
                            {
                                uc.ContextMenuOpening += HitContextMenu;
                            }
                        }

                        circuit.EvaluateCircuit();
                        circuit.setSimulation(true);
                    }
                }
            }
        }