public void CanDeserializeSimpleLine()
        {
            Entity[] Items = DeserializeAssertISO10303AndExtractItems(Utilities.StepSimpleLineString());
            Assert.AreEqual(1, Items.Length);
            Assert.IsNotNull(Items[0]);
            IfcQuantityLength ql = Items[0] as IfcQuantityLength;

            Assert.IsNotNull(ql);
            Assert.AreEqual("Depth", ql.Name);
            Assert.AreEqual("Depth", ql.Description);
            Assert.AreEqual(0.3, ql.LengthValue);
            Assert.IsNull(ql.Unit);
        }
Esempio n. 2
0
        public static IfcLengthMeasure?GetTotalHeight(this IfcBuildingStorey buildingStorey)
        {
            IfcQuantityLength qLen = buildingStorey.GetQuantity <IfcQuantityLength>("BaseQuantities", "TotalHeight");

            if (qLen == null)
            {
                qLen = buildingStorey.GetQuantity <IfcQuantityLength>("TotalHeight");              //just look for any height
            }
            if (qLen != null)
            {
                return(qLen.LengthValue);
            }
            return(null);
        }
        private static IfcNamedUnit resolveUnit(IIfcPhysicalQuantity quan)
        {
            IEntityCollection ifcModel = quan.Model.Instances;

            if (quan is IfcQuantityLength)
            {
                IfcQuantityLength ifcValue = (IfcQuantityLength)quan;
                return(ifcValue.Unit != null
                    ? ifcValue.Unit
                    : ifcModel.FirstOrDefault <IfcNamedUnit>(ifcNamedUnit => ifcNamedUnit.UnitType.Equals(IfcUnitEnum.LENGTHUNIT)));
            }
            else if (quan is IfcQuantityArea)
            {
                IfcQuantityArea ifcValue = (IfcQuantityArea)quan;
                return(ifcValue.Unit != null
                    ? ifcValue.Unit
                    : ifcModel.FirstOrDefault <IfcNamedUnit>(ifcNamedUnit => ifcNamedUnit.UnitType.Equals(IfcUnitEnum.AREAUNIT)));
            }
            else if (quan is IfcQuantityVolume)
            {
                IfcQuantityVolume ifcValue = (IfcQuantityVolume)quan;
                return(ifcValue.Unit != null
                    ? ifcValue.Unit
                    : ifcModel.FirstOrDefault <IfcNamedUnit>(ifcNamedUnit => ifcNamedUnit.UnitType.Equals(IfcUnitEnum.VOLUMEUNIT)));
            }
            else if (quan is IfcQuantityTime)
            {
                IfcQuantityTime ifcValue = (IfcQuantityTime)quan;
                return(ifcValue.Unit != null
                    ? ifcValue.Unit
                    : ifcModel.FirstOrDefault <IfcNamedUnit>(ifcNamedUnit => ifcNamedUnit.UnitType.Equals(IfcUnitEnum.TIMEUNIT)));
            }
            else if (quan is IfcQuantityWeight)
            {
                IfcQuantityWeight ifcValue = (IfcQuantityWeight)quan;
                return(ifcValue.Unit != null
                    ? ifcValue.Unit
                    : ifcModel.FirstOrDefault <IfcNamedUnit>(ifcNamedUnit => ifcNamedUnit.UnitType.Equals(IfcUnitEnum.MASSUNIT)));
            }
            else if (quan is IfcQuantityCount)
            {
                IfcQuantityCount ifcValue = (IfcQuantityCount)quan;
                return(ifcValue.Unit);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Returns the Perimeter, if the element base quantity GrossPerimeter is defined
        ///
        /// </summary>
        /// <returns></returns>
        public static IfcLengthMeasure GetGrossPerimeter(this IfcSpace space)
        {
            IfcQuantityLength qLength = space.GetQuantity <IfcQuantityLength>("BaseQuantities", "GrossPerimeter");

            if (qLength == null)
            {
                qLength = space.GetQuantity <IfcQuantityLength>("GrossPerimeter");                 //just look for any area
            }
            if (qLength != null)
            {
                return(qLength.LengthValue);
            }
            //try none schema defined properties
            return(null);
        }
 private static IfcUnit resolveUnit(IIfcPhysicalQuantity quan)
 {
     if (quan is IfcQuantityLength)
     {
         IfcQuantityLength ifcValue = (IfcQuantityLength)quan;
         return(ifcValue.Unit);
     }
     else if (quan is IfcQuantityArea)
     {
         IfcQuantityArea ifcValue = (IfcQuantityArea)quan;
         return(ifcValue.Unit);
     }
     else if (quan is IfcQuantityVolume)
     {
         IfcQuantityVolume ifcValue = (IfcQuantityVolume)quan;
         return(ifcValue.Unit);
     }
     else if (quan is IfcQuantityTime)
     {
         IfcQuantityTime ifcValue = (IfcQuantityTime)quan;
         return(ifcValue.Unit);
     }
     else if (quan is IfcQuantityWeight)
     {
         IfcQuantityWeight ifcValue = (IfcQuantityWeight)quan;
         return(ifcValue.Unit);
     }
     else if (quan is IfcQuantityCount)
     {
         IfcQuantityCount ifcValue = (IfcQuantityCount)quan;
         return(ifcValue.Unit);
     }
     else
     {
         return(null);
     }
 }
 private static IfcValue resolveValue(IIfcPhysicalQuantity quan)
 {
     if (quan is IfcQuantityLength)
     {
         IfcQuantityLength ifcValue = (IfcQuantityLength)quan;
         return(new IfcLengthMeasure(ifcValue.LengthValue.ToString()));
     }
     else if (quan is IfcQuantityArea)
     {
         IfcQuantityArea ifcValue = (IfcQuantityArea)quan;
         return(new IfcAreaMeasure(ifcValue.AreaValue.ToString()));
     }
     else if (quan is IfcQuantityVolume)
     {
         IfcQuantityVolume ifcValue = (IfcQuantityVolume)quan;
         return(new IfcVolumeMeasure(ifcValue.VolumeValue.ToString()));
     }
     else if (quan is IfcQuantityTime)
     {
         IfcQuantityTime ifcValue = (IfcQuantityTime)quan;
         return(new IfcTimeMeasure(ifcValue.TimeValue.ToString()));
     }
     else if (quan is IfcQuantityWeight)
     {
         IfcQuantityWeight ifcValue = (IfcQuantityWeight)quan;
         return(new IfcMassMeasure(ifcValue.WeightValue));
     }
     else if (quan is IfcQuantityCount)
     {
         IfcQuantityCount ifcValue = (IfcQuantityCount)quan;
         return(new IfcCountMeasure(ifcValue.CountValue.ToString()));
     }
     else
     {
         return(null);
     }
 }
Esempio n. 7
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);
            }
        }
Esempio n. 8
0
 public string GetLinearUnit(IfcQuantityLength lengthUnit)
 {
     return(lengthUnit.Unit != null?lengthUnit.Unit.GetName() : ModelLinearUnit.ToString());
 }
Esempio n. 9
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;
            });
        }