Beispiel #1
0
        private void AddPrimitiveToDrawing(ClientDrawing clientDrawing, IPrimitive primitive, CadColor?fallBackColor)
        {
            var primitiveColor = primitive.Color ?? fallBackColor;

            primitive.DoPrimitive(
                ellipse =>
            {
                var startAngle = ellipse.StartAngle.CorrectAngleDegrees();
                var endAngle   = ellipse.EndAngle.CorrectAngleDegrees();
                if (endAngle <= startAngle)
                {
                    endAngle += 360.0;
                }
                var transform = Matrix4.CreateScale(1.0, 1.0, 0.0) * ellipse.FromUnitCircle;     // flatten display in z-plane
                clientDrawing.Ellipses.Add(new ClientEllipse(startAngle, endAngle, transform.ToTransposeArray(), primitiveColor));
            },
                line => clientDrawing.Lines.Add(new ClientLine(line.P1, line.P2, primitiveColor)),
                point => clientDrawing.Points.Add(new ClientPointLocation(point.Location, primitiveColor)),
                text => clientDrawing.Text.Add(new ClientText(text.Value, text.Location, text.Height, text.Rotation, primitiveColor)),
                bezier =>
            {
                var lineSegments = 10;
                var last         = bezier.P1;
                for (int i = 1; i <= lineSegments; i++)
                {
                    var t    = (double)i / lineSegments;
                    var next = bezier.ComputeParameterizedPoint(t);
                    clientDrawing.Lines.Add(new ClientLine(last, next, primitiveColor));
                    last = next;
                }
            },
                image => clientDrawing.Images.Add(new ClientImage(image.Location, Convert.ToBase64String(image.ImageData), image.Path, image.Width, image.Height, image.Rotation, image.Color))
                );
        }