Improving primitives

grouping
colors
update button
consistency
This commit is contained in:
Lars Brubaker 2018-04-27 10:13:45 -07:00
parent 15084e7b84
commit ce9b84f67f
15 changed files with 90 additions and 35 deletions

View file

@ -210,6 +210,42 @@ namespace MatterHackers.MatterControl
await this.SetActivePrinter(emptyPrinter);
}
public Color BlendHsl(string a, string b, int index, int count)
{
return PrimitiveColors[a].BlendHsl(PrimitiveColors[b], 1.0 / (count + 1.0) * index);
}
Dictionary<string, Color> _primitiveColors;
public Dictionary<string, Color> PrimitiveColors
{
get
{
if (_primitiveColors == null)
{
_primitiveColors = new Dictionary<string, Color>();
// put in all the constant things before blening them
_primitiveColors.Add("Cube", Color.FromHSL(.01, .98, .76)); // red
_primitiveColors.Add("Text", Color.FromHSL(.175, .98, .76)); // yellow
_primitiveColors.Add("HalfSphere", Color.FromHSL(.87, .98, .76)); // violet
// first color
_primitiveColors.Add("Pyramid", BlendHsl("Cube", "Text", 1, 3));
_primitiveColors.Add("Wedge", BlendHsl("Cube", "Text", 2, 3));
_primitiveColors.Add("HalfWedge", BlendHsl("Cube", "Text", 3, 3));
// mid color
_primitiveColors.Add("Cylinder", BlendHsl("Text", "HalfSphere", 1, 6));
_primitiveColors.Add("Cone", BlendHsl("Text", "HalfSphere", 2, 6));
_primitiveColors.Add("HalfCylinder", BlendHsl("Text", "HalfSphere", 3, 6));
_primitiveColors.Add("Torus", BlendHsl("Text", "HalfSphere", 4, 6));
_primitiveColors.Add("Ring", BlendHsl("Text", "HalfSphere", 5, 6));
_primitiveColors.Add("Sphere", BlendHsl("Text", "HalfSphere", 6, 6));
// end color
}
return _primitiveColors;
}
}
public void LaunchBrowser(string targetUri)
{
UiThread.RunOnIdle(() =>

View file

@ -38,11 +38,12 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
[HideUpdateButtonAttribute]
public class ConeObject3D : Object3D, IRebuildable
{
public ConeObject3D()
{
Color = PrimitiveColors["Cone"];
Color = ApplicationController.Instance.PrimitiveColors["Cone"];
}
public static ConeObject3D Create()

View file

@ -34,6 +34,7 @@ using MatterHackers.PolygonMesh;
namespace MatterHackers.MatterControl.DesignTools
{
[HideUpdateButtonAttribute]
public class CubeObject3D : Object3D, IRebuildable
{
public CubeObject3D()
@ -56,7 +57,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
var item = new CubeObject3D()
{
Color = PrimitiveColors["Cube"]
Color = ApplicationController.Instance.PrimitiveColors["Cube"]
};
item.Rebuild(null);
return item;

View file

@ -38,11 +38,12 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
[HideUpdateButtonAttribute]
public class CylinderObject3D : Object3D, IRebuildable, IPropertyGridModifier
{
public CylinderObject3D()
{
Color = PrimitiveColors["Cylinder"];
Color = ApplicationController.Instance.PrimitiveColors["Cylinder"];
}
public CylinderObject3D(double diameter, double height, int sides)
@ -112,10 +113,11 @@ namespace MatterHackers.MatterControl.DesignTools
public double Diameter { get; set; } = 20;
public double Height { get; set; } = 20;
public int Sides { get; set; } = 30;
public bool Advanced { get; set; } = false;
public double DiameterTop { get; set; } = 20;
public double StartingAngle { get; set; } = 0;
public double EndingAngle { get; set; } = 360;
public double DiameterTop { get; set; } = 20;
public void Rebuild(UndoBuffer undoBuffer)
{

View file

@ -37,16 +37,17 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
public class RoundRoofObject3D : Object3D, IRebuildable
[HideUpdateButtonAttribute]
public class HalfCylinderObject3D : Object3D, IRebuildable
{
public RoundRoofObject3D()
public HalfCylinderObject3D()
{
Color = PrimitiveColors["RoundRoof"];
Color = ApplicationController.Instance.PrimitiveColors["HalfCylinder"];
}
public static RoundRoofObject3D Create()
public static HalfCylinderObject3D Create()
{
var item = new RoundRoofObject3D();
var item = new HalfCylinderObject3D();
item.Rebuild(null);
return item;

View file

@ -37,11 +37,12 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
[HideUpdateButtonAttribute]
public class HalfSphereObject3D : Object3D, IRebuildable
{
public HalfSphereObject3D()
{
Color = PrimitiveColors["HalfSphere"];
Color = ApplicationController.Instance.PrimitiveColors["HalfSphere"];
}
public HalfSphereObject3D(double diametar, int sides)

View file

@ -37,16 +37,17 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
public class RoofObject3D : Object3D, IRebuildable
[HideUpdateButtonAttribute]
public class HalfWedgeObject3D : Object3D, IRebuildable
{
public RoofObject3D()
public HalfWedgeObject3D()
{
Color = PrimitiveColors["Roof"];
Color = ApplicationController.Instance.PrimitiveColors["HalfWedge"];
}
public static RoofObject3D Create()
public static HalfWedgeObject3D Create()
{
var item = new RoofObject3D();
var item = new HalfWedgeObject3D();
item.Rebuild(null);
return item;

View file

@ -36,11 +36,12 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
[HideUpdateButtonAttribute]
public class PyramidObject3D : Object3D, IRebuildable
{
public PyramidObject3D()
{
Color = PrimitiveColors["Pyramid"];
Color = ApplicationController.Instance.PrimitiveColors["Pyramid"];
}
public static PyramidObject3D Create()

View file

@ -39,11 +39,12 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
[HideUpdateButtonAttribute]
public class RingObject3D : Object3D, IRebuildable, IPropertyGridModifier
{
public RingObject3D()
{
Color = PrimitiveColors["Ring"];
Color = ApplicationController.Instance.PrimitiveColors["Ring"];
}
public RingObject3D(double outerDiameter, double innerDiameter, double height, int sides)
@ -68,6 +69,7 @@ namespace MatterHackers.MatterControl.DesignTools
public double InnerDiameter { get; set; } = 15;
public double Height { get; set; } = 5;
public int Sides { get; set; } = 30;
public bool Advanced { get; set; } = false;
public double StartingAngle { get; set; } = 0;
public double EndingAngle { get; set; } = 360;

View file

@ -37,11 +37,12 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
[HideUpdateButtonAttribute]
public class SphereObject3D : Object3D, IRebuildable, IPropertyGridModifier
{
public SphereObject3D()
{
Color = PrimitiveColors["Sphere"];
Color = ApplicationController.Instance.PrimitiveColors["Sphere"];
}
public SphereObject3D(double diameter, int sides)
@ -62,10 +63,11 @@ namespace MatterHackers.MatterControl.DesignTools
public double Diameter { get; set; } = 20;
public int Sides { get; set; } = 30;
public bool Advanced { get; set; } = false;
public int LatitudeSides { get; set; } = 30;
public double StartingAngle { get; set; } = 0;
public double EndingAngle { get; set; } = 360;
public int LatitudeSides { get; set; } = 30;
public void Rebuild(UndoBuffer undoBuffer)
{

View file

@ -42,6 +42,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
public enum NamedTypeFace { Liberation_Sans, Liberation_Sans_Bold, Liberation_Mono, Titillium, Damion };
[HideUpdateButtonAttribute]
public static class NamedTypeFaceCache
{
public static TypeFace GetTypeFace(NamedTypeFace Name)
@ -73,7 +74,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
public TextObject3D()
{
Color = PrimitiveColors["Text"];
Color = ApplicationController.Instance.PrimitiveColors["Text"];
}
public static TextObject3D Create()

View file

@ -39,11 +39,12 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
[HideUpdateButtonAttribute]
public class TorusObject3D : Object3D, IRebuildable, IPropertyGridModifier
{
public TorusObject3D()
{
Color = PrimitiveColors["Torus"];
Color = ApplicationController.Instance.PrimitiveColors["Torus"];
}
public static TorusObject3D Create()
@ -53,26 +54,28 @@ namespace MatterHackers.MatterControl.DesignTools
return item;
}
public double InnerDiameter { get; set; } = 10;
public double OuterDiameter { get; set; } = 20;
public double InnerDiameter { get; set; } = 10;
public int Sides { get; set; } = 30;
public bool Advanced { get; set; } = false;
[DisplayName("Ring Sides")]
public int RingSides { get; set; } = 15;
public double StartingAngle { get; set; } = 0;
public double EndingAngle { get; set; } = 360;
public int RingSides { get; set; } = 15;
public int RingPhaseAngle { get; set; } = 0;
public void Rebuild(UndoBuffer undoBuffer)
{
var ringSides = RingSides;
var startingAngle = StartingAngle;
var endingAngle = EndingAngle;
if(!Advanced)
var ringPhaseAngle = RingPhaseAngle;
if (!Advanced)
{
ringSides = Math.Max(3, (int)(Sides / 2));
startingAngle = 0;
endingAngle = 360;
ringPhaseAngle = 0;
}
var innerDiameter = Math.Min(OuterDiameter - .1, InnerDiameter);
@ -83,16 +86,17 @@ namespace MatterHackers.MatterControl.DesignTools
var toroidRadius = innerDiameter / 2 + poleRadius;
var path = new VertexStorage();
var angleDelta = MathHelper.Tau / ringSides;
var angle = 0.0;
var ringStartAngle = MathHelper.DegreesToRadians(ringPhaseAngle);
var ringAngle = ringStartAngle;
var circleCenter = new Vector2(toroidRadius, 0);
path.MoveTo(circleCenter + new Vector2(poleRadius * Math.Cos(angle), poleRadius * Math.Sin(angle)));
path.MoveTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringStartAngle), poleRadius * Math.Sin(ringStartAngle)));
for (int i = 0; i < ringSides - 1; i++)
{
angle += angleDelta;
path.LineTo(circleCenter + new Vector2(poleRadius * Math.Cos(angle), poleRadius * Math.Sin(angle)));
ringAngle += angleDelta;
path.LineTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringAngle), poleRadius * Math.Sin(ringAngle)));
}
path.LineTo(circleCenter + new Vector2(poleRadius * Math.Cos(0), poleRadius * Math.Sin(0)));
path.LineTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringStartAngle), poleRadius * Math.Sin(ringStartAngle)));
var startAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(startingAngle));
var endAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(endingAngle));
@ -107,9 +111,10 @@ namespace MatterHackers.MatterControl.DesignTools
public void UpdateControls(PublicPropertyEditor editor)
{
editor.GetEditRow((this.ID, nameof(RingSides))).Visible = Advanced;
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;
InnerDiameter = Math.Min(OuterDiameter - .1, InnerDiameter);
}
}

View file

@ -37,11 +37,12 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
[HideUpdateButtonAttribute]
public class WedgeObject3D : Object3D, IRebuildable
{
public WedgeObject3D()
{
Color = PrimitiveColors["Wedge"];
Color = ApplicationController.Instance.PrimitiveColors["Wedge"];
}
public static WedgeObject3D Create()

View file

@ -74,6 +74,8 @@
<Compile Include="AboutPage\CacheDirectory.cs" />
<Compile Include="AboutPage\CheckForUpdatesPage.cs" />
<Compile Include="ApplicationView\LogoSpinner.cs" />
<Compile Include="DesignTools\Primitives\HalfCylinderObject3D.cs" />
<Compile Include="DesignTools\Primitives\HalfWedgeObject3D.cs" />
<Compile Include="PrinterControls\ControlWidgets\CalibrationControls.cs" />
<Compile Include="ConfigurationPage\PrintLeveling\LevelingFunctions.cs" />
<Compile Include="ConfigurationPage\PrintLeveling\LevelWizard3x3Mesh.cs" />
@ -125,8 +127,6 @@
<Compile Include="DesignTools\Primitives\BaseObject3D.cs" />
<Compile Include="DesignTools\Primitives\ImageObject3D.cs" />
<Compile Include="DesignTools\Primitives\RingObject3D.cs" />
<Compile Include="DesignTools\Primitives\RoofObject3D.cs" />
<Compile Include="DesignTools\Primitives\RoundRoofObject3D.cs" />
<Compile Include="DesignTools\Primitives\WedgeObject3D.cs" />
<Compile Include="DesignTools\Primitives\PyramidObject3D.cs" />
<Compile Include="DesignTools\Primitives\CylinderObject3D.cs" />

@ -1 +1 @@
Subproject commit 44b1f77abed3748b62ac082d190a6e2df4df2fe6
Subproject commit 5ff72caf66fa6b90d2619a84adbbd6899094dee0