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

ProcessObjectsForPush() to first Unpack any IContainer, then check for IBHoMObjects #351

Merged
Merged
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
42 changes: 23 additions & 19 deletions BHoM_Adapter/AdapterActions/_PushMethods/ProcessObjectsForPush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,42 +53,46 @@ protected virtual IEnumerable<IBHoMObject> ProcessObjectsForPush(IEnumerable<obj
wrapNonBHoMObjects = actionConfig.WrapNonBHoMObjects;


// -------------------------------- //
// CHECKS //
// -------------------------------- //

// Verify that the input objects are IBHoMObjects.
if (objects.OfType<IBHoMObject>().Count() != objects.Count() & !wrapNonBHoMObjects)
{
BH.Engine.Base.Compute.RecordWarning("Only non-null BHoMObjects are supported by the default Push. " + // = you can override if needed;
"\nConsider specifying actionConfig['WrapNonBHoMObjects'] to true.");
}

// -------------------------------- //
// OBJECT PREPARATION //
// -------------------------------- //
// ---------------------------------------- //
// OBJECT PREPARATION - Unpack //
// ---------------------------------------- //

// Unpack any container present in the input objects
List<object> unpackedObjs = new List<object>();
List<object> objectsIncludingUnpacked = new List<object>();

foreach (var obj in objects)
{
if (obj is IContainer container)
{
unpackedObjs.AddRange(container.Unpack());
objectsIncludingUnpacked.AddRange(container.Unpack());
}
else
unpackedObjs.Add(obj);
objectsIncludingUnpacked.Add(obj);
}

// -------------------------------- //
// CHECKS //
// -------------------------------- //

// Verify that the input objects are IBHoMObjects.
if (objectsIncludingUnpacked.OfType<IBHoMObject>().Count() != objectsIncludingUnpacked.Count() & !wrapNonBHoMObjects)
{
BH.Engine.Base.Compute.RecordWarning("Only non-null BHoMObjects are supported by the default Push. " + // = you can override if needed;
"\nConsider specifying actionConfig['WrapNonBHoMObjects'] to true.");
}

IEnumerable<IBHoMObject> objectsToPush = new List<IBHoMObject>();

// Wrap non-BHoM objects into a Custom BHoMObject to make them compatible with the CRUD.
if (wrapNonBHoMObjects)
objectsToPush = WrapNonBHoMObjects(unpackedObjs);
objectsToPush = WrapNonBHoMObjects(objectsIncludingUnpacked);
else
objectsToPush = unpackedObjs.OfType<IBHoMObject>();
objectsToPush = objectsIncludingUnpacked.OfType<IBHoMObject>();


// ----------------------------------------- //
// OBJECT PREPARATION - Cloning //
// ----------------------------------------- //

// Clone the objects for immutability in the UI. CloneBeforePush should always be true, except for very specific cases.
if (m_AdapterSettings.CloneBeforePush)
Expand Down