mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-11 13:38:33 +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.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)
|
||||
{
|
||||
if (this.hasMatchingSynonym(propertyName))
|
||||
return this.bindings[this.synonyms[propertyName]];
|
||||
|
||||
return bindings[propertyName];
|
||||
}
|
||||
|
||||
|
||||
@ -42,6 +42,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Bindings\BindableBoolean.cs" />
|
||||
<Compile Include="Settings\Dependencies.cs" />
|
||||
<Compile Include="Files\DefaultFileInvoker.cs" />
|
||||
<Compile Include="Files\DefaultFileWriter.cs" />
|
||||
|
||||
@ -16,6 +16,8 @@ namespace OSCADSharp.Solids
|
||||
{
|
||||
#region Attributes
|
||||
private Vector3 size = new BindableVector(1, 1, 1, sizeSynonyms);
|
||||
private bool center = false;
|
||||
private BindableBoolean centerBinding = new BindableBoolean("center");
|
||||
|
||||
/// <summary>
|
||||
/// 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)
|
||||
/// </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
|
||||
|
||||
#region Constructors
|
||||
@ -77,8 +87,10 @@ namespace OSCADSharp.Solids
|
||||
/// <returns>Script for this object</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("cube(size = {0}, center = {1}); {2}",
|
||||
this.Size.ToString(), this.Center.ToString().ToLower(), Environment.NewLine); ;
|
||||
return String.Format("cube(size = {0}, center = {1}); {2}",
|
||||
this.Size.ToString(),
|
||||
this.centerBinding.IsBound ? this.centerBinding.ToString() : this.center.ToString().ToLower(),
|
||||
Environment.NewLine); ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -161,6 +173,12 @@ namespace OSCADSharp.Solids
|
||||
|
||||
vec.Bind(property, variable);
|
||||
}
|
||||
|
||||
if(property.ToLower() == "center")
|
||||
{
|
||||
this.centerBinding.Bind(property, variable);
|
||||
this.center = Convert.ToBoolean(variable.Value);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user