コード例 #1
0
ファイル: IfcBuilding.cs プロジェクト: sxh2000251/Ifc.NET
 private void UpdateIfcPropertySingleValue(string propertyName, object value)
 {
     if (m_IfcPropertySingleValueCollection != null)
     {
         Ifc4.IfcPropertySingleValue ifcPropertySingleValue = m_IfcPropertySingleValueCollection.FirstOrDefault(item => item.Name == propertyName);
         UpdateIfcPropertySingleValue(ifcPropertySingleValue, value);
     }
 }
コード例 #2
0
ファイル: IfcBuilding.cs プロジェクト: sxh2000251/Ifc.NET
        private void UpdateIfcPropertySingleValue(Ifc4.IfcPropertySingleValue ifcPropertySingleValue, object value)
        {
            if (ifcPropertySingleValue == null || ifcPropertySingleValue.NominalValue == null)
            {
                return;
            }

            object item = ifcPropertySingleValue.NominalValue.Item;

            if (value is Boolean)
            {
                if (item is IfcLogicalwrapper)
                {
                    var valueItem = Get <IfcLogicalwrapper>(item);
                    valueItem.Value = ((Boolean)value) ? IfcLogical.True : IfcLogical.False;
                    valueItem.InvariantStringValue = ((Boolean)value) ? Boolean.TrueString : Boolean.FalseString;
                }
                else if (item is IfcBooleanwrapper)
                {
                    var valueItem = Get <IfcBooleanwrapper>(item);
                    valueItem.Value = (Boolean)Convert.ChangeType(value, typeof(Boolean));
                }
            }
            else if (value is Int32)
            {
                var valueItem = Get <IfcIntegerwrapper>(item);
                valueItem.Value = (Int32)Convert.ChangeType(value, typeof(Int32));
            }
            else if (value is Int64)
            {
                var valueItem = Get <IfcIntegerwrapper>(item);
                valueItem.Value = (Int64)Convert.ChangeType(value, typeof(Int64));
            }
            else if (value is Double)
            {
                var valueItem = Get <IfcRealwrapper>(item);
                valueItem.Value = (Double)Convert.ChangeType(value, typeof(Double));
            }
            else
            {
                var valueItem = Get <IfcLabelwrapper>(item);
                valueItem.Value = (value == null) ? String.Empty : value.ToString();
            }
        }
コード例 #3
0
ファイル: IfcBuilding.cs プロジェクト: sxh2000251/Ifc.NET
        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);
            }
        }