improved hole behavior
This commit is contained in:
parent
ab6a75c586
commit
218f8d5a15
9 changed files with 127 additions and 57 deletions
|
|
@ -99,9 +99,9 @@ namespace MatterHackers.Agg.UI
|
|||
|
||||
public EventHandler CollapseChanged;
|
||||
|
||||
private static string CollapseKey(string opperationGroupName)
|
||||
private static string CollapseKey(string operationGroupName)
|
||||
{
|
||||
return $"scene_operation_collapse_{opperationGroupName}";
|
||||
return $"scene_operation_collapse_{operationGroupName}";
|
||||
}
|
||||
|
||||
public bool Collapse
|
||||
|
|
@ -123,9 +123,9 @@ namespace MatterHackers.Agg.UI
|
|||
|
||||
public EventHandler VisibleChanged;
|
||||
|
||||
private static string VisibleKey(string opperationGroupName)
|
||||
private static string VisibleKey(string operationGroupName)
|
||||
{
|
||||
return $"scene_operation_visible_{opperationGroupName}";
|
||||
return $"scene_operation_visible_{operationGroupName}";
|
||||
}
|
||||
|
||||
public static bool GetVisible(string id, bool defaultIfNotSet)
|
||||
|
|
|
|||
|
|
@ -69,6 +69,9 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
Diameter,
|
||||
}
|
||||
|
||||
[HideFromEditor]
|
||||
public Vector3 PostCurveOffset { get; set; } = new Vector3();
|
||||
|
||||
[EnumDisplay(Mode = EnumDisplayAttribute.PresentationMode.Tabs)]
|
||||
public BendTypes BendType { get; set; } = BendTypes.Angle;
|
||||
|
||||
|
|
@ -207,7 +210,13 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
}
|
||||
}
|
||||
|
||||
public override Task Rebuild()
|
||||
public override void Cancel(UndoBuffer undoBuffer)
|
||||
{
|
||||
this.Matrix *= Matrix4X4.CreateTranslation(-PostCurveOffset);
|
||||
base.Cancel(undoBuffer);
|
||||
}
|
||||
|
||||
public override Task Rebuild()
|
||||
{
|
||||
this.DebugDepth("Rebuild");
|
||||
|
||||
|
|
@ -348,36 +357,13 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
if (firstBuild)
|
||||
{
|
||||
var postAabb = this.GetAxisAlignedBoundingBox();
|
||||
this.Matrix *= Matrix4X4.CreateTranslation(initialAabb.Center.X - postAabb.Center.X,
|
||||
PostCurveOffset = new Vector3(initialAabb.Center.X - postAabb.Center.X,
|
||||
initialAabb.MinXYZ.Y - postAabb.MinXYZ.Y,
|
||||
initialAabb.MinXYZ.Z - postAabb.MinXYZ.Z);
|
||||
this.Matrix *= Matrix4X4.CreateTranslation(PostCurveOffset);
|
||||
}
|
||||
|
||||
var removeItems = Children.Where(c => c.OutputType == PrintOutputTypes.Hole && c.Visible);
|
||||
if (removeItems.Any())
|
||||
{
|
||||
var keepItems = Children.Where(c => c.OutputType != PrintOutputTypes.Hole && c.Visible);
|
||||
|
||||
// apply any holes before we return
|
||||
var resultItems = SubtractObject3D_2.DoSubtract(this,
|
||||
keepItems,
|
||||
removeItems,
|
||||
reporter,
|
||||
cancellationToken.Token);
|
||||
|
||||
RemoveAllButSource();
|
||||
|
||||
// add back in the results of the hole removal
|
||||
Children.Modify(list =>
|
||||
{
|
||||
foreach (var child in resultItems)
|
||||
{
|
||||
list.Add(child);
|
||||
child.Visible = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ApplyHoles(reporter, cancellationToken.Token);
|
||||
|
||||
this.cancellationToken = null;
|
||||
UiThread.RunOnIdle(() =>
|
||||
|
|
|
|||
|
|
@ -115,6 +115,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
// set the matrix back
|
||||
Matrix = currentMatrix;
|
||||
SourceContainer.Visible = false;
|
||||
ApplyHoles(reporter, cancellationToken.Token);
|
||||
rebuildLocks.Dispose();
|
||||
|
||||
Invalidate(InvalidateType.DisplayValues);
|
||||
|
|
|
|||
|
|
@ -331,6 +331,8 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
list.AddRange(twistedChildren);
|
||||
});
|
||||
|
||||
ApplyHoles(reporter, cancellationToken.Token);
|
||||
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
rebuildLocks.Dispose();
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ using MatterHackers.Agg.UI;
|
|||
using MatterHackers.DataConverters3D;
|
||||
using MatterHackers.DataConverters3D.UndoCommands;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.PartPreviewWindow.View3D;
|
||||
using MatterHackers.PolygonMesh;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
|
@ -320,6 +321,49 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
|
||||
this.Invalidate(InvalidateType.Children);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use after source itmes have been processed to modify the transformed children of the inherited operation.
|
||||
/// Example: A bend operation has been applied and there are still holes, this will remove the holes.
|
||||
/// </summary>
|
||||
/// <param name="reporter">Show progress</param>
|
||||
/// <param name="cancellationToken">Can check if the operation has been canceled</param>
|
||||
/// <returns>Did any holes get subtracted</returns>
|
||||
public bool ApplyHoles(IProgress<ProgressStatus> reporter,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var removeItems = Children.Where(c => c.OutputType == PrintOutputTypes.Hole && c.Visible);
|
||||
if (removeItems.Any())
|
||||
{
|
||||
var keepItems = Children.Where(c => c.OutputType != PrintOutputTypes.Hole && c.Visible);
|
||||
|
||||
if (keepItems.Any())
|
||||
{
|
||||
// apply any holes before we return
|
||||
var resultItems = SubtractObject3D_2.DoSubtract(null,
|
||||
keepItems,
|
||||
removeItems,
|
||||
reporter,
|
||||
cancellationToken);
|
||||
|
||||
RemoveAllButSource();
|
||||
|
||||
// add back in the results of the hole removal
|
||||
Children.Modify(list =>
|
||||
{
|
||||
foreach (var child in resultItems)
|
||||
{
|
||||
list.Add(child);
|
||||
child.Visible = true;
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class OperationSourceObject3D : Object3D
|
||||
|
|
|
|||
|
|
@ -129,21 +129,49 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
SourceContainer.Visible = true;
|
||||
RemoveAllButSource();
|
||||
|
||||
var participants = SourceContainer.VisibleMeshes();
|
||||
if (participants.Count() < 2)
|
||||
Mesh resultsMesh = null;
|
||||
var participants = SourceContainer.VisibleMeshes().Where(m => m.WorldOutputType(this) != PrintOutputTypes.Hole);
|
||||
if (participants.Count() == 0)
|
||||
{
|
||||
if (participants.Count() == 1)
|
||||
{
|
||||
var newMesh = new Object3D();
|
||||
newMesh.CopyProperties(participants.First(), Object3DPropertyFlags.All);
|
||||
newMesh.Mesh = participants.First().Mesh;
|
||||
this.Children.Add(newMesh);
|
||||
SourceContainer.Visible = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
resultsMesh = CombineParticipanets(reporter, participants, cancellationToken);
|
||||
}
|
||||
|
||||
var resultsItem = new Object3D()
|
||||
{
|
||||
Mesh = resultsMesh
|
||||
};
|
||||
|
||||
if (resultsMesh != null)
|
||||
{
|
||||
var holes = SourceContainer.VisibleMeshes().Where(m => m.WorldOutputType(this) == PrintOutputTypes.Hole);
|
||||
if (holes != null)
|
||||
{
|
||||
var holesMesh = CombineParticipanets(null, holes, cancellationToken);
|
||||
var holesItem = new Object3D()
|
||||
{
|
||||
Mesh = holesMesh
|
||||
};
|
||||
var resultItems = SubtractObject3D_2.DoSubtract(null,
|
||||
new List<IObject3D>() { resultsItem },
|
||||
new List<IObject3D>() { holesItem },
|
||||
null,
|
||||
cancellationToken);
|
||||
|
||||
resultsItem.Mesh = resultItems.First().Mesh;
|
||||
}
|
||||
}
|
||||
|
||||
resultsItem.CopyProperties(participants.First(), Object3DPropertyFlags.All & (~Object3DPropertyFlags.Matrix));
|
||||
this.Children.Add(resultsItem);
|
||||
SourceContainer.Visible = false;
|
||||
}
|
||||
|
||||
private Mesh CombineParticipanets(IProgress<ProgressStatus> reporter, IEnumerable<IObject3D> participants, CancellationToken cancellationToken)
|
||||
{
|
||||
List<List<(Mesh mesh, Matrix4X4 matrix, AxisAlignedBoundingBox aabb)>> touchingSets = GetTouchingMeshes(participants);
|
||||
|
||||
var totalOperations = touchingSets.Sum(t => t.Count);
|
||||
|
|
@ -233,16 +261,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
}
|
||||
}
|
||||
|
||||
if (resultsMesh != null)
|
||||
{
|
||||
var resultsItem = new Object3D()
|
||||
{
|
||||
Mesh = resultsMesh
|
||||
};
|
||||
resultsItem.CopyProperties(participants.First(), Object3DPropertyFlags.All & (~Object3DPropertyFlags.Matrix));
|
||||
this.Children.Add(resultsItem);
|
||||
SourceContainer.Visible = false;
|
||||
}
|
||||
return resultsMesh;
|
||||
}
|
||||
|
||||
private List<List<(Mesh mesh, Matrix4X4 matrix, AxisAlignedBoundingBox aabb)>> GetTouchingMeshes(IEnumerable<IObject3D> participants)
|
||||
|
|
|
|||
|
|
@ -341,15 +341,25 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
};
|
||||
|
||||
var resultsMesh = keep.Mesh;
|
||||
var keepWorldMatrix = keep.WorldMatrix(sourceContainer);
|
||||
var keepWorldMatrix = keep.Matrix;
|
||||
if (sourceContainer != null)
|
||||
{
|
||||
keepWorldMatrix = keep.WorldMatrix(sourceContainer);
|
||||
}
|
||||
|
||||
foreach (var remove in removeItems)
|
||||
{
|
||||
var removeWorldMatrix = remove.Matrix;
|
||||
if (sourceContainer != null)
|
||||
{
|
||||
removeWorldMatrix = remove.WorldMatrix(sourceContainer);
|
||||
}
|
||||
|
||||
resultsMesh = BooleanProcessing.Do(resultsMesh,
|
||||
keepWorldMatrix,
|
||||
// other mesh
|
||||
remove.Mesh,
|
||||
remove.WorldMatrix(sourceContainer),
|
||||
removeWorldMatrix,
|
||||
// operation type
|
||||
CsgModes.Subtract,
|
||||
processingMode,
|
||||
|
|
@ -381,7 +391,15 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
};
|
||||
|
||||
// copy all the properties but the matrix
|
||||
resultsItem.CopyWorldProperties(keep, sourceContainer, Object3DPropertyFlags.All & (~(Object3DPropertyFlags.Matrix | Object3DPropertyFlags.Visible)));
|
||||
if (sourceContainer != null)
|
||||
{
|
||||
resultsItem.CopyWorldProperties(keep, sourceContainer, Object3DPropertyFlags.All & (~(Object3DPropertyFlags.Matrix | Object3DPropertyFlags.Visible)));
|
||||
}
|
||||
else
|
||||
{
|
||||
resultsItem.CopyProperties(keep, Object3DPropertyFlags.All & (~(Object3DPropertyFlags.Matrix | Object3DPropertyFlags.Visible)));
|
||||
}
|
||||
|
||||
// and add it to this
|
||||
results.Add(resultsItem);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 8d5c8129f1ab281e613a7eef0f05a24074371d90
|
||||
Subproject commit 365d3ed687c1502e0d5f12d36ae79b03b92ba9e0
|
||||
|
|
@ -420,7 +420,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
|||
}
|
||||
|
||||
[Test]
|
||||
public async Task DesignTabFileOpperations()
|
||||
public async Task DesignTabFileOperations()
|
||||
{
|
||||
await MatterControlUtilities.RunTest((testRunner) =>
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue