mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-12 05:58:34 +00:00
Added Clone() method to OSCADObject and all descendants
This commit is contained in:
parent
49fcccc8df
commit
1449cdd2b2
@ -2,6 +2,7 @@
|
||||
using OSCADSharp.Transforms;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -14,7 +15,7 @@ namespace OSCADSharp.ConsoleTests
|
||||
{
|
||||
OSCADObject cube = new Cube()
|
||||
{
|
||||
Size = new Vector3(5, 5, 5),
|
||||
Size = new Vector3(15, 15, 15),
|
||||
Center = false
|
||||
};
|
||||
|
||||
@ -27,13 +28,17 @@ namespace OSCADSharp.ConsoleTests
|
||||
|
||||
OSCADObject cylinder = new Cylinder()
|
||||
{
|
||||
Diameter = 25.4,
|
||||
Diameter = 35.4,
|
||||
Height = 50.8
|
||||
}.Translate(10, 5, 2);
|
||||
|
||||
var combined = cube.Intersection(cylinder);
|
||||
var combined = cube.Intersection(cylinder).Color("Blue");
|
||||
combined = cube.Clone().Mirror(0, 0, 1).Union(combined);
|
||||
|
||||
Console.WriteLine(combined.ToString());
|
||||
string script = combined.ToString();
|
||||
File.WriteAllLines("test.scad", new string[] { script });
|
||||
|
||||
Console.WriteLine(script);
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,6 +18,6 @@ namespace OSCADSharp.Booleans
|
||||
/// <param name="children"></param>
|
||||
public Difference(IEnumerable<OSCADObject> children) : base("difference()", children)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -182,5 +182,14 @@ namespace OSCADSharp
|
||||
return factory(children);
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Creates a copy of this object and all of its children
|
||||
///
|
||||
/// This is not a deep copy in the sense that all OSCADObjects will be new instances,
|
||||
/// but any complex objects used as parameters (Such as Vector3s) will be referenced by the copies
|
||||
/// </summary>
|
||||
/// <returns>Clone of this object</returns>
|
||||
public abstract OSCADObject Clone();
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,11 +27,22 @@ namespace OSCADSharp.Scripting
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (var child in this.children)
|
||||
{
|
||||
sb.AppendLine(child.ToString());
|
||||
sb.Append(child.ToString());
|
||||
}
|
||||
|
||||
var formatter = new BlockFormatter(this.outerStatement, sb.ToString());
|
||||
return formatter.ToString();
|
||||
}
|
||||
|
||||
public override OSCADObject Clone()
|
||||
{
|
||||
List<OSCADObject> childClones = new List<OSCADObject>();
|
||||
foreach (var child in this.children)
|
||||
{
|
||||
childClones.Add(child.Clone());
|
||||
}
|
||||
|
||||
return new BlockStatementObject(this.outerStatement, childClones);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,5 +30,14 @@ namespace OSCADSharp.Solids
|
||||
return String.Format("cube(size = [{0}, {1}, {2}], center = {3});",
|
||||
this.Size.X.ToString(), this.Size.Y.ToString(), this.Size.Z.ToString(), this.Center.ToString().ToLower()); ;
|
||||
}
|
||||
|
||||
public override OSCADObject Clone()
|
||||
{
|
||||
return new Cube()
|
||||
{
|
||||
Size = this.Size,
|
||||
Center = this.Center
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,5 +101,19 @@ namespace OSCADSharp.Solids
|
||||
Resolution.ToString(), MinimumAngle.ToString(), MinimumCircumferentialLength.ToString(),
|
||||
Height.ToString(), Radius1.ToString(), Radius2.ToString(), Center.ToString().ToLower());
|
||||
}
|
||||
|
||||
public override OSCADObject Clone()
|
||||
{
|
||||
return new Cylinder()
|
||||
{
|
||||
Height = this.Height,
|
||||
Radius1 = this.Radius1,
|
||||
Radius2 = this.Radius2,
|
||||
Resolution = this.Resolution,
|
||||
MinimumAngle = this.MinimumAngle,
|
||||
MinimumCircumferentialLength = this.MinimumCircumferentialLength,
|
||||
Center = this.Center
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,5 +50,16 @@ namespace OSCADSharp.Solids
|
||||
this.Resolution.ToString(), this.MinimumAngle.ToString(),
|
||||
this.MinimumFragmentSize.ToString(), this.Radius.ToString());
|
||||
}
|
||||
|
||||
public override OSCADObject Clone()
|
||||
{
|
||||
return new Sphere()
|
||||
{
|
||||
Resolution = this.Resolution,
|
||||
MinimumAngle = this.MinimumAngle,
|
||||
MinimumFragmentSize = this.MinimumFragmentSize,
|
||||
Radius = this.Radius
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,5 +38,10 @@ namespace OSCADSharp.Transforms
|
||||
var formatter = new BlockFormatter(colorCommand, this.obj.ToString());
|
||||
return formatter.ToString();
|
||||
}
|
||||
|
||||
public override OSCADObject Clone()
|
||||
{
|
||||
return new ColoredObject(this.obj, this.ColorName, this.Opacity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,5 +37,10 @@ namespace OSCADSharp.Transforms
|
||||
var formatter = new BlockFormatter(mirrorCommand, this.obj.ToString());
|
||||
return formatter.ToString();
|
||||
}
|
||||
|
||||
public override OSCADObject Clone()
|
||||
{
|
||||
return new MirroredObject(this.obj, this.Normal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,5 +36,10 @@ namespace OSCADSharp.Transforms
|
||||
var formatter = new BlockFormatter(resizeCommand, this.obj.ToString());
|
||||
return formatter.ToString();
|
||||
}
|
||||
|
||||
public override OSCADObject Clone()
|
||||
{
|
||||
return new ResizedObject(this.obj, this.Size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,5 +36,10 @@ namespace OSCADSharp.Transforms
|
||||
var formatter = new BlockFormatter(rotateCommand, this.obj.ToString());
|
||||
return formatter.ToString();
|
||||
}
|
||||
|
||||
public override OSCADObject Clone()
|
||||
{
|
||||
return new RotatedObject(this.obj, this.Angle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,5 +36,10 @@ namespace OSCADSharp.Transforms
|
||||
var formatter = new BlockFormatter(scaleCommand, this.obj.ToString());
|
||||
return formatter.ToString();
|
||||
}
|
||||
|
||||
public override OSCADObject Clone()
|
||||
{
|
||||
return new ScaledObject(this.obj, this.ScaleFactor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,5 +33,10 @@ namespace OSCADSharp.Transforms
|
||||
var formatter = new BlockFormatter(translateCommmand, this.obj.ToString());
|
||||
return formatter.ToString();
|
||||
}
|
||||
|
||||
public override OSCADObject Clone()
|
||||
{
|
||||
return new TranslatedObject(this.obj, this.Vector);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user