From 255318fb071c5f9f3d0aa274b57f5e8bb098d4c3 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Mon, 29 Feb 2016 23:58:31 -0800 Subject: [PATCH] + Added IBindable on OSCADObject and cascaded it down. + Removed redundant IBindable declaration on Solids --- OSCADSharp/OSCADSharp.ConsoleTests/Program.cs | 2 +- OSCADSharp/OSCADSharp/OSCADObject.cs | 13 +++++++++++-- .../OSCADSharp/Scripting/MultiStatementObject.cs | 5 +++++ OSCADSharp/OSCADSharp/Solids/Cube.cs | 4 ++-- OSCADSharp/OSCADSharp/Solids/Cylinder.cs | 4 ++-- OSCADSharp/OSCADSharp/Solids/Sphere.cs | 4 ++-- OSCADSharp/OSCADSharp/Solids/Text3D.cs | 4 ++-- OSCADSharp/OSCADSharp/Transforms/ColoredObject.cs | 5 +++++ .../OSCADSharp/Transforms/LinearExtrudedObject.cs | 5 +++++ OSCADSharp/OSCADSharp/Transforms/MirroredObject.cs | 5 +++++ OSCADSharp/OSCADSharp/Transforms/ResizedObject.cs | 5 +++++ OSCADSharp/OSCADSharp/Transforms/RotatedObject.cs | 5 +++++ OSCADSharp/OSCADSharp/Transforms/ScaledObject.cs | 5 +++++ .../OSCADSharp/Transforms/TranslatedObject.cs | 5 +++++ 14 files changed, 60 insertions(+), 11 deletions(-) diff --git a/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs b/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs index 349d8d5..f159b76 100644 --- a/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs +++ b/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs @@ -18,7 +18,7 @@ namespace OSCADSharp.ConsoleTests Variables.Global.Add("cubeWidth", 10); OSCADObject obj = new Sphere(); - ((Sphere)obj).Bind("Radius", Variables.Global["sphereRadius"]); + obj.Bind("Radius", Variables.Global["sphereRadius"]); var cube = new Cube(); cube.Bind("Width", Variables.Global["cubeWidth"]); diff --git a/OSCADSharp/OSCADSharp/OSCADObject.cs b/OSCADSharp/OSCADSharp/OSCADObject.cs index 6a62825..0b3dc64 100644 --- a/OSCADSharp/OSCADSharp/OSCADObject.cs +++ b/OSCADSharp/OSCADSharp/OSCADObject.cs @@ -1,4 +1,5 @@ -using OSCADSharp.Booleans; +using OSCADSharp.Bindings; +using OSCADSharp.Booleans; using OSCADSharp.Files; using OSCADSharp.Scripting; using OSCADSharp.Spatial; @@ -16,7 +17,7 @@ namespace OSCADSharp /// Represents any Object or collection of objects that becomes am /// an OpenSCAD script when converted to a string. /// - public abstract class OSCADObject + public abstract class OSCADObject : IBindable { #region Attributes private uint id = Ids.Get(); @@ -340,6 +341,14 @@ namespace OSCADSharp return Dependencies.FileInvokerFactory(filePath); } + + /// + /// 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 abstract void Bind(string property, Variable variable); #endregion #region Operators diff --git a/OSCADSharp/OSCADSharp/Scripting/MultiStatementObject.cs b/OSCADSharp/OSCADSharp/Scripting/MultiStatementObject.cs index d7f6193..b186a7e 100644 --- a/OSCADSharp/OSCADSharp/Scripting/MultiStatementObject.cs +++ b/OSCADSharp/OSCADSharp/Scripting/MultiStatementObject.cs @@ -95,5 +95,10 @@ namespace OSCADSharp.Scripting return new Bounds(newBottomLeft, newTopRight); } + + public override void Bind(string property, Variable variable) + { + throw new NotImplementedException(); + } } } diff --git a/OSCADSharp/OSCADSharp/Solids/Cube.cs b/OSCADSharp/OSCADSharp/Solids/Cube.cs index f9fd5f1..b896c95 100644 --- a/OSCADSharp/OSCADSharp/Solids/Cube.cs +++ b/OSCADSharp/OSCADSharp/Solids/Cube.cs @@ -12,7 +12,7 @@ namespace OSCADSharp.Solids /// /// A Cube geometry /// - public class Cube : OSCADObject, IBindable + public class Cube : OSCADObject { #region Attributes private Vector3 size = new BindableVector(1, 1, 1, sizeSynonyms); @@ -161,7 +161,7 @@ namespace OSCADSharp.Solids /// 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) + public override void Bind(string property, Variable variable) { if (sizeSynonyms.ContainsKey(property.ToLower())) { diff --git a/OSCADSharp/OSCADSharp/Solids/Cylinder.cs b/OSCADSharp/OSCADSharp/Solids/Cylinder.cs index db68537..9e1e71a 100644 --- a/OSCADSharp/OSCADSharp/Solids/Cylinder.cs +++ b/OSCADSharp/OSCADSharp/Solids/Cylinder.cs @@ -12,7 +12,7 @@ namespace OSCADSharp.Solids /// /// A Cylinder geometry /// - public class Cylinder : OSCADObject, IBindable + public class Cylinder : OSCADObject { #region Attributes private bool center = false; @@ -255,7 +255,7 @@ namespace OSCADSharp.Solids /// 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) + public override void Bind(string property, Variable variable) { if (property.ToLower() == "center") { diff --git a/OSCADSharp/OSCADSharp/Solids/Sphere.cs b/OSCADSharp/OSCADSharp/Solids/Sphere.cs index 8842a1c..f51ba3d 100644 --- a/OSCADSharp/OSCADSharp/Solids/Sphere.cs +++ b/OSCADSharp/OSCADSharp/Solids/Sphere.cs @@ -14,7 +14,7 @@ namespace OSCADSharp.Solids /// /// A Sphere geometry /// - public class Sphere : OSCADObject, IBindable + public class Sphere : OSCADObject { #region Attributes /// @@ -146,7 +146,7 @@ namespace OSCADSharp.Solids /// 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) + public override void Bind(string property, Variable variable) { this.bindings.Add(this, property, variable); } diff --git a/OSCADSharp/OSCADSharp/Solids/Text3D.cs b/OSCADSharp/OSCADSharp/Solids/Text3D.cs index 9a6dd78..95afe7d 100644 --- a/OSCADSharp/OSCADSharp/Solids/Text3D.cs +++ b/OSCADSharp/OSCADSharp/Solids/Text3D.cs @@ -12,7 +12,7 @@ namespace OSCADSharp.Solids /// /// Create text using fonts installed on the local system or provided as separate font file. /// - public class Text3D : OSCADObject, IBindable + public class Text3D : OSCADObject { #region Attributes /// @@ -165,7 +165,7 @@ namespace OSCADSharp.Solids /// 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) + public override void Bind(string property, Variable variable) { this.bindings.Add(this, property, variable); } diff --git a/OSCADSharp/OSCADSharp/Transforms/ColoredObject.cs b/OSCADSharp/OSCADSharp/Transforms/ColoredObject.cs index 15b15ba..4bdf5aa 100644 --- a/OSCADSharp/OSCADSharp/Transforms/ColoredObject.cs +++ b/OSCADSharp/OSCADSharp/Transforms/ColoredObject.cs @@ -54,5 +54,10 @@ namespace OSCADSharp.Transforms { return this.obj.Bounds(); } + + public override void Bind(string property, Variable variable) + { + throw new NotImplementedException(); + } } } diff --git a/OSCADSharp/OSCADSharp/Transforms/LinearExtrudedObject.cs b/OSCADSharp/OSCADSharp/Transforms/LinearExtrudedObject.cs index bc1b594..19f5f2b 100644 --- a/OSCADSharp/OSCADSharp/Transforms/LinearExtrudedObject.cs +++ b/OSCADSharp/OSCADSharp/Transforms/LinearExtrudedObject.cs @@ -57,5 +57,10 @@ namespace OSCADSharp.Transforms { throw new NotImplementedException(); } + + public override void Bind(string property, Variable variable) + { + throw new NotImplementedException(); + } } } diff --git a/OSCADSharp/OSCADSharp/Transforms/MirroredObject.cs b/OSCADSharp/OSCADSharp/Transforms/MirroredObject.cs index 54d0b68..5242a5f 100644 --- a/OSCADSharp/OSCADSharp/Transforms/MirroredObject.cs +++ b/OSCADSharp/OSCADSharp/Transforms/MirroredObject.cs @@ -88,5 +88,10 @@ namespace OSCADSharp.Transforms return new Bounds(newBottomLeft, newTopRight); } + + public override void Bind(string property, Variable variable) + { + throw new NotImplementedException(); + } } } diff --git a/OSCADSharp/OSCADSharp/Transforms/ResizedObject.cs b/OSCADSharp/OSCADSharp/Transforms/ResizedObject.cs index 240c49e..8e9ffac 100644 --- a/OSCADSharp/OSCADSharp/Transforms/ResizedObject.cs +++ b/OSCADSharp/OSCADSharp/Transforms/ResizedObject.cs @@ -61,5 +61,10 @@ namespace OSCADSharp.Transforms return new Bounds(oldBounds.BottomLeft * scaleMultiplier, oldBounds.TopRight * scaleMultiplier); } + + public override void Bind(string property, Variable variable) + { + throw new NotImplementedException(); + } } } diff --git a/OSCADSharp/OSCADSharp/Transforms/RotatedObject.cs b/OSCADSharp/OSCADSharp/Transforms/RotatedObject.cs index 6d18cbf..e08032c 100644 --- a/OSCADSharp/OSCADSharp/Transforms/RotatedObject.cs +++ b/OSCADSharp/OSCADSharp/Transforms/RotatedObject.cs @@ -55,5 +55,10 @@ namespace OSCADSharp.Transforms return new Bounds(Matrix.GetRotatedPoint(oldBounds.BottomLeft, this.Angle.X, this.Angle.Y, this.Angle.Z), Matrix.GetRotatedPoint(oldBounds.TopRight, this.Angle.X, this.Angle.Y, this.Angle.Z)); } + + public override void Bind(string property, Variable variable) + { + throw new NotImplementedException(); + } } } diff --git a/OSCADSharp/OSCADSharp/Transforms/ScaledObject.cs b/OSCADSharp/OSCADSharp/Transforms/ScaledObject.cs index 94cdf36..0fbd263 100644 --- a/OSCADSharp/OSCADSharp/Transforms/ScaledObject.cs +++ b/OSCADSharp/OSCADSharp/Transforms/ScaledObject.cs @@ -54,5 +54,10 @@ namespace OSCADSharp.Transforms var oldBounds = obj.Bounds(); return new Bounds(oldBounds.BottomLeft * this.ScaleFactor, oldBounds.TopRight * this.ScaleFactor); } + + public override void Bind(string property, Variable variable) + { + throw new NotImplementedException(); + } } } diff --git a/OSCADSharp/OSCADSharp/Transforms/TranslatedObject.cs b/OSCADSharp/OSCADSharp/Transforms/TranslatedObject.cs index 8f5cd5d..a9ee28c 100644 --- a/OSCADSharp/OSCADSharp/Transforms/TranslatedObject.cs +++ b/OSCADSharp/OSCADSharp/Transforms/TranslatedObject.cs @@ -51,5 +51,10 @@ namespace OSCADSharp.Transforms var oldBounds = obj.Bounds(); return new Bounds(oldBounds.BottomLeft + this.Vector, oldBounds.TopRight + this.Vector); } + + public override void Bind(string property, Variable variable) + { + throw new NotImplementedException(); + } } }