Beispiel #1
0
        public int SnapHierarchy(DidSnapModes mode)
        {
            switch (mode)
            {
            case DidSnapModes.DidSnapToIntersectionPoint:
                return(1);

            case DidSnapModes.DidSnapToObjectSnapPoint:
                return(1);

            case DidSnapModes.DidSnapToTangentPoint:
                return(2);

            case DidSnapModes.DidSnapToDropPoint:
                return(2);

            case DidSnapModes.DidSnapToObjectCenter:
                return(3);

            case DidSnapModes.DidSnapToObjectPoint:
                return(4);

            case DidSnapModes.DidSnapToGridPoint:
                return(5);

            case DidSnapModes.DidAdjustOrtho:
                return(6);

            default:
                return(7);
            }
        }
Beispiel #2
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;
        }
Beispiel #3
0
        /// <summary>
        /// The <see cref="IGeoObject"/> obj offers the point p as a snappoint in the given mode.
        /// This method checks whether to use this point as the closest snap point.
        /// This method is typically called by GeoObjects from the <see cref="IGeoObject.FindSnapPoint"/> method.
        /// </summary>
        /// <param name="p"></param>
        /// <param name="obj"></param>
        /// <param name="mode"></param>
        public void Check(GeoPoint p, IGeoObject obj, DidSnapModes mode)
        {
            GeoPoint p2 = Geometry.DropPL(p, SourceBeam.Location, SourceBeam.Direction);
            double   d  = Projection.WorldToProjectionPlane(p) | Projection.WorldToProjectionPlane(p2);
            // d ist der Abstand bezogen auf die projectionplane
            bool DoIt = false;

            if (SnapHierarchy(mode) <= SnapHierarchy(DidSnap))
            {
                if (mode == DidSnapModes.DidSnapToFaceSurface)
                {   // hier zählt die sichtbare Fläche, die das
                    // kleinste faceDist hat. Das wird in Face gecheckt
                    DoIt = true;
                }
                else if (SnapHierarchy(mode) == SnapHierarchy(DidSnap))
                {
                    DoIt = (d < BestDist && d < MaxDist);
                }
                else
                {
                    DoIt = d < MaxDist;
                }
                if (mode == DidSnapModes.DidSnapToDropPoint ||
                    mode == DidSnapModes.DidSnapToObjectCenter ||
                    mode == DidSnapModes.DidSnapToTangentPoint)
                {
                    DoIt = d < BestDist;
                }
                if (mode == DidSnapModes.DidAdjustOrtho || mode == DidSnapModes.DidSnapToGridPoint)
                {
                    DoIt = true;                                                                                 // Orthogonal unabhängig von der Entfernung
                }
            }
            if (DoIt)
            {
                SnapPoint  = p;
                BestDist   = d;
                DidSnap    = mode;
                BestObject = obj;
            }
        }