From 019eb3165beb5e0e4b92545e90770f7a2926e648 Mon Sep 17 00:00:00 2001 From: larsbrubaker Date: Fri, 14 Feb 2014 12:50:55 -0800 Subject: [PATCH] Moved the print leveling code out of PrinterCommunication into ActviePrinterProfile --- ActivePrinterProfile.cs | 69 +++++++++++++++++++++- CustomWidgets/ExportQueueItemWindow.cs | 2 +- PrintLevelWizard.cs | 6 +- PrintLibrary/ExportLibraryItemWindow.cs | 2 +- PrintQueue/ExportToFolderProcess.cs | 2 +- PrintQueue/ExportToSdCardProcess.cs | 2 +- PrinterCommunication.cs | 72 +---------------------- PrinterControls/ManualPrinterControls.cs | 8 +-- SliceConfiguration/ActiveSliceSettings.cs | 6 +- 9 files changed, 84 insertions(+), 85 deletions(-) diff --git a/ActivePrinterProfile.cs b/ActivePrinterProfile.cs index 05d8af95b..d86ad28f5 100644 --- a/ActivePrinterProfile.cs +++ b/ActivePrinterProfile.cs @@ -27,6 +27,7 @@ namespace MatterHackers.MatterControl static ActivePrinterProfile globalInstance = null; public RootedObjectEventHandler ActivePrinterChanged = new RootedObjectEventHandler(); + public RootedObjectEventHandler DoPrintLevelingChanged = new RootedObjectEventHandler(); // private so that it can only be gotten through the Instance ActivePrinterProfile() @@ -92,12 +93,78 @@ namespace MatterHackers.MatterControl } } - public void OnActivePrinterChanged(EventArgs e) { ActivePrinterChanged.CallEvents(this, e); } + public bool DoPrintLeveling + { + get + { + if (ActivePrinter != null) + { + return ActivePrinter.DoPrintLeveling; + } + return false; + } + + set + { + if (ActivePrinter != null && ActivePrinter.DoPrintLeveling != value) + { + ActivePrinter.DoPrintLeveling = value; + DoPrintLevelingChanged.CallEvents(this, null); + ActivePrinter.Commit(); + + if (DoPrintLeveling) + { + PrintLeveling.Instance.SetPrintLevelingEquation( + GetPrintLevelingProbePosition(0), + GetPrintLevelingProbePosition(1), + GetPrintLevelingProbePosition(2), + ActiveSliceSettings.Instance.PrintCenter); + } + } + } + } + + /// + /// This function returns one of the three positions that will be probed when setting + /// up print leveling. + /// + /// + /// + public Vector3 GetPrintLevelingProbePosition(int position0To2) + { + if (ActivePrinter != null) + { + double[] positions = ActivePrinter.GetPrintLevelingPositions(); + switch (position0To2) + { + case 0: + return new Vector3(positions[0], positions[1], positions[2]); + case 1: + return new Vector3(positions[3], positions[4], positions[5]); + case 2: + return new Vector3(positions[6], positions[7], positions[8]); + default: + throw new Exception("there are only 3 probe positions."); + } + } + + return Vector3.Zero; + } + + public void SetPrintLevelingProbePositions(double[] printLevelingPositions3_xyz) + { + if (ActivePrinter != null) + { + ActivePrinter.SetPrintLevelingPositions(printLevelingPositions3_xyz); + ActivePrinter.Commit(); + } + } + public static void CheckForAndDoAutoConnect() { DataStorage.Printer autoConnectProfile = ActivePrinterProfile.GetAutoConnectProfile(); diff --git a/CustomWidgets/ExportQueueItemWindow.cs b/CustomWidgets/ExportQueueItemWindow.cs index ab98f05f4..ccb25611d 100644 --- a/CustomWidgets/ExportQueueItemWindow.cs +++ b/CustomWidgets/ExportQueueItemWindow.cs @@ -141,7 +141,7 @@ namespace MatterHackers.MatterControl private void SaveGCodeToNewLocation(string source, string dest) { - if (PrinterCommunication.Instance.DoPrintLeveling) + if (ActivePrinterProfile.Instance.DoPrintLeveling) { GCodeFile unleveledGCode = new GCodeFile(source); PrintLeveling.Instance.ApplyLeveling(unleveledGCode); diff --git a/PrintLevelWizard.cs b/PrintLevelWizard.cs index 18bf6924d..039a00513 100644 --- a/PrintLevelWizard.cs +++ b/PrintLevelWizard.cs @@ -85,7 +85,7 @@ namespace MatterHackers.MatterControl public override void PageIsBecomingActive() { - PrinterCommunication.Instance.DoPrintLeveling = false; + ActivePrinterProfile.Instance.DoPrintLeveling = false; base.PageIsBecomingActive(); } } @@ -108,9 +108,9 @@ namespace MatterHackers.MatterControl probePositions[1].position.x, probePositions[1].position.y, probePositions[1].position.z, probePositions[2].position.x, probePositions[2].position.y, probePositions[2].position.z, }; - PrinterCommunication.Instance.SetPrintLevelingProbePositions(printLevelPositions3x3); + ActivePrinterProfile.Instance.SetPrintLevelingProbePositions(printLevelPositions3x3); - PrinterCommunication.Instance.DoPrintLeveling = true; + ActivePrinterProfile.Instance.DoPrintLeveling = true; base.PageIsBecomingActive(); } } diff --git a/PrintLibrary/ExportLibraryItemWindow.cs b/PrintLibrary/ExportLibraryItemWindow.cs index 3ca8992b6..f6038739c 100644 --- a/PrintLibrary/ExportLibraryItemWindow.cs +++ b/PrintLibrary/ExportLibraryItemWindow.cs @@ -128,7 +128,7 @@ namespace MatterHackers.MatterControl.PrintLibrary private void SaveGCodeToNewLocation(string source, string dest) { - if (PrinterCommunication.Instance.DoPrintLeveling) + if (ActivePrinterProfile.Instance.DoPrintLeveling) { GCodeFile unleveledGCode = new GCodeFile(source); PrintLeveling.Instance.ApplyLeveling(unleveledGCode); diff --git a/PrintQueue/ExportToFolderProcess.cs b/PrintQueue/ExportToFolderProcess.cs index d4889635d..03bcde744 100644 --- a/PrintQueue/ExportToFolderProcess.cs +++ b/PrintQueue/ExportToFolderProcess.cs @@ -147,7 +147,7 @@ namespace MatterHackers.MatterControl.PrintQueue string outputFileName = Path.ChangeExtension(originalFileName, ".gcode"); string outputPathAndName = Path.Combine(exportPath, outputFileName); - if (PrinterCommunication.Instance.DoPrintLeveling) + if (ActivePrinterProfile.Instance.DoPrintLeveling) { GCodeFile unleveledGCode = new GCodeFile(savedGcodeFileName); PrintLeveling.Instance.ApplyLeveling(unleveledGCode); diff --git a/PrintQueue/ExportToSdCardProcess.cs b/PrintQueue/ExportToSdCardProcess.cs index 2b469a9d9..639077cfd 100644 --- a/PrintQueue/ExportToSdCardProcess.cs +++ b/PrintQueue/ExportToSdCardProcess.cs @@ -143,7 +143,7 @@ namespace MatterHackers.MatterControl.PrintQueue throw new NotImplementedException(); //string outputPathAndName = Path.Combine(exportPath, outputFileName); - if (PrinterCommunication.Instance.DoPrintLeveling) + if (ActivePrinterProfile.Instance.DoPrintLeveling) { GCodeFile unleveledGCode = new GCodeFile(savedGcodeFileName); PrintLeveling.Instance.ApplyLeveling(unleveledGCode); diff --git a/PrinterCommunication.cs b/PrinterCommunication.cs index b897e8da2..63ab0fac1 100644 --- a/PrinterCommunication.cs +++ b/PrinterCommunication.cs @@ -111,7 +111,6 @@ namespace MatterHackers.MatterControl public RootedObjectEventHandler ConnectionStateChanged = new RootedObjectEventHandler(); public RootedObjectEventHandler ConnectionSucceeded = new RootedObjectEventHandler(); public RootedObjectEventHandler DestinationChanged = new RootedObjectEventHandler(); - public RootedObjectEventHandler DoPrintLevelingChanged = new RootedObjectEventHandler(); public RootedObjectEventHandler EnableChanged = new RootedObjectEventHandler(); public RootedObjectEventHandler ExtruderTemperatureRead = new RootedObjectEventHandler(); public RootedObjectEventHandler ExtruderTemperatureSet = new RootedObjectEventHandler(); @@ -204,73 +203,6 @@ namespace MatterHackers.MatterControl Thread sendGCodeToPrinterThread; - public bool DoPrintLeveling - { - get - { - if (ActivePrinter != null) - { - return ActivePrinter.DoPrintLeveling; - } - return false; - } - - set - { - if (ActivePrinter != null && ActivePrinter.DoPrintLeveling != value) - { - ActivePrinter.DoPrintLeveling = value; - DoPrintLevelingChanged.CallEvents(this, null); - ActivePrinter.Commit(); - - if (DoPrintLeveling) - { - PrintLeveling.Instance.SetPrintLevelingEquation( - PrinterCommunication.Instance.GetPrintLevelingProbePosition(0), - PrinterCommunication.Instance.GetPrintLevelingProbePosition(1), - PrinterCommunication.Instance.GetPrintLevelingProbePosition(2), - ActiveSliceSettings.Instance.PrintCenter); - } - } - } - } - - /// - /// This function returns one of the three positions that will be probed when setting - /// up print leveling. - /// - /// - /// - public Vector3 GetPrintLevelingProbePosition(int position0To2) - { - if (ActivePrinter != null) - { - double[] positions = ActivePrinter.GetPrintLevelingPositions(); - switch (position0To2) - { - case 0: - return new Vector3(positions[0], positions[1], positions[2]); - case 1: - return new Vector3(positions[3], positions[4], positions[5]); - case 2: - return new Vector3(positions[6], positions[7], positions[8]); - default: - throw new Exception("there are only 3 probe positions."); - } - } - - return Vector3.Zero; - } - - public void SetPrintLevelingProbePositions(double[] printLevelingPositions3_xyz) - { - if (ActivePrinter != null) - { - ActivePrinter.SetPrintLevelingPositions(printLevelingPositions3_xyz); - ActivePrinter.Commit(); - } - } - public bool DtrEnableOnConnect { get @@ -748,7 +680,7 @@ namespace MatterHackers.MatterControl public void HomeWasWritenToPrinter(object sender, EventArgs e) { - if (DoPrintLeveling) + if (ActivePrinter.DoPrintLeveling) { ReadPosition(); } @@ -1326,7 +1258,7 @@ namespace MatterHackers.MatterControl } } - if (DoPrintLeveling) + if (ActivePrinter.DoPrintLeveling) { lineBeingSent = PrintLeveling.Instance.ApplyLeveling(currentDestination, movementMode, lineBeingSent, addLFCR, includeSpaces); } diff --git a/PrinterControls/ManualPrinterControls.cs b/PrinterControls/ManualPrinterControls.cs index 3dff88aab..184fe60d4 100644 --- a/PrinterControls/ManualPrinterControls.cs +++ b/PrinterControls/ManualPrinterControls.cs @@ -516,17 +516,17 @@ namespace MatterHackers.MatterControl doLevelingCheckBox.Margin = new BorderDouble(left: 3); doLevelingCheckBox.TextColor = ActiveTheme.Instance.PrimaryTextColor; doLevelingCheckBox.VAnchor = VAnchor.ParentCenter; - doLevelingCheckBox.Checked = PrinterCommunication.Instance.DoPrintLeveling; + doLevelingCheckBox.Checked = ActivePrinterProfile.Instance.DoPrintLeveling; buttonBar.AddChild(doLevelingCheckBox); buttonBar.AddChild(runPrintLevelingButton); doLevelingCheckBox.CheckedStateChanged += (sender, e) => { - PrinterCommunication.Instance.DoPrintLeveling = doLevelingCheckBox.Checked; + ActivePrinterProfile.Instance.DoPrintLeveling = doLevelingCheckBox.Checked; }; - PrinterCommunication.Instance.DoPrintLevelingChanged.RegisterEvent((sender, e) => + ActivePrinterProfile.Instance.DoPrintLevelingChanged.RegisterEvent((sender, e) => { - doLevelingCheckBox.Checked = PrinterCommunication.Instance.DoPrintLeveling; + doLevelingCheckBox.Checked = ActivePrinterProfile.Instance.DoPrintLeveling; if (doLevelingCheckBox.Checked && ActivePrinterProfile.Instance.ActivePrinter.PrintLevelingProbePositions == null) { //OpenPrintLevelWizard(); diff --git a/SliceConfiguration/ActiveSliceSettings.cs b/SliceConfiguration/ActiveSliceSettings.cs index 87cdbf1ae..084c0119f 100644 --- a/SliceConfiguration/ActiveSliceSettings.cs +++ b/SliceConfiguration/ActiveSliceSettings.cs @@ -138,9 +138,9 @@ namespace MatterHackers.MatterControl if (ActivePrinterProfile.Instance.ActivePrinter != null) { PrintLeveling.Instance.SetPrintLevelingEquation( - PrinterCommunication.Instance.GetPrintLevelingProbePosition(0), - PrinterCommunication.Instance.GetPrintLevelingProbePosition(1), - PrinterCommunication.Instance.GetPrintLevelingProbePosition(2), + ActivePrinterProfile.Instance.GetPrintLevelingProbePosition(0), + ActivePrinterProfile.Instance.GetPrintLevelingProbePosition(1), + ActivePrinterProfile.Instance.GetPrintLevelingProbePosition(2), ActiveSliceSettings.Instance.PrintCenter); } #endif