void LineAdorner_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (!IsControlModeOn)
            {
                if (this.IsMouseCaptured)
                {
                    CustomLineElement line     = this.AdornedElement as CustomLineElement;
                    LineLogicItem     lineItem = line.DataContext as LineLogicItem;
                    Point             p        = SnapGrid.Snap(e.GetPosition(line), gridSize, GridOffsetLeft, GridOffsetTop);

                    if (IsStartPoint)
                    {
                        lineItem.X1 = p.X;
                        lineItem.Y1 = p.Y;
                    }
                    else
                    {
                        lineItem.X2 = p.X;
                        lineItem.Y2 = p.Y;
                    }

                    // update line item modification flag
                    //if (originalLineItem.CheckForModification(lineItem))
                    //    lineItem.IsModified = true;

                    this.InvalidateVisual();
                    this.ReleaseMouseCapture();
                    this.Cursor = Cursors.Arrow;
                }
            }
        }
Beispiel #2
0
        protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
        {
            if (this.DataContext is PageItem)
            {
                PageItem Page = this.DataContext as PageItem;
                Point    p    = SnapGrid.Snap(e.GetPosition(this), GridSize, GridOffsetLeft, GridOffsetTop);

                if (this.IsMouseCaptured)
                {
                    if ((currentLineItem.X1 == p.X && currentLineItem.Y1 == p.Y) ||
                        (currentLineItem.X1 == currentLineItem.X2 && currentLineItem.Y1 == currentLineItem.Y2))
                    {
                        Page.Items.Remove(currentLineItem);
                        currentLineItem = null;
                        this.ReleaseMouseCapture();
                    }
                    else
                    {
                        currentLineItem.X2 = p.X;
                        currentLineItem.Y2 = p.Y;
                        this.ReleaseMouseCapture();
                    }
                }
            }
        }
Beispiel #3
0
 public static void FromPoints(this LineLogicItem item, Point startPoint, Point endPoint)
 {
     item.X1 = startPoint.X;
     item.Y1 = startPoint.Y;
     item.X2 = endPoint.X;
     item.Y2 = endPoint.Y;
 }
        void Paste()
        {
            if (cloneItem != null)
            {
                var   Page = this.DataContext as PageItem;
                Point p    = GetClickLocation(GridOffsetLeft, GridOffsetTop);

                Item item = (Item)cloneItem.Clone();
                item.X = p.X;
                item.Y = p.Y;

                if (item is DataBlockLogicItem)
                {
                    SnapDataBlockLogicItem(item, 0.0, 0.0, DataBlockSnapMode.Auto);
                }
                else if (item is LineLogicItem)
                {
                    LineLogicItem line = (LineLogicItem)item;

                    // TODO:
                }

                Page.Items.Add(item);
            }
        }
        void LineAdorner_MouseMove(object sender, MouseEventArgs e)
        {
            if (this.IsMouseCaptured)
            {
                if (this.AdornedElement.GetType() == typeof(CustomLineElement))
                {
                    CustomLineElement line     = this.AdornedElement as CustomLineElement;
                    LineLogicItem     lineItem = line.DataContext as LineLogicItem;

                    Point p = SnapGrid.Snap(e.GetPosition(line), gridSize, GridOffsetLeft, GridOffsetTop);

                    // edit mode: move line start point OR move line end point
                    if (mode == LineAdornerMode.Edit)
                    {
                        if (IsStartPoint)
                        {
                            lineItem.X1 = p.X;
                            lineItem.Y1 = p.Y;
                        }
                        else
                        {
                            lineItem.X2 = p.X;
                            lineItem.Y2 = p.Y;
                        }
                    }

                    // move mode: move line start point AND move line end point

                    if (mode == LineAdornerMode.Move)
                    {
                        if (IsStartPoint)
                        {
                            double dX   = lineItem.X1 - p.X;
                            double dY   = lineItem.Y1 - p.Y;
                            Point  pEnd = new Point(lineItem.X2 - dX, lineItem.Y2 - dY);

                            lineItem.X1 = p.X;
                            lineItem.Y1 = p.Y;
                            lineItem.X2 = pEnd.X;
                            lineItem.Y2 = pEnd.Y;
                        }
                        else
                        {
                            double dX     = lineItem.X2 - p.X;
                            double dY     = lineItem.Y2 - p.Y;
                            Point  pStart = new Point(lineItem.X1 - dX, lineItem.Y1 - dY);

                            lineItem.X2 = p.X;
                            lineItem.Y2 = p.Y;
                            lineItem.X1 = pStart.X;
                            lineItem.Y1 = pStart.Y;
                        }
                    }

                    this.InvalidateVisual();
                }
            }
        }
Beispiel #6
0
 public static bool CheckForModification(this LineLogicItem oldLine, LineLogicItem newLine)
 {
     if (oldLine.X1 == newLine.X1 &&
         oldLine.Y1 == newLine.Y1 &&
         oldLine.X2 == newLine.X2 &&
         oldLine.Y2 == newLine.Y2)
     {
         return(false);
     }
     return(true);
 }
Beispiel #7
0
        public static LineLogicItem Copy(LineLogicItem source)
        {
            LineLogicItem destination = new LineLogicItem()
            {
                IsNew      = source.IsNew,
                IsModified = source.IsModified,
                IsDeleted  = source.IsDeleted,
                X1         = source.X1,
                Y1         = source.Y1,
                X2         = source.X2,
                Y2         = source.Y2,
                X          = source.X,
                Y          = source.Y,
                Z          = source.Z
            };

            return(destination);
        }
Beispiel #8
0
 public static bool Compare(this LineLogicItem oldLine, LineLogicItem newLine)
 {
     if (
         oldLine.IsNew == newLine.IsNew &&
         oldLine.IsModified == newLine.IsModified &&
         oldLine.IsDeleted == newLine.IsDeleted &&
         oldLine.X1 == newLine.X1 &&
         oldLine.Y1 == newLine.Y1 &&
         oldLine.X2 == newLine.X2 &&
         oldLine.Y2 == newLine.Y2 &&
         oldLine.X == newLine.X &&
         oldLine.Y == newLine.Y &&
         oldLine.Z == newLine.Z)
     {
         return(true);
     }
     return(false);
 }
        //static Pen penGuide = new Pen(new SolidColorBrush(Color.FromArgb(128, 255, 127, 0)), 1.0);

        protected override void OnRender(DrawingContext drawingContext)
        {
            if (this.AdornedElement.GetType() == typeof(CustomLineElement))
            {
                CustomLineElement line     = this.AdornedElement as CustomLineElement;
                LineLogicItem     lineItem = line.DataContext as LineLogicItem;

                Canvas c = FindVisualParent <Canvas>(line);
                double w = c.Width;
                double h = c.Height;

                // draw guide lines
                if (this.IsMouseCaptured)
                {
                    /*
                     * double halfPenWidthGuide = penGuide.Thickness / 2;
                     *
                     * // horizontal guide
                     * Point h0 = new Point(0, IsStartPoint ? lineItem.Y1 : lineItem.Y2);
                     * Point h1 = new Point(w, IsStartPoint ? lineItem.Y1 : lineItem.Y2);
                     *
                     * // vertical guide
                     * Point v0 = new Point(IsStartPoint ? lineItem.X1 : lineItem.X2, 0);
                     * Point v1 = new Point(IsStartPoint ? lineItem.X1 : lineItem.X2, h);
                     *
                     * // draw lines
                     * GuidelineSet gg1 = new GuidelineSet();
                     * gg1.GuidelinesX.Add(h0.X + halfPenWidthGuide);
                     * gg1.GuidelinesX.Add(h1.X + halfPenWidthGuide);
                     * gg1.GuidelinesY.Add(h0.Y + halfPenWidthGuide);
                     * gg1.GuidelinesY.Add(h1.Y + halfPenWidthGuide);
                     * drawingContext.PushGuidelineSet(gg1);
                     *
                     * drawingContext.DrawLine(penGuide, h0, h1);
                     * drawingContext.Pop();
                     *
                     * GuidelineSet gg2 = new GuidelineSet();
                     * gg2.GuidelinesX.Add(v0.X + halfPenWidthGuide);
                     * gg2.GuidelinesX.Add(v1.X + halfPenWidthGuide);
                     * gg2.GuidelinesY.Add(v0.Y + halfPenWidthGuide);
                     * gg2.GuidelinesY.Add(v1.Y + halfPenWidthGuide);
                     * drawingContext.PushGuidelineSet(gg2);
                     *
                     * drawingContext.DrawLine(penGuide, v0, v1);
                     * drawingContext.Pop();
                     */
                }

                double halfPenWidth = pen.Thickness / 2;

                //Point p1 = new Point(lineItem.X1, lineItem.Y1);
                //Point p2 = new Point(lineItem.X2, lineItem.Y2);

                Point p1 = new Point(line.X1, line.Y1);
                Point p2 = new Point(line.X2, line.Y2);

                p1.Offset(-size.Width / 2, -size.Height / 2);
                p2.Offset(-size.Width / 2, -size.Height / 2);

                Rect r1 = new Rect(p1, size);
                Rect r2 = new Rect(p2, size);

                GuidelineSet g1 = new GuidelineSet();
                g1.GuidelinesX.Add(r1.Left + halfPenWidth);
                g1.GuidelinesX.Add(r1.Right + halfPenWidth);
                g1.GuidelinesY.Add(r1.Top + halfPenWidth);
                g1.GuidelinesY.Add(r1.Bottom + halfPenWidth);
                drawingContext.PushGuidelineSet(g1);

                drawingContext.DrawRectangle(brush, pen, r1);
                drawingContext.Pop();

                GuidelineSet g2 = new GuidelineSet();
                g2.GuidelinesX.Add(r2.Left + halfPenWidth);
                g2.GuidelinesX.Add(r2.Right + halfPenWidth);
                g2.GuidelinesY.Add(r2.Top + halfPenWidth);
                g2.GuidelinesY.Add(r2.Bottom + halfPenWidth);
                drawingContext.PushGuidelineSet(g2);

                drawingContext.DrawRectangle(brush, pen, r2);
                drawingContext.Pop();
            }

            base.OnRender(drawingContext);
        }
        void LineAdorner_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (Keyboard.Modifiers == ModifierKeys.Control)
            {
                IsControlModeOn = true;
            }

            CustomLineElement line     = this.AdornedElement as CustomLineElement;
            LineLogicItem     lineItem = line.DataContext as LineLogicItem;
            Point             p        = SnapGrid.Snap(e.GetPosition(line), GridSize, GridOffsetLeft, GridOffsetTop);

            double dStart = 0.0;
            double dEnd   = 0.0;

            if (!this.IsMouseCaptured)
            {
                // copy original coordinates
                originalLineItem = new LineLogicItem()
                {
                    X1 = lineItem.X1,
                    Y1 = lineItem.Y1,
                    X2 = lineItem.X2,
                    Y2 = lineItem.Y2
                };

                // calculate start/end point coordinates
                dStart = Math.Sqrt(Math.Pow(lineItem.X1 - p.X, 2) + Math.Pow(lineItem.Y1 - p.Y, 2));
                dEnd   = Math.Sqrt(Math.Pow(lineItem.X2 - p.X, 2) + Math.Pow(lineItem.Y2 - p.Y, 2));
            }

            if (IsControlModeOn)
            {
                if (this.IsMouseCaptured)
                {
                    if (IsStartPoint)
                    {
                        lineItem.X1 = p.X;
                        lineItem.Y1 = p.Y;
                    }
                    else
                    {
                        lineItem.X2 = p.X;
                        lineItem.Y2 = p.Y;
                    }

                    this.InvalidateVisual();
                    this.ReleaseMouseCapture();

                    IsControlModeOn = false;
                }
                else
                {
                    IsStartPoint = dStart < dEnd ? true : false;
                    this.Cursor  = Cursors.Hand;
                    this.InvalidateVisual();
                    this.CaptureMouse();
                }
            }
            else
            {
                if (!this.IsMouseCaptured)
                {
                    IsStartPoint = dStart < dEnd ? true : false;
                    this.Cursor  = Cursors.Hand;
                    this.InvalidateVisual();
                    this.CaptureMouse();
                }
            }
        }
Beispiel #11
0
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            if (this.DataContext is PageItem)
            {
                //if (Keyboard.Modifiers == ModifierKeys.Control)
                //    IsControlModeOn = true;

                /*
                 * PageItem Page = this.DataContext as PageItem;
                 * Point p = GetClickLocation(e.GetPosition(this), GridOffsetLeft, GridOffsetTop);
                 * Page.Items.Add(new AndGateLogicItem()
                 * {
                 *  IsNew = true,
                 *  IsModified = false,
                 *  IsDeleted = false,
                 *  X = p.X,
                 *  Y = p.Y,
                 *  Z = 1
                 * });
                 */

                PageItem Page = this.DataContext as PageItem;
                Page.SelectedItem = null;

                Point p = SnapGrid.Snap(e.GetPosition(this), GridSize, GridOffsetLeft, GridOffsetTop);
                if (this.IsMouseCaptured)
                {
                    //currentLineItem.X2 = p.X;
                    //currentLineItem.Y2 = p.Y;
                    //c.ReleaseMouseCapture();
                }
                else
                {
                    Point pHit = e.GetPosition(this);

                    CustomLineElement lineHit = null;
                    HitTestResult     result  = VisualTreeHelper.HitTest(this, pHit);
                    if (result != null)
                    {
                        if (result.VisualHit.GetType() == typeof(CustomLineElement))
                        {
                            lineHit = result.VisualHit as CustomLineElement;
                        }
                    }

                    if (lineHit == null && selectedLine == null)
                    {
                        currentLineItem = new LineLogicItem()
                        {
                            IsNew      = false,
                            IsModified = false,
                            IsDeleted  = false,
                            X1         = p.X,
                            Y1         = p.Y,
                            X2         = p.X,
                            Y2         = p.Y,
                            Z          = 0
                        };

                        Page.Items.Add(currentLineItem);
                        this.CaptureMouse();
                    }

                    if (lineHit != selectedLine && selectedLine != null)
                    {
                        if (Keyboard.Modifiers != ModifierKeys.Control)
                        {
                            var LineAdornerLayer = AdornerLayer.GetAdornerLayer(selectedLine);
                            if (LineAdornerLayer != null)
                            {
                                LineAdornerLayer.Remove(LineAdornerLayer.GetAdorners(selectedLine)[0]);
                            }

                            selectedLine = null;
                        }
                    }

                    if (lineHit != null && lineHit != selectedLine)
                    {
                        selectedLine = lineHit;
                        var LineAdornerLayer = AdornerLayer.GetAdornerLayer(lineHit);

                        if (LineAdornerLayer != null)
                        {
                            LineAdornerLayer.Add(new LineAdorner(lineHit));
                        }
                    }

                    //currentLineItem = new LineLogicItem() { X1 = p.X, Y1 = p.Y, X2 = p.X, Y2 = p.Y, Z = 0 };
                    //Page.Items.Add(currentLineItem);
                    //c.CaptureMouse();
                }
            }
        }
Beispiel #12
0
        protected override void OnMouseRightButtonDown(MouseButtonEventArgs e)
        {
            if (this.DataContext is PageItem)
            {
                PageItem Page = this.DataContext as PageItem;
                Point    p    = SnapGrid.Snap(e.GetPosition(this), GridSize, GridOffsetLeft, GridOffsetTop);

                if (this.IsMouseCaptured)
                {
                    Page.Items.Remove(currentLineItem);
                    currentLineItem = null;
                    this.ReleaseMouseCapture();
                }
                else
                {
                    // delete line element

                    /*
                     * Point pHit = e.GetPosition(this);
                     *
                     * CustomLineElement lineHit = null;
                     * HitTestResult result = VisualTreeHelper.HitTest(this, pHit);
                     * if (result != null)
                     * {
                     *  if (result.VisualHit.GetType() == typeof(CustomLineElement))
                     *  {
                     *      lineHit = result.VisualHit as CustomLineElement;
                     *      Page.Items.Remove(lineHit.DataContext as LineLogicItem);
                     *  }
                     * }
                     */
                }

                /*
                 * Canvas c = sender as Canvas;
                 * Point p = SnapGrid.Snap(e.GetPosition(this), GridSize, GridOffsetLeft, GridOffsetTop);
                 * CustomLineElement lineHit = null;
                 *
                 * HitTestResult result = VisualTreeHelper.HitTest(c, p);
                 * if (result != null)
                 * {
                 *  if (result.VisualHit.GetType() == typeof(CustomLineElement))
                 *  {
                 *      lineHit = result.VisualHit as CustomLineElement;
                 *  }
                 * }
                 *
                 * if (selectedLine != null && lineHit != selectedLine)
                 * {
                 *  var LineAdornerLayer = AdornerLayer.GetAdornerLayer(selectedLine);
                 *  LineAdornerLayer.Remove(LineAdornerLayer.GetAdorners(selectedLine)[0]);
                 *  selectedLine = null;
                 * }
                 *
                 * if (lineHit != null && lineHit != selectedLine)
                 * {
                 *  selectedLine = lineHit;
                 *  var LineAdornerLayer = AdornerLayer.GetAdornerLayer(lineHit);
                 *  LineAdornerLayer.Add(new LineAdorner(lineHit));
                 * }
                 */
            }
        }