public void CreateFeaturesForLayerIfRequired(int layerToCreate)
        {
            if (renderFeatures.Count == 0 ||
                renderFeatures[layerToCreate].Count > 0)
            {
                return;
            }

            List <RenderFeatureBase> renderFeaturesForLayer = renderFeatures[layerToCreate];

            int startRenderIndex = gCodeFileToDraw.GetFirstLayerInstruction(layerToCreate);
            int endRenderIndex   = gCodeFileToDraw.LineCount - 1;

            if (layerToCreate < gCodeFileToDraw.LayerCount - 1)
            {
                endRenderIndex = gCodeFileToDraw.GetFirstLayerInstruction(layerToCreate + 1);
            }

            for (int instructionIndex = startRenderIndex; instructionIndex < endRenderIndex; instructionIndex++)
            {
                PrinterMachineInstruction currentInstruction  = gCodeFileToDraw.Instruction(instructionIndex);
                PrinterMachineInstruction previousInstruction = currentInstruction;
                if (instructionIndex > 0)
                {
                    previousInstruction = gCodeFileToDraw.Instruction(instructionIndex - 1);
                }

                if (currentInstruction.Position == previousInstruction.Position)
                {
                    if (Math.Abs(currentInstruction.EPosition - previousInstruction.EPosition) > 0)
                    {
                        // this is a retraction
                        renderFeaturesForLayer.Add(new RenderFeatureRetract(currentInstruction.Position, currentInstruction.EPosition - previousInstruction.EPosition, currentInstruction.ExtruderIndex, currentInstruction.FeedRate));
                    }
                    if (currentInstruction.Line.StartsWith("G10"))
                    {
                        renderFeaturesForLayer.Add(new RenderFeatureRetract(currentInstruction.Position, -1, currentInstruction.ExtruderIndex, currentInstruction.FeedRate));
                    }
                    else if (currentInstruction.Line.StartsWith("G11"))
                    {
                        renderFeaturesForLayer.Add(new RenderFeatureRetract(currentInstruction.Position, 1, currentInstruction.ExtruderIndex, currentInstruction.FeedRate));
                    }
                }
                else
                {
                    if (gCodeFileToDraw.IsExtruding(instructionIndex))
                    {
                        double layerThickness = gCodeFileToDraw.GetLayerHeight(layerToCreate);

                        Color extrusionColor = ExtrusionColors.GetColorForSpeed((float)currentInstruction.FeedRate);
                        renderFeaturesForLayer.Add(
                            new RenderFeatureExtrusion(
                                previousInstruction.Position,
                                currentInstruction.Position,
                                currentInstruction.ExtruderIndex,
                                currentInstruction.FeedRate,
                                currentInstruction.EPosition - previousInstruction.EPosition,
                                gCodeFileToDraw.GetFilamentDiameter(),
                                layerThickness,
                                extrusionColor,
                                this.Gray));
                    }
                    else
                    {
                        renderFeaturesForLayer.Add(
                            new RenderFeatureTravel(
                                previousInstruction.Position,
                                currentInstruction.Position,
                                currentInstruction.ExtruderIndex,
                                currentInstruction.FeedRate));
                    }
                }
            }
        }
		public ColorGradientWidget(GCodeFile gcodeFileTest)
			: base(FlowDirection.TopToBottom)
		{
			BackgroundColor = new RGBA_Bytes(0, 0, 0, 120);

			HashSet<float> speeds = new HashSet<float>();
			PrinterMachineInstruction previousInstruction = gcodeFileTest.Instruction(0);
			for (int i = 1; i < gcodeFileTest.LineCount; i++)
			{
				PrinterMachineInstruction instruction = gcodeFileTest.Instruction(i);
				if (instruction.EPosition > previousInstruction.EPosition && (instruction.Line.IndexOf('X') != -1 || instruction.Line.IndexOf('Y') != -1))
				{
					speeds.Add((float)instruction.FeedRate);
				}
				previousInstruction = instruction;
			}

			ExtrusionColors extrusionColors = new ExtrusionColors();

			speeds.Select(speed => extrusionColors.GetColorForSpeed(speed)).ToArray();

			if(speeds.Count <= 0)
			{
				// There are no paths so don't generate the rest of the widget.
				return;
			}

			float min = speeds.Min();
			float max = speeds.Max();
			int maxItems = Math.Min(7, speeds.Count());

			int count = maxItems - 1;
			float increment = (max - min) / count;
			int index = 0;

			int[] rangeValues;
			if (speeds.Count < 8)
			{
				rangeValues = speeds.Select(s => (int)s).OrderBy(i => i).ToArray();
			}
			else
			{
				rangeValues = Enumerable.Range(0, maxItems).Select(x => (int)(min + increment * index++)).ToArray();
			}

			RGBA_Bytes[] speedColors = rangeValues.OrderBy(s => s).Select(speed => extrusionColors.GetColorForSpeed(speed)).ToArray();

			for (int i = 0; i < speedColors.Length; i++)
			{
				RGBA_Bytes color = speedColors[i];
				int speed = rangeValues[i];

				GuiWidget colorWidget = new GuiWidget();
				colorWidget.Width = 20;
				colorWidget.Height = 20;
				colorWidget.BackgroundColor = color;
				colorWidget.Margin = new BorderDouble(2);
				double feedRateToMMPerSecond = speed / 60;

				ColorToSpeedWidget colorToSpeedWidget = new ColorToSpeedWidget(colorWidget, feedRateToMMPerSecond);
				this.AddChild(colorToSpeedWidget);
			}

			Margin = new BorderDouble(5, 5, 200, 50);
			HAnchor |= Agg.UI.HAnchor.ParentLeft;
			VAnchor = Agg.UI.VAnchor.ParentTop;
		}
Beispiel #3
0
        void CreateFeaturesForLayerIfRequired(int layerToCreate)
        {
            if (extrusionColors == null)
            {
                extrusionColors = new ExtrusionColors();
                for (int layerIndex = 0; layerIndex < gCodeFileToDraw.NumChangesInZ; layerIndex++)
                {
                    for (int i = 1; i < gCodeFileToDraw.Count; i++)
                    {
                        PrinterMachineInstruction prevInstruction = gCodeFileToDraw.Instruction(i-1);
                        PrinterMachineInstruction instruction = gCodeFileToDraw.Instruction(i);
                        if (instruction.EPosition > prevInstruction.EPosition)
                        {
                            extrusionColors.GetColorForSpeed((float)instruction.FeedRate);
                        }
                    }
                }
            }

            if (renderFeatures[layerToCreate].Count > 0)
            {
                return;
            }

            List<RenderFeatureBase> renderFeaturesForLayer = renderFeatures[layerToCreate];

            int startRenderIndex = gCodeFileToDraw.IndexOfChangeInZ[layerToCreate];
            int endRenderIndex = gCodeFileToDraw.Count - 1;
            if (layerToCreate < gCodeFileToDraw.IndexOfChangeInZ.Count - 1)
            {
                endRenderIndex = gCodeFileToDraw.IndexOfChangeInZ[layerToCreate + 1];
            }

            for (int i = startRenderIndex; i < endRenderIndex; i++ )
            {
                PrinterMachineInstruction currentInstruction = gCodeFileToDraw.Instruction(i);
                PrinterMachineInstruction previousInstruction = currentInstruction;
                if (i > 0)
                {
                    previousInstruction = gCodeFileToDraw.Instruction(i - 1);
                }

                if (currentInstruction.Position == previousInstruction.Position)
                {
                    if (Math.Abs(currentInstruction.EPosition - previousInstruction.EPosition) > 0)
                    {
                        // this is a retraction
                        renderFeaturesForLayer.Add(new RenderFeatureRetract(currentInstruction.Position, currentInstruction.EPosition - previousInstruction.EPosition, currentInstruction.FeedRate));
                    }
                    if (currentInstruction.Line.StartsWith("G10"))
                    {
                        renderFeaturesForLayer.Add(new RenderFeatureRetract(currentInstruction.Position, -1, currentInstruction.FeedRate));
                    }
                    else if (currentInstruction.Line.StartsWith("G11"))
                    {
                        renderFeaturesForLayer.Add(new RenderFeatureRetract(currentInstruction.Position, 1, currentInstruction.FeedRate));
                    }
                }
                else
                {
                    if (gCodeFileToDraw.IsExtruding(i))
                    {
                        double layerThickness = gCodeFileToDraw.GetLayerHeight();
                        if (layerToCreate == 0)
                        {
                            layerThickness = gCodeFileToDraw.GetFirstLayerHeight();
                        }
                        renderFeaturesForLayer.Add(new RenderFeatureExtrusion(previousInstruction.Position, currentInstruction.Position, currentInstruction.FeedRate, currentInstruction.EPosition - previousInstruction.EPosition, gCodeFileToDraw.GetFilamentDiamter(), layerThickness, extrusionColors.GetColorForSpeed((float)currentInstruction.FeedRate)));
                    }
                    else
                    {
                        renderFeaturesForLayer.Add(new RenderFeatureTravel(previousInstruction.Position, currentInstruction.Position, currentInstruction.FeedRate));
                    }
                }
            }

            TotalRenderFeatures += renderFeaturesForLayer.Count;
        }
        public void CreateFeaturesForLayerIfRequired(int layerToCreate)
        {
            if (extrusionColors == null &&
                gCodeFileToDraw != null &&
                gCodeFileToDraw.LineCount > 0)
            {
                extrusionColors = new ExtrusionColors();
                HashSet <float>           speeds          = new HashSet <float>();
                PrinterMachineInstruction prevInstruction = gCodeFileToDraw.Instruction(0);
                for (int i = 1; i < gCodeFileToDraw.LineCount; i++)
                {
                    PrinterMachineInstruction instruction = gCodeFileToDraw.Instruction(i);
                    if (instruction.EPosition > prevInstruction.EPosition && (instruction.Line.IndexOf('X') != -1 || instruction.Line.IndexOf('Y') != -1))
                    {
                        speeds.Add((float)instruction.FeedRate);
                    }

                    prevInstruction = instruction;
                }

                foreach (float speed in speeds)
                {
                    extrusionColors.GetColorForSpeed(speed);
                }
            }

            if (renderFeatures.Count == 0 ||
                renderFeatures[layerToCreate].Count > 0)
            {
                return;
            }

            List <RenderFeatureBase> renderFeaturesForLayer = renderFeatures[layerToCreate];

            int startRenderIndex = gCodeFileToDraw.GetInstructionIndexAtLayer(layerToCreate);
            int endRenderIndex   = gCodeFileToDraw.LineCount - 1;

            if (layerToCreate < gCodeFileToDraw.NumChangesInZ - 1)
            {
                endRenderIndex = gCodeFileToDraw.GetInstructionIndexAtLayer(layerToCreate + 1);
            }

            for (int instructionIndex = startRenderIndex; instructionIndex < endRenderIndex; instructionIndex++)
            {
                PrinterMachineInstruction currentInstruction  = gCodeFileToDraw.Instruction(instructionIndex);
                PrinterMachineInstruction previousInstruction = currentInstruction;
                if (instructionIndex > 0)
                {
                    previousInstruction = gCodeFileToDraw.Instruction(instructionIndex - 1);
                }

                if (currentInstruction.Position == previousInstruction.Position)
                {
                    if (Math.Abs(currentInstruction.EPosition - previousInstruction.EPosition) > 0)
                    {
                        // this is a retraction
                        renderFeaturesForLayer.Add(new RenderFeatureRetract(currentInstruction.Position, currentInstruction.EPosition - previousInstruction.EPosition, currentInstruction.ExtruderIndex, currentInstruction.FeedRate));
                    }
                    if (currentInstruction.Line.StartsWith("G10"))
                    {
                        renderFeaturesForLayer.Add(new RenderFeatureRetract(currentInstruction.Position, -1, currentInstruction.ExtruderIndex, currentInstruction.FeedRate));
                    }
                    else if (currentInstruction.Line.StartsWith("G11"))
                    {
                        renderFeaturesForLayer.Add(new RenderFeatureRetract(currentInstruction.Position, 1, currentInstruction.ExtruderIndex, currentInstruction.FeedRate));
                    }
                }
                else
                {
                    if (gCodeFileToDraw.IsExtruding(instructionIndex))
                    {
                        double layerThickness = gCodeFileToDraw.GetLayerHeight();
                        if (layerToCreate == 0)
                        {
                            layerThickness = gCodeFileToDraw.GetFirstLayerHeight();
                        }

                        Color extrusionColor = extrusionColors.GetColorForSpeed((float)currentInstruction.FeedRate);
                        renderFeaturesForLayer.Add(new RenderFeatureExtrusion(previousInstruction.Position, currentInstruction.Position, currentInstruction.ExtruderIndex, currentInstruction.FeedRate, currentInstruction.EPosition - previousInstruction.EPosition, gCodeFileToDraw.GetFilamentDiameter(), layerThickness, extrusionColor));
                    }
                    else
                    {
                        renderFeaturesForLayer.Add(new RenderFeatureTravel(previousInstruction.Position, currentInstruction.Position, currentInstruction.ExtruderIndex, currentInstruction.FeedRate));
                    }
                }
            }
        }
Beispiel #5
0
		public void CreateFeaturesForLayerIfRequired(int layerToCreate)
		{
			if (extrusionColors == null
				&& gCodeFileToDraw != null
				&& gCodeFileToDraw.LineCount > 0)
			{
				extrusionColors = new ExtrusionColors();
				HashSet<float> speeds = new HashSet<float>();
				PrinterMachineInstruction prevInstruction = gCodeFileToDraw.Instruction(0);
				for (int i = 1; i < gCodeFileToDraw.LineCount; i++)
				{
					PrinterMachineInstruction instruction = gCodeFileToDraw.Instruction(i);
					if (instruction.EPosition > prevInstruction.EPosition && (instruction.Line.IndexOf('X') != -1 || instruction.Line.IndexOf('Y') != -1))
					{
						speeds.Add((float)instruction.FeedRate);
					}

					prevInstruction = instruction;
				}

				foreach (float speed in speeds)
				{
					extrusionColors.GetColorForSpeed(speed);
				}
			}

			if (renderFeatures.Count == 0
				|| renderFeatures[layerToCreate].Count > 0)
			{
				return;
			}

			List<RenderFeatureBase> renderFeaturesForLayer = renderFeatures[layerToCreate];

			int startRenderIndex = gCodeFileToDraw.GetInstructionIndexAtLayer(layerToCreate);
			int endRenderIndex = gCodeFileToDraw.LineCount - 1;
			if (layerToCreate < gCodeFileToDraw.NumChangesInZ - 1)
			{
				endRenderIndex = gCodeFileToDraw.GetInstructionIndexAtLayer(layerToCreate + 1);
			}

			for (int instructionIndex = startRenderIndex; instructionIndex < endRenderIndex; instructionIndex++)
			{
				PrinterMachineInstruction currentInstruction = gCodeFileToDraw.Instruction(instructionIndex);
				PrinterMachineInstruction previousInstruction = currentInstruction;
				if (instructionIndex > 0)
				{
					previousInstruction = gCodeFileToDraw.Instruction(instructionIndex - 1);
				}

				if (currentInstruction.Position == previousInstruction.Position)
				{
					if (Math.Abs(currentInstruction.EPosition - previousInstruction.EPosition) > 0)
					{
						// this is a retraction
						renderFeaturesForLayer.Add(new RenderFeatureRetract(currentInstruction.Position, currentInstruction.EPosition - previousInstruction.EPosition, currentInstruction.ExtruderIndex, currentInstruction.FeedRate));
					}
					if (currentInstruction.Line.StartsWith("G10"))
					{
						renderFeaturesForLayer.Add(new RenderFeatureRetract(currentInstruction.Position, -1, currentInstruction.ExtruderIndex, currentInstruction.FeedRate));
					}
					else if (currentInstruction.Line.StartsWith("G11"))
					{
						renderFeaturesForLayer.Add(new RenderFeatureRetract(currentInstruction.Position, 1, currentInstruction.ExtruderIndex, currentInstruction.FeedRate));
					}
				}
				else
				{
					if (gCodeFileToDraw.IsExtruding(instructionIndex))
					{
						double layerThickness = gCodeFileToDraw.GetLayerHeight();
						if (layerToCreate == 0)
						{
							layerThickness = gCodeFileToDraw.GetFirstLayerHeight();
						}

                        RGBA_Bytes extrusionColor = extrusionColors.GetColorForSpeed((float)currentInstruction.FeedRate);
                        renderFeaturesForLayer.Add(new RenderFeatureExtrusion(previousInstruction.Position, currentInstruction.Position, currentInstruction.ExtruderIndex, currentInstruction.FeedRate, currentInstruction.EPosition - previousInstruction.EPosition, gCodeFileToDraw.GetFilamentDiameter(), layerThickness, extrusionColor));
					}
					else
					{
						renderFeaturesForLayer.Add(new RenderFeatureTravel(previousInstruction.Position, currentInstruction.Position, currentInstruction.ExtruderIndex, currentInstruction.FeedRate));
					}
				}
			}
		}
        public void CreateFeaturesForLayerIfRequired(int layerToCreate)
        {
            if (all.layers.Count == 0 ||
                all.layers[layerToCreate].features.Count > 0)
            {
                return;
            }

            List <RenderFeatureBase> renderFeaturesForLayer = all.layers[layerToCreate].features;

            int startRenderIndex = gCodeFileToDraw.GetFirstLayerInstruction(layerToCreate);
            int endRenderIndex   = gCodeFileToDraw.LineCount - 1;

            if (layerToCreate < gCodeFileToDraw.LayerCount - 1)
            {
                endRenderIndex = gCodeFileToDraw.GetFirstLayerInstruction(layerToCreate + 1);
            }

            for (int instructionIndex = startRenderIndex; instructionIndex < endRenderIndex; instructionIndex++)
            {
                PrinterMachineInstruction currentInstruction  = gCodeFileToDraw.Instruction(instructionIndex);
                PrinterMachineInstruction previousInstruction = currentInstruction;
                if (instructionIndex > 0)
                {
                    previousInstruction = gCodeFileToDraw.Instruction(instructionIndex - 1);
                }

                if (currentInstruction.Position == previousInstruction.Position)
                {
                    double eMovement = 0;
                    if (currentInstruction.PositionSet != PositionSet.E)
                    {
                        eMovement = currentInstruction.EPosition - previousInstruction.EPosition;
                    }

                    if (Math.Abs(eMovement) > 0)
                    {
                        // this is a retraction
                        renderFeaturesForLayer.Add(new RenderFeatureRetract(instructionIndex, currentInstruction.Position, eMovement, currentInstruction.ToolIndex, currentInstruction.FeedRate));
                    }

                    if (currentInstruction.Line.StartsWith("G10"))
                    {
                        renderFeaturesForLayer.Add(new RenderFeatureRetract(instructionIndex, currentInstruction.Position, -1, currentInstruction.ToolIndex, currentInstruction.FeedRate));
                    }
                    else if (currentInstruction.Line.StartsWith("G11"))
                    {
                        renderFeaturesForLayer.Add(new RenderFeatureRetract(instructionIndex, currentInstruction.Position, 1, currentInstruction.ToolIndex, currentInstruction.FeedRate));
                    }
                }
                else
                {
                    var extrusionAmount    = currentInstruction.EPosition - previousInstruction.EPosition;
                    var filamentDiameterMm = gCodeFileToDraw.GetFilamentDiameter();

                    if (gCodeFileToDraw.IsExtruding(instructionIndex))
                    {
                        double layerThickness = gCodeFileToDraw.GetLayerHeight(layerToCreate);

                        Color extrusionColor = ExtrusionColors.GetColorForSpeed((float)currentInstruction.FeedRate);
                        renderFeaturesForLayer.Add(
                            new RenderFeatureExtrusion(
                                instructionIndex,
                                previousInstruction.Position,
                                currentInstruction.Position,
                                currentInstruction.ToolIndex,
                                currentInstruction.FeedRate,
                                extrusionAmount,
                                filamentDiameterMm,
                                layerThickness,
                                extrusionColor,
                                this.Gray));
                    }
                    else
                    {
                        if (extrusionAmount < 0)
                        {
                            double moveLength     = (currentInstruction.Position - previousInstruction.Position).Length;
                            double filamentRadius = filamentDiameterMm / 2;
                            double areaSquareMm   = (filamentRadius * filamentRadius) * Math.PI;

                            var extrusionVolumeMm3 = (float)(areaSquareMm * extrusionAmount);
                            var area = extrusionVolumeMm3 / moveLength;
                        }

                        renderFeaturesForLayer.Add(
                            new RenderFeatureTravel(
                                instructionIndex,
                                previousInstruction.Position,
                                currentInstruction.Position,
                                currentInstruction.ToolIndex,
                                currentInstruction.FeedRate,
                                extrusionAmount < 0));
                    }
                }
            }
        }