private void InputByNumbers()
 {
     _variables = (int)MintermNumbers.Value;
     try
     {
         if (string.IsNullOrEmpty(MintermInput.Text))
         {
             throw new Exception("No minterm numbers entered");
         }
         string[] items    = MintermInput.Text.Split(',');
         string[] dontcare = null;
         if (!string.IsNullOrEmpty(DontcarInput.Text))
         {
             dontcare = DontcarInput.Text.Split(',');
             if (dontcare.Length < 1)
             {
                 items = DontcarInput.Text.Split(' ');
             }
         }
         if (items.Length < 1)
         {
             items = MintermInput.Text.Split(' ');
         }
         if (items.Length < 1)
         {
             throw new Exception("Incorrect input");
         }
         List <LogicItem> litems = new List <LogicItem>();
         foreach (var item in items)
         {
             litems.Add(new LogicItem()
             {
                 Index       = Convert.ToInt32(item),
                 BinaryValue = LogicItem.GetBinaryValue(Convert.ToInt32(item), _variables),
                 Checked     = true
             });
         }
         if (dontcare != null)
         {
             foreach (var item in dontcare)
             {
                 litems.Add(new LogicItem()
                 {
                     Index       = Convert.ToInt32(item),
                     BinaryValue = LogicItem.GetBinaryValue(Convert.ToInt32(item), _variables),
                     Checked     = null
                 });
             }
         }
         SimpleMinterm.Text = QuineMcclusky.GetSimplified(litems, _variables, (bool)HazardSafe.IsChecked, (bool)LsbBit.IsChecked, false);
         SimpleMaxterm.Text = QuineMcclusky.GetSimplified(litems, _variables, (bool)HazardSafe.IsChecked, (bool)LsbBit.IsChecked, true);
     }
     catch (Exception ex)
     {
         WpfHelpers.ExceptionDialog(ex);
     }
 }
        private async void BtnMinimize_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var items     = new List <LogicItem>();
                int variables = 2;
                switch (TabInputMode.SelectedIndex)
                {
                case 0:
                    items.AddRange(Minterm2x.GetSelected());
                    variables = 2;
                    break;

                case 1:
                    items.AddRange(Minterm3x.GetSelected());
                    variables = 3;
                    break;

                case 2:
                    items.AddRange(Minterm4x.GetSelected());
                    variables = 4;
                    break;

                case 3:
                    items.AddRange(Minterm5x.GetSelected());
                    variables = 5;
                    break;

                case 4:
                    variables = (int)EsListVarCount.Value;
                    foreach (var line in TbListSet.Text.Split('\n'))
                    {
                        if (string.IsNullOrEmpty(line))
                        {
                            continue;
                        }
                        items.Add(LogicItem.CreateFromMintermIndex(Convert.ToInt32(line.Replace("\r", "")), variables, true));
                    }
                    foreach (var line in TbListDontCare.Text.Split('\n'))
                    {
                        if (string.IsNullOrEmpty(line))
                        {
                            continue;
                        }
                        items.Add(LogicItem.CreateFromMintermIndex(Convert.ToInt32(line.Replace("\r", "")), variables, null));
                    }
                    break;
                }
                string result = QuineMcclusky.GetSimplified(items, variables, (bool)CbHazardFree.IsChecked, (bool)RadioLSB.IsChecked);
                TbResults.Text = result;
            }
            catch (Exception ex)
            {
                await _app.ShowMessageBox("Error", ex.Message, DialogButtons.Ok);
            }
        }
        private void Button_Minimize_Click(object sender, RoutedEventArgs e)
        {
            if (!_loaded)
            {
                return;
            }
            //string simple = null;
            IMintermTable mintermatble = null;

            switch (InputMode.SelectedIndex)
            {
            case 0:
                SimpleMinterm.Text = QuineMcclusky.GetSimplified(_items, _variables, (bool)HazardSafe.IsChecked, (bool)LsbBit.IsChecked, false);
                SimpleMaxterm.Text = QuineMcclusky.GetSimplified(_items, _variables, (bool)HazardSafe.IsChecked, (bool)LsbBit.IsChecked, true);
                break;

            case 1:
                mintermatble = Minterm2x;
                _variables   = 2;
                break;

            case 2:
                mintermatble = Minterm3x;
                _variables   = 3;
                break;

            case 3:
                mintermatble = Minterm4x;
                _variables   = 4;
                break;

            case 4:
                mintermatble = Minterm5x;
                _variables   = 5;
                break;

            case 5:
                InputByNumbers();
                break;
            }
            if (mintermatble != null)
            {
                SimpleMinterm.Text = QuineMcclusky.GetSimplified(mintermatble.Selected, _variables, (bool)HazardSafe.IsChecked, (bool)LsbBit.IsChecked, false);
                SimpleMaxterm.Text = QuineMcclusky.GetSimplified(mintermatble.Selected, _variables, (bool)HazardSafe.IsChecked, (bool)LsbBit.IsChecked, true);
            }
        }
        private string Design()
        {
            LogicItem[]   minterms1, minterms2;
            StringBuilder sb = new StringBuilder();

            //i = betű
            //j = sorszm
            for (int i = 0; i < _variables; i++)
            {
                minterms1 = GenerateMinterms();
                minterms2 = GenerateMinterms();
                for (int j = 0; j < _counter.Count; j++)
                {
                    if (_counter[j].Current == null && _counter[j].Next == null)
                    {
                        break;
                    }
                    int index = Convert.ToInt32(_counter[j].Current, 2);
                    switch (_flipflop)
                    {
                    case "SR":
                        minterms1[index].Checked = DecodeFlipFlop(_counter[j].Current[i], _counter[j].Next[i], "S");
                        minterms2[index].Checked = DecodeFlipFlop(_counter[j].Current[i], _counter[j].Next[i], "R");
                        break;

                    case "S'R'":
                        minterms1[index].Checked = DecodeFlipFlop(_counter[j].Current[i], _counter[j].Next[i], "S'");
                        minterms2[index].Checked = DecodeFlipFlop(_counter[j].Current[i], _counter[j].Next[i], "R'");
                        break;

                    case "JK":
                        minterms1[index].Checked = DecodeFlipFlop(_counter[j].Current[i], _counter[j].Next[i], "J");
                        minterms2[index].Checked = DecodeFlipFlop(_counter[j].Current[i], _counter[j].Next[i], "K");
                        break;

                    case "T":
                        minterms1[index].Checked = DecodeFlipFlop(_counter[j].Current[i], _counter[j].Next[i], "T");
                        break;

                    case "D":
                        minterms1[index].Checked = DecodeFlipFlop(_counter[j].Current[i], _counter[j].Next[i], "D");
                        break;
                    }
                }
                switch (_flipflop)
                {
                case "SR":
                    sb.AppendFormat("S{0} = {1}\r\n", (char)(i + 65), QuineMcclusky.GetSimplified(minterms1, _variables, true));
                    sb.AppendFormat("R{0} = {1}\r\n", (char)(i + 65), QuineMcclusky.GetSimplified(minterms2, _variables, true));
                    break;

                case "S'R'":
                    sb.AppendFormat("S'{0} = {1}\r\n", (char)(i + 65), QuineMcclusky.GetSimplified(minterms1, _variables, true));
                    sb.AppendFormat("R'{0} = {1}\r\n", (char)(i + 65), QuineMcclusky.GetSimplified(minterms2, _variables, true));
                    break;

                case "JK":
                    sb.AppendFormat("J{0} = {1}\r\n", (char)(i + 65), QuineMcclusky.GetSimplified(minterms1, _variables, true));
                    sb.AppendFormat("K{0} = {1}\r\n", (char)(i + 65), QuineMcclusky.GetSimplified(minterms2, _variables, true));
                    break;

                case "T":
                    sb.AppendFormat("T{0} = {1}\r\n", (char)(i + 65), QuineMcclusky.GetSimplified(minterms1, _variables, true));
                    break;

                case "D":
                    sb.AppendFormat("D{0} = {1}\r\n", (char)(i + 65), QuineMcclusky.GetSimplified(minterms1, _variables, true));
                    break;
                }
            }
            return(sb.ToString());
        }