/// <summary> /// Creates a new instance of the RelationMember class based on the data from RelationInfo object. /// </summary> /// <param name="info">The RelationMemberInfo object that contains data about member.</param> /// <param name="entities">The entities that can be referenced by RelationMember.</param> /// <param name="throwOnMissing">bool value indicating whether references to the missing entity should cause exception.</param> /// <returns>The RelationMember object created from RelationMemberInfo or null if referenced node is missing.</returns> public static RelationMember FromRelationMemberInfo(RelationMemberInfo info, IEntityCollection <IOsmGeometry> entities, bool throwOnMissing) { if (info.MemberType == EntityType.Unknown) { throw new ArgumentException("info.MemberType cannot be EntityType.Unknown"); } if (entities.Contains(info.Reference, info.MemberType) == false) { if (throwOnMissing) { throw new ArgumentException(string.Format("Referenced Entity (ID = {0}, type = {1}) not found in entities collection.", info.Reference, info.MemberType), "info.Reference"); } else { return(null); } } RelationMember result = new RelationMember(entities[info.Reference, info.MemberType], info.Role) { MemberType = info.MemberType }; if (result.Member.EntityType != info.MemberType) { throw new ArgumentException("Type of the referenced entity doesn't match type of the entity in the collection."); } return(result); }
/// <summary> /// Adds or replaces an entity in the given collection. /// </summary> public static void AddOrReplace <T>(this IEntityCollection <T> collection, T entity) where T : Entities.GTFSEntity { if (!collection.Contains(entity)) { collection.Add(entity); } }
/// <summary> /// Adds the diode model that can be used to define minimum constraints. /// </summary> /// <param name="circuit">The circuit.</param> public static void AddRectifyingModel(IEntityCollection circuit) { if (circuit.Contains(DiodeModelName)) { return; } var model = new VoltageSwitchModel(DiodeModelName); model.Parameters.OnResistance = 1e-6; model.Parameters.OffResistance = 1e9; model.Parameters.Hysteresis = 1e-3; model.Parameters.Threshold = 0.0; circuit.Add(model); }
/// <inheritdoc/> public bool Contains(string name) => _entities.Contains(name);
/// <summary> /// Creates a new instance of the RelationMember class based on the data from RelationInfo object. /// </summary> /// <param name="info">The RelationMemberInfo object that contains data about member.</param> /// <param name="entities">The entities that can be referenced by RelationMember.</param> /// <param name="throwOnMissing">bool value indicating whether references to the missing entity should cause exception.</param> /// <returns>The RelationMember object created from RelationMemberInfo or null if referenced node is missing.</returns> public static RelationMember FromRelationMemberInfo(RelationMemberInfo info, IEntityCollection<IOsmGeometry> entities, bool throwOnMissing) { if (info.MemberType == EntityType.Unknown) { throw new ArgumentException("info.MemberType cannot be EntityType.Unknown"); } if (entities.Contains(info.Reference, info.MemberType) == false) { if (throwOnMissing) { throw new ArgumentException(string.Format("Referenced Entity (ID = {0}, type = {1}) not found in entities collection.", info.Reference, info.MemberType), "info.Reference"); } else { return null; } } RelationMember result = new RelationMember(entities[info.Reference, info.MemberType], info.Role) { MemberType = info.MemberType }; if (result.Member.EntityType != info.MemberType) { throw new ArgumentException("Type of the referenced entity doesn't match type of the entity in the collection."); } return result; }