Exemplo n.º 1
0
        public void Init(System.Drawing.Point SourcePoint, Projection projection, SnapModes SnapMode, int MaxDist)
#endif
        {
            this.BestDist       = double.MaxValue;
            this.BestObject     = null;
            this.SnapPointIndex = 0;
            SourceBeam          = projection.PointBeam(SourcePoint);
            this.SourcePoint    = projection.ProjectionPlane.Intersect(SourceBeam);
            this.Projection     = projection;
            this.SnapPoint      = projection.DrawingPlanePoint(SourcePoint);
            // MaxDist die die maximale Entfernung des Fangpunktes vom aktuellen Punkt bezogen auf die ProjectionPlane
#if WEBASSEMBLY
            GeoPoint2D p1 = projection.ProjectionPlane.Intersect(projection.PointBeam(new CADability.WebDrawing.Point(SourcePoint.X, SourcePoint.Y + MaxDist)));
            GeoPoint2D p2 = projection.ProjectionPlane.Intersect(projection.PointBeam(new CADability.WebDrawing.Point(SourcePoint.X + MaxDist, SourcePoint.Y)));
            GeoPoint2D p3 = projection.ProjectionPlane.Intersect(projection.PointBeam(new CADability.WebDrawing.Point(SourcePoint.X, SourcePoint.Y - MaxDist)));
            GeoPoint2D p4 = projection.ProjectionPlane.Intersect(projection.PointBeam(new CADability.WebDrawing.Point(SourcePoint.X - MaxDist, SourcePoint.Y)));
#else
            GeoPoint2D p1 = projection.ProjectionPlane.Intersect(projection.PointBeam(new System.Drawing.Point(SourcePoint.X, SourcePoint.Y + MaxDist)));
            GeoPoint2D p2 = projection.ProjectionPlane.Intersect(projection.PointBeam(new System.Drawing.Point(SourcePoint.X + MaxDist, SourcePoint.Y)));
            GeoPoint2D p3 = projection.ProjectionPlane.Intersect(projection.PointBeam(new System.Drawing.Point(SourcePoint.X, SourcePoint.Y - MaxDist)));
            GeoPoint2D p4 = projection.ProjectionPlane.Intersect(projection.PointBeam(new System.Drawing.Point(SourcePoint.X - MaxDist, SourcePoint.Y)));
#endif
            this.MaxDist        = Math.Max(Math.Max(p1 | this.SourcePoint, p2 | this.SourcePoint), Math.Max(p3 | this.SourcePoint, p4 | this.SourcePoint));
            pickArea            = projection.GetPickSpace(new Rectangle(SourcePoint.X - MaxDist, SourcePoint.Y - MaxDist, 2 * MaxDist, 2 * MaxDist));
            this.BasePointValid = false;
            this.SnapMode       = SnapMode;
            this.DidSnap        = DidSnapModes.DidNotSnap;
            faceDist            = double.MaxValue;
        }
Exemplo n.º 2
0
        public override bool Tidy(SnapModes mode, Page page)
        {
            bool changed   = false;
            int  direction = base.TurnDirection();

            if (mode == SnapModes.Shape)
            {
                // Not used the standard TidyVertices because this would only adjust the first two points.  This is also a problem with some triangles and rectangle/squares
                // but it is not so noticeable is the point which are ignored are usually outnumbered by the active points
                // Instead we will use the full shape snapping functionality in the Move transformation
                TransformMove transform = new TransformMove(0, 0);
                if (transform.Snap(this.GetPointsWhichSnapWhenMoving(), 1, page, this, Centre, Centre))
                {
                    base.ApplyTransformation(transform);
                    changed = true;
                }
            }
            else
            {
                changed = base.TidyVertices(mode, page, 1);
                if (changed)
                {
                    PlacePoints(direction);
                }
            }
            return(changed);
        }
Exemplo n.º 3
0
        public void Init(System.Drawing.Point SourcePoint, Projection projection, SnapModes SnapMode, int MaxDist, GeoPoint BasePoint)
#endif
        {
            Init(SourcePoint, projection, SnapMode, MaxDist);
            this.BasePoint      = BasePoint;
            this.BasePointValid = true;
        }
Exemplo n.º 4
0
        public override bool Tidy(SnapModes mode, Page page)
        {
            // By default this isn't enabled - is only usable if the overriding class adds Tidy to the Allows return value
            switch (mode)
            {
            case SnapModes.Grid:
                switch (page.Paper.PaperType)
                {
                case Paper.Papers.Plain:
                    return(false);                                    // cannot tidy up to an isometric grid
                }
                break;

            case SnapModes.Shape:                     // will be attempted below
                break;

            default:
                return(false);                        // mainly intended for angle; where the shape is by definition aligned on the grid
            }
            List <PointF> points = new List <PointF>();

            points.AddRange(m_Bounds.GetPoints());
            Lined.TidyVertices(points, this, mode, page, 3);
            // but that might not have created an orthogonal rectangle.  So calculate the complete rectangle bounding these.  For tidying to grid
            // that should just return the same points again
            m_Bounds = RectangleF.Empty;
            Geometry.Extend(ref m_Bounds, points);
            return(true);
        }
Exemplo n.º 5
0
        public override bool Tidy(SnapModes mode, Page page)
        {
            PointF newPoint = m_Centre;

            switch (mode)
            {
            case SnapModes.Grid:
                newPoint = page.Paper.SnapPoint2(newPoint);
                break;

            case SnapModes.Shape:
                newPoint = Lined.TidyPointToShapes(newPoint, page, this);
                break;

            case SnapModes.Angle:
                SizeF newVector = Geometry.AngleSnapVector(m_Exit);
                if (newVector.Equals(m_Exit))
                {
                    return(false);
                }
                m_Exit = newVector;
                return(true);

            default:
                Debug.Fail("Bad Tidy mode");
                break;
            }
            if (newPoint == m_Centre)
            {
                return(false);
            }
            m_Centre = newPoint;
            return(true);
        }
Exemplo n.º 6
0
 public override SnapModes SnapNext(SnapModes requested)
 {
     if (requested == SnapModes.Angle)
     {
         requested = SnapModes.Off;
     }
     return(requested);
 }
Exemplo n.º 7
0
 public override SnapModes SnapNext(SnapModes requested)
 {
     if (requested != SnapModes.Shape)
     {
         return(SnapModes.Off);
     }
     return(SnapModes.Shape);            // can snap the end point to a shape
 }
Exemplo n.º 8
0
 public override bool Tidy(SnapModes mode, Page page)
 {
     if (mode == SnapModes.Shape || mode == SnapModes.Angle)
     {
         return(false);
     }
     return(base.Tidy(mode, page));
 }
Exemplo n.º 9
0
 public override SnapModes SnapNext(SnapModes requested)
 {
     if (m_DefinedVertices >= 2)
     {
         return(SnapModes.Off);
     }
     // do not want to grid snap this point - we only care which side of the line it is.  If we snap it it will tend to be on the line giving no shape at all
     return(base.SnapNext(requested));
 }
Exemplo n.º 10
0
        public override bool Tidy(SnapModes mode, Page page)
        {
            bool changed = base.TidyVertices(mode, page, 2);

            if (changed)
            {
                Vertices[3] = Vertices[0] + Vertices[1].VectorTo(Vertices[2]);
            }
            DiscardPath();
            return(changed);
        }
Exemplo n.º 11
0
        public override bool Tidy(SnapModes mode, Page page)
        {
            int  direction = base.TurnDirection();
            bool changed   = base.TidyVertices(mode, page, 1);

            if (changed)
            {
                PlaceThird(direction);
            }
            return(changed);
        }
Exemplo n.º 12
0
 public override SnapModes SnapNext(SnapModes requested)
 {
     if (!m_PositionFixed)
     {
         return(SnapModes.Off);
     }
     if (requested == SnapModes.Angle)
     {
         return(SnapModes.Off);    // doesn't make much sense placing bottom right to adjust angle
     }
     return(requested);            // do not try and snap the size of the image
 }
Exemplo n.º 13
0
        public override SnapModes SnapNext(SnapModes requested)
        {
            switch (requested)
            {
            case SnapModes.Grid:
            case SnapModes.Shape:
                return(requested);

            default:
                return(SnapModes.Off);                        // Angle snap doesn't make much sense here
            }
        }
Exemplo n.º 14
0
        public override bool Tidy(SnapModes mode, Page page)
        {
            int  direction = base.TurnDirection();
            bool changed   = base.TidyVertices(mode, page, 1);

            if (changed)
            {
                PlaceSquare(direction);
            }
            DiscardPath();
            return(changed);
        }
Exemplo n.º 15
0
 public override SnapModes SnapNext(SnapModes requested)
 {
     if (m_DefinedVertices >= 2)
     {
         // because the direction of the second line is fixed, it only makes sense to snap this to a grid point
         // if the first line was lined up with the grid.  Otherwise the second line is going diagonally and will probably never hit any grid points
         if (!Geometry.LineApproxPerpendicular(Vertices[0], Vertices[1]))
         {
             return(SnapModes.Off);
         }
     }
     return(base.SnapNext(requested));
 }
Exemplo n.º 16
0
        public override bool Tidy(SnapModes mode, Page page)
        {
            List <PointF> vertices = new List <PointF>(Vertices);           // function below needs a list not an array
            bool          changed  = Lined.TidyVertices(vertices, this, mode, page, 1);

            if (changed)
            {
                Vertices = vertices.ToArray();
                m_Bounds = RectangleF.Empty;
                ClearTextCache();
            }
            return(changed);
        }
Exemplo n.º 17
0
 public override SnapModes SnapNext(SnapModes requested)
 {
     if (m_DefinedVertices >= 2)
     {
         // because the direction of the second line is fixed, it only makes sense to snap this to a grid point
         // if the first line was lined up with the grid.  Otherwise the second line is going diagonally and will probably never hit any grid points
         // we do allow shape snapping, because snapping to a target point will create a rectangle which passes through that target
         if (requested == SnapModes.Shape || Geometry.LineApproxPerpendicular(Vertices[0], Vertices[1]))
         {
             return(requested);
         }
         return(SnapModes.Off);
     }
     return(base.SnapNext(requested));
 }
Exemplo n.º 18
0
        public override bool Tidy(SnapModes mode, Page page)
        {
            List <PointF> col        = new List <PointF>(Vertices);
            float         transverse = Geometry.DistanceBetween(Vertices[1], Vertices[2]);     // the transverse distance

            if (!Lined.TidyVertices(col, this, mode, page, 3))
            {
                return(false);
            }
            // make sure it is rectangular again!...
            // the base class tidies the points independently and could end up with a parallelogram, this ensures that it remains a rectangle.  Copied from rectangle, but removing part of it which snapped the transverse size (not so applicable here we probably want to maintain the ratio for images?)
            Vertices = col.ToArray();
            int direction = Geometry.TurnDirection(Vertices[0], Vertices[1], Vertices[2]);

            Vertices[2] = Vertices[1] + Vertices[0].VectorTo(Vertices[1]).Perpendicular(direction).ChangeLength(transverse);
            Vertices[3] = Vertices[0] + Vertices[1].VectorTo(Vertices[2]);
            m_Bounds    = CalculateBounds();
            return(true);
            // This doesn't perform very well when aligning with other shapes; the initial function will tidy the individual points, but usually one will become misaligned again
            // when correcting the rectangle.  It would be better to do a proper moving snap, but I'm not sure if it's really worth the effort
        }
Exemplo n.º 19
0
        public override bool Tidy(SnapModes mode, Page page)
        {
            int  direction = base.TurnDirection();
            bool changed   = base.TidyVertices(mode, page, 2);

            if (changed)
            {
                // just need to check that the vertices do not form a single line
                if (Geometry.PointApproxOnLine(Vertices[0], Vertices[1], Vertices[2]))
                {
                    // move the point again to get it off the line
                    if (direction == 0)
                    {
                        direction = 1;                         // just in case it was already a single line
                    }
                    SizeF vector = Vertices[0].VectorTo(Vertices[1]).Perpendicular(direction);
                    Vertices[2] = Vertices[2] + vector.ChangeLength(page.Paper.UnitStep);                     // UnitStep always returns a valid value
                }
            }
            return(changed);
        }
Exemplo n.º 20
0
        public override bool Tidy(SnapModes mode, Page page)
        {
            int   direction      = base.TurnDirection();
            float transverseSize = Geometry.DistanceBetween(Geometry.MidPoint(Vertices[0], Vertices[1]), Vertices[2]);
            bool  changed        = base.TidyVertices(mode, page, 1);

            if (mode == SnapModes.Grid)
            {
                float newSize = page.Paper.SnapScalar(transverseSize);
                if (transverseSize > Geometry.NEGLIGIBLE && transverseSize != newSize)
                {
                    transverseSize = newSize;
                    changed        = true;
                }
            }
            if (changed)
            {
                SizeF baseVector = BaseVector().MultiplyBy(0.5f);                 // actually half the base vector
                Vertices[2] = Vertices[0] + baseVector + baseVector.Perpendicular(direction).ChangeLength(transverseSize);
            }
            return(changed);
        }
Exemplo n.º 21
0
        public override bool Tidy(SnapModes mode, Page page)
        {
            // the base class tidies the points independently and could end up with a parallelogram, this ensures that it remains a rectangle
            float transverse = Geometry.DistanceBetween(Vertices[1], Vertices[2]);             // the transverse distance
            bool  changed    = base.Tidy(mode, page);

            if (mode == SnapModes.Grid)
            {
                float newValue = page.Paper.SnapScalar(transverse, 0);
                if (newValue > Geometry.NEGLIGIBLE && newValue != transverse)
                {
                    changed    = true;
                    transverse = newValue;
                }
            }
            if (changed)
            {
                int direction = Geometry.TurnDirection(Vertices[0], Vertices[1], Vertices[2]);
                Vertices[2] = Vertices[1] + Vertices[0].VectorTo(Vertices[1]).Perpendicular(direction).ChangeLength(transverse);
                Vertices[3] = Vertices[0] + Vertices[1].VectorTo(Vertices[2]);
            }
            DiscardPath();
            return(changed);
        }
Exemplo n.º 22
0
 public override SnapModes SnapNext(SnapModes requested) => requested == SnapModes.Angle ? SnapModes.Off : base.SnapNext(requested);
Exemplo n.º 23
0
 protected override bool TidyVertices(SnapModes modes, Page page, int last)
 {
     DiscardPath();
     return(base.TidyVertices(modes, page, last));
 }
Exemplo n.º 24
0
 public override bool Tidy(SnapModes mode, Page page)
 {
     return(base.TidyVertices(mode, page, 1));
 }
Exemplo n.º 25
0
 public override SnapModes SnapNext(SnapModes requested) => SnapModes.Socket;
Exemplo n.º 26
0
 public void Init(CADability.WebDrawing.Point SourcePoint, Projection projection, SnapModes SnapMode, int MaxDist, GeoPoint BasePoint)