2015-11-28 19:59:14 -08:00
|
|
|
|
/*
|
|
|
|
|
|
Copyright (c) 2015, Lars Brubaker
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
|
|
list of conditions and the following disclaimer.
|
|
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
|
and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
|
|
The views and conclusions contained in the software and documentation are those
|
|
|
|
|
|
of the authors and should not be interpreted as representing official policies,
|
|
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
2017-02-02 07:54:52 -08:00
|
|
|
|
using System.Diagnostics;
|
2017-02-02 16:38:48 -08:00
|
|
|
|
using System.IO;
|
2016-11-04 16:00:54 -07:00
|
|
|
|
using System.Text.RegularExpressions;
|
2017-02-02 07:54:52 -08:00
|
|
|
|
using System.Threading;
|
2017-02-02 16:38:48 -08:00
|
|
|
|
using MatterHackers.Agg.Image;
|
2017-08-20 02:34:39 -07:00
|
|
|
|
using MatterHackers.Agg.Platform;
|
2016-11-04 16:00:54 -07:00
|
|
|
|
using MatterHackers.Agg.UI;
|
2017-02-02 07:54:52 -08:00
|
|
|
|
using MatterHackers.MatterControl.PrinterControls;
|
|
|
|
|
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
2015-11-28 19:59:14 -08:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
|
|
|
|
|
{
|
2016-11-04 16:00:54 -07:00
|
|
|
|
public class QueuedCommandsStream : GCodeStreamProxy
|
|
|
|
|
|
{
|
2017-02-02 07:54:52 -08:00
|
|
|
|
private List<string> commandQueue = new List<string>();
|
|
|
|
|
|
private object locker = new object();
|
2015-11-28 19:59:14 -08:00
|
|
|
|
|
2016-11-04 16:00:54 -07:00
|
|
|
|
public QueuedCommandsStream(GCodeStream internalStream)
|
|
|
|
|
|
: base(internalStream)
|
2016-01-19 15:16:05 -08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-04-11 10:41:23 -07:00
|
|
|
|
public void Add(string line, bool forceTopOfQueue = false)
|
2016-11-04 16:00:54 -07:00
|
|
|
|
{
|
|
|
|
|
|
// lock queue
|
|
|
|
|
|
lock (locker)
|
2015-12-31 09:40:17 -08:00
|
|
|
|
{
|
2017-04-11 10:41:23 -07:00
|
|
|
|
if (forceTopOfQueue)
|
|
|
|
|
|
{
|
|
|
|
|
|
commandQueue.Insert(0, line);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
commandQueue.Add(line);
|
|
|
|
|
|
}
|
2015-12-31 09:40:17 -08:00
|
|
|
|
}
|
2016-11-04 16:00:54 -07:00
|
|
|
|
}
|
2015-12-31 09:40:17 -08:00
|
|
|
|
|
2017-02-02 07:54:52 -08:00
|
|
|
|
public void Cancel()
|
|
|
|
|
|
{
|
|
|
|
|
|
Reset();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-02-06 14:17:49 -08:00
|
|
|
|
public ImageBuffer LoadImageAsset(string uri)
|
|
|
|
|
|
{
|
|
|
|
|
|
string filePath = Path.Combine("Images", "Macros", uri);
|
|
|
|
|
|
bool imageOnDisk = false;
|
|
|
|
|
|
if (uri.IndexOfAny(Path.GetInvalidFileNameChars()) == -1)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2017-08-20 02:34:39 -07:00
|
|
|
|
imageOnDisk = AggContext.StaticData.FileExists(filePath);
|
2017-02-06 14:17:49 -08:00
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
imageOnDisk = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (imageOnDisk)
|
|
|
|
|
|
{
|
2017-08-20 02:34:39 -07:00
|
|
|
|
return AggContext.StaticData.LoadImage(filePath);
|
2017-02-06 14:17:49 -08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
var imageBuffer = new ImageBuffer(320, 10);
|
|
|
|
|
|
|
|
|
|
|
|
ApplicationController.Instance.DownloadToImageAsync(imageBuffer, uri, true);
|
|
|
|
|
|
|
|
|
|
|
|
return imageBuffer;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-11-04 16:00:54 -07:00
|
|
|
|
public override string ReadLine()
|
|
|
|
|
|
{
|
|
|
|
|
|
string lineToSend = null;
|
|
|
|
|
|
|
2015-12-31 09:40:17 -08:00
|
|
|
|
{
|
2016-11-04 16:00:54 -07:00
|
|
|
|
// lock queue
|
|
|
|
|
|
lock (locker)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (commandQueue.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
lineToSend = commandQueue[0];
|
2016-11-29 15:14:38 -08:00
|
|
|
|
lineToSend = GCodeProcessing.ReplaceMacroValues(lineToSend);
|
2016-11-04 16:00:54 -07:00
|
|
|
|
commandQueue.RemoveAt(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-04 09:37:28 -07:00
|
|
|
|
if (lineToSend == null)
|
2016-11-04 16:00:54 -07:00
|
|
|
|
{
|
|
|
|
|
|
lineToSend = base.ReadLine();
|
|
|
|
|
|
}
|
2015-12-31 09:40:17 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return lineToSend;
|
2016-11-04 16:00:54 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-02-06 14:17:49 -08:00
|
|
|
|
public void Reset()
|
2017-02-03 17:54:49 -08:00
|
|
|
|
{
|
2017-02-06 14:17:49 -08:00
|
|
|
|
lock (locker)
|
|
|
|
|
|
{
|
|
|
|
|
|
commandQueue.Clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-11-04 16:00:54 -07:00
|
|
|
|
}
|
2015-11-28 19:59:14 -08:00
|
|
|
|
}
|