コード例 #1
0
        private static void SetCoBieAttributeValue <TCoBieValueBaseType>(TCoBieValueBaseType result, IIfcValue ifcValue) where TCoBieValueBaseType : ValueBaseType
        {
            var stringValueType  = result as StringValueType;
            var decimalValueType = result as DecimalValueType;
            var booleanValueType = result as BooleanValueType;
            var integerValueType = result as IntegerValueType;
            var expressValue     = (IExpressValueType)ifcValue;

            if (stringValueType != null)
            {
                stringValueType.StringValue = ifcValue.ToString();
            }
            else if (decimalValueType != null)
            {
                try
                {
                    decimalValueType.DecimalValue          = Convert.ToDouble(expressValue.Value);
                    decimalValueType.DecimalValueSpecified = true;
                }
                catch (ArgumentNullException)
                {
                    logger.LogWarning("Decimal Conversion: String is null.");
                }
                catch (FormatException)
                {
                    logger.LogWarning("Decimal Conversion: value {strValue} is not correctly formatted", expressValue.Value);
                }
                catch (OverflowException)
                {
                    logger.LogWarning("Decimal Conversion: Overflow in string to decimal conversion.");
                }
            }
            else if (booleanValueType != null)
            {
                try
                {
                    booleanValueType.BooleanValue          = Convert.ToBoolean(expressValue.Value);
                    booleanValueType.BooleanValueSpecified = true;
                }
                catch (ArgumentNullException)
                {
                    logger.LogWarning("Boolean Conversion: String is null.");
                }
                catch (FormatException)
                {
                    logger.LogWarning("Boolean Conversion: value {strValue} is not correctly formatted", expressValue.Value);
                }
            }
            else if (integerValueType != null)
            {
                try
                {
                    //this looks like an error in COBieLite, suggest should be same as Decimal and Boolean
                    integerValueType.IntegerValue = Convert.ToInt32(expressValue.Value);
                }
                catch (ArgumentNullException)
                {
                    logger.LogWarning("Integer Conversion: String is null.");
                }
                catch (FormatException)
                {
                    logger.LogWarning("Integer Conversion: value {strValue} is not correctly formatted", expressValue.Value);
                }
                catch (OverflowException)
                {
                    logger.LogWarning("Integer Conversion: Overflow in string to int conversion.");
                }
            }
            else
            {
                logger.LogWarning("Unexpected ValueBaseType {valueType}", ifcValue);
            }
        }
コード例 #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);
        }
コード例 #3
0
        private static void SetCoBieAttributeValue <TCoBieValueBaseType>(TCoBieValueBaseType result, IIfcValue ifcValue) where TCoBieValueBaseType : ValueBaseType
        {
            var stringValueType  = result as StringValueType;
            var decimalValueType = result as DecimalValueType;
            var booleanValueType = result as BooleanValueType;
            var integerValueType = result as IntegerValueType;
            var expressValue     = (IExpressValueType)ifcValue;

            if (stringValueType != null)
            {
                stringValueType.StringValue = ifcValue.ToString();
            }
            else if (decimalValueType != null)
            {
                try
                {
                    decimalValueType.DecimalValue          = Convert.ToDouble(expressValue.Value);
                    decimalValueType.DecimalValueSpecified = true;
                }
                catch (ArgumentNullException)
                {
                    CoBieLiteHelper.Logger.WarnFormat("Decimal Conversion: String is null.");
                }
                catch (FormatException)
                {
                    CoBieLiteHelper.Logger.WarnFormat("Decimal Conversion: String does not consist of an " + "optional sign followed by a series of digits.");
                }
                catch (OverflowException)
                {
                    CoBieLiteHelper.Logger.WarnFormat("Decimal Conversion: Overflow in string to int conversion.");
                }
            }
            else if (booleanValueType != null)
            {
                try
                {
                    booleanValueType.BooleanValue          = Convert.ToBoolean(expressValue.Value);
                    booleanValueType.BooleanValueSpecified = true;
                }
                catch (ArgumentNullException)
                {
                    CoBieLiteHelper.Logger.WarnFormat("Boolean Conversion: String is null.");
                }
                catch (FormatException)
                {
                    CoBieLiteHelper.Logger.WarnFormat("Boolean Conversion: String does not consist of an " + "optional sign followed by a series of digits.");
                }
                catch (OverflowException)
                {
                    CoBieLiteHelper.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.IntegerValue = Convert.ToInt32(expressValue.Value);
                }
                catch (ArgumentNullException)
                {
                    CoBieLiteHelper.Logger.WarnFormat("Integer Conversion: String is null.");
                }
                catch (FormatException)
                {
                    CoBieLiteHelper.Logger.WarnFormat("Integer Conversion: String does not consist of an " +
                                                      "optional sign followed by a series of digits.");
                }
                catch (OverflowException)
                {
                    CoBieLiteHelper.Logger.WarnFormat("Integer Conversion: Overflow in string to int conversion.");
                }
            }
            else
            {
                CoBieLiteHelper.Logger.Warn("Unexpected ValueBaseType");
            }
        }