Beispiel #1
0
        public static SystemWindow LoadRootWindow(int width, int height)
        {
            timer = Stopwatch.StartNew();

            if (false)
            {
                // set the default font
                AggContext.DefaultFont           = ApplicationController.GetTypeFace(NamedTypeFace.Nunito_Regular);
                AggContext.DefaultFontBold       = ApplicationController.GetTypeFace(NamedTypeFace.Nunito_Bold);
                AggContext.DefaultFontItalic     = ApplicationController.GetTypeFace(NamedTypeFace.Nunito_Italic);
                AggContext.DefaultFontBoldItalic = ApplicationController.GetTypeFace(NamedTypeFace.Nunito_Bold_Italic);
            }

            var systemWindow = new RootSystemWindow(width, height);

            var overlay = new GuiWidget()
            {
                BackgroundColor = AppContext.Theme.BackgroundColor,
            };

            overlay.AnchorAll();

            systemWindow.AddChild(overlay);

            var mutedAccentColor = AppContext.Theme.SplashAccentColor;

            var spinner = new LogoSpinner(overlay, rotateX: -0.05)
            {
                MeshColor = mutedAccentColor
            };

            progressPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                Position    = new Vector2(0, height * .25),
                HAnchor     = HAnchor.Center | HAnchor.Fit,
                VAnchor     = VAnchor.Fit,
                MinimumSize = new Vector2(400, 100),
                Margin      = new BorderDouble(0, 0, 0, 200)
            };
            overlay.AddChild(progressPanel);

            progressPanel.AddChild(statusText = new TextWidget("", textColor: AppContext.Theme.TextColor)
            {
                MinimumSize            = new Vector2(200, 30),
                HAnchor                = HAnchor.Center,
                AutoExpandBoundsToText = true
            });

            progressPanel.AddChild(progressBar = new ProgressBar()
            {
                FillColor   = mutedAccentColor,
                BorderColor = Color.Gray,                 // theme.BorderColor75,
                Height      = 11 * GuiWidget.DeviceScale,
                Width       = 230 * GuiWidget.DeviceScale,
                HAnchor     = HAnchor.Center,
                VAnchor     = VAnchor.Absolute
            });

            AppContext.RootSystemWindow = systemWindow;

            // hook up a keyboard watcher to rout keys when not handled by children

            systemWindow.KeyPressed += SystemWindow_KeyPressed;

            systemWindow.KeyDown += (s, keyEvent) =>
            {
                var view3D            = systemWindow.Descendants <View3DWidget>().Where((v) => v.ActuallyVisibleOnScreen()).FirstOrDefault();
                var printerTabPage    = systemWindow.Descendants <PrinterTabPage>().Where((v) => v.ActuallyVisibleOnScreen()).FirstOrDefault();
                var offsetDist        = 50;
                var arrowKeyOperation = keyEvent.Shift ? TrackBallTransformType.Translation : TrackBallTransformType.Rotation;

                var gcode2D = systemWindow.Descendants <GCode2DWidget>().Where((v) => v.ActuallyVisibleOnScreen()).FirstOrDefault();

                if (keyEvent.KeyCode == Keys.F1)
                {
                    ApplicationController.Instance.ActivateHelpTab();
                }

                if (EnableF5Collect &&
                    keyEvent.KeyCode == Keys.F5)
                {
                    GC.Collect();
                    systemWindow.Invalidate();
                }

                if (!keyEvent.Handled &&
                    gcode2D != null)
                {
                    switch (keyEvent.KeyCode)
                    {
                    case Keys.Oemplus:
                    case Keys.Add:
                        if (keyEvent.Control)
                        {
                            // Zoom out
                            gcode2D.Zoom(1.2);
                            keyEvent.Handled = true;
                        }

                        break;

                    case Keys.OemMinus:
                    case Keys.Subtract:
                        if (keyEvent.Control)
                        {
                            // Zoom in
                            gcode2D.Zoom(.8);
                            keyEvent.Handled = true;
                        }

                        break;
                    }
                }

                if (!keyEvent.Handled &&
                    view3D != null)
                {
                    switch (keyEvent.KeyCode)
                    {
                    case Keys.C:
                        if (keyEvent.Control)
                        {
                            view3D.Scene.Copy();
                            keyEvent.Handled = true;
                        }

                        break;

                    case Keys.P:
                        if (keyEvent.Control)
                        {
                            view3D.PushToPrinterAndPrint();
                        }

                        break;

                    case Keys.X:
                        if (keyEvent.Control)
                        {
                            view3D.Scene.Cut();
                            keyEvent.Handled = true;
                        }

                        break;

                    case Keys.Y:
                        if (keyEvent.Control)
                        {
                            view3D.Scene.UndoBuffer.Redo();
                            keyEvent.Handled = true;
                        }

                        break;

                    case Keys.A:
                        if (keyEvent.Control)
                        {
                            view3D.SelectAll();
                            keyEvent.Handled = true;
                        }

                        break;

                    case Keys.S:
                        if (keyEvent.Control)
                        {
                            view3D.Save();
                            keyEvent.Handled = true;
                        }

                        break;

                    case Keys.V:
                        if (keyEvent.Control)
                        {
                            view3D.sceneContext.Paste();
                            keyEvent.Handled = true;
                        }

                        break;

                    case Keys.Oemplus:
                    case Keys.Add:
                        if (keyEvent.Control)
                        {
                            // Zoom out
                            Offset3DView(view3D, new Vector2(0, offsetDist), TrackBallTransformType.Scale);
                            keyEvent.Handled = true;
                        }

                        break;

                    case Keys.OemMinus:
                    case Keys.Subtract:
                        if (keyEvent.Control)
                        {
                            // Zoom in
                            Offset3DView(view3D, new Vector2(0, -offsetDist), TrackBallTransformType.Scale);
                            keyEvent.Handled = true;
                        }

                        break;

                    case Keys.Z:
                        if (keyEvent.Control)
                        {
                            if (keyEvent.Shift)
                            {
                                view3D.Scene.Redo();
                            }
                            else
                            {
                                // undo last operation
                                view3D.Scene.Undo();
                            }

                            keyEvent.Handled = true;
                        }

                        break;

                    case Keys.Insert:
                        if (keyEvent.Shift)
                        {
                            view3D.sceneContext.Paste();
                            keyEvent.Handled = true;
                        }

                        break;

                    case Keys.Delete:
                    case Keys.Back:
                        view3D.Scene.DeleteSelection();
                        keyEvent.Handled          = true;
                        keyEvent.SuppressKeyPress = true;
                        break;

                    case Keys.Escape:
                        if (view3D.CurrentSelectInfo.DownOnPart)
                        {
                            view3D.CurrentSelectInfo.DownOnPart = false;

                            view3D.Scene.SelectedItem.Matrix = view3D.TransformOnMouseDown;

                            keyEvent.Handled          = true;
                            keyEvent.SuppressKeyPress = true;
                        }

                        foreach (var object3DControls in view3D.Object3DControlLayer.Object3DControls)
                        {
                            object3DControls.CancelOperation();
                        }

                        break;

                    case Keys.Left:
                        if (keyEvent.Control &&
                            printerTabPage != null &&
                            !printerTabPage.sceneContext.ViewState.ModelView)
                        {
                            // Decrement slider
                            printerTabPage.LayerFeaturesIndex -= 1;
                        }
                        else
                        {
                            if (view3D.sceneContext.Scene.SelectedItem is IObject3D object3D)
                            {
                                NudgeItem(view3D, object3D, ArrowDirection.Left, keyEvent);
                            }
                            else
                            {
                                // move or rotate view left
                                Offset3DView(view3D, new Vector2(-offsetDist, 0), arrowKeyOperation);
                            }
                        }

                        keyEvent.Handled          = true;
                        keyEvent.SuppressKeyPress = true;
                        break;

                    case Keys.Right:
                        if (keyEvent.Control &&
                            printerTabPage != null &&
                            !printerTabPage.sceneContext.ViewState.ModelView)
                        {
                            // Increment slider
                            printerTabPage.LayerFeaturesIndex += 1;
                        }
                        else
                        {
                            if (view3D.sceneContext.Scene.SelectedItem is IObject3D object3D)
                            {
                                NudgeItem(view3D, object3D, ArrowDirection.Right, keyEvent);
                            }
                            else
                            {
                                // move or rotate view right
                                Offset3DView(view3D, new Vector2(offsetDist, 0), arrowKeyOperation);
                            }
                        }

                        keyEvent.Handled          = true;
                        keyEvent.SuppressKeyPress = true;
                        break;

                    case Keys.Up:
                        if (view3D.Printer != null &&
                            printerTabPage != null &&
                            view3D.Printer.ViewState.ViewMode != PartViewMode.Model)
                        {
                            printerTabPage.LayerScrollbar.Value += 1;
                        }
                        else
                        {
                            if (view3D.sceneContext.Scene.SelectedItem is IObject3D object3D)
                            {
                                NudgeItem(view3D, object3D, ArrowDirection.Up, keyEvent);
                            }
                            else
                            {
                                Offset3DView(view3D, new Vector2(0, offsetDist), arrowKeyOperation);
                            }
                        }

                        keyEvent.Handled          = true;
                        keyEvent.SuppressKeyPress = true;
                        break;

                    case Keys.Down:
                        if (view3D.Printer != null &&
                            printerTabPage != null &&
                            view3D.Printer.ViewState.ViewMode != PartViewMode.Model)
                        {
                            printerTabPage.LayerScrollbar.Value -= 1;
                        }
                        else
                        {
                            if (view3D.sceneContext.Scene.SelectedItem is IObject3D object3D)
                            {
                                NudgeItem(view3D, object3D, ArrowDirection.Down, keyEvent);
                            }
                            else
                            {
                                Offset3DView(view3D, new Vector2(0, -offsetDist), arrowKeyOperation);
                            }
                        }

                        keyEvent.Handled          = true;
                        keyEvent.SuppressKeyPress = true;
                        break;
                    }
                }
            };

            // Hook SystemWindow load and spin up MatterControl once we've hit first draw
            systemWindow.Load += (s, e) =>
            {
                // Show the End User License Agreement if it has not been shown (on windows it is shown in the installer)
                if (AggContext.OperatingSystem != OSType.Windows &&
                    UserSettings.Instance.get(UserSettingsKey.SoftwareLicenseAccepted) != "true")
                {
                    var eula = new LicenseAgreementPage(LoadMC)
                    {
                        Margin = new BorderDouble(5)
                    };

                    systemWindow.AddChild(eula);
                }
                else
                {
                    LoadMC();
                }
            };

            void LoadMC()
            {
                ReportStartupProgress(0.02, "First draw->RunOnIdle");

                // UiThread.RunOnIdle(() =>
                Task.Run(async() =>
                {
                    try
                    {
                        ReportStartupProgress(0.15, "MatterControlApplication.Initialize");

                        ApplicationController.LoadTranslationMap();

                        var mainView = await Initialize(systemWindow, (progress0To1, status) =>
                        {
                            ReportStartupProgress(0.2 + progress0To1 * 0.7, status);
                        });

                        ReportStartupProgress(0.9, "AddChild->MainView");
                        systemWindow.AddChild(mainView, 0);

                        ReportStartupProgress(1, "");
                        systemWindow.BackgroundColor = Color.Transparent;
                        overlay.Close();
                    }
                    catch (Exception ex)
                    {
                        UiThread.RunOnIdle(() =>
                        {
                            statusText.Visible = false;

                            var errorTextColor = Color.White;

                            progressPanel.Margin          = 0;
                            progressPanel.VAnchor         = VAnchor.Center | VAnchor.Fit;
                            progressPanel.BackgroundColor = Color.DarkGray;
                            progressPanel.Padding         = 20;
                            progressPanel.Border          = 1;
                            progressPanel.BorderColor     = Color.Red;

                            var theme = new ThemeConfig();

                            progressPanel.AddChild(
                                new TextWidget("Startup Failure".Localize() + ":", pointSize: theme.DefaultFontSize, textColor: errorTextColor));

                            progressPanel.AddChild(
                                new TextWidget(ex.Message, pointSize: theme.FontSize9, textColor: errorTextColor));

                            var closeButton = new TextButton("Close", theme)
                            {
                                BackgroundColor = theme.SlightShade,
                                HAnchor         = HAnchor.Right,
                                VAnchor         = VAnchor.Absolute
                            };
                            closeButton.Click += (s1, e1) =>
                            {
                                systemWindow.Close();
                            };

                            spinner.SpinLogo    = false;
                            progressBar.Visible = false;

                            progressPanel.AddChild(closeButton);
                        });
                    }

                    AppContext.IsLoading = false;
                });
            }

            ReportStartupProgress(0, "ShowAsSystemWindow");

            AddTextWidgetRightClickMenu();

            return(systemWindow);
        }
Beispiel #2
0
 public ExtrudeButton(PrinterConfig printer, string text, double movementFeedRate, int extruderNumber, ThemeConfig theme)
     : base(text, theme)
 {
     this.printer          = printer;
     this.ExtruderNumber   = extruderNumber;
     this.MovementFeedRate = movementFeedRate;
 }
Beispiel #3
0
        public UpdateControlView(ThemeConfig theme)
        {
            this.HAnchor         = HAnchor.Stretch;
            this.BackgroundColor = theme.MinimalShade;
            this.Padding         = theme.ToolbarPadding.Clone(left: 8);

            this.AddChild(updateStatusText = new TextWidget(string.Format(""), textColor: theme.TextColor)
            {
                AutoExpandBoundsToText = true,
                VAnchor = VAnchor.Center
            });

            this.AddChild(new HorizontalSpacer());

            checkUpdateButton = new IconButton(StaticData.Instance.LoadIcon("fa-refresh_14.png", 14, 14).SetToColor(theme.TextColor), theme)
            {
                ToolTipText     = "Check for Update".Localize(),
                BackgroundColor = theme.MinimalShade,
                Cursor          = Cursors.Hand,
                Visible         = false
            };
            checkUpdateButton.Click += (s, e) =>
            {
                UpdateControlData.Instance.CheckForUpdate();
            };
            this.AddChild(checkUpdateButton);

            this.MinimumSize = new Vector2(0, checkUpdateButton.Height);

            downloadButton = new TextButton("Download Update".Localize(), theme)
            {
                BackgroundColor = theme.MinimalShade,
                Visible         = false
            };
            downloadButton.Click += (s, e) =>
            {
                downloadButton.Visible = false;
                updateStatusText.Text  = "Retrieving download info...".Localize();

                UpdateControlData.Instance.InitiateUpdateDownload();
            };
            this.AddChild(downloadButton);

            installButton = new TextButton("Install Update".Localize(), theme)
            {
                BackgroundColor = theme.MinimalShade,
                Visible         = false
            };
            installButton.Click += (s, e) =>
            {
                try
                {
                    if (!UpdateControlData.Instance.InstallUpdate())
                    {
                        installButton.Visible = false;
                        updateStatusText.Text = "Oops! Unable to install update.".Localize();
                    }
                }
                catch
                {
                    GuiWidget.BreakInDebugger();
                    installButton.Visible = false;
                    updateStatusText.Text = "Oops! Unable to install update.".Localize();
                }
            };
            this.AddChild(installButton);

            UpdateControlData.Instance.UpdateStatusChanged.RegisterEvent(UpdateStatusChanged, ref unregisterEvents);

            this.UpdateStatusChanged(null, null);
        }
Beispiel #4
0
 public MoveButton(string text, PrinterConfig printer, PrinterConnection.Axis axis, double movementFeedRate, ThemeConfig theme)
     : base(text, theme)
 {
     this.printer          = printer;
     this.moveAxis         = axis;
     this.MovementFeedRate = movementFeedRate;
 }
Beispiel #5
0
        public JogControls(PrinterConfig printer, XYZColors colors, ThemeConfig theme)
        {
            this.theme   = theme;
            this.printer = printer;

            double distanceBetweenControls  = 12;
            double buttonSeparationDistance = 10;

            var allControlsTopToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Stretch
            };

            var allControlsLeftToRight = new FlowLayoutWidget();

            using (allControlsLeftToRight.LayoutLock())
            {
                var xYZWithDistance = new FlowLayoutWidget(FlowDirection.TopToBottom);
                {
                    var xYZControls = new FlowLayoutWidget();
                    xYZControls.AddChild(this.CreateXYGridControl(colors, distanceBetweenControls, buttonSeparationDistance));

                    FlowLayoutWidget zButtons = JogControls.CreateZButtons(printer, buttonSeparationDistance, out zPlusControl, out zMinusControl, colors, theme);
                    zButtons.VAnchor = VAnchor.Bottom;
                    xYZControls.AddChild(zButtons);
                    xYZWithDistance.AddChild(xYZControls);

                    // add in some movement radio buttons
                    var setMoveDistanceControl = new FlowLayoutWidget
                    {
                        HAnchor = HAnchor.Left | HAnchor.Fit,
                        VAnchor = VAnchor.Fit
                    };

                    {
                        var moveRadioButtons = new FlowLayoutWidget();
                        var radioList        = new List <GuiWidget>();

                        movePointZeroTwoMmButton = theme.CreateMicroRadioButton("0.02", radioList);
                        movePointZeroTwoMmButton.CheckedStateChanged += (s, e) =>
                        {
                            if (movePointZeroTwoMmButton.Checked)
                            {
                                SetXYZMoveAmount(.02);
                            }
                        };
                        moveRadioButtons.AddChild(movePointZeroTwoMmButton);

                        var pointOneButton = theme.CreateMicroRadioButton("0.1", radioList);
                        pointOneButton.CheckedStateChanged += (s, e) =>
                        {
                            if (pointOneButton.Checked)
                            {
                                SetXYZMoveAmount(.1);
                            }
                        };
                        moveRadioButtons.AddChild(pointOneButton);

                        moveOneMmButton = theme.CreateMicroRadioButton("1", radioList);
                        moveOneMmButton.CheckedStateChanged += (s, e) =>
                        {
                            if (moveOneMmButton.Checked)
                            {
                                SetXYZMoveAmount(1);
                            }
                        };
                        moveRadioButtons.AddChild(moveOneMmButton);

                        tenButton = theme.CreateMicroRadioButton("10", radioList);
                        tenButton.CheckedStateChanged += (s, e) =>
                        {
                            if (tenButton.Checked)
                            {
                                SetXYZMoveAmount(10);
                            }
                        };
                        moveRadioButtons.AddChild(tenButton);

                        oneHundredButton = theme.CreateMicroRadioButton("100", radioList);
                        oneHundredButton.CheckedStateChanged += (s, e) =>
                        {
                            if (oneHundredButton.Checked)
                            {
                                SetXYZMoveAmount(100);
                            }
                        };
                        moveRadioButtons.AddChild(oneHundredButton);

                        tenButton.Checked = true;
                        SetXYZMoveAmount(10);
                        moveRadioButtons.Margin = new BorderDouble(0, 3);
                        setMoveDistanceControl.AddChild(moveRadioButtons);

                        moveRadioButtons.AddChild(new TextWidget("mm", textColor: theme.TextColor, pointSize: 8)
                        {
                            Margin  = new BorderDouble(left: 10),
                            VAnchor = VAnchor.Center
                        });
                    }

                    xYZWithDistance.AddChild(setMoveDistanceControl);
                }

                allControlsLeftToRight.AddChild(xYZWithDistance);

#if !__ANDROID__
                allControlsLeftToRight.AddChild(GetHotkeyControlContainer());
#endif
                // Bar between Z And E
                allControlsLeftToRight.AddChild(new GuiWidget(1, 1)
                {
                    VAnchor         = VAnchor.Stretch,
                    BackgroundColor = colors.ZColor,
                    Margin          = new BorderDouble(distanceBetweenControls, 5)
                });

                // EButtons
                disableableEButtons         = CreateEButtons(buttonSeparationDistance, colors);
                disableableEButtons.Name    = "disableableEButtons";
                disableableEButtons.HAnchor = HAnchor.Fit;
                disableableEButtons.VAnchor = VAnchor.Fit | VAnchor.Top;

                allControlsLeftToRight.AddChild(disableableEButtons);
                allControlsTopToBottom.AddChild(allControlsLeftToRight);
            }
            allControlsLeftToRight.PerformLayout();

            using (this.LayoutLock())
            {
                this.AddChild(allControlsTopToBottom);
                this.HAnchor = HAnchor.Fit;
                this.VAnchor = VAnchor.Fit;
                Margin       = new BorderDouble(3);
            }

            this.PerformLayout();

            // Register listeners
            printer.Settings.SettingChanged += Printer_SettingChanged;
        }
Beispiel #6
0
            public CriteriaRow(string itemText, string fixitText, string errorText, bool succeeded, Action fixAction, ThemeConfig theme)
                : base(FlowDirection.LeftToRight)
            {
                HAnchor = HAnchor.Stretch;
                VAnchor = VAnchor.Absolute;

                ErrorText = errorText;

                base.Height = 40;

                base.AddChild(new TextWidget(string.Format("  {0}. {1}", criteriaCount + 1, itemText))
                {
                    TextColor = stillSuccessful ? Color.White : disabledTextColor,
                    VAnchor   = VAnchor.Center
                });

                if (stillSuccessful && !succeeded)
                {
                    ActiveErrorItem = this;
                }

                base.AddChild(new HorizontalSpacer());

                if (stillSuccessful)
                {
                    if (succeeded)
                    {
                        // Add checkmark image
                        AddSuccessIcon();
                    }
                    else
                    {
                        // Add Fix button
                        var button = theme.CreateDialogButton(fixitText);
                        button.VAnchor = VAnchor.Center;
                        button.Padding = new BorderDouble(3, 8);
                        button.Click  += (s, e) => fixAction?.Invoke();
                        base.AddChild(button);
                    }
                }

                if (stillSuccessful)
                {
                    this.BackgroundColor = (criteriaCount % 2 == 0) ? Color.Gray : toggleColor;
                }
                else
                {
                    this.BackgroundColor = disabledBackColor;
                }

                stillSuccessful &= succeeded;

                criteriaCount++;
            }
Beispiel #7
0
        public static FlowLayoutWidget CreateZButtons(PrinterConfig printer, double buttonSeparationDistance, out MoveButton zPlusControl, out MoveButton zMinusControl, XYZColors colors, ThemeConfig theme, bool levelingButtons = false)
        {
            var zButtons = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                Margin = new BorderDouble(0, 5),
            };

            zPlusControl             = theme.CreateMoveButton(printer, "Z+", PrinterConnection.Axis.Z, printer.Settings.ZSpeed(), levelingButtons);
            zPlusControl.Name        = "Move Z positive".Localize();
            zPlusControl.ToolTipText = "Move Z positive".Localize();
            zButtons.AddChild(zPlusControl);

            // spacer
            zButtons.AddChild(new GuiWidget(1, buttonSeparationDistance)
            {
                HAnchor         = HAnchor.Center,
                BackgroundColor = colors.ZColor
            });

            zMinusControl             = theme.CreateMoveButton(printer, "Z-", PrinterConnection.Axis.Z, printer.Settings.ZSpeed(), levelingButtons);
            zMinusControl.ToolTipText = "Move Z negative".Localize();
            zButtons.AddChild(zMinusControl);

            return(zButtons);
        }
Beispiel #8
0
 public WidescreenPanel(ThemeConfig theme)
 {
     this.theme = theme;
 }
        public PrinterCalibrationWizard(PrinterConfig printer, ThemeConfig theme)
        {
            var stages = new List <ISetupWizard>()
            {
                new ZCalibrationWizard(printer),
                new PrintLevelingWizard(printer),
                new LoadFilamentWizard(printer, extruderIndex: 0, showAlreadyLoadedButton: true),
                new LoadFilamentWizard(printer, extruderIndex: 1, showAlreadyLoadedButton: true),
                new XyCalibrationWizard(printer, 1)
            };

            this.Stages  = stages;
            this.printer = printer;

            this.HomePageGenerator = () =>
            {
                var homePage = new WizardSummaryPage()
                {
                    HeaderText = "Printer Setup & Calibration".Localize()
                };

                var contentRow = homePage.ContentRow;

                if (!ReturnedToHomePage)
                {
                    contentRow.AddChild(
                        new WrappedTextWidget(
                            @"Select the calibration task on the left to continue".Replace("\r\n", "\n"),
                            pointSize: theme.DefaultFontSize,
                            textColor: theme.TextColor));
                }

                contentRow.BackgroundColor = Color.Transparent;

                foreach (var stage in this.Stages.Where(s => s.Enabled && s.Visible))
                {
                    GuiWidget rightWidget = null;
                    var       widget      = new GuiWidget();

                    if (stage is ZCalibrationWizard probeWizard)
                    {
                        var column = CreateColumn(theme);
                        column.FlowDirection = FlowDirection.LeftToRight;

                        var offset = printer.Settings.GetValue <Vector3>(SettingsKey.probe_offset);

                        column.AddChild(
                            new ValueTag(
                                "Z Offset".Localize(),
                                offset.Z.ToString("0.###"),
                                new BorderDouble(12, 5, 2, 5),
                                5,
                                11)
                        {
                            Margin      = new BorderDouble(bottom: 4),
                            MinimumSize = new Vector2(125, 0)
                        });

                        AddRunStageButton("Run Z Calibration".Localize(), theme, stage, column);

                        widget = column;
                    }

                    if (stage is PrintLevelingWizard levelingWizard)
                    {
                        PrintLevelingData levelingData = printer.Settings.Helpers.PrintLevelingData;

                        var column = CreateColumn(theme);

                        if (levelingData != null &&
                            printer.Settings?.GetValue <bool>(SettingsKey.print_leveling_enabled) == true)
                        {
                            var positions = levelingData.SampledPositions;

                            var levelingSolution = printer.Settings.GetValue(SettingsKey.print_leveling_solution);

                            column.AddChild(
                                new ValueTag(
                                    "Leveling Solution".Localize(),
                                    levelingSolution,
                                    new BorderDouble(12, 5, 2, 5),
                                    5,
                                    11)
                            {
                                Margin      = new BorderDouble(bottom: 4),
                                MinimumSize = new Vector2(125, 0)
                            });

                            var editButton = new IconButton(AggContext.StaticData.LoadIcon("icon_edit.png", 16, 16, theme.InvertIcons), theme)
                            {
                                Name        = "Edit Leveling Data Button",
                                ToolTipText = "Edit Leveling Data".Localize(),
                            };

                            editButton.Click += (s, e) =>
                            {
                                DialogWindow.Show(new EditLevelingSettingsPage(printer, theme));
                            };

                            var row = new FlowLayoutWidget()
                            {
                                VAnchor = VAnchor.Fit,
                                HAnchor = HAnchor.Fit
                            };
                            row.AddChild(editButton);

                            // only show the switch if leveling can be turned off (it can't if it is required).
                            if (!printer.Settings.GetValue <bool>(SettingsKey.print_leveling_required_to_print))
                            {
                                // put in the switch
                                printLevelingSwitch = new RoundedToggleSwitch(theme)
                                {
                                    VAnchor     = VAnchor.Center,
                                    Margin      = new BorderDouble(theme.DefaultContainerPadding, 0),
                                    Checked     = printer.Settings.GetValue <bool>(SettingsKey.print_leveling_enabled),
                                    ToolTipText = "Enable Software Leveling".Localize()
                                };
                                printLevelingSwitch.CheckedStateChanged += (sender, e) =>
                                {
                                    printer.Settings.Helpers.DoPrintLeveling(printLevelingSwitch.Checked);
                                };
                                printLevelingSwitch.Closed += (s, e) =>
                                {
                                    // Unregister listeners
                                    printer.Settings.PrintLevelingEnabledChanged -= Settings_PrintLevelingEnabledChanged;
                                };

                                // TODO: Why is this listener conditional? If the leveling changes somehow, shouldn't we be updated the UI to reflect that?
                                // Register listeners
                                printer.Settings.PrintLevelingEnabledChanged += Settings_PrintLevelingEnabledChanged;

                                row.AddChild(printLevelingSwitch);
                            }

                            rightWidget = row;

                            var leftToRight = new FlowLayoutWidget()
                            {
                                HAnchor = HAnchor.Stretch
                            };

                            column.AddChild(leftToRight);

                            var probeWidget = new ProbePositionsWidget(printer, positions.Select(v => new Vector2(v)).ToList(), theme)
                            {
                                HAnchor            = HAnchor.Absolute,
                                VAnchor            = VAnchor.Absolute,
                                Height             = 200,
                                Width              = 200,
                                RenderLevelingData = true,
                                RenderProbePath    = false,
                                SimplePoints       = true,
                            };
                            leftToRight.AddChild(probeWidget);

                            AddRunStageButton("Run Print Leveling".Localize(), theme, stage, leftToRight);
                        }
                        else if (!printer.Settings.GetValue <bool>(SettingsKey.print_leveling_required_to_print))
                        {
                            column.AddChild(new WrappedTextWidget(
                                                @"Print Leveling is an optional feature for this printer that can help improve print quality. If the bed is uneven or cannot be mechanically leveled, you can click the button to the left to setup Print Leveling.".Localize(),
                                                pointSize: theme.DefaultFontSize,
                                                textColor: theme.TextColor));
                        }

                        widget = column;
                    }

                    if (stage is XyCalibrationWizard xyWizard)
                    {
                        var row = CreateColumn(theme);
                        row.FlowDirection = FlowDirection.LeftToRight;

                        var hotendOffset = printer.Settings.Helpers.ExtruderOffset(1);

                        var tool2Column = new FlowLayoutWidget(FlowDirection.TopToBottom);
                        row.AddChild(tool2Column);

                        tool2Column.AddChild(
                            new TextWidget("Tool".Localize() + " 2", pointSize: theme.DefaultFontSize, textColor: theme.TextColor)
                        {
                            Margin = new BorderDouble(bottom: 4)
                        });

                        tool2Column.AddChild(
                            new ValueTag(
                                "X Offset".Localize(),
                                hotendOffset.X.ToString("0.###"),
                                new BorderDouble(12, 5, 2, 5),
                                5,
                                11)
                        {
                            Margin      = new BorderDouble(bottom: 4),
                            MinimumSize = new Vector2(125, 0)
                        });

                        tool2Column.AddChild(
                            new ValueTag(
                                "Y Offset".Localize(),
                                hotendOffset.Y.ToString("0.###"),
                                new BorderDouble(12, 5, 2, 5),
                                5,
                                11)
                        {
                            MinimumSize = new Vector2(125, 0)
                        });

                        AddRunStageButton("Run Nozzle Alignment".Localize(), theme, stage, row);

                        widget = row;
                    }

                    if (stage.SetupRequired)
                    {
                        var column = CreateColumn(theme);
                        column.AddChild(new TextWidget("Setup Required".Localize(), pointSize: theme.DefaultFontSize, textColor: theme.TextColor));

                        widget = column;
                    }
                    else if (stage is LoadFilamentWizard filamentWizard)
                    {
                        widget.Margin = new BorderDouble(left: theme.DefaultContainerPadding);
                    }

                    var section = new SectionWidget(stage.Title, widget, theme, rightAlignedContent: rightWidget, expandingContent: false);
                    theme.ApplyBoxStyle(section);

                    section.Margin            = section.Margin.Clone(left: 0);
                    section.ShowExpansionIcon = false;

                    if (stage.SetupRequired)
                    {
                        section.BackgroundColor = Color.Red.WithAlpha(30);
                    }

                    contentRow.AddChild(section);
                }

                return(homePage);
            };
        }
Beispiel #10
0
        public ConfigurePrinterWidget(SettingsContext settingsContext, PrinterConfig printer, ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            var inlineNameEdit = new InlineStringEdit(printer.Settings.GetValue(SettingsKey.printer_name), theme, "Printer Name", boldFont: true);

            inlineNameEdit.ValueChanged += (s, e) =>
            {
                printer.Settings.SetValue(SettingsKey.printer_name, inlineNameEdit.Text);
            };
            this.AddChild(inlineNameEdit);

            this.AddChild(
                new SliceSettingsTabView(
                    settingsContext,
                    "ConfigurePrinter",
                    printer,
                    "Printer",
                    theme,
                    isPrimarySettingsView: true,
                    databaseMRUKey: UserSettingsKey.ConfigurePrinter_CurrentTab));
        }
        public EditLevelingSettingsPage(PrinterConfig printer, ThemeConfig theme)
        {
            this.printer = printer;

            this.WindowTitle = "Leveling Settings".Localize();
            this.HeaderText  = "Sampled Positions".Localize();

            var scrollableWidget = new ScrollableWidget()
            {
                AutoScroll = true,
                HAnchor    = HAnchor.Stretch,
                VAnchor    = VAnchor.Stretch,
            };

            scrollableWidget.ScrollArea.HAnchor = HAnchor.Stretch;
            contentRow.AddChild(scrollableWidget);

            // No right padding removes unexpected spacing to the right of scrollbar
            contentRow.Padding = contentRow.Padding.Clone(right: 0);

            var column = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Stretch,
                Padding = new BorderDouble(right: theme.DefaultContainerPadding + 4)
            };

            scrollableWidget.AddChild(column);

            var positions = new List <Vector3>();

            PrintLevelingData levelingData = printer.Settings.Helpers.PrintLevelingData;

            for (int i = 0; i < levelingData.SampledPositions.Count; i++)
            {
                positions.Add(levelingData.SampledPositions[i]);
            }

            int tab_index = 0;

            for (int row = 0; row < positions.Count; row++)
            {
                var leftRightEdit = new FlowLayoutWidget
                {
                    Padding = new BorderDouble(3),
                    HAnchor = HAnchor.Stretch
                };

                var positionLabel = new TextWidget("{0} {1,-5}".FormatWith("Position".Localize(), row + 1), textColor: theme.TextColor);

                positionLabel.VAnchor = VAnchor.Center;
                leftRightEdit.AddChild(positionLabel);

                for (int axis = 0; axis < 3; axis++)
                {
                    leftRightEdit.AddChild(new HorizontalSpacer());

                    string axisName = "x";
                    if (axis == 1)
                    {
                        axisName = "y";
                    }
                    else if (axis == 2)
                    {
                        axisName = "z";
                    }

                    leftRightEdit.AddChild(
                        new TextWidget($"  {axisName}: ", textColor: theme.TextColor)
                    {
                        VAnchor = VAnchor.Center
                    });

                    int linkCompatibleRow  = row;
                    int linkCompatibleAxis = axis;

                    MHNumberEdit valueEdit = new MHNumberEdit(positions[linkCompatibleRow][linkCompatibleAxis], theme, allowNegatives: true, allowDecimals: true, pixelWidth: 60 * GuiWidget.DeviceScale, tabIndex: tab_index++)
                    {
                        Name = $"{axisName} Position {row}"
                    };
                    valueEdit.ActuallNumberEdit.InternalTextEditWidget.EditComplete += (sender, e) =>
                    {
                        Vector3 position = positions[linkCompatibleRow];
                        position[linkCompatibleAxis] = valueEdit.ActuallNumberEdit.Value;
                        positions[linkCompatibleRow] = position;
                    };

                    valueEdit.Margin = new BorderDouble(3);
                    leftRightEdit.AddChild(valueEdit);
                }

                column.AddChild(leftRightEdit);
            }

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

            savePresetsButton.Name   = "Save Leveling Button";
            savePresetsButton.Click += (s, e) =>
            {
                PrintLevelingData newLevelingData = printer.Settings.Helpers.PrintLevelingData;

                for (int i = 0; i < newLevelingData.SampledPositions.Count; i++)
                {
                    newLevelingData.SampledPositions[i] = positions[i];
                }

                printer.Settings.Helpers.PrintLevelingData = newLevelingData;
                this.DialogWindow.Close();
            };
            this.AddPageAction(savePresetsButton);

            var exportButton = theme.CreateDialogButton("Export".Localize());

            exportButton.Click += (s, e) => {
                UiThread.RunOnIdle(this.ExportSettings, .1);
            };
            this.AddPageAction(exportButton);
        }
        public ConfigurePrinterWidget(SettingsContext settingsContext, PrinterConfig printer, ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            var inlineNameEdit = new InlineStringEdit(printer.Settings.GetValue(SettingsKey.printer_name), theme, "Printer Name", boldFont: true);

            inlineNameEdit.ValueChanged += (s, e) =>
            {
                printer.Settings.SetValue(SettingsKey.printer_name, inlineNameEdit.Text);
            };
            this.AddChild(inlineNameEdit);

            void Printer_SettingChanged(object s, StringEventArgs stringEvent)
            {
                if (s is PrinterSettings printerSettings &&
                    stringEvent?.Data == SettingsKey.printer_name)
                {
                    // Try to find a printer tab for the given printer
                    inlineNameEdit.Text = printerSettings.GetValue(SettingsKey.printer_name);
                }
            }

            printer.Settings.SettingChanged += Printer_SettingChanged;

            inlineNameEdit.Closed += (s, e) =>
            {
                printer.Settings.SettingChanged -= Printer_SettingChanged;
            };

            var settingsSection = PrinterSettings.Layout.PrinterSections[0];

            switch (UserSettings.Instance.get(UserSettingsKey.SliceSettingsViewDetail))
            {
            case "Simple":
                settingsSection = PrinterSettings.Layout.PrinterSections[0];
                break;

            case "Intermediate":
                settingsSection = PrinterSettings.Layout.PrinterSections[1];
                break;

            case "Advanced":
                settingsSection = PrinterSettings.Layout.PrinterSections[2];
                break;
            }

            this.AddChild(
                new SliceSettingsTabView(
                    settingsContext,
                    "ConfigurePrinter",
                    printer,
                    settingsSection,
                    theme,
                    isPrimarySettingsView: true,
                    justMySettingsTitle: "My Modified Settings (Printer)".Localize(),
                    databaseMRUKey: UserSettingsKey.ConfigurePrinter_CurrentTab));
        }
Beispiel #13
0
        public CalibrationTabWidget(XyCalibrationWizard calibrationWizard, TextButton nextButton, ThemeConfig theme)
        {
            this.calibrationWizard = calibrationWizard;
            this.theme             = theme;
            this.NextButton        = nextButton;
            tabBaseColor           = new Color(theme.SlightShade.ToColorF(), theme.SlightShade.Alpha0To1 * 1.2);

            double barWidth  = 30;
            double barHeight = 300;

            double left   = LocalBounds.Left + 15;
            double bottom = LocalBounds.Bottom + 15;
            double right  = left + barHeight;

            var a = new Vector2(left, bottom);
            var b = new Vector2(left, bottom + barHeight);
            var c = new Vector2(left + barWidth, bottom + barHeight);
            var d = new Vector2(left + barWidth, bottom + barWidth);
            var e = new Vector2(right, bottom + barWidth);
            var f = new Vector2(right + (barWidth * .7), bottom + (barWidth / 2));
            var g = new Vector2(right, bottom);

            var m = new Vector2(b.X + (barWidth / 2), b.Y + (barWidth * .6));
            var n = new Vector2(m.X, b.Y);
            var r = new Vector2(b.X, m.Y);

            var tabShape2 = new VertexStorage();

            tabShape2.Add(a.X, a.Y, FlagsAndCommand.MoveTo); // A
            tabShape2.LineTo(b);                             // A - B

            tabShape2.curve3(r.X, r.Y, m.X, m.Y);            // B -> C
            tabShape2.curve3(c.X, c.Y);

            tabShape2.LineTo(d);             // C -> D
            tabShape2.LineTo(e);             // D -> E
            tabShape2.LineTo(f);             // E -> F
            tabShape2.LineTo(g);             // F -> G
            tabShape2.ClosePolygon();

            int highlightStroke = 2;
            int highlightOffset = 8;
            int highlightWidth  = 16;

            double x1 = d.X + highlightOffset;
            double x2 = x1 + highlightWidth;
            double y1 = d.Y + highlightOffset;
            double y2 = c.Y - highlightOffset;

            double midY = y1 + (y2 - y1) / 2;

            var highlighter = new VertexStorage();

            highlighter.MoveTo(x1, y1);
            highlighter.LineTo(x2, y1);
            highlighter.LineTo(x2, midY);
            highlighter.LineTo(x2 + highlightOffset, midY);
            highlighter.LineTo(x2, midY);
            highlighter.LineTo(x2, y2);
            highlighter.LineTo(x1, y2);

            xHighlighter = new Stroke(highlighter, highlightStroke);

            xLabel = new TextWidget("Select the most centered pad", pointSize: theme.DefaultFontSize, textColor: theme.TextColor)
            {
                HAnchor = HAnchor.Absolute,
                VAnchor = VAnchor.Absolute
            };

            xLabel.Position = new Vector2(x2 + highlightOffset * 2, midY - xLabel.Height / 2);

            this.AddChild(xLabel);

            x1 = d.X + highlightOffset;
            y1 = d.Y + 50;

            x1 = d.X + highlightOffset;
            x2 = e.X - highlightOffset;
            y1 = d.Y + highlightOffset;
            y2 = y1 + highlightWidth;

            double midX = x1 + (x2 - x1) / 2;

            highlighter = new VertexStorage();
            highlighter.MoveTo(x1, y1);
            highlighter.LineTo(x1, y2);
            highlighter.LineTo(midX, y2);
            highlighter.LineTo(midX, y2 + highlightOffset);
            highlighter.LineTo(midX, y2);
            highlighter.LineTo(x2, y2);
            highlighter.LineTo(x2, y1);

            yHighlighter = new Stroke(highlighter, highlightStroke);

            yLabel = new TextWidget("Select the most centered pad", pointSize: theme.DefaultFontSize, textColor: theme.TextColor)
            {
                HAnchor = HAnchor.Absolute,
                VAnchor = VAnchor.Absolute,
                Visible = false,
            };
            this.AddChild(yLabel);

            yLabel.Position = new Vector2(midX - yLabel.Width / 2, y2 + (highlightOffset * 2));

            yHighlighter = new Stroke(highlighter, highlightStroke);

            int padCount = 7;

            double cellSize = (barHeight - barWidth) / padCount;
            int    padding  = (int)(cellSize * .3);

            double padSize = cellSize - padding;

            var titles = new[] { "-3", "-2", "-1", "0", "+1", "+2", "+3" };

            for (var i = 0; i < padCount; i++)
            {
                this.AddChild(new CalibrationPad(titles[i], theme, pointSize: theme.DefaultFontSize - 1)
                {
                    Position = new Vector2(left, bottom + 3 + barWidth + (cellSize * i)),
                    Height   = padSize,
                    Width    = barWidth,
                    Index    = i,
                    IsActive = i == 3,
                    Axis     = PrinterConnection.Axis.X
                });

                this.AddChild(new CalibrationPad(titles[i], theme, pointSize: theme.DefaultFontSize - 1)
                {
                    Position = new Vector2(left + 3 + barWidth + (cellSize * i), bottom),
                    Height   = barWidth,
                    Width    = padSize,
                    Index    = i,
                    IsActive = i == 3,
                    Axis     = PrinterConnection.Axis.Y
                });
            }

            foreach (var calibrationPad in this.Children.OfType <CalibrationPad>())
            {
                calibrationPad.Click   += this.CalibrationPad_Click;
                calibrationPad.Hovered += this.CalibrationPad_Hovered;
            }

            tabShape  = new FlattenCurves(tabShape2);
            tabStroke = new Stroke(tabShape);
        }
Beispiel #14
0
        public PrinterSelector(ThemeConfig theme)
            : base("Printers".Localize() + "... ", theme.Colors.PrimaryTextColor, pointSize: theme.DefaultFontSize)
        {
            this.Name            = "Printers... Menu";
            this.BorderColor     = Color.Transparent;
            this.AutoScaleIcons  = false;
            this.BackgroundColor = theme.MinimalShade;
            this.GutterWidth     = 30;

            this.MenuItemsTextHoverColor = new Color("#ddd");

            this.Rebuild();

            this.SelectionChanged += (s, e) =>
            {
                var activePrinter = ApplicationController.Instance.ActivePrinter;

                string printerID = this.SelectedValue;
                if (printerID == "new" ||
                    string.IsNullOrEmpty(printerID) ||
                    printerID == activePrinter.Settings.ID)
                {
                    // do nothing
                }
                else
                {
                    // TODO: when this opens a new tab we will not need to check any printer
                    if (activePrinter.Connection.PrinterIsPrinting ||
                        activePrinter.Connection.PrinterIsPaused)
                    {
                        if (this.SelectedIndex != lastSelectedIndex)
                        {
                            UiThread.RunOnIdle(() =>
                                               StyledMessageBox.ShowMessageBox("Please wait until the print has finished and try again.".Localize(), "Can't switch printers while printing".Localize())
                                               );
                            this.SelectedIndex = lastSelectedIndex;
                        }
                    }
                    else
                    {
                        lastSelectedIndex = this.SelectedIndex;

                        ProfileManager.Instance.LastProfileID = this.SelectedValue;
                    }
                }
            };

            PrinterSettings.SettingChanged.RegisterEvent((s, e) =>
            {
                var activePrinter = ApplicationController.Instance.ActivePrinter;

                string settingsName = (e as StringEventArgs)?.Data;
                if (settingsName != null && settingsName == SettingsKey.printer_name)
                {
                    if (ProfileManager.Instance.ActiveProfile != null)
                    {
                        ProfileManager.Instance.ActiveProfile.Name = activePrinter.Settings.GetValue(SettingsKey.printer_name);
                        Rebuild();
                    }
                }
            }, ref unregisterEvents);

            // Rebuild the droplist any time the ActivePrinter changes
            ApplicationController.Instance.ActivePrinterChanged.RegisterEvent((s, e) =>
            {
                this.Rebuild();
            }, ref unregisterEvents);

            // Rebuild the droplist any time the Profiles list changes
            ProfileManager.ProfilesListChanged.RegisterEvent((s, e) =>
            {
                this.Rebuild();
            }, ref unregisterEvents);

            HAnchor = HAnchor.Fit;
            Cursor  = Cursors.Hand;
            Margin  = 0;
        }