Importing a printer/settings from a file will now notify the user if the file contains no valid user settings
- ImportFomEisting now returns a bool of whether or not it succeeded - PrinterSettings now has a Contains method - merging or importing quality/material settings check to make sure at least one setting was importable and notifies user if not
This commit is contained in:
parent
c78be029c6
commit
bdf3e8f2a5
4 changed files with 104 additions and 40 deletions
|
|
@ -431,11 +431,18 @@ namespace MatterHackers.MatterControl
|
||||||
{
|
{
|
||||||
if(newPrinterButton.Checked)
|
if(newPrinterButton.Checked)
|
||||||
{
|
{
|
||||||
ProfileManager.ImportFromExisting(settingsFilePath);
|
if(ProfileManager.ImportFromExisting(settingsFilePath))
|
||||||
WizardWindow.ChangeToPage(new ImportSucceeded(importPrinterSuccessMessage.FormatWith(Path.GetFileNameWithoutExtension(settingsFilePath)))
|
|
||||||
{
|
{
|
||||||
WizardWindow = this.WizardWindow,
|
WizardWindow.ChangeToPage(new ImportSucceeded(importPrinterSuccessMessage.FormatWith(Path.GetFileNameWithoutExtension(settingsFilePath)))
|
||||||
});
|
{
|
||||||
|
WizardWindow = this.WizardWindow,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
displayFailedToImportMessage(settingsFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(mergeButton.Checked)
|
else if(mergeButton.Checked)
|
||||||
{
|
{
|
||||||
|
|
@ -487,6 +494,7 @@ namespace MatterHackers.MatterControl
|
||||||
var settingsToImport = PrinterSettingsLayer.LoadFromIni(settingsFilePath);
|
var settingsToImport = PrinterSettingsLayer.LoadFromIni(settingsFilePath);
|
||||||
string layerHeight;
|
string layerHeight;
|
||||||
|
|
||||||
|
bool containsValidSetting = false;
|
||||||
bool isSlic3r = importType == ".slice" || settingsToImport.TryGetValue(SettingsKey.layer_height, out layerHeight);
|
bool isSlic3r = importType == ".slice" || settingsToImport.TryGetValue(SettingsKey.layer_height, out layerHeight);
|
||||||
if (isSlic3r)
|
if (isSlic3r)
|
||||||
{
|
{
|
||||||
|
|
@ -502,35 +510,49 @@ namespace MatterHackers.MatterControl
|
||||||
|
|
||||||
foreach (var item in settingsToImport)
|
foreach (var item in settingsToImport)
|
||||||
{
|
{
|
||||||
string currentValue = ActiveSliceSettings.Instance.GetValue(item.Key, baseAndOEMCascade).Trim();
|
if(ActiveSliceSettings.Instance.Contains(item.Key))
|
||||||
// Compare the value to import to the layer cascade value and only set if different
|
|
||||||
if (currentValue != item.Value)
|
|
||||||
{
|
{
|
||||||
newLayer[item.Key] = item.Value;
|
containsValidSetting = true;
|
||||||
|
string currentValue = ActiveSliceSettings.Instance.GetValue(item.Key, baseAndOEMCascade).Trim();
|
||||||
|
// Compare the value to import to the layer cascade value and only set if different
|
||||||
|
if (currentValue != item.Value)
|
||||||
|
{
|
||||||
|
newLayer[item.Key] = item.Value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newMaterialPresetButton.Checked)
|
if(containsValidSetting)
|
||||||
{
|
{
|
||||||
ActiveSliceSettings.Instance.MaterialLayers.Add(newLayer);
|
if (newMaterialPresetButton.Checked)
|
||||||
|
{
|
||||||
|
ActiveSliceSettings.Instance.MaterialLayers.Add(newLayer);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ActiveSliceSettings.Instance.QualityLayers.Add(newLayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
ActiveSliceSettings.Instance.Save();
|
||||||
|
|
||||||
|
WizardWindow.ChangeToPage(new ImportSucceeded(importSettingSuccessMessage.FormatWith(Path.GetFileNameWithoutExtension(settingsFilePath), sectionName))
|
||||||
|
{
|
||||||
|
WizardWindow = this.WizardWindow,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ActiveSliceSettings.Instance.QualityLayers.Add(newLayer);
|
displayFailedToImportMessage(settingsFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
ActiveSliceSettings.Instance.Save();
|
|
||||||
|
|
||||||
WizardWindow.ChangeToPage(new ImportSucceeded(importSettingSuccessMessage.FormatWith(Path.GetFileNameWithoutExtension(settingsFilePath), sectionName))
|
|
||||||
{
|
|
||||||
WizardWindow = this.WizardWindow,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
displayFailedToImportMessage(settingsFilePath);
|
||||||
// looks like a cura file
|
// looks like a cura file
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
throw new NotImplementedException("need to import from 'cure.ini' files");
|
//throw new NotImplementedException("need to import from 'cure.ini' files");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -562,23 +584,35 @@ namespace MatterHackers.MatterControl
|
||||||
string layerHeight;
|
string layerHeight;
|
||||||
|
|
||||||
bool isSlic3r = settingsToImport.TryGetValue(SettingsKey.layer_height, out layerHeight);
|
bool isSlic3r = settingsToImport.TryGetValue(SettingsKey.layer_height, out layerHeight);
|
||||||
|
bool containsValidSetting = false;
|
||||||
//if (isSlic3r)
|
//if (isSlic3r)
|
||||||
{
|
{
|
||||||
var activeSettings = ActiveSliceSettings.Instance;
|
var activeSettings = ActiveSliceSettings.Instance;
|
||||||
|
|
||||||
foreach (var item in settingsToImport)
|
foreach (var item in settingsToImport)
|
||||||
{
|
{
|
||||||
// Compare the value to import to the layer cascade value and only set if different
|
if(activeSettings.Contains(item.Key))
|
||||||
string currentValue = activeSettings.GetValue(item.Key, null).Trim();
|
|
||||||
if (currentValue != item.Value)
|
|
||||||
{
|
{
|
||||||
activeSettings.UserLayer[item.Key] = item.Value;
|
containsValidSetting = true;
|
||||||
|
string currentValue = activeSettings.GetValue(item.Key, null).Trim();
|
||||||
|
// Compare the value to import to the layer cascade value and only set if different
|
||||||
|
if (currentValue != item.Value)
|
||||||
|
{
|
||||||
|
activeSettings.UserLayer[item.Key] = item.Value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if(containsValidSetting)
|
||||||
|
{
|
||||||
|
activeSettings.Save();
|
||||||
|
|
||||||
activeSettings.Save();
|
UiThread.RunOnIdle(ApplicationController.Instance.ReloadAdvancedControlsPanel);
|
||||||
|
}
|
||||||
UiThread.RunOnIdle(ApplicationController.Instance.ReloadAdvancedControlsPanel);
|
else
|
||||||
|
{
|
||||||
|
displayFailedToImportMessage(settingsFilePath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//else
|
//else
|
||||||
{
|
{
|
||||||
|
|
@ -598,5 +632,10 @@ namespace MatterHackers.MatterControl
|
||||||
}
|
}
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void displayFailedToImportMessage(string settingsFilePath)
|
||||||
|
{
|
||||||
|
StyledMessageBox.ShowMessageBox(null, "Oops! Settings file '{0}' did not contain any settings we could import.".Localize().FormatWith(Path.GetFileName(settingsFilePath)), "Unable to Import".Localize());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -371,6 +371,23 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool Contains(string sliceSetting, IEnumerable<PrinterSettingsLayer> layerCascade = null)
|
||||||
|
{
|
||||||
|
if (layerCascade == null)
|
||||||
|
{
|
||||||
|
layerCascade = defaultLayerCascade;
|
||||||
|
}
|
||||||
|
foreach (PrinterSettingsLayer layer in layerCascade)
|
||||||
|
{
|
||||||
|
string value;
|
||||||
|
if (layer.TryGetValue(sliceSetting, out value))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public PrinterSettingsLayer BaseLayer
|
public PrinterSettingsLayer BaseLayer
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -262,11 +262,11 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void ImportFromExisting(string settingsFilePath)
|
internal static bool ImportFromExisting(string settingsFilePath)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(settingsFilePath) || !File.Exists(settingsFilePath))
|
if (string.IsNullOrEmpty(settingsFilePath) || !File.Exists(settingsFilePath))
|
||||||
{
|
{
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var printerInfo = new PrinterInfo
|
var printerInfo = new PrinterInfo
|
||||||
|
|
@ -274,7 +274,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||||
Name = Path.GetFileNameWithoutExtension(settingsFilePath),
|
Name = Path.GetFileNameWithoutExtension(settingsFilePath),
|
||||||
ID = Guid.NewGuid().ToString()
|
ID = Guid.NewGuid().ToString()
|
||||||
};
|
};
|
||||||
|
bool importSuccessful = false;
|
||||||
string importType = Path.GetExtension(settingsFilePath).ToLower();
|
string importType = Path.GetExtension(settingsFilePath).ToLower();
|
||||||
switch (importType)
|
switch (importType)
|
||||||
{
|
{
|
||||||
|
|
@ -290,28 +290,33 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||||
Instance.Profiles.Add(printerInfo);
|
Instance.Profiles.Add(printerInfo);
|
||||||
|
|
||||||
profile.Save();
|
profile.Save();
|
||||||
|
importSuccessful = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ".ini":
|
case ".ini":
|
||||||
var settingsToImport = PrinterSettingsLayer.LoadFromIni(settingsFilePath);
|
var settingsToImport = PrinterSettingsLayer.LoadFromIni(settingsFilePath);
|
||||||
|
//Other import paths validate that this is a slicer or MC ini file via checking if layer_height is a setting
|
||||||
var layeredProfile = new PrinterSettings()
|
if(settingsToImport.ContainsKey(SettingsKey.layer_height))
|
||||||
{
|
{
|
||||||
ID = printerInfo.ID,
|
var layeredProfile = new PrinterSettings()
|
||||||
OemLayer = settingsToImport
|
{
|
||||||
};
|
ID = printerInfo.ID,
|
||||||
|
OemLayer = settingsToImport
|
||||||
|
};
|
||||||
|
|
||||||
// TODO: Resolve name conflicts
|
// TODO: Resolve name conflicts
|
||||||
layeredProfile.UserLayer[SettingsKey.printer_name.ToString()] = printerInfo.Name;
|
layeredProfile.UserLayer[SettingsKey.printer_name.ToString()] = printerInfo.Name;
|
||||||
|
|
||||||
layeredProfile.ClearValue(SettingsKey.device_token);
|
layeredProfile.ClearValue(SettingsKey.device_token);
|
||||||
printerInfo.DeviceToken = "";
|
printerInfo.DeviceToken = "";
|
||||||
Instance.Profiles.Add(printerInfo);
|
Instance.Profiles.Add(printerInfo);
|
||||||
|
|
||||||
layeredProfile.Save();
|
|
||||||
|
|
||||||
|
layeredProfile.Save();
|
||||||
|
importSuccessful = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
return importSuccessful;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static async void AcquireNewProfile(string make, string model, string printerName)
|
internal static async void AcquireNewProfile(string make, string model, string printerName)
|
||||||
|
|
|
||||||
|
|
@ -5311,3 +5311,6 @@ Translated:There is a required update available.
|
||||||
English:Import Printer
|
English:Import Printer
|
||||||
Translated:Import Printer
|
Translated:Import Printer
|
||||||
|
|
||||||
|
English:Oops! Settings file '{0}' did not contain any settings we could import.
|
||||||
|
Translated:Oops! Settings file '{0}' did not contain any settings we could import.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue