Extension methods for SnapPoint to simplify querying connected components. More...
Static Public Member Functions | |
| static IEnumerable< T > | GetConnectedComponents< T > (this SnapPoint snapPoint) |
| Gets all connected components of the specified type from a snap point. | |
| static T | GetFirstConnected< T > (this SnapPoint snapPoint) |
| Gets the first connected component of the specified type, or null if none found. | |
| static bool | HasConnections (this SnapPoint snapPoint) |
| Checks if the snap point has any connections (mate or mates). | |
| static bool | AnyConnected< T > (this SnapPoint snapPoint, System.Func< T, bool > predicate) |
| Checks if any connected component of type T satisfies a condition. | |
Detailed Description
Extension methods for SnapPoint to simplify querying connected components.
These extension methods provide a fluent, LINQ-friendly API for working with snap point connections. They handle both single mate and multiple mates scenarios transparently, making it easy to query connected components.
Key Features:
- Query connected components by type with GetConnectedComponents<T>()
- Check for any connections with HasConnections()
- Get first connected component with GetFirstConnected<T>()
- LINQ-compatible IEnumerable results
- Null-safe implementations
Usage Example: // Check if any connected conveyor is occupied bool anyOccupied = snapOut.GetConnectedComponents<IPalletHandling>() .Any(h => h.GetOccupied());
// Get all connected conveyors var conveyors = snapOut.GetConnectedComponents<PalletConveyor>().ToList();
// Quick connection check if (snapIn.HasConnections()) { // Has predecessors }
Member Function Documentation
◆ AnyConnected< T >()
|
static |
Checks if any connected component of type T satisfies a condition.
Convenience method combining GetConnectedComponents with a predicate check. More efficient than ToList().Any() since it uses deferred execution.
- Template Parameters
-
T The component type to search for
- Parameters
-
snapPoint The snap point to query for connections predicate The condition to test each connected component against
- Returns
- True if any connected component of type T satisfies the predicate
Example:
- Type Constraints
-
T : class
◆ GetConnectedComponents< T >()
|
static |
Gets all connected components of the specified type from a snap point.
This method traverses both single mate and multiple mates connections, searching for components of type T in the parent hierarchy of each connected snap point. Returns an IEnumerable for LINQ compatibility.
- Template Parameters
-
T The component type to search for (e.g., IPalletHandling, Drive, Sensor)
- Parameters
-
snapPoint The snap point to query for connections
- Returns
- An enumerable of all connected components of type T (may be empty)
Example:
- Type Constraints
-
T : class
◆ GetFirstConnected< T >()
|
static |
Gets the first connected component of the specified type, or null if none found.
Convenience method for when you only need the first connected component or know there should only be one connection.
- Template Parameters
-
T The component type to search for
- Parameters
-
snapPoint The snap point to query for connections
- Returns
- The first connected component of type T, or null if none found
Example:
- Type Constraints
-
T : class
◆ HasConnections()
|
static |
Checks if the snap point has any connections (mate or mates).
Quick boolean check for whether a snap point is connected to anything. More efficient than checking GetConnectedComponents().Any() since it doesn't need to traverse the component hierarchy.
- Parameters
-
snapPoint The snap point to check
- Returns
- True if the snap point has at least one connection, false otherwise
Example: