Ejemplo n.º 1
0
        public void ParseDiagramUserControl(LogicPad2.Diagram.UserControl1 userControl, 
            out string generatedExpr, out TruthTableWindow.TruthTable generatedTruthTable)
        { 
            userControl.Parse(out generatedExpr);

            generatedTruthTable = new TruthTableWindow.TruthTable();

            int numberOfTerm;
            String[] terms_names;
            int[] fvalues;
            String outputName;
            LogicPadParser.LogicPadParser.Instance.ParseInterTreeToTruthTable(
                LogicPadParser.LogicPadParser.diagram,
                out numberOfTerm,
                out terms_names,
                out fvalues,
                out outputName
             );

            LogicPadParser.TruthTable interTruthTable = new LogicPadParser.TruthTable(numberOfTerm);
            interTruthTable.Terms_names = terms_names;
            interTruthTable.Fvalues = fvalues;
            interTruthTable.OutputName = outputName;

            //Diagram To TruthTable Minimization
            LogicPadParser.TruthTableSolver solver = new LogicPadParser.TruthTableSolver();
            solver.CurrentTruthTable = interTruthTable;
            solver.Solve();

            LogicPadParser.LogicPadParser.Instance.ParseInterTreeToTruthTable(
                LogicPadParser.LogicPadParser.truthTable,
                out numberOfTerm,
                out terms_names,
                out fvalues,
                out outputName
             );

            generatedTruthTable.Number_of_terms = numberOfTerm;
            generatedTruthTable.Terms_names = terms_names;
            generatedTruthTable.Fvalues = fvalues;
            generatedTruthTable.Rows = (int)Math.Pow(2, generatedTruthTable.Number_of_terms) + 1;
            generatedTruthTable.Columns = generatedTruthTable.Number_of_terms + 2;
            generatedTruthTable.OutputName = outputName;


            generatedExpr = InterTree.ParseExpressionToString(LogicPadParser.LogicPadParser.truthTable);
        }
Ejemplo n.º 2
0
        public int ParseExpressionUserControl(LogicPad2.Expression.UserControl1 userControl,
            out TruthTableWindow.TruthTable generatedTruthTable, out XElement generatedXElement)
        {
            int output = 2;
            generatedXElement = userControl.Parse(ref output);
            if(output != 2)
            {
                generatedTruthTable = null;
                return output;
            }
            LogicPadParser.LogicPadParser.Instance.ParseExpressionXElement(generatedXElement);
           
            generatedTruthTable = new TruthTableWindow.TruthTable();

            int numberOfTerm;
            String[] terms_names;
            int[] fvalues;
            string outputName;

            LogicPadParser.LogicPadParser.Instance.ParseInterTreeToTruthTable(
                LogicPadParser.LogicPadParser.expression,
                out numberOfTerm,
                out terms_names,
                out fvalues,
                out outputName
             );

            if (numberOfTerm == 0)
            {
                generatedTruthTable = null;
                return 0;
            }
            else if (numberOfTerm == -1)
            {
                generatedTruthTable = null;
                return 1;
            }

            LogicPadParser.TruthTable interTruthTable = new LogicPadParser.TruthTable(numberOfTerm);
            interTruthTable.Terms_names = terms_names;
            interTruthTable.Fvalues = fvalues;
            interTruthTable.OutputName = outputName;
            
            //Expression Minimization
            LogicPadParser.TruthTableSolver solver = new LogicPadParser.TruthTableSolver();
            solver.CurrentTruthTable = interTruthTable;
            solver.Solve();

            LogicPadParser.LogicPadParser.Instance.ParseInterTreeToTruthTable(
                LogicPadParser.LogicPadParser.truthTable,
                out numberOfTerm,
                out terms_names,
                out fvalues,
                out outputName
             );

            if (numberOfTerm == 0)
            {
                generatedTruthTable = null;
                return 0;
            }
            else if (numberOfTerm == -1)
            {
                generatedTruthTable = null;
                return 1;
            }

            generatedTruthTable.Number_of_terms = numberOfTerm;
            generatedTruthTable.Terms_names = terms_names;
            generatedTruthTable.Fvalues = fvalues;
            generatedTruthTable.Rows = (int)Math.Pow(2, generatedTruthTable.Number_of_terms) + 1;
            generatedTruthTable.Columns = generatedTruthTable.Number_of_terms + 2;

            return 2;
        }