Exemplo n.º 1
0
        private static GuiWidget MatterControlToolTipWidget(string toolTipText)
        {
            var toolTipPopover = new ClickablePopover(ArrowDirection.Up, new BorderDouble(0, 0), 7, 0);

            var markdownWidegt = new MarkdownWidget(Theme, false)
            {
                HAnchor         = HAnchor.Absolute,
                VAnchor         = VAnchor.Fit,
                Width           = 350 * GuiWidget.DeviceScale,
                BackgroundColor = Theme.BackgroundColor,
                Border          = 1,
                BorderColor     = Color.Black,
            };

            markdownWidegt.Markdown = toolTipText;
            markdownWidegt.Width    = 350;
            var maxLineWidth = 0.0;

            if (markdownWidegt.Descendants <ParagraphX>().Any())
            {
                maxLineWidth = markdownWidegt.Descendants <ParagraphX>().Max(i => i.MaxLineWidth);
            }

            markdownWidegt.Width = maxLineWidth + 15;

            return(markdownWidegt);
        }
Exemplo n.º 2
0
        public static WizardPage GetLevelXCarriagePage(ISetupWizard setupWizard, PrinterConfig printer)
        {
            var levelXCarriagePage = new WizardPage(setupWizard, "Level X Carriage".Localize(), "")
            {
                PageLoad = (page) =>
                {
                    // release the motors so the z-axis can be moved
                    printer.Connection.ReleaseMotors();

                    var markdownText   = printer.Settings.GetValue(SettingsKey.level_x_carriage_markdown);
                    var markdownWidget = new MarkdownWidget(ApplicationController.Instance.Theme);
                    markdownWidget.Markdown = markdownText = markdownText.Replace("\\n", "\n");
                    page.ContentRow.AddChild(markdownWidget);
                },
                PageClose = () =>
                {
                    // home the printer again to make sure we are ready to level (same behavior as homing page)
                    printer.Connection.HomeAxis(PrinterConnection.Axis.XYZ);

                    if (!printer.Settings.GetValue <bool>(SettingsKey.z_homes_to_max))
                    {
                        // move so we don't heat the printer while the nozzle is touching the bed
                        printer.Connection.MoveAbsolute(PrinterConnection.Axis.Z, 10, printer.Settings.Helpers.ManualMovementSpeeds().Z);
                    }
                }
            };

            return(levelXCarriagePage);
        }
Exemplo n.º 3
0
        public UpgradeToProTabPage(ThemeConfig theme)
        {
            this.Padding         = new BorderDouble(3);
            this.HAnchor         = HAnchor.Stretch;
            this.VAnchor         = VAnchor.Stretch;
            this.MinimumSize     = new Vector2(200, 200);
            this.BackgroundColor = theme.TabBodyBackground;

            this.Name = "UpgradeTab";

            markdownWidget = new MarkdownWidget(theme)
            {
                Padding = new BorderDouble(left: theme.DefaultContainerPadding / 2)
            };

            markdownWidget.Markdown = "# Upgrade to [MatterControl Pro](https://www.matterhackers.com/admin/product-preview/ag1zfm1oLXBscy1wcm9kchsLEg5Qcm9kdWN0TGlzdGluZxiAgIC_65WICww)";

            this.AddChild(markdownWidget);

            CheckForUpdate();
        }
Exemplo n.º 4
0
        public override async void OnLoad(EventArgs args)
        {
            if (File.Exists(printerInfo.ProfilePath))
            {
                // load up the printer profile so we can get the MatterHackers Skew-ID out of it
                var printerSettings = PrinterSettings.LoadFile(printerInfo.ProfilePath);

                // Get the printer sid from settings
                string storeID = null;

                // Use the make-model mapping table
                if (OemSettings.Instance.OemPrinters.TryGetValue($"{printerInfo.Make}-{ printerInfo.Model}", out StorePrinterID storePrinterID))
                {
                    storeID = storePrinterID?.SID;
                }

                if (!string.IsNullOrWhiteSpace(storeID))
                {
                    var product = (await LoadProductData(storeID)).ProductSku;
                    // put in controls from the feed that show relevant printer information

                    var row = new FlowLayoutWidget()
                    {
                        HAnchor = HAnchor.Stretch,
                        Margin  = new BorderDouble(top: theme.DefaultContainerPadding)
                    };
                    this.AddChild(row);

                    var image = new ImageBuffer(150, 10);
                    row.AddChild(new ImageWidget(image)
                    {
                        Margin  = new BorderDouble(right: theme.DefaultContainerPadding),
                        VAnchor = VAnchor.Top
                    });

                    ApplicationController.Instance.DownloadToImageAsync(image, product.FeaturedImage.ImageUrl, scaleToImageX: true);

                    var descriptionBackground = new GuiWidget()
                    {
                        HAnchor = HAnchor.Stretch,
                        VAnchor = VAnchor.Fit | VAnchor.Top,
                        Padding = theme.DefaultContainerPadding
                    };

                    var description = new MarkdownWidget(theme)
                    {
                        MinimumSize = new VectorMath.Vector2(350, 0),
                        HAnchor     = HAnchor.Stretch,
                        VAnchor     = VAnchor.Fit,
                        Markdown    = product.ProductDescription.Trim()
                    };
                    descriptionBackground.AddChild(description);
                    descriptionBackground.BeforeDraw += (s, e) =>
                    {
                        var rect = new RoundedRect(descriptionBackground.LocalBounds, 3);
                        e.Graphics2D.Render(rect, theme.SlightShade);
                    };

                    row.AddChild(descriptionBackground);

                    var padding = theme.DefaultContainerPadding;

                    var addonsColumn = new FlowLayoutWidget(FlowDirection.TopToBottom)
                    {
                        Padding = new BorderDouble(padding, padding, padding, 0),
                        HAnchor = HAnchor.Stretch
                    };

                    var addonsSection = new SectionWidget("Upgrades and Accessories", addonsColumn, theme);
                    this.AddChild(addonsSection);
                    theme.ApplyBoxStyle(addonsSection);
                    addonsSection.Margin = addonsSection.Margin.Clone(left: 0);

                    foreach (var item in product.ProductListing.AddOns)
                    {
                        var icon = new ImageBuffer(80, 0);
                        ApplicationController.Instance.DownloadToImageAsync(icon, item.FeaturedImage.ImageUrl, scaleToImageX: true);

                        var addOnRow = new AddOnRow(item.AddOnTitle, theme, null, icon)
                        {
                            HAnchor = HAnchor.Stretch,
                            Cursor  = Cursors.Hand
                        };

                        foreach (var child in addOnRow.Children)
                        {
                            child.Selectable = false;
                        }

                        addOnRow.Click += (s, e) =>
                        {
                            ApplicationController.Instance.LaunchBrowser($"https://www.matterhackers.com/store/l/{item.AddOnListingReference}/sk/{item.AddOnSkuReference}");
                        };

                        addonsColumn.AddChild(addOnRow);
                    }

                    if (false)
                    {
                        var settingsPanel = new GuiWidget()
                        {
                            HAnchor         = HAnchor.Stretch,
                            VAnchor         = VAnchor.Stretch,
                            MinimumSize     = new VectorMath.Vector2(20, 20),
                            DebugShowBounds = true
                        };

                        settingsPanel.Load += (s, e) =>
                        {
                            var printer = new PrinterConfig(printerSettings);

                            var settingsContext = new SettingsContext(
                                printer,
                                null,
                                NamedSettingsLayers.All);

                            settingsPanel.AddChild(
                                new ConfigurePrinterWidget(settingsContext, printer, theme)
                            {
                                HAnchor = HAnchor.Stretch,
                                VAnchor = VAnchor.Stretch,
                            });
                        };

                        this.AddChild(new SectionWidget("Settings", settingsPanel, theme, expanded: false, setContentVAnchor: false)
                        {
                            VAnchor = VAnchor.Stretch
                        });
                    }
                }
            }

            base.OnLoad(args);
        }
Exemplo n.º 5
0
        protected override IEnumerator <PrinterSetupWizardPage> GetWizardSteps()
        {
            var levelingStrings = new LevelingStrings(printer.Settings);

            var title        = "Select Material".Localize();
            var instructions = "Please select the material you will be printing with.".Localize();

            if (onlyLoad)
            {
                title        = "Load Material".Localize();
                instructions = "Please select the material you want to load.".Localize();
            }

            // select the material
            yield return(new SelectMaterialPage(this, title, instructions, onlyLoad ? "Load".Localize() : "Select".Localize(), onlyLoad));

            var theme = ApplicationController.Instance.Theme;

            // show the trim filament message
            {
                PrinterSetupWizardPage trimFilamentPage = null;
                trimFilamentPage = new PrinterSetupWizardPage(
                    this,
                    "Trim Filament".Localize(),
                    "")
                {
                    BecomingActive = () =>
                    {
                        // start heating up the extruder
                        printer.Connection.SetTargetHotendTemperature(0, printer.Settings.GetValue <double>(SettingsKey.temperature));

                        var markdownText   = printer.Settings.GetValue(SettingsKey.trim_filament_markdown);
                        var markdownWidget = new MarkdownWidget(theme);
                        markdownWidget.Markdown = markdownText = markdownText.Replace("\\n", "\n");
                        trimFilamentPage.ContentRow.AddChild(markdownWidget);
                    }
                };
                yield return(trimFilamentPage);
            }

            // show the insert filament page
            {
                RunningInterval        runningGCodeCommands = null;
                PrinterSetupWizardPage insertFilamentPage   = null;
                insertFilamentPage = new PrinterSetupWizardPage(
                    this,
                    "Insert Filament".Localize(),
                    "")
                {
                    BecomingActive = () =>
                    {
                        var markdownText   = printer.Settings.GetValue(SettingsKey.insert_filament_markdown2);
                        var markdownWidget = new MarkdownWidget(theme);
                        markdownWidget.Markdown = markdownText = markdownText.Replace("\\n", "\n");
                        insertFilamentPage.ContentRow.AddChild(markdownWidget);

                        // turn off the fan
                        printer.Connection.FanSpeed0To255 = 0;
                        // Allow extrusion at any temperature. S0 only works on Marlin S1 works on repetier and marlin
                        printer.Connection.QueueLine("M302 S1");

                        var runningTime = Stopwatch.StartNew();
                        runningGCodeCommands = UiThread.SetInterval(() =>
                        {
                            if (printer.Connection.NumQueuedCommands == 0)
                            {
                                printer.Connection.MoveRelative(PrinterCommunication.PrinterConnection.Axis.E, .2, 80);
                                int secondsToRun = 300;
                                if (runningTime.ElapsedMilliseconds > secondsToRun * 1000)
                                {
                                    UiThread.ClearInterval(runningGCodeCommands);
                                }
                            }
                        },
                                                                    .1);
                    },
                    BecomingInactive = () =>
                    {
                        if (runningGCodeCommands != null)
                        {
                            UiThread.ClearInterval(runningGCodeCommands);
                        }
                    }
                };
                insertFilamentPage.Closed += (s, e) =>
                {
                    if (runningGCodeCommands != null)
                    {
                        UiThread.ClearInterval(runningGCodeCommands);
                    }
                };

                yield return(insertFilamentPage);
            }

            // show the loading filament progress bar
            {
                RunningInterval        runningGCodeCommands = null;
                PrinterSetupWizardPage loadingFilamentPage  = null;
                loadingFilamentPage = new PrinterSetupWizardPage(
                    this,
                    "Loading Filament".Localize(),
                    "")
                {
                    BecomingActive = () =>
                    {
                        loadingFilamentPage.NextButton.Enabled = false;

                        // add the progress bar
                        var holder = new FlowLayoutWidget()
                        {
                            Margin = new BorderDouble(3, 0, 0, 10),
                        };
                        var progressBar = new ProgressBar((int)(150 * GuiWidget.DeviceScale), (int)(15 * GuiWidget.DeviceScale))
                        {
                            FillColor       = theme.PrimaryAccentColor,
                            BorderColor     = theme.TextColor,
                            BackgroundColor = Color.White,
                            VAnchor         = VAnchor.Center,
                        };
                        var progressBarText = new TextWidget("", pointSize: 10, textColor: theme.TextColor)
                        {
                            AutoExpandBoundsToText = true,
                            Margin  = new BorderDouble(5, 0, 0, 0),
                            VAnchor = VAnchor.Center,
                        };
                        holder.AddChild(progressBar);
                        holder.AddChild(progressBarText);
                        loadingFilamentPage.ContentRow.AddChild(holder);

                        // Allow extrusion at any temperature. S0 only works on Marlin S1 works on repetier and marlin
                        printer.Connection.QueueLine("M302 S1");
                        // send a dwel to empty out the current move commands
                        printer.Connection.QueueLine("G4 P1");
                        // put in a second one to use as a signal for the first being processed
                        printer.Connection.QueueLine("G4 P1");
                        // start heating up the extruder
                        printer.Connection.SetTargetHotendTemperature(0, printer.Settings.GetValue <double>(SettingsKey.temperature));

                        var loadingSpeedMmPerS     = printer.Settings.GetValue <double>(SettingsKey.load_filament_speed);
                        var loadLengthMm           = Math.Max(1, printer.Settings.GetValue <double>(SettingsKey.load_filament_length));
                        var remainingLengthMm      = loadLengthMm;
                        var maxSingleExtrudeLength = 20;

                        Stopwatch runningTime   = null;
                        var       expectedTimeS = loadLengthMm / loadingSpeedMmPerS;

                        runningGCodeCommands = UiThread.SetInterval(() =>
                        {
                            if (printer.Connection.NumQueuedCommands == 0)
                            {
                                if (runningTime == null)
                                {
                                    runningTime = Stopwatch.StartNew();
                                }

                                if (progressBar.RatioComplete < 1)
                                {
                                    var thisExtrude = Math.Min(remainingLengthMm, maxSingleExtrudeLength);
                                    var currentE    = printer.Connection.CurrentExtruderDestination;
                                    printer.Connection.QueueLine("G1 E{0:0.###} F{1}".FormatWith(currentE + thisExtrude, loadingSpeedMmPerS * 60));
                                    remainingLengthMm        -= thisExtrude;
                                    var elapsedSeconds        = runningTime.Elapsed.TotalSeconds;
                                    progressBar.RatioComplete = Math.Min(1, elapsedSeconds / expectedTimeS);
                                    progressBarText.Text      = $"Loading Filament: {Math.Max(0, expectedTimeS - elapsedSeconds):0}";
                                }
                            }

                            if (progressBar.RatioComplete == 1 &&
                                remainingLengthMm <= .001)
                            {
                                UiThread.ClearInterval(runningGCodeCommands);
                                loadingFilamentPage.NextButton.InvokeClick();
                            }
                        },
                                                                    .1);
                    },
                    BecomingInactive = () =>
                    {
                        UiThread.ClearInterval(runningGCodeCommands);
                    }
                };
                loadingFilamentPage.Closed += (s, e) =>
                {
                    UiThread.ClearInterval(runningGCodeCommands);
                };

                yield return(loadingFilamentPage);
            }

            // wait for extruder to heat
            {
                double targetHotendTemp = printer.Settings.Helpers.ExtruderTemperature(0);
                yield return(new WaitForTempPage(
                                 this,
                                 "Waiting For Printer To Heat".Localize(),
                                 "Waiting for the hotend to heat to ".Localize() + targetHotendTemp + "°C.\n"
                                 + "This will ensure that filament is able to flow through the nozzle.".Localize() + "\n"
                                 + "\n"
                                 + "Warning! The tip of the nozzle will be HOT!".Localize() + "\n"
                                 + "Avoid contact with your skin.".Localize(),
                                 0,
                                 targetHotendTemp));
            }

            // extrude slowly so that we can prime the extruder
            {
                RunningInterval        runningGCodeCommands = null;
                PrinterSetupWizardPage runningCleanPage     = null;
                runningCleanPage = new PrinterSetupWizardPage(
                    this,
                    "Wait For Running Clean".Localize(),
                    "")
                {
                    BecomingActive = () =>
                    {
                        var markdownText   = printer.Settings.GetValue(SettingsKey.running_clean_markdown2);
                        var markdownWidget = new MarkdownWidget(theme);
                        markdownWidget.Markdown = markdownText = markdownText.Replace("\\n", "\n");
                        runningCleanPage.ContentRow.AddChild(markdownWidget);

                        var runningTime = Stopwatch.StartNew();
                        runningGCodeCommands = UiThread.SetInterval(() =>
                        {
                            if (printer.Connection.NumQueuedCommands == 0)
                            {
                                printer.Connection.MoveRelative(PrinterCommunication.PrinterConnection.Axis.E, .35, 140);
                                int secondsToRun = 90;
                                if (runningTime.ElapsedMilliseconds > secondsToRun * 1000)
                                {
                                    UiThread.ClearInterval(runningGCodeCommands);
                                }
                            }
                        },
                                                                    .1);
                    },
                    BecomingInactive = () =>
                    {
                        UiThread.ClearInterval(runningGCodeCommands);
                    }
                };
                runningCleanPage.Closed += (s, e) =>
                {
                    UiThread.ClearInterval(runningGCodeCommands);
                    printer.Settings.SetValue(SettingsKey.filament_has_been_loaded, "1");
                };

                yield return(runningCleanPage);
            }

            // put up a success message
            PrinterSetupWizardPage finalPage = null;

            finalPage = new PrinterSetupWizardPage(this, "Success".Localize(), "Success!\n\nYour filament should now be loaded".Localize())
            {
                BecomingActive = () =>
                {
                    finalPage.ShowWizardFinished();
                }
            };

            yield return(finalPage);
        }
Exemplo n.º 6
0
        //private void CreateProductDataWidgets(PrinterSettings printerSettings, ProductSkuData product)
        private void CreateProductDataWidgets(ProductSkuData product)
        {
            var row = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.Stretch,
                Margin  = new BorderDouble(top: theme.DefaultContainerPadding)
            };

            productDataContainer.AddChild(row);

            var image = new ImageBuffer(150, 10);

            row.AddChild(new ImageWidget(image)
            {
                Margin  = new BorderDouble(right: theme.DefaultContainerPadding),
                VAnchor = VAnchor.Top
            });

            WebCache.RetrieveImageAsync(image, product.FeaturedImage.ImageUrl, scaleToImageX: true);

            var descriptionBackground = new GuiWidget()
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit | VAnchor.Top,
                Padding = theme.DefaultContainerPadding
            };

            var description = new MarkdownWidget(theme)
            {
                MinimumSize = new VectorMath.Vector2(50, 0),
                HAnchor     = HAnchor.Stretch,
                VAnchor     = VAnchor.Fit,
                AutoScroll  = false,
                Markdown    = product.ProductDescription.Trim()
            };

            descriptionBackground.AddChild(description);
            descriptionBackground.BeforeDraw += (s, e) =>
            {
                var rect = new RoundedRect(descriptionBackground.LocalBounds, 3);
                e.Graphics2D.Render(rect, theme.SlightShade);
            };

            row.AddChild(descriptionBackground);

            if (this.ShowProducts)
            {
                var padding = theme.DefaultContainerPadding;

                var addonsColumn = new FlowLayoutWidget(FlowDirection.TopToBottom)
                {
                    Padding = new BorderDouble(padding, padding, padding, 0),
                    HAnchor = HAnchor.Stretch
                };

                var addonsSection = new SectionWidget("Upgrades and Accessories", addonsColumn, theme);
                productDataContainer.AddChild(addonsSection);
                theme.ApplyBoxStyle(addonsSection);
                addonsSection.Margin = addonsSection.Margin.Clone(left: 0);

                foreach (var item in product.ProductListing.AddOns)
                {
                    var addOnRow = new AddOnRow(item.AddOnTitle, theme, null, item.Icon)
                    {
                        HAnchor = HAnchor.Stretch,
                        Cursor  = Cursors.Hand
                    };

                    foreach (var child in addOnRow.Children)
                    {
                        child.Selectable = false;
                    }

                    addOnRow.Click += (s, e) =>
                    {
                        ApplicationController.LaunchBrowser($"https://www.matterhackers.com/store/l/{item.AddOnListingReference}/sk/{item.AddOnSkuReference}");
                    };

                    addonsColumn.AddChild(addOnRow);
                }
            }

            //if (false)
            //{
            //	var settingsPanel = new GuiWidget()
            //	{
            //		HAnchor = HAnchor.Stretch,
            //		VAnchor = VAnchor.Stretch,
            //		MinimumSize = new VectorMath.Vector2(20, 20),
            //		DebugShowBounds = true
            //	};

            //	settingsPanel.Load += (s, e) =>
            //	{
            //		var printer = new PrinterConfig(printerSettings);

            //		var settingsContext = new SettingsContext(
            //			printer,
            //			null,
            //			NamedSettingsLayers.All);

            //		settingsPanel.AddChild(
            //			new ConfigurePrinterWidget(settingsContext, printer, theme)
            //			{
            //				HAnchor = HAnchor.Stretch,
            //				VAnchor = VAnchor.Stretch,
            //			});
            //	};

            //	this.AddChild(new SectionWidget("Settings", settingsPanel, theme, expanded: false, setContentVAnchor: false)
            //	{
            //		VAnchor = VAnchor.Stretch
            //	});
            //}
        }
Exemplo n.º 7
0
        private IEnumerator <WizardPage> GetPages()
        {
            var extruderCount = printer.Settings.GetValue <int>(SettingsKey.extruder_count);

            var levelingStrings = new LevelingStrings();

            var instructions = "Please select the material you want to load.".Localize();

            if (extruderCount > 1)
            {
                instructions = "Please select the material you want to load into extruder {0}.".Localize().FormatWith(extruderIndex + 1);
            }

            // select the material
            yield return(new SelectMaterialPage(this, "Load Material".Localize(), instructions, "Select".Localize(), extruderIndex, true, showAlreadyLoadedButton)
            {
                WindowTitle = WindowTitle
            });

            var theme = ApplicationController.Instance.Theme;

            // show the trim filament message
            {
                var trimFilamentPage = new WizardPage(this, "Trim Filament".Localize(), "")
                {
                    PageLoad = (page) =>
                    {
                        // start heating up the extruder
                        printer.Connection.SetTargetHotendTemperature(extruderIndex, printer.Settings.GetValue <double>(SettingsKey.temperature));

                        var markdownText   = printer.Settings.GetValue(SettingsKey.trim_filament_markdown);
                        var markdownWidget = new MarkdownWidget(theme);
                        markdownWidget.Markdown = markdownText = markdownText.Replace("\\n", "\n");
                        page.ContentRow.AddChild(markdownWidget);
                    }
                };
                yield return(trimFilamentPage);
            }

            if (extruderCount > 1)
            {
                // reset the extruder that was active
                printer.Connection.QueueLine($"T{extruderIndex}");
            }

            // reset the extrusion amount so this is easier to debug
            printer.Connection.QueueLine("G92 E0");

            // show the insert filament page
            {
                RunningInterval runningGCodeCommands = null;
                var             insertFilamentPage   = new WizardPage(this, "Insert Filament".Localize(), "")
                {
                    PageLoad = (page) =>
                    {
                        var markdownText = printer.Settings.GetValue(SettingsKey.insert_filament_markdown2);
                        if (extruderIndex == 1)
                        {
                            markdownText = printer.Settings.GetValue(SettingsKey.insert_filament_1_markdown);
                        }
                        var markdownWidget = new MarkdownWidget(theme);
                        markdownWidget.Markdown = markdownText = markdownText.Replace("\\n", "\n");
                        page.ContentRow.AddChild(markdownWidget);

                        // turn off the fan
                        printer.Connection.FanSpeed0To255 = 0;
                        // Allow extrusion at any temperature. S0 only works on Marlin S1 works on repetier and marlin
                        printer.Connection.QueueLine("M302 S1");

                        int maxSecondsToStartLoading = 300;
                        var runningTime = Stopwatch.StartNew();
                        runningGCodeCommands = UiThread.SetInterval(() =>
                        {
                            if (printer.Connection.NumQueuedCommands == 0)
                            {
                                printer.Connection.MoveRelative(PrinterCommunication.PrinterConnection.Axis.E, 1, 80);
                                // send a dwell to empty out the current move commands
                                printer.Connection.QueueLine("G4 P1");

                                if (runningTime.ElapsedMilliseconds > maxSecondsToStartLoading * 1000)
                                {
                                    UiThread.ClearInterval(runningGCodeCommands);
                                }
                            }
                        },
                                                                    .1);
                    },
                    PageClose = () =>
                    {
                        if (runningGCodeCommands != null)
                        {
                            UiThread.ClearInterval(runningGCodeCommands);
                        }
                    }
                };
                insertFilamentPage.Closed += (s, e) =>
                {
                    if (runningGCodeCommands != null)
                    {
                        UiThread.ClearInterval(runningGCodeCommands);
                    }
                };

                yield return(insertFilamentPage);
            }

            // show the loading filament progress bar
            {
                RunningInterval runningGCodeCommands = null;
                var             loadingFilamentPage  = new WizardPage(this, "Loading Filament".Localize(), "")
                {
                    PageLoad = (page) =>
                    {
                        page.NextButton.Enabled = false;

                        // add the progress bar
                        var holder = new FlowLayoutWidget()
                        {
                            Margin = new BorderDouble(3, 0, 0, 10),
                        };
                        var progressBar = new ProgressBar((int)(150 * GuiWidget.DeviceScale), (int)(15 * GuiWidget.DeviceScale))
                        {
                            FillColor       = theme.PrimaryAccentColor,
                            BorderColor     = theme.TextColor,
                            BackgroundColor = Color.White,
                            VAnchor         = VAnchor.Center,
                        };
                        var progressBarText = new TextWidget("", pointSize: 10, textColor: theme.TextColor)
                        {
                            AutoExpandBoundsToText = true,
                            Margin  = new BorderDouble(5, 0, 0, 0),
                            VAnchor = VAnchor.Center,
                        };
                        holder.AddChild(progressBar);
                        holder.AddChild(progressBarText);
                        page.ContentRow.AddChild(holder);

                        // Allow extrusion at any temperature. S0 only works on Marlin S1 works on repetier and marlin
                        printer.Connection.QueueLine("M302 S1");
                        // send a dwell to empty out the current move commands
                        printer.Connection.QueueLine("G4 P1");
                        // put in a second one to use as a signal for the first being processed
                        printer.Connection.QueueLine("G4 P1");
                        // start heating up the extruder
                        printer.Connection.SetTargetHotendTemperature(extruderIndex, printer.Settings.GetValue <double>(SettingsKey.temperature));

                        var loadingSpeedMmPerS     = printer.Settings.GetValue <double>(SettingsKey.load_filament_speed);
                        var loadLengthMm           = Math.Max(1, printer.Settings.GetValue <double>(SettingsKey.load_filament_length));
                        var remainingLengthMm      = loadLengthMm;
                        var maxSingleExtrudeLength = 20;

                        Stopwatch runningTime   = null;
                        var       expectedTimeS = loadLengthMm / loadingSpeedMmPerS;

                        runningGCodeCommands = UiThread.SetInterval(() =>
                        {
                            if (printer.Connection.NumQueuedCommands == 0)
                            {
                                if (runningTime == null)
                                {
                                    runningTime = Stopwatch.StartNew();
                                }

                                if (progressBar.RatioComplete < 1 ||
                                    remainingLengthMm >= .001)
                                {
                                    var thisExtrude = Math.Min(remainingLengthMm, maxSingleExtrudeLength);
                                    var currentE    = printer.Connection.CurrentExtruderDestination;
                                    printer.Connection.QueueLine("G1 E{0:0.###} F{1}".FormatWith(currentE + thisExtrude, loadingSpeedMmPerS * 60));
                                    // make sure we wait for this command to finish so we can cancel the unload at any time without delay
                                    printer.Connection.QueueLine("G4 P1");
                                    remainingLengthMm        -= thisExtrude;
                                    var elapsedSeconds        = runningTime.Elapsed.TotalSeconds;
                                    progressBar.RatioComplete = Math.Min(1, elapsedSeconds / expectedTimeS);
                                    progressBarText.Text      = $"Loading Filament: {Math.Max(0, expectedTimeS - elapsedSeconds):0}";
                                }
                            }

                            if (progressBar.RatioComplete == 1 &&
                                remainingLengthMm <= .001)
                            {
                                UiThread.ClearInterval(runningGCodeCommands);
                                page.NextButton.InvokeClick();
                            }
                        },
                                                                    .1);
                    },
                    PageClose = () =>
                    {
                        UiThread.ClearInterval(runningGCodeCommands);
                    }
                };
                loadingFilamentPage.Closed += (s, e) =>
                {
                    UiThread.ClearInterval(runningGCodeCommands);
                };

                yield return(loadingFilamentPage);
            }

            // wait for extruder to heat
            {
                var targetHotendTemp = printer.Settings.Helpers.ExtruderTargetTemperature(extruderIndex);
                var temps            = new double[4];
                temps[extruderIndex] = targetHotendTemp;
                yield return(new WaitForTempPage(
                                 this,
                                 "Waiting For Printer To Heat".Localize(),
                                 "Waiting for the hotend to heat to ".Localize() + targetHotendTemp + "°C.\n"
                                 + "This will ensure that filament is able to flow through the nozzle.".Localize() + "\n"
                                 + "\n"
                                 + "Warning! The tip of the nozzle will be HOT!".Localize() + "\n"
                                 + "Avoid contact with your skin.".Localize(),
                                 0,
                                 temps));
            }

            // extrude slowly so that we can prime the extruder
            {
                RunningInterval runningGCodeCommands = null;
                var             runningCleanPage     = new WizardPage(this, "Wait For Running Clean".Localize(), "")
                {
                    PageLoad = (page) =>
                    {
                        var markdownText = printer.Settings.GetValue(SettingsKey.running_clean_markdown2);
                        if (extruderIndex == 1)
                        {
                            markdownText = printer.Settings.GetValue(SettingsKey.running_clean_1_markdown);
                        }
                        var markdownWidget = new MarkdownWidget(theme);
                        markdownWidget.Markdown = markdownText = markdownText.Replace("\\n", "\n");
                        page.ContentRow.AddChild(markdownWidget);

                        var runningTime = Stopwatch.StartNew();
                        runningGCodeCommands = UiThread.SetInterval(() =>
                        {
                            if (printer.Connection.NumQueuedCommands == 0)
                            {
                                printer.Connection.MoveRelative(PrinterCommunication.PrinterConnection.Axis.E, 2, 140);
                                // make sure we wait for this command to finish so we can cancel the unload at any time without delay
                                printer.Connection.QueueLine("G4 P1");
                                int secondsToRun = 90;
                                if (runningTime.ElapsedMilliseconds > secondsToRun * 1000)
                                {
                                    UiThread.ClearInterval(runningGCodeCommands);
                                }
                            }
                        },
                                                                    .1);
                    },
                    PageClose = () =>
                    {
                        UiThread.ClearInterval(runningGCodeCommands);
                    }
                };
                runningCleanPage.Closed += (s, e) =>
                {
                    switch (extruderIndex)
                    {
                    case 0:
                        printer.Settings.SetValue(SettingsKey.filament_has_been_loaded, "1");
                        break;

                    case 1:
                        printer.Settings.SetValue(SettingsKey.filament_1_has_been_loaded, "1");
                        break;
                    }
                    printer.Settings.SetValue(SettingsKey.filament_has_been_loaded, "1");
                };

                yield return(runningCleanPage);
            }

            // put up a success message
            yield return(new DoneLoadingPage(this, extruderIndex));
        }
Exemplo n.º 8
0
        public MarkdownEditPage(UIField uiField)
        {
            this.WindowTitle = "MatterControl - " + "Markdown Edit".Localize();
            this.HeaderText  = "Edit Page".Localize() + ":";

            var tabControl = new SimpleTabs(theme, new GuiWidget())
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch,
            };

            tabControl.TabBar.BackgroundColor = theme.TabBarBackground;
            tabControl.TabBar.Padding         = 0;

            contentRow.AddChild(tabControl);
            contentRow.Padding = 0;

            var editContainer = new GuiWidget()
            {
                HAnchor         = HAnchor.Stretch,
                VAnchor         = VAnchor.Stretch,
                Padding         = theme.DefaultContainerPadding,
                BackgroundColor = theme.BackgroundColor
            };

            editWidget = new MHTextEditWidget("", theme, multiLine: true, typeFace: ApplicationController.GetTypeFace(NamedTypeFace.Liberation_Mono))
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch,
                Name    = this.Name
            };
            editWidget.DrawFromHintedCache();
            editWidget.ActualTextEditWidget.VAnchor = VAnchor.Stretch;

            editContainer.AddChild(editWidget);

            markdownWidget = new MarkdownWidget(theme, true)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch,
                Margin  = 0,
                Padding = 0,
            };

            var previewTab = new ToolTab("Preview", "Preview".Localize(), tabControl, markdownWidget, theme, hasClose: false)
            {
                Name = "Preview Tab"
            };

            tabControl.AddTab(previewTab);

            var editTab = new ToolTab("Edit", "Edit".Localize(), tabControl, editContainer, theme, hasClose: false)
            {
                Name = "Edit Tab"
            };

            tabControl.AddTab(editTab);

            tabControl.ActiveTabChanged += (s, e) =>
            {
                if (tabControl.SelectedTabIndex == 1)
                {
                    markdownWidget.Markdown = editWidget.Text;
                }
            };

            tabControl.SelectedTabIndex = 0;

            var saveButton = theme.CreateDialogButton("Save".Localize());

            saveButton.Click += (s, e) =>
            {
                uiField.SetValue(
                    editWidget.Text.Replace("\n", "\\n"),
                    userInitiated: true);

                this.DialogWindow.CloseOnIdle();
            };
            this.AddPageAction(saveButton);

            var link = new LinkLabel("Markdown Help", theme)
            {
                Margin  = new BorderDouble(right: 20),
                VAnchor = VAnchor.Center
            };

            link.Click += (s, e) =>
            {
                ApplicationController.Instance.LaunchBrowser("https://guides.github.com/features/mastering-markdown/");
            };
            footerRow.AddChild(link, 0);
        }
Exemplo n.º 9
0
        public RunningMacroPage(PrinterConfig printer, MacroCommandData macroData, ThemeConfig theme)
            : base("Cancel")
        {
            this.printer     = printer;
            this.WindowTitle = "Running Macro".Localize();
            this.HeaderText  = macroData.title;

            if (macroData.showMaterialSelector)
            {
                contentRow.AddChild(new PresetSelectorWidget(printer, "Material".Localize(), Color.Transparent, NamedSettingsLayers.Material, theme)
                {
                    BackgroundColor = Color.Transparent,
                    Margin          = new BorderDouble(0, 0, 0, 15)
                });
            }

            printer.Connection.LineSent.RegisterEvent(LookForTempRequest, ref unregisterEvents);

            if (macroData.waitOk | macroData.expireTime > 0)
            {
                var okButton = theme.CreateDialogButton("Continue".Localize());
                okButton.Name   = "Continue Button";
                okButton.Click += (s, e) =>
                {
                    ContinueToNextPage = true;
                    printer.Connection.MacroContinue();
                };

                this.AddPageAction(okButton);
            }

#if !__ANDROID__
            if (!string.IsNullOrEmpty(macroData.markdown))
            {
                var markdown = new MarkdownWidget(theme);

                markdown.Markdown = macroData.markdown;

                contentRow.AddChild(markdown);
            }
#endif

            var holder = new FlowLayoutWidget();
            progressBar = new ProgressBar((int)(150 * GuiWidget.DeviceScale), (int)(15 * GuiWidget.DeviceScale))
            {
                FillColor       = ActiveTheme.Instance.PrimaryAccentColor,
                BorderColor     = ActiveTheme.Instance.PrimaryTextColor,
                BackgroundColor = Color.White,
                Margin          = new BorderDouble(3, 0, 0, 10),
            };
            progressBarText = new TextWidget("", pointSize: 10, textColor: ActiveTheme.Instance.PrimaryTextColor)
            {
                AutoExpandBoundsToText = true,
                Margin = new BorderDouble(5, 0, 0, 0),
            };
            holder.AddChild(progressBar);
            holder.AddChild(progressBarText);
            contentRow.AddChild(holder);
            progressBar.Visible = false;

            if (macroData.countDown > 0)
            {
                timeToWaitMs    = (long)(macroData.countDown * 1000);
                startTimeMs     = UiThread.CurrentTimerMs;
                runningInterval = UiThread.SetInterval(CountDownTime, .2);
            }
        }