2022-04-12 11:46:09 -07:00
|
|
|
|
/*
|
|
|
|
|
|
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;
|
2022-04-25 10:13:31 -07:00
|
|
|
|
using MatterHackers.Agg.UI;
|
2022-04-12 11:46:09 -07:00
|
|
|
|
using MatterHackers.DataConverters3D;
|
|
|
|
|
|
using MatterHackers.Localizations;
|
|
|
|
|
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
|
|
|
|
|
using MatterHackers.PolygonMesh;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
2022-04-20 14:28:34 -07:00
|
|
|
|
using System.Linq;
|
2022-04-12 11:46:09 -07:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.DesignTools.Operations
|
|
|
|
|
|
{
|
|
|
|
|
|
[HideChildrenFromTreeView]
|
|
|
|
|
|
[RequiresPermissions]
|
|
|
|
|
|
[HideMeterialAndColor]
|
|
|
|
|
|
public class PartSettingsObject3D : Object3D, IEditorButtonProvider, IStaticThumbnail
|
|
|
|
|
|
{
|
|
|
|
|
|
public PartSettingsObject3D()
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "Part Settings".Localize();
|
2022-04-25 10:13:31 -07:00
|
|
|
|
|
|
|
|
|
|
// 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);
|
2022-04-12 11:46:09 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
2022-04-25 10:13:31 -07:00
|
|
|
|
private void UpdateSettingsDisplay()
|
2022-04-13 17:44:10 -07:00
|
|
|
|
{
|
2022-04-25 10:13:31 -07:00
|
|
|
|
var containingPrinter = this.ContainingPrinter();
|
|
|
|
|
|
|
2022-04-13 17:44:10 -07:00
|
|
|
|
if (containingPrinter != null)
|
|
|
|
|
|
{
|
2022-04-25 10:13:31 -07:00
|
|
|
|
// 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
|
2022-04-25 10:13:31 -07:00
|
|
|
|
containingPrinter.Bed.Scene.SelectedItem = null;
|
|
|
|
|
|
containingPrinter.Bed.Scene.SelectedItem = this;
|
|
|
|
|
|
}
|
2022-04-13 17:44:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
2022-04-25 10:13:31 -07:00
|
|
|
|
SettingsKey.z_offset,
|
2022-04-13 17:44:10 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2022-04-12 11:46:09 -07:00
|
|
|
|
public IEnumerable<EditorButtonData> GetEditorButtonsData()
|
|
|
|
|
|
{
|
2022-05-17 16:19:09 -07:00
|
|
|
|
if (ApplicationController.Instance.UserHasPermission(this))
|
2022-04-13 17:44:10 -07:00
|
|
|
|
{
|
2022-05-17 16:19:09 -07:00
|
|
|
|
var containingPrinter = this.ContainingPrinter();
|
|
|
|
|
|
if (containingPrinter != null)
|
2022-04-13 17:44:10 -07:00
|
|
|
|
{
|
2022-05-17 16:19:09 -07:00
|
|
|
|
yield return new EditorButtonData()
|
2022-04-13 17:44:10 -07:00
|
|
|
|
{
|
2022-05-17 16:19:09 -07:00
|
|
|
|
Action = () =>
|
2022-04-13 17:44:10 -07:00
|
|
|
|
{
|
2022-05-23 15:11:49 -07:00
|
|
|
|
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-04-13 17:44:10 -07:00
|
|
|
|
{
|
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))
|
|
|
|
|
|
{
|
2022-05-23 15:11:49 -07:00
|
|
|
|
editOverrides[setting.Key] = setting.Value;
|
2022-05-17 16:19:09 -07:00
|
|
|
|
}
|
2022-04-13 17:44:10 -07:00
|
|
|
|
}
|
2022-04-20 14:28:34 -07:00
|
|
|
|
|
2022-05-23 15:11:49 -07:00
|
|
|
|
foreach (var setting in editOverrides.ToList())
|
2022-04-20 14:28:34 -07:00
|
|
|
|
{
|
2022-05-17 16:19:09 -07:00
|
|
|
|
if (!SliceSettingsLayouts.ContainesKey(SliceSettingsLayouts.SliceSettings(), setting.Key)
|
|
|
|
|
|
|| !SliceSettingsTabView.CheckIfShouldBeShown(PrinterSettings.SettingsData[setting.Key], settingsContext))
|
|
|
|
|
|
{
|
2022-05-23 15:11:49 -07:00
|
|
|
|
editOverrides.Remove(setting.Key);
|
2022-05-17 16:19:09 -07:00
|
|
|
|
}
|
2022-04-20 14:28:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-23 15:11:49 -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()
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2022-04-13 17:44:10 -07:00
|
|
|
|
|
|
|
|
|
|
|
2022-04-12 11:46:09 -07:00
|
|
|
|
yield return new EditorButtonData()
|
|
|
|
|
|
{
|
|
|
|
|
|
Action = () =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var settings = new PrinterSettings();
|
2022-05-23 15:11:49 -07:00
|
|
|
|
var startingOverrides = new PrinterSettingsLayer(Overrides);
|
|
|
|
|
|
var editOverrides = new PrinterSettingsLayer(Overrides);
|
|
|
|
|
|
settings.GetSceneLayer = () => editOverrides;
|
2022-04-12 11:46:09 -07:00
|
|
|
|
var printer = new PrinterConfig(settings);
|
2022-04-19 09:50:45 -07:00
|
|
|
|
if (containingPrinter != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
printer = containingPrinter;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// set this after the PrinterConfig is constructed to change it to overrides
|
2022-04-12 11:46:09 -07:00
|
|
|
|
// set this after the PrinterConfig is constructed to change it to overrides
|
2022-05-23 15:11:49 -07:00
|
|
|
|
settings.GetSceneLayer = () => editOverrides;
|
2022-04-12 11:46:09 -07:00
|
|
|
|
|
2022-05-23 15:11:49 -07:00
|
|
|
|
var presetsContext = new PresetsContext(null, editOverrides)
|
2022-04-12 11:46:09 -07:00
|
|
|
|
{
|
|
|
|
|
|
LayerType = NamedSettingsLayers.Scene,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2022-04-20 14:28:34 -07:00
|
|
|
|
var editPartSettingsPresetsPage = new SlicePresetsPage(printer, presetsContext, false);
|
|
|
|
|
|
editPartSettingsPresetsPage.Closed += (s, e2) =>
|
2022-04-12 11:46:09 -07:00
|
|
|
|
{
|
|
|
|
|
|
ApplicationController.Instance.AcitveSlicePresetsPage = null;
|
|
|
|
|
|
|
2022-05-23 15:11:49 -07:00
|
|
|
|
// 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();
|
|
|
|
|
|
}));
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2022-04-20 14:28:34 -07:00
|
|
|
|
ApplicationController.Instance.AcitveSlicePresetsPage = editPartSettingsPresetsPage;
|
|
|
|
|
|
DialogWindow.Show(editPartSettingsPresetsPage);
|
2022-04-12 11:46:09 -07:00
|
|
|
|
},
|
|
|
|
|
|
Name = "Edit".Localize(),
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|