2017-07-10 15:04:33 -07:00
|
|
|
|
/*
|
|
|
|
|
|
Copyright (c) 2014, Lars Brubaker
|
|
|
|
|
|
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;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
2017-07-14 13:55:02 -07:00
|
|
|
|
using System.Threading;
|
2017-07-10 15:04:33 -07:00
|
|
|
|
using MatterHackers.Agg;
|
2017-08-20 02:34:39 -07:00
|
|
|
|
using MatterHackers.Agg.Platform;
|
2017-07-10 15:04:33 -07:00
|
|
|
|
using MatterHackers.Agg.UI;
|
|
|
|
|
|
using MatterHackers.DataConverters3D;
|
2021-06-06 09:07:18 -07:00
|
|
|
|
using MatterHackers.Localizations;
|
2017-07-10 15:04:33 -07:00
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
|
|
|
|
|
using MatterHackers.MeshVisualizer;
|
|
|
|
|
|
using MatterHackers.PolygonMesh;
|
2018-07-31 10:32:25 -07:00
|
|
|
|
using MatterHackers.PolygonMesh.Processors;
|
2017-07-10 15:04:33 -07:00
|
|
|
|
using MatterHackers.RayTracer;
|
|
|
|
|
|
using MatterHackers.RenderOpenGl;
|
|
|
|
|
|
using MatterHackers.VectorMath;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.PartPreviewWindow
|
|
|
|
|
|
{
|
2020-09-12 13:09:17 -07:00
|
|
|
|
public class MoveInZControl : Object3DControl
|
2017-07-10 15:04:33 -07:00
|
|
|
|
{
|
2020-09-11 19:59:14 -07:00
|
|
|
|
public IObject3D ActiveSelectedItem { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
private PlaneShape hitPlane;
|
|
|
|
|
|
private Vector3 initialHitPosition;
|
|
|
|
|
|
private readonly Mesh upArrowMesh;
|
|
|
|
|
|
private AxisAlignedBoundingBox mouseDownSelectedBounds;
|
|
|
|
|
|
private Matrix4X4 transformOnMouseDown = Matrix4X4.Identity;
|
2020-09-13 08:32:43 -07:00
|
|
|
|
private readonly double distToStart = 5 * GuiWidget.DeviceScale;
|
|
|
|
|
|
private readonly double lineLength = 55 * GuiWidget.DeviceScale;
|
2020-09-11 19:59:14 -07:00
|
|
|
|
private readonly List<Vector2> lines = new List<Vector2>();
|
|
|
|
|
|
private readonly double upArrowSize = 7 * GuiWidget.DeviceScale;
|
|
|
|
|
|
private readonly InlineEditControl zHeightDisplayInfo;
|
|
|
|
|
|
private bool hadClickOnControl;
|
|
|
|
|
|
private readonly ThemeConfig theme;
|
|
|
|
|
|
|
2021-06-06 09:07:18 -07:00
|
|
|
|
public override string UiHint => "Type 'Esc' to cancel".Localize();
|
|
|
|
|
|
|
2020-09-11 19:59:14 -07:00
|
|
|
|
public MoveInZControl(IObject3DControlContext context)
|
2017-07-12 22:12:08 -07:00
|
|
|
|
: base(context)
|
2017-07-10 15:04:33 -07:00
|
|
|
|
{
|
2019-04-26 18:51:45 -07:00
|
|
|
|
theme = AppContext.Theme;
|
2017-10-26 17:57:17 -07:00
|
|
|
|
Name = "MoveInZControl";
|
2017-11-08 23:24:10 -08:00
|
|
|
|
zHeightDisplayInfo = new InlineEditControl()
|
2017-07-10 15:04:33 -07:00
|
|
|
|
{
|
|
|
|
|
|
ForceHide = () =>
|
|
|
|
|
|
{
|
2018-08-08 14:00:35 -07:00
|
|
|
|
var selectedItem = RootSelection;
|
2017-07-10 15:04:33 -07:00
|
|
|
|
// if the selection changes
|
2017-12-26 21:05:16 -08:00
|
|
|
|
if (selectedItem != ActiveSelectedItem)
|
2017-07-10 15:04:33 -07:00
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// if another control gets a hover
|
2020-09-12 09:51:43 -07:00
|
|
|
|
if (Object3DControlContext.HoveredObject3DControl != this
|
|
|
|
|
|
&& Object3DControlContext.HoveredObject3DControl != null)
|
2017-07-10 15:04:33 -07:00
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// if we clicked on the control
|
2020-09-11 19:59:14 -07:00
|
|
|
|
if (hadClickOnControl)
|
2017-07-10 15:04:33 -07:00
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
2020-09-11 19:59:14 -07:00
|
|
|
|
},
|
2020-09-15 07:56:31 -07:00
|
|
|
|
GetDisplayString = (value) => "{0:0.0#}".FormatWith(value)
|
2017-07-10 15:04:33 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
zHeightDisplayInfo.VisibleChanged += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!zHeightDisplayInfo.Visible)
|
|
|
|
|
|
{
|
2020-09-11 19:59:14 -07:00
|
|
|
|
hadClickOnControl = false;
|
2017-07-10 15:04:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
zHeightDisplayInfo.EditComplete += (s, e) =>
|
|
|
|
|
|
{
|
2018-08-08 14:00:35 -07:00
|
|
|
|
var selectedItem = RootSelection;
|
2017-07-10 15:04:33 -07:00
|
|
|
|
|
|
|
|
|
|
Matrix4X4 startingTransform = selectedItem.Matrix;
|
|
|
|
|
|
|
|
|
|
|
|
var newZPosition = zHeightDisplayInfo.Value;
|
|
|
|
|
|
|
2020-09-12 09:51:43 -07:00
|
|
|
|
if (Object3DControlContext.SnapGridDistance > 0)
|
2017-07-10 15:04:33 -07:00
|
|
|
|
{
|
|
|
|
|
|
// snap this position to the grid
|
2020-09-12 09:51:43 -07:00
|
|
|
|
double snapGridDistance = Object3DControlContext.SnapGridDistance;
|
2017-07-10 15:04:33 -07:00
|
|
|
|
|
|
|
|
|
|
// snap this position to the grid
|
|
|
|
|
|
newZPosition = ((int)((newZPosition / snapGridDistance) + .5)) * snapGridDistance;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-21 07:27:58 -07:00
|
|
|
|
AxisAlignedBoundingBox originalSelectedBounds = selectedItem.GetAxisAlignedBoundingBox();
|
2019-01-11 16:49:34 -08:00
|
|
|
|
var moveAmount = newZPosition - originalSelectedBounds.MinXYZ.Z;
|
2017-07-10 15:04:33 -07:00
|
|
|
|
|
|
|
|
|
|
if (moveAmount != 0)
|
|
|
|
|
|
{
|
2020-09-11 19:59:14 -07:00
|
|
|
|
selectedItem.Matrix *= Matrix4X4.CreateTranslation(0, 0, moveAmount);
|
2017-07-10 15:04:33 -07:00
|
|
|
|
Invalidate();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-01 15:09:30 -08:00
|
|
|
|
context.Scene.AddTransformSnapshot(startingTransform);
|
2017-07-10 15:04:33 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2020-09-12 09:51:43 -07:00
|
|
|
|
Object3DControlContext.GuiSurface.AddChild(zHeightDisplayInfo);
|
2017-07-10 15:04:33 -07:00
|
|
|
|
|
|
|
|
|
|
DrawOnTop = true;
|
|
|
|
|
|
|
2020-11-25 07:39:36 -08:00
|
|
|
|
using (Stream arrowStream = StaticData.Instance.OpenStream(Path.Combine("Stls", "up_pointer.stl")))
|
2017-07-10 15:04:33 -07:00
|
|
|
|
{
|
2018-07-31 10:32:25 -07:00
|
|
|
|
upArrowMesh = StlProcessing.Load(arrowStream, CancellationToken.None);
|
2017-07-10 15:04:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-01 20:48:59 -07:00
|
|
|
|
CollisionVolume = upArrowMesh.CreateBVHData();
|
2017-07-10 15:04:33 -07:00
|
|
|
|
|
2020-09-15 23:00:25 -07:00
|
|
|
|
Object3DControlContext.GuiSurface.BeforeDraw += Object3DControl_BeforeDraw;
|
2017-07-10 15:04:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-12 19:44:18 -07:00
|
|
|
|
public override void Dispose()
|
|
|
|
|
|
{
|
|
|
|
|
|
zHeightDisplayInfo.Close();
|
2020-09-15 23:00:25 -07:00
|
|
|
|
Object3DControlContext.GuiSurface.BeforeDraw -= Object3DControl_BeforeDraw;
|
2020-09-12 19:44:18 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-02 00:52:04 +00:00
|
|
|
|
bool ShouldDrawMoveControls()
|
2017-07-10 15:04:33 -07:00
|
|
|
|
{
|
2018-06-05 13:38:25 -07:00
|
|
|
|
bool shouldDrawMoveControls = true;
|
2020-09-12 09:51:43 -07:00
|
|
|
|
if (Object3DControlContext.SelectedObject3DControl != null
|
|
|
|
|
|
&& Object3DControlContext.SelectedObject3DControl as MoveInZControl == null)
|
2017-07-10 15:04:33 -07:00
|
|
|
|
{
|
2018-06-05 13:38:25 -07:00
|
|
|
|
shouldDrawMoveControls = false;
|
2017-07-10 15:04:33 -07:00
|
|
|
|
}
|
2022-03-02 00:52:04 +00:00
|
|
|
|
return shouldDrawMoveControls;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void Draw(DrawGlContentEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool shouldDrawMoveControls = ShouldDrawMoveControls();
|
2017-07-10 15:04:33 -07:00
|
|
|
|
|
2018-08-08 14:00:35 -07:00
|
|
|
|
var selectedItem = RootSelection;
|
2018-06-05 13:38:25 -07:00
|
|
|
|
if (selectedItem != null)
|
2017-07-10 15:04:33 -07:00
|
|
|
|
{
|
2018-06-05 13:38:25 -07:00
|
|
|
|
if (shouldDrawMoveControls)
|
2017-07-10 15:04:33 -07:00
|
|
|
|
{
|
|
|
|
|
|
// don't draw if any other control is dragging
|
2021-04-12 18:00:59 -07:00
|
|
|
|
if (MouseIsOver || MouseDownOnControl)
|
2017-07-10 15:04:33 -07:00
|
|
|
|
{
|
2019-04-26 18:51:45 -07:00
|
|
|
|
GLHelper.Render(upArrowMesh, theme.PrimaryAccentColor, TotalTransform, RenderTypes.Shaded);
|
2017-07-10 15:04:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-04-26 18:51:45 -07:00
|
|
|
|
GLHelper.Render(upArrowMesh, theme.TextColor, TotalTransform, RenderTypes.Shaded);
|
2017-07-10 15:04:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-11 19:59:14 -07:00
|
|
|
|
base.Draw(e);
|
2017-07-10 15:04:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Vector3 GetTopPosition(IObject3D selectedItem)
|
|
|
|
|
|
{
|
2019-05-21 07:27:58 -07:00
|
|
|
|
AxisAlignedBoundingBox originalSelectedBounds = selectedItem.GetAxisAlignedBoundingBox();
|
2019-01-11 16:49:34 -08:00
|
|
|
|
if (originalSelectedBounds.MinXYZ.X != double.PositiveInfinity)
|
2017-08-08 17:49:26 -07:00
|
|
|
|
{
|
2019-01-11 16:49:34 -08:00
|
|
|
|
return new Vector3(originalSelectedBounds.Center.X, originalSelectedBounds.Center.Y, originalSelectedBounds.MaxXYZ.Z);
|
2017-08-08 17:49:26 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Vector3.Zero;
|
2017-07-10 15:04:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-28 11:39:41 -07:00
|
|
|
|
public override void OnMouseDown(Mouse3DEventArgs mouseEvent3D)
|
2017-07-10 15:04:33 -07:00
|
|
|
|
{
|
2018-08-08 14:00:35 -07:00
|
|
|
|
var selectedItem = RootSelection;
|
2017-12-26 21:05:16 -08:00
|
|
|
|
|
2018-08-07 14:03:35 -07:00
|
|
|
|
if (mouseEvent3D.info != null
|
2017-12-26 21:05:16 -08:00
|
|
|
|
&& selectedItem != null)
|
2017-07-10 15:04:33 -07:00
|
|
|
|
{
|
2020-09-11 19:59:14 -07:00
|
|
|
|
hadClickOnControl = true;
|
2017-12-26 21:05:16 -08:00
|
|
|
|
ActiveSelectedItem = selectedItem;
|
2017-07-10 15:04:33 -07:00
|
|
|
|
|
|
|
|
|
|
zHeightDisplayInfo.Visible = true;
|
|
|
|
|
|
|
2022-06-18 20:40:06 -07:00
|
|
|
|
var upNormal = Vector3.UnitZ;
|
|
|
|
|
|
var sideNormal = upNormal.Cross(mouseEvent3D.MouseRay.directionNormal).GetNormal();
|
|
|
|
|
|
var planeNormal = upNormal.Cross(sideNormal).GetNormal();
|
|
|
|
|
|
hitPlane = new PlaneShape(new Plane(planeNormal, mouseEvent3D.info.HitPosition), null);
|
2017-07-10 15:04:33 -07:00
|
|
|
|
|
|
|
|
|
|
initialHitPosition = mouseEvent3D.info.HitPosition;
|
|
|
|
|
|
transformOnMouseDown = selectedItem.Matrix;
|
2019-05-21 07:27:58 -07:00
|
|
|
|
mouseDownSelectedBounds = selectedItem.GetAxisAlignedBoundingBox();
|
2017-07-10 15:04:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
base.OnMouseDown(mouseEvent3D);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-13 15:02:30 -07:00
|
|
|
|
public override void OnMouseMove(Mouse3DEventArgs mouseEvent3D, bool mouseIsOver)
|
2017-07-10 15:04:33 -07:00
|
|
|
|
{
|
2018-08-08 14:00:35 -07:00
|
|
|
|
var selectedItem = RootSelection;
|
2017-12-26 21:05:16 -08:00
|
|
|
|
ActiveSelectedItem = selectedItem;
|
2020-09-11 19:59:14 -07:00
|
|
|
|
if (MouseIsOver)
|
2017-07-10 15:04:33 -07:00
|
|
|
|
{
|
|
|
|
|
|
zHeightDisplayInfo.Visible = true;
|
|
|
|
|
|
}
|
2020-09-11 19:59:14 -07:00
|
|
|
|
else if (!hadClickOnControl)
|
2017-07-10 15:04:33 -07:00
|
|
|
|
{
|
|
|
|
|
|
zHeightDisplayInfo.Visible = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-21 18:07:44 -07:00
|
|
|
|
if (MouseDownOnControl && hitPlane != null)
|
2017-07-10 15:04:33 -07:00
|
|
|
|
{
|
2022-03-02 00:52:04 +00:00
|
|
|
|
IntersectInfo info = hitPlane.GetClosestIntersectionWithinRayDistanceRange(mouseEvent3D.MouseRay);
|
2017-07-10 15:04:33 -07:00
|
|
|
|
|
2018-08-07 14:03:35 -07:00
|
|
|
|
if (info != null
|
2021-03-08 17:41:11 -08:00
|
|
|
|
&& selectedItem != null
|
|
|
|
|
|
&& mouseDownSelectedBounds != null)
|
2017-07-10 15:04:33 -07:00
|
|
|
|
{
|
2017-10-31 12:51:16 -07:00
|
|
|
|
var delta = info.HitPosition.Z - initialHitPosition.Z;
|
2017-07-10 15:04:33 -07:00
|
|
|
|
|
2019-01-11 16:49:34 -08:00
|
|
|
|
double newZPosition = mouseDownSelectedBounds.MinXYZ.Z + delta;
|
2017-07-10 15:04:33 -07:00
|
|
|
|
|
2020-09-12 09:51:43 -07:00
|
|
|
|
if (Object3DControlContext.SnapGridDistance > 0)
|
2017-07-10 15:04:33 -07:00
|
|
|
|
{
|
|
|
|
|
|
// snap this position to the grid
|
2020-09-12 09:51:43 -07:00
|
|
|
|
double snapGridDistance = Object3DControlContext.SnapGridDistance;
|
2017-07-10 15:04:33 -07:00
|
|
|
|
|
|
|
|
|
|
// snap this position to the grid
|
|
|
|
|
|
newZPosition = ((int)((newZPosition / snapGridDistance) + .5)) * snapGridDistance;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-21 07:27:58 -07:00
|
|
|
|
AxisAlignedBoundingBox originalSelectedBounds = selectedItem.GetAxisAlignedBoundingBox();
|
2019-01-11 16:49:34 -08:00
|
|
|
|
var moveAmount = newZPosition - originalSelectedBounds.MinXYZ.Z;
|
2017-07-10 15:04:33 -07:00
|
|
|
|
|
|
|
|
|
|
if (moveAmount != 0)
|
|
|
|
|
|
{
|
2020-09-11 19:59:14 -07:00
|
|
|
|
selectedItem.Matrix *= Matrix4X4.CreateTranslation(0, 0, moveAmount);
|
2017-07-10 15:04:33 -07:00
|
|
|
|
Invalidate();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-13 15:02:30 -07:00
|
|
|
|
base.OnMouseMove(mouseEvent3D, mouseIsOver);
|
2017-07-10 15:04:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-28 11:39:41 -07:00
|
|
|
|
public override void OnMouseUp(Mouse3DEventArgs mouseEvent3D)
|
2017-07-10 15:04:33 -07:00
|
|
|
|
{
|
2020-09-12 09:51:43 -07:00
|
|
|
|
Object3DControlContext.Scene.AddTransformSnapshot(transformOnMouseDown);
|
2017-07-10 15:04:33 -07:00
|
|
|
|
base.OnMouseUp(mouseEvent3D);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-24 15:53:34 -07:00
|
|
|
|
public override void CancelOperation()
|
2018-06-12 10:03:37 -07:00
|
|
|
|
{
|
2018-08-08 14:00:35 -07:00
|
|
|
|
IObject3D selectedItem = RootSelection;
|
2018-06-12 10:03:37 -07:00
|
|
|
|
if (selectedItem != null
|
|
|
|
|
|
&& MouseDownOnControl)
|
|
|
|
|
|
{
|
|
|
|
|
|
selectedItem.Matrix = transformOnMouseDown;
|
|
|
|
|
|
MouseDownOnControl = false;
|
2020-09-11 19:59:14 -07:00
|
|
|
|
MouseIsOver = false;
|
2018-06-12 10:03:37 -07:00
|
|
|
|
|
2020-09-12 09:51:43 -07:00
|
|
|
|
Object3DControlContext.Scene.DrawSelection = true;
|
|
|
|
|
|
Object3DControlContext.Scene.ShowSelectionShadow = true;
|
2018-06-12 10:03:37 -07:00
|
|
|
|
}
|
2021-06-06 09:07:18 -07:00
|
|
|
|
|
|
|
|
|
|
base.CancelOperation();
|
2018-06-12 10:03:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-12 19:44:18 -07:00
|
|
|
|
public override void SetPosition(IObject3D selectedItem, MeshSelectInfo selectInfo)
|
2017-07-10 15:04:33 -07:00
|
|
|
|
{
|
2019-05-21 07:27:58 -07:00
|
|
|
|
AxisAlignedBoundingBox selectedBounds = selectedItem.GetAxisAlignedBoundingBox();
|
2017-07-10 15:04:33 -07:00
|
|
|
|
|
|
|
|
|
|
Vector3 topPosition = GetTopPosition(selectedItem);
|
2020-09-11 19:59:14 -07:00
|
|
|
|
var bottomPosition = new Vector3(topPosition.X, topPosition.Y, selectedBounds.MinXYZ.Z);
|
2020-09-12 09:51:43 -07:00
|
|
|
|
double distBetweenPixelsWorldSpace = Object3DControlContext.World.GetWorldUnitsPerScreenPixelAtPosition(topPosition);
|
2017-07-10 15:04:33 -07:00
|
|
|
|
|
|
|
|
|
|
Vector3 boxCenter = topPosition;
|
2020-09-11 07:55:14 -07:00
|
|
|
|
boxCenter.Z += (10 * GuiWidget.DeviceScale + upArrowSize / 2) * distBetweenPixelsWorldSpace;
|
2017-07-10 15:04:33 -07:00
|
|
|
|
|
2020-09-11 19:59:14 -07:00
|
|
|
|
var centerMatrix = Matrix4X4.CreateTranslation(boxCenter);
|
2020-09-11 07:55:14 -07:00
|
|
|
|
TotalTransform = Matrix4X4.CreateScale(distBetweenPixelsWorldSpace * GuiWidget.DeviceScale) * centerMatrix;
|
2017-07-10 15:04:33 -07:00
|
|
|
|
|
|
|
|
|
|
lines.Clear();
|
|
|
|
|
|
// left lines
|
|
|
|
|
|
// the lines on the bed
|
2017-10-31 12:51:16 -07:00
|
|
|
|
var bedPosition = new Vector3(topPosition.X, topPosition.Y, 0);
|
2020-09-12 09:51:43 -07:00
|
|
|
|
lines.Add(Object3DControlContext.World.GetScreenPosition(bedPosition + new Vector3(distToStart * distBetweenPixelsWorldSpace, 0, 0)));
|
2017-10-31 12:51:16 -07:00
|
|
|
|
lines.Add(new Vector2(lines[0].X + lineLength, lines[0].Y));
|
2017-07-10 15:04:33 -07:00
|
|
|
|
|
2020-09-12 09:51:43 -07:00
|
|
|
|
lines.Add(Object3DControlContext.World.GetScreenPosition(bottomPosition + new Vector3(distToStart * distBetweenPixelsWorldSpace, 0, 0)));
|
2017-10-31 12:51:16 -07:00
|
|
|
|
lines.Add(new Vector2(lines[2].X + lineLength, lines[2].Y));
|
2017-07-10 15:04:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-15 23:00:25 -07:00
|
|
|
|
private void Object3DControl_BeforeDraw(object sender, DrawEventArgs drawEvent)
|
2017-07-10 15:04:33 -07:00
|
|
|
|
{
|
2018-08-08 14:00:35 -07:00
|
|
|
|
var selectedItem = RootSelection;
|
2017-12-26 21:05:16 -08:00
|
|
|
|
|
|
|
|
|
|
if (selectedItem != null
|
2017-12-26 20:35:19 -08:00
|
|
|
|
&& lines.Count > 2)
|
2017-07-10 15:04:33 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (zHeightDisplayInfo.Visible)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 0; i < lines.Count; i += 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
// draw the measure line
|
2019-04-26 18:51:45 -07:00
|
|
|
|
drawEvent.Graphics2D.Line(lines[i], lines[i + 1], theme.TextColor);
|
2017-07-10 15:04:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < lines.Count; i += 4)
|
|
|
|
|
|
{
|
2020-09-11 19:59:14 -07:00
|
|
|
|
drawEvent.Graphics2D.DrawMeasureLine((lines[i] + lines[i + 1]) / 2, (lines[i + 2] + lines[i + 3]) / 2, LineArrows.Both, theme);
|
2017-07-10 15:04:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-21 07:27:58 -07:00
|
|
|
|
AxisAlignedBoundingBox selectedBounds = selectedItem.GetAxisAlignedBoundingBox();
|
2017-07-10 15:04:33 -07:00
|
|
|
|
|
2019-01-11 16:49:34 -08:00
|
|
|
|
zHeightDisplayInfo.Value = selectedBounds.MinXYZ.Z;
|
2020-09-11 19:59:14 -07:00
|
|
|
|
zHeightDisplayInfo.OriginRelativeParent = lines[1] + new Vector2(10, -zHeightDisplayInfo.LocalBounds.Center.Y);
|
2017-07-10 15:04:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-03-02 00:52:04 +00:00
|
|
|
|
|
|
|
|
|
|
public override AxisAlignedBoundingBox GetWorldspaceAABB()
|
|
|
|
|
|
{
|
|
|
|
|
|
AxisAlignedBoundingBox box = AxisAlignedBoundingBox.Empty();
|
|
|
|
|
|
|
|
|
|
|
|
bool shouldDrawScaleControls = ShouldDrawMoveControls();
|
|
|
|
|
|
var selectedItem = RootSelection;
|
|
|
|
|
|
|
|
|
|
|
|
if (selectedItem != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (shouldDrawScaleControls)
|
|
|
|
|
|
{
|
|
|
|
|
|
box = AxisAlignedBoundingBox.Union(box, upArrowMesh.GetAxisAlignedBoundingBox().NewTransformed(TotalTransform));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return box;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-07-10 15:04:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|