+ Refactored Text3D to use StatementBuilder

This commit is contained in:
Michael L Smith 2016-02-22 20:12:04 -08:00
parent 0e47d85f42
commit ddb0a319c9
2 changed files with 12 additions and 13 deletions

View File

@ -14,8 +14,7 @@ namespace OSCADSharp.ConsoleTests
static void Main(string[] args) static void Main(string[] args)
{ {
var obj = new Cube(5, 5, 20) var obj = new Text3D("Whaat is thissss?");
.Translate(30, 0, 0).Rotate(0, 90, 0).Resize(2, 2, 2);
var pos = obj.Position(); var pos = obj.Position();
var cyl1 = new Cylinder(1, 100, true).Translate(pos); var cyl1 = new Cylinder(1, 100, true).Translate(pos);
@ -23,10 +22,10 @@ namespace OSCADSharp.ConsoleTests
var cyl3 = new Cylinder(1, 100, true).Rotate(90, 0, 0).Translate(pos); var cyl3 = new Cylinder(1, 100, true).Rotate(90, 0, 0).Translate(pos);
var axisHelper = cyl1.Union(cyl2, cyl3).Color("Red"); var axisHelper = cyl1.Union(cyl2, cyl3).Color("Red");
var topCorner = new Sphere().Translate(obj.Bounds().TopRight); //var topCorner = new Sphere().Translate(obj.Bounds().TopRight);
var botCorner = new Sphere().Translate(obj.Bounds().BottomLeft); //var botCorner = new Sphere().Translate(obj.Bounds().BottomLeft);
(obj + topCorner + botCorner + axisHelper).ToFile("test.scad"); (obj + axisHelper).ToFile("test.scad");
//Console.ReadKey(); //Console.ReadKey();
} }

View File

@ -107,22 +107,22 @@ namespace OSCADSharp.Solids
/// <returns>Script for this object</returns> /// <returns>Script for this object</returns>
public override string ToString() public override string ToString()
{ {
StringBuilder sb = new StringBuilder(); StatementBuilder sb = new StatementBuilder();
sb.Append("text("); sb.Append("text(");
sb.Append("\""); sb.Append("\"");
sb.Append(this.Text); sb.Append(this.Text);
sb.Append("\""); sb.Append("\"");
appendIfValueNotNullOrEmpty("size", this.Size?.ToString(), sb); sb.AppendValuePairIfExists("size", this.Size?.ToString(), true);
// Text is always centered in OSCADSharp to ensure correctness of // Text is always centered in OSCADSharp to ensure correctness of
// position interpolation // position interpolation
appendIfValueNotNullOrEmpty("halign", "\"center\"", sb); sb.AppendValuePairIfExists("halign", "\"center\"", true);
appendIfValueNotNullOrEmpty("valign", "\"center\"", sb); sb.AppendValuePairIfExists("valign", "\"center\"", true);
appendIfValueNotNullOrEmpty("font", this.Font, sb); sb.AppendValuePairIfExists("font", this.Font, true);
appendIfValueNotNullOrEmpty("spacing", this.Spacing?.ToString(), sb); sb.AppendValuePairIfExists("spacing", this.Spacing?.ToString(), true);
appendIfValueNotNullOrEmpty("direction", this.TextDirection?.ToString(), sb); sb.AppendValuePairIfExists("direction", this.TextDirection?.ToString(), true);
appendIfValueNotNullOrEmpty("language", this.Language?.ToString(), sb); sb.AppendValuePairIfExists("language", this.Language?.ToString(), true);
sb.Append(");"); sb.Append(");");
sb.Append(Environment.NewLine); sb.Append(Environment.NewLine);