diff --git a/OSCADSharp/OSCADSharp/Internal/Bindings/IBindings.cs b/OSCADSharp/OSCADSharp/Internal/Bindings/IBindings.cs new file mode 100644 index 0000000..66e2b34 --- /dev/null +++ b/OSCADSharp/OSCADSharp/Internal/Bindings/IBindings.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OSCADSharp.Bindings +{ + internal interface IBindings + { + void Bind(T obj, string property, Variable variable); + + bool Contains(string openScadFieldName); + + Binding Get(string propertyName); + + void Synonym(string propertyName, string alternateName); + } +} diff --git a/OSCADSharp/OSCADSharp/Internal/Bindings/Solids/SphereBindings.cs b/OSCADSharp/OSCADSharp/Internal/Bindings/Solids/SphereBindings.cs new file mode 100644 index 0000000..c71fc25 --- /dev/null +++ b/OSCADSharp/OSCADSharp/Internal/Bindings/Solids/SphereBindings.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OSCADSharp.Bindings.Solids +{ + 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/Internal/ICloneable.cs b/OSCADSharp/OSCADSharp/Internal/ICloneable.cs new file mode 100644 index 0000000..ea9f203 --- /dev/null +++ b/OSCADSharp/OSCADSharp/Internal/ICloneable.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OSCADSharp +{ + internal interface ICloneable + { + T Clone(); + } +} diff --git a/OSCADSharp/OSCADSharp/Internal/Scripting/StatementBuilder.cs b/OSCADSharp/OSCADSharp/Internal/Scripting/StatementBuilder.cs index 8d7ab13..f8b3036 100644 --- a/OSCADSharp/OSCADSharp/Internal/Scripting/StatementBuilder.cs +++ b/OSCADSharp/OSCADSharp/Internal/Scripting/StatementBuilder.cs @@ -1,4 +1,5 @@ -using System; +using OSCADSharp.Bindings; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -14,6 +15,7 @@ namespace OSCADSharp.Scripting { private StringBuilder SB { get; set; } = new StringBuilder(); private Bindings.Bindings bindings = null; + private IBindings ibindings = null; internal StatementBuilder() { @@ -24,6 +26,10 @@ namespace OSCADSharp.Scripting this.bindings = bindings; } + internal StatementBuilder(IBindings ibindings) + { + this.ibindings = ibindings; + } /// /// Special append method for conditionally adding value-pairs @@ -47,7 +53,8 @@ namespace OSCADSharp.Scripting if(useBinding) { - SB.Append(this.bindings.Get(name).BoundVariable.Text); + SB.Append(this.bindings?.Get(name).BoundVariable.Text); + SB.Append(this.ibindings?.Get(name).BoundVariable.Text); } else { @@ -58,7 +65,8 @@ namespace OSCADSharp.Scripting private bool shouldUseBinding(string name) { - return this.bindings != null && this.bindings.Contains(name); + return (this.bindings != null && this.bindings.Contains(name)) + || (this.ibindings != null && this.ibindings.Contains(name)); } /// diff --git a/OSCADSharp/OSCADSharp/OSCADSharp.csproj b/OSCADSharp/OSCADSharp/OSCADSharp.csproj index 2b43925..5859df1 100644 --- a/OSCADSharp/OSCADSharp/OSCADSharp.csproj +++ b/OSCADSharp/OSCADSharp/OSCADSharp.csproj @@ -43,6 +43,9 @@ + + + diff --git a/OSCADSharp/OSCADSharp/Public/Solids/Sphere.cs b/OSCADSharp/OSCADSharp/Public/Solids/Sphere.cs index a23d780..61648e5 100644 --- a/OSCADSharp/OSCADSharp/Public/Solids/Sphere.cs +++ b/OSCADSharp/OSCADSharp/Public/Solids/Sphere.cs @@ -8,6 +8,7 @@ using OSCADSharp.Scripting; using System.Collections.Concurrent; using System.Reflection; using OSCADSharp.Bindings; +using OSCADSharp.Bindings.Solids; namespace OSCADSharp { @@ -147,15 +148,7 @@ namespace OSCADSharp new Vector3(this.Radius, this.Radius, this.Radius)); } - private Bindings.Bindings bindings = new Bindings.Bindings(new Dictionary() - { - { "radius", "r" }, - { "minimumangle", "$fa" }, - { "minimumfragmentsize", "$fs" }, - { "resolution", "$fn" }, - { "diameter", "d" } - }); - + private SphereBindings bindings = new SphereBindings(); /// /// Binds a a variable to a property on this object /// @@ -164,7 +157,7 @@ namespace OSCADSharp /// literal value of the property public override void Bind(string property, Variable variable) { - this.bindings.Add(this, property, variable); + this.bindings.Bind(this, property, variable); } #endregion }