Fix for Cube/TranslatedObject cloning of bindings

This commit is contained in:
Michael L Smith 2016-03-05 15:26:14 -08:00
parent d8eb02ecc4
commit 6e4c018df7
5 changed files with 35 additions and 11 deletions

View File

@ -189,7 +189,8 @@ namespace OSCADSharp.UnitTests
string script = clone.ToString(); string script = clone.ToString();
Assert.IsTrue(script.Contains("translate(v = [xOffset"));
Assert.IsTrue(script.Contains("size = [15, 5, myHeight]"));
} }
} }
} }

View File

@ -42,6 +42,14 @@ namespace OSCADSharp.Bindings
this.bindings.Add<BindableBoolean>(this, property, stringifiedVar); this.bindings.Add<BindableBoolean>(this, property, stringifiedVar);
} }
public BindableBoolean Clone()
{
var clone = new BindableBoolean(this.boundProperty);
clone.bindings = this.bindings;
return clone;
}
public override string ToString() public override string ToString()
{ {
return this.bindings.Get(this.boundProperty).BoundVariable.Name; return this.bindings.Get(this.boundProperty).BoundVariable.Name;

View File

@ -56,10 +56,10 @@ namespace OSCADSharp.Bindings
public new BindableVector Clone() public new BindableVector Clone()
{ {
return new BindableVector(base.Clone()) var clone = new BindableVector(base.Clone());
{ clone.bindings = this.bindings.Clone();
bindings = this.bindings
}; return clone;
} }
} }
} }

View File

@ -114,13 +114,19 @@ namespace OSCADSharp.Solids
/// <returns></returns> /// <returns></returns>
public override OSCADObject Clone() public override OSCADObject Clone()
{ {
return new Cube() var size = this.size as BindableVector;
var center = this.centerBinding.Clone();
var clone = new Cube()
{ {
Name = this.Name, Name = this.Name,
Size = ((BindableVector)this.Size).Clone(), size = size.Clone(),
Center = this.Center, center = this.Center,
centerBinding = center,
bindings = this.bindings.Clone() bindings = this.bindings.Clone()
}; };
return clone;
} }
/// <summary> /// <summary>

View File

@ -15,7 +15,7 @@ namespace OSCADSharp.Transforms
internal class TranslatedObject : SingleStatementObject internal class TranslatedObject : SingleStatementObject
{ {
internal Vector3 Vector { get; set; } internal Vector3 Vector { get; set; }
/// <summary> /// <summary>
/// Creates a translated object /// Creates a translated object
/// </summary> /// </summary>
@ -40,6 +40,10 @@ namespace OSCADSharp.Transforms
this.BindIfVariableNotNull("z", z); this.BindIfVariableNotNull("z", z);
} }
internal TranslatedObject(OSCADObject obj) : base(obj)
{
}
public override string ToString() public override string ToString()
{ {
string translation = this.bindings.Contains("vector") ? this.bindings.Get("vector").BoundVariable.Name : this.Vector.ToString(); string translation = this.bindings.Contains("vector") ? this.bindings.Get("vector").BoundVariable.Name : this.Vector.ToString();
@ -51,11 +55,16 @@ namespace OSCADSharp.Transforms
public override OSCADObject Clone() public override OSCADObject Clone()
{ {
return new TranslatedObject(this.obj.Clone(), this.Vector) var bindableVec = this.Vector as BindableVector;
var clone = new TranslatedObject(this.obj.Clone())
{ {
Name = this.Name, Name = this.Name,
bindings = this.bindings.Clone() bindings = this.bindings.Clone(),
Vector = bindableVec != null ? bindableVec.Clone() : this.Vector.Clone()
}; };
return clone;
} }
public override Vector3 Position() public override Vector3 Position()