Beispiel #1
0
        private void AddRightClickPrinterMenu(ChromeTab printerTab, PrinterConfig printer, MouseEventArgs mouseEvent)
        {
            var menuTheme = ApplicationController.Instance.MenuTheme;
            var popupMenu = new PopupMenu(menuTheme);

            var renameMenuItem = popupMenu.CreateMenuItem("Rename".Localize());

            renameMenuItem.Click += (s, e) =>
            {
                DialogWindow.Show(
                    new InputBoxPage(
                        "Rename Item".Localize(),
                        "Name".Localize(),
                        printer.Settings.GetValue(SettingsKey.printer_name),
                        "Enter New Name Here".Localize(),
                        "Rename".Localize(),
                        (newName) =>
                {
                    printer.Settings.SetValue(SettingsKey.printer_name, newName);
                }));
            };

            popupMenu.ShowMenu(printerTab, mouseEvent);
        }
        private void AddRightClickTabMenu(ChromeTabs tabs, ChromeTab printerTab, PrinterConfig printer, PartWorkspace workspace, MouseEventArgs mouseEvent)
        {
            var menuTheme = ApplicationController.Instance.MenuTheme;
            var popupMenu = new PopupMenu(menuTheme);

            var renameMenuItem = popupMenu.CreateMenuItem("Rename".Localize());

            renameMenuItem.Click += (s, e) =>
            {
                if (workspace != null)
                {
                    workspace.LibraryView.ActiveContainer.Rename(workspace.LibraryView.ActiveContainer.Items.FirstOrDefault());
                }
                else if (printer != null)
                {
                    DialogWindow.Show(
                        new InputBoxPage(
                            "Rename Item".Localize(),
                            "Name".Localize(),
                            printer.Settings.GetValue(SettingsKey.printer_name),
                            "Enter New Name Here".Localize(),
                            "Rename".Localize(),
                            (newName) =>
                    {
                        printer.Settings.SetValue(SettingsKey.printer_name, newName);
                    }));
                }
            };


            var moveButtons = new FlowLayoutWidget();

            var textWidget = new TextWidget("Move Tab", pointSize: theme.DefaultFontSize, textColor: theme.TextColor)
            {
                Margin  = PopupMenu.MenuPadding.Clone(PopupMenu.MenuPadding.Left - 5, right: 5),
                VAnchor = VAnchor.Center,
            };

            moveButtons.AddChild(textWidget);
            var buttonSize     = 24 * DeviceScale;
            var moveLeftButton = new IconButton(StaticData.Instance.LoadIcon("fa-angle-right_12.png", 14, 14, theme.InvertIcons).MirrorX(), theme)
            {
                Width      = buttonSize,
                Height     = buttonSize,
                Margin     = new BorderDouble(3, 0),
                HoverColor = theme.AccentMimimalOverlay,
                VAnchor    = VAnchor.Center,
                Enabled    = tabs.GetTabIndex(printerTab) > tabs.FirstMovableTab,
            };

            moveLeftButton.Click += (s, e) =>
            {
                tabs.MoveTabLeft(printerTab);
                popupMenu.Unfocus();
            };
            moveButtons.AddChild(moveLeftButton);

            var moveRightButton = new IconButton(StaticData.Instance.LoadIcon("fa-angle-right_12.png", 14, 14, theme.InvertIcons), theme)
            {
                Width      = buttonSize,
                Height     = buttonSize,
                Margin     = new BorderDouble(3, 0),
                HoverColor = theme.AccentMimimalOverlay,
                VAnchor    = VAnchor.Center,
                Enabled    = printerTab.NextTab != null,
            };

            moveRightButton.Click += (s, e) =>
            {
                tabs.MoveTabRight(printerTab);
                popupMenu.Unfocus();
            };
            moveButtons.AddChild(moveRightButton);

            popupMenu.AddChild(moveButtons);

            popupMenu.ShowMenu(printerTab, mouseEvent);
        }
Beispiel #3
0
        private void GeneratePrinterOverflowMenu(PopupMenu popupMenu, ThemeConfig theme)
        {
            var menuActions = new List <NamedAction>()
            {
                new NamedAction()
                {
                    Icon      = AggContext.StaticData.LoadIcon("memory_16x16.png", 16, 16, theme.InvertIcons),
                    Title     = "Configure EEProm".Localize(),
                    Action    = configureEePromButton_Click,
                    IsEnabled = () => printer.Connection.IsConnected
                },
                new NamedBoolAction()
                {
                    Title       = "Show Controls".Localize(),
                    Action      = () => { },
                    GetIsActive = () => printer.ViewState.ControlsVisible,
                    SetIsActive = (value) => printer.ViewState.ControlsVisible = value
                },
                new NamedBoolAction()
                {
                    Title       = "Show Terminal".Localize(),
                    Action      = () => { },
                    GetIsActive = () => printer.ViewState.TerminalVisible,
                    SetIsActive = (value) => printer.ViewState.TerminalVisible = value
                },
                new NamedBoolAction()
                {
                    Title       = "Configure Printer".Localize(),
                    Action      = () => { },
                    GetIsActive = () => printer.ViewState.ConfigurePrinterVisible,
                    SetIsActive = (value) => printer.ViewState.ConfigurePrinterVisible = value
                },
                new ActionSeparator(),
                new NamedAction()
                {
                    Title  = "Import Presets".Localize(),
                    Action = () =>
                    {
                        AggContext.FileDialogs.OpenFileDialog(
                            new OpenFileDialogParams("settings files|*.printer"),
                            (dialogParams) =>
                        {
                            if (!string.IsNullOrEmpty(dialogParams.FileName))
                            {
                                DialogWindow.Show(new ImportSettingsPage(dialogParams.FileName, printer));
                            }
                        });
                    }
                },
                new NamedAction()
                {
                    Title  = "Export Printer".Localize(),
                    Action = () => UiThread.RunOnIdle(() =>
                    {
                        ApplicationController.Instance.ExportAsMatterControlConfig(printer);
                    }),
                    Icon = AggContext.StaticData.LoadIcon("cube_export.png", 16, 16, theme.InvertIcons),
                },
                new ActionSeparator(),

                new NamedAction()
                {
                    Title  = "Calibrate Printer".Localize(),
                    Action = () => UiThread.RunOnIdle(() =>
                    {
                        UiThread.RunOnIdle(() =>
                        {
                            DialogWindow.Show(new PrinterCalibrationWizard(printer, theme));
                        });
                    }),
                    Icon = AggContext.StaticData.LoadIcon("compass.png", theme.InvertIcons)
                },
                new ActionSeparator(),
                new NamedAction()
                {
                    Title  = "Restore Settings".Localize(),
                    Action = () =>
                    {
                        DialogWindow.Show(new PrinterProfileHistoryPage(printer));
                    }
                },
                new NamedAction()
                {
                    Title  = "Reset to Defaults".Localize(),
                    Action = () =>
                    {
                        StyledMessageBox.ShowMessageBox(
                            (revertSettings) =>
                        {
                            if (revertSettings)
                            {
                                printer.Settings.ClearUserOverrides();
                                printer.Settings.ClearBlackList();
                                // this is user driven
                                printer.Settings.Save();
                                printer.Settings.Helpers.PrintLevelingData.SampledPositions.Clear();

                                ApplicationController.Instance.ReloadAll().ConfigureAwait(false);
                            }
                        },
                            "Resetting to default values will remove your current overrides and restore your original printer settings.\nAre you sure you want to continue?".Localize(),
                            "Revert Settings".Localize(),
                            StyledMessageBox.MessageType.YES_NO);
                    }
                },
                new ActionSeparator(),
                new NamedAction()
                {
                    Title  = "Delete Printer".Localize(),
                    Action = () =>
                    {
                        StyledMessageBox.ShowMessageBox(
                            (doDelete) =>
                        {
                            if (doDelete)
                            {
                                ProfileManager.Instance.DeletePrinter(printer.Settings.ID);
                            }
                        },
                            "Are you sure you want to delete printer '{0}'?".Localize().FormatWith(printer.Settings.GetValue(SettingsKey.printer_name)),
                            "Delete Printer?".Localize(),
                            StyledMessageBox.MessageType.YES_NO,
                            "Delete Printer".Localize());
                    },
                }
            };

            theme.CreateMenuItems(popupMenu, menuActions);
        }
        public SelectedObjectPanel(View3DWidget view3DWidget, BedConfig sceneContext, ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            this.HAnchor      = HAnchor.Stretch;
            this.VAnchor      = VAnchor.Top | VAnchor.Fit;
            this.Padding      = 0;
            this.view3DWidget = view3DWidget;
            this.theme        = theme;
            this.sceneContext = sceneContext;

            this.ContentPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit,
            };

            var scrollable = new ScrollableWidget(true)
            {
                Name    = "editorPanel",
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch,
            };

            scrollable.AddChild(this.ContentPanel);
            scrollable.ScrollArea.HAnchor = HAnchor.Stretch;

            this.AddChild(scrollable);

            var toolbar = new LeftClipFlowLayoutWidget()
            {
                BackgroundColor = theme.TabBodyBackground,
                Padding         = theme.ToolbarPadding,
                HAnchor         = HAnchor.Fit,
                VAnchor         = VAnchor.Fit
            };

            var scene = sceneContext.Scene;

            // put in a make permanent button
            var icon        = AggContext.StaticData.LoadIcon("fa-check_16.png", 16, 16, theme.InvertIcons).SetPreMultiply();
            var applyButton = new IconButton(icon, theme)
            {
                Margin      = theme.ButtonSpacing,
                ToolTipText = "Apply operation and make permanent".Localize()
            };

            applyButton.Click += (s, e) =>
            {
                this.item.Apply(view3DWidget.Scene.UndoBuffer);
                scene.SelectedItem = null;
            };
            scene.SelectionChanged += (s, e) => applyButton.Enabled = scene.SelectedItem?.CanApply == true;
            toolbar.AddChild(applyButton);

            // put in a remove button
            var removeButton = new IconButton(AggContext.StaticData.LoadIcon("close.png", 16, 16, theme.InvertIcons), theme)
            {
                Margin      = theme.ButtonSpacing,
                ToolTipText = "Remove operation from parts".Localize()
            };

            removeButton.Click += (s, e) =>
            {
                item.Remove(view3DWidget.Scene.UndoBuffer);
                scene.SelectedItem = null;
            };
            scene.SelectionChanged += (s, e) => removeButton.Enabled = scene.SelectedItem?.CanRemove == true;
            toolbar.AddChild(removeButton);

            var overflowButton = new OverflowBar.OverflowMenuButton(theme);

            overflowButton.PopupBorderColor    = ApplicationController.Instance.MenuTheme.GetBorderColor(120);
            overflowButton.DynamicPopupContent = () =>
            {
                var popupMenu = new PopupMenu(ApplicationController.Instance.MenuTheme);

                var menuItem = popupMenu.CreateMenuItem("Rename");
                menuItem.Click += (s, e) =>
                {
                    DialogWindow.Show(
                        new InputBoxPage(
                            "Rename Item".Localize(),
                            "Name".Localize(),
                            item.Name,
                            "Enter New Name Here".Localize(),
                            "Rename".Localize(),
                            (newName) =>
                    {
                        item.Name = newName;
                        editorSectionWidget.Text = newName;
                    }));
                };

                popupMenu.CreateHorizontalLine();

                if (true)                 //allowOperations)
                {
                    var selectedItemType = item.GetType();
                    var selectedItem     = item;

                    foreach (var nodeOperation in ApplicationController.Instance.Graph.Operations)
                    {
                        foreach (var type in nodeOperation.MappedTypes)
                        {
                            if (type.IsAssignableFrom(selectedItemType) &&
                                (nodeOperation.IsVisible?.Invoke(selectedItem) != false) &&
                                nodeOperation.IsEnabled?.Invoke(selectedItem) != false)
                            {
                                var button = popupMenu.CreateMenuItem(nodeOperation.Title, nodeOperation.IconCollector?.Invoke()?.CreateScaledImage(16, 16));
                                button.Click += (s, e) =>
                                {
                                    nodeOperation.Operation(selectedItem, sceneContext.Scene).ConfigureAwait(false);
                                };
                            }
                        }
                    }
                }

                return(popupMenu);
            };
            toolbar.AddChild(overflowButton);

            editorPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit,
                Padding = new BorderDouble(top: 10)
            };

            // Wrap editorPanel with scrollable container
            var scrollableWidget = new ScrollableWidget(true)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            };

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

            editorSectionWidget = new ResizableSectionWidget("Editor", sceneContext.ViewState.SelectedObjectEditorHeight, scrollableWidget, theme, serializationKey: UserSettingsKey.EditorPanelExpanded, rightAlignedContent: toolbar, defaultExpansion: true)
            {
                VAnchor = VAnchor.Fit,
            };
            editorSectionWidget.Resized += (s, e) =>
            {
                sceneContext.ViewState.SelectedObjectEditorHeight = editorSectionWidget.ResizeContainer.Height;
            };

            this.ContentPanel.AddChild(editorSectionWidget);

            var colorSection = new SectionWidget(
                "Color".Localize(),
                new ColorSwatchSelector(scene, theme, buttonSize: 16, buttonSpacing: new BorderDouble(1, 1, 0, 0))
            {
                Margin = new BorderDouble(left: 10)
            },
                theme,
                serializationKey: UserSettingsKey.ColorPanelExpanded)
            {
                Name = "Color Panel",
            };

            this.ContentPanel.AddChild(colorSection);

            var materialsSection = new SectionWidget("Materials".Localize(), new MaterialControls(scene, theme), theme, serializationKey: UserSettingsKey.MaterialsPanelExpanded)
            {
                Name = "Materials Panel",
            };

            this.ContentPanel.AddChild(materialsSection);

            // Enforce panel padding in sidebar
            foreach (var sectionWidget in this.ContentPanel.Children <SectionWidget>())
            {
                // Special case for editorResizeWrapper due to ResizeContainer
                if (sectionWidget is ResizableSectionWidget resizableSectionWidget)
                {
                    // Apply padding to ResizeContainer not wrapper
                    resizableSectionWidget.ResizeContainer.Padding = new BorderDouble(10, 10, 10, 0);
                }
                else
                {
                    sectionWidget.ContentPanel.Padding   = new BorderDouble(10, 10, 10, 0);
                    sectionWidget.ExpandableWhenDisabled = true;
                    sectionWidget.Enabled = false;
                }
            }
        }
Beispiel #5
0
 protected virtual void GetViewControls3DOverflowMenu(PopupMenu popupMenu)
 {
     view3DWidget.ShowOverflowMenu(popupMenu);
 }
Beispiel #6
0
 internal void ShowGCodeOverflowMenu(PopupMenu popupMenu)
 {
 }
Beispiel #7
0
 protected virtual void OnExtendPopupMenu(PopupMenu popupMenu)
 {
     this.ExtendOverflowMenu(popupMenu);
 }
        public ViewControls3D(PartWorkspace workspace, ThemeConfig theme, UndoBuffer undoBuffer, bool isPrinterType, bool showPrintButton)
            : base(theme)
        {
            this.theme             = theme;
            this.undoBuffer        = undoBuffer;
            this.ActionArea.Click += (s, e) =>
            {
                view3DWidget.InteractionLayer.Focus();
            };

            this.OverflowButton.DynamicPopupContent = () =>
            {
                var menuTheme = AppContext.MenuTheme;
                var popupMenu = new PopupMenu(theme);
                int i         = 0;

                foreach (var widget in this.ActionArea.Children.Where(c => !c.Visible && !ignoredInMenuTypes.Contains(c.GetType())))
                {
                    if (operationButtons.TryGetValue(widget, out SceneSelectionOperation operation))
                    {
                        if (operation is OperationGroup operationGroup)
                        {
                            popupMenu.CreateSubMenu(
                                operationGroup.Title,
                                menuTheme,
                                (subMenu) =>
                            {
                                foreach (var childOperation in operationGroup.Operations)
                                {
                                    var menuItem    = subMenu.CreateMenuItem(childOperation.Title, childOperation.Icon(menuTheme.InvertIcons));
                                    menuItem.Click += (s, e) => UiThread.RunOnIdle(() =>
                                    {
                                        childOperation.Action?.Invoke(sceneContext);
                                    });
                                }
                            });
                        }
                        else
                        {
                            popupMenu.CreateMenuItem(operation.Title, operation.Icon(menuTheme.InvertIcons));
                        }
                    }
                }

                return(popupMenu);
            };

            this.IsPrinterMode = isPrinterType;
            this.sceneContext  = workspace.SceneContext;
            this.workspace     = workspace;

            string iconPath;

            this.AddChild(CreateAddButton(sceneContext, theme));

            this.AddChild(new ToolbarSeparator(theme));

            bedMenuButton = new PopupMenuButton(AggContext.StaticData.LoadIcon("bed.png", 16, 16, theme.InvertIcons), theme)
            {
                Name        = "Bed Options Menu",
                ToolTipText = "Bed",
                Enabled     = true,
                Margin      = theme.ButtonSpacing,
                VAnchor     = VAnchor.Center,
                DrawArrow   = true
            };

            this.AddChild(bedMenuButton);

            this.AddChild(new ToolbarSeparator(theme));

            this.AddChild(CreateOpenButton(theme));

            this.AddChild(CreateSaveButton(theme));

            this.AddChild(new ToolbarSeparator(theme));

            undoButton = new IconButton(AggContext.StaticData.LoadIcon("Undo_grey_16x.png", 16, 16, theme.InvertIcons), theme)
            {
                Name        = "3D View Undo",
                ToolTipText = "Undo".Localize(),
                Enabled     = false,
                Margin      = theme.ButtonSpacing,
                VAnchor     = VAnchor.Center
            };
            undoButton.Click += (sender, e) =>
            {
                sceneContext.Scene.Undo();
                view3DWidget.InteractionLayer.Focus();
            };
            this.AddChild(undoButton);

            redoButton = new IconButton(AggContext.StaticData.LoadIcon("Redo_grey_16x.png", 16, 16, theme.InvertIcons), theme)
            {
                Name        = "3D View Redo",
                Margin      = theme.ButtonSpacing,
                ToolTipText = "Redo".Localize(),
                Enabled     = false,
                VAnchor     = VAnchor.Center
            };
            redoButton.Click += (sender, e) =>
            {
                sceneContext.Scene.Redo();
                view3DWidget.InteractionLayer.Focus();
            };
            this.AddChild(redoButton);

            if (showPrintButton)
            {
                var printButton = new TextButton("Print", theme)
                {
                    Name            = "Print Button",
                    BackgroundColor = theme.AccentMimimalOverlay
                };
                printButton.Click += (s, e) =>
                {
                    view3DWidget.PushToPrinterAndPrint();
                };
                this.AddChild(printButton);
            }

            this.AddChild(new ToolbarSeparator(theme));

            undoButton.Enabled = undoBuffer.UndoCount > 0;
            redoButton.Enabled = undoBuffer.RedoCount > 0;

            var buttonGroupA = new ObservableCollection <GuiWidget>();

            if (UserSettings.Instance.IsTouchScreen)
            {
                iconPath     = Path.Combine("ViewTransformControls", "rotate.png");
                rotateButton = new RadioIconButton(AggContext.StaticData.LoadIcon(iconPath, 32, 32, theme.InvertIcons), theme)
                {
                    SiblingRadioButtonList = buttonGroupA,
                    ToolTipText            = "Rotate (Alt + Left Mouse)".Localize(),
                    Margin = theme.ButtonSpacing
                };
                rotateButton.Click += (s, e) => this.ActiveButton = ViewControls3DButtons.Rotate;
                buttonGroupA.Add(rotateButton);
                AddChild(rotateButton);

                iconPath        = Path.Combine("ViewTransformControls", "translate.png");
                translateButton = new RadioIconButton(AggContext.StaticData.LoadIcon(iconPath, 32, 32, theme.InvertIcons), theme)
                {
                    SiblingRadioButtonList = buttonGroupA,
                    ToolTipText            = "Move (Shift + Left Mouse)".Localize(),
                    Margin = theme.ButtonSpacing
                };
                translateButton.Click += (s, e) => this.ActiveButton = ViewControls3DButtons.Translate;
                buttonGroupA.Add(translateButton);
                AddChild(translateButton);

                iconPath    = Path.Combine("ViewTransformControls", "scale.png");
                scaleButton = new RadioIconButton(AggContext.StaticData.LoadIcon(iconPath, 32, 32, theme.InvertIcons), theme)
                {
                    SiblingRadioButtonList = buttonGroupA,
                    ToolTipText            = "Zoom (Ctrl + Left Mouse)".Localize(),
                    Margin = theme.ButtonSpacing
                };
                scaleButton.Click += (s, e) => this.ActiveButton = ViewControls3DButtons.Scale;
                buttonGroupA.Add(scaleButton);
                AddChild(scaleButton);

                rotateButton.Checked = true;

                // Add vertical separator
                this.AddChild(new ToolbarSeparator(theme));

                iconPath         = Path.Combine("ViewTransformControls", "partSelect.png");
                partSelectButton = new RadioIconButton(AggContext.StaticData.LoadIcon(iconPath, 32, 32, theme.InvertIcons), theme)
                {
                    SiblingRadioButtonList = buttonGroupA,
                    ToolTipText            = "Select Part".Localize(),
                    Margin = theme.ButtonSpacing
                };
                partSelectButton.Click += (s, e) => this.ActiveButton = ViewControls3DButtons.PartSelect;
                buttonGroupA.Add(partSelectButton);
                AddChild(partSelectButton);
            }

            operationButtons = new Dictionary <GuiWidget, SceneSelectionOperation>();

            // Add Selected IObject3D -> Operations to toolbar
            foreach (var namedAction in ApplicationController.Instance.RegisteredSceneOperations)
            {
                if (namedAction is SceneSelectionSeparator)
                {
                    this.AddChild(new ToolbarSeparator(theme));
                    continue;
                }

                // add the create support before the align
                if (namedAction is OperationGroup group &&
                    group.GroupName == "Align")
                {
                    this.AddChild(CreateWipeTowerButton(theme));
                    this.AddChild(CreateSupportButton(theme));
                    this.AddChild(new ToolbarSeparator(theme));
                }

                GuiWidget button = null;

                if (namedAction is OperationGroup operationGroup)
                {
                    if (operationGroup.Collapse)
                    {
                        var defaultOperation = operationGroup.GetDefaultOperation();

                        PopupMenuButton groupButton = null;

                        groupButton = theme.CreateSplitButton(
                            new SplitButtonParams()
                        {
                            Icon          = defaultOperation.Icon(theme.InvertIcons),
                            DefaultAction = (menuButton) =>
                            {
                                defaultOperation.Action.Invoke(sceneContext);
                            },
                            DefaultActionTooltip = defaultOperation.HelpText ?? defaultOperation.Title,
                            ButtonName           = defaultOperation.Title,
                            ExtendPopupMenu      = (PopupMenu popupMenu) =>
                            {
                                foreach (var operation in operationGroup.Operations)
                                {
                                    var operationMenu = popupMenu.CreateMenuItem(operation.Title, operation.Icon?.Invoke(theme.InvertIcons));

                                    operationMenu.ToolTipText = operation.HelpText;
                                    operationMenu.Enabled     = operation.IsEnabled(sceneContext);
                                    operationMenu.Click      += (s, e) => UiThread.RunOnIdle(() =>
                                    {
                                        if (operationGroup.StickySelection &&
                                            defaultOperation != operation)
                                        {
                                            // Update button
                                            var iconButton = groupButton.Children.OfType <IconButton>().First();
                                            iconButton.SetIcon(operation.Icon(theme.InvertIcons));
                                            iconButton.ToolTipText = operation.HelpText ?? operation.Title;

                                            UserSettings.Instance.set(operationGroup.GroupRecordId, operationGroup.Operations.IndexOf(operation).ToString());

                                            defaultOperation = operation;

                                            iconButton.Invalidate();
                                        }

                                        operation.Action?.Invoke(sceneContext);
                                    });
                                }
                            }
                        },
                            operationGroup);

                        button = groupButton;
                    }
                    else
                    {
                        if (!(this.ActionArea.Children.LastOrDefault() is ToolbarSeparator))
                        {
                            this.AddChild(new ToolbarSeparator(theme));
                        }

                        foreach (var operation in operationGroup.Operations)
                        {
                            var operationButton = new OperationIconButton(operation, sceneContext, theme);
                            operationButtons.Add(operationButton, operation);

                            this.AddChild(operationButton);
                        }

                        this.AddChild(new ToolbarSeparator(theme));
                    }
                }
                else if (namedAction.Icon != null)
                {
                    button = new IconButton(namedAction.Icon(theme.InvertIcons), theme)
                    {
                        Name            = namedAction.Title + " Button",
                        ToolTipText     = namedAction.Title,
                        Margin          = theme.ButtonSpacing,
                        BackgroundColor = theme.ToolbarButtonBackground,
                        HoverColor      = theme.ToolbarButtonHover,
                        MouseDownColor  = theme.ToolbarButtonDown,
                    };
                }
                else
                {
                    button = new TextButton(namedAction.Title, theme)
                    {
                        Name            = namedAction.Title + " Button",
                        Margin          = theme.ButtonSpacing,
                        BackgroundColor = theme.ToolbarButtonBackground,
                        HoverColor      = theme.ToolbarButtonHover,
                        MouseDownColor  = theme.ToolbarButtonDown,
                    };
                }

                if (button != null)
                {
                    operationButtons.Add(button, namedAction);

                    // Only bind Click event if not a SplitButton
                    if (!(button is PopupMenuButton))
                    {
                        button.Click += (s, e) => UiThread.RunOnIdle(() =>
                        {
                            namedAction.Action.Invoke(sceneContext);
                            var partTab = button.Parents <PartTabPage>().FirstOrDefault();
                            var view3D  = partTab.Descendants <View3DWidget>().FirstOrDefault();
                            view3D.InteractionLayer.Focus();
                        });
                    }

                    this.AddChild(button);
                }
            }

            // Register listeners
            undoBuffer.Changed += UndoBuffer_Changed;
            sceneContext.Scene.SelectionChanged += UpdateToolbarButtons;
            sceneContext.Scene.ItemsModified    += UpdateToolbarButtons;

            // Run on load
            UpdateToolbarButtons(null, null);
        }
Beispiel #9
0
        private GuiWidget ShowViewOptions()
        {
            var popupMenu = new PopupMenu(ApplicationController.Instance.MenuTheme);

            var siblingList = new List <GuiWidget>();

            popupMenu.CreateBoolMenuItem(
                "Shaded".Localize(),
                viewIcons[RenderTypes.Shaded],
                () => sceneContext.ViewState.RenderType == RenderTypes.Shaded,
                (isChecked) =>
            {
                sceneContext.ViewState.RenderType = RenderTypes.Shaded;
            },
                useRadioStyle: true,
                siblingRadioButtonList: siblingList);

            popupMenu.CreateBoolMenuItem(
                "Outlines".Localize(),
                viewIcons[RenderTypes.Outlines],
                () => sceneContext.ViewState.RenderType == RenderTypes.Outlines,
                (isChecked) =>
            {
                sceneContext.ViewState.RenderType = RenderTypes.Outlines;
            },
                useRadioStyle: true,
                siblingRadioButtonList: siblingList);

#if DEBUG
            popupMenu.CreateBoolMenuItem(
                "Non-Manifold".Localize(),
                viewIcons[RenderTypes.Polygons],
                () => sceneContext.ViewState.RenderType == RenderTypes.NonManifold,
                (isChecked) =>
            {
                sceneContext.ViewState.RenderType = RenderTypes.NonManifold;
            },
                useRadioStyle: true,
                siblingRadioButtonList: siblingList);
#endif

            popupMenu.CreateBoolMenuItem(
                "Polygons".Localize(),
                viewIcons[RenderTypes.Polygons],
                () => sceneContext.ViewState.RenderType == RenderTypes.Polygons,
                (isChecked) =>
            {
                sceneContext.ViewState.RenderType = RenderTypes.Polygons;
            },
                useRadioStyle: true,
                siblingRadioButtonList: siblingList);

            popupMenu.CreateBoolMenuItem(
                "Materials".Localize(),
                viewIcons[RenderTypes.Materials],
                () => sceneContext.ViewState.RenderType == RenderTypes.Materials,
                (isChecked) =>
            {
                sceneContext.ViewState.RenderType = RenderTypes.Materials;
            },
                useRadioStyle: true,
                siblingRadioButtonList: siblingList);

            popupMenu.CreateBoolMenuItem(
                "Overhang".Localize(),
                viewIcons[RenderTypes.Overhang],
                () => sceneContext.ViewState.RenderType == RenderTypes.Overhang,
                (isChecked) =>
            {
                sceneContext.ViewState.RenderType = RenderTypes.Overhang;
            },
                useRadioStyle: true,
                siblingRadioButtonList: siblingList);

            // Override menu left padding to improve radio circle -> icon spacing
            foreach (var menuItem in popupMenu.Children)
            {
                menuItem.Padding = menuItem.Padding.Clone(left: 25);
            }

            return(popupMenu);
        }
Beispiel #10
0
        private void GeneratePrinterOverflowMenu(PopupMenu popupMenu, ThemeConfig theme)
        {
            var menuActions = new List <NamedAction>()
            {
                new NamedAction()
                {
                    Icon      = AggContext.StaticData.LoadIcon("memory_16x16.png", 16, 16, theme.InvertIcons),
                    Title     = "Configure EEProm".Localize(),
                    Action    = configureEePromButton_Click,
                    IsEnabled = () => printer.Connection.IsConnected
                },
                new NamedBoolAction()
                {
                    Title       = "Show Controls".Localize(),
                    Action      = () => { },
                    GetIsActive = () => printer.ViewState.ControlsVisible,
                    SetIsActive = (value) => printer.ViewState.ControlsVisible = value
                },
                new NamedBoolAction()
                {
                    Title       = "Show Terminal".Localize(),
                    Action      = () => { },
                    GetIsActive = () => printer.ViewState.TerminalVisible,
                    SetIsActive = (value) => printer.ViewState.TerminalVisible = value
                },
                new NamedBoolAction()
                {
                    Title       = "Configure Printer".Localize(),
                    Action      = () => { },
                    GetIsActive = () => printer.ViewState.ConfigurePrinterVisible,
                    SetIsActive = (value) => printer.ViewState.ConfigurePrinterVisible = value
                },
                new ActionSeparator(),
                new NamedAction()
                {
                    Title  = "Import Presets".Localize(),
                    Action = () =>
                    {
                        AggContext.FileDialogs.OpenFileDialog(
                            new OpenFileDialogParams("settings files|*.printer"),
                            (dialogParams) =>
                        {
                            if (!string.IsNullOrEmpty(dialogParams.FileName))
                            {
                                DialogWindow.Show(new ImportSettingsPage(dialogParams.FileName, printer));
                            }
                        });
                    }
                },
                new NamedAction()
                {
                    Title  = "Export All Settings".Localize(),
                    Action = () =>
                    {
                        printer.Settings.Helpers.ExportAsMatterControlConfig();
                    }
                },
                new ActionSeparator(),
                new NamedAction()
                {
                    Title  = "Restore Settings".Localize(),
                    Action = () =>
                    {
                        DialogWindow.Show <PrinterProfileHistoryPage>();
                    }
                },
                new NamedAction()
                {
                    Title  = "Reset to Defaults".Localize(),
                    Action = () =>
                    {
                        StyledMessageBox.ShowMessageBox(
                            (revertSettings) =>
                        {
                            if (revertSettings)
                            {
                                bool onlyReloadSliceSettings = true;
                                if (printer.Settings.GetValue <bool>(SettingsKey.print_leveling_required_to_print) &&
                                    printer.Settings.GetValue <bool>(SettingsKey.print_leveling_enabled))
                                {
                                    onlyReloadSliceSettings = false;
                                }

                                printer.Settings.ClearUserOverrides();
                                printer.Settings.Save();

                                if (onlyReloadSliceSettings)
                                {
                                    printer?.Bed.GCodeRenderer?.Clear3DGCode();
                                }
                                else
                                {
                                    ApplicationController.Instance.ReloadAll();
                                }
                            }
                        },
                            "Resetting to default values will remove your current overrides and restore your original printer settings.\nAre you sure you want to continue?".Localize(),
                            "Revert Settings".Localize(),
                            StyledMessageBox.MessageType.YES_NO);
                    }
                },
                new ActionSeparator(),
                new NamedAction()
                {
                    Title  = "Delete Printer".Localize(),
                    Action = () =>
                    {
                        StyledMessageBox.ShowMessageBox(
                            (doDelete) =>
                        {
                            if (doDelete)
                            {
                                ProfileManager.Instance.DeleteActivePrinter(true);
                            }
                        },
                            "Are you sure you want to delete your currently selected printer?".Localize(),
                            "Delete Printer?".Localize(),
                            StyledMessageBox.MessageType.YES_NO,
                            "Delete Printer".Localize());
                    }
                }
            };

            theme.CreateMenuItems(popupMenu, menuActions);
        }