Skip to content

Commit

Permalink
Merge pull request #157 from hrntsm/feature/output-story
Browse files Browse the repository at this point in the history
Feature/output story
  • Loading branch information
hrntsm authored Aug 22, 2021
2 parents 4f728be + ce0e7bf commit 15276a1
Show file tree
Hide file tree
Showing 6 changed files with 310 additions and 7 deletions.
51 changes: 44 additions & 7 deletions HoaryFox/Component/Geometry/Axes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Drawing;
using System.Linq;
using Grasshopper.Kernel;
using HoaryFox.Properties;
using Rhino.Geometry;
using STBDotNet.v202;

Expand All @@ -12,9 +13,12 @@ public class Axis : GH_Component
{
private ST_BRIDGE _stBridge;
private int _size;
private double _factor;
private readonly List<Line> _axisLines = new List<Line>();
private readonly List<Point3d> _axisPts = new List<Point3d>();
private readonly List<string> _axisStr = new List<string>();
private readonly List<Point3d> _storyPts = new List<Point3d>();
private readonly List<string> _storyStr = new List<string>();

public override bool IsPreviewCapable => true;
public Axis()
Expand All @@ -30,6 +34,8 @@ public override void ClearData()
_axisLines.Clear();
_axisPts.Clear();
_axisStr.Clear();
_storyPts.Clear();
_storyStr.Clear();
}

protected override void RegisterInputParams(GH_InputParamManager pManager)
Expand All @@ -46,25 +52,39 @@ protected override void RegisterOutputParams(GH_OutputParamManager pManager)

protected override void SolveInstance(IGH_DataAccess dataAccess)
{
double factor = 1;
if (!dataAccess.GetData(0, ref _stBridge)) { return; }
if (!dataAccess.GetData(1, ref factor)) { return; }
if (!dataAccess.GetData(1, ref _factor)) { return; }
if (!dataAccess.GetData(2, ref _size)) { return; }

StbAxes axis = _stBridge.StbModel.StbAxes;
StbParallelAxes[] parallels = axis.StbParallelAxes;
StbStory[] stories = _stBridge.StbModel.StbStories;
double length = GetMaxLength(_stBridge.StbModel.StbNodes);

StbParallelAxesToLine(factor, parallels, length);
StbParallelAxesToLine(_factor, parallels, stories, length);

dataAccess.SetDataList(0, _axisLines);
}

private void StbParallelAxesToLine(double factor, StbParallelAxes[] parallels, double length)
private void StbParallelAxesToLine(double factor, StbParallelAxes[] parallels, IEnumerable<StbStory> stories, double length)
{
var isFirst = true;
foreach (StbStory story in stories)
{
double height = story.height;
_storyStr.Add(story.name);
_storyPts.Add(new Point3d(0, 0, height));
CreateEachAxis(factor, parallels, length, isFirst, height);

isFirst = false;
}
}

private void CreateEachAxis(double factor, StbParallelAxes[] parallels, double length, bool isFirst, double height)
{
foreach (StbParallelAxes parallel in parallels)
{
var basePt = new Point3d(parallel.X, parallel.Y, 0);
var basePt = new Point3d(parallel.X, parallel.Y, height);
Vector3d axisVec = Vector3d.XAxis * length;
axisVec.Rotate(parallel.angle * Math.PI / 180, -Vector3d.ZAxis);
Vector3d distanceVec = Vector3d.YAxis;
Expand All @@ -77,7 +97,7 @@ private void StbParallelAxesToLine(double factor, StbParallelAxes[] parallels, d
basePt + (axisVec * factor) + (distanceVec * pAxis.distance)
));
_axisPts.Add(basePt - (axisVec * (factor - 1)) + (distanceVec * pAxis.distance));
_axisStr.Add(pAxis.name);
_axisStr.Add(isFirst ? pAxis.name : string.Empty);
}
}
}
Expand All @@ -97,9 +117,26 @@ public override void DrawViewportWires(IGH_PreviewArgs args)
args.Display.Draw2dText(_axisStr[i], Color.Black, _axisPts[i], true, _size);
args.Display.DrawPatternedLine(_axisLines[i], Color.Black, 0x0000AFAF, 1);
}

double xMin = _axisPts.Min(pt => pt.X);
double yMin = _axisPts.Min(pt => pt.Y);
var vec = new Vector3d(xMin, yMin, 0);
double length = _axisLines.Max(line => line.Length);

for (var i = 1; i < _storyPts.Count; i++)
{
args.Display.DrawLine(new Line(_storyPts[i - 1] + vec, _storyPts[i] + vec), Color.Black);
}

for (var i = 0; i < _storyPts.Count; i++)
{
args.Display.Draw2dText(_storyStr[i], Color.Black, _storyPts[i] + vec, true, _size);
args.Display.DrawLine(new Line(_storyPts[i] + vec, _storyPts[i] + vec + length * Vector3d.XAxis), Color.Black);
args.Display.DrawLine(new Line(_storyPts[i] + vec, _storyPts[i] + vec + length * Vector3d.YAxis), Color.Black);
}
}

protected override Bitmap Icon => null;
protected override Bitmap Icon => Resource.Axis;

public override Guid ComponentGuid => new Guid("98315013-7bb3-4ad9-8b69-ad1457ebe0b7");
}
Expand Down
15 changes: 15 additions & 0 deletions HoaryFox/HoaryFox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@
<PackageReference Include="System.Resources.Extensions" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Resource.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resource.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Properties\Resource.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resource.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

<PropertyGroup Condition="$(Configuration) == 'Debug' AND $([MSBuild]::IsOSPlatform(Windows))">
<StartProgram>C:\Program Files\Rhino 6\System\Rhino.exe</StartProgram>
<StartArguments></StartArguments>
Expand Down
10 changes: 10 additions & 0 deletions HoaryFox/Properties/Resource.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions HoaryFox/Properties/Resource.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="Axis" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Axis.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="BeamName" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\BeamName.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
Expand Down
Binary file added HoaryFox/Resources/Axis.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
238 changes: 238 additions & 0 deletions HoaryFox/Resources/Axis.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 15276a1

Please sign in to comment.