Ejemplo n.º 1
0
        /// <summary>
        /// oblouk tvoreny dvema po sobe jdoucimi useckami a polomerem
        /// takzvane zaobleni rohu
        /// pokud je polomer zaporny vytvori se tzv. vykousnuti  se stredem ve spolecnem bode
        /// objekt se nastavi na empty pokud jsou usecky rovnobezne nebo jedna z nich ma nulovou delku
        /// </summary>
        /// <param name="pt1">pocatecni bod prvni ridici usecky</param>
        /// <param name="pt2">spolecny bod ridicich usecek</param>
        /// <param name="pt3">konecny bod druhe ridici usecky</param>
        /// <param name="radius">polomer zaobleni, zaporny polomer provede vykousnuti</param>
        /// <param name="testPt">pokud se pocatecni nebo koncovy bod vypocita mimo usecku, objekt se nastavi na Empty</param>
        public Arc2D(Point pt1, Point pt2, Point pt3, double radius, bool testPt = false)
        {
            // zjistim smer offsetu
            double a = Vector.AngleBetween(pt2.Minus(pt1), pt3.Minus(pt2));

            if (a > 0)
            {
                a         = -Math.Abs(radius);
                Clockwise = false;
            }
            else
            {
                a         = Math.Abs(radius);
                Clockwise = true;
            }

            // vypocitam prusecik offsetovanych primek
            Point[] p1 = Funcs2D.LineOffset(pt1, pt2, a);
            Point[] p2 = Funcs2D.LineOffset(pt2, pt3, a);
            if (p1 == null || p2 == null || !TwoLine2D.CrossRel(p1[0], p1[1], p2[0], p2[1], out Point rr))
            {
                // tri body na jedne primce
                Begin  = pt1; End = pt3;
                Radius = 0;
                return;
            }
            if (radius > 0)
            {
                if (testPt)
                {
                    if (!TwoLine2D.TestRelOnLine(TwoLine2D.CrossStatus.And, rr.X) || !TwoLine2D.TestRelOnLine(TwoLine2D.CrossStatus.And, rr.Y))
                    {
                        // body jsou mimo usecky
                        Begin  = pt1; End = pt3;
                        Radius = 0;
                        return;
                    }
                }

                // koeficienty prenesu do puvodnich usecek a spocitam body
                Begin  = Funcs2D.PointOnLine(pt1, pt2, rr.X);
                End    = Funcs2D.PointOnLine(pt2, pt3, rr.Y);
                Radius = radius;
            }
            else
            {
                Radius = -radius;
                if (testPt)
                {
                    if (Funcs2D.Distance(pt1, pt2) < Radius || Funcs2D.Distance(pt2, pt3) < Radius)
                    {
                        // body jsou mimo usecky
                        Begin  = pt1; End = pt3;
                        Radius = 0;
                        return;
                    }
                }
                // bod na prvni primce ve vzdalenosti abs(radius) od spolecneho bodu
                Begin = Funcs2D.PointOnLineLen(pt2, pt1, Radius);
                // bod na druhe primce
                End       = Funcs2D.PointOnLineLen(pt2, pt3, Radius);
                Clockwise = !Clockwise;
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// vytvori oblouk zadany dvema body a zdvihem v poloine usecky ktera je tvorena body
 /// </summary>
 /// <param name="pt1">pocatecni bod oblouku</param>
 /// <param name="pt2">koncovy bod oblouky</param>
 /// <param name="elevation">zdvih oblouku v polovine usecky [pt1,pt2]</param>
 /// <returns></returns>
 public static Arc2D Arc2DElevation(Point pt1, Point pt2, double elevation)
 {
     return(Arc2DElevation(pt1, pt2.Minus(pt1), elevation));
 }
Ejemplo n.º 3
0
 public override void MoveToCore(Point newPosition)
 {
     Offset = newPosition.Minus(Origin);
     base.MoveToCore(newPosition);
 }
Ejemplo n.º 4
0
 public Rectangle MoveTo(Point absolute)
 {
     return(new Rectangle(absolute, absolute.Plus(_max.Minus(_min))));
 }
Ejemplo n.º 5
0
 public override void MoveToCore(Point newPosition)
 {
     Point newOffset = newPosition.Minus(Point(0));
     Offset = newOffset;
     base.MoveToCore(newPosition);
 }
Ejemplo n.º 6
0
 internal void MouseMove(Point point)
 {
     if (state == CanvasState.Dragging)
     {
         Point d = point.Minus(draggingOrigin);
         Point p1 = allViews[dragged];
         Point p2 = p1.Offseted(d);
         Size sz = dragged.Assemble().Size;
         Rectangle inva = Rectangle.Union(new Rectangle(p1, sz), new Rectangle(p2, sz));
         inva.Inflate(5, 5);
         draggedModel.Location = p2;
         draggingOrigin = point;
         DropRegion active;
         if (FindActiveDropRegion(ViewBounds(dragged), out active))
         {
             Rectangle topLevelDest = ViewBounds(active.Destination.AbsoluteAncestor());
             inva = Rectangle.Union(inva, topLevelDest);
         }
         Update(inva);
     }
     if (state == CanvasState.Ready)
     {
         /*
         IBlockView hit = HitTest(point);
         if (hit != null)
             canvasView.status = hit.ToString();
         else
             canvasView.status = "<None>";
          //*/
     }
 }
Ejemplo n.º 7
0
        private void LButtonDown(Point pt)
        {
            offsetFromFigureLeftTopCorner = this.ToLogical(pt);

            oldCoordinates = offsetFromFigureLeftTopCorner;

            moving = new List <IMovable>();
            IEnumerable <IFigure> roots = null;

            IFigure found = Drawing.Figures.HitTest(offsetFromFigureLeftTopCorner);
            IEnumerable <IFigure> selection = null;

            if (found is SubPoint)
            {// can't move sub point 01-11-10 scott
                return;
            }
            // remove by scott 08-25-2009
            if (IsCtrlPressed())
            {
                if (found != null)
                {
                    found.Selected = !found.Selected;
                }
                selection = Drawing.GetSelectedFigures();
            }
            else
            {
                if (found == null || !found.Selected)
                {
                    Drawing.ClearSelectedFigures();
                    if (found != null)
                    {
                        found.Selected = true;
                        selection      = found.AsEnumerable();
                    }
                }
            }

            IEnumerable <IFigure> selectedFigures = Drawing.GetSelectedFigures();

            Drawing.RaiseSelectionChanged(new Drawing.SelectionChangedEventArgs(selectedFigures));

            IMovable oneMovable = found as IMovable;

            if (oneMovable != null /*&&!(oneMovable is Game.Zone)* 03-10-2011 Scott*/)
            {
                /*if (oneMovable is IPoint)
                 * {
                 *  // when we drag a point, we want it to snap to the cursor
                 *  // so that the point center is directly under the tip of the mouse
                 *  offsetFromFigureLeftTopCorner = new Point();
                 *  oldCoordinates = oneMovable.Coordinates;
                 * }
                 * else
                 * {*/
                // however when we drag other stuff (such as text labels)
                // we want the mouse to always touch the part of the draggable
                // where it first touched during MouseDown
                // we don't want the draggable to "snap" to the cursor like points do
                offsetFromFigureLeftTopCorner = offsetFromFigureLeftTopCorner.Minus(oneMovable.Coordinates);
                /*}*/
                moving.Add(oneMovable);
                roots = found.AsEnumerable();
            }
            else if (found != null)
            {
                if (!(found is Game.Zone) && !(found is LineBase))  // 11-18-2010 Scott
                {
                    roots = DependencyAlgorithms.FindRoots(f => f.Dependencies, found);
                    if (roots.All(root => root is IMovable))
                    {
                        moving.AddRange(roots.Cast <IMovable>());
                    }
                }
            }

            if (roots != null)
            {
                toRecalculate = DependencyAlgorithms.FindDescendants(f => f.Dependents, roots).Reverse();
            }
            else
            {
                toRecalculate = null;
            }

            //03-09-2010 Scott
            if (moving.Count > 0 && moving[0] is Game.PBBall && mode == 1)
            {
                Drawing.Figures.OfType <IMovable>().ForEach(f =>
                {
                    if (!(f is Game.PBBall) && !(f is SubPoint))
                    {
                        moving.Add(f);
                    }
                }
                                                            );
            }
            else if (found != null)
            {
                IEnumerable <IFigure> figuresSelected = Drawing.GetSelectedFigures();
                if (figuresSelected.All(f => f is Game.PBPlayer || f is LabelBase || f is FreePoint || f is PrePoint || f is PBLine)) // 11-12-2010 Scott add labelbase support
                {
                    moving.Clear();
                    IEnumerable <IFigure> fs = Drawing.GetSelectedFigures();
                    // 08-04-11 Scott
                    foreach (IFigure f in fs)
                    {
                        if (f is PBLine)
                        {
                            foreach (IFigure pf in (f as PBLine).Dependencies)
                            {
                                if (pf is IMovable && !moving.Contains(pf as IMovable))
                                {
                                    moving.Add(pf as IMovable);
                                }
                            }
                        }

                        if (f is IMovable)
                        {
                            moving.Add(f as IMovable);
                        }
                    }
                    // end
                }
            }

            if (moving.IsEmpty())
            {// coordinate system
             //Drawing.Canvas.Cursor = new Cursor(AppDomain.CurrentDomain.BaseDirectory + @"\Resource\CursorHand.cur");    //01-04-2010 scott

                //moving.Add(Drawing.CoordinateSystem);

                //var allFigures = Drawing.Figures.GetAllFiguresRecursive();    // remove by scott 06-24-2009
                //roots = DependencyAlgorithms.FindRoots(f => f.Dependencies, allFigures);
                //moving.AddRange(roots.OfType<IMovable>());
                //roots = null;
                toRecalculate = null; // Figures;
            }
        }
Ejemplo n.º 8
0
        public static void MoveTo(this IMovable movable, Point newPosition, Drawing drawing)
        {
            MoveAction action = new MoveAction(drawing, new[] { movable }, newPosition.Minus(movable.Coordinates), null);

            drawing.ActionManager.RecordAction(action);
        }
Ejemplo n.º 9
0
        private static Rectangle selectTooltipBounds(Size size, Rectangle target, Rectangle workingArea, Point cursor)
        {
            var bounds = new Rectangle(target.Location, size);

            if (bounds.Width > workingArea.Width)
            {
                bounds.Width = workingArea.Width;
            }

            if (bounds.Height > workingArea.Height)
            {
                bounds.Height = workingArea.Height;
            }

            int atTop = target.Top - size.Height;
            int atBtm = target.Bottom;
            int atRht = target.Right;
            int atLft = target.Left - size.Width;

            int byTop = target.Top;
            int byMid = cursor.Y - size.Height / 2;
            int byBtm = target.Bottom - size.Height;

            int byRht = target.Right - size.Width;
            int byCtr = cursor.X - size.Width / 2;
            int byLft = target.Left;

            var toBtm = new Point(0, TooltipMargin);
            var toTop = new Point(0, -TooltipMargin);
            var toRht = new Point(TooltipMargin, 0);
            var toLft = new Point(-TooltipMargin, 0);

            var candidates = new List <TooltipPosition>
            {
                new TooltipPosition(size, byLft, atBtm, toBtm),
                new TooltipPosition(size, byCtr, atBtm, toBtm),
                new TooltipPosition(size, byRht, atBtm, toBtm),

                new TooltipPosition(size, byLft, atTop, toTop),
                new TooltipPosition(size, byCtr, atTop, toTop),
                new TooltipPosition(size, byRht, atTop, toTop),

                new TooltipPosition(size, atRht, byTop, toRht),
                new TooltipPosition(size, atRht, byMid, toRht),
                new TooltipPosition(size, atRht, byBtm, toRht),

                new TooltipPosition(size, atLft, byTop, toLft),
                new TooltipPosition(size, atLft, byMid, toLft),
                new TooltipPosition(size, atLft, byBtm, toLft)
            };

            for (int i = 0; i < candidates.Count; i++)
            {
                var c = candidates[i];

                c.Bounds           = c.Bounds.OffsetInto(workingArea);
                c.IntersectsTarget = target.IntersectsWith(c.Bounds);
                c.DistanceToCursor = cursor.Minus(c.Bounds.Center()).SquareNorm();
            }

            var candidate = candidates
                            .AtMin(_ => _.IntersectsTarget)
                            .ThenAtMin(_ => _.DistanceToCursor)
                            .Find();

            return(candidate.Bounds);
        }
Ejemplo n.º 10
0
 public override void MoveToCore(Point newPosition)
 {
     Point newOffset = newPosition.Minus(Point(0));
     newOffset = newOffset.TrimToMaxLength(ToLogical(100));
     Offset = newOffset;
     base.MoveToCore(newPosition);
 }
Ejemplo n.º 11
0
 public override void MoveToCore(Point newPosition)
 {
     Offset = newPosition.Minus(Midpoint());
     base.MoveToCore(newPosition);
 }
Ejemplo n.º 12
0
 public static void CartesianToPolar(Point point, Point center, out double radius, out double phi)
 {
     var p = point.Minus(center);
     radius = Math.Sqrt((p.X * p.X) + (p.Y * p.Y));
     phi = Math.Atan2(p.Y, p.X);
 }
Ejemplo n.º 13
0
        protected override void MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            // Add by scott 11-06-2009
            if (Drawing.HasGridLines)
            {
                Point ptCoordinates = Coordinates(e);

                if (moving != null && moving.Count > 0 && (moving.Count == 1 && moving[0] is Game.PBPlayer || moving[0] is Game.PBBall || moving.Count > 1))
                {
                    IMovable mv = moving[0];

                    double x = mv.Coordinates.X % 0.5;
                    double y = mv.Coordinates.Y % 0.5;
                    if (Math.Abs(x) > 0.25)
                    {
                        if (x >= 0)
                        {
                            ptCoordinates.X = ((int)(mv.Coordinates.X / 0.5) + 1) * 0.5;
                        }
                        else
                        {
                            ptCoordinates.X = ((int)(mv.Coordinates.X / 0.5) - 1) * 0.5;
                        }
                    }
                    else
                    {
                        ptCoordinates.X = (int)(mv.Coordinates.X / 0.5) * 0.5;
                    }
                    if (Math.Abs(y) > 0.25)
                    {
                        if (y >= 0)
                        {
                            ptCoordinates.Y = ((int)(mv.Coordinates.Y / 0.5) + 1) * 0.5;
                        }
                        else
                        {
                            ptCoordinates.Y = ((int)(mv.Coordinates.Y / 0.5) - 1) * 0.5;
                        }
                    }
                    else
                    {
                        ptCoordinates.Y = (int)(mv.Coordinates.Y / 0.5) * 0.5;
                    }
                    //ptCoordinates.X = Math.Round(player.Coordinates.X, 0);
                    //ptCoordinates.Y = Math.Round(player.Coordinates.Y, 0);

                    var offset = ptCoordinates.Minus(mv.Coordinates);

                    MoveAction action = new MoveAction(Drawing, moving, offset, toRecalculate);
                    Drawing.ActionManager.RecordAction(action);
                }
            }

            if (moving != null && moving.IsEmpty())
            {//01-04-2010 scott
                Drawing.Canvas.Cursor = null;
            }

            moving = null;

            Drawing.Figures.UpdateVisual();
        }
Ejemplo n.º 14
0
            public static void ArcToBezier(double xStart, double yStart, double xRadius, double yRadius,
                                           double rRotation, bool fLargeArc, bool fSweepUp, double xEnd, double yEnd, out Point[] pPt,
                                           out int cPieces)
            {
                var num = 1E-06;

                pPt = new Point[12];
                var num12 = num * num;
                var flag  = false;

                cPieces = -1;
                var num2 = 0.5 * (xEnd - xStart);
                var num3 = 0.5 * (yEnd - yStart);
                var num4 = num2 * num2 + num3 * num3;

                if (num4 >= num12)
                {
                    if (!AcceptRadius(num4, num12, ref xRadius) || !AcceptRadius(num4, num12, ref yRadius))
                    {
                        cPieces = 0;
                    }
                    else
                    {
                        double num5;
                        double num6;
                        // ReSharper disable once InlineOutVariableDeclaration
                        double num7;
                        // ReSharper disable once InlineOutVariableDeclaration
                        double num8;
                        double num9;
                        double num10;
                        Point  point4;
                        if (Math.Abs(rRotation) < num)
                        {
                            num5 = 1.0;
                            num6 = 0.0;
                        }
                        else
                        {
                            rRotation = -rRotation * 3.1415926535897931 / 180.0;
                            num5      = Math.Cos(rRotation);
                            num6      = Math.Sin(rRotation);
                            var num15 = num2 * num5 - num3 * num6;
                            num3 = num2 * num6 + num3 * num5;
                            num2 = num15;
                        }

                        num2 /= xRadius;
                        num3 /= yRadius;
                        num4  = num2 * num2 + num3 * num3;
                        if (num4 > 1.0)
                        {
                            var num16 = Math.Sqrt(num4);
                            xRadius *= num16;
                            yRadius *= num16;
                            num9     = num10 = 0.0;
                            flag     = true;
                            num2    /= num16;
                            num3    /= num16;
                        }
                        else
                        {
                            var num17 = Math.Sqrt((1.0 - num4) / num4);
                            if (fLargeArc != fSweepUp)
                            {
                                num9  = -num17 * num3;
                                num10 = num17 * num2;
                            }
                            else
                            {
                                num9  = num17 * num3;
                                num10 = -num17 * num2;
                            }
                        }

                        var ptStart = new Point(-num2 - num9, -num3 - num10);
                        var ptEnd   = new Point(num2 - num9, num3 - num10);
                        var matrix  = new Matrix(num5 * xRadius, -num6 * xRadius, num6 * yRadius,
                                                 num5 * yRadius, 0.5 * (xEnd + xStart), 0.5 * (yEnd + yStart));
                        if (!flag)
                        {
                            matrix.OffsetX += matrix.M11 * num9 + matrix.M21 * num10;
                            matrix.OffsetY += matrix.M12 * num9 + matrix.M22 * num10;
                        }

                        GetArcAngle(ptStart, ptEnd, fLargeArc, fSweepUp, out num7, out num8, out cPieces);
                        var bezierDistance = GetBezierDistance(num7);
                        if (!fSweepUp)
                        {
                            bezierDistance = -bezierDistance;
                        }
                        var rhs   = new Point(-bezierDistance * ptStart.Y, bezierDistance * ptStart.X);
                        var index = 0;
                        pPt = new Point[cPieces * 3];
                        for (var i = 1; i < cPieces; i++)
                        {
                            var lhs = new Point(ptStart.X * num7 - ptStart.Y * num8,
                                                ptStart.X * num8 + ptStart.Y * num7);
                            point4       = new Point(-bezierDistance * lhs.Y, bezierDistance * lhs.X);
                            pPt[index++] = matrix.Transform(ptStart.Plus(rhs));
                            pPt[index++] = matrix.Transform(lhs.Minus(point4));
                            pPt[index++] = matrix.Transform(lhs);
                            ptStart      = lhs;
                            rhs          = point4;
                        }

                        point4       = new Point(-bezierDistance * ptEnd.Y, bezierDistance * ptEnd.X);
                        pPt[index++] = matrix.Transform(ptStart.Plus(rhs));
                        pPt[index++] = matrix.Transform(ptEnd.Minus(point4));
                        pPt[index]   = new Point(xEnd, yEnd);
                    }
                }
            }
Ejemplo n.º 15
0
        private void LButtonUp(Point pt)
        {
            // Add by scott 11-06-2009
            if (Drawing.HasGridLines && Webb.Playbook.Data.GameSetting.Instance.SnapToGrid)
            {
                Point ptCoordinates = ToLogical(pt);

                if (moving != null && moving.All(f => f is LabelBase))
                {
                }
                else if (moving != null && moving.Count > 0 && (moving.Count == 1 && moving[0] is Game.PBPlayer || moving[0] is Game.PBBall || moving.Count > 1))
                {
                    IMovable mv = moving[0];

                    double x = mv.Coordinates.X % SnapUnit;
                    double y = mv.Coordinates.Y % SnapUnit;
                    if (Math.Abs(x) > SnapUnit / 2)
                    {
                        if (x >= 0)
                        {
                            ptCoordinates.X = ((int)(mv.Coordinates.X / SnapUnit) + 1) * SnapUnit;
                        }
                        else
                        {
                            ptCoordinates.X = ((int)(mv.Coordinates.X / SnapUnit) - 1) * SnapUnit;
                        }
                    }
                    else
                    {
                        ptCoordinates.X = (int)(mv.Coordinates.X / SnapUnit) * SnapUnit;
                    }
                    if (Math.Abs(y) > SnapUnit / 2)
                    {
                        if (y >= 0)
                        {
                            ptCoordinates.Y = ((int)(mv.Coordinates.Y / SnapUnit) + 1) * SnapUnit;
                        }
                        else
                        {
                            ptCoordinates.Y = ((int)(mv.Coordinates.Y / SnapUnit) - 1) * SnapUnit;
                        }
                    }
                    else
                    {
                        ptCoordinates.Y = (int)(mv.Coordinates.Y / SnapUnit) * SnapUnit;
                    }
                    //ptCoordinates.X = Math.Round(player.Coordinates.X, 0);
                    //ptCoordinates.Y = Math.Round(player.Coordinates.Y, 0);

                    var offset = ptCoordinates.Minus(mv.Coordinates);

                    MoveAction action = new MoveAction(Drawing, moving, offset, toRecalculate);
                    Drawing.ActionManager.RecordAction(action);
                }
            }

            if (moving != null && moving.IsEmpty())
            {//01-04-2010 scott
                Drawing.Canvas.Cursor = null;
            }

            moving = null;

            Drawing.Figures.UpdateVisual();
        }
        public void ProcessSelRectToEnd(Rectangle selRect, UMat magT, UMat phT)
        {
            ///Takes the selected rectangle portion, crops it and pastes it onto a zero image with its maximum value at the bottom-right centre,
            ///calls the next function.
            ///Previous name was ProcessSelRectToPasteRect

            UMat magSelT = new UMat(magT, selRect);
            UMat phSelT  = new UMat(phT, selRect);

            //gets the values and locations of maximum and minimum points for each channel, but we only have 1 channel
            //so we only use the [0] index.
            magSelT.MinMax(out double[] minMagValues, out selRectMaxMagValues,
                           out Point[] minMagLocations, out selRectMaxMagLocations);


            //create empty UMats to "paste" the first-order spectrum into
            if (magFoT != null)
            {
                magFoT.Dispose();
            }
            magFoT = new UMat(magT.Size, DepthType.Cv32F, 1);             //magnitude of First-Order only frequency spectrum image
            magFoT.SetTo(new MCvScalar(0));
            if (phFoT != null)
            {
                phFoT.Dispose();
            }
            phFoT = magFoT.Clone();
            //find 0Hz point in image.
            //0Hz point is at the bottom-right of the centre, because the width and height are even numbers as I
            //cropped them earlier in SwitchQuadrants(). There's no +1 because coordinates start at index 0.
            Point foT0HzPoint = new Point(magFoT.Cols / 2, magFoT.Rows / 2);

            //find centered ROI on first-order-only, where the maximum value is placed at the 0Hz point on FoT
            this.ctrRect = new Rectangle(foT0HzPoint.Minus(selRectMaxMagLocations[0]), selRect.Size);

            LimitRectToWithinImage(magFoT, ref ctrRect);

            UMat magCtrFoT = new UMat(magFoT, ctrRect);
            UMat phCtrFoT  = new UMat(phFoT, ctrRect);

            magSelT.CopyTo(magCtrFoT);
            phSelT.CopyTo(phCtrFoT);
            //dispose the UMat headers. I don't think they will free the memory unless it's the last UMat accessing the memory.
            magSelT.Dispose();
            phSelT.Dispose();
            magCtrFoT.Dispose();
            phCtrFoT.Dispose();

            /*
             * //debugging: create a clone for displaying, process for displaying and display.
             * //I made it complicated because normalisation and log should be done only in the ctredROI,
             * //as any other area is just a 0.
             * //I believe that speeds up the processing for display.
             * UMat MagFoTCpy = magFoT.Clone();
             * UMat magCtrFoTCpy = new UMat(MagFoTCpy, ctrRect);
             * Norm4Disp(magCtrFoTCpy, log: true, norm: false);
             * CvInvoke.Normalize(magCtrFoTCpy, magCtrFoTCpy, 0, 255, NormType.MinMax);
             * MagFoTCpy.ConvertTo(MagFoTCpy, DepthType.Cv8U);
             * imageBox3.Image = MagFoTCpy;
             */

            //continue the chain
            ProcessAddPhaseToEnd(
                this.rDist,
                this.sensorPixelWidth,
                this.sensorPixelHeight,
                this.wavelength,
                this.magFoT,
                this.phFoT,
                this.ctrRect,
                this.selRectMaxMagLocations[0]);
        }
Ejemplo n.º 17
0
        public override void MouseDown(object sender, MouseButtonEventArgs e)
        {
#if !SILVERLIGHT
            if (e.ClickCount == 2)
            {
                Drawing.CoordinateSystem.ZoomExtend();
                return;
            }
#endif
            offsetFromFigureLeftTopCorner = Coordinates(e, false, false, false);
            oldCoordinates         = offsetFromFigureLeftTopCorner;
            coordinatesOnMouseDown = offsetFromFigureLeftTopCorner;
            startedMoving          = false;

            moving = new List <IMovable>();
            IEnumerable <IFigure> roots = null;
            var isLocked = false;

            found = Drawing.Figures.HitTest(offsetFromFigureLeftTopCorner);

            var oneMovable = found as IMovable;
            if (oneMovable != null)
            {
                if (!found.Locked)
                {
                    if (oneMovable is IPoint)
                    {
                        // when we drag a point, we want it to snap to the cursor
                        // so that the point center is directly under the tip of the mouse
                        offsetFromFigureLeftTopCorner = new Point();
                        oldCoordinates = oneMovable.Coordinates;
                    }
                    else
                    {
                        // however when we drag other stuff (such as text labels)
                        // we want the mouse to always touch the part of the draggable
                        // where it first touched during MouseDown
                        // we don't want the draggable to "snap" to the cursor like points do
                        offsetFromFigureLeftTopCorner = offsetFromFigureLeftTopCorner.Minus(oneMovable.Coordinates);
                    }
                    roots = DependencyAlgorithms.FindRoots(f => f.Dependents, found);
                    if (roots.All(root => (!root.Locked)))
                    {
                        moving.Add(oneMovable);
                        roots = found.AsEnumerable();
                    }
                    else
                    {
                        isLocked = true;
                    }
                }
                else
                {
                    isLocked = true;
                }
            }
            else if (found != null && !found.Locked)
            {
                if (!found.Locked)
                {
                    roots = DependencyAlgorithms.FindRoots(f => f.Dependencies, found);
                    if (roots.All(root => root is IMovable))
                    {
                        if (roots.All(root => ((IMovable)root).AllowMove()))
                        {
                            moving.AddRange(roots.OfType <IMovable>());
                        }
                        else
                        {
                            isLocked = true;
                        }
                    }
                }
                else
                {
                    isLocked = true;
                }
            }

            if (roots != null)
            {
                toRecalculate = DependencyAlgorithms.FindDescendants(f => f.Dependents, roots);
                toRecalculate.Reverse();
            }
            else
            {
                toRecalculate = null;
            }

            if (moving.IsEmpty() && !isLocked && !Drawing.CoordinateGrid.Locked)
            {
                moving.Add(Drawing.CoordinateSystem);
                //var allFigures = Drawing.Figures.GetAllFiguresRecursive();
                //roots = DependencyAlgorithms.FindRoots(f => f.Dependencies, allFigures);
                //moving.AddRange(roots.OfType<IMovable>());
                //roots = null;
                toRecalculate = null; // Figures;
            }
        }