Merge pull request #3397 from jlewin/design_tools

Remove unused original editors
This commit is contained in:
Lars Brubaker 2018-06-09 10:20:09 -07:00 committed by GitHub
commit bac2100e60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 179 additions and 195 deletions

View file

@ -124,9 +124,16 @@ namespace MatterHackers.MatterControl.DesignTools
return mainContainer;
}
private static FlowLayoutWidget CreateSettingsRow(EditableProperty property)
private static FlowLayoutWidget CreateSettingsRow(EditableProperty property, GuiWidget widget = null)
{
return CreateSettingsRow(property.DisplayName.Localize(), property.Description.Localize());
var row = CreateSettingsRow(property.DisplayName.Localize(), property.Description.Localize());
if (widget != null)
{
row.AddChild(widget);
}
return row;
}
private static FlowLayoutWidget CreateSettingsRow(string labelText, string toolTipText = null)
@ -227,8 +234,6 @@ namespace MatterHackers.MatterControl.DesignTools
// create a double editor
if (property.Value is double doubleValue)
{
rowContainer = CreateSettingsRow(property);
var field = new DoubleField();
field.Initialize(0);
field.DoubleValue = doubleValue;
@ -239,13 +244,10 @@ namespace MatterHackers.MatterControl.DesignTools
propertyGridModifier?.UpdateControls(context);
};
rowContainer.AddChild(field.Content);
editControlsContainer.AddChild(rowContainer);
rowContainer = CreateSettingsRow(property, field.Content);
}
else if (property.Value is Vector2 vector2)
{
rowContainer = CreateSettingsRow(property);
var field = new Vector2Field();
field.Initialize(0);
field.Vector2 = vector2;
@ -256,13 +258,10 @@ namespace MatterHackers.MatterControl.DesignTools
propertyGridModifier?.UpdateControls(context);
};
rowContainer.AddChild(field.Content);
editControlsContainer.AddChild(rowContainer);
rowContainer = CreateSettingsRow(property, field.Content);
}
else if (property.Value is Vector3 vector3)
{
rowContainer = CreateSettingsRow(property);
var field = new Vector3Field();
field.Initialize(0);
field.Vector3 = vector3;
@ -273,170 +272,86 @@ namespace MatterHackers.MatterControl.DesignTools
propertyGridModifier?.UpdateControls(context);
};
rowContainer.AddChild(field.Content);
editControlsContainer.AddChild(rowContainer);
rowContainer = CreateSettingsRow(property, field.Content);
}
else if (property.Value is DirectionVector directionVector)
{
bool simpleEdit = true;
if (simpleEdit)
var dropDownList = new DropDownList("Name".Localize(), theme.Colors.PrimaryTextColor, Direction.Down, pointSize: theme.DefaultFontSize)
{
rowContainer = CreateSettingsRow(property);
BorderColor = theme.GetBorderColor(75)
};
var dropDownList = new DropDownList("Name".Localize(), theme.Colors.PrimaryTextColor, Direction.Down, pointSize: theme.DefaultFontSize)
foreach (var orderItem in new string[] { "Right", "Back", "Up" })
{
MenuItem newItem = dropDownList.AddItem(orderItem);
var localOredrItem = orderItem;
newItem.Selected += (sender, e) =>
{
BorderColor = theme.GetBorderColor(75)
};
var orderedItems = new string[] { "Right", "Back", "Up" };
foreach (var orderItem in orderedItems)
{
MenuItem newItem = dropDownList.AddItem(orderItem);
var localOredrItem = orderItem;
newItem.Selected += (sender, e) =>
switch (dropDownList.SelectedValue)
{
switch (dropDownList.SelectedValue)
{
case "Right":
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { new DirectionVector() { Normal = Vector3.UnitX } });
break;
case "Back":
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { new DirectionVector() { Normal = Vector3.UnitY } });
break;
case "Up":
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { new DirectionVector() { Normal = Vector3.UnitZ } });
break;
}
case "Right":
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { new DirectionVector() { Normal = Vector3.UnitX } });
break;
case "Back":
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { new DirectionVector() { Normal = Vector3.UnitY } });
break;
case "Up":
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { new DirectionVector() { Normal = Vector3.UnitZ } });
break;
}
rebuildable?.Rebuild(undoBuffer);
propertyGridModifier?.UpdateControls(context);
};
}
dropDownList.SelectedLabel = "Right";
rowContainer.AddChild(dropDownList);
editControlsContainer.AddChild(rowContainer);
}
else // edit the vector
{
rowContainer = CreateSettingsRow(property);
var field = new Vector3Field();
field.Initialize(0);
field.Vector3 = directionVector.Normal;
field.ValueChanged += (s, e) =>
{
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { new DirectionVector() { Normal = field.Vector3 } });
rebuildable?.Rebuild(undoBuffer);
propertyGridModifier?.UpdateControls(context);
};
rowContainer.AddChild(field.Content);
editControlsContainer.AddChild(rowContainer);
}
dropDownList.SelectedLabel = "Right";
rowContainer = CreateSettingsRow(property, dropDownList);
}
else if (property.Value is DirectionAxis directionAxis)
{
bool simpleAxis = true;
if (simpleAxis)
// the direction axis
// the distance from the center of the part
// create a double editor
var field = new DoubleField();
field.Initialize(0);
field.DoubleValue = directionAxis.Origin.X - property.Item.Children.First().GetAxisAlignedBoundingBox().Center.X;
field.ValueChanged += (s, e) =>
{
// the direction axis
// the distance from the center of the part
// create a double editor
rowContainer = CreateSettingsRow(property);
var field = new DoubleField();
field.Initialize(0);
field.DoubleValue = directionAxis.Origin.X - property.Item.Children.First().GetAxisAlignedBoundingBox().Center.X;
field.ValueChanged += (s, e) =>
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[]
{
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[]
{
new DirectionAxis()
{
Normal = Vector3.UnitZ, Origin = property.Item.Children.First().GetAxisAlignedBoundingBox().Center + new Vector3(field.DoubleValue, 0, 0)
}
});
rebuildable?.Rebuild(undoBuffer);
propertyGridModifier?.UpdateControls(context);
};
new DirectionAxis()
{
Normal = Vector3.UnitZ, Origin = property.Item.Children.First().GetAxisAlignedBoundingBox().Center + new Vector3(field.DoubleValue, 0, 0)
}
});
rebuildable?.Rebuild(undoBuffer);
propertyGridModifier?.UpdateControls(context);
};
rowContainer.AddChild(field.Content);
editControlsContainer.AddChild(rowContainer);
// update tihs when changed
EventHandler< InvalidateArgs> updateData = (s, e) =>
{
field.DoubleValue = ((DirectionAxis)property.PropertyInfo.GetGetMethod().Invoke(property.Item, null)).Origin.X - property.Item.Children.First().GetAxisAlignedBoundingBox().Center.X;
};
property.Item.Invalidated += updateData;
editControlsContainer.Closed += (s, e) =>
{
property.Item.Invalidated -= updateData;
};
}
else
// update tihs when changed
EventHandler<InvalidateArgs> updateData = (s, e) =>
{
// add in the position
FlowLayoutWidget originRowContainer = CreateSettingsRow(property);
field.DoubleValue = ((DirectionAxis)property.PropertyInfo.GetGetMethod().Invoke(property.Item, null)).Origin.X - property.Item.Children.First().GetAxisAlignedBoundingBox().Center.X;
};
property.Item.Invalidated += updateData;
editControlsContainer.Closed += (s, e) =>
{
property.Item.Invalidated -= updateData;
};
var originField = new Vector3Field();
originField.Initialize(0);
originField.Vector3 = directionAxis.Origin;
var normalField = new Vector3Field();
normalField.Initialize(0);
normalField.Vector3 = directionAxis.Normal;
originField.ValueChanged += (s, e) =>
{
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { new DirectionAxis() { Origin = originField.Vector3, Normal = normalField.Vector3 } });
rebuildable?.Rebuild(undoBuffer);
propertyGridModifier?.UpdateControls(context);
};
originRowContainer.AddChild(originField.Content);
editControlsContainer.AddChild(originRowContainer);
// add in the direction
FlowLayoutWidget directionRowContainer = CreateSettingsRow(property);
normalField.ValueChanged += (s, e) =>
{
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { new DirectionAxis() { Origin = originField.Vector3, Normal = normalField.Vector3 } });
rebuildable?.Rebuild(undoBuffer);
propertyGridModifier?.UpdateControls(context);
};
directionRowContainer.AddChild(normalField.Content);
editControlsContainer.AddChild(directionRowContainer);
// update tihs when changed
EventHandler<InvalidateArgs> updateData = (s, e) =>
{
originField.Vector3 = ((DirectionAxis)property.PropertyInfo.GetGetMethod().Invoke(property.Item, null)).Origin;
};
property.Item.Invalidated += updateData;
editControlsContainer.Closed += (s, e) =>
{
property.Item.Invalidated -= updateData;
};
}
rowContainer = CreateSettingsRow(property, field.Content);
}
else if (property.Value is ChildrenSelector childSelector)
{
rowContainer = CreateSettingsColumn(property);
rowContainer.AddChild(CreateSelector(childSelector, property.Item, theme));
editControlsContainer.AddChild(rowContainer);
}
// create a int editor
else if (property.Value is int intValue)
{
rowContainer = CreateSettingsRow(property);
var field = new IntField();
field.Initialize(0);
field.IntValue = intValue;
@ -447,14 +362,11 @@ namespace MatterHackers.MatterControl.DesignTools
propertyGridModifier?.UpdateControls(context);
};
rowContainer.AddChild(field.Content);
editControlsContainer.AddChild(rowContainer);
rowContainer = CreateSettingsRow(property, field.Content);
}
// create a bool editor
else if (property.Value is bool boolValue)
{
rowContainer = CreateSettingsRow(property);
var field = new ToggleboxField(theme);
field.Initialize(0);
field.Checked = boolValue;
@ -465,52 +377,37 @@ namespace MatterHackers.MatterControl.DesignTools
propertyGridModifier?.UpdateControls(context);
};
rowContainer.AddChild(field.Content);
editControlsContainer.AddChild(rowContainer);
rowContainer = CreateSettingsRow(property, field.Content);
}
// create a string editor
else if (property.Value is string stringValue)
{
rowContainer = CreateSettingsRow(property);
var textEditWidget = new MHTextEditWidget(stringValue, pixelWidth: 150 * GuiWidget.DeviceScale)
var field = new TextField();
field.Initialize(0);
field.SetValue(stringValue, false);
field.ValueChanged += (s, e) =>
{
SelectAllOnFocus = true,
VAnchor = VAnchor.Center
};
textEditWidget.ActualTextEditWidget.EditComplete += (s, e) =>
{
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { textEditWidget.Text });
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { field.Value });
rebuildable?.Rebuild(undoBuffer);
propertyGridModifier?.UpdateControls(context);
};
rowContainer.AddChild(textEditWidget);
editControlsContainer.AddChild(rowContainer);
rowContainer = CreateSettingsRow(property, field.Content);
}
// create a char editor
else if (property.Value is char charValue)
{
rowContainer = CreateSettingsRow(property);
var textEditWidget = new MHTextEditWidget(charValue.ToString(), pixelWidth: 150 * GuiWidget.DeviceScale)
var field = new CharField();
field.Initialize(0);
field.SetValue(charValue.ToString(), false);
field.ValueChanged += (s, e) =>
{
SelectAllOnFocus = true,
VAnchor = VAnchor.Center
};
textEditWidget.ActualTextEditWidget.EditComplete += (s, e) =>
{
if (textEditWidget.Text.Length < 1)
{
textEditWidget.Text = "a";
}
if (textEditWidget.Text.Length > 1)
{
textEditWidget.Text = textEditWidget.Text.Substring(0, 1);
}
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { textEditWidget.Text[0] });
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { Convert.ToChar(field.Value) });
rebuildable?.Rebuild(undoBuffer);
propertyGridModifier?.UpdateControls(context);
};
rowContainer.AddChild(textEditWidget);
editControlsContainer.AddChild(rowContainer);
rowContainer = CreateSettingsRow(property, field.Content);
}
// create an enum editor
else if (property.PropertyType.IsEnum)
@ -518,16 +415,16 @@ namespace MatterHackers.MatterControl.DesignTools
rowContainer = CreateEnumEditor(context, rebuildable,
property, property.PropertyType, property.Value, property.DisplayName,
theme, undoBuffer);
editControlsContainer.AddChild(rowContainer);
}
// Use known IObject3D editors
else if (property.Value is IObject3D object3D
&& ApplicationController.Instance.GetEditorsForType(property.PropertyType)?.FirstOrDefault() is IObject3DEditor editor)
{
rowContainer = editor.Create(object3D, view3DWidget, theme);
editControlsContainer.AddChild(rowContainer);
}
editControlsContainer.AddChild(rowContainer);
// remember the row name and widget
context.editRows.Add(property.PropertyInfo.Name, rowContainer);
}

View file

@ -255,6 +255,7 @@
<Compile Include="SetupWizard\DialogWindow.cs" />
<Compile Include="SlicerConfiguration\SettingsOrganizer.cs" />
<Compile Include="SlicerConfiguration\SettingsRow.cs" />
<Compile Include="SlicerConfiguration\UIFields\CharField.cs" />
<Compile Include="SlicerConfiguration\UIFields\IpAddessField.cs" />
<Compile Include="SlicerConfiguration\UIFields\Vector3Field.cs" />
<Compile Include="Utilities\IGCodePostProcessor.cs" />

View file

@ -0,0 +1,90 @@
/*
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.Linq;
using MatterHackers.Agg.UI;
namespace MatterHackers.MatterControl.SlicerConfiguration
{
public class CharField : UIField
{
protected MHTextEditWidget textEditWidget;
public override void Initialize(int tabIndex)
{
textEditWidget = new MHTextEditWidget("", pixelWidth: ControlWidth, tabIndex: tabIndex)
{
ToolTipText = this.HelpText,
SelectAllOnFocus = true,
Name = this.Name,
};
textEditWidget.ActualTextEditWidget.InternalTextEditWidget.KeyPressed += (s, e) =>
{
string keyChar = e.KeyChar.ToString();
if (this.Value != keyChar)
{
this.SetValue(
keyChar,
userInitiated: true);
}
e.Handled = true;
};
textEditWidget.ActualTextEditWidget.KeyUp += (s, e) =>
{
switch(e.KeyCode)
{
case Keys.Back:
this.SetValue(" ", true);
break;
}
};
this.Content = textEditWidget;
}
protected override void OnValueChanged(FieldChangedEventArgs fieldChangedEventArgs)
{
if (this.Value != textEditWidget.Text)
{
textEditWidget.Text = this.Value;
}
base.OnValueChanged(fieldChangedEventArgs);
}
//protected override string ConvertValue(string newValue)
//{
// var lastChar = newValue?.ToCharArray().LastOrDefault();
// return lastChar.ToString();
//}
}
}

View file

@ -1,5 +1,5 @@
/*
Copyright (c) 2017, Lars Brubaker, John Lewin
Copyright (c) 2018, Lars Brubaker, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -27,8 +27,6 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using MatterHackers.Agg.UI;
namespace MatterHackers.MatterControl.SlicerConfiguration
{
public class TextField : UIField
@ -56,7 +54,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
this.Content = textEditWidget;
}
protected override void OnValueChanged(FieldChangedEventArgs fieldChangedEventArgs)
{
if (this.Value != textEditWidget.Text)

View file

@ -337,6 +337,13 @@ namespace MatterControl.Tests.MatterControl
Assert.Fail();
}
[Test, Ignore("Not Implemented")]
public void CharFieldTest()
{
//var field = new BoundDoubleField();
Assert.Fail();
}
public class ValueMap
{
[DebuggerStepThrough]

View file

@ -27,20 +27,12 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System.ComponentModel;
using System.IO;
using MatterHackers.Agg;
using MatterHackers.Agg.Font;
using MatterHackers.Agg.Platform;
using MatterHackers.Agg.Transform;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.MatterControl.DesignTools.Operations;
using MatterHackers.MatterControl.Plugins.BrailleBuilder;
using MatterHackers.VectorMath;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace MatterHackers.MatterControl.DesignTools
{