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

Aligning with changes in BHoMAdapter Refactoring Level 04 #11

Merged
merged 2 commits into from
Jan 24, 2020
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
32 changes: 4 additions & 28 deletions OpenStudio_Adapter/CRUD/Create.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
using BHC = BH.oM.Physical.Constructions;
using BHEM = BH.oM.Environment.MaterialFragments;

using BH.oM.Adapter;

namespace BH.Adapter.OpenStudio
{
public partial class OpenStudioAdapter : BHoMAdapter
{
protected override bool Create<T>(IEnumerable<T> objects)
protected override bool ICreate<T>(IEnumerable<T> objects, ActionConfig actionConfig = null)
{
bool success = true;

Expand All @@ -29,32 +31,6 @@ protected override bool Create<T>(IEnumerable<T> objects)
CreateModel(objects as List<IBHoMObject>);
}

/*OpenStudio.Model model = new Model();

if (typeof(IBHoMObject).IsAssignableFrom(typeof(T)))
{
List<IBHoMObject> objs = objects.ToList() as List<IBHoMObject>;

List<BHE.BuildingElement> buildingElements = objs.BuildingElements();

List<List<BHE.BuildingElement>> elementsAsSpaces = buildingElements.BuildSpaces(buildingElements.UniqueSpaceNames());

model = CreateModel(elementsAsSpaces, model);
}

EnergyPlusForwardTranslator translator = new EnergyPlusForwardTranslator();
Workspace workspace = translator.translateModel(model);
IdfFile idf = workspace.toIdfFile();
idf.save(OpenStudio.OpenStudioUtilitiesCore.toPath(IDFFilePath));
/*OpenStudio.Model model = new Model();

EnergyPlusForwardTranslator t2 = new EnergyPlusForwardTranslator();
Workspace w2 = t2.translateModel(model);
IdfFile i2 = w2.toIdfFile();


i2.save(new OpenStudio.Path(OpenStudio.OpenStudioUtilitiesCore.toPath(@"C:\Users\fgreenro\Documents\Repo Code\Test Files & Scripts\BHoM Testing\EnergyPlus_Toolkit\firstTest.idf")), true);
*/
return success;
}

Expand All @@ -75,7 +51,7 @@ public bool CreateModel(List<IBHoMObject> objects)
EnergyPlusForwardTranslator translator = new EnergyPlusForwardTranslator();
Workspace workspace = translator.translateModel(model);
IdfFile idf = workspace.toIdfFile();
idf.save(global::OpenStudio.OpenStudioUtilitiesCore.toPath(IDFFilePath), true); //setting overwrite file true to avoid appending the surfaces to the exisiting idf file
idf.save(global::OpenStudio.OpenStudioUtilitiesCore.toPath(m_IDFFilePath), true); //setting overwrite file true to avoid appending the surfaces to the exisiting idf file

return success;
}
Expand Down
13 changes: 0 additions & 13 deletions OpenStudio_Adapter/CRUD/Delete.cs

This file was deleted.

26 changes: 0 additions & 26 deletions OpenStudio_Adapter/CRUD/Read.cs

This file was deleted.

13 changes: 0 additions & 13 deletions OpenStudio_Adapter/CRUD/Update.cs

This file was deleted.

36 changes: 5 additions & 31 deletions OpenStudio_Adapter/OpenStudioAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Threading.Tasks;

using BH.oM.Base;
//using System.Reflection;
using BH.oM.Data.Requests;
using BH.oM.Reflection.Attributes;
using System.ComponentModel;
Expand All @@ -20,38 +19,13 @@ public partial class OpenStudioAdapter : BHoMAdapter
public OpenStudioAdapter(string idfFilePath)
{
BH.Engine.Reflection.Compute.RecordWarning("This adapter is under development. Its use is not yet sanctioned for project work. You use this at your own risk. Check the GitHub repo for the latest version and updates on development status");
IDFFilePath = idfFilePath;
m_IDFFilePath = idfFilePath;

AdapterId = "OpenStudio_Adapter";
Config.UseAdapterId = false; //Set to true when NextId method and id tagging has been implemented
}

public override List<IObject> Push(IEnumerable<IObject> objects, String tag = "", Dictionary<String, object> config = null)
{
bool success = true;

//MethodInfo methodInfos = typeof(Enumerable).GetMethod("Cast");
/*foreach (var typeGroup in objects.GroupBy(x => x.GetType()))
{
MethodInfo mInfo = methodInfos.MakeGenericMethod(new[] { typeGroup.Key });
var list = mInfo.Invoke(typeGroup, new object[] { typeGroup });
success &= Create(list as dynamic, false);
}*/

CreateModel(objects.ToList().ConvertAll(x => (IBHoMObject)x).ToList());
AdapterIdName = "OpenStudio_Adapter";

return success ? objects.ToList() : new List<IObject>();
m_AdapterSettings.DefaultPushType = oM.Adapter.PushType.CreateOnly;
}

public override IEnumerable<object> Pull(IRequest request, Dictionary<string, object> config = null)
{
if (request is IRequest)
return Read();

return new List<IBHoMObject>();
}


private string IDFFilePath { get; set; }
private string m_IDFFilePath;
}
}
}
7 changes: 4 additions & 3 deletions OpenStudio_Adapter/OpenStudio_Adapter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Adapter_oM">
<HintPath>..\..\BHoM_Adapter\Build\Adapter_oM.dll</HintPath>
</Reference>
<Reference Include="Analytical_oM, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\BHoM\Build\Analytical_oM.dll</HintPath>
Expand Down Expand Up @@ -98,9 +101,6 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CRUD\Create.cs" />
<Compile Include="CRUD\Delete.cs" />
<Compile Include="CRUD\Read.cs" />
<Compile Include="CRUD\Update.cs" />
<Compile Include="OpenStudioAdapter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand All @@ -114,6 +114,7 @@
<Name>OpenStudio_oM</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>Copy /Y "$(ProjectDir)..\libs\msvcp120.dll" "$(ProjectDir)..\Build\msvcp120.dll"
Expand Down