Exemplo n.º 1
0
        public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo)
        {
            if (renderInfo.CurrentRenderType.HasFlag(RenderType.Extrusions))
            {
                double extrusionLineWidths = GetExtrusionWidth(renderInfo.CurrentRenderType) * 2 * renderInfo.LayerScale;

                Color extrusionColor = Color.Black;

                if (renderInfo.CurrentRenderType.HasFlag(RenderType.SpeedColors))
                {
                    extrusionColor = color;
                }
                else if (renderInfo.CurrentRenderType.HasFlag(RenderType.GrayColors))
                {
                    extrusionColor = Color.Gray;
                }
                else
                {
                    extrusionColor = renderInfo.GetMaterialColor(extruderIndex);
                }

                if (renderInfo.CurrentRenderType.HasFlag(RenderType.TransparentExtrusion))
                {
                    extrusionColor = new Color(extrusionColor, 200);
                }

                // render the part using opengl
                Graphics2DOpenGL graphics2DGl = graphics2D as Graphics2DOpenGL;
                if (graphics2DGl != null)
                {
                    Vector3Float startF = this.GetStart(renderInfo);
                    Vector3Float endF   = this.GetEnd(renderInfo);
                    Vector2      start  = new Vector2(startF.x, startF.y);
                    renderInfo.Transform.transform(ref start);

                    Vector2 end = new Vector2(endF.x, endF.y);
                    renderInfo.Transform.transform(ref end);

                    graphics2DGl.DrawAALineRounded(start, end, extrusionLineWidths / 2, extrusionColor);
                }
                else
                {
                    VertexStorage pathStorage = new VertexStorage();
                    VertexSourceApplyTransform transformedPathStorage = new VertexSourceApplyTransform(pathStorage, renderInfo.Transform);
                    Stroke stroke = new Stroke(transformedPathStorage, extrusionLineWidths / 2);

                    stroke.line_cap(LineCap.Round);
                    stroke.line_join(LineJoin.Round);

                    Vector3Float start = this.GetStart(renderInfo);
                    Vector3Float end   = this.GetEnd(renderInfo);

                    pathStorage.Add(start.x, start.y, ShapePath.FlagsAndCommand.MoveTo);
                    pathStorage.Add(end.x, end.y, ShapePath.FlagsAndCommand.LineTo);

                    graphics2D.Render(stroke, 0, extrusionColor);
                }
            }
        }
        public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo)
        {
            if ((renderInfo.CurrentRenderType & RenderType.Moves) == RenderType.Moves)
            {
                double movementLineWidth = 0.35 * renderInfo.LayerScale;
                Color  movementColor     = new Color(10, 190, 15);

                // render the part using opengl
                Graphics2DOpenGL graphics2DGl = graphics2D as Graphics2DOpenGL;
                if (graphics2DGl != null)
                {
                    Vector3Float startF = this.GetStart(renderInfo);
                    Vector3Float endF   = this.GetEnd(renderInfo);
                    Vector2      start  = new Vector2(startF.x, startF.y);
                    renderInfo.Transform.transform(ref start);

                    Vector2 end = new Vector2(endF.x, endF.y);
                    renderInfo.Transform.transform(ref end);

                    if (renderInfo.CurrentRenderType.HasFlag(RenderType.TransparentExtrusion))
                    {
                        movementColor = new Color(movementColor, 200);
                    }

                    graphics2DGl.DrawAALineRounded(start, end, movementLineWidth, movementColor);
                }
                else
                {
                    VertexStorage pathStorage = new VertexStorage();
                    VertexSourceApplyTransform transformedPathStorage = new VertexSourceApplyTransform(pathStorage, renderInfo.Transform);
                    Stroke stroke = new Stroke(transformedPathStorage, movementLineWidth);

                    stroke.line_cap(LineCap.Round);
                    stroke.line_join(LineJoin.Round);

                    Vector3Float start = this.GetStart(renderInfo);
                    Vector3Float end   = this.GetEnd(renderInfo);

                    pathStorage.Add(start.x, start.y, ShapePath.FlagsAndCommand.MoveTo);
                    if (end.x != start.x || end.y != start.y)
                    {
                        pathStorage.Add(end.x, end.y, ShapePath.FlagsAndCommand.LineTo);
                    }
                    else
                    {
                        pathStorage.Add(end.x + .01, end.y, ShapePath.FlagsAndCommand.LineTo);
                    }

                    graphics2D.Render(stroke, movementColor);
                }
            }
        }