From 03ea1c3cb6bc6d87b51844aa4ce57eb813f5c28b Mon Sep 17 00:00:00 2001 From: Mike Smith Date: Wed, 10 Feb 2016 23:16:20 -0800 Subject: [PATCH] Added some constructors for common ways to create simple solids --- OSCADSharp/OSCADSharp.ConsoleTests/Program.cs | 24 +++----------- OSCADSharp/OSCADSharp/Solids/Cube.cs | 22 +++++++++++++ OSCADSharp/OSCADSharp/Solids/Cylinder.cs | 22 +++++++++++++ OSCADSharp/OSCADSharp/Solids/Sphere.cs | 20 ++++++++++++ OSCADSharp/OSCADSharp/Text3D.cs | 31 +++++++++++++------ 5 files changed, 91 insertions(+), 28 deletions(-) diff --git a/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs b/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs index 29b3d94..2e3d040 100644 --- a/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs +++ b/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs @@ -13,11 +13,7 @@ namespace OSCADSharp.ConsoleTests { static void Main(string[] args) { - OSCADObject cube = new Cube() - { - Size = new Vector3(15, 15, 15), - Center = false - }; + OSCADObject cube = new Cube(new Vector3(15, 15, 15)); cube = cube.Color("Red") .Mirror(1, 0, 0) @@ -26,28 +22,18 @@ namespace OSCADSharp.ConsoleTests .Scale(1, 1, 2) .Translate(10, 5, 2); - OSCADObject cylinder = new Cylinder() - { - Diameter = 35.4, - Height = 50.8 - }.Translate(10, 5, 2); + OSCADObject cylinder = new Cylinder(35.4, 50.8).Translate(10, 5, 2); var combined = cube.Intersection(cylinder).Color("Blue"); combined = cube.Clone().Mirror(0, 0, 1).Union(combined); - var text = new Text3D() - { - Text = "Hello!" - }.Translate(-30, 0, 0); + var text = new Text3D("Hello").Translate(-30, 0, 0); combined = text.Union(combined); - string script = combined.ToString(); + string script = text.ToString(); - File.WriteAllLines("test.scad", new string[] { script.ToString() }); - - Console.WriteLine(script); - Console.ReadKey(); + File.WriteAllLines("test.scad", new string[] { script.ToString() }); } } } diff --git a/OSCADSharp/OSCADSharp/Solids/Cube.cs b/OSCADSharp/OSCADSharp/Solids/Cube.cs index 9031b9a..f55ea02 100644 --- a/OSCADSharp/OSCADSharp/Solids/Cube.cs +++ b/OSCADSharp/OSCADSharp/Solids/Cube.cs @@ -25,6 +25,27 @@ namespace OSCADSharp.Solids public bool Center { get; set; } = false; #endregion + #region Constructors + /// + /// Creates a new cube object with the default initialization values + /// + public Cube() + { + } + + /// + /// Creates a new Cube object + /// + /// The Size of the cube in terms of X/Y/Z dimensions + /// Indicates whether the cube should be centered on the origin + public Cube(Vector3 size = null, bool center = false) + { + this.Size = size ?? new Vector3(1, 1, 1); + this.Center = center; + } + #endregion + + #region Overrides public override string ToString() { return String.Format("cube(size = [{0}, {1}, {2}], center = {3});", @@ -39,5 +60,6 @@ namespace OSCADSharp.Solids Center = this.Center }; } + #endregion } } diff --git a/OSCADSharp/OSCADSharp/Solids/Cylinder.cs b/OSCADSharp/OSCADSharp/Solids/Cylinder.cs index fd53370..ff752f3 100644 --- a/OSCADSharp/OSCADSharp/Solids/Cylinder.cs +++ b/OSCADSharp/OSCADSharp/Solids/Cylinder.cs @@ -95,6 +95,27 @@ namespace OSCADSharp.Solids public int Resolution { get; set; } = 0; #endregion + #region Constructors + /// + /// Creates a cylinder with the default initialization values + /// + public Cylinder() + { + } + + /// + /// Creates a cylinder with the specified diameter and centering + /// + /// Diameter of the cylinder + /// Determines whether the cylinder should be centered on the z-axis, if false the base will start on the Z axis + public Cylinder(double diameter = 2, double height = 1, bool center = false) + { + this.Diameter = diameter; + this.Center = center; + } + #endregion + + #region Overrides public override string ToString() { return String.Format("cylinder($fn = {0}, $fa = {1}, $fs = {2}, h = {3}, r1 = {4}, r2 = {5}, center = {6});", @@ -115,5 +136,6 @@ namespace OSCADSharp.Solids Center = this.Center }; } + #endregion } } diff --git a/OSCADSharp/OSCADSharp/Solids/Sphere.cs b/OSCADSharp/OSCADSharp/Solids/Sphere.cs index 20575ee..e3c16c2 100644 --- a/OSCADSharp/OSCADSharp/Solids/Sphere.cs +++ b/OSCADSharp/OSCADSharp/Solids/Sphere.cs @@ -44,6 +44,25 @@ namespace OSCADSharp.Solids public int Resolution { get; set; } = 0; #endregion + #region Constructors + /// + /// Creates a sphere with the default initialization values + /// + public Sphere() + { + } + + /// + /// Creates a sphere of the specified diameter + /// + /// Diameter of the sphere + public Sphere(double diameter) + { + this.Diameter = diameter; + } + #endregion + + #region Overrides public override string ToString() { return String.Format("sphere($fn = {0}, $fa = {1}, $fs = {2}, r = {3});", @@ -61,5 +80,6 @@ namespace OSCADSharp.Solids Radius = this.Radius }; } + #endregion } } diff --git a/OSCADSharp/OSCADSharp/Text3D.cs b/OSCADSharp/OSCADSharp/Text3D.cs index d0d5d3f..663cc25 100644 --- a/OSCADSharp/OSCADSharp/Text3D.cs +++ b/OSCADSharp/OSCADSharp/Text3D.cs @@ -12,6 +12,7 @@ namespace OSCADSharp /// public class Text3D : OSCADObject { + #region Attributes /// /// Text to display /// @@ -56,20 +57,31 @@ namespace OSCADSharp /// The language of the text. Default is "en". /// public string Language { get; set; } - + + #endregion + #region Constructors /// - /// Used for subdividing the curved path segments provided by freetype - /// ($fn in OpenSCAD) + /// Creates 3d text with the default parameters + /// if the text is not specified, text will say "Text" /// - /// TODO: Implement Resolution - // public int? Resolution { get; set; } = 0; + public Text3D() + { + this.Text = "Text"; + } /// - /// The script of the text. Default is "latin". - /// - /// TODO: Implement Script - // public string Script { get; set; } + /// Creates 3d text with the specified text to create + /// + /// Text to display + /// Font size for the text + public Text3D(string text, uint? size = null) + { + this.Text = text; + this.Size = size; + } + #endregion + #region Overrides public override OSCADObject Clone() { return new Text3D() @@ -113,5 +125,6 @@ namespace OSCADSharp var formatter = new BlockFormatter(String.Format("linear_extrude(height = {0})", 1), sb.ToString()); return formatter.ToString(); } + #endregion } }