From cf1a0f2cbc9389194ca59dc02c57e9afa82a22c7 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Thu, 17 Mar 2016 23:14:39 -0700 Subject: [PATCH] Reverted addition of SphereBindings --- OSCADSharp/OSCADSharp/OSCADSharp.csproj | 2 - OSCADSharp/OSCADSharp/Sphere.cs | 40 ++++++++++++++--- OSCADSharp/OSCADSharp/SphereBindings.cs | 47 -------------------- OSCADSharp/OSCADSharp/SphereScriptBuilder.cs | 43 ------------------ 4 files changed, 33 insertions(+), 99 deletions(-) delete mode 100644 OSCADSharp/OSCADSharp/SphereBindings.cs delete mode 100644 OSCADSharp/OSCADSharp/SphereScriptBuilder.cs diff --git a/OSCADSharp/OSCADSharp/OSCADSharp.csproj b/OSCADSharp/OSCADSharp/OSCADSharp.csproj index 572469b..efc8269 100644 --- a/OSCADSharp/OSCADSharp/OSCADSharp.csproj +++ b/OSCADSharp/OSCADSharp/OSCADSharp.csproj @@ -44,9 +44,7 @@ - - diff --git a/OSCADSharp/OSCADSharp/Sphere.cs b/OSCADSharp/OSCADSharp/Sphere.cs index 21410ce..9eb5745 100644 --- a/OSCADSharp/OSCADSharp/Sphere.cs +++ b/OSCADSharp/OSCADSharp/Sphere.cs @@ -22,11 +22,12 @@ namespace OSCADSharp /// /// This is the diameter of the sphere /// - public double Diameter { + public double Diameter + { get { return this.Radius * 2; } set { this.Radius = value / 2; } } - + /// /// Minimum angle (in degrees) of each cylinder fragment. /// ($fa in OpenSCAD) @@ -86,8 +87,25 @@ namespace OSCADSharp /// Script for this object public override string ToString() { - var scriptBuilder = new SphereScriptBuilder(this.bindings, this); - return scriptBuilder.GetScript(); + StatementBuilder sb = new StatementBuilder(this.bindings); + sb.Append("sphere("); + + if (this.bindings.Contains("d")) + { + sb.AppendValuePairIfExists("d", this.Diameter); + } + else + { + sb.AppendValuePairIfExists("r", this.Radius); + } + + sb.AppendValuePairIfExists("$fn", this.Resolution, true); + sb.AppendValuePairIfExists("$fa", this.MinimumAngle, true); + sb.AppendValuePairIfExists("$fs", this.MinimumFragmentSize, true); + sb.Append(");"); + sb.Append(Environment.NewLine); + + return sb.ToString(); } /// @@ -123,11 +141,19 @@ namespace OSCADSharp /// public override Bounds Bounds() { - return new Bounds(new Vector3(-this.Radius, -this.Radius, -this.Radius), + return new Bounds(new Vector3(-this.Radius, -this.Radius, -this.Radius), new Vector3(this.Radius, this.Radius, this.Radius)); } - private SphereBindings bindings = new SphereBindings(); + private Bindings bindings = new Bindings(new Dictionary() + { + { "radius", "r" }, + { "minimumangle", "$fa" }, + { "minimumfragmentsize", "$fs" }, + { "resolution", "$fn" }, + { "diameter", "d" } + }); + /// /// Binds a a variable to a property on this object /// @@ -136,7 +162,7 @@ namespace OSCADSharp /// literal value of the property public override void Bind(string property, Variable variable) { - this.bindings.Bind(this, property, variable); + this.bindings.Add(this, property, variable); } #endregion } diff --git a/OSCADSharp/OSCADSharp/SphereBindings.cs b/OSCADSharp/OSCADSharp/SphereBindings.cs deleted file mode 100644 index fd0de53..0000000 --- a/OSCADSharp/OSCADSharp/SphereBindings.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace OSCADSharp -{ - internal class SphereBindings : ICloneable, IBindings - { - private Bindings bindings = new Bindings(new Dictionary() - { - { "radius", "r" }, - { "minimumangle", "$fa" }, - { "minimumfragmentsize", "$fs" }, - { "resolution", "$fn" }, - { "diameter", "d" } - }); - - public SphereBindings Clone() - { - return new SphereBindings() { - bindings = bindings.Clone() - }; - } - - public bool Contains(string openScadFieldName) - { - return this.bindings.Contains(openScadFieldName); - } - - public Binding Get(string propertyName) - { - return this.bindings.Get(propertyName); - } - - public void Synonym(string propertyName, string alternateName) - { - this.bindings.Synonym(propertyName, alternateName); - } - - public void Bind(T obj, string property, Variable variable) - { - this.bindings.Add(obj, property, variable); - } - } -} diff --git a/OSCADSharp/OSCADSharp/SphereScriptBuilder.cs b/OSCADSharp/OSCADSharp/SphereScriptBuilder.cs deleted file mode 100644 index 89dbe6c..0000000 --- a/OSCADSharp/OSCADSharp/SphereScriptBuilder.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace OSCADSharp -{ - internal class SphereScriptBuilder - { - private readonly IBindings bindings; - private readonly Sphere sphere; - - internal SphereScriptBuilder(IBindings bindings, Sphere sphere) - { - this.bindings = bindings; - this.sphere = sphere; - } - - internal string GetScript() - { - StatementBuilder sb = new StatementBuilder(this.bindings); - sb.Append("sphere("); - - if (this.bindings.Contains("d")) - { - sb.AppendValuePairIfExists("d", this.sphere.Diameter); - } - else - { - sb.AppendValuePairIfExists("r", this.sphere.Radius); - } - - sb.AppendValuePairIfExists("$fn", this.sphere.Resolution, true); - sb.AppendValuePairIfExists("$fa", this.sphere.MinimumAngle, true); - sb.AppendValuePairIfExists("$fs", this.sphere.MinimumFragmentSize, true); - sb.Append(");"); - sb.Append(Environment.NewLine); - - return sb.ToString(); - } - } -}