Create new DirectionVectorField for DirectionVector content
This commit is contained in:
parent
097b1d2a35
commit
5a842e6207
5 changed files with 132 additions and 31 deletions
|
|
@ -276,39 +276,17 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
}
|
||||
else if (property.Value is DirectionVector directionVector)
|
||||
{
|
||||
var dropDownList = new DropDownList("Name".Localize(), theme.Colors.PrimaryTextColor, Direction.Down, pointSize: theme.DefaultFontSize)
|
||||
var field = new DirectionVectorField();
|
||||
field.Initialize(0);
|
||||
field.SetValue(directionVector);
|
||||
field.ValueChanged += (s, e) =>
|
||||
{
|
||||
BorderColor = theme.GetBorderColor(75)
|
||||
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { field.DirectionVector });
|
||||
rebuildable?.Rebuild(undoBuffer);
|
||||
propertyGridModifier?.UpdateControls(context);
|
||||
};
|
||||
|
||||
foreach (var orderItem in new string[] { "Right", "Back", "Up" })
|
||||
{
|
||||
MenuItem newItem = dropDownList.AddItem(orderItem);
|
||||
|
||||
var localOredrItem = orderItem;
|
||||
newItem.Selected += (sender, e) =>
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
rebuildable?.Rebuild(undoBuffer);
|
||||
propertyGridModifier?.UpdateControls(context);
|
||||
};
|
||||
}
|
||||
|
||||
dropDownList.SelectedLabel = "Right";
|
||||
|
||||
rowContainer = CreateSettingsRow(property, dropDownList);
|
||||
rowContainer = CreateSettingsRow(property, field.Content);
|
||||
}
|
||||
else if (property.Value is DirectionAxis directionAxis)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -256,6 +256,7 @@
|
|||
<Compile Include="SlicerConfiguration\SettingsOrganizer.cs" />
|
||||
<Compile Include="SlicerConfiguration\SettingsRow.cs" />
|
||||
<Compile Include="SlicerConfiguration\UIFields\CharField.cs" />
|
||||
<Compile Include="SlicerConfiguration\UIFields\DirectionVectorField.cs" />
|
||||
<Compile Include="SlicerConfiguration\UIFields\IpAddessField.cs" />
|
||||
<Compile Include="SlicerConfiguration\UIFields\Vector3Field.cs" />
|
||||
<Compile Include="Utilities\IGCodePostProcessor.cs" />
|
||||
|
|
|
|||
115
SlicerConfiguration/UIFields/DirectionVectorField.cs
Normal file
115
SlicerConfiguration/UIFields/DirectionVectorField.cs
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
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 MatterHackers.Agg.UI;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.DesignTools.EditableTypes;
|
||||
using MatterHackers.VectorMath;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||
{
|
||||
public class DirectionVectorField : UIField
|
||||
{
|
||||
private DropDownList dropDownList;
|
||||
|
||||
public override void Initialize(int tabIndex)
|
||||
{
|
||||
var theme = ApplicationController.Instance.Theme;
|
||||
|
||||
dropDownList = new DropDownList("Name".Localize(), theme.Colors.PrimaryTextColor, Direction.Down, pointSize: theme.DefaultFontSize)
|
||||
{
|
||||
BorderColor = theme.GetBorderColor(75)
|
||||
};
|
||||
|
||||
dropDownList.AddItem(
|
||||
"Back".Localize(),
|
||||
JsonConvert.SerializeObject(
|
||||
new DirectionVector()
|
||||
{
|
||||
Normal = Vector3.UnitY
|
||||
}));
|
||||
|
||||
dropDownList.AddItem(
|
||||
"Up".Localize(),
|
||||
JsonConvert.SerializeObject(
|
||||
new DirectionVector()
|
||||
{
|
||||
Normal = Vector3.UnitZ
|
||||
}));
|
||||
|
||||
dropDownList.AddItem(
|
||||
"Right".Localize(),
|
||||
JsonConvert.SerializeObject(
|
||||
new DirectionVector()
|
||||
{
|
||||
Normal = Vector3.UnitX
|
||||
}));
|
||||
|
||||
dropDownList.SelectedLabel = "Right";
|
||||
|
||||
dropDownList.SelectionChanged += (s, e) =>
|
||||
{
|
||||
if (this.Value != dropDownList.SelectedValue)
|
||||
{
|
||||
this.SetValue(
|
||||
dropDownList.SelectedValue,
|
||||
userInitiated: true);
|
||||
};
|
||||
};
|
||||
|
||||
this.Content = dropDownList;
|
||||
}
|
||||
|
||||
public DirectionVector DirectionVector { get; private set; }
|
||||
|
||||
public void SetValue(DirectionVector directionVector)
|
||||
{
|
||||
this.SetValue(
|
||||
JsonConvert.SerializeObject(directionVector),
|
||||
false);
|
||||
}
|
||||
|
||||
protected override string ConvertValue(string newValue)
|
||||
{
|
||||
this.DirectionVector = JsonConvert.DeserializeObject<DirectionVector>(newValue);
|
||||
return base.ConvertValue(newValue);
|
||||
}
|
||||
|
||||
protected override void OnValueChanged(FieldChangedEventArgs fieldChangedEventArgs)
|
||||
{
|
||||
if (this.Value != dropDownList.SelectedValue)
|
||||
{
|
||||
dropDownList.SelectedValue = this.Value;
|
||||
}
|
||||
|
||||
base.OnValueChanged(fieldChangedEventArgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -46,7 +46,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
if (this.Value != textEditWidget.Text)
|
||||
{
|
||||
this.SetValue(
|
||||
textEditWidget.Text,
|
||||
textEditWidget.Text,
|
||||
userInitiated: true);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -344,6 +344,13 @@ namespace MatterControl.Tests.MatterControl
|
|||
Assert.Fail();
|
||||
}
|
||||
|
||||
[Test, Ignore("Not Implemented")]
|
||||
public void DirectionVectorFieldTest()
|
||||
{
|
||||
//var field = new BoundDoubleField();
|
||||
Assert.Fail();
|
||||
}
|
||||
|
||||
public class ValueMap
|
||||
{
|
||||
[DebuggerStepThrough]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue