The Curve tool can rebuild when its children change

Adding Rebuliding and Rebuild to IObject3D
This commit is contained in:
Lars Brubaker 2018-05-22 09:45:01 -07:00
parent 410c95d613
commit ca438aba4b
30 changed files with 68 additions and 46 deletions

View file

@ -31,7 +31,7 @@ using MatterHackers.Agg.UI;
namespace MatterHackers.MatterControl.DesignTools
{
public interface IRebuildable
public interface IPublicPropertyObject
{
void Rebuild(UndoBuffer undoBuffer);
}

View file

@ -42,7 +42,7 @@ using Newtonsoft.Json;
namespace MatterHackers.MatterControl.Plugins.Lithophane
{
public class LithophaneObject3D : Object3D, IRebuildable
public class LithophaneObject3D : Object3D, IPublicPropertyObject
{
[JsonIgnore]
public ImageObject3D Image => this.Children.OfType<ImageObject3D>().FirstOrDefault();

View file

@ -178,7 +178,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
}
[HideUpdateButtonAttribute]
public class Align3D : Object3D, IRebuildable, IPropertyGridModifier
public class Align3D : Object3D, IPublicPropertyObject, IPropertyGridModifier
{
// We need to serialize this so we can remove the arrange and get back to the objects before arranging
public List<Aabb> OriginalChildrenBounds = new List<Aabb>();

View file

@ -35,7 +35,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools.Operations
{
public class ArrayAdvanced3D : Object3D, IRebuildable
public class ArrayAdvanced3D : Object3D, IPublicPropertyObject
{
public ArrayAdvanced3D()
{

View file

@ -35,7 +35,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools.Operations
{
public class ArrayLinear3D : Object3D, IRebuildable
public class ArrayLinear3D : Object3D, IPublicPropertyObject
{
public ArrayLinear3D()
{

View file

@ -36,7 +36,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools.Operations
{
public class ArrayRadial3D : Object3D, IRebuildable
public class ArrayRadial3D : Object3D, IPublicPropertyObject
{
public ArrayRadial3D()
{

View file

@ -39,7 +39,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
public class CurveObject3D : MeshWrapperObject3D, IRebuildable
public class CurveObject3D : MeshWrapperObject3D, IPublicPropertyObject
{
public double Diameter { get; set; } = 0;
@ -50,8 +50,10 @@ namespace MatterHackers.MatterControl.DesignTools
{
}
public void Rebuild(UndoBuffer undoBuffer)
public override void Rebuild(UndoBuffer undoBuffer)
{
ResetMeshWrappers();
var meshWrapper = this.Descendants()
.Where((obj) => obj.OwnerID == this.ID).ToList();
@ -119,6 +121,9 @@ namespace MatterHackers.MatterControl.DesignTools
transformedMesh.CalculateNormals();
}
}
// Let the base know it needs to rebuild
base.Rebuild(undoBuffer);
}
}
}

View file

@ -46,7 +46,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
public enum MaintainRatio { None, X_Y, X_Y_Z }
[HideUpdateButtonAttribute]
public class FitToBounds3D : Object3D, IRebuildable, IEditorDraw, IPropertyGridModifier
public class FitToBounds3D : Object3D, IPublicPropertyObject, IEditorDraw, IPropertyGridModifier
{
[Description("Set the shape the part will be fit into.")]
public FitType FitType { get; set; } = FitType.Box;

View file

@ -38,7 +38,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
public class PinchObject3D : MeshWrapperObject3D, IRebuildable
public class PinchObject3D : MeshWrapperObject3D, IPublicPropertyObject
{
[DisplayName("Back Ratio")]
public double PinchRatio { get; set; } = 1;

View file

@ -38,7 +38,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
using Polygon = List<IntPoint>;
using Polygons = List<List<IntPoint>>;
public class SmoothPath : Object3D, IRebuildable
public class SmoothPath : Object3D, IPublicPropertyObject
{
public Polygons PathData;

View file

@ -43,7 +43,7 @@ namespace MatterHackers.MatterControl.DesignTools
using Polygons = List<List<IntPoint>>;
public enum BaseTypes { None, Rectangle, Circle, /* Oval, Frame,*/ Outline, };
public class BaseObject3D : Object3D, IRebuildable, IPropertyGridModifier
public class BaseObject3D : Object3D, IPublicPropertyObject, IPropertyGridModifier
{
readonly double scalingForClipper = 1000;

View file

@ -40,7 +40,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
[HideUpdateButtonAttribute]
public class ConeObject3D : Object3D, IRebuildable
public class ConeObject3D : Object3D, IPublicPropertyObject
{
public ConeObject3D()
{

View file

@ -36,7 +36,7 @@ using MatterHackers.PolygonMesh;
namespace MatterHackers.MatterControl.DesignTools
{
[HideUpdateButtonAttribute]
public class CubeObject3D : Object3D, IRebuildable
public class CubeObject3D : Object3D, IPublicPropertyObject
{
public CubeObject3D()
{

View file

@ -40,7 +40,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
[HideUpdateButtonAttribute]
public class CylinderObject3D : Object3D, IRebuildable, IPropertyGridModifier
public class CylinderObject3D : Object3D, IPublicPropertyObject, IPropertyGridModifier
{
public CylinderObject3D()
{

View file

@ -39,7 +39,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
[HideUpdateButtonAttribute]
public class HalfCylinderObject3D : Object3D, IRebuildable
public class HalfCylinderObject3D : Object3D, IPublicPropertyObject
{
public HalfCylinderObject3D()
{

View file

@ -39,7 +39,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
[HideUpdateButtonAttribute]
public class HalfSphereObject3D : Object3D, IRebuildable
public class HalfSphereObject3D : Object3D, IPublicPropertyObject
{
public HalfSphereObject3D()
{

View file

@ -39,7 +39,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
[HideUpdateButtonAttribute]
public class HalfWedgeObject3D : Object3D, IRebuildable
public class HalfWedgeObject3D : Object3D, IPublicPropertyObject
{
public HalfWedgeObject3D()
{

View file

@ -41,7 +41,7 @@ using Newtonsoft.Json;
namespace MatterHackers.MatterControl.DesignTools
{
public class ImageObject3D : AssetObject3D, IRebuildable
public class ImageObject3D : AssetObject3D, IPublicPropertyObject
{
private const double DefaultSizeMm = 60;

View file

@ -38,7 +38,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
[HideUpdateButtonAttribute]
public class PyramidObject3D : Object3D, IRebuildable
public class PyramidObject3D : Object3D, IPublicPropertyObject
{
public PyramidObject3D()
{

View file

@ -41,7 +41,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
[HideUpdateButtonAttribute]
public class RingObject3D : Object3D, IRebuildable, IPropertyGridModifier
public class RingObject3D : Object3D, IPublicPropertyObject, IPropertyGridModifier
{
public RingObject3D()
{

View file

@ -39,7 +39,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
[HideUpdateButtonAttribute]
public class SphereObject3D : Object3D, IRebuildable, IPropertyGridModifier
public class SphereObject3D : Object3D, IPublicPropertyObject, IPropertyGridModifier
{
public SphereObject3D()
{

View file

@ -44,7 +44,7 @@ using Newtonsoft.Json.Converters;
namespace MatterHackers.MatterControl.DesignTools
{
public class TextObject3D : Object3D, IRebuildable
public class TextObject3D : Object3D, IPublicPropertyObject
{
public TextObject3D()
{
@ -85,7 +85,7 @@ namespace MatterHackers.MatterControl.DesignTools
undoBuffer.AddAndDo(new ReplaceCommand(new List<IObject3D> { this }, new List<IObject3D> { newContainer }));
}
public void Rebuild(UndoBuffer undoBuffer)
public override void Rebuild(UndoBuffer undoBuffer)
{
var aabb = this.GetAxisAlignedBoundingBox();
@ -120,6 +120,9 @@ namespace MatterHackers.MatterControl.DesignTools
// If the part was already created and at a height, maintain the height.
PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z);
}
// Let the base know it needs to rebuild
base.Rebuild(undoBuffer);
}
}
}

View file

@ -41,7 +41,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
[HideUpdateButtonAttribute]
public class TorusObject3D : Object3D, IRebuildable, IPropertyGridModifier
public class TorusObject3D : Object3D, IPublicPropertyObject, IPropertyGridModifier
{
public TorusObject3D()
{

View file

@ -39,7 +39,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
[HideUpdateButtonAttribute]
public class WedgeObject3D : Object3D, IRebuildable
public class WedgeObject3D : Object3D, IPublicPropertyObject
{
public WedgeObject3D()
{

View file

@ -80,7 +80,7 @@ namespace MatterHackers.MatterControl.DesignTools
public bool Unlocked { get; } = true;
public IEnumerable<Type> SupportedTypes() => new Type[] { typeof(IRebuildable) };
public IEnumerable<Type> SupportedTypes() => new Type[] { typeof(IPublicPropertyObject) };
private static Type[] allowedTypes =
{
@ -160,7 +160,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
var undoBuffer = view3DWidget.sceneContext.Scene.UndoBuffer;
var rebuildable = context.item as IRebuildable;
var rebuildable = context.item as IPublicPropertyObject;
var propertyGridModifier = context.item as IPropertyGridModifier;
var editableProperties = GetEditablePropreties(context.item);
@ -192,7 +192,7 @@ namespace MatterHackers.MatterControl.DesignTools
private static void AddPropertyEditor(PublicPropertyEditor publicPropertyEditor,
View3DWidget view3DWidget, FlowLayoutWidget editControlsContainer, ThemeConfig theme,
UndoBuffer undoBuffer, IRebuildable rebuildable, IPropertyGridModifier propertyGridModifier,
UndoBuffer undoBuffer, IPublicPropertyObject rebuildable, IPropertyGridModifier propertyGridModifier,
EditableProperty property, PPEContext context)
{
GuiWidget rowContainer = null;
@ -538,7 +538,7 @@ namespace MatterHackers.MatterControl.DesignTools
}
}
private static GuiWidget CreateEnumEditor(PPEContext context, IRebuildable item,
private static GuiWidget CreateEnumEditor(PPEContext context, IPublicPropertyObject item,
EditableProperty property, Type propertyType, object value, string displayName,
ThemeConfig theme,
UndoBuffer undoBuffer)

View file

@ -82,6 +82,7 @@
<Compile Include="CustomWidgets\TreeView\TreeNode.cs" />
<Compile Include="CustomWidgets\TreeView\TreeView.cs" />
<Compile Include="DesignTools\Attributes\ShowSearchFieldAttribute.cs" />
<Compile Include="DesignTools\Interfaces\IPublicPropertyObject.cs" />
<Compile Include="DesignTools\Primitives\HalfCylinderObject3D.cs" />
<Compile Include="DesignTools\Primitives\HalfWedgeObject3D.cs" />
<Compile Include="Library\Providers\MatterControl\LibraryCollectionContainer.cs" />
@ -124,7 +125,6 @@
<Compile Include="DesignTools\Attributes\WebPageLinkAttribute.cs" />
<Compile Include="DesignTools\Interfaces\IEditorDraw.cs" />
<Compile Include="DesignTools\Interfaces\IPropertyGridModifier.cs" />
<Compile Include="DesignTools\Interfaces\IRebuildable.cs" />
<Compile Include="DesignTools\Lithophane.cs" />
<Compile Include="DesignTools\Operations\Align3D.cs" />
<Compile Include="DesignTools\Operations\ArrayAdvanced3D.cs" />

View file

@ -27,11 +27,13 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.DataConverters3D.UndoCommands;
using MatterHackers.MatterControl.DesignTools.Operations;
using MatterHackers.PolygonMesh;
namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
@ -57,7 +59,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
{
child.OutputType = PrintOutputTypes.Default;
}
// collapes our children into our parent
// collapse our children into our parent
base.Remove(undoBuffer);
}
@ -89,9 +92,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
public static void WrapSelection(MeshWrapperObject3D meshWrapper, InteractiveScene scene)
{
if (scene.HasSelection)
var selectedItem = scene.SelectedItem;
if (selectedItem != null)
{
var selectedItem = scene.SelectedItem;
scene.SelectedItem = null;
List<IObject3D> originalItems;
@ -130,29 +133,40 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
}
});
AddMeshWrapperToAllChildren();
}
private void AddMeshWrapperToAllChildren()
{
// Wrap every first descendant that has a mesh
foreach (var child in this.VisibleMeshes().ToList())
{
// wrap the child
child.object3D.Parent.Children.Modify((list) =>
if (child.object3D.OwnerID != this.ID)
{
list.Remove(child.object3D);
list.Add(new MeshWrapper(child.object3D, this.ID));
});
// wrap the child
child.object3D.Parent.Children.Modify((list) =>
{
list.Remove(child.object3D);
list.Add(new MeshWrapper(child.object3D, this.ID));
});
}
}
}
public void ResetMeshWrappers()
{
// if there are not already, wrap all meshes with our id (some inner object may have changed it's meshes)
AddMeshWrapperToAllChildren();
this.Mesh = null;
var participants = this.Descendants().Where(o => o.OwnerID == this.ID).ToList();
foreach (var item in participants)
{
item.Visible = true;
var firstChild = item.Children.First();
// set the mesh back to the child mesh
item.Mesh = item.Children.First().Mesh;
// and set the color back
item.Color = item.Children.First().Color;
item.Mesh = firstChild.Mesh;
// and reset the properties
firstChild.CopyProperties(firstChild);
}
}
}

@ -1 +1 @@
Subproject commit e89443cc472308fcbf407581d30f358c557a7394
Subproject commit 5c85549d073d6a033a26875289a01ad26ff3909c

View file

@ -45,7 +45,7 @@ using Newtonsoft.Json.Converters;
namespace MatterHackers.MatterControl.DesignTools
{
[WebPageLink("About Braille", "https://en.wikipedia.org/wiki/Braille")]
public class BrailleCardObject3D : Object3D, IRebuildable
public class BrailleCardObject3D : Object3D, IPublicPropertyObject
{
public BrailleCardObject3D()
{

View file

@ -45,7 +45,7 @@ using Newtonsoft.Json.Converters;
namespace MatterHackers.MatterControl.DesignTools
{
[WebPageLink("About Braille", "https://en.wikipedia.org/wiki/Braille")]
public class BrailleObject3D : Object3D, IRebuildable
public class BrailleObject3D : Object3D, IPublicPropertyObject
{
public BrailleObject3D()
{