Skip to content

Commit

Permalink
feat(goo): add GH_Element and GH_Structure classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Svilans committed Nov 19, 2020
1 parent 36961d2 commit 22a711a
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 80 deletions.
193 changes: 114 additions & 79 deletions GluLamb.GH/GluLambGoo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,123 +280,158 @@ public override bool Read(GH_IReader reader)
}
#endregion
}
/*
public class GH_GlulamWorkpiece : GH_Goo<GlulamWorkpiece>, IGH_PreviewData

public class GH_Element : GH_Goo<Element>
{
public GH_GlulamWorkpiece() { this.Value = null; }
public GH_GlulamWorkpiece(GH_GlulamWorkpiece goo) { this.Value = goo.Value; }
public GH_GlulamWorkpiece(GlulamWorkpiece native) { this.Value = native; }
public override IGH_Goo Duplicate() => new GH_GlulamWorkpiece(this);
public override bool IsValid => true;
public override string TypeName => "GluLamb Workpiece";
public override string TypeDescription => "GluLamb Workpiece";
public override string ToString() => Value.ToString(); //this.Value.ToString();
#region Constructors
public GH_Element() : this(null) { }
public GH_Element(Element native) { this.Value = native; }

public override IGH_Goo Duplicate()
{
if (Value == null)
return new GH_Element();
else
return new GH_Element(Value.Duplicate());
}
#endregion

public static Element ParseGlulam(object obj)
{
if (obj is GH_Element)
return (obj as GH_Element).Value;
else
return obj as Element;
}
public override string ToString()
{
if (Value == null) return "Null glulam element";
return Value.ToString();
}

public override string TypeName => "GlulamElementGoo";
public override string TypeDescription => "GlulamElementGoo";
public override object ScriptVariable() => Value;

public override bool CastFrom(object source)
public override bool IsValid
{
if (source is GlulamWorkpiece)
get
{
Value = source as GlulamWorkpiece;
if (Value == null) return false;
return true;
}
if (source is GH_GlulamWorkpiece)
}
public override string IsValidWhyNot
{
get
{
Value = (source as GH_GlulamWorkpiece).Value;
return true;
if (Value == null) return "No data";
return string.Empty;
}
if (source is Glulam)
}

#region Casting
public override bool CastFrom(object source)
{
if (source == null) return false;
if (source is Element glulam)
{
Value = new GlulamWorkpiece(new BasicAssembly(source as Glulam));
Value = glulam;
return true;
}
if (source is GH_Glulam)
if (source is GH_Element ghGlulam)
{
Value = new GlulamWorkpiece(new BasicAssembly((source as GH_Glulam).Value));
Value = ghGlulam.Value;
return true;
}
return false;
}

public override bool CastTo<Q>(ref Q target)
{
if (typeof(Q).IsAssignableFrom(typeof(GH_Mesh)))
{
Mesh[] meshes = Value.GetMesh();
Mesh m = new Mesh();
for (int i = 0; i < meshes.Length; ++i)
{
m.Append(meshes[i]);
}
object mesh = new GH_Mesh(m);
if (Value == null) return false;

target = (Q)mesh;
return true;
}
if (typeof(Q).IsAssignableFrom(typeof(GlulamWorkpiece)))
return false;
}

#endregion

}

public class GH_Structure : GH_Goo<Structure>
{
#region Constructors
public GH_Structure() : this(null) { }
public GH_Structure(Structure native) { this.Value = native; }

public override IGH_Goo Duplicate()
{
if (Value == null)
return new GH_Structure();
else
return new GH_Structure(Value.Duplicate());
}
#endregion

public static Structure ParseStructure(object obj)
{
if (obj is GH_Structure)
return (obj as GH_Structure).Value;
else
return obj as Structure;
}
public override string ToString()
{
if (Value == null) return "Null glulam structure";
return Value.ToString();
}

public override string TypeName => "GlulamStructureGoo";
public override string TypeDescription => "GlulamStructureGoo";
public override object ScriptVariable() => Value;

public override bool IsValid
{
get
{
object blank = Value;
target = (Q)blank;
if (Value == null) return false;
return true;
}
if (typeof(Q).IsAssignableFrom(typeof(GH_Brep)))
}
public override string IsValidWhyNot
{
get
{
Brep[] breps = Value.GetBrep();
Brep b = new Brep();
for (int i = 0; i < breps.Length; ++i)
{
b.Append(breps[i]);
}
object brep = new GH_Brep(b);
target = (Q)brep;
return true;
if (Value == null) return "No data";
return string.Empty;
}
//if (typeof(Q).IsAssignableFrom(typeof(GH_)))
if (typeof(Q).IsAssignableFrom(typeof(GH_Curve)))
}

#region Casting
public override bool CastFrom(object source)
{
if (source == null) return false;
if (source is Structure structure)
{
Curve[] crvs = Value.Blank.GetAllGlulams().Select(x => x.Centreline).ToArray();
//target = crvs.Select(x => new GH_Curve(x)).ToList() as Q;
object crv = new GH_Curve(crvs.FirstOrDefault());
target = (Q)(crv);
Value = structure;
return true;
}
if (typeof(Q).IsAssignableFrom(typeof(List<GH_Curve>)))
if (source is GH_Structure ghStructure)
{
Curve[] crvs = Value.Blank.GetAllGlulams().Select(x => x.Centreline).ToArray();
//target = crvs.Select(x => new GH_Curve(x)).ToList() as Q;
object crv = crvs.Select(x => new GH_Curve(x)).ToList();
target = (Q)(crv);
Value = ghStructure.Value;
return true;
}
return base.CastTo<Q>(ref target);
return false;
}

BoundingBox IGH_PreviewData.ClippingBox
public override bool CastTo<Q>(ref Q target)
{
get
{
BoundingBox box = BoundingBox.Empty;
Mesh[] meshes = Value.GetMesh();
if (Value == null) return false;

for (int i = 0; i < meshes.Length; ++i)
{
box.Union(meshes[i].GetBoundingBox(true));
}
return box;
}
return false;
}

public void DrawViewportMeshes(GH_PreviewMeshArgs args)
{
//args.Pipeline.DrawMeshShaded(Value.GetBoundingMesh(), args.Material);
}
#endregion

public void DrawViewportWires(GH_PreviewWireArgs args)
{
}
}
*/
}
6 changes: 6 additions & 0 deletions GluLamb/Structure/Element.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public Element(Plane handle, string name = "")
m_plane = handle;
}

public Element Duplicate()
{
// TODO
return this;
}

public Plane Handle
{
get
Expand Down
7 changes: 7 additions & 0 deletions GluLamb/Structure/ElementGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ public ElementGroup(string name = "ElementGroup")
Name = name;
//m_elements = new List<Element>();
}

public ElementGroup Duplicate()
{
// TODO
return this;
}

/*
public int Count
{
Expand Down
6 changes: 5 additions & 1 deletion GluLamb/Structure/Structure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ public Structure()
Elements = new List<Element>();
Groups = new Dictionary<string, List<Element>>();
}

public Structure Duplicate()
{
// TODO
return this;
}
public static Structure FromBeamElements(List<BeamElement> elements, double searchDistance, double overlapDistance)
{
int counter = 0;
Expand Down

0 comments on commit 22a711a

Please sign in to comment.