Revise layer indicators

This commit is contained in:
John Lewin 2017-07-07 16:50:47 -07:00
parent 3c4f449059
commit 0ce412c8d5
2 changed files with 58 additions and 34 deletions

View file

@ -40,10 +40,10 @@ namespace MatterHackers.MatterControl.CustomWidgets
private TextWidget numberDisplay; private TextWidget numberDisplay;
private NumberEdit numberEdit; private NumberEdit numberEdit;
public ValueDisplayInfo() public ValueDisplayInfo(string defaultSizeString = "-0000.00", Agg.Font.Justification justification = Agg.Font.Justification.Left)
{ {
double pointSize = 12; double pointSize = 12;
numberDisplay = new TextWidget("-0000.00", 0, 0, pointSize) numberDisplay = new TextWidget(defaultSizeString, 0, 0, pointSize, justification: justification)
{ {
VAnchor = VAnchor.ParentBottom, VAnchor = VAnchor.ParentBottom,
HAnchor = HAnchor.ParentLeft, HAnchor = HAnchor.ParentLeft,

View file

@ -27,18 +27,18 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project. either expressed or implied, of the FreeBSD Project.
*/ */
using System;
using MatterHackers.Agg; using MatterHackers.Agg;
using MatterHackers.Agg.UI; using MatterHackers.Agg.UI;
using MatterHackers.GCodeVisualizer;
using MatterHackers.Localizations; using MatterHackers.Localizations;
using MatterHackers.MatterControl.CustomWidgets; using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.PrinterControls;
using MatterHackers.MatterControl.PrintQueue; using MatterHackers.MatterControl.PrintQueue;
using MatterHackers.MatterControl.SlicerConfiguration; using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.MeshVisualizer; using MatterHackers.MeshVisualizer;
using MatterHackers.VectorMath; using MatterHackers.VectorMath;
using System;
using MatterHackers.MatterControl.PrinterControls;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.GCodeVisualizer;
namespace MatterHackers.MatterControl.PartPreviewWindow namespace MatterHackers.MatterControl.PartPreviewWindow
{ {
@ -56,6 +56,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
private View3DConfig gcodeOptions; private View3DConfig gcodeOptions;
private GuiWidget view3DContainer; private GuiWidget view3DContainer;
private TextWidget layerCountText;
private TextWidget layerStartText;
private ValueDisplayInfo currentLayerInfo;
public PrinterTabPage(PrinterSettings activeSettings, PrintItemWrapper printItem) public PrinterTabPage(PrinterSettings activeSettings, PrintItemWrapper printItem)
{ {
printer = ApplicationController.Instance.Printer; printer = ApplicationController.Instance.Printer;
@ -98,6 +103,18 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
int sliderWidth = (UserSettings.Instance.IsTouchScreen) ? 20 : 10; int sliderWidth = (UserSettings.Instance.IsTouchScreen) ? 20 : 10;
layerCountText = new TextWidget("", pointSize: 9, textColor: ActiveTheme.Instance.PrimaryTextColor)
{
Visible = false,
AutoExpandBoundsToText = true
};
layerStartText = new TextWidget("1", pointSize: 9, textColor: ActiveTheme.Instance.PrimaryTextColor)
{
Visible = false,
AutoExpandBoundsToText = true
};
selectLayerSlider = new SolidSlider(new Vector2(), sliderWidth, 0, 1, Orientation.Vertical); selectLayerSlider = new SolidSlider(new Vector2(), sliderWidth, 0, 1, Orientation.Vertical);
selectLayerSlider.ValueChanged += (s, e) => selectLayerSlider.ValueChanged += (s, e) =>
{ {
@ -127,7 +144,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
printer.BedPlate.RenderInfo.FeatureToStartOnRatio0To1 = layerRenderRatioSlider.FirstValue; printer.BedPlate.RenderInfo.FeatureToStartOnRatio0To1 = layerRenderRatioSlider.FirstValue;
printer.BedPlate.RenderInfo.FeatureToEndOnRatio0To1 = layerRenderRatioSlider.SecondValue; printer.BedPlate.RenderInfo.FeatureToEndOnRatio0To1 = layerRenderRatioSlider.SecondValue;
this.Invalidate(); this.Invalidate();
}; };
@ -183,38 +199,22 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
view3DContainer.AddChild(gcodeViewer); view3DContainer.AddChild(gcodeViewer);
view3DContainer.AddChild(layerRenderRatioSlider); view3DContainer.AddChild(layerRenderRatioSlider);
view3DContainer.AddChild(selectLayerSlider); view3DContainer.AddChild(selectLayerSlider);
view3DContainer.AddChild(layerCountText);
view3DContainer.AddChild(layerStartText);
ValueDisplayInfo currentLayerInfo = new ValueDisplayInfo() //currentLayerInfo = new ValueDisplayInfo("1000", Agg.Font.Justification.Right)
currentLayerInfo = new ValueDisplayInfo("1000")
{ {
GetDisplayString = (value) => $"{value + 1}/{printer?.BedPlate?.LoadedGCode?.LayerCount}" GetDisplayString = (value) => $"{value + 1}"
}; };
currentLayerInfo.EditComplete += (s, e) => currentLayerInfo.EditComplete += (s, e) =>
{ {
printer.BedPlate.ActiveLayerIndex = (int)currentLayerInfo.Value; printer.BedPlate.ActiveLayerIndex = (int)currentLayerInfo.Value - 1;
}; };
printer.BedPlate.ActiveLayerChanged += (s, e) => printer.BedPlate.ActiveLayerChanged += SetPositionAndValue;
{ selectLayerSlider.MouseEnter += SetPositionAndValue;
UiThread.RunOnIdle(() =>
{
currentLayerInfo.Value = printer.BedPlate.ActiveLayerIndex;
currentLayerInfo.OriginRelativeParent = selectLayerSlider.OriginRelativeParent
+ new Vector2(-currentLayerInfo.Width, selectLayerSlider.PositionPixelsFromFirstValue - currentLayerInfo.Height / 2);
currentLayerInfo.Visible = true;
});
};
selectLayerSlider.MouseEnter += (s, e) =>
{
UiThread.RunOnIdle(() =>
{
currentLayerInfo.Value = printer.BedPlate.ActiveLayerIndex;
currentLayerInfo.OriginRelativeParent = selectLayerSlider.OriginRelativeParent
+ new Vector2(-currentLayerInfo.Width, selectLayerSlider.PositionPixelsFromFirstValue - currentLayerInfo.Height / 2);
currentLayerInfo.Visible = true;
});
};
currentLayerInfo.Visible = false; currentLayerInfo.Visible = false;
@ -250,10 +250,27 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
this.AnchorAll(); this.AnchorAll();
} }
private void SetPositionAndValue(object sender, EventArgs e)
{
UiThread.RunOnIdle(() =>
{
currentLayerInfo.Value = printer.BedPlate.ActiveLayerIndex;
//currentLayerInfo.DebugShowBounds = true;
currentLayerInfo.OriginRelativeParent = selectLayerSlider.OriginRelativeParent
+ new Vector2(-currentLayerInfo.Width - 10, selectLayerSlider.PositionPixelsFromFirstValue - currentLayerInfo.Height / 2);
currentLayerInfo.Visible = true;
});
}
private void BedPlate_LoadedGCodeChanged(object sender, EventArgs e) private void BedPlate_LoadedGCodeChanged(object sender, EventArgs e)
{ {
selectLayerSlider.Maximum = printer.BedPlate.LoadedGCode.LayerCount - 1; var layerCount = printer.BedPlate.LoadedGCode.LayerCount;
selectLayerSlider.Maximum = layerCount - 1;
layerCountText.Text = layerCount.ToString();
layerCountText.Visible = true;
layerStartText.Visible = true;
// ResetRenderInfo // ResetRenderInfo
printer.BedPlate.RenderInfo = new GCodeRenderInfo( printer.BedPlate.RenderInfo = new GCodeRenderInfo(
0, 0,
@ -441,6 +458,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
printer.BedPlate.ActiveLayerChanged -= ActiveLayer_Changed; printer.BedPlate.ActiveLayerChanged -= ActiveLayer_Changed;
printer.BedPlate.LoadedGCodeChanged -= BedPlate_LoadedGCodeChanged; printer.BedPlate.LoadedGCodeChanged -= BedPlate_LoadedGCodeChanged;
printer.BedPlate.ActiveLayerChanged -= SetPositionAndValue;
selectLayerSlider.MouseEnter -= SetPositionAndValue;
base.OnClosed(e); base.OnClosed(e);
} }
@ -554,6 +574,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
return popupContainer; return popupContainer;
} }
private void SetSyncToPrintVisibility() private void SetSyncToPrintVisibility()
{ {
bool printerIsRunningPrint = PrinterConnection.Instance.PrinterIsPaused || PrinterConnection.Instance.PrinterIsPrinting; bool printerIsRunningPrint = PrinterConnection.Instance.PrinterIsPaused || PrinterConnection.Instance.PrinterIsPrinting;
@ -590,10 +611,13 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
} }
selectLayerSlider.OriginRelativeParent = new Vector2(modelViewer.Width - 20, 78); selectLayerSlider.OriginRelativeParent = new Vector2(modelViewer.Width - 20, 78);
selectLayerSlider.TotalWidthInPixels = modelViewer.Height - 85; selectLayerSlider.TotalWidthInPixels = modelViewer.Height - 100;
layerRenderRatioSlider.OriginRelativeParent = new Vector2(11, 65); layerRenderRatioSlider.OriginRelativeParent = new Vector2(11, 65);
layerRenderRatioSlider.TotalWidthInPixels = modelViewer.Width - 45; layerRenderRatioSlider.TotalWidthInPixels = modelViewer.Width - 45;
layerCountText.OriginRelativeParent = new Vector2(modelViewer.Width - 26 + (layerCountText.Width / 2), modelViewer.Height - 15);
layerStartText.OriginRelativeParent = new Vector2(modelViewer.Width - 26 + (layerStartText.Width / 2), 63);
} }
private void SetAnimationPosition() private void SetAnimationPosition()
{ {