2022-03-15 17:51:28 -07:00
|
|
|
|
/*
|
|
|
|
|
|
Copyright (c) 2022, John Lewin, Lars Brubaker
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
|
|
list of conditions and the following disclaimer.
|
|
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
|
and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
|
|
The views and conclusions contained in the software and documentation are those
|
|
|
|
|
|
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.Image;
|
2022-03-16 17:25:59 -07:00
|
|
|
|
using MatterHackers.Agg.Platform;
|
2022-03-15 17:51:28 -07:00
|
|
|
|
using MatterHackers.Agg.UI;
|
|
|
|
|
|
using MatterHackers.Localizations;
|
|
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
|
|
|
|
|
using MatterHackers.MatterControl.Library.Widgets.HardwarePage;
|
2022-03-16 17:25:59 -07:00
|
|
|
|
using MatterHackers.MatterControl.PartPreviewWindow;
|
2022-03-15 17:51:28 -07:00
|
|
|
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2022-03-16 17:25:59 -07:00
|
|
|
|
using System.IO;
|
2022-03-15 17:51:28 -07:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.Library.Widgets
|
|
|
|
|
|
{
|
|
|
|
|
|
public class AddMaterialWidget : SearchableTreePanel
|
|
|
|
|
|
{
|
2022-03-16 17:25:59 -07:00
|
|
|
|
public class MaterialInfo
|
|
|
|
|
|
{
|
|
|
|
|
|
public string Path { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public string Sku { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-15 17:51:28 -07:00
|
|
|
|
private Action<bool> nextButtonEnabled;
|
2022-03-16 17:25:59 -07:00
|
|
|
|
private FlowLayoutWidget materialInfo;
|
|
|
|
|
|
public MaterialInfo SelectedMaterial { get; private set; }
|
2022-03-15 17:51:28 -07:00
|
|
|
|
|
|
|
|
|
|
public AddMaterialWidget(GuiWidget nextButton, ThemeConfig theme, Action<bool> nextButtonEnabled)
|
|
|
|
|
|
: base(theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.nextButtonEnabled = nextButtonEnabled;
|
|
|
|
|
|
this.Name = "AddPrinterWidget";
|
|
|
|
|
|
|
|
|
|
|
|
horizontalSplitter.Panel2.Padding = theme.DefaultContainerPadding;
|
|
|
|
|
|
|
2023-03-24 17:23:05 -07:00
|
|
|
|
TreeView.AfterSelect += this.TreeView_AfterSelect;
|
2022-03-15 17:51:28 -07:00
|
|
|
|
|
2023-03-24 17:23:05 -07:00
|
|
|
|
TreeView.NodeMouseDoubleClick += (s, e) =>
|
2022-03-15 17:51:28 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (e is MouseEventArgs mouseEvent
|
|
|
|
|
|
&& mouseEvent.Button == MouseButtons.Left
|
|
|
|
|
|
&& mouseEvent.Clicks == 2
|
2023-03-24 17:23:05 -07:00
|
|
|
|
&& TreeView?.SelectedNode is TreeNode treeNode)
|
2022-03-15 17:51:28 -07:00
|
|
|
|
{
|
|
|
|
|
|
nextButton.InvokeClick();
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
UiThread.RunOnIdle(() =>
|
|
|
|
|
|
{
|
2022-03-16 17:25:59 -07:00
|
|
|
|
foreach (var rootDirectory in Directory.EnumerateDirectories(Path.Combine(StaticData.RootPath, "Materials")).OrderBy(f => Path.GetFileName(f)))
|
2022-03-15 17:51:28 -07:00
|
|
|
|
{
|
2022-03-16 17:25:59 -07:00
|
|
|
|
var rootNode = this.CreateTreeNode(rootDirectory);
|
2022-03-15 17:51:28 -07:00
|
|
|
|
rootNode.Expandable = true;
|
2023-03-24 17:23:05 -07:00
|
|
|
|
rootNode.TreeView = TreeView;
|
2022-03-15 17:51:28 -07:00
|
|
|
|
contentPanel.AddChild(rootNode);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.TreeLoaded = true;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var container = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
Margin = new BorderDouble(theme.DefaultContainerPadding).Clone(top: 0)
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var panel2Column = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Stretch
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2022-03-16 17:25:59 -07:00
|
|
|
|
materialInfo = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
2022-03-15 17:51:28 -07:00
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Stretch
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Padding allows space for scrollbar
|
2022-03-16 17:25:59 -07:00
|
|
|
|
materialInfo.Padding = new BorderDouble(right: theme.DefaultContainerPadding + 2);
|
2022-03-15 17:51:28 -07:00
|
|
|
|
|
2022-03-16 17:25:59 -07:00
|
|
|
|
panel2Column.AddChild(materialInfo);
|
2022-03-15 17:51:28 -07:00
|
|
|
|
|
|
|
|
|
|
horizontalSplitter.Panel2.Padding = horizontalSplitter.Panel2.Padding.Clone(right: 0, bottom: 0);
|
|
|
|
|
|
|
|
|
|
|
|
horizontalSplitter.Panel2.AddChild(panel2Column);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-24 17:23:05 -07:00
|
|
|
|
protected override bool NodeMatchesFilter(TreeNode context, string filter)
|
2022-03-15 17:51:28 -07:00
|
|
|
|
{
|
2023-03-24 17:23:05 -07:00
|
|
|
|
// check if the node matches the filter
|
|
|
|
|
|
return context.Text.IndexOf(filter, StringComparison.OrdinalIgnoreCase) != -1;
|
2022-03-15 17:51:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void SetImage(TreeNode node, ImageBuffer image)
|
|
|
|
|
|
{
|
|
|
|
|
|
node.Image = image;
|
|
|
|
|
|
|
|
|
|
|
|
// Push to children
|
|
|
|
|
|
foreach (var child in node.Nodes)
|
|
|
|
|
|
{
|
|
|
|
|
|
SetImage(child, image);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-16 17:25:59 -07:00
|
|
|
|
private TreeNode CreateTreeNode(string directory)
|
2022-03-15 17:51:28 -07:00
|
|
|
|
{
|
|
|
|
|
|
var treeNode = new TreeNode(theme)
|
|
|
|
|
|
{
|
2022-03-17 18:23:44 -07:00
|
|
|
|
Text = Path.GetFileName(directory).Replace("_", " ").Trim(),
|
2022-03-15 17:51:28 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2022-03-16 17:25:59 -07:00
|
|
|
|
foreach (var subDirectory in Directory.EnumerateDirectories(directory).OrderBy(f => Path.GetFileName(f)))
|
|
|
|
|
|
{
|
|
|
|
|
|
treeNode.Nodes.Add(CreateTreeNode(subDirectory));
|
|
|
|
|
|
}
|
2022-03-15 17:51:28 -07:00
|
|
|
|
|
2022-03-16 17:25:59 -07:00
|
|
|
|
foreach (var materialFile in Directory.EnumerateFiles(directory, "*.material").OrderBy(f => Path.GetFileName(f)))
|
2022-03-15 17:51:28 -07:00
|
|
|
|
{
|
2022-03-16 17:25:59 -07:00
|
|
|
|
var materialToAdd = PrinterSettings.LoadFile(materialFile);
|
|
|
|
|
|
var name = materialToAdd.MaterialLayers[0].Name;
|
2022-03-17 18:23:44 -07:00
|
|
|
|
var fileName = Path.GetFileNameWithoutExtension(materialFile).Replace("_", " ").Trim();
|
2022-03-16 17:25:59 -07:00
|
|
|
|
var sku = "";
|
|
|
|
|
|
if (materialToAdd.MaterialLayers[0].ContainsKey(SettingsKey.material_sku))
|
2022-03-15 17:51:28 -07:00
|
|
|
|
{
|
2022-03-16 17:25:59 -07:00
|
|
|
|
sku = materialToAdd.MaterialLayers[0][SettingsKey.material_sku];
|
2022-03-15 17:51:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-16 17:25:59 -07:00
|
|
|
|
treeNode.Nodes.Add(new TreeNode(theme, nodeParent: treeNode)
|
2022-03-15 17:51:28 -07:00
|
|
|
|
{
|
2022-03-16 17:25:59 -07:00
|
|
|
|
Text = fileName,
|
|
|
|
|
|
Name = fileName,
|
|
|
|
|
|
Tag = new MaterialInfo()
|
2022-03-15 17:51:28 -07:00
|
|
|
|
{
|
2022-03-16 17:25:59 -07:00
|
|
|
|
Name = name,
|
|
|
|
|
|
Path = materialFile,
|
|
|
|
|
|
Sku = sku
|
2022-03-15 17:51:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-25 09:53:43 -07:00
|
|
|
|
if (Path.GetFileName(directory).Contains("MatterHackers"))
|
2022-03-20 19:16:06 -07:00
|
|
|
|
{
|
|
|
|
|
|
treeNode.Expanded = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-15 17:51:28 -07:00
|
|
|
|
return treeNode;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void TreeView_AfterSelect(object sender, TreeNode e)
|
|
|
|
|
|
{
|
2023-03-24 17:23:05 -07:00
|
|
|
|
if (TreeView.SelectedNode?.Tag != null)
|
2022-03-15 17:51:28 -07:00
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle(() =>
|
|
|
|
|
|
{
|
2023-03-24 17:23:05 -07:00
|
|
|
|
if (TreeView.SelectedNode != null)
|
2022-03-15 17:51:28 -07:00
|
|
|
|
{
|
2023-03-24 17:23:05 -07:00
|
|
|
|
string printerName = TreeView.SelectedNode.Tag.ToString();
|
2022-03-15 17:51:28 -07:00
|
|
|
|
|
2023-03-24 17:23:05 -07:00
|
|
|
|
this.SelectedMaterial = TreeView.SelectedNode.Tag as MaterialInfo;
|
2022-03-16 17:25:59 -07:00
|
|
|
|
materialInfo.CloseChildren();
|
|
|
|
|
|
|
|
|
|
|
|
var printerDetails = new PrinterDetails(
|
|
|
|
|
|
new PrinterInfo()
|
|
|
|
|
|
{
|
|
|
|
|
|
ID = SelectedMaterial.Sku,
|
|
|
|
|
|
Make = "Pulse",
|
|
|
|
|
|
Model = "E-223",
|
|
|
|
|
|
}, theme,
|
|
|
|
|
|
false)
|
|
|
|
|
|
{
|
|
|
|
|
|
ShowProducts = false,
|
|
|
|
|
|
ShowHeadingRow = false,
|
|
|
|
|
|
StoreID = SelectedMaterial.Sku,
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Stretch
|
|
|
|
|
|
};
|
2022-03-15 17:51:28 -07:00
|
|
|
|
|
2022-03-16 17:25:59 -07:00
|
|
|
|
// get the material_sku out of it
|
2022-03-15 17:51:28 -07:00
|
|
|
|
|
2022-03-16 17:25:59 -07:00
|
|
|
|
materialInfo.AddChild(printerDetails);
|
2022-03-15 17:51:28 -07:00
|
|
|
|
|
2022-03-16 17:25:59 -07:00
|
|
|
|
printerDetails.AfterLoad += (s, e2) =>
|
2022-03-15 17:51:28 -07:00
|
|
|
|
{
|
2022-03-18 15:58:13 -07:00
|
|
|
|
if (printerDetails.ProductDataContainer.Children.Count > 0)
|
2022-03-16 17:25:59 -07:00
|
|
|
|
{
|
2022-03-18 15:58:13 -07:00
|
|
|
|
printerDetails.ProductDataContainer.AddChild(new HorizontalLine(theme.TextColor)
|
|
|
|
|
|
{
|
|
|
|
|
|
Margin = new BorderDouble(0, 7)
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2022-03-16 17:25:59 -07:00
|
|
|
|
|
2022-04-19 09:50:45 -07:00
|
|
|
|
var printerProfile = PrinterSettings.LoadFile(SelectedMaterial.Path);
|
|
|
|
|
|
var printerSettingsLayer = printerProfile.MaterialLayers[0];
|
|
|
|
|
|
printerProfile.MaterialLayers.RemoveAt(0);
|
|
|
|
|
|
printerProfile.MaterialLayers.Add(new PrinterSettingsLayer());
|
2022-03-17 18:23:44 -07:00
|
|
|
|
|
2022-04-19 09:50:45 -07:00
|
|
|
|
var settingsBackground = CreateSetingsList(printerProfile, printerSettingsLayer, theme);
|
|
|
|
|
|
printerDetails.ProductDataContainer.AddChild(settingsBackground);
|
|
|
|
|
|
};
|
2022-03-17 18:23:44 -07:00
|
|
|
|
|
2023-03-24 17:23:05 -07:00
|
|
|
|
nextButtonEnabled(TreeView.SelectedNode != null);
|
2022-04-19 09:50:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
nextButtonEnabled(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-03-17 18:23:44 -07:00
|
|
|
|
|
2022-04-19 09:50:45 -07:00
|
|
|
|
public static GuiWidget CreateSetingsList(PrinterSettings printerProfile, PrinterSettingsLayer printerSettingsLayer, ThemeConfig theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
var settingsBackground = new GuiWidget()
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "Background",
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Fit,
|
|
|
|
|
|
Margin = 7,
|
|
|
|
|
|
};
|
2022-03-17 18:23:44 -07:00
|
|
|
|
|
2022-04-19 09:50:45 -07:00
|
|
|
|
var settingsHolder = settingsBackground.AddChild(new FlowLayoutWidget(FlowDirection.TopToBottom)
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "Holder",
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
});
|
2022-03-17 18:23:44 -07:00
|
|
|
|
|
2022-04-19 09:50:45 -07:00
|
|
|
|
var settingsCover = settingsBackground.AddChild(new GuiWidget()
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "Cover",
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
BackgroundColor = theme.BackgroundColor.WithAlpha(100),
|
|
|
|
|
|
});
|
2022-03-16 17:25:59 -07:00
|
|
|
|
|
2022-04-19 09:50:45 -07:00
|
|
|
|
settingsHolder.SizeChanged += (s5, e5) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
settingsCover.Height = settingsHolder.Height;
|
|
|
|
|
|
};
|
2022-03-16 17:25:59 -07:00
|
|
|
|
|
2022-04-19 09:50:45 -07:00
|
|
|
|
printerProfile.OemLayer = new PrinterSettingsLayer();
|
|
|
|
|
|
// move all the settings to the oem layer
|
|
|
|
|
|
var layout = new List<(int index, string category, string group, string key)>();
|
|
|
|
|
|
foreach (var kvp in printerSettingsLayer)
|
|
|
|
|
|
{
|
|
|
|
|
|
printerProfile.OemLayer[kvp.Key] = kvp.Value;
|
|
|
|
|
|
layout.Add(SliceSettingsLayouts.GetLayout(kvp.Key));
|
|
|
|
|
|
}
|
2022-03-16 17:25:59 -07:00
|
|
|
|
|
2022-04-19 09:50:45 -07:00
|
|
|
|
var printer = new PrinterConfig(printerProfile);
|
|
|
|
|
|
var settingsContext = new SettingsContext(printer, null, NamedSettingsLayers.All);
|
|
|
|
|
|
var tabIndex = 0;
|
|
|
|
|
|
var orderedSettings = layout.OrderBy(i => i.index).Select(i => (i.category, i.key));
|
2022-03-16 17:25:59 -07:00
|
|
|
|
|
2022-04-19 09:50:45 -07:00
|
|
|
|
var lastCategory = "";
|
2022-03-16 17:25:59 -07:00
|
|
|
|
|
2022-04-19 09:50:45 -07:00
|
|
|
|
foreach ((string category, string key) setting in orderedSettings)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (setting.category == "")
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2022-03-16 17:25:59 -07:00
|
|
|
|
|
2022-04-19 09:50:45 -07:00
|
|
|
|
if (setting.category != lastCategory)
|
|
|
|
|
|
{
|
|
|
|
|
|
lastCategory = setting.category;
|
|
|
|
|
|
// add a new setting header
|
|
|
|
|
|
settingsHolder.AddChild(new TextWidget(setting.category.Localize() + " " + "Settings".Localize() + ":", 0, 0, bold: true)
|
|
|
|
|
|
{
|
|
|
|
|
|
TextColor = theme.TextColor,
|
|
|
|
|
|
Margin = new BorderDouble(0, 5, 0, 7)
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2022-03-16 17:25:59 -07:00
|
|
|
|
|
2022-04-19 09:50:45 -07:00
|
|
|
|
var settingsData = PrinterSettings.SettingsData[setting.key];
|
|
|
|
|
|
var row = SliceSettingsTabView.CreateItemRow(settingsData, settingsContext, printer, theme, ref tabIndex);
|
|
|
|
|
|
|
|
|
|
|
|
if (row is SliceSettingsRow settingsRow)
|
|
|
|
|
|
{
|
|
|
|
|
|
settingsRow.ArrowDirection = ArrowDirection.Left;
|
|
|
|
|
|
settingsRow.Enabled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
settingsHolder.AddChild(row);
|
2022-03-15 17:51:28 -07:00
|
|
|
|
}
|
2022-04-19 09:50:45 -07:00
|
|
|
|
|
|
|
|
|
|
return settingsBackground;
|
2022-03-15 17:51:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|