diff --git a/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs b/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs
index 5e22705..660e587 100644
--- a/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs
+++ b/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs
@@ -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();
}
diff --git a/OSCADSharp/OSCADSharp.UnitTests/Solids/CylinderTests.cs b/OSCADSharp/OSCADSharp.UnitTests/Solids/CylinderTests.cs
index fd9b5ea..7d0bd05 100644
--- a/OSCADSharp/OSCADSharp.UnitTests/Solids/CylinderTests.cs
+++ b/OSCADSharp/OSCADSharp.UnitTests/Solids/CylinderTests.cs
@@ -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"));
+
+ }
}
}
diff --git a/OSCADSharp/OSCADSharp/Scripting/Variables.cs b/OSCADSharp/OSCADSharp/Scripting/Variables.cs
index 79a2367..84be48b 100644
--- a/OSCADSharp/OSCADSharp/Scripting/Variables.cs
+++ b/OSCADSharp/OSCADSharp/Scripting/Variables.cs
@@ -29,6 +29,15 @@ namespace OSCADSharp.Scripting
this.variables[name] = new Variable(name, value);
}
+ ///
+ /// Adds a variable to the collection
+ ///
+ ///
+ public void Add(Variable variable)
+ {
+ this.variables[variable.Name] = variable;
+ }
+
///
/// Removes a variable from the collection
///
diff --git a/OSCADSharp/OSCADSharp/Solids/Cylinder.cs b/OSCADSharp/OSCADSharp/Solids/Cylinder.cs
index 9e1e71a..ad2391e 100644
--- a/OSCADSharp/OSCADSharp/Solids/Cylinder.cs
+++ b/OSCADSharp/OSCADSharp/Solids/Cylinder.cs
@@ -129,6 +129,28 @@ namespace OSCADSharp.Solids
this.Height = height;
this.Center = center;
}
+
+ ///
+ /// Creates a cylinder with one or more pre-bound variables
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ 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" }