From 0959340974eabb623669db293d56858565f35547 Mon Sep 17 00:00:00 2001 From: LarsBrubaker Date: Sat, 10 Feb 2018 20:17:09 -0800 Subject: [PATCH] Get the array functions working better Improved editors --- ApplicationView/ApplicationController.cs | 9 +- DesignTools/Operations/ArrayObject3D.cs | 29 +++-- DesignTools/PublicPropertyEditor.cs | 109 ++++++++++++++---- PartPreviewWindow/PlatingHelper.cs | 2 - StaticData/Icons/array_advanced.png | Bin 0 -> 958 bytes .../Icons/{array.png => array_linear.png} | Bin StaticData/Icons/array_radial.png | Bin 0 -> 1100 bytes Submodules/MatterSlice | 2 +- Submodules/agg-sharp | 2 +- 9 files changed, 107 insertions(+), 46 deletions(-) create mode 100644 StaticData/Icons/array_advanced.png rename StaticData/Icons/{array.png => array_linear.png} (100%) create mode 100644 StaticData/Icons/array_radial.png diff --git a/ApplicationView/ApplicationController.cs b/ApplicationView/ApplicationController.cs index 6f261493d..417b6154b 100644 --- a/ApplicationView/ApplicationController.cs +++ b/ApplicationView/ApplicationController.cs @@ -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() { diff --git a/DesignTools/Operations/ArrayObject3D.cs b/DesignTools/Operations/ArrayObject3D.cs index 339d55795..124a954f3 100644 --- a/DesignTools/Operations/ArrayObject3D.cs +++ b/DesignTools/Operations/ArrayObject3D.cs @@ -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(); } } diff --git a/DesignTools/PublicPropertyEditor.cs b/DesignTools/PublicPropertyEditor.cs index 53f9edc76..b45093552 100644 --- a/DesignTools/PublicPropertyEditor.cs +++ b/DesignTools/PublicPropertyEditor.cs @@ -89,12 +89,13 @@ namespace MatterHackers.MatterControl.DesignTools public IEnumerable 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().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); } } } \ No newline at end of file diff --git a/PartPreviewWindow/PlatingHelper.cs b/PartPreviewWindow/PlatingHelper.cs index a81f42f15..01705c93e 100644 --- a/PartPreviewWindow/PlatingHelper.cs +++ b/PartPreviewWindow/PlatingHelper.cs @@ -273,7 +273,5 @@ namespace MatterHackers.MatterControl return true; } - - } } diff --git a/StaticData/Icons/array_advanced.png b/StaticData/Icons/array_advanced.png new file mode 100644 index 0000000000000000000000000000000000000000..56e4656b9e3284d38caa866b7893717003c299b3 GIT binary patch literal 958 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4mJh`2Kmqb6B!s7r87e!N+NuHtdjF{^%7I^ zlT!66atjzhz{b9!ATc>RwL~E)H9a%WR_Xoj{Yna%DYi=CroINg16w1-Ypui3%0DIeEoa6}C!XbFK1lpi<;HsXMd|v6mX?*7iAWdWaj57fXqxx$}cUkRZ`LiS)vaT z3373>gRBj?(Ps@;VN`+wP&23;_=6OSp=gG znk`VcRU!IIJVQHzyJ-xPwpg3;rH%1K%IBy8 zqX$tDF-14yH(crw=Kd?_8lLVfocQY2^Swtp?^d0S`uh0a)@czj;Ri0M*sNL+6<6U^ zk*2$T)*j_IAwd&oe3-exeKI%K{h3u;&a78cKm8|nlNeuLIE_3R#4q<4x6OBSJM#PEqs9JZS5C@nJUu^ga*XSq zQ&v)|RXisiSI%-=bv)I#LvH%Sw7YNq-{1GDQ!#$$E@g(^^KBpRF@MYbp(%Cj`ozRP zGR(*-iiThYII?ucW?xTNwW6c32&w)!p<<3!R%<85kHi3p^r=85sDEfH31!Z9ZuR z28P|9E{-7BO2a~*OJXxo2PckNk5ojY!9EdCRkEBM#CoUz^GE|sfWa!{$GqxV77 z?Ine|HAiMFNK*Y#{`tqV`I0|gXRqAUw6%=aWRqn*`!l6Wb*2ZtPkJEceyp%p`7uM< z0T=x>y`n9aiyyDP`rGq@q~!LCT!#*>I>-4z&c=&(_PQ{Z*g1@4%8!>F2xDHde7ScB zA45c!hxYvy+@20DUjHYDs?J}b^`GzihJzMH>$o@go3@8MR{WQ7D*rXln_RP`k3NjG Ppls*q>gTe~DWM4fhysR) literal 0 HcmV?d00001 diff --git a/StaticData/Icons/array.png b/StaticData/Icons/array_linear.png similarity index 100% rename from StaticData/Icons/array.png rename to StaticData/Icons/array_linear.png diff --git a/StaticData/Icons/array_radial.png b/StaticData/Icons/array_radial.png new file mode 100644 index 0000000000000000000000000000000000000000..73b177f80c0a395ff8a436b9c972070afac23fdf GIT binary patch literal 1100 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4mJh`2Kmqb6B!s7r87e!N+NuHtdjF{^%7I^ zlT!66atjzhz{b9!ATc>RwL~E)H9a%WR_Xoj{Yna%DYi=CroINg16w1-Ypui3%0DIeEoa6}C!XbFK1lpi<;HsXMd|v6mX?*7iAWdWaj57fXqxx$}cUkRZ`LiS)vaT z3373>A1Ea zRHGy6m+6)Gfb0u0EUtns&cVfj-X~w%@J=~VZ27(B-S>ONJHE$kaJ%H?mjA&?ZT5Ai zgALVni5GM04|Xw&$L(6wweDPty3&=c=c{$n_I#bO_0{~}*Jp)4+Ql?Y?O~wn)lY{e zAG(}fdG(3x!!lLTSV24Cch{dZ9V%ZYxBA2ClP9_AXRmQ}N>0cXE>q982s`ZMb(-V! z>6a&$aG!c#duIBUBb$p8JMTW4`=W(I=)hT#$2||zCkW2`Tk*kALHpH{>eD|rKT!#v z7?~>D8#-ypiOc#~j;oHVs=4%^_Sl^F?SFp!*CP|w2klj5=sn-|@gDcLTn$m)$FENq zcpXouZaSS~YG2NASbmZC>ZtRK7UmECtXg%n>|qkOmE6@8V!GaDh1p7s`O7ctVpu0# zpc7j4ZTI<;%r0h6Rxrd@6INNg6glE6m)oHEuVy)c!d*zk+JDBTTR<6)gx_orrwOs+P zch1?}%y!qY`Et9}wJ58(=PvcL1&Zi)pEz3bYv+O8Uk#24v?b~&t