Exemple #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;
            }
        }
Exemple #2
0
 private void CommitSliceSettings(Dictionary <string, string> settingsDict, int collectionId)
 {
     foreach (KeyValuePair <string, string> item in settingsDict)
     {
         DataStorage.SliceSetting sliceSetting = new DataStorage.SliceSetting();
         sliceSetting.Name  = item.Key;
         sliceSetting.Value = item.Value;
         sliceSetting.SettingsCollectionId = collectionId;
         sliceSetting.Commit();
     }
 }
Exemple #3
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);
            }
        }
		private void CommitSliceSettings(Dictionary<string, string> settingsDict, int collectionId)
		{
			foreach (KeyValuePair<string, string> item in settingsDict)
			{
				DataStorage.SliceSetting sliceSetting = new DataStorage.SliceSetting();
				sliceSetting.Name = item.Key;
				sliceSetting.Value = item.Value;
				sliceSetting.SettingsCollectionId = collectionId;
				sliceSetting.Commit();
			}
		}
		private static ClassicSettingsLayer LoadConfigurationSettingsFromFile(string pathAndFileName, SliceSettingsCollection collection)
		{
			Dictionary<string, SliceSetting> settingsDictionary = new Dictionary<string, SliceSetting>();
			ClassicSettingsLayer activeCollection;
			try
			{
				if (StaticData.Instance.FileExists(pathAndFileName))
				{
					foreach (string line in StaticData.Instance.ReadAllLines(pathAndFileName))
					{
						//Ignore commented lines
						if (!line.StartsWith("#"))
						{
							string[] settingLine = line.Split('=');
							string keyName = settingLine[0].Trim();
							string settingDefaultValue = settingLine[1].Trim();

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

							settingsDictionary.Add(keyName, sliceSetting);
						}
					}
					activeCollection = new ClassicSettingsLayer(collection, settingsDictionary);
					return activeCollection;
				}
				return null;
			}
			catch (Exception e)
			{
				Debug.Print(e.Message);
				GuiWidget.BreakInDebugger();
				Debug.WriteLine(string.Format("Error loading configuration: {0}", e));
				return null;
			}
		} 
		private void onLoadPreset(OpenFileDialogParams openParams)
		{
			if (openParams.FileNames != null)
			{
				Dictionary<string, SliceSetting> settingsDictionary = new Dictionary<string, SliceSetting>();
				try
				{
					if (File.Exists(openParams.FileName))
					{
						string[] lines = System.IO.File.ReadAllLines(openParams.FileName);
						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();

								SliceSetting sliceSetting = new SliceSetting();
								sliceSetting.Name = keyName;
								sliceSetting.Value = settingDefaultValue;
								sliceSetting.SettingsCollectionId = windowController.ActivePresetLayer.settingsCollectionData.Id;

								settingsDictionary.Add(keyName, sliceSetting);
							}
						}
						windowController.ActivePresetLayer.settingsDictionary = settingsDictionary;
						LoadSettingsRows();
					}
				}
				catch (Exception)
				{
					// Error loading configuration
				}
			}
		}
		private void duplicatePresets_Click(object sender, EventArgs mouseEvent)
		{
			UiThread.RunOnIdle(() =>
			{
				SliceSettingsCollection duplicateCollection = new SliceSettingsCollection();
				duplicateCollection.Name = string.Format("{0} (copy)".FormatWith(windowController.ActivePresetLayer.settingsCollectionData.Name));
				duplicateCollection.Tag = windowController.ActivePresetLayer.settingsCollectionData.Tag;
				duplicateCollection.PrinterId = windowController.ActivePresetLayer.settingsCollectionData.PrinterId;

				Dictionary<string, SliceSetting> settingsDictionary = new Dictionary<string, SliceSetting>();
				IEnumerable<SliceSetting> settingsList = this.windowController.GetCollectionSettings(windowController.ActivePresetLayer.settingsCollectionData.Id);
				foreach (SliceSetting s in settingsList)
				{
					SliceSetting newSetting = new SliceSetting();
					newSetting.Name = s.Name;
					newSetting.Value = s.Value;

					settingsDictionary.Add(s.Name, newSetting);
				}

				var duplicateLayer = new ClassicSqlitePrinterProfiles.ClassicSettingsLayer(duplicateCollection, settingsDictionary);
				windowController.ActivePresetLayer = duplicateLayer;
				windowController.ChangeToSlicePresetDetail();
			});
		}
		public void SaveValue(string keyName, string keyValue)
		{
			if (this.windowController.ActivePresetLayer.settingsDictionary.ContainsKey(keyName)
				&& this.windowController.ActivePresetLayer.settingsDictionary[keyName].Value != keyValue)
			{
				this.windowController.ActivePresetLayer.settingsDictionary[keyName].Value = keyValue;

				OnSettingsChanged();
			}
			else
			{
				SliceSetting sliceSetting = new SliceSetting();
				sliceSetting.Name = keyName;
				sliceSetting.Value = keyValue;
				sliceSetting.SettingsCollectionId = this.windowController.ActivePresetLayer.settingsCollectionData.Id;

				this.windowController.ActivePresetLayer.settingsDictionary[keyName] = sliceSetting;

				OnSettingsChanged();
			}
		}
		private void AddSettingToPreset()
		{
			UiThread.RunOnIdle(() =>
			{
				if (addRowSettingData != null)
				{
					if (!this.windowController.ActivePresetLayer.settingsDictionary.ContainsKey(addRowSettingData.SlicerConfigName))
					{
						SliceSetting sliceSetting = new SliceSetting();
						sliceSetting.Name = addRowSettingData.SlicerConfigName;
						sliceSetting.Value = ActiveSliceSettings.Instance.GetActiveValue(addRowSettingData.SlicerConfigName); //populate with current
						sliceSetting.SettingsCollectionId = this.windowController.ActivePresetLayer.settingsCollectionData.Id;

						this.windowController.ActivePresetLayer.settingsDictionary[addRowSettingData.SlicerConfigName] = sliceSetting;

						OnSettingsChanged();
					}
					addRowSettingData = null;
					PopulateAddSettingRow(-1, -1, "-1");
					LoadSettingsRows();

					duplicatePresetButton.Visible = false;
					exportPresetButton.Visible = false;
				}
				else
				{
					errorMessageContainer.Visible = true;
				}
			});
		}
		private void onPresetLoad(OpenFileDialogParams openParams)
		{
			if (openParams.FileNames != null)
			{
				SliceSettingsCollection settingsCollection;
				try
				{
					if (File.Exists(openParams.FileName))
					{
						// TODO: Review bindings to int printerID
						int printerID;
						int.TryParse(ActiveSliceSettings.Instance.Id, out printerID);

						//Create collection to hold preset settings
						settingsCollection = new SliceSettingsCollection();
						settingsCollection.Tag = windowController.filterTag;
						settingsCollection.PrinterId = printerID;
						settingsCollection.Name = System.IO.Path.GetFileNameWithoutExtension(openParams.FileName);
						settingsCollection.Commit();

						string[] lines = System.IO.File.ReadAllLines(openParams.FileName);
						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();

								//To do - validate imported settings as valid (KP)
								SliceSetting sliceSetting = new SliceSetting();
								sliceSetting.Name = keyName;
								sliceSetting.Value = settingDefaultValue;
								sliceSetting.SettingsCollectionId = settingsCollection.Id;
								sliceSetting.Commit();
							}
						}
						windowController.ChangeToSlicePresetList();
					}
				}
				catch (Exception)
				{
					// Error loading configuration
				}
			}
		}