Get the array functions working better

Improved editors
This commit is contained in:
LarsBrubaker 2018-02-10 20:17:09 -08:00
parent 2cd09dd365
commit 0959340974
9 changed files with 107 additions and 46 deletions

View file

@ -385,7 +385,6 @@ namespace MatterHackers.MatterControl
Icon = AggContext.StaticData.LoadIcon("subtract_and_replace.png").SetPreMultiply(),
IsEnabled = (scene) => scene.SelectedItem is SelectionGroup,
},
#if DEBUG // keep this work in progress to the editor for now
new SceneSelectionSeparator(),
new SceneSelectionOperation()
{
@ -398,7 +397,7 @@ namespace MatterHackers.MatterControl
array.Rebuild();
}
},
Icon = AggContext.StaticData.LoadIcon("array.png").SetPreMultiply(),
Icon = AggContext.StaticData.LoadIcon("array_linear.png").SetPreMultiply(),
IsEnabled = (scene) => scene.HasSelection && !(scene.SelectedItem is SelectionGroup),
},
new SceneSelectionOperation()
@ -412,10 +411,9 @@ namespace MatterHackers.MatterControl
array.Rebuild();
}
},
Icon = AggContext.StaticData.LoadIcon("array.png").SetPreMultiply(),
Icon = AggContext.StaticData.LoadIcon("array_radial.png").SetPreMultiply(),
IsEnabled = (scene) => scene.HasSelection && !(scene.SelectedItem is SelectionGroup),
},
new SceneSelectionSeparator(),
new SceneSelectionOperation()
{
TitleResolver = () => "Advanced Array".Localize(),
@ -427,9 +425,10 @@ namespace MatterHackers.MatterControl
array.Rebuild();
}
},
Icon = AggContext.StaticData.LoadIcon("array.png").SetPreMultiply(),
Icon = AggContext.StaticData.LoadIcon("array_advanced.png").SetPreMultiply(),
IsEnabled = (scene) => scene.HasSelection && !(scene.SelectedItem is SelectionGroup),
},
#if DEBUG // keep this work in progress to the editor for now
new SceneSelectionSeparator(),
new SceneSelectionOperation()
{

View file

@ -83,7 +83,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
{
public int Count { get; set; } = 3;
public DirectionAxis Axis { get; set; } = new DirectionAxis() { Origin = new Vector3(-30, 0, 0), Normal = Vector3.UnitZ };
public DirectionAxis Axis { get; set; } = new DirectionAxis() { Origin = Vector3.NegativeInfinity, Normal = Vector3.UnitZ };
public double Angle { get; set; } = 360;
[DisplayName("Keep Within Angle")]
@ -102,31 +102,36 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
public void Rebuild()
{
if(Axis.Origin.X == double.NegativeInfinity)
{
// make it something reasonable (just to the left of the aabb of the object)
var aabb = this.GetAxisAlignedBoundingBox();
Axis.Origin = new Vector3(aabb.minXYZ.X - aabb.XSize / 2, aabb.Center.Y, 0);
}
this.Children.Modify(list =>
{
IObject3D lastChild = list.First();
var partCenter = lastChild.GetAxisAlignedBoundingBox().Center;
IObject3D first = list.First();
list.Clear();
list.Add(lastChild);
list.Add(first);
var offset = Vector3.Zero;
for (int i = 1; i < Count; i++)
{
var angleRadians = MathHelper.DegreesToRadians(Angle);
var nextOffset = Axis.Origin;
var next = first.Clone();
//nextOffset Rotate(angleRadians * i);
var next = lastChild.Clone();
next.Matrix *= Matrix4X4.CreateTranslation(nextOffset.X, nextOffset.Y, 0);
var normal = Axis.Normal.GetNormal();
var angleRadians = MathHelper.DegreesToRadians(Angle) / Count * i;
next.Rotate(Axis.Origin, normal, angleRadians);
if (RotatePart)
if (!RotatePart)
{
next.ApplyAtBoundsCenter(Matrix4X4.CreateRotationZ(angleRadians));
next.Rotate(next.GetAxisAlignedBoundingBox().Center, normal, -angleRadians);
}
lastChild = next;
list.Add(next);
}
});
this.Invalidate();
}
}

View file

@ -89,12 +89,13 @@ namespace MatterHackers.MatterControl.DesignTools
public IEnumerable<Type> SupportedTypes() => new Type[] { typeof(IRebuildable) };
private static FlowLayoutWidget CreateSettingsRow(string labelText)
private static FlowLayoutWidget CreateSettingsRow(string labelText, string toolTipText = null)
{
var rowContainer = new FlowLayoutWidget(FlowDirection.LeftToRight)
{
HAnchor = HAnchor.Stretch,
Padding = new BorderDouble(5)
Padding = new BorderDouble(5),
ToolTipText = toolTipText
};
var label = new TextWidget(labelText + ":", pointSize: 11, textColor: ActiveTheme.Instance.PrimaryTextColor)
@ -115,7 +116,13 @@ namespace MatterHackers.MatterControl.DesignTools
return nameAttribute?.DisplayName ?? prop.Name;
}
private void ModifyObject(View3DWidget view3DWidget, FlowLayoutWidget tabContainer, ThemeConfig theme)
private string GetDescription(PropertyInfo prop)
{
var nameAttribute = prop.GetCustomAttributes(true).OfType<DescriptionAttribute>().FirstOrDefault();
return nameAttribute?.Description ?? null;
}
private void ModifyObject(View3DWidget view3DWidget, FlowLayoutWidget editControlsContainer, ThemeConfig theme)
{
var rebuildable = item as IRebuildable;
@ -127,6 +134,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
Value = p.GetGetMethod().Invoke(this.item, null),
DisplayName = GetDisplayName(p),
Description = GetDescription(p),
PropertyType = p.PropertyType,
PropertyInfo = p
});
@ -148,7 +156,7 @@ namespace MatterHackers.MatterControl.DesignTools
};
rowContainer.AddChild(field.Content);
tabContainer.AddChild(rowContainer);
editControlsContainer.AddChild(rowContainer);
}
else if (property.Value is Vector2 vector2)
{
@ -164,7 +172,7 @@ namespace MatterHackers.MatterControl.DesignTools
};
rowContainer.AddChild(field.Content);
tabContainer.AddChild(rowContainer);
editControlsContainer.AddChild(rowContainer);
}
else if (property.Value is Vector3 vector3)
{
@ -180,23 +188,63 @@ namespace MatterHackers.MatterControl.DesignTools
};
rowContainer.AddChild(field.Content);
tabContainer.AddChild(rowContainer);
editControlsContainer.AddChild(rowContainer);
}
else if (property.Value is DirectionVector directionVector)
{
FlowLayoutWidget rowContainer = CreateSettingsRow(property.DisplayName.Localize());
var field = new Vector3Field();
field.Initialize(0);
field.Vector3 = directionVector.Normal;
field.ValueChanged += (s, e) =>
bool simpleEdit = true;
if (simpleEdit)
{
property.PropertyInfo.GetSetMethod().Invoke(this.item, new Object[] { new DirectionVector() { Normal = field.Vector3 } });
rebuildable?.Rebuild();
};
FlowLayoutWidget rowContainer = CreateSettingsRow(property.DisplayName.Localize());
rowContainer.AddChild(field.Content);
tabContainer.AddChild(rowContainer);
var dropDownList = new DropDownList("Name".Localize(), theme.Colors.PrimaryTextColor, Direction.Down, pointSize: theme.DefaultFontSize);
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)
{
case "Right":
property.PropertyInfo.GetSetMethod().Invoke(this.item, new Object[] { new DirectionVector() { Normal = Vector3.UnitX } });
break;
case "Back":
property.PropertyInfo.GetSetMethod().Invoke(this.item, new Object[] { new DirectionVector() { Normal = Vector3.UnitY } });
break;
case "Up":
property.PropertyInfo.GetSetMethod().Invoke(this.item, new Object[] { new DirectionVector() { Normal = Vector3.UnitZ } });
break;
}
rebuildable?.Rebuild();
};
}
dropDownList.SelectedLabel = "Right";
rowContainer.AddChild(dropDownList);
editControlsContainer.AddChild(rowContainer);
}
else // edit the vector
{
FlowLayoutWidget rowContainer = CreateSettingsRow(property.DisplayName.Localize());
var field = new Vector3Field();
field.Initialize(0);
field.Vector3 = directionVector.Normal;
field.ValueChanged += (s, e) =>
{
property.PropertyInfo.GetSetMethod().Invoke(this.item, new Object[] { new DirectionVector() { Normal = field.Vector3 } });
rebuildable?.Rebuild();
};
rowContainer.AddChild(field.Content);
editControlsContainer.AddChild(rowContainer);
}
}
else if (property.Value is DirectionAxis directionAxis)
{
@ -218,7 +266,7 @@ namespace MatterHackers.MatterControl.DesignTools
};
originRowContainer.AddChild(originField.Content);
tabContainer.AddChild(originRowContainer);
editControlsContainer.AddChild(originRowContainer);
// add in the direction
FlowLayoutWidget directionRowContainer = CreateSettingsRow(property.DisplayName.Localize());
@ -230,7 +278,18 @@ namespace MatterHackers.MatterControl.DesignTools
};
directionRowContainer.AddChild(normalField.Content);
tabContainer.AddChild(directionRowContainer);
editControlsContainer.AddChild(directionRowContainer);
// update tihs when changed
EventHandler updateData = (object s, EventArgs e) =>
{
originField.Vector3 = ((DirectionAxis)property.PropertyInfo.GetGetMethod().Invoke(this.item, null)).Origin;
};
item.Invalidated += updateData;
editControlsContainer.Closed += (s, e) =>
{
item.Invalidated -= updateData;
};
}
// create a int editor
else if (property.Value is int intValue)
@ -247,12 +306,12 @@ namespace MatterHackers.MatterControl.DesignTools
};
rowContainer.AddChild(field.Content);
tabContainer.AddChild(rowContainer);
editControlsContainer.AddChild(rowContainer);
}
// create a bool editor
else if (property.Value is bool boolValue)
{
FlowLayoutWidget rowContainer = CreateSettingsRow(property.DisplayName.Localize());
FlowLayoutWidget rowContainer = CreateSettingsRow(property.DisplayName.Localize(), property.Description.Localize());
var field = new ToggleboxField(ApplicationController.Instance.Theme.Colors.PrimaryTextColor);
field.Initialize(0);
@ -264,7 +323,7 @@ namespace MatterHackers.MatterControl.DesignTools
};
rowContainer.AddChild(field.Content);
tabContainer.AddChild(rowContainer);
editControlsContainer.AddChild(rowContainer);
}
// create a string editor
else if (property.Value is string stringValue)
@ -281,7 +340,7 @@ namespace MatterHackers.MatterControl.DesignTools
rebuildable?.Rebuild();
};
rowContainer.AddChild(textEditWidget);
tabContainer.AddChild(rowContainer);
editControlsContainer.AddChild(rowContainer);
}
// create a enum editor
else if (property.PropertyType.IsEnum)
@ -319,7 +378,7 @@ namespace MatterHackers.MatterControl.DesignTools
dropDownList.SelectedLabel = property.Value.ToString().Replace('_', ' ');
rowContainer.AddChild(dropDownList);
tabContainer.AddChild(rowContainer);
editControlsContainer.AddChild(rowContainer);
}
}
@ -330,7 +389,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
rebuildable?.Rebuild();
};
tabContainer.AddChild(updateButton);
editControlsContainer.AddChild(updateButton);
}
}
}

View file

@ -273,7 +273,5 @@ namespace MatterHackers.MatterControl
return true;
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 958 B

View file

Before

Width:  |  Height:  |  Size: 240 B

After

Width:  |  Height:  |  Size: 240 B

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

@ -1 +1 @@
Subproject commit a2b16945b16273fa243153926b9121ec20f06911
Subproject commit ae67b42d370677299e944d410aeb0eb01a6d248f

@ -1 +1 @@
Subproject commit 475340af7062eb5ee3130d077230fdca434bd50e
Subproject commit 3badb0ba9d782ea89a0bb3a9f4f31daf54b8e4e7