Skip to content

Commit

Permalink
Merge pull request #113 from hrntsm/feature/add-bake-more-info
Browse files Browse the repository at this point in the history
Feature/add bake more info
  • Loading branch information
hrntsm authored Jul 7, 2021
2 parents 4fe44e2 + 6856f81 commit 74c8c93
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 30 deletions.
4 changes: 1 addition & 3 deletions HoaryFox/Component_v2/Geometry/Stb2Line.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,12 @@ private void BakeLine()
foreach ((Line line, int bIndex) in lines.Select((brep, bIndex) => (brep, bIndex)))
{
var objAttr = new ObjectAttributes();
objAttr.SetUserString("Type", parentLayerNames[index]);

if (index < 5)
{
Dictionary<string, string>[] infos = infoArray[index];
Dictionary<string, string> info = infos[bIndex];
// Misc.SetFrameUserString(ref objAttr, tag);

foreach (KeyValuePair<string, string> pair in info)
{
objAttr.SetUserString(pair.Key, pair.Value);
Expand All @@ -112,7 +111,6 @@ private void BakeLine()
activeDoc.Objects.AddLine(line, objAttr);
}
}

}

private void CreateLine()
Expand Down
71 changes: 44 additions & 27 deletions HoaryFox/Component_v2/Utils/TagUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Xml;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;
using Rhino.Geometry;
using STBDotNet.v202;


namespace HoaryFox.Component_v2.Utils
{
internal static class TagUtils
Expand Down Expand Up @@ -123,34 +123,51 @@ public static Dictionary<string, string>[][] GetAllSectionInfoArray(StbMembers m
{
var allTagList = new Dictionary<string, string>[5][];

// TODO: 必要な中身をDictionaryで返すようにする
allTagList[0] = members.StbColumns != null
? members.StbColumns
.Select(column => column.name)
.Select(s => new Dictionary<string, string> { { "name", s }, { "StbElementName", "StbColumn" } }).ToArray()
: new Dictionary<string, string>[] { };
allTagList[1] = members.StbGirders != null
? members.StbGirders
.Select(column => column.name)
.Select(s => new Dictionary<string, string> { { "name", s }, { "StbElementName", "StbGirder" } }).ToArray()
: new Dictionary<string, string>[] { };
allTagList[2] = members.StbPosts != null
? members.StbPosts
.Select(column => column.name)
.Select(s => new Dictionary<string, string> { { "name", s }, { "StbElementName", "StbPost" } }).ToArray()
: new Dictionary<string, string>[] { };
allTagList[3] = members.StbBeams != null
? members.StbBeams
.Select(column => column.name)
.Select(s => new Dictionary<string, string> { { "name", s }, { "StbElementName", "StbBeam" } }).ToArray()
: new Dictionary<string, string>[] { };
allTagList[4] = members.StbBraces != null
? members.StbBraces
.Select(column => column.name)
.Select(s => new Dictionary<string, string> { { "name", s }, { "StbElementName", "StbBrace" } }).ToArray()
: new Dictionary<string, string>[] { };
var memberArray = new object[][] { members.StbColumns, members.StbGirders, members.StbPosts, members.StbBeams, members.StbBraces };
for (var i = 0; i < 5; i++)
{
allTagList[i] = memberArray[i] != null ? StbMembersToDictArray(memberArray[i]) : new Dictionary<string, string>[] { };
}

return allTagList;
}

private static Dictionary<string, string>[] StbMembersToDictArray(IReadOnlyList<object> members)
{
var propertiesArray = new Dictionary<string, string>[members.Count];

object item = members[0];
Type t = item.GetType();

foreach ((object column, int index) in members.Select((column, index) => (column, index)))
{
propertiesArray[index] = GetMemberInfoDictionary(t, column);
}

return propertiesArray;
}

private static Dictionary<string, string> GetMemberInfoDictionary(Type type, object member)
{
PropertyInfo[] props = type.GetProperties();
var instanceProps = new Dictionary<string, string> { { "stb_element_type", type.Name } };
foreach (PropertyInfo prop in props)
{
if (prop.GetValue(member) == null)
{
continue;
}
try
{
instanceProps.Add(prop.Name, prop.GetValue(member).ToString());
}
catch
{
// ignored
}
}

return instanceProps;
}
}
}
3 changes: 3 additions & 0 deletions HoaryFox/HoaryFox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@
<Version>6.20.19322.20361</Version>
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.1</Version>
</PackageReference>
<PackageReference Include="RhinoCommon">
<Version>6.20.19322.20361</Version>
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down

0 comments on commit 74c8c93

Please sign in to comment.