diff --git a/MatterControlLib/DesignTools/Primitives/ComponentObject3D.cs b/MatterControlLib/DesignTools/Primitives/ComponentObject3D.cs index b61ff8c65..285a61ea0 100644 --- a/MatterControlLib/DesignTools/Primitives/ComponentObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/ComponentObject3D.cs @@ -149,12 +149,11 @@ namespace MatterHackers.MatterControl.DesignTools } else { - var firtSheet = this.Descendants().FirstOrDefault(); - if (firtSheet != null) + var controledSheet = ControledSheet; + if (controledSheet != null) { // We don't have any cache of the cell content, get the current content - double.TryParse(firtSheet.SheetData.GetCellValue(cellId2), out double value); - cellData2 = value.ToString(); + cellData2 = controledSheet.SheetData.GetCellValue(cellId2); } } @@ -164,6 +163,8 @@ namespace MatterHackers.MatterControl.DesignTools return (null, null); } + private SheetObject3D ControledSheet => this.Descendants().ToArray()[0];//.FirstOrDefault(); + // this.Children.Where(s => s is SheetObject3D).FirstOrDefault() as SheetObject3D; private void RecalculateSheet() { @@ -174,10 +175,10 @@ namespace MatterHackers.MatterControl.DesignTools if (cellData.StartsWith("=")) { var expression = new DoubleOrExpression(cellData); - var firtSheet = this.Descendants().FirstOrDefault(); - if (firtSheet != null) + var controledSheet = ControledSheet; + if (controledSheet != null) { - var cell = firtSheet.SheetData[cellId]; + var cell = controledSheet.SheetData[cellId]; if (cell != null) { cell.Expression = expression.Value(this).ToString(); @@ -189,16 +190,16 @@ namespace MatterHackers.MatterControl.DesignTools if (SurfacedEditors.Any(se => se.StartsWith("!")) && !this.RebuildLocked) { - var firtSheet = this.Descendants().FirstOrDefault(); + var controledSheet = ControledSheet; var componentLock = this.RebuildLock(); - firtSheet.SheetData.Recalculate(); + controledSheet.SheetData.Recalculate(); UiThread.RunOnIdle(() => { // wait until the sheet is done rebuilding (or 30 seconds) var startTime = UiThread.CurrentTimerMs; - while (firtSheet.RebuildLocked + while (controledSheet.RebuildLocked && startTime + 30000 < UiThread.CurrentTimerMs) { Thread.Sleep(1); diff --git a/MatterControlLib/DesignTools/Primitives/SendGCodeObject3D.cs b/MatterControlLib/DesignTools/Primitives/SendGCodeObject3D.cs index 84224db1e..2c38a5fe8 100644 --- a/MatterControlLib/DesignTools/Primitives/SendGCodeObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/SendGCodeObject3D.cs @@ -118,14 +118,17 @@ namespace MatterHackers.MatterControl.DesignTools && lineToWrite.StartsWith("; LAYER_HEIGHT:")) { double layerHeight = 0; + // this gives us the layer height we will be at AFTER this layer is done printing if (GCodeFile.GetFirstNumberAfter("; LAYER_HEIGHT", lineToWrite, ref layerHeight, out _, stopCheckingString: ":")) { - accumulatedLayerHeight += layerHeight; + // check if we are above the accumulated at the start of the layer but before adding in this layer height if (accumulatedLayerHeight > WorldZ) { hasBeenReached = true; yield return $"{GCodeToSend} ; G-Code from Scene Object"; } + + accumulatedLayerHeight += layerHeight; } } } diff --git a/MatterControlLib/DesignTools/Sheets/SheetData.cs b/MatterControlLib/DesignTools/Sheets/SheetData.cs index 772c09b47..9383c7f9c 100644 --- a/MatterControlLib/DesignTools/Sheets/SheetData.cs +++ b/MatterControlLib/DesignTools/Sheets/SheetData.cs @@ -59,38 +59,18 @@ namespace MatterHackers.MatterControl.DesignTools { lock (locker) { - if (!tabelCalculated) - { - BuildTableConstants(); - } - var cell = this[cellId]; if (cell != null) - { - var expression = cell.Expression; + { + return GetCellValue(cell); + } - if (expression.StartsWith("=")) - { - expression = expression.Substring(1); - var evaluator = new Expression(expression.ToLower()); - AddConstants(evaluator); - var value = evaluator.calculate(); - - return value.ToString(); - } - else - { - // return the expression without evaluation - return expression; - } - } - - return "0"; + return "0"; } } - public string EvaluateExpression(string expression) + public string GetCellValue(TableCell cell) { lock (locker) { @@ -99,11 +79,42 @@ namespace MatterHackers.MatterControl.DesignTools BuildTableConstants(); } - if(expression.StartsWith("=")) + var expression = cell.Expression; + + if (expression.StartsWith("=")) { + expression = expression.Substring(1); + var evaluator = new Expression(expression.ToLower()); + AddConstants(evaluator); + var value = evaluator.calculate(); + + return value.ToString(); + } + else + { + // return the expression without evaluation + return expression; + } + } + } + + public string EvaluateExpression(string inExpression) + { + lock (locker) + { + if (!tabelCalculated) + { + BuildTableConstants(); + } + + var expression = inExpression; + + if (expression.StartsWith("=")) + { + // to handle string values we first check if the expression is a cell reference expression = expression.Substring(1).Trim(); - // if it is a direct cell reference than return that cells value + // if it might be a direct cell reference check for column row data if (expression.Length == 2) { var column = (uint)expression.Substring(0, 1).ToUpper()[0] - 'A'; @@ -113,9 +124,24 @@ namespace MatterHackers.MatterControl.DesignTools return GetCellValue(CellId((int)column, (int)row)); } } - } - var evaluator = new Expression(expression.ToLower()); + // check if it is the exact name of a cell + foreach (var row in Rows) + { + foreach (var cell in row.Cells) + { + if (expression.Equals(cell.Name, StringComparison.OrdinalIgnoreCase)) + { + return GetCellValue(cell); + } + } + } + + + // fall through to evaluate the expression + } + + var evaluator = new Expression(expression.ToLower()); AddConstants(evaluator); var value = evaluator.calculate(); diff --git a/MatterControlLib/DesignTools/Sheets/SheetObject3D.cs b/MatterControlLib/DesignTools/Sheets/SheetObject3D.cs index 19f458194..7152e332c 100644 --- a/MatterControlLib/DesignTools/Sheets/SheetObject3D.cs +++ b/MatterControlLib/DesignTools/Sheets/SheetObject3D.cs @@ -507,26 +507,20 @@ namespace MatterHackers.MatterControl.DesignTools return (T)(object)inputExpression; } - if (double.TryParse(inputExpression, out var result)) + double.TryParse(inputExpression, out var result); + + if (typeof(T) == typeof(double)) { - if (typeof(T) == typeof(double)) - { - return (T)(object)result; - } - if (typeof(T) == typeof(int)) - { - return (T)(object)(int)Math.Round(result); - } + return (T)(object)result; + } + if (typeof(T) == typeof(int)) + { + return (T)(object)(int)Math.Round(result); } - if (typeof(T) == typeof(double)) - { - return (T)(object)0; - } - return (T)(object)(int)0; - } - } + } + } /// /// Find the sheet that the given item will reference diff --git a/MatterControlLib/Library/Export/GCodeExport.cs b/MatterControlLib/Library/Export/GCodeExport.cs index c4bfced15..0ada085d8 100644 --- a/MatterControlLib/Library/Export/GCodeExport.cs +++ b/MatterControlLib/Library/Export/GCodeExport.cs @@ -331,9 +331,9 @@ namespace MatterHackers.MatterControl.Library.Export accumulatedStream = new BabyStepsStream(printer, accumulatedStream); - accumulatedStream = new RemoveNOPsStream(printer, accumulatedStream); - accumulatedStream = new RunSceneGCodeProcesorsStream(printer, accumulatedStream, queuedCommandStream); + + accumulatedStream = new RemoveNOPsStream(printer, accumulatedStream); accumulatedStream = new ProcessWriteRegexStream(printer, accumulatedStream, queuedCommandStream); diff --git a/MatterControlLib/Library/Providers/MatterControl/ScriptingPartsContainer.cs b/MatterControlLib/Library/Providers/MatterControl/ScriptingPartsContainer.cs index 08f1477da..018bf6f8b 100644 --- a/MatterControlLib/Library/Providers/MatterControl/ScriptingPartsContainer.cs +++ b/MatterControlLib/Library/Providers/MatterControl/ScriptingPartsContainer.cs @@ -65,6 +65,18 @@ namespace MatterHackers.MatterControl.Library { Category = this.Name }); + + Items.Add(new GeneratorItem( + "Pause".Localize(), + async () => + { + var gcodeObject = await SendGCodeObject3D.Create(); + gcodeObject.GCodeToSend = "M226"; + return gcodeObject; + }) + { + Category = this.Name + }); } private class StaticDataItem : ILibraryAssetStream diff --git a/MatterControlLib/PartPreviewWindow/SelectedObjectPanel.cs b/MatterControlLib/PartPreviewWindow/SelectedObjectPanel.cs index 5edd51bf9..fb639bd90 100644 --- a/MatterControlLib/PartPreviewWindow/SelectedObjectPanel.cs +++ b/MatterControlLib/PartPreviewWindow/SelectedObjectPanel.cs @@ -595,23 +595,14 @@ namespace MatterHackers.MatterControl.PartPreviewWindow if (cell != null) { // create an expresion editor - var field = new ExpressionField(theme) + var field = new TextField(theme) { - Name = cellId + " Field" + Name = cellId + " Field", }; field.Initialize(0); - if (cellData.Contains("=")) - { - field.SetValue(cellData, false); - } - else // make sure it is formatted - { - double.TryParse(cellData, out double value); - var format = "0." + new string('#', 5); - field.SetValue(value.ToString(format), false); - } - - field.ClearUndoHistory(); + field.SetValue(cellData, false); + field.ClearUndoHistory(); + field.Content.HAnchor = HAnchor.Stretch; var doOrUndoing = false; field.ValueChanged += (s, e) => @@ -624,7 +615,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { doOrUndoing = true; editorList[editorIndex] = "!" + cellId + "," + oldValue; - var expression = new DoubleOrExpression(oldValue); + var expression = new StringOrExpression(oldValue); cell.Expression = expression.Value(componentObject).ToString(); componentObject.Invalidate(InvalidateType.SheetUpdated); doOrUndoing = false; @@ -633,7 +624,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { doOrUndoing = true; editorList[editorIndex] = "!" + cellId + "," + newValue; - var expression = new DoubleOrExpression(newValue); + var expression = new StringOrExpression(newValue); cell.Expression = expression.Value(componentObject).ToString(); componentObject.Invalidate(InvalidateType.SheetUpdated); doOrUndoing = false; diff --git a/MatterControlLib/PrinterCommunication/PrinterConnection.cs b/MatterControlLib/PrinterCommunication/PrinterConnection.cs index 915d90483..ecf76c6e8 100644 --- a/MatterControlLib/PrinterCommunication/PrinterConnection.cs +++ b/MatterControlLib/PrinterCommunication/PrinterConnection.cs @@ -2442,8 +2442,6 @@ Make sure that your printer is turned on. Some printers will appear to be connec { accumulatedStream = new SendProgressStream(gCodeFileSwitcher, Printer); } - - accumulatedStream = pauseHandlingStream = new PauseHandlingStream(Printer, accumulatedStream); } else { @@ -2494,8 +2492,9 @@ Make sure that your printer is turned on. Some printers will appear to be connec accumulatedStream = softwareEndstopsExStream12; } - accumulatedStream = new RemoveNOPsStream(Printer, accumulatedStream); + accumulatedStream = pauseHandlingStream = new PauseHandlingStream(Printer, accumulatedStream); accumulatedStream = new RunSceneGCodeProcesorsStream(Printer, accumulatedStream, queuedCommandStream); + accumulatedStream = new RemoveNOPsStream(Printer, accumulatedStream); processWriteRegexStream = new ProcessWriteRegexStream(Printer, accumulatedStream, queuedCommandStream); accumulatedStream = processWriteRegexStream; diff --git a/StaticData/Images/Thumbnails/11153474566755746919-256x256.png b/StaticData/Images/Thumbnails/11153474566755746919-256x256.png new file mode 100644 index 000000000..46a4bbf97 Binary files /dev/null and b/StaticData/Images/Thumbnails/11153474566755746919-256x256.png differ