Finished out composite behaviors for OSCADObject transforms.

This commit is contained in:
Mike Smith 2016-02-07 11:40:13 -08:00
parent 64066f81f1
commit 43d9369187
8 changed files with 104 additions and 30 deletions

View File

@ -12,15 +12,20 @@ namespace OSCADSharp.ConsoleTests
{
static void Main(string[] args)
{
Cube cube = new Cube() {
OSCADObject cube = new Cube()
{
Size = new Vector3(5, 5, 5),
Center = true
Center = false
};
ColoredObject co = new ColoredObject(cube, "Red");
var mirror = new RotatedObject(co, new Vector3(0, 90, 0));
cube = cube.Color("Red")
.Mirror(new Vector3(1, 0, 0))
.Resize(new Vector3(10, 20, 10))
.Rotate(new Vector3(90, 90, 0))
.Scale(new Vector3(1, 1, 2))
.Translate(new Vector3(10, 5, 2));
Console.WriteLine(mirror.ToString());
Console.WriteLine(cube.ToString());
Console.ReadKey();
}
}

View File

@ -1,4 +1,5 @@
using System;
using OSCADSharp.Transforms;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -8,5 +9,68 @@ namespace OSCADSharp
{
public abstract class OSCADObject
{
#region Transforms
/// <summary>
/// Applies Color and/or Opacity to this object
/// </summary>
/// <param name="colorName">The name of the color to apply</param>
/// <param name="opacity">The opacity from 0.0 to 1.0</param>
/// <returns>A colorized object</returns>
public OSCADObject Color(string colorName, double opacity = 1.0)
{
return new ColoredObject(this, colorName, opacity);
}
/// <summary>
/// Mirrors the object about a plane, as specified by the normal
/// </summary>
/// <param name="normal">The normal vector of the plane intersecting the origin of the object,
/// through which to mirror it.</param>
/// <returns>A mirrored object</returns>
public OSCADObject Mirror(Vector3 normal)
{
return new MirroredObject(this, normal);
}
/// <summary>
/// Resizes to a specified set of X/Y/Z dimensions
/// </summary>
/// <param name="newsize">The X/Y/Z dimensions</param>
/// <returns>A resized object</returns>
public OSCADObject Resize(Vector3 newsize)
{
return new ResizedObject(this, newsize);
}
/// <summary>
/// Rotates about a specified X/Y/Z euler angle
/// </summary>
/// <param name="angle">The angle(s) to rotate</param>
/// <returns>A rotated object</returns>
public OSCADObject Rotate(Vector3 angle)
{
return new RotatedObject(this, angle);
}
/// <summary>
/// Rescales an object by an X/Y/Z scale factor
/// </summary>
/// <param name="scale">The scale to apply. For example 1, 2, 1 would yield 2x scale on the Y axis</param>
/// <returns>A scaled object</returns>
public OSCADObject Scale(Vector3 scale)
{
return new ScaledObject(this, scale);
}
/// <summary>
/// Translates an object by the specified amount
/// </summary>
/// <param name="translation">The vector upon which to translate (move object(s))</param>
/// <returns>A translated object</returns>
public OSCADObject Translate(Vector3 translation)
{
return new TranslatedObject(this, translation);
}
#endregion
}
}

View File

@ -9,11 +9,11 @@ namespace OSCADSharp.Transforms
/// <summary>
/// An object that has color and/or opacity applied to it
/// </summary>
public class ColoredObject : OSCADObject
internal class ColoredObject : OSCADObject
{
#region Attributes
public string Color { get; set; } = "Yellow";
public double Opacity { get; set; } = 1.0;
internal string ColorName { get; set; } = "Yellow";
internal double Opacity { get; set; } = 1.0;
#endregion
private OSCADObject obj;
@ -22,18 +22,18 @@ namespace OSCADSharp.Transforms
/// Creates a colorized object
/// </summary>
/// <param name="obj">The object(s) to which color will be applied</param>
/// <param name="Color">The string-wise name of the color to be applied</param>
/// <param name="color">The string-wise name of the color to be applied</param>
/// <param name="opacity">Opacity from 0.0 to 1.0 </param>
public ColoredObject(OSCADObject obj, string Color = "Yellow", double opacity = 1.0)
internal ColoredObject(OSCADObject obj, string color = "Yellow", double opacity = 1.0)
{
this.obj = obj;
this.Color = Color;
this.ColorName = color;
this.Opacity = opacity;
}
public override string ToString()
{
string colorCommand = String.Format("color(\"{0}\", {1})", this.Color, this.Opacity);
string colorCommand = String.Format("color(\"{0}\", {1})", this.ColorName, this.Opacity);
var formatter = new BlockFormatter(colorCommand, this.obj.ToString());
return formatter.ToString();
}

View File

@ -9,13 +9,13 @@ namespace OSCADSharp.Transforms
/// <summary>
/// An object that's mirrored on a plane
/// </summary>
public class MirroredObject
internal class MirroredObject : OSCADObject
{
/// <summary>
/// The normal vector of a plane intersecting the origin of the object,
/// through which to mirror it.
/// </summary>
public Vector3 Normal { get; set; } = new Vector3();
internal Vector3 Normal { get; set; } = new Vector3();
private OSCADObject obj;
@ -24,7 +24,7 @@ namespace OSCADSharp.Transforms
/// </summary>
/// <param name="obj">The object(s) to be mirrored</param>
/// <param name="normal">The normal vector of the plane on the object's origin to mirror upon</param>
public MirroredObject(OSCADObject obj, Vector3 normal)
internal MirroredObject(OSCADObject obj, Vector3 normal)
{
this.obj = obj;
this.Normal = normal;

View File

@ -9,12 +9,12 @@ namespace OSCADSharp.Transforms
/// <summary>
/// An object that's been resized to a specified set of X/Y/Z dimensions
/// </summary>
public class ResizedObject
internal class ResizedObject : OSCADObject
{
/// <summary>
/// Size of the object in terms of X/Y/Z
/// </summary>
public Vector3 Size { get; set; }
internal Vector3 Size { get; set; }
private OSCADObject obj;
/// <summary>
@ -22,7 +22,7 @@ namespace OSCADSharp.Transforms
/// </summary>
/// <param name="obj">The object(s) to be resized</param>
/// <param name="size">The size to resize to, in terms of x/y/z dimensions</param>
public ResizedObject(OSCADObject obj, Vector3 size)
internal ResizedObject(OSCADObject obj, Vector3 size)
{
this.obj = obj;
this.Size = size;

View File

@ -9,15 +9,20 @@ namespace OSCADSharp.Transforms
/// <summary>
/// An object with rotation applied
/// </summary>
public class RotatedObject
internal class RotatedObject : OSCADObject
{
/// <summary>
/// The angle to rotate, in terms of X/Y/Z euler angles
/// </summary>
public Vector3 Angle { get; set; } = new Vector3();
internal Vector3 Angle { get; set; } = new Vector3();
private OSCADObject obj;
public RotatedObject(OSCADObject obj, Vector3 angle)
/// <summary>
/// Creates an object with rotation applied
/// </summary>
/// <param name="obj">The object being rotated</param>
/// <param name="angle">The angle to rotate</param>
internal RotatedObject(OSCADObject obj, Vector3 angle)
{
this.obj = obj;
this.Angle = angle;

View File

@ -9,12 +9,12 @@ namespace OSCADSharp.Transforms
/// <summary>
/// An object that's been rescaled
/// </summary>
public class ScaledObject
internal class ScaledObject : OSCADObject
{
/// <summary>
/// The scale factor to be applied
/// </summary>
public Vector3 Scale { get; set; } = new Vector3(1, 1, 1);
internal Vector3 ScaleFactor { get; set; } = new Vector3(1, 1, 1);
private OSCADObject obj;
/// <summary>
@ -22,16 +22,16 @@ namespace OSCADSharp.Transforms
/// </summary>
/// <param name="obj">Object(s) to be scaled</param>
/// <param name="scale">Scale factor in x/y/z components</param>
public ScaledObject(OSCADObject obj, Vector3 scale)
internal ScaledObject(OSCADObject obj, Vector3 scale)
{
this.obj = obj;
this.Scale = scale;
this.ScaleFactor = scale;
}
public override string ToString()
{
string scaleCommand = String.Format("scale(v = [{0}, {1}, {2}])",
this.Scale.X.ToString(), this.Scale.Y.ToString(), this.Scale.Z.ToString());
this.ScaleFactor.X.ToString(), this.ScaleFactor.Y.ToString(), this.ScaleFactor.Z.ToString());
var formatter = new BlockFormatter(scaleCommand, this.obj.ToString());
return formatter.ToString();
}

View File

@ -9,9 +9,9 @@ namespace OSCADSharp.Transforms
/// <summary>
/// An object or objects that have been moved along the specified vector
/// </summary>
public class TranslatedObject
internal class TranslatedObject : OSCADObject
{
public Vector3 Vector { get; set; }
internal Vector3 Vector { get; set; }
private OSCADObject obj;
/// <summary>
@ -19,7 +19,7 @@ namespace OSCADSharp.Transforms
/// </summary>
/// <param name="obj">Object(s) to translate</param>
/// <param name="vector">Amount to translate by</param>
public TranslatedObject(OSCADObject obj, Vector3 vector)
internal TranslatedObject(OSCADObject obj, Vector3 vector)
{
this.obj = obj;
this.Vector = vector;