/// <summary>
        /// Set the area measure to the building
        /// </summary>
        /// <param name="ifcBuilding">Building object</param>
        /// <param name="row">COBieFacilityRow object holding data</param>
        private void SetAreaMeasure(IfcBuilding ifcBuilding, COBieFacilityRow row)
        {
            IfcSIUnit ifcSIUnitArea = null;

            if (ValidateString(row.AreaUnits))
            {
                ifcSIUnitArea = GetSIUnit(row.AreaUnits);
            }
            string areaMeasure = string.Empty;

            if (ValidateString(row.AreaMeasurement))
            {
                areaMeasure = row.AreaMeasurement;
            }

            IfcQuantityArea IfcQuantityArea = Model.Instances.New <IfcQuantityArea>(qa =>
            {
                qa.Unit        = ifcSIUnitArea;
                qa.Name        = "AreaMeasure";
                qa.Description = "Created to maintain COBie information";
            });
            IfcElementQuantity ifcElementQuantity = Model.Instances.New <IfcElementQuantity>(eq =>
            {
                eq.Quantities.Add(IfcQuantityArea);
                eq.MethodOfMeasurement = areaMeasure;
                eq.Description         = "Created to maintain COBie information";
            });
            IfcRelDefinesByProperties ifcRelDefinesByProperties = Model.Instances.New <IfcRelDefinesByProperties>(rdbp =>
            {
                rdbp.RelatedObjects.Add(ifcBuilding);
                rdbp.RelatingPropertyDefinition = ifcElementQuantity;
                rdbp.Description = "Created to maintain COBie information";
            });
        }
        public static void SetElementPhysicalSimpleQuantity(this IfcObject elem, string qSetName, string qualityName, double value, XbimQuantityTypeEnum quantityType, IfcNamedUnit unit)
        {
            IModel model = elem.ModelOf;

            IfcElementQuantity qset = GetElementQuantity(elem, qSetName);

            if (qset == null)
            {
                qset      = model.Instances.New <IfcElementQuantity>();
                qset.Name = qSetName;
                IfcRelDefinesByProperties relDef = model.Instances.New <IfcRelDefinesByProperties>();
                relDef.RelatingPropertyDefinition = qset;
                relDef.RelatedObjects.Add(elem);
            }

            //remove existing simple quality
            IfcPhysicalSimpleQuantity simpleQuality = GetElementPhysicalSimpleQuantity(elem, qSetName, qualityName);

            if (simpleQuality != null)
            {
                IfcElementQuantity elementQuality = GetElementQuantity(elem, qSetName);
                elementQuality.Quantities.Remove(simpleQuality);
                model.Delete(simpleQuality);
            }

            switch (quantityType)
            {
            case XbimQuantityTypeEnum.AREA:
                simpleQuality = model.Instances.New <IfcQuantityArea>(sq => sq.AreaValue = (IfcAreaMeasure)value);
                break;

            case XbimQuantityTypeEnum.COUNT:
                simpleQuality = model.Instances.New <IfcQuantityCount>(sq => sq.CountValue = (IfcCountMeasure)value);
                break;

            case XbimQuantityTypeEnum.LENGTH:
                simpleQuality = model.Instances.New <IfcQuantityLength>(sq => sq.LengthValue = (IfcLengthMeasure)value);
                break;

            case XbimQuantityTypeEnum.TIME:
                simpleQuality = model.Instances.New <IfcQuantityTime>(sq => sq.TimeValue = (IfcTimeMeasure)value);
                break;

            case XbimQuantityTypeEnum.VOLUME:
                simpleQuality = model.Instances.New <IfcQuantityVolume>(sq => sq.VolumeValue = (IfcVolumeMeasure)value);
                break;

            case XbimQuantityTypeEnum.WEIGHT:
                simpleQuality = model.Instances.New <IfcQuantityWeight>(sq => sq.WeightValue = (IfcMassMeasure)value);
                break;

            default:
                return;
            }

            simpleQuality.Unit = unit;
            simpleQuality.Name = qualityName;

            qset.Quantities.Add(simpleQuality);
        }
        public static void RemoveElementPhysicalSimpleQuantity(this IfcObject elem, string pSetName, string qualityName)
        {
            IfcElementQuantity elementQuality = GetElementQuantity(elem, pSetName);

            if (elementQuality != null)
            {
                IfcPhysicalSimpleQuantity simpleQuality = elementQuality.Quantities.Where <IfcPhysicalSimpleQuantity>(sq => sq.Name == qualityName).FirstOrDefault();
                if (simpleQuality != null)
                {
                    elementQuality.Quantities.Remove(simpleQuality);
                }
            }
        }
        /// <summary>
        /// Returns simple physical quality of the element.
        /// </summary>
        /// <param name="elem"></param>
        /// <param name="pSetName"></param>
        /// <param name="qualityName"></param>
        /// <returns></returns>
        public static IfcPhysicalSimpleQuantity GetElementPhysicalSimpleQuantity(this IfcObject elem, string pSetName, string qualityName)
        {
            IfcElementQuantity elementQuality = GetElementQuantity(elem, pSetName);

            if (elementQuality != null)
            {
                return(elementQuality.Quantities.Where <IfcPhysicalSimpleQuantity>(sq => sq.Name == qualityName).FirstOrDefault());
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// Returns the first quantity that matches the quantity name
        /// </summary>
        /// <typeparam name="QType"></typeparam>
        /// <param name="elem"></param>
        /// <param name="qName"></param>
        /// <returns></returns>
        public static QType GetQuantity <QType>(this IfcObject elem, string qName) where QType : IfcPhysicalQuantity
        {
            IfcRelDefinesByProperties rel = elem.IsDefinedByProperties.Where(r => r.RelatingPropertyDefinition is IfcElementQuantity).FirstOrDefault();

            if (rel != null)
            {
                IfcElementQuantity eQ = rel.RelatingPropertyDefinition as IfcElementQuantity;
                if (eQ != null)
                {
                    QType result = eQ.Quantities.Where <QType>(q => q.Name == qName).FirstOrDefault();
                    return(result);
                }
            }
            return(default(QType));
        }
Example #6
0
 private void AddQuantityPSet(IfcElementQuantity pSet, IfcUnitAssignment modelUnits)
 {
     if (pSet == null)
     {
         return;
     }
     foreach (var item in pSet.Quantities.OfType <IfcPhysicalSimpleQuantity>())
     // currently only handles IfcPhysicalSimpleQuantity
     {
         var v = modelUnits.GetUnitFor(item);
         _quantities.Add(new PropertyItem
         {
             PropertySetName = pSet.Name,
             Name            = item.Name,
             Value           = item + " " + v.GetName()
         });
     }
 }
Example #7
0
        public Ifc4.IfcElementQuantity GetIfcElementQuantityFromRelatingPropertyDefinition()
        {
            Ifc4.Document document = this.Document;
            m_IfcElementQuantities = null;

            IfcElementQuantity ifcElementQuantity = (from ifcRelDefinesByProperties in document.IfcXmlDocument.Items.OfType <Ifc4.IfcRelDefinesByProperties>()
                                                     where ifcRelDefinesByProperties.RelatedObjects != null &&
                                                     ifcRelDefinesByProperties.RelatedObjects.Ref == this.Id &&
                                                     ifcRelDefinesByProperties.RelatingPropertyDefinition != null &&
                                                     ifcRelDefinesByProperties.RelatingPropertyDefinition.Item is IfcElementQuantity
                                                     select ifcRelDefinesByProperties.RelatingPropertyDefinition.Item).FirstOrDefault() as IfcElementQuantity;

            if (ifcElementQuantity != null && ifcElementQuantity.IsRef)
            {
                ifcElementQuantity = document.IfcXmlDocument.Items.OfType <IfcElementQuantity>().FirstOrDefault(item => item.Id == ifcElementQuantity.Ref);
            }

            return(ifcElementQuantity);
        }
        /// <summary>
        /// Adds a new IfcPhysicalQuantity to the IfcElementQuantity called propertySetName
        /// </summary>
        /// <param name="elem"></param>
        /// <param name="propertySetName">Name of the IfcElementQuantity property set</param>
        /// <param name="quantity">quantity to be added</param>
        /// <param name="methodOfMeasurement">Sets the method of measurement, if not null overrides previous value</param>
        public static IfcElementQuantity AddQuantity(this IfcObject elem, string propertySetName, IfcPhysicalQuantity quantity, string methodOfMeasurement)
        {
            IfcElementQuantity pset = elem.GetElementQuantity(propertySetName);

            if (pset == null)
            {
                IModel model = elem.ModelOf;
                pset      = model.Instances.New <IfcElementQuantity>();
                pset.Name = propertySetName;
                IfcRelDefinesByProperties relDef = model.Instances.New <IfcRelDefinesByProperties>();
                relDef.RelatingPropertyDefinition = pset;
                relDef.RelatedObjects.Add(elem);
            }
            pset.Quantities.Add(quantity);
            if (!string.IsNullOrEmpty(methodOfMeasurement))
            {
                pset.MethodOfMeasurement = methodOfMeasurement;
            }
            return(pset);
        }
 BbQuantityRequired()
 {
     IfcQuantityCount = new IfcQuantityCount
                            {
                                Name = "Quantity",
                                CountValue = 0,
                            };
     IfcElementQuantity = new IfcElementQuantity
                              {
                                  GlobalId = IfcGloballyUniqueId.NewGuid(),
                                  OwnerHistory = BbHeaderSetting.Setting3D.IfcOwnerHistory,
                                  Quantities = new List<IfcPhysicalQuantity>{IfcQuantityCount},
                              };
     IfcRelDefinesByProperties = new IfcRelDefinesByProperties
                                     {
                                         GlobalId = IfcGloballyUniqueId.NewGuid(),
                                         OwnerHistory = BbHeaderSetting.Setting3D.IfcOwnerHistory,
                                         RelatedObjects = new List<IfcObject>(),
                                         RelatingPropertyDefinition = IfcElementQuantity,
                                     };
 }
 BbQuantityRequired()
 {
     IfcQuantityCount = new IfcQuantityCount
     {
         Name       = "Quantity",
         CountValue = 0,
     };
     IfcElementQuantity = new IfcElementQuantity
     {
         GlobalId     = IfcGloballyUniqueId.NewGuid(),
         OwnerHistory = BbHeaderSetting.Setting3D.IfcOwnerHistory,
         Quantities   = new List <IfcPhysicalQuantity> {
             IfcQuantityCount
         },
     };
     IfcRelDefinesByProperties = new IfcRelDefinesByProperties
     {
         GlobalId                   = IfcGloballyUniqueId.NewGuid(),
         OwnerHistory               = BbHeaderSetting.Setting3D.IfcOwnerHistory,
         RelatedObjects             = new List <IfcObject>(),
         RelatingPropertyDefinition = IfcElementQuantity,
     };
 }
        private void FillQuantityData()
        {
            if (_quantities.Count > 0)
            {
                return;                        //don't fill unless empty
            }
            //now the property sets for any
            IfcObject ifcObj = _entity as IfcObject;
            // local cache for efficiency
            IfcUnitAssignment modelUnits = null;

            if (ifcObj != null)
            {
                foreach (IfcRelDefinesByProperties relDef in ifcObj.IsDefinedByProperties.Where(r => r.RelatingPropertyDefinition is IfcElementQuantity))
                {
                    IfcElementQuantity pSet = relDef.RelatingPropertyDefinition as IfcElementQuantity;
                    if (pSet != null)
                    {
                        foreach (var item in pSet.Quantities.OfType <IfcPhysicalSimpleQuantity>()) //only handle simple quantities properties
                        {
                            if (modelUnits == null)
                            {
                                modelUnits = item.ModelOf.Instances.OfType <IfcUnitAssignment>().FirstOrDefault(); // not optional, should never return void in valid model
                            }
                            var v = modelUnits.GetUnitFor(item);
                            _quantities.Add(new PropertyItem()
                            {
                                PropertySetName = pSet.Name,
                                Name            = item.Name,
                                Value           = item.ToString() + " " + v.GetName()
                            });
                        }
                    }
                }
            }
        }
Example #12
0
        public void InitializeAdditionalProperties()
        {
            Ifc4.IfcElementQuantity         ifcElementQuantity          = this.GetIfcElementQuantityFromRelatingPropertyDefinition();
            IEnumerable <IfcQuantityLength> ifcQuantityLengthCollection = this.Document.IfcXmlDocument.Items.OfType <IfcQuantityLength>().ToList();
            IEnumerable <IfcQuantityArea>   ifcQuantityAreaCollection   = this.Document.IfcXmlDocument.Items.OfType <IfcQuantityArea>().ToList();
            IEnumerable <IfcQuantityVolume> ifcQuantityVolumeCollection = this.Document.IfcXmlDocument.Items.OfType <IfcQuantityVolume>().ToList();

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

            if (ifcElementQuantity.Quantities == null)
            {
                ifcElementQuantity.Quantities = new IfcElementQuantityQuantities();
            }
            // ---------------------------------------------------------------------------------------
            m_IfcQuantityLengthCollection = new List <IfcQuantityLength>();
            m_IfcQuantityAreaCollection   = new List <IfcQuantityArea>();
            m_IfcQuantityVolumeCollection = new List <IfcQuantityVolume>();

            foreach (IfcPhysicalQuantity ifcPhysicalQuantityTmp in ifcElementQuantity.Quantities.Items)
            {
                if (ifcPhysicalQuantityTmp.IsRef && ifcPhysicalQuantityTmp is IfcQuantityLength)
                {
                    IfcQuantityLength existingIfcQuantityLength = ifcQuantityLengthCollection.FirstOrDefault(item => item.Id == ifcPhysicalQuantityTmp.Ref);
                    if (existingIfcQuantityLength != null)
                    {
                        m_IfcQuantityLengthCollection.Add(existingIfcQuantityLength);
                    }
                }
                else if (ifcPhysicalQuantityTmp.IsRef && ifcPhysicalQuantityTmp is IfcQuantityArea)
                {
                    IfcQuantityArea existingIfcQuantityArea = ifcQuantityAreaCollection.FirstOrDefault(item => item.Id == ifcPhysicalQuantityTmp.Ref);
                    if (existingIfcQuantityArea != null)
                    {
                        m_IfcQuantityAreaCollection.Add(existingIfcQuantityArea);
                    }
                }
                else if (ifcPhysicalQuantityTmp.IsRef && ifcPhysicalQuantityTmp is IfcQuantityVolume)
                {
                    IfcQuantityVolume existingIfcQuantityVolume = ifcQuantityVolumeCollection.FirstOrDefault(item => item.Id == ifcPhysicalQuantityTmp.Ref);
                    if (existingIfcQuantityVolume != null)
                    {
                        m_IfcQuantityVolumeCollection.Add(existingIfcQuantityVolume);
                    }
                }
            }
            // ---------------------------------------------------------------------------------------
            string[] ifcQuantityLengthNames = new string[]
            {
                nameof(GrossHeight),
                nameof(NetHeight),
                nameof(GrossPerimeter)
            };
            foreach (var ifcQuantityLengthName in ifcQuantityLengthNames)
            {
                var ifcQuantityLengthPropertyInfo = this.GetType().GetProperty(ifcQuantityLengthName);
                if (ifcQuantityLengthPropertyInfo == null)
                {
                    continue;
                }

                var ifcQuantityLength = m_IfcQuantityLengthCollection.FirstOrDefault(item => item.Name.Equals(ifcQuantityLengthName, StringComparison.OrdinalIgnoreCase));
                if (ifcQuantityLength == null)
                {
                    ifcQuantityLength = new IfcQuantityLength()
                    {
                        Id          = this.Document.GetNextSid(),
                        Name        = ifcQuantityLengthName,
                        LengthValue = (double)ifcQuantityLengthPropertyInfo.GetValue(this, null)
                    };
                    m_IfcQuantityLengthCollection.Add(ifcQuantityLength);
                    this.Document.IfcXmlDocument.Items.Add(ifcQuantityLength);
                    ifcElementQuantity.Quantities.Items.Add(new Ifc4.IfcQuantityLength()
                    {
                        Ref = ifcQuantityLength.Id
                    });
                }
                else
                {
                    // read
                    ifcQuantityLengthPropertyInfo.SetValue(this, ifcQuantityLength.LengthValue, null);
                }
            }
            // ---------------------------------------------------------------------------------------
            string[] ifcQuantityAreaNames = new string[]
            {
                nameof(GrossFloorArea),
                nameof(NetFloorArea)
            };
            foreach (var ifcQuantityAreaName in ifcQuantityAreaNames)
            {
                var ifcQuantityAreaPropertyInfo = this.GetType().GetProperty(ifcQuantityAreaName);
                if (ifcQuantityAreaPropertyInfo == null)
                {
                    continue;
                }

                var ifcQuantityArea = m_IfcQuantityAreaCollection.FirstOrDefault(item => item.Name.Equals(ifcQuantityAreaName, StringComparison.OrdinalIgnoreCase));
                if (ifcQuantityArea == null)
                {
                    ifcQuantityArea = new IfcQuantityArea()
                    {
                        Id        = this.Document.GetNextSid(),
                        Name      = ifcQuantityAreaName,
                        AreaValue = (double)ifcQuantityAreaPropertyInfo.GetValue(this, null)
                    };
                    m_IfcQuantityAreaCollection.Add(ifcQuantityArea);
                    this.Document.IfcXmlDocument.Items.Add(ifcQuantityArea);
                    ifcElementQuantity.Quantities.Items.Add(new Ifc4.IfcQuantityArea()
                    {
                        Ref = ifcQuantityArea.Id
                    });
                }
                else
                {
                    // read
                    ifcQuantityAreaPropertyInfo.SetValue(this, ifcQuantityArea.AreaValue, null);
                }
            }
            // ---------------------------------------------------------------------------------------
            string[] ifcQuantityVolumeNames = new string[]
            {
                nameof(GrossVolume),
                nameof(NetVolume)
            };
            foreach (var ifcQuantityVolumeName in ifcQuantityVolumeNames)
            {
                var ifcQuantityVolumePropertyInfo = this.GetType().GetProperty(ifcQuantityVolumeName);
                if (ifcQuantityVolumePropertyInfo == null)
                {
                    continue;
                }

                var ifcQuantityVolume = m_IfcQuantityVolumeCollection.FirstOrDefault(item => item.Name.Equals(ifcQuantityVolumeName, StringComparison.OrdinalIgnoreCase));
                if (ifcQuantityVolume == null)
                {
                    ifcQuantityVolume = new IfcQuantityVolume()
                    {
                        Id          = this.Document.GetNextSid(),
                        Name        = ifcQuantityVolumeName,
                        VolumeValue = (double)ifcQuantityVolumePropertyInfo.GetValue(this, null)
                    };
                    m_IfcQuantityVolumeCollection.Add(ifcQuantityVolume);
                    this.Document.IfcXmlDocument.Items.Add(ifcQuantityVolume);
                    ifcElementQuantity.Quantities.Items.Add(new Ifc4.IfcQuantityVolume()
                    {
                        Ref = ifcQuantityVolume.Id
                    });
                }
                else
                {
                    // read
                    ifcQuantityVolumePropertyInfo.SetValue(this, ifcQuantityVolume.VolumeValue, null);
                }
            }
            // ---------------------------------------------------------------------------------------
            if (ifcElementQuantity.Id == null)
            {
                ifcElementQuantity.Id   = this.Document.GetNextSid();
                ifcElementQuantity.Name = "Qto_BuildingStoreyBaseQuantities";
                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();
                ifcRelDefinesByProperties.RelatingPropertyDefinition.Item = new Ifc4.IfcElementQuantity()
                {
                    Ref = ifcElementQuantity.Id
                };
                this.Document.IfcXmlDocument.Items.Add(ifcRelDefinesByProperties);
            }
        }
Example #13
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);
        }
Example #14
0
        /// <summary>
        /// Fill sheet rows for Facility sheet
        /// </summary>
        /// <returns>COBieSheet</returns>
        public override COBieSheet <COBieFacilityRow> Fill()
        {
            ProgressIndicator.ReportMessage("Starting Facilities...");

            //Create new sheet
            COBieSheet <COBieFacilityRow> facilities = new COBieSheet <COBieFacilityRow>(Constants.WORKSHEET_FACILITY);

            IfcProject  ifcProject  = Model.IfcProject as IfcProject;
            IfcSite     ifcSite     = Model.Instances.OfType <IfcSite>().FirstOrDefault();
            IfcBuilding ifcBuilding = Model.Instances.OfType <IfcBuilding>().FirstOrDefault();

            //get Element Quantity holding area values as used for AreaMeasurement below
            IfcElementQuantity ifcElementQuantityAreas = Model.Instances.OfType <IfcElementQuantity>().Where(eq => eq.Quantities.OfType <IfcQuantityArea>().Count() > 0).FirstOrDefault();

            List <IfcObject> ifcObjectList = new List <IfcObject>();

            if (ifcProject != null)
            {
                ifcObjectList.Add(ifcProject);
            }
            if (ifcSite != null)
            {
                ifcObjectList.Add(ifcSite);
            }
            if (ifcBuilding != null)
            {
                ifcObjectList.Add(ifcBuilding);
            }

            IEnumerable <IfcObject> ifcObjects = ifcObjectList.AsEnumerable();

            if (ifcObjects.Any())
            {
                COBieDataPropertySetValues allPropertyValues = new COBieDataPropertySetValues(); //properties helper class
                COBieDataAttributeBuilder  attributeBuilder  = new COBieDataAttributeBuilder(Context, allPropertyValues);
                attributeBuilder.InitialiseAttributes(ref _attributes);

                //list of attributes to exclude form attribute sheet
                //set up filters on COBieDataPropertySetValues for the SetAttributes only
                attributeBuilder.ExcludeAttributePropertyNames.AddRange(Context.Exclude.Facility.AttributesEqualTo);
                attributeBuilder.ExcludeAttributePropertyNamesWildcard.AddRange(Context.Exclude.Facility.AttributesContain);
                attributeBuilder.RowParameters["Sheet"] = "Facility";

                COBieFacilityRow facility = new COBieFacilityRow(facilities);

                string name = "";
                if ((ifcBuilding != null) && (!string.IsNullOrEmpty(ifcBuilding.Name)))
                {
                    name = ifcBuilding.Name;
                }
                else if ((ifcSite != null) && (!string.IsNullOrEmpty(ifcSite.Name)))
                {
                    name = ifcSite.Name;
                }
                else if ((ifcProject != null) && (!string.IsNullOrEmpty(ifcProject.Name)))
                {
                    name = ifcProject.Name;
                }
                else
                {
                    name = DEFAULT_STRING;
                }

                facility.Name = (string.IsNullOrEmpty(name)) ? "The Facility Name Here" : name;

                IfcValue createBy = ifcBuilding.GetPropertySingleNominalValue("Other", "COBieCreatedBy");  //support for COBie Toolkit for Autodesk Revit
                facility.CreatedBy = ((createBy != null) && ValidateString(createBy.ToString())) ? createBy.ToString() : GetTelecomEmailAddress(ifcBuilding.OwnerHistory);
                IfcValue createdOn = ifcBuilding.GetPropertySingleNominalValue("Other", "COBieCreatedOn"); //support for COBie Toolkit for Autodesk Revit
                facility.CreatedOn = ((createdOn != null) && ValidateString(createdOn.ToString())) ? createdOn.ToString() : GetCreatedOnDateAsFmtString(ifcBuilding.OwnerHistory);

                facility.Category = GetCategory(ifcBuilding);

                facility.ProjectName = GetFacilityProjectName(ifcProject);
                facility.SiteName    = GetFacilitySiteName(ifcSite);

                facility.LinearUnits  = Context.WorkBookUnits.LengthUnit;
                facility.AreaUnits    = Context.WorkBookUnits.AreaUnit;
                facility.VolumeUnits  = Context.WorkBookUnits.VolumeUnit;
                facility.CurrencyUnit = Context.WorkBookUnits.MoneyUnit;

                string AreaMeasurement = (ifcElementQuantityAreas == null) ? DEFAULT_STRING : ifcElementQuantityAreas.MethodOfMeasurement.ToString();

                facility.AreaMeasurement = ((AreaMeasurement == DEFAULT_STRING) || (AreaMeasurement.ToLower().Contains("bim area"))) ? AreaMeasurement : AreaMeasurement + " BIM Area";
                facility.ExternalSystem  = GetExternalSystem(ifcBuilding);

                facility.ExternalProjectObject     = "IfcProject";
                facility.ExternalProjectIdentifier = ifcProject.GlobalId;

                facility.ExternalSiteObject     = "IfcSite";
                facility.ExternalSiteIdentifier = (ifcSite != null) ? ifcSite.GlobalId.ToString() : DEFAULT_STRING;

                facility.ExternalFacilityObject     = "IfcBuilding";
                facility.ExternalFacilityIdentifier = ifcBuilding.GlobalId;

                facility.Description        = GetFacilityDescription(ifcBuilding);
                facility.ProjectDescription = GetFacilityProjectDescription(ifcProject);
                facility.SiteDescription    = GetFacilitySiteDescription(ifcSite);
                facility.Phase = (string.IsNullOrEmpty(Model.IfcProject.Phase.ToString())) ? DEFAULT_STRING : Model.IfcProject.Phase.ToString();

                facilities.AddRow(facility);


                //fill in the attribute information
                foreach (IfcObject ifcObject in ifcObjects)
                {
                    attributeBuilder.RowParameters["Name"]      = facility.Name;
                    attributeBuilder.RowParameters["CreatedBy"] = facility.CreatedBy;
                    attributeBuilder.RowParameters["CreatedOn"] = facility.CreatedOn;
                    attributeBuilder.RowParameters["ExtSystem"] = facility.ExternalSystem;
                    attributeBuilder.PopulateAttributesRows(ifcObject); //fill attribute sheet rows//pass data from this sheet info as Dictionary
                }
            }

            facilities.OrderBy(s => s.Name);

            ProgressIndicator.Finalise();
            return(facilities);
        }
Example #15
0
        private static void CreateElementQuantity(XbimModel model, IfcWallStandardCase wall, IfcOwnerHistory ifcOwnerHistory)
        {
            //Create a IfcElementQuantity
            //first we need a IfcPhysicalSimpleQuantity,first will use IfcQuantityArea
            IfcQuantityArea ifcQuantityArea = model.Instances.New <IfcQuantityArea>(qa =>
            {
                qa.Name        = "IfcQuantityArea:Area";
                qa.Description = "";
                qa.Unit        = model.Instances.New <IfcSIUnit>(siu =>
                {
                    siu.UnitType   = IfcUnitEnum.AREAUNIT;
                    siu.Prefix     = IfcSIPrefix.MILLI;
                    siu.Name       = IfcSIUnitName.SQUARE_METRE;
                    siu.Dimensions = model.Instances.New <IfcDimensionalExponents>(de =>
                    {
                        de.LengthExponent                   = 1;
                        de.MassExponent                     = 0;
                        de.TimeExponent                     = 0;
                        de.ElectricCurrentExponent          = 0;
                        de.ThermodynamicTemperatureExponent = 0;
                        de.AmountOfSubstanceExponent        = 0;
                        de.LuminousIntensityExponent        = 0;
                    });
                });
                qa.AreaValue = 100.0;
            });
            //next quantity IfcQuantityCount using IfcContextDependentUnit
            IfcContextDependentUnit ifcContextDependentUnit = model.Instances.New <IfcContextDependentUnit>(cd =>
            {
                cd.Dimensions = model.Instances.New <IfcDimensionalExponents>(de =>
                {
                    de.LengthExponent                   = 1;
                    de.MassExponent                     = 0;
                    de.TimeExponent                     = 0;
                    de.ElectricCurrentExponent          = 0;
                    de.ThermodynamicTemperatureExponent = 0;
                    de.AmountOfSubstanceExponent        = 0;
                    de.LuminousIntensityExponent        = 0;
                });
                cd.UnitType = IfcUnitEnum.LENGTHUNIT;
                cd.Name     = "Elephants";
            });
            IfcQuantityCount ifcQuantityCount = model.Instances.New <IfcQuantityCount>(qc =>
            {
                qc.Name       = "IfcQuantityCount:Elephant";
                qc.CountValue = 12;
                qc.Unit       = ifcContextDependentUnit;
            });


            //next quantity IfcQuantityLength using IfcConversionBasedUnit
            IfcConversionBasedUnit ifcConversionBasedUnit = model.Instances.New <IfcConversionBasedUnit>(cbu =>
            {
                cbu.ConversionFactor = model.Instances.New <IfcMeasureWithUnit>(mu =>
                {
                    mu.ValueComponent = new IfcRatioMeasure(25.4);
                    mu.UnitComponent  = model.Instances.New <IfcSIUnit>(siu =>
                    {
                        siu.UnitType = IfcUnitEnum.LENGTHUNIT;
                        siu.Prefix   = IfcSIPrefix.MILLI;
                        siu.Name     = IfcSIUnitName.METRE;
                    });
                });
                cbu.Dimensions = model.Instances.New <IfcDimensionalExponents>(de =>
                {
                    de.LengthExponent                   = 1;
                    de.MassExponent                     = 0;
                    de.TimeExponent                     = 0;
                    de.ElectricCurrentExponent          = 0;
                    de.ThermodynamicTemperatureExponent = 0;
                    de.AmountOfSubstanceExponent        = 0;
                    de.LuminousIntensityExponent        = 0;
                });
                cbu.UnitType = IfcUnitEnum.LENGTHUNIT;
                cbu.Name     = "Inch";
            });
            IfcQuantityLength ifcQuantityLength = model.Instances.New <IfcQuantityLength>(qa =>
            {
                qa.Name        = "IfcQuantityLength:Length";
                qa.Description = "";
                qa.Unit        = ifcConversionBasedUnit;
                qa.LengthValue = 24.0;
            });

            //lets create the IfcElementQuantity
            IfcElementQuantity ifcElementQuantity = model.Instances.New <IfcElementQuantity>(eq =>
            {
                eq.OwnerHistory = ifcOwnerHistory;
                eq.Name         = "Test:IfcElementQuantity";
                eq.Description  = "Measurement quantity";
                eq.Quantities.Add(ifcQuantityArea);
                eq.Quantities.Add(ifcQuantityCount);
                eq.Quantities.Add(ifcQuantityLength);
            });

            //need to create the relationship
            IfcRelDefinesByProperties ifcRelDefinesByProperties = model.Instances.New <IfcRelDefinesByProperties>(rdbp =>
            {
                rdbp.OwnerHistory = ifcOwnerHistory;
                rdbp.Name         = "Area Association";
                rdbp.Description  = "IfcElementQuantity associated to wall";
                rdbp.RelatedObjects.Add(wall);
                rdbp.RelatingPropertyDefinition = ifcElementQuantity;
            });
        }
Example #16
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);
            }
        }
        private void AddQuantity(ValueBaseType valueBaseType, string cobiePropertyName,
                                 IfcUnitConverter actualUnits, IfcElementQuantity propertySetDefinition, NamedProperty namedProperty)
        {
            try
            {
                var cobieValue = valueBaseType.ConvertTo <double>(); //quantities are always doubles
                if (actualUnits.IsUndefined)
                {
                    throw new ArgumentException("Invalid unit type " + actualUnits.UserDefinedSiUnitName +
                                                " has been pass to CreatePropertySingleValue");
                }

                IfcPhysicalQuantity quantity;

                switch (actualUnits.UnitName)
                //they are all here for future proofing, time, mass and count though are not really used by COBie
                {
                case IfcUnitEnum.AREAUNIT:
                    quantity =
                        TargetRepository.Instances.New <IfcQuantityArea>(
                            q => q.AreaValue = new IfcAreaMeasure(cobieValue));
                    break;

                case IfcUnitEnum.LENGTHUNIT:
                    quantity =
                        TargetRepository.Instances.New <IfcQuantityLength>(
                            q => q.LengthValue = new IfcLengthMeasure(cobieValue));
                    break;

                case IfcUnitEnum.MASSUNIT:
                    quantity =
                        TargetRepository.Instances.New <IfcQuantityWeight>(
                            q => q.WeightValue = new IfcMassMeasure(cobieValue));
                    break;

                case IfcUnitEnum.TIMEUNIT:
                    quantity =
                        TargetRepository.Instances.New <IfcQuantityTime>(
                            q => q.TimeValue = new IfcTimeMeasure(cobieValue));
                    break;

                case IfcUnitEnum.VOLUMEUNIT:
                    quantity =
                        TargetRepository.Instances.New <IfcQuantityVolume>(
                            q => q.VolumeValue = new IfcVolumeMeasure(cobieValue));
                    break;

                case IfcUnitEnum.USERDEFINED:     //we will treat this as Item for now
                    quantity =
                        TargetRepository.Instances.New <IfcQuantityCount>(
                            q => q.CountValue = new IfcCountMeasure(cobieValue));
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                quantity.Description = "Converted from COBie " + cobiePropertyName;
                quantity.Name        = namedProperty.PropertyName;
                propertySetDefinition.Quantities.Add(quantity);
            }
            catch (Exception e)
            {
                throw new Exception("Failed to convert a COBie Value to and Ifc Quantity. " + e.Message);
            }
        }
Example #18
0
        public static void SetElementPhysicalSimpleQuantity(this IfcTypeObject elem, string qSetName, string qualityName, double value, XbimQuantityTypeEnum quantityType, IfcNamedUnit unit)
        {
            IModel model = null;

            if (elem is IPersistIfcEntity)
            {
                model = (elem as IPersistIfcEntity).ModelOf;
            }
            else
            {
                model = elem.ModelOf;
            }

            IfcElementQuantity qset = GetElementQuantity(elem, qSetName);

            if (qset == null)
            {
                qset      = model.Instances.New <IfcElementQuantity>();
                qset.Name = qSetName;
                if (elem.HasPropertySets == null)
                {
                    elem.CreateHasPropertySets();
                }
                elem.HasPropertySets.Add(qset);
            }

            //remove existing simple quality
            IfcPhysicalSimpleQuantity simpleQuality = GetElementPhysicalSimpleQuantity(elem, qSetName, qualityName);

            if (simpleQuality != null)
            {
                IfcElementQuantity elementQuality = GetElementQuantity(elem, qSetName);
                elementQuality.Quantities.Remove(simpleQuality);
                model.Delete(simpleQuality);
            }

            switch (quantityType)
            {
            case XbimQuantityTypeEnum.AREA:
                simpleQuality = model.Instances.New <IfcQuantityArea>(sq => sq.AreaValue = value);
                break;

            case XbimQuantityTypeEnum.COUNT:
                simpleQuality = model.Instances.New <IfcQuantityCount>(sq => sq.CountValue = value);
                break;

            case XbimQuantityTypeEnum.LENGTH:
                simpleQuality = model.Instances.New <IfcQuantityLength>(sq => sq.LengthValue = value);
                break;

            case XbimQuantityTypeEnum.TIME:
                simpleQuality = model.Instances.New <IfcQuantityTime>(sq => sq.TimeValue = value);
                break;

            case XbimQuantityTypeEnum.VOLUME:
                simpleQuality = model.Instances.New <IfcQuantityVolume>(sq => sq.VolumeValue = value);
                break;

            case XbimQuantityTypeEnum.WEIGHT:
                simpleQuality = model.Instances.New <IfcQuantityWeight>(sq => sq.WeightValue = value);
                break;

            default:
                return;
            }

            simpleQuality.Unit = unit;
            simpleQuality.Name = qualityName;

            qset.Quantities.Add(simpleQuality);
        }