Convert ConditionallyCancelPrint to extension method
- Extract printer extension methods to common class
This commit is contained in:
parent
4ce363e29b
commit
a7385aa057
4 changed files with 134 additions and 91 deletions
|
|
@ -37,6 +37,7 @@ using MatterHackers.Agg;
|
|||
using MatterHackers.Agg.Image;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.DataConverters3D;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl;
|
||||
using MatterHackers.MatterControl.DesignTools.EditableTypes;
|
||||
using MatterHackers.MatterControl.DesignTools.Operations;
|
||||
|
|
@ -231,67 +232,6 @@ namespace MatterHackers.MeshVisualizer
|
|||
{
|
||||
return (materialIndex == -1) ? unassignedColor : ColorF.FromHSL(materialIndex / 10.0, .99, .49).ToColor();
|
||||
}
|
||||
|
||||
public static bool InsideBuildVolume(this PrinterConfig printerConfig, IObject3D item)
|
||||
{
|
||||
if(item.Mesh == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var worldMatrix = item.WorldMatrix();
|
||||
// probably need , true (require precision)
|
||||
var aabb = item.Mesh.GetAxisAlignedBoundingBox(worldMatrix);
|
||||
|
||||
var bed = printerConfig.Bed;
|
||||
|
||||
if (bed.BuildHeight > 0
|
||||
&& aabb.maxXYZ.Z >= bed.BuildHeight
|
||||
|| aabb.maxXYZ.Z <= 0)
|
||||
{
|
||||
// object completely below the bed or any part above the build volume
|
||||
return false;
|
||||
}
|
||||
|
||||
switch(bed.BedShape)
|
||||
{
|
||||
case BedShape.Rectangular:
|
||||
if(aabb.minXYZ.X < bed.BedCenter.X - bed.ViewerVolume.X/2
|
||||
|| aabb.maxXYZ.X > bed.BedCenter.X + bed.ViewerVolume.X / 2
|
||||
|| aabb.minXYZ.Y < bed.BedCenter.Y - bed.ViewerVolume.Y / 2
|
||||
|| aabb.maxXYZ.Y > bed.BedCenter.Y + bed.ViewerVolume.Y / 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case BedShape.Circular:
|
||||
// This could be much better if it checked the actual vertex data of the mesh against the cylinder
|
||||
// first check if any of it is outside the bed rect
|
||||
if (aabb.minXYZ.X < bed.BedCenter.X - bed.ViewerVolume.X / 2
|
||||
|| aabb.maxXYZ.X > bed.BedCenter.X + bed.ViewerVolume.X / 2
|
||||
|| aabb.minXYZ.Y < bed.BedCenter.Y - bed.ViewerVolume.Y / 2
|
||||
|| aabb.maxXYZ.Y > bed.BedCenter.Y + bed.ViewerVolume.Y / 2)
|
||||
{
|
||||
// TODO: then check if all of it is outside the bed circle
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filters items from a given source returning only persistable items inside the Build Volume
|
||||
/// </summary>
|
||||
/// <param name="source">The source content to filter</param>
|
||||
/// <param name="printer">The printer config to consider</param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<IObject3D> PrintableItems(this PrinterConfig printer, IObject3D source)
|
||||
{
|
||||
return source.VisibleMeshes().Where(item => printer.InsideBuildVolume(item) && item.WorldPersistable());
|
||||
}
|
||||
}
|
||||
|
||||
public class MeshViewerWidget : GuiWidget
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue