Simplify InteractionControls and reduce to subset of InteractionVolume

This commit is contained in:
John Lewin 2019-05-18 13:17:21 -07:00 committed by jlewin
parent 76471e3800
commit cd266984ac
7 changed files with 112 additions and 34 deletions

View file

@ -0,0 +1,41 @@
/*
Copyright (c) 2019, 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.
*/
namespace MatterHackers.MeshVisualizer
{
/// <summary>
/// Interaction control which draws adornments with native OpenGL calls
/// </summary>
public interface IGLInteractionElement : IInteractionElement
{
bool DrawOnTop { get; }
void DrawGlContent(DrawGlContentEventArgs e);
}
}

View file

@ -0,0 +1,45 @@
/*
Copyright (c) 2019, 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 MatterHackers.DataConverters3D;
namespace MatterHackers.MeshVisualizer
{
/// <summary>
/// Basic Interaction control - notified of position per OpenGL draw
/// </summary>
public interface IInteractionElement
{
string Name { get; }
void SetPosition(IObject3D selectedItem);
void CancelOperation();
}
}

View file

@ -28,6 +28,7 @@ either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.Collections.Generic;
using MatterHackers.Agg;
using MatterHackers.Agg.Transform;
using MatterHackers.Agg.UI;
@ -39,7 +40,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MeshVisualizer
{
public class InteractionVolume
public class InteractionVolume : IInteractionElement, IGLInteractionElement
{
private bool mouseOver = false;

View file

@ -27,10 +27,10 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System;
using MatterHackers.Agg.UI;
using MatterHackers.RayTracer;
using MatterHackers.VectorMath;
using System;
namespace MatterHackers.MeshVisualizer
{
@ -38,15 +38,14 @@ namespace MatterHackers.MeshVisualizer
{
public IntersectInfo info;
public MouseEventArgs MouseEvent2D;
private Ray mouseRay;
public Ray MouseRay { get { return mouseRay; } }
public Ray MouseRay { get; }
public MouseEvent3DArgs(MouseEventArgs mouseEvent2D, Ray mouseRay, IntersectInfo info)
{
this.info = info;
this.MouseEvent2D = mouseEvent2D;
this.mouseRay = mouseRay;
this.MouseRay = mouseRay;
}
}
}

View file

@ -51,12 +51,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
/// <summary>
/// Contains type to IAVolume mappings
/// </summary>
private Dictionary<Type, List<InteractionVolume>> iavMappings = new Dictionary<Type, List<InteractionVolume>>();
private Dictionary<Type, List<IInteractionElement>> iavMappings = new Dictionary<Type, List<IInteractionElement>>();
/// <summary>
/// Interaction Volume Overrides for the selected scene item
/// </summary>
private List<InteractionVolume> iavOverrides = null;
private List<IInteractionElement> iavOverrides = null;
private Type selectedItemType;
@ -66,15 +66,15 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
public bool DrawOpenGLContent { get; set; } = true;
private List<InteractionVolume> registeredIAVolumes = new List<InteractionVolume>();
private List<IInteractionElement> registeredIAVolumes = new List<IInteractionElement>();
public IEnumerable<InteractionVolume> InteractionVolumes
public IEnumerable<IInteractionElement> InteractionVolumes
{
get
{
if (selectedItemType == null)
{
return Enumerable.Empty<InteractionVolume>();
return Enumerable.Empty<IInteractionElement>();
}
else
{
@ -114,7 +114,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
});
}
iavMappings.Add(typeof(ImageObject3D), new List<InteractionVolume> { new MoveInZControl(this) });
iavMappings.Add(typeof(ImageObject3D), new List<IInteractionElement> { new MoveInZControl(this) });
// Register listeners
sceneContext.Scene.SelectionChanged += this.Scene_SelectionChanged;
@ -143,12 +143,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
drawables.Add(drawable);
}
public void RegisterIAVolume(InteractionVolume interactionVolume)
public void RegisterIAVolume(IInteractionElement interactionVolume)
{
registeredIAVolumes.Add(interactionVolume);
}
public void RegisterIAVolumes(IEnumerable<InteractionVolume> interactionVolumes)
public void RegisterIAVolumes(IEnumerable<IInteractionElement> interactionVolumes)
{
registeredIAVolumes.AddRange(interactionVolumes);
}
@ -193,7 +193,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
}
public static void RenderBounds(DrawEventArgs e, WorldView world, IEnumerable<BvhIterator> allResults)
{
foreach (var bvhIterator in allResults)
@ -248,17 +247,14 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
}
public override void OnMouseDown(MouseEventArgs mouseEvent)
{
base.OnMouseDown(mouseEvent);
Ray ray = this.World.GetRayForLocalBounds(mouseEvent.Position);
IntersectInfo info;
if (this.Scene.SelectedItem != null
&& !SuppressUiVolumes
&& FindInteractionVolumeHit(ray, out mouseDownIAVolume, out info))
&& FindInteractionVolumeHit(ray, out mouseDownIAVolume, out IntersectInfo info))
{
mouseDownIAVolume.OnMouseDown(new MouseEvent3DArgs(mouseEvent, ray, info));
SelectedInteractionVolume = mouseDownIAVolume;
@ -293,7 +289,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
var iaVolumes = this.InteractionVolumes;
foreach (var iaVolume in iaVolumes)
foreach (var iaVolume in iaVolumes.OfType<InteractionVolume>())
{
if (hitIAVolume == iaVolume)
{
@ -323,9 +319,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
Ray ray = this.World.GetRayForLocalBounds(mouseEvent.Position);
IntersectInfo info;
bool anyInteractionVolumeHit = FindInteractionVolumeHit(ray, out InteractionVolume iaVolume, out info);
MouseEvent3DArgs mouseEvent3D = new MouseEvent3DArgs(mouseEvent, ray, info);
bool anyInteractionVolumeHit = FindInteractionVolumeHit(ray, out InteractionVolume iaVolume, out IntersectInfo info);
var mouseEvent3D = new MouseEvent3DArgs(mouseEvent, ray, info);
if (MouseDownOnInteractionVolume && mouseDownIAVolume != null)
{
@ -342,6 +337,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
iaVolume.OnMouseUp(mouseEvent3D);
}
SelectedInteractionVolume = null;
}
@ -398,7 +394,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
// - Looks like the extra list is always required as CreateNewHierachy requires a List and we can only produce an IEnumerable without the list overhead
// - var uiTraceables = iaVolumes.Where(ia => ia.CollisionVolume != null).Select(ia => new Transform(ia.CollisionVolume, ia.TotalTransform)).ToList<IPrimitive>();
var uiTraceables = new List<IPrimitive>();
foreach (InteractionVolume interactionVolume in iaVolumes)
foreach (var interactionVolume in iaVolumes.OfType<InteractionVolume>())
{
if (interactionVolume.CollisionVolume != null)
{
@ -412,7 +408,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
info = allUiObjects.GetClosestIntersection(ray);
if (info != null)
{
foreach (var iaVolume in iaVolumes)
foreach (var iaVolume in iaVolumes.OfType<InteractionVolume>())
{
var insideBounds = new List<IBvhItem>();
if (iaVolume.CollisionVolume != null)
@ -435,16 +431,18 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
public bool MouseDownOnInteractionVolume => SelectedInteractionVolume != null;
public InteractionVolume SelectedInteractionVolume { get; set; } = null;
public InteractionVolume HoveredInteractionVolume { get; set; } = null;
public double SnapGridDistance
{
get
{
if(string.IsNullOrEmpty(UserSettings.Instance.get(UserSettingsKey.SnapGridDistance)))
if (string.IsNullOrEmpty(UserSettings.Instance.get(UserSettingsKey.SnapGridDistance)))
{
return 1;
}
return UserSettings.Instance.GetValue<double>(UserSettingsKey.SnapGridDistance);
}

View file

@ -611,7 +611,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
// draw on top of anything that is already drawn
GL.Disable(EnableCap.DepthTest);
foreach (InteractionVolume interactionVolume in this.InteractionVolumes)
foreach (var interactionVolume in this.InteractionVolumes.OfType<IGLInteractionElement>())
{
if (interactionVolume.DrawOnTop)
{
@ -623,7 +623,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
GL.Enable(EnableCap.DepthTest);
// Draw again setting the depth buffer and ensuring that all the interaction objects are sorted as well as we can
foreach (InteractionVolume interactionVolume in this.InteractionVolumes)
foreach (var interactionVolume in this.InteractionVolumes.OfType<IGLInteractionElement>())
{
interactionVolume.DrawGlContent(new DrawGlContentEventArgs(true, e));
}

View file

@ -1047,19 +1047,13 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
if (selectedItem != null)
{
foreach (InteractionVolume volume in this.InteractionLayer.InteractionVolumes)
foreach (var volume in this.InteractionLayer.InteractionVolumes)
{
volume.SetPosition(selectedItem);
}
}
base.OnDraw(graphics2D);
if (selectedItem != null)
{
// DrawTestToGl(graphics2D, selectedItem);
}
}
private void AfterDraw3DContent(object sender, DrawEventArgs e)