private void LoadColumnTwo()
        {
            ColumnTwo.CloseAllChildren();

            PartPreviewContent partViewContent = new PartPreviewContent(PrinterConnectionAndCommunication.Instance.ActivePrintItem, View3DWidget.WindowMode.Embeded, View3DWidget.AutoRotate.Enabled);

            partViewContent.AnchorAll();

            ColumnTwo.AddChild(partViewContent);

            ColumnTwo.AnchorAll();
        }
        private void RebuildUi()
        {
            var tempList = new List <EePromRepetierParameter>();

            lock (currentEePromSettings.eePromSettingsList)
            {
                foreach (var keyValue in currentEePromSettings.eePromSettingsList)
                {
                    tempList.Add(keyValue.Value);
                }
            }

            settingsColumn.CloseAllChildren();

            foreach (EePromRepetierParameter newSetting in tempList)
            {
                if (newSetting != null)
                {
                    var row = new FlowLayoutWidget
                    {
                        HAnchor = HAnchor.MaxFitOrStretch,
                        Padding = new BorderDouble(5, 0)
                    };
                    row.AddChild(AddDescription(newSetting.Description));

                    if ((settingsColumn.Children.Count % 2) == 1)
                    {
                        row.BackgroundColor = new Color(0, 0, 0, 30);
                    }

                    CreateSpacer(row);

                    double.TryParse(newSetting.Value, out double currentValue);
                    var valueEdit = new MHNumberEdit(currentValue, theme, pixelWidth: 80 * GuiWidget.DeviceScale, allowNegatives: true, allowDecimals: true)
                    {
                        SelectAllOnFocus = true,
                        TabIndex         = currentTabIndex++,
                        VAnchor          = VAnchor.Center
                    };
                    valueEdit.ActuallNumberEdit.EditComplete += (s, e) =>
                    {
                        newSetting.Value = valueEdit.ActuallNumberEdit.Value.ToString();
                    };
                    row.AddChild(valueEdit);

                    settingsColumn.AddChild(row);
                }
            }
            waitingForUiUpdate = false;
        }
Exemple #3
0
        private void RebuildUi()
        {
            List <EePromRepetierParameter> tempList = new List <EePromRepetierParameter>();

            lock (currentEePromSettings.eePromSettingsList)
            {
                foreach (KeyValuePair <int, EePromRepetierParameter> keyValue in currentEePromSettings.eePromSettingsList)
                {
                    tempList.Add(keyValue.Value);
                }
            }

            settingsColmun.CloseAllChildren();

            foreach (EePromRepetierParameter newSetting in tempList)
            {
                if (newSetting != null)
                {
                    FlowLayoutWidget row = new FlowLayoutWidget();
                    row.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth;
                    row.AddChild(AddDescription(newSetting.Description));
                    row.Padding = new BorderDouble(5, 0);
                    if ((settingsColmun.Children.Count % 2) == 1)
                    {
                        row.BackgroundColor = new RGBA_Bytes(0, 0, 0, 30);
                    }

                    CreateSpacer(row);

                    double currentValue;
                    double.TryParse(newSetting.Value, out currentValue);
                    MHNumberEdit valueEdit = new MHNumberEdit(currentValue, pixelWidth: 80 * GuiWidget.DeviceScale, allowNegatives: true, allowDecimals: true);
                    valueEdit.SelectAllOnFocus = true;
                    valueEdit.TabIndex         = currentTabIndex++;
                    valueEdit.VAnchor          = Agg.UI.VAnchor.ParentCenter;
                    valueEdit.ActuallNumberEdit.EditComplete += (sender, e) =>
                    {
                        newSetting.Value = valueEdit.ActuallNumberEdit.Value.ToString();
                    };
                    row.AddChild(valueEdit);

                    settingsColmun.AddChild(row);
                }
            }
            waitingForUiUpdate = false;
        }
Exemple #4
0
        public ExportPrintItemPage(IEnumerable <ILibraryItem> libraryItems, bool centerOnBed, PrinterConfig printer)
        {
            this.WindowTitle = "Export File".Localize();
            this.HeaderText  = "Export selection to".Localize() + ":";
            this.Name        = "Export Item Window";

            var commonMargin = new BorderDouble(4, 2);

            bool isFirstItem = true;

            // Must be constructed before plugins are initialized
            var exportButton = theme.CreateDialogButton("Export".Localize());

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

            // GCode export
            exportPluginButtons = new Dictionary <RadioButton, IExportPlugin>();

            foreach (IExportPlugin plugin in PluginFinder.CreateInstancesOf <IExportPlugin>().OrderBy(p => p.ButtonText))
            {
                plugin.Initialize(printer);

                // Skip plugins which are invalid for the current printer
                if (!plugin.Enabled)
                {
                    if (!string.IsNullOrEmpty(plugin.DisabledReason))
                    {
                        // add a message to let us know why not enabled
                        var disabledPluginButton = new RadioButton(new RadioImageWidget(plugin.ButtonText, theme.TextColor, plugin.Icon))
                        {
                            HAnchor = HAnchor.Left,
                            Margin  = commonMargin,
                            Cursor  = Cursors.Hand,
                            Name    = plugin.ButtonText + " Button",
                            Enabled = false
                        };
                        contentRow.AddChild(disabledPluginButton);
                        contentRow.AddChild(new TextWidget("Disabled: {0}".Localize().FormatWith(plugin.DisabledReason), textColor: theme.PrimaryAccentColor)
                        {
                            Margin  = new BorderDouble(left: 80),
                            HAnchor = HAnchor.Left
                        });
                    }
                    continue;
                }

                // Create export button for each plugin
                var pluginButton = new RadioButton(new RadioImageWidget(plugin.ButtonText, theme.TextColor, plugin.Icon))
                {
                    HAnchor = HAnchor.Left,
                    Margin  = commonMargin,
                    Cursor  = Cursors.Hand,
                    Name    = plugin.ButtonText + " Button"
                };
                contentRow.AddChild(pluginButton);

                if (plugin is GCodeExport)
                {
                    var gcodeExportButton = pluginButton;
                    gcodeExportButton.CheckedStateChanged += (s, e) =>
                    {
                        validationPanel.CloseAllChildren();

                        if (gcodeExportButton.Checked)
                        {
                            var errors = printer.ValidateSettings(validatePrintBed: false);

                            exportButton.Enabled = !errors.Any(item => item.ErrorLevel == ValidationErrorLevel.Error);

                            validationPanel.AddChild(
                                new ValidationErrorsPanel(
                                    errors,
                                    AppContext.Theme)
                            {
                                HAnchor = HAnchor.Stretch
                            });
                        }
                        else
                        {
                            exportButton.Enabled = true;
                        }
                    };
                }

                if (isFirstItem)
                {
                    pluginButton.Checked = true;
                    isFirstItem          = false;
                }

                if (plugin is IExportWithOptions pluginWithOptions)
                {
                    var optionPanel = pluginWithOptions.GetOptionsPanel();
                    if (optionPanel != null)
                    {
                        optionPanel.HAnchor = HAnchor.Stretch;
                        optionPanel.VAnchor = VAnchor.Fit;
                        contentRow.AddChild(optionPanel);
                    }
                }

                exportPluginButtons.Add(pluginButton, plugin);
            }

            ContentRow.AddChild(new VerticalSpacer());
            contentRow.AddChild(validationPanel);

            // TODO: make this work on the mac and then delete this if
            if (AggContext.OperatingSystem == OSType.Windows ||
                AggContext.OperatingSystem == OSType.X11)
            {
                showInFolderAfterSave = new CheckBox("Show file in folder after save".Localize(), theme.TextColor, 10)
                {
                    HAnchor = HAnchor.Left,
                    Cursor  = Cursors.Hand
                };
                contentRow.AddChild(showInFolderAfterSave);
            }

            exportButton.Name   = "Export Button";
            exportButton.Click += (s, e) =>
            {
                IExportPlugin activePlugin = null;

                // Loop over all plugin buttons, break on the first checked item found
                foreach (var button in this.exportPluginButtons.Keys)
                {
                    if (button.Checked)
                    {
                        activePlugin = exportPluginButtons[button];
                        break;
                    }
                }

                // Early exit if no plugin radio button is selected
                if (activePlugin == null)
                {
                    return;
                }

                DoExport(libraryItems, printer, activePlugin, centerOnBed, showInFolderAfterSave.Checked);

                this.Parent.CloseOnIdle();
            };


            this.AddPageAction(exportButton);
        }
Exemple #5
0
        public GCodeOptionsPanel(BedConfig sceneContext, PrinterConfig printer, ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            gcodeOptions = sceneContext.RendererOptions;

            var buttonPanel = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.Fit,
                VAnchor = VAnchor.Fit
            };

            var buttonGroup = new ObservableCollection <GuiWidget>();

            speedsButton = new RadioIconButton(AggContext.StaticData.LoadIcon("speeds.png", theme.InvertIcons), theme)
            {
                SiblingRadioButtonList = buttonGroup,
                Name        = "Speeds Button",
                Checked     = gcodeOptions.GCodeLineColorStyle == "Speeds",
                ToolTipText = "Show Speeds".Localize(),
                Margin      = theme.ButtonSpacing
            };
            speedsButton.Click += SwitchColorModes_Click;
            buttonGroup.Add(speedsButton);

            buttonPanel.AddChild(speedsButton);

            materialsButton = new RadioIconButton(AggContext.StaticData.LoadIcon("materials.png", theme.InvertIcons), theme)
            {
                SiblingRadioButtonList = buttonGroup,
                Name        = "Materials Button",
                Checked     = gcodeOptions.GCodeLineColorStyle == "Materials",
                ToolTipText = "Show Materials".Localize(),
                Margin      = theme.ButtonSpacing
            };
            materialsButton.Click += SwitchColorModes_Click;
            buttonGroup.Add(materialsButton);

            buttonPanel.AddChild(materialsButton);

            noColorButton = new RadioIconButton(AggContext.StaticData.LoadIcon("no-color.png", theme.InvertIcons), theme)
            {
                SiblingRadioButtonList = buttonGroup,
                Name        = "No Color Button",
                Checked     = gcodeOptions.GCodeLineColorStyle == "None",
                ToolTipText = "No Color".Localize(),
                Margin      = theme.ButtonSpacing
            };
            noColorButton.Click += SwitchColorModes_Click;
            buttonGroup.Add(noColorButton);

            buttonPanel.AddChild(noColorButton);

            this.AddChild(
                new SettingsItem(
                    "Color View".Localize(),
                    theme,
                    optionalControls: buttonPanel,
                    enforceGutter: false));

            buttonPanel = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.Fit,
                VAnchor = VAnchor.Fit
            };

            // Reset to new button group
            buttonGroup = new ObservableCollection <GuiWidget>();

            solidButton = new RadioIconButton(AggContext.StaticData.LoadIcon("solid.png", theme.InvertIcons), theme)
            {
                SiblingRadioButtonList = buttonGroup,
                Name        = "Solid Button",
                Checked     = gcodeOptions.GCodeModelView == "Semi-Transparent",
                ToolTipText = "Show Semi-Transparent Model".Localize(),
                Margin      = theme.ButtonSpacing
            };
            solidButton.Click += SwitchModelModes_Click;
            buttonGroup.Add(solidButton);

            buttonPanel.AddChild(solidButton);

            materialsButton = new RadioIconButton(AggContext.StaticData.LoadIcon("wireframe.png", theme.InvertIcons), theme)
            {
                SiblingRadioButtonList = buttonGroup,
                Name        = "Wireframe Button",
                Checked     = gcodeOptions.GCodeModelView == "Wireframe",
                ToolTipText = "Show Wireframe Model".Localize(),
                Margin      = theme.ButtonSpacing
            };
            materialsButton.Click += SwitchModelModes_Click;
            buttonGroup.Add(materialsButton);

            buttonPanel.AddChild(materialsButton);

            noColorButton = new RadioIconButton(AggContext.StaticData.LoadIcon("no-color.png", theme.InvertIcons), theme)
            {
                SiblingRadioButtonList = buttonGroup,
                Name        = "No Model Button",
                Checked     = gcodeOptions.GCodeModelView == "None",
                ToolTipText = "No Model".Localize(),
                Margin      = theme.ButtonSpacing
            };
            noColorButton.Click += SwitchModelModes_Click;
            buttonGroup.Add(noColorButton);

            buttonPanel.AddChild(noColorButton);

            this.AddChild(
                new SettingsItem(
                    "Model View".Localize(),
                    buttonPanel,
                    theme,
                    enforceGutter: false));

            gcodeOptions = sceneContext.RendererOptions;

            var viewOptions = sceneContext.GetBaseViewOptions();

            viewOptions.AddRange(new[]
            {
                new BoolOption(
                    "Moves".Localize(),
                    () => gcodeOptions.RenderMoves,
                    (value) => gcodeOptions.RenderMoves = value),
                new BoolOption(
                    "Retractions".Localize(),
                    () => gcodeOptions.RenderRetractions,
                    (value) => gcodeOptions.RenderRetractions = value),
                new BoolOption(
                    "Extrusion".Localize(),
                    () => gcodeOptions.SimulateExtrusion,
                    (value) => gcodeOptions.SimulateExtrusion = value),
                new BoolOption(
                    "Transparent".Localize(),
                    () => gcodeOptions.TransparentExtrusion,
                    (value) => gcodeOptions.TransparentExtrusion = value),
                new BoolOption(
                    "Hide Offsets".Localize(),
                    () => gcodeOptions.HideExtruderOffsets,
                    (value) => gcodeOptions.HideExtruderOffsets = value,
                    () => printer.Settings.GetValue <int>(SettingsKey.extruder_count) > 1),
                new BoolOption(
                    "Sync To Print".Localize(),
                    () => gcodeOptions.SyncToPrint,
                    (value) =>
                {
                    gcodeOptions.SyncToPrint = value;
                    if (!gcodeOptions.SyncToPrint)
                    {
                        // If we are turning off sync to print, set the slider to full.
                        //layerRenderRatioSlider.SecondValue = 1;
                    }
                })
            });

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

            this.AddChild(optionsContainer);

            void BuildMenu()
            {
                foreach (var option in viewOptions.Where(option => option.IsVisible()))
                {
                    var settingsItem = new SettingsItem(
                        option.Title,
                        theme,
                        new SettingsItem.ToggleSwitchConfig()
                    {
                        Name         = option.Title + " Toggle",
                        Checked      = option.IsChecked(),
                        ToggleAction = option.SetValue
                    },
                        enforceGutter: false);

                    settingsItem.Padding = settingsItem.Padding.Clone(right: 8);

                    optionsContainer.AddChild(settingsItem);
                }
            }

            BuildMenu();

            PropertyChangedEventHandler syncProperties = (s, e) =>
            {
                if (e.PropertyName == nameof(gcodeOptions.RenderBed) ||
                    e.PropertyName == nameof(gcodeOptions.RenderBuildVolume))
                {
                    optionsContainer.CloseAllChildren();
                    BuildMenu();
                }
            };

            gcodeOptions.PropertyChanged += syncProperties;

            optionsContainer.Closed += (s, e) =>
            {
                gcodeOptions.PropertyChanged -= syncProperties;
            };
        }
Exemple #6
0
        public ExportPrintItemPage(IEnumerable <ILibraryItem> libraryItems, bool centerOnBed, PrinterConfig printer)
        {
            this.centerOnBed = centerOnBed;
            this.WindowTitle = "Export File".Localize();
            this.HeaderText  = "Export selection to".Localize() + ":";

            this.libraryItems = libraryItems;
            this.Name         = "Export Item Window";

            var commonMargin = new BorderDouble(4, 2);

            bool isFirstItem = true;

            // Must be constructed before plugins are initialized
            var exportButton = theme.CreateDialogButton("Export".Localize());

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

            // GCode export
            exportPluginButtons = new Dictionary <RadioButton, IExportPlugin>();

            foreach (IExportPlugin plugin in PluginFinder.CreateInstancesOf <IExportPlugin>().OrderBy(p => p.ButtonText))
            {
                plugin.Initialize(printer);

                // Skip plugins which are invalid for the current printer
                if (!plugin.Enabled)
                {
                    if (!string.IsNullOrEmpty(plugin.DisabledReason))
                    {
                        // add a message to let us know why not enabled
                        var disabledPluginButton = new RadioButton(new RadioImageWidget(plugin.ButtonText, theme.TextColor, plugin.Icon))
                        {
                            HAnchor = HAnchor.Left,
                            Margin  = commonMargin,
                            Cursor  = Cursors.Hand,
                            Name    = plugin.ButtonText + " Button",
                            Enabled = false
                        };
                        contentRow.AddChild(disabledPluginButton);
                        contentRow.AddChild(new TextWidget("Disabled: {0}".Localize().FormatWith(plugin.DisabledReason), textColor: theme.PrimaryAccentColor)
                        {
                            Margin  = new BorderDouble(left: 80),
                            HAnchor = HAnchor.Left
                        });
                    }
                    continue;
                }

                // Create export button for each plugin
                var pluginButton = new RadioButton(new RadioImageWidget(plugin.ButtonText, theme.TextColor, plugin.Icon))
                {
                    HAnchor = HAnchor.Left,
                    Margin  = commonMargin,
                    Cursor  = Cursors.Hand,
                    Name    = plugin.ButtonText + " Button"
                };
                contentRow.AddChild(pluginButton);

                if (plugin is GCodeExport)
                {
                    var gcodeExportButton = pluginButton;
                    gcodeExportButton.CheckedStateChanged += (s, e) =>
                    {
                        validationPanel.CloseAllChildren();

                        if (gcodeExportButton.Checked)
                        {
                            var errors = printer.ValidateSettings();

                            exportButton.Enabled = !errors.Any(item => item.ErrorLevel == ValidationErrorLevel.Error);

                            validationPanel.AddChild(
                                new ValidationErrorsPanel(
                                    errors,
                                    AppContext.Theme)
                            {
                                HAnchor = HAnchor.Stretch
                            });
                        }
                        else
                        {
                            exportButton.Enabled = true;
                        }
                    };
                }

                if (isFirstItem)
                {
                    pluginButton.Checked = true;
                    isFirstItem          = false;
                }

                if (plugin is IExportWithOptions pluginWithOptions)
                {
                    var optionPanel = pluginWithOptions.GetOptionsPanel();
                    if (optionPanel != null)
                    {
                        optionPanel.HAnchor = HAnchor.Stretch;
                        optionPanel.VAnchor = VAnchor.Fit;
                        contentRow.AddChild(optionPanel);
                    }
                }


                exportPluginButtons.Add(pluginButton, plugin);
            }

            ContentRow.AddChild(new VerticalSpacer());
            contentRow.AddChild(validationPanel);

            // TODO: make this work on the mac and then delete this if
            if (AggContext.OperatingSystem == OSType.Windows ||
                AggContext.OperatingSystem == OSType.X11)
            {
                showInFolderAfterSave = new CheckBox("Show file in folder after save".Localize(), theme.TextColor, 10)
                {
                    HAnchor = HAnchor.Left,
                    Cursor  = Cursors.Hand
                };
                contentRow.AddChild(showInFolderAfterSave);
            }

            exportButton.Name   = "Export Button";
            exportButton.Click += (s, e) =>
            {
                string fileTypeFilter  = "";
                string targetExtension = "";

                IExportPlugin activePlugin = null;

                // Loop over all plugin buttons, break on the first checked item found
                foreach (var button in this.exportPluginButtons.Keys)
                {
                    if (button.Checked)
                    {
                        activePlugin = exportPluginButtons[button];
                        break;
                    }
                }

                // Early exit if no plugin radio button is selected
                if (activePlugin == null)
                {
                    return;
                }

                fileTypeFilter  = activePlugin.ExtensionFilter;
                targetExtension = activePlugin.FileExtension;

                this.Parent.CloseOnIdle();

                if (activePlugin is FolderExport)
                {
                    UiThread.RunOnIdle(() =>
                    {
                        AggContext.FileDialogs.SelectFolderDialog(
                            new SelectFolderDialogParams("Select Location To Export Files")
                        {
                            ActionButtonLabel = "Export".Localize(),
                            Title             = ApplicationController.Instance.ProductName + " - " + "Select A Folder".Localize()
                        },
                            (openParams) =>
                        {
                            ApplicationController.Instance.Tasks.Execute(
                                "Saving".Localize() + "...",
                                printer,
                                async(reporter, cancellationToken) =>
                            {
                                string path = openParams.FolderPath;
                                if (!string.IsNullOrEmpty(path))
                                {
                                    await activePlugin.Generate(libraryItems, path, reporter, cancellationToken);
                                }
                            });
                        });
                    });

                    return;
                }

                UiThread.RunOnIdle(() =>
                {
                    string title         = ApplicationController.Instance.ProductName + " - " + "Export File".Localize();
                    string workspaceName = "Workspace " + DateTime.Now.ToString("yyyy-MM-dd HH_mm_ss");
                    AggContext.FileDialogs.SaveFileDialog(
                        new SaveFileDialogParams(fileTypeFilter)
                    {
                        Title             = title,
                        ActionButtonLabel = "Export".Localize(),
                        FileName          = Path.GetFileNameWithoutExtension(libraryItems.FirstOrDefault()?.Name ?? workspaceName)
                    },
                        (saveParams) =>
                    {
                        string savePath = saveParams.FileName;

                        if (!string.IsNullOrEmpty(savePath))
                        {
                            ApplicationController.Instance.Tasks.Execute(
                                "Exporting".Localize() + "...",
                                printer,
                                async(reporter, cancellationToken) =>
                            {
                                string extension = Path.GetExtension(savePath);
                                if (extension != targetExtension)
                                {
                                    savePath += targetExtension;
                                }

                                List <ValidationError> exportErrors = null;

                                if (activePlugin != null)
                                {
                                    if (activePlugin is GCodeExport gCodeExport)
                                    {
                                        gCodeExport.CenterOnBed = centerOnBed;
                                    }

                                    exportErrors = await activePlugin.Generate(libraryItems, savePath, reporter, cancellationToken);
                                }

                                if (exportErrors == null || exportErrors.Count == 0)
                                {
                                    ShowFileIfRequested(savePath);
                                }
                                else
                                {
                                    bool showGenerateErrors = !(activePlugin is GCodeExport);

                                    // Only show errors in Generate if not GCodeExport - GCodeExport shows validation errors before Generate call
                                    if (showGenerateErrors)
                                    {
                                        ApplicationController.Instance.ShowValidationErrors("Export Error".Localize(), exportErrors);
                                    }
                                }
                            });
                        }
                    });
                });
            };

            this.AddPageAction(exportButton);
        }