Add mechanism to override default IAVolumes per type

- Change .InteractionVolumes from List to IEnumerable
- Add mappings of type -> IAVolument overrides
- Conditionally returned mapped IAVolume overrides
- Force IAVolume registration through .RegisterIAVolume()
This commit is contained in:
John Lewin 2019-02-02 19:43:50 -08:00
parent d8c8be922d
commit 1a33e8d074
3 changed files with 38 additions and 10 deletions

View file

@ -34,6 +34,7 @@ using MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.MatterControl.DesignTools;
using MatterHackers.MeshVisualizer;
using MatterHackers.RayTracer;
using MatterHackers.RayTracer.Traceable;
@ -46,15 +47,37 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
private InteractionVolume mouseDownIAVolume = null;
/// <summary>
/// Contains type to IAVolume mappings
/// </summary>
private Dictionary<Type, List<InteractionVolume>> iavMappings = new Dictionary<Type, List<InteractionVolume>>();
public WorldView World => sceneContext.World;
public InteractiveScene Scene => sceneContext.Scene;
public bool DoOpenGlDrawing { get; set; } = true;
// TODO: Collapse into auto-property
private List<InteractionVolume> interactionVolumes = new List<InteractionVolume>();
public List<InteractionVolume> InteractionVolumes { get; }
private List<InteractionVolume> registeredIAVolumes = new List<InteractionVolume>();
public IEnumerable<InteractionVolume> InteractionVolumes
{
get
{
if (selectedItemType == null)
{
return Enumerable.Empty<InteractionVolume>();
}
else if (iavMappings.TryGetValue(selectedItemType, out List<InteractionVolume> mappedIAVolumes))
{
return mappedIAVolumes;
}
else
{
return registeredIAVolumes;
}
}
}
private LightingData lighting = new LightingData();
private GuiWidget renderSource;
@ -62,7 +85,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
public InteractionLayer(ISceneContext sceneContext, ThemeConfig theme, EditorType editorType = EditorType.Part)
{
this.sceneContext = sceneContext;
this.InteractionVolumes = interactionVolumes;
this.EditorMode = editorType;
this.theme = theme;
@ -87,11 +109,18 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
var plugin = ImageGlPlugin.GetImageGlPlugin(ViewOnlyTexture, true, true, false);
});
}
iavMappings.Add(typeof(ImageObject3D), new List<InteractionVolume> { new MoveInZControlTest(this) });
}
public void RegisterDrawable(IDrawable drawable)
{
this.drawables.Add(drawable);
drawables.Add(drawable);
}
public void RegisterIAVolume(InteractionVolume interactionVolume)
{
registeredIAVolumes.Add(interactionVolume);
}
public IEnumerable<IDrawable> Drawables => drawables;

View file

@ -185,7 +185,6 @@ namespace MatterHackers.MeshVisualizer
GuiWidget GuiSurface { get; }
List<InteractionVolume> InteractionVolumes { get; }
double SnapGridDistance { get; }
}

View file

@ -346,15 +346,15 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
viewOptionsBar.AddChild(gridSnapButton);
var interactionVolumes = this.InteractionLayer.InteractionVolumes;
interactionVolumes.Add(new MoveInZControl(this.InteractionLayer));
interactionVolumes.Add(new SelectionShadow(this.InteractionLayer));
interactionVolumes.Add(new SnappingIndicators(this.InteractionLayer, this.CurrentSelectInfo));
this.InteractionLayer.RegisterIAVolume(new MoveInZControl(this.InteractionLayer));
this.InteractionLayer.RegisterIAVolume(new SelectionShadow(this.InteractionLayer));
this.InteractionLayer.RegisterIAVolume(new SnappingIndicators(this.InteractionLayer, this.CurrentSelectInfo));
// Add IAVolumeProviderPlugins
foreach (var ivProvider in ApplicationController.Instance.Extensions.IAVolumeProviders)
{
interactionVolumes.AddRange(ivProvider.Create(this.InteractionLayer));
this.InteractionLayer.RegisterIAVolume(plugin.CreateInteractionVolume(this.InteractionLayer));
}
this.InteractionLayer.AfterDraw += AfterDraw3DContent;