New Import and Export for RepetierEeprom Window.
This commit is contained in:
parent
ba01f22dc5
commit
9d5c9c0181
6 changed files with 178 additions and 63 deletions
|
|
@ -145,7 +145,6 @@ namespace MatterHackers.MatterControl
|
|||
saveParams.ActionButtonLabel = "Export";
|
||||
FileDialog.SaveFileDialog(saveParams, delegate(SaveFileDialogParams saveParam)
|
||||
{
|
||||
|
||||
string extension = Path.GetExtension(saveParam.FileName);
|
||||
if (extension == "")
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,8 +27,10 @@ of the authors and should not be interpreted as representing official policies,
|
|||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.MatterControl.PrinterCommunication;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace MatterHackers.MatterControl.EeProm
|
||||
{
|
||||
|
|
@ -37,7 +39,7 @@ namespace MatterHackers.MatterControl.EeProm
|
|||
public string description = "";
|
||||
public int type;
|
||||
public int position;
|
||||
private string val = "";
|
||||
public string value { get; private set; } = "";
|
||||
private bool changed = false;
|
||||
|
||||
public EePromRepetierParameter(string line)
|
||||
|
|
@ -54,7 +56,7 @@ namespace MatterHackers.MatterControl.EeProm
|
|||
{
|
||||
int.TryParse(lines[0], out type);
|
||||
int.TryParse(lines[1], out position);
|
||||
val = lines[2];
|
||||
value = lines[2];
|
||||
int startPos = 7 + lines[0].Length + lines[1].Length + lines[2].Length;
|
||||
if (line.Length > startPos)
|
||||
{
|
||||
|
|
@ -65,7 +67,7 @@ namespace MatterHackers.MatterControl.EeProm
|
|||
}
|
||||
}
|
||||
|
||||
public void save()
|
||||
public void Save()
|
||||
{
|
||||
if (!changed)
|
||||
{
|
||||
|
|
@ -73,8 +75,8 @@ namespace MatterHackers.MatterControl.EeProm
|
|||
}
|
||||
|
||||
string cmd = "M206 T" + type + " P" + position + " ";
|
||||
if (type == 3) cmd += "X" + val;
|
||||
else cmd += "S" + val;
|
||||
if (type == 3) cmd += "X" + value;
|
||||
else cmd += "S" + value;
|
||||
PrinterConnectionAndCommunication.Instance.SendLineToPrinterNow(cmd);
|
||||
changed = false;
|
||||
}
|
||||
|
|
@ -87,14 +89,19 @@ namespace MatterHackers.MatterControl.EeProm
|
|||
|
||||
public string Value
|
||||
{
|
||||
get { return val; }
|
||||
get { return value; }
|
||||
set
|
||||
{
|
||||
value = value.Replace(',', '.').Trim();
|
||||
if (val.Equals(value)) return;
|
||||
val = value;
|
||||
changed = true;
|
||||
if (this.value.Equals(value)) return;
|
||||
this.value = value;
|
||||
MarkChanged();
|
||||
}
|
||||
}
|
||||
|
||||
internal void MarkChanged()
|
||||
{
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -27,10 +27,12 @@ of the authors and should not be interpreted as representing official policies,
|
|||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.MatterControl.PrinterCommunication;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace MatterHackers.MatterControl.EeProm
|
||||
{
|
||||
|
|
@ -61,7 +63,7 @@ namespace MatterHackers.MatterControl.EeProm
|
|||
{
|
||||
foreach (EePromRepetierParameter p in eePromSettingsList.Values)
|
||||
{
|
||||
p.save();
|
||||
p.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -100,5 +102,52 @@ namespace MatterHackers.MatterControl.EeProm
|
|||
{
|
||||
PrinterConnectionAndCommunication.Instance.SendLineToPrinterNow("M205");
|
||||
}
|
||||
|
||||
internal void Export(string fileName)
|
||||
{
|
||||
FileStream fs = new FileStream(fileName, FileMode.Create);
|
||||
StreamWriter sw = new System.IO.StreamWriter(fs);
|
||||
|
||||
lock (eePromSettingsList)
|
||||
{
|
||||
foreach (EePromRepetierParameter p in eePromSettingsList.Values)
|
||||
{
|
||||
string data = "{0}|{1}".FormatWith(p.description, p.value);
|
||||
sw.WriteLine(data);
|
||||
}
|
||||
}
|
||||
|
||||
sw.Close();
|
||||
}
|
||||
|
||||
internal void Import(string fileName)
|
||||
{
|
||||
// read all the lines
|
||||
string[] allLines = File.ReadAllLines(fileName);
|
||||
// find all the descriptions we can
|
||||
foreach (string line in allLines)
|
||||
{
|
||||
if (line.Contains("|"))
|
||||
{
|
||||
string[] descriptionValue = line.Split('|');
|
||||
if (descriptionValue.Length == 2)
|
||||
{
|
||||
foreach (KeyValuePair<int, EePromRepetierParameter> keyValue in eePromSettingsList)
|
||||
{
|
||||
if (keyValue.Value.Description == descriptionValue[0])
|
||||
{
|
||||
if(keyValue.Value.Value != descriptionValue[1])
|
||||
{
|
||||
// push in the value
|
||||
keyValue.Value.Value = descriptionValue[1];
|
||||
keyValue.Value.MarkChanged();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -46,9 +46,6 @@ namespace MatterHackers.MatterControl.EeProm
|
|||
|
||||
private event EventHandler unregisterEvents;
|
||||
|
||||
private Button buttonCancel;
|
||||
private Button buttonSave;
|
||||
|
||||
public EePromRepetierWindow()
|
||||
: base(540, 480)
|
||||
{
|
||||
|
|
@ -61,20 +58,20 @@ namespace MatterHackers.MatterControl.EeProm
|
|||
topToBottom.VAnchor = Agg.UI.VAnchor.Max_FitToChildren_ParentHeight;
|
||||
topToBottom.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
|
||||
topToBottom.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
|
||||
topToBottom.Padding = new BorderDouble(3, 0);
|
||||
topToBottom.Padding = new BorderDouble(3, 0) * TextWidget.GlobalPointSizeScaleRatio;
|
||||
|
||||
FlowLayoutWidget row = new FlowLayoutWidget();
|
||||
row.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
|
||||
row.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
|
||||
GuiWidget descriptionWidget = AddDescription(LocalizedString.Get("Description"));
|
||||
descriptionWidget.Margin = new BorderDouble(left: 3);
|
||||
descriptionWidget.Margin = new BorderDouble(left: 3) * TextWidget.GlobalPointSizeScaleRatio;
|
||||
row.AddChild(descriptionWidget);
|
||||
|
||||
CreateSpacer(row);
|
||||
|
||||
GuiWidget valueText = new TextWidget(LocalizedString.Get("Value"), textColor: ActiveTheme.Instance.PrimaryTextColor);
|
||||
valueText.VAnchor = Agg.UI.VAnchor.ParentCenter;
|
||||
valueText.Margin = new BorderDouble(left: 5, right: 60);
|
||||
valueText.Margin = new BorderDouble(left: 5, right: 60) * TextWidget.GlobalPointSizeScaleRatio;
|
||||
row.AddChild(valueText);
|
||||
topToBottom.AddChild(row);
|
||||
|
||||
|
|
@ -94,15 +91,96 @@ namespace MatterHackers.MatterControl.EeProm
|
|||
FlowLayoutWidget buttonBar = new FlowLayoutWidget();
|
||||
buttonBar.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth;
|
||||
buttonBar.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
|
||||
buttonSave = textImageButtonFactory.Generate(LocalizedString.Get("Save To EEPROM"));
|
||||
buttonSave.Margin = new BorderDouble(0, 3);
|
||||
buttonBar.AddChild(buttonSave);
|
||||
|
||||
// put in the save button
|
||||
{
|
||||
Button buttonSave = textImageButtonFactory.Generate("Save To EEPROM".Localize());
|
||||
buttonSave.Margin = new BorderDouble(0, 3) * TextWidget.GlobalPointSizeScaleRatio;
|
||||
buttonSave.Click += (sender, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
currentEePromSettings.Save();
|
||||
currentEePromSettings.Clear();
|
||||
currentEePromSettings.eventAdded -= NewSettingReadFromPrinter;
|
||||
Close();
|
||||
});
|
||||
};
|
||||
|
||||
buttonBar.AddChild(buttonSave);
|
||||
}
|
||||
|
||||
CreateSpacer(buttonBar);
|
||||
|
||||
buttonCancel = textImageButtonFactory.Generate(LocalizedString.Get("Cancel"));
|
||||
buttonCancel.Margin = new BorderDouble(3);
|
||||
buttonBar.AddChild(buttonCancel);
|
||||
// put in the import button
|
||||
{
|
||||
Button buttonImport = textImageButtonFactory.Generate("Import".Localize() + "...");
|
||||
buttonImport.Margin = new BorderDouble(0, 3) * TextWidget.GlobalPointSizeScaleRatio;
|
||||
buttonImport.Click += (sender, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
FileDialog.OpenFileDialog(
|
||||
new OpenFileDialogParams("EEPROM Settings" + "|*.ini")
|
||||
{
|
||||
ActionButtonLabel = "Import EEPROM Settings".Localize(),
|
||||
Title = "Import EEPROM".Localize(),
|
||||
},
|
||||
(openParams) =>
|
||||
{
|
||||
if (openParams.FileName != null)
|
||||
{
|
||||
currentEePromSettings.Import(openParams.FileName);
|
||||
RebuildUi();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
buttonBar.AddChild(buttonImport);
|
||||
}
|
||||
|
||||
// put in the export button
|
||||
{
|
||||
Button buttonExport = textImageButtonFactory.Generate("Export".Localize() + "...");
|
||||
buttonExport.Margin = new BorderDouble(0, 3) * TextWidget.GlobalPointSizeScaleRatio;
|
||||
buttonExport.Click += (sender, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
FileDialog.SaveFileDialog(
|
||||
new SaveFileDialogParams("EEPROM Settings" + "|*.ini")
|
||||
{
|
||||
ActionButtonLabel = "Export EEPROM Settings".Localize(),
|
||||
Title = "Export EEPROM".Localize(),
|
||||
FileName = "eeprom_settings.ini"
|
||||
},
|
||||
(saveParams) =>
|
||||
{
|
||||
if (saveParams.FileName != null)
|
||||
{
|
||||
currentEePromSettings.Export(saveParams.FileName);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
buttonBar.AddChild(buttonExport);
|
||||
}
|
||||
|
||||
// put in the cancel button
|
||||
{
|
||||
Button buttonCancel = textImageButtonFactory.Generate("Close".Localize());
|
||||
buttonCancel.Margin = new BorderDouble(10, 3, 0, 3) * TextWidget.GlobalPointSizeScaleRatio;
|
||||
buttonCancel.Click += (sender, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
currentEePromSettings.Clear();
|
||||
currentEePromSettings.eventAdded -= NewSettingReadFromPrinter;
|
||||
Close();
|
||||
});
|
||||
};
|
||||
buttonBar.AddChild(buttonCancel);
|
||||
}
|
||||
|
||||
topToBottom.AddChild(buttonBar);
|
||||
|
||||
|
|
@ -114,7 +192,7 @@ namespace MatterHackers.MatterControl.EeProm
|
|||
this.AddChild(topToBottom);
|
||||
#endif
|
||||
|
||||
translate();
|
||||
Title = LocalizedString.Get("Firmware EEPROM Settings");
|
||||
|
||||
ShowAsSystemWindow();
|
||||
|
||||
|
|
@ -158,16 +236,6 @@ namespace MatterHackers.MatterControl.EeProm
|
|||
base.OnClosed(e);
|
||||
}
|
||||
|
||||
public void translate()
|
||||
{
|
||||
Title = LocalizedString.Get("Firmware EEPROM Settings");
|
||||
buttonCancel.Text = LocalizedString.Get("Close");
|
||||
buttonCancel.Click += buttonAbort_Click;
|
||||
|
||||
buttonSave.Text = LocalizedString.Get("Save to EEPROM");
|
||||
buttonSave.Click += buttonSave_Click;
|
||||
}
|
||||
|
||||
bool waitingForUiUpdate = false;
|
||||
private void NewSettingReadFromPrinter(object sender, EventArgs e)
|
||||
{
|
||||
|
|
@ -177,14 +245,14 @@ namespace MatterHackers.MatterControl.EeProm
|
|||
if (!waitingForUiUpdate)
|
||||
{
|
||||
waitingForUiUpdate = true;
|
||||
UiThread.RunOnIdle(AddItemToUi, 1);
|
||||
UiThread.RunOnIdle(RebuildUi, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int currentTabIndex = 0;
|
||||
|
||||
private void AddItemToUi()
|
||||
private void RebuildUi()
|
||||
{
|
||||
List<EePromRepetierParameter> tempList = new List<EePromRepetierParameter>();
|
||||
lock (currentEePromSettings.eePromSettingsList)
|
||||
|
|
@ -195,6 +263,8 @@ namespace MatterHackers.MatterControl.EeProm
|
|||
}
|
||||
}
|
||||
|
||||
settingsColmun.CloseAllChildren();
|
||||
|
||||
foreach (EePromRepetierParameter newSetting in tempList)
|
||||
{
|
||||
if (newSetting != null)
|
||||
|
|
@ -202,7 +272,7 @@ namespace MatterHackers.MatterControl.EeProm
|
|||
FlowLayoutWidget row = new FlowLayoutWidget();
|
||||
row.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth;
|
||||
row.AddChild(AddDescription(newSetting.Description));
|
||||
row.Padding = new BorderDouble(5, 0);
|
||||
row.Padding = new BorderDouble(5, 0) * TextWidget.GlobalPointSizeScaleRatio;
|
||||
if ((settingsColmun.Children.Count % 2) == 1)
|
||||
{
|
||||
row.BackgroundColor = new RGBA_Bytes(0, 0, 0, 30);
|
||||
|
|
@ -237,30 +307,5 @@ namespace MatterHackers.MatterControl.EeProm
|
|||
|
||||
return holder;
|
||||
}
|
||||
|
||||
private void buttonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
UiThread.RunOnIdle(DoButtonSave_Click);
|
||||
}
|
||||
|
||||
private void DoButtonSave_Click()
|
||||
{
|
||||
currentEePromSettings.Save();
|
||||
currentEePromSettings.Clear();
|
||||
currentEePromSettings.eventAdded -= NewSettingReadFromPrinter;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void buttonAbort_Click(object sender, EventArgs e)
|
||||
{
|
||||
UiThread.RunOnIdle(DoButtonAbort_Click);
|
||||
}
|
||||
|
||||
private void DoButtonAbort_Click()
|
||||
{
|
||||
currentEePromSettings.Clear();
|
||||
currentEePromSettings.eventAdded -= NewSettingReadFromPrinter;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4507,3 +4507,18 @@ Translated:Loading G-Code
|
|||
English:Estimated Weight
|
||||
Translated:Estimated Weight
|
||||
|
||||
English:Export EEPROM Settings
|
||||
Translated:Export EEPROM Settings
|
||||
|
||||
English:MatterControl -
|
||||
Translated:MatterControl -
|
||||
|
||||
English:Export EEPROM
|
||||
Translated:Export EEPROM
|
||||
|
||||
English:Import EEPROM Settings
|
||||
Translated:Import EEPROM Settings
|
||||
|
||||
English:Import EEPROM
|
||||
Translated:Import EEPROM
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 64d2268986974c22ab2e425539ec17517738ddf4
|
||||
Subproject commit 1ca18756e0d6f9c673f3c46b7fa4a2fa2538f5c3
|
||||
Loading…
Add table
Add a link
Reference in a new issue