Working on fit to bounds having radial option (image coin support)

Make default names and colors for all primitives
Improving public property editor context so we can show many at the same time
fixed spelling
This commit is contained in:
Lars Brubaker 2018-05-02 10:59:08 -07:00
parent f5d8c448fe
commit 27b1e31ac5
26 changed files with 223 additions and 302 deletions

View file

@ -594,22 +594,6 @@ namespace MatterHackers.MatterControl
#if DEBUG // keep this work in progress to the editor for now
new SceneSelectionSeparator(),
new SceneSelectionOperation()
{
TitleResolver = () => "Package".Localize(),
Action = (scene) =>
{
var selectedItem = scene.SelectedItem;
scene.SelectedItem = null;
var package = Package3D.Create(selectedItem.Clone());
package.MakeNameNonColliding();
scene.UndoBuffer.AddAndDo(new ReplaceCommand(new List<IObject3D> { selectedItem }, new List<IObject3D> { package }));
scene.SelectedItem = package;
},
IsEnabled = (scene) => scene.HasSelection,
},
new SceneSelectionOperation()
{
TitleResolver = () => "Bend".Localize(),
Action = (scene) => new BendObject3D(scene.SelectedItem),

View file

@ -17,7 +17,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
#region JSON data
public List<Vector3> SampledPositions = new List<Vector3>();
public LevelingSystem LevelingSystem;
public DateTime CreationData;
public DateTime CreationDate;
public double BedTemperature;
#endregion

View file

@ -61,7 +61,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
}
levelingData.LevelingSystem = printer.Settings.GetValue<LevelingSystem>(SettingsKey.print_leveling_solution);
levelingData.CreationData = DateTime.Now;
levelingData.CreationDate = DateTime.Now;
// record the temp the bed was when we measured it (or 0 if no heated bed)
levelingData.BedTemperature = printer.Settings.GetValue<bool>(SettingsKey.has_heated_bed) ?
printer.Settings.GetValue<double>(SettingsKey.bed_temperature)

View file

@ -27,11 +27,33 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.MatterControl.PartPreviewWindow;
using System.Collections.Generic;
namespace MatterHackers.MatterControl.DesignTools
{
public class PPEContext
{
public IObject3D item { get; set; }
public View3DWidget view3DWidget { get; set; }
public Dictionary<string, GuiWidget> editRows { get; private set; } = new Dictionary<string, GuiWidget>();
public GuiWidget GetEditRow(string propertyName)
{
GuiWidget value;
if (editRows.TryGetValue(propertyName, out value))
{
return value;
}
return null;
}
}
public interface IPropertyGridModifier
{
void UpdateControls(PublicPropertyEditor editor);
void UpdateControls(PPEContext editor);
}
}

View file

@ -38,12 +38,13 @@ using MatterHackers.Localizations;
using MatterHackers.MatterControl.DesignTools;
using MatterHackers.MatterControl.PartPreviewWindow;
using MatterHackers.VectorMath;
using Newtonsoft.Json;
namespace MatterHackers.MatterControl.Plugins.Lithophane
{
public class LithophaneObject3D : Object3D, IRebuildable
{
[IObject3DComponent]
[JsonIgnore]
public ImageObject3D Image => this.Children.OfType<ImageObject3D>().FirstOrDefault();
[DisplayName("Pixels Per mm"), Range(0.5, 3, ErrorMessage = "Value for {0} must be between {1} and {2}.")]

View file

@ -421,14 +421,14 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
base.Remove();
}
public void UpdateControls(PublicPropertyEditor editor)
public void UpdateControls(PPEContext context)
{
editor.GetEditRow((this.ID, nameof(XAlignTo))).Visible = Advanced && XAlign != Align.Origin;
editor.GetEditRow((this.ID, nameof(XOffset))).Visible = Advanced;
editor.GetEditRow((this.ID, nameof(YAlignTo))).Visible = Advanced && YAlign != Align.Origin;
editor.GetEditRow((this.ID, nameof(YOffset))).Visible = Advanced;
editor.GetEditRow((this.ID, nameof(ZAlignTo))).Visible = Advanced && ZAlign != Align.Origin;
editor.GetEditRow((this.ID, nameof(ZOffset))).Visible = Advanced;
context.GetEditRow(nameof(XAlignTo)).Visible = Advanced && XAlign != Align.Origin;
context.GetEditRow(nameof(XOffset)).Visible = Advanced;
context.GetEditRow(nameof(YAlignTo)).Visible = Advanced && YAlign != Align.Origin;
context.GetEditRow(nameof(YOffset)).Visible = Advanced;
context.GetEditRow(nameof(ZAlignTo)).Visible = Advanced && ZAlign != Align.Origin;
context.GetEditRow(nameof(ZOffset)).Visible = Advanced;
}
private static bool IsSet(Face variableToCheck, Face faceToCheckFor, Face faceToAssertNot)

View file

@ -28,8 +28,9 @@ either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.Drawing;
using System.ComponentModel;
using System.Linq;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.MatterControl.PartPreviewWindow;
@ -40,15 +41,22 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools.Operations
{
public enum FitType { Box, Cylinder }
public enum MaintainRatio { None, X_Y, X_Y_Z }
public class FitToBounds3D : Object3D, IRebuildable, IEditorDraw
[HideUpdateButtonAttribute]
public class FitToBounds3D : Object3D, IRebuildable, IEditorDraw, IPropertyGridModifier
{
public FitType FitType { get; set; } = FitType.Box;
public double Width { get; set; }
public double Diameter { get; set ; }
public double Depth { get; set; }
public double Height { get; set; }
public MaintainRatio MaintainRatio { get; set; } = MaintainRatio.X_Y;
[Description("Allows you turn turn on and off applying the fit to the x axis.")]
public bool StretchX { get; set; } = true;
public bool StretchY { get; set; } = true;
public bool StretchZ { get; set; } = true;
@ -110,6 +118,8 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
fitToBounds.Depth = aabb.YSize;
fitToBounds.Height = aabb.ZSize;
fitToBounds.Diameter = aabb.XSize;
var scaleItem = new Object3D();
fitToBounds.Children.Add(scaleItem);
scaleItem.Children.Add(itemToFit);
@ -164,27 +174,80 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
scale.Z = minXyz;
break;
}
ScaleItem.Matrix = Object3DExtensions.ApplyAtPosition(ScaleItem.Matrix, Matrix4X4.CreateScale(scale), aabb.Center);
}
public void DrawEditor(object sender, DrawEventArgs e)
{
if (sender is InteractionLayer layer
&& layer.Scene.SelectedItem == this)
&& layer.Scene.SelectedItem != null
&& layer.Scene.SelectedItem.DescendantsAndSelf().Where((i) => i == this).Any())
{
var aabb = ItemToScale.GetAxisAlignedBoundingBox();
var center = aabb.Center;
var worldMatrix = this.WorldMatrix();
var minXyz = center - new Vector3(Width / 2, Depth / 2, Height / 2);
var maxXyz = center + new Vector3(Width / 2, Depth / 2, Height / 2);
var bounds = new AxisAlignedBoundingBox(minXyz, maxXyz);
//var leftW = Vector3.Transform(, worldMatrix);
var right = Vector3.Transform(center + new Vector3(Width / 2, 0, 0), worldMatrix);
// GLHelper.Render3DLine(layer.World, left, right, Agg.Color.Red);
layer.World.RenderAabb(bounds, worldMatrix, Agg.Color.Red, 1);
if (FitType == FitType.Box)
{
var aabb = ItemToScale.GetAxisAlignedBoundingBox();
var center = aabb.Center;
var worldMatrix = this.WorldMatrix();
var minXyz = center - new Vector3(Width / 2, Depth / 2, Height / 2);
var maxXyz = center + new Vector3(Width / 2, Depth / 2, Height / 2);
var bounds = new AxisAlignedBoundingBox(minXyz, maxXyz);
//var leftW = Vector3.Transform(, worldMatrix);
var right = Vector3.Transform(center + new Vector3(Width / 2, 0, 0), worldMatrix);
// GLHelper.Render3DLine(layer.World, left, right, Agg.Color.Red);
layer.World.RenderAabb(bounds, worldMatrix, Agg.Color.Red, 1, 1);
}
else
{
RenderCylinderOutline(layer.World, Color.Red, 1, 1);
}
// turn the lighting back on
GL.Enable(EnableCap.Lighting);
}
}
public void RenderCylinderOutline(WorldView world, Color color, double lineWidth, double extendLineLength)
{
var aabb = ItemToScale.GetAxisAlignedBoundingBox();
var center = aabb.Center;
center.Z = 0;
var worldMatrix = this.WorldMatrix();
GLHelper.PrepareFor3DLineRender(true);
Frustum frustum = world.GetClippingFrustum();
int sides = 30;
for (int i=0; i<sides; i++)
{
var rotatedPoint = new Vector3(Math.Cos(MathHelper.Tau * i / sides), Math.Sin(MathHelper.Tau * i / sides), 0) * Diameter / 2;
var sideTop = Vector3.Transform(center + rotatedPoint + new Vector3(0, 0, aabb.minXYZ.Z + Height), worldMatrix);
var sideBottom = Vector3.Transform(center + rotatedPoint + new Vector3(0, 0, aabb.minXYZ.Z), worldMatrix);
var rotated2Point = new Vector3(Math.Cos(MathHelper.Tau * (i + 1) / sides), Math.Sin(MathHelper.Tau * (i + 1) / sides), 0) * Diameter / 2;
var topStart = sideTop;
var topEnd = Vector3.Transform(center + rotated2Point + new Vector3(0, 0, aabb.minXYZ.Z + Height), worldMatrix);
var bottomStart = sideBottom;
var bottomEnd = Vector3.Transform(center + rotated2Point + new Vector3(0, 0, aabb.minXYZ.Z), worldMatrix);
if (extendLineLength > 0)
{
GLHelper.ExtendLineEnds(ref sideTop, ref sideBottom, extendLineLength);
}
GLHelper.Render3DLineNoPrep(world, frustum, sideTop, sideBottom, color, lineWidth);
GLHelper.Render3DLineNoPrep(world, frustum, topStart, topEnd, color, lineWidth);
GLHelper.Render3DLineNoPrep(world, frustum, bottomStart, bottomEnd, color, lineWidth);
}
}
public void UpdateControls(PPEContext context)
{
context.GetEditRow(nameof(Diameter)).Visible = FitType != FitType.Box;
context.GetEditRow(nameof(Width)).Visible = FitType == FitType.Box;
context.GetEditRow(nameof(Depth)).Visible = FitType == FitType.Box;
context.GetEditRow(nameof(MaintainRatio)).Visible = FitType == FitType.Box;
context.GetEditRow(nameof(StretchX)).Visible = FitType == FitType.Box;
context.GetEditRow(nameof(StretchY)).Visible = FitType == FitType.Box;
}
}
}

View file

@ -1,95 +0,0 @@
/*
Copyright (c) 2018, Lars Brubaker
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 MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace MatterHackers.MatterControl.DesignTools.Operations
{
public class Package3D : Object3D, IRebuildable
{
public Package3D()
{
}
[JsonIgnore]
private SubProperties _subProperties = new SubProperties();
[JsonIgnore]
public SubProperties LiftedProperties
{
get
{
_subProperties.Items.Clear();
foreach (var child in this.Descendants<TextObject3D>())
{
PropertyInfo propertyToEdit = child.GetType().GetProperties().First();
_subProperties.Items.Add(new EditableProperty(propertyToEdit, child));
}
return _subProperties;
}
set
{
// only here so it will show up in PublicPropertyEditor
}
}
public static Package3D Create(IObject3D itemToPackage)
{
Package3D package = new Package3D();
package.Children.Add(itemToPackage);
return package;
}
public void Rebuild(UndoBuffer undoBuffer)
{
foreach (var child in this.Descendants<TextObject3D>())
{
child.Rebuild(null);
foreach (var parent in child.Parents<IObject3D>())
{
if (parent is IRebuildable rebuildable
&& parent != this)
{
rebuildable.Rebuild(null);
}
}
}
return;
}
}
}

View file

@ -225,9 +225,9 @@ namespace MatterHackers.MatterControl.DesignTools
return solution;
}
public void UpdateControls(PublicPropertyEditor editor)
public void UpdateControls(PPEContext context)
{
//editor.GetEditRow((this.ID, nameof(InfillAmount))).Visible = CurrentBaseType == BaseTypes.Outline;
//context.GetEditRow((this.ID, nameof(InfillAmount))).Visible = CurrentBaseType == BaseTypes.Outline;
}
}
}

View file

@ -33,6 +33,7 @@ using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.PolygonMesh;
using MatterHackers.VectorMath;
@ -43,6 +44,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
public ConeObject3D()
{
Name = "Cone".Localize();
Color = ApplicationController.Instance.PrimitiveColors["Cone"];
}

View file

@ -30,6 +30,7 @@ either expressed or implied, of the FreeBSD Project.
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.PolygonMesh;
namespace MatterHackers.MatterControl.DesignTools
@ -39,9 +40,12 @@ namespace MatterHackers.MatterControl.DesignTools
{
public CubeObject3D()
{
Name = "Cylinder".Localize();
Color = ApplicationController.Instance.PrimitiveColors["Cube"];
}
public CubeObject3D(double width, double depth, double height)
: this()
{
Width = width;
Depth = depth;
@ -55,10 +59,7 @@ namespace MatterHackers.MatterControl.DesignTools
public static CubeObject3D Create()
{
var item = new CubeObject3D()
{
Color = ApplicationController.Instance.PrimitiveColors["Cube"]
};
var item = new CubeObject3D();
item.Rebuild(null);
return item;
}

View file

@ -32,6 +32,7 @@ using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DesignTools.Operations;
using MatterHackers.PolygonMesh;
using MatterHackers.VectorMath;
@ -43,11 +44,12 @@ namespace MatterHackers.MatterControl.DesignTools
{
public CylinderObject3D()
{
Name = "Cylinder".Localize();
Color = ApplicationController.Instance.PrimitiveColors["Cylinder"];
}
public CylinderObject3D(double diameter, double height, int sides)
: base()
: this()
{
Diameter = diameter;
Height = height;
@ -151,11 +153,11 @@ namespace MatterHackers.MatterControl.DesignTools
}
}
public void UpdateControls(PublicPropertyEditor editor)
public void UpdateControls(PPEContext context)
{
editor.GetEditRow((this.ID, nameof(DiameterTop))).Visible = Advanced;
editor.GetEditRow((this.ID, nameof(StartingAngle))).Visible = Advanced;
editor.GetEditRow((this.ID, nameof(EndingAngle))).Visible = Advanced;
context.GetEditRow(nameof(DiameterTop)).Visible = Advanced;
context.GetEditRow(nameof(StartingAngle)).Visible = Advanced;
context.GetEditRow(nameof(EndingAngle)).Visible = Advanced;
}
}
}

View file

@ -33,6 +33,7 @@ using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
@ -42,6 +43,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
public HalfCylinderObject3D()
{
Name = "Half Cylinder".Localize();
Color = ApplicationController.Instance.PrimitiveColors["HalfCylinder"];
}

View file

@ -33,6 +33,7 @@ using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
@ -42,6 +43,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
public HalfSphereObject3D()
{
Name = "Half Sphere".Localize();
Color = ApplicationController.Instance.PrimitiveColors["HalfSphere"];
}

View file

@ -33,6 +33,7 @@ using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
@ -42,6 +43,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
public HalfWedgeObject3D()
{
Name = "Half Wedge".Localize();
Color = ApplicationController.Instance.PrimitiveColors["HalfWedge"];
}

View file

@ -32,6 +32,7 @@ using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
@ -41,6 +42,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
public PyramidObject3D()
{
Name = "Pyriamid".Localize();
Color = ApplicationController.Instance.PrimitiveColors["Pyramid"];
}

View file

@ -34,6 +34,7 @@ using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.PolygonMesh;
using MatterHackers.VectorMath;
@ -44,10 +45,12 @@ namespace MatterHackers.MatterControl.DesignTools
{
public RingObject3D()
{
Name = "Ring".Localize();
Color = ApplicationController.Instance.PrimitiveColors["Ring"];
}
public RingObject3D(double outerDiameter, double innerDiameter, double height, int sides)
: this()
{
this.OuterDiameter = outerDiameter;
this.InnerDiameter = innerDiameter;
@ -105,10 +108,10 @@ namespace MatterHackers.MatterControl.DesignTools
}
}
public void UpdateControls(PublicPropertyEditor editor)
public void UpdateControls(PPEContext context)
{
editor.GetEditRow((this.ID, nameof(StartingAngle))).Visible = Advanced;
editor.GetEditRow((this.ID, nameof(EndingAngle))).Visible = Advanced;
context.GetEditRow(nameof(StartingAngle)).Visible = Advanced;
context.GetEditRow(nameof(EndingAngle)).Visible = Advanced;
InnerDiameter = Math.Min(OuterDiameter - .1, InnerDiameter);
}
}

View file

@ -33,6 +33,7 @@ using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
@ -42,10 +43,12 @@ namespace MatterHackers.MatterControl.DesignTools
{
public SphereObject3D()
{
Name = "Sphere".Localize();
Color = ApplicationController.Instance.PrimitiveColors["Sphere"];
}
public SphereObject3D(double diameter, int sides)
: this()
{
Diameter = diameter;
Sides = sides;
@ -108,11 +111,11 @@ namespace MatterHackers.MatterControl.DesignTools
}
}
public void UpdateControls(PublicPropertyEditor editor)
public void UpdateControls(PPEContext context)
{
editor.GetEditRow((this.ID, nameof(StartingAngle))).Visible = Advanced;
editor.GetEditRow((this.ID, nameof(EndingAngle))).Visible = Advanced;
editor.GetEditRow((this.ID, nameof(LatitudeSides))).Visible = Advanced;
context.GetEditRow(nameof(StartingAngle)).Visible = Advanced;
context.GetEditRow(nameof(EndingAngle)).Visible = Advanced;
context.GetEditRow(nameof(LatitudeSides)).Visible = Advanced;
}
}
}

View file

@ -34,6 +34,7 @@ using MatterHackers.Agg.Transform;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.VectorMath;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
@ -74,6 +75,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
public TextObject3D()
{
Name = "Text".Localize();
Color = ApplicationController.Instance.PrimitiveColors["Text"];
}

View file

@ -34,6 +34,7 @@ using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.PolygonMesh;
using MatterHackers.VectorMath;
@ -44,6 +45,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
public TorusObject3D()
{
Name = "Torus".Localize();
Color = ApplicationController.Instance.PrimitiveColors["Torus"];
}
@ -109,12 +111,12 @@ namespace MatterHackers.MatterControl.DesignTools
}
}
public void UpdateControls(PublicPropertyEditor editor)
public void UpdateControls(PPEContext context)
{
editor.GetEditRow((this.ID, nameof(StartingAngle))).Visible = Advanced;
editor.GetEditRow((this.ID, nameof(EndingAngle))).Visible = Advanced;
editor.GetEditRow((this.ID, nameof(RingSides))).Visible = Advanced;
editor.GetEditRow((this.ID, nameof(RingPhaseAngle))).Visible = Advanced;
context.GetEditRow(nameof(StartingAngle)).Visible = Advanced;
context.GetEditRow(nameof(EndingAngle)).Visible = Advanced;
context.GetEditRow(nameof(RingSides)).Visible = Advanced;
context.GetEditRow(nameof(RingPhaseAngle)).Visible = Advanced;
InnerDiameter = Math.Min(OuterDiameter - .1, InnerDiameter);
}
}

View file

@ -33,6 +33,7 @@ using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
@ -42,6 +43,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
public WedgeObject3D()
{
Name = "Wedge".Localize();
Color = ApplicationController.Instance.PrimitiveColors["Wedge"];
}

View file

@ -74,44 +74,30 @@ namespace MatterHackers.MatterControl.DesignTools
public Type PropertyType => PropertyInfo.PropertyType;
}
public class SubProperties
{
public List<EditableProperty> Items = new List<EditableProperty>();
public virtual IEnumerable<EditableProperty> GetProperties()
{
foreach (var item in Items)
{
yield return item;
}
}
}
public class PublicPropertyEditor : IObject3DEditor
{
private IObject3D item;
private View3DWidget view3DWidget;
public string Name => "Property Editor";
public bool Unlocked { get; } = true;
public IEnumerable<Type> SupportedTypes() => new Type[] { typeof(IRebuildable) };
private Dictionary<(string id, string propertyName), GuiWidget> editRows = new Dictionary<(string id, string propertyName), GuiWidget>();
private static Type[] allowedTypes =
{
typeof(double), typeof(int), typeof(char), typeof(string), typeof(bool),
typeof(Vector2), typeof(Vector3),
typeof(DirectionVector), typeof(DirectionAxis),
typeof(ImageObject3D), typeof(SubProperties)
typeof(DirectionVector), typeof(DirectionAxis)
};
public const BindingFlags OwnedPropertiesOnly = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly;
public GuiWidget Create(IObject3D item, View3DWidget view3DWidget, ThemeConfig theme)
{
this.view3DWidget = view3DWidget;
this.item = item;
var context = new PPEContext()
{
view3DWidget = view3DWidget,
item = item
};
var mainContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
{
@ -127,25 +113,14 @@ namespace MatterHackers.MatterControl.DesignTools
};
}
if (this.item != null)
if (context.item != null)
{
this.CreateEditor(view3DWidget, mainContainer, theme);
this.CreateEditor(context, view3DWidget, mainContainer, theme);
}
return mainContainer;
}
public GuiWidget GetEditRow((string id, string propertyName) key)
{
GuiWidget value;
if (editRows.TryGetValue(key, out value))
{
return value;
}
return null;
}
private static FlowLayoutWidget CreateSettingsRow(string labelText, string toolTipText = null)
{
var rowContainer = new FlowLayoutWidget(FlowDirection.LeftToRight)
@ -176,25 +151,24 @@ namespace MatterHackers.MatterControl.DesignTools
.Select(p => new EditableProperty(p, item));
}
private void CreateEditor(View3DWidget view3DWidget, FlowLayoutWidget editControlsContainer, ThemeConfig theme)
private void CreateEditor(PPEContext context, View3DWidget view3DWidget, FlowLayoutWidget editControlsContainer, ThemeConfig theme)
{
var undoBuffer = view3DWidget.sceneContext.Scene.UndoBuffer;
editRows.Clear();
var rebuildable = item as IRebuildable;
var propertyGridModifier = item as IPropertyGridModifier;
var rebuildable = context.item as IRebuildable;
var propertyGridModifier = context.item as IPropertyGridModifier;
var editableProperties = GetEditablePropreties(item);
var editableProperties = GetEditablePropreties(context.item);
AddWebPageLinkIfRequired(editControlsContainer, theme);
AddUnlockLinkIfRequired(editControlsContainer, theme);
AddWebPageLinkIfRequired(context, editControlsContainer, theme);
AddUnlockLinkIfRequired(context, editControlsContainer, theme);
foreach (var property in editableProperties)
{
AddPropertyEditor(this, view3DWidget, editControlsContainer, theme, undoBuffer, rebuildable, propertyGridModifier, property, editRows);
AddPropertyEditor(this, view3DWidget, editControlsContainer, theme, undoBuffer, rebuildable, propertyGridModifier, property, context);
}
var hideUpdate = item.GetType().GetCustomAttributes(typeof(HideUpdateButtonAttribute), true).FirstOrDefault() as HideUpdateButtonAttribute;
var hideUpdate = context.item.GetType().GetCustomAttributes(typeof(HideUpdateButtonAttribute), true).FirstOrDefault() as HideUpdateButtonAttribute;
if (hideUpdate == null)
{
var updateButton = theme.ButtonFactory.Generate("Update".Localize());
@ -208,13 +182,13 @@ namespace MatterHackers.MatterControl.DesignTools
}
// make sure the ui is set right to start
propertyGridModifier?.UpdateControls(this);
propertyGridModifier?.UpdateControls(context);
}
private static void AddPropertyEditor(PublicPropertyEditor publicPropertyEditor,
View3DWidget view3DWidget, FlowLayoutWidget editControlsContainer, ThemeConfig theme,
UndoBuffer undoBuffer, IRebuildable rebuildable, IPropertyGridModifier propertyGridModifier,
EditableProperty property, Dictionary<(string id, string propertyName), GuiWidget> editRows)
EditableProperty property, PPEContext context)
{
GuiWidget rowContainer = null;
@ -230,22 +204,12 @@ namespace MatterHackers.MatterControl.DesignTools
{
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { field.DoubleValue });
rebuildable?.Rebuild(undoBuffer);
propertyGridModifier?.UpdateControls(publicPropertyEditor);
propertyGridModifier?.UpdateControls(context);
};
rowContainer.AddChild(field.Content);
editControlsContainer.AddChild(rowContainer);
}
else if (property.Value is SubProperties subProperties)
{
foreach(var subProperty in subProperties.GetProperties())
{
AddPropertyEditor(publicPropertyEditor, view3DWidget, editControlsContainer, theme, undoBuffer,
rebuildable, propertyGridModifier, subProperty, editRows);
}
// don't add a row, they were added for the individual properties
return;
}
else if (property.Value is Vector2 vector2)
{
rowContainer = CreateSettingsRow(property.DisplayName.Localize());
@ -257,7 +221,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { field.Vector2 });
rebuildable?.Rebuild(undoBuffer);
propertyGridModifier?.UpdateControls(publicPropertyEditor);
propertyGridModifier?.UpdateControls(context);
};
rowContainer.AddChild(field.Content);
@ -274,7 +238,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { field.Vector3 });
rebuildable?.Rebuild(undoBuffer);
propertyGridModifier?.UpdateControls(publicPropertyEditor);
propertyGridModifier?.UpdateControls(context);
};
rowContainer.AddChild(field.Content);
@ -315,7 +279,7 @@ namespace MatterHackers.MatterControl.DesignTools
}
rebuildable?.Rebuild(undoBuffer);
propertyGridModifier?.UpdateControls(publicPropertyEditor);
propertyGridModifier?.UpdateControls(context);
};
}
@ -334,7 +298,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { new DirectionVector() { Normal = field.Vector3 } });
rebuildable?.Rebuild(undoBuffer);
propertyGridModifier?.UpdateControls(publicPropertyEditor);
propertyGridModifier?.UpdateControls(context);
};
rowContainer.AddChild(field.Content);
@ -365,7 +329,7 @@ namespace MatterHackers.MatterControl.DesignTools
}
});
rebuildable?.Rebuild(undoBuffer);
propertyGridModifier?.UpdateControls(publicPropertyEditor);
propertyGridModifier?.UpdateControls(context);
};
rowContainer.AddChild(field.Content);
@ -399,7 +363,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { new DirectionAxis() { Origin = originField.Vector3, Normal = normalField.Vector3 } });
rebuildable?.Rebuild(undoBuffer);
propertyGridModifier?.UpdateControls(publicPropertyEditor);
propertyGridModifier?.UpdateControls(context);
};
originRowContainer.AddChild(originField.Content);
@ -412,7 +376,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { new DirectionAxis() { Origin = originField.Vector3, Normal = normalField.Vector3 } });
rebuildable?.Rebuild(undoBuffer);
propertyGridModifier?.UpdateControls(publicPropertyEditor);
propertyGridModifier?.UpdateControls(context);
};
directionRowContainer.AddChild(normalField.Content);
@ -442,7 +406,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { field.IntValue });
rebuildable?.Rebuild(undoBuffer);
propertyGridModifier?.UpdateControls(publicPropertyEditor);
propertyGridModifier?.UpdateControls(context);
};
rowContainer.AddChild(field.Content);
@ -460,7 +424,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { field.Checked });
rebuildable?.Rebuild(undoBuffer);
propertyGridModifier?.UpdateControls(publicPropertyEditor);
propertyGridModifier?.UpdateControls(context);
};
rowContainer.AddChild(field.Content);
@ -479,7 +443,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { textEditWidget.Text });
rebuildable?.Rebuild(undoBuffer);
propertyGridModifier?.UpdateControls(publicPropertyEditor);
propertyGridModifier?.UpdateControls(context);
};
rowContainer.AddChild(textEditWidget);
editControlsContainer.AddChild(rowContainer);
@ -505,7 +469,7 @@ namespace MatterHackers.MatterControl.DesignTools
}
property.PropertyInfo.GetSetMethod().Invoke(property.Item, new Object[] { textEditWidget.Text[0] });
rebuildable?.Rebuild(undoBuffer);
propertyGridModifier?.UpdateControls(publicPropertyEditor);
propertyGridModifier?.UpdateControls(context);
};
rowContainer.AddChild(textEditWidget);
editControlsContainer.AddChild(rowContainer);
@ -513,7 +477,7 @@ namespace MatterHackers.MatterControl.DesignTools
// create an enum editor
else if (property.PropertyType.IsEnum)
{
rowContainer = CreateEnumEditor(publicPropertyEditor, rebuildable,
rowContainer = CreateEnumEditor(context, rebuildable,
property, property.PropertyType, property.Value, property.DisplayName,
theme, undoBuffer);
editControlsContainer.AddChild(rowContainer);
@ -527,17 +491,17 @@ namespace MatterHackers.MatterControl.DesignTools
}
// remember the row name and widget
editRows.Add((property.Item.ID, property.PropertyInfo.Name), rowContainer);
context.editRows.Add(property.PropertyInfo.Name, rowContainer);
}
private void AddUnlockLinkIfRequired(FlowLayoutWidget editControlsContainer, ThemeConfig theme)
private void AddUnlockLinkIfRequired(PPEContext context, FlowLayoutWidget editControlsContainer, ThemeConfig theme)
{
var unlockLink = item.GetType().GetCustomAttributes(typeof(UnlockLinkAttribute), true).FirstOrDefault() as UnlockLinkAttribute;
var unlockLink = context.item.GetType().GetCustomAttributes(typeof(UnlockLinkAttribute), true).FirstOrDefault() as UnlockLinkAttribute;
if (unlockLink != null
&& !string.IsNullOrEmpty(unlockLink.UnlockPageLink)
&& !item.Persistable)
&& !context.item.Persistable)
{
var row = CreateSettingsRow(item.Persistable ? "Registered".Localize() : "Demo Mode".Localize());
var row = CreateSettingsRow(context.item.Persistable ? "Registered".Localize() : "Demo Mode".Localize());
Button detailsLink = theme.ButtonFactory.Generate("Unlock".Localize(), AggContext.StaticData.LoadIcon("locked.png", 16, 16));
detailsLink.BackgroundColor = theme.Colors.PrimaryAccentColor.AdjustContrast(theme.Colors.PrimaryTextColor, 8).ToColor();
@ -551,9 +515,9 @@ namespace MatterHackers.MatterControl.DesignTools
}
}
private void AddWebPageLinkIfRequired(FlowLayoutWidget editControlsContainer, ThemeConfig theme)
private void AddWebPageLinkIfRequired(PPEContext context, FlowLayoutWidget editControlsContainer, ThemeConfig theme)
{
var unlockLink = item.GetType().GetCustomAttributes(typeof(WebPageLinkAttribute), true).FirstOrDefault() as WebPageLinkAttribute;
var unlockLink = context.item.GetType().GetCustomAttributes(typeof(WebPageLinkAttribute), true).FirstOrDefault() as WebPageLinkAttribute;
if (unlockLink != null)
{
var row = CreateSettingsRow(unlockLink.Name.Localize());
@ -569,7 +533,7 @@ namespace MatterHackers.MatterControl.DesignTools
}
}
private static GuiWidget CreateEnumEditor(PublicPropertyEditor publicPropertyEditor, IRebuildable item,
private static GuiWidget CreateEnumEditor(PPEContext context, IRebuildable item,
EditableProperty property, Type propertyType, object value, string displayName,
ThemeConfig theme,
UndoBuffer undoBuffer)
@ -631,7 +595,7 @@ namespace MatterHackers.MatterControl.DesignTools
property.Item,
new Object[] { Enum.Parse(propertyType, localItem.Key) });
item?.Rebuild(undoBuffer);
propertyGridModifier?.UpdateControls(publicPropertyEditor);
propertyGridModifier?.UpdateControls(context);
if (localIndex != 0
|| !iconsAttribute.Item0IsNone)
{
@ -668,7 +632,7 @@ namespace MatterHackers.MatterControl.DesignTools
property.Item,
new Object[] { Enum.Parse(propertyType, localOrderedItem.Key) });
item?.Rebuild(undoBuffer);
propertyGridModifier?.UpdateControls(publicPropertyEditor);
propertyGridModifier?.UpdateControls(context);
};
}

View file

@ -122,7 +122,6 @@
<Compile Include="DesignTools\Operations\CurveObject3D.cs" />
<Compile Include="DesignTools\Operations\FitToBounds3D.cs" />
<Compile Include="DesignTools\Operations\Object3DExtensions.cs" />
<Compile Include="DesignTools\Operations\Package3D.cs" />
<Compile Include="DesignTools\Operations\PinchEditor.cs" />
<Compile Include="DesignTools\Operations\Rotate.cs" />
<Compile Include="DesignTools\Operations\Scale.cs" />

View file

@ -42,15 +42,6 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.PartPreviewWindow
{
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class IObject3DComponentAttribute: Attribute
{
}
public interface IObject3DComponent
{
}
[HideUpdateButtonAttribute]
public class SelectedObjectPanel : FlowLayoutWidget, IContentStore
{
@ -253,8 +244,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
public GuiWidget ContentPanel { get; set; }
private static Type componentAttribute = typeof(IObject3DComponentAttribute);
private static Type componentType = typeof(IObject3DComponent);
private static Type iobject3DType = typeof(IObject3D);
public void SetActiveItem(IObject3D selectedItem)
@ -279,56 +268,13 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
var activeEditors = new List<(IObject3DEditor, IObject3D, string)>();
// If item is IObject3DComponent
if (componentType.IsAssignableFrom(selectedItemType))
foreach (var child in selectedItem.DescendantsAndSelf())
{
// Get all public, instance properties where property type is IObject3D
var members = from item in selectedItemType.GetProperties(PublicPropertyEditor.OwnedPropertiesOnly)
let propertyType = item.PropertyType
where iobject3DType.IsAssignableFrom(propertyType)
select new
{
Type = propertyType,
Value = item.GetValue(selectedItem, null) as IObject3D,
DisplayName = EditableProperty.GetDisplayName(item)
};
// Shown known editors for any matching properties
foreach (var member in members)
if (ApplicationController.Instance.GetEditorsForType(child.GetType())?.FirstOrDefault() is IObject3DEditor editor)
{
if (ApplicationController.Instance.GetEditorsForType(member.Type)?.FirstOrDefault() is IObject3DEditor editor)
{
activeEditors.Add((editor, member.Value, member.DisplayName));
}
activeEditors.Add((editor, child, child.Name));
}
}
else
{
// Get all public, instance properties where property type is marked with IObject3DComponentAttribute
var members = from item in selectedItemType.GetProperties(PublicPropertyEditor.OwnedPropertiesOnly)
where Attribute.IsDefined(item, componentAttribute)
select new
{
Type = item.PropertyType,
Value = item.GetValue(selectedItem, null) as IObject3D,
DisplayName = EditableProperty.GetDisplayName(item)
};
// Shown known editors for any matching properties
foreach (var member in members.Where(m => m.Value != null))
{
if (ApplicationController.Instance.GetEditorsForType(member.Type)?.FirstOrDefault() is IObject3DEditor editor)
{
activeEditors.Add((editor, member.Value, member.DisplayName));
}
}
}
if (mappedEditors?.Any() == true)
{
// Use first filtered or fall back to unfiltered first
activeEditors.Add((mappedEditors.First(), selectedItem, null));
}
ShowObjectEditor(activeEditors, selectedItem);
}

View file

@ -64,21 +64,33 @@ namespace MatterHackers.MeshVisualizer
public static class MaterialRendering
{
public static void RenderAabb(this WorldView world, AxisAlignedBoundingBox bounds, Matrix4X4 matrix, Color color, double width)
public static void RenderAabb(this WorldView world, AxisAlignedBoundingBox bounds, Matrix4X4 matrix, Color color, double width, double extendLineLength = 0)
{
GLHelper.PrepareFor3DLineRender(true);
Frustum frustum = world.GetClippingFrustum();
for (int i = 0; i < 4; i++)
{
Vector3 bottomStartPosition = Vector3.Transform(bounds.GetBottomCorner(i), matrix);
Vector3 sideStartPosition = Vector3.Transform(bounds.GetBottomCorner(i), matrix);
Vector3 sideEndPosition = Vector3.Transform(bounds.GetTopCorner(i), matrix);
Vector3 bottomStartPosition = sideStartPosition;
Vector3 bottomEndPosition = Vector3.Transform(bounds.GetBottomCorner((i + 1) % 4), matrix);
Vector3 topStartPosition = Vector3.Transform(bounds.GetTopCorner(i), matrix);
Vector3 topStartPosition = sideEndPosition;
Vector3 topEndPosition = Vector3.Transform(bounds.GetTopCorner((i + 1) % 4), matrix);
GLHelper.Render3DLineNoPrep(frustum, world, bottomStartPosition, bottomEndPosition, color, width);
GLHelper.Render3DLineNoPrep(frustum, world, topStartPosition, topEndPosition, color, width);
GLHelper.Render3DLineNoPrep(frustum, world, topStartPosition, bottomStartPosition, color, width);
if(extendLineLength > 0)
{
GLHelper.ExtendLineEnds(ref sideStartPosition, ref sideEndPosition, extendLineLength);
GLHelper.ExtendLineEnds(ref topStartPosition, ref topEndPosition, extendLineLength);
GLHelper.ExtendLineEnds(ref bottomStartPosition, ref bottomEndPosition, extendLineLength);
}
// draw each of the edge lines (4) and their touching top and bottom lines (2 each)
world.Render3DLineNoPrep(frustum, sideStartPosition, sideEndPosition, color, width);
world.Render3DLineNoPrep(frustum, topStartPosition, topEndPosition, color, width);
world.Render3DLineNoPrep(frustum, bottomStartPosition, bottomEndPosition, color, width);
}
GL.Enable(EnableCap.Lighting);
@ -624,7 +636,7 @@ namespace MatterHackers.MeshVisualizer
var transformed1 = Vector3.Transform(faceCenter, renderData.Matrix);
var normal = Vector3.TransformNormal(face.Normal, renderData.Matrix).GetNormal();
GLHelper.Render3DLineNoPrep(frustum, World, transformed1, transformed1 + normal, Color.Red, 2);
GLHelper.Render3DLineNoPrep(World, frustum, transformed1, transformed1 + normal, Color.Red, 2);
}
}
@ -663,7 +675,7 @@ namespace MatterHackers.MeshVisualizer
var transformed1 = Vector3.Transform(meshEdge.VertexOnEnd[0].Position, renderData.WorldMatrix());
var transformed2 = Vector3.Transform(meshEdge.VertexOnEnd[1].Position, renderData.WorldMatrix());
GLHelper.Render3DLineNoPrep(frustum, World, transformed1, transformed2, selectionColor, selectionHighlightWidth);
GLHelper.Render3DLineNoPrep(World, frustum, transformed1, transformed2, selectionColor, selectionHighlightWidth);
}
}
}

@ -1 +1 @@
Subproject commit b1bc1d73be878293cc2f8e4e1c2275ea1e43cd0c
Subproject commit e6fc4dd9646fed5d3dfa6aa962a0da724b1f425f