From a37d896edf80dbe1fd5e2d7f212e1396f0b59a7f Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Wed, 1 Aug 2018 18:05:04 -0700 Subject: [PATCH] Fixing bug in component packaging Started work on component editor --- ApplicationView/ApplicationController.cs | 26 ++++++++++ CustomWidgets/TreeView/TreeView.cs | 4 ++ DesignTools/Obsolete/FitToBoundsObject3D.cs | 19 ++++--- DesignTools/Operations/AlignObject3D.cs | 18 ++++--- DesignTools/Operations/ScaleObject3D.cs | 18 ++++--- DesignTools/Primitives/BaseObject3D.cs | 3 +- .../Primitives/ComponentEditorObject3D.cs | 49 +++++++++++++++++++ DesignTools/Primitives/ComponentObject3D.cs | 7 +++ DesignTools/Primitives/CylinderObject3D.cs | 15 ++++-- DesignTools/Primitives/RingObject3D.cs | 6 ++- DesignTools/Primitives/SphereObject3D.cs | 9 ++-- DesignTools/Primitives/TorusObject3D.cs | 12 +++-- MatterControl.csproj | 1 + Utilities/InspectForm.cs | 4 ++ Utilities/JsonPath.cs | 15 ++++-- 15 files changed, 169 insertions(+), 37 deletions(-) create mode 100644 DesignTools/Primitives/ComponentEditorObject3D.cs diff --git a/ApplicationView/ApplicationController.cs b/ApplicationView/ApplicationController.cs index 55ad433cf..c11304330 100644 --- a/ApplicationView/ApplicationController.cs +++ b/ApplicationView/ApplicationController.cs @@ -765,6 +765,32 @@ namespace MatterHackers.MatterControl }, iconCollector: (theme) => AggContext.StaticData.LoadIcon(Path.Combine("ViewTransformControls", "rotate.png"), 16, 16, theme.InvertIcons)); +#if DEBUG // when this is working (Component and ComponentPicker work), enable it. + this.Graph.RegisterOperation( + typeof(IObject3D), + typeof(ComponentEditorObject3D), + "Make Component".Localize(), + (sceneItem, scene) => + { + var selectedItem = scene.SelectedItem; + scene.SelectedItem = null; + var component = new ComponentEditorObject3D(); + component.Children.Add(selectedItem.Clone()); + component.MakeNameNonColliding(); + + scene.UndoBuffer.AddAndDo(new ReplaceCommand(new List { selectedItem }, new List { component })); + scene.SelectedItem = component; + + return Task.CompletedTask; + }, + isVisible: (sceneItem) => + { + bool noInternalComponents = sceneItem.Descendants().All((d) => !(d is ComponentObject3D) && !(d is ComponentEditorObject3D)); + return noInternalComponents; + }, + iconCollector: (theme) => AggContext.StaticData.LoadIcon("scale_32x32.png", 16, 16, theme.InvertIcons)); +#endif + this.Graph.RegisterOperation( typeof(IObject3D), typeof(ScaleObject3D), diff --git a/CustomWidgets/TreeView/TreeView.cs b/CustomWidgets/TreeView/TreeView.cs index 17fb8c951..9ab72fb25 100644 --- a/CustomWidgets/TreeView/TreeView.cs +++ b/CustomWidgets/TreeView/TreeView.cs @@ -35,6 +35,10 @@ using MatterHackers.VectorMath; namespace MatterHackers.MatterControl.CustomWidgets { + /// + /// Make this object a terminating leafe in the Design History. Do + /// not show any of its children + /// public interface IVisualLeafNode { } diff --git a/DesignTools/Obsolete/FitToBoundsObject3D.cs b/DesignTools/Obsolete/FitToBoundsObject3D.cs index 969165a3f..f1f753f65 100644 --- a/DesignTools/Obsolete/FitToBoundsObject3D.cs +++ b/DesignTools/Obsolete/FitToBoundsObject3D.cs @@ -270,13 +270,18 @@ namespace MatterHackers.MatterControl.DesignTools.Operations public void UpdateControls(PublicPropertyChange change) { - change.Context.GetEditRow(nameof(Diameter)).Visible = FitType != FitType.Box; - - change.Context.GetEditRow(nameof(Width)).Visible = FitType == FitType.Box; - change.Context.GetEditRow(nameof(Depth)).Visible = FitType == FitType.Box; - change.Context.GetEditRow(nameof(MaintainRatio)).Visible = FitType == FitType.Box; - change.Context.GetEditRow(nameof(StretchX)).Visible = FitType == FitType.Box; - change.Context.GetEditRow(nameof(StretchY)).Visible = FitType == FitType.Box; + var editRow = change.Context.GetEditRow(nameof(Diameter)); + if(editRow != null) editRow.Visible = FitType != FitType.Box; + editRow = change.Context.GetEditRow(nameof(Width)); + if (editRow != null) editRow.Visible = FitType == FitType.Box; + editRow = change.Context.GetEditRow(nameof(Depth)); + if (editRow != null) editRow.Visible = FitType == FitType.Box; + editRow = change.Context.GetEditRow(nameof(MaintainRatio)); + if (editRow != null) editRow.Visible = FitType == FitType.Box; + editRow = change.Context.GetEditRow(nameof(StretchX)); + if (editRow != null) editRow.Visible = FitType == FitType.Box; + editRow = change.Context.GetEditRow(nameof(StretchY)); + if (editRow != null) editRow.Visible = FitType == FitType.Box; } } } \ No newline at end of file diff --git a/DesignTools/Operations/AlignObject3D.cs b/DesignTools/Operations/AlignObject3D.cs index bbf38579a..251101933 100644 --- a/DesignTools/Operations/AlignObject3D.cs +++ b/DesignTools/Operations/AlignObject3D.cs @@ -386,12 +386,18 @@ namespace MatterHackers.MatterControl.DesignTools.Operations public void UpdateControls(PublicPropertyChange change) { - change.Context.GetEditRow(nameof(XAlignTo)).Visible = Advanced && XAlign != Align.Origin; - change.Context.GetEditRow(nameof(XOffset)).Visible = Advanced; - change.Context.GetEditRow(nameof(YAlignTo)).Visible = Advanced && YAlign != Align.Origin; - change.Context.GetEditRow(nameof(YOffset)).Visible = Advanced; - change.Context.GetEditRow(nameof(ZAlignTo)).Visible = Advanced && ZAlign != Align.Origin; - change.Context.GetEditRow(nameof(ZOffset)).Visible = Advanced; + var editRow = change.Context.GetEditRow(nameof(XAlignTo)); + if (editRow != null) editRow.Visible = Advanced && XAlign != Align.Origin; + editRow = change.Context.GetEditRow(nameof(XOffset)); + if (editRow != null) editRow.Visible = Advanced; + editRow = change.Context.GetEditRow(nameof(YAlignTo)); + if (editRow != null) editRow.Visible = Advanced && YAlign != Align.Origin; + editRow = change.Context.GetEditRow(nameof(YOffset)); + if (editRow != null) editRow.Visible = Advanced; + editRow = change.Context.GetEditRow(nameof(ZAlignTo)); + if (editRow != null) editRow.Visible = Advanced && ZAlign != Align.Origin; + editRow = change.Context.GetEditRow(nameof(ZOffset)); + if (editRow != null) editRow.Visible = Advanced; } private static bool IsSet(FaceAlign variableToCheck, FaceAlign faceToCheckFor, FaceAlign faceToAssertNot) diff --git a/DesignTools/Operations/ScaleObject3D.cs b/DesignTools/Operations/ScaleObject3D.cs index 1dd835106..5045dcc93 100644 --- a/DesignTools/Operations/ScaleObject3D.cs +++ b/DesignTools/Operations/ScaleObject3D.cs @@ -242,13 +242,19 @@ namespace MatterHackers.MatterControl.DesignTools.Operations public void UpdateControls(PublicPropertyChange change) { - change.Context.GetEditRow(nameof(SizeX)).Visible = Operation == ScaleType.Specify; - change.Context.GetEditRow(nameof(SizeY)).Visible = Operation == ScaleType.Specify; - change.Context.GetEditRow(nameof(SizeZ)).Visible = Operation == ScaleType.Specify; + var editRow = change.Context.GetEditRow(nameof(SizeX)); + if (editRow != null) editRow.Visible = Operation == ScaleType.Specify; + editRow = change.Context.GetEditRow(nameof(SizeY)); + if (editRow != null) editRow.Visible = Operation == ScaleType.Specify; + editRow = change.Context.GetEditRow(nameof(SizeZ)); + if (editRow != null) editRow.Visible = Operation == ScaleType.Specify; - change.Context.GetEditRow(nameof(MaitainProportions)).Visible = Operation == ScaleType.Specify; - change.Context.GetEditRow(nameof(UsePercentage)).Visible = Operation == ScaleType.Specify; - change.Context.GetEditRow(nameof(ScaleAbout)).Visible = Operation == ScaleType.Specify; + editRow = change.Context.GetEditRow(nameof(MaitainProportions)); + if (editRow != null) editRow.Visible = Operation == ScaleType.Specify; + editRow = change.Context.GetEditRow(nameof(UsePercentage)); + if (editRow != null) editRow.Visible = Operation == ScaleType.Specify; + editRow = change.Context.GetEditRow(nameof(ScaleAbout)); + if (editRow != null) editRow.Visible = Operation == ScaleType.Specify; if(change.Changed == nameof(Operation)) { diff --git a/DesignTools/Primitives/BaseObject3D.cs b/DesignTools/Primitives/BaseObject3D.cs index 6db3dd0bf..892860247 100644 --- a/DesignTools/Primitives/BaseObject3D.cs +++ b/DesignTools/Primitives/BaseObject3D.cs @@ -334,7 +334,8 @@ namespace MatterHackers.MatterControl.DesignTools public void UpdateControls(PublicPropertyChange change) { - //context.GetEditRow((this.ID, nameof(InfillAmount))).Visible = CurrentBaseType == BaseTypes.Outline; + //var editRow = context.GetEditRow((this.ID, nameof(InfillAmount))); + //if (editRow != null) editRow.Visible = CurrentBaseType == BaseTypes.Outline; } } } \ No newline at end of file diff --git a/DesignTools/Primitives/ComponentEditorObject3D.cs b/DesignTools/Primitives/ComponentEditorObject3D.cs new file mode 100644 index 000000000..6efb5533f --- /dev/null +++ b/DesignTools/Primitives/ComponentEditorObject3D.cs @@ -0,0 +1,49 @@ +/* +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.Collections.Generic; +using MatterHackers.Agg.UI; +using MatterHackers.DataConverters3D; +using MatterHackers.MatterControl.CustomWidgets; + +namespace MatterHackers.MatterControl.DesignTools +{ + public class ComponentEditorObject3D : Object3D, IVisualLeafNode + { + public ComponentEditorObject3D() + { + } + + public override void Apply(UndoBuffer undoBuffer) + { + // TODO: change this into a Component + base.Apply(undoBuffer); + } + } +} \ No newline at end of file diff --git a/DesignTools/Primitives/ComponentObject3D.cs b/DesignTools/Primitives/ComponentObject3D.cs index 12c5be56c..776cc3ce8 100644 --- a/DesignTools/Primitives/ComponentObject3D.cs +++ b/DesignTools/Primitives/ComponentObject3D.cs @@ -28,6 +28,7 @@ either expressed or implied, of the FreeBSD Project. */ using System.Collections.Generic; +using MatterHackers.Agg.UI; using MatterHackers.DataConverters3D; using MatterHackers.MatterControl.CustomWidgets; @@ -45,5 +46,11 @@ namespace MatterHackers.MatterControl.DesignTools } public List SurfacedEditors { get; set; } = new List(); + + public override void Remove(UndoBuffer undoBuffer) + { + // TODO: change this into a ComponentEditorObject3D + base.Remove(undoBuffer); + } } } \ No newline at end of file diff --git a/DesignTools/Primitives/CylinderObject3D.cs b/DesignTools/Primitives/CylinderObject3D.cs index 8dcd7b441..a6b2bd185 100644 --- a/DesignTools/Primitives/CylinderObject3D.cs +++ b/DesignTools/Primitives/CylinderObject3D.cs @@ -179,9 +179,18 @@ namespace MatterHackers.MatterControl.DesignTools public void UpdateControls(PublicPropertyChange change) { - change.Context.GetEditRow(nameof(DiameterTop)).Visible = Advanced; - change.Context.GetEditRow(nameof(StartingAngle)).Visible = Advanced; - change.Context.GetEditRow(nameof(EndingAngle)).Visible = Advanced; + if (change.Context.GetEditRow(nameof(DiameterTop)) is GuiWidget diameterWidget) + { + diameterWidget.Visible = Advanced; + } + if (change.Context.GetEditRow(nameof(StartingAngle)) is GuiWidget startingAngleWidget) + { + startingAngleWidget.Visible = Advanced; + } + if (change.Context.GetEditRow(nameof(EndingAngle)) is GuiWidget endingAngleWidget) + { + endingAngleWidget.Visible = Advanced; + } } } } \ No newline at end of file diff --git a/DesignTools/Primitives/RingObject3D.cs b/DesignTools/Primitives/RingObject3D.cs index 6009451df..37f7fb5ee 100644 --- a/DesignTools/Primitives/RingObject3D.cs +++ b/DesignTools/Primitives/RingObject3D.cs @@ -137,8 +137,10 @@ namespace MatterHackers.MatterControl.DesignTools public void UpdateControls(PublicPropertyChange change) { - change.Context.GetEditRow(nameof(StartingAngle)).Visible = Advanced; - change.Context.GetEditRow(nameof(EndingAngle)).Visible = Advanced; + var editRow = change.Context.GetEditRow(nameof(StartingAngle)); + if (editRow != null) editRow.Visible = Advanced; + editRow = change.Context.GetEditRow(nameof(EndingAngle)); + if (editRow != null) editRow.Visible = Advanced; } } } \ No newline at end of file diff --git a/DesignTools/Primitives/SphereObject3D.cs b/DesignTools/Primitives/SphereObject3D.cs index c35ebaf88..7c020f0e0 100644 --- a/DesignTools/Primitives/SphereObject3D.cs +++ b/DesignTools/Primitives/SphereObject3D.cs @@ -140,9 +140,12 @@ namespace MatterHackers.MatterControl.DesignTools public void UpdateControls(PublicPropertyChange change) { - change.Context.GetEditRow(nameof(StartingAngle)).Visible = Advanced; - change.Context.GetEditRow(nameof(EndingAngle)).Visible = Advanced; - change.Context.GetEditRow(nameof(LatitudeSides)).Visible = Advanced; + var editRow = change.Context.GetEditRow(nameof(StartingAngle)); + if (editRow != null) editRow.Visible = Advanced; + editRow = change.Context.GetEditRow(nameof(EndingAngle)); + if (editRow != null) editRow.Visible = Advanced; + editRow = change.Context.GetEditRow(nameof(LatitudeSides)); + if (editRow != null) editRow.Visible = Advanced; } } } \ No newline at end of file diff --git a/DesignTools/Primitives/TorusObject3D.cs b/DesignTools/Primitives/TorusObject3D.cs index e3172130b..e1b2d3e79 100644 --- a/DesignTools/Primitives/TorusObject3D.cs +++ b/DesignTools/Primitives/TorusObject3D.cs @@ -137,10 +137,14 @@ namespace MatterHackers.MatterControl.DesignTools public void UpdateControls(PublicPropertyChange change) { - change.Context.GetEditRow(nameof(StartingAngle)).Visible = Advanced; - change.Context.GetEditRow(nameof(EndingAngle)).Visible = Advanced; - change.Context.GetEditRow(nameof(RingSides)).Visible = Advanced; - change.Context.GetEditRow(nameof(RingPhaseAngle)).Visible = Advanced; + var editRow = change.Context.GetEditRow(nameof(StartingAngle)); + if (editRow != null) editRow.Visible = Advanced; + editRow = change.Context.GetEditRow(nameof(EndingAngle)); + if (editRow != null) editRow.Visible = Advanced; + editRow = change.Context.GetEditRow(nameof(RingSides)); + if (editRow != null) editRow.Visible = Advanced; + editRow = change.Context.GetEditRow(nameof(RingPhaseAngle)); + if (editRow != null) editRow.Visible = Advanced; } } } \ No newline at end of file diff --git a/MatterControl.csproj b/MatterControl.csproj index 284bd872e..935eec046 100644 --- a/MatterControl.csproj +++ b/MatterControl.csproj @@ -118,6 +118,7 @@ + diff --git a/Utilities/InspectForm.cs b/Utilities/InspectForm.cs index c606c7d85..7aa722d2d 100644 --- a/Utilities/InspectForm.cs +++ b/Utilities/InspectForm.cs @@ -301,6 +301,10 @@ namespace MatterHackers.MatterControl { this.InspectedObject3D = e.Node.Tag as IObject3D; this.scene.DebugItem = this.InspectedObject3D; + + var selector = string.Join(".", this.InspectedObject3D.AncestorsAndSelf().Select(o => $"Children<{o.GetType().Name.ToString()}>").Reverse().ToArray()); + Console.WriteLine(selector); + view3DWidget.Invalidate(); } diff --git a/Utilities/JsonPath.cs b/Utilities/JsonPath.cs index 303eb6bd5..0467610fb 100644 --- a/Utilities/JsonPath.cs +++ b/Utilities/JsonPath.cs @@ -366,13 +366,16 @@ namespace JsonPath // Separate member and typeFilter from member field (member, typeFilter) = StripTypeFilter(member); + //if (TryParseInt(member) is int) + //{ + // return true; + //} + // IEnumerable field must be iterated to check - if (value is IEnumerable enumerable) + if (!string.IsNullOrEmpty(typeFilter) + && GetMemberValue(value, member) is IEnumerable enumerable) { - if (TryParseInt(member) is int) - { - return true; - } + // Handle the typeFilter case foreach (var n in enumerable) @@ -382,6 +385,8 @@ namespace JsonPath return true; } } + + return false; } // TODO: Inline once troubleshooting is complete