mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-22 18:58:28 +00:00
Reverted addition of SphereBindings
This commit is contained in:
parent
637e10162b
commit
cf1a0f2cbc
@ -44,9 +44,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="BindableBoolean.cs" />
|
<Compile Include="BindableBoolean.cs" />
|
||||||
<Compile Include="IBindings.cs" />
|
<Compile Include="IBindings.cs" />
|
||||||
<Compile Include="SphereBindings.cs" />
|
|
||||||
<Compile Include="ICloneable.cs" />
|
<Compile Include="ICloneable.cs" />
|
||||||
<Compile Include="SphereScriptBuilder.cs" />
|
|
||||||
<Compile Include="VariableCalculator.cs" />
|
<Compile Include="VariableCalculator.cs" />
|
||||||
<Compile Include="CompoundVariable.cs" />
|
<Compile Include="CompoundVariable.cs" />
|
||||||
<Compile Include="Dependencies.cs" />
|
<Compile Include="Dependencies.cs" />
|
||||||
|
|||||||
@ -22,11 +22,12 @@ namespace OSCADSharp
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is the diameter of the sphere
|
/// This is the diameter of the sphere
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double Diameter {
|
public double Diameter
|
||||||
|
{
|
||||||
get { return this.Radius * 2; }
|
get { return this.Radius * 2; }
|
||||||
set { this.Radius = value / 2; }
|
set { this.Radius = value / 2; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Minimum angle (in degrees) of each cylinder fragment.
|
/// Minimum angle (in degrees) of each cylinder fragment.
|
||||||
/// ($fa in OpenSCAD)
|
/// ($fa in OpenSCAD)
|
||||||
@ -86,8 +87,25 @@ namespace OSCADSharp
|
|||||||
/// <returns>Script for this object</returns>
|
/// <returns>Script for this object</returns>
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
var scriptBuilder = new SphereScriptBuilder(this.bindings, this);
|
StatementBuilder sb = new StatementBuilder(this.bindings);
|
||||||
return scriptBuilder.GetScript();
|
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>
|
/// <summary>
|
||||||
@ -123,11 +141,19 @@ namespace OSCADSharp
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override Bounds Bounds()
|
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));
|
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>
|
/// <summary>
|
||||||
/// Binds a a variable to a property on this object
|
/// Binds a a variable to a property on this object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -136,7 +162,7 @@ namespace OSCADSharp
|
|||||||
/// literal value of the property</param>
|
/// literal value of the property</param>
|
||||||
public override void Bind(string property, Variable variable)
|
public override void Bind(string property, Variable variable)
|
||||||
{
|
{
|
||||||
this.bindings.Bind<Sphere>(this, property, variable);
|
this.bindings.Add<Sphere>(this, property, variable);
|
||||||
}
|
}
|
||||||
#endregion
|
#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