New method to ensure meshes are within the printable bounds

considers brim, skirt and raft
This commit is contained in:
Lars Brubaker 2022-03-21 17:40:22 -07:00
parent aee3fc6e3a
commit ef3f57a524
2 changed files with 51 additions and 4 deletions

View file

@ -374,6 +374,46 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
}
}
/// <summary>
/// The bounds that a mesh can be placed at and the gcode it creates will be within the bed
/// </summary>
[JsonIgnore]
public RectangleDouble MeshAllowedBounds
{
get
{
var firstLayerExtrusionWidth = GetDouble(SettingsKey.first_layer_extrusion_width);
var bedBounds = BedBounds;
var totalOffset = 0.0;
if (GetBool(SettingsKey.create_raft))
{
// The slicing engine creates a raft 3x the extrusion width
firstLayerExtrusionWidth *= 3;
totalOffset += firstLayerExtrusionWidth;
totalOffset += GetDouble(SettingsKey.raft_extra_distance_around_part);
}
if (GetBool(SettingsKey.create_skirt))
{
totalOffset += GetValue<double>(SettingsKey.skirt_distance);
totalOffset += (GetDouble(SettingsKey.skirts) + .5) * firstLayerExtrusionWidth;
// for every 400mm of min skirt length add another skirt loops
totalOffset += GetDouble(SettingsKey.min_skirt_length) / (20 * 20);
}
if (GetBool(SettingsKey.create_brim)
&& !GetBool(SettingsKey.create_raft))
{
totalOffset += GetValue<double>(SettingsKey.brims) * GetDouble(SettingsKey.first_layer_extrusion_width);
}
bedBounds.Inflate(-totalOffset);
return bedBounds;
}
}
[JsonIgnore]
public IEnumerable<PrinterSettingsLayer> DefaultLayerCascade
{
@ -1176,6 +1216,11 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
return GetValue<int>(settingsKey);
}
public double GetDouble(string settingsKey)
{
return GetValue<double>(settingsKey);
}
/// <summary>
/// Returns the first matching value discovered while enumerating the settings layers
/// </summary>

View file

@ -63,13 +63,15 @@ namespace MatterHackers.MatterControl
return false;
}
var bedBounds = printerConfig.Settings.MeshAllowedBounds;
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)
if (aabb.MinXYZ.X < bedBounds.Left
|| aabb.MaxXYZ.X > bedBounds.Right
|| aabb.MinXYZ.Y < bedBounds.Bottom
|| aabb.MaxXYZ.Y > bedBounds.Top)
{
return false;
}