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();
        }
Exemple #2
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);
                        }
                    }
                }
            }
        }