From 0d578131d8bed0366c006b24ebf7140e7da13336 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Mon, 29 Feb 2016 19:25:33 -0800 Subject: [PATCH] Added BindableVector --- .../OSCADSharp/Bindings/BindableVector.cs | 33 +++++++++++++++++++ OSCADSharp/OSCADSharp/OSCADSharp.csproj | 1 + OSCADSharp/OSCADSharp/Solids/Cube.cs | 22 ++++++++++++- 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 OSCADSharp/OSCADSharp/Bindings/BindableVector.cs diff --git a/OSCADSharp/OSCADSharp/Bindings/BindableVector.cs b/OSCADSharp/OSCADSharp/Bindings/BindableVector.cs new file mode 100644 index 0000000..5ea06d0 --- /dev/null +++ b/OSCADSharp/OSCADSharp/Bindings/BindableVector.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using OSCADSharp.Scripting; + +namespace OSCADSharp.Bindings +{ + internal class BindableVector : Vector3, IBindable + { + private Bindings bindings = new Bindings(new Dictionary() + { + { "x", "x" }, + { "y", "y" }, + { "z", "z" } + }); + + public void Bind(string property, Variable variable) + { + this.bindings.Add(this, property, variable); + } + + public override string ToString() + { + string x = this.bindings.Contains("x") ? this.bindings.Get("x").BoundVariable.Name : this.X.ToString(); + string y = this.bindings.Contains("y") ? this.bindings.Get("y").BoundVariable.Name : this.Y.ToString(); + string z = this.bindings.Contains("z") ? this.bindings.Get("z").BoundVariable.Name : this.Z.ToString(); + + return String.Format("[{0}, {1}, {2}]", x, y, z); + } + } +} diff --git a/OSCADSharp/OSCADSharp/OSCADSharp.csproj b/OSCADSharp/OSCADSharp/OSCADSharp.csproj index 3288f64..a6643e1 100644 --- a/OSCADSharp/OSCADSharp/OSCADSharp.csproj +++ b/OSCADSharp/OSCADSharp/OSCADSharp.csproj @@ -57,6 +57,7 @@ + diff --git a/OSCADSharp/OSCADSharp/Solids/Cube.cs b/OSCADSharp/OSCADSharp/Solids/Cube.cs index 50e85b8..c9ecc63 100644 --- a/OSCADSharp/OSCADSharp/Solids/Cube.cs +++ b/OSCADSharp/OSCADSharp/Solids/Cube.cs @@ -4,13 +4,15 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using OSCADSharp.Spatial; +using OSCADSharp.Bindings; +using OSCADSharp.Scripting; namespace OSCADSharp.Solids { /// /// A Cube geometry /// - public class Cube : OSCADObject + public class Cube : OSCADObject, IBindable { #region Attributes /// @@ -124,6 +126,24 @@ namespace OSCADSharp.Solids new Vector3(this.Size.X / 2, this.Size.Y / 2, this.Size.Z / 2)); } } + + private Bindings.Bindings bindings = new Bindings.Bindings(new Dictionary() + { + { "center", "center" }, + { "size", "size" } + }); + + /// + /// Binds a a variable to a property on this object + /// + /// A string specifying the property such as "Diameter" or "Radius" + /// The variable to bind the to. This variable will appear in script output in lieu of the + /// literal value of the property + public void Bind(string property, Variable variable) + { + throw new NotImplementedException(); + //this.bindings.Add(this, property, variable); + } #endregion } }