make esc work on description and measure tools

issue: MatterHackers/MCCentral#6391
Make Esc on drag trace object work

issue: MatterHackers/MCCentral#6395
fix local positions on measure tool
This commit is contained in:
LarsBrubaker 2021-04-27 07:19:02 -07:00
parent a1f02aff54
commit d7e8ecc744
4 changed files with 43 additions and 18 deletions

View file

@ -31,7 +31,6 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
using Markdig.Agg;
@ -320,6 +319,17 @@ namespace MatterHackers.MatterControl.DesignTools
markdownWidget.MouseDown += MarkdownWidget_MouseDown;
markdownWidget.MouseMove += MarkdownWidget_MouseMove;
markdownWidget.MouseUp += MarkdownWidget_MouseUp;
markdownWidget.KeyDown += MarkdownWidget_KeyDown; ;
}
}
private void MarkdownWidget_KeyDown(object sender, KeyEventArgs e)
{
if (mouseDownOnWidget
&& e.KeyCode == Keys.Escape)
{
mouseDownOnWidget = false;
worldPosition = mouseDownPosition;
}
}

View file

@ -111,10 +111,10 @@ namespace MatterHackers.MatterControl.DesignTools
[HideFromEditor]
public Vector3 LocalStartPosition { get; set; } = new Vector3(-10, 5, 3);
public Vector3 LocalStartPosition { get; set; }
[HideFromEditor]
public Vector3 LocalEndPosition { get; set; } = new Vector3(10, 5, 3);
public Vector3 LocalEndPosition { get; set; }
[ReadOnly(true)]
@ -133,16 +133,12 @@ namespace MatterHackers.MatterControl.DesignTools
{
new TracedPositionObject3DControl(object3DControlsLayer,
this,
() =>
{
return PositionsHaveBeenSet ? worldStartPosition : worldStartPosition.Transform(Matrix);
},
() => worldStartPosition,
(position) =>
{
if (!PositionsHaveBeenSet)
{
PositionsHaveBeenSet = true;
worldEndPosition = worldEndPosition.Transform(this.Matrix);
}
worldStartPosition = position;
@ -151,16 +147,12 @@ namespace MatterHackers.MatterControl.DesignTools
}),
new TracedPositionObject3DControl(object3DControlsLayer,
this,
() =>
{
return PositionsHaveBeenSet ? worldEndPosition : worldEndPosition.Transform(Matrix);
},
() => worldEndPosition,
(position) =>
{
if (!PositionsHaveBeenSet)
{
PositionsHaveBeenSet = true;
worldStartPosition = worldStartPosition.Transform(this.Matrix);
}
worldEndPosition = position;
@ -206,8 +198,15 @@ namespace MatterHackers.MatterControl.DesignTools
public void DrawEditor(Object3DControlsLayer controlLayer, List<Object3DView> transparentMeshes, DrawEventArgs e)
{
var start = PositionsHaveBeenSet ? worldStartPosition : worldStartPosition.Transform(Matrix);
var end = PositionsHaveBeenSet ? worldEndPosition : worldEndPosition.Transform(Matrix);
if (!PositionsHaveBeenSet)
{
var aabb = this.Mesh.GetAxisAlignedBoundingBox();
LocalStartPosition = aabb.Center + new Vector3(-10, 5, 3);
LocalEndPosition = aabb.Center + new Vector3(10, 5, 3);
}
var start = worldStartPosition;
var end = worldEndPosition;
var world = controlLayer.World;
// draw on top of anything that is already drawn
@ -238,6 +237,7 @@ namespace MatterHackers.MatterControl.DesignTools
CreateWidgetIfRequired(controlLayer);
textWidget.Text = Distance.ToString("0.##");
containerWidget.Position = center - new Vector2(containerWidget.LocalBounds.Width / 2, containerWidget.LocalBounds.Height / 2);
containerWidget.Visible = true;
}
}
@ -298,8 +298,6 @@ namespace MatterHackers.MatterControl.DesignTools
{
Action = () =>
{
LocalStartPosition = new Vector3(-10, 5, 3);
LocalEndPosition = new Vector3(10, 5, 3);
Distance = 0;
if (containerWidget != null)
{

View file

@ -63,6 +63,8 @@ namespace MatterHackers.MatterControl.DesignTools
public PlaneShape HitPlane { get; private set; }
public bool DownOnControl { get; private set; }
private Vector3 mouseDownPosition;
public TracedPositionObject3DControl(IObject3DControlContext object3DControlContext,
IObject3D owner,
Func<Vector3> getPosition,
@ -78,6 +80,19 @@ namespace MatterHackers.MatterControl.DesignTools
this.shape = SphereObject3D.CreateSphere(1, 15, 10);
collisionVolume = shape.CreateBVHData();
this.owner = owner;
Keyboard.StateChanged += Keyboard_StateChanged;
}
private void Keyboard_StateChanged(object sender, EventArgs e)
{
if (DownOnControl
&& Keyboard.IsKeyDown(Keys.Escape))
{
DownOnControl = false;
setPosition(mouseDownPosition);
return;
}
}
public bool DrawOnTop => true;
@ -92,6 +107,7 @@ namespace MatterHackers.MatterControl.DesignTools
public void Dispose()
{
Keyboard.StateChanged -= Keyboard_StateChanged;
}
public void Draw(DrawGlContentEventArgs e)
@ -130,6 +146,7 @@ namespace MatterHackers.MatterControl.DesignTools
public void OnMouseDown(Mouse3DEventArgs mouseEvent3D)
{
DownOnControl = true;
mouseDownPosition = getPosition();
// Make sure we always get a new hit plane
ResetHitPlane();
}

@ -1 +1 @@
Subproject commit 04db6991f2bd3175afb65f6b9a4bceb7723caec3
Subproject commit 8b63c00291f013be69d95e96564d7fc766d3fd17