From eec0211b3bf54a0d1eb6fb596e3986117e035cf8 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Wed, 21 Jan 2015 11:45:42 -0800 Subject: [PATCH] Made the terminal window in 32 bit be limited to 10 megs of cache. --- .../PrinterSettings/PrinterSettingsView.cs | 10 +-- .../TerminalWindow/PrinterOutputCache.cs | 21 +++++ .../TerminalWindow/TextScrollWidget.cs | 82 ++++++++++--------- 3 files changed, 69 insertions(+), 44 deletions(-) diff --git a/ConfigurationPage/PrinterSettings/PrinterSettingsView.cs b/ConfigurationPage/PrinterSettings/PrinterSettingsView.cs index bba49b979..2771a8e84 100644 --- a/ConfigurationPage/PrinterSettings/PrinterSettingsView.cs +++ b/ConfigurationPage/PrinterSettings/PrinterSettingsView.cs @@ -328,14 +328,12 @@ namespace MatterHackers.MatterControl.ConfigurationPage }); } - void openGcodeTerminalButton_Click(object sender, EventArgs mouseEvent) + void openGcodeTerminalButton_Click(object sender, EventArgs mouseEvent) { - UiThread.RunOnIdle((state) => - { - TerminalWindow.Show(); - }); - + { + TerminalWindow.Show(); + }); } private void onPrinterStatusChanged(object sender, EventArgs e) diff --git a/PrinterControls/TerminalWindow/PrinterOutputCache.cs b/PrinterControls/TerminalWindow/PrinterOutputCache.cs index 68caaec44..6866e56f1 100644 --- a/PrinterControls/TerminalWindow/PrinterOutputCache.cs +++ b/PrinterControls/TerminalWindow/PrinterOutputCache.cs @@ -55,9 +55,21 @@ namespace MatterHackers.MatterControl } } + static bool Is32Bit() + { + if (IntPtr.Size == 4) + { + return true; + } + + return false; + } + + public List PrinterLines = new List(); public RootedObjectEventHandler HasChanged = new RootedObjectEventHandler(); + int maxLinesToBuffer = int.MaxValue - 1; event EventHandler unregisterEvents; PrinterOutputCache() @@ -65,11 +77,20 @@ namespace MatterHackers.MatterControl PrinterConnectionAndCommunication.Instance.ConnectionFailed.RegisterEvent(Instance_ConnectionFailed, ref unregisterEvents); PrinterConnectionAndCommunication.Instance.CommunicationUnconditionalFromPrinter.RegisterEvent(FromPrinter, ref unregisterEvents); PrinterConnectionAndCommunication.Instance.CommunicationUnconditionalToPrinter.RegisterEvent(ToPrinter, ref unregisterEvents); + if (Is32Bit()) + { + // About 10 megs worth. Average line length in gcode file is about 14 and we store strings as chars (16 bit) so 450,000 lines. + maxLinesToBuffer = 450000; + } } void OnHasChanged(EventArgs e) { HasChanged.CallEvents(this, e); + if (PrinterLines.Count > maxLinesToBuffer) + { + Clear(); + } } void FromPrinter(Object sender, EventArgs e) diff --git a/PrinterControls/TerminalWindow/TextScrollWidget.cs b/PrinterControls/TerminalWindow/TextScrollWidget.cs index d9e3acfcd..2eb6617ac 100644 --- a/PrinterControls/TerminalWindow/TextScrollWidget.cs +++ b/PrinterControls/TerminalWindow/TextScrollWidget.cs @@ -135,12 +135,15 @@ namespace MatterHackers.MatterControl void CreateFilteredList() { - visibleLines = new List(); - List allSourceLinesTemp = new List(allSourceLines); - foreach (string line in allSourceLinesTemp) - { - ConditionalyAddToVisible(line); - } + using (TimedLock.Lock(this, "CreatingFilteredList")) + { + visibleLines = new List(); + List allSourceLinesTemp = new List(allSourceLines); + foreach (string line in allSourceLinesTemp) + { + ConditionalyAddToVisible(line); + } + } } public void SetLineStartFilter(string[] startLineStringsToFilter) @@ -178,39 +181,42 @@ namespace MatterHackers.MatterControl int numLinesToDraw = NumVisibleLines; double y = LocalBounds.Bottom + printer.TypeFaceStyle.EmSizeInPixels * numLinesToDraw; - int startLineIndex = visibleLines.Count - numLinesToDraw; - if (forceStartLine != -1) - { - y = LocalBounds.Top; + using (TimedLock.Lock(this, "DrawingLines")) + { + int startLineIndex = visibleLines.Count - numLinesToDraw; + if (forceStartLine != -1) + { + y = LocalBounds.Top; - if (forceStartLine > visibleLines.Count - numLinesToDraw) - { - forceStartLine = -1; - } - else - { - // make sure we show all the lines we can - startLineIndex = Math.Min(forceStartLine, startLineIndex); - } - } - int endLineIndex = visibleLines.Count; - for (int lineIndex = startLineIndex; lineIndex < endLineIndex; lineIndex++) - { - if (lineIndex >= 0) - { - if (visibleLines[lineIndex] != null) - { - printer.Text = visibleLines[lineIndex]; - printer.Origin = new Vector2(Bounds.Left + 2, y); - printer.Render(graphics2D, TextColor); - } - } - y -= printer.TypeFaceStyle.EmSizeInPixels; - if (y < -printer.TypeFaceStyle.EmSizeInPixels) - { - break; - } - } + if (forceStartLine > visibleLines.Count - numLinesToDraw) + { + forceStartLine = -1; + } + else + { + // make sure we show all the lines we can + startLineIndex = Math.Min(forceStartLine, startLineIndex); + } + } + int endLineIndex = visibleLines.Count; + for (int lineIndex = startLineIndex; lineIndex < endLineIndex; lineIndex++) + { + if (lineIndex >= 0) + { + if (visibleLines[lineIndex] != null) + { + printer.Text = visibleLines[lineIndex]; + printer.Origin = new Vector2(Bounds.Left + 2, y); + printer.Render(graphics2D, TextColor); + } + } + y -= printer.TypeFaceStyle.EmSizeInPixels; + if (y < -printer.TypeFaceStyle.EmSizeInPixels) + { + break; + } + } + } base.OnDraw(graphics2D); }