public static void ImportPrinters(ProfileManager profileData, string profilePath)
		{
			foreach (Printer printer in Datastore.Instance.dbSQLite.Query<Printer>("SELECT * FROM Printer;"))
			{
				ImportPrinter(printer, profileData, profilePath);
			}
		}
Beispiel #2
0
 internal static async Task SwitchToProfile(string printerID)
 {
     ProfileManager.Instance.LastProfileID = printerID;
     Instance = (await ProfileManager.LoadProfileAsync(printerID)) ?? PrinterSettings.Empty;
 }
Beispiel #3
0
 internal static async Task SwitchToProfile(string printerID)
 {
     ProfileManager.Instance.SetLastProfile(printerID);
     Instance = (await ProfileManager.LoadProfileAsync(printerID)) ?? ProfileManager.LoadEmptyProfile();
 }
Beispiel #4
0
 static ActiveSliceSettings()
 {
     // Load last profile or fall back to empty
     Instance = ProfileManager.Instance?.LoadLastProfileWithoutRecovery() ?? ProfileManager.LoadEmptyProfile();
 }
		/// <summary>
		/// Loads a ProfileManager for the given user
		/// </summary>
		/// <param name="userName">The user name to load</param>
		public static ProfileManager Load(string userName)
		{
			if (string.IsNullOrEmpty(userName))
			{
				userName = "******";
			}

			string profilesDocPath = GetProfilesDocPathForUser(userName);

			ProfileManager loadedInstance;

			// Deserialize from disk or if missing, initialize a new instance
			if (File.Exists(profilesDocPath))
			{
				string json = File.ReadAllText(profilesDocPath);
				loadedInstance = JsonConvert.DeserializeObject<ProfileManager>(json);
				loadedInstance.UserName = userName;
			}
			else
			{
				loadedInstance = new ProfileManager() { UserName = userName };
			}

			// If the loaded slice settings do not match the last active settings for this profile, change to the last active
			if (ActiveSliceSettings.Instance?.ID != loadedInstance.LastProfileID)
			{
				// async so we can safely wait for LoadProfileAsync to complete
				Task.Run(async () =>
				{
					// Load or download on a background thread
					var lastProfile = await LoadProfileAsync(Instance.LastProfileID);

					if (MatterControlApplication.IsLoading)
					{
						// TODO: Not true - we're on a background thread in an async lambda... what is the intent of this?
						// Assign on the UI thread
						ActiveSliceSettings.Instance = lastProfile ?? LoadEmptyProfile();
					}
					else
					{
						UiThread.RunOnIdle(() =>
						{
							// Assign on the UI thread
							ActiveSliceSettings.Instance = lastProfile ?? LoadEmptyProfile();
						});
					}
				});
			}

			return loadedInstance;
		}
		public static void ImportPrinter(Printer printer, ProfileManager profileData, string profilePath)
		{
			var printerInfo = new PrinterInfo()
			{
				Name = printer.Name,
				ID = printer.Id.ToString(),
				Make = printer.Make ?? "",
				Model = printer.Model ?? "",
			};
			profileData.Profiles.Add(printerInfo);

			var printerSettings = new PrinterSettings()
			{
				OemLayer = LoadOemLayer(printer)
			};

			printerSettings.OemLayer[SettingsKey.make] = printerInfo.Make;
			printerSettings.OemLayer[SettingsKey.model] = printer.Model;

			LoadQualitySettings(printerSettings, printer);
			LoadMaterialSettings(printerSettings, printer);

			printerSettings.ID = printer.Id.ToString();

			printerSettings.UserLayer[SettingsKey.printer_name] = printer.Name ?? "";
			printerSettings.UserLayer[SettingsKey.baud_rate] = printer.BaudRate ?? "";
			printerSettings.UserLayer[SettingsKey.auto_connect] = printer.AutoConnect ? "1" : "0";
			printerSettings.UserLayer[SettingsKey.default_material_presets] = printer.MaterialCollectionIds ?? "";
			printerSettings.UserLayer[SettingsKey.windows_driver] = printer.DriverType ?? "";
			printerSettings.UserLayer[SettingsKey.device_token] = printer.DeviceToken ?? "";
			printerSettings.UserLayer[SettingsKey.device_type] = printer.DeviceType ?? "";

			if (string.IsNullOrEmpty(ProfileManager.Instance.LastProfileID))
			{
				ProfileManager.Instance.SetLastProfile(printer.Id.ToString());
			}

			printerSettings.UserLayer[SettingsKey.active_theme_name] = UserSettings.Instance.get(UserSettingsKey.ActiveThemeName);

			// Import macros from the database
			var allMacros =  Datastore.Instance.dbSQLite.Query<CustomCommands>("SELECT * FROM CustomCommands WHERE PrinterId = " + printer.Id);
			printerSettings.Macros = allMacros.Select(macro => new GCodeMacro()
			{
				GCode = macro.Value.Trim(),
				Name = macro.Name,
				LastModified = macro.DateLastModified
			}).ToList();

			string query = string.Format("SELECT * FROM PrinterSetting WHERE Name = 'PublishBedImage' and PrinterId = {0};", printer.Id);
			var publishBedImage = Datastore.Instance.dbSQLite.Query<PrinterSetting>(query).FirstOrDefault();

			printerSettings.UserLayer[SettingsKey.publish_bed_image] = publishBedImage?.Value == "true" ? "1" : "0";

			// Print leveling
			var printLevelingData = PrintLevelingData.Create(
				printerSettings, 
				printer.PrintLevelingJsonData, 
				printer.PrintLevelingProbePositions);

			printerSettings.UserLayer[SettingsKey.print_leveling_data] = JsonConvert.SerializeObject(printLevelingData);
			printerSettings.UserLayer[SettingsKey.print_leveling_enabled] = printer.DoPrintLeveling ? "true" : "false";

			printerSettings.UserLayer["manual_movement_speeds"] = printer.ManualMovementSpeeds;

			// make sure we clear the one time settings
			printerSettings.OemLayer[SettingsKey.spiral_vase] = "";
			printerSettings.OemLayer[SettingsKey.bottom_clip_amount] = "";
			printerSettings.OemLayer[SettingsKey.layer_to_pause] = "";

			// TODO: Where can we find CalibrationFiiles in the current model?
			//layeredProfile.SetActiveValue(""calibration_files"", ???);

			printerSettings.ID = printer.Id.ToString();

			printerSettings.DocumentVersion = PrinterSettings.LatestVersion;

			printerSettings.Helpers.SetComPort(printer.ComPort);

			printerSettings.Save();
		}
		public static void Reload()
		{
			if (Instance?.Profiles != null)
			{
				// Release event registration
				Instance.Profiles.CollectionChanged -= Profiles_CollectionChanged;
			}

			// Load the profiles document
			if (File.Exists(ProfilesDBPath))
			{
				string json = File.ReadAllText(ProfilesDBPath);
				Instance = JsonConvert.DeserializeObject<ProfileManager>(json);
			}
			else
			{
				Instance = new ProfileManager();
			}

			if (ActiveSliceSettings.Instance?.ID != Instance.LastProfileID)
			{
				Task.Run(async () =>
				{
					// Load or download on a background thread
					var lastProfile = await LoadProfileAsync(Instance.LastProfileID);

					if (MatterControlApplication.IsLoading)
					{
						// Assign on the UI thread
						ActiveSliceSettings.Instance = lastProfile ?? LoadEmptyProfile();
					}
					else
					{
						UiThread.RunOnIdle(() =>
						{
							// Assign on the UI thread
							ActiveSliceSettings.Instance = lastProfile ?? LoadEmptyProfile();
						});
					}
				});
			}

			// In either case, wire up the CollectionChanged event
			Instance.Profiles.CollectionChanged += Profiles_CollectionChanged;
		}