mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-25 12:08:26 +00:00
Added Cylinder variable-binding constructor, test + missed Height in binding.
This commit is contained in:
parent
4c51ffc3f4
commit
421694559f
@ -14,23 +14,15 @@ namespace OSCADSharp.ConsoleTests
|
|||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Variables.Global.Add("myColor", "\"Red\"");
|
var diam = new Variable("mainColumn", Sizes.HalfInch);
|
||||||
Variables.Global.Add("sphereRadius", 15);
|
var height = new Variable("overallHeight", Sizes.QuarterInch);
|
||||||
Variables.Global.Add("cubeWidth", 10);
|
Variables.Global.Add(diam);
|
||||||
|
Variables.Global.Add(height);
|
||||||
|
|
||||||
OSCADObject obj = new Sphere();
|
var cyl = new Cylinder(diam, diam, height);
|
||||||
obj.Bind("Radius", Variables.Global["sphereRadius"]);
|
|
||||||
|
|
||||||
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 = cyl.Position();
|
||||||
|
|
||||||
var pos = obj.Position();
|
|
||||||
var cyl1 = new Cylinder(1, 100, true).Translate(pos);
|
var cyl1 = new Cylinder(1, 100, true).Translate(pos);
|
||||||
var cyl2 = new Cylinder(1, 100, true).Rotate(0, 90, 0).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);
|
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 topCorner = new Sphere().Translate(obj.Bounds().TopRight);
|
||||||
//var botCorner = new Sphere().Translate(obj.Bounds().BottomLeft);
|
//var botCorner = new Sphere().Translate(obj.Bounds().BottomLeft);
|
||||||
|
|
||||||
(obj + axisHelper).ToFile("test.scad").Open();
|
(cyl + axisHelper).ToFile("test.scad").Open();
|
||||||
|
|
||||||
//Console.ReadKey();
|
//Console.ReadKey();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -179,5 +179,24 @@ namespace OSCADSharp.UnitTests
|
|||||||
Assert.IsTrue(script.Contains("$fa = angle"));
|
Assert.IsTrue(script.Contains("$fa = angle"));
|
||||||
Assert.IsTrue(script.Contains("$fs = circLength"));
|
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"));
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,6 +29,15 @@ namespace OSCADSharp.Scripting
|
|||||||
this.variables[name] = new Variable(name, value);
|
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>
|
/// <summary>
|
||||||
/// Removes a variable from the collection
|
/// Removes a variable from the collection
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -129,6 +129,28 @@ namespace OSCADSharp.Solids
|
|||||||
this.Height = height;
|
this.Height = height;
|
||||||
this.Center = center;
|
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
|
#endregion
|
||||||
|
|
||||||
#region Overrides
|
#region Overrides
|
||||||
@ -245,6 +267,7 @@ namespace OSCADSharp.Solids
|
|||||||
{"diameter", "d" },
|
{"diameter", "d" },
|
||||||
{"diameter1", "d1" },
|
{"diameter1", "d1" },
|
||||||
{"diameter2", "d2" },
|
{"diameter2", "d2" },
|
||||||
|
{"height", "h" },
|
||||||
{"resolution", "$fn" },
|
{"resolution", "$fn" },
|
||||||
{"minimumangle", "$fa" },
|
{"minimumangle", "$fa" },
|
||||||
{"minimumcircumferentiallength", "$fs" }
|
{"minimumcircumferentiallength", "$fs" }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user