From afc8d156fd87373f66117b5564e6695e2040b0b0 Mon Sep 17 00:00:00 2001 From: larsbrubaker Date: Mon, 3 Mar 2014 08:03:23 -0800 Subject: [PATCH] Got more of the new layout code not crashing. Sped up gcode parsing a bit (almost back to what it was). --- PartPreviewWindow/GcodeViewBasic.cs | 55 +++++++++++--------- PartPreviewWindow/View3DTransfromPart.cs | 9 ++-- PrinterCommunication/PrinterCommunication.cs | 24 ++++----- PrinterControls/PrintLeveling.cs | 10 ++-- 4 files changed, 54 insertions(+), 44 deletions(-) diff --git a/PartPreviewWindow/GcodeViewBasic.cs b/PartPreviewWindow/GcodeViewBasic.cs index 52ce0dc97..8320dd03d 100644 --- a/PartPreviewWindow/GcodeViewBasic.cs +++ b/PartPreviewWindow/GcodeViewBasic.cs @@ -119,33 +119,37 @@ namespace MatterHackers.MatterControl.PartPreviewWindow gcodeDispalyWidget = new GuiWidget(HAnchor.ParentLeftRight, Agg.UI.VAnchor.ParentBottomTop); - string startingMessage = new LocalizedString("Loading GCode...").Translated; - if (Path.GetExtension(printItem.FileLocation).ToUpper() == ".GCODE") + string startingMessage = new LocalizedString("No GCode Available...").Translated; + if (printItem != null) { - gcodeDispalyWidget.AddChild(CreateGCodeViewWidget(printItem.FileLocation)); - } - else - { - string gcodePathAndFileName = printItem.GCodePathAndFileName; - bool gcodeFileIsComplete = printItem.IsGCodeFileComplete(gcodePathAndFileName); - - if (gcodeProcessingStateInfoText != null && gcodeProcessingStateInfoText.Text == "Slicing Error") + startingMessage = new LocalizedString("Loading GCode...").Translated; + if (Path.GetExtension(printItem.FileLocation).ToUpper() == ".GCODE") { - startingMessage = "Slicing Error. Please review your slice settings."; + gcodeDispalyWidget.AddChild(CreateGCodeViewWidget(printItem.FileLocation)); } else { - startingMessage = new LocalizedString("Press 'generate' to view layers").Translated; - } + string gcodePathAndFileName = printItem.GCodePathAndFileName; + bool gcodeFileIsComplete = printItem.IsGCodeFileComplete(gcodePathAndFileName); - if (File.Exists(gcodePathAndFileName) && gcodeFileIsComplete) - { - gcodeDispalyWidget.AddChild(CreateGCodeViewWidget(gcodePathAndFileName)); - } + if (gcodeProcessingStateInfoText != null && gcodeProcessingStateInfoText.Text == "Slicing Error") + { + startingMessage = "Slicing Error. Please review your slice settings."; + } + else + { + startingMessage = new LocalizedString("Press 'generate' to view layers").Translated; + } - // we only hook these up to make sure we can regenerate the gcode when we want - printItem.SlicingOutputMessage += sliceItem_SlicingOutputMessage; - printItem.Done += new EventHandler(sliceItem_Done); + if (File.Exists(gcodePathAndFileName) && gcodeFileIsComplete) + { + gcodeDispalyWidget.AddChild(CreateGCodeViewWidget(gcodePathAndFileName)); + } + + // we only hook these up to make sure we can regenerate the gcode when we want + printItem.SlicingOutputMessage += sliceItem_SlicingOutputMessage; + printItem.Done += new EventHandler(sliceItem_Done); + } } centerPartPreviewAndControls.AddChild(gcodeDispalyWidget); @@ -583,11 +587,14 @@ namespace MatterHackers.MatterControl.PartPreviewWindow public override void OnClosed(EventArgs e) { - printItem.SlicingOutputMessage -= sliceItem_SlicingOutputMessage; - printItem.Done -= new EventHandler(sliceItem_Done); - if (startedSliceFromGenerateButton && printItem.CurrentlySlicing) + if (printItem != null) { - SlicingQueue.Instance.CancelCurrentSlicing(); + printItem.SlicingOutputMessage -= sliceItem_SlicingOutputMessage; + printItem.Done -= new EventHandler(sliceItem_Done); + if (startedSliceFromGenerateButton && printItem.CurrentlySlicing) + { + SlicingQueue.Instance.CancelCurrentSlicing(); + } } base.OnClosed(e); } diff --git a/PartPreviewWindow/View3DTransfromPart.cs b/PartPreviewWindow/View3DTransfromPart.cs index 06b60f0ba..9f63c9a9e 100644 --- a/PartPreviewWindow/View3DTransfromPart.cs +++ b/PartPreviewWindow/View3DTransfromPart.cs @@ -408,9 +408,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow AddHandlers(); - // don't load the mesh until we get all the rest of the interface built - meshViewerWidget.LoadMesh(printItemWrapper.FileLocation); - meshViewerWidget.LoadDone += new EventHandler(meshViewerWidget_LoadDone); + if (printItemWrapper != null) + { + // don't load the mesh until we get all the rest of the interface built + meshViewerWidget.LoadMesh(printItemWrapper.FileLocation); + meshViewerWidget.LoadDone += new EventHandler(meshViewerWidget_LoadDone); + } } private void MakeCopyOfMesh() diff --git a/PrinterCommunication/PrinterCommunication.cs b/PrinterCommunication/PrinterCommunication.cs index a17dc3a79..a851b7eeb 100644 --- a/PrinterCommunication/PrinterCommunication.cs +++ b/PrinterCommunication/PrinterCommunication.cs @@ -823,18 +823,18 @@ namespace MatterHackers.MatterControl string lineToParse = foundStringEventArgs.LineToCheck; Vector3 positionRead = Vector3.Zero; - GCodeFile.GetFirstNumberAfter("X:", lineToParse, ref positionRead.x); - GCodeFile.GetFirstNumberAfter("Y:", lineToParse, ref positionRead.y); - GCodeFile.GetFirstNumberAfter("Z:", lineToParse, ref positionRead.z); + GCodeFile.GetFirstNumberAfter('X', lineToParse, ref positionRead.x); + GCodeFile.GetFirstNumberAfter('Y', lineToParse, ref positionRead.y); + GCodeFile.GetFirstNumberAfter('Z', lineToParse, ref positionRead.z); int xPosition = lineToParse.IndexOf('X'); int secondXPosition = lineToParse.IndexOf("Count", xPosition); if (secondXPosition != -1) { Vector3 currentPositionRead = Vector3.Zero; - GCodeFile.GetFirstNumberAfter("X:", lineToParse, ref currentPositionRead.x, secondXPosition - 1); - GCodeFile.GetFirstNumberAfter("Y:", lineToParse, ref currentPositionRead.y, secondXPosition - 1); - GCodeFile.GetFirstNumberAfter("Z:", lineToParse, ref currentPositionRead.z, secondXPosition - 1); + GCodeFile.GetFirstNumberAfter('X', lineToParse, ref currentPositionRead.x, secondXPosition - 1); + GCodeFile.GetFirstNumberAfter('Y', lineToParse, ref currentPositionRead.y, secondXPosition - 1); + GCodeFile.GetFirstNumberAfter('Z', lineToParse, ref currentPositionRead.z, secondXPosition - 1); lastReportedPosition = currentPositionRead; } @@ -1289,9 +1289,9 @@ namespace MatterHackers.MatterControl newDestination = Vector3.Zero; } - GCodeFile.GetFirstNumberAfter("X", lineBeingSent, ref newDestination.x); - GCodeFile.GetFirstNumberAfter("Y", lineBeingSent, ref newDestination.y); - GCodeFile.GetFirstNumberAfter("Z", lineBeingSent, ref newDestination.z); + GCodeFile.GetFirstNumberAfter('X', lineBeingSent, ref newDestination.x); + GCodeFile.GetFirstNumberAfter('Y', lineBeingSent, ref newDestination.y); + GCodeFile.GetFirstNumberAfter('Z', lineBeingSent, ref newDestination.z); if (movementMode == PrinterMachineInstruction.MovementTypes.Relative) { @@ -1318,7 +1318,7 @@ namespace MatterHackers.MatterControl lineBeingSent = lineBeingSent.ToUpper().Trim(); if (lineBeingSent.StartsWith("G0") || lineBeingSent.StartsWith("G1")) { - if (GCodeFile.GetFirstNumberAfter("E", lineBeingSent, ref gcodeRequestedExtrusionPosition)) + if (GCodeFile.GetFirstNumberAfter('E', lineBeingSent, ref gcodeRequestedExtrusionPosition)) { double delta = gcodeRequestedExtrusionPosition - previousGcodeRequestedExtrusionPosition; if (extruderMode == PrinterMachineInstruction.MovementTypes.Relative) @@ -1333,7 +1333,7 @@ namespace MatterHackers.MatterControl } else if (lineBeingSent.StartsWith("G92")) { - if (GCodeFile.GetFirstNumberAfter("E", lineBeingSent, ref gcodeRequestedExtrusionPosition)) + if (GCodeFile.GetFirstNumberAfter('E', lineBeingSent, ref gcodeRequestedExtrusionPosition)) { previousGcodeRequestedExtrusionPosition = gcodeRequestedExtrusionPosition; currentActualExtrusionPosition = gcodeRequestedExtrusionPosition; @@ -1351,7 +1351,7 @@ namespace MatterHackers.MatterControl if (lineBeingSent.StartsWith("G0") || lineBeingSent.StartsWith("G1")) { double feedRate = 0; - if (GCodeFile.GetFirstNumberAfter("F", lineBeingSent, ref feedRate)) + if (GCodeFile.GetFirstNumberAfter('F', lineBeingSent, ref feedRate)) { lineBeingSent = GCodeFile.ReplaceNumberAfter('F', lineBeingSent, feedRate * FeedRateRatio); } diff --git a/PrinterControls/PrintLeveling.cs b/PrinterControls/PrintLeveling.cs index 1e118182b..5c7de53bb 100644 --- a/PrinterControls/PrintLeveling.cs +++ b/PrinterControls/PrintLeveling.cs @@ -85,9 +85,9 @@ namespace MatterHackers.MatterControl && lineBeingSent[2] == ' ') { double extruderDelta = 0; - GCodeFile.GetFirstNumberAfter("E", lineBeingSent, ref extruderDelta); + GCodeFile.GetFirstNumberAfter('E', lineBeingSent, ref extruderDelta); double feedRate = 0; - GCodeFile.GetFirstNumberAfter("F", lineBeingSent, ref feedRate); + GCodeFile.GetFirstNumberAfter('F', lineBeingSent, ref feedRate); string newLine = "G1 "; @@ -97,9 +97,9 @@ namespace MatterHackers.MatterControl if (movementMode == PrinterMachineInstruction.MovementTypes.Relative) { Vector3 relativeMove = Vector3.Zero; - GCodeFile.GetFirstNumberAfter("X", lineBeingSent, ref relativeMove.x); - GCodeFile.GetFirstNumberAfter("Y", lineBeingSent, ref relativeMove.y); - GCodeFile.GetFirstNumberAfter("Z", lineBeingSent, ref relativeMove.z); + GCodeFile.GetFirstNumberAfter('X', lineBeingSent, ref relativeMove.x); + GCodeFile.GetFirstNumberAfter('Y', lineBeingSent, ref relativeMove.y); + GCodeFile.GetFirstNumberAfter('Z', lineBeingSent, ref relativeMove.z); outPosition = PrintLeveling.Instance.ApplyLevelingRotation(relativeMove); }