Esempio n. 1
0
        /// <summary>
        /// TEMP Display result when possible
        /// </summary>
        private void sketchPanel_ResultReceived(SketchPanelLib.RecognitionResult result)
        {
            // Get the result
            TruthTableRecognitionResult ttResult;

            if (result is TruthTableRecognitionResult && result.UserTriggered)
            {
                ttResult = (TruthTableRecognitionResult)result;
            }
            else
            {
                return; // ignore other results
            }
            // Clear display
            clear();

            // Validate result as displayable; display error message otherwise
            if (ttResult.NumCols > 1 &&                       // Need at two columns
                ttResult.NumRows > 0 &&                       // Need at least one row
                ttResult.LabelPins.Count == ttResult.NumCols) // Need # labels == # columns
            {
                // Display the result
                currentResult = ttResult;
                displayResult();
            }
            else
            {
                System.Windows.MessageBox.Show("Error: Truth table could not be recognized.  " +
                                               "Please ensure that truth table is drawn according to necessary conventions");
            }
        }
Esempio n. 2
0
        private void clear()
        {
            if (ttGrid != null)
            {
                sketchPanel.InkCanvas.Controls.Remove(ttGrid);
            }

            ttGrid        = null;
            currentResult = null;
        }
Esempio n. 3
0
        /// <summary>
        /// <see cref="FeedbackMechanism.UnsubscribeFromPanel"/>
        /// </summary>
        public override void UnsubscribeFromPanel()
        {
            sketchPanel.ResultReceived -= new SketchPanelLib.RecognitionResultReceivedHandler(sketchPanel_ResultReceived);

            if (ttGrid != null)
            {
                sketchPanel.InkPicture.Controls.Remove(ttGrid);
            }

            ttGrid        = null;
            currentResult = null;

            /*sketchPanel.ResultReceived -= new RecognitionResultReceivedHandler(sketchPanel_ResultReceived);
             * sketchPanel.InkPicture.MouseMove -= new System.Windows.Forms.MouseEventHandler(InkPicture_MouseMove);
             * sketchPanel.InkPicture.CursorInRange -= new Microsoft.Ink.InkCollectorCursorInRangeEventHandler(InkPicture_CursorInRange);
             * sketchPanel.InkPicture.Painted -= new InkOverlayPaintedEventHandler(InkPicture_Painted);
             * sketchPanel.InkPicture.StrokesDeleting -= new InkOverlayStrokesDeletingEventHandler(InkPicture_StrokesDeleting);
             * sketchPanel.ZoomEvent -= new ZoomEventHandler(sketchPanel_ZoomEvent);
             * sketchPanel.SketchFileLoaded -= new SketchFileLoadedHandler(sketchPanel_SketchFileLoaded);
             * */
        }
        public override RecognitionResult Recognize(RecognitionArgs args)
        {
            TruthTableRecognitionResult result = new TruthTableRecognitionResult();

            // Only recognizer on user triggered event
            if (!args.UserTriggered)
            {
                return(result);
            }

            // Extract number of columns, if available
            // TEMP Removed because TruthTable.assign(int) is no longer available
            //int numCols = -1;
            //if (args is TruthTableRecognitionArgs)
            //{
            //    numCols = ((TruthTableRecognitionArgs)args).NumCols;
            //}

            // Run recognition and create result
            result.Sketch = args.Sketch;
            TruthTable ttRecognizer = new TruthTable(result.Sketch);

            //if (numCols == -1)
            //{
            result.DataMatrix = ttRecognizer.assign();
            //}
            //else
            //{
            //    result.DataMatrix = ttRecognizer.assign(numCols);
            //}



            result.DataPins      = ttRecognizer.createPins(result.DataMatrix);
            result.LabelPins     = ttRecognizer.outputLabels();
            result.NumCols       = ttRecognizer.NumCols;
            result.NumRows       = ttRecognizer.NumRows;
            result.DividerIndex  = ttRecognizer.DivIndex;
            result.UserTriggered = args.UserTriggered;
            //result.Sketch = ttRecognizer.LabeledSketch;

            #region DEBUG

            /*Console.WriteLine("printing labels " + args.Sketch.LabelStrings.ToString());
             *
             * foreach (Sketch.Shape sh in result.Sketch.Shapes)
             * {
             *  Console.WriteLine("sketch shape " + sh.XmlAttrs.Type);
             *  if (sh.XmlAttrs.Type.Equals("Divider"))
             *  {
             *      foreach (Sketch.Substroke sub in sh.Substrokes)
             *      {
             *          sub.XmlAttrs.Color = System.Drawing.Color.Red.ToArgb();
             *          Console.WriteLine("divider has substroke with props: " + sub.XmlAttrs.Id + "\n" + sub.Points[0]);
             *      }
             *  }
             * }
             *
             * foreach (Sketch.Substroke sub in result.Sketch.Substrokes)
             * {
             *  if (sub.ParentShapes.Count == 0)
             *  {
             *      Console.WriteLine("no parent shapes: " + sub.XmlAttrs.Id + "\n " + sub.Points[0]);
             *  }
             *  else if (sub.ParentShapes[0].XmlAttrs.Type.Equals("Divider"))
             *  {
             *      Console.WriteLine("has a parent as divider: " + sub.XmlAttrs.Id + "\n " + sub.Points[0]);
             *  }
             * }*/


            //
            // TEMP START Debug code from TruthTables/Debugging.cs
            //

            /*int cols = result.NumCols;
             * Console.WriteLine("cols: " + cols);
             * int rows = result.NumRows;
             * Console.WriteLine("rows: " + rows);
             *
             * // print out the labels
             * ttRecognizer.outputLabels();
             *
             * // put the data values into the matrix,
             * // including the underscore between inputs and outputs
             * if (rows == -1)
             *  return result;
             * string[] list = new string[rows];
             * int d = result.DividerIndex;
             * Console.WriteLine("divider index: " + d);
             *
             * for (int j = 0; j < rows; j++)
             * {
             *  for (int k = 0; k < cols; k++)
             *  {
             *      if (k == d)
             *      {
             *          list[j] += "_"; // separate inputs from outputs
             *      }
             *      if (result.DataMatrix[j, k] == -1)
             *      {
             *          list[j] += "X";
             *      }
             *      else
             *      {
             *          list[j] += result.DataMatrix[j, k];
             *      }
             *  }
             * }
             *
             * // print out the matrix
             * for (int u = 0; u < list.Length; u++)
             * {
             *  Console.WriteLine(list[u]);
             * }
             *
             * //
             * // TEMP END Debug code from TruthTables/Debugging.cs
             * //
             */

            #endregion

            return(result);
        }