+ Renamed Sizes class to Inches

+ In progress Bindings clone functionality
This commit is contained in:
Michael Smith 2016-03-04 22:36:14 -08:00
parent 047a6472b1
commit d8eb02ecc4
18 changed files with 74 additions and 30 deletions

View File

@ -14,8 +14,8 @@ namespace OSCADSharp.ConsoleTests
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
var diam = new Variable("mainColumn", Sizes.HalfInch); var diam = new Variable("mainColumn", Inches.Half);
var height = new Variable("overallHeight", Sizes.QuarterInch); var height = new Variable("overallHeight", Inches.Quarter);
Variables.Global.Add(diam); Variables.Global.Add(diam);
Variables.Global.Add(height); Variables.Global.Add(height);

View File

@ -162,9 +162,9 @@ namespace OSCADSharp.UnitTests
[TestMethod] [TestMethod]
public void Cube_ConstructorBindingsAppearInOutput() public void Cube_ConstructorBindingsAppearInOutput()
{ {
var length = new Variable("deckBoxLength", Sizes.SixteenthInch * 32); var length = new Variable("deckBoxLength", Inches.Sixteenth * 32);
var width = new Variable("deckBoxWidth", Sizes.SixteenthInch * 32); var width = new Variable("deckBoxWidth", Inches.Sixteenth * 32);
var height = new Variable("deckboxHeight", Sizes.InchesToMillimeters(2.5)); var height = new Variable("deckboxHeight", Inches.ToMillimeters(2.5));
var centered = new Variable("isCentered", true); var centered = new Variable("isCentered", true);
var cube = new Cube(length, width, height, centered); var cube = new Cube(length, width, height, centered);
@ -174,5 +174,22 @@ namespace OSCADSharp.UnitTests
Assert.IsTrue(script.Contains("size = [deckBoxLength, deckBoxWidth, deckboxHeight]")); Assert.IsTrue(script.Contains("size = [deckBoxLength, deckBoxWidth, deckboxHeight]"));
Assert.IsTrue(script.Contains("center = isCentered")); Assert.IsTrue(script.Contains("center = isCentered"));
} }
[TestMethod]
public void Cube_CloneHasSameBindings()
{
var cubeHeight = new Variable("myHeight", 35);
var cubeXTranslation = new Variable("xOffset", 50);
OSCADObject cube = new Cube(15, 5, 15);
cube.Bind("Height", cubeHeight);
cube = cube.Translate(cubeXTranslation, 0, 0);
var clone = cube.Clone();
string script = clone.ToString();
}
} }
} }

View File

@ -183,8 +183,8 @@ namespace OSCADSharp.UnitTests
[TestMethod] [TestMethod]
public void Cylinder_CanCreatePreBoundCylinderWithConstructor() public void Cylinder_CanCreatePreBoundCylinderWithConstructor()
{ {
var diam = new Variable("mainColumn", Sizes.HalfInch); var diam = new Variable("mainColumn", Inches.Half);
var height = new Variable("overallHeight", Sizes.QuarterInch); var height = new Variable("overallHeight", Inches.Quarter);
var cyl = new Cylinder(diam, diam, height); var cyl = new Cylinder(diam, diam, height);

View File

@ -170,7 +170,7 @@ namespace OSCADSharp.UnitTests
[TestMethod] [TestMethod]
public void Sphere_CanCreateSphereWithBindingsFromConstructor() public void Sphere_CanCreateSphereWithBindingsFromConstructor()
{ {
var diam = new Variable("width", Sizes.OneInch); var diam = new Variable("width", Inches.One);
var resolution = new Variable("rez", 100); var resolution = new Variable("rez", 100);
var sphere = new Sphere(diam, resolution); var sphere = new Sphere(diam, resolution);

View File

@ -53,5 +53,13 @@ namespace OSCADSharp.Bindings
return String.Format("[{0}, {1}, {2}]", x, y, z); return String.Format("[{0}, {1}, {2}]", x, y, z);
} }
public new BindableVector Clone()
{
return new BindableVector(base.Clone())
{
bindings = this.bindings
};
}
} }
} }

View File

@ -130,6 +130,15 @@ namespace OSCADSharp.Bindings
{ {
this.synonyms[alternateName] = propertyName; this.synonyms[alternateName] = propertyName;
} }
internal Bindings Clone()
{
var clone = new Bindings(this.propertyNametoOpenSCADFieldMappings);
clone.synonyms = this.synonyms;
clone.bindings = this.bindings;
return clone;
}
#endregion #endregion
} }
} }

View File

@ -9,41 +9,41 @@ namespace OSCADSharp
/// <summary> /// <summary>
/// Constants and conversions for units for us imperial-minded folks. /// Constants and conversions for units for us imperial-minded folks.
/// </summary> /// </summary>
public class Sizes public class Inches
{ {
/// <summary> /// <summary>
/// One imperial inch /// One imperial inch
/// </summary> /// </summary>
public const double OneInch = 25.4; public const double One = 25.4;
/// <summary> /// <summary>
/// Half of an imperial inch /// Half of an imperial inch
/// </summary> /// </summary>
public const double HalfInch = OneInch / 2; public const double Half = One / 2;
/// <summary> /// <summary>
/// Quarter of an imperial inch /// Quarter of an imperial inch
/// </summary> /// </summary>
public const double QuarterInch = HalfInch / 2; public const double Quarter = Half / 2;
/// <summary> /// <summary>
/// Eigth of an imperial inch /// Eigth of an imperial inch
/// </summary> /// </summary>
public const double EigthInch = QuarterInch / 2; public const double Eigth = Quarter / 2;
/// <summary> /// <summary>
/// Sixteenth of an imperial inch /// Sixteenth of an imperial inch
/// </summary> /// </summary>
public const double SixteenthInch = EigthInch / 2; public const double Sixteenth = Eigth / 2;
/// <summary> /// <summary>
/// Converts inches to millimeters /// Converts inches to millimeters
/// </summary> /// </summary>
/// <param name="inches">Number of inches</param> /// <param name="inches">Number of inches</param>
/// <returns>Equivalent value in milimeters</returns> /// <returns>Equivalent value in milimeters</returns>
public static double InchesToMillimeters(double inches) public static double ToMillimeters(double inches)
{ {
return inches * OneInch; return inches * One;
} }
} }
} }

View File

@ -117,8 +117,9 @@ namespace OSCADSharp.Solids
return new Cube() return new Cube()
{ {
Name = this.Name, Name = this.Name,
Size = this.Size, Size = ((BindableVector)this.Size).Clone(),
Center = this.Center Center = this.Center,
bindings = this.bindings.Clone()
}; };
} }

View File

@ -217,7 +217,8 @@ namespace OSCADSharp.Solids
Resolution = this.Resolution, Resolution = this.Resolution,
MinimumAngle = this.MinimumAngle, MinimumAngle = this.MinimumAngle,
MinimumCircumferentialLength = this.MinimumCircumferentialLength, MinimumCircumferentialLength = this.MinimumCircumferentialLength,
Center = this.Center Center = this.Center,
bindings = this.bindings.Clone()
}; };
} }

View File

@ -122,7 +122,8 @@ namespace OSCADSharp.Solids
Resolution = this.Resolution, Resolution = this.Resolution,
MinimumAngle = this.MinimumAngle, MinimumAngle = this.MinimumAngle,
MinimumFragmentSize = this.MinimumFragmentSize, MinimumFragmentSize = this.MinimumFragmentSize,
Radius = this.Radius Radius = this.Radius,
bindings = this.bindings.Clone()
}; };
} }

View File

@ -106,7 +106,8 @@ namespace OSCADSharp.Solids
Font = this.Font, Font = this.Font,
Spacing = this.Spacing, Spacing = this.Spacing,
TextDirection = this.TextDirection, TextDirection = this.TextDirection,
Language = this.Language Language = this.Language,
bindings = this.bindings.Clone()
}; };
} }

View File

@ -58,7 +58,8 @@ namespace OSCADSharp.Transforms
{ {
return new ColoredObject(this.obj.Clone(), this.ColorName, this.Opacity) return new ColoredObject(this.obj.Clone(), this.ColorName, this.Opacity)
{ {
Name = this.Name Name = this.Name,
bindings = this.bindings.Clone()
}; };
} }

View File

@ -56,7 +56,8 @@ namespace OSCADSharp.Transforms
{ {
return new MirroredObject(this.obj.Clone(), this.Normal) return new MirroredObject(this.obj.Clone(), this.Normal)
{ {
Name = this.Name Name = this.Name,
bindings = this.bindings.Clone()
}; };
} }

View File

@ -56,7 +56,8 @@ namespace OSCADSharp.Transforms
{ {
return new ResizedObject(this.obj.Clone(), this.Size) return new ResizedObject(this.obj.Clone(), this.Size)
{ {
Name = this.Name Name = this.Name,
bindings = this.bindings.Clone()
}; };
} }

View File

@ -56,7 +56,8 @@ namespace OSCADSharp.Transforms
{ {
return new RotatedObject(this.obj.Clone(), this.Angle) return new RotatedObject(this.obj.Clone(), this.Angle)
{ {
Name = this.Name Name = this.Name,
bindings = this.bindings.Clone()
}; };
} }

View File

@ -56,7 +56,8 @@ namespace OSCADSharp.Transforms
{ {
return new ScaledObject(this.obj.Clone(), this.ScaleFactor) return new ScaledObject(this.obj.Clone(), this.ScaleFactor)
{ {
Name = this.Name Name = this.Name,
bindings = this.bindings.Clone()
}; };
} }

View File

@ -53,7 +53,8 @@ namespace OSCADSharp.Transforms
{ {
return new TranslatedObject(this.obj.Clone(), this.Vector) return new TranslatedObject(this.obj.Clone(), this.Vector)
{ {
Name = this.Name Name = this.Name,
bindings = this.bindings.Clone()
}; };
} }