示例#1
0
        private Grid CreatePrimitivePoint(PrimitivePoint point, CadColor?color)
        {
            const double size = 0.5;
            var          loc  = PlaneProjection.Transform(point.Location);
            var          path = new Path()
            {
                Data = new GeometryGroup()
                {
                    Children = new GeometryCollection()
                    {
                        new PathGeometry()
                        {
                            Figures = new PathFigureCollection()
                            {
                                new PathFigure()
                                {
                                    StartPoint = new DisplayPoint(-size, 0.0),
                                    Segments   = new PathSegmentCollection()
                                    {
                                        new LineSegment()
                                        {
                                            Point = new DisplayPoint(size, 0.0)
                                        }
                                    }
                                },
                                new PathFigure()
                                {
                                    StartPoint = new DisplayPoint(0.0, -size),
                                    Segments   = new PathSegmentCollection()
                                    {
                                        new LineSegment()
                                        {
                                            Point = new DisplayPoint(0.0, size)
                                        }
                                    }
                                },
                            }
                        }
                    }
                },
                StrokeThickness = 1.0 / PointSize
            };

            SetBinding(path, "Scale", Path.RenderTransformProperty);
            SetColor(path, color);

            var grid = new Grid();

            grid.Children.Add(path);
            grid.RenderTransform = new TranslateTransform()
            {
                X = loc.X, Y = loc.Y
            };

            return(grid);
        }
示例#2
0
文件: Location.cs 项目: nbright/BCad
 public Location(PrimitivePoint point, object tag = null)
     : base(point.Color, tag)
 {
     _primitive  = point;
     _primitives = new[] { _primitive };
     _snapPoints = new[]
     {
         new EndPoint(Point)
     };
     BoundingBox = new BoundingBox(Point, Vector.Zero);
 }
示例#3
0
 public static IEnumerable <Point> IntersectionPoints(this PrimitivePoint first, PrimitivePoint second)
 {
     if (first.Location.CloseTo(second.Location))
     {
         return new Point[] { first.Location }
     }
     ;
     else
     {
         return(Enumerable.Empty <Point>());
     }
 }
示例#4
0
        public static IPrimitive Offset(Plane drawingPlane, IPrimitive primitive, Point offsetDirection, double offsetDistance)
        {
            if (!drawingPlane.Contains(offsetDirection))
            {
                return(null);
            }

            IPrimitive result;

            switch (primitive.Kind)
            {
            case PrimitiveKind.Ellipse:
                var el          = (PrimitiveEllipse)primitive;
                var projection  = el.FromUnitCircle.Inverse();
                var isInside    = projection.Transform((Vector)offsetDirection).LengthSquared <= 1.0;
                var majorLength = el.MajorAxis.Length;
                if (isInside && (offsetDistance > majorLength * el.MinorAxisRatio) ||
                    (offsetDistance >= majorLength))
                {
                    result = null;
                }
                else
                {
                    Vector newMajor;
                    if (isInside)
                    {
                        newMajor = el.MajorAxis.Normalize() * (majorLength - offsetDistance);
                    }
                    else
                    {
                        newMajor = el.MajorAxis.Normalize() * (majorLength + offsetDistance);
                    }
                    result = new PrimitiveEllipse(
                        center: el.Center,
                        majorAxis: newMajor,
                        normal: el.Normal,
                        minorAxisRatio: el.MinorAxisRatio,
                        startAngle: el.StartAngle,
                        endAngle: el.EndAngle,
                        color: el.Color);
                }
                break;

            case PrimitiveKind.Line:
                // find what side the offset occured on and move both end points
                var line = (PrimitiveLine)primitive;
                // normalize to XY plane
                var picked        = drawingPlane.ToXYPlane(offsetDirection);
                var p1            = drawingPlane.ToXYPlane(line.P1);
                var p2            = drawingPlane.ToXYPlane(line.P2);
                var pline         = new PrimitiveLine(p1, p2);
                var perpendicular = new PrimitiveLine(picked, pline.PerpendicularSlope());
                var intersection  = pline.IntersectionPoint(perpendicular, false);
                if (intersection.HasValue && intersection.Value != picked)
                {
                    var offsetVector = (picked - intersection.Value).Normalize() * offsetDistance;
                    offsetVector = drawingPlane.FromXYPlane(offsetVector);
                    result       = new PrimitiveLine(
                        p1: line.P1 + offsetVector,
                        p2: line.P2 + offsetVector,
                        color: line.Color);
                }
                else
                {
                    // the selected point was directly on the line
                    result = null;
                }
                break;

            case PrimitiveKind.Point:
                var point             = (PrimitivePoint)primitive;
                var pointOffsetVector = (offsetDirection - point.Location).Normalize() * offsetDistance;
                result = new PrimitivePoint(point.Location + pointOffsetVector, point.Color);
                break;

            case PrimitiveKind.Text:
                result = null;
                break;

            default:
                throw new ArgumentException("primitive.Kind");
            }

            return(result);
        }
 public PointEditViewModel(PrimitivePoint point)
 {
     this.basePoint    = point;
     this.currentPoint = (PrimitivePoint)point.Clone();
 }
示例#6
0
        public static IEnumerable <Point> IntersectionPoints(this PrimitiveEllipse ellipse, PrimitivePoint point, bool withinBounds = true)
        {
            var fromUnit    = ellipse.FromUnitCircle;
            var toUnit      = fromUnit.Inverse();
            var pointOnUnit = (Vector)toUnit.Transform(point.Location);

            if (MathHelper.CloseTo(pointOnUnit.LengthSquared, 1.0))
            {
                if (!withinBounds)
                {
                    return new Point[] { point.Location }
                }
                ;                                          // always a match
                else
                {
                    var pointAngle = pointOnUnit.ToAngle();

                    if (ellipse.IsAngleContained(pointAngle))
                    {
                        return new Point[] { point.Location }
                    }
                    ;
                    else
                    {
                        return(new Point[0]);
                    }
                }
            }
            else
            {
                // wrong distance
                return(new Point[0]);
            }
        }