Moved the print leveling code out of PrinterCommunication into ActviePrinterProfile

This commit is contained in:
larsbrubaker 2014-02-14 12:50:55 -08:00
parent ecabfa08b5
commit 019eb3165b
9 changed files with 84 additions and 85 deletions

View file

@ -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);
}
}
}
}
/// <summary>
/// This function returns one of the three positions that will be probed when setting
/// up print leveling.
/// </summary>
/// <param name="position0To2"></param>
/// <returns></returns>
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();

View file

@ -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);

View file

@ -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();
}
}

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);
}
}
}
}
/// <summary>
/// This function returns one of the three positions that will be probed when setting
/// up print leveling.
/// </summary>
/// <param name="position0To2"></param>
/// <returns></returns>
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);
}

View file

@ -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();

View file

@ -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