Parameterized bindings for color, mirror, resize.

This commit is contained in:
Michael L Smith 2016-03-02 20:42:37 -08:00
parent 892fccdf7e
commit cc293b1638
6 changed files with 272 additions and 6 deletions

View File

@ -1,4 +1,5 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OSCADSharp.Scripting;
using OSCADSharp.Solids;
using System;
using System.Collections.Generic;
@ -69,5 +70,25 @@ namespace OSCADSharp.UnitTests
string script = cube.ToString();
Assert.IsTrue(script.Contains("mirror(myVar)"));
}
[TestMethod]
public void Mirror_CanBindNormalWithParameter()
{
var cube = new Cube(5, 20, 15).Mirror(new Scripting.Variable("myVar", new Vector3(1, 0, 0)));
string script = cube.ToString();
Assert.IsTrue(script.Contains("mirror(myVar)"));
}
[TestMethod]
public void Mirror_VariablesForXandZ()
{
var x = new Variable("xComp", 0);
var z = new Variable("zComp", 1);
var cube = new Cube().Mirror(x, 0, z);
string script = cube.ToString();
Assert.IsTrue(script.Contains("mirror([xComp, 0, zComp])"));
}
}
}

View File

@ -44,5 +44,17 @@ namespace OSCADSharp.UnitTests.Transforms
Assert.IsTrue(script.Contains("resize(mySize)"));
}
[TestMethod]
public void Resize_ParameterizedSizeBindingAppearsInOutput()
{
var xAmount = new Variable("xAmt", 15);
var resizedCube = new Cube().Resize(xAmount, 5, 10);
string script = resizedCube.ToString();
Assert.IsTrue(script.Contains("resize([xAmt, 5, 10])"));
}
}
}

View File

@ -51,12 +51,13 @@ namespace OSCADSharp
/// </summary>
/// <param name="colorName">Color name variable to apply</param>
/// <param name="opacity">(optional)Opacity variable</param>
/// <returns></returns>
/// <returns>A colored object</returns>
public OSCADObject Color(Variable colorName, Variable opacity = null)
{
return new ColoredObject(this, colorName, opacity);
}
#region Mirror
/// <summary>
/// Mirrors the object about a plane, as specified by the normal
/// </summary>
@ -67,6 +68,16 @@ namespace OSCADSharp
{
return new MirroredObject(this, normal);
}
/// <summary>
/// Mirrors the object on a plane represented in a variable
/// </summary>
/// <param name="normal">Variable for the normal vector of the plane</param>
/// <returns>A mirrored object</returns>
public OSCADObject Mirror(Variable normal)
{
return new MirroredObject(this, normal);
}
/// <summary>
/// Mirrors the object about a plane, as specified by the normal
@ -81,6 +92,92 @@ namespace OSCADSharp
return this.Mirror(new Vector3(x, y, z));
}
/// <summary>
/// Mirrors an object about a plane with variables for some components of the normal
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A mirrored object</returns>
public OSCADObject Mirror(Variable x, Variable y, Variable z)
{
return new MirroredObject(this, new Vector3(), x, y, z);
}
/// <summary>
/// Mirrors an object about a plane with variables for some components of the normal
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A mirrored object</returns>
public OSCADObject Mirror(Variable x, double y, double z)
{
return new MirroredObject(this, new Vector3(0, y, z), x, null, null);
}
/// <summary>
/// Mirrors an object about a plane with variables for some components of the normal
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A mirrored object</returns>
public OSCADObject Mirror(double x, Variable y, double z)
{
return new MirroredObject(this, new Vector3(x, 0, z), null, y, null);
}
/// <summary>
/// Mirrors an object about a plane with variables for some components of the normal
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A mirrored object</returns>
public OSCADObject Mirror(double x, double y, Variable z)
{
return new MirroredObject(this, new Vector3(x, y, 0), null, null, z);
}
/// <summary>
/// Mirrors an object about a plane with variables for some components of the normal
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A mirrored object</returns>
public OSCADObject Mirror(Variable x, Variable y, double z)
{
return new MirroredObject(this, new Vector3(0, 0, z), x, y, null);
}
/// <summary>
/// Mirrors an object about a plane with variables for some components of the normal
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A mirrored object</returns>
public OSCADObject Mirror(double x, Variable y, Variable z)
{
return new MirroredObject(this, new Vector3(x, 0, 0), null, y, z);
}
/// <summary>
/// Mirrors an object about a plane with variables for some components of the normal
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A mirrored object</returns>
public OSCADObject Mirror(Variable x, double y, Variable z)
{
return new MirroredObject(this, new Vector3(0, y, 0), x, null, z);
}
#endregion
#region Resize
/// <summary>
/// Resizes to a specified set of X/Y/Z dimensions
/// </summary>
@ -91,6 +188,16 @@ namespace OSCADSharp
return new ResizedObject(this, newsize);
}
/// <summary>
/// Resizes to a specified set of X/Y/Z dimensions using a variable
/// </summary>
/// <param name="newsize">The X/Y/Z dimensions</param>
/// <returns>A resized object</returns>
public OSCADObject Resize(Variable newsize)
{
return new ResizedObject(this, newsize);
}
/// <summary>
/// Resizes to a specified set of X/Y/Z dimensions
/// </summary>
@ -103,6 +210,91 @@ namespace OSCADSharp
return this.Resize(new Vector3(x, y, z));
}
/// <summary>
/// Resizes to a specified set of X/Y/Z dimensions using one or more variables
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A resized object</returns>
public OSCADObject Resize(Variable x, Variable y, Variable z)
{
return new ResizedObject(this, new Vector3(), x, y, z);
}
/// <summary>
/// Resizes to a specified set of X/Y/Z dimensions using one or more variables
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A resized object</returns>
public OSCADObject Resize(Variable x, double y, double z)
{
return new ResizedObject(this, new Vector3(0, y, z), x, null, null);
}
/// <summary>
/// Resizes to a specified set of X/Y/Z dimensions using one or more variables
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A resized object</returns>
public OSCADObject Resize(double x, Variable y, double z)
{
return new ResizedObject(this, new Vector3(x, 0, z), null, y, null);
}
/// <summary>
/// Resizes to a specified set of X/Y/Z dimensions using one or more variables
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A resized object</returns>
public OSCADObject Resize(double x, double y, Variable z)
{
return new ResizedObject(this, new Vector3(x, y, 0), null, null, z);
}
/// <summary>
/// Resizes to a specified set of X/Y/Z dimensions using one or more variables
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A resized object</returns>
public OSCADObject Resize(Variable x, double y, Variable z)
{
return new ResizedObject(this, new Vector3(0, y, 0), x, null, z);
}
/// <summary>
/// Resizes to a specified set of X/Y/Z dimensions using one or more variables
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A resized object</returns>
public OSCADObject Resize(double x, Variable y, Variable z)
{
return new ResizedObject(this, new Vector3(x, 0, 0), null, y, z);
}
/// <summary>
/// Resizes to a specified set of X/Y/Z dimensions using one or more variables
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>A resized object</returns>
public OSCADObject Resize(Variable x, Variable y, double z)
{
return new ResizedObject(this, new Vector3(0, 0, z), x, y, null);
}
#endregion
/// <summary>
/// Rotates about a specified X/Y/Z euler angle
/// </summary>

View File

@ -38,10 +38,10 @@ namespace OSCADSharp.Transforms
/// <param name="opacity"></param>
internal ColoredObject(OSCADObject obj, Variable colorName, Variable opacity) : base(obj)
{
this.bindings.Add<ColoredObject>(this, "color", colorName);
this.Bind("color", colorName);
if(opacity != null)
{
this.bindings.Add<ColoredObject>(this, "opacity", opacity);
this.Bind("opacity", opacity);
}
}
@ -79,8 +79,6 @@ namespace OSCADSharp.Transforms
{"color", "color" },
{"opacity", "opacity" }
});
private Variable colorName;
private Variable opacity;
public override void Bind(string property, Variable variable)
{

View File

@ -29,6 +29,23 @@ namespace OSCADSharp.Transforms
{
this.Normal = new BindableVector(normal);
}
internal MirroredObject(OSCADObject obj, Variable normal) : base(obj)
{
this.Bind("normal", normal);
}
internal MirroredObject(OSCADObject obj, Vector3 normal, Variable x, Variable y, Variable z) : base(obj)
{
this.Normal = new BindableVector(normal);
if (x != null)
this.Bind("x", x);
if (y != null)
this.Bind("y", y);
if (z != null)
this.Bind("z", z);
}
public override string ToString()
{
@ -97,7 +114,16 @@ namespace OSCADSharp.Transforms
});
public override void Bind(string property, Variable variable)
{
this.bindings.Add<MirroredObject>(this, property, variable);
var bindableVec = this.Normal as BindableVector;
if (bindableVec != null && property == "x" || property == "y" || property == "z")
{
bindableVec.Bind(property, variable);
}
else
{
this.bindings.Add<MirroredObject>(this, property, variable);
}
}
}
}

View File

@ -29,6 +29,23 @@ namespace OSCADSharp.Transforms
Size = new BindableVector(size);
}
internal ResizedObject(OSCADObject obj, Variable size) : base(obj)
{
this.Bind("size", size);
}
internal ResizedObject(OSCADObject obj, Vector3 size, Variable x, Variable y, Variable z) :base(obj)
{
this.Size = new BindableVector(size);
if (x != null)
this.Bind("x", x);
if (y != null)
this.Bind("y", y);
if (z != null)
this.Bind("z", z);
}
public override string ToString()
{
string size = this.bindings.Contains("size") ? this.bindings.Get("size").BoundVariable.Name : this.Size.ToString();