improving subtract and subtract and replace editor display
This commit is contained in:
parent
c2d418f370
commit
3b420c2ef8
5 changed files with 176 additions and 69 deletions
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
Copyright (c) 2018, Lars Brubaker, John Lewin
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
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
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace MatterHackers.MatterControl.DesignTools
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class HideFromEditorAttribute : Attribute
|
||||
{
|
||||
public HideFromEditorAttribute()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -137,6 +137,11 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
// Create a field editor for each editable property detected via reflection
|
||||
foreach (var property in GetEditablePropreties(context.item))
|
||||
{
|
||||
if (property.PropertyInfo.GetCustomAttributes(true).OfType<HideFromEditorAttribute>().Any())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Create SectionWidget for SectionStartAttributes
|
||||
if (property.PropertyInfo.GetCustomAttributes(true).OfType<SectionStartAttribute>().FirstOrDefault() is SectionStartAttribute sectionStart)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -52,55 +52,92 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
Name = "Subtract and Replace";
|
||||
}
|
||||
|
||||
[HideFromEditor]
|
||||
public SelectedChildren ComputedChildren { get; set; } = new SelectedChildren();
|
||||
|
||||
public SelectedChildren SelectedChildren { get; set; } = new SelectedChildren();
|
||||
|
||||
public void DrawEditor(InteractionLayer layer, List<Object3DView> transparentMeshes, DrawEventArgs e, ref bool suppressNormalDraw)
|
||||
{
|
||||
if (layer.Scene.SelectedItem != null
|
||||
&& layer.Scene.SelectedItem == this)
|
||||
suppressNormalDraw = true;
|
||||
|
||||
var parentOfSourceItems = this.SourceContainer.DescendantsAndSelfMultipleChildrenFirstOrSelf();
|
||||
|
||||
var sourceItems = parentOfSourceItems.Children.ToList();
|
||||
|
||||
foreach (var paintItem in sourceItems)
|
||||
{
|
||||
suppressNormalDraw = true;
|
||||
var paintItemResults = this.Children.Where(i => i.OwnerID == paintItem.ID);
|
||||
var wasSelected = ComputedChildren.Contains(paintItem.ID);
|
||||
var currentlySelected = SelectedChildren.Contains(paintItem.ID);
|
||||
|
||||
var parentOfPaintTargets = this.SourceContainer.DescendantsAndSelfMultipleChildrenFirstOrSelf();
|
||||
|
||||
var paintObjects = parentOfPaintTargets.Children
|
||||
.Where((i) => SelectedChildren
|
||||
.Contains(i.ID))
|
||||
.SelectMany(c => c.VisibleMeshes())
|
||||
.ToList();
|
||||
|
||||
foreach (var item in paintObjects)
|
||||
if (currentlySelected)
|
||||
{
|
||||
transparentMeshes.Add(new Object3DView(item, new Color(item.WorldColor(this.SourceContainer), 128)));
|
||||
}
|
||||
|
||||
var keepObjects = parentOfPaintTargets.Children
|
||||
.Where((i) => !SelectedChildren
|
||||
.Contains(i.ID))
|
||||
.ToList();
|
||||
|
||||
foreach (var keepItem in keepObjects)
|
||||
{
|
||||
var isPaintChild = this.Children.Where(i => i.ID == keepItem.ID).FirstOrDefault() != null;
|
||||
foreach (var item in keepItem.VisibleMeshes())
|
||||
// if this is selected always paint a transparent source
|
||||
foreach (var item in paintItem.VisibleMeshes())
|
||||
{
|
||||
if (isPaintChild)
|
||||
transparentMeshes.Add(new Object3DView(item, new Color(item.WorldColor(this.SourceContainer), 80)));
|
||||
}
|
||||
|
||||
// if it was also selected in before (the results are right)
|
||||
if (wasSelected)
|
||||
{
|
||||
// paint solid results
|
||||
if (paintItemResults != null)
|
||||
{
|
||||
foreach (var paintItemResult in paintItemResults)
|
||||
{
|
||||
foreach (var item in paintItemResult.VisibleMeshes())
|
||||
{
|
||||
GLHelper.Render(item.Mesh,
|
||||
item.WorldColor(),
|
||||
item.WorldMatrix(),
|
||||
RenderTypes.Outlines,
|
||||
item.WorldMatrix() * layer.World.ModelviewMatrix);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (wasSelected)
|
||||
{
|
||||
// it is not selected now but was selected before (changed state)
|
||||
// pant the solid source
|
||||
foreach (var item in paintItem.VisibleMeshes())
|
||||
{
|
||||
GLHelper.Render(item.Mesh,
|
||||
item.WorldColor(),
|
||||
item.WorldMatrix(),
|
||||
RenderTypes.Outlines,
|
||||
item.WorldMatrix() * layer.World.ModelviewMatrix);
|
||||
}
|
||||
}
|
||||
else // it is not selected now and was not before (same state)
|
||||
{
|
||||
// paint the results
|
||||
if (paintItemResults != null && paintItemResults.Count() > 0)
|
||||
{
|
||||
foreach (var paintItemResult in paintItemResults)
|
||||
{
|
||||
foreach (var item in paintItemResult.VisibleMeshes())
|
||||
{
|
||||
GLHelper.Render(item.Mesh,
|
||||
item.WorldColor(),
|
||||
item.WorldMatrix(),
|
||||
RenderTypes.Outlines,
|
||||
item.WorldMatrix() * layer.World.ModelviewMatrix);
|
||||
}
|
||||
}
|
||||
}
|
||||
else // we don't have any results yet
|
||||
{
|
||||
foreach (var item in paintItem.VisibleMeshes())
|
||||
{
|
||||
GLHelper.Render(item.Mesh,
|
||||
item.WorldColor(),
|
||||
item.WorldMatrix(),
|
||||
RenderTypes.Outlines,
|
||||
item.WorldMatrix() * layer.World.ModelviewMatrix);
|
||||
|
||||
//suppressNormalDraw = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
GLHelper.Render(item.Mesh,
|
||||
item.WorldColor(this.SourceContainer),
|
||||
item.WorldMatrix(),
|
||||
RenderTypes.Outlines,
|
||||
item.WorldMatrix() * layer.World.ModelviewMatrix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -138,6 +175,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
try
|
||||
{
|
||||
SubtractAndReplace(cancellationToken, reporter);
|
||||
var newComputedChildren = new SelectedChildren();
|
||||
newComputedChildren.AddRange(SelectedChildren);
|
||||
ComputedChildren = newComputedChildren;
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
@ -168,6 +208,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
this.Children.Add(SourceContainer.Clone());
|
||||
SourceContainer.Visible = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -192,8 +233,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
double amountPerOperation = 1.0 / totalOperations;
|
||||
double percentCompleted = 0;
|
||||
|
||||
ProgressStatus progressStatus = new ProgressStatus();
|
||||
progressStatus.Status = "Do CSG";
|
||||
var progressStatus = new ProgressStatus
|
||||
{
|
||||
Status = "Do CSG"
|
||||
};
|
||||
|
||||
foreach (var keep in keepVisibleItems)
|
||||
{
|
||||
var keepResultsMesh = keep.Mesh;
|
||||
|
|
@ -201,13 +245,33 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
|
||||
foreach (var paint in paintObjects)
|
||||
{
|
||||
Mesh paintMesh = BooleanProcessing.Do(keepResultsMesh, keepWorldMatrix,
|
||||
paint.Mesh, paint.WorldMatrix(SourceContainer),
|
||||
2, reporter, amountPerOperation, percentCompleted, progressStatus, cancellationToken);
|
||||
Mesh paintMesh = BooleanProcessing.Do(keepResultsMesh,
|
||||
keepWorldMatrix,
|
||||
// paint data
|
||||
paint.Mesh,
|
||||
paint.WorldMatrix(SourceContainer),
|
||||
// operation type
|
||||
2,
|
||||
// reporting data
|
||||
reporter,
|
||||
amountPerOperation,
|
||||
percentCompleted,
|
||||
progressStatus,
|
||||
cancellationToken);
|
||||
|
||||
keepResultsMesh = BooleanProcessing.Do(keepResultsMesh, keepWorldMatrix,
|
||||
paint.Mesh, paint.WorldMatrix(SourceContainer),
|
||||
1, reporter, amountPerOperation, percentCompleted, progressStatus, cancellationToken);
|
||||
keepResultsMesh = BooleanProcessing.Do(keepResultsMesh,
|
||||
keepWorldMatrix,
|
||||
// point data
|
||||
paint.Mesh,
|
||||
paint.WorldMatrix(SourceContainer),
|
||||
// operation type
|
||||
1,
|
||||
// reporting data
|
||||
reporter,
|
||||
amountPerOperation,
|
||||
percentCompleted,
|
||||
progressStatus,
|
||||
cancellationToken);
|
||||
|
||||
// after the first time we get a result the results mesh is in the right coordinate space
|
||||
keepWorldMatrix = Matrix4X4.Identity;
|
||||
|
|
@ -216,7 +280,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
var paintResultsItem = new Object3D()
|
||||
{
|
||||
Mesh = paintMesh,
|
||||
Visible = false
|
||||
Visible = false,
|
||||
OwnerID = paint.ID
|
||||
};
|
||||
// copy all the properties but the matrix
|
||||
paintResultsItem.CopyWorldProperties(paint, SourceContainer, Object3DPropertyFlags.All & (~(Object3DPropertyFlags.Matrix | Object3DPropertyFlags.Visible)));
|
||||
|
|
@ -233,7 +298,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
var keepResultsItem = new Object3D()
|
||||
{
|
||||
Mesh = keepResultsMesh,
|
||||
Visible = false
|
||||
Visible = false,
|
||||
OwnerID = keep.ID
|
||||
};
|
||||
// copy all the properties but the matrix
|
||||
keepResultsItem.CopyWorldProperties(keep, SourceContainer, Object3DPropertyFlags.All & (~(Object3DPropertyFlags.Matrix | Object3DPropertyFlags.Visible)));
|
||||
|
|
@ -245,6 +311,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
{
|
||||
child.Visible = true;
|
||||
}
|
||||
|
||||
SourceContainer.Visible = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,36 +70,28 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
|
||||
foreach (var item in removeObjects)
|
||||
{
|
||||
transparentMeshes.Add(new Object3DView(item, new Color(item.WorldColor(this.SourceContainer), 128)));
|
||||
transparentMeshes.Add(new Object3DView(item, new Color(item.WorldColor(this.SourceContainer), 80)));
|
||||
}
|
||||
|
||||
var keepObjects = parentOfSubtractTargets.Children
|
||||
var keepItems = parentOfSubtractTargets.Children
|
||||
.Where((i) => !SelectedChildren
|
||||
.Contains(i.ID))
|
||||
.ToList();
|
||||
|
||||
foreach (var keepItem in keepObjects)
|
||||
foreach (var keepItem in keepItems)
|
||||
{
|
||||
var isSubtractChild = this.Children.Where(i => i.ID == keepItem.ID).FirstOrDefault() != null;
|
||||
foreach (var keepVisibleItem in keepItem.VisibleMeshes())
|
||||
var drawItem = keepItem;
|
||||
|
||||
var keepItemResult = this.Children.Where(i => i.OwnerID == keepItem.ID).FirstOrDefault();
|
||||
drawItem = keepItemResult != null ? keepItemResult : drawItem;
|
||||
|
||||
foreach (var item in drawItem.VisibleMeshes())
|
||||
{
|
||||
if (isSubtractChild)
|
||||
{
|
||||
GLHelper.Render(keepVisibleItem.Mesh,
|
||||
Color.Transparent,
|
||||
keepVisibleItem.WorldMatrix(),
|
||||
RenderTypes.Outlines,
|
||||
keepVisibleItem.WorldMatrix() * layer.World.ModelviewMatrix);
|
||||
suppressNormalDraw = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
GLHelper.Render(keepVisibleItem.Mesh,
|
||||
keepVisibleItem.WorldColor(this.SourceContainer),
|
||||
keepVisibleItem.WorldMatrix(),
|
||||
RenderTypes.Outlines,
|
||||
keepVisibleItem.WorldMatrix() * layer.World.ModelviewMatrix);
|
||||
}
|
||||
GLHelper.Render(item.Mesh,
|
||||
item.WorldColor(),
|
||||
item.WorldMatrix(),
|
||||
RenderTypes.Outlines,
|
||||
item.WorldMatrix() * layer.World.ModelviewMatrix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -236,8 +228,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
var resultsItem = new Object3D()
|
||||
{
|
||||
Mesh = resultsMesh,
|
||||
Visible = false
|
||||
Visible = false,
|
||||
OwnerID = keep.ID
|
||||
};
|
||||
|
||||
// copy all the properties but the matrix
|
||||
resultsItem.CopyWorldProperties(keep, SourceContainer, Object3DPropertyFlags.All & (~(Object3DPropertyFlags.Matrix | Object3DPropertyFlags.Visible)));
|
||||
// and add it to this
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 349f806487110a62eeee82837cbfa247dfd2db89
|
||||
Subproject commit ae7a2f0e11d0f328e19af0b4eb0ec38fa280875a
|
||||
Loading…
Add table
Add a link
Reference in a new issue