private static void SetCoBieAttributeValue <TCoBieValueBaseType>(TCoBieValueBaseType result, IfcValue ifcValue) where TCoBieValueBaseType : AttributeValue { var stringValueType = result as StringAttributeValue; var decimalValueType = result as DecimalAttributeValue; var booleanValueType = result as BooleanAttributeValue; var integerValueType = result as IntegerAttributeValue; if (stringValueType != null) { stringValueType.Value = ifcValue.ToString(); } else if (decimalValueType != null) { try { decimalValueType.Value = Convert.ToDouble(ifcValue.Value); } catch (ArgumentNullException) { //CoBieLiteUkHelper.Logger.WarnFormat("Decimal Conversion: String is null."); } catch (FormatException) { //CoBieLiteUkHelper.Logger.WarnFormat("Decimal Conversion: String does not consist of an " + "optional sign followed by a series of digits."); } catch (OverflowException) { //CoBieLiteUkHelper.Logger.WarnFormat("Decimal Conversion: Overflow in string to int conversion."); } } else if (booleanValueType != null) { try { booleanValueType.Value = Convert.ToBoolean(ifcValue.Value); } catch (ArgumentNullException) { //CoBieLiteUkHelper.Logger.WarnFormat("Boolean Conversion: String is null."); } catch (FormatException) { //CoBieLiteUkHelper.Logger.WarnFormat("Boolean Conversion: String does not consist of an " + "optional sign followed by a series of digits."); } catch (OverflowException) { //CoBieLiteUkHelper.Logger.WarnFormat("Boolean Conversion: Overflow in string to int conversion."); } } else if (integerValueType != null) { try { //this looks like an error in COBieLite, suggest should be same as Decimal and Boolean integerValueType.Value = Convert.ToInt32(ifcValue.Value); } catch (ArgumentNullException) { //CoBieLiteUkHelper.Logger.WarnFormat("Integer Conversion: String is null."); } catch (FormatException) { //CoBieLiteUkHelper.Logger.WarnFormat("Integer Conversion: String does not consist of an " + // "optional sign followed by a series of digits."); } catch (OverflowException) { //CoBieLiteUkHelper.Logger.WarnFormat("Integer Conversion: Overflow in string to int conversion."); } } else { CoBieLiteUkHelper.Logger.Warn("Unexpected ValueBaseType"); } }
static public AttributeValueType GetAttributeValueType(IfcPropertySingleValue ifcProperty) { IfcValue ifcValue = ifcProperty.NominalValue; var attributeValueType = new AttributeValueType(); if (ifcValue == null) { return(null); } if (ifcValue is IfcMonetaryMeasure) { attributeValueType.ItemElementName = ItemChoiceType.AttributeMonetaryValue; var monetaryValue = new AttributeMonetaryValueType { MonetaryValue = Convert.ToDecimal((double)ifcValue.Value) }; attributeValueType.Item = monetaryValue; if (ifcProperty.Unit is IfcMonetaryUnit) { var mu = ifcProperty.Unit as IfcMonetaryUnit; CurrencyUnitSimpleType cu; if (Enum.TryParse(mu.Currency.ToString(), true, out cu)) { monetaryValue.MonetaryUnit = cu; } else { CoBieLiteHelper.Logger.WarnFormat("Invalid monetary unit: {0} ", mu.Currency); } } } else if (ifcValue is IfcTimeStamp) { attributeValueType.ItemElementName = ItemChoiceType.AttributeDateTimeValue; var timeStamp = (IfcTimeStamp)ifcValue; attributeValueType.Item = IfcTimeStamp.ToDateTime(timeStamp); } else if (ifcValue.UnderlyingSystemType == typeof(int) || ifcValue.UnderlyingSystemType == typeof(long) || ifcValue.UnderlyingSystemType == typeof(short) || ifcValue.UnderlyingSystemType == typeof(byte)) { var integerValue = new AttributeIntegerValueType { IntegerValue = Convert.ToInt32(ifcValue.Value) }; attributeValueType.Item = integerValue; attributeValueType.ItemElementName = ItemChoiceType.AttributeIntegerValue; } else if (ifcValue.UnderlyingSystemType == typeof(double) || ifcValue.UnderlyingSystemType == typeof(float)) { var decimalValue = new AttributeDecimalValueType { DecimalValue = (double)ifcValue.Value, DecimalValueSpecified = true }; attributeValueType.Item = decimalValue; attributeValueType.ItemElementName = ItemChoiceType.AttributeDecimalValue; } else if (ifcValue.UnderlyingSystemType == typeof(string)) { var stringValue = new AttributeStringValueType { StringValue = ifcValue.ToString() }; attributeValueType.Item = stringValue; attributeValueType.ItemElementName = ItemChoiceType.AttributeStringValue; } else if (ifcValue.UnderlyingSystemType == typeof(bool) || ifcValue.UnderlyingSystemType == typeof(bool?)) { var boolValue = new BooleanValueType(); if (ifcValue.Value != null && (bool)ifcValue.Value) { var theBool = (bool)ifcValue.Value; boolValue.BooleanValue = theBool; boolValue.BooleanValueSpecified = true; } attributeValueType.Item = boolValue; attributeValueType.ItemElementName = ItemChoiceType.AttributeBooleanValue; } else { attributeValueType = null; } return(attributeValueType); }
/// <summary> /// Fill sheet rows for Facility sheet /// </summary> /// <returns>COBieSheet</returns> public override COBieSheet <COBieFacilityRow> Fill() { ProgressIndicator.ReportMessage("Starting Facilities..."); //Create new sheet COBieSheet <COBieFacilityRow> facilities = new COBieSheet <COBieFacilityRow>(Constants.WORKSHEET_FACILITY); IfcProject ifcProject = Model.IfcProject as IfcProject; IfcSite ifcSite = Model.Instances.OfType <IfcSite>().FirstOrDefault(); IfcBuilding ifcBuilding = Model.Instances.OfType <IfcBuilding>().FirstOrDefault(); //get Element Quantity holding area values as used for AreaMeasurement below IfcElementQuantity ifcElementQuantityAreas = Model.Instances.OfType <IfcElementQuantity>().Where(eq => eq.Quantities.OfType <IfcQuantityArea>().Count() > 0).FirstOrDefault(); List <IfcObject> ifcObjectList = new List <IfcObject>(); if (ifcProject != null) { ifcObjectList.Add(ifcProject); } if (ifcSite != null) { ifcObjectList.Add(ifcSite); } if (ifcBuilding != null) { ifcObjectList.Add(ifcBuilding); } IEnumerable <IfcObject> ifcObjects = ifcObjectList.AsEnumerable(); if (ifcObjects.Any()) { COBieDataPropertySetValues allPropertyValues = new COBieDataPropertySetValues(); //properties helper class COBieDataAttributeBuilder attributeBuilder = new COBieDataAttributeBuilder(Context, allPropertyValues); attributeBuilder.InitialiseAttributes(ref _attributes); //list of attributes to exclude form attribute sheet //set up filters on COBieDataPropertySetValues for the SetAttributes only attributeBuilder.ExcludeAttributePropertyNames.AddRange(Context.Exclude.Facility.AttributesEqualTo); attributeBuilder.ExcludeAttributePropertyNamesWildcard.AddRange(Context.Exclude.Facility.AttributesContain); attributeBuilder.RowParameters["Sheet"] = "Facility"; COBieFacilityRow facility = new COBieFacilityRow(facilities); string name = ""; if ((ifcBuilding != null) && (!string.IsNullOrEmpty(ifcBuilding.Name))) { name = ifcBuilding.Name; } else if ((ifcSite != null) && (!string.IsNullOrEmpty(ifcSite.Name))) { name = ifcSite.Name; } else if ((ifcProject != null) && (!string.IsNullOrEmpty(ifcProject.Name))) { name = ifcProject.Name; } else { name = DEFAULT_STRING; } facility.Name = (string.IsNullOrEmpty(name)) ? "The Facility Name Here" : name; IfcValue createBy = ifcBuilding.GetPropertySingleNominalValue("Other", "COBieCreatedBy"); //support for COBie Toolkit for Autodesk Revit facility.CreatedBy = ((createBy != null) && ValidateString(createBy.ToString())) ? createBy.ToString() : GetTelecomEmailAddress(ifcBuilding.OwnerHistory); IfcValue createdOn = ifcBuilding.GetPropertySingleNominalValue("Other", "COBieCreatedOn"); //support for COBie Toolkit for Autodesk Revit facility.CreatedOn = ((createdOn != null) && ValidateString(createdOn.ToString())) ? createdOn.ToString() : GetCreatedOnDateAsFmtString(ifcBuilding.OwnerHistory); facility.Category = GetCategory(ifcBuilding); facility.ProjectName = GetFacilityProjectName(ifcProject); facility.SiteName = GetFacilitySiteName(ifcSite); facility.LinearUnits = Context.WorkBookUnits.LengthUnit; facility.AreaUnits = Context.WorkBookUnits.AreaUnit; facility.VolumeUnits = Context.WorkBookUnits.VolumeUnit; facility.CurrencyUnit = Context.WorkBookUnits.MoneyUnit; string AreaMeasurement = (ifcElementQuantityAreas == null) ? DEFAULT_STRING : ifcElementQuantityAreas.MethodOfMeasurement.ToString(); facility.AreaMeasurement = ((AreaMeasurement == DEFAULT_STRING) || (AreaMeasurement.ToLower().Contains("bim area"))) ? AreaMeasurement : AreaMeasurement + " BIM Area"; facility.ExternalSystem = GetExternalSystem(ifcBuilding); facility.ExternalProjectObject = "IfcProject"; facility.ExternalProjectIdentifier = ifcProject.GlobalId; facility.ExternalSiteObject = "IfcSite"; facility.ExternalSiteIdentifier = (ifcSite != null) ? ifcSite.GlobalId.ToString() : DEFAULT_STRING; facility.ExternalFacilityObject = "IfcBuilding"; facility.ExternalFacilityIdentifier = ifcBuilding.GlobalId; facility.Description = GetFacilityDescription(ifcBuilding); facility.ProjectDescription = GetFacilityProjectDescription(ifcProject); facility.SiteDescription = GetFacilitySiteDescription(ifcSite); facility.Phase = (string.IsNullOrEmpty(Model.IfcProject.Phase.ToString())) ? DEFAULT_STRING : Model.IfcProject.Phase.ToString(); facilities.AddRow(facility); //fill in the attribute information foreach (IfcObject ifcObject in ifcObjects) { attributeBuilder.RowParameters["Name"] = facility.Name; attributeBuilder.RowParameters["CreatedBy"] = facility.CreatedBy; attributeBuilder.RowParameters["CreatedOn"] = facility.CreatedOn; attributeBuilder.RowParameters["ExtSystem"] = facility.ExternalSystem; attributeBuilder.PopulateAttributesRows(ifcObject); //fill attribute sheet rows//pass data from this sheet info as Dictionary } } facilities.OrderBy(s => s.Name); ProgressIndicator.Finalise(); return(facilities); }
public override string ToString() { return(string.Format("{0} {1}", _nominalValue == null ? "" : _nominalValue.ToString(), _unit == null ? "" : _unit.ToString())); }
/// <summary> /// format the IfcValue if a number, if not just get the string value. append/prepend the unit string to the value depending on unit type /// </summary> /// <param name="ifcValue">IfcValue</param> /// <param name="unit">string holding unit</param> /// <param name="moneyUnit">bool true if a money value</param> /// <returns></returns> public static string FormatIfcValue(IfcValue ifcValue, string unit, bool moneyUnit) { string numberFormat = "{0,0:N2}"; string value = string.Empty; if (ifcValue.UnderlyingSystemType == typeof(double)) value = string.Format(numberFormat, double.Parse(ifcValue.ToString())); else if (ifcValue.UnderlyingSystemType == typeof(string)) return ConvertUrlsToLinks(ifcValue.ToString()); else return ifcValue.ToString(); //add the unit if (moneyUnit) return unit + value; else return value + unit; }