diff --git a/ControlElements/TextImageButtonFactory.cs b/ControlElements/TextImageButtonFactory.cs index 417a8df76..926d05650 100644 --- a/ControlElements/TextImageButtonFactory.cs +++ b/ControlElements/TextImageButtonFactory.cs @@ -259,7 +259,25 @@ namespace MatterHackers.MatterControl return textImageCheckBoxButton; } - public Button Generate(string label, string normalImageName = null, string hoverImageName = null, string pressedImageName = null, string disabledImageName = null, bool centerText = false) + public Button GenerateFromImages(string label, ImageBuffer normalImage, ImageBuffer hoverImage = null, ImageBuffer pressedImage = null, ImageBuffer disabledImage = null, bool centerText = false) + { + //Create button based on view container widget + ButtonViewStates buttonViewWidget = getButtonView(label, normalImage, hoverImage, pressedImage, disabledImage, centerText); + Button textImageButton = new Button(0, 0, buttonViewWidget); + + textImageButton.Margin = new BorderDouble(0); + textImageButton.Padding = new BorderDouble(0); + + //Override the width if requested + if (this.FixedWidth != 0) + { + buttonViewWidget.Width = this.FixedWidth; + textImageButton.Width = this.FixedWidth; + } + return textImageButton; + } + + public Button Generate(string label, string normalImageName = null, string hoverImageName = null, string pressedImageName = null, string disabledImageName = null, bool centerText = false) { //Create button based on view container widget ButtonViewStates buttonViewWidget = getButtonView(label, normalImageName, hoverImageName, pressedImageName, disabledImageName, centerText); @@ -302,37 +320,53 @@ namespace MatterHackers.MatterControl if (normalImageName != null) { StaticData.Instance.LoadIcon(normalImageName, normalImage); - if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage) - { - InvertLightness.DoInvertLightness(normalImage); - } } if (hoverImageName != null) { StaticData.Instance.LoadIcon(pressedImageName, pressedImage); - if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage) - { - InvertLightness.DoInvertLightness(pressedImage); - } } if (pressedImageName != null) { StaticData.Instance.LoadIcon(hoverImageName, hoverImage); - if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage) - { - InvertLightness.DoInvertLightness(hoverImage); - } } if (disabledImageName != null) { StaticData.Instance.LoadIcon(disabledImageName, disabledImage); - if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage) - { - InvertLightness.DoInvertLightness(disabledImage); - } + } + + return getButtonView(label, normalImage, hoverImage, pressedImage, disabledImage, centerText); + } + + private ButtonViewStates getButtonView(string label, ImageBuffer normalImage = null, ImageBuffer hoverImage = null, ImageBuffer pressedImage = null, ImageBuffer disabledImage = null, bool centerText = false) + { + if (normalImage == null) + { + normalImage = new ImageBuffer(0, 0, 32, new BlenderBGRA()); + } + if (hoverImage == null) + { + hoverImage = new ImageBuffer(normalImage); + } + + if (pressedImage == null) + { + pressedImage = new ImageBuffer(hoverImage); + } + + if (disabledImage == null) + { + disabledImage = new ImageBuffer(normalImage); + } + + if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage) + { + InvertLightness.DoInvertLightness(normalImage); + InvertLightness.DoInvertLightness(pressedImage); + InvertLightness.DoInvertLightness(hoverImage); + InvertLightness.DoInvertLightness(disabledImage); } if (invertImageLocation) diff --git a/MatterControl.csproj b/MatterControl.csproj index aaea71710..19b8f14f2 100644 --- a/MatterControl.csproj +++ b/MatterControl.csproj @@ -149,6 +149,7 @@ + diff --git a/PrinterCommunication/Io/PrinterIoAdapter.cs b/PrinterCommunication/Io/PrinterIoAdapter.cs new file mode 100644 index 000000000..d780016c3 --- /dev/null +++ b/PrinterCommunication/Io/PrinterIoAdapter.cs @@ -0,0 +1,67 @@ +/* +Copyright (c) 2014, 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. +*/ + +// This is the base class for translators and sources to the printer communication. Things like bed leveling, +// temperature injection, etc. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace MatterHackers.MatterControl.PrinterCommunication.Io +{ + public class PrinterIoAdapter + { + PrinterIoBase source; + + public PrinterIoAdapter(PrinterIoBase source) + { + this.source = source; + } + + public string PeekNextInstruction() + { + throw new NotImplementedException(); + } + + public string PopNextInstruction() + { + throw new NotImplementedException(); + } + + public int NumberOfLines + { + get + { + throw new NotImplementedException(); + } + } + } +} diff --git a/PrinterCommunication/Io/PrinterIoBase.cs b/PrinterCommunication/Io/PrinterIoBase.cs index b76959b76..996470332 100644 --- a/PrinterCommunication/Io/PrinterIoBase.cs +++ b/PrinterCommunication/Io/PrinterIoBase.cs @@ -34,34 +34,44 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using MatterHackers.GCodeVisualizer; namespace MatterHackers.MatterControl.PrinterCommunication.Io { public abstract class PrinterIoBase { - PrinterIoBase source; - - public PrinterIoBase(PrinterIoBase source) + public PrinterIoBase() { - this.source = source; } - public string PeekNextLine() + public virtual PrinterMachineInstruction PeekNextInstruction() { throw new NotImplementedException(); } - public string PopNextLine() + public virtual PrinterMachineInstruction PopNextInstruction() { throw new NotImplementedException(); } - public int NumberOfLines + public virtual void AddInstruction(PrinterMachineInstruction newCommand) { - get - { - throw new NotImplementedException(); - } + throw new NotImplementedException(); + } + + public virtual int NumberOfInstruction + { + get { throw new NotImplementedException(); } + } + + public virtual double TotalSecondsInPrint + { + get { throw new NotImplementedException(); } + } + + public virtual double SecondsRemaining + { + get { throw new NotImplementedException(); } } } } diff --git a/PrinterCommunication/Io/PrinterIoGCodeFile.cs b/PrinterCommunication/Io/PrinterIoGCodeFile.cs index 56530e10b..56e0ff049 100644 --- a/PrinterCommunication/Io/PrinterIoGCodeFile.cs +++ b/PrinterCommunication/Io/PrinterIoGCodeFile.cs @@ -38,10 +38,105 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io public class PrinterIoGCodeFile : PrinterIoBase { GCodeFile loadedGCode = new GCodeFile(); + int printerCommandQueueIndex; public PrinterIoGCodeFile(GCodeFile loadedGCode) - : base(null) { this.loadedGCode = loadedGCode; } + + public double TotalSecondsInPrint + { + get + { + if (loadedGCode.Count > 0) + { + return loadedGCode.Instruction(0).secondsToEndFromHere; + } + + return 0; + } + } + + int backupAmount = 16; + public int CurrentlyPrintingLayer + { + get + { + int currentIndex = printerCommandQueueIndex - backupAmount; + if (currentIndex >= 0 + && currentIndex < loadedGCode.Count) + { + for (int zIndex = 0; zIndex < loadedGCode.NumChangesInZ; zIndex++) + { + if (currentIndex < loadedGCode.IndexOfChangeInZ[zIndex]) + { + return zIndex - 1; + } + } + + return loadedGCode.NumChangesInZ - 1; + } + + return -1; + } + } + + public int TotalLayersInPrint + { + get + { + try + { + int layerCount = loadedGCode.NumChangesInZ; + return layerCount; + } + catch + { + return -1; + } + } + } + + public double RatioIntoCurrentLayer + { + get + { + int currentIndex = printerCommandQueueIndex - backupAmount; + if (currentIndex >= 0 + && currentIndex < loadedGCode.Count) + { + int currentLayer = CurrentlyPrintingLayer; + int startIndex = loadedGCode.IndexOfChangeInZ[currentLayer]; + int endIndex = loadedGCode.Count - 1; + if (currentLayer < loadedGCode.NumChangesInZ - 2) + { + endIndex = loadedGCode.IndexOfChangeInZ[currentLayer + 1] - 1; + } + + int deltaFromStart = Math.Max(0, currentIndex - startIndex); + return deltaFromStart / (double)(endIndex - startIndex); + } + + return 0; + } + } + + public double SecondsRemaining + { + get + { + if (NumberOfInstruction > 0) + { + if (printerCommandQueueIndex >= 0 + && printerCommandQueueIndex < loadedGCode.Count + && loadedGCode.Instruction(printerCommandQueueIndex).secondsToEndFromHere != 0) + { + return loadedGCode.Instruction(printerCommandQueueIndex).secondsToEndFromHere; + } + } + + return 0; + } + } } } diff --git a/PrinterCommunication/Io/PrinterIoInjectionFifo.cs b/PrinterCommunication/Io/PrinterIoInjectionFifo.cs index 0074908fb..7ed706859 100644 --- a/PrinterCommunication/Io/PrinterIoInjectionFifo.cs +++ b/PrinterCommunication/Io/PrinterIoInjectionFifo.cs @@ -31,7 +31,7 @@ using System.Collections.Generic; namespace MatterHackers.MatterControl.PrinterCommunication.Io { - public class PrinterIoInjectionFifo : PrinterIoBase + public class PrinterIoInjectionFifo : PrinterIoAdapter { public PrinterIoInjectionFifo(PrinterIoBase source) : base(source) diff --git a/PrinterControls/ControlWidgets/AdjustmentControls.cs b/PrinterControls/ControlWidgets/AdjustmentControls.cs index 9f05d7af0..c8bb94ab7 100644 --- a/PrinterControls/ControlWidgets/AdjustmentControls.cs +++ b/PrinterControls/ControlWidgets/AdjustmentControls.cs @@ -31,9 +31,11 @@ using System; using System.Collections.Generic; using System.Linq; using MatterHackers.Agg; +using MatterHackers.Agg.Image; using MatterHackers.Agg.UI; using MatterHackers.Localizations; using MatterHackers.VectorMath; +using MatterHackers.MatterControl.CustomWidgets; using MatterHackers.MatterControl.PrinterCommunication; namespace MatterHackers.MatterControl.PrinterControls @@ -76,7 +78,7 @@ namespace MatterHackers.MatterControl.PrinterControls } TextWidget subheader = new TextWidget("Fine-tune adjustment while actively printing", pointSize: 8, textColor: ActiveTheme.Instance.PrimaryTextColor); - subheader.Margin = new BorderDouble(bottom:6); + subheader.Margin = new BorderDouble(bottom: 6); tuningRatiosLayout.AddChild(subheader); TextWidget feedRateDescription; { @@ -167,6 +169,33 @@ namespace MatterHackers.MatterControl.PrinterControls } adjustmentControlsGroupBox.AddChild(tuningRatiosLayout); + + if(false) + { + HorizontalLine line = new HorizontalLine(); + line.Margin = new BorderDouble(0, 10); + tuningRatiosLayout.AddChild(line); + TextWidget subheader2 = new TextWidget("Fine-tune z-height if print leveling enabled, while actively printing", pointSize: 8, textColor: ActiveTheme.Instance.PrimaryTextColor); + subheader2.Margin = new BorderDouble(bottom: 6); + tuningRatiosLayout.AddChild(subheader2); + + int buttonSize = 32; + ImageBuffer togetherBig = new ImageBuffer(buttonSize, buttonSize, 32, new BlenderBGRA()); + Graphics2D togetherBigGraphics = togetherBig.NewGraphics2D(); + togetherBigGraphics.Circle(new Vector2(32, 32), 12, RGBA_Bytes.Blue); + Button togetherALot = textImageButtonFactory.GenerateFromImages("", togetherBig); + + ImageBuffer appartBig = new ImageBuffer(buttonSize, buttonSize, 32, new BlenderBGRA()); + Graphics2D appartBigGraphics = appartBig.NewGraphics2D(); + appartBigGraphics.Circle(new Vector2(32, 32), 12, RGBA_Bytes.Red); + Button appartALot = textImageButtonFactory.GenerateFromImages("", appartBig); + + FlowLayoutWidget leftToRigth = new FlowLayoutWidget(); + leftToRigth.AddChild(togetherALot); + leftToRigth.AddChild(appartALot); + + tuningRatiosLayout.AddChild(leftToRigth); + } } this.AddChild(adjustmentControlsGroupBox);