2014-03-30 17:54:05 -07:00
|
|
|
|
/*
|
2018-04-17 07:43:18 -07:00
|
|
|
|
Copyright (c) 2018, Kevin Pope, John Lewin
|
2014-03-30 17:54:05 -07:00
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
2015-04-08 15:20:10 -07:00
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
2014-03-30 17:54:05 -07:00
|
|
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
2015-04-08 15:20:10 -07:00
|
|
|
|
list of conditions and the following disclaimer.
|
2014-03-30 17:54:05 -07:00
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
2015-04-08 15:20:10 -07:00
|
|
|
|
and/or other materials provided with the distribution.
|
2014-03-30 17:54:05 -07:00
|
|
|
|
|
|
|
|
|
|
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
|
2015-04-08 15:20:10 -07:00
|
|
|
|
of the authors and should not be interpreted as representing official policies,
|
2014-03-30 17:54:05 -07:00
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
2014-12-16 08:26:35 -08:00
|
|
|
|
//#define DO_IN_PLACE_EDIT
|
2014-03-30 17:54:05 -07:00
|
|
|
|
|
2017-06-27 18:41:34 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
2014-03-30 17:54:05 -07:00
|
|
|
|
using MatterHackers.Agg;
|
2017-08-20 02:34:39 -07:00
|
|
|
|
using MatterHackers.Agg.Platform;
|
2014-03-30 17:54:05 -07:00
|
|
|
|
using MatterHackers.Agg.UI;
|
2018-04-17 07:43:18 -07:00
|
|
|
|
using MatterHackers.Agg.VertexSource;
|
2014-03-30 17:54:05 -07:00
|
|
|
|
using MatterHackers.Localizations;
|
2018-05-06 07:57:15 -07:00
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
using MatterHackers.VectorMath;
|
2014-03-30 17:54:05 -07:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.SlicerConfiguration
|
|
|
|
|
|
{
|
2016-04-18 11:31:31 -07:00
|
|
|
|
public class PresetSelectorWidget : FlowLayoutWidget
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2017-09-20 11:12:13 -07:00
|
|
|
|
public DropDownList DropDownList;
|
2016-12-06 18:12:57 -08:00
|
|
|
|
private string defaultMenuItemText = "- none -".Localize();
|
2018-01-16 19:01:09 -08:00
|
|
|
|
private GuiWidget editButton;
|
2019-02-05 11:22:22 -08:00
|
|
|
|
private int extruderIndex;
|
2016-05-07 17:47:42 -07:00
|
|
|
|
private NamedSettingsLayers layerType;
|
2018-01-12 12:57:53 -08:00
|
|
|
|
private ThemeConfig theme;
|
2017-09-17 01:11:18 -07:00
|
|
|
|
private PrinterConfig printer;
|
2017-09-20 11:12:13 -07:00
|
|
|
|
private GuiWidget pullDownContainer;
|
2019-02-05 17:39:11 -08:00
|
|
|
|
private bool createAsFit;
|
2016-04-18 11:31:31 -07:00
|
|
|
|
|
2019-02-05 17:39:11 -08:00
|
|
|
|
public PresetSelectorWidget(PrinterConfig printer, string label, Color accentColor, NamedSettingsLayers layerType, int extruderIndex, ThemeConfig theme, bool createAsFit = false)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
: base(FlowDirection.TopToBottom)
|
|
|
|
|
|
{
|
2019-02-05 17:39:11 -08:00
|
|
|
|
this.createAsFit = createAsFit;
|
2019-02-05 11:22:22 -08:00
|
|
|
|
this.extruderIndex = extruderIndex;
|
2018-04-17 07:43:18 -07:00
|
|
|
|
this.layerType = layerType;
|
2017-09-17 01:11:18 -07:00
|
|
|
|
this.printer = printer;
|
2018-01-12 12:57:53 -08:00
|
|
|
|
this.Name = label;
|
2018-04-12 08:42:10 -07:00
|
|
|
|
this.theme = theme;
|
2019-02-05 17:39:11 -08:00
|
|
|
|
this.HAnchor = createAsFit ? HAnchor.Fit : HAnchor.Stretch;
|
2018-04-17 07:43:18 -07:00
|
|
|
|
this.VAnchor = VAnchor.Fit;
|
|
|
|
|
|
this.BackgroundColor = theme.MinimalShade;
|
|
|
|
|
|
this.Padding = theme.DefaultContainerPadding;
|
2017-05-23 10:51:12 -07:00
|
|
|
|
|
|
|
|
|
|
// Section Label
|
2018-11-03 09:13:07 -07:00
|
|
|
|
this.AddChild(new TextWidget(label, pointSize: theme.DefaultFontSize, textColor: theme.TextColor)
|
2016-04-18 11:31:31 -07:00
|
|
|
|
{
|
2017-09-20 11:12:13 -07:00
|
|
|
|
HAnchor = HAnchor.Left,
|
2018-04-17 07:43:18 -07:00
|
|
|
|
Margin = new BorderDouble(0)
|
2017-05-23 10:51:12 -07:00
|
|
|
|
});
|
2014-03-30 17:54:05 -07:00
|
|
|
|
|
2017-09-20 18:05:15 -07:00
|
|
|
|
pullDownContainer = new GuiWidget()
|
|
|
|
|
|
{
|
2019-02-05 17:39:11 -08:00
|
|
|
|
HAnchor = createAsFit ? HAnchor.Fit : HAnchor.Stretch,
|
2018-04-17 07:43:18 -07:00
|
|
|
|
VAnchor = VAnchor.Fit,
|
|
|
|
|
|
Border = new BorderDouble(left: 3),
|
|
|
|
|
|
BorderColor = accentColor,
|
|
|
|
|
|
Margin = new BorderDouble(top: 6),
|
|
|
|
|
|
Padding = new BorderDouble(left: (accentColor != Color.Transparent) ? 6 : 0)
|
2017-09-20 18:05:15 -07:00
|
|
|
|
};
|
2018-04-17 17:15:32 -07:00
|
|
|
|
pullDownContainer.AddChild(this.GetPulldownContainer());
|
2017-09-20 18:05:15 -07:00
|
|
|
|
this.AddChild(pullDownContainer);
|
2018-04-17 08:14:08 -07:00
|
|
|
|
|
2018-11-16 08:44:56 -08:00
|
|
|
|
// Register listeners
|
2018-10-05 16:03:31 -07:00
|
|
|
|
printer.Settings.MaterialPresetChanged += ActiveSliceSettings_MaterialPresetChanged;
|
2018-11-12 17:20:59 -08:00
|
|
|
|
printer.Settings.SettingChanged += Printer_SettingChanged;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
2014-03-30 17:54:05 -07:00
|
|
|
|
|
2016-08-11 17:18:32 -07:00
|
|
|
|
public FlowLayoutWidget GetPulldownContainer()
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2017-09-07 16:24:11 -07:00
|
|
|
|
DropDownList = CreateDropdown();
|
2014-03-30 17:54:05 -07:00
|
|
|
|
|
2018-04-17 07:43:18 -07:00
|
|
|
|
var container = new FlowLayoutWidget()
|
2017-05-23 10:51:12 -07:00
|
|
|
|
{
|
2019-02-05 17:39:11 -08:00
|
|
|
|
HAnchor = createAsFit ? HAnchor.Fit : HAnchor.MaxFitOrStretch,
|
2017-06-27 18:41:34 -07:00
|
|
|
|
Name = "Preset Pulldown Container"
|
2017-05-23 10:51:12 -07:00
|
|
|
|
};
|
2014-03-30 17:54:05 -07:00
|
|
|
|
|
2018-05-06 07:57:15 -07:00
|
|
|
|
editButton = new IconButton(AggContext.StaticData.LoadIcon("icon_edit.png", 16, 16, theme.InvertIcons), theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
ToolTipText = "Edit Selected Setting".Localize(),
|
|
|
|
|
|
Enabled = DropDownList.SelectedIndex != -1,
|
|
|
|
|
|
VAnchor = VAnchor.Center,
|
|
|
|
|
|
Margin = new BorderDouble(left: 6)
|
|
|
|
|
|
};
|
2019-02-05 11:22:22 -08:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
editButton.Click += (sender, e) =>
|
|
|
|
|
|
{
|
2016-05-07 17:47:42 -07:00
|
|
|
|
if (layerType == NamedSettingsLayers.Material)
|
2016-05-11 21:27:30 -07:00
|
|
|
|
{
|
2018-06-17 12:22:33 -07:00
|
|
|
|
if (ApplicationController.Instance.EditMaterialPresetsPage == null)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2018-01-10 12:55:41 -08:00
|
|
|
|
string presetsID = printer.Settings.ActiveMaterialKey;
|
2016-06-08 19:02:34 -07:00
|
|
|
|
if (string.IsNullOrEmpty(presetsID))
|
2016-05-11 21:27:30 -07:00
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-17 01:11:18 -07:00
|
|
|
|
var layerToEdit = printer.Settings.MaterialLayers.Where(layer => layer.LayerID == presetsID).FirstOrDefault();
|
2016-06-08 19:02:34 -07:00
|
|
|
|
|
2017-09-17 01:11:18 -07:00
|
|
|
|
var presetsContext = new PresetsContext(printer.Settings.MaterialLayers, layerToEdit)
|
2016-05-16 16:21:42 -07:00
|
|
|
|
{
|
|
|
|
|
|
LayerType = NamedSettingsLayers.Material,
|
2016-05-17 17:12:19 -07:00
|
|
|
|
SetAsActive = (materialKey) =>
|
|
|
|
|
|
{
|
2018-01-10 12:55:41 -08:00
|
|
|
|
printer.Settings.ActiveMaterialKey = materialKey;
|
2016-06-16 11:52:56 -07:00
|
|
|
|
},
|
2017-09-20 11:12:13 -07:00
|
|
|
|
DeleteLayer = () =>
|
2016-06-16 11:52:56 -07:00
|
|
|
|
{
|
2017-09-17 01:11:18 -07:00
|
|
|
|
var materialKeys = printer.Settings.MaterialSettingsKeys;
|
2016-06-16 11:52:56 -07:00
|
|
|
|
for (var i = 0; i < materialKeys.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (materialKeys[i] == presetsID)
|
|
|
|
|
|
{
|
|
|
|
|
|
materialKeys[i] = "";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-10 12:55:41 -08:00
|
|
|
|
printer.Settings.ActiveMaterialKey = "";
|
2017-09-17 01:11:18 -07:00
|
|
|
|
printer.Settings.MaterialLayers.Remove(layerToEdit);
|
|
|
|
|
|
printer.Settings.Save();
|
2016-05-17 17:12:19 -07:00
|
|
|
|
}
|
2016-05-16 16:21:42 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2018-06-17 12:22:33 -07:00
|
|
|
|
var editMaterialPresetsPage = new SlicePresetsPage(printer, presetsContext);
|
|
|
|
|
|
editMaterialPresetsPage.Closed += (s, e2) =>
|
2016-05-07 21:07:14 -07:00
|
|
|
|
{
|
2018-06-17 12:22:33 -07:00
|
|
|
|
ApplicationController.Instance.EditMaterialPresetsPage = null;
|
2016-05-07 21:07:14 -07:00
|
|
|
|
};
|
2018-06-17 12:22:33 -07:00
|
|
|
|
|
|
|
|
|
|
ApplicationController.Instance.EditMaterialPresetsPage = editMaterialPresetsPage;
|
|
|
|
|
|
DialogWindow.Show(editMaterialPresetsPage);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-06-19 15:02:25 -07:00
|
|
|
|
ApplicationController.Instance.EditMaterialPresetsPage.DialogWindow.BringToFront();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-11-11 14:51:36 -08:00
|
|
|
|
|
2016-05-07 17:47:42 -07:00
|
|
|
|
if (layerType == NamedSettingsLayers.Quality)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (ApplicationController.Instance.EditQualityPresetsWindow == null)
|
|
|
|
|
|
{
|
2017-09-17 01:11:18 -07:00
|
|
|
|
string presetsID = printer.Settings.ActiveQualityKey;
|
2016-06-08 19:02:34 -07:00
|
|
|
|
if (string.IsNullOrEmpty(presetsID))
|
2016-05-11 21:27:30 -07:00
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-17 01:11:18 -07:00
|
|
|
|
var layerToEdit = printer.Settings.QualityLayers.Where(layer => layer.LayerID == presetsID).FirstOrDefault();
|
2016-06-08 19:02:34 -07:00
|
|
|
|
|
2017-09-17 01:11:18 -07:00
|
|
|
|
var presetsContext = new PresetsContext(printer.Settings.QualityLayers, layerToEdit)
|
2016-05-16 16:21:42 -07:00
|
|
|
|
{
|
|
|
|
|
|
LayerType = NamedSettingsLayers.Quality,
|
2017-09-17 01:11:18 -07:00
|
|
|
|
SetAsActive = (qualityKey) => printer.Settings.ActiveQualityKey = qualityKey,
|
2016-06-16 11:52:56 -07:00
|
|
|
|
DeleteLayer = () =>
|
|
|
|
|
|
{
|
2017-09-17 01:11:18 -07:00
|
|
|
|
printer.Settings.ActiveQualityKey = "";
|
|
|
|
|
|
printer.Settings.QualityLayers.Remove(layerToEdit);
|
|
|
|
|
|
printer.Settings.Save();
|
2016-06-16 11:52:56 -07:00
|
|
|
|
}
|
2016-05-16 16:21:42 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2018-06-17 12:22:33 -07:00
|
|
|
|
var editQualityPresetsWindow = new SlicePresetsPage(printer, presetsContext);
|
|
|
|
|
|
editQualityPresetsWindow.Closed += (s, e2) =>
|
2016-05-07 21:07:14 -07:00
|
|
|
|
{
|
|
|
|
|
|
ApplicationController.Instance.EditQualityPresetsWindow = null;
|
|
|
|
|
|
};
|
2018-06-17 12:22:33 -07:00
|
|
|
|
|
|
|
|
|
|
ApplicationController.Instance.EditQualityPresetsWindow = editQualityPresetsWindow;
|
|
|
|
|
|
DialogWindow.Show(editQualityPresetsWindow);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-06-19 15:02:25 -07:00
|
|
|
|
ApplicationController.Instance.EditQualityPresetsWindow.DialogWindow.BringToFront();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2017-09-07 16:24:11 -07:00
|
|
|
|
container.AddChild(DropDownList);
|
2016-05-13 11:37:22 -07:00
|
|
|
|
container.AddChild(editButton);
|
2016-03-30 18:33:29 -07:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
return container;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-17 07:43:18 -07:00
|
|
|
|
public override void OnDrawBackground(Graphics2D graphics2D)
|
|
|
|
|
|
{
|
|
|
|
|
|
//base.OnDrawBackground(graphics2D);
|
2018-04-20 13:51:41 -07:00
|
|
|
|
if (this.BackgroundColor != Color.Transparent)
|
|
|
|
|
|
{
|
|
|
|
|
|
graphics2D.Render(new RoundedRect(this.LocalBounds, 5), this.BackgroundColor);
|
|
|
|
|
|
}
|
2018-04-17 07:43:18 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-23 16:44:11 -07:00
|
|
|
|
public override void OnClosed(EventArgs e)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2018-11-16 08:44:56 -08:00
|
|
|
|
// Unregister listeners
|
2018-10-05 16:03:31 -07:00
|
|
|
|
printer.Settings.MaterialPresetChanged -= ActiveSliceSettings_MaterialPresetChanged;
|
2018-11-16 08:44:56 -08:00
|
|
|
|
printer.Settings.SettingChanged -= Printer_SettingChanged;
|
2018-01-12 12:57:53 -08:00
|
|
|
|
|
2017-09-20 11:12:13 -07:00
|
|
|
|
base.OnClosed(e);
|
|
|
|
|
|
}
|
2016-04-18 11:31:31 -07:00
|
|
|
|
|
2018-12-20 12:38:05 -08:00
|
|
|
|
private void Printer_SettingChanged(object s, StringEventArgs stringEvent)
|
2018-11-16 08:44:56 -08:00
|
|
|
|
{
|
2018-12-20 12:38:05 -08:00
|
|
|
|
if (stringEvent != null
|
2018-11-16 08:44:56 -08:00
|
|
|
|
&& (stringEvent.Data == SettingsKey.default_material_presets
|
|
|
|
|
|
|| stringEvent.Data == SettingsKey.layer_name))
|
|
|
|
|
|
{
|
|
|
|
|
|
RebuildDropDownList();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-20 11:12:13 -07:00
|
|
|
|
private void ActiveSliceSettings_MaterialPresetChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
RebuildDropDownList();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-06-03 18:11:51 -07:00
|
|
|
|
private DropDownList CreateDropdown()
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2018-10-17 20:31:31 -07:00
|
|
|
|
var dropDownList = new MHDropDownList(defaultMenuItemText, theme, maxHeight: 300, useLeftIcons: true)
|
2016-04-27 17:34:33 -07:00
|
|
|
|
{
|
2017-08-07 15:47:27 -07:00
|
|
|
|
HAnchor = HAnchor.Stretch,
|
2018-04-17 07:43:18 -07:00
|
|
|
|
VAnchor = VAnchor.Center,
|
2017-05-26 00:23:20 -07:00
|
|
|
|
MenuItemsPadding = new BorderDouble(10, 7, 7, 7),
|
2016-04-27 17:34:33 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2017-09-07 16:24:11 -07:00
|
|
|
|
dropDownList.Name = layerType.ToString() + " DropDown List";
|
2018-04-17 07:43:18 -07:00
|
|
|
|
dropDownList.Margin = 0;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
dropDownList.MinimumSize = new Vector2(dropDownList.LocalBounds.Width, dropDownList.LocalBounds.Height);
|
2016-04-18 11:31:31 -07:00
|
|
|
|
|
2016-08-23 09:35:22 -07:00
|
|
|
|
MenuItem defaultMenuItem = dropDownList.AddItem(defaultMenuItemText, "");
|
2016-05-03 10:59:37 -07:00
|
|
|
|
defaultMenuItem.Selected += MenuItem_Selected;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2017-09-17 01:11:18 -07:00
|
|
|
|
var listSource = (layerType == NamedSettingsLayers.Material) ? printer.Settings.MaterialLayers : printer.Settings.QualityLayers;
|
2018-06-05 14:38:09 -07:00
|
|
|
|
foreach (var layer in listSource.OrderBy(l => l.Name))
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2016-06-15 12:58:36 -07:00
|
|
|
|
MenuItem menuItem = dropDownList.AddItem(layer.Name, layer.LayerID);
|
2016-12-06 17:48:13 -08:00
|
|
|
|
menuItem.Name = layer.Name + " Menu";
|
2016-05-03 10:59:37 -07:00
|
|
|
|
menuItem.Selected += MenuItem_Selected;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-23 15:53:12 -07:00
|
|
|
|
MenuItem addNewPreset = dropDownList.AddItem(AggContext.StaticData.LoadIcon("icon_plus.png", 16, 16), "Add New Setting".Localize() + "...", "new");
|
2016-05-07 17:47:42 -07:00
|
|
|
|
addNewPreset.Selected += (s, e) =>
|
2016-04-26 17:32:55 -07:00
|
|
|
|
{
|
2016-06-15 14:50:12 -07:00
|
|
|
|
var newLayer = new PrinterSettingsLayer();
|
2016-05-07 17:47:42 -07:00
|
|
|
|
if (layerType == NamedSettingsLayers.Quality)
|
2016-04-26 17:32:55 -07:00
|
|
|
|
{
|
2017-09-17 01:11:18 -07:00
|
|
|
|
newLayer.Name = "Quality" + printer.Settings.QualityLayers.Count;
|
|
|
|
|
|
printer.Settings.QualityLayers.Add(newLayer);
|
|
|
|
|
|
printer.Settings.ActiveQualityKey = newLayer.LayerID;
|
2016-05-07 17:47:42 -07:00
|
|
|
|
}
|
2016-05-16 16:21:42 -07:00
|
|
|
|
else
|
2016-04-26 17:32:55 -07:00
|
|
|
|
{
|
2017-09-17 01:11:18 -07:00
|
|
|
|
newLayer.Name = "Material" + printer.Settings.MaterialLayers.Count;
|
|
|
|
|
|
printer.Settings.MaterialLayers.Add(newLayer);
|
2018-01-10 12:55:41 -08:00
|
|
|
|
printer.Settings.ActiveMaterialKey = newLayer.LayerID;
|
2016-05-07 17:47:42 -07:00
|
|
|
|
}
|
2016-04-26 17:32:55 -07:00
|
|
|
|
|
2016-06-20 12:47:10 -07:00
|
|
|
|
RebuildDropDownList();
|
2016-05-07 17:47:42 -07:00
|
|
|
|
|
2017-09-22 14:06:52 -07:00
|
|
|
|
editButton.OnClick(new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0));
|
2016-05-10 11:42:40 -07:00
|
|
|
|
};
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2016-04-18 11:31:31 -07:00
|
|
|
|
try
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2016-04-18 11:31:31 -07:00
|
|
|
|
string settingsKey;
|
|
|
|
|
|
|
2016-05-07 17:47:42 -07:00
|
|
|
|
if (layerType == NamedSettingsLayers.Material)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2019-02-05 11:22:22 -08:00
|
|
|
|
if (extruderIndex == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
settingsKey = printer.Settings.ActiveMaterialKey;
|
2016-06-20 12:56:11 -07:00
|
|
|
|
|
2019-02-05 11:22:22 -08:00
|
|
|
|
printer.Settings.MaterialLayers.CollectionChanged += SettingsLayers_CollectionChanged;
|
|
|
|
|
|
dropDownList.Closed += (s1, e1) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
printer.Settings.MaterialLayers.CollectionChanged -= SettingsLayers_CollectionChanged;
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
else // try to find the right material based on the extruders temperature
|
2016-06-20 12:56:11 -07:00
|
|
|
|
{
|
2019-02-05 11:22:22 -08:00
|
|
|
|
settingsKey = null;
|
|
|
|
|
|
var extuderTemp = printer.Settings.GetValue<double>(SettingsKey.temperature1).ToString();
|
|
|
|
|
|
foreach(var materialLayer in printer.Settings.MaterialLayers)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(materialLayer.TryGetValue(SettingsKey.temperature, out string _temp))
|
|
|
|
|
|
{
|
|
|
|
|
|
if(_temp == extuderTemp)
|
|
|
|
|
|
{
|
|
|
|
|
|
settingsKey = materialLayer.LayerID;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
2016-04-18 11:31:31 -07:00
|
|
|
|
else
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2017-09-17 01:11:18 -07:00
|
|
|
|
settingsKey = printer.Settings.ActiveQualityKey;
|
2016-06-20 12:47:10 -07:00
|
|
|
|
|
2017-09-17 01:11:18 -07:00
|
|
|
|
printer.Settings.QualityLayers.CollectionChanged += SettingsLayers_CollectionChanged;
|
2016-06-20 12:47:10 -07:00
|
|
|
|
dropDownList.Closed += (s1, e1) =>
|
|
|
|
|
|
{
|
2017-09-17 01:11:18 -07:00
|
|
|
|
printer.Settings.QualityLayers.CollectionChanged -= SettingsLayers_CollectionChanged;
|
2016-06-20 12:47:10 -07:00
|
|
|
|
};
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
2016-04-18 11:31:31 -07:00
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(settingsKey))
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2016-04-18 11:31:31 -07:00
|
|
|
|
dropDownList.SelectedValue = settingsKey;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-04-18 11:31:31 -07:00
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
GuiWidget.BreakInDebugger(ex.Message);
|
|
|
|
|
|
}
|
2017-09-20 11:12:13 -07:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
return dropDownList;
|
|
|
|
|
|
}
|
2016-06-20 12:47:10 -07:00
|
|
|
|
|
2017-09-20 11:12:13 -07:00
|
|
|
|
private void MenuItem_Selected(object sender, EventArgs e)
|
2016-08-10 14:20:52 -07:00
|
|
|
|
{
|
2017-09-20 11:12:13 -07:00
|
|
|
|
// When a preset is selected store the current values of all known settings to compare against after applying the preset
|
|
|
|
|
|
Dictionary<string, string> settingBeforeChange = new Dictionary<string, string>();
|
|
|
|
|
|
foreach (var keyName in PrinterSettings.KnownSettings)
|
2016-08-10 14:20:52 -07:00
|
|
|
|
{
|
2017-09-20 11:12:13 -07:00
|
|
|
|
settingBeforeChange.Add(keyName, printer.Settings.GetValue(keyName));
|
2016-08-10 14:20:52 -07:00
|
|
|
|
}
|
2017-09-20 11:12:13 -07:00
|
|
|
|
|
|
|
|
|
|
var activeSettings = printer.Settings;
|
|
|
|
|
|
MenuItem item = (MenuItem)sender;
|
|
|
|
|
|
|
|
|
|
|
|
if (layerType == NamedSettingsLayers.Material)
|
|
|
|
|
|
{
|
2019-02-05 11:22:22 -08:00
|
|
|
|
if (extruderIndex == 0)
|
2017-09-20 11:12:13 -07:00
|
|
|
|
{
|
2019-02-05 11:22:22 -08:00
|
|
|
|
if (activeSettings.ActiveMaterialKey != item.Value)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Restore deactivated user overrides by iterating the Material preset we're coming off of
|
|
|
|
|
|
activeSettings.RestoreConflictingUserOverrides(activeSettings.MaterialLayer);
|
2017-09-20 11:12:13 -07:00
|
|
|
|
|
2019-02-05 11:22:22 -08:00
|
|
|
|
activeSettings.ActiveMaterialKey = item.Value;
|
2017-09-20 11:12:13 -07:00
|
|
|
|
|
2019-02-05 11:22:22 -08:00
|
|
|
|
// Deactivate conflicting user overrides by iterating the Material preset we've just switched to
|
|
|
|
|
|
activeSettings.DeactivateConflictingUserOverrides(activeSettings.MaterialLayer);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else // set the temperature for the given extruder
|
|
|
|
|
|
{
|
|
|
|
|
|
var selectedMaterial = activeSettings.MaterialLayers.Where(l => l.LayerID == item.Value).FirstOrDefault();
|
|
|
|
|
|
if (selectedMaterial != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
selectedMaterial.TryGetValue(SettingsKey.temperature, out string _temperature);
|
|
|
|
|
|
activeSettings.SetValue(SettingsKey.temperature1, _temperature);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
activeSettings.SetValue(SettingsKey.temperature1, printer.Settings.GetValue(SettingsKey.temperature));
|
|
|
|
|
|
}
|
2017-09-20 11:12:13 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (layerType == NamedSettingsLayers.Quality)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (activeSettings.ActiveQualityKey != item.Value)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Restore deactivated user overrides by iterating the Quality preset we're coming off of
|
|
|
|
|
|
activeSettings.RestoreConflictingUserOverrides(activeSettings.QualityLayer);
|
|
|
|
|
|
|
|
|
|
|
|
activeSettings.ActiveQualityKey = item.Value;
|
|
|
|
|
|
|
|
|
|
|
|
// Deactivate conflicting user overrides by iterating the Quality preset we've just switched to
|
|
|
|
|
|
activeSettings.DeactivateConflictingUserOverrides(activeSettings.QualityLayer);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Ensure that activated or deactivated user overrides are always persisted to disk
|
|
|
|
|
|
activeSettings.Save();
|
|
|
|
|
|
|
|
|
|
|
|
UiThread.RunOnIdle(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var keyName in PrinterSettings.KnownSettings)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (settingBeforeChange[keyName] != printer.Settings.GetValue(keyName))
|
|
|
|
|
|
{
|
2018-11-12 17:20:59 -08:00
|
|
|
|
printer.Settings.OnSettingChanged(keyName);
|
2017-09-20 11:12:13 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
editButton.Enabled = item.Text != defaultMenuItemText;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void RebuildDropDownList()
|
|
|
|
|
|
{
|
|
|
|
|
|
pullDownContainer.CloseAllChildren();
|
2018-04-17 17:15:32 -07:00
|
|
|
|
pullDownContainer.AddChild(this.GetPulldownContainer());
|
2016-08-10 14:20:52 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-06-20 12:56:11 -07:00
|
|
|
|
private void SettingsLayers_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
|
2016-06-20 12:47:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
RebuildDropDownList();
|
|
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|