diff --git a/MatterControl.Printing/GCode/GCodeMemoryFile.cs b/MatterControl.Printing/GCode/GCodeMemoryFile.cs index 12b438117..797d164c8 100644 --- a/MatterControl.Printing/GCode/GCodeMemoryFile.cs +++ b/MatterControl.Printing/GCode/GCodeMemoryFile.cs @@ -26,7 +26,6 @@ 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. */ -#define MULTI_THREAD #define DUMP_SLOW_TIMES using System; @@ -727,28 +726,10 @@ namespace MatterControl.Printing public override Vector2 GetWeightedCenter() { Vector2 total = new Vector2(); -#if !MULTI_THREAD - foreach (PrinterMachineInstruction state in GCodeCommandQueue) - { - total += new Vector2(state.Position.x, state.Position.y); - } -#else - Parallel.For( - 0, - GCodeCommandQueue.Count, - () => new Vector2(), - (int index, ParallelLoopState loop, Vector2 subtotal) => - { - PrinterMachineInstruction state = GCodeCommandQueue[index]; - subtotal += new Vector2(state.Position.X, state.Position.Y); - return subtotal; - }, -(Action)((x) => - { - total += new Vector2(x.X, (double)x.Y); - }) - ); -#endif + foreach (PrinterMachineInstruction state in GCodeCommandQueue) + { + total += new Vector2(state.Position.X, state.Position.Y); + } return total / GCodeCommandQueue.Count; } @@ -756,38 +737,14 @@ namespace MatterControl.Printing public override RectangleDouble GetBounds() { RectangleDouble bounds = new RectangleDouble(double.MaxValue, double.MaxValue, double.MinValue, double.MinValue); -#if !MULTI_THREAD - foreach (PrinterMachineInstruction state in GCodeCommandQueue) - { - bounds.Left = Math.Min(state.Position.x, bounds.Left); - bounds.Right = Math.Max(state.Position.x, bounds.Right); - bounds.Bottom = Math.Min(state.Position.y, bounds.Bottom); - bounds.Top = Math.Max(state.Position.y, bounds.Top); - } -#else - Parallel.For( - 0, - GCodeCommandQueue.Count, - () => new RectangleDouble(double.MaxValue, double.MaxValue, double.MinValue, double.MinValue), - (int index, ParallelLoopState loop, RectangleDouble subtotal) => - { - PrinterMachineInstruction state = GCodeCommandQueue[index]; - subtotal.Left = Math.Min(state.Position.X, subtotal.Left); - subtotal.Right = Math.Max(state.Position.X, subtotal.Right); - subtotal.Bottom = Math.Min(state.Position.Y, subtotal.Bottom); - subtotal.Top = Math.Max(state.Position.Y, subtotal.Top); + foreach (PrinterMachineInstruction state in GCodeCommandQueue) + { + bounds.Left = Math.Min(state.Position.X, bounds.Left); + bounds.Right = Math.Max(state.Position.X, bounds.Right); + bounds.Bottom = Math.Min(state.Position.Y, bounds.Bottom); + bounds.Top = Math.Max(state.Position.Y, bounds.Top); + } - return subtotal; - }, - (x) => - { - bounds.Left = Math.Min(x.Left, bounds.Left); - bounds.Right = Math.Max(x.Right, bounds.Right); - bounds.Bottom = Math.Min(x.Bottom, bounds.Bottom); - bounds.Top = Math.Max(x.Top, bounds.Top); - } - ); -#endif return bounds; } diff --git a/PartPreviewWindow/GCode2DWidget.cs b/PartPreviewWindow/GCode2DWidget.cs index 5d3b85360..28cf94d34 100644 --- a/PartPreviewWindow/GCode2DWidget.cs +++ b/PartPreviewWindow/GCode2DWidget.cs @@ -49,7 +49,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow private Vector2 lastMousePosition = new Vector2(0, 0); private Vector2 mouseDownPosition = new Vector2(0, 0); - private double layerScale = 1; + private double layerScale { get; set; } = 1; private Vector2 gridSizeMm; private Vector2 gridCenterMm; @@ -96,6 +96,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { if (loadedGCode != null) { + if(layerScale == 0) + { + CenterPartInView(); + } //using (new PerformanceTimer("GCode Timer", "Total")) { Affine transform = totalTransform; diff --git a/PartPreviewWindow/PrinterTabPage.cs b/PartPreviewWindow/PrinterTabPage.cs index 552a222d2..c18320bb1 100644 --- a/PartPreviewWindow/PrinterTabPage.cs +++ b/PartPreviewWindow/PrinterTabPage.cs @@ -203,9 +203,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { case PartViewMode.Layers2D: UserSettings.Instance.set("LayerViewDefault", "2D Layer"); - // HACK: Getting the Layer2D view to show content only works if CenterPartInView is called after the control is visible and after some cycles have passed gcode2DWidget.Visible = true; - UiThread.RunOnIdle(gcode2DWidget.CenterPartInView); break; case PartViewMode.Layers3D: