Example #1
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 sart and end are set to the last feature
                    // Try to set the start feture to one from the end
                    startFeature = Math.Max(endFeature - 1, 0);
                }

                for (int i = startFeature; i < endFeature; i++)
                {
                    RenderFeatureBase feature = renderFeatures[renderInfo.EndLayerIndex][i];
                    if (feature != null)
                    {
                        feature.Render(graphics2D, renderInfo);
                    }
                }
            }
        }
        private GCodeVertexBuffer Create3DDataForLayer(int layerIndex, GCodeRenderInfo renderInfo)
        {
            var colorVertexData  = new VectorPOD <ColorVertexData>();
            var vertexIndexArray = new VectorPOD <int>();

            featureStartIndex[layerIndex].Clear();
            featureEndIndex[layerIndex].Clear();

            for (int i = 0; i < renderFeatures[layerIndex].Count; i++)
            {
                featureStartIndex[layerIndex].Add(vertexIndexArray.Count);

                RenderFeatureBase feature = renderFeatures[layerIndex][i];

                if (feature != null)
                {
                    // Build the color and index data for the feature
                    feature.CreateRender3DData(colorVertexData, vertexIndexArray, renderInfo);
                }

                featureEndIndex[layerIndex].Add(vertexIndexArray.Count);
            }

            // Construct and return the new VertexBuffer object with all color/index data
            return(new GCodeVertexBuffer(vertexIndexArray.Array, colorVertexData.Array));
        }
        public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo)
        {
            if ((renderInfo.CurrentRenderType & RenderType.Moves) == RenderType.Moves)
            {
                double     movementLineWidth = 0.35 * renderInfo.LayerScale;
                RGBA_Bytes movementColor     = new RGBA_Bytes(10, 190, 15);

                PathStorage pathStorage = new PathStorage();
                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.CommandMoveTo);
                if (end.x != start.x || end.y != start.y)
                {
                    pathStorage.Add(end.x, end.y, ShapePath.FlagsAndCommand.CommandLineTo);
                }
                else
                {
                    pathStorage.Add(end.x + .01, end.y, ShapePath.FlagsAndCommand.CommandLineTo);
                }
                graphics2D.Render(stroke, 0, movementColor);
            }
        }
Example #4
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);
                }
            }
        }
        public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo)
        {
            if ((renderInfo.CurrentRenderType & RenderType.Extrusions) == RenderType.Extrusions)
            {
                double extrusionLineWidths = GetRadius(renderInfo.CurrentRenderType) * 2 * renderInfo.LayerScale;

                RGBA_Bytes extrusionColor = RGBA_Bytes.Black;
                if (extruderIndex > 0)
                {
                    extrusionColor = MeshViewerWidget.GetMaterialColor(extruderIndex + 1);
                }
                if ((renderInfo.CurrentRenderType & RenderType.SpeedColors) == RenderType.SpeedColors)
                {
                    extrusionColor = color;
                }

                PathStorage pathStorage = new PathStorage();
                VertexSourceApplyTransform transformedPathStorage = new VertexSourceApplyTransform(pathStorage, renderInfo.Transform);
                Stroke stroke = new Stroke(transformedPathStorage, extrusionLineWidths);

                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.CommandMoveTo);
                pathStorage.Add(end.x, end.y, ShapePath.FlagsAndCommand.CommandLineTo);

                graphics2D.Render(stroke, 0, extrusionColor);
            }
        }
Example #6
0
        public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo, bool highlightFeature = false)
        {
            if ((renderInfo.CurrentRenderType & RenderType.Retractions) == RenderType.Retractions)
            {
                double radius = Radius(renderInfo.LayerScale);

                var position = new Vector2(this.position.X, this.position.Y);
                renderInfo.Transform.transform(ref position);

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

                if (graphics2D is Graphics2DOpenGL graphics2DGl)
                {
                    // render using opengl
                    graphics2DGl.DrawAACircle(position, radius, retractionColor);
                }
                else
                {
                    // render using agg
                    graphics2D.Render(
                        new Ellipse(position, radius),
                        retractionColor);
                }
            }
        }
		public override void CreateRender3DData(VectorPOD<ColorVertexData> colorVertexData, VectorPOD<int> indexData, GCodeRenderInfo renderInfo)
		{
			if ((renderInfo.CurrentRenderType & RenderType.Retractions) == RenderType.Retractions)
			{
				Vector3 position = new Vector3(this.position);
				RGBA_Bytes color = MeshViewerWidget.GetMaterialColor(extruderIndex + 1);
				if (extruderIndex == 0)
				{
					if (extrusionAmount > 0)
					{
						color = RGBA_Bytes.Blue;
					}
					else
					{
						color = RGBA_Bytes.Red;
					}
				}
				if (extrusionAmount > 0)
				{
					// unretraction
					CreatePointer(colorVertexData, indexData, position + new Vector3(0, 0, 1.3), position + new Vector3(0, 0, .3), Radius(1), 5, color);
				}
				else
				{
					// retraction
					CreatePointer(colorVertexData, indexData, position + new Vector3(0, 0, .3), position + new Vector3(0, 0, 1.3), Radius(1), 5, color);
				}
			}
		}
Example #8
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
                if (graphics2D is Graphics2DOpenGL graphics2DGl)
                {
                    graphics2DGl.DrawAACircle(position, radius, retractionColor);
                }
                else
                {
                    Ellipse extrusion = new Ellipse(position, radius);
                    graphics2D.Render(extrusion, retractionColor);
                }
            }
        }
        public override void OnDraw(Graphics2D graphics2D)
        {
            if (loadedGCode != null)
            {
                Affine transform = TotalTransform;

                CreateGrid(transform);

                double gridLineWidths = 0.2 * layerScale;
                Stroke stroke         = new Stroke(grid, gridLineWidths);

                if (RenderGrid)
                {
                    graphics2D.Render(stroke, RGBA_Bytes.DarkGray);
                }

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

                GCodeRenderInfo renderInfo = new GCodeRenderInfo(activeLayerIndex, activeLayerIndex, transform, layerScale, renderType,
                                                                 FeatureToStartOnRatio0To1, FeatureToEndOnRatio0To1, null);
                gCodeRenderer.Render(graphics2D, renderInfo);
            }

            base.OnDraw(graphics2D);
        }
Example #10
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 CreateRender3DData(VectorPOD<ColorVertexData> colorVertexData, VectorPOD<int> indexData, GCodeRenderInfo renderInfo)
		{
			if ((renderInfo.CurrentRenderType & RenderType.Moves) == RenderType.Moves)
			{
				Vector3Float start = this.GetStart(renderInfo);
				Vector3Float end = this.GetEnd(renderInfo);
				CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), .1, 6, GCodeRenderer.TravelColor, .2);
			}
		}
Example #12
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);
                        }
                    }
                }
            }
        }
        public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo, bool highlightFeature = false)
        {
            if ((renderInfo.CurrentRenderType & RenderType.Moves) == RenderType.Moves)
            {
                double movementLineWidth = 0.2 * renderInfo.LayerScale;
                Color  movementColor     = (highlightFeature) ? RenderFeatureBase.HighlightColor : new Color(10, 190, 15);

                if (graphics2D is Graphics2DOpenGL graphics2DGl)
                {
                    // render using opengl
                    var startPoint = new Vector2(start.X, start.Y);
                    renderInfo.Transform.transform(ref startPoint);

                    var endPoint = new Vector2(end.X, end.Y);
                    renderInfo.Transform.transform(ref endPoint);

                    if (retractionTravel)
                    {
                        movementColor = GCodeRenderer.RetractionColor;
                    }

                    if (renderInfo.CurrentRenderType.HasFlag(RenderType.TransparentExtrusion))
                    {
                        movementColor = movementColor.WithAlpha(120);
                    }

                    graphics2DGl.DrawAALineRounded(startPoint, endPoint, movementLineWidth, movementColor);
                }
                else
                {
                    // render using agg
                    var pathStorage            = new VertexStorage();
                    var transformedPathStorage = new VertexSourceApplyTransform(pathStorage, renderInfo.Transform);
                    var stroke = new Stroke(transformedPathStorage, movementLineWidth)
                    {
                        LineCap  = LineCap.Round,
                        LineJoin = LineJoin.Round
                    };

                    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);
                }
            }
        }
        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);
                }
            }
        }
		protected Vector3Float GetEnd(GCodeRenderInfo renderInfo)
		{
			if ((renderInfo.CurrentRenderType & RenderType.HideExtruderOffsets) == RenderType.HideExtruderOffsets)
			{
				Vector3Float end = this.end;
				Vector2 offset = renderInfo.GetExtruderOffset(extruderIndex);
				end.x += (float)offset.x;
				end.y += (float)offset.y;
				return end;
			}

			return this.end;
		}
		protected Vector3Float GetStart(GCodeRenderInfo renderInfo)
		{
			if ((renderInfo.CurrentRenderType & RenderType.HideExtruderOffsets) == RenderType.HideExtruderOffsets)
			{
				Vector3Float start = this.start;
				Vector2 offset = renderInfo.GetExtruderOffset(extruderIndex);
				start.x += (float)offset.x;
				start.y += (float)offset.y;
				return start;
			}

			return this.start;
		}
Example #17
0
        protected Vector3Float GetStart(GCodeRenderInfo renderInfo)
        {
            if ((renderInfo.CurrentRenderType & RenderType.HideExtruderOffsets) == RenderType.HideExtruderOffsets)
            {
                Vector3Float start  = this.start;
                Vector2      offset = renderInfo.GetExtruderOffset(extruderIndex);
                start.x += (float)offset.x;
                start.y += (float)offset.y;
                return(start);
            }

            return(this.start);
        }
Example #18
0
        protected Vector3Float GetStart(GCodeRenderInfo renderInfo)
        {
            if (renderInfo.CurrentRenderType.HasFlag(RenderType.HideExtruderOffsets))
            {
                Vector3Float start  = this.start;
                Vector2      offset = renderInfo.GetExtruderOffset(extruderIndex);
                start.X += (float)offset.X;
                start.Y += (float)offset.Y;
                return(start);
            }

            return(this.start);
        }
Example #19
0
        protected Vector3Float GetEnd(GCodeRenderInfo renderInfo)
        {
            if ((renderInfo.CurrentRenderType & RenderType.HideExtruderOffsets) == RenderType.HideExtruderOffsets)
            {
                Vector3Float end    = this.end;
                Vector2      offset = renderInfo.GetExtruderOffset(extruderIndex);
                end.x += (float)offset.x;
                end.y += (float)offset.y;
                return(end);
            }

            return(this.end);
        }
Example #20
0
        protected Vector3Float GetEnd(GCodeRenderInfo renderInfo)
        {
            if (renderInfo.CurrentRenderType.HasFlag(RenderType.HideExtruderOffsets))
            {
                Vector3Float end    = this.end;
                Vector2      offset = renderInfo.GetExtruderOffset(extruderIndex);
                end.X += (float)offset.X;
                end.Y += (float)offset.Y;
                return(end);
            }

            return(this.end);
        }
Example #21
0
        private void Create3DDataForLayer(int layerIndex,
                                          VectorPOD <ColorVertexData> colorVertexData,
                                          VectorPOD <int> vertexIndexArray,
                                          GCodeRenderInfo renderInfo)
        {
            colorVertexData.Clear();
            vertexIndexArray.Clear();
            featureStartIndex[layerIndex].Clear();
            featureEndIndex[layerIndex].Clear();

            for (int i = 0; i < renderFeatures[layerIndex].Count; i++)
            {
                featureStartIndex[layerIndex].Add(vertexIndexArray.Count);
                RenderFeatureBase feature = renderFeatures[layerIndex][i];
                if (feature != null)
                {
                    feature.CreateRender3DData(colorVertexData, vertexIndexArray, renderInfo);
                }
                featureEndIndex[layerIndex].Add(vertexIndexArray.Count);
            }
        }
Example #22
0
        public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo)
        {
            if ((renderInfo.CurrentRenderType & RenderType.Retractions) == RenderType.Retractions)
            {
                Vector2 position = new Vector2(this.position.x, this.position.y);
                renderInfo.Transform.transform(ref position);
                double  radius    = Radius(renderInfo.LayerScale);
                Ellipse extrusion = new Ellipse(position, radius);

                if (extrusionAmount > 0)
                {
                    // unretraction
                    graphics2D.Render(extrusion, new RGBA_Bytes(RGBA_Bytes.Blue, 200));
                }
                else
                {
                    // retraction
                    graphics2D.Render(extrusion, new RGBA_Bytes(RGBA_Bytes.Red, 200));
                }
            }
        }
        public override void CreateRender3DData(VectorPOD<ColorVertexData> colorVertexData, VectorPOD<int> indexData, GCodeRenderInfo renderInfo)
		{
			if ((renderInfo.CurrentRenderType & RenderType.Extrusions) == RenderType.Extrusions)
			{
				Vector3Float start = this.GetStart(renderInfo);
				Vector3Float end = this.GetEnd(renderInfo);
				double radius = GetRadius(renderInfo.CurrentRenderType);
				if ((renderInfo.CurrentRenderType & RenderType.SpeedColors) == RenderType.SpeedColors)
				{
					CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), radius, 6, color, layerHeight);
				}
				else
				{
					if (extruderIndex == 0)
					{
						CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), radius, 6, GCodeRenderer.ExtrusionColor, layerHeight);
					}
					else
					{
						CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), radius, 6, MeshViewerWidget.GetMaterialColor(extruderIndex + 1), layerHeight);
					}
				}
			}
		}
 public override void CreateRender3DData(VectorPOD <ColorVertexData> colorVertexData, VectorPOD <int> indexData, GCodeRenderInfo renderInfo)
 {
     if ((renderInfo.CurrentRenderType & RenderType.Moves) == RenderType.Moves)
     {
         CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), .1, 6, retractionTravel ?  GCodeRenderer.RetractionColor : GCodeRenderer.TravelColor, .2);
     }
 }
		public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo)
		{
			if ((renderInfo.CurrentRenderType & RenderType.Extrusions) == RenderType.Extrusions)
			{
				double extrusionLineWidths = GetRadius(renderInfo.CurrentRenderType) * 2 * renderInfo.LayerScale;

				RGBA_Bytes extrusionColor = RGBA_Bytes.Black;
				if (extruderIndex > 0)
				{
					extrusionColor = MeshViewerWidget.GetMaterialColor(extruderIndex + 1);
				}
				if ((renderInfo.CurrentRenderType & RenderType.SpeedColors) == RenderType.SpeedColors)
				{
					extrusionColor = color;
				}

				PathStorage pathStorage = new PathStorage();
				VertexSourceApplyTransform transformedPathStorage = new VertexSourceApplyTransform(pathStorage, renderInfo.Transform);
				Stroke stroke = new Stroke(transformedPathStorage, extrusionLineWidths);

				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.CommandMoveTo);
				pathStorage.Add(end.x, end.y, ShapePath.FlagsAndCommand.CommandLineTo);

				graphics2D.Render(stroke, 0, extrusionColor);
			}
		}
Example #26
0
 public abstract void CreateRender3DData(VectorPOD <ColorVertexData> colorVertexData, VectorPOD <int> indexData, GCodeRenderInfo renderInfo);
		public override void OnDraw(Graphics2D graphics2D)
		{
			if (loadedGCode != null)
			{
				Affine transform = TotalTransform;

				CreateGrid(transform);

				double gridLineWidths = 0.2 * layerScale;
				Stroke stroke = new Stroke(grid, gridLineWidths);

				if (RenderGrid)
				{
					graphics2D.Render(stroke, new RGBA_Bytes(190, 190, 190, 255));
				}

				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) });
				gCodeRenderer.Render(graphics2D, renderInfo);
			}

			base.OnDraw(graphics2D);
		}
		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);
				}
			}
		}
		public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo)
		{
			if ((renderInfo.CurrentRenderType & RenderType.Retractions) == RenderType.Retractions)
			{
				Vector2 position = new Vector2(this.position.x, this.position.y);
				renderInfo.Transform.transform(ref position);
				double radius = Radius(renderInfo.LayerScale);
				Ellipse extrusion = new Ellipse(position, radius);

				if (extrusionAmount > 0)
				{
					// unretraction
					graphics2D.Render(extrusion, new RGBA_Bytes(RGBA_Bytes.Blue, 200));
				}
				else
				{
					// retraction
					graphics2D.Render(extrusion, new RGBA_Bytes(RGBA_Bytes.Red, 200));
				}
			}
		}
Example #30
0
		public abstract void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo);
Example #31
0
 public override void CreateRender3DData(VectorPOD <ColorVertexData> colorVertexData, VectorPOD <int> indexData, GCodeRenderInfo renderInfo)
 {
     if ((renderInfo.CurrentRenderType & RenderType.Extrusions) == RenderType.Extrusions)
     {
         Vector3Float start  = this.GetStart(renderInfo);
         Vector3Float end    = this.GetEnd(renderInfo);
         double       radius = GetRadius(renderInfo.CurrentRenderType);
         if ((renderInfo.CurrentRenderType & RenderType.SpeedColors) == RenderType.SpeedColors)
         {
             CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), radius, 6, color, layerHeight);
         }
         else
         {
             if (extruderIndex == 0)
             {
                 CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), radius, 6, GCodeRenderer.ExtrusionColor, layerHeight);
             }
             else
             {
                 CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), radius, 6, MeshViewerWidget.GetMaterialColor(extruderIndex + 1), layerHeight);
             }
         }
     }
 }
        public override void CreateRender3DData(VectorPOD <ColorVertexData> colorVertexData, VectorPOD <int> indexData, GCodeRenderInfo renderInfo)
        {
            if ((renderInfo.CurrentRenderType & RenderType.Extrusions) == RenderType.Extrusions)
            {
                double radius = GetRadius(renderInfo.CurrentRenderType);

                Color lineColor;

                if (renderInfo.CurrentRenderType.HasFlag(RenderType.SpeedColors))
                {
                    lineColor = color;
                }
                else if (renderInfo.CurrentRenderType.HasFlag(RenderType.GrayColors))
                {
                    lineColor = this.gray;
                }
                else
                {
                    lineColor = renderInfo.GetMaterialColor(toolIndex);
                }

                CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), radius, 6, lineColor, layerHeight);
            }
        }
Example #33
0
 public abstract void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo, bool highlightFeature = false);
Example #34
0
		public void Render3D(GCodeRenderInfo renderInfo)
		{
			if (layerVertexBuffer == null)
			{
				layerVertexBuffer = new List<GCodeVertexBuffer>();
				layerVertexBuffer.Capacity = gCodeFileToDraw.NumChangesInZ;
				for (int layerIndex = 0; layerIndex < gCodeFileToDraw.NumChangesInZ; layerIndex++)
				{
					layerVertexBuffer.Add(null);
					featureStartIndex.Add(new List<int>());
					featureEndIndex.Add(new List<int>());
				}
			}

			for (int layerIndex = 0; layerIndex < gCodeFileToDraw.NumChangesInZ; layerIndex++)
			{
				CreateFeaturesForLayerIfRequired(layerIndex);
			}

			if (lastRenderType != renderInfo.CurrentRenderType)
			{
				Clear3DGCode();
				lastRenderType = renderInfo.CurrentRenderType;
			}

			if (renderFeatures.Count > 0)
			{
				for (int i = renderInfo.StartLayerIndex; i < renderInfo.EndLayerIndex; i++)
				{
					// If its the first render or we change what we are trying to render then create vertex data.
					if (layerVertexBuffer[i] == null)
					{
						VectorPOD<ColorVertexData> colorVertexData = new VectorPOD<ColorVertexData>();
						VectorPOD<int> vertexIndexArray = new VectorPOD<int>();

						Create3DDataForLayer(i, colorVertexData, vertexIndexArray, renderInfo);

						layerVertexBuffer[i] = new GCodeVertexBuffer();
						layerVertexBuffer[i].SetVertexData(colorVertexData.Array);
						layerVertexBuffer[i].SetIndexData(vertexIndexArray.Array);
					}
				}

				GL.Disable(EnableCap.Texture2D);
				GL.PushAttrib(AttribMask.EnableBit);
				GL.DisableClientState(ArrayCap.TextureCoordArray);
				GL.Enable(EnableCap.PolygonSmooth);

				if (renderInfo.EndLayerIndex - 1 > renderInfo.StartLayerIndex)
				{
					for (int i = renderInfo.StartLayerIndex; i < renderInfo.EndLayerIndex - 1; i++)
					{
						int featuresOnLayer = renderFeatures[i].Count;
						if (featuresOnLayer > 1)
						{
							layerVertexBuffer[i].renderRange(0, featureEndIndex[i][featuresOnLayer - 1]);
						}
					}
				}

				// draw the partial layer of end-1 from startRatio to endRatio
				{
					int layerIndex = renderInfo.EndLayerIndex - 1;
					int featuresOnLayer = renderFeatures[layerIndex].Count;
					int startFeature = (int)(featuresOnLayer * renderInfo.FeatureToStartOnRatio0To1 + .5);
					startFeature = Math.Max(0, Math.Min(startFeature, featuresOnLayer));

					int endFeature = (int)(featuresOnLayer * renderInfo.FeatureToEndOnRatio0To1 + .5);
					endFeature = Math.Max(0, Math.Min(endFeature, 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 sart and end are set to the last feature
						// Try to set the start feture to one from the end
						startFeature = Math.Max(endFeature - 1, 0);
					}

					if (endFeature > startFeature)
					{
						int ellementCount = featureEndIndex[layerIndex][endFeature - 1] - featureStartIndex[layerIndex][startFeature];

						layerVertexBuffer[layerIndex].renderRange(featureStartIndex[layerIndex][startFeature], ellementCount);
					}
				}
				GL.PopAttrib();
			}
		}
Example #35
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			if (loadedGCode != null)
			{
				Affine transform = TotalTransform;

				CreateGrid(transform);

				double gridLineWidths = 0.2 * layerScale;
				Stroke stroke = new Stroke(grid, gridLineWidths);

				if (RenderGrid)
				{
					graphics2D.Render(stroke, RGBA_Bytes.DarkGray);
				}

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

				GCodeRenderInfo renderInfo = new GCodeRenderInfo(activeLayerIndex, activeLayerIndex, transform, layerScale, renderType,
					FeatureToStartOnRatio0To1, FeatureToEndOnRatio0To1, null);
				gCodeRenderer.Render(graphics2D, renderInfo);
			}

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

				PathStorage pathStorage = new PathStorage();
				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.CommandMoveTo);
				if (end.x != start.x || end.y != start.y)
				{
					pathStorage.Add(end.x, end.y, ShapePath.FlagsAndCommand.CommandLineTo);
				}
				else
				{
					pathStorage.Add(end.x + .01, end.y, ShapePath.FlagsAndCommand.CommandLineTo);
				}
				graphics2D.Render(stroke, 0, movementColor);
			}
		}
Example #37
0
        public void Render3D(GCodeRenderInfo renderInfo, DrawEventArgs e)
        {
            if (renderInfo == null)
            {
                return;
            }

            if (layerVertexBuffer == null)
            {
                layerVertexBuffer = new List <GCodeVertexBuffer>(gCodeFileToDraw.LayerCount);
                for (int layerIndex = 0; layerIndex < gCodeFileToDraw.LayerCount; layerIndex++)
                {
                    layerVertexBuffer.Add(null);
                    featureStartIndex.Add(new List <int>());
                    featureEndIndex.Add(new List <int>());
                }
            }

            for (int layerIndex = 0; layerIndex < gCodeFileToDraw.LayerCount; layerIndex++)
            {
                CreateFeaturesForLayerIfRequired(layerIndex);
            }

            if (lastRenderType != renderInfo.CurrentRenderType)
            {
                Clear3DGCode();
                lastRenderType = renderInfo.CurrentRenderType;
            }

            if (renderFeatures.Count > 0)
            {
                if (Is32Bit && !GL.GlHasBufferObjects)
                {
                    int  maxFeaturesForThisSystem = 125000;
                    int  totalFeaturesToRender    = 0;
                    bool cleanUnusedLayers        = false;
                    // if on 32 bit system make sure we don't run out of memory rendering too many features
                    for (int i = renderInfo.EndLayerIndex - 1; i >= renderInfo.StartLayerIndex; i--)
                    {
                        if (totalFeaturesToRender + renderFeatures[i].Count < maxFeaturesForThisSystem)
                        {
                            totalFeaturesToRender += renderFeatures[i].Count;
                        }
                        else                         // don't render any of the layers below this and in fact remove them from memory if possible
                        {
                            renderInfo.StartLayerIndex = i + 1;
                            cleanUnusedLayers          = true;
                            break;
                        }
                    }

                    if (cleanUnusedLayers)
                    {
                        // no remove any layers that are set that we are not going to render
                        for (int removeIndex = 0; removeIndex < layerVertexBuffer.Count; removeIndex++)
                        {
                            if (removeIndex < renderInfo.StartLayerIndex || removeIndex >= renderInfo.EndLayerIndex)
                            {
                                if (layerVertexBuffer[removeIndex] != null)
                                {
                                    layerVertexBuffer[removeIndex].Dispose();
                                    layerVertexBuffer[removeIndex] = null;
                                }
                            }
                        }
                    }
                }

                for (int i = renderInfo.EndLayerIndex - 1; i >= renderInfo.StartLayerIndex; i--)
                {
                    // If its the first render or we change what we are trying to render then create vertex data.
                    if (layerVertexBuffer[i] == null)
                    {
                        layerVertexBuffer[i] = Create3DDataForLayer(i, renderInfo);
                    }
                }

                GL.Disable(EnableCap.Texture2D);
                GL.PushAttrib(AttribMask.EnableBit);
                GL.DisableClientState(ArrayCap.TextureCoordArray);
                GL.Enable(EnableCap.PolygonSmooth);

                if (renderInfo.EndLayerIndex - 1 > renderInfo.StartLayerIndex)
                {
                    for (int i = renderInfo.StartLayerIndex; i < renderInfo.EndLayerIndex - 1; i++)
                    {
                        int featuresOnLayer = renderFeatures[i].Count;
                        if (featuresOnLayer > 1 &&
                            layerVertexBuffer[i] != null)
                        {
                            layerVertexBuffer[i].RenderRange(0, featureEndIndex[i][featuresOnLayer - 1]);
                        }
                    }
                }

                // draw the partial layer of end-1 from startRatio to endRatio
                {
                    int layerIndex      = renderInfo.EndLayerIndex - 1;
                    int featuresOnLayer = renderFeatures[layerIndex].Count;
                    int startFeature    = (int)(featuresOnLayer * renderInfo.FeatureToStartOnRatio0To1 + .5);
                    startFeature = Math.Max(0, Math.Min(startFeature, featuresOnLayer));

                    int endFeature = (int)(featuresOnLayer * renderInfo.FeatureToEndOnRatio0To1 + .5);
                    endFeature = Math.Max(0, Math.Min(endFeature, 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);
                    }

                    if (endFeature > startFeature &&
                        layerVertexBuffer[layerIndex] != null)
                    {
                        int ellementCount = featureEndIndex[layerIndex][endFeature - 1] - featureStartIndex[layerIndex][startFeature];

                        layerVertexBuffer[layerIndex].RenderRange(featureStartIndex[layerIndex][startFeature], ellementCount);
                    }
                }
                GL.PopAttrib();
            }
        }
		public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo)
		{
			if (renderInfo.CurrentRenderType.HasFlag(RenderType.Extrusions))
			{
				double extrusionLineWidths = GetExtrusionWidth(renderInfo.CurrentRenderType) * 2 * renderInfo.LayerScale;

				RGBA_Bytes extrusionColor = RGBA_Bytes.Black;
				if (extruderIndex > 0)
				{
					extrusionColor = MeshViewerWidget.GetMaterialColor(extruderIndex + 1);
				}
				if (renderInfo.CurrentRenderType.HasFlag(RenderType.SpeedColors))
				{
					extrusionColor = color;
				}

                if (renderInfo.CurrentRenderType.HasFlag(RenderType.TransparentExtrusion))
                {
                    extrusionColor = new RGBA_Bytes(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
				{
					PathStorage pathStorage = new PathStorage();
					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.CommandMoveTo);
					pathStorage.Add(end.x, end.y, ShapePath.FlagsAndCommand.CommandLineTo);

					graphics2D.Render(stroke, 0, extrusionColor);
				}
			}
		}
		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);
		}
Example #40
0
        public override void CreateRender3DData(VectorPOD <ColorVertexData> colorVertexData, VectorPOD <int> indexData, GCodeRenderInfo renderInfo)
        {
            if ((renderInfo.CurrentRenderType & RenderType.Extrusions) == RenderType.Extrusions)
            {
                Vector3Float start  = this.GetStart(renderInfo);
                Vector3Float end    = this.GetEnd(renderInfo);
                double       radius = GetRadius(renderInfo.CurrentRenderType);

                Color lineColor;

                if (renderInfo.CurrentRenderType.HasFlag(RenderType.SpeedColors))
                {
                    lineColor = color;
                }
                else if (renderInfo.CurrentRenderType.HasFlag(RenderType.GrayColors))
                {
                    lineColor = ActiveTheme.Instance.IsDarkTheme ? Color.DarkGray : Color.Gray;
                }
                else
                {
                    lineColor = renderInfo.GetMaterialColor(extruderIndex);
                }

                CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), radius, 6, lineColor, layerHeight);
            }
        }
Example #41
0
        public override void CreateRender3DData(VectorPOD <ColorVertexData> colorVertexData, VectorPOD <int> indexData, GCodeRenderInfo renderInfo)
        {
            if ((renderInfo.CurrentRenderType & RenderType.Retractions) == RenderType.Retractions)
            {
                var position = new Vector3(this.position);

                // retract and unretract are the extruder color
                Color color = renderInfo.GetMaterialColor(extruderIndex);
                // except for extruder 0 where they are the red and blue we are familiar with
                if (extruderIndex == 0)
                {
                    if (extrusionAmount > 0)
                    {
                        color = Color.Blue;
                    }
                    else
                    {
                        color = Color.Red;
                    }
                }
                if (extrusionAmount > 0)
                {
                    // unretraction
                    CreatePointer(colorVertexData, indexData, position + new Vector3(0, 0, 1.3), position + new Vector3(0, 0, .3), Radius(1), 5, color);
                }
                else
                {
                    // retraction
                    CreatePointer(colorVertexData, indexData, position + new Vector3(0, 0, .3), position + new Vector3(0, 0, 1.3), Radius(1), 5, color);
                }
            }
        }
Example #42
0
 public abstract void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo);
Example #43
0
		public abstract void CreateRender3DData(VectorPOD<ColorVertexData> colorVertexData, VectorPOD<int> indexData, GCodeRenderInfo renderInfo);
Example #44
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);
		}
Example #45
0
 public override void CreateRender3DData(VectorPOD <ColorVertexData> colorVertexData, VectorPOD <int> indexData, GCodeRenderInfo renderInfo)
 {
     if ((renderInfo.CurrentRenderType & RenderType.Moves) == RenderType.Moves)
     {
         Vector3Float start = this.GetStart(renderInfo);
         Vector3Float end   = this.GetEnd(renderInfo);
         CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), .1, 6, GCodeRenderer.TravelColor, .2);
     }
 }
        public void Render3D(GCodeRenderInfo renderInfo, DrawEventArgs e)
        {
            if (renderInfo == null)
            {
                return;
            }

            if (layerVertexBuffer == null)
            {
                layerVertexBuffer = new List <GCodeVertexBuffer>(gCodeFileToDraw.LayerCount);
                for (int layerIndex = 0; layerIndex < gCodeFileToDraw.LayerCount; layerIndex++)
                {
                    layerVertexBuffer.Add(null);
                    featureStartIndex.Add(new List <int>());
                    featureEndIndex.Add(new List <int>());
                }
            }

            for (int layerIndex = 0; layerIndex < gCodeFileToDraw.LayerCount; layerIndex++)
            {
                CreateFeaturesForLayerIfRequired(layerIndex);
            }

            if (lastRenderType != renderInfo.CurrentRenderType)
            {
                Clear3DGCode();
                lastRenderType = renderInfo.CurrentRenderType;
            }

            if (renderFeatures.Count > 0)
            {
                for (int i = renderInfo.EndLayerIndex - 1; i >= renderInfo.StartLayerIndex; i--)
                {
                    // If its the first render or we change what we are trying to render then create vertex data.
                    if (layerVertexBuffer[i] == null)
                    {
                        layerVertexBuffer[i] = Create3DDataForLayer(i, renderInfo);
                    }
                }

                GL.Disable(EnableCap.Texture2D);
                GL.PushAttrib(AttribMask.EnableBit);
                GL.DisableClientState(ArrayCap.TextureCoordArray);
                GL.Enable(EnableCap.PolygonSmooth);

                if (renderInfo.EndLayerIndex - 1 > renderInfo.StartLayerIndex)
                {
                    for (int i = renderInfo.StartLayerIndex; i < renderInfo.EndLayerIndex - 1; i++)
                    {
                        int featuresOnLayer = renderFeatures[i].Count;
                        if (featuresOnLayer > 1 &&
                            layerVertexBuffer[i] != null)
                        {
                            layerVertexBuffer[i].RenderRange(0, featureEndIndex[i][featuresOnLayer - 1]);
                        }
                    }
                }

                // draw the partial layer of end-1 from startRatio to endRatio
                {
                    int layerIndex      = renderInfo.EndLayerIndex - 1;
                    int featuresOnLayer = renderFeatures[layerIndex].Count;
                    int startFeature    = (int)(featuresOnLayer * renderInfo.FeatureToStartOnRatio0To1 + .5);
                    startFeature = Math.Max(0, Math.Min(startFeature, featuresOnLayer));

                    int endFeature = (int)(featuresOnLayer * renderInfo.FeatureToEndOnRatio0To1 + .5);
                    endFeature = Math.Max(0, Math.Min(endFeature, 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);
                    }

                    if (endFeature > startFeature &&
                        layerVertexBuffer[layerIndex] != null)
                    {
                        int ellementCount = featureEndIndex[layerIndex][endFeature - 1] - featureStartIndex[layerIndex][startFeature];

                        layerVertexBuffer[layerIndex].RenderRange(featureStartIndex[layerIndex][startFeature], ellementCount);
                    }
                }
                GL.PopAttrib();
            }
        }
Example #47
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 sart and end are set to the last feature
					// Try to set the start feture to one from the end
					startFeature = Math.Max(endFeature - 1, 0);
				}

				Graphics2DOpenGL graphics2DGl = graphics2D as Graphics2DOpenGL;
				if (graphics2DGl != null)
				{
					graphics2DGl.PreRender();
					GL.Begin(BeginMode.Triangles);
					for (int i = startFeature; i < endFeature; i++)
					{
						RenderFeatureBase feature = renderFeatures[renderInfo.EndLayerIndex][i];
						if (feature != null)
						{
							feature.Render(graphics2DGl, renderInfo);
						}
					}
					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);
						}
					}
				}
			}
		}
Example #48
0
		private void Create3DDataForLayer(int layerIndex,
			VectorPOD<ColorVertexData> colorVertexData,
			VectorPOD<int> vertexIndexArray,
			GCodeRenderInfo renderInfo)
		{
			colorVertexData.Clear();
			vertexIndexArray.Clear();
			featureStartIndex[layerIndex].Clear();
			featureEndIndex[layerIndex].Clear();

			for (int i = 0; i < renderFeatures[layerIndex].Count; i++)
			{
				featureStartIndex[layerIndex].Add(vertexIndexArray.Count);
				RenderFeatureBase feature = renderFeatures[layerIndex][i];
				if (feature != null)
				{
					feature.CreateRender3DData(colorVertexData, vertexIndexArray, renderInfo);
				}
				featureEndIndex[layerIndex].Add(vertexIndexArray.Count);
			}
		}
Example #49
0
 public override void CreateRender3DData(VectorPOD <ColorVertexData> colorVertexData, VectorPOD <int> indexData, GCodeRenderInfo renderInfo)
 {
     if ((renderInfo.CurrentRenderType & RenderType.Retractions) == RenderType.Retractions)
     {
         Vector3    position = new Vector3(this.position);
         RGBA_Bytes color    = MeshViewerWidget.GetMaterialColor(extruderIndex + 1);
         if (extruderIndex == 0)
         {
             if (extrusionAmount > 0)
             {
                 color = RGBA_Bytes.Blue;
             }
             else
             {
                 color = RGBA_Bytes.Red;
             }
         }
         if (extrusionAmount > 0)
         {
             // unretraction
             CreatePointer(colorVertexData, indexData, position + new Vector3(0, 0, 1.3), position + new Vector3(0, 0, .3), Radius(1), 5, color);
         }
         else
         {
             // retraction
             CreatePointer(colorVertexData, indexData, position + new Vector3(0, 0, .3), position + new Vector3(0, 0, 1.3), Radius(1), 5, color);
         }
     }
 }
Example #50
0
		public void Render3D(GCodeRenderInfo renderInfo)
		{
			if (layerVertexBuffer == null)
			{
				layerVertexBuffer = new List<GCodeVertexBuffer>();
				layerVertexBuffer.Capacity = gCodeFileToDraw.NumChangesInZ;
				for (int layerIndex = 0; layerIndex < gCodeFileToDraw.NumChangesInZ; layerIndex++)
				{
					layerVertexBuffer.Add(null);
					featureStartIndex.Add(new List<int>());
					featureEndIndex.Add(new List<int>());
				}
			}

			for (int layerIndex = 0; layerIndex < gCodeFileToDraw.NumChangesInZ; layerIndex++)
			{
				CreateFeaturesForLayerIfRequired(layerIndex);
			}

			if (lastRenderType != renderInfo.CurrentRenderType)
			{
				Clear3DGCode();
				lastRenderType = renderInfo.CurrentRenderType;
			}

			if (renderFeatures.Count > 0)
			{
				if (Is32Bit() && !GL.GlHasBufferObjects)
				{
					int maxFeaturesForThisSystem = 125000;
					int totalFeaturesToRunder = 0;
					bool cleanUnusedLayers = false;
					// if on 32 bit system make sure we don't run out of memory rendering too many features
					for (int i = renderInfo.EndLayerIndex - 1; i >= renderInfo.StartLayerIndex; i--)
					{
						if (totalFeaturesToRunder + renderFeatures[i].Count < maxFeaturesForThisSystem)
						{
							totalFeaturesToRunder += renderFeatures[i].Count;
						}
						else // don't render any of the layers below this and in fact remove them from memory if possible
						{
							renderInfo.startLayerIndex = i + 1;
							cleanUnusedLayers = true; 
							break;
						}
					}

					if (cleanUnusedLayers)
					{
						// no remove any layers that are set that we are not going to render
						for (int removeIndex = 0; removeIndex < layerVertexBuffer.Count; removeIndex++)
						{
							if (removeIndex < renderInfo.StartLayerIndex || removeIndex >= renderInfo.EndLayerIndex)
							{
								if (layerVertexBuffer[removeIndex] != null)
								{
									layerVertexBuffer[removeIndex].Dispose();
									layerVertexBuffer[removeIndex] = null;
								}
							}
						}
					}
				}

				for (int i = renderInfo.EndLayerIndex - 1; i >= renderInfo.StartLayerIndex; i--)
				{
					// If its the first render or we change what we are trying to render then create vertex data.
					if (layerVertexBuffer[i] == null)
					{
						VectorPOD<ColorVertexData> colorVertexData = new VectorPOD<ColorVertexData>();
						VectorPOD<int> vertexIndexArray = new VectorPOD<int>();

						Create3DDataForLayer(i, colorVertexData, vertexIndexArray, renderInfo);

						layerVertexBuffer[i] = new GCodeVertexBuffer();
						layerVertexBuffer[i].SetVertexData(colorVertexData.Array);
						layerVertexBuffer[i].SetIndexData(vertexIndexArray.Array);
					}
				}

				GL.Disable(EnableCap.Texture2D);
				GL.PushAttrib(AttribMask.EnableBit);
				GL.DisableClientState(ArrayCap.TextureCoordArray);
				GL.Enable(EnableCap.PolygonSmooth);

				if (renderInfo.EndLayerIndex - 1 > renderInfo.StartLayerIndex)
				{
					for (int i = renderInfo.StartLayerIndex; i < renderInfo.EndLayerIndex - 1; i++)
					{
						int featuresOnLayer = renderFeatures[i].Count;
						if (featuresOnLayer > 1)
						{
							layerVertexBuffer[i].renderRange(0, featureEndIndex[i][featuresOnLayer - 1]);
						}
					}
				}

				// draw the partial layer of end-1 from startRatio to endRatio
				{
					int layerIndex = renderInfo.EndLayerIndex - 1;
					int featuresOnLayer = renderFeatures[layerIndex].Count;
					int startFeature = (int)(featuresOnLayer * renderInfo.FeatureToStartOnRatio0To1 + .5);
					startFeature = Math.Max(0, Math.Min(startFeature, featuresOnLayer));

					int endFeature = (int)(featuresOnLayer * renderInfo.FeatureToEndOnRatio0To1 + .5);
					endFeature = Math.Max(0, Math.Min(endFeature, 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 sart and end are set to the last feature
						// Try to set the start feture to one from the end
						startFeature = Math.Max(endFeature - 1, 0);
					}

					if (endFeature > startFeature)
					{
						int ellementCount = featureEndIndex[layerIndex][endFeature - 1] - featureStartIndex[layerIndex][startFeature];

						layerVertexBuffer[layerIndex].renderRange(featureStartIndex[layerIndex][startFeature], ellementCount);
					}
				}
				GL.PopAttrib();
			}
		}
		private void TrackballTumbleWidget_DrawGlContent(object sender, EventArgs e)
		{
			GCodeRenderer.ExtrusionColor = ActiveTheme.Instance.PrimaryAccentColor;

			GCodeRenderInfo renderInfo = new GCodeRenderInfo(0,
				Math.Min(gcodeViewWidget.ActiveLayerIndex + 1, gcodeViewWidget.LoadedGCode.NumChangesInZ),
				gcodeViewWidget.TotalTransform,
				1,
				GetRenderType(),
				gcodeViewWidget.FeatureToStartOnRatio0To1,
				gcodeViewWidget.FeatureToEndOnRatio0To1,
				new Vector2[] { ActiveSliceSettings.Instance.GetOffset(0), ActiveSliceSettings.Instance.GetOffset(1) });

			gcodeViewWidget.gCodeRenderer.Render3D(renderInfo);
		}
		public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo)
		{
			if ((renderInfo.CurrentRenderType & RenderType.Moves) == RenderType.Moves)
			{
				double movementLineWidth = 0.35 * renderInfo.LayerScale;
				RGBA_Bytes movementColor = new RGBA_Bytes(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);

					graphics2DGl.DrawAALineRounded(start, end, movementLineWidth, movementColor);
				}
				else
				{
					PathStorage pathStorage = new PathStorage();
					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.CommandMoveTo);
					if (end.x != start.x || end.y != start.y)
					{
						pathStorage.Add(end.x, end.y, ShapePath.FlagsAndCommand.CommandLineTo);
					}
					else
					{
						pathStorage.Add(end.x + .01, end.y, ShapePath.FlagsAndCommand.CommandLineTo);
					}

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