Esempio n. 1
0
        /// <summary>
        /// These units are used for specification of the new properties. Existing properties are not affected.
        /// </summary>
        public static void SetMetersAndMilimetersAsBaseUnit(IfcObjectDefinition ifcObject)
        {
            IModel model = ifcObject.ModelOf;

            if (_lengthUnit == null || !(_lengthUnit is IfcSIUnit)) 
            {
                //length unit
                IfcSIUnit lengthUnit = model.Instances.New<IfcSIUnit>();
                lengthUnit.Name = IfcSIUnitName.METRE;
                lengthUnit.Prefix = IfcSIPrefix.MILLI;
                lengthUnit.UnitType = IfcUnitEnum.LENGTHUNIT;
                _lengthUnit = lengthUnit;
            }

            if (_areaUnit == null ||!(_areaUnit is IfcSIUnit))
            {
                //area unit
                IfcSIUnit areaUnit = model.Instances.New<IfcSIUnit>();
                areaUnit.Name = IfcSIUnitName.SQUARE_METRE;
                areaUnit.UnitType = IfcUnitEnum.AREAUNIT;
                _areaUnit = areaUnit;
            }

            if (_volumeUnit == null || !(_volumeUnit is IfcSIUnit))
            {
                //volume init
                IfcSIUnit volumeUnit = model.Instances.New<IfcSIUnit>();
                volumeUnit.Name = IfcSIUnitName.CUBIC_METRE;
                volumeUnit.UnitType = IfcUnitEnum.VOLUMEUNIT;
                _volumeUnit = volumeUnit;
            }
        }
Esempio n. 2
0
 /// <summary>
 /// These units are used for specification of the new properties. Existing properties are not affected.
 /// </summary>
 /// <param name="lengthUnit">Length unit</param>
 /// <param name="areaUnit">Area unit</param>
 /// <param name="volumeUnit">Volume unit</param>
 public void SetNamedUnitsForProperties(IfcNamedUnit lengthUnit, IfcNamedUnit areaUnit, IfcNamedUnit volumeUnit, IfcNamedUnit weight)
 {
     _lengthUnit = lengthUnit;
     _areaUnit = areaUnit;
     _volumeUnit = volumeUnit;
     _weight = weight;
 }
        public IfcNamedUnit GetUnitFor(IfcPhysicalSimpleQuantity quantity)
        {
            if (quantity.Unit != null)
            {
                return(quantity.Unit);
            }

            IfcUnitEnum?requiredUnit = null;

            // list of possible types taken from:
            // http://www.buildingsmart-tech.org/ifc/IFC2x3/TC1/html/ifcquantityresource/lexical/ifcphysicalsimplequantity.htm
            //
            if (quantity is IfcQuantityLength)
            {
                requiredUnit = IfcUnitEnum.LENGTHUNIT;
            }
            else if (quantity is IfcQuantityArea)
            {
                requiredUnit = IfcUnitEnum.AREAUNIT;
            }
            else if (quantity is IfcQuantityVolume)
            {
                requiredUnit = IfcUnitEnum.VOLUMEUNIT;
            }
            else if (quantity is IfcQuantityCount) // really not sure what to do here.
            {
                return(null);
            }
            else if (quantity is IfcQuantityWeight)
            {
                requiredUnit = IfcUnitEnum.MASSUNIT;
            }
            else if (quantity is IfcQuantityTime)
            {
                requiredUnit = IfcUnitEnum.TIMEUNIT;
            }

            if (requiredUnit == null)
            {
                return(null);
            }

            IfcNamedUnit nu = Units.OfType <IfcSIUnit>().FirstOrDefault(u => u.UnitType == (IfcUnitEnum)requiredUnit);

            if (nu == null)
            {
                nu = Units.OfType <IfcConversionBasedUnit>().FirstOrDefault(u => u.UnitType == (IfcUnitEnum)requiredUnit);
            }
            return(nu);
        }
 public override void IfcParse(int propIndex, IPropertyValue value)
 {
     switch (propIndex)
     {
         case 0:
         case 1:
             base.IfcParse(propIndex, value);
             break;
         case 2:
             _unit = (IfcNamedUnit) value.EntityVal;
             break;
         default:
             this.HandleUnexpectedAttribute(propIndex, value); break;
     }
 }
        public override void Parse(int propIndex, IPropertyValue value, int[] nestedIndex)
        {
            switch (propIndex)
            {
            case 0:
                _unit = (IfcNamedUnit)(value.EntityVal);
                return;

            case 1:
                _exponent = value.IntegerVal;
                return;

            default:
                throw new XbimParserException(string.Format("Attribute index {0} is out of range for {1}", propIndex + 1, GetType().Name.ToUpper()));
            }
        }
        public void IfcParse(int propIndex, IPropertyValue value)
        {
            switch (propIndex)
            {
            case 0:
                _unit = (IfcNamedUnit)value.EntityVal;
                break;

            case 1:
                _exponent = (int)value.IntegerVal;
                break;

            default:
                this.HandleUnexpectedAttribute(propIndex, value); break;
            }
        }
Esempio n. 7
0
        public override bool Equals(object obj)
        {
            // Check for null
            if (obj == null)
            {
                return(false);
            }

            // Check for type
            if (this.GetType() != obj.GetType())
            {
                return(false);
            }

            // Cast as IfcRoot
            IfcNamedUnit root = (IfcNamedUnit)obj;

            return(this == root);
        }
        public static void SetElementPhysicalSimpleQuantity(this IfcTypeObject elem, string qSetName, string qualityName, double value, XbimQuantityTypeEnum quantityType, IfcNamedUnit unit)
        {
            IModel model = null;

            if (elem is IPersistIfcEntity) 
                model = (elem as IPersistIfcEntity).ModelOf;
            else  
                model = elem.ModelOf;

            IfcElementQuantity qset = GetElementQuantity(elem, qSetName);
            if (qset == null)
            {
                qset = model.Instances.New<IfcElementQuantity>();
                qset.Name = qSetName;
                if (elem.HasPropertySets == null) elem.CreateHasPropertySets();
                elem.HasPropertySets.Add(qset);
            }

            //remove existing simple quality
            IfcPhysicalSimpleQuantity simpleQuality = GetElementPhysicalSimpleQuantity(elem, qSetName, qualityName);
            if (simpleQuality != null)
            {
                IfcElementQuantity elementQuality = GetElementQuantity(elem, qSetName);
                elementQuality.Quantities.Remove(simpleQuality);
                model.Delete(simpleQuality);
            }

            switch (quantityType)
            {
                case XbimQuantityTypeEnum.AREA:
                    simpleQuality = model.Instances.New<IfcQuantityArea>(sq => sq.AreaValue = value);
                    break;
                case XbimQuantityTypeEnum.COUNT:
                    simpleQuality = model.Instances.New<IfcQuantityCount>(sq => sq.CountValue = value);
                    break;
                case XbimQuantityTypeEnum.LENGTH:
                    simpleQuality = model.Instances.New<IfcQuantityLength>(sq => sq.LengthValue = value);
                    break;
                case XbimQuantityTypeEnum.TIME:
                    simpleQuality = model.Instances.New<IfcQuantityTime>(sq => sq.TimeValue = value);
                    break;
                case XbimQuantityTypeEnum.VOLUME:
                    simpleQuality = model.Instances.New<IfcQuantityVolume>(sq => sq.VolumeValue = value);
                    break;
                case XbimQuantityTypeEnum.WEIGHT:
                    simpleQuality = model.Instances.New<IfcQuantityWeight>(sq => sq.WeightValue = value);
                    break;
                default:
                    return;
            }

            simpleQuality.Unit = unit;
            simpleQuality.Name = qualityName;

            qset.Quantities.Add(simpleQuality);
        }
        public IfcNamedUnit GetUnitFor(IfcPropertySingleValue property)
        {
            if (property.Unit != null)
            {
                return((IfcNamedUnit)property.Unit);
            }

            // nominal value can be of types with subtypes:
            //	IfcMeasureValue, IfcSimpleValue, IfcDerivedMeasureValue

            IfcUnitEnum?requiredUnit;

            // types from http://www.buildingsmart-tech.org/ifc/IFC2x3/TC1/html/ifcmeasureresource/lexical/ifcmeasurevalue.htm
            if (property.NominalValue is IfcVolumeMeasure)
            {
                requiredUnit = IfcUnitEnum.VOLUMEUNIT;
            }
            else if (property.NominalValue is IfcAreaMeasure)
            {
                requiredUnit = IfcUnitEnum.AREAUNIT;
            }
            else if (property.NominalValue is IfcLengthMeasure)
            {
                requiredUnit = IfcUnitEnum.LENGTHUNIT;
            }
            else if (property.NominalValue is IfcPositiveLengthMeasure)
            {
                requiredUnit = IfcUnitEnum.LENGTHUNIT;
            }
            else if (property.NominalValue is IfcAmountOfSubstanceMeasure)
            {
                requiredUnit = IfcUnitEnum.AMOUNTOFSUBSTANCEUNIT;
            }
            else if (property.NominalValue is IfcContextDependentMeasure)
            {
                requiredUnit = null; // todo: not sure what to do here
            }
            else if (property.NominalValue is IfcCountMeasure)
            {
                requiredUnit = null; // todo: not sure what to do here
            }
            else if (property.NominalValue is IfcDescriptiveMeasure)
            {
                requiredUnit = null; // todo: not sure what to do here
            }
            else if (property.NominalValue is IfcElectricCurrentMeasure)
            {
                requiredUnit = IfcUnitEnum.ELECTRICCURRENTUNIT;
            }
            else if (property.NominalValue is IfcLuminousIntensityMeasure)
            {
                requiredUnit = IfcUnitEnum.LUMINOUSINTENSITYUNIT;
            }
            else if (property.NominalValue is IfcMassMeasure)
            {
                requiredUnit = IfcUnitEnum.MASSUNIT;
            }
            else if (property.NominalValue is IfcNormalisedRatioMeasure)
            {
                requiredUnit = null; // todo: not sure what to do here
            }
            else if (property.NominalValue is IfcNumericMeasure)
            {
                requiredUnit = null; // todo: not sure what to do here.
            }
            else if (property.NominalValue is IfcParameterValue)
            {
                requiredUnit = null; // todo: not sure what to do here.
            }
            else if (property.NominalValue is IfcPlaneAngleMeasure)
            {
                requiredUnit = IfcUnitEnum.PLANEANGLEUNIT;
            }
            else if (property.NominalValue is IfcPositiveRatioMeasure)
            {
                requiredUnit = null; // todo: not sure what to do here.
            }
            else if (property.NominalValue is IfcPositivePlaneAngleMeasure)
            {
                requiredUnit = IfcUnitEnum.PLANEANGLEUNIT;
            }
            else if (property.NominalValue is IfcRatioMeasure)
            {
                requiredUnit = null; // todo: not sure what to do here.
            }
            else if (property.NominalValue is IfcSolidAngleMeasure)
            {
                requiredUnit = IfcUnitEnum.SOLIDANGLEUNIT;
            }
            else if (property.NominalValue is IfcThermodynamicTemperatureMeasure)
            {
                requiredUnit = IfcUnitEnum.THERMODYNAMICTEMPERATUREUNIT;
            }
            else if (property.NominalValue is IfcTimeMeasure)
            {
                requiredUnit = IfcUnitEnum.TIMEUNIT;
            }
            else if (property.NominalValue is IfcComplexNumber)
            {
                requiredUnit = null; // todo: not sure what to do here.
            }
            // types from IfcSimpleValue
            else if (property.NominalValue is IfcSimpleValue)
            {
                requiredUnit = null;
            }
            else
            {
                requiredUnit = null;
            }
            // more measures types to be taken from http://www.buildingsmart-tech.org/ifc/IFC2x3/TC1/html/ifcmeasureresource/lexical/ifcderivedmeasurevalue.htm

            if (requiredUnit == null)
            {
                return(null);
            }

            IfcNamedUnit nu = Units.OfType <IfcSIUnit>().FirstOrDefault(u => u.UnitType == (IfcUnitEnum)requiredUnit);

            if (nu == null)
            {
                nu = Units.OfType <IfcConversionBasedUnit>().FirstOrDefault(u => u.UnitType == (IfcUnitEnum)requiredUnit);
            }
            return(nu);
        }
Esempio n. 10
0
        /// <summary>
        /// Get the unit abbreviation html friendly
        /// </summary>
        /// <param name="ifcNamedUnit">IfcNamedUnit unit to abbreviate</param>
        /// <returns>string as abbreviation</returns>
        public static string GetUnitAbbreviation(IfcNamedUnit ifcNamedUnit)
        {
            string abbriv = string.Empty;

            if (ifcNamedUnit is IfcSIUnit)
            {
                //get abbreviation for unit
                abbriv = (ifcNamedUnit as IfcSIUnit).GetSymbol(); //try Unicode
            }

            if (ifcNamedUnit is IfcConversionBasedUnit)
            {
                abbriv = (ifcNamedUnit as IfcConversionBasedUnit).GetSymbol();
            }

            if (ifcNamedUnit is IfcContextDependentUnit)
            {
                abbriv = (ifcNamedUnit as IfcContextDependentUnit).GetSymbol();
            }

            abbriv = AbbreviationToHTML(abbriv);

            return abbriv.ToLower();
        }