mattercontrol/MatterControlLib/DesignTools/Operations/PartSettingsObject3D.cs

267 lines
11 KiB
C#
Raw Normal View History

/*
Copyright (c) 2022, 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.Platform;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.PolygonMesh;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace MatterHackers.MatterControl.DesignTools.Operations
{
[HideChildrenFromTreeView]
[RequiresPermissions]
[HideMeterialAndColor]
public class PartSettingsObject3D : Object3D, IEditorButtonProvider, IStaticThumbnail
{
public PartSettingsObject3D()
{
Name = "Part Settings".Localize();
// Once we are done loading (json load will happen after creation)
// Make sure any settings are updated
UiThread.RunOnIdle(() =>
{
// check if the object is part of the scene (it could just be a memory copy)
if (Parent != null)
{
UpdateSettingsDisplay();
}
}, .5);
}
public PrinterSettingsLayer Overrides { get; set; } = new PrinterSettingsLayer();
public static async Task<PartSettingsObject3D> Create()
{
var item = new PartSettingsObject3D();
await item.Rebuild();
return item;
}
private static object loadLock = new object();
private static IObject3D sliceSettingsObject;
public override Mesh Mesh
{
get
{
if (this.Children.Count == 0)
{
lock (loadLock)
{
if (sliceSettingsObject == null)
{
sliceSettingsObject = MeshContentProvider.LoadMCX(StaticData.Instance.OpenStream(Path.Combine("Stls", "part_settings.mcx")));
}
this.Children.Modify((list) =>
{
list.Clear();
list.Add(sliceSettingsObject.Clone());
});
}
}
return null;
}
set => base.Mesh = value;
}
public override bool Printable => false;
public string ThumbnailName => nameof(PartSettingsObject3D);
private void UpdateSettingsDisplay()
{
var containingPrinter = this.ContainingPrinter();
if (containingPrinter != null)
{
// this will check if the current scene layer is the same as the last update
containingPrinter.Settings.GetSceneLayer();
// ApplicationController.Instance.ReloadSettings(containingPrinter);
if (containingPrinter.Bed.Scene.SelectedItem == this)
{
2023-04-27 11:45:58 -07:00
// refresh the properties panel by unselecting and selecting
containingPrinter.Bed.Scene.SelectedItem = null;
containingPrinter.Bed.Scene.SelectedItem = this;
}
}
}
public static HashSet<string> settingsToIgnore = new HashSet<string>()
{
SettingsKey.spiral_vase,
SettingsKey.layer_to_pause,
SettingsKey.perimeter_acceleration,
SettingsKey.default_acceleration,
SettingsKey.t1_extrusion_move_speed_multiplier,
SettingsKey.bed_surface,
SettingsKey.brim_extruder,
SettingsKey.support_material_extruder,
SettingsKey.support_material_interface_extruder,
SettingsKey.material_color,
SettingsKey.material_color_1,
SettingsKey.material_color_2,
SettingsKey.material_color_3,
SettingsKey.filament_diameter,
SettingsKey.filament_density,
SettingsKey.filament_cost,
SettingsKey.temperature,
SettingsKey.temperature1,
SettingsKey.temperature2,
SettingsKey.temperature3,
SettingsKey.bed_temperature,
SettingsKey.bed_temperature_blue_tape,
SettingsKey.bed_temperature_buildtak,
SettingsKey.bed_temperature_garolite,
SettingsKey.bed_temperature_glass,
SettingsKey.bed_temperature_kapton,
SettingsKey.bed_temperature_pei,
SettingsKey.bed_temperature_pp,
SettingsKey.inactive_cool_down,
SettingsKey.seconds_to_reheat,
SettingsKey.z_offset,
};
public IEnumerable<EditorButtonData> GetEditorButtonsData()
{
2022-05-17 16:19:09 -07:00
if (ApplicationController.Instance.UserHasPermission(this))
{
2022-05-17 16:19:09 -07:00
var containingPrinter = this.ContainingPrinter();
if (containingPrinter != null)
{
2022-05-17 16:19:09 -07:00
yield return new EditorButtonData()
{
2022-05-17 16:19:09 -07:00
Action = () =>
{
var startingOverrides = new PrinterSettingsLayer(Overrides);
var editOverrides = new PrinterSettingsLayer(Overrides);
2022-05-17 16:19:09 -07:00
var settingsContext = new SettingsContext(containingPrinter, null, NamedSettingsLayers.All);
foreach (var setting in containingPrinter.Settings.UserLayer.ToList())
{
2022-05-17 16:19:09 -07:00
var data = SliceSettingsRow.GetStyleData(containingPrinter, ApplicationController.Instance.Theme, settingsContext, setting.Key, true);
if (!settingsToIgnore.Contains(setting.Key)
&& data.showRestoreButton
&& SliceSettingsLayouts.ContainesKey(SliceSettingsLayouts.SliceSettings(), setting.Key)
&& SliceSettingsTabView.CheckIfShouldBeShown(PrinterSettings.SettingsData[setting.Key], settingsContext))
{
editOverrides[setting.Key] = setting.Value;
2022-05-17 16:19:09 -07:00
}
}
foreach (var setting in editOverrides.ToList())
{
2022-05-17 16:19:09 -07:00
if (!SliceSettingsLayouts.ContainesKey(SliceSettingsLayouts.SliceSettings(), setting.Key)
|| !SliceSettingsTabView.CheckIfShouldBeShown(PrinterSettings.SettingsData[setting.Key], settingsContext))
{
editOverrides.Remove(setting.Key);
2022-05-17 16:19:09 -07:00
}
}
var scene = this.ContainingScene();
scene.UndoBuffer.AddAndDo(new UndoRedoActions(() =>
{
Overrides = new PrinterSettingsLayer(startingOverrides);
UpdateSettingsDisplay();
},
() =>
{
Overrides = new PrinterSettingsLayer(editOverrides);
UpdateSettingsDisplay();
}));
2022-05-17 16:19:09 -07:00
},
Name = "Add User Overrides".Localize(),
HelpText = "Copy in all current user overides".Localize()
};
}
yield return new EditorButtonData()
{
Action = () =>
{
var settings = new PrinterSettings();
var startingOverrides = new PrinterSettingsLayer(Overrides);
var editOverrides = new PrinterSettingsLayer(Overrides);
settings.GetSceneLayer = () => editOverrides;
var printer = new PrinterConfig(settings);
if (containingPrinter != null)
{
printer = containingPrinter;
}
// set this after the PrinterConfig is constructed to change it to overrides
// set this after the PrinterConfig is constructed to change it to overrides
settings.GetSceneLayer = () => editOverrides;
var presetsContext = new PresetsContext(null, editOverrides)
{
LayerType = NamedSettingsLayers.Scene,
};
var editPartSettingsPresetsPage = new SlicePresetsPage(printer, presetsContext, false);
editPartSettingsPresetsPage.Closed += (s, e2) =>
{
ApplicationController.Instance.AcitveSlicePresetsPage = null;
// push the new settings into this object
var scene = this.ContainingScene();
scene.UndoBuffer.AddAndDo(new UndoRedoActions(() =>
{
Overrides = new PrinterSettingsLayer(startingOverrides);
UpdateSettingsDisplay();
},
() =>
{
Overrides = new PrinterSettingsLayer(editOverrides);
UpdateSettingsDisplay();
}));
};
ApplicationController.Instance.AcitveSlicePresetsPage = editPartSettingsPresetsPage;
DialogWindow.Show(editPartSettingsPresetsPage);
},
Name = "Edit".Localize(),
};
}
}
}
}