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

Fix get dependency modules depending on order in constructor #358

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
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ public StructuralAdapter(bool cacheCRUDobjects = true)
{typeof(BarRelease), new NameOrDescriptionComparer() }
};

AdapterIdFragmentType = typeof(StructuralAdapterId);

BH.Adapter.Modules.Structure.ModuleLoader.LoadModules(this);
AdapterIdFragmentType = typeof(StructuralAdapterId);
}

protected override bool ICreate<T>(IEnumerable<T> objects, ActionConfig actionConfig = null)
Expand Down
25 changes: 17 additions & 8 deletions Structure_AdapterModules/GetGravityLoadElementsWithoutID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,36 @@ public class GetGravityLoadElementsWithoutID<T> : IGetDependencyModule<GravityLo

public IEnumerable<T> GetDependencies(IEnumerable<GravityLoad> objects)
{
List<T> noIdLoadObjects = new List<T>();
foreach (GravityLoad load in objects)

if (m_adapter?.AdapterIdFragmentType == null)
{
string adapterType = m_adapter == null ? "Adapter" : m_adapter.GetType().Name;
BH.Engine.Base.Compute.RecordWarning($"{adapterType} does not have a set {nameof(m_adapter.AdapterIdFragmentType)}. Unable to filter load objects by set ID. All objects on the load will be treated as a dependency.");
return objects.Select(x => x?.Objects?.Elements).Where(x => x != null).SelectMany(x => x).Where(x => x != null).OfType<T>().ToList();
}
else
{
if(load?.Objects?.Elements != null)
noIdLoadObjects.AddRange(load.Objects.Elements.OfType<T>().Where(x => x != null && !x.Fragments.Contains(m_adapterIdType)));
List<T> noIdLoadObjects = new List<T>();
foreach (GravityLoad load in objects)
{
if (load?.Objects?.Elements != null)
noIdLoadObjects.AddRange(load.Objects.Elements.OfType<T>().Where(x => x != null && !x.Fragments.Contains(m_adapter.AdapterIdFragmentType)));
}
return noIdLoadObjects;
}
return noIdLoadObjects;
}

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

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

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

private Type m_adapterIdType;
private IBHoMAdapter m_adapter;

/***************************************************/
}
Expand Down
24 changes: 17 additions & 7 deletions Structure_AdapterModules/GetLoadElementsWithoutID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,23 @@ public class GetLoadElementsWithoutID<T> : IGetDependencyModule<IElementLoad<T>,

public IEnumerable<T> GetDependencies(IEnumerable<IElementLoad<T>> objects)
{
List<T> noIdLoadObjects = new List<T>();
foreach (IElementLoad<T> load in objects)
if (m_adapter?.AdapterIdFragmentType == null)
{
if(load?.Objects?.Elements != null)
noIdLoadObjects.AddRange(load.Objects.Elements.Where(x => x != null && !x.Fragments.Contains(m_adapterIdType)));
string adapterType = m_adapter == null ? "Adapter" : m_adapter.GetType().Name;
BH.Engine.Base.Compute.RecordWarning($"{adapterType} does not have a set {nameof(m_adapter.AdapterIdFragmentType)}. Unable to filter load objects by set ID. All objects on the load will be treated as a dependency.");
return objects.Select(x => x?.Objects?.Elements).Where(x => x != null).SelectMany(x => x).Where(x => x != null).ToList();
}
return noIdLoadObjects;
else
{
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_adapter.AdapterIdFragmentType)));
}
return noIdLoadObjects;
}

}

/***************************************************/
Expand All @@ -60,12 +70,12 @@ public IEnumerable<T> GetDependencies(IEnumerable<IElementLoad<T>> objects)

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

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

private Type m_adapterIdType;
private IBHoMAdapter m_adapter;

/***************************************************/
}
Expand Down