Merge pull request #1874 from larsbrubaker/master

Made load filament macro work.
This commit is contained in:
johnlewin 2017-02-02 17:29:20 -08:00 committed by GitHub
commit 37e78aa99a
8 changed files with 142 additions and 52 deletions

View file

@ -184,7 +184,7 @@ namespace MatterHackers.MatterControl
// put the image into the widget when it is done downloading.
var image = new ImageBuffer(Math.Max(elementState.SizeFixed.x, 1), Math.Max(elementState.SizeFixed.y, 1));
var imageWidget = new ImageWidget(image);
imageWidget.Load += (s, e) => ApplicationController.Instance.DownloadToImageAsync(image, elementState.src, elementState.SizeFixed.x == 0);
imageWidget.Load += (s, e) => ApplicationController.Instance.DownloadToImageAsync(image, elementState.src, elementState.SizeFixed.x != 0);
if (elementsUnderConstruction.Peek().Name == "a")
{

View file

@ -692,7 +692,7 @@ namespace MatterHackers.MatterControl
byte[] raw = e.Result;
Stream stream = new MemoryStream(raw);
ImageBuffer unScaledImage = new ImageBuffer(10, 10);
if (!scaleImage)
if (scaleImage)
{
StaticData.Instance.LoadImageData(stream, unScaledImage);
// If the source image (the one we downloaded) is more than twice as big as our dest image.

View file

@ -30,6 +30,8 @@ either expressed or implied, of the FreeBSD Project.
using System;
using System.Collections.Generic;
using MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.PlatformAbstract;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.CustomWidgets;
@ -50,15 +52,12 @@ namespace MatterHackers.MatterControl.PrinterControls
List<double> startingExtruderTemps = new List<double>();
double startingBedTemp = 0;
public RunningMacroPage(string message, bool showOkButton, bool showMaterialSelector, double expectedSeconds, double expectedTemperature)
public RunningMacroPage(string message, bool showOkButton, bool showMaterialSelector, double expectedSeconds, double expectedTemperature, ImageBuffer imageBuffer)
: base("Cancel", "Macro Feedback")
{
TextWidget syncingText = new TextWidget(message, textColor: ActiveTheme.Instance.PrimaryTextColor);
contentRow.AddChild(syncingText);
footerRow.AddChild(new HorizontalSpacer());
footerRow.AddChild(cancelButton);
int extruderCount = ActiveSliceSettings.Instance.GetValue<int>(SettingsKey.extruder_count);
for (int i = 0; i < extruderCount; i++)
{
@ -72,25 +71,46 @@ namespace MatterHackers.MatterControl.PrinterControls
cancelButton.Click += (s, e) =>
{
for (int i = 0; i < startingExtruderTemps.Count; i++)
{
PrinterConnectionAndCommunication.Instance.SetTargetExtruderTemperature(i, startingExtruderTemps[i]);
}
if (ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.has_heated_bed))
{
PrinterConnectionAndCommunication.Instance.TargetBedTemperature = startingBedTemp;
}
PrinterConnectionAndCommunication.Instance.MacroCancel();
CancelScript();
};
if (showMaterialSelector)
{
int extruderIndex = 0;
contentRow.AddChild(new PresetSelectorWidget(string.Format($"{"Material".Localize()} {extruderIndex + 1}"), RGBA_Bytes.Orange, NamedSettingsLayers.Material, extruderIndex));
var materialSelector = new PresetSelectorWidget(string.Format($"{"Material".Localize()} {extruderIndex + 1}"), RGBA_Bytes.Transparent, NamedSettingsLayers.Material, extruderIndex);
materialSelector.BackgroundColor = RGBA_Bytes.Transparent;
materialSelector.Margin = new BorderDouble(0, 0, 0, 15);
contentRow.AddChild(materialSelector);
}
PrinterConnectionAndCommunication.Instance.WroteLine.RegisterEvent(LookForTempRequest, ref unregisterEvents);
if (showOkButton)
{
Button okButton = textImageButtonFactory.Generate("Continue".Localize());
okButton.Click += (s, e) =>
{
PrinterConnectionAndCommunication.Instance.MacroContinue();
UiThread.RunOnIdle(() => WizardWindow?.Close());
};
footerRow.AddChild(okButton);
}
if (imageBuffer != null)
{
var imageWidget = new ImageWidget(imageBuffer)
{
HAnchor = HAnchor.ParentCenter,
Margin = new BorderDouble(5,15),
};
contentRow.AddChild(imageWidget);
}
contentRow.AddChild(new VerticalSpacer());
var holder = new FlowLayoutWidget();
progressBar = new ProgressBar((int)(150 * GuiWidget.DeviceScale), (int)(15 * GuiWidget.DeviceScale))
{
@ -117,34 +137,34 @@ namespace MatterHackers.MatterControl.PrinterControls
progressBar.Visible = true;
}
PrinterConnectionAndCommunication.Instance.WroteLine.RegisterEvent(LookForTempRequest, ref unregisterEvents);
footerRow.AddChild(new HorizontalSpacer());
footerRow.AddChild(cancelButton);
}
if (showOkButton)
private void CancelScript()
{
for (int i = 0; i < startingExtruderTemps.Count; i++)
{
Button okButton = textImageButtonFactory.Generate("Continue".Localize());
okButton.Margin = new BorderDouble(0, 0, 0, 25);
okButton.HAnchor = HAnchor.ParentCenter;
okButton.Click += (s, e) =>
{
PrinterConnectionAndCommunication.Instance.MacroContinue();
UiThread.RunOnIdle(() => WizardWindow?.Close());
};
contentRow.AddChild(okButton);
PrinterConnectionAndCommunication.Instance.SetTargetExtruderTemperature(i, startingExtruderTemps[i]);
}
if (ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.has_heated_bed))
{
PrinterConnectionAndCommunication.Instance.TargetBedTemperature = startingBedTemp;
}
PrinterConnectionAndCommunication.Instance.MacroCancel();
}
private EventHandler unregisterEvents;
public static void Show(string message, bool showOkButton = false, bool showMaterialSelector = false, double expectedSeconds = 0, double expectedTemperature = 0)
public static void Show(string message, bool showOkButton = false, bool showMaterialSelector = false, double expectedSeconds = 0, double expectedTemperature = 0, ImageBuffer image = null)
{
WizardWindow.Show("Macro", "Running Macro", new RunningMacroPage(message, showOkButton, showMaterialSelector, expectedSeconds, expectedTemperature));
WizardWindow.Show("Macro", "Running Macro", new RunningMacroPage(message, showOkButton, showMaterialSelector, expectedSeconds, expectedTemperature, image));
}
public override void OnClosed(EventArgs e)
{
PrinterConnectionAndCommunication.Instance.MacroContinue();
unregisterEvents?.Invoke(this, null);
base.OnClosed(e);

View file

@ -21,16 +21,22 @@ namespace MatterHackers.MatterControl.CustomWidgets
&& Parent.Height > 0
&& Parent.Children.Count > 1)
{
var childBounds = GetChildrenBoundsIncludingMargins(considerChild: (parent, child) =>
{
if (child == disableOverlay)
if(Children.IndexOf(disableOverlay) != Children.Count-1)
{
return false;
Children.RemoveAt(Children.IndexOf(disableOverlay));
disableOverlay.ClearRemovedFlag();
Children.Add(disableOverlay);
}
return true;
});
var childBounds = GetChildrenBoundsIncludingMargins(considerChild: (parent, child) =>
{
if (child == disableOverlay)
{
return false;
}
return true;
});
if (childBounds != RectangleDouble.ZeroIntersection)
{

View file

@ -29,8 +29,11 @@ either expressed or implied, of the FreeBSD Project.
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.PlatformAbstract;
using MatterHackers.Agg.UI;
using MatterHackers.GCodeVisualizer;
using MatterHackers.MatterControl.PrinterControls;
@ -45,7 +48,8 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
private object locker = new object();
private bool waitingForUserInput = false;
private double maxTimeToWaitForOk = 0;
private string commandToRepeat = "";
private int repeatCommandIndex = 0;
private List<string> commandsToRepeat = new List<string>();
private Stopwatch timeHaveBeenWaiting = new Stopwatch();
public QueuedCommandsStream(GCodeStream internalStream)
@ -72,7 +76,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
waitingForUserInput = false;
timeHaveBeenWaiting.Reset();
maxTimeToWaitForOk = 0;
commandToRepeat = "";
commandsToRepeat.Clear();
}
public override string ReadLine()
@ -85,16 +89,26 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
Thread.Sleep(100);
if(timeHaveBeenWaiting.IsRunning
&& timeHaveBeenWaiting.Elapsed.TotalSeconds < maxTimeToWaitForOk)
&& timeHaveBeenWaiting.Elapsed.TotalSeconds > maxTimeToWaitForOk)
{
Continue();
if(commandsToRepeat.Count > 0)
{
// We timed out without the user responding. Cancel the operation.
Reset();
}
else
{
// everything normal continue after time waited
Continue();
}
}
if (maxTimeToWaitForOk > 0
&& timeHaveBeenWaiting.Elapsed.TotalSeconds < maxTimeToWaitForOk
&& commandToRepeat != "")
&& commandsToRepeat.Count > 0)
{
lineToSend = commandToRepeat;
lineToSend = commandsToRepeat[repeatCommandIndex % commandsToRepeat.Count];
repeatCommandIndex++;
}
}
else
@ -132,6 +146,9 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
messages.Add(matchString.Substring(1, matchString.Length - 2));
}
var macroMatch = Regex.Match(lineToSend, "MacroImage:([^\\s]+)\\s*");
var macroImage = macroMatch.Success ? LoadImageAsset(macroMatch.Groups[1].Value) : null;
switch (command)
{
case "ChooseMaterial":
@ -150,18 +167,30 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
GCodeFile.GetFirstNumberAfter("ExpectedSeconds:", lineToSend, ref seconds);
double temperature = 0;
GCodeFile.GetFirstNumberAfter("ExpectedTemperature:", lineToSend, ref temperature);
UiThread.RunOnIdle(() => RunningMacroPage.Show(messages[0], expectedSeconds: seconds, expectedTemperature: temperature));
UiThread.RunOnIdle(() => RunningMacroPage.Show(messages[0], expectedSeconds: seconds, expectedTemperature: temperature, image: macroImage));
}
break;
case "RepeatUntil": // Repeat a command until the user clicks or or the max time elapses.
waitingForUserInput = true;
UiThread.RunOnIdle(() => RunningMacroPage.Show(messages.Count > 0 ? messages[0] : "", true));
if(messages.Count > 1)
{
double seconds = 10;
GCodeFile.GetFirstNumberAfter("ExpectedSeconds:", lineToSend, ref seconds);
timeHaveBeenWaiting.Restart();
maxTimeToWaitForOk = seconds;
waitingForUserInput = true;
for (int i = 1; i < messages.Count; i++)
{
commandsToRepeat.Add(messages[i]);
}
UiThread.RunOnIdle(() => RunningMacroPage.Show(messages[0], true, expectedSeconds: seconds, image: macroImage));
}
break;
case "WaitOK":
waitingForUserInput = true;
UiThread.RunOnIdle(() => RunningMacroPage.Show(messages.Count > 0 ? messages[0] : "", true));
UiThread.RunOnIdle(() => RunningMacroPage.Show(messages.Count > 0 ? messages[0] : "", true, image: macroImage));
break;
default:
@ -179,6 +208,26 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
return lineToSend;
}
public ImageBuffer LoadImageAsset(string fileName)
{
string filePath = Path.Combine("Images", "Macros", fileName);
if (StaticData.Instance.FileExists(filePath))
{
return StaticData.Instance.LoadImage(filePath);
}
else
{
var imageBuffer = new ImageBuffer();
ApplicationController.Instance.DownloadToImageAsync(imageBuffer, "http://sync-dot-mattercontrol-test.appspot.com/static/macros/" + fileName, false);
return imageBuffer;
}
return null;
}
public void Reset()
{
lock (locker)
@ -187,6 +236,9 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
}
waitingForUserInput = false;
timeHaveBeenWaiting.Reset();
maxTimeToWaitForOk = 0;
UiThread.RunOnIdle(() => WizardWindow.Close("Macro"));
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View file

@ -5881,3 +5881,15 @@ Translated:The starting height (z) of the print head before probing each print l
English:Probe Start Height
Translated:Probe Start Height
English:Controls the speed of printer moves
Translated:Controls the speed of printer moves
English:Controls the amount of extrusion
Translated:Controls the amount of extrusion
English:feedrate_ratio
Translated:feedrate_ratio
English:extrusion_ratio
Translated:extrusion_ratio

@ -1 +1 @@
Subproject commit 94b1d7d360e70b19ed2a0a97e2e913985a12dc71
Subproject commit 2662bb28359665783d511e5d79fab63dfe7f3968