mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-11 13:38:33 +00:00
Tests / fixes for bindings being propagated on cloned objects
This commit is contained in:
parent
6e4c018df7
commit
627569e6ed
@ -198,5 +198,29 @@ namespace OSCADSharp.UnitTests
|
||||
Assert.IsTrue(script.Contains("h = overallHeight"));
|
||||
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Cylinder_CloningCylinderClonesBindings()
|
||||
{
|
||||
var diam = new Variable("mainColumn", Inches.Half);
|
||||
var height = new Variable("overallHeight", Inches.Quarter);
|
||||
var center = new Variable("isCentered", true);
|
||||
var color = new Variable("myColor", "Blue");
|
||||
var rotation = new Variable("myRot", new Vector3(90, 90, -90));
|
||||
|
||||
OSCADObject cyl = new Cylinder(diam, diam, height, center);
|
||||
cyl = cyl.Rotate(rotation).Color(color);
|
||||
|
||||
var clone = cyl.Clone();
|
||||
|
||||
string script = clone.ToString();
|
||||
|
||||
Assert.IsTrue(script.Contains("color(myColor"));
|
||||
Assert.IsTrue(script.Contains("rotate(myRot)"));
|
||||
Assert.IsTrue(script.Contains("center = isCentered"));
|
||||
Assert.IsTrue(script.Contains("d1 = mainColumn"));
|
||||
Assert.IsTrue(script.Contains("d2 = mainColumn"));
|
||||
Assert.IsTrue(script.Contains("h = overallHeight"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -183,5 +183,22 @@ namespace OSCADSharp.UnitTests
|
||||
Assert.IsTrue(script.Contains("d = width"));
|
||||
Assert.IsTrue(script.Contains("$fn = rez"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Sphere_BindingsAreClonedWithObject()
|
||||
{
|
||||
var diam = new Variable("width", Inches.One);
|
||||
var resolution = new Variable("rez", 100);
|
||||
var scale = new Variable("theScale", new Vector3(1, 2, 3));
|
||||
|
||||
var sphere = new Sphere(diam, resolution).Scale(scale);
|
||||
var clone = sphere.Clone();
|
||||
|
||||
string script = clone.ToString();
|
||||
|
||||
Assert.IsTrue(script.Contains("d = width"));
|
||||
Assert.IsTrue(script.Contains("$fn = rez"));
|
||||
Assert.IsTrue(script.Contains("scale(v = theScale)"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,5 +97,25 @@ namespace OSCADSharp.UnitTests
|
||||
Assert.IsTrue(script.Contains(String.Format("text(\"{0}\"", text.Name)));
|
||||
Assert.IsTrue(script.Contains(String.Format("size = {0}", size.Name)));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_ClonedObjectHasBindings()
|
||||
{
|
||||
var text = new Variable("txt", "Greetings, Earthlings");
|
||||
var size = new Variable("txtSize", 82);
|
||||
var mirrorNormal = new Variable("xMirror", new Vector3(1, 0, 0));
|
||||
var zResize = new Variable("zSize", 30);
|
||||
|
||||
var txt = new Text3D(text, size)
|
||||
.Mirror(mirrorNormal).Resize(15, 15, zResize);
|
||||
var clone = txt.Clone();
|
||||
|
||||
string script = clone.ToString();
|
||||
|
||||
Assert.IsTrue(script.Contains(String.Format("text(\"{0}\"", text.Name)));
|
||||
Assert.IsTrue(script.Contains(String.Format("size = {0}", size.Name)));
|
||||
Assert.IsTrue(script.Contains(String.Format("mirror(xMirror)", size.Name)));
|
||||
Assert.IsTrue(script.Contains(String.Format("resize([15, 15, zSize])", size.Name)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -218,6 +218,7 @@ namespace OSCADSharp.Solids
|
||||
MinimumAngle = this.MinimumAngle,
|
||||
MinimumCircumferentialLength = this.MinimumCircumferentialLength,
|
||||
Center = this.Center,
|
||||
centerBinding = this.centerBinding,
|
||||
bindings = this.bindings.Clone()
|
||||
};
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ namespace OSCADSharp.Transforms
|
||||
this.Bind("size", size);
|
||||
}
|
||||
|
||||
internal ResizedObject(OSCADObject obj, Vector3 size, Variable x, Variable y, Variable z) :base(obj)
|
||||
internal ResizedObject(OSCADObject obj, Vector3 size, Variable x, Variable y, Variable z) : base(obj)
|
||||
{
|
||||
this.Size = new BindableVector(size);
|
||||
|
||||
@ -43,6 +43,10 @@ namespace OSCADSharp.Transforms
|
||||
this.BindIfVariableNotNull("z", z);
|
||||
}
|
||||
|
||||
internal ResizedObject(OSCADObject obj) : base(obj)
|
||||
{
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string size = this.bindings.Contains("size") ? this.bindings.Get("size").BoundVariable.Name : this.Size.ToString();
|
||||
@ -54,10 +58,13 @@ namespace OSCADSharp.Transforms
|
||||
|
||||
public override OSCADObject Clone()
|
||||
{
|
||||
return new ResizedObject(this.obj.Clone(), this.Size)
|
||||
var bndSize = this.Size as BindableVector;
|
||||
|
||||
return new ResizedObject(this.obj.Clone())
|
||||
{
|
||||
Name = this.Name,
|
||||
bindings = this.bindings.Clone()
|
||||
bindings = this.bindings.Clone(),
|
||||
Size = bndSize != null ? bndSize.Clone() : this.Size.Clone()
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user