示例#1
0
        public XyCalibrationStartPrintPage(XyCalibrationWizard calibrationWizard)
            : base(calibrationWizard)
        {
            this.WindowTitle = "Nozzle Offset Calibration Wizard".Localize();
            this.HeaderText  = "Nozzle Offset Calibration".Localize();
            this.Name        = "Nozzle Offset Calibration Wizard";

            var content = "Here is what we are going to do:".Localize();

            content += "\n\n    • " + "Stash your current bed".Localize();
            content += "\n    • " + "Print the calibration object".Localize();
            content += "\n    • " + "Collect data".Localize();
            content += "\n    • " + "Restore your current bed, after all calibration is complete".Localize();

            contentRow.AddChild(this.CreateTextField(content));

            contentRow.Padding = theme.DefaultContainerPadding;

            this.NextButton.Visible = false;

            var startCalibrationPrint = theme.CreateDialogButton("Start Print".Localize());

            startCalibrationPrint.Name   = "Start Calibration Print";
            startCalibrationPrint.Click += async(s, e) =>
            {
                var scene = new Object3D();

                // create the calibration objects
                IObject3D item = await CreateCalibrationObject(printer, calibrationWizard);

                // add the calibration object to the bed
                scene.Children.Add(item);

                // move the part to the center of the bed
                var bedBounds = printer.Bed.Bounds;
                var aabb      = item.GetAxisAlignedBoundingBox();
                item.Matrix *= Matrix4X4.CreateTranslation(bedBounds.Center.X - aabb.MinXYZ.X - aabb.XSize / 2, bedBounds.Center.Y - aabb.MinXYZ.Y - aabb.YSize / 2, -aabb.MinXYZ.Z);

                // register callbacks for print completion
                printer.Connection.Disposed                  += this.Connection_Disposed;
                printer.Connection.PrintCanceled             += this.Connection_PrintCanceled;
                printer.Connection.CommunicationStateChanged += this.Connection_CommunicationStateChanged;

                this.MoveToNextPage();

                // hide this window
                this.DialogWindow.Visible = false;

                string gcodePath = EditContext.GCodeFilePath(printer, scene);

                printer.Connection.CommunicationState = CommunicationStates.PreparingToPrint;

                (bool slicingSucceeded, string finalGCodePath) = await ApplicationController.Instance.SliceItemLoadOutput(
                    printer,
                    scene,
                    gcodePath);

                // Only start print if slicing completed
                if (slicingSucceeded)
                {
                    await printer.Bed.LoadContent(new EditContext()
                    {
                        SourceItem   = new FileSystemFileItem(gcodePath),
                        ContentStore = null                         // No content store for GCode
                    });

                    await printer.Connection.StartPrint(finalGCodePath, allowRecovery : false);

                    ApplicationController.Instance.MonitorPrintTask(printer);
                }
                else
                {
                    printer.Connection.CommunicationState = CommunicationStates.Connected;
                }
            };

            theme.ApplyPrimaryActionStyle(startCalibrationPrint);

            this.AddPageAction(startCalibrationPrint);
        }