Ejemplo n.º 1
0
        public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo)
        {
            if ((renderInfo.CurrentRenderType & RenderType.Retractions) == RenderType.Retractions)
            {
                double  radius   = Radius(renderInfo.LayerScale);
                Vector2 position = new Vector2(this.position.x, this.position.y);
                renderInfo.Transform.transform(ref position);

                RGBA_Bytes retractionColor = new RGBA_Bytes(RGBA_Bytes.Red, 200);
                if (extrusionAmount > 0)
                {
                    // unretraction
                    retractionColor = new RGBA_Bytes(RGBA_Bytes.Blue, 200);
                }

                // render the part using opengl
                Graphics2DOpenGL graphics2DGl = graphics2D as Graphics2DOpenGL;
                if (graphics2DGl != null)
                {
                    graphics2DGl.DrawAACircle(position, radius, retractionColor);
                }
                else
                {
                    Ellipse extrusion = new Ellipse(position, radius);
                    graphics2D.Render(extrusion, retractionColor);
                }
            }
        }
Ejemplo n.º 2
0
        private void DrawSnappingMarks(DrawGlContentEventArgs drawEventArgs, double mouseAngle, double alphaValue, Matrix4X4 rotationCenterTransform, double distanceFromCenter, int numSnapPoints, int markToSnapTo)
        {
            var graphics2DOpenGL = new Graphics2DOpenGL(GuiWidget.DeviceScale);

            double snappingRadians = MathHelper.Tau / numSnapPoints;

            for (int i = 0; i < numSnapPoints; i++)
            {
                double startAngle = i * snappingRadians + mouseAngle;

                var snapShape = new VertexStorage();
                var scale     = GuiWidget.DeviceScale;
                snapShape.MoveTo(-10 * scale, 0);
                snapShape.LineTo(5 * scale, 7 * scale);
                snapShape.LineTo(5 * scale, -7 * scale);
                snapShape.ClosePolygon();

                var transformed = new VertexSourceApplyTransform(snapShape, Affine.NewTranslation(distanceFromCenter, 0) * Affine.NewRotation(startAngle));
                // new Ellipse(startPosition.x, startPosition.y, dotRadius, dotRadius);

                var color = theme.TextColor;
                if (i == markToSnapTo)
                {
                    color = theme.PrimaryAccentColor;
                }

                graphics2DOpenGL.RenderTransformedPath(rotationCenterTransform, transformed, new Color(color, (int)(254 * alphaValue)), drawEventArgs.ZBuffered);
            }
        }
Ejemplo n.º 3
0
        private void DrawSnappingMarks(DrawGlContentEventArgs drawEventArgs, double mouseAngle, double alphaValue, Matrix4X4 rotationCenterTransform, double distanceFromCenter, double dotRadius, int numSnapPoints, int markToSnapTo)
        {
            var graphics2DOpenGL = new Graphics2DOpenGL();

            double snappingRadians = MathHelper.Tau / numSnapPoints;
            var    clippingFrustum = GLHelper.GetClippingFrustum(InteractionContext.World);

            for (int i = 0; i < numSnapPoints; i++)
            {
                double startAngle = i * snappingRadians + mouseAngle;

                VertexStorage snapShape = new VertexStorage();
                snapShape.MoveTo(-10, 0);
                snapShape.LineTo(5, 7);
                snapShape.LineTo(5, -7);
                snapShape.ClosePolygon();

                var transformed = new VertexSourceApplyTransform(snapShape, Affine.NewTranslation(distanceFromCenter, 0) * Affine.NewRotation(startAngle));
                // new Ellipse(startPosition.x, startPosition.y, dotRadius, dotRadius);

                var color = Color.Black;
                if (i == markToSnapTo)
                {
                    color = Color.Red;
                }

                graphics2DOpenGL.RenderTransformedPath(rotationCenterTransform, transformed, new Color(color, (int)(254 * alphaValue)), drawEventArgs.ZBuffered);
            }
        }
        public static void RenderTransformedPath(Matrix4X4 transform, IVertexSource path, RGBA_Bytes color, bool doDepthTest)
        {
            GL.Disable(EnableCap.Texture2D);

            GL.MatrixMode(MatrixMode.Modelview);
            GL.PushMatrix();
            GL.MultMatrix(transform.GetAsFloatArray());
            //GL.DepthMask(false);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.Disable(EnableCap.Lighting);
            if (doDepthTest)
            {
                GL.Enable(EnableCap.DepthTest);
            }
            else
            {
                GL.Disable(EnableCap.DepthTest);
            }

            Graphics2DOpenGL openGlRender = new Graphics2DOpenGL();

            openGlRender.DrawAAShape(path, color);

            GL.PopMatrix();
        }
Ejemplo n.º 5
0
        private void GlRenderGrid(Graphics2DOpenGL graphics2DGl, Affine transform, double width)
        {
            graphics2DGl.PreRender();
            GL.Begin(BeginMode.Triangles);

            Vector2 gridOffset = gridCenterMm - gridSizeMm / 2;

            if (gridSizeMm.x > 0 && gridSizeMm.y > 0)
            {
                grid.remove_all();
                for (int y = 0; y <= gridSizeMm.y; y += 10)
                {
                    Vector2 start = new Vector2(0, y) + gridOffset;
                    Vector2 end   = new Vector2(gridSizeMm.x, y) + gridOffset;
                    transform.transform(ref start);
                    transform.transform(ref end);

                    graphics2DGl.DrawAALine(start, end, width, gridColor);
                }

                for (int x = 0; x <= gridSizeMm.x; x += 10)
                {
                    Vector2 start = new Vector2(x, 0) + gridOffset;
                    Vector2 end   = new Vector2(x, gridSizeMm.y) + gridOffset;
                    transform.transform(ref start);
                    transform.transform(ref end);

                    graphics2DGl.DrawAALine(start, end, width, gridColor);
                }
            }

            GL.End();
            graphics2DGl.PopOrthoProjection();
        }
Ejemplo n.º 6
0
        public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo)
        {
            if ((renderInfo.CurrentRenderType & RenderType.Retractions) == RenderType.Retractions)
            {
                double  radius   = Radius(renderInfo.LayerScale);
                Vector2 position = new Vector2(this.position.x, this.position.y);

                if (renderInfo.CurrentRenderType.HasFlag(RenderType.HideExtruderOffsets))
                {
                    Vector2 offset = renderInfo.GetExtruderOffset(extruderIndex);
                    position = position + offset;
                }

                renderInfo.Transform.transform(ref position);

                Color retractionColor = new Color(Color.Red, 200);
                if (extrusionAmount > 0)
                {
                    // unretraction
                    retractionColor = new Color(Color.Blue, 200);
                }

                // render the part using opengl
                Graphics2DOpenGL graphics2DGl = graphics2D as Graphics2DOpenGL;
                if (graphics2DGl != null)
                {
                    graphics2DGl.DrawAACircle(position, radius, retractionColor);
                }
                else
                {
                    Ellipse extrusion = new Ellipse(position, radius);
                    graphics2D.Render(extrusion, retractionColor);
                }
            }
        }
Ejemplo n.º 7
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);
                }
            }
        }
Ejemplo n.º 8
0
        public void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo)
        {
            if (renderFeatures.Count > 0)
            {
                CreateFeaturesForLayerIfRequired(renderInfo.EndLayerIndex);

                int featuresOnLayer = renderFeatures[renderInfo.EndLayerIndex].Count;
                int endFeature      = (int)(featuresOnLayer * renderInfo.FeatureToEndOnRatio0To1 + .5);
                endFeature = Math.Max(0, Math.Min(endFeature, featuresOnLayer));

                int startFeature = (int)(featuresOnLayer * renderInfo.FeatureToStartOnRatio0To1 + .5);
                startFeature = Math.Max(0, Math.Min(startFeature, featuresOnLayer));

                // try to make sure we always draw at least one feature
                if (endFeature <= startFeature)
                {
                    endFeature = Math.Min(startFeature + 1, featuresOnLayer);
                }
                if (startFeature >= endFeature)
                {
                    // This can only happen if the start and end are set to the last feature
                    // Try to set the start feature to one from the end
                    startFeature = Math.Max(endFeature - 1, 0);
                }

                Graphics2DOpenGL graphics2DGl = graphics2D as Graphics2DOpenGL;
                if (graphics2DGl != null)
                {
                    graphics2DGl.PreRender(Color.White);
                    GL.Begin(BeginMode.Triangles);

                    int lastFeature = endFeature - 1;
                    for (int i = startFeature; i < endFeature; i++)
                    {
                        RenderFeatureBase feature = renderFeatures[renderInfo.EndLayerIndex][i];
                        if (feature != null)
                        {
                            feature.Render(graphics2DGl, renderInfo, highlightFeature: this.GCodeInspector && i == lastFeature);
                        }
                    }
                    GL.End();
                    graphics2DGl.PopOrthoProjection();
                }
                else
                {
                    for (int i = startFeature; i < endFeature; i++)
                    {
                        RenderFeatureBase feature = renderFeatures[renderInfo.EndLayerIndex][i];
                        if (feature != null)
                        {
                            feature.Render(graphics2D, renderInfo);
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public Graphics2D NewGraphics2D()
        {
            // this is for testing the openGL implementation
            var graphics2D = new Graphics2DOpenGL((int)this.aggSystemWindow.Width,
                                                  (int)this.aggSystemWindow.Height,
                                                  GuiWidget.DeviceScale);

            graphics2D.PushTransform();

            return(graphics2D);
        }
        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);
                }
            }
        }
Ejemplo n.º 11
0
        public override Graphics2D NewGraphics2D()
        {
            if (!viewPortHasBeenSet)
            {
                SetAndClearViewPort();
            }

            Graphics2D graphics2D = new Graphics2DOpenGL(this.ClientSize.Width, this.ClientSize.Height);

            graphics2D.PushTransform();

            return(graphics2D);
        }
Ejemplo n.º 12
0
        public Graphics2D NewGraphics2D()
        {
            Graphics2D graphics2D = new Graphics2DVeldrid(this.Width, this.Height)
            {
                WindowProvider = windowProvider
            };

            // this is for testing the open gl implementation
            graphics2D = new Graphics2DOpenGL(this.Width, this.Height);
            graphics2D.PushTransform();

            return(graphics2D);
        }
Ejemplo n.º 13
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            if (LoadedGCode != null)
            {
                //using (new PerformanceTimer("GCode Timer", "Total"))
                {
                    Affine transform = TotalTransform;

                    if (RenderGrid)
                    {
                        //using (new PerformanceTimer("GCode Timer", "Render Grid"))
                        {
                            double gridLineWidths = 0.2 * layerScale;

                            Graphics2DOpenGL graphics2DGl = graphics2D as Graphics2DOpenGL;
                            if (graphics2DGl != null)
                            {
                                GlRenderGrid(graphics2DGl, transform, gridLineWidths);
                            }
                            else
                            {
                                CreateGrid(transform);

                                Stroke stroke = new Stroke(grid, gridLineWidths);
                                graphics2D.Render(stroke, gridColor);
                            }
                        }
                    }

                    GCodeRenderInfo renderInfo = new GCodeRenderInfo(activeLayerIndex, activeLayerIndex, transform, layerScale, CreateRenderInfo(),
                                                                     FeatureToStartOnRatio0To1, FeatureToEndOnRatio0To1,
                                                                     new Vector2[] { ActiveSliceSettings.Instance.Helpers.ExtruderOffset(0), ActiveSliceSettings.Instance.Helpers.ExtruderOffset(1) });

                    //using (new PerformanceTimer("GCode Timer", "Render"))
                    {
                        gCodeRenderer?.Render(graphics2D, renderInfo);
                    }
                }
            }

            base.OnDraw(graphics2D);
        }
Ejemplo n.º 14
0
        private void DrawRotationCompass(IObject3D selectedItem, DrawGlContentEventArgs drawEventArgs)
        {
            if (InteractionContext.Scene.SelectedItem == null)
            {
                return;
            }

            double alphaValue = 1;

            if (!drawEventArgs.ZBuffered)
            {
                alphaValue = .3;
            }

            AxisAlignedBoundingBox currentSelectedBounds = selectedItem.GetAxisAlignedBoundingBox(Matrix4X4.Identity);

            if (currentSelectedBounds.XSize > 100000)
            {
                // something is wrong the part is too big (probably in invalid selection)
                return;
            }
            Vector3 controlCenter  = GetControlCenter(selectedItem);
            Vector3 rotationCenter = GetRotationCenter(selectedItem, currentSelectedBounds);

            if (mouseDownInfo != null)
            {
                rotationCenter = mouseDownInfo.SelectedObjectRotationCenter;
                controlCenter  = mouseDownInfo.ControlCenter;
            }

            if (mouseMoveInfo != null)
            {
                double distBetweenPixelsWorldSpace = InteractionContext.World.GetWorldUnitsPerScreenPixelAtPosition(rotationCenter);

                double    radius;
                Matrix4X4 rotationCenterTransform = GetRotationTransform(selectedItem, out radius);

                double innerRadius        = radius + ringWidth / 2;
                double outerRadius        = innerRadius + ringWidth;
                double snappingMarkRadius = outerRadius + 20;

                double startBlue = 0;
                double endBlue   = MathHelper.Tau;

                double mouseAngle = 0;
                if (mouseMoveInfo != null)
                {
                    mouseAngle = mouseMoveInfo.AngleOfHit;
                }
                if (mouseDownInfo != null)
                {
                    mouseAngle = mouseDownInfo.AngleOfHit;
                }

                var graphics2DOpenGL = new Graphics2DOpenGL();

                if (mouseDownInfo != null || MouseOver)
                {
                    IVertexSource blueRing = new JoinPaths(new Arc(0, 0, outerRadius, outerRadius, startBlue, endBlue, Arc.Direction.CounterClockWise),
                                                           new Arc(0, 0, innerRadius, innerRadius, startBlue, endBlue, Arc.Direction.ClockWise));
                    graphics2DOpenGL.RenderTransformedPath(rotationCenterTransform, blueRing, new Color(Color.Blue, (int)(50 * alphaValue)), drawEventArgs.ZBuffered);
                    // tick 60 marks
                    DrawTickMarks(drawEventArgs, alphaValue, rotationCenterTransform, innerRadius, outerRadius, 60);
                }

                if (mouseDownInfo != null)
                {
                    double startRed = mouseDownInfo.AngleOfHit;
                    double endRed   = SnappedRotationAngle + mouseDownInfo.AngleOfHit;

                    if (!rotatingCW)
                    {
                        var temp = startRed;
                        startRed = endRed;
                        endRed   = temp;
                    }

                    IVertexSource redAngle = new JoinPaths(new Arc(0, 0, 0, 0, startRed, endRed, Arc.Direction.CounterClockWise),
                                                           new Arc(0, 0, innerRadius, innerRadius, startRed, endRed, Arc.Direction.ClockWise));
                    graphics2DOpenGL.RenderTransformedPath(rotationCenterTransform, redAngle, new Color(Color.Red, (int)(70 * alphaValue)), drawEventArgs.ZBuffered);

                    // draw a line to the mouse on the rotation circle
                    if (mouseMoveInfo != null && MouseDownOnControl)
                    {
                        Vector3 unitPosition  = new Vector3(Math.Cos(mouseMoveInfo.AngleOfHit), Math.Sin(mouseMoveInfo.AngleOfHit), 0);
                        Vector3 startPosition = Vector3Ex.Transform(unitPosition * innerRadius, rotationCenterTransform);
                        var     center        = Vector3Ex.Transform(Vector3.Zero, rotationCenterTransform);
                        if ((mouseMoveInfo.HitPosition - center).Length > rotationTransformScale * innerRadius)
                        {
                            InteractionContext.World.Render3DLine(startPosition, mouseMoveInfo.HitPosition, Color.Red, drawEventArgs.ZBuffered);
                        }

                        DrawSnappingMarks(drawEventArgs, mouseAngle, alphaValue, rotationCenterTransform, snappingMarkRadius, 5, numSnapPoints, GetSnapIndex(selectedItem, numSnapPoints));
                    }
                }
            }
        }
Ejemplo n.º 15
0
 protected void Render3DStartEndMarkers(Graphics2DOpenGL graphics2DGl, double radius, Vector2 startPoint, Vector2 endPoint)
 {
     graphics2DGl.DrawAACircle(startPoint, radius, RenderFeatureBase.StartColor);
     graphics2DGl.DrawAACircle(endPoint, radius, RenderFeatureBase.EndColor);
 }
Ejemplo n.º 16
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            if (loadedGCode != null)
            {
                //using (new PerformanceTimer("GCode Timer", "Total"))
                {
                    Affine transform = TotalTransform;

                    if (RenderGrid)
                    {
                        //using (new PerformanceTimer("GCode Timer", "Render Grid"))
                        {
                            double gridLineWidths = 0.2 * layerScale;

                            Graphics2DOpenGL graphics2DGl = graphics2D as Graphics2DOpenGL;
                            if (graphics2DGl != null)
                            {
                                GlRenderGrid(graphics2DGl, transform, gridLineWidths);
                            }
                            else
                            {
                                CreateGrid(transform);

                                Stroke stroke = new Stroke(grid, gridLineWidths);
                                graphics2D.Render(stroke, gridColor);
                            }
                        }
                    }

                    RenderType renderType = RenderType.Extrusions;
                    if (RenderMoves)
                    {
                        renderType |= RenderType.Moves;
                    }
                    if (RenderRetractions)
                    {
                        renderType |= RenderType.Retractions;
                    }
                    if (RenderSpeeds)
                    {
                        renderType |= RenderType.SpeedColors;
                    }
                    if (SimulateExtrusion)
                    {
                        renderType |= RenderType.SimulateExtrusion;
                    }
                    if (HideExtruderOffsets)
                    {
                        renderType |= RenderType.HideExtruderOffsets;
                    }

                    GCodeRenderInfo renderInfo = new GCodeRenderInfo(activeLayerIndex, activeLayerIndex, transform, layerScale, renderType,
                                                                     FeatureToStartOnRatio0To1, FeatureToEndOnRatio0To1,
                                                                     new Vector2[] { ActiveSliceSettings.Instance.GetOffset(0), ActiveSliceSettings.Instance.GetOffset(1) });

                    //using (new PerformanceTimer("GCode Timer", "Render"))
                    {
                        gCodeRenderer.Render(graphics2D, renderInfo);
                    }
                }
            }

            base.OnDraw(graphics2D);
        }