mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-24 03:38:26 +00:00
+ In-progress Cube/center binding implementation
This commit is contained in:
parent
0989c4660c
commit
564a19a286
@ -144,5 +144,19 @@ namespace OSCADSharp.UnitTests
|
|||||||
Assert.AreEqual(Convert.ToDouble(zValue.Value), obj.Size.Z);
|
Assert.AreEqual(Convert.ToDouble(zValue.Value), obj.Size.Z);
|
||||||
Assert.IsTrue(script.Contains("size = [xVal, yVal, zVal]"));
|
Assert.IsTrue(script.Contains("size = [xVal, yVal, zVal]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Cube_CenterBindingAppearsInOutput()
|
||||||
|
{
|
||||||
|
Variable centerVal = new Variable("isCentered", true);
|
||||||
|
|
||||||
|
var obj = new Cube();
|
||||||
|
obj.Bind("Center", centerVal);
|
||||||
|
|
||||||
|
string script = obj.ToString();
|
||||||
|
|
||||||
|
Assert.AreEqual(centerVal.Value, obj.Center);
|
||||||
|
Assert.IsTrue(script.Contains("center = isCentered"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
50
OSCADSharp/OSCADSharp/Bindings/BindableBoolean.cs
Normal file
50
OSCADSharp/OSCADSharp/Bindings/BindableBoolean.cs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using OSCADSharp.Scripting;
|
||||||
|
|
||||||
|
namespace OSCADSharp.Bindings
|
||||||
|
{
|
||||||
|
internal class BindableBoolean : IBindable
|
||||||
|
{
|
||||||
|
public string InnerValue
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Bindings bindings = new Bindings(new Dictionary<string, string>()
|
||||||
|
{
|
||||||
|
{ "innervalue", "innervalue" }
|
||||||
|
});
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a bindable boolean, which is more or less a
|
||||||
|
/// proxy for bindings on boolean fields
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="propertyName">Name of the property in the containing class for binding.
|
||||||
|
/// This will be used as a synonym</param>
|
||||||
|
internal BindableBoolean(string propertyName)
|
||||||
|
{
|
||||||
|
this.boundProperty = propertyName;
|
||||||
|
this.bindings.Synonym("innervalue", propertyName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string boundProperty = null;
|
||||||
|
|
||||||
|
public bool IsBound { get; set; } = false;
|
||||||
|
public void Bind(string property, Variable variable)
|
||||||
|
{
|
||||||
|
this.IsBound = true;
|
||||||
|
var stringifiedVar = new Variable(variable.Name, variable.Value.ToString().ToLower());
|
||||||
|
this.bindings.Add<BindableBoolean>(this, property, stringifiedVar);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return this.bindings.Get(this.boundProperty).BoundVariable.Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -120,6 +120,9 @@ namespace OSCADSharp.Bindings
|
|||||||
|
|
||||||
internal Binding Get(string propertyName)
|
internal Binding Get(string propertyName)
|
||||||
{
|
{
|
||||||
|
if (this.hasMatchingSynonym(propertyName))
|
||||||
|
return this.bindings[this.synonyms[propertyName]];
|
||||||
|
|
||||||
return bindings[propertyName];
|
return bindings[propertyName];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -42,6 +42,7 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Bindings\BindableBoolean.cs" />
|
||||||
<Compile Include="Settings\Dependencies.cs" />
|
<Compile Include="Settings\Dependencies.cs" />
|
||||||
<Compile Include="Files\DefaultFileInvoker.cs" />
|
<Compile Include="Files\DefaultFileInvoker.cs" />
|
||||||
<Compile Include="Files\DefaultFileWriter.cs" />
|
<Compile Include="Files\DefaultFileWriter.cs" />
|
||||||
|
|||||||
@ -16,6 +16,8 @@ namespace OSCADSharp.Solids
|
|||||||
{
|
{
|
||||||
#region Attributes
|
#region Attributes
|
||||||
private Vector3 size = new BindableVector(1, 1, 1, sizeSynonyms);
|
private Vector3 size = new BindableVector(1, 1, 1, sizeSynonyms);
|
||||||
|
private bool center = false;
|
||||||
|
private BindableBoolean centerBinding = new BindableBoolean("center");
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Size of the cube in terms of X/Y/Z units
|
/// The Size of the cube in terms of X/Y/Z units
|
||||||
@ -31,7 +33,15 @@ namespace OSCADSharp.Solids
|
|||||||
///
|
///
|
||||||
/// If False (default) one corner will be centered at 0,0, 0, with the cube extending into the positive octant (positive X/Y/Z)
|
/// If False (default) one corner will be centered at 0,0, 0, with the cube extending into the positive octant (positive X/Y/Z)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Center { get; set; } = false;
|
public bool Center
|
||||||
|
{
|
||||||
|
get { return this.center; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
this.center = value;
|
||||||
|
this.centerBinding.InnerValue = this.center.ToString().ToLower();
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
@ -78,7 +88,9 @@ namespace OSCADSharp.Solids
|
|||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return String.Format("cube(size = {0}, center = {1}); {2}",
|
return String.Format("cube(size = {0}, center = {1}); {2}",
|
||||||
this.Size.ToString(), this.Center.ToString().ToLower(), Environment.NewLine); ;
|
this.Size.ToString(),
|
||||||
|
this.centerBinding.IsBound ? this.centerBinding.ToString() : this.center.ToString().ToLower(),
|
||||||
|
Environment.NewLine); ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -161,6 +173,12 @@ namespace OSCADSharp.Solids
|
|||||||
|
|
||||||
vec.Bind(property, variable);
|
vec.Bind(property, variable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(property.ToLower() == "center")
|
||||||
|
{
|
||||||
|
this.centerBinding.Bind(property, variable);
|
||||||
|
this.center = Convert.ToBoolean(variable.Value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user