예제 #1
0
        public static string GetCreatedOnDate(IfcOwnerHistory ownerHistory)
        {
            if (ownerHistory != null)
            {
                int 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);
        }
예제 #2
0
        public override void Parse(int propIndex, IPropertyValue value, int[] nestedIndex)
        {
            switch (propIndex)
            {
            case 0:
                _owningUser = (IfcPersonAndOrganization)(value.EntityVal);
                return;

            case 1:
                _owningApplication = (IfcApplication)(value.EntityVal);
                return;

            case 2:
                _state = (IfcStateEnum)System.Enum.Parse(typeof(IfcStateEnum), value.EnumVal, true);
                return;

            case 3:
                _changeAction = (IfcChangeActionEnum)System.Enum.Parse(typeof(IfcChangeActionEnum), value.EnumVal, true);
                return;

            case 4:
                _lastModifiedDate = value.IntegerVal;
                return;

            case 5:
                _lastModifyingUser = (IfcPersonAndOrganization)(value.EntityVal);
                return;

            case 6:
                _lastModifyingApplication = (IfcApplication)(value.EntityVal);
                return;

            case 7:
                _creationDate = value.IntegerVal;
                return;

            default:
                throw new XbimParserException(string.Format("Attribute index {0} is out of range for {1}", propIndex + 1, GetType().Name.ToUpper()));
            }
        }
예제 #3
0
        public virtual void IfcParse(int propIndex, IPropertyValue value)
        {
            switch (propIndex)
            {
            case 0:
                _owningUser = (IfcPersonAndOrganization)value.EntityVal;
                break;

            case 1:
                _owningApplication = (IfcApplication)value.EntityVal;
                break;

            case 2:
                _state = (IfcStateEnum?)Enum.Parse(typeof(IfcStateEnum), value.EnumVal, true);
                break;

            case 3:
                _changeAction = (IfcChangeActionEnum)Enum.Parse(typeof(IfcChangeActionEnum), value.EnumVal, true);
                break;

            case 4:
                _lastModifiedDate = value.IntegerVal;
                break;

            case 5:
                _lastModifyingUser = (IfcPersonAndOrganization)value.EntityVal;
                break;

            case 6:
                _lastModifyingApplication = (IfcApplication)value.EntityVal;
                break;

            case 7:
                _creationDate = value.IntegerVal;
                break;

            default:
                this.HandleUnexpectedAttribute(propIndex, value); break;
            }
        }
        /// <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());
        }
예제 #6
0
        public void DateTimeTest()
        {
            var dt = new DateTime(2016, 3, 31, 10, 54, 2);

            IfcDate date = dt;

            Assert.AreEqual(date.ToString(), "2016-03-31");
            Assert.AreEqual((DateTime)date, new DateTime(2016, 3, 31));
            date = "2016-03-31";
            Assert.AreEqual((DateTime)date, new DateTime(2016, 3, 31));


            IfcDateTime dateTime = dt;

            Assert.AreEqual(dateTime.ToString(), "2016-03-31T10:54:02.0000000");
            dateTime = "2016-03-31T10:54:02";
            Assert.AreEqual((DateTime)dateTime, dt);

            IfcTimeStamp stamp = dt;

            Assert.AreEqual((TimeSpan)stamp, dt - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc));

            IfcTime time = dt;

            Assert.AreEqual(time.ToString(), "10:54:02.0000000");
            time = "10:54:02.0000000";
            var sTime = DateTime.Today.AddHours(10).AddMinutes(54).AddSeconds(2);

            Assert.AreEqual((DateTime)time, sTime);

            var         span     = new TimeSpan(9, 5, 32, 45, 12);
            IfcDuration duration = span;

            Assert.AreEqual(duration.ToString(), "P9DT5H32M45.012S");
            Assert.AreEqual(span, (TimeSpan)duration);
        }
        /// <summary>
        /// Converts an attribute in to an Ifc Property, still needs support for units adding
        /// </summary>
        /// <param name="attributeType"></param>
        /// <returns></returns>
        internal IfcSimpleProperty ConvertAttributeTypeToIfcSimpleProperty(AttributeType attributeType)
        {
            var attributeValueType = attributeType.AttributeValue;

            IfcSimpleProperty theProperty;

            var simplePropertyType = attributeValueType.SimplePropertyType();

            switch (simplePropertyType)
            {
            case XbimSimplePropertyType.SimpleDecimal:
            case XbimSimplePropertyType.SimpleInteger:
            case XbimSimplePropertyType.SimpleBoolean:
            case XbimSimplePropertyType.SimpleMonetary:
            case XbimSimplePropertyType.SimpleString:
            case XbimSimplePropertyType.SimpleDateTime:
            case XbimSimplePropertyType.Null:
                theProperty = TargetRepository.Instances.New <IfcPropertySingleValue>();
                break;

            case XbimSimplePropertyType.BoundedDecimal:
            case XbimSimplePropertyType.BoundedInteger:
                theProperty = TargetRepository.Instances.New <IfcPropertyBoundedValue>();
                break;

            case XbimSimplePropertyType.EnumerationString:
                theProperty = TargetRepository.Instances.New <IfcPropertyEnumeratedValue>();
                break;

            default:
                throw new ArgumentOutOfRangeException("attributeType", "Invalid attribute value type");
            }

            theProperty.Name        = attributeType.AttributeName;
            theProperty.Description = attributeType.AttributeDescription;
            if (attributeValueType != null)
            {
                switch (simplePropertyType)
                {
                case XbimSimplePropertyType.SimpleDecimal:
                    var    attributeDecimalValueType = attributeValueType.Item as AttributeDecimalValueType;
                    double?decimalValue;
                    if (attributeDecimalValueType != null && attributeDecimalValueType.DecimalValueSpecified)
                    {
                        decimalValue = attributeDecimalValueType.DecimalValue;
                    }
                    else
                    {
                        decimalValue = null;
                    }
                    var simpleProperty = (IfcPropertySingleValue)theProperty;
                    if (decimalValue.HasValue)
                    {
                        simpleProperty.NominalValue = new IfcReal(decimalValue.Value);
                    }
                    //if (attributeDecimalValueType != null)
                    //{
                    //    var unitConverter = new IfcUnitConverter(attributeDecimalValueType.UnitName);
                    //    if (!unitConverter.IsUndefined)
                    //        simpleProperty.Unit = unitConverter.IfcUnit(TargetRepository);
                    //}
                    break;

                case XbimSimplePropertyType.BoundedDecimal:
                    var    attributeBoundedDecimalValueType = attributeValueType.Item as AttributeDecimalValueType;
                    double?maxDecimalValue;
                    double?minDecimalValue;
                    if (attributeBoundedDecimalValueType != null &&
                        attributeBoundedDecimalValueType.MaxValueDecimalSpecified)
                    {
                        maxDecimalValue = attributeBoundedDecimalValueType.MaxValueDecimal;
                    }
                    else
                    {
                        maxDecimalValue = null;
                    }
                    if (attributeBoundedDecimalValueType != null &&
                        attributeBoundedDecimalValueType.MinValueDecimalSpecified)
                    {
                        minDecimalValue = attributeBoundedDecimalValueType.MinValueDecimal;
                    }
                    else
                    {
                        minDecimalValue = null;
                    }
                    var boundedProperty = (IfcPropertyBoundedValue)theProperty;
                    if (maxDecimalValue.HasValue)
                    {
                        boundedProperty.UpperBoundValue = new IfcReal(maxDecimalValue.Value);
                    }
                    if (minDecimalValue.HasValue)
                    {
                        boundedProperty.LowerBoundValue = new IfcReal(minDecimalValue.Value);
                    }
                    break;

                case XbimSimplePropertyType.SimpleInteger:
                    var attributeSimpleIntegerValueType = attributeValueType.Item as AttributeIntegerValueType;
                    if (attributeSimpleIntegerValueType != null &&
                        attributeSimpleIntegerValueType.IntegerValue.HasValue)
                    {
                        var simpleIntProperty = (IfcPropertySingleValue)theProperty;
                        simpleIntProperty.NominalValue =
                            new IfcInteger(attributeSimpleIntegerValueType.IntegerValue.Value);
                    }
                    break;

                case XbimSimplePropertyType.BoundedInteger:
                    var attributeBoundedIntegerValueType = attributeValueType.Item as AttributeIntegerValueType;
                    if (attributeBoundedIntegerValueType != null)
                    {
                        var boundedIntegerProperty = (IfcPropertyBoundedValue)theProperty;
                        if (attributeBoundedIntegerValueType.MaxValueInteger.HasValue)
                        {
                            boundedIntegerProperty.UpperBoundValue =
                                new IfcInteger(attributeBoundedIntegerValueType.MaxValueInteger.Value);
                        }
                        if (attributeBoundedIntegerValueType.MinValueInteger.HasValue)
                        {
                            boundedIntegerProperty.LowerBoundValue =
                                new IfcInteger(attributeBoundedIntegerValueType.MinValueInteger.Value);
                        }
                    }
                    break;

                case XbimSimplePropertyType.SimpleBoolean:
                    var attributeBooleanValueType = attributeValueType.Item as BooleanValueType;
                    if (attributeBooleanValueType != null && attributeBooleanValueType.BooleanValueSpecified)
                    {
                        var simpleBooleanProperty = (IfcPropertySingleValue)theProperty;
                        simpleBooleanProperty.NominalValue = new IfcBoolean(attributeBooleanValueType.BooleanValue);
                    }
                    break;

                case XbimSimplePropertyType.SimpleMonetary:
                    var attributeMonetaryValueType = attributeValueType.Item as AttributeMonetaryValueType;
                    if (attributeMonetaryValueType != null)
                    {
                        var simpleMonetaryProperty = (IfcPropertySingleValue)theProperty;
                        var monetaryValue          = (double)attributeMonetaryValueType.MonetaryValue;
                        simpleMonetaryProperty.NominalValue = new IfcReal(monetaryValue);
                        IfcCurrencyEnum currencyEnum;
                        if (Enum.TryParse(attributeMonetaryValueType.MonetaryUnit.ToString(), true, out currencyEnum))
                        {
                            simpleMonetaryProperty.Unit = new IfcMonetaryUnit {
                                Currency = currencyEnum
                            }
                        }
                        ;
                    }
                    break;

                case XbimSimplePropertyType.EnumerationString:
                    var attributeEnumStringValueType = attributeValueType.Item as AttributeStringValueType;
                    if (attributeEnumStringValueType != null)
                    {
                        var simpleEnumStringProperty = (IfcPropertyEnumeratedValue)theProperty;
                        simpleEnumStringProperty.EnumerationValues.Add(
                            new IfcLabel(attributeEnumStringValueType.StringValue));
                        if (attributeEnumStringValueType.AllowedValues != null &&
                            attributeEnumStringValueType.AllowedValues.Any())
                        {
                            simpleEnumStringProperty.EnumerationReference =
                                TargetRepository.Instances.New <IfcPropertyEnumeration>();
                            foreach (var allowedValue in attributeEnumStringValueType.AllowedValues)
                            {
                                simpleEnumStringProperty.EnumerationReference.Name = attributeType.AttributeName;
                                simpleEnumStringProperty.EnumerationReference.EnumerationValues.Add(
                                    new IfcLabel(allowedValue));
                            }
                        }
                    }
                    break;

                case XbimSimplePropertyType.SimpleString:
                case XbimSimplePropertyType.Null:
                    var attributeStringValueType = attributeValueType.Item as AttributeStringValueType;
                    if (attributeStringValueType != null)
                    {
                        var simpleStringProperty = (IfcPropertySingleValue)theProperty;
                        simpleStringProperty.NominalValue = new IfcText(attributeStringValueType.StringValue);
                    }
                    break;

                case XbimSimplePropertyType.SimpleDateTime:
                    if (attributeValueType.Item is DateTime)
                    {
                        var simpleDateTimeProperty     = (IfcPropertySingleValue)theProperty;
                        var attributeDateTimeValueType = (DateTime)attributeValueType.Item;
                        simpleDateTimeProperty.NominalValue = IfcTimeStamp.ToTimeStamp(attributeDateTimeValueType);
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException("attributeType", "Invalid attribute value type");
                }
            }
            return(theProperty);
        }
예제 #8
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);
        }
예제 #9
0
 /// <summary>
 ///   Creates an Ifc schema compliant OwnerHistory, Creation Date default to Now, changeAction to ADDED
 /// </summary>
 public IfcOwnerHistory()
 {
     _creationDate = IfcTimeStamp.ToTimeStamp(DateTime.UtcNow);
 }
예제 #10
0
 public IfcOwnerHistory(IfcPersonAndOrganization __OwningUser, IfcApplication __OwningApplication, IfcStateEnum?__State, IfcChangeActionEnum?__ChangeAction, IfcTimeStamp?__LastModifiedDate, IfcPersonAndOrganization __LastModifyingUser, IfcApplication __LastModifyingApplication, IfcTimeStamp __CreationDate)
 {
     this._OwningUser               = __OwningUser;
     this._OwningApplication        = __OwningApplication;
     this._State                    = __State;
     this._ChangeAction             = __ChangeAction;
     this._LastModifiedDate         = __LastModifiedDate;
     this._LastModifyingUser        = __LastModifyingUser;
     this._LastModifyingApplication = __LastModifyingApplication;
     this._CreationDate             = __CreationDate;
 }
예제 #11
0
        private static void WriteValueType(Type pInfoType, object pVal, BinaryWriter entityWriter)
        {
            if (pInfoType == typeof(Double))
            {
                entityWriter.Write(Convert.ToByte(P21ParseAction.SetFloatValue));
                entityWriter.Write((double)pVal);
            }
            else if (pInfoType == typeof(String)) //convert  string
            {
                if (pVal == null)
                {
                    entityWriter.Write(Convert.ToByte(P21ParseAction.SetNonDefinedValue));
                }
                else
                {
                    entityWriter.Write(Convert.ToByte(P21ParseAction.SetStringValue));
                    entityWriter.Write((string)pVal);
                }
            }
            else if (pInfoType == typeof(Int16))
            {
                entityWriter.Write(Convert.ToByte(P21ParseAction.SetIntegerValue));
                entityWriter.Write((long)(Int16)pVal);
            }
            else if (pInfoType == typeof(Int32))
            {
                entityWriter.Write(Convert.ToByte(P21ParseAction.SetIntegerValue));
                entityWriter.Write((long)(Int32)pVal);
            }
            else if (pInfoType == typeof(Int64))
            {
                entityWriter.Write(Convert.ToByte(P21ParseAction.SetIntegerValue));
                entityWriter.Write((long)pVal);
            }
            else if (pInfoType.IsEnum) //convert enum
            {
                entityWriter.Write(Convert.ToByte(P21ParseAction.SetEnumValue));
                entityWriter.Write(pVal.ToString().ToUpper());
            }
            else if (pInfoType == typeof(Boolean))
            {
                if (pVal == null) //we have a logical
                {
                    entityWriter.Write(Convert.ToByte(P21ParseAction.SetNonDefinedValue));
                }
                else
                {
                    entityWriter.Write(Convert.ToByte(P21ParseAction.SetBooleanValue));
                    entityWriter.Write((bool)pVal);
                }
            }

            else if (pInfoType == typeof(DateTime)) //convert  TimeStamp
            {
                IfcTimeStamp ts = IfcTimeStamp.ToTimeStamp((DateTime)pVal);
                entityWriter.Write(Convert.ToByte(P21ParseAction.SetIntegerValue));
                entityWriter.Write((long)ts);
            }
            else if (pInfoType == typeof(Guid)) //convert  Guid string
            {
                if (pVal == null)
                {
                    entityWriter.Write(Convert.ToByte(P21ParseAction.SetNonDefinedValue));
                }
                else
                {
                    entityWriter.Write(Convert.ToByte(P21ParseAction.SetStringValue));
                    entityWriter.Write((string)pVal);
                }
            }
            else if (pInfoType == typeof(bool?)) //convert  logical
            {
                bool?b = (bool?)pVal;
                if (!b.HasValue)
                {
                    entityWriter.Write(Convert.ToByte(P21ParseAction.SetNonDefinedValue));
                }
                else
                {
                    entityWriter.Write(Convert.ToByte(P21ParseAction.SetBooleanValue));
                    entityWriter.Write(b.Value);
                }
            }
            else
            {
                throw new ArgumentException(string.Format("Invalid Value Type {0}", pInfoType.Name), "pInfoType");
            }
        }