コード例 #1
0
        public void SaveValue(string keyName, string keyValue, int layerIndex = 1)
        {
            SettingsLayer layer = this.activeSettingsLayers[layerIndex];

            if (layer.settingsDictionary.ContainsKey(keyName) &&
                layer.settingsDictionary[keyName].Value != keyValue)
            {
                layer.settingsDictionary[keyName].Value = keyValue;

                OnSettingsChanged();
                HasUncommittedChanges = true;
            }
            else
            {
                DataStorage.SliceSetting sliceSetting = new DataStorage.SliceSetting();
                sliceSetting.Name  = keyName;
                sliceSetting.Value = keyValue;
                sliceSetting.SettingsCollectionId = layer.settingsCollectionData.Id;

                layer.settingsDictionary[keyName] = sliceSetting;

                OnSettingsChanged();
                HasUncommittedChanges = true;
            }
        }
コード例 #2
0
        public void CommitLayerChanges(int layerIndex)
        {
            SettingsLayer layer = this.activeSettingsLayers[layerIndex];

            foreach (KeyValuePair <String, DataStorage.SliceSetting> item in layer.settingsDictionary)
            {
                item.Value.Commit();
            }
        }
コード例 #3
0
        private void LoadDefaultConfigrationSettings()
        {
            string slic3rDefaultConfigurationPathAndFile = Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "PrinterSettings", "config.ini");

            DataStorage.SliceSettingsCollection defaultCollection = new DataStorage.SliceSettingsCollection();
            defaultCollection.Name = "__default__";
            SettingsLayer defaultSettingsLayer = LoadConfigurationSettingsFromFile(slic3rDefaultConfigurationPathAndFile, defaultCollection);

            this.activeSettingsLayers.Add(defaultSettingsLayer);
        }
コード例 #4
0
        private void ReplaceOrMergeSettings(string settingsFilePath)
        {
            if (!string.IsNullOrEmpty(settingsFilePath) && File.Exists(settingsFilePath))
            {
                string importType = Path.GetExtension(settingsFilePath).ToLower();
                switch (importType)
                {
                case ".printer":
                    throw new NotImplementedException("need to import from 'MatterControl.printer' files");
                    break;

                case ".ini":
                    var    settingsToImport = SettingsLayer.LoadFromIni(settingsFilePath);
                    string layerHeight;

                    bool isSlic3r = settingsToImport.TryGetValue("layer_height", out layerHeight);
                    if (isSlic3r)
                    {
                        var activeSettings = ActiveSliceSettings.Instance;

                        if (importMode == "replace")
                        {
                            activeSettings.ClearUserOverrides();
                        }

                        foreach (var item in settingsToImport)
                        {
                            // Compare the value to import to the layer cascade value and only set if different
                            string currentValue = activeSettings.GetActiveValue(item.Key, null).Trim();
                            if (currentValue != item.Value)
                            {
                                activeSettings.UserLayer[item.Key] = item.Value;
                            }
                        }

                        activeSettings.SaveChanges();

                        UiThread.RunOnIdle(ApplicationController.Instance.ReloadAdvancedControlsPanel);
                    }
                    else
                    {
                        // looks like a cura file
                        throw new NotImplementedException("need to import from 'cure.ini' files");
                    }
                    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();
        }
コード例 #5
0
        private SettingsLayer LoadConfigurationSettingsFromDatastore(DataStorage.SliceSettingsCollection collection)
        {
            Dictionary <string, DataStorage.SliceSetting> settingsDictionary = new Dictionary <string, DataStorage.SliceSetting>();

            IEnumerable <DataStorage.SliceSetting> settingsList = GetCollectionSettings(collection.Id);

            foreach (DataStorage.SliceSetting s in settingsList)
            {
                settingsDictionary[s.Name] = s;
            }

            SettingsLayer settingsLayer = new SettingsLayer(collection, settingsDictionary);

            return(settingsLayer);
        }
コード例 #6
0
        public void LoadPrinterConfigurationSettings()
        {
            if (PrinterCommunication.Instance.ActivePrinter != null)
            {
                DataStorage.SliceSettingsCollection collection;
                if (PrinterCommunication.Instance.ActivePrinter.DefaultSettingsCollectionId != 0)
                {
                    int activePrinterSettingsID = PrinterCommunication.Instance.ActivePrinter.DefaultSettingsCollectionId;
                    collection = DataStorage.Datastore.Instance.dbSQLite.Table <DataStorage.SliceSettingsCollection>().Where(v => v.Id == activePrinterSettingsID).Take(1).FirstOrDefault();
                }
                else
                {
                    collection      = new DataStorage.SliceSettingsCollection();
                    collection.Name = PrinterCommunication.Instance.ActivePrinter.Name;
                    collection.Commit();

                    PrinterCommunication.Instance.ActivePrinter.DefaultSettingsCollectionId = collection.Id;
                    PrinterCommunication.Instance.ActivePrinter.Commit();
                }
                SettingsLayer printerSettingsLayer = LoadConfigurationSettingsFromDatastore(collection);
                this.activeSettingsLayers.Add(printerSettingsLayer);
            }
        }
コード例 #7
0
        public SettingsLayer LoadConfigurationSettingsFromFile(string pathAndFileName, DataStorage.SliceSettingsCollection collection)
        {
            Dictionary <string, DataStorage.SliceSetting> settingsDictionary = new Dictionary <string, DataStorage.SliceSetting>();
            SettingsLayer activeCollection;

            try
            {
                if (File.Exists(pathAndFileName))
                {
                    string[] lines = System.IO.File.ReadAllLines(pathAndFileName);
                    foreach (string line in lines)
                    {
                        //Ignore commented lines
                        if (!line.StartsWith("#"))
                        {
                            string[] settingLine         = line.Split('=');
                            string   keyName             = settingLine[0].Trim();
                            string   settingDefaultValue = settingLine[1].Trim();

                            DataStorage.SliceSetting sliceSetting = new DataStorage.SliceSetting();
                            sliceSetting.Name  = keyName;
                            sliceSetting.Value = settingDefaultValue;

                            settingsDictionary.Add(keyName, sliceSetting);
                        }
                    }
                    activeCollection = new SettingsLayer(collection, settingsDictionary);
                    return(activeCollection);
                }
                return(null);
            }
            catch (Exception e)
            {
                Debug.WriteLine(string.Format("Error loading configuration: {0}", e));
                return(null);
            }
        }