Bindings for Color

This commit is contained in:
Michael L Smith 2016-03-01 18:30:42 -08:00
parent 8eba76a670
commit 7f7447e633
3 changed files with 43 additions and 2 deletions

View File

@ -59,6 +59,7 @@
<Compile Include="SettingsTests.cs" />
<Compile Include="Solids\CubeTests.cs" />
<Compile Include="Solids\CylinderTests.cs" />
<Compile Include="Transforms\ColorTests.cs" />
<Compile Include="Transforms\HullTests.cs" />
<Compile Include="InterpolationTests.cs" />
<Compile Include="Transforms\MirrorTests.cs" />

View File

@ -0,0 +1,31 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OSCADSharp.Scripting;
using OSCADSharp.Solids;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OSCADSharp.UnitTests.Transforms
{
[TestClass]
public class ColorTests
{
[TestMethod]
public void Color_BoundFieldsAppearInOutput()
{
Variable colorVar = new Variable("myFavoriteColor", "blue");
Variable cubeOpacity = new Variable("cubeOpacity", .6);
var obj = new Cube().Color("Red", .5);
obj.Bind("color", colorVar);
obj.Bind("opacity", cubeOpacity);
string script = obj.ToString();
Assert.IsTrue(script.Contains("myFavoriteColor"));
Assert.IsTrue(script.Contains("cubeOpacity"));
}
}
}

View File

@ -32,7 +32,12 @@ namespace OSCADSharp.Transforms
public override string ToString()
{
string colorCommand = String.Format("color(\"{0}\", {1})", this.ColorName, this.Opacity);
string colorName = this.bindings.Contains("color") ? this.bindings.Get("color").BoundVariable.Name :
this.ColorName;
string opacity = this.bindings.Contains("opacity") ? this.bindings.Get("opacity").BoundVariable.Name
: this.Opacity.ToString();
string colorCommand = String.Format("color(\"{0}\", {1})", colorName, opacity);
var formatter = new SingleBlockFormatter(colorCommand, this.obj.ToString());
return formatter.ToString();
}
@ -55,9 +60,13 @@ namespace OSCADSharp.Transforms
return this.obj.Bounds();
}
private Bindings.Bindings bindings = new Bindings.Bindings(new Dictionary<string, string>() {
{"color", "color" },
{"opacity", "opacity" }
});
public override void Bind(string property, Variable variable)
{
throw new NotImplementedException();
this.bindings.Add<ColoredObject>(this, property, variable);
}
}
}