mattercontrol/original/MatterControl.Printing/Settings/SettingsLayout.cs

183 lines
5.8 KiB
C#
Raw Permalink Normal View History

/*
Copyright (c) 2019, Kevin Pope, John Lewin
2014-04-05 15:51:13 -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-04-05 15:51:13 -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-04-05 15:51:13 -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-04-05 15:51:13 -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-04-05 15:51:13 -07:00
either expressed or implied, of the FreeBSD Project.
*/
2015-04-08 15:20:10 -07:00
2014-04-05 15:51:13 -07:00
using System;
2014-01-29 19:09:30 -08:00
using System.Collections.Generic;
namespace MatterHackers.MatterControl.SlicerConfiguration
2014-01-29 19:09:30 -08:00
{
public class SettingsLayout
2015-04-08 15:20:10 -07:00
{
public SettingsSection[] SlicingSections { get; } =
new[]
{
new SettingsSection("Slice Simple"),
new SettingsSection("Slice Intermediate"),
new SettingsSection("Slice Advanced")
};
public SettingsSection[] PrinterSections { get; } =
new[]
{
new SettingsSection("Printer Simple"),
new SettingsSection("Printer Intermediate"),
new SettingsSection("Printer Advanced")
};
public SettingsSection AllSliceSettings => SlicingSections[2];
public SettingsSection AllPrinterSettings => PrinterSections[2];
2015-04-08 15:20:10 -07:00
internal SettingsLayout()
2015-04-08 15:20:10 -07:00
{
// slice settings
CreateLayout(SlicingSections[0], SliceSettingsLayouts.SliceSettings(), (setting) =>
{
if (PrinterSettings.SettingsData.TryGetValue(setting, out SliceSettingData data))
{
2021-01-22 17:51:25 -08:00
return data.RequiredDisplayDetail == SliceSettingData.DisplayDetailRequired.Simple;
}
return false;
});
CreateLayout(SlicingSections[1], SliceSettingsLayouts.SliceSettings(), (setting) =>
{
if (PrinterSettings.SettingsData.TryGetValue(setting, out SliceSettingData data))
{
2021-01-22 17:51:25 -08:00
return data.RequiredDisplayDetail != SliceSettingData.DisplayDetailRequired.Advanced;
}
return false;
});
CreateLayout(SlicingSections[2], SliceSettingsLayouts.SliceSettings());
// printer settings
CreateLayout(PrinterSections[0], SliceSettingsLayouts.PrinterSettings(), (setting) =>
{
if (PrinterSettings.SettingsData.TryGetValue(setting, out SliceSettingData data))
{
2021-01-22 17:51:25 -08:00
return data.RequiredDisplayDetail == SliceSettingData.DisplayDetailRequired.Simple;
}
return false;
});
CreateLayout(PrinterSections[1], SliceSettingsLayouts.PrinterSettings(), (setting) =>
{
if (PrinterSettings.SettingsData.TryGetValue(setting, out SliceSettingData data))
{
2021-01-22 17:51:25 -08:00
return data.RequiredDisplayDetail != SliceSettingData.DisplayDetailRequired.Advanced;
}
return false;
});
CreateLayout(PrinterSections[2], SliceSettingsLayouts.PrinterSettings());
2015-04-08 15:20:10 -07:00
}
private void CreateLayout(SettingsSection section, (string categoryName, (string groupName, string[] settings)[] groups)[] layout, Func<string, bool> includeSetting = null)
2015-04-08 15:20:10 -07:00
{
foreach (var (categoryName, groups) in layout)
2015-04-08 15:20:10 -07:00
{
var categoryToAddTo = new Category(categoryName, section);
section.Categories.Add(categoryToAddTo);
2015-04-08 15:20:10 -07:00
foreach (var (groupName, settings) in groups)
2015-04-08 15:20:10 -07:00
{
var groupToAddTo = new Group(groupName, categoryToAddTo);
categoryToAddTo.Groups.Add(groupToAddTo);
foreach (var setting in settings)
2015-04-08 15:20:10 -07:00
{
if (PrinterSettings.SettingsData.TryGetValue(setting, out SliceSettingData data)
&& includeSetting?.Invoke(setting) != false)
{
groupToAddTo.Settings.Add(data);
data.OrganizerGroup = groupToAddTo;
section.AddSetting(data.SlicerConfigName, groupToAddTo);
}
2015-04-08 15:20:10 -07:00
}
}
}
}
/// <summary>
/// This is the 'Slice Settings' or the 'Printer' settings sections
/// </summary>
public class SettingsSection
2018-01-13 18:40:35 -08:00
{
2020-06-21 13:41:37 -07:00
private Dictionary<string, Group> subgroups = new Dictionary<string, Group>();
2018-01-13 18:40:35 -08:00
public SettingsSection(string settingsSectionName)
2018-01-13 18:40:35 -08:00
{
this.Name = settingsSectionName;
2018-01-13 18:40:35 -08:00
}
public string Name { get; set; }
2020-06-21 09:34:53 -07:00
public List<Category> Categories { get; private set; } = new List<Category>();
2018-01-13 18:40:35 -08:00
2020-06-21 13:41:37 -07:00
internal void AddSetting(string slicerConfigName, Group organizerGroup)
2018-01-13 18:40:35 -08:00
{
2020-06-21 13:41:37 -07:00
subgroups.Add(slicerConfigName, organizerGroup);
2018-01-13 18:40:35 -08:00
}
public bool ContainsKey(string settingsKey) => subgroups.ContainsKey(settingsKey);
2018-01-13 18:40:35 -08:00
}
public class Category
{
public Category(string categoryName, SettingsSection settingsSection)
2018-01-13 18:40:35 -08:00
{
this.Name = categoryName;
this.SettingsSection = settingsSection;
2018-01-13 18:40:35 -08:00
}
public string Name { get; set; }
2020-06-21 09:34:53 -07:00
public List<Group> Groups { get; private set; } = new List<Group>();
2018-01-13 18:40:35 -08:00
public SettingsSection SettingsSection { get; }
2018-01-13 18:40:35 -08:00
}
public class Group
{
public Group(string displayName, Category organizerCategory)
{
this.Name = displayName;
this.Category = organizerCategory;
}
public string Name { get; }
public List<SliceSettingData> Settings { get; private set; } = new List<SliceSettingData>();
2020-06-21 13:41:37 -07:00
public Category Category { get; }
2018-01-13 18:40:35 -08:00
}
2015-04-08 15:20:10 -07:00
}
}