private string ConvertToString(IIfcPropertySingleValue ifcProperty)
        {
            var ifcValue = ifcProperty.NominalValue;

            if (ifcValue == null)
            {
                return(null);
            }
            if (ifcValue is IfcTimeStamp)
            {
                var timeStamp = (IfcTimeStamp)ifcValue;
                return(WriteDateTime(timeStamp.ToDateTime()));
            }
            var expressVal = (IExpressValueType)ifcValue;
            var tp         = expressVal.UnderlyingSystemType;

            if (tp == typeof(bool) || tp == typeof(bool?))
            {
                return(expressVal.Value != null && (bool)expressVal.Value
                    ? "yes"
                    : "no");
            }
            // all other cases will convert to a string
            return(expressVal.Value != null
                ? expressVal.Value.ToString()
                : null);
        }
Esempio n. 2
0
        private string ConvertToString(IIfcPropertySingleValue ifcProperty)
        {
            IIfcValue ifcValue = ifcProperty.NominalValue;

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

            if (ifcValue is Xbim.Ifc4.DateTimeResource.IfcTimeStamp)
            {
                var timeStamp = (Xbim.Ifc4.DateTimeResource.IfcTimeStamp)ifcValue;
                return(WriteDateTime(timeStamp.ToDateTime()));
            }
            if (underlyingType == typeof(bool) || underlyingType == typeof(bool?))
            {
                if (expressValue.Value != null && (bool)expressValue.Value)
                {
                    return("yes");
                }
                return("no");
            }
            // all other cases will convert to a string
            return(expressValue.Value.ToString());
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="ifcProperty"></param>
        /// <returns></returns>
        public static AttributeValue GetAttributeValueType(IIfcPropertySingleValue ifcProperty)
        {
            var ifcValue = (IExpressValueType)ifcProperty.NominalValue;

            if (ifcValue == null)
            {
                return(null);
            }
            if (ifcValue is IfcMonetaryMeasure)
            {
                var moneyAttribute = new DecimalAttributeValue {
                    Value = (double)ifcValue.Value
                };
                if (!(ifcProperty.Unit is IIfcMonetaryUnit))
                {
                    return(null);
                }
                var mu = (IIfcMonetaryUnit)ifcProperty.Unit;
                moneyAttribute.Unit = mu.ToString();
            }
            else if (ifcValue is IfcTimeStamp)
            {
                var timeStamp = (IfcTimeStamp)ifcValue;
                return(new DateTimeAttributeValue {
                    Value = timeStamp.ToDateTime()
                });
            }

            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);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="ifcProperty"></param>
        /// <param name="attribute"></param>
        /// <returns></returns>
        public static void SetAttributeValueType(IIfcPropertySingleValue ifcProperty, CobieAttribute attribute)
        {
            var ifcValue = ifcProperty.NominalValue;

            if (ifcValue == null)
            {
                return;
            }

            if (ifcProperty.Unit != null)
            {
                attribute.Unit = ifcProperty.Unit.FullName;
            }

            if (ifcValue is IfcMonetaryMeasure)
            {
                attribute.Value = (FloatValue)ifcValue.Value;
                var monUnit = ifcProperty.Unit as IIfcMonetaryUnit;
                if (monUnit == null)
                {
                    return;
                }

                attribute.Unit = monUnit.ToString();
                return;
            }

            if (ifcValue is IfcTimeStamp)
            {
                var timeStamp = (IfcTimeStamp)ifcValue;
                var timeValue = (DateTimeValue)timeStamp.ToDateTime();
                attribute.Value = timeValue;
                return;
            }
            if (ifcValue.UnderlyingSystemType == typeof(int) || ifcValue.UnderlyingSystemType == typeof(long) || ifcValue.UnderlyingSystemType == typeof(short) || ifcValue.UnderlyingSystemType == typeof(byte))
            {
                attribute.Value = (IntegerValue)Convert.ToInt32(ifcValue.Value);
                return;
            }
            if (ifcValue.UnderlyingSystemType == typeof(double) || ifcValue.UnderlyingSystemType == typeof(float))
            {
                attribute.Value = (FloatValue)(double)ifcValue.Value;
                return;
            }
            if (ifcValue.UnderlyingSystemType == typeof(string))
            {
                attribute.Value = (StringValue)ifcValue.ToString();
                return;
            }
            if (ifcValue.UnderlyingSystemType == typeof(bool) || ifcValue.UnderlyingSystemType == typeof(bool?))
            {
                if (ifcValue.Value == null || !(bool)ifcValue.Value)
                {
                    return;
                }
                attribute.Value = (BooleanValue)(bool)ifcValue.Value;
            }
        }
        private void AddProperty(IIfcPropertySingleValue item, string groupName)
        {
            var val    = "";
            var nomVal = item.NominalValue;

            if (nomVal != null)
            {
                val = nomVal.ToString();
            }
            _properties.Add(new PropertyItem
            {
                IfcLabel        = item.EntityLabel,
                PropertySetName = groupName,
                Name            = item.Name,
                Value           = val
            });
        }
Esempio n. 6
0
        public static TValue ConvertToSimpleType <TValue>(IIfcPropertySingleValue ifcProperty) where TValue : struct
        {
            IIfcValue ifcValue       = ifcProperty.NominalValue;
            var       expressValue   = (IExpressValueType)ifcValue;
            var       underlyingType = expressValue.UnderlyingSystemType;
            var       value          = new TValue();

            if (ifcValue is Xbim.Ifc4.MeasureResource.IfcMonetaryMeasure)
            {
                value = (TValue)Convert.ChangeType(expressValue.Value, typeof(TValue));
            }
            else if (ifcValue is Xbim.Ifc4.DateTimeResource.IfcTimeStamp)
            {
                var timeStamp = (Xbim.Ifc4.DateTimeResource.IfcTimeStamp)ifcValue;
                value = (TValue)Convert.ChangeType(timeStamp.ToDateTime(), typeof(TValue));
            }
            else if (value is DateTime) //sometimes these are written as strings in the ifc file
            {
                value = (TValue)Convert.ChangeType(ReadDateTime(expressValue.Value.ToString()), typeof(TValue));
            }
            else if (underlyingType == typeof(int) || underlyingType == typeof(long) || underlyingType == typeof(short) || underlyingType == typeof(byte))
            {
                value = (TValue)Convert.ChangeType(expressValue.Value, typeof(TValue));
            }
            else if (underlyingType == typeof(double) || underlyingType == typeof(float))
            {
                value = (TValue)Convert.ChangeType(expressValue.Value, typeof(TValue));
            }
            else if (underlyingType == typeof(string))
            {
                value = (TValue)Convert.ChangeType(expressValue.Value, typeof(TValue));
            }
            else if (underlyingType == typeof(bool) || underlyingType == typeof(bool?))
            {
                if (ifcValue != null)
                {
                    value = (TValue)Convert.ChangeType(expressValue.Value, typeof(TValue));
                }
            }
            return(value);
        }
        internal static void ResolveUnits(IfcStore ifcStore, Dictionary <string, string> propertySetNamePropertyNameToUnit)
        {
            IEnumerable <IfcPropertySet> psets = ifcStore.Instances.OfType <IfcPropertySet>();

            foreach (IfcPropertySet pset in psets)
            {
                if (pset != null && pset.Name != null)
                {
                    IItemSet <IfcProperty> properties = pset.HasProperties;
                    foreach (IfcProperty property in properties)
                    {
                        if (property is IIfcPropertySingleValue && property != null && property.Name != null)
                        {
                            IIfcPropertySingleValue propertySingleValue = property as IIfcPropertySingleValue;

                            IfcUnitEnum ifcUnitEnum = resolveUnit(propertySingleValue);
                            if (!ifcUnitEnum.Equals(IfcUnitEnum.USERDEFINED))
                            {
                                var key = pset.Name + "_" + property.Name;
                                if (!propertySetNamePropertyNameToUnit.ContainsKey(key))
                                {
                                    IfcSIUnit ifcSIUnit = ifcStore.FederatedInstances
                                                          .Where <IfcSIUnit>(a => a.UnitType.ToString().Equals(ifcUnitEnum.ToString()))
                                                          .FirstOrDefault <IfcSIUnit>();

                                    if (ifcSIUnit != null && ifcSIUnit.Symbol != null)
                                    {
                                        var value = ifcSIUnit.UnitType.ToString() + "|" + ifcSIUnit.Symbol.ToString();
                                        propertySetNamePropertyNameToUnit.Add(key, value);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        private static IfcUnitEnum resolveUnit(IIfcPropertySingleValue property)
        {
            var expressValueType = (IExpressValueType)property.NominalValue;

            IfcUnitEnum ifcUnitEnum = IfcUnitEnum.USERDEFINED;

            if (expressValueType is IfcAmountOfSubstanceMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.AMOUNTOFSUBSTANCEUNIT;
            }
            else if (expressValueType is IfcAreaMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.AREAUNIT;
            }
            else if (expressValueType is IfcElectricCurrentMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.ELECTRICCURRENTUNIT;
            }
            else if (expressValueType is IfcLengthMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.LENGTHUNIT;
            }
            else if (expressValueType is IfcLuminousIntensityMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.LUMINOUSINTENSITYUNIT;
            }
            else if (expressValueType is IfcMassMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.MASSUNIT;
            }
            else if (expressValueType is IfcPlaneAngleMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.PLANEANGLEUNIT;
            }
            else if (expressValueType is IfcPositiveLengthMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.LENGTHUNIT;
            }
            else if (expressValueType is IfcPositivePlaneAngleMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.PLANEANGLEUNIT;
            }
            else if (expressValueType is IfcSolidAngleMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.SOLIDANGLEUNIT;
            }
            else if (expressValueType is IfcThermodynamicTemperatureMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.THERMODYNAMICTEMPERATUREUNIT;
            }
            else if (expressValueType is IfcTimeMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.TIMEUNIT;
            }
            else if (expressValueType is IfcVolumeMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.VOLUMEUNIT;
            }
            else if (expressValueType is IfcAbsorbedDoseMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.ABSORBEDDOSEUNIT;
            }
            else if (expressValueType is IfcDoseEquivalentMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.DOSEEQUIVALENTUNIT;
            }
            else if (expressValueType is IfcElectricCapacitanceMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.ELECTRICCAPACITANCEUNIT;
            }
            else if (expressValueType is IfcElectricChargeMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.ELECTRICCHARGEUNIT;
            }
            else if (expressValueType is IfcElectricConductanceMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.ELECTRICCONDUCTANCEUNIT;
            }
            else if (expressValueType is IfcElectricResistanceMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.ELECTRICRESISTANCEUNIT;
            }
            else if (expressValueType is IfcElectricVoltageMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.ELECTRICVOLTAGEUNIT;
            }
            else if (expressValueType is IfcForceMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.FORCEUNIT;
            }
            else if (expressValueType is IfcFrequencyMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.FREQUENCYUNIT;
            }
            else if (expressValueType is IfcIlluminanceMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.ILLUMINANCEUNIT;
            }
            else if (expressValueType is IfcInductanceMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.INDUCTANCEUNIT;
            }
            else if (expressValueType is IfcLuminousFluxMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.LUMINOUSFLUXUNIT;
            }
            else if (expressValueType is IfcMagneticFluxDensityMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.MAGNETICFLUXDENSITYUNIT;
            }
            else if (expressValueType is IfcMagneticFluxMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.MAGNETICFLUXUNIT;
            }
            else if (expressValueType is IfcPowerMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.POWERUNIT;
            }
            else if (expressValueType is IfcPressureMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.PRESSUREUNIT;
            }
            else if (expressValueType is IfcRadioActivityMeasure)
            {
                ifcUnitEnum = IfcUnitEnum.RADIOACTIVITYUNIT;
            }

            return(ifcUnitEnum);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="ifcProperty"></param>
        /// <param name="value"></param>
        /// <typeparam name="TValue"></typeparam>
        /// <returns></returns>
        public static bool ConvertPropertySingleValueToSimpleType <TValue>(IIfcPropertySingleValue ifcProperty, out TValue value)
            where TValue : struct
        {
            var ifcValue = (IExpressValueType)ifcProperty.NominalValue;

            try
            {
                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(timeStamp.ToDateTime(), 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))
                {
                    var str = ifcValue.Value as string;
                    if (!string.IsNullOrWhiteSpace(str))
                    {
                        value = (TValue)Convert.ChangeType(ifcValue.Value, typeof(TValue));
                    }
                    else
                    {
                        value = new TValue();
                        return(false);
                    }
                }
                else if (
                    ifcValue.UnderlyingSystemType == typeof(bool) ||
                    ifcValue.UnderlyingSystemType == typeof(bool?)
                    )
                {
                    value = (TValue)Convert.ChangeType(ifcValue.Value, typeof(TValue));
                }
                else
                {
                    value = new TValue();
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Logger.LogDebug(0, ex,
                                "Conversion of '{value}' ({type}) to {targetType} failed.",
                                ifcValue.Value,
                                ifcValue.Value.GetType(),
                                typeof(TValue),
                                ex.Message);
                value = new TValue();
                return(false);
            }
            return(true);
        }
Esempio n. 10
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);
        }
Esempio n. 11
0
        public static B5dProperty ConvertProperty(IIfcPropertySingleValue ifcPropValue, B5dObject propOwner)
        {
            if (ifcPropValue.NominalValue == null)
            {
                return(null);
            }

            var propName  = ifcPropValue.Name.Value.ToString();
            var propValue = ifcPropValue.NominalValue.Value;
            var propType  = ifcPropValue.NominalValue.UnderlyingSystemType.Name;

            switch (propType)
            {
            case "Boolean":
                if (propValue is bool boolValue)
                {
                    return(new B5dBoolean()
                    {
                        Name = propName, Value = boolValue, BelongsTo = propOwner
                    });
                }
                break;

            case "Double":
                if (propValue is double doubleValue)
                {
                    return(new B5dDouble()
                    {
                        Name = propName, Value = doubleValue, BelongsTo = propOwner
                    });
                }
                break;

            case "Int64":
                if (propValue is Int64 int64Value)
                {
                    return(new B5dInteger()
                    {
                        Name = propName, Value = int64Value, BelongsTo = propOwner
                    });
                }
                break;

            case "Int32":
                if (propValue is Int32 int32Value)
                {
                    return(new B5dInteger()
                    {
                        Name = propName, Value = int32Value, BelongsTo = propOwner
                    });
                }
                break;

            case "String":
                if (propValue is string stringValue)
                {
                    return(new B5dString()
                    {
                        Name = propName, Value = stringValue, BelongsTo = propOwner
                    });
                }
                break;

            default:
                return(null);
            }

            return(null);
        }