Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Remove GBXML DocumentBuilder from workflow for pushing Environment objects to XML #582

Merged
merged 2 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 52 additions & 10 deletions XML_Adapter/AdapterActions/Push.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -41,26 +44,65 @@ public override List<object> Push(IEnumerable<object> 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<object>();
}*/
}

IEnumerable<IBHoMObject> 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<object>();
}

bool success = true;
IEnumerable<IBHoMObject> 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<object>();
}

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;
}
}
}

Expand Down
102 changes: 0 additions & 102 deletions XML_Adapter/CRUD/Create.cs

This file was deleted.

26 changes: 8 additions & 18 deletions XML_Adapter/CRUD/GBXML/CreateGBXML.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -58,29 +61,16 @@ private bool CreateGBXML<T>(IEnumerable<T> 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<Panel> panels = objects.Where(x => x.GetType() == typeof(Panel)).Cast<Panel>().ToList();

List<IBHoMObject> bhomObjects = new List<IBHoMObject>();
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<oM.Environment.Elements.Building>());
bhomObjects.AddRange(objects.Where(x => x.GetType() == typeof(Level)).Cast<Level>());

if (settings.ExportDetail == oM.Adapters.XML.Enums.ExportDetail.Full)
{
foreach (List<Panel> 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");
Expand Down
8 changes: 2 additions & 6 deletions XML_Adapter/XML_Adapter.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down Expand Up @@ -149,7 +149,6 @@
<Compile Include="Convert\KML\ToKML.cs" />
<Compile Include="Convert\KML\ToLatLon.cs" />
<Compile Include="CRUD\Bluebeam\ReadBluebeam.cs" />
<Compile Include="CRUD\Create.cs" />
<Compile Include="CRUD\CSProject\CreateCSProject.cs" />
<Compile Include="CRUD\CSProject\ReadCSProject.cs" />
<Compile Include="CRUD\Default\CreateDefault.cs" />
Expand Down Expand Up @@ -243,9 +242,6 @@
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="Versioning_42.json" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
Expand All @@ -259,4 +255,4 @@ xcopy "$(TargetDir)$(TargetFileName)" "C:\ProgramData\BHoM\Assemblies" /Y
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
89 changes: 0 additions & 89 deletions XML_Engine/Create/DocumentBuilder.cs

This file was deleted.

7 changes: 7 additions & 0 deletions XML_Engine/Versioning_63.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"MessageForDeleted": {
"BH.Engine.Adapters.XML.Create.DocumentBuilder(System.Collections.Generic.List<BH.oM.Base.IBHoMObject>)": "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<BH.oM.Environment.Elements.Building>, System.Collections.Generic.List<System.Collections.Generic.List<BH.oM.Environment.Elements.Panel>>, System.Collections.Generic.List<BH.oM.Environment.Elements.Panel>, System.Collections.Generic.List<BH.oM.Spatial.SettingOut.Level>, System.Collections.Generic.List<BH.oM.Environment.Elements.Panel>)": "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."
}
}
5 changes: 2 additions & 3 deletions XML_Engine/XML_Engine.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down Expand Up @@ -106,7 +106,6 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Create\DocumentBuilder.cs" />
<Compile Include="Create\GBXMLUnitSetUp.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Query\CleanName.cs" />
Expand Down Expand Up @@ -138,4 +137,4 @@ xcopy "$(TargetDir)$(TargetFileName)" "C:\ProgramData\BHoM\Assemblies" /Y
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
Loading