Improved measure tool

This commit is contained in:
LarsBrubaker 2021-04-17 22:35:53 -07:00
parent ed0940605b
commit f59b323c61
32 changed files with 277 additions and 81 deletions

View file

@ -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.Class)]
public class HideMeterialAndColor : Attribute
{
public HideMeterialAndColor()
{
}
}
}

View file

@ -38,4 +38,15 @@ namespace MatterHackers.MatterControl.DesignTools
{
}
}
[AttributeUsage(AttributeTargets.Class)]
public class MarkDownDescriptionAttribute : Attribute
{
public MarkDownDescriptionAttribute(string markdown)
{
this.Markdown = markdown;
}
public string Markdown { get; }
}
}

View file

@ -69,8 +69,8 @@ namespace MatterHackers.Plugins.EditorTools
private Vector2 sizeOnMouseDown;
private Matrix4X4 matrixOnMouseDown;
public ScaleWidthDepthCornerControl(IObject3DControlContext context, int quadrant)
: base(context)
public ScaleWidthDepthCornerControl(IObject3DControlContext object3DControlContext, int quadrant)
: base(object3DControlContext)
{
theme = MatterControl.AppContext.Theme;

View file

@ -33,8 +33,12 @@ using MatterHackers.MatterControl.PartPreviewWindow;
namespace MatterHackers.MatterControl.DesignTools
{
public interface IEditorDraw
public interface ISelectedEditorDraw
{
void DrawEditor(Object3DControlsLayer object3DControlLayer, List<Object3DView> transparentMeshes, DrawEventArgs e);
}
public interface IAlwaysEditorDraw : ISelectedEditorDraw
{
}
}

View file

@ -53,7 +53,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
[Obsolete("Use CurveObject3D_3 instead", false)]
public class CurveObject3D : MeshWrapperObject3D, IEditorDraw
public class CurveObject3D : MeshWrapperObject3D, ISelectedEditorDraw
{
// holds where we rotate the object
private Vector2 rotationCenter;

View file

@ -64,7 +64,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
}
[Obsolete("Not used anymore. Replaced with FitToBoundsObject3D_2", true)]
public class FitToBoundsObject3D : Object3D, IEditorDraw, IPropertyGridModifier
public class FitToBoundsObject3D : Object3D, ISelectedEditorDraw, IPropertyGridModifier
{
[Description("Set the shape the part will be fit into.")]
public FitType FitType { get; set; } = FitType.Box;

View file

@ -42,7 +42,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools.Operations
{
public class ArrayRadialObject3D : ArrayObject3D, IEditorDraw
public class ArrayRadialObject3D : ArrayObject3D, ISelectedEditorDraw
{
public ArrayRadialObject3D()
{

View file

@ -52,7 +52,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
[Obsolete("Use CurveObject3D_3 instead", false)]
public class CurveObject3D_2 : OperationSourceContainerObject3D, IEditorDraw
public class CurveObject3D_2 : OperationSourceContainerObject3D, ISelectedEditorDraw
{
public CurveObject3D_2()
{

View file

@ -46,7 +46,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
public class CurveObject3D_3 : OperationSourceContainerObject3D, IPropertyGridModifier, IEditorDraw
public class CurveObject3D_3 : OperationSourceContainerObject3D, IPropertyGridModifier, ISelectedEditorDraw
{
public CurveObject3D_3()
{

View file

@ -45,7 +45,7 @@ using System.Threading.Tasks;
namespace MatterHackers.MatterControl.DesignTools.Operations
{
public class FitToBoundsObject3D_2 : TransformWrapperObject3D, IEditorDraw
public class FitToBoundsObject3D_2 : TransformWrapperObject3D, ISelectedEditorDraw
{
private Vector3 boundsSize;

View file

@ -49,7 +49,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools.Operations
{
public class FitToCylinderObject3D : TransformWrapperObject3D, IEditorDraw
public class FitToCylinderObject3D : TransformWrapperObject3D, ISelectedEditorDraw
{
public FitToCylinderObject3D()
{

View file

@ -51,7 +51,7 @@ using Polygons = System.Collections.Generic.List<System.Collections.Generic.List
namespace MatterHackers.MatterControl.DesignTools
{
public class ImageToPathObject3D : Object3D, IPathObject, IEditorDraw, IObject3DControlsProvider
public class ImageToPathObject3D : Object3D, IPathObject, ISelectedEditorDraw, IObject3DControlsProvider
{
private ThresholdFunctions _featureDetector = ThresholdFunctions.Silhouette;

View file

@ -48,7 +48,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
Sharp,
}
public class InflatePathObject3D : Object3D, IPathObject, IEditorDraw, IObject3DControlsProvider
public class InflatePathObject3D : Object3D, IPathObject, ISelectedEditorDraw, IObject3DControlsProvider
{
public IVertexSource VertexSource { get; set; } = new VertexStorage();

View file

@ -42,7 +42,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools.Operations
{
public class MergePathObject3D : OperationSourceContainerObject3D, IPathObject, IEditorDraw, IObject3DControlsProvider
public class MergePathObject3D : OperationSourceContainerObject3D, IPathObject, ISelectedEditorDraw, IObject3DControlsProvider
{
private bool union;
private string operationName;

View file

@ -43,7 +43,7 @@ using MatterHackers.MatterControl.PartPreviewWindow;
namespace MatterHackers.MatterControl.DesignTools.Operations
{
public class OutlinePathObject3D : Object3D, IPathObject, IEditorDraw, IObject3DControlsProvider
public class OutlinePathObject3D : Object3D, IPathObject, ISelectedEditorDraw, IObject3DControlsProvider
{
public IVertexSource VertexSource { get; set; } = new VertexStorage();

View file

@ -46,7 +46,7 @@ using Newtonsoft.Json;
namespace MatterHackers.MatterControl.DesignTools.Operations
{
public class RevolveObject3D : Object3D, IEditorDraw
public class RevolveObject3D : Object3D, ISelectedEditorDraw
{
[MaxDecimalPlaces(2)]
public double AxisPosition { get; set; } = 0;

View file

@ -43,7 +43,7 @@ using Polygons = System.Collections.Generic.List<System.Collections.Generic.List
namespace MatterHackers.MatterControl.DesignTools.Operations
{
public class SmoothPathObject3D : Object3D, IPathObject, IEditorDraw, IObject3DControlsProvider
public class SmoothPathObject3D : Object3D, IPathObject, ISelectedEditorDraw, IObject3DControlsProvider
{
public IVertexSource VertexSource { get; set; } = new VertexStorage();

View file

@ -42,7 +42,7 @@ using Newtonsoft.Json;
namespace MatterHackers.MatterControl.DesignTools.Operations
{
public class RotateObject3D_2 : TransformWrapperObject3D, IEditorDraw
public class RotateObject3D_2 : TransformWrapperObject3D, ISelectedEditorDraw
{
public RotateObject3D_2()
{

View file

@ -42,7 +42,7 @@ using Newtonsoft.Json;
namespace MatterHackers.MatterControl.DesignTools.Operations
{
public class ScaleObject3D : TransformWrapperObject3D, IEditorDraw, IPropertyGridModifier
public class ScaleObject3D : TransformWrapperObject3D, ISelectedEditorDraw, IPropertyGridModifier
{
public enum ScaleType
{

View file

@ -48,7 +48,7 @@ using Newtonsoft.Json;
namespace MatterHackers.MatterControl.DesignTools
{
public class TwistObject3D : OperationSourceContainerObject3D, IPropertyGridModifier, IEditorDraw
public class TwistObject3D : OperationSourceContainerObject3D, IPropertyGridModifier, ISelectedEditorDraw
{
public TwistObject3D()
{

View file

@ -59,7 +59,7 @@ namespace MatterHackers.MatterControl.DesignTools
Outline
}
public class BaseObject3D : Object3D, IPropertyGridModifier, IEditorDraw
public class BaseObject3D : Object3D, IPropertyGridModifier, ISelectedEditorDraw
{
public enum CenteringTypes
{

View file

@ -115,6 +115,8 @@ namespace MatterHackers.MatterControl.DesignTools
public void AddObject3DControls(Object3DControlsLayer object3DControlsLayer)
{
object3DControlsLayer.AddControls(ControlTypes.ScaleWidthDepth);
object3DControlsLayer.AddControls(ControlTypes.MoveInZ);
object3DControlsLayer.AddControls(ControlTypes.RotateXYZ);
}
}
}

View file

@ -33,6 +33,7 @@ using System.IO;
using System.Threading;
using System.Threading.Tasks;
using MatterHackers.Agg;
using MatterHackers.Agg.Font;
using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
@ -42,12 +43,13 @@ using MatterHackers.MeshVisualizer;
using MatterHackers.PolygonMesh;
using MatterHackers.PolygonMesh.Processors;
using MatterHackers.RenderOpenGl;
using MatterHackers.RenderOpenGl.OpenGl;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
public class MeasureToolObject3D : Object3D, IObject3DControlsProvider, IEditorDraw
[MarkDownDescription("Drag the spheres to the locations you would like to measure the distance between.")]
[HideMeterialAndColor]
public class MeasureToolObject3D : Object3D, IObject3DControlsProvider, IAlwaysEditorDraw, IEditorButtonProvider
{
private static Mesh shape = null;
private List<IObject3DControl> editorControls = null;
@ -82,7 +84,9 @@ namespace MatterHackers.MatterControl.DesignTools
public Vector3 EndPosition { get; set; } = new Vector3(10, 5, 3);
[ReadOnly(true)]
public double Distance { get; set; } = 10;
public double Distance { get; set; } = 0;
public bool AlwaysVisible { get; set; } = false;
[HideFromEditor]
public bool PositionsHaveBeenSet { get; set; } = false;
@ -168,16 +172,72 @@ namespace MatterHackers.MatterControl.DesignTools
return Task.CompletedTask;
}
public void DrawEditor(Object3DControlsLayer object3DControlLayer, List<Object3DView> transparentMeshes, DrawEventArgs e)
public void DrawEditor(Object3DControlsLayer controlLayer, List<Object3DView> transparentMeshes, DrawEventArgs e)
{
if (controlLayer.Scene.SelectedItem != this
&& !AlwaysVisible)
{
return;
}
var start = PositionsHaveBeenSet ? StartPosition : StartPosition.Transform(Matrix);
var end = PositionsHaveBeenSet ? EndPosition : EndPosition.Transform(Matrix);
var world = controlLayer.World;
// draw on top of anything that is already drawn
object3DControlLayer.World.Render3DLine(start, end, Color.Black.WithAlpha(Constants.LineAlpha), false, width: GuiWidget.DeviceScale);
world.Render3DLine(start,
end,
Color.Black.WithAlpha(Constants.LineAlpha),
false,
width: GuiWidget.DeviceScale,
true,
true);
// Restore DepthTest
object3DControlLayer.World.Render3DLine(start, end, Color.Black, true, width: GuiWidget.DeviceScale);
world.Render3DLine(start, end, Color.Black, true, width: GuiWidget.DeviceScale);
var screenStart = world.GetScreenPosition(start);
var screenEnd = world.GetScreenPosition(end);
var center = (screenStart + screenEnd) / 2;
if (PositionsHaveBeenSet)
{
controlLayer.DrawBeforeGui((graphics) =>
{
var number = new TypeFacePrinter(Distance.ToString("0.##"),
10,
center,
Justification.Center,
Baseline.BoundsCenter);
var theme = ApplicationController.Instance.MenuTheme;
var bounds = number.LocalBounds;
bounds.Inflate(3 * GuiWidget.DeviceScale);
graphics.Render(new RoundedRectShape(bounds, 3 * GuiWidget.DeviceScale), theme.BackgroundColor);
graphics.Render(number, theme.TextColor);
});
}
}
public IEnumerable<EditorButtonData> GetEditorButtonsData()
{
yield return new EditorButtonData()
{
Action = () =>
{
StartPosition = new Vector3(-10, 5, 3);
EndPosition = new Vector3(10, 5, 3);
Distance = 0;
PositionsHaveBeenSet = false;
UiThread.RunOnIdle(() => Invalidate(InvalidateType.DisplayValues));
},
HelpText = "Reset the line ends back to their starting positions".Localize(),
Name = "Reset".Localize(),
};
}
}
}

View file

@ -42,7 +42,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
public class SetTemperatureObject3D : Object3D, IObject3DControlsProvider, IGCodeTransformer, IEditorDraw
public class SetTemperatureObject3D : Object3D, IObject3DControlsProvider, IGCodeTransformer, ISelectedEditorDraw
{
private bool hasBeenReached;
private double accumulatedLayerHeight;

View file

@ -47,7 +47,7 @@ using Newtonsoft.Json.Converters;
namespace MatterHackers.MatterControl.DesignTools
{
public class TextPathObject3D : Object3D, IPathObject, IEditorDraw
public class TextPathObject3D : Object3D, IPathObject, ISelectedEditorDraw
{
public TextPathObject3D()
{

View file

@ -46,6 +46,9 @@ namespace MatterHackers.MatterControl.DesignTools
private readonly double blockSize = 11 * GuiWidget.DeviceScale;
private ITraceable collisionVolume;
public IObject3DControlContext Object3DControlContext { get; }
private ThemeConfig theme;
private IObject3DControlContext context;
@ -57,12 +60,18 @@ namespace MatterHackers.MatterControl.DesignTools
private Mesh shape;
private bool mouseOver;
private PlaneShape hitPlane;
private bool downOnControl;
public TracedPositionObject3DControl(IObject3DControlContext context, IObject3D owner, Func<Vector3> getPosition, Action<Vector3> setPosition)
public TracedPositionObject3DControl(IObject3DControlContext object3DControlContext,
IObject3D owner,
Func<Vector3> getPosition,
Action<Vector3> setPosition)
{
this.Object3DControlContext = object3DControlContext;
this.theme = ApplicationController.Instance.Theme;
this.context = context;
this.context = object3DControlContext;
this.getPosition = getPosition;
this.setPosition = setPosition;
this.shape = PlatonicSolids.CreateCube();
@ -93,7 +102,13 @@ namespace MatterHackers.MatterControl.DesignTools
color = theme.PrimaryAccentColor;
}
GLHelper.Render(shape, color, ShapeMatrix(), RenderTypes.Shaded);
GLHelper.Render(shape, color.WithAlpha(e.Alpha0to255), ShapeMatrix(), RenderTypes.Shaded);
if (hitPlane != null)
{
//Object3DControlContext.World.RenderPlane(hitPlane.Plane, Color.Red, true, 30, 3);
//Object3DControlContext.World.RenderPlane(initialHitPosition, hitPlane.Plane.Normal, Color.Red, true, 30, 3);
}
}
private Matrix4X4 ShapeMatrix()
@ -114,6 +129,7 @@ namespace MatterHackers.MatterControl.DesignTools
public void OnMouseDown(Mouse3DEventArgs mouseEvent3D)
{
hitPlane = new PlaneShape(new Plane(mouseEvent3D.MouseRay.directionNormal, mouseEvent3D.info.HitPosition), null);
downOnControl = true;
}
@ -130,22 +146,36 @@ namespace MatterHackers.MatterControl.DesignTools
var ray = context.World.GetRayForLocalBounds(mouseEvent3D.MouseEvent2D.Position);
var scene = context.Scene;
var intersectionInfo = scene.GetBVHData().GetClosestIntersection(ray);
if (intersectionInfo != null)
var oldPosition = getPosition();
var newPosition = oldPosition;
if (intersectionInfo == null)
{
intersectionInfo = hitPlane.GetClosestIntersection(ray);
if (intersectionInfo != null)
{
newPosition = intersectionInfo.HitPosition;
}
}
else
{
hitPlane = new PlaneShape(new Plane(mouseEvent3D.MouseRay.directionNormal, intersectionInfo.HitPosition), null);
foreach (var object3D in scene.Children)
{
if (object3D.GetBVHData().Contains(intersectionInfo.HitPosition))
{
var newPosition = intersectionInfo.HitPosition;
if (newPosition != getPosition())
{
setPosition(newPosition);
context.GuiSurface.Invalidate();
break;
}
newPosition = intersectionInfo.HitPosition;
break;
}
}
}
if (newPosition != oldPosition)
{
setPosition(newPosition);
context.GuiSurface.Invalidate();
}
}
}

View file

@ -33,6 +33,7 @@ using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Threading;
using Markdig.Agg;
using MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.Platform;
@ -84,6 +85,8 @@ namespace MatterHackers.MatterControl.DesignTools
// CreateEditor
AddUnlockLinkIfRequired(context.item, mainContainer, theme);
AddMarkDownDescription(context.item, mainContainer, theme);
GuiWidget scope = mainContainer;
@ -185,7 +188,7 @@ namespace MatterHackers.MatterControl.DesignTools
}
var row = new SettingsRow("".Localize(), null, editorButton, theme);
editorButtonData.SetStates(editorButton, row);
editorButtonData.SetStates?.Invoke(editorButton, row);
editorButton.Click += (s, e) =>
{
editorButtonData.Action?.Invoke();
@ -1003,6 +1006,21 @@ namespace MatterHackers.MatterControl.DesignTools
}
}
public static void AddMarkDownDescription(IObject3D item, GuiWidget editControlsContainer, ThemeConfig theme)
{
if (item.GetType().GetCustomAttributes(typeof(MarkDownDescriptionAttribute), true).FirstOrDefault() is MarkDownDescriptionAttribute markdownDescription)
{
var markdownWidget = new MarkdownWidget(theme)
{
Padding = new BorderDouble(left: theme.DefaultContainerPadding / 2),
Markdown = markdownDescription.Markdown,
VAnchor = VAnchor.Fit
};
editControlsContainer.AddChild(markdownWidget);
}
}
public static GuiWidget GetUnlockRow(ThemeConfig theme, string url)
{
var detailsLink = new TextIconButton("Unlock".Localize(), StaticData.Instance.LoadIcon("locked.png", 16, 16, theme.InvertIcons), theme)

View file

@ -241,59 +241,62 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
var undoBuffer = sceneContext.Scene.UndoBuffer;
// put in a color edit field
var colorField = new ColorField(theme, selectedItem.Color);
colorField.Initialize(0);
colorField.ValueChanged += (s, e) =>
if (!(selectedItem.GetType().GetCustomAttributes(typeof(HideMeterialAndColor), true).FirstOrDefault() is HideMeterialAndColor))
{
if (selectedItem.Color != colorField.Color)
// put in a color edit field
var colorField = new ColorField(theme, selectedItem.Color);
colorField.Initialize(0);
colorField.ValueChanged += (s, e) =>
{
undoBuffer.AddAndDo(new ChangeColor(selectedItem, colorField.Color));
}
};
if (selectedItem.Color != colorField.Color)
{
undoBuffer.AddAndDo(new ChangeColor(selectedItem, colorField.Color));
}
};
colorField.Content.MouseDown += (s, e) =>
{
colorField.Content.MouseDown += (s, e) =>
{
// make sure the render mode is set to shaded or outline
if (sceneContext.ViewState.RenderType != RenderOpenGl.RenderTypes.Shaded
&& sceneContext.ViewState.RenderType != RenderOpenGl.RenderTypes.Outlines)
{
&& sceneContext.ViewState.RenderType != RenderOpenGl.RenderTypes.Outlines)
{
// make sure the render mode is set to outline
sceneContext.ViewState.RenderType = RenderOpenGl.RenderTypes.Outlines;
}
};
}
};
// color row
var row = new SettingsRow("Color".Localize(), null, colorField.Content, theme);
// color row
var row = new SettingsRow("Color".Localize(), null, colorField.Content, theme);
// Special top border style for first item in editor
row.Border = new BorderDouble(0, 1);
// Special top border style for first item in editor
row.Border = new BorderDouble(0, 1);
editorPanel.AddChild(row);
editorPanel.AddChild(row);
// put in a material edit field
var materialField = new MaterialIndexField(sceneContext.Printer, theme, selectedItem.MaterialIndex);
materialField.Initialize(0);
materialField.ValueChanged += (s, e) =>
{
if (selectedItem.MaterialIndex != materialField.MaterialIndex)
// put in a material edit field
var materialField = new MaterialIndexField(sceneContext.Printer, theme, selectedItem.MaterialIndex);
materialField.Initialize(0);
materialField.ValueChanged += (s, e) =>
{
undoBuffer.AddAndDo(new ChangeMaterial(selectedItem, materialField.MaterialIndex));
}
};
if (selectedItem.MaterialIndex != materialField.MaterialIndex)
{
undoBuffer.AddAndDo(new ChangeMaterial(selectedItem, materialField.MaterialIndex));
}
};
materialField.Content.MouseDown += (s, e) =>
{
if (sceneContext.ViewState.RenderType != RenderOpenGl.RenderTypes.Materials)
materialField.Content.MouseDown += (s, e) =>
{
if (sceneContext.ViewState.RenderType != RenderOpenGl.RenderTypes.Materials)
{
// make sure the render mode is set to material
sceneContext.ViewState.RenderType = RenderOpenGl.RenderTypes.Materials;
}
};
}
};
// material row
editorPanel.AddChild(
new SettingsRow("Material".Localize(), null, materialField.Content, theme));
// material row
editorPanel.AddChild(
new SettingsRow("Material".Localize(), null, materialField.Content, theme));
}
// put in the normal editor
if (selectedItem is ComponentObject3D componentObject

View file

@ -46,7 +46,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
{
[ShowUpdateButton]
public class SubtractAndReplaceObject3D_2 : OperationSourceContainerObject3D, ISelectableChildContainer, IEditorDraw
public class SubtractAndReplaceObject3D_2 : OperationSourceContainerObject3D, ISelectableChildContainer, ISelectedEditorDraw
{
public SubtractAndReplaceObject3D_2()
{

View file

@ -45,7 +45,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
{
[ShowUpdateButton]
public class SubtractObject3D_2 : OperationSourceContainerObject3D, ISelectableChildContainer, IEditorDraw
public class SubtractObject3D_2 : OperationSourceContainerObject3D, ISelectableChildContainer, ISelectedEditorDraw
{
public SubtractObject3D_2()
{

View file

@ -46,7 +46,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
{
public class SubtractPathObject3D : OperationSourceContainerObject3D, IPathObject, IEditorDraw, IObject3DControlsProvider
public class SubtractPathObject3D : OperationSourceContainerObject3D, IPathObject, ISelectedEditorDraw, IObject3DControlsProvider
{
public SubtractPathObject3D()
{

View file

@ -205,6 +205,25 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
});
}
private List<Action<Graphics2D>> drawBeforeCallbacks = new List<Action<Graphics2D>>();
public void DrawBeforeGui(Action<Graphics2D> drawFunction)
{
drawBeforeCallbacks.Add(drawFunction);
}
public override void OnDraw(Graphics2D graphics2D)
{
foreach (var draw in drawBeforeCallbacks)
{
draw(graphics2D);
}
drawBeforeCallbacks.Clear();
base.OnDraw(graphics2D);
}
public void AddControls(ControlTypes controls)
{
if (controls.HasFlag(ControlTypes.RotateXYZ))
@ -939,6 +958,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
return bCenterInViewSpace.LengthSquared.CompareTo(aCenterInViewSpace.LengthSquared);
}
private HashSet<IObject3D> editorDrawItems = new HashSet<IObject3D>();
private void DrawGlContent(DrawEventArgs e)
{
var gcodeOptions = sceneContext.RendererOptions;
@ -974,6 +994,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
var transparentMeshes = new List<Object3DView>();
var selectedItem = scene.SelectedItem;
editorDrawItems.Clear();
editorDrawItems.Add(selectedItem);
foreach (var item in scene.Children)
{
@ -981,6 +1003,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
DrawObject(item, transparentMeshes, e);
}
if (item is IAlwaysEditorDraw editorDraw)
{
editorDrawItems.Add(item);
}
}
if (sceneContext.Printer?.Connection?.serialPort is PrinterEmulator.Emulator emulator)
@ -1059,10 +1086,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
// Draw the editor items in the same scope as the 3D Controls
if (selectedItem != null)
foreach (var item in editorDrawItems)
{
// Invoke existing IEditorDraw when iterating items
if (selectedItem is IEditorDraw editorDraw)
if (item is ISelectedEditorDraw editorDraw)
{
editorDraw.DrawEditor(this, transparentMeshes, e);
}