private IEnumerable <ValidationResult> CheckCostItems(IModel model) { foreach (var item in model.Instances.OfType <IIfcCostItem>()) { var err = new ValidationResult { IssueSource = "Template Types and Units validation", Item = item, IssueType = ValidationFlags.Properties }; var quantType = item.CostQuantities.FirstOrDefault()?.ExpressType; if (quantType != null && !item.CostQuantities.All(q => q.ExpressType == quantType)) { var types = item.CostQuantities.Select(q => q.ExpressType.Name).Distinct(); err.AddDetail(new ValidationResult { Item = item, IssueType = ValidationFlags.Properties, IssueSource = "Same quantity type validation", Message = $"Quantities must be of the same type. Types: {string.Join(", ", types)}" }); } var noUnits = item.CostQuantities.OfType <IIfcPhysicalSimpleQuantity>() .Select(q => new Quantity(q)) .Where(q => q.Unit == null && q.Type != QuantityTypeEnum.Count) .ToList(); if (noUnits.Any()) { err.AddDetail(new ValidationResult { Item = item, IssueType = ValidationFlags.Properties, IssueSource = "Quantity unit defined", Message = $"Quantities should have units either explicit or on the level of the project. Quantities: {string.Join(", ", noUnits.Select(q => q.Name))}" }); } if (err.Details != null && err.Details.Any()) { yield return(err); } } }
private IEnumerable <ValidationResult> CheckPropertyTemplateTypesAndUnits(IModel model) { var templates = model.Instances.OfType <IIfcSimplePropertyTemplate>(); foreach (var property in templates) { if (!property.TemplateType.HasValue) { // if template type is not defined there is no point in validation continue; } var err = new ValidationResult { IssueSource = "Template Types and Units validation", Item = property, IssueType = ValidationFlags.Properties }; ValidationResult detail; switch (property.TemplateType.Value) { case IfcSimplePropertyTemplateTypeEnum.P_SINGLEVALUE: case IfcSimplePropertyTemplateTypeEnum.P_LISTVALUE: if ((detail = CheckMeasureType(property.PrimaryMeasureType, model.Metadata, false)) != null) { err.AddDetail(detail); } if (property.PrimaryUnit != null && (detail = CheckUnit(property.PrimaryMeasureType, property.PrimaryUnit, property)) != null) { err.AddDetail(detail); } break; case IfcSimplePropertyTemplateTypeEnum.P_ENUMERATEDVALUE: if (property.Enumerators == null) { detail = new ValidationResult { Message = "Enumerators must be defined", IssueType = ValidationFlags.Properties }; err.AddDetail(detail); } break; case IfcSimplePropertyTemplateTypeEnum.P_TABLEVALUE: case IfcSimplePropertyTemplateTypeEnum.P_BOUNDEDVALUE: if ((detail = CheckMeasureType(property.PrimaryMeasureType, model.Metadata, false)) != null) { err.AddDetail(detail); } if ((detail = CheckMeasureType(property.SecondaryMeasureType, model.Metadata, false)) != null) { err.AddDetail(detail); } if (property.PrimaryUnit != null && (detail = CheckUnit(property.PrimaryMeasureType, property.PrimaryUnit, property)) != null) { err.AddDetail(detail); } if (property.SecondaryUnit != null && (detail = CheckUnit(property.SecondaryMeasureType, property.SecondaryUnit, property)) != null) { err.AddDetail(detail); } break; case IfcSimplePropertyTemplateTypeEnum.P_REFERENCEVALUE: if ((detail = CheckMeasureType(property.PrimaryMeasureType, model.Metadata, true)) != null) { err.AddDetail(detail); } break; case IfcSimplePropertyTemplateTypeEnum.Q_LENGTH: case IfcSimplePropertyTemplateTypeEnum.Q_AREA: case IfcSimplePropertyTemplateTypeEnum.Q_VOLUME: case IfcSimplePropertyTemplateTypeEnum.Q_COUNT: case IfcSimplePropertyTemplateTypeEnum.Q_WEIGHT: case IfcSimplePropertyTemplateTypeEnum.Q_TIME: default: break; } if (err.Details != null && err.Details.Any()) { yield return(err); } } }
private IEnumerable <ValidationResult> CheckPropertyUnits(IModel model) { var properties = model.Instances.OfType <IIfcSimpleProperty>(); foreach (var property in properties) { var err = new ValidationResult { IssueSource = "Template Types and Units validation", Item = property, IssueType = ValidationFlags.Properties }; ValidationResult detail; if (property is IIfcPropertySingleValue single) { if (single.NominalValue == null) { continue; } if ((detail = CheckUnit(single.NominalValue.GetType().Name, single.Unit, property)) != null) { err.AddDetail(detail); } continue; } if (property is IIfcPropertyListValue list) { if (list.ListValues.FirstOrDefault() == null) { continue; } if ((detail = CheckUnit(list.ListValues.FirstOrDefault().GetType().Name, list.Unit, property)) != null) { err.AddDetail(detail); } continue; } if (property is IIfcPropertyBoundedValue bounded) { if (bounded.UpperBoundValue != null) { if ((detail = CheckUnit(bounded.UpperBoundValue.GetType().Name, bounded.Unit, property)) != null) { err.AddDetail(detail); } } if (bounded.SetPointValue != null) { if ((detail = CheckUnit(bounded.SetPointValue.GetType().Name, bounded.Unit, property)) != null) { err.AddDetail(detail); } } if (bounded.LowerBoundValue != null) { if ((detail = CheckUnit(bounded.LowerBoundValue.GetType().Name, bounded.Unit, property)) != null) { err.AddDetail(detail); } } continue; } if (property is IIfcPropertyTableValue table) { if (table.DefinedValues.FirstOrDefault() != null) { if ((detail = CheckUnit(table.DefinedValues.FirstOrDefault().GetType().Name, table.DefinedUnit, property)) != null) { err.AddDetail(detail); } } if (table.DefiningValues.FirstOrDefault() != null) { if ((detail = CheckUnit(table.DefiningValues.FirstOrDefault().GetType().Name, table.DefiningUnit, property)) != null) { err.AddDetail(detail); } } continue; } if (err.Details != null && err.Details.Any()) { yield return(err); } } }