Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opening fix #208

Merged
merged 16 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion IES_Adapter/CRUD/Create.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
using System.IO;

using System.Linq;
using BH.Engine.Adapters.IES;

using BH.oM.Adapter;
using BH.Engine.Adapter;
Expand Down
1 change: 0 additions & 1 deletion IES_Adapter/CRUD/Read.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
using BH.oM.Environment;

using System.IO;
using BH.Engine.Adapters.IES;

using BH.oM.Adapter;
using BH.Engine.Adapter;
Expand Down
75 changes: 75 additions & 0 deletions IES_Adapter/Convert/Environment/Opening.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BH.Engine.Environment;
using BH.oM.Environment.Elements;
using BH.oM.Geometry;
using BH.Engine.Geometry;
using BH.oM.IES.Settings;

namespace BH.Adapter.IES
{
public static partial class Convert
{
public static List<string> ToIES(this Opening opening, Panel hostPanel, SettingsIES settingsIES)
{
List<string> rtn = new List<string>();

var coordSystem = hostPanel.Polyline().CoordinateSystem(settingsIES.DistanceTolerance, settingsIES.AngleTolerance);
var localToGlobal = BH.Engine.Geometry.Create.OrientationMatrixLocalToGlobal(coordSystem);

var polyline = opening.Polyline().Transform(localToGlobal);

rtn.Add($"{polyline.ControlPoints.Count.ToString()} {opening.Type.ToIES(settingsIES)}\n");

foreach (var cPoint in polyline.ControlPoints)
rtn.Add($" {cPoint.ToIES(settingsIES, false)}");

return rtn;
}
public static Opening FromIESOpening(this List<string> openingPts, string openingType, Polyline hostPanel, SettingsIES settingsIES )
{

var polyline = new Polyline();

foreach (var iesPt in openingPts)
polyline.ControlPoints.Add(iesPt.FromIES(settingsIES));

polyline.ControlPoints.Add(polyline.ControlPoints[0]);

var coordSystem = hostPanel.CoordinateSystem(settingsIES.DistanceTolerance, settingsIES.AngleTolerance);
var globalToLocal = BH.Engine.Geometry.Create.OrientationMatrixGlobalToLocal(coordSystem);

Opening opening = new Opening();

opening.Edges = polyline.Transform(globalToLocal).ToEdges();
opening.Type = openingType.FromIESOpeningType(settingsIES);

return opening;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
Expand All @@ -20,32 +20,28 @@
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using BH.oM.Base.Attributes;
using BH.oM.IES.Settings;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using BH.oM.Geometry;
using BH.oM.Base.Attributes;
using System.ComponentModel;
using BH.oM.Environment.Elements;
using BH.Engine.Environment;
using BH.Engine.Geometry;
using BH.oM.IES.Settings;

namespace BH.Engine.Adapters.IES
namespace BH.Adapter.IES
{
public static partial class Convert
{

[Description("Convert a BHoM Opening Type to an IES string representation for GEM format")]
[Input("type", "The BHoM Opening Type to convert")]
[Input("settingsIES", "The IES settings to use with the IES adapter")]
[Output("iesOpeningType", "The IES string representation of the BHoM opening type")]
public static string ToIES(this OpeningType type, SettingsIES settingsIES)
{
switch(type)
switch (type)
{
case OpeningType.CurtainWall:
case OpeningType.Glazing:
Expand Down Expand Up @@ -80,5 +76,3 @@ public static OpeningType FromIESOpeningType(this string iesOpeningType, Setting
}
}
}


Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
Expand Down Expand Up @@ -34,7 +34,7 @@
using BH.Engine.Geometry;
using BH.oM.IES.Settings;

namespace BH.Engine.Adapters.IES
namespace BH.Adapter.IES
{
public static partial class Convert
{
Expand All @@ -53,25 +53,12 @@ public static List<string> ToIESShading(this List<Panel> panelsAsShade, Settings

for (int x = 0; x < panels.Count; x++)
{
gemPanel.Add("LAYER\n");
gemPanel.Add("64\n");
gemPanel.Add("COLOUR\n");
gemPanel.Add("0\n");
gemPanel.Add("CATEGORY\n");
gemPanel.Add("1\n");
gemPanel.Add("TYPE\n");
if (panels[x].Type == PanelType.Shade)
{
gemPanel.Add("4\n");
}
else
{
gemPanel.Add("1\n");
gemPanel.Add("SUBTYPE\n");
gemPanel.Add("2102\n");
}
gemPanel.Add("COLOURRGB\n");
gemPanel.Add("65280\n");
var template = Create.ShadeTemplate();
template.Layer = "64";
template.Colour = "0";

gemPanel.AddRange(template.ToIES());

gemPanel.Add("IES IES_SHD_" + (x + 1).ToString() + "\n");

List<Point> points = panels[x].Vertices().Select(y => y.RoundCoordinates(settingsIES.DecimalPlaces)).ToList();
Expand All @@ -80,14 +67,14 @@ public static List<string> ToIESShading(this List<Panel> panelsAsShade, Settings

string s = points.Count.ToString();

foreach(Point p in points)
foreach (Point p in points)
{
gemPanel.Add(p.ToIES(settingsIES));
s += " " + (points.IndexOf(p) + 1).ToString();
}
s += "\n";
gemPanel.Add(s);

// Add Openings
if (panels[x].Openings.Count == 0)
gemPanel.Add("0\n");
Expand All @@ -96,11 +83,11 @@ public static List<string> ToIESShading(this List<Panel> panelsAsShade, Settings
gemPanel.Add(panels[x].Openings.Count.ToString() + "\n");

foreach (Opening o in panels[x].Openings)
gemPanel.AddRange(o.ToIES(panels[x], new List<Panel> { panels[x] }, settingsIES));
gemPanel.AddRange(o.ToIES(panels[x], settingsIES));
}
}

return gemPanel;
return gemPanel;
}

[Description("Convert an IES string representation of a space into a collection of BHoM Environment Panels")]
Expand All @@ -116,17 +103,17 @@ public static Panel FromIESShading(this List<string> iesPanel, SettingsIES setti
List<string> iesPoints = new List<string>(); //Add the coordinate pts to a list
for (int x = 0; x < numCoordinates; x++)
iesPoints.Add(iesPanel[x + 2]);

List<Point> bhomPoints = iesPoints.Select(x => x.FromIES(settingsIES)).ToList();

int count = numCoordinates + 2; //Number of coordinates + 2 to get on to the line of the panel in GEM

//Convert to panels
List<string> panelCoord = iesPanel[count].Trim().Split(' ').ToList();
List<Point> pLinePts = new List<Point>();
for (int y = 1; y < panelCoord.Count; y++)
pLinePts.Add(bhomPoints[System.Convert.ToInt32(panelCoord[y]) - 1]); //Add coordinate points in order

pLinePts.Add(pLinePts.First()); //Add first point to close polyline

Polyline pLine = new Polyline { ControlPoints = pLinePts, };
Expand All @@ -150,13 +137,13 @@ public static Panel FromIESShading(this List<string> iesPanel, SettingsIES setti
for (int x = 0; x < numCoords; x++)
openingPts.Add(iesPanel[count + x]);

panel.Openings.Add(openingPts.FromIES(openingData.Split(' ')[1], settingsIES));
//panel.Openings.Add(openingPts.FromIES(openingData.Split(' ')[1], settingsIES));

count += numCoords;
countOpenings++;
}

if (settingsIES.PullOpenings)
/*if (settingsIES.PullOpenings)
{
//This if-statement is a fix for the IES implementation of translucent shades,
// where these shades contain openings defined by 3d coordinates, which differs from how
Expand All @@ -172,7 +159,7 @@ public static Panel FromIESShading(this List<string> iesPanel, SettingsIES setti
else
{
panel.Openings = new List<Opening>();
}
}*/

return panel;
}
Expand Down
Loading