Example #1
0
        public void SetValue(string settingsKey, string settingsValue, PrinterSettingsLayer layer = null)
        {
            // Stash user overrides if a non-user override is being set
            if (layer != null && layer != UserLayer)
            {
                StashUserOverride(layer, settingsKey);
            }
            else
            {
                // Remove any staged/conflicting user override, making this the new and active user override
                if (StagedUserSettings.ContainsKey(settingsKey))
                {
                    StagedUserSettings.Remove(settingsKey);
                }
            }

            var persistenceLayer = layer ?? UserLayer;

            // If the setting exists and is set to the requested value, exit without setting or saving
            string existingValue;

            if (persistenceLayer.TryGetValue(settingsKey, out existingValue) && existingValue == settingsValue)
            {
                return;
            }

            // Otherwise, set and save
            persistenceLayer[settingsKey] = settingsValue;
            Save();

            ActiveSliceSettings.OnSettingChanged(settingsKey);
        }
Example #2
0
        private void MenuItem_Selected(object sender, EventArgs e)
        {
            // When a preset is selected store the current values of all known settings to compare against after applying the preset
            Dictionary <string, string> settingBeforeChange = new Dictionary <string, string>();

            foreach (var keyName in PrinterSettings.KnownSettings)
            {
                settingBeforeChange.Add(keyName, printer.Settings.GetValue(keyName));
            }

            var      activeSettings = printer.Settings;
            MenuItem item           = (MenuItem)sender;

            if (layerType == NamedSettingsLayers.Material)
            {
                if (activeSettings.ActiveMaterialKey != item.Value)
                {
                    // Restore deactivated user overrides by iterating the Material preset we're coming off of
                    activeSettings.RestoreConflictingUserOverrides(activeSettings.MaterialLayer);

                    activeSettings.ActiveMaterialKey = item.Value;

                    // Deactivate conflicting user overrides by iterating the Material preset we've just switched to
                    activeSettings.DeactivateConflictingUserOverrides(activeSettings.MaterialLayer);
                }
            }
            else if (layerType == NamedSettingsLayers.Quality)
            {
                if (activeSettings.ActiveQualityKey != item.Value)
                {
                    // Restore deactivated user overrides by iterating the Quality preset we're coming off of
                    activeSettings.RestoreConflictingUserOverrides(activeSettings.QualityLayer);

                    activeSettings.ActiveQualityKey = item.Value;

                    // Deactivate conflicting user overrides by iterating the Quality preset we've just switched to
                    activeSettings.DeactivateConflictingUserOverrides(activeSettings.QualityLayer);
                }
            }

            // Ensure that activated or deactivated user overrides are always persisted to disk
            activeSettings.Save();

            UiThread.RunOnIdle(() =>
            {
                foreach (var keyName in PrinterSettings.KnownSettings)
                {
                    if (settingBeforeChange[keyName] != printer.Settings.GetValue(keyName))
                    {
                        ActiveSliceSettings.OnSettingChanged(keyName);
                    }
                }
            });

            editButton.Enabled = item.Text != defaultMenuItemText;
        }
        private void MenuItem_Selected(object sender, EventArgs e)
        {
            Dictionary <string, string> settingBeforeChange = new Dictionary <string, string>();

            foreach (var keyName in PrinterSettings.KnownSettings)
            {
                settingBeforeChange.Add(keyName, ActiveSliceSettings.Instance.GetValue(keyName));
            }

            var      activeSettings = ActiveSliceSettings.Instance;
            MenuItem item           = (MenuItem)sender;

            if (layerType == NamedSettingsLayers.Material)
            {
                if (activeSettings.GetMaterialPresetKey(extruderIndex) != item.Value)
                {
                    // Restore deactivated user overrides by iterating the Material preset we're coming off of
                    activeSettings.RestoreConflictingUserOverrides(activeSettings.MaterialLayer);

                    activeSettings.SetMaterialPreset(extruderIndex, item.Value);

                    // Deactivate conflicting user overrides by iterating the Material preset we've just switched to
                    activeSettings.DeactivateConflictingUserOverrides(activeSettings.MaterialLayer);
                }
            }
            else if (layerType == NamedSettingsLayers.Quality)
            {
                if (activeSettings.ActiveQualityKey != item.Value)
                {
                    // Restore deactivated user overrides by iterating the Quality preset we're coming off of
                    activeSettings.RestoreConflictingUserOverrides(activeSettings.QualityLayer);

                    activeSettings.ActiveQualityKey = item.Value;

                    // Deactivate conflicting user overrides by iterating the Quality preset we've just switched to
                    activeSettings.DeactivateConflictingUserOverrides(activeSettings.QualityLayer);
                }
            }

            // Ensure that activated or deactivated user overrides are always persisted to disk
            activeSettings.Save();

            UiThread.RunOnIdle(() =>
            {
                ApplicationController.Instance.ReloadAdvancedControlsPanel();
                foreach (var keyName in PrinterSettings.KnownSettings)
                {
                    if (settingBeforeChange[keyName] != ActiveSliceSettings.Instance.GetValue(keyName))
                    {
                        ActiveSliceSettings.OnSettingChanged(keyName);
                    }
                }
            });

            editButton.Enabled = item.Text != defaultMenuItemText;
        }
Example #4
0
        internal void ClearValue(string settingsKey, PrinterSettingsLayer layer = null)
        {
            var persistenceLayer = layer ?? UserLayer;

            if (persistenceLayer.ContainsKey(settingsKey))
            {
                persistenceLayer.Remove(settingsKey);

                // Restore user overrides if a non-user override is being cleared
                if (layer != null && layer != UserLayer)
                {
                    RestoreUserOverride(layer, settingsKey);
                }

                Save();

                ActiveSliceSettings.OnSettingChanged(settingsKey);
            }
        }