Added Cylinder variable-binding constructor, test + missed Height in binding.

This commit is contained in:
Michael Smith 2016-03-03 21:47:23 -08:00
parent 4c51ffc3f4
commit 421694559f
4 changed files with 59 additions and 16 deletions

View File

@ -14,23 +14,15 @@ namespace OSCADSharp.ConsoleTests
{
static void Main(string[] args)
{
Variables.Global.Add("myColor", "\"Red\"");
Variables.Global.Add("sphereRadius", 15);
Variables.Global.Add("cubeWidth", 10);
var diam = new Variable("mainColumn", Sizes.HalfInch);
var height = new Variable("overallHeight", Sizes.QuarterInch);
Variables.Global.Add(diam);
Variables.Global.Add(height);
OSCADObject obj = new Sphere();
obj.Bind("Radius", Variables.Global["sphereRadius"]);
var cyl = new Cylinder(diam, diam, height);
var cube = new Cube();
cube.Bind("Width", Variables.Global["cubeWidth"]);
cube.Bind("Height", Variables.Global["sphereRadius"]);
cube.Size.X = 30;
var cb = cube.Color(Variables.Global["myColor"]);
obj = obj + cb;
var pos = obj.Position();
var pos = cyl.Position();
var cyl1 = new Cylinder(1, 100, true).Translate(pos);
var cyl2 = new Cylinder(1, 100, true).Rotate(0, 90, 0).Translate(pos);
var cyl3 = new Cylinder(1, 100, true).Rotate(90, 0, 0).Translate(pos);
@ -39,7 +31,7 @@ namespace OSCADSharp.ConsoleTests
//var topCorner = new Sphere().Translate(obj.Bounds().TopRight);
//var botCorner = new Sphere().Translate(obj.Bounds().BottomLeft);
(obj + axisHelper).ToFile("test.scad").Open();
(cyl + axisHelper).ToFile("test.scad").Open();
//Console.ReadKey();
}

View File

@ -179,5 +179,24 @@ namespace OSCADSharp.UnitTests
Assert.IsTrue(script.Contains("$fa = angle"));
Assert.IsTrue(script.Contains("$fs = circLength"));
}
[TestMethod]
public void Cylinder_CanCreatePreBoundCylinderWithConstructor()
{
var diam = new Variable("mainColumn", Sizes.HalfInch);
var height = new Variable("overallHeight", Sizes.QuarterInch);
var cyl = new Cylinder(diam, diam, height);
Assert.AreEqual(diam.Value, cyl.Diameter);
Assert.AreEqual(height.Value, cyl.Height);
string script = cyl.ToString();
Assert.IsTrue(script.Contains("d1 = mainColumn"));
Assert.IsTrue(script.Contains("d2 = mainColumn"));
Assert.IsTrue(script.Contains("h = overallHeight"));
}
}
}

View File

@ -29,6 +29,15 @@ namespace OSCADSharp.Scripting
this.variables[name] = new Variable(name, value);
}
/// <summary>
/// Adds a variable to the collection
/// </summary>
/// <param name="variable"></param>
public void Add(Variable variable)
{
this.variables[variable.Name] = variable;
}
/// <summary>
/// Removes a variable from the collection
/// </summary>

View File

@ -129,6 +129,28 @@ namespace OSCADSharp.Solids
this.Height = height;
this.Center = center;
}
/// <summary>
/// Creates a cylinder with one or more pre-bound variables
/// </summary>
/// <param name="diameter1"></param>
/// <param name="diameter2"></param>
/// <param name="height"></param>
/// <param name="center"></param>
/// <param name="resolution"></param>
/// <param name="minimumangle"></param>
/// <param name="minimumcircumferentiallength"></param>
public Cylinder(Variable diameter1 = null, Variable diameter2 = null, Variable height = null,
Variable center = null, Variable resolution = null, Variable minimumangle = null, Variable minimumcircumferentiallength = null)
{
this.BindIfVariableNotNull("diameter1", diameter1);
this.BindIfVariableNotNull("diameter2", diameter2);
this.BindIfVariableNotNull("height", height);
this.BindIfVariableNotNull("center", center);
this.BindIfVariableNotNull("resolution", resolution);
this.BindIfVariableNotNull("minimumangle", minimumangle);
this.BindIfVariableNotNull("minimumcircumferentiallength", minimumcircumferentiallength);
}
#endregion
#region Overrides
@ -245,6 +267,7 @@ namespace OSCADSharp.Solids
{"diameter", "d" },
{"diameter1", "d1" },
{"diameter2", "d2" },
{"height", "h" },
{"resolution", "$fn" },
{"minimumangle", "$fa" },
{"minimumcircumferentiallength", "$fs" }