Skip to content

Commit

Permalink
Merge pull request #131 from hrntsm/feature/bake-brep
Browse files Browse the repository at this point in the history
Add brep bake
  • Loading branch information
hrntsm authored Jul 18, 2021
2 parents 5c0cd53 + 4681316 commit e17887b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
51 changes: 49 additions & 2 deletions HoaryFox/Component_v2/Geometry/Stb2Brep.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using Grasshopper.Kernel;
using HoaryFox.Component_v2.Utils.Geometry;
using HoaryFox.Properties;
using Rhino;
using Rhino.DocObjects;
using Rhino.Geometry;
using STBDotNet.v202;

Expand Down Expand Up @@ -50,17 +53,22 @@ protected override void SolveInstance(IGH_DataAccess dataAccess)
if (!dataAccess.GetData("Data", ref _stBridge)) { return; }
if (!dataAccess.GetData("Bake", ref isBake)) { return; }

MakeBrep();
CreateBrep();
if (isBake)
{
BakeBrep();
}

for (var i = 0; i < 7; i++)
{
dataAccess.SetDataList(i, _brepList[i]);
}
}

protected override Bitmap Icon => Resource.Brep;
public override Guid ComponentGuid => new Guid("B2D5EA7F-E75F-406B-8D22-C267B43C5E72");

private void MakeBrep()
private void CreateBrep()
{
StbMembers member = _stBridge.StbModel.StbMembers;
var brepFromStb = new CreateBrepFromStb(_stBridge.StbModel.StbSections, _stBridge.StbModel.StbNodes, new[] { DocumentTolerance(), DocumentAngleTolerance() });
Expand All @@ -72,5 +80,44 @@ private void MakeBrep()
_brepList.Add(brepFromStb.Slab(member.StbSlabs));
_brepList.Add(brepFromStb.Wall(member.StbWalls));
}

private void BakeBrep()
{
RhinoDoc activeDoc = RhinoDoc.ActiveDoc;
var parentLayerNames = new[] { "Column", "Girder", "Post", "Beam", "Brace", "Slab", "Wall" };
Color[] layerColors = { Color.Red, Color.Green, Color.Aquamarine, Color.LightCoral, Color.MediumPurple, Color.DarkGray, Color.CornflowerBlue };
GeometryBaker.MakeParentLayers(activeDoc, parentLayerNames, layerColors);

Dictionary<string, string>[][] infoArray = Utils.TagUtils.GetAllSectionInfoArray(_stBridge.StbModel.StbMembers);

foreach ((List<Brep> breps, int index) in _brepList.Select((frameBrep, index) => (frameBrep, index)))
{
Layer parentLayer = activeDoc.Layers.FindName(parentLayerNames[index]);
Guid parentId = parentLayer.Id;
foreach ((Brep brep, int bIndex) in breps.Select((brep, bIndex) => (brep, bIndex)))
{
var objAttr = new ObjectAttributes();

Dictionary<string, string>[] infos = infoArray[index];
Dictionary<string, string> info = infos[bIndex];

foreach (KeyValuePair<string, string> pair in info)
{
objAttr.SetUserString(pair.Key, pair.Value);
}

var layer = new Layer { Name = info["name"], ParentLayerId = parentId, Color = layerColors[index] };
int layerIndex = activeDoc.Layers.Add(layer);
if (layerIndex == -1)
{
layer = activeDoc.Layers.FindName(info["name"]);
layerIndex = layer.Index;
}
objAttr.LayerIndex = layerIndex;

activeDoc.Objects.AddBrep(brep, objAttr);
}
}
}
}
}
6 changes: 3 additions & 3 deletions HoaryFox/Component_v2/Utils/TagUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ internal static IEnumerable<GH_String> GetColumnSSection(object steelFigure)

public static Dictionary<string, string>[][] GetAllSectionInfoArray(StbMembers members)
{
var allTagList = new Dictionary<string, string>[5][];
var allTagList = new Dictionary<string, string>[7][];

var memberArray = new object[][] { members.StbColumns, members.StbGirders, members.StbPosts, members.StbBeams, members.StbBraces };
for (var i = 0; i < 5; i++)
var memberArray = new object[][] { members.StbColumns, members.StbGirders, members.StbPosts, members.StbBeams, members.StbBraces, members.StbSlabs, members.StbWalls };
for (var i = 0; i < 7; i++)
{
allTagList[i] = memberArray[i] != null ? StbMembersToDictArray(memberArray[i]) : Array.Empty<Dictionary<string, string>>();
}
Expand Down

0 comments on commit e17887b

Please sign in to comment.