Color Gradient almost complete just need to modify visibility bashed on speed checkbox state

This commit is contained in:
Gregory Diaz 2015-05-04 13:34:13 -07:00
parent 567899e0c6
commit cd9c2e8cbd
2 changed files with 65 additions and 38 deletions

View file

@ -2,8 +2,11 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading.Tasks;
using MatterHackers.Agg;
using MatterHackers.MatterControl.PrintQueue;
using MatterHackers.GCodeVisualizer;
using MatterHackers.Agg.UI;
using MatterHackers.MeshVisualizer;
using MatterHackers.VectorMath;
@ -15,61 +18,86 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
public class ColorGradientWidget : FlowLayoutWidget
{
private List<ColorToSpeedWidget> allColorToSpeedWidgets;
public ColorGradientWidget()
public ColorGradientWidget(GCodeFile gcodeFileTest)
: base(FlowDirection.TopToBottom)
{
VAnchor = VAnchor.FitToChildren;
BackgroundColor = new RGBA_Bytes(0, 0, 0, 120);
ColorToSpeedWidget blue = new ColorToSpeedWidget("blue.png", "BLUE");
ColorToSpeedWidget red = new ColorToSpeedWidget("red.png", "RED");
ColorToSpeedWidget teal = new ColorToSpeedWidget("teal.png", "TEAL");
ColorToSpeedWidget yellow = new ColorToSpeedWidget("yellow.png", "YELLOW");
ColorToSpeedWidget green = new ColorToSpeedWidget("green.png", "GREEN");
ColorToSpeedWidget orange = new ColorToSpeedWidget("orange.png", "ORANGE");
ColorToSpeedWidget lightBlue = new ColorToSpeedWidget("lightblue.png", "LIGHT-BLUE");
this.AddChild(blue);
this.AddChild(red);
this.AddChild(teal);
this.AddChild(yellow);
this.AddChild(green);
this.AddChild(orange);
this.AddChild(lightBlue);
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)
{
speeds.Add((float)instruction.FeedRate);
}
previousInstruction = instruction;
}
Margin = new BorderDouble(top:50, left: 5, right: 530);
ExtrusionColors extrusionColors = new ExtrusionColors();
}
speeds.Select(speed => extrusionColors.GetColorForSpeed(speed)).ToArray();
float[] orderedSpeeds = speeds.OrderByDescending(speed => speed).ToArray();
float slow = orderedSpeeds.Last();
float fast = orderedSpeeds.First();
float range = fast - slow;
int count = 6;
float increment = (fast - slow) / count;
int index = 0;
int[] rangeValues = Enumerable.Range(0, 7).Select(x => (int)(slow + increment * index++)).ToArray();
RGBA_Bytes[] speedColors = rangeValues.OrderBy(s => s).Select(speed => extrusionColors.GetColorForSpeed(speed)).ToArray();
for (int i = 0; i < speedColors.Length; i++)
{
var color = speedColors[i];
var speed = rangeValues[i];
GuiWidget colorWidget = new GuiWidget();
colorWidget.Width = 20;
colorWidget.Height = 20;
colorWidget.BackgroundColor = color;
colorWidget.Margin = new BorderDouble(2);
ColorToSpeedWidget test = new ColorToSpeedWidget(colorWidget, speed.ToString());
this.AddChild(test);
}
Margin = new BorderDouble(5, 5, 200, 50);
HAnchor |= Agg.UI.HAnchor.ParentLeft;
VAnchor = Agg.UI.VAnchor.ParentTop;
}
public class ColorToSpeedWidget : FlowLayoutWidget
{
public ColorToSpeedWidget(String imageFileName, String layerSpeed)
public GuiWidget speedColor;
public string layerSpeed;
public ColorToSpeedWidget(GuiWidget colorWidget, String speed)
: base(FlowDirection.LeftToRight)
{
Margin = new BorderDouble(2);
Agg.Image.ImageBuffer color = StaticData.Instance.LoadIcon(Path.Combine("ColorGradient", imageFileName));
ImageWidget colorWidget = new ImageWidget(color);
colorWidget.Margin = new BorderDouble(left:2);
speedColor = colorWidget;
layerSpeed = speed + " mm\\s";
colorWidget.Margin = new BorderDouble(left: 2);
TextWidget speedTextBox = new TextWidget(layerSpeed, pointSize: 12);
speedTextBox.TextColor = RGBA_Bytes.White;
speedTextBox.VAnchor = VAnchor.ParentCenter;
speedTextBox.Margin = new BorderDouble(left: 2);
this.AddChild(colorWidget);
this.AddChild(speedTextBox);
}
}
}

View file

@ -259,11 +259,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
viewControls2D = new ViewControls2D();
AddChild(viewControls2D);
gradient = new ColorGradientWidget();
gradient.VAnchor = Agg.UI.VAnchor.ParentTop;
gradient.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
AddChild(gradient);
viewControls3D = new ViewControls3D(meshViewerWidget);
viewControls3D.PartSelectVisible = false;
AddChild(viewControls3D);
@ -927,6 +922,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
layerRenderRatioSlider.SecondValueChanged += new EventHandler(layerEndRenderRatioSlider_ValueChanged);
AddChild(layerRenderRatioSlider);
CloseIfNotNull(gradient);
gradient = new ColorGradientWidget(gcodeViewWidget.LoadedGCode);
AddChild(gradient);
SetSliderSizes();
// let's change the active layer so that it is set to the first layer with data