diameter control is working cancel scale is working
This commit is contained in:
parent
75dd3834ab
commit
ec41a2b6aa
17 changed files with 524 additions and 33 deletions
|
|
@ -117,6 +117,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
|
||||
public void CancelOperation()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Draw(DrawGlContentEventArgs e)
|
||||
|
|
|
|||
|
|
@ -451,8 +451,6 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
Object3DControlContext.Scene.DrawSelection = true;
|
||||
Object3DControlContext.Scene.ShowSelectionShadow = true;
|
||||
}
|
||||
|
||||
base.CancelOperation();
|
||||
}
|
||||
|
||||
public override void SetPosition(IObject3D selectedItem, MeshSelectInfo selectInfo)
|
||||
|
|
|
|||
|
|
@ -44,6 +44,16 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
|
||||
private IObject3DControlContext context;
|
||||
|
||||
private Func<double> getDiameter;
|
||||
|
||||
private Action<double> setDiameter;
|
||||
|
||||
public ScaleController(Func<double> getDiameter = null, Action<double> setDiameter = null)
|
||||
{
|
||||
this.getDiameter = getDiameter;
|
||||
this.setDiameter = setDiameter;
|
||||
}
|
||||
|
||||
public bool HasChange
|
||||
{
|
||||
get
|
||||
|
|
@ -76,7 +86,21 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
widthDepthItem.Depth = InitialState.Depth;
|
||||
}
|
||||
|
||||
if (selectedItem is IObjectWithHeight heightItem)
|
||||
{
|
||||
heightItem.Height= InitialState.Height;
|
||||
}
|
||||
|
||||
if (setDiameter != null)
|
||||
{
|
||||
setDiameter?.Invoke(InitialState.Diameter);
|
||||
}
|
||||
|
||||
selectedItem.Rebuild();
|
||||
|
||||
selectedItem.Matrix = InitialState.Matrix;
|
||||
|
||||
selectedItem?.Invalidate(new InvalidateArgs(selectedItem, InvalidateType.DisplayValues));
|
||||
}
|
||||
|
||||
public void EditComplete()
|
||||
|
|
@ -101,6 +125,18 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
SetItem(selectedItem, FinalState);
|
||||
}
|
||||
|
||||
public void ScaleDiameter(double newSize)
|
||||
{
|
||||
FinalState = InitialState;
|
||||
FinalState.Diameter = newSize;
|
||||
if (context.GuiSurface.ModifierKeys == Keys.Shift)
|
||||
{
|
||||
ScaleProportional(newSize / InitialState.Diameter);
|
||||
}
|
||||
|
||||
SetItem(selectedItem, FinalState);
|
||||
}
|
||||
|
||||
public void ScaleHeight(double newHeight)
|
||||
{
|
||||
FinalState = InitialState;
|
||||
|
|
@ -140,6 +176,11 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
InitialState.Height = heightItem.Height;
|
||||
}
|
||||
|
||||
if (getDiameter != null)
|
||||
{
|
||||
InitialState.Diameter = getDiameter.Invoke();
|
||||
}
|
||||
|
||||
InitialState.Matrix = selectedItem.Matrix;
|
||||
}
|
||||
|
||||
|
|
@ -184,6 +225,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
FinalState.Width = InitialState.Width * scale;
|
||||
FinalState.Depth = InitialState.Depth * scale;
|
||||
FinalState.Height = InitialState.Height * scale;
|
||||
FinalState.Diameter = InitialState.Diameter * scale;
|
||||
}
|
||||
|
||||
private void SetItem(IObject3D item, ScaleStates states)
|
||||
|
|
@ -199,9 +241,11 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
heightItem.Height = states.Height;
|
||||
}
|
||||
|
||||
setDiameter?.Invoke(states.Diameter);
|
||||
|
||||
item.Matrix = states.Matrix;
|
||||
|
||||
selectedItem.Invalidate(new InvalidateArgs(selectedItem, InvalidateType.DisplayValues));
|
||||
item.Invalidate(new InvalidateArgs(item, InvalidateType.DisplayValues));
|
||||
}
|
||||
|
||||
public struct ScaleStates
|
||||
|
|
@ -212,6 +256,8 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
|
||||
public double Width;
|
||||
|
||||
public double Diameter { get; internal set; }
|
||||
|
||||
public Matrix4X4 Matrix { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,423 @@
|
|||
/*
|
||||
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 MatterHackers.Agg;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.DataConverters3D;
|
||||
using MatterHackers.MatterControl;
|
||||
using MatterHackers.MatterControl.CustomWidgets;
|
||||
using MatterHackers.MatterControl.DesignTools;
|
||||
using MatterHackers.MatterControl.PartPreviewWindow;
|
||||
using MatterHackers.MeshVisualizer;
|
||||
using MatterHackers.PolygonMesh;
|
||||
using MatterHackers.RayTracer;
|
||||
using MatterHackers.RenderOpenGl;
|
||||
using MatterHackers.VectorMath;
|
||||
using System;
|
||||
|
||||
namespace MatterHackers.Plugins.EditorTools
|
||||
{
|
||||
public class ScaleDiameterControl : Object3DControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Edge starting from the back (+y) going ccw
|
||||
/// </summary>
|
||||
private readonly Mesh minXminYMesh;
|
||||
|
||||
private readonly double selectCubeSize = 7 * GuiWidget.DeviceScale;
|
||||
|
||||
private readonly ThemeConfig theme;
|
||||
|
||||
private readonly InlineEditControl diameterValueDisplayInfo;
|
||||
|
||||
private bool hadClickOnControl;
|
||||
|
||||
private PlaneShape hitPlane;
|
||||
|
||||
private Vector3 initialHitPosition;
|
||||
|
||||
private ScaleController scaleController;
|
||||
private Func<double> getDiameter;
|
||||
private Action<double> setDiameter;
|
||||
|
||||
public ScaleDiameterControl(IObject3DControlContext context, Func<double> getDiameter, Action<double> setDiameter)
|
||||
: base(context)
|
||||
{
|
||||
this.getDiameter = getDiameter;
|
||||
this.setDiameter = setDiameter;
|
||||
theme = MatterControl.AppContext.Theme;
|
||||
|
||||
scaleController = new ScaleController(getDiameter, setDiameter);
|
||||
|
||||
diameterValueDisplayInfo = new InlineEditControl()
|
||||
{
|
||||
ForceHide = ForceHideScale,
|
||||
GetDisplayString = (value) => "{0:0.0}".FormatWith(value),
|
||||
};
|
||||
|
||||
diameterValueDisplayInfo.EditComplete += EditComplete;
|
||||
|
||||
diameterValueDisplayInfo.VisibleChanged += (s, e) =>
|
||||
{
|
||||
if (!diameterValueDisplayInfo.Visible)
|
||||
{
|
||||
hadClickOnControl = false;
|
||||
}
|
||||
};
|
||||
|
||||
Object3DControlContext.GuiSurface.AddChild(diameterValueDisplayInfo);
|
||||
|
||||
DrawOnTop = true;
|
||||
|
||||
minXminYMesh = PlatonicSolids.CreateCube(selectCubeSize, selectCubeSize, selectCubeSize);
|
||||
|
||||
CollisionVolume = minXminYMesh.CreateBVHData();
|
||||
|
||||
Object3DControlContext.GuiSurface.BeforeDraw += Object3DControl_BeforeDraw;
|
||||
}
|
||||
|
||||
public IObject3D ActiveSelectedItem { get; set; }
|
||||
|
||||
private double LineLength => 35 * GuiWidget.DeviceScale;
|
||||
|
||||
public override void CancelOperation()
|
||||
{
|
||||
IObject3D selectedItem = RootSelection;
|
||||
if (selectedItem != null
|
||||
&& MouseDownOnControl)
|
||||
{
|
||||
scaleController.Cancel();
|
||||
|
||||
MouseDownOnControl = false;
|
||||
MouseIsOver = false;
|
||||
|
||||
Object3DControlContext.Scene.DrawSelection = true;
|
||||
Object3DControlContext.Scene.ShowSelectionShadow = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
diameterValueDisplayInfo.Close();
|
||||
Object3DControlContext.GuiSurface.BeforeDraw -= Object3DControl_BeforeDraw;
|
||||
}
|
||||
|
||||
public override void Draw(DrawGlContentEventArgs e)
|
||||
{
|
||||
bool shouldDrawScaleControls = true;
|
||||
if (Object3DControlContext.SelectedObject3DControl != null
|
||||
&& Object3DControlContext.SelectedObject3DControl as ScaleDiameterControl == null)
|
||||
{
|
||||
shouldDrawScaleControls = false;
|
||||
}
|
||||
|
||||
var selectedItem = RootSelection;
|
||||
|
||||
if (selectedItem != null)
|
||||
{
|
||||
// Ensures that functions in this scope run against the original instance reference rather than the
|
||||
// current value, thus avoiding null reference errors that would occur otherwise
|
||||
|
||||
if (shouldDrawScaleControls)
|
||||
{
|
||||
// don't draw if any other control is dragging
|
||||
if (MouseIsOver || MouseDownOnControl)
|
||||
{
|
||||
GLHelper.Render(minXminYMesh, theme.PrimaryAccentColor.WithAlpha(e.Alpha0to255), TotalTransform, RenderTypes.Shaded);
|
||||
}
|
||||
else
|
||||
{
|
||||
GLHelper.Render(minXminYMesh, theme.TextColor.Blend(theme.BackgroundColor, .35).WithAlpha(e.Alpha0to255), TotalTransform, RenderTypes.Shaded);
|
||||
}
|
||||
}
|
||||
|
||||
if (hitPlane != null)
|
||||
{
|
||||
//Object3DControlContext.World.RenderPlane(hitPlane.Plane, Color.Red, true, 50, 3);
|
||||
//Object3DControlContext.World.RenderPlane(initialHitPosition, hitPlane.Plane.Normal, Color.Red, true, 50, 3);
|
||||
}
|
||||
}
|
||||
|
||||
if (MouseIsOver || MouseDownOnControl)
|
||||
{
|
||||
DrawMeasureLines(e);
|
||||
}
|
||||
|
||||
base.Draw(e);
|
||||
}
|
||||
|
||||
public override void OnMouseDown(Mouse3DEventArgs mouseEvent3D)
|
||||
{
|
||||
var selectedItem = RootSelection;
|
||||
ActiveSelectedItem = selectedItem;
|
||||
|
||||
if (mouseEvent3D.MouseEvent2D.Button == MouseButtons.Left
|
||||
&& mouseEvent3D.info != null
|
||||
&& selectedItem != null)
|
||||
{
|
||||
hadClickOnControl = true;
|
||||
|
||||
diameterValueDisplayInfo.Visible = true;
|
||||
|
||||
var edge = ObjectSpace.GetEdgePosition(selectedItem, 0);
|
||||
var otherSide = ObjectSpace.GetEdgePosition(selectedItem, 2);
|
||||
|
||||
var upNormal = (edge - otherSide).GetNormal();
|
||||
var sideNormal = upNormal.Cross(mouseEvent3D.MouseRay.directionNormal).GetNormal();
|
||||
var planeNormal = upNormal.Cross(sideNormal).GetNormal();
|
||||
hitPlane = new PlaneShape(new Plane(planeNormal, mouseEvent3D.info.HitPosition), null);
|
||||
|
||||
initialHitPosition = mouseEvent3D.info.HitPosition;
|
||||
|
||||
scaleController.SetInitialState(Object3DControlContext);
|
||||
|
||||
Object3DControlContext.Scene.ShowSelectionShadow = false;
|
||||
}
|
||||
|
||||
base.OnMouseDown(mouseEvent3D);
|
||||
}
|
||||
|
||||
public override async void OnMouseMove(Mouse3DEventArgs mouseEvent3D, bool mouseIsOver)
|
||||
{
|
||||
var selectedItem = RootSelection;
|
||||
ActiveSelectedItem = selectedItem;
|
||||
|
||||
if (MouseIsOver || MouseDownOnControl)
|
||||
{
|
||||
diameterValueDisplayInfo.Visible = true;
|
||||
}
|
||||
else if (!hadClickOnControl || scaleController.HasChange)
|
||||
{
|
||||
diameterValueDisplayInfo.Visible = false;
|
||||
}
|
||||
|
||||
if (MouseDownOnControl && hitPlane != null)
|
||||
{
|
||||
var info = hitPlane.GetClosestIntersection(mouseEvent3D.MouseRay);
|
||||
|
||||
if (info != null
|
||||
&& selectedItem != null)
|
||||
{
|
||||
var delta = info.HitPosition - initialHitPosition;
|
||||
|
||||
var lockedEdge = ObjectSpace.GetEdgePosition(selectedItem, 2);
|
||||
|
||||
var stretchDirection = (ObjectSpace.GetEdgePosition(selectedItem, 0) - lockedEdge).GetNormal();
|
||||
var deltaAlongStretch = stretchDirection.Dot(delta);
|
||||
|
||||
// scale it
|
||||
var newSize = scaleController.InitialState.Diameter;
|
||||
newSize += deltaAlongStretch;
|
||||
newSize = Math.Max(Math.Max(newSize, .001), Object3DControlContext.SnapGridDistance);
|
||||
|
||||
if (Object3DControlContext.SnapGridDistance > 0)
|
||||
{
|
||||
// snap this position to the grid
|
||||
double snapGridDistance = Object3DControlContext.SnapGridDistance;
|
||||
|
||||
// snap this position to the grid
|
||||
newSize = ((int)((newSize / snapGridDistance) + .5)) * snapGridDistance;
|
||||
}
|
||||
|
||||
scaleController.ScaleDiameter(newSize);
|
||||
|
||||
await selectedItem.Rebuild();
|
||||
|
||||
// and keep the locked edge in place
|
||||
Vector3 newLockedEdge = ObjectSpace.GetEdgePosition(selectedItem, 2);
|
||||
|
||||
selectedItem.Matrix *= Matrix4X4.CreateTranslation(lockedEdge - newLockedEdge);
|
||||
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
base.OnMouseMove(mouseEvent3D, mouseIsOver);
|
||||
}
|
||||
|
||||
public override void OnMouseUp(Mouse3DEventArgs mouseEvent3D)
|
||||
{
|
||||
if (hadClickOnControl)
|
||||
{
|
||||
if (getDiameter() != scaleController.InitialState.Diameter)
|
||||
{
|
||||
scaleController.EditComplete();
|
||||
}
|
||||
Object3DControlContext.Scene.ShowSelectionShadow = true;
|
||||
}
|
||||
|
||||
base.OnMouseUp(mouseEvent3D);
|
||||
}
|
||||
|
||||
public override void SetPosition(IObject3D selectedItem, MeshSelectInfo selectInfo)
|
||||
{
|
||||
// create the transform for the box
|
||||
Vector3 edgePosition = ObjectSpace.GetEdgePosition(selectedItem, 0);
|
||||
|
||||
Vector3 boxCenter = edgePosition;
|
||||
|
||||
double distBetweenPixelsWorldSpace = Object3DControlContext.World.GetWorldUnitsPerScreenPixelAtPosition(edgePosition);
|
||||
boxCenter.Y += selectCubeSize / 2 * distBetweenPixelsWorldSpace;
|
||||
boxCenter.Z += selectCubeSize / 2 * distBetweenPixelsWorldSpace;
|
||||
|
||||
var rotation = Matrix4X4.CreateRotation(new Quaternion(selectedItem.Matrix));
|
||||
|
||||
var centerMatrix = Matrix4X4.CreateTranslation(boxCenter);
|
||||
centerMatrix = rotation * Matrix4X4.CreateScale(distBetweenPixelsWorldSpace) * centerMatrix;
|
||||
TotalTransform = centerMatrix;
|
||||
}
|
||||
|
||||
private void DrawMeasureLines(DrawGlContentEventArgs e)
|
||||
{
|
||||
var limitsLines = GetMeasureLine();
|
||||
|
||||
var color = theme.TextColor.WithAlpha(e.Alpha0to255);
|
||||
if (!e.ZBuffered)
|
||||
{
|
||||
theme.TextColor.WithAlpha(Constants.LineAlpha);
|
||||
}
|
||||
|
||||
Frustum clippingFrustum = Object3DControlContext.World.GetClippingFrustum();
|
||||
|
||||
Object3DControlContext.World.Render3DLine(clippingFrustum, limitsLines.start0, limitsLines.end0, color, e.ZBuffered, GuiWidget.DeviceScale);
|
||||
Object3DControlContext.World.Render3DLine(clippingFrustum, limitsLines.start1, limitsLines.end1, color, e.ZBuffered, GuiWidget.DeviceScale);
|
||||
var start = (limitsLines.start0 + limitsLines.end0) / 2;
|
||||
var end = (limitsLines.start1 + limitsLines.end1) / 2;
|
||||
Object3DControlContext.World.Render3DLine(clippingFrustum, start, end, color, e.ZBuffered, GuiWidget.DeviceScale * 1.2, true, true);
|
||||
}
|
||||
|
||||
private void EditComplete(object s, EventArgs e)
|
||||
{
|
||||
scaleController.FinalState.Diameter = diameterValueDisplayInfo.Value != 0 ? diameterValueDisplayInfo.Value : getDiameter();
|
||||
|
||||
throw new NotImplementedException("Need to have the matrix set by the time we edit complete for undo to be right");
|
||||
scaleController.EditComplete();
|
||||
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
private bool ForceHideScale()
|
||||
{
|
||||
var selectedItem = RootSelection;
|
||||
// if the selection changes
|
||||
if (selectedItem != ActiveSelectedItem)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// if another control gets a hover
|
||||
if (Object3DControlContext.HoveredObject3DControl != this
|
||||
&& Object3DControlContext.HoveredObject3DControl != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// if we clicked on the control
|
||||
if (hadClickOnControl)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private Vector3 GetDeltaToOtherSideXy(IObject3D selectedItem, int quadrantIndex)
|
||||
{
|
||||
Vector3 cornerPosition = ObjectSpace.GetCornerPosition(selectedItem, quadrantIndex);
|
||||
Vector3 cornerPositionCcw = ObjectSpace.GetCornerPosition(selectedItem, quadrantIndex + 1);
|
||||
Vector3 cornerPositionCw = ObjectSpace.GetCornerPosition(selectedItem, quadrantIndex + 3);
|
||||
|
||||
double xDirection = cornerPositionCcw.X - cornerPosition.X;
|
||||
if (xDirection == 0)
|
||||
{
|
||||
xDirection = cornerPositionCw.X - cornerPosition.X;
|
||||
}
|
||||
|
||||
double yDirection = cornerPositionCcw.Y - cornerPosition.Y;
|
||||
if (yDirection == 0)
|
||||
{
|
||||
yDirection = cornerPositionCw.Y - cornerPosition.Y;
|
||||
}
|
||||
|
||||
return new Vector3(xDirection, yDirection, cornerPosition.Z);
|
||||
}
|
||||
|
||||
private (Vector3 start0, Vector3 end0, Vector3 start1, Vector3 end1) GetMeasureLine()
|
||||
{
|
||||
var selectedItem = RootSelection;
|
||||
var corner = new Vector3[4];
|
||||
var screen = new Vector3[4];
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
corner[i] = ObjectSpace.GetCornerPosition(selectedItem, i);
|
||||
screen[i] = Object3DControlContext.World.GetScreenSpace(corner[i]);
|
||||
}
|
||||
|
||||
var start = corner[0];
|
||||
var direction = (start - corner[1]).GetNormal();
|
||||
var end = corner[3];
|
||||
// find out which side we should render on (the one closer to the screen)
|
||||
if (screen[0].Z > screen[1].Z)
|
||||
{
|
||||
start = corner[1];
|
||||
end = corner[2];
|
||||
direction = (start - corner[0]).GetNormal();
|
||||
}
|
||||
|
||||
var startScale = Object3DControlContext.World.GetWorldUnitsPerScreenPixelAtPosition(start);
|
||||
var endScale = Object3DControlContext.World.GetWorldUnitsPerScreenPixelAtPosition(end);
|
||||
var offset = .3;
|
||||
var start0 = start + direction * LineLength * offset * startScale;
|
||||
var end0 = start + direction * LineLength * (1 + offset) * endScale;
|
||||
var start1 = end + direction * LineLength * offset * endScale;
|
||||
var end1 = end + direction * LineLength * (1 + offset) * endScale;
|
||||
return (start0, end0, start1, end1);
|
||||
}
|
||||
|
||||
private void Object3DControl_BeforeDraw(object sender, DrawEventArgs drawEvent)
|
||||
{
|
||||
var selectedItem = RootSelection;
|
||||
|
||||
if (selectedItem != null)
|
||||
{
|
||||
if (MouseIsOver || MouseDownOnControl)
|
||||
{
|
||||
var limitsLines = GetMeasureLine();
|
||||
var start = (limitsLines.start0 + limitsLines.end0) / 2;
|
||||
var end = (limitsLines.start1 + limitsLines.end1) / 2;
|
||||
var screenStart = Object3DControlContext.World.GetScreenPosition(start);
|
||||
var screenEnd = Object3DControlContext.World.GetScreenPosition(end);
|
||||
|
||||
diameterValueDisplayInfo.Value = (start - end).Length;
|
||||
diameterValueDisplayInfo.OriginRelativeParent = (screenStart + screenEnd) / 2 - diameterValueDisplayInfo.LocalBounds.Center;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -65,13 +65,19 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
|
||||
private Vector3 originalPointToMove;
|
||||
|
||||
private ScaleController scaleController = new ScaleController();
|
||||
private ScaleController scaleController;
|
||||
private Func<double> getDiameter;
|
||||
private readonly Action<double> setDiameter;
|
||||
|
||||
public ScaleHeightControl(IObject3DControlContext context)
|
||||
public ScaleHeightControl(IObject3DControlContext context, Func<double> getDiameter = null, Action<double> setDiameter = null)
|
||||
: base(context)
|
||||
{
|
||||
this.getDiameter = getDiameter;
|
||||
this.setDiameter = setDiameter;
|
||||
theme = MatterControl.AppContext.Theme;
|
||||
|
||||
scaleController = new ScaleController(getDiameter, setDiameter);
|
||||
|
||||
heightValueDisplayInfo = new InlineEditControl()
|
||||
{
|
||||
ForceHide = () =>
|
||||
|
|
@ -153,8 +159,6 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
Object3DControlContext.Scene.DrawSelection = true;
|
||||
Object3DControlContext.Scene.ShowSelectionShadow = true;
|
||||
}
|
||||
|
||||
base.CancelOperation();
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
|
|
|
|||
|
|
@ -393,8 +393,6 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
Object3DControlContext.Scene.DrawSelection = true;
|
||||
Object3DControlContext.Scene.ShowSelectionShadow = true;
|
||||
}
|
||||
|
||||
base.CancelOperation();
|
||||
}
|
||||
|
||||
public override void SetPosition(IObject3D selectedItem, MeshSelectInfo selectInfo)
|
||||
|
|
|
|||
|
|
@ -365,8 +365,6 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
Object3DControlContext.Scene.DrawSelection = true;
|
||||
Object3DControlContext.Scene.ShowSelectionShadow = true;
|
||||
}
|
||||
|
||||
base.CancelOperation();
|
||||
}
|
||||
|
||||
public override void SetPosition(IObject3D selectedItem, MeshSelectInfo selectInfo)
|
||||
|
|
|
|||
|
|
@ -313,8 +313,6 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
Object3DControlContext.Scene.DrawSelection = true;
|
||||
Object3DControlContext.Scene.ShowSelectionShadow = true;
|
||||
}
|
||||
|
||||
base.CancelOperation();
|
||||
}
|
||||
|
||||
public override void SetPosition(IObject3D selectedItem, MeshSelectInfo selectInfo)
|
||||
|
|
|
|||
|
|
@ -137,8 +137,6 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
Object3DControlContext.Scene.DrawSelection = true;
|
||||
Object3DControlContext.Scene.ShowSelectionShadow = true;
|
||||
}
|
||||
|
||||
base.CancelOperation();
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
|
|
|
|||
|
|
@ -143,8 +143,6 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
Object3DControlContext.Scene.DrawSelection = true;
|
||||
Object3DControlContext.Scene.ShowSelectionShadow = true;
|
||||
}
|
||||
|
||||
base.CancelOperation();
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
|
|
|
|||
|
|
@ -45,13 +45,17 @@ using Newtonsoft.Json;
|
|||
|
||||
namespace MatterHackers.MatterControl.DesignTools.Operations
|
||||
{
|
||||
public class LinearExtrudeObject3D : Object3D, IPropertyGridModifier
|
||||
public class LinearExtrudeObject3D : Object3D
|
||||
#if DEBUG
|
||||
, IPropertyGridModifier
|
||||
#endif
|
||||
{
|
||||
public double Height { get; set; } = 5;
|
||||
|
||||
#if DEBUG
|
||||
[Description("Bevel the top of the extrusion")]
|
||||
public bool BevelTop { get; set; } = false;
|
||||
|
||||
|
||||
[Description("The amount to inset the bevel")]
|
||||
public double BevelInset { get; set; } = 2;
|
||||
|
||||
|
|
@ -61,6 +65,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
public double BevelStart { get; set; } = 4;
|
||||
|
||||
public int BevelSteps { get; set; } = 1;
|
||||
#endif
|
||||
|
||||
public override bool CanFlatten => true;
|
||||
|
||||
|
|
@ -136,6 +141,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
|
||||
bool valuesChanged = false;
|
||||
|
||||
#if DEBUG
|
||||
if (BevelTop)
|
||||
{
|
||||
BevelSteps = agg_basics.Clamp(BevelSteps, 1, 32, ref valuesChanged);
|
||||
|
|
@ -143,6 +149,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
var aabb = this.GetAxisAlignedBoundingBox();
|
||||
BevelInset = agg_basics.Clamp(BevelInset, 0, Math.Min(aabb.XSize /2, aabb.YSize / 2), ref valuesChanged);
|
||||
}
|
||||
#endif
|
||||
|
||||
var rebuildLock = RebuildLock();
|
||||
// now create a long running task to process the image
|
||||
|
|
@ -153,6 +160,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
{
|
||||
var vertexSource = this.VertexSource;
|
||||
List<(double height, double inset)> bevel = null;
|
||||
#if DEBUG
|
||||
if (BevelTop)
|
||||
{
|
||||
bevel = new List<(double height, double inset)>();
|
||||
|
|
@ -165,6 +173,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
bevel.Add((height, inset));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Mesh = VertexSourceToMesh.Extrude(this.VertexSource, Height, bevel);
|
||||
if (Mesh.Vertices.Count == 0)
|
||||
|
|
@ -184,11 +193,13 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
});
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
public void UpdateControls(PublicPropertyChange change)
|
||||
{
|
||||
change.SetRowVisible(nameof(BevelStart), () => BevelTop);
|
||||
change.SetRowVisible(nameof(BevelInset), () => BevelTop);
|
||||
change.SetRowVisible(nameof(BevelSteps), () => BevelTop);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
@ -36,11 +36,13 @@ using MatterHackers.Agg.VertexSource;
|
|||
using MatterHackers.DataConverters3D;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.DesignTools.Operations;
|
||||
using MatterHackers.MatterControl.PartPreviewWindow;
|
||||
using MatterHackers.Plugins.EditorTools;
|
||||
using MatterHackers.VectorMath;
|
||||
|
||||
namespace MatterHackers.MatterControl.DesignTools
|
||||
{
|
||||
public class CylinderObject3D : PrimitiveObject3D, IPropertyGridModifier, IObjectWithHeight
|
||||
public class CylinderObject3D : PrimitiveObject3D, IPropertyGridModifier, IObjectWithHeight, IObject3DControlsProvider
|
||||
{
|
||||
public CylinderObject3D()
|
||||
{
|
||||
|
|
@ -213,5 +215,17 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
endingAngleWidget.Visible = Advanced;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddObject3DControls(Object3DControlsLayer object3DControlsLayer)
|
||||
{
|
||||
object3DControlsLayer.Object3DControls.Add(new ScaleDiameterControl(object3DControlsLayer,
|
||||
() => Diameter,
|
||||
(diameter) => Diameter = diameter));
|
||||
object3DControlsLayer.Object3DControls.Add(new ScaleHeightControl(object3DControlsLayer,
|
||||
() => Diameter,
|
||||
(diameter) => Diameter = diameter));
|
||||
object3DControlsLayer.AddControls(ControlTypes.MoveInZ);
|
||||
object3DControlsLayer.AddControls(ControlTypes.RotateXYZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -283,8 +283,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
Object3DControlContext.Scene.DrawSelection = true;
|
||||
Object3DControlContext.Scene.ShowSelectionShadow = true;
|
||||
}
|
||||
|
||||
base.CancelOperation();
|
||||
}
|
||||
|
||||
public override void SetPosition(IObject3D selectedItem, MeshSelectInfo selectInfo)
|
||||
|
|
|
|||
|
|
@ -89,5 +89,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
{
|
||||
// no widgets allocated so nothing to close
|
||||
}
|
||||
|
||||
public override void CancelOperation()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -138,5 +138,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void CancelOperation()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -110,9 +110,7 @@ namespace MatterHackers.MeshVisualizer
|
|||
Object3DControlContext.GuiSurface.Invalidate();
|
||||
}
|
||||
|
||||
public virtual void CancelOperation()
|
||||
{
|
||||
}
|
||||
public abstract void CancelOperation();
|
||||
|
||||
public virtual void OnMouseDown(Mouse3DEventArgs mouseEvent3D)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -52,14 +52,14 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
[Flags]
|
||||
public enum ControlTypes
|
||||
{
|
||||
MoveInZ = 1,
|
||||
RotateXYZ = 2,
|
||||
RotateZ = 4,
|
||||
ScaleWidthDepth = 8,
|
||||
ScaleMatrixXY = 16,
|
||||
Shadow = 32,
|
||||
SnappingIndicators = 64,
|
||||
ScaleHeight = 128,
|
||||
MoveInZ = 1 << 0,
|
||||
RotateXYZ = 1 << 1,
|
||||
RotateZ = 1 << 2,
|
||||
ScaleWidthDepth = 1 << 3,
|
||||
ScaleMatrixXY = 1 << 4,
|
||||
Shadow = 1 << 5,
|
||||
SnappingIndicators = 1 << 6,
|
||||
ScaleHeight = 1 << 7,
|
||||
|
||||
Standard2D = MoveInZ | Shadow | SnappingIndicators | RotateZ | ScaleMatrixXY
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue