2017-06-29 17:11:17 -07:00
|
|
|
|
/*
|
2019-01-15 12:23:40 -08:00
|
|
|
|
Copyright (c) 2019, Lars Brubaker, John Lewin
|
2014-02-15 18:06:03 -08: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-02-15 18:06:03 -08: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-02-15 18:06:03 -08: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-02-15 18:06:03 -08: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-02-15 18:06:03 -08:00
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2014-02-15 18:06:03 -08:00
|
|
|
|
using System;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
using System.Collections.Generic;
|
2014-06-11 14:52:58 -07:00
|
|
|
|
using System.IO;
|
2018-02-05 17:37:42 -08:00
|
|
|
|
using System.Linq;
|
2014-06-11 14:52:58 -07:00
|
|
|
|
using System.Threading;
|
2017-06-29 19:42:20 -07:00
|
|
|
|
using System.Threading.Tasks;
|
2017-06-29 17:11:17 -07:00
|
|
|
|
using MatterHackers.Agg;
|
|
|
|
|
|
using MatterHackers.DataConverters3D;
|
|
|
|
|
|
using MatterHackers.PolygonMesh;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2014-02-15 18:06:03 -08:00
|
|
|
|
namespace MatterHackers.MatterControl.SlicerConfiguration
|
2014-01-29 19:09:30 -08:00
|
|
|
|
{
|
2017-10-17 12:42:52 -07:00
|
|
|
|
public static class Slicer
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2019-05-02 15:29:51 -07:00
|
|
|
|
public static List<bool> ExtrudersUsed = new List<bool>();
|
|
|
|
|
|
|
2018-09-23 19:22:44 -07:00
|
|
|
|
public static bool RunInProcess { get; set; } = false;
|
2017-10-16 17:09:00 -07:00
|
|
|
|
|
2019-07-02 14:02:35 -07:00
|
|
|
|
public static void GetExtrudersUsed(List<bool> extrudersUsed, IEnumerable<IObject3D> printableItems, PrinterSettings settings, bool checkForMeshFile)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2019-05-14 18:20:02 -07:00
|
|
|
|
extrudersUsed.Clear();
|
2017-12-11 14:15:50 -08:00
|
|
|
|
|
2019-06-27 09:27:16 -07:00
|
|
|
|
if (!printableItems.Any())
|
2019-05-14 18:20:02 -07:00
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2019-06-27 09:27:16 -07:00
|
|
|
|
int extruderCount = settings.GetValue<int>(SettingsKey.extruder_count);
|
2019-05-29 07:54:31 -07:00
|
|
|
|
// Make sure we only consider 1 extruder if in spiral vase mode
|
2019-06-27 09:27:16 -07:00
|
|
|
|
if (settings.GetValue<bool>(SettingsKey.spiral_vase)
|
2019-05-31 11:43:21 -07:00
|
|
|
|
&& extrudersUsed.Count(used => used == true) > 1)
|
2019-05-29 07:54:31 -07:00
|
|
|
|
{
|
|
|
|
|
|
extruderCount = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
for (int extruderIndex = 0; extruderIndex < extruderCount; extruderIndex++)
|
|
|
|
|
|
{
|
2019-05-14 18:20:02 -07:00
|
|
|
|
extrudersUsed.Add(false);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-01-04 21:18:57 -08:00
|
|
|
|
// If we have support enabled and are using an extruder other than 0 for it
|
2019-07-02 14:02:35 -07:00
|
|
|
|
if (printableItems.Any(i => i.WorldOutputType() == PrintOutputTypes.Support))
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2019-06-27 09:27:16 -07:00
|
|
|
|
if (settings.GetValue<int>(SettingsKey.support_material_extruder) != 0)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2020-06-05 13:00:39 -07:00
|
|
|
|
int supportExtruder = Math.Max(0, Math.Min(extruderCount - 1, settings.GetValue<int>(SettingsKey.support_material_extruder)));
|
|
|
|
|
|
extrudersUsed[supportExtruder] = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (settings.GetValue<int>(SettingsKey.support_material_interface_extruder) != 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
int supportExtruder = Math.Max(0, Math.Min(extruderCount - 1, settings.GetValue<int>(SettingsKey.support_material_interface_extruder)));
|
2019-05-14 18:20:02 -07:00
|
|
|
|
extrudersUsed[supportExtruder] = true;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If we have raft enabled and are using an extruder other than 0 for it
|
2019-06-27 09:27:16 -07:00
|
|
|
|
if (settings.GetValue<bool>(SettingsKey.create_raft))
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2019-06-27 09:27:16 -07:00
|
|
|
|
if (settings.GetValue<int>(SettingsKey.raft_extruder) != 0)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2019-06-27 09:27:16 -07:00
|
|
|
|
int raftExtruder = Math.Max(0, Math.Min(extruderCount - 1, settings.GetValue<int>(SettingsKey.raft_extruder) - 1));
|
2019-05-14 18:20:02 -07:00
|
|
|
|
extrudersUsed[raftExtruder] = true;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-14 18:20:02 -07:00
|
|
|
|
for (int extruderIndex = 0; extruderIndex < extruderCount; extruderIndex++)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2019-06-27 09:27:16 -07:00
|
|
|
|
IEnumerable<IObject3D> itemsThisExtruder = GetItemsForExtruder(printableItems, extruderCount, extruderIndex, checkForMeshFile);
|
2019-05-14 18:20:02 -07:00
|
|
|
|
extrudersUsed[extruderIndex] |= itemsThisExtruder.Any();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-11-16 22:13:35 -08:00
|
|
|
|
|
2019-05-14 18:20:02 -07:00
|
|
|
|
public static bool T1OrGreaterUsed(PrinterConfig printer)
|
|
|
|
|
|
{
|
2019-06-27 09:27:16 -07:00
|
|
|
|
var scene = printer.Bed.Scene;
|
|
|
|
|
|
|
2019-05-14 18:20:02 -07:00
|
|
|
|
var extrudersUsed = new List<bool>();
|
2019-07-02 14:02:35 -07:00
|
|
|
|
Slicer.GetExtrudersUsed(extrudersUsed, printer.PrintableItems(scene), printer.Settings, false);
|
2019-06-27 09:27:16 -07:00
|
|
|
|
|
2019-05-14 18:20:02 -07:00
|
|
|
|
for (int i = 1; i < extrudersUsed.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (extrudersUsed[i])
|
2018-07-08 16:07:22 -07:00
|
|
|
|
{
|
2019-05-14 18:20:02 -07:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-02-05 17:37:42 -08:00
|
|
|
|
|
2019-05-14 18:20:02 -07:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2019-06-27 09:27:16 -07:00
|
|
|
|
public static IEnumerable<IObject3D> GetItemsForExtruder(IEnumerable<IObject3D> meshItemsOnBuildPlate, int extruderCount, int extruderIndex, bool checkForMeshFile)
|
2019-05-14 18:20:02 -07:00
|
|
|
|
{
|
|
|
|
|
|
var itemsThisExtruder = meshItemsOnBuildPlate.Where((item) =>
|
|
|
|
|
|
(!checkForMeshFile || (File.Exists(item.MeshPath) // Drop missing files
|
|
|
|
|
|
|| File.Exists(Path.Combine(Object3D.AssetsPath, item.MeshPath))))
|
|
|
|
|
|
&& (item.WorldMaterialIndex() == extruderIndex
|
|
|
|
|
|
|| (extruderIndex == 0
|
|
|
|
|
|
&& (item.WorldMaterialIndex() >= extruderCount || item.WorldMaterialIndex() == -1)))
|
|
|
|
|
|
&& (item.WorldOutputType() == PrintOutputTypes.Solid || item.WorldOutputType() == PrintOutputTypes.Default));
|
2017-06-29 17:11:17 -07:00
|
|
|
|
|
2019-06-27 09:27:16 -07:00
|
|
|
|
return itemsThisExtruder;
|
2015-12-14 08:29:24 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-09 18:11:55 -08:00
|
|
|
|
public static Task<bool> SliceItem(IObject3D object3D, string gcodeFilePath, PrinterConfig printer, IProgress<ProgressStatus> progressReporter, CancellationToken cancellationToken)
|
2017-06-29 19:42:20 -07:00
|
|
|
|
{
|
2019-07-02 14:02:35 -07:00
|
|
|
|
return printer.Settings.Slicer.Slice(printer.PrintableItems(object3D), printer.Settings, gcodeFilePath, progressReporter, cancellationToken);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-08-20 02:34:39 -07:00
|
|
|
|
}
|