diff --git a/XML_Adapter/AdapterActions/Push.cs b/XML_Adapter/AdapterActions/Push.cs index 453c441..70f7478 100644 --- a/XML_Adapter/AdapterActions/Push.cs +++ b/XML_Adapter/AdapterActions/Push.cs @@ -30,6 +30,9 @@ using BH.oM.Adapter; using BH.oM.Base; using System.Reflection; +using BH.oM.Adapters.XML; +using BH.oM.Adapters.XML.Enums; +using System.IO; namespace BH.Adapter.XML { @@ -41,26 +44,65 @@ public override List Push(IEnumerable objects, String tag = "", if (pushType == PushType.AdapterDefault) pushType = m_AdapterSettings.DefaultPushType; - /*if (_xmlSettings == null) + if (actionConfig == null) { - BH.Engine.Base.Compute.RecordError("Please set some XML Settings on the XML Adapter before pushing to an XML File"); + BH.Engine.Base.Compute.RecordError("Please provide configuration settings to push to an XML file"); return new List(); - }*/ + } - IEnumerable objectsToPush = ProcessObjectsForPush(objects, actionConfig); // Note: default Push only supports IBHoMObjects. + XMLConfig config = actionConfig as XMLConfig; + if (config == null) + { + BH.Engine.Base.Compute.RecordError("Please provide valid a XMLConfig object for pushing to an XML file"); + return new List(); + } - bool success = true; + IEnumerable objectsToPush = ProcessObjectsForPush(objects, actionConfig); // Note: default Push only supports IBHoMObjects. - MethodInfo methodInfos = typeof(Enumerable).GetMethod("Cast"); - foreach (var typeGroup in objectsToPush.GroupBy(x => x.GetType())) + bool success = false; + switch (config.Schema) { - MethodInfo mInfo = methodInfos.MakeGenericMethod(new[] { typeGroup.Key }); - var list = mInfo.Invoke(typeGroup, new object[] { typeGroup }); - success &= ICreate(list as dynamic, actionConfig); + case Schema.CSProject: + success = CreateCSProject(objectsToPush, config); + break; + case Schema.GBXML: + success = CreateGBXML(objectsToPush, config); + break; + case Schema.KML: + success = CreateKML(objectsToPush, config); + break; + case Schema.EnergyPlusLoads: + BH.Engine.Base.Compute.RecordError("The EnergyPlusLoads Schema is not supported for push operations at this time"); + success = false; + break; + case Schema.Bluebeam: + BH.Engine.Base.Compute.RecordError("The Bluebeam markup schema is not supported for push operations at this time."); + success = false; + break; + default: + success = CreateDefault(objectsToPush, config); + break; } + if (success && config.RemoveNils) + RemoveNil(_fileSettings); + return success ? objects.ToList() : new List(); } + + private static bool RemoveNil(FileSettings file) + { + var path = Path.Combine(file.Directory, file.FileName); + var xmlFile = File.ReadAllLines(path); + + xmlFile = xmlFile.Where(x => !x.Trim().Contains("xsi:nil")).ToArray(); + xmlFile = xmlFile.Where(x => x != null).ToArray(); + + File.Delete(path); + File.WriteAllLines(path, xmlFile); + + return true; + } } } diff --git a/XML_Adapter/CRUD/Create.cs b/XML_Adapter/CRUD/Create.cs deleted file mode 100644 index f7621cb..0000000 --- a/XML_Adapter/CRUD/Create.cs +++ /dev/null @@ -1,102 +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.Adapters.XML; -using BH.oM.Adapters.XML.Enums; - -using BH.oM.Adapter; -using System.IO; - -namespace BH.Adapter.XML -{ - public partial class XMLAdapter : BHoMAdapter - { - protected override bool ICreate(IEnumerable objects, ActionConfig actionConfig = null) - { - if(actionConfig == null) - { - BH.Engine.Base.Compute.RecordError("Please provide configuration settings to push to an XML file"); - return false; - } - - XMLConfig config = actionConfig as XMLConfig; - if(config == null) - { - BH.Engine.Base.Compute.RecordError("Please provide valid a XMLConfig object for pushing to an XML file"); - return false; - } - - bool success = false; - - switch(config.Schema) - { - case Schema.CSProject: - success = CreateCSProject(objects, config); - break; - case Schema.GBXML: - success = CreateGBXML(objects, config); - break; - case Schema.KML: - success = CreateKML(objects, config); - break; - case Schema.EnergyPlusLoads: - BH.Engine.Base.Compute.RecordError("The EnergyPlusLoads Schema is not supported for push operations at this time"); - success = false; - break; - case Schema.Bluebeam: - BH.Engine.Base.Compute.RecordError("The Bluebeam markup schema is not supported for push operations at this time."); - success = false; - break; - default: - success = CreateDefault(objects, config); - break; - } - - if (success && config.RemoveNils) - RemoveNil(_fileSettings); - - return success; - } - - private static bool RemoveNil(FileSettings file) - { - var path = Path.Combine(file.Directory, file.FileName); - var xmlFile = File.ReadAllLines(path); - - xmlFile = xmlFile.Where(x => !x.Trim().Contains("xsi:nil")).ToArray(); - xmlFile = xmlFile.Where(x => x != null).ToArray(); - - File.Delete(path); - File.WriteAllLines(path, xmlFile); - - return true; - } - } -} - - diff --git a/XML_Adapter/CRUD/GBXML/CreateGBXML.cs b/XML_Adapter/CRUD/GBXML/CreateGBXML.cs index 1d2fb2a..de2f77e 100644 --- a/XML_Adapter/CRUD/GBXML/CreateGBXML.cs +++ b/XML_Adapter/CRUD/GBXML/CreateGBXML.cs @@ -37,6 +37,9 @@ using BH.Engine.Adapter; using BH.Engine.Adapters.XML; +using BH.oM.Spatial.SettingOut; +using BH.Engine.Environment; + namespace BH.Adapter.XML { public partial class XMLAdapter : BHoMAdapter @@ -58,29 +61,16 @@ private bool CreateGBXML(IEnumerable objects, XMLConfig config) return false; } - GBXMLDocumentBuilder doc = objects.ToList()[0] as GBXMLDocumentBuilder; - - if(doc == null) - { - BH.Engine.Base.Compute.RecordError("The GBXML schema requires a full model to be provided as a single push operation. For pushing to the GBXML version, you need to plug your objects into a GBXMLDocumentBuilder which collates the objects for pushing and push that to GBXML via this adapter."); - return false; - } + List panels = objects.Where(x => x.GetType() == typeof(Panel)).Cast().ToList(); List bhomObjects = new List(); - bhomObjects.AddRange(doc.Buildings); - bhomObjects.AddRange(doc.Levels); - bhomObjects.AddRange(doc.ShadingElements); - bhomObjects.AddRange(doc.UnassignedPanels); + bhomObjects.AddRange(objects.Where(x => x.GetType() == typeof(oM.Environment.Elements.Building)).Cast()); + bhomObjects.AddRange(objects.Where(x => x.GetType() == typeof(Level)).Cast()); if (settings.ExportDetail == oM.Adapters.XML.Enums.ExportDetail.Full) - { - foreach (List p in doc.ElementsAsSpaces) - bhomObjects.AddRange(p); - } + bhomObjects.AddRange(panels); else if(settings.ExportDetail == oM.Adapters.XML.Enums.ExportDetail.BuildingShell) - { - bhomObjects.AddRange(doc.ElementsAsSpaces.ExternalElements()); - } + bhomObjects.AddRange(panels.ToSpaces().ExternalElements()); else { BH.Engine.Base.Compute.RecordError("The ExportDetail has not been appropriately set. Please set the ExportDetail to continue"); diff --git a/XML_Adapter/XML_Adapter.csproj b/XML_Adapter/XML_Adapter.csproj index 22980b4..326ca62 100644 --- a/XML_Adapter/XML_Adapter.csproj +++ b/XML_Adapter/XML_Adapter.csproj @@ -1,4 +1,4 @@ - + @@ -149,7 +149,6 @@ - @@ -243,9 +242,6 @@ False - - - @@ -259,4 +255,4 @@ xcopy "$(TargetDir)$(TargetFileName)" "C:\ProgramData\BHoM\Assemblies" /Y --> - + \ No newline at end of file diff --git a/XML_Engine/Create/DocumentBuilder.cs b/XML_Engine/Create/DocumentBuilder.cs deleted file mode 100644 index 91ab361..0000000 --- a/XML_Engine/Create/DocumentBuilder.cs +++ /dev/null @@ -1,89 +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.Base.Attributes; - -using BH.oM.Environment.Elements; -using GBXML = BH.oM.Adapters.XML; -using BH.oM.Base; -using BH.oM.Spatial.SettingOut; -using BH.Engine.Environment; - -using System.ComponentModel; - -namespace BH.Engine.Adapters.XML -{ - public static partial class Create - { - /***************************************************/ - /**** Public Methods ****/ - /***************************************************/ - - [Description("Create a Document Builder object to collate data required for GBXML schema documents")] - [Input("building", "The building object for the elements in the schema")] - [Input("elementsAsSpaces", "The nested collection of Environment Panels which form closed spaces within the building")] - [Input("shadingElements", "A collection of Environment Panels which provide shading to the building")] - [Input("levels", "A collection of levels which group spaces by floor")] - [Input("unassignedPanels", "Any additional panels needed to be included within the GBXML file")] - [Output("documentBuilder", "A Document Builder object suitable for GBXML schema document creation")] - public static GBXML.GBXMLDocumentBuilder DocumentBuilder(List building, List> elementsAsSpaces, List shadingElements, List levels, List unassignedPanels) - { - return new GBXML.GBXMLDocumentBuilder - { - Buildings = building, - ElementsAsSpaces = elementsAsSpaces, - ShadingElements = shadingElements, - Levels = levels, - UnassignedPanels = unassignedPanels, - }; - } - - [Description("Create a Document Builder object to collate data required for GBXML schema documents automatically from a given list of BHoM Objects")] - [Input("objs", "A collection of BHoM Objects to sort into a suitable format for inclusion within a GBXML file")] - [Output("documentBuilder", "A Document Builder object suitable for GBXML schema document creation")] - public static GBXML.GBXMLDocumentBuilder DocumentBuilder(List objs) - { - List panels = objs.Panels(); - List spaces = objs.Spaces(); - List levels = objs.Levels(); - List buildings = objs.Buildings(); - - List unassignedPanels = new List(); - - List shadingElements = panels.FilterPanelsByType(new List() { PanelType.Shade }).Item1; - panels = panels.FilterPanelsByType(new List() { PanelType.Shade }).Item2; //Remove shading if it exists - - List> elementsAsSpaces = panels.ToSpaces(); - unassignedPanels.AddRange(panels.Where(x => !elementsAsSpaces.IsContaining(x)).ToList()); - - return DocumentBuilder(buildings, elementsAsSpaces, shadingElements, levels, unassignedPanels); - } - } -} - - - diff --git a/XML_Engine/Versioning_63.json b/XML_Engine/Versioning_63.json new file mode 100644 index 0000000..a2e9826 --- /dev/null +++ b/XML_Engine/Versioning_63.json @@ -0,0 +1,7 @@ +{ + "MessageForDeleted": { + "BH.Engine.Adapters.XML.Create.DocumentBuilder(System.Collections.Generic.List)": "The GBXML Document Builder has been retired in favour of allowing objects to be pushed to XML in a manner that is aligned with other BHoM adapters. Please plug your BHoM objects directly into the Push component to continue your workflow. Ensure the XML Schema is set to GBXML in your configuration settings. Please reach out to the development team via https://github.com/BHoM/XML_Toolkit/issues if you encounter any issues with this.", + "BH.Engine.Adapters.XML.Create.DocumentBuilder(System.Collections.Generic.List, System.Collections.Generic.List>, System.Collections.Generic.List, System.Collections.Generic.List, System.Collections.Generic.List)": "The GBXML Document Builder has been retired in favour of allowing objects to be pushed to XML in a manner that is aligned with other BHoM adapters. Please plug your BHoM objects directly into the Push component to continue your workflow. Ensure the XML Schema is set to GBXML in your configuration settings. Please reach out to the development team via https://github.com/BHoM/XML_Toolkit/issues if you encounter any issues with this.", + "BH.oM.Adapters.XML.GBXMLDocumentBuilder": "The GBXML Document Builder has been retired in favour of allowing objects to be pushed to XML in a manner that is aligned with other BHoM adapters. Please plug your BHoM objects directly into the Push component to continue your workflow. Ensure the XML Schema is set to GBXML in your configuration settings. Please reach out to the development team via https://github.com/BHoM/XML_Toolkit/issues if you encounter any issues with this." + } +} \ No newline at end of file diff --git a/XML_Engine/XML_Engine.csproj b/XML_Engine/XML_Engine.csproj index cf91d23..f882a07 100644 --- a/XML_Engine/XML_Engine.csproj +++ b/XML_Engine/XML_Engine.csproj @@ -1,4 +1,4 @@ - + @@ -106,7 +106,6 @@ - @@ -138,4 +137,4 @@ xcopy "$(TargetDir)$(TargetFileName)" "C:\ProgramData\BHoM\Assemblies" /Y --> - + \ No newline at end of file diff --git a/XML_oM/GBXML/GBXMLDocumentBuilder.cs b/XML_oM/GBXML/GBXMLDocumentBuilder.cs deleted file mode 100644 index 5ae8963..0000000 --- a/XML_oM/GBXML/GBXMLDocumentBuilder.cs +++ /dev/null @@ -1,48 +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 BH.oM.Base; -using BHoME = BH.oM.Environment.Elements; - -namespace BH.oM.Adapters.XML -{ - public class GBXMLDocumentBuilder : BHoMObject - { - /***************************************************/ - /**** Properties ****/ - /***************************************************/ - - public virtual List Buildings { get; set; } = new List(); - public virtual List> ElementsAsSpaces { get; set; } = new List>(); - public virtual List ShadingElements { get; set; } = new List(); - public virtual List Levels { get; set; } = new List(); - public virtual List UnassignedPanels { get; set; } = new List(); - - /***************************************************/ - } -} - - - - diff --git a/XML_oM/XML_oM.csproj b/XML_oM/XML_oM.csproj index 0c6cdda..82072a4 100644 --- a/XML_oM/XML_oM.csproj +++ b/XML_oM/XML_oM.csproj @@ -1,4 +1,4 @@ - + @@ -109,7 +109,6 @@ - @@ -132,4 +131,4 @@ xcopy "$(TargetDir)$(TargetFileName)" "C:\ProgramData\BHoM\Assemblies" /Y - + \ No newline at end of file