Color Gradient Widget (complete)
This commit is contained in:
parent
1715dd953b
commit
0cddaaad10
1 changed files with 23 additions and 11 deletions
|
|
@ -12,6 +12,7 @@ using MatterHackers.MeshVisualizer;
|
|||
using MatterHackers.VectorMath;
|
||||
using System.IO;
|
||||
using MatterHackers.Agg.PlatformAbstract;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||
{
|
||||
|
|
@ -19,6 +20,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
public class ColorGradientWidget : FlowLayoutWidget
|
||||
{
|
||||
|
||||
Regex regex = new Regex("[XY]\\d+");
|
||||
|
||||
public ColorGradientWidget(GCodeFile gcodeFileTest)
|
||||
: base(FlowDirection.TopToBottom)
|
||||
{
|
||||
|
|
@ -30,7 +33,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
for (int i = 1; i < gcodeFileTest.LineCount; i++)
|
||||
{
|
||||
PrinterMachineInstruction instruction = gcodeFileTest.Instruction(i);
|
||||
if(instruction.EPosition > previousInstruction.EPosition)
|
||||
if(instruction.EPosition > previousInstruction.EPosition && regex.Match(instruction.Line).Success)
|
||||
{
|
||||
speeds.Add((float)instruction.FeedRate);
|
||||
}
|
||||
|
|
@ -41,30 +44,39 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
|
||||
speeds.Select(speed => extrusionColors.GetColorForSpeed(speed)).ToArray();
|
||||
|
||||
float[] orderedSpeeds = speeds.OrderByDescending(speed => speed).ToArray();
|
||||
float min = speeds.Min();
|
||||
float max = speeds.Max();
|
||||
int maxItems = Math.Min(7, speeds.Count());
|
||||
|
||||
float slow = orderedSpeeds.Last();
|
||||
float fast = orderedSpeeds.First();
|
||||
float range = fast - slow;
|
||||
int count = 6;
|
||||
float increment = (fast - slow) / count;
|
||||
int count = maxItems - 1;
|
||||
float increment = (max - min) / count;
|
||||
int index = 0;
|
||||
|
||||
int[] rangeValues = Enumerable.Range(0, 7).Select(x => (int)(slow + increment * index++)).ToArray();
|
||||
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++)
|
||||
{
|
||||
var color = speedColors[i];
|
||||
var speed = rangeValues[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);
|
||||
float feedRateToMMPerSecond = speed / 60;
|
||||
|
||||
ColorToSpeedWidget colorToSpeedWidget = new ColorToSpeedWidget(colorWidget, speed.ToString());
|
||||
ColorToSpeedWidget colorToSpeedWidget = new ColorToSpeedWidget(colorWidget, feedRateToMMPerSecond.ToString());
|
||||
this.AddChild(colorToSpeedWidget);
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue