Beispiel #1
0
        public Ifc4.IfcPropertySet GetIfcPropertySetFromRelatingPropertyDefinition()
        {
            Ifc4.Document document = this.Document;

            //<IfcRelDefinesByProperties id="i98" GlobalId="0DZQ9OC1z3EwnCxq2V5i7q" Name="PropertyContainer" Description="BuildingContainerForPropertySet">
            //    <RelatedObjects xsi:type="IfcBuilding" ref="i85"/>
            //    <RelatingPropertyDefinition>
            //        <IfcPropertySet xsi:nil="true" ref="i97"/>
            //    </RelatingPropertyDefinition>
            //</IfcRelDefinesByProperties>

            IfcPropertySet ifcPropertySet = (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 IfcPropertySet
                                             select ifcRelDefinesByProperties.RelatingPropertyDefinition.Item).FirstOrDefault() as IfcPropertySet;

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

            return(ifcPropertySet);
        }
Beispiel #2
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);
            }
        }
Beispiel #3
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);
        }