From e8f7eeeb31057df596edc0c2121f5cf4fdcc4e77 Mon Sep 17 00:00:00 2001 From: Michael L Smith Date: Mon, 3 Oct 2016 22:13:12 -0700 Subject: [PATCH] + Added compound object 'box' sans bindings --- OSCADSharp/OSCADSharp/OSCADSharp.csproj | 1 + OSCADSharp/OSCADSharp/Solids/Compound/Box.cs | 157 +++++++++++++++++++ OSCADSharp/OSCADSharp/Solids/Cylinder.cs | 1 + 3 files changed, 159 insertions(+) create mode 100644 OSCADSharp/OSCADSharp/Solids/Compound/Box.cs diff --git a/OSCADSharp/OSCADSharp/OSCADSharp.csproj b/OSCADSharp/OSCADSharp/OSCADSharp.csproj index eb067c2..03e1da2 100644 --- a/OSCADSharp/OSCADSharp/OSCADSharp.csproj +++ b/OSCADSharp/OSCADSharp/OSCADSharp.csproj @@ -48,6 +48,7 @@ + diff --git a/OSCADSharp/OSCADSharp/Solids/Compound/Box.cs b/OSCADSharp/OSCADSharp/Solids/Compound/Box.cs new file mode 100644 index 0000000..1c5f26f --- /dev/null +++ b/OSCADSharp/OSCADSharp/Solids/Compound/Box.cs @@ -0,0 +1,157 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using OSCADSharp.DataBinding; +using OSCADSharp.Spatial; + +namespace OSCADSharp.Solids.Compound +{ + /// + /// Represents a four-sided container, by default it has a solid bottom and an open top. + /// + public class Box : OSCADObject + { + #region Attributes + /// + /// The thickness of the container walls + /// + public double WallThickness { get; set; } = .1; + + /// + /// The Size of the box in terms of X/Y/Z units + /// + public Vector3 Size { get; set; } = new Vector3(1, 1, 1); + + /// + /// If True, the center of the box will be at 0, 0, 0 + /// + /// If False (default) one corner will be centered at 0,0, 0, with the cube extending into the positive octant (positive X/Y/Z) + /// + public bool Center { get; set; } = false; + + /// + /// If true, the container has a solid bottom + /// + public bool Bottom { get; set; } = true; + + /// + /// If true, the container has a solid top, otherwise the top is open + /// + public bool Top { get; set; } = false; + #endregion + + #region Constructors + /// + /// Creates a box with the default initialization values + /// + public Box() + { + } + #endregion + + #region Overrides + /// + /// Converts this object to an OpenSCAD script + /// + /// Script for this object + public override string ToString() + { + OSCADObject inner = new Cube(new Vector3(this.Size.X - WallThickness*2, + this.Size.Y - WallThickness*2, + this.Size.Z - WallThickness*2), + this.Center); + + if (!this.Bottom && !this.Top) + { + ((Cube)inner).Size.Z += WallThickness * 4; + } + else if (!this.Top) + { + ((Cube)inner).Size.Z += WallThickness*2; + inner = inner.Translate(0, 0, WallThickness); + } + else if (!this.Bottom) + { + ((Cube)inner).Size.Z += WallThickness*2; + inner = inner.Translate(0, 0, -WallThickness); + } + + + if (!this.Center) + { + inner = inner.Translate(this.WallThickness, this.WallThickness, this.WallThickness); + } + + OSCADObject box = new Cube(this.Size, this.Center) - inner; + + return box.ToString(); + } + /// + /// 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 override void Bind(string property, Variable variable) + { + throw new NotImplementedException(); + } + + /// + /// Returns the approximate boundaries of this OpenSCAD object + /// + /// + public override Bounds Bounds() + { + if (Center == false) + { + return new Bounds(new Vector3(), new Vector3(this.Size.X, this.Size.Y, this.Size.Z)); + } + else + { + return new Bounds(new Vector3(-this.Size.X / 2, -this.Size.Y / 2, -this.Size.Z / 2), + new Vector3(this.Size.X / 2, this.Size.Y / 2, this.Size.Z / 2)); + } + } + + /// + /// Gets a copy of this object that is a new instance + /// + /// + public override OSCADObject Clone() + { + return new Box() + { + Name = this.Name, + Size = this.Size, + Bottom = this.Bottom, + Top = this.Top, + Center = this.Center, + WallThickness = this.WallThickness + }; + } + + /// + /// Gets the position of this object's center (origin) in + /// world space + /// + /// + public override Vector3 Position() + { + Vector3 position; + if (this.Center == false) + { + position = new Vector3(this.Size.X / 2, this.Size.Y / 2, this.Size.Z / 2); + } + else + { + position = new Vector3(); + } + + return position; + } + #endregion + } +} diff --git a/OSCADSharp/OSCADSharp/Solids/Cylinder.cs b/OSCADSharp/OSCADSharp/Solids/Cylinder.cs index 4cfd65a..9d40c64 100644 --- a/OSCADSharp/OSCADSharp/Solids/Cylinder.cs +++ b/OSCADSharp/OSCADSharp/Solids/Cylinder.cs @@ -274,6 +274,7 @@ namespace OSCADSharp.Solids {"minimumangle", "$fa" }, {"minimumcircumferentiallength", "$fs" } }); + /// /// Binds a a variable to a property on this object ///