public static bool ShowMessageBox(string message, string caption, GuiWidget[] extraWidgetsToAdd, MessageType messageType, string yesOk = "", string no = "")
 {
     StyledMessageBox messageBox = new StyledMessageBox(message, caption, messageType, extraWidgetsToAdd, 400, 300, yesOk, no);
     bool okClicked = false;
     messageBox.ClickedOk += (sender, e) => { okClicked = true; };
     messageBox.ShowAsSystemWindow();
     return okClicked;
 }
 public static bool ShowMessageBox(string message, string caption, GuiWidget[] extraWidgetsToAdd, MessageType messageType)
 {
     string wrappedMessage = TypeFacePrinter.InsertCRs(message, 300, 12);
     StyledMessageBox messageBox = new StyledMessageBox(wrappedMessage, caption, messageType, extraWidgetsToAdd, 400, 300);
     bool okClicked = false;
     messageBox.ClickedOk += (sender, e) => { okClicked = true; };
     messageBox.ShowAsSystemWindow();
     return okClicked;
 }
 public static bool ShowMessageBox(String message, string caption, MessageType messageType = MessageType.OK)
 {
     string wrappedMessage = TypeFacePrinter.InsertCRs(message, 350, 12);
     StyledMessageBox messageBox = new StyledMessageBox(wrappedMessage, caption, messageType, null, 400, 300);
     bool okClicked = false;
     messageBox.ClickedOk += (sender, e) => { okClicked = true; };
     messageBox.ShowAsSystemWindow();
     return okClicked;
 }
예제 #4
0
 private void displayFailedToImportMessage(string settingsFilePath)
 {
     StyledMessageBox.ShowMessageBox(null, "Oops! Settings file '{0}' did not contain any settings we could import.".Localize().FormatWith(Path.GetFileName(settingsFilePath)), "Unable to Import".Localize());
 }
예제 #5
0
        private void ImportToPreset(string settingsFilePath)
        {
            if (!string.IsNullOrEmpty(settingsFilePath) && File.Exists(settingsFilePath))
            {
                PrinterSettingsLayer newLayer;

                string sectionName = (newMaterialPresetButton.Checked) ? "Material".Localize() : "Quality".Localize();

                string importType = Path.GetExtension(settingsFilePath).ToLower();
                switch (importType)
                {
                case ProfileManager.ProfileExtension:
                    newLayer = new PrinterSettingsLayer();
                    newLayer[SettingsKey.layer_name] = Path.GetFileNameWithoutExtension(settingsFilePath);

                    if (newQualityPresetButton.Checked)
                    {
                        ActiveSliceSettings.Instance.QualityLayers.Add(newLayer);
                    }
                    else
                    {
                        // newMaterialPresetButton.Checked
                        ActiveSliceSettings.Instance.MaterialLayers.Add(newLayer);
                    }

                    // open a wizard to ask what to import to the preset
                    WizardWindow.ChangeToPage(new SelectPartsOfPrinterToImport(settingsFilePath, newLayer, sectionName));

                    break;

                case ".slice":                         // legacy presets file extension
                case ".ini":
                    var settingsToImport = PrinterSettingsLayer.LoadFromIni(settingsFilePath);

                    bool containsValidSetting = false;
                    {
                        newLayer      = new PrinterSettingsLayer();
                        newLayer.Name = Path.GetFileNameWithoutExtension(settingsFilePath);

                        // Only be the base and oem layers (not the user, quality or material layer)
                        var baseAndOEMCascade = new List <PrinterSettingsLayer>
                        {
                            ActiveSliceSettings.Instance.OemLayer,
                            ActiveSliceSettings.Instance.BaseLayer
                        };

                        foreach (var keyName in PrinterSettings.KnownSettings)
                        {
                            if (ActiveSliceSettings.Instance.Contains(keyName))
                            {
                                containsValidSetting = true;
                                string currentValue = ActiveSliceSettings.Instance.GetValue(keyName, baseAndOEMCascade).Trim();
                                string newValue;
                                // Compare the value to import to the layer cascade value and only set if different
                                if (settingsToImport.TryGetValue(keyName, out newValue) &&
                                    currentValue != newValue)
                                {
                                    newLayer[keyName] = newValue;
                                }
                            }
                        }

                        if (containsValidSetting)
                        {
                            if (newMaterialPresetButton.Checked)
                            {
                                ActiveSliceSettings.Instance.MaterialLayers.Add(newLayer);
                            }
                            else
                            {
                                ActiveSliceSettings.Instance.QualityLayers.Add(newLayer);
                            }

                            ActiveSliceSettings.Instance.Save();

                            WizardWindow.ChangeToPage(new ImportSucceeded(importSettingSuccessMessage.FormatWith(Path.GetFileNameWithoutExtension(settingsFilePath), sectionName))
                            {
                                WizardWindow = this.WizardWindow,
                            });
                        }
                        else
                        {
                            displayFailedToImportMessage(settingsFilePath);
                        }
                    }

                    break;

                default:
                    // Did not figure out what this file is, let the user know we don't understand it
                    StyledMessageBox.ShowMessageBox(null, "Oops! Unable to recognize settings file '{0}'.".Localize().FormatWith(Path.GetFileName(settingsFilePath)), "Unable to Import".Localize());
                    break;
                }
            }
            Invalidate();
        }
        private void AddGeneralPannel(GuiWidget settingsColumn)
        {
            var generalPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit,
            };

            var configureIcon = StaticData.Instance.LoadIcon("fa-cog_16.png", 16, 16).SetToColor(theme.TextColor);

            var generalSection = new SectionWidget("General".Localize(), generalPanel, theme, expandingContent: false)
            {
                Name    = "General Section",
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit,
            };

            settingsColumn.AddChild(generalSection);

            theme.ApplyBoxStyle(generalSection);

#if __ANDROID__
            // Camera Monitoring
            bool hasCamera = true || ApplicationSettings.Instance.get(ApplicationSettingsKey.HardwareHasCamera) == "true";

            var previewButton = new IconButton(configureIcon, theme)
            {
                ToolTipText = "Preview".Localize()
            };
            previewButton.Click += (s, e) =>
            {
                AppContext.Platform.OpenCameraPreview();
            };

            var printer = ApplicationController.Instance.ActivePrinters.FirstOrDefault();

            // TODO: Sort out how handle this better on Android and in a multi-printer setup
            if (printer != null)
            {
                this.AddSettingsRow(
                    new SettingsItem(
                        "Camera Monitoring".Localize(),
                        theme,
                        new SettingsItem.ToggleSwitchConfig()
                {
                    Checked      = printer.Settings.GetValue <bool>(SettingsKey.publish_bed_image),
                    ToggleAction = (itemChecked) =>
                    {
                        printer.Settings.SetValue(SettingsKey.publish_bed_image, itemChecked ? "1" : "0");
                    }
                },
                        previewButton,
                        StaticData.Instance.LoadIcon("camera-24x24.png", 24, 24))
                {
                    Enabled = printer.Settings.PrinterSelected
                },
                    generalPanel
                    );
            }
#endif
            // Print Notifications
            var configureNotificationsButton = new IconButton(configureIcon, theme)
            {
                Name        = "Configure Notification Settings Button",
                ToolTipText = "Configure Notifications".Localize(),
                Margin      = new BorderDouble(left: 6),
                VAnchor     = VAnchor.Center
            };
            configureNotificationsButton.Click += (s, e) =>
            {
                if (ApplicationController.ChangeToPrintNotification != null)
                {
                    UiThread.RunOnIdle(() =>
                    {
                        ApplicationController.ChangeToPrintNotification(this.DialogWindow);
                    });
                }
            };

            this.AddSettingsRow(
                new SettingsItem(
                    "Notifications".Localize(),
                    theme,
                    new SettingsItem.ToggleSwitchConfig()
            {
                Checked      = UserSettings.Instance.get(UserSettingsKey.PrintNotificationsEnabled) == "true",
                ToggleAction = (itemChecked) =>
                {
                    UserSettings.Instance.set(UserSettingsKey.PrintNotificationsEnabled, itemChecked ? "true" : "false");
                }
            },
                    configureNotificationsButton,
                    StaticData.Instance.LoadIcon("notify-24x24.png", 16, 16).SetToColor(theme.TextColor)),
                generalPanel);

            // LanguageControl
            var languageSelector = new LanguageSelector(theme);
            languageSelector.SelectionChanged += (s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    string languageCode = languageSelector.SelectedValue;
                    if (languageCode != UserSettings.Instance.get(UserSettingsKey.Language))
                    {
                        UserSettings.Instance.set(UserSettingsKey.Language, languageCode);

                        if (languageCode == "L10N")
                        {
#if DEBUG
                            AppContext.Platform.GenerateLocalizationValidationFile();
#endif
                        }

                        ApplicationController.Instance.ResetTranslationMap();
                        ApplicationController.Instance.ReloadAll().ConfigureAwait(false);
                    }
                });
            };

            this.AddSettingsRow(new SettingsItem("Language".Localize(), languageSelector, theme), generalPanel);

#if !__ANDROID__
            // ThumbnailRendering
            var thumbnailsModeDropList = new MHDropDownList("", theme, maxHeight: 200 * GuiWidget.DeviceScale);
            thumbnailsModeDropList.AddItem("Flat".Localize(), "orthographic");
            thumbnailsModeDropList.AddItem("3D".Localize(), "raytraced");

            thumbnailsModeDropList.SelectedValue     = UserSettings.Instance.ThumbnailRenderingMode;
            thumbnailsModeDropList.SelectionChanged += (s, e) =>
            {
                string thumbnailRenderingMode = thumbnailsModeDropList.SelectedValue;
                if (thumbnailRenderingMode != UserSettings.Instance.ThumbnailRenderingMode)
                {
                    UserSettings.Instance.ThumbnailRenderingMode = thumbnailRenderingMode;

                    UiThread.RunOnIdle(() =>
                    {
                        // Ask if the user they would like to rebuild their thumbnails
                        StyledMessageBox.ShowMessageBox(
                            (bool rebuildThumbnails) =>
                        {
                            if (rebuildThumbnails)
                            {
                                string[] thumbnails = new string[]
                                {
                                    ApplicationController.CacheablePath(
                                        Path.Combine("Thumbnails", "Content"), ""),
                                    ApplicationController.CacheablePath(
                                        Path.Combine("Thumbnails", "Library"), "")
                                };
                                foreach (var directoryToRemove in thumbnails)
                                {
                                    try
                                    {
                                        if (Directory.Exists(directoryToRemove))
                                        {
                                            Directory.Delete(directoryToRemove, true);
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        GuiWidget.BreakInDebugger();
                                    }

                                    Directory.CreateDirectory(directoryToRemove);
                                }

                                ApplicationController.Instance.Library.NotifyContainerChanged();
                            }
                        },
                            "You are switching to a different thumbnail rendering mode. If you want, your current thumbnails can be removed and recreated in the new style. You can switch back and forth at any time. There will be some processing overhead while the new thumbnails are created.\n\nDo you want to rebuild your existing thumbnails now?".Localize(),
                            "Rebuild Thumbnails Now".Localize(),
                            StyledMessageBox.MessageType.YES_NO,
                            "Rebuild".Localize());
                    });
                }
            };

            this.AddSettingsRow(
                new SettingsItem(
                    "Thumbnails".Localize(),
                    thumbnailsModeDropList,
                    theme),
                generalPanel);
#endif

            // TextSize
            if (!double.TryParse(UserSettings.Instance.get(UserSettingsKey.ApplicationTextSize), out double currentTextSize))
            {
                currentTextSize = 1.0;
            }

            double sliderThumbWidth = 10 * GuiWidget.DeviceScale;
            double sliderWidth      = 100 * GuiWidget.DeviceScale;
            var    textSizeSlider   = new SolidSlider(default(Vector2), sliderThumbWidth, theme, .7, 2.5)
            {
                Name               = "Text Size Slider",
                Margin             = new BorderDouble(5, 0),
                Value              = currentTextSize,
                HAnchor            = HAnchor.Stretch,
                VAnchor            = VAnchor.Center,
                TotalWidthInPixels = sliderWidth,
            };
            theme.ApplySliderStyle(textSizeSlider);

            var optionalContainer = new FlowLayoutWidget()
            {
                VAnchor = VAnchor.Center | VAnchor.Fit,
                HAnchor = HAnchor.Fit
            };

            TextWidget sectionLabel = null;

            var textSizeApplyButton = new TextButton("Apply".Localize(), theme)
            {
                VAnchor         = VAnchor.Center,
                BackgroundColor = theme.SlightShade,
                Visible         = false,
                Margin          = new BorderDouble(right: 6)
            };
            textSizeApplyButton.Click += (s, e) => UiThread.RunOnIdle(() =>
            {
                GuiWidget.DeviceScale = textSizeSlider.Value;
                ApplicationController.Instance.ReloadAll().ConfigureAwait(false);
            });
            optionalContainer.AddChild(textSizeApplyButton);

            textSizeSlider.ValueChanged += (s, e) =>
            {
                double textSizeNew = textSizeSlider.Value;
                UserSettings.Instance.set(UserSettingsKey.ApplicationTextSize, textSizeNew.ToString("0.0"));
                sectionLabel.Text           = "Text Size".Localize() + $" : {textSizeNew:0.0}";
                textSizeApplyButton.Visible = textSizeNew != currentTextSize;
            };

            var textSizeRow = new SettingsItem(
                "Text Size".Localize() + $" : {currentTextSize:0.0}",
                textSizeSlider,
                theme,
                optionalContainer);

            sectionLabel = textSizeRow.Children <TextWidget>().FirstOrDefault();

            this.AddSettingsRow(textSizeRow, generalPanel);

            var themeSection = CreateThemePanel(theme);
            settingsColumn.AddChild(themeSection);
            theme.ApplyBoxStyle(themeSection);
        }
예제 #7
0
        public ApplicationSettingsPage()
        {
            this.AlwaysOnTopOfMain = true;
            this.WindowTitle       = this.HeaderText = "MatterControl " + "Settings".Localize();
            this.WindowSize        = new Vector2(700 * GuiWidget.DeviceScale, 600 * GuiWidget.DeviceScale);

            contentRow.Padding = contentRow.Padding.Clone(top: 0);

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

            contentRow.AddChild(generalPanel);

            var configureIcon = AggContext.StaticData.LoadIcon("fa-cog_16.png", 16, 16, theme.InvertIcons);

#if __ANDROID__
            // Camera Monitoring
            bool hasCamera = true || ApplicationSettings.Instance.get(ApplicationSettingsKey.HardwareHasCamera) == "true";

            var previewButton = new IconButton(configureIcon, theme)
            {
                ToolTipText = "Configure Camera View".Localize()
            };
            previewButton.Click += (s, e) =>
            {
                AppContext.Platform.OpenCameraPreview();
            };

            var printer = ApplicationController.Instance.ActivePrinter;

            this.AddSettingsRow(
                new SettingsItem(
                    "Camera Monitoring".Localize(),
                    theme,
                    new SettingsItem.ToggleSwitchConfig()
            {
                Checked      = printer.Settings.GetValue <bool>(SettingsKey.publish_bed_image),
                ToggleAction = (itemChecked) =>
                {
                    printer.Settings.SetValue(SettingsKey.publish_bed_image, itemChecked ? "1" : "0");
                }
            },
                    previewButton,
                    AggContext.StaticData.LoadIcon("camera-24x24.png", 24, 24)),
                generalPanel
                );
#endif
            // Print Notifications
            var configureNotificationsButton = new IconButton(configureIcon, theme)
            {
                Name        = "Configure Notification Settings Button",
                ToolTipText = "Configure Notifications".Localize(),
                Margin      = new BorderDouble(left: 6),
                VAnchor     = VAnchor.Center
            };
            configureNotificationsButton.Click += (s, e) =>
            {
                if (ApplicationController.ChangeToPrintNotification != null)
                {
                    UiThread.RunOnIdle(() =>
                    {
                        ApplicationController.ChangeToPrintNotification(this.DialogWindow);
                    });
                }
            };

            this.AddSettingsRow(
                new SettingsItem(
                    "Notifications".Localize(),
                    theme,
                    new SettingsItem.ToggleSwitchConfig()
            {
                Checked      = UserSettings.Instance.get(UserSettingsKey.PrintNotificationsEnabled) == "true",
                ToggleAction = (itemChecked) =>
                {
                    UserSettings.Instance.set(UserSettingsKey.PrintNotificationsEnabled, itemChecked ? "true" : "false");
                }
            },
                    configureNotificationsButton,
                    AggContext.StaticData.LoadIcon("notify-24x24.png", 16, 16, theme.InvertIcons)),
                generalPanel);

            // LanguageControl
            var languageSelector = new LanguageSelector(theme);
            languageSelector.SelectionChanged += (s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    string languageCode = languageSelector.SelectedValue;
                    if (languageCode != UserSettings.Instance.get(UserSettingsKey.Language))
                    {
                        UserSettings.Instance.set(UserSettingsKey.Language, languageCode);

                        if (languageCode == "L10N")
                        {
#if DEBUG
                            AppContext.Platform.GenerateLocalizationValidationFile();
#endif
                        }

                        ApplicationController.Instance.ResetTranslationMap();
                        ApplicationController.Instance.ReloadAll();
                    }
                });
            };

            this.AddSettingsRow(new SettingsItem("Language".Localize(), languageSelector, theme), generalPanel);

#if !__ANDROID__
            // ThumbnailRendering
            var thumbnailsModeDropList = new DropDownList("", theme.Colors.PrimaryTextColor, maxHeight: 200, pointSize: theme.DefaultFontSize)
            {
                BorderColor = theme.GetBorderColor(75)
            };
            thumbnailsModeDropList.AddItem("Flat".Localize(), "orthographic");
            thumbnailsModeDropList.AddItem("3D".Localize(), "raytraced");

            thumbnailsModeDropList.SelectedValue     = UserSettings.Instance.ThumbnailRenderingMode;
            thumbnailsModeDropList.SelectionChanged += (s, e) =>
            {
                string thumbnailRenderingMode = thumbnailsModeDropList.SelectedValue;
                if (thumbnailRenderingMode != UserSettings.Instance.ThumbnailRenderingMode)
                {
                    UserSettings.Instance.ThumbnailRenderingMode = thumbnailRenderingMode;

                    UiThread.RunOnIdle(() =>
                    {
                        // Ask if the user they would like to rebuild their thumbnails
                        StyledMessageBox.ShowMessageBox(
                            (bool rebuildThumbnails) =>
                        {
                            if (rebuildThumbnails)
                            {
                                string[] thumbnails = new string[]
                                {
                                    ApplicationController.CacheablePath(
                                        Path.Combine("Thumbnails", "Content"), ""),
                                    ApplicationController.CacheablePath(
                                        Path.Combine("Thumbnails", "Library"), "")
                                };
                                foreach (var directoryToRemove in thumbnails)
                                {
                                    try
                                    {
                                        if (Directory.Exists(directoryToRemove))
                                        {
                                            Directory.Delete(directoryToRemove, true);
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        GuiWidget.BreakInDebugger();
                                    }

                                    Directory.CreateDirectory(directoryToRemove);
                                }

                                ApplicationController.Instance.Library.NotifyContainerChanged();
                            }
                        },
                            "You are switching to a different thumbnail rendering mode. If you want, your current thumbnails can be removed and recreated in the new style. You can switch back and forth at any time. There will be some processing overhead while the new thumbnails are created.\n\nDo you want to rebuild your existing thumbnails now?".Localize(),
                            "Rebuild Thumbnails Now".Localize(),
                            StyledMessageBox.MessageType.YES_NO,
                            "Rebuild".Localize());
                    });
                }
            };

            this.AddSettingsRow(
                new SettingsItem(
                    "Thumbnails".Localize(),
                    thumbnailsModeDropList,
                    theme),
                generalPanel);
#endif

            // TextSize
            if (!double.TryParse(UserSettings.Instance.get(UserSettingsKey.ApplicationTextSize), out double currentTextSize))
            {
                currentTextSize = 1.0;
            }

            double sliderThumbWidth = 10 * GuiWidget.DeviceScale;
            double sliderWidth      = 100 * GuiWidget.DeviceScale;
            var    textSizeSlider   = new SolidSlider(new Vector2(), sliderThumbWidth, .7, 1.4)
            {
                Name               = "Text Size Slider",
                Margin             = new BorderDouble(5, 0),
                Value              = currentTextSize,
                HAnchor            = HAnchor.Stretch,
                VAnchor            = VAnchor.Center,
                TotalWidthInPixels = sliderWidth,
            };

            var optionalContainer = new FlowLayoutWidget()
            {
                VAnchor = VAnchor.Center | VAnchor.Fit,
                HAnchor = HAnchor.Fit
            };

            TextWidget sectionLabel = null;

            var textSizeApplyButton = new TextButton("Apply".Localize(), theme)
            {
                VAnchor         = VAnchor.Center,
                BackgroundColor = theme.SlightShade,
                Visible         = false,
                Margin          = new BorderDouble(right: 6)
            };
            textSizeApplyButton.Click += (s, e) =>
            {
                GuiWidget.DeviceScale = textSizeSlider.Value;
                ApplicationController.Instance.ReloadAll();
            };
            optionalContainer.AddChild(textSizeApplyButton);

            textSizeSlider.ValueChanged += (s, e) =>
            {
                double textSizeNew = textSizeSlider.Value;
                UserSettings.Instance.set(UserSettingsKey.ApplicationTextSize, textSizeNew.ToString("0.0"));
                sectionLabel.Text           = "Text Size".Localize() + $" : {textSizeNew:0.0}";
                textSizeApplyButton.Visible = textSizeNew != currentTextSize;
            };

            var section = new SettingsItem(
                "Text Size".Localize() + $" : {currentTextSize:0.0}",
                textSizeSlider,
                theme,
                optionalContainer);

            sectionLabel = section.Children <TextWidget>().FirstOrDefault();

            this.AddSettingsRow(section, generalPanel);

            themeColorPanel = new ThemeColorPanel(theme)
            {
                HAnchor = HAnchor.Stretch
            };

            var droplist = new DropDownList("Custom", theme.Colors.PrimaryTextColor, maxHeight: 200, pointSize: theme.DefaultFontSize)
            {
                BorderColor = theme.GetBorderColor(75),
                Margin      = new BorderDouble(0, 0, 10, 0)
            };

            int i = 0;

            foreach (var item in AppContext.ThemeProviders)
            {
                var newItem = droplist.AddItem(item.Key);

                if (item.Value == themeColorPanel.ThemeProvider)
                {
                    droplist.SelectedIndex = i;
                }

                i++;
            }

            droplist.SelectionChanged += (s, e) =>
            {
                if (AppContext.ThemeProviders.TryGetValue(droplist.SelectedValue, out IColorTheme provider))
                {
                    themeColorPanel.ThemeProvider = provider;
                    UserSettings.Instance.set(UserSettingsKey.ThemeName, droplist.SelectedValue);
                }
            };

            var themeRow = new SettingsItem("Theme".Localize(), droplist, theme);
            generalPanel.AddChild(themeRow);
            generalPanel.AddChild(themeColorPanel);

            themeColorPanel.Border      = themeRow.Border;
            themeColorPanel.BorderColor = themeRow.BorderColor;
            themeRow.Border             = 0;

            var advancedPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                Margin = new BorderDouble(2, 0)
            };

            var sectionWidget = new SectionWidget("Advanced".Localize(), advancedPanel, theme, serializationKey: "ApplicationSettings-Advanced", expanded: false)
            {
                Name    = "Advanced Section",
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit,
                Margin  = 0
            };
            contentRow.AddChild(sectionWidget);

            theme.ApplyBoxStyle(sectionWidget);

            sectionWidget.Margin = new BorderDouble(0, 10);

            // Touch Screen Mode
            this.AddSettingsRow(
                new SettingsItem(
                    "Touch Screen Mode".Localize(),
                    theme,
                    new SettingsItem.ToggleSwitchConfig()
            {
                Checked      = UserSettings.Instance.get(UserSettingsKey.ApplicationDisplayMode) == "touchscreen",
                ToggleAction = (itemChecked) =>
                {
                    string displayMode = itemChecked ? "touchscreen" : "responsive";
                    if (displayMode != UserSettings.Instance.get(UserSettingsKey.ApplicationDisplayMode))
                    {
                        UserSettings.Instance.set(UserSettingsKey.ApplicationDisplayMode, displayMode);
                        ApplicationController.Instance.ReloadAll();
                    }
                }
            }),
                advancedPanel);

            var openCacheButton = new IconButton(AggContext.StaticData.LoadIcon("fa-link_16.png", 16, 16, theme.InvertIcons), theme)
            {
                ToolTipText = "Open Folder".Localize(),
            };
            openCacheButton.Click += (s, e) => UiThread.RunOnIdle(() =>
            {
                Process.Start(ApplicationDataStorage.ApplicationUserDataPath);
            });

            this.AddSettingsRow(
                new SettingsItem(
                    "Application Storage".Localize(),
                    openCacheButton,
                    theme),
                advancedPanel);

            var clearCacheButton = new HoverIconButton(AggContext.StaticData.LoadIcon("remove.png", 16, 16, theme.InvertIcons), theme)
            {
                ToolTipText = "Clear Cache".Localize(),
            };
            clearCacheButton.Click += (s, e) => UiThread.RunOnIdle(() =>
            {
                CacheDirectory.DeleteCacheData();
            });

            this.AddSettingsRow(
                new SettingsItem(
                    "Application Cache".Localize(),
                    clearCacheButton,
                    theme),
                advancedPanel);

            advancedPanel.Children <SettingsItem>().First().Border = new BorderDouble(0, 1);
        }
예제 #8
0
        public override void OnClosing(ClosingEventArgs eventArgs)
        {
            if (this.HasBeenClosed)
            {
                return;
            }

            // save the last size of the window so we can restore it next time.
            ApplicationSettings.Instance.set(ApplicationSettingsKey.MainWindowMaximized, this.Maximized.ToString().ToLower());

            if (!this.Maximized)
            {
                ApplicationSettings.Instance.set(ApplicationSettingsKey.WindowSize, string.Format("{0},{1}", Width, Height));
                ApplicationSettings.Instance.set(ApplicationSettingsKey.DesktopPosition, string.Format("{0},{1}", DesktopPosition.x, DesktopPosition.y));
            }

            // Save a snapshot of the prints in queue
            QueueData.Instance.SaveDefaultQueue();

            // If we are waiting for a response and get another request, just cancel the close until we get a response.
            if (exitDialogOpen)
            {
                eventArgs.Cancel = true;
            }

            string caption = null;
            string message = null;

            if (!ApplicationController.Instance.ApplicationExiting &&
                !exitDialogOpen)
            {
                int printingCount = 0;
                int sdPrinting    = 0;
                foreach (var printer in ApplicationController.Instance.ActivePrinters)
                {
                    if (printer.Connection.Printing)
                    {
                        if (printer.Connection.CommunicationState == CommunicationStates.PrintingFromSd)
                        {
                            sdPrinting++;
                        }

                        printingCount++;
                    }
                }

                if (sdPrinting > 0)
                {
                    caption = "Exit while printing".Localize();
                    message = "Are you sure you want to exit while a print is running from SD Card?\n\nNote: If you exit, it is recommended you wait until the print is completed before running MatterControl again.".Localize();
                }
                else if (printingCount > 0)
                {
                    caption = "Abort Print".Localize();
                    message = "Are you sure you want to abort the current print and close MatterControl?".Localize();
                }
            }

            if (caption != null)
            {
                // Record that we are waiting for a response to the request to close
                exitDialogOpen = true;

                // We need to show an interactive dialog to determine if the original Close request should be honored, thus cancel the current Close request
                eventArgs.Cancel = true;

                UiThread.RunOnIdle(() =>
                {
                    StyledMessageBox.ShowMessageBox(
                        (exitConfirmed) =>
                    {
                        // Record that the exitDialog has closed
                        exitDialogOpen = false;

                        // Continue with the original shutdown request if exit confirmed by user
                        if (exitConfirmed)
                        {
                            ApplicationController.Instance.ApplicationExiting = true;
                            ApplicationController.Instance.Shutdown();

                            foreach (var printer in ApplicationController.Instance.ActivePrinters)
                            {
                                // the will shutdown any active (and non-sd) prints that are running
                                printer.Connection.Disable();
                            }

                            this.CloseOnIdle();
                        }
                    },
                        message,
                        caption,
                        StyledMessageBox.MessageType.YES_NO_WITHOUT_HIGHLIGHT);
                });
            }
            else if (!ApplicationController.Instance.ApplicationExiting)
            {
                // cancel the close so that we can save all our active work spaces
                eventArgs.Cancel = true;

                UiThread.RunOnIdle(async() =>
                {
                    var application = ApplicationController.Instance;

                    await application.PersistUserTabs();

                    application.ApplicationExiting = true;

                    // Make sure we tell the Application Controller to shut down. This will release the slicing thread if running.
                    application.Shutdown();

                    this.CloseOnIdle();
                });
            }
        }
		public static void ShowMessageBox(MessageBoxDelegate callback, string message, string caption, GuiWidget[] extraWidgetsToAdd, MessageType messageType, string yesOk = "", string no = "")
		{
			StyledMessageBox messageBox = new StyledMessageBox(callback, message, caption, messageType, extraWidgetsToAdd, 400, 300, yesOk, no);
			messageBox.ShowAsSystemWindow();
		}
예제 #10
0
        public static void ShowMessageBox(MessageBoxDelegate callback, string message, string caption, GuiWidget[] extraWidgetsToAdd, MessageType messageType, string yesOk = "", string no = "")
        {
            StyledMessageBox messageBox = new StyledMessageBox(callback, message, caption, messageType, extraWidgetsToAdd, 400, 300, yesOk, no);

            messageBox.ShowAsSystemWindow();
        }
예제 #11
0
        public void CreateWindowContent()
        {
            this.RemoveAllChildren();
            TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory();
            FlowLayoutWidget       topToBottom            = new FlowLayoutWidget(FlowDirection.TopToBottom);

            topToBottom.Padding = new BorderDouble(3, 0, 3, 5);
            topToBottom.AnchorAll();

            // Creates Header
            FlowLayoutWidget headerRow = new FlowLayoutWidget(FlowDirection.LeftToRight);

            headerRow.HAnchor = HAnchor.ParentLeftRight;
            headerRow.Margin  = new BorderDouble(0, 3, 0, 0);
            headerRow.Padding = new BorderDouble(0, 3, 0, 3);
            BackgroundColor   = ActiveTheme.Instance.PrimaryBackgroundColor;

            //Creates Text and adds into header
            {
                TextWidget elementHeader = new TextWidget("File export options:".Localize(), pointSize: 14);
                elementHeader.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                elementHeader.HAnchor   = HAnchor.ParentLeftRight;
                elementHeader.VAnchor   = Agg.UI.VAnchor.ParentBottom;

                headerRow.AddChild(elementHeader);
                topToBottom.AddChild(headerRow);
            }

            // Creates container in the middle of window
            FlowLayoutWidget middleRowContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
            {
                middleRowContainer.HAnchor         = HAnchor.ParentLeftRight;
                middleRowContainer.VAnchor         = VAnchor.ParentBottomTop;
                middleRowContainer.Padding         = new BorderDouble(5);
                middleRowContainer.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
            }

            bool modelCanBeExported = !partIsGCode;

            if (modelCanBeExported &&
                printItemWrapper != null &&
                (printItemWrapper.PrintItem.Protected ||
                 printItemWrapper.PrintItem.ReadOnly))
            {
                modelCanBeExported = false;
            }

            if (modelCanBeExported)
            {
                // put in stl export
                string exportStlText     = "Export as".Localize();
                string exportStlTextFull = string.Format("{0} STL", exportStlText);

                Button exportAsStlButton = textImageButtonFactory.Generate(exportStlTextFull);
                exportAsStlButton.Name    = "Export as STL button";
                exportAsStlButton.HAnchor = HAnchor.ParentLeft;
                exportAsStlButton.Cursor  = Cursors.Hand;
                exportAsStlButton.Click  += exportSTL_Click;
                middleRowContainer.AddChild(exportAsStlButton);

                // put in amf export
                string exportAmfText     = "Export as".Localize();
                string exportAmfTextFull = string.Format("{0} AMF", exportAmfText);

                Button exportAsAmfButton = textImageButtonFactory.Generate(exportAmfTextFull);
                exportAsAmfButton.Name    = "Export as AMF button";
                exportAsAmfButton.HAnchor = HAnchor.ParentLeft;
                exportAsAmfButton.Cursor  = Cursors.Hand;
                exportAsAmfButton.Click  += exportAMF_Click;
                middleRowContainer.AddChild(exportAsAmfButton);
            }

            bool showExportGCodeButton = ActiveSliceSettings.Instance.PrinterSelected || partIsGCode;

            if (showExportGCodeButton)
            {
                string exportGCodeTextFull = string.Format("{0} G-Code", "Export as".Localize());
                Button exportGCode         = textImageButtonFactory.Generate(exportGCodeTextFull);
                exportGCode.Name    = "Export as GCode Button";
                exportGCode.HAnchor = HAnchor.ParentLeft;
                exportGCode.Cursor  = Cursors.Hand;
                exportGCode.Click  += (s, e) =>
                {
                    UiThread.RunOnIdle(ExportGCode_Click);
                };
                middleRowContainer.AddChild(exportGCode);

                PluginFinder <ExportGcodePlugin> exportPluginFinder = new PluginFinder <ExportGcodePlugin>();

                foreach (ExportGcodePlugin plugin in exportPluginFinder.Plugins)
                {
                    if (plugin.EnabledForCurrentPart(printItemWrapper))
                    {
                        //Create export button for each Plugin found

                        string exportButtonText = plugin.GetButtonText().Localize();

                        Button exportButton = textImageButtonFactory.Generate(exportButtonText);
                        exportButton.HAnchor = HAnchor.ParentLeft;
                        exportButton.Cursor  = Cursors.Hand;
                        exportButton.Click  += (s, e) =>
                        {
                            UiThread.RunOnIdle(() =>
                            {
                                // Close the export window
                                Close();

                                // Open a SaveFileDialog. If Save is clicked, slice the part if needed and pass the plugin the
                                // path to the gcode file and the target save path
                                FileDialog.SaveFileDialog(
                                    new SaveFileDialogParams(plugin.GetExtensionFilter())
                                {
                                    Title             = "MatterControl: Export File",
                                    FileName          = printItemWrapper.Name,
                                    ActionButtonLabel = "Export"
                                },
                                    (SaveFileDialogParams saveParam) =>
                                {
                                    string extension = Path.GetExtension(saveParam.FileName);
                                    if (extension == "")
                                    {
                                        saveParam.FileName += plugin.GetFileExtension();
                                    }

                                    if (partIsGCode)
                                    {
                                        try
                                        {
                                            plugin.Generate(printItemWrapper.FileLocation, saveParam.FileName);
                                        }
                                        catch (Exception exception)
                                        {
                                            UiThread.RunOnIdle(() =>
                                            {
                                                StyledMessageBox.ShowMessageBox(null, exception.Message, "Couldn't save file".Localize());
                                            });
                                        }
                                    }
                                    else
                                    {
                                        SlicingQueue.Instance.QueuePartForSlicing(printItemWrapper);

                                        printItemWrapper.SlicingDone += (printItem, eventArgs) =>
                                        {
                                            PrintItemWrapper sliceItem = (PrintItemWrapper)printItem;
                                            if (File.Exists(sliceItem.GetGCodePathAndFileName()))
                                            {
                                                try
                                                {
                                                    plugin.Generate(sliceItem.GetGCodePathAndFileName(), saveParam.FileName);
                                                }
                                                catch (Exception exception)
                                                {
                                                    UiThread.RunOnIdle(() =>
                                                    {
                                                        StyledMessageBox.ShowMessageBox(null, exception.Message, "Couldn't save file".Localize());
                                                    });
                                                }
                                            }
                                        };
                                    }
                                });
                            });
                        };                         // End exportButton Click handler

                        middleRowContainer.AddChild(exportButton);
                    }
                }
            }

            middleRowContainer.AddChild(new VerticalSpacer());

            // If print leveling is enabled then add in a check box 'Apply Leveling During Export' and default checked.
            if (showExportGCodeButton && ActiveSliceSettings.Instance.GetValue <bool>(SettingsKey.print_leveling_enabled))
            {
                applyLeveling         = new CheckBox(LocalizedString.Get(applyLevelingDuringExportString), ActiveTheme.Instance.PrimaryTextColor, 10);
                applyLeveling.Checked = true;
                applyLeveling.HAnchor = HAnchor.ParentLeft;
                applyLeveling.Cursor  = Cursors.Hand;
                //applyLeveling.Margin = new BorderDouble(top: 10);
                middleRowContainer.AddChild(applyLeveling);
            }

            // TODO: make this work on the mac and then delete this if
            if (OsInformation.OperatingSystem == OSType.Windows ||
                OsInformation.OperatingSystem == OSType.X11)
            {
                showInFolderAfterSave         = new CheckBox("Show file in folder after save".Localize(), ActiveTheme.Instance.PrimaryTextColor, 10);
                showInFolderAfterSave.HAnchor = HAnchor.ParentLeft;
                showInFolderAfterSave.Cursor  = Cursors.Hand;
                //showInFolderAfterSave.Margin = new BorderDouble(top: 10);
                middleRowContainer.AddChild(showInFolderAfterSave);
            }

            if (!showExportGCodeButton)
            {
                string     noGCodeMessageTextBeg  = "Note".Localize();
                string     noGCodeMessageTextEnd  = "To enable GCode export, select a printer profile.".Localize();
                string     noGCodeMessageTextFull = string.Format("{0}: {1}", noGCodeMessageTextBeg, noGCodeMessageTextEnd);
                TextWidget noGCodeMessage         = new TextWidget(noGCodeMessageTextFull, textColor: ActiveTheme.Instance.PrimaryTextColor, pointSize: 10);
                noGCodeMessage.HAnchor = HAnchor.ParentLeft;
                middleRowContainer.AddChild(noGCodeMessage);
            }

            //Creates button container on the bottom of window
            FlowLayoutWidget buttonRow = new FlowLayoutWidget(FlowDirection.LeftToRight);
            {
                BackgroundColor   = ActiveTheme.Instance.PrimaryBackgroundColor;
                buttonRow.HAnchor = HAnchor.ParentLeftRight;
                buttonRow.Padding = new BorderDouble(0, 3);
            }

            Button cancelButton = textImageButtonFactory.Generate("Cancel".Localize());

            cancelButton.Name   = "Export Item Window Cancel Button";
            cancelButton.Cursor = Cursors.Hand;
            cancelButton.Click += (sender, e) =>
            {
                CloseOnIdle();
            };

            buttonRow.AddChild(new HorizontalSpacer());
            buttonRow.AddChild(cancelButton);
            topToBottom.AddChild(middleRowContainer);
            topToBottom.AddChild(buttonRow);

            this.AddChild(topToBottom);
        }
예제 #12
0
        public ImportSettingsPage(string settingsFilePath, PrinterConfig printer)
        {
            this.WindowTitle = "Import Wizard";
            this.HeaderText  = "Select What to Import".Localize();

            // TODO: Need to handle load failures for import attempts
            var settingsToImport = PrinterSettings.LoadFile(settingsFilePath);

            // if there are no settings to import
            if (settingsToImport.QualityLayers.Count == 0 && settingsToImport.MaterialLayers.Count == 0)
            {
                // Only main setting so don't ask what to merge just do it.
                DisplayFailedToImportMessage(settingsFilePath);
                this.Parents <SystemWindow>().First().Close();
            }

            this.settingsFilePath = settingsFilePath;

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

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

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

            scrollWindow.AddChild(container);

            if (settingsToImport.QualityLayers.Count > 0)
            {
                container.AddChild(new TextWidget("Quality Presets:")
                {
                    TextColor = theme.TextColor,
                    Margin    = new BorderDouble(0, 3),
                });

                int buttonIndex = 0;
                foreach (var qualitySetting in settingsToImport.QualityLayers)
                {
                    var qualityButton = new RadioButton(string.IsNullOrEmpty(qualitySetting.Name) ? "no name" : qualitySetting.Name)
                    {
                        TextColor = theme.TextColor,
                        Margin    = new BorderDouble(5, 0, 0, 0),
                        HAnchor   = HAnchor.Left,
                    };
                    container.AddChild(qualityButton);

                    int localButtonIndex = buttonIndex;
                    qualityButton.CheckedStateChanged += (s, e) =>
                    {
                        if (qualityButton.Checked)
                        {
                            selectedQuality = localButtonIndex;
                        }
                        else
                        {
                            selectedQuality = -1;
                        }
                    };

                    buttonIndex++;
                }
            }

            if (settingsToImport.MaterialLayers.Count > 0)
            {
                container.AddChild(new TextWidget("Material Presets:")
                {
                    TextColor = theme.TextColor,
                    Margin    = new BorderDouble(0, 3, 0, 15),
                });

                int buttonIndex = 0;
                foreach (var materialSetting in settingsToImport.MaterialLayers)
                {
                    var materialButton = new RadioButton(string.IsNullOrEmpty(materialSetting.Name) ? "no name" : materialSetting.Name)
                    {
                        TextColor = theme.TextColor,
                        Margin    = new BorderDouble(5, 0),
                        HAnchor   = HAnchor.Left,
                    };

                    container.AddChild(materialButton);

                    int localButtonIndex = buttonIndex;
                    materialButton.CheckedStateChanged += (s, e) =>
                    {
                        if (materialButton.Checked)
                        {
                            selectedMaterial = localButtonIndex;
                        }
                        else
                        {
                            selectedMaterial = -1;
                        }
                    };

                    buttonIndex++;
                }
            }

            var mergeButton = theme.CreateDialogButton("Import".Localize());

            mergeButton.Name   = "Merge Profile";
            mergeButton.Click += (s, e) => UiThread.RunOnIdle(() =>
            {
                bool copyName = false;
                PrinterSettingsLayer sourceLayer = null;
                bool destIsMaterial = true;
                if (selectedMaterial > -1)
                {
                    sourceLayer = settingsToImport.MaterialLayers[selectedMaterial];
                    copyName    = true;
                }
                else if (selectedQuality > -1)
                {
                    destIsMaterial = false;
                    sourceLayer    = settingsToImport.QualityLayers[selectedQuality];
                    copyName       = true;
                }

                List <PrinterSettingsLayer> sourceFilter;

                if (selectedQuality == -1 && selectedMaterial == -1)
                {
                    sourceFilter = new List <PrinterSettingsLayer>()
                    {
                        settingsToImport.OemLayer,
                        settingsToImport.UserLayer
                    };
                }
                else
                {
                    sourceFilter = new List <PrinterSettingsLayer>()
                    {
                        sourceLayer
                    };
                }

                if (File.Exists(settingsFilePath))
                {
                    if (Path.GetExtension(settingsFilePath).ToLower() == ProfileManager.ProfileExtension)
                    {
                        var printerSettingsLayer = new PrinterSettingsLayer();
                        printer.Settings.Merge(printerSettingsLayer, settingsToImport, sourceFilter, copyName);

                        var layerName = printerSettingsLayer.ContainsKey(SettingsKey.layer_name) ? printerSettingsLayer[SettingsKey.layer_name] : "none";

                        string sectionName = destIsMaterial ? "Material".Localize() : "Quality".Localize();

                        string importSettingSuccessMessage = string.Format("You have successfully imported a new {0} setting. You can find '{1}' in your list of {0} settings.".Localize(), sectionName, layerName);

                        DialogWindow.ChangeToPage(
                            new ImportSucceededPage(importSettingSuccessMessage)
                        {
                            DialogWindow = this.DialogWindow,
                        });

                        if (destIsMaterial)
                        {
                            printer.Settings.MaterialLayers.Add(printerSettingsLayer);
                            var newMaterial = printer.Settings.MaterialLayers[printer.Settings.MaterialLayers.Count - 1];
                            printer.Settings.SetValue(SettingsKey.active_material_key, newMaterial.LayerID);
                        }
                        else
                        {
                            printer.Settings.QualityLayers.Add(printerSettingsLayer);
                            var newQuality = printer.Settings.QualityLayers[printer.Settings.QualityLayers.Count - 1];
                            printer.Settings.SetValue(SettingsKey.active_quality_key, newQuality.LayerID);
                        }
                    }
                    else
                    {
                        // Inform of unexpected extension type
                        StyledMessageBox.ShowMessageBox(
                            "Oops! Unable to recognize settings file '{0}'.".Localize().FormatWith(Path.GetFileName(settingsFilePath)),
                            "Unable to Import".Localize());
                    }
                }
            });

            this.AddPageAction(mergeButton);
        }
예제 #13
0
        public TerminalWidget(PrinterConfig printer, ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            this.printer = printer;
            this.Name    = "TerminalWidget";
            this.Padding = new BorderDouble(5, 0);

            // Header
            var headerRow = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                HAnchor = HAnchor.Left | HAnchor.Stretch,
                Padding = new BorderDouble(0, 8)
            };

            this.AddChild(headerRow);

            headerRow.AddChild(CreateVisibilityOptions(theme));

            autoUppercase = new CheckBox("Auto Uppercase".Localize(), textSize: theme.DefaultFontSize)
            {
                Margin    = new BorderDouble(left: 25),
                Checked   = UserSettings.Instance.Fields.GetBool(UserSettingsKey.TerminalAutoUppercase, true),
                TextColor = theme.TextColor,
                VAnchor   = VAnchor.Center
            };
            autoUppercase.CheckedStateChanged += (s, e) =>
            {
                UserSettings.Instance.Fields.SetBool(UserSettingsKey.TerminalAutoUppercase, autoUppercase.Checked);
            };
            headerRow.AddChild(autoUppercase);

            // Body
            var bodyRow = new FlowLayoutWidget()
            {
                Margin  = new BorderDouble(bottom: 4),
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            };

            this.AddChild(bodyRow);

            textScrollWidget = new TextScrollWidget(printer, printer.TerminalLog.PrinterLines)
            {
                BackgroundColor = theme.MinimalShade,
                TextColor       = theme.TextColor,
                HAnchor         = HAnchor.Stretch,
                VAnchor         = VAnchor.Stretch,
                Margin          = 0,
                Padding         = new BorderDouble(3, 0)
            };
            bodyRow.AddChild(textScrollWidget);
            bodyRow.AddChild(new TextScrollBar(textScrollWidget, 15)
            {
                ThumbColor      = theme.AccentMimimalOverlay,
                BackgroundColor = theme.SlightShade,
                Margin          = 0
            });

            textScrollWidget.LineFilterFunction = lineData =>
            {
                var line       = lineData.Line;
                var output     = lineData.Direction == TerminalLine.MessageDirection.ToPrinter;
                var outputLine = line;

                var lineWithoutChecksum = GCodeFile.GetLineWithoutChecksum(line);

                // and set this as the output if desired
                if (output &&
                    !UserSettings.Instance.Fields.GetBool(UserSettingsKey.TerminalShowChecksum, true))
                {
                    outputLine = lineWithoutChecksum;
                }

                if (!output &&
                    lineWithoutChecksum == "ok" &&
                    !UserSettings.Instance.Fields.GetBool(UserSettingsKey.TerminalShowOks, true))
                {
                    return(null);
                }
                else if (output &&
                         lineWithoutChecksum.StartsWith("M105") &&
                         !UserSettings.Instance.Fields.GetBool(UserSettingsKey.TerminalShowTempRequests, true))
                {
                    return(null);
                }
                else if (output &&
                         (lineWithoutChecksum.StartsWith("G0 ") || lineWithoutChecksum.StartsWith("G1 ")) &&
                         !UserSettings.Instance.Fields.GetBool(UserSettingsKey.TerminalShowMovementRequests, true))
                {
                    return(null);
                }
                else if (!output &&
                         (lineWithoutChecksum.StartsWith("T") || lineWithoutChecksum.StartsWith("ok T")) &&
                         !UserSettings.Instance.Fields.GetBool(UserSettingsKey.TerminalShowTempResponse, true))
                {
                    return(null);
                }
                else if (!output &&
                         lineWithoutChecksum == "wait" &&
                         !UserSettings.Instance.Fields.GetBool(UserSettingsKey.TerminalShowWaitResponse, false))
                {
                    return(null);
                }

                if (UserSettings.Instance.Fields.GetBool(UserSettingsKey.TerminalShowInputOutputMarks, true))
                {
                    switch (lineData.Direction)
                    {
                    case TerminalLine.MessageDirection.FromPrinter:
                        outputLine = "→ " + outputLine;
                        break;

                    case TerminalLine.MessageDirection.ToPrinter:
                        outputLine = "← " + outputLine;
                        break;

                    case TerminalLine.MessageDirection.ToTerminal:
                        outputLine = "* " + outputLine;
                        break;
                    }
                }

                return(outputLine);
            };

            // Input Row
            var inputRow = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                BackgroundColor = this.BackgroundColor,
                HAnchor         = HAnchor.Stretch,
                Margin          = new BorderDouble(bottom: 2)
            };

            this.AddChild(inputRow);

            manualCommandTextEdit = new MHTextEditWidget("", theme, typeFace: ApplicationController.GetTypeFace(NamedTypeFace.Liberation_Mono))
            {
                Margin  = new BorderDouble(right: 3),
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Bottom
            };
            manualCommandTextEdit.ActualTextEditWidget.EnterPressed += (s, e) =>
            {
                SendManualCommand();
            };
            manualCommandTextEdit.ActualTextEditWidget.KeyDown += (s, keyEvent) =>
            {
                bool changeToHistory = false;
                if (keyEvent.KeyCode == Keys.Up)
                {
                    commandHistoryIndex--;
                    if (commandHistoryIndex < 0)
                    {
                        commandHistoryIndex = 0;
                    }
                    changeToHistory = true;
                }
                else if (keyEvent.KeyCode == Keys.Down)
                {
                    commandHistoryIndex++;
                    if (commandHistoryIndex > commandHistory.Count - 1)
                    {
                        commandHistoryIndex = commandHistory.Count - 1;
                    }
                    else
                    {
                        changeToHistory = true;
                    }
                }
                else if (keyEvent.KeyCode == Keys.Escape)
                {
                    manualCommandTextEdit.Text = "";
                }

                if (changeToHistory && commandHistory.Count > 0)
                {
                    manualCommandTextEdit.Text = commandHistory[commandHistoryIndex];
                }
            };
            inputRow.AddChild(manualCommandTextEdit);

            // Footer
            var toolbarPadding = theme.ToolbarPadding;
            var footerRow      = new FlowLayoutWidget
            {
                HAnchor = HAnchor.Stretch,
                Padding = new BorderDouble(0, toolbarPadding.Bottom, toolbarPadding.Right, toolbarPadding.Top)
            };

            this.AddChild(footerRow);

            var sendButton = theme.CreateDialogButton("Send".Localize());

            sendButton.Margin = theme.ButtonSpacing;
            sendButton.Click += (s, e) =>
            {
                SendManualCommand();
            };
            footerRow.AddChild(sendButton);

            var clearButton = theme.CreateDialogButton("Clear".Localize());

            clearButton.Margin = theme.ButtonSpacing;
            clearButton.Click += (s, e) =>
            {
                printer.TerminalLog.Clear();
            };
            footerRow.AddChild(clearButton);

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

            exportButton.Margin = theme.ButtonSpacing;
            exportButton.Click += (s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    AggContext.FileDialogs.SaveFileDialog(
                        new SaveFileDialogParams("Save as Text|*.txt")
                    {
                        Title             = "MatterControl: Terminal Log",
                        ActionButtonLabel = "Export",
                        FileName          = "print_log.txt"
                    },
                        (saveParams) =>
                    {
                        if (!string.IsNullOrEmpty(saveParams.FileName))
                        {
                            string filePathToSave = saveParams.FileName;

                            if (filePathToSave != null && filePathToSave != "")
                            {
                                try
                                {
                                    textScrollWidget.WriteToFile(filePathToSave);
                                }
                                catch (UnauthorizedAccessException ex)
                                {
                                    Debug.Print(ex.Message);

                                    ApplicationController.Instance.LogError("");
                                    ApplicationController.Instance.LogError("WARNING: Write Failed!".Localize());
                                    ApplicationController.Instance.LogError("Can't access".Localize() + " " + filePathToSave);
                                    ApplicationController.Instance.LogError("");

                                    UiThread.RunOnIdle(() =>
                                    {
                                        StyledMessageBox.ShowMessageBox(ex.Message, "Couldn't save file".Localize());
                                    });
                                }
                            }
                        }
                    });
                });
            };
            footerRow.AddChild(exportButton);

            footerRow.AddChild(new HorizontalSpacer());

            this.AnchorAll();
        }
        public ExportPrintItemPage(IEnumerable <ILibraryItem> libraryItems)
        {
            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;

            // TODO: Someday export operations need to resolve printer context interactively
            var printer = ApplicationController.Instance.ActivePrinter;

            // 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)
                {
                    continue;
                }

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

                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());

            // 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(), ActiveTheme.Instance.PrimaryTextColor, 10)
                {
                    HAnchor = HAnchor.Left,
                    Cursor  = Cursors.Hand
                };
                contentRow.AddChild(showInFolderAfterSave);
            }

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

            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() + "...",
                                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() + "...",
                                async(reporter, cancellationToken) =>
                            {
                                string extension = Path.GetExtension(savePath);
                                if (extension != targetExtension)
                                {
                                    savePath += targetExtension;
                                }

                                bool succeeded = false;

                                if (activePlugin != null)
                                {
                                    succeeded = await activePlugin.Generate(libraryItems, savePath, reporter, cancellationToken);
                                }

                                if (succeeded)
                                {
                                    ShowFileIfRequested(savePath);
                                }
                                else
                                {
                                    UiThread.RunOnIdle(() =>
                                    {
                                        StyledMessageBox.ShowMessageBox("Export failed".Localize(), title);
                                    });
                                }
                            });
                        }
                    });
                });
            };

            this.AddPageAction(exportButton);
        }
예제 #15
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) =>
            {
                string printerID = this.SelectedValue;
                if (printerID == "new" ||
                    string.IsNullOrEmpty(printerID) ||
                    printerID == ActiveSliceSettings.Instance.ID)
                {
                    // do nothing
                }
                else
                {
                    // TODO: when this opens a new tab we will not need to check any printer
                    if (ApplicationController.Instance.ActivePrinter.Connection.PrinterIsPrinting ||
                        ApplicationController.Instance.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;
                    }
                }
            };

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

            // Rebuild the droplist any time the ActivePrinter changes
            ActiveSliceSettings.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;
        }
예제 #16
0
        private void AddEePromControls(FlowLayoutWidget controlsTopToBottomLayout)
        {
            GroupBox eePromControlsGroupBox = new GroupBox(LocalizedString.Get("EEProm Settings"));

            eePromControlsGroupBox.Margin      = new BorderDouble(0);
            eePromControlsGroupBox.TextColor   = ActiveTheme.Instance.PrimaryTextColor;
            eePromControlsGroupBox.BorderColor = ActiveTheme.Instance.PrimaryTextColor;
            eePromControlsGroupBox.HAnchor     = Agg.UI.HAnchor.ParentLeftRight;
            eePromControlsGroupBox.VAnchor     = Agg.UI.VAnchor.FitToChildren;
            eePromControlsGroupBox.Height      = 68;
            {
                FlowLayoutWidget eePromControlsLayout = new FlowLayoutWidget();
                eePromControlsLayout.HAnchor |= HAnchor.ParentCenter;
                eePromControlsLayout.VAnchor |= Agg.UI.VAnchor.ParentCenter;
                eePromControlsLayout.Margin   = new BorderDouble(3, 0, 3, 6);
                eePromControlsLayout.Padding  = new BorderDouble(0);
                {
                    Agg.Image.ImageBuffer eePromImage = new Agg.Image.ImageBuffer();
                    ImageIO.LoadImageData(Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "Icons", "PrintStatusControls", "leveling-24x24.png"), eePromImage);
                    ImageWidget eePromIcon = new ImageWidget(eePromImage);
                    eePromIcon.Margin = new BorderDouble(right: 6);

                    Button openEePromWindow = textImageButtonFactory.Generate("Configure".Localize().ToUpper());
                    openEePromWindow.Click += (sender, e) =>
                    {
#if false // This is to force the creation of the repetier window for testing when we don't have repetier firmware.
                        new MatterHackers.MatterControl.EeProm.EePromRepetierWidget();
#else
                        switch (PrinterCommunication.Instance.FirmwareType)
                        {
                        case PrinterCommunication.FirmwareTypes.Repetier:
                            new MatterHackers.MatterControl.EeProm.EePromRepetierWidget();
                            break;

                        case PrinterCommunication.FirmwareTypes.Marlin:
                            new MatterHackers.MatterControl.EeProm.EePromMarlinWidget();
                            break;

                        default:
                            UiThread.RunOnIdle((state) =>
                            {
                                string message = LocalizedString.Get("Oops! There is no eeprom mapping for your printer's firmware.");
                                StyledMessageBox.ShowMessageBox(message, "Warning no eeprom mapping", StyledMessageBox.MessageType.OK);
                            }
                                               );
                            break;
                        }
#endif
                    };
                    //eePromControlsLayout.AddChild(eePromIcon);
                    eePromControlsLayout.AddChild(openEePromWindow);
                }

                eePromControlsGroupBox.AddChild(eePromControlsLayout);
            }

            eePromControlsContainer = new DisableableWidget();
            eePromControlsContainer.AddChild(eePromControlsGroupBox);

            controlsTopToBottomLayout.AddChild(eePromControlsContainer);
        }
예제 #17
0
        public TerminalWidget(PrinterConfig printer, ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            this.printer = printer;
            this.Name    = "TerminalWidget";
            this.Padding = new BorderDouble(5, 0);

            // Header
            var headerRow = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                HAnchor = HAnchor.Left | HAnchor.Stretch,
                Padding = new BorderDouble(0, 8)
            };

            this.AddChild(headerRow);

            filterOutput = new CheckBox("Filter Output".Localize(), textSize: theme.DefaultFontSize)
            {
                TextColor = theme.TextColor,
                VAnchor   = VAnchor.Bottom,
            };
            filterOutput.CheckedStateChanged += (s, e) =>
            {
                if (filterOutput.Checked)
                {
                    textScrollWidget.SetLineStartFilter(new string[] { "<-wait", "<-ok", "<-T" });
                }
                else
                {
                    textScrollWidget.SetLineStartFilter(null);
                }

                UserSettings.Instance.Fields.SetBool(UserSettingsKey.TerminalFilterOutput, filterOutput.Checked);
            };
            headerRow.AddChild(filterOutput);

            autoUppercase = new CheckBox("Auto Uppercase".Localize(), textSize: theme.DefaultFontSize)
            {
                Margin    = new BorderDouble(left: 25),
                Checked   = UserSettings.Instance.Fields.GetBool(UserSettingsKey.TerminalAutoUppercase, true),
                TextColor = theme.TextColor,
                VAnchor   = VAnchor.Bottom
            };
            autoUppercase.CheckedStateChanged += (s, e) =>
            {
                UserSettings.Instance.Fields.SetBool(UserSettingsKey.TerminalAutoUppercase, autoUppercase.Checked);
            };
            headerRow.AddChild(autoUppercase);

            // Body
            var bodyRow = new FlowLayoutWidget()
            {
                Margin  = new BorderDouble(bottom: 4),
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            };

            this.AddChild(bodyRow);

            textScrollWidget = new TextScrollWidget(printer, printer.Connection.TerminalLog.PrinterLines)
            {
                BackgroundColor = theme.MinimalShade,
                TextColor       = theme.TextColor,
                HAnchor         = HAnchor.Stretch,
                VAnchor         = VAnchor.Stretch,
                Margin          = 0,
                Padding         = new BorderDouble(3, 0)
            };
            bodyRow.AddChild(textScrollWidget);
            bodyRow.AddChild(new TextScrollBar(textScrollWidget, 15)
            {
                ThumbColor      = theme.AccentMimimalOverlay,
                BackgroundColor = theme.SlightShade,
                Margin          = 0
            });

            // Input Row
            var inputRow = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                BackgroundColor = this.BackgroundColor,
                HAnchor         = HAnchor.Stretch,
                Margin          = new BorderDouble(bottom: 2)
            };

            this.AddChild(inputRow);

            manualCommandTextEdit = new MHTextEditWidget("", theme, typeFace: ApplicationController.GetTypeFace(NamedTypeFace.Liberation_Mono))
            {
                Margin  = new BorderDouble(right: 3),
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Bottom
            };
            manualCommandTextEdit.ActualTextEditWidget.EnterPressed += (s, e) =>
            {
                SendManualCommand();
            };
            manualCommandTextEdit.ActualTextEditWidget.KeyDown += (s, keyEvent) =>
            {
                bool changeToHistory = false;
                if (keyEvent.KeyCode == Keys.Up)
                {
                    commandHistoryIndex--;
                    if (commandHistoryIndex < 0)
                    {
                        commandHistoryIndex = 0;
                    }
                    changeToHistory = true;
                }
                else if (keyEvent.KeyCode == Keys.Down)
                {
                    commandHistoryIndex++;
                    if (commandHistoryIndex > commandHistory.Count - 1)
                    {
                        commandHistoryIndex = commandHistory.Count - 1;
                    }
                    else
                    {
                        changeToHistory = true;
                    }
                }
                else if (keyEvent.KeyCode == Keys.Escape)
                {
                    manualCommandTextEdit.Text = "";
                }

                if (changeToHistory && commandHistory.Count > 0)
                {
                    manualCommandTextEdit.Text = commandHistory[commandHistoryIndex];
                }
            };
            inputRow.AddChild(manualCommandTextEdit);

            // Footer
            var toolbarPadding = theme.ToolbarPadding;
            var footerRow      = new FlowLayoutWidget
            {
                HAnchor = HAnchor.Stretch,
                Padding = new BorderDouble(0, toolbarPadding.Bottom, toolbarPadding.Right, toolbarPadding.Top)
            };

            this.AddChild(footerRow);

            var sendButton = theme.CreateDialogButton("Send".Localize());

            sendButton.Margin = theme.ButtonSpacing;
            sendButton.Click += (s, e) =>
            {
                SendManualCommand();
            };
            footerRow.AddChild(sendButton);

            var clearButton = theme.CreateDialogButton("Clear".Localize());

            clearButton.Margin = theme.ButtonSpacing;
            clearButton.Click += (s, e) =>
            {
                printer.Connection.TerminalLog.Clear();
            };
            footerRow.AddChild(clearButton);

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

            exportButton.Margin = theme.ButtonSpacing;
            exportButton.Click += (s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    AggContext.FileDialogs.SaveFileDialog(
                        new SaveFileDialogParams("Save as Text|*.txt")
                    {
                        Title             = "MatterControl: Terminal Log",
                        ActionButtonLabel = "Export",
                        FileName          = "print_log.txt"
                    },
                        (saveParams) =>
                    {
                        if (!string.IsNullOrEmpty(saveParams.FileName))
                        {
                            string filePathToSave = saveParams.FileName;
                            if (filePathToSave != null && filePathToSave != "")
                            {
                                try
                                {
                                    textScrollWidget.WriteToFile(filePathToSave);
                                }
                                catch (UnauthorizedAccessException ex)
                                {
                                    Debug.Print(ex.Message);

                                    printer.Connection.TerminalLog.PrinterLines.Add("");
                                    printer.Connection.TerminalLog.PrinterLines.Add(writeFaildeWaring);
                                    printer.Connection.TerminalLog.PrinterLines.Add(cantAccessPath.FormatWith(filePathToSave));
                                    printer.Connection.TerminalLog.PrinterLines.Add("");

                                    UiThread.RunOnIdle(() =>
                                    {
                                        StyledMessageBox.ShowMessageBox(ex.Message, "Couldn't save file".Localize());
                                    });
                                }
                            }
                        }
                    });
                });
            };
            footerRow.AddChild(exportButton);

            footerRow.AddChild(new HorizontalSpacer());

            this.AnchorAll();
        }
		public static void ShowMessageBox(Action<bool> callback, string message, string caption, GuiWidget[] extraWidgetsToAdd, MessageType messageType, string yesOk = "", string no = "")
		{
			StyledMessageBox messageBox = new StyledMessageBox(callback, message, caption, messageType, extraWidgetsToAdd, 400, 300, yesOk, no);
			messageBox.CenterInParent = true;
			messageBox.ShowAsSystemWindow();
		}
예제 #19
0
        private void ImportToPreset(string settingsFilePath)
        {
            if (!string.IsNullOrEmpty(settingsFilePath) && File.Exists(settingsFilePath))
            {
                PrinterSettingsLayer newLayer;

                string sectionName = (newMaterialPresetButton.Checked) ? "Material".Localize() : "Quality".Localize();

                string importType = Path.GetExtension(settingsFilePath).ToLower();
                switch (importType)
                {
                case ".printer":
                    newLayer = new PrinterSettingsLayer();
                    newLayer["layer_name"] = Path.GetFileNameWithoutExtension(settingsFilePath);

                    if (newQualityPresetButton.Checked)
                    {
                        ActiveSliceSettings.Instance.QualityLayers.Add(newLayer);
                    }
                    else
                    {
                        // newMaterialPresetButton.Checked
                        ActiveSliceSettings.Instance.MaterialLayers.Add(newLayer);
                    }

                    // open a wizard to ask what to import to the preset
                    WizardWindow.ChangeToPage(new SelectPartsOfPrinterToImport(settingsFilePath, newLayer, sectionName));

                    break;

                case ".slice":                         // legacy presets file extension
                case ".ini":
                    var    settingsToImport = PrinterSettingsLayer.LoadFromIni(settingsFilePath);
                    string layerHeight;

                    bool isSlic3r = importType == ".slice" || settingsToImport.TryGetValue(SettingsKey.layer_height, out layerHeight);
                    if (isSlic3r)
                    {
                        newLayer      = new PrinterSettingsLayer();
                        newLayer.Name = Path.GetFileNameWithoutExtension(settingsFilePath);

                        // Only be the base and oem layers (not the user, quality or material layer)
                        var baseAndOEMCascade = new List <PrinterSettingsLayer>
                        {
                            ActiveSliceSettings.Instance.OemLayer,
                            ActiveSliceSettings.Instance.BaseLayer
                        };

                        foreach (var item in settingsToImport)
                        {
                            string currentValue = ActiveSliceSettings.Instance.GetValue(item.Key, baseAndOEMCascade).Trim();
                            // Compare the value to import to the layer cascade value and only set if different
                            if (currentValue != item.Value)
                            {
                                newLayer[item.Key] = item.Value;
                            }
                        }

                        if (newMaterialPresetButton.Checked)
                        {
                            ActiveSliceSettings.Instance.MaterialLayers.Add(newLayer);
                        }
                        else
                        {
                            ActiveSliceSettings.Instance.QualityLayers.Add(newLayer);
                        }

                        ActiveSliceSettings.Instance.SaveChanges();

                        WizardWindow.ChangeToPage(new ImportSucceeded(importSettingSuccessMessage.FormatWith(Path.GetFileNameWithoutExtension(settingsFilePath), sectionName))
                        {
                            WizardWindow = this.WizardWindow,
                        });
                    }
                    else
                    {
                        // looks like a cura file
#if DEBUG
                        throw new NotImplementedException("need to import from 'cure.ini' files");
#endif
                    }
                    break;

                default:
                    // Did not figure out what this file is, let the user know we don't understand it
                    StyledMessageBox.ShowMessageBox(null, "Oops! Unable to recognize settings file '{0}'.".Localize().FormatWith(Path.GetFileName(settingsFilePath)), "Unable to Import".Localize());
                    break;
                }
            }
            Invalidate();
        }