public static void ImportPrinter(Printer printer, ProfileData profileData, string profilePath) { var printerInfo = new PrinterInfo() { Name = printer.Name, Id = printer.Id.ToString() }; profileData.Profiles.Add(printerInfo); var layeredProfile = ActiveSliceSettings.LoadEmptyProfile(); //Load printer settings from database as second layer layeredProfile.OemProfile = new OemProfile(LoadOemLayer(printer)); //Ordering matters - Material presets trump Quality LoadQualitySettings(layeredProfile, printer); LoadMaterialSettings(layeredProfile, printer); string fullProfilePath = Path.Combine(profilePath, printer.Id + ".json"); File.WriteAllText(fullProfilePath, JsonConvert.SerializeObject(layeredProfile, Formatting.Indented)); //GET LEVELING DATA from DB //PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(printer); /* PrintLevelingPlane.Instance.SetPrintLevelingEquation( levelingData.SampledPosition0, levelingData.SampledPosition1, levelingData.SampledPosition2, ActiveSliceSettings.Instance.PrintCenter); */ }
public PrinterSetupStatus(PrinterInfo printer = null) { if (printer == null) { this.ActivePrinter = new PrinterInfo(); this.ActivePrinter.Make = null; this.ActivePrinter.Model = null; this.ActivePrinter.Name = "Default Printer ({0})".FormatWith(ExistingPrinterCount() + 1); this.ActivePrinter.BaudRate = null; this.ActivePrinter.ComPort = null; } else { this.ActivePrinter = printer; } }
internal static bool ImportFromExisting(string settingsFilePath) { if (string.IsNullOrEmpty(settingsFilePath) || !File.Exists(settingsFilePath)) { return false; } string fileName = Path.GetFileNameWithoutExtension(settingsFilePath); var existingPrinterNames = Instance.ActiveProfiles.Select(p => p.Name); var printerInfo = new PrinterInfo { Name = agg_basics.GetNonCollidingName(existingPrinterNames, fileName), ID = Guid.NewGuid().ToString(), Make = "Other", Model = "Other", }; bool importSuccessful = false; string importType = Path.GetExtension(settingsFilePath).ToLower(); switch (importType) { case ProfileManager.ProfileExtension: // Add the Settings as a profile before performing any actions on it to ensure file paths resolve { Instance.Profiles.Add(printerInfo); var printerSettings = PrinterSettings.LoadFile(settingsFilePath); printerSettings.ID = printerInfo.ID; printerSettings.ClearValue(SettingsKey.device_token); printerInfo.DeviceToken = ""; // TODO: Resolve name conflicts printerSettings.Helpers.SetName(printerInfo.Name); if (printerSettings.OemLayer.ContainsKey(SettingsKey.make)) { printerInfo.Make = printerSettings.OemLayer[SettingsKey.make]; } if (printerSettings.OemLayer.ContainsKey(SettingsKey.model)) { printerInfo.Model = printerSettings.OemLayer[SettingsKey.model] ?? "Other"; } printerSettings.Save(); importSuccessful = true; } break; case ".ini": //Scope variables { var settingsToImport = PrinterSettingsLayer.LoadFromIni(settingsFilePath); var printerSettings = new PrinterSettings() { ID = printerInfo.ID, }; bool containsValidSetting = false; printerSettings.OemLayer = new PrinterSettingsLayer(); printerSettings.OemLayer[SettingsKey.make] = "Other"; printerSettings.OemLayer[SettingsKey.model] = "Other"; foreach (var item in settingsToImport) { if (printerSettings.Contains(item.Key)) { containsValidSetting = true; string currentValue = printerSettings.GetValue(item.Key).Trim(); // Compare the value to import to the layer cascade value and only set if different if (currentValue != item.Value) { printerSettings.OemLayer[item.Key] = item.Value; } } } if(containsValidSetting) { printerSettings.UserLayer[SettingsKey.printer_name] = printerInfo.Name; printerSettings.ClearValue(SettingsKey.device_token); printerInfo.DeviceToken = ""; printerInfo.Make = printerSettings.OemLayer[SettingsKey.make] ?? "Other"; printerInfo.Model = printerSettings.OemLayer[SettingsKey.model] ?? "Other"; Instance.Profiles.Add(printerInfo); printerSettings.Helpers.SetName(printerInfo.Name); printerSettings.Save(); importSuccessful = true; } } break; } return importSuccessful; }
public string ProfilePath(PrinterInfo printer) { return Path.Combine(UserProfilesDirectory, printer.ID + ProfileExtension); }
internal void ChangeToAddPrinter() { this.activePrinter = null; ChangeToStep(new SetupStepMakeModelName(this)); }
public PrinterSelectRadioButton(PrinterInfo printer) : base(printer.Name) { this.printer = printer; }
public PrinterActionLink(string text, PrinterInfo printer, int fontSize = 10) : base(text, fontSize) { this.LinkedPrinter = printer; }
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 string ProfilePath(PrinterInfo printer) { return Path.Combine(ProfileManager.ProfilesPath, printer.ID + ProfileExtension); }