can merge from .printer into current.
This commit is contained in:
parent
e74e0c1108
commit
93530a64c1
1 changed files with 119 additions and 63 deletions
|
|
@ -42,18 +42,18 @@ namespace MatterHackers.MatterControl
|
|||
{
|
||||
public class SelectPartsOfPrinterToImport : WizardPage
|
||||
{
|
||||
static string importMessage = "Select the parts of the printer file that you would like to merge into your current profile.".Localize();
|
||||
static string importMessage = "Select what you would like to merge into your current profile.".Localize();
|
||||
string settingsFilePath;
|
||||
List<CheckBox> qualityChecks = new List<CheckBox>();
|
||||
List<CheckBox> materialChecks = new List<CheckBox>();
|
||||
PrinterSettings settingsToImport;
|
||||
int selectedMaterial = -1;
|
||||
int selectedQuality = -1;
|
||||
|
||||
public SelectPartsOfPrinterToImport(string settingsFilePath) :
|
||||
base(unlocalizedTextForTitle: "Import Wizard")
|
||||
{
|
||||
settingsToImport = PrinterSettings.LoadFile(settingsFilePath);
|
||||
|
||||
this.headerLabel.Text = "Select Parts to Import".Localize();
|
||||
this.headerLabel.Text = "Select What to Import".Localize();
|
||||
|
||||
this.settingsFilePath = settingsFilePath;
|
||||
|
||||
|
|
@ -82,14 +82,14 @@ namespace MatterHackers.MatterControl
|
|||
Margin = new BorderDouble(0, 3, 0, 10),
|
||||
});
|
||||
|
||||
var mainProfileCheckBox = new CheckBox("Printer Profile")
|
||||
var mainProfileRadioButton = new RadioButton("Printer Profile")
|
||||
{
|
||||
TextColor = ActiveTheme.Instance.PrimaryTextColor,
|
||||
Margin = new BorderDouble(5, 0),
|
||||
HAnchor = HAnchor.ParentLeft,
|
||||
Checked = true,
|
||||
};
|
||||
container.AddChild(mainProfileCheckBox);
|
||||
container.AddChild(mainProfileRadioButton);
|
||||
|
||||
if (settingsToImport.QualityLayers.Count > 0)
|
||||
{
|
||||
|
|
@ -99,15 +99,31 @@ namespace MatterHackers.MatterControl
|
|||
Margin = new BorderDouble(0, 3, 0, 15),
|
||||
});
|
||||
|
||||
int buttonIndex = 0;
|
||||
foreach (var qualitySetting in settingsToImport.QualityLayers)
|
||||
{
|
||||
qualityChecks.Add(new CheckBox(qualitySetting.Name)
|
||||
RadioButton qualityButton = new RadioButton(qualitySetting.Name)
|
||||
{
|
||||
TextColor = ActiveTheme.Instance.PrimaryTextColor,
|
||||
Margin = new BorderDouble(5, 0, 0, 0),
|
||||
HAnchor = HAnchor.ParentLeft,
|
||||
});
|
||||
container.AddChild(qualityChecks[qualityChecks.Count - 1]);
|
||||
};
|
||||
container.AddChild(qualityButton);
|
||||
|
||||
int localButtonIndex = buttonIndex;
|
||||
qualityButton.CheckedStateChanged += (s, e) =>
|
||||
{
|
||||
if (qualityButton.Checked)
|
||||
{
|
||||
selectedQuality = localButtonIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
selectedQuality = -1;
|
||||
}
|
||||
};
|
||||
|
||||
buttonIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -119,34 +135,97 @@ namespace MatterHackers.MatterControl
|
|||
Margin = new BorderDouble(0, 3, 0, 15),
|
||||
});
|
||||
|
||||
int buttonIndex = 0;
|
||||
foreach (var materialSetting in settingsToImport.MaterialLayers)
|
||||
{
|
||||
materialChecks.Add(new CheckBox(materialSetting.Name)
|
||||
RadioButton materialButton = new RadioButton(materialSetting.Name)
|
||||
{
|
||||
TextColor = ActiveTheme.Instance.PrimaryTextColor,
|
||||
Margin = new BorderDouble(5, 0),
|
||||
HAnchor = HAnchor.ParentLeft,
|
||||
});
|
||||
container.AddChild(materialChecks[materialChecks.Count - 1]);
|
||||
};
|
||||
|
||||
container.AddChild(materialButton);
|
||||
|
||||
int localButtonIndex = buttonIndex;
|
||||
materialButton.CheckedStateChanged += (s, e) =>
|
||||
{
|
||||
if (materialButton.Checked)
|
||||
{
|
||||
selectedMaterial = localButtonIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
selectedMaterial = -1;
|
||||
}
|
||||
};
|
||||
|
||||
buttonIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
var mergeButton = textImageButtonFactory.Generate("Merge".Localize());
|
||||
mergeButton.Name = "Merge Profile";
|
||||
mergeButton.Click += (s, e) =>
|
||||
mergeButton.Click += (s,e) => UiThread.RunOnIdle(Merge);
|
||||
footerRow.AddChild(mergeButton);
|
||||
|
||||
footerRow.AddChild(new HorizontalSpacer());
|
||||
footerRow.AddChild(cancelButton);
|
||||
|
||||
if(settingsToImport.QualityLayers.Count == 0 && settingsToImport.MaterialLayers.Count == 0)
|
||||
{
|
||||
UiThread.RunOnIdle(() => WizardWindow?.Close());
|
||||
// Only main setting so don't ask what to merge just do it.
|
||||
UiThread.RunOnIdle(Merge);
|
||||
}
|
||||
}
|
||||
|
||||
var activeSettings = ActiveSliceSettings.Instance;
|
||||
static string importPrinterSuccessMessage = "Settings have been merged into your current printer.".Localize();
|
||||
|
||||
var layerCascade = new List<PrinterSettingsLayer>
|
||||
HashSet<string> skipKeys = new HashSet<string>
|
||||
{
|
||||
"layer_name",
|
||||
"layer_id",
|
||||
};
|
||||
|
||||
void Merge()
|
||||
{
|
||||
var activeSettings = ActiveSliceSettings.Instance;
|
||||
|
||||
var layerCascade = new List<PrinterSettingsLayer>
|
||||
{
|
||||
ActiveSliceSettings.Instance.OemLayer,
|
||||
ActiveSliceSettings.Instance.BaseLayer,
|
||||
ActiveSliceSettings.Instance.UserLayer,
|
||||
};
|
||||
|
||||
PrinterSettingsLayer layerToImport = settingsToImport.BaseLayer;
|
||||
if (selectedMaterial > -1)
|
||||
{
|
||||
var material = settingsToImport.MaterialLayers[selectedMaterial];
|
||||
|
||||
foreach(var item in material)
|
||||
{
|
||||
ActiveSliceSettings.Instance.OemLayer,
|
||||
ActiveSliceSettings.Instance.BaseLayer,
|
||||
ActiveSliceSettings.Instance.UserLayer,
|
||||
};
|
||||
if (!skipKeys.Contains(item.Key))
|
||||
{
|
||||
activeSettings.UserLayer[item.Key] = item.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (selectedQuality > -1)
|
||||
{
|
||||
var quality = settingsToImport.QualityLayers[selectedQuality];
|
||||
|
||||
foreach (var item in settingsToImport.BaseLayer)
|
||||
foreach (var item in quality)
|
||||
{
|
||||
if (!skipKeys.Contains(item.Key))
|
||||
{
|
||||
activeSettings.UserLayer[item.Key] = item.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var item in layerToImport)
|
||||
{
|
||||
// Compare the value to import to the layer cascade value and only set if different
|
||||
string currentValue = activeSettings.GetValue(item.Key, layerCascade).Trim();
|
||||
|
|
@ -156,28 +235,27 @@ namespace MatterHackers.MatterControl
|
|||
activeSettings.UserLayer[item.Key] = item.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
activeSettings.SaveChanges();
|
||||
activeSettings.SaveChanges();
|
||||
|
||||
UiThread.RunOnIdle(ApplicationController.Instance.ReloadAdvancedControlsPanel);
|
||||
};
|
||||
footerRow.AddChild(mergeButton);
|
||||
UiThread.RunOnIdle(ApplicationController.Instance.ReloadAdvancedControlsPanel);
|
||||
|
||||
footerRow.AddChild(new HorizontalSpacer());
|
||||
footerRow.AddChild(cancelButton);
|
||||
ProfileManager.ImportFromExisting(settingsFilePath);
|
||||
WizardWindow.ChangeToPage(new ImportSucceeded(importPrinterSuccessMessage.FormatWith(Path.GetFileNameWithoutExtension(settingsFilePath)))
|
||||
{
|
||||
WizardWindow = this.WizardWindow,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class ImportToPrinterSucceeded : WizardPage
|
||||
public class ImportSucceeded : WizardPage
|
||||
{
|
||||
static string successMessage = "You have successfully imported a new printer profile. You can find '{0}' in your list of available printers.".Localize();
|
||||
public ImportToPrinterSucceeded(string newProfileName) :
|
||||
public ImportSucceeded(string successMessage) :
|
||||
base("Done", "Import Wizard")
|
||||
{
|
||||
this.headerLabel.Text = "Import Successful".Localize();
|
||||
|
||||
successMessage = successMessage.FormatWith(newProfileName);
|
||||
|
||||
var container = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
||||
{
|
||||
HAnchor = HAnchor.ParentLeftRight,
|
||||
|
|
@ -192,34 +270,6 @@ namespace MatterHackers.MatterControl
|
|||
}
|
||||
}
|
||||
|
||||
public class ImportToSettingSucceeded : WizardPage
|
||||
{
|
||||
static string successMessage = "You have successfully imported a new {0} setting. You can find '{1}' in your list of {2} settings.".Localize();
|
||||
string settingType;
|
||||
|
||||
public ImportToSettingSucceeded(string newProfileName, string settingType) :
|
||||
base("Done", "Import Wizard")
|
||||
{
|
||||
this.settingType = settingType;
|
||||
this.headerLabel.Text = "Import Successful".Localize();
|
||||
|
||||
successMessage = successMessage.FormatWith(settingType, newProfileName, settingType);
|
||||
|
||||
var container = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
||||
{
|
||||
HAnchor = HAnchor.ParentLeftRight,
|
||||
};
|
||||
contentRow.AddChild(container);
|
||||
|
||||
var successMessageWidget = new WrappedTextWidget(successMessage, 10, textColor: ActiveTheme.Instance.PrimaryTextColor);
|
||||
container.AddChild(successMessageWidget);
|
||||
|
||||
footerRow.AddChild(new HorizontalSpacer());
|
||||
footerRow.AddChild(cancelButton);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class ImportSettingsPage : WizardPage
|
||||
{
|
||||
RadioButton newPrinterButton;
|
||||
|
|
@ -344,12 +394,18 @@ namespace MatterHackers.MatterControl
|
|||
return container;
|
||||
}
|
||||
|
||||
static string importPrinterSuccessMessage = "You have successfully imported a new printer profile. You can find '{0}' in your list of available printers.".Localize();
|
||||
static string importSettingSuccessMessage = "You have successfully imported a new {0} setting. You can find '{1}' in your list of {2} settings.".Localize();
|
||||
|
||||
private void ImportSettingsFile(string settingsFilePath)
|
||||
{
|
||||
if(newPrinterButton.Checked)
|
||||
{
|
||||
ProfileManager.ImportFromExisting(settingsFilePath);
|
||||
WizardWindow.ChangeToPage(new ImportToPrinterSucceeded(Path.GetFileNameWithoutExtension(settingsFilePath)));
|
||||
WizardWindow.ChangeToPage(new ImportSucceeded(importPrinterSuccessMessage.FormatWith(Path.GetFileNameWithoutExtension(settingsFilePath)))
|
||||
{
|
||||
WizardWindow = this.WizardWindow,
|
||||
});
|
||||
}
|
||||
else if(mergeButton.Checked)
|
||||
{
|
||||
|
|
@ -358,7 +414,7 @@ namespace MatterHackers.MatterControl
|
|||
else if(newQualityPresetButton.Checked)
|
||||
{
|
||||
ImportToPreset(settingsFilePath);
|
||||
WizardWindow.ChangeToPage(new ImportToSettingSucceeded(Path.GetFileNameWithoutExtension(settingsFilePath), "Quality".Localize())
|
||||
WizardWindow.ChangeToPage(new ImportSucceeded(importSettingSuccessMessage.FormatWith(Path.GetFileNameWithoutExtension(settingsFilePath), "Quality".Localize()))
|
||||
{
|
||||
WizardWindow = this.WizardWindow,
|
||||
});
|
||||
|
|
@ -366,7 +422,7 @@ namespace MatterHackers.MatterControl
|
|||
else if(newMaterialPresetButton.Checked)
|
||||
{
|
||||
ImportToPreset(settingsFilePath);
|
||||
WizardWindow.ChangeToPage(new ImportToSettingSucceeded(Path.GetFileNameWithoutExtension(settingsFilePath), "Material".Localize())
|
||||
WizardWindow.ChangeToPage(new ImportSucceeded(importSettingSuccessMessage.FormatWith(Path.GetFileNameWithoutExtension(settingsFilePath), "Material".Localize()))
|
||||
{
|
||||
WizardWindow = this.WizardWindow,
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue