Beispiel #1
0
        public OrganizerCategory NewAndAddSettingsGroup(string settingsGroupName)
        {
            OrganizerCategory newCategoriesGroup = new OrganizerCategory(settingsGroupName);

            CategoriesList.Add(newCategoriesGroup);
            return(newCategoriesGroup);
        }
Beispiel #2
0
        void LoadAndParseSettingsFiles(string properties, string layout)
        {
            {
                string propertiesFileContents = "";
                using (FileStream fileStream = new FileStream(properties, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    using (StreamReader propertiesReader = new StreamReader(fileStream))
                    {
                        propertiesFileContents = propertiesReader.ReadToEnd();
                    }
                }

                string[] lines = propertiesFileContents.Split('\n');
                foreach (string line in lines)
                {
                    if (line.Trim().Length > 0)
                    {
                        settingsData.Add(OrganizerSettingsData.NewOrganizerSettingData(line));
                    }
                }
            }

            {
                string layoutFileContents = "";
                using (FileStream fileStream = new FileStream(layout, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    using (StreamReader layoutReader = new StreamReader(fileStream))
                    {
                        layoutFileContents = layoutReader.ReadToEnd();
                    }
                }

                OrganizerUserLevel userLevelToAddTo = null;
                OrganizerCategory  categoryToAddTo  = null;
                OrganizerGroup     groupToAddTo     = null;
                OrganizerSubGroup  subGroupToAddTo  = null;
                string[]           lines            = layoutFileContents.Split('\n');
                foreach (string line in lines)
                {
                    if (line.Length > 0)
                    {
                        switch (CountLeadingSpaces(line))
                        {
                        case 0:
                            string userLevelText = line.Replace('"', ' ').Trim();
                            userLevelToAddTo = new OrganizerUserLevel(userLevelText);
                            UserLevels.Add(userLevelText, userLevelToAddTo);
                            break;

                        case 2:
                            categoryToAddTo = new OrganizerCategory(line.Replace('"', ' ').Trim());
                            userLevelToAddTo.CategoriesList.Add(categoryToAddTo);
                            break;

                        case 4:
                            groupToAddTo = new OrganizerGroup(line.Replace('"', ' ').Trim());
                            categoryToAddTo.GroupsList.Add(groupToAddTo);
                            break;

                        case 6:
                            subGroupToAddTo = new OrganizerSubGroup(line.Replace('"', ' ').Trim());
                            groupToAddTo.SubGroupsList.Add(subGroupToAddTo);
                            break;

                        case 8:
                            subGroupToAddTo.SettingDataList.Add(GetSettingsData(line.Replace('"', ' ').Trim()));
                            break;

                        default:
                            throw new Exception("Bad file, too many spaces (must be 0, 2, 4 or 6).");
                        }
                    }
                }
            }
        }
        void AddControls(UiState uiState)
        {
            int minSettingNameWidth = 220;

            showHelpBox         = new CheckBox(new LocalizedString("Show Help").Translated);
            showHelpBox.Checked = uiState.showHelp;

            showAllDetails         = new CheckBox(new LocalizedString("Show All Settings").Translated);
            showAllDetails.Checked = uiState.userLevel == "Advanced";

            FlowLayoutWidget pageTopToBottomLayout = new FlowLayoutWidget(FlowDirection.TopToBottom, vAnchor: Agg.UI.VAnchor.ParentTop);

            pageTopToBottomLayout.AnchorAll();
            pageTopToBottomLayout.Padding = new BorderDouble(3, 0);
            this.AddChild(pageTopToBottomLayout);

            settingsControlBar = new SettingsControlBar();
            pageTopToBottomLayout.AddChild(settingsControlBar);

            noConnectionMessageContainer             = new GroupBox(new LocalizedString("No Printer Selected").Translated);
            noConnectionMessageContainer.Margin      = new BorderDouble(top: 10);
            noConnectionMessageContainer.TextColor   = ActiveTheme.Instance.PrimaryTextColor;
            noConnectionMessageContainer.BorderColor = ActiveTheme.Instance.PrimaryTextColor;
            noConnectionMessageContainer.HAnchor     = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth;
            noConnectionMessageContainer.Height      = 80;

            TextWidget noConnectionMessage = new TextWidget(new LocalizedString("No printer is currently selected. Select printer to edit slice settings.").Translated);

            noConnectionMessage.Margin    = new BorderDouble(5);
            noConnectionMessage.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            noConnectionMessage.VAnchor   = VAnchor.ParentCenter;

            noConnectionMessageContainer.AddChild(noConnectionMessage);
            pageTopToBottomLayout.AddChild(noConnectionMessageContainer);

            categoryTabs = new TabControl();
            categoryTabs.TabBar.BorderColor = RGBA_Bytes.White;
            categoryTabs.Margin             = new BorderDouble(top: 8);
            categoryTabs.AnchorAll();
            List <TabBar> sideTabBarsListForLayout = new List <TabBar>();

            for (int categoryIndex = 0; categoryIndex < SliceSettingsOrganizer.Instance.UserLevels[UserLevel].CategoriesList.Count; categoryIndex++)
            {
                OrganizerCategory   category        = SliceSettingsOrganizer.Instance.UserLevels[UserLevel].CategoriesList[categoryIndex];
                string              categoryPageLbl = new LocalizedString(category.Name).Translated;
                TabPage             categoryPage    = new TabPage(categoryPageLbl);
                SimpleTextTabWidget textTabWidget   = new SimpleTextTabWidget(categoryPage, 16,
                                                                              ActiveTheme.Instance.TabLabelSelected, new RGBA_Bytes(), ActiveTheme.Instance.TabLabelUnselected, new RGBA_Bytes());
                categoryPage.AnchorAll();
                categoryTabs.AddTab(textTabWidget);

                TabControl sideTabs = CreateSideTabsAndPages(minSettingNameWidth, category, uiState);
                sideTabBarsListForLayout.Add(sideTabs.TabBar);

                categoryPage.AddChild(sideTabs);
            }

            if (showAllDetails.Checked && PrinterCommunication.Instance.ActiveSliceEngine == PrinterCommunication.SlicingEngine.Slic3r)
            {
                TabPage             extraSettingsPage          = new TabPage("Other");
                SimpleTextTabWidget extraSettingsTextTabWidget = new SimpleTextTabWidget(extraSettingsPage, 16,
                                                                                         ActiveTheme.Instance.TabLabelSelected, new RGBA_Bytes(), ActiveTheme.Instance.TabLabelUnselected, new RGBA_Bytes());
                extraSettingsPage.AnchorAll();
                int        count;
                TabControl extraSettingsSideTabs = CreateExtraSettingsSideTabsAndPages(minSettingNameWidth, categoryTabs, out count);
                if (count > 0)
                {
                    categoryTabs.AddTab(extraSettingsTextTabWidget);
                    sideTabBarsListForLayout.Add(extraSettingsSideTabs.TabBar);
                    extraSettingsPage.AddChild(extraSettingsSideTabs);
                }
            }

            double sideTabBarsMinimumWidth = 0;

            foreach (TabBar tabBar in sideTabBarsListForLayout)
            {
                sideTabBarsMinimumWidth = Math.Max(sideTabBarsMinimumWidth, tabBar.Width);
            }
            foreach (TabBar tabBar in sideTabBarsListForLayout)
            {
                tabBar.MinimumSize = new Vector2(sideTabBarsMinimumWidth, tabBar.MinimumSize.y);
            }

            // space before checkboxes (hold the right aligned)
            {
                GuiWidget hSpacer = new GuiWidget();
                hSpacer.HAnchor = HAnchor.ParentLeftRight;

                categoryTabs.TabBar.AddChild(hSpacer);
            }

            // add in the ability to turn on and off all details settings
            {
                showAllDetails.TextColor            = RGBA_Bytes.White;
                showAllDetails.Margin               = new BorderDouble(right: 8);
                showAllDetails.VAnchor              = VAnchor.ParentCenter;
                showAllDetails.Cursor               = Cursors.Hand;
                showAllDetails.CheckedStateChanged += new CheckBox.CheckedStateChangedEventHandler(RebuildSlicerSettings);

                categoryTabs.TabBar.AddChild(showAllDetails);
            }

            // add in the ability to turn on and off help text
            {
                showHelpBox.TextColor            = RGBA_Bytes.White;
                showHelpBox.Margin               = new BorderDouble(right: 3);
                showHelpBox.VAnchor              = VAnchor.ParentCenter;
                showHelpBox.Cursor               = Cursors.Hand;
                showHelpBox.CheckedStateChanged += new CheckBox.CheckedStateChangedEventHandler(RebuildSlicerSettings);

                categoryTabs.TabBar.AddChild(showHelpBox);
            }

            pageTopToBottomLayout.AddChild(categoryTabs);
            AddHandlers();
            SetVisibleControls();

            if (!categoryTabs.SelectTab(uiState.selectedCategory.name))
            {
                categoryTabs.SelectTab(uiState.selectedCategory.index);
            }
        }
        private TabControl CreateSideTabsAndPages(int minSettingNameWidth, OrganizerCategory category, UiState uiState)
        {
            TabControl groupTabs = new TabControl(Orientation.Vertical);

            groupTabs.Margin             = new BorderDouble(0, 0, 0, 5);
            groupTabs.TabBar.BorderColor = RGBA_Bytes.White;
            foreach (OrganizerGroup group in category.GroupsList)
            {
                tabIndexForItem = 0;
                string              groupTabLbl    = new LocalizedString(group.Name).Translated;
                TabPage             groupTabPage   = new TabPage(groupTabLbl);
                SimpleTextTabWidget groupTabWidget = new SimpleTextTabWidget(groupTabPage, 14,
                                                                             ActiveTheme.Instance.TabLabelSelected, new RGBA_Bytes(), ActiveTheme.Instance.TabLabelUnselected, new RGBA_Bytes());

                FlowLayoutWidget subGroupLayoutTopToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);
                subGroupLayoutTopToBottom.AnchorAll();

                bool needToAddSubGroup = false;
                foreach (OrganizerSubGroup subGroup in group.SubGroupsList)
                {
                    bool             addedSettingToSubGroup = false;
                    FlowLayoutWidget topToBottomSettings    = new FlowLayoutWidget(FlowDirection.TopToBottom);
                    topToBottomSettings.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth;

                    foreach (OrganizerSettingsData settingInfo in subGroup.SettingDataList)
                    {
                        if (PrinterCommunication.Instance.ActiveSliceEngine == PrinterCommunication.SlicingEngine.Slic3r ||
                            CuraEngineMappings.MapContains(settingInfo.SlicerConfigName))
                        {
                            addedSettingToSubGroup = true;
                            GuiWidget controlsForThisSetting = CreateSettingInfoUIControls(settingInfo, minSettingNameWidth);
                            topToBottomSettings.AddChild(controlsForThisSetting);

                            if (showHelpBox.Checked)
                            {
                                AddInHelpText(topToBottomSettings, settingInfo);
                            }
                        }
                    }

                    if (addedSettingToSubGroup)
                    {
                        needToAddSubGroup = true;
                        string   groupBoxLbl = new LocalizedString(subGroup.Name).Translated;
                        GroupBox groupBox    = new GroupBox(groupBoxLbl);
                        groupBox.TextColor   = ActiveTheme.Instance.PrimaryTextColor;
                        groupBox.BorderColor = ActiveTheme.Instance.PrimaryTextColor;
                        groupBox.AddChild(topToBottomSettings);

                        groupBox.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth;

                        subGroupLayoutTopToBottom.AddChild(groupBox);
                    }
                }

                if (needToAddSubGroup)
                {
                    ScrollableWidget scrollOnGroupTab = new ScrollableWidget(true);
                    scrollOnGroupTab.AnchorAll();
                    subGroupLayoutTopToBottom.HAnchor = HAnchor.Max_FitToChildren_ParentWidth;
                    subGroupLayoutTopToBottom.VAnchor = VAnchor.FitToChildren;
                    //subGroupLayoutTopToBottom.DebugShowBounds = true;
                    //scrollOnGroupTab.DebugShowBounds = true;
                    scrollOnGroupTab.AddChild(subGroupLayoutTopToBottom);
                    groupTabPage.AddChild(scrollOnGroupTab);
                    groupTabs.AddTab(groupTabWidget);
                }
            }

            if (!groupTabs.SelectTab(uiState.selectedGroup.name))
            {
                groupTabs.SelectTab(uiState.selectedGroup.index);
            }
            return(groupTabs);
        }