コード例 #1
0
        static public AttributeType ConvertToAttributeType(IfcProperty ifcProperty)
        {
            var attributeType = new AttributeType
            {
                AttributeDescription = ifcProperty.Description,
                AttributeName        = ifcProperty.Name,
                AttributeCategory    = "Submitted"

                                       //srl we need to define categories, the schema proposes "As Built|Submitted|Approved|Exact Requirement|Maximum Requirement|Minimum Requirement|Requirement", should DPoW set requirements?
            };


            var ifcPropertySingleValue     = ifcProperty as IfcPropertySingleValue;
            var ifcPropertyEnumeratedValue = ifcProperty as IfcPropertyEnumeratedValue;
            var ifcPropertyBoundedValue    = ifcProperty as IfcPropertyBoundedValue;
            var ifcPropertyTableValue      = ifcProperty as IfcPropertyTableValue;
            var ifcPropertyReferenceValue  = ifcProperty as IfcPropertyReferenceValue;
            var ifcPropertyListValue       = ifcProperty as IfcPropertyListValue;

            if (ifcPropertySingleValue != null)
            {
                attributeType.AttributeValue = GetAttributeValueType(ifcPropertySingleValue);
            }
            else if (ifcPropertyEnumeratedValue != null)
            {
                attributeType.AttributeValue = new AttributeValueType
                {
                    ItemElementName = ItemChoiceType.AttributeStringValue
                };
                var valueItem = new AttributeStringValueType();
                attributeType.AttributeValue.Item = valueItem;
                if (ifcPropertyEnumeratedValue.EnumerationReference != null && ifcPropertyEnumeratedValue.EnumerationReference.Unit != null)
                {
                    valueItem.UnitName = ifcPropertyEnumeratedValue.EnumerationReference.Unit.GetName();
                }
                if (ifcPropertyEnumeratedValue.EnumerationValues.Count == 1)
                {
                    valueItem.StringValue = ifcPropertyEnumeratedValue.EnumerationValues[0].ToString();
                }
                else
                {
                    valueItem.StringValue = "";
                    foreach (var enumValue in ifcPropertyEnumeratedValue.EnumerationValues)
                    {
                        valueItem.StringValue += enumValue + ";";
                    }
                    valueItem.StringValue = valueItem.StringValue.TrimEnd(new[] { ';', ' ' });
                }
                //add in the allowed values

                if (ifcPropertyEnumeratedValue.EnumerationReference != null && ifcPropertyEnumeratedValue.EnumerationReference.EnumerationValues.Count > 0)
                {
                    var allowedValues = new AllowedValueCollectionType
                    {
                        AttributeAllowedValue = new List <string>(ifcPropertyEnumeratedValue.EnumerationReference.EnumerationValues.Count)
                    };
                    foreach (var enumValue in ifcPropertyEnumeratedValue.EnumerationReference.EnumerationValues)
                    {
                        allowedValues.AttributeAllowedValue.Add(enumValue.ToString());
                    }
                }
            }
            else if (ifcPropertyBoundedValue != null)
            {
                attributeType.AttributeValue = GetAttributeValue(ifcPropertyBoundedValue);
            }
            else if (ifcPropertyTableValue != null)
            {
                //Logger.WarnFormat("Table values are not supported in COBie");
            }
            else if (ifcPropertyReferenceValue != null)
            {
                //Logger.WarnFormat("Reference property values are not supported in COBie");
            }
            else if (ifcPropertyListValue != null)
            {
                //Logger.WarnFormat("Multiple List values are not supported in COBie");
            }
            return(attributeType);
        }
コード例 #2
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);
        }
コード例 #3
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);
        }