コード例 #1
0
        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);
        }
コード例 #2
0
        public static AttributeValueType GetAttributeValueType(IIfcPropertySingleValue ifcProperty)
        {
            IIfcValue ifcValue           = ifcProperty.NominalValue;
            var       attributeValueType = new AttributeValueType();

            if (ifcValue == null)
            {
                return(null);
            }
            var expressValue   = (IExpressValueType)ifcValue;
            var underlyingType = expressValue.UnderlyingSystemType;

            if (ifcValue is Xbim.Ifc4.MeasureResource.IfcMonetaryMeasure)
            {
                attributeValueType.ItemElementName = ItemChoiceType.AttributeMonetaryValue;
                var monetaryValue = new AttributeMonetaryValueType
                {
                    MonetaryValue = Convert.ToDecimal((double)expressValue.Value)
                };
                attributeValueType.Item = monetaryValue;
                if (!(ifcProperty.Unit is IIfcMonetaryUnit))
                {
                    return(attributeValueType);
                }
                var mu = (IIfcMonetaryUnit)ifcProperty.Unit;
                CurrencyUnitSimpleType cu;
                if (Enum.TryParse(mu.Currency.ToString(), true, out cu))
                {
                    monetaryValue.MonetaryUnit = cu;
                }
                else
                {
                    logger.LogWarning("Invalid monetary unit: {currency} ", mu.Currency);
                }
            }
            else if (ifcValue is Xbim.Ifc4.DateTimeResource.IfcTimeStamp)
            {
                attributeValueType.ItemElementName = ItemChoiceType.AttributeDateTimeValue;
                var timeStamp = (Xbim.Ifc4.DateTimeResource.IfcTimeStamp)ifcValue;
                attributeValueType.Item = timeStamp.ToDateTime();
            }
            else if (underlyingType == typeof(int) || underlyingType == typeof(long) || underlyingType == typeof(short) || underlyingType == typeof(byte))
            {
                var integerValue = new AttributeIntegerValueType {
                    IntegerValue = Convert.ToInt32(expressValue.Value)
                };
                attributeValueType.Item            = integerValue;
                attributeValueType.ItemElementName = ItemChoiceType.AttributeIntegerValue;
            }
            else if (underlyingType == typeof(double) || underlyingType == typeof(float))
            {
                var decimalValue = new AttributeDecimalValueType {
                    DecimalValue = (double)expressValue.Value, DecimalValueSpecified = true
                };
                attributeValueType.Item            = decimalValue;
                attributeValueType.ItemElementName = ItemChoiceType.AttributeDecimalValue;
            }
            else if (underlyingType == typeof(string))
            {
                var stringValue = new AttributeStringValueType {
                    StringValue = ifcValue.ToString()
                };
                attributeValueType.Item            = stringValue;
                attributeValueType.ItemElementName = ItemChoiceType.AttributeStringValue;
            }
            else if (underlyingType == typeof(bool) || underlyingType == typeof(bool?))
            {
                var boolValue = new BooleanValueType();
                if (expressValue.Value != null && (bool)expressValue.Value)
                {
                    var theBool = (bool)expressValue.Value;
                    boolValue.BooleanValue          = theBool;
                    boolValue.BooleanValueSpecified = true;
                }
                attributeValueType.Item            = boolValue;
                attributeValueType.ItemElementName = ItemChoiceType.AttributeBooleanValue;
            }
            else
            {
                attributeValueType = null;
            }
            return(attributeValueType);
        }