From 847652a9c7194336ec5af8b2072babdcf1ca1a55 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Sun, 21 Feb 2016 16:30:59 -0800 Subject: [PATCH] Added "Name" as an optional identifier for OSCADObjects --- OSCADSharp/OSCADSharp/OSCADObject.cs | 17 ++++++++++++++++- .../Scripting/MultiBlockStatementObject.cs | 5 ++++- OSCADSharp/OSCADSharp/Solids/Cube.cs | 1 + OSCADSharp/OSCADSharp/Solids/Cylinder.cs | 1 + OSCADSharp/OSCADSharp/Solids/Sphere.cs | 1 + OSCADSharp/OSCADSharp/Solids/Text3D.cs | 1 + .../OSCADSharp/Transforms/ColoredObject.cs | 5 ++++- .../Transforms/LinearExtrudedObject.cs | 5 ++++- .../OSCADSharp/Transforms/MirroredObject.cs | 5 ++++- .../OSCADSharp/Transforms/ResizedObject.cs | 5 ++++- .../OSCADSharp/Transforms/RotatedObject.cs | 5 ++++- .../OSCADSharp/Transforms/ScaledObject.cs | 5 ++++- .../OSCADSharp/Transforms/TranslatedObject.cs | 5 ++++- 13 files changed, 52 insertions(+), 9 deletions(-) diff --git a/OSCADSharp/OSCADSharp/OSCADObject.cs b/OSCADSharp/OSCADSharp/OSCADObject.cs index a8d259d..7d70590 100644 --- a/OSCADSharp/OSCADSharp/OSCADObject.cs +++ b/OSCADSharp/OSCADSharp/OSCADObject.cs @@ -16,7 +16,7 @@ namespace OSCADSharp /// public abstract class OSCADObject { - #region Fields + #region Attributes private uint id = Ids.Get(); /// @@ -24,6 +24,11 @@ namespace OSCADSharp /// these values auto-increment /// public uint Id { get { return this.id; } } + + /// + /// Name of this OSCADObject + /// + public string Name { get; set; } = null; #endregion #region Transforms @@ -288,6 +293,16 @@ namespace OSCADSharp return allChildren; } + /// + /// Retrieves children that match the filtering predicate + /// + /// An expression like Linq's .Where() clause + /// + public IEnumerable Children(Func predicate) + { + return this.Children().Where(predicate); + } + /// /// Copies the transforms that have been applied to another OSCADObject, and applies /// the same transforms to this object. (Only pure transforms, like Translate, Rotate, Scale, Color) diff --git a/OSCADSharp/OSCADSharp/Scripting/MultiBlockStatementObject.cs b/OSCADSharp/OSCADSharp/Scripting/MultiBlockStatementObject.cs index ce7c1ec..f1a8c7c 100644 --- a/OSCADSharp/OSCADSharp/Scripting/MultiBlockStatementObject.cs +++ b/OSCADSharp/OSCADSharp/Scripting/MultiBlockStatementObject.cs @@ -42,7 +42,10 @@ namespace OSCADSharp.Scripting childClones.Add(child.Clone()); } - return new MultiBlockStatementObject(this.outerStatement, childClones); + return new MultiBlockStatementObject(this.outerStatement, childClones) + { + Name = this.Name + }; } public override Vector3 Position() diff --git a/OSCADSharp/OSCADSharp/Solids/Cube.cs b/OSCADSharp/OSCADSharp/Solids/Cube.cs index 60d87a0..50e85b8 100644 --- a/OSCADSharp/OSCADSharp/Solids/Cube.cs +++ b/OSCADSharp/OSCADSharp/Solids/Cube.cs @@ -82,6 +82,7 @@ namespace OSCADSharp.Solids { return new Cube() { + Name = this.Name, Size = this.Size, Center = this.Center }; diff --git a/OSCADSharp/OSCADSharp/Solids/Cylinder.cs b/OSCADSharp/OSCADSharp/Solids/Cylinder.cs index b06c754..5fe08b8 100644 --- a/OSCADSharp/OSCADSharp/Solids/Cylinder.cs +++ b/OSCADSharp/OSCADSharp/Solids/Cylinder.cs @@ -138,6 +138,7 @@ namespace OSCADSharp.Solids { return new Cylinder() { + Name = this.Name, Height = this.Height, Radius1 = this.Radius1, Radius2 = this.Radius2, diff --git a/OSCADSharp/OSCADSharp/Solids/Sphere.cs b/OSCADSharp/OSCADSharp/Solids/Sphere.cs index 9fd82e4..766decb 100644 --- a/OSCADSharp/OSCADSharp/Solids/Sphere.cs +++ b/OSCADSharp/OSCADSharp/Solids/Sphere.cs @@ -83,6 +83,7 @@ namespace OSCADSharp.Solids { return new Sphere() { + Name = this.Name, Resolution = this.Resolution, MinimumAngle = this.MinimumAngle, MinimumFragmentSize = this.MinimumFragmentSize, diff --git a/OSCADSharp/OSCADSharp/Solids/Text3D.cs b/OSCADSharp/OSCADSharp/Solids/Text3D.cs index 9f07cf1..180cfd4 100644 --- a/OSCADSharp/OSCADSharp/Solids/Text3D.cs +++ b/OSCADSharp/OSCADSharp/Solids/Text3D.cs @@ -80,6 +80,7 @@ namespace OSCADSharp.Solids { return new Text3D() { + Name = this.Name, Text = this.Text, Size = this.Size, Font = this.Font, diff --git a/OSCADSharp/OSCADSharp/Transforms/ColoredObject.cs b/OSCADSharp/OSCADSharp/Transforms/ColoredObject.cs index 7f7aae1..e0e2e26 100644 --- a/OSCADSharp/OSCADSharp/Transforms/ColoredObject.cs +++ b/OSCADSharp/OSCADSharp/Transforms/ColoredObject.cs @@ -44,7 +44,10 @@ namespace OSCADSharp.Transforms public override OSCADObject Clone() { - return new ColoredObject(this.obj.Clone(), this.ColorName, this.Opacity); + return new ColoredObject(this.obj.Clone(), this.ColorName, this.Opacity) + { + Name = this.Name + }; } public OSCADObject MimicObject(OSCADObject obj) diff --git a/OSCADSharp/OSCADSharp/Transforms/LinearExtrudedObject.cs b/OSCADSharp/OSCADSharp/Transforms/LinearExtrudedObject.cs index ee21a6d..0467bb6 100644 --- a/OSCADSharp/OSCADSharp/Transforms/LinearExtrudedObject.cs +++ b/OSCADSharp/OSCADSharp/Transforms/LinearExtrudedObject.cs @@ -39,7 +39,10 @@ namespace OSCADSharp.Transforms public override OSCADObject Clone() { - return new LinearExtrudedObject(this.obj.Clone(), this.Height); + return new LinearExtrudedObject(this.obj.Clone(), this.Height) + { + Name = this.Name + }; } public override string ToString() diff --git a/OSCADSharp/OSCADSharp/Transforms/MirroredObject.cs b/OSCADSharp/OSCADSharp/Transforms/MirroredObject.cs index a38a938..8b555da 100644 --- a/OSCADSharp/OSCADSharp/Transforms/MirroredObject.cs +++ b/OSCADSharp/OSCADSharp/Transforms/MirroredObject.cs @@ -43,7 +43,10 @@ namespace OSCADSharp.Transforms public override OSCADObject Clone() { - return new MirroredObject(this.obj.Clone(), this.Normal); + return new MirroredObject(this.obj.Clone(), this.Normal) + { + Name = this.Name + }; } public OSCADObject MimicObject(OSCADObject obj) diff --git a/OSCADSharp/OSCADSharp/Transforms/ResizedObject.cs b/OSCADSharp/OSCADSharp/Transforms/ResizedObject.cs index fc0d034..fb6b361 100644 --- a/OSCADSharp/OSCADSharp/Transforms/ResizedObject.cs +++ b/OSCADSharp/OSCADSharp/Transforms/ResizedObject.cs @@ -42,7 +42,10 @@ namespace OSCADSharp.Transforms public override OSCADObject Clone() { - return new ResizedObject(this.obj.Clone(), this.Size); + return new ResizedObject(this.obj.Clone(), this.Size) + { + Name = this.Name + }; } public OSCADObject MimicObject(OSCADObject obj) diff --git a/OSCADSharp/OSCADSharp/Transforms/RotatedObject.cs b/OSCADSharp/OSCADSharp/Transforms/RotatedObject.cs index 4dc01ce..88c73d4 100644 --- a/OSCADSharp/OSCADSharp/Transforms/RotatedObject.cs +++ b/OSCADSharp/OSCADSharp/Transforms/RotatedObject.cs @@ -42,7 +42,10 @@ namespace OSCADSharp.Transforms public override OSCADObject Clone() { - return new RotatedObject(this.obj.Clone(), this.Angle); + return new RotatedObject(this.obj.Clone(), this.Angle) + { + Name = this.Name + }; } public OSCADObject MimicObject(OSCADObject obj) diff --git a/OSCADSharp/OSCADSharp/Transforms/ScaledObject.cs b/OSCADSharp/OSCADSharp/Transforms/ScaledObject.cs index 138fd3f..e6f59f9 100644 --- a/OSCADSharp/OSCADSharp/Transforms/ScaledObject.cs +++ b/OSCADSharp/OSCADSharp/Transforms/ScaledObject.cs @@ -42,7 +42,10 @@ namespace OSCADSharp.Transforms public override OSCADObject Clone() { - return new ScaledObject(this.obj.Clone(), this.ScaleFactor); + return new ScaledObject(this.obj.Clone(), this.ScaleFactor) + { + Name = this.Name + }; } public OSCADObject MimicObject(OSCADObject obj) diff --git a/OSCADSharp/OSCADSharp/Transforms/TranslatedObject.cs b/OSCADSharp/OSCADSharp/Transforms/TranslatedObject.cs index 25e672b..a820447 100644 --- a/OSCADSharp/OSCADSharp/Transforms/TranslatedObject.cs +++ b/OSCADSharp/OSCADSharp/Transforms/TranslatedObject.cs @@ -39,7 +39,10 @@ namespace OSCADSharp.Transforms public override OSCADObject Clone() { - return new TranslatedObject(this.obj.Clone(), this.Vector); + return new TranslatedObject(this.obj.Clone(), this.Vector) + { + Name = this.Name + }; } public OSCADObject MimicObject(OSCADObject obj)