Exemplo n.º 1
0
        public Text(PrimitiveText text, object tag = null)
            : base(text.Color, tag)
        {
            _primitive  = text;
            _primitives = new[] { _primitive };
            _snapPoints = new[] { new EndPoint(Location) };

            var rad   = Rotation * MathHelper.DegreesToRadians;
            var right = new Vector(Math.Cos(rad), Math.Sin(rad), 0.0).Normalize() * Width;
            var up    = Normal.Cross(right).Normalize() * Height;

            BoundingBox = BoundingBox.FromPoints(
                Location,
                Location + right,
                Location + up,
                Location + right + up);
        }
Exemplo n.º 2
0
        private static bool IsPointOnPrimitive(this PrimitiveText text, Point point)
        {
            // check for plane containment
            var plane = new Plane(text.Location, text.Normal);

            if (plane.Contains(point))
            {
                // check for horizontal/vertical containment
                var right      = Vector.RightVectorFromNormal(text.Normal);
                var up         = text.Normal.Cross(right).Normalize();
                var projection = Matrix4.FromUnitCircleProjection(text.Normal, right, up, text.Location, 1.0, 1.0, 1.0).Inverse();

                var projected = projection.Transform(point);
                if (MathHelper.Between(0.0, text.Width, projected.X) &&
                    MathHelper.Between(0.0, text.Height, projected.Y))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 3
0
        private TextBlock CreatePrimitiveText(PrimitiveText text, CadColor?color)
        {
            var location = PlaneProjection.Transform(text.Location);
            var t        = new TextBlock();

            t.Text       = text.Value;
            t.FontFamily = new FontFamily("Consolas");
            t.FontSize   = text.Height * 0.75; // 0.75 = 72ppi/96dpi
            var trans = new TransformGroup();

            trans.Children.Add(new ScaleTransform()
            {
                ScaleX = 1, ScaleY = -1
            });
            trans.Children.Add(new RotateTransform()
            {
                Angle = text.Rotation, CenterX = 0, CenterY = -text.Height
            });
            t.RenderTransform = trans;
            Canvas.SetLeft(t, location.X);
            Canvas.SetTop(t, location.Y + text.Height);
            SetColor(t, TextBlock.ForegroundProperty, color);
            return(t);
        }