From dd626569f97b379a13dab4d8c55145cd98d272b7 Mon Sep 17 00:00:00 2001 From: larsbrubaker Date: Thu, 23 Jul 2015 07:47:56 -0700 Subject: [PATCH] Took out some dead code Renaming for clarity Created a GCodeProxy class to clean up some of the gcode injection and processing. --- MatterControl.csproj | 5 +- PartPreviewWindow/ViewGcodeBasic.cs | 2 +- PartPreviewWindow/ViewGcodeWidget.cs | 2 +- PrinterCommunication/Io/GCodeFileProxy.cs | 158 ++++++++++++++++++ PrinterCommunication/Io/PrinterIoAdapter.cs | 64 ------- PrinterCommunication/Io/PrinterIoBase.cs | 74 -------- PrinterCommunication/Io/PrinterIoGCodeFile.cs | 141 ---------------- .../Io/PrinterIoInjectionFifo.cs | 39 ----- Submodules/agg-sharp | 2 +- 9 files changed, 162 insertions(+), 325 deletions(-) create mode 100644 PrinterCommunication/Io/GCodeFileProxy.cs delete mode 100644 PrinterCommunication/Io/PrinterIoAdapter.cs delete mode 100644 PrinterCommunication/Io/PrinterIoBase.cs delete mode 100644 PrinterCommunication/Io/PrinterIoGCodeFile.cs delete mode 100644 PrinterCommunication/Io/PrinterIoInjectionFifo.cs diff --git a/MatterControl.csproj b/MatterControl.csproj index d7e2c97d2..91667e4d3 100644 --- a/MatterControl.csproj +++ b/MatterControl.csproj @@ -189,10 +189,7 @@ - - - - + diff --git a/PartPreviewWindow/ViewGcodeBasic.cs b/PartPreviewWindow/ViewGcodeBasic.cs index abb8ed6cf..35a03d983 100644 --- a/PartPreviewWindow/ViewGcodeBasic.cs +++ b/PartPreviewWindow/ViewGcodeBasic.cs @@ -446,7 +446,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow // show the filament used modelInfoContainer.AddChild(new TextWidget(filamentLengthLabelFull, textColor: ActiveTheme.Instance.PrimaryTextColor, pointSize: 9)); { - double filamentUsed = gcodeViewWidget.LoadedGCode.GetFilamentUsedMm(ActiveSliceSettings.Instance.NozzleDiameter); + double filamentUsed = gcodeViewWidget.LoadedGCode.GetFilamentUsedMm(ActiveSliceSettings.Instance.FilamentDiameter); GuiWidget estimatedPrintTime = new TextWidget(string.Format("{0:0.0} mm", filamentUsed), pointSize: 14, textColor: ActiveTheme.Instance.PrimaryTextColor); //estimatedPrintTime.HAnchor = Agg.UI.HAnchor.ParentLeft; diff --git a/PartPreviewWindow/ViewGcodeWidget.cs b/PartPreviewWindow/ViewGcodeWidget.cs index cef4ae6ad..fa9b3ef74 100644 --- a/PartPreviewWindow/ViewGcodeWidget.cs +++ b/PartPreviewWindow/ViewGcodeWidget.cs @@ -302,7 +302,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { if (gCodeRenderer.GCodeFileToDraw != null) { - gCodeRenderer.GCodeFileToDraw.GetFilamentUsedMm(ActiveSliceSettings.Instance.NozzleDiameter); + gCodeRenderer.GCodeFileToDraw.GetFilamentUsedMm(ActiveSliceSettings.Instance.FilamentDiameter); } } catch (Exception) diff --git a/PrinterCommunication/Io/GCodeFileProxy.cs b/PrinterCommunication/Io/GCodeFileProxy.cs new file mode 100644 index 000000000..600953e8b --- /dev/null +++ b/PrinterCommunication/Io/GCodeFileProxy.cs @@ -0,0 +1,158 @@ +/* +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. +*/ + +using System; +using MatterHackers.Agg; +using MatterHackers.GCodeVisualizer; +using MatterHackers.VectorMath; + +namespace MatterHackers.MatterControl.PrinterCommunication.Io +{ + public class GCodeFileProxy : GCodeFile + { + private GCodeFile source; + + public GCodeFileProxy(GCodeFile source) + { + this.source = source; + } + + #region Abstract Functions + public override void Add(PrinterMachineInstruction printerMachineInstruction) + { + source.Add(printerMachineInstruction); + } + + public override void Clear() + { + source.Clear(); + } + + public override RectangleDouble GetBounds() + { + return source.GetBounds(); + } + + public override double GetFilamentCubicMm(double filamentDiameter) + { + return source.GetFilamentCubicMm(filamentDiameter); + } + + public override double GetFilamentDiamter() + { + return source.GetFilamentDiamter(); + } + + public override double GetFilamentUsedMm(double filamentDiameter) + { + return source.GetFilamentUsedMm(filamentDiameter); + } + + public override double GetFilamentWeightGrams(double filamentDiameterMm, double density) + { + return source.GetFilamentWeightGrams(filamentDiameterMm, density); + } + + public override double GetFirstLayerHeight() + { + return source.GetFirstLayerHeight(); + } + + public override int GetInstructionIndexAtLayer(int layerIndex) + { + return source.GetInstructionIndexAtLayer(layerIndex); + } + + public override double GetLayerHeight() + { + return source.GetLayerHeight(); + } + + public override int GetLayerIndex(int instructionIndex) + { + return source.GetLayerIndex(instructionIndex); + } + + public override Vector2 GetWeightedCenter() + { + return source.GetWeightedCenter(); + } + + public override void Insert(int indexToStartInjection, PrinterMachineInstruction printerMachineInstruction) + { + source.Insert(indexToStartInjection, printerMachineInstruction); + } + + public override PrinterMachineInstruction Instruction(int i) + { + return source.Instruction(i); + } + + public override bool IsExtruding(int instructionIndexToCheck) + { + return source.IsExtruding(instructionIndexToCheck); + } + + public override double PercentComplete(int instructionIndex) + { + return source.PercentComplete(instructionIndex); + } + + public override double Ratio0to1IntoContainedLayer(int instructionIndex) + { + return source.Ratio0to1IntoContainedLayer(instructionIndex); + } + + public override int LineCount + { + get + { + return source.LineCount; + } + } + + public override int NumChangesInZ + { + get + { + return source.NumChangesInZ; + } + } + + public override double TotalSecondsInPrint + { + get + { + return source.TotalSecondsInPrint; + } + } + + #endregion Abstract Functions + } +} \ No newline at end of file diff --git a/PrinterCommunication/Io/PrinterIoAdapter.cs b/PrinterCommunication/Io/PrinterIoAdapter.cs deleted file mode 100644 index fd44312e3..000000000 --- a/PrinterCommunication/Io/PrinterIoAdapter.cs +++ /dev/null @@ -1,64 +0,0 @@ -/* -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; - -namespace MatterHackers.MatterControl.PrinterCommunication.Io -{ - public class PrinterIoAdapter - { - private 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(); - } - } - } -} \ No newline at end of file diff --git a/PrinterCommunication/Io/PrinterIoBase.cs b/PrinterCommunication/Io/PrinterIoBase.cs deleted file mode 100644 index c62610733..000000000 --- a/PrinterCommunication/Io/PrinterIoBase.cs +++ /dev/null @@ -1,74 +0,0 @@ -/* -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 MatterHackers.GCodeVisualizer; -using System; - -namespace MatterHackers.MatterControl.PrinterCommunication.Io -{ - public abstract class PrinterIoBase - { - public PrinterIoBase() - { - } - - public virtual PrinterMachineInstruction PeekNextInstruction() - { - throw new NotImplementedException(); - } - - public virtual PrinterMachineInstruction PopNextInstruction() - { - throw new NotImplementedException(); - } - - public virtual void AddInstruction(PrinterMachineInstruction newCommand) - { - 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(); } - } - } -} \ No newline at end of file diff --git a/PrinterCommunication/Io/PrinterIoGCodeFile.cs b/PrinterCommunication/Io/PrinterIoGCodeFile.cs deleted file mode 100644 index 73ccee3ff..000000000 --- a/PrinterCommunication/Io/PrinterIoGCodeFile.cs +++ /dev/null @@ -1,141 +0,0 @@ -/* -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. -*/ - -using MatterHackers.GCodeVisualizer; -using System; - -namespace MatterHackers.MatterControl.PrinterCommunication.Io -{ - public class PrinterIoGCodeFile : PrinterIoBase - { - private GCodeFile loadedGCode; - private int printerCommandQueueLineIndex; - - public PrinterIoGCodeFile(GCodeFile loadedGCode) - { - this.loadedGCode = loadedGCode; - } - - public override double TotalSecondsInPrint - { - get - { - if (loadedGCode.LineCount > 0) - { - return loadedGCode.Instruction(0).secondsToEndFromHere; - } - - return 0; - } - } - - private int backupAmount = 16; - - public int CurrentlyPrintingLayer - { - get - { - int currentIndex = printerCommandQueueLineIndex - backupAmount; - if (currentIndex >= 0 - && currentIndex < loadedGCode.LineCount) - { - for (int zIndex = 0; zIndex < loadedGCode.NumChangesInZ; zIndex++) - { - if (currentIndex < loadedGCode.GetInstructionIndexAtLayer(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 currentLineIndex = printerCommandQueueLineIndex - backupAmount; - if (currentLineIndex >= 0 - && currentLineIndex < loadedGCode.LineCount) - { - int currentLayer = CurrentlyPrintingLayer; - int startIndex = loadedGCode.GetInstructionIndexAtLayer(currentLayer); - int endIndex = loadedGCode.LineCount - 1; - if (currentLayer < loadedGCode.NumChangesInZ - 2) - { - endIndex = loadedGCode.GetInstructionIndexAtLayer(currentLayer + 1) - 1; - } - - int deltaFromStart = Math.Max(0, currentLineIndex - startIndex); - return deltaFromStart / (double)(endIndex - startIndex); - } - - return 0; - } - } - - public override double SecondsRemaining - { - get - { - if (NumberOfInstruction > 0) - { - if (printerCommandQueueLineIndex >= 0 - && printerCommandQueueLineIndex < loadedGCode.LineCount - && loadedGCode.Instruction(printerCommandQueueLineIndex).secondsToEndFromHere != 0) - { - return loadedGCode.Instruction(printerCommandQueueLineIndex).secondsToEndFromHere; - } - } - - return 0; - } - } - } -} \ No newline at end of file diff --git a/PrinterCommunication/Io/PrinterIoInjectionFifo.cs b/PrinterCommunication/Io/PrinterIoInjectionFifo.cs deleted file mode 100644 index 9dce9c90a..000000000 --- a/PrinterCommunication/Io/PrinterIoInjectionFifo.cs +++ /dev/null @@ -1,39 +0,0 @@ -/* -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. -*/ - -namespace MatterHackers.MatterControl.PrinterCommunication.Io -{ - public class PrinterIoInjectionFifo : PrinterIoAdapter - { - public PrinterIoInjectionFifo(PrinterIoBase source) - : base(source) - { - } - } -} \ No newline at end of file diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 91ee28e15..33adced5a 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 91ee28e157743069fd68d8b5e2e84c725e3921e1 +Subproject commit 33adced5a229ab88d4d949261d30c74289816144