2014-03-30 17:54:05 -07:00
|
|
|
|
/*
|
2016-04-18 11:31:31 -07:00
|
|
|
|
Copyright (c) 2016, Lars Brubaker, 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.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2016-05-07 18:23:40 -07:00
|
|
|
|
using MatterHackers.Agg;
|
2014-03-30 17:54:05 -07:00
|
|
|
|
using MatterHackers.Agg.UI;
|
|
|
|
|
|
using MatterHackers.Localizations;
|
2016-05-07 18:23:40 -07:00
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
using MatterHackers.MatterControl.DataStorage;
|
2016-04-18 11:31:31 -07:00
|
|
|
|
using MatterHackers.MatterControl.DataStorage.ClassicDB;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
using MatterHackers.VectorMath;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2016-06-20 12:47:10 -07:00
|
|
|
|
using System.Collections.ObjectModel;
|
2016-05-16 16:21:42 -07:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text.RegularExpressions;
|
2017-09-03 11:48:08 -07:00
|
|
|
|
using MatterHackers.MatterControl.PrinterCommunication;
|
2014-03-30 17:54:05 -07:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.SlicerConfiguration
|
|
|
|
|
|
{
|
2016-05-16 16:21:42 -07:00
|
|
|
|
public class PresetsContext
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2016-06-20 12:47:10 -07:00
|
|
|
|
public ObservableCollection<PrinterSettingsLayer> PresetLayers { get; }
|
2016-06-15 14:50:12 -07:00
|
|
|
|
public PrinterSettingsLayer PersistenceLayer { get; set; }
|
2016-05-16 16:21:42 -07:00
|
|
|
|
public Action<string> SetAsActive { get; set; }
|
2016-06-16 11:52:56 -07:00
|
|
|
|
public Action DeleteLayer { get; set; }
|
|
|
|
|
|
|
2016-05-16 16:21:42 -07:00
|
|
|
|
public NamedSettingsLayers LayerType { get; set; }
|
|
|
|
|
|
|
2016-06-20 12:47:10 -07:00
|
|
|
|
public PresetsContext(ObservableCollection<PrinterSettingsLayer> settingsLayers, PrinterSettingsLayer activeLayer)
|
2016-05-16 16:21:42 -07:00
|
|
|
|
{
|
2016-06-08 19:02:34 -07:00
|
|
|
|
this.PersistenceLayer = activeLayer;
|
|
|
|
|
|
this.PresetLayers = settingsLayers;
|
2016-05-16 16:21:42 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-17 12:22:33 -07:00
|
|
|
|
public class SlicePresetsPage : DialogPage
|
2016-05-16 16:21:42 -07:00
|
|
|
|
{
|
2016-05-17 17:12:19 -07:00
|
|
|
|
private static Regex numberMatch = new Regex("\\s*\\(\\d+\\)", RegexOptions.Compiled);
|
|
|
|
|
|
|
2016-05-16 16:21:42 -07:00
|
|
|
|
private PresetsContext presetsContext;
|
2017-09-17 01:11:18 -07:00
|
|
|
|
private PrinterConfig printer;
|
2016-05-16 16:21:42 -07:00
|
|
|
|
|
2018-06-17 12:22:33 -07:00
|
|
|
|
public SlicePresetsPage(PrinterConfig printer, PresetsContext presetsContext)
|
2018-06-19 17:34:30 -07:00
|
|
|
|
: base("Close".Localize())
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2016-05-16 16:21:42 -07:00
|
|
|
|
this.presetsContext = presetsContext;
|
2017-09-17 01:11:18 -07:00
|
|
|
|
this.printer = printer;
|
2016-05-07 18:23:40 -07:00
|
|
|
|
this.AlwaysOnTopOfMain = true;
|
|
|
|
|
|
|
2018-06-17 12:22:33 -07:00
|
|
|
|
this.WindowTitle = "Slice Presets Editor".Localize();
|
|
|
|
|
|
this.WindowSize = new Vector2(640, 480);
|
|
|
|
|
|
this.AnchorAll();
|
2016-05-07 18:23:40 -07:00
|
|
|
|
|
2018-06-17 12:22:33 -07:00
|
|
|
|
this.headerRow.Visible = false;
|
2018-11-03 10:12:27 -07:00
|
|
|
|
this.contentRow.Padding = 0;
|
2016-05-07 18:23:40 -07:00
|
|
|
|
|
2018-11-03 10:12:27 -07:00
|
|
|
|
contentRow.BackgroundColor = Color.Transparent;
|
2016-05-17 17:12:19 -07:00
|
|
|
|
|
2018-08-03 07:38:47 -07:00
|
|
|
|
var inlineNameEdit = new InlineStringEdit(presetsContext.PersistenceLayer.Name, theme, presetsContext.LayerType.ToString() + " Name", boldFont: true);
|
|
|
|
|
|
inlineNameEdit.ValueChanged += (s, e) =>
|
2018-01-17 23:43:05 -08:00
|
|
|
|
{
|
2018-08-03 07:38:47 -07:00
|
|
|
|
printer.Settings.SetValue(SettingsKey.layer_name, inlineNameEdit.Text, presetsContext.PersistenceLayer);
|
2017-01-11 14:27:33 -08:00
|
|
|
|
};
|
2018-11-03 10:12:27 -07:00
|
|
|
|
contentRow.AddChild(inlineNameEdit);
|
2016-05-07 18:23:40 -07:00
|
|
|
|
|
2018-06-17 12:22:33 -07:00
|
|
|
|
var sliceSettingsWidget = CreateSliceSettingsWidget(printer, presetsContext.PersistenceLayer);
|
2018-11-03 10:12:27 -07:00
|
|
|
|
contentRow.AddChild(sliceSettingsWidget);
|
2016-05-07 18:23:40 -07:00
|
|
|
|
|
2018-06-17 12:22:33 -07:00
|
|
|
|
var duplicateButton = theme.CreateDialogButton("Duplicate".Localize());
|
2016-05-07 18:23:40 -07:00
|
|
|
|
duplicateButton.Click += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle(() =>
|
|
|
|
|
|
{
|
2018-08-03 07:38:47 -07:00
|
|
|
|
string sanitizedName = numberMatch.Replace(inlineNameEdit.Text, "").Trim();
|
2017-12-06 16:29:31 -08:00
|
|
|
|
string newProfileName = agg_basics.GetNonCollidingName(sanitizedName, presetsContext.PresetLayers.Select(preset => preset.ValueOrDefault(SettingsKey.layer_name)));
|
2016-05-16 16:21:42 -07:00
|
|
|
|
|
|
|
|
|
|
var clonedLayer = presetsContext.PersistenceLayer.Clone();
|
|
|
|
|
|
clonedLayer.Name = newProfileName;
|
2016-06-08 19:02:34 -07:00
|
|
|
|
presetsContext.PresetLayers.Add(clonedLayer);
|
2016-05-16 16:21:42 -07:00
|
|
|
|
|
2016-06-15 12:58:36 -07:00
|
|
|
|
presetsContext.SetAsActive(clonedLayer.LayerID);
|
2016-05-17 17:12:19 -07:00
|
|
|
|
presetsContext.PersistenceLayer = clonedLayer;
|
|
|
|
|
|
|
2018-06-17 12:22:33 -07:00
|
|
|
|
sliceSettingsWidget.Close();
|
|
|
|
|
|
sliceSettingsWidget = CreateSliceSettingsWidget(printer, clonedLayer);
|
2018-11-03 10:12:27 -07:00
|
|
|
|
contentRow.AddChild(sliceSettingsWidget);
|
2016-05-17 17:12:19 -07:00
|
|
|
|
|
2018-08-03 07:38:47 -07:00
|
|
|
|
inlineNameEdit.Text = newProfileName;
|
2016-05-07 18:23:40 -07:00
|
|
|
|
});
|
|
|
|
|
|
};
|
2018-06-17 12:22:33 -07:00
|
|
|
|
this.AddPageAction(duplicateButton);
|
2016-05-07 18:23:40 -07:00
|
|
|
|
|
2018-06-17 12:22:33 -07:00
|
|
|
|
var deleteButton = theme.CreateDialogButton("Delete".Localize());
|
2016-06-16 11:52:56 -07:00
|
|
|
|
deleteButton.Click += (s, e) =>
|
2016-05-07 18:23:40 -07:00
|
|
|
|
{
|
2016-06-16 11:52:56 -07:00
|
|
|
|
UiThread.RunOnIdle(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
presetsContext.DeleteLayer();
|
2018-06-19 15:02:25 -07:00
|
|
|
|
this.DialogWindow.Close();
|
2016-06-16 11:52:56 -07:00
|
|
|
|
});
|
2016-05-07 18:23:40 -07:00
|
|
|
|
};
|
2018-06-17 12:22:33 -07:00
|
|
|
|
this.AddPageAction(deleteButton);
|
|
|
|
|
|
}
|
2016-05-07 18:23:40 -07:00
|
|
|
|
|
2018-06-17 12:22:33 -07:00
|
|
|
|
private GuiWidget CreateSliceSettingsWidget(PrinterConfig printer, PrinterSettingsLayer persistenceLayer)
|
|
|
|
|
|
{
|
|
|
|
|
|
var settingsContext = new SettingsContext(
|
|
|
|
|
|
printer,
|
|
|
|
|
|
new List<PrinterSettingsLayer>
|
|
|
|
|
|
{
|
|
|
|
|
|
persistenceLayer,
|
2018-10-05 09:24:57 -07:00
|
|
|
|
printer.Settings.OemLayer,
|
|
|
|
|
|
printer.Settings.BaseLayer
|
2018-06-17 12:22:33 -07:00
|
|
|
|
},
|
|
|
|
|
|
presetsContext.LayerType);
|
|
|
|
|
|
|
2018-07-12 09:22:28 -07:00
|
|
|
|
return new SliceSettingsWidget(printer, settingsContext, theme)
|
2016-05-07 18:23:40 -07:00
|
|
|
|
{
|
2018-06-17 12:22:33 -07:00
|
|
|
|
ShowControlBar = false
|
2016-05-07 18:23:40 -07:00
|
|
|
|
};
|
2018-06-17 12:22:33 -07:00
|
|
|
|
}
|
2016-05-07 18:23:40 -07:00
|
|
|
|
|
2018-06-17 12:22:33 -07:00
|
|
|
|
public override void OnLoad(EventArgs args)
|
|
|
|
|
|
{
|
2018-06-19 15:02:25 -07:00
|
|
|
|
this.DialogWindow.Padding = 0;
|
2018-06-17 12:22:33 -07:00
|
|
|
|
footerRow.Padding = theme.DefaultContainerPadding;
|
|
|
|
|
|
footerRow.Margin = 0;
|
|
|
|
|
|
footerRow.Border = new BorderDouble(top: 1);
|
|
|
|
|
|
footerRow.BorderColor = theme.TabBarBackground;
|
|
|
|
|
|
base.OnLoad(args);
|
2016-05-07 18:23:40 -07:00
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
2017-09-03 18:50:44 +03:00
|
|
|
|
}
|