Ejemplo n.º 1
0
        //--------------------------------------------------------------------------------------------------

        public override bool Render(IDrawingRenderer renderer)
        {
            if (!ComputeParameters(out var p))
            {
                return(false);
            }

            if (renderer.RenderElement(this))
            {
                return(true);
            }

            // Render each element separately
            renderer.SetStyle(new StrokeStyle(Color.Black, 0.1f, LineStyle.Solid), null, null);
            renderer.BeginGroup("Dimension");

            if (_Debug_DrawPoints)
            {
                DrawingRenderHelper.RenderCross(renderer, _FirstPoint);
                DrawingRenderHelper.RenderCross(renderer, _SecondPoint);
                DrawingRenderHelper.RenderCross(renderer, Position);
            }

            // Extension lines
            renderer.Line(_FirstPoint, _FirstPoint.Translated(p.ExtensionVector));
            renderer.Line(_SecondPoint, _SecondPoint.Translated(p.ExtensionVector));

            // Dimension line
            var arrowSize = DrawingRenderHelper.GetArrowSize();

            renderer.Line(_FirstPoint.Translated(p.DimensionOffset)
                          .Translated(p.DimensionDirection.ToVec(arrowSize.Length * p.Scale)),
                          _SecondPoint.Translated(p.DimensionOffset)
                          .Translated(p.DimensionDirection.Reversed().ToVec(arrowSize.Length * p.Scale)));
            DrawingRenderHelper.RenderArrow(renderer, new Ax2d(_FirstPoint.Translated(p.DimensionOffset), p.DimensionDirection.Reversed()), p.Scale);
            DrawingRenderHelper.RenderArrow(renderer, new Ax2d(_SecondPoint.Translated(p.DimensionOffset), p.DimensionDirection), p.Scale);

            // Dimension text
            if (!Text.IsNullOrWhiteSpace())
            {
                var fontStyle = DrawingRenderHelper.GetDefaultFontStyle();
                renderer.SetStyle(null, new FillStyle(Color.Black),
                                  new FontStyle(fontStyle.Family, (float)(fontStyle.Size * p.TextScale)));
                renderer.Text(Text, p.TextOrigin, p.DimensionRotation);
                if (_IsNotToScale)
                {
                    var start = p.TextOrigin.Translated(p.ExtensionVector.Normalized().Scaled(-0.5));
                    renderer.Line(start, start.Translated(p.DimensionDirection.ToVec(p.TextWidth)));
                }
            }

            renderer.EndGroup();

            return(true);
        }
Ejemplo n.º 2
0
        //--------------------------------------------------------------------------------------------------

        public override bool Render(IDrawingRenderer renderer)
        {
            if (!ComputeParameters(out var p))
            {
                return(false);
            }

            if (renderer.RenderElement(this))
            {
                return(true);
            }

            // Render each element separately
            renderer.SetStyle(new StrokeStyle(Color.Black, 0.1f, LineStyle.Solid), null, null);
            renderer.BeginGroup("Dimension");

            if (_Debug_DrawPoints)
            {
                DrawingRenderHelper.RenderCross(renderer, _FirstPoint);
                DrawingRenderHelper.RenderCross(renderer, _SecondPoint);
                DrawingRenderHelper.RenderCross(renderer, _CenterPoint);
                DrawingRenderHelper.RenderCross(renderer, Position);
            }

            // Extension lines
            renderer.Line(_FirstPoint, _FirstPoint.Translated(p.FirstExtensionVector));
            renderer.Line(_SecondPoint, _SecondPoint.Translated(p.SecondExtensionVector));

            // Dimension line
            BrepRenderHelper.RenderCircle(renderer, new Geom2d_Circle(new Ax2d(_CenterPoint, Dir2d.DX), p.Radius), p.StartAngle, p.EndAngle, false);
            DrawingRenderHelper.RenderArrow(renderer, new Ax2d(p.FirstArrowPoint, p.FirstArrowTangent), p.Scale);
            DrawingRenderHelper.RenderArrow(renderer, new Ax2d(p.SecondArrowPoint, p.SecondArrowTangent), p.Scale);

            // Dimension text
            if (!Text.IsNullOrWhiteSpace())
            {
                var fontStyle = DrawingRenderHelper.GetDefaultFontStyle();
                renderer.SetStyle(null, new FillStyle(Color.Black),
                                  new FontStyle(fontStyle.Family, (float)(fontStyle.Size * p.TextScale)));
                renderer.Text(Text, p.TextOrigin, p.TextRotation);
                if (_IsNotToScale)
                {
                    var start = p.TextOrigin.Translated(Dir2d.DX.Rotated(-p.TextRotation + Maths.HalfPI).ToVec(-0.5));
                    renderer.Line(start, start.Translated(Dir2d.DX.Rotated(-p.TextRotation).ToVec(p.TextWidth)));
                }
            }

            renderer.EndGroup();

            return(true);
        }