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); } }
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); } }
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); } }
public string GetVolumeUnit(IfcQuantityVolume volumeUnit) { return(volumeUnit.Unit != null?volumeUnit.Unit.GetName() : ModelVolumeUnit.ToString()); }