Shifted code in .ToString of sphere to SphereScriptBuilder

This commit is contained in:
Michael Smith 2016-03-09 00:16:26 -08:00
parent 4ecf664db5
commit 16d59a1a19
3 changed files with 48 additions and 19 deletions

View File

@ -0,0 +1,44 @@
using OSCADSharp.Bindings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OSCADSharp.Scripting.Solids
{
internal class SphereScriptBuilder
{
private IBindings bindings;
private Sphere sphere;
public SphereScriptBuilder(IBindings bindings, Sphere sphere)
{
this.bindings = bindings;
this.sphere = sphere;
}
internal string GetScript()
{
StatementBuilder sb = new StatementBuilder(this.bindings);
sb.Append("sphere(");
if (this.bindings.Contains("d"))
{
sb.AppendValuePairIfExists("d", this.sphere.Diameter);
}
else
{
sb.AppendValuePairIfExists("r", this.sphere.Radius);
}
sb.AppendValuePairIfExists("$fn", this.sphere.Resolution, true);
sb.AppendValuePairIfExists("$fa", this.sphere.MinimumAngle, true);
sb.AppendValuePairIfExists("$fs", this.sphere.MinimumFragmentSize, true);
sb.Append(");");
sb.Append(Environment.NewLine);
return sb.ToString();
}
}
}

View File

@ -46,6 +46,7 @@
<Compile Include="Internal\Bindings\IBindings.cs" />
<Compile Include="Internal\Bindings\Solids\SphereBindings.cs" />
<Compile Include="Internal\ICloneable.cs" />
<Compile Include="Internal\Scripting\Solids\SphereScriptBuilder.cs" />
<Compile Include="Internal\Scripting\VariableCalculator.cs" />
<Compile Include="Internal\Scripting\CompoundVariable.cs" />
<Compile Include="Public\Settings\Dependencies.cs" />

View File

@ -9,6 +9,7 @@ using System.Collections.Concurrent;
using System.Reflection;
using OSCADSharp.Bindings;
using OSCADSharp.Bindings.Solids;
using OSCADSharp.Scripting.Solids;
namespace OSCADSharp
{
@ -90,25 +91,8 @@ namespace OSCADSharp
/// <returns>Script for this object</returns>
public override string ToString()
{
StatementBuilder sb = new StatementBuilder(this.bindings);
sb.Append("sphere(");
if (this.bindings.Contains("d"))
{
sb.AppendValuePairIfExists("d", this.Diameter);
}
else
{
sb.AppendValuePairIfExists("r", this.Radius);
}
sb.AppendValuePairIfExists("$fn", this.Resolution, true);
sb.AppendValuePairIfExists("$fa", this.MinimumAngle, true);
sb.AppendValuePairIfExists("$fs", this.MinimumFragmentSize, true);
sb.Append(");");
sb.Append(Environment.NewLine);
return sb.ToString();
var scriptBuilder = new SphereScriptBuilder(this.bindings, this);
return scriptBuilder.GetScript();
}
/// <summary>