public void SetPrintLevelingEquation(Vector3 position0, Vector3 position1, Vector3 position2, Vector2 bedCenter) { if (position0 == position1 || position1 == position2 || position2 == position0) { return; } Plane planeOfPoints = new Plane(position0, position1, position2); Ray ray = new Ray(new Vector3(bedCenter, 0), Vector3.UnitZ); bool inFront; double distanceToPlaneAtBedCenter = planeOfPoints.GetDistanceToIntersection(ray, out inFront); Matrix4X4 makePointsFlatMatrix = Matrix4X4.CreateTranslation(-bedCenter.x, -bedCenter.y, -distanceToPlaneAtBedCenter); makePointsFlatMatrix *= Matrix4X4.CreateRotation(planeOfPoints.planeNormal, Vector3.UnitZ); makePointsFlatMatrix *= Matrix4X4.CreateTranslation(bedCenter.x, bedCenter.y, 0); //distanceToPlaneAtBedCenter); bedLevelMatrix = Matrix4X4.Invert(makePointsFlatMatrix); { // test that the points come back as 0 zs Vector3 outPosition0 = Vector3.TransformPosition(position0, makePointsFlatMatrix); Vector3 outPosition1 = Vector3.TransformPosition(position1, makePointsFlatMatrix); Vector3 outPosition2 = Vector3.TransformPosition(position2, makePointsFlatMatrix); Vector3 printPosition0 = new Vector3(LevelWizardBase.GetPrintLevelPositionToSample(0), 0); Vector3 printPosition1 = new Vector3(LevelWizardBase.GetPrintLevelPositionToSample(1), 0); Vector3 printPosition2 = new Vector3(LevelWizardBase.GetPrintLevelPositionToSample(2), 0); Vector3 leveledPositon0 = Vector3.TransformPosition(printPosition0, bedLevelMatrix); Vector3 leveledPositon1 = Vector3.TransformPosition(printPosition1, bedLevelMatrix); Vector3 leveledPositon2 = Vector3.TransformPosition(printPosition2, bedLevelMatrix); } }
void ExportToSdCard_Click(object state) { if (applyLeveling != null && applyLeveling.Checked) // check if the user wants that output leveled { // Check if the printer needs to run calibration to print PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(ActivePrinterProfile.Instance.ActivePrinter); if (levelingData != null && levelingData.needsPrintLeveling && levelingData.sampledPosition0.z == 0 && levelingData.sampledPosition1.z == 0 && levelingData.sampledPosition2.z == 0) { LevelWizardBase.ShowPrintLevelWizard(LevelWizardBase.RuningState.InitialStartupCalibration); // we will exit and not export until the printe has been leveled Close(); return; } } // set the printer to this item PrinterConnectionAndCommunication.Instance.ActivePrintItem = printItemWrapper; // tell the printer to save to sd. StringBuilder commands = new StringBuilder(); string sdUsableName = Get8Name(printItemWrapper.Name); commands.AppendLine("M28 {0}.gco".FormatWith(sdUsableName)); // Begin write to SD card PrinterConnectionAndCommunication.Instance.SendLineToPrinterNow(commands.ToString()); // check if we need to turn off the print leveling levelingEnabledStateBeforeSdOutput = ActivePrinterProfile.Instance.DoPrintLeveling; if (applyLeveling != null && !applyLeveling.Checked) { ActivePrinterProfile.Instance.DoPrintLeveling = false; } // Tell the printer we are getting ready to print PrinterConnectionAndCommunication.Instance.CommunicationState = PrinterConnectionAndCommunication.CommunicationStates.PreparingToPrintToSd; // slice the part or start the gcode printing Close(); PrintItemWrapper partToPrint = PrinterConnectionAndCommunication.Instance.ActivePrintItem; SlicingQueue.Instance.QueuePartForSlicing(partToPrint); partToPrint.SlicingDone.RegisterEvent(PartSlicedStartPrintingToSd, ref unregisterEvents); // register to know when the print finishes so we can close the sd save PrinterConnectionAndCommunication.Instance.PrintFinished.RegisterEvent(DoneWritingToSdCard, ref unregisterEvents); }
private FlowLayoutWidget GetAutoLevelControl() { FlowLayoutWidget buttonRow = new FlowLayoutWidget(); buttonRow.HAnchor = HAnchor.ParentLeftRight; buttonRow.Margin = new BorderDouble(0, 4); TextWidget notificationSettingsLabel = new TextWidget("Software Print Leveling"); notificationSettingsLabel.AutoExpandBoundsToText = true; notificationSettingsLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor; notificationSettingsLabel.VAnchor = VAnchor.ParentCenter; Button editButton = textImageButtonFactory.GenerateEditButton(); editButton.VAnchor = Agg.UI.VAnchor.ParentCenter; editButton.Click += (sender, e) => { UiThread.RunOnIdle(() => { if (editLevelingSettingsWindow == null) { editLevelingSettingsWindow = new EditLevelingSettingsWindow(); editLevelingSettingsWindow.Closed += (sender2, e2) => { editLevelingSettingsWindow = null; }; } else { editLevelingSettingsWindow.BringToFront(); } }); }; Button runPrintLevelingButton = textImageButtonFactory.Generate("Configure".Localize().ToUpper()); runPrintLevelingButton.Margin = new BorderDouble(left: 6); runPrintLevelingButton.VAnchor = VAnchor.ParentCenter; runPrintLevelingButton.Click += (sender, e) => { UiThread.RunOnIdle(() => { LevelWizardBase.ShowPrintLevelWizard(LevelWizardBase.RuningState.UserRequestedCalibration); }); }; Agg.Image.ImageBuffer levelingImage = StaticData.Instance.LoadIcon(Path.Combine("PrintStatusControls", "leveling-24x24.png")); if (!ActiveTheme.Instance.IsDarkTheme) { InvertLightness.DoInvertLightness(levelingImage); } ImageWidget levelingIcon = new ImageWidget(levelingImage); levelingIcon.Margin = new BorderDouble(right: 6); CheckBox printLevelingSwitch = ImageButtonFactory.CreateToggleSwitch(ActivePrinterProfile.Instance.DoPrintLeveling); printLevelingSwitch.VAnchor = VAnchor.ParentCenter; printLevelingSwitch.Margin = new BorderDouble(left: 16); printLevelingSwitch.CheckedStateChanged += (sender, e) => { ActivePrinterProfile.Instance.DoPrintLeveling = printLevelingSwitch.Checked; }; printLevelingStatusLabel = new TextWidget(""); printLevelingStatusLabel.AutoExpandBoundsToText = true; printLevelingStatusLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor; printLevelingStatusLabel.VAnchor = VAnchor.ParentCenter; GuiWidget hSpacer = new GuiWidget(); hSpacer.HAnchor = HAnchor.ParentLeftRight; ActivePrinterProfile.Instance.DoPrintLevelingChanged.RegisterEvent((sender, e) => { SetPrintLevelButtonVisiblity(); printLevelingSwitch.Checked = ActivePrinterProfile.Instance.DoPrintLeveling; }, ref unregisterEvents); buttonRow.AddChild(levelingIcon); buttonRow.AddChild(printLevelingStatusLabel); buttonRow.AddChild(editButton); buttonRow.AddChild(new HorizontalSpacer()); buttonRow.AddChild(runPrintLevelingButton); buttonRow.AddChild(printLevelingSwitch); SetPrintLevelButtonVisiblity(); return(buttonRow); }
private FlowLayoutWidget GetAutoLevelControl() { FlowLayoutWidget buttonRow = new FlowLayoutWidget(); buttonRow.Name = "AutoLevelRowItem"; buttonRow.HAnchor = HAnchor.ParentLeftRight; buttonRow.Margin = new BorderDouble(0, 4); ImageBuffer levelingImage = StaticData.Instance.LoadIcon("leveling_32x32.png", 24, 24).InvertLightness(); if (!ActiveTheme.Instance.IsDarkTheme) { levelingImage.InvertLightness(); } ImageWidget levelingIcon = new ImageWidget(levelingImage); levelingIcon.Margin = new BorderDouble(right: 6); buttonRow.AddChild(levelingIcon); // label printLevelingStatusLabel = new TextWidget("") { AutoExpandBoundsToText = true, TextColor = ActiveTheme.Instance.PrimaryTextColor, VAnchor = VAnchor.ParentCenter, Text = "Software Print Leveling".Localize() }; buttonRow.AddChild(printLevelingStatusLabel); // edit button Button editButton = TextImageButtonFactory.GetThemedEditButton(); editButton.Margin = new BorderDouble(2, 2, 2, 0); editButton.VAnchor = Agg.UI.VAnchor.ParentTop; editButton.VAnchor = VAnchor.ParentCenter; editButton.Click += (sender, e) => { UiThread.RunOnIdle(() => { if (editLevelingSettingsWindow == null) { editLevelingSettingsWindow = new EditLevelingSettingsWindow(); editLevelingSettingsWindow.Closed += (sender2, e2) => { editLevelingSettingsWindow = null; }; } else { editLevelingSettingsWindow.BringToFront(); } }); }; buttonRow.AddChild(editButton); buttonRow.AddChild(new HorizontalSpacer()); // configure button runPrintLevelingButton = textImageButtonFactory.Generate("Configure".Localize().ToUpper()); runPrintLevelingButton.Margin = new BorderDouble(left: 6); runPrintLevelingButton.VAnchor = VAnchor.ParentCenter; runPrintLevelingButton.Click += (sender, e) => { UiThread.RunOnIdle(() => LevelWizardBase.ShowPrintLevelWizard(LevelWizardBase.RuningState.UserRequestedCalibration)); }; buttonRow.AddChild(runPrintLevelingButton); // put in the switch CheckBox printLevelingSwitch = ImageButtonFactory.CreateToggleSwitch(ActiveSliceSettings.Instance.GetValue <bool>(SettingsKey.print_leveling_enabled)); printLevelingSwitch.VAnchor = VAnchor.ParentCenter; printLevelingSwitch.Margin = new BorderDouble(left: 16); printLevelingSwitch.CheckedStateChanged += (sender, e) => { ActiveSliceSettings.Instance.Helpers.DoPrintLeveling(printLevelingSwitch.Checked); }; PrinterSettings.PrintLevelingEnabledChanged.RegisterEvent((sender, e) => { printLevelingSwitch.Checked = ActiveSliceSettings.Instance.GetValue <bool>(SettingsKey.print_leveling_enabled); }, ref unregisterEvents); // only show the switch if leveling can be turned off (it can't if it is required). if (!ActiveSliceSettings.Instance.GetValue <bool>(SettingsKey.print_leveling_required_to_print)) { buttonRow.AddChild(printLevelingSwitch); } return(buttonRow); }
private GuiWidget CreatePrintLevelingControlsContainer() { Button editButton; AltGroupBox printLevelingControlsContainer = new AltGroupBox(textImageButtonFactory.GenerateGroupBoxLabelWithEdit(LocalizedString.Get("Automatic Calibration"), out editButton)); editButton.Click += (sender, e) => { UiThread.RunOnIdle((state) => { if (editLevelingSettingsWindow == null) { editLevelingSettingsWindow = new EditLevelingSettingsWindow(); editLevelingSettingsWindow.Closed += (sender2, e2) => { editLevelingSettingsWindow = null; }; } else { editLevelingSettingsWindow.BringToFront(); } }); }; printLevelingControlsContainer.Margin = new BorderDouble(0); printLevelingControlsContainer.TextColor = ActiveTheme.Instance.PrimaryTextColor; printLevelingControlsContainer.BorderColor = ActiveTheme.Instance.PrimaryTextColor; printLevelingControlsContainer.HAnchor = Agg.UI.HAnchor.ParentLeftRight; printLevelingControlsContainer.Height = 68; { FlowLayoutWidget buttonBar = new FlowLayoutWidget(); buttonBar.HAnchor |= HAnchor.ParentLeftRight; buttonBar.VAnchor |= Agg.UI.VAnchor.ParentCenter; buttonBar.Margin = new BorderDouble(0, 0, 0, 0); buttonBar.Padding = new BorderDouble(0); this.textImageButtonFactory.FixedHeight = TallButtonHeight; Button runPrintLevelingButton = textImageButtonFactory.Generate("Configure".Localize().ToUpper()); runPrintLevelingButton.Margin = new BorderDouble(left: 6); runPrintLevelingButton.VAnchor = VAnchor.ParentCenter; runPrintLevelingButton.Click += (sender, e) => { UiThread.RunOnIdle((state) => { LevelWizardBase.ShowPrintLevelWizard(LevelWizardBase.RuningState.UserRequestedCalibration); }); }; Agg.Image.ImageBuffer levelingImage = new Agg.Image.ImageBuffer(); ImageIO.LoadImageData(Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "Icons", "PrintStatusControls", "leveling-24x24.png"), levelingImage); if (!ActiveTheme.Instance.IsDarkTheme) { InvertLightness.DoInvertLightness(levelingImage); } ImageWidget levelingIcon = new ImageWidget(levelingImage); levelingIcon.Margin = new BorderDouble(right: 6); enablePrintLevelingButton = textImageButtonFactory.Generate("Enable".Localize().ToUpper()); enablePrintLevelingButton.Margin = new BorderDouble(left: 6); enablePrintLevelingButton.VAnchor = VAnchor.ParentCenter; enablePrintLevelingButton.Click += new EventHandler(enablePrintLeveling_Click); disablePrintLevelingButton = textImageButtonFactory.Generate("Disable".Localize().ToUpper()); disablePrintLevelingButton.Margin = new BorderDouble(left: 6); disablePrintLevelingButton.VAnchor = VAnchor.ParentCenter; disablePrintLevelingButton.Click += new EventHandler(disablePrintLeveling_Click); printLevelingStatusLabel = new TextWidget(""); printLevelingStatusLabel.AutoExpandBoundsToText = true; printLevelingStatusLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor; printLevelingStatusLabel.VAnchor = VAnchor.ParentCenter; GuiWidget hSpacer = new GuiWidget(); hSpacer.HAnchor = HAnchor.ParentLeftRight; buttonBar.AddChild(levelingIcon); buttonBar.AddChild(printLevelingStatusLabel); buttonBar.AddChild(hSpacer); buttonBar.AddChild(enablePrintLevelingButton); buttonBar.AddChild(disablePrintLevelingButton); buttonBar.AddChild(runPrintLevelingButton); ActivePrinterProfile.Instance.DoPrintLevelingChanged.RegisterEvent((sender, e) => { SetPrintLevelButtonVisiblity(); }, ref unregisterEvents); printLevelingControlsContainer.AddChild(buttonBar); } SetPrintLevelButtonVisiblity(); return(printLevelingControlsContainer); }