Revise auto switch to GCode animation

- Issue MatterHackers/MCCentral#4534
This commit is contained in:
John Lewin 2018-11-08 08:13:08 -08:00
parent 486c31c862
commit 41bd4965f8
6 changed files with 97 additions and 30 deletions

View file

@ -778,12 +778,16 @@ namespace MatterHackers.MatterControl
{
if (viewMode != value)
{
// Capture before/after state
var eventArgs = new ViewModeChangedEventArgs()
{
ViewMode = value,
PreviousMode = viewMode
};
viewMode = value;
ViewModeChanged?.Invoke(this, new ViewModeChangedEventArgs()
{
ViewMode = this.ViewMode
});
this.ViewModeChanged?.Invoke(this, eventArgs);
}
}
}

View file

@ -537,17 +537,21 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
bottomRow.Name = printer.Bed.EditContext.GCodeFilePath;
}
await ApplicationController.Instance.Tasks.Execute("Saving".Localize(), printer.Bed.SaveChanges);
// start up a new slice on a backgroud thread
// start up a new slice on a background thread
await ApplicationController.Instance.SliceItemLoadOutput(
printer,
printer.Bed.Scene,
printer.Bed.EditContext.GCodeFilePath);
// Switch to the 3D layer view if on Model view
if (printer.ViewState.ViewMode == PartViewMode.Model)
{
printer.ViewState.ViewMode = PartViewMode.Layers3D;
}
// when it is done queue it to the change to gcode stream
var message2 = "Would you like to switch to the new G-Code? Before you switch, check that your are seeing the changes you expect.".Localize();
var caption2 = "Switch to new G-Code?".Localize();

View file

@ -70,6 +70,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
ActionArea.AddChild(childToAdd, indexInChildrenList);
}
public void AddChildDirect(GuiWidget guiWidget)
{
base.AddChild(guiWidget);
}
}
public class ToolbarSeparator : VerticalLine

View file

@ -60,6 +60,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
internal RadioIconButton layers3DButton;
internal RadioIconButton modelViewButton;
private Dictionary<PartViewMode, RadioIconButton> viewModes = new Dictionary<PartViewMode, RadioIconButton>();
public PrinterActionsBar(PrinterConfig printer, PrinterTabPage printerTabPage, ThemeConfig theme)
: base(theme)
{
@ -120,6 +122,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
buttonGroupB.Add(modelViewButton);
AddChild(modelViewButton);
viewModes.Add(PartViewMode.Model, modelViewButton);
iconPath = Path.Combine("ViewTransformControls", "gcode_3d.png");
layers3DButton = new RadioIconButton(AggContext.StaticData.LoadIcon(iconPath, 16, 16, theme.InvertIcons), theme)
{
@ -132,6 +136,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
layers3DButton.Click += SwitchModes_Click;
buttonGroupB.Add(layers3DButton);
viewModes.Add(PartViewMode.Layers3D, layers3DButton);
if (!UserSettings.Instance.IsTouchScreen)
{
this.AddChild(layers3DButton);
@ -150,6 +156,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
buttonGroupB.Add(layers2DButton);
this.AddChild(layers2DButton);
viewModes.Add(PartViewMode.Layers2D, layers2DButton);
this.AddChild(new HorizontalSpacer());
bool shareTemp = printer.Settings.GetValue<bool>(SettingsKey.extruders_share_temperature);
@ -179,28 +187,19 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
printer.ViewState.ViewModeChanged += (s, e) =>
{
RadioIconButton activeButton = null;
if (e.ViewMode == PartViewMode.Layers2D)
if (viewModes[e.ViewMode] is RadioIconButton activeButton
&& viewModes[e.PreviousMode] is RadioIconButton previousButton
&& !buttonIsBeingClicked)
{
activeButton = layers2DButton;
}
else if (e.ViewMode == PartViewMode.Layers3D)
{
activeButton = layers3DButton;
}
else
{
activeButton = modelViewButton;
}
if(activeButton != null)
{
activeButton.Checked = true;
if (!buttonIsBeingClicked)
{
activeButton.FlashBackground(theme.PrimaryAccentColor.WithContrast(theme.TextColor, 6).ToColor());
}
// Show slide to animation from previous to current, on completion update view to current by setting active.Checked
previousButton.SlideToNewState(
activeButton,
this,
() =>
{
activeButton.Checked = true;
},
theme);
}
};

View file

@ -27,8 +27,11 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.Threading.Tasks;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.MatterControl.CustomWidgets;
namespace MatterHackers.MatterControl.PartPreviewWindow
{
@ -63,5 +66,59 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
};
flashBackground.Start();
}
public static void SlideToNewState(this RadioIconButton widget, RadioIconButton newActiveButton, OverflowBar parent, Action animationComplete, ThemeConfig theme)
{
double displayTime = 600;
double elapsedMs = 0;
var box = new GuiWidget()
{
HAnchor = HAnchor.Absolute,
VAnchor = VAnchor.Absolute,
Position = widget.Position + new VectorMath.Vector2(widget.Margin.Width, widget.Margin.Height),
Size = widget.Size,
BackgroundColor = theme.AccentMimimalOverlay,
Border = 1,
BorderColor = theme.PrimaryAccentColor
};
parent.AddChildDirect(box);
var startX = box.Position.X;
var startY = box.Position.Y;
var xdistance = (newActiveButton.Position.X + newActiveButton.Margin.Width) - startX;
var direction = xdistance > 0 ? 1 : -1;
var startedMS = UiThread.CurrentTimerMs;
Animation animation = null;
animation = new Animation()
{
DrawTarget = widget,
FramesPerSecond = 20,
Update = (s1, updateEvent) =>
{
elapsedMs = UiThread.CurrentTimerMs - startedMS;
if (elapsedMs < (displayTime + 300))
{
var ratio = Math.Min(1, elapsedMs / displayTime);
double blend = Easing.Cubic.In(ratio);
box.Position = new VectorMath.Vector2(startX + (xdistance * blend), startY);
//Console.WriteLine("Ms: {0}, Ratio: {1}, Easing: {2}, Position: {3}", elapsedMs, ratio, blend, box.Position);
box.Invalidate();
}
else
{
animation.Stop();
animationComplete?.Invoke();
UiThread.RunOnIdle(box.Close, .3);
}
}
};
animation.Start();
}
}
}

View file

@ -66,6 +66,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
public class ViewModeChangedEventArgs : EventArgs
{
public PartViewMode ViewMode { get; set; }
public PartViewMode PreviousMode { get; set; }
}
public class TransformStateChangedEventArgs : EventArgs
@ -102,10 +103,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
public ViewControls3DButtons ActiveButton
{
get
{
return activeTransformState;
}
get => activeTransformState;
set
{
this.activeTransformState = value;