Skip to content

Commit

Permalink
Release v1.3.1
Browse files Browse the repository at this point in the history
Release v1.3.1
  • Loading branch information
hrntsm committed Mar 28, 2021
2 parents 727d99e + 8dce64d commit 2943bf7
Show file tree
Hide file tree
Showing 19 changed files with 424 additions and 86 deletions.
2 changes: 1 addition & 1 deletion HoaryFox/Component/Base/SecTagBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public override void DrawViewportWires(IGH_PreviewArgs args)
private void GetTag(StbFrame stbFrame)
{
var tags = new CreateTag(_stbData.Nodes, _stbData.SecColumnRc, _stbData.SecColumnS, _stbData.SecBeamRc, _stbData.SecBeamS, _stbData.SecBraceS, _stbData.SecSteel);
_frameTags = tags.Frame(stbFrame);
_frameTags = tags.FrameGHStructure(stbFrame);
_tagPos = tags.Position;
}
}
Expand Down
86 changes: 68 additions & 18 deletions HoaryFox/Component/Geometry/Stb2Brep.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using Grasshopper.Kernel;
using HoaryFox.Member;
using HoaryFox.Properties;
using Rhino;
using Rhino.DocObjects;
using Rhino.Geometry;
using STBReader;
using STBReader.Member;
Expand All @@ -12,9 +17,7 @@ public class Stb2Brep : GH_Component
{
private StbData _stbData;

private List<Brep> _slabBreps = new List<Brep>();
private List<Brep> _wallBreps = new List<Brep>();
private readonly List<List<Brep>> _frameBreps = new List<List<Brep>>();
private readonly List<List<Brep>> _geometryBreps = new List<List<Brep>>();

public Stb2Brep()
: base("Stb to Brep", "S2B", "Read ST-Bridge file and display", "HoaryFox", "Geometry")
Expand All @@ -24,14 +27,13 @@ public Stb2Brep()
public override void ClearData()
{
base.ClearData();
_slabBreps.Clear();
_wallBreps.Clear();
_frameBreps.Clear();
_geometryBreps.Clear();
}

protected override void RegisterInputParams(GH_InputParamManager pManager)
{
pManager.AddGenericParameter("Data", "D", "input ST-Bridge Data", GH_ParamAccess.item);
pManager.AddBooleanParameter("Bake", "Bake", "If it true, bake geometry.", GH_ParamAccess.item, false);
}

protected override void RegisterOutputParams(GH_OutputParamManager pManager)
Expand All @@ -47,35 +49,83 @@ protected override void RegisterOutputParams(GH_OutputParamManager pManager)

protected override void SolveInstance(IGH_DataAccess DA)
{
var isBake = false;
if (!DA.GetData("Data", ref _stbData)) { return; }
MakeBrep();
if (!DA.GetData("Bake", ref isBake)) { return; }
this.MakeBrep(isBake);

for (var i = 0; i < 5; i++)
for (var i = 0; i < 7; i++)
{
DA.SetDataList(i, _frameBreps[i]);
DA.SetDataList(i, _geometryBreps[i]);
}
DA.SetDataList(5, _slabBreps);
DA.SetDataList(6, _wallBreps);
}

protected override System.Drawing.Bitmap Icon => Properties.Resource.Brep;
protected override Bitmap Icon => Resource.Brep;
public override Guid ComponentGuid => new Guid("7d2f0c4e-4888-4607-8548-592104f6f06f");

private void MakeBrep()
private void MakeBrep(bool isBake)
{
var stbFrames = new List<StbFrame>
{
_stbData.Columns, _stbData.Girders, _stbData.Posts, _stbData.Beams, _stbData.Braces
};

var breps = new FrameBreps(_stbData);

_slabBreps = breps.Slab(_stbData.Slabs);
_wallBreps = breps.Wall(_stbData.Walls);

foreach (StbFrame frame in stbFrames)
{
_frameBreps.Add(breps.Frame(frame));
_geometryBreps.Add(breps.Frame(frame));
}
_geometryBreps.Add(breps.Slab(_stbData.Slabs));
_geometryBreps.Add(breps.Wall(_stbData.Walls));

if (isBake)
{
this.BakeBreps(stbFrames);
}
}

private void BakeBreps(IEnumerable<StbFrame> stbFrames)
{
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 };
Misc.MakeParentLayers(activeDoc, parentLayerNames, layerColors);

//TODO: このネストは直す
List<List<List<string>>> tagList = stbFrames.Select(stbFrame => Misc.GetTag(_stbData, stbFrame)).ToList();

foreach ((List<Brep> frameBreps, int index) in _geometryBreps.Select((frameBrep, index) => (frameBrep, index)))
{
Layer parentLayer = activeDoc.Layers.FindName(parentLayerNames[index]);
int parentIndex = parentLayer.Index;
Guid parentId = parentLayer.Id;

foreach ((Brep brep, int bIndex) in frameBreps.Select((brep, bIndex) => (brep, bIndex)))
{
var objAttr = new ObjectAttributes();
objAttr.SetUserString("Type", parentLayerNames[index]);

if (index < 5)
{
List<List<string>> tags = tagList[index];
List<string> tag = tags[bIndex];
Misc.SetFrameUserString(ref objAttr, tag);

var layer = new Layer { Name = tag[0], ParentLayerId = parentId, Color = layerColors[index] };
int layerIndex = activeDoc.Layers.Add(layer);
if (layerIndex == -1)
{
layer = activeDoc.Layers.FindName(tag[0]);
layerIndex = layer.Index;
}
objAttr.LayerIndex = layerIndex;
}
else
{
objAttr.LayerIndex = parentIndex;
}
activeDoc.Objects.AddBrep(brep, objAttr);
}
}
}
}
Expand Down
99 changes: 74 additions & 25 deletions HoaryFox/Component/Geometry/Stb2Line.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using Grasshopper.Kernel;
using HoaryFox.Member;
using Rhino;
using Rhino.DocObjects;
using Rhino.Geometry;
using STBReader;
using STBReader.Member;


namespace HoaryFox.Component.Geometry
Expand All @@ -12,11 +17,7 @@ public class Stb2Line : GH_Component
{
private StbData _stbData;
private List<Point3d> _nodes = new List<Point3d>();
private List<Line> _columns = new List<Line>();
private List<Line> _girders = new List<Line>();
private List<Line> _posts = new List<Line>();
private List<Line> _beams = new List<Line>();
private List<Line> _braces = new List<Line>();
private readonly List<List<Line>> _lineList = new List<List<Line>>();

public Stb2Line()
: base(name: "Stb to Line", nickname: "S2L", description: "Read ST-Bridge file and display", category: "HoaryFox", subCategory: "Geometry")
Expand All @@ -26,17 +27,13 @@ public Stb2Line()
public override void ClearData()
{
base.ClearData();
_nodes.Clear();
_columns.Clear();
_girders.Clear();
_posts.Clear();
_beams.Clear();
_braces.Clear();
_lineList.Clear();
}

protected override void RegisterInputParams(GH_InputParamManager pManager)
{
pManager.AddGenericParameter("Data", "D", "input ST-Bridge Data", GH_ParamAccess.item);
pManager.AddBooleanParameter("Bake", "Bake", "If it true, bake geometry.", GH_ParamAccess.item, false);
}

protected override void RegisterOutputParams(GH_OutputParamManager pManager)
Expand All @@ -51,30 +48,82 @@ protected override void RegisterOutputParams(GH_OutputParamManager pManager)

protected override void SolveInstance(IGH_DataAccess DA)
{
var isBake = false;
if (!DA.GetData("Data", ref _stbData)) { return; }
if (!DA.GetData("Bake", ref isBake)) { return; }

MakeLine();

MakeLine(isBake);
DA.SetDataList(0, _nodes);
DA.SetDataList(1, _columns);
DA.SetDataList(2, _girders);
DA.SetDataList(3, _posts);
DA.SetDataList(4, _beams);
DA.SetDataList(5, _braces);
foreach ((List<Line> geometry, int i) in _lineList.Select((geo, index) => (geo, index + 1)))
{
DA.SetDataList(i, geometry);
}
}

private void MakeLine()
private void MakeLine(bool isBake)
{
var createLines = new FrameLines(_stbData);
_nodes = createLines.Nodes();
_columns = createLines.Columns();
_girders = createLines.Girders();
_posts = createLines.Posts();
_beams = createLines.Beams();
_braces = createLines.Braces();
_lineList.Add(createLines.Columns());
_lineList.Add(createLines.Girders());
_lineList.Add(createLines.Posts());
_lineList.Add(createLines.Beams());
_lineList.Add(createLines.Braces());

if (isBake)
{
this.BakeLines();
}
}

private void BakeLines()
{
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 };
Misc.MakeParentLayers(activeDoc, parentLayerNames, layerColors);
var stbFrames = new List<StbFrame> { _stbData.Columns, _stbData.Girders, _stbData.Posts, _stbData.Beams, _stbData.Braces };

//TODO: このネストは直す
List<List<List<string>>> tagList = stbFrames.Select(stbFrame => Misc.GetTag(_stbData, stbFrame)).ToList();

foreach ((List<Line> lines, int index) in _lineList.Select((frameBrep, index) => (frameBrep, index)))
{
Layer parentLayer = activeDoc.Layers.FindName(parentLayerNames[index]);
int parentIndex = parentLayer.Index;
Guid parentId = parentLayer.Id;
foreach ((Line line, int bIndex) in lines.Select((brep, bIndex) => (brep, bIndex)))
{
var objAttr = new ObjectAttributes();
objAttr.SetUserString("Type", parentLayerNames[index]);

if (index < 5)
{
List<List<string>> tags = tagList[index];
List<string> tag = tags[bIndex];
Misc.SetFrameUserString(ref objAttr, tag);

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

activeDoc.Objects.AddLine(line, objAttr);
}
}
}

protected override System.Drawing.Bitmap Icon => Properties.Resource.Line;
protected override Bitmap Icon => Properties.Resource.Line;
public override Guid ComponentGuid => new Guid("7d2f0c4e-4888-4607-8548-592104f6f06d");
}
}
1 change: 1 addition & 0 deletions HoaryFox/HoaryFox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<Compile Include="Member\ShapeInfo.cs" />
<Compile Include="Member\SteelCroSecBrep.cs" />
<Compile Include="HoaryFoxInfo.cs" />
<Compile Include="Misc.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resource.Designer.cs">
<AutoGen>True</AutoGen>
Expand Down
7 changes: 3 additions & 4 deletions HoaryFox/Member/CreateBreps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public static IEnumerable<Brep> FromEndPoint(StbData stbData, ShapeInfo shapeInf

List<List<Point3d>> origins = GetOriginPoints(frameType, shapeInfo, angles);
List<Brep> breps = GetSecBrep(stbData, shapeType, origins, shapeInfo);
List<Brep> brepRot = ApplyRotation(breps, shapeInfo.Rotate, frameType, origins);
IEnumerable<Brep> brepRot = ApplyRotation(breps, shapeInfo.Rotate, frameType, origins);
return brepRot;
}

private static List<Brep> ApplyRotation(List<Brep> breps, double rotate, FrameType frameType, List<List<Point3d>> origins)
private static IEnumerable<Brep> ApplyRotation(IReadOnlyCollection<Brep> breps, double rotate, FrameType frameType, IReadOnlyList<List<Point3d>> origins)
{
double rotateAngle = rotate * Math.PI / 180d;
var rotationCenter = new Point3d[2];
Expand All @@ -47,11 +47,10 @@ private static List<Brep> ApplyRotation(List<Brep> breps, double rotate, FrameTy
{
b.Rotate(rotateAngle, rotationAxis, rotationCenter[0]);
}

return breps;
}

private static List<Brep> GetSecBrep(StbData stbData, ShapeTypes shapeType, List<List<Point3d>> origins, ShapeInfo shapeInfo)
private static List<Brep> GetSecBrep(StbData stbData, ShapeTypes shapeType, IReadOnlyList<List<Point3d>> origins, ShapeInfo shapeInfo)
{
var secBrep = new SteelCroSecBrep(stbData, origins);
switch (shapeType)
Expand Down
45 changes: 44 additions & 1 deletion HoaryFox/Member/CreateTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public CreateTag(StbNodes nodes, StbSecColumnRc colRc, StbSecColumnS colS, StbSe
_colRc = colRc;
}

public GH_Structure<GH_String> Frame(StbFrame frameData)
public GH_Structure<GH_String> FrameGHStructure(StbFrame frameData)
{
var ghSecStrings = new GH_Structure<GH_String>();

Expand Down Expand Up @@ -75,6 +75,49 @@ public GH_Structure<GH_String> Frame(StbFrame frameData)
return ghSecStrings;
}

public List<List<string>> FrameList(StbFrame frameData)
{
var tags = new List<List<string>>();

for (var eNum = 0; eNum < frameData.Id.Count; eNum++)
{
TagInfo tagInfo;
var tag = new List<string>();
int idSection = frameData.IdSection[eNum];
KindsStructure kind = frameData.KindStructure[eNum];
SetTagPosition(frameData, eNum);

switch (kind)
{
case KindsStructure.Rc:
tagInfo = TagRc(frameData, idSection);
break;
case KindsStructure.S:
tagInfo = TagSteel(frameData, idSection);
break;
case KindsStructure.Src:
case KindsStructure.Cft:
case KindsStructure.Deck:
case KindsStructure.Precast:
case KindsStructure.Other:
throw new ArgumentException("Wrong kind structure");
default:
throw new ArgumentOutOfRangeException();
}

tag.Add(tagInfo.Name);
tag.Add(tagInfo.ShapeTypes.ToString());
tag.Add(tagInfo.P1.ToString());
tag.Add(tagInfo.P2.ToString());
tag.Add(tagInfo.P3.ToString());
tag.Add(tagInfo.P4.ToString());
tag.Add(kind.ToString());
tags.Add(tag);
}

return tags;
}

private void SetTagPosition(StbFrame frame, int eNum)
{
// 始点と終点の座標取得
Expand Down
Loading

0 comments on commit 2943bf7

Please sign in to comment.