Working on more enum display options

Improving image converter display
This commit is contained in:
LarsBrubaker 2020-05-10 19:17:48 -07:00
parent ae6caba71b
commit 18581597c7
9 changed files with 169 additions and 45 deletions

View file

@ -104,7 +104,6 @@ namespace MatterHackers.MatterControl
Titan,
Titillium,
}
;
public class WorkspacesChangedEventArgs : EventArgs
{

View file

@ -32,23 +32,29 @@ using System;
namespace MatterHackers.MatterControl.DesignTools
{
[AttributeUsage(AttributeTargets.Property)]
public class IconsAttribute : Attribute
public class EnumDisplayAttribute : Attribute
{
public IconsAttribute(string[] iconPaths, int width = 16, int height = 16, bool item0IsNone = true)
public enum PresentationMode
{
Width = width;
Height = height;
this.IconPaths = iconPaths;
Item0IsNone = item0IsNone;
DropDownList,
IconRow,
Tabs,
Buttons
}
public bool Item0IsNone { get; private set; }
public PresentationMode Mode { get; set; } = PresentationMode.DropDownList;
public string[] IconPaths { get; private set; }
public EnumDisplayAttribute()
{
}
public int Width { get; set; }
public bool Item0IsNone { get; set; } = true;
public int Height { get; set; }
public string[] IconPaths { get; set; }
public int IconWidth { get; set; } = 16;
public int IconHeight { get; set; } = 16;
public bool InvertIcons { get; set; } = false;
}

View file

@ -304,6 +304,7 @@ namespace MatterHackers.Plugins.EditorTools
{
newSize.X *= -1;
}
newSize.Y = lockedCorner.Y - newPosition.Y;
if (quadrantIndex == 0 || quadrantIndex == 1)
{
@ -344,6 +345,7 @@ namespace MatterHackers.Plugins.EditorTools
{
InteractionContext.Scene.AddTransformSnapshot(transformOnMouseDown);
}
base.OnMouseUp(mouseEvent3D);
}
@ -445,11 +447,13 @@ namespace MatterHackers.Plugins.EditorTools
newSize.X = newSize.X <= minimumSize ? minimumSize : newSize.X;
scaleAmount.X = newSize.X / originalSelectedBounds.XSize;
}
if (newSize.Y > 0)
{
newSize.Y = newSize.Y <= minimumSize ? minimumSize : newSize.Y;
scaleAmount.Y = newSize.Y / originalSelectedBounds.YSize;
}
if (newSize.Z > 0)
{
newSize.Z = newSize.Z <= minimumSize ? minimumSize : newSize.Z;
@ -484,6 +488,7 @@ namespace MatterHackers.Plugins.EditorTools
return false;
}
private Vector3 GetDeltaToOtherSideXy(IObject3D selectedItem, int quadrantIndex)
{
Vector3 cornerPosition = GetCornerPosition(selectedItem, quadrantIndex);

View file

@ -176,33 +176,33 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
public bool Advanced { get; set; } = false;
[SectionStart("X Axis"), DisplayName("Align")]
[Icons(new string[] { "424.png", "align_left.png", "align_center_x.png", "align_right.png", "align_origin.png" }, InvertIcons = true)]
[EnumDisplay(IconPaths = new string[] { "424.png", "align_left.png", "align_center_x.png", "align_right.png", "align_origin.png" }, InvertIcons = true)]
public Align XAlign { get; set; } = Align.None;
[DisplayName("Anchor")]
[Icons(new string[] { "424.png", "align_to_left.png", "align_to_center_x.png", "align_to_right.png", "align_origin.png" }, InvertIcons = true)]
[EnumDisplay(IconPaths = new string[] { "424.png", "align_to_left.png", "align_to_center_x.png", "align_to_right.png", "align_origin.png" }, InvertIcons = true)]
public Align XAlignTo { get; set; } = Align.None;
[DisplayName("Offset")]
public double XOffset { get; set; } = 0;
[SectionStart("Y Axis"), DisplayName("Align")]
[Icons(new string[] { "424.png", "align_bottom.png", "align_center_y.png", "align_Top.png", "align_origin.png" }, InvertIcons = true)]
[EnumDisplay(IconPaths = new string[] { "424.png", "align_bottom.png", "align_center_y.png", "align_Top.png", "align_origin.png" }, InvertIcons = true)]
public Align YAlign { get; set; } = Align.None;
[DisplayName("Anchor")]
[Icons(new string[] { "424.png", "align_to_bottom.png", "align_to_center_y.png", "align_to_top.png", "align_origin.png" }, InvertIcons = true)]
[EnumDisplay(IconPaths = new string[] { "424.png", "align_to_bottom.png", "align_to_center_y.png", "align_to_top.png", "align_origin.png" }, InvertIcons = true)]
public Align YAlignTo { get; set; } = Align.None;
[DisplayName("Offset")]
public double YOffset { get; set; } = 0;
[SectionStart("Z Axis"), DisplayName("Align")]
[Icons(new string[] { "424.png", "align_bottom.png", "align_center_y.png", "align_Top.png", "align_origin.png" }, InvertIcons = true)]
[EnumDisplay(IconPaths = new string[] { "424.png", "align_bottom.png", "align_center_y.png", "align_Top.png", "align_origin.png" }, InvertIcons = true)]
public Align ZAlign { get; set; } = Align.None;
[DisplayName("Anchor")]
[Icons(new string[] { "424.png", "align_to_bottom.png", "align_to_center_y.png", "align_to_top.png", "align_origin.png" }, InvertIcons = true)]
[EnumDisplay(IconPaths = new string[] { "424.png", "align_to_bottom.png", "align_to_center_y.png", "align_to_top.png", "align_origin.png" }, InvertIcons = true)]
public Align ZAlignTo { get; set; } = Align.None;
[DisplayName("Offset")]

View file

@ -28,7 +28,7 @@ either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using ClipperLib;
@ -38,6 +38,7 @@ using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters2D;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DesignTools;
using MatterHackers.MatterControl.DesignTools.Operations;
using MatterHackers.VectorMath;
using Newtonsoft.Json;
@ -57,6 +58,12 @@ namespace MatterHackers.MatterControl.DesignTools
public class BaseObject3D : Object3D, IPropertyGridModifier
{
public enum CenteringTypes
{
Bounds,
Weighted
}
readonly double scalingForClipper = 1000;
public BaseObject3D()
@ -66,14 +73,20 @@ namespace MatterHackers.MatterControl.DesignTools
public override bool CanFlatten => true;
[EnumDisplay(Mode = EnumDisplayAttribute.PresentationMode.Tabs)]
public BaseTypes BaseType { get; set; } = BaseTypes.Circle;
[DisplayName("Expand")]
public double BaseSize { get; set; } = 3;
public double InfillAmount { get; set; } = 3;
[DisplayName("Height")]
public double ExtrusionHeight { get; set; } = 5;
[EnumDisplay(Mode = EnumDisplayAttribute.PresentationMode.Buttons)]
public CenteringTypes Centering { get; set; } = CenteringTypes.Weighted;
public override void Remove(UndoBuffer undoBuffer)
{
using (RebuildLock())
@ -327,7 +340,10 @@ namespace MatterHackers.MatterControl.DesignTools
public void UpdateControls(PublicPropertyChange change)
{
// change.SetRowVisible(nameof(InfillAmount), () => CurrentBaseType == BaseTypes.Outline);
change.SetRowVisible(nameof(BaseSize), () => BaseType != BaseTypes.None);
change.SetRowVisible(nameof(InfillAmount), () => BaseType == BaseTypes.Outline);
change.SetRowVisible(nameof(Centering), () => BaseType == BaseTypes.Circle);
change.SetRowVisible(nameof(ExtrusionHeight), () => BaseType != BaseTypes.None);
}
}
}

View file

@ -613,13 +613,19 @@ namespace MatterHackers.MatterControl.DesignTools
{
// create an enum editor
UIField field;
var iconsAttribute = property.PropertyInfo.GetCustomAttributes(true).OfType<IconsAttribute>().FirstOrDefault();
if (iconsAttribute != null)
var enumDisplayAttribute = property.PropertyInfo.GetCustomAttributes(true).OfType<EnumDisplayAttribute>().FirstOrDefault();
var addToSettingsRow = true;
if (enumDisplayAttribute != null)
{
field = new IconEnumField(property, iconsAttribute, theme)
field = new EnumDisplayField(property, enumDisplayAttribute, theme)
{
InitialValue = propertyValue.ToString()
};
if (enumDisplayAttribute.Mode == EnumDisplayAttribute.PresentationMode.Tabs)
{
addToSettingsRow = false;
}
}
else
{
@ -647,7 +653,14 @@ namespace MatterHackers.MatterControl.DesignTools
propertyGridModifier?.UpdateControls(new PublicPropertyChange(context, property.PropertyInfo.Name));
};
rowContainer = CreateSettingsRow(property, field, theme);
if (addToSettingsRow)
{
rowContainer = CreateSettingsRow(property, field, theme);
}
else
{
rowContainer = field.Content;
}
}
else if (propertyValue is IObject3D item
&& ApplicationController.Instance.Extensions.GetEditorsForType(property.PropertyType)?.FirstOrDefault() is IObject3DEditor iObject3DEditor)

View file

@ -145,10 +145,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
var children = scene.Children.ToList();
var transformData = new List<TransformData>();
foreach(var child in children)
foreach (var child in children)
{
transformData.Add(new TransformData() { TransformedObject = child, UndoTransform = child.Matrix });
}
PlatingHelper.ArrangeOnBed(children, bedCenter);
int i = 0;
foreach (var child in children)
@ -156,6 +157,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
transformData[i].RedoTransform = child.Matrix;
i++;
}
scene.UndoBuffer.Add(new TransformCommand(transformData));
});
}

View file

@ -28,6 +28,7 @@ either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using MatterHackers.Agg;
using MatterHackers.Agg.Image;
@ -39,16 +40,16 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.SlicerConfiguration
{
public class IconEnumField : UIField
public class EnumDisplayField : UIField
{
private EditableProperty property;
private IconsAttribute iconsAttribute;
private ThemeConfig theme;
private readonly EditableProperty property;
private readonly EnumDisplayAttribute enumDisplayAttibute;
private readonly ThemeConfig theme;
public IconEnumField(EditableProperty property, IconsAttribute iconsAttribute, ThemeConfig theme)
public EnumDisplayField(EditableProperty property, EnumDisplayAttribute iconsAttribute, ThemeConfig theme)
{
this.property = property;
this.iconsAttribute = iconsAttribute;
this.enumDisplayAttibute = iconsAttribute;
this.theme = theme;
}
@ -58,32 +59,114 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
public override void Initialize(int tabIndex)
{
// Enum keyed on name to friendly name
var enumItems = Enum.GetNames(property.PropertyType).Select(enumName =>
{
return new
{
Key = enumName,
Value = enumName.Replace('_', ' ')
};
});
var enumItems = Enum.GetNames(property.PropertyType).Select(enumName => (enumName, enumName.Replace('_', ' ')));
switch (enumDisplayAttibute.Mode)
{
case EnumDisplayAttribute.PresentationMode.IconRow:
AddIconRow(enumItems);
break;
case EnumDisplayAttribute.PresentationMode.Tabs:
AddTabs(enumItems);
break;
case EnumDisplayAttribute.PresentationMode.Buttons:
AddButtons(enumItems);
break;
default:
throw new NotImplementedException();
}
}
private void AddTabs(IEnumerable<(string Key, string Value)> enumItems)
{
var menuRow = new FlowLayoutWidget();
int index = 0;
foreach (var enumItem in enumItems)
{
var localIndex = index;
var radioButton = new RadioTextButton(enumItem.Value, theme);
// set it if checked
if (enumItem.Value == this.InitialValue)
{
radioButton.Checked = true;
}
menuRow.AddChild(radioButton);
var localItem = enumItem;
radioButton.CheckedStateChanged += (s, e) =>
{
if (radioButton.Checked)
{
this.SetValue(localItem.Key, true);
}
};
index++;
}
this.Content = menuRow;
}
private void AddButtons(IEnumerable<(string Key, string Value)> enumItems)
{
var menuRow = new FlowLayoutWidget();
int index = 0;
foreach (var enumItem in enumItems)
{
var localIndex = index;
var radioButton = new RadioTextButton(enumItem.Value, theme);
// set it if checked
if (enumItem.Value == this.InitialValue)
{
radioButton.Checked = true;
}
menuRow.AddChild(radioButton);
var localItem = enumItem;
radioButton.CheckedStateChanged += (s, e) =>
{
if (radioButton.Checked)
{
this.SetValue(localItem.Key, true);
}
};
index++;
}
this.Content = menuRow;
}
private void AddIconRow(IEnumerable<(string Key, string Value)> enumItems)
{
var iconsRow = new FlowLayoutWidget();
int index = 0;
var radioButtonSize = new Vector2(iconsAttribute.Width, iconsAttribute.Height);
var radioButtonSize = new Vector2(enumDisplayAttibute.IconWidth, enumDisplayAttibute.IconHeight);
foreach (var enumItem in enumItems)
{
var localIndex = index;
ImageBuffer iconImage = null;
var iconPath = iconsAttribute.IconPaths[localIndex];
var iconPath = enumDisplayAttibute.IconPaths[localIndex];
if (!string.IsNullOrWhiteSpace(iconPath))
{
if (iconsAttribute.Width > 0)
if (enumDisplayAttibute.IconWidth > 0)
{
// If the attribute allows invert, use the theme.InvertIcons state
bool invertIcons = iconsAttribute.InvertIcons ? theme.InvertIcons : false;
bool invertIcons = enumDisplayAttibute.InvertIcons ? theme.InvertIcons : false;
iconImage = AggContext.StaticData.LoadIcon(iconPath, iconsAttribute.Width, iconsAttribute.Height, invertIcons);
iconImage = AggContext.StaticData.LoadIcon(iconPath, enumDisplayAttibute.IconWidth, enumDisplayAttibute.IconHeight, invertIcons);
}
else
{
@ -114,7 +197,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
}
};
}
else if(iconsAttribute.Width > 0)
else if (enumDisplayAttibute.IconWidth > 0)
{
// hold the space of the empty icon
iconsRow.AddChild(new GuiWidget(radioButtonSize.X, radioButtonSize.Y));