Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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);
            }
        }