From b1b04e0f2ea3764185f7a3693183fc21fe637ecf Mon Sep 17 00:00:00 2001 From: BHoMBot Date: Tue, 3 Jan 2023 11:45:55 +0000 Subject: [PATCH 01/27] Upgrade AssemblyFileVersion to 6.1.0.0 --- IES_Adapter/Properties/AssemblyInfo.cs | 2 +- IES_Engine/Properties/AssemblyInfo.cs | 2 +- IES_oM/Properties/AssemblyInfo.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/IES_Adapter/Properties/AssemblyInfo.cs b/IES_Adapter/Properties/AssemblyInfo.cs index e46d579..2b2bc57 100644 --- a/IES_Adapter/Properties/AssemblyInfo.cs +++ b/IES_Adapter/Properties/AssemblyInfo.cs @@ -55,6 +55,6 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("6.0.0.0")] -[assembly: AssemblyFileVersion("6.0.0.0")] +[assembly: AssemblyFileVersion("6.1.0.0")] diff --git a/IES_Engine/Properties/AssemblyInfo.cs b/IES_Engine/Properties/AssemblyInfo.cs index 0801227..e8da00a 100644 --- a/IES_Engine/Properties/AssemblyInfo.cs +++ b/IES_Engine/Properties/AssemblyInfo.cs @@ -55,6 +55,6 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("6.0.0.0")] -[assembly: AssemblyFileVersion("6.0.0.0")] +[assembly: AssemblyFileVersion("6.1.0.0")] diff --git a/IES_oM/Properties/AssemblyInfo.cs b/IES_oM/Properties/AssemblyInfo.cs index fbfe063..3a8537b 100644 --- a/IES_oM/Properties/AssemblyInfo.cs +++ b/IES_oM/Properties/AssemblyInfo.cs @@ -55,6 +55,6 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("6.0.0.0")] -[assembly: AssemblyFileVersion("6.0.0.0")] +[assembly: AssemblyFileVersion("6.1.0.0")] From 5e5db913515752e21f80efe6f142d24ca66621e2 Mon Sep 17 00:00:00 2001 From: BHoMBot Date: Wed, 4 Jan 2023 11:35:13 +0000 Subject: [PATCH 02/27] Update copyright headers to 2023 --- IES_Adapter/CRUD/Create.cs | 3 ++- IES_Adapter/CRUD/Read.cs | 3 ++- IES_Adapter/IESAdapter.cs | 3 ++- IES_Adapter/Properties/AssemblyInfo.cs | 3 ++- IES_Engine/Convert/Environment/Opening.cs | 3 ++- IES_Engine/Convert/Environment/OpeningType.cs | 3 ++- IES_Engine/Convert/Environment/Panel.cs | 3 ++- IES_Engine/Convert/Environment/Space.cs | 3 ++- IES_Engine/Convert/Geometry/Point.cs | 3 ++- IES_Engine/Modify/RepairOpening.cs | 3 ++- IES_Engine/Properties/AssemblyInfo.cs | 3 ++- IES_Engine/Query/Polyline.cs | 3 ++- IES_oM/Fragments/SurfaceIndexFragment.cs | 3 ++- IES_oM/Properties/AssemblyInfo.cs | 3 ++- IES_oM/SettingsIES.cs | 3 ++- 15 files changed, 30 insertions(+), 15 deletions(-) diff --git a/IES_Adapter/CRUD/Create.cs b/IES_Adapter/CRUD/Create.cs index 60a5fff..3937781 100644 --- a/IES_Adapter/CRUD/Create.cs +++ b/IES_Adapter/CRUD/Create.cs @@ -1,6 +1,6 @@ /* * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. + * 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. @@ -83,3 +83,4 @@ protected override bool ICreate(IEnumerable objects, ActionConfig actionCo } + diff --git a/IES_Adapter/CRUD/Read.cs b/IES_Adapter/CRUD/Read.cs index 0332f48..02547b8 100644 --- a/IES_Adapter/CRUD/Read.cs +++ b/IES_Adapter/CRUD/Read.cs @@ -1,6 +1,6 @@ /* * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. + * 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. @@ -185,3 +185,4 @@ private List ReadSpaces(List panels) } + diff --git a/IES_Adapter/IESAdapter.cs b/IES_Adapter/IESAdapter.cs index f9fa06e..4c380a3 100644 --- a/IES_Adapter/IESAdapter.cs +++ b/IES_Adapter/IESAdapter.cs @@ -1,6 +1,6 @@ /* * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. + * 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. @@ -86,3 +86,4 @@ public IESAdapter(BH.oM.Adapter.FileSettings fileSettings = null, SettingsIES se + diff --git a/IES_Adapter/Properties/AssemblyInfo.cs b/IES_Adapter/Properties/AssemblyInfo.cs index 2b2bc57..e0a57ed 100644 --- a/IES_Adapter/Properties/AssemblyInfo.cs +++ b/IES_Adapter/Properties/AssemblyInfo.cs @@ -1,6 +1,6 @@ /* * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. + * 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. @@ -58,3 +58,4 @@ [assembly: AssemblyFileVersion("6.1.0.0")] + diff --git a/IES_Engine/Convert/Environment/Opening.cs b/IES_Engine/Convert/Environment/Opening.cs index f9db9b5..6fa1e67 100644 --- a/IES_Engine/Convert/Environment/Opening.cs +++ b/IES_Engine/Convert/Environment/Opening.cs @@ -1,6 +1,6 @@ /* * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. + * 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. @@ -153,3 +153,4 @@ public static Opening FromIES(this List openingPts, string openingType, } } + diff --git a/IES_Engine/Convert/Environment/OpeningType.cs b/IES_Engine/Convert/Environment/OpeningType.cs index b5de197..4d76401 100644 --- a/IES_Engine/Convert/Environment/OpeningType.cs +++ b/IES_Engine/Convert/Environment/OpeningType.cs @@ -1,6 +1,6 @@ /* * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. + * 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. @@ -81,3 +81,4 @@ public static OpeningType FromIESOpeningType(this string iesOpeningType, Setting } } + diff --git a/IES_Engine/Convert/Environment/Panel.cs b/IES_Engine/Convert/Environment/Panel.cs index da45e28..7038164 100644 --- a/IES_Engine/Convert/Environment/Panel.cs +++ b/IES_Engine/Convert/Environment/Panel.cs @@ -1,6 +1,6 @@ /* * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. + * 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. @@ -179,3 +179,4 @@ public static Panel FromIESShading(this List iesPanel, SettingsIES setti } } + diff --git a/IES_Engine/Convert/Environment/Space.cs b/IES_Engine/Convert/Environment/Space.cs index b398acf..e35b8ef 100644 --- a/IES_Engine/Convert/Environment/Space.cs +++ b/IES_Engine/Convert/Environment/Space.cs @@ -1,6 +1,6 @@ /* * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. + * 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. @@ -229,3 +229,4 @@ public static List FromIES(this List iesSpace, SettingsIES settin } } + diff --git a/IES_Engine/Convert/Geometry/Point.cs b/IES_Engine/Convert/Geometry/Point.cs index 353e99e..8ec445f 100644 --- a/IES_Engine/Convert/Geometry/Point.cs +++ b/IES_Engine/Convert/Geometry/Point.cs @@ -1,6 +1,6 @@ /* * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. + * 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. @@ -73,3 +73,4 @@ public static Point FromIES(this string iesPt, SettingsIES settingsIES) } } + diff --git a/IES_Engine/Modify/RepairOpening.cs b/IES_Engine/Modify/RepairOpening.cs index a8a1907..55f7764 100644 --- a/IES_Engine/Modify/RepairOpening.cs +++ b/IES_Engine/Modify/RepairOpening.cs @@ -1,6 +1,6 @@ /* * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. + * 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. @@ -141,3 +141,4 @@ public static Opening RepairOpening(this Opening opening, Panel hostPanel, Panel } } + diff --git a/IES_Engine/Properties/AssemblyInfo.cs b/IES_Engine/Properties/AssemblyInfo.cs index e8da00a..255eca6 100644 --- a/IES_Engine/Properties/AssemblyInfo.cs +++ b/IES_Engine/Properties/AssemblyInfo.cs @@ -1,6 +1,6 @@ /* * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. + * 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. @@ -58,3 +58,4 @@ [assembly: AssemblyFileVersion("6.1.0.0")] + diff --git a/IES_Engine/Query/Polyline.cs b/IES_Engine/Query/Polyline.cs index dd5a78c..ae687d5 100644 --- a/IES_Engine/Query/Polyline.cs +++ b/IES_Engine/Query/Polyline.cs @@ -1,6 +1,6 @@ /* * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. + * 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. @@ -128,3 +128,4 @@ public static Polyline Polyline(this BoundingBox box) } + diff --git a/IES_oM/Fragments/SurfaceIndexFragment.cs b/IES_oM/Fragments/SurfaceIndexFragment.cs index d099b67..0a8b933 100644 --- a/IES_oM/Fragments/SurfaceIndexFragment.cs +++ b/IES_oM/Fragments/SurfaceIndexFragment.cs @@ -1,6 +1,6 @@ /* * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. + * 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. @@ -38,3 +38,4 @@ public class SurfaceIndexFragment : IFragment } } + diff --git a/IES_oM/Properties/AssemblyInfo.cs b/IES_oM/Properties/AssemblyInfo.cs index 3a8537b..38ccb0f 100644 --- a/IES_oM/Properties/AssemblyInfo.cs +++ b/IES_oM/Properties/AssemblyInfo.cs @@ -1,6 +1,6 @@ /* * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. + * 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. @@ -58,3 +58,4 @@ [assembly: AssemblyFileVersion("6.1.0.0")] + diff --git a/IES_oM/SettingsIES.cs b/IES_oM/SettingsIES.cs index a0c9734..f50aaac 100644 --- a/IES_oM/SettingsIES.cs +++ b/IES_oM/SettingsIES.cs @@ -1,6 +1,6 @@ /* * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. + * 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. @@ -50,3 +50,4 @@ public class SettingsIES : BHoMObject } + From cbbbd9a506820fd0ee57a413e775738ddc73ee3b Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Tue, 24 Jan 2023 10:53:12 +0000 Subject: [PATCH 03/27] Initial commit of clean up for Karolina to take on in opening conversion --- IES_Adapter/CRUD/Create.cs | 4 +- IES_Adapter/CRUD/Read.cs | 6 +- .../Convert/Environment/Space.cs | 70 ++-- .../Convert/Geometry/Point.cs | 6 +- IES_Adapter/Convert/Objects/GEMTemplate.cs | 39 ++ IES_Adapter/Create/ShadeTemplate.cs | 24 ++ IES_Adapter/Create/SpaceTemplate.cs | 24 ++ IES_Adapter/IES_Adapter.csproj | 11 +- IES_Adapter/Objects/GEMTemplate.cs | 21 ++ IES_Engine/Convert/Environment/Opening.cs | 308 +++++++-------- IES_Engine/Convert/Environment/Panel.cs | 350 +++++++++--------- IES_Engine/IES_Engine.csproj | 6 +- 12 files changed, 478 insertions(+), 391 deletions(-) rename {IES_Engine => IES_Adapter}/Convert/Environment/Space.cs (78%) rename {IES_Engine => IES_Adapter}/Convert/Geometry/Point.cs (98%) create mode 100644 IES_Adapter/Convert/Objects/GEMTemplate.cs create mode 100644 IES_Adapter/Create/ShadeTemplate.cs create mode 100644 IES_Adapter/Create/SpaceTemplate.cs create mode 100644 IES_Adapter/Objects/GEMTemplate.cs diff --git a/IES_Adapter/CRUD/Create.cs b/IES_Adapter/CRUD/Create.cs index 3937781..37ef4e4 100644 --- a/IES_Adapter/CRUD/Create.cs +++ b/IES_Adapter/CRUD/Create.cs @@ -67,8 +67,8 @@ protected override bool ICreate(IEnumerable objects, ActionConfig actionCo sw.Write(s); } - if (panelsAsShade.Count > 0 && !_settingsIES.ShadesAs3D) - panelsAsShade.ToIESShading(_settingsIES).ForEach(x => sw.Write(x)); + //if (panelsAsShade.Count > 0 && !_settingsIES.ShadesAs3D) + //panelsAsShade.ToIESShading(_settingsIES).ForEach(x => sw.Write(x)); } catch(Exception e) { diff --git a/IES_Adapter/CRUD/Read.cs b/IES_Adapter/CRUD/Read.cs index 02547b8..27ca1c9 100644 --- a/IES_Adapter/CRUD/Read.cs +++ b/IES_Adapter/CRUD/Read.cs @@ -125,9 +125,9 @@ private List ReadPanels() for (int x = 0; x < nextIndex; x++) space.Add(iesStrings[x]); - if ((panelType == PanelType.Shade || panelType == PanelType.TranslucentShade) && !_settingsIES.ShadesAs3D) - panels.Add(space.FromIESShading(_settingsIES, panelType)); //Make a shade panel - else if ((panelType == PanelType.Shade || panelType == PanelType.TranslucentShade) && _settingsIES.ShadesAs3D) + //if ((panelType == PanelType.Shade || panelType == PanelType.TranslucentShade) && !_settingsIES.ShadesAs3D) + //panels.Add(space.FromIESShading(_settingsIES, panelType)); //Make a shade panel + /*else*/ if ((panelType == PanelType.Shade || panelType == PanelType.TranslucentShade) && _settingsIES.ShadesAs3D) { var shadePanels = space.FromIES(_settingsIES); shadePanels.ForEach(x => x.Type = panelType); diff --git a/IES_Engine/Convert/Environment/Space.cs b/IES_Adapter/Convert/Environment/Space.cs similarity index 78% rename from IES_Engine/Convert/Environment/Space.cs rename to IES_Adapter/Convert/Environment/Space.cs index e35b8ef..edf8e6f 100644 --- a/IES_Engine/Convert/Environment/Space.cs +++ b/IES_Adapter/Convert/Environment/Space.cs @@ -1,55 +1,31 @@ -/* - * 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 . - */ - +using BH.oM.Base.Attributes; +using BH.oM.Environment.Elements; +using BH.oM.Geometry; +using BH.oM.IES.Fragments; +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; -using BH.oM.IES.Fragments; -using BH.Engine.Base; -namespace BH.Engine.Adapters.IES +namespace BH.Adapter.IES { public static partial class Convert - { + { [Description("Convert a collection of BHoM Environment Panels that represent a single volumetric space into the IES string representation for GEM format")] [Input("panelsAsSpace", "The collection of BHoM Environment Panels that represent a space")] [Input("settingsIES", "The IES settings to use with the IES adapter")] [Output("iesSpace", "The IES string representation of the space for GEM")] - public static List ToIES(this List panelsAsSpace, SettingsIES settingsIES) + public static List ToIES(this List panelsAsSpace, SettingsIES settingsIES) { if (panelsAsSpace == null || panelsAsSpace.Count == 0) return new List(); - if(settingsIES == null) + if (settingsIES == null) { BH.Engine.Base.Compute.RecordWarning("A null set of IES Settings was provided when attempting to convert a collection of panels (forming a closed space or 3D shade) to GEM. As such, default settings have been applied."); settingsIES = new SettingsIES(); @@ -60,7 +36,7 @@ public static List ToIES(this List panelsAsSpace, SettingsIES set if (panels.Count != panelsAsSpace.Count) BH.Engine.Base.Compute.RecordWarning("The space " + panelsAsSpace.ConnectedSpaceName() + " has panels which did not contain geometry. Panels without valid geometry cannot be converted for IES to handle and have been ignored."); - List gemSpace = new List(); + List gemSpace = new List(); gemSpace.Add("LAYER\n"); gemSpace.Add("1\n"); @@ -114,7 +90,7 @@ public static List ToIES(this List panelsAsSpace, SettingsIES set v.Reverse(); //Reverse the point order if the normal is not away from the space but the first adjacency is this space string s = v.Count.ToString() + " "; - foreach(Point pt in v) + foreach (Point pt in v) s += (spaceVertices.IndexOf(pt.RoundCoordinates(settingsIES.DecimalPlaces)) + 1) + " "; s += "\n"; @@ -126,14 +102,14 @@ public static List ToIES(this List panelsAsSpace, SettingsIES set { gemSpace.Add(p.Openings.Count.ToString() + "\n"); - foreach (Opening o in p.Openings) - gemSpace.AddRange(o.ToIES(p, panels, settingsIES)); + /*foreach (Opening o in p.Openings) + gemSpace.AddRange(o.ToIES(p, panels, settingsIES));*/ } } return gemSpace; } - + [Description("Convert an IES string representation of a space into a collection of BHoM Environment Panels")] [Input("iesSpace", "The IES representation of a space")] [Input("settingsIES", "The IES settings to use with the IES adapter")] @@ -144,7 +120,7 @@ public static List FromIES(this List iesSpace, SettingsIES settin //Convert the strings which make up the IES Gem file back into BHoM panels. string spaceName = iesSpace[0]; //First string is the name - if(spaceName.StartsWith("IES")) + if (spaceName.StartsWith("IES")) { spaceName = spaceName.Substring(3); spaceName = spaceName.Trim(); @@ -161,7 +137,7 @@ public static List FromIES(this List iesSpace, SettingsIES settin //Number of coordinated + 2 to get on to the line of the fist panel in GEM int count = numCoordinates + 2; - while(count < iesSpace.Count) + while (count < iesSpace.Count) { //Convert to panels List panelCoord = iesSpace[count].Trim().Split(' ').ToList(); @@ -188,7 +164,7 @@ public static List FromIES(this List iesSpace, SettingsIES settin int numOpenings = System.Convert.ToInt32(iesSpace[count]); count++; int countOpenings = 0; - while(countOpenings < numOpenings) + while (countOpenings < numOpenings) { string openingData = iesSpace[count]; int numCoords = System.Convert.ToInt32(openingData.Split(' ')[0]); @@ -198,7 +174,7 @@ public static List FromIES(this List iesSpace, SettingsIES settin for (int x = 0; x < numCoords; x++) openingPts.Add(iesSpace[count + x]); - panel.Openings.Add(openingPts.FromIES(openingData.Split(' ')[1], settingsIES)); + //panel.Openings.Add(openingPts.FromIES(openingData.Split(' ')[1], settingsIES)); count += numCoords; countOpenings++; @@ -207,7 +183,7 @@ public static List FromIES(this List iesSpace, SettingsIES settin panels.Add(panel); } - if (settingsIES.PullOpenings) + /*if (settingsIES.PullOpenings) { //Fix the openings now foreach (Panel p in panels) @@ -220,13 +196,11 @@ public static List FromIES(this List iesSpace, SettingsIES settin } else { - foreach(Panel p in panels) + foreach (Panel p in panels) p.Openings = new List(); - } + }*/ return panels; } } } - - diff --git a/IES_Engine/Convert/Geometry/Point.cs b/IES_Adapter/Convert/Geometry/Point.cs similarity index 98% rename from IES_Engine/Convert/Geometry/Point.cs rename to IES_Adapter/Convert/Geometry/Point.cs index 8ec445f..8cc2294 100644 --- a/IES_Engine/Convert/Geometry/Point.cs +++ b/IES_Adapter/Convert/Geometry/Point.cs @@ -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. * @@ -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 { @@ -64,7 +64,7 @@ public static Point FromIES(this string iesPt, SettingsIES settingsIES) Z = (split.Length > 2 ? System.Convert.ToDouble(split[2]) : 0), }; } - catch(Exception e) + catch (Exception e) { BH.Engine.Base.Compute.RecordError("An error occurred in parsing that IES string to a BHoM point. Error was: " + e.ToString()); return null; diff --git a/IES_Adapter/Convert/Objects/GEMTemplate.cs b/IES_Adapter/Convert/Objects/GEMTemplate.cs new file mode 100644 index 0000000..1cd9f67 --- /dev/null +++ b/IES_Adapter/Convert/Objects/GEMTemplate.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Adapter.IES +{ + public static partial class Convert + { + public static List ToIES(this GEMTemplate gemTemplate) + { + List gemLines = new List(); + + gemLines.Add("LAYER\n"); + gemLines.Add($"{gemTemplate.Layer}\n"); + + gemLines.Add("COLOUR\n"); + gemLines.Add($"{gemTemplate.Colour}\n"); + + gemLines.Add("CATEGORY\n"); + gemLines.Add($"{gemTemplate.Category}\n"); + + gemLines.Add("TYPE\n"); + gemLines.Add($"{gemTemplate.Type}\n"); + + gemLines.Add("SUBTYPE\n"); + gemLines.Add($"{gemTemplate.SubType}\n"); + + gemLines.Add("COLOURRGB\n"); + gemLines.Add($"{gemTemplate.ColourRGB}\n"); + + gemLines.Add($"IES {gemTemplate.Name}\n"); + gemLines.Add($"{gemTemplate.VerticesCount.ToString()} {gemTemplate.FaceCount.ToString()}\n"); + + return gemLines; + } + } +} diff --git a/IES_Adapter/Create/ShadeTemplate.cs b/IES_Adapter/Create/ShadeTemplate.cs new file mode 100644 index 0000000..493c2b0 --- /dev/null +++ b/IES_Adapter/Create/ShadeTemplate.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Adapter.IES +{ + public static partial class Create + { + public static GEMTemplate ShadeTemplate() + { + return new GEMTemplate() + { + Layer = "1", + Colour = "62", + Category = "1", + Type = "4", + SubType = "0", + ColourRGB = "65280" + }; + } + } +} diff --git a/IES_Adapter/Create/SpaceTemplate.cs b/IES_Adapter/Create/SpaceTemplate.cs new file mode 100644 index 0000000..81caf23 --- /dev/null +++ b/IES_Adapter/Create/SpaceTemplate.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Adapter.IES +{ + public static partial class Create + { + public static GEMTemplate SpaceTemplate() + { + return new GEMTemplate() + { + Layer = "1", + Colour = "0", + Category = "1", + Type = "1", + SubType = "2001", + ColourRGB = "16711690" + }; + } + } +} diff --git a/IES_Adapter/IES_Adapter.csproj b/IES_Adapter/IES_Adapter.csproj index e510140..6ff573a 100644 --- a/IES_Adapter/IES_Adapter.csproj +++ b/IES_Adapter/IES_Adapter.csproj @@ -1,4 +1,4 @@ - + @@ -117,9 +117,15 @@ + + + + + + @@ -137,6 +143,7 @@ False + @@ -150,4 +157,4 @@ xcopy "$(TargetDir)$(TargetFileName)" "C:\ProgramData\BHoM\Assemblies" /Y --> - + \ No newline at end of file diff --git a/IES_Adapter/Objects/GEMTemplate.cs b/IES_Adapter/Objects/GEMTemplate.cs new file mode 100644 index 0000000..d37311b --- /dev/null +++ b/IES_Adapter/Objects/GEMTemplate.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Adapter.IES +{ + public class GEMTemplate + { + public virtual string Layer { get; set; } + public virtual string Colour { get; set; } + public virtual string Category { get; set; } + public virtual string Type { get; set; } + public virtual string SubType { get; set; } + public virtual string ColourRGB { get; set; } + public virtual string Name { get; set; } + public virtual int VerticesCount { get; set; } + public virtual int FaceCount { get; set; } + } +} diff --git a/IES_Engine/Convert/Environment/Opening.cs b/IES_Engine/Convert/Environment/Opening.cs index 6fa1e67..cdfca3c 100644 --- a/IES_Engine/Convert/Environment/Opening.cs +++ b/IES_Engine/Convert/Environment/Opening.cs @@ -1,156 +1,156 @@ -/* - * 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 . - */ - -using System; -using System.Collections.Generic; -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; - -using BH.oM.Geometry.CoordinateSystem; - -namespace BH.Engine.Adapters.IES -{ - public static partial class Convert - { - - [Description("Convert a BHoM Environment Opening to an IES string representation of an opening for GEM format - this is for vertical openings (openings on walls)")] - [Input("opening", "The BHoM Environment Opening to convert")] - [Input("panelsAsSpace", "The panels representing a single space which hosts this opening, used to check the orientation of the opening")] - [Input("settingsIES", "The IES settings to use with the IES adapter")] - [Output("iesOpening", "The string representation for IES GEM format")] - public static List ToIES(this Opening opening, Panel hostPanel, List panelsAsSpace, SettingsIES settingsIES) - { - List gemOpening = new List(); - - Polyline openingCurve = opening.Polyline(); - Polyline hostCurve = hostPanel.Polyline(); - - if (hostCurve.ControlPoints.Select(x => x.Z).Max() == hostCurve.ControlPoints.Select(x => x.Z).Min()) - return opening.ToIES(hostPanel, settingsIES); //Horizontal openings are handled slightly differently - - Point panelBottomRightReference = hostPanel.BottomRight(panelsAsSpace); - Point panelBottomLeftReference = hostPanel.BottomLeft(panelsAsSpace); - Point panelTopRightReference = hostPanel.TopRight(panelsAsSpace); - - Vector xVector = panelBottomLeftReference - panelBottomRightReference; - xVector.Z = 0; - Vector yVector = panelTopRightReference - panelBottomRightReference; - - Point worldOrigin = new Point { X = 0, Y = 0, Z = 0 }; - Cartesian worldCartesian = BH.Engine.Geometry.Create.CartesianCoordinateSystem(worldOrigin, Vector.XAxis, Vector.YAxis); - Cartesian localCartesian = BH.Engine.Geometry.Create.CartesianCoordinateSystem(panelBottomRightReference, xVector, yVector); - - Polyline hostTransformed = hostCurve.Orient(localCartesian, worldCartesian); - Polyline openingTranslated = openingCurve.Orient(localCartesian, worldCartesian); - - //If the orientation to 0,0,0 returns a negative X or Y point, translate the opening appropriately so that the bottom right reference would (if we wanted it) become 0,0,0 of the bounds of the host panel - double minX = hostTransformed.ControlPoints.Select(x => x.X).Min(); - double minY = hostTransformed.ControlPoints.Select(x => x.Y).Min(); - if (minX < 0) - { - Vector translateVectorX = new Vector { X = -minX, Y = 0, Z = 0 }; - openingTranslated = openingTranslated.Translate(translateVectorX); - } - if (minY < 0) - { - Vector translateVectorY = new Vector { X = 0, Y = -minY, Z = 0 }; - openingTranslated = openingTranslated.Translate(translateVectorY); - } - - List vertices = openingTranslated.IDiscontinuityPoints(); - gemOpening.Add(vertices.Count.ToString() + " " + opening.Type.ToIES(settingsIES) + "\n"); - - foreach (Point p in vertices) - gemOpening.Add(" " + Math.Abs(Math.Round(p.X, settingsIES.DecimalPlaces)).ToString() + " " + Math.Abs(Math.Round(p.Y, settingsIES.DecimalPlaces)).ToString() + "\n"); - - return gemOpening; - } - - [Description("Convert a BHoM Environment Opening to an IES string representation of an opening for GEM format - this is for horizontal openings (openings on roofs and floors)")] - [Input("opening", "The BHoM Environment Opening to convert")] - [Input("settingsIES", "The IES settings to use with the IES adapter")] - [Output("iesOpening", "The string representation for IES GEM format")] - public static List ToIES(this Opening opening, Panel hostPanel, SettingsIES settingsIES) - { - List gemOpening = new List(); - - Point zeroReference = null; - BoundingBox bounds = hostPanel.Bounds(); - Vector xVector = new Vector { X = -1, Y = 0, Z = 0 }; - Vector yVector = new Vector { X = 0, Y = 1, Z = 0 }; - - if (hostPanel.Type == PanelType.Floor || hostPanel.Type == PanelType.FloorExposed || hostPanel.Type == PanelType.FloorRaised) - zeroReference = new Point { X = bounds.Max.X, Y = bounds.Min.Y, Z = bounds.Min.Z }; - else - { - zeroReference = new Point { X = bounds.Max.X, Y = bounds.Max.Y, Z = bounds.Max.Z }; - yVector.Y = -1; - } - - Polyline openingCurve = opening.Polyline(); - - Point worldOrigin = new Point { X = 0, Y = 0, Z = 0 }; - Cartesian worldCartesian = BH.Engine.Geometry.Create.CartesianCoordinateSystem(worldOrigin, Vector.XAxis, Vector.YAxis); - Cartesian localCartesian = BH.Engine.Geometry.Create.CartesianCoordinateSystem(zeroReference, xVector, yVector); - - Polyline openingTranslated = openingCurve.Orient(localCartesian, worldCartesian); - - List vertices = openingTranslated.IDiscontinuityPoints(); - gemOpening.Add(vertices.Count.ToString() + " " + opening.Type.ToIES(settingsIES) + "\n"); - - foreach (Point p in vertices) - gemOpening.Add(" " + Math.Abs(p.X).ToString() + " " + Math.Abs(p.Y).ToString() + "\n"); - - return gemOpening; - } - - [Description("Convert an IES string representation of an opening to a BHoM Environment Opening")] - [Input("openingPts", "The string representations of coordinates that make up the opening")] - [Input("openingType", "The IES representation of the opening type")] - [Input("settingsIES", "The IES settings to use with the IES adapter")] - [Output("opening", "The BHoM Environment Opening converted from IES GEM format")] - public static Opening FromIES(this List openingPts, string openingType, SettingsIES settingsIES) - { - List points = openingPts.Select(x => x.FromIES(settingsIES)).ToList(); - points.Add(points.First()); - - Polyline pLine = new Polyline { ControlPoints = points, }; - - Opening opening = new Opening(); - opening.Edges = pLine.ToEdges(); - opening.Type = openingType.FromIESOpeningType(settingsIES); - - return opening; - } - } -} +///* +// * 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 . +// */ + +//using System; +//using System.Collections.Generic; +//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; + +//using BH.oM.Geometry.CoordinateSystem; + +//namespace BH.Engine.Adapters.IES +//{ +// public static partial class Convert +// { + +// [Description("Convert a BHoM Environment Opening to an IES string representation of an opening for GEM format - this is for vertical openings (openings on walls)")] +// [Input("opening", "The BHoM Environment Opening to convert")] +// [Input("panelsAsSpace", "The panels representing a single space which hosts this opening, used to check the orientation of the opening")] +// [Input("settingsIES", "The IES settings to use with the IES adapter")] +// [Output("iesOpening", "The string representation for IES GEM format")] +// public static List ToIES(this Opening opening, Panel hostPanel, List panelsAsSpace, SettingsIES settingsIES) +// { +// List gemOpening = new List(); + +// Polyline openingCurve = opening.Polyline(); +// Polyline hostCurve = hostPanel.Polyline(); + +// if (hostCurve.ControlPoints.Select(x => x.Z).Max() == hostCurve.ControlPoints.Select(x => x.Z).Min()) +// return opening.ToIES(hostPanel, settingsIES); //Horizontal openings are handled slightly differently + +// Point panelBottomRightReference = hostPanel.BottomRight(panelsAsSpace); +// Point panelBottomLeftReference = hostPanel.BottomLeft(panelsAsSpace); +// Point panelTopRightReference = hostPanel.TopRight(panelsAsSpace); + +// Vector xVector = panelBottomLeftReference - panelBottomRightReference; +// xVector.Z = 0; +// Vector yVector = panelTopRightReference - panelBottomRightReference; + +// Point worldOrigin = new Point { X = 0, Y = 0, Z = 0 }; +// Cartesian worldCartesian = BH.Engine.Geometry.Create.CartesianCoordinateSystem(worldOrigin, Vector.XAxis, Vector.YAxis); +// Cartesian localCartesian = BH.Engine.Geometry.Create.CartesianCoordinateSystem(panelBottomRightReference, xVector, yVector); + +// Polyline hostTransformed = hostCurve.Orient(localCartesian, worldCartesian); +// Polyline openingTranslated = openingCurve.Orient(localCartesian, worldCartesian); + +// //If the orientation to 0,0,0 returns a negative X or Y point, translate the opening appropriately so that the bottom right reference would (if we wanted it) become 0,0,0 of the bounds of the host panel +// double minX = hostTransformed.ControlPoints.Select(x => x.X).Min(); +// double minY = hostTransformed.ControlPoints.Select(x => x.Y).Min(); +// if (minX < 0) +// { +// Vector translateVectorX = new Vector { X = -minX, Y = 0, Z = 0 }; +// openingTranslated = openingTranslated.Translate(translateVectorX); +// } +// if (minY < 0) +// { +// Vector translateVectorY = new Vector { X = 0, Y = -minY, Z = 0 }; +// openingTranslated = openingTranslated.Translate(translateVectorY); +// } + +// List vertices = openingTranslated.IDiscontinuityPoints(); +// gemOpening.Add(vertices.Count.ToString() + " " + opening.Type.ToIES(settingsIES) + "\n"); + +// foreach (Point p in vertices) +// gemOpening.Add(" " + Math.Abs(Math.Round(p.X, settingsIES.DecimalPlaces)).ToString() + " " + Math.Abs(Math.Round(p.Y, settingsIES.DecimalPlaces)).ToString() + "\n"); + +// return gemOpening; +// } + +// [Description("Convert a BHoM Environment Opening to an IES string representation of an opening for GEM format - this is for horizontal openings (openings on roofs and floors)")] +// [Input("opening", "The BHoM Environment Opening to convert")] +// [Input("settingsIES", "The IES settings to use with the IES adapter")] +// [Output("iesOpening", "The string representation for IES GEM format")] +// public static List ToIES(this Opening opening, Panel hostPanel, SettingsIES settingsIES) +// { +// List gemOpening = new List(); + +// Point zeroReference = null; +// BoundingBox bounds = hostPanel.Bounds(); +// Vector xVector = new Vector { X = -1, Y = 0, Z = 0 }; +// Vector yVector = new Vector { X = 0, Y = 1, Z = 0 }; + +// if (hostPanel.Type == PanelType.Floor || hostPanel.Type == PanelType.FloorExposed || hostPanel.Type == PanelType.FloorRaised) +// zeroReference = new Point { X = bounds.Max.X, Y = bounds.Min.Y, Z = bounds.Min.Z }; +// else +// { +// zeroReference = new Point { X = bounds.Max.X, Y = bounds.Max.Y, Z = bounds.Max.Z }; +// yVector.Y = -1; +// } + +// Polyline openingCurve = opening.Polyline(); + +// Point worldOrigin = new Point { X = 0, Y = 0, Z = 0 }; +// Cartesian worldCartesian = BH.Engine.Geometry.Create.CartesianCoordinateSystem(worldOrigin, Vector.XAxis, Vector.YAxis); +// Cartesian localCartesian = BH.Engine.Geometry.Create.CartesianCoordinateSystem(zeroReference, xVector, yVector); + +// Polyline openingTranslated = openingCurve.Orient(localCartesian, worldCartesian); + +// List vertices = openingTranslated.IDiscontinuityPoints(); +// gemOpening.Add(vertices.Count.ToString() + " " + opening.Type.ToIES(settingsIES) + "\n"); + +// foreach (Point p in vertices) +// gemOpening.Add(" " + Math.Abs(p.X).ToString() + " " + Math.Abs(p.Y).ToString() + "\n"); + +// return gemOpening; +// } + +// [Description("Convert an IES string representation of an opening to a BHoM Environment Opening")] +// [Input("openingPts", "The string representations of coordinates that make up the opening")] +// [Input("openingType", "The IES representation of the opening type")] +// [Input("settingsIES", "The IES settings to use with the IES adapter")] +// [Output("opening", "The BHoM Environment Opening converted from IES GEM format")] +// public static Opening FromIES(this List openingPts, string openingType, SettingsIES settingsIES) +// { +// List points = openingPts.Select(x => x.FromIES(settingsIES)).ToList(); +// points.Add(points.First()); + +// Polyline pLine = new Polyline { ControlPoints = points, }; + +// Opening opening = new Opening(); +// opening.Edges = pLine.ToEdges(); +// opening.Type = openingType.FromIESOpeningType(settingsIES); + +// return opening; +// } +// } +//} diff --git a/IES_Engine/Convert/Environment/Panel.cs b/IES_Engine/Convert/Environment/Panel.cs index 7038164..cee3fcf 100644 --- a/IES_Engine/Convert/Environment/Panel.cs +++ b/IES_Engine/Convert/Environment/Panel.cs @@ -1,182 +1,182 @@ -/* - * 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 . - */ - -using System; -using System.Collections.Generic; -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 -{ - public static partial class Convert - { - [Description("Convert a collection of BHoM Environment Panels that represent shading elements into the IES string representation for GEM format")] - [Input("panelsAsShade", "The collection of BHoM Environment Panels that represent shading elements")] - [Input("settingsIES", "The IES settings to use with the IES adapter")] - [Output("iesSpace", "The IES string representation of shade for GEM")] - public static List ToIESShading(this List panelsAsShade, SettingsIES settingsIES) - { - List panels = panelsAsShade.Where(x => x.ExternalEdges.Count > 0).ToList(); - - if (panels.Count != panelsAsShade.Count) - BH.Engine.Base.Compute.RecordWarning("The panels for shading contain panels which did not contain geometry. Panels without valid geometry cannot be converted for IES to handle and have been ignored."); - - List gemPanel = new List(); - - 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"); - gemPanel.Add("IES IES_SHD_" + (x + 1).ToString() + "\n"); - - List points = panels[x].Vertices().Select(y => y.RoundCoordinates(settingsIES.DecimalPlaces)).ToList(); - points = points.Distinct().ToList(); - gemPanel.Add(points.Count.ToString() + " 1\n"); - - string s = points.Count.ToString(); - - foreach(Point p in points) - { - gemPanel.Add(p.ToIES(settingsIES)); - s += " " + (points.IndexOf(p) + 1).ToString(); - } - s += "\n"; - gemPanel.Add(s); +///* +// * 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 . +// */ + +//using System; +//using System.Collections.Generic; +//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 +//{ +// public static partial class Convert +// { +// [Description("Convert a collection of BHoM Environment Panels that represent shading elements into the IES string representation for GEM format")] +// [Input("panelsAsShade", "The collection of BHoM Environment Panels that represent shading elements")] +// [Input("settingsIES", "The IES settings to use with the IES adapter")] +// [Output("iesSpace", "The IES string representation of shade for GEM")] +// public static List ToIESShading(this List panelsAsShade, SettingsIES settingsIES) +// { +// List panels = panelsAsShade.Where(x => x.ExternalEdges.Count > 0).ToList(); + +// if (panels.Count != panelsAsShade.Count) +// BH.Engine.Base.Compute.RecordWarning("The panels for shading contain panels which did not contain geometry. Panels without valid geometry cannot be converted for IES to handle and have been ignored."); + +// List gemPanel = new List(); + +// 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"); +// gemPanel.Add("IES IES_SHD_" + (x + 1).ToString() + "\n"); + +// List points = panels[x].Vertices().Select(y => y.RoundCoordinates(settingsIES.DecimalPlaces)).ToList(); +// points = points.Distinct().ToList(); +// gemPanel.Add(points.Count.ToString() + " 1\n"); + +// string s = points.Count.ToString(); + +// 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"); - else - { - gemPanel.Add(panels[x].Openings.Count.ToString() + "\n"); - - foreach (Opening o in panels[x].Openings) - gemPanel.AddRange(o.ToIES(panels[x], new List { panels[x] }, settingsIES)); - } - } - - return gemPanel; - } - - [Description("Convert an IES string representation of a space into a collection of BHoM Environment Panels")] - [Input("iesPanel", "The IES representation of a space.")] - [Input("settingsIES", "The IES settings to use with the IES adapter")] - [Output("panelsAsSpace", "BHoM Environment Space")] - public static Panel FromIESShading(this List iesPanel, SettingsIES settingsIES, PanelType panelType) - { - Panel panel = new Panel(); - - int numCoordinates = System.Convert.ToInt32(iesPanel[1].Split(' ')[0]); - - List iesPoints = new List(); //Add the coordinate pts to a list - for (int x = 0; x < numCoordinates; x++) - iesPoints.Add(iesPanel[x + 2]); +// // Add Openings +// if (panels[x].Openings.Count == 0) +// gemPanel.Add("0\n"); +// else +// { +// gemPanel.Add(panels[x].Openings.Count.ToString() + "\n"); + +// foreach (Opening o in panels[x].Openings) +// gemPanel.AddRange(o.ToIES(panels[x], new List { panels[x] }, settingsIES)); +// } +// } + +// return gemPanel; +// } + +// [Description("Convert an IES string representation of a space into a collection of BHoM Environment Panels")] +// [Input("iesPanel", "The IES representation of a space.")] +// [Input("settingsIES", "The IES settings to use with the IES adapter")] +// [Output("panelsAsSpace", "BHoM Environment Space")] +// public static Panel FromIESShading(this List iesPanel, SettingsIES settingsIES, PanelType panelType) +// { +// Panel panel = new Panel(); + +// int numCoordinates = System.Convert.ToInt32(iesPanel[1].Split(' ')[0]); + +// List iesPoints = new List(); //Add the coordinate pts to a list +// for (int x = 0; x < numCoordinates; x++) +// iesPoints.Add(iesPanel[x + 2]); - List bhomPoints = iesPoints.Select(x => x.FromIES(settingsIES)).ToList(); +// List 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 +// int count = numCoordinates + 2; //Number of coordinates + 2 to get on to the line of the panel in GEM - //Convert to panels - List panelCoord = iesPanel[count].Trim().Split(' ').ToList(); - List pLinePts = new List(); - for (int y = 1; y < panelCoord.Count; y++) - pLinePts.Add(bhomPoints[System.Convert.ToInt32(panelCoord[y]) - 1]); //Add coordinate points in order +// //Convert to panels +// List panelCoord = iesPanel[count].Trim().Split(' ').ToList(); +// List pLinePts = new List(); +// 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, }; - - panel.ExternalEdges = pLine.ToEdges(); - panel.Type = panelType; - panel.Openings = new List(); - - //Add Openings - count++; - int numOpenings = System.Convert.ToInt32(iesPanel[count]); //Number of openings - count++; - int countOpenings = 0; - while (countOpenings < numOpenings) - { - string openingData = iesPanel[count]; - int numCoords = System.Convert.ToInt32(openingData.Split(' ')[0]); - count++; - - List openingPts = new List(); - for (int x = 0; x < numCoords; x++) - openingPts.Add(iesPanel[count + x]); - - panel.Openings.Add(openingPts.FromIES(openingData.Split(' ')[1], settingsIES)); - - count += numCoords; - countOpenings++; - } - - 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 - // IES traditionally defines openings with 2d coordinates. - if (panel.Type != PanelType.TranslucentShade) - { - for (int x = 0; x < panel.Openings.Count; x++) - { - panel.Openings[x] = panel.Openings[x].RepairOpening(panel, new List { panel }); - } - } - } - else - { - panel.Openings = new List(); - } - - return panel; - } - } -} +// pLinePts.Add(pLinePts.First()); //Add first point to close polyline + +// Polyline pLine = new Polyline { ControlPoints = pLinePts, }; + +// panel.ExternalEdges = pLine.ToEdges(); +// panel.Type = panelType; +// panel.Openings = new List(); + +// //Add Openings +// count++; +// int numOpenings = System.Convert.ToInt32(iesPanel[count]); //Number of openings +// count++; +// int countOpenings = 0; +// while (countOpenings < numOpenings) +// { +// string openingData = iesPanel[count]; +// int numCoords = System.Convert.ToInt32(openingData.Split(' ')[0]); +// count++; + +// List openingPts = new List(); +// for (int x = 0; x < numCoords; x++) +// openingPts.Add(iesPanel[count + x]); + +// panel.Openings.Add(openingPts.FromIES(openingData.Split(' ')[1], settingsIES)); + +// count += numCoords; +// countOpenings++; +// } + +// 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 +// // IES traditionally defines openings with 2d coordinates. +// if (panel.Type != PanelType.TranslucentShade) +// { +// for (int x = 0; x < panel.Openings.Count; x++) +// { +// panel.Openings[x] = panel.Openings[x].RepairOpening(panel, new List { panel }); +// } +// } +// } +// else +// { +// panel.Openings = new List(); +// } + +// return panel; +// } +// } +//} diff --git a/IES_Engine/IES_Engine.csproj b/IES_Engine/IES_Engine.csproj index 2992e4a..c4dd77d 100644 --- a/IES_Engine/IES_Engine.csproj +++ b/IES_Engine/IES_Engine.csproj @@ -1,4 +1,4 @@ - + @@ -88,8 +88,6 @@ - - @@ -118,4 +116,4 @@ xcopy "$(ProjectDir)Extensions" "C:\ProgramData\BHoM\Extensions\CFD" /E /Y /I --> - + \ No newline at end of file From 021bedab249a763838ab2adbcb2c7134667e1ba8 Mon Sep 17 00:00:00 2001 From: Karolina Prusicka Date: Tue, 24 Jan 2023 17:21:57 +0000 Subject: [PATCH 04/27] Creating new methods --- IES_Adapter/Convert/Environment/Opening.cs | 17 ++++++++++++ IES_Adapter/Query/Corner.cs | 12 +++++++++ IES_Adapter/Query/UpperOrientatedPlane.cs | 30 +++++++++++++++++++++ IES_Adapter/Query/XyzToXy.cs | 31 ++++++++++++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 IES_Adapter/Convert/Environment/Opening.cs create mode 100644 IES_Adapter/Query/Corner.cs create mode 100644 IES_Adapter/Query/UpperOrientatedPlane.cs create mode 100644 IES_Adapter/Query/XyzToXy.cs diff --git a/IES_Adapter/Convert/Environment/Opening.cs b/IES_Adapter/Convert/Environment/Opening.cs new file mode 100644 index 0000000..50641e4 --- /dev/null +++ b/IES_Adapter/Convert/Environment/Opening.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BH.oM.Environment.Elements; + +namespace BH.Adapter.IES +{ + public static partial class Convert + { + public static List ToIES (this Opening opening) + { + + } + } +} diff --git a/IES_Adapter/Query/Corner.cs b/IES_Adapter/Query/Corner.cs new file mode 100644 index 0000000..b01273e --- /dev/null +++ b/IES_Adapter/Query/Corner.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Adapter.IES.Query +{ + internal class Corner + { + } +} diff --git a/IES_Adapter/Query/UpperOrientatedPlane.cs b/IES_Adapter/Query/UpperOrientatedPlane.cs new file mode 100644 index 0000000..b3a63ee --- /dev/null +++ b/IES_Adapter/Query/UpperOrientatedPlane.cs @@ -0,0 +1,30 @@ +using BH.Engine.Environment; +using BH.Engine.Geometry; +using BH.oM.Environment.Elements; +using BH.oM.Geometry; +using BH.oM.Geometry.CoordinateSystem; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Adapter.IES +{ + public static partial class Query + { + public static Cartesian UpperOrientatedPlane(this Panel panel) + { + var plane = panel.Polyline().FitPlane(); + + if (plane.Normal.Z == 1 || plane.Normal.Z == -1) + return new Cartesian(plane.Origin, Vector.XAxis, Vector.YAxis, Vector.ZAxis); + else + { + var projY = new Vector() { X = 0, Y = 0, Z = 0 }.Project(plane.Normal); + var projX = projY.Rotate(Math.PI / -2, plane.Normal); + return new Cartesian(plane.Origin, projX, Vector.YAxis, Vector.ZAxis); + } + } + } +} diff --git a/IES_Adapter/Query/XyzToXy.cs b/IES_Adapter/Query/XyzToXy.cs new file mode 100644 index 0000000..8974757 --- /dev/null +++ b/IES_Adapter/Query/XyzToXy.cs @@ -0,0 +1,31 @@ +using BH.Engine.Geometry; +using BH.oM.Geometry; +using BH.oM.Geometry.CoordinateSystem; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Adapter.IES +{ + public static partial class Query + { + public static Point XyzToXy(this Point pt, Cartesian refPlane) + { + var diff = new Vector() + { + X = pt.X - refPlane.Origin.X, + Y = pt.Y - refPlane.Origin.Y, + Z = pt.Z - refPlane.Origin.Z, + }; + + return new Point() + { + X = refPlane.X.DotProduct(diff), + Y = refPlane.Y.DotProduct(diff), + Z = 0 + }; + } + } +} From 72c2852b3b9a007f6d1df0226456276d01ab8343 Mon Sep 17 00:00:00 2001 From: Karolina Prusicka Date: Tue, 24 Jan 2023 17:23:06 +0000 Subject: [PATCH 05/27] Creating new methods v2 --- IES_Adapter/Convert/Environment/Opening.cs | 10 ++++++++- IES_Adapter/Query/Corner.cs | 22 +++++++++++++++++--- IES_Adapter/Query/XyzToXy.cs | 24 ++++++++++++++++++++++ 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/IES_Adapter/Convert/Environment/Opening.cs b/IES_Adapter/Convert/Environment/Opening.cs index 50641e4..056437e 100644 --- a/IES_Adapter/Convert/Environment/Opening.cs +++ b/IES_Adapter/Convert/Environment/Opening.cs @@ -3,15 +3,23 @@ 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; namespace BH.Adapter.IES { public static partial class Convert { - public static List ToIES (this Opening opening) + public static List ToIES (this Opening opening, Panel hostPanel) { + + + var fuckYou = hostPanel.Polyline().FitPlane().Normal; + //Vector normal = + } } } diff --git a/IES_Adapter/Query/Corner.cs b/IES_Adapter/Query/Corner.cs index b01273e..2fcf49b 100644 --- a/IES_Adapter/Query/Corner.cs +++ b/IES_Adapter/Query/Corner.cs @@ -1,12 +1,28 @@ -using System; +using BH.Engine.Environment; +using BH.oM.Environment.Elements; +using BH.oM.Geometry; +using BH.oM.Geometry.CoordinateSystem; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BH.Adapter.IES.Query +namespace BH.Adapter.IES { - internal class Corner + public static partial class Query { + public static Point LowerLeftCorner(this Panel panel) + { + var pline = panel.Polyline(); + var refPlane = panel.UpperOrientatedPlane(); + + var coords = pline.ControlPoints; + coords = coords.Select(x => x.XyzToXy(refPlane)).ToList(); + + var minX = coords.Min(pt => pt.X); + var minY = coords.Min(pt => pt.Y); + + } } } diff --git a/IES_Adapter/Query/XyzToXy.cs b/IES_Adapter/Query/XyzToXy.cs index 8974757..119f670 100644 --- a/IES_Adapter/Query/XyzToXy.cs +++ b/IES_Adapter/Query/XyzToXy.cs @@ -27,5 +27,29 @@ public static Point XyzToXy(this Point pt, Cartesian refPlane) Z = 0 }; } + + public static Point XyToXyz(this Point pt, Cartesian refPlane) + { + var u = new Vector() + { + X = refPlane.X.X * pt.X, + Y = refPlane.X.Y * pt.X, + Z = refPlane.X.Z * pt.X, + }; + + var v = new Vector() + { + X = refPlane.Y.X * pt.Y, + Y = refPlane.Y.Y * pt.Y, + Z = refPlane.Y.Z * pt.Y, + }; + + return new Point() + { + X = refPlane.Origin.X + u.X + v.X, + Y = refPlane.Origin.Y + u.Y + v.Y, + Z = refPlane.Origin.Z + u.Z + v.Z, + }; + } } } From 5f7b8dcb55a59b17087306fd8efa80e1c1738b33 Mon Sep 17 00:00:00 2001 From: Karolina Prusicka Date: Wed, 25 Jan 2023 14:31:14 +0000 Subject: [PATCH 06/27] Modifying new methods --- IES_Adapter/Convert/Environment/Opening.cs | 22 ++++++- IES_Adapter/Query/Corner.cs | 13 ++++ IES_Adapter/Query/FlipPlane.cs | 25 ++++++++ IES_Adapter/Query/PolygonInFace.cs | 71 ++++++++++++++++++++++ IES_Adapter/Query/UpperOrientatedPlane.cs | 2 +- 5 files changed, 130 insertions(+), 3 deletions(-) create mode 100644 IES_Adapter/Query/FlipPlane.cs create mode 100644 IES_Adapter/Query/PolygonInFace.cs diff --git a/IES_Adapter/Convert/Environment/Opening.cs b/IES_Adapter/Convert/Environment/Opening.cs index 056437e..7e4cffc 100644 --- a/IES_Adapter/Convert/Environment/Opening.cs +++ b/IES_Adapter/Convert/Environment/Opening.cs @@ -14,11 +14,29 @@ public static partial class Convert { public static List ToIES (this Opening opening, Panel hostPanel) { + + var panelNormal = hostPanel.Polyline().FitPlane().Normal; + var origin = new Point(); + var flip = false; - var fuckYou = hostPanel.Polyline().FitPlane().Normal; - //Vector normal = + if (panelNormal.Z is (-1|1)) + { + origin = hostPanel.UpperRightCorner(); + flip = true; + } + /*else if (panelNormal.Angle()) + { + + }*/ + else + { + origin = hostPanel.LowerLeftCorner(); + flip = false; + } + + var verts_2d = opening.PolygonInFace(hostPanel,origin, flip); } } diff --git a/IES_Adapter/Query/Corner.cs b/IES_Adapter/Query/Corner.cs index 2fcf49b..735410d 100644 --- a/IES_Adapter/Query/Corner.cs +++ b/IES_Adapter/Query/Corner.cs @@ -22,7 +22,20 @@ public static Point LowerLeftCorner(this Panel panel) var minX = coords.Min(pt => pt.X); var minY = coords.Min(pt => pt.Y); + return new Point() { X = minX, Y = minY, Z=0 }.XyToXyz(refPlane); + } + + public static Point UpperRightCorner(this Panel panel) + { + var pline = panel.Polyline(); + var refPlane = panel.UpperOrientatedPlane(); + + var coords = pline.ControlPoints; + coords = coords.Select(x => x.XyzToXy(refPlane)).ToList(); + var maxX = coords.Max(pt => pt.X); + var maxY = coords.Max(pt => pt.Y); + return new Point() { X = maxX, Y = maxY, Z = 0 }.XyToXyz(refPlane); } } } diff --git a/IES_Adapter/Query/FlipPlane.cs b/IES_Adapter/Query/FlipPlane.cs new file mode 100644 index 0000000..0e9bf64 --- /dev/null +++ b/IES_Adapter/Query/FlipPlane.cs @@ -0,0 +1,25 @@ +using BH.Engine.Geometry; +using BH.oM.Geometry; +using BH.oM.Geometry.CoordinateSystem; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Adapter.IES +{ + public static partial class Query + { + public static Cartesian FlipPlane(this Cartesian refPlane) + { + return new Cartesian( + refPlane.Origin, + refPlane.X, + -refPlane.Y, + -refPlane.Z + ); + } + + } +} diff --git a/IES_Adapter/Query/PolygonInFace.cs b/IES_Adapter/Query/PolygonInFace.cs new file mode 100644 index 0000000..07a9832 --- /dev/null +++ b/IES_Adapter/Query/PolygonInFace.cs @@ -0,0 +1,71 @@ +using BH.Engine.Environment; +using BH.Engine.Geometry; +using BH.oM.Environment.Elements; +using BH.oM.Geometry; +using BH.oM.Geometry.CoordinateSystem; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Adapter.IES +{ + public static partial class Query + { + public static Polyline PolygonInFace ( this Opening opening, Panel hostPanel, Point origin, bool flip ) + { + + + Cartesian coordinateSystem = hostPanel.UpperOrientatedPlane(); + + if (origin is null) + { + if (flip) + { + coordinateSystem = coordinateSystem.FlipPlane(); + } + } + else + { + if (coordinateSystem.Z.IsParallel(Vector.ZAxis) != 0) //Parallel to Z + { + Vector localX = flip ? -Vector.XAxis : Vector.XAxis; + Vector localY = coordinateSystem.Z.CrossProduct(localX); + coordinateSystem = Engine.Geometry.Create.CartesianCoordinateSystem(origin, localX, localY); + + } + else + { + Vector projY = Vector.ZAxis.Project(coordinateSystem.Z); + Vector projX = projY.Rotate(-Math.PI / 2, coordinateSystem.Z); + coordinateSystem = Engine.Geometry.Create.CartesianCoordinateSystem(origin, projX, projY); + + } + } + var vertices = opening.Polyline().ControlPoints; + var pts2D = new List(); + + foreach (Point pt in vertices) + { + var pt2D = pt.XyzToXy(coordinateSystem); + pts2D.Add(pt2D); + } + return Engine.Geometry.Create.Polyline(pts2D); + } +/* + public static Cartesian CoordinateSystem(this Panel hostPanel) + { + Polyline boundary = hostPanel.Polyline(); + Plane plane = boundary.FitPlane(); + + Vector localX = (boundary.ControlPoints[1] - boundary.ControlPoints[0]).Normalise(); + + Vector localY = plane.Normal.CrossProduct(localX); + + return new Cartesian(plane.Origin, localX, localY, plane.Normal); + } +*/ + } +} diff --git a/IES_Adapter/Query/UpperOrientatedPlane.cs b/IES_Adapter/Query/UpperOrientatedPlane.cs index b3a63ee..9930a86 100644 --- a/IES_Adapter/Query/UpperOrientatedPlane.cs +++ b/IES_Adapter/Query/UpperOrientatedPlane.cs @@ -21,7 +21,7 @@ public static Cartesian UpperOrientatedPlane(this Panel panel) return new Cartesian(plane.Origin, Vector.XAxis, Vector.YAxis, Vector.ZAxis); else { - var projY = new Vector() { X = 0, Y = 0, Z = 0 }.Project(plane.Normal); + var projY = Vector.ZAxis.Project(plane.Normal); var projX = projY.Rotate(Math.PI / -2, plane.Normal); return new Cartesian(plane.Origin, projX, Vector.YAxis, Vector.ZAxis); } From 71a84f59ccf4382e8057ae062ab4efaf2e12478c Mon Sep 17 00:00:00 2001 From: Karolina Prusicka Date: Wed, 25 Jan 2023 14:35:07 +0000 Subject: [PATCH 07/27] Update csproj --- IES_Adapter/IES_Adapter.csproj | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/IES_Adapter/IES_Adapter.csproj b/IES_Adapter/IES_Adapter.csproj index 6ff573a..142d4f1 100644 --- a/IES_Adapter/IES_Adapter.csproj +++ b/IES_Adapter/IES_Adapter.csproj @@ -117,6 +117,7 @@ + @@ -127,6 +128,11 @@ + + + + + From 832a6fd8a1354d7d4344b25e80036991a764eb60 Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Wed, 25 Jan 2023 16:56:36 +0000 Subject: [PATCH 08/27] Make work in adapter - lots of incompliant code though --- IES_Adapter/Convert/Environment/Opening.cs | 9 ++ IES_Adapter/Convert/Environment/Space.cs | 4 +- IES_Adapter/Convert/Geometry/Point.cs | 7 +- IES_Adapter/Query/PolygonInFace.cs | 49 ++---- IES_Adapter/Query/UpperOrientatedPlane.cs | 4 +- IES_Engine/Convert/Environment/OpeningType.cs | 144 +++++++++++++++++- 6 files changed, 172 insertions(+), 45 deletions(-) diff --git a/IES_Adapter/Convert/Environment/Opening.cs b/IES_Adapter/Convert/Environment/Opening.cs index 7e4cffc..3551273 100644 --- a/IES_Adapter/Convert/Environment/Opening.cs +++ b/IES_Adapter/Convert/Environment/Opening.cs @@ -38,6 +38,15 @@ public static List ToIES (this Opening opening, Panel hostPanel) var verts_2d = opening.PolygonInFace(hostPanel,origin, flip); + List fuckingHell = new List(); + + fuckingHell.Add($"{verts_2d.ControlPoints.Count} 0\n"); + + foreach (var hell in verts_2d.ControlPoints) + fuckingHell.Add($"{hell.ToIES(new oM.IES.Settings.SettingsIES(), 2)}\n"); + + return fuckingHell; + } } } diff --git a/IES_Adapter/Convert/Environment/Space.cs b/IES_Adapter/Convert/Environment/Space.cs index edf8e6f..33ed5ff 100644 --- a/IES_Adapter/Convert/Environment/Space.cs +++ b/IES_Adapter/Convert/Environment/Space.cs @@ -102,8 +102,8 @@ public static List ToIES(this List panelsAsSpace, SettingsIES set { gemSpace.Add(p.Openings.Count.ToString() + "\n"); - /*foreach (Opening o in p.Openings) - gemSpace.AddRange(o.ToIES(p, panels, settingsIES));*/ + foreach (Opening o in p.Openings) + gemSpace.AddRange(o.ToIES(p)); } } diff --git a/IES_Adapter/Convert/Geometry/Point.cs b/IES_Adapter/Convert/Geometry/Point.cs index 8cc2294..dc4031b 100644 --- a/IES_Adapter/Convert/Geometry/Point.cs +++ b/IES_Adapter/Convert/Geometry/Point.cs @@ -42,9 +42,12 @@ public static partial class Convert [Input("pt", "BHoM Geometry Point to convert")] [Input("settingsIES", "The IES settings to use with the IES adapter")] [Output("iesPt", "The IES string representation of the point")] - public static string ToIES(this Point pt, SettingsIES settingsIES) + public static string ToIES(this Point pt, SettingsIES settingsIES, int num = 3) { - return " " + Math.Round(pt.X, settingsIES.DecimalPlaces).ToString() + " " + Math.Round(pt.Y, settingsIES.DecimalPlaces).ToString() + " " + Math.Round(pt.Z, settingsIES.DecimalPlaces).ToString() + "\n"; + if (num == 3) + return " " + Math.Round(pt.X, settingsIES.DecimalPlaces).ToString() + " " + Math.Round(pt.Y, settingsIES.DecimalPlaces).ToString() + " " + Math.Round(pt.Z, settingsIES.DecimalPlaces).ToString() + "\n"; + else + return " " + Math.Round(pt.X, settingsIES.DecimalPlaces).ToString() + " " + Math.Round(pt.Y, settingsIES.DecimalPlaces).ToString() + "\n"; } [Description("Convert an IES point representation to a BHoM point")] diff --git a/IES_Adapter/Query/PolygonInFace.cs b/IES_Adapter/Query/PolygonInFace.cs index 07a9832..c4ae9e5 100644 --- a/IES_Adapter/Query/PolygonInFace.cs +++ b/IES_Adapter/Query/PolygonInFace.cs @@ -14,48 +14,21 @@ namespace BH.Adapter.IES { public static partial class Query { - public static Polyline PolygonInFace ( this Opening opening, Panel hostPanel, Point origin, bool flip ) + public static Polyline PolygonInFace(this Opening opening, Panel hostPanel, Point origin, bool flip ) { + BH.oM.Geometry.CoordinateSystem.Cartesian coordinateSystem = hostPanel.UpperOrientatedPlane(); + if (flip) + coordinateSystem = coordinateSystem.FlipPlane(); - Cartesian coordinateSystem = hostPanel.UpperOrientatedPlane(); + if (origin != null) + coordinateSystem.Origin = origin; - if (origin is null) - { - if (flip) - { - coordinateSystem = coordinateSystem.FlipPlane(); - } - } - else - { - if (coordinateSystem.Z.IsParallel(Vector.ZAxis) != 0) //Parallel to Z - { - Vector localX = flip ? -Vector.XAxis : Vector.XAxis; - Vector localY = coordinateSystem.Z.CrossProduct(localX); - coordinateSystem = Engine.Geometry.Create.CartesianCoordinateSystem(origin, localX, localY); - - } - else - { - Vector projY = Vector.ZAxis.Project(coordinateSystem.Z); - Vector projX = projY.Rotate(-Math.PI / 2, coordinateSystem.Z); - coordinateSystem = Engine.Geometry.Create.CartesianCoordinateSystem(origin, projX, projY); - - } - } - var vertices = opening.Polyline().ControlPoints; - var pts2D = new List(); - - foreach (Point pt in vertices) - { - var pt2D = pt.XyzToXy(coordinateSystem); - pts2D.Add(pt2D); - } - return Engine.Geometry.Create.Polyline(pts2D); + TransformMatrix transformation = Engine.Geometry.Create.OrientationMatrix(coordinateSystem, new Cartesian()); + return Engine.Geometry.Create.Polyline(opening.Polyline().ControlPoints.Select(x => x.Transform(transformation))); } -/* - public static Cartesian CoordinateSystem(this Panel hostPanel) + + public static Cartesian UpperOrientatedPlane(this Panel hostPanel) { Polyline boundary = hostPanel.Polyline(); Plane plane = boundary.FitPlane(); @@ -66,6 +39,6 @@ public static Cartesian CoordinateSystem(this Panel hostPanel) return new Cartesian(plane.Origin, localX, localY, plane.Normal); } -*/ + } } diff --git a/IES_Adapter/Query/UpperOrientatedPlane.cs b/IES_Adapter/Query/UpperOrientatedPlane.cs index 9930a86..fbc510a 100644 --- a/IES_Adapter/Query/UpperOrientatedPlane.cs +++ b/IES_Adapter/Query/UpperOrientatedPlane.cs @@ -13,7 +13,7 @@ namespace BH.Adapter.IES { public static partial class Query { - public static Cartesian UpperOrientatedPlane(this Panel panel) + /*public static Cartesian UpperOrientatedPlane(this Panel panel) { var plane = panel.Polyline().FitPlane(); @@ -25,6 +25,6 @@ public static Cartesian UpperOrientatedPlane(this Panel panel) var projX = projY.Rotate(Math.PI / -2, plane.Normal); return new Cartesian(plane.Origin, projX, Vector.YAxis, Vector.ZAxis); } - } + }*/ } } diff --git a/IES_Engine/Convert/Environment/OpeningType.cs b/IES_Engine/Convert/Environment/OpeningType.cs index 4d76401..8d94a87 100644 --- a/IES_Engine/Convert/Environment/OpeningType.cs +++ b/IES_Engine/Convert/Environment/OpeningType.cs @@ -32,12 +32,154 @@ using BH.oM.Environment.Elements; using BH.Engine.Environment; using BH.Engine.Geometry; -using BH.oM.IES.Settings; +using BH.oM.IES.Settings; +using BH.oM.Geometry.CoordinateSystem; namespace BH.Engine.Adapters.IES { public static partial class Convert { + public static Point LowerLeftCorner(this Panel panel) + { + var pline = panel.Polyline(); + var refPlane = panel.UpperOrientatedPlane(); + + var coords = pline.ControlPoints; + coords = coords.Select(x => x.XyzToXy(refPlane)).ToList(); + + var minX = coords.Min(pt => pt.X); + var minY = coords.Min(pt => pt.Y); + return new Point() { X = minX, Y = minY, Z = 0 }.XyToXyz(refPlane); + } + + public static Point UpperRightCorner(this Panel panel) + { + var pline = panel.Polyline(); + var refPlane = panel.UpperOrientatedPlane(); + + var coords = pline.ControlPoints; + coords = coords.Select(x => x.XyzToXy(refPlane)).ToList(); + + var maxX = coords.Max(pt => pt.X); + var maxY = coords.Max(pt => pt.Y); + return new Point() { X = maxX, Y = maxY, Z = 0 }.XyToXyz(refPlane); + } + + public static Cartesian FlipPlane(this Cartesian refPlane) + { + return new Cartesian( + refPlane.Origin, + refPlane.X, + -refPlane.Y, + -refPlane.Z + ); + } + + public static Cartesian UpperOrientatedPlane(this Panel hostPanel) + { + Polyline boundary = hostPanel.Polyline(); + Plane plane = boundary.FitPlane(); + + Vector localX = (boundary.ControlPoints[1] - boundary.ControlPoints[0]).Normalise(); + + Vector localY = plane.Normal.CrossProduct(localX); + + return new Cartesian(plane.Origin, localX, localY, plane.Normal); + } + + /*public static Cartesian UpperOrientatedPlane(this Panel panel) + { + var plane = panel.Polyline().FitPlane(); + + if (plane.Normal.Z == 1 || plane.Normal.Z == -1) + return new Cartesian(plane.Origin, Vector.XAxis, Vector.YAxis, Vector.ZAxis); + else + { + var projY = Vector.ZAxis.Project(plane.Normal); + var projX = projY.Rotate(Math.PI / -2, plane.Normal); + return new Cartesian(plane.Origin, projX, Vector.YAxis, Vector.ZAxis); + } + }*/ + + public static Polyline PolygonInFace(this Opening opening, Panel hostPanel, Point origin, bool flip) + { + BH.oM.Geometry.CoordinateSystem.Cartesian coordinateSystem = hostPanel.UpperOrientatedPlane(); + + if (flip) + coordinateSystem = coordinateSystem.FlipPlane(); + + if(origin != null) + coordinateSystem.Origin = origin; + + TransformMatrix transformation = Engine.Geometry.Create.OrientationMatrix(coordinateSystem, new Cartesian()); + return Engine.Geometry.Create.Polyline(opening.Polyline().ControlPoints.Select(x => x.Transform(transformation))); + + + /* if (origin == null && flip) + coordinateSystem = coordinateSystem.FlipPlane(); + else + { + if (coordinateSystem.Z.IsParallel(Vector.ZAxis) != 0) //Parallel to Z + { + Vector localX = flip ? -Vector.XAxis : Vector.XAxis; + Vector localY = coordinateSystem.Z.CrossProduct(localX); + coordinateSystem = Engine.Geometry.Create.CartesianCoordinateSystem(origin, localX, localY); + } + else + { + Vector projY = Vector.ZAxis.Project(coordinateSystem.Z); + Vector projX = projY.Rotate(-Math.PI / 2, coordinateSystem.Z); + coordinateSystem = Engine.Geometry.Create.CartesianCoordinateSystem(origin, projX, projY); + } + } + + var vertices = opening.Polyline().ControlPoints; + var pts2D = vertices.Select(x => x.XyzToXy(coordinateSystem)).ToList(); + + return Engine.Geometry.Create.Polyline(pts2D);*/ + } + + public static Point XyzToXy(this Point pt, Cartesian refPlane) + { + var diff = new Vector() + { + X = pt.X - refPlane.Origin.X, + Y = pt.Y - refPlane.Origin.Y, + Z = pt.Z - refPlane.Origin.Z, + }; + + return new Point() + { + X = refPlane.X.DotProduct(diff), + Y = refPlane.Y.DotProduct(diff), + Z = 0 + }; + } + + public static Point XyToXyz(this Point pt, Cartesian refPlane) + { + var u = new Vector() + { + X = refPlane.X.X * pt.X, + Y = refPlane.X.Y * pt.X, + Z = refPlane.X.Z * pt.X, + }; + + var v = new Vector() + { + X = refPlane.Y.X * pt.Y, + Y = refPlane.Y.Y * pt.Y, + Z = refPlane.Y.Z * pt.Y, + }; + + return new Point() + { + X = refPlane.Origin.X + u.X + v.X, + Y = refPlane.Origin.Y + u.Y + v.Y, + Z = refPlane.Origin.Z + u.Z + v.Z, + }; + } + [Description("Convert a BHoM Opening Type to an IES string representation for GEM format")] [Input("type", "The BHoM Opening Type to convert")] From eeadc823e12101ab7d669c8321ca4bd869d09e63 Mon Sep 17 00:00:00 2001 From: Karolina Prusicka Date: Fri, 27 Jan 2023 15:22:30 +0000 Subject: [PATCH 09/27] Trying to fix the windows --- IES_Adapter/Convert/Environment/Opening.cs | 8 +- IES_Adapter/Convert/Geometry/Point - Copy.cs | 79 ++++++++ IES_Adapter/Convert/Geometry/Point.cs | 2 +- IES_Adapter/IES_Adapter.csproj | 3 + IES_Adapter/Query/Corner.cs | 2 +- IES_Adapter/Query/FitPlane2.cs | 86 +++++++++ IES_Adapter/Query/PolygonInFace.cs | 46 +++-- IES_Adapter/Query/Rotate2.cs | 33 ++++ IES_Adapter/Query/UpperOrientatedPlane.cs | 24 ++- IES_Adapter/Query/XyzToXy.cs | 14 +- IES_Engine/Convert/Environment/OpeningType.cs | 181 +++++++++++++++--- IES_Engine/Convert/Environment/Point.cs | 79 ++++++++ IES_Engine/IES_Engine.csproj | 1 + 13 files changed, 499 insertions(+), 59 deletions(-) create mode 100644 IES_Adapter/Convert/Geometry/Point - Copy.cs create mode 100644 IES_Adapter/Query/FitPlane2.cs create mode 100644 IES_Adapter/Query/Rotate2.cs create mode 100644 IES_Engine/Convert/Environment/Point.cs diff --git a/IES_Adapter/Convert/Environment/Opening.cs b/IES_Adapter/Convert/Environment/Opening.cs index 3551273..bc9b15d 100644 --- a/IES_Adapter/Convert/Environment/Opening.cs +++ b/IES_Adapter/Convert/Environment/Opening.cs @@ -14,10 +14,7 @@ public static partial class Convert { public static List ToIES (this Opening opening, Panel hostPanel) { - - - - var panelNormal = hostPanel.Polyline().FitPlane().Normal; + var panelNormal = hostPanel.Polyline().ControlPoints.FitPlane2().Normal; var origin = new Point(); var flip = false; @@ -43,10 +40,9 @@ public static List ToIES (this Opening opening, Panel hostPanel) fuckingHell.Add($"{verts_2d.ControlPoints.Count} 0\n"); foreach (var hell in verts_2d.ControlPoints) - fuckingHell.Add($"{hell.ToIES(new oM.IES.Settings.SettingsIES(), 2)}\n"); + fuckingHell.Add($"{BH.Adapter.IES.Convert.ToIES(hell, new oM.IES.Settings.SettingsIES(), 2)}"); return fuckingHell; - } } } diff --git a/IES_Adapter/Convert/Geometry/Point - Copy.cs b/IES_Adapter/Convert/Geometry/Point - Copy.cs new file mode 100644 index 0000000..aa910f7 --- /dev/null +++ b/IES_Adapter/Convert/Geometry/Point - Copy.cs @@ -0,0 +1,79 @@ +///* +// * 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 . +// */ + +//using System; +//using System.Collections.Generic; +//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.Adapter.IES +//{ +// public static partial class Convert +// { +// [Description("Convert a BHoM Geometry Point into an IES string representation for GEM files")] +// [Input("pt", "BHoM Geometry Point to convert")] +// [Input("settingsIES", "The IES settings to use with the IES adapter")] +// [Output("iesPt", "The IES string representation of the point")] +// public static string ToIES(this Point pt, SettingsIES settingsIES, int num = 3) +// { +// if (num == 3) +// return " " + Math.Round(pt.X, settingsIES.DecimalPlaces).ToString() + " " + Math.Round(pt.Y, settingsIES.DecimalPlaces).ToString() + " " + Math.Round(pt.Z, settingsIES.DecimalPlaces).ToString() + "\n"; +// else +// return " " + Math.Round(pt.X, settingsIES.DecimalPlaces).ToString() + " " + Math.Round(pt.Y, settingsIES.DecimalPlaces).ToString() + "\n"; +// } + +// [Description("Convert an IES point representation to a BHoM point")] +// [Input("iesPt", "The IES string representation of a point to convert")] +// [Input("settingsIES", "The IES settings to use with the IES adapter")] +// [Output("point", "A BHoM Geometry Point")] +// public static Point FromIES(this string iesPt, SettingsIES settingsIES) +// { +// try +// { +// iesPt = iesPt.Trim(); +// string[] split = System.Text.RegularExpressions.Regex.Split(iesPt, @"\s+"); +// return new Point +// { +// X = System.Convert.ToDouble(split[0]), +// Y = System.Convert.ToDouble(split[1]), +// Z = (split.Length > 2 ? System.Convert.ToDouble(split[2]) : 0), +// }; +// } +// catch (Exception e) +// { +// BH.Engine.Base.Compute.RecordError("An error occurred in parsing that IES string to a BHoM point. Error was: " + e.ToString()); +// return null; +// } +// } +// } +//} + + diff --git a/IES_Adapter/Convert/Geometry/Point.cs b/IES_Adapter/Convert/Geometry/Point.cs index dc4031b..22144d7 100644 --- a/IES_Adapter/Convert/Geometry/Point.cs +++ b/IES_Adapter/Convert/Geometry/Point.cs @@ -47,7 +47,7 @@ public static string ToIES(this Point pt, SettingsIES settingsIES, int num = 3) if (num == 3) return " " + Math.Round(pt.X, settingsIES.DecimalPlaces).ToString() + " " + Math.Round(pt.Y, settingsIES.DecimalPlaces).ToString() + " " + Math.Round(pt.Z, settingsIES.DecimalPlaces).ToString() + "\n"; else - return " " + Math.Round(pt.X, settingsIES.DecimalPlaces).ToString() + " " + Math.Round(pt.Y, settingsIES.DecimalPlaces).ToString() + "\n"; + return " " + Math.Round(Math.Abs(pt.X), settingsIES.DecimalPlaces).ToString() + " " + Math.Round(Math.Abs(pt.Y), settingsIES.DecimalPlaces).ToString() + "\n"; } [Description("Convert an IES point representation to a BHoM point")] diff --git a/IES_Adapter/IES_Adapter.csproj b/IES_Adapter/IES_Adapter.csproj index 142d4f1..8f1fe6c 100644 --- a/IES_Adapter/IES_Adapter.csproj +++ b/IES_Adapter/IES_Adapter.csproj @@ -119,6 +119,7 @@ + @@ -130,8 +131,10 @@ + + diff --git a/IES_Adapter/Query/Corner.cs b/IES_Adapter/Query/Corner.cs index 735410d..5b6c398 100644 --- a/IES_Adapter/Query/Corner.cs +++ b/IES_Adapter/Query/Corner.cs @@ -14,8 +14,8 @@ public static partial class Query { public static Point LowerLeftCorner(this Panel panel) { - var pline = panel.Polyline(); var refPlane = panel.UpperOrientatedPlane(); + var pline = panel.Polyline(); var coords = pline.ControlPoints; coords = coords.Select(x => x.XyzToXy(refPlane)).ToList(); diff --git a/IES_Adapter/Query/FitPlane2.cs b/IES_Adapter/Query/FitPlane2.cs new file mode 100644 index 0000000..4036c7e --- /dev/null +++ b/IES_Adapter/Query/FitPlane2.cs @@ -0,0 +1,86 @@ +using BH.Engine.Geometry; +using BH.oM.Geometry; +using BH.oM.Geometry.CoordinateSystem; +using Microsoft.SqlServer.Server; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices.ComTypes; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Adapter.IES +{ + public static partial class Query + { + public static Plane FitPlane2(this List verts) + { + verts.RemoveAt(verts.Count - 1); + var cprods = new List(); + var baseVert = verts[0]; + for (int x = 0; x < verts.Count - 2; x++) + { + cprods.Add(NormalFrom3Pts(baseVert, verts[x + 1], verts[x + 2])); + } + + var normal = new Vector() {X = 0, Y = 0, Z = 0}; + foreach (var cprodx in cprods) + { + normal.X += cprodx.X; + normal.Y += cprodx.Y; + normal.Z += cprodx.Z; + } + //normalise the vector + Vector normalVec = null; + + if ((normal.X != 0) || (normal.Y != 0) || (normal.Z != 0)) + { + var ds = Math.Sqrt(Math.Pow(normal.X, 2) + Math.Pow(normal.Y,2) + Math.Pow(normal.Z,2)); + normalVec = new Vector() + { + X = normal.X / ds, + Y = normal.Y / ds, + Z = normal.Z / ds + }; + } + else + { + normalVec = new Vector() + { + X = 0, + Y = 0, + Z = 1 + }; + } + return new Plane() + { + Origin = verts[0], + Normal = normalVec + }; + } + + public static Vector NormalFrom3Pts (this Point pt1, Point pt2, Point pt3) + { + var v1 = new Vector + { + X = pt2.X - pt1.X, + Y = pt2.Y - pt1.Y, + Z = pt2.Z - pt1.Z + }; + var v2 = new Vector + { + X = pt3.X - pt1.X, + Y = pt3.Y - pt1.Y, + Z = pt3.Z - pt1.Z + }; + + return new Vector + { + X = v1.Y * v2.Z - v1.Z * v2.Y, + Y = -v1.X * v2.Z + v1.Z * v2.X, + Z = v1.X * v2.Y - v1.Y * v2.X, + }; + } + } +} diff --git a/IES_Adapter/Query/PolygonInFace.cs b/IES_Adapter/Query/PolygonInFace.cs index c4ae9e5..2c89ff3 100644 --- a/IES_Adapter/Query/PolygonInFace.cs +++ b/IES_Adapter/Query/PolygonInFace.cs @@ -14,31 +14,43 @@ namespace BH.Adapter.IES { public static partial class Query { - public static Polyline PolygonInFace(this Opening opening, Panel hostPanel, Point origin, bool flip ) + public static Polyline PolygonInFace(this Opening opening, Panel hostPanel, Point origin = null, bool flip = false) { BH.oM.Geometry.CoordinateSystem.Cartesian coordinateSystem = hostPanel.UpperOrientatedPlane(); + //Plane plane = hostPanel.Polyline().ControlPoints.FitPlane2(); - if (flip) + /*if (flip) coordinateSystem = coordinateSystem.FlipPlane(); - if (origin != null) + if(origin != null) coordinateSystem.Origin = origin; TransformMatrix transformation = Engine.Geometry.Create.OrientationMatrix(coordinateSystem, new Cartesian()); - return Engine.Geometry.Create.Polyline(opening.Polyline().ControlPoints.Select(x => x.Transform(transformation))); + return Engine.Geometry.Create.Polyline(opening.Polyline().ControlPoints.Select(x => x.Transform(transformation)));*/ + + + /*if (origin == null && flip) + refPlane = refPlane.Flip();// = coordinateSystem.FlipPlane(); + else + {*/ + /*if (coordinateSystem.Z.IsParallel(Vector.ZAxis) != 0) //Parallel to Z + { + Vector localX = flip ? -Vector.XAxis : Vector.XAxis; + Vector localY = coordinateSystem.Z.CrossProduct(localX); + coordinateSystem = Engine.Geometry.Create.CartesianCoordinateSystem(origin, localX, localY); + } + else + { + var projY = Vector.ZAxis.Project(plane); + var projX = plane.Normal.CrossProduct(projY); + coordinateSystem = Engine.Geometry.Create.CartesianCoordinateSystem(plane.Origin, projX, projY); + } + //}*/ + + var vertices = opening.Polyline().ControlPoints; + var pts2D = vertices.Select(x => x.XyzToXy(coordinateSystem)).ToList(); + + return Engine.Geometry.Create.Polyline(pts2D); } - - public static Cartesian UpperOrientatedPlane(this Panel hostPanel) - { - Polyline boundary = hostPanel.Polyline(); - Plane plane = boundary.FitPlane(); - - Vector localX = (boundary.ControlPoints[1] - boundary.ControlPoints[0]).Normalise(); - - Vector localY = plane.Normal.CrossProduct(localX); - - return new Cartesian(plane.Origin, localX, localY, plane.Normal); - } - } } diff --git a/IES_Adapter/Query/Rotate2.cs b/IES_Adapter/Query/Rotate2.cs new file mode 100644 index 0000000..33f4d31 --- /dev/null +++ b/IES_Adapter/Query/Rotate2.cs @@ -0,0 +1,33 @@ +using BH.Engine.Geometry; +using BH.oM.Geometry; +using BH.oM.Geometry.CoordinateSystem; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Adapter.IES +{ + public static partial class Query + { + public static Vector Rotate2(this Vector vec, double angle, Vector axis) + { + var x = vec.X; var y = vec.Y; var z = vec.Z; + var u = axis.X; var v = axis.Y; var w = axis.Z; + //Extracted common factors for simplicity and efficiency + var r2 = Math.Pow(u,2) + Math.Pow(v,2) + Math.Pow(w, 2); + var r = Math.Sqrt(r2); + var ct = Math.Cos(angle); + var st = Math.Sin(angle) / r; + var dt = (u * x + v * y + w * z) * (1 - ct) / r2; + + return new Vector () + { + X = u * dt + x * ct + (-w * y + v * z) * st, + Y = v * dt + y * ct + (w * x - u * z) * st, + Z = w * dt + z * ct + (-v * x + u * y) * st, + }; + } + } +} diff --git a/IES_Adapter/Query/UpperOrientatedPlane.cs b/IES_Adapter/Query/UpperOrientatedPlane.cs index fbc510a..a449013 100644 --- a/IES_Adapter/Query/UpperOrientatedPlane.cs +++ b/IES_Adapter/Query/UpperOrientatedPlane.cs @@ -13,18 +13,32 @@ namespace BH.Adapter.IES { public static partial class Query { - /*public static Cartesian UpperOrientatedPlane(this Panel panel) + public static Cartesian UpperOrientatedPlane(this Panel panel) { - var plane = panel.Polyline().FitPlane(); + /* + var plane = panel.Polyline().ControlPoints.FitPlane2(); if (plane.Normal.Z == 1 || plane.Normal.Z == -1) return new Cartesian(plane.Origin, Vector.XAxis, Vector.YAxis, Vector.ZAxis); else { - var projY = Vector.ZAxis.Project(plane.Normal); - var projX = projY.Rotate(Math.PI / -2, plane.Normal); + var projY = Vector.ZAxis.Project(plane); + var projX = projY.Rotate2(Math.PI / -2, plane.Normal); return new Cartesian(plane.Origin, projX, Vector.YAxis, Vector.ZAxis); + }*/ + + var plane = panel.Polyline().ControlPoints.FitPlane2(); + + //if (plane.Normal.Z == 1 || plane.Normal.Z == -1) + if (plane.Normal.IsParallel(Vector.ZAxis) != 0) + return BH.Engine.Geometry.Create.CartesianCoordinateSystem(plane.Origin, Vector.XAxis, plane.Normal.CrossProduct(Vector.XAxis));// new Cartesian(plane.Origin, Vector.XAxis, Vector.YAxis, Vector.ZAxis); + else + { + + var projY = Vector.ZAxis.Project(plane); + var projX = plane.Normal.CrossProduct(projY); + return Engine.Geometry.Create.CartesianCoordinateSystem(plane.Origin, projX, projY); } - }*/ + } } } diff --git a/IES_Adapter/Query/XyzToXy.cs b/IES_Adapter/Query/XyzToXy.cs index 119f670..55cac16 100644 --- a/IES_Adapter/Query/XyzToXy.cs +++ b/IES_Adapter/Query/XyzToXy.cs @@ -12,7 +12,7 @@ namespace BH.Adapter.IES public static partial class Query { public static Point XyzToXy(this Point pt, Cartesian refPlane) - { + {/* var diff = new Vector() { X = pt.X - refPlane.Origin.X, @@ -25,12 +25,15 @@ public static Point XyzToXy(this Point pt, Cartesian refPlane) X = refPlane.X.DotProduct(diff), Y = refPlane.Y.DotProduct(diff), Z = 0 - }; + };*/ + TransformMatrix m = BH.Engine.Geometry.Create.OrientationMatrixLocalToGlobal(refPlane); + + return pt.Transform(m); } public static Point XyToXyz(this Point pt, Cartesian refPlane) { - var u = new Vector() + /*var u = new Vector() { X = refPlane.X.X * pt.X, Y = refPlane.X.Y * pt.X, @@ -49,7 +52,10 @@ public static Point XyToXyz(this Point pt, Cartesian refPlane) X = refPlane.Origin.X + u.X + v.X, Y = refPlane.Origin.Y + u.Y + v.Y, Z = refPlane.Origin.Z + u.Z + v.Z, - }; + };*/ + + TransformMatrix m = BH.Engine.Geometry.Create.OrientationMatrixGlobalToLocal(refPlane); + return pt.Transform(m); } } } diff --git a/IES_Engine/Convert/Environment/OpeningType.cs b/IES_Engine/Convert/Environment/OpeningType.cs index 8d94a87..34bc18a 100644 --- a/IES_Engine/Convert/Environment/OpeningType.cs +++ b/IES_Engine/Convert/Environment/OpeningType.cs @@ -39,6 +39,39 @@ namespace BH.Engine.Adapters.IES { public static partial class Convert { + public static List OpeningToIES(this Opening opening, Panel hostPanel) + { + var panelNormal = hostPanel.Polyline().ControlPoints.FitPlane2().Normal; + var origin = new Point(); + var flip = false; + + if (panelNormal.Z is (-1|1)) + { + origin = hostPanel.UpperRightCorner(); + flip = true; + } + /*else if (panelNormal.Angle()) + { + + }*/ + else + { + origin = hostPanel.LowerLeftCorner(); + flip = false; + } + + var verts_2d = opening.PolygonInFace(hostPanel,origin, flip); + + List fuckingHell = new List(); + + fuckingHell.Add($"{verts_2d.ControlPoints.Count} 0\n"); + + foreach (var hell in verts_2d.ControlPoints) + fuckingHell.Add($"{(hell.ToIES(new oM.IES.Settings.SettingsIES(), 2))}\n"); + + return fuckingHell; + } + public static Point LowerLeftCorner(this Panel panel) { var pline = panel.Polyline(); @@ -74,48 +107,138 @@ public static Cartesian FlipPlane(this Cartesian refPlane) -refPlane.Z ); } + /* + public static Cartesian UpperOrientatedPlane(this Panel hostPanel) + { + Polyline boundary = hostPanel.Polyline(); + Plane plane = boundary.FitPlane(); - public static Cartesian UpperOrientatedPlane(this Panel hostPanel) - { - Polyline boundary = hostPanel.Polyline(); - Plane plane = boundary.FitPlane(); + Vector localX = (boundary.ControlPoints[1] - boundary.ControlPoints[0]).Normalise(); - Vector localX = (boundary.ControlPoints[1] - boundary.ControlPoints[0]).Normalise(); + Vector localY = plane.Normal.CrossProduct(localX); - Vector localY = plane.Normal.CrossProduct(localX); + return new Cartesian(plane.Origin, localX, localY, plane.Normal); + } + */ + public static Cartesian UpperOrientatedPlane(this Panel panel) + { + var plane = panel.Polyline().ControlPoints.FitPlane2(); - return new Cartesian(plane.Origin, localX, localY, plane.Normal); - } + //if (plane.Normal.Z == 1 || plane.Normal.Z == -1) + if (plane.Normal.IsParallel(Vector.ZAxis) != 0) + return BH.Engine.Geometry.Create.CartesianCoordinateSystem(plane.Origin, Vector.XAxis, plane.Normal.CrossProduct(Vector.XAxis));// new Cartesian(plane.Origin, Vector.XAxis, Vector.YAxis, Vector.ZAxis); + else + { - /*public static Cartesian UpperOrientatedPlane(this Panel panel) + var projY = Vector.ZAxis.Project(plane); + var projX = plane.Normal.CrossProduct(projY); + return Engine.Geometry.Create.CartesianCoordinateSystem(plane.Origin, projX, projY); + } + } + public static Plane FitPlane2(this List verts) { - var plane = panel.Polyline().FitPlane(); + verts.RemoveAt(verts.Count - 1); + var cprods = new List(); + var baseVert = verts[0]; + for (int x = 0; x < verts.Count - 2; x++) + { + cprods.Add(NormalFrom3Pts(baseVert, verts[x + 1], verts[x + 2])); + } + + var normal = new Vector() { X = 0, Y = 0, Z = 0 }; + foreach (var cprodx in cprods) + { + normal.X += cprodx.X; + normal.Y += cprodx.Y; + normal.Z += cprodx.Z; + } + //normalise the vector + Vector normalVec = null; - if (plane.Normal.Z == 1 || plane.Normal.Z == -1) - return new Cartesian(plane.Origin, Vector.XAxis, Vector.YAxis, Vector.ZAxis); + if ((normal.X != 0) || (normal.Y != 0) || (normal.Z != 0)) + { + var ds = Math.Sqrt(Math.Pow(normal.X, 2) + Math.Pow(normal.Y, 2) + Math.Pow(normal.Z, 2)); + normalVec = new Vector() + { + X = normal.X / ds, + Y = normal.Y / ds, + Z = normal.Z / ds + }; + } else { - var projY = Vector.ZAxis.Project(plane.Normal); - var projX = projY.Rotate(Math.PI / -2, plane.Normal); - return new Cartesian(plane.Origin, projX, Vector.YAxis, Vector.ZAxis); + normalVec = new Vector() + { + X = 0, + Y = 0, + Z = 1 + }; } - }*/ + return new Plane() + { + Origin = verts[0], + Normal = normalVec + }; + } - public static Polyline PolygonInFace(this Opening opening, Panel hostPanel, Point origin, bool flip) + public static Vector NormalFrom3Pts(this Point pt1, Point pt2, Point pt3) + { + var v1 = new Vector + { + X = pt2.X - pt1.X, + Y = pt2.Y - pt1.Y, + Z = pt2.Z - pt1.Z + }; + var v2 = new Vector + { + X = pt3.X - pt1.X, + Y = pt3.Y - pt1.Y, + Z = pt3.Z - pt1.Z + }; + + return new Vector + { + X = v1.Y * v2.Z - v1.Z * v2.Y, + Y = -v1.X * v2.Z + v1.Z * v2.X, + Z = v1.X * v2.Y - v1.Y * v2.X, + }; + } + + public static Vector Rotate2(this Vector vec, double angle, Vector axis) + { + var x = vec.X; var y = vec.Y; var z = vec.Z; + var u = axis.X; var v = axis.Y; var w = axis.Z; + //Extracted common factors for simplicity and efficiency + var r2 = Math.Pow(u, 2) + Math.Pow(v, 2) + Math.Pow(w, 2); + var r = Math.Sqrt(r2); + var ct = Math.Cos(angle); + var st = Math.Sin(angle) / r; + var dt = (u * x + v * y + w * z) * (1 - ct) / r2; + + return new Vector() + { + X = u * dt + x * ct + (-w * y + v * z) * st, + Y = v * dt + y * ct + (w * x - u * z) * st, + Z = w * dt + z * ct + (-v * x + u * y) * st, + }; + } + + + public static Polyline PolygonInFace(this Opening opening, Panel hostPanel, Point origin = null, bool flip = false) { BH.oM.Geometry.CoordinateSystem.Cartesian coordinateSystem = hostPanel.UpperOrientatedPlane(); - if (flip) + /*if (flip) coordinateSystem = coordinateSystem.FlipPlane(); if(origin != null) coordinateSystem.Origin = origin; TransformMatrix transformation = Engine.Geometry.Create.OrientationMatrix(coordinateSystem, new Cartesian()); - return Engine.Geometry.Create.Polyline(opening.Polyline().ControlPoints.Select(x => x.Transform(transformation))); + return Engine.Geometry.Create.Polyline(opening.Polyline().ControlPoints.Select(x => x.Transform(transformation)));*/ - /* if (origin == null && flip) + if (origin == null && flip) coordinateSystem = coordinateSystem.FlipPlane(); else { @@ -136,12 +259,12 @@ public static Polyline PolygonInFace(this Opening opening, Panel hostPanel, Poin var vertices = opening.Polyline().ControlPoints; var pts2D = vertices.Select(x => x.XyzToXy(coordinateSystem)).ToList(); - return Engine.Geometry.Create.Polyline(pts2D);*/ + return Engine.Geometry.Create.Polyline(pts2D); } public static Point XyzToXy(this Point pt, Cartesian refPlane) { - var diff = new Vector() + /*var diff = new Vector() { X = pt.X - refPlane.Origin.X, Y = pt.Y - refPlane.Origin.Y, @@ -153,12 +276,17 @@ public static Point XyzToXy(this Point pt, Cartesian refPlane) X = refPlane.X.DotProduct(diff), Y = refPlane.Y.DotProduct(diff), Z = 0 - }; + };*/ + + + TransformMatrix m = BH.Engine.Geometry.Create.OrientationMatrixLocalToGlobal(refPlane); + + return pt.Transform(m); } public static Point XyToXyz(this Point pt, Cartesian refPlane) { - var u = new Vector() + /* var u = new Vector() { X = refPlane.X.X * pt.X, Y = refPlane.X.Y * pt.X, @@ -177,7 +305,10 @@ public static Point XyToXyz(this Point pt, Cartesian refPlane) X = refPlane.Origin.X + u.X + v.X, Y = refPlane.Origin.Y + u.Y + v.Y, Z = refPlane.Origin.Z + u.Z + v.Z, - }; + };*/ + + TransformMatrix m = BH.Engine.Geometry.Create.OrientationMatrixGlobalToLocal(refPlane); + return pt.Transform(m); } diff --git a/IES_Engine/Convert/Environment/Point.cs b/IES_Engine/Convert/Environment/Point.cs new file mode 100644 index 0000000..650f045 --- /dev/null +++ b/IES_Engine/Convert/Environment/Point.cs @@ -0,0 +1,79 @@ +/* + * 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 . + */ + +using System; +using System.Collections.Generic; +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 +{ + public static partial class Convert + { + [Description("Convert a BHoM Geometry Point into an IES string representation for GEM files")] + [Input("pt", "BHoM Geometry Point to convert")] + [Input("settingsIES", "The IES settings to use with the IES adapter")] + [Output("iesPt", "The IES string representation of the point")] + public static string ToIES(this Point pt, SettingsIES settingsIES, int num = 3) + { + if (num == 3) + return " " + Math.Round(pt.X, settingsIES.DecimalPlaces).ToString() + " " + Math.Round(pt.Y, settingsIES.DecimalPlaces).ToString() + " " + Math.Round(pt.Z, settingsIES.DecimalPlaces).ToString() + "\n"; + else + return " " + Math.Round(pt.X, settingsIES.DecimalPlaces).ToString() + " " + Math.Round(pt.Y, settingsIES.DecimalPlaces).ToString() + "\n"; + } + + [Description("Convert an IES point representation to a BHoM point")] + [Input("iesPt", "The IES string representation of a point to convert")] + [Input("settingsIES", "The IES settings to use with the IES adapter")] + [Output("point", "A BHoM Geometry Point")] + public static Point FromIES(this string iesPt, SettingsIES settingsIES) + { + try + { + iesPt = iesPt.Trim(); + string[] split = System.Text.RegularExpressions.Regex.Split(iesPt, @"\s+"); + return new Point + { + X = System.Convert.ToDouble(split[0]), + Y = System.Convert.ToDouble(split[1]), + Z = (split.Length > 2 ? System.Convert.ToDouble(split[2]) : 0), + }; + } + catch (Exception e) + { + BH.Engine.Base.Compute.RecordError("An error occurred in parsing that IES string to a BHoM point. Error was: " + e.ToString()); + return null; + } + } + } +} + + diff --git a/IES_Engine/IES_Engine.csproj b/IES_Engine/IES_Engine.csproj index c4dd77d..2d0f312 100644 --- a/IES_Engine/IES_Engine.csproj +++ b/IES_Engine/IES_Engine.csproj @@ -88,6 +88,7 @@ + From 9e76cafef509d29428a622b14cc75b9fa2841bdd Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Tue, 31 Jan 2023 10:15:32 +0000 Subject: [PATCH 10/27] Implementation of coordinate system from @isaknaslundbh and tidy up of code --- IES_Adapter/CRUD/Create.cs | 1 - IES_Adapter/CRUD/Read.cs | 1 - IES_Adapter/Convert/Environment/Opening.cs | 35 +- .../Convert/Environment/OpeningType.cs | 56 +++ IES_Adapter/Convert/Environment/Panel.cs | 182 +++++++++ IES_Adapter/Convert/Environment/Space.cs | 2 +- IES_Adapter/Convert/Geometry/Point - Copy.cs | 79 ---- IES_Adapter/Convert/Geometry/Point.cs | 4 +- IES_Adapter/IESAdapter.cs | 2 - IES_Adapter/IES_Adapter.csproj | 11 +- IES_Adapter/Query/CoordinateSystem.cs | 33 ++ IES_Adapter/Query/Corner.cs | 41 -- IES_Adapter/Query/FitPlane2.cs | 86 ----- IES_Adapter/Query/FlipPlane.cs | 25 -- IES_Adapter/Query/PolygonInFace.cs | 56 --- IES_Adapter/Query/Rotate2.cs | 33 -- IES_Adapter/Query/UpperOrientatedPlane.cs | 44 --- IES_Adapter/Query/XyzToXy.cs | 61 --- IES_Engine/Convert/Environment/Opening.cs | 156 -------- IES_Engine/Convert/Environment/OpeningType.cs | 357 ------------------ IES_Engine/Convert/Environment/Panel.cs | 182 --------- IES_Engine/Convert/Environment/Point.cs | 79 ---- IES_Engine/IES_Engine.csproj | 6 - IES_Engine/Modify/RepairOpening.cs | 144 ------- IES_Engine/Query/Polyline.cs | 131 ------- 25 files changed, 287 insertions(+), 1520 deletions(-) create mode 100644 IES_Adapter/Convert/Environment/OpeningType.cs create mode 100644 IES_Adapter/Convert/Environment/Panel.cs delete mode 100644 IES_Adapter/Convert/Geometry/Point - Copy.cs create mode 100644 IES_Adapter/Query/CoordinateSystem.cs delete mode 100644 IES_Adapter/Query/Corner.cs delete mode 100644 IES_Adapter/Query/FitPlane2.cs delete mode 100644 IES_Adapter/Query/FlipPlane.cs delete mode 100644 IES_Adapter/Query/PolygonInFace.cs delete mode 100644 IES_Adapter/Query/Rotate2.cs delete mode 100644 IES_Adapter/Query/UpperOrientatedPlane.cs delete mode 100644 IES_Adapter/Query/XyzToXy.cs delete mode 100644 IES_Engine/Convert/Environment/Opening.cs delete mode 100644 IES_Engine/Convert/Environment/OpeningType.cs delete mode 100644 IES_Engine/Convert/Environment/Panel.cs delete mode 100644 IES_Engine/Convert/Environment/Point.cs delete mode 100644 IES_Engine/Modify/RepairOpening.cs delete mode 100644 IES_Engine/Query/Polyline.cs diff --git a/IES_Adapter/CRUD/Create.cs b/IES_Adapter/CRUD/Create.cs index 37ef4e4..3790b9b 100644 --- a/IES_Adapter/CRUD/Create.cs +++ b/IES_Adapter/CRUD/Create.cs @@ -30,7 +30,6 @@ using System.IO; using System.Linq; -using BH.Engine.Adapters.IES; using BH.oM.Adapter; using BH.Engine.Adapter; diff --git a/IES_Adapter/CRUD/Read.cs b/IES_Adapter/CRUD/Read.cs index 27ca1c9..89f089d 100644 --- a/IES_Adapter/CRUD/Read.cs +++ b/IES_Adapter/CRUD/Read.cs @@ -32,7 +32,6 @@ using BH.oM.Environment; using System.IO; -using BH.Engine.Adapters.IES; using BH.oM.Adapter; using BH.Engine.Adapter; diff --git a/IES_Adapter/Convert/Environment/Opening.cs b/IES_Adapter/Convert/Environment/Opening.cs index bc9b15d..8d808b6 100644 --- a/IES_Adapter/Convert/Environment/Opening.cs +++ b/IES_Adapter/Convert/Environment/Opening.cs @@ -7,42 +7,27 @@ 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 ToIES (this Opening opening, Panel hostPanel) + public static List ToIES(this Opening opening, Panel hostPanel, SettingsIES settingsIES) { - var panelNormal = hostPanel.Polyline().ControlPoints.FitPlane2().Normal; - var origin = new Point(); - var flip = false; + List rtn = new List(); - if (panelNormal.Z is (-1|1)) - { - origin = hostPanel.UpperRightCorner(); - flip = true; - } - /*else if (panelNormal.Angle()) - { + var coordSystem = hostPanel.Polyline().CoordinateSystem(); + var localToGlobal = BH.Engine.Geometry.Create.OrientationMatrixLocalToGlobal(coordSystem); - }*/ - else - { - origin = hostPanel.LowerLeftCorner(); - flip = false; - } + var polyline = opening.Polyline().Transform(localToGlobal); - var verts_2d = opening.PolygonInFace(hostPanel,origin, flip); + rtn.Add($"{polyline.ControlPoints.Count.ToString()} {opening.Type.ToIES(settingsIES)}\n"); - List fuckingHell = new List(); + foreach (var cPoint in polyline.ControlPoints) + rtn.Add($" {cPoint.ToIES(settingsIES, false)}"); - fuckingHell.Add($"{verts_2d.ControlPoints.Count} 0\n"); - - foreach (var hell in verts_2d.ControlPoints) - fuckingHell.Add($"{BH.Adapter.IES.Convert.ToIES(hell, new oM.IES.Settings.SettingsIES(), 2)}"); - - return fuckingHell; + return rtn; } } } diff --git a/IES_Adapter/Convert/Environment/OpeningType.cs b/IES_Adapter/Convert/Environment/OpeningType.cs new file mode 100644 index 0000000..338299f --- /dev/null +++ b/IES_Adapter/Convert/Environment/OpeningType.cs @@ -0,0 +1,56 @@ +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.Environment.Elements; + +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) + { + case OpeningType.CurtainWall: + case OpeningType.Glazing: + case OpeningType.Rooflight: + case OpeningType.RooflightWithFrame: + case OpeningType.Window: + case OpeningType.WindowWithFrame: + return "0"; + case OpeningType.Door: + case OpeningType.VehicleDoor: + return "1"; + case OpeningType.Hole: + default: + return "2"; //Hole + } + } + + [Description("Convert an IES string representation of a Opening Type to a BHoM Opening Type")] + [Input("iesOpeningType", "The IES string representation of an opening type")] + [Input("settingsIES", "The IES settings to use with the IES adapter")] + [Output("openingType", "The BHoM Opening Type")] + public static OpeningType FromIESOpeningType(this string iesOpeningType, SettingsIES settingsIES) + { + if (iesOpeningType == "0") + return OpeningType.Window; + if (iesOpeningType == "1") + return OpeningType.Door; + if (iesOpeningType == "2") + return OpeningType.Hole; + + return OpeningType.Undefined; + } + } +} diff --git a/IES_Adapter/Convert/Environment/Panel.cs b/IES_Adapter/Convert/Environment/Panel.cs new file mode 100644 index 0000000..48eb515 --- /dev/null +++ b/IES_Adapter/Convert/Environment/Panel.cs @@ -0,0 +1,182 @@ +/* + * 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 . + */ + +using System; +using System.Collections.Generic; +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.Adapter.IES +{ + public static partial class Convert + { + [Description("Convert a collection of BHoM Environment Panels that represent shading elements into the IES string representation for GEM format")] + [Input("panelsAsShade", "The collection of BHoM Environment Panels that represent shading elements")] + [Input("settingsIES", "The IES settings to use with the IES adapter")] + [Output("iesSpace", "The IES string representation of shade for GEM")] + public static List ToIESShading(this List panelsAsShade, SettingsIES settingsIES) + { + List panels = panelsAsShade.Where(x => x.ExternalEdges.Count > 0).ToList(); + + if (panels.Count != panelsAsShade.Count) + BH.Engine.Base.Compute.RecordWarning("The panels for shading contain panels which did not contain geometry. Panels without valid geometry cannot be converted for IES to handle and have been ignored."); + + List gemPanel = new List(); + + 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"); + gemPanel.Add("IES IES_SHD_" + (x + 1).ToString() + "\n"); + + List points = panels[x].Vertices().Select(y => y.RoundCoordinates(settingsIES.DecimalPlaces)).ToList(); + points = points.Distinct().ToList(); + gemPanel.Add(points.Count.ToString() + " 1\n"); + + string s = points.Count.ToString(); + + 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"); + else + { + gemPanel.Add(panels[x].Openings.Count.ToString() + "\n"); + + foreach (Opening o in panels[x].Openings) + gemPanel.AddRange(o.ToIES(panels[x], settingsIES)); + } + } + + return gemPanel; + } + + [Description("Convert an IES string representation of a space into a collection of BHoM Environment Panels")] + [Input("iesPanel", "The IES representation of a space.")] + [Input("settingsIES", "The IES settings to use with the IES adapter")] + [Output("panelsAsSpace", "BHoM Environment Space")] + public static Panel FromIESShading(this List iesPanel, SettingsIES settingsIES, PanelType panelType) + { + Panel panel = new Panel(); + + int numCoordinates = System.Convert.ToInt32(iesPanel[1].Split(' ')[0]); + + List iesPoints = new List(); //Add the coordinate pts to a list + for (int x = 0; x < numCoordinates; x++) + iesPoints.Add(iesPanel[x + 2]); + + List 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 panelCoord = iesPanel[count].Trim().Split(' ').ToList(); + List pLinePts = new List(); + 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, }; + + panel.ExternalEdges = pLine.ToEdges(); + panel.Type = panelType; + panel.Openings = new List(); + + //Add Openings + count++; + int numOpenings = System.Convert.ToInt32(iesPanel[count]); //Number of openings + count++; + int countOpenings = 0; + while (countOpenings < numOpenings) + { + string openingData = iesPanel[count]; + int numCoords = System.Convert.ToInt32(openingData.Split(' ')[0]); + count++; + + List openingPts = new List(); + for (int x = 0; x < numCoords; x++) + openingPts.Add(iesPanel[count + x]); + + //panel.Openings.Add(openingPts.FromIES(openingData.Split(' ')[1], settingsIES)); + + count += numCoords; + countOpenings++; + } + + /*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 + // IES traditionally defines openings with 2d coordinates. + if (panel.Type != PanelType.TranslucentShade) + { + for (int x = 0; x < panel.Openings.Count; x++) + { + panel.Openings[x] = panel.Openings[x].RepairOpening(panel, new List { panel }); + } + } + } + else + { + panel.Openings = new List(); + }*/ + + return panel; + } + } +} + + diff --git a/IES_Adapter/Convert/Environment/Space.cs b/IES_Adapter/Convert/Environment/Space.cs index 33ed5ff..81f8b44 100644 --- a/IES_Adapter/Convert/Environment/Space.cs +++ b/IES_Adapter/Convert/Environment/Space.cs @@ -103,7 +103,7 @@ public static List ToIES(this List panelsAsSpace, SettingsIES set gemSpace.Add(p.Openings.Count.ToString() + "\n"); foreach (Opening o in p.Openings) - gemSpace.AddRange(o.ToIES(p)); + gemSpace.AddRange(o.ToIES(p, settingsIES)); } } diff --git a/IES_Adapter/Convert/Geometry/Point - Copy.cs b/IES_Adapter/Convert/Geometry/Point - Copy.cs deleted file mode 100644 index aa910f7..0000000 --- a/IES_Adapter/Convert/Geometry/Point - Copy.cs +++ /dev/null @@ -1,79 +0,0 @@ -///* -// * 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 . -// */ - -//using System; -//using System.Collections.Generic; -//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.Adapter.IES -//{ -// public static partial class Convert -// { -// [Description("Convert a BHoM Geometry Point into an IES string representation for GEM files")] -// [Input("pt", "BHoM Geometry Point to convert")] -// [Input("settingsIES", "The IES settings to use with the IES adapter")] -// [Output("iesPt", "The IES string representation of the point")] -// public static string ToIES(this Point pt, SettingsIES settingsIES, int num = 3) -// { -// if (num == 3) -// return " " + Math.Round(pt.X, settingsIES.DecimalPlaces).ToString() + " " + Math.Round(pt.Y, settingsIES.DecimalPlaces).ToString() + " " + Math.Round(pt.Z, settingsIES.DecimalPlaces).ToString() + "\n"; -// else -// return " " + Math.Round(pt.X, settingsIES.DecimalPlaces).ToString() + " " + Math.Round(pt.Y, settingsIES.DecimalPlaces).ToString() + "\n"; -// } - -// [Description("Convert an IES point representation to a BHoM point")] -// [Input("iesPt", "The IES string representation of a point to convert")] -// [Input("settingsIES", "The IES settings to use with the IES adapter")] -// [Output("point", "A BHoM Geometry Point")] -// public static Point FromIES(this string iesPt, SettingsIES settingsIES) -// { -// try -// { -// iesPt = iesPt.Trim(); -// string[] split = System.Text.RegularExpressions.Regex.Split(iesPt, @"\s+"); -// return new Point -// { -// X = System.Convert.ToDouble(split[0]), -// Y = System.Convert.ToDouble(split[1]), -// Z = (split.Length > 2 ? System.Convert.ToDouble(split[2]) : 0), -// }; -// } -// catch (Exception e) -// { -// BH.Engine.Base.Compute.RecordError("An error occurred in parsing that IES string to a BHoM point. Error was: " + e.ToString()); -// return null; -// } -// } -// } -//} - - diff --git a/IES_Adapter/Convert/Geometry/Point.cs b/IES_Adapter/Convert/Geometry/Point.cs index 22144d7..437e9c0 100644 --- a/IES_Adapter/Convert/Geometry/Point.cs +++ b/IES_Adapter/Convert/Geometry/Point.cs @@ -42,9 +42,9 @@ public static partial class Convert [Input("pt", "BHoM Geometry Point to convert")] [Input("settingsIES", "The IES settings to use with the IES adapter")] [Output("iesPt", "The IES string representation of the point")] - public static string ToIES(this Point pt, SettingsIES settingsIES, int num = 3) + public static string ToIES(this Point pt, SettingsIES settingsIES, bool allCoords = true) { - if (num == 3) + if (allCoords) return " " + Math.Round(pt.X, settingsIES.DecimalPlaces).ToString() + " " + Math.Round(pt.Y, settingsIES.DecimalPlaces).ToString() + " " + Math.Round(pt.Z, settingsIES.DecimalPlaces).ToString() + "\n"; else return " " + Math.Round(Math.Abs(pt.X), settingsIES.DecimalPlaces).ToString() + " " + Math.Round(Math.Abs(pt.Y), settingsIES.DecimalPlaces).ToString() + "\n"; diff --git a/IES_Adapter/IESAdapter.cs b/IES_Adapter/IESAdapter.cs index 4c380a3..4278d2b 100644 --- a/IES_Adapter/IESAdapter.cs +++ b/IES_Adapter/IESAdapter.cs @@ -34,8 +34,6 @@ using System.ComponentModel; using BH.oM.Base.Attributes; -using BH.Engine.Adapters.IES; - namespace BH.Adapter.IES { public partial class IESAdapter : BHoMAdapter diff --git a/IES_Adapter/IES_Adapter.csproj b/IES_Adapter/IES_Adapter.csproj index 8f1fe6c..23170a3 100644 --- a/IES_Adapter/IES_Adapter.csproj +++ b/IES_Adapter/IES_Adapter.csproj @@ -118,8 +118,9 @@ + + - @@ -129,13 +130,7 @@ - - - - - - - + diff --git a/IES_Adapter/Query/CoordinateSystem.cs b/IES_Adapter/Query/CoordinateSystem.cs new file mode 100644 index 0000000..abffbe7 --- /dev/null +++ b/IES_Adapter/Query/CoordinateSystem.cs @@ -0,0 +1,33 @@ +using BH.oM.Geometry.CoordinateSystem; +using BH.oM.Geometry; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using BH.Engine.Geometry; + +namespace BH.Adapter.IES +{ + public static partial class Query + { + public static Cartesian CoordinateSystem(this Polyline pLine, double distanceTolerance = Tolerance.MacroDistance, double angleTolerance = Tolerance.Angle) + { + Vector locZ = pLine.Normal(distanceTolerance); Cartesian baseCartesiean; if (locZ.IsParallel(Vector.ZAxis, angleTolerance) != 0) + { + baseCartesiean = new Cartesian(pLine.ControlPoints[0], -Vector.XAxis, locZ.CrossProduct(-Vector.XAxis), locZ); + } + else + { + Vector locY = (Vector.ZAxis - Vector.ZAxis.DotProduct(locZ) * locZ).Normalise(); + Vector locX = locY.CrossProduct(locZ); + baseCartesiean = new Cartesian(pLine.ControlPoints[0], locX, locY, locZ); + } + TransformMatrix locGlob1 = BH.Engine.Geometry.Create.OrientationMatrixLocalToGlobal(baseCartesiean); + Point minPtLocal = pLine.ControlPoints.Select(x => x.Transform(locGlob1)).ToList().Bounds().Min; + TransformMatrix globToLoc = BH.Engine.Geometry.Create.OrientationMatrixGlobalToLocal(baseCartesiean); + baseCartesiean.Origin = minPtLocal.Transform(globToLoc); return baseCartesiean; + } + } +} diff --git a/IES_Adapter/Query/Corner.cs b/IES_Adapter/Query/Corner.cs deleted file mode 100644 index 5b6c398..0000000 --- a/IES_Adapter/Query/Corner.cs +++ /dev/null @@ -1,41 +0,0 @@ -using BH.Engine.Environment; -using BH.oM.Environment.Elements; -using BH.oM.Geometry; -using BH.oM.Geometry.CoordinateSystem; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Adapter.IES -{ - public static partial class Query - { - public static Point LowerLeftCorner(this Panel panel) - { - var refPlane = panel.UpperOrientatedPlane(); - var pline = panel.Polyline(); - - var coords = pline.ControlPoints; - coords = coords.Select(x => x.XyzToXy(refPlane)).ToList(); - - var minX = coords.Min(pt => pt.X); - var minY = coords.Min(pt => pt.Y); - return new Point() { X = minX, Y = minY, Z=0 }.XyToXyz(refPlane); - } - - public static Point UpperRightCorner(this Panel panel) - { - var pline = panel.Polyline(); - var refPlane = panel.UpperOrientatedPlane(); - - var coords = pline.ControlPoints; - coords = coords.Select(x => x.XyzToXy(refPlane)).ToList(); - - var maxX = coords.Max(pt => pt.X); - var maxY = coords.Max(pt => pt.Y); - return new Point() { X = maxX, Y = maxY, Z = 0 }.XyToXyz(refPlane); - } - } -} diff --git a/IES_Adapter/Query/FitPlane2.cs b/IES_Adapter/Query/FitPlane2.cs deleted file mode 100644 index 4036c7e..0000000 --- a/IES_Adapter/Query/FitPlane2.cs +++ /dev/null @@ -1,86 +0,0 @@ -using BH.Engine.Geometry; -using BH.oM.Geometry; -using BH.oM.Geometry.CoordinateSystem; -using Microsoft.SqlServer.Server; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices.ComTypes; -using System.Security.Cryptography; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Adapter.IES -{ - public static partial class Query - { - public static Plane FitPlane2(this List verts) - { - verts.RemoveAt(verts.Count - 1); - var cprods = new List(); - var baseVert = verts[0]; - for (int x = 0; x < verts.Count - 2; x++) - { - cprods.Add(NormalFrom3Pts(baseVert, verts[x + 1], verts[x + 2])); - } - - var normal = new Vector() {X = 0, Y = 0, Z = 0}; - foreach (var cprodx in cprods) - { - normal.X += cprodx.X; - normal.Y += cprodx.Y; - normal.Z += cprodx.Z; - } - //normalise the vector - Vector normalVec = null; - - if ((normal.X != 0) || (normal.Y != 0) || (normal.Z != 0)) - { - var ds = Math.Sqrt(Math.Pow(normal.X, 2) + Math.Pow(normal.Y,2) + Math.Pow(normal.Z,2)); - normalVec = new Vector() - { - X = normal.X / ds, - Y = normal.Y / ds, - Z = normal.Z / ds - }; - } - else - { - normalVec = new Vector() - { - X = 0, - Y = 0, - Z = 1 - }; - } - return new Plane() - { - Origin = verts[0], - Normal = normalVec - }; - } - - public static Vector NormalFrom3Pts (this Point pt1, Point pt2, Point pt3) - { - var v1 = new Vector - { - X = pt2.X - pt1.X, - Y = pt2.Y - pt1.Y, - Z = pt2.Z - pt1.Z - }; - var v2 = new Vector - { - X = pt3.X - pt1.X, - Y = pt3.Y - pt1.Y, - Z = pt3.Z - pt1.Z - }; - - return new Vector - { - X = v1.Y * v2.Z - v1.Z * v2.Y, - Y = -v1.X * v2.Z + v1.Z * v2.X, - Z = v1.X * v2.Y - v1.Y * v2.X, - }; - } - } -} diff --git a/IES_Adapter/Query/FlipPlane.cs b/IES_Adapter/Query/FlipPlane.cs deleted file mode 100644 index 0e9bf64..0000000 --- a/IES_Adapter/Query/FlipPlane.cs +++ /dev/null @@ -1,25 +0,0 @@ -using BH.Engine.Geometry; -using BH.oM.Geometry; -using BH.oM.Geometry.CoordinateSystem; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Adapter.IES -{ - public static partial class Query - { - public static Cartesian FlipPlane(this Cartesian refPlane) - { - return new Cartesian( - refPlane.Origin, - refPlane.X, - -refPlane.Y, - -refPlane.Z - ); - } - - } -} diff --git a/IES_Adapter/Query/PolygonInFace.cs b/IES_Adapter/Query/PolygonInFace.cs deleted file mode 100644 index 2c89ff3..0000000 --- a/IES_Adapter/Query/PolygonInFace.cs +++ /dev/null @@ -1,56 +0,0 @@ -using BH.Engine.Environment; -using BH.Engine.Geometry; -using BH.oM.Environment.Elements; -using BH.oM.Geometry; -using BH.oM.Geometry.CoordinateSystem; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Adapter.IES -{ - public static partial class Query - { - public static Polyline PolygonInFace(this Opening opening, Panel hostPanel, Point origin = null, bool flip = false) - { - BH.oM.Geometry.CoordinateSystem.Cartesian coordinateSystem = hostPanel.UpperOrientatedPlane(); - //Plane plane = hostPanel.Polyline().ControlPoints.FitPlane2(); - - /*if (flip) - coordinateSystem = coordinateSystem.FlipPlane(); - - if(origin != null) - coordinateSystem.Origin = origin; - - TransformMatrix transformation = Engine.Geometry.Create.OrientationMatrix(coordinateSystem, new Cartesian()); - return Engine.Geometry.Create.Polyline(opening.Polyline().ControlPoints.Select(x => x.Transform(transformation)));*/ - - - /*if (origin == null && flip) - refPlane = refPlane.Flip();// = coordinateSystem.FlipPlane(); - else - {*/ - /*if (coordinateSystem.Z.IsParallel(Vector.ZAxis) != 0) //Parallel to Z - { - Vector localX = flip ? -Vector.XAxis : Vector.XAxis; - Vector localY = coordinateSystem.Z.CrossProduct(localX); - coordinateSystem = Engine.Geometry.Create.CartesianCoordinateSystem(origin, localX, localY); - } - else - { - var projY = Vector.ZAxis.Project(plane); - var projX = plane.Normal.CrossProduct(projY); - coordinateSystem = Engine.Geometry.Create.CartesianCoordinateSystem(plane.Origin, projX, projY); - } - //}*/ - - var vertices = opening.Polyline().ControlPoints; - var pts2D = vertices.Select(x => x.XyzToXy(coordinateSystem)).ToList(); - - return Engine.Geometry.Create.Polyline(pts2D); - } - } -} diff --git a/IES_Adapter/Query/Rotate2.cs b/IES_Adapter/Query/Rotate2.cs deleted file mode 100644 index 33f4d31..0000000 --- a/IES_Adapter/Query/Rotate2.cs +++ /dev/null @@ -1,33 +0,0 @@ -using BH.Engine.Geometry; -using BH.oM.Geometry; -using BH.oM.Geometry.CoordinateSystem; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Adapter.IES -{ - public static partial class Query - { - public static Vector Rotate2(this Vector vec, double angle, Vector axis) - { - var x = vec.X; var y = vec.Y; var z = vec.Z; - var u = axis.X; var v = axis.Y; var w = axis.Z; - //Extracted common factors for simplicity and efficiency - var r2 = Math.Pow(u,2) + Math.Pow(v,2) + Math.Pow(w, 2); - var r = Math.Sqrt(r2); - var ct = Math.Cos(angle); - var st = Math.Sin(angle) / r; - var dt = (u * x + v * y + w * z) * (1 - ct) / r2; - - return new Vector () - { - X = u * dt + x * ct + (-w * y + v * z) * st, - Y = v * dt + y * ct + (w * x - u * z) * st, - Z = w * dt + z * ct + (-v * x + u * y) * st, - }; - } - } -} diff --git a/IES_Adapter/Query/UpperOrientatedPlane.cs b/IES_Adapter/Query/UpperOrientatedPlane.cs deleted file mode 100644 index a449013..0000000 --- a/IES_Adapter/Query/UpperOrientatedPlane.cs +++ /dev/null @@ -1,44 +0,0 @@ -using BH.Engine.Environment; -using BH.Engine.Geometry; -using BH.oM.Environment.Elements; -using BH.oM.Geometry; -using BH.oM.Geometry.CoordinateSystem; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Adapter.IES -{ - public static partial class Query - { - public static Cartesian UpperOrientatedPlane(this Panel panel) - { - /* - var plane = panel.Polyline().ControlPoints.FitPlane2(); - - if (plane.Normal.Z == 1 || plane.Normal.Z == -1) - return new Cartesian(plane.Origin, Vector.XAxis, Vector.YAxis, Vector.ZAxis); - else - { - var projY = Vector.ZAxis.Project(plane); - var projX = projY.Rotate2(Math.PI / -2, plane.Normal); - return new Cartesian(plane.Origin, projX, Vector.YAxis, Vector.ZAxis); - }*/ - - var plane = panel.Polyline().ControlPoints.FitPlane2(); - - //if (plane.Normal.Z == 1 || plane.Normal.Z == -1) - if (plane.Normal.IsParallel(Vector.ZAxis) != 0) - return BH.Engine.Geometry.Create.CartesianCoordinateSystem(plane.Origin, Vector.XAxis, plane.Normal.CrossProduct(Vector.XAxis));// new Cartesian(plane.Origin, Vector.XAxis, Vector.YAxis, Vector.ZAxis); - else - { - - var projY = Vector.ZAxis.Project(plane); - var projX = plane.Normal.CrossProduct(projY); - return Engine.Geometry.Create.CartesianCoordinateSystem(plane.Origin, projX, projY); - } - } - } -} diff --git a/IES_Adapter/Query/XyzToXy.cs b/IES_Adapter/Query/XyzToXy.cs deleted file mode 100644 index 55cac16..0000000 --- a/IES_Adapter/Query/XyzToXy.cs +++ /dev/null @@ -1,61 +0,0 @@ -using BH.Engine.Geometry; -using BH.oM.Geometry; -using BH.oM.Geometry.CoordinateSystem; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Adapter.IES -{ - public static partial class Query - { - public static Point XyzToXy(this Point pt, Cartesian refPlane) - {/* - var diff = new Vector() - { - X = pt.X - refPlane.Origin.X, - Y = pt.Y - refPlane.Origin.Y, - Z = pt.Z - refPlane.Origin.Z, - }; - - return new Point() - { - X = refPlane.X.DotProduct(diff), - Y = refPlane.Y.DotProduct(diff), - Z = 0 - };*/ - TransformMatrix m = BH.Engine.Geometry.Create.OrientationMatrixLocalToGlobal(refPlane); - - return pt.Transform(m); - } - - public static Point XyToXyz(this Point pt, Cartesian refPlane) - { - /*var u = new Vector() - { - X = refPlane.X.X * pt.X, - Y = refPlane.X.Y * pt.X, - Z = refPlane.X.Z * pt.X, - }; - - var v = new Vector() - { - X = refPlane.Y.X * pt.Y, - Y = refPlane.Y.Y * pt.Y, - Z = refPlane.Y.Z * pt.Y, - }; - - return new Point() - { - X = refPlane.Origin.X + u.X + v.X, - Y = refPlane.Origin.Y + u.Y + v.Y, - Z = refPlane.Origin.Z + u.Z + v.Z, - };*/ - - TransformMatrix m = BH.Engine.Geometry.Create.OrientationMatrixGlobalToLocal(refPlane); - return pt.Transform(m); - } - } -} diff --git a/IES_Engine/Convert/Environment/Opening.cs b/IES_Engine/Convert/Environment/Opening.cs deleted file mode 100644 index cdfca3c..0000000 --- a/IES_Engine/Convert/Environment/Opening.cs +++ /dev/null @@ -1,156 +0,0 @@ -///* -// * 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 . -// */ - -//using System; -//using System.Collections.Generic; -//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; - -//using BH.oM.Geometry.CoordinateSystem; - -//namespace BH.Engine.Adapters.IES -//{ -// public static partial class Convert -// { - -// [Description("Convert a BHoM Environment Opening to an IES string representation of an opening for GEM format - this is for vertical openings (openings on walls)")] -// [Input("opening", "The BHoM Environment Opening to convert")] -// [Input("panelsAsSpace", "The panels representing a single space which hosts this opening, used to check the orientation of the opening")] -// [Input("settingsIES", "The IES settings to use with the IES adapter")] -// [Output("iesOpening", "The string representation for IES GEM format")] -// public static List ToIES(this Opening opening, Panel hostPanel, List panelsAsSpace, SettingsIES settingsIES) -// { -// List gemOpening = new List(); - -// Polyline openingCurve = opening.Polyline(); -// Polyline hostCurve = hostPanel.Polyline(); - -// if (hostCurve.ControlPoints.Select(x => x.Z).Max() == hostCurve.ControlPoints.Select(x => x.Z).Min()) -// return opening.ToIES(hostPanel, settingsIES); //Horizontal openings are handled slightly differently - -// Point panelBottomRightReference = hostPanel.BottomRight(panelsAsSpace); -// Point panelBottomLeftReference = hostPanel.BottomLeft(panelsAsSpace); -// Point panelTopRightReference = hostPanel.TopRight(panelsAsSpace); - -// Vector xVector = panelBottomLeftReference - panelBottomRightReference; -// xVector.Z = 0; -// Vector yVector = panelTopRightReference - panelBottomRightReference; - -// Point worldOrigin = new Point { X = 0, Y = 0, Z = 0 }; -// Cartesian worldCartesian = BH.Engine.Geometry.Create.CartesianCoordinateSystem(worldOrigin, Vector.XAxis, Vector.YAxis); -// Cartesian localCartesian = BH.Engine.Geometry.Create.CartesianCoordinateSystem(panelBottomRightReference, xVector, yVector); - -// Polyline hostTransformed = hostCurve.Orient(localCartesian, worldCartesian); -// Polyline openingTranslated = openingCurve.Orient(localCartesian, worldCartesian); - -// //If the orientation to 0,0,0 returns a negative X or Y point, translate the opening appropriately so that the bottom right reference would (if we wanted it) become 0,0,0 of the bounds of the host panel -// double minX = hostTransformed.ControlPoints.Select(x => x.X).Min(); -// double minY = hostTransformed.ControlPoints.Select(x => x.Y).Min(); -// if (minX < 0) -// { -// Vector translateVectorX = new Vector { X = -minX, Y = 0, Z = 0 }; -// openingTranslated = openingTranslated.Translate(translateVectorX); -// } -// if (minY < 0) -// { -// Vector translateVectorY = new Vector { X = 0, Y = -minY, Z = 0 }; -// openingTranslated = openingTranslated.Translate(translateVectorY); -// } - -// List vertices = openingTranslated.IDiscontinuityPoints(); -// gemOpening.Add(vertices.Count.ToString() + " " + opening.Type.ToIES(settingsIES) + "\n"); - -// foreach (Point p in vertices) -// gemOpening.Add(" " + Math.Abs(Math.Round(p.X, settingsIES.DecimalPlaces)).ToString() + " " + Math.Abs(Math.Round(p.Y, settingsIES.DecimalPlaces)).ToString() + "\n"); - -// return gemOpening; -// } - -// [Description("Convert a BHoM Environment Opening to an IES string representation of an opening for GEM format - this is for horizontal openings (openings on roofs and floors)")] -// [Input("opening", "The BHoM Environment Opening to convert")] -// [Input("settingsIES", "The IES settings to use with the IES adapter")] -// [Output("iesOpening", "The string representation for IES GEM format")] -// public static List ToIES(this Opening opening, Panel hostPanel, SettingsIES settingsIES) -// { -// List gemOpening = new List(); - -// Point zeroReference = null; -// BoundingBox bounds = hostPanel.Bounds(); -// Vector xVector = new Vector { X = -1, Y = 0, Z = 0 }; -// Vector yVector = new Vector { X = 0, Y = 1, Z = 0 }; - -// if (hostPanel.Type == PanelType.Floor || hostPanel.Type == PanelType.FloorExposed || hostPanel.Type == PanelType.FloorRaised) -// zeroReference = new Point { X = bounds.Max.X, Y = bounds.Min.Y, Z = bounds.Min.Z }; -// else -// { -// zeroReference = new Point { X = bounds.Max.X, Y = bounds.Max.Y, Z = bounds.Max.Z }; -// yVector.Y = -1; -// } - -// Polyline openingCurve = opening.Polyline(); - -// Point worldOrigin = new Point { X = 0, Y = 0, Z = 0 }; -// Cartesian worldCartesian = BH.Engine.Geometry.Create.CartesianCoordinateSystem(worldOrigin, Vector.XAxis, Vector.YAxis); -// Cartesian localCartesian = BH.Engine.Geometry.Create.CartesianCoordinateSystem(zeroReference, xVector, yVector); - -// Polyline openingTranslated = openingCurve.Orient(localCartesian, worldCartesian); - -// List vertices = openingTranslated.IDiscontinuityPoints(); -// gemOpening.Add(vertices.Count.ToString() + " " + opening.Type.ToIES(settingsIES) + "\n"); - -// foreach (Point p in vertices) -// gemOpening.Add(" " + Math.Abs(p.X).ToString() + " " + Math.Abs(p.Y).ToString() + "\n"); - -// return gemOpening; -// } - -// [Description("Convert an IES string representation of an opening to a BHoM Environment Opening")] -// [Input("openingPts", "The string representations of coordinates that make up the opening")] -// [Input("openingType", "The IES representation of the opening type")] -// [Input("settingsIES", "The IES settings to use with the IES adapter")] -// [Output("opening", "The BHoM Environment Opening converted from IES GEM format")] -// public static Opening FromIES(this List openingPts, string openingType, SettingsIES settingsIES) -// { -// List points = openingPts.Select(x => x.FromIES(settingsIES)).ToList(); -// points.Add(points.First()); - -// Polyline pLine = new Polyline { ControlPoints = points, }; - -// Opening opening = new Opening(); -// opening.Edges = pLine.ToEdges(); -// opening.Type = openingType.FromIESOpeningType(settingsIES); - -// return opening; -// } -// } -//} - - diff --git a/IES_Engine/Convert/Environment/OpeningType.cs b/IES_Engine/Convert/Environment/OpeningType.cs deleted file mode 100644 index 34bc18a..0000000 --- a/IES_Engine/Convert/Environment/OpeningType.cs +++ /dev/null @@ -1,357 +0,0 @@ -/* - * 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 . - */ - -using System; -using System.Collections.Generic; -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; -using BH.oM.Geometry.CoordinateSystem; - -namespace BH.Engine.Adapters.IES -{ - public static partial class Convert - { - public static List OpeningToIES(this Opening opening, Panel hostPanel) - { - var panelNormal = hostPanel.Polyline().ControlPoints.FitPlane2().Normal; - var origin = new Point(); - var flip = false; - - if (panelNormal.Z is (-1|1)) - { - origin = hostPanel.UpperRightCorner(); - flip = true; - } - /*else if (panelNormal.Angle()) - { - - }*/ - else - { - origin = hostPanel.LowerLeftCorner(); - flip = false; - } - - var verts_2d = opening.PolygonInFace(hostPanel,origin, flip); - - List fuckingHell = new List(); - - fuckingHell.Add($"{verts_2d.ControlPoints.Count} 0\n"); - - foreach (var hell in verts_2d.ControlPoints) - fuckingHell.Add($"{(hell.ToIES(new oM.IES.Settings.SettingsIES(), 2))}\n"); - - return fuckingHell; - } - - public static Point LowerLeftCorner(this Panel panel) - { - var pline = panel.Polyline(); - var refPlane = panel.UpperOrientatedPlane(); - - var coords = pline.ControlPoints; - coords = coords.Select(x => x.XyzToXy(refPlane)).ToList(); - - var minX = coords.Min(pt => pt.X); - var minY = coords.Min(pt => pt.Y); - return new Point() { X = minX, Y = minY, Z = 0 }.XyToXyz(refPlane); - } - - public static Point UpperRightCorner(this Panel panel) - { - var pline = panel.Polyline(); - var refPlane = panel.UpperOrientatedPlane(); - - var coords = pline.ControlPoints; - coords = coords.Select(x => x.XyzToXy(refPlane)).ToList(); - - var maxX = coords.Max(pt => pt.X); - var maxY = coords.Max(pt => pt.Y); - return new Point() { X = maxX, Y = maxY, Z = 0 }.XyToXyz(refPlane); - } - - public static Cartesian FlipPlane(this Cartesian refPlane) - { - return new Cartesian( - refPlane.Origin, - refPlane.X, - -refPlane.Y, - -refPlane.Z - ); - } - /* - public static Cartesian UpperOrientatedPlane(this Panel hostPanel) - { - Polyline boundary = hostPanel.Polyline(); - Plane plane = boundary.FitPlane(); - - Vector localX = (boundary.ControlPoints[1] - boundary.ControlPoints[0]).Normalise(); - - Vector localY = plane.Normal.CrossProduct(localX); - - return new Cartesian(plane.Origin, localX, localY, plane.Normal); - } - */ - public static Cartesian UpperOrientatedPlane(this Panel panel) - { - var plane = panel.Polyline().ControlPoints.FitPlane2(); - - //if (plane.Normal.Z == 1 || plane.Normal.Z == -1) - if (plane.Normal.IsParallel(Vector.ZAxis) != 0) - return BH.Engine.Geometry.Create.CartesianCoordinateSystem(plane.Origin, Vector.XAxis, plane.Normal.CrossProduct(Vector.XAxis));// new Cartesian(plane.Origin, Vector.XAxis, Vector.YAxis, Vector.ZAxis); - else - { - - var projY = Vector.ZAxis.Project(plane); - var projX = plane.Normal.CrossProduct(projY); - return Engine.Geometry.Create.CartesianCoordinateSystem(plane.Origin, projX, projY); - } - } - public static Plane FitPlane2(this List verts) - { - verts.RemoveAt(verts.Count - 1); - var cprods = new List(); - var baseVert = verts[0]; - for (int x = 0; x < verts.Count - 2; x++) - { - cprods.Add(NormalFrom3Pts(baseVert, verts[x + 1], verts[x + 2])); - } - - var normal = new Vector() { X = 0, Y = 0, Z = 0 }; - foreach (var cprodx in cprods) - { - normal.X += cprodx.X; - normal.Y += cprodx.Y; - normal.Z += cprodx.Z; - } - //normalise the vector - Vector normalVec = null; - - if ((normal.X != 0) || (normal.Y != 0) || (normal.Z != 0)) - { - var ds = Math.Sqrt(Math.Pow(normal.X, 2) + Math.Pow(normal.Y, 2) + Math.Pow(normal.Z, 2)); - normalVec = new Vector() - { - X = normal.X / ds, - Y = normal.Y / ds, - Z = normal.Z / ds - }; - } - else - { - normalVec = new Vector() - { - X = 0, - Y = 0, - Z = 1 - }; - } - return new Plane() - { - Origin = verts[0], - Normal = normalVec - }; - } - - public static Vector NormalFrom3Pts(this Point pt1, Point pt2, Point pt3) - { - var v1 = new Vector - { - X = pt2.X - pt1.X, - Y = pt2.Y - pt1.Y, - Z = pt2.Z - pt1.Z - }; - var v2 = new Vector - { - X = pt3.X - pt1.X, - Y = pt3.Y - pt1.Y, - Z = pt3.Z - pt1.Z - }; - - return new Vector - { - X = v1.Y * v2.Z - v1.Z * v2.Y, - Y = -v1.X * v2.Z + v1.Z * v2.X, - Z = v1.X * v2.Y - v1.Y * v2.X, - }; - } - - public static Vector Rotate2(this Vector vec, double angle, Vector axis) - { - var x = vec.X; var y = vec.Y; var z = vec.Z; - var u = axis.X; var v = axis.Y; var w = axis.Z; - //Extracted common factors for simplicity and efficiency - var r2 = Math.Pow(u, 2) + Math.Pow(v, 2) + Math.Pow(w, 2); - var r = Math.Sqrt(r2); - var ct = Math.Cos(angle); - var st = Math.Sin(angle) / r; - var dt = (u * x + v * y + w * z) * (1 - ct) / r2; - - return new Vector() - { - X = u * dt + x * ct + (-w * y + v * z) * st, - Y = v * dt + y * ct + (w * x - u * z) * st, - Z = w * dt + z * ct + (-v * x + u * y) * st, - }; - } - - - public static Polyline PolygonInFace(this Opening opening, Panel hostPanel, Point origin = null, bool flip = false) - { - BH.oM.Geometry.CoordinateSystem.Cartesian coordinateSystem = hostPanel.UpperOrientatedPlane(); - - /*if (flip) - coordinateSystem = coordinateSystem.FlipPlane(); - - if(origin != null) - coordinateSystem.Origin = origin; - - TransformMatrix transformation = Engine.Geometry.Create.OrientationMatrix(coordinateSystem, new Cartesian()); - return Engine.Geometry.Create.Polyline(opening.Polyline().ControlPoints.Select(x => x.Transform(transformation)));*/ - - - if (origin == null && flip) - coordinateSystem = coordinateSystem.FlipPlane(); - else - { - if (coordinateSystem.Z.IsParallel(Vector.ZAxis) != 0) //Parallel to Z - { - Vector localX = flip ? -Vector.XAxis : Vector.XAxis; - Vector localY = coordinateSystem.Z.CrossProduct(localX); - coordinateSystem = Engine.Geometry.Create.CartesianCoordinateSystem(origin, localX, localY); - } - else - { - Vector projY = Vector.ZAxis.Project(coordinateSystem.Z); - Vector projX = projY.Rotate(-Math.PI / 2, coordinateSystem.Z); - coordinateSystem = Engine.Geometry.Create.CartesianCoordinateSystem(origin, projX, projY); - } - } - - var vertices = opening.Polyline().ControlPoints; - var pts2D = vertices.Select(x => x.XyzToXy(coordinateSystem)).ToList(); - - return Engine.Geometry.Create.Polyline(pts2D); - } - - public static Point XyzToXy(this Point pt, Cartesian refPlane) - { - /*var diff = new Vector() - { - X = pt.X - refPlane.Origin.X, - Y = pt.Y - refPlane.Origin.Y, - Z = pt.Z - refPlane.Origin.Z, - }; - - return new Point() - { - X = refPlane.X.DotProduct(diff), - Y = refPlane.Y.DotProduct(diff), - Z = 0 - };*/ - - - TransformMatrix m = BH.Engine.Geometry.Create.OrientationMatrixLocalToGlobal(refPlane); - - return pt.Transform(m); - } - - public static Point XyToXyz(this Point pt, Cartesian refPlane) - { - /* var u = new Vector() - { - X = refPlane.X.X * pt.X, - Y = refPlane.X.Y * pt.X, - Z = refPlane.X.Z * pt.X, - }; - - var v = new Vector() - { - X = refPlane.Y.X * pt.Y, - Y = refPlane.Y.Y * pt.Y, - Z = refPlane.Y.Z * pt.Y, - }; - - return new Point() - { - X = refPlane.Origin.X + u.X + v.X, - Y = refPlane.Origin.Y + u.Y + v.Y, - Z = refPlane.Origin.Z + u.Z + v.Z, - };*/ - - TransformMatrix m = BH.Engine.Geometry.Create.OrientationMatrixGlobalToLocal(refPlane); - return pt.Transform(m); - } - - - [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) - { - case OpeningType.CurtainWall: - case OpeningType.Glazing: - case OpeningType.Rooflight: - case OpeningType.RooflightWithFrame: - case OpeningType.Window: - case OpeningType.WindowWithFrame: - return "0"; - case OpeningType.Door: - case OpeningType.VehicleDoor: - return "1"; - case OpeningType.Hole: - default: - return "2"; //Hole - } - } - - [Description("Convert an IES string representation of a Opening Type to a BHoM Opening Type")] - [Input("iesOpeningType", "The IES string representation of an opening type")] - [Input("settingsIES", "The IES settings to use with the IES adapter")] - [Output("openingType", "The BHoM Opening Type")] - public static OpeningType FromIESOpeningType(this string iesOpeningType, SettingsIES settingsIES) - { - if (iesOpeningType == "0") - return OpeningType.Window; - if (iesOpeningType == "1") - return OpeningType.Door; - if (iesOpeningType == "2") - return OpeningType.Hole; - - return OpeningType.Undefined; - } - } -} - - diff --git a/IES_Engine/Convert/Environment/Panel.cs b/IES_Engine/Convert/Environment/Panel.cs deleted file mode 100644 index cee3fcf..0000000 --- a/IES_Engine/Convert/Environment/Panel.cs +++ /dev/null @@ -1,182 +0,0 @@ -///* -// * 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 . -// */ - -//using System; -//using System.Collections.Generic; -//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 -//{ -// public static partial class Convert -// { -// [Description("Convert a collection of BHoM Environment Panels that represent shading elements into the IES string representation for GEM format")] -// [Input("panelsAsShade", "The collection of BHoM Environment Panels that represent shading elements")] -// [Input("settingsIES", "The IES settings to use with the IES adapter")] -// [Output("iesSpace", "The IES string representation of shade for GEM")] -// public static List ToIESShading(this List panelsAsShade, SettingsIES settingsIES) -// { -// List panels = panelsAsShade.Where(x => x.ExternalEdges.Count > 0).ToList(); - -// if (panels.Count != panelsAsShade.Count) -// BH.Engine.Base.Compute.RecordWarning("The panels for shading contain panels which did not contain geometry. Panels without valid geometry cannot be converted for IES to handle and have been ignored."); - -// List gemPanel = new List(); - -// 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"); -// gemPanel.Add("IES IES_SHD_" + (x + 1).ToString() + "\n"); - -// List points = panels[x].Vertices().Select(y => y.RoundCoordinates(settingsIES.DecimalPlaces)).ToList(); -// points = points.Distinct().ToList(); -// gemPanel.Add(points.Count.ToString() + " 1\n"); - -// string s = points.Count.ToString(); - -// 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"); -// else -// { -// gemPanel.Add(panels[x].Openings.Count.ToString() + "\n"); - -// foreach (Opening o in panels[x].Openings) -// gemPanel.AddRange(o.ToIES(panels[x], new List { panels[x] }, settingsIES)); -// } -// } - -// return gemPanel; -// } - -// [Description("Convert an IES string representation of a space into a collection of BHoM Environment Panels")] -// [Input("iesPanel", "The IES representation of a space.")] -// [Input("settingsIES", "The IES settings to use with the IES adapter")] -// [Output("panelsAsSpace", "BHoM Environment Space")] -// public static Panel FromIESShading(this List iesPanel, SettingsIES settingsIES, PanelType panelType) -// { -// Panel panel = new Panel(); - -// int numCoordinates = System.Convert.ToInt32(iesPanel[1].Split(' ')[0]); - -// List iesPoints = new List(); //Add the coordinate pts to a list -// for (int x = 0; x < numCoordinates; x++) -// iesPoints.Add(iesPanel[x + 2]); - -// List 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 panelCoord = iesPanel[count].Trim().Split(' ').ToList(); -// List pLinePts = new List(); -// 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, }; - -// panel.ExternalEdges = pLine.ToEdges(); -// panel.Type = panelType; -// panel.Openings = new List(); - -// //Add Openings -// count++; -// int numOpenings = System.Convert.ToInt32(iesPanel[count]); //Number of openings -// count++; -// int countOpenings = 0; -// while (countOpenings < numOpenings) -// { -// string openingData = iesPanel[count]; -// int numCoords = System.Convert.ToInt32(openingData.Split(' ')[0]); -// count++; - -// List openingPts = new List(); -// for (int x = 0; x < numCoords; x++) -// openingPts.Add(iesPanel[count + x]); - -// panel.Openings.Add(openingPts.FromIES(openingData.Split(' ')[1], settingsIES)); - -// count += numCoords; -// countOpenings++; -// } - -// 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 -// // IES traditionally defines openings with 2d coordinates. -// if (panel.Type != PanelType.TranslucentShade) -// { -// for (int x = 0; x < panel.Openings.Count; x++) -// { -// panel.Openings[x] = panel.Openings[x].RepairOpening(panel, new List { panel }); -// } -// } -// } -// else -// { -// panel.Openings = new List(); -// } - -// return panel; -// } -// } -//} - - diff --git a/IES_Engine/Convert/Environment/Point.cs b/IES_Engine/Convert/Environment/Point.cs deleted file mode 100644 index 650f045..0000000 --- a/IES_Engine/Convert/Environment/Point.cs +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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 . - */ - -using System; -using System.Collections.Generic; -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 -{ - public static partial class Convert - { - [Description("Convert a BHoM Geometry Point into an IES string representation for GEM files")] - [Input("pt", "BHoM Geometry Point to convert")] - [Input("settingsIES", "The IES settings to use with the IES adapter")] - [Output("iesPt", "The IES string representation of the point")] - public static string ToIES(this Point pt, SettingsIES settingsIES, int num = 3) - { - if (num == 3) - return " " + Math.Round(pt.X, settingsIES.DecimalPlaces).ToString() + " " + Math.Round(pt.Y, settingsIES.DecimalPlaces).ToString() + " " + Math.Round(pt.Z, settingsIES.DecimalPlaces).ToString() + "\n"; - else - return " " + Math.Round(pt.X, settingsIES.DecimalPlaces).ToString() + " " + Math.Round(pt.Y, settingsIES.DecimalPlaces).ToString() + "\n"; - } - - [Description("Convert an IES point representation to a BHoM point")] - [Input("iesPt", "The IES string representation of a point to convert")] - [Input("settingsIES", "The IES settings to use with the IES adapter")] - [Output("point", "A BHoM Geometry Point")] - public static Point FromIES(this string iesPt, SettingsIES settingsIES) - { - try - { - iesPt = iesPt.Trim(); - string[] split = System.Text.RegularExpressions.Regex.Split(iesPt, @"\s+"); - return new Point - { - X = System.Convert.ToDouble(split[0]), - Y = System.Convert.ToDouble(split[1]), - Z = (split.Length > 2 ? System.Convert.ToDouble(split[2]) : 0), - }; - } - catch (Exception e) - { - BH.Engine.Base.Compute.RecordError("An error occurred in parsing that IES string to a BHoM point. Error was: " + e.ToString()); - return null; - } - } - } -} - - diff --git a/IES_Engine/IES_Engine.csproj b/IES_Engine/IES_Engine.csproj index 2d0f312..2eb4dca 100644 --- a/IES_Engine/IES_Engine.csproj +++ b/IES_Engine/IES_Engine.csproj @@ -85,13 +85,7 @@ - - - - - - diff --git a/IES_Engine/Modify/RepairOpening.cs b/IES_Engine/Modify/RepairOpening.cs deleted file mode 100644 index 55f7764..0000000 --- a/IES_Engine/Modify/RepairOpening.cs +++ /dev/null @@ -1,144 +0,0 @@ -/* - * 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 . - */ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -using BH.oM.Geometry; -using BH.oM.Environment.Elements; - -using BH.Engine.Environment; -using BH.Engine.Geometry; - -using System.ComponentModel; -using BH.oM.Base.Attributes; - -using BH.oM.Geometry.CoordinateSystem; - -using BH.Engine.Base; - -namespace BH.Engine.Adapters.IES -{ - public static partial class Modify - { - [Description("The openings when converted from IES do not have the right coordinates for 3D space, this method will repair them.")] - [Input("opening", "The broken environment opening pulled from IES.")] - [Input("host", "The host panel for the opening.")] - [Input("panelsAsSpace", "A collection of panels defining the space around the opening.")] - [Output("repairedOpening", "The repaired environment opening.")] - public static Opening RepairOpening(this Opening opening, Panel host, List panelsAsSpace) - { - Polyline openingCurve = opening.Polyline(); - Polyline hostCurve = host.Polyline(); - - if (hostCurve.ControlPoints.Select(x => x.Z).Max() == hostCurve.ControlPoints.Select(x => x.Z).Min()) - { - //Horizontal openings are handled slightly differently - if (panelsAsSpace.Select(x => x.Polyline().ControlPoints.Select(y => y.Z).Max()).Max() == hostCurve.ControlPoints.Select(x => x.Z).Max()) - return opening.RepairOpening(host, PanelType.Roof); //If the maximum Z level of the space is equal to the Z level of this panel - else - return opening.RepairOpening(host, PanelType.Floor); - } - - Point panelBottomRightReference = host.BottomRight(panelsAsSpace); - Point panelBottomLeftReference = host.BottomLeft(panelsAsSpace); - Point panelTopRightReference = host.TopRight(panelsAsSpace); - - if(panelBottomRightReference == null || panelBottomLeftReference == null || panelTopRightReference == null) - { - BH.Engine.Base.Compute.RecordWarning("An error occurred in attempting to repair opening with GUID " + opening.BHoM_Guid + " hosted by the panel with GUID " + host.BHoM_Guid + " . The opening on this panel may not be correctly pulled and should be investigated."); - return opening; - } - - Vector xVector = panelBottomLeftReference - panelBottomRightReference; - xVector.Z = 0; - Vector yVector = panelTopRightReference - panelBottomRightReference; - - Point worldOrigin = new Point { X = 0, Y = 0, Z = 0 }; - Cartesian worldCartesian = BH.Engine.Geometry.Create.CartesianCoordinateSystem(worldOrigin, Vector.XAxis, Vector.YAxis); - Cartesian localCartesian = BH.Engine.Geometry.Create.CartesianCoordinateSystem(panelBottomRightReference, xVector, yVector); - - Polyline hostTransformed = hostCurve.Orient(localCartesian, worldCartesian); - Polyline openingTranslated = openingCurve.DeepClone(); - - //If the orientation to 0,0,0 returns a negative X or Y point, translate the opening appropriately so that the bottom right reference would (if we wanted it) become 0,0,0 of the bounds of the host panel - double minX = hostTransformed.ControlPoints.Select(x => x.X).Min(); - double minY = hostTransformed.ControlPoints.Select(x => x.Y).Min(); - if (minX < 0) - { - Vector translateVectorX = new Vector { X = minX, Y = 0, Z = 0 }; - openingTranslated = openingTranslated.Translate(translateVectorX); - } - if(minY < 0) - { - Vector translateVectorY = new Vector { X = 0, Y = minY, Z = 0 }; - openingTranslated = openingTranslated.Translate(translateVectorY); - } - - Polyline openingTransformed = openingTranslated.Orient(worldCartesian, localCartesian); - - Opening newOpening = opening.ShallowClone(); - newOpening.Edges = openingTransformed.ToEdges(); - - return newOpening; - } - - [Description("The openings when converted from IES do not have the right coordinates for 3D space, this method will repair them. This method is for horizontal openings (openings on roofs and floors)")] - [Input("opening", "The broken environment opening pulled from IES.")] - [Input("hostPanel", "The host panel for the opening.")] - [Input("hostType", "Determines whether the host panel is the floor of the space it is part of, or the ceiling.")] - [Output("repairedOpening", "The repaired environment opening.")] - public static Opening RepairOpening(this Opening opening, Panel hostPanel, PanelType hostType) - { - Point zeroReference = null; - BoundingBox bounds = hostPanel.Bounds(); - Vector xVector = new Vector { X = -1, Y = 0, Z = 0 }; - Vector yVector = new Vector { X = 0, Y = 1, Z = 0 }; - - if (hostType == PanelType.Floor || hostType == PanelType.FloorExposed || hostType == PanelType.FloorRaised) - zeroReference = new Point { X = bounds.Max.X, Y = bounds.Min.Y, Z = bounds.Min.Z }; - else - { - zeroReference = new Point { X = bounds.Max.X, Y = bounds.Max.Y, Z = bounds.Max.Z }; - yVector.Y = -1; - } - - Polyline openingCurve = opening.Polyline(); - - Point worldOrigin = new Point { X = 0, Y = 0, Z = 0 }; - Cartesian worldCartesian = BH.Engine.Geometry.Create.CartesianCoordinateSystem(worldOrigin, Vector.XAxis, Vector.YAxis); - Cartesian localCartesian = BH.Engine.Geometry.Create.CartesianCoordinateSystem(zeroReference, xVector, yVector); - - Polyline openingTranslated = openingCurve.Orient(worldCartesian, localCartesian); - - Opening newOpening = opening.ShallowClone(); - newOpening.Edges = openingTranslated.ToEdges(); - - return newOpening; - } - } -} - - diff --git a/IES_Engine/Query/Polyline.cs b/IES_Engine/Query/Polyline.cs deleted file mode 100644 index ae687d5..0000000 --- a/IES_Engine/Query/Polyline.cs +++ /dev/null @@ -1,131 +0,0 @@ -/* - * 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 . - */ - -using BH.oM.Geometry; -using System; -using System.Collections.Generic; -using System.Linq; - -using BH.oM.Base.Attributes; -using System.ComponentModel; -using BH.Engine.Geometry; - -namespace BH.Engine.Adapters.IES -{ - public static partial class Query - { - /***************************************************/ - /**** Public Methods - Bounding Box ****/ - /***************************************************/ - - [Description("Get a 2d polyline representation of a BHoM BoundingBox")] - [Input("box", "The BHoM bounding box")] - [Output("polyline", "The 2d polyline representation of the box")] - public static Polyline Polyline(this BoundingBox box) - { - Point min = box.Min.RoundCoordinates(); - Point max = box.Max.RoundCoordinates(); - - double minDist = Math.Min(max.X - min.X, max.Y - min.Y); - minDist = Math.Min(minDist, max.Z - min.Z); - - List pnts = new List(); - pnts.Add(min); - - if((max.X - min.X) == minDist || (max.Z - min.Z) == minDist) - { - //YZ plane - double x1 = min.Z; - double x2 = max.Z; - double y1 = min.Y; - double y2 = max.Y; - - double xc = (x1 + x2) / 2; - double xd = (x1 - x2) / 2; - - double yc = (y1 + y2) / 2; - double yd = (y1 - y2) / 2; - - double x3 = xc - yd; - double x4 = xc + yd; - double y3 = yc + xd; - double y4 = yc - xd; - - pnts.Add(new Point { X = min.X, Y = y3, Z = x3 }); - pnts.Add(max); - pnts.Add(new Point { X = max.X, Y = y4, Z = x4 }); - } - else if ((max.Y - min.Y) == minDist) - { - //XZ - double x1 = min.X; - double x2 = max.X; - double y1 = min.Z; - double y2 = max.Z; - - double xc = (x1 + x2) / 2; - double xd = (x1 - x2) / 2; - - double yc = (y1 + y2) / 2; - double yd = (y1 - y2) / 2; - - double x3 = xc - yd; - double x4 = xc + yd; - double y3 = yc + xd; - double y4 = yc - xd; - - pnts.Add(new Point { X = x3, Y = min.Y, Z = y3 }); - pnts.Add(max); - pnts.Add(new Point { X = x4, Y = max.Y, Z = y4 }); - } - else - { - double x1 = min.X; - double x2 = max.X; - double y1 = min.Y; - double y2 = max.Y; - - double xc = (x1 + x2) / 2; - double xd = (x1 - x2) / 2; - - double yc = (y1 + y2) / 2; - double yd = (y1 - y2) / 2; - - double x3 = xc - yd; - double x4 = xc + yd; - double y3 = yc + xd; - double y4 = yc - xd; - - pnts.Add(new Point { X = x3, Y = y3, Z = min.Z }); - pnts.Add(max); - pnts.Add(new Point { X = x4, Y = y4, Z = max.Z }); - } - - pnts.Add(min); - - return new Polyline { ControlPoints = pnts }; - } - } -} - - - From 8a8903f895179a4d15531ffbc4dbf3eb723cc824 Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Tue, 31 Jan 2023 10:17:25 +0000 Subject: [PATCH 11/27] Add copyright headers to new files --- IES_Adapter/Convert/Environment/Opening.cs | 24 ++++++++++++++++++- .../Convert/Environment/OpeningType.cs | 24 ++++++++++++++++++- IES_Adapter/Convert/Environment/Space.cs | 24 ++++++++++++++++++- IES_Adapter/Convert/Objects/GEMTemplate.cs | 24 ++++++++++++++++++- IES_Adapter/Create/ShadeTemplate.cs | 24 ++++++++++++++++++- IES_Adapter/Create/SpaceTemplate.cs | 24 ++++++++++++++++++- IES_Adapter/Objects/GEMTemplate.cs | 24 ++++++++++++++++++- IES_Adapter/Query/CoordinateSystem.cs | 24 ++++++++++++++++++- 8 files changed, 184 insertions(+), 8 deletions(-) diff --git a/IES_Adapter/Convert/Environment/Opening.cs b/IES_Adapter/Convert/Environment/Opening.cs index 8d808b6..3f69c69 100644 --- a/IES_Adapter/Convert/Environment/Opening.cs +++ b/IES_Adapter/Convert/Environment/Opening.cs @@ -1,4 +1,26 @@ -using System; +/* + * 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 . + */ + +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/IES_Adapter/Convert/Environment/OpeningType.cs b/IES_Adapter/Convert/Environment/OpeningType.cs index 338299f..8c2cb82 100644 --- a/IES_Adapter/Convert/Environment/OpeningType.cs +++ b/IES_Adapter/Convert/Environment/OpeningType.cs @@ -1,4 +1,26 @@ -using BH.oM.Base.Attributes; +/* + * 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 . + */ + +using BH.oM.Base.Attributes; using BH.oM.IES.Settings; using System; using System.Collections.Generic; diff --git a/IES_Adapter/Convert/Environment/Space.cs b/IES_Adapter/Convert/Environment/Space.cs index 81f8b44..402886a 100644 --- a/IES_Adapter/Convert/Environment/Space.cs +++ b/IES_Adapter/Convert/Environment/Space.cs @@ -1,4 +1,26 @@ -using BH.oM.Base.Attributes; +/* + * 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 . + */ + +using BH.oM.Base.Attributes; using BH.oM.Environment.Elements; using BH.oM.Geometry; using BH.oM.IES.Fragments; diff --git a/IES_Adapter/Convert/Objects/GEMTemplate.cs b/IES_Adapter/Convert/Objects/GEMTemplate.cs index 1cd9f67..e8e08af 100644 --- a/IES_Adapter/Convert/Objects/GEMTemplate.cs +++ b/IES_Adapter/Convert/Objects/GEMTemplate.cs @@ -1,4 +1,26 @@ -using System; +/* + * 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 . + */ + +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/IES_Adapter/Create/ShadeTemplate.cs b/IES_Adapter/Create/ShadeTemplate.cs index 493c2b0..cecddcd 100644 --- a/IES_Adapter/Create/ShadeTemplate.cs +++ b/IES_Adapter/Create/ShadeTemplate.cs @@ -1,4 +1,26 @@ -using System; +/* + * 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 . + */ + +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/IES_Adapter/Create/SpaceTemplate.cs b/IES_Adapter/Create/SpaceTemplate.cs index 81caf23..01a2303 100644 --- a/IES_Adapter/Create/SpaceTemplate.cs +++ b/IES_Adapter/Create/SpaceTemplate.cs @@ -1,4 +1,26 @@ -using System; +/* + * 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 . + */ + +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/IES_Adapter/Objects/GEMTemplate.cs b/IES_Adapter/Objects/GEMTemplate.cs index d37311b..f350a86 100644 --- a/IES_Adapter/Objects/GEMTemplate.cs +++ b/IES_Adapter/Objects/GEMTemplate.cs @@ -1,4 +1,26 @@ -using System; +/* + * 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 . + */ + +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/IES_Adapter/Query/CoordinateSystem.cs b/IES_Adapter/Query/CoordinateSystem.cs index abffbe7..6b3a198 100644 --- a/IES_Adapter/Query/CoordinateSystem.cs +++ b/IES_Adapter/Query/CoordinateSystem.cs @@ -1,4 +1,26 @@ -using BH.oM.Geometry.CoordinateSystem; +/* + * 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 . + */ + +using BH.oM.Geometry.CoordinateSystem; using BH.oM.Geometry; using System; using System.Collections.Generic; From fc14de908d8ecf0e1014fba6eacccaf66d3505ab Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Tue, 31 Jan 2023 10:19:41 +0000 Subject: [PATCH 12/27] Update formatting --- IES_Adapter/Query/CoordinateSystem.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/IES_Adapter/Query/CoordinateSystem.cs b/IES_Adapter/Query/CoordinateSystem.cs index 6b3a198..202e42c 100644 --- a/IES_Adapter/Query/CoordinateSystem.cs +++ b/IES_Adapter/Query/CoordinateSystem.cs @@ -36,20 +36,25 @@ public static partial class Query { public static Cartesian CoordinateSystem(this Polyline pLine, double distanceTolerance = Tolerance.MacroDistance, double angleTolerance = Tolerance.Angle) { - Vector locZ = pLine.Normal(distanceTolerance); Cartesian baseCartesiean; if (locZ.IsParallel(Vector.ZAxis, angleTolerance) != 0) - { + Vector locZ = pLine.Normal(distanceTolerance); + + Cartesian baseCartesiean; + + if (locZ.IsParallel(Vector.ZAxis, angleTolerance) != 0) baseCartesiean = new Cartesian(pLine.ControlPoints[0], -Vector.XAxis, locZ.CrossProduct(-Vector.XAxis), locZ); - } else { Vector locY = (Vector.ZAxis - Vector.ZAxis.DotProduct(locZ) * locZ).Normalise(); Vector locX = locY.CrossProduct(locZ); baseCartesiean = new Cartesian(pLine.ControlPoints[0], locX, locY, locZ); } + TransformMatrix locGlob1 = BH.Engine.Geometry.Create.OrientationMatrixLocalToGlobal(baseCartesiean); Point minPtLocal = pLine.ControlPoints.Select(x => x.Transform(locGlob1)).ToList().Bounds().Min; TransformMatrix globToLoc = BH.Engine.Geometry.Create.OrientationMatrixGlobalToLocal(baseCartesiean); - baseCartesiean.Origin = minPtLocal.Transform(globToLoc); return baseCartesiean; + baseCartesiean.Origin = minPtLocal.Transform(globToLoc); + + return baseCartesiean; } } } From 29fbc56abb2005693d5291747704e877dd0aa64c Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Tue, 31 Jan 2023 10:25:31 +0000 Subject: [PATCH 13/27] Make use of templates for Space and Shade --- IES_Adapter/Convert/Environment/Panel.cs | 25 ++++++------------------ IES_Adapter/Convert/Environment/Space.cs | 24 ++--------------------- 2 files changed, 8 insertions(+), 41 deletions(-) diff --git a/IES_Adapter/Convert/Environment/Panel.cs b/IES_Adapter/Convert/Environment/Panel.cs index 48eb515..7f278a2 100644 --- a/IES_Adapter/Convert/Environment/Panel.cs +++ b/IES_Adapter/Convert/Environment/Panel.cs @@ -53,25 +53,12 @@ public static List ToIESShading(this List 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 points = panels[x].Vertices().Select(y => y.RoundCoordinates(settingsIES.DecimalPlaces)).ToList(); diff --git a/IES_Adapter/Convert/Environment/Space.cs b/IES_Adapter/Convert/Environment/Space.cs index 402886a..126f0c6 100644 --- a/IES_Adapter/Convert/Environment/Space.cs +++ b/IES_Adapter/Convert/Environment/Space.cs @@ -60,30 +60,10 @@ public static List ToIES(this List panelsAsSpace, SettingsIES set List gemSpace = new List(); - gemSpace.Add("LAYER\n"); - gemSpace.Add("1\n"); - gemSpace.Add("COLOUR\n"); - gemSpace.Add("1\n"); - gemSpace.Add("CATEGORY\n"); - gemSpace.Add("1\n"); - if (panels.First().IsShade()) - { - gemSpace.Add("TYPE\n"); - gemSpace.Add("4\n"); - gemSpace.Add("SUBTYPE\n"); - gemSpace.Add("0\n"); - } + gemSpace.AddRange(Create.ShadeTemplate().ToIES()); else - { - gemSpace.Add("TYPE\n"); - gemSpace.Add("1\n"); - gemSpace.Add("SUBTYPE\n"); - gemSpace.Add("2001\n"); - } - - gemSpace.Add("COLOURRGB\n"); - gemSpace.Add("16711690\n"); + gemSpace.AddRange(Create.SpaceTemplate().ToIES()); gemSpace.Add("IES " + panels.ConnectedSpaceName() + "\n"); From 534a808d8a4753a9b86c0c34aa2e2af952fc45f9 Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Tue, 31 Jan 2023 10:43:46 +0000 Subject: [PATCH 14/27] Include some versioning for the deleted methods --- IES_Engine/Versioning_61.json | 50 +++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 IES_Engine/Versioning_61.json diff --git a/IES_Engine/Versioning_61.json b/IES_Engine/Versioning_61.json new file mode 100644 index 0000000..18ef4f0 --- /dev/null +++ b/IES_Engine/Versioning_61.json @@ -0,0 +1,50 @@ +{ + "Namespace": { + "ToNew": { + }, + "ToOld": { + } + }, + "Type": { + "ToNew": { + + }, + "ToOld": { + + } + }, + "Method": { + "ToNew": { + + }, + "ToOld": { + } + }, + "Property": { + "ToNew": { + + }, + "ToOld": { + + } + }, + "MessageForDeleted": { + "BH.Engine.Adapters.IES.Convert.ToIES(BH.oM.Geometry.Point, BH.oM.IES.Settings.SettingsIES)" : "This method has been moved into the adapter to be handled internally and prevent UI clutter of methods. If this method is needed for script work independently of the adapter, please raise an issue at: https://github.com/BHoM/IES_Toolkit", + "BH.Engine.Adapters.IES.Convert.ToIES(System.Collections.Generic.List, BH.oM.IES.Settings.SettingsIES)" : "This method has been moved into the adapter to be handled internally and prevent UI clutter of methods. If this method is needed for script work independently of the adapter, please raise an issue at: https://github.com/BHoM/IES_Toolkit", + "BH.Engine.Adapters.IES.Convert.ToIES(BH.oM.Environment.Elements.OpeningType, BH.oM.IES.Settings.SettingsIES)" : "This method has been moved into the adapter to be handled internally and prevent UI clutter of methods. If this method is needed for script work independently of the adapter, please raise an issue at: https://github.com/BHoM/IES_Toolkit", + "BH.Engine.Adapters.IES.Convert.ToIES(BH.oM.Environment.Elements.Opening, BH.oM.Environment.Elements.Panel, BH.oM.IES.Settings.SettingsIES)" : "This method has been moved into the adapter to be handled internally and prevent UI clutter of methods. If this method is needed for script work independently of the adapter, please raise an issue at: https://github.com/BHoM/IES_Toolkit", + "BH.Engine.Adapters.IES.Convert.ToIES(BH.oM.Environment.Elements.Opening, BH.oM.Environment.Elements.Panel, System.Collections.Generic.List, BH.oM.IES.Settings.SettingsIES)" : "This method has been moved into the adapter to be handled internally and prevent UI clutter of methods. If this method is needed for script work independently of the adapter, please raise an issue at: https://github.com/BHoM/IES_Toolkit", + "BH.Engine.Adapters.IES.Convert.FromIES(System.String, BH.oM.IES.Settings.SettingsIES)" : "This method has been moved into the adapter to be handled internally and prevent UI clutter of methods. If this method is needed for script work independently of the adapter, please raise an issue at: https://github.com/BHoM/IES_Toolkit", + "BH.Engine.Adapters.IES.Convert.FromIES(System.Collections.Generic.List, BH.oM.IES.Settings.SettingsIES)" : "This method has been moved into the adapter to be handled internally and prevent UI clutter of methods. If this method is needed for script work independently of the adapter, please raise an issue at: https://github.com/BHoM/IES_Toolkit", + "BH.Engine.Adapters.IES.Convert.FromIES(System.Collections.Generic.List, System.String, BH.oM.IES.Settings.SettingsIES)" : "This method has been moved into the adapter to be handled internally and prevent UI clutter of methods. If this method is needed for script work independently of the adapter, please raise an issue at: https://github.com/BHoM/IES_Toolkit", + "BH.Engine.Adapters.IES.Convert.FromIESOpeningType(System.String, BH.oM.IES.Settings.SettingsIES)" : "This method has been moved into the adapter to be handled internally and prevent UI clutter of methods. If this method is needed for script work independently of the adapter, please raise an issue at: https://github.com/BHoM/IES_Toolkit", + "BH.Engine.Adapters.IES.Convert.FromIESShading(System.Collections.Generic.List, BH.oM.IES.Settings.SettingsIES, BH.oM.Environment.Elements.PanelType)" : "This method has been moved into the adapter to be handled internally and prevent UI clutter of methods. If this method is needed for script work independently of the adapter, please raise an issue at: https://github.com/BHoM/IES_Toolkit", + "BH.Engine.Adapters.IES.Convert.ToIESShading(System.Collections.Generic.List, BH.oM.IES.Settings.SettingsIES)" : "This method has been moved into the adapter to be handled internally and prevent UI clutter of methods. If this method is needed for script work independently of the adapter, please raise an issue at: https://github.com/BHoM/IES_Toolkit", + "BH.Engine.Adapters.IES.Query.Polyline(BH.oM.Geometry.BoundingBox)" : "This method has been moved into the adapter to be handled internally and prevent UI clutter of methods. If this method is needed for script work independently of the adapter, please raise an issue at: https://github.com/BHoM/IES_Toolkit", + "BH.Engine.Adapters.IES.Modify.RepairOpening(BH.oM.Environment.Elements.Opening, BH.oM.Environment.Elements.Panel, BH.oM.Environment.Elements.PanelType)" : "This method has been moved into the adapter to be handled internally and prevent UI clutter of methods. If this method is needed for script work independently of the adapter, please raise an issue at: https://github.com/BHoM/IES_Toolkit", + "BH.Engine.Adapters.IES.Modify.RepairOpening(BH.oM.Environment.Elements.Opening, BH.oM.Environment.Elements.Panel, System.Collections.Generic.List)" : "This method has been moved into the adapter to be handled internally and prevent UI clutter of methods. If this method is needed for script work independently of the adapter, please raise an issue at: https://github.com/BHoM/IES_Toolkit", + }, + "MessageForNoUpgrade": { + + } +} \ No newline at end of file From 61a7a3dadf79ae9093064f2a95f68bb5fd555574 Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Wed, 1 Feb 2023 15:08:01 +0000 Subject: [PATCH 15/27] Fix normal away from space check --- IES_Adapter/Convert/Environment/Space.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/IES_Adapter/Convert/Environment/Space.cs b/IES_Adapter/Convert/Environment/Space.cs index 126f0c6..fa9f81a 100644 --- a/IES_Adapter/Convert/Environment/Space.cs +++ b/IES_Adapter/Convert/Environment/Space.cs @@ -85,12 +85,12 @@ public static List ToIES(this List panelsAsSpace, SettingsIES set if (p.Type == PanelType.Air && p.Openings.Count == 0) p.Openings.Add(new Opening { Edges = new List(p.ExternalEdges), Type = OpeningType.Hole }); //Air walls need the polyline adding as an opening of type hole + if(!p.NormalAwayFromSpace(panels, settingsIES.PlanarTolerance)) + p.ExternalEdges = p.Polyline().Flip().ToEdges(); //Reverse the point order if the normal is not away from the space but the first adjacency is this space + List v = p.Vertices(); v.RemoveAt(v.Count - 1); //Remove the last point because we don't need duplicated points - if (!p.NormalAwayFromSpace(panels, settingsIES.PlanarTolerance)) - v.Reverse(); //Reverse the point order if the normal is not away from the space but the first adjacency is this space - string s = v.Count.ToString() + " "; foreach (Point pt in v) s += (spaceVertices.IndexOf(pt.RoundCoordinates(settingsIES.DecimalPlaces)) + 1) + " "; From 4a50a6d74ec2421ff6a0409ccc127d2934e1a68a Mon Sep 17 00:00:00 2001 From: Karolina Prusicka Date: Thu, 2 Feb 2023 17:40:19 +0000 Subject: [PATCH 16/27] Adding pull --- IES_Adapter/Convert/Environment/Opening.cs | 18 ++++++++++++++++++ IES_Adapter/Convert/Environment/Space.cs | 19 +------------------ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/IES_Adapter/Convert/Environment/Opening.cs b/IES_Adapter/Convert/Environment/Opening.cs index 3f69c69..d8507fc 100644 --- a/IES_Adapter/Convert/Environment/Opening.cs +++ b/IES_Adapter/Convert/Environment/Opening.cs @@ -51,5 +51,23 @@ public static List ToIES(this Opening opening, Panel hostPanel, Settings return rtn; } + public static Opening FromIESOpening(this List openingIES, string openingType, SettingsIES settingsIES ) + { + + var polyline = new Polyline(); + + foreach (var iesPt in openingIES) + polyline.ControlPoints.Add(iesPt.FromIES(settingsIES)); + + var coordSystem = polyline.CoordinateSystem(); + var globalToLocal = BH.Engine.Geometry.Create.OrientationMatrixLocalToGlobal(coordSystem); + + Opening opening = new Opening(); + + opening.Edges = polyline.Transform(globalToLocal).ToEdges(); + opening.Type = openingType.FromIESOpeningType(settingsIES); + + return opening; + } } } diff --git a/IES_Adapter/Convert/Environment/Space.cs b/IES_Adapter/Convert/Environment/Space.cs index fa9f81a..5e4ff3c 100644 --- a/IES_Adapter/Convert/Environment/Space.cs +++ b/IES_Adapter/Convert/Environment/Space.cs @@ -176,7 +176,7 @@ public static List FromIES(this List iesSpace, SettingsIES settin for (int x = 0; x < numCoords; x++) openingPts.Add(iesSpace[count + x]); - //panel.Openings.Add(openingPts.FromIES(openingData.Split(' ')[1], settingsIES)); + panel.Openings.Add(openingPts.FromIESOpening(openingData.Split(' ')[1], settingsIES)); count += numCoords; countOpenings++; @@ -185,23 +185,6 @@ public static List FromIES(this List iesSpace, SettingsIES settin panels.Add(panel); } - /*if (settingsIES.PullOpenings) - { - //Fix the openings now - foreach (Panel p in panels) - { - for (int x = 0; x < p.Openings.Count; x++) - { - p.Openings[x] = p.Openings[x].RepairOpening(p, panels); - } - } - } - else - { - foreach (Panel p in panels) - p.Openings = new List(); - }*/ - return panels; } } From 01b97c2459c55ec5eea223581e2cd42aec7deadf Mon Sep 17 00:00:00 2001 From: Karolina Prusicka Date: Fri, 3 Feb 2023 12:47:30 +0000 Subject: [PATCH 17/27] Adding pull tolerances --- IES_Adapter/Convert/Environment/Opening.cs | 12 +++++++----- IES_Adapter/Convert/Environment/Space.cs | 3 ++- IES_oM/SettingsIES.cs | 5 +++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/IES_Adapter/Convert/Environment/Opening.cs b/IES_Adapter/Convert/Environment/Opening.cs index d8507fc..bfa17c3 100644 --- a/IES_Adapter/Convert/Environment/Opening.cs +++ b/IES_Adapter/Convert/Environment/Opening.cs @@ -39,7 +39,7 @@ public static List ToIES(this Opening opening, Panel hostPanel, Settings { List rtn = new List(); - var coordSystem = hostPanel.Polyline().CoordinateSystem(); + var coordSystem = hostPanel.Polyline().CoordinateSystem(settingsIES.DistanceTolerance, settingsIES.AngleTolerance); var localToGlobal = BH.Engine.Geometry.Create.OrientationMatrixLocalToGlobal(coordSystem); var polyline = opening.Polyline().Transform(localToGlobal); @@ -51,16 +51,18 @@ public static List ToIES(this Opening opening, Panel hostPanel, Settings return rtn; } - public static Opening FromIESOpening(this List openingIES, string openingType, SettingsIES settingsIES ) + public static Opening FromIESOpening(this List openingPts, string openingType, Polyline hostPanel, SettingsIES settingsIES ) { var polyline = new Polyline(); - foreach (var iesPt in openingIES) + foreach (var iesPt in openingPts) polyline.ControlPoints.Add(iesPt.FromIES(settingsIES)); - var coordSystem = polyline.CoordinateSystem(); - var globalToLocal = BH.Engine.Geometry.Create.OrientationMatrixLocalToGlobal(coordSystem); + 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(); diff --git a/IES_Adapter/Convert/Environment/Space.cs b/IES_Adapter/Convert/Environment/Space.cs index 5e4ff3c..b2e99b1 100644 --- a/IES_Adapter/Convert/Environment/Space.cs +++ b/IES_Adapter/Convert/Environment/Space.cs @@ -152,6 +152,7 @@ public static List FromIES(this List iesSpace, SettingsIES settin Polyline pLine = new Polyline { ControlPoints = pLinePts, }; + Panel panel = new Panel(); panel.ExternalEdges = pLine.ToEdges(); panel.Openings = new List(); @@ -176,7 +177,7 @@ public static List FromIES(this List iesSpace, SettingsIES settin for (int x = 0; x < numCoords; x++) openingPts.Add(iesSpace[count + x]); - panel.Openings.Add(openingPts.FromIESOpening(openingData.Split(' ')[1], settingsIES)); + panel.Openings.Add(openingPts.FromIESOpening(openingData.Split(' ')[1], pLine, settingsIES)); count += numCoords; countOpenings++; diff --git a/IES_oM/SettingsIES.cs b/IES_oM/SettingsIES.cs index f50aaac..15b1fbe 100644 --- a/IES_oM/SettingsIES.cs +++ b/IES_oM/SettingsIES.cs @@ -24,6 +24,7 @@ using System.Collections.Generic; using BH.oM.Base; using System.ComponentModel; +using BH.oM.Geometry; namespace BH.oM.IES.Settings { @@ -45,6 +46,10 @@ public class SettingsIES : BHoMObject public virtual bool ShadesAs3D { get; set; } = true; + public virtual double AngleTolerance { get; set; } = BH.oM.Geometry.Tolerance.Angle; + + public virtual double DistanceTolerance { get; set; } = BH.oM.Geometry.Tolerance.MacroDistance; + /***************************************************/ } } From bf777856057757e56171bd16aa9fc4b36400d540 Mon Sep 17 00:00:00 2001 From: Karolina Prusicka Date: Fri, 3 Feb 2023 15:56:40 +0000 Subject: [PATCH 18/27] Turning on the 2D shades --- IES_Adapter/CRUD/Create.cs | 4 ++-- IES_Adapter/CRUD/Read.cs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/IES_Adapter/CRUD/Create.cs b/IES_Adapter/CRUD/Create.cs index 3790b9b..128e7c0 100644 --- a/IES_Adapter/CRUD/Create.cs +++ b/IES_Adapter/CRUD/Create.cs @@ -66,8 +66,8 @@ protected override bool ICreate(IEnumerable objects, ActionConfig actionCo sw.Write(s); } - //if (panelsAsShade.Count > 0 && !_settingsIES.ShadesAs3D) - //panelsAsShade.ToIESShading(_settingsIES).ForEach(x => sw.Write(x)); + if (panelsAsShade.Count > 0 && !_settingsIES.ShadesAs3D) + panelsAsShade.ToIESShading(_settingsIES).ForEach(x => sw.Write(x)); } catch(Exception e) { diff --git a/IES_Adapter/CRUD/Read.cs b/IES_Adapter/CRUD/Read.cs index 89f089d..6df7d87 100644 --- a/IES_Adapter/CRUD/Read.cs +++ b/IES_Adapter/CRUD/Read.cs @@ -124,9 +124,9 @@ private List ReadPanels() for (int x = 0; x < nextIndex; x++) space.Add(iesStrings[x]); - //if ((panelType == PanelType.Shade || panelType == PanelType.TranslucentShade) && !_settingsIES.ShadesAs3D) - //panels.Add(space.FromIESShading(_settingsIES, panelType)); //Make a shade panel - /*else*/ if ((panelType == PanelType.Shade || panelType == PanelType.TranslucentShade) && _settingsIES.ShadesAs3D) + if ((panelType == PanelType.Shade || panelType == PanelType.TranslucentShade) && !_settingsIES.ShadesAs3D) + panels.Add(space.FromIESShading(_settingsIES, panelType)); //Make a shade panel + else if ((panelType == PanelType.Shade || panelType == PanelType.TranslucentShade) && _settingsIES.ShadesAs3D) { var shadePanels = space.FromIES(_settingsIES); shadePanels.ForEach(x => x.Type = panelType); From 2513f9b63e6e08961f4bc073162f8a7095a72b93 Mon Sep 17 00:00:00 2001 From: Ellie Adebowale Date: Fri, 24 Feb 2023 13:07:09 +0000 Subject: [PATCH 19/27] Layer was attribute was already changed to Layer 64, and I have changed the colour to shade 65280 --- IES_Adapter/Convert/Environment/Panel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IES_Adapter/Convert/Environment/Panel.cs b/IES_Adapter/Convert/Environment/Panel.cs index 7f278a2..be1b009 100644 --- a/IES_Adapter/Convert/Environment/Panel.cs +++ b/IES_Adapter/Convert/Environment/Panel.cs @@ -55,7 +55,7 @@ public static List ToIESShading(this List panelsAsShade, Settings { var template = Create.ShadeTemplate(); template.Layer = "64"; - template.Colour = "0"; + template.Colour = "65280"; gemPanel.AddRange(template.ToIES()); From e4859e2bcb9596e16814bbe15a9ab118a0a19031 Mon Sep 17 00:00:00 2001 From: Ellie Adebowale Date: Fri, 24 Feb 2023 13:16:57 +0000 Subject: [PATCH 20/27] Changed Shade layer in GEMTemplate --- IES_Adapter/Create/ShadeTemplate.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IES_Adapter/Create/ShadeTemplate.cs b/IES_Adapter/Create/ShadeTemplate.cs index cecddcd..3d9a9aa 100644 --- a/IES_Adapter/Create/ShadeTemplate.cs +++ b/IES_Adapter/Create/ShadeTemplate.cs @@ -34,7 +34,7 @@ public static GEMTemplate ShadeTemplate() { return new GEMTemplate() { - Layer = "1", + Layer = "64", Colour = "62", Category = "1", Type = "4", From 64519fcdd27ef15873873a31934c2b3d2bc74c1a Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Thu, 16 Mar 2023 11:16:15 +0000 Subject: [PATCH 21/27] Call me GhostBusters because we just removed some Ghost Spaces #212 --- IES_Adapter/Convert/Objects/GEMTemplate.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/IES_Adapter/Convert/Objects/GEMTemplate.cs b/IES_Adapter/Convert/Objects/GEMTemplate.cs index e8e08af..b3dac5b 100644 --- a/IES_Adapter/Convert/Objects/GEMTemplate.cs +++ b/IES_Adapter/Convert/Objects/GEMTemplate.cs @@ -52,9 +52,6 @@ public static List ToIES(this GEMTemplate gemTemplate) gemLines.Add("COLOURRGB\n"); gemLines.Add($"{gemTemplate.ColourRGB}\n"); - gemLines.Add($"IES {gemTemplate.Name}\n"); - gemLines.Add($"{gemTemplate.VerticesCount.ToString()} {gemTemplate.FaceCount.ToString()}\n"); - return gemLines; } } From e616fd0546f6f5faedc3912d69dd95c8aa87e423 Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Thu, 16 Mar 2023 17:31:17 +0000 Subject: [PATCH 22/27] Tidy up properties --- IES_Adapter/Objects/GEMTemplate.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/IES_Adapter/Objects/GEMTemplate.cs b/IES_Adapter/Objects/GEMTemplate.cs index f350a86..d26c2c9 100644 --- a/IES_Adapter/Objects/GEMTemplate.cs +++ b/IES_Adapter/Objects/GEMTemplate.cs @@ -36,8 +36,5 @@ public class GEMTemplate public virtual string Type { get; set; } public virtual string SubType { get; set; } public virtual string ColourRGB { get; set; } - public virtual string Name { get; set; } - public virtual int VerticesCount { get; set; } - public virtual int FaceCount { get; set; } } } From 5482865ee5dcf03e352a763dff956650d75ab7e8 Mon Sep 17 00:00:00 2001 From: Courtney Boulter Date: Fri, 17 Mar 2023 13:30:26 +0000 Subject: [PATCH 23/27] Set AdapterID to false --- IES_Adapter/IESAdapter.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/IES_Adapter/IESAdapter.cs b/IES_Adapter/IESAdapter.cs index 4278d2b..d716d8f 100644 --- a/IES_Adapter/IESAdapter.cs +++ b/IES_Adapter/IESAdapter.cs @@ -50,6 +50,7 @@ public IESAdapter(BH.oM.Adapter.FileSettings fileSettings = null, SettingsIES se { // This asks the base adapter to only Create the objects. m_AdapterSettings.DefaultPushType = oM.Adapter.PushType.CreateOnly; + m_AdapterSettings.UseAdapterId = false; if (fileSettings == null) { From 31707212747cf2d702580cf7d408a4c46c76c394 Mon Sep 17 00:00:00 2001 From: Courtney Boulter Date: Fri, 17 Mar 2023 13:46:40 +0000 Subject: [PATCH 24/27] Fixed punctuation. --- IES_Adapter/IESAdapter.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/IES_Adapter/IESAdapter.cs b/IES_Adapter/IESAdapter.cs index d716d8f..6cd1bf7 100644 --- a/IES_Adapter/IESAdapter.cs +++ b/IES_Adapter/IESAdapter.cs @@ -42,10 +42,10 @@ public partial class IESAdapter : BHoMAdapter /**** Constructors ****/ /***************************************************/ - [Description("Produces an IES Adapter to allow interopability with IES GEM files and the BHoM")] - [Input("fileSettings", "Input fileSettings to get the file name and directory the IES Adapter should use")] + [Description("Produces an IES Adapter to allow interopability with IES GEM files and the BHoM.")] + [Input("fileSettings", "Input fileSettings to get the file name and directory the IES Adapter should use.")] [Input("settingsIES", "Input additional settings the adapter should use.")] - [Output("adapter", "Adapter to IES GEM")] + [Output("adapter", "Adapter to IES GEM.")] public IESAdapter(BH.oM.Adapter.FileSettings fileSettings = null, SettingsIES settingsIES = null) { // This asks the base adapter to only Create the objects. From 84b19479a686a41dd5d18a9242b7b7ebdcc90c0a Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Tue, 21 Mar 2023 10:23:05 +0000 Subject: [PATCH 25/27] Fix #218 --- IES_Adapter/CRUD/Create.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/IES_Adapter/CRUD/Create.cs b/IES_Adapter/CRUD/Create.cs index 128e7c0..c501230 100644 --- a/IES_Adapter/CRUD/Create.cs +++ b/IES_Adapter/CRUD/Create.cs @@ -57,6 +57,11 @@ protected override bool ICreate(IEnumerable objects, ActionConfig actionCo StreamWriter sw = new StreamWriter(_fileSettings.GetFullFileName()); + sw.WriteLine("COM GEM data file exported by BHoM"); + sw.WriteLine("CAT"); //Lol - Default GEM files use ANT + sw.WriteLine("SITE"); + sw.WriteLine("51.378  2.3648  0.000  0.000"); + try { foreach (List space in panelsAsSpaces) From e89f2a81389edefa0a4db83396dbc3d5cb320cf5 Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Tue, 21 Mar 2023 10:24:04 +0000 Subject: [PATCH 26/27] Fix #217 --- IES_Adapter/Convert/Environment/Space.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/IES_Adapter/Convert/Environment/Space.cs b/IES_Adapter/Convert/Environment/Space.cs index b2e99b1..67d723e 100644 --- a/IES_Adapter/Convert/Environment/Space.cs +++ b/IES_Adapter/Convert/Environment/Space.cs @@ -177,7 +177,8 @@ public static List FromIES(this List iesSpace, SettingsIES settin for (int x = 0; x < numCoords; x++) openingPts.Add(iesSpace[count + x]); - panel.Openings.Add(openingPts.FromIESOpening(openingData.Split(' ')[1], pLine, settingsIES)); + if(settingsIES.PullOpenings) + panel.Openings.Add(openingPts.FromIESOpening(openingData.Split(' ')[1], pLine, settingsIES)); count += numCoords; countOpenings++; From 2ecd9d46ffe5721263a3059f0a10883cea7d7e98 Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Tue, 21 Mar 2023 10:50:22 +0000 Subject: [PATCH 27/27] Fix formatting issues in GEM create --- IES_Adapter/CRUD/Create.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IES_Adapter/CRUD/Create.cs b/IES_Adapter/CRUD/Create.cs index c501230..0c40298 100644 --- a/IES_Adapter/CRUD/Create.cs +++ b/IES_Adapter/CRUD/Create.cs @@ -60,7 +60,7 @@ protected override bool ICreate(IEnumerable objects, ActionConfig actionCo sw.WriteLine("COM GEM data file exported by BHoM"); sw.WriteLine("CAT"); //Lol - Default GEM files use ANT sw.WriteLine("SITE"); - sw.WriteLine("51.378  2.3648  0.000  0.000"); + sw.WriteLine("51.378 2.3648 0.000 0.000"); try {