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();
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);
}
public BindableBoolean Clone()
{
var clone = new BindableBoolean(this.boundProperty);
clone.bindings = this.bindings;
return clone;
}
public override string ToString()
{
return this.bindings.Get(this.boundProperty).BoundVariable.Name;

View File

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

View File

@ -114,13 +114,19 @@ namespace OSCADSharp.Solids
/// <returns></returns>
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,
Size = ((BindableVector)this.Size).Clone(),
Center = this.Center,
size = size.Clone(),
center = this.Center,
centerBinding = center,
bindings = this.bindings.Clone()
};
return clone;
}
/// <summary>

View File

@ -15,7 +15,7 @@ namespace OSCADSharp.Transforms
internal class TranslatedObject : SingleStatementObject
{
internal Vector3 Vector { get; set; }
/// <summary>
/// Creates a translated object
/// </summary>
@ -40,6 +40,10 @@ namespace OSCADSharp.Transforms
this.BindIfVariableNotNull("z", z);
}
internal TranslatedObject(OSCADObject obj) : base(obj)
{
}
public override string 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()
{
return new TranslatedObject(this.obj.Clone(), this.Vector)
var bindableVec = this.Vector as BindableVector;
var clone = new TranslatedObject(this.obj.Clone())
{
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()