From cbe6a38d38a7dad7c7992cda2b9c130a479fb872 Mon Sep 17 00:00:00 2001 From: Anna Stigenberg Date: Tue, 9 Feb 2021 14:48:43 +0000 Subject: [PATCH 1/3] Create AnalysisStage Class and Convert Method --- .../Convert/ToGsa/Analysis/AnalysisStage.cs | 92 +++++++++++++++++++ GSA_Adapter/GSA_Adapter.csproj | 1 + GSA_oM/Analysis/AnalysisStage.cs | 46 ++++++++++ GSA_oM/GSA_oM.csproj | 1 + 4 files changed, 140 insertions(+) create mode 100644 GSA_Adapter/Convert/ToGsa/Analysis/AnalysisStage.cs create mode 100644 GSA_oM/Analysis/AnalysisStage.cs diff --git a/GSA_Adapter/Convert/ToGsa/Analysis/AnalysisStage.cs b/GSA_Adapter/Convert/ToGsa/Analysis/AnalysisStage.cs new file mode 100644 index 00000000..392b5c0d --- /dev/null +++ b/GSA_Adapter/Convert/ToGsa/Analysis/AnalysisStage.cs @@ -0,0 +1,92 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2021, 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.Engine.Adapters.GSA; +using BH.oM.Adapters.GSA.Analysis; +using BH.oM.Base; +using BH.oM.Structure.Constraints; +using BH.oM.Structure.SectionProperties; +using BH.oM.Structure.SurfaceProperties; +using System; +using System.Collections.Generic; + +namespace BH.Adapter.GSA +{ + public static partial class Convert + { + /***************************************************/ + /**** Public Methods ****/ + /***************************************************/ + + private static string ToGsaString(this AnalysisStage stage, string index) + { + string command = "ANAL_STAGE"; + string name = stage.Name; + + List elements = stage.Elements; + string objectIds = ""; + + for (int i = 0; i < elements.Count; i++) + { + string id = ""; + + // String type + if (int.TryParse(elements[i].ToString(), out int idInt)) + { + id = idInt.ToString(); + } + + // Property Type + else if (elements[i] is ISectionProperty) + { + id = "PB" + (elements[i] as ISectionProperty).GSAId().ToString(); + } + else if (elements[i] is LinkConstraint) + { + id = "PL" + (elements[i] as LinkConstraint).GSAId().ToString(); + } + else if (elements[i] is ISurfaceProperty) + { + id = "PA" + (elements[i] as ISurfaceProperty).GSAId().ToString(); + } + + // Element type + else if (elements[i] is IBHoMObject) + { + id = (elements[i] as IBHoMObject).GSAId().ToString(); + } + else + { + BH.Engine.Reflection.Compute.RecordError("Unable to extract GSA Id. Supported types are doubles, ints, strings and BHoMObjects."); + continue; + } + + objectIds += " " + id; + } + + string str = command + ", " + index + " , " + name + ", NO_RGB , " + objectIds + " , 0 ,"; + return str; + } + + /***************************************/ + } +} \ No newline at end of file diff --git a/GSA_Adapter/GSA_Adapter.csproj b/GSA_Adapter/GSA_Adapter.csproj index 23640b03..f02cbee5 100644 --- a/GSA_Adapter/GSA_Adapter.csproj +++ b/GSA_Adapter/GSA_Adapter.csproj @@ -141,6 +141,7 @@ + diff --git a/GSA_oM/Analysis/AnalysisStage.cs b/GSA_oM/Analysis/AnalysisStage.cs new file mode 100644 index 00000000..6713ded7 --- /dev/null +++ b/GSA_oM/Analysis/AnalysisStage.cs @@ -0,0 +1,46 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2021, 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; +using System; +using System.Collections.Generic; +using System.ComponentModel; + +namespace BH.oM.Adapters.GSA.Analysis +{ + public class AnalysisStage : BHoMObject + { + /***************************************************/ + /**** Properties ****/ + /***************************************************/ + + [Description("List of objects to include in the Analysis Stage. This can be the following types: doubles, ints, strings and BHoMObjects.")] + public virtual List Elements { get; set; } + + /***************************************************/ + + [Description("This is an int.")] + public virtual int Number { get; set; } + + /***************************************************/ + } +} diff --git a/GSA_oM/GSA_oM.csproj b/GSA_oM/GSA_oM.csproj index 84c0202d..f822da30 100644 --- a/GSA_oM/GSA_oM.csproj +++ b/GSA_oM/GSA_oM.csproj @@ -57,6 +57,7 @@ + From 5c2f7e32d59296d59fe48144a8f2fd67a61e4a2b Mon Sep 17 00:00:00 2001 From: Anna Stigenberg Date: Tue, 9 Feb 2021 16:55:22 +0000 Subject: [PATCH 2/3] Update initialisation of idInt --- GSA_Adapter/Convert/ToGsa/Analysis/AnalysisStage.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/GSA_Adapter/Convert/ToGsa/Analysis/AnalysisStage.cs b/GSA_Adapter/Convert/ToGsa/Analysis/AnalysisStage.cs index 392b5c0d..66dee261 100644 --- a/GSA_Adapter/Convert/ToGsa/Analysis/AnalysisStage.cs +++ b/GSA_Adapter/Convert/ToGsa/Analysis/AnalysisStage.cs @@ -48,9 +48,10 @@ private static string ToGsaString(this AnalysisStage stage, string index) for (int i = 0; i < elements.Count; i++) { string id = ""; + int idInt; // String type - if (int.TryParse(elements[i].ToString(), out int idInt)) + if (int.TryParse(elements[i].ToString(), out idInt)) { id = idInt.ToString(); } From c36fb2890b2fde640306df98edee7d27a72a3d45 Mon Sep 17 00:00:00 2001 From: Anna Stigenberg Date: Wed, 10 Feb 2021 09:43:37 +0000 Subject: [PATCH 3/3] Custom Indexing --- GSA_Adapter/Convert/ToGsa/Analysis/AnalysisStage.cs | 4 ++++ GSA_oM/Analysis/AnalysisStage.cs | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/GSA_Adapter/Convert/ToGsa/Analysis/AnalysisStage.cs b/GSA_Adapter/Convert/ToGsa/Analysis/AnalysisStage.cs index 66dee261..e03ff040 100644 --- a/GSA_Adapter/Convert/ToGsa/Analysis/AnalysisStage.cs +++ b/GSA_Adapter/Convert/ToGsa/Analysis/AnalysisStage.cs @@ -28,6 +28,7 @@ using BH.oM.Structure.SurfaceProperties; using System; using System.Collections.Generic; +using BH.Engine.Adapter; namespace BH.Adapter.GSA { @@ -41,6 +42,9 @@ private static string ToGsaString(this AnalysisStage stage, string index) { string command = "ANAL_STAGE"; string name = stage.Name; + index = stage.Number.ToString(); + + stage.SetAdapterId(typeof(BH.oM.Adapters.GSA.GSAId), stage.Number); List elements = stage.Elements; string objectIds = ""; diff --git a/GSA_oM/Analysis/AnalysisStage.cs b/GSA_oM/Analysis/AnalysisStage.cs index 6713ded7..24321b51 100644 --- a/GSA_oM/Analysis/AnalysisStage.cs +++ b/GSA_oM/Analysis/AnalysisStage.cs @@ -38,7 +38,7 @@ public class AnalysisStage : BHoMObject /***************************************************/ - [Description("This is an int.")] + [Description("GSA Id. This is an int. Must be greater than 0.")] public virtual int Number { get; set; } /***************************************************/