Skip to content

Commit

Permalink
Add module getting objects with no set ID from loads
Browse files Browse the repository at this point in the history
  • Loading branch information
IsakNaslundBh committed Dec 9, 2022
1 parent 7902708 commit 28a94ec
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
74 changes: 74 additions & 0 deletions Structure_AdapterModules/GetLoadElementsWithoutId.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, 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 <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using BH.oM.Base;
using BH.oM.Adapter;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Reflection;
using System.ComponentModel;
using BH.oM.Structure.Elements;
using System.Collections;
using BH.oM.Geometry;
using BH.oM.Structure.Constraints;
using BH.oM.Structure.Loads;


namespace BH.Adapter.Modules
{
[Description("Get all elements that does not contain an adapter ID of the expected type. Avoids the need to again read and check against elements already in the model.")]
public class GetLoadElementsWithoutId<T> : IGetDependencyModule<IElementLoad<T>, T> where T : IBHoMObject
{
/***************************************************/
/**** Interface method ****/
/***************************************************/

public IEnumerable<T> GetDependencies(IEnumerable<IElementLoad<T>> objects)
{
List<T> noIdLoadObjects = new List<T>();
foreach (IElementLoad<T> load in objects)
{
if(load?.Objects?.Elements != null)
noIdLoadObjects.AddRange(load.Objects.Elements.Where(x => x != null && !x.Fragments.Contains(m_adapterIdType)));
}
return noIdLoadObjects;
}

/***************************************************/
/**** Constructors ****/
/***************************************************/

public GetLoadElementsWithoutId(IBHoMAdapter adapter)
{
m_adapterIdType = adapter.AdapterIdFragmentType;
}

/***************************************************/

private Type m_adapterIdType;

/***************************************************/
}
}


5 changes: 5 additions & 0 deletions Structure_AdapterModules/ModuleLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using BH.Adapter;
using BH.oM.Adapter;
using BH.oM.Base;
using BH.oM.Structure.Elements;

namespace BH.Adapter.Modules.Structure
{
Expand All @@ -40,6 +41,10 @@ public static void LoadModules(this BHoMAdapter adapter)
adapter.AdapterModules.Add(new CopyNodeProperties());
adapter.AdapterModules.Add(new GetCasesFromCombinations());
adapter.AdapterModules.Add(new GetCombinationsFromCombinations());
adapter.AdapterModules.Add(new GetLoadElementsWithoutId<Bar>(adapter));
adapter.AdapterModules.Add(new GetLoadElementsWithoutId<Node>(adapter));
adapter.AdapterModules.Add(new GetLoadElementsWithoutId<IAreaElement>(adapter));
adapter.AdapterModules.Add(new GetLoadElementsWithoutId<BHoMObject>(adapter)); //Gravity loads
}
}
}
Expand Down

0 comments on commit 28a94ec

Please sign in to comment.