improving path editor
This commit is contained in:
parent
bb8d8b3859
commit
512ac181b3
3 changed files with 107 additions and 8 deletions
|
|
@ -37,6 +37,7 @@ using MatterHackers.Localizations;
|
||||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||||
using MatterHackers.VectorMath;
|
using MatterHackers.VectorMath;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace MatterHackers.MatterControl.DesignTools
|
namespace MatterHackers.MatterControl.DesignTools
|
||||||
{
|
{
|
||||||
|
|
@ -49,6 +50,13 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
Scale
|
Scale
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public enum ControlPointConstraint
|
||||||
|
{
|
||||||
|
Sharp,
|
||||||
|
Aligned,
|
||||||
|
Free
|
||||||
|
}
|
||||||
|
|
||||||
private Vector2 lastMousePosition = new Vector2(0, 0);
|
private Vector2 lastMousePosition = new Vector2(0, 0);
|
||||||
private ETransformState mouseDownTransformOverride;
|
private ETransformState mouseDownTransformOverride;
|
||||||
private Vector2 mouseDownPosition = new Vector2(0, 0);
|
private Vector2 mouseDownPosition = new Vector2(0, 0);
|
||||||
|
|
@ -60,6 +68,8 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
|
|
||||||
private VertexStorage vertexStorage;
|
private VertexStorage vertexStorage;
|
||||||
|
|
||||||
|
private ControlPointConstraint controlPointConstraint = ControlPointConstraint.Free;
|
||||||
|
|
||||||
public PathEditorWidget(VertexStorage vertexStorage,
|
public PathEditorWidget(VertexStorage vertexStorage,
|
||||||
UndoBuffer undoBuffer,
|
UndoBuffer undoBuffer,
|
||||||
ThemeConfig theme,
|
ThemeConfig theme,
|
||||||
|
|
@ -94,14 +104,19 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
{
|
{
|
||||||
HAnchor = HAnchor.Stretch,
|
HAnchor = HAnchor.Stretch,
|
||||||
Margin = 5,
|
Margin = 5,
|
||||||
BackgroundColor= theme.TextColor.WithAlpha(20),
|
BackgroundColor = theme.TextColor.WithAlpha(20),
|
||||||
};
|
};
|
||||||
|
|
||||||
toolBar.VAnchor |= VAnchor.Bottom;
|
toolBar.VAnchor |= VAnchor.Bottom;
|
||||||
|
|
||||||
this.AddChild(toolBar);
|
this.AddChild(toolBar);
|
||||||
|
|
||||||
AddHomeButton(theme, toolBar);
|
AddControlsToToolBar(theme, toolBar);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddControlsToToolBar(ThemeConfig theme, FlowLayoutWidget toolBar)
|
||||||
|
{
|
||||||
|
AddButtons(theme, toolBar);
|
||||||
|
|
||||||
toolBar.AddChild(new HorizontalSpacer());
|
toolBar.AddChild(new HorizontalSpacer());
|
||||||
|
|
||||||
|
|
@ -113,13 +128,14 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
private void AddPositionControls(ThemeConfig theme, FlowLayoutWidget toolBar)
|
private void AddPositionControls(ThemeConfig theme, FlowLayoutWidget toolBar)
|
||||||
{
|
{
|
||||||
var tabIndex = 0;
|
var tabIndex = 0;
|
||||||
var xEditWidget = new ThemedNumberEdit(0, theme, singleCharLabel: 'X', allowNegatives: true, allowDecimals: true, pixelWidth: VectorXYEditWidth, tabIndex: tabIndex)
|
xEditWidget = new ThemedNumberEdit(0, theme, singleCharLabel: 'X', allowNegatives: true, allowDecimals: true, pixelWidth: VectorXYEditWidth, tabIndex: tabIndex)
|
||||||
{
|
{
|
||||||
TabIndex = tabIndex++,
|
TabIndex = tabIndex++,
|
||||||
SelectAllOnFocus = true,
|
SelectAllOnFocus = true,
|
||||||
Margin = theme.ButtonSpacing,
|
Margin = theme.ButtonSpacing,
|
||||||
VAnchor = VAnchor.Center,
|
VAnchor = VAnchor.Center,
|
||||||
};
|
};
|
||||||
|
xEditWidget.ActuallNumberEdit.InternalNumberEdit.MaxDecimalsPlaces = 3;
|
||||||
xEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
|
xEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
|
||||||
{
|
{
|
||||||
if (controlPointBeingDragged > -1)
|
if (controlPointBeingDragged > -1)
|
||||||
|
|
@ -137,7 +153,6 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -145,13 +160,14 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
xEditWidget.ActuallNumberEdit.KeyDown += NumberField.InternalTextEditWidget_KeyDown;
|
xEditWidget.ActuallNumberEdit.KeyDown += NumberField.InternalTextEditWidget_KeyDown;
|
||||||
toolBar.AddChild(xEditWidget);
|
toolBar.AddChild(xEditWidget);
|
||||||
|
|
||||||
var yEditWidget = new ThemedNumberEdit(0, theme, 'Y', allowNegatives: true, allowDecimals: true, pixelWidth: VectorXYEditWidth, tabIndex: tabIndex)
|
yEditWidget = new ThemedNumberEdit(0, theme, 'Y', allowNegatives: true, allowDecimals: true, pixelWidth: VectorXYEditWidth, tabIndex: tabIndex)
|
||||||
{
|
{
|
||||||
TabIndex = tabIndex++,
|
TabIndex = tabIndex++,
|
||||||
SelectAllOnFocus = true,
|
SelectAllOnFocus = true,
|
||||||
VAnchor = VAnchor.Center,
|
VAnchor = VAnchor.Center,
|
||||||
Margin = theme.ButtonSpacing,
|
Margin = theme.ButtonSpacing,
|
||||||
};
|
};
|
||||||
|
yEditWidget.ActuallNumberEdit.InternalNumberEdit.MaxDecimalsPlaces = 3;
|
||||||
yEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
|
yEditWidget.ActuallNumberEdit.EditComplete += (sender, e) =>
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
@ -160,7 +176,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
toolBar.AddChild(yEditWidget);
|
toolBar.AddChild(yEditWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddHomeButton(ThemeConfig theme, FlowLayoutWidget toolBar)
|
private void AddButtons(ThemeConfig theme, FlowLayoutWidget toolBar)
|
||||||
{
|
{
|
||||||
var homeButton = new ThemedIconButton(StaticData.Instance.LoadIcon("fa-home_16.png", 16, 16).GrayToColor(theme.TextColor), theme)
|
var homeButton = new ThemedIconButton(StaticData.Instance.LoadIcon("fa-home_16.png", 16, 16).GrayToColor(theme.TextColor), theme)
|
||||||
{
|
{
|
||||||
|
|
@ -175,6 +191,45 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
{
|
{
|
||||||
CenterPartInView();
|
CenterPartInView();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// the sharp corner button
|
||||||
|
var sharpButton = new ThemedRadioTextButton("S", theme)
|
||||||
|
{
|
||||||
|
BackgroundColor = theme.SlightShade,
|
||||||
|
HoverColor = theme.SlightShade.WithAlpha(75),
|
||||||
|
Margin = new BorderDouble(3, 3, 6, 3),
|
||||||
|
ToolTipText = "Sharp Corner".Localize(),
|
||||||
|
Checked = controlPointConstraint == ControlPointConstraint.Sharp,
|
||||||
|
};
|
||||||
|
toolBar.AddChild(sharpButton);
|
||||||
|
|
||||||
|
sharpButton.Click += (s, e) => { controlPointConstraint = ControlPointConstraint.Sharp; };
|
||||||
|
|
||||||
|
// the aligned corner button
|
||||||
|
var alignedButton = new ThemedRadioTextButton("A", theme)
|
||||||
|
{
|
||||||
|
BackgroundColor = theme.SlightShade,
|
||||||
|
HoverColor = theme.SlightShade.WithAlpha(75),
|
||||||
|
Margin = new BorderDouble(3, 3, 6, 3),
|
||||||
|
ToolTipText = "Aligned Corner".Localize(),
|
||||||
|
Checked = controlPointConstraint == ControlPointConstraint.Aligned,
|
||||||
|
};
|
||||||
|
toolBar.AddChild(alignedButton);
|
||||||
|
|
||||||
|
alignedButton.Click += (s, e) => { controlPointConstraint = ControlPointConstraint.Aligned; };
|
||||||
|
|
||||||
|
// the free button
|
||||||
|
var freeButton = new ThemedRadioTextButton("F", theme)
|
||||||
|
{
|
||||||
|
BackgroundColor = theme.SlightShade,
|
||||||
|
HoverColor = theme.SlightShade.WithAlpha(75),
|
||||||
|
Margin = new BorderDouble(3, 3, 6, 3),
|
||||||
|
ToolTipText = "Free".Localize(),
|
||||||
|
Checked = controlPointConstraint == ControlPointConstraint.Free,
|
||||||
|
};
|
||||||
|
toolBar.AddChild(freeButton);
|
||||||
|
|
||||||
|
freeButton.Click += (s, e) => { controlPointConstraint = ControlPointConstraint.Free; };
|
||||||
}
|
}
|
||||||
|
|
||||||
public ETransformState TransformState { get; set; }
|
public ETransformState TransformState { get; set; }
|
||||||
|
|
@ -184,7 +239,10 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
private Affine TotalTransform => Affine.NewTranslation(unscaledRenderOffset) * ScalingTransform * Affine.NewTranslation(Width / 2, Height / 2);
|
private Affine TotalTransform => Affine.NewTranslation(unscaledRenderOffset) * ScalingTransform * Affine.NewTranslation(Width / 2, Height / 2);
|
||||||
|
|
||||||
private int controlPointBeingDragged = -1;
|
private int controlPointBeingDragged = -1;
|
||||||
|
private int selectedPointIndex;
|
||||||
private int controlPointBeingHovered = -1;
|
private int controlPointBeingHovered = -1;
|
||||||
|
private ThemedNumberEdit yEditWidget;
|
||||||
|
private ThemedNumberEdit xEditWidget;
|
||||||
|
|
||||||
public void CenterPartInView()
|
public void CenterPartInView()
|
||||||
{
|
{
|
||||||
|
|
@ -204,6 +262,16 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
{
|
{
|
||||||
new VertexSourceApplyTransform(vertexStorage, TotalTransform).RenderCurve(graphics2D, theme.TextColor, 2, true, theme.PrimaryAccentColor.Blend(theme.TextColor, .5), theme.PrimaryAccentColor);
|
new VertexSourceApplyTransform(vertexStorage, TotalTransform).RenderCurve(graphics2D, theme.TextColor, 2, true, theme.PrimaryAccentColor.Blend(theme.TextColor, .5), theme.PrimaryAccentColor);
|
||||||
|
|
||||||
|
//if (vertexStorage.GetType().GetCustomAttributes(typeof(PathEditorFactory.ShowAxisAttribute), true).FirstOrDefault() is PathEditorFactory.ShowAxisAttribute showAxisAttribute)
|
||||||
|
{
|
||||||
|
var leftOrigin = new Vector2(-10000, 0);
|
||||||
|
var rightOrigin = new Vector2(10000, 0);
|
||||||
|
graphics2D.Line(TotalTransform.Transform(leftOrigin), TotalTransform.Transform(rightOrigin), Color.Red);
|
||||||
|
var bottomOrigin = new Vector2(0, -10000);
|
||||||
|
var topOrigin = new Vector2(0, 10000);
|
||||||
|
graphics2D.Line(TotalTransform.Transform(bottomOrigin), TotalTransform.Transform(topOrigin), Color.Green);
|
||||||
|
}
|
||||||
|
|
||||||
base.OnDraw(graphics2D);
|
base.OnDraw(graphics2D);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -240,6 +308,21 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
{
|
{
|
||||||
// we are in edit mode, check if we are over any control points
|
// we are in edit mode, check if we are over any control points
|
||||||
controlPointBeingDragged = GetControlPointIndex(mouseEvent.Position);
|
controlPointBeingDragged = GetControlPointIndex(mouseEvent.Position);
|
||||||
|
selectedPointIndex = controlPointBeingDragged;
|
||||||
|
|
||||||
|
if (selectedPointIndex == -1)
|
||||||
|
{
|
||||||
|
xEditWidget.Text = "---";
|
||||||
|
xEditWidget.Enabled= false;
|
||||||
|
yEditWidget.Text = "---";
|
||||||
|
yEditWidget.Enabled= false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
xEditWidget.Enabled = true;
|
||||||
|
yEditWidget.Enabled = true;
|
||||||
|
UpdatePositionControls();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -254,6 +337,12 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdatePositionControls()
|
||||||
|
{
|
||||||
|
xEditWidget.Value = vertexStorage[controlPointBeingDragged].Position.X;
|
||||||
|
yEditWidget.Value = vertexStorage[controlPointBeingDragged].Position.Y;
|
||||||
|
}
|
||||||
|
|
||||||
private int GetControlPointIndex(Vector2 mousePosition)
|
private int GetControlPointIndex(Vector2 mousePosition)
|
||||||
{
|
{
|
||||||
double hitThreshold = 10; // Threshold for considering a hit, in screen pixels
|
double hitThreshold = 10; // Threshold for considering a hit, in screen pixels
|
||||||
|
|
@ -291,6 +380,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
ScalingTransform.inverse_transform(ref mouseDelta);
|
ScalingTransform.inverse_transform(ref mouseDelta);
|
||||||
OffsetSelectedPoint(mouseDelta);
|
OffsetSelectedPoint(mouseDelta);
|
||||||
vertexChanged?.Invoke();
|
vertexChanged?.Invoke();
|
||||||
|
UpdatePositionControls();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -306,7 +396,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
{
|
{
|
||||||
if (controlPointBeingDragged < 0
|
if (controlPointBeingDragged < 0
|
||||||
|| controlPointBeingDragged >= vertexStorage.Count)
|
|| controlPointBeingDragged >= vertexStorage.Count)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -313,6 +313,9 @@ Translated:Alert
|
||||||
English:Align
|
English:Align
|
||||||
Translated:Align
|
Translated:Align
|
||||||
|
|
||||||
|
English:Aligned Corner
|
||||||
|
Translated:Aligned Corner
|
||||||
|
|
||||||
English:Aligning Z Axis
|
English:Aligning Z Axis
|
||||||
Translated:Aligning Z Axis
|
Translated:Aligning Z Axis
|
||||||
|
|
||||||
|
|
@ -2068,6 +2071,9 @@ Translated:Forums
|
||||||
English:Found a line that is {0} characters long.\n{1}...
|
English:Found a line that is {0} characters long.\n{1}...
|
||||||
Translated:Found a line that is {0} characters long.\n{1}...
|
Translated:Found a line that is {0} characters long.\n{1}...
|
||||||
|
|
||||||
|
English:Free
|
||||||
|
Translated:Free
|
||||||
|
|
||||||
English:Furthest Back
|
English:Furthest Back
|
||||||
Translated:Furthest Back
|
Translated:Furthest Back
|
||||||
|
|
||||||
|
|
@ -4861,6 +4867,9 @@ Translated:Share with someone
|
||||||
English:Shared with Me
|
English:Shared with Me
|
||||||
Translated:Shared with Me
|
Translated:Shared with Me
|
||||||
|
|
||||||
|
English:Sharp Corner
|
||||||
|
Translated:Sharp Corner
|
||||||
|
|
||||||
English:Shift + G
|
English:Shift + G
|
||||||
Translated:Shift + G
|
Translated:Shift + G
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 3c76fcb1852d66078ab527e5871dd8c62865680b
|
Subproject commit b2125420fc190b876dabccb44c0107832bd156fd
|
||||||
Loading…
Add table
Add a link
Reference in a new issue