Merge pull request #5311 from larsbrubaker/main

main
This commit is contained in:
Lars Brubaker 2022-04-28 14:31:59 -07:00 committed by GitHub
commit 2c602e0ba5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 163 additions and 94 deletions

View file

@ -1073,37 +1073,12 @@ namespace MatterHackers.MatterControl
return new SceneOperation("Group")
{
OperationType = typeof(SelectionGroupObject3D),
ResultType = typeof(GroupObject3D),
ResultType = typeof(GroupHolesAppliedObject3D),
TitleGetter = () => "Group".Localize(),
Action = (sceneContext) =>
{
var scene = sceneContext.Scene;
var selectedItem = scene.SelectedItem;
scene.SelectedItem = null;
var newGroup = new GroupObject3D();
// When grouping items, move them to be centered on their bounding box
newGroup.Children.Modify((gChildren) =>
{
selectedItem.Clone().Children.Modify((sChildren) =>
{
var center = selectedItem.GetAxisAlignedBoundingBox().Center;
foreach (var child in sChildren)
{
child.Translate(-center.X, -center.Y, 0);
gChildren.Add(child);
}
newGroup.Translate(center.X, center.Y, 0);
});
});
scene.UndoBuffer.AddAndDo(new ReplaceCommand(selectedItem.Children.ToList(), new[] { newGroup }));
newGroup.MakeNameNonColliding();
scene.SelectedItem = newGroup;
var group = new GroupHolesAppliedObject3D();
group.WrapSelectedItemAndSelect(sceneContext.Scene);
},
HelpTextGetter = () => "At least 2 parts must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => sceneContext.Scene is InteractiveScene scene
@ -1534,6 +1509,7 @@ namespace MatterHackers.MatterControl
if (selectedItem != null)
{
return selectedItem is GroupObject3D
|| selectedItem is GroupHolesAppliedObject3D
|| selectedItem.GetType() == typeof(Object3D)
|| selectedItem.CanApply;
}

View file

@ -34,11 +34,11 @@ namespace MatterHackers.MatterControl.DesignTools
[AttributeUsage(AttributeTargets.Class)]
public class ShowUpdateButtonAttribute : Attribute
{
public bool SuppressPropertyChangeUpdates { get; set; }
public bool Show { get; set; } = true;
public bool SuppressPropertyChangeUpdates { get; set; }
public ShowUpdateButtonAttribute(bool suppressPropertyChangeUpdates)
public ShowUpdateButtonAttribute()
{
SuppressPropertyChangeUpdates = suppressPropertyChangeUpdates;
}
}
}

View file

@ -44,7 +44,7 @@ using Newtonsoft.Json;
namespace MatterHackers.MatterControl.Plugins.Lithophane
{
[ShowUpdateButton(true)]
[ShowUpdateButton(SuppressPropertyChangeUpdates = true)]
public class LithophaneObject3D : Object3D
{
public LithophaneObject3D()

View file

@ -29,10 +29,14 @@ either expressed or implied, of the FreeBSD Project.
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.PartPreviewWindow.View3D;
using System;
using System.Linq;
using System.Text.Json.Serialization;
namespace MatterHackers.MatterControl.DesignTools.Operations
{
public class GroupObject3D : Object3D
public class GroupObject3D : Object3D
{
public override bool CanApply => true;
@ -41,4 +45,33 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
Name = "Group".Localize();
}
}
[ShowUpdateButton(Show = false)]
public class GroupHolesAppliedObject3D : SubtractObject3D_2
{
public GroupHolesAppliedObject3D()
{
Name = "Group".Localize();
}
public override SelectedChildren SelectedChildren
{
get
{
var selections = new SelectedChildren();
foreach(var child in SourceContainer.DescendantsAndSelfMultipleChildrenFirstOrSelf().Children.Where(i => i.WorldOutputType(this) == PrintOutputTypes.Hole))
{
selections.Add(child.ID);
}
return selections;
}
set
{
}
}
}
}

View file

@ -110,7 +110,7 @@ namespace MatterHackers.MatterControl.DesignTools
if (newChildren.Count > 1)
{
var group = new GroupObject3D
var group = new GroupHolesAppliedObject3D
{
Name = this.Name
};

View file

@ -159,7 +159,8 @@ namespace MatterHackers.MatterControl.DesignTools
AddWebPageLinkIfRequired(context.item, mainContainer, theme);
// add in an Update button if applicable
if (context.item.GetType().GetCustomAttributes(typeof(ShowUpdateButtonAttribute), true).FirstOrDefault() is ShowUpdateButtonAttribute showUpdate)
var showUpdate = context.item.GetType().GetCustomAttributes(typeof(ShowUpdateButtonAttribute), true).FirstOrDefault() as ShowUpdateButtonAttribute;
if (showUpdate?.Show == true)
{
var updateButton = new TextButton("Update".Localize(), theme)
{

View file

@ -44,7 +44,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
{
[ShowUpdateButton(false)]
[ShowUpdateButton]
public class CombineObject3D_2 : OperationSourceContainerObject3D, IPropertyGridModifier, IBuildsOnThread
{
private CancellationTokenSource cancellationToken;
@ -147,15 +147,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
var totalOperations = touchingSets.Sum(t => t.Count);
#if false
var resultsMesh = BooleanProcessing.DoArray(items,
CsgModes.Union,
Processing,
InputResolution,
OutputResolution,
reporter,
cancellationToken);
#else
double amountPerOperation = 1.0 / totalOperations;
double ratioCompleted = 0;
@ -169,6 +160,16 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
if (set.Count > 1)
{
#if false
setMesh = BooleanProcessing.DoArray(set.Select(i => (i.mesh, i.matrix)),
CsgModes.Union,
Processing,
InputResolution,
OutputResolution,
reporter,
cancellationToken);
#else
bool first = true;
foreach (var next in set)
{
@ -203,6 +204,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
progressStatus.Progress0To1 = ratioCompleted;
reporter?.Report(progressStatus);
}
#endif
setMeshes.Add(setMesh);
}
@ -229,7 +231,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
resultsMesh.CopyAllFaces(setMesh, Matrix4X4.Identity);
}
}
#endif
if (resultsMesh != null)
{

View file

@ -42,7 +42,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
{
[ShowUpdateButton(false)]
[ShowUpdateButton]
public class IntersectionObject3D_2 : OperationSourceContainerObject3D, IPropertyGridModifier
{
public IntersectionObject3D_2()

View file

@ -49,7 +49,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
{
[Obsolete("Use SubtractAndReplaceObject3D_2 instead", false)]
[ShowUpdateButton(true)]
[ShowUpdateButton(SuppressPropertyChangeUpdates = true)]
public class SubtractAndReplaceObject3D : MeshWrapperObject3D, ISelectableChildContainer
{
public SubtractAndReplaceObject3D()

View file

@ -45,7 +45,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
{
[ShowUpdateButton(false)]
[ShowUpdateButton]
public class SubtractAndReplaceObject3D_2 : OperationSourceContainerObject3D, ISelectableChildContainer, ICustomEditorDraw, IPropertyGridModifier
{
public SubtractAndReplaceObject3D_2()

View file

@ -47,7 +47,7 @@ using MatterHackers.PolygonMesh.Csg;
namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
{
[Obsolete("Use SubtractObject3D_2 instead", false)]
[ShowUpdateButton(true)]
[ShowUpdateButton(SuppressPropertyChangeUpdates = true)]
public class SubtractObject3D : MeshWrapperObject3D, ISelectableChildContainer
{
public SubtractObject3D()

View file

@ -44,7 +44,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
{
[ShowUpdateButton(false)]
[ShowUpdateButton]
public class SubtractObject3D_2 : OperationSourceContainerObject3D, ISelectableChildContainer, ICustomEditorDraw, IPropertyGridModifier, IBuildsOnThread
{
public SubtractObject3D_2()
@ -54,7 +54,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
}
[DisplayName("Part(s) to Subtract")]
public SelectedChildren SelectedChildren { get; set; } = new SelectedChildren();
public virtual SelectedChildren SelectedChildren { get; set; } = new SelectedChildren();
#if DEBUG
public ProcessingModes Processing { get; set; } = ProcessingModes.Polygons;
@ -257,7 +257,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
foreach (var keep in keepItems)
{
#if false
var items = removeVisibleItems.Select(i => (i.Mesh, i.WorldMatrix(SourceContainer))).ToList();
var items = removeItems.Select(i => (i.Mesh, i.WorldMatrix(SourceContainer))).ToList();
items.Insert(0, (keep.Mesh, keep.Matrix));
var resultsMesh = BooleanProcessing.DoArray(items,
CsgModes.Subtract,

View file

@ -748,7 +748,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
Tuple<double, double> nearFar = null;
foreach (var aabb in Object3DControlLayer.MakeListOfObjectControlBoundingBoxes())
{
nearFar = ExpandNearAndFarToClippedBounds(nearFar, world.IsOrthographic, worldspacePlanes, world.ModelviewMatrix, aabb);
if (!double.IsNaN(aabb.MinXYZ.X) && !double.IsInfinity(aabb.MinXYZ.X))
{
nearFar = ExpandNearAndFarToClippedBounds(nearFar, world.IsOrthographic, worldspacePlanes, world.ModelviewMatrix, aabb);
}
}
nearFar = ExpandNearAndFarToClippedBounds(nearFar, world.IsOrthographic, worldspacePlanes, world.ModelviewMatrix, Object3DControlLayer.GetPrinterNozzleAABB());
nearFar = ExpandNearAndFarToClippedBounds(nearFar, world.IsOrthographic, worldspacePlanes, world.ModelviewMatrix, Scene.GetAxisAlignedBoundingBox());

View file

@ -294,7 +294,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
for (int extruderIndexIn = 0; extruderIndexIn < extruderCount; extruderIndexIn++)
{
var extruderIndex = extruderIndexIn;
IEnumerable<IObject3D> itemsThisExtruder = Slicer.GetItemsForExtruder(meshItemsOnBuildPlate, extruderCount, extruderIndex, true);
IEnumerable<IObject3D> itemsThisExtruder = Slicer.GetSolidsForExtruder(meshItemsOnBuildPlate, extruderCount, extruderIndex, true);
itemsByExtruder.Add(itemsThisExtruder);
if (Slicer.ExtrudersUsed[extruderIndex])
@ -305,17 +305,18 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
var outputOptions = new List<(Matrix4X4 matrix, string fileName)>();
var holes = Slicer.GetAllHoles(meshItemsOnBuildPlate);
int savedStlCount = 0;
bool first = true;
var firstExtruder = true;
for (int extruderIndex = 0; extruderIndex < itemsByExtruder.Count; extruderIndex++)
{
if (!first)
if (!firstExtruder)
{
mergeRules += ",";
first = false;
}
mergeRules += AddObjectsForExtruder(itemsByExtruder[extruderIndex], outputOptions, ref savedStlCount);
mergeRules += AddObjectsForExtruder(itemsByExtruder[extruderIndex], holes, outputOptions, ref savedStlCount);
firstExtruder = false;
}
var supportObjects = meshItemsOnBuildPlate.Where((item) => item.WorldOutputType() == PrintOutputTypes.Support);
@ -323,7 +324,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
if (supportObjects.Any())
{
// add a flag to the merge rules to let us know there was support
mergeRules += ",S" + AddObjectsForExtruder(supportObjects, outputOptions, ref savedStlCount);
mergeRules += "S" + AddObjectsForExtruder(supportObjects, holes, outputOptions, ref savedStlCount);
}
var wipeTowerObjects = meshItemsOnBuildPlate.Where((item) => item.WorldOutputType() == PrintOutputTypes.WipeTower);
@ -331,7 +332,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
if (wipeTowerObjects.Any())
{
// add a flag to the merge rules to let us know there was a wipe tower
mergeRules += ",W" + AddObjectsForExtruder(wipeTowerObjects, outputOptions, ref savedStlCount);
mergeRules += "W" + AddObjectsForExtruder(wipeTowerObjects, holes, outputOptions, ref savedStlCount);
}
var fuzzyObjects = meshItemsOnBuildPlate.Where((item) => item.WorldOutputType() == PrintOutputTypes.Fuzzy);
@ -339,11 +340,9 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
if (fuzzyObjects.Any())
{
// add a flag to the merge rules to let us know there was a wipe tower
mergeRules += ",F" + AddObjectsForExtruder(fuzzyObjects, outputOptions, ref savedStlCount);
mergeRules += "F" + AddObjectsForExtruder(fuzzyObjects, holes, outputOptions, ref savedStlCount);
}
mergeRules += " ";
return outputOptions;
}
@ -600,36 +599,70 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
}
}
private static string AddObjectsForExtruder(IEnumerable<IObject3D> items, List<(Matrix4X4 matrix, string fileName)> outputItems, ref int savedStlCount)
private static string AddObjectsForExtruder(IEnumerable<IObject3D> solids, IEnumerable<IObject3D> holes, List<(Matrix4X4 matrix, string fileName)> outputItems, ref int savedStlCount)
{
string mergeString = "";
if (items.Any())
if (solids.Any())
{
bool first = true;
foreach (var item in items)
bool firstSolid = true;
foreach (var solid in solids)
{
if (!first)
{
mergeString += ",";
}
var itemWorldMatrix = item.WorldMatrix();
if (item is GeneratedSupportObject3D generatedSupportObject3D
&& item.Mesh != null)
var itemWorldMatrix = solid.WorldMatrix();
if (solid is GeneratedSupportObject3D generatedSupportObject3D
&& solid.Mesh != null)
{
// grow the support columns by the amount they are reduced by
var aabbForCenter = item.Mesh.GetAxisAlignedBoundingBox();
var aabbForSize = item.Mesh.GetAxisAlignedBoundingBox(item.Matrix);
var aabbForCenter = solid.Mesh.GetAxisAlignedBoundingBox();
var aabbForSize = solid.Mesh.GetAxisAlignedBoundingBox(solid.Matrix);
var xyScale = (aabbForSize.XSize + 2 * SupportGenerator.ColumnReduceAmount) / aabbForSize.XSize;
itemWorldMatrix = itemWorldMatrix.ApplyAtPosition(aabbForCenter.Center.Transform(itemWorldMatrix), Matrix4X4.CreateScale(xyScale, xyScale, 1));
}
outputItems.Add((itemWorldMatrix, Path.Combine(ApplicationDataStorage.Instance.LibraryAssetsPath, item.MeshPath)));
mergeString += $"({savedStlCount++}";
first = false;
outputItems.Add((itemWorldMatrix, Path.Combine(ApplicationDataStorage.Instance.LibraryAssetsPath, solid.MeshPath)));
mergeString += $"{savedStlCount++}";
if (solids.Count() > 1)
{
if (firstSolid)
{
mergeString += ",";
firstSolid = false;
}
else
{
mergeString += "+";
}
}
else if (holes.Any())
{
mergeString += ",";
}
}
mergeString += new string(')', items.Count());
if (holes.Any())
{
bool firstHole = true;
foreach (var hole in holes)
{
var itemWorldMatrix = hole.WorldMatrix();
outputItems.Add((itemWorldMatrix, Path.Combine(ApplicationDataStorage.Instance.LibraryAssetsPath, hole.MeshPath)));
mergeString += $"{savedStlCount++}";
if (holes.Count() > 1)
{
if (firstHole)
{
mergeString += ",";
firstHole = false;
}
else
{
mergeString += "+";
}
}
}
mergeString += "-";
}
}
else
{
@ -646,7 +679,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
StlProcessing.Save(tinyMesh, tinyObjectFileName, CancellationToken.None);
outputItems.Add((Matrix4X4.Identity, tinyObjectFileName));
mergeString += $"({savedStlCount++})";
mergeString += $"{savedStlCount++}";
}
return mergeString;

View file

@ -95,7 +95,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
for (int extruderIndex = 0; extruderIndex < extruderCount; extruderIndex++)
{
IEnumerable<IObject3D> itemsThisExtruder = GetItemsForExtruder(printableItems, extruderCount, extruderIndex, checkForMeshFile);
IEnumerable<IObject3D> itemsThisExtruder = GetSolidsForExtruder(printableItems, extruderCount, extruderIndex, checkForMeshFile);
extrudersUsed[extruderIndex] |= itemsThisExtruder.Any();
}
}
@ -118,15 +118,34 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
return false;
}
public static IEnumerable<IObject3D> GetItemsForExtruder(IEnumerable<IObject3D> meshItemsOnBuildPlate, int extruderCount, int extruderIndex, bool checkForMeshFile)
public static IEnumerable<IObject3D> GetSolidsForExtruder(IEnumerable<IObject3D> meshItemsOnBuildPlate, int extruderCount, int extruderIndex, bool checkForMeshFile)
{
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));
{
var outputType = item.WorldOutputType();
var material = item.WorldMaterialIndex();
return (!checkForMeshFile
|| File.Exists(item.MeshPath) // Drop missing files
|| File.Exists(Path.Combine(Object3D.AssetsPath, item.MeshPath)))
&& (material == extruderIndex || (extruderIndex == 0 && (material >= extruderCount || material == -1)))
&& (outputType == PrintOutputTypes.Solid || outputType == PrintOutputTypes.Default);
});
return itemsThisExtruder;
}
public static IEnumerable<IObject3D> GetAllHoles(IEnumerable<IObject3D> meshItemsOnBuildPlate)
{
var itemsThisExtruder = meshItemsOnBuildPlate.Where((item) =>
{
var outputType = item.WorldOutputType();
var material = item.WorldMaterialIndex();
return (File.Exists(item.MeshPath) // Drop missing files
|| File.Exists(Path.Combine(Object3D.AssetsPath, item.MeshPath)))
&& outputType == PrintOutputTypes.Hole;
});
return itemsThisExtruder;
}

View file

@ -4339,6 +4339,9 @@ Translated:Select this option only if your printer does not appear in the list
English:Select What to Import
Translated:Select What to Import
English:Selected Children
Translated:Selected Children
English:Selected Material and Bed Surface are Incompatable
Translated:Selected Material and Bed Surface are Incompatable

@ -1 +1 @@
Subproject commit e754c81428db89bb94fadac23f026de7579bff8f
Subproject commit d318d70f3f2772d1b987a63291a1860c7dfc04f9

@ -1 +1 @@
Subproject commit 444ce54704973489addef582e27353a0f84b59ac
Subproject commit 9e115e5373d44f9cc7fdcee0e3290b1e88c39970