/// <summary>
        ///
        /// </summary>
        /// <param name="ifcProperty"></param>
        /// <returns></returns>
        static public AttributeValue GetAttributeValueType(IfcPropertySingleValue ifcProperty)
        {
            var ifcValue = ifcProperty.NominalValue;

            if (ifcValue == null)
            {
                return(null);
            }
            if (ifcValue is IfcMonetaryMeasure)
            {
                var moneyAttribute = new DecimalAttributeValue {
                    Value = (double)ifcValue.Value
                };
                if (ifcProperty.Unit is IfcMonetaryUnit)
                {
                    var mu = ifcProperty.Unit as IfcMonetaryUnit;
                    moneyAttribute.Unit = mu.ToString();
                }
            }
            else if (ifcValue is IfcTimeStamp)
            {
                var timeStamp = (IfcTimeStamp)ifcValue;
                return(new DateTimeAttributeValue {
                    Value = IfcTimeStamp.ToDateTime(timeStamp)
                });
            }
            else if (ifcValue.UnderlyingSystemType == typeof(int) || ifcValue.UnderlyingSystemType == typeof(long) || ifcValue.UnderlyingSystemType == typeof(short) || ifcValue.UnderlyingSystemType == typeof(byte))
            {
                return(new IntegerAttributeValue {
                    Value = Convert.ToInt32(ifcValue.Value)
                });
            }
            else if (ifcValue.UnderlyingSystemType == typeof(double) || ifcValue.UnderlyingSystemType == typeof(float))
            {
                return(new DecimalAttributeValue {
                    Value = (double)ifcValue.Value
                });
            }
            else if (ifcValue.UnderlyingSystemType == typeof(string))
            {
                return(new StringAttributeValue {
                    Value = ifcValue.ToString()
                });
            }
            else if (ifcValue.UnderlyingSystemType == typeof(bool) || ifcValue.UnderlyingSystemType == typeof(bool?))
            {
                if (ifcValue.Value != null && (bool)ifcValue.Value)
                {
                    return(new BooleanAttributeValue {
                        Value = (bool)ifcValue.Value
                    });
                }
                return(new BooleanAttributeValue());//return an undefined
            }

            return(null);
        }
Example #2
0
        public static string GetCreatedOnDate(IIfcOwnerHistory ownerHistory)
        {
            if (ownerHistory != null)
            {
                var createdOnTStamp = (int)ownerHistory.CreationDate;
                if (createdOnTStamp != 0) //assume not set, but could it be 1970/1/1 00:00:00!!!
                {
                    //to remove trailing decimal seconds use a set format string as "o" option is to long.

                    //We have a day light saving problem with the comparison with other COBie Export Programs. if we convert to local time we get a match
                    //but if the time stamp is Coordinated Universal Time (UTC), then daylight time should be ignored. see http://msdn.microsoft.com/en-us/library/bb546099.aspx
                    //IfcTimeStamp.ToDateTime(CreatedOnTStamp).ToLocalTime()...; //test to see if corrects 1 hour difference, and yes it did, but should we?

                    return(IfcTimeStamp.ToDateTime(createdOnTStamp).ToString(Constants.DATETIME_FORMAT));
                }
            }
            return(null);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="ifcProperty"></param>
        /// <typeparam name="TValue"></typeparam>
        /// <returns></returns>
        static public TValue ConvertToSimpleType <TValue>(IfcPropertySingleValue ifcProperty) where TValue : struct
        {
            IfcValue ifcValue = ifcProperty.NominalValue;
            var      value    = new TValue();

            if (ifcValue is IfcMonetaryMeasure)
            {
                value = (TValue)Convert.ChangeType(ifcValue.Value, typeof(TValue));
            }
            else if (ifcValue is IfcTimeStamp)
            {
                var timeStamp = (IfcTimeStamp)ifcValue;
                value = (TValue)Convert.ChangeType(IfcTimeStamp.ToDateTime(timeStamp), typeof(TValue));
            }
            else if (value is DateTime) //sometimes these are written as strings in the ifc file
            {
                value = (TValue)Convert.ChangeType(ReadDateTime(ifcValue.Value.ToString()), typeof(TValue));
            }
            else if (ifcValue.UnderlyingSystemType == typeof(int) || ifcValue.UnderlyingSystemType == typeof(long) || ifcValue.UnderlyingSystemType == typeof(short) || ifcValue.UnderlyingSystemType == typeof(byte))
            {
                value = (TValue)Convert.ChangeType(ifcValue.Value, typeof(TValue));
            }
            else if (ifcValue.UnderlyingSystemType == typeof(double) || ifcValue.UnderlyingSystemType == typeof(float))
            {
                value = (TValue)Convert.ChangeType(ifcValue.Value, typeof(TValue));
            }
            else if (ifcValue.UnderlyingSystemType == typeof(string))
            {
                value = (TValue)Convert.ChangeType(ifcValue.Value, typeof(TValue));
            }
            else if (ifcValue.UnderlyingSystemType == typeof(bool) || ifcValue.UnderlyingSystemType == typeof(bool?))
            {
                if (ifcValue != null)
                {
                    value = (TValue)Convert.ChangeType(ifcValue.Value, typeof(TValue));
                }
            }
            return(value);
        }
        private string ConvertToString(IfcPropertySingleValue ifcProperty)
        {
            IfcValue ifcValue = ifcProperty.NominalValue;

            if (ifcValue == null)
            {
                return(null);
            }
            if (ifcValue is IfcTimeStamp)
            {
                var timeStamp = (IfcTimeStamp)ifcValue;
                return(WriteDateTime(IfcTimeStamp.ToDateTime(timeStamp)));
            }
            if (ifcValue.UnderlyingSystemType == typeof(bool) || ifcValue.UnderlyingSystemType == typeof(bool?))
            {
                if (ifcValue.Value != null && (bool)ifcValue.Value)
                {
                    return("yes");
                }
                return("no");
            }
            // all other cases will convert to a string
            return(ifcValue.Value.ToString());
        }
        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);
        }