private string ConvertToString(IfcProperty ifcProperty)
        {
            var ifcPropertySingleValue     = ifcProperty as IfcPropertySingleValue;
            var ifcPropertyEnumeratedValue = ifcProperty as IfcPropertyEnumeratedValue;

            if (ifcPropertySingleValue != null)
            {
                return(ConvertToString(ifcPropertySingleValue));
            }
            if (ifcPropertyEnumeratedValue != null)
            {
                if (ifcPropertyEnumeratedValue.EnumerationValues.Count == 1)
                {
                    return(ifcPropertyEnumeratedValue.EnumerationValues[0].ToString());
                }
                var result = "";
                foreach (var enumValue in ifcPropertyEnumeratedValue.EnumerationValues)
                {
                    result += enumValue + ";";
                }
                return(result.TrimEnd(new[] { ';', ' ' }));
            }

            CoBieLiteUkHelper.Logger.WarnFormat("Conversion Error: #{0}={1} [{2}] cannot be converted to s simple value type", ifcProperty.EntityLabel, ifcProperty.Name, ifcProperty.GetType().Name);
            return(null);
        }
        public override void Parse(int propIndex, IPropertyValue value, int[] nestedIndex)
        {
            switch (propIndex)
            {
            case 0:
            case 1:
                base.Parse(propIndex, value, nestedIndex);
                return;

            case 2:
                _dependingProperty = (IfcProperty)(value.EntityVal);
                return;

            case 3:
                _dependantProperty = (IfcProperty)(value.EntityVal);
                return;

            case 4:
                _expression = value.StringVal;
                return;

            default:
                throw new XbimParserException(string.Format("Attribute index {0} is out of range for {1}", propIndex + 1, GetType().Name.ToUpper()));
            }
        }
        private static CcManufacturerProductDetail GetDetailsFromProperty(IfcProperty prop)
        {
            CcManufacturerProductDetail result = null;

            if (prop is IfcPropertySingleValue)
            {
                IfcPropertySingleValue single = prop as IfcPropertySingleValue;
                result = new CcManufacturerProductDetail()
                {
                    AttributeName = single.Name
                };
                result.AttributeValue = GetNominalValue(single.NominalValue);
            }
            else if (prop is IfcPropertyEnumeratedValue)
            {
                IfcPropertyEnumeratedValue enumval = prop as IfcPropertyEnumeratedValue;
                result = new CcManufacturerProductDetail()
                {
                    AttributeName = enumval.Name, AttributeDescription = enumval.Description
                };
                result.AttributeValue = GetEnumeratedValue(enumval.EnumerationValues);
            }
            else
            {
                throw new NotImplementedException();
            }

            return(result);
        }
        /// <summary>
        /// Converts the property to a simple type, date, string
        /// </summary>
        /// <param name="ifcProperty"></param>
        /// <returns></returns>
        static public TValue ConvertToSimpleType <TValue>(IfcProperty ifcProperty) where TValue : struct
        {
            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)
            {
                return(ConvertToSimpleType <TValue>(ifcPropertySingleValue));
            }
            if (ifcPropertyEnumeratedValue != null)
            {
                if (ifcPropertyEnumeratedValue.EnumerationValues.Count == 1)
                {
                    return((TValue)Convert.ChangeType(ifcPropertyEnumeratedValue.EnumerationValues[0].ToString(), typeof(TValue)));
                }
                var result = "";
                foreach (var enumValue in ifcPropertyEnumeratedValue.EnumerationValues)
                {
                    result += enumValue + ";";
                }
                result = result.TrimEnd(new[] { ';', ' ' });
                return((TValue)Convert.ChangeType(result, typeof(TValue)));
            }
            if (ifcPropertyBoundedValue != null)
            {
                CoBieLiteUkHelper.Logger.WarnFormat("Conversion Error: PropertyBoundedValue #{0}={1} cannot be converted to s simple value type", ifcProperty.EntityLabel, ifcProperty.Name);
            }
            else if (ifcPropertyTableValue != null)
            {
                CoBieLiteUkHelper.Logger.WarnFormat("Conversion Error: PropertyTableValue #{0}={1} cannot be converted to s simple value type", ifcProperty.EntityLabel, ifcProperty.Name);
            }
            else if (ifcPropertyReferenceValue != null)
            {
                CoBieLiteUkHelper.Logger.WarnFormat("Conversion Error: PropertyReferenceValue #{0}={1} cannot be converted to s simple value type", ifcProperty.EntityLabel, ifcProperty.Name);
            }
            else if (ifcPropertyListValue != null)
            {
                CoBieLiteUkHelper.Logger.WarnFormat("Conversion Error: PropertyListValue #{0}={1} cannot be converted to s simple value type", ifcProperty.EntityLabel, ifcProperty.Name);
            }
            return(default(TValue));
        }
Ejemplo n.º 5
0
        public void InitializeAdditionalProperties()
        {
            // default value
            this.IsLandmarked       = false;
            this.YearOfConstruction = "";
            this.NumberOfStoreys    = 0;
            this.OccupancyType      = "";

            Ifc4.IfcPropertySet ifcPropertySet = this.GetIfcPropertySetFromRelatingPropertyDefinition();

            IEnumerable <IfcProperty> ifcPropertyCollection = this.Document.IfcXmlDocument.Items.OfType <IfcProperty>().ToList();

            if (ifcPropertySet == null)
            {
                ifcPropertySet = new IfcPropertySet();
            }

            if (ifcPropertySet.HasProperties == null)
            {
                ifcPropertySet.HasProperties = new IfcPropertySetHasProperties();
            }

            m_IfcPropertySingleValueCollection = new List <IfcPropertySingleValue>();
            foreach (IfcProperty ifcPropertyTmp in ifcPropertySet.HasProperties.Items)
            {
                if (ifcPropertyTmp.IsRef)
                {
                    IfcProperty ifcProperty = ifcPropertyCollection.FirstOrDefault(item => item.Id == ifcPropertyTmp.Ref);
                    if (ifcProperty != null && ifcProperty is IfcPropertySingleValue)
                    {
                        m_IfcPropertySingleValueCollection.Add((IfcPropertySingleValue)ifcProperty);
                    }
                }
            }

            IfcPropertySingleValue ifcPropertySingleValue = null;

            ifcPropertySingleValue = m_IfcPropertySingleValueCollection.FirstOrDefault(item => item.Name.Equals("IsLandmarked", StringComparison.OrdinalIgnoreCase));
            if (ifcPropertySingleValue == null)
            {
                ifcPropertySingleValue = new Ifc4.IfcPropertySingleValue()
                {
                    Id           = this.Document.GetNextSid(),
                    Name         = "IsLandmarked",
                    NominalValue = new Ifc4.IfcPropertySingleValueNominalValue(),
                };

                ifcPropertySingleValue.NominalValue.Item = new Ifc4.IfcLogicalwrapper()
                {
                    Value = IsLandmarked ? Ifc4.IfcLogical.True : Ifc4.IfcLogical.False
                };

                m_IfcPropertySingleValueCollection.Add(ifcPropertySingleValue);
                this.Document.IfcXmlDocument.Items.Add(ifcPropertySingleValue);
                ifcPropertySet.HasProperties.Items.Add(new Ifc4.IfcPropertySingleValue()
                {
                    Ref = ifcPropertySingleValue.Id
                });
            }
            else
            {
                // read
                Ifc4.IfcLogicalwrapper ifcLogicalwrapper = ifcPropertySingleValue.NominalValue.Item as Ifc4.IfcLogicalwrapper;
                if (ifcLogicalwrapper != null)
                {
                    this.IsLandmarked = ifcLogicalwrapper.Value == IfcLogical.True ? true : false;
                }
            }

            ifcPropertySingleValue = m_IfcPropertySingleValueCollection.FirstOrDefault(item => item.Name.Equals("YearOfConstruction", StringComparison.OrdinalIgnoreCase));
            if (ifcPropertySingleValue == null)
            {
                ifcPropertySingleValue = new Ifc4.IfcPropertySingleValue()
                {
                    Id           = this.Document.GetNextSid(),
                    Name         = "YearOfConstruction",
                    NominalValue = new Ifc4.IfcPropertySingleValueNominalValue(),
                };

                ifcPropertySingleValue.NominalValue.Item = new Ifc4.IfcLabelwrapper()
                {
                    Value = this.YearOfConstruction
                };

                m_IfcPropertySingleValueCollection.Add(ifcPropertySingleValue);
                this.Document.IfcXmlDocument.Items.Add(ifcPropertySingleValue);
                ifcPropertySet.HasProperties.Items.Add(new Ifc4.IfcPropertySingleValue()
                {
                    Ref = ifcPropertySingleValue.Id
                });
            }
            else
            {
                // read
                Ifc4.IfcLabelwrapper ifcLabelwrapper = ifcPropertySingleValue.NominalValue.Item as Ifc4.IfcLabelwrapper;
                if (ifcLabelwrapper != null)
                {
                    this.YearOfConstruction = ifcLabelwrapper.Value;
                }
            }

            ifcPropertySingleValue = m_IfcPropertySingleValueCollection.FirstOrDefault(item => item.Name.Equals("NumberOfStoreys", StringComparison.OrdinalIgnoreCase));
            if (ifcPropertySingleValue == null)
            {
                ifcPropertySingleValue = new Ifc4.IfcPropertySingleValue()
                {
                    Id           = this.Document.GetNextSid(),
                    Name         = "NumberOfStoreys",
                    NominalValue = new Ifc4.IfcPropertySingleValueNominalValue(),
                };

                ifcPropertySingleValue.NominalValue.Item = new Ifc4.IfcIntegerwrapper()
                {
                    Value = this.NumberOfStoreys
                };


                m_IfcPropertySingleValueCollection.Add(ifcPropertySingleValue);
                this.Document.IfcXmlDocument.Items.Add(ifcPropertySingleValue);
                ifcPropertySet.HasProperties.Items.Add(new Ifc4.IfcPropertySingleValue()
                {
                    Ref = ifcPropertySingleValue.Id
                });
            }
            else
            {
                // read
                Ifc4.IfcIntegerwrapper ifcIntegerwrapper = ifcPropertySingleValue.NominalValue.Item as Ifc4.IfcIntegerwrapper;
                if (ifcIntegerwrapper != null)
                {
                    this.NumberOfStoreys = ifcIntegerwrapper.Value;
                }
            }

            ifcPropertySingleValue = m_IfcPropertySingleValueCollection.FirstOrDefault(item => item.Name.Equals("OccupancyType", StringComparison.OrdinalIgnoreCase));
            if (ifcPropertySingleValue == null)
            {
                ifcPropertySingleValue = new Ifc4.IfcPropertySingleValue()
                {
                    Id           = this.Document.GetNextSid(),
                    Name         = "OccupancyType",
                    NominalValue = new Ifc4.IfcPropertySingleValueNominalValue(),
                };

                ifcPropertySingleValue.NominalValue.Item = new Ifc4.IfcLabelwrapper()
                {
                    Value = this.OccupancyType
                };

                m_IfcPropertySingleValueCollection.Add(ifcPropertySingleValue);
                this.Document.IfcXmlDocument.Items.Add(ifcPropertySingleValue);
                ifcPropertySet.HasProperties.Items.Add(new Ifc4.IfcPropertySingleValue()
                {
                    Ref = ifcPropertySingleValue.Id
                });
            }
            else
            {
                // read
                Ifc4.IfcLabelwrapper ifcLabelwrapper = ifcPropertySingleValue.NominalValue.Item as Ifc4.IfcLabelwrapper;
                if (ifcLabelwrapper != null)
                {
                    this.OccupancyType = ifcLabelwrapper.Value;
                }
            }


            if (ifcPropertySet.Id == null)
            {
                ifcPropertySet.Id   = this.Document.GetNextSid();
                ifcPropertySet.Name = "Pset_BuildingCommon";
                this.Document.IfcXmlDocument.Items.Add(ifcPropertySet);

                Ifc4.IfcRelDefinesByProperties ifcRelDefinesByProperties = new Ifc4.IfcRelDefinesByProperties();
                ifcRelDefinesByProperties.Id = this.Document.GetNextSid();
                //ifcRelDefinesByProperties.RelatedObjects = new Ifc4.IfcBuilding() { Ref = this.Id };
                ifcRelDefinesByProperties.RelatedObjects                  = this.RefInstance();
                ifcRelDefinesByProperties.RelatingPropertyDefinition      = new Ifc4.IfcRelDefinesByPropertiesRelatingPropertyDefinition();
                ifcRelDefinesByProperties.RelatingPropertyDefinition.Item = new Ifc4.IfcPropertySet()
                {
                    Ref = ifcPropertySet.Id
                };
                this.Document.IfcXmlDocument.Items.Add(ifcRelDefinesByProperties);
            }

            // -----------------------------------------
            Ifc4.IfcElementQuantity ifcElementQuantity = this.GetIfcElementQuantityFromRelatingPropertyDefinition();
            if (ifcElementQuantity != null && ifcElementQuantity.IsRef)
            {
                ifcElementQuantity = this.Document.IfcXmlDocument.Items.OfType <IfcElementQuantity>().FirstOrDefault(item => item.Id == ifcElementQuantity.Ref);
            }

            IEnumerable <IfcQuantityArea> ifcQuantityAreaCollection = this.Document.IfcXmlDocument.Items.OfType <IfcQuantityArea>();

            if (ifcElementQuantity == null)
            {
                ifcElementQuantity = new IfcElementQuantity();
            }

            if (ifcElementQuantity.Quantities == null)
            {
                ifcElementQuantity.Quantities = new IfcElementQuantityQuantities();
            }


            m_IfcQuantityAreaCollection = new List <IfcQuantityArea>();
            foreach (IfcQuantityArea ifcQuantityAreaTmp in ifcElementQuantity.Quantities.Items)
            {
                if (ifcQuantityAreaTmp.IsRef)
                {
                    IfcQuantityArea existingIfcQuantityArea = ifcQuantityAreaCollection.FirstOrDefault(item => item.Id == ifcQuantityAreaTmp.Ref);
                    if (existingIfcQuantityArea != null)
                    {
                        m_IfcQuantityAreaCollection.Add(existingIfcQuantityArea);
                    }
                }
            }

            IfcQuantityArea ifcQuantityArea = null;

            ifcQuantityArea = m_IfcQuantityAreaCollection.FirstOrDefault(item => item.Name.Equals("GrossFloorArea", StringComparison.OrdinalIgnoreCase));
            if (ifcQuantityArea == null)
            {
                ifcQuantityArea = new IfcQuantityArea()
                {
                    Id        = this.Document.GetNextSid(),
                    Name      = "GrossFloorArea",
                    AreaValue = GrossFloorArea
                };

                m_IfcQuantityAreaCollection.Add(ifcQuantityArea);
                this.Document.IfcXmlDocument.Items.Add(ifcQuantityArea);
                ifcElementQuantity.Quantities.Items.Add(new Ifc4.IfcQuantityArea()
                {
                    Ref = ifcQuantityArea.Id
                });
            }
            else
            {
                // read
                this.GrossFloorArea = ifcQuantityArea.AreaValue;
            }

            ifcQuantityArea = m_IfcQuantityAreaCollection.FirstOrDefault(item => item.Name.Equals("NetFloorArea", StringComparison.OrdinalIgnoreCase));
            if (ifcQuantityArea == null)
            {
                ifcQuantityArea = new IfcQuantityArea()
                {
                    Id        = this.Document.GetNextSid(),
                    Name      = "NetFloorArea",
                    AreaValue = NetFloorArea
                };

                m_IfcQuantityAreaCollection.Add(ifcQuantityArea);
                this.Document.IfcXmlDocument.Items.Add(ifcQuantityArea);
                ifcElementQuantity.Quantities.Items.Add(new Ifc4.IfcQuantityArea()
                {
                    Ref = ifcQuantityArea.Id
                });
            }
            else
            {
                // read
                this.NetFloorArea = ifcQuantityArea.AreaValue;
            }

            if (ifcElementQuantity.Id == null)
            {
                ifcElementQuantity.Id   = this.Document.GetNextSid();
                ifcElementQuantity.Name = "Qto_BuildingBaseQuantities";
                this.Document.IfcXmlDocument.Items.Add(ifcElementQuantity);

                Ifc4.IfcRelDefinesByProperties ifcRelDefinesByProperties = new Ifc4.IfcRelDefinesByProperties();
                ifcRelDefinesByProperties.Id                         = this.Document.GetNextSid();
                ifcRelDefinesByProperties.RelatedObjects             = this.RefInstance();
                ifcRelDefinesByProperties.RelatingPropertyDefinition = new Ifc4.IfcRelDefinesByPropertiesRelatingPropertyDefinition();


                // old
                // ifcRelDefinesByProperties.RelatingPropertyDefinition.Item = new Ifc4.IfcElementQuantity() { Ref = ifcElementQuantity.Id };

                // new
                ifcRelDefinesByProperties.RelatingPropertyDefinition.Item = ((IfcPropertySetDefinition)(new Ifc4.IfcElementQuantity()
                {
                    Ref = ifcElementQuantity.Id
                }));

                this.Document.IfcXmlDocument.Items.Add(ifcRelDefinesByProperties);
            }
        }
        /// <summary>
        /// Converts an IfcProperty to a COBie Attribute
        /// </summary>
        /// <param name="ifcProperty"></param>
        /// <returns></returns>
        static public Attribute ConvertToAttributeType(IfcProperty ifcProperty)
        {
            var attributeType = new Attribute
            {
                Description = ifcProperty.Description,
                Name        = ifcProperty.Name,
                Categories  = new List <Category>
                {
                    new Category {
                        Classification = "DPoW Status", Code = "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.Value = GetAttributeValueType(ifcPropertySingleValue);
            }
            else if (ifcPropertyEnumeratedValue != null)
            {
                var valueItem = new StringAttributeValue();
                attributeType.Value = valueItem;

                if (ifcPropertyEnumeratedValue.EnumerationReference != null && ifcPropertyEnumeratedValue.EnumerationReference.Unit != null)
                {
                    valueItem.Unit = ifcPropertyEnumeratedValue.EnumerationReference.Unit.GetName();
                }
                if (ifcPropertyEnumeratedValue.EnumerationValues.Count == 1)
                {
                    valueItem.Value = ifcPropertyEnumeratedValue.EnumerationValues[0].ToString();
                }
                else
                {
                    valueItem.Value = "";
                    foreach (var enumValue in ifcPropertyEnumeratedValue.EnumerationValues)
                    {
                        valueItem.Value += enumValue + ";";
                    }
                    valueItem.Value = valueItem.Value.TrimEnd(new[] { ';', ' ' });
                }
                //add in the allowed values

                if (ifcPropertyEnumeratedValue.EnumerationReference != null && ifcPropertyEnumeratedValue.EnumerationReference.EnumerationValues.Count > 0)
                {
                    var allowedValues = new List <string>(ifcPropertyEnumeratedValue.EnumerationReference.EnumerationValues.Count);

                    foreach (var enumValue in ifcPropertyEnumeratedValue.EnumerationReference.EnumerationValues)
                    {
                        allowedValues.Add(enumValue.ToString());
                    }
                }
            }
            else if (ifcPropertyBoundedValue != null)
            {
                attributeType.Value = 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);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="ifcProperty"></param>
        /// <typeparam name="TCoBieValueBaseType"></typeparam>
        /// <returns></returns>
        public static TCoBieValueBaseType ConvertAttribute <TCoBieValueBaseType>(IfcProperty ifcProperty) where TCoBieValueBaseType : AttributeValue, new()
        {
            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;

            var result = new TCoBieValueBaseType();

            if (ifcPropertySingleValue != null)
            {
                SetCoBieAttributeValue(result, ifcPropertySingleValue.NominalValue);
                if (ifcPropertySingleValue.Unit != null)
                {
                    result.Unit = ifcPropertySingleValue.Unit.GetName();
                }
            }
            else if (ifcPropertyEnumeratedValue != null)
            {
                if (ifcPropertyEnumeratedValue.EnumerationReference != null)
                {
                    result.Unit = ifcPropertyEnumeratedValue.EnumerationReference.Unit.GetName();
                }
                if (ifcPropertyEnumeratedValue.EnumerationValues.Count == 1)
                {
                    SetCoBieAttributeValue(result, ifcPropertyEnumeratedValue.EnumerationValues[0]);
                }
                else if (result is StringAttributeValue) //if it is a string we can add all the  values in a list
                {
                    var stringValueType = result as StringAttributeValue;
                    foreach (var enumValue in ifcPropertyEnumeratedValue.EnumerationValues)
                    {
                        stringValueType.Value += enumValue + ";";
                    }
                    stringValueType.Value = stringValueType.Value.TrimEnd(new[] { ';', ' ' });
                }
                else
                {
                    CoBieLiteUkHelper.Logger.WarnFormat("IfcPropertyEnumeratedValue Conversion: Multiple Enumerated values can only be stored in a string type");
                }
            }
            else if (ifcPropertyBoundedValue != null)
            {
                if (result is StringAttributeValue) //if it is a string we can add  the bounded values in a statement
                {
                    if (ifcPropertyBoundedValue.Unit != null)
                    {
                        result.Unit = ifcPropertyBoundedValue.Unit.GetName();
                    }
                    var stringValueType = result as StringAttributeValue;
                    stringValueType.Value = ifcPropertyBoundedValue.LowerBoundValue + " to " +
                                            ifcPropertyBoundedValue.UpperBoundValue;
                }
                else
                {
                    CoBieLiteUkHelper.Logger.WarnFormat("IfcPropertyBoundedValue Conversion: Bounded values can only be stored in a string type");
                }
            }
            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)
            {
                if (ifcPropertyListValue.Unit != null)
                {
                    result.Unit = ifcPropertyListValue.Unit.GetName();
                }
                if (ifcPropertyListValue.ListValues.Count == 1)
                {
                    SetCoBieAttributeValue(result, ifcPropertyListValue.ListValues[0]);
                }
                else if (result is StringAttributeValue) //if it is a string we can add all the  values in a list
                {
                    var stringValueType = result as StringAttributeValue;
                    foreach (var listValue in ifcPropertyListValue.ListValues)
                    {
                        stringValueType.Value += listValue + ";";
                    }
                    stringValueType.Value = stringValueType.Value.TrimEnd(new[] { ';', ' ' });
                }
                else
                {
                    CoBieLiteUkHelper.Logger.WarnFormat("IfcPropertyList Conversion: ValueMultiple List values can only be stored in a string type");
                }
            }

            return(result);
        }
Ejemplo n.º 8
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();
                attributeType.AttributeValue.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 string[ifcPropertyEnumeratedValue.EnumerationReference.EnumerationValues.Count]
                    };
                    int i = 0;
                    foreach (var enumValue in ifcPropertyEnumeratedValue.EnumerationReference.EnumerationValues)
                    {
                        allowedValues.AttributeAllowedValue[i] = enumValue.ToString();
                        i++;
                    }
                }
            }
            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);
        }
 public virtual void IfcParse(int propIndex, IPropertyValue value)
 {
     switch (propIndex)
     {
         case 0:
             _dependingProperty = (IfcProperty) value.EntityVal;
             break;
         case 1:
             _dependantProperty = (IfcProperty) value.EntityVal;
             break;
         case 2:
             _name = value.StringVal;
             break;
         case 3:
             _description = value.StringVal;
             break;
         case 4:
             _expression = value.StringVal;
             break;
         default:
             this.HandleUnexpectedAttribute(propIndex, value); break;
     }
 }
Ejemplo n.º 10
0
        private bool InternalRemove()
        {
            // throw new NotImplementedException("You must override Remove method.");

            if (this is Ifc4.Entity)
            {
                string sid = ((Ifc4.Entity) this).Id;

                List <Entity> removeEntities = new List <Entity>();

                // ------------------------------------------------------------------------------
                foreach (var ifcRelAggregates in this.Document.IfcXmlDocument.Items.OfType <IfcRelAggregates>())
                {
                    if (ifcRelAggregates.RelatedObjects != null && ifcRelAggregates.RelatedObjects.Items != null)
                    {
                        ifcRelAggregates.RelatedObjects.Items.RemoveAll(relatedObject => relatedObject.Ref == sid);
                        if (!ifcRelAggregates.RelatedObjects.Items.Any()) // has no items
                        {
                            removeEntities.Add(ifcRelAggregates);
                        }
                    }
                }
                // ------------------------------------------------------------------------------
                //< IfcRelAssociatesDocument GlobalId="0eDueiBMrB9AOMWod2KzTn">
                //  <RelatedObjects>
                //    <IfcProject ref="i1" xsi:nil="true" />
                //  </RelatedObjects>
                //  <RelatingDocument>
                //    <IfcDocumentInformation ref="i3302" xsi:nil="true" />
                //  </RelatingDocument>
                //</IfcRelAssociatesDocument>
                // ------------------------------------------------------------------------------
                foreach (var ifcRelAssociatesDocument in this.Document.IfcXmlDocument.Items.OfType <IfcRelAssociatesDocument>())
                {
                    if (ifcRelAssociatesDocument.RelatingDocument?.Item?.Ref == sid)
                    {
                        removeEntities.Add(ifcRelAssociatesDocument);
                    }
                }
                foreach (var ifcExternalReferenceRelationship in this.Document.IfcXmlDocument.Items.OfType <IfcExternalReferenceRelationship>())
                {
                    if (
                        ifcExternalReferenceRelationship.RelatedResourceObjects?.Items != null &&
                        ifcExternalReferenceRelationship.RelatedResourceObjects.Items.Any(item => item.Ref == sid)
                        )
                    {
                        ifcExternalReferenceRelationship.RelatedResourceObjects.Items.RemoveAll(relatedResourceObject => relatedResourceObject.Ref == sid);
                        if (!ifcExternalReferenceRelationship.RelatedResourceObjects.Items.Any()) // has no items
                        {
                            removeEntities.Add(ifcExternalReferenceRelationship);
                        }
                    }
                }
                // ------------------------------------------------------------------------------
                if (this.Parent is System.Collections.IList)
                {
                    var parent = (System.Collections.IList) this.Parent;
                    if (parent != null)
                    {
                        parent.Remove(this);
                    }
                }
                // ------------------------------------------------------------------------------
                foreach (var ifcRelDefinesByProperties in this.Document.IfcXmlDocument.Items.OfType <IfcRelDefinesByProperties>())
                {
                    if (ifcRelDefinesByProperties.RelatedObjects == null || ifcRelDefinesByProperties.RelatedObjects.Ref != sid)
                    {
                        continue;
                    }

                    if (ifcRelDefinesByProperties.RelatingPropertyDefinition == null || ifcRelDefinesByProperties.RelatingPropertyDefinition.Item == null)
                    {
                        continue;
                    }

                    //1. [System.Xml.Serialization.XmlElementAttribute("IfcElementQuantity", typeof(IfcElementQuantity), IsNullable = true)]
                    //2. [System.Xml.Serialization.XmlElementAttribute("IfcPropertySet", typeof(IfcPropertySet), IsNullable=true)]
                    //[System.Xml.Serialization.XmlElementAttribute("IfcPropertySetDefinition", typeof(IfcPropertySetDefinition), IsNullable=true)]
                    //[System.Xml.Serialization.XmlElementAttribute("IfcPropertySetDefinitionSet-wrapper", typeof(IfcPropertySetDefinitionSetwrapper), IsNullable=true)]

                    // --------------------------------------------------------------------------------
                    // 1.
                    if (ifcRelDefinesByProperties.RelatingPropertyDefinition.Item is IfcElementQuantity)
                    {
                        IfcElementQuantity ifcElementQuantity = (IfcElementQuantity)ifcRelDefinesByProperties.RelatingPropertyDefinition.Item;
                        if (ifcElementQuantity.IsRef)
                        {
                            ifcElementQuantity = this.Document.IfcXmlDocument.Items.OfType <IfcElementQuantity>().FirstOrDefault(item => item.Id == ifcElementQuantity.Ref);
                        }

                        if (ifcElementQuantity.Quantities != null && ifcElementQuantity.Quantities.Items != null)
                        {
                            foreach (var quantityItem in ifcElementQuantity.Quantities.Items)
                            {
                                IfcPhysicalQuantity ifcPhysicalQuantity = quantityItem;
                                if (ifcPhysicalQuantity.IsRef)
                                {
                                    ifcPhysicalQuantity = this.Document.IfcXmlDocument.Items.OfType <IfcPhysicalQuantity>().FirstOrDefault(item => item.Id == ifcPhysicalQuantity.Ref);
                                }

                                removeEntities.Add(ifcPhysicalQuantity);
                            }
                            ifcElementQuantity.Quantities.Items.Clear();
                            removeEntities.Add(ifcElementQuantity);
                        }
                    }
                    // --------------------------------------------------------------------------------
                    // 2.
                    else if (ifcRelDefinesByProperties.RelatingPropertyDefinition.Item is IfcPropertySet)
                    {
                        IfcPropertySet ifcPropertySet = (IfcPropertySet)ifcRelDefinesByProperties.RelatingPropertyDefinition.Item;
                        if (ifcPropertySet.IsRef)
                        {
                            ifcPropertySet = this.Document.IfcXmlDocument.Items.OfType <IfcPropertySet>().FirstOrDefault(item => item.Id == ifcPropertySet.Ref);
                        }

                        if (ifcPropertySet.HasProperties != null && ifcPropertySet.HasProperties.Items != null)
                        {
                            foreach (var ifcPropertyItem in ifcPropertySet.HasProperties.Items)
                            {
                                IfcProperty ifcProperty = ifcPropertyItem;
                                if (ifcProperty.IsRef)
                                {
                                    ifcProperty = this.Document.IfcXmlDocument.Items.OfType <IfcProperty>().FirstOrDefault(item => item.Id == ifcProperty.Ref);
                                }

                                removeEntities.Add(ifcProperty);
                            }
                            ifcPropertySet.HasProperties.Items.Clear();
                        }

                        // ------------------------------------------------------------------------------
                        foreach (var ifcRelDefinesByTemplate in this.Document.IfcXmlDocument.Items.OfType <IfcRelDefinesByTemplate>())
                        {
                            if (ifcRelDefinesByTemplate.RelatedPropertySets != null && ifcRelDefinesByTemplate.RelatedPropertySets.Items != null)
                            {
                                ifcRelDefinesByTemplate.RelatedPropertySets.Items.RemoveAll(relatedPropertySet => relatedPropertySet.Ref == ifcPropertySet.Id);
                                if (!ifcRelDefinesByTemplate.RelatedPropertySets.Items.Any()) // has no items
                                {
                                    removeEntities.Add(ifcRelDefinesByTemplate);
                                }
                            }
                        }

                        removeEntities.Add(ifcPropertySet);
                    }
                    else
                    {
                    }

                    removeEntities.Add(ifcRelDefinesByProperties);
                }
                // ------------------------------------------------------------------------------
                foreach (var ifcRelAssignsToGroup in this.Document.IfcXmlDocument.Items.OfType <IfcRelAssignsToGroup>())
                {
                    if (ifcRelAssignsToGroup.RelatedObjects != null && ifcRelAssignsToGroup.RelatedObjects.Items != null)
                    {
                        ifcRelAssignsToGroup.RelatedObjects.Items.RemoveAll(relatedObject => relatedObject.Ref == sid);
                        if (!ifcRelAssignsToGroup.RelatedObjects.Items.Any()) // has no items
                        {
                            removeEntities.Add(ifcRelAssignsToGroup);
                        }
                    }
                }
                // ------------------------------------------------------------------------------
                foreach (var ifcRelAssociatesClassification in this.Document.IfcXmlDocument.Items.OfType <IfcRelAssociatesClassification>())
                {
                    if (ifcRelAssociatesClassification.RelatedObjects != null && ifcRelAssociatesClassification.RelatedObjects.Items != null)
                    {
                        ifcRelAssociatesClassification.RelatedObjects.Items.RemoveAll(relatedObject => relatedObject.Ref == sid);
                        if (!ifcRelAssociatesClassification.RelatedObjects.Items.Any()) // has no items
                        {
                            removeEntities.Add(ifcRelAssociatesClassification);
                        }
                    }
                }
                // ------------------------------------------------------------------------------
                removeEntities.Add(((Ifc4.Entity) this));
                this.Document.IfcXmlDocument.Items.RemoveAll(item => removeEntities.Contains(item));
                // ------------------------------------------------------------------------------
            }
            return(true);
        }
        public static int GetPropertyHash(this IfcProperty property)
        {
            if (property == null)
            {
                return(0);
            }

            //check actual value
            switch (property.GetType().Name)
            {
            case "IfcPropertySingleValue":
                var baseVal = ((IfcPropertySingleValue)(property)).NominalValue;
                var baseStr = baseVal == null ? "" : baseVal.ToString();
                return("IfcPropertySingleValue".GetHashCode() + baseStr.GetHashCode());

            case "IfcPropertyEnumeratedValue":
                var baseEnum = property as IfcPropertyEnumeratedValue;
                int enumHash = "IfcPropertyEnumeratedValue".GetHashCode();
                foreach (var e in baseEnum.EnumerationValues)
                {
                    enumHash += e.ToString().GetHashCode();
                }
                return(enumHash);

            case "IfcPropertyBoundedValue":
                var baseBounded = property as IfcPropertyBoundedValue;
                return("IfcPropertyBoundedValue".GetHashCode() + baseBounded.UpperBoundValue.ToString().GetHashCode()
                       + baseBounded.LowerBoundValue.ToString().GetHashCode());

            case "IfcPropertyTableValue":
                var baseTable = property as IfcPropertyTableValue;
                //check all table items
                int tableHash = "IfcPropertyTableValue".GetHashCode();
                for (int i = 0; i < baseTable.DefiningValues.Count; i++)
                {
                    tableHash +=
                        baseTable.DefiningValues[i].ToString().GetHashCode() +
                        baseTable.DefinedValues[i].ToString().GetHashCode();
                }
                return(tableHash);

            case "IfcPropertyReferenceValue":
                var baseRef = property as IfcPropertyReferenceValue;
                var refHash = "IfcPropertyReferenceValue".GetHashCode();
                refHash += baseRef.UsageName.ToString().GetHashCode();
                refHash += baseRef.PropertyReference.GetType().GetHashCode();
                //should go deeper but it would be too complicated for now
                return(refHash);

            case "IfcPropertyListValue":
                var baseList = property as IfcPropertyListValue;
                var listHash = "IfcPropertyListValue".GetHashCode();
                foreach (var item in baseList.ListValues)
                {
                    listHash += item.ToString().GetHashCode();
                }
                return(listHash);

            default:
                break;
            }
            throw new NotImplementedException();
        }
Ejemplo n.º 12
0
            private bool HasEquivalent(IfcProperty property, IfcPropertySet revisionPset)
            {
                //check if property with the same name even exist
                var candidate = revisionPset.HasProperties.Where(p => p.Name == property.Name).FirstOrDefault();

                if (candidate == null)
                {
                    return(false);
                }

                //check actual value
                switch (property.GetType().Name)
                {
                case "IfcPropertySingleValue":
                    var single = candidate as IfcPropertySingleValue;
                    if (single == null)
                    {
                        return(false);
                    }
                    var revVal  = single.NominalValue;
                    var baseVal = ((IfcPropertySingleValue)(property)).NominalValue;
                    var revStr  = revVal == null ? "" : revVal.ToString();
                    var baseStr = baseVal == null ? "" : baseVal.ToString();
                    if (baseStr != revStr)
                    {
                        return(false);
                    }
                    break;

                case "IfcPropertyEnumeratedValue":
                    var enumerated = candidate as IfcPropertyEnumeratedValue;
                    if (enumerated == null)
                    {
                        return(false);
                    }
                    var baseEnum = property as IfcPropertyEnumeratedValue;
                    if (baseEnum.EnumerationValues.Count != enumerated.EnumerationValues.Count)
                    {
                        return(false);
                    }
                    foreach (var e in baseEnum.EnumerationValues)
                    {
                        if (!enumerated.EnumerationValues.Contains(e))
                        {
                            return(false);
                        }
                    }
                    break;

                case "IfcPropertyBoundedValue":
                    var bounded = candidate as IfcPropertyBoundedValue;
                    if (bounded == null)
                    {
                        return(false);
                    }
                    var baseBounded = property as IfcPropertyBoundedValue;
                    if (bounded.LowerBoundValue != baseBounded.LowerBoundValue)
                    {
                        return(false);
                    }
                    if (baseBounded.UpperBoundValue != bounded.UpperBoundValue)
                    {
                        return(false);
                    }
                    break;

                case "IfcPropertyTableValue":
                    var table = candidate as IfcPropertyTableValue;
                    if (table == null)
                    {
                        return(false);
                    }
                    var baseTable = property as IfcPropertyTableValue;
                    if (baseTable.DefiningValues.Count != table.DefiningValues.Count)
                    {
                        return(false);
                    }
                    //check all table items
                    foreach (var item in baseTable.DefiningValues)
                    {
                        var revDefiningValue = table.DefiningValues.Where(v => v.ToString() == item.ToString()).FirstOrDefault();
                        if (revDefiningValue == null)
                        {
                            return(false);
                        }
                        var revIndex  = table.DefiningValues.IndexOf(revDefiningValue);
                        var baseIndex = baseTable.DefiningValues.IndexOf(item);
                        if (table.DefinedValues[revIndex].ToString() != baseTable.DefinedValues[baseIndex].ToString())
                        {
                            return(false);
                        }
                    }
                    break;

                case "IfcPropertyReferenceValue":
                    var reference = candidate as IfcPropertyReferenceValue;
                    if (reference == null)
                    {
                        return(false);
                    }
                    var baseRef = property as IfcPropertyReferenceValue;
                    if (reference.UsageName != baseRef.UsageName)
                    {
                        return(false);
                    }
                    if (reference.PropertyReference.GetType() != baseRef.PropertyReference.GetType())
                    {
                        return(false);
                    }
                    //should go deeper but it would be too complicated for now
                    break;

                case "IfcPropertyListValue":
                    var list = candidate as IfcPropertyListValue;
                    if (list == null)
                    {
                        return(false);
                    }
                    var baseList = property as IfcPropertyListValue;
                    if (baseList.ListValues.Count != list.ListValues.Count)
                    {
                        return(false);
                    }
                    foreach (var item in baseList.ListValues)
                    {
                        if (!list.ListValues.Contains(item))
                        {
                            return(false);
                        }
                    }
                    break;

                default:
                    break;
                }
                return(true);
            }