-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add overrides for interior partitions
- Loading branch information
1 parent
039e731
commit 036ea8f
Showing
15 changed files
with
1,637 additions
and
17 deletions.
There are no files selected for viewing
153 changes: 153 additions & 0 deletions
153
LayoutFunctions/InteriorPartitions/dependencies/InteriorPartitionTypesOverride.g.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
using Elements; | ||
using System.Collections.Generic; | ||
using System; | ||
using System.Linq; | ||
|
||
namespace InteriorPartitions | ||
{ | ||
/// <summary> | ||
/// Override metadata for InteriorPartitionTypesOverride | ||
/// </summary> | ||
public partial class InteriorPartitionTypesOverride : IOverride | ||
{ | ||
public static string Name = "Interior Partition Types"; | ||
public static string Dependency = null; | ||
public static string Context = "[*discriminator=Elements.WallCandidate]"; | ||
public static string Paradigm = "Edit"; | ||
|
||
/// <summary> | ||
/// Get the override name for this override. | ||
/// </summary> | ||
public string GetName() { | ||
return Name; | ||
} | ||
|
||
public object GetIdentity() { | ||
|
||
return Identity; | ||
} | ||
|
||
} | ||
public static class InteriorPartitionTypesOverrideExtensions | ||
{ | ||
/// <summary> | ||
/// Apply Interior Partition Types edit overrides to a collection of existing elements | ||
/// </summary> | ||
/// <param name="overrideData">The Interior Partition Types Overrides to apply</param> | ||
/// <param name="existingElements">A collection of existing elements to which to apply the overrides.</param> | ||
/// <param name="identityMatch">A function returning a boolean which indicates whether an element is a match for an override's identity.</param> | ||
/// <param name="modifyElement">A function to modify a matched element, returning the modified element.</param> | ||
/// <typeparam name="T">The element type this override applies to. Should match the type(s) in the override's context.</typeparam> | ||
/// <returns>A collection of elements, including unmodified and modified elements from the supplied collection.</returns> | ||
public static List<T> Apply<T>( | ||
this IList<InteriorPartitionTypesOverride> overrideData, | ||
IEnumerable<T> existingElements, | ||
Func<T, InteriorPartitionTypesIdentity, bool> identityMatch, | ||
Func<T, InteriorPartitionTypesOverride, T> modifyElement) where T : Element | ||
{ | ||
var resultElements = new List<T>(existingElements); | ||
if (overrideData != null) | ||
{ | ||
foreach (var overrideValue in overrideData) | ||
{ | ||
// Assuming there will only be one match per identity, find the first element that matches. | ||
var matchingElement = existingElements.FirstOrDefault(e => identityMatch(e, overrideValue.Identity)); | ||
// if we found a match, | ||
if (matchingElement != null) | ||
{ | ||
// remove the old matching element | ||
resultElements.Remove(matchingElement); | ||
// apply the modification function to it | ||
var modifiedElement = modifyElement(matchingElement, overrideValue); | ||
// set the identity | ||
Identity.AddOverrideIdentity(modifiedElement, overrideValue); | ||
//and re-add it to the collection | ||
resultElements.Add(modifiedElement); | ||
} | ||
} | ||
} | ||
return resultElements; | ||
} | ||
|
||
/// <summary> | ||
/// Apply Interior Partition Types edit overrides to a collection of existing elements | ||
/// </summary> | ||
/// <param name="existingElements">A collection of existing elements to which to apply the overrides.</param> | ||
/// <param name="overrideData">The Interior Partition Types Overrides to apply — typically `input.Overrides.InteriorPartitionTypes`</param> | ||
/// <param name="identityMatch">A function returning a boolean which indicates whether an element is a match for an override's identity.</param> | ||
/// <param name="modifyElement">A function to modify a matched element, returning the modified element.</param> | ||
/// <typeparam name="T">The element type this override applies to. Should match the type(s) in the override's context.</typeparam> | ||
/// <returns>A collection of elements, including unmodified and modified elements from the supplied collection.</returns> | ||
public static void ApplyOverrides<T>( | ||
this List<T> existingElements, | ||
IList<InteriorPartitionTypesOverride> overrideData, | ||
Func<T, InteriorPartitionTypesIdentity, bool> identityMatch, | ||
Func<T, InteriorPartitionTypesOverride, T> modifyElement | ||
) where T : Element | ||
{ | ||
var updatedElements = overrideData.Apply(existingElements, identityMatch, modifyElement); | ||
existingElements.Clear(); | ||
existingElements.AddRange(updatedElements); | ||
} | ||
|
||
/// <summary> | ||
/// Create elements from add/removeoverrides, and apply any edits. | ||
/// </summary> | ||
/// <param name="edits">The collection of edit overrides (Overrides.InteriorPartitionTypes)</param> | ||
/// <param name="additions">The collection of add overrides (Overrides.Additions.InteriorPartitionTypes)</param> | ||
/// <param name="removals">The collection of remove overrides (Overrides.Removals.InteriorPartitionTypes)</param> /// <param name="identityMatch">A function returning a boolean which indicates whether an element is a match for an override's identity.</param> | ||
/// <param name="createElement">A function to create a new element, returning the created element.</param> | ||
/// <param name="modifyElement">A function to modify a matched element, returning the modified element.</param> | ||
/// <param name="existingElements">An optional collection of existing elements to which to apply any edit overrides, or remove if remove overrides are found.</param> | ||
/// <typeparam name="T">The element type this override applies to. Should match the type(s) in the override's context.</typeparam> | ||
/// <returns>A collection of elements, including new, unmodified, and modified elements from the supplied collection.</returns> | ||
public static List<T> CreateElements<T>( | ||
this IList<InteriorPartitionTypesOverride> edits, | ||
IList<InteriorPartitionTypesOverrideAddition> additions, | ||
IList<InteriorPartitionTypesOverrideRemoval> removals, Func<InteriorPartitionTypesOverrideAddition, T> createElement, | ||
Func<T, InteriorPartitionTypesIdentity, bool> identityMatch, | ||
Func<T, InteriorPartitionTypesOverride, T> modifyElement, | ||
IEnumerable<T> existingElements = null | ||
) where T : Element | ||
{ | ||
List<T> resultElements = existingElements == null ? new List<T>() : new List<T>(existingElements); | ||
if (removals != null) | ||
{ | ||
foreach (var removedElement in removals) | ||
{ | ||
var elementToRemove = resultElements.FirstOrDefault(e => identityMatch(e, removedElement.Identity)); | ||
if (elementToRemove != null) | ||
{ | ||
resultElements.Remove(elementToRemove); | ||
} | ||
} | ||
} if (additions != null) | ||
{ | ||
foreach (var addedElement in additions) | ||
{ | ||
var elementToAdd = createElement(addedElement); | ||
resultElements.Add(elementToAdd); | ||
Identity.AddOverrideIdentity(elementToAdd, addedElement); | ||
} | ||
} | ||
if (edits != null) | ||
{ | ||
foreach (var editedElement in edits) | ||
{ | ||
var elementToEdit = resultElements.FirstOrDefault(e => identityMatch(e, editedElement.Identity)); | ||
if (elementToEdit != null) | ||
{ | ||
resultElements.Remove(elementToEdit); | ||
var newElement = modifyElement(elementToEdit, editedElement); | ||
resultElements.Add(newElement); | ||
Identity.AddOverrideIdentity(newElement, editedElement); | ||
} | ||
} | ||
} | ||
return resultElements; | ||
} | ||
|
||
} | ||
|
||
|
||
} |
32 changes: 32 additions & 0 deletions
32
LayoutFunctions/InteriorPartitions/dependencies/InteriorPartitionTypesOverrideAddition.g.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Elements; | ||
using System.Collections.Generic; | ||
using System; | ||
using System.Linq; | ||
|
||
namespace InteriorPartitions | ||
{ | ||
/// <summary> | ||
/// Override metadata for InteriorPartitionTypesOverrideAddition | ||
/// </summary> | ||
public partial class InteriorPartitionTypesOverrideAddition : IOverride | ||
{ | ||
public static string Name = "Interior Partition Types Addition"; | ||
public static string Dependency = null; | ||
public static string Context = "[*discriminator=Elements.WallCandidate]"; | ||
public static string Paradigm = "Edit"; | ||
|
||
/// <summary> | ||
/// Get the override name for this override. | ||
/// </summary> | ||
public string GetName() { | ||
return Name; | ||
} | ||
|
||
public object GetIdentity() { | ||
|
||
return Identity; | ||
} | ||
|
||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
LayoutFunctions/InteriorPartitions/dependencies/InteriorPartitionTypesOverrideRemoval.g.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Elements; | ||
using System.Collections.Generic; | ||
using System; | ||
using System.Linq; | ||
|
||
namespace InteriorPartitions | ||
{ | ||
/// <summary> | ||
/// Override metadata for InteriorPartitionTypesOverrideRemoval | ||
/// </summary> | ||
public partial class InteriorPartitionTypesOverrideRemoval : IOverride | ||
{ | ||
public static string Name = "Interior Partition Types Removal"; | ||
public static string Dependency = null; | ||
public static string Context = "[*discriminator=Elements.WallCandidate]"; | ||
public static string Paradigm = "Edit"; | ||
|
||
/// <summary> | ||
/// Get the override name for this override. | ||
/// </summary> | ||
public string GetName() { | ||
return Name; | ||
} | ||
|
||
public object GetIdentity() { | ||
|
||
return Identity; | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.