Example #1
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;
 }
Example #2
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;
            }
        }
 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 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);
        }
        /// <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();
        }