mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-12 05:58:34 +00:00
Reverted addition of SphereBindings
This commit is contained in:
parent
637e10162b
commit
cf1a0f2cbc
@ -44,9 +44,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="BindableBoolean.cs" />
|
||||
<Compile Include="IBindings.cs" />
|
||||
<Compile Include="SphereBindings.cs" />
|
||||
<Compile Include="ICloneable.cs" />
|
||||
<Compile Include="SphereScriptBuilder.cs" />
|
||||
<Compile Include="VariableCalculator.cs" />
|
||||
<Compile Include="CompoundVariable.cs" />
|
||||
<Compile Include="Dependencies.cs" />
|
||||
|
||||
@ -22,11 +22,12 @@ namespace OSCADSharp
|
||||
/// <summary>
|
||||
/// This is the diameter of the sphere
|
||||
/// </summary>
|
||||
public double Diameter {
|
||||
public double Diameter
|
||||
{
|
||||
get { return this.Radius * 2; }
|
||||
set { this.Radius = value / 2; }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Minimum angle (in degrees) of each cylinder fragment.
|
||||
/// ($fa in OpenSCAD)
|
||||
@ -86,8 +87,25 @@ namespace OSCADSharp
|
||||
/// <returns>Script for this object</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
var scriptBuilder = new SphereScriptBuilder(this.bindings, this);
|
||||
return scriptBuilder.GetScript();
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -123,11 +141,19 @@ namespace OSCADSharp
|
||||
/// <returns></returns>
|
||||
public override Bounds Bounds()
|
||||
{
|
||||
return new Bounds(new Vector3(-this.Radius, -this.Radius, -this.Radius),
|
||||
return new Bounds(new Vector3(-this.Radius, -this.Radius, -this.Radius),
|
||||
new Vector3(this.Radius, this.Radius, this.Radius));
|
||||
}
|
||||
|
||||
private SphereBindings bindings = new SphereBindings();
|
||||
private Bindings bindings = new Bindings(new Dictionary<string, string>()
|
||||
{
|
||||
{ "radius", "r" },
|
||||
{ "minimumangle", "$fa" },
|
||||
{ "minimumfragmentsize", "$fs" },
|
||||
{ "resolution", "$fn" },
|
||||
{ "diameter", "d" }
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
/// Binds a a variable to a property on this object
|
||||
/// </summary>
|
||||
@ -136,7 +162,7 @@ namespace OSCADSharp
|
||||
/// literal value of the property</param>
|
||||
public override void Bind(string property, Variable variable)
|
||||
{
|
||||
this.bindings.Bind<Sphere>(this, property, variable);
|
||||
this.bindings.Add<Sphere>(this, property, variable);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -1,47 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OSCADSharp
|
||||
{
|
||||
internal class SphereBindings : ICloneable<SphereBindings>, IBindings
|
||||
{
|
||||
private Bindings bindings = new Bindings(new Dictionary<string, string>()
|
||||
{
|
||||
{ "radius", "r" },
|
||||
{ "minimumangle", "$fa" },
|
||||
{ "minimumfragmentsize", "$fs" },
|
||||
{ "resolution", "$fn" },
|
||||
{ "diameter", "d" }
|
||||
});
|
||||
|
||||
public SphereBindings Clone()
|
||||
{
|
||||
return new SphereBindings() {
|
||||
bindings = bindings.Clone()
|
||||
};
|
||||
}
|
||||
|
||||
public bool Contains(string openScadFieldName)
|
||||
{
|
||||
return this.bindings.Contains(openScadFieldName);
|
||||
}
|
||||
|
||||
public Binding Get(string propertyName)
|
||||
{
|
||||
return this.bindings.Get(propertyName);
|
||||
}
|
||||
|
||||
public void Synonym(string propertyName, string alternateName)
|
||||
{
|
||||
this.bindings.Synonym(propertyName, alternateName);
|
||||
}
|
||||
|
||||
public void Bind<T>(T obj, string property, Variable variable)
|
||||
{
|
||||
this.bindings.Add<T>(obj, property, variable);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OSCADSharp
|
||||
{
|
||||
internal class SphereScriptBuilder
|
||||
{
|
||||
private readonly IBindings bindings;
|
||||
private readonly Sphere sphere;
|
||||
|
||||
internal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user