示例#1
0
 private bool HasControlInRightRegion(ref InkQueryRegionStruct inkRegion)
 {
     foreach (UIElement element in this.Children)
     {
         if (element is UserControl)
         {
             if (UserControlIntersectWithInkRegion(element as UserControl, ref inkRegion, true))
             {
                 if (inkRegion.RightSideUserControl == null)
                 {
                     inkRegion.RightSideUserControl = element as UserControl;
                     return true;
                 }
             }
         }   
     }
     return false;
 }
示例#2
0
        private bool UserControlIntersectWithInkRegion(UserControl element, ref InkQueryRegionStruct inkRegion, bool isRightSide)
        {
            Rect rect;

            if (element is LogicPad2.Diagram.UserControl1)
            {
                #region Diagram
                LogicPad2.Diagram.UserControl1 diagramUserControl = element as LogicPad2.Diagram.UserControl1;
                Rect userControlRect = new Rect(diagramUserControl.UserControlX,
                            diagramUserControl.UserControlY,
                            diagramUserControl.ActualWidth * diagramUserControl.UserControlScaleX,
                            diagramUserControl.ActualHeight * diagramUserControl.UserControlScaleY);

                if (isRightSide)
                {
                    //rect = inkRegion.RightSideRegionRect;
                    rect = new Rect(new Point(inkRegion.EqualRect.TopRight.X, inkRegion.EqualRect.TopRight.Y),
                            new Size(diagramUserControl.ActualWidth * diagramUserControl.UserControlScaleX, diagramUserControl.ActualHeight * diagramUserControl.UserControlScaleY));
                }
                else
                {
                    //rect = inkRegion.LeftSideRegionRect;
                    rect = new Rect(new Point(inkRegion.EqualRect.TopLeft.X - diagramUserControl.ActualWidth * diagramUserControl.UserControlScaleX, inkRegion.EqualRect.TopLeft.Y),
                           new Size(diagramUserControl.ActualWidth * diagramUserControl.UserControlScaleX, diagramUserControl.ActualHeight * diagramUserControl.UserControlScaleY));
                }

                if (userControlRect.IntersectsWith(rect))
                {
                    return true;
                }
                #endregion
            }
            else if (element is LogicPad2.Expression.UserControl1)
            {
                #region Expression

                LogicPad2.Expression.UserControl1 expressionUserControl = element as LogicPad2.Expression.UserControl1;
                Rect userControlRect = new Rect(expressionUserControl.UserControlX,
                            expressionUserControl.UserControlY,
                            expressionUserControl.ActualWidth * expressionUserControl.UserControlScaleX,
                            expressionUserControl.ActualHeight * expressionUserControl.UserControlScaleY);

                if (isRightSide)
                {
                    //rect = inkRegion.RightSideRegionRect;
                    rect = new Rect(new Point(inkRegion.EqualRect.TopRight.X, inkRegion.EqualRect.TopRight.Y),
                            new Size(expressionUserControl.ActualWidth * expressionUserControl.UserControlScaleX, expressionUserControl.ActualHeight * expressionUserControl.UserControlScaleY));
                }
                else
                {
                    //rect = inkRegion.LeftSideRegionRect;
                    rect = new Rect(new Point(inkRegion.EqualRect.TopLeft.X - expressionUserControl.ActualWidth * expressionUserControl.UserControlScaleX, inkRegion.EqualRect.TopLeft.Y),
                           new Size(expressionUserControl.ActualWidth * expressionUserControl.UserControlScaleX, expressionUserControl.ActualHeight * expressionUserControl.UserControlScaleY));
                }

                if (userControlRect.IntersectsWith(rect))
                {
                    return true;
                }

                #endregion
            }
            else if (element is LogicPad2.TruthTable.UserControl1)
            {
                #region TruthTable

                LogicPad2.TruthTable.UserControl1 truthTableUserControl = element as LogicPad2.TruthTable.UserControl1;
                Rect userControlRect = new Rect(truthTableUserControl.UserControlX,
                            truthTableUserControl.UserControlY,
                            truthTableUserControl.ActualWidth * truthTableUserControl.UserControlScaleX,
                            truthTableUserControl.ActualHeight * truthTableUserControl.UserControlScaleY);

                if (isRightSide)
                {
                    //rect = inkRegion.RightSideRegionRect;
                    rect = new Rect(new Point(inkRegion.EqualRect.TopRight.X, inkRegion.EqualRect.TopRight.Y),
                            new Size(truthTableUserControl.ActualWidth * truthTableUserControl.UserControlScaleX, truthTableUserControl.ActualHeight * truthTableUserControl.UserControlScaleY));
                }
                else
                {
                    //rect = inkRegion.LeftSideRegionRect;
                    rect = new Rect(new Point(inkRegion.EqualRect.TopLeft.X - truthTableUserControl.ActualWidth * truthTableUserControl.UserControlScaleX, inkRegion.EqualRect.TopLeft.Y),
                           new Size(truthTableUserControl.ActualWidth * truthTableUserControl.UserControlScaleX, truthTableUserControl.ActualHeight * truthTableUserControl.UserControlScaleY));
                }

                if (userControlRect.IntersectsWith(rect))
                {
                    return true;
                }

                #endregion
            }
            return false;
        }
示例#3
0
        public void GenerateSubInkCanvas(object sender, SubCanvasEventArgs args)
        {
            switch (args.LogicCanvasType)
            { 
                case LogicCanvasType.Diagram:
                    
                    Diagram.UserControl1 diagramUserControl1 = new Diagram.UserControl1();

                    diagramUserControl1.UserControlX = args.Central.X;
                    diagramUserControl1.UserControlY = args.Central.Y;

                    this.Children.Add(diagramUserControl1);

                    //Ad-hoc
                    diagramUserControl1.disableInkHandler += new DisableInkHandler(diagramUserControl1_disableInkCanvasInkHandler);
                    
                    if(args.MyStrokes != null)
                        DeleteRecognizedStrokesOnInkCanvas(args.MyStrokes);
                    
                    break;
                case LogicCanvasType.Expression:    
                    Expression.UserControl1 expressionUserControl = new Expression.UserControl1();

                    expressionUserControl.UserControlX = args.Central.X - expressionUserControl.UserControlWidth / 2;
                    expressionUserControl.UserControlY = args.Central.Y - expressionUserControl.UserControlHeight / 2;
                  
                    this.Children.Add(expressionUserControl);

                    if(args.MyStrokes != null)
                        DeleteRecognizedStrokesOnInkCanvas(args.MyStrokes);
                   
                    break;
                case LogicCanvasType.TruthTable:
                    TruthTable.UserControl1 truthTableUserControl = new TruthTable.UserControl1();

                    truthTableUserControl.UserControlX = args.Central.X - truthTableUserControl.UserControlWidth / 2;
                    truthTableUserControl.UserControlY = args.Central.Y - truthTableUserControl.UserControlHeight / 2;

                    this.Children.Add(truthTableUserControl);

                    if(args.MyStrokes != null)
                        DeleteRecognizedStrokesOnInkCanvas(args.MyStrokes);

                    break;
                case LogicCanvasType.EqualSign:
                    if (!HasEqualSignInkRegionAdded(args.MyStrokes))
                    {
                        InkQueryRegionStruct equalRegion = new InkQueryRegionStruct(args.MyStrokes);

                        if (!HasControlInLeftRegion(ref equalRegion))
                        {
                            equalRegion.GenerateLeftSideRegion();
                        }
                        
                        if (!HasControlInRightRegion(ref equalRegion))
                        {
                            equalRegion.GenerateRightSideRegion();
                        }

                        //Check Parsing Current InkQueryRegionStruct
                        if (equalRegion.LeftSideUserControl != null && equalRegion.RightSideUserControl != null)
                        {
                            if (LogicParser1.Instance.MatchTwoUserControl(equalRegion.LeftSideUserControl, equalRegion.RightSideUserControl))
                            {
                                this.Dispatcher.BeginInvoke((Action)(() => { MessageBox.Show("Match On Two Representations"); }));
                            }
                            else
                            {

                                this.Dispatcher.BeginInvoke((Action)(() => { MessageBox.Show("Not Match on Two Representations"); }));
                            }
                            this.Strokes.Remove(equalRegion.EqualStrokes);
                        }
                        else {
                            this.Children.Add(equalRegion);
                        }
                        
                    }
                    _inkAnalyzer.RemoveStrokes(args.MyStrokes);
                    ShowInkAnalysisFeedback = false;
                    break;
                case LogicCanvasType.Question:
                    this.Dispatcher.BeginInvoke((Action)(() => { MessageBox.Show("Basic User Manual"); }));
                    break;
            }
        }