Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/tsvilans/glulamb
Browse files Browse the repository at this point in the history
  • Loading branch information
tsvilans committed Feb 18, 2021
2 parents 8d1bd9f + 17abba4 commit ea0f4c3
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 81 deletions.
89 changes: 89 additions & 0 deletions GluLamb.GH/Create/Cmpt_CreateGlulamBeamElement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* GluLamb
* A constrained glulam modelling toolkit.
* Copyright 2020 Tom Svilans
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

using System;
using System.Collections.Generic;
using System.Linq;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Types;
using Rhino.Geometry;

namespace GluLamb.GH.Components
{
public class Cmpt_CreateGlulamBeamElement : GH_Component
{
public Cmpt_CreateGlulamBeamElement()
: base("Glulam Beam", "GBeam",
"Create glulam beam element.",
"GluLamb", "Create")
{
}


protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddTextParameter("Name", "N", "Name of glulam beam.", GH_ParamAccess.item, "GlulamBeamElement");
pManager.AddGenericParameter("Glulam", "G", "Glulam blank.", GH_ParamAccess.item);
pManager.AddPlaneParameter("Plane", "P", "Handle for element (baseplane).", GH_ParamAccess.item);

pManager[0].Optional = true;
pManager[2].Optional = true;
}

protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddGenericParameter("Element", "E", "Glulam beam element.", GH_ParamAccess.item);
}

protected override void SolveInstance(IGH_DataAccess DA)
{
Glulam glulam = null;

if (!DA.GetData("Glulam", ref glulam))
return;

string name = "GlulamBeamElement";
DA.GetData("Name", ref name);

Plane handle = Plane.Unset;
DA.GetData("Plane", ref handle);

BeamElement beam_element;
if (handle == Plane.Unset)
beam_element = new BeamElement(glulam, name);
else
beam_element = new BeamElement(glulam, handle, name);

DA.SetData("Element", new GH_Element(beam_element));
}

protected override System.Drawing.Bitmap Icon
{
get
{
return Properties.Resources.glulamb_FreeformGlulam_24x24;
}
}

public override Guid ComponentGuid
{
get { return new Guid("950B8230-422B-45D0-A5EA-01FE2E446E8A"); }
}
}
}
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)
{
}
}
*/
}
Loading

0 comments on commit ea0f4c3

Please sign in to comment.